3 # Check smbclient cannot get a file that matches a veto files
4 # parameter, or inside a directory that matches a veto files
7 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=15143
12 Usage: $0 SERVER SERVER_IP USERNAME PASSWORD SHAREPATH SMBCLIENT
24 SMBCLIENT
="$VALGRIND ${SMBCLIENT}"
25 # Used by test_smbclient()
26 # shellcheck disable=2034
27 smbclient
="$VALGRIND ${SMBCLIENT}"
30 incdir
=$
(dirname "$0")/..
/..
/..
/testprogs
/blackbox
31 .
"$incdir"/subunit.sh
32 .
"${incdir}/common_test_fns.inc"
36 TMPDIR
=${PREFIX_ABS}/$
(basename "${0}")
37 mkdir
-p "${TMPDIR}" ||
exit 1
38 cd "${TMPDIR}" ||
exit 1
47 rm -rf "$SHAREPATH/dir1"
48 rm -rf "$SHAREPATH/veto_name_dir"
49 rm -rf "$SHAREPATH/veto_name_dir\"mangle"
50 rm -f "$SHAREPATH/veto_name_file"
51 rm -f "$SHAREPATH/veto_name_file\"mangle"
52 rm -f "${SHAREPATH}/regular_file"
53 rm -f "${SHAREPATH}/.hidden_file"
58 # smbclient function given path and expected error.
60 smbclient_get_expect_error
()
64 tmpfile
=${TMPDIR}/smbclient_interactive_prompt_commands
66 get $filename1 got_file
71 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/veto_files -I$SERVER_IP < $tmpfile 2>&1'
78 if [ $ret != 0 ]; then
80 printf "failed accessing veto_files share with error %s\n" "$ret"
84 if [ "$expected_error" = "NT_STATUS_OK" ]; then
85 printf "%s" "$out" |
grep "NT_STATUS_" |
wc -l |
grep '^0$'
87 printf "%s" "$out" |
grep "$expected_error"
90 if [ $ret != 0 ]; then
92 printf "failed - should get %s doing \"get %s got_file\"\n" "$expected_error" "$filename1"
97 smbclient_create_expect_error
()
101 tmpfile
=${TMPDIR}/smbclient_interactive_prompt_commands
102 cat >"$tmpfile" <<EOF
103 put $tmpfile $filename
107 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/veto_files -I$SERVER_IP < $tmpfile 2>&1'
112 rm -f "$SHAREPATH/$filename"
114 if [ $ret != 0 ]; then
116 printf "failed accessing veto_files share with error %s\n" "$ret"
120 if [ "$expected_error" = "NT_STATUS_OK" ]; then
121 printf "%s" "$out" |
grep -c "NT_STATUS_" && false
123 printf "%s" "$out" |
grep "$expected_error"
126 if [ $ret != 0 ]; then
128 printf "failed - should get %s doing \"put %s\"\n" "$expected_error" "$filename"
134 # Using the share "[veto_files]" ensure we
135 # cannot fetch a veto'd file or file in a veto'd directory.
140 smbclient_get_expect_error
"veto_name_file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
141 smbclient_get_expect_error
"veto_name_dir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
142 smbclient_get_expect_error
"veto_name_dir/testdir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
144 # toplevel mangle names
145 smbclient_get_expect_error
"VHXE5P~M" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
146 smbclient_get_expect_error
"VF5SKC~B/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
147 smbclient_get_expect_error
"VF5SKC~B/testdir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
150 smbclient_get_expect_error
"dir1/veto_name_file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
151 smbclient_get_expect_error
"dir1/veto_name_dir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
152 smbclient_get_expect_error
"dir1/veto_name_dir/testdir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
154 # depth1 mangle names
155 smbclient_get_expect_error
"dir1/VHXE5P~M" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
156 smbclient_get_expect_error
"dir1/VF5SKC~B/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
157 smbclient_get_expect_error
"dir1/VF5SKC~B/testdir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
160 smbclient_get_expect_error
"dir1/dir2/veto_name_file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
161 smbclient_get_expect_error
"dir1/dir2/veto_name_dir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
162 smbclient_get_expect_error
"dir1/dir2/veto_name_dir/testdir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
164 # depth2 mangle names
165 smbclient_get_expect_error
"dir1/dir2/VHXE5P~M" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
166 smbclient_get_expect_error
"dir1/dir2/VF5SKC~B/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
167 smbclient_get_expect_error
"dir1/dir2/VF5SKC~B/testdir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
170 smbclient_get_expect_error
"dir1/dir2/dir3/veto_name_file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
171 smbclient_get_expect_error
"dir1/dir2/dir3/veto_name_dir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
172 smbclient_get_expect_error
"dir1/dir2/dir3/veto_name_dir/testdir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
174 # depth3 mangle names
175 smbclient_get_expect_error
"dir1/dir2/dir3/VHXE5P~M" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
176 smbclient_get_expect_error
"dir1/dir2/dir3/VF5SKC~B/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
177 smbclient_get_expect_error
"dir1/dir2/dir3/VF5SKC~B/testdir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
182 test_create_veto_file
()
184 # Test creating files
185 smbclient_create_expect_error
"veto_name_file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
186 smbclient_create_expect_error
"veto_name_dir/file_inside_dir" "NT_STATUS_OBJECT_PATH_NOT_FOUND" ||
return 1
187 smbclient_create_expect_error
"dir1/veto_name_file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
195 smbclient_get_expect_error
"dir1/user1file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
196 smbclient_get_expect_error
"dir1/user2file" "NT_STATUS_OK" ||
return 1
197 smbclient_get_expect_error
"dir1/group1file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
198 smbclient_get_expect_error
"dir1/group2file" "NT_STATUS_OK" ||
return 1
201 smbclient_get_expect_error
"dir1/user1file" "NT_STATUS_OK" ||
return 1
202 smbclient_get_expect_error
"dir1/user2file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
203 smbclient_get_expect_error
"dir1/group1file" "NT_STATUS_OK" ||
return 1
204 smbclient_get_expect_error
"dir1/group2file" "NT_STATUS_OBJECT_NAME_NOT_FOUND" ||
return 1
211 echo "regular_file" > "${SHAREPATH}/regular_file"
212 echo "hidden_file" > "${SHAREPATH}/.hidden_file"
214 test_smbclient
"download regular file" \
215 "get regular_file" "//${SERVER}/veto_files_nohidden" \
216 -U"${USERNAME}%${PASSWORD}" ||
217 failed
=$
((failed
+ 1))
219 test_smbclient_expect_failure
"hidden file can't be downloaded" \
220 "get .hidden_file" "//${SERVER}/veto_files_nohidden" \
221 -U"${USERNAME}%${PASSWORD}" ||
222 failed
=$
((failed
+ 1))
223 test_smbclient
"list files" \
224 "ls" "//${SERVER}/veto_files_nohidden" \
225 -U"${USERNAME}%${PASSWORD}" ||
226 failed
=$
((failed
+ 1))
230 # Using hash2, veto_name_file\"mangle == VHXE5P~M
231 # Using hash2, veto_name_dir\"mangle == VF5SKC~B
233 # I think a depth of 3 should be enough.
235 touch "$SHAREPATH/veto_name_file"
236 mkdir
"$SHAREPATH/veto_name_dir"
237 touch "$SHAREPATH/veto_name_dir/file_inside_dir"
238 mkdir
"$SHAREPATH/veto_name_dir/testdir"
239 touch "$SHAREPATH/veto_name_dir/testdir/file_inside_dir"
240 # toplevel mangle names.
241 touch "$SHAREPATH/veto_name_file\"mangle"
242 mkdir
"$SHAREPATH/veto_name_dir\"mangle"
243 touch "$SHAREPATH/veto_name_dir\"mangle/file_inside_dir"
244 mkdir
"$SHAREPATH/veto_name_dir\"mangle/testdir"
245 touch "$SHAREPATH/veto_name_dir\"mangle/testdir/file_inside_dir"
248 mkdir
"$SHAREPATH/dir1"
249 touch "$SHAREPATH/dir1/veto_name_file"
250 mkdir
"$SHAREPATH/dir1/veto_name_dir"
251 touch "$SHAREPATH/dir1/veto_name_dir/file_inside_dir"
252 mkdir
"$SHAREPATH/dir1/veto_name_dir/testdir"
253 touch "$SHAREPATH/dir1/veto_name_dir/testdir/file_inside_dir"
254 # depth1 mangle names.
255 touch "$SHAREPATH/dir1/veto_name_file\"mangle"
256 mkdir
"$SHAREPATH/dir1/veto_name_dir\"mangle"
257 touch "$SHAREPATH/dir1/veto_name_dir\"mangle/file_inside_dir"
258 mkdir
"$SHAREPATH/dir1/veto_name_dir\"mangle/testdir"
259 touch "$SHAREPATH/dir1/veto_name_dir\"mangle/testdir/file_inside_dir"
262 mkdir
"$SHAREPATH/dir1/dir2"
263 touch "$SHAREPATH/dir1/dir2/veto_name_file"
264 mkdir
"$SHAREPATH/dir1/dir2/veto_name_dir"
265 touch "$SHAREPATH/dir1/dir2/veto_name_dir/file_inside_dir"
266 mkdir
"$SHAREPATH/dir1/dir2/veto_name_dir/testdir"
267 touch "$SHAREPATH/dir1/dir2/veto_name_dir/testdir/file_inside_dir"
268 # depth2 mangle names.
269 touch "$SHAREPATH/dir1/dir2/veto_name_file\"mangle"
270 mkdir
"$SHAREPATH/dir1/dir2/veto_name_dir\"mangle"
271 touch "$SHAREPATH/dir1/dir2/veto_name_dir\"mangle/file_inside_dir"
272 mkdir
"$SHAREPATH/dir1/dir2/veto_name_dir\"mangle/testdir"
273 touch "$SHAREPATH/dir1/dir2/veto_name_dir\"mangle/testdir/file_inside_dir"
276 mkdir
"$SHAREPATH/dir1/dir2/dir3"
277 touch "$SHAREPATH/dir1/dir2/dir3/veto_name_file"
278 mkdir
"$SHAREPATH/dir1/dir2/dir3/veto_name_dir"
279 touch "$SHAREPATH/dir1/dir2/dir3/veto_name_dir/file_inside_dir"
280 mkdir
"$SHAREPATH/dir1/dir2/dir3/veto_name_dir/testdir"
281 touch "$SHAREPATH/dir1/dir2/dir3/veto_name_dir/testdir/file_inside_dir"
282 # depth3 mangle names.
283 touch "$SHAREPATH/dir1/dir2/dir3/veto_name_file\"mangle"
284 mkdir
"$SHAREPATH/dir1/dir2/dir3/veto_name_dir\"mangle"
285 touch "$SHAREPATH/dir1/dir2/dir3/veto_name_dir\"mangle/file_inside_dir"
286 mkdir
"$SHAREPATH/dir1/dir2/dir3/veto_name_dir\"mangle/testdir"
287 touch "$SHAREPATH/dir1/dir2/dir3/veto_name_dir\"mangle/testdir/file_inside_dir"
289 # testfiles for per-user feature
290 touch "$SHAREPATH/dir1/user1file"
291 touch "$SHAREPATH/dir1/user2file"
292 touch "$SHAREPATH/dir1/group1file"
293 touch "$SHAREPATH/dir1/group2file"
295 testit
"create_veto_file" test_create_veto_file || failed
=$
((failed
+ 1))
296 testit
"get_veto_file" test_get_veto_file || failed
=$
(("$failed" + 1))
297 testit
"per-user" test_per_user || failed
=$
(("$failed" + 1))
301 cd "${PREFIX_ABS}" && rm -rf ${TMPDIR}