3 # Show all commands when run with environment variable VERBOSE=yes.
4 test -z "$VERBOSE" || set -x
8 echo "Skipping test: insufficient ACL support"
13 # creates a temporary directory.
15 # - tmp pathname of freshly created temporary directory
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.
23 # Use the mktemp program if available. If not available, hide the error
25 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
26 test -n "$tmp" && test -d "$tmp"
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
34 tmp=$TMPDIR/gl$$-$RANDOM
35 (umask 077 && mkdir "$tmp")
38 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
47 echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
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.)
56 rm -f tmpfile[0-9] tmpaclout[0-2]
57 echo "Simple contents" > tmpfile0
60 # Classification of the platform according to the programs available for
62 # Possible values are:
63 # linux, cygwin, freebsd, solaris, hpux, osf1, aix, macosx, irix, none.
64 # TODO: Support also native Win32 platforms (mingw).
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
71 if (LC_ALL=C setfacl --help | grep ' --set-file' >/dev/null) 2>/dev/null; then
79 if (LC_ALL=C setfacl 2>&1 | grep '\-x entries' >/dev/null) 2>/dev/null; then
88 if (lsacl / >/dev/null) 2>/dev/null; then
89 # Platforms with the lsacl and chacl programs.
90 # HP-UX, sometimes also IRIX.
93 if (getacl tmpfile0 >/dev/null) 2>/dev/null; then
94 # Tru64, NonStop Kernel.
95 if (getacl -m tmpfile0 >/dev/null) 2>/dev/null; then
103 if (aclget tmpfile0 >/dev/null) 2>/dev/null; then
107 if (fsaclctl -v >/dev/null) 2>/dev/null; then
111 if test -f /sbin/chacl; then
121 # Define a function to test for the same ACLs, from the point of view of
123 # func_test_same_acls file1 file2
125 linux | cygwin | freebsd | solaris)
126 func_test_same_acls ()
128 getfacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
129 getfacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
130 cmp tmpaclout1 tmpaclout2 > /dev/null
134 func_test_same_acls ()
136 lsacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
137 lsacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
138 cmp tmpaclout1 tmpaclout2 > /dev/null
142 func_test_same_acls ()
144 getacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
145 getacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
146 cmp tmpaclout1 tmpaclout2 > /dev/null
150 func_test_same_acls ()
152 aclget "$1" > tmpaclout1
153 aclget "$2" > tmpaclout2
154 cmp tmpaclout1 tmpaclout2 > /dev/null
158 func_test_same_acls ()
160 /bin/ls -le "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
161 /bin/ls -le "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
162 cmp tmpaclout1 tmpaclout2 > /dev/null
166 func_test_same_acls ()
168 /bin/ls -lD "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
169 /bin/ls -lD "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
170 cmp tmpaclout1 tmpaclout2 > /dev/null
174 func_test_same_acls ()
181 # func_test_copy file1 file2
182 # copies file1 to file2 and verifies the permissions and ACLs are the same
186 echo "Simple contents" > "$2"
188 "$builddir"/test-copy-acl${EXEEXT} "$1" "$2" || exit 1
189 "$builddir"/test-sameacls${EXEEXT} "$1" "$2" || exit 1
190 func_test_same_acls "$1" "$2" || exit 1
193 func_test_copy tmpfile0 tmpfile1
195 if test $acl_flavor != none; then
196 # A POSIX compliant 'id' program.
197 if test -f /usr/xpg4/bin/id; then
202 # Use a user and group id different from the current one, to avoid
203 # redundant/ambiguous ACLs.
207 if test "$auid" = "$myuid"; then auid=2; fi
209 if test "$agid" = "$mygid"; then agid=2; fi
212 linux | freebsd | solaris)
214 # Set an ACL for a user.
215 setfacl -m user:$auid:1 tmpfile0
217 func_test_copy tmpfile0 tmpfile2
219 # Set an ACL for a group.
220 setfacl -m group:$agid:4 tmpfile0
222 func_test_copy tmpfile0 tmpfile3
224 # Set an ACL for other.
226 freebsd) setfacl -m other::4 tmpfile0 ;;
227 solaris) chmod o+r tmpfile0 ;;
228 *) setfacl -m other:4 tmpfile0 ;;
231 func_test_copy tmpfile0 tmpfile4
233 # Remove the ACL for the user.
235 linux) setfacl -x user:$auid tmpfile0 ;;
236 freebsd) setfacl -x user:$auid:1 tmpfile0 ;;
237 *) setfacl -d user:$auid:1 tmpfile0 ;;
240 func_test_copy tmpfile0 tmpfile5
242 # Remove the ACL for other.
244 linux | solaris) ;; # impossible
245 freebsd) setfacl -x other::4 tmpfile0 ;;
246 *) setfacl -d other:4 tmpfile0 ;;
249 func_test_copy tmpfile0 tmpfile6
251 # Remove the ACL for the group.
253 linux) setfacl -x group:$agid tmpfile0 ;;
254 freebsd) setfacl -x group:$agid:4 tmpfile0 ;;
255 *) setfacl -d group:$agid:4 tmpfile0 ;;
258 func_test_copy tmpfile0 tmpfile7
260 # Delete all optional ACLs.
263 setfacl -m user:$auid:1 tmpfile0
267 setfacl -s user::6,group::0,other:0 tmpfile0 ;;
270 func_test_copy tmpfile0 tmpfile8
272 # Copy ACLs from a file that has no ACLs.
276 linux) getfacl tmpfile9 | setfacl --set-file=- tmpfile0 ;;
278 *) getfacl tmpfile9 | setfacl -f - tmpfile0 ;;
282 func_test_copy tmpfile0 tmpfile9
288 # Set an ACL for a group.
289 setfacl -m group:0:1 tmpfile0
291 func_test_copy tmpfile0 tmpfile2
293 # Set an ACL for other.
294 setfacl -m other:4 tmpfile0
296 func_test_copy tmpfile0 tmpfile4
298 # Remove the ACL for the group.
299 setfacl -d group:0 tmpfile0
301 func_test_copy tmpfile0 tmpfile5
303 # Remove the ACL for other.
304 setfacl -d other:4 tmpfile0
306 func_test_copy tmpfile0 tmpfile6
308 # Delete all optional ACLs.
309 setfacl -s user::6,group::0,other:0 tmpfile0
311 func_test_copy tmpfile0 tmpfile8
313 # Copy ACLs from a file that has no ACLs.
316 getfacl tmpfile9 | setfacl -f - tmpfile0
319 func_test_copy tmpfile0 tmpfile9
325 # Set an ACL for a user.
326 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
327 chacl -r "${orig}($auid.%,--x)" tmpfile0
329 func_test_copy tmpfile0 tmpfile2
331 # Set an ACL for a group.
332 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
333 chacl -r "${orig}(%.$agid,r--)" tmpfile0
335 func_test_copy tmpfile0 tmpfile3
337 # Set an ACL for other.
338 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
339 chacl -r "${orig}(%.%,r--)" tmpfile0
341 func_test_copy tmpfile0 tmpfile4
343 # Remove the ACL for the user.
344 chacl -d "($auid.%,--x)" tmpfile0
346 func_test_copy tmpfile0 tmpfile5
348 # Remove the ACL for the group.
349 chacl -d "(%.$agid,r--)" tmpfile0
351 func_test_copy tmpfile0 tmpfile6
353 # Delete all optional ACLs.
356 func_test_copy tmpfile0 tmpfile8
358 # Copy ACLs from a file that has no ACLs.
361 orig=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
363 chacl -r "${orig}" tmpfile0
365 func_test_copy tmpfile0 tmpfile9
371 # Set an ACL for a user.
372 setacl -u user:$auid:1 tmpfile0
374 func_test_copy tmpfile0 tmpfile2
376 # Set an ACL for a group.
377 setacl -u group:$agid:4 tmpfile0
379 func_test_copy tmpfile0 tmpfile3
381 # Set an ACL for other.
382 setacl -u other::4 tmpfile0
384 func_test_copy tmpfile0 tmpfile4
386 # Remove the ACL for the user.
387 setacl -x user:$auid:1 tmpfile0
389 func_test_copy tmpfile0 tmpfile5
391 if false; then # would give an error "can't set ACL: Invalid argument"
392 # Remove the ACL for other.
393 setacl -x other::4 tmpfile0
395 func_test_copy tmpfile0 tmpfile6
398 # Remove the ACL for the group.
399 setacl -x group:$agid:4 tmpfile0
401 func_test_copy tmpfile0 tmpfile7
403 # Delete all optional ACLs.
404 setacl -u user:$auid:1 tmpfile0
407 func_test_copy tmpfile0 tmpfile8
409 # Copy ACLs from a file that has no ACLs.
412 getacl tmpfile9 > tmpaclout0
413 setacl -b -U tmpaclout0 tmpfile0
416 func_test_copy tmpfile0 tmpfile9
422 # Set an ACL for a user.
423 setacl -m user:$auid:1 tmpfile0
425 func_test_copy tmpfile0 tmpfile2
427 # Set an ACL for a group.
428 setacl -m group:$agid:4 tmpfile0
430 func_test_copy tmpfile0 tmpfile3
432 # Set an ACL for other.
433 setacl -m other:4 tmpfile0
435 func_test_copy tmpfile0 tmpfile4
437 # Remove the ACL for the user.
438 setacl -d user:$auid tmpfile0
440 func_test_copy tmpfile0 tmpfile5
442 # Remove the ACL for the group.
443 setacl -d group:$agid tmpfile0
445 func_test_copy tmpfile0 tmpfile6
447 # Delete all optional ACLs.
448 setacl -m user:$auid:1 tmpfile0
449 setacl -s user::6,group::0,class:7,other:0 tmpfile0
451 func_test_copy tmpfile0 tmpfile8
453 # Copy ACLs from a file that has no ACLs.
456 getacl tmpfile9 > tmpaclout0
457 setacl -f tmpaclout0 tmpfile0
460 func_test_copy tmpfile0 tmpfile9
466 # Set an ACL for a user.
467 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
469 func_test_copy tmpfile0 tmpfile2
471 # Set an ACL for a group.
472 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit r-- g:$agid"; } | aclput tmpfile0
474 func_test_copy tmpfile0 tmpfile3
476 # Set an ACL for other.
479 func_test_copy tmpfile0 tmpfile4
481 # Remove the ACL for the user.
482 aclget tmpfile0 | grep -v ' u:[^ ]*$' | aclput tmpfile0
484 func_test_copy tmpfile0 tmpfile5
486 # Remove the ACL for the group.
487 aclget tmpfile0 | grep -v ' g:[^ ]*$' | aclput tmpfile0
489 func_test_copy tmpfile0 tmpfile7
491 # Delete all optional ACLs.
492 aclget tmpfile0 | sed -e 's/enabled$/disabled/' | sed -e '/disabled$/q' | aclput tmpfile0
494 func_test_copy tmpfile0 tmpfile8
496 # Copy ACLs from a file that has no ACLs.
499 aclget tmpfile9 | aclput tmpfile0
502 func_test_copy tmpfile0 tmpfile9
508 # Set an ACL for a user.
509 /bin/chmod +a "user:daemon allow execute" tmpfile0
511 func_test_copy tmpfile0 tmpfile2
513 # Set an ACL for a group.
514 /bin/chmod +a "group:daemon allow read" tmpfile0
516 func_test_copy tmpfile0 tmpfile3
518 # Set an ACL for other.
521 func_test_copy tmpfile0 tmpfile4
523 # Remove the ACL for the user.
524 /bin/chmod -a "user:daemon allow execute" tmpfile0
526 func_test_copy tmpfile0 tmpfile5
528 # Remove the ACL for the group.
529 /bin/chmod -a "group:daemon allow read" tmpfile0
531 func_test_copy tmpfile0 tmpfile7
533 # Delete all optional ACLs.
534 /bin/chmod -N tmpfile0
536 func_test_copy tmpfile0 tmpfile8
538 # Copy ACLs from a file that has no ACLs.
541 { /bin/ls -le tmpfile9 | sed -n -e 's/^ [0-9][0-9]*: //p'; echo; } | /bin/chmod -E tmpfile0
544 func_test_copy tmpfile0 tmpfile9
550 # Set an ACL for a user.
551 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0
553 func_test_copy tmpfile0 tmpfile2
555 # Set an ACL for a group.
556 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x,group:$agid:r-- tmpfile0
558 func_test_copy tmpfile0 tmpfile3
560 # Set an ACL for other.
561 /sbin/chacl user::rw-,group::---,user:$auid:--x,group:$agid:r--,other::r-- tmpfile0
563 func_test_copy tmpfile0 tmpfile4
565 # Remove the ACL for the user.
566 /sbin/chacl user::rw-,group::---,group:$agid:r--,other::r-- tmpfile0
568 func_test_copy tmpfile0 tmpfile5
570 # Remove the ACL for the group.
571 /sbin/chacl user::rw-,group::---,other::r-- tmpfile0
573 func_test_copy tmpfile0 tmpfile7
580 rm -f tmpfile[0-9] tmpaclout[0-2]