tombstones-expunge: Add a test for deleting links to recycled objects
[Samba.git] / source3 / script / tests / test_dfree_quota.sh
blob6e227c4b5ad8ff191b201d9444f3f89e0cd01679
1 #!/bin/sh
3 # Blackbox test for disk-free, quota, and their interaction
6 if [ $# -lt 6 ]; then
7 cat <<EOF
8 Usage: test_dfree_quota.sh SERVER DOMAIN USERNAME PASSWORD LOCAL_PATH SMBCLIENT SMBCQUOTAS SMBCACLS
9 EOF
10 exit 1;
13 SERVER=$1
14 DOMAIN=$2
15 USERNAME=$3
16 PASSWORD=$4
17 ENVDIR=`dirname $5`
18 WORKDIR=$5/dfree
19 smbclient=$6
20 smbcquotas=$7
21 smbcacls=$8
22 shift 8
23 failed=0
25 CONFFILE=$ENVDIR/lib/dfq.conf
27 incdir=`dirname $0`/../../../testprogs/blackbox
28 . $incdir/subunit.sh
30 sighup_smbd() {
31 kill -HUP -`cat $ENVDIR/pid/smbd.pid`
34 conf_lines() {
35 local uid
36 local gid
37 uid=$(id -u $USERNAME)
38 gid=$(id -g $USERNAME)
39 uid1=$(id -u user1)
40 uid2=$(id -u user2)
41 cat <<ABC
42 conf1:df:block size = 512:disk free = 10:disk size = 20
43 conf2:df:block size = 1024:disk free = 10:disk size = 20
44 conf3:df:block size = 4096:disk free = 750:disk size = 281474976710656
45 confq1:u$uid:block size = 4096:hard limit = 750:soft limit = 1000:cur blocks = 10
46 confdfq1:df:block size = 4096:disk free = 10:disk size = 20
47 confdfq1:u$uid:block size = 4096:hard limit = 750:soft limit = 1000:cur blocks = 10
48 confdfq2:df:block size = 4096:disk free = 10:disk size = 20
49 confdfq2:u$uid:block size = 4096:hard limit = 40:soft limit = 40:cur blocks = 37
50 confdfq3:df:block size = 4096:disk free = 10:disk size = 80
51 confdfq3:u$uid:block size = 4096:hard limit = 40:soft limit = 40:cur blocks = 0
52 confdfq4:df:block size = 4096:disk free = 10:disk size = 80
53 confdfq4:u$uid:block size = 4096:hard limit = 40:soft limit = 40:cur blocks = 37
54 slimit:df:block size = 4096:disk free = 10:disk size = 80
55 slimit:u$uid:block size = 4096:hard limit = 44:soft limit = 40:cur blocks = 42
56 hlimit:df:block size = 4096:disk free = 10:disk size = 80
57 hlimit:u$uid:block size = 4096:hard limit = 44:soft limit = 0:cur blocks = 45
58 islimit:df:block size = 4096:disk free = 10:disk size = 80
59 islimit:u$uid:block size = 4096:hard limit = 44:soft limit = 40:cur blocks = 37:inode soft limit = 30:inode hard limit = 35:cur inodes = 32
60 ihlimit:df:block size = 4096:disk free = 10:disk size = 80
61 ihlimit:u$uid:block size = 4096:hard limit = 44:soft limit = 40:cur blocks = 37:inode soft limit = 0:inode hard limit = 35:cur inodes = 36
62 trygrp1:df:block size = 4096:disk free = 10:disk size = 80
63 trygrp1:u$uid:block size = 4096:hard limit = 40:soft limit = 40:cur blocks = 41:err = 1
64 trygrp1:g$gid:block size = 4096:hard limit = 60:soft limit = 60:cur blocks = 55
65 trygrp2:df:block size = 4096:disk free = 10:disk size = 80
66 trygrp2:u$uid:block size = 4096:hard limit = 0:soft limit = 0:cur blocks = 41
67 trygrp2:g$gid:block size = 4096:hard limit = 60:soft limit = 60:cur blocks = 56
68 blksize:df:block size = 512:disk free = 614400:disk size = 614400
69 blksize:u$uid:block size = 1024:hard limit = 512000:soft limit = 0:cur blocks = 0
70 notenforce:df:block size = 4096:disk free = 10:disk size = 80
71 notenforce:u$uid:block size = 4096:hard limit = 40:soft limit = 40:cur blocks = 37
72 notenforce:udflt:block size = 4096:qflags = 0
73 nfs:df:block size = 4096:disk free = 10:disk size = 80
74 nfs:u$uid:block size = 4096:hard limit = 40:soft limit = 40:cur blocks = 37
75 nfs:udflt:nosys = 1
76 confdfqp:df:block size = 4096:disk free = 10:disk size = 80
77 confdfqp:u$uid1:block size = 4096:hard limit = 40:soft limit = 40:cur blocks = 36
78 confdfqp:u$uid2:block size = 4096:hard limit = 41:soft limit = 41:cur blocks = 36
79 ABC
82 setup_1_conf() {
83 conf_name="$1"
84 subdir="$2"
85 absdir=`readlink -f $WORKDIR/$subdir`
86 conf_lines | sed -rn "s/^$conf_name:(.*)/\1/p" | tr ":" "\n" | \
87 awk -F '=' -v atdir=$absdir 'NF==1 {section=$1} NF==2 {sub(/\s*$/, "", $1); printf "\tfake_dfq:%s/%s/%s =%s\n", section, $1, atdir, $2}'
90 setup_conf() {
91 rm $CONFFILE
92 touch $CONFFILE
94 until [ -z "$1" ]
96 setup_1_conf $1 $2 >> $CONFFILE
97 shift
98 shift
99 done
100 sighup_smbd
101 #let it load...
102 sleep .5
106 test_smbclient_dfree() {
107 name="$1"
108 share="$2"
109 dir="$3"
110 confs="$4"
111 expected="$5"
112 shift
113 shift
114 shift
115 shift
116 subunit_start_test "$name"
117 setup_conf $confs
118 output=$($VALGRIND $smbclient //$SERVER/$share -c "cd $dir; l" $@ 2>&1)
119 status=$?
120 if [ "$status" = "0" ]; then
121 received=$(echo "$output" | awk '/blocks of size/ {print $1, $5, $6}')
122 if [ "$expected" = "$received" ]; then
123 subunit_pass_test "$name"
124 else
125 echo "$output" | subunit_fail_test "$name"
127 else
128 echo "$output" | subunit_fail_test "$name"
130 return $status
133 test_smbcquotas() {
134 name="$1"
135 conf="$2"
136 user="$3"
137 expected="$4"
138 shift
139 shift
140 shift
141 shift
142 subunit_start_test "$name"
143 setup_conf "$conf" "."
144 output=$($VALGRIND $smbcquotas //$SERVER/dfq $@ 2>/dev/null | tr '\\' '/')
145 status=$?
146 if [ "$status" = "0" ]; then
147 received=$(echo "$output" | awk "/$SERVER\\/$user/ {printf \"%s%s%s\", \$3, \$4, \$5}")
148 if [ "$expected" = "$received" ]; then
149 subunit_pass_test "$name"
150 else
151 echo "$output" | subunit_fail_test "$name"
153 else
154 echo "$output" | subunit_fail_test "$name"
156 return $status
159 #basic disk-free tests
160 test_smbclient_dfree "Test dfree share root SMB3 no quota" dfq "." "conf1 ." "10 1024. 5" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
161 test_smbclient_dfree "Test dfree subdir SMB3 no quota" dfq "subdir1" "conf1 . conf2 subdir1" "20 1024. 10" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
162 test_smbclient_dfree "Test dfree subdir NT1 no quota" dfq "subdir1" "conf1 . conf2 subdir1" "10 1024. 5" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=NT1 || failed=`expr $failed + 1`
163 test_smbclient_dfree "Test large disk" dfq "." "conf3 ." "1125899906842624 1024. 3000" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
164 #basic quota test (SMB1 only)
165 test_smbcquotas "Test user quota" confq1 $USERNAME "40960/4096000/3072000" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=NT1 || failed=`expr $failed + 1`
167 #quota limit > disk size, remaining quota > disk free
168 test_smbclient_dfree "Test dfree share root df vs quota case 1" dfq "." "confdfq1 ." "80 1024. 40" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
169 #quota limit > disk size, remaining quota < disk free
170 test_smbclient_dfree "Test dfree share root df vs quota case 2" dfq "." "confdfq2 ." "80 1024. 12" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
171 #quota limit < disk size, remaining quota > disk free
172 test_smbclient_dfree "Test dfree share root df vs quota case 3" dfq "." "confdfq3 ." "160 1024. 40" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
173 #quota limit < disk size, remaining quota < disk free
174 test_smbclient_dfree "Test dfree share root df vs quota case 4" dfq "." "confdfq4 ." "160 1024. 12" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
175 test_smbclient_dfree "Test dfree subdir df vs quota case 4" dfq "subdir1" "confdfq4 subdir1" "160 1024. 12" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
177 #quota-->disk free special cases
178 test_smbclient_dfree "Test quota->dfree soft limit" dfq "subdir1" "slimit subdir1" "168 1024. 0" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
179 test_smbclient_dfree "Test quota->dfree hard limit" dfq "subdir1" "hlimit subdir1" "180 1024. 0" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
180 test_smbclient_dfree "Test quota->dfree inode soft limit" dfq "subdir1" "islimit subdir1" "148 1024. 0" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
181 test_smbclient_dfree "Test quota->dfree inode hard limit" dfq "subdir1" "ihlimit subdir1" "148 1024. 0" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
182 test_smbclient_dfree "Test quota->dfree err try group" dfq "subdir1" "trygrp1 subdir1" "240 1024. 20" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
183 test_smbclient_dfree "Test quota->dfree no-quota try group" dfq "subdir1" "trygrp2 subdir1" "240 1024. 16" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
185 #block size different in quota and df systems
186 test_smbclient_dfree "Test quota->dfree different block size" dfq "subdir1" "blksize subdir1" "307200 1024. 307200" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
188 #quota configured but not enforced
189 test_smbclient_dfree "Test dfree share root quota not enforced" dfq "." "notenforce ." "320 1024. 40" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
191 #FS quota not implemented (NFS case)
192 test_smbclient_dfree "Test dfree share root FS quota not implemented" dfq "." "nfs ." "160 1024. 12" -U$USERNAME%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
194 #test for dfree when owner is inherited
195 #setup two folders with different owners
196 rm -rf $WORKDIR/subdir3/*
197 for d in / subdir3
199 $VALGRIND $smbcacls -U$USERNAME%$PASSWORD -D "ACL:$SERVER\user1:ALLOWED/0x0/FULL" //$SERVER/dfq $d > /dev/null 2>&1
200 $VALGRIND $smbcacls -U$USERNAME%$PASSWORD -a "ACL:$SERVER\user1:ALLOWED/0x0/FULL" //$SERVER/dfq $d || failed=`expr $failed + 1`
201 $VALGRIND $smbcacls -U$USERNAME%$PASSWORD -D "ACL:$SERVER\user2:ALLOWED/0x0/FULL" //$SERVER/dfq $d > /dev/null 2>&1
202 $VALGRIND $smbcacls -U$USERNAME%$PASSWORD -a "ACL:$SERVER\user2:ALLOWED/0x0/FULL" //$SERVER/dfq $d || failed=`expr $failed + 1`
203 done
205 $VALGRIND $smbclient //$SERVER/dfq -c "cd subdir3; mkdir user1" -Uuser1%$PASSWORD --option=clientmaxprotocol=SMB3 > /dev/null 2>&1 || failed=`expr $failed + 1`
206 $VALGRIND $smbclient //$SERVER/dfq -c "cd subdir3; mkdir user2" -Uuser2%$PASSWORD --option=clientmaxprotocol=SMB3 > /dev/null 2>&1 || failed=`expr $failed + 1`
207 #test quotas
208 test_smbclient_dfree "Test dfree without inherit owner - user1 at user1" \
209 dfq "subdir3/user1" "confdfqp subdir3/user1 confdfqp subdir3/user2" "160 1024. 16" \
210 -Uuser1%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
211 test_smbclient_dfree "Test dfree without inherit owner - user1 at user2" \
212 dfq "subdir3/user2" "confdfqp subdir3/user1 confdfqp subdir3/user2" "160 1024. 16" \
213 -Uuser1%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
214 test_smbclient_dfree "Test dfree with inherit owner - user1 at user1" \
215 dfq_owner "subdir3/user1" "confdfqp subdir3/user1 confdfqp subdir3/user2" "160 1024. 16" \
216 -Uuser1%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
217 test_smbclient_dfree "Test dfree with inherit owner - user1 at user2" \
218 dfq_owner "subdir3/user2" "confdfqp subdir3/user1 confdfqp subdir3/user2" "164 1024. 20" \
219 -Uuser1%$PASSWORD --option=clientmaxprotocol=SMB3 || failed=`expr $failed + 1`
221 setup_conf
222 exit $failed