tests for smbclient, map to guest, various types of shares

Ben Gould ben at abduction.org
Wed Jun 25 15:51:04 GMT 2003


hi,

i had some time to look at the tests, and try various combinations of 
map to guest, different username, password & share (guest ok, guest 
only) configurations.  to test this it was necessary to add a flag to 
client/client.c which disables the fall-back to anonymous 
authentication.  (easier than finding "Anonymous login successful" in 
the output of smbclient)

you may want to add these to cvs and consider whether or not the option 
'guest only' is correctly implemented; it appears to allow 
authenticated users to connect to a guest-only share.

-- ben

changes - add -a (--no-anon) flag to smbclient to disable automatic 
guest logon on failure to authenticate.

cvs server: Diffing client
Index: client/client.c
===================================================================
RCS file: /cvsroot/samba/source/client/client.c,v
retrieving revision 1.209.2.26
diff -u -d -b -B -w -r1.209.2.26 client.c
--- client/client.c     11 Jun 2003 06:23:53 -0000      1.209.2.26
+++ client/client.c     25 Jun 2003 15:38:20 -0000
@@ -41,6 +41,7 @@
  static BOOL got_pass;
  static char *cmdstr = NULL;

+static BOOL no_anon = False;
  static int io_bufsize = 64512;

  static int name_type = 0x20;
@@ -2559,6 +2560,8 @@
                                password, strlen(password),
                                password, strlen(password),
                                lp_workgroup())) {
+         if (!no_anon)
+           {
                 /* if a password was not supplied then try again with a 
null username */
                 if (password[0] || !username[0] || use_kerberos ||
                     !cli_session_setup(c, "", "", 0, "", 0, 
lp_workgroup())) {
@@ -2568,6 +2571,13 @@
                 }
                 d_printf("Anonymous login successful\n");
         }
+         else
+           {
+             d_printf("Login failed, anonymous login disabled.\n");
+             cli_shutdown(c);
+             return NULL;
+           }
+       }

         if (*c->server_domain) {
                 DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
@@ -2749,12 +2759,14 @@
                 { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', 
"Execute semicolon separated commands" },
                 { "send-buffer", 'b', POPT_ARG_INT, &io_bufsize, 'b', 
"Changes the transmit/send buffer", "BYTES" },
                 { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to 
connect to", "PORT" },
+               { "no-anon", 'a', POPT_ARG_NONE, NULL, 'a', "Disable 
fallback to anonymous connections", "NO-ANON" },
                 POPT_COMMON_SAMBA
                 POPT_COMMON_CONNECTION
                 POPT_COMMON_CREDENTIALS
                 POPT_TABLEEND
         };

+       no_anon = False;

  #ifdef KANJI
         pstrcpy(term_code, KANJI);
@@ -2821,6 +2833,9 @@
                 case 'D':
                         fstrcpy(base_directory,poptGetOptArg(pc));
                         break;
+               case 'a':
+                 no_anon=True;
+                 break;
                 }
         }


configuration changes for the tests, added "guest_user" environment 
variable

Index: build_farm/basicsmb.fns
===================================================================
RCS file: /cvsroot/samba/testsuite/build_farm/basicsmb.fns,v
retrieving revision 1.19.2.5
diff -u -d -b -B -w -r1.19.2.5 basicsmb.fns
--- build_farm/basicsmb.fns	4 May 2003 00:55:52 -0000	1.19.2.5
+++ build_farm/basicsmb.fns	25 Jun 2003 15:41:11 -0000
@@ -26,7 +26,8 @@
                sed "s|PREFIX|$prefix|g" | \
  	      sed "s|BUILD_FARM|$test_root|g" | \
  	      sed "s|WHOAMI|$whoami|g" | \
-	      sed "s|LOGLEVEL|$loglevel|g" \
+	      sed "s|LOGLEVEL|$loglevel|g" | \
+	      sed "s|GUESTUSER|$guest_user|g" \
          > $prefix/$2
  	echo "template_setup: Created $prefix/$2"
  }
@@ -41,6 +42,7 @@
      echo "    BUILD_FARM=$test_root"
      echo "    WHOAMI=$whoami"
      echo "    LOGLEVEL=$loglevel"
+    echo "    GUESTUSER=$guest_user"
      echo "    TREE=$tree"

      case "$prefix" in
@@ -68,6 +70,10 @@
      template_smb_conf_setup .server
      template_smb_conf_setup .domain

+    template_smb_conf_setup .m2g_never
+    template_smb_conf_setup .m2g_baduser
+    template_smb_conf_setup .m2g_badpass
+
      template_setup preexec lib/preexec

      touch $prefix/lib/smb.conf.
@@ -85,17 +91,19 @@
      echo "127.0.0.7    PREEXEC">>$prefix/lib/lmhosts
      echo "127.0.0.7    PREEXEC_CLOSE">>$prefix/lib/lmhosts
      echo "127.0.0.7    PREEXEC_CL_FL">>$prefix/lib/lmhosts
-
+	echo "127.0.0.7    M2G_NEVER">>$prefix/lib/lmhosts
+	echo "127.0.0.7    M2G_BADUSER">>$prefix/lib/lmhosts
+	echo "127.0.0.7    M2G_BADPASS">>$prefix/lib/lmhosts

  	echo "127.0.0.1" > $prefix/lib/hosts.equiv

  }

-test_smbpasswd() {
-	test_smbpasswd_password="$1"
-	rm -f $prefix/private/smbpasswd
-	echo "( echo $test_smbpasswd_password ; echo 
$test_smbpasswd_password; ) | $prefix/bin/smbpasswd -L -s -a $whoami"
-	( echo $test_smbpasswd_password; echo $test_smbpasswd_password; ) | 
$prefix/bin/smbpasswd -L -s -a $whoami
+test_smbpasswd_user() {
+	test_smbpasswd_user="$1"
+	test_smbpasswd_password="$2"
+	echo "( echo $test_smbpasswd_password ; echo 
$test_smbpasswd_password; ) | $prefix/bin/smbpasswd -L -s -a 
$test_smbpasswd_user"
+	( echo $test_smbpasswd_password; echo $test_smbpasswd_password; ) | 
$prefix/bin/smbpasswd -L -s -a $test_smbpasswd_user
  	status=$?
  	if [ $status = 0 ]; then
  	    echo "smbpasswd correctly set initial password 
($test_smbpasswd_password)"
@@ -106,6 +114,12 @@
  	return 0
  }

+test_smbpasswd() {
+    rm -f $prefix/private/smbpasswd
+    ( test_smbpasswd_user $whoami "$1" || return 1)
+    return 0
+}
+
  test_smbpasswd_remote() {
  	test_smbpasswd_rem_password="$1"
  	test_smbpasswd_rem_newpassword="$2"
@@ -159,6 +173,35 @@
  		return 1
  	else
  		echo "listing files with smbd failed with status $status (correct)"
+	fi
+	return 0
+}
+
+test_listfiles_nofallback() {
+	remote_name="$1"
+	remote_share="$2"
+	remote_username="$3"
+	test_for_correct="$4"
+	
+	echo $prefix/bin/smbclient //$remote_name/$remote_share -a -n 
buildclient -U$remote_username  -c 'ls'
+	$prefix/bin/smbclient //$remote_name/$remote_share -a -n buildclient 
-U$remote_username -c 'ls'
+	status=$?
+	if [ $test_for_correct == 0 ]; then
+	    if [ $status = 0 ]; then
+		echo "listed files OK (correct)"
+		return 0
+	    else
+		echo "listing files with smbd failed with status $status (FAILURE)"
+		return 1
+	    fi
+	else
+	    if [ $status = 0 ]; then
+		echo "listed files OK (FAILURE)"
+		return 1
+	    else
+		echo "listing files with smbd failed with status $status (correct)"
+		return 0
+	    fi
  	fi
  	return 0
  }

Index: build_farm/template/basicsmb.smb.conf
===================================================================
RCS file: 
/cvsroot/samba/testsuite/build_farm/template/basicsmb.smb.conf,v
retrieving revision 1.3.2.4
diff -u -d -b -B -w -r1.3.2.4 basicsmb.smb.conf
--- build_farm/template/basicsmb.smb.conf	7 Jun 2003 00:27:15 
-0000	1.3.2.4
+++ build_farm/template/basicsmb.smb.conf	25 Jun 2003 15:41:11 -0000
@@ -6,7 +6,7 @@
      encrypt passwords = yes
      server string = Samba %v Build Farm Tests
      name resolve order = lmhosts
-    guest account = WHOAMI
+    guest account = GUESTUSER
      domain logons = yes

      strict locking = yes
@@ -47,3 +47,16 @@
      guest ok = yes
      read only = yes
      comment = Unauthenticated share for use in share level test
+
+[guest_test]
+    path = PREFIX/testdir
+    guest ok = yes
+    read only = no
+    comment = Test guest access via this share
+
+[guest_only]
+    path = PREFIX/testdir
+    guest ok = yes
+    guest only = yes
+    read only = no
+    comment = Test guest-only access via this share
\ No newline at end of file

and the other missing files;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: basicsmb-m2g_badpass.test
Type: application/octet-stream
Size: 3348 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030625/ca988877/basicsmb-m2g_badpass.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: basicsmb-m2g_baduser.test
Type: application/octet-stream
Size: 3356 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030625/ca988877/basicsmb-m2g_baduser.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: basicsmb-m2g_never.test
Type: application/octet-stream
Size: 3298 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030625/ca988877/basicsmb-m2g_never.obj
-------------- next part --------------


and

-------------- next part --------------
A non-text attachment was scrubbed...
Name: basicsmb.smb.conf.m2g_badpass
Type: application/octet-stream
Size: 43 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030625/ca988877/basicsmb.smb.conf.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: basicsmb.smb.conf.m2g_baduser
Type: application/octet-stream
Size: 39 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030625/ca988877/basicsmb.smb.conf-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: basicsmb.smb.conf.m2g_never
Type: application/octet-stream
Size: 36 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20030625/ca988877/basicsmb.smb.conf-0002.obj
-------------- next part --------------



More information about the samba-technical mailing list