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