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 | |
70891d26 | 1131 | @@ -23,6 +23,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; | |
1aa236e1 | 1139 | @@ -93,7 +94,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; | |
1aa236e1 | 1149 | @@ -125,15 +127,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 = '/'; | |
1aa236e1 | 1178 | @@ -171,15 +182,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 */ | |
1aa236e1 | 1199 | @@ -189,6 +203,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))) { | |
81ecd8e0 | 1213 | @@ -260,7 +281,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 | |
a7592111 | 1224 | @@ -56,6 +56,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 | |
a7592111 | 1328 | @@ -42,6 +42,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; | |
a7592111 | 1336 | @@ -153,6 +154,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", | |
a7592111 | 1345 | @@ -712,6 +715,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 | |
a7592111 | 1358 | @@ -849,6 +858,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 | + | |
1367 | return file; | |
1368 | } | |
1369 | ||
a7592111 WD |
1370 | @@ -1120,6 +1134,9 @@ static struct file_struct *send_file_nam |
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) | |
1380 | @@ -1128,12 +1145,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 | |
a7592111 | 1410 | @@ -36,6 +36,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; | |
a7592111 | 1418 | @@ -90,6 +91,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; | |
a7592111 | 1426 | @@ -509,22 +511,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! */ | |
a7592111 | 1459 | @@ -532,20 +539,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 | ||
a7592111 | 1489 | @@ -799,7 +810,7 @@ void check_for_finished_hlinks(int itemi |
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; |
a7592111 | 1498 | @@ -808,7 +819,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: | |
a7592111 | 1507 | @@ -816,16 +827,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; | |
a7592111 | 1531 | @@ -840,7 +855,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 | ||
a7592111 | 1540 | @@ -850,16 +865,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; |
a7592111 | 1570 | @@ -876,8 +900,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) | |
a7592111 | 1586 | @@ -888,7 +917,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 | } | |
a7592111 | 1595 | @@ -900,7 +929,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]; |
a7592111 | 1604 | @@ -933,24 +962,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 | |
a7592111 | 1634 | @@ -965,7 +994,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 | |
a7592111 | 1643 | @@ -982,7 +1011,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; | |
a7592111 | 1656 | @@ -995,7 +1028,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 | ||
a7592111 | 1665 | @@ -1026,7 +1059,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", |
a7592111 | 1682 | @@ -1039,6 +1080,7 @@ static int try_dests_non(struct file_str |
26c810d8 WD |
1683 | } |
1684 | ||
1685 | static int phase = 0; | |
1686 | +static int dflt_perms; | |
1687 | ||
a7592111 | 1688 | /* Acts on cur_flist->file's ndx'th item, whose name is fname. If a dir, |
26c810d8 | 1689 | * make sure it exists, and has the right permissions/timestamp info. For |
a7592111 | 1690 | @@ -1059,7 +1101,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; | |
a7592111 | 1700 | @@ -1104,6 +1147,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); | |
1710 | @@ -1116,7 +1162,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", | |
a7592111 | 1719 | @@ -1128,6 +1174,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 | |
a7592111 | 1730 | @@ -1137,7 +1187,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 | } | |
a7592111 | 1739 | @@ -1163,8 +1213,9 @@ static void recv_generator(char *fname, |
0870c22a | 1740 | * mode based on the local permissions and some heuristics. */ |
90fa6d68 WD |
1741 | if (!preserve_perms) { |
1742 | int exists = statret == 0 | |
0870c22a | 1743 | - && S_ISDIR(st.st_mode) == S_ISDIR(file->mode); |
90fa6d68 | 1744 | - file->mode = dest_mode(file->mode, st.st_mode, exists); |
0870c22a WD |
1745 | + && S_ISDIR(sx.st.st_mode) == S_ISDIR(file->mode); |
1746 | + file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms, | |
26c810d8 | 1747 | + exists); |
90fa6d68 WD |
1748 | } |
1749 | ||
1750 | if (S_ISDIR(file->mode)) { | |
a7592111 | 1751 | @@ -1173,8 +1224,8 @@ static void recv_generator(char *fname, |
147c8f4c | 1752 | * file of that name and it is *not* a directory, then |
0870c22a WD |
1753 | * we need to delete it. If it doesn't exist, then |
1754 | * (perhaps recursively) create it. */ | |
1755 | - if (statret == 0 && !S_ISDIR(st.st_mode)) { | |
87d0091c | 1756 | - if (delete_item(fname, st.st_mode, "directory", del_opts) != 0) |
0870c22a | 1757 | + if (statret == 0 && !S_ISDIR(sx.st.st_mode)) { |
87d0091c | 1758 | + if (delete_item(fname, sx.st.st_mode, "directory", del_opts) != 0) |
0870c22a WD |
1759 | return; |
1760 | statret = -1; | |
1761 | } | |
a7592111 | 1762 | @@ -1183,14 +1234,14 @@ static void recv_generator(char *fname, |
147c8f4c WD |
1763 | dry_run++; |
1764 | } | |
1765 | real_ret = statret; | |
1766 | - real_st = st; | |
1767 | + real_sx = sx; | |
1768 | if (new_root_dir) { | |
1769 | if (*fname == '.' && fname[1] == '\0') | |
1770 | statret = -1; | |
05031682 WD |
1771 | new_root_dir = 0; |
1772 | } | |
147c8f4c | 1773 | if (statret != 0 && basis_dir[0] != NULL) { |
05031682 WD |
1774 | - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st, |
1775 | + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, | |
7b80cd0e | 1776 | itemizing, code); |
05031682 WD |
1777 | if (j == -2) { |
1778 | itemizing = 0; | |
a7592111 | 1779 | @@ -1199,7 +1250,11 @@ static void recv_generator(char *fname, |
147c8f4c | 1780 | statret = 1; |
05031682 WD |
1781 | } |
1782 | if (itemizing && f_out != -1) { | |
147c8f4c | 1783 | - itemize(file, ndx, statret, &st, |
0870c22a | 1784 | +#ifdef SUPPORT_ACLS |
147c8f4c | 1785 | + if (preserve_acls && statret == 0) |
98ccc74a | 1786 | + get_acl(fname, &sx); |
0870c22a | 1787 | +#endif |
147c8f4c WD |
1788 | + itemize(file, ndx, statret, &sx, |
1789 | statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL); | |
0870c22a | 1790 | } |
147c8f4c | 1791 | if (real_ret != 0 && do_mkdir(fname,file->mode) < 0 && errno != EEXIST) { |
a7592111 WD |
1792 | @@ -1213,31 +1268,31 @@ static void recv_generator(char *fname, |
1793 | "*** Skipping any contents from this failed directory ***\n"); | |
1794 | missing_below = F_DEPTH(file); | |
1795 | file->flags |= FLAG_MISSING_DIR; | |
1796 | - return; | |
1797 | + goto cleanup; | |
0870c22a WD |
1798 | } |
1799 | } | |
147c8f4c WD |
1800 | - if (set_file_attrs(fname, file, real_ret ? NULL : &real_st, 0) |
1801 | + if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, 0) | |
3758a5a5 | 1802 | && verbose && code != FNONE && f_out != -1) |
0870c22a | 1803 | rprintf(code, "%s/\n", fname); |
147c8f4c WD |
1804 | if (real_ret != 0 && one_file_system) |
1805 | - real_st.st_dev = filesystem_dev; | |
1806 | + real_sx.st.st_dev = filesystem_dev; | |
a7592111 WD |
1807 | if (incremental) { |
1808 | if (one_file_system) { | |
1809 | uint32 *devp = F_DIRDEV_P(file); | |
1810 | - DEV_MAJOR(devp) = major(real_st.st_dev); | |
1811 | - DEV_MINOR(devp) = minor(real_st.st_dev); | |
1812 | + DEV_MAJOR(devp) = major(real_sx.st.st_dev); | |
1813 | + DEV_MINOR(devp) = minor(real_sx.st.st_dev); | |
1814 | } | |
1815 | } | |
1816 | else if (delete_during && f_out != -1 && !phase && dry_run < 2 | |
70891d26 | 1817 | && (file->flags & FLAG_XFER_DIR)) |
a7592111 | 1818 | - delete_in_dir(cur_flist, fname, file, &real_st.st_dev); |
0870c22a | 1819 | - return; |
a7592111 | 1820 | + delete_in_dir(cur_flist, fname, file, &real_sx.st.st_dev); |
0870c22a WD |
1821 | + goto cleanup; |
1822 | } | |
1823 | ||
81ecd8e0 | 1824 | #ifdef SUPPORT_HARD_LINKS |
49551128 | 1825 | if (preserve_hard_links && F_HLINK_NOT_FIRST(file) |
7b80cd0e | 1826 | - && hard_link_check(file, ndx, fname, statret, &st, itemizing, code)) |
0870c22a | 1827 | - return; |
7b80cd0e | 1828 | + && hard_link_check(file, ndx, fname, statret, &sx, itemizing, code)) |
0870c22a | 1829 | + goto cleanup; |
81ecd8e0 | 1830 | #endif |
0870c22a WD |
1831 | |
1832 | if (preserve_links && S_ISLNK(file->mode)) { | |
a7592111 | 1833 | @@ -1257,28 +1312,28 @@ static void recv_generator(char *fname, |
0870c22a WD |
1834 | char lnk[MAXPATHLEN]; |
1835 | int len; | |
1836 | ||
05031682 WD |
1837 | - if (!S_ISLNK(st.st_mode)) |
1838 | + if (!S_ISLNK(sx.st.st_mode)) | |
1839 | statret = -1; | |
1840 | else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0 | |
70891d26 | 1841 | && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') { |
05031682 WD |
1842 | /* The link is pointing to the right place. */ |
1843 | if (itemizing) | |
1844 | - itemize(file, ndx, 0, &st, 0, 0, NULL); | |
1845 | - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT); | |
1846 | + itemize(file, ndx, 0, &sx, 0, 0, NULL); | |
1847 | + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT); | |
81ecd8e0 | 1848 | #ifdef SUPPORT_HARD_LINKS |
1aa236e1 | 1849 | if (preserve_hard_links && F_IS_HLINKED(file)) |
7b80cd0e WD |
1850 | - finish_hard_link(file, fname, &st, itemizing, code, -1); |
1851 | + finish_hard_link(file, fname, &sx.st, itemizing, code, -1); | |
1852 | #endif | |
1853 | if (remove_source_files == 1) | |
1854 | goto return_with_success; | |
a7592111 WD |
1855 | - return; |
1856 | + goto cleanup; | |
0870c22a WD |
1857 | } |
1858 | /* Not the right symlink (or not a symlink), so | |
1859 | * delete it. */ | |
87d0091c | 1860 | - if (delete_item(fname, st.st_mode, "symlink", del_opts) != 0) |
a7592111 | 1861 | - return; |
87d0091c | 1862 | + if (delete_item(fname, sx.st.st_mode, "symlink", del_opts) != 0) |
a7592111 | 1863 | + goto cleanup; |
0870c22a | 1864 | } else if (basis_dir[0] != NULL) { |
05031682 WD |
1865 | - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st, |
1866 | + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, | |
7b80cd0e | 1867 | itemizing, code); |
05031682 WD |
1868 | if (j == -2) { |
1869 | #ifndef CAN_HARDLINK_SYMLINK | |
a7592111 WD |
1870 | @@ -1287,7 +1342,7 @@ static void recv_generator(char *fname, |
1871 | } else | |
1872 | #endif | |
1873 | if (!copy_dest) | |
1874 | - return; | |
1875 | + goto cleanup; | |
1876 | itemizing = 0; | |
1877 | code = FNONE; | |
1878 | } else if (j >= 0) | |
1879 | @@ -1295,7 +1350,7 @@ static void recv_generator(char *fname, | |
1880 | } | |
1881 | #ifdef SUPPORT_HARD_LINKS | |
1882 | if (preserve_hard_links && F_HLINK_NOT_LAST(file)) | |
1883 | - return; | |
1884 | + goto cleanup; | |
1885 | #endif | |
1886 | if (do_symlink(sl, fname) != 0) { | |
1887 | rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed", | |
1888 | @@ -1303,7 +1358,7 @@ static void recv_generator(char *fname, | |
0870c22a WD |
1889 | } else { |
1890 | set_file_attrs(fname, file, NULL, 0); | |
1891 | if (itemizing) { | |
1892 | - itemize(file, ndx, statret, &st, | |
1893 | + itemize(file, ndx, statret, &sx, | |
1894 | ITEM_LOCAL_CHANGE, 0, NULL); | |
1895 | } | |
05031682 | 1896 | if (code != FNONE && verbose) |
a7592111 WD |
1897 | @@ -1319,7 +1374,7 @@ static void recv_generator(char *fname, |
1898 | goto return_with_success; | |
1899 | } | |
1900 | #endif | |
1901 | - return; | |
1902 | + goto cleanup; | |
1903 | } | |
1904 | ||
1905 | if ((am_root && preserve_devices && IS_DEVICE(file->mode)) | |
1906 | @@ -1329,33 +1384,38 @@ static void recv_generator(char *fname, | |
05031682 | 1907 | if (statret == 0) { |
87d0091c WD |
1908 | char *t; |
1909 | if (IS_DEVICE(file->mode)) { | |
1910 | - if (!IS_DEVICE(st.st_mode)) | |
1911 | + if (!IS_DEVICE(sx.st.st_mode)) | |
1912 | statret = -1; | |
1913 | t = "device file"; | |
1914 | } else { | |
1915 | - if (!IS_SPECIAL(st.st_mode)) | |
1916 | + if (!IS_SPECIAL(sx.st.st_mode)) | |
1917 | statret = -1; | |
1918 | t = "special file"; | |
1919 | } | |
1920 | if (statret == 0 | |
3d3ad7f1 | 1921 | - && BITS_EQUAL(st.st_mode, file->mode, _S_IFMT) |
70891d26 | 1922 | - && st.st_rdev == rdev) { |
3d3ad7f1 | 1923 | + && BITS_EQUAL(sx.st.st_mode, file->mode, _S_IFMT) |
70891d26 | 1924 | + && sx.st.st_rdev == rdev) { |
05031682 WD |
1925 | /* The device or special file is identical. */ |
1926 | - if (itemizing) | |
1927 | - itemize(file, ndx, 0, &st, 0, 0, NULL); | |
1928 | - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT); | |
1929 | + if (itemizing) { | |
1930 | +#ifdef SUPPORT_ACLS | |
1931 | + if (preserve_acls) | |
1932 | + get_acl(fname, &sx); | |
1933 | +#endif | |
1934 | + itemize(file, ndx, 0, &sx, 0, 0, NULL); | |
1935 | + } | |
1936 | + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT); | |
81ecd8e0 | 1937 | #ifdef SUPPORT_HARD_LINKS |
1aa236e1 | 1938 | if (preserve_hard_links && F_IS_HLINKED(file)) |
7b80cd0e WD |
1939 | - finish_hard_link(file, fname, &st, itemizing, code, -1); |
1940 | + finish_hard_link(file, fname, &sx.st, itemizing, code, -1); | |
81ecd8e0 | 1941 | #endif |
05031682 WD |
1942 | if (remove_source_files == 1) |
1943 | goto return_with_success; | |
1944 | - return; | |
1945 | + goto cleanup; | |
0870c22a | 1946 | } |
87d0091c | 1947 | - if (delete_item(fname, st.st_mode, t, del_opts) != 0) |
a7592111 | 1948 | - return; |
87d0091c | 1949 | + if (delete_item(fname, sx.st.st_mode, t, del_opts) != 0) |
a7592111 | 1950 | + goto cleanup; |
05031682 WD |
1951 | } else if (basis_dir[0] != NULL) { |
1952 | - int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &st, | |
1953 | + int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx, | |
7b80cd0e | 1954 | itemizing, code); |
05031682 WD |
1955 | if (j == -2) { |
1956 | #ifndef CAN_HARDLINK_SPECIAL | |
a7592111 WD |
1957 | @@ -1364,7 +1424,7 @@ static void recv_generator(char *fname, |
1958 | } else | |
1959 | #endif | |
1960 | if (!copy_dest) | |
1961 | - return; | |
1962 | + goto cleanup; | |
1963 | itemizing = 0; | |
1964 | code = FNONE; | |
1965 | } else if (j >= 0) | |
1966 | @@ -1372,7 +1432,7 @@ static void recv_generator(char *fname, | |
1967 | } | |
1968 | #ifdef SUPPORT_HARD_LINKS | |
1969 | if (preserve_hard_links && F_HLINK_NOT_LAST(file)) | |
1970 | - return; | |
1971 | + goto cleanup; | |
1972 | #endif | |
1973 | if (verbose > 2) { | |
1974 | rprintf(FINFO, "mknod(%s, 0%o, [%ld,%ld])\n", | |
1975 | @@ -1385,7 +1445,11 @@ static void recv_generator(char *fname, | |
0870c22a | 1976 | } else { |
05031682 WD |
1977 | set_file_attrs(fname, file, NULL, 0); |
1978 | if (itemizing) { | |
1979 | - itemize(file, ndx, statret, &st, | |
1980 | +#ifdef SUPPORT_ACLS | |
1981 | + if (preserve_acls && statret == 0) | |
1982 | + get_acl(fname, &sx); | |
1983 | +#endif | |
1984 | + itemize(file, ndx, statret, &sx, | |
1985 | ITEM_LOCAL_CHANGE, 0, NULL); | |
1986 | } | |
1987 | if (code != FNONE && verbose) | |
a7592111 | 1988 | @@ -1397,14 +1461,14 @@ static void recv_generator(char *fname, |
195ca26e WD |
1989 | if (remove_source_files == 1) |
1990 | goto return_with_success; | |
0870c22a WD |
1991 | } |
1992 | - return; | |
1993 | + goto cleanup; | |
1994 | } | |
1995 | ||
1996 | if (!S_ISREG(file->mode)) { | |
a7592111 WD |
1997 | if (solo_file) |
1998 | fname = f_name(file, NULL); | |
1999 | rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname); | |
2000 | - return; | |
2001 | + goto cleanup; | |
2002 | } | |
2003 | ||
2004 | if (max_size > 0 && F_LENGTH(file) > max_size) { | |
2005 | @@ -1413,7 +1477,7 @@ static void recv_generator(char *fname, | |
2006 | fname = f_name(file, NULL); | |
2007 | rprintf(FINFO, "%s is over max-size\n", fname); | |
2008 | } | |
2009 | - return; | |
2010 | + goto cleanup; | |
2011 | } | |
2012 | if (min_size > 0 && F_LENGTH(file) < min_size) { | |
2013 | if (verbose > 1) { | |
2014 | @@ -1421,39 +1485,39 @@ static void recv_generator(char *fname, | |
2015 | fname = f_name(file, NULL); | |
2016 | rprintf(FINFO, "%s is under min-size\n", fname); | |
2017 | } | |
2018 | - return; | |
2019 | + goto cleanup; | |
2020 | } | |
2021 | ||
2022 | if (ignore_existing > 0 && statret == 0) { | |
2023 | if (verbose > 1) | |
2024 | rprintf(FINFO, "%s exists\n", fname); | |
2025 | - return; | |
2026 | + goto cleanup; | |
0870c22a WD |
2027 | } |
2028 | ||
a7592111 | 2029 | if (update_only > 0 && statret == 0 |
0870c22a WD |
2030 | - && cmp_time(st.st_mtime, file->modtime) > 0) { |
2031 | + && cmp_time(sx.st.st_mtime, file->modtime) > 0) { | |
2032 | if (verbose > 1) | |
2033 | rprintf(FINFO, "%s is newer\n", fname); | |
a7592111 WD |
2034 | - return; |
2035 | + goto cleanup; | |
2036 | } | |
2037 | ||
0870c22a WD |
2038 | fnamecmp = fname; |
2039 | fnamecmp_type = FNAMECMP_FNAME; | |
2040 | ||
2041 | - if (statret == 0 && !S_ISREG(st.st_mode)) { | |
87d0091c | 2042 | - if (delete_item(fname, st.st_mode, "regular file", del_opts) != 0) |
a7592111 | 2043 | - return; |
0870c22a | 2044 | + if (statret == 0 && !S_ISREG(sx.st.st_mode)) { |
87d0091c | 2045 | + if (delete_item(fname, sx.st.st_mode, "regular file", del_opts) != 0) |
a7592111 | 2046 | + goto cleanup; |
0870c22a WD |
2047 | statret = -1; |
2048 | stat_errno = ENOENT; | |
2049 | } | |
2050 | ||
2051 | if (statret != 0 && basis_dir[0] != NULL) { | |
2052 | - int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &st, | |
2053 | + int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx, | |
7b80cd0e | 2054 | itemizing, code); |
195ca26e WD |
2055 | if (j == -2) { |
2056 | if (remove_source_files == 1) | |
2057 | goto return_with_success; | |
0870c22a WD |
2058 | - return; |
2059 | + goto cleanup; | |
195ca26e | 2060 | } |
1ed0b5c9 | 2061 | if (j >= 0) { |
0870c22a | 2062 | fnamecmp = fnamecmpbuf; |
a7592111 | 2063 | @@ -1463,7 +1527,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
2064 | } |
2065 | ||
2066 | real_ret = statret; | |
2067 | - real_st = st; | |
2068 | + real_sx = sx; | |
2069 | ||
2070 | if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL | |
2071 | && link_stat(partialptr, &partial_st, 0) == 0 | |
a7592111 | 2072 | @@ -1482,7 +1546,7 @@ static void recv_generator(char *fname, |
0870c22a WD |
2073 | rprintf(FINFO, "fuzzy basis selected for %s: %s\n", |
2074 | fname, fnamecmpbuf); | |
2075 | } | |
1aa236e1 WD |
2076 | - st.st_size = F_LENGTH(fuzzy_file); |
2077 | + sx.st.st_size = F_LENGTH(fuzzy_file); | |
0870c22a WD |
2078 | statret = 0; |
2079 | fnamecmp = fnamecmpbuf; | |
2080 | fnamecmp_type = FNAMECMP_FUZZY; | |
a7592111 WD |
2081 | @@ -1492,45 +1556,50 @@ static void recv_generator(char *fname, |
2082 | if (statret != 0) { | |
2083 | #ifdef SUPPORT_HARD_LINKS | |
2084 | if (preserve_hard_links && F_HLINK_NOT_LAST(file)) | |
2085 | - return; | |
2086 | + goto cleanup; | |
2087 | #endif | |
2088 | if (stat_errno == ENOENT) | |
2089 | goto notify_others; | |
2090 | rsyserr(FERROR, stat_errno, "recv_generator: failed to stat %s", | |
2091 | full_fname(fname)); | |
2092 | - return; | |
2093 | + goto cleanup; | |
0870c22a WD |
2094 | } |
2095 | ||
a7592111 WD |
2096 | - if (append_mode > 0 && st.st_size > F_LENGTH(file)) |
2097 | - return; | |
2098 | + if (append_mode > 0 && sx.st.st_size > F_LENGTH(file)) | |
2099 | + goto cleanup; | |
0870c22a WD |
2100 | |
2101 | if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) | |
2102 | ; | |
2103 | else if (fnamecmp_type == FNAMECMP_FUZZY) | |
2104 | ; | |
2105 | - else if (unchanged_file(fnamecmp, file, &st)) { | |
2106 | + else if (unchanged_file(fnamecmp, file, &sx.st)) { | |
2107 | if (partialptr) { | |
2108 | do_unlink(partialptr); | |
2109 | handle_partial_dir(partialptr, PDIR_DELETE); | |
2110 | } | |
fdb46bbc WD |
2111 | - if (itemizing) |
2112 | - itemize(file, ndx, statret, &st, 0, 0, NULL); | |
2113 | - set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT); | |
2114 | + if (itemizing) { | |
0870c22a | 2115 | +#ifdef SUPPORT_ACLS |
7b80cd0e WD |
2116 | + if (preserve_acls && statret == 0) |
2117 | + get_acl(fnamecmp, &sx); | |
0870c22a | 2118 | +#endif |
fdb46bbc WD |
2119 | + itemize(file, ndx, statret, &sx, 0, 0, NULL); |
2120 | + } | |
0870c22a | 2121 | + set_file_attrs(fname, file, &sx, maybe_ATTRS_REPORT); |
81ecd8e0 | 2122 | #ifdef SUPPORT_HARD_LINKS |
1aa236e1 | 2123 | if (preserve_hard_links && F_IS_HLINKED(file)) |
7b80cd0e WD |
2124 | - finish_hard_link(file, fname, &st, itemizing, code, -1); |
2125 | + finish_hard_link(file, fname, &sx.st, itemizing, code, -1); | |
81ecd8e0 | 2126 | #endif |
195ca26e WD |
2127 | if (remove_source_files != 1) |
2128 | - return; | |
2129 | + goto cleanup; | |
2130 | return_with_success: | |
dfb2ddef | 2131 | if (!dry_run) |
a7592111 | 2132 | send_msg_int(MSG_SUCCESS, ndx + cur_flist->ndx_start); |
0870c22a WD |
2133 | - return; |
2134 | + goto cleanup; | |
2135 | } | |
2136 | ||
2137 | prepare_to_open: | |
2138 | if (partialptr) { | |
2139 | - st = partial_st; | |
2140 | + sx.st = partial_st; | |
2141 | fnamecmp = partialptr; | |
2142 | fnamecmp_type = FNAMECMP_PARTIAL_DIR; | |
2143 | statret = 0; | |
a7592111 | 2144 | @@ -1555,16 +1624,20 @@ static void recv_generator(char *fname, |
0870c22a | 2145 | /* pretend the file didn't exist */ |
81ecd8e0 | 2146 | #ifdef SUPPORT_HARD_LINKS |
49551128 | 2147 | if (preserve_hard_links && F_HLINK_NOT_LAST(file)) |
0870c22a WD |
2148 | - return; |
2149 | + goto cleanup; | |
81ecd8e0 | 2150 | #endif |
0870c22a WD |
2151 | statret = real_ret = -1; |
2152 | +#ifdef SUPPORT_ACLS | |
2153 | + if (preserve_acls && ACL_READY(sx)) | |
98ccc74a | 2154 | + free_acl(&sx); |
0870c22a WD |
2155 | +#endif |
2156 | goto notify_others; | |
2157 | } | |
2158 | ||
a7592111 | 2159 | if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) { |
0870c22a WD |
2160 | if (!(backupptr = get_backup_name(fname))) { |
2161 | close(fd); | |
2162 | - return; | |
2163 | + goto cleanup; | |
2164 | } | |
2165 | if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) { | |
2166 | close(fd); | |
a7592111 | 2167 | @@ -1575,7 +1648,7 @@ static void recv_generator(char *fname, |
0870c22a | 2168 | full_fname(backupptr)); |
70891d26 | 2169 | unmake_file(back_file); |
0870c22a WD |
2170 | close(fd); |
2171 | - return; | |
2172 | + goto cleanup; | |
2173 | } | |
2174 | if ((f_copy = do_open(backupptr, | |
2175 | O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) { | |
a7592111 | 2176 | @@ -1583,14 +1656,14 @@ static void recv_generator(char *fname, |
0870c22a | 2177 | full_fname(backupptr)); |
70891d26 | 2178 | unmake_file(back_file); |
0870c22a WD |
2179 | close(fd); |
2180 | - return; | |
2181 | + goto cleanup; | |
2182 | } | |
2183 | fnamecmp_type = FNAMECMP_BACKUP; | |
2184 | } | |
2185 | ||
2186 | if (verbose > 3) { | |
2187 | rprintf(FINFO, "gen mapped %s of size %.0f\n", | |
2188 | - fnamecmp, (double)st.st_size); | |
2189 | + fnamecmp, (double)sx.st.st_size); | |
2190 | } | |
2191 | ||
2192 | if (verbose > 2) | |
a7592111 | 2193 | @@ -1614,26 +1687,34 @@ static void recv_generator(char *fname, |
0870c22a WD |
2194 | iflags |= ITEM_BASIS_TYPE_FOLLOWS; |
2195 | if (fnamecmp_type == FNAMECMP_FUZZY) | |
2196 | iflags |= ITEM_XNAME_FOLLOWS; | |
2197 | - itemize(file, -1, real_ret, &real_st, iflags, fnamecmp_type, | |
2198 | +#ifdef SUPPORT_ACLS | |
2199 | + if (preserve_acls && real_ret == 0) | |
b6c2bb12 | 2200 | + get_acl(fnamecmp, &real_sx); |
0870c22a WD |
2201 | +#endif |
2202 | + itemize(file, -1, real_ret, &real_sx, iflags, fnamecmp_type, | |
b80daf10 | 2203 | fuzzy_file ? fuzzy_file->basename : NULL); |
0870c22a WD |
2204 | +#ifdef SUPPORT_ACLS |
2205 | + if (preserve_acls) | |
98ccc74a | 2206 | + free_acl(&real_sx); |
0870c22a WD |
2207 | +#endif |
2208 | } | |
2209 | ||
2210 | if (!do_xfers) { | |
7b80cd0e | 2211 | #ifdef SUPPORT_HARD_LINKS |
1aa236e1 | 2212 | if (preserve_hard_links && F_IS_HLINKED(file)) |
7b80cd0e WD |
2213 | - finish_hard_link(file, fname, &st, itemizing, code, -1); |
2214 | + finish_hard_link(file, fname, &sx.st, itemizing, code, -1); | |
81ecd8e0 | 2215 | #endif |
0870c22a WD |
2216 | - return; |
2217 | + goto cleanup; | |
2218 | } | |
2219 | if (read_batch) | |
2220 | - return; | |
2221 | + goto cleanup; | |
2222 | ||
2223 | if (statret != 0 || whole_file) { | |
2224 | write_sum_head(f_out, NULL); | |
2225 | - return; | |
2226 | + goto cleanup; | |
2227 | } | |
2228 | ||
2229 | - generate_and_send_sums(fd, st.st_size, f_out, f_copy); | |
2230 | + generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy); | |
2231 | ||
2232 | if (f_copy >= 0) { | |
2233 | close(f_copy); | |
a7592111 | 2234 | @@ -1646,6 +1727,13 @@ static void recv_generator(char *fname, |
0870c22a WD |
2235 | } |
2236 | ||
2237 | close(fd); | |
2238 | + | |
2239 | + cleanup: | |
2240 | +#ifdef SUPPORT_ACLS | |
2241 | + if (preserve_acls) | |
98ccc74a | 2242 | + free_acl(&sx); |
0870c22a WD |
2243 | +#endif |
2244 | + return; | |
2245 | } | |
2246 | ||
a7592111 WD |
2247 | void generate_files(int f_out, char *local_name) |
2248 | @@ -1708,6 +1796,8 @@ void generate_files(int f_out, char *loc | |
26c810d8 WD |
2249 | * notice that and let us know via the redo pipe (or its closing). */ |
2250 | ignore_timeout = 1; | |
2251 | ||
2252 | + dflt_perms = (ACCESSPERMS & ~orig_umask); | |
2253 | + | |
a7592111 WD |
2254 | do { |
2255 | if (incremental && delete_during && cur_flist->ndx_start) { | |
2256 | struct file_struct *fp = dir_flist->files[cur_flist->parent_ndx]; | |
0870c22a WD |
2257 | --- old/hlink.c |
2258 | +++ new/hlink.c | |
70891d26 WD |
2259 | @@ -27,6 +27,7 @@ extern int verbose; |
2260 | extern int dry_run; | |
195ca26e | 2261 | extern int do_xfers; |
0870c22a WD |
2262 | extern int link_dest; |
2263 | +extern int preserve_acls; | |
2264 | extern int make_backups; | |
7c15d5aa | 2265 | extern int protocol_version; |
195ca26e | 2266 | extern int remove_source_files; |
7e27b6c0 | 2267 | @@ -268,15 +269,19 @@ void match_hard_links(void) |
81ecd8e0 | 2268 | } |
0870c22a | 2269 | |
0870c22a | 2270 | static int maybe_hard_link(struct file_struct *file, int ndx, |
81ecd8e0 WD |
2271 | - const char *fname, int statret, STRUCT_STAT *stp, |
2272 | + const char *fname, int statret, statx *sxp, | |
7b80cd0e WD |
2273 | const char *oldname, STRUCT_STAT *old_stp, |
2274 | const char *realname, int itemizing, enum logcode code) | |
0870c22a WD |
2275 | { |
2276 | if (statret == 0) { | |
7b80cd0e WD |
2277 | - if (stp->st_dev == old_stp->st_dev |
2278 | - && stp->st_ino == old_stp->st_ino) { | |
2279 | + if (sxp->st.st_dev == old_stp->st_dev | |
2280 | + && sxp->st.st_ino == old_stp->st_ino) { | |
0870c22a | 2281 | if (itemizing) { |
81ecd8e0 | 2282 | - itemize(file, ndx, statret, stp, |
0870c22a WD |
2283 | +#ifdef SUPPORT_ACLS |
2284 | + if (preserve_acls && !ACL_READY(*sxp)) | |
98ccc74a | 2285 | + get_acl(fname, sxp); |
0870c22a WD |
2286 | +#endif |
2287 | + itemize(file, ndx, statret, sxp, | |
2288 | ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, | |
2289 | 0, ""); | |
2290 | } | |
7e27b6c0 | 2291 | @@ -297,7 +302,11 @@ static int maybe_hard_link(struct file_s |
0870c22a | 2292 | |
7b80cd0e WD |
2293 | if (hard_link_one(file, fname, oldname, 0)) { |
2294 | if (itemizing) { | |
2295 | - itemize(file, ndx, statret, stp, | |
2296 | +#ifdef SUPPORT_ACLS | |
2297 | + if (preserve_acls && statret == 0 && !ACL_READY(*sxp)) | |
2298 | + get_acl(fname, sxp); | |
2299 | +#endif | |
2300 | + itemize(file, ndx, statret, sxp, | |
2301 | ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS, 0, | |
2302 | realname); | |
2303 | } | |
7e27b6c0 | 2304 | @@ -311,7 +320,7 @@ static int maybe_hard_link(struct file_s |
7b80cd0e WD |
2305 | /* Only called if FLAG_HLINKED is set and FLAG_HLINK_FIRST is not. Returns: |
2306 | * 0 = process the file, 1 = skip the file, -1 = error occurred. */ | |
81ecd8e0 WD |
2307 | int hard_link_check(struct file_struct *file, int ndx, const char *fname, |
2308 | - int statret, STRUCT_STAT *stp, int itemizing, | |
0870c22a | 2309 | + int statret, statx *sxp, int itemizing, |
7b80cd0e | 2310 | enum logcode code) |
0870c22a | 2311 | { |
7b80cd0e | 2312 | STRUCT_STAT prev_st; |
7e27b6c0 | 2313 | @@ -362,18 +371,20 @@ int hard_link_check(struct file_struct * |
7b80cd0e WD |
2314 | if (statret < 0 && basis_dir[0] != NULL) { |
2315 | /* If we match an alt-dest item, we don't output this as a change. */ | |
2316 | char cmpbuf[MAXPATHLEN]; | |
2317 | - STRUCT_STAT alt_st; | |
2318 | + statx alt_sx; | |
2319 | int j = 0; | |
0870c22a | 2320 | +#ifdef SUPPORT_ACLS |
7b80cd0e | 2321 | + alt_sx.acc_acl = alt_sx.def_acl = NULL; |
0870c22a | 2322 | +#endif |
7b80cd0e WD |
2323 | do { |
2324 | pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname); | |
2325 | - if (link_stat(cmpbuf, &alt_st, 0) < 0) | |
2326 | + if (link_stat(cmpbuf, &alt_sx.st, 0) < 0) | |
2327 | continue; | |
2328 | if (link_dest) { | |
2329 | - if (prev_st.st_dev != alt_st.st_dev | |
2330 | - || prev_st.st_ino != alt_st.st_ino) | |
2331 | + if (prev_st.st_dev != alt_sx.st.st_dev | |
2332 | + || prev_st.st_ino != alt_sx.st.st_ino) | |
2333 | continue; | |
2334 | statret = 1; | |
2335 | - *stp = alt_st; | |
2336 | if (verbose < 2 || !stdout_format_has_i) { | |
2337 | itemizing = 0; | |
2338 | code = FNONE; | |
7e27b6c0 | 2339 | @@ -382,16 +393,36 @@ int hard_link_check(struct file_struct * |
7b80cd0e WD |
2340 | } |
2341 | break; | |
0870c22a | 2342 | } |
7b80cd0e WD |
2343 | - if (!unchanged_file(cmpbuf, file, &alt_st)) |
2344 | + if (!unchanged_file(cmpbuf, file, &alt_sx.st)) | |
2345 | continue; | |
2346 | statret = 1; | |
2347 | - *stp = alt_st; | |
2348 | - if (unchanged_attrs(file, &alt_st)) | |
0870c22a | 2349 | +#ifdef SUPPORT_ACLS |
7b80cd0e WD |
2350 | + if (preserve_acls) |
2351 | + get_acl(cmpbuf, &alt_sx); | |
2352 | +#endif | |
2353 | + if (unchanged_attrs(file, &alt_sx)) | |
2354 | break; | |
2355 | } while (basis_dir[++j] != NULL); | |
2356 | + if (statret == 1) { | |
2357 | + sxp->st = alt_sx.st; | |
2358 | +#ifdef SUPPORT_ACLS | |
2359 | + if (preserve_acls) { | |
2360 | + if (!ACL_READY(*sxp)) | |
2361 | + get_acl(cmpbuf, sxp); | |
2362 | + else { | |
2363 | + sxp->acc_acl = alt_sx.acc_acl; | |
2364 | + sxp->def_acl = alt_sx.def_acl; | |
2365 | + } | |
2366 | + } | |
2367 | +#endif | |
2368 | + } | |
2369 | +#ifdef SUPPORT_ACLS | |
2370 | + else if (preserve_acls) | |
2371 | + free_acl(&alt_sx); | |
0870c22a | 2372 | +#endif |
0870c22a | 2373 | } |
7b80cd0e WD |
2374 | |
2375 | - if (maybe_hard_link(file, ndx, fname, statret, stp, prev_name, &prev_st, | |
2376 | + if (maybe_hard_link(file, ndx, fname, statret, sxp, prev_name, &prev_st, | |
2377 | realname, itemizing, code) < 0) | |
2378 | return -1; | |
2379 | ||
7e27b6c0 | 2380 | @@ -426,7 +457,8 @@ void finish_hard_link(struct file_struct |
7b80cd0e WD |
2381 | STRUCT_STAT *stp, int itemizing, enum logcode code, |
2382 | int alt_dest) | |
81ecd8e0 | 2383 | { |
7b80cd0e WD |
2384 | - STRUCT_STAT st, prev_st; |
2385 | + statx prev_sx; | |
0870c22a | 2386 | + STRUCT_STAT st; |
7b80cd0e WD |
2387 | char alt_name[MAXPATHLEN], *prev_name; |
2388 | const char *our_name; | |
2389 | int prev_statret, ndx, prev_ndx = F_HL_PREV(file); | |
7e27b6c0 | 2390 | @@ -450,14 +482,24 @@ void finish_hard_link(struct file_struct |
7b80cd0e WD |
2391 | } else |
2392 | our_name = fname; | |
0870c22a | 2393 | |
7b80cd0e WD |
2394 | +#ifdef SUPPORT_ACLS |
2395 | + prev_sx.acc_acl = prev_sx.def_acl = NULL; | |
2396 | +#endif | |
2397 | + | |
2398 | while ((ndx = prev_ndx) >= 0) { | |
2399 | + int val; | |
2400 | file = FPTR(ndx); | |
2401 | file->flags = (file->flags & ~FLAG_HLINK_FIRST) | FLAG_HLINK_DONE; | |
2402 | prev_ndx = F_HL_PREV(file); | |
2403 | prev_name = f_name(file, NULL); | |
2404 | - prev_statret = link_stat(prev_name, &prev_st, 0); | |
2405 | - if (maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_st, | |
2406 | - our_name, stp, fname, itemizing, code) < 0) | |
2407 | + prev_statret = link_stat(prev_name, &prev_sx.st, 0); | |
2408 | + val = maybe_hard_link(file, ndx, prev_name, prev_statret, &prev_sx, | |
2409 | + our_name, stp, fname, itemizing, code); | |
0870c22a WD |
2410 | +#ifdef SUPPORT_ACLS |
2411 | + if (preserve_acls) | |
7b80cd0e | 2412 | + free_acl(&prev_sx); |
0870c22a | 2413 | +#endif |
7b80cd0e WD |
2414 | + if (val < 0) |
2415 | continue; | |
dfb2ddef WD |
2416 | if (remove_source_files == 1 && do_xfers) |
2417 | send_msg_int(MSG_SUCCESS, ndx); | |
9a7eef96 WD |
2418 | --- old/lib/sysacls.c |
2419 | +++ new/lib/sysacls.c | |
131abbd3 | 2420 | @@ -0,0 +1,3251 @@ |
0870c22a WD |
2421 | +/* |
2422 | + Unix SMB/CIFS implementation. | |
2423 | + Samba system utilities for ACL support. | |
2424 | + Copyright (C) Jeremy Allison 2000. | |
2425 | + | |
2426 | + This program is free software; you can redistribute it and/or modify | |
2427 | + it under the terms of the GNU General Public License as published by | |
2428 | + the Free Software Foundation; either version 2 of the License, or | |
2429 | + (at your option) any later version. | |
2430 | + | |
2431 | + This program is distributed in the hope that it will be useful, | |
2432 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2433 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2434 | + GNU General Public License for more details. | |
2435 | + | |
2436 | + You should have received a copy of the GNU General Public License | |
2437 | + along with this program; if not, write to the Free Software | |
2438 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
2439 | +*/ | |
fa26e11c | 2440 | + |
0f6733d8 | 2441 | +#include "rsync.h" |
252945ef | 2442 | +#include "sysacls.h" /****** ADDED ******/ |
fa26e11c | 2443 | + |
131abbd3 WD |
2444 | +#ifdef SUPPORT_ACLS |
2445 | + | |
252945ef | 2446 | +/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/ |
f42b0645 WD |
2447 | +#ifdef DEBUG |
2448 | +#undef DEBUG | |
2449 | +#endif | |
2450 | +#define DEBUG(x,y) | |
2451 | + | |
0f6733d8 WD |
2452 | +void SAFE_FREE(void *mem) |
2453 | +{ | |
2454 | + if (mem) | |
2455 | + free(mem); | |
2456 | +} | |
fa26e11c | 2457 | + |
5ca9317d WD |
2458 | +char *uidtoname(uid_t uid) |
2459 | +{ | |
2460 | + static char idbuf[12]; | |
2461 | + struct passwd *pw; | |
2462 | + | |
2463 | + if ((pw = getpwuid(uid)) == NULL) { | |
2464 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid); | |
2465 | + return idbuf; | |
2466 | + } | |
2467 | + return pw->pw_name; | |
2468 | +} | |
252945ef | 2469 | +/****** EXTRAS -- END ******/ |
5ca9317d | 2470 | + |
0f6733d8 WD |
2471 | +/* |
2472 | + This file wraps all differing system ACL interfaces into a consistent | |
2473 | + one based on the POSIX interface. It also returns the correct errors | |
2474 | + for older UNIX systems that don't support ACLs. | |
fa26e11c | 2475 | + |
0f6733d8 | 2476 | + The interfaces that each ACL implementation must support are as follows : |
fa26e11c | 2477 | + |
0f6733d8 WD |
2478 | + int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
2479 | + int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) | |
2480 | + int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p | |
2481 | + void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) | |
2482 | + SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) | |
2483 | + SMB_ACL_T sys_acl_get_fd(int fd) | |
2484 | + int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); | |
2485 | + int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
2486 | + char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) | |
2487 | + SMB_ACL_T sys_acl_init( int count) | |
2488 | + int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) | |
2489 | + int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) | |
2490 | + int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) | |
2491 | + int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) | |
2492 | + int sys_acl_valid( SMB_ACL_T theacl ) | |
2493 | + int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
2494 | + int sys_acl_set_fd( int fd, SMB_ACL_T theacl) | |
2495 | + int sys_acl_delete_def_file(const char *path) | |
fa26e11c | 2496 | + |
0f6733d8 WD |
2497 | + This next one is not POSIX complient - but we *have* to have it ! |
2498 | + More POSIX braindamage. | |
fa26e11c | 2499 | + |
0f6733d8 | 2500 | + int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 2501 | + |
0f6733d8 WD |
2502 | + The generic POSIX free is the following call. We split this into |
2503 | + several different free functions as we may need to add tag info | |
2504 | + to structures when emulating the POSIX interface. | |
fa26e11c | 2505 | + |
0f6733d8 | 2506 | + int sys_acl_free( void *obj_p) |
fa26e11c | 2507 | + |
0f6733d8 | 2508 | + The calls we actually use are : |
fa26e11c | 2509 | + |
0f6733d8 WD |
2510 | + int sys_acl_free_text(char *text) - free acl_to_text |
2511 | + int sys_acl_free_acl(SMB_ACL_T posix_acl) | |
2512 | + int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype) | |
fa26e11c | 2513 | + |
0f6733d8 | 2514 | +*/ |
fa26e11c | 2515 | + |
0f6733d8 | 2516 | +#if defined(HAVE_POSIX_ACLS) |
fa26e11c | 2517 | + |
0f6733d8 | 2518 | +/* Identity mapping - easy. */ |
fa26e11c | 2519 | + |
0f6733d8 | 2520 | +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 2521 | +{ |
0f6733d8 | 2522 | + return acl_get_entry( the_acl, entry_id, entry_p); |
fa26e11c WD |
2523 | +} |
2524 | + | |
0f6733d8 | 2525 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c | 2526 | +{ |
0f6733d8 | 2527 | + return acl_get_tag_type( entry_d, tag_type_p); |
fa26e11c WD |
2528 | +} |
2529 | + | |
0f6733d8 | 2530 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c | 2531 | +{ |
0f6733d8 | 2532 | + return acl_get_permset( entry_d, permset_p); |
fa26e11c WD |
2533 | +} |
2534 | + | |
0f6733d8 | 2535 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 2536 | +{ |
0f6733d8 | 2537 | + return acl_get_qualifier( entry_d); |
fa26e11c WD |
2538 | +} |
2539 | + | |
0f6733d8 | 2540 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 2541 | +{ |
0f6733d8 | 2542 | + return acl_get_file( path_p, type); |
fa26e11c WD |
2543 | +} |
2544 | + | |
2545 | +SMB_ACL_T sys_acl_get_fd(int fd) | |
2546 | +{ | |
2547 | + return acl_get_fd(fd); | |
2548 | +} | |
2549 | + | |
2550 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) | |
2551 | +{ | |
2552 | + return acl_clear_perms(permset); | |
2553 | +} | |
2554 | + | |
0f6733d8 | 2555 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2556 | +{ |
2557 | + return acl_add_perm(permset, perm); | |
2558 | +} | |
2559 | + | |
0f6733d8 | 2560 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2561 | +{ |
2562 | +#if defined(HAVE_ACL_GET_PERM_NP) | |
0f6733d8 WD |
2563 | + /* |
2564 | + * Required for TrustedBSD-based ACL implementations where | |
fa26e11c | 2565 | + * non-POSIX.1e functions are denoted by a _np (non-portable) |
0f6733d8 WD |
2566 | + * suffix. |
2567 | + */ | |
fa26e11c WD |
2568 | + return acl_get_perm_np(permset, perm); |
2569 | +#else | |
2570 | + return acl_get_perm(permset, perm); | |
2571 | +#endif | |
2572 | +} | |
2573 | + | |
0f6733d8 | 2574 | +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) |
fa26e11c | 2575 | +{ |
0f6733d8 | 2576 | + return acl_to_text( the_acl, plen); |
fa26e11c WD |
2577 | +} |
2578 | + | |
0f6733d8 | 2579 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
2580 | +{ |
2581 | + return acl_init(count); | |
2582 | +} | |
2583 | + | |
0f6733d8 | 2584 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
2585 | +{ |
2586 | + return acl_create_entry(pacl, pentry); | |
2587 | +} | |
2588 | + | |
0f6733d8 | 2589 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
2590 | +{ |
2591 | + return acl_set_tag_type(entry, tagtype); | |
2592 | +} | |
2593 | + | |
0f6733d8 | 2594 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
2595 | +{ |
2596 | + return acl_set_qualifier(entry, qual); | |
2597 | +} | |
2598 | + | |
0f6733d8 | 2599 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
2600 | +{ |
2601 | + return acl_set_permset(entry, permset); | |
2602 | +} | |
2603 | + | |
0f6733d8 | 2604 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c WD |
2605 | +{ |
2606 | + return acl_valid(theacl); | |
2607 | +} | |
2608 | + | |
2609 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) | |
2610 | +{ | |
2611 | + return acl_set_file(name, acltype, theacl); | |
2612 | +} | |
2613 | + | |
0f6733d8 | 2614 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
2615 | +{ |
2616 | + return acl_set_fd(fd, theacl); | |
2617 | +} | |
2618 | + | |
2619 | +int sys_acl_delete_def_file(const char *name) | |
2620 | +{ | |
2621 | + return acl_delete_def_file(name); | |
2622 | +} | |
2623 | + | |
2624 | +int sys_acl_free_text(char *text) | |
2625 | +{ | |
2626 | + return acl_free(text); | |
2627 | +} | |
2628 | + | |
0f6733d8 | 2629 | +int sys_acl_free_acl(SMB_ACL_T the_acl) |
fa26e11c WD |
2630 | +{ |
2631 | + return acl_free(the_acl); | |
2632 | +} | |
2633 | + | |
1f839b40 | 2634 | +int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
2635 | +{ |
2636 | + return acl_free(qual); | |
2637 | +} | |
2638 | + | |
2639 | +#elif defined(HAVE_TRU64_ACLS) | |
0f6733d8 WD |
2640 | +/* |
2641 | + * The interface to DEC/Compaq Tru64 UNIX ACLs | |
fa26e11c WD |
2642 | + * is based on Draft 13 of the POSIX spec which is |
2643 | + * slightly different from the Draft 16 interface. | |
0f6733d8 | 2644 | + * |
fa26e11c WD |
2645 | + * Also, some of the permset manipulation functions |
2646 | + * such as acl_clear_perm() and acl_add_perm() appear | |
2647 | + * to be broken on Tru64 so we have to manipulate | |
0f6733d8 WD |
2648 | + * the permission bits in the permset directly. |
2649 | + */ | |
2650 | +int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p) | |
fa26e11c | 2651 | +{ |
0f6733d8 | 2652 | + SMB_ACL_ENTRY_T entry; |
fa26e11c WD |
2653 | + |
2654 | + if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) { | |
2655 | + return -1; | |
2656 | + } | |
2657 | + | |
2658 | + errno = 0; | |
2659 | + if ((entry = acl_get_entry(the_acl)) != NULL) { | |
2660 | + *entry_p = entry; | |
2661 | + return 1; | |
2662 | + } | |
2663 | + | |
2664 | + return errno ? -1 : 0; | |
2665 | +} | |
2666 | + | |
0f6733d8 | 2667 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c | 2668 | +{ |
0f6733d8 | 2669 | + return acl_get_tag_type( entry_d, tag_type_p); |
fa26e11c WD |
2670 | +} |
2671 | + | |
0f6733d8 | 2672 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c | 2673 | +{ |
0f6733d8 | 2674 | + return acl_get_permset( entry_d, permset_p); |
fa26e11c WD |
2675 | +} |
2676 | + | |
0f6733d8 | 2677 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 2678 | +{ |
0f6733d8 | 2679 | + return acl_get_qualifier( entry_d); |
fa26e11c WD |
2680 | +} |
2681 | + | |
0f6733d8 | 2682 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c WD |
2683 | +{ |
2684 | + return acl_get_file((char *)path_p, type); | |
2685 | +} | |
2686 | + | |
0f6733d8 | 2687 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c WD |
2688 | +{ |
2689 | + return acl_get_fd(fd, ACL_TYPE_ACCESS); | |
2690 | +} | |
2691 | + | |
0f6733d8 | 2692 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
fa26e11c | 2693 | +{ |
0f6733d8 | 2694 | + *permset = 0; /* acl_clear_perm() is broken on Tru64 */ |
fa26e11c WD |
2695 | + |
2696 | + return 0; | |
2697 | +} | |
2698 | + | |
0f6733d8 | 2699 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2700 | +{ |
2701 | + if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) { | |
2702 | + errno = EINVAL; | |
2703 | + return -1; | |
2704 | + } | |
2705 | + | |
0f6733d8 | 2706 | + *permset |= perm; /* acl_add_perm() is broken on Tru64 */ |
fa26e11c WD |
2707 | + |
2708 | + return 0; | |
2709 | +} | |
2710 | + | |
0f6733d8 | 2711 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
2712 | +{ |
2713 | + return *permset & perm; /* Tru64 doesn't have acl_get_perm() */ | |
2714 | +} | |
2715 | + | |
0f6733d8 | 2716 | +char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen) |
fa26e11c | 2717 | +{ |
0f6733d8 | 2718 | + return acl_to_text( the_acl, plen); |
fa26e11c WD |
2719 | +} |
2720 | + | |
0f6733d8 | 2721 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
2722 | +{ |
2723 | + return acl_init(count); | |
2724 | +} | |
2725 | + | |
0f6733d8 | 2726 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
2727 | +{ |
2728 | + SMB_ACL_ENTRY_T entry; | |
2729 | + | |
2730 | + if ((entry = acl_create_entry(pacl)) == NULL) { | |
2731 | + return -1; | |
2732 | + } | |
2733 | + | |
2734 | + *pentry = entry; | |
2735 | + return 0; | |
2736 | +} | |
2737 | + | |
0f6733d8 | 2738 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
2739 | +{ |
2740 | + return acl_set_tag_type(entry, tagtype); | |
2741 | +} | |
2742 | + | |
0f6733d8 | 2743 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
2744 | +{ |
2745 | + return acl_set_qualifier(entry, qual); | |
2746 | +} | |
2747 | + | |
0f6733d8 | 2748 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
2749 | +{ |
2750 | + return acl_set_permset(entry, permset); | |
2751 | +} | |
2752 | + | |
0f6733d8 | 2753 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c | 2754 | +{ |
0f6733d8 | 2755 | + acl_entry_t entry; |
fa26e11c WD |
2756 | + |
2757 | + return acl_valid(theacl, &entry); | |
2758 | +} | |
2759 | + | |
0f6733d8 | 2760 | +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
fa26e11c WD |
2761 | +{ |
2762 | + return acl_set_file((char *)name, acltype, theacl); | |
2763 | +} | |
2764 | + | |
0f6733d8 | 2765 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
2766 | +{ |
2767 | + return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl); | |
2768 | +} | |
2769 | + | |
0f6733d8 | 2770 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
2771 | +{ |
2772 | + return acl_delete_def_file((char *)name); | |
2773 | +} | |
2774 | + | |
0f6733d8 | 2775 | +int sys_acl_free_text(char *text) |
fa26e11c | 2776 | +{ |
0f6733d8 WD |
2777 | + /* |
2778 | + * (void) cast and explicit return 0 are for DEC UNIX | |
2779 | + * which just #defines acl_free_text() to be free() | |
2780 | + */ | |
fa26e11c WD |
2781 | + (void) acl_free_text(text); |
2782 | + return 0; | |
2783 | +} | |
2784 | + | |
0f6733d8 | 2785 | +int sys_acl_free_acl(SMB_ACL_T the_acl) |
fa26e11c WD |
2786 | +{ |
2787 | + return acl_free(the_acl); | |
2788 | +} | |
2789 | + | |
0f6733d8 | 2790 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
2791 | +{ |
2792 | + return acl_free_qualifier(qual, tagtype); | |
2793 | +} | |
2794 | + | |
2795 | +#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS) | |
2796 | + | |
0f6733d8 WD |
2797 | +/* |
2798 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
2799 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. | |
2800 | + */ | |
fa26e11c | 2801 | + |
0f6733d8 WD |
2802 | +/* |
2803 | + * Note that while this code implements sufficient functionality | |
fa26e11c WD |
2804 | + * to support the sys_acl_* interfaces it does not provide all |
2805 | + * of the semantics of the POSIX ACL interfaces. | |
2806 | + * | |
2807 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned | |
2808 | + * from a call to sys_acl_get_entry() should not be assumed to be | |
2809 | + * valid after calling any of the following functions, which may | |
2810 | + * reorder the entries in the ACL. | |
2811 | + * | |
2812 | + * sys_acl_valid() | |
2813 | + * sys_acl_set_file() | |
2814 | + * sys_acl_set_fd() | |
2815 | + */ | |
2816 | + | |
0f6733d8 WD |
2817 | +/* |
2818 | + * The only difference between Solaris and UnixWare / OpenUNIX is | |
2819 | + * that the #defines for the ACL operations have different names | |
2820 | + */ | |
fa26e11c WD |
2821 | +#if defined(HAVE_UNIXWARE_ACLS) |
2822 | + | |
0f6733d8 WD |
2823 | +#define SETACL ACL_SET |
2824 | +#define GETACL ACL_GET | |
2825 | +#define GETACLCNT ACL_CNT | |
fa26e11c WD |
2826 | + |
2827 | +#endif | |
2828 | + | |
2829 | + | |
0f6733d8 | 2830 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
2831 | +{ |
2832 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
2833 | + errno = EINVAL; | |
2834 | + return -1; | |
2835 | + } | |
2836 | + | |
2837 | + if (entry_p == NULL) { | |
2838 | + errno = EINVAL; | |
2839 | + return -1; | |
2840 | + } | |
2841 | + | |
2842 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
2843 | + acl_d->next = 0; | |
2844 | + } | |
2845 | + | |
2846 | + if (acl_d->next < 0) { | |
2847 | + errno = EINVAL; | |
2848 | + return -1; | |
2849 | + } | |
2850 | + | |
2851 | + if (acl_d->next >= acl_d->count) { | |
2852 | + return 0; | |
2853 | + } | |
2854 | + | |
2855 | + *entry_p = &acl_d->acl[acl_d->next++]; | |
2856 | + | |
2857 | + return 1; | |
2858 | +} | |
2859 | + | |
0f6733d8 | 2860 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
2861 | +{ |
2862 | + *type_p = entry_d->a_type; | |
2863 | + | |
2864 | + return 0; | |
2865 | +} | |
2866 | + | |
0f6733d8 | 2867 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
2868 | +{ |
2869 | + *permset_p = &entry_d->a_perm; | |
2870 | + | |
2871 | + return 0; | |
2872 | +} | |
2873 | + | |
0f6733d8 | 2874 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
2875 | +{ |
2876 | + if (entry_d->a_type != SMB_ACL_USER | |
2877 | + && entry_d->a_type != SMB_ACL_GROUP) { | |
2878 | + errno = EINVAL; | |
2879 | + return NULL; | |
2880 | + } | |
2881 | + | |
2882 | + return &entry_d->a_id; | |
2883 | +} | |
2884 | + | |
0f6733d8 WD |
2885 | +/* |
2886 | + * There is no way of knowing what size the ACL returned by | |
fa26e11c WD |
2887 | + * GETACL will be unless you first call GETACLCNT which means |
2888 | + * making an additional system call. | |
2889 | + * | |
2890 | + * In the hope of avoiding the cost of the additional system | |
2891 | + * call in most cases, we initially allocate enough space for | |
2892 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to | |
2893 | + * be too small then we use GETACLCNT to find out the actual | |
0f6733d8 WD |
2894 | + * size, reallocate the ACL buffer, and then call GETACL again. |
2895 | + */ | |
fa26e11c | 2896 | + |
0f6733d8 | 2897 | +#define INITIAL_ACL_SIZE 16 |
fa26e11c | 2898 | + |
0f6733d8 | 2899 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 2900 | +{ |
0f6733d8 WD |
2901 | + SMB_ACL_T acl_d; |
2902 | + int count; /* # of ACL entries allocated */ | |
2903 | + int naccess; /* # of access ACL entries */ | |
2904 | + int ndefault; /* # of default ACL entries */ | |
fa26e11c WD |
2905 | + |
2906 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
2907 | + errno = EINVAL; | |
2908 | + return NULL; | |
2909 | + } | |
2910 | + | |
2911 | + count = INITIAL_ACL_SIZE; | |
2912 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2913 | + return NULL; | |
2914 | + } | |
2915 | + | |
0f6733d8 WD |
2916 | + /* |
2917 | + * If there isn't enough space for the ACL entries we use | |
fa26e11c WD |
2918 | + * GETACLCNT to determine the actual number of ACL entries |
2919 | + * reallocate and try again. This is in a loop because it | |
2920 | + * is possible that someone else could modify the ACL and | |
2921 | + * increase the number of entries between the call to | |
0f6733d8 WD |
2922 | + * GETACLCNT and the call to GETACL. |
2923 | + */ | |
fa26e11c WD |
2924 | + while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0 |
2925 | + && errno == ENOSPC) { | |
2926 | + | |
2927 | + sys_acl_free_acl(acl_d); | |
2928 | + | |
2929 | + if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) { | |
2930 | + return NULL; | |
2931 | + } | |
2932 | + | |
2933 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2934 | + return NULL; | |
2935 | + } | |
2936 | + } | |
2937 | + | |
2938 | + if (count < 0) { | |
2939 | + sys_acl_free_acl(acl_d); | |
2940 | + return NULL; | |
2941 | + } | |
2942 | + | |
0f6733d8 WD |
2943 | + /* |
2944 | + * calculate the number of access and default ACL entries | |
fa26e11c WD |
2945 | + * |
2946 | + * Note: we assume that the acl() system call returned a | |
2947 | + * well formed ACL which is sorted so that all of the | |
0f6733d8 WD |
2948 | + * access ACL entries preceed any default ACL entries |
2949 | + */ | |
fa26e11c WD |
2950 | + for (naccess = 0; naccess < count; naccess++) { |
2951 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
2952 | + break; | |
2953 | + } | |
2954 | + ndefault = count - naccess; | |
0f6733d8 WD |
2955 | + |
2956 | + /* | |
2957 | + * if the caller wants the default ACL we have to copy | |
fa26e11c | 2958 | + * the entries down to the start of the acl[] buffer |
0f6733d8 WD |
2959 | + * and mask out the ACL_DEFAULT flag from the type field |
2960 | + */ | |
fa26e11c | 2961 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
0f6733d8 | 2962 | + int i, j; |
fa26e11c WD |
2963 | + |
2964 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { | |
2965 | + acl_d->acl[i] = acl_d->acl[j]; | |
2966 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; | |
2967 | + } | |
2968 | + | |
2969 | + acl_d->count = ndefault; | |
2970 | + } else { | |
2971 | + acl_d->count = naccess; | |
2972 | + } | |
2973 | + | |
2974 | + return acl_d; | |
2975 | +} | |
2976 | + | |
0f6733d8 | 2977 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 2978 | +{ |
0f6733d8 WD |
2979 | + SMB_ACL_T acl_d; |
2980 | + int count; /* # of ACL entries allocated */ | |
2981 | + int naccess; /* # of access ACL entries */ | |
fa26e11c WD |
2982 | + |
2983 | + count = INITIAL_ACL_SIZE; | |
2984 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2985 | + return NULL; | |
2986 | + } | |
2987 | + | |
2988 | + while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0 | |
2989 | + && errno == ENOSPC) { | |
2990 | + | |
2991 | + sys_acl_free_acl(acl_d); | |
2992 | + | |
2993 | + if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) { | |
2994 | + return NULL; | |
2995 | + } | |
2996 | + | |
2997 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
2998 | + return NULL; | |
2999 | + } | |
3000 | + } | |
3001 | + | |
3002 | + if (count < 0) { | |
3003 | + sys_acl_free_acl(acl_d); | |
3004 | + return NULL; | |
3005 | + } | |
3006 | + | |
0f6733d8 WD |
3007 | + /* |
3008 | + * calculate the number of access ACL entries | |
3009 | + */ | |
fa26e11c WD |
3010 | + for (naccess = 0; naccess < count; naccess++) { |
3011 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
3012 | + break; | |
3013 | + } | |
0f6733d8 | 3014 | + |
fa26e11c WD |
3015 | + acl_d->count = naccess; |
3016 | + | |
3017 | + return acl_d; | |
3018 | +} | |
3019 | + | |
0f6733d8 | 3020 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3021 | +{ |
3022 | + *permset_d = 0; | |
3023 | + | |
3024 | + return 0; | |
3025 | +} | |
3026 | + | |
0f6733d8 | 3027 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
3028 | +{ |
3029 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
3030 | + && perm != SMB_ACL_EXECUTE) { | |
3031 | + errno = EINVAL; | |
3032 | + return -1; | |
3033 | + } | |
3034 | + | |
3035 | + if (permset_d == NULL) { | |
3036 | + errno = EINVAL; | |
3037 | + return -1; | |
3038 | + } | |
3039 | + | |
3040 | + *permset_d |= perm; | |
3041 | + | |
3042 | + return 0; | |
3043 | +} | |
3044 | + | |
0f6733d8 | 3045 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
3046 | +{ |
3047 | + return *permset_d & perm; | |
3048 | +} | |
3049 | + | |
0f6733d8 | 3050 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c | 3051 | +{ |
0f6733d8 WD |
3052 | + int i; |
3053 | + int len, maxlen; | |
3054 | + char *text; | |
fa26e11c | 3055 | + |
0f6733d8 WD |
3056 | + /* |
3057 | + * use an initial estimate of 20 bytes per ACL entry | |
fa26e11c | 3058 | + * when allocating memory for the text representation |
0f6733d8 WD |
3059 | + * of the ACL |
3060 | + */ | |
3061 | + len = 0; | |
3062 | + maxlen = 20 * acl_d->count; | |
252945ef | 3063 | + if ((text = SMB_MALLOC(maxlen)) == NULL) { |
fa26e11c WD |
3064 | + errno = ENOMEM; |
3065 | + return NULL; | |
3066 | + } | |
3067 | + | |
3068 | + for (i = 0; i < acl_d->count; i++) { | |
0f6733d8 | 3069 | + struct acl *ap = &acl_d->acl[i]; |
0f6733d8 WD |
3070 | + struct group *gr; |
3071 | + char tagbuf[12]; | |
3072 | + char idbuf[12]; | |
3073 | + char *tag; | |
3074 | + char *id = ""; | |
3075 | + char perms[4]; | |
3076 | + int nbytes; | |
fa26e11c WD |
3077 | + |
3078 | + switch (ap->a_type) { | |
0f6733d8 WD |
3079 | + /* |
3080 | + * for debugging purposes it's probably more | |
fa26e11c | 3081 | + * useful to dump unknown tag types rather |
0f6733d8 WD |
3082 | + * than just returning an error |
3083 | + */ | |
fa26e11c | 3084 | + default: |
0f6733d8 | 3085 | + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x", |
fa26e11c WD |
3086 | + ap->a_type); |
3087 | + tag = tagbuf; | |
0f6733d8 | 3088 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
3089 | + (long)ap->a_id); |
3090 | + id = idbuf; | |
3091 | + break; | |
3092 | + | |
3093 | + case SMB_ACL_USER: | |
5ca9317d | 3094 | + id = uidtoname(ap->a_id); |
fa26e11c WD |
3095 | + case SMB_ACL_USER_OBJ: |
3096 | + tag = "user"; | |
3097 | + break; | |
3098 | + | |
3099 | + case SMB_ACL_GROUP: | |
3100 | + if ((gr = getgrgid(ap->a_id)) == NULL) { | |
0f6733d8 | 3101 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
3102 | + (long)ap->a_id); |
3103 | + id = idbuf; | |
3104 | + } else { | |
3105 | + id = gr->gr_name; | |
3106 | + } | |
3107 | + case SMB_ACL_GROUP_OBJ: | |
3108 | + tag = "group"; | |
3109 | + break; | |
3110 | + | |
3111 | + case SMB_ACL_OTHER: | |
3112 | + tag = "other"; | |
3113 | + break; | |
3114 | + | |
3115 | + case SMB_ACL_MASK: | |
3116 | + tag = "mask"; | |
3117 | + break; | |
3118 | + | |
3119 | + } | |
3120 | + | |
3121 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; | |
3122 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; | |
3123 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; | |
3124 | + perms[3] = '\0'; | |
3125 | + | |
3126 | + /* <tag> : <qualifier> : rwx \n \0 */ | |
3127 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; | |
3128 | + | |
0f6733d8 WD |
3129 | + /* |
3130 | + * If this entry would overflow the buffer | |
fa26e11c WD |
3131 | + * allocate enough additional memory for this |
3132 | + * entry and an estimate of another 20 bytes | |
0f6733d8 WD |
3133 | + * for each entry still to be processed |
3134 | + */ | |
fa26e11c WD |
3135 | + if ((len + nbytes) > maxlen) { |
3136 | + char *oldtext = text; | |
3137 | + | |
3138 | + maxlen += nbytes + 20 * (acl_d->count - i); | |
3139 | + | |
252945ef | 3140 | + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) { |
0f6733d8 | 3141 | + SAFE_FREE(oldtext); |
fa26e11c WD |
3142 | + errno = ENOMEM; |
3143 | + return NULL; | |
3144 | + } | |
3145 | + } | |
3146 | + | |
0f6733d8 | 3147 | + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); |
fa26e11c WD |
3148 | + len += nbytes - 1; |
3149 | + } | |
3150 | + | |
3151 | + if (len_p) | |
3152 | + *len_p = len; | |
3153 | + | |
3154 | + return text; | |
3155 | +} | |
3156 | + | |
0f6733d8 | 3157 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 3158 | +{ |
0f6733d8 | 3159 | + SMB_ACL_T a; |
fa26e11c WD |
3160 | + |
3161 | + if (count < 0) { | |
3162 | + errno = EINVAL; | |
3163 | + return NULL; | |
3164 | + } | |
3165 | + | |
0f6733d8 WD |
3166 | + /* |
3167 | + * note that since the definition of the structure pointed | |
fa26e11c WD |
3168 | + * to by the SMB_ACL_T includes the first element of the |
3169 | + * acl[] array, this actually allocates an ACL with room | |
0f6733d8 WD |
3170 | + * for (count+1) entries |
3171 | + */ | |
53c1073a | 3172 | + if ((a = (SMB_ACL_T)SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) { |
fa26e11c WD |
3173 | + errno = ENOMEM; |
3174 | + return NULL; | |
3175 | + } | |
3176 | + | |
3177 | + a->size = count + 1; | |
3178 | + a->count = 0; | |
3179 | + a->next = -1; | |
3180 | + | |
3181 | + return a; | |
3182 | +} | |
3183 | + | |
3184 | + | |
0f6733d8 | 3185 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 3186 | +{ |
0f6733d8 WD |
3187 | + SMB_ACL_T acl_d; |
3188 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
3189 | + |
3190 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
3191 | + errno = EINVAL; | |
3192 | + return -1; | |
3193 | + } | |
3194 | + | |
3195 | + if (acl_d->count >= acl_d->size) { | |
3196 | + errno = ENOSPC; | |
3197 | + return -1; | |
3198 | + } | |
3199 | + | |
0f6733d8 WD |
3200 | + entry_d = &acl_d->acl[acl_d->count++]; |
3201 | + entry_d->a_type = 0; | |
3202 | + entry_d->a_id = -1; | |
3203 | + entry_d->a_perm = 0; | |
3204 | + *entry_p = entry_d; | |
fa26e11c WD |
3205 | + |
3206 | + return 0; | |
3207 | +} | |
3208 | + | |
0f6733d8 | 3209 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
3210 | +{ |
3211 | + switch (tag_type) { | |
3212 | + case SMB_ACL_USER: | |
3213 | + case SMB_ACL_USER_OBJ: | |
3214 | + case SMB_ACL_GROUP: | |
3215 | + case SMB_ACL_GROUP_OBJ: | |
3216 | + case SMB_ACL_OTHER: | |
3217 | + case SMB_ACL_MASK: | |
3218 | + entry_d->a_type = tag_type; | |
3219 | + break; | |
3220 | + default: | |
3221 | + errno = EINVAL; | |
3222 | + return -1; | |
3223 | + } | |
3224 | + | |
3225 | + return 0; | |
3226 | +} | |
3227 | + | |
0f6733d8 | 3228 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
3229 | +{ |
3230 | + if (entry_d->a_type != SMB_ACL_GROUP | |
3231 | + && entry_d->a_type != SMB_ACL_USER) { | |
3232 | + errno = EINVAL; | |
3233 | + return -1; | |
3234 | + } | |
3235 | + | |
3236 | + entry_d->a_id = *((id_t *)qual_p); | |
3237 | + | |
3238 | + return 0; | |
3239 | +} | |
3240 | + | |
0f6733d8 | 3241 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3242 | +{ |
3243 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
3244 | + return EINVAL; | |
3245 | + } | |
3246 | + | |
3247 | + entry_d->a_perm = *permset_d; | |
3248 | + | |
3249 | + return 0; | |
3250 | +} | |
3251 | + | |
0f6733d8 WD |
3252 | +/* |
3253 | + * sort the ACL and check it for validity | |
fa26e11c | 3254 | + * |
0f6733d8 | 3255 | + * if it's a minimal ACL with only 4 entries then we |
fa26e11c WD |
3256 | + * need to recalculate the mask permissions to make |
3257 | + * sure that they are the same as the GROUP_OBJ | |
3258 | + * permissions as required by the UnixWare acl() system call. | |
3259 | + * | |
0f6733d8 | 3260 | + * (note: since POSIX allows minimal ACLs which only contain |
fa26e11c WD |
3261 | + * 3 entries - ie there is no mask entry - we should, in theory, |
3262 | + * check for this and add a mask entry if necessary - however | |
3263 | + * we "know" that the caller of this interface always specifies | |
3264 | + * a mask so, in practice "this never happens" (tm) - if it *does* | |
3265 | + * happen aclsort() will fail and return an error and someone will | |
0f6733d8 WD |
3266 | + * have to fix it ...) |
3267 | + */ | |
fa26e11c WD |
3268 | + |
3269 | +static int acl_sort(SMB_ACL_T acl_d) | |
3270 | +{ | |
3271 | + int fixmask = (acl_d->count <= 4); | |
3272 | + | |
3273 | + if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) { | |
3274 | + errno = EINVAL; | |
3275 | + return -1; | |
3276 | + } | |
3277 | + return 0; | |
3278 | +} | |
0f6733d8 WD |
3279 | + |
3280 | +int sys_acl_valid(SMB_ACL_T acl_d) | |
fa26e11c WD |
3281 | +{ |
3282 | + return acl_sort(acl_d); | |
3283 | +} | |
3284 | + | |
0f6733d8 | 3285 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c | 3286 | +{ |
0f6733d8 WD |
3287 | + struct stat s; |
3288 | + struct acl *acl_p; | |
3289 | + int acl_count; | |
3290 | + struct acl *acl_buf = NULL; | |
3291 | + int ret; | |
fa26e11c WD |
3292 | + |
3293 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
3294 | + errno = EINVAL; | |
3295 | + return -1; | |
3296 | + } | |
3297 | + | |
3298 | + if (acl_sort(acl_d) != 0) { | |
3299 | + return -1; | |
3300 | + } | |
3301 | + | |
0f6733d8 WD |
3302 | + acl_p = &acl_d->acl[0]; |
3303 | + acl_count = acl_d->count; | |
fa26e11c | 3304 | + |
0f6733d8 WD |
3305 | + /* |
3306 | + * if it's a directory there is extra work to do | |
3307 | + * since the acl() system call will replace both | |
3308 | + * the access ACLs and the default ACLs (if any) | |
3309 | + */ | |
fa26e11c WD |
3310 | + if (stat(name, &s) != 0) { |
3311 | + return -1; | |
3312 | + } | |
3313 | + if (S_ISDIR(s.st_mode)) { | |
0f6733d8 WD |
3314 | + SMB_ACL_T acc_acl; |
3315 | + SMB_ACL_T def_acl; | |
3316 | + SMB_ACL_T tmp_acl; | |
3317 | + int i; | |
fa26e11c WD |
3318 | + |
3319 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
3320 | + acc_acl = acl_d; | |
3321 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); | |
3322 | + | |
3323 | + } else { | |
3324 | + def_acl = acl_d; | |
3325 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); | |
3326 | + } | |
3327 | + | |
3328 | + if (tmp_acl == NULL) { | |
3329 | + return -1; | |
3330 | + } | |
3331 | + | |
0f6733d8 WD |
3332 | + /* |
3333 | + * allocate a temporary buffer for the complete ACL | |
3334 | + */ | |
fa26e11c | 3335 | + acl_count = acc_acl->count + def_acl->count; |
252945ef | 3336 | + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
fa26e11c WD |
3337 | + |
3338 | + if (acl_buf == NULL) { | |
3339 | + sys_acl_free_acl(tmp_acl); | |
3340 | + errno = ENOMEM; | |
3341 | + return -1; | |
3342 | + } | |
3343 | + | |
0f6733d8 WD |
3344 | + /* |
3345 | + * copy the access control and default entries into the buffer | |
3346 | + */ | |
fa26e11c | 3347 | + memcpy(&acl_buf[0], &acc_acl->acl[0], |
0f6733d8 | 3348 | + acc_acl->count * sizeof(acl_buf[0])); |
fa26e11c WD |
3349 | + |
3350 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], | |
0f6733d8 | 3351 | + def_acl->count * sizeof(acl_buf[0])); |
fa26e11c | 3352 | + |
0f6733d8 WD |
3353 | + /* |
3354 | + * set the ACL_DEFAULT flag on the default entries | |
3355 | + */ | |
fa26e11c WD |
3356 | + for (i = acc_acl->count; i < acl_count; i++) { |
3357 | + acl_buf[i].a_type |= ACL_DEFAULT; | |
3358 | + } | |
3359 | + | |
3360 | + sys_acl_free_acl(tmp_acl); | |
3361 | + | |
3362 | + } else if (type != SMB_ACL_TYPE_ACCESS) { | |
3363 | + errno = EINVAL; | |
3364 | + return -1; | |
3365 | + } | |
3366 | + | |
3367 | + ret = acl(name, SETACL, acl_count, acl_p); | |
3368 | + | |
0f6733d8 | 3369 | + SAFE_FREE(acl_buf); |
fa26e11c WD |
3370 | + |
3371 | + return ret; | |
3372 | +} | |
3373 | + | |
0f6733d8 | 3374 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c WD |
3375 | +{ |
3376 | + if (acl_sort(acl_d) != 0) { | |
3377 | + return -1; | |
3378 | + } | |
3379 | + | |
3380 | + return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]); | |
3381 | +} | |
3382 | + | |
0f6733d8 | 3383 | +int sys_acl_delete_def_file(const char *path) |
fa26e11c | 3384 | +{ |
0f6733d8 WD |
3385 | + SMB_ACL_T acl_d; |
3386 | + int ret; | |
fa26e11c | 3387 | + |
0f6733d8 WD |
3388 | + /* |
3389 | + * fetching the access ACL and rewriting it has | |
3390 | + * the effect of deleting the default ACL | |
3391 | + */ | |
fa26e11c WD |
3392 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
3393 | + return -1; | |
3394 | + } | |
3395 | + | |
3396 | + ret = acl(path, SETACL, acl_d->count, acl_d->acl); | |
3397 | + | |
3398 | + sys_acl_free_acl(acl_d); | |
0f6733d8 | 3399 | + |
fa26e11c WD |
3400 | + return ret; |
3401 | +} | |
3402 | + | |
0f6733d8 | 3403 | +int sys_acl_free_text(char *text) |
fa26e11c | 3404 | +{ |
0f6733d8 | 3405 | + SAFE_FREE(text); |
fa26e11c WD |
3406 | + return 0; |
3407 | +} | |
3408 | + | |
0f6733d8 | 3409 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c | 3410 | +{ |
0f6733d8 | 3411 | + SAFE_FREE(acl_d); |
fa26e11c WD |
3412 | + return 0; |
3413 | +} | |
3414 | + | |
53c1073a | 3415 | +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
3416 | +{ |
3417 | + return 0; | |
3418 | +} | |
3419 | + | |
3420 | +#elif defined(HAVE_HPUX_ACLS) | |
3421 | +#include <dl.h> | |
3422 | + | |
0f6733d8 WD |
3423 | +/* |
3424 | + * Based on the Solaris/SCO code - with modifications. | |
3425 | + */ | |
fa26e11c | 3426 | + |
0f6733d8 WD |
3427 | +/* |
3428 | + * Note that while this code implements sufficient functionality | |
fa26e11c WD |
3429 | + * to support the sys_acl_* interfaces it does not provide all |
3430 | + * of the semantics of the POSIX ACL interfaces. | |
3431 | + * | |
3432 | + * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned | |
3433 | + * from a call to sys_acl_get_entry() should not be assumed to be | |
3434 | + * valid after calling any of the following functions, which may | |
3435 | + * reorder the entries in the ACL. | |
3436 | + * | |
3437 | + * sys_acl_valid() | |
3438 | + * sys_acl_set_file() | |
3439 | + * sys_acl_set_fd() | |
3440 | + */ | |
3441 | + | |
0f6733d8 WD |
3442 | +/* This checks if the POSIX ACL system call is defined */ |
3443 | +/* which basically corresponds to whether JFS 3.3 or */ | |
3444 | +/* higher is installed. If acl() was called when it */ | |
3445 | +/* isn't defined, it causes the process to core dump */ | |
3446 | +/* so it is important to check this and avoid acl() */ | |
3447 | +/* calls if it isn't there. */ | |
fa26e11c WD |
3448 | + |
3449 | +static BOOL hpux_acl_call_presence(void) | |
3450 | +{ | |
3451 | + | |
3452 | + shl_t handle = NULL; | |
3453 | + void *value; | |
3454 | + int ret_val=0; | |
3455 | + static BOOL already_checked=0; | |
3456 | + | |
0f6733d8 | 3457 | + if(already_checked) |
fa26e11c WD |
3458 | + return True; |
3459 | + | |
3460 | + | |
3461 | + ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value); | |
3462 | + | |
0f6733d8 | 3463 | + if(ret_val != 0) { |
fa26e11c WD |
3464 | + DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n", |
3465 | + ret_val, errno, strerror(errno))); | |
3466 | + DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n")); | |
3467 | + return False; | |
3468 | + } | |
3469 | + | |
3470 | + DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n")); | |
3471 | + | |
3472 | + already_checked = True; | |
3473 | + return True; | |
3474 | +} | |
3475 | + | |
0f6733d8 | 3476 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
3477 | +{ |
3478 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
3479 | + errno = EINVAL; | |
3480 | + return -1; | |
3481 | + } | |
3482 | + | |
3483 | + if (entry_p == NULL) { | |
3484 | + errno = EINVAL; | |
3485 | + return -1; | |
3486 | + } | |
3487 | + | |
3488 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
3489 | + acl_d->next = 0; | |
3490 | + } | |
3491 | + | |
3492 | + if (acl_d->next < 0) { | |
3493 | + errno = EINVAL; | |
3494 | + return -1; | |
3495 | + } | |
3496 | + | |
3497 | + if (acl_d->next >= acl_d->count) { | |
3498 | + return 0; | |
3499 | + } | |
3500 | + | |
3501 | + *entry_p = &acl_d->acl[acl_d->next++]; | |
3502 | + | |
3503 | + return 1; | |
3504 | +} | |
3505 | + | |
0f6733d8 | 3506 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
3507 | +{ |
3508 | + *type_p = entry_d->a_type; | |
3509 | + | |
3510 | + return 0; | |
3511 | +} | |
3512 | + | |
0f6733d8 | 3513 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
3514 | +{ |
3515 | + *permset_p = &entry_d->a_perm; | |
3516 | + | |
3517 | + return 0; | |
3518 | +} | |
3519 | + | |
0f6733d8 | 3520 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
3521 | +{ |
3522 | + if (entry_d->a_type != SMB_ACL_USER | |
3523 | + && entry_d->a_type != SMB_ACL_GROUP) { | |
3524 | + errno = EINVAL; | |
3525 | + return NULL; | |
3526 | + } | |
3527 | + | |
3528 | + return &entry_d->a_id; | |
3529 | +} | |
3530 | + | |
0f6733d8 WD |
3531 | +/* |
3532 | + * There is no way of knowing what size the ACL returned by | |
fa26e11c WD |
3533 | + * ACL_GET will be unless you first call ACL_CNT which means |
3534 | + * making an additional system call. | |
3535 | + * | |
3536 | + * In the hope of avoiding the cost of the additional system | |
3537 | + * call in most cases, we initially allocate enough space for | |
3538 | + * an ACL with INITIAL_ACL_SIZE entries. If this turns out to | |
3539 | + * be too small then we use ACL_CNT to find out the actual | |
3540 | + * size, reallocate the ACL buffer, and then call ACL_GET again. | |
3541 | + */ | |
3542 | + | |
0f6733d8 | 3543 | +#define INITIAL_ACL_SIZE 16 |
fa26e11c | 3544 | + |
0f6733d8 | 3545 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 3546 | +{ |
0f6733d8 WD |
3547 | + SMB_ACL_T acl_d; |
3548 | + int count; /* # of ACL entries allocated */ | |
3549 | + int naccess; /* # of access ACL entries */ | |
3550 | + int ndefault; /* # of default ACL entries */ | |
fa26e11c | 3551 | + |
0f6733d8 WD |
3552 | + if(hpux_acl_call_presence() == False) { |
3553 | + /* Looks like we don't have the acl() system call on HPUX. | |
3554 | + * May be the system doesn't have the latest version of JFS. | |
3555 | + */ | |
3556 | + return NULL; | |
fa26e11c WD |
3557 | + } |
3558 | + | |
3559 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
3560 | + errno = EINVAL; | |
3561 | + return NULL; | |
3562 | + } | |
3563 | + | |
3564 | + count = INITIAL_ACL_SIZE; | |
3565 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
3566 | + return NULL; | |
3567 | + } | |
3568 | + | |
0f6733d8 WD |
3569 | + /* |
3570 | + * If there isn't enough space for the ACL entries we use | |
fa26e11c WD |
3571 | + * ACL_CNT to determine the actual number of ACL entries |
3572 | + * reallocate and try again. This is in a loop because it | |
3573 | + * is possible that someone else could modify the ACL and | |
3574 | + * increase the number of entries between the call to | |
0f6733d8 WD |
3575 | + * ACL_CNT and the call to ACL_GET. |
3576 | + */ | |
fa26e11c WD |
3577 | + while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) { |
3578 | + | |
3579 | + sys_acl_free_acl(acl_d); | |
3580 | + | |
3581 | + if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) { | |
3582 | + return NULL; | |
3583 | + } | |
3584 | + | |
3585 | + if ((acl_d = sys_acl_init(count)) == NULL) { | |
3586 | + return NULL; | |
3587 | + } | |
3588 | + } | |
3589 | + | |
3590 | + if (count < 0) { | |
3591 | + sys_acl_free_acl(acl_d); | |
3592 | + return NULL; | |
3593 | + } | |
3594 | + | |
0f6733d8 WD |
3595 | + /* |
3596 | + * calculate the number of access and default ACL entries | |
fa26e11c WD |
3597 | + * |
3598 | + * Note: we assume that the acl() system call returned a | |
3599 | + * well formed ACL which is sorted so that all of the | |
0f6733d8 WD |
3600 | + * access ACL entries preceed any default ACL entries |
3601 | + */ | |
fa26e11c WD |
3602 | + for (naccess = 0; naccess < count; naccess++) { |
3603 | + if (acl_d->acl[naccess].a_type & ACL_DEFAULT) | |
3604 | + break; | |
3605 | + } | |
3606 | + ndefault = count - naccess; | |
0f6733d8 WD |
3607 | + |
3608 | + /* | |
3609 | + * if the caller wants the default ACL we have to copy | |
fa26e11c | 3610 | + * the entries down to the start of the acl[] buffer |
0f6733d8 WD |
3611 | + * and mask out the ACL_DEFAULT flag from the type field |
3612 | + */ | |
fa26e11c | 3613 | + if (type == SMB_ACL_TYPE_DEFAULT) { |
0f6733d8 | 3614 | + int i, j; |
fa26e11c WD |
3615 | + |
3616 | + for (i = 0, j = naccess; i < ndefault; i++, j++) { | |
3617 | + acl_d->acl[i] = acl_d->acl[j]; | |
3618 | + acl_d->acl[i].a_type &= ~ACL_DEFAULT; | |
3619 | + } | |
3620 | + | |
3621 | + acl_d->count = ndefault; | |
3622 | + } else { | |
3623 | + acl_d->count = naccess; | |
3624 | + } | |
3625 | + | |
3626 | + return acl_d; | |
3627 | +} | |
3628 | + | |
0f6733d8 | 3629 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 3630 | +{ |
0f6733d8 WD |
3631 | + /* |
3632 | + * HPUX doesn't have the facl call. Fake it using the path.... JRA. | |
3633 | + */ | |
fa26e11c WD |
3634 | + |
3635 | + files_struct *fsp = file_find_fd(fd); | |
3636 | + | |
3637 | + if (fsp == NULL) { | |
3638 | + errno = EBADF; | |
3639 | + return NULL; | |
3640 | + } | |
3641 | + | |
0f6733d8 WD |
3642 | + /* |
3643 | + * We know we're in the same conn context. So we | |
3644 | + * can use the relative path. | |
3645 | + */ | |
fa26e11c | 3646 | + |
5ca9317d | 3647 | + return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS); |
fa26e11c WD |
3648 | +} |
3649 | + | |
0f6733d8 | 3650 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3651 | +{ |
3652 | + *permset_d = 0; | |
3653 | + | |
3654 | + return 0; | |
3655 | +} | |
3656 | + | |
0f6733d8 | 3657 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
3658 | +{ |
3659 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
3660 | + && perm != SMB_ACL_EXECUTE) { | |
3661 | + errno = EINVAL; | |
3662 | + return -1; | |
3663 | + } | |
3664 | + | |
3665 | + if (permset_d == NULL) { | |
3666 | + errno = EINVAL; | |
3667 | + return -1; | |
3668 | + } | |
3669 | + | |
3670 | + *permset_d |= perm; | |
3671 | + | |
3672 | + return 0; | |
3673 | +} | |
3674 | + | |
0f6733d8 | 3675 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
3676 | +{ |
3677 | + return *permset_d & perm; | |
3678 | +} | |
3679 | + | |
0f6733d8 | 3680 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c | 3681 | +{ |
0f6733d8 WD |
3682 | + int i; |
3683 | + int len, maxlen; | |
3684 | + char *text; | |
fa26e11c | 3685 | + |
0f6733d8 WD |
3686 | + /* |
3687 | + * use an initial estimate of 20 bytes per ACL entry | |
3688 | + * when allocating memory for the text representation | |
3689 | + * of the ACL | |
3690 | + */ | |
3691 | + len = 0; | |
3692 | + maxlen = 20 * acl_d->count; | |
252945ef | 3693 | + if ((text = SMB_MALLOC(maxlen)) == NULL) { |
fa26e11c WD |
3694 | + errno = ENOMEM; |
3695 | + return NULL; | |
3696 | + } | |
3697 | + | |
3698 | + for (i = 0; i < acl_d->count; i++) { | |
0f6733d8 | 3699 | + struct acl *ap = &acl_d->acl[i]; |
0f6733d8 WD |
3700 | + struct group *gr; |
3701 | + char tagbuf[12]; | |
3702 | + char idbuf[12]; | |
3703 | + char *tag; | |
3704 | + char *id = ""; | |
3705 | + char perms[4]; | |
3706 | + int nbytes; | |
fa26e11c WD |
3707 | + |
3708 | + switch (ap->a_type) { | |
0f6733d8 WD |
3709 | + /* |
3710 | + * for debugging purposes it's probably more | |
fa26e11c | 3711 | + * useful to dump unknown tag types rather |
0f6733d8 WD |
3712 | + * than just returning an error |
3713 | + */ | |
fa26e11c | 3714 | + default: |
0f6733d8 | 3715 | + slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x", |
fa26e11c WD |
3716 | + ap->a_type); |
3717 | + tag = tagbuf; | |
0f6733d8 | 3718 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
3719 | + (long)ap->a_id); |
3720 | + id = idbuf; | |
3721 | + break; | |
3722 | + | |
3723 | + case SMB_ACL_USER: | |
5ca9317d | 3724 | + id = uidtoname(ap->a_id); |
fa26e11c WD |
3725 | + case SMB_ACL_USER_OBJ: |
3726 | + tag = "user"; | |
3727 | + break; | |
3728 | + | |
3729 | + case SMB_ACL_GROUP: | |
3730 | + if ((gr = getgrgid(ap->a_id)) == NULL) { | |
0f6733d8 | 3731 | + slprintf(idbuf, sizeof(idbuf)-1, "%ld", |
fa26e11c WD |
3732 | + (long)ap->a_id); |
3733 | + id = idbuf; | |
3734 | + } else { | |
3735 | + id = gr->gr_name; | |
3736 | + } | |
3737 | + case SMB_ACL_GROUP_OBJ: | |
3738 | + tag = "group"; | |
3739 | + break; | |
3740 | + | |
3741 | + case SMB_ACL_OTHER: | |
3742 | + tag = "other"; | |
3743 | + break; | |
3744 | + | |
3745 | + case SMB_ACL_MASK: | |
3746 | + tag = "mask"; | |
3747 | + break; | |
3748 | + | |
3749 | + } | |
3750 | + | |
3751 | + perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-'; | |
3752 | + perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-'; | |
3753 | + perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-'; | |
3754 | + perms[3] = '\0'; | |
3755 | + | |
3756 | + /* <tag> : <qualifier> : rwx \n \0 */ | |
3757 | + nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1; | |
3758 | + | |
0f6733d8 WD |
3759 | + /* |
3760 | + * If this entry would overflow the buffer | |
fa26e11c WD |
3761 | + * allocate enough additional memory for this |
3762 | + * entry and an estimate of another 20 bytes | |
0f6733d8 WD |
3763 | + * for each entry still to be processed |
3764 | + */ | |
fa26e11c WD |
3765 | + if ((len + nbytes) > maxlen) { |
3766 | + char *oldtext = text; | |
3767 | + | |
3768 | + maxlen += nbytes + 20 * (acl_d->count - i); | |
3769 | + | |
252945ef | 3770 | + if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) { |
fa26e11c WD |
3771 | + free(oldtext); |
3772 | + errno = ENOMEM; | |
3773 | + return NULL; | |
3774 | + } | |
3775 | + } | |
3776 | + | |
0f6733d8 | 3777 | + slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms); |
fa26e11c WD |
3778 | + len += nbytes - 1; |
3779 | + } | |
3780 | + | |
3781 | + if (len_p) | |
3782 | + *len_p = len; | |
3783 | + | |
3784 | + return text; | |
3785 | +} | |
3786 | + | |
0f6733d8 | 3787 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 3788 | +{ |
0f6733d8 | 3789 | + SMB_ACL_T a; |
fa26e11c WD |
3790 | + |
3791 | + if (count < 0) { | |
3792 | + errno = EINVAL; | |
3793 | + return NULL; | |
3794 | + } | |
3795 | + | |
0f6733d8 WD |
3796 | + /* |
3797 | + * note that since the definition of the structure pointed | |
fa26e11c WD |
3798 | + * to by the SMB_ACL_T includes the first element of the |
3799 | + * acl[] array, this actually allocates an ACL with room | |
0f6733d8 WD |
3800 | + * for (count+1) entries |
3801 | + */ | |
252945ef | 3802 | + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) { |
fa26e11c WD |
3803 | + errno = ENOMEM; |
3804 | + return NULL; | |
3805 | + } | |
3806 | + | |
3807 | + a->size = count + 1; | |
3808 | + a->count = 0; | |
3809 | + a->next = -1; | |
3810 | + | |
3811 | + return a; | |
3812 | +} | |
3813 | + | |
3814 | + | |
0f6733d8 | 3815 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 3816 | +{ |
0f6733d8 WD |
3817 | + SMB_ACL_T acl_d; |
3818 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
3819 | + |
3820 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
3821 | + errno = EINVAL; | |
3822 | + return -1; | |
3823 | + } | |
3824 | + | |
3825 | + if (acl_d->count >= acl_d->size) { | |
3826 | + errno = ENOSPC; | |
3827 | + return -1; | |
3828 | + } | |
3829 | + | |
0f6733d8 WD |
3830 | + entry_d = &acl_d->acl[acl_d->count++]; |
3831 | + entry_d->a_type = 0; | |
3832 | + entry_d->a_id = -1; | |
3833 | + entry_d->a_perm = 0; | |
3834 | + *entry_p = entry_d; | |
fa26e11c WD |
3835 | + |
3836 | + return 0; | |
3837 | +} | |
3838 | + | |
0f6733d8 | 3839 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
3840 | +{ |
3841 | + switch (tag_type) { | |
3842 | + case SMB_ACL_USER: | |
3843 | + case SMB_ACL_USER_OBJ: | |
3844 | + case SMB_ACL_GROUP: | |
3845 | + case SMB_ACL_GROUP_OBJ: | |
3846 | + case SMB_ACL_OTHER: | |
3847 | + case SMB_ACL_MASK: | |
3848 | + entry_d->a_type = tag_type; | |
3849 | + break; | |
3850 | + default: | |
3851 | + errno = EINVAL; | |
3852 | + return -1; | |
3853 | + } | |
3854 | + | |
3855 | + return 0; | |
3856 | +} | |
3857 | + | |
0f6733d8 | 3858 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
3859 | +{ |
3860 | + if (entry_d->a_type != SMB_ACL_GROUP | |
3861 | + && entry_d->a_type != SMB_ACL_USER) { | |
3862 | + errno = EINVAL; | |
3863 | + return -1; | |
3864 | + } | |
3865 | + | |
3866 | + entry_d->a_id = *((id_t *)qual_p); | |
3867 | + | |
3868 | + return 0; | |
3869 | +} | |
3870 | + | |
0f6733d8 | 3871 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
3872 | +{ |
3873 | + if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
3874 | + return EINVAL; | |
3875 | + } | |
3876 | + | |
3877 | + entry_d->a_perm = *permset_d; | |
3878 | + | |
3879 | + return 0; | |
3880 | +} | |
3881 | + | |
3882 | +/* Structure to capture the count for each type of ACE. */ | |
3883 | + | |
3884 | +struct hpux_acl_types { | |
3885 | + int n_user; | |
3886 | + int n_def_user; | |
3887 | + int n_user_obj; | |
3888 | + int n_def_user_obj; | |
3889 | + | |
3890 | + int n_group; | |
3891 | + int n_def_group; | |
3892 | + int n_group_obj; | |
3893 | + int n_def_group_obj; | |
3894 | + | |
3895 | + int n_other; | |
3896 | + int n_other_obj; | |
3897 | + int n_def_other_obj; | |
3898 | + | |
3899 | + int n_class_obj; | |
3900 | + int n_def_class_obj; | |
3901 | + | |
3902 | + int n_illegal_obj; | |
3903 | +}; | |
3904 | + | |
3905 | +/* count_obj: | |
3906 | + * Counts the different number of objects in a given array of ACL | |
3907 | + * structures. | |
3908 | + * Inputs: | |
3909 | + * | |
3910 | + * acl_count - Count of ACLs in the array of ACL strucutres. | |
3911 | + * aclp - Array of ACL structures. | |
3912 | + * acl_type_count - Pointer to acl_types structure. Should already be | |
3913 | + * allocated. | |
0f6733d8 | 3914 | + * Output: |
fa26e11c | 3915 | + * |
0f6733d8 | 3916 | + * acl_type_count - This structure is filled up with counts of various |
fa26e11c WD |
3917 | + * acl types. |
3918 | + */ | |
3919 | + | |
3920 | +static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count) | |
3921 | +{ | |
3922 | + int i; | |
3923 | + | |
0f6733d8 | 3924 | + memset(acl_type_count, 0, sizeof(struct hpux_acl_types)); |
fa26e11c | 3925 | + |
0f6733d8 WD |
3926 | + for(i=0;i<acl_count;i++) { |
3927 | + switch(aclp[i].a_type) { | |
3928 | + case USER: | |
fa26e11c WD |
3929 | + acl_type_count->n_user++; |
3930 | + break; | |
0f6733d8 | 3931 | + case USER_OBJ: |
fa26e11c WD |
3932 | + acl_type_count->n_user_obj++; |
3933 | + break; | |
0f6733d8 | 3934 | + case DEF_USER_OBJ: |
fa26e11c WD |
3935 | + acl_type_count->n_def_user_obj++; |
3936 | + break; | |
0f6733d8 | 3937 | + case GROUP: |
fa26e11c WD |
3938 | + acl_type_count->n_group++; |
3939 | + break; | |
0f6733d8 | 3940 | + case GROUP_OBJ: |
fa26e11c WD |
3941 | + acl_type_count->n_group_obj++; |
3942 | + break; | |
0f6733d8 | 3943 | + case DEF_GROUP_OBJ: |
fa26e11c WD |
3944 | + acl_type_count->n_def_group_obj++; |
3945 | + break; | |
0f6733d8 | 3946 | + case OTHER_OBJ: |
fa26e11c WD |
3947 | + acl_type_count->n_other_obj++; |
3948 | + break; | |
0f6733d8 | 3949 | + case DEF_OTHER_OBJ: |
fa26e11c WD |
3950 | + acl_type_count->n_def_other_obj++; |
3951 | + break; | |
3952 | + case CLASS_OBJ: | |
3953 | + acl_type_count->n_class_obj++; | |
3954 | + break; | |
3955 | + case DEF_CLASS_OBJ: | |
3956 | + acl_type_count->n_def_class_obj++; | |
3957 | + break; | |
3958 | + case DEF_USER: | |
3959 | + acl_type_count->n_def_user++; | |
3960 | + break; | |
3961 | + case DEF_GROUP: | |
3962 | + acl_type_count->n_def_group++; | |
3963 | + break; | |
0f6733d8 | 3964 | + default: |
fa26e11c WD |
3965 | + acl_type_count->n_illegal_obj++; |
3966 | + break; | |
3967 | + } | |
3968 | + } | |
3969 | +} | |
3970 | + | |
0f6733d8 | 3971 | +/* swap_acl_entries: Swaps two ACL entries. |
fa26e11c WD |
3972 | + * |
3973 | + * Inputs: aclp0, aclp1 - ACL entries to be swapped. | |
3974 | + */ | |
3975 | + | |
3976 | +static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1) | |
3977 | +{ | |
3978 | + struct acl temp_acl; | |
3979 | + | |
3980 | + temp_acl.a_type = aclp0->a_type; | |
3981 | + temp_acl.a_id = aclp0->a_id; | |
3982 | + temp_acl.a_perm = aclp0->a_perm; | |
3983 | + | |
3984 | + aclp0->a_type = aclp1->a_type; | |
3985 | + aclp0->a_id = aclp1->a_id; | |
3986 | + aclp0->a_perm = aclp1->a_perm; | |
3987 | + | |
3988 | + aclp1->a_type = temp_acl.a_type; | |
3989 | + aclp1->a_id = temp_acl.a_id; | |
3990 | + aclp1->a_perm = temp_acl.a_perm; | |
3991 | +} | |
3992 | + | |
3993 | +/* prohibited_duplicate_type | |
0f6733d8 | 3994 | + * Identifies if given ACL type can have duplicate entries or |
fa26e11c WD |
3995 | + * not. |
3996 | + * | |
3997 | + * Inputs: acl_type - ACL Type. | |
3998 | + * | |
0f6733d8 | 3999 | + * Outputs: |
fa26e11c | 4000 | + * |
0f6733d8 | 4001 | + * Return.. |
fa26e11c WD |
4002 | + * |
4003 | + * True - If the ACL type matches any of the prohibited types. | |
4004 | + * False - If the ACL type doesn't match any of the prohibited types. | |
0f6733d8 | 4005 | + */ |
fa26e11c WD |
4006 | + |
4007 | +static BOOL hpux_prohibited_duplicate_type(int acl_type) | |
4008 | +{ | |
0f6733d8 | 4009 | + switch(acl_type) { |
fa26e11c WD |
4010 | + case USER: |
4011 | + case GROUP: | |
0f6733d8 | 4012 | + case DEF_USER: |
fa26e11c WD |
4013 | + case DEF_GROUP: |
4014 | + return True; | |
0f6733d8 WD |
4015 | + default: |
4016 | + return False; | |
fa26e11c | 4017 | + } |
fa26e11c WD |
4018 | +} |
4019 | + | |
4020 | +/* get_needed_class_perm | |
4021 | + * Returns the permissions of a ACL structure only if the ACL | |
0f6733d8 | 4022 | + * type matches one of the pre-determined types for computing |
fa26e11c WD |
4023 | + * CLASS_OBJ permissions. |
4024 | + * | |
4025 | + * Inputs: aclp - Pointer to ACL structure. | |
4026 | + */ | |
4027 | + | |
4028 | +static int hpux_get_needed_class_perm(struct acl *aclp) | |
4029 | +{ | |
0f6733d8 WD |
4030 | + switch(aclp->a_type) { |
4031 | + case USER: | |
4032 | + case GROUP_OBJ: | |
4033 | + case GROUP: | |
4034 | + case DEF_USER_OBJ: | |
fa26e11c | 4035 | + case DEF_USER: |
0f6733d8 | 4036 | + case DEF_GROUP_OBJ: |
fa26e11c WD |
4037 | + case DEF_GROUP: |
4038 | + case DEF_CLASS_OBJ: | |
0f6733d8 | 4039 | + case DEF_OTHER_OBJ: |
fa26e11c | 4040 | + return aclp->a_perm; |
0f6733d8 | 4041 | + default: |
fa26e11c WD |
4042 | + return 0; |
4043 | + } | |
4044 | +} | |
4045 | + | |
4046 | +/* acl_sort for HPUX. | |
4047 | + * Sorts the array of ACL structures as per the description in | |
4048 | + * aclsort man page. Refer to aclsort man page for more details | |
4049 | + * | |
4050 | + * Inputs: | |
4051 | + * | |
4052 | + * acl_count - Count of ACLs in the array of ACL structures. | |
4053 | + * calclass - If this is not zero, then we compute the CLASS_OBJ | |
4054 | + * permissions. | |
4055 | + * aclp - Array of ACL structures. | |
4056 | + * | |
4057 | + * Outputs: | |
4058 | + * | |
4059 | + * aclp - Sorted array of ACL structures. | |
4060 | + * | |
4061 | + * Outputs: | |
4062 | + * | |
4063 | + * Returns 0 for success -1 for failure. Prints a message to the Samba | |
4064 | + * debug log in case of failure. | |
4065 | + */ | |
4066 | + | |
4067 | +static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp) | |
4068 | +{ | |
4069 | +#if !defined(HAVE_HPUX_ACLSORT) | |
0f6733d8 WD |
4070 | + /* |
4071 | + * The aclsort() system call is availabe on the latest HPUX General | |
4072 | + * Patch Bundles. So for HPUX, we developed our version of acl_sort | |
4073 | + * function. Because, we don't want to update to a new | |
4074 | + * HPUX GR bundle just for aclsort() call. | |
4075 | + */ | |
fa26e11c WD |
4076 | + |
4077 | + struct hpux_acl_types acl_obj_count; | |
4078 | + int n_class_obj_perm = 0; | |
4079 | + int i, j; | |
0f6733d8 WD |
4080 | + |
4081 | + if(!acl_count) { | |
fa26e11c WD |
4082 | + DEBUG(10,("Zero acl count passed. Returning Success\n")); |
4083 | + return 0; | |
4084 | + } | |
4085 | + | |
0f6733d8 | 4086 | + if(aclp == NULL) { |
fa26e11c WD |
4087 | + DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n")); |
4088 | + return -1; | |
4089 | + } | |
4090 | + | |
4091 | + /* Count different types of ACLs in the ACLs array */ | |
4092 | + | |
4093 | + hpux_count_obj(acl_count, aclp, &acl_obj_count); | |
4094 | + | |
0f6733d8 WD |
4095 | + /* There should be only one entry each of type USER_OBJ, GROUP_OBJ, |
4096 | + * CLASS_OBJ and OTHER_OBJ | |
fa26e11c WD |
4097 | + */ |
4098 | + | |
0f6733d8 WD |
4099 | + if( (acl_obj_count.n_user_obj != 1) || |
4100 | + (acl_obj_count.n_group_obj != 1) || | |
4101 | + (acl_obj_count.n_class_obj != 1) || | |
4102 | + (acl_obj_count.n_other_obj != 1) | |
4103 | + ) { | |
fa26e11c WD |
4104 | + DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \ |
4105 | +USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n")); | |
4106 | + return -1; | |
4107 | + } | |
4108 | + | |
4109 | + /* If any of the default objects are present, there should be only | |
4110 | + * one of them each. | |
4111 | + */ | |
4112 | + | |
0f6733d8 WD |
4113 | + if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) || |
4114 | + (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) { | |
fa26e11c WD |
4115 | + DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \ |
4116 | +or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n")); | |
4117 | + return -1; | |
4118 | + } | |
4119 | + | |
0f6733d8 WD |
4120 | + /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl |
4121 | + * structures. | |
fa26e11c WD |
4122 | + * |
4123 | + * Sorting crieteria - First sort by ACL type. If there are multiple entries of | |
4124 | + * same ACL type, sort by ACL id. | |
4125 | + * | |
0f6733d8 | 4126 | + * I am using the trival kind of sorting method here because, performance isn't |
fa26e11c | 4127 | + * really effected by the ACLs feature. More over there aren't going to be more |
0f6733d8 | 4128 | + * than 17 entries on HPUX. |
fa26e11c WD |
4129 | + */ |
4130 | + | |
0f6733d8 | 4131 | + for(i=0; i<acl_count;i++) { |
fa26e11c | 4132 | + for (j=i+1; j<acl_count; j++) { |
0f6733d8 | 4133 | + if( aclp[i].a_type > aclp[j].a_type ) { |
fa26e11c WD |
4134 | + /* ACL entries out of order, swap them */ |
4135 | + | |
4136 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); | |
4137 | + | |
0f6733d8 | 4138 | + } else if ( aclp[i].a_type == aclp[j].a_type ) { |
fa26e11c WD |
4139 | + |
4140 | + /* ACL entries of same type, sort by id */ | |
4141 | + | |
0f6733d8 | 4142 | + if(aclp[i].a_id > aclp[j].a_id) { |
fa26e11c WD |
4143 | + hpux_swap_acl_entries((aclp+i), (aclp+j)); |
4144 | + } else if (aclp[i].a_id == aclp[j].a_id) { | |
4145 | + /* We have a duplicate entry. */ | |
0f6733d8 | 4146 | + if(hpux_prohibited_duplicate_type(aclp[i].a_type)) { |
fa26e11c WD |
4147 | + DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n", |
4148 | + aclp[i].a_type, aclp[i].a_id)); | |
4149 | + return -1; | |
4150 | + } | |
4151 | + } | |
4152 | + | |
4153 | + } | |
4154 | + } | |
4155 | + } | |
4156 | + | |
4157 | + /* set the class obj permissions to the computed one. */ | |
0f6733d8 | 4158 | + if(calclass) { |
fa26e11c WD |
4159 | + int n_class_obj_index = -1; |
4160 | + | |
0f6733d8 | 4161 | + for(i=0;i<acl_count;i++) { |
fa26e11c WD |
4162 | + n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i)); |
4163 | + | |
0f6733d8 | 4164 | + if(aclp[i].a_type == CLASS_OBJ) |
fa26e11c WD |
4165 | + n_class_obj_index = i; |
4166 | + } | |
4167 | + aclp[n_class_obj_index].a_perm = n_class_obj_perm; | |
4168 | + } | |
4169 | + | |
4170 | + return 0; | |
4171 | +#else | |
4172 | + return aclsort(acl_count, calclass, aclp); | |
4173 | +#endif | |
4174 | +} | |
4175 | + | |
0f6733d8 WD |
4176 | +/* |
4177 | + * sort the ACL and check it for validity | |
fa26e11c | 4178 | + * |
0f6733d8 | 4179 | + * if it's a minimal ACL with only 4 entries then we |
fa26e11c WD |
4180 | + * need to recalculate the mask permissions to make |
4181 | + * sure that they are the same as the GROUP_OBJ | |
4182 | + * permissions as required by the UnixWare acl() system call. | |
4183 | + * | |
0f6733d8 | 4184 | + * (note: since POSIX allows minimal ACLs which only contain |
fa26e11c WD |
4185 | + * 3 entries - ie there is no mask entry - we should, in theory, |
4186 | + * check for this and add a mask entry if necessary - however | |
4187 | + * we "know" that the caller of this interface always specifies | |
4188 | + * a mask so, in practice "this never happens" (tm) - if it *does* | |
4189 | + * happen aclsort() will fail and return an error and someone will | |
0f6733d8 WD |
4190 | + * have to fix it ...) |
4191 | + */ | |
fa26e11c WD |
4192 | + |
4193 | +static int acl_sort(SMB_ACL_T acl_d) | |
4194 | +{ | |
4195 | + int fixmask = (acl_d->count <= 4); | |
4196 | + | |
4197 | + if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) { | |
4198 | + errno = EINVAL; | |
4199 | + return -1; | |
4200 | + } | |
4201 | + return 0; | |
4202 | +} | |
0f6733d8 WD |
4203 | + |
4204 | +int sys_acl_valid(SMB_ACL_T acl_d) | |
fa26e11c WD |
4205 | +{ |
4206 | + return acl_sort(acl_d); | |
4207 | +} | |
4208 | + | |
0f6733d8 | 4209 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c | 4210 | +{ |
0f6733d8 WD |
4211 | + struct stat s; |
4212 | + struct acl *acl_p; | |
4213 | + int acl_count; | |
4214 | + struct acl *acl_buf = NULL; | |
4215 | + int ret; | |
fa26e11c | 4216 | + |
0f6733d8 WD |
4217 | + if(hpux_acl_call_presence() == False) { |
4218 | + /* Looks like we don't have the acl() system call on HPUX. | |
4219 | + * May be the system doesn't have the latest version of JFS. | |
4220 | + */ | |
4221 | + errno=ENOSYS; | |
4222 | + return -1; | |
fa26e11c WD |
4223 | + } |
4224 | + | |
4225 | + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { | |
4226 | + errno = EINVAL; | |
4227 | + return -1; | |
4228 | + } | |
4229 | + | |
4230 | + if (acl_sort(acl_d) != 0) { | |
4231 | + return -1; | |
4232 | + } | |
4233 | + | |
0f6733d8 WD |
4234 | + acl_p = &acl_d->acl[0]; |
4235 | + acl_count = acl_d->count; | |
fa26e11c | 4236 | + |
0f6733d8 WD |
4237 | + /* |
4238 | + * if it's a directory there is extra work to do | |
4239 | + * since the acl() system call will replace both | |
4240 | + * the access ACLs and the default ACLs (if any) | |
4241 | + */ | |
fa26e11c WD |
4242 | + if (stat(name, &s) != 0) { |
4243 | + return -1; | |
4244 | + } | |
4245 | + if (S_ISDIR(s.st_mode)) { | |
0f6733d8 WD |
4246 | + SMB_ACL_T acc_acl; |
4247 | + SMB_ACL_T def_acl; | |
4248 | + SMB_ACL_T tmp_acl; | |
4249 | + int i; | |
fa26e11c WD |
4250 | + |
4251 | + if (type == SMB_ACL_TYPE_ACCESS) { | |
4252 | + acc_acl = acl_d; | |
4253 | + def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT); | |
4254 | + | |
4255 | + } else { | |
4256 | + def_acl = acl_d; | |
4257 | + acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS); | |
4258 | + } | |
4259 | + | |
4260 | + if (tmp_acl == NULL) { | |
4261 | + return -1; | |
4262 | + } | |
4263 | + | |
0f6733d8 WD |
4264 | + /* |
4265 | + * allocate a temporary buffer for the complete ACL | |
4266 | + */ | |
fa26e11c | 4267 | + acl_count = acc_acl->count + def_acl->count; |
252945ef | 4268 | + acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count); |
fa26e11c WD |
4269 | + |
4270 | + if (acl_buf == NULL) { | |
4271 | + sys_acl_free_acl(tmp_acl); | |
4272 | + errno = ENOMEM; | |
4273 | + return -1; | |
4274 | + } | |
4275 | + | |
0f6733d8 WD |
4276 | + /* |
4277 | + * copy the access control and default entries into the buffer | |
4278 | + */ | |
fa26e11c | 4279 | + memcpy(&acl_buf[0], &acc_acl->acl[0], |
0f6733d8 | 4280 | + acc_acl->count * sizeof(acl_buf[0])); |
fa26e11c WD |
4281 | + |
4282 | + memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0], | |
0f6733d8 | 4283 | + def_acl->count * sizeof(acl_buf[0])); |
fa26e11c | 4284 | + |
0f6733d8 WD |
4285 | + /* |
4286 | + * set the ACL_DEFAULT flag on the default entries | |
4287 | + */ | |
fa26e11c WD |
4288 | + for (i = acc_acl->count; i < acl_count; i++) { |
4289 | + acl_buf[i].a_type |= ACL_DEFAULT; | |
4290 | + } | |
4291 | + | |
4292 | + sys_acl_free_acl(tmp_acl); | |
4293 | + | |
4294 | + } else if (type != SMB_ACL_TYPE_ACCESS) { | |
4295 | + errno = EINVAL; | |
4296 | + return -1; | |
4297 | + } | |
4298 | + | |
4299 | + ret = acl(name, ACL_SET, acl_count, acl_p); | |
4300 | + | |
0f6733d8 WD |
4301 | + if (acl_buf) { |
4302 | + free(acl_buf); | |
4303 | + } | |
fa26e11c WD |
4304 | + |
4305 | + return ret; | |
4306 | +} | |
4307 | + | |
0f6733d8 | 4308 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c | 4309 | +{ |
0f6733d8 WD |
4310 | + /* |
4311 | + * HPUX doesn't have the facl call. Fake it using the path.... JRA. | |
4312 | + */ | |
fa26e11c WD |
4313 | + |
4314 | + files_struct *fsp = file_find_fd(fd); | |
4315 | + | |
4316 | + if (fsp == NULL) { | |
4317 | + errno = EBADF; | |
4318 | + return NULL; | |
4319 | + } | |
4320 | + | |
4321 | + if (acl_sort(acl_d) != 0) { | |
4322 | + return -1; | |
4323 | + } | |
4324 | + | |
0f6733d8 WD |
4325 | + /* |
4326 | + * We know we're in the same conn context. So we | |
4327 | + * can use the relative path. | |
4328 | + */ | |
fa26e11c | 4329 | + |
5ca9317d | 4330 | + return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d); |
fa26e11c WD |
4331 | +} |
4332 | + | |
0f6733d8 | 4333 | +int sys_acl_delete_def_file(const char *path) |
fa26e11c | 4334 | +{ |
0f6733d8 WD |
4335 | + SMB_ACL_T acl_d; |
4336 | + int ret; | |
fa26e11c | 4337 | + |
0f6733d8 WD |
4338 | + /* |
4339 | + * fetching the access ACL and rewriting it has | |
4340 | + * the effect of deleting the default ACL | |
4341 | + */ | |
fa26e11c WD |
4342 | + if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) { |
4343 | + return -1; | |
4344 | + } | |
4345 | + | |
4346 | + ret = acl(path, ACL_SET, acl_d->count, acl_d->acl); | |
4347 | + | |
4348 | + sys_acl_free_acl(acl_d); | |
0f6733d8 | 4349 | + |
fa26e11c WD |
4350 | + return ret; |
4351 | +} | |
4352 | + | |
0f6733d8 | 4353 | +int sys_acl_free_text(char *text) |
fa26e11c WD |
4354 | +{ |
4355 | + free(text); | |
4356 | + return 0; | |
4357 | +} | |
4358 | + | |
0f6733d8 | 4359 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c WD |
4360 | +{ |
4361 | + free(acl_d); | |
4362 | + return 0; | |
4363 | +} | |
4364 | + | |
0f6733d8 | 4365 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
4366 | +{ |
4367 | + return 0; | |
4368 | +} | |
4369 | + | |
4370 | +#elif defined(HAVE_IRIX_ACLS) | |
4371 | + | |
0f6733d8 | 4372 | +int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
4373 | +{ |
4374 | + if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) { | |
4375 | + errno = EINVAL; | |
4376 | + return -1; | |
4377 | + } | |
4378 | + | |
4379 | + if (entry_p == NULL) { | |
4380 | + errno = EINVAL; | |
4381 | + return -1; | |
4382 | + } | |
4383 | + | |
4384 | + if (entry_id == SMB_ACL_FIRST_ENTRY) { | |
4385 | + acl_d->next = 0; | |
4386 | + } | |
4387 | + | |
4388 | + if (acl_d->next < 0) { | |
4389 | + errno = EINVAL; | |
4390 | + return -1; | |
4391 | + } | |
4392 | + | |
4393 | + if (acl_d->next >= acl_d->aclp->acl_cnt) { | |
4394 | + return 0; | |
4395 | + } | |
4396 | + | |
4397 | + *entry_p = &acl_d->aclp->acl_entry[acl_d->next++]; | |
4398 | + | |
4399 | + return 1; | |
4400 | +} | |
4401 | + | |
0f6733d8 | 4402 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p) |
fa26e11c WD |
4403 | +{ |
4404 | + *type_p = entry_d->ae_tag; | |
4405 | + | |
4406 | + return 0; | |
4407 | +} | |
4408 | + | |
0f6733d8 | 4409 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
4410 | +{ |
4411 | + *permset_p = entry_d; | |
4412 | + | |
4413 | + return 0; | |
4414 | +} | |
4415 | + | |
0f6733d8 | 4416 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d) |
fa26e11c WD |
4417 | +{ |
4418 | + if (entry_d->ae_tag != SMB_ACL_USER | |
4419 | + && entry_d->ae_tag != SMB_ACL_GROUP) { | |
4420 | + errno = EINVAL; | |
4421 | + return NULL; | |
4422 | + } | |
4423 | + | |
4424 | + return &entry_d->ae_id; | |
4425 | +} | |
4426 | + | |
0f6733d8 | 4427 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c | 4428 | +{ |
0f6733d8 | 4429 | + SMB_ACL_T a; |
fa26e11c | 4430 | + |
252945ef | 4431 | + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
fa26e11c WD |
4432 | + errno = ENOMEM; |
4433 | + return NULL; | |
4434 | + } | |
4435 | + if ((a->aclp = acl_get_file(path_p, type)) == NULL) { | |
0f6733d8 | 4436 | + SAFE_FREE(a); |
fa26e11c WD |
4437 | + return NULL; |
4438 | + } | |
4439 | + a->next = -1; | |
4440 | + a->freeaclp = True; | |
4441 | + return a; | |
4442 | +} | |
4443 | + | |
0f6733d8 | 4444 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c | 4445 | +{ |
0f6733d8 | 4446 | + SMB_ACL_T a; |
fa26e11c | 4447 | + |
252945ef | 4448 | + if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) { |
fa26e11c WD |
4449 | + errno = ENOMEM; |
4450 | + return NULL; | |
4451 | + } | |
4452 | + if ((a->aclp = acl_get_fd(fd)) == NULL) { | |
0f6733d8 | 4453 | + SAFE_FREE(a); |
fa26e11c WD |
4454 | + return NULL; |
4455 | + } | |
4456 | + a->next = -1; | |
4457 | + a->freeaclp = True; | |
4458 | + return a; | |
4459 | +} | |
4460 | + | |
0f6733d8 | 4461 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
4462 | +{ |
4463 | + permset_d->ae_perm = 0; | |
4464 | + | |
4465 | + return 0; | |
4466 | +} | |
4467 | + | |
0f6733d8 | 4468 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
4469 | +{ |
4470 | + if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE | |
4471 | + && perm != SMB_ACL_EXECUTE) { | |
4472 | + errno = EINVAL; | |
4473 | + return -1; | |
4474 | + } | |
4475 | + | |
4476 | + if (permset_d == NULL) { | |
4477 | + errno = EINVAL; | |
4478 | + return -1; | |
4479 | + } | |
4480 | + | |
4481 | + permset_d->ae_perm |= perm; | |
4482 | + | |
4483 | + return 0; | |
4484 | +} | |
4485 | + | |
0f6733d8 | 4486 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm) |
fa26e11c WD |
4487 | +{ |
4488 | + return permset_d->ae_perm & perm; | |
4489 | +} | |
4490 | + | |
0f6733d8 | 4491 | +char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p) |
fa26e11c WD |
4492 | +{ |
4493 | + return acl_to_text(acl_d->aclp, len_p); | |
4494 | +} | |
4495 | + | |
0f6733d8 | 4496 | +SMB_ACL_T sys_acl_init(int count) |
fa26e11c | 4497 | +{ |
0f6733d8 | 4498 | + SMB_ACL_T a; |
fa26e11c WD |
4499 | + |
4500 | + if (count < 0) { | |
4501 | + errno = EINVAL; | |
4502 | + return NULL; | |
4503 | + } | |
4504 | + | |
252945ef | 4505 | + if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) { |
fa26e11c WD |
4506 | + errno = ENOMEM; |
4507 | + return NULL; | |
4508 | + } | |
4509 | + | |
4510 | + a->next = -1; | |
4511 | + a->freeaclp = False; | |
0f6733d8 | 4512 | + a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *)); |
fa26e11c WD |
4513 | + a->aclp->acl_cnt = 0; |
4514 | + | |
4515 | + return a; | |
4516 | +} | |
4517 | + | |
4518 | + | |
0f6733d8 | 4519 | +int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c | 4520 | +{ |
0f6733d8 WD |
4521 | + SMB_ACL_T acl_d; |
4522 | + SMB_ACL_ENTRY_T entry_d; | |
fa26e11c WD |
4523 | + |
4524 | + if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) { | |
4525 | + errno = EINVAL; | |
4526 | + return -1; | |
4527 | + } | |
4528 | + | |
4529 | + if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) { | |
4530 | + errno = ENOSPC; | |
4531 | + return -1; | |
4532 | + } | |
4533 | + | |
0f6733d8 WD |
4534 | + entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++]; |
4535 | + entry_d->ae_tag = 0; | |
4536 | + entry_d->ae_id = 0; | |
4537 | + entry_d->ae_perm = 0; | |
4538 | + *entry_p = entry_d; | |
fa26e11c WD |
4539 | + |
4540 | + return 0; | |
4541 | +} | |
4542 | + | |
0f6733d8 | 4543 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type) |
fa26e11c WD |
4544 | +{ |
4545 | + switch (tag_type) { | |
4546 | + case SMB_ACL_USER: | |
4547 | + case SMB_ACL_USER_OBJ: | |
4548 | + case SMB_ACL_GROUP: | |
4549 | + case SMB_ACL_GROUP_OBJ: | |
4550 | + case SMB_ACL_OTHER: | |
4551 | + case SMB_ACL_MASK: | |
4552 | + entry_d->ae_tag = tag_type; | |
4553 | + break; | |
4554 | + default: | |
4555 | + errno = EINVAL; | |
4556 | + return -1; | |
4557 | + } | |
4558 | + | |
4559 | + return 0; | |
4560 | +} | |
4561 | + | |
0f6733d8 | 4562 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p) |
fa26e11c WD |
4563 | +{ |
4564 | + if (entry_d->ae_tag != SMB_ACL_GROUP | |
4565 | + && entry_d->ae_tag != SMB_ACL_USER) { | |
4566 | + errno = EINVAL; | |
4567 | + return -1; | |
4568 | + } | |
4569 | + | |
4570 | + entry_d->ae_id = *((id_t *)qual_p); | |
4571 | + | |
4572 | + return 0; | |
4573 | +} | |
4574 | + | |
0f6733d8 | 4575 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d) |
fa26e11c WD |
4576 | +{ |
4577 | + if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) { | |
4578 | + return EINVAL; | |
4579 | + } | |
4580 | + | |
4581 | + entry_d->ae_perm = permset_d->ae_perm; | |
4582 | + | |
4583 | + return 0; | |
4584 | +} | |
4585 | + | |
0f6733d8 | 4586 | +int sys_acl_valid(SMB_ACL_T acl_d) |
fa26e11c WD |
4587 | +{ |
4588 | + return acl_valid(acl_d->aclp); | |
4589 | +} | |
4590 | + | |
0f6733d8 | 4591 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d) |
fa26e11c WD |
4592 | +{ |
4593 | + return acl_set_file(name, type, acl_d->aclp); | |
4594 | +} | |
4595 | + | |
0f6733d8 | 4596 | +int sys_acl_set_fd(int fd, SMB_ACL_T acl_d) |
fa26e11c WD |
4597 | +{ |
4598 | + return acl_set_fd(fd, acl_d->aclp); | |
4599 | +} | |
4600 | + | |
0f6733d8 | 4601 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
4602 | +{ |
4603 | + return acl_delete_def_file(name); | |
4604 | +} | |
4605 | + | |
0f6733d8 | 4606 | +int sys_acl_free_text(char *text) |
fa26e11c WD |
4607 | +{ |
4608 | + return acl_free(text); | |
4609 | +} | |
4610 | + | |
0f6733d8 | 4611 | +int sys_acl_free_acl(SMB_ACL_T acl_d) |
fa26e11c WD |
4612 | +{ |
4613 | + if (acl_d->freeaclp) { | |
4614 | + acl_free(acl_d->aclp); | |
4615 | + } | |
4616 | + acl_free(acl_d); | |
4617 | + return 0; | |
4618 | +} | |
4619 | + | |
0f6733d8 | 4620 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
4621 | +{ |
4622 | + return 0; | |
4623 | +} | |
4624 | + | |
4625 | +#elif defined(HAVE_AIX_ACLS) | |
4626 | + | |
4627 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
4628 | + | |
0f6733d8 | 4629 | +int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) |
fa26e11c WD |
4630 | +{ |
4631 | + struct acl_entry_link *link; | |
4632 | + struct new_acl_entry *entry; | |
4633 | + int keep_going; | |
4634 | + | |
4635 | + DEBUG(10,("This is the count: %d\n",theacl->count)); | |
4636 | + | |
0f6733d8 WD |
4637 | + /* Check if count was previously set to -1. * |
4638 | + * If it was, that means we reached the end * | |
4639 | + * of the acl last time. */ | |
4640 | + if(theacl->count == -1) | |
4641 | + return(0); | |
fa26e11c WD |
4642 | + |
4643 | + link = theacl; | |
0f6733d8 WD |
4644 | + /* To get to the next acl, traverse linked list until index * |
4645 | + * of acl matches the count we are keeping. This count is * | |
4646 | + * incremented each time we return an acl entry. */ | |
fa26e11c | 4647 | + |
0f6733d8 | 4648 | + for(keep_going = 0; keep_going < theacl->count; keep_going++) |
fa26e11c WD |
4649 | + link = link->nextp; |
4650 | + | |
4651 | + entry = *entry_p = link->entryp; | |
4652 | + | |
4653 | + DEBUG(10,("*entry_p is %d\n",entry_p)); | |
4654 | + DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access)); | |
4655 | + | |
4656 | + /* Increment count */ | |
4657 | + theacl->count++; | |
0f6733d8 | 4658 | + if(link->nextp == NULL) |
fa26e11c WD |
4659 | + theacl->count = -1; |
4660 | + | |
0f6733d8 | 4661 | + return(1); |
fa26e11c WD |
4662 | +} |
4663 | + | |
0f6733d8 | 4664 | +int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) |
fa26e11c WD |
4665 | +{ |
4666 | + /* Initialize tag type */ | |
4667 | + | |
4668 | + *tag_type_p = -1; | |
4669 | + DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type)); | |
4670 | + | |
0f6733d8 WD |
4671 | + /* Depending on what type of entry we have, * |
4672 | + * return tag type. */ | |
4673 | + switch(entry_d->ace_id->id_type) { | |
fa26e11c WD |
4674 | + case ACEID_USER: |
4675 | + *tag_type_p = SMB_ACL_USER; | |
4676 | + break; | |
4677 | + case ACEID_GROUP: | |
4678 | + *tag_type_p = SMB_ACL_GROUP; | |
4679 | + break; | |
4680 | + | |
4681 | + case SMB_ACL_USER_OBJ: | |
4682 | + case SMB_ACL_GROUP_OBJ: | |
4683 | + case SMB_ACL_OTHER: | |
4684 | + *tag_type_p = entry_d->ace_id->id_type; | |
4685 | + break; | |
0f6733d8 | 4686 | + |
fa26e11c | 4687 | + default: |
0f6733d8 | 4688 | + return(-1); |
fa26e11c WD |
4689 | + } |
4690 | + | |
0f6733d8 | 4691 | + return(0); |
fa26e11c WD |
4692 | +} |
4693 | + | |
0f6733d8 | 4694 | +int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) |
fa26e11c WD |
4695 | +{ |
4696 | + DEBUG(10,("Starting AIX sys_acl_get_permset\n")); | |
4697 | + *permset_p = &entry_d->ace_access; | |
4698 | + DEBUG(10,("**permset_p is %d\n",**permset_p)); | |
0f6733d8 WD |
4699 | + if(!(**permset_p & S_IXUSR) && |
4700 | + !(**permset_p & S_IWUSR) && | |
4701 | + !(**permset_p & S_IRUSR) && | |
4702 | + (**permset_p != 0)) | |
4703 | + return(-1); | |
fa26e11c WD |
4704 | + |
4705 | + DEBUG(10,("Ending AIX sys_acl_get_permset\n")); | |
0f6733d8 | 4706 | + return(0); |
fa26e11c WD |
4707 | +} |
4708 | + | |
0f6733d8 | 4709 | +void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) |
fa26e11c | 4710 | +{ |
0f6733d8 | 4711 | + return(entry_d->ace_id->id_data); |
fa26e11c WD |
4712 | +} |
4713 | + | |
0f6733d8 | 4714 | +SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) |
fa26e11c WD |
4715 | +{ |
4716 | + struct acl *file_acl = (struct acl *)NULL; | |
4717 | + struct acl_entry *acl_entry; | |
4718 | + struct new_acl_entry *new_acl_entry; | |
4719 | + struct ace_id *idp; | |
4720 | + struct acl_entry_link *acl_entry_link; | |
4721 | + struct acl_entry_link *acl_entry_link_head; | |
4722 | + int i; | |
4723 | + int rc = 0; | |
4724 | + uid_t user_id; | |
4725 | + | |
252945ef | 4726 | + /* AIX has no DEFAULT */ |
85148847 WD |
4727 | + if ( type == SMB_ACL_TYPE_DEFAULT ) { |
4728 | + errno = ENOTSUP; | |
252945ef | 4729 | + return NULL; |
85148847 | 4730 | + } |
252945ef | 4731 | + |
fa26e11c | 4732 | + /* Get the acl using statacl */ |
0f6733d8 | 4733 | + |
fa26e11c WD |
4734 | + DEBUG(10,("Entering sys_acl_get_file\n")); |
4735 | + DEBUG(10,("path_p is %s\n",path_p)); | |
4736 | + | |
252945ef | 4737 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
0f6733d8 WD |
4738 | + |
4739 | + if(file_acl == NULL) { | |
fa26e11c WD |
4740 | + errno=ENOMEM; |
4741 | + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno)); | |
0f6733d8 | 4742 | + return(NULL); |
fa26e11c WD |
4743 | + } |
4744 | + | |
4745 | + memset(file_acl,0,BUFSIZ); | |
4746 | + | |
4747 | + rc = statacl((char *)path_p,0,file_acl,BUFSIZ); | |
0f6733d8 | 4748 | + if(rc == -1) { |
fa26e11c | 4749 | + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno)); |
0f6733d8 WD |
4750 | + SAFE_FREE(file_acl); |
4751 | + return(NULL); | |
fa26e11c WD |
4752 | + } |
4753 | + | |
4754 | + DEBUG(10,("Got facl and returned it\n")); | |
4755 | + | |
4756 | + /* Point to the first acl entry in the acl */ | |
4757 | + acl_entry = file_acl->acl_ext; | |
4758 | + | |
0f6733d8 WD |
4759 | + /* Begin setting up the head of the linked list * |
4760 | + * that will be used for the storing the acl * | |
4761 | + * in a way that is useful for the posix_acls.c * | |
4762 | + * code. */ | |
fa26e11c WD |
4763 | + |
4764 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); | |
0f6733d8 WD |
4765 | + if(acl_entry_link_head == NULL) |
4766 | + return(NULL); | |
fa26e11c | 4767 | + |
252945ef | 4768 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
4769 | + if(acl_entry_link->entryp == NULL) { |
4770 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4771 | + errno = ENOMEM; |
4772 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4773 | + return(NULL); |
fa26e11c WD |
4774 | + } |
4775 | + | |
4776 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); | |
4777 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); | |
4778 | + | |
0f6733d8 WD |
4779 | + /* Check if the extended acl bit is on. * |
4780 | + * If it isn't, do not show the * | |
4781 | + * contents of the acl since AIX intends * | |
4782 | + * the extended info to remain unused */ | |
fa26e11c | 4783 | + |
0f6733d8 | 4784 | + if(file_acl->acl_mode & S_IXACL){ |
fa26e11c | 4785 | + /* while we are not pointing to the very end */ |
0f6733d8 | 4786 | + while(acl_entry < acl_last(file_acl)) { |
fa26e11c WD |
4787 | + /* before we malloc anything, make sure this is */ |
4788 | + /* a valid acl entry and one that we want to map */ | |
4789 | + idp = id_nxt(acl_entry->ace_id); | |
0f6733d8 WD |
4790 | + if((acl_entry->ace_type == ACC_SPECIFY || |
4791 | + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { | |
4792 | + acl_entry = acl_nxt(acl_entry); | |
4793 | + continue; | |
fa26e11c WD |
4794 | + } |
4795 | + | |
4796 | + idp = acl_entry->ace_id; | |
4797 | + | |
0f6733d8 WD |
4798 | + /* Check if this is the first entry in the linked list. * |
4799 | + * The first entry needs to keep prevp pointing to NULL * | |
4800 | + * and already has entryp allocated. */ | |
fa26e11c | 4801 | + |
0f6733d8 | 4802 | + if(acl_entry_link_head->count != 0) { |
252945ef | 4803 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
fa26e11c | 4804 | + |
0f6733d8 WD |
4805 | + if(acl_entry_link->nextp == NULL) { |
4806 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4807 | + errno = ENOMEM; |
4808 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4809 | + return(NULL); |
fa26e11c WD |
4810 | + } |
4811 | + | |
4812 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4813 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4814 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
4815 | + if(acl_entry_link->entryp == NULL) { |
4816 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4817 | + errno = ENOMEM; |
4818 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4819 | + return(NULL); |
fa26e11c WD |
4820 | + } |
4821 | + acl_entry_link->nextp = NULL; | |
4822 | + } | |
4823 | + | |
4824 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; | |
4825 | + | |
0f6733d8 WD |
4826 | + /* Don't really need this since all types are going * |
4827 | + * to be specified but, it's better than leaving it 0 */ | |
fa26e11c WD |
4828 | + |
4829 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; | |
0f6733d8 | 4830 | + |
fa26e11c | 4831 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; |
0f6733d8 WD |
4832 | + |
4833 | + memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id)); | |
fa26e11c | 4834 | + |
0f6733d8 WD |
4835 | + /* The access in the acl entries must be left shifted by * |
4836 | + * three bites, because they will ultimately be compared * | |
4837 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ | |
fa26e11c | 4838 | + |
0f6733d8 | 4839 | + switch(acl_entry->ace_type){ |
fa26e11c WD |
4840 | + case ACC_PERMIT: |
4841 | + case ACC_SPECIFY: | |
4842 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
4843 | + acl_entry_link->entryp->ace_access <<= 6; | |
4844 | + acl_entry_link_head->count++; | |
4845 | + break; | |
4846 | + case ACC_DENY: | |
0f6733d8 WD |
4847 | + /* Since there is no way to return a DENY acl entry * |
4848 | + * change to PERMIT and then shift. */ | |
fa26e11c WD |
4849 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); |
4850 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; | |
4851 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); | |
4852 | + acl_entry_link->entryp->ace_access <<= 6; | |
4853 | + acl_entry_link_head->count++; | |
4854 | + break; | |
4855 | + default: | |
0f6733d8 | 4856 | + return(0); |
fa26e11c WD |
4857 | + } |
4858 | + | |
4859 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); | |
4860 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); | |
0f6733d8 | 4861 | + |
fa26e11c WD |
4862 | + acl_entry = acl_nxt(acl_entry); |
4863 | + } | |
4864 | + } /* end of if enabled */ | |
4865 | + | |
0f6733d8 WD |
4866 | + /* Since owner, group, other acl entries are not * |
4867 | + * part of the acl entries in an acl, they must * | |
4868 | + * be dummied up to become part of the list. */ | |
fa26e11c | 4869 | + |
0f6733d8 | 4870 | + for( i = 1; i < 4; i++) { |
fa26e11c | 4871 | + DEBUG(10,("i is %d\n",i)); |
0f6733d8 | 4872 | + if(acl_entry_link_head->count != 0) { |
252945ef | 4873 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 WD |
4874 | + if(acl_entry_link->nextp == NULL) { |
4875 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4876 | + errno = ENOMEM; |
4877 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4878 | + return(NULL); |
fa26e11c WD |
4879 | + } |
4880 | + | |
4881 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
4882 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 4883 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 WD |
4884 | + if(acl_entry_link->entryp == NULL) { |
4885 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
4886 | + errno = ENOMEM; |
4887 | + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); | |
0f6733d8 | 4888 | + return(NULL); |
fa26e11c WD |
4889 | + } |
4890 | + } | |
4891 | + | |
4892 | + acl_entry_link->nextp = NULL; | |
4893 | + | |
4894 | + new_acl_entry = acl_entry_link->entryp; | |
4895 | + idp = new_acl_entry->ace_id; | |
4896 | + | |
0f6733d8 | 4897 | + new_acl_entry->ace_len = sizeof(struct acl_entry); |
fa26e11c | 4898 | + new_acl_entry->ace_type = ACC_PERMIT; |
0f6733d8 | 4899 | + idp->id_len = sizeof(struct ace_id); |
fa26e11c | 4900 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); |
0f6733d8 | 4901 | + memset(idp->id_data,0,sizeof(uid_t)); |
fa26e11c | 4902 | + |
0f6733d8 | 4903 | + switch(i) { |
fa26e11c WD |
4904 | + case 2: |
4905 | + new_acl_entry->ace_access = file_acl->g_access << 6; | |
4906 | + idp->id_type = SMB_ACL_GROUP_OBJ; | |
4907 | + break; | |
4908 | + | |
4909 | + case 3: | |
4910 | + new_acl_entry->ace_access = file_acl->o_access << 6; | |
4911 | + idp->id_type = SMB_ACL_OTHER; | |
4912 | + break; | |
0f6733d8 | 4913 | + |
fa26e11c WD |
4914 | + case 1: |
4915 | + new_acl_entry->ace_access = file_acl->u_access << 6; | |
4916 | + idp->id_type = SMB_ACL_USER_OBJ; | |
4917 | + break; | |
0f6733d8 | 4918 | + |
fa26e11c | 4919 | + default: |
0f6733d8 | 4920 | + return(NULL); |
fa26e11c WD |
4921 | + |
4922 | + } | |
4923 | + | |
4924 | + acl_entry_link_head->count++; | |
4925 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); | |
4926 | + } | |
4927 | + | |
4928 | + acl_entry_link_head->count = 0; | |
0f6733d8 | 4929 | + SAFE_FREE(file_acl); |
fa26e11c | 4930 | + |
0f6733d8 | 4931 | + return(acl_entry_link_head); |
fa26e11c WD |
4932 | +} |
4933 | + | |
0f6733d8 | 4934 | +SMB_ACL_T sys_acl_get_fd(int fd) |
fa26e11c WD |
4935 | +{ |
4936 | + struct acl *file_acl = (struct acl *)NULL; | |
4937 | + struct acl_entry *acl_entry; | |
4938 | + struct new_acl_entry *new_acl_entry; | |
4939 | + struct ace_id *idp; | |
4940 | + struct acl_entry_link *acl_entry_link; | |
4941 | + struct acl_entry_link *acl_entry_link_head; | |
4942 | + int i; | |
4943 | + int rc = 0; | |
4944 | + uid_t user_id; | |
4945 | + | |
4946 | + /* Get the acl using fstatacl */ | |
0f6733d8 | 4947 | + |
fa26e11c WD |
4948 | + DEBUG(10,("Entering sys_acl_get_fd\n")); |
4949 | + DEBUG(10,("fd is %d\n",fd)); | |
252945ef | 4950 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 4951 | + |
0f6733d8 | 4952 | + if(file_acl == NULL) { |
fa26e11c WD |
4953 | + errno=ENOMEM; |
4954 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 | 4955 | + return(NULL); |
fa26e11c WD |
4956 | + } |
4957 | + | |
4958 | + memset(file_acl,0,BUFSIZ); | |
4959 | + | |
4960 | + rc = fstatacl(fd,0,file_acl,BUFSIZ); | |
0f6733d8 | 4961 | + if(rc == -1) { |
fa26e11c | 4962 | + DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno)); |
0f6733d8 WD |
4963 | + SAFE_FREE(file_acl); |
4964 | + return(NULL); | |
fa26e11c WD |
4965 | + } |
4966 | + | |
4967 | + DEBUG(10,("Got facl and returned it\n")); | |
4968 | + | |
4969 | + /* Point to the first acl entry in the acl */ | |
4970 | + | |
4971 | + acl_entry = file_acl->acl_ext; | |
0f6733d8 WD |
4972 | + /* Begin setting up the head of the linked list * |
4973 | + * that will be used for the storing the acl * | |
4974 | + * in a way that is useful for the posix_acls.c * | |
4975 | + * code. */ | |
fa26e11c WD |
4976 | + |
4977 | + acl_entry_link_head = acl_entry_link = sys_acl_init(0); | |
0f6733d8 WD |
4978 | + if(acl_entry_link_head == NULL){ |
4979 | + SAFE_FREE(file_acl); | |
4980 | + return(NULL); | |
fa26e11c WD |
4981 | + } |
4982 | + | |
252945ef | 4983 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
fa26e11c | 4984 | + |
0f6733d8 | 4985 | + if(acl_entry_link->entryp == NULL) { |
fa26e11c WD |
4986 | + errno = ENOMEM; |
4987 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
4988 | + SAFE_FREE(file_acl); |
4989 | + return(NULL); | |
fa26e11c WD |
4990 | + } |
4991 | + | |
4992 | + DEBUG(10,("acl_entry is %d\n",acl_entry)); | |
4993 | + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); | |
0f6733d8 WD |
4994 | + |
4995 | + /* Check if the extended acl bit is on. * | |
4996 | + * If it isn't, do not show the * | |
4997 | + * contents of the acl since AIX intends * | |
4998 | + * the extended info to remain unused */ | |
4999 | + | |
5000 | + if(file_acl->acl_mode & S_IXACL){ | |
fa26e11c | 5001 | + /* while we are not pointing to the very end */ |
0f6733d8 | 5002 | + while(acl_entry < acl_last(file_acl)) { |
fa26e11c WD |
5003 | + /* before we malloc anything, make sure this is */ |
5004 | + /* a valid acl entry and one that we want to map */ | |
5005 | + | |
5006 | + idp = id_nxt(acl_entry->ace_id); | |
0f6733d8 WD |
5007 | + if((acl_entry->ace_type == ACC_SPECIFY || |
5008 | + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { | |
5009 | + acl_entry = acl_nxt(acl_entry); | |
5010 | + continue; | |
fa26e11c WD |
5011 | + } |
5012 | + | |
5013 | + idp = acl_entry->ace_id; | |
0f6733d8 WD |
5014 | + |
5015 | + /* Check if this is the first entry in the linked list. * | |
5016 | + * The first entry needs to keep prevp pointing to NULL * | |
5017 | + * and already has entryp allocated. */ | |
fa26e11c | 5018 | + |
0f6733d8 | 5019 | + if(acl_entry_link_head->count != 0) { |
252945ef | 5020 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 5021 | + if(acl_entry_link->nextp == NULL) { |
fa26e11c WD |
5022 | + errno = ENOMEM; |
5023 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
5024 | + SAFE_FREE(file_acl); |
5025 | + return(NULL); | |
fa26e11c WD |
5026 | + } |
5027 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
5028 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 5029 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 | 5030 | + if(acl_entry_link->entryp == NULL) { |
fa26e11c WD |
5031 | + errno = ENOMEM; |
5032 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
5033 | + SAFE_FREE(file_acl); |
5034 | + return(NULL); | |
fa26e11c WD |
5035 | + } |
5036 | + | |
5037 | + acl_entry_link->nextp = NULL; | |
5038 | + } | |
5039 | + | |
5040 | + acl_entry_link->entryp->ace_len = acl_entry->ace_len; | |
5041 | + | |
0f6733d8 WD |
5042 | + /* Don't really need this since all types are going * |
5043 | + * to be specified but, it's better than leaving it 0 */ | |
fa26e11c WD |
5044 | + |
5045 | + acl_entry_link->entryp->ace_type = acl_entry->ace_type; | |
5046 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
5047 | + | |
0f6733d8 | 5048 | + memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id)); |
fa26e11c | 5049 | + |
0f6733d8 WD |
5050 | + /* The access in the acl entries must be left shifted by * |
5051 | + * three bites, because they will ultimately be compared * | |
5052 | + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ | |
fa26e11c | 5053 | + |
0f6733d8 | 5054 | + switch(acl_entry->ace_type){ |
fa26e11c WD |
5055 | + case ACC_PERMIT: |
5056 | + case ACC_SPECIFY: | |
5057 | + acl_entry_link->entryp->ace_access = acl_entry->ace_access; | |
5058 | + acl_entry_link->entryp->ace_access <<= 6; | |
5059 | + acl_entry_link_head->count++; | |
5060 | + break; | |
5061 | + case ACC_DENY: | |
0f6733d8 WD |
5062 | + /* Since there is no way to return a DENY acl entry * |
5063 | + * change to PERMIT and then shift. */ | |
fa26e11c WD |
5064 | + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); |
5065 | + acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7; | |
5066 | + DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access)); | |
5067 | + acl_entry_link->entryp->ace_access <<= 6; | |
5068 | + acl_entry_link_head->count++; | |
5069 | + break; | |
5070 | + default: | |
0f6733d8 | 5071 | + return(0); |
fa26e11c WD |
5072 | + } |
5073 | + | |
5074 | + DEBUG(10,("acl_entry = %d\n",acl_entry)); | |
5075 | + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); | |
0f6733d8 | 5076 | + |
fa26e11c WD |
5077 | + acl_entry = acl_nxt(acl_entry); |
5078 | + } | |
5079 | + } /* end of if enabled */ | |
5080 | + | |
0f6733d8 WD |
5081 | + /* Since owner, group, other acl entries are not * |
5082 | + * part of the acl entries in an acl, they must * | |
5083 | + * be dummied up to become part of the list. */ | |
fa26e11c | 5084 | + |
0f6733d8 | 5085 | + for( i = 1; i < 4; i++) { |
fa26e11c | 5086 | + DEBUG(10,("i is %d\n",i)); |
0f6733d8 | 5087 | + if(acl_entry_link_head->count != 0){ |
252945ef | 5088 | + acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 5089 | + if(acl_entry_link->nextp == NULL) { |
fa26e11c WD |
5090 | + errno = ENOMEM; |
5091 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 WD |
5092 | + SAFE_FREE(file_acl); |
5093 | + return(NULL); | |
fa26e11c WD |
5094 | + } |
5095 | + | |
5096 | + acl_entry_link->nextp->prevp = acl_entry_link; | |
5097 | + acl_entry_link = acl_entry_link->nextp; | |
252945ef | 5098 | + acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry); |
fa26e11c | 5099 | + |
0f6733d8 WD |
5100 | + if(acl_entry_link->entryp == NULL) { |
5101 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
5102 | + errno = ENOMEM; |
5103 | + DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno)); | |
0f6733d8 | 5104 | + return(NULL); |
fa26e11c WD |
5105 | + } |
5106 | + } | |
5107 | + | |
5108 | + acl_entry_link->nextp = NULL; | |
0f6733d8 | 5109 | + |
fa26e11c WD |
5110 | + new_acl_entry = acl_entry_link->entryp; |
5111 | + idp = new_acl_entry->ace_id; | |
0f6733d8 WD |
5112 | + |
5113 | + new_acl_entry->ace_len = sizeof(struct acl_entry); | |
fa26e11c | 5114 | + new_acl_entry->ace_type = ACC_PERMIT; |
0f6733d8 | 5115 | + idp->id_len = sizeof(struct ace_id); |
fa26e11c | 5116 | + DEBUG(10,("idp->id_len = %d\n",idp->id_len)); |
0f6733d8 WD |
5117 | + memset(idp->id_data,0,sizeof(uid_t)); |
5118 | + | |
5119 | + switch(i) { | |
fa26e11c WD |
5120 | + case 2: |
5121 | + new_acl_entry->ace_access = file_acl->g_access << 6; | |
5122 | + idp->id_type = SMB_ACL_GROUP_OBJ; | |
5123 | + break; | |
0f6733d8 | 5124 | + |
fa26e11c WD |
5125 | + case 3: |
5126 | + new_acl_entry->ace_access = file_acl->o_access << 6; | |
5127 | + idp->id_type = SMB_ACL_OTHER; | |
5128 | + break; | |
0f6733d8 | 5129 | + |
fa26e11c WD |
5130 | + case 1: |
5131 | + new_acl_entry->ace_access = file_acl->u_access << 6; | |
5132 | + idp->id_type = SMB_ACL_USER_OBJ; | |
5133 | + break; | |
0f6733d8 | 5134 | + |
fa26e11c | 5135 | + default: |
0f6733d8 | 5136 | + return(NULL); |
fa26e11c | 5137 | + } |
0f6733d8 | 5138 | + |
fa26e11c WD |
5139 | + acl_entry_link_head->count++; |
5140 | + DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access)); | |
5141 | + } | |
5142 | + | |
5143 | + acl_entry_link_head->count = 0; | |
0f6733d8 WD |
5144 | + SAFE_FREE(file_acl); |
5145 | + | |
5146 | + return(acl_entry_link_head); | |
fa26e11c WD |
5147 | +} |
5148 | + | |
0f6733d8 | 5149 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
5150 | +{ |
5151 | + *permset = *permset & ~0777; | |
0f6733d8 | 5152 | + return(0); |
fa26e11c WD |
5153 | +} |
5154 | + | |
0f6733d8 | 5155 | +int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 5156 | +{ |
0f6733d8 WD |
5157 | + if((perm != 0) && |
5158 | + (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0) | |
5159 | + return(-1); | |
fa26e11c WD |
5160 | + |
5161 | + *permset |= perm; | |
5162 | + DEBUG(10,("This is the permset now: %d\n",*permset)); | |
0f6733d8 | 5163 | + return(0); |
fa26e11c WD |
5164 | +} |
5165 | + | |
0f6733d8 | 5166 | +char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) |
fa26e11c | 5167 | +{ |
0f6733d8 | 5168 | + return(NULL); |
fa26e11c WD |
5169 | +} |
5170 | + | |
0f6733d8 | 5171 | +SMB_ACL_T sys_acl_init( int count) |
fa26e11c WD |
5172 | +{ |
5173 | + struct acl_entry_link *theacl = NULL; | |
0f6733d8 | 5174 | + |
fa26e11c WD |
5175 | + DEBUG(10,("Entering sys_acl_init\n")); |
5176 | + | |
252945ef | 5177 | + theacl = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 5178 | + if(theacl == NULL) { |
fa26e11c WD |
5179 | + errno = ENOMEM; |
5180 | + DEBUG(0,("Error in sys_acl_init is %d\n",errno)); | |
0f6733d8 | 5181 | + return(NULL); |
fa26e11c WD |
5182 | + } |
5183 | + | |
5184 | + theacl->count = 0; | |
5185 | + theacl->nextp = NULL; | |
5186 | + theacl->prevp = NULL; | |
5187 | + theacl->entryp = NULL; | |
5188 | + DEBUG(10,("Exiting sys_acl_init\n")); | |
0f6733d8 | 5189 | + return(theacl); |
fa26e11c WD |
5190 | +} |
5191 | + | |
0f6733d8 | 5192 | +int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) |
fa26e11c WD |
5193 | +{ |
5194 | + struct acl_entry_link *theacl; | |
5195 | + struct acl_entry_link *acl_entryp; | |
5196 | + struct acl_entry_link *temp_entry; | |
5197 | + int counting; | |
5198 | + | |
5199 | + DEBUG(10,("Entering the sys_acl_create_entry\n")); | |
5200 | + | |
5201 | + theacl = acl_entryp = *pacl; | |
5202 | + | |
5203 | + /* Get to the end of the acl before adding entry */ | |
5204 | + | |
0f6733d8 | 5205 | + for(counting=0; counting < theacl->count; counting++){ |
fa26e11c WD |
5206 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); |
5207 | + temp_entry = acl_entryp; | |
5208 | + acl_entryp = acl_entryp->nextp; | |
5209 | + } | |
5210 | + | |
0f6733d8 | 5211 | + if(theacl->count != 0){ |
252945ef | 5212 | + temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link); |
0f6733d8 | 5213 | + if(acl_entryp == NULL) { |
fa26e11c WD |
5214 | + errno = ENOMEM; |
5215 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); | |
0f6733d8 | 5216 | + return(-1); |
fa26e11c WD |
5217 | + } |
5218 | + | |
5219 | + DEBUG(10,("The acl_entryp is %d\n",acl_entryp)); | |
5220 | + acl_entryp->prevp = temp_entry; | |
5221 | + DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp)); | |
5222 | + } | |
5223 | + | |
252945ef | 5224 | + *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry); |
0f6733d8 | 5225 | + if(*pentry == NULL) { |
fa26e11c WD |
5226 | + errno = ENOMEM; |
5227 | + DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno)); | |
0f6733d8 | 5228 | + return(-1); |
fa26e11c WD |
5229 | + } |
5230 | + | |
0f6733d8 WD |
5231 | + memset(*pentry,0,sizeof(struct new_acl_entry)); |
5232 | + acl_entryp->entryp->ace_len = sizeof(struct acl_entry); | |
fa26e11c | 5233 | + acl_entryp->entryp->ace_type = ACC_PERMIT; |
0f6733d8 | 5234 | + acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id); |
fa26e11c WD |
5235 | + acl_entryp->nextp = NULL; |
5236 | + theacl->count++; | |
5237 | + DEBUG(10,("Exiting sys_acl_create_entry\n")); | |
0f6733d8 | 5238 | + return(0); |
fa26e11c WD |
5239 | +} |
5240 | + | |
0f6733d8 | 5241 | +int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) |
fa26e11c WD |
5242 | +{ |
5243 | + DEBUG(10,("Starting AIX sys_acl_set_tag_type\n")); | |
5244 | + entry->ace_id->id_type = tagtype; | |
5245 | + DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type)); | |
5246 | + DEBUG(10,("Ending AIX sys_acl_set_tag_type\n")); | |
5247 | +} | |
5248 | + | |
0f6733d8 | 5249 | +int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) |
fa26e11c WD |
5250 | +{ |
5251 | + DEBUG(10,("Starting AIX sys_acl_set_qualifier\n")); | |
0f6733d8 | 5252 | + memcpy(entry->ace_id->id_data,qual,sizeof(uid_t)); |
fa26e11c | 5253 | + DEBUG(10,("Ending AIX sys_acl_set_qualifier\n")); |
0f6733d8 | 5254 | + return(0); |
fa26e11c WD |
5255 | +} |
5256 | + | |
0f6733d8 | 5257 | +int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) |
fa26e11c WD |
5258 | +{ |
5259 | + DEBUG(10,("Starting AIX sys_acl_set_permset\n")); | |
0f6733d8 WD |
5260 | + if(!(*permset & S_IXUSR) && |
5261 | + !(*permset & S_IWUSR) && | |
5262 | + !(*permset & S_IRUSR) && | |
5263 | + (*permset != 0)) | |
5264 | + return(-1); | |
fa26e11c WD |
5265 | + |
5266 | + entry->ace_access = *permset; | |
5267 | + DEBUG(10,("entry->ace_access = %d\n",entry->ace_access)); | |
5268 | + DEBUG(10,("Ending AIX sys_acl_set_permset\n")); | |
0f6733d8 | 5269 | + return(0); |
fa26e11c WD |
5270 | +} |
5271 | + | |
0f6733d8 | 5272 | +int sys_acl_valid( SMB_ACL_T theacl ) |
fa26e11c WD |
5273 | +{ |
5274 | + int user_obj = 0; | |
5275 | + int group_obj = 0; | |
5276 | + int other_obj = 0; | |
5277 | + struct acl_entry_link *acl_entry; | |
5278 | + | |
0f6733d8 | 5279 | + for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) { |
fa26e11c WD |
5280 | + user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ); |
5281 | + group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ); | |
5282 | + other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER); | |
5283 | + } | |
5284 | + | |
5285 | + DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj)); | |
0f6733d8 WD |
5286 | + |
5287 | + if(user_obj != 1 || group_obj != 1 || other_obj != 1) | |
5288 | + return(-1); | |
fa26e11c | 5289 | + |
0f6733d8 | 5290 | + return(0); |
fa26e11c WD |
5291 | +} |
5292 | + | |
0f6733d8 | 5293 | +int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) |
fa26e11c WD |
5294 | +{ |
5295 | + struct acl_entry_link *acl_entry_link = NULL; | |
5296 | + struct acl *file_acl = NULL; | |
5297 | + struct acl *file_acl_temp = NULL; | |
5298 | + struct acl_entry *acl_entry = NULL; | |
5299 | + struct ace_id *ace_id = NULL; | |
5300 | + uint id_type; | |
5301 | + uint ace_access; | |
5302 | + uint user_id; | |
5303 | + uint acl_length; | |
5304 | + uint rc; | |
5305 | + | |
5306 | + DEBUG(10,("Entering sys_acl_set_file\n")); | |
5307 | + DEBUG(10,("File name is %s\n",name)); | |
0f6733d8 | 5308 | + |
fa26e11c | 5309 | + /* AIX has no default ACL */ |
0f6733d8 WD |
5310 | + if(acltype == SMB_ACL_TYPE_DEFAULT) |
5311 | + return(0); | |
fa26e11c WD |
5312 | + |
5313 | + acl_length = BUFSIZ; | |
252945ef | 5314 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 5315 | + |
0f6733d8 | 5316 | + if(file_acl == NULL) { |
fa26e11c WD |
5317 | + errno = ENOMEM; |
5318 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); | |
0f6733d8 | 5319 | + return(-1); |
fa26e11c WD |
5320 | + } |
5321 | + | |
5322 | + memset(file_acl,0,BUFSIZ); | |
5323 | + | |
5324 | + file_acl->acl_len = ACL_SIZ; | |
5325 | + file_acl->acl_mode = S_IXACL; | |
5326 | + | |
0f6733d8 | 5327 | + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
fa26e11c WD |
5328 | + acl_entry_link->entryp->ace_access >>= 6; |
5329 | + id_type = acl_entry_link->entryp->ace_id->id_type; | |
5330 | + | |
0f6733d8 | 5331 | + switch(id_type) { |
fa26e11c WD |
5332 | + case SMB_ACL_USER_OBJ: |
5333 | + file_acl->u_access = acl_entry_link->entryp->ace_access; | |
5334 | + continue; | |
5335 | + case SMB_ACL_GROUP_OBJ: | |
5336 | + file_acl->g_access = acl_entry_link->entryp->ace_access; | |
5337 | + continue; | |
5338 | + case SMB_ACL_OTHER: | |
5339 | + file_acl->o_access = acl_entry_link->entryp->ace_access; | |
5340 | + continue; | |
5341 | + case SMB_ACL_MASK: | |
5342 | + continue; | |
5343 | + } | |
5344 | + | |
0f6733d8 WD |
5345 | + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { |
5346 | + acl_length += sizeof(struct acl_entry); | |
252945ef | 5347 | + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
0f6733d8 WD |
5348 | + if(file_acl_temp == NULL) { |
5349 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
5350 | + errno = ENOMEM; |
5351 | + DEBUG(0,("Error in sys_acl_set_file is %d\n",errno)); | |
0f6733d8 WD |
5352 | + return(-1); |
5353 | + } | |
fa26e11c WD |
5354 | + |
5355 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); | |
0f6733d8 | 5356 | + SAFE_FREE(file_acl); |
fa26e11c WD |
5357 | + file_acl = file_acl_temp; |
5358 | + } | |
5359 | + | |
5360 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); | |
0f6733d8 | 5361 | + file_acl->acl_len += sizeof(struct acl_entry); |
fa26e11c WD |
5362 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
5363 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; | |
0f6733d8 | 5364 | + |
fa26e11c | 5365 | + /* In order to use this, we'll need to wait until we can get denies */ |
0f6733d8 WD |
5366 | + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) |
5367 | + acl_entry->ace_type = ACC_SPECIFY; */ | |
fa26e11c WD |
5368 | + |
5369 | + acl_entry->ace_type = ACC_SPECIFY; | |
0f6733d8 | 5370 | + |
fa26e11c | 5371 | + ace_id = acl_entry->ace_id; |
0f6733d8 | 5372 | + |
fa26e11c WD |
5373 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
5374 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); | |
5375 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; | |
0f6733d8 WD |
5376 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t)); |
5377 | + memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t)); | |
fa26e11c WD |
5378 | + } |
5379 | + | |
0f6733d8 | 5380 | + rc = chacl(name,file_acl,file_acl->acl_len); |
fa26e11c WD |
5381 | + DEBUG(10,("errno is %d\n",errno)); |
5382 | + DEBUG(10,("return code is %d\n",rc)); | |
0f6733d8 | 5383 | + SAFE_FREE(file_acl); |
fa26e11c | 5384 | + DEBUG(10,("Exiting the sys_acl_set_file\n")); |
0f6733d8 | 5385 | + return(rc); |
fa26e11c WD |
5386 | +} |
5387 | + | |
0f6733d8 | 5388 | +int sys_acl_set_fd( int fd, SMB_ACL_T theacl) |
fa26e11c WD |
5389 | +{ |
5390 | + struct acl_entry_link *acl_entry_link = NULL; | |
5391 | + struct acl *file_acl = NULL; | |
5392 | + struct acl *file_acl_temp = NULL; | |
5393 | + struct acl_entry *acl_entry = NULL; | |
5394 | + struct ace_id *ace_id = NULL; | |
5395 | + uint id_type; | |
5396 | + uint user_id; | |
5397 | + uint acl_length; | |
5398 | + uint rc; | |
0f6733d8 | 5399 | + |
fa26e11c WD |
5400 | + DEBUG(10,("Entering sys_acl_set_fd\n")); |
5401 | + acl_length = BUFSIZ; | |
252945ef | 5402 | + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); |
fa26e11c | 5403 | + |
0f6733d8 | 5404 | + if(file_acl == NULL) { |
fa26e11c WD |
5405 | + errno = ENOMEM; |
5406 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); | |
0f6733d8 | 5407 | + return(-1); |
fa26e11c WD |
5408 | + } |
5409 | + | |
5410 | + memset(file_acl,0,BUFSIZ); | |
0f6733d8 | 5411 | + |
fa26e11c WD |
5412 | + file_acl->acl_len = ACL_SIZ; |
5413 | + file_acl->acl_mode = S_IXACL; | |
5414 | + | |
0f6733d8 | 5415 | + for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) { |
fa26e11c WD |
5416 | + acl_entry_link->entryp->ace_access >>= 6; |
5417 | + id_type = acl_entry_link->entryp->ace_id->id_type; | |
5418 | + DEBUG(10,("The id_type is %d\n",id_type)); | |
5419 | + | |
0f6733d8 | 5420 | + switch(id_type) { |
fa26e11c WD |
5421 | + case SMB_ACL_USER_OBJ: |
5422 | + file_acl->u_access = acl_entry_link->entryp->ace_access; | |
5423 | + continue; | |
5424 | + case SMB_ACL_GROUP_OBJ: | |
5425 | + file_acl->g_access = acl_entry_link->entryp->ace_access; | |
5426 | + continue; | |
5427 | + case SMB_ACL_OTHER: | |
5428 | + file_acl->o_access = acl_entry_link->entryp->ace_access; | |
5429 | + continue; | |
5430 | + case SMB_ACL_MASK: | |
5431 | + continue; | |
5432 | + } | |
5433 | + | |
0f6733d8 WD |
5434 | + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { |
5435 | + acl_length += sizeof(struct acl_entry); | |
252945ef | 5436 | + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); |
0f6733d8 WD |
5437 | + if(file_acl_temp == NULL) { |
5438 | + SAFE_FREE(file_acl); | |
fa26e11c WD |
5439 | + errno = ENOMEM; |
5440 | + DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno)); | |
0f6733d8 | 5441 | + return(-1); |
fa26e11c WD |
5442 | + } |
5443 | + | |
5444 | + memcpy(file_acl_temp,file_acl,file_acl->acl_len); | |
0f6733d8 | 5445 | + SAFE_FREE(file_acl); |
fa26e11c WD |
5446 | + file_acl = file_acl_temp; |
5447 | + } | |
5448 | + | |
5449 | + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); | |
0f6733d8 | 5450 | + file_acl->acl_len += sizeof(struct acl_entry); |
fa26e11c WD |
5451 | + acl_entry->ace_len = acl_entry_link->entryp->ace_len; |
5452 | + acl_entry->ace_access = acl_entry_link->entryp->ace_access; | |
0f6733d8 | 5453 | + |
fa26e11c | 5454 | + /* In order to use this, we'll need to wait until we can get denies */ |
0f6733d8 | 5455 | + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) |
fa26e11c | 5456 | + acl_entry->ace_type = ACC_SPECIFY; */ |
0f6733d8 | 5457 | + |
fa26e11c | 5458 | + acl_entry->ace_type = ACC_SPECIFY; |
0f6733d8 | 5459 | + |
fa26e11c | 5460 | + ace_id = acl_entry->ace_id; |
0f6733d8 | 5461 | + |
fa26e11c WD |
5462 | + ace_id->id_type = acl_entry_link->entryp->ace_id->id_type; |
5463 | + DEBUG(10,("The id type is %d\n",ace_id->id_type)); | |
5464 | + ace_id->id_len = acl_entry_link->entryp->ace_id->id_len; | |
0f6733d8 WD |
5465 | + memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t)); |
5466 | + memcpy(ace_id->id_data, &user_id, sizeof(uid_t)); | |
fa26e11c | 5467 | + } |
0f6733d8 | 5468 | + |
fa26e11c WD |
5469 | + rc = fchacl(fd,file_acl,file_acl->acl_len); |
5470 | + DEBUG(10,("errno is %d\n",errno)); | |
5471 | + DEBUG(10,("return code is %d\n",rc)); | |
0f6733d8 | 5472 | + SAFE_FREE(file_acl); |
fa26e11c | 5473 | + DEBUG(10,("Exiting sys_acl_set_fd\n")); |
0f6733d8 | 5474 | + return(rc); |
fa26e11c WD |
5475 | +} |
5476 | + | |
0f6733d8 | 5477 | +int sys_acl_delete_def_file(const char *name) |
fa26e11c WD |
5478 | +{ |
5479 | + /* AIX has no default ACL */ | |
5480 | + return 0; | |
5481 | +} | |
5482 | + | |
0f6733d8 | 5483 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c | 5484 | +{ |
0f6733d8 | 5485 | + return(*permset & perm); |
fa26e11c WD |
5486 | +} |
5487 | + | |
0f6733d8 | 5488 | +int sys_acl_free_text(char *text) |
fa26e11c | 5489 | +{ |
0f6733d8 | 5490 | + return(0); |
fa26e11c WD |
5491 | +} |
5492 | + | |
0f6733d8 | 5493 | +int sys_acl_free_acl(SMB_ACL_T posix_acl) |
fa26e11c WD |
5494 | +{ |
5495 | + struct acl_entry_link *acl_entry_link; | |
5496 | + | |
0f6733d8 WD |
5497 | + for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) { |
5498 | + SAFE_FREE(acl_entry_link->prevp->entryp); | |
5499 | + SAFE_FREE(acl_entry_link->prevp); | |
fa26e11c WD |
5500 | + } |
5501 | + | |
0f6733d8 WD |
5502 | + SAFE_FREE(acl_entry_link->prevp->entryp); |
5503 | + SAFE_FREE(acl_entry_link->prevp); | |
5504 | + SAFE_FREE(acl_entry_link->entryp); | |
5505 | + SAFE_FREE(acl_entry_link); | |
5506 | + | |
5507 | + return(0); | |
fa26e11c WD |
5508 | +} |
5509 | + | |
0f6733d8 | 5510 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype) |
fa26e11c | 5511 | +{ |
0f6733d8 | 5512 | + return(0); |
fa26e11c WD |
5513 | +} |
5514 | + | |
5515 | +#else /* No ACLs. */ | |
5516 | + | |
4df546eb | 5517 | +int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p)) |
fa26e11c WD |
5518 | +{ |
5519 | + errno = ENOSYS; | |
5520 | + return -1; | |
5521 | +} | |
5522 | + | |
4df546eb | 5523 | +int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p)) |
fa26e11c WD |
5524 | +{ |
5525 | + errno = ENOSYS; | |
5526 | + return -1; | |
5527 | +} | |
5528 | + | |
4df546eb | 5529 | +int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p)) |
fa26e11c WD |
5530 | +{ |
5531 | + errno = ENOSYS; | |
5532 | + return -1; | |
5533 | +} | |
5534 | + | |
4df546eb | 5535 | +void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d)) |
fa26e11c WD |
5536 | +{ |
5537 | + errno = ENOSYS; | |
5538 | + return NULL; | |
5539 | +} | |
5540 | + | |
4df546eb | 5541 | +SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type)) |
fa26e11c WD |
5542 | +{ |
5543 | + errno = ENOSYS; | |
5ca9317d | 5544 | + return (SMB_ACL_T)NULL; |
fa26e11c WD |
5545 | +} |
5546 | + | |
4df546eb | 5547 | +SMB_ACL_T sys_acl_get_fd(UNUSED(int fd)) |
fa26e11c WD |
5548 | +{ |
5549 | + errno = ENOSYS; | |
5ca9317d | 5550 | + return (SMB_ACL_T)NULL; |
fa26e11c WD |
5551 | +} |
5552 | + | |
4df546eb | 5553 | +int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset)) |
fa26e11c WD |
5554 | +{ |
5555 | + errno = ENOSYS; | |
5556 | + return -1; | |
5557 | +} | |
5558 | + | |
4df546eb | 5559 | +int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm)) |
fa26e11c WD |
5560 | +{ |
5561 | + errno = ENOSYS; | |
5562 | + return -1; | |
5563 | +} | |
5564 | + | |
0f6733d8 | 5565 | +int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) |
fa26e11c WD |
5566 | +{ |
5567 | + errno = ENOSYS; | |
0f6733d8 | 5568 | + return (permset & perm) ? 1 : 0; |
fa26e11c WD |
5569 | +} |
5570 | + | |
4df546eb | 5571 | +char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen)) |
fa26e11c WD |
5572 | +{ |
5573 | + errno = ENOSYS; | |
5574 | + return NULL; | |
5575 | +} | |
5576 | + | |
4df546eb | 5577 | +int sys_acl_free_text(UNUSED(char *text)) |
fa26e11c WD |
5578 | +{ |
5579 | + errno = ENOSYS; | |
5580 | + return -1; | |
5581 | +} | |
5582 | + | |
4df546eb | 5583 | +SMB_ACL_T sys_acl_init(UNUSED(int count)) |
fa26e11c WD |
5584 | +{ |
5585 | + errno = ENOSYS; | |
5586 | + return NULL; | |
5587 | +} | |
5588 | + | |
4df546eb | 5589 | +int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry)) |
fa26e11c WD |
5590 | +{ |
5591 | + errno = ENOSYS; | |
5592 | + return -1; | |
5593 | +} | |
5594 | + | |
4df546eb | 5595 | +int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
5596 | +{ |
5597 | + errno = ENOSYS; | |
5598 | + return -1; | |
5599 | +} | |
5600 | + | |
4df546eb | 5601 | +int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual)) |
fa26e11c WD |
5602 | +{ |
5603 | + errno = ENOSYS; | |
5604 | + return -1; | |
5605 | +} | |
5606 | + | |
4df546eb | 5607 | +int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset)) |
fa26e11c WD |
5608 | +{ |
5609 | + errno = ENOSYS; | |
5610 | + return -1; | |
5611 | +} | |
5612 | + | |
4df546eb | 5613 | +int sys_acl_valid(UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
5614 | +{ |
5615 | + errno = ENOSYS; | |
5616 | + return -1; | |
5617 | +} | |
5618 | + | |
4df546eb | 5619 | +int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
5620 | +{ |
5621 | + errno = ENOSYS; | |
5622 | + return -1; | |
5623 | +} | |
5624 | + | |
4df546eb | 5625 | +int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl)) |
fa26e11c WD |
5626 | +{ |
5627 | + errno = ENOSYS; | |
5628 | + return -1; | |
5629 | +} | |
5630 | + | |
4df546eb | 5631 | +int sys_acl_delete_def_file(UNUSED(const char *name)) |
fa26e11c WD |
5632 | +{ |
5633 | + errno = ENOSYS; | |
5634 | + return -1; | |
5635 | +} | |
5636 | + | |
4df546eb | 5637 | +int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl)) |
fa26e11c WD |
5638 | +{ |
5639 | + errno = ENOSYS; | |
5640 | + return -1; | |
5641 | +} | |
5642 | + | |
4df546eb | 5643 | +int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype)) |
fa26e11c WD |
5644 | +{ |
5645 | + errno = ENOSYS; | |
5646 | + return -1; | |
5647 | +} | |
5648 | + | |
5649 | +#endif /* No ACLs. */ | |
252945ef WD |
5650 | + |
5651 | +/************************************************************************ | |
5652 | + Deliberately outside the ACL defines. Return 1 if this is a "no acls" | |
5653 | + errno, 0 if not. | |
5654 | +************************************************************************/ | |
5655 | + | |
5656 | +int no_acl_syscall_error(int err) | |
5657 | +{ | |
5658 | +#if defined(ENOSYS) | |
5659 | + if (err == ENOSYS) { | |
5660 | + return 1; | |
5661 | + } | |
5662 | +#endif | |
5663 | +#if defined(ENOTSUP) | |
5664 | + if (err == ENOTSUP) { | |
5665 | + return 1; | |
5666 | + } | |
5667 | +#endif | |
5668 | + return 0; | |
5669 | +} | |
131abbd3 WD |
5670 | + |
5671 | +#endif /* SUPPORT_ACLS */ | |
9a7eef96 WD |
5672 | --- old/lib/sysacls.h |
5673 | +++ new/lib/sysacls.h | |
131abbd3 WD |
5674 | @@ -0,0 +1,40 @@ |
5675 | +#ifdef SUPPORT_ACLS | |
5676 | + | |
5677 | +#ifdef HAVE_SYS_ACL_H | |
a35da1c7 WD |
5678 | +#include <sys/acl.h> |
5679 | +#endif | |
0909ae28 WD |
5680 | +#ifdef HAVE_ACL_LIBACL_H |
5681 | +#include <acl/libacl.h> | |
5682 | +#endif | |
a35da1c7 WD |
5683 | +#include "smb_acls.h" |
5684 | + | |
252945ef WD |
5685 | +#define SMB_MALLOC(cnt) new_array(char, cnt) |
5686 | +#define SMB_MALLOC_P(obj) new_array(obj, 1) | |
5687 | +#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt) | |
5688 | +#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt) | |
5ca9317d | 5689 | +#define slprintf snprintf |
0f6733d8 WD |
5690 | + |
5691 | +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p); | |
5692 | +int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p); | |
5693 | +int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p); | |
5694 | +void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d); | |
5695 | +SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type); | |
5696 | +SMB_ACL_T sys_acl_get_fd(int fd); | |
5697 | +int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); | |
5698 | +int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
5699 | +int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); | |
5700 | +char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen); | |
5701 | +SMB_ACL_T sys_acl_init(int count); | |
5702 | +int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry); | |
5703 | +int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype); | |
5704 | +int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual); | |
5705 | +int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset); | |
5706 | +int sys_acl_valid(SMB_ACL_T theacl); | |
5707 | +int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); | |
5708 | +int sys_acl_set_fd(int fd, SMB_ACL_T theacl); | |
5709 | +int sys_acl_delete_def_file(const char *name); | |
5710 | +int sys_acl_free_text(char *text); | |
5711 | +int sys_acl_free_acl(SMB_ACL_T the_acl); | |
5712 | +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype); | |
131abbd3 WD |
5713 | + |
5714 | +#endif /* SUPPORT_ACLS */ | |
0870c22a WD |
5715 | --- old/log.c |
5716 | +++ new/log.c | |
1aa236e1 | 5717 | @@ -625,8 +625,10 @@ static void log_formatted(enum logcode c |
fb11cdd7 WD |
5718 | c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p'; |
5719 | c[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o'; | |
5720 | c[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g'; | |
5721 | - c[8] = '.'; | |
5722 | - c[9] = '\0'; | |
5723 | + c[8] = !(iflags & ITEM_REPORT_ATIME) ? '.' : 'u'; | |
5724 | + c[9] = !(iflags & ITEM_REPORT_ACL) ? '.' : 'a'; | |
5725 | + c[10] = !(iflags & ITEM_REPORT_XATTR) ? '.' : 'x'; | |
5726 | + c[11] = '\0'; | |
0870c22a WD |
5727 | |
5728 | if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) { | |
5729 | char ch = iflags & ITEM_IS_NEW ? '+' : '?'; | |
9a7eef96 WD |
5730 | --- old/options.c |
5731 | +++ new/options.c | |
c1471566 | 5732 | @@ -47,6 +47,7 @@ int copy_dirlinks = 0; |
0f6733d8 WD |
5733 | int copy_links = 0; |
5734 | int preserve_links = 0; | |
5735 | int preserve_hard_links = 0; | |
5736 | +int preserve_acls = 0; | |
5737 | int preserve_perms = 0; | |
90fa6d68 | 5738 | int preserve_executability = 0; |
0f6733d8 | 5739 | int preserve_devices = 0; |
a7592111 | 5740 | @@ -199,6 +200,7 @@ static void print_rsync_version(enum log |
0f6733d8 WD |
5741 | char const *got_socketpair = "no "; |
5742 | char const *have_inplace = "no "; | |
5743 | char const *hardlinks = "no "; | |
5744 | + char const *acls = "no "; | |
5745 | char const *links = "no "; | |
5746 | char const *ipv6 = "no "; | |
5747 | STRUCT_STAT *dumstat; | |
a7592111 | 5748 | @@ -215,6 +217,10 @@ static void print_rsync_version(enum log |
0f6733d8 WD |
5749 | hardlinks = ""; |
5750 | #endif | |
5751 | ||
09fb8f03 | 5752 | +#ifdef SUPPORT_ACLS |
0f6733d8 WD |
5753 | + acls = ""; |
5754 | +#endif | |
5755 | + | |
09fb8f03 | 5756 | #ifdef SUPPORT_LINKS |
0f6733d8 WD |
5757 | links = ""; |
5758 | #endif | |
a7592111 | 5759 | @@ -233,8 +239,8 @@ static void print_rsync_version(enum log |
5e3c6c93 WD |
5760 | (int)(sizeof (int64) * 8)); |
5761 | rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n", | |
5762 | got_socketpair, hardlinks, links, ipv6, have_inplace); | |
5763 | - rprintf(f, " %sappend\n", | |
5764 | - have_inplace); | |
5765 | + rprintf(f, " %sappend, %sACLs\n", | |
5766 | + have_inplace, acls); | |
0f6733d8 | 5767 | |
131abbd3 | 5768 | #ifdef MAINTAINER_MODE |
5e3c6c93 | 5769 | rprintf(f, "Panic Action: \"%s\"\n", get_panic_action()); |
a7592111 | 5770 | @@ -280,7 +286,7 @@ void usage(enum logcode F) |
5a9d3244 | 5771 | rprintf(F," -q, --quiet suppress non-error messages\n"); |
4959107f | 5772 | rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n"); |
5a9d3244 WD |
5773 | rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n"); |
5774 | - rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H)\n"); | |
5775 | + rprintf(F," -a, --archive archive mode; same as -rlptgoD (no -H, -A)\n"); | |
5776 | rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n"); | |
5777 | rprintf(F," -r, --recursive recurse into directories\n"); | |
5778 | rprintf(F," -R, --relative use relative path names\n"); | |
a7592111 | 5779 | @@ -302,6 +308,9 @@ void usage(enum logcode F) |
0f6733d8 | 5780 | rprintf(F," -p, --perms preserve permissions\n"); |
90fa6d68 | 5781 | rprintf(F," -E, --executability preserve the file's executability\n"); |
063cf77b | 5782 | rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n"); |
25d385b9 | 5783 | +#ifdef SUPPORT_ACLS |
0f6733d8 | 5784 | + rprintf(F," -A, --acls preserve ACLs (implies --perms)\n"); |
25d385b9 | 5785 | +#endif |
90fa6d68 | 5786 | rprintf(F," -o, --owner preserve owner (super-user only)\n"); |
0f6733d8 | 5787 | rprintf(F," -g, --group preserve group\n"); |
1ed0b5c9 | 5788 | rprintf(F," --devices preserve device files (super-user only)\n"); |
a7592111 | 5789 | @@ -422,6 +431,9 @@ static struct poptOption long_options[] |
489b0a72 WD |
5790 | {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, |
5791 | {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 }, | |
90fa6d68 | 5792 | {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 }, |
489b0a72 WD |
5793 | + {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 }, |
5794 | + {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
5795 | + {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 }, | |
5796 | {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 }, | |
5797 | {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
5798 | {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 }, | |
a7592111 | 5799 | @@ -1093,6 +1105,24 @@ int parse_arguments(int *argc, const cha |
3b05e91f WD |
5800 | usage(FINFO); |
5801 | exit_cleanup(0); | |
0f6733d8 WD |
5802 | |
5803 | + case 'A': | |
4df546eb | 5804 | +#ifdef SUPPORT_ACLS |
70891d26 | 5805 | + preserve_acls = 1; |
a5e3a4cc | 5806 | + preserve_perms = 1; |
489b0a72 | 5807 | + break; |
0f6733d8 WD |
5808 | +#else |
5809 | + /* FIXME: this should probably be ignored with a | |
5810 | + * warning and then countermeasures taken to | |
5811 | + * restrict group and other access in the presence | |
5812 | + * of any more restrictive ACLs, but this is safe | |
5813 | + * for now */ | |
5814 | + snprintf(err_buf,sizeof(err_buf), | |
5815 | + "ACLs are not supported on this %s\n", | |
5816 | + am_server ? "server" : "client"); | |
5817 | + return 0; | |
25d385b9 | 5818 | +#endif |
0f6733d8 WD |
5819 | + |
5820 | + | |
5821 | default: | |
5822 | /* A large opt value means that set_refuse_options() | |
27a7053c | 5823 | * turned this option off. */ |
a7592111 WD |
5824 | @@ -1556,6 +1586,10 @@ void server_options(char **args,int *arg |
5825 | argstr[x++] = 'p'; | |
5826 | else if (preserve_executability && am_sender) | |
5827 | argstr[x++] = 'E'; | |
25d385b9 | 5828 | +#ifdef SUPPORT_ACLS |
0f6733d8 WD |
5829 | + if (preserve_acls) |
5830 | + argstr[x++] = 'A'; | |
25d385b9 | 5831 | +#endif |
a7592111 WD |
5832 | if (recurse) |
5833 | argstr[x++] = 'r'; | |
5834 | if (always_checksum) | |
9a7eef96 WD |
5835 | --- old/receiver.c |
5836 | +++ new/receiver.c | |
a7592111 | 5837 | @@ -48,6 +48,7 @@ extern int keep_partial; |
1a2fa68f WD |
5838 | extern int checksum_seed; |
5839 | extern int inplace; | |
5840 | extern int delay_updates; | |
5841 | +extern mode_t orig_umask; | |
5842 | extern struct stats stats; | |
a859733e | 5843 | extern char *stdout_format; |
1a2fa68f | 5844 | extern char *tmpdir; |
a7592111 | 5845 | @@ -349,6 +350,10 @@ int recv_files(int f_in, char *local_nam |
a859733e WD |
5846 | int itemizing = am_server ? logfile_format_has_i : stdout_format_has_i; |
5847 | enum logcode log_code = log_before_transfer ? FLOG : FINFO; | |
26c810d8 WD |
5848 | int max_phase = protocol_version >= 29 ? 2 : 1; |
5849 | + int dflt_perms = (ACCESSPERMS & ~orig_umask); | |
5c8b4e6e | 5850 | +#ifdef SUPPORT_ACLS |
d997cb77 | 5851 | + const char *parent_dirname = ""; |
5c8b4e6e | 5852 | +#endif |
81ecd8e0 | 5853 | int ndx, recv_ok; |
26c810d8 WD |
5854 | |
5855 | if (verbose > 2) | |
a7592111 | 5856 | @@ -562,7 +567,16 @@ int recv_files(int f_in, char *local_nam |
90fa6d68 WD |
5857 | * mode based on the local permissions and some heuristics. */ |
5858 | if (!preserve_perms) { | |
5859 | int exists = fd1 != -1; | |
5860 | - file->mode = dest_mode(file->mode, st.st_mode, exists); | |
26c810d8 | 5861 | +#ifdef SUPPORT_ACLS |
d997cb77 | 5862 | + const char *dn = file->dirname ? file->dirname : "."; |
5c8b4e6e WD |
5863 | + if (parent_dirname != dn |
5864 | + && strcmp(parent_dirname, dn) != 0) { | |
5865 | + dflt_perms = default_perms_for_dir(dn); | |
5866 | + parent_dirname = dn; | |
26c810d8 WD |
5867 | + } |
5868 | +#endif | |
5869 | + file->mode = dest_mode(file->mode, st.st_mode, | |
5870 | + dflt_perms, exists); | |
90fa6d68 WD |
5871 | } |
5872 | ||
bdf1eee8 | 5873 | /* We now check to see if we are writing the file "inplace" */ |
9a7eef96 WD |
5874 | --- old/rsync.c |
5875 | +++ new/rsync.c | |
74eccbb1 WD |
5876 | @@ -32,6 +32,7 @@ |
5877 | ||
162234a7 WD |
5878 | extern int verbose; |
5879 | extern int dry_run; | |
162234a7 WD |
5880 | +extern int preserve_acls; |
5881 | extern int preserve_perms; | |
5882 | extern int preserve_executability; | |
5883 | extern int preserve_times; | |
a7592111 WD |
5884 | @@ -50,7 +51,6 @@ extern int inplace; |
5885 | extern int flist_eof; | |
78b1089b WD |
5886 | extern int keep_dirlinks; |
5887 | extern int make_backups; | |
5888 | -extern mode_t orig_umask; | |
5889 | extern struct stats stats; | |
a7592111 | 5890 | extern struct file_list *cur_flist, *first_flist, *dir_flist; |
78b1089b | 5891 | extern struct chmod_mode_struct *daemon_chmod_modes; |
a7592111 | 5892 | @@ -203,7 +203,8 @@ void free_sums(struct sum_struct *s) |
90fa6d68 WD |
5893 | |
5894 | /* This is only called when we aren't preserving permissions. Figure out what | |
5895 | * the permissions should be and return them merged back into the mode. */ | |
bdf1eee8 WD |
5896 | -mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int exists) |
5897 | +mode_t dest_mode(mode_t flist_mode, mode_t stat_mode, int dflt_perms, | |
26c810d8 | 5898 | + int exists) |
90fa6d68 | 5899 | { |
bdf1eee8 | 5900 | int new_mode; |
25d385b9 | 5901 | /* If the file already exists, we'll return the local permissions, |
a7592111 | 5902 | @@ -220,56 +221,65 @@ mode_t dest_mode(mode_t flist_mode, mode |
bdf1eee8 | 5903 | new_mode |= (new_mode & 0444) >> 2; |
90fa6d68 | 5904 | } |
bdf1eee8 WD |
5905 | } else { |
5906 | - /* Apply the umask and turn off special permissions. */ | |
5907 | - new_mode = flist_mode & (~CHMOD_BITS | (ACCESSPERMS & ~orig_umask)); | |
5908 | + /* Apply destination default permissions and turn | |
5909 | + * off special permissions. */ | |
5910 | + new_mode = flist_mode & (~CHMOD_BITS | dflt_perms); | |
5911 | } | |
bdf1eee8 | 5912 | return new_mode; |
0870c22a WD |
5913 | } |
5914 | ||
5915 | -int set_file_attrs(char *fname, struct file_struct *file, STRUCT_STAT *st, | |
5916 | +int set_file_attrs(char *fname, struct file_struct *file, statx *sxp, | |
5917 | int flags) | |
5918 | { | |
5919 | int updated = 0; | |
5920 | - STRUCT_STAT st2; | |
5921 | + statx sx2; | |
5922 | int change_uid, change_gid; | |
1ed0b5c9 | 5923 | mode_t new_mode = file->mode; |
0870c22a WD |
5924 | |
5925 | - if (!st) { | |
5926 | + if (!sxp) { | |
5927 | if (dry_run) | |
5928 | return 1; | |
5929 | - if (link_stat(fname, &st2, 0) < 0) { | |
5930 | + if (link_stat(fname, &sx2.st, 0) < 0) { | |
5931 | rsyserr(FERROR, errno, "stat %s failed", | |
5932 | full_fname(fname)); | |
5933 | return 0; | |
5934 | } | |
5935 | - st = &st2; | |
5936 | +#ifdef SUPPORT_ACLS | |
5937 | + sx2.acc_acl = sx2.def_acl = NULL; | |
5938 | +#endif | |
1ed0b5c9 | 5939 | if (!preserve_perms && S_ISDIR(new_mode) |
0870c22a WD |
5940 | - && st->st_mode & S_ISGID) { |
5941 | + && sx2.st.st_mode & S_ISGID) { | |
5942 | /* We just created this directory and its setgid | |
5943 | * bit is on, so make sure it stays on. */ | |
1ed0b5c9 | 5944 | new_mode |= S_ISGID; |
0870c22a WD |
5945 | } |
5946 | + sxp = &sx2; | |
5947 | } | |
5948 | ||
5949 | - if (!preserve_times || (S_ISDIR(st->st_mode) && omit_dir_times)) | |
5950 | +#ifdef SUPPORT_ACLS | |
5951 | + if (preserve_acls && !ACL_READY(*sxp)) | |
98ccc74a | 5952 | + get_acl(fname, sxp); |
0870c22a WD |
5953 | +#endif |
5954 | + | |
5955 | + if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && omit_dir_times)) | |
5956 | flags |= ATTRS_SKIP_MTIME; | |
5957 | if (!(flags & ATTRS_SKIP_MTIME) | |
5958 | - && cmp_time(st->st_mtime, file->modtime) != 0) { | |
5959 | - int ret = set_modtime(fname, file->modtime, st->st_mode); | |
5960 | + && cmp_time(sxp->st.st_mtime, file->modtime) != 0) { | |
5961 | + int ret = set_modtime(fname, file->modtime, sxp->st.st_mode); | |
5962 | if (ret < 0) { | |
5963 | rsyserr(FERROR, errno, "failed to set times on %s", | |
5964 | full_fname(fname)); | |
5965 | - return 0; | |
5966 | + goto cleanup; | |
5967 | } | |
5968 | if (ret == 0) /* ret == 1 if symlink could not be set */ | |
5969 | updated = 1; | |
5970 | } | |
5971 | ||
70891d26 WD |
5972 | - change_uid = am_root && preserve_uid && st->st_uid != F_UID(file); |
5973 | + change_uid = am_root && preserve_uid && sxp->st.st_uid != F_UID(file); | |
5974 | change_gid = preserve_gid && F_GID(file) != GID_NONE | |
5975 | - && st->st_gid != F_GID(file); | |
5976 | + && sxp->st.st_gid != F_GID(file); | |
0870c22a WD |
5977 | #if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK |
5978 | - if (S_ISLNK(st->st_mode)) | |
5979 | + if (S_ISLNK(sxp->st.st_mode)) | |
5980 | ; | |
5981 | else | |
5982 | #endif | |
a7592111 | 5983 | @@ -279,45 +289,57 @@ int set_file_attrs(char *fname, struct f |
0870c22a WD |
5984 | rprintf(FINFO, |
5985 | "set uid of %s from %ld to %ld\n", | |
5986 | fname, | |
70891d26 WD |
5987 | - (long)st->st_uid, (long)F_UID(file)); |
5988 | + (long)sxp->st.st_uid, (long)F_UID(file)); | |
0870c22a WD |
5989 | } |
5990 | if (change_gid) { | |
5991 | rprintf(FINFO, | |
5992 | "set gid of %s from %ld to %ld\n", | |
5993 | fname, | |
70891d26 WD |
5994 | - (long)st->st_gid, (long)F_GID(file)); |
5995 | + (long)sxp->st.st_gid, (long)F_GID(file)); | |
0870c22a WD |
5996 | } |
5997 | } | |
5998 | if (do_lchown(fname, | |
70891d26 WD |
5999 | - change_uid ? F_UID(file) : st->st_uid, |
6000 | - change_gid ? F_GID(file) : st->st_gid) != 0) { | |
6001 | + change_uid ? F_UID(file) : sxp->st.st_uid, | |
6002 | + change_gid ? F_GID(file) : sxp->st.st_gid) != 0) { | |
0870c22a WD |
6003 | /* shouldn't have attempted to change uid or gid |
6004 | * unless have the privilege */ | |
6005 | rsyserr(FERROR, errno, "%s %s failed", | |
6006 | change_uid ? "chown" : "chgrp", | |
6007 | full_fname(fname)); | |
6008 | - return 0; | |
6009 | + goto cleanup; | |
6010 | } | |
6011 | /* a lchown had been done - we have to re-stat if the | |
6012 | * destination had the setuid or setgid bits set due | |
6013 | * to the side effect of the chown call */ | |
6014 | - if (st->st_mode & (S_ISUID | S_ISGID)) { | |
6015 | - link_stat(fname, st, | |
6016 | - keep_dirlinks && S_ISDIR(st->st_mode)); | |
6017 | + if (sxp->st.st_mode & (S_ISUID | S_ISGID)) { | |
6018 | + link_stat(fname, &sxp->st, | |
6019 | + keep_dirlinks && S_ISDIR(sxp->st.st_mode)); | |
6020 | } | |
c6437996 WD |
6021 | updated = 1; |
6022 | } | |
34a409bc | 6023 | |
1ed0b5c9 WD |
6024 | if (daemon_chmod_modes && !S_ISLNK(new_mode)) |
6025 | new_mode = tweak_mode(new_mode, daemon_chmod_modes); | |
6026 | + | |
c6437996 | 6027 | +#ifdef SUPPORT_ACLS |
98ccc74a | 6028 | + /* It's OK to call set_acl() now, even for a dir, as the generator |
c6437996 WD |
6029 | + * will enable owner-writability using chmod, if necessary. |
6030 | + * | |
98ccc74a | 6031 | + * If set_acl() changes permission bits in the process of setting |
0870c22a | 6032 | + * an access ACL, it changes sxp->st.st_mode so we know whether we |
98ccc74a WD |
6033 | + * need to chmod(). */ |
6034 | + if (preserve_acls && set_acl(fname, file, sxp) == 0) | |
c6437996 WD |
6035 | + updated = 1; |
6036 | +#endif | |
6037 | + | |
34a409bc | 6038 | #ifdef HAVE_CHMOD |
3d3ad7f1 WD |
6039 | - if (!BITS_EQUAL(st->st_mode, new_mode, CHMOD_BITS)) { |
6040 | + if (!BITS_EQUAL(sxp->st.st_mode, new_mode, CHMOD_BITS)) { | |
1ed0b5c9 | 6041 | int ret = do_chmod(fname, new_mode); |
0870c22a WD |
6042 | if (ret < 0) { |
6043 | rsyserr(FERROR, errno, | |
6044 | "failed to set permissions on %s", | |
6045 | full_fname(fname)); | |
6046 | - return 0; | |
6047 | + goto cleanup; | |
6048 | } | |
6049 | if (ret == 0) /* ret == 1 if symlink could not be set */ | |
6050 | updated = 1; | |
a7592111 | 6051 | @@ -330,6 +352,11 @@ int set_file_attrs(char *fname, struct f |
0870c22a | 6052 | else |
74eccbb1 | 6053 | rprintf(FCLIENT, "%s is uptodate\n", fname); |
0870c22a WD |
6054 | } |
6055 | + cleanup: | |
6056 | +#ifdef SUPPORT_ACLS | |
6057 | + if (preserve_acls && sxp == &sx2) | |
98ccc74a | 6058 | + free_acl(&sx2); |
0870c22a WD |
6059 | +#endif |
6060 | return updated; | |
6061 | } | |
6062 | ||
9a7eef96 WD |
6063 | --- old/rsync.h |
6064 | +++ new/rsync.h | |
a7592111 | 6065 | @@ -546,6 +546,14 @@ struct idev_node { |
0870c22a WD |
6066 | #define IN_LOOPBACKNET 127 |
6067 | #endif | |
0f6733d8 | 6068 | |
131abbd3 | 6069 | +#ifndef HAVE_NO_ACLS |
4df546eb WD |
6070 | +#define SUPPORT_ACLS 1 |
6071 | +#endif | |
0f6733d8 | 6072 | + |
4df546eb WD |
6073 | +#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS |
6074 | +#define ACLS_NEED_MASK 1 | |
6075 | +#endif | |
0f6733d8 | 6076 | + |
0870c22a WD |
6077 | #define GID_NONE ((gid_t)-1) |
6078 | ||
590329e5 | 6079 | union file_extras { |
a7592111 | 6080 | @@ -565,6 +573,7 @@ struct file_struct { |
7e27b6c0 | 6081 | extern int file_extra_cnt; |
3b3650bb WD |
6082 | extern int preserve_uid; |
6083 | extern int preserve_gid; | |
6084 | +extern int preserve_acls; | |
6085 | ||
6086 | #define FILE_STRUCT_LEN (offsetof(struct file_struct, basename)) | |
6087 | #define EXTRA_LEN (sizeof (union file_extras)) | |
a7592111 | 6088 | @@ -597,10 +606,12 @@ extern int preserve_gid; |
1aa236e1 | 6089 | /* When the associated option is on, all entries will have these present: */ |
a7592111 WD |
6090 | #define F_OWNER(f) REQ_EXTRA(f, preserve_uid)->unum |
6091 | #define F_GROUP(f) REQ_EXTRA(f, preserve_gid)->unum | |
1aa236e1 | 6092 | +#define F_ACL(f) REQ_EXTRA(f, preserve_acls)->unum |
70891d26 | 6093 | |
81ecd8e0 | 6094 | /* These items are per-entry optional and mutally exclusive: */ |
7c15d5aa | 6095 | #define F_HL_GNUM(f) OPT_EXTRA(f, LEN64_BUMP(f))->num |
7b80cd0e | 6096 | #define F_HL_PREV(f) OPT_EXTRA(f, LEN64_BUMP(f))->num |
81ecd8e0 | 6097 | +#define F_DEF_ACL(f) OPT_EXTRA(f, LEN64_BUMP(f))->unum |
a7592111 WD |
6098 | #define F_DIRDEV_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + 2 - 1)->unum) |
6099 | #define F_DIRNODE_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + 3 - 1)->num) | |
70891d26 | 6100 | |
a7592111 | 6101 | @@ -752,6 +763,17 @@ struct stats { |
6250eb3e WD |
6102 | |
6103 | struct chmod_mode_struct; | |
6104 | ||
6105 | +#define EMPTY_ITEM_LIST {NULL, 0, 0} | |
6106 | + | |
6107 | +typedef struct { | |
6108 | + void *items; | |
6109 | + size_t count; | |
6110 | + size_t malloced; | |
6111 | +} item_list; | |
6112 | + | |
645e162c WD |
6113 | +#define EXPAND_ITEM_LIST(lp, type, incr) \ |
6114 | + (type*)expand_item_list(lp, sizeof (type), #type, incr) | |
6250eb3e WD |
6115 | + |
6116 | #include "byteorder.h" | |
6117 | #include "lib/mdfour.h" | |
6118 | #include "lib/wildmatch.h" | |
a7592111 | 6119 | @@ -770,6 +792,16 @@ struct chmod_mode_struct; |
3758a5a5 | 6120 | #define NORETURN __attribute__((__noreturn__)) |
d997cb77 | 6121 | #endif |
0870c22a | 6122 | |
0870c22a WD |
6123 | +typedef struct { |
6124 | + STRUCT_STAT st; | |
6125 | +#ifdef SUPPORT_ACLS | |
6126 | + struct rsync_acl *acc_acl; /* access ACL */ | |
6127 | + struct rsync_acl *def_acl; /* default ACL */ | |
6128 | +#endif | |
6129 | +} statx; | |
6130 | + | |
6131 | +#define ACL_READY(sx) ((sx).acc_acl != NULL) | |
0f6733d8 WD |
6132 | + |
6133 | #include "proto.h" | |
6134 | ||
6135 | /* We have replacement versions of these if they're missing. */ | |
9a7eef96 WD |
6136 | --- old/rsync.yo |
6137 | +++ new/rsync.yo | |
4959107f | 6138 | @@ -301,7 +301,7 @@ to the detailed description below for a |
5a9d3244 | 6139 | -q, --quiet suppress non-error messages |
4959107f | 6140 | --no-motd suppress daemon-mode MOTD (see caveat) |
5a9d3244 WD |
6141 | -c, --checksum skip based on checksum, not mod-time & size |
6142 | - -a, --archive archive mode; same as -rlptgoD (no -H) | |
6143 | + -a, --archive archive mode; same as -rlptgoD (no -H, -A) | |
6144 | --no-OPTION turn off an implied OPTION (e.g. --no-D) | |
6145 | -r, --recursive recurse into directories | |
6146 | -R, --relative use relative path names | |
4959107f | 6147 | @@ -323,6 +323,7 @@ to the detailed description below for a |
0f6733d8 | 6148 | -p, --perms preserve permissions |
90fa6d68 | 6149 | -E, --executability preserve executability |
063cf77b | 6150 | --chmod=CHMOD affect file and/or directory permissions |
90fa6d68 | 6151 | + -A, --acls preserve ACLs (implies -p) [non-standard] |
90fa6d68 | 6152 | -o, --owner preserve owner (super-user only) |
0f6733d8 | 6153 | -g, --group preserve group |
1ed0b5c9 | 6154 | --devices preserve device files (super-user only) |
d997cb77 | 6155 | @@ -754,7 +755,9 @@ quote(itemization( |
90fa6d68 WD |
6156 | permissions, though the bf(--executability) option might change just |
6157 | the execute permission for the file. | |
03baf100 WD |
6158 | it() New files get their "normal" permission bits set to the source |
6159 | - file's permissions masked with the receiving end's umask setting, and | |
6160 | + file's permissions masked with the receiving directory's default | |
6161 | + permissions (either the receiving process's umask, or the permissions | |
6162 | + specified via the destination directory's default ACL), and | |
6163 | their special permission bits disabled except in the case where a new | |
6164 | directory inherits a setgid bit from its parent directory. | |
90fa6d68 | 6165 | )) |
d997cb77 | 6166 | @@ -785,9 +788,11 @@ The preservation of the destination's se |
03baf100 WD |
6167 | directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync |
6168 | versions erroneously preserved the three special permission bits for | |
6169 | newly-created files when bf(--perms) was off, while overriding the | |
6170 | -destination's setgid bit setting on a newly-created directory. (Keep in | |
6171 | -mind that it is the version of the receiving rsync that affects this | |
6172 | -behavior.) | |
6173 | +destination's setgid bit setting on a newly-created directory. Default ACL | |
6174 | +observance was added to the ACL patch for rsync 2.6.7, so older (or | |
6175 | +non-ACL-enabled) rsyncs use the umask even if default ACLs are present. | |
6176 | +(Keep in mind that it is the version of the receiving rsync that affects | |
6177 | +these behaviors.) | |
90fa6d68 | 6178 | |
90fa6d68 WD |
6179 | dit(bf(-E, --executability)) This option causes rsync to preserve the |
6180 | executability (or non-executability) of regular files when bf(--perms) is | |
b80daf10 | 6181 | @@ -805,6 +810,14 @@ quote(itemization( |
90fa6d68 WD |
6182 | |
6183 | If bf(--perms) is enabled, this option is ignored. | |
6184 | ||
6185 | +dit(bf(-A, --acls)) This option causes rsync to update the destination | |
6186 | +ACLs to be the same as the source ACLs. This nonstandard option only | |
6187 | +works if the remote rsync also supports it. bf(--acls) implies bf(--perms). | |
b57f8e02 | 6188 | + |
b80daf10 | 6189 | +The ACL-sending protocol used by this version was first introduced in |
590329e5 | 6190 | +the patch that was shipped with 2.6.8. Sending ACLs to an older version |
b80daf10 | 6191 | +of the ACL patch is not supported. |
90fa6d68 WD |
6192 | + |
6193 | dit(bf(--chmod)) This option tells rsync to apply one or more | |
6194 | comma-separated "chmod" strings to the permission of the files in the | |
6195 | transfer. The resulting value is treated as though it was the permissions | |
b80daf10 | 6196 | @@ -1402,8 +1415,8 @@ if the receiving rsync is at least versi |
0870c22a WD |
6197 | with older versions of rsync, but that also turns on the output of other |
6198 | verbose messages). | |
6199 | ||
6200 | -The "%i" escape has a cryptic output that is 9 letters long. The general | |
6201 | -format is like the string bf(YXcstpogz), where bf(Y) is replaced by the | |
6202 | +The "%i" escape has a cryptic output that is 11 letters long. The general | |
6203 | +format is like the string bf(YXcstpoguax), where bf(Y) is replaced by the | |
6204 | type of update being done, bf(X) is replaced by the file-type, and the | |
6205 | other letters represent attributes that may be output if they are being | |
6206 | modified. | |
b80daf10 | 6207 | @@ -1452,7 +1465,11 @@ quote(itemization( |
0870c22a WD |
6208 | sender's value (requires bf(--owner) and super-user privileges). |
6209 | it() A bf(g) means the group is different and is being updated to the | |
6210 | sender's value (requires bf(--group) and the authority to set the group). | |
6211 | - it() The bf(z) slot is reserved for future use. | |
6212 | + it() The bf(u) slot is reserved for reporting update (access) time changes | |
6213 | + (a feature that is not yet released). | |
6214 | + it() The bf(a) means that the ACL information changed. | |
6215 | + it() The bf(x) slot is reserved for reporting extended attribute changes | |
6216 | + (a feature that is not yet released). | |
6217 | )) | |
6218 | ||
6219 | One other output is possible: when deleting files, the "%i" will output | |
9a7eef96 WD |
6220 | --- old/smb_acls.h |
6221 | +++ new/smb_acls.h | |
0870c22a WD |
6222 | @@ -0,0 +1,281 @@ |
6223 | +/* | |
6224 | + Unix SMB/Netbios implementation. | |
6225 | + Version 2.2.x | |
6226 | + Portable SMB ACL interface | |
6227 | + Copyright (C) Jeremy Allison 2000 | |
6228 | + | |
6229 | + This program is free software; you can redistribute it and/or modify | |
6230 | + it under the terms of the GNU General Public License as published by | |
6231 | + the Free Software Foundation; either version 2 of the License, or | |
6232 | + (at your option) any later version. | |
6233 | + | |
6234 | + This program is distributed in the hope that it will be useful, | |
6235 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6236 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6237 | + GNU General Public License for more details. | |
6238 | + | |
6239 | + You should have received a copy of the GNU General Public License | |
6240 | + along with this program; if not, write to the Free Software | |
6241 | + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
6242 | +*/ | |
0f6733d8 WD |
6243 | + |
6244 | +#ifndef _SMB_ACLS_H | |
6245 | +#define _SMB_ACLS_H | |
6246 | + | |
e6a7303b | 6247 | +#if defined HAVE_POSIX_ACLS |
0f6733d8 WD |
6248 | + |
6249 | +/* This is an identity mapping (just remove the SMB_). */ | |
6250 | + | |
6251 | +#define SMB_ACL_TAG_T acl_tag_t | |
6252 | +#define SMB_ACL_TYPE_T acl_type_t | |
6253 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
6254 | +#define SMB_ACL_PERM_T acl_perm_t | |
6255 | +#define SMB_ACL_READ ACL_READ | |
6256 | +#define SMB_ACL_WRITE ACL_WRITE | |
6257 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
6258 | + | |
6259 | +/* Types of ACLs. */ | |
6260 | +#define SMB_ACL_USER ACL_USER | |
6261 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
6262 | +#define SMB_ACL_GROUP ACL_GROUP | |
6263 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
6264 | +#define SMB_ACL_OTHER ACL_OTHER | |
6265 | +#define SMB_ACL_MASK ACL_MASK | |
6266 | + | |
6267 | +#define SMB_ACL_T acl_t | |
6268 | + | |
6269 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
6270 | + | |
6271 | +#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY | |
6272 | +#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY | |
6273 | + | |
6274 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
6275 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
6276 | + | |
e6a7303b | 6277 | +#elif defined HAVE_TRU64_ACLS |
0f6733d8 WD |
6278 | + |
6279 | +/* This is for DEC/Compaq Tru64 UNIX */ | |
6280 | + | |
6281 | +#define SMB_ACL_TAG_T acl_tag_t | |
6282 | +#define SMB_ACL_TYPE_T acl_type_t | |
6283 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
6284 | +#define SMB_ACL_PERM_T acl_perm_t | |
6285 | +#define SMB_ACL_READ ACL_READ | |
6286 | +#define SMB_ACL_WRITE ACL_WRITE | |
6287 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
6288 | + | |
6289 | +/* Types of ACLs. */ | |
6290 | +#define SMB_ACL_USER ACL_USER | |
6291 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
6292 | +#define SMB_ACL_GROUP ACL_GROUP | |
6293 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
6294 | +#define SMB_ACL_OTHER ACL_OTHER | |
6295 | +#define SMB_ACL_MASK ACL_MASK | |
6296 | + | |
6297 | +#define SMB_ACL_T acl_t | |
6298 | + | |
6299 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
6300 | + | |
6301 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6302 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6303 | + | |
6304 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
6305 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
6306 | + | |
e6a7303b | 6307 | +#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS |
0f6733d8 WD |
6308 | +/* |
6309 | + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. | |
6310 | + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. | |
6311 | + */ | |
6312 | + | |
6313 | +/* SVR4.2 ES/MP ACLs */ | |
6314 | +typedef int SMB_ACL_TAG_T; | |
6315 | +typedef int SMB_ACL_TYPE_T; | |
6316 | +typedef ushort *SMB_ACL_PERMSET_T; | |
6317 | +typedef ushort SMB_ACL_PERM_T; | |
6318 | +#define SMB_ACL_READ 4 | |
6319 | +#define SMB_ACL_WRITE 2 | |
6320 | +#define SMB_ACL_EXECUTE 1 | |
6321 | + | |
6322 | +/* Types of ACLs. */ | |
6323 | +#define SMB_ACL_USER USER | |
6324 | +#define SMB_ACL_USER_OBJ USER_OBJ | |
6325 | +#define SMB_ACL_GROUP GROUP | |
6326 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
6327 | +#define SMB_ACL_OTHER OTHER_OBJ | |
6328 | +#define SMB_ACL_MASK CLASS_OBJ | |
6329 | + | |
6330 | +typedef struct SMB_ACL_T { | |
6331 | + int size; | |
6332 | + int count; | |
6333 | + int next; | |
6334 | + struct acl acl[1]; | |
6335 | +} *SMB_ACL_T; | |
6336 | + | |
6337 | +typedef struct acl *SMB_ACL_ENTRY_T; | |
6338 | + | |
6339 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6340 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6341 | + | |
6342 | +#define SMB_ACL_TYPE_ACCESS 0 | |
6343 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
6344 | + | |
53c1073a WD |
6345 | +#ifdef __CYGWIN__ |
6346 | +#define SMB_ACL_LOSES_SPECIAL_MODE_BITS | |
6347 | +#endif | |
6348 | + | |
e6a7303b | 6349 | +#elif defined HAVE_HPUX_ACLS |
0f6733d8 WD |
6350 | + |
6351 | +/* | |
6352 | + * Based on the Solaris & UnixWare code. | |
6353 | + */ | |
6354 | + | |
6355 | +#undef GROUP | |
6356 | +#include <sys/aclv.h> | |
6357 | + | |
6358 | +/* SVR4.2 ES/MP ACLs */ | |
6359 | +typedef int SMB_ACL_TAG_T; | |
6360 | +typedef int SMB_ACL_TYPE_T; | |
6361 | +typedef ushort *SMB_ACL_PERMSET_T; | |
6362 | +typedef ushort SMB_ACL_PERM_T; | |
6363 | +#define SMB_ACL_READ 4 | |
6364 | +#define SMB_ACL_WRITE 2 | |
6365 | +#define SMB_ACL_EXECUTE 1 | |
6366 | + | |
6367 | +/* Types of ACLs. */ | |
6368 | +#define SMB_ACL_USER USER | |
6369 | +#define SMB_ACL_USER_OBJ USER_OBJ | |
6370 | +#define SMB_ACL_GROUP GROUP | |
6371 | +#define SMB_ACL_GROUP_OBJ GROUP_OBJ | |
6372 | +#define SMB_ACL_OTHER OTHER_OBJ | |
6373 | +#define SMB_ACL_MASK CLASS_OBJ | |
6374 | + | |
6375 | +typedef struct SMB_ACL_T { | |
6376 | + int size; | |
6377 | + int count; | |
6378 | + int next; | |
6379 | + struct acl acl[1]; | |
6380 | +} *SMB_ACL_T; | |
6381 | + | |
6382 | +typedef struct acl *SMB_ACL_ENTRY_T; | |
6383 | + | |
6384 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6385 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6386 | + | |
6387 | +#define SMB_ACL_TYPE_ACCESS 0 | |
6388 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
6389 | + | |
e6a7303b | 6390 | +#elif defined HAVE_IRIX_ACLS |
0f6733d8 WD |
6391 | + |
6392 | +#define SMB_ACL_TAG_T acl_tag_t | |
6393 | +#define SMB_ACL_TYPE_T acl_type_t | |
6394 | +#define SMB_ACL_PERMSET_T acl_permset_t | |
6395 | +#define SMB_ACL_PERM_T acl_perm_t | |
6396 | +#define SMB_ACL_READ ACL_READ | |
6397 | +#define SMB_ACL_WRITE ACL_WRITE | |
6398 | +#define SMB_ACL_EXECUTE ACL_EXECUTE | |
6399 | + | |
6400 | +/* Types of ACLs. */ | |
6401 | +#define SMB_ACL_USER ACL_USER | |
6402 | +#define SMB_ACL_USER_OBJ ACL_USER_OBJ | |
6403 | +#define SMB_ACL_GROUP ACL_GROUP | |
6404 | +#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ | |
6405 | +#define SMB_ACL_OTHER ACL_OTHER_OBJ | |
6406 | +#define SMB_ACL_MASK ACL_MASK | |
6407 | + | |
6408 | +typedef struct SMB_ACL_T { | |
6409 | + int next; | |
6410 | + BOOL freeaclp; | |
6411 | + struct acl *aclp; | |
6412 | +} *SMB_ACL_T; | |
6413 | + | |
6414 | +#define SMB_ACL_ENTRY_T acl_entry_t | |
6415 | + | |
6416 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6417 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6418 | + | |
6419 | +#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS | |
6420 | +#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT | |
6421 | + | |
e6a7303b | 6422 | +#elif defined HAVE_AIX_ACLS |
0f6733d8 WD |
6423 | + |
6424 | +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */ | |
6425 | + | |
6426 | +#include "/usr/include/acl.h" | |
6427 | + | |
6428 | +typedef uint *SMB_ACL_PERMSET_T; | |
6429 | + | |
6430 | +struct acl_entry_link{ | |
6431 | + struct acl_entry_link *prevp; | |
6432 | + struct new_acl_entry *entryp; | |
6433 | + struct acl_entry_link *nextp; | |
6434 | + int count; | |
6435 | +}; | |
6436 | + | |
6437 | +struct new_acl_entry{ | |
6438 | + unsigned short ace_len; | |
6439 | + unsigned short ace_type; | |
6440 | + unsigned int ace_access; | |
6441 | + struct ace_id ace_id[1]; | |
6442 | +}; | |
6443 | + | |
6444 | +#define SMB_ACL_ENTRY_T struct new_acl_entry* | |
6445 | +#define SMB_ACL_T struct acl_entry_link* | |
6446 | + | |
6447 | +#define SMB_ACL_TAG_T unsigned short | |
6448 | +#define SMB_ACL_TYPE_T int | |
6449 | +#define SMB_ACL_PERM_T uint | |
6450 | +#define SMB_ACL_READ S_IRUSR | |
6451 | +#define SMB_ACL_WRITE S_IWUSR | |
6452 | +#define SMB_ACL_EXECUTE S_IXUSR | |
6453 | + | |
6454 | +/* Types of ACLs. */ | |
6455 | +#define SMB_ACL_USER ACEID_USER | |
6456 | +#define SMB_ACL_USER_OBJ 3 | |
6457 | +#define SMB_ACL_GROUP ACEID_GROUP | |
6458 | +#define SMB_ACL_GROUP_OBJ 4 | |
6459 | +#define SMB_ACL_OTHER 5 | |
6460 | +#define SMB_ACL_MASK 6 | |
6461 | + | |
6462 | + | |
6463 | +#define SMB_ACL_FIRST_ENTRY 1 | |
6464 | +#define SMB_ACL_NEXT_ENTRY 2 | |
6465 | + | |
6466 | +#define SMB_ACL_TYPE_ACCESS 0 | |
6467 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
6468 | + | |
6469 | +#else /* No ACLs. */ | |
6470 | + | |
6471 | +/* No ACLS - fake it. */ | |
6472 | +#define SMB_ACL_TAG_T int | |
6473 | +#define SMB_ACL_TYPE_T int | |
6474 | +#define SMB_ACL_PERMSET_T mode_t | |
6475 | +#define SMB_ACL_PERM_T mode_t | |
6476 | +#define SMB_ACL_READ S_IRUSR | |
6477 | +#define SMB_ACL_WRITE S_IWUSR | |
6478 | +#define SMB_ACL_EXECUTE S_IXUSR | |
6479 | + | |
6480 | +/* Types of ACLs. */ | |
6481 | +#define SMB_ACL_USER 0 | |
6482 | +#define SMB_ACL_USER_OBJ 1 | |
6483 | +#define SMB_ACL_GROUP 2 | |
6484 | +#define SMB_ACL_GROUP_OBJ 3 | |
6485 | +#define SMB_ACL_OTHER 4 | |
6486 | +#define SMB_ACL_MASK 5 | |
6487 | + | |
6488 | +typedef struct SMB_ACL_T { | |
6489 | + int dummy; | |
6490 | +} *SMB_ACL_T; | |
6491 | + | |
6492 | +typedef struct SMB_ACL_ENTRY_T { | |
6493 | + int dummy; | |
6494 | +} *SMB_ACL_ENTRY_T; | |
6495 | + | |
6496 | +#define SMB_ACL_FIRST_ENTRY 0 | |
6497 | +#define SMB_ACL_NEXT_ENTRY 1 | |
6498 | + | |
6499 | +#define SMB_ACL_TYPE_ACCESS 0 | |
6500 | +#define SMB_ACL_TYPE_DEFAULT 1 | |
6501 | + | |
6502 | +#endif /* No ACLs. */ | |
6503 | +#endif /* _SMB_ACLS_H */ | |
475c4a36 WD |
6504 | --- old/testsuite/acls.test |
6505 | +++ new/testsuite/acls.test | |
6506 | @@ -0,0 +1,34 @@ | |
6507 | +#! /bin/sh | |
6508 | + | |
6509 | +# This program is distributable under the terms of the GNU GPL (see | |
6510 | +# COPYING). | |
6511 | + | |
6512 | +# Test that rsync handles basic ACL preservation. | |
6513 | + | |
6514 | +. $srcdir/testsuite/rsync.fns | |
6515 | + | |
6516 | +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support" | |
6517 | +case "$setfacl_nodef" in | |
6518 | +true) test_skipped "I don't know how to use your setfacl command" ;; | |
6519 | +esac | |
6520 | + | |
6521 | +makepath "$fromdir/foo" | |
6522 | +echo something >"$fromdir/file1" | |
6523 | +echo else >"$fromdir/file2" | |
6524 | + | |
6525 | +files='foo file1 file2' | |
6526 | + | |
6527 | +setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled" | |
6528 | +setfacl -m u:0:5 "$fromdir/file1" | |
6529 | +setfacl -m u:0:5 "$fromdir/file2" | |
6530 | + | |
6531 | +$RSYNC -avvA "$fromdir/" "$todir/" | |
6532 | + | |
6533 | +cd "$fromdir" | |
6534 | +getfacl $files >"$scratchdir/acls.txt" | |
6535 | + | |
6536 | +cd "$todir" | |
6537 | +getfacl $files | diff $diffopt "$scratchdir/acls.txt" - | |
6538 | + | |
6539 | +# The script would have aborted on error, so getting here means we've won. | |
6540 | +exit 0 | |
9a7eef96 WD |
6541 | --- old/testsuite/default-acls.test |
6542 | +++ new/testsuite/default-acls.test | |
475c4a36 | 6543 | @@ -0,0 +1,65 @@ |
90fa6d68 WD |
6544 | +#! /bin/sh |
6545 | + | |
475c4a36 | 6546 | +# This program is distributable under the terms of the GNU GPL (see |
90fa6d68 WD |
6547 | +# COPYING). |
6548 | + | |
6549 | +# Test that rsync obeys default ACLs. -- Matt McCutchen | |
6550 | + | |
6551 | +. $srcdir/testsuite/rsync.fns | |
6552 | + | |
25d385b9 | 6553 | +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support" |
53c1073a | 6554 | +case "$setfacl_nodef" in |
475c4a36 | 6555 | +true) test_skipped "I don't know how to use your setfacl command" ;; |
53c1073a WD |
6556 | +*-k*) opts='-dm u::7,g::5,o:5' ;; |
6557 | +*) opts='-m d:u::7,d:g::5,d:o:5' ;; | |
6558 | +esac | |
6559 | +setfacl $opts "$scratchdir" || test_skipped "Your filesystem has ACLs disabled" | |
90fa6d68 | 6560 | + |
90fa6d68 | 6561 | +# Call as: testit <dirname> <default-acl> <file-expected> <program-expected> |
25d385b9 | 6562 | +testit() { |
90fa6d68 WD |
6563 | + todir="$scratchdir/$1" |
6564 | + mkdir "$todir" | |
53c1073a WD |
6565 | + $setfacl_nodef "$todir" |
6566 | + if [ "$2" ]; then | |
6567 | + case "$setfacl_nodef" in | |
6568 | + *-k*) opts="-dm $2" ;; | |
6569 | + *) opts="-m `echo $2 | sed 's/\([ugom]:\)/d:\1/g'`" | |
6570 | + esac | |
6571 | + setfacl $opts "$todir" | |
6572 | + fi | |
90fa6d68 WD |
6573 | + # Make sure we obey ACLs when creating a directory to hold multiple transferred files, |
6574 | + # even though the directory itself is outside the transfer | |
25d385b9 | 6575 | + $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/" |
0251480d | 6576 | + check_perms "$todir/to" $4 "Target $1" |
25d385b9 | 6577 | + check_perms "$todir/to/dir" $4 "Target $1" |
0251480d WD |
6578 | + check_perms "$todir/to/file" $3 "Target $1" |
6579 | + check_perms "$todir/to/program" $4 "Target $1" | |
90fa6d68 WD |
6580 | + # Make sure get_local_name doesn't mess us up when transferring only one file |
6581 | + $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile" | |
0251480d | 6582 | + check_perms "$todir/to/anotherfile" $3 "Target $1" |
bb81ee98 | 6583 | + # Make sure we obey default ACLs when not transferring a regular file |
2578e2b6 | 6584 | + $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/" |
bb81ee98 | 6585 | + check_perms "$todir/to/anotherdir" $4 "Target $1" |
90fa6d68 WD |
6586 | +} |
6587 | + | |
25d385b9 | 6588 | +mkdir "$scratchdir/dir" |
0251480d | 6589 | +echo "File!" >"$scratchdir/file" |
25d385b9 WD |
6590 | +echo "#!/bin/sh" >"$scratchdir/program" |
6591 | +chmod 777 "$scratchdir/dir" | |
0251480d WD |
6592 | +chmod 666 "$scratchdir/file" |
6593 | +chmod 777 "$scratchdir/program" | |
6594 | + | |
90fa6d68 WD |
6595 | +# Test some target directories |
6596 | +umask 0077 | |
53c1073a WD |
6597 | +testit da777 u::7,g::7,o:7 rw-rw-rw- rwxrwxrwx |
6598 | +testit da775 u::7,g::7,o:5 rw-rw-r-- rwxrwxr-x | |
6599 | +testit da750 u::7,g::5,o:0 rw-r----- rwxr-x--- | |
6600 | +testit da770mask u::7,u:0:7,g::0,m:7,o:0 rw-rw---- rwxrwx--- | |
0251480d | 6601 | +testit noda1 '' rw------- rwx------ |
90fa6d68 | 6602 | +umask 0000 |
0251480d | 6603 | +testit noda2 '' rw-rw-rw- rwxrwxrwx |
90fa6d68 | 6604 | +umask 0022 |
0251480d | 6605 | +testit noda3 '' rw-r--r-- rwxr-xr-x |
90fa6d68 WD |
6606 | + |
6607 | +# Hooray | |
6608 | +exit 0 | |
0870c22a WD |
6609 | --- old/testsuite/devices.test |
6610 | +++ new/testsuite/devices.test | |
6611 | @@ -42,14 +42,14 @@ touch -r "$fromdir/block" "$fromdir/bloc | |
6612 | $RSYNC -ai "$fromdir/block" "$todir/block2" \ | |
6613 | | tee "$outfile" | |
6614 | cat <<EOT >"$chkfile" | |
6615 | -cD+++++++ block | |
6616 | +cD+++++++++ block | |
6617 | EOT | |
6618 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" | |
6619 | ||
6620 | $RSYNC -ai "$fromdir/block2" "$todir/block" \ | |
6621 | | tee "$outfile" | |
6622 | cat <<EOT >"$chkfile" | |
6623 | -cD+++++++ block2 | |
6624 | +cD+++++++++ block2 | |
6625 | EOT | |
6626 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" | |
6627 | ||
6628 | @@ -58,7 +58,7 @@ sleep 1 | |
6629 | $RSYNC -Di "$fromdir/block3" "$todir/block" \ | |
6630 | | tee "$outfile" | |
6631 | cat <<EOT >"$chkfile" | |
6632 | -cD..T.... block3 | |
6633 | +cD..T...... block3 | |
6634 | EOT | |
6635 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" | |
6636 | ||
6637 | @@ -66,15 +66,15 @@ $RSYNC -aiHvv "$fromdir/" "$todir/" \ | |
6638 | | tee "$outfile" | |
6639 | filter_outfile | |
6640 | cat <<EOT >"$chkfile" | |
6641 | -.d..t.... ./ | |
6642 | -cD..t.... block | |
05031682 | 6643 | -cD block2 |
0870c22a WD |
6644 | -cD+++++++ block3 |
6645 | -hD+++++++ block2.5 => block3 | |
6646 | -cD+++++++ char | |
6647 | -cD+++++++ char2 | |
6648 | -cD+++++++ char3 | |
6649 | -cS+++++++ fifo | |
6650 | +.d..t...... ./ | |
6651 | +cD..t...... block | |
05031682 | 6652 | +cD block2 |
0870c22a WD |
6653 | +cD+++++++++ block3 |
6654 | +hD+++++++++ block2.5 => block3 | |
6655 | +cD+++++++++ char | |
6656 | +cD+++++++++ char2 | |
6657 | +cD+++++++++ char3 | |
6658 | +cS+++++++++ fifo | |
6659 | EOT | |
6660 | if test ! -b "$fromdir/block2.5"; then | |
6661 | sed -e '/block2\.5/d' \ | |
05031682 WD |
6662 | @@ -94,15 +94,15 @@ if test -b "$fromdir/block2.5"; then |
6663 | $RSYNC -aii --link-dest="$todir" "$fromdir/" "$chkdir/" \ | |
6664 | | tee "$outfile" | |
6665 | cat <<EOT >"$chkfile" | |
6666 | -cd ./ | |
6667 | -hD block | |
6668 | -hD block2 | |
6669 | -hD block2.5 | |
6670 | -hD block3 | |
6671 | -hD char | |
6672 | -hD char2 | |
6673 | -hD char3 | |
6674 | -hS fifo | |
6675 | +cd ./ | |
6676 | +hD block | |
6677 | +hD block2 | |
6678 | +hD block2.5 | |
6679 | +hD block3 | |
6680 | +hD char | |
6681 | +hD char2 | |
6682 | +hD char3 | |
6683 | +hS fifo | |
6684 | EOT | |
6685 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 4 failed" | |
6686 | fi | |
0870c22a WD |
6687 | --- old/testsuite/itemize.test |
6688 | +++ new/testsuite/itemize.test | |
a7592111 | 6689 | @@ -47,16 +47,16 @@ rm -f "$to2dir" "$to2dir.test" |
0870c22a WD |
6690 | $RSYNC -iplr "$fromdir/" "$todir/" \ |
6691 | | tee "$outfile" | |
a7592111 | 6692 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
2a787d74 | 6693 | -cd+++++++ ./ |
0870c22a | 6694 | -cd+++++++ bar/ |
a7592111 | 6695 | -cd+++++++ foo/_P30_ |
0870c22a WD |
6696 | -cd+++++++ bar/baz/ |
6697 | ->f+++++++ bar/baz/rsync | |
a7592111 | 6698 | -cd+++++++ foo/_P29_ |
0870c22a WD |
6699 | ->f+++++++ foo/config1 |
6700 | ->f+++++++ foo/config2 | |
6701 | ->f+++++++ foo/extra | |
6702 | -cL+++++++ foo/sym -> ../bar/baz/rsync | |
2a787d74 | 6703 | +cd+++++++++ ./ |
0870c22a | 6704 | +cd+++++++++ bar/ |
a7592111 | 6705 | +cd+++++++++ foo/_P30_ |
0870c22a WD |
6706 | +cd+++++++++ bar/baz/ |
6707 | +>f+++++++++ bar/baz/rsync | |
a7592111 | 6708 | +cd+++++++++ foo/_P29_ |
0870c22a WD |
6709 | +>f+++++++++ foo/config1 |
6710 | +>f+++++++++ foo/config2 | |
6711 | +>f+++++++++ foo/extra | |
6712 | +cL+++++++++ foo/sym -> ../bar/baz/rsync | |
6713 | EOT | |
6714 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 1 failed" | |
6715 | ||
a7592111 | 6716 | @@ -68,10 +68,10 @@ chmod 601 "$fromdir/foo/config2" |
0870c22a WD |
6717 | $RSYNC -iplrH "$fromdir/" "$todir/" \ |
6718 | | tee "$outfile" | |
a7592111 | 6719 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
0870c22a WD |
6720 | ->f..T.... bar/baz/rsync |
6721 | ->f..T.... foo/config1 | |
6722 | ->f.sTp... foo/config2 | |
6723 | -hf..T.... foo/extra => foo/config1 | |
6724 | +>f..T...... bar/baz/rsync | |
6725 | +>f..T...... foo/config1 | |
6726 | +>f.sTp..... foo/config2 | |
6727 | +hf..T...... foo/extra => foo/config1 | |
6728 | EOT | |
6729 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 2 failed" | |
6730 | ||
a7592111 | 6731 | @@ -88,12 +88,12 @@ chmod 777 "$todir/bar/baz/rsync" |
0870c22a WD |
6732 | $RSYNC -iplrtc "$fromdir/" "$todir/" \ |
6733 | | tee "$outfile" | |
a7592111 WD |
6734 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
6735 | -.d..t.... foo/_P30_ | |
0870c22a | 6736 | -.f..tp... bar/baz/rsync |
a7592111 | 6737 | -.d..t.... foo/_P29_ |
0870c22a WD |
6738 | -.f..t.... foo/config1 |
6739 | ->fcstp... foo/config2 | |
6740 | -cL..T.... foo/sym -> ../bar/baz/rsync | |
a7592111 | 6741 | +.d..t...... foo/_P30_ |
0870c22a | 6742 | +.f..tp..... bar/baz/rsync |
a7592111 | 6743 | +.d..t...... foo/_P29_ |
0870c22a WD |
6744 | +.f..t...... foo/config1 |
6745 | +>fcstp..... foo/config2 | |
6746 | +cL..T...... foo/sym -> ../bar/baz/rsync | |
6747 | EOT | |
6748 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 3 failed" | |
6749 | ||
a7592111 | 6750 | @@ -118,15 +118,15 @@ $RSYNC -ivvplrtH "$fromdir/" "$todir/" \ |
0870c22a WD |
6751 | | tee "$outfile" |
6752 | filter_outfile | |
a7592111 | 6753 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
0870c22a WD |
6754 | -.d ./ |
6755 | -.d bar/ | |
6756 | -.d bar/baz/ | |
6757 | -.f...p... bar/baz/rsync | |
6758 | -.d foo/ | |
6759 | -.f foo/config1 | |
6760 | ->f..t.... foo/config2 | |
6761 | -hf foo/extra | |
6762 | -.L foo/sym -> ../bar/baz/rsync | |
6763 | +.d ./ | |
6764 | +.d bar/ | |
6765 | +.d bar/baz/ | |
6766 | +.f...p..... bar/baz/rsync | |
6767 | +.d foo/ | |
6768 | +.f foo/config1 | |
6769 | +>f..t...... foo/config2 | |
6770 | +hf foo/extra | |
6771 | +.L foo/sym -> ../bar/baz/rsync | |
6772 | EOT | |
6773 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 5 failed" | |
6774 | ||
a7592111 | 6775 | @@ -145,8 +145,8 @@ touch "$todir/foo/config2" |
0870c22a WD |
6776 | $RSYNC -iplrtH "$fromdir/" "$todir/" \ |
6777 | | tee "$outfile" | |
a7592111 | 6778 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
0870c22a WD |
6779 | -.f...p... foo/config1 |
6780 | ->f..t.... foo/config2 | |
6781 | +.f...p..... foo/config1 | |
6782 | +>f..t...... foo/config2 | |
6783 | EOT | |
6784 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 7 failed" | |
6785 | ||
a7592111 | 6786 | @@ -154,15 +154,15 @@ $RSYNC -ivvplrtH --copy-dest=../to "$fro |
0870c22a WD |
6787 | | tee "$outfile" |
6788 | filter_outfile | |
a7592111 | 6789 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
05031682 WD |
6790 | -cd ./ |
6791 | -cd bar/ | |
6792 | -cd bar/baz/ | |
0870c22a | 6793 | -cf bar/baz/rsync |
05031682 | 6794 | -cd foo/ |
0870c22a WD |
6795 | -cf foo/config1 |
6796 | -cf foo/config2 | |
6797 | -hf foo/extra => foo/config1 | |
05031682 WD |
6798 | -cL foo/sym -> ../bar/baz/rsync |
6799 | +cd ./ | |
6800 | +cd bar/ | |
6801 | +cd bar/baz/ | |
0870c22a | 6802 | +cf bar/baz/rsync |
05031682 | 6803 | +cd foo/ |
0870c22a WD |
6804 | +cf foo/config1 |
6805 | +cf foo/config2 | |
6806 | +hf foo/extra => foo/config1 | |
05031682 | 6807 | +cL foo/sym -> ../bar/baz/rsync |
0870c22a WD |
6808 | EOT |
6809 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 8 failed" | |
6810 | ||
a7592111 | 6811 | @@ -170,7 +170,7 @@ rm -rf "$to2dir" |
147c8f4c | 6812 | $RSYNC -iplrtH --copy-dest=../to "$fromdir/" "$to2dir/" \ |
0870c22a | 6813 | | tee "$outfile" |
a7592111 | 6814 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
0870c22a | 6815 | -hf foo/extra => foo/config1 |
0870c22a WD |
6816 | +hf foo/extra => foo/config1 |
6817 | EOT | |
6818 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 9 failed" | |
6819 | ||
a7592111 | 6820 | @@ -196,15 +196,15 @@ $RSYNC -ivvplrtH --link-dest="$todir" "$ |
0870c22a WD |
6821 | | tee "$outfile" |
6822 | filter_outfile | |
a7592111 | 6823 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
05031682 WD |
6824 | -cd ./ |
6825 | -cd bar/ | |
6826 | -cd bar/baz/ | |
0870c22a | 6827 | -hf bar/baz/rsync |
05031682 | 6828 | -cd foo/ |
0870c22a WD |
6829 | -hf foo/config1 |
6830 | -hf foo/config2 | |
6831 | -hf foo/extra => foo/config1 | |
147c8f4c | 6832 | -$L foo/sym -> ../bar/baz/rsync |
05031682 WD |
6833 | +cd ./ |
6834 | +cd bar/ | |
6835 | +cd bar/baz/ | |
0870c22a | 6836 | +hf bar/baz/rsync |
05031682 | 6837 | +cd foo/ |
0870c22a WD |
6838 | +hf foo/config1 |
6839 | +hf foo/config2 | |
6840 | +hf foo/extra => foo/config1 | |
147c8f4c | 6841 | +$L foo/sym -> ../bar/baz/rsync |
0870c22a WD |
6842 | EOT |
6843 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 11 failed" | |
6844 | ||
a7592111 | 6845 | @@ -244,15 +244,15 @@ $RSYNC -ivvplrtH --compare-dest="$todir" |
7b80cd0e WD |
6846 | | tee "$outfile" |
6847 | filter_outfile | |
a7592111 | 6848 | sed -e "$sed_cmd" <<EOT >"$chkfile" |
05031682 WD |
6849 | -cd ./ |
6850 | -cd bar/ | |
6851 | -cd bar/baz/ | |
0870c22a | 6852 | -.f bar/baz/rsync |
05031682 | 6853 | -cd foo/ |
0870c22a WD |
6854 | -.f foo/config1 |
6855 | -.f foo/config2 | |
7b80cd0e | 6856 | -.f foo/extra |
0870c22a | 6857 | -.L foo/sym -> ../bar/baz/rsync |
05031682 WD |
6858 | +cd ./ |
6859 | +cd bar/ | |
6860 | +cd bar/baz/ | |
0870c22a | 6861 | +.f bar/baz/rsync |
05031682 | 6862 | +cd foo/ |
0870c22a WD |
6863 | +.f foo/config1 |
6864 | +.f foo/config2 | |
7b80cd0e | 6865 | +.f foo/extra |
0870c22a WD |
6866 | +.L foo/sym -> ../bar/baz/rsync |
6867 | EOT | |
2a787d74 | 6868 | diff $diffopt "$chkfile" "$outfile" || test_fail "test 15 failed" |
0870c22a | 6869 | |
9a7eef96 WD |
6870 | --- old/uidlist.c |
6871 | +++ new/uidlist.c | |
a7592111 WD |
6872 | @@ -36,6 +36,7 @@ extern int verbose; |
6873 | extern int am_root; | |
fa26e11c WD |
6874 | extern int preserve_uid; |
6875 | extern int preserve_gid; | |
6876 | +extern int preserve_acls; | |
6877 | extern int numeric_ids; | |
fa26e11c | 6878 | |
a7592111 WD |
6879 | struct idlist { |
6880 | @@ -272,7 +273,7 @@ void send_uid_list(int f) | |
70891d26 WD |
6881 | { |
6882 | struct idlist *list; | |
fa26e11c WD |
6883 | |
6884 | - if (preserve_uid) { | |
6885 | + if (preserve_uid || preserve_acls) { | |
6886 | int len; | |
6887 | /* we send sequences of uid/byte-length/name */ | |
6888 | for (list = uidlist; list; list = list->next) { | |
a7592111 | 6889 | @@ -289,7 +290,7 @@ void send_uid_list(int f) |
fa26e11c WD |
6890 | write_int(f, 0); |
6891 | } | |
6892 | ||
6893 | - if (preserve_gid) { | |
6894 | + if (preserve_gid || preserve_acls) { | |
6895 | int len; | |
6896 | for (list = gidlist; list; list = list->next) { | |
6897 | if (!list->name) | |
a7592111 WD |
6898 | @@ -329,18 +330,28 @@ void recv_uid_list(int f, struct file_li |
6899 | { | |
fa26e11c | 6900 | int id, i; |
fa26e11c WD |
6901 | |
6902 | - if (preserve_uid && !numeric_ids) { | |
6903 | + if ((preserve_uid || preserve_acls) && !numeric_ids) { | |
6904 | /* read the uid list */ | |
a7592111 WD |
6905 | while ((id = read_int(f)) != 0) |
6906 | recv_user_name(f, (uid_t)id); | |
fa26e11c WD |
6907 | } |
6908 | ||
fa26e11c WD |
6909 | - if (preserve_gid && !numeric_ids) { |
6910 | + if ((preserve_gid || preserve_acls) && !numeric_ids) { | |
6911 | /* read the gid list */ | |
a7592111 WD |
6912 | while ((id = read_int(f)) != 0) |
6913 | recv_group_name(f, (gid_t)id); | |
fa26e11c | 6914 | } |
125d7fca | 6915 | |
4edb99c8 | 6916 | +#ifdef SUPPORT_ACLS |
fa26e11c | 6917 | + if (preserve_acls && !numeric_ids) { |
c52977bc WD |
6918 | + id_t *id; |
6919 | + while ((id = next_acl_uid(flist)) != NULL) | |
6920 | + *id = match_uid(*id); | |
6921 | + while ((id = next_acl_gid(flist)) != NULL) | |
6922 | + *id = match_gid(*id); | |
fa26e11c | 6923 | + } |
162234a7 | 6924 | +#endif |
125d7fca | 6925 | + |
90fa6d68 | 6926 | /* Now convert all the uids/gids from sender values to our values. */ |
125d7fca | 6927 | if (am_root && preserve_uid && !numeric_ids) { |
90fa6d68 | 6928 | for (i = 0; i < flist->count; i++) |
6250eb3e WD |
6929 | --- old/util.c |
6930 | +++ new/util.c | |
5e3c6c93 | 6931 | @@ -1467,3 +1467,31 @@ int bitbag_next_bit(struct bitbag *bb, i |
6250eb3e WD |
6932 | |
6933 | return -1; | |
6934 | } | |
6935 | + | |
6936 | +void *expand_item_list(item_list *lp, size_t item_size, | |
645e162c | 6937 | + const char *desc, int incr) |
6250eb3e WD |
6938 | +{ |
6939 | + /* First time through, 0 <= 0, so list is expanded. */ | |
6940 | + if (lp->malloced <= lp->count) { | |
6941 | + void *new_ptr; | |
6942 | + size_t new_size = lp->malloced; | |
645e162c WD |
6943 | + if (incr < 0) |
6944 | + new_size -= incr; /* increase slowly */ | |
98ccc74a | 6945 | + else if (new_size < (size_t)incr) |
645e162c WD |
6946 | + new_size += incr; |
6947 | + else | |
6948 | + new_size *= 2; | |
6250eb3e WD |
6949 | + new_ptr = realloc_array(lp->items, char, new_size * item_size); |
6950 | + if (verbose >= 4) { | |
6951 | + rprintf(FINFO, "[%s] expand %s to %.0f bytes, did%s move\n", | |
6952 | + who_am_i(), desc, (double)new_size * item_size, | |
6953 | + new_ptr == lp->items ? " not" : ""); | |
6954 | + } | |
6955 | + if (!new_ptr) | |
6956 | + out_of_memory("expand_item_list"); | |
6957 | + | |
6958 | + lp->items = new_ptr; | |
6959 | + lp->malloced = new_size; | |
6960 | + } | |
6961 | + return (char*)lp->items + (lp->count++ * item_size); | |
6962 | +} |