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
91 if (aclget tmpfile0 >/dev/null) 2>/dev/null; then
95 if (fsaclctl -v >/dev/null) 2>/dev/null; then
99 if test -f /sbin/chacl; then
109 # Define a function to test for the same ACLs, from the point of view of
111 # func_test_same_acls file1 file2
113 linux | cygwin | freebsd | solaris)
114 func_test_same_acls ()
116 getfacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
117 getfacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
118 cmp tmpaclout1 tmpaclout2 > /dev/null
122 func_test_same_acls ()
124 lsacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
125 lsacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
126 cmp tmpaclout1 tmpaclout2 > /dev/null
130 func_test_same_acls ()
132 getacl "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
133 getacl "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
134 cmp tmpaclout1 tmpaclout2 > /dev/null
138 func_test_same_acls ()
140 aclget "$1" > tmpaclout1
141 aclget "$2" > tmpaclout2
142 cmp tmpaclout1 tmpaclout2 > /dev/null
146 func_test_same_acls ()
148 /bin/ls -le "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
149 /bin/ls -le "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
150 cmp tmpaclout1 tmpaclout2 > /dev/null
154 func_test_same_acls ()
156 /bin/ls -lD "$1" | sed -e "s/$1/FILENAME/g" > tmpaclout1
157 /bin/ls -lD "$2" | sed -e "s/$2/FILENAME/g" > tmpaclout2
158 cmp tmpaclout1 tmpaclout2 > /dev/null
162 func_test_same_acls ()
169 # func_test_copy file1 file2
170 # copies file1 to file2 and verifies the permissions and ACLs are the same
174 "$builddir"/test-copy-file${EXEEXT} "$1" "$2" || exit 1
175 "$builddir"/test-sameacls${EXEEXT} "$1" "$2" || exit 1
176 func_test_same_acls "$1" "$2" || exit 1
179 func_test_copy tmpfile0 tmpfile1
181 if test $acl_flavor != none; then
182 # Use a user and group id different from the current one, to avoid
183 # redundant/ambiguous ACLs.
187 if test "$auid" = "$myuid"; then auid=2; fi
189 if test "$agid" = "$mygid"; then agid=2; fi
192 linux | freebsd | solaris)
194 # Set an ACL for a user.
195 setfacl -m user:$auid:1 tmpfile0
197 func_test_copy tmpfile0 tmpfile2
199 # Set an ACL for a group.
200 setfacl -m group:$agid:4 tmpfile0
202 func_test_copy tmpfile0 tmpfile3
204 # Set an ACL for other.
206 freebsd) setfacl -m other::4 tmpfile0 ;;
207 solaris) chmod o+r tmpfile0 ;;
208 *) setfacl -m other:4 tmpfile0 ;;
211 func_test_copy tmpfile0 tmpfile4
213 # Remove the ACL for the user.
215 linux) setfacl -x user:$auid tmpfile0 ;;
216 freebsd) setfacl -x user:$auid:1 tmpfile0 ;;
217 *) setfacl -d user:$auid:1 tmpfile0 ;;
220 func_test_copy tmpfile0 tmpfile5
222 # Remove the ACL for other.
224 linux | solaris) ;; # impossible
225 freebsd) setfacl -x other::4 tmpfile0 ;;
226 *) setfacl -d other:4 tmpfile0 ;;
229 func_test_copy tmpfile0 tmpfile6
231 # Remove the ACL for the group.
233 linux) setfacl -x group:$agid tmpfile0 ;;
234 freebsd) setfacl -x group:$agid:4 tmpfile0 ;;
235 *) setfacl -d group:$agid:4 tmpfile0 ;;
238 func_test_copy tmpfile0 tmpfile7
240 # Delete all optional ACLs.
243 setfacl -m user:$auid:1 tmpfile0
247 setfacl -s user::6,group::0,other:0 tmpfile0 ;;
250 func_test_copy tmpfile0 tmpfile8
252 # Copy ACLs from a file that has no ACLs.
256 linux) getfacl tmpfile9 | setfacl --set-file=- tmpfile0 ;;
258 *) getfacl tmpfile9 | setfacl -f - tmpfile0 ;;
262 func_test_copy tmpfile0 tmpfile9
268 # Set an ACL for a group.
269 setfacl -m group:0:1 tmpfile0
271 func_test_copy tmpfile0 tmpfile2
273 # Set an ACL for other.
274 setfacl -m other:4 tmpfile0
276 func_test_copy tmpfile0 tmpfile4
278 # Remove the ACL for the group.
279 setfacl -d group:0 tmpfile0
281 func_test_copy tmpfile0 tmpfile5
283 # Remove the ACL for other.
284 setfacl -d other:4 tmpfile0
286 func_test_copy tmpfile0 tmpfile6
288 # Delete all optional ACLs.
289 setfacl -s user::6,group::0,other:0 tmpfile0
291 func_test_copy tmpfile0 tmpfile8
293 # Copy ACLs from a file that has no ACLs.
296 getfacl tmpfile9 | setfacl -f - tmpfile0
299 func_test_copy tmpfile0 tmpfile9
305 # Set an ACL for a user.
306 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
307 chacl -r "${orig}($auid.%,--x)" tmpfile0
309 func_test_copy tmpfile0 tmpfile2
311 # Set an ACL for a group.
312 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
313 chacl -r "${orig}(%.$agid,r--)" tmpfile0
315 func_test_copy tmpfile0 tmpfile3
317 # Set an ACL for other.
318 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
319 chacl -r "${orig}(%.%,r--)" tmpfile0
321 func_test_copy tmpfile0 tmpfile4
323 # Remove the ACL for the user.
324 chacl -d "($auid.%,--x)" tmpfile0
326 func_test_copy tmpfile0 tmpfile5
328 # Remove the ACL for the group.
329 chacl -d "(%.$agid,r--)" tmpfile0
331 func_test_copy tmpfile0 tmpfile6
333 # Delete all optional ACLs.
336 func_test_copy tmpfile0 tmpfile8
338 # Copy ACLs from a file that has no ACLs.
341 orig=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
343 chacl -r "${orig}" tmpfile0
345 func_test_copy tmpfile0 tmpfile9
351 # Set an ACL for a user.
352 setacl -u user:$auid:1 tmpfile0
354 func_test_copy tmpfile0 tmpfile2
356 # Set an ACL for a group.
357 setacl -u group:$agid:4 tmpfile0
359 func_test_copy tmpfile0 tmpfile3
361 # Set an ACL for other.
362 setacl -u other::4 tmpfile0
364 func_test_copy tmpfile0 tmpfile4
366 # Remove the ACL for the user.
367 setacl -x user:$auid:1 tmpfile0
369 func_test_copy tmpfile0 tmpfile5
371 if false; then # would give an error "can't set ACL: Invalid argument"
372 # Remove the ACL for other.
373 setacl -x other::4 tmpfile0
375 func_test_copy tmpfile0 tmpfile6
378 # Remove the ACL for the group.
379 setacl -x group:$agid:4 tmpfile0
381 func_test_copy tmpfile0 tmpfile7
383 # Delete all optional ACLs.
384 setacl -u user:$auid:1 tmpfile0
387 func_test_copy tmpfile0 tmpfile8
389 # Copy ACLs from a file that has no ACLs.
392 getacl tmpfile9 > tmpaclout0
393 setacl -b -U tmpaclout0 tmpfile0
396 func_test_copy tmpfile0 tmpfile9
402 # Set an ACL for a user.
403 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
405 func_test_copy tmpfile0 tmpfile2
407 # Set an ACL for a group.
408 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit r-- g:$agid"; } | aclput tmpfile0
410 func_test_copy tmpfile0 tmpfile3
412 # Set an ACL for other.
415 func_test_copy tmpfile0 tmpfile4
417 # Remove the ACL for the user.
418 aclget tmpfile0 | grep -v ' u:[^ ]*$' | aclput tmpfile0
420 func_test_copy tmpfile0 tmpfile5
422 # Remove the ACL for the group.
423 aclget tmpfile0 | grep -v ' g:[^ ]*$' | aclput tmpfile0
425 func_test_copy tmpfile0 tmpfile7
427 # Delete all optional ACLs.
428 aclget tmpfile0 | sed -e 's/enabled$/disabled/' | sed -e '/disabled$/q' | aclput tmpfile0
430 func_test_copy tmpfile0 tmpfile8
432 # Copy ACLs from a file that has no ACLs.
435 aclget tmpfile9 | aclput tmpfile0
438 func_test_copy tmpfile0 tmpfile9
444 # Set an ACL for a user.
445 /bin/chmod +a "user:daemon allow execute" tmpfile0
447 func_test_copy tmpfile0 tmpfile2
449 # Set an ACL for a group.
450 /bin/chmod +a "group:daemon allow read" tmpfile0
452 func_test_copy tmpfile0 tmpfile3
454 # Set an ACL for other.
457 func_test_copy tmpfile0 tmpfile4
459 # Remove the ACL for the user.
460 /bin/chmod -a "user:daemon allow execute" tmpfile0
462 func_test_copy tmpfile0 tmpfile5
464 # Remove the ACL for the group.
465 /bin/chmod -a "group:daemon allow read" tmpfile0
467 func_test_copy tmpfile0 tmpfile7
469 # Delete all optional ACLs.
470 /bin/chmod -N tmpfile0
472 func_test_copy tmpfile0 tmpfile8
474 # Copy ACLs from a file that has no ACLs.
477 { /bin/ls -le tmpfile9 | sed -n -e 's/^ [0-9][0-9]*: //p'; echo; } | /bin/chmod -E tmpfile0
480 func_test_copy tmpfile0 tmpfile9
486 # Set an ACL for a user.
487 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0
489 func_test_copy tmpfile0 tmpfile2
491 # Set an ACL for a group.
492 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x,group:$agid:r-- tmpfile0
494 func_test_copy tmpfile0 tmpfile3
496 # Set an ACL for other.
497 /sbin/chacl user::rw-,group::---,user:$auid:--x,group:$agid:r--,other::r-- tmpfile0
499 func_test_copy tmpfile0 tmpfile4
501 # Remove the ACL for the user.
502 /sbin/chacl user::rw-,group::---,group:$agid:r--,other::r-- tmpfile0
504 func_test_copy tmpfile0 tmpfile5
506 # Remove the ACL for the group.
507 /sbin/chacl user::rw-,group::---,other::r-- tmpfile0
509 func_test_copy tmpfile0 tmpfile7
516 rm -f tmpfile[0-9] tmpaclout[0-2]