2006-03-23 14:55:38 +00:00
#!/bin/sh
# this runs the file serving tests that are expected to pass with samba3
2011-02-21 09:10:33 +11:00
if [ $# -lt 7 ] ; then
2006-03-23 14:55:38 +00:00
cat <<EOF
2011-06-09 16:20:15 +10:00
Usage: test_smbclient_s3.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD USERID LOCAL_PATH PREFIX SMBCLIENT
2006-03-23 14:55:38 +00:00
EOF
exit 1;
fi
SERVER = " $1 "
SERVER_IP = " $2 "
2011-06-09 16:20:15 +10:00
DOMAIN = " $3 "
USERNAME = " $4 "
PASSWORD = " $5 "
USERID = " $6 "
LOCAL_PATH = " $7 "
PREFIX = " $8 "
SMBCLIENT = " $9 "
2011-04-15 16:39:53 +10:00
SMBCLIENT = " $VALGRIND ${ SMBCLIENT } "
2010-04-17 21:31:57 +02:00
WBINFO = " $VALGRIND ${ WBINFO :- $BINDIR /wbinfo } "
2011-06-09 16:20:15 +10:00
shift 9
2008-01-04 16:58:23 -08:00
ADDARGS = " $* "
2006-03-23 14:55:38 +00:00
2011-02-19 00:32:06 +01:00
incdir = ` dirname $0 ` /../../../testprogs/blackbox
. $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
2006-06-15 23:47:41 +00:00
# Test that a noninteractive smbclient does not prompt
test_noninteractive_no_prompt( )
{
prompt = "smb"
2011-02-21 16:01:44 +11:00
cmd = 'echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
2009-01-29 10:29:35 +01:00
eval echo " $cmd "
out = ` eval $cmd `
if [ $? != 0 ] ; then
echo " $out "
echo "command failed"
false
return
fi
echo " $out " | grep $prompt >/dev/null 2>& 1
2006-06-15 23:47:41 +00:00
if [ $? = 0 ] ; then
# got a prompt .. fail
echo matched interactive prompt in non-interactive mode
false
else
true
fi
}
# Test that an interactive smbclient prompts to stdout
test_interactive_prompt_stdout( )
{
prompt = "smb"
2011-02-21 09:10:33 +11:00
tmpfile = $PREFIX /smbclient_interactive_prompt_commands
2006-06-15 23:47:41 +00:00
2006-06-16 04:44:59 +00:00
cat > $tmpfile <<EOF
du
quit
EOF
2011-02-21 16:01:44 +11:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
2009-01-29 10:29:35 +01:00
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo "command failed"
false
return
fi
echo " $out " | grep $prompt >/dev/null 2>& 1
2006-06-15 23:47:41 +00:00
if [ $? = 0 ] ; then
# got a prompt .. succeed
true
else
echo failed to match interactive prompt on stdout
false
fi
}
2009-10-06 17:18:15 -07:00
# Test creating a bad symlink and deleting it.
test_bad_symlink( )
{
prompt = "posix_unlink deleted file /newname"
2011-02-21 09:10:33 +11:00
tmpfile = $PREFIX /smbclient_bad_symlinks_commands
2009-10-06 17:18:15 -07:00
cat > $tmpfile <<EOF
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
2011-02-21 16:01:44 +11:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
2009-10-06 17:18:15 -07:00
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
2009-10-17 10:38:44 -07:00
echo " failed create then delete bad symlink with error $ret "
2009-10-06 17:18:15 -07:00
false
return
fi
2009-10-17 20:46:22 -07:00
echo " $out " | grep " $prompt " >/dev/null 2>& 1
2009-10-06 17:18:15 -07:00
2009-10-17 20:46:22 -07:00
ret = $?
if [ $ret = 0 ] ; then
2009-10-06 17:18:15 -07:00
# got the correct prompt .. succeed
true
else
2009-10-16 16:37:20 -07:00
echo " $out "
2009-10-17 20:46:22 -07:00
echo " failed create then delete bad symlink - grep failed with $ret "
2009-10-06 17:18:15 -07:00
false
fi
}
2010-03-10 14:40:20 -08:00
# Test creating a good symlink and deleting it by path.
test_good_symlink( )
{
2011-04-04 19:18:47 +10:00
tmpfile = $PREFIX /smbclient.in.$$
2010-03-11 14:39:14 -08:00
slink_name = " $LOCAL_PATH /slink "
slink_target = " $LOCAL_PATH /slink_target "
2010-03-10 14:40:20 -08:00
2010-03-11 14:39:14 -08:00
touch $slink_target
ln -s $slink_target $slink_name
2010-03-10 14:40:20 -08:00
cat > $tmpfile <<EOF
2010-03-11 14:39:14 -08:00
del slink
2010-03-10 14:40:20 -08:00
quit
EOF
2011-02-21 16:01:44 +11:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
2010-03-10 14:40:20 -08:00
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed delete good symlink with error $ret "
2010-03-11 14:39:14 -08:00
rm $slink_target
rm $slink_name
2010-03-10 14:40:20 -08:00
false
return
fi
2010-03-11 14:39:14 -08:00
if [ ! -e $slink_target ] ; then
echo "failed delete good symlink - symlink target deleted !"
rm $slink_target
rm $slink_name
false
return
fi
if [ -e $slink_name ] ; then
2010-03-10 14:40:20 -08:00
echo "failed delete good symlink - symlink still exists"
2010-03-11 14:39:14 -08:00
rm $slink_target
rm $slink_name
2010-03-10 14:40:20 -08:00
false
else
# got the correct prompt .. succeed
2010-03-11 14:39:14 -08:00
rm $slink_target
2010-03-10 14:40:20 -08:00
true
fi
}
2010-03-09 16:36:48 -08:00
# Test writing into a read-only directory (logon as guest) fails.
test_read_only_dir( )
{
prompt = "NT_STATUS_ACCESS_DENIED making remote directory"
2011-04-04 19:18:47 +10:00
tmpfile = $PREFIX /smbclient.in.$$
2010-03-09 16:36:48 -08:00
##
## We can't do this as non-root. We always have rights to
## create the directory.
##
2010-03-09 20:06:19 -08:00
if [ " $USERID " != 0 ] ; then
2010-03-09 16:36:48 -08:00
echo "skipping test_read_only_dir as non-root"
true
return
fi
##
## We can't do this with an encrypted connection. No credentials
## to set up the channel.
##
2010-03-09 20:06:19 -08:00
if [ " $ADDARGS " = "-e" ] ; then
2010-03-09 16:36:48 -08:00
echo "skipping test_read_only_dir with encrypted connection"
true
return
fi
cat > $tmpfile <<EOF
mkdir a_test_dir
quit
EOF
2011-02-21 16:01:44 +11:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
2010-03-09 16:36:48 -08:00
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed writing into read-only directory with error $ret "
2011-06-09 15:22:19 +10:00
2010-03-09 16:36:48 -08:00
false
return
fi
echo " $out " | grep " $prompt " >/dev/null 2>& 1
ret = $?
if [ $ret = 0 ] ; then
# got the correct prompt .. succeed
true
else
echo " $out "
echo " failed writing into read-only directory - grep failed with $ret "
false
fi
}
2011-06-09 15:22:19 +10:00
# Test sending a message
test_message( )
{
tmpfile = $PREFIX /message_in.$$
cat > $tmpfile <<EOF
Test message from pid $$
EOF
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 "
false
rm -f $tmpfile
return
fi
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 "
false
return
fi
if [ cmp $PREFIX /message_out.$$ $tmpfile != 0 ] ; then
echo " failed comparison of message from $SERVER "
false
return
fi
true
}
2010-03-09 16:36:48 -08:00
# Test reading an owner-only file (logon as guest) fails.
test_owner_only_file( )
{
prompt = "NT_STATUS_ACCESS_DENIED opening remote file"
2011-04-04 19:18:47 +10:00
tmpfile = $PREFIX /smbclient.in.$$
2010-03-09 16:36:48 -08:00
##
## We can't do this as non-root. We always have rights to
## read the file.
##
2010-03-09 20:06:19 -08:00
if [ " $USERID " != 0 ] ; then
2010-03-09 16:36:48 -08:00
echo "skipping test_owner_only_file as non-root"
true
return
fi
##
## We can't do this with an encrypted connection. No credentials
## to set up the channel.
##
2010-03-09 20:06:19 -08:00
if [ " $ADDARGS " = "-e" ] ; then
2010-03-09 16:36:48 -08:00
echo "skipping test_owner_only_file with encrypted connection"
true
return
fi
cat > $tmpfile <<EOF
get unreadable_file
quit
EOF
2011-02-21 16:01:44 +11:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
2010-03-09 16:36:48 -08:00
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed reading owner-only file with error $ret "
false
return
fi
echo " $out " | grep " $prompt " >/dev/null 2>& 1
ret = $?
if [ $ret = 0 ] ; then
# got the correct prompt .. succeed
true
else
echo " $out "
echo " failed reading owner-only file - grep failed with $ret "
false
fi
}
2009-10-06 17:18:15 -07:00
2010-04-13 18:42:24 -07:00
# Test accessing an msdfs path.
test_msdfs_link( )
{
2011-04-04 19:18:47 +10:00
tmpfile = $PREFIX /smbclient.in.$$
2010-04-13 18:42:24 -07:00
prompt = " msdfs-target "
cat > $tmpfile <<EOF
ls
cd \\ msdfs-src1
ls msdfs-target
quit
EOF
2011-02-21 16:01:44 +11:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
2010-04-13 18:42:24 -07:00
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing \\msdfs-src1 link with error $ret "
false
return
fi
echo " $out " | grep " $prompt " >/dev/null 2>& 1
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\msdfs-src1 - grep failed with $ret "
false
fi
cat > $tmpfile <<EOF
ls
cd \\ deeppath\\ msdfs-src2
ls msdfs-target
quit
EOF
2011-02-21 16:01:44 +11:00
cmd = 'CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
2010-04-13 18:42:24 -07:00
eval echo " $cmd "
out = ` eval $cmd `
ret = $?
rm -f $tmpfile
if [ $ret != 0 ] ; then
echo " $out "
echo " failed accessing \\deeppath\\msdfs-src2 link with error $ret "
false
return
fi
echo " $out " | grep " $prompt " >/dev/null 2>& 1
ret = $?
if [ $ret != 0 ] ; then
echo " $out "
echo " failed listing \\deeppath\\msdfs-src2 - grep failed with $ret "
false
return
else
true
return
fi
}
2010-04-17 21:31:57 +02:00
# Test authenticating using the winbind ccache
test_ccache_access( )
{
$WBINFO --ccache-save= " ${ USERNAME } % ${ PASSWORD } "
2011-02-21 16:01:44 +11:00
$SMBCLIENT //$SERVER_IP /tmp -C -U " ${ USERNAME } % " \
2010-04-17 21:31:57 +02:00
-c quit 2>& 1
ret = $?
if [ $ret != 0 ] ; then
echo "smbclient failed to use cached credentials"
false
return
fi
$WBINFO --ccache-save= " ${ USERNAME } %GarBage "
2011-02-21 16:01:44 +11:00
$SMBCLIENT //$SERVER_IP /tmp -C -U " ${ USERNAME } % " \
2010-04-17 21:31:57 +02:00
-c quit 2>& 1
ret = $?
2010-12-02 10:20:59 +01:00
if [ $ret -eq 0 ] ; then
2010-04-17 21:31:57 +02:00
echo "smbclient succeeded with wrong cached credentials"
false
return
fi
$WBINFO --logoff
}
2011-06-09 16:20:15 +10:00
# Test authenticating using the winbind ccache
test_auth_file( )
{
tmpfile = $PREFIX /smbclient.in.$$
cat > $tmpfile <<EOF
username = ${ USERNAME }
password = ${ PASSWORD }
domain = ${ DOMAIN }
EOF
$SMBCLIENT //$SERVER_IP /tmp --authentication-file= $tmpfile \
-c quit 2>& 1
ret = $?
rm $tmpfile
if [ $ret != 0 ] ; then
echo "smbclient failed to use auth file"
false
return
fi
cat > $tmpfile <<EOF
username = ${ USERNAME }
password = xxxx
domain = ${ DOMAIN }
EOF
$SMBCLIENT //$SERVER_IP /tmp --authentication-file= $tmpfile \
-c quit 2>& 1
ret = $?
rm $tmpfile
if [ $ret -eq 0 ] ; then
echo "smbclient succeeded with wrong auth file credentials"
false
return
fi
}
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
2011-02-21 12:48:48 +01:00
for OLDDIR in $( find ${ PREFIX } -type d -name " ${ LOGDIR_PREFIX } _* " ) ; do
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
2010-04-13 18:42:24 -07:00
2011-02-21 16:01:44 +11:00
testit " smbclient -L $SERVER_IP " $SMBCLIENT -L $SERVER_IP -N -p 139 || failed = ` expr $failed + 1`
testit " smbclient -L $SERVER -I $SERVER_IP " $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed = ` expr $failed + 1`
2006-06-15 23:47:41 +00:00
testit "noninteractive smbclient does not prompt" \
test_noninteractive_no_prompt || \
failed = ` expr $failed + 1`
testit "noninteractive smbclient -l does not prompt" \
2011-02-19 11:49:43 +01:00
test_noninteractive_no_prompt -l $LOGDIR || \
2006-06-15 23:47:41 +00:00
failed = ` expr $failed + 1`
testit "interactive smbclient prompts on stdout" \
test_interactive_prompt_stdout || \
failed = ` expr $failed + 1`
testit "interactive smbclient -l prompts on stdout" \
2011-02-19 11:49:43 +01:00
test_interactive_prompt_stdout -l $LOGDIR || \
2006-06-15 23:47:41 +00:00
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" \
test_bad_symlink || \
failed = ` expr $failed + 1`
2010-03-10 14:40:20 -08:00
testit "creating a good symlink and deleting it by path" \
test_good_symlink || \
failed = ` expr $failed + 1`
2010-03-09 16:36:48 -08:00
testit "writing into a read-only directory fails" \
test_read_only_dir || \
failed = ` expr $failed + 1`
testit "Reading a owner-only file fails" \
test_owner_only_file || \
failed = ` expr $failed + 1`
2010-04-13 18:42:24 -07:00
testit "Accessing an MS-DFS link" \
test_msdfs_link || \
failed = ` expr $failed + 1`
2010-04-17 21:31:57 +02:00
testit "ccache access works for smbclient" \
test_ccache_access || \
failed = ` expr $failed + 1`
2011-06-09 15:22:19 +10:00
testit "sending a message to the remote server" \
test_message || \
failed = ` expr $failed + 1`
2011-06-09 16:20:15 +10:00
testit "using an authentication file" \
test_auth_file || \
failed = ` expr $failed + 1`
2011-02-19 11:49:43 +01:00
testit " rm -rf $LOGDIR " \
rm -rf $LOGDIR || \
failed = ` expr $failed + 1`
2007-10-10 15:34:30 -05:00
testok $0 $failed