s3:net rpc conf: factor validation of parameter out for re-use.
authorMichael Adam <obnox@samba.org>
Tue, 24 Sep 2013 04:38:09 +0000 (06:38 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 24 Sep 2013 05:44:28 +0000 (07:44 +0200)
This goes into a new module net_conf_util to be shared
between net conf and net rpc conf.

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/utils/net_conf_util.c [new file with mode: 0644]
source3/utils/net_conf_util.h [new file with mode: 0644]
source3/utils/net_rpc_conf.c
source3/wscript_build

diff --git a/source3/utils/net_conf_util.c b/source3/utils/net_conf_util.c
new file mode 100644 (file)
index 0000000..2c70371
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *  Samba Unix/Linux SMB client library
+ *  Distributed SMB/CIFS Server Management Utility
+ *  Configuration interface
+ *
+ *  Copyright (C) Michael Adam 2013
+ *
+ *  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/>.
+ */
+
+/*
+ * Utility functions for net conf and net rpc conf.
+ */
+
+#include "includes.h"
+#include "lib/smbconf/smbconf.h"
+#include "lib/smbconf/smbconf_reg.h"
+#include "lib/param/loadparm.h"
+#include "net_conf_util.h"
+
+bool net_conf_param_valid(const char *service,
+                         const char *param,
+                         const char *valstr)
+{
+       const char *canon_param, *canon_valstr;
+
+       if (!lp_parameter_is_valid(param)) {
+               d_fprintf(stderr, "Invalid parameter '%s' given.\n", param);
+               return false;
+       }
+
+       if (!smbconf_reg_parameter_is_valid(param)) {
+               d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n",
+                         param);
+               return false;
+       }
+
+       if (!strequal(service, "global") && lp_parameter_is_global(param)) {
+               d_fprintf(stderr, "Global parameter '%s' not allowed in "
+                         "service definition ('%s').\n", param, service);
+               return false;
+       }
+
+       if (!lp_canonicalize_parameter_with_value(param, valstr,
+                                                 &canon_param,
+                                                 &canon_valstr))
+       {
+               /*
+                * We already know the parameter name is valid.
+                * So the value must be invalid.
+                */
+               d_fprintf(stderr, "invalid value '%s' given for "
+                         "parameter '%s'\n", param, valstr);
+               return false;
+       }
+
+       return true;
+}
diff --git a/source3/utils/net_conf_util.h b/source3/utils/net_conf_util.h
new file mode 100644 (file)
index 0000000..798b399
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ *  Samba Unix/Linux SMB client library
+ *  Distributed SMB/CIFS Server Management Utility
+ *  Configuration interface
+ *
+ *  Copyright (C) Michael Adam 2013
+ *
+ *  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/>.
+ */
+
+#ifndef __NET_CONF_UTIL_H__
+#define __NET_CONF_UTIL_H__
+
+/*
+ * Utility functions for net conf and net rpc conf.
+ */
+
+bool net_conf_param_valid(const char *service,
+                         const char *param,
+                         const char *valstr);
+
+#endif /* __NET_CONF_UTIL_H__ */
index 4b5f58e45bca1f70fc03f5c16553938b62bbc1ed..5a64accdcf4785f7318f2285cdebd3992b38cbd9 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "includes.h"
 #include "utils/net.h"
+#include "utils/net_conf_util.h"
 #include "rpc_client/cli_pipe.h"
 #include "../librpc/gen_ndr/ndr_samr_c.h"
 #include "rpc_client/init_samr.h"
@@ -1740,8 +1741,6 @@ static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
        enum winreg_CreateAction action = 0;
 
        const char *service_name, *param_name, *valstr;
-       const char *canon_param_name;
-       const char *canon_valstr;
 
        ZERO_STRUCT(hive_hnd);
        ZERO_STRUCT(key_hnd);
@@ -1832,40 +1831,7 @@ static NTSTATUS rpc_conf_setparm_internal(struct net_context *c,
         * check if parameter is valid for writing
         */
 
-       if (!lp_parameter_is_valid(param_name)) {
-               d_fprintf(stderr, "Invalid parameter '%s' given.\n",
-                         param_name);
-               werr = WERR_INVALID_PARAM;
-               goto error;
-       }
-
-       if (!smbconf_reg_parameter_is_valid(param_name)) {
-               d_fprintf(stderr, "Parameter '%s' not allowed in registry.\n",
-                         param_name);
-               werr = WERR_INVALID_PARAM;
-               goto error;
-       }
-
-       if (!strequal(service_name, "global") &&
-          lp_parameter_is_global(param_name))
-       {
-               d_fprintf(stderr, "Global parameter '%s' not allowed in "
-                         "service definition ('%s').\n", param_name,
-                         service_name);
-               werr = WERR_INVALID_PARAM;
-               goto error;
-       }
-
-       if (!lp_canonicalize_parameter_with_value(param_name, valstr,
-                                                 &canon_param_name,
-                                                 &canon_valstr))
-       {
-               /*
-                * We already know the parameter name is valid.
-                * So the value must be invalid.
-                */
-               d_fprintf(stderr, "invalid value '%s' given for "
-                         "parameter '%s'\n", param_name, valstr);
+       if (!net_conf_param_valid(service_name, param_name, valstr)) {
                werr = WERR_INVALID_PARAM;
                goto error;
        }
index 02d9a1a087094c07560b6330c33732a9737d439c..2122d15bb8d6a26713b6cb8ba0fa5e30daf870f3 100755 (executable)
@@ -1056,6 +1056,7 @@ bld.SAMBA3_BINARY('net',
                  utils/net_dns.c
                  utils/net_ads_gpo.c
                  utils/net_conf.c
+                 utils/net_conf_util.c
                  utils/net_join.c
                  utils/net_user.c
                  utils/net_group.c