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] tmp.err
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 # func_test_has_acl file expected
110 # tests the result of the file_has_acl function on file, and checks that it
111 # matches the expected value.
114 res=`"$builddir"/test-file-has-acl${EXEEXT} "$1"`
115 test "$res" = "$2" || {
116 echo "file_has_acl(\"$1\") returned $res, expected $2" 1>&2
121 # func_test_file_has_acl file expected
122 # tests the result of the file_has_acl function on file, and checks that it
123 # matches the expected value.
124 func_test_file_has_acl ()
126 res=`"$builddir"/test-file-has-acl${EXEEXT} "$1"`
127 test "$res" = "$2" || {
128 echo "file_has_acl(\"$1\") returned $res, expected $2" 1>&2
133 # func_test_has_acl file expected
134 # tests the result of the file_has_acl function on file, and checks that it
135 # matches the expected value, also taking into account the system's 'ls'
138 freebsd | solaris | hpux | macosx)
140 freebsd | solaris | hpux) acl_ls_option="-ld" ;;
141 macosx) acl_ls_option="-lde" ;;
145 func_test_file_has_acl "$1" "$2"
146 case `/bin/ls $acl_ls_option "$1" | sed 1q` in
149 echo "/bin/ls $acl_ls_option $1 shows an ACL, but expected $2" 1>&2
155 echo "/bin/ls $acl_ls_option $1 shows no ACL, but expected $2" 1>&2
165 func_test_file_has_acl "$1" "$2"
166 case `/bin/ls -ldD "$1" | sed 1q` in
169 echo "/bin/ls -ldD $1 shows no ACL, but expected $2" 1>&2
175 echo "/bin/ls -ldD $1 shows an ACL, but expected $2" 1>&2
185 func_test_file_has_acl "$1" "$2"
190 func_test_has_acl tmpfile0 no
192 if test $acl_flavor != none; then
193 # Use a user and group id different from the current one, to avoid
194 # redundant/ambiguous ACLs.
198 if test "$auid" = "$myuid"; then auid=2; fi
200 if test "$agid" = "$mygid"; then agid=2; fi
203 linux | cygwin | freebsd | solaris)
205 # Set an ACL for a user.
206 if setfacl -m user:$auid:1 tmpfile0; then
208 func_test_has_acl tmpfile0 yes
210 # Remove the ACL for the user.
212 linux) setfacl -x user:$auid tmpfile0 ;;
213 freebsd) setfacl -x user:$auid:1 tmpfile0 ;;
214 *) setfacl -d user:$auid:1 tmpfile0 ;;
217 # On Linux, the ACL for the mask is implicitly added.
218 # On Solaris, it is always there.
220 linux) func_test_has_acl tmpfile0 yes ;;
221 *) func_test_has_acl tmpfile0 no ;;
224 # Remove the ACL for the mask, if it was implicitly added.
226 linux | freebsd) setfacl -x mask: tmpfile0 ;;
227 *) setfacl -d mask: tmpfile0 ;;
230 func_test_has_acl tmpfile0 no
237 # Set an ACL for a user.
238 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
239 if chacl -r "${orig}($auid.%,--x)" tmpfile0; then
241 func_test_has_acl tmpfile0 yes
243 # Remove the ACL for the user.
244 chacl -d "($auid.%,--x)" tmpfile0
246 func_test_has_acl tmpfile0 no
253 # Set an ACL for a user.
254 setacl -u user:$auid:1 tmpfile0 2> tmp.err
256 if grep 'Error:' tmp.err > /dev/null \
257 || grep 'Operation not supported' tmp.err > /dev/null; then
261 func_test_has_acl tmpfile0 yes
263 # Remove the ACL for the user.
264 setacl -x user:$auid:1 tmpfile0
266 func_test_has_acl tmpfile0 no
273 # Set an ACL for a user.
274 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
275 if aclget tmpfile0 | grep enabled > /dev/null; then
277 func_test_has_acl tmpfile0 yes
279 # Remove the ACL for the user.
280 aclget tmpfile0 | grep -v ' u:[^ ]*$' | aclput tmpfile0
282 func_test_has_acl tmpfile0 no
289 # Set an ACL for a user.
290 /bin/chmod +a "user:daemon allow execute" tmpfile0
292 func_test_has_acl tmpfile0 yes
294 # Remove the ACL for the user.
295 /bin/chmod -a "user:daemon allow execute" tmpfile0
297 func_test_has_acl tmpfile0 no
303 # Set an ACL for a user.
304 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0 2> tmp.err
306 if test -s tmp.err; then :; else
308 func_test_has_acl tmpfile0 yes
310 # Remove the ACL for the user.
311 /sbin/chacl user::rw-,group::---,other::--- tmpfile0
313 func_test_has_acl tmpfile0 no
321 rm -f tmpfile[0-9] tmp.err