Mercurial > gnulib
annotate tests/test-file-has-acl.sh @ 13757:87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
* m4/acl.m4 (gl_FUNC_ACL): For Solaris, test for facl(), not for acl().
Check whether the function aclsort() exists.
* lib/acl-internal.h: For Solaris, test HAVE_FACL, not HAVE_ACL.
(acl_nontrivial) [HAVE_ACLSORT]: New declaration.
* lib/file-has-acl.c: For Solaris, test HAVE_FACL, not HAVE_ACL.
(acl_nontrivial [HAVE_ACLSORT]: New function.
(file_has_acl): Implement for NonStop Kernel.
* lib/set-mode-acl.c: For Solaris, test HAVE_FACL, not HAVE_ACL.
(qset_acl): Implement for NonStop Kernel.
* lib/copy-acl.c (qcopy_acl): Implement for NonStop Kernel.
* tests/test-sameacls.c: For Solaris, test HAVE_FACL, not HAVE_ACL.
(main): Implement for NonStop Kernel.
* tests/test-file-has-acl.sh (acl_flavor): Set to 'nsk' on NonStop
Kernel. Handle this flavor.
* tests/test-set-mode-acl.sh: Likewise.
* tests/test-copy-acl.sh: Likewise.
* tests/test-copy-file.sh: Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 03 Oct 2010 18:03:48 +0200 |
parents | e9cf9c46ad7a |
children | a9b67d6b93df |
rev | line source |
---|---|
10142 | 1 #!/bin/sh |
2 | |
3 # Show all commands when run with environment variable VERBOSE=yes. | |
4 test -z "$VERBOSE" || set -x | |
5 | |
10444
e7595530873e
avoid spurious test failure when library is built without ACL support
Jim Meyering <meyering@redhat.com>
parents:
10149
diff
changeset
|
6 test "$USE_ACL" = 0 && |
e7595530873e
avoid spurious test failure when library is built without ACL support
Jim Meyering <meyering@redhat.com>
parents:
10149
diff
changeset
|
7 { |
e7595530873e
avoid spurious test failure when library is built without ACL support
Jim Meyering <meyering@redhat.com>
parents:
10149
diff
changeset
|
8 echo "Skipping test: insufficient ACL support" |
e7595530873e
avoid spurious test failure when library is built without ACL support
Jim Meyering <meyering@redhat.com>
parents:
10149
diff
changeset
|
9 exit 77 |
e7595530873e
avoid spurious test failure when library is built without ACL support
Jim Meyering <meyering@redhat.com>
parents:
10149
diff
changeset
|
10 } |
e7595530873e
avoid spurious test failure when library is built without ACL support
Jim Meyering <meyering@redhat.com>
parents:
10149
diff
changeset
|
11 |
10142 | 12 # func_tmpdir |
13 # creates a temporary directory. | |
14 # Sets variable | |
15 # - tmp pathname of freshly created temporary directory | |
16 func_tmpdir () | |
17 { | |
18 # Use the environment variable TMPDIR, falling back to /tmp. This allows | |
19 # users to specify a different temporary directory, for example, if their | |
20 # /tmp is filled up or too small. | |
21 : ${TMPDIR=/tmp} | |
22 { | |
23 # Use the mktemp program if available. If not available, hide the error | |
24 # message. | |
25 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` && | |
26 test -n "$tmp" && test -d "$tmp" | |
27 } || | |
28 { | |
29 # Use a simple mkdir command. It is guaranteed to fail if the directory | |
30 # already exists. $RANDOM is bash specific and expands to empty in shells | |
31 # other than bash, ksh and zsh. Its use does not increase security; | |
32 # rather, it minimizes the probability of failure in a very cluttered /tmp | |
33 # directory. | |
34 tmp=$TMPDIR/gl$$-$RANDOM | |
35 (umask 077 && mkdir "$tmp") | |
36 } || | |
37 { | |
38 echo "$0: cannot create a temporary directory in $TMPDIR" >&2 | |
39 exit 1 | |
40 } | |
41 } | |
42 | |
43 func_tmpdir | |
44 builddir=`pwd` | |
45 cd "$builddir" || | |
46 { | |
47 echo "$0: cannot determine build directory (unreadable parent dir?)" >&2 | |
48 exit 1 | |
49 } | |
50 # Switch to a temporary directory, to increase the likelihood that ACLs are | |
51 # supported on the current file system. (/tmp is usually locally mounted, | |
52 # whereas the build dir is sometimes NFS-mounted.) | |
53 ( cd "$tmp" | |
54 | |
55 # Prepare tmpfile0. | |
56 rm -f tmpfile[0-9] tmp.err | |
57 echo "Simple contents" > tmpfile0 | |
58 chmod 600 tmpfile0 | |
59 | |
60 # Classification of the platform according to the programs available for | |
61 # manipulating ACLs. | |
62 # Possible values are: | |
63 # linux, cygwin, freebsd, solaris, hpux, osf1, aix, macosx, irix, none. | |
64 # TODO: Support also native Win32 platforms (mingw). | |
65 acl_flavor=none | |
66 if (getfacl tmpfile0 >/dev/null) 2>/dev/null; then | |
67 # Platforms with the getfacl and setfacl programs. | |
68 # Linux, FreeBSD, Solaris, Cygwin. | |
69 if (setfacl --help >/dev/null) 2>/dev/null; then | |
70 # Linux, Cygwin. | |
71 if (LC_ALL=C setfacl --help | grep ' --set-file' >/dev/null) 2>/dev/null; then | |
72 # Linux. | |
73 acl_flavor=linux | |
74 else | |
75 acl_flavor=cygwin | |
76 fi | |
77 else | |
78 # FreeBSD, Solaris. | |
79 if (LC_ALL=C setfacl 2>&1 | grep '\-x entries' >/dev/null) 2>/dev/null; then | |
80 # FreeBSD. | |
81 acl_flavor=freebsd | |
82 else | |
83 # Solaris. | |
84 acl_flavor=solaris | |
85 fi | |
86 fi | |
87 else | |
88 if (lsacl / >/dev/null) 2>/dev/null; then | |
89 # Platforms with the lsacl and chacl programs. | |
90 # HP-UX, sometimes also IRIX. | |
91 acl_flavor=hpux | |
92 else | |
93 if (getacl tmpfile0 >/dev/null) 2>/dev/null; then | |
13757
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
94 # Tru64, NonStop Kernel. |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
95 if (getacl -m tmpfile0 >/dev/null) 2>/dev/null; then |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
96 # Tru64. |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
97 acl_flavor=osf1 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
98 else |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
99 # NonStop Kernel. |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
100 acl_flavor=nsk |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
101 fi |
10142 | 102 else |
103 if (aclget tmpfile0 >/dev/null) 2>/dev/null; then | |
104 # AIX. | |
105 acl_flavor=aix | |
106 else | |
107 if (fsaclctl -v >/dev/null) 2>/dev/null; then | |
108 # MacOS X. | |
109 acl_flavor=macosx | |
110 else | |
111 if test -f /sbin/chacl; then | |
112 # IRIX. | |
113 acl_flavor=irix | |
114 fi | |
115 fi | |
116 fi | |
117 fi | |
118 fi | |
119 fi | |
120 | |
121 # func_test_file_has_acl file expected | |
122 # tests the result of the file_has_acl function on file, and checks that it | |
123 # matches the expected value. | |
124 func_test_file_has_acl () | |
125 { | |
126 res=`"$builddir"/test-file-has-acl${EXEEXT} "$1"` | |
127 test "$res" = "$2" || { | |
128 echo "file_has_acl(\"$1\") returned $res, expected $2" 1>&2 | |
129 exit 1 | |
130 } | |
131 } | |
132 | |
133 # func_test_has_acl file expected | |
134 # tests the result of the file_has_acl function on file, and checks that it | |
135 # matches the expected value, also taking into account the system's 'ls' | |
136 # program. | |
137 case $acl_flavor in | |
138 freebsd | solaris | hpux | macosx) | |
139 case $acl_flavor in | |
140 freebsd | solaris | hpux) acl_ls_option="-ld" ;; | |
141 macosx) acl_ls_option="-lde" ;; | |
142 esac | |
143 func_test_has_acl () | |
144 { | |
145 func_test_file_has_acl "$1" "$2" | |
146 case `/bin/ls $acl_ls_option "$1" | sed 1q` in | |
147 ??????????+*) | |
148 test "$2" = yes || { | |
149 echo "/bin/ls $acl_ls_option $1 shows an ACL, but expected $2" 1>&2 | |
150 exit 1 | |
151 } | |
152 ;; | |
153 ??????????" "*) | |
154 test "$2" = no || { | |
155 echo "/bin/ls $acl_ls_option $1 shows no ACL, but expected $2" 1>&2 | |
156 exit 1 | |
157 } | |
158 ;; | |
159 esac | |
160 } | |
161 ;; | |
162 irix) | |
163 func_test_has_acl () | |
164 { | |
165 func_test_file_has_acl "$1" "$2" | |
166 case `/bin/ls -ldD "$1" | sed 1q` in | |
167 *" []") | |
168 test "$2" = no || { | |
169 echo "/bin/ls -ldD $1 shows no ACL, but expected $2" 1>&2 | |
170 exit 1 | |
171 } | |
172 ;; | |
173 *) | |
174 test "$2" = yes || { | |
175 echo "/bin/ls -ldD $1 shows an ACL, but expected $2" 1>&2 | |
176 exit 1 | |
177 } | |
178 ;; | |
179 esac | |
180 } | |
181 ;; | |
182 *) | |
183 func_test_has_acl () | |
184 { | |
185 func_test_file_has_acl "$1" "$2" | |
186 } | |
187 ;; | |
188 esac | |
189 | |
190 func_test_has_acl tmpfile0 no | |
191 | |
11551
957a85702f2b
Fix test-file-has-acl on FreeBSD.
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
10444
diff
changeset
|
192 mkdir tmpdir0 |
957a85702f2b
Fix test-file-has-acl on FreeBSD.
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
10444
diff
changeset
|
193 func_test_has_acl tmpdir0 no |
957a85702f2b
Fix test-file-has-acl on FreeBSD.
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
10444
diff
changeset
|
194 |
10142 | 195 if test $acl_flavor != none; then |
11914
e9cf9c46ad7a
Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents:
11551
diff
changeset
|
196 # A POSIX compliant 'id' program. |
e9cf9c46ad7a
Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents:
11551
diff
changeset
|
197 if test -f /usr/xpg4/bin/id; then |
e9cf9c46ad7a
Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents:
11551
diff
changeset
|
198 ID=/usr/xpg4/bin/id |
e9cf9c46ad7a
Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents:
11551
diff
changeset
|
199 else |
e9cf9c46ad7a
Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents:
11551
diff
changeset
|
200 ID=id |
e9cf9c46ad7a
Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents:
11551
diff
changeset
|
201 fi |
10142 | 202 # Use a user and group id different from the current one, to avoid |
203 # redundant/ambiguous ACLs. | |
11914
e9cf9c46ad7a
Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents:
11551
diff
changeset
|
204 myuid=`$ID -u` |
e9cf9c46ad7a
Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents:
11551
diff
changeset
|
205 mygid=`$ID -g` |
10142 | 206 auid=1 |
207 if test "$auid" = "$myuid"; then auid=2; fi | |
208 agid=1 | |
209 if test "$agid" = "$mygid"; then agid=2; fi | |
210 | |
211 case $acl_flavor in | |
10149
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
212 linux | freebsd | solaris) |
10142 | 213 |
214 # Set an ACL for a user. | |
215 if setfacl -m user:$auid:1 tmpfile0; then | |
216 | |
217 func_test_has_acl tmpfile0 yes | |
218 | |
219 # Remove the ACL for the user. | |
220 case $acl_flavor in | |
221 linux) setfacl -x user:$auid tmpfile0 ;; | |
222 freebsd) setfacl -x user:$auid:1 tmpfile0 ;; | |
223 *) setfacl -d user:$auid:1 tmpfile0 ;; | |
224 esac | |
225 | |
11551
957a85702f2b
Fix test-file-has-acl on FreeBSD.
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
10444
diff
changeset
|
226 # On Linux and FreeBSD, the ACL for the mask is implicitly added. |
10142 | 227 # On Solaris, it is always there. |
228 case $acl_flavor in | |
11551
957a85702f2b
Fix test-file-has-acl on FreeBSD.
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
10444
diff
changeset
|
229 linux | freebsd) func_test_has_acl tmpfile0 yes ;; |
957a85702f2b
Fix test-file-has-acl on FreeBSD.
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
10444
diff
changeset
|
230 *) func_test_has_acl tmpfile0 no ;; |
10142 | 231 esac |
232 | |
233 # Remove the ACL for the mask, if it was implicitly added. | |
234 case $acl_flavor in | |
235 linux | freebsd) setfacl -x mask: tmpfile0 ;; | |
236 *) setfacl -d mask: tmpfile0 ;; | |
237 esac | |
238 | |
239 func_test_has_acl tmpfile0 no | |
240 | |
241 fi | |
242 ;; | |
243 | |
10149
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
244 cygwin) |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
245 |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
246 # Set an ACL for a group. |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
247 if setfacl -m group:0:1 tmpfile0; then |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
248 |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
249 func_test_has_acl tmpfile0 yes |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
250 |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
251 # Remove the ACL for the group. |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
252 setfacl -d group:0 tmpfile0 |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
253 |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
254 func_test_has_acl tmpfile0 no |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
255 |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
256 fi |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
257 ;; |
2f94bd2a861d
Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10148
diff
changeset
|
258 |
10142 | 259 hpux) |
260 | |
261 # Set an ACL for a user. | |
262 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'` | |
263 if chacl -r "${orig}($auid.%,--x)" tmpfile0; then | |
264 | |
265 func_test_has_acl tmpfile0 yes | |
266 | |
267 # Remove the ACL for the user. | |
268 chacl -d "($auid.%,--x)" tmpfile0 | |
269 | |
270 func_test_has_acl tmpfile0 no | |
271 | |
272 fi | |
273 ;; | |
274 | |
275 osf1) | |
276 | |
277 # Set an ACL for a user. | |
278 setacl -u user:$auid:1 tmpfile0 2> tmp.err | |
279 cat tmp.err 1>&2 | |
280 if grep 'Error:' tmp.err > /dev/null \ | |
281 || grep 'Operation not supported' tmp.err > /dev/null; then | |
282 : | |
283 else | |
284 | |
285 func_test_has_acl tmpfile0 yes | |
286 | |
287 # Remove the ACL for the user. | |
288 setacl -x user:$auid:1 tmpfile0 | |
289 | |
290 func_test_has_acl tmpfile0 no | |
291 | |
292 fi | |
293 ;; | |
294 | |
13757
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
295 nsk) |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
296 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
297 # Set an ACL for a user. |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
298 setacl -m user:$auid:1 tmpfile0 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
299 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
300 func_test_has_acl tmpfile0 yes |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
301 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
302 # Remove the ACL for the user. |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
303 setacl -d user:$auid tmpfile0 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
304 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
305 func_test_has_acl tmpfile0 no |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
306 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
307 ;; |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
11914
diff
changeset
|
308 |
10142 | 309 aix) |
310 | |
311 # Set an ACL for a user. | |
312 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0 | |
313 if aclget tmpfile0 | grep enabled > /dev/null; then | |
314 | |
315 func_test_has_acl tmpfile0 yes | |
316 | |
317 # Remove the ACL for the user. | |
318 aclget tmpfile0 | grep -v ' u:[^ ]*$' | aclput tmpfile0 | |
319 | |
320 func_test_has_acl tmpfile0 no | |
321 | |
322 fi | |
323 ;; | |
324 | |
325 macosx) | |
326 | |
327 # Set an ACL for a user. | |
328 /bin/chmod +a "user:daemon allow execute" tmpfile0 | |
329 | |
330 func_test_has_acl tmpfile0 yes | |
331 | |
332 # Remove the ACL for the user. | |
333 /bin/chmod -a "user:daemon allow execute" tmpfile0 | |
334 | |
335 func_test_has_acl tmpfile0 no | |
336 | |
337 ;; | |
338 | |
339 irix) | |
340 | |
341 # Set an ACL for a user. | |
342 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0 2> tmp.err | |
343 cat tmp.err 1>&2 | |
344 if test -s tmp.err; then :; else | |
345 | |
346 func_test_has_acl tmpfile0 yes | |
347 | |
348 # Remove the ACL for the user. | |
349 /sbin/chacl user::rw-,group::---,other::--- tmpfile0 | |
350 | |
351 func_test_has_acl tmpfile0 no | |
352 | |
353 fi | |
354 ;; | |
355 | |
356 esac | |
357 fi | |
358 | |
359 rm -f tmpfile[0-9] tmp.err | |
11551
957a85702f2b
Fix test-file-has-acl on FreeBSD.
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents:
10444
diff
changeset
|
360 rm -rf tmpdir0 |
10142 | 361 ) || exit 1 |
362 | |
363 rm -rf "$tmp" | |
364 exit 0 |