Mercurial > hg > octave-kai > gnulib-hg
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 |
rev | line source |
---|---|
10142 | 1 #!/bin/sh |
2 | |
3 # Show all commands when run with environment variable VERBOSE=yes. | |
4 test -z "$VERBOSE" || set -x | |
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 | 12 # func_tmpdir |
13 # creates a temporary directory. | |
14 # Sets variable | |
15 # - tmp pathname of freshly created temporary directory | |
16 func_tmpdir () | |
17 { | |
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. | |
21 : ${TMPDIR=/tmp} | |
22 { | |
23 # Use the mktemp program if available. If not available, hide the error | |
24 # message. | |
25 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` && | |
26 test -n "$tmp" && test -d "$tmp" | |
27 } || | |
28 { | |
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 | |
33 # directory. | |
34 tmp=$TMPDIR/gl$$-$RANDOM | |
35 (umask 077 && mkdir "$tmp") | |
36 } || | |
37 { | |
38 echo "$0: cannot create a temporary directory in $TMPDIR" >&2 | |
39 exit 1 | |
40 } | |
41 } | |
42 | |
43 func_tmpdir | |
44 builddir=`pwd` | |
45 cd "$builddir" || | |
46 { | |
47 echo "$0: cannot determine build directory (unreadable parent dir?)" >&2 | |
48 exit 1 | |
49 } | |
50 # Switch to a temporary directory, to increase the likelihood that ACLs are | |
51 # supported on the current file system. (/tmp is usually locally mounted, | |
52 # whereas the build dir is sometimes NFS-mounted.) | |
53 ( cd "$tmp" | |
54 | |
55 # Prepare tmpfile0. | |
56 rm -f tmpfile[0-9] | |
57 echo "Simple contents" > tmpfile0 | |
58 chmod 600 tmpfile0 | |
59 | |
60 # Classification of the platform according to the programs available for | |
61 # manipulating ACLs. | |
62 # Possible values are: | |
63 # linux, cygwin, freebsd, solaris, hpux, osf1, aix, macosx, irix, none. | |
64 # TODO: Support also native Win32 platforms (mingw). | |
65 acl_flavor=none | |
66 if (getfacl tmpfile0 >/dev/null) 2>/dev/null; then | |
67 # Platforms with the getfacl and setfacl programs. | |
68 # Linux, FreeBSD, Solaris, Cygwin. | |
69 if (setfacl --help >/dev/null) 2>/dev/null; then | |
70 # Linux, Cygwin. | |
71 if (LC_ALL=C setfacl --help | grep ' --set-file' >/dev/null) 2>/dev/null; then | |
72 # Linux. | |
73 acl_flavor=linux | |
74 else | |
75 acl_flavor=cygwin | |
76 fi | |
77 else | |
78 # FreeBSD, Solaris. | |
79 if (LC_ALL=C setfacl 2>&1 | grep '\-x entries' >/dev/null) 2>/dev/null; then | |
80 # FreeBSD. | |
81 acl_flavor=freebsd | |
82 else | |
83 # Solaris. | |
84 acl_flavor=solaris | |
85 fi | |
86 fi | |
87 else | |
88 if (lsacl / >/dev/null) 2>/dev/null; then | |
89 # Platforms with the lsacl and chacl programs. | |
90 # HP-UX, sometimes also IRIX. | |
91 acl_flavor=hpux | |
92 else | |
93 if (getacl tmpfile0 >/dev/null) 2>/dev/null; then | |
94 # Tru64. | |
95 acl_flavor=osf1 | |
96 else | |
97 if (aclget tmpfile0 >/dev/null) 2>/dev/null; then | |
98 # AIX. | |
99 acl_flavor=aix | |
100 else | |
101 if (fsaclctl -v >/dev/null) 2>/dev/null; then | |
102 # MacOS X. | |
103 acl_flavor=macosx | |
104 else | |
105 if test -f /sbin/chacl; then | |
106 # IRIX. | |
107 acl_flavor=irix | |
108 fi | |
109 fi | |
110 fi | |
111 fi | |
112 fi | |
113 fi | |
114 | |
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 | 122 # Use a user and group id different from the current one, to avoid |
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 | 126 auid=1 |
127 if test "$auid" = "$myuid"; then auid=2; fi | |
128 agid=1 | |
129 if test "$agid" = "$mygid"; then agid=2; fi | |
130 fi | |
131 | |
132 for mode in 700 400 200 100 644 650 605 011 4700 2070; do | |
133 rm -f tmpfile0 tmpfile1 tmpfile2 | |
134 | |
135 # Prepare a file with no ACL. | |
136 echo "Anything" > tmpfile0 | |
137 # If a mode is not supported (e.g. 2070 on FreeBSD), we skip testing it. | |
138 if chmod $mode tmpfile0 2>/dev/null; then | |
139 modestring0=`ls -l tmpfile0 | dd ibs=1 count=10 2>/dev/null` | |
140 | |
141 # Prepare a file with no ACL. | |
142 echo "Some contents" > tmpfile1 | |
143 chmod 600 tmpfile1 | |
144 | |
145 # Try to set the ACL to only the given mode. | |
146 "$builddir"/test-set-mode-acl${EXEEXT} tmpfile1 $mode | |
147 # Verify that tmpfile1 has no ACL and has the desired mode. | |
148 modestring=`ls -l tmpfile1 | dd ibs=1 count=10 2>/dev/null` | |
149 if test "x$modestring" != "x$modestring0"; then | |
150 echo "mode = $mode: tmpfile1 has wrong mode: $modestring" 1>&2 | |
151 exit 1 | |
152 fi | |
153 if test `"$builddir"/test-file-has-acl${EXEEXT} tmpfile1` != no; then | |
154 echo "mode = $mode: tmpfile1 got an ACL" 1>&2 | |
155 exit 1 | |
156 fi | |
157 | |
158 if test $acl_flavor != none; then | |
159 | |
160 # Prepare a file with an ACL. | |
161 echo "Special contents" > tmpfile2 | |
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 | 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 | 166 setfacl -m user:$auid:1 tmpfile0 |
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 | 171 hpux) |
172 orig=`lsacl tmpfile0 | sed -e 's/ tmpfile0$//'` | |
173 chacl -r "${orig}($auid.%,--x)" tmpfile0 | |
174 ;; | |
175 osf1) | |
176 setacl -u user:$auid:1 tmpfile0 | |
177 ;; | |
178 aix) | |
179 { aclget tmpfile0 | sed -e 's/disabled$/enabled/'; echo " permit --x u:$auid"; } | aclput tmpfile0 | |
180 ;; | |
181 macosx) | |
182 /bin/chmod +a "user:daemon allow execute" tmpfile0 | |
183 ;; | |
184 irix) | |
185 /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0 | |
186 ;; | |
187 esac | |
188 | |
189 # Try to set the ACL to only the given mode. | |
190 "$builddir"/test-set-mode-acl${EXEEXT} tmpfile2 $mode | |
191 # Verify that tmpfile2 has no ACL and has the desired mode. | |
192 modestring=`ls -l tmpfile2 | dd ibs=1 count=10 2>/dev/null` | |
193 if test "x$modestring" != "x$modestring0"; then | |
194 echo "mode = $mode: tmpfile2 has wrong mode: $modestring" 1>&2 | |
195 exit 1 | |
196 fi | |
197 if test `"$builddir"/test-file-has-acl${EXEEXT} tmpfile2` != no; then | |
198 echo "mode = $mode: tmpfile2 still has an ACL" 1>&2 | |
199 exit 1 | |
200 fi | |
201 fi | |
202 fi | |
203 done | |
204 | |
205 rm -f tmpfile[0-9] | |
206 ) || exit 1 | |
207 | |
208 rm -rf "$tmp" | |
209 exit 0 |