2006-03-23 14:55:38 +00:00
#!/bin/sh
# this runs the file serving tests that are expected to pass with samba3
2017-06-20 09:03:02 +02:00
if [ $# -lt 13 ] ; then
2022-04-22 15:34:11 +02:00
cat <<EOF
2017-06-20 09:03:02 +02:00
Usage: test_smbclient_s3.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD USERID LOCAL_PATH PREFIX SMBCLIENT WBINFO NET CONFIGURATION PROTOCOL
2006-03-23 14:55:38 +00:00
EOF
2022-04-22 15:34:11 +02:00
exit 1
2006-03-23 14:55:38 +00:00
fi
2011-09-13 15:19:46 +10:00
SERVER = " ${ 1 } "
SERVER_IP = " ${ 2 } "
DOMAIN = " ${ 3 } "
USERNAME = " ${ 4 } "
PASSWORD = " ${ 5 } "
USERID = " ${ 6 } "
LOCAL_PATH = " ${ 7 } "
PREFIX = " ${ 8 } "
SMBCLIENT = " ${ 9 } "
WBINFO = " ${ 10 } "
2012-10-29 14:49:36 -07:00
NET = " ${ 11 } "
2017-06-20 09:03:02 +02:00
CONFIGURATION = " ${ 12 } "
PROTOCOL = " ${ 13 } "
2011-04-15 16:39:53 +10:00
SMBCLIENT = " $VALGRIND ${ SMBCLIENT } "
2011-09-11 08:16:50 +10:00
WBINFO = " $VALGRIND ${ WBINFO } "
2017-06-20 09:03:02 +02:00
shift 13
RAWARGS = " ${ CONFIGURATION } -m ${ PROTOCOL } "
ADDARGS = " ${ RAWARGS } $* "
2006-03-23 14:55:38 +00:00
2022-04-22 15:34:11 +02:00
incdir = $( dirname $0 ) /../../../testprogs/blackbox
2011-02-19 00:32:06 +01:00
. $incdir /subunit.sh
2006-03-23 14:55:38 +00:00
2007-10-10 15:34:30 -05:00
failed = 0
2007-09-28 22:16:14 +00:00
2020-08-10 20:36:53 +12:00
# Do not let deprecated option warnings muck this up
SAMBA_DEPRECATED_SUPPRESS = 1
export SAMBA_DEPRECATED_SUPPRESS
2006-06-15 23:47:41 +00:00
# Test that a noninteractive smbclient does not prompt
test_noninteractive_no_prompt( )
{
2022-04-22 15:34:11 +02:00
prompt = "smb"
2006-06-15 23:47:41 +00:00
2022-04-22 15:34:11 +02:00
cmd = 'echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
2009-01-29 10:29:35 +01:00
2022-04-22 15:34:11 +02:00
if [ $? != 0 ] ; then
echo " $out "
echo "command failed"
return 1
fi
2009-01-29 10:29:35 +01:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep $prompt >/dev/null 2>& 1
2006-06-15 23:47:41 +00:00
2022-04-22 15:34:11 +02:00
if [ $? = 0 ] ; then
# got a prompt .. fail
echo matched interactive prompt in non-interactive mode
return 1
fi
2017-06-23 16:33:04 +02:00
2022-04-22 15:34:11 +02:00
return 0
2006-06-15 23:47:41 +00:00
}
# Test that an interactive smbclient prompts to stdout
test_interactive_prompt_stdout( )
{
2022-04-22 15:34:11 +02:00
prompt = "smb"
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
2006-06-15 23:47:41 +00:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2006-06-16 04:44:59 +00:00
du
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2009-01-29 10:29:35 +01:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo "command failed"
return 1
fi
2009-01-29 10:29:35 +01:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep $prompt >/dev/null 2>& 1
2006-06-15 23:47:41 +00:00
2022-04-22 15:34:11 +02:00
if [ $? != 0 ] ; then
echo failed to match interactive prompt on stdout
return 1
fi
2017-06-23 16:33:04 +02:00
2022-04-22 15:34:11 +02:00
return 0
2006-06-15 23:47:41 +00:00
}
2009-10-06 17:18:15 -07:00
# Test creating a bad symlink and deleting it.
test_bad_symlink( )
{
2022-04-22 15:34:11 +02:00
prompt = "posix_unlink deleted file /newname"
tmpfile = $PREFIX /smbclient_bad_symlinks_commands
2009-10-06 17:18:15 -07:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2009-10-06 17:18:15 -07:00
posix
2009-10-16 16:37:20 -07:00
posix_unlink newname
2009-10-06 17:18:15 -07:00
symlink badname newname
posix_unlink newname
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2009-10-06 17:18:15 -07:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed create then delete bad symlink with error $ret "
return 1
fi
2009-10-06 17:18:15 -07:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt " >/dev/null 2>& 1
2009-10-06 17:18:15 -07:00
2022-04-22 15:34:11 +02:00
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed create then delete bad symlink - grep failed with $ret "
return 1
fi
2017-06-23 16:33:04 +02:00
2022-04-22 15:34:11 +02:00
return 0
2009-10-06 17:18:15 -07:00
}
2010-03-10 14:40:20 -08:00
# Test creating a good symlink and deleting it by path.
test_good_symlink( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient.in.$$
slink_name = " $LOCAL_PATH /slink "
slink_target = " $LOCAL_PATH /slink_target "
2010-03-10 14:40:20 -08:00
2022-04-22 15:34:11 +02:00
touch $slink_target
ln -s $slink_target $slink_name
cat >$tmpfile <<EOF
2010-03-11 14:39:14 -08:00
del slink
2010-03-10 14:40:20 -08:00
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2010-03-10 14:40:20 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed delete good symlink with error $ret "
rm $slink_target
rm $slink_name
return 1
fi
if [ ! -e $slink_target ] ; then
echo "failed delete good symlink - symlink target deleted !"
rm $slink_target
rm $slink_name
return 1
fi
if [ -e $slink_name ] ; then
echo "failed delete good symlink - symlink still exists"
rm $slink_target
rm $slink_name
return 1
fi
2010-03-11 14:39:14 -08:00
rm $slink_target
2022-04-22 15:34:11 +02:00
return 0
2010-03-10 14:40:20 -08:00
}
2010-03-09 16:36:48 -08:00
# Test writing into a read-only directory (logon as guest) fails.
test_read_only_dir( )
{
2022-04-22 15:34:11 +02:00
prompt = "NT_STATUS_ACCESS_DENIED making remote directory"
tmpfile = $PREFIX /smbclient.in.$$
##
## We can't do this as non-root. We always have rights to
## create the directory.
##
if [ " $USERID " != 0 ] ; then
echo "skipping test_read_only_dir as non-root"
return 0
fi
##
## We can't do this with an encrypted connection. No credentials
## to set up the channel.
##
if [ " $ADDARGS " = "-e" ] ; then
echo "skipping test_read_only_dir with encrypted connection"
return 0
fi
cat >$tmpfile <<EOF
2010-03-09 16:36:48 -08:00
mkdir a_test_dir
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U% "//$SERVER/$1" -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2010-03-09 16:36:48 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed writing into read-only directory with error $ret "
2011-06-09 15:22:19 +10:00
2022-04-22 15:34:11 +02:00
return 1
fi
2010-03-09 16:36:48 -08:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt " >/dev/null 2>& 1
2010-03-09 16:36:48 -08:00
2022-04-22 15:34:11 +02:00
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed writing into read-only directory - grep failed with $ret "
return 1
fi
2017-06-23 16:33:04 +02:00
2022-04-22 15:34:11 +02:00
return 0
2010-03-09 16:36:48 -08:00
}
2011-06-09 15:22:19 +10:00
# Test sending a message
test_message( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /message_in.$$
2011-06-09 15:22:19 +10:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2011-06-09 15:22:19 +10:00
Test message from pid $$
EOF
2022-04-22 15:34:11 +02:00
cmd = '$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed sending message to $SERVER with error $ret "
rm -f $tmpfile
return 1
fi
# The server writes this into a file message.msgtest, via message.%m to test the % sub code
cmd = '$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmpguest -p 139 $ADDARGS -c "get message.msgtest $PREFIX/message_out.$$" 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed getting sent message from $SERVER with error $ret "
return 1
fi
2022-03-04 12:08:28 +01:00
if cmp $PREFIX /message_out.$$ $tmpfile ; then
2022-04-22 15:34:11 +02:00
echo " failed comparison of message from $SERVER "
return 1
fi
2011-06-09 15:22:19 +10:00
2022-04-22 15:34:11 +02:00
return 0
2011-06-09 15:22:19 +10:00
}
2010-03-09 16:36:48 -08:00
# Test reading an owner-only file (logon as guest) fails.
test_owner_only_file( )
{
2022-04-22 15:34:11 +02:00
prompt = "NT_STATUS_ACCESS_DENIED opening remote file"
tmpfile = $PREFIX /smbclient.in.$$
##
## We can't do this as non-root. We always have rights to
## read the file.
##
if [ " $USERID " != 0 ] ; then
echo "skipping test_owner_only_file as non-root"
return 0
fi
##
## We can't do this with an encrypted connection. No credentials
## to set up the channel.
##
if [ " $ADDARGS " = "-e" ] ; then
echo "skipping test_owner_only_file with encrypted connection"
return 0
fi
cat >$tmpfile <<EOF
2010-03-09 16:36:48 -08:00
get unreadable_file
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2010-03-09 16:36:48 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed reading owner-only file with error $ret "
return 1
fi
2010-03-09 16:36:48 -08:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt " >/dev/null 2>& 1
2010-03-09 16:36:48 -08:00
2022-04-22 15:34:11 +02:00
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed reading owner-only file - grep failed with $ret "
return 1
fi
2017-06-23 16:33:04 +02:00
2022-04-22 15:34:11 +02:00
return 0
2010-03-09 16:36:48 -08:00
}
2009-10-06 17:18:15 -07:00
2010-04-13 18:42:24 -07:00
# Test accessing an msdfs path.
test_msdfs_link( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient.in.$$
prompt = " msdfs-target "
2010-04-13 18:42:24 -07:00
2022-04-22 15:34:11 +02:00
cmd = '$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS -m $PROTOCOL -c dir 2>&1'
out = $( eval $cmd )
ret = $?
2017-04-07 16:33:57 +02:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing msfds-share\ with error $ret "
return 1
fi
2017-04-07 16:33:57 +02:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2010-04-13 18:42:24 -07:00
ls
cd \\ msdfs-src1
ls msdfs-target
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2010-04-13 18:42:24 -07:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing \\msdfs-src1 link with error $ret "
return 1
fi
2010-04-13 18:42:24 -07:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt " >/dev/null 2>& 1
2010-04-13 18:42:24 -07:00
2022-04-22 15:34:11 +02:00
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\msdfs-src1 - grep failed with $ret "
return 1
fi
2010-04-13 18:42:24 -07:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2010-04-13 18:42:24 -07:00
ls
cd \\ deeppath\\ msdfs-src2
ls msdfs-target
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2010-04-13 18:42:24 -07:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing \\deeppath\\msdfs-src2 link with error $ret "
return 1
fi
2010-04-13 18:42:24 -07:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt " >/dev/null 2>& 1
2010-04-13 18:42:24 -07:00
2022-04-22 15:34:11 +02:00
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\deeppath\\msdfs-src2 - grep failed with $ret "
return 1
fi
2017-06-23 16:33:04 +02:00
2022-04-22 15:34:11 +02:00
return 0
2010-04-13 18:42:24 -07:00
}
2020-10-27 10:12:51 +01:00
# Test recursive listing across msdfs links
test_msdfs_recursive_dir( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient.in.$$
2020-10-27 10:12:51 +01:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2020-10-27 10:12:51 +01:00
recurse
dir
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = '$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS -m $PROTOCOL < $tmpfile 2>&1'
out = $( eval $cmd )
ret = " $? "
2020-10-27 10:12:51 +01:00
2022-04-22 15:34:11 +02:00
if [ " $ret " -ne 0 ] ; then
echo " $out "
echo " failed listing msfds-share\ with error $ret "
return 1
fi
2020-10-27 10:12:51 +01:00
2022-07-14 19:47:23 +02:00
echo " $out " | grep 'NT_STATUS_OBJECT_PATH_NOT_FOUND listing \widelinks\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\dot\*' > /dev/null 2>& 1
2020-10-27 10:12:51 +01:00
2022-04-22 15:34:11 +02:00
ret = " $? "
2022-07-14 19:47:23 +02:00
if [ " $ret " -ne 0 ] ; then
echo " $out "
echo "Listing \\msdfs-share recursively did not properly end in symlink recursion"
2022-04-22 15:34:11 +02:00
fi
2020-10-27 10:12:51 +01:00
2022-04-22 15:34:11 +02:00
return 0
2020-10-27 10:12:51 +01:00
}
2022-02-03 14:21:26 -08:00
# Test doing a normal file rename on an msdfs path.
test_msdfs_rename( )
{
2022-04-22 15:34:11 +02:00
tmpfile = " $PREFIX /smbclient.in. $$ "
filename_src = " src. $$ "
filename_dst = " dest. $$ "
filename_src_path = " $PREFIX / $filename_src "
rm -f " $filename_src_path "
touch " $filename_src_path "
#
# Use both non-force and force rename to
# ensure we test both codepaths inside libsmb.
#
cat >$tmpfile <<EOF
2022-02-03 14:21:26 -08:00
lcd $PREFIX
put $filename_src
ren $filename_src $filename_dst -f
ren $filename_dst $filename_src
del $filename_src
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f " $tmpfile "
rm -f " $filename_src_path "
if [ $ret != 0 ] ; then
echo " $out "
echo " failed renaming $filename_src $filename_dst with error $ret "
return 1
fi
echo " $out " | grep "NT_STATUS" >/dev/null 2>& 1
ret = " $? "
if [ " $ret " -eq 0 ] ; then
echo " $out "
echo " renaming $filename_src $filename_dst got NT_STATUS_ error "
return 1
fi
return 0
2022-02-03 14:21:26 -08:00
}
2022-02-03 13:58:28 -08:00
# Test doing a normal file hardlink on an msdfs path.
test_msdfs_hardlink( )
{
2022-04-22 15:34:11 +02:00
tmpfile = " $PREFIX /smbclient.in. $$ "
filename_src = " src. $$ "
filename_dst = " dest. $$ "
filename_src_path = " $PREFIX / $filename_src "
rm -f " $filename_src_path "
touch " $filename_src_path "
cat >$tmpfile <<EOF
2022-02-03 13:58:28 -08:00
lcd $PREFIX
put $filename_src
hardlink $filename_src $filename_dst
del $filename_src
del $filename_dst
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f " $tmpfile "
rm -f " $filename_src_path "
if [ $ret != 0 ] ; then
echo " $out "
echo " failed hardlink $filename_src $filename_dst with error $ret "
return 1
fi
echo " $out " | grep "NT_STATUS" >/dev/null 2>& 1
ret = " $? "
if [ " $ret " -eq 0 ] ; then
echo " $out "
echo " hardlink $filename_src $filename_dst got NT_STATUS_ error "
return 1
fi
return 0
2022-02-03 13:58:28 -08:00
}
2022-06-17 10:25:49 +01:00
test_msdfs_del( )
{
tmpfile = " $PREFIX /smbclient.in. $$ "
filename_src = " src. $$ "
filename_src_path = " $PREFIX / $filename_src "
rm -f " $filename_src_path "
touch " $filename_src_path "
cat > $tmpfile <<EOF
lcd $PREFIX
cd dfshop1
cd dfshop2
put $filename_src
del $filename_src
quit
EOF
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f " $tmpfile "
rm -f " $filename_src_path "
if [ $ret != 0 ] ; then
echo " $out "
2023-07-17 15:03:58 +02:00
echo " failed deleting $filename_src with error $ret "
2022-06-17 10:25:49 +01:00
return 1
fi
echo " $out " | grep "NT_STATUS" >/dev/null 2>& 1
ret = " $? "
if [ " $ret " -eq 0 ] ; then
echo " $out "
echo " del $filename_src NT_STATUS_ error "
return 1
fi
return 0
}
2022-06-17 10:58:48 +01:00
test_msdfs_deltree( )
{
tmpfile = " $PREFIX /smbclient.in. $$ "
dirname_src = " foodir. $$ "
filename_src = " src. $$ "
filename_src_path = " $PREFIX / $filename_src "
dirname_src_path = " $PREFIX / $dirname "
rm -f " $filename_src_path "
touch " $filename_src_path "
cat > $tmpfile <<EOF
lcd $PREFIX
cd dfshop1
cd dfshop2
mkdir $dirname_src
cd $dirname_src
put $filename_src
cd ..
deltree $dirname_src
quit
EOF
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f " $tmpfile "
rm -f " $filename_src_path "
rm -f " $dirname_src_path "
if [ $ret != 0 ] ; then
echo " $out "
echo " deltree failed deleting dir $dirname_src with error $ret "
return 1
fi
echo " $out " | grep "NT_STATUS" >/dev/null 2>& 1
ret = " $? "
if [ " $ret " -eq 0 ] ; then
echo " $out "
echo " deltree $dirname_src NT_STATUS_ error "
return 1
fi
return 0
}
2013-01-24 12:33:53 -08:00
# Archive bits are correctly set on file/dir creation and rename.
test_rename_archive_bit( )
{
2022-04-22 15:34:11 +02:00
prompt_file = "attributes: A (20)"
prompt_dir = "attributes: D (10)"
tmpfile = " $PREFIX /smbclient.in. $$ "
filename = " foo. $$ "
filename_ren = " bar. $$ "
dirname = " foodir. $$ "
dirname_ren = " bardir. $$ "
filename_path = " $PREFIX / $filename "
local_name1 = " $LOCAL_PATH / $filename "
local_name2 = " $LOCAL_PATH / $filename_ren "
local_dir_name1 = " $LOCAL_PATH / $dirname "
local_dir_name2 = " $LOCAL_PATH / $dirname_ren "
rm -f $filename_path
rm -f $local_name1
rm -f $local_name2
# Create a new file, ensure it has 'A' attributes.
touch $filename_path
cat >$tmpfile <<EOF
2013-01-24 12:33:53 -08:00
lcd $PREFIX
put $filename
allinfo $filename
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed creating file $filename with error $ret "
return 1
fi
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt_file " >/dev/null 2>& 1
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
ret = $?
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
rm -f $filename_path
rm -f $local_name1
rm -f $local_name2
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " Attributes incorrect on new file $ret "
return 1
fi
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
# Now check if we remove 'A' and rename, the A comes back.
touch $filename_path
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2013-01-24 12:33:53 -08:00
lcd $PREFIX
put $filename
setmode $filename -a
ren $filename $filename_ren
allinfo $filename_ren
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed creating file and renaming $filename with error $ret "
return 1
fi
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt_file " >/dev/null 2>& 1
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
ret = $?
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
rm -f $filename_path
rm -f $local_name1
rm -f $local_name2
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " Attributes incorrect on renamed file $ret "
return 1
fi
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
rm -rf $local_dir_name1
rm -rf $local_dir_name2
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
# Create a new directory, ensure it has 'D' but not 'A' attributes.
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2013-01-24 12:33:53 -08:00
mkdir $dirname
allinfo $dirname
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed creating directory $dirname with error $ret "
return 1
fi
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt_dir " >/dev/null 2>& 1
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
ret = $?
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
rm -rf $local_dir_name1
rm -rf $local_dir_name2
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " Attributes incorrect on new directory $ret "
return 1
fi
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
# Now check if we rename, we still only have 'D' attributes
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2013-01-24 12:33:53 -08:00
mkdir $dirname
ren $dirname $dirname_ren
allinfo $dirname_ren
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed creating directory $dirname and renaming with error $ret "
return 1
fi
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
echo " $out " | grep " $prompt_dir " >/dev/null 2>& 1
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
ret = $?
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
rm -f $local_name1
rm -f $local_name2
2013-01-24 12:33:53 -08:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " Attributes incorrect on renamed directory $ret "
return 1
fi
2017-06-23 16:33:04 +02:00
2022-04-22 15:34:11 +02:00
return 0
2013-01-24 12:33:53 -08:00
}
2010-04-17 21:31:57 +02:00
# Test authenticating using the winbind ccache
test_ccache_access( )
{
2022-04-22 15:34:11 +02:00
$WBINFO --ccache-save= " ${ USERNAME } % ${ PASSWORD } "
ret = $?
2011-07-06 12:24:13 +02:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " wbinfo failed to store creds in cache (user=' ${ USERNAME } ', pass=' ${ PASSWORD } ') "
return 1
fi
2011-07-06 12:24:13 +02:00
2022-04-22 15:34:11 +02:00
$SMBCLIENT //$SERVER_IP /tmp --use-winbind-ccache -U " ${ USERNAME } " $ADDARGS -c quit 2>& 1
ret = $?
2010-04-17 21:31:57 +02:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo "smbclient failed to use cached credentials"
return 1
fi
2010-04-17 21:31:57 +02:00
2022-04-22 15:34:11 +02:00
$WBINFO --ccache-save= " ${ USERNAME } %GarBage "
ret = $?
2011-07-06 12:24:13 +02:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " wbinfo failed to store creds in cache (user=' ${ USERNAME } ', pass='GarBage') "
return 1
fi
2011-07-06 12:24:13 +02:00
2022-04-22 15:34:11 +02:00
$SMBCLIENT //$SERVER_IP /tmp --use-winbind-ccache -U " ${ USERNAME } " $ADDARGS -c quit 2>& 1
ret = $?
2010-04-17 21:31:57 +02:00
2022-04-22 15:34:11 +02:00
if [ $ret -eq 0 ] ; then
echo "smbclient succeeded with wrong cached credentials"
return 1
fi
2010-04-17 21:31:57 +02:00
2022-04-22 15:34:11 +02:00
$WBINFO --logoff
2010-04-17 21:31:57 +02:00
}
2011-06-09 16:20:15 +10:00
# Test authenticating using the winbind ccache
test_auth_file( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient.in.$$
cat >$tmpfile <<EOF
2011-06-09 16:20:15 +10:00
username = ${ USERNAME }
password = ${ PASSWORD }
domain = ${ DOMAIN }
EOF
2022-04-22 15:34:11 +02:00
$SMBCLIENT //$SERVER_IP /tmp --authentication-file= $tmpfile $ADDARGS -c quit 2>& 1
ret = $?
rm $tmpfile
2011-06-09 16:20:15 +10:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo "smbclient failed to use auth file"
return 1
fi
2011-06-09 16:20:15 +10:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2011-06-09 16:20:15 +10:00
username = ${ USERNAME }
password = xxxx
domain = ${ DOMAIN }
EOF
2022-04-22 15:34:11 +02:00
$SMBCLIENT //$SERVER_IP /tmp --authentication-file= $tmpfile $ADDARGS -c quit 2>& 1
ret = $?
rm $tmpfile
if [ $ret -eq 0 ] ; then
echo "smbclient succeeded with wrong auth file credentials"
return 1
fi
2011-06-09 16:20:15 +10:00
}
2012-10-29 14:49:36 -07:00
# Test doing a directory listing with backup privilege.
test_backup_privilege_list( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_backup_privilege_list
# selftest uses the forward slash as a separator, but "net sam rights
# grant" requires the backslash separator
USER_TMP = $( printf '%s' " $USERNAME " | tr '/' '\\' )
# If we don't have a DOMAIN component to the username, add it.
printf '%s' " $USER_TMP " | grep '\\' 2>& 1
ret = $?
if [ $ret != 0 ] ; then
priv_username = " $DOMAIN \\ $USER_TMP "
else
priv_username = " $USER_TMP "
fi
$NET sam rights grant $priv_username SeBackupPrivilege 2>& 1
ret = $?
if [ $ret != 0 ] ; then
echo " Failed to add SeBackupPrivilege to user $priv_username - $ret "
return 1
fi
cat >$tmpfile <<EOF
2012-10-29 14:49:36 -07:00
backup
ls
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed backup privilege list $ret "
return 1
fi
# Now remove all privileges from this SID.
$NET sam rights revoke $priv_username SeBackupPrivilege 2>& 1
ret = $?
if [ $ret != 0 ] ; then
echo " failed to remove SeBackupPrivilege from user $priv_username - $ret "
return 1
fi
2012-10-29 14:49:36 -07:00
}
2014-08-27 13:15:29 -07:00
# Test accessing an share with bad names (won't convert).
test_bad_names( )
{
2022-04-22 15:34:11 +02:00
# First with SMB1
if [ $PROTOCOL = "NT1" ] ; then
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP $ADDARGS -m$PROTOCOL -c ls 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing badname-tmp (SMB1) with error $ret "
return 1
fi
echo " $out " | wc -l 2>& 1 | grep 5
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - grep of number of lines (1) failed with $ret "
return 1
fi
echo " $out " | grep '^ \. *D'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - grep (1) failed with $ret "
return 1
fi
echo " $out " | grep '^ \.\. *D'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - grep (2) failed with $ret "
return 1
fi
echo " $out " | grep '^ blank.txt *N'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - grep (3) failed with $ret "
return 1
fi
echo " $out " | grep '^ *$'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - grep (4) failed with $ret "
return 1
fi
echo " $out " | grep 'blocks of size.*blocks available'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - grep (5) failed with $ret "
return 1
fi
fi
if [ $PROTOCOL = "SMB3" ] ; then
# Now check again with -mSMB3
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP $ADDARGS -m$PROTOCOL -c ls 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing badname-tmp (SMB3) with error $ret "
return 1
fi
echo " $out " | wc -l 2>& 1 | grep 5
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - SMB3 grep of number of lines (1) failed with $ret "
return 1
fi
echo " $out " | grep '^ \. *D'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - SMB3 grep (1) failed with $ret "
return 1
fi
echo " $out " | grep '^ \.\. *D'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - SMB3 grep (2) failed with $ret "
return 1
fi
echo " $out " | grep '^ blank.txt *N'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - SMB3 grep (3) failed with $ret "
return 1
fi
echo " $out " | grep '^ *$'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - SMB3 grep (4) failed with $ret "
return 1
fi
echo " $out " | grep 'blocks of size.*blocks available'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\badname-tmp - SMB3 grep (5) failed with $ret "
return 1
fi
fi
2014-08-27 13:15:29 -07:00
}
2013-01-24 12:33:53 -08:00
2015-05-01 21:08:21 -07:00
# Test accessing an share with a name that must be mangled - with acl_xattrs.
# We know foo:bar gets mangled to FF4GBY~Q with the default name-mangling algorithm (hash2).
test_mangled_names( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2015-05-01 21:08:21 -07:00
ls
cd FF4GBY~Q
ls
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/manglenames_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing manglenames_share with error $ret "
return 1
fi
echo " $out " | grep 'NT_STATUS'
ret = $?
if [ $ret = 0 ] ; then
echo " $out "
echo "failed - NT_STATUS_XXXX listing \\manglenames_share\\FF4GBY~Q"
return 1
fi
2015-05-01 21:08:21 -07:00
}
2015-07-13 14:15:45 -07:00
# Test using scopy to copy a file on the server.
test_scopy( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
scopy_file = $PREFIX /scopy_file
2015-07-13 14:15:45 -07:00
2022-04-22 15:34:11 +02:00
rm -f $scopy_file
cat >$tmpfile <<EOF
2015-07-13 14:15:45 -07:00
put ${ SMBCLIENT }
scopy smbclient scopy_file
lcd ${ PREFIX }
get scopy_file
del smbclient
del scopy_file
quit
EOF
2022-04-22 15:34:11 +02:00
if [ $PROTOCOL = "SMB3" ] ; then
# First SMB3
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -m$PROTOOCL < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
out1 = $( md5sum ${ SMBCLIENT } | sed -e 's/ .*//' )
out2 = $( md5sum ${ scopy_file } | sed -e 's/ .*//' )
rm -f $tmpfile
rm -f $scopy_file
if [ $ret != 0 ] ; then
echo " $out "
echo " failed scopy test (1) with output $ret "
return 1
fi
if [ $out1 != $out2 ] ; then
echo " $out1 $out2 "
echo "failed md5sum (1)"
return 1
fi
fi
#
# Now do again using SMB1
# to force client-side fallback.
#
if [ $PROTOCOL = "NT1" ] ; then
cat >$tmpfile <<EOF
2015-07-13 14:15:45 -07:00
put ${ SMBCLIENT }
scopy smbclient scopy_file
lcd ${ PREFIX }
get scopy_file
del smbclient
del scopy_file
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -m$PROTOCOL < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
out1 = $( md5sum ${ SMBCLIENT } | sed -e 's/ .*//' )
out2 = $( md5sum ${ scopy_file } | sed -e 's/ .*//' )
rm -f $tmpfile
rm -f $scopy_file
if [ $ret != 0 ] ; then
echo " $out "
echo " failed scopy test (2) with output $ret "
return 1
fi
if [ $out1 != $out2 ] ; then
echo " $out1 $out2 "
echo "failed md5sum (2)"
return 1
fi
fi
2015-07-13 14:15:45 -07:00
}
2023-07-17 15:03:58 +02:00
# Test creating a stream on the root of the share directory filename - :foobar
2015-09-16 16:12:15 -07:00
test_toplevel_stream( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2015-09-16 16:12:15 -07:00
put ${ PREFIX } /smbclient_interactive_prompt_commands :foobar
allinfo \\
setmode \\ -a
quit
EOF
2022-04-22 15:34:11 +02:00
# Only with SMB3???
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mSMB3 < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed creating toplevel stream :foobar with error $ret "
return 1
fi
echo " $out " | grep '^stream:.*:foobar'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo "failed creating toplevel stream :foobar"
return 1
fi
2015-09-16 16:12:15 -07:00
}
2015-07-09 13:57:58 -07:00
# Test wide links are restricted.
test_widelinks( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2015-07-09 13:57:58 -07:00
cd dot
ls
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/widelinks_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing widelinks_share with error $ret "
return 1
fi
echo " $out " | grep 'NT_STATUS'
ret = $?
if [ $ret = 0 ] ; then
echo " $out "
echo "failed - NT_STATUS_XXXX listing \\widelinks_share\\dot"
return 1
fi
cat >$tmpfile <<EOF
2015-07-09 13:57:58 -07:00
allinfo source
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/widelinks_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing widelinks_share with error $ret "
return 1
fi
# This should fail with NT_STATUS_OBJECT_NAME_NOT_FOUND
echo " $out " | grep 'NT_STATUS_OBJECT_NAME_NOT_FOUND'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo "failed - should get NT_STATUS_OBJECT_NAME_NOT_FOUND listing \\widelinks_share\\source"
return 1
fi
2015-07-09 13:57:58 -07:00
}
2015-05-01 21:08:21 -07:00
2016-10-19 16:33:52 -07:00
# Test creating then deleting a stream file doesn't leave a lost-XXXXX directory.
test_streams_depot_delete( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
rm -rf " $LOCAL_PATH /lost-* "
2016-10-19 16:33:52 -07:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2016-10-19 16:33:52 -07:00
put ${ PREFIX } /smbclient_interactive_prompt_commands foo:bar
del foo
ls lost*
quit
EOF
2022-04-22 15:34:11 +02:00
# This only works with SMB3?
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mSMB3 < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed creating then deleting foo:bar with error $ret "
return 1
fi
echo " $out " | grep 'NT_STATUS_NO_SUCH_FILE listing \\lost\*'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo "deleting foo:bar left lost-XXX directory"
rm -rf " $LOCAL_PATH /lost-* "
return 1
fi
2016-10-19 16:33:52 -07:00
}
2017-03-27 11:48:25 -07:00
# Test follow symlinks can't access symlinks
test_nosymlinks( )
{
2022-04-22 15:34:11 +02:00
# Setup test dirs.
local_test_dir = " $LOCAL_PATH /nosymlinks/test "
local_slink_name = " $local_test_dir /source "
local_slink_target = " $local_test_dir /nosymlink_target_file "
2017-03-27 11:48:25 -07:00
2022-04-22 15:34:11 +02:00
share_test_dir = "test"
share_foo_dir = " $share_test_dir /foo "
share_foobar_dir = " $share_test_dir /foo/bar "
share_target_file = " $share_test_dir /foo/bar/testfile "
2017-04-04 11:07:36 +02:00
2022-04-22 15:34:11 +02:00
rm -rf $local_test_dir
2017-04-04 11:07:36 +02:00
2022-04-22 15:34:11 +02:00
local_nosymlink_target_file = "nosymlink_target_file"
echo " $local_slink_target " >$PREFIX /$local_nosymlink_target_file
2017-07-18 12:29:16 +02:00
2022-04-22 15:34:11 +02:00
local_foobar_target_file = "testfile"
echo " $share_target_file " >$PREFIX /$local_foobar_target_file
2017-07-18 12:29:16 +02:00
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2017-07-18 12:29:16 +02:00
mkdir $share_test_dir
mkdir $share_foo_dir
mkdir $share_foobar_dir
2020-11-19 17:10:02 +00:00
lcd $PREFIX
2017-07-18 12:29:16 +02:00
cd /$share_test_dir
put $local_nosymlink_target_file
cd /$share_foobar_dir
put $local_foobar_target_file
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
rm -f $PREFIX /$local_nosymlink_target_file
rm -f $PREFIX /$local_foobar_target_file
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed accessing local_symlinks with error $ret "
false
return
fi
echo " $out " | grep 'NT_STATUS_'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed - got an NT_STATUS error"
false
return
fi
# Create the symlink locally
ln -s $local_slink_target $local_slink_name
# Getting a file through a symlink name should fail.
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2017-04-04 11:07:36 +02:00
get test\\ source
2017-03-27 11:48:25 -07:00
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed accessing nosymlinks with error $ret "
return 1
fi
echo " $out " | grep 'NT_STATUS_OBJECT_NAME_NOT_FOUND'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo "failed - should get NT_STATUS_OBJECT_NAME_NOT_FOUND getting \\nosymlinks\\source"
return 1
fi
# But we should be able to create and delete directories.
cat >$tmpfile <<EOF
2017-04-04 11:07:36 +02:00
mkdir test\\ a
mkdir test\\ a\\ b
2017-03-27 11:48:25 -07:00
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed accessing nosymlinks with error $ret "
return 1
fi
echo " $out " | grep 'NT_STATUS'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed - NT_STATUS_XXXX doing mkdir a; mkdir a\\b on \\nosymlinks"
return 1
fi
# Ensure regular file/directory access also works.
cat >$tmpfile <<EOF
2017-04-04 11:07:36 +02:00
cd test\\ foo\\ bar
2017-03-27 22:10:29 -07:00
ls
get testfile -
quit
2017-07-18 12:29:16 +02:00
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed accessing nosymlinks with error $ret "
return 1
fi
echo " $out " | grep 'NT_STATUS'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed - NT_STATUS_XXXX doing cd foo\\bar; get testfile on \\nosymlinks"
return 1
fi
# CLEANUP
rm -f $local_slink_name
cat >$tmpfile <<EOF
2017-07-18 12:29:16 +02:00
deltree test
quit
2017-03-27 22:10:29 -07:00
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed accessing nosymlinks with error $ret "
return 1
fi
echo " $out " | grep 'NT_STATUS'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed - NT_STATUS_XXXX doing cd foo\\bar; get testfile on \\nosymlinks"
return 1
fi
2017-03-27 11:48:25 -07:00
}
2016-10-19 16:33:52 -07:00
2017-06-23 11:12:22 -07:00
# Test we can follow normal symlinks.
# Bug: https://bugzilla.samba.org/show_bug.cgi?id=12860
# Note - this needs to be tested over SMB3, not SMB1.
test_local_symlinks( )
{
2022-04-22 15:34:11 +02:00
# Setup test dirs.
LOCAL_RAWARGS = " ${ CONFIGURATION } -mSMB3 "
LOCAL_ADDARGS = " ${ LOCAL_RAWARGS } $* "
2017-06-23 11:12:22 -07:00
2022-04-22 15:34:11 +02:00
share_test_dir = "test"
share_slink_target_dir = " $share_test_dir /dir1 "
2017-06-23 11:12:22 -07:00
2022-04-22 15:34:11 +02:00
local_test_dir = " $LOCAL_PATH /local_symlinks/ $share_test_dir "
local_slink_name = " $local_test_dir /sym_name "
local_slink_target_dir = " $local_test_dir /dir1 "
2017-06-23 11:12:22 -07:00
2022-04-22 15:34:11 +02:00
rm -rf $local_test_dir
2017-06-23 11:12:22 -07:00
2022-04-22 15:34:11 +02:00
# Create the initial directories
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2017-07-18 12:03:32 +02:00
mkdir $share_test_dir
mkdir $share_slink_target_dir
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed accessing local_symlinks with error $ret "
false
return
fi
echo " $out " | grep 'NT_STATUS_'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed - got an NT_STATUS error"
false
return
fi
# Create the symlink locally
ln -s $local_slink_target_dir $local_slink_name
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo "failed - unable to create symlink"
ls -la $local_test_dir
false
return
fi
# Can we cd into the symlink name and ls ?
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2017-07-18 12:03:32 +02:00
cd $share_test_dir \\ sym_name
2017-06-23 11:12:22 -07:00
ls
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed accessing local_symlinks with error $ret "
false
return
fi
echo " $out " | grep 'NT_STATUS_'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed - got an NT_STATUS error"
false
return
fi
# CLEANUP
rm -f $local_slink_name
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2017-07-18 12:03:32 +02:00
deltree $share_test_dir
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed accessing local_symlinks with error $ret "
false
return
fi
echo " $out " | grep 'NT_STATUS_'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed - got an NT_STATUS error"
false
return
fi
2017-06-23 11:12:22 -07:00
}
2019-07-16 15:40:38 +02:00
#
# Regression test for CVE-2019-10197
# we should always get ACCESS_DENIED
#
test_noperm_share_regression( )
{
2022-04-22 15:34:11 +02:00
cmd = '$SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/noperm -I $SERVER_IP $LOCAL_ADDARGS -c "ls;ls" 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed accessing no perm share should not work"
return 1
fi
num = $( echo " $out " | grep 'NT_STATUS_ACCESS_DENIED' | wc -l)
if [ " $num " -ne "2" ] ; then
echo " $out "
echo " failed num[ $num ] - two NT_STATUS_ACCESS_DENIED lines expected "
return 1
fi
return 0
2019-07-16 15:40:38 +02:00
}
2017-07-06 10:52:45 -07:00
# Test smbclient deltree command
test_deltree( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
deltree_dir = $PREFIX /deltree_dir
2017-07-06 10:52:45 -07:00
2022-04-22 15:34:11 +02:00
rm -rf $deltree_dir
cat >$tmpfile <<EOF
2017-07-06 10:52:45 -07:00
mkdir deltree_dir
mkdir deltree_dir/foo
mkdir deltree_dir/foo/bar
put ${ SMBCLIENT } deltree_dir/foo/bar/client
deltree deltree_dir
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed deltree test with output $ret "
false
return
fi
echo " $out " | grep 'NT_STATUS_'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo "failed - got an NT_STATUS error"
false
return
fi
if [ -d $deltree_dir ] ; then
echo "deltree did not delete everything"
false
return
fi
2017-07-06 10:52:45 -07:00
}
2017-07-14 16:09:50 -07:00
# Test smbclient setmode command
test_setmode( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
2017-07-14 16:09:50 -07:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2017-07-14 16:09:50 -07:00
del test_setmode
put ${ SMBCLIENT } test_setmode
setmode test_setmode +r +s +h +a
allinfo test_setmode
setmode test_setmode -rsha
allinfo test_setmode
del test_setmode
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed setmode test with output $ret "
false
return
fi
echo " $out " | grep 'attributes: RHSA'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo "failed - should get attributes: RHSA"
false
return
fi
echo " $out " | grep 'attributes: (80)'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo "failed - should also get attributes: (80)"
false
return
fi
2017-07-14 16:09:50 -07:00
}
2017-10-18 13:54:22 -07:00
# Test smbclient utimes command
test_utimes( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
2017-10-18 13:54:22 -07:00
2022-04-22 15:34:11 +02:00
saved_TZ = " $TZ "
TZ = UTC
export TZ
saved_LANG = " $LANG "
LANG = C
export LANG
2017-12-04 17:13:43 -08:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2017-10-18 13:54:22 -07:00
del utimes_test
put ${ SMBCLIENT } utimes_test
allinfo utimes_test
2020-04-15 14:53:08 -07:00
utimes utimes_test 2016:02:04-06:19:20 17:01:01-05:10:20 -1 -1
2017-10-18 13:54:22 -07:00
allinfo utimes_test
del utimes_test
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ -n " $saved_TZ " ] ; then
export TZ = " $saved_TZ "
else
unset TZ
fi
if [ -n " $saved_LANG " ] ; then
export LANG = " $saved_LANG "
else
unset LANG
fi
if [ $ret != 0 ] ; then
echo " $out "
echo " failed utimes test with output $ret "
false
return
fi
# Now, we should have 2 identical write_time and change_time
# values, but one access_time of Jan 1 05:10:20 AM,
# and one create_time of Feb 04 06:19:20 AM 2016
out_sorted = $( echo " $out " | sort | uniq)
num_create = $( echo " $out_sorted " | grep -c 'create_time:' )
num_access = $( echo " $out_sorted " | grep -c 'access_time:' )
num_write = $( echo " $out_sorted " | grep -c 'write_time:' )
num_change = $( echo " $out_sorted " | grep -c 'change_time:' )
if [ " $num_create " != "2" ] ; then
echo " failed - should get two create_time $out "
false
return
fi
if [ " $num_access " != "2" ] ; then
echo " failed - should get two access_time $out "
false
return
fi
if [ " $num_write " != "1" ] ; then
echo " failed - should only get one write_time $out "
false
return
fi
if [ " $num_change " != "1" ] ; then
echo " failed - should only get one change_time $out "
false
return
fi
# This could be: Sun Jan 1 05:10:20 AM 2017
# or : Sun Jan 1 05:10:20 2017 CET
echo " $out " | grep 'access_time:.*Sun Jan.*1 05:10:20 .*2017.*'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo
echo "failed - should get access_time: Sun Jan 1 05:10:20 [AM] 2017"
false
return
fi
# This could be: Thu Feb 4 06:19:20 AM 2016
# or : Thu Feb 4 06:19:20 2016 CET
echo " $out " | grep 'create_time:.*Thu Feb.*4 06:19:20 .*2016.*'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo
echo "failed - should get access_time: Thu Feb 4 06:19:20 [AM] 2016"
false
return
fi
2017-10-18 13:54:22 -07:00
}
2017-10-23 15:40:04 -07:00
# Test smbclient renames with pathnames containing '..'
test_rename_dotdot( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
2017-10-23 15:40:04 -07:00
2022-04-22 15:34:11 +02:00
cat >$tmpfile <<EOF
2017-10-23 15:40:04 -07:00
deltree dotdot_test
mkdir dotdot_test
cd dotdot_test
mkdir dir1
mkdir dir2
cd dir1
put ${ SMBCLIENT } README
rename README ..\\ dir2\\ README
cd ..
cd dir2
allinfo README
cd \\
deltree dotdot_test
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed rename_dotdot test with output $ret "
false
return
fi
# We are allowed to get NT_STATUS_NO_SUCH_FILE listing \dotdot_test
# as the top level directory should not exist, but no other errors.
error_str = $( echo $out | grep NT_STATUS | grep -v "NT_STATUS_NO_SUCH_FILE listing .dotdot_test" )
if [ " $error_str " != "" ] ; then
echo " failed - unexpected NT_STATUS error in $out "
false
return
fi
2017-10-23 15:40:04 -07:00
}
2017-11-14 15:54:19 -08:00
# Test doing a volume command.
test_volume( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2017-11-14 15:54:19 -08:00
volume
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed doing volume command with error $ret "
return 1
fi
echo " $out " | grep '^Volume: |tmp| serial number'
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo "failed doing volume command"
return 1
fi
2017-11-14 15:54:19 -08:00
}
2017-07-14 16:09:50 -07:00
2017-06-06 17:54:18 +02:00
test_server_os_message( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2017-06-06 17:54:18 +02:00
ls
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed to connect error $ret "
return 1
fi
echo " $out " | grep 'Try "help" to get a list of possible commands.'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo 'failed - should get: Try "help" to get a list of possible commands.'
return 1
fi
return 0
2017-06-06 17:54:18 +02:00
}
2018-06-25 10:29:28 -04:00
test_server_quiet_message( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2018-06-25 10:29:28 -04:00
ls
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS --quiet < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " failed to connect error $ret "
return 1
fi
echo " $out " | grep 'Try "help" to get a list of possible commands.'
ret = $?
if [ $ret -eq 0 ] ; then
echo " $out "
echo 'failed - quiet should skip this message.'
return 1
fi
return 0
2018-06-25 10:29:28 -04:00
}
2018-04-11 10:33:22 -07:00
# Test xattr_stream correctly reports mode.
# BUG: https://bugzilla.samba.org/show_bug.cgi?id=13380
test_stream_directory_xattr( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
#
# Test against streams_xattr
#
cat >$tmpfile <<EOF
2018-04-11 10:33:22 -07:00
deltree foo
mkdir foo
put ${ PREFIX } /smbclient_interactive_prompt_commands foo:bar
setmode foo -a
allinfo foo:bar
deltree foo
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/streams_xattr -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
2018-04-11 10:33:22 -07:00
2022-04-22 15:34:11 +02:00
if [ $ret != 0 ] ; then
echo " $out "
echo " failed checking attributes on xattr stream foo:bar with error $ret "
return 1
fi
echo " $out " | grep "attributes:.*80"
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo "failed checking attributes on xattr stream foo:bar"
return 1
fi
#
# Test against streams_depot
#
cat >$tmpfile <<EOF
2018-04-11 10:33:22 -07:00
deltree foo
mkdir foo
put ${ PREFIX } /smbclient_interactive_prompt_commands foo:bar
setmode foo -a
allinfo foo:bar
deltree foo
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed checking attributes on depot stream foo:bar with error $ret "
return 1
fi
echo " $out " | grep "attributes:.*80"
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo "failed checking attributes on depot stream foo:bar"
return 1
fi
2018-04-11 10:33:22 -07:00
}
2018-08-09 10:02:26 -07:00
# Test smbclient non-empty rmdir command
test_del_nedir( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
del_nedir = " $LOCAL_PATH /del_nedir "
2018-08-09 10:02:26 -07:00
2022-04-22 15:34:11 +02:00
rm -rf $del_nedir
mkdir $del_nedir
touch $del_nedir /afile
cat >$tmpfile <<EOF
2018-08-09 10:02:26 -07:00
rmdir del_nedir
quit
EOF
2022-04-22 15:34:11 +02:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -rf $del_nedir
if [ $ret != 0 ] ; then
echo " $out "
echo " failed test_del_nedir test with output $ret "
false
return
fi
# Should get NT_STATUS_DIRECTORY_NOT_EMPTY error from rmdir
echo " $out " | grep 'NT_STATUS_DIRECTORY_NOT_EMPTY'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo "test_del_nedir failed - should get an NT_STATUS_DIRECTORY_NOT_EMPTY error"
false
return
fi
2018-08-09 10:02:26 -07:00
}
2020-10-19 16:20:04 +03:00
test_valid_users( )
{
2022-04-22 15:34:11 +02:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
cat >$tmpfile <<EOF
2020-10-19 16:20:04 +03:00
ls
quit
EOF
2022-04-22 15:34:11 +02:00
# User in "valid users" can login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$DC_USERNAME%$DC_PASSWORD //$SERVER/valid_users $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:valid_users 'User in 'valid users' can login to service' failed - $ret "
return 1
fi
# User from ad group in "valid users" can login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$DC_USERNAME%$DC_PASSWORD //$SERVER/valid_users_group $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:valid_users_group 'User from ad group in 'valid users' can login to service' failed - $ret "
return 1
fi
# User from UNIX group in "valid users" can login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$DC_USERNAME%$DC_PASSWORD //$SERVER/valid_users_unix_group $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:valid_users_unix_group 'User from UNIX group in 'valid users' can login to service' failed - $ret "
return 1
fi
# User not in NIS group in "valid users" can't login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$DC_USERNAME%$DC_PASSWORD //$SERVER/valid_users_nis_group $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
echo " $out " | grep 'NT_STATUS_ACCESS_DENIED'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:valid_users_nis_group 'User not in NIS group in 'valid users' can't login to service' failed - $ret "
return 1
fi
# Check user in UNIX, then in NIS group in "valid users" can login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$DC_USERNAME%$DC_PASSWORD //$SERVER/valid_users_unix_nis_group $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:valid_users_unix_nis_group 'Check user in UNIX, then in NIS group in 'valid users' can login to service' failed - $ret "
return 1
fi
# Check user in NIS, then in UNIX group in "valid users" can login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$DC_USERNAME%$DC_PASSWORD //$SERVER/valid_users_nis_unix_group $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:valid_users_nis_unix_group 'Check user in NIS, then in UNIX group in 'valid users' can login to service' failed - $ret "
return 1
fi
# User not in "invalid users" can login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -Ualice%Secret007 //$SERVER/invalid_users $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:invalid_users 'User not in 'invalid users' can login to service' failed - $ret "
return 1
fi
# User in "invalid users" can't login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$DC_USERNAME%$DC_PASSWORD //$SERVER/invalid_users $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
echo " $out " | grep 'NT_STATUS_ACCESS_DENIED'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:invalid_users 'User in 'invalid users' can't login to service' failed - $ret "
return 1
fi
# User is in "valid and invalid users" can't login to service
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$DC_USERNAME%$DC_PASSWORD //$SERVER/valid_and_invalid_users $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
echo " $out " | grep 'NT_STATUS_ACCESS_DENIED'
ret = $?
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:valid_and_invalid_users 'User is in 'valid and invalid users' can't login to service' failed - $ret "
return 1
fi
# 2 Users are in "valid users"
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -Ualice%Secret007 //$SERVER/valid_and_invalid_users $ADDARGS < $tmpfile 2>&1'
eval echo " $cmd "
out = $( eval $cmd )
ret = $?
rm -f $tmpfile
if [ $ret -ne 0 ] ; then
echo " $out "
echo " test_valid_users:valid_and_invalid_users '2 Users are in 'valid users'' failed - $ret "
return 1
fi
return 0
2020-10-19 16:20:04 +03:00
}
2022-05-23 20:11:13 +01:00
test_smbclient_minus_e_stderr( )
{
2022-04-22 15:34:11 +02:00
cmd = '$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -c ls'
eval echo " $cmd "
out = $( eval $cmd )
if [ $? != 0 ] ; then
echo " $out "
echo "command failed"
return 1
fi
# test smbclient 'ls' command output went to stdout
echo " $out " | grep "blocks available" >/dev/null 2>& 1
if [ $? != 0 ] ; then
# didn't get output to stdout
echo "expected output was NOT output to stdout"
return 1
fi
# this time execute ls but redirect stdout alone to /dev/null
cmd = '$SMBCLIENT -E "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -c "ls" 2>&1 > /dev/null'
eval echo " $cmd "
out = $( eval $cmd )
if [ $? != 0 ] ; then
echo " $out "
echo "command failed"
return 1
fi
# test smbclient 'ls' command output went to stderr
echo " $out " | grep "blocks available" >/dev/null 2>& 1
if [ $? != 0 ] ; then
# didn't get output to stderr
echo "expected output was NOT output to stderr"
return 1
fi
return 0
2022-05-23 20:11:13 +01:00
}
2018-08-09 10:02:26 -07:00
#
2018-04-11 10:33:22 -07:00
#
2011-02-21 12:48:48 +01:00
LOGDIR_PREFIX = test_smbclient_s3
2011-02-19 11:49:43 +01:00
2011-02-21 12:48:48 +01:00
# possibly remove old logdirs:
2011-02-19 11:49:43 +01:00
2022-04-22 15:34:11 +02:00
for OLDDIR in $( find ${ PREFIX } -type d -name " ${ LOGDIR_PREFIX } _* " ) ; do
2011-02-21 12:48:48 +01:00
echo " removing old directory ${ OLDDIR } "
rm -rf ${ OLDDIR }
done
2011-06-24 16:38:07 +02:00
LOGDIR = $( mktemp -d ${ PREFIX } /${ LOGDIR_PREFIX } _XXXXXX)
2011-02-19 11:49:43 +01:00
2022-04-22 15:34:11 +02:00
testit " smbclient -L $SERVER_IP " $SMBCLIENT -L $SERVER_IP -N -p 139 ${ RAWARGS } || failed = $( expr $failed + 1)
testit " smbclient -L $SERVER -I $SERVER_IP " $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 ${ RAWARGS } -c quit || failed = $( expr $failed + 1)
2006-06-15 23:47:41 +00:00
testit "noninteractive smbclient does not prompt" \
2022-04-22 15:34:11 +02:00
test_noninteractive_no_prompt ||
failed = $( expr $failed + 1)
2006-06-15 23:47:41 +00:00
testit "noninteractive smbclient -l does not prompt" \
2022-04-22 15:34:11 +02:00
test_noninteractive_no_prompt -l $LOGDIR ||
failed = $( expr $failed + 1)
2006-06-15 23:47:41 +00:00
2022-05-23 20:11:13 +01:00
testit "smbclient output goes to stderr when -E is passed" \
2022-04-22 15:34:11 +02:00
test_smbclient_minus_e_stderr ||
failed = $( expr $failed + 1)
2022-05-23 20:11:13 +01:00
2006-06-15 23:47:41 +00:00
testit "interactive smbclient prompts on stdout" \
2022-04-22 15:34:11 +02:00
test_interactive_prompt_stdout ||
failed = $( expr $failed + 1)
2006-06-15 23:47:41 +00:00
testit "interactive smbclient -l prompts on stdout" \
2022-04-22 15:34:11 +02:00
test_interactive_prompt_stdout -l $LOGDIR ||
failed = $( expr $failed + 1)
2006-03-23 14:55:38 +00:00
2009-10-06 17:18:15 -07:00
testit "creating a bad symlink and deleting it" \
2022-04-22 15:34:11 +02:00
test_bad_symlink ||
failed = $( expr $failed + 1)
2009-10-06 17:18:15 -07:00
2010-03-10 14:40:20 -08:00
testit "creating a good symlink and deleting it by path" \
2022-04-22 15:34:11 +02:00
test_good_symlink ||
failed = $( expr $failed + 1)
2010-03-10 14:40:20 -08:00
2010-03-09 16:36:48 -08:00
testit "writing into a read-only directory fails" \
2022-04-22 15:34:11 +02:00
test_read_only_dir ro-tmp ||
failed = $( expr $failed + 1)
2012-12-20 23:05:55 +11:00
testit "writing into a read-only share fails" \
2022-04-22 15:34:11 +02:00
test_read_only_dir valid-users-tmp ||
failed = $( expr $failed + 1)
2010-03-09 16:36:48 -08:00
testit "Reading a owner-only file fails" \
2022-04-22 15:34:11 +02:00
test_owner_only_file ||
failed = $( expr $failed + 1)
2010-03-09 16:36:48 -08:00
2010-04-13 18:42:24 -07:00
testit "Accessing an MS-DFS link" \
2022-04-22 15:34:11 +02:00
test_msdfs_link ||
failed = $( expr $failed + 1)
2010-04-13 18:42:24 -07:00
2020-10-27 10:12:51 +01:00
testit "Recursive ls across MS-DFS links" \
2022-04-22 15:34:11 +02:00
test_msdfs_recursive_dir ||
failed = $( expr $failed + 1)
2020-10-27 10:12:51 +01:00
2022-02-03 14:21:26 -08:00
testit "Rename on MS-DFS share" \
2022-04-22 15:34:11 +02:00
test_msdfs_rename ||
failed = $( expr $failed + 1)
2022-02-03 14:21:26 -08:00
2022-02-03 13:58:28 -08:00
testit "Hardlink on MS-DFS share" \
2022-04-22 15:34:11 +02:00
test_msdfs_hardlink ||
failed = $( expr $failed + 1)
2022-02-03 13:58:28 -08:00
2022-06-17 10:25:49 +01:00
testit "del on MS-DFS share" \
test_msdfs_del || \
failed = ` expr $failed + 1`
2022-06-17 10:58:48 +01:00
testit "deltree on MS-DFS share" \
test_msdfs_deltree || \
failed = ` expr $failed + 1`
2013-01-24 12:33:53 -08:00
testit "Ensure archive bit is set correctly on file/dir rename" \
2022-04-22 15:34:11 +02:00
test_rename_archive_bit ||
failed = $( expr $failed + 1)
2013-01-24 12:33:53 -08:00
2010-04-17 21:31:57 +02:00
testit "ccache access works for smbclient" \
2022-04-22 15:34:11 +02:00
test_ccache_access ||
failed = $( expr $failed + 1)
2010-04-17 21:31:57 +02:00
2011-06-09 15:22:19 +10:00
testit "sending a message to the remote server" \
2022-04-22 15:34:11 +02:00
test_message ||
failed = $( expr $failed + 1)
2011-06-09 15:22:19 +10:00
2011-06-09 16:20:15 +10:00
testit "using an authentication file" \
2022-04-22 15:34:11 +02:00
test_auth_file ||
failed = $( expr $failed + 1)
2011-06-09 16:20:15 +10:00
2012-10-29 14:49:36 -07:00
testit "list with backup privilege" \
2022-04-22 15:34:11 +02:00
test_backup_privilege_list ||
failed = $( expr $failed + 1)
2012-10-29 14:49:36 -07:00
2014-08-27 13:15:29 -07:00
testit "list a share with bad names (won't convert)" \
2022-04-22 15:34:11 +02:00
test_bad_names ||
failed = $( expr $failed + 1)
2014-08-27 13:15:29 -07:00
2015-05-01 21:08:21 -07:00
testit "list a share with a mangled name + acl_xattr object" \
2022-04-22 15:34:11 +02:00
test_mangled_names ||
failed = $( expr $failed + 1)
2015-05-01 21:08:21 -07:00
2015-07-13 14:15:45 -07:00
testit "server-side file copy" \
2022-04-22 15:34:11 +02:00
test_scopy ||
failed = $( expr $failed + 1)
2015-07-13 14:15:45 -07:00
2015-09-16 16:12:15 -07:00
testit "creating a :stream at root of share" \
2022-04-22 15:34:11 +02:00
test_toplevel_stream ||
failed = $( expr $failed + 1)
2015-09-16 16:12:15 -07:00
2015-07-09 13:57:58 -07:00
testit "Ensure widelinks are restricted" \
2022-04-22 15:34:11 +02:00
test_widelinks ||
failed = $( expr $failed + 1)
2015-07-09 13:57:58 -07:00
2016-10-19 16:33:52 -07:00
testit "streams_depot can delete correctly" \
2022-04-22 15:34:11 +02:00
test_streams_depot_delete ||
failed = $( expr $failed + 1)
2016-10-19 16:33:52 -07:00
2018-04-11 10:33:22 -07:00
testit "stream_xattr attributes" \
2022-04-22 15:34:11 +02:00
test_stream_directory_xattr ||
failed = $( expr $failed + 1)
2018-04-11 10:33:22 -07:00
2017-03-27 11:48:25 -07:00
testit "follow symlinks = no" \
2022-04-22 15:34:11 +02:00
test_nosymlinks ||
failed = $( expr $failed + 1)
2017-03-27 11:48:25 -07:00
2017-06-23 11:12:22 -07:00
testit "follow local symlinks" \
2022-04-22 15:34:11 +02:00
test_local_symlinks ||
failed = $( expr $failed + 1)
2017-06-23 11:12:22 -07:00
2019-07-16 15:40:38 +02:00
testit "noperm share regression" \
2022-04-22 15:34:11 +02:00
test_noperm_share_regression ||
failed = $( expr $failed + 1)
2019-07-16 15:40:38 +02:00
2017-07-06 10:52:45 -07:00
testit "smbclient deltree command" \
2022-04-22 15:34:11 +02:00
test_deltree ||
failed = $( expr $failed + 1)
2017-07-06 10:52:45 -07:00
2017-06-06 17:54:18 +02:00
testit "server os message" \
2022-04-22 15:34:11 +02:00
test_server_os_message ||
failed = $( expr $failed + 1)
2017-06-06 17:54:18 +02:00
2018-06-25 10:29:28 -04:00
testit "test server quiet message" \
2022-04-22 15:34:11 +02:00
test_server_quiet_message ||
failed = $( expr $failed + 1)
2018-06-25 10:29:28 -04:00
2017-07-14 16:09:50 -07:00
testit "setmode test" \
2022-04-22 15:34:11 +02:00
test_setmode ||
failed = $( expr $failed + 1)
2017-07-14 16:09:50 -07:00
2017-10-18 13:54:22 -07:00
testit "utimes" \
2022-04-22 15:34:11 +02:00
test_utimes ||
failed = $( expr $failed + 1)
2017-10-18 13:54:22 -07:00
2017-10-23 15:40:04 -07:00
testit "rename_dotdot" \
2022-04-22 15:34:11 +02:00
test_rename_dotdot ||
failed = $( expr $failed + 1)
2017-10-23 15:40:04 -07:00
2017-11-14 15:54:19 -08:00
testit "volume" \
2022-04-22 15:34:11 +02:00
test_volume ||
failed = $( expr $failed + 1)
2017-11-14 15:54:19 -08:00
2011-02-19 11:49:43 +01:00
testit " rm -rf $LOGDIR " \
2022-04-22 15:34:11 +02:00
rm -rf $LOGDIR ||
failed = $( expr $failed + 1)
2011-02-19 11:49:43 +01:00
2018-08-09 10:02:26 -07:00
testit "delete a non empty directory" \
2022-04-22 15:34:11 +02:00
test_del_nedir ||
failed = $( expr $failed + 1)
2018-08-09 10:02:26 -07:00
2020-10-19 16:20:04 +03:00
testit "valid users" \
2022-04-22 15:34:11 +02:00
test_valid_users ||
failed = $( expr $failed + 1)
2020-10-19 16:20:04 +03:00
2007-10-10 15:34:30 -05:00
testok $0 $failed