[SCM] Samba Shared Repository - branch v3-2-test updated -
release-3-2-0pre2-458-gcd17cc7
Michael Adam
obnox at samba.org
Wed Mar 26 23:33:04 GMT 2008
The branch, v3-2-test has been updated
via cd17cc745a35db8ee158f59a5fff1f0f26cf9c6e (commit)
via ee46f0eca6ea21d0c51103252fecf911bb448687 (commit)
via 03efb72b4632e2bbb0838ca56a3e556448bda5c5 (commit)
via 8cb288124993eb59459e7e9777c65e58c0554d55 (commit)
from 4ddf58dbdc3d74cb72788ef4a2ec7587d4948c40 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test
- Log -----------------------------------------------------------------
commit cd17cc745a35db8ee158f59a5fff1f0f26cf9c6e
Author: Michael Adam <obnox at samba.org>
Date: Thu Mar 27 00:32:00 2008 +0100
net_conf: fix non-testmode import function.
Michael
commit ee46f0eca6ea21d0c51103252fecf911bb448687
Author: Michael Adam <obnox at samba.org>
Date: Wed Mar 26 23:58:52 2008 +0100
libsmbconf: text - pass the cache instead of all private data to pm_process.
Michael
commit 03efb72b4632e2bbb0838ca56a3e556448bda5c5
Author: Michael Adam <obnox at samba.org>
Date: Wed Mar 26 23:58:01 2008 +0100
libsmbconf: text - change the cache to be talloced
instead of having it directly as a member in the private data struct.
This makes it easier to flush and initialize the cache.
Michael
commit 8cb288124993eb59459e7e9777c65e58c0554d55
Author: Michael Adam <obnox at samba.org>
Date: Wed Mar 26 23:11:04 2008 +0100
libsmbconf: in text backend, put flushing of the cache into a helper function.
And use it also in the close operation.
Michael
-----------------------------------------------------------------------
Summary of changes:
source/lib/smbconf/smbconf_txt_simple.c | 164 +++++++++++++++++-------------
source/utils/net_conf.c | 12 ++-
2 files changed, 104 insertions(+), 72 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/lib/smbconf/smbconf_txt_simple.c b/source/lib/smbconf/smbconf_txt_simple.c
index 4bd3eee..df33008 100644
--- a/source/lib/smbconf/smbconf_txt_simple.c
+++ b/source/lib/smbconf/smbconf_txt_simple.c
@@ -28,15 +28,17 @@
#include "includes.h"
#include "smbconf_private.h"
+struct txt_cache {
+ uint32_t current_share;
+ uint32_t num_shares;
+ char **share_names;
+ uint32_t *num_params;
+ char ***param_names;
+ char ***param_values;
+};
+
struct txt_private_data {
- struct {
- uint32_t current_share;
- uint32_t num_shares;
- char **share_names;
- uint32_t *num_params;
- char ***param_names;
- char ***param_values;
- } cache;
+ struct txt_cache *cache;
uint64_t csn;
};
@@ -79,49 +81,49 @@ static bool smbconf_txt_do_section(const char *section, void *private_data)
{
WERROR werr;
uint32_t idx;
- struct txt_private_data *data = (struct txt_private_data *)private_data;
+ struct txt_cache *cache = (struct txt_cache *)private_data;
- if (smbconf_txt_find_in_array(section, data->cache.share_names,
- data->cache.num_shares, &idx))
+ if (smbconf_txt_find_in_array(section, cache->share_names,
+ cache->num_shares, &idx))
{
- data->cache.current_share = idx;
+ cache->current_share = idx;
return true;
}
- werr = smbconf_add_string_to_array(data, &(data->cache.share_names),
- data->cache.num_shares, section);
+ werr = smbconf_add_string_to_array(cache, &(cache->share_names),
+ cache->num_shares, section);
if (!W_ERROR_IS_OK(werr)) {
return false;
}
- data->cache.current_share = data->cache.num_shares;
- data->cache.num_shares++;
-
- data->cache.param_names = TALLOC_REALLOC_ARRAY(data,
- data->cache.param_names,
- char **,
- data->cache.num_shares);
- if (data->cache.param_names == NULL) {
+ cache->current_share = cache->num_shares;
+ cache->num_shares++;
+
+ cache->param_names = TALLOC_REALLOC_ARRAY(cache,
+ cache->param_names,
+ char **,
+ cache->num_shares);
+ if (cache->param_names == NULL) {
return false;
}
- data->cache.param_names[data->cache.current_share] = NULL;
+ cache->param_names[cache->current_share] = NULL;
- data->cache.param_values = TALLOC_REALLOC_ARRAY(data,
- data->cache.param_values,
- char **,
- data->cache.num_shares);
- if (data->cache.param_values == NULL) {
+ cache->param_values = TALLOC_REALLOC_ARRAY(cache,
+ cache->param_values,
+ char **,
+ cache->num_shares);
+ if (cache->param_values == NULL) {
return false;
}
- data->cache.param_values[data->cache.current_share] = NULL;
+ cache->param_values[cache->current_share] = NULL;
- data->cache.num_params = TALLOC_REALLOC_ARRAY(data,
- data->cache.num_params,
- uint32_t,
- data->cache.num_shares);
- if (data->cache.num_params == NULL) {
+ cache->num_params = TALLOC_REALLOC_ARRAY(cache,
+ cache->num_params,
+ uint32_t,
+ cache->num_shares);
+ if (cache->num_params == NULL) {
return false;
}
- data->cache.num_params[data->cache.current_share] = 0;
+ cache->num_params[cache->current_share] = 0;
return true;
}
@@ -134,57 +136,76 @@ static bool smbconf_txt_do_parameter(const char *param_name,
char **param_names, **param_values;
uint32_t num_params;
uint32_t idx;
- struct txt_private_data *data = (struct txt_private_data *)private_data;
+ struct txt_cache *cache = (struct txt_cache *)private_data;
- if (data->cache.num_shares == 0) {
+ if (cache->num_shares == 0) {
/* not in any share ... */
return false;
}
- param_names = data->cache.param_names[data->cache.current_share];
- param_values = data->cache.param_values[data->cache.current_share];
- num_params = data->cache.num_params[data->cache.current_share];
+ param_names = cache->param_names[cache->current_share];
+ param_values = cache->param_values[cache->current_share];
+ num_params = cache->num_params[cache->current_share];
if (smbconf_txt_find_in_array(param_name, param_names, num_params,
&idx))
{
TALLOC_FREE(param_values[idx]);
- param_values[idx] = talloc_strdup(data, param_value);
+ param_values[idx] = talloc_strdup(cache, param_value);
if (param_values[idx] == NULL) {
return false;
}
return true;
}
- werr = smbconf_add_string_to_array(data,
- &(data->cache.param_names[data->cache.current_share]),
- num_params, param_name);
+ werr = smbconf_add_string_to_array(cache,
+ &(cache->param_names[cache->current_share]),
+ num_params, param_name);
if (!W_ERROR_IS_OK(werr)) {
return false;
}
- werr = smbconf_add_string_to_array(data,
- &(data->cache.param_values[data->cache.current_share]),
- num_params, param_value);
- data->cache.num_params[data->cache.current_share]++;
+ werr = 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);
}
+static void smbconf_txt_flush_cache(struct smbconf_ctx *ctx)
+{
+ TALLOC_FREE(pd(ctx)->cache);
+}
+
+static WERROR smbconf_txt_init_cache(struct smbconf_ctx *ctx)
+{
+ if (pd(ctx)->cache != NULL) {
+ smbconf_txt_flush_cache(ctx);
+ }
+
+ pd(ctx)->cache = TALLOC_ZERO_P(pd(ctx), struct txt_cache);
+
+ if (pd(ctx)->cache == NULL) {
+ return WERR_NOMEM;
+ }
+
+ return WERR_OK;
+}
+
static WERROR smbconf_txt_load_file(struct smbconf_ctx *ctx)
{
+ WERROR werr;
uint64_t new_csn = (uint64_t)file_modtime(ctx->path);
if (new_csn == pd(ctx)->csn) {
return WERR_OK;
}
- TALLOC_FREE(pd(ctx)->cache.share_names);
- pd(ctx)->cache.current_share = 0;
- pd(ctx)->cache.num_shares = 0;
- TALLOC_FREE(pd(ctx)->cache.param_names);
- TALLOC_FREE(pd(ctx)->cache.param_values);
- TALLOC_FREE(pd(ctx)->cache.num_params);
+ werr = smbconf_txt_init_cache(ctx);
+ if (!W_ERROR_IS_OK(werr)) {
+ return werr;
+ }
if (!pm_process(ctx->path, smbconf_txt_do_section,
- smbconf_txt_do_parameter, pd(ctx)))
+ smbconf_txt_do_parameter, pd(ctx)->cache))
{
return WERR_CAN_NOT_COMPLETE;
}
@@ -231,6 +252,7 @@ static WERROR smbconf_txt_open(struct smbconf_ctx *ctx)
static int smbconf_txt_close(struct smbconf_ctx *ctx)
{
+ smbconf_txt_flush_cache(ctx);
return 0;
}
@@ -297,14 +319,14 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
added_count++;
}
- for (count = 0; count < pd(ctx)->cache.num_shares; count++) {
- if (strequal(pd(ctx)->cache.share_names[count], GLOBAL_NAME)) {
+ for (count = 0; count < pd(ctx)->cache->num_shares; count++) {
+ if (strequal(pd(ctx)->cache->share_names[count], GLOBAL_NAME)) {
continue;
}
werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
added_count,
- pd(ctx)->cache.share_names[count]);
+ pd(ctx)->cache->share_names[count]);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -337,8 +359,8 @@ static bool smbconf_txt_share_exists(struct smbconf_ctx *ctx,
}
return smbconf_txt_find_in_array(servicename,
- pd(ctx)->cache.share_names,
- pd(ctx)->cache.num_shares, NULL);
+ pd(ctx)->cache->share_names,
+ pd(ctx)->cache->num_shares, NULL);
}
/**
@@ -372,8 +394,8 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
}
found = smbconf_txt_find_in_array(servicename,
- pd(ctx)->cache.share_names,
- pd(ctx)->cache.num_shares,
+ pd(ctx)->cache->share_names,
+ pd(ctx)->cache->num_shares,
&sidx);
if (!found) {
return WERR_NO_SUCH_SERVICE;
@@ -385,18 +407,18 @@ static WERROR smbconf_txt_get_share(struct smbconf_ctx *ctx,
goto done;
}
- for (count = 0; count < pd(ctx)->cache.num_params[sidx]; count++) {
+ for (count = 0; count < pd(ctx)->cache->num_params[sidx]; count++) {
werr = smbconf_add_string_to_array(tmp_ctx,
&tmp_param_names,
count,
- pd(ctx)->cache.param_names[sidx][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,
count,
- pd(ctx)->cache.param_values[sidx][count]);
+ pd(ctx)->cache->param_values[sidx][count]);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -455,23 +477,23 @@ static WERROR smbconf_txt_get_parameter(struct smbconf_ctx *ctx,
}
found = smbconf_txt_find_in_array(service,
- pd(ctx)->cache.share_names,
- pd(ctx)->cache.num_shares,
+ pd(ctx)->cache->share_names,
+ pd(ctx)->cache->num_shares,
&share_index);
if (!found) {
return WERR_NO_SUCH_SERVICE;
}
found = smbconf_txt_find_in_array(param,
- pd(ctx)->cache.param_names[share_index],
- pd(ctx)->cache.num_params[share_index],
- ¶m_index);
+ pd(ctx)->cache->param_names[share_index],
+ pd(ctx)->cache->num_params[share_index],
+ ¶m_index);
if (!found) {
return WERR_INVALID_PARAM;
}
*valstr = talloc_strdup(mem_ctx,
- pd(ctx)->cache.param_values[share_index][param_index]);
+ pd(ctx)->cache->param_values[share_index][param_index]);
if (*valstr == NULL) {
return WERR_NOMEM;
diff --git a/source/utils/net_conf.c b/source/utils/net_conf.c
index 630d01d..1e4ab9b 100644
--- a/source/utils/net_conf.c
+++ b/source/utils/net_conf.c
@@ -131,7 +131,13 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
if (opt_testmode) {
d_printf("[%s]\n", servicename);
} else {
- werr = smbconf_delete_share(conf_ctx, servicename);
+ if (smbconf_share_exists(conf_ctx, servicename)) {
+ werr = smbconf_delete_share(conf_ctx, servicename);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+ }
+ werr = smbconf_create_share(conf_ctx, servicename);
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
@@ -280,6 +286,10 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx,
if (!W_ERROR_IS_OK(werr)) {
goto done;
}
+ werr = smbconf_drop(conf_ctx);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
for (sidx = 0; sidx < num_shares; sidx++) {
werr = import_process_service(conf_ctx,
share_names[sidx],
--
Samba Shared Repository
More information about the samba-cvs
mailing list