3 # Show all commands when run with environment variable VERBOSE=yes.
4 test -z "$VERBOSE" || set -x
7 # creates a temporary directory.
9 # - tmp pathname of freshly created temporary directory
12 # Use the environment variable TMPDIR, falling back to /tmp. This allows
13 # users to specify a different temporary directory, for example, if their
14 # /tmp is filled up or too small.
17 # Use the mktemp program if available. If not available, hide the error
19 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
20 test -n "$tmp" && test -d "$tmp"
23 # Use a simple mkdir command. It is guaranteed to fail if the directory
24 # already exists. $RANDOM is bash specific and expands to empty in shells
25 # other than bash, ksh and zsh. Its use does not increase security;
26 # rather, it minimizes the probability of failure in a very cluttered /tmp
28 tmp=$TMPDIR/gl$$-$RANDOM
29 (umask 077 && mkdir "$tmp")
32 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
41 echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
44 # Switch to a temporary directory, to increase the likelihood that ACLs are
45 # supported on the current file system. (/tmp is usually locally mounted,
46 # whereas the build dir is sometimes NFS-mounted.)
50 rm -f tmpfile[0-9] tmpaclout[0-2]
51 echo "Simple contents" > tmpfile0
54 # Classification of the platform according to the programs available for
56 # Possible values are:
57 # linux, cygwin, freebsd, solaris, hpux, osf1, aix, macosx, irix, none.
58 # TODO: Support also native Win32 platforms (mingw).
60 if (getfacl tmpfile0 >/dev/null) 2>/dev/null; then
61 # Platforms with the getfacl and setfacl programs.
62 # Linux, FreeBSD, Solaris, Cygwin.
63 if (setfacl --help >/dev/null) 2>/dev/null; then
65 if (LC_ALL=C setfacl --help | grep ' --set-file' >/dev/null) 2>/dev/null; then
73 if (LC_ALL=C setfacl 2>&1 | grep '\-x entries' >/dev/null) 2>/dev/null; then
82 if (lsacl / >/dev/null) 2>/dev/null; then
83 # Platforms with the lsacl and chacl programs.
84 # HP-UX, sometimes also IRIX.
87 if (getacl tmpfile0 >/dev/null) 2>/dev/null; then
88 # Tru64, NonStop Kernel.
89 if (getacl -m tmpfile0 >/dev/null) 2>/dev/null; then
97 if (aclget tmpfile0 >/dev/null) 2>/dev/null; then
101 if (fsaclctl -v >/dev/null) 2>/dev/null; then
105 if test -f /sbin/chacl; then
115 # Define a function to test for the same ACLs, from the point of view of
117 # func_test_same_acls file1 file2
119 linux | cygwin | freebsd | solaris)
120 func_test_same_acls ()
122 getfacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
123 getfacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
124 cmp tmpaclout1 tmpaclout2 > /dev/null
128 func_test_same_acls ()
130 lsacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
131 lsacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
132 cmp tmpaclout1 tmpaclout2 > /dev/null
136 func_test_same_acls ()
138 getacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
139 getacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
140 cmp tmpaclout1 tmpaclout2 > /dev/null
144 func_test_same_acls ()
146 aclget "$1" > tmpaclout1
147 aclget "$2" > tmpaclout2
148 cmp tmpaclout1 tmpaclout2 > /dev/null
152 func_test_same_acls ()
154 /bin/ls -le "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
155 /bin/ls -le "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
156 cmp tmpaclout1 tmpaclout2 > /dev/null
160 func_test_same_acls ()
162 /bin/ls -lD "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
163 /bin/ls -lD "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
164 cmp tmpaclout1 tmpaclout2 > /dev/null
168 func_test_same_acls ()
175 # func_test_copy file1 file2
176 # copies file1 to file2 and verifies the permissions and ACLs are the same
180 "$builddir"/test-copy-file${EXEEXT} "$1" "$2" || exit 1
181 if test "$USE_ACL" != 0; then
182 "$builddir"/test-sameacls${EXEEXT} "$1" "$2" || exit 1
183 func_test_same_acls "$1" "$2" || exit 1
187 func_test_copy tmpfile0 tmpfile1
189 if test "$USE_ACL" != 0 && test $acl_flavor != none; then
190 # A POSIX compliant 'id' program.
191 if test -f /usr/xpg4/bin/id; then
196 # Use a user and group id different from the current one, to avoid
197 # redundant/ambiguous ACLs.
201 if test "$auid" = "$myuid"; then auid=2; fi
203 if test "$agid" = "$mygid"; then agid=2; fi
206 linux | freebsd | solaris)
208 # Set an ACL for a user.
209 setfacl -m user:$auid:1 tmpfile0
211 func_test_copy tmpfile0 tmpfile2
213 # Set an ACL for a group.
214 setfacl -m group:$agid:4 tmpfile0
216 func_test_copy tmpfile0 tmpfile3
218 # Set an ACL for other.
220 freebsd) setfacl -m other::4 tmpfile0 ;;
221 solaris) chmod o+r tmpfile0 ;;
222 *) setfacl -m other:4 tmpfile0 ;;
225 func_test_copy tmpfile0 tmpfile4
227 # Remove the ACL for the user.
229 linux) setfacl -x user:$auid tmpfile0 ;;
230 freebsd) setfacl -x user:$auid:1 tmpfile0 ;;
231 *) setfacl -d user:$auid:1 tmpfile0 ;;
234 func_test_copy tmpfile0 tmpfile5
236 # Remove the ACL for other.
238 linux | solaris) ;; # impossible
239 freebsd) setfacl -x other::4 tmpfile0 ;;
240 *) setfacl -d other:4 tmpfile0 ;;
243 func_test_copy tmpfile0 tmpfile6
245 # Remove the ACL for the group.
247 linux) setfacl -x group:$agid tmpfile0 ;;
248 freebsd) setfacl -x group:$agid:4 tmpfile0 ;;
249 *) setfacl -d group:$agid:4 tmpfile0 ;;
252 func_test_copy tmpfile0 tmpfile7
254 # Delete all optional ACLs.
257 setfacl -m user:$auid:1 tmpfile0
261 setfacl -s user::6,group::0,other:0 tmpfile0 ;;
264 func_test_copy tmpfile0 tmpfile8
266 # Copy ACLs from a file that has no ACLs.
270 linux) getfacl tmpfile9 | setfacl --set-file=- tmpfile0 ;;
272 *) getfacl tmpfile9 | setfacl -f - tmpfile0 ;;
276 func_test_copy tmpfile0 tmpfile9
282 # Set an ACL for a group.
283 setfacl -m group:0:1 tmpfile0
285 func_test_copy tmpfile0 tmpfile2
287 # Set an ACL for other.
288 setfacl -m other:4 tmpfile0
290 func_test_copy tmpfile0 tmpfile4
292 # Remove the ACL for the group.
293 setfacl -d group:0 tmpfile0
295 func_test_copy tmpfile0 tmpfile5
297 # Remove the ACL for other.
298 setfacl -d other:4 tmpfile0
300 func_test_copy tmpfile0 tmpfile6
302 # Delete all optional ACLs.
303 setfacl -s user::6,group::0,other:0 tmpfile0
305 func_test_copy tmpfile0 tmpfile8
307 # Copy ACLs from a file that has no ACLs.
310 getfacl tmpfile9 | setfacl -f - tmpfile0
313 func_test_copy tmpfile0 tmpfile9
319 # Set an ACL for a user.
320 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
321 chacl -r "${orig}($auid.%,--x)" tmpfile0
323 func_test_copy tmpfile0 tmpfile2
325 # Set an ACL for a group.
326 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
327 chacl -r "${orig}(%.$agid,r--)" tmpfile0
329 func_test_copy tmpfile0 tmpfile3
331 # Set an ACL for other.
332 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
333 chacl -r "${orig}(%.%,r--)" tmpfile0
335 func_test_copy tmpfile0 tmpfile4
337 # Remove the ACL for the user.
338 chacl -d "($auid.%,--x)" tmpfile0
340 func_test_copy tmpfile0 tmpfile5
342 # Remove the ACL for the group.
343 chacl -d "(%.$agid,r--)" tmpfile0
345 func_test_copy tmpfile0 tmpfile6
347 # Delete all optional ACLs.
350 func_test_copy tmpfile0 tmpfile8
352 # Copy ACLs from a file that has no ACLs.
355 orig=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
357 chacl -r "${orig}" tmpfile0
359 func_test_copy tmpfile0 tmpfile9
365 # Set an ACL for a user.
366 setacl -u user:$auid:1 tmpfile0
368 func_test_copy tmpfile0 tmpfile2
370 # Set an ACL for a group.
371 setacl -u group:$agid:4 tmpfile0
373 func_test_copy tmpfile0 tmpfile3
375 # Set an ACL for other.
376 setacl -u other::4 tmpfile0
378 func_test_copy tmpfile0 tmpfile4
380 # Remove the ACL for the user.
381 setacl -x user:$auid:1 tmpfile0
383 func_test_copy tmpfile0 tmpfile5
385 if false; then # would give an error "can't set ACL: Invalid argument"
386 # Remove the ACL for other.
387 setacl -x other::4 tmpfile0
389 func_test_copy tmpfile0 tmpfile6
392 # Remove the ACL for the group.
393 setacl -x group:$agid:4 tmpfile0
395 func_test_copy tmpfile0 tmpfile7
397 # Delete all optional ACLs.
398 setacl -u user:$auid:1 tmpfile0
401 func_test_copy tmpfile0 tmpfile8
403 # Copy ACLs from a file that has no ACLs.
406 getacl tmpfile9 > tmpaclout0
407 setacl -b -U tmpaclout0 tmpfile0
410 func_test_copy tmpfile0 tmpfile9
416 # Set an ACL for a user.
417 setacl -m user:$auid:1 tmpfile0
419 func_test_copy tmpfile0 tmpfile2
421 # Set an ACL for a group.
422 setacl -m group:$agid:4 tmpfile0
424 func_test_copy tmpfile0 tmpfile3
426 # Set an ACL for other.
427 setacl -m other:4 tmpfile0
429 func_test_copy tmpfile0 tmpfile4
431 # Remove the ACL for the user.
432 setacl -d user:$auid tmpfile0
434 func_test_copy tmpfile0 tmpfile5
436 # Remove the ACL for the group.
437 setacl -d group:$agid tmpfile0
439 func_test_copy tmpfile0 tmpfile6
441 # Delete all optional ACLs.
442 setacl -m user:$auid:1 tmpfile0
443 setacl -s user::6,group::0,class:7,other:0 tmpfile0
445 func_test_copy tmpfile0 tmpfile8
447 # Copy ACLs from a file that has no ACLs.
450 getacl tmpfile9 > tmpaclout0
451 setacl -f tmpaclout0 tmpfile0
454 func_test_copy tmpfile0 tmpfile9
460 # Set an ACL for a user.
461 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
463 func_test_copy tmpfile0 tmpfile2
465 # Set an ACL for a group.
466 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit r-- g:$agid"; } | aclput tmpfile0
468 func_test_copy tmpfile0 tmpfile3
470 # Set an ACL for other.
473 func_test_copy tmpfile0 tmpfile4
475 # Remove the ACL for the user.
476 aclget tmpfile0 | grep -v ' u:[^ ]*$' | aclput tmpfile0
478 func_test_copy tmpfile0 tmpfile5
480 # Remove the ACL for the group.
481 aclget tmpfile0 | grep -v ' g:[^ ]*$' | aclput tmpfile0
483 func_test_copy tmpfile0 tmpfile7
485 # Delete all optional ACLs.
486 aclget tmpfile0 | sed -e 's/enabled$/disabled/' | sed -e '/disabled$/q' | aclput tmpfile0
488 func_test_copy tmpfile0 tmpfile8
490 # Copy ACLs from a file that has no ACLs.
493 aclget tmpfile9 | aclput tmpfile0
496 func_test_copy tmpfile0 tmpfile9
502 # Set an ACL for a user.
503 /bin/chmod +a "user:daemon allow execute" tmpfile0
505 func_test_copy tmpfile0 tmpfile2
507 # Set an ACL for a group.
508 /bin/chmod +a "group:daemon allow read" tmpfile0
510 func_test_copy tmpfile0 tmpfile3
512 # Set an ACL for other.
515 func_test_copy tmpfile0 tmpfile4
517 # Remove the ACL for the user.
518 /bin/chmod -a "user:daemon allow execute" tmpfile0
520 func_test_copy tmpfile0 tmpfile5
522 # Remove the ACL for the group.
523 /bin/chmod -a "group:daemon allow read" tmpfile0
525 func_test_copy tmpfile0 tmpfile7
527 # Delete all optional ACLs.
528 /bin/chmod -N tmpfile0
530 func_test_copy tmpfile0 tmpfile8
532 # Copy ACLs from a file that has no ACLs.
535 { /bin/ls -le tmpfile9 | sed -n -e 's/^ [0-9][0-9]*: //p'; echo; } | /bin/chmod -E tmpfile0
538 func_test_copy tmpfile0 tmpfile9
544 # Set an ACL for a user.
545 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0
547 func_test_copy tmpfile0 tmpfile2
549 # Set an ACL for a group.
550 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x,group:$agid:r-- tmpfile0
552 func_test_copy tmpfile0 tmpfile3
554 # Set an ACL for other.
555 /sbin/chacl user::rw-,group::---,user:$auid:--x,group:$agid:r--,other::r-- tmpfile0
557 func_test_copy tmpfile0 tmpfile4
559 # Remove the ACL for the user.
560 /sbin/chacl user::rw-,group::---,group:$agid:r--,other::r-- tmpfile0
562 func_test_copy tmpfile0 tmpfile5
564 # Remove the ACL for the group.
565 /sbin/chacl user::rw-,group::---,other::r-- tmpfile0
567 func_test_copy tmpfile0 tmpfile7
574 rm -f tmpfile[0-9] tmpaclout[0-2]