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, hpuxjfs, osf1, aix, macosx, irix, none.
58 # TODO: Support also native Windows 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.
85 if (getacl tmpfile0
>/dev
/null
) 2>/dev
/null
; then
86 # HP-UX 11.11 or newer.
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 { lsacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
145 lsacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
146 cmp tmpaclout1 tmpaclout2
> /dev
/null
148 { getacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
149 getacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
150 cmp tmpaclout1 tmpaclout2
> /dev
/null
155 func_test_same_acls
()
157 getacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
158 getacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
159 cmp tmpaclout1 tmpaclout2
> /dev
/null
163 func_test_same_acls
()
165 aclget
"$1" > tmpaclout1
166 aclget
"$2" > tmpaclout2
167 cmp tmpaclout1 tmpaclout2
> /dev
/null
171 func_test_same_acls
()
173 /bin
/ls -le "$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
174 /bin
/ls -le "$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
175 cmp tmpaclout1 tmpaclout2
> /dev
/null
179 func_test_same_acls
()
181 /bin
/ls -lD "$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
182 /bin
/ls -lD "$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
183 cmp tmpaclout1 tmpaclout2
> /dev
/null
187 func_test_same_acls
()
194 # func_test_copy file1 file2
195 # copies file1 to file2 and verifies the permissions and ACLs are the same
199 "$builddir"/test-copy-file
${EXEEXT} "$1" "$2" ||
exit 1
200 if test "$USE_ACL" != 0; then
201 "$builddir"/test-sameacls
${EXEEXT} "$1" "$2" ||
exit 1
202 func_test_same_acls
"$1" "$2" ||
exit 1
206 func_test_copy tmpfile0 tmpfile1
208 if test "$USE_ACL" != 0 && test $acl_flavor != none
; then
209 # A POSIX compliant 'id' program.
210 if test -f /usr
/xpg
4/bin
/id
; then
215 # Use a user and group id different from the current one, to avoid
216 # redundant/ambiguous ACLs.
220 if test "$auid" = "$myuid"; then auid
=2; fi
222 if test "$agid" = "$mygid"; then agid
=2; fi
225 linux | freebsd | solaris
)
227 # Set an ACL for a user.
228 setfacl
-m user
:$auid:1 tmpfile0
230 func_test_copy tmpfile0 tmpfile2
232 # Set an ACL for a group.
233 setfacl
-m group
:$agid:4 tmpfile0
235 func_test_copy tmpfile0 tmpfile3
237 # Set an ACL for other.
239 freebsd
) setfacl
-m other
::4 tmpfile0
;;
240 solaris
) chmod o
+r tmpfile0
;;
241 *) setfacl
-m other
:4 tmpfile0
;;
244 func_test_copy tmpfile0 tmpfile4
246 # Remove the ACL for the user.
248 linux
) setfacl
-x user
:$auid tmpfile0
;;
249 freebsd
) setfacl
-x user
:$auid:1 tmpfile0
;;
250 *) setfacl
-d user
:$auid:1 tmpfile0
;;
253 func_test_copy tmpfile0 tmpfile5
255 # Remove the ACL for other.
257 linux | solaris
) ;; # impossible
258 freebsd
) setfacl
-x other
::4 tmpfile0
;;
259 *) setfacl
-d other
:4 tmpfile0
;;
262 func_test_copy tmpfile0 tmpfile6
264 # Remove the ACL for the group.
266 linux
) setfacl
-x group
:$agid tmpfile0
;;
267 freebsd
) setfacl
-x group
:$agid:4 tmpfile0
;;
268 *) setfacl
-d group
:$agid:4 tmpfile0
;;
271 func_test_copy tmpfile0 tmpfile7
273 # Delete all optional ACLs.
276 setfacl
-m user
:$auid:1 tmpfile0
280 setfacl
-s user
::6,group
::0,other
:0 tmpfile0
;;
283 func_test_copy tmpfile0 tmpfile8
285 # Copy ACLs from a file that has no ACLs.
289 linux
) getfacl tmpfile9 | setfacl
--set-file=- tmpfile0
;;
291 *) getfacl tmpfile9 | setfacl
-f - tmpfile0
;;
295 func_test_copy tmpfile0 tmpfile9
301 # Set an ACL for a group.
302 setfacl
-m group
:0:1 tmpfile0
304 func_test_copy tmpfile0 tmpfile2
306 # Set an ACL for other.
307 setfacl
-m other
:4 tmpfile0
309 func_test_copy tmpfile0 tmpfile4
311 # Remove the ACL for the group.
312 setfacl
-d group
:0 tmpfile0
314 func_test_copy tmpfile0 tmpfile5
316 # Remove the ACL for other.
317 setfacl
-d other
:4 tmpfile0
319 func_test_copy tmpfile0 tmpfile6
321 # Delete all optional ACLs.
322 setfacl
-s user
::6,group
::0,other
:0 tmpfile0
324 func_test_copy tmpfile0 tmpfile8
326 # Copy ACLs from a file that has no ACLs.
329 getfacl tmpfile9 | setfacl
-f - tmpfile0
332 func_test_copy tmpfile0 tmpfile9
338 # Set an ACL for a user.
339 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
340 chacl
-r "${orig}($auid.%,--x)" tmpfile0
342 func_test_copy tmpfile0 tmpfile2
344 # Set an ACL for a group.
345 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
346 chacl
-r "${orig}(%.$agid,r--)" tmpfile0
348 func_test_copy tmpfile0 tmpfile3
350 # Set an ACL for other.
351 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
352 chacl
-r "${orig}(%.%,r--)" tmpfile0
354 func_test_copy tmpfile0 tmpfile4
356 # Remove the ACL for the user.
357 chacl
-d "($auid.%,--x)" tmpfile0
359 func_test_copy tmpfile0 tmpfile5
361 # Remove the ACL for the group.
362 chacl
-d "(%.$agid,r--)" tmpfile0
364 func_test_copy tmpfile0 tmpfile6
366 # Delete all optional ACLs.
369 func_test_copy tmpfile0 tmpfile8
371 # Copy ACLs from a file that has no ACLs.
374 orig
=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
376 chacl
-r "${orig}" tmpfile0
378 func_test_copy tmpfile0 tmpfile9
384 # Set an ACL for a user.
385 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
386 chacl
-r "${orig}($auid.%,--x)" tmpfile0 \
387 || setacl
-m user
:$auid:1 tmpfile0
389 func_test_copy tmpfile0 tmpfile2
391 # Set an ACL for a group.
392 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
393 chacl
-r "${orig}(%.$agid,r--)" tmpfile0 \
394 || setacl
-m group
:$agid:4 tmpfile0
396 func_test_copy tmpfile0 tmpfile3
398 # Set an ACL for other.
399 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
400 chacl
-r "${orig}(%.%,r--)" tmpfile0 \
401 || setacl
-m other
:4 tmpfile0
403 func_test_copy tmpfile0 tmpfile4
405 # Remove the ACL for the user.
406 chacl
-d "($auid.%,--x)" tmpfile0 \
407 || setacl
-d user
:$auid tmpfile0
409 func_test_copy tmpfile0 tmpfile5
411 # Remove the ACL for the group.
412 chacl
-d "(%.$agid,r--)" tmpfile0 \
413 || setacl
-d group
:$agid tmpfile0
415 func_test_copy tmpfile0 tmpfile6
417 # Delete all optional ACLs.
419 ||
{ setacl
-m user
:$auid:1 tmpfile0
420 setacl
-s user
::6,group
::0,class
:7,other
:0 tmpfile0
423 func_test_copy tmpfile0 tmpfile8
425 # Copy ACLs from a file that has no ACLs.
428 orig
=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
429 getacl tmpfile9
> tmpaclout0
431 chacl
-r "${orig}" tmpfile0 \
432 || setacl
-f tmpaclout0 tmpfile0
434 func_test_copy tmpfile0 tmpfile9
440 # Set an ACL for a user.
441 setacl
-u user
:$auid:1 tmpfile0
443 func_test_copy tmpfile0 tmpfile2
445 # Set an ACL for a group.
446 setacl
-u group
:$agid:4 tmpfile0
448 func_test_copy tmpfile0 tmpfile3
450 # Set an ACL for other.
451 setacl
-u other
::4 tmpfile0
453 func_test_copy tmpfile0 tmpfile4
455 # Remove the ACL for the user.
456 setacl
-x user
:$auid:1 tmpfile0
458 func_test_copy tmpfile0 tmpfile5
460 if false
; then # would give an error "can't set ACL: Invalid argument"
461 # Remove the ACL for other.
462 setacl
-x other
::4 tmpfile0
464 func_test_copy tmpfile0 tmpfile6
467 # Remove the ACL for the group.
468 setacl
-x group
:$agid:4 tmpfile0
470 func_test_copy tmpfile0 tmpfile7
472 # Delete all optional ACLs.
473 setacl
-u user
:$auid:1 tmpfile0
476 func_test_copy tmpfile0 tmpfile8
478 # Copy ACLs from a file that has no ACLs.
481 getacl tmpfile9
> tmpaclout0
482 setacl
-b -U tmpaclout0 tmpfile0
485 func_test_copy tmpfile0 tmpfile9
491 # Set an ACL for a user.
492 setacl
-m user
:$auid:1 tmpfile0
494 func_test_copy tmpfile0 tmpfile2
496 # Set an ACL for a group.
497 setacl
-m group
:$agid:4 tmpfile0
499 func_test_copy tmpfile0 tmpfile3
501 # Set an ACL for other.
502 setacl
-m other
:4 tmpfile0
504 func_test_copy tmpfile0 tmpfile4
506 # Remove the ACL for the user.
507 setacl
-d user
:$auid tmpfile0
509 func_test_copy tmpfile0 tmpfile5
511 # Remove the ACL for the group.
512 setacl
-d group
:$agid tmpfile0
514 func_test_copy tmpfile0 tmpfile6
516 # Delete all optional ACLs.
517 setacl
-m user
:$auid:1 tmpfile0
518 setacl
-s user
::6,group
::0,class
:7,other
:0 tmpfile0
520 func_test_copy tmpfile0 tmpfile8
522 # Copy ACLs from a file that has no ACLs.
525 getacl tmpfile9
> tmpaclout0
526 setacl
-f tmpaclout0 tmpfile0
529 func_test_copy tmpfile0 tmpfile9
535 # Set an ACL for a user.
536 { aclget tmpfile0 |
sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
538 func_test_copy tmpfile0 tmpfile2
540 # Set an ACL for a group.
541 { aclget tmpfile0 |
sed -e 's/disabled$/enabled/'; echo " permit r-- g:$agid"; } | aclput tmpfile0
543 func_test_copy tmpfile0 tmpfile3
545 # Set an ACL for other.
548 func_test_copy tmpfile0 tmpfile4
550 # Remove the ACL for the user.
551 aclget tmpfile0 |
grep -v ' u:[^ ]*$' | aclput tmpfile0
553 func_test_copy tmpfile0 tmpfile5
555 # Remove the ACL for the group.
556 aclget tmpfile0 |
grep -v ' g:[^ ]*$' | aclput tmpfile0
558 func_test_copy tmpfile0 tmpfile7
560 # Delete all optional ACLs.
561 aclget tmpfile0 |
sed -e 's/enabled$/disabled/' |
sed -e '/disabled$/q' | aclput tmpfile0
563 func_test_copy tmpfile0 tmpfile8
565 # Copy ACLs from a file that has no ACLs.
568 aclget tmpfile9 | aclput tmpfile0
571 func_test_copy tmpfile0 tmpfile9
577 # Set an ACL for a user.
578 /bin
/chmod +a
"user:daemon allow execute" tmpfile0
580 func_test_copy tmpfile0 tmpfile2
582 # Set an ACL for a group.
583 /bin
/chmod +a
"group:daemon allow read" tmpfile0
585 func_test_copy tmpfile0 tmpfile3
587 # Set an ACL for other.
590 func_test_copy tmpfile0 tmpfile4
592 # Remove the ACL for the user.
593 /bin
/chmod -a "user:daemon allow execute" tmpfile0
595 func_test_copy tmpfile0 tmpfile5
597 # Remove the ACL for the group.
598 /bin
/chmod -a "group:daemon allow read" tmpfile0
600 func_test_copy tmpfile0 tmpfile7
602 # Delete all optional ACLs.
603 /bin
/chmod -N tmpfile0
605 func_test_copy tmpfile0 tmpfile8
607 # Copy ACLs from a file that has no ACLs.
610 { /bin
/ls -le tmpfile9 |
sed -n -e 's/^ [0-9][0-9]*: //p'; echo; } |
/bin
/chmod -E tmpfile0
613 func_test_copy tmpfile0 tmpfile9
619 # Set an ACL for a user.
620 /sbin
/chacl user
::rw-
,group
::---,other
::---,user
:$auid:--x tmpfile0
622 func_test_copy tmpfile0 tmpfile2
624 # Set an ACL for a group.
625 /sbin
/chacl user
::rw-
,group
::---,other
::---,user
:$auid:--x,group
:$agid:r-- tmpfile0
627 func_test_copy tmpfile0 tmpfile3
629 # Set an ACL for other.
630 /sbin
/chacl user
::rw-
,group
::---,user
:$auid:--x,group
:$agid:r--
,other
::r-- tmpfile0
632 func_test_copy tmpfile0 tmpfile4
634 # Remove the ACL for the user.
635 /sbin
/chacl user
::rw-
,group
::---,group
:$agid:r--
,other
::r-- tmpfile0
637 func_test_copy tmpfile0 tmpfile5
639 # Remove the ACL for the group.
640 /sbin
/chacl user
::rw-
,group
::---,other
::r-- tmpfile0
642 func_test_copy tmpfile0 tmpfile7
649 rm -f tmpfile
[0-9] tmpaclout
[0-2]