]> git.sur5r.net Git - openldap/blob - servers/slapd/module.c
3768f38b7cf52aab7f04efc1a9b3144e8ea1909f
[openldap] / servers / slapd / module.c
1 #include "portable.h"
2 #include <stdio.h>
3 #include "slap.h"
4
5 #ifdef SLAPD_MODULES
6
7 #include <ltdl.h>
8
9 int module_load(const char* file_name, int argc, char *argv[]) {
10     lt_dlhandle* module = NULL;
11     int (*initialize) LDAP_P((int argc, char *argv[]));
12
13     if (lt_dlinit()) {
14         Debug(LDAP_DEBUG_ANY, "lt_dlinit failed: %s\n", lt_dlerror(), 0, 0);
15         return -1;
16     }
17
18     if ((module = lt_dlopen(file_name)) == NULL) {
19         Debug(LDAP_DEBUG_ANY, "lt_dlopen failed: (%s) %s\n", file_name,
20             lt_dlerror(), 0);
21         return -1;
22     }
23
24     Debug(LDAP_DEBUG_CONFIG, "loaded module %s\n", file_name, 0, 0);
25    
26     if ((initialize = lt_dlsym(module, "init_module")))
27         return initialize(argc, argv);
28
29     Debug(LDAP_DEBUG_CONFIG, "module %s: no init_module() function found\n",
30         file_name, 0, 0);
31     return -1;
32 }
33
34 int module_path(const char *path) {
35
36     if (lt_dlinit()) {
37         Debug(LDAP_DEBUG_ANY, "lt_dlinit failed: %s\n", lt_dlerror(), 0, 0);
38         return -1;
39     }
40
41     return lt_dlsetsearchpath( path );
42 }
43 #endif /* SLAPD_MODULES */
44