libsmbconf: add a "path" variable to the conf context.
authorMichael Adam <obnox@samba.org>
Fri, 21 Mar 2008 16:55:31 +0000 (17:55 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 21 Mar 2008 17:19:24 +0000 (18:19 +0100)
This is passed to the module init routines.
In case of the registry, this is the path of the
basekey in registry, that is to be used, defaulting
to KEY_SMBCONF (HKLM\software\samba\smbconf), when
NULL is given. This is the only case currently used.

In order to support other keys, registry initialization
for smbconf has to be changed to support different keys.

Michael
(This used to be commit 96434d9dc7a66773e313cc128af57493dee245a1)

source3/lib/netapi/serverinfo.c
source3/lib/smbconf/smbconf.c
source3/lib/smbconf/smbconf.h
source3/lib/smbconf/smbconf_private.h
source3/lib/smbconf/smbconf_reg.c
source3/libnet/libnet_join.c
source3/param/loadparm.c
source3/utils/net_conf.c

index 913338fd4951c34657c97f824d09fe6b948ac0a8..a9749a12f96f6f98b4551c5a7faf6e24621ec2f4 100644 (file)
@@ -191,7 +191,7 @@ static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx,
                return WERR_NOT_SUPPORTED;
        }
 
-       werr = smbconf_init_reg(ctx, &conf_ctx);
+       werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
index 0eee5a6c4a2c2425936be912625066c44c988281..756b9ec3caca2d2c1e475644718dfef3bea8d2af 100644 (file)
@@ -92,7 +92,7 @@ static WERROR smbconf_global_check(struct smbconf_ctx *ctx)
  * should be called.
  */
 WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
-                   struct smbconf_ops *ops)
+                   const char *path, struct smbconf_ops *ops)
 {
        WERROR werr = WERR_OK;
        struct smbconf_ctx *ctx;
@@ -108,7 +108,7 @@ WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
 
        ctx->ops = ops;
 
-       werr = ctx->ops->init(ctx);
+       werr = ctx->ops->init(ctx, path);
        if (!W_ERROR_IS_OK(werr)) {
                goto fail;
        }
index 35da36795edd30c4e5ae37df27d5baf3bc6d738d..23b95049712e8f19d31024fe674757f80c152a2c 100644 (file)
@@ -35,7 +35,8 @@ struct smbconf_csn {
  * initialization functions for the available modules
  * (a dispatcher might be added in the future)
  */
-WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx);
+WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+                       const char *path);
 
 /*
  * the smbconf API functions
index 008ae976011fcea7d9724b0a682a543bff15729d..6250dc7339663c5f951f211658e986e91a4e3771 100644 (file)
@@ -21,7 +21,7 @@
 #define __LIBSMBCONF_PRIVATE_H__
 
 struct smbconf_ops {
-       WERROR (*init)(struct smbconf_ctx *ctx);
+       WERROR (*init)(struct smbconf_ctx *ctx, const char *path);
        int (*shutdown)(struct smbconf_ctx *ctx);
        WERROR (*open_conf)(struct smbconf_ctx *ctx);
        int (*close_conf)(struct smbconf_ctx *ctx);
@@ -55,6 +55,7 @@ struct smbconf_ops {
 
 struct smbconf_ctx {
        NT_USER_TOKEN *token;
+       const char *path;
        struct smbconf_ops *ops;
 };
 
@@ -64,6 +65,6 @@ WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx,
                                   const char *string);
 
 WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
-                   struct smbconf_ops *ops);
+                   const char *path, struct smbconf_ops *ops);
 
 #endif
index f0a1f17f8e8c4351983d47ac23520261bb899eab..beb1c20de6e82f6f8bb93063fb15b53415f31398 100644 (file)
@@ -69,7 +69,7 @@ done:
 }
 
 /**
- * Open a subkey of KEY_SMBCONF (i.e a service)
+ * Open a subkey of the base key (i.e a service)
  */
 static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
                                           struct smbconf_ctx *ctx,
@@ -86,7 +86,7 @@ static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       path = talloc_asprintf(mem_ctx, "%s\\%s", KEY_SMBCONF, servicename);
+       path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path, servicename);
        if (path == NULL) {
                werr = WERR_NOMEM;
                goto done;
@@ -100,14 +100,14 @@ done:
 }
 
 /**
- * open the base key KEY_SMBCONF
+ * open the base key
  */
 static WERROR smbconf_reg_open_base_key(TALLOC_CTX *mem_ctx,
                                        struct smbconf_ctx *ctx,
                                        uint32 desired_access,
                                        struct registry_key **key)
 {
-       return smbconf_reg_open_path(mem_ctx, ctx, KEY_SMBCONF, desired_access,
+       return smbconf_reg_open_path(mem_ctx, ctx, ctx->path, desired_access,
                                     key);
 }
 
@@ -131,7 +131,7 @@ static bool smbconf_value_exists(struct registry_key *key, const char *param)
 }
 
 /**
- * create a subkey of KEY_SMBCONF
+ * create a subkey of the base key (i.e. a service...)
  */
 static WERROR smbconf_reg_create_service_key(TALLOC_CTX *mem_ctx,
                                             struct smbconf_ctx *ctx,
@@ -372,10 +372,19 @@ done:
 /**
  * initialize the registry smbconf backend
  */
-static WERROR smbconf_reg_init(struct smbconf_ctx *ctx)
+static WERROR smbconf_reg_init(struct smbconf_ctx *ctx, const char *path)
 {
        WERROR werr = WERR_OK;
 
+       if (path == NULL) {
+               path = KEY_SMBCONF;
+       }
+       ctx->path = talloc_strdup(ctx, path);
+       if (ctx->path == NULL) {
+               werr = WERR_NOMEM;
+               goto done;
+       }
+
        if (!registry_init_smbconf()) {
                werr = WERR_REG_IO_FAILURE;
                goto done;
@@ -433,7 +442,7 @@ static WERROR smbconf_reg_drop(struct smbconf_ctx *ctx)
        TALLOC_CTX* mem_ctx = talloc_stackframe();
        enum winreg_CreateAction action;
 
-       path = talloc_strdup(mem_ctx, KEY_SMBCONF);
+       path = talloc_strdup(mem_ctx, ctx->path);
        if (path == NULL) {
                werr = WERR_NOMEM;
                goto done;
@@ -742,7 +751,8 @@ struct smbconf_ops smbconf_ops_reg = {
  * initialize the smbconf registry backend
  * the only function that is exported from this module
  */
-WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx)
+WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,
+                       const char *path)
 {
-       return smbconf_init(mem_ctx, conf_ctx, &smbconf_ops_reg);
+       return smbconf_init(mem_ctx, conf_ctx, path, &smbconf_ops_reg);
 }
index 52376ac8218f21b677a27625dfc16cfa11679ab1..6d5449ff57e9e6f2e1d71778dd12d4f45d351816 100644 (file)
@@ -1198,7 +1198,7 @@ static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
        WERROR werr;
        struct smbconf_ctx *ctx;
 
-       werr = smbconf_init_reg(r, &ctx);
+       werr = smbconf_init_reg(r, &ctx, NULL);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
@@ -1242,7 +1242,7 @@ static WERROR do_unjoin_modify_vals_config(struct libnet_UnjoinCtx *r)
        WERROR werr = WERR_OK;
        struct smbconf_ctx *ctx;
 
-       werr = smbconf_init_reg(r, &ctx);
+       werr = smbconf_init_reg(r, &ctx, NULL);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }
index 72129693445c2f7f5a2513ea17ca1261e59bab06..f61d0d8fdc14a8fa41b7c458187a1a567d92c27e 100644 (file)
@@ -6497,7 +6497,7 @@ static bool process_registry_globals(bool (*pfunc)(const char *, const char *))
 
        if (conf_ctx == NULL) {
                /* first time */
-               werr = smbconf_init_reg(NULL, &conf_ctx);
+               werr = smbconf_init_reg(NULL, &conf_ctx, NULL);
                if (!W_ERROR_IS_OK(werr)) {
                        goto done;
                }
@@ -6607,7 +6607,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);
+                       werr = smbconf_init_reg(NULL, &conf_ctx, NULL);
                        if (!W_ERROR_IS_OK(werr)) {
                                DEBUG(0, ("error opening configuration: %s\n",
                                          dos_errstr(werr)));
index cde3ab0a923b67994354b0739fd851b1f3b9ad17..d108fe14d26414b083a9b754ee3840a76de33885 100644 (file)
@@ -889,7 +889,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);
+       werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
 
        if (!W_ERROR_IS_OK(werr)) {
                return -1;