lib/util: consolidate module loading into common code
[samba.git] / source4 / param / share.c
index 75b63cef73560e55d2b9a78f537c3a8fac0abf46..da0470d5606c5924bd2c34e95ce4e7ce60dd3eae 100644 (file)
@@ -1,13 +1,13 @@
 /* 
    Unix SMB/CIFS implementation.
    
-   Modular services configuration system
+   Modular shares configuration system
    
    Copyright (C) Simo Sorce    2006
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "param/share.h"
-#include "build.h"
+#include "param/param.h"
+#include "lib/util/samba_modules.h"
 
 const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
 {
@@ -34,7 +34,7 @@ int share_int_option(struct share_config *scfg, const char *opt_name, int defval
        return scfg->ctx->ops->int_option(scfg, opt_name, defval);
 }
 
-BOOL share_bool_option(struct share_config *scfg, const char *opt_name, BOOL defval)
+bool share_bool_option(struct share_config *scfg, const char *opt_name, bool defval)
 {
        return scfg->ctx->ops->bool_option(scfg, opt_name, defval);
 }
@@ -116,12 +116,7 @@ NTSTATUS share_register(const struct share_ops *ops)
                smb_panic("out of memory in share_register");
        }
 
-       backends[i] = malloc(sizeof(struct share_ops));
-       if (!backends[i]) {
-               smb_panic("out of memory in share_register");
-       }
-
-       backends[i] = smb_xmemdup(ops, sizeof(*ops));
+       backends[i] = (struct share_ops *)smb_xmemdup(ops, sizeof(*ops));
        backends[i]->name = smb_xstrdup(ops->name);
 
        backends[i + 1] = NULL;
@@ -131,24 +126,20 @@ NTSTATUS share_register(const struct share_ops *ops)
        return NT_STATUS_OK;
 }
 
-NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, 
-                                                                  const char *backend_name,
-                                                                  struct share_context **ctx)
+NTSTATUS share_get_context_by_name(TALLOC_CTX *mem_ctx, const char *backend_name,
+                                  struct tevent_context *event_ctx, 
+                                  struct loadparm_context *lp_ctx,
+                                  struct share_context **ctx)
 {
        const struct share_ops *ops;
 
        ops = share_backend_by_name(backend_name);
        if (!ops) {
-               DEBUG(0, ("share_init_connection: share backend [%s] not found!\n", lp_share_backend()));
+               DEBUG(0, ("share_init_connection: share backend [%s] not found!\n", backend_name));
                return NT_STATUS_INTERNAL_ERROR;
        }
 
-       return ops->init(mem_ctx, ops, ctx);
-}
-
-NTSTATUS share_get_context(TALLOC_CTX *mem_ctx, struct share_context **ctx)
-{
-       return share_get_context_by_name(mem_ctx, lp_share_backend(), ctx);
+       return ops->init(mem_ctx, ops, event_ctx, lp_ctx, ctx);
 }
 
 /*
@@ -156,13 +147,11 @@ NTSTATUS share_get_context(TALLOC_CTX *mem_ctx, struct share_context **ctx)
 */
 NTSTATUS share_init(void)
 {
-       init_module_fn static_init[] = STATIC_share_MODULES;
-       init_module_fn *shared_init = load_samba_modules(NULL, "share");
+#define _MODULE_PROTO(init) extern NTSTATUS init(void);
+       STATIC_share_MODULES_PROTO;
+       init_module_fn static_init[] = { STATIC_share_MODULES };
 
        run_init_functions(static_init);
-       run_init_functions(shared_init);
-
-       talloc_free(shared_init);
 
        return NT_STATUS_OK;
 }