libnet: Fix Coverity ID 1634803 Dereference after null check
[samba4-gss.git] / source3 / script / tests / test_delete_veto_files_only_rmdir.sh
blob08f257ff8a6a150225110fb4a738a60233681b05
1 #!/bin/sh
3 # Check smbclient can (or cannot) delete a directory containing dangling symlinks.
4 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=14879
7 if [ $# -lt 6 ]; then
8 cat <<EOF
9 Usage: $0 SERVER SERVER_IP USERNAME PASSWORD SHAREPATH SMBCLIENT
10 EOF
11 exit 1
14 SERVER=${1}
15 SERVER_IP=${2}
16 USERNAME=${3}
17 PASSWORD=${4}
18 SHAREPATH=${5}
19 SMBCLIENT=${6}
20 shift 6
21 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
22 ADDARGS="$@"
24 incdir=$(dirname "$0")/../../../testprogs/blackbox
25 . $incdir/subunit.sh
27 failed=0
29 rmdir_path="$SHAREPATH/dir"
32 # Using the share "[delete_veto_files_only]" we CAN delete
33 # a directory containing only a dangling symlink.
35 test_dangle_symlink_delete_veto_rmdir()
37 local dangle_symlink_path="$rmdir_path/bad_link"
38 local tmpfile=$PREFIX/smbclient.in.$$
40 # Create rmdir directory.
41 mkdir -p "$rmdir_path"
42 # Create dangling symlink underneath.
43 ln -s "nowhere-foo" "$dangle_symlink_path"
45 cat >"$tmpfile" <<EOF
46 cd dir
48 quit
49 EOF
51 local cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT //$SERVER/delete_veto_files_only -U$USERNAME%$PASSWORD $ADDARGS < $tmpfile 2>&1'
52 eval echo "$cmd"
53 out=$(eval "$cmd")
54 ret=$?
56 # Check for smbclient error.
57 if [ $ret != 0 ]; then
58 echo "Failed accessing share delete_veto_files_only - $ret"
59 echo "$out"
60 return 1
63 # We should NOT see the dangling symlink file.
64 echo "$out" | grep bad_link
65 ret=$?
66 if [ $ret -eq 0 ]; then
67 echo "Saw dangling symlink bad_link in share delete_veto_files_only"
68 echo "$out"
69 return 1
72 # Try and remove the directory, should succeed.
73 cat >"$tmpfile" <<EOF
74 rd dir
75 quit
76 EOF
78 local cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT //$SERVER/delete_veto_files_only -U$USERNAME%$PASSWORD $ADDARGS < $tmpfile 2>&1'
79 eval echo "$cmd"
80 out=$(eval "$cmd")
81 ret=$?
83 # Check for smbclient error.
84 if [ $ret != 0 ]; then
85 echo "Failed accessing share delete_veto_files_only - $ret"
86 echo "$out"
87 return 1
90 # We should get no NT_STATUS_ errors.
91 echo "$out" | grep NT_STATUS_
92 ret=$?
93 if [ $ret -eq 0 ]; then
94 echo "Got error NT_STATUS_ in share delete_veto_files_only"
95 echo "$out"
96 return 1
99 return 0
103 # Using the share "[veto_files_nodelete]" we CANNOT delete
104 # a directory containing only a dangling symlink.
106 test_dangle_symlink_veto_files_nodelete()
108 local dangle_symlink_path="$rmdir_path/bad_link"
109 local tmpfile=$PREFIX/smbclient.in.$$
111 # Create rmdir directory.
112 mkdir -p "$rmdir_path"
113 # Create dangling symlink underneath.
114 ln -s "nowhere-foo" "$dangle_symlink_path"
116 cat >"$tmpfile" <<EOF
117 cd dir
119 quit
122 local cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT //$SERVER/veto_files_nodelete -U$USERNAME%$PASSWORD $ADDARGS < $tmpfile 2>&1'
123 eval echo "$cmd"
124 out=$(eval "$cmd")
125 ret=$?
127 # Check for smbclient error.
128 if [ $ret != 0 ]; then
129 echo "Failed accessing share veto_files_nodelete - $ret"
130 echo "$out"
131 return 1
134 # We should NOT see the dangling symlink file.
135 echo "$out" | grep bad_link
136 ret=$?
137 if [ $ret -eq 0 ]; then
138 echo "Saw dangling symlink bad_link in share veto_files_nodelete"
139 echo "$out"
140 return 1
143 # Try and remove the directory, should fail with DIRECTORY_NOT_EMPTY.
144 cat >"$tmpfile" <<EOF
145 rd dir
146 quit
149 local cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT //$SERVER/veto_files_nodelete -U$USERNAME%$PASSWORD $ADDARGS < $tmpfile 2>&1'
150 eval echo "$cmd"
151 out=$(eval "$cmd")
152 ret=$?
154 # Check for smbclient error.
155 if [ $ret != 0 ]; then
156 echo "Failed accessing share veto_files_nodelete - $ret"
157 echo "$out"
158 return 1
161 # We should get NT_STATUS_DIRECTORY_NOT_EMPTY errors.
162 echo "$out" | grep NT_STATUS_DIRECTORY_NOT_EMPTY
163 ret=$?
164 if [ $ret -ne 0 ]; then
165 echo "Should get NT_STATUS_DIRECTORY_NOT_EMPTY in share veto_files_nodelete"
166 echo "$out"
167 return 1
170 return 0
173 testit "rmdir can delete directory containing dangling symlink" \
174 test_dangle_symlink_delete_veto_rmdir || failed=$(expr "$failed" + 1)
176 rm -rf "$rmdir_path"
178 testit "rmdir cannot delete directory delete_veto_files_no containing dangling symlink" \
179 test_dangle_symlink_veto_files_nodelete || failed=$(expr "$failed" + 1)
181 rm -rf "$rmdir_path"
182 exit "$failed"