[SCM] Samba Shared Repository - branch master updated

Günther Deschner gd at samba.org
Thu Jan 14 11:50:26 MST 2010


The branch, master has been updated
       via  e635b00... s3-libsmbclient: Fix crash bug in SMBC_parse_path().
       via  d95ad11... s4-smbtorture: add rather simple libsmbclient torture testsuite.
      from  8573471... s3:auth: fix account unlock regression introduced with fix for bug #4347

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit e635b0074c55e0376495abe940355aa7b04f0b70
Author: Günther Deschner <gd at samba.org>
Date:   Thu Jan 14 19:34:26 2010 +0100

    s3-libsmbclient: Fix crash bug in SMBC_parse_path().
    
    Patch from Tim Waugh <twaugh at redhat.com>.
    This resolves https://bugzilla.redhat.com/show_bug.cgi?id=552658
    
    LIBSMBCLIENT-OPENDIR torture test checks this as well.
    
    Guenther

commit d95ad11bc583c99f9bf8faeac7935880da19684b
Author: Günther Deschner <gd at samba.org>
Date:   Tue Jan 12 17:42:00 2010 +0100

    s4-smbtorture: add rather simple libsmbclient torture testsuite.
    
    Guenther

-----------------------------------------------------------------------

Summary of changes:
 source3/libsmb/libsmb_path.c                |    2 +-
 source3/samba4.m4                           |    1 +
 source4/configure.ac                        |    1 +
 source4/torture/config.mk                   |    1 +
 source4/torture/libsmbclient/config.m4      |   34 ++++
 source4/torture/libsmbclient/config.mk      |   15 ++
 source4/torture/libsmbclient/libsmbclient.c |  220 +++++++++++++++++++++++++++
 source4/torture/torture.c                   |    8 +
 8 files changed, 281 insertions(+), 1 deletions(-)
 create mode 100644 source4/torture/libsmbclient/config.m4
 create mode 100644 source4/torture/libsmbclient/config.mk
 create mode 100644 source4/torture/libsmbclient/libsmbclient.c


Changeset truncated at 500 lines:

diff --git a/source3/libsmb/libsmb_path.c b/source3/libsmb/libsmb_path.c
index 9d2eafc..64a956d 100644
--- a/source3/libsmb/libsmb_path.c
+++ b/source3/libsmb/libsmb_path.c
@@ -308,7 +308,7 @@ SMBC_parse_path(TALLOC_CTX *ctx,
 		if (!*pp_server) {
 			return -1;
 		}
-               	*pp_server[wl] = '\0';
+		(*pp_server)[wl] = '\0';
 		return 0;
 	}
 
diff --git a/source3/samba4.m4 b/source3/samba4.m4
index e4b2a0a..fbc19f1 100644
--- a/source3/samba4.m4
+++ b/source3/samba4.m4
@@ -136,6 +136,7 @@ SMB_ENABLE(wbinfo, NO)
 
 m4_include(lib/tls/config.m4)
 m4_include(torture/libnetapi/config.m4)
+m4_include(torture/libsmbclient/config.m4)
 
 dnl m4_include(auth/kerberos/config.m4)
 m4_include(auth/gensec/config.m4)
diff --git a/source4/configure.ac b/source4/configure.ac
index 3f10419..eab1be6 100644
--- a/source4/configure.ac
+++ b/source4/configure.ac
@@ -117,6 +117,7 @@ SMB_INCLUDED_LIB_PKGCONFIG(LIBLDB, ldb = LDB_REQUIRED_VERSION,
 
 m4_include(lib/tls/config.m4)
 m4_include(torture/libnetapi/config.m4)
+m4_include(torture/libsmbclient/config.m4)
 
 dnl m4_include(auth/kerberos/config.m4)
 m4_include(auth/gensec/config.m4)
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index 7976df2..d51ec68 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -90,6 +90,7 @@ $(eval $(call proto_header_template,$(torturesrcdir)/raw/proto.h,$(TORTURE_RAW_O
 mkinclude smb2/config.mk
 mkinclude winbind/config.mk
 mkinclude libnetapi/config.mk
+mkinclude libsmbclient/config.mk
 
 [SUBSYSTEM::TORTURE_NDR]
 PRIVATE_DEPENDENCIES = torture SERVICE_SMB
diff --git a/source4/torture/libsmbclient/config.m4 b/source4/torture/libsmbclient/config.m4
new file mode 100644
index 0000000..a53b4d6
--- /dev/null
+++ b/source4/torture/libsmbclient/config.m4
@@ -0,0 +1,34 @@
+###############################
+# start SMB_EXT_LIB_LIBSMBCLIENT
+# check for libsmbclient.h and -lsmbclient
+
+use_libsmbclient=auto
+AC_ARG_ENABLE(libsmbclient,
+AS_HELP_STRING([--enable-libsmbclient],[Turn on libsmbclient support (default=auto)]),
+    [if test x$enable_libsmbclient = xno; then
+        use_libsmbclient=no
+    fi])
+
+
+#if test x$use_libsmbclient = xauto && pkg-config --exists libsmbclient; then
+#	SMB_EXT_LIB_FROM_PKGCONFIG(LIBSMBCLIENT, libsmbclient < 0.1,
+#							   [use_libsmbclient=yes],
+#							   [use_libsmbclient=no])
+#fi
+
+SMB_ENABLE(TORTURE_LIBSMBCLIENT,NO)
+if test x$use_libsmbclient != xno; then
+	AC_CHECK_HEADERS(libsmbclient.h)
+	AC_CHECK_LIB_EXT(smbclient, SMBCLIENT_LIBS, smbc_new_context)
+	AC_CHECK_LIB_EXT(smbclient, SMBCLIENT_LIBS, smbc_getOptionNoAutoAnonymousLogin)
+	if test x"$ac_cv_header_libsmbclient_h" = x"yes" -a x"$ac_cv_lib_ext_smbclient_smbc_new_context" = x"yes" -a x"$ac_cv_lib_ext_smbclient_smbc_getOptionNoAutoAnonymousLogin" = x"yes"; then
+		AC_DEFINE(ENABLE_LIBSMBCLIENT,1,[Whether we have libsmbclient on the host system])
+		SMB_ENABLE(SMBCLIENT,YES)
+		SMB_ENABLE(TORTURE_LIBSMBCLIENT,YES)
+	else
+		if test x$use_libsmbclient != xauto; then
+			AC_MSG_ERROR([--enable-libsmbclient: libsmbclient not found])
+		fi
+	fi
+	SMB_EXT_LIB(SMBCLIENT, $SMBCLIENT_LIBS)
+fi
diff --git a/source4/torture/libsmbclient/config.mk b/source4/torture/libsmbclient/config.mk
new file mode 100644
index 0000000..a1c62fb
--- /dev/null
+++ b/source4/torture/libsmbclient/config.mk
@@ -0,0 +1,15 @@
+#################################
+# Start SUBSYSTEM TORTURE_LIBSMBCLIENT
+[MODULE::TORTURE_LIBSMBCLIENT]
+SUBSYSTEM = smbtorture
+OUTPUT_TYPE = MERGED_OBJ
+INIT_FUNCTION = torture_libsmbclient_init
+PRIVATE_DEPENDENCIES = \
+		POPT_CREDENTIALS \
+		SMBCLIENT
+# End SUBSYSTEM TORTURE_LIBSMBCLIENT
+#################################
+
+TORTURE_LIBSMBCLIENT_OBJ_FILES = $(addprefix $(torturesrcdir)/libsmbclient/, libsmbclient.o)
+
+$(eval $(call proto_header_template,$(torturesrcdir)/libsmbclient/proto.h,$(TORTURE_LIBSMBCLIENT_OBJ_FILES:.o=.c)))
diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c
new file mode 100644
index 0000000..2f146c9
--- /dev/null
+++ b/source4/torture/libsmbclient/libsmbclient.c
@@ -0,0 +1,220 @@
+/*
+   Unix SMB/CIFS implementation.
+   SMB torture tester
+   Copyright (C) Guenther Deschner 2010
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/smbtorture.h"
+#include "auth/credentials/credentials.h"
+#include "lib/cmdline/popt_common.h"
+#include <libsmbclient.h>
+#include "torture/libsmbclient/proto.h"
+
+bool torture_libsmbclient_init_context(struct torture_context *tctx,
+				       SMBCCTX **ctx_p)
+{
+	SMBCCTX *ctx;
+
+	ctx = smbc_new_context();
+	torture_assert(tctx, ctx, "failed to get new context");
+	torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
+
+	smbc_setDebug(ctx, DEBUGLEVEL);
+	smbc_setOptionDebugToStderr(ctx, 1);
+
+	/* yes, libsmbclient API frees the username when freeing the context, so
+	 * have to pass malloced data here */
+	smbc_setUser(ctx, strdup(cli_credentials_get_username(cmdline_credentials)));
+
+	*ctx_p = ctx;
+
+	return true;
+}
+
+static bool torture_libsmbclient_version(struct torture_context *tctx)
+{
+	torture_comment(tctx, "Testing smbc_version\n");
+
+	torture_assert(tctx, smbc_version(), "failed to get version");
+
+	return true;
+}
+
+static bool torture_libsmbclient_initialize(struct torture_context *tctx)
+{
+	SMBCCTX *ctx;
+
+	torture_comment(tctx, "Testing smbc_new_context\n");
+
+	ctx = smbc_new_context();
+	torture_assert(tctx, ctx, "failed to get new context");
+
+	torture_comment(tctx, "Testing smbc_init_context\n");
+
+	torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
+
+	smbc_free_context(ctx, 1);
+
+	return true;
+}
+
+static bool test_opendir(struct torture_context *tctx,
+			 SMBCCTX *ctx,
+			 const char *fname,
+			 bool expect_success)
+{
+	int handle, ret;
+
+	torture_comment(tctx, "Testing smbc_opendir(%s)\n", fname);
+
+	handle = smbc_opendir(fname);
+	if (!expect_success) {
+		return true;
+	}
+	if (handle < 0) {
+		torture_fail(tctx, talloc_asprintf(tctx, "failed to obain file handle for '%s'", fname));
+	}
+
+	ret = smbc_closedir(handle);
+	torture_assert_int_equal(tctx, ret, 0,
+		talloc_asprintf(tctx, "failed to close file handle for '%s'", fname));
+
+	return true;
+}
+
+static bool torture_libsmbclient_opendir(struct torture_context *tctx)
+{
+	int i;
+	SMBCCTX *ctx;
+	bool ret = true;
+	const char *bad_urls[] = {
+		"",
+		NULL,
+		"smb",
+		"smb:",
+		"smb:/",
+		"smb:///",
+		"bms://",
+		":",
+		":/",
+		"://",
+		":///",
+		"/",
+		"//",
+		"///"
+	};
+	const char *good_urls[] = {
+		"smb://",
+		"smb://WORKGROUP",
+		"smb://WORKGROUP/"
+	};
+
+	torture_assert(tctx, torture_libsmbclient_init_context(tctx, &ctx), "");
+	smbc_set_context(ctx);
+
+	for (i=0; i < ARRAY_SIZE(bad_urls); i++) {
+		ret &= test_opendir(tctx, ctx, bad_urls[i], false);
+	}
+	for (i=0; i < ARRAY_SIZE(good_urls); i++) {
+		ret &= test_opendir(tctx, ctx, good_urls[i], true);
+	}
+
+	smbc_free_context(ctx, 1);
+
+	return ret;
+}
+
+/* note the strdup for string options on smbc_set calls. I think libsmbclient is
+ * really doing something wrong here: in smbc_free_context libsmbclient just
+ * calls free() on the string options so it assumes the callers have malloced
+ * them before setting them via smbc_set calls. */
+
+#define TEST_OPTION_INT(option, val) \
+	torture_comment(tctx, "Testing smbc_set" #option "\n");\
+	smbc_set ##option(ctx, val);\
+	torture_comment(tctx, "Testing smbc_get" #option "\n");\
+	torture_assert_int_equal(tctx, smbc_get ##option(ctx), val, "failed " #option);
+
+#define TEST_OPTION_STRING(option, val) \
+	torture_comment(tctx, "Testing smbc_set" #option "\n");\
+	smbc_set ##option(ctx, strdup(val));\
+	torture_comment(tctx, "Testing smbc_get" #option "\n");\
+	torture_assert_str_equal(tctx, smbc_get ##option(ctx), val, "failed " #option);
+
+bool torture_libsmbclient_configuration(struct torture_context *tctx)
+{
+	SMBCCTX *ctx;
+
+	ctx = smbc_new_context();
+	torture_assert(tctx, ctx, "failed to get new context");
+	torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
+
+	TEST_OPTION_INT(Debug, DEBUGLEVEL);
+	TEST_OPTION_STRING(NetbiosName, "torture_netbios");
+	TEST_OPTION_STRING(Workgroup, "torture_workgroup");
+	TEST_OPTION_STRING(User, "torture_user");
+	TEST_OPTION_INT(Timeout, 12345);
+
+	smbc_free_context(ctx, 1);
+
+	return true;
+}
+
+bool torture_libsmbclient_options(struct torture_context *tctx)
+{
+	SMBCCTX *ctx;
+
+	ctx = smbc_new_context();
+	torture_assert(tctx, ctx, "failed to get new context");
+	torture_assert(tctx, smbc_init_context(ctx), "failed to init context");
+
+	TEST_OPTION_INT(OptionDebugToStderr, true);
+	TEST_OPTION_INT(OptionFullTimeNames, true);
+	TEST_OPTION_INT(OptionOpenShareMode, SMBC_SHAREMODE_DENY_ALL);
+	/* FIXME: OptionUserData */
+	TEST_OPTION_INT(OptionSmbEncryptionLevel, SMBC_ENCRYPTLEVEL_REQUEST);
+	TEST_OPTION_INT(OptionCaseSensitive, false);
+	TEST_OPTION_INT(OptionBrowseMaxLmbCount, 2);
+	TEST_OPTION_INT(OptionUrlEncodeReaddirEntries, true);
+	TEST_OPTION_INT(OptionOneSharePerServer, true);
+	TEST_OPTION_INT(OptionUseKerberos, false);
+	TEST_OPTION_INT(OptionFallbackAfterKerberos, false);
+	TEST_OPTION_INT(OptionNoAutoAnonymousLogin, true);
+
+	smbc_free_context(ctx, 1);
+
+	return true;
+}
+
+NTSTATUS torture_libsmbclient_init(void)
+{
+	struct torture_suite *suite;
+
+	suite = torture_suite_create(talloc_autofree_context(), "LIBSMBCLIENT");
+
+	torture_suite_add_simple_test(suite, "VERSION", torture_libsmbclient_version);
+	torture_suite_add_simple_test(suite, "INITIALIZE", torture_libsmbclient_initialize);
+	torture_suite_add_simple_test(suite, "CONFIGURATION", torture_libsmbclient_configuration);
+	torture_suite_add_simple_test(suite, "OPTIONS", torture_libsmbclient_options);
+	torture_suite_add_simple_test(suite, "OPENDIR", torture_libsmbclient_opendir);
+
+	suite->description = talloc_strdup(suite, "libsmbclient interface tests");
+
+	torture_register_suite(suite);
+
+	return NT_STATUS_OK;
+}
diff --git a/source4/torture/torture.c b/source4/torture/torture.c
index 49a6a8c..a93fbe3 100644
--- a/source4/torture/torture.c
+++ b/source4/torture/torture.c
@@ -50,6 +50,13 @@ NTSTATUS torture_libnetapi_init(void)
 }
 #endif
 
+#ifndef ENABLE_LIBSMBCLIENT
+NTSTATUS torture_libsmbclient_init(void)
+{
+	return NT_STATUS_OK;
+}
+#endif
+
 _PUBLIC_ int torture_init(void)
 {
 	extern NTSTATUS torture_base_init(void);
@@ -63,6 +70,7 @@ _PUBLIC_ int torture_init(void)
 	extern NTSTATUS torture_smb2_init(void);
 	extern NTSTATUS torture_net_init(void);
 	extern NTSTATUS torture_libnetapi_init(void);
+	extern NTSTATUS torture_libsmbclient_init(void);
 	extern NTSTATUS torture_raw_init(void);
 	extern NTSTATUS torture_unix_init(void);
 	extern NTSTATUS torture_winbind_init(void);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list