]> git.sur5r.net Git - openldap/blob - servers/slapd/module.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[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     lt_dlhandle* module = NULL;
12     int (*initialize) LDAP_P((int argc, char *argv[]));
13
14     if (lt_dlinit()) {
15         Debug(LDAP_DEBUG_ANY, "lt_dlinit failed: %s\n", lt_dlerror(), 0, 0);
16         return -1;
17     }
18
19     if ((module = lt_dlopen(file_name)) == NULL) {
20         Debug(LDAP_DEBUG_ANY, "lt_dlopen failed: (%s) %s\n", file_name,
21             lt_dlerror(), 0);
22         return -1;
23     }
24
25     Debug(LDAP_DEBUG_CONFIG, "loaded module %s\n", file_name, 0, 0);
26    
27     if ((initialize = lt_dlsym(module, "init_module")))
28         return initialize(argc, argv);
29
30     Debug(LDAP_DEBUG_CONFIG, "module %s: no init_module() function found\n",
31         file_name, 0, 0);
32     return -1;
33 }
34
35 int module_path(const char *path) {
36
37     if (lt_dlinit()) {
38         Debug(LDAP_DEBUG_ANY, "lt_dlinit failed: %s\n", lt_dlerror(), 0, 0);
39         return -1;
40     }
41
42     return lt_dlsetsearchpath( path );
43 }
44 #endif /* SLAPD_MODULES */
45