]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/acl-xattr-test
Merge branch 'master' into basejobv3
[bacula/bacula] / regress / tests / acl-xattr-test
1 #!/bin/sh
2 #
3 # Run a backup of the Bacula build directory with some acls
4 #   then restore it.
5 #
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 TestName="acl-xattr-test"
14 JobName=backup
15 . scripts/functions
16
17 #
18 # See if the right software is installed.
19 #
20 case `uname -s` in
21    Linux)
22       # Require getfacl to be installed
23       getfacl Makefile 2>&1 >/dev/null
24       if test  $? -ne 0; then
25         echo "$TestName skipped: getfacl not installed"
26         exit 0
27       fi
28
29       # Require attr to be installed
30       attr -l Makefile 2>&1 >/dev/null
31       if test $? -ne 0; then
32         echo "$TestName skipped: attr not installed"
33         exit 0
34       fi
35       ;;
36    Darwin)
37       ;;
38    SunOS)
39       ;;
40    *)
41       echo "Unsupported OS"
42       exit 0
43       ;;
44 esac
45
46 scripts/cleanup
47 scripts/copy-confs
48
49 #
50 # Zap out any schedule in default conf file so that
51 #  it doesn't start during our test
52 #
53 outf="tmp/sed_tmp"
54 echo "s%  Schedule =%# Schedule =%g" > $outf
55 echo "s/Options {/Options { aclsupport=yes; xattrsupport = yes/" >> $outf
56 cp ${cwd}/bin/bacula-dir.conf  $cwd/tmp/1
57 sed -f ${outf} ${cwd}/tmp/1 >${cwd}/bin/bacula-dir.conf
58
59 d=${cwd}/build/acl
60
61 uid=`id -u`
62 rm -rf $d
63 mkdir -p $d
64 mkdir -p $d/acl-dir
65 cp ${cwd}/bin/bconsole $d
66
67 case `uname -s` in
68    Linux)
69       setfacl -m d:user:$uid:r-x $d/acl-dir
70       setfacl -m d:user:root:-wx $d/acl-dir
71       setfacl -m user:nobody:--- $d/acl-dir
72       setfacl -m user:nobody:--- $d/bconsole
73       setfacl -m group:nogroup:--x $d/bconsole
74       cp ${cwd}/bin/bconsole $d/acl-dir
75       cp ${cwd}/bin/bconsole $d/other
76       attr -s bacula.test -V rulez $d/other 2>/dev/null 1>/dev/null
77
78       ( cd $cwd/build
79         getfacl -R acl > $cwd/tmp/org
80         attr -g bacula.test $d/other > $cwd/tmp/attr.org
81       )
82       ;;
83    Darwin)
84       chmod +a "user:$uid allow read execute" $d/acl-dir
85       chmod +a "user:root allow write execute" $d/acl-dir
86       chmod +a "user:nobody deny read write execute" $d/acl-dir
87       chmod +a "user:nobody deny read write execute" $d/bconsole
88       chmod +a "group:nogroup allow execute" $d/bconsole
89       cp ${cwd}/bin/bconsole $d/acl-dir
90       cp ${cwd}/bin/bconsole $d/other
91       xattr -w  bacula.test "rulez" $d/other 2>/dev/null 1>/dev/null
92
93       ( cd $cwd/build
94         ls -lde -R acl > $cwd/tmp/org
95         xattr -p bacula.test $d/other > $cwd/tmp/attr.org
96       )
97       ;;
98    SunOS)
99       #
100       # See if we need to set ZFS or POSIX acls
101       #
102       df -F zfs $d > /dev/null 2>&1
103       if [ $? = 0 ]; then
104          /bin/chmod A+user:$uid:rx:allow $d/acl-dir
105          /bin/chmod A+user:root:wx:allow $d/acl-dir
106          /bin/chmod A+user:nobody:rwx:deny $d/acl-dir
107          /bin/chmod A+user:nobody:rwx:deny $d/bconsole
108          /bin/chmod A+group:nogroup:x:allow $d/bconsole
109       else
110          /bin/chmod A+user:$uid:r-x $d/acl-dir
111          /bin/chmod A+user:root:-wx $d/acl-dir
112          /bin/chmod A+user:nobody:--- $d/acl-dir
113          /bin/chmod A+user:nobody:--- $d/bconsole
114          /bin/chmod A+group:nogroup:--x $d/bconsole
115       fi
116       cp ${cwd}/bin/bconsole $d/other
117       /bin/runat $d/other 'cat > bacula.test' << EOF
118 rulez
119 EOF
120       ( cd $cwd/build
121         /bin/ls -ldv -R acl > $cwd/tmp/org
122         /bin/runat $d/other 'cat bacula.test' > $cwd/tmp/attr.org
123       )
124       ;;
125 esac
126
127 change_jobname BackupClient1 $JobName
128 start_test
129
130 cat <<END_OF_DATA >${cwd}/tmp/bconcmds
131 @$out /dev/null
132 messages
133 @$out ${cwd}/tmp/log1.out
134 label volume=TestVolume001 storage=File pool=File
135 setdebug level=400 trace=1 client
136 setdebug level=300 trace=1 director
137 setdebug level=300 trace=1 storage
138 run job=$JobName yes
139 wait
140 messages
141 @# 
142 @# now do a restore
143 @#
144 @$out ${cwd}/tmp/log2.out  
145 restore where=${cwd}/tmp/bacula-restores select all done
146 yes
147 wait
148 messages
149 quit
150 END_OF_DATA
151
152 run_bacula
153 check_for_zombie_jobs storage=File
154 stop_bacula
155
156 case `uname -s` in
157    Linux)
158       ( cd $cwd/tmp/bacula-restores/$cwd/build
159         getfacl -R acl > $cwd/tmp/new
160         attr -g bacula.test $d/other > $cwd/tmp/attr.new
161       )
162       ;;
163    Darwin)
164       ( cd $cwd/tmp/bacula-restores/$cwd/build
165         ls -lde -R acl > $cwd/tmp/new
166         xattr -p bacula.test $d/other > $cwd/tmp/attr.new
167       )
168       ;;
169    SunOS)
170       ( cd $cwd/tmp/bacula-restores/$cwd/build
171         /bin/ls -ldv -R acl > $cwd/tmp/new
172         /bin/runat $d/other 'cat bacula.test' > $cwd/tmp/attr.new
173       )
174       ;;
175 esac
176
177 diff -u $cwd/tmp/org $cwd/tmp/new
178 if [ $? -ne 0 ]; then
179    rstat=1
180 fi
181
182 diff $cwd/tmp/attr.org $cwd/tmp/attr.new
183 if [ $? -ne 0 ]; then
184    rstat=1
185 fi
186
187 check_two_logs
188 check_restore_diff
189
190 if [ x$REGRESS_DEBUG != x ]; then
191   rm -rf $d
192 fi
193
194 end_test