1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-06-25 01:06:34 +08:00
|
|
|
#include "portable.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "slap.h"
|
|
|
|
|
|
|
|
#ifdef SLAPD_MODULES
|
|
|
|
|
1999-08-07 15:58:11 +08:00
|
|
|
#include <ltdl.h>
|
1999-06-25 01:06:34 +08:00
|
|
|
|
1999-09-28 17:54:00 +08:00
|
|
|
int module_load(const char* file_name, int argc, char *argv[])
|
|
|
|
{
|
1999-08-17 08:28:01 +08:00
|
|
|
lt_dlhandle* module = NULL;
|
1999-09-28 17:54:00 +08:00
|
|
|
const char *error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The result of lt_dlerror(), when called, must be cached prior
|
|
|
|
* to calling Debug. This is because Debug is a macro that expands
|
|
|
|
* into multiple function calls.
|
|
|
|
*/
|
|
|
|
|
1999-08-17 08:28:01 +08:00
|
|
|
int (*initialize) LDAP_P((int argc, char *argv[]));
|
1999-06-25 01:06:34 +08:00
|
|
|
|
1999-08-17 08:28:01 +08:00
|
|
|
if (lt_dlinit()) {
|
1999-09-28 17:54:00 +08:00
|
|
|
error = lt_dlerror();
|
|
|
|
Debug(LDAP_DEBUG_ANY, "lt_dlinit failed: %s\n", error, 0, 0);
|
1999-08-17 08:28:01 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((module = lt_dlopen(file_name)) == NULL) {
|
1999-09-28 17:54:00 +08:00
|
|
|
error = lt_dlerror();
|
1999-08-17 08:28:01 +08:00
|
|
|
Debug(LDAP_DEBUG_ANY, "lt_dlopen failed: (%s) %s\n", file_name,
|
1999-09-28 17:54:00 +08:00
|
|
|
error, 0);
|
1999-08-17 08:28:01 +08:00
|
|
|
return -1;
|
|
|
|
}
|
1999-06-25 01:06:34 +08:00
|
|
|
|
1999-08-17 08:28:01 +08:00
|
|
|
Debug(LDAP_DEBUG_CONFIG, "loaded module %s\n", file_name, 0, 0);
|
1999-06-25 01:06:34 +08:00
|
|
|
|
1999-08-17 08:28:01 +08:00
|
|
|
if ((initialize = lt_dlsym(module, "init_module")))
|
|
|
|
return initialize(argc, argv);
|
|
|
|
|
|
|
|
Debug(LDAP_DEBUG_CONFIG, "module %s: no init_module() function found\n",
|
|
|
|
file_name, 0, 0);
|
|
|
|
return -1;
|
1999-06-25 01:06:34 +08:00
|
|
|
}
|
|
|
|
|
1999-09-28 17:54:00 +08:00
|
|
|
int module_path(const char *path)
|
|
|
|
{
|
|
|
|
const char *error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The result of lt_dlerror(), when called, must be cached prior
|
|
|
|
* to calling Debug. This is because Debug is a macro that expands
|
|
|
|
* into multiple function calls.
|
|
|
|
*/
|
1999-08-17 09:30:09 +08:00
|
|
|
|
|
|
|
if (lt_dlinit()) {
|
1999-09-28 17:54:00 +08:00
|
|
|
error = lt_dlerror();
|
|
|
|
Debug(LDAP_DEBUG_ANY, "lt_dlinit failed: %s\n", error, 0, 0);
|
1999-08-17 09:30:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lt_dlsetsearchpath( path );
|
|
|
|
}
|
1999-06-25 01:06:34 +08:00
|
|
|
#endif /* SLAPD_MODULES */
|
|
|
|
|