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
38 # builddir may already be set by the script that invokes this one.
42 *) builddir
=`pwd`/$builddir ;;
46 echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
49 # Switch to a temporary directory, to increase the likelihood that ACLs are
50 # supported on the current file system. (/tmp is usually locally mounted,
51 # whereas the build dir is sometimes NFS-mounted.)
55 rm -f tmpfile
[0-9] tmpaclout
[0-2]
56 echo "Simple contents" > tmpfile0
59 # Classification of the platform according to the programs available for
61 # Possible values are:
62 # linux, cygwin, freebsd, solaris, hpux, hpuxjfs, osf1, aix, macosx, irix, none.
63 # TODO: Support also native Windows platforms (mingw).
65 if (getfacl tmpfile0
>/dev
/null
) 2>/dev
/null
; then
66 # Platforms with the getfacl and setfacl programs.
67 # Linux, FreeBSD, Solaris, Cygwin.
68 if (setfacl
--help >/dev
/null
) 2>/dev
/null
; then
70 if (LC_ALL
=C setfacl
--help |
grep ' --set-file' >/dev
/null
) 2>/dev
/null
; then
78 if (LC_ALL
=C setfacl
2>&1 |
grep '\-x entries' >/dev
/null
) 2>/dev
/null
; then
87 if (lsacl
/ >/dev
/null
) 2>/dev
/null
; then
88 # Platforms with the lsacl and chacl programs.
89 # HP-UX, sometimes also IRIX.
90 if (getacl tmpfile0
>/dev
/null
) 2>/dev
/null
; then
91 # HP-UX 11.11 or newer.
98 if (getacl tmpfile0
>/dev
/null
) 2>/dev
/null
; then
99 # Tru64, NonStop Kernel.
100 if (getacl
-m tmpfile0
>/dev
/null
) 2>/dev
/null
; then
108 if (aclget tmpfile0
>/dev
/null
) 2>/dev
/null
; then
112 if (fsaclctl
-v >/dev
/null
) 2>/dev
/null
; then
116 if test -f /sbin
/chacl
; then
126 # Define a function to test for the same ACLs, from the point of view of
128 # func_test_same_acls file1 file2
130 linux | cygwin | freebsd | solaris
)
131 func_test_same_acls
()
133 getfacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
134 getfacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
135 cmp tmpaclout1 tmpaclout2
> /dev
/null
139 func_test_same_acls
()
141 lsacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
142 lsacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
143 cmp tmpaclout1 tmpaclout2
> /dev
/null
147 func_test_same_acls
()
149 { lsacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
150 lsacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
151 cmp tmpaclout1 tmpaclout2
> /dev
/null
153 { getacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
154 getacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
155 cmp tmpaclout1 tmpaclout2
> /dev
/null
160 func_test_same_acls
()
162 getacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
163 getacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
164 cmp tmpaclout1 tmpaclout2
> /dev
/null
168 func_test_same_acls
()
170 aclget
"$1" > tmpaclout1
171 aclget
"$2" > tmpaclout2
172 cmp tmpaclout1 tmpaclout2
> /dev
/null
176 func_test_same_acls
()
178 /bin
/ls -le "$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
179 /bin
/ls -le "$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
180 cmp tmpaclout1 tmpaclout2
> /dev
/null
184 func_test_same_acls
()
186 /bin
/ls -lD "$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
187 /bin
/ls -lD "$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
188 cmp tmpaclout1 tmpaclout2
> /dev
/null
192 func_test_same_acls
()
199 # func_test_copy file1 file2
200 # copies file1 to file2 and verifies the permissions and ACLs are the same
204 ${CHECKER} "$builddir"/test-copy-file
${EXEEXT} "$1" "$2" ||
exit 1
205 if test "$USE_ACL" != 0; then
206 ${CHECKER} "$builddir"/test-sameacls
${EXEEXT} "$1" "$2" ||
exit 1
207 func_test_same_acls
"$1" "$2" ||
exit 1
211 func_test_copy tmpfile0 tmpfile1
213 if test "$USE_ACL" != 0 && test $acl_flavor != none
; then
214 # A POSIX compliant 'id' program.
215 if test -f /usr
/xpg
4/bin
/id
; then
220 # Use a user and group id different from the current one, to avoid
221 # redundant/ambiguous ACLs.
225 if test "$auid" = "$myuid"; then auid
=2; fi
227 if test "$agid" = "$mygid"; then agid
=2; fi
230 linux | freebsd | solaris
)
232 # Set an ACL for a user.
233 setfacl
-m user
:$auid:1 tmpfile0
235 func_test_copy tmpfile0 tmpfile2
237 # Set an ACL for a group.
238 setfacl
-m group
:$agid:4 tmpfile0
240 func_test_copy tmpfile0 tmpfile3
242 # Set an ACL for other.
244 freebsd
) setfacl
-m other
::4 tmpfile0
;;
245 solaris
) chmod o
+r tmpfile0
;;
246 *) setfacl
-m other
:4 tmpfile0
;;
249 func_test_copy tmpfile0 tmpfile4
251 # Remove the ACL for the user.
253 linux
) setfacl
-x user
:$auid tmpfile0
;;
254 freebsd
) setfacl
-x user
:$auid:1 tmpfile0
;;
255 *) setfacl
-d user
:$auid:1 tmpfile0
;;
258 func_test_copy tmpfile0 tmpfile5
260 # Remove the ACL for other.
262 linux | solaris
) ;; # impossible
263 freebsd
) setfacl
-x other
::4 tmpfile0
;;
264 *) setfacl
-d other
:4 tmpfile0
;;
267 func_test_copy tmpfile0 tmpfile6
269 # Remove the ACL for the group.
271 linux
) setfacl
-x group
:$agid tmpfile0
;;
272 freebsd
) setfacl
-x group
:$agid:4 tmpfile0
;;
273 *) setfacl
-d group
:$agid:4 tmpfile0
;;
276 func_test_copy tmpfile0 tmpfile7
278 # Delete all optional ACLs.
281 setfacl
-m user
:$auid:1 tmpfile0
285 setfacl
-s user
::6,group
::0,other
:0 tmpfile0
;;
288 func_test_copy tmpfile0 tmpfile8
290 # Copy ACLs from a file that has no ACLs.
294 linux
) getfacl tmpfile9 | setfacl
--set-file=- tmpfile0
;;
296 *) getfacl tmpfile9 | setfacl
-f - tmpfile0
;;
300 func_test_copy tmpfile0 tmpfile9
306 # Set an ACL for a group.
307 setfacl
-m group
:0:1 tmpfile0
309 func_test_copy tmpfile0 tmpfile2
311 # Set an ACL for other.
312 setfacl
-m other
:4 tmpfile0
314 func_test_copy tmpfile0 tmpfile4
316 # Remove the ACL for the group.
317 setfacl
-d group
:0 tmpfile0
319 func_test_copy tmpfile0 tmpfile5
321 # Remove the ACL for other.
322 setfacl
-d other
:4 tmpfile0
324 func_test_copy tmpfile0 tmpfile6
326 # Delete all optional ACLs.
327 setfacl
-s user
::6,group
::0,other
:0 tmpfile0
329 func_test_copy tmpfile0 tmpfile8
331 # Copy ACLs from a file that has no ACLs.
334 getfacl tmpfile9 | setfacl
-f - tmpfile0
337 func_test_copy tmpfile0 tmpfile9
343 # Set an ACL for a user.
344 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
345 chacl
-r "${orig}($auid.%,--x)" tmpfile0
347 func_test_copy tmpfile0 tmpfile2
349 # Set an ACL for a group.
350 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
351 chacl
-r "${orig}(%.$agid,r--)" tmpfile0
353 func_test_copy tmpfile0 tmpfile3
355 # Set an ACL for other.
356 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
357 chacl
-r "${orig}(%.%,r--)" tmpfile0
359 func_test_copy tmpfile0 tmpfile4
361 # Remove the ACL for the user.
362 chacl
-d "($auid.%,--x)" tmpfile0
364 func_test_copy tmpfile0 tmpfile5
366 # Remove the ACL for the group.
367 chacl
-d "(%.$agid,r--)" tmpfile0
369 func_test_copy tmpfile0 tmpfile6
371 # Delete all optional ACLs.
374 func_test_copy tmpfile0 tmpfile8
376 # Copy ACLs from a file that has no ACLs.
379 orig
=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
381 chacl
-r "${orig}" tmpfile0
383 func_test_copy tmpfile0 tmpfile9
389 # Set an ACL for a user.
390 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
391 chacl
-r "${orig}($auid.%,--x)" tmpfile0 \
392 || setacl
-m user
:$auid:1 tmpfile0
394 func_test_copy tmpfile0 tmpfile2
396 # Set an ACL for a group.
397 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
398 chacl
-r "${orig}(%.$agid,r--)" tmpfile0 \
399 || setacl
-m group
:$agid:4 tmpfile0
401 func_test_copy tmpfile0 tmpfile3
403 # Set an ACL for other.
404 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
405 chacl
-r "${orig}(%.%,r--)" tmpfile0 \
406 || setacl
-m other
:4 tmpfile0
408 func_test_copy tmpfile0 tmpfile4
410 # Remove the ACL for the user.
411 chacl
-d "($auid.%,--x)" tmpfile0 \
412 || setacl
-d user
:$auid tmpfile0
414 func_test_copy tmpfile0 tmpfile5
416 # Remove the ACL for the group.
417 chacl
-d "(%.$agid,r--)" tmpfile0 \
418 || setacl
-d group
:$agid tmpfile0
420 func_test_copy tmpfile0 tmpfile6
422 # Delete all optional ACLs.
424 ||
{ setacl
-m user
:$auid:1 tmpfile0
425 setacl
-s user
::6,group
::0,class
:7,other
:0 tmpfile0
428 func_test_copy tmpfile0 tmpfile8
430 # Copy ACLs from a file that has no ACLs.
433 orig
=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
434 getacl tmpfile9
> tmpaclout0
436 chacl
-r "${orig}" tmpfile0 \
437 || setacl
-f tmpaclout0 tmpfile0
439 func_test_copy tmpfile0 tmpfile9
445 # Set an ACL for a user.
446 setacl
-u user
:$auid:1 tmpfile0
448 func_test_copy tmpfile0 tmpfile2
450 # Set an ACL for a group.
451 setacl
-u group
:$agid:4 tmpfile0
453 func_test_copy tmpfile0 tmpfile3
455 # Set an ACL for other.
456 setacl
-u other
::4 tmpfile0
458 func_test_copy tmpfile0 tmpfile4
460 # Remove the ACL for the user.
461 setacl
-x user
:$auid:1 tmpfile0
463 func_test_copy tmpfile0 tmpfile5
465 if false
; then # would give an error "can't set ACL: Invalid argument"
466 # Remove the ACL for other.
467 setacl
-x other
::4 tmpfile0
469 func_test_copy tmpfile0 tmpfile6
472 # Remove the ACL for the group.
473 setacl
-x group
:$agid:4 tmpfile0
475 func_test_copy tmpfile0 tmpfile7
477 # Delete all optional ACLs.
478 setacl
-u user
:$auid:1 tmpfile0
481 func_test_copy tmpfile0 tmpfile8
483 # Copy ACLs from a file that has no ACLs.
486 getacl tmpfile9
> tmpaclout0
487 setacl
-b -U tmpaclout0 tmpfile0
490 func_test_copy tmpfile0 tmpfile9
496 # Set an ACL for a user.
497 setacl
-m user
:$auid:1 tmpfile0
499 func_test_copy tmpfile0 tmpfile2
501 # Set an ACL for a group.
502 setacl
-m group
:$agid:4 tmpfile0
504 func_test_copy tmpfile0 tmpfile3
506 # Set an ACL for other.
507 setacl
-m other
:4 tmpfile0
509 func_test_copy tmpfile0 tmpfile4
511 # Remove the ACL for the user.
512 setacl
-d user
:$auid tmpfile0
514 func_test_copy tmpfile0 tmpfile5
516 # Remove the ACL for the group.
517 setacl
-d group
:$agid tmpfile0
519 func_test_copy tmpfile0 tmpfile6
521 # Delete all optional ACLs.
522 setacl
-m user
:$auid:1 tmpfile0
523 setacl
-s user
::6,group
::0,class
:7,other
:0 tmpfile0
525 func_test_copy tmpfile0 tmpfile8
527 # Copy ACLs from a file that has no ACLs.
530 getacl tmpfile9
> tmpaclout0
531 setacl
-f tmpaclout0 tmpfile0
534 func_test_copy tmpfile0 tmpfile9
540 # Set an ACL for a user.
541 { aclget tmpfile0 |
sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
543 func_test_copy tmpfile0 tmpfile2
545 # Set an ACL for a group.
546 { aclget tmpfile0 |
sed -e 's/disabled$/enabled/'; echo " permit r-- g:$agid"; } | aclput tmpfile0
548 func_test_copy tmpfile0 tmpfile3
550 # Set an ACL for other.
553 func_test_copy tmpfile0 tmpfile4
555 # Remove the ACL for the user.
556 aclget tmpfile0 |
grep -v ' u:[^ ]*$' | aclput tmpfile0
558 func_test_copy tmpfile0 tmpfile5
560 # Remove the ACL for the group.
561 aclget tmpfile0 |
grep -v ' g:[^ ]*$' | aclput tmpfile0
563 func_test_copy tmpfile0 tmpfile7
565 # Delete all optional ACLs.
566 aclget tmpfile0 |
sed -e 's/enabled$/disabled/' |
sed -e '/disabled$/q' | aclput tmpfile0
568 func_test_copy tmpfile0 tmpfile8
570 # Copy ACLs from a file that has no ACLs.
573 aclget tmpfile9 | aclput tmpfile0
576 func_test_copy tmpfile0 tmpfile9
582 # Set an ACL for a user.
583 /bin
/chmod +a
"user:daemon allow execute" tmpfile0
585 func_test_copy tmpfile0 tmpfile2
587 # Set an ACL for a group.
588 /bin
/chmod +a
"group:daemon allow read" tmpfile0
590 func_test_copy tmpfile0 tmpfile3
592 # Set an ACL for other.
595 func_test_copy tmpfile0 tmpfile4
597 # Remove the ACL for the user.
598 /bin
/chmod -a "user:daemon allow execute" tmpfile0
600 func_test_copy tmpfile0 tmpfile5
602 # Remove the ACL for the group.
603 /bin
/chmod -a "group:daemon allow read" tmpfile0
605 func_test_copy tmpfile0 tmpfile7
607 # Delete all optional ACLs.
608 /bin
/chmod -N tmpfile0
610 func_test_copy tmpfile0 tmpfile8
612 # Copy ACLs from a file that has no ACLs.
615 { /bin
/ls -le tmpfile9 |
sed -n -e 's/^ [0-9][0-9]*: //p'; echo; } |
/bin
/chmod -E tmpfile0
618 func_test_copy tmpfile0 tmpfile9
624 # Set an ACL for a user.
625 /sbin
/chacl user
::rw-
,group
::---,other
::---,user
:$auid:--x tmpfile0
627 func_test_copy tmpfile0 tmpfile2
629 # Set an ACL for a group.
630 /sbin
/chacl user
::rw-
,group
::---,other
::---,user
:$auid:--x,group
:$agid:r-- tmpfile0
632 func_test_copy tmpfile0 tmpfile3
634 # Set an ACL for other.
635 /sbin
/chacl user
::rw-
,group
::---,user
:$auid:--x,group
:$agid:r--
,other
::r-- tmpfile0
637 func_test_copy tmpfile0 tmpfile4
639 # Remove the ACL for the user.
640 /sbin
/chacl user
::rw-
,group
::---,group
:$agid:r--
,other
::r-- tmpfile0
642 func_test_copy tmpfile0 tmpfile5
644 # Remove the ACL for the group.
645 /sbin
/chacl user
::rw-
,group
::---,other
::r-- tmpfile0
647 func_test_copy tmpfile0 tmpfile7
654 rm -f tmpfile
[0-9] tmpaclout
[0-2]