The branch, master has been updated via 5c04521 s3:tests: Add test for illegal value detection for 'name resolve order' via 8050db2 param: Check for valid values of 'name resolve order' option from 63c6209 updaterefs: Do not open transaction even when unnecessary
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 5c04521b8e93ae4960e6d367af94fb198599a5f4 Author: Noel Power <noel.po...@suse.com> Date: Tue Apr 11 14:38:34 2017 +0100 s3:tests: Add 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.po...@suse.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: David Disseldorp <dd...@samba.org> Autobuild-User(master): Andreas Schneider <a...@cryptomilk.org> Autobuild-Date(master): Thu Apr 13 15:20:04 CEST 2017 on sn-devel-144 commit 8050db230331d468f2e6ebee341c4e8267cd626d Author: Noel Power <noel.po...@suse.com> Date: Tue Apr 11 11:26:45 2017 +0100 param: Check for valid values of 'name resolve order' option 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.po...@suse.com> Reviewed-by: Andreas Schneider <a...@samba.org> Reviewed-by: David Disseldorp <dd...@samba.org> ----------------------------------------------------------------------- Summary of changes: docs-xml/smbdotconf/protocol/nameresolveorder.xml | 1 + lib/param/loadparm.c | 49 ++++++++++++++++++++++- lib/param/loadparm.h | 1 + python/samba/tests/docs.py | 6 ++- source3/param/loadparm.c | 5 ++- source3/script/tests/test_testparm_s3.sh | 19 +++++++++ 6 files changed, 77 insertions(+), 4 deletions(-) Changeset truncated at 500 lines: diff --git a/docs-xml/smbdotconf/protocol/nameresolveorder.xml b/docs-xml/smbdotconf/protocol/nameresolveorder.xml index ec3aaf3..1e04582 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 cedf8fa..4d21d88 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 d1e2b7c..e3c8216 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/python/samba/tests/docs.py b/python/samba/tests/docs.py index 65df573..202619a 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): diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 57220a6..b543a6f 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; diff --git a/source3/script/tests/test_testparm_s3.sh b/source3/script/tests/test_testparm_s3.sh index c9682f0..6dcdeff 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" || \ -- Samba Shared Repository