annotate tests/test-file-has-acl.sh @ 10142:dc740b83408a

New ACL unit tests.
author Bruno Haible <bruno@clisp.org>
date Sun, 01 Jun 2008 22:51:13 +0200
parents
children 193862d1f436
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10142
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 #!/bin/sh
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 # Show all commands when run with environment variable VERBOSE=yes.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 test -z "$VERBOSE" || set -x
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 # func_tmpdir
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 # creates a temporary directory.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 # Sets variable
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 # - tmp pathname of freshly created temporary directory
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 func_tmpdir ()
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 # Use the environment variable TMPDIR, falling back to /tmp. This allows
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 # users to specify a different temporary directory, for example, if their
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 # /tmp is filled up or too small.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 : ${TMPDIR=/tmp}
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 # Use the mktemp program if available. If not available, hide the error
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 # message.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 test -n "$tmp" && test -d "$tmp"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 } ||
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 # Use a simple mkdir command. It is guaranteed to fail if the directory
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 # already exists. $RANDOM is bash specific and expands to empty in shells
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 # other than bash, ksh and zsh. Its use does not increase security;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 # rather, it minimizes the probability of failure in a very cluttered /tmp
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 # directory.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 tmp=$TMPDIR/gl$$-$RANDOM
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 (umask 077 && mkdir "$tmp")
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 } ||
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 func_tmpdir
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 builddir=`pwd`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 cd "$builddir" ||
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 # Switch to a temporary directory, to increase the likelihood that ACLs are
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 # supported on the current file system. (/tmp is usually locally mounted,
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 # whereas the build dir is sometimes NFS-mounted.)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 ( cd "$tmp"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 # Prepare tmpfile0.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 rm -f tmpfile[0-9] tmp.err
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 echo "Simple contents" > tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 chmod 600 tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 # Classification of the platform according to the programs available for
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 # manipulating ACLs.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 # Possible values are:
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 # linux, cygwin, freebsd, solaris, hpux, osf1, aix, macosx, irix, none.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 # TODO: Support also native Win32 platforms (mingw).
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 acl_flavor=none
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 if (getfacl tmpfile0 >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 # Platforms with the getfacl and setfacl programs.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 # Linux, FreeBSD, Solaris, Cygwin.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 if (setfacl --help >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 # Linux, Cygwin.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 if (LC_ALL=C setfacl --help | grep ' --set-file' >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 # Linux.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 acl_flavor=linux
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 acl_flavor=cygwin
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 # FreeBSD, Solaris.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 if (LC_ALL=C setfacl 2>&1 | grep '\-x entries' >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 # FreeBSD.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 acl_flavor=freebsd
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 # Solaris.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 acl_flavor=solaris
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 if (lsacl / >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 # Platforms with the lsacl and chacl programs.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 # HP-UX, sometimes also IRIX.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 acl_flavor=hpux
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 if (getacl tmpfile0 >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 # Tru64.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 acl_flavor=osf1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 if (aclget tmpfile0 >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 # AIX.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 acl_flavor=aix
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 if (fsaclctl -v >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 # MacOS X.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 acl_flavor=macosx
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 if test -f /sbin/chacl; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 # IRIX.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 acl_flavor=irix
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 # func_test_has_acl file expected
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 # tests the result of the file_has_acl function on file, and checks that it
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 # matches the expected value.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 func_test_has_acl ()
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 res=`"$builddir"/test-file-has-acl${EXEEXT} "$1"`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 test "$res" = "$2" || {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 echo "file_has_acl(\"$1\") returned $res, expected $2" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 # func_test_file_has_acl file expected
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 # tests the result of the file_has_acl function on file, and checks that it
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 # matches the expected value.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 func_test_file_has_acl ()
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 res=`"$builddir"/test-file-has-acl${EXEEXT} "$1"`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 test "$res" = "$2" || {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 echo "file_has_acl(\"$1\") returned $res, expected $2" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 # func_test_has_acl file expected
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 # tests the result of the file_has_acl function on file, and checks that it
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 # matches the expected value, also taking into account the system's 'ls'
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 # program.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 case $acl_flavor in
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 freebsd | solaris | hpux | macosx)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 case $acl_flavor in
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 freebsd | solaris | hpux) acl_ls_option="-ld" ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 macosx) acl_ls_option="-lde" ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 func_test_has_acl ()
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 func_test_file_has_acl "$1" "$2"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 case `/bin/ls $acl_ls_option "$1" | sed 1q` in
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 ??????????+*)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 test "$2" = yes || {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 echo "/bin/ls $acl_ls_option $1 shows an ACL, but expected $2" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 ??????????" "*)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 test "$2" = no || {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 echo "/bin/ls $acl_ls_option $1 shows no ACL, but expected $2" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 irix)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 func_test_has_acl ()
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 func_test_file_has_acl "$1" "$2"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 case `/bin/ls -ldD "$1" | sed 1q` in
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 *" []")
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 test "$2" = no || {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 echo "/bin/ls -ldD $1 shows no ACL, but expected $2" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 *)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 test "$2" = yes || {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 echo "/bin/ls -ldD $1 shows an ACL, but expected $2" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 *)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 func_test_has_acl ()
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 func_test_file_has_acl "$1" "$2"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 func_test_has_acl tmpfile0 no
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 if test $acl_flavor != none; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 # Use a user and group id different from the current one, to avoid
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 # redundant/ambiguous ACLs.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 myuid=`id -u`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 mygid=`id -g`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 auid=1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 if test "$auid" = "$myuid"; then auid=2; fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 agid=1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 if test "$agid" = "$mygid"; then agid=2; fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 case $acl_flavor in
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 linux | cygwin | freebsd | solaris)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 # Set an ACL for a user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 if setfacl -m user:$auid:1 tmpfile0; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 func_test_has_acl tmpfile0 yes
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
210 # Remove the ACL for the user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
211 case $acl_flavor in
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
212 linux) setfacl -x user:$auid tmpfile0 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
213 freebsd) setfacl -x user:$auid:1 tmpfile0 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
214 *) setfacl -d user:$auid:1 tmpfile0 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 # On Linux, the ACL for the mask is implicitly added.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 # On Solaris, it is always there.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 case $acl_flavor in
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 linux) func_test_has_acl tmpfile0 yes ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 *) func_test_has_acl tmpfile0 no ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 # Remove the ACL for the mask, if it was implicitly added.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 case $acl_flavor in
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 linux | freebsd) setfacl -x mask: tmpfile0 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 *) setfacl -d mask: tmpfile0 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 func_test_has_acl tmpfile0 no
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 hpux)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 # Set an ACL for a user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
239 if chacl -r "${orig}($auid.%,--x)" tmpfile0; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
240
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 func_test_has_acl tmpfile0 yes
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 # Remove the ACL for the user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 chacl -d "($auid.%,--x)" tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 func_test_has_acl tmpfile0 no
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 osf1)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 # Set an ACL for a user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 setacl -u user:$auid:1 tmpfile0 2> tmp.err
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 cat tmp.err 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256 if grep 'Error:' tmp.err > /dev/null \
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 || grep 'Operation not supported' tmp.err > /dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 :
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 func_test_has_acl tmpfile0 yes
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 # Remove the ACL for the user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 setacl -x user:$auid:1 tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 func_test_has_acl tmpfile0 no
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 aix)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 # Set an ACL for a user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 if aclget tmpfile0 | grep enabled > /dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 func_test_has_acl tmpfile0 yes
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 # Remove the ACL for the user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 aclget tmpfile0 | grep -v ' u:[^ ]*$' | aclput tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 func_test_has_acl tmpfile0 no
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 macosx)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 # Set an ACL for a user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
290 /bin/chmod +a "user:daemon allow execute" tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
291
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
292 func_test_has_acl tmpfile0 yes
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
293
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 # Remove the ACL for the user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 /bin/chmod -a "user:daemon allow execute" tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 func_test_has_acl tmpfile0 no
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 irix)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 # Set an ACL for a user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0 2> tmp.err
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 cat tmp.err 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 if test -s tmp.err; then :; else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 func_test_has_acl tmpfile0 yes
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 # Remove the ACL for the user.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 /sbin/chacl user::rw-,group::---,other::--- tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 func_test_has_acl tmpfile0 no
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 rm -f tmpfile[0-9] tmp.err
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 ) || exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 rm -rf "$tmp"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 exit 0