Split smbldap in a core file and a utility file
[tprouty/samba.git] / source / param / modconf.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Configuration Modules Support
4    Copyright (C) Simo Sorce 2003
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/
19
20 #include "includes.h"
21
22 #undef DBGC_CLASS
23 #define DBGC_CLASS DBGC_IDMAP
24
25 struct modconf_struct {
26         char *name;
27         struct config_functions *fns;
28 };
29
30 static struct modconf_struct module;
31
32 NTSTATUS smb_register_config(int version, const char *name, struct config_functions *fns)
33 {
34         if ((version != SAMBA_CONFIG_INTERFACE_VERSION)) {
35                 DEBUG(0, ("smb_register_config: Failed to register config module.\n"
36                           "The module has been compiled with a different interface version (%d).\n"
37                           "The supported version is: %d\n",
38                           version, SAMBA_CONFIG_INTERFACE_VERSION));
39                 return NT_STATUS_OBJECT_TYPE_MISMATCH;
40         }
41
42         if (!name || !name[0]) {
43                 DEBUG(0,("smb_register_config: Name missing!\n"));
44                 return NT_STATUS_INVALID_PARAMETER;
45         }
46
47         module.name = smb_xstrdup(name);
48         module.fns = fns;
49         DEBUG(5, ("smb_register_config: Successfully registeres config backend '%s'\n", name));
50         return NT_STATUS_OK;
51 }
52
53 /**********************************************************************
54  * Init the configuration module
55  *********************************************************************/
56
57 BOOL modconf_init(const char *config_backend)
58 {
59         NTSTATUS ret;
60         BOOL bret = False;
61         char *name;
62         char *params;
63
64         /* nothing to do */
65         if (!config_backend)
66                 return True;
67
68         name = smb_xstrdup(config_backend);
69         if ((params = strchr(name, ':')) != NULL ) {
70                 *params = '\0';
71                 params++;
72         }
73
74         ret = smb_probe_module("config", name);
75         
76         if (NT_STATUS_IS_OK(ret) && NT_STATUS_IS_OK(module.fns->init(params)))
77                 bret = True;
78
79         SAFE_FREE(name);
80         return bret;
81 }
82
83 BOOL modconf_load(BOOL (*sfunc)(const char *),BOOL (*pfunc)(const char *, const char *))
84 {
85         if (module.fns) {
86                 if (NT_STATUS_IS_OK(module.fns->load(sfunc, pfunc))) {
87                         return True;
88                 }
89         }
90         return False;
91 }
92
93 NTSTATUS modconf_close(void)
94 {
95         return module.fns->close();
96 }