annotate tests/test-set-mode-acl.sh @ 13328:1c0d89ded4f9

acl: Avoid test failure on Cygwin-hosted mingw.
author Bruno Haible <bruno@clisp.org>
date Sun, 09 May 2010 18:51:48 +0200
parents e9cf9c46ad7a
children 87aaf9340686
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
13328
1c0d89ded4f9 acl: Avoid test failure on Cygwin-hosted mingw.
Bruno Haible <bruno@clisp.org>
parents: 11914
diff changeset
6 test "$USE_ACL" = 0 &&
1c0d89ded4f9 acl: Avoid test failure on Cygwin-hosted mingw.
Bruno Haible <bruno@clisp.org>
parents: 11914
diff changeset
7 {
1c0d89ded4f9 acl: Avoid test failure on Cygwin-hosted mingw.
Bruno Haible <bruno@clisp.org>
parents: 11914
diff changeset
8 echo "Skipping test: insufficient ACL support"
1c0d89ded4f9 acl: Avoid test failure on Cygwin-hosted mingw.
Bruno Haible <bruno@clisp.org>
parents: 11914
diff changeset
9 exit 77
1c0d89ded4f9 acl: Avoid test failure on Cygwin-hosted mingw.
Bruno Haible <bruno@clisp.org>
parents: 11914
diff changeset
10 }
1c0d89ded4f9 acl: Avoid test failure on Cygwin-hosted mingw.
Bruno Haible <bruno@clisp.org>
parents: 11914
diff changeset
11
10142
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 # func_tmpdir
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 # creates a temporary directory.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 # Sets variable
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 # - tmp pathname of freshly created temporary directory
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 func_tmpdir ()
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 # Use the environment variable TMPDIR, falling back to /tmp. This allows
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 # users to specify a different temporary directory, for example, if their
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 # /tmp is filled up or too small.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 : ${TMPDIR=/tmp}
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 the mktemp program if available. If not available, hide the error
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 # message.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 test -n "$tmp" && test -d "$tmp"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 } ||
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 # 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
30 # 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
31 # 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
32 # 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
33 # directory.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 tmp=$TMPDIR/gl$$-$RANDOM
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 (umask 077 && mkdir "$tmp")
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 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 exit 1
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 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 func_tmpdir
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 builddir=`pwd`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 cd "$builddir" ||
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 {
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 echo "$0: cannot determine build directory (unreadable parent dir?)" >&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 }
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 # 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
51 # supported on the current file system. (/tmp is usually locally mounted,
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 # whereas the build dir is sometimes NFS-mounted.)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 ( cd "$tmp"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 # Prepare tmpfile0.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 rm -f tmpfile[0-9]
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 echo "Simple contents" > tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 chmod 600 tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 # Classification of the platform according to the programs available for
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 # manipulating ACLs.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 # Possible values are:
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 # linux, cygwin, freebsd, solaris, hpux, osf1, aix, macosx, irix, none.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 # TODO: Support also native Win32 platforms (mingw).
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 acl_flavor=none
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 if (getfacl tmpfile0 >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 # Platforms with the getfacl and setfacl programs.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 # Linux, FreeBSD, Solaris, Cygwin.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 if (setfacl --help >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 # Linux, Cygwin.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 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
72 # Linux.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 acl_flavor=linux
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 acl_flavor=cygwin
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 # FreeBSD, Solaris.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 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
80 # FreeBSD.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 acl_flavor=freebsd
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 # Solaris.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 acl_flavor=solaris
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 if (lsacl / >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 # Platforms with the lsacl and chacl programs.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 # HP-UX, sometimes also IRIX.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 acl_flavor=hpux
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 if (getacl tmpfile0 >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 # Tru64.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 acl_flavor=osf1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 if (aclget tmpfile0 >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 # AIX.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 acl_flavor=aix
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 if (fsaclctl -v >/dev/null) 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 # MacOS X.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 acl_flavor=macosx
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 else
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 if test -f /sbin/chacl; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 # IRIX.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 acl_flavor=irix
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 if test $acl_flavor != none; then
11914
e9cf9c46ad7a Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents: 10149
diff changeset
116 # A POSIX compliant 'id' program.
e9cf9c46ad7a Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents: 10149
diff changeset
117 if test -f /usr/xpg4/bin/id; then
e9cf9c46ad7a Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents: 10149
diff changeset
118 ID=/usr/xpg4/bin/id
e9cf9c46ad7a Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents: 10149
diff changeset
119 else
e9cf9c46ad7a Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents: 10149
diff changeset
120 ID=id
e9cf9c46ad7a Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents: 10149
diff changeset
121 fi
10142
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 # 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
123 # redundant/ambiguous ACLs.
11914
e9cf9c46ad7a Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents: 10149
diff changeset
124 myuid=`$ID -u`
e9cf9c46ad7a Work around deficient /usr/bin/id program on Solaris.
Bruno Haible <bruno@clisp.org>
parents: 10149
diff changeset
125 mygid=`$ID -g`
10142
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 auid=1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 if test "$auid" = "$myuid"; then auid=2; fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 agid=1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 if test "$agid" = "$mygid"; then agid=2; fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 fi
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 for mode in 700 400 200 100 644 650 605 011 4700 2070; do
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 rm -f tmpfile0 tmpfile1 tmpfile2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 # Prepare a file with no ACL.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 echo "Anything" > tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 # If a mode is not supported (e.g. 2070 on FreeBSD), we skip testing it.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 if chmod $mode tmpfile0 2>/dev/null; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 modestring0=`ls -l tmpfile0 | dd ibs=1 count=10 2>/dev/null`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 # Prepare a file with no ACL.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 echo "Some contents" > tmpfile1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 chmod 600 tmpfile1
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 # Try to set the ACL to only the given mode.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 "$builddir"/test-set-mode-acl${EXEEXT} tmpfile1 $mode
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 # Verify that tmpfile1 has no ACL and has the desired mode.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 modestring=`ls -l tmpfile1 | dd ibs=1 count=10 2>/dev/null`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 if test "x$modestring" != "x$modestring0"; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 echo "mode = $mode: tmpfile1 has wrong mode: $modestring" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 if test `"$builddir"/test-file-has-acl${EXEEXT} tmpfile1` != no; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 echo "mode = $mode: tmpfile1 got an ACL" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 fi
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 if test $acl_flavor != none; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 # Prepare a file with an ACL.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 echo "Special contents" > tmpfile2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 chmod 600 tmpfile2
10149
2f94bd2a861d Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents: 10142
diff changeset
163 # Set an ACL for a user (or group).
10142
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 case $acl_flavor in
10149
2f94bd2a861d Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents: 10142
diff changeset
165 linux | freebsd | solaris)
10142
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 setfacl -m user:$auid:1 tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 ;;
10149
2f94bd2a861d Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents: 10142
diff changeset
168 cygwin)
2f94bd2a861d Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents: 10142
diff changeset
169 setfacl -m group:0:1 tmpfile0
2f94bd2a861d Use different test code for Cygwin.
Bruno Haible <bruno@clisp.org>
parents: 10142
diff changeset
170 ;;
10142
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 hpux)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 chacl -r "${orig}($auid.%,--x)" tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 osf1)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 setacl -u user:$auid:1 tmpfile0
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 aix)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 { 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
180 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
181 macosx)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 /bin/chmod +a "user:daemon allow execute" tmpfile0
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 ;;
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 irix)
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0
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 esac
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 # Try to set the ACL to only the given mode.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 "$builddir"/test-set-mode-acl${EXEEXT} tmpfile2 $mode
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 # Verify that tmpfile2 has no ACL and has the desired mode.
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 modestring=`ls -l tmpfile2 | dd ibs=1 count=10 2>/dev/null`
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 if test "x$modestring" != "x$modestring0"; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 echo "mode = $mode: tmpfile2 has wrong mode: $modestring" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 if test `"$builddir"/test-file-has-acl${EXEEXT} tmpfile2` != no; then
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 echo "mode = $mode: tmpfile2 still has an ACL" 1>&2
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 exit 1
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 fi
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 done
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 rm -f tmpfile[0-9]
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 ) || exit 1
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 rm -rf "$tmp"
dc740b83408a New ACL unit tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 exit 0