summaryrefslogtreecommitdiff
path: root/source3/lib/smbconf
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2008-03-21 23:39:01 +0100
committerMichael Adam <obnox@samba.org>2008-03-21 23:43:52 +0100
commita81ed36e86cf9c275538aea03c80c1ee00122f4a (patch)
treec23dec9c8250f7570d30b4a9e5d8b7fa897dfa72 /source3/lib/smbconf
parentaa3e4d56cb6070a433afe4f460fc426e60882103 (diff)
downloadsamba-a81ed36e86cf9c275538aea03c80c1ee00122f4a.tar.gz
samba-a81ed36e86cf9c275538aea03c80c1ee00122f4a.tar.bz2
samba-a81ed36e86cf9c275538aea03c80c1ee00122f4a.zip
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 (This used to be commit 03e72e13076e3215eb8ae51cfb4e7cd3d3683d3e)
Diffstat (limited to 'source3/lib/smbconf')
-rw-r--r--source3/lib/smbconf/smbconf_reg.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/source3/lib/smbconf/smbconf_reg.c b/source3/lib/smbconf/smbconf_reg.c
index 98613efc2a..1f113c835f 100644
--- a/source3/lib/smbconf/smbconf_reg.c
+++ b/source3/lib/smbconf/smbconf_reg.c
@@ -22,6 +22,7 @@
struct reg_private_data {
NT_USER_TOKEN *token;
+ bool open; /* did _we_ open the registry? */
};
/**********************************************************************
@@ -62,6 +63,12 @@ static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx,
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;
@@ -405,12 +412,14 @@ static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
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;
@@ -418,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;
}
/**
@@ -442,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();
}