2 Unix SMB/CIFS implementation.
3 Grops and Users Management System initializations.
4 Copyright (C) Simo Sorce 2002
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.
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.
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.
24 #define DBGC_CLASS DBGC_SAM
29 static GUMS_FUNCTIONS
*gums_backend
= NULL
;
31 static struct gums_init_function_entry
*backends
= NULL
;
33 static void lazy_initialize_gums(void)
35 static BOOL initialized
= False
;
44 static struct gums_init_function_entry
*gums_find_backend_entry(const char *name
);
46 NTSTATUS
gums_register_module(int version
, const char *name
, gums_init_function init_fn
)
48 struct gums_init_function_entry
*entry
= backends
;
50 if (version
!= GUMS_INTERFACE_VERSION
) {
51 DEBUG(0,("Can't register gums backend!\n"
52 "You tried to register a gums module with"
53 "GUMS_INTERFACE_VERSION %d, while this version"
54 "of samba uses version %d\n", version
,
55 GUMS_INTERFACE_VERSION
));
57 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
60 if (!name
|| !init_fn
) {
61 return NT_STATUS_INVALID_PARAMETER
;
64 DEBUG(5,("Attempting to register gums backend %s\n", name
));
66 /* Check for duplicates */
67 if (gums_find_backend_entry(name
)) {
68 DEBUG(0,("There already is a gums backend registered"
69 "with the name %s!\n", name
));
70 return NT_STATUS_OBJECT_NAME_COLLISION
;
73 entry
= smb_xmalloc(sizeof(struct gums_init_function_entry
));
74 entry
->name
= smb_xstrdup(name
);
75 entry
->init_fn
= init_fn
;
77 DLIST_ADD(backends
, entry
);
78 DEBUG(5,("Successfully added gums backend '%s'\n", name
));
82 static struct gums_init_function_entry
*gums_find_backend_entry(const char *name
)
84 struct gums_init_function_entry
*entry
= backends
;
87 if (strcmp(entry
->name
, name
) == 0)
95 NTSTATUS
gums_setup_backend(const char *backend
)
99 char *module_name
= smb_xstrdup(backend
);
100 char *p
, *module_data
= NULL
;
101 struct gums_init_function_entry
*entry
;
102 NTSTATUS ret
= NT_STATUS_UNSUCCESSFUL
;
104 lazy_initialize_gums();
106 p
= strchr(module_name
, ':');
110 trim_string(module_data
, " ", " ");
113 trim_string(module_name
, " ", " ");
115 DEBUG(5,("Attempting to find a gums backend to match %s (%s)\n", backend
, module_name
));
117 entry
= gums_find_backend_entry(module_name
);
119 /* Try to find a module that contains this module */
121 DEBUG(2,("No builtin backend found, trying to load plugin\n"));
122 if(NT_STATUS_IS_OK(smb_probe_module("gums", module_name
)) && !(entry
= gums_find_backend_entry(module_name
))) {
123 DEBUG(0,("Plugin is available, but doesn't register gums backend %s\n", module_name
));
124 SAFE_FREE(module_name
);
125 return NT_STATUS_UNSUCCESSFUL
;
129 /* No such backend found */
131 DEBUG(0,("No builtin nor plugin backend for %s found\n", module_name
));
132 SAFE_FREE(module_name
);
133 return NT_STATUS_INVALID_PARAMETER
;
136 DEBUG(5,("Found gums backend %s\n", module_name
));
138 /* free current functions structure if any */
140 gums_backend
->free_private_data(gums_backend
->private_data
);
141 talloc_destroy(gums_backend
->mem_ctx
);
145 /* allocate a new GUMS_FUNCTIONS structure and memory context */
146 mem_ctx
= talloc_init("gums_backend (%s)", module_name
);
148 return NT_STATUS_NO_MEMORY
;
149 gums_backend
= talloc(mem_ctx
, sizeof(GUMS_FUNCTIONS
));
151 return NT_STATUS_NO_MEMORY
;
152 gums_backend
->mem_ctx
= mem_ctx
;
154 /* init the requested backend module */
155 if (NT_STATUS_IS_OK(ret
= entry
->init_fn(gums_backend
, module_data
))) {
156 DEBUG(5,("gums backend %s has a valid init\n", backend
));
158 DEBUG(0,("gums backend %s did not correctly init (error was %s)\n", backend
, nt_errstr(ret
)));
160 SAFE_FREE(module_name
);
164 NTSTATUS
get_gums_fns(GUMS_FUNCTIONS
**fns
)
166 if (gums_backend
!= NULL
) {
171 DEBUG(2, ("get_gums_fns: unable to get gums functions! backend uninitialized?\n"));
172 return NT_STATUS_UNSUCCESSFUL
;