2 Unix SMB/CIFS implementation.
3 Loadable san module interface.
4 Copyright (C) Jelmer Vernooij 2002
5 Copyright (C) Andrew Bartlett 2002
6 Copyright (C) Stefan (metze) Metzmacher 2002
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define DBGC_CLASS DBGC_SAM
28 NTSTATUS
sam_init_plugin(SAM_METHODS
*sam_methods
, const char *module_params
)
31 char *plugin_params
, *plugin_name
, *p
;
32 sam_init_function plugin_init
;
33 int (*plugin_version
)(void);
35 if (module_params
== NULL
) {
36 DEBUG(0, ("The plugin module needs an argument!\n"));
37 return NT_STATUS_UNSUCCESSFUL
;
40 plugin_name
= smb_xstrdup(module_params
);
41 p
= strchr(plugin_name
, ':');
45 trim_string(plugin_params
, " ", " ");
46 } else plugin_params
= NULL
;
47 trim_string(plugin_name
, " ", " ");
49 DEBUG(5, ("Trying to load sam plugin %s\n", plugin_name
));
50 dl_handle
= sys_dlopen(plugin_name
, RTLD_NOW
);
52 DEBUG(0, ("Failed to load sam plugin %s using sys_dlopen (%s)\n", plugin_name
, sys_dlerror()));
53 return NT_STATUS_UNSUCCESSFUL
;
56 plugin_version
= sys_dlsym(dl_handle
, "sam_version");
57 if (!plugin_version
) {
58 sys_dlclose(dl_handle
);
59 DEBUG(0, ("Failed to find function 'sam_version' using sys_dlsym in sam plugin %s (%s)\n", plugin_name
, sys_dlerror()));
60 return NT_STATUS_UNSUCCESSFUL
;
63 if (plugin_version()!=SAM_INTERFACE_VERSION
) {
64 sys_dlclose(dl_handle
);
65 DEBUG(0, ("Wrong SAM_INTERFACE_VERSION! sam plugin has version %d and version %d is needed! Please update!\n",
66 plugin_version(),SAM_INTERFACE_VERSION
));
67 return NT_STATUS_UNSUCCESSFUL
;
70 plugin_init
= sys_dlsym(dl_handle
, "sam_init");
72 sys_dlclose(dl_handle
);
73 DEBUG(0, ("Failed to find function 'sam_init' using sys_dlsym in sam plugin %s (%s)\n", plugin_name
, sys_dlerror()));
74 return NT_STATUS_UNSUCCESSFUL
;
77 DEBUG(5, ("Starting sam plugin %s with parameters %s for domain %s\n", plugin_name
, plugin_params
, sam_methods
->domain_name
));
78 return plugin_init(sam_methods
, plugin_params
);