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