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