[SCM] Samba Shared Repository - branch v3-2-stable updated - release-3-2-0pre2-765-g21b5659

Karolin Seeger kseeger at samba.org
Mon Apr 21 12:18:36 GMT 2008


The branch, v3-2-stable has been updated
       via  21b5659cf8b541dc81cf7141e58e7a481a148b96 (commit)
       via  5505e24f64d45166923e5f85e900d6fffe8199c0 (commit)
       via  433c5fcb1bbde8e4d7cb8620087b6ea109dd111e (commit)
       via  766e8dc1f5984fa9fb8a863dd683fb0ef9747609 (commit)
       via  eac6515d615877cd2cfed7f13dfd813f67e42157 (commit)
       via  ba0c8db0f337dccd63a630a831ea78a2f284dfe3 (commit)
       via  7856edd1b52ebccb9ad6f9993860e8b4d7dd115b (commit)
       via  07d938db72a3ea43b7666284d6b83a7d1c8a6b13 (commit)
       via  94d30b470e63666e57979c904195f39ff57e103b (commit)
       via  5c76dfc4fc04eabf2988b45613b519dbbdf6fb00 (commit)
       via  e43e5e1c645d927e34af5c170b9583e736ca4e1d (commit)
       via  aa7c38aaf25724c4fad2be7a4634b106cb49a8a5 (commit)
       via  aa76d020ca28e693048df72de0186055b3b595d5 (commit)
       via  32608d79e78eb899069ce4196e70b9f8613a531c (commit)
       via  832f54ead4b46b3574e6972651e0e3af07f962c7 (commit)
       via  bad9e77dacbcae46f35183d1f49800b8ed2d610d (commit)
       via  1db5396807c0b569e5ef38aa134b89064cb46ea6 (commit)
       via  4437be90eaa4c105e212f313d1179c462e109f4a (commit)
       via  adfc30240e8e928535b2198677ba68b46ef5f768 (commit)
       via  4fd3044bba8e62fa9c57a92c49064b216d339f3c (commit)
       via  cd04debd9a089335bb0f36f9283edc4c85b401ce (commit)
      from  d5d3ba38e238de4523effec1249a871ff6c2a5b6 (commit)

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


- Log -----------------------------------------------------------------
commit 21b5659cf8b541dc81cf7141e58e7a481a148b96
Author: Michael Adam <obnox at samba.org>
Date:   Mon Apr 21 00:17:49 2008 +0200

    loadparm: rename bNoIncludes to bAllowIncludeRegistry (inverting logic)
    
    This is what that variable controls now...
    
    Michael
    (cherry picked from commit bba04a8fba6fd5cf62578733cfdabea590e8ff51)

commit 5505e24f64d45166923e5f85e900d6fffe8199c0
Author: Michael Adam <obnox at samba.org>
Date:   Mon Apr 21 00:06:45 2008 +0200

    loadparm: make lo_load_initial() only skip registry include.
    
    This is only to be able to set everything properly for registry
    before reading registry includes.
    
    This fixes "make test" as non-root user in a directory, where
    root-daemons have already created a messaging.tdb in the compiled
    in lockdir...
    
    Michael
    (cherry picked from commit 1bb28bc1d8e83d174cd171e9d96f22ac524187c3)

commit 433c5fcb1bbde8e4d7cb8620087b6ea109dd111e
Author: Michael Adam <obnox at samba.org>
Date:   Thu Apr 17 15:22:41 2008 +0200

    build: add missing dependency for libtdb.so to pam_smbpass
    
    Thanks to Andreas Schneider for noticing.
    
    Michael
    (cherry picked from commit db708d4004adcd4a75c28d630dbd43b03e40f205)

commit 766e8dc1f5984fa9fb8a863dd683fb0ef9747609
Author: Michael Adam <obnox at samba.org>
Date:   Wed Apr 16 22:42:49 2008 +0200

    libsmbconf: fix segfault in listing share names / config.
    
    Discovered by Günther while giving a talk. - Sorry Günther!
    
    Michael
    (cherry picked from commit 518f4d4e6662138a2e71acc2296acedefc7c739a)

commit eac6515d615877cd2cfed7f13dfd813f67e42157
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
    (cherry picked from commit 6c1181fda2f040d9555917b10a65bc0dfc1f0593)

commit ba0c8db0f337dccd63a630a831ea78a2f284dfe3
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
    (cherry picked from commit aa167de8252bb615bd21fb3fd9468383b8357d32)

commit 7856edd1b52ebccb9ad6f9993860e8b4d7dd115b
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
    (cherry picked from commit 0212b38913945ce3c8b14734804d81f1cd315621)

commit 07d938db72a3ea43b7666284d6b83a7d1c8a6b13
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
    (cherry picked from commit 367c8b133b2f3e73155f20f689602909eef9827b)

commit 94d30b470e63666e57979c904195f39ff57e103b
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
    (cherry picked from commit b50fdf321dc8056caa2b057cbd7f83792dfbcd4d)

commit 5c76dfc4fc04eabf2988b45613b519dbbdf6fb00
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
    (cherry picked from commit 5424e07e7d3e842488cba7ae389124f01221c5ba)

commit e43e5e1c645d927e34af5c170b9583e736ca4e1d
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
    (cherry picked from commit e1b98f1cbce72d12085d86da834f0949ecbfbf67)

commit aa7c38aaf25724c4fad2be7a4634b106cb49a8a5
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
    (cherry picked from commit cb23052b2055d77924b2a593ec14f0c1de9a3b51)

commit aa76d020ca28e693048df72de0186055b3b595d5
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
    (cherry picked from commit a5923bafe9b543d50dca06d251186948baeac8cc)

commit 32608d79e78eb899069ce4196e70b9f8613a531c
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
    (cherry picked from commit aba261a9143bc7ab681b1c57ccfc08da0cffcfe7)

commit 832f54ead4b46b3574e6972651e0e3af07f962c7
Author: Michael Adam <obnox at samba.org>
Date:   Sun Apr 13 17:22:52 2008 +0200

    loadparm: use the new smbconf_init() dispatcher for loading registry config.
    
    Michael
    (cherry picked from commit 78afb30f8073c3804dfa0cecadf973d5af5dd612)

commit bad9e77dacbcae46f35183d1f49800b8ed2d610d
Author: Michael Adam <obnox at samba.org>
Date:   Sun Apr 13 17:16:54 2008 +0200

    net conf: use the new smbconf_init() dispatcher instead of explicit backend init.
    
    Michael
    (cherry picked from commit 281c9287a34533045b62302bb33ced3d216421ac)

commit 1db5396807c0b569e5ef38aa134b89064cb46ea6
Author: Michael Adam <obnox at samba.org>
Date:   Sun Apr 13 17:13:16 2008 +0200

    libsmbconf: add a smbconf init dispatcher smbconf_init().
    
    The dispatcher takes a config source argument in the form
    of "backend:path" where backend can (currently) be one of
    "txt" (aka "file") or "reg" (aka "registry").
    
    When the path is omitted, it is up to the backend to provide
    a default path.
    
    When there is no separator ":" and the string is not a recognized
    backend, then file backend is assumed and the string is passed
    in as the path argument.
    
    Michael
    (cherry picked from commit cc613a60eb0f6b92cae98e8669e5e569a1eb9324)

commit 4437be90eaa4c105e212f313d1179c462e109f4a
Author: Michael Adam <obnox at samba.org>
Date:   Sun Apr 13 16:36:30 2008 +0200

    libsmbconf: move setting of verbatim variable into a more internal function.
    
    Michael
    (cherry picked from commit 9efd7b515183fa28f400fe88af63e0b0126e3e00)

commit adfc30240e8e928535b2198677ba68b46ef5f768
Author: Michael Adam <obnox at samba.org>
Date:   Sun Apr 13 16:34:40 2008 +0200

    libsmbconf: add a check for talloc failure to smbconf_txt_init().
    
    Michael
    (cherry picked from commit f76ec7d87e206426c795374397ba725ecdeec784)

commit 4fd3044bba8e62fa9c57a92c49064b216d339f3c
Author: Michael Adam <obnox at samba.org>
Date:   Sun Apr 13 16:32:05 2008 +0200

    libsmbconf: remove the bool verbatim parameter from txt backend init function.
    
    Always be verbatim for now. Backend config options may be added later
    via some private data pointer.
    
    Michael
    (cherry picked from commit e8bafcfbf4a7ab1dc1ce4f2acd24b0eb74933256)

commit cd04debd9a089335bb0f36f9283edc4c85b401ce
Author: Michael Adam <obnox at samba.org>
Date:   Sun Apr 13 16:26:14 2008 +0200

    libsmbconf: rename smbconf_init() to smbconf_init_internal().
    
    smbconf_init should be the name of the dispatcher (to be written)
    
    Michael
    (cherry picked from commit 3fb95ab757650712716472ebaccb7119feb27596)

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

Summary of changes:
 source/Makefile.in                      |    5 +-
 source/lib/smbconf/smbconf.c            |    5 +-
 source/lib/smbconf/smbconf.h            |    8 ++-
 source/lib/smbconf/smbconf_init.c       |   95 +++++++++++++++++++++++++++
 source/lib/smbconf/smbconf_private.h    |    4 +-
 source/lib/smbconf/smbconf_reg.c        |  108 ++++++++++++++++++++++++++----
 source/lib/smbconf/smbconf_txt_simple.c |   41 +++++++++---
 source/lib/smbconf/smbconf_util.c       |   24 ++++---
 source/lib/smbconf/testsuite.c          |    2 +-
 source/param/loadparm.c                 |   22 +++---
 source/utils/net_conf.c                 |   30 +++++++--
 11 files changed, 280 insertions(+), 64 deletions(-)
 create mode 100644 source/lib/smbconf/smbconf_init.c


Changeset truncated at 500 lines:

diff --git a/source/Makefile.in b/source/Makefile.in
index 5e70bdf..abd60ce 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -828,7 +828,8 @@ LIBNETAPI_OBJ  = $(LIBNETAPI_OBJ1) $(LIBNET_OBJ) \
 
 LIBSMBCONF_OBJ = lib/smbconf/smbconf.o lib/smbconf/smbconf_util.o \
 		 lib/smbconf/smbconf_reg.o \
-		 lib/smbconf/smbconf_txt_simple.o
+		 lib/smbconf/smbconf_txt_simple.o \
+		 lib/smbconf/smbconf_init.o
 
 SMBCONFTORT_OBJ0 = lib/smbconf/testsuite.o
 
@@ -1988,7 +1989,7 @@ bin/ntlm_auth at EXEEXT@: $(BINARY_PREREQS) $(NTLM_AUTH_OBJ) $(PARAM_OBJ) \
 		@POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS) $(NSCD_LIBS) \
 		@LIBTALLOC_LIBS@ @LIBTDB_LIBS@ @WINBIND_LIBS@
 
-bin/pam_smbpass. at SHLIBEXT@: $(BINARY_PREREQS) $(PAM_SMBPASS_OBJ) @LIBTALLOC_SHARED@ @LIBWBCLIENT_SHARED@
+bin/pam_smbpass. at SHLIBEXT@: $(BINARY_PREREQS) $(PAM_SMBPASS_OBJ) @LIBTALLOC_SHARED@ @LIBWBCLIENT_SHARED@ @LIBTDB_SHARED@
 	@echo "Linking shared library $@"
 	@$(SHLD) $(LDSHFLAGS) -o $@ $(PAM_SMBPASS_OBJ) -lpam $(DYNEXP) \
 		$(LIBS) $(LDAP_LIBS) $(KRB5LIBS) $(NSCD_LIBS) \
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.h b/source/lib/smbconf/smbconf.h
index c04be7f..481c2b1 100644
--- a/source/lib/smbconf/smbconf.h
+++ b/source/lib/smbconf/smbconf.h
@@ -29,15 +29,17 @@ struct smbconf_csn {
 
 /*
  * initialization functions for the available modules
- * (a dispatcher might be added in the future)
  */
+
+WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+		    const char *source);
+
 WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
 			const char *path);
 
 WERROR smbconf_init_txt_simple(TALLOC_CTX *mem_ctx,
 			       struct smbconf_ctx **conf_ctx,
-			       const char *path,
-			       bool verbatim);
+			       const char *path);
 
 /*
  * the smbconf API functions
diff --git a/source/lib/smbconf/smbconf_init.c b/source/lib/smbconf/smbconf_init.c
new file mode 100644
index 0000000..2ad3a08
--- /dev/null
+++ b/source/lib/smbconf/smbconf_init.c
@@ -0,0 +1,95 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  libsmbconf - Samba configuration library, init dispatcher
+ *  Copyright (C) Michael Adam 2008
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "smbconf_private.h"
+
+#define INCLUDES_VALNAME "includes"
+
+
+/**
+ * smbconf initialization dispatcher
+ *
+ * this takes a configuration source in the form of
+ * backend:path and calles the appropriate backend
+ * init function with the path argument
+ *
+ * known backends:
+ * -  "registry" or "reg"
+ * -  "txt" or "file"
+ */
+WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+		    const char *source)
+{
+	WERROR werr;
+	char *backend = NULL;
+	char *path = NULL;
+	char *sep;
+	TALLOC_CTX *tmp_ctx = talloc_stackframe();
+
+	if (conf_ctx == NULL) {
+		werr = WERR_INVALID_PARAM;
+		goto done;
+	}
+
+	if ((source == NULL) || (*source == '\0')) {
+		werr = WERR_INVALID_PARAM;
+		goto done;
+	}
+
+	backend = talloc_strdup(tmp_ctx, source);
+	if (backend == NULL) {
+		werr = WERR_NOMEM;
+		goto done;
+	}
+
+	sep = strchr(backend, ':');
+	if (sep != NULL) {
+		*sep = '\0';
+		path = sep + 1;
+		if (strlen(path) == 0) {
+			path = NULL;
+		}
+	}
+
+	if (strequal(backend, "registry") || strequal(backend, "reg")) {
+		werr = smbconf_init_reg(mem_ctx, conf_ctx, path);
+	} else if (strequal(backend, "file") || strequal(backend, "txt")) {
+		werr = smbconf_init_txt_simple(mem_ctx, conf_ctx, path);
+	} else if (sep == NULL) {
+		/*
+		 * If no separator was given in the source, and the string is
+		 * not a know backend, assume file backend and use the source
+		 * string as a path argument.
+		 */
+		werr = smbconf_init_txt_simple(mem_ctx, conf_ctx, backend);
+	} else {
+		/*
+		 * Separator was specified but this is not a known backend.
+		 * Can't handle this.
+		 */
+		DEBUG(1, ("smbconf_init: ERROR - unknown backend '%s' given\n",
+			  backend));
+		werr = WERR_INVALID_PARAM;
+	}
+
+done:
+	TALLOC_FREE(tmp_ctx);
+	return werr;
+}
diff --git a/source/lib/smbconf/smbconf_private.h b/source/lib/smbconf/smbconf_private.h
index 5acba5a..76f91f9 100644
--- a/source/lib/smbconf/smbconf_private.h
+++ b/source/lib/smbconf/smbconf_private.h
@@ -68,8 +68,8 @@ struct smbconf_ctx {
 	void *data; /* private data for use in backends */
 };
 
-WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
-		    const char *path, struct smbconf_ops *ops);
+WERROR smbconf_init_internal(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+			     const char *path, struct smbconf_ops *ops);
 
 WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
 				   char ***array,
diff --git a/source/lib/smbconf/smbconf_reg.c b/source/lib/smbconf/smbconf_reg.c
index 0ac49a7..a456704 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,
+						   added_count, 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);
@@ -1055,5 +1133,5 @@ struct smbconf_ops smbconf_ops_reg = {
 WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
 			const char *path)
 {
-	return smbconf_init(mem_ctx, conf_ctx, path, &smbconf_ops_reg);
+	return smbconf_init_internal(mem_ctx, conf_ctx, path, &smbconf_ops_reg);
 }
diff --git a/source/lib/smbconf/smbconf_txt_simple.c b/source/lib/smbconf/smbconf_txt_simple.c
index 1bea6cb..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];
@@ -223,6 +229,11 @@ static WERROR smbconf_txt_init(struct smbconf_ctx *ctx, const char *path)
 	}
 
 	ctx->data = TALLOC_ZERO_P(ctx, struct txt_private_data);
+	if (ctx->data == NULL) {
+		return WERR_NOMEM;
+	}
+
+	pd(ctx)->verbatim = true;
 
 	return WERR_OK;
 }
@@ -296,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;
 		}
@@ -307,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;
 		}
 
@@ -602,17 +626,14 @@ static struct smbconf_ops smbconf_ops_txt = {
  */
 WERROR smbconf_init_txt_simple(TALLOC_CTX *mem_ctx,
 			       struct smbconf_ctx **conf_ctx,
-			       const char *path,
-			       bool verbatim)
+			       const char *path)
 {
 	WERROR werr;
 
-	werr = smbconf_init(mem_ctx, conf_ctx, path, &smbconf_ops_txt);
+	werr = smbconf_init_internal(mem_ctx, conf_ctx, path, &smbconf_ops_txt);
 	if (!W_ERROR_IS_OK(werr)) {
 		return werr;
 	}
 
-	pd(*conf_ctx)->verbatim = verbatim;
-
 	return smbconf_txt_load_file(*conf_ctx);
 }
diff --git a/source/lib/smbconf/smbconf_util.c b/source/lib/smbconf/smbconf_util.c
index ee79b63..b2e253d 100644
--- a/source/lib/smbconf/smbconf_util.c
+++ b/source/lib/smbconf/smbconf_util.c
@@ -39,8 +39,8 @@ static int smbconf_destroy_ctx(struct smbconf_ctx *ctx)
  * After the work with the configuration is completed, smbconf_shutdown()
  * should be called.
  */
-WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
-		    const char *path, struct smbconf_ops *ops)
+WERROR smbconf_init_internal(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+			     const char *path, struct smbconf_ops *ops)
 {
 	WERROR werr = WERR_OK;
 	struct smbconf_ctx *ctx;
@@ -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/lib/smbconf/testsuite.c b/source/lib/smbconf/testsuite.c
index af24dff..6f7ce10 100644
--- a/source/lib/smbconf/testsuite.c
+++ b/source/lib/smbconf/testsuite.c
@@ -183,7 +183,7 @@ static bool torture_smbconf_txt(void)


-- 
Samba Shared Repository


More information about the samba-cvs mailing list