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