Make libnet_conf handle opening/initialization of the registry.
authorMichael Adam <obnox@samba.org>
Thu, 3 Jan 2008 14:33:09 +0000 (15:33 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 3 Jan 2008 14:33:09 +0000 (15:33 +0100)
Open state is currently tracked by a global variable
to avoid double initialization.

Later, this can possibly be replaced by a conf-context
created by an initialization function and passed around
to the other api functions.

Michael
(This used to be commit 77713e776405800ac54c692a77cd4efd153042cb)

source3/libnet/libnet_conf.c
source3/utils/net_conf.c

index 86ef3e5517c6bbd34465dd21f43a6e3ea22a6e07..665261723b2b43188ccb060f8819e63aa9ded2cb 100644 (file)
 #include "includes.h"
 #include "libnet/libnet.h"
 
+/*
+ * yuck - static variable to keep track of the registry initialization. 
+ */
+static bool registry_initialized = false;
+
 /**********************************************************************
  *
  * Helper functions (mostly registry related)
@@ -54,6 +59,26 @@ static WERROR libnet_conf_add_string_to_array(TALLOC_CTX *mem_ctx,
        return WERR_OK;
 }
 
+static WERROR libnet_conf_reg_initialize(void)
+{
+       WERROR werr = WERR_OK;
+
+       if (registry_initialized) {
+               goto done;
+       }
+
+       if (!registry_init_regdb()) {
+               /* proper error code? */
+               werr = WERR_GENERAL_FAILURE;
+               goto done;
+       }
+
+       registry_initialized = true;
+
+done:
+       return werr;
+}
+
 /**
  * Open a registry key specified by "path"
  */
@@ -78,6 +103,13 @@ static WERROR libnet_conf_reg_open_path(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
+       werr = libnet_conf_reg_initialize();
+       if (!W_ERROR_IS_OK(werr)) {
+               DEBUG(1, ("Error initializing registry: %s\n",
+                         dos_errstr(werr)));
+               goto done;
+       }
+
        token = registry_create_admin_token(tmp_ctx);
        if (token == NULL) {
                DEBUG(1, ("Error creating admin token\n"));
index 2d4b3f40541aec7cbe303e7e4bd801da120c3717..a758391630b497296f8605075bf60917701ef006 100644 (file)
@@ -852,11 +852,6 @@ int net_conf(int argc, const char **argv)
                {NULL, NULL, NULL}
        };
 
-       if (!registry_init_regdb()) {
-               d_fprintf(stderr, "Error initializing the registry!\n");
-               goto done;
-       }
-
        ret = net_run_function2(argc, argv, "net conf", func);
 
        regdb_close();