RFC: new testparam check

Noel Power nopower at suse.com
Wed Apr 12 19:32:52 UTC 2017


On 12/04/17 16:59, Noel Power via samba-technical wrote:
> On 12/04/17 16:46, Andreas Schneider via samba-technical wrote:
[...]
>> [2(6)/2092 at 0s] samba.tests.docs
>> UNEXPECTED(failure): 
>> samba.tests.docs.samba.tests.docs.SmbDotConfTests.test_default_s3(none)
>> REASON: Exception: Exception: Traceback (most recent call last):
>>   File "/memdisk/asn/a/b408368/samba/bin/python/samba/tests/docs.py", line 
>> 166, in test_default_s3
>>     'rpc server dynamic port range'])
>>   File "/memdisk/asn/a/b408368/samba/bin/python/samba/tests/docs.py", line 
>> 344, in _set_arbitrary
>>     "Parameters that were unexpectedly not set:"))
>> AssertionError: Parameters that were unexpectedly not set:
>>
>>     name resolve order
>>       Expected: a b c
>>       Got:
>>
>>
>> The documentation test needs to be adapted. This is a special variable now. It 
>> should probably be ignored.
>>
>>
>> 	Andreas
>>
> I will look into this
>
>
> Noel


ok patch 0003 adapts the doc test, if you are happy I suppose I should
squash it with the existing test patch (0002-xxx) ?

Noel
-------------- next part --------------
>From b049f6d4a99af42455a94ff3ed9f2773662c17fc Mon Sep 17 00:00:00 2001
From: Noel Power <noel.power at suse.com>
Date: Wed, 12 Apr 2017 20:23:40 +0100
Subject: [PATCH 3/3] python/samba/tests: make name resolve order and exception
 when testing set

Testing 'name resolve order' with 'aribrary' values fails (because now
we check the validity of the values) so we need to add this param to
the list of exceptions when testing

Bug: https://bugzilla.samba.org/show_bug.cgi?id=12739
Signed-off-by: Noel Power <noel.power at suse.com>
---
 python/samba/tests/docs.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/python/samba/tests/docs.py b/python/samba/tests/docs.py
index 65df573a350..202619a913e 100644
--- a/python/samba/tests/docs.py
+++ b/python/samba/tests/docs.py
@@ -163,7 +163,8 @@ class SmbDotConfTests(TestCase):
                           'client plaintext auth',
                           'registry shares',
                           'smb ports',
-                          'rpc server dynamic port range'])
+                          'rpc server dynamic port range',
+                          'name resolve order'])
         self._test_empty(['bin/testparm'])
 
     def test_default_s4(self):
@@ -171,7 +172,8 @@ class SmbDotConfTests(TestCase):
         self._set_defaults(['bin/samba-tool', 'testparm'])
         self._set_arbitrary(['bin/samba-tool', 'testparm'],
             exceptions = ['smb ports',
-                          'rpc server dynamic port range'])
+                          'rpc server dynamic port range',
+                          'name resolve order'])
         self._test_empty(['bin/samba-tool', 'testparm'])
 
     def _test_default(self, program):
-- 
2.12.0

-------------- next part --------------
>From 9fccc9f28ed8ec45d5764082dc371e885901109e Mon Sep 17 00:00:00 2001
From: Noel Power <noel.power at suse.com>
Date: Tue, 11 Apr 2017 14:38:34 +0100
Subject: [PATCH 2/3] s3/script/tests: Test for illegal value detection for
 'name resolve order'

Bug: https://bugzilla.samba.org/show_bug.cgi?id=12739
Signed-off-by: Noel Power <noel.power at suse.com>

Reviewed-by: Andreas Schneider <asn at samba.org>
Reviewed-by: David Disseldorp <ddiss at samba.org>
---
 source3/script/tests/test_testparm_s3.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/source3/script/tests/test_testparm_s3.sh b/source3/script/tests/test_testparm_s3.sh
index c9682f0dd10..6dcdeff07d7 100755
--- a/source3/script/tests/test_testparm_s3.sh
+++ b/source3/script/tests/test_testparm_s3.sh
@@ -58,6 +58,25 @@ EOF
 	${TESTPARM} ${TEMP_CONFFILE}
 }
 
+testit "name resolve order = lmhosts wins host bcast"\
+	test_one_global_option "name resolve order = lmhosts wins host bcast" || \
+	failed=`expr ${failed} + 1`
+
+testit_expect_failure "name resolve order = bad wins host bcast"\
+	test_one_global_option "name resolve order = bad wins host bcast" || \
+	failed=`expr ${failed} + 1`
+
+testit_expect_failure "name resolve order = lmhosts bad host bcast"\
+	test_one_global_option "name resolve order = lmhosts bad host bcast" || \
+	failed=`expr ${failed} + 1`
+
+testit_expect_failure "name resolve order = lmhosts wins bad bcast"\
+	test_one_global_option "name resolve order = lmhosts wins bad bcast" || \
+	failed=`expr ${failed} + 1`
+
+testit_expect_failure "name resolve order = lmhosts wins host bad"\
+	test_one_global_option "name resolve order = lmhosts wins host bad" || \
+	failed=`expr ${failed} + 1`
 
 testit "netbios name" \
 	test_one_global_option "netbios name = funky" || \
-- 
2.12.0

-------------- next part --------------
>From 8189083dec3380114aa7d460f083eec3c0d4bca7 Mon Sep 17 00:00:00 2001
From: Noel Power <noel.power at suse.com>
Date: Tue, 11 Apr 2017 11:26:45 +0100
Subject: [PATCH 1/3] Check for valid values for global conf 'name resolve
 order' variable

This variable is populated by a list of values where each value should
be a known option. This patch ensures that illegal values are detected.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=12739
Signed-off-by: Noel Power <noel.power at suse.com>

Reviewed-by: Andreas Schneider <asn at samba.org>
Reviewed-by: David Disseldorp <ddiss at samba.org>
---
 docs-xml/smbdotconf/protocol/nameresolveorder.xml |  1 +
 lib/param/loadparm.c                              | 49 ++++++++++++++++++++++-
 lib/param/loadparm.h                              |  1 +
 source3/param/loadparm.c                          |  5 ++-
 4 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/docs-xml/smbdotconf/protocol/nameresolveorder.xml b/docs-xml/smbdotconf/protocol/nameresolveorder.xml
index ec3aaf375e1..1e0458258d5 100644
--- a/docs-xml/smbdotconf/protocol/nameresolveorder.xml
+++ b/docs-xml/smbdotconf/protocol/nameresolveorder.xml
@@ -1,6 +1,7 @@
 <samba:parameter name="name resolve order"
                  context="G"
                  type="cmdlist"
+                 handler="handle_name_resolve_order"
                  xmlns:samba="http://www.samba.org/samba/DTD/samba-doc"> 
 <description>
     <para>This option is used by the programs in the Samba 
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index cedf8facb8d..4d21d88cc6c 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -69,6 +69,7 @@
 #include "tdb.h"
 #include "librpc/gen_ndr/nbt.h"
 #include "libds/common/roles.h"
+#include "lib/util/samba_util.h"
 
 #ifdef HAVE_HTTPCONNECTENCRYPT
 #include <cups/http.h>
@@ -1710,6 +1711,50 @@ static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr
 
 }
 
+bool handle_name_resolve_order(struct loadparm_context *lp_ctx,
+			       struct loadparm_service *service,
+			       const char *pszParmValue, char **ptr)
+{
+	const char **valid_values = NULL;
+	const char **values_to_set = NULL;
+	int i;
+	bool value_is_valid = false;
+	valid_values = str_list_make_v3_const(NULL,
+					      DEFAULT_NAME_RESOLVE_ORDER,
+					      NULL);
+	if (valid_values == NULL) {
+		DBG_ERR("OOM: failed to make string list from %s\n",
+			DEFAULT_NAME_RESOLVE_ORDER);
+		goto out;
+	}
+	values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
+					       pszParmValue,
+					       NULL);
+	if (values_to_set == NULL) {
+		DBG_ERR("OOM: failed to make string list from %s\n",
+			pszParmValue);
+		goto out;
+	}
+	TALLOC_FREE(lp_ctx->globals->name_resolve_order);
+	for (i = 0; values_to_set[i] != NULL; i++) {
+		value_is_valid = str_list_check(valid_values, values_to_set[i]);
+		if (!value_is_valid) {
+			DBG_ERR("WARNING: Ignoring invalid list value '%s' "
+				"for parameter 'name resolve order'\n",
+				values_to_set[i]);
+			break;
+		}
+	}
+out:
+	if (value_is_valid) {
+		lp_ctx->globals->name_resolve_order = values_to_set;
+	} else {
+		TALLOC_FREE(values_to_set);
+	}
+	TALLOC_FREE(valid_values);
+	return value_is_valid;
+}
+
 static bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service,
 			 int parmnum, void *parm_ptr,
 			 const char *pszParmName, const char *pszParmValue,
@@ -2605,7 +2650,9 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
 	myname = get_myname(lp_ctx);
 	lpcfg_do_global_parameter(lp_ctx, "netbios name", myname);
 	talloc_free(myname);
-	lpcfg_do_global_parameter(lp_ctx, "name resolve order", "lmhosts wins host bcast");
+	lpcfg_do_global_parameter(lp_ctx,
+				  "name resolve order",
+				  DEFAULT_NAME_RESOLVE_ORDER);
 
 	lpcfg_do_global_parameter(lp_ctx, "fstype", "NTFS");
 
diff --git a/lib/param/loadparm.h b/lib/param/loadparm.h
index d1e2b7cb056..e3c82164ca4 100644
--- a/lib/param/loadparm.h
+++ b/lib/param/loadparm.h
@@ -105,6 +105,7 @@ struct file_lists {
 	time_t modtime;
 };
 
+#define DEFAULT_NAME_RESOLVE_ORDER "lmhosts wins host bcast"
 #define FLAG_DEPRECATED 0x1000 /* options that should no longer be used */
 #define FLAG_SYNONYM	0x2000 /* options that is a synonym of another option */
 #define FLAG_CMDLINE	0x10000 /* option has been overridden */
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 57220a64282..b543a6f48c9 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -609,7 +609,10 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
 	lpcfg_string_set(Globals.ctx, &Globals.logon_path,
 			 "\\\\%N\\%U\\profile");
 
-	Globals.name_resolve_order = str_list_make_v3_const(NULL, "lmhosts wins host bcast", NULL);
+	Globals.name_resolve_order =
+			str_list_make_v3_const(Globals.ctx,
+					       DEFAULT_NAME_RESOLVE_ORDER,
+					       NULL);
 	lpcfg_string_set(Globals.ctx, &Globals.password_server, "*");
 
 	Globals.algorithmic_rid_base = BASE_RID;
-- 
2.12.0



More information about the samba-technical mailing list