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