Fixed a typo.
[rsync/rsync-patches.git] / acls.diff
CommitLineData
fa26e11c
WD
1After applying this patch, run these commands for a successful build:
2
27e96866 3 ./prepare-source
f787c90c 4 ./configure --enable-acl-support
fa26e11c
WD
5 make
6
f05cc718
WD
7The program currently complains when the --acls (-A) option is used to copy
8from a disk that doesn't support ACLs. This should be changed to silently
9notice that no ACLs are available to copy. Of course, trying to write out
10ACLs to a non-ACL-supporting disk should complain.
fa26e11c 11
9a7eef96
WD
12--- old/Makefile.in
13+++ new/Makefile.in
4bf6f8c7 14@@ -25,15 +25,15 @@ VERSION=@VERSION@
fa26e11c
WD
15 .SUFFIXES:
16 .SUFFIXES: .c .o
17
18-HEADERS=byteorder.h config.h errcode.h proto.h rsync.h lib/pool_alloc.h
19+HEADERS=byteorder.h config.h errcode.h proto.h rsync.h smb_acls.h lib/pool_alloc.h
20 LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
0f6733d8
WD
21- lib/permstring.o lib/pool_alloc.o @LIBOBJS@
22+ lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
4bf6f8c7
WD
23 ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
24 zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
fa26e11c
WD
25 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
26 main.o checksum.o match.o syscall.o log.o backup.o
27 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
610969d1
WD
28- fileio.o batch.o clientname.o chmod.o
29+ fileio.o batch.o clientname.o chmod.o acls.o
fa26e11c
WD
30 OBJS3=progress.o pipe.o
31 DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
32 popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
9a7eef96
WD
33--- old/acls.c
34+++ new/acls.c
26c810d8 35@@ -0,0 +1,1202 @@
fa26e11c
WD
36+/* -*- c-file-style: "linux" -*-
37+ Copyright (C) Andrew Tridgell 1996
38+ Copyright (C) Paul Mackerras 1996
39+
40+ This program is free software; you can redistribute it and/or modify
41+ it under the terms of the GNU General Public License as published by
42+ the Free Software Foundation; either version 2 of the License, or
43+ (at your option) any later version.
44+
45+ This program is distributed in the hope that it will be useful,
46+ but WITHOUT ANY WARRANTY; without even the implied warranty of
47+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48+ GNU General Public License for more details.
49+
50+ You should have received a copy of the GNU General Public License
51+ along with this program; if not, write to the Free Software
52+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
53+*/
54+
55+/* handle passing ACLs between systems */
56+
57+#include "rsync.h"
0f6733d8 58+#include "lib/sysacls.h"
fa26e11c 59+
4df546eb 60+#ifdef SUPPORT_ACLS
fa26e11c
WD
61+
62+extern int preserve_acls;
63+extern int am_root;
64+extern int dry_run;
90fa6d68 65+extern int orig_umask;
fa26e11c
WD
66+
67+typedef struct {
68+ id_t id;
69+ uchar access;
70+ SMB_ACL_TAG_T tag_type;
71+} rsync_ace;
72+
73+typedef struct {
74+ size_t count;
75+ size_t malloced;
76+ rsync_ace *races;
77+} rsync_acl;
78+
79+static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
80+
81+static void expand_rsync_acl(rsync_acl *racl)
82+{
4edb99c8
WD
83+ /* First time through, 0 <= 0, so list is expanded.
84+ * (Diabolical, rsync guys!) */
fa26e11c 85+ if (racl->malloced <= racl->count) {
0f6733d8
WD
86+ rsync_ace *new_ptr;
87+ size_t new_size = racl->malloced + 10;
88+ new_ptr = realloc_array(racl->races, rsync_ace, new_size);
fa26e11c
WD
89+ if (verbose >= 4) {
90+ rprintf(FINFO, "expand rsync_acl to %.0f bytes, did%s move\n",
0f6733d8 91+ (double) new_size * sizeof racl->races[0],
fa26e11c
WD
92+ racl->races ? "" : " not");
93+ }
94+
0f6733d8
WD
95+ racl->races = new_ptr;
96+ racl->malloced = new_size;
fa26e11c
WD
97+
98+ if (!racl->races)
99+ out_of_memory("expand_rsync_acl");
100+ }
101+}
102+
103+static void rsync_acl_free(rsync_acl *racl)
104+{
105+ free(racl->races);
106+ racl->races = NULL;
107+ racl->count = 0;
108+ racl->malloced = 0;
109+}
110+
111+static int rsync_ace_sorter(const void *r1, const void *r2)
112+{
113+ rsync_ace *race1 = (rsync_ace *)r1;
114+ SMB_ACL_TAG_T rtag1 = race1->tag_type;
115+ id_t rid1 = race1->id;
116+ rsync_ace *race2 = (rsync_ace *)r2;
117+ SMB_ACL_TAG_T rtag2 = race2->tag_type;
118+ id_t rid2 = race2->id;
119+ /* start at the extrema */
120+ if (rtag1 == SMB_ACL_USER_OBJ || rtag2 == SMB_ACL_MASK)
121+ return -1;
122+ if (rtag2 == SMB_ACL_USER_OBJ || rtag1 == SMB_ACL_MASK)
123+ return 1;
124+ /* work inwards */
125+ if (rtag1 == SMB_ACL_OTHER)
126+ return 1;
127+ if (rtag2 == SMB_ACL_OTHER)
128+ return -1;
129+ /* only SMB_ACL_USERs and SMB_ACL_GROUP*s left */
130+ if (rtag1 == SMB_ACL_USER) {
131+ switch (rtag2) {
132+ case SMB_ACL_GROUP:
133+ case SMB_ACL_GROUP_OBJ:
134+ case SMB_ACL_OTHER:
135+ return -1;
136+ }
137+ /* both USER */
138+ return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
139+ }
140+ if (rtag2 == SMB_ACL_USER)
141+ return 1;
142+ /* only SMB_ACL_GROUP*s to worry about; kick out GROUP_OBJs first */
143+ if (rtag1 == SMB_ACL_GROUP_OBJ)
144+ return -1;
145+ if (rtag2 == SMB_ACL_GROUP_OBJ)
146+ return 1;
147+ /* only SMB_ACL_GROUPs left */
148+ return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
149+}
150+
151+static void sort_rsync_acl(rsync_acl *racl)
152+{
153+ if (!racl->count)
154+ return;
155+ qsort((void **)racl->races, racl->count, sizeof racl->races[0],
156+ &rsync_ace_sorter);
157+}
158+
159+static BOOL unpack_smb_acl(rsync_acl *racl, SMB_ACL_T sacl)
160+{
161+ SMB_ACL_ENTRY_T entry;
162+ int rc;
163+ const char *errfun;
164+ *racl = rsync_acl_initializer;
165+ errfun = "sys_acl_get_entry";
166+ for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
167+ rc == 1;
168+ rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
169+ SMB_ACL_PERMSET_T permset;
170+ void *qualifier;
171+ rsync_ace *race;
172+ expand_rsync_acl(racl);
173+ race = &racl->races[racl->count++];
174+ if ((rc = sys_acl_get_tag_type(entry, &race->tag_type))) {
175+ errfun = "sys_acl_get_tag_type";
176+ break;
177+ }
178+ if ((rc = sys_acl_get_permset(entry, &permset))) {
179+ errfun = "sys_acl_get_tag_type";
180+ break;
181+ }
182+ race->access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
183+ | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
184+ | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
185+ switch (race->tag_type) {
186+ case SMB_ACL_USER:
187+ case SMB_ACL_GROUP:
188+ break;
189+ default:
190+ continue;
191+ }
192+ if (!(qualifier = sys_acl_get_qualifier(entry))) {
193+ errfun = "sys_acl_get_tag_type";
194+ rc = EINVAL;
195+ break;
196+ }
197+ race->id = *((id_t *)qualifier);
198+ sys_acl_free_qualifier(qualifier, race->tag_type);
199+ }
200+ if (rc) {
201+ rprintf(FERROR, "unpack_smb_acl: %s(): %s\n",
202+ errfun, strerror(errno));
203+ rsync_acl_free(racl);
204+ return False;
205+ }
206+ sort_rsync_acl(racl);
207+ return True;
208+}
209+
210+static BOOL rsync_acls_equal(const rsync_acl *racl1, const rsync_acl *racl2)
211+{
212+ rsync_ace *race1, *race2;
213+ size_t count = racl1->count;
214+ if (count != racl2->count)
215+ return False;
216+ race1 = racl1->races;
217+ race2 = racl2->races;
218+ for (; count--; race1++, race2++) {
219+ if (race1->tag_type != race2->tag_type
220+ || race1->access != race2->access
221+ || ((race1->tag_type == SMB_ACL_USER
222+ || race1->tag_type == SMB_ACL_GROUP)
223+ && race1->id != race2->id))
224+ return False;
225+ }
226+ return True;
227+}
228+
229+typedef struct {
230+ size_t count;
231+ size_t malloced;
232+ rsync_acl *racls;
233+} rsync_acl_list;
234+
235+static rsync_acl_list _rsync_acl_lists[] = {
236+ { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
237+ { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
238+};
239+
240+static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
241+{
242+ return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
243+ : &_rsync_acl_lists[1];
244+}
245+
246+static void expand_rsync_acl_list(rsync_acl_list *racl_list)
247+{
4edb99c8
WD
248+ /* First time through, 0 <= 0, so list is expanded.
249+ * (Diabolical, rsync guys!) */
fa26e11c 250+ if (racl_list->malloced <= racl_list->count) {
0f6733d8 251+ rsync_acl *new_ptr;
fa26e11c
WD
252+ size_t new_size;
253+ if (racl_list->malloced < 1000)
0f6733d8 254+ new_size = racl_list->malloced + 1000;
fa26e11c 255+ else
0f6733d8
WD
256+ new_size = racl_list->malloced * 2;
257+ new_ptr = realloc_array(racl_list->racls, rsync_acl, new_size);
fa26e11c
WD
258+ if (verbose >= 3) {
259+ rprintf(FINFO, "expand_rsync_acl_list to %.0f bytes, did%s move\n",
0f6733d8 260+ (double) new_size * sizeof racl_list->racls[0],
fa26e11c
WD
261+ racl_list->racls ? "" : " not");
262+ }
263+
0f6733d8
WD
264+ racl_list->racls = new_ptr;
265+ racl_list->malloced = new_size;
fa26e11c
WD
266+
267+ if (!racl_list->racls)
268+ out_of_memory("expand_rsync_acl_list");
269+ }
270+}
271+
272+#if 0
273+static void free_rsync_acl_list(rsync_acl_list *racl_list)
274+{
4edb99c8
WD
275+ /* Run this in reverse, so references are freed before referents,
276+ * although not currently necessary. */
fa26e11c
WD
277+ while (racl_list->count--) {
278+ rsync_acl *racl = &racl_list->racls[racl_list->count];
279+ if (racl)
280+ rsync_acl_free(racl);
281+ }
282+ free(racl_list->racls);
283+ racl_list->racls = NULL;
284+ racl_list->malloced = 0;
285+}
286+#endif
287+
288+static int find_matching_rsync_acl(SMB_ACL_TYPE_T type,
289+ const rsync_acl_list *racl_list,
290+ const rsync_acl *racl)
291+{
292+ static int access_match = -1, default_match = -1;
293+ int *match = (type == SMB_ACL_TYPE_ACCESS) ?
294+ &access_match : &default_match;
295+ size_t count = racl_list->count;
4edb99c8 296+ /* If this is the first time through or we didn't match the last
fa26e11c 297+ * time, then start at the end of the list, which should be the
4edb99c8 298+ * best place to start hunting. */
fa26e11c
WD
299+ if (*match == -1)
300+ *match = racl_list->count - 1;
301+ while (count--) {
302+ if (rsync_acls_equal(&racl_list->racls[*match], racl))
303+ return *match;
304+ if (!(*match)--)
305+ *match = racl_list->count - 1;
306+ }
307+ *match = -1;
308+ return *match;
309+}
310+
4edb99c8 311+/* The general strategy with the tag_type <-> character mapping is that
fa26e11c 312+ * lowercase implies that no qualifier follows, where uppercase does.
4edb99c8 313+ * A similar idiom for the acl type (access or default) itself, but
fa26e11c
WD
314+ * lowercase in this instance means there's no ACL following, so the
315+ * ACL is a repeat, so the receiver should reuse the last of the same
4edb99c8 316+ * type ACL. */
fa26e11c
WD
317+
318+static void send_rsync_acl(int f, const rsync_acl *racl)
319+{
320+ rsync_ace *race;
321+ size_t count = racl->count;
322+ write_int(f, count);
323+ for (race = racl->races; count--; race++) {
324+ char ch;
325+ switch (race->tag_type) {
326+ case SMB_ACL_USER_OBJ:
327+ ch = 'u';
328+ break;
329+ case SMB_ACL_USER:
330+ ch = 'U';
331+ break;
332+ case SMB_ACL_GROUP_OBJ:
333+ ch = 'g';
334+ break;
335+ case SMB_ACL_GROUP:
336+ ch = 'G';
337+ break;
338+ case SMB_ACL_OTHER:
339+ ch = 'o';
340+ break;
341+ case SMB_ACL_MASK:
342+ ch = 'm';
343+ break;
344+ default:
345+ rprintf(FERROR,
e839d833 346+ "send_rsync_acl: unknown tag_type (%02x) on ACE; disregarding\n",
fa26e11c
WD
347+ race->tag_type);
348+ continue;
349+ }
350+ write_byte(f, ch);
351+ write_byte(f, race->access);
352+ if (isupper((int)ch)) {
353+ write_int(f, race->id);
4edb99c8 354+ /* FIXME: sorta wasteful: we should maybe buffer as
fa26e11c 355+ * many ids as max(ACL_USER + ACL_GROUP) objects to
4edb99c8 356+ * keep from making so many calls. */
fa26e11c
WD
357+ if (ch == 'U')
358+ add_uid(race->id);
359+ else
360+ add_gid(race->id);
361+ }
362+ }
363+}
364+
365+static rsync_acl _curr_rsync_acls[2];
366+
367+
368+static const char *str_acl_type(SMB_ACL_TYPE_T type)
369+{
370+ return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
371+ type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
372+ "unknown SMB_ACL_TYPE_T";
373+}
374+
4edb99c8
WD
375+/* Generate the ACL(s) for this flist entry;
376+ * ACL(s) are either sent or cleaned-up by send_acl() below. */
fa26e11c 377+
ee12ff0e 378+int make_acl(const struct file_struct *file, const char *fname)
fa26e11c
WD
379+{
380+ SMB_ACL_TYPE_T *type,
381+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
382+ rsync_acl *curr_racl;
383+ if (!preserve_acls || S_ISLNK(file->mode))
05b88206 384+ return 1;
fa26e11c
WD
385+ for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
386+ type < &types[0] + sizeof types / sizeof types[0]
387+ && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
388+ type++, curr_racl++) {
389+ SMB_ACL_T sacl;
390+ BOOL ok;
391+ *curr_racl = rsync_acl_initializer;
392+ if (!(sacl = sys_acl_get_file(fname, *type))) {
c171f097 393+ rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
fa26e11c 394+ fname, str_acl_type(*type), strerror(errno));
05b88206 395+ return -1;
fa26e11c
WD
396+ }
397+ ok = unpack_smb_acl(curr_racl, sacl);
398+ sys_acl_free_acl(sacl);
399+ if (!ok)
05b88206 400+ return -1;
fa26e11c 401+ }
05b88206 402+ return 0;
fa26e11c
WD
403+}
404+
4edb99c8
WD
405+/* Send the make_acl()-generated ACLs for this flist entry,
406+ * or clean up after an flist entry that's not being sent (f == -1). */
fa26e11c
WD
407+
408+void send_acl(const struct file_struct *file, int f)
409+{
410+ SMB_ACL_TYPE_T *type,
411+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
412+ rsync_acl *curr_racl;
413+ if (!preserve_acls || S_ISLNK(file->mode))
414+ return;
415+ for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
416+ type < &types[0] + sizeof types / sizeof types[0]
417+ && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
418+ type++, curr_racl++) {
419+ int index;
420+ rsync_acl_list *racl_list = rsync_acl_lists(*type);
421+ if (f == -1) {
422+ rsync_acl_free(curr_racl);
423+ continue;
424+ }
425+ if ((index = find_matching_rsync_acl(*type, racl_list, curr_racl))
426+ != -1) {
427+ write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'a' : 'd');
428+ write_int(f, index);
429+ rsync_acl_free(curr_racl);
430+ } else {
431+ write_byte(f, *type == SMB_ACL_TYPE_ACCESS ? 'A' : 'D');
432+ send_rsync_acl(f, curr_racl);
433+ expand_rsync_acl_list(racl_list);
434+ racl_list->racls[racl_list->count++] = *curr_racl;
435+ }
436+ }
437+}
438+
4edb99c8 439+/* The below stuff is only used by the receiver: */
fa26e11c
WD
440+
441+/* structure to hold index to rsync_acl_list member corresponding to
442+ * flist->files[i] */
443+
444+typedef struct {
445+ const struct file_struct *file;
446+ int aclidx;
447+} file_acl_index;
448+
449+typedef struct {
450+ size_t count;
451+ size_t malloced;
452+ file_acl_index *fileaclidxs;
453+} file_acl_index_list;
454+
455+static file_acl_index_list _file_acl_index_lists[] = {
456+ {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
457+ {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
458+};
459+
460+static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
461+{
462+ return type == SMB_ACL_TYPE_ACCESS ?
463+ &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
464+}
465+
466+static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
467+{
4edb99c8
WD
468+ /* First time through, 0 <= 0, so list is expanded.
469+ * (Diabolical, rsync guys!) */
fa26e11c 470+ if (fileaclidx_list->malloced <= fileaclidx_list->count) {
0f6733d8 471+ file_acl_index *new_ptr;
fa26e11c
WD
472+ size_t new_size;
473+ if (fileaclidx_list->malloced < 1000)
0f6733d8 474+ new_size = fileaclidx_list->malloced + 1000;
fa26e11c 475+ else
0f6733d8
WD
476+ new_size = fileaclidx_list->malloced * 2;
477+ new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
fa26e11c
WD
478+ if (verbose >= 3) {
479+ rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
0f6733d8 480+ (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
fa26e11c
WD
481+ fileaclidx_list->fileaclidxs ? "" : " not");
482+ }
483+
0f6733d8
WD
484+ fileaclidx_list->fileaclidxs = new_ptr;
485+ fileaclidx_list->malloced = new_size;
fa26e11c
WD
486+
487+ if (!fileaclidx_list->fileaclidxs)
488+ out_of_memory("expand_file_acl_index_list");
489+ }
490+}
491+
492+#if 0
493+static void free_file_acl_index_list(file_acl_index_list *fileaclidx_list)
494+{
495+ free(fileaclidx_list->fileaclidxs);
496+ fileaclidx_list->fileaclidxs = NULL;
497+ fileaclidx_list->malloced = 0;
498+}
499+#endif
500+
501+/* lists to hold the SMB_ACL_Ts corresponding to the rsync_acl_list entries */
502+
503+typedef struct {
504+ size_t count;
505+ size_t malloced;
506+ SMB_ACL_T *sacls;
507+} smb_acl_list;
508+
509+static smb_acl_list _smb_acl_lists[] = {
510+ { 0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
511+ { 0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
512+};
513+
514+static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
515+{
516+ return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
517+ &_smb_acl_lists[1];
518+}
519+
520+static void expand_smb_acl_list(smb_acl_list *sacl_list)
521+{
4edb99c8
WD
522+ /* First time through, 0 <= 0, so list is expanded.
523+ * (Diabolical, rsync guys!) */
fa26e11c 524+ if (sacl_list->malloced <= sacl_list->count) {
0f6733d8 525+ SMB_ACL_T *new_ptr;
fa26e11c
WD
526+ size_t new_size;
527+ if (sacl_list->malloced < 1000)
0f6733d8 528+ new_size = sacl_list->malloced + 1000;
fa26e11c 529+ else
0f6733d8
WD
530+ new_size = sacl_list->malloced * 2;
531+ new_ptr = realloc_array(sacl_list->sacls, SMB_ACL_T, new_size);
fa26e11c
WD
532+ if (verbose >= 3) {
533+ rprintf(FINFO, "expand_smb_acl_list to %.0f bytes, did%s move\n",
0f6733d8 534+ (double) new_size * sizeof sacl_list->sacls[0],
fa26e11c
WD
535+ sacl_list->sacls ? "" : " not");
536+ }
537+
0f6733d8
WD
538+ sacl_list->sacls = new_ptr;
539+ sacl_list->malloced = new_size;
fa26e11c
WD
540+
541+ if (!sacl_list->sacls)
542+ out_of_memory("expand_smb_acl_list");
543+ }
544+}
545+
546+#if 0
547+static void free_smb_acl_list(SMB_ACL_TYPE_T type)
548+{
549+ smb_acl_list *sacl_list = smb_acl_lists(type);
550+ SMB_ACL_T *sacl = sacl_list->sacls;
551+ while (sacl_list->count--) {
552+ if (*sacl)
553+ sys_acl_free_acl(*sacl++);
554+ }
555+ free(sacl_list->sacls);
556+ sacl_list->sacls = NULL;
557+ sacl_list->malloced = 0;
558+}
559+#endif
560+
561+/* build an SMB_ACL_T corresponding to an rsync_acl */
562+static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
563+{
564+ size_t count = racl->count;
565+ rsync_ace *race = racl->races;
566+ const char *errfun = NULL;
567+ *smb_acl = sys_acl_init(count);
568+ if (!*smb_acl) {
569+ rprintf(FERROR, "pack_smb_acl: sys_acl_int(): %s\n",
570+ strerror(errno));
571+ return False;
572+ }
573+ for (; count--; race++) {
574+ SMB_ACL_ENTRY_T entry;
575+ SMB_ACL_PERMSET_T permset;
576+ if (sys_acl_create_entry(smb_acl, &entry)) {
577+ errfun = "sys_acl_create)";
578+ break;
579+ }
580+ if (sys_acl_set_tag_type(entry, race->tag_type)) {
581+ errfun = "sys_acl_set_tag";
582+ break;
583+ }
584+ if (race->tag_type == SMB_ACL_USER ||
585+ race->tag_type == SMB_ACL_GROUP)
586+ if (sys_acl_set_qualifier(entry, (void*)&race->id)) {
587+ errfun = "sys_acl_set_qualfier";
588+ break;
589+ }
590+ if (sys_acl_get_permset(entry, &permset)) {
591+ errfun = "sys_acl_get_permset";
592+ break;
593+ }
594+ if (sys_acl_clear_perms(permset)) {
595+ errfun = "sys_acl_clear_perms";
596+ break;
597+ }
598+ if (race->access & 4)
599+ if (sys_acl_add_perm(permset, SMB_ACL_READ)) {
600+ errfun = "sys_acl_add_perm";
601+ break;
602+ }
603+ if (race->access & 2)
604+ if (sys_acl_add_perm(permset, SMB_ACL_WRITE)) {
605+ errfun = "sys_acl_add_perm";
606+ break;
607+ }
608+ if (race->access & 1)
609+ if (sys_acl_add_perm(permset, SMB_ACL_EXECUTE)) {
610+ errfun = "sys_acl_add_perm";
611+ break;
612+ }
613+ if (sys_acl_set_permset(entry, permset)) {
614+ errfun = "sys_acl_set_permset";
615+ break;
616+ }
617+ }
618+ if (errfun) {
619+ sys_acl_free_acl(*smb_acl);
620+ rprintf(FERROR, "pack_smb_acl %s(): %s\n", errfun,
621+ strerror(errno));
622+ return False;
623+ }
624+ return True;
625+}
626+
627+static void receive_rsync_acl(rsync_acl *racl, int f)
628+{
629+#if ACLS_NEED_MASK
630+ uchar required_mask_perm = 0;
fa26e11c 631+#endif
1ce58df1 632+ BOOL saw_mask = False;
fa26e11c
WD
633+ BOOL saw_user_obj = False, saw_group_obj = False,
634+ saw_other = False;
635+ size_t count = read_int(f);
636+ rsync_ace *race;
637+ if (!count)
638+ return;
639+ while (count--) {
640+ uchar tag = read_byte(f);
641+ expand_rsync_acl(racl);
642+ race = &racl->races[racl->count++];
643+ switch (tag) {
644+ case 'u':
645+ race->tag_type = SMB_ACL_USER_OBJ;
646+ saw_user_obj = True;
647+ break;
648+ case 'U':
649+ race->tag_type = SMB_ACL_USER;
650+ break;
651+ case 'g':
652+ race->tag_type = SMB_ACL_GROUP_OBJ;
653+ saw_group_obj = True;
654+ break;
655+ case 'G':
656+ race->tag_type = SMB_ACL_GROUP;
657+ break;
658+ case 'o':
659+ race->tag_type = SMB_ACL_OTHER;
660+ saw_other = True;
661+ break;
662+ case 'm':
663+ race->tag_type = SMB_ACL_MASK;
fa26e11c 664+ saw_mask = True;
fa26e11c
WD
665+ break;
666+ default:
667+ rprintf(FERROR, "receive_rsync_acl: unknown tag %c\n",
668+ tag);
669+ exit_cleanup(RERR_STREAMIO);
670+ }
671+ race->access = read_byte(f);
672+ if (race->access & ~ (4 | 2 | 1)) {
673+ rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
674+ race->access);
675+ exit_cleanup(RERR_STREAMIO);
676+ }
677+ if (race->tag_type == SMB_ACL_USER ||
678+ race->tag_type == SMB_ACL_GROUP) {
679+ race->id = read_int(f);
680+#if ACLS_NEED_MASK
681+ required_mask_perm |= race->access;
682+#endif
683+ }
684+#if ACLS_NEED_MASK
685+ else if (race->tag_type == SMB_ACL_GROUP_OBJ)
686+ required_mask_perm |= race->access;
687+#endif
688+
689+ }
690+ if (!saw_user_obj) {
691+ expand_rsync_acl(racl);
692+ race = &racl->races[racl->count++];
693+ race->tag_type = SMB_ACL_USER_OBJ;
694+ race->access = 7;
695+ }
696+ if (!saw_group_obj) {
697+ expand_rsync_acl(racl);
698+ race = &racl->races[racl->count++];
699+ race->tag_type = SMB_ACL_GROUP_OBJ;
700+ race->access = 0;
701+ }
702+ if (!saw_other) {
703+ expand_rsync_acl(racl);
704+ race = &racl->races[racl->count++];
705+ race->tag_type = SMB_ACL_OTHER;
706+ race->access = 0;
707+ }
708+#if ACLS_NEED_MASK
709+ if (!saw_mask) {
710+ expand_rsync_acl(racl);
711+ race = &racl->races[racl->count++];
712+ race->tag_type = SMB_ACL_MASK;
713+ race->access = required_mask_perm;
714+ }
1ce58df1
WD
715+#else
716+ /* If we, a system without ACLS_NEED_MASK, received data from a
717+ * system that has masks, throw away the extraneous CLASS_OBJs. */
718+ if (saw_mask && racl->count == 4) {
719+ rsync_ace *group_obj_race = NULL, *mask_race = NULL;
720+ rsync_ace *p;
721+ size_t i;
722+ for (i = 0, p = racl->races; i < racl->count; i++, p++) {
723+ if (p->tag_type == SMB_ACL_MASK)
724+ mask_race = p;
725+ else if (p->tag_type == SMB_ACL_GROUP_OBJ)
726+ group_obj_race = p;
727+ }
728+ if (mask_race == NULL || group_obj_race == NULL) {
729+ rprintf(FERROR, "receive_rsync_acl: have four ACES "
730+ "and one's ACL_MASK but missing "
731+ "either it or ACL_GROUP_OBJ, "
732+ "when pruning ACL\n");
733+ } else {
734+ /* mask off group perms with it first */
735+ group_obj_race->access &= mask_race->access;
736+ /* dump mask_race; re-slot any followers-on */
737+ racl->count--;
738+ if (mask_race != &racl->races[racl->count]) {
739+ *mask_race = racl->races[racl->count];
740+ saw_user_obj = False; /* force re-sort */
741+ }
742+ }
743+ }
fa26e11c
WD
744+#endif
745+#if ACLS_NEED_MASK
746+ if (!(saw_user_obj && saw_group_obj && saw_other && saw_mask))
747+#else
748+ if (!(saw_user_obj && saw_group_obj && saw_other))
749+#endif
750+ sort_rsync_acl(racl);
751+}
752+
753+/* receive and build the rsync_acl_lists */
754+
755+void receive_acl(struct file_struct *file, int f)
756+{
757+ SMB_ACL_TYPE_T *type,
758+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
759+ char *fname;
760+ if (!preserve_acls || S_ISLNK(file->mode))
761+ return;
bd68c3c2 762+ fname = f_name(file, NULL);
fa26e11c
WD
763+ for (type = &types[0];
764+ type < &types[0] + sizeof types / sizeof types[0]
765+ && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
766+ type++) {
767+ file_acl_index_list *fileaclidx_list =
768+ file_acl_index_lists(*type);
769+ uchar tag;
770+ expand_file_acl_index_list(fileaclidx_list);
771+
772+ tag = read_byte(f);
773+ if (tag == 'A' || tag == 'a') {
774+ if (*type != SMB_ACL_TYPE_ACCESS) {
775+ rprintf(FERROR, "receive_acl %s: duplicate access ACL\n",
776+ fname);
777+ exit_cleanup(RERR_STREAMIO);
778+ }
779+ } else if (tag == 'D' || tag == 'd') {
780+ if (*type == SMB_ACL_TYPE_ACCESS) {
781+ rprintf(FERROR, "receive_acl %s: expecting access ACL; got default\n",
782+ fname);
783+ exit_cleanup(RERR_STREAMIO);
784+ }
785+ } else {
786+ rprintf(FERROR, "receive_acl %s: unknown ACL type tag: %c\n",
787+ fname, tag);
788+ exit_cleanup(RERR_STREAMIO);
789+ }
790+ if (tag == 'A' || tag == 'D') {
791+ rsync_acl racl = rsync_acl_initializer;
792+ rsync_acl_list *racl_list = rsync_acl_lists(*type);
793+ smb_acl_list *sacl_list = smb_acl_lists(*type);
794+ fileaclidx_list->fileaclidxs[fileaclidx_list->count].
795+ aclidx = racl_list->count;
796+ fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
797+ file = file;
798+ receive_rsync_acl(&racl, f);
799+ expand_rsync_acl_list(racl_list);
800+ racl_list->racls[racl_list->count++] = racl;
801+ expand_smb_acl_list(sacl_list);
802+ sacl_list->sacls[sacl_list->count++] = NULL;
803+ } else {
804+ int index = read_int(f);
805+ rsync_acl_list *racl_list = rsync_acl_lists(*type);
806+ if ((size_t) index >= racl_list->count) {
807+ rprintf(FERROR, "receive_acl %s: %s ACL index %d out of range\n",
808+ fname,
809+ str_acl_type(*type),
810+ index);
811+ exit_cleanup(RERR_STREAMIO);
812+ }
813+ fileaclidx_list->fileaclidxs[fileaclidx_list->count].
814+ aclidx = index;
815+ fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
816+ file = file;
817+ }
818+ }
819+}
820+
821+static int file_acl_index_list_sorter(const void *f1, const void *f2)
822+{
823+ const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
824+ const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
825+ return fileaclidx1->file == fileaclidx2->file ? 0 :
826+ fileaclidx1->file < fileaclidx2->file ? -1 : 1;
827+}
828+
829+void sort_file_acl_index_lists()
830+{
831+ SMB_ACL_TYPE_T *type,
832+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
833+ if (!preserve_acls)
834+ return;
835+ for (type = &types[0];
836+ type < &types[0] + sizeof types / sizeof types[0];
837+ type++)
838+ {
839+ file_acl_index_list *fileaclidx_list =
840+ file_acl_index_lists(*type);
841+ if (!fileaclidx_list->count)
842+ continue;
843+ qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
844+ sizeof fileaclidx_list->fileaclidxs[0],
845+ &file_acl_index_list_sorter);
846+ }
847+}
848+
849+static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
850+ const struct file_struct *file) {
851+ int low = 0, high = fileaclidx_list->count;
852+ const struct file_struct *file_mid;
853+ if (!high--)
854+ return -1;
855+ do {
856+ int mid = (high + low) / 2;
857+ file_mid = fileaclidx_list->fileaclidxs[mid].file;
858+ if (file_mid == file)
859+ return fileaclidx_list->fileaclidxs[mid].aclidx;
860+ if (file_mid > file)
861+ high = mid - 1;
862+ else
863+ low = mid + 1;
864+ } while (low < high);
865+ if (low == high) {
866+ file_mid = fileaclidx_list->fileaclidxs[low].file;
867+ if (file_mid == file)
868+ return fileaclidx_list->fileaclidxs[low].aclidx;
869+ }
870+ rprintf(FERROR,
871+ "find_file_acl_index: can't find entry for file in list\n");
872+ exit_cleanup(RERR_STREAMIO);
873+ return -1;
874+}
875+
876+/* for duplicating ACLs on backups when using backup_dir */
877+
878+int dup_acl(const char *orig, const char *bak, mode_t mode)
879+{
880+ SMB_ACL_TYPE_T *type,
881+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
882+ int ret = 0;
883+ if (!preserve_acls)
05b88206 884+ return 1;
fa26e11c
WD
885+ for (type = &types[0];
886+ type < &types[0] + sizeof types / sizeof types[0]
887+ && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
888+ type++) {
889+ SMB_ACL_T sacl_orig, sacl_bak;
890+ rsync_acl racl_orig, racl_bak;
891+ if (!(sacl_orig = sys_acl_get_file(orig, *type))) {
c171f097 892+ rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s\n",
fa26e11c
WD
893+ orig, str_acl_type(*type), strerror(errno));
894+ ret = -1;
895+ continue;
896+ }
897+ if (!(sacl_bak = sys_acl_get_file(orig, *type))) {
c171f097 898+ rprintf(FERROR, "dup_acl: sys_acl_get_file(%s, %s): %s. ignoring\n",
fa26e11c
WD
899+ bak, str_acl_type(*type), strerror(errno));
900+ ret = -1;
901+ /* try to forge on through */
902+ }
903+ if (!unpack_smb_acl(&racl_orig, sacl_orig)) {
904+ ret = -1;
905+ goto out_with_sacls;
906+ }
907+ if (sacl_bak) {
908+ if (!unpack_smb_acl(&racl_bak, sacl_bak)) {
909+ ret = -1;
910+ goto out_with_one_racl;
911+ }
912+ if (rsync_acls_equal(&racl_orig, &racl_bak))
913+ goto out_with_all;
914+ } else {
915+ ; /* presume they're unequal */
916+ }
917+ if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
918+ if (-1 == sys_acl_delete_def_file(bak)) {
919+ rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
920+ bak, strerror(errno));
921+ ret = -1;
922+ }
923+ } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
c171f097 924+ rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
fa26e11c
WD
925+ bak, str_acl_type(*type), strerror(errno));
926+ ret = -1;
927+ }
928+ out_with_all:
929+ if (sacl_bak)
930+ rsync_acl_free(&racl_bak);
931+ out_with_one_racl:
932+ rsync_acl_free(&racl_orig);
933+ out_with_sacls:
934+ if (sacl_bak)
935+ sys_acl_free_acl(sacl_bak);
936+ /* out_with_one_sacl: */
937+ if (sacl_orig)
938+ sys_acl_free_acl(sacl_orig);
939+ }
940+ return ret;
941+}
942+
90fa6d68 943+/* Stuff for redirecting calls to set_acl() from set_file_attrs()
4edb99c8 944+ * for keep_backup(). */
fa26e11c
WD
945+static const struct file_struct *backup_orig_file = NULL;
946+static const char null_string[] = "";
947+static const char *backup_orig_fname = null_string;
948+static const char *backup_dest_fname = null_string;
949+static SMB_ACL_T _backup_sacl[] = { NULL, NULL };
950+
951+void push_keep_backup_acl(const struct file_struct *file,
952+ const char *orig, const char *dest)
953+{
954+ if (preserve_acls) {
955+ SMB_ACL_TYPE_T *type,
956+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
957+ SMB_ACL_T *sacl;
958+ backup_orig_file = file;
959+ backup_orig_fname = orig;
960+ backup_dest_fname = dest;
961+ for (type = &types[0], sacl = &_backup_sacl[0];
962+ type < &types[0] + sizeof types / sizeof types[0];
963+ type++) {
964+ if (*type == SMB_ACL_TYPE_DEFAULT && !S_ISDIR(file->mode))
965+ *sacl = NULL;
966+ else {
967+ if (!(*sacl = sys_acl_get_file(orig, *type))) {
c171f097 968+ rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
fa26e11c
WD
969+ orig, str_acl_type(*type),
970+ strerror(errno));
971+ }
972+ }
973+ }
974+ }
975+}
976+
977+static int set_keep_backup_acl()
978+{
979+ if (preserve_acls) {
980+ SMB_ACL_TYPE_T *type,
981+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
982+ SMB_ACL_T *sacl;
983+ int ret = 0;
984+ for (type = &types[0], sacl = &_backup_sacl[0];
985+ type < &types[0] + sizeof types / sizeof types[0];
986+ type++) {
987+ if (*sacl) {
988+ if (-1 == sys_acl_set_file(backup_dest_fname,
989+ *type, *sacl))
990+ {
c171f097 991+ rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
fa26e11c
WD
992+ backup_dest_fname,
993+ str_acl_type(*type),
994+ strerror(errno));
995+ ret = -1;
996+ }
997+ }
998+ }
999+ return ret;
1000+ }
05b88206 1001+ return 1;
fa26e11c
WD
1002+}
1003+
1004+void cleanup_keep_backup_acl()
1005+{
1006+ if (preserve_acls) {
1007+ SMB_ACL_TYPE_T *type,
1008+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1009+ SMB_ACL_T *sacl;
1010+ backup_orig_file = NULL;
1011+ backup_orig_fname = null_string;
1012+ backup_dest_fname = null_string;
1013+ for (type = &types[0], sacl = &_backup_sacl[0];
1014+ type < &types[0] + sizeof types / sizeof types[0];
1015+ type++) {
1016+ if (*sacl)
1017+ sys_acl_free_acl(*sacl);
1018+ *sacl = NULL;
1019+ }
1020+ }
1021+}
1022+
1023+/* set ACL on rsync-ed or keep_backup-ed file */
1024+
1025+int set_acl(const char *fname, const struct file_struct *file)
1026+{
1027+ int updated = 0;
1028+ SMB_ACL_TYPE_T *type,
1029+ types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
1030+ if (dry_run || !preserve_acls || S_ISLNK(file->mode))
05b88206 1031+ return 1;
fa26e11c
WD
1032+ if (file == backup_orig_file) {
1033+ if (!strcmp(fname, backup_dest_fname))
1034+ return set_keep_backup_acl();
1035+ }
1036+ for (type = &types[0];
1037+ type < &types[0] + sizeof types / sizeof types[0]
1038+ && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
1039+ type++) {
1040+ SMB_ACL_T sacl_orig, *sacl_new;
1041+ rsync_acl racl_orig, *racl_new;
1042+ int aclidx = find_file_acl_index(file_acl_index_lists(*type),
1043+ file);
1044+ BOOL ok;
1045+ racl_new = &(rsync_acl_lists(*type)->racls[aclidx]);
1046+ sacl_new = &(smb_acl_lists(*type)->sacls[aclidx]);
1047+ sacl_orig = sys_acl_get_file(fname, *type);
1048+ if (!sacl_orig) {
1049+ rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
1050+ fname, str_acl_type(*type), strerror(errno));
1051+ updated = -1;
1052+ continue;
1053+ }
1054+ ok = unpack_smb_acl(&racl_orig, sacl_orig);
1055+ sys_acl_free_acl(sacl_orig);
1056+ if (!ok) {
1057+ updated = -1;
1058+ continue;
1059+ }
1060+ ok = rsync_acls_equal(&racl_orig, racl_new);
1061+ rsync_acl_free(&racl_orig);
1062+ if (ok)
1063+ continue;
1064+ if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
1065+ if (-1 == sys_acl_delete_def_file(fname)) {
1066+ rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
1067+ fname, strerror(errno));
1068+ updated = -1;
1069+ continue;
1070+ }
1071+ } else {
1072+ if (!*sacl_new)
1073+ if (!pack_smb_acl(sacl_new, racl_new)) {
1074+ updated = -1;
1075+ continue;
1076+ }
1077+ if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
1078+ rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
1079+ fname, str_acl_type(*type),
1080+ strerror(errno));
1081+ updated = -1;
1082+ continue;
1083+ }
1084+ }
1085+ if (!updated)
1086+ updated = 1;
1087+ }
1088+ return updated;
1089+}
1090+
4edb99c8 1091+/* Enumeration functions for uid mapping: */
fa26e11c 1092+
4edb99c8
WD
1093+/* Context -- one and only one. Should be cycled through once on uid
1094+ * mapping and once on gid mapping. */
fa26e11c
WD
1095+static rsync_acl_list *_enum_racl_lists[] = {
1096+ &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
1097+};
1098+
1099+static rsync_acl_list **enum_racl_list = &_enum_racl_lists[0];
1100+static size_t enum_racl_index = 0;
1101+static size_t enum_race_index = 0;
1102+
4edb99c8
WD
1103+/* This returns the next tag_type id from the given acl for the next entry,
1104+ * or it returns 0 if there are no more tag_type ids in the acl. */
fa26e11c
WD
1105+
1106+static id_t next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
1107+{
1108+ for (; enum_race_index < racl->count; enum_race_index++) {
1109+ rsync_ace *race = &racl->races[enum_race_index];
1110+ if (race->tag_type == tag_type)
1111+ return race->id;
1112+ }
1113+ enum_race_index = 0;
1114+ return 0;
1115+}
1116+
1117+static id_t next_acl_id(SMB_ACL_TAG_T tag_type, const rsync_acl_list *racl_list)
1118+{
1119+ for (; enum_racl_index < racl_list->count; enum_racl_index++) {
1120+ rsync_acl *racl = &racl_list->racls[enum_racl_index];
1121+ id_t id = next_ace_id(tag_type, racl);
1122+ if (id)
1123+ return id;
1124+ }
1125+ enum_racl_index = 0;
1126+ return 0;
1127+}
1128+
1129+static id_t next_acl_list_id(SMB_ACL_TAG_T tag_type)
1130+{
1131+ for (; *enum_racl_list; enum_racl_list++) {
1132+ id_t id = next_acl_id(tag_type, *enum_racl_list);
1133+ if (id)
1134+ return id;
1135+ }
1136+ enum_racl_list = &_enum_racl_lists[0];
1137+ return 0;
1138+}
1139+
1140+id_t next_acl_uid()
1141+{
1142+ return next_acl_list_id(SMB_ACL_USER);
1143+}
1144+
1145+id_t next_acl_gid()
1146+{
1147+ return next_acl_list_id(SMB_ACL_GROUP);
1148+}
1149+
1150+/* referring to the global context enum_entry, sets the entry's id */
1151+static void set_acl_id(id_t id)
1152+{
1153+ (*enum_racl_list)->racls[enum_racl_index].races[enum_race_index++].id = id;
1154+}
1155+
1156+void acl_uid_map(id_t uid)
1157+{
1158+ set_acl_id(uid);
1159+}
1160+
1161+void acl_gid_map(id_t gid)
1162+{
1163+ set_acl_id(gid);
1164+}
1165+
26c810d8 1166+#define PERMS_SPLICE(perms,newbits,where) (((perms) & ~(7 << (where))) | ((newbits) << (where)))
90fa6d68 1167+
26c810d8 1168+int default_perms_for_dir(const char *dir)
90fa6d68
WD
1169+{
1170+ rsync_acl racl;
1171+ SMB_ACL_T sacl;
1172+ BOOL ok, saw_mask = False;
90fa6d68 1173+ size_t i;
26c810d8 1174+ int perms;
90fa6d68
WD
1175+
1176+ if (dir == NULL)
1177+ dir = ".";
26c810d8 1178+ perms = ACCESSPERMS & ~orig_umask;
90fa6d68
WD
1179+ /* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
1180+ sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
1181+ if (sacl == NULL) {
1182+ /* Couldn't get an ACL. Darn. */
1183+ switch (errno) {
1184+ case ENOTSUP:
1185+ /* ACLs are disabled. We could yell at the user to turn them on, but... */
1186+ break;
1187+ case ENOENT:
1188+ if (dry_run) {
1189+ /* We're doing a dry run, so the containing directory
1190+ * wasn't actually created. Don't worry about it. */
1191+ break;
1192+ }
1193+ /* Otherwise fall through. */
1194+ default:
26c810d8 1195+ rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
90fa6d68
WD
1196+ dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
1197+ }
26c810d8 1198+ return perms;
90fa6d68
WD
1199+ }
1200+
1201+ /* Convert it. */
1202+ ok = unpack_smb_acl(&racl, sacl);
1203+ sys_acl_free_acl(sacl);
1204+ if (!ok) {
26c810d8
WD
1205+ rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
1206+ return perms;
90fa6d68
WD
1207+ }
1208+
26c810d8
WD
1209+ /* Look at each default ACL entry and possibly modify three bits of `perms' accordingly.
1210+ * If there's "no" default ACL, there will be zero entries and the umask-based perms is unchanged. */
90fa6d68
WD
1211+ for (i = 0; i < racl.count; i++) {
1212+ switch (racl.races[i].tag_type) {
1213+ case SMB_ACL_USER_OBJ:
26c810d8 1214+ perms = PERMS_SPLICE(perms, racl.races[i].access, 6);
90fa6d68
WD
1215+ break;
1216+ case SMB_ACL_GROUP_OBJ:
1217+ if (!saw_mask)
26c810d8 1218+ perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
90fa6d68
WD
1219+ break;
1220+ case SMB_ACL_MASK:
1221+ saw_mask = True;
26c810d8 1222+ perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
90fa6d68
WD
1223+ break;
1224+ case SMB_ACL_OTHER:
26c810d8 1225+ perms = PERMS_SPLICE(perms, racl.races[i].access, 0);
90fa6d68
WD
1226+ break;
1227+ default:
1228+ break;
1229+ }
1230+ }
1231+ rsync_acl_free(&racl);
1232+ if (verbose > 2)
26c810d8
WD
1233+ rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
1234+ return perms;
90fa6d68
WD
1235+}
1236+
fa26e11c 1237+#endif /* SUPPORT_ACLS */
9a7eef96
WD
1238--- old/backup.c
1239+++ new/backup.c
2578e2b6 1240@@ -132,6 +132,7 @@ static int make_bak_dir(char *fullpath)
fa26e11c
WD
1241 } else {
1242 do_lchown(fullpath, st.st_uid, st.st_gid);
1243 do_chmod(fullpath, st.st_mode);
1244+ (void)DUP_ACL(end, fullpath, st.st_mode);
1245 }
1246 }
1247 *p = '/';
2578e2b6 1248@@ -185,6 +186,8 @@ static int keep_backup(char *fname)
172ad6c3 1249 if (!(buf = get_backup_name(fname)))
fa26e11c 1250 return 0;
fa26e11c 1251
172ad6c3 1252+ PUSH_KEEP_BACKUP_ACL(file, fname, buf);
fa26e11c 1253+
fa26e11c 1254 /* Check to see if this is a device file, or link */
90fa6d68
WD
1255 if ((am_root && preserve_devices && IS_DEVICE(file->mode))
1256 || (preserve_specials && IS_SPECIAL(file->mode))) {
2578e2b6 1257@@ -260,6 +263,7 @@ static int keep_backup(char *fname)
fa26e11c
WD
1258 }
1259 }
90fa6d68 1260 set_file_attrs(buf, file, NULL, 0);
fa26e11c
WD
1261+ CLEANUP_KEEP_BACKUP_ACL();
1262 free(file);
1263
27a7053c 1264 if (verbose > 1) {
9a7eef96
WD
1265--- old/configure.in
1266+++ new/configure.in
afcb578c 1267@@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
fa26e11c
WD
1268 AC_CHECK_LIB(resolv, strcasecmp)
1269 fi
1270
1271+AC_CHECK_FUNCS(aclsort)
1272+if test x"$ac_cv_func_aclsort" = x"no"; then
1273+ AC_CHECK_LIB(sec, aclsort)
1274+fi
1275+
1276 dnl At the moment we don't test for a broken memcmp(), because all we
1277 dnl need to do is test for equality, not comparison, and it seems that
1278 dnl every platform has a memcmp that can do at least that.
afcb578c 1279@@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
fa26e11c
WD
1280 AC_SUBST(CC_SHOBJ_FLAG)
1281 AC_SUBST(BUILD_POPT)
125d7fca 1282
fa26e11c
WD
1283+AC_CHECK_HEADERS(sys/acl.h)
1284+AC_CHECK_FUNCS(_acl __acl _facl __facl)
1285+#################################################
1286+# check for ACL support
1287+
1288+AC_MSG_CHECKING(whether to support ACLs)
f787c90c
WD
1289+AC_ARG_ENABLE(acl-support,
1290+AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
3b05e91f 1291+[ case "$enableval" in
fa26e11c
WD
1292+ yes)
1293+
1294+ case "$host_os" in
1295+ *sysv5*)
1296+ AC_MSG_RESULT(Using UnixWare ACLs)
1297+ AC_DEFINE(HAVE_UNIXWARE_ACLS, 1, [true if you have UnixWare ACLs])
1298+ ;;
1299+ *solaris*)
1300+ AC_MSG_RESULT(Using solaris ACLs)
1301+ AC_DEFINE(HAVE_SOLARIS_ACLS, 1, [true if you have solaris ACLs])
1302+ ;;
1303+ *hpux*)
1304+ AC_MSG_RESULT(Using HPUX ACLs)
1305+ AC_DEFINE(HAVE_HPUX_ACLS, 1, [true if you have HPUX ACLs])
1306+ ;;
1307+ *irix*)
1308+ AC_MSG_RESULT(Using IRIX ACLs)
1309+ AC_DEFINE(HAVE_IRIX_ACLS, 1, [true if you have IRIX ACLs])
1310+ ;;
1311+ *aix*)
1312+ AC_MSG_RESULT(Using AIX ACLs)
1313+ AC_DEFINE(HAVE_AIX_ACLS, 1, [true if you have AIX ACLs])
1314+ ;;
1315+ *osf*)
1316+ AC_MSG_RESULT(Using Tru64 ACLs)
1317+ AC_DEFINE(HAVE_TRU64_ACLS, 1, [true if you have Tru64 ACLs])
1318+ LIBS="$LIBS -lpacl"
1319+ ;;
1320+ *)
81549708 1321+ AC_MSG_RESULT(ACLs requested -- running tests)
fa26e11c
WD
1322+ AC_CHECK_LIB(acl,acl_get_file)
1323+ AC_CACHE_CHECK([for ACL support],samba_cv_HAVE_POSIX_ACLS,[
1324+ AC_TRY_LINK([#include <sys/types.h>
1325+#include <sys/acl.h>],
1326+[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
1327+samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
1328+ if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
1329+ AC_MSG_RESULT(Using posix ACLs)
1330+ AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
81549708 1331+ AC_CACHE_CHECK([for acl_get_perm_np],samba_cv_HAVE_ACL_GET_PERM_NP,[
fa26e11c
WD
1332+ AC_TRY_LINK([#include <sys/types.h>
1333+#include <sys/acl.h>],
1334+[ acl_permset_t permset_d; acl_perm_t perm; return acl_get_perm_np( permset_d, perm);],
1335+samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_cv_HAVE_ACL_GET_PERM_NP=no)])
81549708
WD
1336+ if test x"$samba_cv_HAVE_ACL_GET_PERM_NP" = x"yes"; then
1337+ AC_DEFINE(HAVE_ACL_GET_PERM_NP, 1, [true if you have acl_get_perm_np])
1338+ fi
1339+ else
1340+ AC_MSG_ERROR(Failed to find ACL support)
fa26e11c
WD
1341+ fi
1342+ ;;
1343+ esac
1344+ ;;
1345+ *)
1346+ AC_MSG_RESULT(no)
1347+ AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1348+ ;;
1349+ esac ],
1350+ AC_DEFINE(HAVE_NO_ACLS, 1, [true if you don't have ACLs])
1351+ AC_MSG_RESULT(no)
1352+)
125d7fca 1353+
fa26e11c
WD
1354 AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
1355 AC_OUTPUT
125d7fca 1356
9a7eef96
WD
1357--- old/flist.c
1358+++ new/flist.c
2578e2b6 1359@@ -966,6 +966,8 @@ static struct file_struct *send_file_nam
e0e47893 1360 f == -2 ? SERVER_FILTERS : ALL_FILTERS);
09fb8f03 1361 if (!file)
5e048c14 1362 return NULL;
05b88206 1363+ if (MAKE_ACL(file, fname) < 0)
4df546eb 1364+ return NULL;
fa26e11c 1365
3b05e91f 1366 if (chmod_modes && !S_ISLNK(file->mode))
e0e47893 1367 file->mode = tweak_mode(file->mode, chmod_modes);
2578e2b6 1368@@ -977,6 +979,10 @@ static struct file_struct *send_file_nam
fa26e11c
WD
1369 if (file->basename[0]) {
1370 flist->files[flist->count++] = file;
e0e47893 1371 send_file_entry(file, f);
fa26e11c
WD
1372+ SEND_ACL(file, f);
1373+ } else {
1374+ /* Cleanup unsent ACL(s). */
1375+ SEND_ACL(file, -1);
1376 }
5e048c14
WD
1377 return file;
1378 }
2578e2b6 1379@@ -1365,6 +1371,8 @@ struct file_list *recv_file_list(int f)
fa26e11c 1380 flags |= read_byte(f) << 8;
618752a7 1381 file = receive_file_entry(flist, flags, f);
fa26e11c 1382
618752a7 1383+ RECEIVE_ACL(file, f);
fa26e11c 1384+
ae6834e1 1385 if (S_ISREG(file->mode) || S_ISLNK(file->mode))
618752a7 1386 stats.total_size += file->length;
fa26e11c 1387
2578e2b6 1388@@ -1387,6 +1395,8 @@ struct file_list *recv_file_list(int f)
fa26e11c
WD
1389
1390 clean_flist(flist, relative_paths, 1);
fa26e11c 1391
125d7fca
WD
1392+ SORT_FILE_ACL_INDEX_LISTS();
1393+
09fb8f03 1394 if (f >= 0) {
90fa6d68
WD
1395 recv_uid_list(f, flist);
1396
9a7eef96
WD
1397--- old/generator.c
1398+++ new/generator.c
2578e2b6 1399@@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
1a2fa68f
WD
1400 extern int max_delete;
1401 extern int force_delete;
1402 extern int one_file_system;
1403+extern mode_t orig_umask;
1404 extern struct stats stats;
1405 extern dev_t filesystem_dev;
1406 extern char *backup_dir;
2578e2b6 1407@@ -753,6 +754,7 @@ static int try_dests_non(struct file_str
26c810d8
WD
1408 }
1409
1410 static int phase = 0;
1411+static int dflt_perms;
1412
1413 /* Acts on the_file_list->file's ndx'th item, whose name is fname. If a dir,
1414 * make sure it exists, and has the right permissions/timestamp info. For
1a2fa68f 1415@@ -844,6 +846,10 @@ static void recv_generator(char *fname,
01deb4dc
WD
1416 }
1417 if (fuzzy_basis)
63673ef2 1418 need_fuzzy_dirlist = 1;
26c810d8 1419+#ifdef SUPPORT_ACLS
01deb4dc
WD
1420+ if (!preserve_perms)
1421+ dflt_perms = default_perms_for_dir(dn);
26c810d8 1422+#endif
26c810d8 1423 }
01deb4dc 1424 parent_dirname = dn;
26c810d8 1425
1a2fa68f 1426@@ -871,7 +877,8 @@ static void recv_generator(char *fname,
90fa6d68
WD
1427 if (!preserve_perms) {
1428 int exists = statret == 0
1429 && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
1430- file->mode = dest_mode(file->mode, st.st_mode, exists);
26c810d8
WD
1431+ file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
1432+ exists);
90fa6d68
WD
1433 }
1434
1435 if (S_ISDIR(file->mode)) {
1a2fa68f 1436@@ -905,6 +912,10 @@ static void recv_generator(char *fname,
90fa6d68 1437 if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
1d15f8d9 1438 && verbose && code && f_out != -1)
93ca4d27 1439 rprintf(code, "%s/\n", fname);
4df546eb 1440+#ifdef SUPPORT_ACLS
fa26e11c
WD
1441+ if (f_out == -1)
1442+ SET_ACL(fname, file);
1443+#endif
8f72c7ae 1444 if (delete_during && f_out != -1 && !phase && dry_run < 2
a7219d20 1445 && (file->flags & FLAG_DEL_HERE))
3b05e91f 1446 delete_in_dir(the_file_list, fname, file, &st);
1a2fa68f 1447@@ -1342,6 +1353,8 @@ void generate_files(int f_out, struct fi
26c810d8
WD
1448 * notice that and let us know via the redo pipe (or its closing). */
1449 ignore_timeout = 1;
1450
1451+ dflt_perms = (ACCESSPERMS & ~orig_umask);
1452+
1453 for (i = 0; i < flist->count; i++) {
1454 struct file_struct *file = flist->files[i];
1455
9a7eef96
WD
1456--- old/lib/sysacls.c
1457+++ new/lib/sysacls.c
252945ef 1458@@ -0,0 +1,3242 @@
fa26e11c 1459+/*
5ca9317d 1460+ Unix SMB/CIFS implementation.
0f6733d8
WD
1461+ Samba system utilities for ACL support.
1462+ Copyright (C) Jeremy Allison 2000.
fa26e11c
WD
1463+
1464+ This program is free software; you can redistribute it and/or modify
1465+ it under the terms of the GNU General Public License as published by
1466+ the Free Software Foundation; either version 2 of the License, or
1467+ (at your option) any later version.
1468+
1469+ This program is distributed in the hope that it will be useful,
1470+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1471+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1472+ GNU General Public License for more details.
1473+
1474+ You should have received a copy of the GNU General Public License
1475+ along with this program; if not, write to the Free Software
1476+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1477+*/
1478+
0f6733d8 1479+#include "rsync.h"
252945ef 1480+#include "sysacls.h" /****** ADDED ******/
fa26e11c 1481+
252945ef 1482+/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
0f6733d8
WD
1483+void SAFE_FREE(void *mem)
1484+{
1485+ if (mem)
1486+ free(mem);
1487+}
fa26e11c 1488+
5ca9317d
WD
1489+char *uidtoname(uid_t uid)
1490+{
1491+ static char idbuf[12];
1492+ struct passwd *pw;
1493+
1494+ if ((pw = getpwuid(uid)) == NULL) {
1495+ slprintf(idbuf, sizeof(idbuf)-1, "%ld", (long)uid);
1496+ return idbuf;
1497+ }
1498+ return pw->pw_name;
1499+}
252945ef 1500+/****** EXTRAS -- END ******/
5ca9317d 1501+
0f6733d8
WD
1502+/*
1503+ This file wraps all differing system ACL interfaces into a consistent
1504+ one based on the POSIX interface. It also returns the correct errors
1505+ for older UNIX systems that don't support ACLs.
fa26e11c 1506+
0f6733d8 1507+ The interfaces that each ACL implementation must support are as follows :
fa26e11c 1508+
0f6733d8
WD
1509+ int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
1510+ int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
1511+ int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
1512+ void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
1513+ SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
1514+ SMB_ACL_T sys_acl_get_fd(int fd)
1515+ int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
1516+ int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
1517+ char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
1518+ SMB_ACL_T sys_acl_init( int count)
1519+ int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1520+ int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
1521+ int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
1522+ int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
1523+ int sys_acl_valid( SMB_ACL_T theacl )
1524+ int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1525+ int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
1526+ int sys_acl_delete_def_file(const char *path)
fa26e11c 1527+
0f6733d8
WD
1528+ This next one is not POSIX complient - but we *have* to have it !
1529+ More POSIX braindamage.
fa26e11c 1530+
0f6733d8 1531+ int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
fa26e11c 1532+
0f6733d8
WD
1533+ The generic POSIX free is the following call. We split this into
1534+ several different free functions as we may need to add tag info
1535+ to structures when emulating the POSIX interface.
fa26e11c 1536+
0f6733d8 1537+ int sys_acl_free( void *obj_p)
fa26e11c 1538+
0f6733d8 1539+ The calls we actually use are :
fa26e11c 1540+
0f6733d8
WD
1541+ int sys_acl_free_text(char *text) - free acl_to_text
1542+ int sys_acl_free_acl(SMB_ACL_T posix_acl)
1543+ int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)
fa26e11c 1544+
0f6733d8 1545+*/
fa26e11c 1546+
0f6733d8 1547+#if defined(HAVE_POSIX_ACLS)
fa26e11c 1548+
0f6733d8 1549+/* Identity mapping - easy. */
fa26e11c 1550+
0f6733d8 1551+int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
fa26e11c 1552+{
0f6733d8 1553+ return acl_get_entry( the_acl, entry_id, entry_p);
fa26e11c
WD
1554+}
1555+
0f6733d8 1556+int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
fa26e11c 1557+{
0f6733d8 1558+ return acl_get_tag_type( entry_d, tag_type_p);
fa26e11c
WD
1559+}
1560+
0f6733d8 1561+int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
fa26e11c 1562+{
0f6733d8 1563+ return acl_get_permset( entry_d, permset_p);
fa26e11c
WD
1564+}
1565+
0f6733d8 1566+void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
fa26e11c 1567+{
0f6733d8 1568+ return acl_get_qualifier( entry_d);
fa26e11c
WD
1569+}
1570+
0f6733d8 1571+SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
fa26e11c 1572+{
0f6733d8 1573+ return acl_get_file( path_p, type);
fa26e11c
WD
1574+}
1575+
1576+SMB_ACL_T sys_acl_get_fd(int fd)
1577+{
1578+ return acl_get_fd(fd);
1579+}
1580+
1581+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
1582+{
1583+ return acl_clear_perms(permset);
1584+}
1585+
0f6733d8 1586+int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
fa26e11c
WD
1587+{
1588+ return acl_add_perm(permset, perm);
1589+}
1590+
0f6733d8 1591+int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
fa26e11c
WD
1592+{
1593+#if defined(HAVE_ACL_GET_PERM_NP)
0f6733d8
WD
1594+ /*
1595+ * Required for TrustedBSD-based ACL implementations where
fa26e11c 1596+ * non-POSIX.1e functions are denoted by a _np (non-portable)
0f6733d8
WD
1597+ * suffix.
1598+ */
fa26e11c
WD
1599+ return acl_get_perm_np(permset, perm);
1600+#else
1601+ return acl_get_perm(permset, perm);
1602+#endif
1603+}
1604+
0f6733d8 1605+char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
fa26e11c 1606+{
0f6733d8 1607+ return acl_to_text( the_acl, plen);
fa26e11c
WD
1608+}
1609+
0f6733d8 1610+SMB_ACL_T sys_acl_init( int count)
fa26e11c
WD
1611+{
1612+ return acl_init(count);
1613+}
1614+
0f6733d8 1615+int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
fa26e11c
WD
1616+{
1617+ return acl_create_entry(pacl, pentry);
1618+}
1619+
0f6733d8 1620+int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
fa26e11c
WD
1621+{
1622+ return acl_set_tag_type(entry, tagtype);
1623+}
1624+
0f6733d8 1625+int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
fa26e11c
WD
1626+{
1627+ return acl_set_qualifier(entry, qual);
1628+}
1629+
0f6733d8 1630+int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
fa26e11c
WD
1631+{
1632+ return acl_set_permset(entry, permset);
1633+}
1634+
0f6733d8 1635+int sys_acl_valid( SMB_ACL_T theacl )
fa26e11c
WD
1636+{
1637+ return acl_valid(theacl);
1638+}
1639+
1640+int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
1641+{
1642+ return acl_set_file(name, acltype, theacl);
1643+}
1644+
0f6733d8 1645+int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
fa26e11c
WD
1646+{
1647+ return acl_set_fd(fd, theacl);
1648+}
1649+
1650+int sys_acl_delete_def_file(const char *name)
1651+{
1652+ return acl_delete_def_file(name);
1653+}
1654+
1655+int sys_acl_free_text(char *text)
1656+{
1657+ return acl_free(text);
1658+}
1659+
0f6733d8 1660+int sys_acl_free_acl(SMB_ACL_T the_acl)
fa26e11c
WD
1661+{
1662+ return acl_free(the_acl);
1663+}
1664+
1f839b40 1665+int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
fa26e11c
WD
1666+{
1667+ return acl_free(qual);
1668+}
1669+
1670+#elif defined(HAVE_TRU64_ACLS)
0f6733d8
WD
1671+/*
1672+ * The interface to DEC/Compaq Tru64 UNIX ACLs
fa26e11c
WD
1673+ * is based on Draft 13 of the POSIX spec which is
1674+ * slightly different from the Draft 16 interface.
0f6733d8 1675+ *
fa26e11c
WD
1676+ * Also, some of the permset manipulation functions
1677+ * such as acl_clear_perm() and acl_add_perm() appear
1678+ * to be broken on Tru64 so we have to manipulate
0f6733d8
WD
1679+ * the permission bits in the permset directly.
1680+ */
1681+int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
fa26e11c 1682+{
0f6733d8 1683+ SMB_ACL_ENTRY_T entry;
fa26e11c
WD
1684+
1685+ if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {
1686+ return -1;
1687+ }
1688+
1689+ errno = 0;
1690+ if ((entry = acl_get_entry(the_acl)) != NULL) {
1691+ *entry_p = entry;
1692+ return 1;
1693+ }
1694+
1695+ return errno ? -1 : 0;
1696+}
1697+
0f6733d8 1698+int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
fa26e11c 1699+{
0f6733d8 1700+ return acl_get_tag_type( entry_d, tag_type_p);
fa26e11c
WD
1701+}
1702+
0f6733d8 1703+int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
fa26e11c 1704+{
0f6733d8 1705+ return acl_get_permset( entry_d, permset_p);
fa26e11c
WD
1706+}
1707+
0f6733d8 1708+void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
fa26e11c 1709+{
0f6733d8 1710+ return acl_get_qualifier( entry_d);
fa26e11c
WD
1711+}
1712+
0f6733d8 1713+SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
fa26e11c
WD
1714+{
1715+ return acl_get_file((char *)path_p, type);
1716+}
1717+
0f6733d8 1718+SMB_ACL_T sys_acl_get_fd(int fd)
fa26e11c
WD
1719+{
1720+ return acl_get_fd(fd, ACL_TYPE_ACCESS);
1721+}
1722+
0f6733d8 1723+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
fa26e11c 1724+{
0f6733d8 1725+ *permset = 0; /* acl_clear_perm() is broken on Tru64 */
fa26e11c
WD
1726+
1727+ return 0;
1728+}
1729+
0f6733d8 1730+int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
fa26e11c
WD
1731+{
1732+ if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {
1733+ errno = EINVAL;
1734+ return -1;
1735+ }
1736+
0f6733d8 1737+ *permset |= perm; /* acl_add_perm() is broken on Tru64 */
fa26e11c
WD
1738+
1739+ return 0;
1740+}
1741+
0f6733d8 1742+int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
fa26e11c
WD
1743+{
1744+ return *permset & perm; /* Tru64 doesn't have acl_get_perm() */
1745+}
1746+
0f6733d8 1747+char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
fa26e11c 1748+{
0f6733d8 1749+ return acl_to_text( the_acl, plen);
fa26e11c
WD
1750+}
1751+
0f6733d8 1752+SMB_ACL_T sys_acl_init( int count)
fa26e11c
WD
1753+{
1754+ return acl_init(count);
1755+}
1756+
0f6733d8 1757+int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
fa26e11c
WD
1758+{
1759+ SMB_ACL_ENTRY_T entry;
1760+
1761+ if ((entry = acl_create_entry(pacl)) == NULL) {
1762+ return -1;
1763+ }
1764+
1765+ *pentry = entry;
1766+ return 0;
1767+}
1768+
0f6733d8 1769+int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
fa26e11c
WD
1770+{
1771+ return acl_set_tag_type(entry, tagtype);
1772+}
1773+
0f6733d8 1774+int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
fa26e11c
WD
1775+{
1776+ return acl_set_qualifier(entry, qual);
1777+}
1778+
0f6733d8 1779+int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
fa26e11c
WD
1780+{
1781+ return acl_set_permset(entry, permset);
1782+}
1783+
0f6733d8 1784+int sys_acl_valid( SMB_ACL_T theacl )
fa26e11c 1785+{
0f6733d8 1786+ acl_entry_t entry;
fa26e11c
WD
1787+
1788+ return acl_valid(theacl, &entry);
1789+}
1790+
0f6733d8 1791+int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
fa26e11c
WD
1792+{
1793+ return acl_set_file((char *)name, acltype, theacl);
1794+}
1795+
0f6733d8 1796+int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
fa26e11c
WD
1797+{
1798+ return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);
1799+}
1800+
0f6733d8 1801+int sys_acl_delete_def_file(const char *name)
fa26e11c
WD
1802+{
1803+ return acl_delete_def_file((char *)name);
1804+}
1805+
0f6733d8 1806+int sys_acl_free_text(char *text)
fa26e11c 1807+{
0f6733d8
WD
1808+ /*
1809+ * (void) cast and explicit return 0 are for DEC UNIX
1810+ * which just #defines acl_free_text() to be free()
1811+ */
fa26e11c
WD
1812+ (void) acl_free_text(text);
1813+ return 0;
1814+}
1815+
0f6733d8 1816+int sys_acl_free_acl(SMB_ACL_T the_acl)
fa26e11c
WD
1817+{
1818+ return acl_free(the_acl);
1819+}
1820+
0f6733d8 1821+int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
fa26e11c
WD
1822+{
1823+ return acl_free_qualifier(qual, tagtype);
1824+}
1825+
1826+#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
1827+
0f6733d8
WD
1828+/*
1829+ * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
1830+ * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
1831+ */
fa26e11c 1832+
0f6733d8
WD
1833+/*
1834+ * Note that while this code implements sufficient functionality
fa26e11c
WD
1835+ * to support the sys_acl_* interfaces it does not provide all
1836+ * of the semantics of the POSIX ACL interfaces.
1837+ *
1838+ * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
1839+ * from a call to sys_acl_get_entry() should not be assumed to be
1840+ * valid after calling any of the following functions, which may
1841+ * reorder the entries in the ACL.
1842+ *
1843+ * sys_acl_valid()
1844+ * sys_acl_set_file()
1845+ * sys_acl_set_fd()
1846+ */
1847+
0f6733d8
WD
1848+/*
1849+ * The only difference between Solaris and UnixWare / OpenUNIX is
1850+ * that the #defines for the ACL operations have different names
1851+ */
fa26e11c
WD
1852+#if defined(HAVE_UNIXWARE_ACLS)
1853+
0f6733d8
WD
1854+#define SETACL ACL_SET
1855+#define GETACL ACL_GET
1856+#define GETACLCNT ACL_CNT
fa26e11c
WD
1857+
1858+#endif
1859+
1860+
0f6733d8 1861+int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
fa26e11c
WD
1862+{
1863+ if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
1864+ errno = EINVAL;
1865+ return -1;
1866+ }
1867+
1868+ if (entry_p == NULL) {
1869+ errno = EINVAL;
1870+ return -1;
1871+ }
1872+
1873+ if (entry_id == SMB_ACL_FIRST_ENTRY) {
1874+ acl_d->next = 0;
1875+ }
1876+
1877+ if (acl_d->next < 0) {
1878+ errno = EINVAL;
1879+ return -1;
1880+ }
1881+
1882+ if (acl_d->next >= acl_d->count) {
1883+ return 0;
1884+ }
1885+
1886+ *entry_p = &acl_d->acl[acl_d->next++];
1887+
1888+ return 1;
1889+}
1890+
0f6733d8 1891+int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
fa26e11c
WD
1892+{
1893+ *type_p = entry_d->a_type;
1894+
1895+ return 0;
1896+}
1897+
0f6733d8 1898+int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
fa26e11c
WD
1899+{
1900+ *permset_p = &entry_d->a_perm;
1901+
1902+ return 0;
1903+}
1904+
0f6733d8 1905+void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
fa26e11c
WD
1906+{
1907+ if (entry_d->a_type != SMB_ACL_USER
1908+ && entry_d->a_type != SMB_ACL_GROUP) {
1909+ errno = EINVAL;
1910+ return NULL;
1911+ }
1912+
1913+ return &entry_d->a_id;
1914+}
1915+
0f6733d8
WD
1916+/*
1917+ * There is no way of knowing what size the ACL returned by
fa26e11c
WD
1918+ * GETACL will be unless you first call GETACLCNT which means
1919+ * making an additional system call.
1920+ *
1921+ * In the hope of avoiding the cost of the additional system
1922+ * call in most cases, we initially allocate enough space for
1923+ * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
1924+ * be too small then we use GETACLCNT to find out the actual
0f6733d8
WD
1925+ * size, reallocate the ACL buffer, and then call GETACL again.
1926+ */
fa26e11c 1927+
0f6733d8 1928+#define INITIAL_ACL_SIZE 16
fa26e11c 1929+
0f6733d8 1930+SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
fa26e11c 1931+{
0f6733d8
WD
1932+ SMB_ACL_T acl_d;
1933+ int count; /* # of ACL entries allocated */
1934+ int naccess; /* # of access ACL entries */
1935+ int ndefault; /* # of default ACL entries */
fa26e11c
WD
1936+
1937+ if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
1938+ errno = EINVAL;
1939+ return NULL;
1940+ }
1941+
1942+ count = INITIAL_ACL_SIZE;
1943+ if ((acl_d = sys_acl_init(count)) == NULL) {
1944+ return NULL;
1945+ }
1946+
0f6733d8
WD
1947+ /*
1948+ * If there isn't enough space for the ACL entries we use
fa26e11c
WD
1949+ * GETACLCNT to determine the actual number of ACL entries
1950+ * reallocate and try again. This is in a loop because it
1951+ * is possible that someone else could modify the ACL and
1952+ * increase the number of entries between the call to
0f6733d8
WD
1953+ * GETACLCNT and the call to GETACL.
1954+ */
fa26e11c
WD
1955+ while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0
1956+ && errno == ENOSPC) {
1957+
1958+ sys_acl_free_acl(acl_d);
1959+
1960+ if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {
1961+ return NULL;
1962+ }
1963+
1964+ if ((acl_d = sys_acl_init(count)) == NULL) {
1965+ return NULL;
1966+ }
1967+ }
1968+
1969+ if (count < 0) {
1970+ sys_acl_free_acl(acl_d);
1971+ return NULL;
1972+ }
1973+
0f6733d8
WD
1974+ /*
1975+ * calculate the number of access and default ACL entries
fa26e11c
WD
1976+ *
1977+ * Note: we assume that the acl() system call returned a
1978+ * well formed ACL which is sorted so that all of the
0f6733d8
WD
1979+ * access ACL entries preceed any default ACL entries
1980+ */
fa26e11c
WD
1981+ for (naccess = 0; naccess < count; naccess++) {
1982+ if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
1983+ break;
1984+ }
1985+ ndefault = count - naccess;
0f6733d8
WD
1986+
1987+ /*
1988+ * if the caller wants the default ACL we have to copy
fa26e11c 1989+ * the entries down to the start of the acl[] buffer
0f6733d8
WD
1990+ * and mask out the ACL_DEFAULT flag from the type field
1991+ */
fa26e11c 1992+ if (type == SMB_ACL_TYPE_DEFAULT) {
0f6733d8 1993+ int i, j;
fa26e11c
WD
1994+
1995+ for (i = 0, j = naccess; i < ndefault; i++, j++) {
1996+ acl_d->acl[i] = acl_d->acl[j];
1997+ acl_d->acl[i].a_type &= ~ACL_DEFAULT;
1998+ }
1999+
2000+ acl_d->count = ndefault;
2001+ } else {
2002+ acl_d->count = naccess;
2003+ }
2004+
2005+ return acl_d;
2006+}
2007+
0f6733d8 2008+SMB_ACL_T sys_acl_get_fd(int fd)
fa26e11c 2009+{
0f6733d8
WD
2010+ SMB_ACL_T acl_d;
2011+ int count; /* # of ACL entries allocated */
2012+ int naccess; /* # of access ACL entries */
fa26e11c
WD
2013+
2014+ count = INITIAL_ACL_SIZE;
2015+ if ((acl_d = sys_acl_init(count)) == NULL) {
2016+ return NULL;
2017+ }
2018+
2019+ while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0
2020+ && errno == ENOSPC) {
2021+
2022+ sys_acl_free_acl(acl_d);
2023+
2024+ if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {
2025+ return NULL;
2026+ }
2027+
2028+ if ((acl_d = sys_acl_init(count)) == NULL) {
2029+ return NULL;
2030+ }
2031+ }
2032+
2033+ if (count < 0) {
2034+ sys_acl_free_acl(acl_d);
2035+ return NULL;
2036+ }
2037+
0f6733d8
WD
2038+ /*
2039+ * calculate the number of access ACL entries
2040+ */
fa26e11c
WD
2041+ for (naccess = 0; naccess < count; naccess++) {
2042+ if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2043+ break;
2044+ }
0f6733d8 2045+
fa26e11c
WD
2046+ acl_d->count = naccess;
2047+
2048+ return acl_d;
2049+}
2050+
0f6733d8 2051+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
fa26e11c
WD
2052+{
2053+ *permset_d = 0;
2054+
2055+ return 0;
2056+}
2057+
0f6733d8 2058+int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
fa26e11c
WD
2059+{
2060+ if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2061+ && perm != SMB_ACL_EXECUTE) {
2062+ errno = EINVAL;
2063+ return -1;
2064+ }
2065+
2066+ if (permset_d == NULL) {
2067+ errno = EINVAL;
2068+ return -1;
2069+ }
2070+
2071+ *permset_d |= perm;
2072+
2073+ return 0;
2074+}
2075+
0f6733d8 2076+int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
fa26e11c
WD
2077+{
2078+ return *permset_d & perm;
2079+}
2080+
0f6733d8 2081+char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
fa26e11c 2082+{
0f6733d8
WD
2083+ int i;
2084+ int len, maxlen;
2085+ char *text;
fa26e11c 2086+
0f6733d8
WD
2087+ /*
2088+ * use an initial estimate of 20 bytes per ACL entry
fa26e11c 2089+ * when allocating memory for the text representation
0f6733d8
WD
2090+ * of the ACL
2091+ */
2092+ len = 0;
2093+ maxlen = 20 * acl_d->count;
252945ef 2094+ if ((text = SMB_MALLOC(maxlen)) == NULL) {
fa26e11c
WD
2095+ errno = ENOMEM;
2096+ return NULL;
2097+ }
2098+
2099+ for (i = 0; i < acl_d->count; i++) {
0f6733d8
WD
2100+ struct acl *ap = &acl_d->acl[i];
2101+ struct passwd *pw;
2102+ struct group *gr;
2103+ char tagbuf[12];
2104+ char idbuf[12];
2105+ char *tag;
2106+ char *id = "";
2107+ char perms[4];
2108+ int nbytes;
fa26e11c
WD
2109+
2110+ switch (ap->a_type) {
0f6733d8
WD
2111+ /*
2112+ * for debugging purposes it's probably more
fa26e11c 2113+ * useful to dump unknown tag types rather
0f6733d8
WD
2114+ * than just returning an error
2115+ */
fa26e11c 2116+ default:
0f6733d8 2117+ slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
fa26e11c
WD
2118+ ap->a_type);
2119+ tag = tagbuf;
0f6733d8 2120+ slprintf(idbuf, sizeof(idbuf)-1, "%ld",
fa26e11c
WD
2121+ (long)ap->a_id);
2122+ id = idbuf;
2123+ break;
2124+
2125+ case SMB_ACL_USER:
5ca9317d 2126+ id = uidtoname(ap->a_id);
fa26e11c
WD
2127+ case SMB_ACL_USER_OBJ:
2128+ tag = "user";
2129+ break;
2130+
2131+ case SMB_ACL_GROUP:
2132+ if ((gr = getgrgid(ap->a_id)) == NULL) {
0f6733d8 2133+ slprintf(idbuf, sizeof(idbuf)-1, "%ld",
fa26e11c
WD
2134+ (long)ap->a_id);
2135+ id = idbuf;
2136+ } else {
2137+ id = gr->gr_name;
2138+ }
2139+ case SMB_ACL_GROUP_OBJ:
2140+ tag = "group";
2141+ break;
2142+
2143+ case SMB_ACL_OTHER:
2144+ tag = "other";
2145+ break;
2146+
2147+ case SMB_ACL_MASK:
2148+ tag = "mask";
2149+ break;
2150+
2151+ }
2152+
2153+ perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2154+ perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2155+ perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2156+ perms[3] = '\0';
2157+
2158+ /* <tag> : <qualifier> : rwx \n \0 */
2159+ nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2160+
0f6733d8
WD
2161+ /*
2162+ * If this entry would overflow the buffer
fa26e11c
WD
2163+ * allocate enough additional memory for this
2164+ * entry and an estimate of another 20 bytes
0f6733d8
WD
2165+ * for each entry still to be processed
2166+ */
fa26e11c
WD
2167+ if ((len + nbytes) > maxlen) {
2168+ char *oldtext = text;
2169+
2170+ maxlen += nbytes + 20 * (acl_d->count - i);
2171+
252945ef 2172+ if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
0f6733d8 2173+ SAFE_FREE(oldtext);
fa26e11c
WD
2174+ errno = ENOMEM;
2175+ return NULL;
2176+ }
2177+ }
2178+
0f6733d8 2179+ slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
fa26e11c
WD
2180+ len += nbytes - 1;
2181+ }
2182+
2183+ if (len_p)
2184+ *len_p = len;
2185+
2186+ return text;
2187+}
2188+
0f6733d8 2189+SMB_ACL_T sys_acl_init(int count)
fa26e11c 2190+{
0f6733d8 2191+ SMB_ACL_T a;
fa26e11c
WD
2192+
2193+ if (count < 0) {
2194+ errno = EINVAL;
2195+ return NULL;
2196+ }
2197+
0f6733d8
WD
2198+ /*
2199+ * note that since the definition of the structure pointed
fa26e11c
WD
2200+ * to by the SMB_ACL_T includes the first element of the
2201+ * acl[] array, this actually allocates an ACL with room
0f6733d8
WD
2202+ * for (count+1) entries
2203+ */
252945ef 2204+ if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
fa26e11c
WD
2205+ errno = ENOMEM;
2206+ return NULL;
2207+ }
2208+
2209+ a->size = count + 1;
2210+ a->count = 0;
2211+ a->next = -1;
2212+
2213+ return a;
2214+}
2215+
2216+
0f6733d8 2217+int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
fa26e11c 2218+{
0f6733d8
WD
2219+ SMB_ACL_T acl_d;
2220+ SMB_ACL_ENTRY_T entry_d;
fa26e11c
WD
2221+
2222+ if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2223+ errno = EINVAL;
2224+ return -1;
2225+ }
2226+
2227+ if (acl_d->count >= acl_d->size) {
2228+ errno = ENOSPC;
2229+ return -1;
2230+ }
2231+
0f6733d8
WD
2232+ entry_d = &acl_d->acl[acl_d->count++];
2233+ entry_d->a_type = 0;
2234+ entry_d->a_id = -1;
2235+ entry_d->a_perm = 0;
2236+ *entry_p = entry_d;
fa26e11c
WD
2237+
2238+ return 0;
2239+}
2240+
0f6733d8 2241+int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
fa26e11c
WD
2242+{
2243+ switch (tag_type) {
2244+ case SMB_ACL_USER:
2245+ case SMB_ACL_USER_OBJ:
2246+ case SMB_ACL_GROUP:
2247+ case SMB_ACL_GROUP_OBJ:
2248+ case SMB_ACL_OTHER:
2249+ case SMB_ACL_MASK:
2250+ entry_d->a_type = tag_type;
2251+ break;
2252+ default:
2253+ errno = EINVAL;
2254+ return -1;
2255+ }
2256+
2257+ return 0;
2258+}
2259+
0f6733d8 2260+int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
fa26e11c
WD
2261+{
2262+ if (entry_d->a_type != SMB_ACL_GROUP
2263+ && entry_d->a_type != SMB_ACL_USER) {
2264+ errno = EINVAL;
2265+ return -1;
2266+ }
2267+
2268+ entry_d->a_id = *((id_t *)qual_p);
2269+
2270+ return 0;
2271+}
2272+
0f6733d8 2273+int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
fa26e11c
WD
2274+{
2275+ if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2276+ return EINVAL;
2277+ }
2278+
2279+ entry_d->a_perm = *permset_d;
2280+
2281+ return 0;
2282+}
2283+
0f6733d8
WD
2284+/*
2285+ * sort the ACL and check it for validity
fa26e11c 2286+ *
0f6733d8 2287+ * if it's a minimal ACL with only 4 entries then we
fa26e11c
WD
2288+ * need to recalculate the mask permissions to make
2289+ * sure that they are the same as the GROUP_OBJ
2290+ * permissions as required by the UnixWare acl() system call.
2291+ *
0f6733d8 2292+ * (note: since POSIX allows minimal ACLs which only contain
fa26e11c
WD
2293+ * 3 entries - ie there is no mask entry - we should, in theory,
2294+ * check for this and add a mask entry if necessary - however
2295+ * we "know" that the caller of this interface always specifies
2296+ * a mask so, in practice "this never happens" (tm) - if it *does*
2297+ * happen aclsort() will fail and return an error and someone will
0f6733d8
WD
2298+ * have to fix it ...)
2299+ */
fa26e11c
WD
2300+
2301+static int acl_sort(SMB_ACL_T acl_d)
2302+{
2303+ int fixmask = (acl_d->count <= 4);
2304+
2305+ if (aclsort(acl_d->count, fixmask, acl_d->acl) != 0) {
2306+ errno = EINVAL;
2307+ return -1;
2308+ }
2309+ return 0;
2310+}
0f6733d8
WD
2311+
2312+int sys_acl_valid(SMB_ACL_T acl_d)
fa26e11c
WD
2313+{
2314+ return acl_sort(acl_d);
2315+}
2316+
0f6733d8 2317+int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
fa26e11c 2318+{
0f6733d8
WD
2319+ struct stat s;
2320+ struct acl *acl_p;
2321+ int acl_count;
2322+ struct acl *acl_buf = NULL;
2323+ int ret;
fa26e11c
WD
2324+
2325+ if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2326+ errno = EINVAL;
2327+ return -1;
2328+ }
2329+
2330+ if (acl_sort(acl_d) != 0) {
2331+ return -1;
2332+ }
2333+
0f6733d8
WD
2334+ acl_p = &acl_d->acl[0];
2335+ acl_count = acl_d->count;
fa26e11c 2336+
0f6733d8
WD
2337+ /*
2338+ * if it's a directory there is extra work to do
2339+ * since the acl() system call will replace both
2340+ * the access ACLs and the default ACLs (if any)
2341+ */
fa26e11c
WD
2342+ if (stat(name, &s) != 0) {
2343+ return -1;
2344+ }
2345+ if (S_ISDIR(s.st_mode)) {
0f6733d8
WD
2346+ SMB_ACL_T acc_acl;
2347+ SMB_ACL_T def_acl;
2348+ SMB_ACL_T tmp_acl;
2349+ int i;
fa26e11c
WD
2350+
2351+ if (type == SMB_ACL_TYPE_ACCESS) {
2352+ acc_acl = acl_d;
2353+ def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
2354+
2355+ } else {
2356+ def_acl = acl_d;
2357+ acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
2358+ }
2359+
2360+ if (tmp_acl == NULL) {
2361+ return -1;
2362+ }
2363+
0f6733d8
WD
2364+ /*
2365+ * allocate a temporary buffer for the complete ACL
2366+ */
fa26e11c 2367+ acl_count = acc_acl->count + def_acl->count;
252945ef 2368+ acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
fa26e11c
WD
2369+
2370+ if (acl_buf == NULL) {
2371+ sys_acl_free_acl(tmp_acl);
2372+ errno = ENOMEM;
2373+ return -1;
2374+ }
2375+
0f6733d8
WD
2376+ /*
2377+ * copy the access control and default entries into the buffer
2378+ */
fa26e11c 2379+ memcpy(&acl_buf[0], &acc_acl->acl[0],
0f6733d8 2380+ acc_acl->count * sizeof(acl_buf[0]));
fa26e11c
WD
2381+
2382+ memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
0f6733d8 2383+ def_acl->count * sizeof(acl_buf[0]));
fa26e11c 2384+
0f6733d8
WD
2385+ /*
2386+ * set the ACL_DEFAULT flag on the default entries
2387+ */
fa26e11c
WD
2388+ for (i = acc_acl->count; i < acl_count; i++) {
2389+ acl_buf[i].a_type |= ACL_DEFAULT;
2390+ }
2391+
2392+ sys_acl_free_acl(tmp_acl);
2393+
2394+ } else if (type != SMB_ACL_TYPE_ACCESS) {
2395+ errno = EINVAL;
2396+ return -1;
2397+ }
2398+
2399+ ret = acl(name, SETACL, acl_count, acl_p);
2400+
0f6733d8 2401+ SAFE_FREE(acl_buf);
fa26e11c
WD
2402+
2403+ return ret;
2404+}
2405+
0f6733d8 2406+int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
fa26e11c
WD
2407+{
2408+ if (acl_sort(acl_d) != 0) {
2409+ return -1;
2410+ }
2411+
2412+ return facl(fd, SETACL, acl_d->count, &acl_d->acl[0]);
2413+}
2414+
0f6733d8 2415+int sys_acl_delete_def_file(const char *path)
fa26e11c 2416+{
0f6733d8
WD
2417+ SMB_ACL_T acl_d;
2418+ int ret;
fa26e11c 2419+
0f6733d8
WD
2420+ /*
2421+ * fetching the access ACL and rewriting it has
2422+ * the effect of deleting the default ACL
2423+ */
fa26e11c
WD
2424+ if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
2425+ return -1;
2426+ }
2427+
2428+ ret = acl(path, SETACL, acl_d->count, acl_d->acl);
2429+
2430+ sys_acl_free_acl(acl_d);
0f6733d8 2431+
fa26e11c
WD
2432+ return ret;
2433+}
2434+
0f6733d8 2435+int sys_acl_free_text(char *text)
fa26e11c 2436+{
0f6733d8 2437+ SAFE_FREE(text);
fa26e11c
WD
2438+ return 0;
2439+}
2440+
0f6733d8 2441+int sys_acl_free_acl(SMB_ACL_T acl_d)
fa26e11c 2442+{
0f6733d8 2443+ SAFE_FREE(acl_d);
fa26e11c
WD
2444+ return 0;
2445+}
2446+
0f6733d8 2447+int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
fa26e11c
WD
2448+{
2449+ return 0;
2450+}
2451+
2452+#elif defined(HAVE_HPUX_ACLS)
2453+#include <dl.h>
2454+
0f6733d8
WD
2455+/*
2456+ * Based on the Solaris/SCO code - with modifications.
2457+ */
fa26e11c 2458+
0f6733d8
WD
2459+/*
2460+ * Note that while this code implements sufficient functionality
fa26e11c
WD
2461+ * to support the sys_acl_* interfaces it does not provide all
2462+ * of the semantics of the POSIX ACL interfaces.
2463+ *
2464+ * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned
2465+ * from a call to sys_acl_get_entry() should not be assumed to be
2466+ * valid after calling any of the following functions, which may
2467+ * reorder the entries in the ACL.
2468+ *
2469+ * sys_acl_valid()
2470+ * sys_acl_set_file()
2471+ * sys_acl_set_fd()
2472+ */
2473+
0f6733d8
WD
2474+/* This checks if the POSIX ACL system call is defined */
2475+/* which basically corresponds to whether JFS 3.3 or */
2476+/* higher is installed. If acl() was called when it */
2477+/* isn't defined, it causes the process to core dump */
2478+/* so it is important to check this and avoid acl() */
2479+/* calls if it isn't there. */
fa26e11c
WD
2480+
2481+static BOOL hpux_acl_call_presence(void)
2482+{
2483+
2484+ shl_t handle = NULL;
2485+ void *value;
2486+ int ret_val=0;
2487+ static BOOL already_checked=0;
2488+
0f6733d8 2489+ if(already_checked)
fa26e11c
WD
2490+ return True;
2491+
2492+
2493+ ret_val = shl_findsym(&handle, "acl", TYPE_PROCEDURE, &value);
2494+
0f6733d8 2495+ if(ret_val != 0) {
fa26e11c
WD
2496+ DEBUG(5, ("hpux_acl_call_presence: shl_findsym() returned %d, errno = %d, error %s\n",
2497+ ret_val, errno, strerror(errno)));
2498+ DEBUG(5,("hpux_acl_call_presence: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
2499+ return False;
2500+ }
2501+
2502+ DEBUG(10,("hpux_acl_call_presence: acl() system call is present. We have JFS 3.3 or above \n"));
2503+
2504+ already_checked = True;
2505+ return True;
2506+}
2507+
0f6733d8 2508+int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
fa26e11c
WD
2509+{
2510+ if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
2511+ errno = EINVAL;
2512+ return -1;
2513+ }
2514+
2515+ if (entry_p == NULL) {
2516+ errno = EINVAL;
2517+ return -1;
2518+ }
2519+
2520+ if (entry_id == SMB_ACL_FIRST_ENTRY) {
2521+ acl_d->next = 0;
2522+ }
2523+
2524+ if (acl_d->next < 0) {
2525+ errno = EINVAL;
2526+ return -1;
2527+ }
2528+
2529+ if (acl_d->next >= acl_d->count) {
2530+ return 0;
2531+ }
2532+
2533+ *entry_p = &acl_d->acl[acl_d->next++];
2534+
2535+ return 1;
2536+}
2537+
0f6733d8 2538+int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
fa26e11c
WD
2539+{
2540+ *type_p = entry_d->a_type;
2541+
2542+ return 0;
2543+}
2544+
0f6733d8 2545+int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
fa26e11c
WD
2546+{
2547+ *permset_p = &entry_d->a_perm;
2548+
2549+ return 0;
2550+}
2551+
0f6733d8 2552+void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
fa26e11c
WD
2553+{
2554+ if (entry_d->a_type != SMB_ACL_USER
2555+ && entry_d->a_type != SMB_ACL_GROUP) {
2556+ errno = EINVAL;
2557+ return NULL;
2558+ }
2559+
2560+ return &entry_d->a_id;
2561+}
2562+
0f6733d8
WD
2563+/*
2564+ * There is no way of knowing what size the ACL returned by
fa26e11c
WD
2565+ * ACL_GET will be unless you first call ACL_CNT which means
2566+ * making an additional system call.
2567+ *
2568+ * In the hope of avoiding the cost of the additional system
2569+ * call in most cases, we initially allocate enough space for
2570+ * an ACL with INITIAL_ACL_SIZE entries. If this turns out to
2571+ * be too small then we use ACL_CNT to find out the actual
2572+ * size, reallocate the ACL buffer, and then call ACL_GET again.
2573+ */
2574+
0f6733d8 2575+#define INITIAL_ACL_SIZE 16
fa26e11c 2576+
0f6733d8 2577+SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
fa26e11c 2578+{
0f6733d8
WD
2579+ SMB_ACL_T acl_d;
2580+ int count; /* # of ACL entries allocated */
2581+ int naccess; /* # of access ACL entries */
2582+ int ndefault; /* # of default ACL entries */
fa26e11c 2583+
0f6733d8
WD
2584+ if(hpux_acl_call_presence() == False) {
2585+ /* Looks like we don't have the acl() system call on HPUX.
2586+ * May be the system doesn't have the latest version of JFS.
2587+ */
2588+ return NULL;
fa26e11c
WD
2589+ }
2590+
2591+ if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
2592+ errno = EINVAL;
2593+ return NULL;
2594+ }
2595+
2596+ count = INITIAL_ACL_SIZE;
2597+ if ((acl_d = sys_acl_init(count)) == NULL) {
2598+ return NULL;
2599+ }
2600+
0f6733d8
WD
2601+ /*
2602+ * If there isn't enough space for the ACL entries we use
fa26e11c
WD
2603+ * ACL_CNT to determine the actual number of ACL entries
2604+ * reallocate and try again. This is in a loop because it
2605+ * is possible that someone else could modify the ACL and
2606+ * increase the number of entries between the call to
0f6733d8
WD
2607+ * ACL_CNT and the call to ACL_GET.
2608+ */
fa26e11c
WD
2609+ while ((count = acl(path_p, ACL_GET, count, &acl_d->acl[0])) < 0 && errno == ENOSPC) {
2610+
2611+ sys_acl_free_acl(acl_d);
2612+
2613+ if ((count = acl(path_p, ACL_CNT, 0, NULL)) < 0) {
2614+ return NULL;
2615+ }
2616+
2617+ if ((acl_d = sys_acl_init(count)) == NULL) {
2618+ return NULL;
2619+ }
2620+ }
2621+
2622+ if (count < 0) {
2623+ sys_acl_free_acl(acl_d);
2624+ return NULL;
2625+ }
2626+
0f6733d8
WD
2627+ /*
2628+ * calculate the number of access and default ACL entries
fa26e11c
WD
2629+ *
2630+ * Note: we assume that the acl() system call returned a
2631+ * well formed ACL which is sorted so that all of the
0f6733d8
WD
2632+ * access ACL entries preceed any default ACL entries
2633+ */
fa26e11c
WD
2634+ for (naccess = 0; naccess < count; naccess++) {
2635+ if (acl_d->acl[naccess].a_type & ACL_DEFAULT)
2636+ break;
2637+ }
2638+ ndefault = count - naccess;
0f6733d8
WD
2639+
2640+ /*
2641+ * if the caller wants the default ACL we have to copy
fa26e11c 2642+ * the entries down to the start of the acl[] buffer
0f6733d8
WD
2643+ * and mask out the ACL_DEFAULT flag from the type field
2644+ */
fa26e11c 2645+ if (type == SMB_ACL_TYPE_DEFAULT) {
0f6733d8 2646+ int i, j;
fa26e11c
WD
2647+
2648+ for (i = 0, j = naccess; i < ndefault; i++, j++) {
2649+ acl_d->acl[i] = acl_d->acl[j];
2650+ acl_d->acl[i].a_type &= ~ACL_DEFAULT;
2651+ }
2652+
2653+ acl_d->count = ndefault;
2654+ } else {
2655+ acl_d->count = naccess;
2656+ }
2657+
2658+ return acl_d;
2659+}
2660+
0f6733d8 2661+SMB_ACL_T sys_acl_get_fd(int fd)
fa26e11c 2662+{
0f6733d8
WD
2663+ /*
2664+ * HPUX doesn't have the facl call. Fake it using the path.... JRA.
2665+ */
fa26e11c
WD
2666+
2667+ files_struct *fsp = file_find_fd(fd);
2668+
2669+ if (fsp == NULL) {
2670+ errno = EBADF;
2671+ return NULL;
2672+ }
2673+
0f6733d8
WD
2674+ /*
2675+ * We know we're in the same conn context. So we
2676+ * can use the relative path.
2677+ */
fa26e11c 2678+
5ca9317d 2679+ return sys_acl_get_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS);
fa26e11c
WD
2680+}
2681+
0f6733d8 2682+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
fa26e11c
WD
2683+{
2684+ *permset_d = 0;
2685+
2686+ return 0;
2687+}
2688+
0f6733d8 2689+int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
fa26e11c
WD
2690+{
2691+ if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
2692+ && perm != SMB_ACL_EXECUTE) {
2693+ errno = EINVAL;
2694+ return -1;
2695+ }
2696+
2697+ if (permset_d == NULL) {
2698+ errno = EINVAL;
2699+ return -1;
2700+ }
2701+
2702+ *permset_d |= perm;
2703+
2704+ return 0;
2705+}
2706+
0f6733d8 2707+int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
fa26e11c
WD
2708+{
2709+ return *permset_d & perm;
2710+}
2711+
0f6733d8 2712+char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
fa26e11c 2713+{
0f6733d8
WD
2714+ int i;
2715+ int len, maxlen;
2716+ char *text;
fa26e11c 2717+
0f6733d8
WD
2718+ /*
2719+ * use an initial estimate of 20 bytes per ACL entry
2720+ * when allocating memory for the text representation
2721+ * of the ACL
2722+ */
2723+ len = 0;
2724+ maxlen = 20 * acl_d->count;
252945ef 2725+ if ((text = SMB_MALLOC(maxlen)) == NULL) {
fa26e11c
WD
2726+ errno = ENOMEM;
2727+ return NULL;
2728+ }
2729+
2730+ for (i = 0; i < acl_d->count; i++) {
0f6733d8
WD
2731+ struct acl *ap = &acl_d->acl[i];
2732+ struct passwd *pw;
2733+ struct group *gr;
2734+ char tagbuf[12];
2735+ char idbuf[12];
2736+ char *tag;
2737+ char *id = "";
2738+ char perms[4];
2739+ int nbytes;
fa26e11c
WD
2740+
2741+ switch (ap->a_type) {
0f6733d8
WD
2742+ /*
2743+ * for debugging purposes it's probably more
fa26e11c 2744+ * useful to dump unknown tag types rather
0f6733d8
WD
2745+ * than just returning an error
2746+ */
fa26e11c 2747+ default:
0f6733d8 2748+ slprintf(tagbuf, sizeof(tagbuf)-1, "0x%x",
fa26e11c
WD
2749+ ap->a_type);
2750+ tag = tagbuf;
0f6733d8 2751+ slprintf(idbuf, sizeof(idbuf)-1, "%ld",
fa26e11c
WD
2752+ (long)ap->a_id);
2753+ id = idbuf;
2754+ break;
2755+
2756+ case SMB_ACL_USER:
5ca9317d 2757+ id = uidtoname(ap->a_id);
fa26e11c
WD
2758+ case SMB_ACL_USER_OBJ:
2759+ tag = "user";
2760+ break;
2761+
2762+ case SMB_ACL_GROUP:
2763+ if ((gr = getgrgid(ap->a_id)) == NULL) {
0f6733d8 2764+ slprintf(idbuf, sizeof(idbuf)-1, "%ld",
fa26e11c
WD
2765+ (long)ap->a_id);
2766+ id = idbuf;
2767+ } else {
2768+ id = gr->gr_name;
2769+ }
2770+ case SMB_ACL_GROUP_OBJ:
2771+ tag = "group";
2772+ break;
2773+
2774+ case SMB_ACL_OTHER:
2775+ tag = "other";
2776+ break;
2777+
2778+ case SMB_ACL_MASK:
2779+ tag = "mask";
2780+ break;
2781+
2782+ }
2783+
2784+ perms[0] = (ap->a_perm & SMB_ACL_READ) ? 'r' : '-';
2785+ perms[1] = (ap->a_perm & SMB_ACL_WRITE) ? 'w' : '-';
2786+ perms[2] = (ap->a_perm & SMB_ACL_EXECUTE) ? 'x' : '-';
2787+ perms[3] = '\0';
2788+
2789+ /* <tag> : <qualifier> : rwx \n \0 */
2790+ nbytes = strlen(tag) + 1 + strlen(id) + 1 + 3 + 1 + 1;
2791+
0f6733d8
WD
2792+ /*
2793+ * If this entry would overflow the buffer
fa26e11c
WD
2794+ * allocate enough additional memory for this
2795+ * entry and an estimate of another 20 bytes
0f6733d8
WD
2796+ * for each entry still to be processed
2797+ */
fa26e11c
WD
2798+ if ((len + nbytes) > maxlen) {
2799+ char *oldtext = text;
2800+
2801+ maxlen += nbytes + 20 * (acl_d->count - i);
2802+
252945ef 2803+ if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
fa26e11c
WD
2804+ free(oldtext);
2805+ errno = ENOMEM;
2806+ return NULL;
2807+ }
2808+ }
2809+
0f6733d8 2810+ slprintf(&text[len], nbytes-1, "%s:%s:%s\n", tag, id, perms);
fa26e11c
WD
2811+ len += nbytes - 1;
2812+ }
2813+
2814+ if (len_p)
2815+ *len_p = len;
2816+
2817+ return text;
2818+}
2819+
0f6733d8 2820+SMB_ACL_T sys_acl_init(int count)
fa26e11c 2821+{
0f6733d8 2822+ SMB_ACL_T a;
fa26e11c
WD
2823+
2824+ if (count < 0) {
2825+ errno = EINVAL;
2826+ return NULL;
2827+ }
2828+
0f6733d8
WD
2829+ /*
2830+ * note that since the definition of the structure pointed
fa26e11c
WD
2831+ * to by the SMB_ACL_T includes the first element of the
2832+ * acl[] array, this actually allocates an ACL with room
0f6733d8
WD
2833+ * for (count+1) entries
2834+ */
252945ef 2835+ if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
fa26e11c
WD
2836+ errno = ENOMEM;
2837+ return NULL;
2838+ }
2839+
2840+ a->size = count + 1;
2841+ a->count = 0;
2842+ a->next = -1;
2843+
2844+ return a;
2845+}
2846+
2847+
0f6733d8 2848+int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
fa26e11c 2849+{
0f6733d8
WD
2850+ SMB_ACL_T acl_d;
2851+ SMB_ACL_ENTRY_T entry_d;
fa26e11c
WD
2852+
2853+ if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
2854+ errno = EINVAL;
2855+ return -1;
2856+ }
2857+
2858+ if (acl_d->count >= acl_d->size) {
2859+ errno = ENOSPC;
2860+ return -1;
2861+ }
2862+
0f6733d8
WD
2863+ entry_d = &acl_d->acl[acl_d->count++];
2864+ entry_d->a_type = 0;
2865+ entry_d->a_id = -1;
2866+ entry_d->a_perm = 0;
2867+ *entry_p = entry_d;
fa26e11c
WD
2868+
2869+ return 0;
2870+}
2871+
0f6733d8 2872+int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
fa26e11c
WD
2873+{
2874+ switch (tag_type) {
2875+ case SMB_ACL_USER:
2876+ case SMB_ACL_USER_OBJ:
2877+ case SMB_ACL_GROUP:
2878+ case SMB_ACL_GROUP_OBJ:
2879+ case SMB_ACL_OTHER:
2880+ case SMB_ACL_MASK:
2881+ entry_d->a_type = tag_type;
2882+ break;
2883+ default:
2884+ errno = EINVAL;
2885+ return -1;
2886+ }
2887+
2888+ return 0;
2889+}
2890+
0f6733d8 2891+int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
fa26e11c
WD
2892+{
2893+ if (entry_d->a_type != SMB_ACL_GROUP
2894+ && entry_d->a_type != SMB_ACL_USER) {
2895+ errno = EINVAL;
2896+ return -1;
2897+ }
2898+
2899+ entry_d->a_id = *((id_t *)qual_p);
2900+
2901+ return 0;
2902+}
2903+
0f6733d8 2904+int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
fa26e11c
WD
2905+{
2906+ if (*permset_d & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
2907+ return EINVAL;
2908+ }
2909+
2910+ entry_d->a_perm = *permset_d;
2911+
2912+ return 0;
2913+}
2914+
2915+/* Structure to capture the count for each type of ACE. */
2916+
2917+struct hpux_acl_types {
2918+ int n_user;
2919+ int n_def_user;
2920+ int n_user_obj;
2921+ int n_def_user_obj;
2922+
2923+ int n_group;
2924+ int n_def_group;
2925+ int n_group_obj;
2926+ int n_def_group_obj;
2927+
2928+ int n_other;
2929+ int n_other_obj;
2930+ int n_def_other_obj;
2931+
2932+ int n_class_obj;
2933+ int n_def_class_obj;
2934+
2935+ int n_illegal_obj;
2936+};
2937+
2938+/* count_obj:
2939+ * Counts the different number of objects in a given array of ACL
2940+ * structures.
2941+ * Inputs:
2942+ *
2943+ * acl_count - Count of ACLs in the array of ACL strucutres.
2944+ * aclp - Array of ACL structures.
2945+ * acl_type_count - Pointer to acl_types structure. Should already be
2946+ * allocated.
0f6733d8 2947+ * Output:
fa26e11c 2948+ *
0f6733d8 2949+ * acl_type_count - This structure is filled up with counts of various
fa26e11c
WD
2950+ * acl types.
2951+ */
2952+
2953+static int hpux_count_obj(int acl_count, struct acl *aclp, struct hpux_acl_types *acl_type_count)
2954+{
2955+ int i;
2956+
0f6733d8 2957+ memset(acl_type_count, 0, sizeof(struct hpux_acl_types));
fa26e11c 2958+
0f6733d8
WD
2959+ for(i=0;i<acl_count;i++) {
2960+ switch(aclp[i].a_type) {
2961+ case USER:
fa26e11c
WD
2962+ acl_type_count->n_user++;
2963+ break;
0f6733d8 2964+ case USER_OBJ:
fa26e11c
WD
2965+ acl_type_count->n_user_obj++;
2966+ break;
0f6733d8 2967+ case DEF_USER_OBJ:
fa26e11c
WD
2968+ acl_type_count->n_def_user_obj++;
2969+ break;
0f6733d8 2970+ case GROUP:
fa26e11c
WD
2971+ acl_type_count->n_group++;
2972+ break;
0f6733d8 2973+ case GROUP_OBJ:
fa26e11c
WD
2974+ acl_type_count->n_group_obj++;
2975+ break;
0f6733d8 2976+ case DEF_GROUP_OBJ:
fa26e11c
WD
2977+ acl_type_count->n_def_group_obj++;
2978+ break;
0f6733d8 2979+ case OTHER_OBJ:
fa26e11c
WD
2980+ acl_type_count->n_other_obj++;
2981+ break;
0f6733d8 2982+ case DEF_OTHER_OBJ:
fa26e11c
WD
2983+ acl_type_count->n_def_other_obj++;
2984+ break;
2985+ case CLASS_OBJ:
2986+ acl_type_count->n_class_obj++;
2987+ break;
2988+ case DEF_CLASS_OBJ:
2989+ acl_type_count->n_def_class_obj++;
2990+ break;
2991+ case DEF_USER:
2992+ acl_type_count->n_def_user++;
2993+ break;
2994+ case DEF_GROUP:
2995+ acl_type_count->n_def_group++;
2996+ break;
0f6733d8 2997+ default:
fa26e11c
WD
2998+ acl_type_count->n_illegal_obj++;
2999+ break;
3000+ }
3001+ }
3002+}
3003+
0f6733d8 3004+/* swap_acl_entries: Swaps two ACL entries.
fa26e11c
WD
3005+ *
3006+ * Inputs: aclp0, aclp1 - ACL entries to be swapped.
3007+ */
3008+
3009+static void hpux_swap_acl_entries(struct acl *aclp0, struct acl *aclp1)
3010+{
3011+ struct acl temp_acl;
3012+
3013+ temp_acl.a_type = aclp0->a_type;
3014+ temp_acl.a_id = aclp0->a_id;
3015+ temp_acl.a_perm = aclp0->a_perm;
3016+
3017+ aclp0->a_type = aclp1->a_type;
3018+ aclp0->a_id = aclp1->a_id;
3019+ aclp0->a_perm = aclp1->a_perm;
3020+
3021+ aclp1->a_type = temp_acl.a_type;
3022+ aclp1->a_id = temp_acl.a_id;
3023+ aclp1->a_perm = temp_acl.a_perm;
3024+}
3025+
3026+/* prohibited_duplicate_type
0f6733d8 3027+ * Identifies if given ACL type can have duplicate entries or
fa26e11c
WD
3028+ * not.
3029+ *
3030+ * Inputs: acl_type - ACL Type.
3031+ *
0f6733d8 3032+ * Outputs:
fa26e11c 3033+ *
0f6733d8 3034+ * Return..
fa26e11c
WD
3035+ *
3036+ * True - If the ACL type matches any of the prohibited types.
3037+ * False - If the ACL type doesn't match any of the prohibited types.
0f6733d8 3038+ */
fa26e11c
WD
3039+
3040+static BOOL hpux_prohibited_duplicate_type(int acl_type)
3041+{
0f6733d8 3042+ switch(acl_type) {
fa26e11c
WD
3043+ case USER:
3044+ case GROUP:
0f6733d8 3045+ case DEF_USER:
fa26e11c
WD
3046+ case DEF_GROUP:
3047+ return True;
0f6733d8
WD
3048+ default:
3049+ return False;
fa26e11c 3050+ }
fa26e11c
WD
3051+}
3052+
3053+/* get_needed_class_perm
3054+ * Returns the permissions of a ACL structure only if the ACL
0f6733d8 3055+ * type matches one of the pre-determined types for computing
fa26e11c
WD
3056+ * CLASS_OBJ permissions.
3057+ *
3058+ * Inputs: aclp - Pointer to ACL structure.
3059+ */
3060+
3061+static int hpux_get_needed_class_perm(struct acl *aclp)
3062+{
0f6733d8
WD
3063+ switch(aclp->a_type) {
3064+ case USER:
3065+ case GROUP_OBJ:
3066+ case GROUP:
3067+ case DEF_USER_OBJ:
fa26e11c 3068+ case DEF_USER:
0f6733d8 3069+ case DEF_GROUP_OBJ:
fa26e11c
WD
3070+ case DEF_GROUP:
3071+ case DEF_CLASS_OBJ:
0f6733d8 3072+ case DEF_OTHER_OBJ:
fa26e11c 3073+ return aclp->a_perm;
0f6733d8 3074+ default:
fa26e11c
WD
3075+ return 0;
3076+ }
3077+}
3078+
3079+/* acl_sort for HPUX.
3080+ * Sorts the array of ACL structures as per the description in
3081+ * aclsort man page. Refer to aclsort man page for more details
3082+ *
3083+ * Inputs:
3084+ *
3085+ * acl_count - Count of ACLs in the array of ACL structures.
3086+ * calclass - If this is not zero, then we compute the CLASS_OBJ
3087+ * permissions.
3088+ * aclp - Array of ACL structures.
3089+ *
3090+ * Outputs:
3091+ *
3092+ * aclp - Sorted array of ACL structures.
3093+ *
3094+ * Outputs:
3095+ *
3096+ * Returns 0 for success -1 for failure. Prints a message to the Samba
3097+ * debug log in case of failure.
3098+ */
3099+
3100+static int hpux_acl_sort(int acl_count, int calclass, struct acl *aclp)
3101+{
3102+#if !defined(HAVE_HPUX_ACLSORT)
0f6733d8
WD
3103+ /*
3104+ * The aclsort() system call is availabe on the latest HPUX General
3105+ * Patch Bundles. So for HPUX, we developed our version of acl_sort
3106+ * function. Because, we don't want to update to a new
3107+ * HPUX GR bundle just for aclsort() call.
3108+ */
fa26e11c
WD
3109+
3110+ struct hpux_acl_types acl_obj_count;
3111+ int n_class_obj_perm = 0;
3112+ int i, j;
0f6733d8
WD
3113+
3114+ if(!acl_count) {
fa26e11c
WD
3115+ DEBUG(10,("Zero acl count passed. Returning Success\n"));
3116+ return 0;
3117+ }
3118+
0f6733d8 3119+ if(aclp == NULL) {
fa26e11c
WD
3120+ DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
3121+ return -1;
3122+ }
3123+
3124+ /* Count different types of ACLs in the ACLs array */
3125+
3126+ hpux_count_obj(acl_count, aclp, &acl_obj_count);
3127+
0f6733d8
WD
3128+ /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
3129+ * CLASS_OBJ and OTHER_OBJ
fa26e11c
WD
3130+ */
3131+
0f6733d8
WD
3132+ if( (acl_obj_count.n_user_obj != 1) ||
3133+ (acl_obj_count.n_group_obj != 1) ||
3134+ (acl_obj_count.n_class_obj != 1) ||
3135+ (acl_obj_count.n_other_obj != 1)
3136+ ) {
fa26e11c
WD
3137+ DEBUG(0,("hpux_acl_sort: More than one entry or no entries for \
3138+USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
3139+ return -1;
3140+ }
3141+
3142+ /* If any of the default objects are present, there should be only
3143+ * one of them each.
3144+ */
3145+
0f6733d8
WD
3146+ if( (acl_obj_count.n_def_user_obj > 1) || (acl_obj_count.n_def_group_obj > 1) ||
3147+ (acl_obj_count.n_def_other_obj > 1) || (acl_obj_count.n_def_class_obj > 1) ) {
fa26e11c
WD
3148+ DEBUG(0,("hpux_acl_sort: More than one entry for DEF_CLASS_OBJ \
3149+or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
3150+ return -1;
3151+ }
3152+
0f6733d8
WD
3153+ /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
3154+ * structures.
fa26e11c
WD
3155+ *
3156+ * Sorting crieteria - First sort by ACL type. If there are multiple entries of
3157+ * same ACL type, sort by ACL id.
3158+ *
0f6733d8 3159+ * I am using the trival kind of sorting method here because, performance isn't
fa26e11c 3160+ * really effected by the ACLs feature. More over there aren't going to be more
0f6733d8 3161+ * than 17 entries on HPUX.
fa26e11c
WD
3162+ */
3163+
0f6733d8 3164+ for(i=0; i<acl_count;i++) {
fa26e11c 3165+ for (j=i+1; j<acl_count; j++) {
0f6733d8 3166+ if( aclp[i].a_type > aclp[j].a_type ) {
fa26e11c
WD
3167+ /* ACL entries out of order, swap them */
3168+
3169+ hpux_swap_acl_entries((aclp+i), (aclp+j));
3170+
0f6733d8 3171+ } else if ( aclp[i].a_type == aclp[j].a_type ) {
fa26e11c
WD
3172+
3173+ /* ACL entries of same type, sort by id */
3174+
0f6733d8 3175+ if(aclp[i].a_id > aclp[j].a_id) {
fa26e11c
WD
3176+ hpux_swap_acl_entries((aclp+i), (aclp+j));
3177+ } else if (aclp[i].a_id == aclp[j].a_id) {
3178+ /* We have a duplicate entry. */
0f6733d8 3179+ if(hpux_prohibited_duplicate_type(aclp[i].a_type)) {
fa26e11c
WD
3180+ DEBUG(0, ("hpux_acl_sort: Duplicate entry: Type(hex): %x Id: %d\n",
3181+ aclp[i].a_type, aclp[i].a_id));
3182+ return -1;
3183+ }
3184+ }
3185+
3186+ }
3187+ }
3188+ }
3189+
3190+ /* set the class obj permissions to the computed one. */
0f6733d8 3191+ if(calclass) {
fa26e11c
WD
3192+ int n_class_obj_index = -1;
3193+
0f6733d8 3194+ for(i=0;i<acl_count;i++) {
fa26e11c
WD
3195+ n_class_obj_perm |= hpux_get_needed_class_perm((aclp+i));
3196+
0f6733d8 3197+ if(aclp[i].a_type == CLASS_OBJ)
fa26e11c
WD
3198+ n_class_obj_index = i;
3199+ }
3200+ aclp[n_class_obj_index].a_perm = n_class_obj_perm;
3201+ }
3202+
3203+ return 0;
3204+#else
3205+ return aclsort(acl_count, calclass, aclp);
3206+#endif
3207+}
3208+
0f6733d8
WD
3209+/*
3210+ * sort the ACL and check it for validity
fa26e11c 3211+ *
0f6733d8 3212+ * if it's a minimal ACL with only 4 entries then we
fa26e11c
WD
3213+ * need to recalculate the mask permissions to make
3214+ * sure that they are the same as the GROUP_OBJ
3215+ * permissions as required by the UnixWare acl() system call.
3216+ *
0f6733d8 3217+ * (note: since POSIX allows minimal ACLs which only contain
fa26e11c
WD
3218+ * 3 entries - ie there is no mask entry - we should, in theory,
3219+ * check for this and add a mask entry if necessary - however
3220+ * we "know" that the caller of this interface always specifies
3221+ * a mask so, in practice "this never happens" (tm) - if it *does*
3222+ * happen aclsort() will fail and return an error and someone will
0f6733d8
WD
3223+ * have to fix it ...)
3224+ */
fa26e11c
WD
3225+
3226+static int acl_sort(SMB_ACL_T acl_d)
3227+{
3228+ int fixmask = (acl_d->count <= 4);
3229+
3230+ if (hpux_acl_sort(acl_d->count, fixmask, acl_d->acl) != 0) {
3231+ errno = EINVAL;
3232+ return -1;
3233+ }
3234+ return 0;
3235+}
0f6733d8
WD
3236+
3237+int sys_acl_valid(SMB_ACL_T acl_d)
fa26e11c
WD
3238+{
3239+ return acl_sort(acl_d);
3240+}
3241+
0f6733d8 3242+int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
fa26e11c 3243+{
0f6733d8
WD
3244+ struct stat s;
3245+ struct acl *acl_p;
3246+ int acl_count;
3247+ struct acl *acl_buf = NULL;
3248+ int ret;
fa26e11c 3249+
0f6733d8
WD
3250+ if(hpux_acl_call_presence() == False) {
3251+ /* Looks like we don't have the acl() system call on HPUX.
3252+ * May be the system doesn't have the latest version of JFS.
3253+ */
3254+ errno=ENOSYS;
3255+ return -1;
fa26e11c
WD
3256+ }
3257+
3258+ if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
3259+ errno = EINVAL;
3260+ return -1;
3261+ }
3262+
3263+ if (acl_sort(acl_d) != 0) {
3264+ return -1;
3265+ }
3266+
0f6733d8
WD
3267+ acl_p = &acl_d->acl[0];
3268+ acl_count = acl_d->count;
fa26e11c 3269+
0f6733d8
WD
3270+ /*
3271+ * if it's a directory there is extra work to do
3272+ * since the acl() system call will replace both
3273+ * the access ACLs and the default ACLs (if any)
3274+ */
fa26e11c
WD
3275+ if (stat(name, &s) != 0) {
3276+ return -1;
3277+ }
3278+ if (S_ISDIR(s.st_mode)) {
0f6733d8
WD
3279+ SMB_ACL_T acc_acl;
3280+ SMB_ACL_T def_acl;
3281+ SMB_ACL_T tmp_acl;
3282+ int i;
fa26e11c
WD
3283+
3284+ if (type == SMB_ACL_TYPE_ACCESS) {
3285+ acc_acl = acl_d;
3286+ def_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_DEFAULT);
3287+
3288+ } else {
3289+ def_acl = acl_d;
3290+ acc_acl = tmp_acl = sys_acl_get_file(name, SMB_ACL_TYPE_ACCESS);
3291+ }
3292+
3293+ if (tmp_acl == NULL) {
3294+ return -1;
3295+ }
3296+
0f6733d8
WD
3297+ /*
3298+ * allocate a temporary buffer for the complete ACL
3299+ */
fa26e11c 3300+ acl_count = acc_acl->count + def_acl->count;
252945ef 3301+ acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
fa26e11c
WD
3302+
3303+ if (acl_buf == NULL) {
3304+ sys_acl_free_acl(tmp_acl);
3305+ errno = ENOMEM;
3306+ return -1;
3307+ }
3308+
0f6733d8
WD
3309+ /*
3310+ * copy the access control and default entries into the buffer
3311+ */
fa26e11c 3312+ memcpy(&acl_buf[0], &acc_acl->acl[0],
0f6733d8 3313+ acc_acl->count * sizeof(acl_buf[0]));
fa26e11c
WD
3314+
3315+ memcpy(&acl_buf[acc_acl->count], &def_acl->acl[0],
0f6733d8 3316+ def_acl->count * sizeof(acl_buf[0]));
fa26e11c 3317+
0f6733d8
WD
3318+ /*
3319+ * set the ACL_DEFAULT flag on the default entries
3320+ */
fa26e11c
WD
3321+ for (i = acc_acl->count; i < acl_count; i++) {
3322+ acl_buf[i].a_type |= ACL_DEFAULT;
3323+ }
3324+
3325+ sys_acl_free_acl(tmp_acl);
3326+
3327+ } else if (type != SMB_ACL_TYPE_ACCESS) {
3328+ errno = EINVAL;
3329+ return -1;
3330+ }
3331+
3332+ ret = acl(name, ACL_SET, acl_count, acl_p);
3333+
0f6733d8
WD
3334+ if (acl_buf) {
3335+ free(acl_buf);
3336+ }
fa26e11c
WD
3337+
3338+ return ret;
3339+}
3340+
0f6733d8 3341+int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
fa26e11c 3342+{
0f6733d8
WD
3343+ /*
3344+ * HPUX doesn't have the facl call. Fake it using the path.... JRA.
3345+ */
fa26e11c
WD
3346+
3347+ files_struct *fsp = file_find_fd(fd);
3348+
3349+ if (fsp == NULL) {
3350+ errno = EBADF;
3351+ return NULL;
3352+ }
3353+
3354+ if (acl_sort(acl_d) != 0) {
3355+ return -1;
3356+ }
3357+
0f6733d8
WD
3358+ /*
3359+ * We know we're in the same conn context. So we
3360+ * can use the relative path.
3361+ */
fa26e11c 3362+
5ca9317d 3363+ return sys_acl_set_file(fsp->fsp_name, SMB_ACL_TYPE_ACCESS, acl_d);
fa26e11c
WD
3364+}
3365+
0f6733d8 3366+int sys_acl_delete_def_file(const char *path)
fa26e11c 3367+{
0f6733d8
WD
3368+ SMB_ACL_T acl_d;
3369+ int ret;
fa26e11c 3370+
0f6733d8
WD
3371+ /*
3372+ * fetching the access ACL and rewriting it has
3373+ * the effect of deleting the default ACL
3374+ */
fa26e11c
WD
3375+ if ((acl_d = sys_acl_get_file(path, SMB_ACL_TYPE_ACCESS)) == NULL) {
3376+ return -1;
3377+ }
3378+
3379+ ret = acl(path, ACL_SET, acl_d->count, acl_d->acl);
3380+
3381+ sys_acl_free_acl(acl_d);
0f6733d8 3382+
fa26e11c
WD
3383+ return ret;
3384+}
3385+
0f6733d8 3386+int sys_acl_free_text(char *text)
fa26e11c
WD
3387+{
3388+ free(text);
3389+ return 0;
3390+}
3391+
0f6733d8 3392+int sys_acl_free_acl(SMB_ACL_T acl_d)
fa26e11c
WD
3393+{
3394+ free(acl_d);
3395+ return 0;
3396+}
3397+
0f6733d8 3398+int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
fa26e11c
WD
3399+{
3400+ return 0;
3401+}
3402+
3403+#elif defined(HAVE_IRIX_ACLS)
3404+
0f6733d8 3405+int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p)
fa26e11c
WD
3406+{
3407+ if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {
3408+ errno = EINVAL;
3409+ return -1;
3410+ }
3411+
3412+ if (entry_p == NULL) {
3413+ errno = EINVAL;
3414+ return -1;
3415+ }
3416+
3417+ if (entry_id == SMB_ACL_FIRST_ENTRY) {
3418+ acl_d->next = 0;
3419+ }
3420+
3421+ if (acl_d->next < 0) {
3422+ errno = EINVAL;
3423+ return -1;
3424+ }
3425+
3426+ if (acl_d->next >= acl_d->aclp->acl_cnt) {
3427+ return 0;
3428+ }
3429+
3430+ *entry_p = &acl_d->aclp->acl_entry[acl_d->next++];
3431+
3432+ return 1;
3433+}
3434+
0f6733d8 3435+int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p)
fa26e11c
WD
3436+{
3437+ *type_p = entry_d->ae_tag;
3438+
3439+ return 0;
3440+}
3441+
0f6733d8 3442+int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
fa26e11c
WD
3443+{
3444+ *permset_p = entry_d;
3445+
3446+ return 0;
3447+}
3448+
0f6733d8 3449+void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d)
fa26e11c
WD
3450+{
3451+ if (entry_d->ae_tag != SMB_ACL_USER
3452+ && entry_d->ae_tag != SMB_ACL_GROUP) {
3453+ errno = EINVAL;
3454+ return NULL;
3455+ }
3456+
3457+ return &entry_d->ae_id;
3458+}
3459+
0f6733d8 3460+SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type)
fa26e11c 3461+{
0f6733d8 3462+ SMB_ACL_T a;
fa26e11c 3463+
252945ef 3464+ if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
fa26e11c
WD
3465+ errno = ENOMEM;
3466+ return NULL;
3467+ }
3468+ if ((a->aclp = acl_get_file(path_p, type)) == NULL) {
0f6733d8 3469+ SAFE_FREE(a);
fa26e11c
WD
3470+ return NULL;
3471+ }
3472+ a->next = -1;
3473+ a->freeaclp = True;
3474+ return a;
3475+}
3476+
0f6733d8 3477+SMB_ACL_T sys_acl_get_fd(int fd)
fa26e11c 3478+{
0f6733d8 3479+ SMB_ACL_T a;
fa26e11c 3480+
252945ef 3481+ if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
fa26e11c
WD
3482+ errno = ENOMEM;
3483+ return NULL;
3484+ }
3485+ if ((a->aclp = acl_get_fd(fd)) == NULL) {
0f6733d8 3486+ SAFE_FREE(a);
fa26e11c
WD
3487+ return NULL;
3488+ }
3489+ a->next = -1;
3490+ a->freeaclp = True;
3491+ return a;
3492+}
3493+
0f6733d8 3494+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d)
fa26e11c
WD
3495+{
3496+ permset_d->ae_perm = 0;
3497+
3498+ return 0;
3499+}
3500+
0f6733d8 3501+int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
fa26e11c
WD
3502+{
3503+ if (perm != SMB_ACL_READ && perm != SMB_ACL_WRITE
3504+ && perm != SMB_ACL_EXECUTE) {
3505+ errno = EINVAL;
3506+ return -1;
3507+ }
3508+
3509+ if (permset_d == NULL) {
3510+ errno = EINVAL;
3511+ return -1;
3512+ }
3513+
3514+ permset_d->ae_perm |= perm;
3515+
3516+ return 0;
3517+}
3518+
0f6733d8 3519+int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm)
fa26e11c
WD
3520+{
3521+ return permset_d->ae_perm & perm;
3522+}
3523+
0f6733d8 3524+char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p)
fa26e11c
WD
3525+{
3526+ return acl_to_text(acl_d->aclp, len_p);
3527+}
3528+
0f6733d8 3529+SMB_ACL_T sys_acl_init(int count)
fa26e11c 3530+{
0f6733d8 3531+ SMB_ACL_T a;
fa26e11c
WD
3532+
3533+ if (count < 0) {
3534+ errno = EINVAL;
3535+ return NULL;
3536+ }
3537+
252945ef 3538+ if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
fa26e11c
WD
3539+ errno = ENOMEM;
3540+ return NULL;
3541+ }
3542+
3543+ a->next = -1;
3544+ a->freeaclp = False;
0f6733d8 3545+ a->aclp = (struct acl *)(&a->aclp + sizeof(struct acl *));
fa26e11c
WD
3546+ a->aclp->acl_cnt = 0;
3547+
3548+ return a;
3549+}
3550+
3551+
0f6733d8 3552+int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p)
fa26e11c 3553+{
0f6733d8
WD
3554+ SMB_ACL_T acl_d;
3555+ SMB_ACL_ENTRY_T entry_d;
fa26e11c
WD
3556+
3557+ if (acl_p == NULL || entry_p == NULL || (acl_d = *acl_p) == NULL) {
3558+ errno = EINVAL;
3559+ return -1;
3560+ }
3561+
3562+ if (acl_d->aclp->acl_cnt >= ACL_MAX_ENTRIES) {
3563+ errno = ENOSPC;
3564+ return -1;
3565+ }
3566+
0f6733d8
WD
3567+ entry_d = &acl_d->aclp->acl_entry[acl_d->aclp->acl_cnt++];
3568+ entry_d->ae_tag = 0;
3569+ entry_d->ae_id = 0;
3570+ entry_d->ae_perm = 0;
3571+ *entry_p = entry_d;
fa26e11c
WD
3572+
3573+ return 0;
3574+}
3575+
0f6733d8 3576+int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type)
fa26e11c
WD
3577+{
3578+ switch (tag_type) {
3579+ case SMB_ACL_USER:
3580+ case SMB_ACL_USER_OBJ:
3581+ case SMB_ACL_GROUP:
3582+ case SMB_ACL_GROUP_OBJ:
3583+ case SMB_ACL_OTHER:
3584+ case SMB_ACL_MASK:
3585+ entry_d->ae_tag = tag_type;
3586+ break;
3587+ default:
3588+ errno = EINVAL;
3589+ return -1;
3590+ }
3591+
3592+ return 0;
3593+}
3594+
0f6733d8 3595+int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p)
fa26e11c
WD
3596+{
3597+ if (entry_d->ae_tag != SMB_ACL_GROUP
3598+ && entry_d->ae_tag != SMB_ACL_USER) {
3599+ errno = EINVAL;
3600+ return -1;
3601+ }
3602+
3603+ entry_d->ae_id = *((id_t *)qual_p);
3604+
3605+ return 0;
3606+}
3607+
0f6733d8 3608+int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d)
fa26e11c
WD
3609+{
3610+ if (permset_d->ae_perm & ~(SMB_ACL_READ|SMB_ACL_WRITE|SMB_ACL_EXECUTE)) {
3611+ return EINVAL;
3612+ }
3613+
3614+ entry_d->ae_perm = permset_d->ae_perm;
3615+
3616+ return 0;
3617+}
3618+
0f6733d8 3619+int sys_acl_valid(SMB_ACL_T acl_d)
fa26e11c
WD
3620+{
3621+ return acl_valid(acl_d->aclp);
3622+}
3623+
0f6733d8 3624+int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d)
fa26e11c
WD
3625+{
3626+ return acl_set_file(name, type, acl_d->aclp);
3627+}
3628+
0f6733d8 3629+int sys_acl_set_fd(int fd, SMB_ACL_T acl_d)
fa26e11c
WD
3630+{
3631+ return acl_set_fd(fd, acl_d->aclp);
3632+}
3633+
0f6733d8 3634+int sys_acl_delete_def_file(const char *name)
fa26e11c
WD
3635+{
3636+ return acl_delete_def_file(name);
3637+}
3638+
0f6733d8 3639+int sys_acl_free_text(char *text)
fa26e11c
WD
3640+{
3641+ return acl_free(text);
3642+}
3643+
0f6733d8 3644+int sys_acl_free_acl(SMB_ACL_T acl_d)
fa26e11c
WD
3645+{
3646+ if (acl_d->freeaclp) {
3647+ acl_free(acl_d->aclp);
3648+ }
3649+ acl_free(acl_d);
3650+ return 0;
3651+}
3652+
0f6733d8 3653+int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
fa26e11c
WD
3654+{
3655+ return 0;
3656+}
3657+
3658+#elif defined(HAVE_AIX_ACLS)
3659+
3660+/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
3661+
0f6733d8 3662+int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
fa26e11c
WD
3663+{
3664+ struct acl_entry_link *link;
3665+ struct new_acl_entry *entry;
3666+ int keep_going;
3667+
3668+ DEBUG(10,("This is the count: %d\n",theacl->count));
3669+
0f6733d8
WD
3670+ /* Check if count was previously set to -1. *
3671+ * If it was, that means we reached the end *
3672+ * of the acl last time. */
3673+ if(theacl->count == -1)
3674+ return(0);
fa26e11c
WD
3675+
3676+ link = theacl;
0f6733d8
WD
3677+ /* To get to the next acl, traverse linked list until index *
3678+ * of acl matches the count we are keeping. This count is *
3679+ * incremented each time we return an acl entry. */
fa26e11c 3680+
0f6733d8 3681+ for(keep_going = 0; keep_going < theacl->count; keep_going++)
fa26e11c
WD
3682+ link = link->nextp;
3683+
3684+ entry = *entry_p = link->entryp;
3685+
3686+ DEBUG(10,("*entry_p is %d\n",entry_p));
3687+ DEBUG(10,("*entry_p->ace_access is %d\n",entry->ace_access));
3688+
3689+ /* Increment count */
3690+ theacl->count++;
0f6733d8 3691+ if(link->nextp == NULL)
fa26e11c
WD
3692+ theacl->count = -1;
3693+
0f6733d8 3694+ return(1);
fa26e11c
WD
3695+}
3696+
0f6733d8 3697+int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
fa26e11c
WD
3698+{
3699+ /* Initialize tag type */
3700+
3701+ *tag_type_p = -1;
3702+ DEBUG(10,("the tagtype is %d\n",entry_d->ace_id->id_type));
3703+
0f6733d8
WD
3704+ /* Depending on what type of entry we have, *
3705+ * return tag type. */
3706+ switch(entry_d->ace_id->id_type) {
fa26e11c
WD
3707+ case ACEID_USER:
3708+ *tag_type_p = SMB_ACL_USER;
3709+ break;
3710+ case ACEID_GROUP:
3711+ *tag_type_p = SMB_ACL_GROUP;
3712+ break;
3713+
3714+ case SMB_ACL_USER_OBJ:
3715+ case SMB_ACL_GROUP_OBJ:
3716+ case SMB_ACL_OTHER:
3717+ *tag_type_p = entry_d->ace_id->id_type;
3718+ break;
0f6733d8 3719+
fa26e11c 3720+ default:
0f6733d8 3721+ return(-1);
fa26e11c
WD
3722+ }
3723+
0f6733d8 3724+ return(0);
fa26e11c
WD
3725+}
3726+
0f6733d8 3727+int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
fa26e11c
WD
3728+{
3729+ DEBUG(10,("Starting AIX sys_acl_get_permset\n"));
3730+ *permset_p = &entry_d->ace_access;
3731+ DEBUG(10,("**permset_p is %d\n",**permset_p));
0f6733d8
WD
3732+ if(!(**permset_p & S_IXUSR) &&
3733+ !(**permset_p & S_IWUSR) &&
3734+ !(**permset_p & S_IRUSR) &&
3735+ (**permset_p != 0))
3736+ return(-1);
fa26e11c
WD
3737+
3738+ DEBUG(10,("Ending AIX sys_acl_get_permset\n"));
0f6733d8 3739+ return(0);
fa26e11c
WD
3740+}
3741+
0f6733d8 3742+void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
fa26e11c 3743+{
0f6733d8 3744+ return(entry_d->ace_id->id_data);
fa26e11c
WD
3745+}
3746+
0f6733d8 3747+SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
fa26e11c
WD
3748+{
3749+ struct acl *file_acl = (struct acl *)NULL;
3750+ struct acl_entry *acl_entry;
3751+ struct new_acl_entry *new_acl_entry;
3752+ struct ace_id *idp;
3753+ struct acl_entry_link *acl_entry_link;
3754+ struct acl_entry_link *acl_entry_link_head;
3755+ int i;
3756+ int rc = 0;
3757+ uid_t user_id;
3758+
252945ef
WD
3759+ /* AIX has no DEFAULT */
3760+ if ( type == SMB_ACL_TYPE_DEFAULT )
3761+ return NULL;
3762+
fa26e11c 3763+ /* Get the acl using statacl */
0f6733d8 3764+
fa26e11c
WD
3765+ DEBUG(10,("Entering sys_acl_get_file\n"));
3766+ DEBUG(10,("path_p is %s\n",path_p));
3767+
252945ef 3768+ file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
0f6733d8
WD
3769+
3770+ if(file_acl == NULL) {
fa26e11c
WD
3771+ errno=ENOMEM;
3772+ DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno));
0f6733d8 3773+ return(NULL);
fa26e11c
WD
3774+ }
3775+
3776+ memset(file_acl,0,BUFSIZ);
3777+
3778+ rc = statacl((char *)path_p,0,file_acl,BUFSIZ);
0f6733d8 3779+ if(rc == -1) {
fa26e11c 3780+ DEBUG(0,("statacl returned %d with errno %d\n",rc,errno));
0f6733d8
WD
3781+ SAFE_FREE(file_acl);
3782+ return(NULL);
fa26e11c
WD
3783+ }
3784+
3785+ DEBUG(10,("Got facl and returned it\n"));
3786+
3787+ /* Point to the first acl entry in the acl */
3788+ acl_entry = file_acl->acl_ext;
3789+
0f6733d8
WD
3790+ /* Begin setting up the head of the linked list *
3791+ * that will be used for the storing the acl *
3792+ * in a way that is useful for the posix_acls.c *
3793+ * code. */
fa26e11c
WD
3794+
3795+ acl_entry_link_head = acl_entry_link = sys_acl_init(0);
0f6733d8
WD
3796+ if(acl_entry_link_head == NULL)
3797+ return(NULL);
fa26e11c 3798+
252945ef 3799+ acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
0f6733d8
WD
3800+ if(acl_entry_link->entryp == NULL) {
3801+ SAFE_FREE(file_acl);
fa26e11c
WD
3802+ errno = ENOMEM;
3803+ DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
0f6733d8 3804+ return(NULL);
fa26e11c
WD
3805+ }
3806+
3807+ DEBUG(10,("acl_entry is %d\n",acl_entry));
3808+ DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
3809+
0f6733d8
WD
3810+ /* Check if the extended acl bit is on. *
3811+ * If it isn't, do not show the *
3812+ * contents of the acl since AIX intends *
3813+ * the extended info to remain unused */
fa26e11c 3814+
0f6733d8 3815+ if(file_acl->acl_mode & S_IXACL){
fa26e11c 3816+ /* while we are not pointing to the very end */
0f6733d8 3817+ while(acl_entry < acl_last(file_acl)) {
fa26e11c
WD
3818+ /* before we malloc anything, make sure this is */
3819+ /* a valid acl entry and one that we want to map */
3820+ idp = id_nxt(acl_entry->ace_id);
0f6733d8
WD
3821+ if((acl_entry->ace_type == ACC_SPECIFY ||
3822+ (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
3823+ acl_entry = acl_nxt(acl_entry);
3824+ continue;
fa26e11c
WD
3825+ }
3826+
3827+ idp = acl_entry->ace_id;
3828+
0f6733d8
WD
3829+ /* Check if this is the first entry in the linked list. *
3830+ * The first entry needs to keep prevp pointing to NULL *
3831+ * and already has entryp allocated. */
fa26e11c 3832+
0f6733d8 3833+ if(acl_entry_link_head->count != 0) {
252945ef 3834+ acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
fa26e11c 3835+
0f6733d8
WD
3836+ if(acl_entry_link->nextp == NULL) {
3837+ SAFE_FREE(file_acl);
fa26e11c
WD
3838+ errno = ENOMEM;
3839+ DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
0f6733d8 3840+ return(NULL);
fa26e11c
WD
3841+ }
3842+
3843+ acl_entry_link->nextp->prevp = acl_entry_link;
3844+ acl_entry_link = acl_entry_link->nextp;
252945ef 3845+ acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
0f6733d8
WD
3846+ if(acl_entry_link->entryp == NULL) {
3847+ SAFE_FREE(file_acl);
fa26e11c
WD
3848+ errno = ENOMEM;
3849+ DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
0f6733d8 3850+ return(NULL);
fa26e11c
WD
3851+ }
3852+ acl_entry_link->nextp = NULL;
3853+ }
3854+
3855+ acl_entry_link->entryp->ace_len = acl_entry->ace_len;
3856+
0f6733d8
WD
3857+ /* Don't really need this since all types are going *
3858+ * to be specified but, it's better than leaving it 0 */
fa26e11c
WD
3859+
3860+ acl_entry_link->entryp->ace_type = acl_entry->ace_type;
0f6733d8 3861+
fa26e11c 3862+ acl_entry_link->entryp->ace_access = acl_entry->ace_access;
0f6733d8
WD
3863+
3864+ memcpy(acl_entry_link->entryp->ace_id,idp,sizeof(struct ace_id));
fa26e11c 3865+
0f6733d8
WD
3866+ /* The access in the acl entries must be left shifted by *
3867+ * three bites, because they will ultimately be compared *
3868+ * to S_IRUSR, S_IWUSR, and S_IXUSR. */
fa26e11c 3869+
0f6733d8 3870+ switch(acl_entry->ace_type){
fa26e11c
WD
3871+ case ACC_PERMIT:
3872+ case ACC_SPECIFY:
3873+ acl_entry_link->entryp->ace_access = acl_entry->ace_access;
3874+ acl_entry_link->entryp->ace_access <<= 6;
3875+ acl_entry_link_head->count++;
3876+ break;
3877+ case ACC_DENY:
0f6733d8
WD
3878+ /* Since there is no way to return a DENY acl entry *
3879+ * change to PERMIT and then shift. */
fa26e11c
WD
3880+ DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
3881+ acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
3882+ DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
3883+ acl_entry_link->entryp->ace_access <<= 6;
3884+ acl_entry_link_head->count++;
3885+ break;
3886+ default:
0f6733d8 3887+ return(0);
fa26e11c
WD
3888+ }
3889+
3890+ DEBUG(10,("acl_entry = %d\n",acl_entry));
3891+ DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
0f6733d8 3892+
fa26e11c
WD
3893+ acl_entry = acl_nxt(acl_entry);
3894+ }
3895+ } /* end of if enabled */
3896+
0f6733d8
WD
3897+ /* Since owner, group, other acl entries are not *
3898+ * part of the acl entries in an acl, they must *
3899+ * be dummied up to become part of the list. */
fa26e11c 3900+
0f6733d8 3901+ for( i = 1; i < 4; i++) {
fa26e11c 3902+ DEBUG(10,("i is %d\n",i));
0f6733d8 3903+ if(acl_entry_link_head->count != 0) {
252945ef 3904+ acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
0f6733d8
WD
3905+ if(acl_entry_link->nextp == NULL) {
3906+ SAFE_FREE(file_acl);
fa26e11c
WD
3907+ errno = ENOMEM;
3908+ DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
0f6733d8 3909+ return(NULL);
fa26e11c
WD
3910+ }
3911+
3912+ acl_entry_link->nextp->prevp = acl_entry_link;
3913+ acl_entry_link = acl_entry_link->nextp;
252945ef 3914+ acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
0f6733d8
WD
3915+ if(acl_entry_link->entryp == NULL) {
3916+ SAFE_FREE(file_acl);
fa26e11c
WD
3917+ errno = ENOMEM;
3918+ DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno));
0f6733d8 3919+ return(NULL);
fa26e11c
WD
3920+ }
3921+ }
3922+
3923+ acl_entry_link->nextp = NULL;
3924+
3925+ new_acl_entry = acl_entry_link->entryp;
3926+ idp = new_acl_entry->ace_id;
3927+
0f6733d8 3928+ new_acl_entry->ace_len = sizeof(struct acl_entry);
fa26e11c 3929+ new_acl_entry->ace_type = ACC_PERMIT;
0f6733d8 3930+ idp->id_len = sizeof(struct ace_id);
fa26e11c 3931+ DEBUG(10,("idp->id_len = %d\n",idp->id_len));
0f6733d8 3932+ memset(idp->id_data,0,sizeof(uid_t));
fa26e11c 3933+
0f6733d8 3934+ switch(i) {
fa26e11c
WD
3935+ case 2:
3936+ new_acl_entry->ace_access = file_acl->g_access << 6;
3937+ idp->id_type = SMB_ACL_GROUP_OBJ;
3938+ break;
3939+
3940+ case 3:
3941+ new_acl_entry->ace_access = file_acl->o_access << 6;
3942+ idp->id_type = SMB_ACL_OTHER;
3943+ break;
0f6733d8 3944+
fa26e11c
WD
3945+ case 1:
3946+ new_acl_entry->ace_access = file_acl->u_access << 6;
3947+ idp->id_type = SMB_ACL_USER_OBJ;
3948+ break;
0f6733d8 3949+
fa26e11c 3950+ default:
0f6733d8 3951+ return(NULL);
fa26e11c
WD
3952+
3953+ }
3954+
3955+ acl_entry_link_head->count++;
3956+ DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
3957+ }
3958+
3959+ acl_entry_link_head->count = 0;
0f6733d8 3960+ SAFE_FREE(file_acl);
fa26e11c 3961+
0f6733d8 3962+ return(acl_entry_link_head);
fa26e11c
WD
3963+}
3964+
0f6733d8 3965+SMB_ACL_T sys_acl_get_fd(int fd)
fa26e11c
WD
3966+{
3967+ struct acl *file_acl = (struct acl *)NULL;
3968+ struct acl_entry *acl_entry;
3969+ struct new_acl_entry *new_acl_entry;
3970+ struct ace_id *idp;
3971+ struct acl_entry_link *acl_entry_link;
3972+ struct acl_entry_link *acl_entry_link_head;
3973+ int i;
3974+ int rc = 0;
3975+ uid_t user_id;
3976+
3977+ /* Get the acl using fstatacl */
0f6733d8 3978+
fa26e11c
WD
3979+ DEBUG(10,("Entering sys_acl_get_fd\n"));
3980+ DEBUG(10,("fd is %d\n",fd));
252945ef 3981+ file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
fa26e11c 3982+
0f6733d8 3983+ if(file_acl == NULL) {
fa26e11c
WD
3984+ errno=ENOMEM;
3985+ DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
0f6733d8 3986+ return(NULL);
fa26e11c
WD
3987+ }
3988+
3989+ memset(file_acl,0,BUFSIZ);
3990+
3991+ rc = fstatacl(fd,0,file_acl,BUFSIZ);
0f6733d8 3992+ if(rc == -1) {
fa26e11c 3993+ DEBUG(0,("The fstatacl call returned %d with errno %d\n",rc,errno));
0f6733d8
WD
3994+ SAFE_FREE(file_acl);
3995+ return(NULL);
fa26e11c
WD
3996+ }
3997+
3998+ DEBUG(10,("Got facl and returned it\n"));
3999+
4000+ /* Point to the first acl entry in the acl */
4001+
4002+ acl_entry = file_acl->acl_ext;
0f6733d8
WD
4003+ /* Begin setting up the head of the linked list *
4004+ * that will be used for the storing the acl *
4005+ * in a way that is useful for the posix_acls.c *
4006+ * code. */
fa26e11c
WD
4007+
4008+ acl_entry_link_head = acl_entry_link = sys_acl_init(0);
0f6733d8
WD
4009+ if(acl_entry_link_head == NULL){
4010+ SAFE_FREE(file_acl);
4011+ return(NULL);
fa26e11c
WD
4012+ }
4013+
252945ef 4014+ acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
fa26e11c 4015+
0f6733d8 4016+ if(acl_entry_link->entryp == NULL) {
fa26e11c
WD
4017+ errno = ENOMEM;
4018+ DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
0f6733d8
WD
4019+ SAFE_FREE(file_acl);
4020+ return(NULL);
fa26e11c
WD
4021+ }
4022+
4023+ DEBUG(10,("acl_entry is %d\n",acl_entry));
4024+ DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
0f6733d8
WD
4025+
4026+ /* Check if the extended acl bit is on. *
4027+ * If it isn't, do not show the *
4028+ * contents of the acl since AIX intends *
4029+ * the extended info to remain unused */
4030+
4031+ if(file_acl->acl_mode & S_IXACL){
fa26e11c 4032+ /* while we are not pointing to the very end */
0f6733d8 4033+ while(acl_entry < acl_last(file_acl)) {
fa26e11c
WD
4034+ /* before we malloc anything, make sure this is */
4035+ /* a valid acl entry and one that we want to map */
4036+
4037+ idp = id_nxt(acl_entry->ace_id);
0f6733d8
WD
4038+ if((acl_entry->ace_type == ACC_SPECIFY ||
4039+ (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) {
4040+ acl_entry = acl_nxt(acl_entry);
4041+ continue;
fa26e11c
WD
4042+ }
4043+
4044+ idp = acl_entry->ace_id;
0f6733d8
WD
4045+
4046+ /* Check if this is the first entry in the linked list. *
4047+ * The first entry needs to keep prevp pointing to NULL *
4048+ * and already has entryp allocated. */
fa26e11c 4049+
0f6733d8 4050+ if(acl_entry_link_head->count != 0) {
252945ef 4051+ acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
0f6733d8 4052+ if(acl_entry_link->nextp == NULL) {
fa26e11c
WD
4053+ errno = ENOMEM;
4054+ DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
0f6733d8
WD
4055+ SAFE_FREE(file_acl);
4056+ return(NULL);
fa26e11c
WD
4057+ }
4058+ acl_entry_link->nextp->prevp = acl_entry_link;
4059+ acl_entry_link = acl_entry_link->nextp;
252945ef 4060+ acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
0f6733d8 4061+ if(acl_entry_link->entryp == NULL) {
fa26e11c
WD
4062+ errno = ENOMEM;
4063+ DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
0f6733d8
WD
4064+ SAFE_FREE(file_acl);
4065+ return(NULL);
fa26e11c
WD
4066+ }
4067+
4068+ acl_entry_link->nextp = NULL;
4069+ }
4070+
4071+ acl_entry_link->entryp->ace_len = acl_entry->ace_len;
4072+
0f6733d8
WD
4073+ /* Don't really need this since all types are going *
4074+ * to be specified but, it's better than leaving it 0 */
fa26e11c
WD
4075+
4076+ acl_entry_link->entryp->ace_type = acl_entry->ace_type;
4077+ acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4078+
0f6733d8 4079+ memcpy(acl_entry_link->entryp->ace_id, idp, sizeof(struct ace_id));
fa26e11c 4080+
0f6733d8
WD
4081+ /* The access in the acl entries must be left shifted by *
4082+ * three bites, because they will ultimately be compared *
4083+ * to S_IRUSR, S_IWUSR, and S_IXUSR. */
fa26e11c 4084+
0f6733d8 4085+ switch(acl_entry->ace_type){
fa26e11c
WD
4086+ case ACC_PERMIT:
4087+ case ACC_SPECIFY:
4088+ acl_entry_link->entryp->ace_access = acl_entry->ace_access;
4089+ acl_entry_link->entryp->ace_access <<= 6;
4090+ acl_entry_link_head->count++;
4091+ break;
4092+ case ACC_DENY:
0f6733d8
WD
4093+ /* Since there is no way to return a DENY acl entry *
4094+ * change to PERMIT and then shift. */
fa26e11c
WD
4095+ DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access));
4096+ acl_entry_link->entryp->ace_access = ~acl_entry->ace_access & 7;
4097+ DEBUG(10,("acl_entry_link->entryp->ace_access is %d\n",acl_entry_link->entryp->ace_access));
4098+ acl_entry_link->entryp->ace_access <<= 6;
4099+ acl_entry_link_head->count++;
4100+ break;
4101+ default:
0f6733d8 4102+ return(0);
fa26e11c
WD
4103+ }
4104+
4105+ DEBUG(10,("acl_entry = %d\n",acl_entry));
4106+ DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
0f6733d8 4107+
fa26e11c
WD
4108+ acl_entry = acl_nxt(acl_entry);
4109+ }
4110+ } /* end of if enabled */
4111+
0f6733d8
WD
4112+ /* Since owner, group, other acl entries are not *
4113+ * part of the acl entries in an acl, they must *
4114+ * be dummied up to become part of the list. */
fa26e11c 4115+
0f6733d8 4116+ for( i = 1; i < 4; i++) {
fa26e11c 4117+ DEBUG(10,("i is %d\n",i));
0f6733d8 4118+ if(acl_entry_link_head->count != 0){
252945ef 4119+ acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
0f6733d8 4120+ if(acl_entry_link->nextp == NULL) {
fa26e11c
WD
4121+ errno = ENOMEM;
4122+ DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
0f6733d8
WD
4123+ SAFE_FREE(file_acl);
4124+ return(NULL);
fa26e11c
WD
4125+ }
4126+
4127+ acl_entry_link->nextp->prevp = acl_entry_link;
4128+ acl_entry_link = acl_entry_link->nextp;
252945ef 4129+ acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
fa26e11c 4130+
0f6733d8
WD
4131+ if(acl_entry_link->entryp == NULL) {
4132+ SAFE_FREE(file_acl);
fa26e11c
WD
4133+ errno = ENOMEM;
4134+ DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
0f6733d8 4135+ return(NULL);
fa26e11c
WD
4136+ }
4137+ }
4138+
4139+ acl_entry_link->nextp = NULL;
0f6733d8 4140+
fa26e11c
WD
4141+ new_acl_entry = acl_entry_link->entryp;
4142+ idp = new_acl_entry->ace_id;
0f6733d8
WD
4143+
4144+ new_acl_entry->ace_len = sizeof(struct acl_entry);
fa26e11c 4145+ new_acl_entry->ace_type = ACC_PERMIT;
0f6733d8 4146+ idp->id_len = sizeof(struct ace_id);
fa26e11c 4147+ DEBUG(10,("idp->id_len = %d\n",idp->id_len));
0f6733d8
WD
4148+ memset(idp->id_data,0,sizeof(uid_t));
4149+
4150+ switch(i) {
fa26e11c
WD
4151+ case 2:
4152+ new_acl_entry->ace_access = file_acl->g_access << 6;
4153+ idp->id_type = SMB_ACL_GROUP_OBJ;
4154+ break;
0f6733d8 4155+
fa26e11c
WD
4156+ case 3:
4157+ new_acl_entry->ace_access = file_acl->o_access << 6;
4158+ idp->id_type = SMB_ACL_OTHER;
4159+ break;
0f6733d8 4160+
fa26e11c
WD
4161+ case 1:
4162+ new_acl_entry->ace_access = file_acl->u_access << 6;
4163+ idp->id_type = SMB_ACL_USER_OBJ;
4164+ break;
0f6733d8 4165+
fa26e11c 4166+ default:
0f6733d8 4167+ return(NULL);
fa26e11c 4168+ }
0f6733d8 4169+
fa26e11c
WD
4170+ acl_entry_link_head->count++;
4171+ DEBUG(10,("new_acl_entry->ace_access = %d\n",new_acl_entry->ace_access));
4172+ }
4173+
4174+ acl_entry_link_head->count = 0;
0f6733d8
WD
4175+ SAFE_FREE(file_acl);
4176+
4177+ return(acl_entry_link_head);
fa26e11c
WD
4178+}
4179+
0f6733d8 4180+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
fa26e11c
WD
4181+{
4182+ *permset = *permset & ~0777;
0f6733d8 4183+ return(0);
fa26e11c
WD
4184+}
4185+
0f6733d8 4186+int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
fa26e11c 4187+{
0f6733d8
WD
4188+ if((perm != 0) &&
4189+ (perm & (S_IXUSR | S_IWUSR | S_IRUSR)) == 0)
4190+ return(-1);
fa26e11c
WD
4191+
4192+ *permset |= perm;
4193+ DEBUG(10,("This is the permset now: %d\n",*permset));
0f6733d8 4194+ return(0);
fa26e11c
WD
4195+}
4196+
0f6733d8 4197+char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
fa26e11c 4198+{
0f6733d8 4199+ return(NULL);
fa26e11c
WD
4200+}
4201+
0f6733d8 4202+SMB_ACL_T sys_acl_init( int count)
fa26e11c
WD
4203+{
4204+ struct acl_entry_link *theacl = NULL;
0f6733d8 4205+
fa26e11c
WD
4206+ DEBUG(10,("Entering sys_acl_init\n"));
4207+
252945ef 4208+ theacl = SMB_MALLOC_P(struct acl_entry_link);
0f6733d8 4209+ if(theacl == NULL) {
fa26e11c
WD
4210+ errno = ENOMEM;
4211+ DEBUG(0,("Error in sys_acl_init is %d\n",errno));
0f6733d8 4212+ return(NULL);
fa26e11c
WD
4213+ }
4214+
4215+ theacl->count = 0;
4216+ theacl->nextp = NULL;
4217+ theacl->prevp = NULL;
4218+ theacl->entryp = NULL;
4219+ DEBUG(10,("Exiting sys_acl_init\n"));
0f6733d8 4220+ return(theacl);
fa26e11c
WD
4221+}
4222+
0f6733d8 4223+int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
fa26e11c
WD
4224+{
4225+ struct acl_entry_link *theacl;
4226+ struct acl_entry_link *acl_entryp;
4227+ struct acl_entry_link *temp_entry;
4228+ int counting;
4229+
4230+ DEBUG(10,("Entering the sys_acl_create_entry\n"));
4231+
4232+ theacl = acl_entryp = *pacl;
4233+
4234+ /* Get to the end of the acl before adding entry */
4235+
0f6733d8 4236+ for(counting=0; counting < theacl->count; counting++){
fa26e11c
WD
4237+ DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4238+ temp_entry = acl_entryp;
4239+ acl_entryp = acl_entryp->nextp;
4240+ }
4241+
0f6733d8 4242+ if(theacl->count != 0){
252945ef 4243+ temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
0f6733d8 4244+ if(acl_entryp == NULL) {
fa26e11c
WD
4245+ errno = ENOMEM;
4246+ DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
0f6733d8 4247+ return(-1);
fa26e11c
WD
4248+ }
4249+
4250+ DEBUG(10,("The acl_entryp is %d\n",acl_entryp));
4251+ acl_entryp->prevp = temp_entry;
4252+ DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
4253+ }
4254+
252945ef 4255+ *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
0f6733d8 4256+ if(*pentry == NULL) {
fa26e11c
WD
4257+ errno = ENOMEM;
4258+ DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
0f6733d8 4259+ return(-1);
fa26e11c
WD
4260+ }
4261+
0f6733d8
WD
4262+ memset(*pentry,0,sizeof(struct new_acl_entry));
4263+ acl_entryp->entryp->ace_len = sizeof(struct acl_entry);
fa26e11c 4264+ acl_entryp->entryp->ace_type = ACC_PERMIT;
0f6733d8 4265+ acl_entryp->entryp->ace_id->id_len = sizeof(struct ace_id);
fa26e11c
WD
4266+ acl_entryp->nextp = NULL;
4267+ theacl->count++;
4268+ DEBUG(10,("Exiting sys_acl_create_entry\n"));
0f6733d8 4269+ return(0);
fa26e11c
WD
4270+}
4271+
0f6733d8 4272+int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
fa26e11c
WD
4273+{
4274+ DEBUG(10,("Starting AIX sys_acl_set_tag_type\n"));
4275+ entry->ace_id->id_type = tagtype;
4276+ DEBUG(10,("The tag type is %d\n",entry->ace_id->id_type));
4277+ DEBUG(10,("Ending AIX sys_acl_set_tag_type\n"));
4278+}
4279+
0f6733d8 4280+int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
fa26e11c
WD
4281+{
4282+ DEBUG(10,("Starting AIX sys_acl_set_qualifier\n"));
0f6733d8 4283+ memcpy(entry->ace_id->id_data,qual,sizeof(uid_t));
fa26e11c 4284+ DEBUG(10,("Ending AIX sys_acl_set_qualifier\n"));
0f6733d8 4285+ return(0);
fa26e11c
WD
4286+}
4287+
0f6733d8 4288+int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
fa26e11c
WD
4289+{
4290+ DEBUG(10,("Starting AIX sys_acl_set_permset\n"));
0f6733d8
WD
4291+ if(!(*permset & S_IXUSR) &&
4292+ !(*permset & S_IWUSR) &&
4293+ !(*permset & S_IRUSR) &&
4294+ (*permset != 0))
4295+ return(-1);
fa26e11c
WD
4296+
4297+ entry->ace_access = *permset;
4298+ DEBUG(10,("entry->ace_access = %d\n",entry->ace_access));
4299+ DEBUG(10,("Ending AIX sys_acl_set_permset\n"));
0f6733d8 4300+ return(0);
fa26e11c
WD
4301+}
4302+
0f6733d8 4303+int sys_acl_valid( SMB_ACL_T theacl )
fa26e11c
WD
4304+{
4305+ int user_obj = 0;
4306+ int group_obj = 0;
4307+ int other_obj = 0;
4308+ struct acl_entry_link *acl_entry;
4309+
0f6733d8 4310+ for(acl_entry=theacl; acl_entry != NULL; acl_entry = acl_entry->nextp) {
fa26e11c
WD
4311+ user_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_USER_OBJ);
4312+ group_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_GROUP_OBJ);
4313+ other_obj += (acl_entry->entryp->ace_id->id_type == SMB_ACL_OTHER);
4314+ }
4315+
4316+ DEBUG(10,("user_obj=%d, group_obj=%d, other_obj=%d\n",user_obj,group_obj,other_obj));
0f6733d8
WD
4317+
4318+ if(user_obj != 1 || group_obj != 1 || other_obj != 1)
4319+ return(-1);
fa26e11c 4320+
0f6733d8 4321+ return(0);
fa26e11c
WD
4322+}
4323+
0f6733d8 4324+int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
fa26e11c
WD
4325+{
4326+ struct acl_entry_link *acl_entry_link = NULL;
4327+ struct acl *file_acl = NULL;
4328+ struct acl *file_acl_temp = NULL;
4329+ struct acl_entry *acl_entry = NULL;
4330+ struct ace_id *ace_id = NULL;
4331+ uint id_type;
4332+ uint ace_access;
4333+ uint user_id;
4334+ uint acl_length;
4335+ uint rc;
4336+
4337+ DEBUG(10,("Entering sys_acl_set_file\n"));
4338+ DEBUG(10,("File name is %s\n",name));
0f6733d8 4339+
fa26e11c 4340+ /* AIX has no default ACL */
0f6733d8
WD
4341+ if(acltype == SMB_ACL_TYPE_DEFAULT)
4342+ return(0);
fa26e11c
WD
4343+
4344+ acl_length = BUFSIZ;
252945ef 4345+ file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
fa26e11c 4346+
0f6733d8 4347+ if(file_acl == NULL) {
fa26e11c
WD
4348+ errno = ENOMEM;
4349+ DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
0f6733d8 4350+ return(-1);
fa26e11c
WD
4351+ }
4352+
4353+ memset(file_acl,0,BUFSIZ);
4354+
4355+ file_acl->acl_len = ACL_SIZ;
4356+ file_acl->acl_mode = S_IXACL;
4357+
0f6733d8 4358+ for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
fa26e11c
WD
4359+ acl_entry_link->entryp->ace_access >>= 6;
4360+ id_type = acl_entry_link->entryp->ace_id->id_type;
4361+
0f6733d8 4362+ switch(id_type) {
fa26e11c
WD
4363+ case SMB_ACL_USER_OBJ:
4364+ file_acl->u_access = acl_entry_link->entryp->ace_access;
4365+ continue;
4366+ case SMB_ACL_GROUP_OBJ:
4367+ file_acl->g_access = acl_entry_link->entryp->ace_access;
4368+ continue;
4369+ case SMB_ACL_OTHER:
4370+ file_acl->o_access = acl_entry_link->entryp->ace_access;
4371+ continue;
4372+ case SMB_ACL_MASK:
4373+ continue;
4374+ }
4375+
0f6733d8
WD
4376+ if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4377+ acl_length += sizeof(struct acl_entry);
252945ef 4378+ file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
0f6733d8
WD
4379+ if(file_acl_temp == NULL) {
4380+ SAFE_FREE(file_acl);
fa26e11c
WD
4381+ errno = ENOMEM;
4382+ DEBUG(0,("Error in sys_acl_set_file is %d\n",errno));
0f6733d8
WD
4383+ return(-1);
4384+ }
fa26e11c
WD
4385+
4386+ memcpy(file_acl_temp,file_acl,file_acl->acl_len);
0f6733d8 4387+ SAFE_FREE(file_acl);
fa26e11c
WD
4388+ file_acl = file_acl_temp;
4389+ }
4390+
4391+ acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
0f6733d8 4392+ file_acl->acl_len += sizeof(struct acl_entry);
fa26e11c
WD
4393+ acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4394+ acl_entry->ace_access = acl_entry_link->entryp->ace_access;
0f6733d8 4395+
fa26e11c 4396+ /* In order to use this, we'll need to wait until we can get denies */
0f6733d8
WD
4397+ /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
4398+ acl_entry->ace_type = ACC_SPECIFY; */
fa26e11c
WD
4399+
4400+ acl_entry->ace_type = ACC_SPECIFY;
0f6733d8 4401+
fa26e11c 4402+ ace_id = acl_entry->ace_id;
0f6733d8 4403+
fa26e11c
WD
4404+ ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4405+ DEBUG(10,("The id type is %d\n",ace_id->id_type));
4406+ ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
0f6733d8
WD
4407+ memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4408+ memcpy(acl_entry->ace_id->id_data, &user_id, sizeof(uid_t));
fa26e11c
WD
4409+ }
4410+
0f6733d8 4411+ rc = chacl(name,file_acl,file_acl->acl_len);
fa26e11c
WD
4412+ DEBUG(10,("errno is %d\n",errno));
4413+ DEBUG(10,("return code is %d\n",rc));
0f6733d8 4414+ SAFE_FREE(file_acl);
fa26e11c 4415+ DEBUG(10,("Exiting the sys_acl_set_file\n"));
0f6733d8 4416+ return(rc);
fa26e11c
WD
4417+}
4418+
0f6733d8 4419+int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
fa26e11c
WD
4420+{
4421+ struct acl_entry_link *acl_entry_link = NULL;
4422+ struct acl *file_acl = NULL;
4423+ struct acl *file_acl_temp = NULL;
4424+ struct acl_entry *acl_entry = NULL;
4425+ struct ace_id *ace_id = NULL;
4426+ uint id_type;
4427+ uint user_id;
4428+ uint acl_length;
4429+ uint rc;
0f6733d8 4430+
fa26e11c
WD
4431+ DEBUG(10,("Entering sys_acl_set_fd\n"));
4432+ acl_length = BUFSIZ;
252945ef 4433+ file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
fa26e11c 4434+
0f6733d8 4435+ if(file_acl == NULL) {
fa26e11c
WD
4436+ errno = ENOMEM;
4437+ DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
0f6733d8 4438+ return(-1);
fa26e11c
WD
4439+ }
4440+
4441+ memset(file_acl,0,BUFSIZ);
0f6733d8 4442+
fa26e11c
WD
4443+ file_acl->acl_len = ACL_SIZ;
4444+ file_acl->acl_mode = S_IXACL;
4445+
0f6733d8 4446+ for(acl_entry_link=theacl; acl_entry_link != NULL; acl_entry_link = acl_entry_link->nextp) {
fa26e11c
WD
4447+ acl_entry_link->entryp->ace_access >>= 6;
4448+ id_type = acl_entry_link->entryp->ace_id->id_type;
4449+ DEBUG(10,("The id_type is %d\n",id_type));
4450+
0f6733d8 4451+ switch(id_type) {
fa26e11c
WD
4452+ case SMB_ACL_USER_OBJ:
4453+ file_acl->u_access = acl_entry_link->entryp->ace_access;
4454+ continue;
4455+ case SMB_ACL_GROUP_OBJ:
4456+ file_acl->g_access = acl_entry_link->entryp->ace_access;
4457+ continue;
4458+ case SMB_ACL_OTHER:
4459+ file_acl->o_access = acl_entry_link->entryp->ace_access;
4460+ continue;
4461+ case SMB_ACL_MASK:
4462+ continue;
4463+ }
4464+
0f6733d8
WD
4465+ if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
4466+ acl_length += sizeof(struct acl_entry);
252945ef 4467+ file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
0f6733d8
WD
4468+ if(file_acl_temp == NULL) {
4469+ SAFE_FREE(file_acl);
fa26e11c
WD
4470+ errno = ENOMEM;
4471+ DEBUG(0,("Error in sys_acl_set_fd is %d\n",errno));
0f6733d8 4472+ return(-1);
fa26e11c
WD
4473+ }
4474+
4475+ memcpy(file_acl_temp,file_acl,file_acl->acl_len);
0f6733d8 4476+ SAFE_FREE(file_acl);
fa26e11c
WD
4477+ file_acl = file_acl_temp;
4478+ }
4479+
4480+ acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len);
0f6733d8 4481+ file_acl->acl_len += sizeof(struct acl_entry);
fa26e11c
WD
4482+ acl_entry->ace_len = acl_entry_link->entryp->ace_len;
4483+ acl_entry->ace_access = acl_entry_link->entryp->ace_access;
0f6733d8 4484+
fa26e11c 4485+ /* In order to use this, we'll need to wait until we can get denies */
0f6733d8 4486+ /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT)
fa26e11c 4487+ acl_entry->ace_type = ACC_SPECIFY; */
0f6733d8 4488+
fa26e11c 4489+ acl_entry->ace_type = ACC_SPECIFY;
0f6733d8 4490+
fa26e11c 4491+ ace_id = acl_entry->ace_id;
0f6733d8 4492+
fa26e11c
WD
4493+ ace_id->id_type = acl_entry_link->entryp->ace_id->id_type;
4494+ DEBUG(10,("The id type is %d\n",ace_id->id_type));
4495+ ace_id->id_len = acl_entry_link->entryp->ace_id->id_len;
0f6733d8
WD
4496+ memcpy(&user_id, acl_entry_link->entryp->ace_id->id_data, sizeof(uid_t));
4497+ memcpy(ace_id->id_data, &user_id, sizeof(uid_t));
fa26e11c 4498+ }
0f6733d8 4499+
fa26e11c
WD
4500+ rc = fchacl(fd,file_acl,file_acl->acl_len);
4501+ DEBUG(10,("errno is %d\n",errno));
4502+ DEBUG(10,("return code is %d\n",rc));
0f6733d8 4503+ SAFE_FREE(file_acl);
fa26e11c 4504+ DEBUG(10,("Exiting sys_acl_set_fd\n"));
0f6733d8 4505+ return(rc);
fa26e11c
WD
4506+}
4507+
0f6733d8 4508+int sys_acl_delete_def_file(const char *name)
fa26e11c
WD
4509+{
4510+ /* AIX has no default ACL */
4511+ return 0;
4512+}
4513+
0f6733d8 4514+int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
fa26e11c 4515+{
0f6733d8 4516+ return(*permset & perm);
fa26e11c
WD
4517+}
4518+
0f6733d8 4519+int sys_acl_free_text(char *text)
fa26e11c 4520+{
0f6733d8 4521+ return(0);
fa26e11c
WD
4522+}
4523+
0f6733d8 4524+int sys_acl_free_acl(SMB_ACL_T posix_acl)
fa26e11c
WD
4525+{
4526+ struct acl_entry_link *acl_entry_link;
4527+
0f6733d8
WD
4528+ for(acl_entry_link = posix_acl->nextp; acl_entry_link->nextp != NULL; acl_entry_link = acl_entry_link->nextp) {
4529+ SAFE_FREE(acl_entry_link->prevp->entryp);
4530+ SAFE_FREE(acl_entry_link->prevp);
fa26e11c
WD
4531+ }
4532+
0f6733d8
WD
4533+ SAFE_FREE(acl_entry_link->prevp->entryp);
4534+ SAFE_FREE(acl_entry_link->prevp);
4535+ SAFE_FREE(acl_entry_link->entryp);
4536+ SAFE_FREE(acl_entry_link);
4537+
4538+ return(0);
fa26e11c
WD
4539+}
4540+
0f6733d8 4541+int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
fa26e11c 4542+{
0f6733d8 4543+ return(0);
fa26e11c
WD
4544+}
4545+
4546+#else /* No ACLs. */
4547+
4df546eb 4548+int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
fa26e11c
WD
4549+{
4550+ errno = ENOSYS;
4551+ return -1;
4552+}
4553+
4df546eb 4554+int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
fa26e11c
WD
4555+{
4556+ errno = ENOSYS;
4557+ return -1;
4558+}
4559+
4df546eb 4560+int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
fa26e11c
WD
4561+{
4562+ errno = ENOSYS;
4563+ return -1;
4564+}
4565+
4df546eb 4566+void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
fa26e11c
WD
4567+{
4568+ errno = ENOSYS;
4569+ return NULL;
4570+}
4571+
4df546eb 4572+SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
fa26e11c
WD
4573+{
4574+ errno = ENOSYS;
5ca9317d 4575+ return (SMB_ACL_T)NULL;
fa26e11c
WD
4576+}
4577+
4df546eb 4578+SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
fa26e11c
WD
4579+{
4580+ errno = ENOSYS;
5ca9317d 4581+ return (SMB_ACL_T)NULL;
fa26e11c
WD
4582+}
4583+
4df546eb 4584+int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
fa26e11c
WD
4585+{
4586+ errno = ENOSYS;
4587+ return -1;
4588+}
4589+
4df546eb 4590+int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
fa26e11c
WD
4591+{
4592+ errno = ENOSYS;
4593+ return -1;
4594+}
4595+
0f6733d8 4596+int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
fa26e11c
WD
4597+{
4598+ errno = ENOSYS;
0f6733d8 4599+ return (permset & perm) ? 1 : 0;
fa26e11c
WD
4600+}
4601+
4df546eb 4602+char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
fa26e11c
WD
4603+{
4604+ errno = ENOSYS;
4605+ return NULL;
4606+}
4607+
4df546eb 4608+int sys_acl_free_text(UNUSED(char *text))
fa26e11c
WD
4609+{
4610+ errno = ENOSYS;
4611+ return -1;
4612+}
4613+
4df546eb 4614+SMB_ACL_T sys_acl_init(UNUSED(int count))
fa26e11c
WD
4615+{
4616+ errno = ENOSYS;
4617+ return NULL;
4618+}
4619+
4df546eb 4620+int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
fa26e11c
WD
4621+{
4622+ errno = ENOSYS;
4623+ return -1;
4624+}
4625+
4df546eb 4626+int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
fa26e11c
WD
4627+{
4628+ errno = ENOSYS;
4629+ return -1;
4630+}
4631+
4df546eb 4632+int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
fa26e11c
WD
4633+{
4634+ errno = ENOSYS;
4635+ return -1;
4636+}
4637+
4df546eb 4638+int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
fa26e11c
WD
4639+{
4640+ errno = ENOSYS;
4641+ return -1;
4642+}
4643+
4df546eb 4644+int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
fa26e11c
WD
4645+{
4646+ errno = ENOSYS;
4647+ return -1;
4648+}
4649+
4df546eb 4650+int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
fa26e11c
WD
4651+{
4652+ errno = ENOSYS;
4653+ return -1;
4654+}
4655+
4df546eb 4656+int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
fa26e11c
WD
4657+{
4658+ errno = ENOSYS;
4659+ return -1;
4660+}
4661+
4df546eb 4662+int sys_acl_delete_def_file(UNUSED(const char *name))
fa26e11c
WD
4663+{
4664+ errno = ENOSYS;
4665+ return -1;
4666+}
4667+
4df546eb 4668+int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
fa26e11c
WD
4669+{
4670+ errno = ENOSYS;
4671+ return -1;
4672+}
4673+
4df546eb 4674+int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
fa26e11c
WD
4675+{
4676+ errno = ENOSYS;
4677+ return -1;
4678+}
4679+
4680+#endif /* No ACLs. */
252945ef
WD
4681+
4682+/************************************************************************
4683+ Deliberately outside the ACL defines. Return 1 if this is a "no acls"
4684+ errno, 0 if not.
4685+************************************************************************/
4686+
4687+int no_acl_syscall_error(int err)
4688+{
4689+#if defined(ENOSYS)
4690+ if (err == ENOSYS) {
4691+ return 1;
4692+ }
4693+#endif
4694+#if defined(ENOTSUP)
4695+ if (err == ENOTSUP) {
4696+ return 1;
4697+ }
4698+#endif
4699+ return 0;
4700+}
9a7eef96
WD
4701--- old/lib/sysacls.h
4702+++ new/lib/sysacls.h
252945ef
WD
4703@@ -0,0 +1,28 @@
4704+#define SMB_MALLOC(cnt) new_array(char, cnt)
4705+#define SMB_MALLOC_P(obj) new_array(obj, 1)
4706+#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
4707+#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
5ca9317d 4708+#define slprintf snprintf
0f6733d8
WD
4709+
4710+int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
4711+int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
4712+int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
4713+void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
4714+SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
4715+SMB_ACL_T sys_acl_get_fd(int fd);
4716+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
4717+int sys_acl_add_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4718+int sys_acl_get_perm(SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
4719+char *sys_acl_to_text(SMB_ACL_T the_acl, ssize_t *plen);
4720+SMB_ACL_T sys_acl_init(int count);
4721+int sys_acl_create_entry(SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
4722+int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
4723+int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry, void *qual);
4724+int sys_acl_set_permset(SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
4725+int sys_acl_valid(SMB_ACL_T theacl);
4726+int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
4727+int sys_acl_set_fd(int fd, SMB_ACL_T theacl);
4728+int sys_acl_delete_def_file(const char *name);
4729+int sys_acl_free_text(char *text);
4730+int sys_acl_free_acl(SMB_ACL_T the_acl);
4731+int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
9a7eef96
WD
4732--- old/mkproto.awk
4733+++ new/mkproto.awk
0f6733d8
WD
4734@@ -58,7 +58,7 @@ BEGIN {
4735 next;
4736 }
4737
bc5988ec
WD
4738-!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
4739+!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
0f6733d8
WD
4740 next;
4741 }
4742
9a7eef96
WD
4743--- old/options.c
4744+++ new/options.c
2578e2b6 4745@@ -45,6 +45,7 @@ int copy_dirlinks = 0;
0f6733d8
WD
4746 int copy_links = 0;
4747 int preserve_links = 0;
4748 int preserve_hard_links = 0;
4749+int preserve_acls = 0;
4750 int preserve_perms = 0;
90fa6d68 4751 int preserve_executability = 0;
0f6733d8 4752 int preserve_devices = 0;
2578e2b6 4753@@ -194,6 +195,7 @@ static void print_rsync_version(enum log
0f6733d8
WD
4754 char const *got_socketpair = "no ";
4755 char const *have_inplace = "no ";
4756 char const *hardlinks = "no ";
4757+ char const *acls = "no ";
4758 char const *links = "no ";
4759 char const *ipv6 = "no ";
4760 STRUCT_STAT *dumstat;
2578e2b6 4761@@ -210,6 +212,10 @@ static void print_rsync_version(enum log
0f6733d8
WD
4762 hardlinks = "";
4763 #endif
4764
09fb8f03 4765+#ifdef SUPPORT_ACLS
0f6733d8
WD
4766+ acls = "";
4767+#endif
4768+
09fb8f03 4769 #ifdef SUPPORT_LINKS
0f6733d8
WD
4770 links = "";
4771 #endif
2578e2b6 4772@@ -223,9 +229,9 @@ static void print_rsync_version(enum log
3b05e91f 4773 rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
0f6733d8
WD
4774 rprintf(f, "<http://rsync.samba.org/>\n");
4775 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
bc5988ec
WD
4776- "%shard links, %ssymlinks, batchfiles,\n",
4777+ "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
0f6733d8
WD
4778 (int) (sizeof (OFF_T) * 8),
4779- got_socketpair, hardlinks, links);
4780+ got_socketpair, hardlinks, acls, links);
4781
4782 /* Note that this field may not have type ino_t. It depends
4783 * on the complicated interaction between largefile feature
2578e2b6
WD
4784@@ -295,6 +301,9 @@ void usage(enum logcode F)
4785 rprintf(F," -H, --hard-links preserve hard links\n");
0f6733d8 4786 rprintf(F," -p, --perms preserve permissions\n");
90fa6d68 4787 rprintf(F," -E, --executability preserve the file's executability\n");
25d385b9 4788+#ifdef SUPPORT_ACLS
0f6733d8 4789+ rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
25d385b9 4790+#endif
90fa6d68
WD
4791 rprintf(F," --chmod=CHMOD change destination permissions\n");
4792 rprintf(F," -o, --owner preserve owner (super-user only)\n");
0f6733d8 4793 rprintf(F," -g, --group preserve group\n");
2578e2b6 4794@@ -410,6 +419,9 @@ static struct poptOption long_options[]
489b0a72
WD
4795 {"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
4796 {"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
90fa6d68 4797 {"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
489b0a72
WD
4798+ {"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
4799+ {"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4800+ {"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
4801 {"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
4802 {"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
4803 {"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
2578e2b6 4804@@ -1068,6 +1080,23 @@ int parse_arguments(int *argc, const cha
3b05e91f
WD
4805 usage(FINFO);
4806 exit_cleanup(0);
0f6733d8
WD
4807
4808+ case 'A':
4df546eb 4809+#ifdef SUPPORT_ACLS
25d385b9 4810+ preserve_acls = preserve_perms = 1;
489b0a72 4811+ break;
0f6733d8
WD
4812+#else
4813+ /* FIXME: this should probably be ignored with a
4814+ * warning and then countermeasures taken to
4815+ * restrict group and other access in the presence
4816+ * of any more restrictive ACLs, but this is safe
4817+ * for now */
4818+ snprintf(err_buf,sizeof(err_buf),
4819+ "ACLs are not supported on this %s\n",
4820+ am_server ? "server" : "client");
4821+ return 0;
25d385b9 4822+#endif
0f6733d8
WD
4823+
4824+
4825 default:
4826 /* A large opt value means that set_refuse_options()
27a7053c 4827 * turned this option off. */
2578e2b6 4828@@ -1511,6 +1540,10 @@ void server_options(char **args,int *arg
c7bc7375 4829
0f6733d8
WD
4830 if (preserve_hard_links)
4831 argstr[x++] = 'H';
25d385b9 4832+#ifdef SUPPORT_ACLS
0f6733d8
WD
4833+ if (preserve_acls)
4834+ argstr[x++] = 'A';
25d385b9 4835+#endif
0f6733d8
WD
4836 if (preserve_uid)
4837 argstr[x++] = 'o';
4838 if (preserve_gid)
9a7eef96
WD
4839--- old/receiver.c
4840+++ new/receiver.c
2578e2b6 4841@@ -46,6 +46,7 @@ extern int keep_partial;
1a2fa68f
WD
4842 extern int checksum_seed;
4843 extern int inplace;
4844 extern int delay_updates;
4845+extern mode_t orig_umask;
4846 extern struct stats stats;
4847 extern char *log_format;
4848 extern char *tmpdir;
2578e2b6 4849@@ -344,6 +345,10 @@ int recv_files(int f_in, struct file_lis
26c810d8
WD
4850 int itemizing = am_daemon ? daemon_log_format_has_i
4851 : !am_server && log_format_has_i;
4852 int max_phase = protocol_version >= 29 ? 2 : 1;
4853+ int dflt_perms = (ACCESSPERMS & ~orig_umask);
5c8b4e6e 4854+#ifdef SUPPORT_ACLS
26c810d8 4855+ char *parent_dirname = "";
5c8b4e6e 4856+#endif
26c810d8
WD
4857 int i, recv_ok;
4858
4859 if (verbose > 2)
2578e2b6 4860@@ -541,7 +546,16 @@ int recv_files(int f_in, struct file_lis
90fa6d68
WD
4861 * mode based on the local permissions and some heuristics. */
4862 if (!preserve_perms) {
4863 int exists = fd1 != -1;
4864- file->mode = dest_mode(file->mode, st.st_mode, exists);
26c810d8 4865+#ifdef SUPPORT_ACLS
5c8b4e6e
WD
4866+ char *dn = file->dirname ? file->dirname : ".";
4867+ if (parent_dirname != dn
4868+ && strcmp(parent_dirname, dn) != 0) {
4869+ dflt_perms = default_perms_for_dir(dn);
4870+ parent_dirname = dn;
26c810d8
WD
4871+ }
4872+#endif
4873+ file->mode = dest_mode(file->mode, st.st_mode,
4874+ dflt_perms, exists);
90fa6d68
WD
4875 }
4876
4877 /* We now check to see if we are writing file "inplace" */
9a7eef96
WD
4878--- old/rsync.c
4879+++ new/rsync.c
c769ea2c 4880@@ -101,7 +101,8 @@ void free_sums(struct sum_struct *s)
90fa6d68
WD
4881
4882 /* This is only called when we aren't preserving permissions. Figure out what
4883 * the permissions should be and return them merged back into the mode. */
02929d4c
WD
4884-mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int exists)
4885+mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
26c810d8 4886+ int exists)
90fa6d68 4887 {
25d385b9 4888 /* If the file already exists, we'll return the local permissions,
90fa6d68 4889 * possibly tweaked by the --executability option. */
c769ea2c 4890@@ -116,7 +117,7 @@ mode_t dest_mode(mode_t flist_mode, mode
02929d4c 4891 cur_mode |= (cur_mode & 0444) >> 2;
90fa6d68 4892 }
26c810d8 4893 } else
02929d4c
WD
4894- cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
4895+ cur_mode = (flist_mode & ACCESSPERMS & dflt_perms) | S_IWUSR;
c769ea2c
WD
4896 if (daemon_chmod_modes && !S_ISLNK(flist_mode))
4897 cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
02929d4c 4898 return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
c769ea2c 4899@@ -217,6 +218,14 @@ int set_file_attrs(char *fname, struct f
0f6733d8
WD
4900 }
4901 #endif
4902
4903+ /* If this is a directory, SET_ACL() will be called on the cleanup
4edb99c8
WD
4904+ * receive_generator() pass (if we called it here, we might clobber
4905+ * writability on the directory). Everything else is OK to do now. */
0f6733d8
WD
4906+ if (!S_ISDIR(st->st_mode)) {
4907+ if (SET_ACL(fname, file) == 0)
4908+ updated = 1;
4909+ }
4910+
90fa6d68 4911 if (verbose > 1 && flags & ATTRS_REPORT) {
1d15f8d9
WD
4912 enum logcode code = daemon_log_format_has_i || dry_run
4913 ? FCLIENT : FINFO;
9a7eef96
WD
4914--- old/rsync.h
4915+++ new/rsync.h
2578e2b6 4916@@ -658,6 +658,44 @@ struct chmod_mode_struct;
bc5988ec
WD
4917
4918 #define UNUSED(x) x __attribute__((__unused__))
0f6733d8 4919
4df546eb
WD
4920+#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
4921+ HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
4922+#define SUPPORT_ACLS 1
4923+#endif
0f6733d8 4924+
4df546eb
WD
4925+#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
4926+#define ACLS_NEED_MASK 1
4927+#endif
0f6733d8 4928+
4df546eb
WD
4929+#ifdef SUPPORT_ACLS
4930+#ifdef HAVE_SYS_ACL_H
0f6733d8
WD
4931+#include <sys/acl.h>
4932+#endif
4933+#define MAKE_ACL(file, fname) make_acl(file, fname)
4934+#define SEND_ACL(file, f) send_acl(file, f)
4935+#define RECEIVE_ACL(file, f) receive_acl(file, f)
4936+#define SORT_FILE_ACL_INDEX_LISTS() sort_file_acl_index_lists()
4937+#define SET_ACL(fname, file) set_acl(fname, file)
4938+#define NEXT_ACL_UID() next_acl_uid()
4939+#define ACL_UID_MAP(uid) acl_uid_map(uid)
4940+#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
4941+ push_keep_backup_acl(file, orig, dest)
4942+#define CLEANUP_KEEP_BACKUP_ACL() cleanup_keep_backup_acl()
4943+#define DUP_ACL(orig, dest, mode) dup_acl(orig, dest, mode)
4944+#else /* SUPPORT_ACLS */
4945+#define MAKE_ACL(file, fname) 1 /* checked return value */
4946+#define SEND_ACL(file, f)
4947+#define RECEIVE_ACL(file, f)
4948+#define SORT_FILE_ACL_INDEX_LISTS()
05b88206 4949+#define SET_ACL(fname, file) 1 /* checked return value */
0f6733d8
WD
4950+#define NEXT_ACL_UID()
4951+#define ACL_UID_MAP(uid)
4952+#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
4953+#define CLEANUP_KEEP_BACKUP_ACL()
05b88206 4954+#define DUP_ACL(src, orig, mode) 1 /* checked return value */
0f6733d8
WD
4955+#endif /* SUPPORT_ACLS */
4956+#include "smb_acls.h"
4957+
4958 #include "proto.h"
4959
4960 /* We have replacement versions of these if they're missing. */
9a7eef96
WD
4961--- old/rsync.yo
4962+++ new/rsync.yo
2578e2b6
WD
4963@@ -321,6 +321,7 @@ to the detailed description below for a
4964 -H, --hard-links preserve hard links
0f6733d8 4965 -p, --perms preserve permissions
90fa6d68
WD
4966 -E, --executability preserve executability
4967+ -A, --acls preserve ACLs (implies -p) [non-standard]
4968 --chmod=CHMOD change destination permissions
4969 -o, --owner preserve owner (super-user only)
0f6733d8 4970 -g, --group preserve group
2578e2b6 4971@@ -742,7 +743,9 @@ quote(itemize(
90fa6d68
WD
4972 permissions, though the bf(--executability) option might change just
4973 the execute permission for the file.
03baf100
WD
4974 it() New files get their "normal" permission bits set to the source
4975- file's permissions masked with the receiving end's umask setting, and
4976+ file's permissions masked with the receiving directory's default
4977+ permissions (either the receiving process's umask, or the permissions
4978+ specified via the destination directory's default ACL), and
4979 their special permission bits disabled except in the case where a new
4980 directory inherits a setgid bit from its parent directory.
90fa6d68 4981 ))
2578e2b6 4982@@ -773,9 +776,11 @@ The preservation of the destination's se
03baf100
WD
4983 directories when bf(--perms) is off was added in rsync 2.6.7. Older rsync
4984 versions erroneously preserved the three special permission bits for
4985 newly-created files when bf(--perms) was off, while overriding the
4986-destination's setgid bit setting on a newly-created directory. (Keep in
4987-mind that it is the version of the receiving rsync that affects this
4988-behavior.)
4989+destination's setgid bit setting on a newly-created directory. Default ACL
4990+observance was added to the ACL patch for rsync 2.6.7, so older (or
4991+non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
4992+(Keep in mind that it is the version of the receiving rsync that affects
4993+these behaviors.)
90fa6d68 4994
90fa6d68
WD
4995 dit(bf(-E, --executability)) This option causes rsync to preserve the
4996 executability (or non-executability) of regular files when bf(--perms) is
2578e2b6 4997@@ -793,6 +798,10 @@ quote(itemize(
90fa6d68
WD
4998
4999 If bf(--perms) is enabled, this option is ignored.
5000
5001+dit(bf(-A, --acls)) This option causes rsync to update the destination
5002+ACLs to be the same as the source ACLs. This nonstandard option only
5003+works if the remote rsync also supports it. bf(--acls) implies bf(--perms).
5004+
5005 dit(bf(--chmod)) This option tells rsync to apply one or more
5006 comma-separated "chmod" strings to the permission of the files in the
5007 transfer. The resulting value is treated as though it was the permissions
9a7eef96
WD
5008--- old/smb_acls.h
5009+++ new/smb_acls.h
0f6733d8
WD
5010@@ -0,0 +1,277 @@
5011+/*
5012+ Unix SMB/Netbios implementation.
5013+ Version 2.2.x
5014+ Portable SMB ACL interface
5015+ Copyright (C) Jeremy Allison 2000
5016+
5017+ This program is free software; you can redistribute it and/or modify
5018+ it under the terms of the GNU General Public License as published by
5019+ the Free Software Foundation; either version 2 of the License, or
5020+ (at your option) any later version.
5021+
5022+ This program is distributed in the hope that it will be useful,
5023+ but WITHOUT ANY WARRANTY; without even the implied warranty of
5024+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5025+ GNU General Public License for more details.
5026+
5027+ You should have received a copy of the GNU General Public License
5028+ along with this program; if not, write to the Free Software
5029+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
5030+*/
5031+
5032+#ifndef _SMB_ACLS_H
5033+#define _SMB_ACLS_H
5034+
5035+#if defined(HAVE_POSIX_ACLS)
5036+
5037+/* This is an identity mapping (just remove the SMB_). */
5038+
5039+#define SMB_ACL_TAG_T acl_tag_t
5040+#define SMB_ACL_TYPE_T acl_type_t
5041+#define SMB_ACL_PERMSET_T acl_permset_t
5042+#define SMB_ACL_PERM_T acl_perm_t
5043+#define SMB_ACL_READ ACL_READ
5044+#define SMB_ACL_WRITE ACL_WRITE
5045+#define SMB_ACL_EXECUTE ACL_EXECUTE
5046+
5047+/* Types of ACLs. */
5048+#define SMB_ACL_USER ACL_USER
5049+#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5050+#define SMB_ACL_GROUP ACL_GROUP
5051+#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5052+#define SMB_ACL_OTHER ACL_OTHER
5053+#define SMB_ACL_MASK ACL_MASK
5054+
5055+#define SMB_ACL_T acl_t
5056+
5057+#define SMB_ACL_ENTRY_T acl_entry_t
5058+
5059+#define SMB_ACL_FIRST_ENTRY ACL_FIRST_ENTRY
5060+#define SMB_ACL_NEXT_ENTRY ACL_NEXT_ENTRY
5061+
5062+#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5063+#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5064+
5065+#elif defined(HAVE_TRU64_ACLS)
5066+
5067+/* This is for DEC/Compaq Tru64 UNIX */
5068+
5069+#define SMB_ACL_TAG_T acl_tag_t
5070+#define SMB_ACL_TYPE_T acl_type_t
5071+#define SMB_ACL_PERMSET_T acl_permset_t
5072+#define SMB_ACL_PERM_T acl_perm_t
5073+#define SMB_ACL_READ ACL_READ
5074+#define SMB_ACL_WRITE ACL_WRITE
5075+#define SMB_ACL_EXECUTE ACL_EXECUTE
5076+
5077+/* Types of ACLs. */
5078+#define SMB_ACL_USER ACL_USER
5079+#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5080+#define SMB_ACL_GROUP ACL_GROUP
5081+#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5082+#define SMB_ACL_OTHER ACL_OTHER
5083+#define SMB_ACL_MASK ACL_MASK
5084+
5085+#define SMB_ACL_T acl_t
5086+
5087+#define SMB_ACL_ENTRY_T acl_entry_t
5088+
5089+#define SMB_ACL_FIRST_ENTRY 0
5090+#define SMB_ACL_NEXT_ENTRY 1
5091+
5092+#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5093+#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5094+
5095+#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
5096+/*
5097+ * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
5098+ * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
5099+ */
5100+
5101+/* SVR4.2 ES/MP ACLs */
5102+typedef int SMB_ACL_TAG_T;
5103+typedef int SMB_ACL_TYPE_T;
5104+typedef ushort *SMB_ACL_PERMSET_T;
5105+typedef ushort SMB_ACL_PERM_T;
5106+#define SMB_ACL_READ 4
5107+#define SMB_ACL_WRITE 2
5108+#define SMB_ACL_EXECUTE 1
5109+
5110+/* Types of ACLs. */
5111+#define SMB_ACL_USER USER
5112+#define SMB_ACL_USER_OBJ USER_OBJ
5113+#define SMB_ACL_GROUP GROUP
5114+#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5115+#define SMB_ACL_OTHER OTHER_OBJ
5116+#define SMB_ACL_MASK CLASS_OBJ
5117+
5118+typedef struct SMB_ACL_T {
5119+ int size;
5120+ int count;
5121+ int next;
5122+ struct acl acl[1];
5123+} *SMB_ACL_T;
5124+
5125+typedef struct acl *SMB_ACL_ENTRY_T;
5126+
5127+#define SMB_ACL_FIRST_ENTRY 0
5128+#define SMB_ACL_NEXT_ENTRY 1
5129+
5130+#define SMB_ACL_TYPE_ACCESS 0
5131+#define SMB_ACL_TYPE_DEFAULT 1
5132+
5133+#elif defined(HAVE_HPUX_ACLS)
5134+
5135+/*
5136+ * Based on the Solaris & UnixWare code.
5137+ */
5138+
5139+#undef GROUP
5140+#include <sys/aclv.h>
5141+
5142+/* SVR4.2 ES/MP ACLs */
5143+typedef int SMB_ACL_TAG_T;
5144+typedef int SMB_ACL_TYPE_T;
5145+typedef ushort *SMB_ACL_PERMSET_T;
5146+typedef ushort SMB_ACL_PERM_T;
5147+#define SMB_ACL_READ 4
5148+#define SMB_ACL_WRITE 2
5149+#define SMB_ACL_EXECUTE 1
5150+
5151+/* Types of ACLs. */
5152+#define SMB_ACL_USER USER
5153+#define SMB_ACL_USER_OBJ USER_OBJ
5154+#define SMB_ACL_GROUP GROUP
5155+#define SMB_ACL_GROUP_OBJ GROUP_OBJ
5156+#define SMB_ACL_OTHER OTHER_OBJ
5157+#define SMB_ACL_MASK CLASS_OBJ
5158+
5159+typedef struct SMB_ACL_T {
5160+ int size;
5161+ int count;
5162+ int next;
5163+ struct acl acl[1];
5164+} *SMB_ACL_T;
5165+
5166+typedef struct acl *SMB_ACL_ENTRY_T;
5167+
5168+#define SMB_ACL_FIRST_ENTRY 0
5169+#define SMB_ACL_NEXT_ENTRY 1
5170+
5171+#define SMB_ACL_TYPE_ACCESS 0
5172+#define SMB_ACL_TYPE_DEFAULT 1
5173+
5174+#elif defined(HAVE_IRIX_ACLS)
5175+
5176+#define SMB_ACL_TAG_T acl_tag_t
5177+#define SMB_ACL_TYPE_T acl_type_t
5178+#define SMB_ACL_PERMSET_T acl_permset_t
5179+#define SMB_ACL_PERM_T acl_perm_t
5180+#define SMB_ACL_READ ACL_READ
5181+#define SMB_ACL_WRITE ACL_WRITE
5182+#define SMB_ACL_EXECUTE ACL_EXECUTE
5183+
5184+/* Types of ACLs. */
5185+#define SMB_ACL_USER ACL_USER
5186+#define SMB_ACL_USER_OBJ ACL_USER_OBJ
5187+#define SMB_ACL_GROUP ACL_GROUP
5188+#define SMB_ACL_GROUP_OBJ ACL_GROUP_OBJ
5189+#define SMB_ACL_OTHER ACL_OTHER_OBJ
5190+#define SMB_ACL_MASK ACL_MASK
5191+
5192+typedef struct SMB_ACL_T {
5193+ int next;
5194+ BOOL freeaclp;
5195+ struct acl *aclp;
5196+} *SMB_ACL_T;
5197+
5198+#define SMB_ACL_ENTRY_T acl_entry_t
5199+
5200+#define SMB_ACL_FIRST_ENTRY 0
5201+#define SMB_ACL_NEXT_ENTRY 1
5202+
5203+#define SMB_ACL_TYPE_ACCESS ACL_TYPE_ACCESS
5204+#define SMB_ACL_TYPE_DEFAULT ACL_TYPE_DEFAULT
5205+
5206+#elif defined(HAVE_AIX_ACLS)
5207+
5208+/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
5209+
5210+#include "/usr/include/acl.h"
5211+
5212+typedef uint *SMB_ACL_PERMSET_T;
5213+
5214+struct acl_entry_link{
5215+ struct acl_entry_link *prevp;
5216+ struct new_acl_entry *entryp;
5217+ struct acl_entry_link *nextp;
5218+ int count;
5219+};
5220+
5221+struct new_acl_entry{
5222+ unsigned short ace_len;
5223+ unsigned short ace_type;
5224+ unsigned int ace_access;
5225+ struct ace_id ace_id[1];
5226+};
5227+
5228+#define SMB_ACL_ENTRY_T struct new_acl_entry*
5229+#define SMB_ACL_T struct acl_entry_link*
5230+
5231+#define SMB_ACL_TAG_T unsigned short
5232+#define SMB_ACL_TYPE_T int
5233+#define SMB_ACL_PERM_T uint
5234+#define SMB_ACL_READ S_IRUSR
5235+#define SMB_ACL_WRITE S_IWUSR
5236+#define SMB_ACL_EXECUTE S_IXUSR
5237+
5238+/* Types of ACLs. */
5239+#define SMB_ACL_USER ACEID_USER
5240+#define SMB_ACL_USER_OBJ 3
5241+#define SMB_ACL_GROUP ACEID_GROUP
5242+#define SMB_ACL_GROUP_OBJ 4
5243+#define SMB_ACL_OTHER 5
5244+#define SMB_ACL_MASK 6
5245+
5246+
5247+#define SMB_ACL_FIRST_ENTRY 1
5248+#define SMB_ACL_NEXT_ENTRY 2
5249+
5250+#define SMB_ACL_TYPE_ACCESS 0
5251+#define SMB_ACL_TYPE_DEFAULT 1
5252+
5253+#else /* No ACLs. */
5254+
5255+/* No ACLS - fake it. */
5256+#define SMB_ACL_TAG_T int
5257+#define SMB_ACL_TYPE_T int
5258+#define SMB_ACL_PERMSET_T mode_t
5259+#define SMB_ACL_PERM_T mode_t
5260+#define SMB_ACL_READ S_IRUSR
5261+#define SMB_ACL_WRITE S_IWUSR
5262+#define SMB_ACL_EXECUTE S_IXUSR
5263+
5264+/* Types of ACLs. */
5265+#define SMB_ACL_USER 0
5266+#define SMB_ACL_USER_OBJ 1
5267+#define SMB_ACL_GROUP 2
5268+#define SMB_ACL_GROUP_OBJ 3
5269+#define SMB_ACL_OTHER 4
5270+#define SMB_ACL_MASK 5
5271+
5272+typedef struct SMB_ACL_T {
5273+ int dummy;
5274+} *SMB_ACL_T;
5275+
5276+typedef struct SMB_ACL_ENTRY_T {
5277+ int dummy;
5278+} *SMB_ACL_ENTRY_T;
5279+
5280+#define SMB_ACL_FIRST_ENTRY 0
5281+#define SMB_ACL_NEXT_ENTRY 1
5282+
5283+#define SMB_ACL_TYPE_ACCESS 0
5284+#define SMB_ACL_TYPE_DEFAULT 1
5285+
5286+#endif /* No ACLs. */
5287+#endif /* _SMB_ACLS_H */
9a7eef96
WD
5288--- old/testsuite/default-acls.test
5289+++ new/testsuite/default-acls.test
bb81ee98 5290@@ -0,0 +1,55 @@
90fa6d68
WD
5291+#! /bin/sh
5292+
5293+# This program is distributable under the terms of the GNU GPL see
5294+# COPYING).
5295+
5296+# Test that rsync obeys default ACLs. -- Matt McCutchen
5297+
5298+. $srcdir/testsuite/rsync.fns
5299+
25d385b9 5300+$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
90fa6d68
WD
5301+setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
5302+
90fa6d68 5303+# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
25d385b9 5304+testit() {
90fa6d68
WD
5305+ todir="$scratchdir/$1"
5306+ mkdir "$todir"
25d385b9 5307+ # FIXME This doesn't work on solaris...
90fa6d68 5308+ setfacl -k "$todir"
90fa6d68
WD
5309+ [ "$2" ] && setfacl -dm "$2" "$todir"
5310+ # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
5311+ # even though the directory itself is outside the transfer
25d385b9 5312+ $RSYNC -rvv "$scratchdir/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
0251480d 5313+ check_perms "$todir/to" $4 "Target $1"
25d385b9 5314+ check_perms "$todir/to/dir" $4 "Target $1"
0251480d
WD
5315+ check_perms "$todir/to/file" $3 "Target $1"
5316+ check_perms "$todir/to/program" $4 "Target $1"
90fa6d68
WD
5317+ # Make sure get_local_name doesn't mess us up when transferring only one file
5318+ $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
0251480d 5319+ check_perms "$todir/to/anotherfile" $3 "Target $1"
bb81ee98 5320+ # Make sure we obey default ACLs when not transferring a regular file
2578e2b6 5321+ $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
bb81ee98 5322+ check_perms "$todir/to/anotherdir" $4 "Target $1"
90fa6d68
WD
5323+}
5324+
25d385b9 5325+mkdir "$scratchdir/dir"
0251480d 5326+echo "File!" >"$scratchdir/file"
25d385b9
WD
5327+echo "#!/bin/sh" >"$scratchdir/program"
5328+chmod 777 "$scratchdir/dir"
0251480d
WD
5329+chmod 666 "$scratchdir/file"
5330+chmod 777 "$scratchdir/program"
5331+
90fa6d68
WD
5332+# Test some target directories
5333+umask 0077
0251480d
WD
5334+testit da777 u::rwx,g::rwx,o::rwx rw-rw-rw- rwxrwxrwx
5335+testit da775 u::rwx,g::rwx,o::r-x rw-rw-r-- rwxrwxr-x
5336+testit da750 u::rwx,g::r-x,o::--- rw-r----- rwxr-x---
5337+testit da770mask u::rwx,g::---,m::rwx,o::--- rw-rw---- rwxrwx---
5338+testit noda1 '' rw------- rwx------
90fa6d68 5339+umask 0000
0251480d 5340+testit noda2 '' rw-rw-rw- rwxrwxrwx
90fa6d68 5341+umask 0022
0251480d 5342+testit noda3 '' rw-r--r-- rwxr-xr-x
90fa6d68
WD
5343+
5344+# Hooray
5345+exit 0
9a7eef96
WD
5346--- old/uidlist.c
5347+++ new/uidlist.c
fa26e11c
WD
5348@@ -34,6 +34,7 @@
5349 extern int verbose;
5350 extern int preserve_uid;
5351 extern int preserve_gid;
5352+extern int preserve_acls;
5353 extern int numeric_ids;
5354 extern int am_root;
5355
5356@@ -274,7 +275,7 @@ void send_uid_list(int f)
5357 if (numeric_ids)
5358 return;
5359
5360- if (preserve_uid) {
5361+ if (preserve_uid || preserve_acls) {
5362 int len;
5363 /* we send sequences of uid/byte-length/name */
5364 for (list = uidlist; list; list = list->next) {
5365@@ -291,7 +292,7 @@ void send_uid_list(int f)
5366 write_int(f, 0);
5367 }
5368
5369- if (preserve_gid) {
5370+ if (preserve_gid || preserve_acls) {
5371 int len;
5372 for (list = gidlist; list; list = list->next) {
5373 if (!list->name)
5374@@ -312,7 +313,7 @@ void recv_uid_list(int f, struct file_li
5375 int id, i;
5376 char *name;
5377
5378- if (preserve_uid && !numeric_ids) {
5379+ if ((preserve_uid || preserve_acls) && !numeric_ids) {
5380 /* read the uid list */
5381 while ((id = read_int(f)) != 0) {
5382 int len = read_byte(f);
6849cd84
WD
5383@@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
5384 }
fa26e11c
WD
5385 }
5386
fa26e11c
WD
5387- if (preserve_gid && !numeric_ids) {
5388+ if ((preserve_gid || preserve_acls) && !numeric_ids) {
5389 /* read the gid list */
5390 while ((id = read_int(f)) != 0) {
5391 int len = read_byte(f);
6849cd84 5392@@ -336,6 +337,18 @@ void recv_uid_list(int f, struct file_li
fa26e11c
WD
5393 }
5394 }
125d7fca 5395
4edb99c8 5396+#ifdef SUPPORT_ACLS
fa26e11c
WD
5397+ if (preserve_acls && !numeric_ids) {
5398+ id_t id;
4edb99c8
WD
5399+ /* The enumerations don't return 0 except to flag the last
5400+ * entry, since uidlist doesn't munge 0 anyway. */
5401+ while ((id = next_acl_uid(flist)) != 0)
fa26e11c 5402+ acl_uid_map(match_uid(id));
4edb99c8 5403+ while ((id = next_acl_gid(flist)) != 0)
fa26e11c
WD
5404+ acl_gid_map(match_gid(id));
5405+ }
5406+#endif /* SUPPORT_ACLS */
125d7fca 5407+
90fa6d68 5408 /* Now convert all the uids/gids from sender values to our values. */
125d7fca 5409 if (am_root && preserve_uid && !numeric_ids) {
90fa6d68 5410 for (i = 0; i < flist->count; i++)