libsmbconf: Convert smbconf_get_share_names() to sbcErr.
authorAndreas Schneider <asn@samba.org>
Fri, 8 Apr 2011 12:19:15 +0000 (14:19 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 11 May 2011 10:03:27 +0000 (12:03 +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
lib/smbconf/smbconf_util.c
source3/lib/smbconf/smbconf_reg.c
source3/utils/net_conf.c

index 366b78dd6ec0ec21ba5d3717b8f5eae09491d9f6..f429295568f3da1e41d7d03cbf6e5524804ad750 100644 (file)
@@ -146,6 +146,7 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx,
                          struct smbconf_service ***services)
 {
        WERROR werr = WERR_OK;
+       sbcErr err;
        TALLOC_CTX *tmp_ctx = NULL;
        uint32_t tmp_num_shares;
        char **tmp_share_names;
@@ -159,9 +160,10 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx,
 
        tmp_ctx = talloc_stackframe();
 
-       werr = smbconf_get_share_names(ctx, tmp_ctx, &tmp_num_shares,
-                                      &tmp_share_names);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_get_share_names(ctx, tmp_ctx, &tmp_num_shares,
+                                     &tmp_share_names);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_GENERAL_FAILURE;
                goto done;
        }
 
@@ -199,7 +201,7 @@ done:
 /**
  * get the list of share names defined in the configuration.
  */
-WERROR smbconf_get_share_names(struct smbconf_ctx *ctx,
+sbcErr smbconf_get_share_names(struct smbconf_ctx *ctx,
                               TALLOC_CTX *mem_ctx,
                               uint32_t *num_shares,
                               char ***share_names)
index 535582565abaddefd6aacc3f2dfc24b42ff211e8..af50dfb9a57f5f35022a497bd1e310e9403cc849 100644 (file)
@@ -79,7 +79,7 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx,
                          TALLOC_CTX *mem_ctx,
                          uint32_t *num_shares,
                          struct smbconf_service ***services);
-WERROR smbconf_get_share_names(struct smbconf_ctx *ctx,
+sbcErr smbconf_get_share_names(struct smbconf_ctx *ctx,
                               TALLOC_CTX *mem_ctx,
                               uint32_t *num_shares,
                               char ***share_names);
index 3d68a05c343fea4cef5ca80453d3bc036b09760c..4058ade2e446d18d84f7ee33893a6fa391cfe5c8 100644 (file)
@@ -36,7 +36,7 @@ struct smbconf_ops {
        void (*get_csn)(struct smbconf_ctx *ctx, struct smbconf_csn *csn,
                        const char *service, const char *param);
        sbcErr (*drop)(struct smbconf_ctx *ctx);
-       WERROR (*get_share_names)(struct smbconf_ctx *ctx,
+       sbcErr (*get_share_names)(struct smbconf_ctx *ctx,
                                  TALLOC_CTX *mem_ctx,
                                  uint32_t *num_shares,
                                  char ***share_names);
@@ -82,7 +82,7 @@ struct smbconf_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,
+sbcErr smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
                                   char ***array,
                                   uint32_t count,
                                   const char *string);
index 4b16cc23aaa54e9ea43c2941be7968636eff5ef9..444fa086633f3acadd8a7f0b6a6a677f4ed1cce3 100644 (file)
@@ -60,7 +60,7 @@ static struct txt_private_data *pd(struct smbconf_ctx *ctx)
 
 static bool smbconf_txt_do_section(const char *section, void *private_data)
 {
-       WERROR werr;
+       sbcErr err;
        uint32_t idx;
        struct txt_private_data *tpd = (struct txt_private_data *)private_data;
        struct txt_cache *cache = tpd->cache;
@@ -72,9 +72,9 @@ static bool smbconf_txt_do_section(const char *section, void *private_data)
                return true;
        }
 
-       werr = smbconf_add_string_to_array(cache, &(cache->share_names),
-                                          cache->num_shares, section);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_add_string_to_array(cache, &(cache->share_names),
+                                         cache->num_shares, section);
+       if (!SBC_ERROR_IS_OK(err)) {
                return false;
        }
        cache->current_share = cache->num_shares;
@@ -114,7 +114,7 @@ static bool smbconf_txt_do_parameter(const char *param_name,
                                     const char *param_value,
                                     void *private_data)
 {
-       WERROR werr;
+       sbcErr err;
        char **param_names, **param_values;
        uint32_t num_params;
        uint32_t idx;
@@ -146,17 +146,17 @@ static bool smbconf_txt_do_parameter(const char *param_name,
                }
                return true;
        }
-       werr = smbconf_add_string_to_array(cache,
+       err = smbconf_add_string_to_array(cache,
                                &(cache->param_names[cache->current_share]),
                                num_params, param_name);
-       if (!W_ERROR_IS_OK(werr)) {
+       if (!SBC_ERROR_IS_OK(err)) {
                return false;
        }
-       werr = smbconf_add_string_to_array(cache,
+       err = smbconf_add_string_to_array(cache,
                                &(cache->param_values[cache->current_share]),
                                num_params, param_value);
        cache->num_params[cache->current_share]++;
-       return W_ERROR_IS_OK(werr);
+       return SBC_ERROR_IS_OK(err);
 }
 
 static void smbconf_txt_flush_cache(struct smbconf_ctx *ctx)
@@ -293,7 +293,7 @@ static sbcErr smbconf_txt_drop(struct smbconf_ctx *ctx)
 /**
  * get the list of share names defined in the configuration.
  */
-static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
+static sbcErr smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
                                          TALLOC_CTX *mem_ctx,
                                          uint32_t *num_shares,
                                          char ***share_names)
@@ -301,18 +301,16 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
        uint32_t count;
        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)) {
-               werr = WERR_INVALID_PARAM;
-               goto done;
+               return SBC_ERR_INVALID_PARAM;
        }
 
        err = smbconf_txt_load_file(ctx);
        if (!SBC_ERROR_IS_OK(err)) {
-               return WERR_GENERAL_FAILURE;
+               return err;
        }
 
        tmp_ctx = talloc_stackframe();
@@ -321,18 +319,18 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
         * possibly after NULL section */
 
        if (smbconf_share_exists(ctx, NULL)) {
-               werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
-                                                  0, NULL);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
+                                                 0, NULL);
+               if (!SBC_ERROR_IS_OK(err)) {
                        goto done;
                }
                added_count++;
        }
 
        if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
-               werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
+               err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
                                                   added_count, GLOBAL_NAME);
-               if (!W_ERROR_IS_OK(werr)) {
+               if (!SBC_ERROR_IS_OK(err)) {
                        goto done;
                }
                added_count++;
@@ -345,10 +343,10 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
                        continue;
                }
 
-               werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
+               err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
                                        added_count,
                                        pd(ctx)->cache->share_names[count]);
-               if (!W_ERROR_IS_OK(werr)) {
+               if (!SBC_ERROR_IS_OK(err)) {
                        goto done;
                }
                added_count++;
@@ -363,7 +361,7 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
 
 done:
        talloc_free(tmp_ctx);
-       return werr;
+       return err;
 }
 
 /**
@@ -438,18 +436,20 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
        }
 
        for (count = 0; count < pd(ctx)->cache->num_params[sidx]; count++) {
-               werr = smbconf_add_string_to_array(tmp_service,
+               err = smbconf_add_string_to_array(tmp_service,
                                &(tmp_service->param_names),
                                count,
                                pd(ctx)->cache->param_names[sidx][count]);
-               if (!W_ERROR_IS_OK(werr)) {
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NOMEM;
                        goto done;
                }
-               werr = smbconf_add_string_to_array(tmp_service,
+               err = smbconf_add_string_to_array(tmp_service,
                                &(tmp_service->param_values),
                                count,
                                pd(ctx)->cache->param_values[sidx][count]);
-               if (!W_ERROR_IS_OK(werr)) {
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NOMEM;
                        goto done;
                }
        }
@@ -569,11 +569,12 @@ static WERROR smbconf_txt_get_includes(struct smbconf_ctx *ctx,
                if (strequal(pd(ctx)->cache->param_names[sidx][count],
                             "include"))
                {
-                       werr = smbconf_add_string_to_array(tmp_ctx,
+                       err = smbconf_add_string_to_array(tmp_ctx,
                                &tmp_includes,
                                tmp_num_includes,
                                pd(ctx)->cache->param_values[sidx][count]);
-                       if (!W_ERROR_IS_OK(werr)) {
+                       if (!SBC_ERROR_IS_OK(err)) {
+                               werr = WERR_NOMEM;
                                goto done;
                        }
                        tmp_num_includes++;
index 63ce50d6689c08776521ac27af012640490d8fde..86a95988f1069e776126af70ad5f1a610f14ea6f 100644 (file)
@@ -75,7 +75,7 @@ fail:
 /**
  * add a string to a talloced array of strings.
  */
-WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
+sbcErr smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
                                   char ***array,
                                   uint32_t count,
                                   const char *string)
@@ -83,12 +83,12 @@ WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
        char **new_array = NULL;
 
        if (array == NULL) {
-               return WERR_INVALID_PARAM;
+               return SBC_ERR_INVALID_PARAM;
        }
 
        new_array = talloc_realloc(mem_ctx, *array, char *, count + 1);
        if (new_array == NULL) {
-               return WERR_NOMEM;
+               return SBC_ERR_NOMEM;
        }
 
        if (string == NULL) {
@@ -97,13 +97,13 @@ WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
                new_array[count] = talloc_strdup(new_array, string);
                if (new_array[count] == NULL) {
                        talloc_free(new_array);
-                       return WERR_NOMEM;
+                       return SBC_ERR_NOMEM;
                }
        }
 
        *array = new_array;
 
-       return WERR_OK;
+       return SBC_ERR_OK;
 }
 
 bool smbconf_find_in_array(const char *string, char **list,
index 844a9b6b483bf218e43d7f330a3c8d7ff13aeb35..f6b6d8d46bbcda08524939174b73823dfae1b2e4 100644 (file)
@@ -348,6 +348,7 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
                                                char ***includes)
 {
        WERROR werr;
+       sbcErr err;
        uint32_t count;
        struct registry_value *value = NULL;
        char **tmp_includes = NULL;
@@ -378,11 +379,12 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
        }
 
        for (count = 0; array[count] != NULL; count++) {
-               werr = smbconf_add_string_to_array(tmp_ctx,
+               err = smbconf_add_string_to_array(tmp_ctx,
                                        &tmp_includes,
                                        count,
                                        array[count]);
-               if (!W_ERROR_IS_OK(werr)) {
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NOMEM;
                        goto done;
                }
        }
@@ -416,6 +418,7 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
 {
        TALLOC_CTX *tmp_ctx = NULL;
        WERROR werr = WERR_OK;
+       sbcErr err;
        uint32_t count;
        struct registry_value *valvalue = NULL;
        char *valname = NULL;
@@ -445,17 +448,19 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
                        continue;
                }
 
-               werr = smbconf_add_string_to_array(tmp_ctx,
-                                                  &tmp_valnames,
-                                                  tmp_num_values, valname);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_add_string_to_array(tmp_ctx,
+                                                 &tmp_valnames,
+                                                 tmp_num_values, valname);
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NOMEM;
                        goto done;
                }
 
                valstring = smbconf_format_registry_value(tmp_ctx, valvalue);
-               werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
-                                                  tmp_num_values, valstring);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
+                                                 tmp_num_values, valstring);
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NOMEM;
                        goto done;
                }
                tmp_num_values++;
@@ -471,16 +476,18 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
                goto done;
        }
        for (count = 0; count < num_includes; count++) {
-               werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valnames,
-                                                  tmp_num_values, "include");
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_add_string_to_array(tmp_ctx, &tmp_valnames,
+                                                 tmp_num_values, "include");
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NOMEM;
                        goto done;
                }
 
-               werr = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
-                                                  tmp_num_values,
-                                                  includes[count]);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_add_string_to_array(tmp_ctx, &tmp_valstrings,
+                                                 tmp_num_values,
+                                                 includes[count]);
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_NOMEM;
                        goto done;
                }
 
@@ -756,7 +763,7 @@ done:
  * get the list of share names defined in the configuration.
  * registry version.
  */
-static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
+static sbcErr smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
                                          TALLOC_CTX *mem_ctx,
                                          uint32_t *num_shares,
                                          char ***share_names)
@@ -764,13 +771,13 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
        uint32_t count;
        uint32_t added_count = 0;
        TALLOC_CTX *tmp_ctx = NULL;
-       WERROR werr = WERR_OK;
+       WERROR werr;
+       sbcErr err = SBC_ERR_OK;
        char *subkey_name = NULL;
        char **tmp_share_names = NULL;
 
        if ((num_shares == NULL) || (share_names == NULL)) {
-               werr = WERR_INVALID_PARAM;
-               goto done;
+               return SBC_ERR_INVALID_PARAM;
        }
 
        tmp_ctx = talloc_stackframe();
@@ -778,9 +785,9 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
        /* if there are values in the base key, return NULL as share name */
 
        if (smbconf_reg_key_has_values(rpd(ctx)->base_key)) {
-               werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
+               err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
                                                   0, NULL);
-               if (!W_ERROR_IS_OK(werr)) {
+               if (!SBC_ERROR_IS_OK(err)) {
                        goto done;
                }
                added_count++;
@@ -788,9 +795,9 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
 
        /* make sure "global" is always listed first */
        if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
-               werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
-                                                  added_count, GLOBAL_NAME);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
+                                                 added_count, GLOBAL_NAME);
+               if (!SBC_ERROR_IS_OK(err)) {
                        goto done;
                }
                added_count++;
@@ -806,19 +813,20 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
                        continue;
                }
 
-               werr = smbconf_add_string_to_array(tmp_ctx,
+               err = smbconf_add_string_to_array(tmp_ctx,
                                                   &tmp_share_names,
                                                   added_count,
                                                   subkey_name);
-               if (!W_ERROR_IS_OK(werr)) {
+               if (!SBC_ERROR_IS_OK(err)) {
                        goto done;
                }
                added_count++;
        }
        if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
+               err = SBC_ERR_NO_MORE_ITEMS;
                goto done;
        }
-       werr = WERR_OK;
+       err = SBC_ERR_OK;
 
        *num_shares = added_count;
        if (added_count > 0) {
@@ -829,7 +837,7 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
 
 done:
        talloc_free(tmp_ctx);
-       return werr;
+       return err;
 }
 
 /**
index c0f6e08ec2bb447def1ed15353ca194d6b9a1bb7..192088c6ba5eeabaafc30dab4d9492971d93ec6e 100644 (file)
@@ -466,7 +466,7 @@ static int net_conf_listshares(struct net_context *c,
                               struct smbconf_ctx *conf_ctx, int argc,
                               const char **argv)
 {
-       WERROR werr = WERR_OK;
+       sbcErr err;
        int ret = -1;
        uint32_t count, num_shares = 0;
        char **share_names = NULL;
@@ -479,9 +479,9 @@ static int net_conf_listshares(struct net_context *c,
                goto done;
        }
 
-       werr = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
-                                      &share_names);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_get_share_names(conf_ctx, mem_ctx, &num_shares,
+                                     &share_names);
+       if (!SBC_ERROR_IS_OK(err)) {
                goto done;
        }