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