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