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