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