annotate lib/set-mode-acl.c @ 17160:72f4bab621be

fts: introduce FTS_VERBATIM This gives clients the option to disable stripping of trailing slashes from input path names during fts_open initialization. The recent change v0.0-7611-g3a9002d that made fts_open strip trailing slashes from input path names had a negative impact on findutils that relies on the old fts_open behavior to implement POSIX requirement that each path operand of the find utility shall be evaluated unaltered as it was provided, including all trailing slash characters. * lib/fts_.h (FTS_VERBATIM): New bit flag. (FTS_OPTIONMASK, FTS_NAMEONLY, FTS_STOP): Adjust. * lib/fts.c (fts_open): Honor it.
author Dmitry V. Levin <ldv@altlinux.org>
date Sun, 18 Nov 2012 04:40:18 +0400
parents 16d02df1b46e
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* set-mode-acl.c - set access control list equivalent to a mode
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 15593
diff changeset
3 Copyright (C) 2002-2003, 2005-2012 Free Software Foundation, Inc.
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
10184
9da2345fe8f6 Add me as co-author.
Bruno Haible <bruno@clisp.org>
parents: 10183
diff changeset
18 Written by Paul Eggert and Andreas Gruenbacher, and Bruno Haible. */
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <config.h>
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
17098
16d02df1b46e acl, mbchar, priv-set: use extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents: 16935
diff changeset
22 #define ACL_INTERNAL_INLINE _GL_EXTERN_INLINE
16d02df1b46e acl, mbchar, priv-set: use extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents: 16935
diff changeset
23
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include "acl.h"
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include "acl-internal.h"
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
10198
5056e8a13405 Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents: 10191
diff changeset
28 #include "gettext.h"
5056e8a13405 Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents: 10191
diff changeset
29 #define _(msgid) gettext (msgid)
5056e8a13405 Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents: 10191
diff changeset
30
5056e8a13405 Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents: 10191
diff changeset
31
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 /* If DESC is a valid file descriptor use fchmod to change the
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 file's mode to MODE on systems that have fchown. On systems
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 that don't have fchown and if DESC is invalid, use chown on
10169
7215efd0ff4f Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents: 10168
diff changeset
35 NAME instead.
7215efd0ff4f Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents: 10168
diff changeset
36 Return 0 if successful. Return -1 and set errno upon failure. */
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 int
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 chmod_or_fchmod (const char *name, int desc, mode_t mode)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 if (HAVE_FCHMOD && desc != -1)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 return fchmod (desc, mode);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 else
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 return chmod (name, mode);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 /* Set the access control lists of a file. If DESC is a valid file
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 descriptor, use file descriptor operations where available, else use
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 filename based operations on NAME. If access control lists are not
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 available, fchmod the target file to MODE. Also sets the
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 non-permission bits of the destination file (S_ISUID, S_ISGID, S_ISVTX)
10150
0c9f7838132c Document qset_acl return value precisely.
Bruno Haible <bruno@clisp.org>
parents: 10126
diff changeset
52 to those from MODE if any are set.
0c9f7838132c Document qset_acl return value precisely.
Bruno Haible <bruno@clisp.org>
parents: 10126
diff changeset
53 Return 0 if successful. Return -1 and set errno upon failure. */
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 int
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 qset_acl (char const *name, int desc, mode_t mode)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 {
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 #if USE_ACL
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
59 # if HAVE_ACL_GET_FILE
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 /* POSIX 1003.1e draft 17 (abandoned) specific version. */
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
61 /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */
15575
3e19c8849877 acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents: 15572
diff changeset
62 # if !HAVE_ACL_TYPE_EXTENDED
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 /* Linux, FreeBSD, IRIX, Tru64 */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* We must also have acl_from_text and acl_delete_def_file.
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 (acl_delete_def_file could be emulated with acl_init followed
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 by acl_set_file, but acl_set_file with an empty acl is
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 unspecified.) */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 # ifndef HAVE_ACL_FROM_TEXT
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 # error Must have acl_from_text (see POSIX 1003.1e draft 17).
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 # endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 # ifndef HAVE_ACL_DELETE_DEF_FILE
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 # error Must have acl_delete_def_file (see POSIX 1003.1e draft 17).
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 # endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 acl_t acl;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 int ret;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 if (HAVE_ACL_FROM_MODE) /* Linux */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 {
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 acl = acl_from_mode (mode);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 if (!acl)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
84 return -1;
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 else /* FreeBSD, IRIX, Tru64 */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 {
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 /* If we were to create the ACL using the functions acl_init(),
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
89 acl_create_entry(), acl_set_tag_type(), acl_set_qualifier(),
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
90 acl_get_permset(), acl_clear_perm[s](), acl_add_perm(), we
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
91 would need to create a qualifier. I don't know how to do this.
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
92 So create it using acl_from_text(). */
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 # if HAVE_ACL_FREE_TEXT /* Tru64 */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 char acl_text[] = "u::---,g::---,o::---,";
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 # else /* FreeBSD, IRIX */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 char acl_text[] = "u::---,g::---,o::---";
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 # endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 if (mode & S_IRUSR) acl_text[ 3] = 'r';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 if (mode & S_IWUSR) acl_text[ 4] = 'w';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 if (mode & S_IXUSR) acl_text[ 5] = 'x';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 if (mode & S_IRGRP) acl_text[10] = 'r';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 if (mode & S_IWGRP) acl_text[11] = 'w';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 if (mode & S_IXGRP) acl_text[12] = 'x';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 if (mode & S_IROTH) acl_text[17] = 'r';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 if (mode & S_IWOTH) acl_text[18] = 'w';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 if (mode & S_IXOTH) acl_text[19] = 'x';
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 acl = acl_from_text (acl_text);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 if (!acl)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
112 return -1;
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 if (HAVE_ACL_SET_FD && desc != -1)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 ret = acl_set_fd (desc, acl);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 else
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 ret = acl_set_file (name, ACL_TYPE_ACCESS, acl);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 if (ret != 0)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 {
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 int saved_errno = errno;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 acl_free (acl);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 if (ACL_NOT_WELL_SUPPORTED (errno))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
124 return chmod_or_fchmod (name, desc, mode);
10176
43bafd6ea0d8 Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
125 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
126 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
127 errno = saved_errno;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
128 return -1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
129 }
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 else
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 acl_free (acl);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 if (S_ISDIR (mode) && acl_delete_def_file (name))
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 return -1;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136
15575
3e19c8849877 acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents: 15572
diff changeset
137 if (!MODE_INSIDE_ACL || (mode & (S_ISUID | S_ISGID | S_ISVTX)))
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 {
15575
3e19c8849877 acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents: 15572
diff changeset
139 /* We did not call chmod so far, and either the mode and the ACL are
3e19c8849877 acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents: 15572
diff changeset
140 separate or special bits are to be set which don't fit into ACLs. */
10176
43bafd6ea0d8 Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
141 return chmod_or_fchmod (name, desc, mode);
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 return 0;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144
15575
3e19c8849877 acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents: 15572
diff changeset
145 # else /* HAVE_ACL_TYPE_EXTENDED */
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
146 /* Mac OS X */
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
148 /* On Mac OS X, acl_get_file (name, ACL_TYPE_ACCESS)
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
149 and acl_get_file (name, ACL_TYPE_DEFAULT)
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
150 always return NULL / EINVAL. You have to use
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
151 acl_get_file (name, ACL_TYPE_EXTENDED)
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
152 or acl_get_fd (open (name, ...))
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
153 to retrieve an ACL.
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
154 On the other hand,
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
155 acl_set_file (name, ACL_TYPE_ACCESS, acl)
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
156 and acl_set_file (name, ACL_TYPE_DEFAULT, acl)
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
157 have the same effect as
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16382
diff changeset
158 acl_set_file (name, ACL_TYPE_EXTENDED, acl):
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
159 Each of these calls sets the file's ACL. */
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
160
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 acl_t acl;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 int ret;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 /* Remove the ACL if the file has ACLs. */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 if (HAVE_ACL_GET_FD && desc != -1)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 acl = acl_get_fd (desc);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 else
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
168 acl = acl_get_file (name, ACL_TYPE_EXTENDED);
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 if (acl)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 {
10171
f988df7e273d Fix memory leak introduced on 2008-05-22.
Bruno Haible <bruno@clisp.org>
parents: 10170
diff changeset
171 acl_free (acl);
f988df7e273d Fix memory leak introduced on 2008-05-22.
Bruno Haible <bruno@clisp.org>
parents: 10170
diff changeset
172
10170
75a6b6b966a8 Avoid needing to know the textual representation of an ACL when possible.
Bruno Haible <bruno@clisp.org>
parents: 10169
diff changeset
173 acl = acl_init (0);
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 if (acl)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
175 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
176 if (HAVE_ACL_SET_FD && desc != -1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
177 ret = acl_set_fd (desc, acl);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
178 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
179 ret = acl_set_file (name, ACL_TYPE_EXTENDED, acl);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
180 if (ret != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
181 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
182 int saved_errno = errno;
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
184 acl_free (acl);
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
186 if (ACL_NOT_WELL_SUPPORTED (saved_errno))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
187 return chmod_or_fchmod (name, desc, mode);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
188 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
189 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
190 errno = saved_errno;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
191 return -1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
192 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
193 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
194 acl_free (acl);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
195 }
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197
10176
43bafd6ea0d8 Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
198 /* Since !MODE_INSIDE_ACL, we have to call chmod explicitly. */
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 return chmod_or_fchmod (name, desc, mode);
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
200 # endif
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
201
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
202 # elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
203
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
204 int done_setacl = 0;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
205
15572
dd7c06a51643 acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents: 15567
diff changeset
206 # ifdef ACE_GETACL
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
207 /* Solaris also has a different variant of ACLs, used in ZFS and NFSv4
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
208 file systems (whereas the other ones are used in UFS file systems). */
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
209
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
210 /* The flags in the ace_t structure changed in a binary incompatible way
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
211 when ACL_NO_TRIVIAL etc. were introduced in <sys/acl.h> version 1.15.
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
212 How to distinguish the two conventions at runtime?
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
213 We fetch the existing ACL. In the old convention, usually three ACEs have
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
214 a_flags = ACE_OWNER / ACE_GROUP / ACE_OTHER, in the range 0x0100..0x0400.
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
215 In the new convention, these values are not used. */
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
216 int convention;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
217
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
218 {
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
219 /* Initially, try to read the entries into a stack-allocated buffer.
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
220 Use malloc if it does not fit. */
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
221 enum
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
222 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
223 alloc_init = 4000 / sizeof (ace_t), /* >= 3 */
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
224 alloc_max = MIN (INT_MAX, SIZE_MAX / sizeof (ace_t))
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
225 };
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
226 ace_t buf[alloc_init];
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
227 size_t alloc = alloc_init;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
228 ace_t *entries = buf;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
229 ace_t *malloced = NULL;
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
230 int count;
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
231
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
232 for (;;)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
233 {
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
234 count = (desc != -1
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
235 ? facl (desc, ACE_GETACL, alloc, entries)
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
236 : acl (name, ACE_GETACL, alloc, entries));
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
237 if (count < 0 && errno == ENOSPC)
16381
fc5c37ccbece acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents: 16269
diff changeset
238 {
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
239 /* Increase the size of the buffer. */
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
240 free (malloced);
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
241 if (alloc > alloc_max / 2)
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
242 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
243 errno = ENOMEM;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
244 return -1;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
245 }
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
246 alloc = 2 * alloc; /* <= alloc_max */
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
247 entries = malloced = (ace_t *) malloc (alloc * sizeof (ace_t));
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
248 if (entries == NULL)
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
249 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
250 errno = ENOMEM;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
251 return -1;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
252 }
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
253 continue;
16381
fc5c37ccbece acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents: 16269
diff changeset
254 }
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
255 break;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
256 }
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
257
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
258 if (count <= 0)
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
259 convention = -1;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
260 else
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
261 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
262 int i;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
263
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
264 convention = 0;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
265 for (i = 0; i < count; i++)
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
266 if (entries[i].a_flags & (OLD_ACE_OWNER | OLD_ACE_GROUP | OLD_ACE_OTHER))
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
267 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
268 convention = 1;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
269 break;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
270 }
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
271 }
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
272 free (malloced);
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
273 }
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
274
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
275 if (convention >= 0)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
276 {
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
277 ace_t entries[6];
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
278 int count;
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
279 int ret;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
280
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
281 if (convention)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
282 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
283 /* Running on Solaris 10. */
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
284 entries[0].a_type = OLD_ALLOW;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
285 entries[0].a_flags = OLD_ACE_OWNER;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
286 entries[0].a_who = 0; /* irrelevant */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
287 entries[0].a_access_mask = (mode >> 6) & 7;
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
288 entries[1].a_type = OLD_ALLOW;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
289 entries[1].a_flags = OLD_ACE_GROUP;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
290 entries[1].a_who = 0; /* irrelevant */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
291 entries[1].a_access_mask = (mode >> 3) & 7;
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
292 entries[2].a_type = OLD_ALLOW;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
293 entries[2].a_flags = OLD_ACE_OTHER;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
294 entries[2].a_who = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
295 entries[2].a_access_mask = mode & 7;
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
296 count = 3;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
297 }
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
298 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
299 {
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
300 /* Running on Solaris 10 (newer version) or Solaris 11.
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
301 The details here were found through "/bin/ls -lvd somefiles". */
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
302 entries[0].a_type = NEW_ACE_ACCESS_DENIED_ACE_TYPE;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
303 entries[0].a_flags = NEW_ACE_OWNER;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
304 entries[0].a_who = 0; /* irrelevant */
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
305 entries[0].a_access_mask = 0;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
306 entries[1].a_type = NEW_ACE_ACCESS_ALLOWED_ACE_TYPE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
307 entries[1].a_flags = NEW_ACE_OWNER;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
308 entries[1].a_who = 0; /* irrelevant */
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
309 entries[1].a_access_mask = NEW_ACE_WRITE_NAMED_ATTRS
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
310 | NEW_ACE_WRITE_ATTRIBUTES
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
311 | NEW_ACE_WRITE_ACL
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
312 | NEW_ACE_WRITE_OWNER;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
313 if (mode & 0400)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
314 entries[1].a_access_mask |= NEW_ACE_READ_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
315 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
316 entries[0].a_access_mask |= NEW_ACE_READ_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
317 if (mode & 0200)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
318 entries[1].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
319 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
320 entries[0].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
321 if (mode & 0100)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
322 entries[1].a_access_mask |= NEW_ACE_EXECUTE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
323 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
324 entries[0].a_access_mask |= NEW_ACE_EXECUTE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
325 entries[2].a_type = NEW_ACE_ACCESS_DENIED_ACE_TYPE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
326 entries[2].a_flags = NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
327 entries[2].a_who = 0; /* irrelevant */
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
328 entries[2].a_access_mask = 0;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
329 entries[3].a_type = NEW_ACE_ACCESS_ALLOWED_ACE_TYPE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
330 entries[3].a_flags = NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
331 entries[3].a_who = 0; /* irrelevant */
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
332 entries[3].a_access_mask = 0;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
333 if (mode & 0040)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
334 entries[3].a_access_mask |= NEW_ACE_READ_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
335 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
336 entries[2].a_access_mask |= NEW_ACE_READ_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
337 if (mode & 0020)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
338 entries[3].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
339 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
340 entries[2].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
341 if (mode & 0010)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
342 entries[3].a_access_mask |= NEW_ACE_EXECUTE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
343 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
344 entries[2].a_access_mask |= NEW_ACE_EXECUTE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
345 entries[4].a_type = NEW_ACE_ACCESS_DENIED_ACE_TYPE;
15593
270852a80105 acl: Fix compilation on Solaris 10 (older version).
Bruno Haible <bruno@clisp.org>
parents: 15575
diff changeset
346 entries[4].a_flags = NEW_ACE_EVERYONE;
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
347 entries[4].a_who = 0;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
348 entries[4].a_access_mask = NEW_ACE_WRITE_NAMED_ATTRS
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
349 | NEW_ACE_WRITE_ATTRIBUTES
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
350 | NEW_ACE_WRITE_ACL
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
351 | NEW_ACE_WRITE_OWNER;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
352 entries[5].a_type = NEW_ACE_ACCESS_ALLOWED_ACE_TYPE;
15593
270852a80105 acl: Fix compilation on Solaris 10 (older version).
Bruno Haible <bruno@clisp.org>
parents: 15575
diff changeset
353 entries[5].a_flags = NEW_ACE_EVERYONE;
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
354 entries[5].a_who = 0;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
355 entries[5].a_access_mask = NEW_ACE_READ_NAMED_ATTRS
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
356 | NEW_ACE_READ_ATTRIBUTES
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
357 | NEW_ACE_READ_ACL
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
358 | NEW_ACE_SYNCHRONIZE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
359 if (mode & 0004)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
360 entries[5].a_access_mask |= NEW_ACE_READ_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
361 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
362 entries[4].a_access_mask |= NEW_ACE_READ_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
363 if (mode & 0002)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
364 entries[5].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
365 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
366 entries[4].a_access_mask |= NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
367 if (mode & 0001)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
368 entries[5].a_access_mask |= NEW_ACE_EXECUTE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
369 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
370 entries[4].a_access_mask |= NEW_ACE_EXECUTE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
371 count = 6;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
372 }
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
373 if (desc != -1)
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
374 ret = facl (desc, ACE_SETACL, count, entries);
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
375 else
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
376 ret = acl (name, ACE_SETACL, count, entries);
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
377 if (ret < 0 && errno != EINVAL && errno != ENOTSUP)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
378 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
379 if (errno == ENOSYS)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
380 return chmod_or_fchmod (name, desc, mode);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
381 return -1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
382 }
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
383 if (ret == 0)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
384 done_setacl = 1;
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
385 }
15572
dd7c06a51643 acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents: 15567
diff changeset
386 # endif
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
387
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
388 if (!done_setacl)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
389 {
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
390 aclent_t entries[3];
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
391 int ret;
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
392
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
393 entries[0].a_type = USER_OBJ;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
394 entries[0].a_id = 0; /* irrelevant */
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
395 entries[0].a_perm = (mode >> 6) & 7;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
396 entries[1].a_type = GROUP_OBJ;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
397 entries[1].a_id = 0; /* irrelevant */
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
398 entries[1].a_perm = (mode >> 3) & 7;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
399 entries[2].a_type = OTHER_OBJ;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
400 entries[2].a_id = 0;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
401 entries[2].a_perm = mode & 7;
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
402
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
403 if (desc != -1)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
404 ret = facl (desc, SETACL,
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
405 sizeof (entries) / sizeof (aclent_t), entries);
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
406 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
407 ret = acl (name, SETACL,
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
408 sizeof (entries) / sizeof (aclent_t), entries);
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
409 if (ret < 0)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
410 {
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
411 if (errno == ENOSYS || errno == EOPNOTSUPP)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
412 return chmod_or_fchmod (name, desc, mode);
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
413 return -1;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
414 }
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
415 }
10184
9da2345fe8f6 Add me as co-author.
Bruno Haible <bruno@clisp.org>
parents: 10183
diff changeset
416
10181
5282ccc922b9 Add support for Cygwin ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10180
diff changeset
417 if (!MODE_INSIDE_ACL || (mode & (S_ISUID | S_ISGID | S_ISVTX)))
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
418 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
419 /* We did not call chmod so far, so the special bits have not yet
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
420 been set. */
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
421 return chmod_or_fchmod (name, desc, mode);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
422 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
423 return 0;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
424
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
425 # elif HAVE_GETACL /* HP-UX */
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
426
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
427 struct stat statbuf;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
428 int ret;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
429
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
430 if (desc != -1)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
431 ret = fstat (desc, &statbuf);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
432 else
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
433 ret = stat (name, &statbuf);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
434 if (ret < 0)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
435 return -1;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
436
14905
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
437 {
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
438 struct acl_entry entries[3];
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
439
14905
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
440 entries[0].uid = statbuf.st_uid;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
441 entries[0].gid = ACL_NSGROUP;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
442 entries[0].mode = (mode >> 6) & 7;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
443 entries[1].uid = ACL_NSUSER;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
444 entries[1].gid = statbuf.st_gid;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
445 entries[1].mode = (mode >> 3) & 7;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
446 entries[2].uid = ACL_NSUSER;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
447 entries[2].gid = ACL_NSGROUP;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
448 entries[2].mode = mode & 7;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
449
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
450 if (desc != -1)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
451 ret = fsetacl (desc, sizeof (entries) / sizeof (struct acl_entry), entries);
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
452 else
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
453 ret = setacl (name, sizeof (entries) / sizeof (struct acl_entry), entries);
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
454 }
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
455 if (ret < 0)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
456 {
14905
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
457 if (!(errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP))
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
458 return -1;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
459
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
460 # if HAVE_ACLV_H /* HP-UX >= 11.11 */
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
461 {
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
462 struct acl entries[4];
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
463
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
464 entries[0].a_type = USER_OBJ;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
465 entries[0].a_id = 0; /* irrelevant */
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
466 entries[0].a_perm = (mode >> 6) & 7;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
467 entries[1].a_type = GROUP_OBJ;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
468 entries[1].a_id = 0; /* irrelevant */
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
469 entries[1].a_perm = (mode >> 3) & 7;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
470 entries[2].a_type = CLASS_OBJ;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
471 entries[2].a_id = 0;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
472 entries[2].a_perm = (mode >> 3) & 7;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
473 entries[3].a_type = OTHER_OBJ;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
474 entries[3].a_id = 0;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
475 entries[3].a_perm = mode & 7;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
476
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
477 ret = aclsort (sizeof (entries) / sizeof (struct acl), 1, entries);
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
478 if (ret > 0)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
479 abort ();
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
480 if (ret < 0)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
481 {
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
482 if (0)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
483 return chmod_or_fchmod (name, desc, mode);
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
484 return -1;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
485 }
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
486
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
487 ret = acl ((char *) name, ACL_SET,
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
488 sizeof (entries) / sizeof (struct acl), entries);
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
489 if (ret < 0)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
490 {
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
491 if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
492 return chmod_or_fchmod (name, desc, mode);
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
493 return -1;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
494 }
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
495 }
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
496 # else
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
497 return chmod_or_fchmod (name, desc, mode);
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
498 # endif
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
499 }
10184
9da2345fe8f6 Add me as co-author.
Bruno Haible <bruno@clisp.org>
parents: 10183
diff changeset
500
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
501 if (mode & (S_ISUID | S_ISGID | S_ISVTX))
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
502 {
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
503 /* We did not call chmod so far, so the special bits have not yet
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
504 been set. */
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
505 return chmod_or_fchmod (name, desc, mode);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
506 }
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
507 return 0;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
508
12077
72b0c1288a50 Disable untested support for new flavours of ACLs on AIX.
Bruno Haible <bruno@clisp.org>
parents: 12075
diff changeset
509 # elif HAVE_ACLX_GET && defined ACL_AIX_WIP /* AIX */
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
510
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
511 acl_type_list_t types;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
512 size_t types_size = sizeof (types);
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
513 acl_type_t type;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
514
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
515 if (aclx_gettypes (name, &types, &types_size) < 0
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
516 || types.num_entries == 0)
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
517 return chmod_or_fchmod (name, desc, mode);
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
518
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
519 /* XXX Do we need to clear all types of ACLs for the given file, or is it
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
520 sufficient to clear the first one? */
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
521 type = types.entries[0];
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
522 if (type.u64 == ACL_AIXC)
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
523 {
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
524 union { struct acl a; char room[128]; } u;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
525 int ret;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
526
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
527 u.a.acl_len = (char *) &u.a.acl_ext[0] - (char *) &u.a; /* no entries */
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
528 u.a.acl_mode = mode & ~(S_IXACL | 0777);
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
529 u.a.u_access = (mode >> 6) & 7;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
530 u.a.g_access = (mode >> 3) & 7;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
531 u.a.o_access = mode & 7;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
532
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
533 if (desc != -1)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
534 ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
535 type, &u.a, u.a.acl_len, mode);
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
536 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
537 ret = aclx_put (name, SET_ACL | SET_MODE_S_BITS,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
538 type, &u.a, u.a.acl_len, mode);
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
539 if (!(ret < 0 && errno == ENOSYS))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
540 return ret;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
541 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
542 else if (type.u64 == ACL_NFS4)
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
543 {
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
544 union { nfs4_acl_int_t a; char room[128]; } u;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
545 nfs4_ace_int_t *ace;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
546 int ret;
10183
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
547
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
548 u.a.aclVersion = NFS4_ACL_INT_STRUCT_VERSION;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
549 u.a.aclEntryN = 0;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
550 ace = &u.a.aclEntry[0];
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
551 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
552 ace->flags = ACE4_ID_SPECIAL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
553 ace->aceWho.special_whoid = ACE4_WHO_OWNER;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
554 ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
555 ace->aceFlags = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
556 ace->aceMask =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
557 (mode & 0400 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
558 | (mode & 0200
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
559 ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
560 | ACE4_ADD_SUBDIRECTORY
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
561 : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
562 | (mode & 0100 ? ACE4_EXECUTE : 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
563 ace->aceWhoString[0] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
564 ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
565 ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
566 u.a.aclEntryN++;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
567 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
568 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
569 ace->flags = ACE4_ID_SPECIAL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
570 ace->aceWho.special_whoid = ACE4_WHO_GROUP;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
571 ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
572 ace->aceFlags = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
573 ace->aceMask =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
574 (mode & 0040 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
575 | (mode & 0020
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
576 ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
577 | ACE4_ADD_SUBDIRECTORY
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
578 : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
579 | (mode & 0010 ? ACE4_EXECUTE : 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
580 ace->aceWhoString[0] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
581 ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
582 ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
583 u.a.aclEntryN++;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
584 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
585 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
586 ace->flags = ACE4_ID_SPECIAL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
587 ace->aceWho.special_whoid = ACE4_WHO_EVERYONE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
588 ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
589 ace->aceFlags = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
590 ace->aceMask =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
591 (mode & 0004 ? ACE4_READ_DATA | ACE4_LIST_DIRECTORY : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
592 | (mode & 0002
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
593 ? ACE4_WRITE_DATA | ACE4_ADD_FILE | ACE4_APPEND_DATA
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
594 | ACE4_ADD_SUBDIRECTORY
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
595 : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
596 | (mode & 0001 ? ACE4_EXECUTE : 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
597 ace->aceWhoString[0] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
598 ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
599 ace = (nfs4_ace_int_t *) (char *) &ace->aceWhoString[4];
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
600 u.a.aclEntryN++;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
601 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
602 u.a.aclLength = (char *) ace - (char *) &u.a;
10183
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
603
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
604 if (desc != -1)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
605 ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
606 type, &u.a, u.a.aclLength, mode);
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
607 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
608 ret = aclx_put (name, SET_ACL | SET_MODE_S_BITS,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
609 type, &u.a, u.a.aclLength, mode);
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
610 if (!(ret < 0 && errno == ENOSYS))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
611 return ret;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
612 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
613
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
614 return chmod_or_fchmod (name, desc, mode);
12077
72b0c1288a50 Disable untested support for new flavours of ACLs on AIX.
Bruno Haible <bruno@clisp.org>
parents: 12075
diff changeset
615
10183
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
616 # elif HAVE_STATACL /* older AIX */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
617
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
618 union { struct acl a; char room[128]; } u;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
619 int ret;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
620
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
621 u.a.acl_len = (char *) &u.a.acl_ext[0] - (char *) &u.a; /* no entries */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
622 u.a.acl_mode = mode & ~(S_IXACL | 0777);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
623 u.a.u_access = (mode >> 6) & 7;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
624 u.a.g_access = (mode >> 3) & 7;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
625 u.a.o_access = mode & 7;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
626
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
627 if (desc != -1)
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
628 ret = fchacl (desc, &u.a, u.a.acl_len);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
629 else
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
630 ret = chacl (name, &u.a, u.a.acl_len);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
631
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
632 if (ret < 0 && errno == ENOSYS)
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
633 return chmod_or_fchmod (name, desc, mode);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
634
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
635 return ret;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
636
13757
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
637 # elif HAVE_ACLSORT /* NonStop Kernel */
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
638
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
639 struct acl entries[4];
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
640 int ret;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
641
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
642 entries[0].a_type = USER_OBJ;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
643 entries[0].a_id = 0; /* irrelevant */
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
644 entries[0].a_perm = (mode >> 6) & 7;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
645 entries[1].a_type = GROUP_OBJ;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
646 entries[1].a_id = 0; /* irrelevant */
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
647 entries[1].a_perm = (mode >> 3) & 7;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
648 entries[2].a_type = CLASS_OBJ;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
649 entries[2].a_id = 0;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
650 entries[2].a_perm = (mode >> 3) & 7;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
651 entries[3].a_type = OTHER_OBJ;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
652 entries[3].a_id = 0;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
653 entries[3].a_perm = mode & 7;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
654
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
655 ret = aclsort (sizeof (entries) / sizeof (struct acl), 1, entries);
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
656 if (ret > 0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
657 abort ();
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
658 if (ret < 0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
659 {
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
660 if (0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
661 return chmod_or_fchmod (name, desc, mode);
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
662 return -1;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
663 }
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
664
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
665 ret = acl ((char *) name, ACL_SET,
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
666 sizeof (entries) / sizeof (struct acl), entries);
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
667 if (ret < 0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
668 {
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
669 if (0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
670 return chmod_or_fchmod (name, desc, mode);
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
671 return -1;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
672 }
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
673
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
674 if (mode & (S_ISUID | S_ISGID | S_ISVTX))
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
675 {
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
676 /* We did not call chmod so far, so the special bits have not yet
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
677 been set. */
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
678 return chmod_or_fchmod (name, desc, mode);
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
679 }
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
680 return 0;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
681
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
682 # else /* Unknown flavor of ACLs */
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
683 return chmod_or_fchmod (name, desc, mode);
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
684 # endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
685 #else /* !USE_ACL */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
686 return chmod_or_fchmod (name, desc, mode);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
687 #endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
688 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
689
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
690 /* As with qset_acl, but also output a diagnostic on failure. */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
691
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
692 int
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
693 set_acl (char const *name, int desc, mode_t mode)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
694 {
16269
ee1df2d14b96 acl: Rename a local variable.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
695 int ret = qset_acl (name, desc, mode);
ee1df2d14b96 acl: Rename a local variable.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
696 if (ret != 0)
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
697 error (0, errno, _("setting permissions for %s"), quote (name));
16269
ee1df2d14b96 acl: Rename a local variable.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
698 return ret;
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
699 }