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

Michael Adam obnox at samba.org
Sun Apr 13 18:05:22 GMT 2008


The branch, v3-2-test has been updated
       via  78afb30f8073c3804dfa0cecadf973d5af5dd612 (commit)
       via  281c9287a34533045b62302bb33ced3d216421ac (commit)
       via  cc613a60eb0f6b92cae98e8669e5e569a1eb9324 (commit)
       via  9efd7b515183fa28f400fe88af63e0b0126e3e00 (commit)
       via  f76ec7d87e206426c795374397ba725ecdeec784 (commit)
       via  e8bafcfbf4a7ab1dc1ce4f2acd24b0eb74933256 (commit)
       via  3fb95ab757650712716472ebaccb7119feb27596 (commit)
      from  15bef5ae413adf278cccc0e547c4b8ccd180eca2 (commit)

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


- Log -----------------------------------------------------------------
commit 78afb30f8073c3804dfa0cecadf973d5af5dd612
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

commit 281c9287a34533045b62302bb33ced3d216421ac
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

commit cc613a60eb0f6b92cae98e8669e5e569a1eb9324
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

commit 9efd7b515183fa28f400fe88af63e0b0126e3e00
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

commit f76ec7d87e206426c795374397ba725ecdeec784
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

commit e8bafcfbf4a7ab1dc1ce4f2acd24b0eb74933256
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

commit 3fb95ab757650712716472ebaccb7119feb27596
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

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

Summary of changes:
 source/Makefile.in                      |    3 +-
 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        |    2 +-
 source/lib/smbconf/smbconf_txt_simple.c |   12 ++--
 source/lib/smbconf/smbconf_util.c       |    4 +-
 source/lib/smbconf/testsuite.c          |    2 +-
 source/param/loadparm.c                 |    4 +-
 source/utils/net_conf.c                 |   11 +++-
 10 files changed, 126 insertions(+), 19 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 dbc0e46..243a353 100644
--- a/source/Makefile.in
+++ b/source/Makefile.in
@@ -847,7 +847,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
 
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 ce38a20..2bdc11f 100644
--- a/source/lib/smbconf/smbconf_reg.c
+++ b/source/lib/smbconf/smbconf_reg.c
@@ -1055,5 +1055,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..1ce9069 100644
--- a/source/lib/smbconf/smbconf_txt_simple.c
+++ b/source/lib/smbconf/smbconf_txt_simple.c
@@ -223,6 +223,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;
 }
@@ -602,17 +607,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..1a3a0de 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;
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)
 	printf("test: text backend\n");
 
 	printf("test: init\n");
-	werr = smbconf_init_txt_simple(mem_ctx, &conf_ctx, NULL, true);
+	werr = smbconf_init_txt_simple(mem_ctx, &conf_ctx, NULL);
 	if (!W_ERROR_IS_OK(werr)) {
 		printf("failure: init failed: %s\n", dos_errstr(werr));
 		ret = false;
diff --git a/source/param/loadparm.c b/source/param/loadparm.c
index 27bf1e8..d5fd571 100644
--- a/source/param/loadparm.c
+++ b/source/param/loadparm.c
@@ -6498,7 +6498,7 @@ static bool process_registry_globals(bool (*pfunc)(const char *, const char *, v
 
 	if (conf_ctx == NULL) {
 		/* first time */
-		werr = smbconf_init_reg(NULL, &conf_ctx, NULL);
+		werr = smbconf_init(NULL, &conf_ctx, "registry:");
 		if (!W_ERROR_IS_OK(werr)) {
 			goto done;
 		}
@@ -6608,7 +6608,7 @@ bool lp_file_list_changed(void)
 	if (lp_config_backend_is_registry()) {
 		if (conf_ctx == NULL) {
 			WERROR werr;
-			werr = smbconf_init_reg(NULL, &conf_ctx, NULL);
+			werr = smbconf_init(NULL, &conf_ctx, "registry:");
 			if (!W_ERROR_IS_OK(werr)) {
 				DEBUG(0, ("error opening configuration: %s\n",
 					  dos_errstr(werr)));
diff --git a/source/utils/net_conf.c b/source/utils/net_conf.c
index 7221f3b..88cc15e 100644
--- a/source/utils/net_conf.c
+++ b/source/utils/net_conf.c
@@ -266,6 +266,7 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx,
 	int ret = -1;
 	const char *filename = NULL;
 	const char *servicename = NULL;
+	char *conf_source = NULL;
 	TALLOC_CTX *mem_ctx;
 	struct smbconf_ctx *txt_ctx;
 	WERROR werr;
@@ -291,7 +292,13 @@ static int net_conf_import(struct smbconf_ctx *conf_ctx,
 	DEBUG(3,("net_conf_import: reading configuration from file %s.\n",
 		filename));
 
-	werr = smbconf_init_txt_simple(mem_ctx, &txt_ctx, filename, true);
+	conf_source = talloc_asprintf(mem_ctx, "file:%s", filename);
+	if (conf_source == NULL) {
+		d_printf("error: out of memory!\n");
+		goto done;
+	}
+
+	werr = smbconf_init(mem_ctx, &txt_ctx, conf_source);
 	if (!W_ERROR_IS_OK(werr)) {
 		d_printf("error loading file '%s': %s\n", filename,
 			 dos_errstr(werr));
@@ -969,7 +976,7 @@ static int net_conf_wrap_function(int (*fn)(struct smbconf_ctx *,
 	struct smbconf_ctx *conf_ctx;
 	int ret = -1;
 
-	werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
+	werr = smbconf_init(mem_ctx, &conf_ctx, "registry:");
 
 	if (!W_ERROR_IS_OK(werr)) {
 		return -1;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list