summaryrefslogtreecommitdiff
path: root/source3/lib/smbconf
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-04-22 16:31:16 +0200
committerMichael Adam <obnox@samba.org>2008-04-23 01:43:31 +0200
commitfb9232c0a98d9ce600e379dd03ee6fa3cd73cba5 (patch)
tree611aebbcadfb490cb37bcb70fd22f942be888ea7 /source3/lib/smbconf
parent5dd54c58b4d65b28751fda3ba2acbfe71ea7a75f (diff)
downloadsamba-fb9232c0a98d9ce600e379dd03ee6fa3cd73cba5.tar.gz
samba-fb9232c0a98d9ce600e379dd03ee6fa3cd73cba5.tar.bz2
samba-fb9232c0a98d9ce600e379dd03ee6fa3cd73cba5.zip
libsmbconf: rewrite API to use smbconf_service struct
instead of lists of strings and counters directly... Michael (This used to be commit 17415e2dc457ce41793a7e28e71f72c538c19c61)
Diffstat (limited to 'source3/lib/smbconf')
-rw-r--r--source3/lib/smbconf/smbconf.c44
-rw-r--r--source3/lib/smbconf/smbconf.h7
-rw-r--r--source3/lib/smbconf/smbconf_private.h4
-rw-r--r--source3/lib/smbconf/smbconf_reg.c33
-rw-r--r--source3/lib/smbconf/smbconf_txt.c36
5 files changed, 68 insertions, 56 deletions
diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c
index 9565540df4..00b9ba3e07 100644
--- a/source3/lib/smbconf/smbconf.c
+++ b/source3/lib/smbconf/smbconf.c
@@ -91,22 +91,16 @@ WERROR smbconf_drop(struct smbconf_ctx *ctx)
WERROR smbconf_get_config(struct smbconf_ctx *ctx,
TALLOC_CTX *mem_ctx,
uint32_t *num_shares,
- char ***share_names, uint32_t **num_params,
- char ****param_names, char ****param_values)
+ struct smbconf_service ***services)
{
WERROR werr = WERR_OK;
TALLOC_CTX *tmp_ctx = NULL;
uint32_t tmp_num_shares;
char **tmp_share_names;
- uint32_t *tmp_num_params;
- char ***tmp_param_names;
- char ***tmp_param_values;
+ struct smbconf_service **tmp_services;
uint32_t count;
- if ((num_shares == NULL) || (share_names == NULL) ||
- (num_params == NULL) || (param_names == NULL) ||
- (param_values == NULL))
- {
+ if ((num_shares == NULL) || (services == NULL)) {
werr = WERR_INVALID_PARAM;
goto done;
}
@@ -123,23 +117,18 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx,
goto done;
}
- tmp_num_params = TALLOC_ARRAY(tmp_ctx, uint32_t, tmp_num_shares);
- tmp_param_names = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares);
- tmp_param_values = TALLOC_ARRAY(tmp_ctx, char **, tmp_num_shares);
+ tmp_services = TALLOC_ARRAY(tmp_ctx, struct smbconf_service *,
+ tmp_num_shares);
- if ((tmp_num_params == NULL) || (tmp_param_names == NULL) ||
- (tmp_param_values == NULL))
- {
+ if (tmp_services == NULL) {
werr = WERR_NOMEM;
goto done;
}
for (count = 0; count < tmp_num_shares; count++) {
- werr = smbconf_get_share(ctx, mem_ctx,
+ werr = smbconf_get_share(ctx, tmp_services,
tmp_share_names[count],
- &tmp_num_params[count],
- &tmp_param_names[count],
- &tmp_param_values[count]);
+ &tmp_services[count]);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -149,15 +138,9 @@ WERROR smbconf_get_config(struct smbconf_ctx *ctx,
*num_shares = tmp_num_shares;
if (tmp_num_shares > 0) {
- *share_names = talloc_move(mem_ctx, &tmp_share_names);
- *num_params = talloc_move(mem_ctx, &tmp_num_params);
- *param_names = talloc_move(mem_ctx, &tmp_param_names);
- *param_values = talloc_move(mem_ctx, &tmp_param_values);
+ *services = talloc_move(mem_ctx, &tmp_services);
} else {
- *share_names = NULL;
- *num_params = NULL;
- *param_names = NULL;
- *param_values = NULL;
+ *services = NULL;
}
done:
@@ -204,15 +187,14 @@ WERROR smbconf_create_share(struct smbconf_ctx *ctx,
*/
WERROR smbconf_get_share(struct smbconf_ctx *ctx,
TALLOC_CTX *mem_ctx,
- const char *servicename, uint32_t *num_params,
- char ***param_names, char ***param_values)
+ const char *servicename,
+ struct smbconf_service **service)
{
if (!smbconf_share_exists(ctx, servicename)) {
return WERR_NO_SUCH_SERVICE;
}
- return ctx->ops->get_share(ctx, mem_ctx, servicename, num_params,
- param_names, param_values);
+ return ctx->ops->get_share(ctx, mem_ctx, servicename, service);
}
/**
diff --git a/source3/lib/smbconf/smbconf.h b/source3/lib/smbconf/smbconf.h
index 86ee3ed231..e337476665 100644
--- a/source3/lib/smbconf/smbconf.h
+++ b/source3/lib/smbconf/smbconf.h
@@ -63,8 +63,7 @@ WERROR smbconf_drop(struct smbconf_ctx *ctx);
WERROR smbconf_get_config(struct smbconf_ctx *ctx,
TALLOC_CTX *mem_ctx,
uint32_t *num_shares,
- char ***share_names, uint32_t **num_params,
- char ****param_names, char ****param_values);
+ struct smbconf_service ***services);
WERROR smbconf_get_share_names(struct smbconf_ctx *ctx,
TALLOC_CTX *mem_ctx,
uint32_t *num_shares,
@@ -73,8 +72,8 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename);
WERROR 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, uint32_t *num_params,
- char ***param_names, char ***param_values);
+ const char *servicename,
+ struct smbconf_service **service);
WERROR smbconf_delete_share(struct smbconf_ctx *ctx,
const char *servicename);
WERROR smbconf_set_parameter(struct smbconf_ctx *ctx,
diff --git a/source3/lib/smbconf/smbconf_private.h b/source3/lib/smbconf/smbconf_private.h
index 76f91f94d3..8e7d6a9983 100644
--- a/source3/lib/smbconf/smbconf_private.h
+++ b/source3/lib/smbconf/smbconf_private.h
@@ -36,8 +36,8 @@ struct smbconf_ops {
WERROR (*create_share)(struct smbconf_ctx *ctx, const char *service);
WERROR (*get_share)(struct smbconf_ctx *ctx,
TALLOC_CTX *mem_ctx,
- const char *servicename, uint32_t *num_params,
- char ***param_names, char ***param_values);
+ const char *servicename,
+ struct smbconf_service **service);
WERROR (*delete_share)(struct smbconf_ctx *ctx,
const char *servicename);
WERROR (*set_parameter)(struct smbconf_ctx *ctx,
diff --git a/source3/lib/smbconf/smbconf_reg.c b/source3/lib/smbconf/smbconf_reg.c
index 930999cc3f..5f5724c406 100644
--- a/source3/lib/smbconf/smbconf_reg.c
+++ b/source3/lib/smbconf/smbconf_reg.c
@@ -875,23 +875,44 @@ static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx,
static WERROR smbconf_reg_get_share(struct smbconf_ctx *ctx,
TALLOC_CTX *mem_ctx,
const char *servicename,
- uint32_t *num_params,
- char ***param_names, char ***param_values)
+ struct smbconf_service **service)
{
WERROR werr = WERR_OK;
struct registry_key *key = NULL;
+ struct smbconf_service *tmp_service = NULL;
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
- werr = smbconf_reg_open_service_key(mem_ctx, ctx, servicename,
+ werr = smbconf_reg_open_service_key(tmp_ctx, ctx, servicename,
REG_KEY_READ, &key);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
- werr = smbconf_reg_get_values(mem_ctx, key, num_params,
- param_names, param_values);
+ tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service);
+ if (tmp_service == NULL) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+
+ if (servicename != NULL) {
+ tmp_service->name = talloc_strdup(tmp_service, servicename);
+ if (tmp_service->name == NULL) {
+ werr = WERR_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)) {
+ *service = talloc_move(mem_ctx, &tmp_service);
+ }
done:
- TALLOC_FREE(key);
+ TALLOC_FREE(tmp_ctx);
return werr;
}
diff --git a/source3/lib/smbconf/smbconf_txt.c b/source3/lib/smbconf/smbconf_txt.c
index c511185cb9..c4c636d0bc 100644
--- a/source3/lib/smbconf/smbconf_txt.c
+++ b/source3/lib/smbconf/smbconf_txt.c
@@ -389,15 +389,13 @@ static WERROR smbconf_txt_create_share(struct smbconf_ctx *ctx,
static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
TALLOC_CTX *mem_ctx,
const char *servicename,
- uint32_t *num_params,
- char ***param_names, char ***param_values)
+ struct smbconf_service **service)
{
WERROR werr;
uint32_t sidx, count;
bool found;
TALLOC_CTX *tmp_ctx = NULL;
- char **tmp_param_names = NULL;
- char **tmp_param_values = NULL;
+ struct smbconf_service *tmp_service = NULL;
werr = smbconf_txt_load_file(ctx);
if (!W_ERROR_IS_OK(werr)) {
@@ -418,16 +416,30 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
goto done;
}
+ tmp_service = TALLOC_ZERO_P(tmp_ctx, struct smbconf_service);
+ if (tmp_service == NULL) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+
+ if (servicename != NULL) {
+ tmp_service->name = talloc_strdup(tmp_service, servicename);
+ if (tmp_service->name == NULL) {
+ werr = WERR_NOMEM;
+ goto done;
+ }
+ }
+
for (count = 0; count < pd(ctx)->cache->num_params[sidx]; count++) {
- werr = smbconf_add_string_to_array(tmp_ctx,
- &tmp_param_names,
+ werr = 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)) {
goto done;
}
- werr = smbconf_add_string_to_array(tmp_ctx,
- &tmp_param_values,
+ werr = 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)) {
@@ -435,13 +447,11 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
}
}
- *num_params = count;
+ tmp_service->num_params = count;
if (count > 0) {
- *param_names = talloc_move(mem_ctx, &tmp_param_names);
- *param_values = talloc_move(mem_ctx, &tmp_param_values);
+ *service = talloc_move(mem_ctx, &tmp_service);
} else {
- *param_names = NULL;
- *param_values = NULL;
+ *service = NULL;
}
done: