libsmbconf: Convert smbconf_set_parameter() to sbcErr.
authorAndreas Schneider <asn@samba.org>
Mon, 11 Apr 2011 11:23:26 +0000 (13:23 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 10 May 2011 17:13:21 +0000 (19:13 +0200)
Signed-off-by: Michael Adam <obnox@samba.org>
lib/smbconf/smbconf.c
lib/smbconf/smbconf.h
lib/smbconf/smbconf_private.h
lib/smbconf/smbconf_txt.c
source3/lib/netapi/serverinfo.c
source3/lib/smbconf/smbconf_reg.c
source3/libnet/libnet_join.c
source3/utils/net_conf.c

index c02899c0d5bdf896317fb0ba26fe72a508c0fc7d..786f4d32d13ecad820425753e6c1e163e5e1faab 100644 (file)
@@ -260,7 +260,7 @@ sbcErr smbconf_delete_share(struct smbconf_ctx *ctx, const char *servicename)
 /**
  * set a configuration parameter to the value provided.
  */
-WERROR smbconf_set_parameter(struct smbconf_ctx *ctx,
+sbcErr smbconf_set_parameter(struct smbconf_ctx *ctx,
                             const char *service,
                             const char *param,
                             const char *valstr)
@@ -274,19 +274,18 @@ WERROR smbconf_set_parameter(struct smbconf_ctx *ctx,
  *
  * This also creates [global] when it does not exist.
  */
-WERROR smbconf_set_global_parameter(struct smbconf_ctx *ctx,
+sbcErr smbconf_set_global_parameter(struct smbconf_ctx *ctx,
                                    const char *param, const char *val)
 {
-       WERROR werr = WERR_OK;
        sbcErr err;
 
        err = smbconf_global_check(ctx);
        if (!SBC_ERROR_IS_OK(err)) {
-               return WERR_GENERAL_FAILURE;
+               return err;
        }
-       werr = smbconf_set_parameter(ctx, GLOBAL_NAME, param, val);
+       err = smbconf_set_parameter(ctx, GLOBAL_NAME, param, val);
 
-       return werr;
+       return err;
 }
 
 /**
index af021f95d76793ab683fa9db4349aeb93dfa9882..1471ceca1d016e82182218affe06d3e6006004dd 100644 (file)
@@ -91,11 +91,11 @@ sbcErr smbconf_get_share(struct smbconf_ctx *ctx,
                         struct smbconf_service **service);
 sbcErr smbconf_delete_share(struct smbconf_ctx *ctx,
                            const char *servicename);
-WERROR smbconf_set_parameter(struct smbconf_ctx *ctx,
+sbcErr smbconf_set_parameter(struct smbconf_ctx *ctx,
                             const char *service,
                             const char *param,
                             const char *valstr);
-WERROR smbconf_set_global_parameter(struct smbconf_ctx *ctx,
+sbcErr smbconf_set_global_parameter(struct smbconf_ctx *ctx,
                                    const char *param, const char *val);
 WERROR smbconf_get_parameter(struct smbconf_ctx *ctx,
                             TALLOC_CTX *mem_ctx,
index 0fa47e87a766d0402aa5925af171a7f3d9da881b..b11a1420ae0041de6b2d24e7bc4bfd68176b9b07 100644 (file)
@@ -48,7 +48,7 @@ struct smbconf_ops {
                            struct smbconf_service **service);
        sbcErr (*delete_share)(struct smbconf_ctx *ctx,
                                    const char *servicename);
-       WERROR (*set_parameter)(struct smbconf_ctx *ctx,
+       sbcErr (*set_parameter)(struct smbconf_ctx *ctx,
                                const char *service,
                                const char *param,
                                const char *valstr);
index 1017b5a1c84ddd2ca66ed83fa9ec804339fb8331..0f77254d38137bd4dcf14d60926b00ac30328ef9 100644 (file)
@@ -471,12 +471,12 @@ static sbcErr smbconf_txt_delete_share(struct smbconf_ctx *ctx,
 /**
  * set a configuration parameter to the value provided.
  */
-static WERROR smbconf_txt_set_parameter(struct smbconf_ctx *ctx,
+static sbcErr smbconf_txt_set_parameter(struct smbconf_ctx *ctx,
                                        const char *service,
                                        const char *param,
                                        const char *valstr)
 {
-       return WERR_NOT_SUPPORTED;
+       return SBC_ERR_NOT_SUPPORTED;
 }
 
 /**
index e995bdaf474eaeeb21d3be7c638106e3099afba2..f321648f249c9de0ad6bd2bb505bb35eb099ccc3 100644 (file)
@@ -573,8 +573,15 @@ static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
                goto done;
        }
 
-       werr = smbconf_set_global_parameter(conf_ctx, "server string",
+       err = smbconf_set_global_parameter(conf_ctx, "server string",
                                            info1005->comment);
+       if (!SBC_ERROR_IS_OK(err)) {
+               libnetapi_set_error_string(ctx,
+                       "Could not set global parameter: %s",
+                       sbcErrorString(err));
+               werr = WERR_NO_SUCH_SERVICE;
+               goto done;
+       }
 
  done:
        smbconf_shutdown(conf_ctx);
index e27a871a136abb7489ca0430b922efcf05d52326..f7faf51e7d087e4f21b095ec9a73063ea78df48e 100644 (file)
@@ -163,12 +163,13 @@ static sbcErr smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
 /**
  * add a value to a key.
  */
-static WERROR smbconf_reg_set_value(struct registry_key *key,
+static sbcErr smbconf_reg_set_value(struct registry_key *key,
                                    const char *valname,
                                    const char *valstr)
 {
        struct registry_value val;
        WERROR werr = WERR_OK;
+       sbcErr err;
        char *subkeyname;
        const char *canon_valname;
        const char *canon_valstr;
@@ -184,14 +185,14 @@ static WERROR smbconf_reg_set_value(struct registry_key *key,
                        DEBUG(5, ("invalid value '%s' given for "
                                  "parameter '%s'\n", valstr, valname));
                }
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
 
        if (smbconf_reg_valname_forbidden(canon_valname)) {
                DEBUG(5, ("Parameter '%s' not allowed in registry.\n",
                          canon_valname));
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
 
@@ -199,7 +200,7 @@ static WERROR smbconf_reg_set_value(struct registry_key *key,
        if ((subkeyname == NULL) || (*(subkeyname +1) == '\0')) {
                DEBUG(5, ("Invalid registry key '%s' given as "
                          "smbconf section.\n", key->key->name));
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
        subkeyname++;
@@ -209,7 +210,7 @@ static WERROR smbconf_reg_set_value(struct registry_key *key,
                DEBUG(5, ("Global parameter '%s' not allowed in "
                          "service definition ('%s').\n", canon_valname,
                          subkeyname));
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
 
@@ -217,7 +218,7 @@ static WERROR smbconf_reg_set_value(struct registry_key *key,
 
        val.type = REG_SZ;
        if (!push_reg_sz(talloc_tos(), &val.data, canon_valstr)) {
-               werr = WERR_NOMEM;
+               err = SBC_ERR_NOMEM;
                goto done;
        }
 
@@ -226,10 +227,13 @@ static WERROR smbconf_reg_set_value(struct registry_key *key,
                DEBUG(5, ("Error adding value '%s' to "
                          "key '%s': %s\n",
                          canon_valname, key->key->name, win_errstr(werr)));
+               err = SBC_ERR_NOMEM;
+               goto done;
        }
 
+       err = SBC_ERR_OK;
 done:
-       return werr;
+       return err;
 }
 
 static WERROR smbconf_reg_set_multi_sz_value(struct registry_key *key,
@@ -960,12 +964,11 @@ static sbcErr smbconf_reg_delete_share(struct smbconf_ctx *ctx,
 /**
  * set a configuration parameter to the value provided.
  */
-static WERROR smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
+static sbcErr smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
                                        const char *service,
                                        const char *param,
                                        const char *valstr)
 {
-       WERROR werr;
        sbcErr err;
        struct registry_key *key = NULL;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
@@ -973,15 +976,14 @@ static WERROR smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
        err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
                                           REG_KEY_WRITE, &key);
        if (!SBC_ERROR_IS_OK(err)) {
-               werr = WERR_NOMEM;
                goto done;
        }
 
-       werr = smbconf_reg_set_value(key, param, valstr);
+       err = smbconf_reg_set_value(key, param, valstr);
 
 done:
        talloc_free(mem_ctx);
-       return werr;
+       return err;
 }
 
 /**
index 5f7f93e087113e10d52a85ed40049afccb3ba567..ef0d5d0850c2e4fe04daa8b5e1fa9331c7e6dff0 100644 (file)
@@ -1467,30 +1467,49 @@ static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
 
        if (!(r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE)) {
 
-               werr = smbconf_set_global_parameter(ctx, "security", "user");
-               W_ERROR_NOT_OK_GOTO_DONE(werr);
+               err = smbconf_set_global_parameter(ctx, "security", "user");
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NO_SUCH_SERVICE;
+                       goto done;
+               }
 
-               werr = smbconf_set_global_parameter(ctx, "workgroup",
-                                                   r->in.domain_name);
+               err = smbconf_set_global_parameter(ctx, "workgroup",
+                                                  r->in.domain_name);
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NO_SUCH_SERVICE;
+                       goto done;
+               }
 
                smbconf_delete_global_parameter(ctx, "realm");
                goto done;
        }
 
-       werr = smbconf_set_global_parameter(ctx, "security", "domain");
-       W_ERROR_NOT_OK_GOTO_DONE(werr);
+       err = smbconf_set_global_parameter(ctx, "security", "domain");
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NO_SUCH_SERVICE;
+               goto done;
+       }
 
-       werr = smbconf_set_global_parameter(ctx, "workgroup",
-                                           r->out.netbios_domain_name);
-       W_ERROR_NOT_OK_GOTO_DONE(werr);
+       err = smbconf_set_global_parameter(ctx, "workgroup",
+                                          r->out.netbios_domain_name);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NO_SUCH_SERVICE;
+               goto done;
+       }
 
        if (r->out.domain_is_ad) {
-               werr = smbconf_set_global_parameter(ctx, "security", "ads");
-               W_ERROR_NOT_OK_GOTO_DONE(werr);
+               err = smbconf_set_global_parameter(ctx, "security", "ads");
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NO_SUCH_SERVICE;
+                       goto done;
+               }
 
-               werr = smbconf_set_global_parameter(ctx, "realm",
-                                                   r->out.dns_domain_name);
-               W_ERROR_NOT_OK_GOTO_DONE(werr);
+               err = smbconf_set_global_parameter(ctx, "realm",
+                                                  r->out.dns_domain_name);
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NO_SUCH_SERVICE;
+                       goto done;
+               }
        }
 
  done:
@@ -1515,8 +1534,11 @@ static WERROR do_unjoin_modify_vals_config(struct libnet_UnjoinCtx *r)
 
        if (r->in.unjoin_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
 
-               werr = smbconf_set_global_parameter(ctx, "security", "user");
-               W_ERROR_NOT_OK_GOTO_DONE(werr);
+               err = smbconf_set_global_parameter(ctx, "security", "user");
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NO_SUCH_SERVICE;
+                       goto done;
+               }
 
                werr = smbconf_delete_global_parameter(ctx, "workgroup");
                W_ERROR_NOT_OK_GOTO_DONE(werr);
index 7e166e8e37a17af71b40d3e736195e7045d4dcdb..4be91e35a8a32f1d35b842059074fdd0ed36bd5c 100644 (file)
@@ -231,15 +231,16 @@ static WERROR import_process_service(struct net_context *c,
                        }
                        num_includes++;
                } else {
-                       werr = smbconf_set_parameter(conf_ctx,
+                       err = smbconf_set_parameter(conf_ctx,
                                                     service->name,
                                                     service->param_names[idx],
                                                     service->param_values[idx]);
-                       if (!W_ERROR_IS_OK(werr)) {
+                       if (!SBC_ERROR_IS_OK(err)) {
                                d_fprintf(stderr,
                                          _("Error in section [%s], parameter \"%s\": %s\n"),
                                          service->name, service->param_names[idx],
-                                         win_errstr(werr));
+                                         sbcErrorString(err));
+                               werr = WERR_NOMEM;
                                goto done;
                        }
                }
@@ -729,35 +730,35 @@ static int net_conf_addshare(struct net_context *c,
         * fill the share with parameters
         */
 
-       werr = smbconf_set_parameter(conf_ctx, sharename, "path", path);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_set_parameter(conf_ctx, sharename, "path", path);
+       if (!SBC_ERROR_IS_OK(err)) {
                d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
-                         "path", win_errstr(werr));
+                         "path", sbcErrorString(err));
                goto cancel;
        }
 
        if (comment != NULL) {
-               werr = smbconf_set_parameter(conf_ctx, sharename, "comment",
-                                            comment);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_set_parameter(conf_ctx, sharename, "comment",
+                                           comment);
+               if (!SBC_ERROR_IS_OK(err)) {
                        d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
-                                 "comment", win_errstr(werr));
+                                 "comment", sbcErrorString(err));
                        goto cancel;
                }
        }
 
-       werr = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_set_parameter(conf_ctx, sharename, "guest ok", guest_ok);
+       if (!SBC_ERROR_IS_OK(err)) {
                d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
-                         "'guest ok'", win_errstr(werr));
+                         "'guest ok'", sbcErrorString(err));
                goto cancel;
        }
 
-       werr = smbconf_set_parameter(conf_ctx, sharename, "writeable",
-                                    writeable);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_set_parameter(conf_ctx, sharename, "writeable",
+                                   writeable);
+       if (!SBC_ERROR_IS_OK(err)) {
                d_fprintf(stderr, _("Error setting parameter %s: %s\n"),
-                         "writeable", win_errstr(werr));
+                         "writeable", sbcErrorString(err));
                goto cancel;
        }
 
@@ -868,11 +869,10 @@ static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
                }
        }
 
-       werr = smbconf_set_parameter(conf_ctx, service, param, value_str);
-
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_set_parameter(conf_ctx, service, param, value_str);
+       if (!SBC_ERROR_IS_OK(err)) {
                d_fprintf(stderr, _("Error setting value '%s': %s\n"),
-                         param, win_errstr(werr));
+                         param, sbcErrorString(err));
                goto cancel;
        }