RFC: new testparam check
Noel Power
nopower at suse.com
Wed Apr 12 09:04:43 UTC 2017
Dave
please see attached :-)
On 12/04/17 08:38, Noel Power via samba-technical wrote:
> On 11/04/17 17:53, David Disseldorp via samba-technical wrote:
>> On Tue, 11 Apr 2017 17:33:19 +0100, Noel Power via samba-technical wrote:
>>
>>> + valid_values = str_list_make_v3_const(NULL,
>>> + DEFAULT_NAME_RESOLVE_ORDER,
>>> + NULL);
>>> + if (!valid_values) {
>>> + DBG_ERR("OOM: failed to make string list from %s\n",
>>> + DEFAULT_NAME_RESOLVE_ORDER);
>>> + return false;
>>> + }
>>> + values_to_set = str_list_make_v3_const(lp_ctx->globals->ctx,
>>> + pszParmValue,
>>> + NULL);
>>> + if (!values_to_set) {
>>> + DBG_ERR("OOM: failed to make string list from %s\n",
>>> + pszParmValue);
>> valid_values should be freed on failure here.
> /me face palms,
> knew it was a bad idea to do this while running out the door, I'll post
> an updated patch later on this morning
>
> Noel
>
>
-------------- next part --------------
>From 8ff0be8d1a4fd2988a6d2bbebc13d4bfdef4415f 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/2] 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 9c8799d67716ba5c17bca7efaacf202c0df9cf6b 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/2] 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