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.)
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 if test $acl_flavor != none; then
110 # A POSIX compliant 'id' program.
111 if test -f /usr/xpg4/bin/id; then
116 # Use a user and group id different from the current one, to avoid
117 # redundant/ambiguous ACLs.
121 if test "$auid" = "$myuid"; then auid=2; fi
123 if test "$agid" = "$mygid"; then agid=2; fi
126 for mode in 700 400 200 100 644 650 605 011 4700 2070; do
127 rm -f tmpfile0 tmpfile1 tmpfile2
129 # Prepare a file with no ACL.
130 echo "Anything" > tmpfile0
131 # If a mode is not supported (e.g. 2070 on FreeBSD), we skip testing it.
132 if chmod $mode tmpfile0 2>/dev/null; then
133 modestring0=`ls -l tmpfile0 | dd ibs=1 count=10 2>/dev/null`
135 # Prepare a file with no ACL.
136 echo "Some contents" > tmpfile1
139 # Try to set the ACL to only the given mode.
140 "$builddir"/test-set-mode-acl${EXEEXT} tmpfile1 $mode
141 # Verify that tmpfile1 has no ACL and has the desired mode.
142 modestring=`ls -l tmpfile1 | dd ibs=1 count=10 2>/dev/null`
143 if test "x$modestring" != "x$modestring0"; then
144 echo "mode = $mode: tmpfile1 has wrong mode: $modestring" 1>&2
147 if test `"$builddir"/test-file-has-acl${EXEEXT} tmpfile1` != no; then
148 echo "mode = $mode: tmpfile1 got an ACL" 1>&2
152 if test $acl_flavor != none; then
154 # Prepare a file with an ACL.
155 echo "Special contents" > tmpfile2
157 # Set an ACL for a user (or group).
159 linux | freebsd | solaris)
160 setfacl -m user:$auid:1 tmpfile0
163 setfacl -m group:0:1 tmpfile0
166 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
167 chacl -r "${orig}($auid.%,--x)" tmpfile0
170 setacl -u user:$auid:1 tmpfile0
173 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0
176 /bin/chmod +a "user:daemon allow execute" tmpfile0
179 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0
183 # Try to set the ACL to only the given mode.
184 "$builddir"/test-set-mode-acl${EXEEXT} tmpfile2 $mode
185 # Verify that tmpfile2 has no ACL and has the desired mode.
186 modestring=`ls -l tmpfile2 | dd ibs=1 count=10 2>/dev/null`
187 if test "x$modestring" != "x$modestring0"; then
188 echo "mode = $mode: tmpfile2 has wrong mode: $modestring" 1>&2
191 if test `"$builddir"/test-file-has-acl${EXEEXT} tmpfile2` != no; then
192 echo "mode = $mode: tmpfile2 still has an ACL" 1>&2