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