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
44 # builddir may already be set by the script that invokes this one.
48 *) builddir
=`pwd`/$builddir ;;
52 echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
55 # Switch to a temporary directory, to increase the likelihood that ACLs are
56 # supported on the current file system. (/tmp is usually locally mounted,
57 # whereas the build dir is sometimes NFS-mounted.)
61 rm -f tmpfile
[0-9] tmpaclout
[0-2]
62 echo "Simple contents" > tmpfile0
65 # Classification of the platform according to the programs available for
67 # Possible values are:
68 # linux, cygwin, freebsd, solaris, hpux, hpuxjfs, osf1, aix, macosx, irix, none.
69 # TODO: Support also native Windows platforms (mingw).
71 if (getfacl tmpfile0
>/dev
/null
) 2>/dev
/null
; then
72 # Platforms with the getfacl and setfacl programs.
73 # Linux, FreeBSD, Solaris, Cygwin.
74 if (setfacl
--help >/dev
/null
) 2>/dev
/null
; then
76 if (LC_ALL
=C setfacl
--help |
grep ' --set-file' >/dev
/null
) 2>/dev
/null
; then
84 if (LC_ALL
=C setfacl
2>&1 |
grep '\-x entries' >/dev
/null
) 2>/dev
/null
; then
93 if (lsacl
/ >/dev
/null
) 2>/dev
/null
; then
94 # Platforms with the lsacl and chacl programs.
95 # HP-UX, sometimes also IRIX.
96 if (getacl tmpfile0
>/dev
/null
) 2>/dev
/null
; then
97 # HP-UX 11.11 or newer.
104 if (getacl tmpfile0
>/dev
/null
) 2>/dev
/null
; then
105 # Tru64, NonStop Kernel.
106 if (getacl
-m tmpfile0
>/dev
/null
) 2>/dev
/null
; then
114 if (aclget tmpfile0
>/dev
/null
) 2>/dev
/null
; then
118 if (fsaclctl
-v >/dev
/null
) 2>/dev
/null
; then
122 if test -f /sbin
/chacl
; then
132 # Define a function to test for the same ACLs, from the point of view of
134 # func_test_same_acls file1 file2
136 linux | cygwin | freebsd | solaris
)
137 func_test_same_acls
()
139 getfacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
140 getfacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
141 cmp tmpaclout1 tmpaclout2
> /dev
/null
145 func_test_same_acls
()
147 lsacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
148 lsacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
149 cmp tmpaclout1 tmpaclout2
> /dev
/null
153 func_test_same_acls
()
155 { lsacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
156 lsacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
157 cmp tmpaclout1 tmpaclout2
> /dev
/null
159 { getacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
160 getacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
161 cmp tmpaclout1 tmpaclout2
> /dev
/null
166 func_test_same_acls
()
168 getacl
"$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
169 getacl
"$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
170 cmp tmpaclout1 tmpaclout2
> /dev
/null
174 func_test_same_acls
()
176 aclget
"$1" > tmpaclout1
177 aclget
"$2" > tmpaclout2
178 cmp tmpaclout1 tmpaclout2
> /dev
/null
182 func_test_same_acls
()
184 /bin
/ls -le "$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
185 /bin
/ls -le "$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
186 cmp tmpaclout1 tmpaclout2
> /dev
/null
190 func_test_same_acls
()
192 /bin
/ls -lD "$1" |
sed -e "s/$1/FILENAME/g" > tmpaclout1
193 /bin
/ls -lD "$2" |
sed -e "s/$2/FILENAME/g" > tmpaclout2
194 cmp tmpaclout1 tmpaclout2
> /dev
/null
198 func_test_same_acls
()
205 # func_test_copy file1 file2
206 # copies file1 to file2 and verifies the permissions and ACLs are the same
210 echo "Simple contents" > "$2"
212 ${CHECKER} "$builddir"/test-copy-acl
${EXEEXT} "$1" "$2" ||
exit 1
213 ${CHECKER} "$builddir"/test-sameacls
${EXEEXT} "$1" "$2" ||
exit 1
214 func_test_same_acls
"$1" "$2" ||
exit 1
217 func_test_copy tmpfile0 tmpfile1
219 if test $acl_flavor != none
; then
220 # A POSIX compliant 'id' program.
221 if test -f /usr
/xpg
4/bin
/id
; then
226 # Use a user and group id different from the current one, to avoid
227 # redundant/ambiguous ACLs.
231 if test "$auid" = "$myuid"; then auid
=2; fi
233 if test "$agid" = "$mygid"; then agid
=2; fi
236 linux | freebsd | solaris
)
238 # Set an ACL for a user.
239 setfacl
-m user
:$auid:1 tmpfile0
241 func_test_copy tmpfile0 tmpfile2
243 # Set an ACL for a group.
244 setfacl
-m group
:$agid:4 tmpfile0
246 func_test_copy tmpfile0 tmpfile3
248 # Set an ACL for other.
250 freebsd
) setfacl
-m other
::4 tmpfile0
;;
251 solaris
) chmod o
+r tmpfile0
;;
252 *) setfacl
-m other
:4 tmpfile0
;;
255 func_test_copy tmpfile0 tmpfile4
257 # Remove the ACL for the user.
259 linux
) setfacl
-x user
:$auid tmpfile0
;;
260 freebsd
) setfacl
-x user
:$auid:1 tmpfile0
;;
261 *) setfacl
-d user
:$auid:1 tmpfile0
;;
264 func_test_copy tmpfile0 tmpfile5
266 # Remove the ACL for other.
268 linux | solaris
) ;; # impossible
269 freebsd
) setfacl
-x other
::4 tmpfile0
;;
270 *) setfacl
-d other
:4 tmpfile0
;;
273 func_test_copy tmpfile0 tmpfile6
275 # Remove the ACL for the group.
277 linux
) setfacl
-x group
:$agid tmpfile0
;;
278 freebsd
) setfacl
-x group
:$agid:4 tmpfile0
;;
279 *) setfacl
-d group
:$agid:4 tmpfile0
;;
282 func_test_copy tmpfile0 tmpfile7
284 # Delete all optional ACLs.
287 setfacl
-m user
:$auid:1 tmpfile0
291 setfacl
-s user
::6,group
::0,other
:0 tmpfile0
;;
294 func_test_copy tmpfile0 tmpfile8
296 # Copy ACLs from a file that has no ACLs.
300 linux
) getfacl tmpfile9 | setfacl
--set-file=- tmpfile0
;;
302 *) getfacl tmpfile9 | setfacl
-f - tmpfile0
;;
306 func_test_copy tmpfile0 tmpfile9
312 # Set an ACL for a group.
313 setfacl
-m group
:0:1 tmpfile0
315 func_test_copy tmpfile0 tmpfile2
317 # Set an ACL for other.
318 setfacl
-m other
:4 tmpfile0
320 func_test_copy tmpfile0 tmpfile4
322 # Remove the ACL for the group.
323 setfacl
-d group
:0 tmpfile0
325 func_test_copy tmpfile0 tmpfile5
327 # Remove the ACL for other.
328 setfacl
-d other
:4 tmpfile0
330 func_test_copy tmpfile0 tmpfile6
332 # Delete all optional ACLs.
333 setfacl
-s user
::6,group
::0,other
:0 tmpfile0
335 func_test_copy tmpfile0 tmpfile8
337 # Copy ACLs from a file that has no ACLs.
340 getfacl tmpfile9 | setfacl
-f - tmpfile0
343 func_test_copy tmpfile0 tmpfile9
349 # Set an ACL for a user.
350 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
351 chacl
-r "${orig}($auid.%,--x)" tmpfile0
353 func_test_copy tmpfile0 tmpfile2
355 # Set an ACL for a group.
356 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
357 chacl
-r "${orig}(%.$agid,r--)" tmpfile0
359 func_test_copy tmpfile0 tmpfile3
361 # Set an ACL for other.
362 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
363 chacl
-r "${orig}(%.%,r--)" tmpfile0
365 func_test_copy tmpfile0 tmpfile4
367 # Remove the ACL for the user.
368 chacl
-d "($auid.%,--x)" tmpfile0
370 func_test_copy tmpfile0 tmpfile5
372 # Remove the ACL for the group.
373 chacl
-d "(%.$agid,r--)" tmpfile0
375 func_test_copy tmpfile0 tmpfile6
377 # Delete all optional ACLs.
380 func_test_copy tmpfile0 tmpfile8
382 # Copy ACLs from a file that has no ACLs.
385 orig
=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
387 chacl
-r "${orig}" tmpfile0
389 func_test_copy tmpfile0 tmpfile9
395 # Set an ACL for a user.
396 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
397 chacl
-r "${orig}($auid.%,--x)" tmpfile0 \
398 || setacl
-m user
:$auid:1 tmpfile0
400 func_test_copy tmpfile0 tmpfile2
402 # Set an ACL for a group.
403 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
404 chacl
-r "${orig}(%.$agid,r--)" tmpfile0 \
405 || setacl
-m group
:$agid:4 tmpfile0
407 func_test_copy tmpfile0 tmpfile3
409 # Set an ACL for other.
410 orig
=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
411 chacl
-r "${orig}(%.%,r--)" tmpfile0 \
412 || setacl
-m other
:4 tmpfile0
414 func_test_copy tmpfile0 tmpfile4
416 # Remove the ACL for the user.
417 chacl
-d "($auid.%,--x)" tmpfile0 \
418 || setacl
-d user
:$auid tmpfile0
420 func_test_copy tmpfile0 tmpfile5
422 # Remove the ACL for the group.
423 chacl
-d "(%.$agid,r--)" tmpfile0 \
424 || setacl
-d group
:$agid tmpfile0
426 func_test_copy tmpfile0 tmpfile6
428 # Delete all optional ACLs.
430 ||
{ setacl
-m user
:$auid:1 tmpfile0
431 setacl
-s user
::6,group
::0,class
:7,other
:0 tmpfile0
434 func_test_copy tmpfile0 tmpfile8
436 # Copy ACLs from a file that has no ACLs.
439 orig
=`lsacl tmpfile9 | sed -e 's/ tmpfile9$//'`
440 getacl tmpfile9
> tmpaclout0
442 chacl
-r "${orig}" tmpfile0 \
443 || setacl
-f tmpaclout0 tmpfile0
445 func_test_copy tmpfile0 tmpfile9
451 # Set an ACL for a user.
452 setacl
-u user
:$auid:1 tmpfile0
454 func_test_copy tmpfile0 tmpfile2
456 # Set an ACL for a group.
457 setacl
-u group
:$agid:4 tmpfile0
459 func_test_copy tmpfile0 tmpfile3
461 # Set an ACL for other.
462 setacl
-u other
::4 tmpfile0
464 func_test_copy tmpfile0 tmpfile4
466 # Remove the ACL for the user.
467 setacl
-x user
:$auid:1 tmpfile0
469 func_test_copy tmpfile0 tmpfile5
471 if false
; then # would give an error "can't set ACL: Invalid argument"
472 # Remove the ACL for other.
473 setacl
-x other
::4 tmpfile0
475 func_test_copy tmpfile0 tmpfile6
478 # Remove the ACL for the group.
479 setacl
-x group
:$agid:4 tmpfile0
481 func_test_copy tmpfile0 tmpfile7
483 # Delete all optional ACLs.
484 setacl
-u user
:$auid:1 tmpfile0
487 func_test_copy tmpfile0 tmpfile8
489 # Copy ACLs from a file that has no ACLs.
492 getacl tmpfile9
> tmpaclout0
493 setacl
-b -U tmpaclout0 tmpfile0
496 func_test_copy tmpfile0 tmpfile9
502 # Set an ACL for a user.
503 setacl
-m user
:$auid:1 tmpfile0
505 func_test_copy tmpfile0 tmpfile2
507 # Set an ACL for a group.
508 setacl
-m group
:$agid:4 tmpfile0
510 func_test_copy tmpfile0 tmpfile3
512 # Set an ACL for other.
513 setacl
-m other
:4 tmpfile0
515 func_test_copy tmpfile0 tmpfile4
517 # Remove the ACL for the user.
518 setacl
-d user
:$auid tmpfile0
520 func_test_copy tmpfile0 tmpfile5
522 # Remove the ACL for the group.
523 setacl
-d group
:$agid tmpfile0
525 func_test_copy tmpfile0 tmpfile6
527 # Delete all optional ACLs.
528 setacl
-m user
:$auid:1 tmpfile0
529 setacl
-s user
::6,group
::0,class
:7,other
:0 tmpfile0
531 func_test_copy tmpfile0 tmpfile8
533 # Copy ACLs from a file that has no ACLs.
536 getacl tmpfile9
> tmpaclout0
537 setacl
-f tmpaclout0 tmpfile0
540 func_test_copy tmpfile0 tmpfile9
546 # Set an ACL for a user.
547 { aclget tmpfile0 |
sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
549 func_test_copy tmpfile0 tmpfile2
551 # Set an ACL for a group.
552 { aclget tmpfile0 |
sed -e 's/disabled$/enabled/'; echo " permit r-- g:$agid"; } | aclput tmpfile0
554 func_test_copy tmpfile0 tmpfile3
556 # Set an ACL for other.
559 func_test_copy tmpfile0 tmpfile4
561 # Remove the ACL for the user.
562 aclget tmpfile0 |
grep -v ' u:[^ ]*$' | aclput tmpfile0
564 func_test_copy tmpfile0 tmpfile5
566 # Remove the ACL for the group.
567 aclget tmpfile0 |
grep -v ' g:[^ ]*$' | aclput tmpfile0
569 func_test_copy tmpfile0 tmpfile7
571 # Delete all optional ACLs.
572 aclget tmpfile0 |
sed -e 's/enabled$/disabled/' |
sed -e '/disabled$/q' | aclput tmpfile0
574 func_test_copy tmpfile0 tmpfile8
576 # Copy ACLs from a file that has no ACLs.
579 aclget tmpfile9 | aclput tmpfile0
582 func_test_copy tmpfile0 tmpfile9
588 # Set an ACL for a user.
589 /bin
/chmod +a
"user:daemon allow execute" tmpfile0
591 func_test_copy tmpfile0 tmpfile2
593 # Set an ACL for a group.
594 /bin
/chmod +a
"group:daemon allow read" tmpfile0
596 func_test_copy tmpfile0 tmpfile3
598 # Set an ACL for other.
601 func_test_copy tmpfile0 tmpfile4
603 # Remove the ACL for the user.
604 /bin
/chmod -a "user:daemon allow execute" tmpfile0
606 func_test_copy tmpfile0 tmpfile5
608 # Remove the ACL for the group.
609 /bin
/chmod -a "group:daemon allow read" tmpfile0
611 func_test_copy tmpfile0 tmpfile7
613 # Delete all optional ACLs.
614 /bin
/chmod -N tmpfile0
616 func_test_copy tmpfile0 tmpfile8
618 # Copy ACLs from a file that has no ACLs.
621 { /bin
/ls -le tmpfile9 |
sed -n -e 's/^ [0-9][0-9]*: //p'; echo; } |
/bin
/chmod -E tmpfile0
624 func_test_copy tmpfile0 tmpfile9
630 # Set an ACL for a user.
631 /sbin
/chacl user
::rw-
,group
::---,other
::---,user
:$auid:--x tmpfile0
633 func_test_copy tmpfile0 tmpfile2
635 # Set an ACL for a group.
636 /sbin
/chacl user
::rw-
,group
::---,other
::---,user
:$auid:--x,group
:$agid:r-- tmpfile0
638 func_test_copy tmpfile0 tmpfile3
640 # Set an ACL for other.
641 /sbin
/chacl user
::rw-
,group
::---,user
:$auid:--x,group
:$agid:r--
,other
::r-- tmpfile0
643 func_test_copy tmpfile0 tmpfile4
645 # Remove the ACL for the user.
646 /sbin
/chacl user
::rw-
,group
::---,group
:$agid:r--
,other
::r-- tmpfile0
648 func_test_copy tmpfile0 tmpfile5
650 # Remove the ACL for the group.
651 /sbin
/chacl user
::rw-
,group
::---,other
::r-- tmpfile0
653 func_test_copy tmpfile0 tmpfile7
660 rm -f tmpfile
[0-9] tmpaclout
[0-2]