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, hpuxjfs, 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.
91 if (getacl tmpfile0 >/dev/null) 2>/dev/null; then
92 # HP-UX 11.11 or newer.
99 if (getacl tmpfile0 >/dev/null) 2>/dev/null; then
100 # Tru64, NonStop Kernel.
101 if (getacl -m tmpfile0 >/dev/null) 2>/dev/null; then
109 if (aclget tmpfile0 >/dev/null) 2>/dev/null; then
113 if (fsaclctl -v >/dev/null) 2>/dev/null; then
117 if test -f /sbin/chacl; then
127 # Define a function to test for the same ACLs, from the point of view of
129 # func_test_same_acls file1 file2
131 linux | cygwin | freebsd | solaris)
132 func_test_same_acls ()
134 getfacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
135 getfacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
136 cmp tmpaclout1 tmpaclout2 > /dev/null
140 func_test_same_acls ()
142 lsacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
143 lsacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
144 cmp tmpaclout1 tmpaclout2 > /dev/null
148 func_test_same_acls ()
150 { lsacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
151 lsacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
152 cmp tmpaclout1 tmpaclout2 > /dev/null
154 { getacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
155 getacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
156 cmp tmpaclout1 tmpaclout2 > /dev/null
161 func_test_same_acls ()
163 getacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
164 getacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
165 cmp tmpaclout1 tmpaclout2 > /dev/null
169 func_test_same_acls ()
171 aclget "$1" > tmpaclout1
172 aclget "$2" > tmpaclout2
173 cmp tmpaclout1 tmpaclout2 > /dev/null
177 func_test_same_acls ()
179 /bin/ls -le "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
180 /bin/ls -le "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
181 cmp tmpaclout1 tmpaclout2 > /dev/null
185 func_test_same_acls ()
187 /bin/ls -lD "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
188 /bin/ls -lD "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
189 cmp tmpaclout1 tmpaclout2 > /dev/null
193 func_test_same_acls ()
200 # func_test_copy file1 file2
201 # copies file1 to file2 and verifies the permissions and ACLs are the same
205 echo "Simple contents" > "$2"
207 "$builddir"/test-copy-acl${EXEEXT} "$1" "$2" || exit 1
208 "$builddir"/test-sameacls${EXEEXT} "$1" "$2" || exit 1
209 func_test_same_acls "$1" "$2" || exit 1
212 func_test_copy tmpfile0 tmpfile1
214 if test $acl_flavor != none; then
215 # A POSIX compliant 'id' program.
216 if test -f /usr/xpg4/bin/id; then
221 # Use a user and group id different from the current one, to avoid
222 # redundant/ambiguous ACLs.
226 if test "$auid" = "$myuid"; then auid=2; fi
228 if test "$agid" = "$mygid"; then agid=2; fi
231 linux | freebsd | solaris)
233 # Set an ACL for a user.
234 setfacl -m user:$auid:1 tmpfile0
236 func_test_copy tmpfile0 tmpfile2
238 # Set an ACL for a group.
239 setfacl -m group:$agid:4 tmpfile0
241 func_test_copy tmpfile0 tmpfile3
243 # Set an ACL for other.
245 freebsd) setfacl -m other::4 tmpfile0 ;;
246 solaris) chmod o+r tmpfile0 ;;
247 *) setfacl -m other:4 tmpfile0 ;;
250 func_test_copy tmpfile0 tmpfile4
252 # Remove the ACL for the user.
254 linux) setfacl -x user:$auid tmpfile0 ;;
255 freebsd) setfacl -x user:$auid:1 tmpfile0 ;;
256 *) setfacl -d user:$auid:1 tmpfile0 ;;
259 func_test_copy tmpfile0 tmpfile5
261 # Remove the ACL for other.
263 linux | solaris) ;; # impossible
264 freebsd) setfacl -x other::4 tmpfile0 ;;
265 *) setfacl -d other:4 tmpfile0 ;;
268 func_test_copy tmpfile0 tmpfile6
270 # Remove the ACL for the group.
272 linux) setfacl -x group:$agid tmpfile0 ;;
273 freebsd) setfacl -x group:$agid:4 tmpfile0 ;;
274 *) setfacl -d group:$agid:4 tmpfile0 ;;
277 func_test_copy tmpfile0 tmpfile7
279 # Delete all optional ACLs.
282 setfacl -m user:$auid:1 tmpfile0
286 setfacl -s user::6,group::0,other:0 tmpfile0 ;;
289 func_test_copy tmpfile0 tmpfile8
291 # Copy ACLs from a file that has no ACLs.
295 linux) getfacl tmpfile9 | setfacl --set-file=- tmpfile0 ;;
297 *) getfacl tmpfile9 | setfacl -f - tmpfile0 ;;
301 func_test_copy tmpfile0 tmpfile9
307 # Set an ACL for a group.
308 setfacl -m group:0:1 tmpfile0
310 func_test_copy tmpfile0 tmpfile2
312 # Set an ACL for other.
313 setfacl -m other:4 tmpfile0
315 func_test_copy tmpfile0 tmpfile4
317 # Remove the ACL for the group.
318 setfacl -d group:0 tmpfile0
320 func_test_copy tmpfile0 tmpfile5
322 # Remove the ACL for other.
323 setfacl -d other:4 tmpfile0
325 func_test_copy tmpfile0 tmpfile6
327 # Delete all optional ACLs.
328 setfacl -s user::6,group::0,other:0 tmpfile0
330 func_test_copy tmpfile0 tmpfile8
332 # Copy ACLs from a file that has no ACLs.
335 getfacl tmpfile9 | setfacl -f - tmpfile0
338 func_test_copy tmpfile0 tmpfile9
344 # Set an ACL for a user.
345 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
346 chacl -r "${orig}($auid.%,--x)" tmpfile0
348 func_test_copy tmpfile0 tmpfile2
350 # Set an ACL for a group.
351 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
352 chacl -r "${orig}(%.$agid,r--)" tmpfile0
354 func_test_copy tmpfile0 tmpfile3
356 # Set an ACL for other.
357 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
358 chacl -r "${orig}(%.%,r--)" tmpfile0
360 func_test_copy tmpfile0 tmpfile4
362 # Remove the ACL for the user.
363 chacl -d "($auid.%,--x)" tmpfile0
365 func_test_copy tmpfile0 tmpfile5
367 # Remove the ACL for the group.
368 chacl -d "(%.$agid,r--)" tmpfile0
370 func_test_copy tmpfile0 tmpfile6
372 # Delete all optional ACLs.
375 func_test_copy tmpfile0 tmpfile8
377 # Copy ACLs from a file that has no ACLs.
380 orig=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
382 chacl -r "${orig}" tmpfile0
384 func_test_copy tmpfile0 tmpfile9
390 # Set an ACL for a user.
391 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
392 chacl -r "${orig}($auid.%,--x)" tmpfile0 \
393 || setacl -m user:$auid:1 tmpfile0
395 func_test_copy tmpfile0 tmpfile2
397 # Set an ACL for a group.
398 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
399 chacl -r "${orig}(%.$agid,r--)" tmpfile0 \
400 || setacl -m group:$agid:4 tmpfile0
402 func_test_copy tmpfile0 tmpfile3
404 # Set an ACL for other.
405 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
406 chacl -r "${orig}(%.%,r--)" tmpfile0 \
407 || setacl -m other:4 tmpfile0
409 func_test_copy tmpfile0 tmpfile4
411 # Remove the ACL for the user.
412 chacl -d "($auid.%,--x)" tmpfile0 \
413 || setacl -d user:$auid tmpfile0
415 func_test_copy tmpfile0 tmpfile5
417 # Remove the ACL for the group.
418 chacl -d "(%.$agid,r--)" tmpfile0 \
419 || setacl -d group:$agid tmpfile0
421 func_test_copy tmpfile0 tmpfile6
423 # Delete all optional ACLs.
425 || { setacl -m user:$auid:1 tmpfile0
426 setacl -s user::6,group::0,class:7,other:0 tmpfile0
429 func_test_copy tmpfile0 tmpfile8
431 # Copy ACLs from a file that has no ACLs.
434 orig=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
435 getacl tmpfile9 > tmpaclout0
437 chacl -r "${orig}" tmpfile0 \
438 || setacl -f tmpaclout0 tmpfile0
440 func_test_copy tmpfile0 tmpfile9
446 # Set an ACL for a user.
447 setacl -u user:$auid:1 tmpfile0
449 func_test_copy tmpfile0 tmpfile2
451 # Set an ACL for a group.
452 setacl -u group:$agid:4 tmpfile0
454 func_test_copy tmpfile0 tmpfile3
456 # Set an ACL for other.
457 setacl -u other::4 tmpfile0
459 func_test_copy tmpfile0 tmpfile4
461 # Remove the ACL for the user.
462 setacl -x user:$auid:1 tmpfile0
464 func_test_copy tmpfile0 tmpfile5
466 if false; then # would give an error "can't set ACL: Invalid argument"
467 # Remove the ACL for other.
468 setacl -x other::4 tmpfile0
470 func_test_copy tmpfile0 tmpfile6
473 # Remove the ACL for the group.
474 setacl -x group:$agid:4 tmpfile0
476 func_test_copy tmpfile0 tmpfile7
478 # Delete all optional ACLs.
479 setacl -u user:$auid:1 tmpfile0
482 func_test_copy tmpfile0 tmpfile8
484 # Copy ACLs from a file that has no ACLs.
487 getacl tmpfile9 > tmpaclout0
488 setacl -b -U tmpaclout0 tmpfile0
491 func_test_copy tmpfile0 tmpfile9
497 # Set an ACL for a user.
498 setacl -m user:$auid:1 tmpfile0
500 func_test_copy tmpfile0 tmpfile2
502 # Set an ACL for a group.
503 setacl -m group:$agid:4 tmpfile0
505 func_test_copy tmpfile0 tmpfile3
507 # Set an ACL for other.
508 setacl -m other:4 tmpfile0
510 func_test_copy tmpfile0 tmpfile4
512 # Remove the ACL for the user.
513 setacl -d user:$auid tmpfile0
515 func_test_copy tmpfile0 tmpfile5
517 # Remove the ACL for the group.
518 setacl -d group:$agid tmpfile0
520 func_test_copy tmpfile0 tmpfile6
522 # Delete all optional ACLs.
523 setacl -m user:$auid:1 tmpfile0
524 setacl -s user::6,group::0,class:7,other:0 tmpfile0
526 func_test_copy tmpfile0 tmpfile8
528 # Copy ACLs from a file that has no ACLs.
531 getacl tmpfile9 > tmpaclout0
532 setacl -f tmpaclout0 tmpfile0
535 func_test_copy tmpfile0 tmpfile9
541 # Set an ACL for a user.
542 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
544 func_test_copy tmpfile0 tmpfile2
546 # Set an ACL for a group.
547 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit r-- g:$agid"; } | aclput tmpfile0
549 func_test_copy tmpfile0 tmpfile3
551 # Set an ACL for other.
554 func_test_copy tmpfile0 tmpfile4
556 # Remove the ACL for the user.
557 aclget tmpfile0 | grep -v ' u:[^ ]*$' | aclput tmpfile0
559 func_test_copy tmpfile0 tmpfile5
561 # Remove the ACL for the group.
562 aclget tmpfile0 | grep -v ' g:[^ ]*$' | aclput tmpfile0
564 func_test_copy tmpfile0 tmpfile7
566 # Delete all optional ACLs.
567 aclget tmpfile0 | sed -e 's/enabled$/disabled/' | sed -e '/disabled$/q' | aclput tmpfile0
569 func_test_copy tmpfile0 tmpfile8
571 # Copy ACLs from a file that has no ACLs.
574 aclget tmpfile9 | aclput tmpfile0
577 func_test_copy tmpfile0 tmpfile9
583 # Set an ACL for a user.
584 /bin/chmod +a "user:daemon allow execute" tmpfile0
586 func_test_copy tmpfile0 tmpfile2
588 # Set an ACL for a group.
589 /bin/chmod +a "group:daemon allow read" tmpfile0
591 func_test_copy tmpfile0 tmpfile3
593 # Set an ACL for other.
596 func_test_copy tmpfile0 tmpfile4
598 # Remove the ACL for the user.
599 /bin/chmod -a "user:daemon allow execute" tmpfile0
601 func_test_copy tmpfile0 tmpfile5
603 # Remove the ACL for the group.
604 /bin/chmod -a "group:daemon allow read" tmpfile0
606 func_test_copy tmpfile0 tmpfile7
608 # Delete all optional ACLs.
609 /bin/chmod -N tmpfile0
611 func_test_copy tmpfile0 tmpfile8
613 # Copy ACLs from a file that has no ACLs.
616 { /bin/ls -le tmpfile9 | sed -n -e 's/^ [0-9][0-9]*: //p'; echo; } | /bin/chmod -E tmpfile0
619 func_test_copy tmpfile0 tmpfile9
625 # Set an ACL for a user.
626 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0
628 func_test_copy tmpfile0 tmpfile2
630 # Set an ACL for a group.
631 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x,group:$agid:r-- tmpfile0
633 func_test_copy tmpfile0 tmpfile3
635 # Set an ACL for other.
636 /sbin/chacl user::rw-,group::---,user:$auid:--x,group:$agid:r--,other::r-- tmpfile0
638 func_test_copy tmpfile0 tmpfile4
640 # Remove the ACL for the user.
641 /sbin/chacl user::rw-,group::---,group:$agid:r--,other::r-- tmpfile0
643 func_test_copy tmpfile0 tmpfile5
645 # Remove the ACL for the group.
646 /sbin/chacl user::rw-,group::---,other::r-- tmpfile0
648 func_test_copy tmpfile0 tmpfile7
655 rm -f tmpfile[0-9] tmpaclout[0-2]