annotate lib/file-has-acl.c @ 10780:5c7a68d31801

Add support for Haiku.
author Bruno Haible <bruno@clisp.org>
date Mon, 10 Nov 2008 12:37:32 +0100
parents ccfd3047da72
children 03ef9ae804c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
1 /* Test whether a file has a nontrivial access control list.
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
2
10114
51164d97e89b Make copy_acl work on MacOS X 10.5.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
3 Copyright (C) 2002-2003, 2005-2008 Free Software Foundation, Inc.
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8476
diff changeset
5 This program is free software: you can redistribute it and/or modify
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8476
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8476
diff changeset
8 (at your option) any later version.
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13 GNU General Public License for more details.
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8476
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
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, Andreas Grünbacher, and Bruno Haible. */
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
20 #include <config.h>
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
21
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
22 #include "acl.h"
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
23
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
24 #include "acl-internal.h"
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
25
10158
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
26
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
27 #if USE_ACL && HAVE_ACL_GET_FILE
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
28
10177
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
29 # if HAVE_ACL_TYPE_EXTENDED /* MacOS X */
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
30
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
31 /* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED.
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
32 Return 1 if the given ACL is non-trivial.
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
33 Return 0 if it is trivial. */
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
34 int
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
35 acl_extended_nontrivial (acl_t acl)
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
36 {
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
37 /* acl is non-trivial if it is non-empty. */
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
38 return (acl_entries (acl) > 0);
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
39 }
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
40
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
41 # else /* Linux, FreeBSD, IRIX, Tru64 */
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
42
10158
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
43 /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
44 Return 1 if the given ACL is non-trivial.
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
45 Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
46 Return -1 and set errno upon failure to determine it. */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
47 int
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
48 acl_access_nontrivial (acl_t acl)
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
49 {
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
50 /* acl is non-trivial if it has some entries other than for "user::",
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
51 "group::", and "other::". Normally these three should be present
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
52 at least, allowing us to write
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
53 return (3 < acl_entries (acl));
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
54 but the following code is more robust. */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
55 # if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
56
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
57 acl_entry_t ace;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
58 int at_end;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
59
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
60 for (at_end = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace);
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
61 !at_end;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
62 at_end = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace))
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
63 {
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
64 acl_tag_t tag;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
65 if (acl_get_tag_type (ace, &tag) < 0)
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
66 return -1;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
67 if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER))
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
68 return 1;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
69 }
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
70 return 0;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
71
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
72 # else /* IRIX, Tru64 */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
73 # if HAVE_ACL_TO_SHORT_TEXT /* IRIX */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
74 /* Don't use acl_get_entry: it is undocumented. */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
75
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
76 int count = acl->acl_cnt;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
77 int i;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
78
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
79 for (i = 0; i < count; i++)
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
80 {
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
81 acl_entry_t ace = &acl->acl_entry[i];
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
82 acl_tag_t tag = ace->ae_tag;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
83
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
84 if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
85 || tag == ACL_OTHER_OBJ))
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
86 return 1;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
87 }
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
88 return 0;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
89
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
90 # endif
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
91 # if HAVE_ACL_FREE_TEXT /* Tru64 */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
92 /* Don't use acl_get_entry: it takes only one argument and does not work. */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
93
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
94 int count = acl->acl_num;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
95 acl_entry_t ace;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
96
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
97 for (ace = acl->acl_first; count > 0; ace = ace->next, count--)
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
98 {
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
99 acl_tag_t tag;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
100 acl_perm_t perm;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
101
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
102 tag = ace->entry->acl_type;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
103 if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER))
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
104 return 1;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
105
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
106 perm = ace->entry->acl_perm;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
107 /* On Tru64, perm can also contain non-standard bits such as
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
108 PERM_INSERT, PERM_DELETE, PERM_MODIFY, PERM_LOOKUP, ... */
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
109 if ((perm & ~(ACL_READ | ACL_WRITE | ACL_EXECUTE)) != 0)
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
110 return 1;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
111 }
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
112 return 0;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
113
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
114 # endif
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
115 # endif
10177
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
116 }
10158
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
117
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
118 # endif
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
119
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
120
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
121 #elif USE_ACL && HAVE_ACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
122
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
123 # if !defined ACL_NO_TRIVIAL /* Solaris <= 10, Cygwin */
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
124
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
125 /* Test an ACL retrieved with GETACL.
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
126 Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
127 Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
128 int
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
129 acl_nontrivial (int count, aclent_t *entries)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
130 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
131 int i;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
132
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
133 for (i = 0; i < count; i++)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
134 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
135 aclent_t *ace = &entries[i];
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
136
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
137 /* Note: If ace->a_type = USER_OBJ, ace->a_id is the st_uid from stat().
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
138 If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat().
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
139 We don't need to check ace->a_id in these cases. */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
140 if (!(ace->a_type == USER_OBJ
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
141 || ace->a_type == GROUP_OBJ
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
142 || ace->a_type == OTHER_OBJ
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
143 /* Note: Cygwin does not return a CLASS_OBJ ("mask:") entry
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
144 sometimes. */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
145 || ace->a_type == CLASS_OBJ))
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
146 return 1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
147 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
148 return 0;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
149 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
150
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
151 # ifdef ACE_GETACL
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
152
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
153 /* Test an ACL retrieved with ACE_GETACL.
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
154 Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
155 Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
156 int
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
157 acl_ace_nontrivial (int count, ace_t *entries)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
158 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
159 int i;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
160
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
161 /* 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: 10185
diff changeset
162 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: 10185
diff changeset
163 How to distinguish the two conventions at runtime?
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
164 In the old convention, usually three ACEs have a_flags = ACE_OWNER /
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
165 ACE_GROUP / ACE_OTHER, in the range 0x0100..0x0400. In the new
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
166 convention, these values are not used. */
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
167 int old_convention = 0;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
168
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
169 for (i = 0; i < count; i++)
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
170 if (entries[i].a_flags & (ACE_OWNER | ACE_GROUP | ACE_OTHER))
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
171 {
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
172 old_convention = 1;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
173 break;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
174 }
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
175
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
176 if (old_convention)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
177 /* Running on Solaris 10. */
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
178 for (i = 0; i < count; i++)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
179 {
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
180 ace_t *ace = &entries[i];
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
181
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
182 /* Note:
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
183 If ace->a_flags = ACE_OWNER, ace->a_who is the st_uid from stat().
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
184 If ace->a_flags = ACE_GROUP, ace->a_who is the st_gid from stat().
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
185 We don't need to check ace->a_who in these cases. */
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
186 if (!(ace->a_type == ALLOW
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
187 && (ace->a_flags == ACE_OWNER
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
188 || ace->a_flags == ACE_GROUP
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
189 || ace->a_flags == ACE_OTHER)))
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
190 return 1;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
191 }
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
192 else
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
193 /* Running on Solaris 10 (newer version) or Solaris 11. */
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
194 for (i = 0; i < count; i++)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
195 {
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
196 ace_t *ace = &entries[i];
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
197
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
198 if (!(ace->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
199 && (ace->a_flags == NEW_ACE_OWNER
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
200 || ace->a_flags
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
201 == (NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
202 || ace->a_flags == ACE_EVERYONE)
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
203 && (ace->a_access_mask
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
204 & ~(NEW_ACE_READ_DATA | NEW_ACE_WRITE_DATA | NEW_ACE_EXECUTE))
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
205 == 0))
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
206 return 1;
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
207 }
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
208
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
209 return 0;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
210 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
211
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
212 # endif
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
213
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
214 # endif
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
215
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
216 #elif USE_ACL && HAVE_GETACL /* HP-UX */
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
217
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
218 /* Return 1 if the given ACL is non-trivial.
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
219 Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
220 int
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
221 acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
222 {
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
223 int i;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
224
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
225 for (i = 0; i < count; i++)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
226 {
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
227 struct acl_entry *ace = &entries[i];
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
228
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
229 if (!((ace->uid == sb->st_uid && ace->gid == ACL_NSGROUP)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
230 || (ace->uid == ACL_NSUSER && ace->gid == sb->st_gid)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
231 || (ace->uid == ACL_NSUSER && ace->gid == ACL_NSGROUP)))
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
232 return 1;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
233 }
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
234 return 0;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
235 }
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
236
10183
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
237 #elif USE_ACL && HAVE_ACLX_GET && 0 /* AIX */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
238
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
239 /* TODO */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
240
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
241 #elif USE_ACL && HAVE_STATACL /* older AIX */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
242
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
243 /* Return 1 if the given ACL is non-trivial.
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
244 Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
245 int
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
246 acl_nontrivial (struct acl *a)
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
247 {
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
248 /* The normal way to iterate through an ACL is like this:
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
249 struct acl_entry *ace;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
250 for (ace = a->acl_ext; ace != acl_last (a); ace = acl_nxt (ace))
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
251 {
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
252 struct ace_id *aei;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
253 switch (ace->ace_type)
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
254 {
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
255 case ACC_PERMIT:
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
256 case ACC_DENY:
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
257 case ACC_SPECIFY:
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
258 ...;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
259 }
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
260 for (aei = ace->ace_id; aei != id_last (ace); aei = id_nxt (aei))
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
261 ...
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
262 }
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
263 */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
264 return (acl_last (a) != a->acl_ext ? 1 : 0);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
265 }
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
266
10158
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
267 #endif
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
268
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
269
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
270 /* Return 1 if NAME has a nontrivial access control list, 0 if NAME
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
271 only has no or a base access control list, and -1 (setting errno)
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
272 on error. SB must be set to the stat buffer of FILE. */
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
273
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
274 int
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
275 file_has_acl (char const *name, struct stat const *sb)
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
276 {
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
277 #if USE_ACL
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
278 if (! S_ISLNK (sb->st_mode))
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
279 {
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
280 # if HAVE_ACL_GET_FILE
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
281
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
282 /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */
10114
51164d97e89b Make copy_acl work on MacOS X 10.5.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
283 /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
284 int ret;
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
285
10175
ed86dd8c386e Comments.
Bruno Haible <bruno@clisp.org>
parents: 10173
diff changeset
286 if (HAVE_ACL_EXTENDED_FILE) /* Linux */
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
287 {
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
288 /* On Linux, acl_extended_file is an optimized function: It only
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
289 makes two calls to getxattr(), one for ACL_TYPE_ACCESS, one for
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
290 ACL_TYPE_DEFAULT. */
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
291 ret = acl_extended_file (name);
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
292 }
10175
ed86dd8c386e Comments.
Bruno Haible <bruno@clisp.org>
parents: 10173
diff changeset
293 else /* FreeBSD, MacOS X, IRIX, Tru64 */
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
294 {
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
295 # if HAVE_ACL_TYPE_EXTENDED /* MacOS X */
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
296 /* On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS)
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
297 and acl_get_file (name, ACL_TYPE_DEFAULT)
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
298 always return NULL / EINVAL. There is no point in making
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
299 these two useless calls. The real ACL is retrieved through
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
300 acl_get_file (name, ACL_TYPE_EXTENDED). */
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
301 acl_t acl = acl_get_file (name, ACL_TYPE_EXTENDED);
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
302 if (acl)
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
303 {
10177
caed32fb1892 New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents: 10175
diff changeset
304 ret = acl_extended_nontrivial (acl);
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
305 acl_free (acl);
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
306 }
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
307 else
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
308 ret = -1;
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
309 # else /* FreeBSD, IRIX, Tru64 */
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
310 acl_t acl = acl_get_file (name, ACL_TYPE_ACCESS);
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
311 if (acl)
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
312 {
10158
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
313 int saved_errno;
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
314
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
315 ret = acl_access_nontrivial (acl);
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
316 saved_errno = errno;
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
317 acl_free (acl);
10158
73042342e7f6 New function for testing triviality of ACL with POSIX-draft like API.
Bruno Haible <bruno@clisp.org>
parents: 10155
diff changeset
318 errno = saved_errno;
10173
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
319 # if HAVE_ACL_FREE_TEXT /* Tru64 */
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
320 /* On OSF/1, acl_get_file (name, ACL_TYPE_DEFAULT) always
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
321 returns NULL with errno not set. There is no point in
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
322 making this call. */
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
323 # else /* FreeBSD, IRIX */
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
324 /* On Linux, FreeBSD, IRIX, acl_get_file (name, ACL_TYPE_ACCESS)
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
325 and acl_get_file (name, ACL_TYPE_DEFAULT) on a directory
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
326 either both succeed or both fail; it depends on the
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
327 filesystem. Therefore there is no point in making the second
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
328 call if the first one already failed. */
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
329 if (ret == 0 && S_ISDIR (sb->st_mode))
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
330 {
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
331 acl = acl_get_file (name, ACL_TYPE_DEFAULT);
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
332 if (acl)
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
333 {
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
334 ret = (0 < acl_entries (acl));
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
335 acl_free (acl);
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
336 }
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
337 else
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
338 ret = -1;
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
339 }
10173
33543159ba5b Don't test the ACL_TYPE_DEFAULT ACL on OSF/1.
Bruno Haible <bruno@clisp.org>
parents: 10172
diff changeset
340 # endif
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
341 }
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
342 else
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
343 ret = -1;
10172
50e666f281ef Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10158
diff changeset
344 # endif
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
345 }
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
346 if (ret < 0)
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
347 return ACL_NOT_WELL_SUPPORTED (errno) ? 0 : -1;
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
348 return ret;
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
349
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
350 # elif HAVE_ACL && defined GETACLCNT /* Solaris, Cygwin, not HP-UX */
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
351
10191
ccfd3047da72 Work around the Solaris 10 ACE ACLs ABI change.
Bruno Haible <bruno@clisp.org>
parents: 10185
diff changeset
352 # if defined ACL_NO_TRIVIAL
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
353
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
354 /* Solaris 10 (newer version), which has additional API declared in
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
355 <sys/acl.h> (acl_t) and implemented in libsec (acl_set, acl_trivial,
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
356 acl_fromtext, ...). */
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
357 return acl_trivial (name);
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
358
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
359 # else /* Solaris, Cygwin, general case */
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
360
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
361 /* Solaris 2.5 through Solaris 10, Cygwin, and contemporaneous versions
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
362 of Unixware. The acl() call returns the access and default ACL both
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
363 at once. */
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
364 int count;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
365 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
366 aclent_t *entries;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
367
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
368 for (;;)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
369 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
370 count = acl (name, GETACLCNT, 0, NULL);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
371
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
372 if (count < 0)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
373 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
374 if (errno == ENOSYS || errno == ENOTSUP)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
375 break;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
376 else
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
377 return -1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
378 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
379
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
380 if (count == 0)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
381 break;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
382
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
383 /* Don't use MIN_ACL_ENTRIES: It's set to 4 on Cygwin, but Cygwin
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
384 returns only 3 entries for files with no ACL. But this is safe:
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
385 If there are more than 4 entries, there cannot be only the
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
386 "user::", "group::", "other:", and "mask:" entries. */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
387 if (count > 4)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
388 return 1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
389
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
390 entries = (aclent_t *) malloc (count * sizeof (aclent_t));
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
391 if (entries == NULL)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
392 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
393 errno = ENOMEM;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
394 return -1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
395 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
396 if (acl (name, GETACL, count, entries) == count)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
397 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
398 if (acl_nontrivial (count, entries))
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
399 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
400 free (entries);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
401 return 1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
402 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
403 free (entries);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
404 break;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
405 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
406 /* Huh? The number of ACL entries changed since the last call.
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
407 Repeat. */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
408 free (entries);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
409 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
410 }
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
411
10179
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
412 # ifdef ACE_GETACL
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
413 /* 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: 10177
diff changeset
414 file systems (whereas the other ones are used in UFS file systems). */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
415 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
416 ace_t *entries;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
417
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
418 for (;;)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
419 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
420 count = acl (name, ACE_GETACLCNT, 0, NULL);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
421
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
422 if (count < 0)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
423 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
424 if (errno == ENOSYS || errno == EINVAL)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
425 break;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
426 else
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
427 return -1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
428 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
429
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
430 if (count == 0)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
431 break;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
432
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
433 /* If there are more than 3 entries, there cannot be only the
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
434 ACE_OWNER, ACE_GROUP, ACE_OTHER entries. */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
435 if (count > 3)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
436 return 1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
437
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
438 entries = (ace_t *) malloc (count * sizeof (ace_t));
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
439 if (entries == NULL)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
440 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
441 errno = ENOMEM;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
442 return -1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
443 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
444 if (acl (name, ACE_GETACL, count, entries) == count)
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
445 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
446 if (acl_ace_nontrivial (count, entries))
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
447 {
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
448 free (entries);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
449 return 1;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
450 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
451 free (entries);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
452 break;
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
453 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
454 /* Huh? The number of ACL entries changed since the last call.
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
455 Repeat. */
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
456 free (entries);
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
457 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
458 }
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
459 # endif
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
460
90f51b86b088 Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10177
diff changeset
461 return 0;
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
462 # endif
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
463
10182
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
464 # elif HAVE_GETACL /* HP-UX */
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
465
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
466 int count;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
467 struct acl_entry entries[NACLENTRIES];
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
468
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
469 for (;;)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
470 {
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
471 count = getacl (name, 0, NULL);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
472
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
473 if (count < 0)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
474 return (errno == ENOSYS || errno == EOPNOTSUPP ? 0 : -1);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
475
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
476 if (count == 0)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
477 return 0;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
478
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
479 if (count > NACLENTRIES)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
480 /* If NACLENTRIES cannot be trusted, use dynamic memory
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
481 allocation. */
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
482 abort ();
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
483
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
484 /* If there are more than 3 entries, there cannot be only the
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
485 (uid,%), (%,gid), (%,%) entries. */
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
486 if (count > 3)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
487 return 1;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
488
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
489 if (getacl (name, count, entries) == count)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
490 {
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
491 struct stat statbuf;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
492
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
493 if (stat (name, &statbuf) < 0)
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
494 return -1;
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
495
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
496 return acl_nontrivial (count, entries, &statbuf);
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
497 }
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
498 /* Huh? The number of ACL entries changed since the last call.
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
499 Repeat. */
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
500 }
4a177f4b083f Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10179
diff changeset
501
10183
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
502 # elif HAVE_ACLX_GET && 0 /* AIX */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
503
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
504 /* TODO: use aclx_get(), and then? */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
505
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
506 # elif HAVE_STATACL /* older AIX */
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
507
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
508 union { struct acl a; char room[4096]; } u;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
509
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
510 if (statacl (name, STX_NORMAL, &u.a, sizeof (u)) < 0)
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
511 return -1;
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
512
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
513 return acl_nontrivial (&u.a);
e8efce9962b0 Add support for AIX ACLs.
Bruno Haible <bruno@clisp.org>
parents: 10182
diff changeset
514
10155
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
515 # endif
3df501903792 Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents: 10114
diff changeset
516 }
8476
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
517 #endif
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
518
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
519 return 0;
2798cb65bd90 Add limited support for Solaris 10 ZFS-style ACLs: just enough to
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
520 }