Add autogen.sh from distcc via mbp.
[kai/samba.git] / source / passdb / pdb_plugin.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Loadable passdb module interface.
4    Copyright (C) Jelmer Vernooij 2002
5    Copyright (C) Andrew Bartlett 2002
6       
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 #undef DBGC_CLASS
25 #define DBGC_CLASS DBGC_PASSDB
26
27 NTSTATUS pdb_init_plugin(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
28 {
29         void * dl_handle;
30         char *plugin_location, *plugin_name, *p;
31         pdb_init_function plugin_init;
32         int (*plugin_version)(void);
33
34         if (location == NULL) {
35                 DEBUG(0, ("The plugin module needs an argument!\n"));
36                 return NT_STATUS_UNSUCCESSFUL;
37         }
38
39         plugin_name = smb_xstrdup(location);
40         p = strchr(plugin_name, ':');
41         if (p) {
42                 *p = 0;
43                 plugin_location = p+1;
44                 trim_string(plugin_location, " ", " ");
45         } else plugin_location = NULL;
46         trim_string(plugin_name, " ", " ");
47
48         DEBUG(5, ("Trying to load sam plugin %s\n", plugin_name));
49         dl_handle = sys_dlopen(plugin_name, RTLD_NOW );
50         if (!dl_handle) {
51                 DEBUG(0, ("Failed to load sam plugin %s using sys_dlopen (%s)\n", plugin_name, sys_dlerror()));
52                 return NT_STATUS_UNSUCCESSFUL;
53         }
54     
55         plugin_version = sys_dlsym(dl_handle, "pdb_version");
56         if (!plugin_version) {
57                 sys_dlclose(dl_handle);
58                 DEBUG(0, ("Failed to find function 'pdb_version' using sys_dlsym in sam plugin %s (%s)\n", plugin_name, sys_dlerror()));            
59                 return NT_STATUS_UNSUCCESSFUL;
60         }
61
62         if (plugin_version() != PASSDB_INTERFACE_VERSION) {
63                 sys_dlclose(dl_handle);
64                 DEBUG(0, ("Wrong PASSDB_INTERFACE_VERSION! sam plugin has version %d and version %d is needed! Please update!\n",
65                             plugin_version(),PASSDB_INTERFACE_VERSION));
66                 return NT_STATUS_UNSUCCESSFUL;
67         }
68                                         
69         plugin_init = sys_dlsym(dl_handle, "pdb_init");
70         if (!plugin_init) {
71                 sys_dlclose(dl_handle);
72                 DEBUG(0, ("Failed to find function 'pdb_init' using sys_dlsym in sam plugin %s (%s)\n", plugin_name, sys_dlerror()));       
73                 return NT_STATUS_UNSUCCESSFUL;
74         }
75
76         DEBUG(5, ("Starting sam plugin %s with location %s\n", plugin_name, plugin_location));
77         return plugin_init(pdb_context, pdb_method, plugin_location);
78 }