3 # Check smbclient can (or cannot) delete a directory containing dangling symlinks.
4 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=14879
9 Usage: $0 SERVER SERVER_IP USERNAME PASSWORD SHAREPATH SMBCLIENT
21 SMBCLIENT
="$VALGRIND ${SMBCLIENT}"
24 incdir
=$
(dirname "$0")/..
/..
/..
/testprogs
/blackbox
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"
51 local cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT //$SERVER/delete_veto_files_only -U$USERNAME%$PASSWORD $ADDARGS < $tmpfile 2>&1'
56 # Check for smbclient error.
57 if [ $ret != 0 ]; then
58 echo "Failed accessing share delete_veto_files_only - $ret"
63 # We should NOT see the dangling symlink file.
64 echo "$out" |
grep bad_link
66 if [ $ret -eq 0 ]; then
67 echo "Saw dangling symlink bad_link in share delete_veto_files_only"
72 # Try and remove the directory, should succeed.
78 local cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT //$SERVER/delete_veto_files_only -U$USERNAME%$PASSWORD $ADDARGS < $tmpfile 2>&1'
83 # Check for smbclient error.
84 if [ $ret != 0 ]; then
85 echo "Failed accessing share delete_veto_files_only - $ret"
90 # We should get no NT_STATUS_ errors.
91 echo "$out" |
grep NT_STATUS_
93 if [ $ret -eq 0 ]; then
94 echo "Got error NT_STATUS_ in share delete_veto_files_only"
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
122 local cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT //$SERVER/veto_files_nodelete -U$USERNAME%$PASSWORD $ADDARGS < $tmpfile 2>&1'
127 # Check for smbclient error.
128 if [ $ret != 0 ]; then
129 echo "Failed accessing share veto_files_nodelete - $ret"
134 # We should NOT see the dangling symlink file.
135 echo "$out" |
grep bad_link
137 if [ $ret -eq 0 ]; then
138 echo "Saw dangling symlink bad_link in share veto_files_nodelete"
143 # Try and remove the directory, should fail with DIRECTORY_NOT_EMPTY.
144 cat >"$tmpfile" <<EOF
149 local cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT //$SERVER/veto_files_nodelete -U$USERNAME%$PASSWORD $ADDARGS < $tmpfile 2>&1'
154 # Check for smbclient error.
155 if [ $ret != 0 ]; then
156 echo "Failed accessing share veto_files_nodelete - $ret"
161 # We should get NT_STATUS_DIRECTORY_NOT_EMPTY errors.
162 echo "$out" |
grep NT_STATUS_DIRECTORY_NOT_EMPTY
164 if [ $ret -ne 0 ]; then
165 echo "Should get NT_STATUS_DIRECTORY_NOT_EMPTY in share veto_files_nodelete"
173 testit
"rmdir can delete directory containing dangling symlink" \
174 test_dangle_symlink_delete_veto_rmdir || failed
=$
(expr "$failed" + 1)
178 testit
"rmdir cannot delete directory delete_veto_files_no containing dangling symlink" \
179 test_dangle_symlink_veto_files_nodelete || failed
=$
(expr "$failed" + 1)