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