#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include <dlfcn.h>
#include <err.h>
+#include <sys/param.h>
#include <sys/queue.h>
#include <netinet/in.h>
/* modulespec is a string formatted as:
- "/path/to/module,options"
+ "modulename,options"
+
+ where modulename corresponds to a dlopen()able module in
+
+ $prefix/lib/smtpsink/ssm_modulename.so
parsing of "options" is module dependent
*/
+
+#define MODDIR "/usr/local/lib/smtpsink"
+
void
module_init(char *modulespec)
{
- char modpath[1024];
- char *file, *t;
+ char modpath[MAXPATHLEN];
+ char *moddir, *t;
struct smtpsink_module *mod;
void *dlmod;
t = strchr(modulespec, ',');
- if (!t) file = modulespec;
- else {
- if (t-modulespec - 1 > sizeof(modpath))
- errx(1, "module path too long: %s\n", modulespec);
- strncpy(modpath, modulespec, t - modulespec);
- modpath[t-modulespec] = 0;
- file = modpath;
- t++;
- }
+ if (t) *t++ = 0;
+
+ moddir = getenv("SMTPSINK_MODDIR");
+ if (!moddir) moddir = MODDIR;
+ snprintf(modpath, sizeof(modpath), "%s/ssm_%s.so", moddir, modulespec);
- dlmod = dlopen(file, RTLD_NOW);
+ dlmod = dlopen(modpath, RTLD_NOW);
if (!dlmod)
- errx(1, "could not load %s: %s\n", file, dlerror());
+ errx(1, "could not load %s: %s\n", modpath, dlerror());
mod = (void *)dlsym(dlmod, "ss_module");
if (!mod)
- errx(1, "module %s invalid: %s\n", file, dlerror());
+ errx(1, "module %s invalid: %s\n", modpath, dlerror());
mod->ssm_module_index = nmod;
if (mod->ssm_module_init) mod->ssm_module_init(t);