libsmbconf: Convert smbconf_create_share() to smbErr.
authorAndreas Schneider <asn@samba.org>
Fri, 8 Apr 2011 13:48:01 +0000 (15:48 +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>
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 f429295568f3da1e41d7d03cbf6e5524804ad750..68f7dfc9028e6c6aa05291e7b8f1d34ab8b26888 100644 (file)
  *
  **********************************************************************/
 
-static WERROR smbconf_global_check(struct smbconf_ctx *ctx)
+static sbcErr smbconf_global_check(struct smbconf_ctx *ctx)
 {
        if (!smbconf_share_exists(ctx, GLOBAL_NAME)) {
                return smbconf_create_share(ctx, GLOBAL_NAME);
        }
-       return WERR_OK;
+
+       return SBC_ERR_OK;
 }
 
 
@@ -222,11 +223,11 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx,
 /**
  * Add a service if it does not already exist.
  */
-WERROR smbconf_create_share(struct smbconf_ctx *ctx,
+sbcErr smbconf_create_share(struct smbconf_ctx *ctx,
                            const char *servicename)
 {
        if ((servicename != NULL) && smbconf_share_exists(ctx, servicename)) {
-               return WERR_FILE_EXISTS;
+               return SBC_ERR_FILE_EXISTS;
        }
 
        return ctx->ops->create_share(ctx, servicename);
@@ -275,12 +276,14 @@ WERROR smbconf_set_parameter(struct smbconf_ctx *ctx,
 WERROR smbconf_set_global_parameter(struct smbconf_ctx *ctx,
                                    const char *param, const char *val)
 {
-       WERROR werr;
+       WERROR werr = WERR_OK;
+       sbcErr err;
 
-       werr = smbconf_global_check(ctx);
-       if (W_ERROR_IS_OK(werr)) {
-               werr = smbconf_set_parameter(ctx, GLOBAL_NAME, param, val);
+       err = smbconf_global_check(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
+       werr = smbconf_set_parameter(ctx, GLOBAL_NAME, param, val);
 
        return werr;
 }
@@ -312,13 +315,16 @@ WERROR smbconf_get_global_parameter(struct smbconf_ctx *ctx,
                                    char **valstr)
 {
        WERROR werr;
+       sbcErr err;
 
-       werr = smbconf_global_check(ctx);
-       if (W_ERROR_IS_OK(werr)) {
-               werr = smbconf_get_parameter(ctx, mem_ctx, GLOBAL_NAME, param,
-                                            valstr);
+       err = smbconf_global_check(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
 
+       werr = smbconf_get_parameter(ctx, mem_ctx, GLOBAL_NAME, param,
+                                    valstr);
+
        return werr;
 }
 
@@ -340,11 +346,13 @@ WERROR smbconf_delete_global_parameter(struct smbconf_ctx *ctx,
                                       const char *param)
 {
        WERROR werr;
+       sbcErr err;
 
-       werr = smbconf_global_check(ctx);
-       if (W_ERROR_IS_OK(werr)) {
-               werr = smbconf_delete_parameter(ctx, GLOBAL_NAME, param);
+       err = smbconf_global_check(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
+       werr = smbconf_delete_parameter(ctx, GLOBAL_NAME, param);
 
        return werr;
 }
@@ -363,12 +371,14 @@ WERROR smbconf_get_global_includes(struct smbconf_ctx *ctx,
                                   uint32_t *num_includes, char ***includes)
 {
        WERROR werr;
+       sbcErr err;
 
-       werr = smbconf_global_check(ctx);
-       if (W_ERROR_IS_OK(werr)) {
-               werr = smbconf_get_includes(ctx, mem_ctx, GLOBAL_NAME,
-                                           num_includes, includes);
+       err = smbconf_global_check(ctx);
+       if (SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
+       werr = smbconf_get_includes(ctx, mem_ctx, GLOBAL_NAME,
+                                   num_includes, includes);
 
        return werr;
 }
@@ -385,12 +395,14 @@ WERROR smbconf_set_global_includes(struct smbconf_ctx *ctx,
                                   const char **includes)
 {
        WERROR werr;
+       sbcErr err;
 
-       werr = smbconf_global_check(ctx);
-       if (W_ERROR_IS_OK(werr)) {
-               werr = smbconf_set_includes(ctx, GLOBAL_NAME,
-                                           num_includes, includes);
+       err = smbconf_global_check(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
+       werr = smbconf_set_includes(ctx, GLOBAL_NAME,
+                                   num_includes, includes);
 
        return werr;
 }
@@ -404,11 +416,13 @@ WERROR smbconf_delete_includes(struct smbconf_ctx *ctx, const char *service)
 WERROR smbconf_delete_global_includes(struct smbconf_ctx *ctx)
 {
        WERROR werr;
+       sbcErr err;
 
-       werr = smbconf_global_check(ctx);
-       if (W_ERROR_IS_OK(werr)) {
-               werr = smbconf_delete_includes(ctx, GLOBAL_NAME);
+       err = smbconf_global_check(ctx);
+       if (!SBC_ERROR_IS_OK(err)) {
+               return WERR_GENERAL_FAILURE;
        }
+       werr = smbconf_delete_includes(ctx, GLOBAL_NAME);
 
        return werr;
 }
index af50dfb9a57f5f35022a497bd1e310e9403cc849..c1a82b5cf8e3e2b0a330342a094598f16d2fba0c 100644 (file)
@@ -84,7 +84,7 @@ sbcErr smbconf_get_share_names(struct smbconf_ctx *ctx,
                               uint32_t *num_shares,
                               char ***share_names);
 bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename);
-WERROR smbconf_create_share(struct smbconf_ctx *ctx, const char *servicename);
+sbcErr smbconf_create_share(struct smbconf_ctx *ctx, const char *servicename);
 WERROR smbconf_get_share(struct smbconf_ctx *ctx,
                         TALLOC_CTX *mem_ctx,
                         const char *servicename,
index 4058ade2e446d18d84f7ee33893a6fa391cfe5c8..222497d0319b04e09b211f89eee44bd045105163 100644 (file)
@@ -41,7 +41,7 @@ struct smbconf_ops {
                                  uint32_t *num_shares,
                                  char ***share_names);
        bool (*share_exists)(struct smbconf_ctx *ctx, const char *service);
-       WERROR (*create_share)(struct smbconf_ctx *ctx, const char *service);
+       sbcErr (*create_share)(struct smbconf_ctx *ctx, const char *service);
        WERROR (*get_share)(struct smbconf_ctx *ctx,
                            TALLOC_CTX *mem_ctx,
                            const char *servicename,
index 444fa086633f3acadd8a7f0b6a6a677f4ed1cce3..1be27e6bbde3a781932d9ca6afca6465bcb76854 100644 (file)
@@ -385,10 +385,10 @@ static bool smbconf_txt_share_exists(struct smbconf_ctx *ctx,
 /**
  * Add a service if it does not already exist
  */
-static WERROR smbconf_txt_create_share(struct smbconf_ctx *ctx,
+static sbcErr smbconf_txt_create_share(struct smbconf_ctx *ctx,
                                       const char *servicename)
 {
-       return WERR_NOT_SUPPORTED;
+       return SBC_ERR_NOT_SUPPORTED;
 }
 
 /**
index f6b6d8d46bbcda08524939174b73823dfae1b2e4..78a3145db50dc0f5041a8e0ab4aa21c924e419b2 100644 (file)
@@ -127,12 +127,13 @@ static bool smbconf_value_exists(struct registry_key *key, const char *param)
 /**
  * create a subkey of the base key (i.e. a service...)
  */
-static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
+static sbcErr smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
                                             struct smbconf_ctx *ctx,
                                             const char * subkeyname,
                                             struct registry_key **newkey)
 {
-       WERROR werr = WERR_OK;
+       WERROR werr;
+       sbcErr err = SBC_ERR_OK;
        TALLOC_CTX *create_ctx;
        enum winreg_CreateAction action = REG_ACTION_NONE;
 
@@ -145,15 +146,16 @@ static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
                             REG_KEY_WRITE, newkey, &action);
        if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) {
                DEBUG(10, ("Key '%s' already exists.\n", subkeyname));
-               werr = WERR_FILE_EXISTS;
+               err = SBC_ERR_FILE_EXISTS;
        }
        if (!W_ERROR_IS_OK(werr)) {
                DEBUG(5, ("Error creating key %s: %s\n",
                         subkeyname, win_errstr(werr)));
+               err = SBC_ERR_UNKNOWN_FAILURE;
        }
 
        talloc_free(create_ctx);
-       return werr;
+       return err;
 }
 
 /**
@@ -864,21 +866,21 @@ static bool smbconf_reg_share_exists(struct smbconf_ctx *ctx,
 /**
  * Add a service if it does not already exist - registry version
  */
-static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx,
+static sbcErr smbconf_reg_create_share(struct smbconf_ctx *ctx,
                                       const char *servicename)
 {
-       WERROR werr;
+       sbcErr err;
        struct registry_key *key = NULL;
 
        if (servicename == NULL) {
-               return WERR_OK;
+               return SBC_ERR_OK;
        }
 
-       werr = smbconf_reg_create_service_key(talloc_tos(), ctx,
-                                             servicename, &key);
+       err = smbconf_reg_create_service_key(talloc_tos(), ctx,
+                                            servicename, &key);
 
        talloc_free(key);
-       return werr;
+       return err;
 }
 
 /**
index 192088c6ba5eeabaafc30dab4d9492971d93ec6e..3b6005a2b9599ef45c96c4aded165ea3a92ef732 100644 (file)
@@ -180,6 +180,7 @@ static WERROR import_process_service(struct net_context *c,
 {
        uint32_t idx;
        WERROR werr = WERR_OK;
+       sbcErr err;
        uint32_t num_includes = 0;
        char **includes = NULL;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
@@ -205,8 +206,9 @@ static WERROR import_process_service(struct net_context *c,
                        goto done;
                }
        }
-       werr = smbconf_create_share(conf_ctx, service->name);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_create_share(conf_ctx, service->name);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_GENERAL_FAILURE;
                goto done;
        }
 
@@ -578,6 +580,7 @@ static int net_conf_addshare(struct net_context *c,
 {
        int ret = -1;
        WERROR werr = WERR_OK;
+       sbcErr err;
        char *sharename = NULL;
        const char *path = NULL;
        const char *comment = NULL;
@@ -714,10 +717,10 @@ static int net_conf_addshare(struct net_context *c,
         * create the share
         */
 
-       werr = smbconf_create_share(conf_ctx, sharename);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_create_share(conf_ctx, sharename);
+       if (!SBC_ERROR_IS_OK(err)) {
                d_fprintf(stderr, _("Error creating share %s: %s\n"),
-                         sharename, win_errstr(werr));
+                         sharename, sbcErrorString(err));
                goto cancel;
        }
 
@@ -820,6 +823,7 @@ static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
 {
        int ret = -1;
        WERROR werr = WERR_OK;
+       sbcErr err;
        char *service = NULL;
        char *param = NULL;
        const char *value_str = NULL;
@@ -855,10 +859,10 @@ static int net_conf_setparm(struct net_context *c, struct smbconf_ctx *conf_ctx,
        }
 
        if (!smbconf_share_exists(conf_ctx, service)) {
-               werr = smbconf_create_share(conf_ctx, service);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_create_share(conf_ctx, service);
+               if (!SBC_ERROR_IS_OK(err)) {
                        d_fprintf(stderr, _("Error creating share '%s': %s\n"),
-                                 service, win_errstr(werr));
+                                 service, sbcErrorString(err));
                        goto cancel;
                }
        }