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