libsmbconf: Convert smbconf_get_share() to sbcErr.
authorAndreas Schneider <asn@samba.org>
Fri, 8 Apr 2011 15:20:35 +0000 (17:20 +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/param/loadparm.c
source3/utils/net_conf.c

index 68f7dfc9028e6c6aa05291e7b8f1d34ab8b26888..e374956ca32c50aa38a04913520258125b114584 100644 (file)
@@ -177,10 +177,11 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx,
        }
 
        for (count = 0; count < tmp_num_shares; count++) {
-               werr = smbconf_get_share(ctx, tmp_services,
-                                        tmp_share_names[count],
-                                        &tmp_services[count]);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_get_share(ctx, tmp_services,
+                                       tmp_share_names[count],
+                                       &tmp_services[count]);
+               if (!SBC_ERROR_IS_OK(err)) {
+                       werr = WERR_GENERAL_FAILURE;
                        goto done;
                }
        }
@@ -236,7 +237,7 @@ sbcErr smbconf_create_share(struct smbconf_ctx *ctx,
 /**
  * get a definition of a share (service) from configuration.
  */
-WERROR smbconf_get_share(struct smbconf_ctx *ctx,
+sbcErr smbconf_get_share(struct smbconf_ctx *ctx,
                         TALLOC_CTX *mem_ctx,
                         const char *servicename,
                         struct smbconf_service **service)
index c1a82b5cf8e3e2b0a330342a094598f16d2fba0c..93f916f0e4aee92dab83f2e781c4509de641fd75 100644 (file)
@@ -85,7 +85,7 @@ sbcErr smbconf_get_share_names(struct smbconf_ctx *ctx,
                               char ***share_names);
 bool smbconf_share_exists(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,
+sbcErr smbconf_get_share(struct smbconf_ctx *ctx,
                         TALLOC_CTX *mem_ctx,
                         const char *servicename,
                         struct smbconf_service **service);
index 222497d0319b04e09b211f89eee44bd045105163..d1af40bf7c52f3d988e4173a9deb4dab25d4a415 100644 (file)
@@ -42,7 +42,7 @@ struct smbconf_ops {
                                  char ***share_names);
        bool (*share_exists)(struct smbconf_ctx *ctx, const char *service);
        sbcErr (*create_share)(struct smbconf_ctx *ctx, const char *service);
-       WERROR (*get_share)(struct smbconf_ctx *ctx,
+       sbcErr (*get_share)(struct smbconf_ctx *ctx,
                            TALLOC_CTX *mem_ctx,
                            const char *servicename,
                            struct smbconf_service **service);
index 1be27e6bbde3a781932d9ca6afca6465bcb76854..e44abb154dba19971e9b6b1477c7a8feb5dd2282 100644 (file)
@@ -394,12 +394,11 @@ static sbcErr smbconf_txt_create_share(struct smbconf_ctx *ctx,
 /**
  * get a definition of a share (service) from configuration.
  */
-static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
+static sbcErr smbconf_txt_get_share(struct smbconf_ctx *ctx,
                                    TALLOC_CTX *mem_ctx,
                                    const char *servicename,
                                    struct smbconf_service **service)
 {
-       WERROR werr;
        sbcErr err;
        uint32_t sidx, count;
        bool found;
@@ -408,7 +407,7 @@ static WERROR smbconf_txt_get_share(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(servicename,
@@ -416,21 +415,21 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
                                      pd(ctx)->cache->num_shares,
                                      &sidx);
        if (!found) {
-               return WERR_NO_SUCH_SERVICE;
+               return SBC_ERR_NO_SUCH_SERVICE;
        }
 
        tmp_ctx = talloc_stackframe();
 
        tmp_service = talloc_zero(tmp_ctx, struct smbconf_service);
        if (tmp_service == NULL) {
-               werr = WERR_NOMEM;
+               err = SBC_ERR_NOMEM;
                goto done;
        }
 
        if (servicename != NULL) {
                tmp_service->name = talloc_strdup(tmp_service, servicename);
                if (tmp_service->name == NULL) {
-                       werr = WERR_NOMEM;
+                       err = SBC_ERR_NOMEM;
                        goto done;
                }
        }
@@ -441,7 +440,6 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
                                count,
                                pd(ctx)->cache->param_names[sidx][count]);
                if (!SBC_ERROR_IS_OK(err)) {
-                       werr = WERR_NOMEM;
                        goto done;
                }
                err = smbconf_add_string_to_array(tmp_service,
@@ -449,7 +447,6 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
                                count,
                                pd(ctx)->cache->param_values[sidx][count]);
                if (!SBC_ERROR_IS_OK(err)) {
-                       werr = WERR_NOMEM;
                        goto done;
                }
        }
@@ -459,7 +456,7 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
 
 done:
        talloc_free(tmp_ctx);
-       return werr;
+       return err;
 }
 
 /**
index 78a3145db50dc0f5041a8e0ab4aa21c924e419b2..2425180bd50080e2490d921e96418c73f0449504 100644 (file)
@@ -83,7 +83,7 @@ static bool smbconf_reg_valname_valid(const char *valname)
 /**
  * Open a subkey of the base key (i.e a service)
  */
-static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
+static sbcErr smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
                                           struct smbconf_ctx *ctx,
                                           const char *servicename,
                                           uint32 desired_access,
@@ -93,16 +93,18 @@ static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
 
        if (servicename == NULL) {
                *key = rpd(ctx)->base_key;
-               return WERR_OK;
+               return SBC_ERR_OK;
        }
        werr = reg_openkey(mem_ctx, rpd(ctx)->base_key, servicename,
                           desired_access, key);
-
        if (W_ERROR_EQUAL(werr, WERR_BADFILE)) {
-               werr = WERR_NO_SUCH_SERVICE;
+               return SBC_ERR_NO_SUCH_SERVICE;
+       }
+       if (!W_ERROR_IS_OK(werr)) {
+               return SBC_ERR_NOMEM;
        }
 
-       return werr;
+       return SBC_ERR_OK;
 }
 
 /**
@@ -344,7 +346,7 @@ static char *smbconf_format_registry_value(TALLOC_CTX *mem_ctx,
        return result;
 }
 
-static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
+static sbcErr smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
                                                struct registry_key *key,
                                                uint32_t *num_includes,
                                                char ***includes)
@@ -361,22 +363,24 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
                /* no includes */
                *num_includes = 0;
                *includes = NULL;
-               werr = WERR_OK;
+               err = SBC_ERR_OK;
                goto done;
        }
 
        werr = reg_queryvalue(tmp_ctx, key, INCLUDES_VALNAME, &value);
        if (!W_ERROR_IS_OK(werr)) {
+               err = SBC_ERR_ACCESS_DENIED;
                goto done;
        }
 
        if (value->type != REG_MULTI_SZ) {
                /* wrong type -- ignore */
+               err = SBC_ERR_OK;
                goto done;
        }
 
        if (!pull_reg_multi_sz(tmp_ctx, &value->data, &array)) {
-               werr = WERR_NOMEM;
+               err = SBC_ERR_NOMEM;
                goto done;
        }
 
@@ -394,7 +398,7 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
        if (count > 0) {
                *includes = talloc_move(mem_ctx, &tmp_includes);
                if (*includes == NULL) {
-                       werr = WERR_NOMEM;
+                       err = SBC_ERR_NOMEM;
                        goto done;
                }
                *num_includes = count;
@@ -405,14 +409,14 @@ static WERROR smbconf_reg_get_includes_internal(TALLOC_CTX *mem_ctx,
 
 done:
        talloc_free(tmp_ctx);
-       return werr;
+       return err;
 }
 
 /**
  * Get the values of a key as a list of value names
  * and a list of value strings (ordered)
  */
-static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
+static sbcErr smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
                                     struct registry_key *key,
                                     uint32_t *num_values,
                                     char ***value_names,
@@ -433,7 +437,7 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
        if ((num_values == NULL) || (value_names == NULL) ||
            (value_strings == NULL))
        {
-               werr = WERR_INVALID_PARAM;
+               err = SBC_ERR_INVALID_PARAM;
                goto done;
        }
 
@@ -454,7 +458,6 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
                                                  &tmp_valnames,
                                                  tmp_num_values, valname);
                if (!SBC_ERROR_IS_OK(err)) {
-                       werr = WERR_NOMEM;
                        goto done;
                }
 
@@ -462,26 +465,26 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
                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++;
        }
        if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
+               err = SBC_ERR_NOMEM;
                goto done;
        }
 
        /* now add the includes at the end */
-       werr = smbconf_reg_get_includes_internal(tmp_ctx, key, &num_includes,
+       err = smbconf_reg_get_includes_internal(tmp_ctx, key, &num_includes,
                                                 &includes);
-       if (!W_ERROR_IS_OK(werr)) {
+       if (!SBC_ERROR_IS_OK(err)) {
                goto done;
        }
+
        for (count = 0; count < num_includes; count++) {
                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;
                }
 
@@ -489,7 +492,6 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
                                                  tmp_num_values,
                                                  includes[count]);
                if (!SBC_ERROR_IS_OK(err)) {
-                       werr = WERR_NOMEM;
                        goto done;
                }
 
@@ -507,7 +509,7 @@ static WERROR smbconf_reg_get_values(TALLOC_CTX *mem_ctx,
 
 done:
        talloc_free(tmp_ctx);
-       return werr;
+       return err;
 }
 
 static bool smbconf_reg_key_has_values(struct registry_key *key)
@@ -849,13 +851,13 @@ static bool smbconf_reg_share_exists(struct smbconf_ctx *ctx,
                                     const char *servicename)
 {
        bool ret = false;
-       WERROR werr = WERR_OK;
+       sbcErr err;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
        struct registry_key *key = NULL;
 
-       werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
-                                           REG_KEY_READ, &key);
-       if (W_ERROR_IS_OK(werr)) {
+       err = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
+                                          REG_KEY_READ, &key);
+       if (SBC_ERROR_IS_OK(err)) {
                ret = true;
        }
 
@@ -886,48 +888,47 @@ static sbcErr smbconf_reg_create_share(struct smbconf_ctx *ctx,
 /**
  * get a definition of a share (service) from configuration.
  */
-static WERROR smbconf_reg_get_share(struct smbconf_ctx *ctx,
+static sbcErr smbconf_reg_get_share(struct smbconf_ctx *ctx,
                                    TALLOC_CTX *mem_ctx,
                                    const char *servicename,
                                    struct smbconf_service **service)
 {
-       WERROR werr = WERR_OK;
+       sbcErr err;
        struct registry_key *key = NULL;
        struct smbconf_service *tmp_service = NULL;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
-       werr = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
-                                           REG_KEY_READ, &key);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
+                                          REG_KEY_READ, &key);
+       if (!SBC_ERROR_IS_OK(err)) {
                goto done;
        }
 
        tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service);
        if (tmp_service == NULL) {
-               werr =  WERR_NOMEM;
+               err = SBC_ERR_NOMEM;
                goto done;
        }
 
        if (servicename != NULL) {
                tmp_service->name = talloc_strdup(tmp_service, servicename);
                if (tmp_service->name == NULL) {
-                       werr = WERR_NOMEM;
+                       err = SBC_ERR_NOMEM;
                        goto done;
                }
        }
 
-       werr = smbconf_reg_get_values(tmp_service, key,
-                                     &(tmp_service->num_params),
-                                     &(tmp_service->param_names),
-                                     &(tmp_service->param_values));
-
-       if (W_ERROR_IS_OK(werr)) {
+       err = smbconf_reg_get_values(tmp_service, key,
+                                    &(tmp_service->num_params),
+                                    &(tmp_service->param_names),
+                                    &(tmp_service->param_values));
+       if (SBC_ERROR_IS_OK(err)) {
                *service = talloc_move(mem_ctx, &tmp_service);
        }
 
 done:
        talloc_free(tmp_ctx);
-       return werr;
+       return err;
 }
 
 /**
@@ -958,12 +959,14 @@ static WERROR smbconf_reg_set_parameter(struct smbconf_ctx *ctx,
                                        const char *valstr)
 {
        WERROR werr;
+       sbcErr err;
        struct registry_key *key = NULL;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
 
-       werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
-                                           REG_KEY_WRITE, &key);
-       if (!W_ERROR_IS_OK(werr)) {
+       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;
        }
 
@@ -984,12 +987,14 @@ static WERROR smbconf_reg_get_parameter(struct smbconf_ctx *ctx,
                                        char **valstr)
 {
        WERROR werr = WERR_OK;
+       sbcErr err;
        struct registry_key *key = NULL;
        struct registry_value *value = NULL;
 
-       werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
-                                           REG_KEY_READ, &key);
-       if (!W_ERROR_IS_OK(werr)) {
+       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;
        }
 
@@ -1029,11 +1034,13 @@ static WERROR smbconf_reg_delete_parameter(struct smbconf_ctx *ctx,
 {
        struct registry_key *key = NULL;
        WERROR werr = WERR_OK;
+       sbcErr err;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
 
-       werr = smbconf_reg_open_service_key(mem_ctx, ctx, service,
-                                           REG_KEY_ALL, &key);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_reg_open_service_key(mem_ctx, ctx, service,
+                                          REG_KEY_ALL, &key);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NOMEM;
                goto done;
        }
 
@@ -1061,17 +1068,23 @@ static WERROR smbconf_reg_get_includes(struct smbconf_ctx *ctx,
                                       char ***includes)
 {
        WERROR werr;
+       sbcErr err;
        struct registry_key *key = NULL;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
-       werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
-                                           REG_KEY_READ, &key);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
+                                          REG_KEY_READ, &key);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NOMEM;
                goto done;
        }
 
-       werr = smbconf_reg_get_includes_internal(mem_ctx, key, num_includes,
+       err = smbconf_reg_get_includes_internal(mem_ctx, key, num_includes,
                                                 includes);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NOMEM;
+               goto done;
+       }
 
 done:
        talloc_free(tmp_ctx);
@@ -1084,12 +1097,14 @@ static WERROR smbconf_reg_set_includes(struct smbconf_ctx *ctx,
                                       const char **includes)
 {
        WERROR werr = WERR_OK;
+       sbcErr err;
        struct registry_key *key = NULL;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
-       werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
-                                           REG_KEY_ALL, &key);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
+                                          REG_KEY_ALL, &key);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NOMEM;
                goto done;
        }
 
@@ -1112,12 +1127,14 @@ static WERROR smbconf_reg_delete_includes(struct smbconf_ctx *ctx,
                                          const char *service)
 {
        WERROR werr = WERR_OK;
+       sbcErr err;
        struct registry_key *key = NULL;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
 
-       werr = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
-                                           REG_KEY_ALL, &key);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_reg_open_service_key(tmp_ctx, ctx, service,
+                                          REG_KEY_ALL, &key);
+       if (!SBC_ERROR_IS_OK(err)) {
+               werr = WERR_NOMEM;
                goto done;
        }
 
index 53fd3dad50f6a86e8c28ca076b91fc56264ed0a0..d9608babc885bf83586af38fb200504d8f406c68 100644 (file)
@@ -7255,7 +7255,7 @@ static bool process_smbconf_service(struct smbconf_service *service)
  */
 bool process_registry_service(const char *service_name)
 {
-       WERROR werr;
+       sbcErr err;
        struct smbconf_service *service = NULL;
        TALLOC_CTX *mem_ctx = talloc_stackframe();
        struct smbconf_ctx *conf_ctx = lp_smbconf_ctx();
@@ -7276,8 +7276,8 @@ bool process_registry_service(const char *service_name)
                goto done;
        }
 
-       werr = smbconf_get_share(conf_ctx, mem_ctx, service_name, &service);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_get_share(conf_ctx, mem_ctx, service_name, &service);
+       if (!SBC_ERROR_IS_OK(err)) {
                goto done;
        }
 
index 3b6005a2b9599ef45c96c4aded165ea3a92ef732..d4f91c691a5836f5dd3994a095b61c28874241e7 100644 (file)
@@ -366,10 +366,10 @@ static int net_conf_import(struct net_context *c, struct smbconf_ctx *conf_ctx,
        if (servicename != NULL) {
                struct smbconf_service *service = NULL;
 
-               werr = smbconf_get_share(txt_ctx, mem_ctx,
-                                        servicename,
-                                        &service);
-               if (!W_ERROR_IS_OK(werr)) {
+               err = smbconf_get_share(txt_ctx, mem_ctx,
+                                       servicename,
+                                       &service);
+               if (!SBC_ERROR_IS_OK(err)) {
                        goto cancel;
                }
 
@@ -528,7 +528,7 @@ static int net_conf_showshare(struct net_context *c,
                              const char **argv)
 {
        int ret = -1;
-       WERROR werr = WERR_OK;
+       sbcErr err;
        const char *sharename = NULL;
        TALLOC_CTX *mem_ctx;
        uint32_t count;
@@ -547,10 +547,10 @@ static int net_conf_showshare(struct net_context *c,
                goto done;
        }
 
-       werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
-       if (!W_ERROR_IS_OK(werr)) {
+       err = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
+       if (!SBC_ERROR_IS_OK(err)) {
                d_printf(_("error getting share parameters: %s\n"),
-                        win_errstr(werr));
+                        sbcErrorString(err));
                goto done;
        }