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