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