Commit | Line | Data |
---|---|---|
03019e41 | 1 | To use this patch, run these commands for a successful build: |
fa26e11c | 2 | |
03019e41 | 3 | patch -p1 <patches/acls.diff |
27e96866 | 4 | ./prepare-source |
f787c90c | 5 | ./configure --enable-acl-support |
fa26e11c WD |
6 | make |
7 | ||
a5e3a4cc WD |
8 | See the --acls (-A) option in the revised man page for a note on using this |
9 | latest ACL-enabling patch to send files to an older ACL-enabled rsync. | |
10 | ||
9a7eef96 WD |
11 | --- old/Makefile.in |
12 | +++ new/Makefile.in | |
bdf1eee8 | 13 | @@ -26,15 +26,15 @@ VERSION=@VERSION@ |
fa26e11c WD |
14 | .SUFFIXES: |
15 | .SUFFIXES: .c .o | |
16 | ||
17 | -HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h | |
18 | +HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h | |
19 | LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \ | |
0f6733d8 WD |
20 | - lib/permstring.o lib/pool_alloc.o @LIBOBJS@ |
21 | + lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@ | |
4bf6f8c7 WD |
22 | ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \ |
23 | zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o | |
fa26e11c WD |
24 | OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \ |
25 | main.o checksum.o match.o syscall.o log.o backup.o | |
26 | OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \ | |
610969d1 WD |
27 | - fileio.o batch.o clientname.o chmod.o |
28 | + fileio.o batch.o clientname.o chmod.o acls.o | |
fa26e11c WD |
29 | OBJS3=progress.o pipe.o |
30 | DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o | |
31 | popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \ | |
9a7eef96 WD |
32 | --- old/acls.c |
33 | +++ new/acls.c | |
78b1089b | 34 | @@ -0,0 +1,1098 @@ |
c32e843a WD |
35 | +/* |
36 | + * Handle passing Access Control Lists between systems. | |
37 | + * | |
38 | + * Copyright (C) 1996 Andrew Tridgell | |
39 | + * Copyright (C) 1996 Paul Mackerras | |
c32e843a WD |
40 | + * Copyright (C) 2006 Wayne Davison |
41 | + * | |
42 | + * This program is free software; you can redistribute it and/or modify | |
43 | + * it under the terms of the GNU General Public License as published by | |
44 | + * the Free Software Foundation; either version 2 of the License, or | |
45 | + * (at your option) any later version. | |
46 | + * | |
47 | + * This program is distributed in the hope that it will be useful, | |
48 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
49 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
50 | + * GNU General Public License for more details. | |
51 | + * | |
52 | + * You should have received a copy of the GNU General Public License along | |
53 | + * with this program; if not, write to the Free Software Foundation, Inc., | |
54 | + * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. | |
55 | + */ | |
fa26e11c WD |
56 | + |
57 | +#include "rsync.h" | |
0f6733d8 | 58 | +#include "lib/sysacls.h" |
fa26e11c | 59 | + |
4df546eb | 60 | +#ifdef SUPPORT_ACLS |
fa26e11c | 61 | + |
fa26e11c | 62 | +extern int dry_run; |
0909ae28 WD |
63 | +extern int read_only; |
64 | +extern int list_only; | |
90fa6d68 | 65 | +extern int orig_umask; |
a5e3a4cc | 66 | +extern int preserve_acls; |
0870c22a WD |
67 | +extern unsigned int file_struct_len; |
68 | + | |
69 | +/* === ACL structures === */ | |
fa26e11c WD |
70 | + |
71 | +typedef struct { | |
72 | + id_t id; | |
73 | + uchar access; | |
c6437996 | 74 | +} id_access; |
fa26e11c WD |
75 | + |
76 | +typedef struct { | |
c6437996 | 77 | + id_access *idas; |
0870c22a WD |
78 | + int count; |
79 | +} ida_entries; | |
c6437996 | 80 | + |
0870c22a WD |
81 | +#define NO_ENTRY ((uchar)0x80) |
82 | +typedef struct rsync_acl { | |
83 | + ida_entries users; | |
84 | + ida_entries groups; | |
85 | + /* These will be NO_ENTRY if there's no such entry. */ | |
c6437996 WD |
86 | + uchar user_obj; |
87 | + uchar group_obj; | |
88 | + uchar mask; | |
89 | + uchar other; | |
fa26e11c WD |
90 | +} rsync_acl; |
91 | + | |
0870c22a WD |
92 | +typedef struct { |
93 | + rsync_acl racl; | |
94 | + SMB_ACL_T sacl; | |
95 | +} acl_duo; | |
96 | + | |
cd1d1a9d | 97 | +static const rsync_acl empty_rsync_acl = { |
0870c22a | 98 | + {NULL, 0}, {NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY |
56294981 | 99 | +}; |
8db8e7d2 | 100 | + |
6250eb3e WD |
101 | +static item_list access_acl_list = EMPTY_ITEM_LIST; |
102 | +static item_list default_acl_list = EMPTY_ITEM_LIST; | |
0870c22a WD |
103 | + |
104 | +/* === Calculations on ACL types === */ | |
105 | + | |
106 | +static const char *str_acl_type(SMB_ACL_TYPE_T type) | |
107 | +{ | |
108 | + return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" | |
109 | + : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" | |
110 | + : "unknown SMB_ACL_TYPE_T"; | |
111 | +} | |
112 | + | |
8db8e7d2 WD |
113 | +#define OTHER_TYPE(t) (SMB_ACL_TYPE_ACCESS+SMB_ACL_TYPE_DEFAULT-(t)) |
114 | +#define BUMP_TYPE(t) ((t = OTHER_TYPE(t)) == SMB_ACL_TYPE_DEFAULT) | |
fa26e11c | 115 | + |
56294981 WD |
116 | +static int count_racl_entries(const rsync_acl *racl) |
117 | +{ | |
118 | + return racl->users.count + racl->groups.count | |
0870c22a WD |
119 | + + (racl->user_obj != NO_ENTRY) |
120 | + + (racl->group_obj != NO_ENTRY) | |
121 | + + (racl->mask != NO_ENTRY) | |
122 | + + (racl->other != NO_ENTRY); | |
56294981 WD |
123 | +} |
124 | + | |
125 | +static int calc_sacl_entries(const rsync_acl *racl) | |
9a7b72b5 | 126 | +{ |
0870c22a | 127 | + /* A System ACL always gets user/group/other permission entries. */ |
c6437996 | 128 | + return racl->users.count + racl->groups.count |
56294981 WD |
129 | +#ifdef ACLS_NEED_MASK |
130 | + + 4; | |
131 | +#else | |
0870c22a | 132 | + + (racl->mask != NO_ENTRY) + 3; |
56294981 | 133 | +#endif |
c6437996 WD |
134 | +} |
135 | + | |
0870c22a WD |
136 | +/* Extracts and returns the permission bits from the ACL. This cannot be |
137 | + * called on an rsync_acl that has NO_ENTRY in any spot but the mask. */ | |
9a7b72b5 WD |
138 | +static int rsync_acl_get_perms(const rsync_acl *racl) |
139 | +{ | |
8eb3e3ae | 140 | + return (racl->user_obj << 6) |
0870c22a | 141 | + + ((racl->mask != NO_ENTRY ? racl->mask : racl->group_obj) << 3) |
8eb3e3ae | 142 | + + racl->other; |
c6437996 WD |
143 | +} |
144 | + | |
0870c22a WD |
145 | +/* Removes the permission-bit entries from the ACL because these |
146 | + * can be reconstructed from the file's mode. */ | |
9a7b72b5 WD |
147 | +static void rsync_acl_strip_perms(rsync_acl *racl) |
148 | +{ | |
0870c22a WD |
149 | + racl->user_obj = NO_ENTRY; |
150 | + if (racl->mask == NO_ENTRY) | |
151 | + racl->group_obj = NO_ENTRY; | |
152 | + else { | |
153 | + if (racl->group_obj == racl->mask) | |
154 | + racl->group_obj = NO_ENTRY; | |
155 | + racl->mask = NO_ENTRY; | |
156 | + } | |
157 | + racl->other = NO_ENTRY; | |
c6437996 | 158 | +} |
34a409bc | 159 | + |
0870c22a WD |
160 | +/* Given an empty rsync_acl, fake up the permission bits. */ |
161 | +static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode) | |
fa26e11c | 162 | +{ |
0870c22a WD |
163 | + racl->user_obj = (mode >> 6) & 7; |
164 | + racl->group_obj = (mode >> 3) & 7; | |
0870c22a WD |
165 | + racl->other = mode & 7; |
166 | +} | |
167 | + | |
168 | +/* === Rsync ACL functions === */ | |
169 | + | |
170 | +static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2) | |
171 | +{ | |
172 | + id_access *ida1, *ida2; | |
173 | + int count = ial1->count; | |
174 | + if (count != ial2->count) | |
175 | + return False; | |
176 | + ida1 = ial1->idas; | |
177 | + ida2 = ial2->idas; | |
178 | + for (; count--; ida1++, ida2++) { | |
179 | + if (ida1->access != ida2->access || ida1->id != ida2->id) | |
180 | + return False; | |
181 | + } | |
182 | + return True; | |
183 | +} | |
fa26e11c | 184 | + |
98ccc74a | 185 | +static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2) |
0870c22a | 186 | +{ |
adabede5 WD |
187 | + return racl1->user_obj == racl2->user_obj |
188 | + && racl1->group_obj == racl2->group_obj | |
189 | + && racl1->mask == racl2->mask | |
190 | + && racl1->other == racl2->other | |
191 | + && ida_entries_equal(&racl1->users, &racl2->users) | |
192 | + && ida_entries_equal(&racl1->groups, &racl2->groups); | |
0870c22a WD |
193 | +} |
194 | + | |
195 | +/* Are the extended (non-permission-bit) entries equal? If so, the rest of | |
196 | + * the ACL will be handled by the normal mode-preservation code. This is | |
197 | + * only meaningful for access ACLs! Note: the 1st arg is a fully-populated | |
198 | + * rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means | |
adabede5 | 199 | + * that it might have several of its permission objects set to NO_ENTRY. */ |
98ccc74a WD |
200 | +static BOOL rsync_acl_equal_enough(const rsync_acl *racl1, |
201 | + const rsync_acl *racl2, mode_t m) | |
0870c22a WD |
202 | +{ |
203 | + if ((racl1->mask ^ racl2->mask) & NO_ENTRY) | |
204 | + return False; /* One has a mask and the other doesn't */ | |
fa26e11c | 205 | + |
0870c22a WD |
206 | + /* When there's a mask, the group_obj becomes an extended entry. */ |
207 | + if (racl1->mask != NO_ENTRY) { | |
208 | + /* A condensed rsync_acl with a mask can only have no | |
209 | + * group_obj when it was identical to the mask. This | |
210 | + * means that it was also identical to the group attrs | |
211 | + * from the mode. */ | |
212 | + if (racl2->group_obj == NO_ENTRY) { | |
213 | + if (racl1->group_obj != ((m >> 3) & 7)) | |
214 | + return False; | |
215 | + } else if (racl1->group_obj != racl2->group_obj) | |
216 | + return False; | |
fa26e11c | 217 | + } |
0870c22a WD |
218 | + return ida_entries_equal(&racl1->users, &racl2->users) |
219 | + && ida_entries_equal(&racl1->groups, &racl2->groups); | |
fa26e11c WD |
220 | +} |
221 | + | |
222 | +static void rsync_acl_free(rsync_acl *racl) | |
223 | +{ | |
8eb3e3ae WD |
224 | + if (racl->users.idas) |
225 | + free(racl->users.idas); | |
226 | + if (racl->groups.idas) | |
227 | + free(racl->groups.idas); | |
228 | + *racl = empty_rsync_acl; | |
fa26e11c WD |
229 | +} |
230 | + | |
98ccc74a | 231 | +void free_acl(statx *sxp) |
0870c22a WD |
232 | +{ |
233 | + if (sxp->acc_acl) { | |
234 | + rsync_acl_free(sxp->acc_acl); | |
235 | + free(sxp->acc_acl); | |
236 | + sxp->acc_acl = NULL; | |
237 | + } | |
238 | + if (sxp->def_acl) { | |
239 | + rsync_acl_free(sxp->def_acl); | |
240 | + free(sxp->def_acl); | |
241 | + sxp->def_acl = NULL; | |
242 | + } | |
243 | +} | |
244 | + | |
c6437996 | 245 | +static int id_access_sorter(const void *r1, const void *r2) |
fa26e11c | 246 | +{ |
c6437996 WD |
247 | + id_access *ida1 = (id_access *)r1; |
248 | + id_access *ida2 = (id_access *)r2; | |
249 | + id_t rid1 = ida1->id, rid2 = ida2->id; | |
fa26e11c WD |
250 | + return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1; |
251 | +} | |
252 | + | |
0870c22a | 253 | +static void sort_ida_entries(ida_entries *idal) |
fa26e11c | 254 | +{ |
c6437996 | 255 | + if (!idal->count) |
fa26e11c | 256 | + return; |
0870c22a | 257 | + qsort(idal->idas, idal->count, sizeof idal->idas[0], id_access_sorter); |
fa26e11c WD |
258 | +} |
259 | + | |
0870c22a WD |
260 | +/* Transfer the count id_access items out of the temp_ida_list into either |
261 | + * the users or groups ida_entries list in racl. */ | |
262 | +static void save_idas(item_list *temp_ida_list, rsync_acl *racl, SMB_ACL_TAG_T type) | |
263 | +{ | |
264 | + id_access *idas; | |
265 | + ida_entries *ent; | |
266 | + | |
267 | + if (temp_ida_list->count) { | |
268 | + int cnt = temp_ida_list->count; | |
269 | + id_access *temp_idas = temp_ida_list->items; | |
270 | + if (!(idas = new_array(id_access, cnt))) | |
271 | + out_of_memory("save_idas"); | |
272 | + memcpy(idas, temp_idas, cnt * sizeof *temp_idas); | |
273 | + } else | |
274 | + idas = NULL; | |
275 | + | |
276 | + ent = type == SMB_ACL_USER ? &racl->users : &racl->groups; | |
277 | + | |
278 | + if (ent->count) { | |
279 | + rprintf(FERROR, "save_idas: disjoint list found for type %d\n", type); | |
280 | + exit_cleanup(RERR_UNSUPPORTED); | |
281 | + } | |
282 | + ent->count = temp_ida_list->count; | |
283 | + ent->idas = idas; | |
284 | + | |
285 | + /* Truncate the temporary list now that its idas have been saved. */ | |
286 | + temp_ida_list->count = 0; | |
287 | +} | |
288 | + | |
289 | +/* === System ACLs === */ | |
290 | + | |
adabede5 | 291 | +/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */ |
fa26e11c WD |
292 | +static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl) |
293 | +{ | |
6250eb3e | 294 | + static item_list temp_ida_list = EMPTY_ITEM_LIST; |
0870c22a | 295 | + SMB_ACL_TAG_T prior_list_type = 0; |
fa26e11c | 296 | + SMB_ACL_ENTRY_T entry; |
fa26e11c | 297 | + const char *errfun; |
c6437996 WD |
298 | + int rc; |
299 | + | |
fa26e11c WD |
300 | + errfun = "sys_acl_get_entry"; |
301 | + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry); | |
302 | + rc == 1; | |
303 | + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) { | |
c6437996 | 304 | + SMB_ACL_TAG_T tag_type; |
fa26e11c | 305 | + SMB_ACL_PERMSET_T permset; |
c6437996 | 306 | + uchar access; |
fa26e11c | 307 | + void *qualifier; |
c6437996 | 308 | + id_access *ida; |
c6437996 | 309 | + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) { |
fa26e11c WD |
310 | + errfun = "sys_acl_get_tag_type"; |
311 | + break; | |
312 | + } | |
313 | + if ((rc = sys_acl_get_permset(entry, &permset))) { | |
314 | + errfun = "sys_acl_get_tag_type"; | |
315 | + break; | |
316 | + } | |
c6437996 WD |
317 | + access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0) |
318 | + | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0) | |
319 | + | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0); | |
0870c22a | 320 | + /* continue == done with entry; break == store in temporary ida list */ |
c6437996 WD |
321 | + switch (tag_type) { |
322 | + case SMB_ACL_USER_OBJ: | |
0870c22a | 323 | + if (racl->user_obj == NO_ENTRY) |
c6437996 WD |
324 | + racl->user_obj = access; |
325 | + else | |
326 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n"); | |
327 | + continue; | |
fa26e11c | 328 | + case SMB_ACL_USER: |
c6437996 WD |
329 | + break; |
330 | + case SMB_ACL_GROUP_OBJ: | |
0870c22a | 331 | + if (racl->group_obj == NO_ENTRY) |
c6437996 WD |
332 | + racl->group_obj = access; |
333 | + else | |
334 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n"); | |
335 | + continue; | |
fa26e11c WD |
336 | + case SMB_ACL_GROUP: |
337 | + break; | |
c6437996 | 338 | + case SMB_ACL_MASK: |
0870c22a | 339 | + if (racl->mask == NO_ENTRY) |
c6437996 WD |
340 | + racl->mask = access; |
341 | + else | |
342 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n"); | |
343 | + continue; | |
344 | + case SMB_ACL_OTHER: | |
0870c22a | 345 | + if (racl->other == NO_ENTRY) |
c6437996 WD |
346 | + racl->other = access; |
347 | + else | |
348 | + rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n"); | |
349 | + continue; | |
fa26e11c | 350 | + default: |
c6437996 | 351 | + rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n"); |
fa26e11c WD |
352 | + continue; |
353 | + } | |
354 | + if (!(qualifier = sys_acl_get_qualifier(entry))) { | |
355 | + errfun = "sys_acl_get_tag_type"; | |
356 | + rc = EINVAL; | |
357 | + break; | |
358 | + } | |
0870c22a WD |
359 | + if (tag_type != prior_list_type) { |
360 | + if (prior_list_type) | |
361 | + save_idas(&temp_ida_list, racl, prior_list_type); | |
362 | + prior_list_type = tag_type; | |
363 | + } | |
645e162c | 364 | + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10); |
c6437996 WD |
365 | + ida->id = *((id_t *)qualifier); |
366 | + ida->access = access; | |
367 | + sys_acl_free_qualifier(qualifier, tag_type); | |
fa26e11c WD |
368 | + } |
369 | + if (rc) { | |
0870c22a | 370 | + rsyserr(FERROR, errno, "unpack_smb_acl: %s()", errfun); |
fa26e11c WD |
371 | + rsync_acl_free(racl); |
372 | + return False; | |
373 | + } | |
0870c22a WD |
374 | + if (prior_list_type) |
375 | + save_idas(&temp_ida_list, racl, prior_list_type); | |
c6437996 | 376 | + |
0870c22a WD |
377 | + sort_ida_entries(&racl->users); |
378 | + sort_ida_entries(&racl->groups); | |
c6437996 | 379 | + |
8eb3e3ae | 380 | +#ifdef ACLS_NEED_MASK |
aea6b054 | 381 | + if (!racl->users.count && !racl->groups.count && racl->mask != NO_ENTRY) { |
8eb3e3ae WD |
382 | + /* Throw away a superfluous mask, but mask off the |
383 | + * group perms with it first. */ | |
384 | + racl->group_obj &= racl->mask; | |
0870c22a | 385 | + racl->mask = NO_ENTRY; |
8eb3e3ae WD |
386 | + } |
387 | +#endif | |
388 | + | |
fa26e11c WD |
389 | + return True; |
390 | +} | |
391 | + | |
0870c22a | 392 | +/* Synactic sugar for system calls */ |
fa26e11c | 393 | + |
0e879f7f | 394 | +#define CALL_OR_ERROR(func,args,str) \ |
c6437996 WD |
395 | + do { \ |
396 | + if (func args) { \ | |
0e879f7f | 397 | + errfun = str; \ |
c6437996 WD |
398 | + goto error_exit; \ |
399 | + } \ | |
400 | + } while (0) | |
401 | + | |
0e879f7f WD |
402 | +#define COE(func,args) CALL_OR_ERROR(func,args,#func) |
403 | +#define COE2(func,args) CALL_OR_ERROR(func,args,NULL) | |
404 | + | |
0870c22a | 405 | +/* Store the permissions in the system ACL entry. */ |
0e879f7f | 406 | +static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry) |
fa26e11c | 407 | +{ |
c6437996 WD |
408 | + const char *errfun = NULL; |
409 | + SMB_ACL_PERMSET_T permset; | |
410 | + | |
411 | + COE( sys_acl_get_permset,(entry, &permset) ); | |
412 | + COE( sys_acl_clear_perms,(permset) ); | |
413 | + if (access & 4) | |
414 | + COE( sys_acl_add_perm,(permset, SMB_ACL_READ) ); | |
415 | + if (access & 2) | |
416 | + COE( sys_acl_add_perm,(permset, SMB_ACL_WRITE) ); | |
417 | + if (access & 1) | |
418 | + COE( sys_acl_add_perm,(permset, SMB_ACL_EXECUTE) ); | |
419 | + COE( sys_acl_set_permset,(entry, permset) ); | |
420 | + | |
0e879f7f | 421 | + return 0; |
c6437996 | 422 | + |
0e879f7f | 423 | + error_exit: |
0870c22a | 424 | + rsyserr(FERROR, errno, "store_access_in_entry %s()", errfun); |
0e879f7f | 425 | + return -1; |
fa26e11c | 426 | +} |
fa26e11c | 427 | + |
adabede5 | 428 | +/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */ |
c6437996 | 429 | +static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl) |
fa26e11c | 430 | +{ |
8eb3e3ae WD |
431 | +#ifdef ACLS_NEED_MASK |
432 | + uchar mask_bits; | |
433 | +#endif | |
c6437996 WD |
434 | + size_t count; |
435 | + id_access *ida; | |
fa26e11c | 436 | + const char *errfun = NULL; |
c6437996 | 437 | + SMB_ACL_ENTRY_T entry; |
69aaf170 | 438 | + |
56294981 | 439 | + if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) { |
0870c22a | 440 | + rsyserr(FERROR, errno, "pack_smb_acl: sys_acl_init()"); |
fa26e11c WD |
441 | + return False; |
442 | + } | |
69aaf170 | 443 | + |
c6437996 WD |
444 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
445 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER_OBJ) ); | |
56294981 | 446 | + COE2( store_access_in_entry,(racl->user_obj & 7, entry) ); |
c6437996 | 447 | + |
8eb3e3ae | 448 | + for (ida = racl->users.idas, count = racl->users.count; count--; ida++) { |
c6437996 WD |
449 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
450 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_USER) ); | |
451 | + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) ); | |
0e879f7f | 452 | + COE2( store_access_in_entry,(ida->access, entry) ); |
c6437996 WD |
453 | + } |
454 | + | |
455 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); | |
456 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP_OBJ) ); | |
56294981 | 457 | + COE2( store_access_in_entry,(racl->group_obj & 7, entry) ); |
c6437996 | 458 | + |
8eb3e3ae | 459 | + for (ida = racl->groups.idas, count = racl->groups.count; count--; ida++) { |
c6437996 WD |
460 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
461 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_GROUP) ); | |
462 | + COE( sys_acl_set_qualifier,(entry, (void*)&ida->id) ); | |
0e879f7f | 463 | + COE2( store_access_in_entry,(ida->access, entry) ); |
c6437996 | 464 | + } |
8eb3e3ae WD |
465 | + |
466 | +#ifdef ACLS_NEED_MASK | |
0870c22a | 467 | + mask_bits = racl->mask == NO_ENTRY ? racl->group_obj & 7 : racl->mask; |
8eb3e3ae WD |
468 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
469 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) ); | |
470 | + COE2( store_access_in_entry,(mask_bits, entry) ); | |
471 | +#else | |
0870c22a | 472 | + if (racl->mask != NO_ENTRY) { |
c6437996 WD |
473 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); |
474 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_MASK) ); | |
0e879f7f | 475 | + COE2( store_access_in_entry,(racl->mask, entry) ); |
c6437996 | 476 | + } |
56294981 | 477 | +#endif |
c6437996 WD |
478 | + |
479 | + COE( sys_acl_create_entry,(smb_acl, &entry) ); | |
480 | + COE( sys_acl_set_tag_type,(entry, SMB_ACL_OTHER) ); | |
56294981 | 481 | + COE2( store_access_in_entry,(racl->other & 7, entry) ); |
c6437996 WD |
482 | + |
483 | +#ifdef DEBUG | |
484 | + if (sys_acl_valid(*smb_acl) < 0) | |
0870c22a | 485 | + rprintf(FERROR, "pack_smb_acl: warning: system says the ACL I packed is invalid\n"); |
c6437996 WD |
486 | +#endif |
487 | + | |
488 | + return True; | |
489 | + | |
0e879f7f WD |
490 | + error_exit: |
491 | + if (errfun) { | |
0870c22a | 492 | + rsyserr(FERROR, errno, "pack_smb_acl %s()", errfun); |
0e879f7f | 493 | + } |
c6437996 WD |
494 | + sys_acl_free_acl(*smb_acl); |
495 | + return False; | |
496 | +} | |
497 | + | |
0870c22a WD |
498 | +static int find_matching_rsync_acl(SMB_ACL_TYPE_T type, |
499 | + const item_list *racl_list, | |
500 | + const rsync_acl *racl) | |
c6437996 | 501 | +{ |
0870c22a WD |
502 | + static int access_match = -1, default_match = -1; |
503 | + int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match; | |
504 | + size_t count = racl_list->count; | |
c6437996 | 505 | + |
0870c22a WD |
506 | + /* If this is the first time through or we didn't match the last |
507 | + * time, then start at the end of the list, which should be the | |
508 | + * best place to start hunting. */ | |
509 | + if (*match == -1) | |
510 | + *match = racl_list->count - 1; | |
511 | + while (count--) { | |
512 | + rsync_acl *base = racl_list->items; | |
98ccc74a | 513 | + if (rsync_acl_equal(base + *match, racl)) |
0870c22a WD |
514 | + return *match; |
515 | + if (!(*match)--) | |
516 | + *match = racl_list->count - 1; | |
c6437996 WD |
517 | + } |
518 | + | |
0870c22a WD |
519 | + *match = -1; |
520 | + return *match; | |
521 | +} | |
522 | + | |
adabede5 | 523 | +/* Return the Access Control List for the given filename. */ |
98ccc74a | 524 | +int get_acl(const char *fname, statx *sxp) |
0870c22a WD |
525 | +{ |
526 | + SMB_ACL_TYPE_T type; | |
527 | + | |
528 | + if (S_ISLNK(sxp->st.st_mode)) | |
529 | + return 0; | |
530 | + | |
531 | + type = SMB_ACL_TYPE_ACCESS; | |
532 | + do { | |
533 | + SMB_ACL_T sacl = sys_acl_get_file(fname, type); | |
534 | + rsync_acl *racl = new(rsync_acl); | |
535 | + | |
536 | + if (!racl) | |
98ccc74a | 537 | + out_of_memory("get_acl"); |
b6c2bb12 | 538 | + *racl = empty_rsync_acl; |
0870c22a WD |
539 | + if (type == SMB_ACL_TYPE_ACCESS) |
540 | + sxp->acc_acl = racl; | |
541 | + else | |
542 | + sxp->def_acl = racl; | |
543 | + | |
544 | + if (sacl) { | |
545 | + BOOL ok = unpack_smb_acl(racl, sacl); | |
546 | + | |
547 | + sys_acl_free_acl(sacl); | |
548 | + if (!ok) { | |
98ccc74a | 549 | + free_acl(sxp); |
0870c22a WD |
550 | + return -1; |
551 | + } | |
552 | + } else if (errno == ENOTSUP) { | |
553 | + /* ACLs are not supported, so pretend we have a basic ACL. */ | |
0870c22a WD |
554 | + if (type == SMB_ACL_TYPE_ACCESS) |
555 | + rsync_acl_fake_perms(racl, sxp->st.st_mode); | |
556 | + } else { | |
98ccc74a | 557 | + rsyserr(FERROR, errno, "get_acl: sys_acl_get_file(%s, %s)", |
0870c22a | 558 | + fname, str_acl_type(type)); |
98ccc74a | 559 | + free_acl(sxp); |
0870c22a | 560 | + return -1; |
56294981 | 561 | + } |
0870c22a WD |
562 | + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode)); |
563 | + | |
564 | + return 0; | |
565 | +} | |
566 | + | |
567 | +/* === Send functions === */ | |
568 | + | |
569 | +/* The general strategy with the tag_type <-> character mapping is that | |
570 | + * lowercase implies that no qualifier follows, where uppercase does. | |
adabede5 | 571 | + * A similar idiom for the ACL type (access or default) itself, but |
0870c22a WD |
572 | + * lowercase in this instance means there's no ACL following, so the |
573 | + * ACL is a repeat, so the receiver should reuse the last of the same | |
574 | + * type ACL. */ | |
575 | + | |
576 | +/* Send the ida list over the file descriptor. */ | |
577 | +static void send_ida_entries(int f, const ida_entries *idal, char tag_char) | |
578 | +{ | |
579 | + id_access *ida; | |
580 | + size_t count = idal->count; | |
581 | + for (ida = idal->idas; count--; ida++) { | |
582 | + write_byte(f, tag_char); | |
583 | + write_byte(f, ida->access); | |
584 | + write_int(f, ida->id); | |
585 | + /* FIXME: sorta wasteful: we should maybe buffer as | |
586 | + * many ids as max(ACL_USER + ACL_GROUP) objects to | |
587 | + * keep from making so many calls. */ | |
588 | + if (tag_char == 'U') | |
589 | + add_uid(ida->id); | |
590 | + else | |
591 | + add_gid(ida->id); | |
fa26e11c | 592 | + } |
0870c22a WD |
593 | +} |
594 | + | |
adabede5 | 595 | +/* Send an rsync ACL over the file descriptor. */ |
0870c22a WD |
596 | +static void send_rsync_acl(int f, const rsync_acl *racl) |
597 | +{ | |
598 | + size_t count = count_racl_entries(racl); | |
599 | + write_int(f, count); | |
600 | + if (racl->user_obj != NO_ENTRY) { | |
601 | + write_byte(f, 'u'); | |
602 | + write_byte(f, racl->user_obj); | |
603 | + } | |
604 | + send_ida_entries(f, &racl->users, 'U'); | |
605 | + if (racl->group_obj != NO_ENTRY) { | |
606 | + write_byte(f, 'g'); | |
607 | + write_byte(f, racl->group_obj); | |
fa26e11c | 608 | + } |
0870c22a WD |
609 | + send_ida_entries(f, &racl->groups, 'G'); |
610 | + if (racl->mask != NO_ENTRY) { | |
611 | + write_byte(f, 'm'); | |
612 | + write_byte(f, racl->mask); | |
613 | + } | |
614 | + if (racl->other != NO_ENTRY) { | |
615 | + write_byte(f, 'o'); | |
616 | + write_byte(f, racl->other); | |
617 | + } | |
618 | +} | |
c6437996 | 619 | + |
98ccc74a | 620 | +/* Send the ACL from the statx structure down the indicated file descriptor. |
0870c22a | 621 | + * This also frees the ACL data. */ |
98ccc74a | 622 | +void send_acl(statx *sxp, int f) |
0870c22a WD |
623 | +{ |
624 | + SMB_ACL_TYPE_T type; | |
625 | + rsync_acl *racl, *new_racl; | |
626 | + item_list *racl_list; | |
5d2612ca | 627 | + int ndx; |
53c1073a | 628 | + |
0870c22a WD |
629 | + if (S_ISLNK(sxp->st.st_mode)) |
630 | + return; | |
631 | + | |
632 | + type = SMB_ACL_TYPE_ACCESS; | |
633 | + racl = sxp->acc_acl; | |
634 | + racl_list = &access_acl_list; | |
635 | + do { | |
5d2612ca WD |
636 | + if (!racl) { |
637 | + racl = new(rsync_acl); | |
638 | + if (!racl) | |
639 | + out_of_memory("send_acl"); | |
640 | + *racl = empty_rsync_acl; | |
641 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
642 | + rsync_acl_fake_perms(racl, sxp->st.st_mode); | |
643 | + sxp->acc_acl = racl; | |
644 | + } else | |
645 | + sxp->def_acl = racl; | |
646 | + } | |
0870c22a | 647 | + |
0870c22a WD |
648 | + /* Avoid sending values that can be inferred from other data, |
649 | + * but only when preserve_acls == 1 (it is 2 when we must be | |
650 | + * backward compatible with older acls.diff versions). */ | |
651 | + if (type == SMB_ACL_TYPE_ACCESS && preserve_acls == 1) | |
652 | + rsync_acl_strip_perms(racl); | |
653 | + if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) != -1) { | |
654 | + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd'); | |
655 | + write_int(f, ndx); | |
0870c22a | 656 | + } else { |
645e162c | 657 | + new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000); |
0870c22a WD |
658 | + write_byte(f, type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D'); |
659 | + send_rsync_acl(f, racl); | |
660 | + *new_racl = *racl; | |
661 | + *racl = empty_rsync_acl; | |
662 | + } | |
663 | + racl = sxp->def_acl; | |
664 | + racl_list = &default_acl_list; | |
665 | + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode)); | |
666 | + | |
98ccc74a | 667 | + free_acl(sxp); |
fa26e11c WD |
668 | +} |
669 | + | |
0870c22a WD |
670 | +/* === Receive functions === */ |
671 | + | |
56294981 | 672 | +static void receive_rsync_acl(rsync_acl *racl, int f, SMB_ACL_TYPE_T type) |
fa26e11c | 673 | +{ |
6250eb3e | 674 | + static item_list temp_ida_list = EMPTY_ITEM_LIST; |
0870c22a | 675 | + SMB_ACL_TAG_T tag_type = 0, prior_list_type = 0; |
090d78e1 | 676 | + uchar computed_mask_bits = 0; |
c6437996 | 677 | + id_access *ida; |
ad625644 WD |
678 | + size_t count; |
679 | + | |
680 | + if (!(count = read_int(f))) | |
fa26e11c | 681 | + return; |
ad625644 | 682 | + |
fa26e11c | 683 | + while (count--) { |
dfadc68a | 684 | + char tag = read_byte(f); |
c6437996 WD |
685 | + uchar access = read_byte(f); |
686 | + if (access & ~ (4 | 2 | 1)) { | |
687 | + rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n", | |
688 | + access); | |
689 | + exit_cleanup(RERR_STREAMIO); | |
690 | + } | |
fa26e11c WD |
691 | + switch (tag) { |
692 | + case 'u': | |
0870c22a | 693 | + if (racl->user_obj != NO_ENTRY) { |
c6437996 WD |
694 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate USER_OBJ entry\n"); |
695 | + exit_cleanup(RERR_STREAMIO); | |
696 | + } | |
697 | + racl->user_obj = access; | |
698 | + continue; | |
fa26e11c | 699 | + case 'U': |
0870c22a | 700 | + tag_type = SMB_ACL_USER; |
fa26e11c WD |
701 | + break; |
702 | + case 'g': | |
0870c22a | 703 | + if (racl->group_obj != NO_ENTRY) { |
c6437996 WD |
704 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate GROUP_OBJ entry\n"); |
705 | + exit_cleanup(RERR_STREAMIO); | |
706 | + } | |
707 | + racl->group_obj = access; | |
708 | + continue; | |
fa26e11c | 709 | + case 'G': |
0870c22a | 710 | + tag_type = SMB_ACL_GROUP; |
fa26e11c WD |
711 | + break; |
712 | + case 'm': | |
0870c22a | 713 | + if (racl->mask != NO_ENTRY) { |
c6437996 WD |
714 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate MASK entry\n"); |
715 | + exit_cleanup(RERR_STREAMIO); | |
716 | + } | |
717 | + racl->mask = access; | |
718 | + continue; | |
719 | + case 'o': | |
0870c22a | 720 | + if (racl->other != NO_ENTRY) { |
c6437996 WD |
721 | + rprintf(FERROR, "receive_rsync_acl: error: duplicate OTHER entry\n"); |
722 | + exit_cleanup(RERR_STREAMIO); | |
723 | + } | |
724 | + racl->other = access; | |
725 | + continue; | |
fa26e11c WD |
726 | + default: |
727 | + rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n", | |
728 | + tag); | |
729 | + exit_cleanup(RERR_STREAMIO); | |
730 | + } | |
0870c22a WD |
731 | + if (tag_type != prior_list_type) { |
732 | + if (prior_list_type) | |
733 | + save_idas(&temp_ida_list, racl, prior_list_type); | |
734 | + prior_list_type = tag_type; | |
735 | + } | |
645e162c | 736 | + ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10); |
c6437996 WD |
737 | + ida->access = access; |
738 | + ida->id = read_int(f); | |
090d78e1 | 739 | + computed_mask_bits |= access; |
c6437996 | 740 | + } |
0870c22a WD |
741 | + if (prior_list_type) |
742 | + save_idas(&temp_ida_list, racl, prior_list_type); | |
c6437996 | 743 | + |
56294981 WD |
744 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
745 | + /* Ensure that these are never unset. */ | |
0870c22a | 746 | + if (racl->user_obj == NO_ENTRY) |
56294981 | 747 | + racl->user_obj = 7; |
0870c22a | 748 | + if (racl->group_obj == NO_ENTRY) |
56294981 | 749 | + racl->group_obj = 0; |
0870c22a | 750 | + if (racl->other == NO_ENTRY) |
56294981 WD |
751 | + racl->other = 0; |
752 | + } | |
8eb3e3ae | 753 | + |
c6437996 | 754 | + if (!racl->users.count && !racl->groups.count) { |
8eb3e3ae | 755 | + /* If we received a superfluous mask, throw it away. */ |
0870c22a | 756 | + if (racl->mask != NO_ENTRY) { |
8eb3e3ae | 757 | + /* Mask off the group perms with it first. */ |
0870c22a WD |
758 | + racl->group_obj &= racl->mask | NO_ENTRY; |
759 | + racl->mask = NO_ENTRY; | |
fa26e11c | 760 | + } |
0870c22a | 761 | + } else if (racl->mask == NO_ENTRY) /* Must be non-empty with lists. */ |
56294981 | 762 | + racl->mask = computed_mask_bits | (racl->group_obj & 7); |
fa26e11c WD |
763 | +} |
764 | + | |
0870c22a | 765 | +/* Receive the ACL info the sender has included for this file-list entry. */ |
98ccc74a | 766 | +void receive_acl(struct file_struct *file, int f) |
fa26e11c | 767 | +{ |
8db8e7d2 | 768 | + SMB_ACL_TYPE_T type; |
0870c22a WD |
769 | + item_list *racl_list; |
770 | + char *ndx_ptr; | |
36aa3171 | 771 | + |
162234a7 | 772 | + if (S_ISLNK(file->mode)) |
fa26e11c | 773 | + return; |
36aa3171 | 774 | + |
8db8e7d2 | 775 | + type = SMB_ACL_TYPE_ACCESS; |
0870c22a WD |
776 | + racl_list = &access_acl_list; |
777 | + ndx_ptr = (char*)file + file_struct_len; | |
8db8e7d2 | 778 | + do { |
0870c22a WD |
779 | + char tag = read_byte(f); |
780 | + int ndx; | |
fa26e11c | 781 | + |
fa26e11c | 782 | + if (tag == 'A' || tag == 'a') { |
8db8e7d2 | 783 | + if (type != SMB_ACL_TYPE_ACCESS) { |
fa26e11c | 784 | + rprintf(FERROR, "receive_acl %s: duplicate access ACL\n", |
f4222aa5 | 785 | + f_name(file, NULL)); |
fa26e11c WD |
786 | + exit_cleanup(RERR_STREAMIO); |
787 | + } | |
788 | + } else if (tag == 'D' || tag == 'd') { | |
8db8e7d2 | 789 | + if (type == SMB_ACL_TYPE_ACCESS) { |
fa26e11c | 790 | + rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n", |
f4222aa5 | 791 | + f_name(file, NULL)); |
fa26e11c WD |
792 | + exit_cleanup(RERR_STREAMIO); |
793 | + } | |
794 | + } else { | |
795 | + rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n", | |
f4222aa5 | 796 | + f_name(file, NULL), tag); |
fa26e11c WD |
797 | + exit_cleanup(RERR_STREAMIO); |
798 | + } | |
799 | + if (tag == 'A' || tag == 'D') { | |
0870c22a WD |
800 | + acl_duo *duo_item; |
801 | + ndx = racl_list->count; | |
645e162c | 802 | + duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000); |
b6c2bb12 | 803 | + duo_item->racl = empty_rsync_acl; |
0870c22a WD |
804 | + receive_rsync_acl(&duo_item->racl, f, type); |
805 | + duo_item->sacl = NULL; | |
fa26e11c | 806 | + } else { |
0870c22a | 807 | + ndx = read_int(f); |
d4531ffb | 808 | + if (ndx < 0 || (size_t)ndx >= racl_list->count) { |
fa26e11c | 809 | + rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n", |
0870c22a | 810 | + f_name(file, NULL), str_acl_type(type), ndx); |
fa26e11c WD |
811 | + exit_cleanup(RERR_STREAMIO); |
812 | + } | |
fa26e11c | 813 | + } |
0870c22a WD |
814 | + SIVAL(ndx_ptr, 0, ndx); |
815 | + racl_list = &default_acl_list; | |
816 | + ndx_ptr += 4; | |
8db8e7d2 | 817 | + } while (BUMP_TYPE(type) && S_ISDIR(file->mode)); |
fa26e11c WD |
818 | +} |
819 | + | |
5d2612ca WD |
820 | +/* Turn the ACL data in statx into cached ACL data, setting the index |
821 | + * values in the file struct. */ | |
822 | +void cache_acl(struct file_struct *file, statx *sxp) | |
823 | +{ | |
824 | + SMB_ACL_TYPE_T type; | |
825 | + rsync_acl *racl; | |
826 | + item_list *racl_list; | |
827 | + char *ndx_ptr; | |
828 | + int ndx; | |
829 | + | |
830 | + if (S_ISLNK(file->mode)) | |
831 | + return; | |
832 | + | |
833 | + type = SMB_ACL_TYPE_ACCESS; | |
834 | + racl = sxp->acc_acl; | |
835 | + racl_list = &access_acl_list; | |
836 | + ndx_ptr = (char*)file + file_struct_len; | |
837 | + do { | |
838 | + if (!racl) | |
839 | + ndx = -1; | |
840 | + else if ((ndx = find_matching_rsync_acl(type, racl_list, racl)) == -1) { | |
841 | + acl_duo *new_duo; | |
842 | + ndx = racl_list->count; | |
843 | + new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000); | |
844 | + new_duo->racl = *racl; | |
845 | + new_duo->sacl = NULL; | |
846 | + *racl = empty_rsync_acl; | |
847 | + } | |
848 | + SIVAL(ndx_ptr, 0, ndx); | |
849 | + racl = sxp->def_acl; | |
850 | + racl_list = &default_acl_list; | |
851 | + ndx_ptr += 4; | |
852 | + } while (BUMP_TYPE(type) && S_ISDIR(sxp->st.st_mode)); | |
853 | + | |
854 | + free_acl(sxp); | |
855 | +} | |
856 | + | |
0870c22a | 857 | +static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode) |
fa26e11c | 858 | +{ |
0870c22a WD |
859 | + SMB_ACL_ENTRY_T entry; |
860 | + const char *errfun; | |
861 | + int rc; | |
8db8e7d2 | 862 | + |
0870c22a WD |
863 | + if (S_ISDIR(mode)) { |
864 | + /* If the sticky bit is going on, it's not safe to allow all | |
adabede5 | 865 | + * the new ACL to go into effect before it gets set. */ |
0870c22a WD |
866 | +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS |
867 | + if (mode & S_ISVTX) | |
868 | + mode &= ~0077; | |
869 | +#else | |
870 | + if (mode & S_ISVTX && !(old_mode & S_ISVTX)) | |
871 | + mode &= ~0077; | |
872 | + } else { | |
873 | + /* If setuid or setgid is going off, it's not safe to allow all | |
adabede5 | 874 | + * the new ACL to go into effect before they get cleared. */ |
0870c22a WD |
875 | + if ((old_mode & S_ISUID && !(mode & S_ISUID)) |
876 | + || (old_mode & S_ISGID && !(mode & S_ISGID))) | |
877 | + mode &= ~0077; | |
878 | +#endif | |
879 | + } | |
8db8e7d2 | 880 | + |
0870c22a WD |
881 | + errfun = "sys_acl_get_entry"; |
882 | + for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry); | |
883 | + rc == 1; | |
884 | + rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) { | |
885 | + SMB_ACL_TAG_T tag_type; | |
886 | + if ((rc = sys_acl_get_tag_type(entry, &tag_type))) { | |
887 | + errfun = "sys_acl_get_tag_type"; | |
8db8e7d2 | 888 | + break; |
fa26e11c | 889 | + } |
0870c22a WD |
890 | + switch (tag_type) { |
891 | + case SMB_ACL_USER_OBJ: | |
892 | + COE2( store_access_in_entry,((mode >> 6) & 7, entry) ); | |
893 | + break; | |
894 | + case SMB_ACL_GROUP_OBJ: | |
895 | + /* group is only empty when identical to group perms. */ | |
896 | + if (racl->group_obj != NO_ENTRY) | |
897 | + break; | |
898 | + COE2( store_access_in_entry,((mode >> 3) & 7, entry) ); | |
899 | + break; | |
900 | + case SMB_ACL_MASK: | |
901 | +#ifndef ACLS_NEED_MASK | |
902 | + /* mask is only empty when we don't need it. */ | |
903 | + if (racl->mask == NO_ENTRY) | |
904 | + break; | |
905 | +#endif | |
906 | + COE2( store_access_in_entry,((mode >> 3) & 7, entry) ); | |
907 | + break; | |
908 | + case SMB_ACL_OTHER: | |
909 | + COE2( store_access_in_entry,(mode & 7, entry) ); | |
910 | + break; | |
8db8e7d2 | 911 | + } |
0870c22a WD |
912 | + } |
913 | + if (rc) { | |
914 | + error_exit: | |
915 | + if (errfun) { | |
916 | + rsyserr(FERROR, errno, "change_sacl_perms: %s()", | |
917 | + errfun); | |
fa26e11c | 918 | + } |
6e4c2d0c | 919 | + return (mode_t)~0; |
0870c22a | 920 | + } |
8db8e7d2 | 921 | + |
0870c22a WD |
922 | +#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS |
923 | + /* Ensure that chmod() will be called to restore any lost setid bits. */ | |
924 | + if (old_mode & (S_ISUID | S_ISGID | S_ISVTX) | |
925 | + && (old_mode & CHMOD_BITS) == (mode & CHMOD_BITS)) | |
926 | + old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX); | |
927 | +#endif | |
8db8e7d2 | 928 | + |
0870c22a WD |
929 | + /* Return the mode of the file on disk, as we will set them. */ |
930 | + return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS); | |
fa26e11c WD |
931 | +} |
932 | + | |
0870c22a | 933 | +/* Set ACL on indicated filename. |
c6437996 | 934 | + * |
adabede5 WD |
935 | + * This sets extended access ACL entries and default ACL. If convenient, |
936 | + * it sets permission bits along with the access ACL and signals having | |
0870c22a | 937 | + * done so by modifying sxp->st.st_mode. |
c6437996 | 938 | + * |
0870c22a | 939 | + * Returns 1 for unchanged, 0 for changed, -1 for failed. Call this |
adabede5 | 940 | + * with fname set to NULL to just check if the ACL is unchanged. */ |
98ccc74a | 941 | +int set_acl(const char *fname, const struct file_struct *file, statx *sxp) |
fa26e11c | 942 | +{ |
81ddc4dc | 943 | + int unchanged = 1; |
8db8e7d2 | 944 | + SMB_ACL_TYPE_T type; |
0870c22a | 945 | + char *ndx_ptr; |
36aa3171 | 946 | + |
0909ae28 WD |
947 | + if (!dry_run && (read_only || list_only)) { |
948 | + errno = EROFS; | |
949 | + return -1; | |
950 | + } | |
951 | + | |
c6437996 WD |
952 | + if (S_ISLNK(file->mode)) |
953 | + return 1; | |
36aa3171 | 954 | + |
8db8e7d2 | 955 | + type = SMB_ACL_TYPE_ACCESS; |
0870c22a | 956 | + ndx_ptr = (char*)file + file_struct_len; |
8db8e7d2 | 957 | + do { |
0870c22a WD |
958 | + acl_duo *duo_item; |
959 | + BOOL eq; | |
5d2612ca | 960 | + int32 ndx = IVAL(ndx_ptr, 0); |
0870c22a WD |
961 | + |
962 | + ndx_ptr += 4; | |
963 | + | |
964 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
5d2612ca WD |
965 | + if (ndx < 0 || (size_t)ndx >= access_acl_list.count) |
966 | + continue; | |
0870c22a WD |
967 | + duo_item = access_acl_list.items; |
968 | + duo_item += ndx; | |
5d2612ca WD |
969 | + eq = sxp->acc_acl |
970 | + && rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, file->mode); | |
0870c22a | 971 | + } else { |
5d2612ca WD |
972 | + if (ndx < 0 || (size_t)ndx >= default_acl_list.count) |
973 | + continue; | |
0870c22a WD |
974 | + duo_item = default_acl_list.items; |
975 | + duo_item += ndx; | |
5d2612ca WD |
976 | + eq = sxp->def_acl |
977 | + && rsync_acl_equal(sxp->def_acl, &duo_item->racl); | |
fa26e11c | 978 | + } |
0870c22a | 979 | + if (eq) |
fa26e11c | 980 | + continue; |
0870c22a | 981 | + if (!dry_run && fname) { |
c6437996 | 982 | + if (type == SMB_ACL_TYPE_DEFAULT |
0870c22a | 983 | + && duo_item->racl.user_obj == NO_ENTRY) { |
c6437996 | 984 | + if (sys_acl_delete_def_file(fname) < 0) { |
0870c22a WD |
985 | + rsyserr(FERROR, errno, "set_acl: sys_acl_delete_def_file(%s)", |
986 | + fname); | |
c6437996 WD |
987 | + unchanged = -1; |
988 | + continue; | |
989 | + } | |
990 | + } else { | |
0870c22a WD |
991 | + mode_t cur_mode = sxp->st.st_mode; |
992 | + if (!duo_item->sacl | |
993 | + && !pack_smb_acl(&duo_item->sacl, &duo_item->racl)) { | |
c6437996 WD |
994 | + unchanged = -1; |
995 | + continue; | |
996 | + } | |
997 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
0870c22a | 998 | + cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl, |
c6437996 | 999 | + cur_mode, file->mode); |
6e4c2d0c | 1000 | + if (cur_mode == (mode_t)~0) |
0e879f7f | 1001 | + continue; |
c6437996 | 1002 | + } |
0870c22a WD |
1003 | + if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) { |
1004 | + rsyserr(FERROR, errno, "set_acl: sys_acl_set_file(%s, %s)", | |
1005 | + fname, str_acl_type(type)); | |
c6437996 WD |
1006 | + unchanged = -1; |
1007 | + continue; | |
1008 | + } | |
1009 | + if (type == SMB_ACL_TYPE_ACCESS) | |
0870c22a | 1010 | + sxp->st.st_mode = cur_mode; |
fa26e11c WD |
1011 | + } |
1012 | + } | |
81ddc4dc WD |
1013 | + if (unchanged == 1) |
1014 | + unchanged = 0; | |
8db8e7d2 WD |
1015 | + } while (BUMP_TYPE(type) && S_ISDIR(file->mode)); |
1016 | + | |
81ddc4dc | 1017 | + return unchanged; |
fa26e11c WD |
1018 | +} |
1019 | + | |
0870c22a | 1020 | +/* === Enumeration functions for uid mapping === */ |
fa26e11c | 1021 | + |
4edb99c8 WD |
1022 | +/* Context -- one and only one. Should be cycled through once on uid |
1023 | + * mapping and once on gid mapping. */ | |
0870c22a WD |
1024 | +static item_list *_enum_racl_lists[] = { |
1025 | + &access_acl_list, &default_acl_list, NULL | |
fa26e11c WD |
1026 | +}; |
1027 | + | |
0870c22a WD |
1028 | +static item_list **enum_racl_list = &_enum_racl_lists[0]; |
1029 | +static int enum_ida_index = 0; | |
fa26e11c | 1030 | +static size_t enum_racl_index = 0; |
fa26e11c | 1031 | + |
adabede5 | 1032 | +/* This returns the next tag_type id from the given ACL for the next entry, |
4edb99c8 | 1033 | + * or it returns 0 if there are no more tag_type ids in the acl. */ |
c52977bc | 1034 | +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl) |
fa26e11c | 1035 | +{ |
0870c22a | 1036 | + const ida_entries *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups; |
c6437996 WD |
1037 | + if (enum_ida_index < idal->count) { |
1038 | + id_access *ida = &idal->idas[enum_ida_index++]; | |
1039 | + return &ida->id; | |
fa26e11c | 1040 | + } |
c6437996 | 1041 | + enum_ida_index = 0; |
c52977bc | 1042 | + return NULL; |
fa26e11c WD |
1043 | +} |
1044 | + | |
0870c22a | 1045 | +static id_t *next_acl_id(SMB_ACL_TAG_T tag_type, const item_list *racl_list) |
fa26e11c WD |
1046 | +{ |
1047 | + for (; enum_racl_index < racl_list->count; enum_racl_index++) { | |
0870c22a WD |
1048 | + id_t *id; |
1049 | + acl_duo *duo_item = racl_list->items; | |
1050 | + duo_item += enum_racl_index; | |
1051 | + if ((id = next_ace_id(tag_type, &duo_item->racl)) != NULL) | |
fa26e11c WD |
1052 | + return id; |
1053 | + } | |
1054 | + enum_racl_index = 0; | |
c52977bc | 1055 | + return NULL; |
fa26e11c WD |
1056 | +} |
1057 | + | |
c52977bc | 1058 | +static id_t *next_acl_list_id(SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
1059 | +{ |
1060 | + for (; *enum_racl_list; enum_racl_list++) { | |
c52977bc | 1061 | + id_t *id = next_acl_id(tag_type, *enum_racl_list); |
fa26e11c WD |
1062 | + if (id) |
1063 | + return id; | |
1064 | + } | |
1065 | + enum_racl_list = &_enum_racl_lists[0]; | |
c52977bc | 1066 | + return NULL; |
fa26e11c WD |
1067 | +} |
1068 | + | |
c52977bc | 1069 | +id_t *next_acl_uid() |
fa26e11c WD |
1070 | +{ |
1071 | + return next_acl_list_id(SMB_ACL_USER); | |
1072 | +} | |
1073 | + | |
c52977bc | 1074 | +id_t *next_acl_gid() |
fa26e11c WD |
1075 | +{ |
1076 | + return next_acl_list_id(SMB_ACL_GROUP); | |
1077 | +} | |
1078 | + | |
0870c22a | 1079 | +/* This is used by dest_mode(). */ |
26c810d8 | 1080 | +int default_perms_for_dir(const char *dir) |
90fa6d68 WD |
1081 | +{ |
1082 | + rsync_acl racl; | |
1083 | + SMB_ACL_T sacl; | |
c6437996 | 1084 | + BOOL ok; |
26c810d8 | 1085 | + int perms; |
90fa6d68 WD |
1086 | + |
1087 | + if (dir == NULL) | |
1088 | + dir = "."; | |
26c810d8 | 1089 | + perms = ACCESSPERMS & ~orig_umask; |
90fa6d68 WD |
1090 | + /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */ |
1091 | + sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT); | |
1092 | + if (sacl == NULL) { | |
1093 | + /* Couldn't get an ACL. Darn. */ | |
1094 | + switch (errno) { | |
1095 | + case ENOTSUP: | |
1096 | + /* ACLs are disabled. We could yell at the user to turn them on, but... */ | |
1097 | + break; | |
1098 | + case ENOENT: | |
1099 | + if (dry_run) { | |
1100 | + /* We're doing a dry run, so the containing directory | |
1101 | + * wasn't actually created. Don't worry about it. */ | |
1102 | + break; | |
1103 | + } | |
1104 | + /* Otherwise fall through. */ | |
1105 | + default: | |
26c810d8 | 1106 | + rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n", |
90fa6d68 WD |
1107 | + dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno)); |
1108 | + } | |
26c810d8 | 1109 | + return perms; |
90fa6d68 WD |
1110 | + } |
1111 | + | |
1112 | + /* Convert it. */ | |
b6c2bb12 | 1113 | + racl = empty_rsync_acl; |
90fa6d68 WD |
1114 | + ok = unpack_smb_acl(&racl, sacl); |
1115 | + sys_acl_free_acl(sacl); | |
1116 | + if (!ok) { | |
26c810d8 WD |
1117 | + rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n"); |
1118 | + return perms; | |
90fa6d68 WD |
1119 | + } |
1120 | + | |
c6437996 | 1121 | + /* Apply the permission-bit entries of the default ACL, if any. */ |
0870c22a | 1122 | + if (racl.user_obj != NO_ENTRY) { |
c6437996 WD |
1123 | + perms = rsync_acl_get_perms(&racl); |
1124 | + if (verbose > 2) | |
1125 | + rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir); | |
90fa6d68 | 1126 | + } |
c6437996 | 1127 | + |
90fa6d68 | 1128 | + rsync_acl_free(&racl); |
26c810d8 | 1129 | + return perms; |
90fa6d68 WD |
1130 | +} |
1131 | + | |
fa26e11c | 1132 | +#endif /* SUPPORT_ACLS */ |
9a7eef96 WD |
1133 | --- old/backup.c |
1134 | +++ new/backup.c | |
c1471566 | 1135 | @@ -29,6 +29,7 @@ extern char *backup_suffix; |
162234a7 WD |
1136 | extern char *backup_dir; |
1137 | ||
1138 | extern int am_root; | |
1139 | +extern int preserve_acls; | |
1140 | extern int preserve_devices; | |
1141 | extern int preserve_specials; | |
1142 | extern int preserve_links; | |
0870c22a WD |
1143 | @@ -94,7 +95,8 @@ path |
1144 | ****************************************************************************/ | |
1145 | static int make_bak_dir(char *fullpath) | |
1146 | { | |
1147 | - STRUCT_STAT st; | |
1148 | + statx sx; | |
1149 | + struct file_struct *file; | |
1150 | char *rel = fullpath + backup_dir_len; | |
1151 | char *end = rel + strlen(rel); | |
1152 | char *p = end; | |
1153 | @@ -126,13 +128,24 @@ static int make_bak_dir(char *fullpath) | |
1154 | if (p >= rel) { | |
1155 | /* Try to transfer the directory settings of the | |
1156 | * actual dir that the files are coming from. */ | |
1157 | - if (do_stat(rel, &st) < 0) { | |
1158 | + if (do_stat(rel, &sx.st) < 0) { | |
1159 | rsyserr(FERROR, errno, | |
1160 | "make_bak_dir stat %s failed", | |
1161 | full_fname(rel)); | |
fa26e11c | 1162 | } else { |
0870c22a WD |
1163 | - do_lchown(fullpath, st.st_uid, st.st_gid); |
1164 | - do_chmod(fullpath, st.st_mode); | |
1165 | +#ifdef SUPPORT_ACLS | |
1166 | + sx.acc_acl = sx.def_acl = NULL; | |
1167 | +#endif | |
1168 | + if (!(file = make_file(rel, NULL, NULL, 0, NO_FILTERS))) | |
1169 | + continue; | |
e6a7303b | 1170 | +#ifdef SUPPORT_ACLS |
0870c22a | 1171 | + if (preserve_acls) { |
98ccc74a WD |
1172 | + get_acl(rel, &sx); |
1173 | + cache_acl(file, &sx); | |
0870c22a | 1174 | + } |
e6a7303b | 1175 | +#endif |
0870c22a WD |
1176 | + set_file_attrs(fullpath, file, NULL, 0); |
1177 | + free(file); | |
fa26e11c WD |
1178 | } |
1179 | } | |
1180 | *p = '/'; | |
0870c22a WD |
1181 | @@ -170,15 +183,18 @@ static int robust_move(char *src, char * |
1182 | * We will move the file to be deleted into a parallel directory tree. */ | |
1183 | static int keep_backup(char *fname) | |
1184 | { | |
1185 | - STRUCT_STAT st; | |
1186 | + statx sx; | |
1187 | struct file_struct *file; | |
1188 | char *buf; | |
1189 | int kept = 0; | |
1190 | int ret_code; | |
1191 | ||
1192 | /* return if no file to keep */ | |
1193 | - if (do_lstat(fname, &st) < 0) | |
1194 | + if (do_lstat(fname, &sx.st) < 0) | |
1195 | return 1; | |
1196 | +#ifdef SUPPORT_ACLS | |
1197 | + sx.acc_acl = sx.def_acl = NULL; | |
1198 | +#endif | |
1199 | ||
1200 | if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) | |
1201 | return 1; /* the file could have disappeared */ | |
1202 | @@ -186,6 +202,13 @@ static int keep_backup(char *fname) | |
172ad6c3 | 1203 | if (!(buf = get_backup_name(fname))) |
fa26e11c | 1204 | return 0; |
fa26e11c | 1205 | |
e6a7303b | 1206 | +#ifdef SUPPORT_ACLS |
0870c22a | 1207 | + if (preserve_acls) { |
98ccc74a WD |
1208 | + get_acl(fname, &sx); |
1209 | + cache_acl(file, &sx); | |
0870c22a | 1210 | + } |
e6a7303b | 1211 | +#endif |
fa26e11c | 1212 | + |
fa26e11c | 1213 | /* Check to see if this is a device file, or link */ |
90fa6d68 WD |
1214 | if ((am_root && preserve_devices && IS_DEVICE(file->mode)) |
1215 | || (preserve_specials && IS_SPECIAL(file->mode))) { | |
0870c22a WD |
1216 | @@ -254,7 +277,7 @@ static int keep_backup(char *fname) |
1217 | if (robust_move(fname, buf) != 0) { | |
1218 | rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"", | |
1219 | full_fname(fname), buf); | |
1220 | - } else if (st.st_nlink > 1) { | |
1221 | + } else if (sx.st.st_nlink > 1) { | |
1222 | /* If someone has hard-linked the file into the backup | |
1223 | * dir, rename() might return success but do nothing! */ | |
1224 | robust_unlink(fname); /* Just in case... */ | |
9a7eef96 WD |
1225 | --- old/configure.in |
1226 | +++ new/configure.in | |
bdf1eee8 | 1227 | @@ -515,6 +515,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no |
fa26e11c WD |
1228 | AC_CHECK_LIB(resolv, strcasecmp) |
1229 | fi | |
1230 | ||
1231 | +AC_CHECK_FUNCS(aclsort) | |
1232 | +if test x"$ac_cv_func_aclsort" = x"no"; then | |
1233 | + AC_CHECK_LIB(sec, aclsort) | |
1234 | +fi | |
1235 | + | |
1236 | dnl At the moment we don't test for a broken memcmp(), because all we | |
1237 | dnl need to do is test for equality, not comparison, and it seems that | |
1238 | dnl every platform has a memcmp that can do at least that. | |
bdf1eee8 | 1239 | @@ -779,6 +784,78 @@ AC_SUBST(OBJ_RESTORE) |
fa26e11c WD |
1240 | AC_SUBST(CC_SHOBJ_FLAG) |
1241 | AC_SUBST(BUILD_POPT) | |
125d7fca | 1242 | |
0909ae28 | 1243 | +AC_CHECK_HEADERS(sys/acl.h acl/libacl.h) |
fa26e11c WD |
1244 | +AC_CHECK_FUNCS(_acl __acl _facl __facl) |
1245 | +################################################# | |
1246 | +# check for ACL support | |
1247 | + | |
1248 | +AC_MSG_CHECKING(whether to support ACLs) | |
f787c90c WD |
1249 | +AC_ARG_ENABLE(acl-support, |
1250 | +AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]), | |
3b05e91f | 1251 | +[ case "$enableval" in |
fa26e11c WD |
1252 | + yes) |
1253 | + | |
1254 | + case "$host_os" in | |
1255 | + *sysv5*) | |
1256 | + AC_MSG_RESULT(Using UnixWare ACLs) | |
1257 | + AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs]) | |
1258 | + ;; | |
53c1073a | 1259 | + *solaris*|*cygwin*) |
fa26e11c WD |
1260 | + AC_MSG_RESULT(Using solaris ACLs) |
1261 | + AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs]) | |
1262 | + ;; | |
1263 | + *hpux*) | |
1264 | + AC_MSG_RESULT(Using HPUX ACLs) | |
1265 | + AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs]) | |
1266 | + ;; | |
1267 | + *irix*) | |
1268 | + AC_MSG_RESULT(Using IRIX ACLs) | |
1269 | + AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs]) | |
1270 | + ;; | |
1271 | + *aix*) | |
1272 | + AC_MSG_RESULT(Using AIX ACLs) | |
1273 | + AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs]) | |
1274 | + ;; | |
1275 | + *osf*) | |
1276 | + AC_MSG_RESULT(Using Tru64 ACLs) | |
1277 | + AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs]) | |
1278 | + LIBS="$LIBS -lpacl" | |
1279 | + ;; | |
1280 | + *) | |
81549708 | 1281 | + AC_MSG_RESULT(ACLs requested -- running tests) |
fa26e11c WD |
1282 | + AC_CHECK_LIB(acl,acl_get_file) |
1283 | + AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[ | |
1284 | + AC_TRY_LINK([#include <sys/types.h> | |
1285 | +#include <sys/acl.h>], | |
1286 | +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);], | |
1287 | +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)]) | |
03d25fc5 | 1288 | + AC_MSG_CHECKING(ACL test results) |
fa26e11c WD |
1289 | + if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then |
1290 | + AC_MSG_RESULT(Using posix ACLs) | |
1291 | + AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs]) | |
81549708 | 1292 | + AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[ |
fa26e11c WD |
1293 | + AC_TRY_LINK([#include <sys/types.h> |
1294 | +#include <sys/acl.h>], | |
1295 | +[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);], | |
1296 | +samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)]) | |
81549708 WD |
1297 | + if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then |
1298 | + AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np]) | |
1299 | + fi | |
1300 | + else | |
1301 | + AC_MSG_ERROR(Failed to find ACL support) | |
fa26e11c WD |
1302 | + fi |
1303 | + ;; | |
1304 | + esac | |
1305 | + ;; | |
1306 | + *) | |
1307 | + AC_MSG_RESULT(no) | |
1308 | + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs]) | |
1309 | + ;; | |
1310 | + esac ], | |
1311 | + AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs]) | |
1312 | + AC_MSG_RESULT(no) | |
1313 | +) | |
125d7fca | 1314 | + |
fa26e11c WD |
1315 | AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig]) |
1316 | AC_OUTPUT | |
125d7fca | 1317 | |
9a7eef96 WD |
1318 | --- old/flist.c |
1319 | +++ new/flist.c | |
55c1a3b7 | 1320 | @@ -40,6 +40,7 @@ extern int filesfrom_fd; |
162234a7 WD |
1321 | extern int one_file_system; |
1322 | extern int copy_dirlinks; | |
1323 | extern int keep_dirlinks; | |
1324 | +extern int preserve_acls; | |
1325 | extern int preserve_links; | |
1326 | extern int preserve_hard_links; | |
1327 | extern int preserve_devices; | |
55c1a3b7 | 1328 | @@ -133,6 +134,8 @@ static void list_file_entry(struct file_ |
0870c22a WD |
1329 | |
1330 | permstring(permbuf, f->mode); | |
1331 | ||
98ccc74a | 1332 | + /* TODO: indicate '+' if the entry has an ACL. */ |
0870c22a WD |
1333 | + |
1334 | #ifdef SUPPORT_LINKS | |
1335 | if (preserve_links && S_ISLNK(f->mode)) { | |
1336 | rprintf(FINFO, "%s %11.0f %s %s -> %s\n", | |
668bbc0a | 1337 | @@ -495,6 +498,9 @@ static struct file_struct *receive_file_ |
0870c22a WD |
1338 | char thisname[MAXPATHLEN]; |
1339 | unsigned int l1 = 0, l2 = 0; | |
1340 | int alloc_len, basename_len, dirname_len, linkname_len, sum_len; | |
1341 | +#ifdef SUPPORT_ACLS | |
f0e2362d | 1342 | + int xtra_len; |
0870c22a WD |
1343 | +#endif |
1344 | OFF_T file_length; | |
1345 | char *basename, *dirname, *bp; | |
1346 | struct file_struct *file; | |
668bbc0a | 1347 | @@ -598,13 +604,27 @@ static struct file_struct *receive_file_ |
0870c22a WD |
1348 | |
1349 | sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0; | |
1350 | ||
1351 | +#ifdef SUPPORT_ACLS | |
1352 | + /* We need one or two index int32s when we're preserving ACLs. */ | |
1353 | + if (preserve_acls) | |
98ccc74a | 1354 | + xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4; |
0870c22a | 1355 | + else |
f0e2362d | 1356 | + xtra_len = 0; |
0870c22a WD |
1357 | +#endif |
1358 | + | |
1359 | alloc_len = file_struct_len + dirname_len + basename_len | |
1360 | +#ifdef SUPPORT_ACLS | |
f0e2362d | 1361 | + + xtra_len |
0870c22a WD |
1362 | +#endif |
1363 | + linkname_len + sum_len; | |
1364 | bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry"); | |
1365 | ||
1366 | file = (struct file_struct *)bp; | |
1367 | memset(bp, 0, file_struct_len); | |
1368 | bp += file_struct_len; | |
1369 | +#ifdef SUPPORT_ACLS | |
f0e2362d | 1370 | + bp += xtra_len; |
0870c22a WD |
1371 | +#endif |
1372 | ||
1373 | file->modtime = modtime; | |
1374 | file->length = file_length; | |
668bbc0a | 1375 | @@ -699,6 +719,11 @@ static struct file_struct *receive_file_ |
0870c22a WD |
1376 | read_buf(f, sum, checksum_len); |
1377 | } | |
1378 | ||
1379 | +#ifdef SUPPORT_ACLS | |
1380 | + if (preserve_acls) | |
98ccc74a | 1381 | + receive_acl(file, f); |
0870c22a WD |
1382 | +#endif |
1383 | + | |
1384 | return file; | |
1385 | } | |
1386 | ||
668bbc0a | 1387 | @@ -949,6 +974,9 @@ static struct file_struct *send_file_nam |
0870c22a WD |
1388 | unsigned short flags) |
1389 | { | |
1390 | struct file_struct *file; | |
1391 | +#ifdef SUPPORT_ACLS | |
1392 | + statx sx; | |
1393 | +#endif | |
1394 | ||
1395 | file = make_file(fname, flist, stp, flags, | |
1396 | f == -2 ? SERVER_FILTERS : ALL_FILTERS); | |
668bbc0a | 1397 | @@ -958,6 +986,15 @@ static struct file_struct *send_file_nam |
cf51033a WD |
1398 | if (chmod_modes && !S_ISLNK(file->mode)) |
1399 | file->mode = tweak_mode(file->mode, chmod_modes); | |
1400 | ||
e6a7303b | 1401 | +#ifdef SUPPORT_ACLS |
0870c22a WD |
1402 | + if (preserve_acls) { |
1403 | + sx.st.st_mode = file->mode; | |
1404 | + sx.acc_acl = sx.def_acl = NULL; | |
98ccc74a | 1405 | + if (get_acl(fname, &sx) < 0) |
0870c22a WD |
1406 | + return NULL; |
1407 | + } | |
e6a7303b | 1408 | +#endif |
cf51033a WD |
1409 | + |
1410 | maybe_emit_filelist_progress(flist->count + flist_count_offset); | |
fa26e11c | 1411 | |
cf51033a | 1412 | flist_expand(flist); |
668bbc0a | 1413 | @@ -965,6 +1002,15 @@ static struct file_struct *send_file_nam |
fa26e11c WD |
1414 | if (file->basename[0]) { |
1415 | flist->files[flist->count++] = file; | |
e0e47893 | 1416 | send_file_entry(file, f); |
e6a7303b | 1417 | +#ifdef SUPPORT_ACLS |
162234a7 | 1418 | + if (preserve_acls) |
98ccc74a | 1419 | + send_acl(&sx, f); |
162234a7 | 1420 | +#endif |
fa26e11c | 1421 | + } else { |
162234a7 | 1422 | +#ifdef SUPPORT_ACLS |
0870c22a | 1423 | + if (preserve_acls) |
98ccc74a | 1424 | + free_acl(&sx); |
0870c22a WD |
1425 | +#endif |
1426 | } | |
1427 | return file; | |
1428 | } | |
1429 | --- old/generator.c | |
1430 | +++ new/generator.c | |
74eccbb1 | 1431 | @@ -35,6 +35,7 @@ extern int do_progress; |
0870c22a WD |
1432 | extern int relative_paths; |
1433 | extern int implied_dirs; | |
1434 | extern int keep_dirlinks; | |
1435 | +extern int preserve_acls; | |
1436 | extern int preserve_links; | |
1437 | extern int preserve_devices; | |
1438 | extern int preserve_specials; | |
2a787d74 | 1439 | @@ -85,6 +86,7 @@ extern long block_size; /* "long" becaus |
0870c22a WD |
1440 | extern int max_delete; |
1441 | extern int force_delete; | |
1442 | extern int one_file_system; | |
1443 | +extern mode_t orig_umask; | |
1444 | extern struct stats stats; | |
1445 | extern dev_t filesystem_dev; | |
1446 | extern char *backup_dir; | |
2a787d74 | 1447 | @@ -317,22 +319,27 @@ static void do_delete_pass(struct file_l |
0870c22a WD |
1448 | rprintf(FINFO, " \r"); |
1449 | } | |
1450 | ||
1451 | -int unchanged_attrs(struct file_struct *file, STRUCT_STAT *st) | |
1452 | +int unchanged_attrs(struct file_struct *file, statx *sxp) | |
1453 | { | |
1454 | if (preserve_perms | |
1455 | - && (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) | |
1456 | + && (sxp->st.st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) | |
1457 | return 0; | |
1458 | ||
1459 | - if (am_root && preserve_uid && st->st_uid != file->uid) | |
1460 | + if (am_root && preserve_uid && sxp->st.st_uid != file->uid) | |
1461 | return 0; | |
1462 | ||
1463 | - if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid) | |
1464 | + if (preserve_gid && file->gid != GID_NONE && sxp->st.st_gid != file->gid) | |
f42b0645 WD |
1465 | + return 0; |
1466 | + | |
0870c22a | 1467 | +#ifdef SUPPORT_ACLS |
98ccc74a | 1468 | + if (preserve_acls && set_acl(NULL, file, sxp) == 0) |
f42b0645 | 1469 | return 0; |
0870c22a | 1470 | +#endif |
f42b0645 | 1471 | |
0870c22a WD |
1472 | return 1; |
1473 | } | |
1474 | ||
1475 | -void itemize(struct file_struct *file, int ndx, int statret, STRUCT_STAT *st, | |
1476 | +void itemize(struct file_struct *file, int ndx, int statret, statx *sxp, | |
1477 | int32 iflags, uchar fnamecmp_type, char *xname) | |
1478 | { | |
1479 | if (statret >= 0) { /* A from-dest-dir statret can == 1! */ | |
2a787d74 | 1480 | @@ -340,19 +347,23 @@ void itemize(struct file_struct *file, i |
0870c22a WD |
1481 | : S_ISDIR(file->mode) ? !omit_dir_times |
1482 | : !S_ISLNK(file->mode); | |
1483 | ||
1484 | - if (S_ISREG(file->mode) && file->length != st->st_size) | |
1485 | + if (S_ISREG(file->mode) && file->length != sxp->st.st_size) | |
1486 | iflags |= ITEM_REPORT_SIZE; | |
1487 | if ((iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !keep_time | |
1488 | && (!(iflags & ITEM_XNAME_FOLLOWS) || *xname)) | |
1489 | - || (keep_time && cmp_time(file->modtime, st->st_mtime) != 0)) | |
1490 | + || (keep_time && cmp_time(file->modtime, sxp->st.st_mtime) != 0)) | |
1491 | iflags |= ITEM_REPORT_TIME; | |
1492 | - if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS)) | |
1493 | + if ((file->mode & CHMOD_BITS) != (sxp->st.st_mode & CHMOD_BITS)) | |
1494 | iflags |= ITEM_REPORT_PERMS; | |
1495 | - if (preserve_uid && am_root && file->uid != st->st_uid) | |
1496 | + if (preserve_uid && am_root && file->uid != sxp->st.st_uid) | |
1497 | iflags |= ITEM_REPORT_OWNER; | |
1498 | if (preserve_gid && file->gid != GID_NONE | |
1499 | - && st->st_gid != file->gid) | |
1500 | + && sxp->st.st_gid != file->gid) | |
1501 | iflags |= ITEM_REPORT_GROUP; | |
1502 | +#ifdef SUPPORT_ACLS | |
98ccc74a | 1503 | + if (preserve_acls && set_acl(NULL, file, sxp) == 0) |
0870c22a WD |
1504 | + iflags |= ITEM_REPORT_ACL; |
1505 | +#endif | |
1506 | } else | |
1507 | iflags |= ITEM_IS_NEW; | |
1508 | ||
2a787d74 | 1509 | @@ -605,7 +616,7 @@ void check_for_finished_hlinks(int itemi |
0870c22a WD |
1510 | * handling the file, -1 if no dest-linking occurred, or a non-negative |
1511 | * value if we found an alternate basis file. */ | |
1512 | static int try_dests_reg(struct file_struct *file, char *fname, int ndx, | |
1513 | - char *cmpbuf, STRUCT_STAT *stp, int itemizing, | |
1514 | + char *cmpbuf, statx *sxp, int itemizing, | |
1515 | int maybe_ATTRS_REPORT, enum logcode code) | |
1516 | { | |
1ed0b5c9 | 1517 | int best_match = -1; |
2a787d74 | 1518 | @@ -614,7 +625,7 @@ static int try_dests_reg(struct file_str |
0870c22a WD |
1519 | |
1520 | do { | |
1521 | pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); | |
1522 | - if (link_stat(cmpbuf, stp, 0) < 0 || !S_ISREG(stp->st_mode)) | |
1523 | + if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode)) | |
1524 | continue; | |
1525 | switch (match_level) { | |
1526 | case 0: | |
2a787d74 | 1527 | @@ -622,16 +633,20 @@ static int try_dests_reg(struct file_str |
0870c22a WD |
1528 | match_level = 1; |
1529 | /* FALL THROUGH */ | |
1530 | case 1: | |
1531 | - if (!unchanged_file(cmpbuf, file, stp)) | |
1532 | + if (!unchanged_file(cmpbuf, file, &sxp->st)) | |
1533 | continue; | |
1534 | best_match = j; | |
1535 | match_level = 2; | |
1536 | /* FALL THROUGH */ | |
1537 | case 2: | |
1538 | - if (!unchanged_attrs(file, stp)) | |
1539 | +#ifdef SUPPORT_ACLS | |
1540 | + if (preserve_acls) | |
98ccc74a | 1541 | + get_acl(cmpbuf, sxp); |
0870c22a WD |
1542 | +#endif |
1543 | + if (!unchanged_attrs(file, sxp)) | |
1544 | continue; | |
9386e6b3 | 1545 | if (always_checksum && preserve_times |
0870c22a WD |
1546 | - && cmp_time(stp->st_mtime, file->modtime)) |
1547 | + && cmp_time(sxp->st.st_mtime, file->modtime)) | |
1548 | continue; | |
1549 | best_match = j; | |
1550 | match_level = 3; | |
2a787d74 | 1551 | @@ -646,14 +661,14 @@ static int try_dests_reg(struct file_str |
0870c22a WD |
1552 | if (j != best_match) { |
1553 | j = best_match; | |
1554 | pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); | |
1555 | - if (link_stat(cmpbuf, stp, 0) < 0) | |
1556 | + if (link_stat(cmpbuf, &sxp->st, 0) < 0) | |
85148847 | 1557 | return -1; |
0870c22a WD |
1558 | } |
1559 | ||
0870c22a | 1560 | if (match_level == 3 && !copy_dest) { |
98e4de3d | 1561 | #ifdef SUPPORT_HARD_LINKS |
0870c22a WD |
1562 | if (link_dest) { |
1563 | - if (hard_link_one(file, ndx, fname, 0, stp, | |
1564 | + if (hard_link_one(file, ndx, fname, 0, sxp, | |
1565 | cmpbuf, 1, | |
1566 | itemizing && verbose > 1, | |
1567 | code) < 0) | |
2a787d74 WD |
1568 | @@ -665,8 +680,13 @@ static int try_dests_reg(struct file_str |
1569 | } | |
98e4de3d WD |
1570 | } else |
1571 | #endif | |
1572 | - if (itemizing) | |
0870c22a | 1573 | - itemize(file, ndx, 0, stp, 0, 0, NULL); |
98e4de3d | 1574 | + if (itemizing) { |
0870c22a WD |
1575 | +#ifdef SUPPORT_ACLS |
1576 | + if (preserve_acls && !ACL_READY(*sxp)) | |
98ccc74a | 1577 | + get_acl(fname, sxp); |
0870c22a WD |
1578 | +#endif |
1579 | + itemize(file, ndx, 0, sxp, 0, 0, NULL); | |
1580 | + } | |
1581 | if (verbose > 1 && maybe_ATTRS_REPORT) { | |
74eccbb1 WD |
1582 | rprintf(FCLIENT, "%s is uptodate\n", fname); |
1583 | } | |
2a787d74 | 1584 | @@ -682,8 +702,13 @@ static int try_dests_reg(struct file_str |
0870c22a WD |
1585 | } |
1586 | return -1; | |
1587 | } | |
1588 | - if (itemizing) | |
1589 | - itemize(file, ndx, 0, stp, ITEM_LOCAL_CHANGE, 0, NULL); | |
1590 | + if (itemizing) { | |
1591 | +#ifdef SUPPORT_ACLS | |
1592 | + if (preserve_acls && !ACL_READY(*sxp)) | |
98ccc74a | 1593 | + get_acl(fname, sxp); |
e6a7303b | 1594 | +#endif |
0870c22a WD |
1595 | + itemize(file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL); |
1596 | + } | |
1597 | set_file_attrs(fname, file, NULL, 0); | |
1598 | if (maybe_ATTRS_REPORT | |
1599 | && ((!itemizing && verbose && match_level == 2) | |
2a787d74 | 1600 | @@ -707,13 +732,18 @@ static int try_dests_non(struct file_str |
0870c22a WD |
1601 | enum logcode code) |
1602 | { | |
1603 | char fnamebuf[MAXPATHLEN]; | |
1604 | - STRUCT_STAT st; | |
1605 | + statx sx; | |
1606 | int i = 0; | |
fa26e11c | 1607 | |
0870c22a WD |
1608 | do { |
1609 | pathjoin(fnamebuf, MAXPATHLEN, basis_dir[i], fname); | |
1610 | - if (link_stat(fnamebuf, &st, 0) < 0 || S_ISDIR(st.st_mode) | |
1611 | - || !unchanged_attrs(file, &st)) | |
1612 | + if (link_stat(fnamebuf, &sx.st, 0) < 0 || S_ISDIR(sx.st.st_mode)) | |
1613 | + continue; | |
e6a7303b | 1614 | +#ifdef SUPPORT_ACLS |
162234a7 | 1615 | + if (preserve_acls) |
98ccc74a | 1616 | + get_acl(fnamebuf, &sx); |
e6a7303b | 1617 | +#endif |
0870c22a WD |
1618 | + if (!unchanged_attrs(file, &sx)) |
1619 | continue; | |
1620 | if (S_ISLNK(file->mode)) { | |
1621 | #ifdef SUPPORT_LINKS | |
2a787d74 | 1622 | @@ -726,10 +756,10 @@ static int try_dests_non(struct file_str |
0870c22a WD |
1623 | #endif |
1624 | continue; | |
1625 | } else if (IS_SPECIAL(file->mode)) { | |
1626 | - if (!IS_SPECIAL(st.st_mode) || st.st_rdev != file->u.rdev) | |
1627 | + if (!IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev) | |
1628 | continue; | |
1629 | } else if (IS_DEVICE(file->mode)) { | |
1630 | - if (!IS_DEVICE(st.st_mode) || st.st_rdev != file->u.rdev) | |
1631 | + if (!IS_DEVICE(sx.st.st_mode) || sx.st.st_rdev != file->u.rdev) | |
1632 | continue; | |
1633 | } else { | |
1634 | rprintf(FERROR, | |
2a787d74 | 1635 | @@ -760,7 +790,15 @@ static int try_dests_non(struct file_str |
0870c22a WD |
1636 | int changes = compare_dest ? 0 : ITEM_LOCAL_CHANGE |
1637 | + (link_dest ? ITEM_XNAME_FOLLOWS : 0); | |
1638 | char *lp = link_dest ? "" : NULL; | |
1639 | - itemize(file, ndx, 0, &st, changes, 0, lp); | |
e6a7303b | 1640 | +#ifdef SUPPORT_ACLS |
0870c22a | 1641 | + if (preserve_acls) |
98ccc74a | 1642 | + get_acl(fname, &sx); |
e6a7303b | 1643 | +#endif |
0870c22a WD |
1644 | + itemize(file, ndx, 0, &sx, changes, 0, lp); |
1645 | +#ifdef SUPPORT_ACLS | |
1646 | + if (preserve_acls) | |
98ccc74a | 1647 | + free_acl(&sx); |
0870c22a WD |
1648 | +#endif |
1649 | } | |
1650 | if (verbose > 1 && maybe_ATTRS_REPORT) { | |
74eccbb1 | 1651 | rprintf(FCLIENT, "%s is uptodate\n", fname); |
2a787d74 | 1652 | @@ -772,6 +810,7 @@ static int try_dests_non(struct file_str |
26c810d8 WD |
1653 | } |
1654 | ||
1655 | static int phase = 0; | |
1656 | +static int dflt_perms; | |
1657 | ||
1658 | /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir, | |
1659 | * make sure it exists, and has the right permissions/timestamp info. For | |
2a787d74 | 1660 | @@ -793,7 +832,8 @@ static void recv_generator(char *fname, |
0870c22a WD |
1661 | static int need_fuzzy_dirlist = 0; |
1662 | struct file_struct *fuzzy_file = NULL; | |
1663 | int fd = -1, f_copy = -1; | |
1664 | - STRUCT_STAT st, real_st, partial_st; | |
1665 | + statx sx, real_sx; | |
1666 | + STRUCT_STAT partial_st; | |
1667 | struct file_struct *back_file = NULL; | |
1668 | int statret, real_ret, stat_errno; | |
1669 | char *fnamecmp, *partialptr, *backupptr = NULL; | |
2a787d74 | 1670 | @@ -849,6 +889,9 @@ static void recv_generator(char *fname, |
74eccbb1 WD |
1671 | } else if (!dry_run) |
1672 | return; | |
0870c22a WD |
1673 | } |
1674 | +#ifdef SUPPORT_ACLS | |
1675 | + sx.acc_acl = sx.def_acl = NULL; | |
1676 | +#endif | |
1677 | if (dry_run > 1) { | |
1678 | statret = -1; | |
1679 | stat_errno = ENOENT; | |
2a787d74 | 1680 | @@ -856,7 +899,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1681 | char *dn = file->dirname ? file->dirname : "."; |
1682 | if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) { | |
1683 | if (relative_paths && !implied_dirs | |
60a8bf36 WD |
1684 | - && do_stat(dn, &st) < 0 |
1685 | + && do_stat(dn, &sx.st) < 0 | |
0870c22a WD |
1686 | && create_directory_path(fname) < 0) { |
1687 | rsyserr(FERROR, errno, | |
1688 | "recv_generator: mkdir %s failed", | |
2a787d74 | 1689 | @@ -868,6 +911,10 @@ static void recv_generator(char *fname, |
01deb4dc WD |
1690 | } |
1691 | if (fuzzy_basis) | |
63673ef2 | 1692 | need_fuzzy_dirlist = 1; |
26c810d8 | 1693 | +#ifdef SUPPORT_ACLS |
01deb4dc WD |
1694 | + if (!preserve_perms) |
1695 | + dflt_perms = default_perms_for_dir(dn); | |
26c810d8 | 1696 | +#endif |
26c810d8 | 1697 | } |
01deb4dc | 1698 | parent_dirname = dn; |
26c810d8 | 1699 | |
2a787d74 | 1700 | @@ -876,7 +923,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1701 | need_fuzzy_dirlist = 0; |
1702 | } | |
1703 | ||
1704 | - statret = link_stat(fname, &st, | |
1705 | + statret = link_stat(fname, &sx.st, | |
1706 | keep_dirlinks && S_ISDIR(file->mode)); | |
1707 | stat_errno = errno; | |
1708 | } | |
2a787d74 | 1709 | @@ -894,8 +941,9 @@ static void recv_generator(char *fname, |
0870c22a | 1710 | * mode based on the local permissions and some heuristics. */ |
90fa6d68 WD |
1711 | if (!preserve_perms) { |
1712 | int exists = statret == 0 | |
0870c22a | 1713 | - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode); |
90fa6d68 | 1714 | - file->mode = dest_mode(file->mode, st.st_mode, exists); |
0870c22a WD |
1715 | + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode); |
1716 | + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, | |
26c810d8 | 1717 | + exists); |
90fa6d68 WD |
1718 | } |
1719 | ||
1720 | if (S_ISDIR(file->mode)) { | |
2a787d74 | 1721 | @@ -904,8 +952,8 @@ static void recv_generator(char *fname, |
0870c22a WD |
1722 | * file of that name and it is *not* a directory, then |
1723 | * we need to delete it. If it doesn't exist, then | |
1724 | * (perhaps recursively) create it. */ | |
1725 | - if (statret == 0 && !S_ISDIR(st.st_mode)) { | |
1726 | - if (delete_item(fname, st.st_mode, del_opts) < 0) | |
1727 | + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) { | |
1728 | + if (delete_item(fname, sx.st.st_mode, del_opts) < 0) | |
1729 | return; | |
1730 | statret = -1; | |
1731 | } | |
2a787d74 WD |
1732 | @@ -920,7 +968,11 @@ static void recv_generator(char *fname, |
1733 | sr = -1; | |
1734 | new_root_dir = 0; | |
1735 | } | |
1736 | - itemize(file, ndx, sr, &st, | |
0870c22a | 1737 | +#ifdef SUPPORT_ACLS |
2a787d74 | 1738 | + if (preserve_acls && sr == 0) |
98ccc74a | 1739 | + get_acl(fname, &sx); |
0870c22a | 1740 | +#endif |
2a787d74 WD |
1741 | + itemize(file, ndx, sr, &sx, |
1742 | sr ? ITEM_LOCAL_CHANGE : 0, 0, NULL); | |
0870c22a WD |
1743 | } |
1744 | if (statret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) { | |
2a787d74 | 1745 | @@ -940,19 +992,19 @@ static void recv_generator(char *fname, |
74eccbb1 | 1746 | return; |
0870c22a WD |
1747 | } |
1748 | } | |
1749 | - if (set_file_attrs(fname, file, statret ? NULL : &st, 0) | |
1750 | + if (set_file_attrs(fname, file, statret ? NULL : &sx, 0) | |
3758a5a5 | 1751 | && verbose && code != FNONE && f_out != -1) |
0870c22a WD |
1752 | rprintf(code, "%s/\n", fname); |
1753 | if (delete_during && f_out != -1 && !phase && dry_run < 2 | |
1754 | && (file->flags & FLAG_DEL_HERE)) | |
1755 | - delete_in_dir(the_file_list, fname, file, &st); | |
1756 | - return; | |
1757 | + delete_in_dir(the_file_list, fname, file, &sx.st); | |
1758 | + goto cleanup; | |
1759 | } | |
1760 | ||
1761 | if (preserve_hard_links && file->link_u.links | |
1762 | - && hard_link_check(file, ndx, fname, statret, &st, | |
1763 | + && hard_link_check(file, ndx, fname, statret, &sx, | |
1764 | itemizing, code, HL_CHECK_MASTER)) | |
1765 | - return; | |
1766 | + goto cleanup; | |
1767 | ||
1768 | if (preserve_links && S_ISLNK(file->mode)) { | |
1769 | #ifdef SUPPORT_LINKS | |
2a787d74 | 1770 | @@ -970,7 +1022,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1771 | char lnk[MAXPATHLEN]; |
1772 | int len; | |
1773 | ||
1774 | - if (!S_ISDIR(st.st_mode) | |
1775 | + if (!S_ISDIR(sx.st.st_mode) | |
1776 | && (len = readlink(fname, lnk, MAXPATHLEN-1)) > 0) { | |
1777 | lnk[len] = 0; | |
1778 | /* A link already pointing to the | |
2a787d74 | 1779 | @@ -978,10 +1030,10 @@ static void recv_generator(char *fname, |
0870c22a WD |
1780 | * required. */ |
1781 | if (strcmp(lnk, file->u.link) == 0) { | |
1782 | if (itemizing) { | |
1783 | - itemize(file, ndx, 0, &st, 0, | |
1784 | + itemize(file, ndx, 0, &sx, 0, | |
1785 | 0, NULL); | |
1786 | } | |
1787 | - set_file_attrs(fname, file, &st, | |
1788 | + set_file_attrs(fname, file, &sx, | |
1789 | maybe_ATTRS_REPORT); | |
1790 | if (preserve_hard_links | |
1791 | && file->link_u.links) { | |
2a787d74 | 1792 | @@ -996,9 +1048,9 @@ static void recv_generator(char *fname, |
0870c22a WD |
1793 | } |
1794 | /* Not the right symlink (or not a symlink), so | |
1795 | * delete it. */ | |
1796 | - if (delete_item(fname, st.st_mode, del_opts) < 0) | |
1797 | + if (delete_item(fname, sx.st.st_mode, del_opts) < 0) | |
1798 | return; | |
1799 | - if (!S_ISLNK(st.st_mode)) | |
1800 | + if (!S_ISLNK(sx.st.st_mode)) | |
1801 | statret = -1; | |
1802 | } else if (basis_dir[0] != NULL) { | |
1803 | if (try_dests_non(file, fname, ndx, itemizing, | |
3758a5a5 | 1804 | @@ -1015,7 +1067,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1805 | } |
1806 | } | |
1807 | if (preserve_hard_links && file->link_u.links | |
1808 | - && hard_link_check(file, ndx, fname, -1, &st, | |
1809 | + && hard_link_check(file, ndx, fname, -1, &sx, | |
1810 | itemizing, code, HL_SKIP)) | |
1811 | return; | |
1812 | if (do_symlink(file->u.link,fname) != 0) { | |
3758a5a5 | 1813 | @@ -1024,7 +1076,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1814 | } else { |
1815 | set_file_attrs(fname, file, NULL, 0); | |
1816 | if (itemizing) { | |
1817 | - itemize(file, ndx, statret, &st, | |
1818 | + itemize(file, ndx, statret, &sx, | |
1819 | ITEM_LOCAL_CHANGE, 0, NULL); | |
1820 | } | |
3758a5a5 | 1821 | if (code != FNONE && verbose) { |
85148847 | 1822 | @@ -1059,18 +1111,22 @@ static void recv_generator(char *fname, |
3758a5a5 | 1823 | code = FNONE; |
0870c22a WD |
1824 | } |
1825 | } | |
1826 | +#ifdef SUPPORT_ACLS | |
1827 | + if (preserve_acls && statret == 0) | |
98ccc74a | 1828 | + get_acl(fname, &sx); |
0870c22a WD |
1829 | +#endif |
1830 | if (statret != 0 | |
1831 | - || (st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS) | |
1832 | - || st.st_rdev != file->u.rdev) { | |
1833 | + || (sx.st.st_mode & ~CHMOD_BITS) != (file->mode & ~CHMOD_BITS) | |
1834 | + || sx.st.st_rdev != file->u.rdev) { | |
1835 | if (statret == 0 | |
1836 | - && delete_item(fname, st.st_mode, del_opts) < 0) | |
1837 | - return; | |
1838 | + && delete_item(fname, sx.st.st_mode, del_opts) < 0) | |
1839 | + goto cleanup; | |
1840 | if (preserve_hard_links && file->link_u.links | |
1841 | - && hard_link_check(file, ndx, fname, -1, &st, | |
1842 | + && hard_link_check(file, ndx, fname, -1, &sx, | |
1843 | itemizing, code, HL_SKIP)) | |
1844 | - return; | |
1845 | - if ((IS_DEVICE(file->mode) && !IS_DEVICE(st.st_mode)) | |
1846 | - || (IS_SPECIAL(file->mode) && !IS_SPECIAL(st.st_mode))) | |
1847 | + goto cleanup; | |
1848 | + if ((IS_DEVICE(file->mode) && !IS_DEVICE(sx.st.st_mode)) | |
1849 | + || (IS_SPECIAL(file->mode) && !IS_SPECIAL(sx.st.st_mode))) | |
1850 | statret = -1; | |
1851 | if (verbose > 2) { | |
1852 | rprintf(FINFO,"mknod(%s,0%o,0x%x)\n", | |
85148847 | 1853 | @@ -1083,7 +1139,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1854 | } else { |
1855 | set_file_attrs(fname, file, NULL, 0); | |
1856 | if (itemizing) { | |
1857 | - itemize(file, ndx, statret, &st, | |
1858 | + itemize(file, ndx, statret, &sx, | |
1859 | ITEM_LOCAL_CHANGE, 0, NULL); | |
1860 | } | |
3758a5a5 | 1861 | if (code != FNONE && verbose) |
85148847 | 1862 | @@ -1097,14 +1153,14 @@ static void recv_generator(char *fname, |
0870c22a WD |
1863 | } |
1864 | } else { | |
1865 | if (itemizing) | |
1866 | - itemize(file, ndx, statret, &st, 0, 0, NULL); | |
1867 | - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT); | |
1868 | + itemize(file, ndx, statret, &sx, 0, 0, NULL); | |
1869 | + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT); | |
1870 | if (preserve_hard_links && file->link_u.links) | |
1871 | hard_link_cluster(file, ndx, itemizing, code); | |
195ca26e WD |
1872 | if (remove_source_files == 1) |
1873 | goto return_with_success; | |
0870c22a WD |
1874 | } |
1875 | - return; | |
1876 | + goto cleanup; | |
1877 | } | |
1878 | ||
1879 | if (!S_ISREG(file->mode)) { | |
85148847 | 1880 | @@ -1138,7 +1194,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1881 | } |
1882 | ||
1883 | if (update_only && statret == 0 | |
1884 | - && cmp_time(st.st_mtime, file->modtime) > 0) { | |
1885 | + && cmp_time(sx.st.st_mtime, file->modtime) > 0) { | |
1886 | if (verbose > 1) | |
1887 | rprintf(FINFO, "%s is newer\n", fname); | |
1888 | return; | |
85148847 | 1889 | @@ -1147,20 +1203,20 @@ static void recv_generator(char *fname, |
0870c22a WD |
1890 | fnamecmp = fname; |
1891 | fnamecmp_type = FNAMECMP_FNAME; | |
1892 | ||
1893 | - if (statret == 0 && !S_ISREG(st.st_mode)) { | |
1894 | - if (delete_item(fname, st.st_mode, del_opts) != 0) | |
1895 | + if (statret == 0 && !S_ISREG(sx.st.st_mode)) { | |
1896 | + if (delete_item(fname, sx.st.st_mode, del_opts) != 0) | |
1897 | return; | |
1898 | statret = -1; | |
1899 | stat_errno = ENOENT; | |
1900 | } | |
1901 | ||
1902 | if (statret != 0 && basis_dir[0] != NULL) { | |
1903 | - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st, | |
1904 | + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx, | |
1905 | itemizing, maybe_ATTRS_REPORT, code); | |
195ca26e WD |
1906 | if (j == -2) { |
1907 | if (remove_source_files == 1) | |
1908 | goto return_with_success; | |
0870c22a WD |
1909 | - return; |
1910 | + goto cleanup; | |
195ca26e | 1911 | } |
1ed0b5c9 | 1912 | if (j >= 0) { |
0870c22a | 1913 | fnamecmp = fnamecmpbuf; |
85148847 | 1914 | @@ -1170,7 +1226,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1915 | } |
1916 | ||
1917 | real_ret = statret; | |
1918 | - real_st = st; | |
1919 | + real_sx = sx; | |
1920 | ||
1921 | if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL | |
1922 | && link_stat(partialptr, &partial_st, 0) == 0 | |
85148847 | 1923 | @@ -1189,7 +1245,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1924 | rprintf(FINFO, "fuzzy basis selected for %s: %s\n", |
1925 | fname, fnamecmpbuf); | |
1926 | } | |
1927 | - st.st_size = fuzzy_file->length; | |
1928 | + sx.st.st_size = fuzzy_file->length; | |
1929 | statret = 0; | |
1930 | fnamecmp = fnamecmpbuf; | |
1931 | fnamecmp_type = FNAMECMP_FUZZY; | |
85148847 | 1932 | @@ -1198,7 +1254,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
1933 | |
1934 | if (statret != 0) { | |
1935 | if (preserve_hard_links && file->link_u.links | |
1936 | - && hard_link_check(file, ndx, fname, statret, &st, | |
1937 | + && hard_link_check(file, ndx, fname, statret, &sx, | |
1938 | itemizing, code, HL_SKIP)) | |
1939 | return; | |
1940 | if (stat_errno == ENOENT) | |
85148847 | 1941 | @@ -1208,39 +1264,52 @@ static void recv_generator(char *fname, |
0870c22a WD |
1942 | return; |
1943 | } | |
1944 | ||
1945 | - if (append_mode && st.st_size > file->length) | |
1946 | + if (append_mode && sx.st.st_size > file->length) | |
1947 | return; | |
1948 | ||
1949 | if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) | |
1950 | ; | |
1951 | else if (fnamecmp_type == FNAMECMP_FUZZY) | |
1952 | ; | |
1953 | - else if (unchanged_file(fnamecmp, file, &st)) { | |
1954 | + else if (unchanged_file(fnamecmp, file, &sx.st)) { | |
1955 | if (partialptr) { | |
1956 | do_unlink(partialptr); | |
1957 | handle_partial_dir(partialptr, PDIR_DELETE); | |
1958 | } | |
1959 | if (itemizing) { | |
1960 | - itemize(file, ndx, real_ret, &real_st, | |
1961 | +#ifdef SUPPORT_ACLS | |
1962 | + if (preserve_acls && real_ret == 0) | |
668bbc0a | 1963 | + get_acl(fnamecmp, &real_sx); |
0870c22a WD |
1964 | +#endif |
1965 | + itemize(file, ndx, real_ret, &real_sx, | |
1966 | 0, 0, NULL); | |
1967 | +#ifdef SUPPORT_ACLS | |
1968 | + if (preserve_acls) { | |
1969 | + if (fnamecmp_type == FNAMECMP_FNAME) { | |
1970 | + sx.acc_acl = real_sx.acc_acl; | |
1971 | + sx.def_acl = real_sx.def_acl; | |
1972 | + } else | |
98ccc74a | 1973 | + free_acl(&real_sx); |
0870c22a WD |
1974 | + } |
1975 | +#endif | |
1976 | } | |
1977 | - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT); | |
1978 | + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT); | |
1979 | if (preserve_hard_links && file->link_u.links) | |
1980 | hard_link_cluster(file, ndx, itemizing, code); | |
195ca26e WD |
1981 | if (remove_source_files != 1) |
1982 | - return; | |
1983 | + goto cleanup; | |
1984 | return_with_success: | |
1985 | if (!dry_run) { | |
1986 | char numbuf[4]; | |
1987 | SIVAL(numbuf, 0, ndx); | |
1988 | send_msg(MSG_SUCCESS, numbuf, 4); | |
1989 | } | |
0870c22a WD |
1990 | - return; |
1991 | + goto cleanup; | |
1992 | } | |
1993 | ||
1994 | prepare_to_open: | |
1995 | if (partialptr) { | |
1996 | - st = partial_st; | |
1997 | + sx.st = partial_st; | |
1998 | fnamecmp = partialptr; | |
1999 | fnamecmp_type = FNAMECMP_PARTIAL_DIR; | |
2000 | statret = 0; | |
85148847 | 2001 | @@ -1264,17 +1333,21 @@ static void recv_generator(char *fname, |
0870c22a WD |
2002 | pretend_missing: |
2003 | /* pretend the file didn't exist */ | |
2004 | if (preserve_hard_links && file->link_u.links | |
2005 | - && hard_link_check(file, ndx, fname, statret, &st, | |
2006 | + && hard_link_check(file, ndx, fname, statret, &sx, | |
2007 | itemizing, code, HL_SKIP)) | |
2008 | - return; | |
2009 | + goto cleanup; | |
2010 | statret = real_ret = -1; | |
2011 | +#ifdef SUPPORT_ACLS | |
2012 | + if (preserve_acls && ACL_READY(sx)) | |
98ccc74a | 2013 | + free_acl(&sx); |
0870c22a WD |
2014 | +#endif |
2015 | goto notify_others; | |
2016 | } | |
2017 | ||
2018 | if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) { | |
2019 | if (!(backupptr = get_backup_name(fname))) { | |
2020 | close(fd); | |
2021 | - return; | |
2022 | + goto cleanup; | |
2023 | } | |
2024 | if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) { | |
2025 | close(fd); | |
85148847 | 2026 | @@ -1285,7 +1358,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
2027 | full_fname(backupptr)); |
2028 | free(back_file); | |
2029 | close(fd); | |
2030 | - return; | |
2031 | + goto cleanup; | |
2032 | } | |
2033 | if ((f_copy = do_open(backupptr, | |
2034 | O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) { | |
85148847 | 2035 | @@ -1293,14 +1366,14 @@ static void recv_generator(char *fname, |
0870c22a WD |
2036 | full_fname(backupptr)); |
2037 | free(back_file); | |
2038 | close(fd); | |
2039 | - return; | |
2040 | + goto cleanup; | |
2041 | } | |
2042 | fnamecmp_type = FNAMECMP_BACKUP; | |
2043 | } | |
2044 | ||
2045 | if (verbose > 3) { | |
2046 | rprintf(FINFO, "gen mapped %s of size %.0f\n", | |
2047 | - fnamecmp, (double)st.st_size); | |
2048 | + fnamecmp, (double)sx.st.st_size); | |
2049 | } | |
2050 | ||
2051 | if (verbose > 2) | |
85148847 | 2052 | @@ -1318,24 +1391,32 @@ static void recv_generator(char *fname, |
0870c22a WD |
2053 | iflags |= ITEM_BASIS_TYPE_FOLLOWS; |
2054 | if (fnamecmp_type == FNAMECMP_FUZZY) | |
2055 | iflags |= ITEM_XNAME_FOLLOWS; | |
2056 | - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type, | |
2057 | +#ifdef SUPPORT_ACLS | |
2058 | + if (preserve_acls && real_ret == 0) | |
b6c2bb12 | 2059 | + get_acl(fnamecmp, &real_sx); |
0870c22a WD |
2060 | +#endif |
2061 | + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type, | |
2062 | fuzzy_file ? fuzzy_file->basename : NULL); | |
2063 | +#ifdef SUPPORT_ACLS | |
2064 | + if (preserve_acls) | |
98ccc74a | 2065 | + free_acl(&real_sx); |
0870c22a WD |
2066 | +#endif |
2067 | } | |
2068 | ||
2069 | if (!do_xfers) { | |
2070 | if (preserve_hard_links && file->link_u.links) | |
2071 | hard_link_cluster(file, ndx, itemizing, code); | |
2072 | - return; | |
2073 | + goto cleanup; | |
2074 | } | |
2075 | if (read_batch) | |
2076 | - return; | |
2077 | + goto cleanup; | |
2078 | ||
2079 | if (statret != 0 || whole_file) { | |
2080 | write_sum_head(f_out, NULL); | |
2081 | - return; | |
2082 | + goto cleanup; | |
2083 | } | |
2084 | ||
2085 | - generate_and_send_sums(fd, st.st_size, f_out, f_copy); | |
2086 | + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy); | |
2087 | ||
2088 | if (f_copy >= 0) { | |
2089 | close(f_copy); | |
85148847 | 2090 | @@ -1348,6 +1429,13 @@ static void recv_generator(char *fname, |
0870c22a WD |
2091 | } |
2092 | ||
2093 | close(fd); | |
2094 | + | |
2095 | + cleanup: | |
2096 | +#ifdef SUPPORT_ACLS | |
2097 | + if (preserve_acls) | |
98ccc74a | 2098 | + free_acl(&sx); |
0870c22a WD |
2099 | +#endif |
2100 | + return; | |
2101 | } | |
2102 | ||
2103 | void generate_files(int f_out, struct file_list *flist, char *local_name) | |
85148847 | 2104 | @@ -1407,6 +1495,8 @@ void generate_files(int f_out, struct fi |
26c810d8 WD |
2105 | * notice that and let us know via the redo pipe (or its closing). */ |
2106 | ignore_timeout = 1; | |
2107 | ||
2108 | + dflt_perms = (ACCESSPERMS & ~orig_umask); | |
2109 | + | |
2110 | for (i = 0; i < flist->count; i++) { | |
2111 | struct file_struct *file = flist->files[i]; | |
2112 | ||
0870c22a WD |
2113 | --- old/hlink.c |
2114 | +++ new/hlink.c | |
195ca26e | 2115 | @@ -26,6 +26,7 @@ |
0870c22a | 2116 | extern int verbose; |
195ca26e | 2117 | extern int do_xfers; |
0870c22a WD |
2118 | extern int link_dest; |
2119 | +extern int preserve_acls; | |
2120 | extern int make_backups; | |
195ca26e | 2121 | extern int remove_source_files; |
a859733e | 2122 | extern int stdout_format_has_i; |
668bbc0a | 2123 | @@ -147,15 +148,19 @@ void init_hard_links(void) |
0870c22a WD |
2124 | |
2125 | #ifdef SUPPORT_HARD_LINKS | |
2126 | static int maybe_hard_link(struct file_struct *file, int ndx, | |
2127 | - char *fname, int statret, STRUCT_STAT *st, | |
2128 | + char *fname, int statret, statx *sxp, | |
2129 | char *toname, STRUCT_STAT *to_st, | |
2130 | int itemizing, enum logcode code) | |
2131 | { | |
2132 | if (statret == 0) { | |
2133 | - if (st->st_dev == to_st->st_dev | |
2134 | - && st->st_ino == to_st->st_ino) { | |
2135 | + if (sxp->st.st_dev == to_st->st_dev | |
2136 | + && sxp->st.st_ino == to_st->st_ino) { | |
2137 | if (itemizing) { | |
2138 | - itemize(file, ndx, statret, st, | |
2139 | +#ifdef SUPPORT_ACLS | |
2140 | + if (preserve_acls && !ACL_READY(*sxp)) | |
98ccc74a | 2141 | + get_acl(fname, sxp); |
0870c22a WD |
2142 | +#endif |
2143 | + itemize(file, ndx, statret, sxp, | |
2144 | ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, | |
2145 | 0, ""); | |
2146 | } | |
668bbc0a | 2147 | @@ -170,13 +175,13 @@ static int maybe_hard_link(struct file_s |
0870c22a WD |
2148 | return -1; |
2149 | } | |
2150 | } | |
2151 | - return hard_link_one(file, ndx, fname, statret, st, toname, | |
2152 | + return hard_link_one(file, ndx, fname, statret, sxp, toname, | |
2153 | 0, itemizing, code); | |
2154 | } | |
2155 | #endif | |
2156 | ||
2157 | int hard_link_check(struct file_struct *file, int ndx, char *fname, | |
2158 | - int statret, STRUCT_STAT *st, int itemizing, | |
2159 | + int statret, statx *sxp, int itemizing, | |
2160 | enum logcode code, int skip) | |
2161 | { | |
2162 | #ifdef SUPPORT_HARD_LINKS | |
668bbc0a | 2163 | @@ -217,7 +222,7 @@ int hard_link_check(struct file_struct * |
0870c22a WD |
2164 | || st2.st_ino != st3.st_ino) |
2165 | continue; | |
2166 | statret = 1; | |
2167 | - st = &st3; | |
2168 | + sxp->st = st3; | |
3758a5a5 WD |
2169 | if (verbose < 2 || !stdout_format_has_i) { |
2170 | itemizing = 0; | |
2171 | code = FNONE; | |
668bbc0a | 2172 | @@ -227,12 +232,16 @@ int hard_link_check(struct file_struct * |
0870c22a WD |
2173 | if (!unchanged_file(cmpbuf, file, &st3)) |
2174 | continue; | |
2175 | statret = 1; | |
2176 | - st = &st3; | |
2177 | - if (unchanged_attrs(file, &st3)) | |
2178 | + sxp->st = st3; | |
2179 | +#ifdef SUPPORT_ACLS | |
2180 | + if (preserve_acls) | |
98ccc74a | 2181 | + get_acl(cmpbuf, sxp); |
0870c22a WD |
2182 | +#endif |
2183 | + if (unchanged_attrs(file, sxp)) | |
2184 | break; | |
2185 | } while (basis_dir[++j] != NULL); | |
2186 | } | |
2187 | - maybe_hard_link(file, ndx, fname, statret, st, | |
2188 | + maybe_hard_link(file, ndx, fname, statret, sxp, | |
2189 | toname, &st2, itemizing, code); | |
195ca26e WD |
2190 | if (remove_source_files == 1 && do_xfers) { |
2191 | char numbuf[4]; | |
668bbc0a | 2192 | @@ -250,7 +259,7 @@ int hard_link_check(struct file_struct * |
0870c22a WD |
2193 | |
2194 | #ifdef SUPPORT_HARD_LINKS | |
2195 | int hard_link_one(struct file_struct *file, int ndx, char *fname, | |
2196 | - int statret, STRUCT_STAT *st, char *toname, int terse, | |
2197 | + int statret, statx *sxp, char *toname, int terse, | |
2198 | int itemizing, enum logcode code) | |
2199 | { | |
2200 | if (do_link(toname, fname)) { | |
668bbc0a | 2201 | @@ -266,7 +275,11 @@ int hard_link_one(struct file_struct *fi |
0870c22a WD |
2202 | } |
2203 | ||
2204 | if (itemizing) { | |
2205 | - itemize(file, ndx, statret, st, | |
2206 | +#ifdef SUPPORT_ACLS | |
2207 | + if (preserve_acls && statret == 0 && !ACL_READY(*sxp)) | |
98ccc74a | 2208 | + get_acl(fname, sxp); |
0870c22a WD |
2209 | +#endif |
2210 | + itemize(file, ndx, statret, sxp, | |
2211 | ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0, | |
2212 | terse ? "" : toname); | |
2213 | } | |
668bbc0a | 2214 | @@ -283,11 +296,12 @@ void hard_link_cluster(struct file_struc |
0870c22a WD |
2215 | #ifdef SUPPORT_HARD_LINKS |
2216 | char hlink1[MAXPATHLEN]; | |
2217 | char *hlink2; | |
2218 | - STRUCT_STAT st1, st2; | |
2219 | + statx sx; | |
2220 | + STRUCT_STAT st; | |
2221 | int statret, ndx = master; | |
2222 | ||
2223 | file->F_HLINDEX = FINISHED_LINK; | |
2224 | - if (link_stat(f_name(file, hlink1), &st1, 0) < 0) | |
2225 | + if (link_stat(f_name(file, hlink1), &st, 0) < 0) | |
2226 | return; | |
2227 | if (!(file->flags & FLAG_HLINK_TOL)) { | |
2228 | while (!(file->flags & FLAG_HLINK_EOL)) { | |
668bbc0a | 2229 | @@ -301,9 +315,13 @@ void hard_link_cluster(struct file_struc |
0870c22a WD |
2230 | if (file->F_HLINDEX != SKIPPED_LINK) |
2231 | continue; | |
2232 | hlink2 = f_name(file, NULL); | |
2233 | - statret = link_stat(hlink2, &st2, 0); | |
2234 | - maybe_hard_link(file, ndx, hlink2, statret, &st2, | |
2235 | - hlink1, &st1, itemizing, code); | |
2236 | + statret = link_stat(hlink2, &sx.st, 0); | |
2237 | + maybe_hard_link(file, ndx, hlink2, statret, &sx, | |
2238 | + hlink1, &st, itemizing, code); | |
2239 | +#ifdef SUPPORT_ACLS | |
2240 | + if (preserve_acls) | |
98ccc74a | 2241 | + free_acl(&sx); |
0870c22a | 2242 | +#endif |
195ca26e WD |
2243 | if (remove_source_files == 1 && do_xfers) { |
2244 | char numbuf[4]; | |
2245 | SIVAL(numbuf, 0, ndx); | |
9a7eef96 WD |
2246 | --- old/lib/sysacls.c |
2247 | +++ new/lib/sysacls.c | |
131abbd3 | 2248 | @@ -0,0 +1,3251 @@ |
0870c22a WD |
2249 | +/* |
2250 | + Unix SMB/CIFS implementation. | |
2251 | + Samba system utilities for ACL support. | |
2252 | + Copyright (C) Jeremy Allison 2000. | |
2253 | + | |
2254 | + This program is free software; you can redistribute it and/or modify | |
2255 | + it under the terms of the GNU General Public License as published by | |
2256 | + the Free Software Foundation; either version 2 of the License, or | |
2257 | + (at your option) any later version. | |
2258 | + | |
2259 | + This program is distributed in the hope that it will be useful, | |
2260 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2261 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2262 | + GNU General Public License for more details. | |
2263 | + | |
2264 | + You should have received a copy of the GNU General Public License | |
2265 | + along with this program; if not, write to the Free Software | |
2266 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
2267 | +*/ | |
fa26e11c | 2268 | + |
0f6733d8 | 2269 | +#include "rsync.h" |
252945ef | 2270 | +#include "sysacls.h" /****** ADDED ******/ |
fa26e11c | 2271 | + |
131abbd3 WD |
2272 | +#ifdef SUPPORT_ACLS |
2273 | + | |
252945ef | 2274 | +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/ |
f42b0645 WD |
2275 | +#ifdef DEBUG |
2276 | +#undef DEBUG | |
2277 | +#endif | |
2278 | +#define DEBUG(x,y) | |
2279 | + | |
0f6733d8 WD |
2280 | +void SAFE_FREE(void *mem) |
2281 | +{ | |
2282 | + if (mem) | |
2283 | + free(mem); | |
2284 | +} | |
fa26e11c | 2285 | + |
5ca9317d WD |
2286 | +char *uidtoname(uid_t uid) |
2287 | +{ | |
2288 | + static char idbuf[12]; | |
2289 | + struct passwd *pw; | |
2290 | + | |
2291 | + if ((pw = getpwuid(uid)) == NULL) { | |
2292 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid); | |
2293 | + return idbuf; | |
2294 | + } | |
2295 | + return pw->pw_name; | |
2296 | +} | |
252945ef | 2297 | +/****** EXTRAS -- END ******/ |
5ca9317d | 2298 | + |
0f6733d8 WD |
2299 | +/* |
2300 | + This file wraps all differing system ACL interfaces into a consistent | |
2301 | + one based on the POSIX interface. It also returns the correct errors | |
2302 | + for older UNIX systems that don't support ACLs. | |
fa26e11c | 2303 | + |
0f6733d8 | 2304 | + The interfaces that each ACL implementation must support are as follows : |
fa26e11c | 2305 | + |
0f6733d8 WD |
2306 | + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
2307 | + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) | |
2308 | + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p | |
2309 | + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) | |
2310 | + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) | |
2311 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
2312 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); | |
2313 | + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
2314 | + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) | |
2315 | + SMB_ACL_T sys_acl_init( int count) | |
2316 | + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) | |
2317 | + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) | |
2318 | + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) | |
2319 | + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) | |
2320 | + int sys_acl_valid( SMB_ACL_T theacl ) | |
2321 | + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
2322 | + int sys_acl_set_fd( int fd, SMB_ACL_T theacl) | |
2323 | + int sys_acl_delete_def_file(const char *path) | |
fa26e11c | 2324 | + |
0f6733d8 WD |
2325 | + This next one is not POSIX complient - but we *have* to have it ! |
2326 | + More POSIX braindamage. | |
fa26e11c | 2327 | + |
0f6733d8 | 2328 | + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 2329 | + |
0f6733d8 WD |
2330 | + The generic POSIX free is the following call. We split this into |
2331 | + several different free functions as we may need to add tag info | |
2332 | + to structures when emulating the POSIX interface. | |
fa26e11c | 2333 | + |
0f6733d8 | 2334 | + int sys_acl_free( void *obj_p) |
fa26e11c | 2335 | + |
0f6733d8 | 2336 | + The calls we actually use are : |
fa26e11c | 2337 | + |
0f6733d8 WD |
2338 | + int sys_acl_free_text(char *text) - free acl_to_text |
2339 | + int sys_acl_free_acl(SMB_ACL_T posix_acl) | |
2340 | + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype) | |
fa26e11c | 2341 | + |
0f6733d8 | 2342 | +*/ |
fa26e11c | 2343 | + |
0f6733d8 | 2344 | +#if defined(HAVE_POSIX_ACLS) |
fa26e11c | 2345 | + |
0f6733d8 | 2346 | +/* Identity mapping - easy. */ |
fa26e11c | 2347 | + |
0f6733d8 | 2348 | +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 2349 | +{ |
0f6733d8 | 2350 | + return acl_get_entry( the_acl, entry_id, entry_p); |
fa26e11c WD |
2351 | +} |
2352 | + | |
0f6733d8 | 2353 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c | 2354 | +{ |
0f6733d8 | 2355 | + return acl_get_tag_type( entry_d, tag_type_p); |
fa26e11c WD |
2356 | +} |
2357 | + | |
0f6733d8 | 2358 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c | 2359 | +{ |
0f6733d8 | 2360 | + return acl_get_permset( entry_d, permset_p); |
fa26e11c WD |
2361 | +} |
2362 | + | |
0f6733d8 | 2363 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 2364 | +{ |
0f6733d8 | 2365 | + return acl_get_qualifier( entry_d); |
fa26e11c WD |
2366 | +} |
2367 | + | |
0f6733d8 | 2368 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 2369 | +{ |
0f6733d8 | 2370 | + return acl_get_file( path_p, type); |
fa26e11c WD |
2371 | +} |
2372 | + | |
2373 | +SMB_ACL_T sys_acl_get_fd(int fd) | |
2374 | +{ | |
2375 | + return acl_get_fd(fd); | |
2376 | +} | |
2377 | + | |
2378 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) | |
2379 | +{ | |
2380 | + return acl_clear_perms(permset); | |
2381 | +} | |
2382 | + | |
0f6733d8 | 2383 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2384 | +{ |
2385 | + return acl_add_perm(permset, perm); | |
2386 | +} | |
2387 | + | |
0f6733d8 | 2388 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2389 | +{ |
2390 | +#if defined(HAVE_ACL_GET_PERM_NP) | |
0f6733d8 WD |
2391 | + /* |
2392 | + * Required for TrustedBSD-based ACL implementations where | |
fa26e11c | 2393 | + * non-POSIX.1e functions are denoted by a _np (non-portable) |
0f6733d8 WD |
2394 | + * suffix. |
2395 | + */ | |
fa26e11c WD |
2396 | + return acl_get_perm_np(permset, perm); |
2397 | +#else | |
2398 | + return acl_get_perm(permset, perm); | |
2399 | +#endif | |
2400 | +} | |
2401 | + | |
0f6733d8 | 2402 | +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) |
fa26e11c | 2403 | +{ |
0f6733d8 | 2404 | + return acl_to_text( the_acl, plen); |
fa26e11c WD |
2405 | +} |
2406 | + | |
0f6733d8 | 2407 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
2408 | +{ |
2409 | + return acl_init(count); | |
2410 | +} | |
2411 | + | |
0f6733d8 | 2412 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
2413 | +{ |
2414 | + return acl_create_entry(pacl, pentry); | |
2415 | +} | |
2416 | + | |
0f6733d8 | 2417 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
2418 | +{ |
2419 | + return acl_set_tag_type(entry, tagtype); | |
2420 | +} | |
2421 | + | |
0f6733d8 | 2422 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
2423 | +{ |
2424 | + return acl_set_qualifier(entry, qual); | |
2425 | +} | |
2426 | + | |
0f6733d8 | 2427 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
2428 | +{ |
2429 | + return acl_set_permset(entry, permset); | |
2430 | +} | |
2431 | + | |
0f6733d8 | 2432 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c WD |
2433 | +{ |
2434 | + return acl_valid(theacl); | |
2435 | +} | |
2436 | + | |
2437 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
2438 | +{ | |
2439 | + return acl_set_file(name, acltype, theacl); | |
2440 | +} | |
2441 | + | |
0f6733d8 | 2442 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
2443 | +{ |
2444 | + return acl_set_fd(fd, theacl); | |
2445 | +} | |
2446 | + | |
2447 | +int sys_acl_delete_def_file(const char *name) | |
2448 | +{ | |
2449 | + return acl_delete_def_file(name); | |
2450 | +} | |
2451 | + | |
2452 | +int sys_acl_free_text(char *text) | |
2453 | +{ | |
2454 | + return acl_free(text); | |
2455 | +} | |
2456 | + | |
0f6733d8 | 2457 | +int sys_acl_free_acl(SMB_ACL_T the_acl) |
fa26e11c WD |
2458 | +{ |
2459 | + return acl_free(the_acl); | |
2460 | +} | |
2461 | + | |
1f839b40 | 2462 | +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
2463 | +{ |
2464 | + return acl_free(qual); | |
2465 | +} | |
2466 | + | |
2467 | +#elif defined(HAVE_TRU64_ACLS) | |
0f6733d8 WD |
2468 | +/* |
2469 | + * The interface to DEC/Compaq Tru64 UNIX ACLs | |
fa26e11c WD |
2470 | + * is based on Draft 13 of the POSIX spec which is |
2471 | + * slightly different from the Draft 16 interface. | |
0f6733d8 | 2472 | + * |
fa26e11c WD |
2473 | + * Also, some of the permset manipulation functions |
2474 | + * such as acl_clear_perm() and acl_add_perm() appear | |
2475 | + * to be broken on Tru64 so we have to manipulate | |
0f6733d8 WD |
2476 | + * the permission bits in the permset directly. |
2477 | + */ | |
2478 | +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
fa26e11c | 2479 | +{ |
0f6733d8 | 2480 | + SMB_ACL_ENTRY_T entry; |
fa26e11c WD |
2481 | + |
2482 | + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) { | |
2483 | + return -1; | |
2484 | + } | |
2485 | + | |
2486 | + errno = 0; | |
2487 | + if ((entry = acl_get_entry(the_acl)) != NULL) { | |
2488 | + *entry_p = entry; | |
2489 | + return 1; | |
2490 | + } | |
2491 | + | |
2492 | + return errno ? -1 : 0; | |
2493 | +} | |
2494 | + | |
0f6733d8 | 2495 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c | 2496 | +{ |
0f6733d8 | 2497 | + return acl_get_tag_type( entry_d, tag_type_p); |
fa26e11c WD |
2498 | +} |
2499 | + | |
0f6733d8 | 2500 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c | 2501 | +{ |
0f6733d8 | 2502 | + return acl_get_permset( entry_d, permset_p); |
fa26e11c WD |
2503 | +} |
2504 | + | |
0f6733d8 | 2505 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 2506 | +{ |
0f6733d8 | 2507 | + return acl_get_qualifier( entry_d); |
fa26e11c WD |
2508 | +} |
2509 | + | |
0f6733d8 | 2510 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c WD |
2511 | +{ |
2512 | + return acl_get_file((char *)path_p, type); | |
2513 | +} | |
2514 | + | |
0f6733d8 | 2515 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c WD |
2516 | +{ |
2517 | + return acl_get_fd(fd, ACL_TYPE_ACCESS); | |
2518 | +} | |
2519 | + | |
0f6733d8 | 2520 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
fa26e11c | 2521 | +{ |
0f6733d8 | 2522 | + *permset = 0; /* acl_clear_perm() is broken on Tru64 */ |
fa26e11c WD |
2523 | + |
2524 | + return 0; | |
2525 | +} | |
2526 | + | |
0f6733d8 | 2527 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2528 | +{ |
2529 | + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) { | |
2530 | + errno = EINVAL; | |
2531 | + return -1; | |
2532 | + } | |
2533 | + | |
0f6733d8 | 2534 | + *permset |= perm; /* acl_add_perm() is broken on Tru64 */ |
fa26e11c WD |
2535 | + |
2536 | + return 0; | |
2537 | +} | |
2538 | + | |
0f6733d8 | 2539 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2540 | +{ |
2541 | + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */ | |
2542 | +} | |
2543 | + | |
0f6733d8 | 2544 | +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) |
fa26e11c | 2545 | +{ |
0f6733d8 | 2546 | + return acl_to_text( the_acl, plen); |
fa26e11c WD |
2547 | +} |
2548 | + | |
0f6733d8 | 2549 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
2550 | +{ |
2551 | + return acl_init(count); | |
2552 | +} | |
2553 | + | |
0f6733d8 | 2554 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
2555 | +{ |
2556 | + SMB_ACL_ENTRY_T entry; | |
2557 | + | |
2558 | + if ((entry = acl_create_entry(pacl)) == NULL) { | |
2559 | + return -1; | |
2560 | + } | |
2561 | + | |
2562 | + *pentry = entry; | |
2563 | + return 0; | |
2564 | +} | |
2565 | + | |
0f6733d8 | 2566 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
2567 | +{ |
2568 | + return acl_set_tag_type(entry, tagtype); | |
2569 | +} | |
2570 | + | |
0f6733d8 | 2571 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
2572 | +{ |
2573 | + return acl_set_qualifier(entry, qual); | |
2574 | +} | |
2575 | + | |
0f6733d8 | 2576 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
2577 | +{ |
2578 | + return acl_set_permset(entry, permset); | |
2579 | +} | |
2580 | + | |
0f6733d8 | 2581 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c | 2582 | +{ |
0f6733d8 | 2583 | + acl_entry_t entry; |
fa26e11c WD |
2584 | + |
2585 | + return acl_valid(theacl, &entry); | |
2586 | +} | |
2587 | + | |
0f6733d8 | 2588 | +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
fa26e11c WD |
2589 | +{ |
2590 | + return acl_set_file((char *)name, acltype, theacl); | |
2591 | +} | |
2592 | + | |
0f6733d8 | 2593 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
2594 | +{ |
2595 | + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl); | |
2596 | +} | |
2597 | + | |
0f6733d8 | 2598 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
2599 | +{ |
2600 | + return acl_delete_def_file((char *)name); | |
2601 | +} | |
2602 | + | |
0f6733d8 | 2603 | +int sys_acl_free_text(char *text) |
fa26e11c | 2604 | +{ |
0f6733d8 WD |
2605 | + /* |
2606 | + * (void) cast and explicit return 0 are for DEC UNIX | |
2607 | + * which just #defines acl_free_text() to be free() | |
2608 | + */ | |
fa26e11c WD |
2609 | + (void) acl_free_text(text); |
2610 | + return 0; | |
2611 | +} | |
2612 | + | |
0f6733d8 | 2613 | +int sys_acl_free_acl(SMB_ACL_T the_acl) |
fa26e11c WD |
2614 | +{ |
2615 | + return acl_free(the_acl); | |
2616 | +} | |
2617 | + | |
0f6733d8 | 2618 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
2619 | +{ |
2620 | + return acl_free_qualifier(qual, tagtype); | |
2621 | +} | |
2622 | + | |
2623 | +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) | |
2624 | + | |
0f6733d8 WD |
2625 | +/* |
2626 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
2627 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. | |
2628 | + */ | |
fa26e11c | 2629 | + |
0f6733d8 WD |
2630 | +/* |
2631 | + * Note that while this code implements sufficient functionality | |
fa26e11c WD |
2632 | + * to support the sys_acl_* interfaces it does not provide all |
2633 | + * of the semantics of the POSIX ACL interfaces. | |
2634 | + * | |
2635 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned | |
2636 | + * from a call to sys_acl_get_entry() should not be assumed to be | |
2637 | + * valid after calling any of the following functions, which may | |
2638 | + * reorder the entries in the ACL. | |
2639 | + * | |
2640 | + * sys_acl_valid() | |
2641 | + * sys_acl_set_file() | |
2642 | + * sys_acl_set_fd() | |
2643 | + */ | |
2644 | + | |
0f6733d8 WD |
2645 | +/* |
2646 | + * The only difference between Solaris and UnixWare / OpenUNIX is | |
2647 | + * that the #defines for the ACL operations have different names | |
2648 | + */ | |
fa26e11c WD |
2649 | +#if defined(HAVE_UNIXWARE_ACLS) |
2650 | + | |
0f6733d8 WD |
2651 | +#define SETACL ACL_SET |
2652 | +#define GETACL ACL_GET | |
2653 | +#define GETACLCNT ACL_CNT | |
fa26e11c WD |
2654 | + |
2655 | +#endif | |
2656 | + | |
2657 | + | |
0f6733d8 | 2658 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
2659 | +{ |
2660 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
2661 | + errno = EINVAL; | |
2662 | + return -1; | |
2663 | + } | |
2664 | + | |
2665 | + if (entry_p == NULL) { | |
2666 | + errno = EINVAL; | |
2667 | + return -1; | |
2668 | + } | |
2669 | + | |
2670 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
2671 | + acl_d->next = 0; | |
2672 | + } | |
2673 | + | |
2674 | + if (acl_d->next < 0) { | |
2675 | + errno = EINVAL; | |
2676 | + return -1; | |
2677 | + } | |
2678 | + | |
2679 | + if (acl_d->next >= acl_d->count) { | |
2680 | + return 0; | |
2681 | + } | |
2682 | + | |
2683 | + *entry_p = &acl_d->acl[acl_d->next++]; | |
2684 | + | |
2685 | + return 1; | |
2686 | +} | |
2687 | + | |
0f6733d8 | 2688 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
2689 | +{ |
2690 | + *type_p = entry_d->a_type; | |
2691 | + | |
2692 | + return 0; | |
2693 | +} | |
2694 | + | |
0f6733d8 | 2695 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
2696 | +{ |
2697 | + *permset_p = &entry_d->a_perm; | |
2698 | + | |
2699 | + return 0; | |
2700 | +} | |
2701 | + | |
0f6733d8 | 2702 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
2703 | +{ |
2704 | + if (entry_d->a_type != SMB_ACL_USER | |
2705 | + && entry_d->a_type != SMB_ACL_GROUP) { | |
2706 | + errno = EINVAL; | |
2707 | + return NULL; | |
2708 | + } | |
2709 | + | |
2710 | + return &entry_d->a_id; | |
2711 | +} | |
2712 | + | |
0f6733d8 WD |
2713 | +/* |
2714 | + * There is no way of knowing what size the ACL returned by | |
fa26e11c WD |
2715 | + * GETACL will be unless you first call GETACLCNT which means |
2716 | + * making an additional system call. | |
2717 | + * | |
2718 | + * In the hope of avoiding the cost of the additional system | |
2719 | + * call in most cases, we initially allocate enough space for | |
2720 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to | |
2721 | + * be too small then we use GETACLCNT to find out the actual | |
0f6733d8 WD |
2722 | + * size, reallocate the ACL buffer, and then call GETACL again. |
2723 | + */ | |
fa26e11c | 2724 | + |
0f6733d8 | 2725 | +#define INITIAL_ACL_SIZE 16 |
fa26e11c | 2726 | + |
0f6733d8 | 2727 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 2728 | +{ |
0f6733d8 WD |
2729 | + SMB_ACL_T acl_d; |
2730 | + int count; /* # of ACL entries allocated */ | |
2731 | + int naccess; /* # of access ACL entries */ | |
2732 | + int ndefault; /* # of default ACL entries */ | |
fa26e11c WD |
2733 | + |
2734 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
2735 | + errno = EINVAL; | |
2736 | + return NULL; | |
2737 | + } | |
2738 | + | |
2739 | + count = INITIAL_ACL_SIZE; | |
2740 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2741 | + return NULL; | |
2742 | + } | |
2743 | + | |
0f6733d8 WD |
2744 | + /* |
2745 | + * If there isn't enough space for the ACL entries we use | |
fa26e11c WD |
2746 | + * GETACLCNT to determine the actual number of ACL entries |
2747 | + * reallocate and try again. This is in a loop because it | |
2748 | + * is possible that someone else could modify the ACL and | |
2749 | + * increase the number of entries between the call to | |
0f6733d8 WD |
2750 | + * GETACLCNT and the call to GETACL. |
2751 | + */ | |
fa26e11c WD |
2752 | + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0 |
2753 | + && errno == ENOSPC) { | |
2754 | + | |
2755 | + sys_acl_free_acl(acl_d); | |
2756 | + | |
2757 | + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) { | |
2758 | + return NULL; | |
2759 | + } | |
2760 | + | |
2761 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2762 | + return NULL; | |
2763 | + } | |
2764 | + } | |
2765 | + | |
2766 | + if (count < 0) { | |
2767 | + sys_acl_free_acl(acl_d); | |
2768 | + return NULL; | |
2769 | + } | |
2770 | + | |
0f6733d8 WD |
2771 | + /* |
2772 | + * calculate the number of access and default ACL entries | |
fa26e11c WD |
2773 | + * |
2774 | + * Note: we assume that the acl() system call returned a | |
2775 | + * well formed ACL which is sorted so that all of the | |
0f6733d8 WD |
2776 | + * access ACL entries preceed any default ACL entries |
2777 | + */ | |
fa26e11c WD |
2778 | + for (naccess = 0; naccess < count; naccess++) { |
2779 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2780 | + break; | |
2781 | + } | |
2782 | + ndefault = count - naccess; | |
0f6733d8 WD |
2783 | + |
2784 | + /* | |
2785 | + * if the caller wants the default ACL we have to copy | |
fa26e11c | 2786 | + * the entries down to the start of the acl[] buffer |
0f6733d8 WD |
2787 | + * and mask out the ACL_DEFAULT flag from the type field |
2788 | + */ | |
fa26e11c | 2789 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
0f6733d8 | 2790 | + int i, j; |
fa26e11c WD |
2791 | + |
2792 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { | |
2793 | + acl_d->acl[i] = acl_d->acl[j]; | |
2794 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; | |
2795 | + } | |
2796 | + | |
2797 | + acl_d->count = ndefault; | |
2798 | + } else { | |
2799 | + acl_d->count = naccess; | |
2800 | + } | |
2801 | + | |
2802 | + return acl_d; | |
2803 | +} | |
2804 | + | |
0f6733d8 | 2805 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 2806 | +{ |
0f6733d8 WD |
2807 | + SMB_ACL_T acl_d; |
2808 | + int count; /* # of ACL entries allocated */ | |
2809 | + int naccess; /* # of access ACL entries */ | |
fa26e11c WD |
2810 | + |
2811 | + count = INITIAL_ACL_SIZE; | |
2812 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2813 | + return NULL; | |
2814 | + } | |
2815 | + | |
2816 | + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0 | |
2817 | + && errno == ENOSPC) { | |
2818 | + | |
2819 | + sys_acl_free_acl(acl_d); | |
2820 | + | |
2821 | + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) { | |
2822 | + return NULL; | |
2823 | + } | |
2824 | + | |
2825 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2826 | + return NULL; | |
2827 | + } | |
2828 | + } | |
2829 | + | |
2830 | + if (count < 0) { | |
2831 | + sys_acl_free_acl(acl_d); | |
2832 | + return NULL; | |
2833 | + } | |
2834 | + | |
0f6733d8 WD |
2835 | + /* |
2836 | + * calculate the number of access ACL entries | |
2837 | + */ | |
fa26e11c WD |
2838 | + for (naccess = 0; naccess < count; naccess++) { |
2839 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2840 | + break; | |
2841 | + } | |
0f6733d8 | 2842 | + |
fa26e11c WD |
2843 | + acl_d->count = naccess; |
2844 | + | |
2845 | + return acl_d; | |
2846 | +} | |
2847 | + | |
0f6733d8 | 2848 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
2849 | +{ |
2850 | + *permset_d = 0; | |
2851 | + | |
2852 | + return 0; | |
2853 | +} | |
2854 | + | |
0f6733d8 | 2855 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2856 | +{ |
2857 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
2858 | + && perm != SMB_ACL_EXECUTE) { | |
2859 | + errno = EINVAL; | |
2860 | + return -1; | |
2861 | + } | |
2862 | + | |
2863 | + if (permset_d == NULL) { | |
2864 | + errno = EINVAL; | |
2865 | + return -1; | |
2866 | + } | |
2867 | + | |
2868 | + *permset_d |= perm; | |
2869 | + | |
2870 | + return 0; | |
2871 | +} | |
2872 | + | |
0f6733d8 | 2873 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2874 | +{ |
2875 | + return *permset_d & perm; | |
2876 | +} | |
2877 | + | |
0f6733d8 | 2878 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c | 2879 | +{ |
0f6733d8 WD |
2880 | + int i; |
2881 | + int len, maxlen; | |
2882 | + char *text; | |
fa26e11c | 2883 | + |
0f6733d8 WD |
2884 | + /* |
2885 | + * use an initial estimate of 20 bytes per ACL entry | |
fa26e11c | 2886 | + * when allocating memory for the text representation |
0f6733d8 WD |
2887 | + * of the ACL |
2888 | + */ | |
2889 | + len = 0; | |
2890 | + maxlen = 20 * acl_d->count; | |
252945ef | 2891 | + if ((text = SMB_MALLOC(maxlen)) == NULL) { |
fa26e11c WD |
2892 | + errno = ENOMEM; |
2893 | + return NULL; | |
2894 | + } | |
2895 | + | |
2896 | + for (i = 0; i < acl_d->count; i++) { | |
0f6733d8 | 2897 | + struct acl *ap = &acl_d->acl[i]; |
0f6733d8 WD |
2898 | + struct group *gr; |
2899 | + char tagbuf[12]; | |
2900 | + char idbuf[12]; | |
2901 | + char *tag; | |
2902 | + char *id = ""; | |
2903 | + char perms[4]; | |
2904 | + int nbytes; | |
fa26e11c WD |
2905 | + |
2906 | + switch (ap->a_type) { | |
0f6733d8 WD |
2907 | + /* |
2908 | + * for debugging purposes it's probably more | |
fa26e11c | 2909 | + * useful to dump unknown tag types rather |
0f6733d8 WD |
2910 | + * than just returning an error |
2911 | + */ | |
fa26e11c | 2912 | + default: |
0f6733d8 | 2913 | + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x", |
fa26e11c WD |
2914 | + ap->a_type); |
2915 | + tag = tagbuf; | |
0f6733d8 | 2916 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
2917 | + (long)ap->a_id); |
2918 | + id = idbuf; | |
2919 | + break; | |
2920 | + | |
2921 | + case SMB_ACL_USER: | |
5ca9317d | 2922 | + id = uidtoname(ap->a_id); |
fa26e11c WD |
2923 | + case SMB_ACL_USER_OBJ: |
2924 | + tag = "user"; | |
2925 | + break; | |
2926 | + | |
2927 | + case SMB_ACL_GROUP: | |
2928 | + if ((gr = getgrgid(ap->a_id)) == NULL) { | |
0f6733d8 | 2929 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
2930 | + (long)ap->a_id); |
2931 | + id = idbuf; | |
2932 | + } else { | |
2933 | + id = gr->gr_name; | |
2934 | + } | |
2935 | + case SMB_ACL_GROUP_OBJ: | |
2936 | + tag = "group"; | |
2937 | + break; | |
2938 | + | |
2939 | + case SMB_ACL_OTHER: | |
2940 | + tag = "other"; | |
2941 | + break; | |
2942 | + | |
2943 | + case SMB_ACL_MASK: | |
2944 | + tag = "mask"; | |
2945 | + break; | |
2946 | + | |
2947 | + } | |
2948 | + | |
2949 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; | |
2950 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; | |
2951 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; | |
2952 | + perms[3] = '\0'; | |
2953 | + | |
2954 | + /* <tag> : <qualifier> : rwx \n \0 */ | |
2955 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; | |
2956 | + | |
0f6733d8 WD |
2957 | + /* |
2958 | + * If this entry would overflow the buffer | |
fa26e11c WD |
2959 | + * allocate enough additional memory for this |
2960 | + * entry and an estimate of another 20 bytes | |
0f6733d8 WD |
2961 | + * for each entry still to be processed |
2962 | + */ | |
fa26e11c WD |
2963 | + if ((len + nbytes) > maxlen) { |
2964 | + char *oldtext = text; | |
2965 | + | |
2966 | + maxlen += nbytes + 20 * (acl_d->count - i); | |
2967 | + | |
252945ef | 2968 | + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) { |
0f6733d8 | 2969 | + SAFE_FREE(oldtext); |
fa26e11c WD |
2970 | + errno = ENOMEM; |
2971 | + return NULL; | |
2972 | + } | |
2973 | + } | |
2974 | + | |
0f6733d8 | 2975 | + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); |
fa26e11c WD |
2976 | + len += nbytes - 1; |
2977 | + } | |
2978 | + | |
2979 | + if (len_p) | |
2980 | + *len_p = len; | |
2981 | + | |
2982 | + return text; | |
2983 | +} | |
2984 | + | |
0f6733d8 | 2985 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 2986 | +{ |
0f6733d8 | 2987 | + SMB_ACL_T a; |
fa26e11c WD |
2988 | + |
2989 | + if (count < 0) { | |
2990 | + errno = EINVAL; | |
2991 | + return NULL; | |
2992 | + } | |
2993 | + | |
0f6733d8 WD |
2994 | + /* |
2995 | + * note that since the definition of the structure pointed | |
fa26e11c WD |
2996 | + * to by the SMB_ACL_T includes the first element of the |
2997 | + * acl[] array, this actually allocates an ACL with room | |
0f6733d8 WD |
2998 | + * for (count+1) entries |
2999 | + */ | |
53c1073a | 3000 | + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) { |
fa26e11c WD |
3001 | + errno = ENOMEM; |
3002 | + return NULL; | |
3003 | + } | |
3004 | + | |
3005 | + a->size = count + 1; | |
3006 | + a->count = 0; | |
3007 | + a->next = -1; | |
3008 | + | |
3009 | + return a; | |
3010 | +} | |
3011 | + | |
3012 | + | |
0f6733d8 | 3013 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 3014 | +{ |
0f6733d8 WD |
3015 | + SMB_ACL_T acl_d; |
3016 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
3017 | + |
3018 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
3019 | + errno = EINVAL; | |
3020 | + return -1; | |
3021 | + } | |
3022 | + | |
3023 | + if (acl_d->count >= acl_d->size) { | |
3024 | + errno = ENOSPC; | |
3025 | + return -1; | |
3026 | + } | |
3027 | + | |
0f6733d8 WD |
3028 | + entry_d = &acl_d->acl[acl_d->count++]; |
3029 | + entry_d->a_type = 0; | |
3030 | + entry_d->a_id = -1; | |
3031 | + entry_d->a_perm = 0; | |
3032 | + *entry_p = entry_d; | |
fa26e11c WD |
3033 | + |
3034 | + return 0; | |
3035 | +} | |
3036 | + | |
0f6733d8 | 3037 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
3038 | +{ |
3039 | + switch (tag_type) { | |
3040 | + case SMB_ACL_USER: | |
3041 | + case SMB_ACL_USER_OBJ: | |
3042 | + case SMB_ACL_GROUP: | |
3043 | + case SMB_ACL_GROUP_OBJ: | |
3044 | + case SMB_ACL_OTHER: | |
3045 | + case SMB_ACL_MASK: | |
3046 | + entry_d->a_type = tag_type; | |
3047 | + break; | |
3048 | + default: | |
3049 | + errno = EINVAL; | |
3050 | + return -1; | |
3051 | + } | |
3052 | + | |
3053 | + return 0; | |
3054 | +} | |
3055 | + | |
0f6733d8 | 3056 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
3057 | +{ |
3058 | + if (entry_d->a_type != SMB_ACL_GROUP | |
3059 | + && entry_d->a_type != SMB_ACL_USER) { | |
3060 | + errno = EINVAL; | |
3061 | + return -1; | |
3062 | + } | |
3063 | + | |
3064 | + entry_d->a_id = *((id_t *)qual_p); | |
3065 | + | |
3066 | + return 0; | |
3067 | +} | |
3068 | + | |
0f6733d8 | 3069 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3070 | +{ |
3071 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
3072 | + return EINVAL; | |
3073 | + } | |
3074 | + | |
3075 | + entry_d->a_perm = *permset_d; | |
3076 | + | |
3077 | + return 0; | |
3078 | +} | |
3079 | + | |
0f6733d8 WD |
3080 | +/* |
3081 | + * sort the ACL and check it for validity | |
fa26e11c | 3082 | + * |
0f6733d8 | 3083 | + * if it's a minimal ACL with only 4 entries then we |
fa26e11c WD |
3084 | + * need to recalculate the mask permissions to make |
3085 | + * sure that they are the same as the GROUP_OBJ | |
3086 | + * permissions as required by the UnixWare acl() system call. | |
3087 | + * | |
0f6733d8 | 3088 | + * (note: since POSIX allows minimal ACLs which only contain |
fa26e11c WD |
3089 | + * 3 entries - ie there is no mask entry - we should, in theory, |
3090 | + * check for this and add a mask entry if necessary - however | |
3091 | + * we "know" that the caller of this interface always specifies | |
3092 | + * a mask so, in practice "this never happens" (tm) - if it *does* | |
3093 | + * happen aclsort() will fail and return an error and someone will | |
0f6733d8 WD |
3094 | + * have to fix it ...) |
3095 | + */ | |
fa26e11c WD |
3096 | + |
3097 | +static int acl_sort(SMB_ACL_T acl_d) | |
3098 | +{ | |
3099 | + int fixmask = (acl_d->count <= 4); | |
3100 | + | |
3101 | + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) { | |
3102 | + errno = EINVAL; | |
3103 | + return -1; | |
3104 | + } | |
3105 | + return 0; | |
3106 | +} | |
0f6733d8 WD |
3107 | + |
3108 | +int sys_acl_valid(SMB_ACL_T acl_d) | |
fa26e11c WD |
3109 | +{ |
3110 | + return acl_sort(acl_d); | |
3111 | +} | |
3112 | + | |
0f6733d8 | 3113 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c | 3114 | +{ |
0f6733d8 WD |
3115 | + struct stat s; |
3116 | + struct acl *acl_p; | |
3117 | + int acl_count; | |
3118 | + struct acl *acl_buf = NULL; | |
3119 | + int ret; | |
fa26e11c WD |
3120 | + |
3121 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
3122 | + errno = EINVAL; | |
3123 | + return -1; | |
3124 | + } | |
3125 | + | |
3126 | + if (acl_sort(acl_d) != 0) { | |
3127 | + return -1; | |
3128 | + } | |
3129 | + | |
0f6733d8 WD |
3130 | + acl_p = &acl_d->acl[0]; |
3131 | + acl_count = acl_d->count; | |
fa26e11c | 3132 | + |
0f6733d8 WD |
3133 | + /* |
3134 | + * if it's a directory there is extra work to do | |
3135 | + * since the acl() system call will replace both | |
3136 | + * the access ACLs and the default ACLs (if any) | |
3137 | + */ | |
fa26e11c WD |
3138 | + if (stat(name, &s) != 0) { |
3139 | + return -1; | |
3140 | + } | |
3141 | + if (S_ISDIR(s.st_mode)) { | |
0f6733d8 WD |
3142 | + SMB_ACL_T acc_acl; |
3143 | + SMB_ACL_T def_acl; | |
3144 | + SMB_ACL_T tmp_acl; | |
3145 | + int i; | |
fa26e11c WD |
3146 | + |
3147 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
3148 | + acc_acl = acl_d; | |
3149 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); | |
3150 | + | |
3151 | + } else { | |
3152 | + def_acl = acl_d; | |
3153 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); | |
3154 | + } | |
3155 | + | |
3156 | + if (tmp_acl == NULL) { | |
3157 | + return -1; | |
3158 | + } | |
3159 | + | |
0f6733d8 WD |
3160 | + /* |
3161 | + * allocate a temporary buffer for the complete ACL | |
3162 | + */ | |
fa26e11c | 3163 | + acl_count = acc_acl->count + def_acl->count; |
252945ef | 3164 | + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
fa26e11c WD |
3165 | + |
3166 | + if (acl_buf == NULL) { | |
3167 | + sys_acl_free_acl(tmp_acl); | |
3168 | + errno = ENOMEM; | |
3169 | + return -1; | |
3170 | + } | |
3171 | + | |
0f6733d8 WD |
3172 | + /* |
3173 | + * copy the access control and default entries into the buffer | |
3174 | + */ | |
fa26e11c | 3175 | + memcpy(&acl_buf[0], &acc_acl->acl[0], |
0f6733d8 | 3176 | + acc_acl->count * sizeof(acl_buf[0])); |
fa26e11c WD |
3177 | + |
3178 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], | |
0f6733d8 | 3179 | + def_acl->count * sizeof(acl_buf[0])); |
fa26e11c | 3180 | + |
0f6733d8 WD |
3181 | + /* |
3182 | + * set the ACL_DEFAULT flag on the default entries | |
3183 | + */ | |
fa26e11c WD |
3184 | + for (i = acc_acl->count; i < acl_count; i++) { |
3185 | + acl_buf[i].a_type |= ACL_DEFAULT; | |
3186 | + } | |
3187 | + | |
3188 | + sys_acl_free_acl(tmp_acl); | |
3189 | + | |
3190 | + } else if (type != SMB_ACL_TYPE_ACCESS) { | |
3191 | + errno = EINVAL; | |
3192 | + return -1; | |
3193 | + } | |
3194 | + | |
3195 | + ret = acl(name, SETACL, acl_count, acl_p); | |
3196 | + | |
0f6733d8 | 3197 | + SAFE_FREE(acl_buf); |
fa26e11c WD |
3198 | + |
3199 | + return ret; | |
3200 | +} | |
3201 | + | |
0f6733d8 | 3202 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c WD |
3203 | +{ |
3204 | + if (acl_sort(acl_d) != 0) { | |
3205 | + return -1; | |
3206 | + } | |
3207 | + | |
3208 | + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]); | |
3209 | +} | |
3210 | + | |
0f6733d8 | 3211 | +int sys_acl_delete_def_file(const char *path) |
fa26e11c | 3212 | +{ |
0f6733d8 WD |
3213 | + SMB_ACL_T acl_d; |
3214 | + int ret; | |
fa26e11c | 3215 | + |
0f6733d8 WD |
3216 | + /* |
3217 | + * fetching the access ACL and rewriting it has | |
3218 | + * the effect of deleting the default ACL | |
3219 | + */ | |
fa26e11c WD |
3220 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
3221 | + return -1; | |
3222 | + } | |
3223 | + | |
3224 | + ret = acl(path, SETACL, acl_d->count, acl_d->acl); | |
3225 | + | |
3226 | + sys_acl_free_acl(acl_d); | |
0f6733d8 | 3227 | + |
fa26e11c WD |
3228 | + return ret; |
3229 | +} | |
3230 | + | |
0f6733d8 | 3231 | +int sys_acl_free_text(char *text) |
fa26e11c | 3232 | +{ |
0f6733d8 | 3233 | + SAFE_FREE(text); |
fa26e11c WD |
3234 | + return 0; |
3235 | +} | |
3236 | + | |
0f6733d8 | 3237 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c | 3238 | +{ |
0f6733d8 | 3239 | + SAFE_FREE(acl_d); |
fa26e11c WD |
3240 | + return 0; |
3241 | +} | |
3242 | + | |
53c1073a | 3243 | +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
3244 | +{ |
3245 | + return 0; | |
3246 | +} | |
3247 | + | |
3248 | +#elif defined(HAVE_HPUX_ACLS) | |
3249 | +#include <dl.h> | |
3250 | + | |
0f6733d8 WD |
3251 | +/* |
3252 | + * Based on the Solaris/SCO code - with modifications. | |
3253 | + */ | |
fa26e11c | 3254 | + |
0f6733d8 WD |
3255 | +/* |
3256 | + * Note that while this code implements sufficient functionality | |
fa26e11c WD |
3257 | + * to support the sys_acl_* interfaces it does not provide all |
3258 | + * of the semantics of the POSIX ACL interfaces. | |
3259 | + * | |
3260 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned | |
3261 | + * from a call to sys_acl_get_entry() should not be assumed to be | |
3262 | + * valid after calling any of the following functions, which may | |
3263 | + * reorder the entries in the ACL. | |
3264 | + * | |
3265 | + * sys_acl_valid() | |
3266 | + * sys_acl_set_file() | |
3267 | + * sys_acl_set_fd() | |
3268 | + */ | |
3269 | + | |
0f6733d8 WD |
3270 | +/* This checks if the POSIX ACL system call is defined */ |
3271 | +/* which basically corresponds to whether JFS 3.3 or */ | |
3272 | +/* higher is installed. If acl() was called when it */ | |
3273 | +/* isn't defined, it causes the process to core dump */ | |
3274 | +/* so it is important to check this and avoid acl() */ | |
3275 | +/* calls if it isn't there. */ | |
fa26e11c WD |
3276 | + |
3277 | +static BOOL hpux_acl_call_presence(void) | |
3278 | +{ | |
3279 | + | |
3280 | + shl_t handle = NULL; | |
3281 | + void *value; | |
3282 | + int ret_val=0; | |
3283 | + static BOOL already_checked=0; | |
3284 | + | |
0f6733d8 | 3285 | + if(already_checked) |
fa26e11c WD |
3286 | + return True; |
3287 | + | |
3288 | + | |
3289 | + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value); | |
3290 | + | |
0f6733d8 | 3291 | + if(ret_val != 0) { |
fa26e11c WD |
3292 | + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n", |
3293 | + ret_val, errno, strerror(errno))); | |
3294 | + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n")); | |
3295 | + return False; | |
3296 | + } | |
3297 | + | |
3298 | + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n")); | |
3299 | + | |
3300 | + already_checked = True; | |
3301 | + return True; | |
3302 | +} | |
3303 | + | |
0f6733d8 | 3304 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
3305 | +{ |
3306 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
3307 | + errno = EINVAL; | |
3308 | + return -1; | |
3309 | + } | |
3310 | + | |
3311 | + if (entry_p == NULL) { | |
3312 | + errno = EINVAL; | |
3313 | + return -1; | |
3314 | + } | |
3315 | + | |
3316 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
3317 | + acl_d->next = 0; | |
3318 | + } | |
3319 | + | |
3320 | + if (acl_d->next < 0) { | |
3321 | + errno = EINVAL; | |
3322 | + return -1; | |
3323 | + } | |
3324 | + | |
3325 | + if (acl_d->next >= acl_d->count) { | |
3326 | + return 0; | |
3327 | + } | |
3328 | + | |
3329 | + *entry_p = &acl_d->acl[acl_d->next++]; | |
3330 | + | |
3331 | + return 1; | |
3332 | +} | |
3333 | + | |
0f6733d8 | 3334 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
3335 | +{ |
3336 | + *type_p = entry_d->a_type; | |
3337 | + | |
3338 | + return 0; | |
3339 | +} | |
3340 | + | |
0f6733d8 | 3341 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
3342 | +{ |
3343 | + *permset_p = &entry_d->a_perm; | |
3344 | + | |
3345 | + return 0; | |
3346 | +} | |
3347 | + | |
0f6733d8 | 3348 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
3349 | +{ |
3350 | + if (entry_d->a_type != SMB_ACL_USER | |
3351 | + && entry_d->a_type != SMB_ACL_GROUP) { | |
3352 | + errno = EINVAL; | |
3353 | + return NULL; | |
3354 | + } | |
3355 | + | |
3356 | + return &entry_d->a_id; | |
3357 | +} | |
3358 | + | |
0f6733d8 WD |
3359 | +/* |
3360 | + * There is no way of knowing what size the ACL returned by | |
fa26e11c WD |
3361 | + * ACL_GET will be unless you first call ACL_CNT which means |
3362 | + * making an additional system call. | |
3363 | + * | |
3364 | + * In the hope of avoiding the cost of the additional system | |
3365 | + * call in most cases, we initially allocate enough space for | |
3366 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to | |
3367 | + * be too small then we use ACL_CNT to find out the actual | |
3368 | + * size, reallocate the ACL buffer, and then call ACL_GET again. | |
3369 | + */ | |
3370 | + | |
0f6733d8 | 3371 | +#define INITIAL_ACL_SIZE 16 |
fa26e11c | 3372 | + |
0f6733d8 | 3373 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 3374 | +{ |
0f6733d8 WD |
3375 | + SMB_ACL_T acl_d; |
3376 | + int count; /* # of ACL entries allocated */ | |
3377 | + int naccess; /* # of access ACL entries */ | |
3378 | + int ndefault; /* # of default ACL entries */ | |
fa26e11c | 3379 | + |
0f6733d8 WD |
3380 | + if(hpux_acl_call_presence() == False) { |
3381 | + /* Looks like we don't have the acl() system call on HPUX. | |
3382 | + * May be the system doesn't have the latest version of JFS. | |
3383 | + */ | |
3384 | + return NULL; | |
fa26e11c WD |
3385 | + } |
3386 | + | |
3387 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
3388 | + errno = EINVAL; | |
3389 | + return NULL; | |
3390 | + } | |
3391 | + | |
3392 | + count = INITIAL_ACL_SIZE; | |
3393 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
3394 | + return NULL; | |
3395 | + } | |
3396 | + | |
0f6733d8 WD |
3397 | + /* |
3398 | + * If there isn't enough space for the ACL entries we use | |
fa26e11c WD |
3399 | + * ACL_CNT to determine the actual number of ACL entries |
3400 | + * reallocate and try again. This is in a loop because it | |
3401 | + * is possible that someone else could modify the ACL and | |
3402 | + * increase the number of entries between the call to | |
0f6733d8 WD |
3403 | + * ACL_CNT and the call to ACL_GET. |
3404 | + */ | |
fa26e11c WD |
3405 | + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) { |
3406 | + | |
3407 | + sys_acl_free_acl(acl_d); | |
3408 | + | |
3409 | + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) { | |
3410 | + return NULL; | |
3411 | + } | |
3412 | + | |
3413 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
3414 | + return NULL; | |
3415 | + } | |
3416 | + } | |
3417 | + | |
3418 | + if (count < 0) { | |
3419 | + sys_acl_free_acl(acl_d); | |
3420 | + return NULL; | |
3421 | + } | |
3422 | + | |
0f6733d8 WD |
3423 | + /* |
3424 | + * calculate the number of access and default ACL entries | |
fa26e11c WD |
3425 | + * |
3426 | + * Note: we assume that the acl() system call returned a | |
3427 | + * well formed ACL which is sorted so that all of the | |
0f6733d8 WD |
3428 | + * access ACL entries preceed any default ACL entries |
3429 | + */ | |
fa26e11c WD |
3430 | + for (naccess = 0; naccess < count; naccess++) { |
3431 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
3432 | + break; | |
3433 | + } | |
3434 | + ndefault = count - naccess; | |
0f6733d8 WD |
3435 | + |
3436 | + /* | |
3437 | + * if the caller wants the default ACL we have to copy | |
fa26e11c | 3438 | + * the entries down to the start of the acl[] buffer |
0f6733d8 WD |
3439 | + * and mask out the ACL_DEFAULT flag from the type field |
3440 | + */ | |
fa26e11c | 3441 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
0f6733d8 | 3442 | + int i, j; |
fa26e11c WD |
3443 | + |
3444 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { | |
3445 | + acl_d->acl[i] = acl_d->acl[j]; | |
3446 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; | |
3447 | + } | |
3448 | + | |
3449 | + acl_d->count = ndefault; | |
3450 | + } else { | |
3451 | + acl_d->count = naccess; | |
3452 | + } | |
3453 | + | |
3454 | + return acl_d; | |
3455 | +} | |
3456 | + | |
0f6733d8 | 3457 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 3458 | +{ |
0f6733d8 WD |
3459 | + /* |
3460 | + * HPUX doesn't have the facl call. Fake it using the path.... JRA. | |
3461 | + */ | |
fa26e11c WD |
3462 | + |
3463 | + files_struct *fsp = file_find_fd(fd); | |
3464 | + | |
3465 | + if (fsp == NULL) { | |
3466 | + errno = EBADF; | |
3467 | + return NULL; | |
3468 | + } | |
3469 | + | |
0f6733d8 WD |
3470 | + /* |
3471 | + * We know we're in the same conn context. So we | |
3472 | + * can use the relative path. | |
3473 | + */ | |
fa26e11c | 3474 | + |
5ca9317d | 3475 | + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS); |
fa26e11c WD |
3476 | +} |
3477 | + | |
0f6733d8 | 3478 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3479 | +{ |
3480 | + *permset_d = 0; | |
3481 | + | |
3482 | + return 0; | |
3483 | +} | |
3484 | + | |
0f6733d8 | 3485 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
3486 | +{ |
3487 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
3488 | + && perm != SMB_ACL_EXECUTE) { | |
3489 | + errno = EINVAL; | |
3490 | + return -1; | |
3491 | + } | |
3492 | + | |
3493 | + if (permset_d == NULL) { | |
3494 | + errno = EINVAL; | |
3495 | + return -1; | |
3496 | + } | |
3497 | + | |
3498 | + *permset_d |= perm; | |
3499 | + | |
3500 | + return 0; | |
3501 | +} | |
3502 | + | |
0f6733d8 | 3503 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
3504 | +{ |
3505 | + return *permset_d & perm; | |
3506 | +} | |
3507 | + | |
0f6733d8 | 3508 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c | 3509 | +{ |
0f6733d8 WD |
3510 | + int i; |
3511 | + int len, maxlen; | |
3512 | + char *text; | |
fa26e11c | 3513 | + |
0f6733d8 WD |
3514 | + /* |
3515 | + * use an initial estimate of 20 bytes per ACL entry | |
3516 | + * when allocating memory for the text representation | |
3517 | + * of the ACL | |
3518 | + */ | |
3519 | + len = 0; | |
3520 | + maxlen = 20 * acl_d->count; | |
252945ef | 3521 | + if ((text = SMB_MALLOC(maxlen)) == NULL) { |
fa26e11c WD |
3522 | + errno = ENOMEM; |
3523 | + return NULL; | |
3524 | + } | |
3525 | + | |
3526 | + for (i = 0; i < acl_d->count; i++) { | |
0f6733d8 | 3527 | + struct acl *ap = &acl_d->acl[i]; |
0f6733d8 WD |
3528 | + struct group *gr; |
3529 | + char tagbuf[12]; | |
3530 | + char idbuf[12]; | |
3531 | + char *tag; | |
3532 | + char *id = ""; | |
3533 | + char perms[4]; | |
3534 | + int nbytes; | |
fa26e11c WD |
3535 | + |
3536 | + switch (ap->a_type) { | |
0f6733d8 WD |
3537 | + /* |
3538 | + * for debugging purposes it's probably more | |
fa26e11c | 3539 | + * useful to dump unknown tag types rather |
0f6733d8 WD |
3540 | + * than just returning an error |
3541 | + */ | |
fa26e11c | 3542 | + default: |
0f6733d8 | 3543 | + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x", |
fa26e11c WD |
3544 | + ap->a_type); |
3545 | + tag = tagbuf; | |
0f6733d8 | 3546 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
3547 | + (long)ap->a_id); |
3548 | + id = idbuf; | |
3549 | + break; | |
3550 | + | |
3551 | + case SMB_ACL_USER: | |
5ca9317d | 3552 | + id = uidtoname(ap->a_id); |
fa26e11c WD |
3553 | + case SMB_ACL_USER_OBJ: |
3554 | + tag = "user"; | |
3555 | + break; | |
3556 | + | |
3557 | + case SMB_ACL_GROUP: | |
3558 | + if ((gr = getgrgid(ap->a_id)) == NULL) { | |
0f6733d8 | 3559 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
3560 | + (long)ap->a_id); |
3561 | + id = idbuf; | |
3562 | + } else { | |
3563 | + id = gr->gr_name; | |
3564 | + } | |
3565 | + case SMB_ACL_GROUP_OBJ: | |
3566 | + tag = "group"; | |
3567 | + break; | |
3568 | + | |
3569 | + case SMB_ACL_OTHER: | |
3570 | + tag = "other"; | |
3571 | + break; | |
3572 | + | |
3573 | + case SMB_ACL_MASK: | |
3574 | + tag = "mask"; | |
3575 | + break; | |
3576 | + | |
3577 | + } | |
3578 | + | |
3579 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; | |
3580 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; | |
3581 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; | |
3582 | + perms[3] = '\0'; | |
3583 | + | |
3584 | + /* <tag> : <qualifier> : rwx \n \0 */ | |
3585 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; | |
3586 | + | |
0f6733d8 WD |
3587 | + /* |
3588 | + * If this entry would overflow the buffer | |
fa26e11c WD |
3589 | + * allocate enough additional memory for this |
3590 | + * entry and an estimate of another 20 bytes | |
0f6733d8 WD |
3591 | + * for each entry still to be processed |
3592 | + */ | |
fa26e11c WD |
3593 | + if ((len + nbytes) > maxlen) { |
3594 | + char *oldtext = text; | |
3595 | + | |
3596 | + maxlen += nbytes + 20 * (acl_d->count - i); | |
3597 | + | |
252945ef | 3598 | + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) { |
fa26e11c WD |
3599 | + free(oldtext); |
3600 | + errno = ENOMEM; | |
3601 | + return NULL; | |
3602 | + } | |
3603 | + } | |
3604 | + | |
0f6733d8 | 3605 | + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); |
fa26e11c WD |
3606 | + len += nbytes - 1; |
3607 | + } | |
3608 | + | |
3609 | + if (len_p) | |
3610 | + *len_p = len; | |
3611 | + | |
3612 | + return text; | |
3613 | +} | |
3614 | + | |
0f6733d8 | 3615 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 3616 | +{ |
0f6733d8 | 3617 | + SMB_ACL_T a; |
fa26e11c WD |
3618 | + |
3619 | + if (count < 0) { | |
3620 | + errno = EINVAL; | |
3621 | + return NULL; | |
3622 | + } | |
3623 | + | |
0f6733d8 WD |
3624 | + /* |
3625 | + * note that since the definition of the structure pointed | |
fa26e11c WD |
3626 | + * to by the SMB_ACL_T includes the first element of the |
3627 | + * acl[] array, this actually allocates an ACL with room | |
0f6733d8 WD |
3628 | + * for (count+1) entries |
3629 | + */ | |
252945ef | 3630 | + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) { |
fa26e11c WD |
3631 | + errno = ENOMEM; |
3632 | + return NULL; | |
3633 | + } | |
3634 | + | |
3635 | + a->size = count + 1; | |
3636 | + a->count = 0; | |
3637 | + a->next = -1; | |
3638 | + | |
3639 | + return a; | |
3640 | +} | |
3641 | + | |
3642 | + | |
0f6733d8 | 3643 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 3644 | +{ |
0f6733d8 WD |
3645 | + SMB_ACL_T acl_d; |
3646 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
3647 | + |
3648 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
3649 | + errno = EINVAL; | |
3650 | + return -1; | |
3651 | + } | |
3652 | + | |
3653 | + if (acl_d->count >= acl_d->size) { | |
3654 | + errno = ENOSPC; | |
3655 | + return -1; | |
3656 | + } | |
3657 | + | |
0f6733d8 WD |
3658 | + entry_d = &acl_d->acl[acl_d->count++]; |
3659 | + entry_d->a_type = 0; | |
3660 | + entry_d->a_id = -1; | |
3661 | + entry_d->a_perm = 0; | |
3662 | + *entry_p = entry_d; | |
fa26e11c WD |
3663 | + |
3664 | + return 0; | |
3665 | +} | |
3666 | + | |
0f6733d8 | 3667 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
3668 | +{ |
3669 | + switch (tag_type) { | |
3670 | + case SMB_ACL_USER: | |
3671 | + case SMB_ACL_USER_OBJ: | |
3672 | + case SMB_ACL_GROUP: | |
3673 | + case SMB_ACL_GROUP_OBJ: | |
3674 | + case SMB_ACL_OTHER: | |
3675 | + case SMB_ACL_MASK: | |
3676 | + entry_d->a_type = tag_type; | |
3677 | + break; | |
3678 | + default: | |
3679 | + errno = EINVAL; | |
3680 | + return -1; | |
3681 | + } | |
3682 | + | |
3683 | + return 0; | |
3684 | +} | |
3685 | + | |
0f6733d8 | 3686 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
3687 | +{ |
3688 | + if (entry_d->a_type != SMB_ACL_GROUP | |
3689 | + && entry_d->a_type != SMB_ACL_USER) { | |
3690 | + errno = EINVAL; | |
3691 | + return -1; | |
3692 | + } | |
3693 | + | |
3694 | + entry_d->a_id = *((id_t *)qual_p); | |
3695 | + | |
3696 | + return 0; | |
3697 | +} | |
3698 | + | |
0f6733d8 | 3699 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3700 | +{ |
3701 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
3702 | + return EINVAL; | |
3703 | + } | |
3704 | + | |
3705 | + entry_d->a_perm = *permset_d; | |
3706 | + | |
3707 | + return 0; | |
3708 | +} | |
3709 | + | |
3710 | +/* Structure to capture the count for each type of ACE. */ | |
3711 | + | |
3712 | +struct hpux_acl_types { | |
3713 | + int n_user; | |
3714 | + int n_def_user; | |
3715 | + int n_user_obj; | |
3716 | + int n_def_user_obj; | |
3717 | + | |
3718 | + int n_group; | |
3719 | + int n_def_group; | |
3720 | + int n_group_obj; | |
3721 | + int n_def_group_obj; | |
3722 | + | |
3723 | + int n_other; | |
3724 | + int n_other_obj; | |
3725 | + int n_def_other_obj; | |
3726 | + | |
3727 | + int n_class_obj; | |
3728 | + int n_def_class_obj; | |
3729 | + | |
3730 | + int n_illegal_obj; | |
3731 | +}; | |
3732 | + | |
3733 | +/* count_obj: | |
3734 | + * Counts the different number of objects in a given array of ACL | |
3735 | + * structures. | |
3736 | + * Inputs: | |
3737 | + * | |
3738 | + * acl_count - Count of ACLs in the array of ACL strucutres. | |
3739 | + * aclp - Array of ACL structures. | |
3740 | + * acl_type_count - Pointer to acl_types structure. Should already be | |
3741 | + * allocated. | |
0f6733d8 | 3742 | + * Output: |
fa26e11c | 3743 | + * |
0f6733d8 | 3744 | + * acl_type_count - This structure is filled up with counts of various |
fa26e11c WD |
3745 | + * acl types. |
3746 | + */ | |
3747 | + | |
3748 | +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count) | |
3749 | +{ | |
3750 | + int i; | |
3751 | + | |
0f6733d8 | 3752 | + memset(acl_type_count, 0, sizeof(struct hpux_acl_types)); |
fa26e11c | 3753 | + |
0f6733d8 WD |
3754 | + for(i=0;i<acl_count;i++) { |
3755 | + switch(aclp[i].a_type) { | |
3756 | + case USER: | |
fa26e11c WD |
3757 | + acl_type_count->n_user++; |
3758 | + break; | |
0f6733d8 | 3759 | + case USER_OBJ: |
fa26e11c WD |
3760 | + acl_type_count->n_user_obj++; |
3761 | + break; | |
0f6733d8 | 3762 | + case DEF_USER_OBJ: |
fa26e11c WD |
3763 | + acl_type_count->n_def_user_obj++; |
3764 | + break; | |
0f6733d8 | 3765 | + case GROUP: |
fa26e11c WD |
3766 | + acl_type_count->n_group++; |
3767 | + break; | |
0f6733d8 | 3768 | + case GROUP_OBJ: |
fa26e11c WD |
3769 | + acl_type_count->n_group_obj++; |
3770 | + break; | |
0f6733d8 | 3771 | + case DEF_GROUP_OBJ: |
fa26e11c WD |
3772 | + acl_type_count->n_def_group_obj++; |
3773 | + break; | |
0f6733d8 | 3774 | + case OTHER_OBJ: |
fa26e11c WD |
3775 | + acl_type_count->n_other_obj++; |
3776 | + break; | |
0f6733d8 | 3777 | + case DEF_OTHER_OBJ: |
fa26e11c WD |
3778 | + acl_type_count->n_def_other_obj++; |
3779 | + break; | |
3780 | + case CLASS_OBJ: | |
3781 | + acl_type_count->n_class_obj++; | |
3782 | + break; | |
3783 | + case DEF_CLASS_OBJ: | |
3784 | + acl_type_count->n_def_class_obj++; | |
3785 | + break; | |
3786 | + case DEF_USER: | |
3787 | + acl_type_count->n_def_user++; | |
3788 | + break; | |
3789 | + case DEF_GROUP: | |
3790 | + acl_type_count->n_def_group++; | |
3791 | + break; | |
0f6733d8 | 3792 | + default: |
fa26e11c WD |
3793 | + acl_type_count->n_illegal_obj++; |
3794 | + break; | |
3795 | + } | |
3796 | + } | |
3797 | +} | |
3798 | + | |
0f6733d8 | 3799 | +/* swap_acl_entries: Swaps two ACL entries. |
fa26e11c WD |
3800 | + * |
3801 | + * Inputs: aclp0, aclp1 - ACL entries to be swapped. | |
3802 | + */ | |
3803 | + | |
3804 | +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1) | |
3805 | +{ | |
3806 | + struct acl temp_acl; | |
3807 | + | |
3808 | + temp_acl.a_type = aclp0->a_type; | |
3809 | + temp_acl.a_id = aclp0->a_id; | |
3810 | + temp_acl.a_perm = aclp0->a_perm; | |
3811 | + | |
3812 | + aclp0->a_type = aclp1->a_type; | |
3813 | + aclp0->a_id = aclp1->a_id; | |
3814 | + aclp0->a_perm = aclp1->a_perm; | |
3815 | + | |
3816 | + aclp1->a_type = temp_acl.a_type; | |
3817 | + aclp1->a_id = temp_acl.a_id; | |
3818 | + aclp1->a_perm = temp_acl.a_perm; | |
3819 | +} | |
3820 | + | |
3821 | +/* prohibited_duplicate_type | |
0f6733d8 | 3822 | + * Identifies if given ACL type can have duplicate entries or |
fa26e11c WD |
3823 | + * not. |
3824 | + * | |
3825 | + * Inputs: acl_type - ACL Type. | |
3826 | + * | |
0f6733d8 | 3827 | + * Outputs: |
fa26e11c | 3828 | + * |
0f6733d8 | 3829 | + * Return.. |
fa26e11c WD |
3830 | + * |
3831 | + * True - If the ACL type matches any of the prohibited types. | |
3832 | + * False - If the ACL type doesn't match any of the prohibited types. | |
0f6733d8 | 3833 | + */ |
fa26e11c WD |
3834 | + |
3835 | +static BOOL hpux_prohibited_duplicate_type(int acl_type) | |
3836 | +{ | |
0f6733d8 | 3837 | + switch(acl_type) { |
fa26e11c WD |
3838 | + case USER: |
3839 | + case GROUP: | |
0f6733d8 | 3840 | + case DEF_USER: |
fa26e11c WD |
3841 | + case DEF_GROUP: |
3842 | + return True; | |
0f6733d8 WD |
3843 | + default: |
3844 | + return False; | |
fa26e11c | 3845 | + } |
fa26e11c WD |
3846 | +} |
3847 | + | |
3848 | +/* get_needed_class_perm | |
3849 | + * Returns the permissions of a ACL structure only if the ACL | |
0f6733d8 | 3850 | + * type matches one of the pre-determined types for computing |
fa26e11c WD |
3851 | + * CLASS_OBJ permissions. |
3852 | + * | |
3853 | + * Inputs: aclp - Pointer to ACL structure. | |
3854 | + */ | |
3855 | + | |
3856 | +static int hpux_get_needed_class_perm(struct acl *aclp) | |
3857 | +{ | |
0f6733d8 WD |
3858 | + switch(aclp->a_type) { |
3859 | + case USER: | |
3860 | + case GROUP_OBJ: | |
3861 | + case GROUP: | |
3862 | + case DEF_USER_OBJ: | |
fa26e11c | 3863 | + case DEF_USER: |
0f6733d8 | 3864 | + case DEF_GROUP_OBJ: |
fa26e11c WD |
3865 | + case DEF_GROUP: |
3866 | + case DEF_CLASS_OBJ: | |
0f6733d8 | 3867 | + case DEF_OTHER_OBJ: |
fa26e11c | 3868 | + return aclp->a_perm; |
0f6733d8 | 3869 | + default: |
fa26e11c WD |
3870 | + return 0; |
3871 | + } | |
3872 | +} | |
3873 | + | |
3874 | +/* acl_sort for HPUX. | |
3875 | + * Sorts the array of ACL structures as per the description in | |
3876 | + * aclsort man page. Refer to aclsort man page for more details | |
3877 | + * | |
3878 | + * Inputs: | |
3879 | + * | |
3880 | + * acl_count - Count of ACLs in the array of ACL structures. | |
3881 | + * calclass - If this is not zero, then we compute the CLASS_OBJ | |
3882 | + * permissions. | |
3883 | + * aclp - Array of ACL structures. | |
3884 | + * | |
3885 | + * Outputs: | |
3886 | + * | |
3887 | + * aclp - Sorted array of ACL structures. | |
3888 | + * | |
3889 | + * Outputs: | |
3890 | + * | |
3891 | + * Returns 0 for success -1 for failure. Prints a message to the Samba | |
3892 | + * debug log in case of failure. | |
3893 | + */ | |
3894 | + | |
3895 | +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp) | |
3896 | +{ | |
3897 | +#if !defined(HAVE_HPUX_ACLSORT) | |
0f6733d8 WD |
3898 | + /* |
3899 | + * The aclsort() system call is availabe on the latest HPUX General | |
3900 | + * Patch Bundles. So for HPUX, we developed our version of acl_sort | |
3901 | + * function. Because, we don't want to update to a new | |
3902 | + * HPUX GR bundle just for aclsort() call. | |
3903 | + */ | |
fa26e11c WD |
3904 | + |
3905 | + struct hpux_acl_types acl_obj_count; | |
3906 | + int n_class_obj_perm = 0; | |
3907 | + int i, j; | |
0f6733d8 WD |
3908 | + |
3909 | + if(!acl_count) { | |
fa26e11c WD |
3910 | + DEBUG(10,("Zero acl count passed. Returning Success\n")); |
3911 | + return 0; | |
3912 | + } | |
3913 | + | |
0f6733d8 | 3914 | + if(aclp == NULL) { |
fa26e11c WD |
3915 | + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n")); |
3916 | + return -1; | |
3917 | + } | |
3918 | + | |
3919 | + /* Count different types of ACLs in the ACLs array */ | |
3920 | + | |
3921 | + hpux_count_obj(acl_count, aclp, &acl_obj_count); | |
3922 | + | |
0f6733d8 WD |
3923 | + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ, |
3924 | + * CLASS_OBJ and OTHER_OBJ | |
fa26e11c WD |
3925 | + */ |
3926 | + | |
0f6733d8 WD |
3927 | + if( (acl_obj_count.n_user_obj != 1) || |
3928 | + (acl_obj_count.n_group_obj != 1) || | |
3929 | + (acl_obj_count.n_class_obj != 1) || | |
3930 | + (acl_obj_count.n_other_obj != 1) | |
3931 | + ) { | |
fa26e11c WD |
3932 | + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \ |
3933 | +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n")); | |
3934 | + return -1; | |
3935 | + } | |
3936 | + | |
3937 | + /* If any of the default objects are present, there should be only | |
3938 | + * one of them each. | |
3939 | + */ | |
3940 | + | |
0f6733d8 WD |
3941 | + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) || |
3942 | + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) { | |
fa26e11c WD |
3943 | + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \ |
3944 | +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n")); | |
3945 | + return -1; | |
3946 | + } | |
3947 | + | |
0f6733d8 WD |
3948 | + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl |
3949 | + * structures. | |
fa26e11c WD |
3950 | + * |
3951 | + * Sorting crieteria - First sort by ACL type. If there are multiple entries of | |
3952 | + * same ACL type, sort by ACL id. | |
3953 | + * | |
0f6733d8 | 3954 | + * I am using the trival kind of sorting method here because, performance isn't |
fa26e11c | 3955 | + * really effected by the ACLs feature. More over there aren't going to be more |
0f6733d8 | 3956 | + * than 17 entries on HPUX. |
fa26e11c WD |
3957 | + */ |
3958 | + | |
0f6733d8 | 3959 | + for(i=0; i<acl_count;i++) { |
fa26e11c | 3960 | + for (j=i+1; j<acl_count; j++) { |
0f6733d8 | 3961 | + if( aclp[i].a_type > aclp[j].a_type ) { |
fa26e11c WD |
3962 | + /* ACL entries out of order, swap them */ |
3963 | + | |
3964 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); | |
3965 | + | |
0f6733d8 | 3966 | + } else if ( aclp[i].a_type == aclp[j].a_type ) { |
fa26e11c WD |
3967 | + |
3968 | + /* ACL entries of same type, sort by id */ | |
3969 | + | |
0f6733d8 | 3970 | + if(aclp[i].a_id > aclp[j].a_id) { |
fa26e11c WD |
3971 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); |
3972 | + } else if (aclp[i].a_id == aclp[j].a_id) { | |
3973 | + /* We have a duplicate entry. */ | |
0f6733d8 | 3974 | + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) { |
fa26e11c WD |
3975 | + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n", |
3976 | + aclp[i].a_type, aclp[i].a_id)); | |
3977 | + return -1; | |
3978 | + } | |
3979 | + } | |
3980 | + | |
3981 | + } | |
3982 | + } | |
3983 | + } | |
3984 | + | |
3985 | + /* set the class obj permissions to the computed one. */ | |
0f6733d8 | 3986 | + if(calclass) { |
fa26e11c WD |
3987 | + int n_class_obj_index = -1; |
3988 | + | |
0f6733d8 | 3989 | + for(i=0;i<acl_count;i++) { |
fa26e11c WD |
3990 | + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i)); |
3991 | + | |
0f6733d8 | 3992 | + if(aclp[i].a_type == CLASS_OBJ) |
fa26e11c WD |
3993 | + n_class_obj_index = i; |
3994 | + } | |
3995 | + aclp[n_class_obj_index].a_perm = n_class_obj_perm; | |
3996 | + } | |
3997 | + | |
3998 | + return 0; | |
3999 | +#else | |
4000 | + return aclsort(acl_count, calclass, aclp); | |
4001 | +#endif | |
4002 | +} | |
4003 | + | |
0f6733d8 WD |
4004 | +/* |
4005 | + * sort the ACL and check it for validity | |
fa26e11c | 4006 | + * |
0f6733d8 | 4007 | + * if it's a minimal ACL with only 4 entries then we |
fa26e11c WD |
4008 | + * need to recalculate the mask permissions to make |
4009 | + * sure that they are the same as the GROUP_OBJ | |
4010 | + * permissions as required by the UnixWare acl() system call. | |
4011 | + * | |
0f6733d8 | 4012 | + * (note: since POSIX allows minimal ACLs which only contain |
fa26e11c WD |
4013 | + * 3 entries - ie there is no mask entry - we should, in theory, |
4014 | + * check for this and add a mask entry if necessary - however | |
4015 | + * we "know" that the caller of this interface always specifies | |
4016 | + * a mask so, in practice "this never happens" (tm) - if it *does* | |
4017 | + * happen aclsort() will fail and return an error and someone will | |
0f6733d8 WD |
4018 | + * have to fix it ...) |
4019 | + */ | |
fa26e11c WD |
4020 | + |
4021 | +static int acl_sort(SMB_ACL_T acl_d) | |
4022 | +{ | |
4023 | + int fixmask = (acl_d->count <= 4); | |
4024 | + | |
4025 | + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) { | |
4026 | + errno = EINVAL; | |
4027 | + return -1; | |
4028 | + } | |
4029 | + return 0; | |
4030 | +} | |
0f6733d8 WD |
4031 | + |
4032 | +int sys_acl_valid(SMB_ACL_T acl_d) | |
fa26e11c WD |
4033 | +{ |
4034 | + return acl_sort(acl_d); | |
4035 | +} | |
4036 | + | |
0f6733d8 | 4037 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c | 4038 | +{ |
0f6733d8 WD |
4039 | + struct stat s; |
4040 | + struct acl *acl_p; | |
4041 | + int acl_count; | |
4042 | + struct acl *acl_buf = NULL; | |
4043 | + int ret; | |
fa26e11c | 4044 | + |
0f6733d8 WD |
4045 | + if(hpux_acl_call_presence() == False) { |
4046 | + /* Looks like we don't have the acl() system call on HPUX. | |
4047 | + * May be the system doesn't have the latest version of JFS. | |
4048 | + */ | |
4049 | + errno=ENOSYS; | |
4050 | + return -1; | |
fa26e11c WD |
4051 | + } |
4052 | + | |
4053 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
4054 | + errno = EINVAL; | |
4055 | + return -1; | |
4056 | + } | |
4057 | + | |
4058 | + if (acl_sort(acl_d) != 0) { | |
4059 | + return -1; | |
4060 | + } | |
4061 | + | |
0f6733d8 WD |
4062 | + acl_p = &acl_d->acl[0]; |
4063 | + acl_count = acl_d->count; | |
fa26e11c | 4064 | + |
0f6733d8 WD |
4065 | + /* |
4066 | + * if it's a directory there is extra work to do | |
4067 | + * since the acl() system call will replace both | |
4068 | + * the access ACLs and the default ACLs (if any) | |
4069 | + */ | |
fa26e11c WD |
4070 | + if (stat(name, &s) != 0) { |
4071 | + return -1; | |
4072 | + } | |
4073 | + if (S_ISDIR(s.st_mode)) { | |
0f6733d8 WD |
4074 | + SMB_ACL_T acc_acl; |
4075 | + SMB_ACL_T def_acl; | |
4076 | + SMB_ACL_T tmp_acl; | |
4077 | + int i; | |
fa26e11c WD |
4078 | + |
4079 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
4080 | + acc_acl = acl_d; | |
4081 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); | |
4082 | + | |
4083 | + } else { | |
4084 | + def_acl = acl_d; | |
4085 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); | |
4086 | + } | |
4087 | + | |
4088 | + if (tmp_acl == NULL) { | |
4089 | + return -1; | |
4090 | + } | |
4091 | + | |
0f6733d8 WD |
4092 | + /* |
4093 | + * allocate a temporary buffer for the complete ACL | |
4094 | + */ | |
fa26e11c | 4095 | + acl_count = acc_acl->count + def_acl->count; |
252945ef | 4096 | + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
fa26e11c WD |
4097 | + |
4098 | + if (acl_buf == NULL) { | |
4099 | + sys_acl_free_acl(tmp_acl); | |
4100 | + errno = ENOMEM; | |
4101 | + return -1; | |
4102 | + } | |
4103 | + | |
0f6733d8 WD |
4104 | + /* |
4105 | + * copy the access control and default entries into the buffer | |
4106 | + */ | |
fa26e11c | 4107 | + memcpy(&acl_buf[0], &acc_acl->acl[0], |
0f6733d8 | 4108 | + acc_acl->count * sizeof(acl_buf[0])); |
fa26e11c WD |
4109 | + |
4110 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], | |
0f6733d8 | 4111 | + def_acl->count * sizeof(acl_buf[0])); |
fa26e11c | 4112 | + |
0f6733d8 WD |
4113 | + /* |
4114 | + * set the ACL_DEFAULT flag on the default entries | |
4115 | + */ | |
fa26e11c WD |
4116 | + for (i = acc_acl->count; i < acl_count; i++) { |
4117 | + acl_buf[i].a_type |= ACL_DEFAULT; | |
4118 | + } | |
4119 | + | |
4120 | + sys_acl_free_acl(tmp_acl); | |
4121 | + | |
4122 | + } else if (type != SMB_ACL_TYPE_ACCESS) { | |
4123 | + errno = EINVAL; | |
4124 | + return -1; | |
4125 | + } | |
4126 | + | |
4127 | + ret = acl(name, ACL_SET, acl_count, acl_p); | |
4128 | + | |
0f6733d8 WD |
4129 | + if (acl_buf) { |
4130 | + free(acl_buf); | |
4131 | + } | |
fa26e11c WD |
4132 | + |
4133 | + return ret; | |
4134 | +} | |
4135 | + | |
0f6733d8 | 4136 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c | 4137 | +{ |
0f6733d8 WD |
4138 | + /* |
4139 | + * HPUX doesn't have the facl call. Fake it using the path.... JRA. | |
4140 | + */ | |
fa26e11c WD |
4141 | + |
4142 | + files_struct *fsp = file_find_fd(fd); | |
4143 | + | |
4144 | + if (fsp == NULL) { | |
4145 | + errno = EBADF; | |
4146 | + return NULL; | |
4147 | + } | |
4148 | + | |
4149 | + if (acl_sort(acl_d) != 0) { | |
4150 | + return -1; | |
4151 | + } | |
4152 | + | |
0f6733d8 WD |
4153 | + /* |
4154 | + * We know we're in the same conn context. So we | |
4155 | + * can use the relative path. | |
4156 | + */ | |
fa26e11c | 4157 | + |
5ca9317d | 4158 | + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d); |
fa26e11c WD |
4159 | +} |
4160 | + | |
0f6733d8 | 4161 | +int sys_acl_delete_def_file(const char *path) |
fa26e11c | 4162 | +{ |
0f6733d8 WD |
4163 | + SMB_ACL_T acl_d; |
4164 | + int ret; | |
fa26e11c | 4165 | + |
0f6733d8 WD |
4166 | + /* |
4167 | + * fetching the access ACL and rewriting it has | |
4168 | + * the effect of deleting the default ACL | |
4169 | + */ | |
fa26e11c WD |
4170 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
4171 | + return -1; | |
4172 | + } | |
4173 | + | |
4174 | + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl); | |
4175 | + | |
4176 | + sys_acl_free_acl(acl_d); | |
0f6733d8 | 4177 | + |
fa26e11c WD |
4178 | + return ret; |
4179 | +} | |
4180 | + | |
0f6733d8 | 4181 | +int sys_acl_free_text(char *text) |
fa26e11c WD |
4182 | +{ |
4183 | + free(text); | |
4184 | + return 0; | |
4185 | +} | |
4186 | + | |
0f6733d8 | 4187 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c WD |
4188 | +{ |
4189 | + free(acl_d); | |
4190 | + return 0; | |
4191 | +} | |
4192 | + | |
0f6733d8 | 4193 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
4194 | +{ |
4195 | + return 0; | |
4196 | +} | |
4197 | + | |
4198 | +#elif defined(HAVE_IRIX_ACLS) | |
4199 | + | |
0f6733d8 | 4200 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
4201 | +{ |
4202 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
4203 | + errno = EINVAL; | |
4204 | + return -1; | |
4205 | + } | |
4206 | + | |
4207 | + if (entry_p == NULL) { | |
4208 | + errno = EINVAL; | |
4209 | + return -1; | |
4210 | + } | |
4211 | + | |
4212 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
4213 | + acl_d->next = 0; | |
4214 | + } | |
4215 | + | |
4216 | + if (acl_d->next < 0) { | |
4217 | + errno = EINVAL; | |
4218 | + return -1; | |
4219 | + } | |
4220 | + | |
4221 | + if (acl_d->next >= acl_d->aclp->acl_cnt) { | |
4222 | + return 0; | |
4223 | + } | |
4224 | + | |
4225 | + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++]; | |
4226 | + | |
4227 | + return 1; | |
4228 | +} | |
4229 | + | |
0f6733d8 | 4230 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
4231 | +{ |
4232 | + *type_p = entry_d->ae_tag; | |
4233 | + | |
4234 | + return 0; | |
4235 | +} | |
4236 | + | |
0f6733d8 | 4237 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
4238 | +{ |
4239 | + *permset_p = entry_d; | |
4240 | + | |
4241 | + return 0; | |
4242 | +} | |
4243 | + | |
0f6733d8 | 4244 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
4245 | +{ |
4246 | + if (entry_d->ae_tag != SMB_ACL_USER | |
4247 | + && entry_d->ae_tag != SMB_ACL_GROUP) { | |
4248 | + errno = EINVAL; | |
4249 | + return NULL; | |
4250 | + } | |
4251 | + | |
4252 | + return &entry_d->ae_id; | |
4253 | +} | |
4254 | + | |
0f6733d8 | 4255 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 4256 | +{ |
0f6733d8 | 4257 | + SMB_ACL_T a; |
fa26e11c | 4258 | + |
252945ef | 4259 | + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
fa26e11c WD |
4260 | + errno = ENOMEM; |
4261 | + return NULL; | |
4262 | + } | |
4263 | + if ((a->aclp = acl_get_file(path_p, type)) == NULL) { | |
0f6733d8 | 4264 | + SAFE_FREE(a); |
fa26e11c WD |
4265 | + return NULL; |
4266 | + } | |
4267 | + a->next = -1; | |
4268 | + a->freeaclp = True; | |
4269 | + return a; | |
4270 | +} | |
4271 | + | |
0f6733d8 | 4272 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 4273 | +{ |
0f6733d8 | 4274 | + SMB_ACL_T a; |
fa26e11c | 4275 | + |
252945ef | 4276 | + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
fa26e11c WD |
4277 | + errno = ENOMEM; |
4278 | + return NULL; | |
4279 | + } | |
4280 | + if ((a->aclp = acl_get_fd(fd)) == NULL) { | |
0f6733d8 | 4281 | + SAFE_FREE(a); |
fa26e11c WD |
4282 | + return NULL; |
4283 | + } | |
4284 | + a->next = -1; | |
4285 | + a->freeaclp = True; | |
4286 | + return a; | |
4287 | +} | |
4288 | + | |
0f6733d8 | 4289 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
4290 | +{ |
4291 | + permset_d->ae_perm = 0; | |
4292 | + | |
4293 | + return 0; | |
4294 | +} | |
4295 | + | |
0f6733d8 | 4296 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
4297 | +{ |
4298 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
4299 | + && perm != SMB_ACL_EXECUTE) { | |
4300 | + errno = EINVAL; | |
4301 | + return -1; | |
4302 | + } | |
4303 | + | |
4304 | + if (permset_d == NULL) { | |
4305 | + errno = EINVAL; | |
4306 | + return -1; | |
4307 | + } | |
4308 | + | |
4309 | + permset_d->ae_perm |= perm; | |
4310 | + | |
4311 | + return 0; | |
4312 | +} | |
4313 | + | |
0f6733d8 | 4314 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
4315 | +{ |
4316 | + return permset_d->ae_perm & perm; | |
4317 | +} | |
4318 | + | |
0f6733d8 | 4319 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c WD |
4320 | +{ |
4321 | + return acl_to_text(acl_d->aclp, len_p); | |
4322 | +} | |
4323 | + | |
0f6733d8 | 4324 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 4325 | +{ |
0f6733d8 | 4326 | + SMB_ACL_T a; |
fa26e11c WD |
4327 | + |
4328 | + if (count < 0) { | |
4329 | + errno = EINVAL; | |
4330 | + return NULL; | |
4331 | + } | |
4332 | + | |
252945ef | 4333 | + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) { |
fa26e11c WD |
4334 | + errno = ENOMEM; |
4335 | + return NULL; | |
4336 | + } | |
4337 | + | |
4338 | + a->next = -1; | |
4339 | + a->freeaclp = False; | |
0f6733d8 | 4340 | + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *)); |
fa26e11c WD |
4341 | + a->aclp->acl_cnt = 0; |
4342 | + | |
4343 | + return a; | |
4344 | +} | |
4345 | + | |
4346 | + | |
0f6733d8 | 4347 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 4348 | +{ |
0f6733d8 WD |
4349 | + SMB_ACL_T acl_d; |
4350 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
4351 | + |
4352 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
4353 | + errno = EINVAL; | |
4354 | + return -1; | |
4355 | + } | |
4356 | + | |
4357 | + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) { | |
4358 | + errno = ENOSPC; | |
4359 | + return -1; | |
4360 | + } | |
4361 | + | |
0f6733d8 WD |
4362 | + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++]; |
4363 | + entry_d->ae_tag = 0; | |
4364 | + entry_d->ae_id = 0; | |
4365 | + entry_d->ae_perm = 0; | |
4366 | + *entry_p = entry_d; | |
fa26e11c WD |
4367 | + |
4368 | + return 0; | |
4369 | +} | |
4370 | + | |
0f6733d8 | 4371 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
4372 | +{ |
4373 | + switch (tag_type) { | |
4374 | + case SMB_ACL_USER: | |
4375 | + case SMB_ACL_USER_OBJ: | |
4376 | + case SMB_ACL_GROUP: | |
4377 | + case SMB_ACL_GROUP_OBJ: | |
4378 | + case SMB_ACL_OTHER: | |
4379 | + case SMB_ACL_MASK: | |
4380 | + entry_d->ae_tag = tag_type; | |
4381 | + break; | |
4382 | + default: | |
4383 | + errno = EINVAL; | |
4384 | + return -1; | |
4385 | + } | |
4386 | + | |
4387 | + return 0; | |
4388 | +} | |
4389 | + | |
0f6733d8 | 4390 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
4391 | +{ |
4392 | + if (entry_d->ae_tag != SMB_ACL_GROUP | |
4393 | + && entry_d->ae_tag != SMB_ACL_USER) { | |
4394 | + errno = EINVAL; | |
4395 | + return -1; | |
4396 | + } | |
4397 | + | |
4398 | + entry_d->ae_id = *((id_t *)qual_p); | |
4399 | + | |
4400 | + return 0; | |
4401 | +} | |
4402 | + | |
0f6733d8 | 4403 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
4404 | +{ |
4405 | + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
4406 | + return EINVAL; | |
4407 | + } | |
4408 | + | |
4409 | + entry_d->ae_perm = permset_d->ae_perm; | |
4410 | + | |
4411 | + return 0; | |
4412 | +} | |
4413 | + | |
0f6733d8 | 4414 | +int sys_acl_valid(SMB_ACL_T acl_d) |
fa26e11c WD |
4415 | +{ |
4416 | + return acl_valid(acl_d->aclp); | |
4417 | +} | |
4418 | + | |
0f6733d8 | 4419 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c WD |
4420 | +{ |
4421 | + return acl_set_file(name, type, acl_d->aclp); | |
4422 | +} | |
4423 | + | |
0f6733d8 | 4424 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c WD |
4425 | +{ |
4426 | + return acl_set_fd(fd, acl_d->aclp); | |
4427 | +} | |
4428 | + | |
0f6733d8 | 4429 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
4430 | +{ |
4431 | + return acl_delete_def_file(name); | |
4432 | +} | |
4433 | + | |
0f6733d8 | 4434 | +int sys_acl_free_text(char *text) |
fa26e11c WD |
4435 | +{ |
4436 | + return acl_free(text); | |
4437 | +} | |
4438 | + | |
0f6733d8 | 4439 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c WD |
4440 | +{ |
4441 | + if (acl_d->freeaclp) { | |
4442 | + acl_free(acl_d->aclp); | |
4443 | + } | |
4444 | + acl_free(acl_d); | |
4445 | + return 0; | |
4446 | +} | |
4447 | + | |
0f6733d8 | 4448 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
4449 | +{ |
4450 | + return 0; | |
4451 | +} | |
4452 | + | |
4453 | +#elif defined(HAVE_AIX_ACLS) | |
4454 | + | |
4455 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
4456 | + | |
0f6733d8 | 4457 | +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
4458 | +{ |
4459 | + struct acl_entry_link *link; | |
4460 | + struct new_acl_entry *entry; | |
4461 | + int keep_going; | |
4462 | + | |
4463 | + DEBUG(10,("This is the count: %d\n",theacl->count)); | |
4464 | + | |
0f6733d8 WD |
4465 | + /* Check if count was previously set to -1. * |
4466 | + * If it was, that means we reached the end * | |
4467 | + * of the acl last time. */ | |
4468 | + if(theacl->count == -1) | |
4469 | + return(0); | |
fa26e11c WD |
4470 | + |
4471 | + link = theacl; | |
0f6733d8 WD |
4472 | + /* To get to the next acl, traverse linked list until index * |
4473 | + * of acl matches the count we are keeping. This count is * | |
4474 | + * incremented each time we return an acl entry. */ | |
fa26e11c | 4475 | + |
0f6733d8 | 4476 | + for(keep_going = 0; keep_going < theacl->count; keep_going++) |
fa26e11c WD |
4477 | + link = link->nextp; |
4478 | + | |
4479 | + entry = *entry_p = link->entryp; | |
4480 | + | |
4481 | + DEBUG(10,("*entry_p is %d\n",entry_p)); | |
4482 | + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access)); | |
4483 | + | |
4484 | + /* Increment count */ | |
4485 | + theacl->count++; | |
0f6733d8 | 4486 | + if(link->nextp == NULL) |
fa26e11c WD |
4487 | + theacl->count = -1; |
4488 | + | |
0f6733d8 | 4489 | + return(1); |
fa26e11c WD |
4490 | +} |
4491 | + | |
0f6733d8 | 4492 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c WD |
4493 | +{ |
4494 | + /* Initialize tag type */ | |
4495 | + | |
4496 | + *tag_type_p = -1; | |
4497 | + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type)); | |
4498 | + | |
0f6733d8 WD |
4499 | + /* Depending on what type of entry we have, * |
4500 | + * return tag type. */ | |
4501 | + switch(entry_d->ace_id->id_type) { | |
fa26e11c WD |
4502 | + case ACEID_USER: |
4503 | + *tag_type_p = SMB_ACL_USER; | |
4504 | + break; | |
4505 | + case ACEID_GROUP: | |
4506 | + *tag_type_p = SMB_ACL_GROUP; | |
4507 | + break; | |
4508 | + | |
4509 | + case SMB_ACL_USER_OBJ: | |
4510 | + case SMB_ACL_GROUP_OBJ: | |
4511 | + case SMB_ACL_OTHER: | |
4512 | + *tag_type_p = entry_d->ace_id->id_type; | |
4513 | + break; | |
0f6733d8 | 4514 | + |
fa26e11c | 4515 | + default: |
0f6733d8 | 4516 | + return(-1); |
fa26e11c WD |
4517 | + } |
4518 | + | |
0f6733d8 | 4519 | + return(0); |
fa26e11c WD |
4520 | +} |
4521 | + | |
0f6733d8 | 4522 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
4523 | +{ |
4524 | + DEBUG(10,("Starting AIX sys_acl_get_permset\n")); | |
4525 | + *permset_p = &entry_d->ace_access; | |
4526 | + DEBUG(10,("**permset_p is %d\n",**permset_p)); | |
0f6733d8 WD |
4527 | + if(!(**permset_p & S_IXUSR) && |
4528 | + !(**permset_p & S_IWUSR) && | |
4529 | + !(**permset_p & S_IRUSR) && | |
4530 | + (**permset_p != 0)) | |
4531 | + return(-1); | |
fa26e11c WD |
4532 | + |
4533 | + DEBUG(10,("Ending AIX sys_acl_get_permset\n")); | |
0f6733d8 | 4534 | + return(0); |
fa26e11c WD |
4535 | +} |
4536 | + | |
0f6733d8 | 4537 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 4538 | +{ |
0f6733d8 | 4539 | + return(entry_d->ace_id->id_data); |
fa26e11c WD |
4540 | +} |
4541 | + | |
0f6733d8 | 4542 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c WD |
4543 | +{ |
4544 | + struct acl *file_acl = (struct acl *)NULL; | |
4545 | + struct acl_entry *acl_entry; | |
4546 | + struct new_acl_entry *new_acl_entry; | |
4547 | + struct ace_id *idp; | |
4548 | + struct acl_entry_link *acl_entry_link; | |
4549 | + struct acl_entry_link *acl_entry_link_head; | |
4550 | + int i; | |
4551 | + int rc = 0; | |
4552 | + uid_t user_id; | |
4553 | + | |
252945ef | 4554 | + /* AIX has no DEFAULT */ |
85148847 WD |
4555 | + if ( type == SMB_ACL_TYPE_DEFAULT ) { |
4556 | + errno = ENOTSUP; | |
252945ef | 4557 | + return NULL; |
85148847 | 4558 | + } |
252945ef | 4559 | + |
fa26e11c | 4560 | + /* Get the acl using statacl */ |
0f6733d8 | 4561 | + |
fa26e11c WD |
4562 | + DEBUG(10,("Entering sys_acl_get_file\n")); |
4563 | + DEBUG(10,("path_p is %s\n",path_p)); | |
4564 | + | |
252945ef | 4565 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
0f6733d8 WD |
4566 | + |
4567 | + if(file_acl == NULL) { | |
fa26e11c WD |
4568 | + errno=ENOMEM; |
4569 | + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno)); | |
0f6733d8 | 4570 | + return(NULL); |
fa26e11c WD |
4571 | + } |
4572 | + | |
4573 | + memset(file_acl,0,BUFSIZ); | |
4574 | + | |
4575 | + rc = statacl((char *)path_p,0,file_acl,BUFSIZ); | |
0f6733d8 | 4576 | + if(rc == -1) { |
fa26e11c | 4577 | + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno)); |
0f6733d8 WD |
4578 | + SAFE_FREE(file_acl); |
4579 | + return(NULL); | |
fa26e11c WD |
4580 | + } |
4581 | + | |
4582 | + DEBUG(10,("Got facl and returned it\n")); | |
4583 | + | |
4584 | + /* Point to the first acl entry in the acl */ | |
4585 | + acl_entry = file_acl->acl_ext; | |
4586 | + | |
0f6733d8 WD |
4587 | + /* Begin setting up the head of the linked list * |
4588 | + * that will be used for the storing the acl * | |
4589 | + * in a way that is useful for the posix_acls.c * | |
4590 | + * code. */ | |
fa26e11c WD |
4591 | + |
4592 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); | |
0f6733d8 WD |
4593 | + if(acl_entry_link_head == NULL) |
4594 | + return(NULL); | |
fa26e11c | 4595 | + |
252945ef | 4596 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
4597 | + if(acl_entry_link->entryp == NULL) { |
4598 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4599 | + errno = ENOMEM; |
4600 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4601 | + return(NULL); |
fa26e11c WD |
4602 | + } |
4603 | + | |
4604 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); | |
4605 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); | |
4606 | + | |
0f6733d8 WD |
4607 | + /* Check if the extended acl bit is on. * |
4608 | + * If it isn't, do not show the * | |
4609 | + * contents of the acl since AIX intends * | |
4610 | + * the extended info to remain unused */ | |
fa26e11c | 4611 | + |
0f6733d8 | 4612 | + if(file_acl->acl_mode & S_IXACL){ |
fa26e11c | 4613 | + /* while we are not pointing to the very end */ |
0f6733d8 | 4614 | + while(acl_entry < acl_last(file_acl)) { |
fa26e11c WD |
4615 | + /* before we malloc anything, make sure this is */ |
4616 | + /* a valid acl entry and one that we want to map */ | |
4617 | + idp = id_nxt(acl_entry->ace_id); | |
0f6733d8 WD |
4618 | + if((acl_entry->ace_type == ACC_SPECIFY || |
4619 | + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { | |
4620 | + acl_entry = acl_nxt(acl_entry); | |
4621 | + continue; | |
fa26e11c WD |
4622 | + } |
4623 | + | |
4624 | + idp = acl_entry->ace_id; | |
4625 | + | |
0f6733d8 WD |
4626 | + /* Check if this is the first entry in the linked list. * |
4627 | + * The first entry needs to keep prevp pointing to NULL * | |
4628 | + * and already has entryp allocated. */ | |
fa26e11c | 4629 | + |
0f6733d8 | 4630 | + if(acl_entry_link_head->count != 0) { |
252945ef | 4631 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
fa26e11c | 4632 | + |
0f6733d8 WD |
4633 | + if(acl_entry_link->nextp == NULL) { |
4634 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4635 | + errno = ENOMEM; |
4636 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4637 | + return(NULL); |
fa26e11c WD |
4638 | + } |
4639 | + | |
4640 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4641 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4642 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
4643 | + if(acl_entry_link->entryp == NULL) { |
4644 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4645 | + errno = ENOMEM; |
4646 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4647 | + return(NULL); |
fa26e11c WD |
4648 | + } |
4649 | + acl_entry_link->nextp = NULL; | |
4650 | + } | |
4651 | + | |
4652 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; | |
4653 | + | |
0f6733d8 WD |
4654 | + /* Don't really need this since all types are going * |
4655 | + * to be specified but, it's better than leaving it 0 */ | |
fa26e11c WD |
4656 | + |
4657 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; | |
0f6733d8 | 4658 | + |
fa26e11c | 4659 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
0f6733d8 WD |
4660 | + |
4661 | + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id)); | |
fa26e11c | 4662 | + |
0f6733d8 WD |
4663 | + /* The access in the acl entries must be left shifted by * |
4664 | + * three bites, because they will ultimately be compared * | |
4665 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ | |
fa26e11c | 4666 | + |
0f6733d8 | 4667 | + switch(acl_entry->ace_type){ |
fa26e11c WD |
4668 | + case ACC_PERMIT: |
4669 | + case ACC_SPECIFY: | |
4670 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4671 | + acl_entry_link->entryp->ace_access <<= 6; | |
4672 | + acl_entry_link_head->count++; | |
4673 | + break; | |
4674 | + case ACC_DENY: | |
0f6733d8 WD |
4675 | + /* Since there is no way to return a DENY acl entry * |
4676 | + * change to PERMIT and then shift. */ | |
fa26e11c WD |
4677 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); |
4678 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; | |
4679 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); | |
4680 | + acl_entry_link->entryp->ace_access <<= 6; | |
4681 | + acl_entry_link_head->count++; | |
4682 | + break; | |
4683 | + default: | |
0f6733d8 | 4684 | + return(0); |
fa26e11c WD |
4685 | + } |
4686 | + | |
4687 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); | |
4688 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); | |
0f6733d8 | 4689 | + |
fa26e11c WD |
4690 | + acl_entry = acl_nxt(acl_entry); |
4691 | + } | |
4692 | + } /* end of if enabled */ | |
4693 | + | |
0f6733d8 WD |
4694 | + /* Since owner, group, other acl entries are not * |
4695 | + * part of the acl entries in an acl, they must * | |
4696 | + * be dummied up to become part of the list. */ | |
fa26e11c | 4697 | + |
0f6733d8 | 4698 | + for( i = 1; i < 4; i++) { |
fa26e11c | 4699 | + DEBUG(10,("i is %d\n",i)); |
0f6733d8 | 4700 | + if(acl_entry_link_head->count != 0) { |
252945ef | 4701 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 WD |
4702 | + if(acl_entry_link->nextp == NULL) { |
4703 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4704 | + errno = ENOMEM; |
4705 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4706 | + return(NULL); |
fa26e11c WD |
4707 | + } |
4708 | + | |
4709 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4710 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4711 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
4712 | + if(acl_entry_link->entryp == NULL) { |
4713 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4714 | + errno = ENOMEM; |
4715 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4716 | + return(NULL); |
fa26e11c WD |
4717 | + } |
4718 | + } | |
4719 | + | |
4720 | + acl_entry_link->nextp = NULL; | |
4721 | + | |
4722 | + new_acl_entry = acl_entry_link->entryp; | |
4723 | + idp = new_acl_entry->ace_id; | |
4724 | + | |
0f6733d8 | 4725 | + new_acl_entry->ace_len = sizeof(struct acl_entry); |
fa26e11c | 4726 | + new_acl_entry->ace_type = ACC_PERMIT; |
0f6733d8 | 4727 | + idp->id_len = sizeof(struct ace_id); |
fa26e11c | 4728 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); |
0f6733d8 | 4729 | + memset(idp->id_data,0,sizeof(uid_t)); |
fa26e11c | 4730 | + |
0f6733d8 | 4731 | + switch(i) { |
fa26e11c WD |
4732 | + case 2: |
4733 | + new_acl_entry->ace_access = file_acl->g_access << 6; | |
4734 | + idp->id_type = SMB_ACL_GROUP_OBJ; | |
4735 | + break; | |
4736 | + | |
4737 | + case 3: | |
4738 | + new_acl_entry->ace_access = file_acl->o_access << 6; | |
4739 | + idp->id_type = SMB_ACL_OTHER; | |
4740 | + break; | |
0f6733d8 | 4741 | + |
fa26e11c WD |
4742 | + case 1: |
4743 | + new_acl_entry->ace_access = file_acl->u_access << 6; | |
4744 | + idp->id_type = SMB_ACL_USER_OBJ; | |
4745 | + break; | |
0f6733d8 | 4746 | + |
fa26e11c | 4747 | + default: |
0f6733d8 | 4748 | + return(NULL); |
fa26e11c WD |
4749 | + |
4750 | + } | |
4751 | + | |
4752 | + acl_entry_link_head->count++; | |
4753 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); | |
4754 | + } | |
4755 | + | |
4756 | + acl_entry_link_head->count = 0; | |
0f6733d8 | 4757 | + SAFE_FREE(file_acl); |
fa26e11c | 4758 | + |
0f6733d8 | 4759 | + return(acl_entry_link_head); |
fa26e11c WD |
4760 | +} |
4761 | + | |
0f6733d8 | 4762 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c WD |
4763 | +{ |
4764 | + struct acl *file_acl = (struct acl *)NULL; | |
4765 | + struct acl_entry *acl_entry; | |
4766 | + struct new_acl_entry *new_acl_entry; | |
4767 | + struct ace_id *idp; | |
4768 | + struct acl_entry_link *acl_entry_link; | |
4769 | + struct acl_entry_link *acl_entry_link_head; | |
4770 | + int i; | |
4771 | + int rc = 0; | |
4772 | + uid_t user_id; | |
4773 | + | |
4774 | + /* Get the acl using fstatacl */ | |
0f6733d8 | 4775 | + |
fa26e11c WD |
4776 | + DEBUG(10,("Entering sys_acl_get_fd\n")); |
4777 | + DEBUG(10,("fd is %d\n",fd)); | |
252945ef | 4778 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 4779 | + |
0f6733d8 | 4780 | + if(file_acl == NULL) { |
fa26e11c WD |
4781 | + errno=ENOMEM; |
4782 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 | 4783 | + return(NULL); |
fa26e11c WD |
4784 | + } |
4785 | + | |
4786 | + memset(file_acl,0,BUFSIZ); | |
4787 | + | |
4788 | + rc = fstatacl(fd,0,file_acl,BUFSIZ); | |
0f6733d8 | 4789 | + if(rc == -1) { |
fa26e11c | 4790 | + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno)); |
0f6733d8 WD |
4791 | + SAFE_FREE(file_acl); |
4792 | + return(NULL); | |
fa26e11c WD |
4793 | + } |
4794 | + | |
4795 | + DEBUG(10,("Got facl and returned it\n")); | |
4796 | + | |
4797 | + /* Point to the first acl entry in the acl */ | |
4798 | + | |
4799 | + acl_entry = file_acl->acl_ext; | |
0f6733d8 WD |
4800 | + /* Begin setting up the head of the linked list * |
4801 | + * that will be used for the storing the acl * | |
4802 | + * in a way that is useful for the posix_acls.c * | |
4803 | + * code. */ | |
fa26e11c WD |
4804 | + |
4805 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); | |
0f6733d8 WD |
4806 | + if(acl_entry_link_head == NULL){ |
4807 | + SAFE_FREE(file_acl); | |
4808 | + return(NULL); | |
fa26e11c WD |
4809 | + } |
4810 | + | |
252945ef | 4811 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
fa26e11c | 4812 | + |
0f6733d8 | 4813 | + if(acl_entry_link->entryp == NULL) { |
fa26e11c WD |
4814 | + errno = ENOMEM; |
4815 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4816 | + SAFE_FREE(file_acl); |
4817 | + return(NULL); | |
fa26e11c WD |
4818 | + } |
4819 | + | |
4820 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); | |
4821 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); | |
0f6733d8 WD |
4822 | + |
4823 | + /* Check if the extended acl bit is on. * | |
4824 | + * If it isn't, do not show the * | |
4825 | + * contents of the acl since AIX intends * | |
4826 | + * the extended info to remain unused */ | |
4827 | + | |
4828 | + if(file_acl->acl_mode & S_IXACL){ | |
fa26e11c | 4829 | + /* while we are not pointing to the very end */ |
0f6733d8 | 4830 | + while(acl_entry < acl_last(file_acl)) { |
fa26e11c WD |
4831 | + /* before we malloc anything, make sure this is */ |
4832 | + /* a valid acl entry and one that we want to map */ | |
4833 | + | |
4834 | + idp = id_nxt(acl_entry->ace_id); | |
0f6733d8 WD |
4835 | + if((acl_entry->ace_type == ACC_SPECIFY || |
4836 | + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { | |
4837 | + acl_entry = acl_nxt(acl_entry); | |
4838 | + continue; | |
fa26e11c WD |
4839 | + } |
4840 | + | |
4841 | + idp = acl_entry->ace_id; | |
0f6733d8 WD |
4842 | + |
4843 | + /* Check if this is the first entry in the linked list. * | |
4844 | + * The first entry needs to keep prevp pointing to NULL * | |
4845 | + * and already has entryp allocated. */ | |
fa26e11c | 4846 | + |
0f6733d8 | 4847 | + if(acl_entry_link_head->count != 0) { |
252945ef | 4848 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 4849 | + if(acl_entry_link->nextp == NULL) { |
fa26e11c WD |
4850 | + errno = ENOMEM; |
4851 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4852 | + SAFE_FREE(file_acl); |
4853 | + return(NULL); | |
fa26e11c WD |
4854 | + } |
4855 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4856 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4857 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 | 4858 | + if(acl_entry_link->entryp == NULL) { |
fa26e11c WD |
4859 | + errno = ENOMEM; |
4860 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4861 | + SAFE_FREE(file_acl); |
4862 | + return(NULL); | |
fa26e11c WD |
4863 | + } |
4864 | + | |
4865 | + acl_entry_link->nextp = NULL; | |
4866 | + } | |
4867 | + | |
4868 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; | |
4869 | + | |
0f6733d8 WD |
4870 | + /* Don't really need this since all types are going * |
4871 | + * to be specified but, it's better than leaving it 0 */ | |
fa26e11c WD |
4872 | + |
4873 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; | |
4874 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4875 | + | |
0f6733d8 | 4876 | + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id)); |
fa26e11c | 4877 | + |
0f6733d8 WD |
4878 | + /* The access in the acl entries must be left shifted by * |
4879 | + * three bites, because they will ultimately be compared * | |
4880 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ | |
fa26e11c | 4881 | + |
0f6733d8 | 4882 | + switch(acl_entry->ace_type){ |
fa26e11c WD |
4883 | + case ACC_PERMIT: |
4884 | + case ACC_SPECIFY: | |
4885 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4886 | + acl_entry_link->entryp->ace_access <<= 6; | |
4887 | + acl_entry_link_head->count++; | |
4888 | + break; | |
4889 | + case ACC_DENY: | |
0f6733d8 WD |
4890 | + /* Since there is no way to return a DENY acl entry * |
4891 | + * change to PERMIT and then shift. */ | |
fa26e11c WD |
4892 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); |
4893 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; | |
4894 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); | |
4895 | + acl_entry_link->entryp->ace_access <<= 6; | |
4896 | + acl_entry_link_head->count++; | |
4897 | + break; | |
4898 | + default: | |
0f6733d8 | 4899 | + return(0); |
fa26e11c WD |
4900 | + } |
4901 | + | |
4902 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); | |
4903 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); | |
0f6733d8 | 4904 | + |
fa26e11c WD |
4905 | + acl_entry = acl_nxt(acl_entry); |
4906 | + } | |
4907 | + } /* end of if enabled */ | |
4908 | + | |
0f6733d8 WD |
4909 | + /* Since owner, group, other acl entries are not * |
4910 | + * part of the acl entries in an acl, they must * | |
4911 | + * be dummied up to become part of the list. */ | |
fa26e11c | 4912 | + |
0f6733d8 | 4913 | + for( i = 1; i < 4; i++) { |
fa26e11c | 4914 | + DEBUG(10,("i is %d\n",i)); |
0f6733d8 | 4915 | + if(acl_entry_link_head->count != 0){ |
252945ef | 4916 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 4917 | + if(acl_entry_link->nextp == NULL) { |
fa26e11c WD |
4918 | + errno = ENOMEM; |
4919 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4920 | + SAFE_FREE(file_acl); |
4921 | + return(NULL); | |
fa26e11c WD |
4922 | + } |
4923 | + | |
4924 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4925 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4926 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
fa26e11c | 4927 | + |
0f6733d8 WD |
4928 | + if(acl_entry_link->entryp == NULL) { |
4929 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4930 | + errno = ENOMEM; |
4931 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 | 4932 | + return(NULL); |
fa26e11c WD |
4933 | + } |
4934 | + } | |
4935 | + | |
4936 | + acl_entry_link->nextp = NULL; | |
0f6733d8 | 4937 | + |
fa26e11c WD |
4938 | + new_acl_entry = acl_entry_link->entryp; |
4939 | + idp = new_acl_entry->ace_id; | |
0f6733d8 WD |
4940 | + |
4941 | + new_acl_entry->ace_len = sizeof(struct acl_entry); | |
fa26e11c | 4942 | + new_acl_entry->ace_type = ACC_PERMIT; |
0f6733d8 | 4943 | + idp->id_len = sizeof(struct ace_id); |
fa26e11c | 4944 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); |
0f6733d8 WD |
4945 | + memset(idp->id_data,0,sizeof(uid_t)); |
4946 | + | |
4947 | + switch(i) { | |
fa26e11c WD |
4948 | + case 2: |
4949 | + new_acl_entry->ace_access = file_acl->g_access << 6; | |
4950 | + idp->id_type = SMB_ACL_GROUP_OBJ; | |
4951 | + break; | |
0f6733d8 | 4952 | + |
fa26e11c WD |
4953 | + case 3: |
4954 | + new_acl_entry->ace_access = file_acl->o_access << 6; | |
4955 | + idp->id_type = SMB_ACL_OTHER; | |
4956 | + break; | |
0f6733d8 | 4957 | + |
fa26e11c WD |
4958 | + case 1: |
4959 | + new_acl_entry->ace_access = file_acl->u_access << 6; | |
4960 | + idp->id_type = SMB_ACL_USER_OBJ; | |
4961 | + break; | |
0f6733d8 | 4962 | + |
fa26e11c | 4963 | + default: |
0f6733d8 | 4964 | + return(NULL); |
fa26e11c | 4965 | + } |
0f6733d8 | 4966 | + |
fa26e11c WD |
4967 | + acl_entry_link_head->count++; |
4968 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); | |
4969 | + } | |
4970 | + | |
4971 | + acl_entry_link_head->count = 0; | |
0f6733d8 WD |
4972 | + SAFE_FREE(file_acl); |
4973 | + | |
4974 | + return(acl_entry_link_head); | |
fa26e11c WD |
4975 | +} |
4976 | + | |
0f6733d8 | 4977 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
4978 | +{ |
4979 | + *permset = *permset & ~0777; | |
0f6733d8 | 4980 | + return(0); |
fa26e11c WD |
4981 | +} |
4982 | + | |
0f6733d8 | 4983 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 4984 | +{ |
0f6733d8 WD |
4985 | + if((perm != 0) && |
4986 | + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0) | |
4987 | + return(-1); | |
fa26e11c WD |
4988 | + |
4989 | + *permset |= perm; | |
4990 | + DEBUG(10,("This is the permset now: %d\n",*permset)); | |
0f6733d8 | 4991 | + return(0); |
fa26e11c WD |
4992 | +} |
4993 | + | |
0f6733d8 | 4994 | +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) |
fa26e11c | 4995 | +{ |
0f6733d8 | 4996 | + return(NULL); |
fa26e11c WD |
4997 | +} |
4998 | + | |
0f6733d8 | 4999 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
5000 | +{ |
5001 | + struct acl_entry_link *theacl = NULL; | |
0f6733d8 | 5002 | + |
fa26e11c WD |
5003 | + DEBUG(10,("Entering sys_acl_init\n")); |
5004 | + | |
252945ef | 5005 | + theacl = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 5006 | + if(theacl == NULL) { |
fa26e11c WD |
5007 | + errno = ENOMEM; |
5008 | + DEBUG(0,("Error in sys_acl_init is %d\n",errno)); | |
0f6733d8 | 5009 | + return(NULL); |
fa26e11c WD |
5010 | + } |
5011 | + | |
5012 | + theacl->count = 0; | |
5013 | + theacl->nextp = NULL; | |
5014 | + theacl->prevp = NULL; | |
5015 | + theacl->entryp = NULL; | |
5016 | + DEBUG(10,("Exiting sys_acl_init\n")); | |
0f6733d8 | 5017 | + return(theacl); |
fa26e11c WD |
5018 | +} |
5019 | + | |
0f6733d8 | 5020 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
5021 | +{ |
5022 | + struct acl_entry_link *theacl; | |
5023 | + struct acl_entry_link *acl_entryp; | |
5024 | + struct acl_entry_link *temp_entry; | |
5025 | + int counting; | |
5026 | + | |
5027 | + DEBUG(10,("Entering the sys_acl_create_entry\n")); | |
5028 | + | |
5029 | + theacl = acl_entryp = *pacl; | |
5030 | + | |
5031 | + /* Get to the end of the acl before adding entry */ | |
5032 | + | |
0f6733d8 | 5033 | + for(counting=0; counting < theacl->count; counting++){ |
fa26e11c WD |
5034 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); |
5035 | + temp_entry = acl_entryp; | |
5036 | + acl_entryp = acl_entryp->nextp; | |
5037 | + } | |
5038 | + | |
0f6733d8 | 5039 | + if(theacl->count != 0){ |
252945ef | 5040 | + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 5041 | + if(acl_entryp == NULL) { |
fa26e11c WD |
5042 | + errno = ENOMEM; |
5043 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); | |
0f6733d8 | 5044 | + return(-1); |
fa26e11c WD |
5045 | + } |
5046 | + | |
5047 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); | |
5048 | + acl_entryp->prevp = temp_entry; | |
5049 | + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp)); | |
5050 | + } | |
5051 | + | |
252945ef | 5052 | + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 | 5053 | + if(*pentry == NULL) { |
fa26e11c WD |
5054 | + errno = ENOMEM; |
5055 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); | |
0f6733d8 | 5056 | + return(-1); |
fa26e11c WD |
5057 | + } |
5058 | + | |
0f6733d8 WD |
5059 | + memset(*pentry,0,sizeof(struct new_acl_entry)); |
5060 | + acl_entryp->entryp->ace_len = sizeof(struct acl_entry); | |
fa26e11c | 5061 | + acl_entryp->entryp->ace_type = ACC_PERMIT; |
0f6733d8 | 5062 | + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id); |
fa26e11c WD |
5063 | + acl_entryp->nextp = NULL; |
5064 | + theacl->count++; | |
5065 | + DEBUG(10,("Exiting sys_acl_create_entry\n")); | |
0f6733d8 | 5066 | + return(0); |
fa26e11c WD |
5067 | +} |
5068 | + | |
0f6733d8 | 5069 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
5070 | +{ |
5071 | + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n")); | |
5072 | + entry->ace_id->id_type = tagtype; | |
5073 | + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type)); | |
5074 | + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n")); | |
5075 | +} | |
5076 | + | |
0f6733d8 | 5077 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
5078 | +{ |
5079 | + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n")); | |
0f6733d8 | 5080 | + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t)); |
fa26e11c | 5081 | + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n")); |
0f6733d8 | 5082 | + return(0); |
fa26e11c WD |
5083 | +} |
5084 | + | |
0f6733d8 | 5085 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
5086 | +{ |
5087 | + DEBUG(10,("Starting AIX sys_acl_set_permset\n")); | |
0f6733d8 WD |
5088 | + if(!(*permset & S_IXUSR) && |
5089 | + !(*permset & S_IWUSR) && | |
5090 | + !(*permset & S_IRUSR) && | |
5091 | + (*permset != 0)) | |
5092 | + return(-1); | |
fa26e11c WD |
5093 | + |
5094 | + entry->ace_access = *permset; | |
5095 | + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access)); | |
5096 | + DEBUG(10,("Ending AIX sys_acl_set_permset\n")); | |
0f6733d8 | 5097 | + return(0); |
fa26e11c WD |
5098 | +} |
5099 | + | |
0f6733d8 | 5100 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c WD |
5101 | +{ |
5102 | + int user_obj = 0; | |
5103 | + int group_obj = 0; | |
5104 | + int other_obj = 0; | |
5105 | + struct acl_entry_link *acl_entry; | |
5106 | + | |
0f6733d8 | 5107 | + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) { |
fa26e11c WD |
5108 | + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ); |
5109 | + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ); | |
5110 | + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER); | |
5111 | + } | |
5112 | + | |
5113 | + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj)); | |
0f6733d8 WD |
5114 | + |
5115 | + if(user_obj != 1 || group_obj != 1 || other_obj != 1) | |
5116 | + return(-1); | |
fa26e11c | 5117 | + |
0f6733d8 | 5118 | + return(0); |
fa26e11c WD |
5119 | +} |
5120 | + | |
0f6733d8 | 5121 | +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
fa26e11c WD |
5122 | +{ |
5123 | + struct acl_entry_link *acl_entry_link = NULL; | |
5124 | + struct acl *file_acl = NULL; | |
5125 | + struct acl *file_acl_temp = NULL; | |
5126 | + struct acl_entry *acl_entry = NULL; | |
5127 | + struct ace_id *ace_id = NULL; | |
5128 | + uint id_type; | |
5129 | + uint ace_access; | |
5130 | + uint user_id; | |
5131 | + uint acl_length; | |
5132 | + uint rc; | |
5133 | + | |
5134 | + DEBUG(10,("Entering sys_acl_set_file\n")); | |
5135 | + DEBUG(10,("File name is %s\n",name)); | |
0f6733d8 | 5136 | + |
fa26e11c | 5137 | + /* AIX has no default ACL */ |
0f6733d8 WD |
5138 | + if(acltype == SMB_ACL_TYPE_DEFAULT) |
5139 | + return(0); | |
fa26e11c WD |
5140 | + |
5141 | + acl_length = BUFSIZ; | |
252945ef | 5142 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 5143 | + |
0f6733d8 | 5144 | + if(file_acl == NULL) { |
fa26e11c WD |
5145 | + errno = ENOMEM; |
5146 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); | |
0f6733d8 | 5147 | + return(-1); |
fa26e11c WD |
5148 | + } |
5149 | + | |
5150 | + memset(file_acl,0,BUFSIZ); | |
5151 | + | |
5152 | + file_acl->acl_len = ACL_SIZ; | |
5153 | + file_acl->acl_mode = S_IXACL; | |
5154 | + | |
0f6733d8 | 5155 | + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
fa26e11c WD |
5156 | + acl_entry_link->entryp->ace_access >>= 6; |
5157 | + id_type = acl_entry_link->entryp->ace_id->id_type; | |
5158 | + | |
0f6733d8 | 5159 | + switch(id_type) { |
fa26e11c WD |
5160 | + case SMB_ACL_USER_OBJ: |
5161 | + file_acl->u_access = acl_entry_link->entryp->ace_access; | |
5162 | + continue; | |
5163 | + case SMB_ACL_GROUP_OBJ: | |
5164 | + file_acl->g_access = acl_entry_link->entryp->ace_access; | |
5165 | + continue; | |
5166 | + case SMB_ACL_OTHER: | |
5167 | + file_acl->o_access = acl_entry_link->entryp->ace_access; | |
5168 | + continue; | |
5169 | + case SMB_ACL_MASK: | |
5170 | + continue; | |
5171 | + } | |
5172 | + | |
0f6733d8 WD |
5173 | + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { |
5174 | + acl_length += sizeof(struct acl_entry); | |
252945ef | 5175 | + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
0f6733d8 WD |
5176 | + if(file_acl_temp == NULL) { |
5177 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
5178 | + errno = ENOMEM; |
5179 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); | |
0f6733d8 WD |
5180 | + return(-1); |
5181 | + } | |
fa26e11c WD |
5182 | + |
5183 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); | |
0f6733d8 | 5184 | + SAFE_FREE(file_acl); |
fa26e11c WD |
5185 | + file_acl = file_acl_temp; |
5186 | + } | |
5187 | + | |
5188 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); | |
0f6733d8 | 5189 | + file_acl->acl_len += sizeof(struct acl_entry); |
fa26e11c WD |
5190 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
5191 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; | |
0f6733d8 | 5192 | + |
fa26e11c | 5193 | + /* In order to use this, we'll need to wait until we can get denies */ |
0f6733d8 WD |
5194 | + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) |
5195 | + acl_entry->ace_type = ACC_SPECIFY; */ | |
fa26e11c WD |
5196 | + |
5197 | + acl_entry->ace_type = ACC_SPECIFY; | |
0f6733d8 | 5198 | + |
fa26e11c | 5199 | + ace_id = acl_entry->ace_id; |
0f6733d8 | 5200 | + |
fa26e11c WD |
5201 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
5202 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); | |
5203 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; | |
0f6733d8 WD |
5204 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t)); |
5205 | + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t)); | |
fa26e11c WD |
5206 | + } |
5207 | + | |
0f6733d8 | 5208 | + rc = chacl(name,file_acl,file_acl->acl_len); |
fa26e11c WD |
5209 | + DEBUG(10,("errno is %d\n",errno)); |
5210 | + DEBUG(10,("return code is %d\n",rc)); | |
0f6733d8 | 5211 | + SAFE_FREE(file_acl); |
fa26e11c | 5212 | + DEBUG(10,("Exiting the sys_acl_set_file\n")); |
0f6733d8 | 5213 | + return(rc); |
fa26e11c WD |
5214 | +} |
5215 | + | |
0f6733d8 | 5216 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
5217 | +{ |
5218 | + struct acl_entry_link *acl_entry_link = NULL; | |
5219 | + struct acl *file_acl = NULL; | |
5220 | + struct acl *file_acl_temp = NULL; | |
5221 | + struct acl_entry *acl_entry = NULL; | |
5222 | + struct ace_id *ace_id = NULL; | |
5223 | + uint id_type; | |
5224 | + uint user_id; | |
5225 | + uint acl_length; | |
5226 | + uint rc; | |
0f6733d8 | 5227 | + |
fa26e11c WD |
5228 | + DEBUG(10,("Entering sys_acl_set_fd\n")); |
5229 | + acl_length = BUFSIZ; | |
252945ef | 5230 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 5231 | + |
0f6733d8 | 5232 | + if(file_acl == NULL) { |
fa26e11c WD |
5233 | + errno = ENOMEM; |
5234 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); | |
0f6733d8 | 5235 | + return(-1); |
fa26e11c WD |
5236 | + } |
5237 | + | |
5238 | + memset(file_acl,0,BUFSIZ); | |
0f6733d8 | 5239 | + |
fa26e11c WD |
5240 | + file_acl->acl_len = ACL_SIZ; |
5241 | + file_acl->acl_mode = S_IXACL; | |
5242 | + | |
0f6733d8 | 5243 | + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
fa26e11c WD |
5244 | + acl_entry_link->entryp->ace_access >>= 6; |
5245 | + id_type = acl_entry_link->entryp->ace_id->id_type; | |
5246 | + DEBUG(10,("The id_type is %d\n",id_type)); | |
5247 | + | |
0f6733d8 | 5248 | + switch(id_type) { |
fa26e11c WD |
5249 | + case SMB_ACL_USER_OBJ: |
5250 | + file_acl->u_access = acl_entry_link->entryp->ace_access; | |
5251 | + continue; | |
5252 | + case SMB_ACL_GROUP_OBJ: | |
5253 | + file_acl->g_access = acl_entry_link->entryp->ace_access; | |
5254 | + continue; | |
5255 | + case SMB_ACL_OTHER: | |
5256 | + file_acl->o_access = acl_entry_link->entryp->ace_access; | |
5257 | + continue; | |
5258 | + case SMB_ACL_MASK: | |
5259 | + continue; | |
5260 | + } | |
5261 | + | |
0f6733d8 WD |
5262 | + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { |
5263 | + acl_length += sizeof(struct acl_entry); | |
252945ef | 5264 | + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
0f6733d8 WD |
5265 | + if(file_acl_temp == NULL) { |
5266 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
5267 | + errno = ENOMEM; |
5268 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); | |
0f6733d8 | 5269 | + return(-1); |
fa26e11c WD |
5270 | + } |
5271 | + | |
5272 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); | |
0f6733d8 | 5273 | + SAFE_FREE(file_acl); |
fa26e11c WD |
5274 | + file_acl = file_acl_temp; |
5275 | + } | |
5276 | + | |
5277 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); | |
0f6733d8 | 5278 | + file_acl->acl_len += sizeof(struct acl_entry); |
fa26e11c WD |
5279 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
5280 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; | |
0f6733d8 | 5281 | + |
fa26e11c | 5282 | + /* In order to use this, we'll need to wait until we can get denies */ |
0f6733d8 | 5283 | + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) |
fa26e11c | 5284 | + acl_entry->ace_type = ACC_SPECIFY; */ |
0f6733d8 | 5285 | + |
fa26e11c | 5286 | + acl_entry->ace_type = ACC_SPECIFY; |
0f6733d8 | 5287 | + |
fa26e11c | 5288 | + ace_id = acl_entry->ace_id; |
0f6733d8 | 5289 | + |
fa26e11c WD |
5290 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
5291 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); | |
5292 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; | |
0f6733d8 WD |
5293 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t)); |
5294 | + memcpy(ace_id->id_data, &user_id, sizeof(uid_t)); | |
fa26e11c | 5295 | + } |
0f6733d8 | 5296 | + |
fa26e11c WD |
5297 | + rc = fchacl(fd,file_acl,file_acl->acl_len); |
5298 | + DEBUG(10,("errno is %d\n",errno)); | |
5299 | + DEBUG(10,("return code is %d\n",rc)); | |
0f6733d8 | 5300 | + SAFE_FREE(file_acl); |
fa26e11c | 5301 | + DEBUG(10,("Exiting sys_acl_set_fd\n")); |
0f6733d8 | 5302 | + return(rc); |
fa26e11c WD |
5303 | +} |
5304 | + | |
0f6733d8 | 5305 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
5306 | +{ |
5307 | + /* AIX has no default ACL */ | |
5308 | + return 0; | |
5309 | +} | |
5310 | + | |
0f6733d8 | 5311 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 5312 | +{ |
0f6733d8 | 5313 | + return(*permset & perm); |
fa26e11c WD |
5314 | +} |
5315 | + | |
0f6733d8 | 5316 | +int sys_acl_free_text(char *text) |
fa26e11c | 5317 | +{ |
0f6733d8 | 5318 | + return(0); |
fa26e11c WD |
5319 | +} |
5320 | + | |
0f6733d8 | 5321 | +int sys_acl_free_acl(SMB_ACL_T posix_acl) |
fa26e11c WD |
5322 | +{ |
5323 | + struct acl_entry_link *acl_entry_link; | |
5324 | + | |
0f6733d8 WD |
5325 | + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) { |
5326 | + SAFE_FREE(acl_entry_link->prevp->entryp); | |
5327 | + SAFE_FREE(acl_entry_link->prevp); | |
fa26e11c WD |
5328 | + } |
5329 | + | |
0f6733d8 WD |
5330 | + SAFE_FREE(acl_entry_link->prevp->entryp); |
5331 | + SAFE_FREE(acl_entry_link->prevp); | |
5332 | + SAFE_FREE(acl_entry_link->entryp); | |
5333 | + SAFE_FREE(acl_entry_link); | |
5334 | + | |
5335 | + return(0); | |
fa26e11c WD |
5336 | +} |
5337 | + | |
0f6733d8 | 5338 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c | 5339 | +{ |
0f6733d8 | 5340 | + return(0); |
fa26e11c WD |
5341 | +} |
5342 | + | |
5343 | +#else /* No ACLs. */ | |
5344 | + | |
4df546eb | 5345 | +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p)) |
fa26e11c WD |
5346 | +{ |
5347 | + errno = ENOSYS; | |
5348 | + return -1; | |
5349 | +} | |
5350 | + | |
4df546eb | 5351 | +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p)) |
fa26e11c WD |
5352 | +{ |
5353 | + errno = ENOSYS; | |
5354 | + return -1; | |
5355 | +} | |
5356 | + | |
4df546eb | 5357 | +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p)) |
fa26e11c WD |
5358 | +{ |
5359 | + errno = ENOSYS; | |
5360 | + return -1; | |
5361 | +} | |
5362 | + | |
4df546eb | 5363 | +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d)) |
fa26e11c WD |
5364 | +{ |
5365 | + errno = ENOSYS; | |
5366 | + return NULL; | |
5367 | +} | |
5368 | + | |
4df546eb | 5369 | +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type)) |
fa26e11c WD |
5370 | +{ |
5371 | + errno = ENOSYS; | |
5ca9317d | 5372 | + return (SMB_ACL_T)NULL; |
fa26e11c WD |
5373 | +} |
5374 | + | |
4df546eb | 5375 | +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd)) |
fa26e11c WD |
5376 | +{ |
5377 | + errno = ENOSYS; | |
5ca9317d | 5378 | + return (SMB_ACL_T)NULL; |
fa26e11c WD |
5379 | +} |
5380 | + | |
4df546eb | 5381 | +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset)) |
fa26e11c WD |
5382 | +{ |
5383 | + errno = ENOSYS; | |
5384 | + return -1; | |
5385 | +} | |
5386 | + | |
4df546eb | 5387 | +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm)) |
fa26e11c WD |
5388 | +{ |
5389 | + errno = ENOSYS; | |
5390 | + return -1; | |
5391 | +} | |
5392 | + | |
0f6733d8 | 5393 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
5394 | +{ |
5395 | + errno = ENOSYS; | |
0f6733d8 | 5396 | + return (permset & perm) ? 1 : 0; |
fa26e11c WD |
5397 | +} |
5398 | + | |
4df546eb | 5399 | +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen)) |
fa26e11c WD |
5400 | +{ |
5401 | + errno = ENOSYS; | |
5402 | + return NULL; | |
5403 | +} | |
5404 | + | |
4df546eb | 5405 | +int sys_acl_free_text(UNUSED(char *text)) |
fa26e11c WD |
5406 | +{ |
5407 | + errno = ENOSYS; | |
5408 | + return -1; | |
5409 | +} | |
5410 | + | |
4df546eb | 5411 | +SMB_ACL_T sys_acl_init(UNUSED(int count)) |
fa26e11c WD |
5412 | +{ |
5413 | + errno = ENOSYS; | |
5414 | + return NULL; | |
5415 | +} | |
5416 | + | |
4df546eb | 5417 | +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry)) |
fa26e11c WD |
5418 | +{ |
5419 | + errno = ENOSYS; | |
5420 | + return -1; | |
5421 | +} | |
5422 | + | |
4df546eb | 5423 | +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
5424 | +{ |
5425 | + errno = ENOSYS; | |
5426 | + return -1; | |
5427 | +} | |
5428 | + | |
4df546eb | 5429 | +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual)) |
fa26e11c WD |
5430 | +{ |
5431 | + errno = ENOSYS; | |
5432 | + return -1; | |
5433 | +} | |
5434 | + | |
4df546eb | 5435 | +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset)) |
fa26e11c WD |
5436 | +{ |
5437 | + errno = ENOSYS; | |
5438 | + return -1; | |
5439 | +} | |
5440 | + | |
4df546eb | 5441 | +int sys_acl_valid(UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
5442 | +{ |
5443 | + errno = ENOSYS; | |
5444 | + return -1; | |
5445 | +} | |
5446 | + | |
4df546eb | 5447 | +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
5448 | +{ |
5449 | + errno = ENOSYS; | |
5450 | + return -1; | |
5451 | +} | |
5452 | + | |
4df546eb | 5453 | +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
5454 | +{ |
5455 | + errno = ENOSYS; | |
5456 | + return -1; | |
5457 | +} | |
5458 | + | |
4df546eb | 5459 | +int sys_acl_delete_def_file(UNUSED(const char *name)) |
fa26e11c WD |
5460 | +{ |
5461 | + errno = ENOSYS; | |
5462 | + return -1; | |
5463 | +} | |
5464 | + | |
4df546eb | 5465 | +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl)) |
fa26e11c WD |
5466 | +{ |
5467 | + errno = ENOSYS; | |
5468 | + return -1; | |
5469 | +} | |
5470 | + | |
4df546eb | 5471 | +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
5472 | +{ |
5473 | + errno = ENOSYS; | |
5474 | + return -1; | |
5475 | +} | |
5476 | + | |
5477 | +#endif /* No ACLs. */ | |
252945ef WD |
5478 | + |
5479 | +/************************************************************************ | |
5480 | + Deliberately outside the ACL defines. Return 1 if this is a "no acls" | |
5481 | + errno, 0 if not. | |
5482 | +************************************************************************/ | |
5483 | + | |
5484 | +int no_acl_syscall_error(int err) | |
5485 | +{ | |
5486 | +#if defined(ENOSYS) | |
5487 | + if (err == ENOSYS) { | |
5488 | + return 1; | |
5489 | + } | |
5490 | +#endif | |
5491 | +#if defined(ENOTSUP) | |
5492 | + if (err == ENOTSUP) { | |
5493 | + return 1; | |
5494 | + } | |
5495 | +#endif | |
5496 | + return 0; | |
5497 | +} | |
131abbd3 WD |
5498 | + |
5499 | +#endif /* SUPPORT_ACLS */ | |
9a7eef96 WD |
5500 | --- old/lib/sysacls.h |
5501 | +++ new/lib/sysacls.h | |
131abbd3 WD |
5502 | @@ -0,0 +1,40 @@ |
5503 | +#ifdef SUPPORT_ACLS | |
5504 | + | |
5505 | +#ifdef HAVE_SYS_ACL_H | |
a35da1c7 WD |
5506 | +#include <sys/acl.h> |
5507 | +#endif | |
0909ae28 WD |
5508 | +#ifdef HAVE_ACL_LIBACL_H |
5509 | +#include <acl/libacl.h> | |
5510 | +#endif | |
a35da1c7 WD |
5511 | +#include "smb_acls.h" |
5512 | + | |
252945ef WD |
5513 | +#define SMB_MALLOC(cnt) new_array(char, cnt) |
5514 | +#define SMB_MALLOC_P(obj) new_array(obj, 1) | |
5515 | +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt) | |
5516 | +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt) | |
5ca9317d | 5517 | +#define slprintf snprintf |
0f6733d8 WD |
5518 | + |
5519 | +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p); | |
5520 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p); | |
5521 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p); | |
5522 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d); | |
5523 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type); | |
5524 | +SMB_ACL_T sys_acl_get_fd(int fd); | |
5525 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); | |
5526 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
5527 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
5528 | +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen); | |
5529 | +SMB_ACL_T sys_acl_init(int count); | |
5530 | +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry); | |
5531 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype); | |
5532 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual); | |
5533 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset); | |
5534 | +int sys_acl_valid(SMB_ACL_T theacl); | |
5535 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); | |
5536 | +int sys_acl_set_fd(int fd, SMB_ACL_T theacl); | |
5537 | +int sys_acl_delete_def_file(const char *name); | |
5538 | +int sys_acl_free_text(char *text); | |
5539 | +int sys_acl_free_acl(SMB_ACL_T the_acl); | |
5540 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype); | |
131abbd3 WD |
5541 | + |
5542 | +#endif /* SUPPORT_ACLS */ | |
0870c22a WD |
5543 | --- old/log.c |
5544 | +++ new/log.c | |
668bbc0a | 5545 | @@ -606,8 +606,10 @@ static void log_formatted(enum logcode c |
0870c22a WD |
5546 | n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p'; |
5547 | n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o'; | |
5548 | n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g'; | |
5549 | - n[8] = '.'; | |
5550 | - n[9] = '\0'; | |
5551 | + n[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u'; | |
5552 | + n[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a'; | |
5553 | + n[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x'; | |
5554 | + n[11] = '\0'; | |
5555 | ||
5556 | if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) { | |
5557 | char ch = iflags & ITEM_IS_NEW ? '+' : '?'; | |
9a7eef96 WD |
5558 | --- old/options.c |
5559 | +++ new/options.c | |
c1471566 | 5560 | @@ -47,6 +47,7 @@ int copy_dirlinks = 0; |
0f6733d8 WD |
5561 | int copy_links = 0; |
5562 | int preserve_links = 0; | |
5563 | int preserve_hard_links = 0; | |
5564 | +int preserve_acls = 0; | |
5565 | int preserve_perms = 0; | |
90fa6d68 | 5566 | int preserve_executability = 0; |
0f6733d8 | 5567 | int preserve_devices = 0; |
4959107f | 5568 | @@ -199,6 +200,7 @@ static void print_rsync_version(enum log |
0f6733d8 WD |
5569 | char const *got_socketpair = "no "; |
5570 | char const *have_inplace = "no "; | |
5571 | char const *hardlinks = "no "; | |
5572 | + char const *acls = "no "; | |
5573 | char const *links = "no "; | |
5574 | char const *ipv6 = "no "; | |
5575 | STRUCT_STAT *dumstat; | |
4959107f | 5576 | @@ -215,6 +217,10 @@ static void print_rsync_version(enum log |
0f6733d8 WD |
5577 | hardlinks = ""; |
5578 | #endif | |
5579 | ||
09fb8f03 | 5580 | +#ifdef SUPPORT_ACLS |
0f6733d8 WD |
5581 | + acls = ""; |
5582 | +#endif | |
5583 | + | |
09fb8f03 | 5584 | #ifdef SUPPORT_LINKS |
0f6733d8 WD |
5585 | links = ""; |
5586 | #endif | |
131abbd3 WD |
5587 | @@ -227,17 +233,16 @@ static void print_rsync_version(enum log |
5588 | RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION); | |
3b05e91f | 5589 | rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n"); |
0f6733d8 | 5590 | rprintf(f, "<http://rsync.samba.org/>\n"); |
131abbd3 | 5591 | - rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, " |
bc5988ec | 5592 | - "%shard links, %ssymlinks, batchfiles,\n", |
131abbd3 | 5593 | - (int) (sizeof (OFF_T) * 8), |
0f6733d8 | 5594 | - got_socketpair, hardlinks, links); |
131abbd3 WD |
5595 | + rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, %shard links, %ssymlinks,\n", |
5596 | + (int) (sizeof (OFF_T) * 8), got_socketpair, hardlinks, links); | |
5597 | + | |
5598 | + rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs,\n", | |
5599 | + have_inplace, ipv6, acls); | |
0f6733d8 WD |
5600 | |
5601 | /* Note that this field may not have type ino_t. It depends | |
5602 | * on the complicated interaction between largefile feature | |
131abbd3 WD |
5603 | * macros. */ |
5604 | - rprintf(f, " %sinplace, %sIPv6, " | |
5605 | - "%d-bit system inums, %d-bit internal inums\n", | |
5606 | - have_inplace, ipv6, | |
5607 | + rprintf(f, " %d-bit system inums, %d-bit internal inums\n", | |
5608 | (int) (sizeof dumstat->st_ino * 8), | |
5609 | (int) (sizeof (int64) * 8)); | |
5610 | #ifdef MAINTAINER_MODE | |
5611 | @@ -284,7 +289,7 @@ void usage(enum logcode F) | |
5a9d3244 | 5612 | rprintf(F," -q, --quiet suppress non-error messages\n"); |
4959107f | 5613 | rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n"); |
5a9d3244 WD |
5614 | rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n"); |
5615 | - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n"); | |
5616 | + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n"); | |
5617 | rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n"); | |
5618 | rprintf(F," -r, --recursive recurse into directories\n"); | |
5619 | rprintf(F," -R, --relative use relative path names\n"); | |
131abbd3 | 5620 | @@ -306,6 +311,9 @@ void usage(enum logcode F) |
0f6733d8 | 5621 | rprintf(F," -p, --perms preserve permissions\n"); |
90fa6d68 | 5622 | rprintf(F," -E, --executability preserve the file's executability\n"); |
063cf77b | 5623 | rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n"); |
25d385b9 | 5624 | +#ifdef SUPPORT_ACLS |
0f6733d8 | 5625 | + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n"); |
25d385b9 | 5626 | +#endif |
90fa6d68 | 5627 | rprintf(F," -o, --owner preserve owner (super-user only)\n"); |
0f6733d8 | 5628 | rprintf(F," -g, --group preserve group\n"); |
1ed0b5c9 | 5629 | rprintf(F," --devices preserve device files (super-user only)\n"); |
131abbd3 | 5630 | @@ -425,6 +433,9 @@ static struct poptOption long_options[] |
489b0a72 WD |
5631 | {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, |
5632 | {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
90fa6d68 | 5633 | {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 }, |
489b0a72 WD |
5634 | + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
5635 | + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
5636 | + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
5637 | {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 }, | |
5638 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
5639 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
131abbd3 | 5640 | @@ -1089,6 +1100,24 @@ int parse_arguments(int *argc, const cha |
3b05e91f WD |
5641 | usage(FINFO); |
5642 | exit_cleanup(0); | |
0f6733d8 WD |
5643 | |
5644 | + case 'A': | |
4df546eb | 5645 | +#ifdef SUPPORT_ACLS |
a5e3a4cc WD |
5646 | + preserve_acls++; |
5647 | + preserve_perms = 1; | |
489b0a72 | 5648 | + break; |
0f6733d8 WD |
5649 | +#else |
5650 | + /* FIXME: this should probably be ignored with a | |
5651 | + * warning and then countermeasures taken to | |
5652 | + * restrict group and other access in the presence | |
5653 | + * of any more restrictive ACLs, but this is safe | |
5654 | + * for now */ | |
5655 | + snprintf(err_buf,sizeof(err_buf), | |
5656 | + "ACLs are not supported on this %s\n", | |
5657 | + am_server ? "server" : "client"); | |
5658 | + return 0; | |
25d385b9 | 5659 | +#endif |
0f6733d8 WD |
5660 | + |
5661 | + | |
5662 | default: | |
5663 | /* A large opt value means that set_refuse_options() | |
27a7053c | 5664 | * turned this option off. */ |
131abbd3 | 5665 | @@ -1530,6 +1559,10 @@ void server_options(char **args,int *arg |
c7bc7375 | 5666 | |
0f6733d8 WD |
5667 | if (preserve_hard_links) |
5668 | argstr[x++] = 'H'; | |
25d385b9 | 5669 | +#ifdef SUPPORT_ACLS |
0f6733d8 WD |
5670 | + if (preserve_acls) |
5671 | + argstr[x++] = 'A'; | |
25d385b9 | 5672 | +#endif |
0f6733d8 WD |
5673 | if (preserve_uid) |
5674 | argstr[x++] = 'o'; | |
5675 | if (preserve_gid) | |
9a7eef96 WD |
5676 | --- old/receiver.c |
5677 | +++ new/receiver.c | |
55c1a3b7 | 5678 | @@ -47,6 +47,7 @@ extern int keep_partial; |
1a2fa68f WD |
5679 | extern int checksum_seed; |
5680 | extern int inplace; | |
5681 | extern int delay_updates; | |
5682 | +extern mode_t orig_umask; | |
5683 | extern struct stats stats; | |
a859733e | 5684 | extern char *stdout_format; |
1a2fa68f | 5685 | extern char *tmpdir; |
3758a5a5 | 5686 | @@ -350,6 +351,10 @@ int recv_files(int f_in, struct file_lis |
a859733e WD |
5687 | int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i; |
5688 | enum logcode log_code = log_before_transfer ? FLOG : FINFO; | |
26c810d8 WD |
5689 | int max_phase = protocol_version >= 29 ? 2 : 1; |
5690 | + int dflt_perms = (ACCESSPERMS & ~orig_umask); | |
5c8b4e6e | 5691 | +#ifdef SUPPORT_ACLS |
26c810d8 | 5692 | + char *parent_dirname = ""; |
5c8b4e6e | 5693 | +#endif |
26c810d8 WD |
5694 | int i, recv_ok; |
5695 | ||
5696 | if (verbose > 2) | |
3758a5a5 | 5697 | @@ -553,7 +558,16 @@ int recv_files(int f_in, struct file_lis |
90fa6d68 WD |
5698 | * mode based on the local permissions and some heuristics. */ |
5699 | if (!preserve_perms) { | |
5700 | int exists = fd1 != -1; | |
5701 | - file->mode = dest_mode(file->mode, st.st_mode, exists); | |
26c810d8 | 5702 | +#ifdef SUPPORT_ACLS |
5c8b4e6e WD |
5703 | + char *dn = file->dirname ? file->dirname : "."; |
5704 | + if (parent_dirname != dn | |
5705 | + && strcmp(parent_dirname, dn) != 0) { | |
5706 | + dflt_perms = default_perms_for_dir(dn); | |
5707 | + parent_dirname = dn; | |
26c810d8 WD |
5708 | + } |
5709 | +#endif | |
5710 | + file->mode = dest_mode(file->mode, st.st_mode, | |
5711 | + dflt_perms, exists); | |
90fa6d68 WD |
5712 | } |
5713 | ||
bdf1eee8 | 5714 | /* We now check to see if we are writing the file "inplace" */ |
9a7eef96 WD |
5715 | --- old/rsync.c |
5716 | +++ new/rsync.c | |
74eccbb1 WD |
5717 | @@ -32,6 +32,7 @@ |
5718 | ||
162234a7 WD |
5719 | extern int verbose; |
5720 | extern int dry_run; | |
162234a7 WD |
5721 | +extern int preserve_acls; |
5722 | extern int preserve_perms; | |
5723 | extern int preserve_executability; | |
5724 | extern int preserve_times; | |
78b1089b WD |
5725 | @@ -47,7 +48,6 @@ extern int preserve_gid; |
5726 | extern int inplace; | |
5727 | extern int keep_dirlinks; | |
5728 | extern int make_backups; | |
5729 | -extern mode_t orig_umask; | |
5730 | extern struct stats stats; | |
5731 | extern struct chmod_mode_struct *daemon_chmod_modes; | |
5732 | ||
5733 | @@ -100,7 +100,8 @@ void free_sums(struct sum_struct *s) | |
90fa6d68 WD |
5734 | |
5735 | /* This is only called when we aren't preserving permissions. Figure out what | |
5736 | * the permissions should be and return them merged back into the mode. */ | |
bdf1eee8 WD |
5737 | -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists) |
5738 | +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms, | |
26c810d8 | 5739 | + int exists) |
90fa6d68 | 5740 | { |
bdf1eee8 | 5741 | int new_mode; |
25d385b9 | 5742 | /* If the file already exists, we'll return the local permissions, |
78b1089b | 5743 | @@ -117,56 +118,65 @@ mode_t dest_mode(mode_t flist_mode, mode |
bdf1eee8 | 5744 | new_mode |= (new_mode & 0444) >> 2; |
90fa6d68 | 5745 | } |
bdf1eee8 WD |
5746 | } else { |
5747 | - /* Apply the umask and turn off special permissions. */ | |
5748 | - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask)); | |
5749 | + /* Apply destination default permissions and turn | |
5750 | + * off special permissions. */ | |
5751 | + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms); | |
5752 | } | |
bdf1eee8 | 5753 | return new_mode; |
0870c22a WD |
5754 | } |
5755 | ||
5756 | -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st, | |
5757 | +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp, | |
5758 | int flags) | |
5759 | { | |
5760 | int updated = 0; | |
5761 | - STRUCT_STAT st2; | |
5762 | + statx sx2; | |
5763 | int change_uid, change_gid; | |
1ed0b5c9 | 5764 | mode_t new_mode = file->mode; |
0870c22a WD |
5765 | |
5766 | - if (!st) { | |
5767 | + if (!sxp) { | |
5768 | if (dry_run) | |
5769 | return 1; | |
5770 | - if (link_stat(fname, &st2, 0) < 0) { | |
5771 | + if (link_stat(fname, &sx2.st, 0) < 0) { | |
5772 | rsyserr(FERROR, errno, "stat %s failed", | |
5773 | full_fname(fname)); | |
5774 | return 0; | |
5775 | } | |
5776 | - st = &st2; | |
5777 | +#ifdef SUPPORT_ACLS | |
5778 | + sx2.acc_acl = sx2.def_acl = NULL; | |
5779 | +#endif | |
1ed0b5c9 | 5780 | if (!preserve_perms && S_ISDIR(new_mode) |
0870c22a WD |
5781 | - && st->st_mode & S_ISGID) { |
5782 | + && sx2.st.st_mode & S_ISGID) { | |
5783 | /* We just created this directory and its setgid | |
5784 | * bit is on, so make sure it stays on. */ | |
1ed0b5c9 | 5785 | new_mode |= S_ISGID; |
0870c22a WD |
5786 | } |
5787 | + sxp = &sx2; | |
5788 | } | |
5789 | ||
5790 | - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times)) | |
5791 | +#ifdef SUPPORT_ACLS | |
5792 | + if (preserve_acls && !ACL_READY(*sxp)) | |
98ccc74a | 5793 | + get_acl(fname, sxp); |
0870c22a WD |
5794 | +#endif |
5795 | + | |
5796 | + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times)) | |
5797 | flags |= ATTRS_SKIP_MTIME; | |
5798 | if (!(flags & ATTRS_SKIP_MTIME) | |
5799 | - && cmp_time(st->st_mtime, file->modtime) != 0) { | |
5800 | - int ret = set_modtime(fname, file->modtime, st->st_mode); | |
5801 | + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) { | |
5802 | + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode); | |
5803 | if (ret < 0) { | |
5804 | rsyserr(FERROR, errno, "failed to set times on %s", | |
5805 | full_fname(fname)); | |
5806 | - return 0; | |
5807 | + goto cleanup; | |
5808 | } | |
5809 | if (ret == 0) /* ret == 1 if symlink could not be set */ | |
5810 | updated = 1; | |
5811 | } | |
5812 | ||
5813 | - change_uid = am_root && preserve_uid && st->st_uid != file->uid; | |
5814 | + change_uid = am_root && preserve_uid && sxp->st.st_uid != file->uid; | |
5815 | change_gid = preserve_gid && file->gid != GID_NONE | |
5816 | - && st->st_gid != file->gid; | |
5817 | + && sxp->st.st_gid != file->gid; | |
5818 | #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK | |
5819 | - if (S_ISLNK(st->st_mode)) | |
5820 | + if (S_ISLNK(sxp->st.st_mode)) | |
5821 | ; | |
5822 | else | |
5823 | #endif | |
78b1089b | 5824 | @@ -176,45 +186,57 @@ int set_file_attrs(char *fname, struct f |
0870c22a WD |
5825 | rprintf(FINFO, |
5826 | "set uid of %s from %ld to %ld\n", | |
5827 | fname, | |
5828 | - (long)st->st_uid, (long)file->uid); | |
5829 | + (long)sxp->st.st_uid, (long)file->uid); | |
5830 | } | |
5831 | if (change_gid) { | |
5832 | rprintf(FINFO, | |
5833 | "set gid of %s from %ld to %ld\n", | |
5834 | fname, | |
5835 | - (long)st->st_gid, (long)file->gid); | |
5836 | + (long)sxp->st.st_gid, (long)file->gid); | |
5837 | } | |
5838 | } | |
5839 | if (do_lchown(fname, | |
5840 | - change_uid ? file->uid : st->st_uid, | |
5841 | - change_gid ? file->gid : st->st_gid) != 0) { | |
5842 | + change_uid ? file->uid : sxp->st.st_uid, | |
5843 | + change_gid ? file->gid : sxp->st.st_gid) != 0) { | |
5844 | /* shouldn't have attempted to change uid or gid | |
5845 | * unless have the privilege */ | |
5846 | rsyserr(FERROR, errno, "%s %s failed", | |
5847 | change_uid ? "chown" : "chgrp", | |
5848 | full_fname(fname)); | |
5849 | - return 0; | |
5850 | + goto cleanup; | |
5851 | } | |
5852 | /* a lchown had been done - we have to re-stat if the | |
5853 | * destination had the setuid or setgid bits set due | |
5854 | * to the side effect of the chown call */ | |
5855 | - if (st->st_mode & (S_ISUID | S_ISGID)) { | |
5856 | - link_stat(fname, st, | |
5857 | - keep_dirlinks && S_ISDIR(st->st_mode)); | |
5858 | + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) { | |
5859 | + link_stat(fname, &sxp->st, | |
5860 | + keep_dirlinks && S_ISDIR(sxp->st.st_mode)); | |
5861 | } | |
c6437996 WD |
5862 | updated = 1; |
5863 | } | |
34a409bc | 5864 | |
1ed0b5c9 WD |
5865 | if (daemon_chmod_modes && !S_ISLNK(new_mode)) |
5866 | new_mode = tweak_mode(new_mode, daemon_chmod_modes); | |
5867 | + | |
c6437996 | 5868 | +#ifdef SUPPORT_ACLS |
98ccc74a | 5869 | + /* It's OK to call set_acl() now, even for a dir, as the generator |
c6437996 WD |
5870 | + * will enable owner-writability using chmod, if necessary. |
5871 | + * | |
98ccc74a | 5872 | + * If set_acl() changes permission bits in the process of setting |
0870c22a | 5873 | + * an access ACL, it changes sxp->st.st_mode so we know whether we |
98ccc74a WD |
5874 | + * need to chmod(). */ |
5875 | + if (preserve_acls && set_acl(fname, file, sxp) == 0) | |
c6437996 WD |
5876 | + updated = 1; |
5877 | +#endif | |
5878 | + | |
34a409bc | 5879 | #ifdef HAVE_CHMOD |
1ed0b5c9 WD |
5880 | - if ((st->st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) { |
5881 | + if ((sxp->st.st_mode & CHMOD_BITS) != (new_mode & CHMOD_BITS)) { | |
5882 | int ret = do_chmod(fname, new_mode); | |
0870c22a WD |
5883 | if (ret < 0) { |
5884 | rsyserr(FERROR, errno, | |
5885 | "failed to set permissions on %s", | |
5886 | full_fname(fname)); | |
5887 | - return 0; | |
5888 | + goto cleanup; | |
5889 | } | |
5890 | if (ret == 0) /* ret == 1 if symlink could not be set */ | |
5891 | updated = 1; | |
78b1089b | 5892 | @@ -227,6 +249,11 @@ int set_file_attrs(char *fname, struct f |
0870c22a | 5893 | else |
74eccbb1 | 5894 | rprintf(FCLIENT, "%s is uptodate\n", fname); |
0870c22a WD |
5895 | } |
5896 | + cleanup: | |
5897 | +#ifdef SUPPORT_ACLS | |
5898 | + if (preserve_acls && sxp == &sx2) | |
98ccc74a | 5899 | + free_acl(&sx2); |
0870c22a WD |
5900 | +#endif |
5901 | return updated; | |
5902 | } | |
5903 | ||
9a7eef96 WD |
5904 | --- old/rsync.h |
5905 | +++ new/rsync.h | |
131abbd3 | 5906 | @@ -492,6 +492,14 @@ struct idev { |
0870c22a WD |
5907 | #define IN_LOOPBACKNET 127 |
5908 | #endif | |
0f6733d8 | 5909 | |
131abbd3 | 5910 | +#ifndef HAVE_NO_ACLS |
4df546eb WD |
5911 | +#define SUPPORT_ACLS 1 |
5912 | +#endif | |
0f6733d8 | 5913 | + |
4df546eb WD |
5914 | +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS |
5915 | +#define ACLS_NEED_MASK 1 | |
5916 | +#endif | |
0f6733d8 | 5917 | + |
0870c22a WD |
5918 | #define GID_NONE ((gid_t)-1) |
5919 | ||
5920 | #define HL_CHECK_MASTER 0 | |
131abbd3 | 5921 | @@ -653,6 +661,17 @@ struct stats { |
6250eb3e WD |
5922 | |
5923 | struct chmod_mode_struct; | |
5924 | ||
5925 | +#define EMPTY_ITEM_LIST {NULL, 0, 0} | |
5926 | + | |
5927 | +typedef struct { | |
5928 | + void *items; | |
5929 | + size_t count; | |
5930 | + size_t malloced; | |
5931 | +} item_list; | |
5932 | + | |
645e162c WD |
5933 | +#define EXPAND_ITEM_LIST(lp, type, incr) \ |
5934 | + (type*)expand_item_list(lp, sizeof (type), #type, incr) | |
6250eb3e WD |
5935 | + |
5936 | #include "byteorder.h" | |
5937 | #include "lib/mdfour.h" | |
5938 | #include "lib/wildmatch.h" | |
131abbd3 | 5939 | @@ -669,6 +688,16 @@ struct chmod_mode_struct; |
0870c22a | 5940 | #define UNUSED(x) x __attribute__((__unused__)) |
3758a5a5 | 5941 | #define NORETURN __attribute__((__noreturn__)) |
0870c22a | 5942 | |
0870c22a WD |
5943 | +typedef struct { |
5944 | + STRUCT_STAT st; | |
5945 | +#ifdef SUPPORT_ACLS | |
5946 | + struct rsync_acl *acc_acl; /* access ACL */ | |
5947 | + struct rsync_acl *def_acl; /* default ACL */ | |
5948 | +#endif | |
5949 | +} statx; | |
5950 | + | |
5951 | +#define ACL_READY(sx) ((sx).acc_acl != NULL) | |
0f6733d8 WD |
5952 | + |
5953 | #include "proto.h" | |
5954 | ||
5955 | /* We have replacement versions of these if they're missing. */ | |
9a7eef96 WD |
5956 | --- old/rsync.yo |
5957 | +++ new/rsync.yo | |
4959107f | 5958 | @@ -301,7 +301,7 @@ to the detailed description below for a |
5a9d3244 | 5959 | -q, --quiet suppress non-error messages |
4959107f | 5960 | --no-motd suppress daemon-mode MOTD (see caveat) |
5a9d3244 WD |
5961 | -c, --checksum skip based on checksum, not mod-time & size |
5962 | - -a, --archive archive mode; same as -rlptgoD (no -H) | |
5963 | + -a, --archive archive mode; same as -rlptgoD (no -H, -A) | |
5964 | --no-OPTION turn off an implied OPTION (e.g. --no-D) | |
5965 | -r, --recursive recurse into directories | |
5966 | -R, --relative use relative path names | |
4959107f | 5967 | @@ -323,6 +323,7 @@ to the detailed description below for a |
0f6733d8 | 5968 | -p, --perms preserve permissions |
90fa6d68 | 5969 | -E, --executability preserve executability |
063cf77b | 5970 | --chmod=CHMOD affect file and/or directory permissions |
90fa6d68 | 5971 | + -A, --acls preserve ACLs (implies -p) [non-standard] |
90fa6d68 | 5972 | -o, --owner preserve owner (super-user only) |
0f6733d8 | 5973 | -g, --group preserve group |
1ed0b5c9 | 5974 | --devices preserve device files (super-user only) |
4959107f | 5975 | @@ -753,7 +754,9 @@ quote(itemization( |
90fa6d68 WD |
5976 | permissions, though the bf(--executability) option might change just |
5977 | the execute permission for the file. | |
03baf100 WD |
5978 | it() New files get their "normal" permission bits set to the source |
5979 | - file's permissions masked with the receiving end's umask setting, and | |
5980 | + file's permissions masked with the receiving directory's default | |
5981 | + permissions (either the receiving process's umask, or the permissions | |
5982 | + specified via the destination directory's default ACL), and | |
5983 | their special permission bits disabled except in the case where a new | |
5984 | directory inherits a setgid bit from its parent directory. | |
90fa6d68 | 5985 | )) |
4959107f | 5986 | @@ -784,9 +787,11 @@ The preservation of the destination's se |
03baf100 WD |
5987 | directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync |
5988 | versions erroneously preserved the three special permission bits for | |
5989 | newly-created files when bf(--perms) was off, while overriding the | |
5990 | -destination's setgid bit setting on a newly-created directory. (Keep in | |
5991 | -mind that it is the version of the receiving rsync that affects this | |
5992 | -behavior.) | |
5993 | +destination's setgid bit setting on a newly-created directory. Default ACL | |
5994 | +observance was added to the ACL patch for rsync 2.6.7, so older (or | |
5995 | +non-ACL-enabled) rsyncs use the umask even if default ACLs are present. | |
5996 | +(Keep in mind that it is the version of the receiving rsync that affects | |
5997 | +these behaviors.) | |
90fa6d68 | 5998 | |
90fa6d68 WD |
5999 | dit(bf(-E, --executability)) This option causes rsync to preserve the |
6000 | executability (or non-executability) of regular files when bf(--perms) is | |
4959107f | 6001 | @@ -804,6 +809,15 @@ quote(itemization( |
90fa6d68 WD |
6002 | |
6003 | If bf(--perms) is enabled, this option is ignored. | |
6004 | ||
6005 | +dit(bf(-A, --acls)) This option causes rsync to update the destination | |
6006 | +ACLs to be the same as the source ACLs. This nonstandard option only | |
6007 | +works if the remote rsync also supports it. bf(--acls) implies bf(--perms). | |
b57f8e02 WD |
6008 | + |
6009 | +Note also that an optimization of the ACL-sending protocol used by this | |
6010 | +version makes it incompatible with sending files to an older ACL-enabled | |
6011 | +rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This | |
6012 | +doubling is not needed when pulling files from an older rsync. | |
90fa6d68 WD |
6013 | + |
6014 | dit(bf(--chmod)) This option tells rsync to apply one or more | |
6015 | comma-separated "chmod" strings to the permission of the files in the | |
6016 | transfer. The resulting value is treated as though it was the permissions | |
4959107f | 6017 | @@ -1389,8 +1403,8 @@ if the receiving rsync is at least versi |
0870c22a WD |
6018 | with older versions of rsync, but that also turns on the output of other |
6019 | verbose messages). | |
6020 | ||
6021 | -The "%i" escape has a cryptic output that is 9 letters long. The general | |
6022 | -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the | |
6023 | +The "%i" escape has a cryptic output that is 11 letters long. The general | |
6024 | +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the | |
6025 | type of update being done, bf(X) is replaced by the file-type, and the | |
6026 | other letters represent attributes that may be output if they are being | |
6027 | modified. | |
4959107f | 6028 | @@ -1439,7 +1453,11 @@ quote(itemization( |
0870c22a WD |
6029 | sender's value (requires bf(--owner) and super-user privileges). |
6030 | it() A bf(g) means the group is different and is being updated to the | |
6031 | sender's value (requires bf(--group) and the authority to set the group). | |
6032 | - it() The bf(z) slot is reserved for future use. | |
6033 | + it() The bf(u) slot is reserved for reporting update (access) time changes | |
6034 | + (a feature that is not yet released). | |
6035 | + it() The bf(a) means that the ACL information changed. | |
6036 | + it() The bf(x) slot is reserved for reporting extended attribute changes | |
6037 | + (a feature that is not yet released). | |
6038 | )) | |
6039 | ||
6040 | One other output is possible: when deleting files, the "%i" will output | |
9a7eef96 WD |
6041 | --- old/smb_acls.h |
6042 | +++ new/smb_acls.h | |
0870c22a WD |
6043 | @@ -0,0 +1,281 @@ |
6044 | +/* | |
6045 | + Unix SMB/Netbios implementation. | |
6046 | + Version 2.2.x | |
6047 | + Portable SMB ACL interface | |
6048 | + Copyright (C) Jeremy Allison 2000 | |
6049 | + | |
6050 | + This program is free software; you can redistribute it and/or modify | |
6051 | + it under the terms of the GNU General Public License as published by | |
6052 | + the Free Software Foundation; either version 2 of the License, or | |
6053 | + (at your option) any later version. | |
6054 | + | |
6055 | + This program is distributed in the hope that it will be useful, | |
6056 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6057 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6058 | + GNU General Public License for more details. | |
6059 | + | |
6060 | + You should have received a copy of the GNU General Public License | |
6061 | + along with this program; if not, write to the Free Software | |
6062 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
6063 | +*/ | |
0f6733d8 WD |
6064 | + |
6065 | +#ifndef _SMB_ACLS_H | |
6066 | +#define _SMB_ACLS_H | |
6067 | + | |
e6a7303b | 6068 | +#if defined HAVE_POSIX_ACLS |
0f6733d8 WD |
6069 | + |
6070 | +/* This is an identity mapping (just remove the SMB_). */ | |
6071 | + | |
6072 | +#define SMB_ACL_TAG_T acl_tag_t | |
6073 | +#define SMB_ACL_TYPE_T acl_type_t | |
6074 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
6075 | +#define SMB_ACL_PERM_T acl_perm_t | |
6076 | +#define SMB_ACL_READ ACL_READ | |
6077 | +#define SMB_ACL_WRITE ACL_WRITE | |
6078 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
6079 | + | |
6080 | +/* Types of ACLs. */ | |
6081 | +#define SMB_ACL_USER ACL_USER | |
6082 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
6083 | +#define SMB_ACL_GROUP ACL_GROUP | |
6084 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
6085 | +#define SMB_ACL_OTHER ACL_OTHER | |
6086 | +#define SMB_ACL_MASK ACL_MASK | |
6087 | + | |
6088 | +#define SMB_ACL_T acl_t | |
6089 | + | |
6090 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
6091 | + | |
6092 | +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY | |
6093 | +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY | |
6094 | + | |
6095 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
6096 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
6097 | + | |
e6a7303b | 6098 | +#elif defined HAVE_TRU64_ACLS |
0f6733d8 WD |
6099 | + |
6100 | +/* This is for DEC/Compaq Tru64 UNIX */ | |
6101 | + | |
6102 | +#define SMB_ACL_TAG_T acl_tag_t | |
6103 | +#define SMB_ACL_TYPE_T acl_type_t | |
6104 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
6105 | +#define SMB_ACL_PERM_T acl_perm_t | |
6106 | +#define SMB_ACL_READ ACL_READ | |
6107 | +#define SMB_ACL_WRITE ACL_WRITE | |
6108 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
6109 | + | |
6110 | +/* Types of ACLs. */ | |
6111 | +#define SMB_ACL_USER ACL_USER | |
6112 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
6113 | +#define SMB_ACL_GROUP ACL_GROUP | |
6114 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
6115 | +#define SMB_ACL_OTHER ACL_OTHER | |
6116 | +#define SMB_ACL_MASK ACL_MASK | |
6117 | + | |
6118 | +#define SMB_ACL_T acl_t | |
6119 | + | |
6120 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
6121 | + | |
6122 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6123 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6124 | + | |
6125 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
6126 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
6127 | + | |
e6a7303b | 6128 | +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS |
0f6733d8 WD |
6129 | +/* |
6130 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
6131 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. | |
6132 | + */ | |
6133 | + | |
6134 | +/* SVR4.2 ES/MP ACLs */ | |
6135 | +typedef int SMB_ACL_TAG_T; | |
6136 | +typedef int SMB_ACL_TYPE_T; | |
6137 | +typedef ushort *SMB_ACL_PERMSET_T; | |
6138 | +typedef ushort SMB_ACL_PERM_T; | |
6139 | +#define SMB_ACL_READ 4 | |
6140 | +#define SMB_ACL_WRITE 2 | |
6141 | +#define SMB_ACL_EXECUTE 1 | |
6142 | + | |
6143 | +/* Types of ACLs. */ | |
6144 | +#define SMB_ACL_USER USER | |
6145 | +#define SMB_ACL_USER_OBJ USER_OBJ | |
6146 | +#define SMB_ACL_GROUP GROUP | |
6147 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
6148 | +#define SMB_ACL_OTHER OTHER_OBJ | |
6149 | +#define SMB_ACL_MASK CLASS_OBJ | |
6150 | + | |
6151 | +typedef struct SMB_ACL_T { | |
6152 | + int size; | |
6153 | + int count; | |
6154 | + int next; | |
6155 | + struct acl acl[1]; | |
6156 | +} *SMB_ACL_T; | |
6157 | + | |
6158 | +typedef struct acl *SMB_ACL_ENTRY_T; | |
6159 | + | |
6160 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6161 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6162 | + | |
6163 | +#define SMB_ACL_TYPE_ACCESS 0 | |
6164 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
6165 | + | |
53c1073a WD |
6166 | +#ifdef __CYGWIN__ |
6167 | +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS | |
6168 | +#endif | |
6169 | + | |
e6a7303b | 6170 | +#elif defined HAVE_HPUX_ACLS |
0f6733d8 WD |
6171 | + |
6172 | +/* | |
6173 | + * Based on the Solaris & UnixWare code. | |
6174 | + */ | |
6175 | + | |
6176 | +#undef GROUP | |
6177 | +#include <sys/aclv.h> | |
6178 | + | |
6179 | +/* SVR4.2 ES/MP ACLs */ | |
6180 | +typedef int SMB_ACL_TAG_T; | |
6181 | +typedef int SMB_ACL_TYPE_T; | |
6182 | +typedef ushort *SMB_ACL_PERMSET_T; | |
6183 | +typedef ushort SMB_ACL_PERM_T; | |
6184 | +#define SMB_ACL_READ 4 | |
6185 | +#define SMB_ACL_WRITE 2 | |
6186 | +#define SMB_ACL_EXECUTE 1 | |
6187 | + | |
6188 | +/* Types of ACLs. */ | |
6189 | +#define SMB_ACL_USER USER | |
6190 | +#define SMB_ACL_USER_OBJ USER_OBJ | |
6191 | +#define SMB_ACL_GROUP GROUP | |
6192 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
6193 | +#define SMB_ACL_OTHER OTHER_OBJ | |
6194 | +#define SMB_ACL_MASK CLASS_OBJ | |
6195 | + | |
6196 | +typedef struct SMB_ACL_T { | |
6197 | + int size; | |
6198 | + int count; | |
6199 | + int next; | |
6200 | + struct acl acl[1]; | |
6201 | +} *SMB_ACL_T; | |
6202 | + | |
6203 | +typedef struct acl *SMB_ACL_ENTRY_T; | |
6204 | + | |
6205 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6206 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6207 | + | |
6208 | +#define SMB_ACL_TYPE_ACCESS 0 | |
6209 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
6210 | + | |
e6a7303b | 6211 | +#elif defined HAVE_IRIX_ACLS |
0f6733d8 WD |
6212 | + |
6213 | +#define SMB_ACL_TAG_T acl_tag_t | |
6214 | +#define SMB_ACL_TYPE_T acl_type_t | |
6215 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
6216 | +#define SMB_ACL_PERM_T acl_perm_t | |
6217 | +#define SMB_ACL_READ ACL_READ | |
6218 | +#define SMB_ACL_WRITE ACL_WRITE | |
6219 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
6220 | + | |
6221 | +/* Types of ACLs. */ | |
6222 | +#define SMB_ACL_USER ACL_USER | |
6223 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
6224 | +#define SMB_ACL_GROUP ACL_GROUP | |
6225 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
6226 | +#define SMB_ACL_OTHER ACL_OTHER_OBJ | |
6227 | +#define SMB_ACL_MASK ACL_MASK | |
6228 | + | |
6229 | +typedef struct SMB_ACL_T { | |
6230 | + int next; | |
6231 | + BOOL freeaclp; | |
6232 | + struct acl *aclp; | |
6233 | +} *SMB_ACL_T; | |
6234 | + | |
6235 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
6236 | + | |
6237 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6238 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6239 | + | |
6240 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
6241 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
6242 | + | |
e6a7303b | 6243 | +#elif defined HAVE_AIX_ACLS |
0f6733d8 WD |
6244 | + |
6245 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
6246 | + | |
6247 | +#include "/usr/include/acl.h" | |
6248 | + | |
6249 | +typedef uint *SMB_ACL_PERMSET_T; | |
6250 | + | |
6251 | +struct acl_entry_link{ | |
6252 | + struct acl_entry_link *prevp; | |
6253 | + struct new_acl_entry *entryp; | |
6254 | + struct acl_entry_link *nextp; | |
6255 | + int count; | |
6256 | +}; | |
6257 | + | |
6258 | +struct new_acl_entry{ | |
6259 | + unsigned short ace_len; | |
6260 | + unsigned short ace_type; | |
6261 | + unsigned int ace_access; | |
6262 | + struct ace_id ace_id[1]; | |
6263 | +}; | |
6264 | + | |
6265 | +#define SMB_ACL_ENTRY_T struct new_acl_entry* | |
6266 | +#define SMB_ACL_T struct acl_entry_link* | |
6267 | + | |
6268 | +#define SMB_ACL_TAG_T unsigned short | |
6269 | +#define SMB_ACL_TYPE_T int | |
6270 | +#define SMB_ACL_PERM_T uint | |
6271 | +#define SMB_ACL_READ S_IRUSR | |
6272 | +#define SMB_ACL_WRITE S_IWUSR | |
6273 | +#define SMB_ACL_EXECUTE S_IXUSR | |
6274 | + | |
6275 | +/* Types of ACLs. */ | |
6276 | +#define SMB_ACL_USER ACEID_USER | |
6277 | +#define SMB_ACL_USER_OBJ 3 | |
6278 | +#define SMB_ACL_GROUP ACEID_GROUP | |
6279 | +#define SMB_ACL_GROUP_OBJ 4 | |
6280 | +#define SMB_ACL_OTHER 5 | |
6281 | +#define SMB_ACL_MASK 6 | |
6282 | + | |
6283 | + | |
6284 | +#define SMB_ACL_FIRST_ENTRY 1 | |
6285 | +#define SMB_ACL_NEXT_ENTRY 2 | |
6286 | + | |
6287 | +#define SMB_ACL_TYPE_ACCESS 0 | |
6288 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
6289 | + | |
6290 | +#else /* No ACLs. */ | |
6291 | + | |
6292 | +/* No ACLS - fake it. */ | |
6293 | +#define SMB_ACL_TAG_T int | |
6294 | +#define SMB_ACL_TYPE_T int | |
6295 | +#define SMB_ACL_PERMSET_T mode_t | |
6296 | +#define SMB_ACL_PERM_T mode_t | |
6297 | +#define SMB_ACL_READ S_IRUSR | |
6298 | +#define SMB_ACL_WRITE S_IWUSR | |
6299 | +#define SMB_ACL_EXECUTE S_IXUSR | |
6300 | + | |
6301 | +/* Types of ACLs. */ | |
6302 | +#define SMB_ACL_USER 0 | |
6303 | +#define SMB_ACL_USER_OBJ 1 | |
6304 | +#define SMB_ACL_GROUP 2 | |
6305 | +#define SMB_ACL_GROUP_OBJ 3 | |
6306 | +#define SMB_ACL_OTHER 4 | |
6307 | +#define SMB_ACL_MASK 5 | |
6308 | + | |
6309 | +typedef struct SMB_ACL_T { | |
6310 | + int dummy; | |
6311 | +} *SMB_ACL_T; | |
6312 | + | |
6313 | +typedef struct SMB_ACL_ENTRY_T { | |
6314 | + int dummy; | |
6315 | +} *SMB_ACL_ENTRY_T; | |
6316 | + | |
6317 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6318 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6319 | + | |
6320 | +#define SMB_ACL_TYPE_ACCESS 0 | |
6321 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
6322 | + | |
6323 | +#endif /* No ACLs. */ | |
6324 | +#endif /* _SMB_ACLS_H */ | |
475c4a36 WD |
6325 | --- old/testsuite/acls.test |
6326 | +++ new/testsuite/acls.test | |
6327 | @@ -0,0 +1,34 @@ | |
6328 | +#! /bin/sh | |
6329 | + | |
6330 | +# This program is distributable under the terms of the GNU GPL (see | |
6331 | +# COPYING). | |
6332 | + | |
6333 | +# Test that rsync handles basic ACL preservation. | |
6334 | + | |
6335 | +. $srcdir/testsuite/rsync.fns | |
6336 | + | |
6337 | +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support" | |
6338 | +case "$setfacl_nodef" in | |
6339 | +true) test_skipped "I don't know how to use your setfacl command" ;; | |
6340 | +esac | |
6341 | + | |
6342 | +makepath "$fromdir/foo" | |
6343 | +echo something >"$fromdir/file1" | |
6344 | +echo else >"$fromdir/file2" | |
6345 | + | |
6346 | +files='foo file1 file2' | |
6347 | + | |
6348 | +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled" | |
6349 | +setfacl -m u:0:5 "$fromdir/file1" | |
6350 | +setfacl -m u:0:5 "$fromdir/file2" | |
6351 | + | |
6352 | +$RSYNC -avvA "$fromdir/" "$todir/" | |
6353 | + | |
6354 | +cd "$fromdir" | |
6355 | +getfacl $files >"$scratchdir/acls.txt" | |
6356 | + | |
6357 | +cd "$todir" | |
6358 | +getfacl $files | diff $diffopt "$scratchdir/acls.txt" - | |
6359 | + | |
6360 | +# The script would have aborted on error, so getting here means we've won. | |
6361 | +exit 0 | |
9a7eef96 WD |
6362 | --- old/testsuite/default-acls.test |
6363 | +++ new/testsuite/default-acls.test | |
475c4a36 | 6364 | @@ -0,0 +1,65 @@ |
90fa6d68 WD |
6365 | +#! /bin/sh |
6366 | + | |
475c4a36 | 6367 | +# This program is distributable under the terms of the GNU GPL (see |
90fa6d68 WD |
6368 | +# COPYING). |
6369 | + | |
6370 | +# Test that rsync obeys default ACLs. -- Matt McCutchen | |
6371 | + | |
6372 | +. $srcdir/testsuite/rsync.fns | |
6373 | + | |
25d385b9 | 6374 | +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support" |
53c1073a | 6375 | +case "$setfacl_nodef" in |
475c4a36 | 6376 | +true) test_skipped "I don't know how to use your setfacl command" ;; |
53c1073a WD |
6377 | +*-k*) opts='-dm u::7,g::5,o:5' ;; |
6378 | +*) opts='-m d:u::7,d:g::5,d:o:5' ;; | |
6379 | +esac | |
6380 | +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled" | |
90fa6d68 | 6381 | + |
90fa6d68 | 6382 | +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected> |
25d385b9 | 6383 | +testit() { |
90fa6d68 WD |
6384 | + todir="$scratchdir/$1" |
6385 | + mkdir "$todir" | |
53c1073a WD |
6386 | + $setfacl_nodef "$todir" |
6387 | + if [ "$2" ]; then | |
6388 | + case "$setfacl_nodef" in | |
6389 | + *-k*) opts="-dm $2" ;; | |
6390 | + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`" | |
6391 | + esac | |
6392 | + setfacl $opts "$todir" | |
6393 | + fi | |
90fa6d68 WD |
6394 | + # Make sure we obey ACLs when creating a directory to hold multiple transferred files, |
6395 | + # even though the directory itself is outside the transfer | |
25d385b9 | 6396 | + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/" |
0251480d | 6397 | + check_perms "$todir/to" $4 "Target $1" |
25d385b9 | 6398 | + check_perms "$todir/to/dir" $4 "Target $1" |
0251480d WD |
6399 | + check_perms "$todir/to/file" $3 "Target $1" |
6400 | + check_perms "$todir/to/program" $4 "Target $1" | |
90fa6d68 WD |
6401 | + # Make sure get_local_name doesn't mess us up when transferring only one file |
6402 | + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile" | |
0251480d | 6403 | + check_perms "$todir/to/anotherfile" $3 "Target $1" |
bb81ee98 | 6404 | + # Make sure we obey default ACLs when not transferring a regular file |
2578e2b6 | 6405 | + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/" |
bb81ee98 | 6406 | + check_perms "$todir/to/anotherdir" $4 "Target $1" |
90fa6d68 WD |
6407 | +} |
6408 | + | |
25d385b9 | 6409 | +mkdir "$scratchdir/dir" |
0251480d | 6410 | +echo "File!" >"$scratchdir/file" |
25d385b9 WD |
6411 | +echo "#!/bin/sh" >"$scratchdir/program" |
6412 | +chmod 777 "$scratchdir/dir" | |
0251480d WD |
6413 | +chmod 666 "$scratchdir/file" |
6414 | +chmod 777 "$scratchdir/program" | |
6415 | + | |
90fa6d68 WD |
6416 | +# Test some target directories |
6417 | +umask 0077 | |
53c1073a WD |
6418 | +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx |
6419 | +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x | |
6420 | +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x--- | |
6421 | +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx--- | |
0251480d | 6422 | +testit noda1 '' rw------- rwx------ |
90fa6d68 | 6423 | +umask 0000 |
0251480d | 6424 | +testit noda2 '' rw-rw-rw- rwxrwxrwx |
90fa6d68 | 6425 | +umask 0022 |
0251480d | 6426 | +testit noda3 '' rw-r--r-- rwxr-xr-x |
90fa6d68 WD |
6427 | + |
6428 | +# Hooray | |
6429 | +exit 0 | |
0870c22a WD |
6430 | --- old/testsuite/devices.test |
6431 | +++ new/testsuite/devices.test | |
6432 | @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc | |
6433 | $RSYNC -ai "$fromdir/block" "$todir/block2" \ | |
6434 | | tee "$outfile" | |
6435 | cat <<EOT >"$chkfile" | |
6436 | -cD+++++++ block | |
6437 | +cD+++++++++ block | |
6438 | EOT | |
6439 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" | |
6440 | ||
6441 | $RSYNC -ai "$fromdir/block2" "$todir/block" \ | |
6442 | | tee "$outfile" | |
6443 | cat <<EOT >"$chkfile" | |
6444 | -cD+++++++ block2 | |
6445 | +cD+++++++++ block2 | |
6446 | EOT | |
6447 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" | |
6448 | ||
6449 | @@ -58,7 +58,7 @@ sleep 1 | |
6450 | $RSYNC -Di "$fromdir/block3" "$todir/block" \ | |
6451 | | tee "$outfile" | |
6452 | cat <<EOT >"$chkfile" | |
6453 | -cD..T.... block3 | |
6454 | +cD..T...... block3 | |
6455 | EOT | |
6456 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" | |
6457 | ||
6458 | @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \ | |
6459 | | tee "$outfile" | |
6460 | filter_outfile | |
6461 | cat <<EOT >"$chkfile" | |
6462 | -.d..t.... ./ | |
6463 | -cD..t.... block | |
6464 | -cD....... block2 | |
6465 | -cD+++++++ block3 | |
6466 | -hD+++++++ block2.5 => block3 | |
6467 | -cD+++++++ char | |
6468 | -cD+++++++ char2 | |
6469 | -cD+++++++ char3 | |
6470 | -cS+++++++ fifo | |
6471 | +.d..t...... ./ | |
6472 | +cD..t...... block | |
6473 | +cD......... block2 | |
6474 | +cD+++++++++ block3 | |
6475 | +hD+++++++++ block2.5 => block3 | |
6476 | +cD+++++++++ char | |
6477 | +cD+++++++++ char2 | |
6478 | +cD+++++++++ char3 | |
6479 | +cS+++++++++ fifo | |
6480 | EOT | |
6481 | if test ! -b "$fromdir/block2.5"; then | |
6482 | sed -e '/block2\.5/d' \ | |
6483 | --- old/testsuite/itemize.test | |
6484 | +++ new/testsuite/itemize.test | |
2a787d74 | 6485 | @@ -29,15 +29,15 @@ ln "$fromdir/foo/config1" "$fromdir/foo/ |
0870c22a WD |
6486 | $RSYNC -iplr "$fromdir/" "$todir/" \ |
6487 | | tee "$outfile" | |
6488 | cat <<EOT >"$chkfile" | |
2a787d74 | 6489 | -cd+++++++ ./ |
0870c22a WD |
6490 | -cd+++++++ bar/ |
6491 | -cd+++++++ bar/baz/ | |
6492 | ->f+++++++ bar/baz/rsync | |
6493 | -cd+++++++ foo/ | |
6494 | ->f+++++++ foo/config1 | |
6495 | ->f+++++++ foo/config2 | |
6496 | ->f+++++++ foo/extra | |
6497 | -cL+++++++ foo/sym -> ../bar/baz/rsync | |
2a787d74 | 6498 | +cd+++++++++ ./ |
0870c22a WD |
6499 | +cd+++++++++ bar/ |
6500 | +cd+++++++++ bar/baz/ | |
6501 | +>f+++++++++ bar/baz/rsync | |
6502 | +cd+++++++++ foo/ | |
6503 | +>f+++++++++ foo/config1 | |
6504 | +>f+++++++++ foo/config2 | |
6505 | +>f+++++++++ foo/extra | |
6506 | +cL+++++++++ foo/sym -> ../bar/baz/rsync | |
6507 | EOT | |
6508 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" | |
6509 | ||
2a787d74 | 6510 | @@ -49,10 +49,10 @@ chmod 601 "$fromdir/foo/config2" |
0870c22a WD |
6511 | $RSYNC -iplrH "$fromdir/" "$todir/" \ |
6512 | | tee "$outfile" | |
6513 | cat <<EOT >"$chkfile" | |
6514 | ->f..T.... bar/baz/rsync | |
6515 | ->f..T.... foo/config1 | |
6516 | ->f.sTp... foo/config2 | |
6517 | -hf..T.... foo/extra => foo/config1 | |
6518 | +>f..T...... bar/baz/rsync | |
6519 | +>f..T...... foo/config1 | |
6520 | +>f.sTp..... foo/config2 | |
6521 | +hf..T...... foo/extra => foo/config1 | |
6522 | EOT | |
6523 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" | |
6524 | ||
2a787d74 | 6525 | @@ -69,11 +69,11 @@ chmod 777 "$todir/bar/baz/rsync" |
0870c22a WD |
6526 | $RSYNC -iplrtc "$fromdir/" "$todir/" \ |
6527 | | tee "$outfile" | |
6528 | cat <<EOT >"$chkfile" | |
6529 | -.f..tp... bar/baz/rsync | |
6530 | -.d..t.... foo/ | |
6531 | -.f..t.... foo/config1 | |
6532 | ->fcstp... foo/config2 | |
6533 | -cL..T.... foo/sym -> ../bar/baz/rsync | |
6534 | +.f..tp..... bar/baz/rsync | |
6535 | +.d..t...... foo/ | |
6536 | +.f..t...... foo/config1 | |
6537 | +>fcstp..... foo/config2 | |
6538 | +cL..T...... foo/sym -> ../bar/baz/rsync | |
6539 | EOT | |
6540 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" | |
6541 | ||
2a787d74 | 6542 | @@ -98,15 +98,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \ |
0870c22a WD |
6543 | | tee "$outfile" |
6544 | filter_outfile | |
6545 | cat <<EOT >"$chkfile" | |
6546 | -.d ./ | |
6547 | -.d bar/ | |
6548 | -.d bar/baz/ | |
6549 | -.f...p... bar/baz/rsync | |
6550 | -.d foo/ | |
6551 | -.f foo/config1 | |
6552 | ->f..t.... foo/config2 | |
6553 | -hf foo/extra | |
6554 | -.L foo/sym -> ../bar/baz/rsync | |
6555 | +.d ./ | |
6556 | +.d bar/ | |
6557 | +.d bar/baz/ | |
6558 | +.f...p..... bar/baz/rsync | |
6559 | +.d foo/ | |
6560 | +.f foo/config1 | |
6561 | +>f..t...... foo/config2 | |
6562 | +hf foo/extra | |
6563 | +.L foo/sym -> ../bar/baz/rsync | |
6564 | EOT | |
6565 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed" | |
6566 | ||
2a787d74 | 6567 | @@ -125,8 +125,8 @@ touch "$todir/foo/config2" |
0870c22a WD |
6568 | $RSYNC -iplrtH "$fromdir/" "$todir/" \ |
6569 | | tee "$outfile" | |
6570 | cat <<EOT >"$chkfile" | |
6571 | -.f...p... foo/config1 | |
6572 | ->f..t.... foo/config2 | |
6573 | +.f...p..... foo/config1 | |
6574 | +>f..t...... foo/config2 | |
6575 | EOT | |
6576 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed" | |
6577 | ||
2a787d74 | 6578 | @@ -135,15 +135,15 @@ $RSYNC -ivvplrtH --copy-dest=../ld "$fro |
0870c22a WD |
6579 | | tee "$outfile" |
6580 | filter_outfile | |
6581 | cat <<EOT >"$chkfile" | |
2a787d74 | 6582 | -cd+++++++ ./ |
0870c22a WD |
6583 | -cd+++++++ bar/ |
6584 | -cd+++++++ bar/baz/ | |
6585 | -cf bar/baz/rsync | |
6586 | -cd+++++++ foo/ | |
6587 | -cf foo/config1 | |
6588 | -cf foo/config2 | |
6589 | -hf foo/extra => foo/config1 | |
6590 | -cL..T.... foo/sym -> ../bar/baz/rsync | |
2a787d74 | 6591 | +cd+++++++++ ./ |
0870c22a WD |
6592 | +cd+++++++++ bar/ |
6593 | +cd+++++++++ bar/baz/ | |
6594 | +cf bar/baz/rsync | |
6595 | +cd+++++++++ foo/ | |
6596 | +cf foo/config1 | |
6597 | +cf foo/config2 | |
6598 | +hf foo/extra => foo/config1 | |
6599 | +cL..T...... foo/sym -> ../bar/baz/rsync | |
6600 | EOT | |
6601 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed" | |
6602 | ||
2a787d74 WD |
6603 | @@ -151,11 +151,11 @@ rm -rf "$todir" |
6604 | $RSYNC -iplrtH --copy-dest=../ld "$fromdir/" "$todir/" \ | |
0870c22a WD |
6605 | | tee "$outfile" |
6606 | cat <<EOT >"$chkfile" | |
2a787d74 | 6607 | -cd+++++++ ./ |
0870c22a WD |
6608 | -cd+++++++ bar/ |
6609 | -cd+++++++ bar/baz/ | |
6610 | -cd+++++++ foo/ | |
6611 | -hf foo/extra => foo/config1 | |
2a787d74 | 6612 | +cd+++++++++ ./ |
0870c22a WD |
6613 | +cd+++++++++ bar/ |
6614 | +cd+++++++++ bar/baz/ | |
6615 | +cd+++++++++ foo/ | |
6616 | +hf foo/extra => foo/config1 | |
6617 | EOT | |
6618 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed" | |
6619 | ||
2a787d74 | 6620 | @@ -182,15 +182,15 @@ $RSYNC -ivvplrtH --link-dest="$lddir" "$ |
0870c22a WD |
6621 | | tee "$outfile" |
6622 | filter_outfile | |
6623 | cat <<EOT >"$chkfile" | |
2a787d74 | 6624 | -cd+++++++ ./ |
0870c22a WD |
6625 | -cd+++++++ bar/ |
6626 | -cd+++++++ bar/baz/ | |
6627 | -hf bar/baz/rsync | |
6628 | -cd+++++++ foo/ | |
6629 | -hf foo/config1 | |
6630 | -hf foo/config2 | |
6631 | -hf foo/extra => foo/config1 | |
6632 | -hL foo/sym -> ../bar/baz/rsync | |
2a787d74 | 6633 | +cd+++++++++ ./ |
0870c22a WD |
6634 | +cd+++++++++ bar/ |
6635 | +cd+++++++++ bar/baz/ | |
6636 | +hf bar/baz/rsync | |
6637 | +cd+++++++++ foo/ | |
6638 | +hf foo/config1 | |
6639 | +hf foo/config2 | |
6640 | +hf foo/extra => foo/config1 | |
6641 | +hL foo/sym -> ../bar/baz/rsync | |
6642 | EOT | |
6643 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed" | |
6644 | ||
2a787d74 WD |
6645 | @@ -198,10 +198,10 @@ rm -rf "$todir" |
6646 | $RSYNC -iplrtH --dry-run --link-dest=../ld "$fromdir/" "$todir/" \ | |
0870c22a WD |
6647 | | tee "$outfile" |
6648 | cat <<EOT >"$chkfile" | |
2a787d74 | 6649 | -cd+++++++ ./ |
0870c22a WD |
6650 | -cd+++++++ bar/ |
6651 | -cd+++++++ bar/baz/ | |
6652 | -cd+++++++ foo/ | |
2a787d74 | 6653 | +cd+++++++++ ./ |
0870c22a WD |
6654 | +cd+++++++++ bar/ |
6655 | +cd+++++++++ bar/baz/ | |
6656 | +cd+++++++++ foo/ | |
6657 | EOT | |
6658 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 12 failed" | |
6659 | ||
2a787d74 WD |
6660 | @@ -209,10 +209,10 @@ rm -rf "$todir" |
6661 | $RSYNC -iplrtH --link-dest=../ld "$fromdir/" "$todir/" \ | |
6662 | | tee "$outfile" | |
6663 | cat <<EOT >"$chkfile" | |
6664 | -cd+++++++ ./ | |
6665 | -cd+++++++ bar/ | |
6666 | -cd+++++++ bar/baz/ | |
6667 | -cd+++++++ foo/ | |
6668 | +cd+++++++++ ./ | |
6669 | +cd+++++++++ bar/ | |
6670 | +cd+++++++++ bar/baz/ | |
6671 | +cd+++++++++ foo/ | |
6672 | EOT | |
6673 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 13 failed" | |
6674 | ||
6675 | @@ -240,14 +240,14 @@ filter_outfile | |
0870c22a WD |
6676 | # TODO fix really-old problem when combining -H with --compare-dest: |
6677 | # missing output for foo/extra hard-link (and it might not be updated)! | |
6678 | cat <<EOT >"$chkfile" | |
2a787d74 | 6679 | -cd+++++++ ./ |
0870c22a WD |
6680 | -cd+++++++ bar/ |
6681 | -cd+++++++ bar/baz/ | |
6682 | -.f bar/baz/rsync | |
6683 | -cd+++++++ foo/ | |
6684 | -.f foo/config1 | |
6685 | -.f foo/config2 | |
6686 | -.L foo/sym -> ../bar/baz/rsync | |
2a787d74 | 6687 | +cd+++++++++ ./ |
0870c22a WD |
6688 | +cd+++++++++ bar/ |
6689 | +cd+++++++++ bar/baz/ | |
6690 | +.f bar/baz/rsync | |
6691 | +cd+++++++++ foo/ | |
6692 | +.f foo/config1 | |
6693 | +.f foo/config2 | |
6694 | +.L foo/sym -> ../bar/baz/rsync | |
6695 | EOT | |
2a787d74 | 6696 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed" |
0870c22a | 6697 | |
2a787d74 | 6698 | @@ -255,10 +255,10 @@ rm -rf "$todir" |
0870c22a WD |
6699 | $RSYNC -iplrtH --compare-dest="$lddir" "$fromdir/" "$todir/" \ |
6700 | | tee "$outfile" | |
6701 | cat <<EOT >"$chkfile" | |
2a787d74 | 6702 | -cd+++++++ ./ |
0870c22a WD |
6703 | -cd+++++++ bar/ |
6704 | -cd+++++++ bar/baz/ | |
6705 | -cd+++++++ foo/ | |
2a787d74 | 6706 | +cd+++++++++ ./ |
0870c22a WD |
6707 | +cd+++++++++ bar/ |
6708 | +cd+++++++++ bar/baz/ | |
6709 | +cd+++++++++ foo/ | |
6710 | EOT | |
2a787d74 | 6711 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 16 failed" |
0870c22a | 6712 | |
9a7eef96 WD |
6713 | --- old/uidlist.c |
6714 | +++ new/uidlist.c | |
c1471566 | 6715 | @@ -35,6 +35,7 @@ |
fa26e11c WD |
6716 | extern int verbose; |
6717 | extern int preserve_uid; | |
6718 | extern int preserve_gid; | |
6719 | +extern int preserve_acls; | |
6720 | extern int numeric_ids; | |
6721 | extern int am_root; | |
6722 | ||
668bbc0a | 6723 | @@ -273,7 +274,7 @@ void send_uid_list(int f) |
fa26e11c WD |
6724 | if (numeric_ids) |
6725 | return; | |
6726 | ||
6727 | - if (preserve_uid) { | |
6728 | + if (preserve_uid || preserve_acls) { | |
6729 | int len; | |
6730 | /* we send sequences of uid/byte-length/name */ | |
6731 | for (list = uidlist; list; list = list->next) { | |
668bbc0a | 6732 | @@ -290,7 +291,7 @@ void send_uid_list(int f) |
fa26e11c WD |
6733 | write_int(f, 0); |
6734 | } | |
6735 | ||
6736 | - if (preserve_gid) { | |
6737 | + if (preserve_gid || preserve_acls) { | |
6738 | int len; | |
6739 | for (list = gidlist; list; list = list->next) { | |
6740 | if (!list->name) | |
668bbc0a | 6741 | @@ -311,7 +312,7 @@ void recv_uid_list(int f, struct file_li |
fa26e11c WD |
6742 | int id, i; |
6743 | char *name; | |
6744 | ||
6745 | - if (preserve_uid && !numeric_ids) { | |
6746 | + if ((preserve_uid || preserve_acls) && !numeric_ids) { | |
6747 | /* read the uid list */ | |
6748 | while ((id = read_int(f)) != 0) { | |
6749 | int len = read_byte(f); | |
668bbc0a | 6750 | @@ -323,7 +324,7 @@ void recv_uid_list(int f, struct file_li |
6849cd84 | 6751 | } |
fa26e11c WD |
6752 | } |
6753 | ||
fa26e11c WD |
6754 | - if (preserve_gid && !numeric_ids) { |
6755 | + if ((preserve_gid || preserve_acls) && !numeric_ids) { | |
6756 | /* read the gid list */ | |
6757 | while ((id = read_int(f)) != 0) { | |
6758 | int len = read_byte(f); | |
668bbc0a | 6759 | @@ -335,6 +336,16 @@ void recv_uid_list(int f, struct file_li |
fa26e11c WD |
6760 | } |
6761 | } | |
125d7fca | 6762 | |
4edb99c8 | 6763 | +#ifdef SUPPORT_ACLS |
fa26e11c | 6764 | + if (preserve_acls && !numeric_ids) { |
c52977bc WD |
6765 | + id_t *id; |
6766 | + while ((id = next_acl_uid(flist)) != NULL) | |
6767 | + *id = match_uid(*id); | |
6768 | + while ((id = next_acl_gid(flist)) != NULL) | |
6769 | + *id = match_gid(*id); | |
fa26e11c | 6770 | + } |
162234a7 | 6771 | +#endif |
125d7fca | 6772 | + |
90fa6d68 | 6773 | /* Now convert all the uids/gids from sender values to our values. */ |
125d7fca | 6774 | if (am_root && preserve_uid && !numeric_ids) { |
90fa6d68 | 6775 | for (i = 0; i < flist->count; i++) |
6250eb3e WD |
6776 | --- old/util.c |
6777 | +++ new/util.c | |
7f8e973e | 6778 | @@ -1468,3 +1468,31 @@ int bitbag_next_bit(struct bitbag *bb, i |
6250eb3e WD |
6779 | |
6780 | return -1; | |
6781 | } | |
6782 | + | |
6783 | +void *expand_item_list(item_list *lp, size_t item_size, | |
645e162c | 6784 | + const char *desc, int incr) |
6250eb3e WD |
6785 | +{ |
6786 | + /* First time through, 0 <= 0, so list is expanded. */ | |
6787 | + if (lp->malloced <= lp->count) { | |
6788 | + void *new_ptr; | |
6789 | + size_t new_size = lp->malloced; | |
645e162c WD |
6790 | + if (incr < 0) |
6791 | + new_size -= incr; /* increase slowly */ | |
98ccc74a | 6792 | + else if (new_size < (size_t)incr) |
645e162c WD |
6793 | + new_size += incr; |
6794 | + else | |
6795 | + new_size *= 2; | |
6250eb3e WD |
6796 | + new_ptr = realloc_array(lp->items, char, new_size * item_size); |
6797 | + if (verbose >= 4) { | |
6798 | + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n", | |
6799 | + who_am_i(), desc, (double)new_size * item_size, | |
6800 | + new_ptr == lp->items ? " not" : ""); | |
6801 | + } | |
6802 | + if (!new_ptr) | |
6803 | + out_of_memory("expand_item_list"); | |
6804 | + | |
6805 | + lp->items = new_ptr; | |
6806 | + lp->malloced = new_size; | |
6807 | + } | |
6808 | + return (char*)lp->items + (lp->count++ * item_size); | |
6809 | +} |