[SCM] Samba Shared Repository - branch v3-2-test updated - release-3-2-0pre2-924-g6c1181f

Michael Adam obnox at samba.org
Tue Apr 15 16:04:15 GMT 2008


The branch, v3-2-test has been updated
       via  6c1181fda2f040d9555917b10a65bc0dfc1f0593 (commit)
       via  aa167de8252bb615bd21fb3fd9468383b8357d32 (commit)
       via  0212b38913945ce3c8b14734804d81f1cd315621 (commit)
       via  367c8b133b2f3e73155f20f689602909eef9827b (commit)
       via  b50fdf321dc8056caa2b057cbd7f83792dfbcd4d (commit)
       via  5424e07e7d3e842488cba7ae389124f01221c5ba (commit)
       via  e1b98f1cbce72d12085d86da834f0949ecbfbf67 (commit)
       via  cb23052b2055d77924b2a593ec14f0c1de9a3b51 (commit)
       via  a5923bafe9b543d50dca06d251186948baeac8cc (commit)
       via  aba261a9143bc7ab681b1c57ccfc08da0cffcfe7 (commit)
      from  ac4c63d999f9ae61428bcdae400d127459896d6c (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 6c1181fda2f040d9555917b10a65bc0dfc1f0593
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 17:39:01 2008 +0200

    libmsbconf: add handling of NULL share parameters to registry backend.
    
    Michael

commit aa167de8252bb615bd21fb3fd9468383b8357d32
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 17:37:39 2008 +0200

    libsmbconf: don't complain with WERR_ALREADY_EXISTS for NULL share in smbconf_create_share().
    
    These are values stored inside the base key for registry.
    This is not getting deleted.
    
    Michael

commit 0212b38913945ce3c8b14734804d81f1cd315621
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 17:36:44 2008 +0200

    net conf: adapt output of NULL share params in net conf list.
    
    don't list NULL share name and don't indent these parameters
    
    Michael

commit 367c8b133b2f3e73155f20f689602909eef9827b
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 17:36:11 2008 +0200

    net conf: simplify logic in test output of net conf import.
    
    Michael

commit b50fdf321dc8056caa2b057cbd7f83792dfbcd4d
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 16:06:57 2008 +0200

    libsmbconf: make sure to always list the NULL section first in text backend.
    
    Michael

commit 5424e07e7d3e842488cba7ae389124f01221c5ba
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 14:38:36 2008 +0200

    net conf: fix output of out-of-share parameters in test mode import
    
    Michael

commit e1b98f1cbce72d12085d86da834f0949ecbfbf67
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 14:37:15 2008 +0200

    libsmbconf: default to the NULL section when a parameter is encountered w/o section
    
    Michael

commit cb23052b2055d77924b2a593ec14f0c1de9a3b51
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 14:36:39 2008 +0200

    libsmbconf: allow NULL sharename in smbconf_share_exists().
    
    Michael

commit a5923bafe9b543d50dca06d251186948baeac8cc
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 13:50:27 2008 +0200

    libsmbconf: add handling of NULL strings to smbconf_find_in_array().
    
    Michael

commit aba261a9143bc7ab681b1c57ccfc08da0cffcfe7
Author: Michael Adam <obnox at samba.org>
Date:   Tue Apr 15 13:49:59 2008 +0200

    libsmbconf: add handling of "NULL" strings to smbconf_add_string_to_array()
    
    Michael

-----------------------------------------------------------------------

Summary of changes:
 source/lib/smbconf/smbconf.c            |    5 +-
 source/lib/smbconf/smbconf_reg.c        |  106 +++++++++++++++++++++++++++----
 source/lib/smbconf/smbconf_txt_simple.c |   29 +++++++--
 source/lib/smbconf/smbconf_util.c       |   20 ++++--
 source/utils/net_conf.c                 |   19 ++++--
 5 files changed, 144 insertions(+), 35 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/smbconf/smbconf.c b/source/lib/smbconf/smbconf.c
index 541b163..9565540 100644
--- a/source/lib/smbconf/smbconf.c
+++ b/source/lib/smbconf/smbconf.c
@@ -183,9 +183,6 @@ WERROR smbconf_get_share_names(struct smbconf_ctx *ctx,
 bool smbconf_share_exists(struct smbconf_ctx *ctx,
 			  const char *servicename)
 {
-	if (servicename == NULL) {
-		return false;
-	}
 	return ctx->ops->share_exists(ctx, servicename);
 }
 
@@ -195,7 +192,7 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx,
 WERROR smbconf_create_share(struct smbconf_ctx *ctx,
 			    const char *servicename)
 {
-	if (smbconf_share_exists(ctx, servicename)) {
+	if ((servicename != NULL) && smbconf_share_exists(ctx, servicename)) {
 		return WERR_ALREADY_EXISTS;
 	}
 
diff --git a/source/lib/smbconf/smbconf_reg.c b/source/lib/smbconf/smbconf_reg.c
index 2bdc11f..39b05f7 100644
--- a/source/lib/smbconf/smbconf_reg.c
+++ b/source/lib/smbconf/smbconf_reg.c
@@ -131,12 +131,11 @@ static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
 	char *path = NULL;
 
 	if (servicename == NULL) {
-		DEBUG(3, ("Error: NULL servicename given.\n"));
-		werr = WERR_INVALID_PARAM;
-		goto done;
+		path = talloc_strdup(mem_ctx, ctx->path);
+	} else {
+		path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path,
+				       servicename);
 	}
-
-	path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path, servicename);
 	if (path == NULL) {
 		werr = WERR_NOMEM;
 		goto done;
@@ -544,6 +543,65 @@ done:
 	return werr;
 }
 
+static bool smbconf_reg_key_has_values(struct registry_key *key)
+{
+	WERROR werr;
+	uint32_t num_subkeys;
+	uint32_t max_subkeylen;
+	uint32_t max_subkeysize;
+	uint32_t num_values;
+	uint32_t max_valnamelen;
+	uint32_t max_valbufsize;
+	uint32_t secdescsize;
+	NTTIME last_changed_time;
+
+	werr = reg_queryinfokey(key, &num_subkeys, &max_subkeylen,
+				&max_subkeysize, &num_values, &max_valnamelen,
+				&max_valbufsize, &secdescsize,
+				&last_changed_time);
+	if (!W_ERROR_IS_OK(werr)) {
+		return false;
+	}
+
+	return (num_values != 0);
+}
+
+/**
+ * delete all values from a key
+ */
+static WERROR smbconf_reg_delete_values(struct registry_key *key)
+{
+	WERROR werr;
+	char *valname;
+	struct registry_value *valvalue;
+	uint32_t count;
+	TALLOC_CTX *mem_ctx = talloc_stackframe();
+
+	for (count = 0;
+	     werr = reg_enumvalue(mem_ctx, key, count, &valname, &valvalue),
+	     W_ERROR_IS_OK(werr);
+	     count++)
+	{
+		werr = reg_deletevalue(key, valname);
+		if (!W_ERROR_IS_OK(werr)) {
+			goto done;
+		}
+	}
+	if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) {
+		DEBUG(1, ("smbconf_reg_delete_values: "
+			  "Error enumerating values of %s: %s\n",
+			  key->key->name,
+			  dos_errstr(werr)));
+		goto done;
+	}
+
+	werr = WERR_OK;
+
+done:
+	TALLOC_FREE(mem_ctx);
+	return werr;
+}
+
 /**********************************************************************
  *
  * smbconf operations: registry implementations
@@ -707,20 +765,30 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx,
 		goto done;
 	}
 
-	/* make sure "global" is always listed first */
-	if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
+	/* if there are values in the base key, return NULL as share name */
+	werr = smbconf_reg_open_base_key(tmp_ctx, ctx,
+					 SEC_RIGHTS_ENUM_SUBKEYS, &key);
+	if (!W_ERROR_IS_OK(werr)) {
+		goto done;
+	}
+
+	if (smbconf_reg_key_has_values(key)) {
 		werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
-						   0, GLOBAL_NAME);
+						   0, NULL);
 		if (!W_ERROR_IS_OK(werr)) {
 			goto done;
 		}
 		added_count++;
 	}
 
-	werr = smbconf_reg_open_base_key(tmp_ctx, ctx,
-					 SEC_RIGHTS_ENUM_SUBKEYS, &key);
-	if (!W_ERROR_IS_OK(werr)) {
-		goto done;
+	/* 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,
+						   1, GLOBAL_NAME);
+		if (!W_ERROR_IS_OK(werr)) {
+			goto done;
+		}
+		added_count++;
 	}
 
 	for (count = 0;
@@ -789,7 +857,13 @@ static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx,
 	TALLOC_CTX *mem_ctx = talloc_stackframe();
 	struct registry_key *key = NULL;
 
-	werr = smbconf_reg_create_service_key(mem_ctx, ctx, servicename, &key);
+	if (servicename == NULL) {
+		werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE,
+						 &key);
+	} else {
+		werr = smbconf_reg_create_service_key(mem_ctx, ctx,
+						      servicename, &key);
+	}
 
 	TALLOC_FREE(mem_ctx);
 	return werr;
@@ -836,7 +910,11 @@ static WERROR smbconf_reg_delete_share(struct smbconf_ctx *ctx,
 		goto done;
 	}
 
-	werr = reg_deletekey_recursive(key, key, servicename);
+	if (servicename != NULL) {
+		werr = reg_deletekey_recursive(key, key, servicename);
+	} else {
+		werr = smbconf_reg_delete_values(key);
+	}
 
 done:
 	TALLOC_FREE(mem_ctx);
diff --git a/source/lib/smbconf/smbconf_txt_simple.c b/source/lib/smbconf/smbconf_txt_simple.c
index 1ce9069..d2dc24a 100644
--- a/source/lib/smbconf/smbconf_txt_simple.c
+++ b/source/lib/smbconf/smbconf_txt_simple.c
@@ -121,8 +121,14 @@ static bool smbconf_txt_do_parameter(const char *param_name,
 	struct txt_cache *cache = tpd->cache;
 
 	if (cache->num_shares == 0) {
-		/* not in any share ... */
-		return false;
+		/*
+		 * not in any share yet,
+		 * initialize the "empty" section (NULL):
+		 * parameters without a previous [section] are stored here.
+		 */
+		if (!smbconf_txt_do_section(NULL, private_data)) {
+			return false;
+		}
 	}
 
 	param_names  = cache->param_names[cache->current_share];
@@ -301,10 +307,21 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
 		goto done;
 	}
 
-	/* make sure "global" is always listed first */
+	/* make sure "global" is always listed first,
+	 * 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)) {
+			goto done;
+		}
+		added_count++;
+	}
+
 	if (smbconf_share_exists(ctx, GLOBAL_NAME)) {
 		werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names,
-						   0, GLOBAL_NAME);
+						   added_count, GLOBAL_NAME);
 		if (!W_ERROR_IS_OK(werr)) {
 			goto done;
 		}
@@ -312,7 +329,9 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx,
 	}
 
 	for (count = 0; count < pd(ctx)->cache->num_shares; count++) {
-		if (strequal(pd(ctx)->cache->share_names[count], GLOBAL_NAME)) {
+		if (strequal(pd(ctx)->cache->share_names[count], GLOBAL_NAME) ||
+		    (pd(ctx)->cache->share_names[count] == NULL))
+		{
 			continue;
 		}
 
diff --git a/source/lib/smbconf/smbconf_util.c b/source/lib/smbconf/smbconf_util.c
index 1a3a0de..b2e253d 100644
--- a/source/lib/smbconf/smbconf_util.c
+++ b/source/lib/smbconf/smbconf_util.c
@@ -82,7 +82,7 @@ WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
 {
 	char **new_array = NULL;
 
-	if ((array == NULL) || (string == NULL)) {
+	if (array == NULL) {
 		return WERR_INVALID_PARAM;
 	}
 
@@ -91,10 +91,14 @@ WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
 		return WERR_NOMEM;
 	}
 
-	new_array[count] = talloc_strdup(new_array, string);
-	if (new_array[count] == NULL) {
-		TALLOC_FREE(new_array);
-		return WERR_NOMEM;
+	if (string == NULL) {
+		new_array[count] = NULL;
+	} else {
+		new_array[count] = talloc_strdup(new_array, string);
+		if (new_array[count] == NULL) {
+			TALLOC_FREE(new_array);
+			return WERR_NOMEM;
+		}
 	}
 
 	*array = new_array;
@@ -107,12 +111,14 @@ bool smbconf_find_in_array(const char *string, char **list,
 {
 	uint32_t i;
 
-	if ((string == NULL) || (list == NULL)) {
+	if (list == NULL) {
 		return false;
 	}
 
 	for (i = 0; i < num_entries; i++) {
-		if (strequal(string, list[i])) {
+		if (((string == NULL) && (list[i] == NULL)) ||
+		    strequal(string, list[i]))
+		{
 			if (entry != NULL) {
 				*entry = i;
 			}
diff --git a/source/utils/net_conf.c b/source/utils/net_conf.c
index 88cc15e..4fffcf8 100644
--- a/source/utils/net_conf.c
+++ b/source/utils/net_conf.c
@@ -150,9 +150,13 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx,
 	TALLOC_CTX *mem_ctx = talloc_stackframe();
 
 	if (opt_testmode) {
-		d_printf("[%s]\n", servicename);
-		for (idx = 0; idx < num_params; idx ++) {
-			d_printf("\t%s = %s\n", param_names[idx],
+		const char *indent = "";
+		if (servicename != NULL) {
+			d_printf("[%s]\n", servicename);
+			indent = "\t";
+		}
+		for (idx = 0; idx < num_params; idx++) {
+			d_printf("%s%s = %s\n", indent, param_names[idx],
 				 param_values[idx]);
 		}
 		d_printf("\n");
@@ -242,11 +246,16 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx,
 	}
 
 	for (share_count = 0; share_count < num_shares; share_count++) {
-		d_printf("[%s]\n", share_names[share_count]);
+		const char *indent = "";
+		if (share_names[share_count] != NULL) {
+			d_printf("[%s]\n", share_names[share_count]);
+			indent = "\t";
+		}
 		for (param_count = 0; param_count < num_params[share_count];
 		     param_count++)
 		{
-			d_printf("\t%s = %s\n",
+			d_printf("%s%s = %s\n",
+				 indent,
 				 param_names[share_count][param_count],
 				 param_values[share_count][param_count]);
 		}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list