Commit | Line | Data |
---|---|---|
fa26e11c WD |
1 | After applying this patch, run these commands for a successful build: |
2 | ||
27e96866 | 3 | ./prepare-source |
f787c90c | 4 | ./configure --enable-acl-support |
fa26e11c WD |
5 | make |
6 | ||
a5e3a4cc WD |
7 | See the --acls (-A) option in the revised man page for a note on using this |
8 | latest ACL-enabling patch to send files to an older ACL-enabled rsync. | |
9 | ||
10 | This code does not yet itemize changes in ACL information (see --itemize). | |
34a409bc | 11 | |
9a7eef96 WD |
12 | --- old/Makefile.in |
13 | +++ new/Makefile.in | |
4bf6f8c7 | 14 | @@ -25,15 +25,15 @@ VERSION=@VERSION@ |
fa26e11c WD |
15 | .SUFFIXES: |
16 | .SUFFIXES: .c .o | |
17 | ||
18 | -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h | |
19 | +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h | |
20 | LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \ | |
0f6733d8 WD |
21 | - lib/permstring.o lib/pool_alloc.o @LIBOBJS@ |
22 | + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@ | |
4bf6f8c7 WD |
23 | ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \ |
24 | zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o | |
fa26e11c WD |
25 | OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \ |
26 | main.o checksum.o match.o syscall.o log.o backup.o | |
27 | OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \ | |
610969d1 WD |
28 | - fileio.o batch.o clientname.o chmod.o |
29 | + fileio.o batch.o clientname.o chmod.o acls.o | |
fa26e11c WD |
30 | OBJS3=progress.o pipe.o |
31 | DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o | |
32 | popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \ | |
9a7eef96 WD |
33 | --- old/acls.c |
34 | +++ new/acls.c | |
a5e3a4cc | 35 | @@ -0,0 +1,1255 @@ |
fa26e11c WD |
36 | +/* -*- c-file-style: "linux" -*- |
37 | + Copyright (C) Andrew Tridgell 1996 | |
38 | + Copyright (C) Paul Mackerras 1996 | |
c6437996 WD |
39 | + Copyright (C) Matt McCutchen 2006 |
40 | + Copyright (C) Wayne Davison 2006 | |
fa26e11c WD |
41 | + |
42 | + This program is free software; you can redistribute it and/or modify | |
43 | + it under the terms of the GNU General Public License as published by | |
44 | + the Free Software Foundation; either version 2 of the License, or | |
45 | + (at your option) any later version. | |
46 | + | |
47 | + This program is distributed in the hope that it will be useful, | |
48 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
49 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
50 | + GNU General Public License for more details. | |
51 | + | |
52 | + You should have received a copy of the GNU General Public License | |
53 | + along with this program; if not, write to the Free Software | |
54 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
55 | +*/ | |
56 | + | |
57 | +/* handle passing ACLs between systems */ | |
58 | + | |
59 | +#include "rsync.h" | |
0f6733d8 | 60 | +#include "lib/sysacls.h" |
fa26e11c | 61 | + |
4df546eb | 62 | +#ifdef SUPPORT_ACLS |
fa26e11c | 63 | + |
fa26e11c WD |
64 | +extern int am_root; |
65 | +extern int dry_run; | |
90fa6d68 | 66 | +extern int orig_umask; |
a5e3a4cc | 67 | +extern int preserve_acls; |
fa26e11c WD |
68 | + |
69 | +typedef struct { | |
70 | + id_t id; | |
71 | + uchar access; | |
c6437996 | 72 | +} id_access; |
fa26e11c WD |
73 | + |
74 | +typedef struct { | |
75 | + size_t count; | |
76 | + size_t malloced; | |
c6437996 WD |
77 | + id_access *idas; |
78 | +} ida_list; | |
79 | + | |
80 | +#define NO_ENTRY ((uchar)0x80) | |
81 | +typedef struct { | |
82 | + ida_list users; | |
83 | + ida_list groups; | |
84 | + /* These will be NO_ENTRY if there's no such entry. */ | |
85 | + uchar user_obj; | |
86 | + uchar group_obj; | |
87 | + uchar mask; | |
88 | + uchar other; | |
fa26e11c WD |
89 | +} rsync_acl; |
90 | + | |
c6437996 WD |
91 | +static const rsync_acl rsync_acl_initializer = |
92 | + { {0, 0, NULL}, {0, 0, NULL}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY}; | |
8db8e7d2 WD |
93 | + |
94 | +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t)) | |
95 | +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT) | |
fa26e11c | 96 | + |
c6437996 WD |
97 | +/* a few useful calculations */ |
98 | + | |
99 | +static int rsync_acl_count_entries(const rsync_acl *racl) { | |
100 | + return racl->users.count + racl->groups.count | |
101 | + + (racl->user_obj != NO_ENTRY) | |
102 | + + (racl->group_obj != NO_ENTRY) | |
103 | + + (racl->mask != NO_ENTRY) | |
104 | + + (racl->other != NO_ENTRY); | |
105 | +} | |
106 | + | |
107 | +static int rsync_acl_get_perms(const rsync_acl *racl) { | |
108 | + /* Note that (NO_ENTRY & 7) is 0. */ | |
109 | + return ((racl->user_obj & 7) << 6) | |
110 | + + (((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) & 7) << 3) | |
111 | + + (racl->other & 7); | |
112 | +} | |
113 | + | |
114 | +static void rsync_acl_strip_perms(rsync_acl *racl) { | |
115 | + racl->user_obj = NO_ENTRY; | |
116 | + if (racl->mask == NO_ENTRY) | |
117 | + racl->group_obj = NO_ENTRY; | |
118 | + else | |
119 | + racl->mask = NO_ENTRY; | |
120 | + racl->other = NO_ENTRY; | |
121 | +} | |
34a409bc | 122 | + |
c6437996 | 123 | +static void expand_ida_list(ida_list *idal) |
fa26e11c | 124 | +{ |
ad625644 | 125 | + /* First time through, 0 <= 0, so list is expanded. */ |
c6437996 WD |
126 | + if (idal->malloced <= idal->count) { |
127 | + id_access *new_ptr; | |
128 | + size_t new_size = idal->malloced + 10; | |
129 | + new_ptr = realloc_array(idal->idas, id_access, new_size); | |
fa26e11c WD |
130 | + if (verbose >= 4) { |
131 | + rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n", | |
c6437996 WD |
132 | + (double) new_size * sizeof idal->idas[0], |
133 | + idal->idas ? "" : " not"); | |
fa26e11c WD |
134 | + } |
135 | + | |
c6437996 WD |
136 | + idal->idas = new_ptr; |
137 | + idal->malloced = new_size; | |
fa26e11c | 138 | + |
c6437996 WD |
139 | + if (!idal->idas) |
140 | + out_of_memory("expand_ida_list"); | |
fa26e11c WD |
141 | + } |
142 | +} | |
143 | + | |
c6437996 WD |
144 | +static void ida_list_free(ida_list *idal) |
145 | +{ | |
146 | + free(idal->idas); | |
147 | + idal->idas = NULL; | |
148 | + idal->count = 0; | |
149 | + idal->malloced = 0; | |
150 | +} | |
151 | + | |
fa26e11c WD |
152 | +static void rsync_acl_free(rsync_acl *racl) |
153 | +{ | |
c6437996 WD |
154 | + ida_list_free(&racl->users); |
155 | + ida_list_free(&racl->groups); | |
fa26e11c WD |
156 | +} |
157 | + | |
c6437996 | 158 | +static int id_access_sorter(const void *r1, const void *r2) |
fa26e11c | 159 | +{ |
c6437996 WD |
160 | + id_access *ida1 = (id_access *)r1; |
161 | + id_access *ida2 = (id_access *)r2; | |
162 | + id_t rid1 = ida1->id, rid2 = ida2->id; | |
fa26e11c WD |
163 | + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1; |
164 | +} | |
165 | + | |
c6437996 | 166 | +static void sort_ida_list(ida_list *idal) |
fa26e11c | 167 | +{ |
c6437996 | 168 | + if (!idal->count) |
fa26e11c | 169 | + return; |
c6437996 WD |
170 | + qsort((void **)idal->idas, idal->count, sizeof idal->idas[0], |
171 | + &id_access_sorter); | |
fa26e11c WD |
172 | +} |
173 | + | |
174 | +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl) | |
175 | +{ | |
176 | + SMB_ACL_ENTRY_T entry; | |
fa26e11c | 177 | + const char *errfun; |
c6437996 WD |
178 | + int rc; |
179 | + | |
fa26e11c WD |
180 | + *racl = rsync_acl_initializer; |
181 | + errfun = "sys_acl_get_entry"; | |
182 | + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry); | |
183 | + rc == 1; | |
184 | + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) { | |
c6437996 | 185 | + SMB_ACL_TAG_T tag_type; |
fa26e11c | 186 | + SMB_ACL_PERMSET_T permset; |
c6437996 | 187 | + uchar access; |
fa26e11c | 188 | + void *qualifier; |
c6437996 WD |
189 | + id_access *ida; |
190 | + ida_list *idal; | |
191 | + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) { | |
fa26e11c WD |
192 | + errfun = "sys_acl_get_tag_type"; |
193 | + break; | |
194 | + } | |
195 | + if ((rc = sys_acl_get_permset(entry, &permset))) { | |
196 | + errfun = "sys_acl_get_tag_type"; | |
197 | + break; | |
198 | + } | |
c6437996 WD |
199 | + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0) |
200 | + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0) | |
201 | + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0); | |
202 | + /* continue == done with entry; break == store in given idal */ | |
203 | + switch (tag_type) { | |
204 | + case SMB_ACL_USER_OBJ: | |
205 | + if (racl->user_obj == NO_ENTRY) | |
206 | + racl->user_obj = access; | |
207 | + else | |
208 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n"); | |
209 | + continue; | |
fa26e11c | 210 | + case SMB_ACL_USER: |
c6437996 WD |
211 | + idal = &racl->users; |
212 | + break; | |
213 | + case SMB_ACL_GROUP_OBJ: | |
214 | + if (racl->group_obj == NO_ENTRY) | |
215 | + racl->group_obj = access; | |
216 | + else | |
217 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n"); | |
218 | + continue; | |
fa26e11c | 219 | + case SMB_ACL_GROUP: |
c6437996 | 220 | + idal = &racl->groups; |
fa26e11c | 221 | + break; |
c6437996 WD |
222 | + case SMB_ACL_MASK: |
223 | + if (racl->mask == NO_ENTRY) | |
224 | + racl->mask = access; | |
225 | + else | |
226 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n"); | |
227 | + continue; | |
228 | + case SMB_ACL_OTHER: | |
229 | + if (racl->other == NO_ENTRY) | |
230 | + racl->other = access; | |
231 | + else | |
232 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n"); | |
233 | + continue; | |
fa26e11c | 234 | + default: |
c6437996 | 235 | + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n"); |
fa26e11c WD |
236 | + continue; |
237 | + } | |
238 | + if (!(qualifier = sys_acl_get_qualifier(entry))) { | |
239 | + errfun = "sys_acl_get_tag_type"; | |
240 | + rc = EINVAL; | |
241 | + break; | |
242 | + } | |
c6437996 WD |
243 | + expand_ida_list(idal); |
244 | + ida = &idal->idas[idal->count++]; | |
245 | + ida->id = *((id_t *)qualifier); | |
246 | + ida->access = access; | |
247 | + sys_acl_free_qualifier(qualifier, tag_type); | |
fa26e11c WD |
248 | + } |
249 | + if (rc) { | |
250 | + rprintf(FERROR, "unpack_smb_acl: %s(): %s\n", | |
251 | + errfun, strerror(errno)); | |
252 | + rsync_acl_free(racl); | |
253 | + return False; | |
254 | + } | |
c6437996 WD |
255 | + |
256 | + sort_ida_list(&racl->users); | |
257 | + sort_ida_list(&racl->groups); | |
258 | + | |
fa26e11c WD |
259 | + return True; |
260 | +} | |
261 | + | |
c6437996 | 262 | +static BOOL ida_lists_equal(const ida_list *ial1, const ida_list *ial2) |
fa26e11c | 263 | +{ |
c6437996 WD |
264 | + id_access *ida1, *ida2; |
265 | + size_t count = ial1->count; | |
266 | + if (count != ial2->count) | |
fa26e11c | 267 | + return False; |
c6437996 WD |
268 | + ida1 = ial1->idas; |
269 | + ida2 = ial2->idas; | |
270 | + for (; count--; ida1++, ida2++) { | |
271 | + if (ida1->access != ida2->access || ida1->id != ida2->id) | |
fa26e11c WD |
272 | + return False; |
273 | + } | |
274 | + return True; | |
275 | +} | |
276 | + | |
c6437996 WD |
277 | +static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2) |
278 | +{ | |
279 | + return (racl1->user_obj == racl2->user_obj | |
280 | + && racl1->group_obj == racl2->group_obj | |
281 | + && racl1->mask == racl2->mask | |
282 | + && racl1->other == racl2->other | |
283 | + && ida_lists_equal(&racl1->users, &racl2->users) | |
284 | + && ida_lists_equal(&racl1->groups, &racl2->groups)); | |
285 | +} | |
286 | + | |
287 | +static BOOL rsync_acl_extended_parts_equal(const rsync_acl *racl1, const rsync_acl *racl2) | |
288 | +{ | |
289 | + /* We ignore any differences that chmod() can take care of. */ | |
290 | + if ((racl1->mask ^ racl2->mask) & NO_ENTRY) | |
291 | + return False; | |
292 | + if (racl1->mask != NO_ENTRY && racl1->group_obj != racl2->group_obj) | |
293 | + return False; | |
294 | + return ida_lists_equal(&racl1->users, &racl2->users) | |
295 | + && ida_lists_equal(&racl1->groups, &racl2->groups); | |
296 | +} | |
297 | + | |
fa26e11c WD |
298 | +typedef struct { |
299 | + size_t count; | |
300 | + size_t malloced; | |
301 | + rsync_acl *racls; | |
302 | +} rsync_acl_list; | |
303 | + | |
304 | +static rsync_acl_list _rsync_acl_lists[] = { | |
305 | + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */ | |
306 | + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */ | |
307 | +}; | |
308 | + | |
309 | +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type) | |
310 | +{ | |
311 | + return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0] | |
312 | + : &_rsync_acl_lists[1]; | |
313 | +} | |
314 | + | |
315 | +static void expand_rsync_acl_list(rsync_acl_list *racl_list) | |
316 | +{ | |
ad625644 | 317 | + /* First time through, 0 <= 0, so list is expanded. */ |
fa26e11c | 318 | + if (racl_list->malloced <= racl_list->count) { |
0f6733d8 | 319 | + rsync_acl *new_ptr; |
fa26e11c WD |
320 | + size_t new_size; |
321 | + if (racl_list->malloced < 1000) | |
0f6733d8 | 322 | + new_size = racl_list->malloced + 1000; |
fa26e11c | 323 | + else |
0f6733d8 WD |
324 | + new_size = racl_list->malloced * 2; |
325 | + new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size); | |
fa26e11c WD |
326 | + if (verbose >= 3) { |
327 | + rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n", | |
0f6733d8 | 328 | + (double) new_size * sizeof racl_list->racls[0], |
fa26e11c WD |
329 | + racl_list->racls ? "" : " not"); |
330 | + } | |
331 | + | |
0f6733d8 WD |
332 | + racl_list->racls = new_ptr; |
333 | + racl_list->malloced = new_size; | |
fa26e11c WD |
334 | + |
335 | + if (!racl_list->racls) | |
336 | + out_of_memory("expand_rsync_acl_list"); | |
337 | + } | |
338 | +} | |
339 | + | |
fa26e11c WD |
340 | +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type, |
341 | + const rsync_acl_list *racl_list, | |
342 | + const rsync_acl *racl) | |
343 | +{ | |
344 | + static int access_match = -1, default_match = -1; | |
345 | + int *match = (type == SMB_ACL_TYPE_ACCESS) ? | |
346 | + &access_match : &default_match; | |
347 | + size_t count = racl_list->count; | |
4edb99c8 | 348 | + /* If this is the first time through or we didn't match the last |
fa26e11c | 349 | + * time, then start at the end of the list, which should be the |
4edb99c8 | 350 | + * best place to start hunting. */ |
fa26e11c WD |
351 | + if (*match == -1) |
352 | + *match = racl_list->count - 1; | |
353 | + while (count--) { | |
354 | + if (rsync_acls_equal(&racl_list->racls[*match], racl)) | |
355 | + return *match; | |
356 | + if (!(*match)--) | |
357 | + *match = racl_list->count - 1; | |
358 | + } | |
359 | + *match = -1; | |
360 | + return *match; | |
361 | +} | |
362 | + | |
4edb99c8 | 363 | +/* The general strategy with the tag_type <-> character mapping is that |
fa26e11c | 364 | + * lowercase implies that no qualifier follows, where uppercase does. |
4edb99c8 | 365 | + * A similar idiom for the acl type (access or default) itself, but |
fa26e11c WD |
366 | + * lowercase in this instance means there's no ACL following, so the |
367 | + * ACL is a repeat, so the receiver should reuse the last of the same | |
4edb99c8 | 368 | + * type ACL. */ |
dfadc68a | 369 | +static void send_ida_list(int f, const ida_list *idal, char tag_char) |
c6437996 WD |
370 | +{ |
371 | + id_access *ida; | |
372 | + size_t count = idal->count; | |
373 | + for (ida = idal->idas; count--; ida++) { | |
374 | + write_byte(f, tag_char); | |
375 | + write_byte(f, ida->access); | |
376 | + write_int(f, ida->id); | |
377 | + /* FIXME: sorta wasteful: we should maybe buffer as | |
378 | + * many ids as max(ACL_USER + ACL_GROUP) objects to | |
379 | + * keep from making so many calls. */ | |
380 | + if (tag_char == 'U') | |
381 | + add_uid(ida->id); | |
382 | + else | |
383 | + add_gid(ida->id); | |
384 | + } | |
385 | +} | |
386 | + | |
fa26e11c WD |
387 | +static void send_rsync_acl(int f, const rsync_acl *racl) |
388 | +{ | |
c6437996 | 389 | + size_t count = rsync_acl_count_entries(racl); |
fa26e11c | 390 | + write_int(f, count); |
c6437996 WD |
391 | + if (racl->user_obj != NO_ENTRY) { |
392 | + write_byte(f, 'u'); | |
393 | + write_byte(f, racl->user_obj); | |
394 | + } | |
395 | + send_ida_list(f, &racl->users, 'U'); | |
396 | + if (racl->group_obj != NO_ENTRY) { | |
397 | + write_byte(f, 'g'); | |
398 | + write_byte(f, racl->group_obj); | |
399 | + } | |
400 | + send_ida_list(f, &racl->groups, 'G'); | |
401 | + if (racl->mask != NO_ENTRY) { | |
402 | + write_byte(f, 'm'); | |
403 | + write_byte(f, racl->mask); | |
404 | + } | |
405 | + if (racl->other != NO_ENTRY) { | |
406 | + write_byte(f, 'o'); | |
407 | + write_byte(f, racl->other); | |
fa26e11c WD |
408 | + } |
409 | +} | |
410 | + | |
411 | +static rsync_acl _curr_rsync_acls[2]; | |
412 | + | |
fa26e11c WD |
413 | +static const char *str_acl_type(SMB_ACL_TYPE_T type) |
414 | +{ | |
415 | + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" : | |
416 | + type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" : | |
417 | + "unknown SMB_ACL_TYPE_T"; | |
418 | +} | |
419 | + | |
4edb99c8 WD |
420 | +/* Generate the ACL(s) for this flist entry; |
421 | + * ACL(s) are either sent or cleaned-up by send_acl() below. */ | |
ee12ff0e | 422 | +int make_acl(const struct file_struct *file, const char *fname) |
fa26e11c | 423 | +{ |
8db8e7d2 | 424 | + SMB_ACL_TYPE_T type; |
fa26e11c | 425 | + rsync_acl *curr_racl; |
36aa3171 | 426 | + |
162234a7 | 427 | + if (S_ISLNK(file->mode)) |
05b88206 | 428 | + return 1; |
8db8e7d2 WD |
429 | + |
430 | + curr_racl = &_curr_rsync_acls[0]; | |
431 | + type = SMB_ACL_TYPE_ACCESS; | |
432 | + do { | |
fa26e11c WD |
433 | + SMB_ACL_T sacl; |
434 | + BOOL ok; | |
8db8e7d2 | 435 | + if ((sacl = sys_acl_get_file(fname, type)) != 0) { |
b8fc785b WD |
436 | + ok = unpack_smb_acl(curr_racl, sacl); |
437 | + sys_acl_free_acl(sacl); | |
438 | + if (!ok) | |
439 | + return -1; | |
c6437996 | 440 | + /* Strip access ACLs of permission-bit entries. */ |
a5e3a4cc | 441 | + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1) |
c6437996 | 442 | + rsync_acl_strip_perms(curr_racl); |
b8fc785b | 443 | + } else if (errno == ENOTSUP) { |
c6437996 | 444 | + /* ACLs are not supported. Leave list empty. */ |
ad625644 | 445 | + *curr_racl = rsync_acl_initializer; |
b8fc785b | 446 | + } else { |
c171f097 | 447 | + rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n", |
8db8e7d2 | 448 | + fname, str_acl_type(type), strerror(errno)); |
05b88206 | 449 | + return -1; |
fa26e11c | 450 | + } |
8db8e7d2 WD |
451 | + curr_racl++; |
452 | + } while (BUMP_TYPE(type) && S_ISDIR(file->mode)); | |
453 | + | |
05b88206 | 454 | + return 0; |
fa26e11c WD |
455 | +} |
456 | + | |
4edb99c8 WD |
457 | +/* Send the make_acl()-generated ACLs for this flist entry, |
458 | + * or clean up after an flist entry that's not being sent (f == -1). */ | |
fa26e11c WD |
459 | +void send_acl(const struct file_struct *file, int f) |
460 | +{ | |
8db8e7d2 | 461 | + SMB_ACL_TYPE_T type; |
fa26e11c | 462 | + rsync_acl *curr_racl; |
36aa3171 | 463 | + |
162234a7 | 464 | + if (S_ISLNK(file->mode)) |
fa26e11c | 465 | + return; |
162234a7 | 466 | + |
8db8e7d2 WD |
467 | + curr_racl = &_curr_rsync_acls[0]; |
468 | + type = SMB_ACL_TYPE_ACCESS; | |
469 | + do { | |
fa26e11c | 470 | + int index; |
8db8e7d2 | 471 | + rsync_acl_list *racl_list = rsync_acl_lists(type); |
fa26e11c WD |
472 | + if (f == -1) { |
473 | + rsync_acl_free(curr_racl); | |
474 | + continue; | |
475 | + } | |
8db8e7d2 | 476 | + if ((index = find_matching_rsync_acl(type, racl_list, curr_racl)) |
fa26e11c | 477 | + != -1) { |
8db8e7d2 | 478 | + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd'); |
fa26e11c WD |
479 | + write_int(f, index); |
480 | + rsync_acl_free(curr_racl); | |
481 | + } else { | |
8db8e7d2 | 482 | + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D'); |
fa26e11c WD |
483 | + send_rsync_acl(f, curr_racl); |
484 | + expand_rsync_acl_list(racl_list); | |
485 | + racl_list->racls[racl_list->count++] = *curr_racl; | |
486 | + } | |
8db8e7d2 WD |
487 | + curr_racl++; |
488 | + } while (BUMP_TYPE(type) && S_ISDIR(file->mode)); | |
fa26e11c WD |
489 | +} |
490 | + | |
4edb99c8 | 491 | +/* The below stuff is only used by the receiver: */ |
fa26e11c WD |
492 | + |
493 | +/* structure to hold index to rsync_acl_list member corresponding to | |
494 | + * flist->files[i] */ | |
495 | + | |
496 | +typedef struct { | |
497 | + const struct file_struct *file; | |
498 | + int aclidx; | |
499 | +} file_acl_index; | |
500 | + | |
501 | +typedef struct { | |
502 | + size_t count; | |
503 | + size_t malloced; | |
504 | + file_acl_index *fileaclidxs; | |
505 | +} file_acl_index_list; | |
506 | + | |
507 | +static file_acl_index_list _file_acl_index_lists[] = { | |
508 | + {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */ | |
509 | + {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */ | |
510 | +}; | |
511 | + | |
512 | +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type) | |
513 | +{ | |
514 | + return type == SMB_ACL_TYPE_ACCESS ? | |
515 | + &_file_acl_index_lists[0] : &_file_acl_index_lists[1]; | |
516 | +} | |
517 | + | |
518 | +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list) | |
519 | +{ | |
ad625644 | 520 | + /* First time through, 0 <= 0, so list is expanded. */ |
fa26e11c | 521 | + if (fileaclidx_list->malloced <= fileaclidx_list->count) { |
0f6733d8 | 522 | + file_acl_index *new_ptr; |
fa26e11c WD |
523 | + size_t new_size; |
524 | + if (fileaclidx_list->malloced < 1000) | |
0f6733d8 | 525 | + new_size = fileaclidx_list->malloced + 1000; |
fa26e11c | 526 | + else |
0f6733d8 WD |
527 | + new_size = fileaclidx_list->malloced * 2; |
528 | + new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size); | |
fa26e11c WD |
529 | + if (verbose >= 3) { |
530 | + rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n", | |
0f6733d8 | 531 | + (double) new_size * sizeof fileaclidx_list->fileaclidxs[0], |
fa26e11c WD |
532 | + fileaclidx_list->fileaclidxs ? "" : " not"); |
533 | + } | |
534 | + | |
0f6733d8 WD |
535 | + fileaclidx_list->fileaclidxs = new_ptr; |
536 | + fileaclidx_list->malloced = new_size; | |
fa26e11c WD |
537 | + |
538 | + if (!fileaclidx_list->fileaclidxs) | |
539 | + out_of_memory("expand_file_acl_index_list"); | |
540 | + } | |
541 | +} | |
542 | + | |
fa26e11c WD |
543 | +/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */ |
544 | + | |
545 | +typedef struct { | |
546 | + size_t count; | |
547 | + size_t malloced; | |
548 | + SMB_ACL_T *sacls; | |
549 | +} smb_acl_list; | |
550 | + | |
551 | +static smb_acl_list _smb_acl_lists[] = { | |
552 | + { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */ | |
553 | + { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */ | |
554 | +}; | |
555 | + | |
556 | +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type) | |
557 | +{ | |
558 | + return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] : | |
559 | + &_smb_acl_lists[1]; | |
560 | +} | |
561 | + | |
562 | +static void expand_smb_acl_list(smb_acl_list *sacl_list) | |
563 | +{ | |
ad625644 | 564 | + /* First time through, 0 <= 0, so list is expanded. */ |
fa26e11c | 565 | + if (sacl_list->malloced <= sacl_list->count) { |
0f6733d8 | 566 | + SMB_ACL_T *new_ptr; |
fa26e11c WD |
567 | + size_t new_size; |
568 | + if (sacl_list->malloced < 1000) | |
0f6733d8 | 569 | + new_size = sacl_list->malloced + 1000; |
fa26e11c | 570 | + else |
0f6733d8 WD |
571 | + new_size = sacl_list->malloced * 2; |
572 | + new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size); | |
fa26e11c WD |
573 | + if (verbose >= 3) { |
574 | + rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n", | |
0f6733d8 | 575 | + (double) new_size * sizeof sacl_list->sacls[0], |
fa26e11c WD |
576 | + sacl_list->sacls ? "" : " not"); |
577 | + } | |
578 | + | |
0f6733d8 WD |
579 | + sacl_list->sacls = new_ptr; |
580 | + sacl_list->malloced = new_size; | |
fa26e11c WD |
581 | + |
582 | + if (!sacl_list->sacls) | |
583 | + out_of_memory("expand_smb_acl_list"); | |
584 | + } | |
585 | +} | |
586 | + | |
0e879f7f | 587 | +#define CALL_OR_ERROR(func,args,str) \ |
c6437996 WD |
588 | + do { \ |
589 | + if (func args) { \ | |
0e879f7f | 590 | + errfun = str; \ |
c6437996 WD |
591 | + goto error_exit; \ |
592 | + } \ | |
593 | + } while (0) | |
594 | + | |
0e879f7f WD |
595 | +#define COE(func,args) CALL_OR_ERROR(func,args,#func) |
596 | +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL) | |
597 | + | |
598 | +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry) | |
fa26e11c | 599 | +{ |
c6437996 WD |
600 | + const char *errfun = NULL; |
601 | + SMB_ACL_PERMSET_T permset; | |
602 | + | |
603 | + COE( sys_acl_get_permset,(entry, &permset) ); | |
604 | + COE( sys_acl_clear_perms,(permset) ); | |
605 | + if (access & 4) | |
606 | + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) ); | |
607 | + if (access & 2) | |
608 | + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) ); | |
609 | + if (access & 1) | |
610 | + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) ); | |
611 | + COE( sys_acl_set_permset,(entry, permset) ); | |
612 | + | |
0e879f7f | 613 | + return 0; |
c6437996 | 614 | + |
0e879f7f | 615 | + error_exit: |
c6437996 WD |
616 | + rprintf(FERROR, "store_access_in_entry %s(): %s\n", errfun, |
617 | + strerror(errno)); | |
0e879f7f | 618 | + return -1; |
fa26e11c | 619 | +} |
fa26e11c WD |
620 | + |
621 | +/* build an SMB_ACL_T corresponding to an rsync_acl */ | |
c6437996 | 622 | +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl) |
fa26e11c | 623 | +{ |
c6437996 WD |
624 | + size_t count; |
625 | + id_access *ida; | |
fa26e11c | 626 | + const char *errfun = NULL; |
c6437996 | 627 | + SMB_ACL_ENTRY_T entry; |
69aaf170 | 628 | + |
c6437996 | 629 | + if (!(*smb_acl = sys_acl_init(rsync_acl_count_entries(racl)))) { |
69aaf170 | 630 | + rprintf(FERROR, "pack_smb_acl: sys_acl_init(): %s\n", |
fa26e11c WD |
631 | + strerror(errno)); |
632 | + return False; | |
633 | + } | |
69aaf170 | 634 | + |
c6437996 WD |
635 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
636 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) ); | |
0e879f7f | 637 | + COE2( store_access_in_entry,(racl->user_obj, entry) ); |
c6437996 WD |
638 | + |
639 | + for (ida = racl->users.idas, count = racl->users.count; | |
640 | + count--; ida++) { | |
641 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); | |
642 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) ); | |
643 | + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) ); | |
0e879f7f | 644 | + COE2( store_access_in_entry,(ida->access, entry) ); |
c6437996 WD |
645 | + } |
646 | + | |
647 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); | |
648 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) ); | |
0e879f7f | 649 | + COE2( store_access_in_entry,(racl->group_obj, entry) ); |
c6437996 WD |
650 | + |
651 | + for (ida = racl->groups.idas, count = racl->groups.count; | |
652 | + count--; ida++) { | |
653 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); | |
654 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) ); | |
655 | + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) ); | |
0e879f7f | 656 | + COE2( store_access_in_entry,(ida->access, entry) ); |
c6437996 WD |
657 | + } |
658 | + if (racl->mask != NO_ENTRY) { | |
659 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); | |
660 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) ); | |
0e879f7f | 661 | + COE2( store_access_in_entry,(racl->mask, entry) ); |
c6437996 WD |
662 | + } |
663 | + | |
664 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); | |
665 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) ); | |
0e879f7f | 666 | + COE2( store_access_in_entry,(racl->other, entry) ); |
c6437996 WD |
667 | + |
668 | +#ifdef DEBUG | |
669 | + if (sys_acl_valid(*smb_acl) < 0) | |
670 | + rprintf(FINFO, "pack_smb_acl: warning: system says the ACL I packed is invalid\n"); | |
671 | +#endif | |
672 | + | |
673 | + return True; | |
674 | + | |
0e879f7f WD |
675 | + error_exit: |
676 | + if (errfun) { | |
677 | + rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun, | |
678 | + strerror(errno)); | |
679 | + } | |
c6437996 WD |
680 | + sys_acl_free_acl(*smb_acl); |
681 | + return False; | |
682 | +} | |
683 | + | |
684 | +static mode_t change_sacl_perms(SMB_ACL_T sacl, uchar mask, mode_t old_mode, mode_t mode) | |
685 | +{ | |
686 | + SMB_ACL_ENTRY_T entry; | |
687 | + int group_id = mask != NO_ENTRY ? SMB_ACL_MASK : SMB_ACL_GROUP_OBJ; | |
688 | + const char *errfun; | |
689 | + int rc; | |
690 | + | |
691 | + if (S_ISDIR(mode)) { | |
692 | + /* If the sticky bit is going on, it's not safe to allow all | |
693 | + * the new ACLs to go into effect before it gets set. */ | |
53c1073a WD |
694 | +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS |
695 | + if (mode & S_ISVTX) | |
696 | + mode &= ~0077; | |
697 | +#else | |
0e879f7f | 698 | + if (mode & S_ISVTX && !(old_mode & S_ISVTX)) |
c6437996 WD |
699 | + mode &= ~0077; |
700 | + } else { | |
701 | + /* If setuid or setgid is going off, it's not safe to allow all | |
702 | + * the new ACLs to go into effect before they get cleared. */ | |
703 | + if ((old_mode & S_ISUID && !(mode & S_ISUID)) | |
704 | + || (old_mode & S_ISGID && !(mode & S_ISGID))) | |
705 | + mode &= ~0077; | |
53c1073a | 706 | +#endif |
c6437996 WD |
707 | + } |
708 | + | |
709 | + errfun = "sys_acl_get_entry"; | |
710 | + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry); | |
711 | + rc == 1; | |
712 | + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) { | |
713 | + SMB_ACL_TAG_T tag_type; | |
714 | + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) { | |
715 | + errfun = "sys_acl_get_tag_type"; | |
fa26e11c WD |
716 | + break; |
717 | + } | |
c6437996 | 718 | + if (tag_type == SMB_ACL_USER_OBJ) |
0e879f7f | 719 | + COE2( store_access_in_entry,((mode >> 6) & 7, entry) ); |
c6437996 | 720 | + else if (tag_type == group_id) |
0e879f7f | 721 | + COE2( store_access_in_entry,((mode >> 3) & 7, entry) ); |
c6437996 | 722 | + else if (tag_type == SMB_ACL_OTHER) |
0e879f7f | 723 | + COE2( store_access_in_entry,(mode & 7, entry) ); |
fa26e11c | 724 | + } |
c6437996 | 725 | + if (rc) { |
0e879f7f WD |
726 | + error_exit: |
727 | + if (errfun) { | |
728 | + rprintf(FERROR, "change_sacl_perms: %s(): %s\n", | |
729 | + errfun, strerror(errno)); | |
730 | + } | |
731 | + return ~0u; | |
fa26e11c | 732 | + } |
c6437996 | 733 | + |
53c1073a WD |
734 | +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS |
735 | + /* Ensure that chmod() will be called to restore any lost setid bits. */ | |
736 | + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX) | |
737 | + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS)) | |
738 | + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX); | |
739 | +#endif | |
740 | + | |
0e879f7f | 741 | + /* Return the mode of the file on disk, as we will set them. */ |
c6437996 | 742 | + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS); |
fa26e11c WD |
743 | +} |
744 | + | |
34a409bc | 745 | +static void receive_rsync_acl(rsync_acl *racl, int f) |
fa26e11c | 746 | +{ |
090d78e1 | 747 | + uchar computed_mask_bits = 0; |
c6437996 WD |
748 | + ida_list *idal = NULL; |
749 | + id_access *ida; | |
ad625644 WD |
750 | + size_t count; |
751 | + | |
c6437996 WD |
752 | + *racl = rsync_acl_initializer; |
753 | + | |
ad625644 | 754 | + if (!(count = read_int(f))) |
fa26e11c | 755 | + return; |
ad625644 | 756 | + |
fa26e11c | 757 | + while (count--) { |
dfadc68a | 758 | + char tag = read_byte(f); |
c6437996 WD |
759 | + uchar access = read_byte(f); |
760 | + if (access & ~ (4 | 2 | 1)) { | |
761 | + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n", | |
762 | + access); | |
763 | + exit_cleanup(RERR_STREAMIO); | |
764 | + } | |
fa26e11c WD |
765 | + switch (tag) { |
766 | + case 'u': | |
c6437996 WD |
767 | + if (racl->user_obj != NO_ENTRY) { |
768 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n"); | |
769 | + exit_cleanup(RERR_STREAMIO); | |
770 | + } | |
771 | + racl->user_obj = access; | |
772 | + continue; | |
fa26e11c | 773 | + case 'U': |
c6437996 | 774 | + idal = &racl->users; |
fa26e11c WD |
775 | + break; |
776 | + case 'g': | |
c6437996 WD |
777 | + if (racl->group_obj != NO_ENTRY) { |
778 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n"); | |
779 | + exit_cleanup(RERR_STREAMIO); | |
780 | + } | |
781 | + racl->group_obj = access; | |
782 | + continue; | |
fa26e11c | 783 | + case 'G': |
c6437996 | 784 | + idal = &racl->groups; |
fa26e11c WD |
785 | + break; |
786 | + case 'm': | |
c6437996 WD |
787 | + if (racl->mask != NO_ENTRY) { |
788 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n"); | |
789 | + exit_cleanup(RERR_STREAMIO); | |
790 | + } | |
791 | + racl->mask = access; | |
792 | + continue; | |
793 | + case 'o': | |
794 | + if (racl->other != NO_ENTRY) { | |
795 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n"); | |
796 | + exit_cleanup(RERR_STREAMIO); | |
797 | + } | |
798 | + racl->other = access; | |
799 | + continue; | |
fa26e11c WD |
800 | + default: |
801 | + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n", | |
802 | + tag); | |
803 | + exit_cleanup(RERR_STREAMIO); | |
804 | + } | |
c6437996 WD |
805 | + expand_ida_list(idal); |
806 | + ida = &idal->idas[idal->count++]; | |
807 | + ida->access = access; | |
808 | + ida->id = read_int(f); | |
090d78e1 | 809 | + computed_mask_bits |= access; |
c6437996 WD |
810 | + } |
811 | + | |
812 | + /* Ensure that these are never unset. */ | |
813 | + if (racl->user_obj == NO_ENTRY) | |
814 | + racl->user_obj = 7; | |
815 | + if (racl->group_obj == NO_ENTRY) | |
816 | + racl->group_obj = 0; | |
817 | + if (racl->other == NO_ENTRY) | |
818 | + racl->other = 0; | |
819 | +#ifndef ACLS_NEED_MASK | |
820 | + if (!racl->users.count && !racl->groups.count) { | |
821 | + /* If we, a system without ACLS_NEED_MASK, received a | |
822 | + * superfluous mask, throw it away. */ | |
823 | + if (racl->mask != NO_ENTRY) { | |
824 | + /* mask off group perms with it first */ | |
825 | + racl->group_obj &= racl->mask; | |
826 | + racl->mask = NO_ENTRY; | |
fa26e11c | 827 | + } |
c6437996 | 828 | + } else |
34a409bc | 829 | +#endif |
c6437996 | 830 | + if (racl->mask == NO_ENTRY) |
090d78e1 | 831 | + racl->mask = computed_mask_bits | racl->group_obj; |
fa26e11c WD |
832 | +} |
833 | + | |
834 | +/* receive and build the rsync_acl_lists */ | |
fa26e11c WD |
835 | +void receive_acl(struct file_struct *file, int f) |
836 | +{ | |
8db8e7d2 | 837 | + SMB_ACL_TYPE_T type; |
fa26e11c | 838 | + char *fname; |
36aa3171 | 839 | + |
162234a7 | 840 | + if (S_ISLNK(file->mode)) |
fa26e11c | 841 | + return; |
36aa3171 | 842 | + |
bd68c3c2 | 843 | + fname = f_name(file, NULL); |
8db8e7d2 WD |
844 | + type = SMB_ACL_TYPE_ACCESS; |
845 | + do { | |
fa26e11c | 846 | + file_acl_index_list *fileaclidx_list = |
8db8e7d2 | 847 | + file_acl_index_lists(type); |
dfadc68a | 848 | + char tag; |
fa26e11c WD |
849 | + expand_file_acl_index_list(fileaclidx_list); |
850 | + | |
851 | + tag = read_byte(f); | |
852 | + if (tag == 'A' || tag == 'a') { | |
8db8e7d2 | 853 | + if (type != SMB_ACL_TYPE_ACCESS) { |
fa26e11c WD |
854 | + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n", |
855 | + fname); | |
856 | + exit_cleanup(RERR_STREAMIO); | |
857 | + } | |
858 | + } else if (tag == 'D' || tag == 'd') { | |
8db8e7d2 | 859 | + if (type == SMB_ACL_TYPE_ACCESS) { |
fa26e11c WD |
860 | + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n", |
861 | + fname); | |
862 | + exit_cleanup(RERR_STREAMIO); | |
863 | + } | |
864 | + } else { | |
865 | + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n", | |
866 | + fname, tag); | |
867 | + exit_cleanup(RERR_STREAMIO); | |
868 | + } | |
869 | + if (tag == 'A' || tag == 'D') { | |
c6437996 | 870 | + rsync_acl racl; |
8db8e7d2 WD |
871 | + rsync_acl_list *racl_list = rsync_acl_lists(type); |
872 | + smb_acl_list *sacl_list = smb_acl_lists(type); | |
fa26e11c WD |
873 | + fileaclidx_list->fileaclidxs[fileaclidx_list->count]. |
874 | + aclidx = racl_list->count; | |
875 | + fileaclidx_list->fileaclidxs[fileaclidx_list->count++]. | |
876 | + file = file; | |
34a409bc | 877 | + receive_rsync_acl(&racl, f); |
fa26e11c WD |
878 | + expand_rsync_acl_list(racl_list); |
879 | + racl_list->racls[racl_list->count++] = racl; | |
880 | + expand_smb_acl_list(sacl_list); | |
881 | + sacl_list->sacls[sacl_list->count++] = NULL; | |
882 | + } else { | |
883 | + int index = read_int(f); | |
8db8e7d2 | 884 | + rsync_acl_list *racl_list = rsync_acl_lists(type); |
fa26e11c WD |
885 | + if ((size_t) index >= racl_list->count) { |
886 | + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n", | |
887 | + fname, | |
8db8e7d2 | 888 | + str_acl_type(type), |
fa26e11c WD |
889 | + index); |
890 | + exit_cleanup(RERR_STREAMIO); | |
891 | + } | |
892 | + fileaclidx_list->fileaclidxs[fileaclidx_list->count]. | |
893 | + aclidx = index; | |
894 | + fileaclidx_list->fileaclidxs[fileaclidx_list->count++]. | |
895 | + file = file; | |
896 | + } | |
8db8e7d2 | 897 | + } while (BUMP_TYPE(type) && S_ISDIR(file->mode)); |
fa26e11c WD |
898 | +} |
899 | + | |
900 | +static int file_acl_index_list_sorter(const void *f1, const void *f2) | |
901 | +{ | |
902 | + const file_acl_index *fileaclidx1 = (const file_acl_index *)f1; | |
903 | + const file_acl_index *fileaclidx2 = (const file_acl_index *)f2; | |
904 | + return fileaclidx1->file == fileaclidx2->file ? 0 : | |
905 | + fileaclidx1->file < fileaclidx2->file ? -1 : 1; | |
906 | +} | |
907 | + | |
908 | +void sort_file_acl_index_lists() | |
909 | +{ | |
8db8e7d2 | 910 | + SMB_ACL_TYPE_T type; |
36aa3171 | 911 | + |
8db8e7d2 WD |
912 | + type = SMB_ACL_TYPE_ACCESS; |
913 | + do { | |
fa26e11c | 914 | + file_acl_index_list *fileaclidx_list = |
8db8e7d2 | 915 | + file_acl_index_lists(type); |
fa26e11c WD |
916 | + if (!fileaclidx_list->count) |
917 | + continue; | |
918 | + qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count, | |
919 | + sizeof fileaclidx_list->fileaclidxs[0], | |
920 | + &file_acl_index_list_sorter); | |
8db8e7d2 | 921 | + } while (BUMP_TYPE(type)); |
fa26e11c WD |
922 | +} |
923 | + | |
924 | +static int find_file_acl_index(const file_acl_index_list *fileaclidx_list, | |
925 | + const struct file_struct *file) { | |
926 | + int low = 0, high = fileaclidx_list->count; | |
927 | + const struct file_struct *file_mid; | |
928 | + if (!high--) | |
929 | + return -1; | |
930 | + do { | |
931 | + int mid = (high + low) / 2; | |
932 | + file_mid = fileaclidx_list->fileaclidxs[mid].file; | |
933 | + if (file_mid == file) | |
934 | + return fileaclidx_list->fileaclidxs[mid].aclidx; | |
935 | + if (file_mid > file) | |
936 | + high = mid - 1; | |
937 | + else | |
938 | + low = mid + 1; | |
939 | + } while (low < high); | |
940 | + if (low == high) { | |
941 | + file_mid = fileaclidx_list->fileaclidxs[low].file; | |
942 | + if (file_mid == file) | |
943 | + return fileaclidx_list->fileaclidxs[low].aclidx; | |
944 | + } | |
945 | + rprintf(FERROR, | |
946 | + "find_file_acl_index: can't find entry for file in list\n"); | |
947 | + exit_cleanup(RERR_STREAMIO); | |
948 | + return -1; | |
949 | +} | |
950 | + | |
951 | +/* for duplicating ACLs on backups when using backup_dir */ | |
fa26e11c WD |
952 | +int dup_acl(const char *orig, const char *bak, mode_t mode) |
953 | +{ | |
8db8e7d2 | 954 | + SMB_ACL_TYPE_T type; |
fa26e11c | 955 | + int ret = 0; |
36aa3171 | 956 | + |
8db8e7d2 WD |
957 | + type = SMB_ACL_TYPE_ACCESS; |
958 | + do { | |
fa26e11c WD |
959 | + SMB_ACL_T sacl_orig, sacl_bak; |
960 | + rsync_acl racl_orig, racl_bak; | |
8db8e7d2 | 961 | + if (!(sacl_orig = sys_acl_get_file(orig, type))) { |
c171f097 | 962 | + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n", |
8db8e7d2 | 963 | + orig, str_acl_type(type), strerror(errno)); |
fa26e11c WD |
964 | + ret = -1; |
965 | + continue; | |
966 | + } | |
8db8e7d2 | 967 | + if (!(sacl_bak = sys_acl_get_file(orig, type))) { |
c171f097 | 968 | + rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n", |
8db8e7d2 | 969 | + bak, str_acl_type(type), strerror(errno)); |
fa26e11c WD |
970 | + ret = -1; |
971 | + /* try to forge on through */ | |
972 | + } | |
973 | + if (!unpack_smb_acl(&racl_orig, sacl_orig)) { | |
974 | + ret = -1; | |
975 | + goto out_with_sacls; | |
976 | + } | |
977 | + if (sacl_bak) { | |
978 | + if (!unpack_smb_acl(&racl_bak, sacl_bak)) { | |
979 | + ret = -1; | |
980 | + goto out_with_one_racl; | |
981 | + } | |
982 | + if (rsync_acls_equal(&racl_orig, &racl_bak)) | |
983 | + goto out_with_all; | |
984 | + } else { | |
985 | + ; /* presume they're unequal */ | |
986 | + } | |
c6437996 WD |
987 | + if (type == SMB_ACL_TYPE_DEFAULT |
988 | + && rsync_acl_count_entries(&racl_orig) == 0) { | |
e6a7303b | 989 | + if (sys_acl_delete_def_file(bak) < 0) { |
fa26e11c WD |
990 | + rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n", |
991 | + bak, strerror(errno)); | |
992 | + ret = -1; | |
993 | + } | |
8db8e7d2 | 994 | + } else if (sys_acl_set_file(bak, type, sacl_bak) < 0) { |
c171f097 | 995 | + rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n", |
8db8e7d2 | 996 | + bak, str_acl_type(type), strerror(errno)); |
fa26e11c WD |
997 | + ret = -1; |
998 | + } | |
999 | + out_with_all: | |
1000 | + if (sacl_bak) | |
1001 | + rsync_acl_free(&racl_bak); | |
1002 | + out_with_one_racl: | |
1003 | + rsync_acl_free(&racl_orig); | |
1004 | + out_with_sacls: | |
1005 | + if (sacl_bak) | |
1006 | + sys_acl_free_acl(sacl_bak); | |
1007 | + /* out_with_one_sacl: */ | |
1008 | + if (sacl_orig) | |
1009 | + sys_acl_free_acl(sacl_orig); | |
8db8e7d2 WD |
1010 | + } while (BUMP_TYPE(type) && S_ISDIR(mode)); |
1011 | + | |
fa26e11c WD |
1012 | + return ret; |
1013 | +} | |
1014 | + | |
90fa6d68 | 1015 | +/* Stuff for redirecting calls to set_acl() from set_file_attrs() |
4edb99c8 | 1016 | + * for keep_backup(). */ |
fa26e11c WD |
1017 | +static const struct file_struct *backup_orig_file = NULL; |
1018 | +static const char null_string[] = ""; | |
1019 | +static const char *backup_orig_fname = null_string; | |
1020 | +static const char *backup_dest_fname = null_string; | |
1021 | +static SMB_ACL_T _backup_sacl[] = { NULL, NULL }; | |
1022 | + | |
1023 | +void push_keep_backup_acl(const struct file_struct *file, | |
1024 | + const char *orig, const char *dest) | |
1025 | +{ | |
8db8e7d2 WD |
1026 | + SMB_ACL_TYPE_T type; |
1027 | + SMB_ACL_T *sacl; | |
1028 | + | |
8db8e7d2 WD |
1029 | + backup_orig_file = file; |
1030 | + backup_orig_fname = orig; | |
1031 | + backup_dest_fname = dest; | |
1032 | + | |
1033 | + sacl = &_backup_sacl[0]; | |
1034 | + type = SMB_ACL_TYPE_ACCESS; | |
1035 | + do { | |
1036 | + if (type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode)) { | |
1037 | + *sacl = NULL; | |
1038 | + break; | |
fa26e11c | 1039 | + } |
8db8e7d2 WD |
1040 | + if (!(*sacl = sys_acl_get_file(orig, type))) { |
1041 | + rprintf(FERROR, | |
1042 | + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n", | |
1043 | + orig, str_acl_type(type), | |
1044 | + strerror(errno)); | |
1045 | + } | |
1046 | + } while (BUMP_TYPE(type)); | |
fa26e11c WD |
1047 | +} |
1048 | + | |
1049 | +static int set_keep_backup_acl() | |
1050 | +{ | |
8db8e7d2 WD |
1051 | + SMB_ACL_TYPE_T type; |
1052 | + SMB_ACL_T *sacl; | |
1053 | + int ret = 0; | |
1054 | + | |
8db8e7d2 WD |
1055 | + sacl = &_backup_sacl[0]; |
1056 | + type = SMB_ACL_TYPE_ACCESS; | |
1057 | + do { | |
1058 | + if (*sacl | |
1059 | + && sys_acl_set_file(backup_dest_fname, type, *sacl) < 0) { | |
1060 | + rprintf(FERROR, | |
1061 | + "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n", | |
1062 | + backup_dest_fname, | |
1063 | + str_acl_type(type), | |
1064 | + strerror(errno)); | |
1065 | + ret = -1; | |
fa26e11c | 1066 | + } |
8db8e7d2 WD |
1067 | + } while (BUMP_TYPE(type)); |
1068 | + | |
1069 | + return ret; | |
fa26e11c WD |
1070 | +} |
1071 | + | |
1072 | +void cleanup_keep_backup_acl() | |
1073 | +{ | |
8db8e7d2 WD |
1074 | + SMB_ACL_TYPE_T type; |
1075 | + SMB_ACL_T *sacl; | |
1076 | + | |
8db8e7d2 WD |
1077 | + backup_orig_file = NULL; |
1078 | + backup_orig_fname = null_string; | |
1079 | + backup_dest_fname = null_string; | |
1080 | + | |
1081 | + sacl = &_backup_sacl[0]; | |
1082 | + type = SMB_ACL_TYPE_ACCESS; | |
1083 | + do { | |
1084 | + if (*sacl) { | |
1085 | + sys_acl_free_acl(*sacl); | |
fa26e11c WD |
1086 | + *sacl = NULL; |
1087 | + } | |
8db8e7d2 | 1088 | + } while (BUMP_TYPE(type)); |
fa26e11c WD |
1089 | +} |
1090 | + | |
c6437996 WD |
1091 | +/* set ACL on rsync-ed or keep_backup-ed file |
1092 | + * | |
1093 | + * This sets extended access ACL entries and default ACLs. If convenient, | |
1094 | + * it sets permission bits along with the access ACLs and signals having | |
53c1073a | 1095 | + * done so by modifying mode_p, which should point into the stat buffer. |
c6437996 WD |
1096 | + * |
1097 | + * returns: 1 for unchanged, 0 for changed, -1 for failed | |
53c1073a WD |
1098 | + * Pass NULL for mode_p to get the return code without changing anything. */ |
1099 | +int set_acl(const char *fname, const struct file_struct *file, mode_t *mode_p) | |
fa26e11c | 1100 | +{ |
81ddc4dc | 1101 | + int unchanged = 1; |
8db8e7d2 | 1102 | + SMB_ACL_TYPE_T type; |
36aa3171 | 1103 | + |
c6437996 WD |
1104 | + if (S_ISLNK(file->mode)) |
1105 | + return 1; | |
36aa3171 | 1106 | + |
fa26e11c WD |
1107 | + if (file == backup_orig_file) { |
1108 | + if (!strcmp(fname, backup_dest_fname)) | |
1109 | + return set_keep_backup_acl(); | |
1110 | + } | |
8db8e7d2 WD |
1111 | + type = SMB_ACL_TYPE_ACCESS; |
1112 | + do { | |
c6437996 | 1113 | + BOOL ok; |
fa26e11c WD |
1114 | + SMB_ACL_T sacl_orig, *sacl_new; |
1115 | + rsync_acl racl_orig, *racl_new; | |
c6437996 WD |
1116 | + int aclidx = find_file_acl_index(file_acl_index_lists(type), file); |
1117 | + | |
8db8e7d2 WD |
1118 | + racl_new = &(rsync_acl_lists(type)->racls[aclidx]); |
1119 | + sacl_new = &(smb_acl_lists(type)->sacls[aclidx]); | |
1120 | + sacl_orig = sys_acl_get_file(fname, type); | |
fa26e11c WD |
1121 | + if (!sacl_orig) { |
1122 | + rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n", | |
8db8e7d2 | 1123 | + fname, str_acl_type(type), strerror(errno)); |
81ddc4dc | 1124 | + unchanged = -1; |
fa26e11c WD |
1125 | + continue; |
1126 | + } | |
1127 | + ok = unpack_smb_acl(&racl_orig, sacl_orig); | |
1128 | + sys_acl_free_acl(sacl_orig); | |
1129 | + if (!ok) { | |
81ddc4dc | 1130 | + unchanged = -1; |
fa26e11c WD |
1131 | + continue; |
1132 | + } | |
c6437996 WD |
1133 | + if (type == SMB_ACL_TYPE_ACCESS) |
1134 | + ok = rsync_acl_extended_parts_equal(&racl_orig, racl_new); | |
1135 | + else | |
1136 | + ok = rsync_acls_equal(&racl_orig, racl_new); | |
fa26e11c WD |
1137 | + rsync_acl_free(&racl_orig); |
1138 | + if (ok) | |
1139 | + continue; | |
53c1073a | 1140 | + if (!dry_run && mode_p) { |
c6437996 WD |
1141 | + if (type == SMB_ACL_TYPE_DEFAULT |
1142 | + && rsync_acl_count_entries(racl_new) == 0) { | |
1143 | + if (sys_acl_delete_def_file(fname) < 0) { | |
1144 | + rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n", | |
1145 | + fname, strerror(errno)); | |
1146 | + unchanged = -1; | |
1147 | + continue; | |
1148 | + } | |
1149 | + } else { | |
53c1073a | 1150 | + mode_t cur_mode = *mode_p; |
c6437996 WD |
1151 | + if (!*sacl_new |
1152 | + && !pack_smb_acl(sacl_new, racl_new)) { | |
1153 | + unchanged = -1; | |
1154 | + continue; | |
1155 | + } | |
1156 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
1157 | + cur_mode = change_sacl_perms(*sacl_new, racl_new->mask, | |
1158 | + cur_mode, file->mode); | |
0e879f7f WD |
1159 | + if (cur_mode == ~0u) |
1160 | + continue; | |
c6437996 WD |
1161 | + } |
1162 | + if (sys_acl_set_file(fname, type, *sacl_new) < 0) { | |
1163 | + rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n", | |
1164 | + fname, str_acl_type(type), | |
1165 | + strerror(errno)); | |
1166 | + unchanged = -1; | |
1167 | + continue; | |
1168 | + } | |
1169 | + if (type == SMB_ACL_TYPE_ACCESS) | |
53c1073a | 1170 | + *mode_p = cur_mode; |
fa26e11c WD |
1171 | + } |
1172 | + } | |
81ddc4dc WD |
1173 | + if (unchanged == 1) |
1174 | + unchanged = 0; | |
8db8e7d2 WD |
1175 | + } while (BUMP_TYPE(type) && S_ISDIR(file->mode)); |
1176 | + | |
81ddc4dc | 1177 | + return unchanged; |
fa26e11c WD |
1178 | +} |
1179 | + | |
4edb99c8 | 1180 | +/* Enumeration functions for uid mapping: */ |
fa26e11c | 1181 | + |
4edb99c8 WD |
1182 | +/* Context -- one and only one. Should be cycled through once on uid |
1183 | + * mapping and once on gid mapping. */ | |
fa26e11c WD |
1184 | +static rsync_acl_list *_enum_racl_lists[] = { |
1185 | + &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL | |
1186 | +}; | |
1187 | + | |
1188 | +static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0]; | |
1189 | +static size_t enum_racl_index = 0; | |
c6437996 | 1190 | +static size_t enum_ida_index = 0; |
fa26e11c | 1191 | + |
4edb99c8 WD |
1192 | +/* This returns the next tag_type id from the given acl for the next entry, |
1193 | + * or it returns 0 if there are no more tag_type ids in the acl. */ | |
c52977bc | 1194 | +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl) |
fa26e11c | 1195 | +{ |
c6437996 WD |
1196 | + const ida_list *idal = (tag_type == SMB_ACL_USER ? |
1197 | + &racl->users : &racl->groups); | |
1198 | + if (enum_ida_index < idal->count) { | |
1199 | + id_access *ida = &idal->idas[enum_ida_index++]; | |
1200 | + return &ida->id; | |
fa26e11c | 1201 | + } |
c6437996 | 1202 | + enum_ida_index = 0; |
c52977bc | 1203 | + return NULL; |
fa26e11c WD |
1204 | +} |
1205 | + | |
c52977bc | 1206 | +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list) |
fa26e11c WD |
1207 | +{ |
1208 | + for (; enum_racl_index < racl_list->count; enum_racl_index++) { | |
1209 | + rsync_acl *racl = &racl_list->racls[enum_racl_index]; | |
c52977bc | 1210 | + id_t *id = next_ace_id(tag_type, racl); |
fa26e11c WD |
1211 | + if (id) |
1212 | + return id; | |
1213 | + } | |
1214 | + enum_racl_index = 0; | |
c52977bc | 1215 | + return NULL; |
fa26e11c WD |
1216 | +} |
1217 | + | |
c52977bc | 1218 | +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
1219 | +{ |
1220 | + for (; *enum_racl_list; enum_racl_list++) { | |
c52977bc | 1221 | + id_t *id = next_acl_id(tag_type, *enum_racl_list); |
fa26e11c WD |
1222 | + if (id) |
1223 | + return id; | |
1224 | + } | |
1225 | + enum_racl_list = &_enum_racl_lists[0]; | |
c52977bc | 1226 | + return NULL; |
fa26e11c WD |
1227 | +} |
1228 | + | |
c52977bc | 1229 | +id_t *next_acl_uid() |
fa26e11c WD |
1230 | +{ |
1231 | + return next_acl_list_id(SMB_ACL_USER); | |
1232 | +} | |
1233 | + | |
c52977bc | 1234 | +id_t *next_acl_gid() |
fa26e11c WD |
1235 | +{ |
1236 | + return next_acl_list_id(SMB_ACL_GROUP); | |
1237 | +} | |
1238 | + | |
26c810d8 | 1239 | +int default_perms_for_dir(const char *dir) |
90fa6d68 WD |
1240 | +{ |
1241 | + rsync_acl racl; | |
1242 | + SMB_ACL_T sacl; | |
c6437996 | 1243 | + BOOL ok; |
26c810d8 | 1244 | + int perms; |
90fa6d68 WD |
1245 | + |
1246 | + if (dir == NULL) | |
1247 | + dir = "."; | |
26c810d8 | 1248 | + perms = ACCESSPERMS & ~orig_umask; |
90fa6d68 WD |
1249 | + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */ |
1250 | + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT); | |
1251 | + if (sacl == NULL) { | |
1252 | + /* Couldn't get an ACL. Darn. */ | |
1253 | + switch (errno) { | |
1254 | + case ENOTSUP: | |
1255 | + /* ACLs are disabled. We could yell at the user to turn them on, but... */ | |
1256 | + break; | |
1257 | + case ENOENT: | |
1258 | + if (dry_run) { | |
1259 | + /* We're doing a dry run, so the containing directory | |
1260 | + * wasn't actually created. Don't worry about it. */ | |
1261 | + break; | |
1262 | + } | |
1263 | + /* Otherwise fall through. */ | |
1264 | + default: | |
26c810d8 | 1265 | + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n", |
90fa6d68 WD |
1266 | + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno)); |
1267 | + } | |
26c810d8 | 1268 | + return perms; |
90fa6d68 WD |
1269 | + } |
1270 | + | |
1271 | + /* Convert it. */ | |
1272 | + ok = unpack_smb_acl(&racl, sacl); | |
1273 | + sys_acl_free_acl(sacl); | |
1274 | + if (!ok) { | |
26c810d8 WD |
1275 | + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n"); |
1276 | + return perms; | |
90fa6d68 WD |
1277 | + } |
1278 | + | |
c6437996 WD |
1279 | + /* Apply the permission-bit entries of the default ACL, if any. */ |
1280 | + if (rsync_acl_count_entries(&racl) > 0) { | |
1281 | + perms = rsync_acl_get_perms(&racl); | |
1282 | + if (verbose > 2) | |
1283 | + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir); | |
90fa6d68 | 1284 | + } |
c6437996 | 1285 | + |
90fa6d68 | 1286 | + rsync_acl_free(&racl); |
26c810d8 | 1287 | + return perms; |
90fa6d68 WD |
1288 | +} |
1289 | + | |
fa26e11c | 1290 | +#endif /* SUPPORT_ACLS */ |
9a7eef96 WD |
1291 | --- old/backup.c |
1292 | +++ new/backup.c | |
162234a7 WD |
1293 | @@ -28,6 +28,7 @@ extern char *backup_suffix; |
1294 | extern char *backup_dir; | |
1295 | ||
1296 | extern int am_root; | |
1297 | +extern int preserve_acls; | |
1298 | extern int preserve_devices; | |
1299 | extern int preserve_specials; | |
1300 | extern int preserve_links; | |
1301 | @@ -132,6 +133,10 @@ static int make_bak_dir(char *fullpath) | |
fa26e11c WD |
1302 | } else { |
1303 | do_lchown(fullpath, st.st_uid, st.st_gid); | |
1304 | do_chmod(fullpath, st.st_mode); | |
e6a7303b | 1305 | +#ifdef SUPPORT_ACLS |
162234a7 WD |
1306 | + if (preserve_acls) |
1307 | + dup_acl(end, fullpath, st.st_mode); | |
e6a7303b | 1308 | +#endif |
fa26e11c WD |
1309 | } |
1310 | } | |
1311 | *p = '/'; | |
162234a7 | 1312 | @@ -185,6 +190,11 @@ static int keep_backup(char *fname) |
172ad6c3 | 1313 | if (!(buf = get_backup_name(fname))) |
fa26e11c | 1314 | return 0; |
fa26e11c | 1315 | |
e6a7303b | 1316 | +#ifdef SUPPORT_ACLS |
162234a7 WD |
1317 | + if (preserve_acls) |
1318 | + push_keep_backup_acl(file, fname, buf); | |
e6a7303b | 1319 | +#endif |
fa26e11c | 1320 | + |
fa26e11c | 1321 | /* Check to see if this is a device file, or link */ |
90fa6d68 WD |
1322 | if ((am_root && preserve_devices && IS_DEVICE(file->mode)) |
1323 | || (preserve_specials && IS_SPECIAL(file->mode))) { | |
162234a7 | 1324 | @@ -260,6 +270,10 @@ static int keep_backup(char *fname) |
fa26e11c WD |
1325 | } |
1326 | } | |
90fa6d68 | 1327 | set_file_attrs(buf, file, NULL, 0); |
e6a7303b | 1328 | +#ifdef SUPPORT_ACLS |
162234a7 WD |
1329 | + if (preserve_acls) |
1330 | + cleanup_keep_backup_acl(); | |
e6a7303b | 1331 | +#endif |
fa26e11c WD |
1332 | free(file); |
1333 | ||
27a7053c | 1334 | if (verbose > 1) { |
9a7eef96 WD |
1335 | --- old/configure.in |
1336 | +++ new/configure.in | |
afcb578c | 1337 | @@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no |
fa26e11c WD |
1338 | AC_CHECK_LIB(resolv, strcasecmp) |
1339 | fi | |
1340 | ||
1341 | +AC_CHECK_FUNCS(aclsort) | |
1342 | +if test x"$ac_cv_func_aclsort" = x"no"; then | |
1343 | + AC_CHECK_LIB(sec, aclsort) | |
1344 | +fi | |
1345 | + | |
1346 | dnl At the moment we don't test for a broken memcmp(), because all we | |
1347 | dnl need to do is test for equality, not comparison, and it seems that | |
1348 | dnl every platform has a memcmp that can do at least that. | |
afcb578c | 1349 | @@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE) |
fa26e11c WD |
1350 | AC_SUBST(CC_SHOBJ_FLAG) |
1351 | AC_SUBST(BUILD_POPT) | |
125d7fca | 1352 | |
fa26e11c WD |
1353 | +AC_CHECK_HEADERS(sys/acl.h) |
1354 | +AC_CHECK_FUNCS(_acl __acl _facl __facl) | |
1355 | +################################################# | |
1356 | +# check for ACL support | |
1357 | + | |
1358 | +AC_MSG_CHECKING(whether to support ACLs) | |
f787c90c WD |
1359 | +AC_ARG_ENABLE(acl-support, |
1360 | +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]), | |
3b05e91f | 1361 | +[ case "$enableval" in |
fa26e11c WD |
1362 | + yes) |
1363 | + | |
1364 | + case "$host_os" in | |
1365 | + *sysv5*) | |
1366 | + AC_MSG_RESULT(Using UnixWare ACLs) | |
1367 | + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs]) | |
1368 | + ;; | |
53c1073a | 1369 | + *solaris*|*cygwin*) |
fa26e11c WD |
1370 | + AC_MSG_RESULT(Using solaris ACLs) |
1371 | + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs]) | |
1372 | + ;; | |
1373 | + *hpux*) | |
1374 | + AC_MSG_RESULT(Using HPUX ACLs) | |
1375 | + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs]) | |
1376 | + ;; | |
1377 | + *irix*) | |
1378 | + AC_MSG_RESULT(Using IRIX ACLs) | |
1379 | + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs]) | |
1380 | + ;; | |
1381 | + *aix*) | |
1382 | + AC_MSG_RESULT(Using AIX ACLs) | |
1383 | + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs]) | |
1384 | + ;; | |
1385 | + *osf*) | |
1386 | + AC_MSG_RESULT(Using Tru64 ACLs) | |
1387 | + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs]) | |
1388 | + LIBS="$LIBS -lpacl" | |
1389 | + ;; | |
1390 | + *) | |
81549708 | 1391 | + AC_MSG_RESULT(ACLs requested -- running tests) |
fa26e11c WD |
1392 | + AC_CHECK_LIB(acl,acl_get_file) |
1393 | + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[ | |
1394 | + AC_TRY_LINK([#include <sys/types.h> | |
1395 | +#include <sys/acl.h>], | |
1396 | +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);], | |
1397 | +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)]) | |
1398 | + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then | |
1399 | + AC_MSG_RESULT(Using posix ACLs) | |
1400 | + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs]) | |
81549708 | 1401 | + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[ |
fa26e11c WD |
1402 | + AC_TRY_LINK([#include <sys/types.h> |
1403 | +#include <sys/acl.h>], | |
1404 | +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);], | |
1405 | +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)]) | |
81549708 WD |
1406 | + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then |
1407 | + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np]) | |
1408 | + fi | |
1409 | + else | |
1410 | + AC_MSG_ERROR(Failed to find ACL support) | |
fa26e11c WD |
1411 | + fi |
1412 | + ;; | |
1413 | + esac | |
1414 | + ;; | |
1415 | + *) | |
1416 | + AC_MSG_RESULT(no) | |
1417 | + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs]) | |
1418 | + ;; | |
1419 | + esac ], | |
1420 | + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs]) | |
1421 | + AC_MSG_RESULT(no) | |
1422 | +) | |
125d7fca | 1423 | + |
fa26e11c WD |
1424 | AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig]) |
1425 | AC_OUTPUT | |
125d7fca | 1426 | |
9a7eef96 WD |
1427 | --- old/flist.c |
1428 | +++ new/flist.c | |
162234a7 WD |
1429 | @@ -44,6 +44,7 @@ extern int filesfrom_fd; |
1430 | extern int one_file_system; | |
1431 | extern int copy_dirlinks; | |
1432 | extern int keep_dirlinks; | |
1433 | +extern int preserve_acls; | |
1434 | extern int preserve_links; | |
1435 | extern int preserve_hard_links; | |
1436 | extern int preserve_devices; | |
cf51033a WD |
1437 | @@ -970,6 +971,11 @@ static struct file_struct *send_file_nam |
1438 | if (chmod_modes && !S_ISLNK(file->mode)) | |
1439 | file->mode = tweak_mode(file->mode, chmod_modes); | |
1440 | ||
e6a7303b | 1441 | +#ifdef SUPPORT_ACLS |
162234a7 | 1442 | + if (preserve_acls && make_acl(file, fname) < 0) |
4df546eb | 1443 | + return NULL; |
e6a7303b | 1444 | +#endif |
cf51033a WD |
1445 | + |
1446 | maybe_emit_filelist_progress(flist->count + flist_count_offset); | |
fa26e11c | 1447 | |
cf51033a WD |
1448 | flist_expand(flist); |
1449 | @@ -977,6 +983,16 @@ static struct file_struct *send_file_nam | |
fa26e11c WD |
1450 | if (file->basename[0]) { |
1451 | flist->files[flist->count++] = file; | |
e0e47893 | 1452 | send_file_entry(file, f); |
e6a7303b | 1453 | +#ifdef SUPPORT_ACLS |
162234a7 WD |
1454 | + if (preserve_acls) |
1455 | + send_acl(file, f); | |
1456 | +#endif | |
fa26e11c | 1457 | + } else { |
162234a7 | 1458 | +#ifdef SUPPORT_ACLS |
fa26e11c | 1459 | + /* Cleanup unsent ACL(s). */ |
162234a7 WD |
1460 | + if (preserve_acls) |
1461 | + send_acl(file, -1); | |
e6a7303b | 1462 | +#endif |
fa26e11c | 1463 | } |
5e048c14 WD |
1464 | return file; |
1465 | } | |
cf51033a | 1466 | @@ -1365,6 +1381,11 @@ struct file_list *recv_file_list(int f) |
fa26e11c | 1467 | flags |= read_byte(f) << 8; |
618752a7 | 1468 | file = receive_file_entry(flist, flags, f); |
fa26e11c | 1469 | |
e6a7303b | 1470 | +#ifdef SUPPORT_ACLS |
162234a7 WD |
1471 | + if (preserve_acls) |
1472 | + receive_acl(file, f); | |
e6a7303b | 1473 | +#endif |
fa26e11c | 1474 | + |
ae6834e1 | 1475 | if (S_ISREG(file->mode) || S_ISLNK(file->mode)) |
618752a7 | 1476 | stats.total_size += file->length; |
fa26e11c | 1477 | |
cf51033a | 1478 | @@ -1387,6 +1408,11 @@ struct file_list *recv_file_list(int f) |
fa26e11c WD |
1479 | |
1480 | clean_flist(flist, relative_paths, 1); | |
fa26e11c | 1481 | |
e6a7303b | 1482 | +#ifdef SUPPORT_ACLS |
162234a7 WD |
1483 | + if (preserve_acls) |
1484 | + sort_file_acl_index_lists(); | |
e6a7303b | 1485 | +#endif |
125d7fca | 1486 | + |
09fb8f03 | 1487 | if (f >= 0) { |
90fa6d68 WD |
1488 | recv_uid_list(f, flist); |
1489 | ||
9a7eef96 WD |
1490 | --- old/generator.c |
1491 | +++ new/generator.c | |
2578e2b6 | 1492 | @@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus |
1a2fa68f WD |
1493 | extern int max_delete; |
1494 | extern int force_delete; | |
1495 | extern int one_file_system; | |
1496 | +extern mode_t orig_umask; | |
1497 | extern struct stats stats; | |
1498 | extern dev_t filesystem_dev; | |
1499 | extern char *backup_dir; | |
c6437996 WD |
1500 | @@ -321,6 +322,8 @@ static void do_delete_pass(struct file_l |
1501 | ||
1502 | int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st) | |
1503 | { | |
1504 | + /* FIXME: Flag ACL changes. */ | |
1505 | + | |
1506 | if (preserve_perms | |
1507 | && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) | |
1508 | return 0; | |
1509 | @@ -355,6 +358,7 @@ void itemize(struct file_struct *file, i | |
1510 | if (preserve_gid && file->gid != GID_NONE | |
1511 | && st->st_gid != file->gid) | |
1512 | iflags |= ITEM_REPORT_GROUP; | |
1513 | + /* FIXME: Itemize ACL changes. ITEM_REPORT_XATTR? */ | |
1514 | } else | |
1515 | iflags |= ITEM_IS_NEW; | |
1516 | ||
1517 | @@ -753,6 +757,7 @@ static int try_dests_non(struct file_str | |
26c810d8 WD |
1518 | } |
1519 | ||
1520 | static int phase = 0; | |
1521 | +static int dflt_perms; | |
1522 | ||
1523 | /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir, | |
1524 | * make sure it exists, and has the right permissions/timestamp info. For | |
c6437996 | 1525 | @@ -844,6 +849,10 @@ static void recv_generator(char *fname, |
01deb4dc WD |
1526 | } |
1527 | if (fuzzy_basis) | |
63673ef2 | 1528 | need_fuzzy_dirlist = 1; |
26c810d8 | 1529 | +#ifdef SUPPORT_ACLS |
01deb4dc WD |
1530 | + if (!preserve_perms) |
1531 | + dflt_perms = default_perms_for_dir(dn); | |
26c810d8 | 1532 | +#endif |
26c810d8 | 1533 | } |
01deb4dc | 1534 | parent_dirname = dn; |
26c810d8 | 1535 | |
c6437996 | 1536 | @@ -871,7 +880,8 @@ static void recv_generator(char *fname, |
90fa6d68 WD |
1537 | if (!preserve_perms) { |
1538 | int exists = statret == 0 | |
1539 | && S_ISDIR(st.st_mode) == S_ISDIR(file->mode); | |
1540 | - file->mode = dest_mode(file->mode, st.st_mode, exists); | |
26c810d8 WD |
1541 | + file->mode = dest_mode(file->mode, st.st_mode, dflt_perms, |
1542 | + exists); | |
90fa6d68 WD |
1543 | } |
1544 | ||
1545 | if (S_ISDIR(file->mode)) { | |
c6437996 | 1546 | @@ -1343,6 +1353,8 @@ void generate_files(int f_out, struct fi |
26c810d8 WD |
1547 | * notice that and let us know via the redo pipe (or its closing). */ |
1548 | ignore_timeout = 1; | |
1549 | ||
1550 | + dflt_perms = (ACCESSPERMS & ~orig_umask); | |
1551 | + | |
1552 | for (i = 0; i < flist->count; i++) { | |
1553 | struct file_struct *file = flist->files[i]; | |
1554 | ||
9a7eef96 WD |
1555 | --- old/lib/sysacls.c |
1556 | +++ new/lib/sysacls.c | |
53c1073a | 1557 | @@ -0,0 +1,3240 @@ |
fa26e11c | 1558 | +/* |
5ca9317d | 1559 | + Unix SMB/CIFS implementation. |
0f6733d8 WD |
1560 | + Samba system utilities for ACL support. |
1561 | + Copyright (C) Jeremy Allison 2000. | |
fa26e11c WD |
1562 | + |
1563 | + This program is free software; you can redistribute it and/or modify | |
1564 | + it under the terms of the GNU General Public License as published by | |
1565 | + the Free Software Foundation; either version 2 of the License, or | |
1566 | + (at your option) any later version. | |
1567 | + | |
1568 | + This program is distributed in the hope that it will be useful, | |
1569 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1570 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1571 | + GNU General Public License for more details. | |
1572 | + | |
1573 | + You should have received a copy of the GNU General Public License | |
1574 | + along with this program; if not, write to the Free Software | |
1575 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
1576 | +*/ | |
1577 | + | |
0f6733d8 | 1578 | +#include "rsync.h" |
252945ef | 1579 | +#include "sysacls.h" /****** ADDED ******/ |
fa26e11c | 1580 | + |
252945ef | 1581 | +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/ |
0f6733d8 WD |
1582 | +void SAFE_FREE(void *mem) |
1583 | +{ | |
1584 | + if (mem) | |
1585 | + free(mem); | |
1586 | +} | |
fa26e11c | 1587 | + |
5ca9317d WD |
1588 | +char *uidtoname(uid_t uid) |
1589 | +{ | |
1590 | + static char idbuf[12]; | |
1591 | + struct passwd *pw; | |
1592 | + | |
1593 | + if ((pw = getpwuid(uid)) == NULL) { | |
1594 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid); | |
1595 | + return idbuf; | |
1596 | + } | |
1597 | + return pw->pw_name; | |
1598 | +} | |
252945ef | 1599 | +/****** EXTRAS -- END ******/ |
5ca9317d | 1600 | + |
0f6733d8 WD |
1601 | +/* |
1602 | + This file wraps all differing system ACL interfaces into a consistent | |
1603 | + one based on the POSIX interface. It also returns the correct errors | |
1604 | + for older UNIX systems that don't support ACLs. | |
fa26e11c | 1605 | + |
0f6733d8 | 1606 | + The interfaces that each ACL implementation must support are as follows : |
fa26e11c | 1607 | + |
0f6733d8 WD |
1608 | + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
1609 | + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) | |
1610 | + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p | |
1611 | + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) | |
1612 | + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) | |
1613 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
1614 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); | |
1615 | + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
1616 | + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) | |
1617 | + SMB_ACL_T sys_acl_init( int count) | |
1618 | + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) | |
1619 | + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) | |
1620 | + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) | |
1621 | + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) | |
1622 | + int sys_acl_valid( SMB_ACL_T theacl ) | |
1623 | + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
1624 | + int sys_acl_set_fd( int fd, SMB_ACL_T theacl) | |
1625 | + int sys_acl_delete_def_file(const char *path) | |
fa26e11c | 1626 | + |
0f6733d8 WD |
1627 | + This next one is not POSIX complient - but we *have* to have it ! |
1628 | + More POSIX braindamage. | |
fa26e11c | 1629 | + |
0f6733d8 | 1630 | + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 1631 | + |
0f6733d8 WD |
1632 | + The generic POSIX free is the following call. We split this into |
1633 | + several different free functions as we may need to add tag info | |
1634 | + to structures when emulating the POSIX interface. | |
fa26e11c | 1635 | + |
0f6733d8 | 1636 | + int sys_acl_free( void *obj_p) |
fa26e11c | 1637 | + |
0f6733d8 | 1638 | + The calls we actually use are : |
fa26e11c | 1639 | + |
0f6733d8 WD |
1640 | + int sys_acl_free_text(char *text) - free acl_to_text |
1641 | + int sys_acl_free_acl(SMB_ACL_T posix_acl) | |
1642 | + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype) | |
fa26e11c | 1643 | + |
0f6733d8 | 1644 | +*/ |
fa26e11c | 1645 | + |
0f6733d8 | 1646 | +#if defined(HAVE_POSIX_ACLS) |
fa26e11c | 1647 | + |
0f6733d8 | 1648 | +/* Identity mapping - easy. */ |
fa26e11c | 1649 | + |
0f6733d8 | 1650 | +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 1651 | +{ |
0f6733d8 | 1652 | + return acl_get_entry( the_acl, entry_id, entry_p); |
fa26e11c WD |
1653 | +} |
1654 | + | |
0f6733d8 | 1655 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c | 1656 | +{ |
0f6733d8 | 1657 | + return acl_get_tag_type( entry_d, tag_type_p); |
fa26e11c WD |
1658 | +} |
1659 | + | |
0f6733d8 | 1660 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c | 1661 | +{ |
0f6733d8 | 1662 | + return acl_get_permset( entry_d, permset_p); |
fa26e11c WD |
1663 | +} |
1664 | + | |
0f6733d8 | 1665 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 1666 | +{ |
0f6733d8 | 1667 | + return acl_get_qualifier( entry_d); |
fa26e11c WD |
1668 | +} |
1669 | + | |
0f6733d8 | 1670 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 1671 | +{ |
0f6733d8 | 1672 | + return acl_get_file( path_p, type); |
fa26e11c WD |
1673 | +} |
1674 | + | |
1675 | +SMB_ACL_T sys_acl_get_fd(int fd) | |
1676 | +{ | |
1677 | + return acl_get_fd(fd); | |
1678 | +} | |
1679 | + | |
1680 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) | |
1681 | +{ | |
1682 | + return acl_clear_perms(permset); | |
1683 | +} | |
1684 | + | |
0f6733d8 | 1685 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
1686 | +{ |
1687 | + return acl_add_perm(permset, perm); | |
1688 | +} | |
1689 | + | |
0f6733d8 | 1690 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
1691 | +{ |
1692 | +#if defined(HAVE_ACL_GET_PERM_NP) | |
0f6733d8 WD |
1693 | + /* |
1694 | + * Required for TrustedBSD-based ACL implementations where | |
fa26e11c | 1695 | + * non-POSIX.1e functions are denoted by a _np (non-portable) |
0f6733d8 WD |
1696 | + * suffix. |
1697 | + */ | |
fa26e11c WD |
1698 | + return acl_get_perm_np(permset, perm); |
1699 | +#else | |
1700 | + return acl_get_perm(permset, perm); | |
1701 | +#endif | |
1702 | +} | |
1703 | + | |
0f6733d8 | 1704 | +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) |
fa26e11c | 1705 | +{ |
0f6733d8 | 1706 | + return acl_to_text( the_acl, plen); |
fa26e11c WD |
1707 | +} |
1708 | + | |
0f6733d8 | 1709 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
1710 | +{ |
1711 | + return acl_init(count); | |
1712 | +} | |
1713 | + | |
0f6733d8 | 1714 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
1715 | +{ |
1716 | + return acl_create_entry(pacl, pentry); | |
1717 | +} | |
1718 | + | |
0f6733d8 | 1719 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
1720 | +{ |
1721 | + return acl_set_tag_type(entry, tagtype); | |
1722 | +} | |
1723 | + | |
0f6733d8 | 1724 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
1725 | +{ |
1726 | + return acl_set_qualifier(entry, qual); | |
1727 | +} | |
1728 | + | |
0f6733d8 | 1729 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
1730 | +{ |
1731 | + return acl_set_permset(entry, permset); | |
1732 | +} | |
1733 | + | |
0f6733d8 | 1734 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c WD |
1735 | +{ |
1736 | + return acl_valid(theacl); | |
1737 | +} | |
1738 | + | |
1739 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
1740 | +{ | |
1741 | + return acl_set_file(name, acltype, theacl); | |
1742 | +} | |
1743 | + | |
0f6733d8 | 1744 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
1745 | +{ |
1746 | + return acl_set_fd(fd, theacl); | |
1747 | +} | |
1748 | + | |
1749 | +int sys_acl_delete_def_file(const char *name) | |
1750 | +{ | |
1751 | + return acl_delete_def_file(name); | |
1752 | +} | |
1753 | + | |
1754 | +int sys_acl_free_text(char *text) | |
1755 | +{ | |
1756 | + return acl_free(text); | |
1757 | +} | |
1758 | + | |
0f6733d8 | 1759 | +int sys_acl_free_acl(SMB_ACL_T the_acl) |
fa26e11c WD |
1760 | +{ |
1761 | + return acl_free(the_acl); | |
1762 | +} | |
1763 | + | |
1f839b40 | 1764 | +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
1765 | +{ |
1766 | + return acl_free(qual); | |
1767 | +} | |
1768 | + | |
1769 | +#elif defined(HAVE_TRU64_ACLS) | |
0f6733d8 WD |
1770 | +/* |
1771 | + * The interface to DEC/Compaq Tru64 UNIX ACLs | |
fa26e11c WD |
1772 | + * is based on Draft 13 of the POSIX spec which is |
1773 | + * slightly different from the Draft 16 interface. | |
0f6733d8 | 1774 | + * |
fa26e11c WD |
1775 | + * Also, some of the permset manipulation functions |
1776 | + * such as acl_clear_perm() and acl_add_perm() appear | |
1777 | + * to be broken on Tru64 so we have to manipulate | |
0f6733d8 WD |
1778 | + * the permission bits in the permset directly. |
1779 | + */ | |
1780 | +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
fa26e11c | 1781 | +{ |
0f6733d8 | 1782 | + SMB_ACL_ENTRY_T entry; |
fa26e11c WD |
1783 | + |
1784 | + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) { | |
1785 | + return -1; | |
1786 | + } | |
1787 | + | |
1788 | + errno = 0; | |
1789 | + if ((entry = acl_get_entry(the_acl)) != NULL) { | |
1790 | + *entry_p = entry; | |
1791 | + return 1; | |
1792 | + } | |
1793 | + | |
1794 | + return errno ? -1 : 0; | |
1795 | +} | |
1796 | + | |
0f6733d8 | 1797 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c | 1798 | +{ |
0f6733d8 | 1799 | + return acl_get_tag_type( entry_d, tag_type_p); |
fa26e11c WD |
1800 | +} |
1801 | + | |
0f6733d8 | 1802 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c | 1803 | +{ |
0f6733d8 | 1804 | + return acl_get_permset( entry_d, permset_p); |
fa26e11c WD |
1805 | +} |
1806 | + | |
0f6733d8 | 1807 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 1808 | +{ |
0f6733d8 | 1809 | + return acl_get_qualifier( entry_d); |
fa26e11c WD |
1810 | +} |
1811 | + | |
0f6733d8 | 1812 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c WD |
1813 | +{ |
1814 | + return acl_get_file((char *)path_p, type); | |
1815 | +} | |
1816 | + | |
0f6733d8 | 1817 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c WD |
1818 | +{ |
1819 | + return acl_get_fd(fd, ACL_TYPE_ACCESS); | |
1820 | +} | |
1821 | + | |
0f6733d8 | 1822 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
fa26e11c | 1823 | +{ |
0f6733d8 | 1824 | + *permset = 0; /* acl_clear_perm() is broken on Tru64 */ |
fa26e11c WD |
1825 | + |
1826 | + return 0; | |
1827 | +} | |
1828 | + | |
0f6733d8 | 1829 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
1830 | +{ |
1831 | + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) { | |
1832 | + errno = EINVAL; | |
1833 | + return -1; | |
1834 | + } | |
1835 | + | |
0f6733d8 | 1836 | + *permset |= perm; /* acl_add_perm() is broken on Tru64 */ |
fa26e11c WD |
1837 | + |
1838 | + return 0; | |
1839 | +} | |
1840 | + | |
0f6733d8 | 1841 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
1842 | +{ |
1843 | + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */ | |
1844 | +} | |
1845 | + | |
0f6733d8 | 1846 | +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) |
fa26e11c | 1847 | +{ |
0f6733d8 | 1848 | + return acl_to_text( the_acl, plen); |
fa26e11c WD |
1849 | +} |
1850 | + | |
0f6733d8 | 1851 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
1852 | +{ |
1853 | + return acl_init(count); | |
1854 | +} | |
1855 | + | |
0f6733d8 | 1856 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
1857 | +{ |
1858 | + SMB_ACL_ENTRY_T entry; | |
1859 | + | |
1860 | + if ((entry = acl_create_entry(pacl)) == NULL) { | |
1861 | + return -1; | |
1862 | + } | |
1863 | + | |
1864 | + *pentry = entry; | |
1865 | + return 0; | |
1866 | +} | |
1867 | + | |
0f6733d8 | 1868 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
1869 | +{ |
1870 | + return acl_set_tag_type(entry, tagtype); | |
1871 | +} | |
1872 | + | |
0f6733d8 | 1873 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
1874 | +{ |
1875 | + return acl_set_qualifier(entry, qual); | |
1876 | +} | |
1877 | + | |
0f6733d8 | 1878 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
1879 | +{ |
1880 | + return acl_set_permset(entry, permset); | |
1881 | +} | |
1882 | + | |
0f6733d8 | 1883 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c | 1884 | +{ |
0f6733d8 | 1885 | + acl_entry_t entry; |
fa26e11c WD |
1886 | + |
1887 | + return acl_valid(theacl, &entry); | |
1888 | +} | |
1889 | + | |
0f6733d8 | 1890 | +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
fa26e11c WD |
1891 | +{ |
1892 | + return acl_set_file((char *)name, acltype, theacl); | |
1893 | +} | |
1894 | + | |
0f6733d8 | 1895 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
1896 | +{ |
1897 | + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl); | |
1898 | +} | |
1899 | + | |
0f6733d8 | 1900 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
1901 | +{ |
1902 | + return acl_delete_def_file((char *)name); | |
1903 | +} | |
1904 | + | |
0f6733d8 | 1905 | +int sys_acl_free_text(char *text) |
fa26e11c | 1906 | +{ |
0f6733d8 WD |
1907 | + /* |
1908 | + * (void) cast and explicit return 0 are for DEC UNIX | |
1909 | + * which just #defines acl_free_text() to be free() | |
1910 | + */ | |
fa26e11c WD |
1911 | + (void) acl_free_text(text); |
1912 | + return 0; | |
1913 | +} | |
1914 | + | |
0f6733d8 | 1915 | +int sys_acl_free_acl(SMB_ACL_T the_acl) |
fa26e11c WD |
1916 | +{ |
1917 | + return acl_free(the_acl); | |
1918 | +} | |
1919 | + | |
0f6733d8 | 1920 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
1921 | +{ |
1922 | + return acl_free_qualifier(qual, tagtype); | |
1923 | +} | |
1924 | + | |
1925 | +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) | |
1926 | + | |
0f6733d8 WD |
1927 | +/* |
1928 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
1929 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. | |
1930 | + */ | |
fa26e11c | 1931 | + |
0f6733d8 WD |
1932 | +/* |
1933 | + * Note that while this code implements sufficient functionality | |
fa26e11c WD |
1934 | + * to support the sys_acl_* interfaces it does not provide all |
1935 | + * of the semantics of the POSIX ACL interfaces. | |
1936 | + * | |
1937 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned | |
1938 | + * from a call to sys_acl_get_entry() should not be assumed to be | |
1939 | + * valid after calling any of the following functions, which may | |
1940 | + * reorder the entries in the ACL. | |
1941 | + * | |
1942 | + * sys_acl_valid() | |
1943 | + * sys_acl_set_file() | |
1944 | + * sys_acl_set_fd() | |
1945 | + */ | |
1946 | + | |
0f6733d8 WD |
1947 | +/* |
1948 | + * The only difference between Solaris and UnixWare / OpenUNIX is | |
1949 | + * that the #defines for the ACL operations have different names | |
1950 | + */ | |
fa26e11c WD |
1951 | +#if defined(HAVE_UNIXWARE_ACLS) |
1952 | + | |
0f6733d8 WD |
1953 | +#define SETACL ACL_SET |
1954 | +#define GETACL ACL_GET | |
1955 | +#define GETACLCNT ACL_CNT | |
fa26e11c WD |
1956 | + |
1957 | +#endif | |
1958 | + | |
1959 | + | |
0f6733d8 | 1960 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
1961 | +{ |
1962 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
1963 | + errno = EINVAL; | |
1964 | + return -1; | |
1965 | + } | |
1966 | + | |
1967 | + if (entry_p == NULL) { | |
1968 | + errno = EINVAL; | |
1969 | + return -1; | |
1970 | + } | |
1971 | + | |
1972 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
1973 | + acl_d->next = 0; | |
1974 | + } | |
1975 | + | |
1976 | + if (acl_d->next < 0) { | |
1977 | + errno = EINVAL; | |
1978 | + return -1; | |
1979 | + } | |
1980 | + | |
1981 | + if (acl_d->next >= acl_d->count) { | |
1982 | + return 0; | |
1983 | + } | |
1984 | + | |
1985 | + *entry_p = &acl_d->acl[acl_d->next++]; | |
1986 | + | |
1987 | + return 1; | |
1988 | +} | |
1989 | + | |
0f6733d8 | 1990 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
1991 | +{ |
1992 | + *type_p = entry_d->a_type; | |
1993 | + | |
1994 | + return 0; | |
1995 | +} | |
1996 | + | |
0f6733d8 | 1997 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
1998 | +{ |
1999 | + *permset_p = &entry_d->a_perm; | |
2000 | + | |
2001 | + return 0; | |
2002 | +} | |
2003 | + | |
0f6733d8 | 2004 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
2005 | +{ |
2006 | + if (entry_d->a_type != SMB_ACL_USER | |
2007 | + && entry_d->a_type != SMB_ACL_GROUP) { | |
2008 | + errno = EINVAL; | |
2009 | + return NULL; | |
2010 | + } | |
2011 | + | |
2012 | + return &entry_d->a_id; | |
2013 | +} | |
2014 | + | |
0f6733d8 WD |
2015 | +/* |
2016 | + * There is no way of knowing what size the ACL returned by | |
fa26e11c WD |
2017 | + * GETACL will be unless you first call GETACLCNT which means |
2018 | + * making an additional system call. | |
2019 | + * | |
2020 | + * In the hope of avoiding the cost of the additional system | |
2021 | + * call in most cases, we initially allocate enough space for | |
2022 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to | |
2023 | + * be too small then we use GETACLCNT to find out the actual | |
0f6733d8 WD |
2024 | + * size, reallocate the ACL buffer, and then call GETACL again. |
2025 | + */ | |
fa26e11c | 2026 | + |
0f6733d8 | 2027 | +#define INITIAL_ACL_SIZE 16 |
fa26e11c | 2028 | + |
0f6733d8 | 2029 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 2030 | +{ |
0f6733d8 WD |
2031 | + SMB_ACL_T acl_d; |
2032 | + int count; /* # of ACL entries allocated */ | |
2033 | + int naccess; /* # of access ACL entries */ | |
2034 | + int ndefault; /* # of default ACL entries */ | |
fa26e11c WD |
2035 | + |
2036 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
2037 | + errno = EINVAL; | |
2038 | + return NULL; | |
2039 | + } | |
2040 | + | |
2041 | + count = INITIAL_ACL_SIZE; | |
2042 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2043 | + return NULL; | |
2044 | + } | |
2045 | + | |
0f6733d8 WD |
2046 | + /* |
2047 | + * If there isn't enough space for the ACL entries we use | |
fa26e11c WD |
2048 | + * GETACLCNT to determine the actual number of ACL entries |
2049 | + * reallocate and try again. This is in a loop because it | |
2050 | + * is possible that someone else could modify the ACL and | |
2051 | + * increase the number of entries between the call to | |
0f6733d8 WD |
2052 | + * GETACLCNT and the call to GETACL. |
2053 | + */ | |
fa26e11c WD |
2054 | + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0 |
2055 | + && errno == ENOSPC) { | |
2056 | + | |
2057 | + sys_acl_free_acl(acl_d); | |
2058 | + | |
2059 | + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) { | |
2060 | + return NULL; | |
2061 | + } | |
2062 | + | |
2063 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2064 | + return NULL; | |
2065 | + } | |
2066 | + } | |
2067 | + | |
2068 | + if (count < 0) { | |
2069 | + sys_acl_free_acl(acl_d); | |
2070 | + return NULL; | |
2071 | + } | |
2072 | + | |
0f6733d8 WD |
2073 | + /* |
2074 | + * calculate the number of access and default ACL entries | |
fa26e11c WD |
2075 | + * |
2076 | + * Note: we assume that the acl() system call returned a | |
2077 | + * well formed ACL which is sorted so that all of the | |
0f6733d8 WD |
2078 | + * access ACL entries preceed any default ACL entries |
2079 | + */ | |
fa26e11c WD |
2080 | + for (naccess = 0; naccess < count; naccess++) { |
2081 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2082 | + break; | |
2083 | + } | |
2084 | + ndefault = count - naccess; | |
0f6733d8 WD |
2085 | + |
2086 | + /* | |
2087 | + * if the caller wants the default ACL we have to copy | |
fa26e11c | 2088 | + * the entries down to the start of the acl[] buffer |
0f6733d8 WD |
2089 | + * and mask out the ACL_DEFAULT flag from the type field |
2090 | + */ | |
fa26e11c | 2091 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
0f6733d8 | 2092 | + int i, j; |
fa26e11c WD |
2093 | + |
2094 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { | |
2095 | + acl_d->acl[i] = acl_d->acl[j]; | |
2096 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; | |
2097 | + } | |
2098 | + | |
2099 | + acl_d->count = ndefault; | |
2100 | + } else { | |
2101 | + acl_d->count = naccess; | |
2102 | + } | |
2103 | + | |
2104 | + return acl_d; | |
2105 | +} | |
2106 | + | |
0f6733d8 | 2107 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 2108 | +{ |
0f6733d8 WD |
2109 | + SMB_ACL_T acl_d; |
2110 | + int count; /* # of ACL entries allocated */ | |
2111 | + int naccess; /* # of access ACL entries */ | |
fa26e11c WD |
2112 | + |
2113 | + count = INITIAL_ACL_SIZE; | |
2114 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2115 | + return NULL; | |
2116 | + } | |
2117 | + | |
2118 | + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0 | |
2119 | + && errno == ENOSPC) { | |
2120 | + | |
2121 | + sys_acl_free_acl(acl_d); | |
2122 | + | |
2123 | + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) { | |
2124 | + return NULL; | |
2125 | + } | |
2126 | + | |
2127 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2128 | + return NULL; | |
2129 | + } | |
2130 | + } | |
2131 | + | |
2132 | + if (count < 0) { | |
2133 | + sys_acl_free_acl(acl_d); | |
2134 | + return NULL; | |
2135 | + } | |
2136 | + | |
0f6733d8 WD |
2137 | + /* |
2138 | + * calculate the number of access ACL entries | |
2139 | + */ | |
fa26e11c WD |
2140 | + for (naccess = 0; naccess < count; naccess++) { |
2141 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2142 | + break; | |
2143 | + } | |
0f6733d8 | 2144 | + |
fa26e11c WD |
2145 | + acl_d->count = naccess; |
2146 | + | |
2147 | + return acl_d; | |
2148 | +} | |
2149 | + | |
0f6733d8 | 2150 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
2151 | +{ |
2152 | + *permset_d = 0; | |
2153 | + | |
2154 | + return 0; | |
2155 | +} | |
2156 | + | |
0f6733d8 | 2157 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2158 | +{ |
2159 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
2160 | + && perm != SMB_ACL_EXECUTE) { | |
2161 | + errno = EINVAL; | |
2162 | + return -1; | |
2163 | + } | |
2164 | + | |
2165 | + if (permset_d == NULL) { | |
2166 | + errno = EINVAL; | |
2167 | + return -1; | |
2168 | + } | |
2169 | + | |
2170 | + *permset_d |= perm; | |
2171 | + | |
2172 | + return 0; | |
2173 | +} | |
2174 | + | |
0f6733d8 | 2175 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2176 | +{ |
2177 | + return *permset_d & perm; | |
2178 | +} | |
2179 | + | |
0f6733d8 | 2180 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c | 2181 | +{ |
0f6733d8 WD |
2182 | + int i; |
2183 | + int len, maxlen; | |
2184 | + char *text; | |
fa26e11c | 2185 | + |
0f6733d8 WD |
2186 | + /* |
2187 | + * use an initial estimate of 20 bytes per ACL entry | |
fa26e11c | 2188 | + * when allocating memory for the text representation |
0f6733d8 WD |
2189 | + * of the ACL |
2190 | + */ | |
2191 | + len = 0; | |
2192 | + maxlen = 20 * acl_d->count; | |
252945ef | 2193 | + if ((text = SMB_MALLOC(maxlen)) == NULL) { |
fa26e11c WD |
2194 | + errno = ENOMEM; |
2195 | + return NULL; | |
2196 | + } | |
2197 | + | |
2198 | + for (i = 0; i < acl_d->count; i++) { | |
0f6733d8 | 2199 | + struct acl *ap = &acl_d->acl[i]; |
0f6733d8 WD |
2200 | + struct group *gr; |
2201 | + char tagbuf[12]; | |
2202 | + char idbuf[12]; | |
2203 | + char *tag; | |
2204 | + char *id = ""; | |
2205 | + char perms[4]; | |
2206 | + int nbytes; | |
fa26e11c WD |
2207 | + |
2208 | + switch (ap->a_type) { | |
0f6733d8 WD |
2209 | + /* |
2210 | + * for debugging purposes it's probably more | |
fa26e11c | 2211 | + * useful to dump unknown tag types rather |
0f6733d8 WD |
2212 | + * than just returning an error |
2213 | + */ | |
fa26e11c | 2214 | + default: |
0f6733d8 | 2215 | + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x", |
fa26e11c WD |
2216 | + ap->a_type); |
2217 | + tag = tagbuf; | |
0f6733d8 | 2218 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
2219 | + (long)ap->a_id); |
2220 | + id = idbuf; | |
2221 | + break; | |
2222 | + | |
2223 | + case SMB_ACL_USER: | |
5ca9317d | 2224 | + id = uidtoname(ap->a_id); |
fa26e11c WD |
2225 | + case SMB_ACL_USER_OBJ: |
2226 | + tag = "user"; | |
2227 | + break; | |
2228 | + | |
2229 | + case SMB_ACL_GROUP: | |
2230 | + if ((gr = getgrgid(ap->a_id)) == NULL) { | |
0f6733d8 | 2231 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
2232 | + (long)ap->a_id); |
2233 | + id = idbuf; | |
2234 | + } else { | |
2235 | + id = gr->gr_name; | |
2236 | + } | |
2237 | + case SMB_ACL_GROUP_OBJ: | |
2238 | + tag = "group"; | |
2239 | + break; | |
2240 | + | |
2241 | + case SMB_ACL_OTHER: | |
2242 | + tag = "other"; | |
2243 | + break; | |
2244 | + | |
2245 | + case SMB_ACL_MASK: | |
2246 | + tag = "mask"; | |
2247 | + break; | |
2248 | + | |
2249 | + } | |
2250 | + | |
2251 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; | |
2252 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; | |
2253 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; | |
2254 | + perms[3] = '\0'; | |
2255 | + | |
2256 | + /* <tag> : <qualifier> : rwx \n \0 */ | |
2257 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; | |
2258 | + | |
0f6733d8 WD |
2259 | + /* |
2260 | + * If this entry would overflow the buffer | |
fa26e11c WD |
2261 | + * allocate enough additional memory for this |
2262 | + * entry and an estimate of another 20 bytes | |
0f6733d8 WD |
2263 | + * for each entry still to be processed |
2264 | + */ | |
fa26e11c WD |
2265 | + if ((len + nbytes) > maxlen) { |
2266 | + char *oldtext = text; | |
2267 | + | |
2268 | + maxlen += nbytes + 20 * (acl_d->count - i); | |
2269 | + | |
252945ef | 2270 | + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) { |
0f6733d8 | 2271 | + SAFE_FREE(oldtext); |
fa26e11c WD |
2272 | + errno = ENOMEM; |
2273 | + return NULL; | |
2274 | + } | |
2275 | + } | |
2276 | + | |
0f6733d8 | 2277 | + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); |
fa26e11c WD |
2278 | + len += nbytes - 1; |
2279 | + } | |
2280 | + | |
2281 | + if (len_p) | |
2282 | + *len_p = len; | |
2283 | + | |
2284 | + return text; | |
2285 | +} | |
2286 | + | |
0f6733d8 | 2287 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 2288 | +{ |
0f6733d8 | 2289 | + SMB_ACL_T a; |
fa26e11c WD |
2290 | + |
2291 | + if (count < 0) { | |
2292 | + errno = EINVAL; | |
2293 | + return NULL; | |
2294 | + } | |
2295 | + | |
0f6733d8 WD |
2296 | + /* |
2297 | + * note that since the definition of the structure pointed | |
fa26e11c WD |
2298 | + * to by the SMB_ACL_T includes the first element of the |
2299 | + * acl[] array, this actually allocates an ACL with room | |
0f6733d8 WD |
2300 | + * for (count+1) entries |
2301 | + */ | |
53c1073a | 2302 | + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) { |
fa26e11c WD |
2303 | + errno = ENOMEM; |
2304 | + return NULL; | |
2305 | + } | |
2306 | + | |
2307 | + a->size = count + 1; | |
2308 | + a->count = 0; | |
2309 | + a->next = -1; | |
2310 | + | |
2311 | + return a; | |
2312 | +} | |
2313 | + | |
2314 | + | |
0f6733d8 | 2315 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 2316 | +{ |
0f6733d8 WD |
2317 | + SMB_ACL_T acl_d; |
2318 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
2319 | + |
2320 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
2321 | + errno = EINVAL; | |
2322 | + return -1; | |
2323 | + } | |
2324 | + | |
2325 | + if (acl_d->count >= acl_d->size) { | |
2326 | + errno = ENOSPC; | |
2327 | + return -1; | |
2328 | + } | |
2329 | + | |
0f6733d8 WD |
2330 | + entry_d = &acl_d->acl[acl_d->count++]; |
2331 | + entry_d->a_type = 0; | |
2332 | + entry_d->a_id = -1; | |
2333 | + entry_d->a_perm = 0; | |
2334 | + *entry_p = entry_d; | |
fa26e11c WD |
2335 | + |
2336 | + return 0; | |
2337 | +} | |
2338 | + | |
0f6733d8 | 2339 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
2340 | +{ |
2341 | + switch (tag_type) { | |
2342 | + case SMB_ACL_USER: | |
2343 | + case SMB_ACL_USER_OBJ: | |
2344 | + case SMB_ACL_GROUP: | |
2345 | + case SMB_ACL_GROUP_OBJ: | |
2346 | + case SMB_ACL_OTHER: | |
2347 | + case SMB_ACL_MASK: | |
2348 | + entry_d->a_type = tag_type; | |
2349 | + break; | |
2350 | + default: | |
2351 | + errno = EINVAL; | |
2352 | + return -1; | |
2353 | + } | |
2354 | + | |
2355 | + return 0; | |
2356 | +} | |
2357 | + | |
0f6733d8 | 2358 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
2359 | +{ |
2360 | + if (entry_d->a_type != SMB_ACL_GROUP | |
2361 | + && entry_d->a_type != SMB_ACL_USER) { | |
2362 | + errno = EINVAL; | |
2363 | + return -1; | |
2364 | + } | |
2365 | + | |
2366 | + entry_d->a_id = *((id_t *)qual_p); | |
2367 | + | |
2368 | + return 0; | |
2369 | +} | |
2370 | + | |
0f6733d8 | 2371 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
2372 | +{ |
2373 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
2374 | + return EINVAL; | |
2375 | + } | |
2376 | + | |
2377 | + entry_d->a_perm = *permset_d; | |
2378 | + | |
2379 | + return 0; | |
2380 | +} | |
2381 | + | |
0f6733d8 WD |
2382 | +/* |
2383 | + * sort the ACL and check it for validity | |
fa26e11c | 2384 | + * |
0f6733d8 | 2385 | + * if it's a minimal ACL with only 4 entries then we |
fa26e11c WD |
2386 | + * need to recalculate the mask permissions to make |
2387 | + * sure that they are the same as the GROUP_OBJ | |
2388 | + * permissions as required by the UnixWare acl() system call. | |
2389 | + * | |
0f6733d8 | 2390 | + * (note: since POSIX allows minimal ACLs which only contain |
fa26e11c WD |
2391 | + * 3 entries - ie there is no mask entry - we should, in theory, |
2392 | + * check for this and add a mask entry if necessary - however | |
2393 | + * we "know" that the caller of this interface always specifies | |
2394 | + * a mask so, in practice "this never happens" (tm) - if it *does* | |
2395 | + * happen aclsort() will fail and return an error and someone will | |
0f6733d8 WD |
2396 | + * have to fix it ...) |
2397 | + */ | |
fa26e11c WD |
2398 | + |
2399 | +static int acl_sort(SMB_ACL_T acl_d) | |
2400 | +{ | |
2401 | + int fixmask = (acl_d->count <= 4); | |
2402 | + | |
2403 | + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) { | |
2404 | + errno = EINVAL; | |
2405 | + return -1; | |
2406 | + } | |
2407 | + return 0; | |
2408 | +} | |
0f6733d8 WD |
2409 | + |
2410 | +int sys_acl_valid(SMB_ACL_T acl_d) | |
fa26e11c WD |
2411 | +{ |
2412 | + return acl_sort(acl_d); | |
2413 | +} | |
2414 | + | |
0f6733d8 | 2415 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c | 2416 | +{ |
0f6733d8 WD |
2417 | + struct stat s; |
2418 | + struct acl *acl_p; | |
2419 | + int acl_count; | |
2420 | + struct acl *acl_buf = NULL; | |
2421 | + int ret; | |
fa26e11c WD |
2422 | + |
2423 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
2424 | + errno = EINVAL; | |
2425 | + return -1; | |
2426 | + } | |
2427 | + | |
2428 | + if (acl_sort(acl_d) != 0) { | |
2429 | + return -1; | |
2430 | + } | |
2431 | + | |
0f6733d8 WD |
2432 | + acl_p = &acl_d->acl[0]; |
2433 | + acl_count = acl_d->count; | |
fa26e11c | 2434 | + |
0f6733d8 WD |
2435 | + /* |
2436 | + * if it's a directory there is extra work to do | |
2437 | + * since the acl() system call will replace both | |
2438 | + * the access ACLs and the default ACLs (if any) | |
2439 | + */ | |
fa26e11c WD |
2440 | + if (stat(name, &s) != 0) { |
2441 | + return -1; | |
2442 | + } | |
2443 | + if (S_ISDIR(s.st_mode)) { | |
0f6733d8 WD |
2444 | + SMB_ACL_T acc_acl; |
2445 | + SMB_ACL_T def_acl; | |
2446 | + SMB_ACL_T tmp_acl; | |
2447 | + int i; | |
fa26e11c WD |
2448 | + |
2449 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
2450 | + acc_acl = acl_d; | |
2451 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); | |
2452 | + | |
2453 | + } else { | |
2454 | + def_acl = acl_d; | |
2455 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); | |
2456 | + } | |
2457 | + | |
2458 | + if (tmp_acl == NULL) { | |
2459 | + return -1; | |
2460 | + } | |
2461 | + | |
0f6733d8 WD |
2462 | + /* |
2463 | + * allocate a temporary buffer for the complete ACL | |
2464 | + */ | |
fa26e11c | 2465 | + acl_count = acc_acl->count + def_acl->count; |
252945ef | 2466 | + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
fa26e11c WD |
2467 | + |
2468 | + if (acl_buf == NULL) { | |
2469 | + sys_acl_free_acl(tmp_acl); | |
2470 | + errno = ENOMEM; | |
2471 | + return -1; | |
2472 | + } | |
2473 | + | |
0f6733d8 WD |
2474 | + /* |
2475 | + * copy the access control and default entries into the buffer | |
2476 | + */ | |
fa26e11c | 2477 | + memcpy(&acl_buf[0], &acc_acl->acl[0], |
0f6733d8 | 2478 | + acc_acl->count * sizeof(acl_buf[0])); |
fa26e11c WD |
2479 | + |
2480 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], | |
0f6733d8 | 2481 | + def_acl->count * sizeof(acl_buf[0])); |
fa26e11c | 2482 | + |
0f6733d8 WD |
2483 | + /* |
2484 | + * set the ACL_DEFAULT flag on the default entries | |
2485 | + */ | |
fa26e11c WD |
2486 | + for (i = acc_acl->count; i < acl_count; i++) { |
2487 | + acl_buf[i].a_type |= ACL_DEFAULT; | |
2488 | + } | |
2489 | + | |
2490 | + sys_acl_free_acl(tmp_acl); | |
2491 | + | |
2492 | + } else if (type != SMB_ACL_TYPE_ACCESS) { | |
2493 | + errno = EINVAL; | |
2494 | + return -1; | |
2495 | + } | |
2496 | + | |
2497 | + ret = acl(name, SETACL, acl_count, acl_p); | |
2498 | + | |
0f6733d8 | 2499 | + SAFE_FREE(acl_buf); |
fa26e11c WD |
2500 | + |
2501 | + return ret; | |
2502 | +} | |
2503 | + | |
0f6733d8 | 2504 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c WD |
2505 | +{ |
2506 | + if (acl_sort(acl_d) != 0) { | |
2507 | + return -1; | |
2508 | + } | |
2509 | + | |
2510 | + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]); | |
2511 | +} | |
2512 | + | |
0f6733d8 | 2513 | +int sys_acl_delete_def_file(const char *path) |
fa26e11c | 2514 | +{ |
0f6733d8 WD |
2515 | + SMB_ACL_T acl_d; |
2516 | + int ret; | |
fa26e11c | 2517 | + |
0f6733d8 WD |
2518 | + /* |
2519 | + * fetching the access ACL and rewriting it has | |
2520 | + * the effect of deleting the default ACL | |
2521 | + */ | |
fa26e11c WD |
2522 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
2523 | + return -1; | |
2524 | + } | |
2525 | + | |
2526 | + ret = acl(path, SETACL, acl_d->count, acl_d->acl); | |
2527 | + | |
2528 | + sys_acl_free_acl(acl_d); | |
0f6733d8 | 2529 | + |
fa26e11c WD |
2530 | + return ret; |
2531 | +} | |
2532 | + | |
0f6733d8 | 2533 | +int sys_acl_free_text(char *text) |
fa26e11c | 2534 | +{ |
0f6733d8 | 2535 | + SAFE_FREE(text); |
fa26e11c WD |
2536 | + return 0; |
2537 | +} | |
2538 | + | |
0f6733d8 | 2539 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c | 2540 | +{ |
0f6733d8 | 2541 | + SAFE_FREE(acl_d); |
fa26e11c WD |
2542 | + return 0; |
2543 | +} | |
2544 | + | |
53c1073a | 2545 | +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
2546 | +{ |
2547 | + return 0; | |
2548 | +} | |
2549 | + | |
2550 | +#elif defined(HAVE_HPUX_ACLS) | |
2551 | +#include <dl.h> | |
2552 | + | |
0f6733d8 WD |
2553 | +/* |
2554 | + * Based on the Solaris/SCO code - with modifications. | |
2555 | + */ | |
fa26e11c | 2556 | + |
0f6733d8 WD |
2557 | +/* |
2558 | + * Note that while this code implements sufficient functionality | |
fa26e11c WD |
2559 | + * to support the sys_acl_* interfaces it does not provide all |
2560 | + * of the semantics of the POSIX ACL interfaces. | |
2561 | + * | |
2562 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned | |
2563 | + * from a call to sys_acl_get_entry() should not be assumed to be | |
2564 | + * valid after calling any of the following functions, which may | |
2565 | + * reorder the entries in the ACL. | |
2566 | + * | |
2567 | + * sys_acl_valid() | |
2568 | + * sys_acl_set_file() | |
2569 | + * sys_acl_set_fd() | |
2570 | + */ | |
2571 | + | |
0f6733d8 WD |
2572 | +/* This checks if the POSIX ACL system call is defined */ |
2573 | +/* which basically corresponds to whether JFS 3.3 or */ | |
2574 | +/* higher is installed. If acl() was called when it */ | |
2575 | +/* isn't defined, it causes the process to core dump */ | |
2576 | +/* so it is important to check this and avoid acl() */ | |
2577 | +/* calls if it isn't there. */ | |
fa26e11c WD |
2578 | + |
2579 | +static BOOL hpux_acl_call_presence(void) | |
2580 | +{ | |
2581 | + | |
2582 | + shl_t handle = NULL; | |
2583 | + void *value; | |
2584 | + int ret_val=0; | |
2585 | + static BOOL already_checked=0; | |
2586 | + | |
0f6733d8 | 2587 | + if(already_checked) |
fa26e11c WD |
2588 | + return True; |
2589 | + | |
2590 | + | |
2591 | + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value); | |
2592 | + | |
0f6733d8 | 2593 | + if(ret_val != 0) { |
fa26e11c WD |
2594 | + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n", |
2595 | + ret_val, errno, strerror(errno))); | |
2596 | + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n")); | |
2597 | + return False; | |
2598 | + } | |
2599 | + | |
2600 | + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n")); | |
2601 | + | |
2602 | + already_checked = True; | |
2603 | + return True; | |
2604 | +} | |
2605 | + | |
0f6733d8 | 2606 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
2607 | +{ |
2608 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
2609 | + errno = EINVAL; | |
2610 | + return -1; | |
2611 | + } | |
2612 | + | |
2613 | + if (entry_p == NULL) { | |
2614 | + errno = EINVAL; | |
2615 | + return -1; | |
2616 | + } | |
2617 | + | |
2618 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
2619 | + acl_d->next = 0; | |
2620 | + } | |
2621 | + | |
2622 | + if (acl_d->next < 0) { | |
2623 | + errno = EINVAL; | |
2624 | + return -1; | |
2625 | + } | |
2626 | + | |
2627 | + if (acl_d->next >= acl_d->count) { | |
2628 | + return 0; | |
2629 | + } | |
2630 | + | |
2631 | + *entry_p = &acl_d->acl[acl_d->next++]; | |
2632 | + | |
2633 | + return 1; | |
2634 | +} | |
2635 | + | |
0f6733d8 | 2636 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
2637 | +{ |
2638 | + *type_p = entry_d->a_type; | |
2639 | + | |
2640 | + return 0; | |
2641 | +} | |
2642 | + | |
0f6733d8 | 2643 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
2644 | +{ |
2645 | + *permset_p = &entry_d->a_perm; | |
2646 | + | |
2647 | + return 0; | |
2648 | +} | |
2649 | + | |
0f6733d8 | 2650 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
2651 | +{ |
2652 | + if (entry_d->a_type != SMB_ACL_USER | |
2653 | + && entry_d->a_type != SMB_ACL_GROUP) { | |
2654 | + errno = EINVAL; | |
2655 | + return NULL; | |
2656 | + } | |
2657 | + | |
2658 | + return &entry_d->a_id; | |
2659 | +} | |
2660 | + | |
0f6733d8 WD |
2661 | +/* |
2662 | + * There is no way of knowing what size the ACL returned by | |
fa26e11c WD |
2663 | + * ACL_GET will be unless you first call ACL_CNT which means |
2664 | + * making an additional system call. | |
2665 | + * | |
2666 | + * In the hope of avoiding the cost of the additional system | |
2667 | + * call in most cases, we initially allocate enough space for | |
2668 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to | |
2669 | + * be too small then we use ACL_CNT to find out the actual | |
2670 | + * size, reallocate the ACL buffer, and then call ACL_GET again. | |
2671 | + */ | |
2672 | + | |
0f6733d8 | 2673 | +#define INITIAL_ACL_SIZE 16 |
fa26e11c | 2674 | + |
0f6733d8 | 2675 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 2676 | +{ |
0f6733d8 WD |
2677 | + SMB_ACL_T acl_d; |
2678 | + int count; /* # of ACL entries allocated */ | |
2679 | + int naccess; /* # of access ACL entries */ | |
2680 | + int ndefault; /* # of default ACL entries */ | |
fa26e11c | 2681 | + |
0f6733d8 WD |
2682 | + if(hpux_acl_call_presence() == False) { |
2683 | + /* Looks like we don't have the acl() system call on HPUX. | |
2684 | + * May be the system doesn't have the latest version of JFS. | |
2685 | + */ | |
2686 | + return NULL; | |
fa26e11c WD |
2687 | + } |
2688 | + | |
2689 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
2690 | + errno = EINVAL; | |
2691 | + return NULL; | |
2692 | + } | |
2693 | + | |
2694 | + count = INITIAL_ACL_SIZE; | |
2695 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2696 | + return NULL; | |
2697 | + } | |
2698 | + | |
0f6733d8 WD |
2699 | + /* |
2700 | + * If there isn't enough space for the ACL entries we use | |
fa26e11c WD |
2701 | + * ACL_CNT to determine the actual number of ACL entries |
2702 | + * reallocate and try again. This is in a loop because it | |
2703 | + * is possible that someone else could modify the ACL and | |
2704 | + * increase the number of entries between the call to | |
0f6733d8 WD |
2705 | + * ACL_CNT and the call to ACL_GET. |
2706 | + */ | |
fa26e11c WD |
2707 | + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) { |
2708 | + | |
2709 | + sys_acl_free_acl(acl_d); | |
2710 | + | |
2711 | + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) { | |
2712 | + return NULL; | |
2713 | + } | |
2714 | + | |
2715 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2716 | + return NULL; | |
2717 | + } | |
2718 | + } | |
2719 | + | |
2720 | + if (count < 0) { | |
2721 | + sys_acl_free_acl(acl_d); | |
2722 | + return NULL; | |
2723 | + } | |
2724 | + | |
0f6733d8 WD |
2725 | + /* |
2726 | + * calculate the number of access and default ACL entries | |
fa26e11c WD |
2727 | + * |
2728 | + * Note: we assume that the acl() system call returned a | |
2729 | + * well formed ACL which is sorted so that all of the | |
0f6733d8 WD |
2730 | + * access ACL entries preceed any default ACL entries |
2731 | + */ | |
fa26e11c WD |
2732 | + for (naccess = 0; naccess < count; naccess++) { |
2733 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2734 | + break; | |
2735 | + } | |
2736 | + ndefault = count - naccess; | |
0f6733d8 WD |
2737 | + |
2738 | + /* | |
2739 | + * if the caller wants the default ACL we have to copy | |
fa26e11c | 2740 | + * the entries down to the start of the acl[] buffer |
0f6733d8 WD |
2741 | + * and mask out the ACL_DEFAULT flag from the type field |
2742 | + */ | |
fa26e11c | 2743 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
0f6733d8 | 2744 | + int i, j; |
fa26e11c WD |
2745 | + |
2746 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { | |
2747 | + acl_d->acl[i] = acl_d->acl[j]; | |
2748 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; | |
2749 | + } | |
2750 | + | |
2751 | + acl_d->count = ndefault; | |
2752 | + } else { | |
2753 | + acl_d->count = naccess; | |
2754 | + } | |
2755 | + | |
2756 | + return acl_d; | |
2757 | +} | |
2758 | + | |
0f6733d8 | 2759 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 2760 | +{ |
0f6733d8 WD |
2761 | + /* |
2762 | + * HPUX doesn't have the facl call. Fake it using the path.... JRA. | |
2763 | + */ | |
fa26e11c WD |
2764 | + |
2765 | + files_struct *fsp = file_find_fd(fd); | |
2766 | + | |
2767 | + if (fsp == NULL) { | |
2768 | + errno = EBADF; | |
2769 | + return NULL; | |
2770 | + } | |
2771 | + | |
0f6733d8 WD |
2772 | + /* |
2773 | + * We know we're in the same conn context. So we | |
2774 | + * can use the relative path. | |
2775 | + */ | |
fa26e11c | 2776 | + |
5ca9317d | 2777 | + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS); |
fa26e11c WD |
2778 | +} |
2779 | + | |
0f6733d8 | 2780 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
2781 | +{ |
2782 | + *permset_d = 0; | |
2783 | + | |
2784 | + return 0; | |
2785 | +} | |
2786 | + | |
0f6733d8 | 2787 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2788 | +{ |
2789 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
2790 | + && perm != SMB_ACL_EXECUTE) { | |
2791 | + errno = EINVAL; | |
2792 | + return -1; | |
2793 | + } | |
2794 | + | |
2795 | + if (permset_d == NULL) { | |
2796 | + errno = EINVAL; | |
2797 | + return -1; | |
2798 | + } | |
2799 | + | |
2800 | + *permset_d |= perm; | |
2801 | + | |
2802 | + return 0; | |
2803 | +} | |
2804 | + | |
0f6733d8 | 2805 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2806 | +{ |
2807 | + return *permset_d & perm; | |
2808 | +} | |
2809 | + | |
0f6733d8 | 2810 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c | 2811 | +{ |
0f6733d8 WD |
2812 | + int i; |
2813 | + int len, maxlen; | |
2814 | + char *text; | |
fa26e11c | 2815 | + |
0f6733d8 WD |
2816 | + /* |
2817 | + * use an initial estimate of 20 bytes per ACL entry | |
2818 | + * when allocating memory for the text representation | |
2819 | + * of the ACL | |
2820 | + */ | |
2821 | + len = 0; | |
2822 | + maxlen = 20 * acl_d->count; | |
252945ef | 2823 | + if ((text = SMB_MALLOC(maxlen)) == NULL) { |
fa26e11c WD |
2824 | + errno = ENOMEM; |
2825 | + return NULL; | |
2826 | + } | |
2827 | + | |
2828 | + for (i = 0; i < acl_d->count; i++) { | |
0f6733d8 | 2829 | + struct acl *ap = &acl_d->acl[i]; |
0f6733d8 WD |
2830 | + struct group *gr; |
2831 | + char tagbuf[12]; | |
2832 | + char idbuf[12]; | |
2833 | + char *tag; | |
2834 | + char *id = ""; | |
2835 | + char perms[4]; | |
2836 | + int nbytes; | |
fa26e11c WD |
2837 | + |
2838 | + switch (ap->a_type) { | |
0f6733d8 WD |
2839 | + /* |
2840 | + * for debugging purposes it's probably more | |
fa26e11c | 2841 | + * useful to dump unknown tag types rather |
0f6733d8 WD |
2842 | + * than just returning an error |
2843 | + */ | |
fa26e11c | 2844 | + default: |
0f6733d8 | 2845 | + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x", |
fa26e11c WD |
2846 | + ap->a_type); |
2847 | + tag = tagbuf; | |
0f6733d8 | 2848 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
2849 | + (long)ap->a_id); |
2850 | + id = idbuf; | |
2851 | + break; | |
2852 | + | |
2853 | + case SMB_ACL_USER: | |
5ca9317d | 2854 | + id = uidtoname(ap->a_id); |
fa26e11c WD |
2855 | + case SMB_ACL_USER_OBJ: |
2856 | + tag = "user"; | |
2857 | + break; | |
2858 | + | |
2859 | + case SMB_ACL_GROUP: | |
2860 | + if ((gr = getgrgid(ap->a_id)) == NULL) { | |
0f6733d8 | 2861 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
2862 | + (long)ap->a_id); |
2863 | + id = idbuf; | |
2864 | + } else { | |
2865 | + id = gr->gr_name; | |
2866 | + } | |
2867 | + case SMB_ACL_GROUP_OBJ: | |
2868 | + tag = "group"; | |
2869 | + break; | |
2870 | + | |
2871 | + case SMB_ACL_OTHER: | |
2872 | + tag = "other"; | |
2873 | + break; | |
2874 | + | |
2875 | + case SMB_ACL_MASK: | |
2876 | + tag = "mask"; | |
2877 | + break; | |
2878 | + | |
2879 | + } | |
2880 | + | |
2881 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; | |
2882 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; | |
2883 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; | |
2884 | + perms[3] = '\0'; | |
2885 | + | |
2886 | + /* <tag> : <qualifier> : rwx \n \0 */ | |
2887 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; | |
2888 | + | |
0f6733d8 WD |
2889 | + /* |
2890 | + * If this entry would overflow the buffer | |
fa26e11c WD |
2891 | + * allocate enough additional memory for this |
2892 | + * entry and an estimate of another 20 bytes | |
0f6733d8 WD |
2893 | + * for each entry still to be processed |
2894 | + */ | |
fa26e11c WD |
2895 | + if ((len + nbytes) > maxlen) { |
2896 | + char *oldtext = text; | |
2897 | + | |
2898 | + maxlen += nbytes + 20 * (acl_d->count - i); | |
2899 | + | |
252945ef | 2900 | + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) { |
fa26e11c WD |
2901 | + free(oldtext); |
2902 | + errno = ENOMEM; | |
2903 | + return NULL; | |
2904 | + } | |
2905 | + } | |
2906 | + | |
0f6733d8 | 2907 | + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); |
fa26e11c WD |
2908 | + len += nbytes - 1; |
2909 | + } | |
2910 | + | |
2911 | + if (len_p) | |
2912 | + *len_p = len; | |
2913 | + | |
2914 | + return text; | |
2915 | +} | |
2916 | + | |
0f6733d8 | 2917 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 2918 | +{ |
0f6733d8 | 2919 | + SMB_ACL_T a; |
fa26e11c WD |
2920 | + |
2921 | + if (count < 0) { | |
2922 | + errno = EINVAL; | |
2923 | + return NULL; | |
2924 | + } | |
2925 | + | |
0f6733d8 WD |
2926 | + /* |
2927 | + * note that since the definition of the structure pointed | |
fa26e11c WD |
2928 | + * to by the SMB_ACL_T includes the first element of the |
2929 | + * acl[] array, this actually allocates an ACL with room | |
0f6733d8 WD |
2930 | + * for (count+1) entries |
2931 | + */ | |
252945ef | 2932 | + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) { |
fa26e11c WD |
2933 | + errno = ENOMEM; |
2934 | + return NULL; | |
2935 | + } | |
2936 | + | |
2937 | + a->size = count + 1; | |
2938 | + a->count = 0; | |
2939 | + a->next = -1; | |
2940 | + | |
2941 | + return a; | |
2942 | +} | |
2943 | + | |
2944 | + | |
0f6733d8 | 2945 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 2946 | +{ |
0f6733d8 WD |
2947 | + SMB_ACL_T acl_d; |
2948 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
2949 | + |
2950 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
2951 | + errno = EINVAL; | |
2952 | + return -1; | |
2953 | + } | |
2954 | + | |
2955 | + if (acl_d->count >= acl_d->size) { | |
2956 | + errno = ENOSPC; | |
2957 | + return -1; | |
2958 | + } | |
2959 | + | |
0f6733d8 WD |
2960 | + entry_d = &acl_d->acl[acl_d->count++]; |
2961 | + entry_d->a_type = 0; | |
2962 | + entry_d->a_id = -1; | |
2963 | + entry_d->a_perm = 0; | |
2964 | + *entry_p = entry_d; | |
fa26e11c WD |
2965 | + |
2966 | + return 0; | |
2967 | +} | |
2968 | + | |
0f6733d8 | 2969 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
2970 | +{ |
2971 | + switch (tag_type) { | |
2972 | + case SMB_ACL_USER: | |
2973 | + case SMB_ACL_USER_OBJ: | |
2974 | + case SMB_ACL_GROUP: | |
2975 | + case SMB_ACL_GROUP_OBJ: | |
2976 | + case SMB_ACL_OTHER: | |
2977 | + case SMB_ACL_MASK: | |
2978 | + entry_d->a_type = tag_type; | |
2979 | + break; | |
2980 | + default: | |
2981 | + errno = EINVAL; | |
2982 | + return -1; | |
2983 | + } | |
2984 | + | |
2985 | + return 0; | |
2986 | +} | |
2987 | + | |
0f6733d8 | 2988 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
2989 | +{ |
2990 | + if (entry_d->a_type != SMB_ACL_GROUP | |
2991 | + && entry_d->a_type != SMB_ACL_USER) { | |
2992 | + errno = EINVAL; | |
2993 | + return -1; | |
2994 | + } | |
2995 | + | |
2996 | + entry_d->a_id = *((id_t *)qual_p); | |
2997 | + | |
2998 | + return 0; | |
2999 | +} | |
3000 | + | |
0f6733d8 | 3001 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3002 | +{ |
3003 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
3004 | + return EINVAL; | |
3005 | + } | |
3006 | + | |
3007 | + entry_d->a_perm = *permset_d; | |
3008 | + | |
3009 | + return 0; | |
3010 | +} | |
3011 | + | |
3012 | +/* Structure to capture the count for each type of ACE. */ | |
3013 | + | |
3014 | +struct hpux_acl_types { | |
3015 | + int n_user; | |
3016 | + int n_def_user; | |
3017 | + int n_user_obj; | |
3018 | + int n_def_user_obj; | |
3019 | + | |
3020 | + int n_group; | |
3021 | + int n_def_group; | |
3022 | + int n_group_obj; | |
3023 | + int n_def_group_obj; | |
3024 | + | |
3025 | + int n_other; | |
3026 | + int n_other_obj; | |
3027 | + int n_def_other_obj; | |
3028 | + | |
3029 | + int n_class_obj; | |
3030 | + int n_def_class_obj; | |
3031 | + | |
3032 | + int n_illegal_obj; | |
3033 | +}; | |
3034 | + | |
3035 | +/* count_obj: | |
3036 | + * Counts the different number of objects in a given array of ACL | |
3037 | + * structures. | |
3038 | + * Inputs: | |
3039 | + * | |
3040 | + * acl_count - Count of ACLs in the array of ACL strucutres. | |
3041 | + * aclp - Array of ACL structures. | |
3042 | + * acl_type_count - Pointer to acl_types structure. Should already be | |
3043 | + * allocated. | |
0f6733d8 | 3044 | + * Output: |
fa26e11c | 3045 | + * |
0f6733d8 | 3046 | + * acl_type_count - This structure is filled up with counts of various |
fa26e11c WD |
3047 | + * acl types. |
3048 | + */ | |
3049 | + | |
3050 | +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count) | |
3051 | +{ | |
3052 | + int i; | |
3053 | + | |
0f6733d8 | 3054 | + memset(acl_type_count, 0, sizeof(struct hpux_acl_types)); |
fa26e11c | 3055 | + |
0f6733d8 WD |
3056 | + for(i=0;i<acl_count;i++) { |
3057 | + switch(aclp[i].a_type) { | |
3058 | + case USER: | |
fa26e11c WD |
3059 | + acl_type_count->n_user++; |
3060 | + break; | |
0f6733d8 | 3061 | + case USER_OBJ: |
fa26e11c WD |
3062 | + acl_type_count->n_user_obj++; |
3063 | + break; | |
0f6733d8 | 3064 | + case DEF_USER_OBJ: |
fa26e11c WD |
3065 | + acl_type_count->n_def_user_obj++; |
3066 | + break; | |
0f6733d8 | 3067 | + case GROUP: |
fa26e11c WD |
3068 | + acl_type_count->n_group++; |
3069 | + break; | |
0f6733d8 | 3070 | + case GROUP_OBJ: |
fa26e11c WD |
3071 | + acl_type_count->n_group_obj++; |
3072 | + break; | |
0f6733d8 | 3073 | + case DEF_GROUP_OBJ: |
fa26e11c WD |
3074 | + acl_type_count->n_def_group_obj++; |
3075 | + break; | |
0f6733d8 | 3076 | + case OTHER_OBJ: |
fa26e11c WD |
3077 | + acl_type_count->n_other_obj++; |
3078 | + break; | |
0f6733d8 | 3079 | + case DEF_OTHER_OBJ: |
fa26e11c WD |
3080 | + acl_type_count->n_def_other_obj++; |
3081 | + break; | |
3082 | + case CLASS_OBJ: | |
3083 | + acl_type_count->n_class_obj++; | |
3084 | + break; | |
3085 | + case DEF_CLASS_OBJ: | |
3086 | + acl_type_count->n_def_class_obj++; | |
3087 | + break; | |
3088 | + case DEF_USER: | |
3089 | + acl_type_count->n_def_user++; | |
3090 | + break; | |
3091 | + case DEF_GROUP: | |
3092 | + acl_type_count->n_def_group++; | |
3093 | + break; | |
0f6733d8 | 3094 | + default: |
fa26e11c WD |
3095 | + acl_type_count->n_illegal_obj++; |
3096 | + break; | |
3097 | + } | |
3098 | + } | |
3099 | +} | |
3100 | + | |
0f6733d8 | 3101 | +/* swap_acl_entries: Swaps two ACL entries. |
fa26e11c WD |
3102 | + * |
3103 | + * Inputs: aclp0, aclp1 - ACL entries to be swapped. | |
3104 | + */ | |
3105 | + | |
3106 | +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1) | |
3107 | +{ | |
3108 | + struct acl temp_acl; | |
3109 | + | |
3110 | + temp_acl.a_type = aclp0->a_type; | |
3111 | + temp_acl.a_id = aclp0->a_id; | |
3112 | + temp_acl.a_perm = aclp0->a_perm; | |
3113 | + | |
3114 | + aclp0->a_type = aclp1->a_type; | |
3115 | + aclp0->a_id = aclp1->a_id; | |
3116 | + aclp0->a_perm = aclp1->a_perm; | |
3117 | + | |
3118 | + aclp1->a_type = temp_acl.a_type; | |
3119 | + aclp1->a_id = temp_acl.a_id; | |
3120 | + aclp1->a_perm = temp_acl.a_perm; | |
3121 | +} | |
3122 | + | |
3123 | +/* prohibited_duplicate_type | |
0f6733d8 | 3124 | + * Identifies if given ACL type can have duplicate entries or |
fa26e11c WD |
3125 | + * not. |
3126 | + * | |
3127 | + * Inputs: acl_type - ACL Type. | |
3128 | + * | |
0f6733d8 | 3129 | + * Outputs: |
fa26e11c | 3130 | + * |
0f6733d8 | 3131 | + * Return.. |
fa26e11c WD |
3132 | + * |
3133 | + * True - If the ACL type matches any of the prohibited types. | |
3134 | + * False - If the ACL type doesn't match any of the prohibited types. | |
0f6733d8 | 3135 | + */ |
fa26e11c WD |
3136 | + |
3137 | +static BOOL hpux_prohibited_duplicate_type(int acl_type) | |
3138 | +{ | |
0f6733d8 | 3139 | + switch(acl_type) { |
fa26e11c WD |
3140 | + case USER: |
3141 | + case GROUP: | |
0f6733d8 | 3142 | + case DEF_USER: |
fa26e11c WD |
3143 | + case DEF_GROUP: |
3144 | + return True; | |
0f6733d8 WD |
3145 | + default: |
3146 | + return False; | |
fa26e11c | 3147 | + } |
fa26e11c WD |
3148 | +} |
3149 | + | |
3150 | +/* get_needed_class_perm | |
3151 | + * Returns the permissions of a ACL structure only if the ACL | |
0f6733d8 | 3152 | + * type matches one of the pre-determined types for computing |
fa26e11c WD |
3153 | + * CLASS_OBJ permissions. |
3154 | + * | |
3155 | + * Inputs: aclp - Pointer to ACL structure. | |
3156 | + */ | |
3157 | + | |
3158 | +static int hpux_get_needed_class_perm(struct acl *aclp) | |
3159 | +{ | |
0f6733d8 WD |
3160 | + switch(aclp->a_type) { |
3161 | + case USER: | |
3162 | + case GROUP_OBJ: | |
3163 | + case GROUP: | |
3164 | + case DEF_USER_OBJ: | |
fa26e11c | 3165 | + case DEF_USER: |
0f6733d8 | 3166 | + case DEF_GROUP_OBJ: |
fa26e11c WD |
3167 | + case DEF_GROUP: |
3168 | + case DEF_CLASS_OBJ: | |
0f6733d8 | 3169 | + case DEF_OTHER_OBJ: |
fa26e11c | 3170 | + return aclp->a_perm; |
0f6733d8 | 3171 | + default: |
fa26e11c WD |
3172 | + return 0; |
3173 | + } | |
3174 | +} | |
3175 | + | |
3176 | +/* acl_sort for HPUX. | |
3177 | + * Sorts the array of ACL structures as per the description in | |
3178 | + * aclsort man page. Refer to aclsort man page for more details | |
3179 | + * | |
3180 | + * Inputs: | |
3181 | + * | |
3182 | + * acl_count - Count of ACLs in the array of ACL structures. | |
3183 | + * calclass - If this is not zero, then we compute the CLASS_OBJ | |
3184 | + * permissions. | |
3185 | + * aclp - Array of ACL structures. | |
3186 | + * | |
3187 | + * Outputs: | |
3188 | + * | |
3189 | + * aclp - Sorted array of ACL structures. | |
3190 | + * | |
3191 | + * Outputs: | |
3192 | + * | |
3193 | + * Returns 0 for success -1 for failure. Prints a message to the Samba | |
3194 | + * debug log in case of failure. | |
3195 | + */ | |
3196 | + | |
3197 | +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp) | |
3198 | +{ | |
3199 | +#if !defined(HAVE_HPUX_ACLSORT) | |
0f6733d8 WD |
3200 | + /* |
3201 | + * The aclsort() system call is availabe on the latest HPUX General | |
3202 | + * Patch Bundles. So for HPUX, we developed our version of acl_sort | |
3203 | + * function. Because, we don't want to update to a new | |
3204 | + * HPUX GR bundle just for aclsort() call. | |
3205 | + */ | |
fa26e11c WD |
3206 | + |
3207 | + struct hpux_acl_types acl_obj_count; | |
3208 | + int n_class_obj_perm = 0; | |
3209 | + int i, j; | |
0f6733d8 WD |
3210 | + |
3211 | + if(!acl_count) { | |
fa26e11c WD |
3212 | + DEBUG(10,("Zero acl count passed. Returning Success\n")); |
3213 | + return 0; | |
3214 | + } | |
3215 | + | |
0f6733d8 | 3216 | + if(aclp == NULL) { |
fa26e11c WD |
3217 | + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n")); |
3218 | + return -1; | |
3219 | + } | |
3220 | + | |
3221 | + /* Count different types of ACLs in the ACLs array */ | |
3222 | + | |
3223 | + hpux_count_obj(acl_count, aclp, &acl_obj_count); | |
3224 | + | |
0f6733d8 WD |
3225 | + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ, |
3226 | + * CLASS_OBJ and OTHER_OBJ | |
fa26e11c WD |
3227 | + */ |
3228 | + | |
0f6733d8 WD |
3229 | + if( (acl_obj_count.n_user_obj != 1) || |
3230 | + (acl_obj_count.n_group_obj != 1) || | |
3231 | + (acl_obj_count.n_class_obj != 1) || | |
3232 | + (acl_obj_count.n_other_obj != 1) | |
3233 | + ) { | |
fa26e11c WD |
3234 | + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \ |
3235 | +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n")); | |
3236 | + return -1; | |
3237 | + } | |
3238 | + | |
3239 | + /* If any of the default objects are present, there should be only | |
3240 | + * one of them each. | |
3241 | + */ | |
3242 | + | |
0f6733d8 WD |
3243 | + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) || |
3244 | + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) { | |
fa26e11c WD |
3245 | + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \ |
3246 | +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n")); | |
3247 | + return -1; | |
3248 | + } | |
3249 | + | |
0f6733d8 WD |
3250 | + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl |
3251 | + * structures. | |
fa26e11c WD |
3252 | + * |
3253 | + * Sorting crieteria - First sort by ACL type. If there are multiple entries of | |
3254 | + * same ACL type, sort by ACL id. | |
3255 | + * | |
0f6733d8 | 3256 | + * I am using the trival kind of sorting method here because, performance isn't |
fa26e11c | 3257 | + * really effected by the ACLs feature. More over there aren't going to be more |
0f6733d8 | 3258 | + * than 17 entries on HPUX. |
fa26e11c WD |
3259 | + */ |
3260 | + | |
0f6733d8 | 3261 | + for(i=0; i<acl_count;i++) { |
fa26e11c | 3262 | + for (j=i+1; j<acl_count; j++) { |
0f6733d8 | 3263 | + if( aclp[i].a_type > aclp[j].a_type ) { |
fa26e11c WD |
3264 | + /* ACL entries out of order, swap them */ |
3265 | + | |
3266 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); | |
3267 | + | |
0f6733d8 | 3268 | + } else if ( aclp[i].a_type == aclp[j].a_type ) { |
fa26e11c WD |
3269 | + |
3270 | + /* ACL entries of same type, sort by id */ | |
3271 | + | |
0f6733d8 | 3272 | + if(aclp[i].a_id > aclp[j].a_id) { |
fa26e11c WD |
3273 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); |
3274 | + } else if (aclp[i].a_id == aclp[j].a_id) { | |
3275 | + /* We have a duplicate entry. */ | |
0f6733d8 | 3276 | + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) { |
fa26e11c WD |
3277 | + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n", |
3278 | + aclp[i].a_type, aclp[i].a_id)); | |
3279 | + return -1; | |
3280 | + } | |
3281 | + } | |
3282 | + | |
3283 | + } | |
3284 | + } | |
3285 | + } | |
3286 | + | |
3287 | + /* set the class obj permissions to the computed one. */ | |
0f6733d8 | 3288 | + if(calclass) { |
fa26e11c WD |
3289 | + int n_class_obj_index = -1; |
3290 | + | |
0f6733d8 | 3291 | + for(i=0;i<acl_count;i++) { |
fa26e11c WD |
3292 | + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i)); |
3293 | + | |
0f6733d8 | 3294 | + if(aclp[i].a_type == CLASS_OBJ) |
fa26e11c WD |
3295 | + n_class_obj_index = i; |
3296 | + } | |
3297 | + aclp[n_class_obj_index].a_perm = n_class_obj_perm; | |
3298 | + } | |
3299 | + | |
3300 | + return 0; | |
3301 | +#else | |
3302 | + return aclsort(acl_count, calclass, aclp); | |
3303 | +#endif | |
3304 | +} | |
3305 | + | |
0f6733d8 WD |
3306 | +/* |
3307 | + * sort the ACL and check it for validity | |
fa26e11c | 3308 | + * |
0f6733d8 | 3309 | + * if it's a minimal ACL with only 4 entries then we |
fa26e11c WD |
3310 | + * need to recalculate the mask permissions to make |
3311 | + * sure that they are the same as the GROUP_OBJ | |
3312 | + * permissions as required by the UnixWare acl() system call. | |
3313 | + * | |
0f6733d8 | 3314 | + * (note: since POSIX allows minimal ACLs which only contain |
fa26e11c WD |
3315 | + * 3 entries - ie there is no mask entry - we should, in theory, |
3316 | + * check for this and add a mask entry if necessary - however | |
3317 | + * we "know" that the caller of this interface always specifies | |
3318 | + * a mask so, in practice "this never happens" (tm) - if it *does* | |
3319 | + * happen aclsort() will fail and return an error and someone will | |
0f6733d8 WD |
3320 | + * have to fix it ...) |
3321 | + */ | |
fa26e11c WD |
3322 | + |
3323 | +static int acl_sort(SMB_ACL_T acl_d) | |
3324 | +{ | |
3325 | + int fixmask = (acl_d->count <= 4); | |
3326 | + | |
3327 | + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) { | |
3328 | + errno = EINVAL; | |
3329 | + return -1; | |
3330 | + } | |
3331 | + return 0; | |
3332 | +} | |
0f6733d8 WD |
3333 | + |
3334 | +int sys_acl_valid(SMB_ACL_T acl_d) | |
fa26e11c WD |
3335 | +{ |
3336 | + return acl_sort(acl_d); | |
3337 | +} | |
3338 | + | |
0f6733d8 | 3339 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c | 3340 | +{ |
0f6733d8 WD |
3341 | + struct stat s; |
3342 | + struct acl *acl_p; | |
3343 | + int acl_count; | |
3344 | + struct acl *acl_buf = NULL; | |
3345 | + int ret; | |
fa26e11c | 3346 | + |
0f6733d8 WD |
3347 | + if(hpux_acl_call_presence() == False) { |
3348 | + /* Looks like we don't have the acl() system call on HPUX. | |
3349 | + * May be the system doesn't have the latest version of JFS. | |
3350 | + */ | |
3351 | + errno=ENOSYS; | |
3352 | + return -1; | |
fa26e11c WD |
3353 | + } |
3354 | + | |
3355 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
3356 | + errno = EINVAL; | |
3357 | + return -1; | |
3358 | + } | |
3359 | + | |
3360 | + if (acl_sort(acl_d) != 0) { | |
3361 | + return -1; | |
3362 | + } | |
3363 | + | |
0f6733d8 WD |
3364 | + acl_p = &acl_d->acl[0]; |
3365 | + acl_count = acl_d->count; | |
fa26e11c | 3366 | + |
0f6733d8 WD |
3367 | + /* |
3368 | + * if it's a directory there is extra work to do | |
3369 | + * since the acl() system call will replace both | |
3370 | + * the access ACLs and the default ACLs (if any) | |
3371 | + */ | |
fa26e11c WD |
3372 | + if (stat(name, &s) != 0) { |
3373 | + return -1; | |
3374 | + } | |
3375 | + if (S_ISDIR(s.st_mode)) { | |
0f6733d8 WD |
3376 | + SMB_ACL_T acc_acl; |
3377 | + SMB_ACL_T def_acl; | |
3378 | + SMB_ACL_T tmp_acl; | |
3379 | + int i; | |
fa26e11c WD |
3380 | + |
3381 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
3382 | + acc_acl = acl_d; | |
3383 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); | |
3384 | + | |
3385 | + } else { | |
3386 | + def_acl = acl_d; | |
3387 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); | |
3388 | + } | |
3389 | + | |
3390 | + if (tmp_acl == NULL) { | |
3391 | + return -1; | |
3392 | + } | |
3393 | + | |
0f6733d8 WD |
3394 | + /* |
3395 | + * allocate a temporary buffer for the complete ACL | |
3396 | + */ | |
fa26e11c | 3397 | + acl_count = acc_acl->count + def_acl->count; |
252945ef | 3398 | + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
fa26e11c WD |
3399 | + |
3400 | + if (acl_buf == NULL) { | |
3401 | + sys_acl_free_acl(tmp_acl); | |
3402 | + errno = ENOMEM; | |
3403 | + return -1; | |
3404 | + } | |
3405 | + | |
0f6733d8 WD |
3406 | + /* |
3407 | + * copy the access control and default entries into the buffer | |
3408 | + */ | |
fa26e11c | 3409 | + memcpy(&acl_buf[0], &acc_acl->acl[0], |
0f6733d8 | 3410 | + acc_acl->count * sizeof(acl_buf[0])); |
fa26e11c WD |
3411 | + |
3412 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], | |
0f6733d8 | 3413 | + def_acl->count * sizeof(acl_buf[0])); |
fa26e11c | 3414 | + |
0f6733d8 WD |
3415 | + /* |
3416 | + * set the ACL_DEFAULT flag on the default entries | |
3417 | + */ | |
fa26e11c WD |
3418 | + for (i = acc_acl->count; i < acl_count; i++) { |
3419 | + acl_buf[i].a_type |= ACL_DEFAULT; | |
3420 | + } | |
3421 | + | |
3422 | + sys_acl_free_acl(tmp_acl); | |
3423 | + | |
3424 | + } else if (type != SMB_ACL_TYPE_ACCESS) { | |
3425 | + errno = EINVAL; | |
3426 | + return -1; | |
3427 | + } | |
3428 | + | |
3429 | + ret = acl(name, ACL_SET, acl_count, acl_p); | |
3430 | + | |
0f6733d8 WD |
3431 | + if (acl_buf) { |
3432 | + free(acl_buf); | |
3433 | + } | |
fa26e11c WD |
3434 | + |
3435 | + return ret; | |
3436 | +} | |
3437 | + | |
0f6733d8 | 3438 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c | 3439 | +{ |
0f6733d8 WD |
3440 | + /* |
3441 | + * HPUX doesn't have the facl call. Fake it using the path.... JRA. | |
3442 | + */ | |
fa26e11c WD |
3443 | + |
3444 | + files_struct *fsp = file_find_fd(fd); | |
3445 | + | |
3446 | + if (fsp == NULL) { | |
3447 | + errno = EBADF; | |
3448 | + return NULL; | |
3449 | + } | |
3450 | + | |
3451 | + if (acl_sort(acl_d) != 0) { | |
3452 | + return -1; | |
3453 | + } | |
3454 | + | |
0f6733d8 WD |
3455 | + /* |
3456 | + * We know we're in the same conn context. So we | |
3457 | + * can use the relative path. | |
3458 | + */ | |
fa26e11c | 3459 | + |
5ca9317d | 3460 | + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d); |
fa26e11c WD |
3461 | +} |
3462 | + | |
0f6733d8 | 3463 | +int sys_acl_delete_def_file(const char *path) |
fa26e11c | 3464 | +{ |
0f6733d8 WD |
3465 | + SMB_ACL_T acl_d; |
3466 | + int ret; | |
fa26e11c | 3467 | + |
0f6733d8 WD |
3468 | + /* |
3469 | + * fetching the access ACL and rewriting it has | |
3470 | + * the effect of deleting the default ACL | |
3471 | + */ | |
fa26e11c WD |
3472 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
3473 | + return -1; | |
3474 | + } | |
3475 | + | |
3476 | + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl); | |
3477 | + | |
3478 | + sys_acl_free_acl(acl_d); | |
0f6733d8 | 3479 | + |
fa26e11c WD |
3480 | + return ret; |
3481 | +} | |
3482 | + | |
0f6733d8 | 3483 | +int sys_acl_free_text(char *text) |
fa26e11c WD |
3484 | +{ |
3485 | + free(text); | |
3486 | + return 0; | |
3487 | +} | |
3488 | + | |
0f6733d8 | 3489 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c WD |
3490 | +{ |
3491 | + free(acl_d); | |
3492 | + return 0; | |
3493 | +} | |
3494 | + | |
0f6733d8 | 3495 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
3496 | +{ |
3497 | + return 0; | |
3498 | +} | |
3499 | + | |
3500 | +#elif defined(HAVE_IRIX_ACLS) | |
3501 | + | |
0f6733d8 | 3502 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
3503 | +{ |
3504 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
3505 | + errno = EINVAL; | |
3506 | + return -1; | |
3507 | + } | |
3508 | + | |
3509 | + if (entry_p == NULL) { | |
3510 | + errno = EINVAL; | |
3511 | + return -1; | |
3512 | + } | |
3513 | + | |
3514 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
3515 | + acl_d->next = 0; | |
3516 | + } | |
3517 | + | |
3518 | + if (acl_d->next < 0) { | |
3519 | + errno = EINVAL; | |
3520 | + return -1; | |
3521 | + } | |
3522 | + | |
3523 | + if (acl_d->next >= acl_d->aclp->acl_cnt) { | |
3524 | + return 0; | |
3525 | + } | |
3526 | + | |
3527 | + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++]; | |
3528 | + | |
3529 | + return 1; | |
3530 | +} | |
3531 | + | |
0f6733d8 | 3532 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
3533 | +{ |
3534 | + *type_p = entry_d->ae_tag; | |
3535 | + | |
3536 | + return 0; | |
3537 | +} | |
3538 | + | |
0f6733d8 | 3539 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
3540 | +{ |
3541 | + *permset_p = entry_d; | |
3542 | + | |
3543 | + return 0; | |
3544 | +} | |
3545 | + | |
0f6733d8 | 3546 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
3547 | +{ |
3548 | + if (entry_d->ae_tag != SMB_ACL_USER | |
3549 | + && entry_d->ae_tag != SMB_ACL_GROUP) { | |
3550 | + errno = EINVAL; | |
3551 | + return NULL; | |
3552 | + } | |
3553 | + | |
3554 | + return &entry_d->ae_id; | |
3555 | +} | |
3556 | + | |
0f6733d8 | 3557 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 3558 | +{ |
0f6733d8 | 3559 | + SMB_ACL_T a; |
fa26e11c | 3560 | + |
252945ef | 3561 | + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
fa26e11c WD |
3562 | + errno = ENOMEM; |
3563 | + return NULL; | |
3564 | + } | |
3565 | + if ((a->aclp = acl_get_file(path_p, type)) == NULL) { | |
0f6733d8 | 3566 | + SAFE_FREE(a); |
fa26e11c WD |
3567 | + return NULL; |
3568 | + } | |
3569 | + a->next = -1; | |
3570 | + a->freeaclp = True; | |
3571 | + return a; | |
3572 | +} | |
3573 | + | |
0f6733d8 | 3574 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 3575 | +{ |
0f6733d8 | 3576 | + SMB_ACL_T a; |
fa26e11c | 3577 | + |
252945ef | 3578 | + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
fa26e11c WD |
3579 | + errno = ENOMEM; |
3580 | + return NULL; | |
3581 | + } | |
3582 | + if ((a->aclp = acl_get_fd(fd)) == NULL) { | |
0f6733d8 | 3583 | + SAFE_FREE(a); |
fa26e11c WD |
3584 | + return NULL; |
3585 | + } | |
3586 | + a->next = -1; | |
3587 | + a->freeaclp = True; | |
3588 | + return a; | |
3589 | +} | |
3590 | + | |
0f6733d8 | 3591 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3592 | +{ |
3593 | + permset_d->ae_perm = 0; | |
3594 | + | |
3595 | + return 0; | |
3596 | +} | |
3597 | + | |
0f6733d8 | 3598 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
3599 | +{ |
3600 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
3601 | + && perm != SMB_ACL_EXECUTE) { | |
3602 | + errno = EINVAL; | |
3603 | + return -1; | |
3604 | + } | |
3605 | + | |
3606 | + if (permset_d == NULL) { | |
3607 | + errno = EINVAL; | |
3608 | + return -1; | |
3609 | + } | |
3610 | + | |
3611 | + permset_d->ae_perm |= perm; | |
3612 | + | |
3613 | + return 0; | |
3614 | +} | |
3615 | + | |
0f6733d8 | 3616 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
3617 | +{ |
3618 | + return permset_d->ae_perm & perm; | |
3619 | +} | |
3620 | + | |
0f6733d8 | 3621 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c WD |
3622 | +{ |
3623 | + return acl_to_text(acl_d->aclp, len_p); | |
3624 | +} | |
3625 | + | |
0f6733d8 | 3626 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 3627 | +{ |
0f6733d8 | 3628 | + SMB_ACL_T a; |
fa26e11c WD |
3629 | + |
3630 | + if (count < 0) { | |
3631 | + errno = EINVAL; | |
3632 | + return NULL; | |
3633 | + } | |
3634 | + | |
252945ef | 3635 | + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) { |
fa26e11c WD |
3636 | + errno = ENOMEM; |
3637 | + return NULL; | |
3638 | + } | |
3639 | + | |
3640 | + a->next = -1; | |
3641 | + a->freeaclp = False; | |
0f6733d8 | 3642 | + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *)); |
fa26e11c WD |
3643 | + a->aclp->acl_cnt = 0; |
3644 | + | |
3645 | + return a; | |
3646 | +} | |
3647 | + | |
3648 | + | |
0f6733d8 | 3649 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 3650 | +{ |
0f6733d8 WD |
3651 | + SMB_ACL_T acl_d; |
3652 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
3653 | + |
3654 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
3655 | + errno = EINVAL; | |
3656 | + return -1; | |
3657 | + } | |
3658 | + | |
3659 | + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) { | |
3660 | + errno = ENOSPC; | |
3661 | + return -1; | |
3662 | + } | |
3663 | + | |
0f6733d8 WD |
3664 | + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++]; |
3665 | + entry_d->ae_tag = 0; | |
3666 | + entry_d->ae_id = 0; | |
3667 | + entry_d->ae_perm = 0; | |
3668 | + *entry_p = entry_d; | |
fa26e11c WD |
3669 | + |
3670 | + return 0; | |
3671 | +} | |
3672 | + | |
0f6733d8 | 3673 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
3674 | +{ |
3675 | + switch (tag_type) { | |
3676 | + case SMB_ACL_USER: | |
3677 | + case SMB_ACL_USER_OBJ: | |
3678 | + case SMB_ACL_GROUP: | |
3679 | + case SMB_ACL_GROUP_OBJ: | |
3680 | + case SMB_ACL_OTHER: | |
3681 | + case SMB_ACL_MASK: | |
3682 | + entry_d->ae_tag = tag_type; | |
3683 | + break; | |
3684 | + default: | |
3685 | + errno = EINVAL; | |
3686 | + return -1; | |
3687 | + } | |
3688 | + | |
3689 | + return 0; | |
3690 | +} | |
3691 | + | |
0f6733d8 | 3692 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
3693 | +{ |
3694 | + if (entry_d->ae_tag != SMB_ACL_GROUP | |
3695 | + && entry_d->ae_tag != SMB_ACL_USER) { | |
3696 | + errno = EINVAL; | |
3697 | + return -1; | |
3698 | + } | |
3699 | + | |
3700 | + entry_d->ae_id = *((id_t *)qual_p); | |
3701 | + | |
3702 | + return 0; | |
3703 | +} | |
3704 | + | |
0f6733d8 | 3705 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3706 | +{ |
3707 | + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
3708 | + return EINVAL; | |
3709 | + } | |
3710 | + | |
3711 | + entry_d->ae_perm = permset_d->ae_perm; | |
3712 | + | |
3713 | + return 0; | |
3714 | +} | |
3715 | + | |
0f6733d8 | 3716 | +int sys_acl_valid(SMB_ACL_T acl_d) |
fa26e11c WD |
3717 | +{ |
3718 | + return acl_valid(acl_d->aclp); | |
3719 | +} | |
3720 | + | |
0f6733d8 | 3721 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c WD |
3722 | +{ |
3723 | + return acl_set_file(name, type, acl_d->aclp); | |
3724 | +} | |
3725 | + | |
0f6733d8 | 3726 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c WD |
3727 | +{ |
3728 | + return acl_set_fd(fd, acl_d->aclp); | |
3729 | +} | |
3730 | + | |
0f6733d8 | 3731 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
3732 | +{ |
3733 | + return acl_delete_def_file(name); | |
3734 | +} | |
3735 | + | |
0f6733d8 | 3736 | +int sys_acl_free_text(char *text) |
fa26e11c WD |
3737 | +{ |
3738 | + return acl_free(text); | |
3739 | +} | |
3740 | + | |
0f6733d8 | 3741 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c WD |
3742 | +{ |
3743 | + if (acl_d->freeaclp) { | |
3744 | + acl_free(acl_d->aclp); | |
3745 | + } | |
3746 | + acl_free(acl_d); | |
3747 | + return 0; | |
3748 | +} | |
3749 | + | |
0f6733d8 | 3750 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
3751 | +{ |
3752 | + return 0; | |
3753 | +} | |
3754 | + | |
3755 | +#elif defined(HAVE_AIX_ACLS) | |
3756 | + | |
3757 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
3758 | + | |
0f6733d8 | 3759 | +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
3760 | +{ |
3761 | + struct acl_entry_link *link; | |
3762 | + struct new_acl_entry *entry; | |
3763 | + int keep_going; | |
3764 | + | |
3765 | + DEBUG(10,("This is the count: %d\n",theacl->count)); | |
3766 | + | |
0f6733d8 WD |
3767 | + /* Check if count was previously set to -1. * |
3768 | + * If it was, that means we reached the end * | |
3769 | + * of the acl last time. */ | |
3770 | + if(theacl->count == -1) | |
3771 | + return(0); | |
fa26e11c WD |
3772 | + |
3773 | + link = theacl; | |
0f6733d8 WD |
3774 | + /* To get to the next acl, traverse linked list until index * |
3775 | + * of acl matches the count we are keeping. This count is * | |
3776 | + * incremented each time we return an acl entry. */ | |
fa26e11c | 3777 | + |
0f6733d8 | 3778 | + for(keep_going = 0; keep_going < theacl->count; keep_going++) |
fa26e11c WD |
3779 | + link = link->nextp; |
3780 | + | |
3781 | + entry = *entry_p = link->entryp; | |
3782 | + | |
3783 | + DEBUG(10,("*entry_p is %d\n",entry_p)); | |
3784 | + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access)); | |
3785 | + | |
3786 | + /* Increment count */ | |
3787 | + theacl->count++; | |
0f6733d8 | 3788 | + if(link->nextp == NULL) |
fa26e11c WD |
3789 | + theacl->count = -1; |
3790 | + | |
0f6733d8 | 3791 | + return(1); |
fa26e11c WD |
3792 | +} |
3793 | + | |
0f6733d8 | 3794 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c WD |
3795 | +{ |
3796 | + /* Initialize tag type */ | |
3797 | + | |
3798 | + *tag_type_p = -1; | |
3799 | + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type)); | |
3800 | + | |
0f6733d8 WD |
3801 | + /* Depending on what type of entry we have, * |
3802 | + * return tag type. */ | |
3803 | + switch(entry_d->ace_id->id_type) { | |
fa26e11c WD |
3804 | + case ACEID_USER: |
3805 | + *tag_type_p = SMB_ACL_USER; | |
3806 | + break; | |
3807 | + case ACEID_GROUP: | |
3808 | + *tag_type_p = SMB_ACL_GROUP; | |
3809 | + break; | |
3810 | + | |
3811 | + case SMB_ACL_USER_OBJ: | |
3812 | + case SMB_ACL_GROUP_OBJ: | |
3813 | + case SMB_ACL_OTHER: | |
3814 | + *tag_type_p = entry_d->ace_id->id_type; | |
3815 | + break; | |
0f6733d8 | 3816 | + |
fa26e11c | 3817 | + default: |
0f6733d8 | 3818 | + return(-1); |
fa26e11c WD |
3819 | + } |
3820 | + | |
0f6733d8 | 3821 | + return(0); |
fa26e11c WD |
3822 | +} |
3823 | + | |
0f6733d8 | 3824 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
3825 | +{ |
3826 | + DEBUG(10,("Starting AIX sys_acl_get_permset\n")); | |
3827 | + *permset_p = &entry_d->ace_access; | |
3828 | + DEBUG(10,("**permset_p is %d\n",**permset_p)); | |
0f6733d8 WD |
3829 | + if(!(**permset_p & S_IXUSR) && |
3830 | + !(**permset_p & S_IWUSR) && | |
3831 | + !(**permset_p & S_IRUSR) && | |
3832 | + (**permset_p != 0)) | |
3833 | + return(-1); | |
fa26e11c WD |
3834 | + |
3835 | + DEBUG(10,("Ending AIX sys_acl_get_permset\n")); | |
0f6733d8 | 3836 | + return(0); |
fa26e11c WD |
3837 | +} |
3838 | + | |
0f6733d8 | 3839 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 3840 | +{ |
0f6733d8 | 3841 | + return(entry_d->ace_id->id_data); |
fa26e11c WD |
3842 | +} |
3843 | + | |
0f6733d8 | 3844 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c WD |
3845 | +{ |
3846 | + struct acl *file_acl = (struct acl *)NULL; | |
3847 | + struct acl_entry *acl_entry; | |
3848 | + struct new_acl_entry *new_acl_entry; | |
3849 | + struct ace_id *idp; | |
3850 | + struct acl_entry_link *acl_entry_link; | |
3851 | + struct acl_entry_link *acl_entry_link_head; | |
3852 | + int i; | |
3853 | + int rc = 0; | |
3854 | + uid_t user_id; | |
3855 | + | |
252945ef WD |
3856 | + /* AIX has no DEFAULT */ |
3857 | + if ( type == SMB_ACL_TYPE_DEFAULT ) | |
3858 | + return NULL; | |
3859 | + | |
fa26e11c | 3860 | + /* Get the acl using statacl */ |
0f6733d8 | 3861 | + |
fa26e11c WD |
3862 | + DEBUG(10,("Entering sys_acl_get_file\n")); |
3863 | + DEBUG(10,("path_p is %s\n",path_p)); | |
3864 | + | |
252945ef | 3865 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
0f6733d8 WD |
3866 | + |
3867 | + if(file_acl == NULL) { | |
fa26e11c WD |
3868 | + errno=ENOMEM; |
3869 | + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno)); | |
0f6733d8 | 3870 | + return(NULL); |
fa26e11c WD |
3871 | + } |
3872 | + | |
3873 | + memset(file_acl,0,BUFSIZ); | |
3874 | + | |
3875 | + rc = statacl((char *)path_p,0,file_acl,BUFSIZ); | |
0f6733d8 | 3876 | + if(rc == -1) { |
fa26e11c | 3877 | + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno)); |
0f6733d8 WD |
3878 | + SAFE_FREE(file_acl); |
3879 | + return(NULL); | |
fa26e11c WD |
3880 | + } |
3881 | + | |
3882 | + DEBUG(10,("Got facl and returned it\n")); | |
3883 | + | |
3884 | + /* Point to the first acl entry in the acl */ | |
3885 | + acl_entry = file_acl->acl_ext; | |
3886 | + | |
0f6733d8 WD |
3887 | + /* Begin setting up the head of the linked list * |
3888 | + * that will be used for the storing the acl * | |
3889 | + * in a way that is useful for the posix_acls.c * | |
3890 | + * code. */ | |
fa26e11c WD |
3891 | + |
3892 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); | |
0f6733d8 WD |
3893 | + if(acl_entry_link_head == NULL) |
3894 | + return(NULL); | |
fa26e11c | 3895 | + |
252945ef | 3896 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
3897 | + if(acl_entry_link->entryp == NULL) { |
3898 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
3899 | + errno = ENOMEM; |
3900 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 3901 | + return(NULL); |
fa26e11c WD |
3902 | + } |
3903 | + | |
3904 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); | |
3905 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); | |
3906 | + | |
0f6733d8 WD |
3907 | + /* Check if the extended acl bit is on. * |
3908 | + * If it isn't, do not show the * | |
3909 | + * contents of the acl since AIX intends * | |
3910 | + * the extended info to remain unused */ | |
fa26e11c | 3911 | + |
0f6733d8 | 3912 | + if(file_acl->acl_mode & S_IXACL){ |
fa26e11c | 3913 | + /* while we are not pointing to the very end */ |
0f6733d8 | 3914 | + while(acl_entry < acl_last(file_acl)) { |
fa26e11c WD |
3915 | + /* before we malloc anything, make sure this is */ |
3916 | + /* a valid acl entry and one that we want to map */ | |
3917 | + idp = id_nxt(acl_entry->ace_id); | |
0f6733d8 WD |
3918 | + if((acl_entry->ace_type == ACC_SPECIFY || |
3919 | + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { | |
3920 | + acl_entry = acl_nxt(acl_entry); | |
3921 | + continue; | |
fa26e11c WD |
3922 | + } |
3923 | + | |
3924 | + idp = acl_entry->ace_id; | |
3925 | + | |
0f6733d8 WD |
3926 | + /* Check if this is the first entry in the linked list. * |
3927 | + * The first entry needs to keep prevp pointing to NULL * | |
3928 | + * and already has entryp allocated. */ | |
fa26e11c | 3929 | + |
0f6733d8 | 3930 | + if(acl_entry_link_head->count != 0) { |
252945ef | 3931 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
fa26e11c | 3932 | + |
0f6733d8 WD |
3933 | + if(acl_entry_link->nextp == NULL) { |
3934 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
3935 | + errno = ENOMEM; |
3936 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 3937 | + return(NULL); |
fa26e11c WD |
3938 | + } |
3939 | + | |
3940 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
3941 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 3942 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
3943 | + if(acl_entry_link->entryp == NULL) { |
3944 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
3945 | + errno = ENOMEM; |
3946 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 3947 | + return(NULL); |
fa26e11c WD |
3948 | + } |
3949 | + acl_entry_link->nextp = NULL; | |
3950 | + } | |
3951 | + | |
3952 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; | |
3953 | + | |
0f6733d8 WD |
3954 | + /* Don't really need this since all types are going * |
3955 | + * to be specified but, it's better than leaving it 0 */ | |
fa26e11c WD |
3956 | + |
3957 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; | |
0f6733d8 | 3958 | + |
fa26e11c | 3959 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
0f6733d8 WD |
3960 | + |
3961 | + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id)); | |
fa26e11c | 3962 | + |
0f6733d8 WD |
3963 | + /* The access in the acl entries must be left shifted by * |
3964 | + * three bites, because they will ultimately be compared * | |
3965 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ | |
fa26e11c | 3966 | + |
0f6733d8 | 3967 | + switch(acl_entry->ace_type){ |
fa26e11c WD |
3968 | + case ACC_PERMIT: |
3969 | + case ACC_SPECIFY: | |
3970 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
3971 | + acl_entry_link->entryp->ace_access <<= 6; | |
3972 | + acl_entry_link_head->count++; | |
3973 | + break; | |
3974 | + case ACC_DENY: | |
0f6733d8 WD |
3975 | + /* Since there is no way to return a DENY acl entry * |
3976 | + * change to PERMIT and then shift. */ | |
fa26e11c WD |
3977 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); |
3978 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; | |
3979 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); | |
3980 | + acl_entry_link->entryp->ace_access <<= 6; | |
3981 | + acl_entry_link_head->count++; | |
3982 | + break; | |
3983 | + default: | |
0f6733d8 | 3984 | + return(0); |
fa26e11c WD |
3985 | + } |
3986 | + | |
3987 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); | |
3988 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); | |
0f6733d8 | 3989 | + |
fa26e11c WD |
3990 | + acl_entry = acl_nxt(acl_entry); |
3991 | + } | |
3992 | + } /* end of if enabled */ | |
3993 | + | |
0f6733d8 WD |
3994 | + /* Since owner, group, other acl entries are not * |
3995 | + * part of the acl entries in an acl, they must * | |
3996 | + * be dummied up to become part of the list. */ | |
fa26e11c | 3997 | + |
0f6733d8 | 3998 | + for( i = 1; i < 4; i++) { |
fa26e11c | 3999 | + DEBUG(10,("i is %d\n",i)); |
0f6733d8 | 4000 | + if(acl_entry_link_head->count != 0) { |
252945ef | 4001 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 WD |
4002 | + if(acl_entry_link->nextp == NULL) { |
4003 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4004 | + errno = ENOMEM; |
4005 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4006 | + return(NULL); |
fa26e11c WD |
4007 | + } |
4008 | + | |
4009 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4010 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4011 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
4012 | + if(acl_entry_link->entryp == NULL) { |
4013 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4014 | + errno = ENOMEM; |
4015 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4016 | + return(NULL); |
fa26e11c WD |
4017 | + } |
4018 | + } | |
4019 | + | |
4020 | + acl_entry_link->nextp = NULL; | |
4021 | + | |
4022 | + new_acl_entry = acl_entry_link->entryp; | |
4023 | + idp = new_acl_entry->ace_id; | |
4024 | + | |
0f6733d8 | 4025 | + new_acl_entry->ace_len = sizeof(struct acl_entry); |
fa26e11c | 4026 | + new_acl_entry->ace_type = ACC_PERMIT; |
0f6733d8 | 4027 | + idp->id_len = sizeof(struct ace_id); |
fa26e11c | 4028 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); |
0f6733d8 | 4029 | + memset(idp->id_data,0,sizeof(uid_t)); |
fa26e11c | 4030 | + |
0f6733d8 | 4031 | + switch(i) { |
fa26e11c WD |
4032 | + case 2: |
4033 | + new_acl_entry->ace_access = file_acl->g_access << 6; | |
4034 | + idp->id_type = SMB_ACL_GROUP_OBJ; | |
4035 | + break; | |
4036 | + | |
4037 | + case 3: | |
4038 | + new_acl_entry->ace_access = file_acl->o_access << 6; | |
4039 | + idp->id_type = SMB_ACL_OTHER; | |
4040 | + break; | |
0f6733d8 | 4041 | + |
fa26e11c WD |
4042 | + case 1: |
4043 | + new_acl_entry->ace_access = file_acl->u_access << 6; | |
4044 | + idp->id_type = SMB_ACL_USER_OBJ; | |
4045 | + break; | |
0f6733d8 | 4046 | + |
fa26e11c | 4047 | + default: |
0f6733d8 | 4048 | + return(NULL); |
fa26e11c WD |
4049 | + |
4050 | + } | |
4051 | + | |
4052 | + acl_entry_link_head->count++; | |
4053 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); | |
4054 | + } | |
4055 | + | |
4056 | + acl_entry_link_head->count = 0; | |
0f6733d8 | 4057 | + SAFE_FREE(file_acl); |
fa26e11c | 4058 | + |
0f6733d8 | 4059 | + return(acl_entry_link_head); |
fa26e11c WD |
4060 | +} |
4061 | + | |
0f6733d8 | 4062 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c WD |
4063 | +{ |
4064 | + struct acl *file_acl = (struct acl *)NULL; | |
4065 | + struct acl_entry *acl_entry; | |
4066 | + struct new_acl_entry *new_acl_entry; | |
4067 | + struct ace_id *idp; | |
4068 | + struct acl_entry_link *acl_entry_link; | |
4069 | + struct acl_entry_link *acl_entry_link_head; | |
4070 | + int i; | |
4071 | + int rc = 0; | |
4072 | + uid_t user_id; | |
4073 | + | |
4074 | + /* Get the acl using fstatacl */ | |
0f6733d8 | 4075 | + |
fa26e11c WD |
4076 | + DEBUG(10,("Entering sys_acl_get_fd\n")); |
4077 | + DEBUG(10,("fd is %d\n",fd)); | |
252945ef | 4078 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 4079 | + |
0f6733d8 | 4080 | + if(file_acl == NULL) { |
fa26e11c WD |
4081 | + errno=ENOMEM; |
4082 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 | 4083 | + return(NULL); |
fa26e11c WD |
4084 | + } |
4085 | + | |
4086 | + memset(file_acl,0,BUFSIZ); | |
4087 | + | |
4088 | + rc = fstatacl(fd,0,file_acl,BUFSIZ); | |
0f6733d8 | 4089 | + if(rc == -1) { |
fa26e11c | 4090 | + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno)); |
0f6733d8 WD |
4091 | + SAFE_FREE(file_acl); |
4092 | + return(NULL); | |
fa26e11c WD |
4093 | + } |
4094 | + | |
4095 | + DEBUG(10,("Got facl and returned it\n")); | |
4096 | + | |
4097 | + /* Point to the first acl entry in the acl */ | |
4098 | + | |
4099 | + acl_entry = file_acl->acl_ext; | |
0f6733d8 WD |
4100 | + /* Begin setting up the head of the linked list * |
4101 | + * that will be used for the storing the acl * | |
4102 | + * in a way that is useful for the posix_acls.c * | |
4103 | + * code. */ | |
fa26e11c WD |
4104 | + |
4105 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); | |
0f6733d8 WD |
4106 | + if(acl_entry_link_head == NULL){ |
4107 | + SAFE_FREE(file_acl); | |
4108 | + return(NULL); | |
fa26e11c WD |
4109 | + } |
4110 | + | |
252945ef | 4111 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
fa26e11c | 4112 | + |
0f6733d8 | 4113 | + if(acl_entry_link->entryp == NULL) { |
fa26e11c WD |
4114 | + errno = ENOMEM; |
4115 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4116 | + SAFE_FREE(file_acl); |
4117 | + return(NULL); | |
fa26e11c WD |
4118 | + } |
4119 | + | |
4120 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); | |
4121 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); | |
0f6733d8 WD |
4122 | + |
4123 | + /* Check if the extended acl bit is on. * | |
4124 | + * If it isn't, do not show the * | |
4125 | + * contents of the acl since AIX intends * | |
4126 | + * the extended info to remain unused */ | |
4127 | + | |
4128 | + if(file_acl->acl_mode & S_IXACL){ | |
fa26e11c | 4129 | + /* while we are not pointing to the very end */ |
0f6733d8 | 4130 | + while(acl_entry < acl_last(file_acl)) { |
fa26e11c WD |
4131 | + /* before we malloc anything, make sure this is */ |
4132 | + /* a valid acl entry and one that we want to map */ | |
4133 | + | |
4134 | + idp = id_nxt(acl_entry->ace_id); | |
0f6733d8 WD |
4135 | + if((acl_entry->ace_type == ACC_SPECIFY || |
4136 | + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { | |
4137 | + acl_entry = acl_nxt(acl_entry); | |
4138 | + continue; | |
fa26e11c WD |
4139 | + } |
4140 | + | |
4141 | + idp = acl_entry->ace_id; | |
0f6733d8 WD |
4142 | + |
4143 | + /* Check if this is the first entry in the linked list. * | |
4144 | + * The first entry needs to keep prevp pointing to NULL * | |
4145 | + * and already has entryp allocated. */ | |
fa26e11c | 4146 | + |
0f6733d8 | 4147 | + if(acl_entry_link_head->count != 0) { |
252945ef | 4148 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 4149 | + if(acl_entry_link->nextp == NULL) { |
fa26e11c WD |
4150 | + errno = ENOMEM; |
4151 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4152 | + SAFE_FREE(file_acl); |
4153 | + return(NULL); | |
fa26e11c WD |
4154 | + } |
4155 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4156 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4157 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 | 4158 | + if(acl_entry_link->entryp == NULL) { |
fa26e11c WD |
4159 | + errno = ENOMEM; |
4160 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4161 | + SAFE_FREE(file_acl); |
4162 | + return(NULL); | |
fa26e11c WD |
4163 | + } |
4164 | + | |
4165 | + acl_entry_link->nextp = NULL; | |
4166 | + } | |
4167 | + | |
4168 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; | |
4169 | + | |
0f6733d8 WD |
4170 | + /* Don't really need this since all types are going * |
4171 | + * to be specified but, it's better than leaving it 0 */ | |
fa26e11c WD |
4172 | + |
4173 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; | |
4174 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4175 | + | |
0f6733d8 | 4176 | + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id)); |
fa26e11c | 4177 | + |
0f6733d8 WD |
4178 | + /* The access in the acl entries must be left shifted by * |
4179 | + * three bites, because they will ultimately be compared * | |
4180 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ | |
fa26e11c | 4181 | + |
0f6733d8 | 4182 | + switch(acl_entry->ace_type){ |
fa26e11c WD |
4183 | + case ACC_PERMIT: |
4184 | + case ACC_SPECIFY: | |
4185 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4186 | + acl_entry_link->entryp->ace_access <<= 6; | |
4187 | + acl_entry_link_head->count++; | |
4188 | + break; | |
4189 | + case ACC_DENY: | |
0f6733d8 WD |
4190 | + /* Since there is no way to return a DENY acl entry * |
4191 | + * change to PERMIT and then shift. */ | |
fa26e11c WD |
4192 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); |
4193 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; | |
4194 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); | |
4195 | + acl_entry_link->entryp->ace_access <<= 6; | |
4196 | + acl_entry_link_head->count++; | |
4197 | + break; | |
4198 | + default: | |
0f6733d8 | 4199 | + return(0); |
fa26e11c WD |
4200 | + } |
4201 | + | |
4202 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); | |
4203 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); | |
0f6733d8 | 4204 | + |
fa26e11c WD |
4205 | + acl_entry = acl_nxt(acl_entry); |
4206 | + } | |
4207 | + } /* end of if enabled */ | |
4208 | + | |
0f6733d8 WD |
4209 | + /* Since owner, group, other acl entries are not * |
4210 | + * part of the acl entries in an acl, they must * | |
4211 | + * be dummied up to become part of the list. */ | |
fa26e11c | 4212 | + |
0f6733d8 | 4213 | + for( i = 1; i < 4; i++) { |
fa26e11c | 4214 | + DEBUG(10,("i is %d\n",i)); |
0f6733d8 | 4215 | + if(acl_entry_link_head->count != 0){ |
252945ef | 4216 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 4217 | + if(acl_entry_link->nextp == NULL) { |
fa26e11c WD |
4218 | + errno = ENOMEM; |
4219 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4220 | + SAFE_FREE(file_acl); |
4221 | + return(NULL); | |
fa26e11c WD |
4222 | + } |
4223 | + | |
4224 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4225 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4226 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
fa26e11c | 4227 | + |
0f6733d8 WD |
4228 | + if(acl_entry_link->entryp == NULL) { |
4229 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4230 | + errno = ENOMEM; |
4231 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 | 4232 | + return(NULL); |
fa26e11c WD |
4233 | + } |
4234 | + } | |
4235 | + | |
4236 | + acl_entry_link->nextp = NULL; | |
0f6733d8 | 4237 | + |
fa26e11c WD |
4238 | + new_acl_entry = acl_entry_link->entryp; |
4239 | + idp = new_acl_entry->ace_id; | |
0f6733d8 WD |
4240 | + |
4241 | + new_acl_entry->ace_len = sizeof(struct acl_entry); | |
fa26e11c | 4242 | + new_acl_entry->ace_type = ACC_PERMIT; |
0f6733d8 | 4243 | + idp->id_len = sizeof(struct ace_id); |
fa26e11c | 4244 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); |
0f6733d8 WD |
4245 | + memset(idp->id_data,0,sizeof(uid_t)); |
4246 | + | |
4247 | + switch(i) { | |
fa26e11c WD |
4248 | + case 2: |
4249 | + new_acl_entry->ace_access = file_acl->g_access << 6; | |
4250 | + idp->id_type = SMB_ACL_GROUP_OBJ; | |
4251 | + break; | |
0f6733d8 | 4252 | + |
fa26e11c WD |
4253 | + case 3: |
4254 | + new_acl_entry->ace_access = file_acl->o_access << 6; | |
4255 | + idp->id_type = SMB_ACL_OTHER; | |
4256 | + break; | |
0f6733d8 | 4257 | + |
fa26e11c WD |
4258 | + case 1: |
4259 | + new_acl_entry->ace_access = file_acl->u_access << 6; | |
4260 | + idp->id_type = SMB_ACL_USER_OBJ; | |
4261 | + break; | |
0f6733d8 | 4262 | + |
fa26e11c | 4263 | + default: |
0f6733d8 | 4264 | + return(NULL); |
fa26e11c | 4265 | + } |
0f6733d8 | 4266 | + |
fa26e11c WD |
4267 | + acl_entry_link_head->count++; |
4268 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); | |
4269 | + } | |
4270 | + | |
4271 | + acl_entry_link_head->count = 0; | |
0f6733d8 WD |
4272 | + SAFE_FREE(file_acl); |
4273 | + | |
4274 | + return(acl_entry_link_head); | |
fa26e11c WD |
4275 | +} |
4276 | + | |
0f6733d8 | 4277 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
4278 | +{ |
4279 | + *permset = *permset & ~0777; | |
0f6733d8 | 4280 | + return(0); |
fa26e11c WD |
4281 | +} |
4282 | + | |
0f6733d8 | 4283 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 4284 | +{ |
0f6733d8 WD |
4285 | + if((perm != 0) && |
4286 | + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0) | |
4287 | + return(-1); | |
fa26e11c WD |
4288 | + |
4289 | + *permset |= perm; | |
4290 | + DEBUG(10,("This is the permset now: %d\n",*permset)); | |
0f6733d8 | 4291 | + return(0); |
fa26e11c WD |
4292 | +} |
4293 | + | |
0f6733d8 | 4294 | +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) |
fa26e11c | 4295 | +{ |
0f6733d8 | 4296 | + return(NULL); |
fa26e11c WD |
4297 | +} |
4298 | + | |
0f6733d8 | 4299 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
4300 | +{ |
4301 | + struct acl_entry_link *theacl = NULL; | |
0f6733d8 | 4302 | + |
fa26e11c WD |
4303 | + DEBUG(10,("Entering sys_acl_init\n")); |
4304 | + | |
252945ef | 4305 | + theacl = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 4306 | + if(theacl == NULL) { |
fa26e11c WD |
4307 | + errno = ENOMEM; |
4308 | + DEBUG(0,("Error in sys_acl_init is %d\n",errno)); | |
0f6733d8 | 4309 | + return(NULL); |
fa26e11c WD |
4310 | + } |
4311 | + | |
4312 | + theacl->count = 0; | |
4313 | + theacl->nextp = NULL; | |
4314 | + theacl->prevp = NULL; | |
4315 | + theacl->entryp = NULL; | |
4316 | + DEBUG(10,("Exiting sys_acl_init\n")); | |
0f6733d8 | 4317 | + return(theacl); |
fa26e11c WD |
4318 | +} |
4319 | + | |
0f6733d8 | 4320 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
4321 | +{ |
4322 | + struct acl_entry_link *theacl; | |
4323 | + struct acl_entry_link *acl_entryp; | |
4324 | + struct acl_entry_link *temp_entry; | |
4325 | + int counting; | |
4326 | + | |
4327 | + DEBUG(10,("Entering the sys_acl_create_entry\n")); | |
4328 | + | |
4329 | + theacl = acl_entryp = *pacl; | |
4330 | + | |
4331 | + /* Get to the end of the acl before adding entry */ | |
4332 | + | |
0f6733d8 | 4333 | + for(counting=0; counting < theacl->count; counting++){ |
fa26e11c WD |
4334 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); |
4335 | + temp_entry = acl_entryp; | |
4336 | + acl_entryp = acl_entryp->nextp; | |
4337 | + } | |
4338 | + | |
0f6733d8 | 4339 | + if(theacl->count != 0){ |
252945ef | 4340 | + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 4341 | + if(acl_entryp == NULL) { |
fa26e11c WD |
4342 | + errno = ENOMEM; |
4343 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); | |
0f6733d8 | 4344 | + return(-1); |
fa26e11c WD |
4345 | + } |
4346 | + | |
4347 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); | |
4348 | + acl_entryp->prevp = temp_entry; | |
4349 | + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp)); | |
4350 | + } | |
4351 | + | |
252945ef | 4352 | + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 | 4353 | + if(*pentry == NULL) { |
fa26e11c WD |
4354 | + errno = ENOMEM; |
4355 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); | |
0f6733d8 | 4356 | + return(-1); |
fa26e11c WD |
4357 | + } |
4358 | + | |
0f6733d8 WD |
4359 | + memset(*pentry,0,sizeof(struct new_acl_entry)); |
4360 | + acl_entryp->entryp->ace_len = sizeof(struct acl_entry); | |
fa26e11c | 4361 | + acl_entryp->entryp->ace_type = ACC_PERMIT; |
0f6733d8 | 4362 | + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id); |
fa26e11c WD |
4363 | + acl_entryp->nextp = NULL; |
4364 | + theacl->count++; | |
4365 | + DEBUG(10,("Exiting sys_acl_create_entry\n")); | |
0f6733d8 | 4366 | + return(0); |
fa26e11c WD |
4367 | +} |
4368 | + | |
0f6733d8 | 4369 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
4370 | +{ |
4371 | + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n")); | |
4372 | + entry->ace_id->id_type = tagtype; | |
4373 | + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type)); | |
4374 | + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n")); | |
4375 | +} | |
4376 | + | |
0f6733d8 | 4377 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
4378 | +{ |
4379 | + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n")); | |
0f6733d8 | 4380 | + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t)); |
fa26e11c | 4381 | + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n")); |
0f6733d8 | 4382 | + return(0); |
fa26e11c WD |
4383 | +} |
4384 | + | |
0f6733d8 | 4385 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
4386 | +{ |
4387 | + DEBUG(10,("Starting AIX sys_acl_set_permset\n")); | |
0f6733d8 WD |
4388 | + if(!(*permset & S_IXUSR) && |
4389 | + !(*permset & S_IWUSR) && | |
4390 | + !(*permset & S_IRUSR) && | |
4391 | + (*permset != 0)) | |
4392 | + return(-1); | |
fa26e11c WD |
4393 | + |
4394 | + entry->ace_access = *permset; | |
4395 | + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access)); | |
4396 | + DEBUG(10,("Ending AIX sys_acl_set_permset\n")); | |
0f6733d8 | 4397 | + return(0); |
fa26e11c WD |
4398 | +} |
4399 | + | |
0f6733d8 | 4400 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c WD |
4401 | +{ |
4402 | + int user_obj = 0; | |
4403 | + int group_obj = 0; | |
4404 | + int other_obj = 0; | |
4405 | + struct acl_entry_link *acl_entry; | |
4406 | + | |
0f6733d8 | 4407 | + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) { |
fa26e11c WD |
4408 | + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ); |
4409 | + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ); | |
4410 | + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER); | |
4411 | + } | |
4412 | + | |
4413 | + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj)); | |
0f6733d8 WD |
4414 | + |
4415 | + if(user_obj != 1 || group_obj != 1 || other_obj != 1) | |
4416 | + return(-1); | |
fa26e11c | 4417 | + |
0f6733d8 | 4418 | + return(0); |
fa26e11c WD |
4419 | +} |
4420 | + | |
0f6733d8 | 4421 | +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
fa26e11c WD |
4422 | +{ |
4423 | + struct acl_entry_link *acl_entry_link = NULL; | |
4424 | + struct acl *file_acl = NULL; | |
4425 | + struct acl *file_acl_temp = NULL; | |
4426 | + struct acl_entry *acl_entry = NULL; | |
4427 | + struct ace_id *ace_id = NULL; | |
4428 | + uint id_type; | |
4429 | + uint ace_access; | |
4430 | + uint user_id; | |
4431 | + uint acl_length; | |
4432 | + uint rc; | |
4433 | + | |
4434 | + DEBUG(10,("Entering sys_acl_set_file\n")); | |
4435 | + DEBUG(10,("File name is %s\n",name)); | |
0f6733d8 | 4436 | + |
fa26e11c | 4437 | + /* AIX has no default ACL */ |
0f6733d8 WD |
4438 | + if(acltype == SMB_ACL_TYPE_DEFAULT) |
4439 | + return(0); | |
fa26e11c WD |
4440 | + |
4441 | + acl_length = BUFSIZ; | |
252945ef | 4442 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 4443 | + |
0f6733d8 | 4444 | + if(file_acl == NULL) { |
fa26e11c WD |
4445 | + errno = ENOMEM; |
4446 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); | |
0f6733d8 | 4447 | + return(-1); |
fa26e11c WD |
4448 | + } |
4449 | + | |
4450 | + memset(file_acl,0,BUFSIZ); | |
4451 | + | |
4452 | + file_acl->acl_len = ACL_SIZ; | |
4453 | + file_acl->acl_mode = S_IXACL; | |
4454 | + | |
0f6733d8 | 4455 | + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
fa26e11c WD |
4456 | + acl_entry_link->entryp->ace_access >>= 6; |
4457 | + id_type = acl_entry_link->entryp->ace_id->id_type; | |
4458 | + | |
0f6733d8 | 4459 | + switch(id_type) { |
fa26e11c WD |
4460 | + case SMB_ACL_USER_OBJ: |
4461 | + file_acl->u_access = acl_entry_link->entryp->ace_access; | |
4462 | + continue; | |
4463 | + case SMB_ACL_GROUP_OBJ: | |
4464 | + file_acl->g_access = acl_entry_link->entryp->ace_access; | |
4465 | + continue; | |
4466 | + case SMB_ACL_OTHER: | |
4467 | + file_acl->o_access = acl_entry_link->entryp->ace_access; | |
4468 | + continue; | |
4469 | + case SMB_ACL_MASK: | |
4470 | + continue; | |
4471 | + } | |
4472 | + | |
0f6733d8 WD |
4473 | + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { |
4474 | + acl_length += sizeof(struct acl_entry); | |
252945ef | 4475 | + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
0f6733d8 WD |
4476 | + if(file_acl_temp == NULL) { |
4477 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4478 | + errno = ENOMEM; |
4479 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); | |
0f6733d8 WD |
4480 | + return(-1); |
4481 | + } | |
fa26e11c WD |
4482 | + |
4483 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); | |
0f6733d8 | 4484 | + SAFE_FREE(file_acl); |
fa26e11c WD |
4485 | + file_acl = file_acl_temp; |
4486 | + } | |
4487 | + | |
4488 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); | |
0f6733d8 | 4489 | + file_acl->acl_len += sizeof(struct acl_entry); |
fa26e11c WD |
4490 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
4491 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; | |
0f6733d8 | 4492 | + |
fa26e11c | 4493 | + /* In order to use this, we'll need to wait until we can get denies */ |
0f6733d8 WD |
4494 | + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) |
4495 | + acl_entry->ace_type = ACC_SPECIFY; */ | |
fa26e11c WD |
4496 | + |
4497 | + acl_entry->ace_type = ACC_SPECIFY; | |
0f6733d8 | 4498 | + |
fa26e11c | 4499 | + ace_id = acl_entry->ace_id; |
0f6733d8 | 4500 | + |
fa26e11c WD |
4501 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
4502 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); | |
4503 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; | |
0f6733d8 WD |
4504 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t)); |
4505 | + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t)); | |
fa26e11c WD |
4506 | + } |
4507 | + | |
0f6733d8 | 4508 | + rc = chacl(name,file_acl,file_acl->acl_len); |
fa26e11c WD |
4509 | + DEBUG(10,("errno is %d\n",errno)); |
4510 | + DEBUG(10,("return code is %d\n",rc)); | |
0f6733d8 | 4511 | + SAFE_FREE(file_acl); |
fa26e11c | 4512 | + DEBUG(10,("Exiting the sys_acl_set_file\n")); |
0f6733d8 | 4513 | + return(rc); |
fa26e11c WD |
4514 | +} |
4515 | + | |
0f6733d8 | 4516 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
4517 | +{ |
4518 | + struct acl_entry_link *acl_entry_link = NULL; | |
4519 | + struct acl *file_acl = NULL; | |
4520 | + struct acl *file_acl_temp = NULL; | |
4521 | + struct acl_entry *acl_entry = NULL; | |
4522 | + struct ace_id *ace_id = NULL; | |
4523 | + uint id_type; | |
4524 | + uint user_id; | |
4525 | + uint acl_length; | |
4526 | + uint rc; | |
0f6733d8 | 4527 | + |
fa26e11c WD |
4528 | + DEBUG(10,("Entering sys_acl_set_fd\n")); |
4529 | + acl_length = BUFSIZ; | |
252945ef | 4530 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 4531 | + |
0f6733d8 | 4532 | + if(file_acl == NULL) { |
fa26e11c WD |
4533 | + errno = ENOMEM; |
4534 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); | |
0f6733d8 | 4535 | + return(-1); |
fa26e11c WD |
4536 | + } |
4537 | + | |
4538 | + memset(file_acl,0,BUFSIZ); | |
0f6733d8 | 4539 | + |
fa26e11c WD |
4540 | + file_acl->acl_len = ACL_SIZ; |
4541 | + file_acl->acl_mode = S_IXACL; | |
4542 | + | |
0f6733d8 | 4543 | + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
fa26e11c WD |
4544 | + acl_entry_link->entryp->ace_access >>= 6; |
4545 | + id_type = acl_entry_link->entryp->ace_id->id_type; | |
4546 | + DEBUG(10,("The id_type is %d\n",id_type)); | |
4547 | + | |
0f6733d8 | 4548 | + switch(id_type) { |
fa26e11c WD |
4549 | + case SMB_ACL_USER_OBJ: |
4550 | + file_acl->u_access = acl_entry_link->entryp->ace_access; | |
4551 | + continue; | |
4552 | + case SMB_ACL_GROUP_OBJ: | |
4553 | + file_acl->g_access = acl_entry_link->entryp->ace_access; | |
4554 | + continue; | |
4555 | + case SMB_ACL_OTHER: | |
4556 | + file_acl->o_access = acl_entry_link->entryp->ace_access; | |
4557 | + continue; | |
4558 | + case SMB_ACL_MASK: | |
4559 | + continue; | |
4560 | + } | |
4561 | + | |
0f6733d8 WD |
4562 | + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { |
4563 | + acl_length += sizeof(struct acl_entry); | |
252945ef | 4564 | + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
0f6733d8 WD |
4565 | + if(file_acl_temp == NULL) { |
4566 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4567 | + errno = ENOMEM; |
4568 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); | |
0f6733d8 | 4569 | + return(-1); |
fa26e11c WD |
4570 | + } |
4571 | + | |
4572 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); | |
0f6733d8 | 4573 | + SAFE_FREE(file_acl); |
fa26e11c WD |
4574 | + file_acl = file_acl_temp; |
4575 | + } | |
4576 | + | |
4577 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); | |
0f6733d8 | 4578 | + file_acl->acl_len += sizeof(struct acl_entry); |
fa26e11c WD |
4579 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
4580 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; | |
0f6733d8 | 4581 | + |
fa26e11c | 4582 | + /* In order to use this, we'll need to wait until we can get denies */ |
0f6733d8 | 4583 | + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) |
fa26e11c | 4584 | + acl_entry->ace_type = ACC_SPECIFY; */ |
0f6733d8 | 4585 | + |
fa26e11c | 4586 | + acl_entry->ace_type = ACC_SPECIFY; |
0f6733d8 | 4587 | + |
fa26e11c | 4588 | + ace_id = acl_entry->ace_id; |
0f6733d8 | 4589 | + |
fa26e11c WD |
4590 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
4591 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); | |
4592 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; | |
0f6733d8 WD |
4593 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t)); |
4594 | + memcpy(ace_id->id_data, &user_id, sizeof(uid_t)); | |
fa26e11c | 4595 | + } |
0f6733d8 | 4596 | + |
fa26e11c WD |
4597 | + rc = fchacl(fd,file_acl,file_acl->acl_len); |
4598 | + DEBUG(10,("errno is %d\n",errno)); | |
4599 | + DEBUG(10,("return code is %d\n",rc)); | |
0f6733d8 | 4600 | + SAFE_FREE(file_acl); |
fa26e11c | 4601 | + DEBUG(10,("Exiting sys_acl_set_fd\n")); |
0f6733d8 | 4602 | + return(rc); |
fa26e11c WD |
4603 | +} |
4604 | + | |
0f6733d8 | 4605 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
4606 | +{ |
4607 | + /* AIX has no default ACL */ | |
4608 | + return 0; | |
4609 | +} | |
4610 | + | |
0f6733d8 | 4611 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 4612 | +{ |
0f6733d8 | 4613 | + return(*permset & perm); |
fa26e11c WD |
4614 | +} |
4615 | + | |
0f6733d8 | 4616 | +int sys_acl_free_text(char *text) |
fa26e11c | 4617 | +{ |
0f6733d8 | 4618 | + return(0); |
fa26e11c WD |
4619 | +} |
4620 | + | |
0f6733d8 | 4621 | +int sys_acl_free_acl(SMB_ACL_T posix_acl) |
fa26e11c WD |
4622 | +{ |
4623 | + struct acl_entry_link *acl_entry_link; | |
4624 | + | |
0f6733d8 WD |
4625 | + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) { |
4626 | + SAFE_FREE(acl_entry_link->prevp->entryp); | |
4627 | + SAFE_FREE(acl_entry_link->prevp); | |
fa26e11c WD |
4628 | + } |
4629 | + | |
0f6733d8 WD |
4630 | + SAFE_FREE(acl_entry_link->prevp->entryp); |
4631 | + SAFE_FREE(acl_entry_link->prevp); | |
4632 | + SAFE_FREE(acl_entry_link->entryp); | |
4633 | + SAFE_FREE(acl_entry_link); | |
4634 | + | |
4635 | + return(0); | |
fa26e11c WD |
4636 | +} |
4637 | + | |
0f6733d8 | 4638 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c | 4639 | +{ |
0f6733d8 | 4640 | + return(0); |
fa26e11c WD |
4641 | +} |
4642 | + | |
4643 | +#else /* No ACLs. */ | |
4644 | + | |
4df546eb | 4645 | +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p)) |
fa26e11c WD |
4646 | +{ |
4647 | + errno = ENOSYS; | |
4648 | + return -1; | |
4649 | +} | |
4650 | + | |
4df546eb | 4651 | +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p)) |
fa26e11c WD |
4652 | +{ |
4653 | + errno = ENOSYS; | |
4654 | + return -1; | |
4655 | +} | |
4656 | + | |
4df546eb | 4657 | +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p)) |
fa26e11c WD |
4658 | +{ |
4659 | + errno = ENOSYS; | |
4660 | + return -1; | |
4661 | +} | |
4662 | + | |
4df546eb | 4663 | +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d)) |
fa26e11c WD |
4664 | +{ |
4665 | + errno = ENOSYS; | |
4666 | + return NULL; | |
4667 | +} | |
4668 | + | |
4df546eb | 4669 | +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type)) |
fa26e11c WD |
4670 | +{ |
4671 | + errno = ENOSYS; | |
5ca9317d | 4672 | + return (SMB_ACL_T)NULL; |
fa26e11c WD |
4673 | +} |
4674 | + | |
4df546eb | 4675 | +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd)) |
fa26e11c WD |
4676 | +{ |
4677 | + errno = ENOSYS; | |
5ca9317d | 4678 | + return (SMB_ACL_T)NULL; |
fa26e11c WD |
4679 | +} |
4680 | + | |
4df546eb | 4681 | +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset)) |
fa26e11c WD |
4682 | +{ |
4683 | + errno = ENOSYS; | |
4684 | + return -1; | |
4685 | +} | |
4686 | + | |
4df546eb | 4687 | +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm)) |
fa26e11c WD |
4688 | +{ |
4689 | + errno = ENOSYS; | |
4690 | + return -1; | |
4691 | +} | |
4692 | + | |
0f6733d8 | 4693 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
4694 | +{ |
4695 | + errno = ENOSYS; | |
0f6733d8 | 4696 | + return (permset & perm) ? 1 : 0; |
fa26e11c WD |
4697 | +} |
4698 | + | |
4df546eb | 4699 | +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen)) |
fa26e11c WD |
4700 | +{ |
4701 | + errno = ENOSYS; | |
4702 | + return NULL; | |
4703 | +} | |
4704 | + | |
4df546eb | 4705 | +int sys_acl_free_text(UNUSED(char *text)) |
fa26e11c WD |
4706 | +{ |
4707 | + errno = ENOSYS; | |
4708 | + return -1; | |
4709 | +} | |
4710 | + | |
4df546eb | 4711 | +SMB_ACL_T sys_acl_init(UNUSED(int count)) |
fa26e11c WD |
4712 | +{ |
4713 | + errno = ENOSYS; | |
4714 | + return NULL; | |
4715 | +} | |
4716 | + | |
4df546eb | 4717 | +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry)) |
fa26e11c WD |
4718 | +{ |
4719 | + errno = ENOSYS; | |
4720 | + return -1; | |
4721 | +} | |
4722 | + | |
4df546eb | 4723 | +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
4724 | +{ |
4725 | + errno = ENOSYS; | |
4726 | + return -1; | |
4727 | +} | |
4728 | + | |
4df546eb | 4729 | +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual)) |
fa26e11c WD |
4730 | +{ |
4731 | + errno = ENOSYS; | |
4732 | + return -1; | |
4733 | +} | |
4734 | + | |
4df546eb | 4735 | +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset)) |
fa26e11c WD |
4736 | +{ |
4737 | + errno = ENOSYS; | |
4738 | + return -1; | |
4739 | +} | |
4740 | + | |
4df546eb | 4741 | +int sys_acl_valid(UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
4742 | +{ |
4743 | + errno = ENOSYS; | |
4744 | + return -1; | |
4745 | +} | |
4746 | + | |
4df546eb | 4747 | +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
4748 | +{ |
4749 | + errno = ENOSYS; | |
4750 | + return -1; | |
4751 | +} | |
4752 | + | |
4df546eb | 4753 | +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
4754 | +{ |
4755 | + errno = ENOSYS; | |
4756 | + return -1; | |
4757 | +} | |
4758 | + | |
4df546eb | 4759 | +int sys_acl_delete_def_file(UNUSED(const char *name)) |
fa26e11c WD |
4760 | +{ |
4761 | + errno = ENOSYS; | |
4762 | + return -1; | |
4763 | +} | |
4764 | + | |
4df546eb | 4765 | +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl)) |
fa26e11c WD |
4766 | +{ |
4767 | + errno = ENOSYS; | |
4768 | + return -1; | |
4769 | +} | |
4770 | + | |
4df546eb | 4771 | +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
4772 | +{ |
4773 | + errno = ENOSYS; | |
4774 | + return -1; | |
4775 | +} | |
4776 | + | |
4777 | +#endif /* No ACLs. */ | |
252945ef WD |
4778 | + |
4779 | +/************************************************************************ | |
4780 | + Deliberately outside the ACL defines. Return 1 if this is a "no acls" | |
4781 | + errno, 0 if not. | |
4782 | +************************************************************************/ | |
4783 | + | |
4784 | +int no_acl_syscall_error(int err) | |
4785 | +{ | |
4786 | +#if defined(ENOSYS) | |
4787 | + if (err == ENOSYS) { | |
4788 | + return 1; | |
4789 | + } | |
4790 | +#endif | |
4791 | +#if defined(ENOTSUP) | |
4792 | + if (err == ENOTSUP) { | |
4793 | + return 1; | |
4794 | + } | |
4795 | +#endif | |
4796 | + return 0; | |
4797 | +} | |
9a7eef96 WD |
4798 | --- old/lib/sysacls.h |
4799 | +++ new/lib/sysacls.h | |
252945ef WD |
4800 | @@ -0,0 +1,28 @@ |
4801 | +#define SMB_MALLOC(cnt) new_array(char, cnt) | |
4802 | +#define SMB_MALLOC_P(obj) new_array(obj, 1) | |
4803 | +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt) | |
4804 | +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt) | |
5ca9317d | 4805 | +#define slprintf snprintf |
0f6733d8 WD |
4806 | + |
4807 | +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p); | |
4808 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p); | |
4809 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p); | |
4810 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d); | |
4811 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type); | |
4812 | +SMB_ACL_T sys_acl_get_fd(int fd); | |
4813 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); | |
4814 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
4815 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
4816 | +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen); | |
4817 | +SMB_ACL_T sys_acl_init(int count); | |
4818 | +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry); | |
4819 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype); | |
4820 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual); | |
4821 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset); | |
4822 | +int sys_acl_valid(SMB_ACL_T theacl); | |
4823 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); | |
4824 | +int sys_acl_set_fd(int fd, SMB_ACL_T theacl); | |
4825 | +int sys_acl_delete_def_file(const char *name); | |
4826 | +int sys_acl_free_text(char *text); | |
4827 | +int sys_acl_free_acl(SMB_ACL_T the_acl); | |
4828 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype); | |
9a7eef96 WD |
4829 | --- old/mkproto.awk |
4830 | +++ new/mkproto.awk | |
0f6733d8 WD |
4831 | @@ -58,7 +58,7 @@ BEGIN { |
4832 | next; | |
4833 | } | |
4834 | ||
bc5988ec WD |
4835 | -!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ { |
4836 | +!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ { | |
0f6733d8 WD |
4837 | next; |
4838 | } | |
4839 | ||
9a7eef96 WD |
4840 | --- old/options.c |
4841 | +++ new/options.c | |
2578e2b6 | 4842 | @@ -45,6 +45,7 @@ int copy_dirlinks = 0; |
0f6733d8 WD |
4843 | int copy_links = 0; |
4844 | int preserve_links = 0; | |
4845 | int preserve_hard_links = 0; | |
4846 | +int preserve_acls = 0; | |
4847 | int preserve_perms = 0; | |
90fa6d68 | 4848 | int preserve_executability = 0; |
0f6733d8 | 4849 | int preserve_devices = 0; |
2578e2b6 | 4850 | @@ -194,6 +195,7 @@ static void print_rsync_version(enum log |
0f6733d8 WD |
4851 | char const *got_socketpair = "no "; |
4852 | char const *have_inplace = "no "; | |
4853 | char const *hardlinks = "no "; | |
4854 | + char const *acls = "no "; | |
4855 | char const *links = "no "; | |
4856 | char const *ipv6 = "no "; | |
4857 | STRUCT_STAT *dumstat; | |
2578e2b6 | 4858 | @@ -210,6 +212,10 @@ static void print_rsync_version(enum log |
0f6733d8 WD |
4859 | hardlinks = ""; |
4860 | #endif | |
4861 | ||
09fb8f03 | 4862 | +#ifdef SUPPORT_ACLS |
0f6733d8 WD |
4863 | + acls = ""; |
4864 | +#endif | |
4865 | + | |
09fb8f03 | 4866 | #ifdef SUPPORT_LINKS |
0f6733d8 WD |
4867 | links = ""; |
4868 | #endif | |
2578e2b6 | 4869 | @@ -223,9 +229,9 @@ static void print_rsync_version(enum log |
3b05e91f | 4870 | rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n"); |
0f6733d8 WD |
4871 | rprintf(f, "<http://rsync.samba.org/>\n"); |
4872 | rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, " | |
bc5988ec WD |
4873 | - "%shard links, %ssymlinks, batchfiles,\n", |
4874 | + "%shard links, %sACLs, %ssymlinks, batchfiles,\n", | |
0f6733d8 WD |
4875 | (int) (sizeof (OFF_T) * 8), |
4876 | - got_socketpair, hardlinks, links); | |
4877 | + got_socketpair, hardlinks, acls, links); | |
4878 | ||
4879 | /* Note that this field may not have type ino_t. It depends | |
4880 | * on the complicated interaction between largefile feature | |
2578e2b6 WD |
4881 | @@ -295,6 +301,9 @@ void usage(enum logcode F) |
4882 | rprintf(F," -H, --hard-links preserve hard links\n"); | |
0f6733d8 | 4883 | rprintf(F," -p, --perms preserve permissions\n"); |
90fa6d68 | 4884 | rprintf(F," -E, --executability preserve the file's executability\n"); |
25d385b9 | 4885 | +#ifdef SUPPORT_ACLS |
0f6733d8 | 4886 | + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n"); |
25d385b9 | 4887 | +#endif |
90fa6d68 WD |
4888 | rprintf(F," --chmod=CHMOD change destination permissions\n"); |
4889 | rprintf(F," -o, --owner preserve owner (super-user only)\n"); | |
0f6733d8 | 4890 | rprintf(F," -g, --group preserve group\n"); |
2578e2b6 | 4891 | @@ -410,6 +419,9 @@ static struct poptOption long_options[] |
489b0a72 WD |
4892 | {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, |
4893 | {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
90fa6d68 | 4894 | {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 }, |
489b0a72 WD |
4895 | + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
4896 | + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
4897 | + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
4898 | {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 }, | |
4899 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
4900 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
a5e3a4cc | 4901 | @@ -1068,6 +1080,24 @@ int parse_arguments(int *argc, const cha |
3b05e91f WD |
4902 | usage(FINFO); |
4903 | exit_cleanup(0); | |
0f6733d8 WD |
4904 | |
4905 | + case 'A': | |
4df546eb | 4906 | +#ifdef SUPPORT_ACLS |
a5e3a4cc WD |
4907 | + preserve_acls++; |
4908 | + preserve_perms = 1; | |
489b0a72 | 4909 | + break; |
0f6733d8 WD |
4910 | +#else |
4911 | + /* FIXME: this should probably be ignored with a | |
4912 | + * warning and then countermeasures taken to | |
4913 | + * restrict group and other access in the presence | |
4914 | + * of any more restrictive ACLs, but this is safe | |
4915 | + * for now */ | |
4916 | + snprintf(err_buf,sizeof(err_buf), | |
4917 | + "ACLs are not supported on this %s\n", | |
4918 | + am_server ? "server" : "client"); | |
4919 | + return 0; | |
25d385b9 | 4920 | +#endif |
0f6733d8 WD |
4921 | + |
4922 | + | |
4923 | default: | |
4924 | /* A large opt value means that set_refuse_options() | |
27a7053c | 4925 | * turned this option off. */ |
a5e3a4cc | 4926 | @@ -1511,6 +1541,10 @@ void server_options(char **args,int *arg |
c7bc7375 | 4927 | |
0f6733d8 WD |
4928 | if (preserve_hard_links) |
4929 | argstr[x++] = 'H'; | |
25d385b9 | 4930 | +#ifdef SUPPORT_ACLS |
0f6733d8 WD |
4931 | + if (preserve_acls) |
4932 | + argstr[x++] = 'A'; | |
25d385b9 | 4933 | +#endif |
0f6733d8 WD |
4934 | if (preserve_uid) |
4935 | argstr[x++] = 'o'; | |
4936 | if (preserve_gid) | |
9a7eef96 WD |
4937 | --- old/receiver.c |
4938 | +++ new/receiver.c | |
2578e2b6 | 4939 | @@ -46,6 +46,7 @@ extern int keep_partial; |
1a2fa68f WD |
4940 | extern int checksum_seed; |
4941 | extern int inplace; | |
4942 | extern int delay_updates; | |
4943 | +extern mode_t orig_umask; | |
4944 | extern struct stats stats; | |
4945 | extern char *log_format; | |
4946 | extern char *tmpdir; | |
2578e2b6 | 4947 | @@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis |
26c810d8 WD |
4948 | int itemizing = am_daemon ? daemon_log_format_has_i |
4949 | : !am_server && log_format_has_i; | |
4950 | int max_phase = protocol_version >= 29 ? 2 : 1; | |
4951 | + int dflt_perms = (ACCESSPERMS & ~orig_umask); | |
5c8b4e6e | 4952 | +#ifdef SUPPORT_ACLS |
26c810d8 | 4953 | + char *parent_dirname = ""; |
5c8b4e6e | 4954 | +#endif |
26c810d8 WD |
4955 | int i, recv_ok; |
4956 | ||
4957 | if (verbose > 2) | |
2578e2b6 | 4958 | @@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis |
90fa6d68 WD |
4959 | * mode based on the local permissions and some heuristics. */ |
4960 | if (!preserve_perms) { | |
4961 | int exists = fd1 != -1; | |
4962 | - file->mode = dest_mode(file->mode, st.st_mode, exists); | |
26c810d8 | 4963 | +#ifdef SUPPORT_ACLS |
5c8b4e6e WD |
4964 | + char *dn = file->dirname ? file->dirname : "."; |
4965 | + if (parent_dirname != dn | |
4966 | + && strcmp(parent_dirname, dn) != 0) { | |
4967 | + dflt_perms = default_perms_for_dir(dn); | |
4968 | + parent_dirname = dn; | |
26c810d8 WD |
4969 | + } |
4970 | +#endif | |
4971 | + file->mode = dest_mode(file->mode, st.st_mode, | |
4972 | + dflt_perms, exists); | |
90fa6d68 WD |
4973 | } |
4974 | ||
4975 | /* We now check to see if we are writing file "inplace" */ | |
9a7eef96 WD |
4976 | --- old/rsync.c |
4977 | +++ new/rsync.c | |
162234a7 WD |
4978 | @@ -33,6 +33,7 @@ |
4979 | extern int verbose; | |
4980 | extern int dry_run; | |
4981 | extern int daemon_log_format_has_i; | |
4982 | +extern int preserve_acls; | |
4983 | extern int preserve_perms; | |
4984 | extern int preserve_executability; | |
4985 | extern int preserve_times; | |
4986 | @@ -101,7 +102,8 @@ void free_sums(struct sum_struct *s) | |
90fa6d68 WD |
4987 | |
4988 | /* This is only called when we aren't preserving permissions. Figure out what | |
4989 | * the permissions should be and return them merged back into the mode. */ | |
02929d4c WD |
4990 | -mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists) |
4991 | +mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms, | |
26c810d8 | 4992 | + int exists) |
90fa6d68 | 4993 | { |
25d385b9 | 4994 | /* If the file already exists, we'll return the local permissions, |
90fa6d68 | 4995 | * possibly tweaked by the --executability option. */ |
162234a7 | 4996 | @@ -116,7 +118,7 @@ mode_t dest_mode(mode_t flist_mode, mode |
02929d4c | 4997 | cur_mode |= (cur_mode & 0444) >> 2; |
90fa6d68 | 4998 | } |
26c810d8 | 4999 | } else |
02929d4c | 5000 | - cur_mode = flist_mode & ACCESSPERMS & ~orig_umask; |
81ddc4dc | 5001 | + cur_mode = flist_mode & ACCESSPERMS & dflt_perms; |
c769ea2c WD |
5002 | if (daemon_chmod_modes && !S_ISLNK(flist_mode)) |
5003 | cur_mode = tweak_mode(cur_mode, daemon_chmod_modes); | |
02929d4c | 5004 | return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS); |
c6437996 WD |
5005 | @@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f |
5006 | updated = 1; | |
5007 | } | |
34a409bc | 5008 | |
c6437996 WD |
5009 | +#ifdef SUPPORT_ACLS |
5010 | + /* It's OK to call set_acl() now, even for a dir, as the generator | |
5011 | + * will enable owner-writability using chmod, if necessary. | |
5012 | + * | |
5013 | + * If set_acl changes permission bits in the process of setting | |
5014 | + * an access ACL, it changes st->st_mode so we know whether we | |
5015 | + * need to chmod. */ | |
5016 | + if (preserve_acls && set_acl(fname, file, &st->st_mode) == 0) | |
5017 | + updated = 1; | |
5018 | +#endif | |
5019 | + | |
34a409bc WD |
5020 | #ifdef HAVE_CHMOD |
5021 | if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) { | |
5022 | - int ret = do_chmod(fname, file->mode); | |
5023 | + mode_t mode = file->mode; | |
c6437996 | 5024 | + int ret = do_chmod(fname, mode); |
34a409bc WD |
5025 | if (ret < 0) { |
5026 | rsyserr(FERROR, errno, | |
5027 | "failed to set permissions on %s", | |
9a7eef96 WD |
5028 | --- old/rsync.h |
5029 | +++ new/rsync.h | |
e6a7303b | 5030 | @@ -658,6 +658,20 @@ struct chmod_mode_struct; |
bc5988ec WD |
5031 | |
5032 | #define UNUSED(x) x __attribute__((__unused__)) | |
0f6733d8 | 5033 | |
4df546eb WD |
5034 | +#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\ |
5035 | + HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS | |
5036 | +#define SUPPORT_ACLS 1 | |
5037 | +#endif | |
0f6733d8 | 5038 | + |
4df546eb WD |
5039 | +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS |
5040 | +#define ACLS_NEED_MASK 1 | |
5041 | +#endif | |
0f6733d8 | 5042 | + |
e6a7303b | 5043 | +#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H |
0f6733d8 WD |
5044 | +#include <sys/acl.h> |
5045 | +#endif | |
0f6733d8 WD |
5046 | +#include "smb_acls.h" |
5047 | + | |
5048 | #include "proto.h" | |
5049 | ||
5050 | /* We have replacement versions of these if they're missing. */ | |
9a7eef96 WD |
5051 | --- old/rsync.yo |
5052 | +++ new/rsync.yo | |
2578e2b6 WD |
5053 | @@ -321,6 +321,7 @@ to the detailed description below for a |
5054 | -H, --hard-links preserve hard links | |
0f6733d8 | 5055 | -p, --perms preserve permissions |
90fa6d68 WD |
5056 | -E, --executability preserve executability |
5057 | + -A, --acls preserve ACLs (implies -p) [non-standard] | |
5058 | --chmod=CHMOD change destination permissions | |
5059 | -o, --owner preserve owner (super-user only) | |
0f6733d8 | 5060 | -g, --group preserve group |
2578e2b6 | 5061 | @@ -742,7 +743,9 @@ quote(itemize( |
90fa6d68 WD |
5062 | permissions, though the bf(--executability) option might change just |
5063 | the execute permission for the file. | |
03baf100 WD |
5064 | it() New files get their "normal" permission bits set to the source |
5065 | - file's permissions masked with the receiving end's umask setting, and | |
5066 | + file's permissions masked with the receiving directory's default | |
5067 | + permissions (either the receiving process's umask, or the permissions | |
5068 | + specified via the destination directory's default ACL), and | |
5069 | their special permission bits disabled except in the case where a new | |
5070 | directory inherits a setgid bit from its parent directory. | |
90fa6d68 | 5071 | )) |
2578e2b6 | 5072 | @@ -773,9 +776,11 @@ The preservation of the destination's se |
03baf100 WD |
5073 | directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync |
5074 | versions erroneously preserved the three special permission bits for | |
5075 | newly-created files when bf(--perms) was off, while overriding the | |
5076 | -destination's setgid bit setting on a newly-created directory. (Keep in | |
5077 | -mind that it is the version of the receiving rsync that affects this | |
5078 | -behavior.) | |
5079 | +destination's setgid bit setting on a newly-created directory. Default ACL | |
5080 | +observance was added to the ACL patch for rsync 2.6.7, so older (or | |
5081 | +non-ACL-enabled) rsyncs use the umask even if default ACLs are present. | |
5082 | +(Keep in mind that it is the version of the receiving rsync that affects | |
5083 | +these behaviors.) | |
90fa6d68 | 5084 | |
90fa6d68 WD |
5085 | dit(bf(-E, --executability)) This option causes rsync to preserve the |
5086 | executability (or non-executability) of regular files when bf(--perms) is | |
b57f8e02 | 5087 | @@ -793,6 +798,15 @@ quote(itemize( |
90fa6d68 WD |
5088 | |
5089 | If bf(--perms) is enabled, this option is ignored. | |
5090 | ||
5091 | +dit(bf(-A, --acls)) This option causes rsync to update the destination | |
5092 | +ACLs to be the same as the source ACLs. This nonstandard option only | |
5093 | +works if the remote rsync also supports it. bf(--acls) implies bf(--perms). | |
b57f8e02 WD |
5094 | + |
5095 | +Note also that an optimization of the ACL-sending protocol used by this | |
5096 | +version makes it incompatible with sending files to an older ACL-enabled | |
5097 | +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This | |
5098 | +doubling is not needed when pulling files from an older rsync. | |
90fa6d68 WD |
5099 | + |
5100 | dit(bf(--chmod)) This option tells rsync to apply one or more | |
5101 | comma-separated "chmod" strings to the permission of the files in the | |
5102 | transfer. The resulting value is treated as though it was the permissions | |
9a7eef96 WD |
5103 | --- old/smb_acls.h |
5104 | +++ new/smb_acls.h | |
53c1073a | 5105 | @@ -0,0 +1,281 @@ |
0f6733d8 WD |
5106 | +/* |
5107 | + Unix SMB/Netbios implementation. | |
5108 | + Version 2.2.x | |
5109 | + Portable SMB ACL interface | |
5110 | + Copyright (C) Jeremy Allison 2000 | |
5111 | + | |
5112 | + This program is free software; you can redistribute it and/or modify | |
5113 | + it under the terms of the GNU General Public License as published by | |
5114 | + the Free Software Foundation; either version 2 of the License, or | |
5115 | + (at your option) any later version. | |
5116 | + | |
5117 | + This program is distributed in the hope that it will be useful, | |
5118 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
5119 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
5120 | + GNU General Public License for more details. | |
5121 | + | |
5122 | + You should have received a copy of the GNU General Public License | |
5123 | + along with this program; if not, write to the Free Software | |
5124 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
5125 | +*/ | |
5126 | + | |
5127 | +#ifndef _SMB_ACLS_H | |
5128 | +#define _SMB_ACLS_H | |
5129 | + | |
e6a7303b | 5130 | +#if defined HAVE_POSIX_ACLS |
0f6733d8 WD |
5131 | + |
5132 | +/* This is an identity mapping (just remove the SMB_). */ | |
5133 | + | |
5134 | +#define SMB_ACL_TAG_T acl_tag_t | |
5135 | +#define SMB_ACL_TYPE_T acl_type_t | |
5136 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
5137 | +#define SMB_ACL_PERM_T acl_perm_t | |
5138 | +#define SMB_ACL_READ ACL_READ | |
5139 | +#define SMB_ACL_WRITE ACL_WRITE | |
5140 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
5141 | + | |
5142 | +/* Types of ACLs. */ | |
5143 | +#define SMB_ACL_USER ACL_USER | |
5144 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
5145 | +#define SMB_ACL_GROUP ACL_GROUP | |
5146 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
5147 | +#define SMB_ACL_OTHER ACL_OTHER | |
5148 | +#define SMB_ACL_MASK ACL_MASK | |
5149 | + | |
5150 | +#define SMB_ACL_T acl_t | |
5151 | + | |
5152 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
5153 | + | |
5154 | +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY | |
5155 | +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY | |
5156 | + | |
5157 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
5158 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
5159 | + | |
e6a7303b | 5160 | +#elif defined HAVE_TRU64_ACLS |
0f6733d8 WD |
5161 | + |
5162 | +/* This is for DEC/Compaq Tru64 UNIX */ | |
5163 | + | |
5164 | +#define SMB_ACL_TAG_T acl_tag_t | |
5165 | +#define SMB_ACL_TYPE_T acl_type_t | |
5166 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
5167 | +#define SMB_ACL_PERM_T acl_perm_t | |
5168 | +#define SMB_ACL_READ ACL_READ | |
5169 | +#define SMB_ACL_WRITE ACL_WRITE | |
5170 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
5171 | + | |
5172 | +/* Types of ACLs. */ | |
5173 | +#define SMB_ACL_USER ACL_USER | |
5174 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
5175 | +#define SMB_ACL_GROUP ACL_GROUP | |
5176 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
5177 | +#define SMB_ACL_OTHER ACL_OTHER | |
5178 | +#define SMB_ACL_MASK ACL_MASK | |
5179 | + | |
5180 | +#define SMB_ACL_T acl_t | |
5181 | + | |
5182 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
5183 | + | |
5184 | +#define SMB_ACL_FIRST_ENTRY 0 | |
5185 | +#define SMB_ACL_NEXT_ENTRY 1 | |
5186 | + | |
5187 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
5188 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
5189 | + | |
e6a7303b | 5190 | +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS |
0f6733d8 WD |
5191 | +/* |
5192 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
5193 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. | |
5194 | + */ | |
5195 | + | |
5196 | +/* SVR4.2 ES/MP ACLs */ | |
5197 | +typedef int SMB_ACL_TAG_T; | |
5198 | +typedef int SMB_ACL_TYPE_T; | |
5199 | +typedef ushort *SMB_ACL_PERMSET_T; | |
5200 | +typedef ushort SMB_ACL_PERM_T; | |
5201 | +#define SMB_ACL_READ 4 | |
5202 | +#define SMB_ACL_WRITE 2 | |
5203 | +#define SMB_ACL_EXECUTE 1 | |
5204 | + | |
5205 | +/* Types of ACLs. */ | |
5206 | +#define SMB_ACL_USER USER | |
5207 | +#define SMB_ACL_USER_OBJ USER_OBJ | |
5208 | +#define SMB_ACL_GROUP GROUP | |
5209 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
5210 | +#define SMB_ACL_OTHER OTHER_OBJ | |
5211 | +#define SMB_ACL_MASK CLASS_OBJ | |
5212 | + | |
5213 | +typedef struct SMB_ACL_T { | |
5214 | + int size; | |
5215 | + int count; | |
5216 | + int next; | |
5217 | + struct acl acl[1]; | |
5218 | +} *SMB_ACL_T; | |
5219 | + | |
5220 | +typedef struct acl *SMB_ACL_ENTRY_T; | |
5221 | + | |
5222 | +#define SMB_ACL_FIRST_ENTRY 0 | |
5223 | +#define SMB_ACL_NEXT_ENTRY 1 | |
5224 | + | |
5225 | +#define SMB_ACL_TYPE_ACCESS 0 | |
5226 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
5227 | + | |
53c1073a WD |
5228 | +#ifdef __CYGWIN__ |
5229 | +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS | |
5230 | +#endif | |
5231 | + | |
e6a7303b | 5232 | +#elif defined HAVE_HPUX_ACLS |
0f6733d8 WD |
5233 | + |
5234 | +/* | |
5235 | + * Based on the Solaris & UnixWare code. | |
5236 | + */ | |
5237 | + | |
5238 | +#undef GROUP | |
5239 | +#include <sys/aclv.h> | |
5240 | + | |
5241 | +/* SVR4.2 ES/MP ACLs */ | |
5242 | +typedef int SMB_ACL_TAG_T; | |
5243 | +typedef int SMB_ACL_TYPE_T; | |
5244 | +typedef ushort *SMB_ACL_PERMSET_T; | |
5245 | +typedef ushort SMB_ACL_PERM_T; | |
5246 | +#define SMB_ACL_READ 4 | |
5247 | +#define SMB_ACL_WRITE 2 | |
5248 | +#define SMB_ACL_EXECUTE 1 | |
5249 | + | |
5250 | +/* Types of ACLs. */ | |
5251 | +#define SMB_ACL_USER USER | |
5252 | +#define SMB_ACL_USER_OBJ USER_OBJ | |
5253 | +#define SMB_ACL_GROUP GROUP | |
5254 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
5255 | +#define SMB_ACL_OTHER OTHER_OBJ | |
5256 | +#define SMB_ACL_MASK CLASS_OBJ | |
5257 | + | |
5258 | +typedef struct SMB_ACL_T { | |
5259 | + int size; | |
5260 | + int count; | |
5261 | + int next; | |
5262 | + struct acl acl[1]; | |
5263 | +} *SMB_ACL_T; | |
5264 | + | |
5265 | +typedef struct acl *SMB_ACL_ENTRY_T; | |
5266 | + | |
5267 | +#define SMB_ACL_FIRST_ENTRY 0 | |
5268 | +#define SMB_ACL_NEXT_ENTRY 1 | |
5269 | + | |
5270 | +#define SMB_ACL_TYPE_ACCESS 0 | |
5271 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
5272 | + | |
e6a7303b | 5273 | +#elif defined HAVE_IRIX_ACLS |
0f6733d8 WD |
5274 | + |
5275 | +#define SMB_ACL_TAG_T acl_tag_t | |
5276 | +#define SMB_ACL_TYPE_T acl_type_t | |
5277 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
5278 | +#define SMB_ACL_PERM_T acl_perm_t | |
5279 | +#define SMB_ACL_READ ACL_READ | |
5280 | +#define SMB_ACL_WRITE ACL_WRITE | |
5281 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
5282 | + | |
5283 | +/* Types of ACLs. */ | |
5284 | +#define SMB_ACL_USER ACL_USER | |
5285 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
5286 | +#define SMB_ACL_GROUP ACL_GROUP | |
5287 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
5288 | +#define SMB_ACL_OTHER ACL_OTHER_OBJ | |
5289 | +#define SMB_ACL_MASK ACL_MASK | |
5290 | + | |
5291 | +typedef struct SMB_ACL_T { | |
5292 | + int next; | |
5293 | + BOOL freeaclp; | |
5294 | + struct acl *aclp; | |
5295 | +} *SMB_ACL_T; | |
5296 | + | |
5297 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
5298 | + | |
5299 | +#define SMB_ACL_FIRST_ENTRY 0 | |
5300 | +#define SMB_ACL_NEXT_ENTRY 1 | |
5301 | + | |
5302 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
5303 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
5304 | + | |
e6a7303b | 5305 | +#elif defined HAVE_AIX_ACLS |
0f6733d8 WD |
5306 | + |
5307 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
5308 | + | |
5309 | +#include "/usr/include/acl.h" | |
5310 | + | |
5311 | +typedef uint *SMB_ACL_PERMSET_T; | |
5312 | + | |
5313 | +struct acl_entry_link{ | |
5314 | + struct acl_entry_link *prevp; | |
5315 | + struct new_acl_entry *entryp; | |
5316 | + struct acl_entry_link *nextp; | |
5317 | + int count; | |
5318 | +}; | |
5319 | + | |
5320 | +struct new_acl_entry{ | |
5321 | + unsigned short ace_len; | |
5322 | + unsigned short ace_type; | |
5323 | + unsigned int ace_access; | |
5324 | + struct ace_id ace_id[1]; | |
5325 | +}; | |
5326 | + | |
5327 | +#define SMB_ACL_ENTRY_T struct new_acl_entry* | |
5328 | +#define SMB_ACL_T struct acl_entry_link* | |
5329 | + | |
5330 | +#define SMB_ACL_TAG_T unsigned short | |
5331 | +#define SMB_ACL_TYPE_T int | |
5332 | +#define SMB_ACL_PERM_T uint | |
5333 | +#define SMB_ACL_READ S_IRUSR | |
5334 | +#define SMB_ACL_WRITE S_IWUSR | |
5335 | +#define SMB_ACL_EXECUTE S_IXUSR | |
5336 | + | |
5337 | +/* Types of ACLs. */ | |
5338 | +#define SMB_ACL_USER ACEID_USER | |
5339 | +#define SMB_ACL_USER_OBJ 3 | |
5340 | +#define SMB_ACL_GROUP ACEID_GROUP | |
5341 | +#define SMB_ACL_GROUP_OBJ 4 | |
5342 | +#define SMB_ACL_OTHER 5 | |
5343 | +#define SMB_ACL_MASK 6 | |
5344 | + | |
5345 | + | |
5346 | +#define SMB_ACL_FIRST_ENTRY 1 | |
5347 | +#define SMB_ACL_NEXT_ENTRY 2 | |
5348 | + | |
5349 | +#define SMB_ACL_TYPE_ACCESS 0 | |
5350 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
5351 | + | |
5352 | +#else /* No ACLs. */ | |
5353 | + | |
5354 | +/* No ACLS - fake it. */ | |
5355 | +#define SMB_ACL_TAG_T int | |
5356 | +#define SMB_ACL_TYPE_T int | |
5357 | +#define SMB_ACL_PERMSET_T mode_t | |
5358 | +#define SMB_ACL_PERM_T mode_t | |
5359 | +#define SMB_ACL_READ S_IRUSR | |
5360 | +#define SMB_ACL_WRITE S_IWUSR | |
5361 | +#define SMB_ACL_EXECUTE S_IXUSR | |
5362 | + | |
5363 | +/* Types of ACLs. */ | |
5364 | +#define SMB_ACL_USER 0 | |
5365 | +#define SMB_ACL_USER_OBJ 1 | |
5366 | +#define SMB_ACL_GROUP 2 | |
5367 | +#define SMB_ACL_GROUP_OBJ 3 | |
5368 | +#define SMB_ACL_OTHER 4 | |
5369 | +#define SMB_ACL_MASK 5 | |
5370 | + | |
5371 | +typedef struct SMB_ACL_T { | |
5372 | + int dummy; | |
5373 | +} *SMB_ACL_T; | |
5374 | + | |
5375 | +typedef struct SMB_ACL_ENTRY_T { | |
5376 | + int dummy; | |
5377 | +} *SMB_ACL_ENTRY_T; | |
5378 | + | |
5379 | +#define SMB_ACL_FIRST_ENTRY 0 | |
5380 | +#define SMB_ACL_NEXT_ENTRY 1 | |
5381 | + | |
5382 | +#define SMB_ACL_TYPE_ACCESS 0 | |
5383 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
5384 | + | |
5385 | +#endif /* No ACLs. */ | |
5386 | +#endif /* _SMB_ACLS_H */ | |
9a7eef96 WD |
5387 | --- old/testsuite/default-acls.test |
5388 | +++ new/testsuite/default-acls.test | |
53c1073a | 5389 | @@ -0,0 +1,64 @@ |
90fa6d68 WD |
5390 | +#! /bin/sh |
5391 | + | |
5392 | +# This program is distributable under the terms of the GNU GPL see | |
5393 | +# COPYING). | |
5394 | + | |
5395 | +# Test that rsync obeys default ACLs. -- Matt McCutchen | |
5396 | + | |
5397 | +. $srcdir/testsuite/rsync.fns | |
5398 | + | |
25d385b9 | 5399 | +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support" |
53c1073a WD |
5400 | +case "$setfacl_nodef" in |
5401 | +*-k*) opts='-dm u::7,g::5,o:5' ;; | |
5402 | +*) opts='-m d:u::7,d:g::5,d:o:5' ;; | |
5403 | +esac | |
5404 | +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled" | |
90fa6d68 | 5405 | + |
90fa6d68 | 5406 | +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected> |
25d385b9 | 5407 | +testit() { |
90fa6d68 WD |
5408 | + todir="$scratchdir/$1" |
5409 | + mkdir "$todir" | |
53c1073a WD |
5410 | + $setfacl_nodef "$todir" |
5411 | + if [ "$2" ]; then | |
5412 | + case "$setfacl_nodef" in | |
5413 | + *-k*) opts="-dm $2" ;; | |
5414 | + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`" | |
5415 | + esac | |
5416 | + setfacl $opts "$todir" | |
5417 | + fi | |
90fa6d68 WD |
5418 | + # Make sure we obey ACLs when creating a directory to hold multiple transferred files, |
5419 | + # even though the directory itself is outside the transfer | |
25d385b9 | 5420 | + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/" |
0251480d | 5421 | + check_perms "$todir/to" $4 "Target $1" |
25d385b9 | 5422 | + check_perms "$todir/to/dir" $4 "Target $1" |
0251480d WD |
5423 | + check_perms "$todir/to/file" $3 "Target $1" |
5424 | + check_perms "$todir/to/program" $4 "Target $1" | |
90fa6d68 WD |
5425 | + # Make sure get_local_name doesn't mess us up when transferring only one file |
5426 | + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile" | |
0251480d | 5427 | + check_perms "$todir/to/anotherfile" $3 "Target $1" |
bb81ee98 | 5428 | + # Make sure we obey default ACLs when not transferring a regular file |
2578e2b6 | 5429 | + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/" |
bb81ee98 | 5430 | + check_perms "$todir/to/anotherdir" $4 "Target $1" |
90fa6d68 WD |
5431 | +} |
5432 | + | |
25d385b9 | 5433 | +mkdir "$scratchdir/dir" |
0251480d | 5434 | +echo "File!" >"$scratchdir/file" |
25d385b9 WD |
5435 | +echo "#!/bin/sh" >"$scratchdir/program" |
5436 | +chmod 777 "$scratchdir/dir" | |
0251480d WD |
5437 | +chmod 666 "$scratchdir/file" |
5438 | +chmod 777 "$scratchdir/program" | |
5439 | + | |
90fa6d68 WD |
5440 | +# Test some target directories |
5441 | +umask 0077 | |
53c1073a WD |
5442 | +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx |
5443 | +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x | |
5444 | +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x--- | |
5445 | +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx--- | |
0251480d | 5446 | +testit noda1 '' rw------- rwx------ |
90fa6d68 | 5447 | +umask 0000 |
0251480d | 5448 | +testit noda2 '' rw-rw-rw- rwxrwxrwx |
90fa6d68 | 5449 | +umask 0022 |
0251480d | 5450 | +testit noda3 '' rw-r--r-- rwxr-xr-x |
90fa6d68 WD |
5451 | + |
5452 | +# Hooray | |
5453 | +exit 0 | |
9a7eef96 WD |
5454 | --- old/uidlist.c |
5455 | +++ new/uidlist.c | |
fa26e11c WD |
5456 | @@ -34,6 +34,7 @@ |
5457 | extern int verbose; | |
5458 | extern int preserve_uid; | |
5459 | extern int preserve_gid; | |
5460 | +extern int preserve_acls; | |
5461 | extern int numeric_ids; | |
5462 | extern int am_root; | |
5463 | ||
5464 | @@ -274,7 +275,7 @@ void send_uid_list(int f) | |
5465 | if (numeric_ids) | |
5466 | return; | |
5467 | ||
5468 | - if (preserve_uid) { | |
5469 | + if (preserve_uid || preserve_acls) { | |
5470 | int len; | |
5471 | /* we send sequences of uid/byte-length/name */ | |
5472 | for (list = uidlist; list; list = list->next) { | |
5473 | @@ -291,7 +292,7 @@ void send_uid_list(int f) | |
5474 | write_int(f, 0); | |
5475 | } | |
5476 | ||
5477 | - if (preserve_gid) { | |
5478 | + if (preserve_gid || preserve_acls) { | |
5479 | int len; | |
5480 | for (list = gidlist; list; list = list->next) { | |
5481 | if (!list->name) | |
5482 | @@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li | |
5483 | int id, i; | |
5484 | char *name; | |
5485 | ||
5486 | - if (preserve_uid && !numeric_ids) { | |
5487 | + if ((preserve_uid || preserve_acls) && !numeric_ids) { | |
5488 | /* read the uid list */ | |
5489 | while ((id = read_int(f)) != 0) { | |
5490 | int len = read_byte(f); | |
6849cd84 WD |
5491 | @@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li |
5492 | } | |
fa26e11c WD |
5493 | } |
5494 | ||
fa26e11c WD |
5495 | - if (preserve_gid && !numeric_ids) { |
5496 | + if ((preserve_gid || preserve_acls) && !numeric_ids) { | |
5497 | /* read the gid list */ | |
5498 | while ((id = read_int(f)) != 0) { | |
5499 | int len = read_byte(f); | |
c52977bc | 5500 | @@ -336,6 +337,16 @@ void recv_uid_list(int f, struct file_li |
fa26e11c WD |
5501 | } |
5502 | } | |
125d7fca | 5503 | |
4edb99c8 | 5504 | +#ifdef SUPPORT_ACLS |
fa26e11c | 5505 | + if (preserve_acls && !numeric_ids) { |
c52977bc WD |
5506 | + id_t *id; |
5507 | + while ((id = next_acl_uid(flist)) != NULL) | |
5508 | + *id = match_uid(*id); | |
5509 | + while ((id = next_acl_gid(flist)) != NULL) | |
5510 | + *id = match_gid(*id); | |
fa26e11c | 5511 | + } |
162234a7 | 5512 | +#endif |
125d7fca | 5513 | + |
90fa6d68 | 5514 | /* Now convert all the uids/gids from sender values to our values. */ |
125d7fca | 5515 | if (am_root && preserve_uid && !numeric_ids) { |
90fa6d68 | 5516 | for (i = 0; i < flist->count; i++) |