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
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 echo "Simple contents" > "$2"
182 "$builddir"/test-copy-acl${EXEEXT} "$1" "$2" || exit 1
183 "$builddir"/test-sameacls${EXEEXT} "$1" "$2" || exit 1
184 func_test_same_acls "$1" "$2" || exit 1
187 func_test_copy tmpfile0 tmpfile1
189 if 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 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
419 func_test_copy tmpfile0 tmpfile2
421 # Set an ACL for a group.
422 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit r-- g:$agid"; } | aclput tmpfile0
424 func_test_copy tmpfile0 tmpfile3
426 # Set an ACL for other.
429 func_test_copy tmpfile0 tmpfile4
431 # Remove the ACL for the user.
432 aclget tmpfile0 | grep -v ' u:[^ ]*$' | aclput tmpfile0
434 func_test_copy tmpfile0 tmpfile5
436 # Remove the ACL for the group.
437 aclget tmpfile0 | grep -v ' g:[^ ]*$' | aclput tmpfile0
439 func_test_copy tmpfile0 tmpfile7
441 # Delete all optional ACLs.
442 aclget tmpfile0 | sed -e 's/enabled$/disabled/' | sed -e '/disabled$/q' | aclput tmpfile0
444 func_test_copy tmpfile0 tmpfile8
446 # Copy ACLs from a file that has no ACLs.
449 aclget tmpfile9 | aclput tmpfile0
452 func_test_copy tmpfile0 tmpfile9
458 # Set an ACL for a user.
459 /bin/chmod +a "user:daemon allow execute" tmpfile0
461 func_test_copy tmpfile0 tmpfile2
463 # Set an ACL for a group.
464 /bin/chmod +a "group:daemon allow read" tmpfile0
466 func_test_copy tmpfile0 tmpfile3
468 # Set an ACL for other.
471 func_test_copy tmpfile0 tmpfile4
473 # Remove the ACL for the user.
474 /bin/chmod -a "user:daemon allow execute" tmpfile0
476 func_test_copy tmpfile0 tmpfile5
478 # Remove the ACL for the group.
479 /bin/chmod -a "group:daemon allow read" tmpfile0
481 func_test_copy tmpfile0 tmpfile7
483 # Delete all optional ACLs.
484 /bin/chmod -N tmpfile0
486 func_test_copy tmpfile0 tmpfile8
488 # Copy ACLs from a file that has no ACLs.
491 { /bin/ls -le tmpfile9 | sed -n -e 's/^ [0-9][0-9]*: //p'; echo; } | /bin/chmod -E tmpfile0
494 func_test_copy tmpfile0 tmpfile9
500 # Set an ACL for a user.
501 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0
503 func_test_copy tmpfile0 tmpfile2
505 # Set an ACL for a group.
506 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x,group:$agid:r-- tmpfile0
508 func_test_copy tmpfile0 tmpfile3
510 # Set an ACL for other.
511 /sbin/chacl user::rw-,group::---,user:$auid:--x,group:$agid:r--,other::r-- tmpfile0
513 func_test_copy tmpfile0 tmpfile4
515 # Remove the ACL for the user.
516 /sbin/chacl user::rw-,group::---,group:$agid:r--,other::r-- tmpfile0
518 func_test_copy tmpfile0 tmpfile5
520 # Remove the ACL for the group.
521 /sbin/chacl user::rw-,group::---,other::r-- tmpfile0
523 func_test_copy tmpfile0 tmpfile7
530 rm -f tmpfile[0-9] tmpaclout[0-2]