param: Check for valid values of 'name resolve order' option
authorNoel Power <noel.power@suse.com>
Tue, 11 Apr 2017 10:26:45 +0000 (11:26 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 13 Apr 2017 09:26:28 +0000 (11:26 +0200)
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@suse.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
docs-xml/smbdotconf/protocol/nameresolveorder.xml
lib/param/loadparm.c
lib/param/loadparm.h
python/samba/tests/docs.py
source3/param/loadparm.c

index ec3aaf3..1e04582 100644 (file)
@@ -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 
index cedf8fa..4d21d88 100644 (file)
@@ -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");
 
index d1e2b7c..e3c8216 100644 (file)
@@ -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 */
index 65df573..202619a 100644 (file)
@@ -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):
index 57220a6..b543a6f 100644 (file)
@@ -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;