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