libsmbconf: Convert smbconf_init() to sbcErr.
authorAndreas Schneider <asn@samba.org>
Thu, 7 Apr 2011 15:19:03 +0000 (17:19 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 10 May 2011 17:13:20 +0000 (19:13 +0200)
Signed-off-by: Michael Adam <obnox@samba.org>
13 files changed:
lib/smbconf/smbconf_private.h
lib/smbconf/smbconf_txt.c
lib/smbconf/smbconf_txt.h
lib/smbconf/smbconf_util.c
source3/lib/netapi/serverinfo.c
source3/lib/smbconf/smbconf_init.c
source3/lib/smbconf/smbconf_init.h
source3/lib/smbconf/smbconf_reg.c
source3/lib/smbconf/smbconf_reg.h
source3/lib/smbconf/testsuite.c
source3/libnet/libnet_join.c
source3/param/loadparm.c
source3/utils/net_conf.c

index e6998ad6392241a794167074a4adaefa7d7eacc3..2b56367f6c77f991c106e8afad93c0bf382fdf8e 100644 (file)
@@ -27,7 +27,7 @@
 #include "lib/smbconf/smbconf.h"
 
 struct smbconf_ops {
-       WERROR (*init)(struct smbconf_ctx *ctx, const char *path);
+       sbcErr (*init)(struct smbconf_ctx *ctx, const char *path);
        int (*shutdown)(struct smbconf_ctx *ctx);
        bool (*requires_messaging)(struct smbconf_ctx *ctx);
        bool (*is_writeable)(struct smbconf_ctx *ctx);
@@ -79,7 +79,7 @@ struct smbconf_ctx {
        void *data; /* private data for use in backends */
 };
 
-WERROR smbconf_init_internal(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+sbcErr smbconf_init_internal(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
                             const char *path, struct smbconf_ops *ops);
 
 WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
index 2114841b817240cea846b65f348bfbd187c41b96..f7bae4e31528e0cdb8c4a4c6087457c836216473 100644 (file)
@@ -165,7 +165,7 @@ static void smbconf_txt_flush_cache(struct smbconf_ctx *ctx)
        pd(ctx)->cache = NULL;
 }
 
-static WERROR smbconf_txt_init_cache(struct smbconf_ctx *ctx)
+static sbcErr smbconf_txt_init_cache(struct smbconf_ctx *ctx)
 {
        if (pd(ctx)->cache != NULL) {
                smbconf_txt_flush_cache(ctx);
@@ -174,40 +174,40 @@ static WERROR smbconf_txt_init_cache(struct smbconf_ctx *ctx)
        pd(ctx)->cache = talloc_zero(pd(ctx), struct txt_cache);
 
        if (pd(ctx)->cache == NULL) {
-               return WERR_NOMEM;
+               return SBC_ERR_NOMEM;
        }
 
-       return WERR_OK;
+       return SBC_ERR_OK;
 }
 
-static WERROR smbconf_txt_load_file(struct smbconf_ctx *ctx)
+static sbcErr smbconf_txt_load_file(struct smbconf_ctx *ctx)
 {
-       WERROR werr;
+       sbcErr err;
        uint64_t new_csn;
 
        if (!file_exist(ctx->path)) {
-               return WERR_BADFILE;
+               return SBC_ERR_BADFILE;
        }
 
        new_csn = (uint64_t)file_modtime(ctx->path);
        if (new_csn == pd(ctx)->csn) {
-               return WERR_OK;
+               return SBC_ERR_OK;
        }
 
-       werr = smbconf_txt_init_cache(ctx);
-       if (!W_ERROR_IS_OK(werr)) {
-               return werr;
+       err = smbconf_txt_init_cache(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return err;
        }
 
        if (!pm_process(ctx->path, smbconf_txt_do_section,
                        smbconf_txt_do_parameter, pd(ctx)))
        {
-               return WERR_CAN_NOT_COMPLETE;
+               return SBC_ERR_CAN_NOT_COMPLETE;
        }
 
        pd(ctx)->csn = new_csn;
 
-       return WERR_OK;
+       return SBC_ERR_OK;
 }
 
 
@@ -220,24 +220,24 @@ static WERROR smbconf_txt_load_file(struct smbconf_ctx *ctx)
 /**
  * initialize the text based smbconf backend
  */
-static WERROR smbconf_txt_init(struct smbconf_ctx *ctx, const char *path)
+static sbcErr smbconf_txt_init(struct smbconf_ctx *ctx, const char *path)
 {
        if (path == NULL) {
-               return WERR_BADFILE;
+               return SBC_ERR_BADFILE;
        }
        ctx->path = talloc_strdup(ctx, path);
        if (ctx->path == NULL) {
-               return WERR_NOMEM;
+               return SBC_ERR_NOMEM;
        }
 
        ctx->data = talloc_zero(ctx, struct txt_private_data);
        if (ctx->data == NULL) {
-               return WERR_NOMEM;
+               return SBC_ERR_NOMEM;
        }
 
        pd(ctx)->verbatim = true;
 
-       return WERR_OK;
+       return SBC_ERR_OK;
 }
 
 static int smbconf_txt_shutdown(struct smbconf_ctx *ctx)
@@ -258,7 +258,14 @@ static bool smbconf_txt_is_writeable(struct smbconf_ctx *ctx)
 
 static WERROR smbconf_txt_open(struct smbconf_ctx *ctx)
 {
-       return smbconf_txt_load_file(ctx);
+       sbcErr err;
+
+       err = smbconf_txt_load_file(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
+       }
+
+       return WERR_OK;
 }
 
 static int smbconf_txt_close(struct smbconf_ctx *ctx)
@@ -302,6 +309,7 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
        uint32_t added_count = 0;
        TALLOC_CTX *tmp_ctx = NULL;
        WERROR werr = WERR_OK;
+       sbcErr err = SBC_ERR_OK;
        char **tmp_share_names = NULL;
 
        if ((num_shares == NULL) || (share_names == NULL)) {
@@ -309,9 +317,9 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
                goto done;
        }
 
-       werr = smbconf_txt_load_file(ctx);
-       if (!W_ERROR_IS_OK(werr)) {
-               return werr;
+       err = smbconf_txt_load_file(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
 
        tmp_ctx = talloc_stackframe();
@@ -371,10 +379,10 @@ done:
 static bool smbconf_txt_share_exists(struct smbconf_ctx *ctx,
                                     const char *servicename)
 {
-       WERROR werr;
+       sbcErr err;
 
-       werr = smbconf_txt_load_file(ctx);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_txt_load_file(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
                return false;
        }
 
@@ -401,14 +409,15 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
                                    struct smbconf_service **service)
 {
        WERROR werr;
+       sbcErr err;
        uint32_t sidx, count;
        bool found;
        TALLOC_CTX *tmp_ctx = NULL;
        struct smbconf_service *tmp_service = NULL;
 
-       werr = smbconf_txt_load_file(ctx);
-       if (!W_ERROR_IS_OK(werr)) {
-               return werr;
+       err = smbconf_txt_load_file(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
 
        found = smbconf_find_in_array(servicename,
@@ -489,13 +498,13 @@ static WERROR smbconf_txt_get_parameter(struct smbconf_ctx *ctx,
                                        const char *param,
                                        char **valstr)
 {
-       WERROR werr;
+       sbcErr err;
        bool found;
        uint32_t share_index, param_index;
 
-       werr = smbconf_txt_load_file(ctx);
-       if (!W_ERROR_IS_OK(werr)) {
-               return werr;
+       err = smbconf_txt_load_file(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
 
        found = smbconf_find_in_array(service,
@@ -541,15 +550,16 @@ static WERROR smbconf_txt_get_includes(struct smbconf_ctx *ctx,
                                       char ***includes)
 {
        WERROR werr;
+       sbcErr err;
        bool found;
        uint32_t sidx, count;
        TALLOC_CTX *tmp_ctx = NULL;
        uint32_t tmp_num_includes = 0;
        char **tmp_includes = NULL;
 
-       werr = smbconf_txt_load_file(ctx);
-       if (!W_ERROR_IS_OK(werr)) {
-               return werr;
+       err = smbconf_txt_load_file(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
 
        found = smbconf_find_in_array(service,
@@ -654,15 +664,15 @@ static struct smbconf_ops smbconf_ops_txt = {
  * initialize the smbconf text backend
  * the only function that is exported from this module
  */
-WERROR smbconf_init_txt(TALLOC_CTX *mem_ctx,
+sbcErr smbconf_init_txt(TALLOC_CTX *mem_ctx,
                        struct smbconf_ctx **conf_ctx,
                        const char *path)
 {
-       WERROR werr;
+       sbcErr err;
 
-       werr = smbconf_init_internal(mem_ctx, conf_ctx, path, &smbconf_ops_txt);
-       if (!W_ERROR_IS_OK(werr)) {
-               return werr;
+       err = smbconf_init_internal(mem_ctx, conf_ctx, path, &smbconf_ops_txt);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return err;
        }
 
        return smbconf_txt_load_file(*conf_ctx);
index 688bbc9d4833658f63bedad89bda0d087db5fa89..72d6207521c7b3101457625b463fe7a7ba4e4c42 100644 (file)
@@ -26,7 +26,7 @@ struct smbconf_ctx;
  * initialization functions for the text/file backend modules
  */
 
-WERROR smbconf_init_txt(TALLOC_CTX *mem_ctx,
+sbcErr smbconf_init_txt(TALLOC_CTX *mem_ctx,
                        struct smbconf_ctx **conf_ctx,
                        const char *path);
 
index b309a3454b13d5fee8ad164b9d99ac30fca7236c..63ce50d6689c08776521ac27af012640490d8fde 100644 (file)
@@ -39,36 +39,36 @@ static int smbconf_destroy_ctx(struct smbconf_ctx *ctx)
  * After the work with the configuration is completed, smbconf_shutdown()
  * should be called.
  */
-WERROR smbconf_init_internal(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+sbcErr smbconf_init_internal(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
                             const char *path, struct smbconf_ops *ops)
 {
-       WERROR werr = WERR_OK;
+       sbcErr err = SBC_ERR_OK;
        struct smbconf_ctx *ctx;
 
        if (conf_ctx == NULL) {
-               return WERR_INVALID_PARAM;
+               return SBC_ERR_INVALID_PARAM;
        }
 
        ctx = talloc_zero(mem_ctx, struct smbconf_ctx);
        if (ctx == NULL) {
-               return WERR_NOMEM;
+               return SBC_ERR_NOMEM;
        }
 
        ctx->ops = ops;
 
-       werr = ctx->ops->init(ctx, path);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = ctx->ops->init(ctx, path);
+       if (!SBC_ERROR_IS_OK(err)) {
                goto fail;
        }
 
        talloc_set_destructor(ctx, smbconf_destroy_ctx);
 
        *conf_ctx = ctx;
-       return werr;
+       return err;
 
 fail:
        talloc_free(ctx);
-       return werr;
+       return err;
 }
 
 
index 22c7df69d12120985074d3640c7b22edae5f620a..e995bdaf474eaeeb21d3be7c638106e3099afba2 100644 (file)
@@ -541,6 +541,7 @@ static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
                                      struct NetServerSetInfo *r)
 {
        WERROR werr;
+       sbcErr err;
        struct smbconf_ctx *conf_ctx;
        struct srvsvc_NetSrvInfo1005 *info1005;
 
@@ -563,8 +564,12 @@ static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
                return WERR_NOT_SUPPORTED;
        }
 
-       werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_init_reg(ctx, &conf_ctx, NULL);
+       if (!SBC_ERROR_IS_OK(err)) {
+               libnetapi_set_error_string(ctx,
+                       "Could not initialize backend: %s",
+                       sbcErrorString(err));
+               werr = WERR_NO_SUCH_SERVICE;
                goto done;
        }
 
index 36c51de5f03f2d336aec52d5a15f8789b09e843d..2587a4fc53d6cfdcf71efe08728b2ef717696967 100644 (file)
  * -  "registry" or "reg"
  * -  "txt" or "file"
  */
-WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+sbcErr smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
                    const char *source)
 {
-       WERROR werr;
+       sbcErr err;
        char *backend = NULL;
        char *path = NULL;
        char *sep;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
        if (conf_ctx == NULL) {
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
 
        if ((source == NULL) || (*source == '\0')) {
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
 
        backend = talloc_strdup(tmp_ctx, source);
        if (backend == NULL) {
-               werr = WERR_NOMEM;
+               err = SBC_ERR_NOMEM;
                goto done;
        }
 
@@ -69,16 +69,16 @@ WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
        }
 
        if (strequal(backend, "registry") || strequal(backend, "reg")) {
-               werr = smbconf_init_reg(mem_ctx, conf_ctx, path);
+               err = smbconf_init_reg(mem_ctx, conf_ctx, path);
        } else if (strequal(backend, "file") || strequal(backend, "txt")) {
-               werr = smbconf_init_txt(mem_ctx, conf_ctx, path);
+               err = smbconf_init_txt(mem_ctx, conf_ctx, path);
        } else if (sep == NULL) {
                /*
                 * If no separator was given in the source, and the string is
                 * not a known backend, assume file backend and use the source
                 * string as a path argument.
                 */
-               werr = smbconf_init_txt(mem_ctx, conf_ctx, backend);
+               err = smbconf_init_txt(mem_ctx, conf_ctx, backend);
        } else {
                /*
                 * Separator was specified but this is not a known backend.
@@ -87,10 +87,10 @@ WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
                 * This may occur with an include directive like this:
                 * 'include = /path/to/file.%T'
                 */
-               werr = smbconf_init_txt(mem_ctx, conf_ctx, source);
+               err = smbconf_init_txt(mem_ctx, conf_ctx, source);
        }
 
 done:
        talloc_free(tmp_ctx);
-       return werr;
+       return err;
 }
index abd62df2045d52c7ec137cfc5f7e36c998e3b074..45ea809624026ea4c6b80c014877cb5f58417a86 100644 (file)
@@ -26,7 +26,7 @@ struct smbconf_ctx;
  * intialization dispatcher function.
  * takes source string in the form of "backend:path"
  */
-WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+sbcErr smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
                    const char *source);
 
 #endif /*  _LIBSMBCONF_INIT_H_  */
index 67df03cbd2d67ec69d193ea0924e86b1f4c378f0..09b4682de05ea0d723416ab2c9359d21d9008a98 100644 (file)
@@ -1156,7 +1156,7 @@ struct smbconf_ops smbconf_ops_reg = {
  * initialize the smbconf registry backend
  * the only function that is exported from this module
  */
-WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+sbcErr smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
                        const char *path)
 {
        return smbconf_init_internal(mem_ctx, conf_ctx, path, &smbconf_ops_reg);
index 7f54b6e32db88a14acb487a8d6fcf870ebf0398c..2c49057a94672f1a42fd2a3a5d42372bcfe4452c 100644 (file)
@@ -26,7 +26,7 @@ struct smbconf_ctx;
  * initialization functions for the registry backend modules
  */
 
-WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+sbcErr smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
                        const char *path);
 
 
index 80754dd20c3cc564fe55ecade2d98d491cf88321..5bde5e162156fd8bbc24172ad3f3549d5a4a2545 100644 (file)
@@ -204,6 +204,7 @@ static bool create_conf_file(const char *filename)
 static bool torture_smbconf_txt(void)
 {
        WERROR werr;
+       sbcErr err;
        bool ret = true;
        const char *filename = "/tmp/smb.conf.smbconf_testsuite";
        struct smbconf_ctx *conf_ctx = NULL;
@@ -217,9 +218,9 @@ static bool torture_smbconf_txt(void)
        }
 
        printf("TEST: init\n");
-       werr = smbconf_init_txt(mem_ctx, &conf_ctx, filename);
-       if (!W_ERROR_IS_OK(werr)) {
-               printf("FAIL: text backend failed: %s\n", win_errstr(werr));
+       err = smbconf_init_txt(mem_ctx, &conf_ctx, filename);
+       if (!SBC_ERROR_IS_OK(err)) {
+               printf("FAIL: text backend failed: %s\n", sbcErrorString(err));
                ret = false;
                goto done;
        }
@@ -246,6 +247,7 @@ done:
 static bool torture_smbconf_reg(void)
 {
        WERROR werr;
+       sbcErr err;
        bool ret = true;
        struct smbconf_ctx *conf_ctx = NULL;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
@@ -253,9 +255,9 @@ static bool torture_smbconf_reg(void)
        printf("test: registry backend\n");
 
        printf("TEST: init\n");
-       werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
-       if (!W_ERROR_IS_OK(werr)) {
-               printf("FAIL: init failed: %s\n", win_errstr(werr));
+       err = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
+       if (!SBC_ERROR_IS_OK(err)) {
+               printf("FAIL: init failed: %s\n", sbcErrorString(err));
                ret = false;
                goto done;
        }
index b65bac907df0e72f55e80224647e797c48f12d30..5f7f93e087113e10d52a85ed40049afccb3ba567 100644 (file)
@@ -1456,10 +1456,12 @@ done:
 static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
 {
        WERROR werr;
+       sbcErr err;
        struct smbconf_ctx *ctx;
 
-       werr = smbconf_init_reg(r, &ctx, NULL);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_init_reg(r, &ctx, NULL);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NO_SUCH_SERVICE;
                goto done;
        }
 
@@ -1502,10 +1504,12 @@ static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
 static WERROR do_unjoin_modify_vals_config(struct libnet_UnjoinCtx *r)
 {
        WERROR werr = WERR_OK;
+       sbcErr err;
        struct smbconf_ctx *ctx;
 
-       werr = smbconf_init_reg(r, &ctx, NULL);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_init_reg(r, &ctx, NULL);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NO_SUCH_SERVICE;
                goto done;
        }
 
index bf504a41b7d0595236266770298fcd5595a7371e..53fd3dad50f6a86e8c28ca076b91fc56264ed0a0 100644 (file)
@@ -7208,14 +7208,14 @@ bool service_ok(int iService)
 
 static struct smbconf_ctx *lp_smbconf_ctx(void)
 {
-       WERROR werr;
+       sbcErr err;
        static struct smbconf_ctx *conf_ctx = NULL;
 
        if (conf_ctx == NULL) {
-               werr = smbconf_init(NULL, &conf_ctx, "registry:");
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_init(NULL, &conf_ctx, "registry:");
+               if (!SBC_ERROR_IS_OK(err)) {
                        DEBUG(1, ("error initializing registry configuration: "
-                                 "%s\n", win_errstr(werr)));
+                                 "%s\n", sbcErrorString(err)));
                        conf_ctx = NULL;
                }
        }
index fd00c008dd6f6384bb1b3d6a61ab179e1e6bfc91..9ed19f1fdb9007311c849a93263a8e9c83a324c7 100644 (file)
@@ -316,6 +316,7 @@ static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx,
        TALLOC_CTX *mem_ctx;
        struct smbconf_ctx *txt_ctx;
        WERROR werr;
+       sbcErr err;
 
        if (c->display_usage)
                return net_conf_import_usage(c, argc, argv);
@@ -347,10 +348,11 @@ static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx,
                goto done;
        }
 
-       werr = smbconf_init(mem_ctx, &txt_ctx, conf_source);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_init(mem_ctx, &txt_ctx, conf_source);
+       if (!SBC_ERROR_IS_OK(err)) {
                d_printf(_("error loading file '%s': %s\n"), filename,
-                        win_errstr(werr));
+                        sbcErrorString(err));
+               werr = WERR_NO_SUCH_SERVICE;
                goto done;
        }
 
@@ -1140,14 +1142,13 @@ static int net_conf_wrap_function(struct net_context *c,
                                            int, const char **),
                                  int argc, const char **argv)
 {
-       WERROR werr;
+       sbcErr err;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
        struct smbconf_ctx *conf_ctx;
        int ret = -1;
 
-       werr = smbconf_init(mem_ctx, &conf_ctx, "registry:");
-
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_init(mem_ctx, &conf_ctx, "registry:");
+       if (!SBC_ERROR_IS_OK(err)) {
                return -1;
        }