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