]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/acl-xattr-test
Fix xattr/acl regression script.
[bacula/bacula] / regress / tests / acl-xattr-test
1 #!/bin/sh
2 #
3 # Run a backup of the Bacula build directory with some acls then restore it.
4 #
5 # For Linux:
6 #    Your filesystem must be mounted with the acl option (mount -o remount,acl,user_xattr /tmp)
7 #    on ubuntu, the attr package must be installed
8 #
9 #    For this script to work, you will also need a number of acl packages loaded
10 #    not default on Debian derivatives: 
11 #       apt-get install acl libacl1 libacl1-dev attr
12 #
13 # For OSX and Solaris:
14 #
15 #    Defaults should be ok
16 #
17 # For FreeBSD:
18 #
19 #    Your filesystem must have acls enabled and needs to be mounted with acls.
20 #       tunefs -a enable <device>
21 #       acls mountoption in /etc/fstab
22 #
23 # For NetBSD:
24 #
25 #    Defaults should be ok (As NetBSD doesn't support native acls we skip that test).
26 #
27 TestName="acl-xattr-test"
28 JobName=backup
29 . scripts/functions
30
31 #
32 # See if the right software is installed.
33 #
34 case `uname -s` in
35    Linux)
36       # Require getfacl to be installed
37       getfacl Makefile 2>&1 >/dev/null
38       if test  $? -ne 0; then
39         echo "$TestName skipped: getfacl not installed"
40         exit 0
41       fi
42
43       # Require getfattr to be installed
44       getfattr -d Makefile 2>&1 >/dev/null
45       if test $? -ne 0; then
46         echo "$TestName skipped: getfattr not installed"
47         exit 0
48       fi
49       ;;
50    Darwin)
51       ;;
52    SunOS)
53       ;;
54    FreeBSD)
55       # Require getfacl to be installed
56       getfacl Makefile 2>&1 >/dev/null
57       if test  $? -ne 0; then
58         echo "$TestName skipped: getfacl not installed"
59         exit 0
60       fi
61
62       # Require lsextattr to be installed
63       lsextattr user Makefile 2>&1 >/dev/null
64       if test $? -ne 0; then
65         echo "$TestName skipped: lsextattr not installed"
66         exit 0
67       fi
68       ;;
69    NetBSD)
70       # Require lsextattr to be installed
71       lsextattr user Makefile 2>&1 >/dev/null
72       if test $? -ne 0; then
73         echo "$TestName skipped: lsextattr not installed"
74         exit 0
75       fi
76       ;;
77    *)
78       echo "Unsupported OS"
79       exit 0
80       ;;
81 esac
82
83 scripts/cleanup
84 scripts/copy-confs
85
86 #
87 # Zap out any schedule in default conf file so that
88 #  it doesn't start during our test
89 #
90 outf="tmp/sed_tmp"
91 echo "s%  Schedule =%# Schedule =%g" > $outf
92 echo "s/Options {/Options { aclsupport=yes; xattrsupport = yes/" >> $outf
93 cp ${cwd}/bin/bacula-dir.conf  $cwd/tmp/1
94 sed -f ${outf} ${cwd}/tmp/1 >${cwd}/bin/bacula-dir.conf
95
96 d=${cwd}/build/acl
97
98 uid=`id -u`
99 rm -rf $d
100 mkdir -p $d
101 mkdir -p $d/acl-dir
102 cp ${cwd}/bin/bconsole $d
103
104 case `uname -s` in
105    Linux)
106       setfacl -m d:user:$uid:r-x $d/acl-dir
107       setfacl -m d:user:root:-wx $d/acl-dir
108       setfacl -m user:nobody:--- $d/acl-dir
109       setfacl -m user:nobody:--- $d/bconsole
110       setfacl -m group:nogroup:--x $d/bconsole
111       cp ${cwd}/bin/bconsole $d/acl-dir
112       cp ${cwd}/bin/bconsole $d/other
113       setfattr -h -n user.bacula.test -v rulez $d/other 2>/dev/null 1>/dev/null
114       setfattr -h -n user.bacula.secondtest -v rulez $d/other 2>/dev/null 1>/dev/null
115
116       ( cd $cwd/build
117         getfacl -R acl > $cwd/tmp/org
118         getfattr -h -n user.bacula.test $d/other > $cwd/tmp/attr.org
119         getfattr -h -n user.bacula.secondtest $d/other >> $cwd/tmp/attr.org
120       )
121       ;;
122    Darwin)
123       chmod +a "user:$uid allow read execute" $d/acl-dir
124       chmod +a "user:root allow write execute" $d/acl-dir
125       chmod +a "user:nobody deny read write execute" $d/acl-dir
126       chmod +a "user:nobody deny read write execute" $d/bconsole
127       chmod +a "group:nogroup allow execute" $d/bconsole
128       cp ${cwd}/bin/bconsole $d/acl-dir
129       cp ${cwd}/bin/bconsole $d/other
130       xattr -w  bacula.test "rulez" $d/other 2>/dev/null 1>/dev/null
131       xattr -w  bacula.secondtest "rulez" $d/other 2>/dev/null 1>/dev/null
132
133       ( cd $cwd/build
134         ls -lde -R acl > $cwd/tmp/org
135         xattr -p bacula.test $d/other > $cwd/tmp/attr.org
136         xattr -p bacula.secondtest $d/other >> $cwd/tmp/attr.org
137       )
138       ;;
139    SunOS)
140       #
141       # See if we need to set ZFS or POSIX acls
142       #
143       df -F zfs $d > /dev/null 2>&1
144       if [ $? = 0 ]; then
145          /bin/chmod A+user:$uid:rx:allow $d/acl-dir
146          /bin/chmod A+user:root:wx:allow $d/acl-dir
147          /bin/chmod A+user:nobody:rwx:deny $d/acl-dir
148          /bin/chmod A+user:nobody:rwx:deny $d/bconsole
149          /bin/chmod A+group:nogroup:x:allow $d/bconsole
150       else
151          /bin/chmod A+user:$uid:r-x $d/acl-dir
152          /bin/chmod A+user:root:-wx $d/acl-dir
153          /bin/chmod A+user:nobody:--- $d/acl-dir
154          /bin/chmod A+user:nobody:--- $d/bconsole
155          /bin/chmod A+group:nogroup:--x $d/bconsole
156       fi
157       cp ${cwd}/bin/bconsole $d/other
158       /bin/runat $d/other 'cat > bacula.test' << EOF
159 rulez
160 EOF
161       /bin/runat $d/other 'cat > bacula.secondtest' << EOF
162 rulez
163 EOF
164       ( cd $cwd/build
165         /bin/ls -ldv -R acl > $cwd/tmp/org
166         /bin/runat $d/other 'cat bacula.test' > $cwd/tmp/attr.org
167         /bin/runat $d/other 'cat bacula.secondtest' >> $cwd/tmp/attr.org
168       )
169       ;;
170    FreeBSD)
171       setfacl -m d:user:$uid:r-x $d/acl-dir
172       setfacl -m d:user:root:-wx $d/acl-dir
173       setfacl -m user:nobody:--- $d/acl-dir
174       setfacl -m user:nobody:--- $d/bconsole
175       setfacl -m group:nogroup:--x $d/bconsole
176       cp ${cwd}/bin/bconsole $d/acl-dir
177       cp ${cwd}/bin/bconsole $d/other
178       setextattr user bacula.test rulez $d/other 2>/dev/null 1>/dev/null
179       setextattr user bacula.secondtest rulez $d/other 2>/dev/null 1>/dev/null
180
181       ( cd $cwd/build
182         for file in acl/*
183         do
184            getfacl $file
185         done > $cwd/tmp/org
186         getextattr user bacula.test $d/other > $cwd/tmp/attr.org
187         getextattr user bacula.secondtest $d/other >> $cwd/tmp/attr.org
188       )
189       ;;
190    NetBSD)
191       cp ${cwd}/bin/bconsole $d/other
192       setextattr user bacula.test rulez $d/other 2>/dev/null 1>/dev/null
193       setextattr user bacula.secondtest rulez $d/other 2>/dev/null 1>/dev/null
194
195       ( cd $cwd/build
196         cp /dev/null $cwd/tmp/org
197         getextattr user bacula.test $d/other > $cwd/tmp/attr.org
198         getextattr user bacula.secondtest $d/other >> $cwd/tmp/attr.org
199       )
200       ;;
201 esac
202
203 change_jobname BackupClient1 $JobName
204 start_test
205
206 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
207 @$out /dev/null
208 messages
209 @$out ${cwd}/tmp/log1.out
210 label volume=TestVolume001 storage=File pool=File
211 setdebug level=400 trace=1 client
212 setdebug level=300 trace=1 director
213 setdebug level=300 trace=1 storage
214 run job=$JobName yes
215 wait
216 messages
217 @# 
218 @# now do a restore
219 @#
220 @$out ${cwd}/tmp/log2.out  
221 restore where=${cwd}/tmp/bacula-restores select all done
222 yes
223 wait
224 messages
225 quit
226 END_OF_DATA
227
228 run_bacula
229 check_for_zombie_jobs storage=File
230 stop_bacula
231
232 case `uname -s` in
233    Linux)
234       ( cd $cwd/tmp/bacula-restores/$cwd/build
235         getfacl -R acl > $cwd/tmp/new
236         getfattr -h -n user.bacula.test $d/other > $cwd/tmp/attr.new
237         getfattr -h -n user.bacula.secondtest $d/other >> $cwd/tmp/attr.new
238       )
239       ;;
240    Darwin)
241       ( cd $cwd/tmp/bacula-restores/$cwd/build
242         ls -lde -R acl > $cwd/tmp/new
243         xattr -p bacula.test $d/other > $cwd/tmp/attr.new
244         xattr -p bacula.secondtest $d/other >> $cwd/tmp/attr.new
245       )
246       ;;
247    SunOS)
248       ( cd $cwd/tmp/bacula-restores/$cwd/build
249         /bin/ls -ldv -R acl > $cwd/tmp/new
250         /bin/runat $d/other 'cat bacula.test' > $cwd/tmp/attr.new
251         /bin/runat $d/other 'cat bacula.secondtest' >> $cwd/tmp/attr.new
252       )
253       ;;
254    FreeBSD)
255       ( cd $cwd/tmp/bacula-restores/$cwd/build
256         for file in acl/*
257         do
258            getfacl $file
259         done > $cwd/tmp/new
260         getextattr user bacula.test $d/other > $cwd/tmp/attr.new
261         getextattr user bacula.secondtest $d/other >> $cwd/tmp/attr.new
262       )
263       ;;
264    NetBSD)
265       ( cd $cwd/tmp/bacula-restores/$cwd/build
266         cp /dev/null $cwd/tmp/new
267         getextattr user bacula.test $d/other > $cwd/tmp/attr.new
268         getextattr user bacula.secondtest $d/other >> $cwd/tmp/attr.new
269       )
270       ;;
271 esac
272
273 diff -u $cwd/tmp/org $cwd/tmp/new
274 if [ $? -ne 0 ]; then
275    rstat=1
276 fi
277
278 diff $cwd/tmp/attr.org $cwd/tmp/attr.new
279 if [ $? -ne 0 ]; then
280    rstat=1
281 fi
282
283 check_two_logs
284 check_restore_diff
285
286 if [ x$REGRESS_DEBUG != x ]; then
287   rm -rf $d
288 fi
289
290 end_test