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