libsmbconf: Convert smbconf_get_parameter() to sbcErr.
authorAndreas Schneider <asn@samba.org>
Mon, 11 Apr 2011 11:50:53 +0000 (13:50 +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/smbconf/smbconf_reg.c
source3/utils/net_conf.c

index 786f4d32d13ecad820425753e6c1e163e5e1faab..02c49cc877dbb885fb56b01c5f6b3513cea56fc0 100644 (file)
@@ -291,14 +291,14 @@ sbcErr smbconf_set_global_parameter(struct smbconf_ctx *ctx,
 /**
  * get the value of a configuration parameter as a string
  */
-WERROR smbconf_get_parameter(struct smbconf_ctx *ctx,
+sbcErr smbconf_get_parameter(struct smbconf_ctx *ctx,
                             TALLOC_CTX *mem_ctx,
                             const char *service,
                             const char *param,
                             char **valstr)
 {
        if (valstr == NULL) {
-               return WERR_INVALID_PARAM;
+               return SBC_ERR_INVALID_PARAM;
        }
 
        return ctx->ops->get_parameter(ctx, mem_ctx, service, param, valstr);
@@ -309,23 +309,22 @@ WERROR smbconf_get_parameter(struct smbconf_ctx *ctx,
  *
  * Create [global] if it does not exist.
  */
-WERROR smbconf_get_global_parameter(struct smbconf_ctx *ctx,
+sbcErr smbconf_get_global_parameter(struct smbconf_ctx *ctx,
                                    TALLOC_CTX *mem_ctx,
                                    const char *param,
                                    char **valstr)
 {
-       WERROR werr;
        sbcErr err;
 
        err = smbconf_global_check(ctx);
        if (!SBC_ERROR_IS_OK(err)) {
-               return WERR_GENERAL_FAILURE;
+               return err;
        }
 
-       werr = smbconf_get_parameter(ctx, mem_ctx, GLOBAL_NAME, param,
-                                    valstr);
+       err = smbconf_get_parameter(ctx, mem_ctx, GLOBAL_NAME, param,
+                                   valstr);
 
-       return werr;
+       return err;
 }
 
 /**
index 1471ceca1d016e82182218affe06d3e6006004dd..15476f146089cd46688727c3fb9365fc9c388e57 100644 (file)
@@ -42,6 +42,7 @@ enum _sbcErrType {
 typedef enum _sbcErrType sbcErr;
 
 #define SBC_ERROR_IS_OK(x) ((x) == SBC_ERR_OK)
+#define SBC_ERROR_EQUAL(x,y) ((x) == (y))
 
 struct smbconf_ctx;
 
@@ -97,12 +98,12 @@ sbcErr smbconf_set_parameter(struct smbconf_ctx *ctx,
                             const char *valstr);
 sbcErr smbconf_set_global_parameter(struct smbconf_ctx *ctx,
                                    const char *param, const char *val);
-WERROR smbconf_get_parameter(struct smbconf_ctx *ctx,
+sbcErr smbconf_get_parameter(struct smbconf_ctx *ctx,
                             TALLOC_CTX *mem_ctx,
                             const char *service,
                             const char *param,
                             char **valstr);
-WERROR smbconf_get_global_parameter(struct smbconf_ctx *ctx,
+sbcErr smbconf_get_global_parameter(struct smbconf_ctx *ctx,
                                    TALLOC_CTX *mem_ctx,
                                    const char *param,
                                    char **valstr);
index b11a1420ae0041de6b2d24e7bc4bfd68176b9b07..9bfcbe097af0e0f208e27ffc737b7a6bbe273d68 100644 (file)
@@ -52,7 +52,7 @@ struct smbconf_ops {
                                const char *service,
                                const char *param,
                                const char *valstr);
-       WERROR (*get_parameter)(struct smbconf_ctx *ctx,
+       sbcErr (*get_parameter)(struct smbconf_ctx *ctx,
                                TALLOC_CTX *mem_ctx,
                                const char *service,
                                const char *param,
index 0f77254d38137bd4dcf14d60926b00ac30328ef9..e31009e7b26c4f9958ed4fe83a10546b3e516c50 100644 (file)
@@ -482,7 +482,7 @@ static sbcErr smbconf_txt_set_parameter(struct smbconf_ctx *ctx,
 /**
  * get the value of a configuration parameter as a string
  */
-static WERROR smbconf_txt_get_parameter(struct smbconf_ctx *ctx,
+static sbcErr smbconf_txt_get_parameter(struct smbconf_ctx *ctx,
                                        TALLOC_CTX *mem_ctx,
                                        const char *service,
                                        const char *param,
@@ -494,7 +494,7 @@ static WERROR smbconf_txt_get_parameter(struct smbconf_ctx *ctx,
 
        err = smbconf_txt_load_file(ctx);
        if (!SBC_ERROR_IS_OK(err)) {
-               return WERR_GENERAL_FAILURE;
+               return err;
        }
 
        found = smbconf_find_in_array(service,
@@ -502,7 +502,7 @@ static WERROR smbconf_txt_get_parameter(struct smbconf_ctx *ctx,
                                      pd(ctx)->cache->num_shares,
                                      &share_index);
        if (!found) {
-               return WERR_NO_SUCH_SERVICE;
+               return SBC_ERR_NO_SUCH_SERVICE;
        }
 
        found = smbconf_reverse_find_in_array(param,
@@ -510,17 +510,17 @@ static WERROR smbconf_txt_get_parameter(struct smbconf_ctx *ctx,
                                pd(ctx)->cache->num_params[share_index],
                                &param_index);
        if (!found) {
-               return WERR_INVALID_PARAM;
+               return SBC_ERR_INVALID_PARAM;
        }
 
        *valstr = talloc_strdup(mem_ctx,
                        pd(ctx)->cache->param_values[share_index][param_index]);
 
        if (*valstr == NULL) {
-               return WERR_NOMEM;
+               return SBC_ERR_NOMEM;
        }
 
-       return WERR_OK;
+       return SBC_ERR_OK;
 }
 
 /**
index f7faf51e7d087e4f21b095ec9a73063ea78df48e..42eb6d18b93d026a2ccf6657de21e30333caf2bf 100644 (file)
@@ -989,7 +989,7 @@ done:
 /**
  * get the value of a configuration parameter as a string
  */
-static WERROR smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
+static sbcErr smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
                                        TALLOC_CTX *mem_ctx,
                                        const char *service,
                                        const char *param,
@@ -1003,35 +1003,34 @@ static WERROR smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
        err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
                                           REG_KEY_READ, &key);
        if (!SBC_ERROR_IS_OK(err)) {
-               werr = WERR_NOMEM;
                goto done;
        }
 
        if (!smbconf_reg_valname_valid(param)) {
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
 
        if (!smbconf_value_exists(key, param)) {
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
 
        werr = reg_queryvalue(mem_ctx, key, param, &value);
        if (!W_ERROR_IS_OK(werr)) {
+               err = SBC_ERR_NOMEM;
                goto done;
        }
 
        *valstr = smbconf_format_registry_value(mem_ctx, value);
-
        if (*valstr == NULL) {
-               werr = WERR_NOMEM;
+               err = SBC_ERR_NOMEM;
        }
 
 done:
        talloc_free(key);
        talloc_free(value);
-       return werr;
+       return err;
 }
 
 /**
index 4be91e35a8a32f1d35b842059074fdd0ed36bd5c..187735027b488cf3e7b6a4037811e6e4458e8920 100644 (file)
@@ -902,7 +902,7 @@ static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
                            int argc, const char **argv)
 {
        int ret = -1;
-       WERROR werr = WERR_OK;
+       sbcErr err;
        char *service = NULL;
        char *param = NULL;
        char *valstr = NULL;
@@ -931,21 +931,20 @@ static int net_conf_getparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
                goto done;
        }
 
-       werr = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
-
-       if (W_ERROR_EQUAL(werr, WERR_NO_SUCH_SERVICE)) {
+       err = smbconf_get_parameter(conf_ctx, mem_ctx, service, param, &valstr);
+       if (SBC_ERROR_EQUAL(err, SBC_ERR_NO_SUCH_SERVICE)) {
                d_fprintf(stderr,
                          _("Error: given service '%s' does not exist.\n"),
                          service);
                goto done;
-       } else if (W_ERROR_EQUAL(werr, WERR_INVALID_PARAM)) {
+       } else if (SBC_ERROR_EQUAL(err, SBC_ERR_INVALID_PARAM)) {
                d_fprintf(stderr,
                          _("Error: given parameter '%s' is not set.\n"),
                          param);
                goto done;
-       } else if (!W_ERROR_IS_OK(werr)) {
+       } else if (!SBC_ERROR_IS_OK(err)) {
                d_fprintf(stderr, _("Error getting value '%s': %s.\n"),
-                         param, win_errstr(werr));
+                         param, sbcErrorString(err));
                goto done;
        }