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

Michael Adam obnox at samba.org
Sat Mar 22 01:37:25 GMT 2008


The branch, v3-2-test has been updated
       via  03e72e13076e3215eb8ae51cfb4e7cd3d3683d3e (commit)
       via  513ae78ef78d3ddcb155f9c38b9a0c82809e0998 (commit)
       via  a02163356bdd0c17a25a45e9904f8bd1e1c4bee4 (commit)
      from  96434d9dc7a66773e313cc128af57493dee245a1 (commit)

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


- Log -----------------------------------------------------------------
commit 03e72e13076e3215eb8ae51cfb4e7cd3d3683d3e
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 21 23:39:01 2008 +0100

    libsmbconf: add internal open/close handling to registry backend.
    
    This internally keeps track of opened registry in the private data
    struct. The first call that really accesses data, opens the registry
    and it is kept open until the destructor is called.
    
    This behaviour might be changed in the future.
    
    Michael

commit 513ae78ef78d3ddcb155f9c38b9a0c82809e0998
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 21 22:55:20 2008 +0100

    libsmbconf: add a comment.
    
    Michael

commit a02163356bdd0c17a25a45e9904f8bd1e1c4bee4
Author: Michael Adam <obnox at samba.org>
Date:   Fri Mar 21 22:52:27 2008 +0100

    libsmbconf: add private_data section to smbconf_ctx.
    
    This private data should be used by backends.
    The token for the registry backend is moved from
    the context to the private data section, since
    this is registry specific.
    
    Michael

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

Summary of changes:
 source/lib/smbconf/smbconf_private.h |    2 +-
 source/lib/smbconf/smbconf_reg.c     |   69 +++++++++++++++++++++++++++++-----
 2 files changed, 60 insertions(+), 11 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/smbconf/smbconf_private.h b/source/lib/smbconf/smbconf_private.h
index 6250dc7..e08a2b1 100644
--- a/source/lib/smbconf/smbconf_private.h
+++ b/source/lib/smbconf/smbconf_private.h
@@ -54,9 +54,9 @@ struct smbconf_ops {
 };
 
 struct smbconf_ctx {
-	NT_USER_TOKEN *token;
 	const char *path;
 	struct smbconf_ops *ops;
+	void *data; /* private data for use in backends */
 };
 
 WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
diff --git a/source/lib/smbconf/smbconf_reg.c b/source/lib/smbconf/smbconf_reg.c
index beb1c20..1f113c8 100644
--- a/source/lib/smbconf/smbconf_reg.c
+++ b/source/lib/smbconf/smbconf_reg.c
@@ -20,6 +20,10 @@
 #include "includes.h"
 #include "smbconf_private.h"
 
+struct reg_private_data {
+	NT_USER_TOKEN *token;
+	bool open;		/* did _we_ open the registry? */
+};
 
 /**********************************************************************
  *
@@ -28,6 +32,14 @@
  **********************************************************************/
 
 /**
+ * a convenience helper to cast the private data structure
+ */
+static struct reg_private_data *rpd(struct smbconf_ctx *ctx)
+{
+	return (struct reg_private_data *)(ctx->data);
+}
+
+/**
  * Open a registry key specified by "path"
  */
 static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx,
@@ -44,20 +56,27 @@ static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx,
 		goto done;
 	}
 
-	if (ctx->token == NULL) {
+	if (rpd(ctx)->token == NULL) {
 		DEBUG(1, ("Error: token missing from smbconf_ctx. "
 			  "was smbconf_init() called?\n"));
 		werr = WERR_INVALID_PARAM;
 		goto done;
 	}
 
+	werr = ctx->ops->open_conf(ctx);
+	if (!W_ERROR_IS_OK(werr)) {
+		DEBUG(1, ("Error opening the registry.\n"));
+		goto done;
+	}
+
 	if (path == NULL) {
 		DEBUG(1, ("Error: NULL path string given\n"));
 		werr = WERR_INVALID_PARAM;
 		goto done;
 	}
 
-	werr = reg_open_path(mem_ctx, path, desired_access, ctx->token, key);
+	werr = reg_open_path(mem_ctx, path, desired_access, rpd(ctx)->token,
+			     key);
 
 	if (!W_ERROR_IS_OK(werr)) {
 		DEBUG(1, ("Error opening registry path '%s': %s\n",
@@ -385,17 +404,22 @@ static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
 		goto done;
 	}
 
-	if (!registry_init_smbconf()) {
-		werr = WERR_REG_IO_FAILURE;
-		goto done;
-	}
+	ctx->data = TALLOC_ZERO_P(ctx, struct reg_private_data);
 
 	werr = ntstatus_to_werror(registry_create_admin_token(ctx,
-							      &(ctx->token)));
+							&(rpd(ctx)->token)));
 	if (!W_ERROR_IS_OK(werr)) {
 		DEBUG(1, ("Error creating admin token\n"));
 		goto done;
 	}
+	rpd(ctx)->open = false;
+
+	if (!registry_init_smbconf()) {
+		werr = WERR_REG_IO_FAILURE;
+		goto done;
+	}
+	/* we know registry_init_smbconf() leaves registry open */
+	regdb_close();
 
 done:
 	return werr;
@@ -403,17 +427,37 @@ done:
 
 static int smbconf_reg_shutdown(struct smbconf_ctx *ctx)
 {
-	return regdb_close();
+	return ctx->ops->close_conf(ctx);
 }
 
 static WERROR smbconf_reg_open(struct smbconf_ctx *ctx)
 {
-	return regdb_open();
+	WERROR werr;
+
+	if (rpd(ctx)->open) {
+		return WERR_OK;
+	}
+
+	werr = regdb_open();
+	if (W_ERROR_IS_OK(werr)) {
+		rpd(ctx)->open = true;
+	}
+	return werr;
 }
 
 static int smbconf_reg_close(struct smbconf_ctx *ctx)
 {
-	return regdb_close();
+	int ret;
+
+	if (!rpd(ctx)->open) {
+		return 0;
+	}
+
+	ret = regdb_close();
+	if (ret == 0) {
+		rpd(ctx)->open = false;
+	}
+	return ret;
 }
 
 /**
@@ -427,6 +471,11 @@ static void smbconf_reg_get_csn(struct smbconf_ctx *ctx,
 	if (csn == NULL) {
 		return;
 	}
+
+	if (!W_ERROR_IS_OK(ctx->ops->open_conf(ctx))) {
+		return;
+	}
+
 	csn->csn = (uint64_t)regdb_get_seqnum();
 }
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list