annotate lib/set-mode-acl.c @ 16382:cc05dad27529

acl: Don't use GETACLCNT and similar ops, since they are unreliable. - There were several instances of this pattern: for (;;) { n = acl (f, GETACLCNT, 0, NULL); [ allocate an array A of size N ] if (acl (f, GETACL, n, a) == n) break; } This loop might never terminate if some other process is constantly manipulating the file's ACL. The loop should be rewritten to terminate. - The acl (... GETACLNT ...) call is merely an optimization; its value is merely a hint as to how big to make the array. A better optimization is to avoid the acl (... GETACLNT ...) call entirely, and just guess a reasonably-big size, growing the size and trying again if it's not large enough. This guarantees termination, and saves a system call. * lib/acl-internal.h: Include <limits.h>. (MIN, SIZE_MAX): New macros. * lib/file-has-acl.c (file_has_acl) [Solaris]: Read the entries into a stack-allocated buffer, and use malloc if it does not fit. Don't use GETACLCNT. * lib/set-mode-acl.c (qset_acl) [Solaris]: Likewise.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 20 Feb 2012 01:12:06 +0100
parents fc5c37ccbece
children 498a2211d839
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
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include "acl.h"
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include "acl-internal.h"
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
10198
5056e8a13405 Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents: 10191
diff changeset
26 #include "gettext.h"
5056e8a13405 Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents: 10191
diff changeset
27 #define _(msgid) gettext (msgid)
5056e8a13405 Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents: 10191
diff changeset
28
5056e8a13405 Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents: 10191
diff changeset
29
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* 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
31 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
32 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
33 NAME instead.
7215efd0ff4f Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents: 10168
diff changeset
34 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
35
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 int
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 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
38 {
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 if (HAVE_FCHMOD && desc != -1)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 return fchmod (desc, mode);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 else
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 return chmod (name, mode);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 /* 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
46 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
47 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
48 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
49 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
50 to those from MODE if any are set.
0c9f7838132c Document qset_acl return value precisely.
Bruno Haible <bruno@clisp.org>
parents: 10126
diff changeset
51 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
52
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 int
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 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
55 {
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 #if USE_ACL
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
57 # if HAVE_ACL_GET_FILE
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 /* POSIX 1003.1e draft 17 (abandoned) specific version. */
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
59 /* Linux, FreeBSD, MacOS 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
60 # if !HAVE_ACL_TYPE_EXTENDED
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 /* Linux, FreeBSD, IRIX, Tru64 */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 /* 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
64 (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
65 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
66 unspecified.) */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 # ifndef HAVE_ACL_FROM_TEXT
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 # 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
70 # endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 # ifndef HAVE_ACL_DELETE_DEF_FILE
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 # 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
73 # endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 acl_t acl;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 int ret;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 if (HAVE_ACL_FROM_MODE) /* Linux */
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 acl = acl_from_mode (mode);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 if (!acl)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
82 return -1;
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 else /* FreeBSD, IRIX, Tru64 */
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 /* 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
87 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
88 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
89 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
90 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
91
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 # if HAVE_ACL_FREE_TEXT /* Tru64 */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 char acl_text[] = "u::---,g::---,o::---,";
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 # else /* FreeBSD, IRIX */
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 # endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 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
106 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
107
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 acl = acl_from_text (acl_text);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 if (!acl)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
110 return -1;
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 if (HAVE_ACL_SET_FD && desc != -1)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 ret = acl_set_fd (desc, acl);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 else
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 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
116 if (ret != 0)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 int saved_errno = errno;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 acl_free (acl);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 if (ACL_NOT_WELL_SUPPORTED (errno))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
122 return chmod_or_fchmod (name, desc, mode);
10176
43bafd6ea0d8 Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
123 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
124 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
125 errno = saved_errno;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
126 return -1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
127 }
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 else
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 acl_free (acl);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 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
133 return -1;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134
15575
3e19c8849877 acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents: 15572
diff changeset
135 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
136 {
15575
3e19c8849877 acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents: 15572
diff changeset
137 /* 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
138 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
139 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
140 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 return 0;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142
15575
3e19c8849877 acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents: 15572
diff changeset
143 # else /* HAVE_ACL_TYPE_EXTENDED */
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 /* MacOS X */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
146 /* On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS)
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
147 and acl_get_file (name, ACL_TYPE_DEFAULT)
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
148 always return NULL / EINVAL. You have to use
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
149 acl_get_file (name, ACL_TYPE_EXTENDED)
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
150 or acl_get_fd (open (name, ...))
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
151 to retrieve an ACL.
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
152 On the other hand,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
153 acl_set_file (name, ACL_TYPE_ACCESS, acl)
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
154 and acl_set_file (name, ACL_TYPE_DEFAULT, acl)
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
155 have the same effect as
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
156 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
157 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
158
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 acl_t acl;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 int ret;
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 /* 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
163 if (HAVE_ACL_GET_FD && desc != -1)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 acl = acl_get_fd (desc);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 else
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10171
diff changeset
166 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
167 if (acl)
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 {
10171
f988df7e273d Fix memory leak introduced on 2008-05-22.
Bruno Haible <bruno@clisp.org>
parents: 10170
diff changeset
169 acl_free (acl);
f988df7e273d Fix memory leak introduced on 2008-05-22.
Bruno Haible <bruno@clisp.org>
parents: 10170
diff changeset
170
10170
75a6b6b966a8 Avoid needing to know the textual representation of an ACL when possible.
Bruno Haible <bruno@clisp.org>
parents: 10169
diff changeset
171 acl = acl_init (0);
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 if (acl)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
173 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
174 if (HAVE_ACL_SET_FD && desc != -1)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
175 ret = acl_set_fd (desc, acl);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
176 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
177 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
178 if (ret != 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
179 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
180 int saved_errno = errno;
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
182 acl_free (acl);
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 if (ACL_NOT_WELL_SUPPORTED (saved_errno))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
185 return chmod_or_fchmod (name, desc, mode);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
186 else
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
187 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
188 errno = saved_errno;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
189 return -1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
190 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
191 }
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
192 acl_free (acl);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
193 }
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195
10176
43bafd6ea0d8 Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
196 /* 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
197 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
198 # endif
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
199
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
200 # 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
201
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
202 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
203
15572
dd7c06a51643 acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents: 15567
diff changeset
204 # ifdef ACE_GETACL
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
205 /* 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
206 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
207
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
208 /* 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
209 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
210 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
211 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
212 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
213 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
214 int convention;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
215
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
216 {
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
217 /* 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
218 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
219 enum
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
220 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
221 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
222 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
223 };
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
224 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
225 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
226 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
227 ace_t *malloced = NULL;
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
228 int count;
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
229
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
230 for (;;)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
231 {
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
232 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
233 ? 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
234 : 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
235 if (count < 0 && errno == ENOSPC)
16381
fc5c37ccbece acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents: 16269
diff changeset
236 {
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
237 /* 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
238 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
239 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
240 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
241 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
242 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
243 }
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
244 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
245 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
246 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
247 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
248 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
249 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
250 }
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
251 continue;
16381
fc5c37ccbece acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents: 16269
diff changeset
252 }
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
253 break;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
254 }
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
255
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
256 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
257 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
258 else
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
259 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
260 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
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 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
263 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
264 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
265 {
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
266 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
267 break;
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
268 }
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
269 }
16382
cc05dad27529 acl: Don't use GETACLCNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16381
diff changeset
270 free (malloced);
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
271 }
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
272
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
273 if (convention >= 0)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
274 {
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
275 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
276 int count;
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
277 int ret;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
278
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
279 if (convention)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
280 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
281 /* 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
282 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
283 entries[0].a_flags = OLD_ACE_OWNER;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
284 entries[0].a_who = 0; /* irrelevant */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
285 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
286 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
287 entries[1].a_flags = OLD_ACE_GROUP;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
288 entries[1].a_who = 0; /* irrelevant */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
289 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
290 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
291 entries[2].a_flags = OLD_ACE_OTHER;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
292 entries[2].a_who = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
293 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
294 count = 3;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
295 }
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
296 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
297 {
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
298 /* 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
299 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
300 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
301 entries[0].a_flags = NEW_ACE_OWNER;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
302 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
303 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
304 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
305 entries[1].a_flags = NEW_ACE_OWNER;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
306 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
307 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
308 | 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
309 | 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
310 | 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
311 if (mode & 0400)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
312 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
313 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
314 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
315 if (mode & 0200)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
316 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
317 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
318 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
319 if (mode & 0100)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
320 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
321 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 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
330 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
331 if (mode & 0040)
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 |= 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
333 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
334 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
335 if (mode & 0020)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
336 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
337 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
338 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
339 if (mode & 0010)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
340 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
341 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
342 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
343 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
344 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
345 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
346 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
347 | 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
348 | 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
349 | 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
350 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
351 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
352 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
353 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
354 | 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
355 | 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
356 | NEW_ACE_SYNCHRONIZE;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
357 if (mode & 0004)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
358 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
359 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
360 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
361 if (mode & 0002)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
362 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
363 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
364 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
365 if (mode & 0001)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
366 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
367 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
368 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
369 count = 6;
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
370 }
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
371 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
372 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
373 else
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
374 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
375 if (ret < 0 && errno != EINVAL && errno != ENOTSUP)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
376 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
377 if (errno == ENOSYS)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
378 return chmod_or_fchmod (name, desc, mode);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
379 return -1;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
380 }
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
381 if (ret == 0)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
382 done_setacl = 1;
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10184
diff changeset
383 }
15572
dd7c06a51643 acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents: 15567
diff changeset
384 # endif
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
385
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
386 if (!done_setacl)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
387 {
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
388 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
389 int ret;
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
390
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
391 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
392 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
393 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
394 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
395 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
396 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
397 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
398 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
399 entries[2].a_perm = mode & 7;
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
400
15566
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
401 if (desc != -1)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
402 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
403 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
404 else
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
405 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
406 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
407 if (ret < 0)
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
408 {
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
409 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
410 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
411 return -1;
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
412 }
8339ac6126c5 acl: Improve support of NFSv4 ACLs on Solaris 10 (newer version).
Bruno Haible <bruno@clisp.org>
parents: 14905
diff changeset
413 }
10184
9da2345fe8f6 Add me as co-author.
Bruno Haible <bruno@clisp.org>
parents: 10183
diff changeset
414
10181
5282ccc922b9 Add support for Cygwin ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10180
diff changeset
415 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
416 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
417 /* 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
418 been set. */
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
419 return chmod_or_fchmod (name, desc, mode);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
420 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
421 return 0;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10176
diff changeset
422
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
423 # elif HAVE_GETACL /* HP-UX */
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
424
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
425 struct stat statbuf;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
426 int ret;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
427
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
428 if (desc != -1)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
429 ret = fstat (desc, &statbuf);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
430 else
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
431 ret = stat (name, &statbuf);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
432 if (ret < 0)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
433 return -1;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
434
14905
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
435 {
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
436 struct acl_entry entries[3];
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
437
14905
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
438 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
439 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
440 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
441 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
442 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
443 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
444 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
445 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
446 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
447
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
448 if (desc != -1)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
449 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
450 else
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
451 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
452 }
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
453 if (ret < 0)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
454 {
14905
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
455 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
456 return -1;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
457
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
458 # 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
459 {
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
460 struct acl entries[4];
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 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
463 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
464 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
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472 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
473 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
474
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
475 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
476 if (ret > 0)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
477 abort ();
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 {
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
480 if (0)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
481 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
482 return -1;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
483 }
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
484
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
485 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
486 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
487 if (ret < 0)
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
488 {
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
489 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
490 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
491 return -1;
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
492 }
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
493 }
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
494 # else
a9b67d6b93df acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents: 14904
diff changeset
495 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
496 # endif
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
497 }
10184
9da2345fe8f6 Add me as co-author.
Bruno Haible <bruno@clisp.org>
parents: 10183
diff changeset
498
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
499 if (mode & (S_ISUID | S_ISGID | S_ISVTX))
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
500 {
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
501 /* 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
502 been set. */
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
503 return chmod_or_fchmod (name, desc, mode);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
504 }
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
505 return 0;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10181
diff changeset
506
12077
72b0c1288a50 Disable untested support for new flavours of ACLs on AIX.
Bruno Haible <bruno@clisp.org>
parents: 12075
diff changeset
507 # 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
508
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
509 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
510 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
511 acl_type_t type;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
512
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
513 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
514 || types.num_entries == 0)
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
515 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
516
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
517 /* 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
518 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
519 type = types.entries[0];
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
520 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
521 {
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
522 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
523 int ret;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
524
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
525 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
526 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
527 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
528 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
529 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
530
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
531 if (desc != -1)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
532 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
533 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
534 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
535 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
536 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
537 if (!(ret < 0 && errno == ENOSYS))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
538 return ret;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
539 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
540 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
541 {
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
542 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
543 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
544 int ret;
10183
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
545
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
546 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
547 u.a.aclEntryN = 0;
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
548 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
549 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
550 ace->flags = ACE4_ID_SPECIAL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
551 ace->aceWho.special_whoid = ACE4_WHO_OWNER;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
552 ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
553 ace->aceFlags = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
554 ace->aceMask =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
555 (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
556 | (mode & 0200
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
557 ? 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
558 | ACE4_ADD_SUBDIRECTORY
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
559 : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
560 | (mode & 0100 ? ACE4_EXECUTE : 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
561 ace->aceWhoString[0] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
562 ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
563 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
564 u.a.aclEntryN++;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
565 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
566 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
567 ace->flags = ACE4_ID_SPECIAL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
568 ace->aceWho.special_whoid = ACE4_WHO_GROUP;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
569 ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
570 ace->aceFlags = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
571 ace->aceMask =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
572 (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
573 | (mode & 0020
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
574 ? 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
575 | ACE4_ADD_SUBDIRECTORY
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
576 : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
577 | (mode & 0010 ? ACE4_EXECUTE : 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
578 ace->aceWhoString[0] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
579 ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
580 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
581 u.a.aclEntryN++;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
582 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
583 {
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
584 ace->flags = ACE4_ID_SPECIAL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
585 ace->aceWho.special_whoid = ACE4_WHO_EVERYONE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
586 ace->aceType = ACE4_ACCESS_ALLOWED_ACE_TYPE;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
587 ace->aceFlags = 0;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
588 ace->aceMask =
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
589 (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
590 | (mode & 0002
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
591 ? 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
592 | ACE4_ADD_SUBDIRECTORY
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
593 : 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
594 | (mode & 0001 ? ACE4_EXECUTE : 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
595 ace->aceWhoString[0] = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
596 ace->entryLen = (char *) &ace->aceWhoString[4] - (char *) ace;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
597 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
598 u.a.aclEntryN++;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
599 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
600 u.a.aclLength = (char *) ace - (char *) &u.a;
10183
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
601
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
602 if (desc != -1)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
603 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
604 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
605 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
606 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
607 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
608 if (!(ret < 0 && errno == ENOSYS))
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 12077
diff changeset
609 return ret;
12075
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
610 }
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
611
c57301f2214b Add support for new flavours of ACLs on AIX. (Untested.)
Bruno Haible <bruno@clisp.org>
parents: 11917
diff changeset
612 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
613
10183
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
614 # elif HAVE_STATACL /* older AIX */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
615
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
616 union { struct acl a; char room[128]; } u;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
617 int ret;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
618
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
619 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
620 u.a.acl_mode = mode & ~(S_IXACL | 0777);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
621 u.a.u_access = (mode >> 6) & 7;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
622 u.a.g_access = (mode >> 3) & 7;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
623 u.a.o_access = mode & 7;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
624
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
625 if (desc != -1)
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
626 ret = fchacl (desc, &u.a, u.a.acl_len);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
627 else
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
628 ret = chacl (name, &u.a, u.a.acl_len);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
629
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
630 if (ret < 0 && errno == ENOSYS)
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
631 return chmod_or_fchmod (name, desc, mode);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
632
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
633 return ret;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
634
13757
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
635 # elif HAVE_ACLSORT /* NonStop Kernel */
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
636
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
637 struct acl entries[4];
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
638 int ret;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
639
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
640 entries[0].a_type = USER_OBJ;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
641 entries[0].a_id = 0; /* irrelevant */
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
642 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
643 entries[1].a_type = GROUP_OBJ;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
644 entries[1].a_id = 0; /* irrelevant */
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
645 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
646 entries[2].a_type = CLASS_OBJ;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
647 entries[2].a_id = 0;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
648 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
649 entries[3].a_type = OTHER_OBJ;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
650 entries[3].a_id = 0;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
651 entries[3].a_perm = mode & 7;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
652
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
653 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
654 if (ret > 0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
655 abort ();
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 {
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
658 if (0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
659 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
660 return -1;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
661 }
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
662
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
663 ret = acl ((char *) name, ACL_SET,
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
664 sizeof (entries) / sizeof (struct acl), entries);
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
665 if (ret < 0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
666 {
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
667 if (0)
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
668 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
669 return -1;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
670 }
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
671
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
672 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
673 {
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
674 /* 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
675 been set. */
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
676 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
677 }
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
678 return 0;
87aaf9340686 acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents: 12906
diff changeset
679
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
680 # else /* Unknown flavor of ACLs */
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10150
diff changeset
681 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
682 # endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
683 #else /* !USE_ACL */
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
684 return chmod_or_fchmod (name, desc, mode);
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
685 #endif
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
686 }
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
687
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
688 /* 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
689
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
690 int
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
691 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
692 {
16269
ee1df2d14b96 acl: Rename a local variable.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
693 int ret = qset_acl (name, desc, mode);
ee1df2d14b96 acl: Rename a local variable.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
694 if (ret != 0)
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
695 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
696 return ret;
10126
66d52359961e Rename acl.c to set-mode-acl.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
697 }