summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--source3/param/loadparm.c12
-rw-r--r--source3/utils/net_conf.c96
7 files changed, 110 insertions, 122 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:
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 962c0a4627..09049db9ff 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -6497,9 +6497,7 @@ bool service_ok(int iService)
static bool process_registry_globals(void)
{
WERROR werr;
- char **param_names;
- char **param_values;
- uint32_t num_params;
+ struct smbconf_service *service = NULL;
uint32_t count;
TALLOC_CTX *mem_ctx = talloc_stackframe();
bool ret = false;
@@ -6519,14 +6517,14 @@ static bool process_registry_globals(void)
goto done;
}
- werr = smbconf_get_share(conf_ctx, mem_ctx, GLOBAL_NAME,
- &num_params, &param_names, &param_values);
+ werr = smbconf_get_share(conf_ctx, mem_ctx, GLOBAL_NAME, &service);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
- for (count = 0; count < num_params; count++) {
- ret = do_parameter(param_names[count], param_values[count],
+ for (count = 0; count < service->num_params; count++) {
+ ret = do_parameter(service->param_names[count],
+ service->param_values[count],
NULL);
if (ret != true) {
goto done;
diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c
index 4fffcf8a8c..08a06eabd4 100644
--- a/source3/utils/net_conf.c
+++ b/source3/utils/net_conf.c
@@ -138,10 +138,7 @@ static int net_conf_delincludes_usage(int argc, const char **argv)
* This functions process a service previously loaded with libsmbconf.
*/
static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
- const char *servicename,
- const uint32_t num_params,
- const char **param_names,
- const char **param_values)
+ struct smbconf_service *service)
{
uint32_t idx;
WERROR werr = WERR_OK;
@@ -151,31 +148,32 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
if (opt_testmode) {
const char *indent = "";
- if (servicename != NULL) {
- d_printf("[%s]\n", servicename);
+ if (service->name != NULL) {
+ d_printf("[%s]\n", service->name);
indent = "\t";
}
- for (idx = 0; idx < num_params; idx++) {
- d_printf("%s%s = %s\n", indent, param_names[idx],
- param_values[idx]);
+ for (idx = 0; idx < service->num_params; idx++) {
+ d_printf("%s%s = %s\n", indent,
+ service->param_names[idx],
+ service->param_values[idx]);
}
d_printf("\n");
goto done;
}
- if (smbconf_share_exists(conf_ctx, servicename)) {
- werr = smbconf_delete_share(conf_ctx, servicename);
+ if (smbconf_share_exists(conf_ctx, service->name)) {
+ werr = smbconf_delete_share(conf_ctx, service->name);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
}
- werr = smbconf_create_share(conf_ctx, servicename);
+ werr = smbconf_create_share(conf_ctx, service->name);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
- for (idx = 0; idx < num_params; idx ++) {
- if (strequal(param_names[idx], "include")) {
+ for (idx = 0; idx < service->num_params; idx ++) {
+ if (strequal(service->param_names[idx], "include")) {
includes = TALLOC_REALLOC_ARRAY(mem_ctx,
includes,
char *,
@@ -185,7 +183,7 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
goto done;
}
includes[num_includes] = talloc_strdup(includes,
- param_values[idx]);
+ service->param_values[idx]);
if (includes[num_includes] == NULL) {
werr = WERR_NOMEM;
goto done;
@@ -193,16 +191,16 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
num_includes++;
} else {
werr = smbconf_set_parameter(conf_ctx,
- servicename,
- param_names[idx],
- param_values[idx]);
+ service->name,
+ service->param_names[idx],
+ service->param_values[idx]);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
}
}
- werr = smbconf_set_includes(conf_ctx, servicename, num_includes,
+ werr = smbconf_set_includes(conf_ctx, service->name, num_includes,
(const char **)includes);
done:
@@ -224,11 +222,8 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx,
int ret = -1;
TALLOC_CTX *mem_ctx;
uint32_t num_shares;
- char **share_names;
- uint32_t *num_params;
- char ***param_names;
- char ***param_values;
uint32_t share_count, param_count;
+ struct smbconf_service **shares = NULL;
mem_ctx = talloc_stackframe();
@@ -237,8 +232,7 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx,
goto done;
}
- werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &share_names,
- &num_params, &param_names, &param_values);
+ werr = smbconf_get_config(conf_ctx, mem_ctx, &num_shares, &shares);
if (!W_ERROR_IS_OK(werr)) {
d_fprintf(stderr, "Error getting config: %s\n",
dos_errstr(werr));
@@ -247,17 +241,18 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx,
for (share_count = 0; share_count < num_shares; share_count++) {
const char *indent = "";
- if (share_names[share_count] != NULL) {
- d_printf("[%s]\n", share_names[share_count]);
+ if (shares[share_count]->name != NULL) {
+ d_printf("[%s]\n", shares[share_count]->name);
indent = "\t";
}
- for (param_count = 0; param_count < num_params[share_count];
+ for (param_count = 0;
+ param_count < shares[share_count]->num_params;
param_count++)
{
d_printf("%s%s = %s\n",
indent,
- param_names[share_count][param_count],
- param_values[share_count][param_count]);
+ shares[share_count]->param_names[param_count],
+ shares[share_count]->param_values[param_count]);
}
d_printf("\n");
}
@@ -320,35 +315,25 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx,
}
if (servicename != NULL) {
- char **param_names, **param_values;
- uint32_t num_params;
+ struct smbconf_service *service = NULL;
werr = smbconf_get_share(txt_ctx, mem_ctx,
servicename,
- &num_params,
- &param_names,
- &param_values);
+ &service);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
- werr = import_process_service(conf_ctx,
- servicename,
- num_params,
- (const char **)param_names,
- (const char **)param_values);
+ werr = import_process_service(conf_ctx, service);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
} else {
- char **share_names, ***param_names, ***param_values;
- uint32_t num_shares, *num_params, sidx;
+ struct smbconf_service **services = NULL;
+ uint32_t num_shares, sidx;
werr = smbconf_get_config(txt_ctx, mem_ctx,
&num_shares,
- &share_names,
- &num_params,
- &param_names,
- &param_values);
+ &services);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -359,11 +344,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx,
}
}
for (sidx = 0; sidx < num_shares; sidx++) {
- werr = import_process_service(conf_ctx,
- share_names[sidx],
- num_params[sidx],
- (const char **)param_names[sidx],
- (const char **)param_values[sidx]);
+ werr = import_process_service(conf_ctx, services[sidx]);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -442,10 +423,8 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx,
WERROR werr = WERR_OK;
const char *sharename = NULL;
TALLOC_CTX *mem_ctx;
- uint32_t num_params;
uint32_t count;
- char **param_names;
- char **param_values;
+ struct smbconf_service *service = NULL;
mem_ctx = talloc_stackframe();
@@ -460,8 +439,7 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx,
goto done;
}
- werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &num_params,
- &param_names, &param_values);
+ werr = smbconf_get_share(conf_ctx, mem_ctx, sharename, &service);
if (!W_ERROR_IS_OK(werr)) {
d_printf("error getting share parameters: %s\n",
dos_errstr(werr));
@@ -470,9 +448,9 @@ static int net_conf_showshare(struct smbconf_ctx *conf_ctx,
d_printf("[%s]\n", sharename);
- for (count = 0; count < num_params; count++) {
- d_printf("\t%s = %s\n", param_names[count],
- param_values[count]);
+ for (count = 0; count < service->num_params; count++) {
+ d_printf("\t%s = %s\n", service->param_names[count],
+ service->param_values[count]);
}
ret = 0;