libsmbconf: add internal open/close handling to registry backend.
authorMichael Adam <obnox@samba.org>
Fri, 21 Mar 2008 22:39:01 +0000 (23:39 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 21 Mar 2008 22:43:52 +0000 (23:43 +0100)
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)

source3/lib/smbconf/smbconf_reg.c

index 98613efc2a0ec15cf62e7f64b360acd7263714d5..1f113c835ff1bd3cb43de2a4ce3cc83a0b4cefa2 100644 (file)
@@ -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();
 }