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