]> git.sur5r.net Git - openldap/blob - servers/slapd/module.c
37884f254b88fc77ac7030087e9eb03bdff507fe
[openldap] / servers / slapd / module.c
1 /* $OpenLDAP$ */
2 #include "portable.h"
3 #include <stdio.h>
4 #include "slap.h"
5
6 #ifdef SLAPD_MODULES
7
8 #include <ltdl.h>
9
10 int module_load(const char* file_name, int argc, char *argv[])
11 {
12     lt_dlhandle* module = NULL;
13     const char *error;
14
15     /*
16      * The result of lt_dlerror(), when called, must be cached prior
17      * to calling Debug. This is because Debug is a macro that expands
18      * into multiple function calls.
19      */
20
21     int (*initialize) LDAP_P((int argc, char *argv[]));
22
23     if (lt_dlinit()) {
24         error = lt_dlerror();
25         Debug(LDAP_DEBUG_ANY, "lt_dlinit failed: %s\n", error, 0, 0);
26         return -1;
27     }
28
29     if ((module = lt_dlopen(file_name)) == NULL) {
30         error = lt_dlerror();
31         Debug(LDAP_DEBUG_ANY, "lt_dlopen failed: (%s) %s\n", file_name,
32             error, 0);
33         return -1;
34     }
35
36     Debug(LDAP_DEBUG_CONFIG, "loaded module %s\n", file_name, 0, 0);
37    
38     if ((initialize = lt_dlsym(module, "init_module")))
39         return initialize(argc, argv);
40
41     Debug(LDAP_DEBUG_CONFIG, "module %s: no init_module() function found\n",
42         file_name, 0, 0);
43     return -1;
44 }
45
46 int module_path(const char *path)
47 {
48     const char *error;
49
50     /*
51      * The result of lt_dlerror(), when called, must be cached prior
52      * to calling Debug. This is because Debug is a macro that expands
53      * into multiple function calls.
54      */
55
56     if (lt_dlinit()) {
57         error = lt_dlerror();
58         Debug(LDAP_DEBUG_ANY, "lt_dlinit failed: %s\n", error, 0, 0);
59         return -1;
60     }
61
62     return lt_dlsetsearchpath( path );
63 }
64 #endif /* SLAPD_MODULES */
65