Beispiel #1
0
static void *get_symbol(struct module *module, const char *symbol, bool quiet)
{
	if (quiet)
		return module_get_symbol_quiet(module, symbol);

	return module_get_symbol(module, symbol);
}
Beispiel #2
0
static int ssl_module_load(const char **error_r)
{
#ifdef HAVE_SSL
	const char *plugin_name = "ssl_iostream_openssl";
	struct module_dir_load_settings mod_set;

	memset(&mod_set, 0, sizeof(mod_set));
	mod_set.abi_version = DOVECOT_ABI_VERSION;
	mod_set.setting_name = "<built-in lib-ssl-iostream lookup>";
	ssl_module = module_dir_load(MODULE_DIR, plugin_name, &mod_set);

	ssl_vfuncs = module_get_symbol(ssl_module, "ssl_vfuncs");
	if (ssl_vfuncs == NULL) {
		*error_r = t_strdup_printf("%s: Broken plugin: "
			"ssl_vfuncs symbol not found", plugin_name);
		module_dir_unload(&ssl_module);
		return -1;
	}

	/* Destroy SSL module after (most of) the others. Especially lib-fs
	   backends may still want to access SSL module in their own
	   atexit-callbacks. */
	lib_atexit_priority(ssl_module_unload, LIB_ATEXIT_PRIORITY_LOW);
	ssl_module_loaded = TRUE;
	return 0;
#else
	*error_r = "SSL support not compiled in";
	return -1;
#endif
}
void sieve_plugins_unload(struct sieve_instance *svinst)
{
	struct sieve_plugin *plugin;

	if ( svinst->plugins == NULL )
		return;

	/* Call plugin unload functions for this instance */

	plugin = svinst->plugins;
	while ( plugin != NULL ) {
		struct module *module = plugin->module;
		sieve_plugin_unload_func_t unload_func;

		unload_func = (sieve_plugin_unload_func_t)module_get_symbol
			(module, t_strdup_printf("%s_unload", module->name));
		if ( unload_func != NULL ) {
			unload_func(svinst, plugin->context);
		}

		plugin = plugin->next;
	}

	/* Physically unload modules */

	i_assert(sieve_modules_refcount > 0);

	if ( --sieve_modules_refcount != 0 )
		return;

	module_dir_unload(&sieve_modules);
}
Beispiel #4
0
static int ssl_module_load(const char **error_r)
{
#ifdef HAVE_SSL
	const char *plugin_name = "ssl_iostream_openssl";
	struct module_dir_load_settings mod_set;

	memset(&mod_set, 0, sizeof(mod_set));
	mod_set.abi_version = DOVECOT_ABI_VERSION;
	mod_set.setting_name = "<built-in lib-ssl-iostream lookup>";
	ssl_module = module_dir_load(MODULE_DIR, plugin_name, &mod_set);

	ssl_vfuncs = module_get_symbol(ssl_module, "ssl_vfuncs");
	if (ssl_vfuncs == NULL) {
		*error_r = t_strdup_printf("%s: Broken plugin: "
			"ssl_vfuncs symbol not found", plugin_name);
		module_dir_unload(&ssl_module);
		return -1;
	}

	atexit(ssl_module_unload);
	ssl_module_loaded = TRUE;
	return 0;
#else
	*error_r = "SSL support not compiled in";
	return -1;
#endif
}
Beispiel #5
0
static void userdb_nss_deinit(struct userdb_module *_module)
{
	struct nss_userdb_module *module = (struct nss_userdb_module *)_module;
	void (*mod_endpwent)(void);
	const char *symbol;

	symbol = t_strdup_printf("_nss_%s_endpwent", module->nss_module.name);
	mod_endpwent = module_get_symbol(&module->nss_module, symbol);
	if (mod_endpwent != NULL)
		mod_endpwent();
}
Beispiel #6
0
static void
userdb_nss_load_module(struct nss_userdb_module *module, pool_t pool)
{
	const char *name = module->nss_module.name;
	char *path;

	path = p_strdup_printf(pool, "/usr/lib/libnss_%s.so", name);
	module->nss_module.handle = dlopen(path, RTLD_GLOBAL | RTLD_NOW);
	if (module->nss_module.handle == NULL)
		i_fatal("dlopen(%s) failed: %s", path, dlerror());
	module->nss_module.path = path;

	module->getpwnam_r =
		module_get_symbol(&module->nss_module,
				  t_strdup_printf("_nss_%s_getpwnam_r", name));
	if (module->getpwnam_r == NULL)
		i_fatal("userdb nss: Module %s missing getpwnam_r()", path);
}
void sieve_plugins_load
(struct sieve_instance *svinst, const char *path, const char *plugins)
{
	struct module *module;
	struct module_dir_load_settings mod_set;
	const char **module_names;
	unsigned int i;

	/* Determine what to load */

	if ( path == NULL && plugins == NULL ) {
		path = sieve_setting_get(svinst, "sieve_plugin_dir");
		plugins = sieve_setting_get(svinst, "sieve_plugins");
	}

	if ( plugins == NULL || *plugins == '\0' )
		return;

	if ( path == NULL || *path == '\0' )
		path = MODULEDIR"/sieve";

	memset(&mod_set, 0, sizeof(mod_set));
	mod_set.abi_version = PIGEONHOLE_ABI_VERSION;
	mod_set.require_init_funcs = TRUE;
	mod_set.debug = FALSE;

	/* Load missing plugin modules */

	sieve_modules = module_dir_load_missing
		(sieve_modules, path, plugins, &mod_set);

	/* Call plugin load functions for this Sieve instance */

	if ( svinst->plugins == NULL ) {
		sieve_modules_refcount++;
	}

	module_names = t_strsplit_spaces(plugins, ", ");

	for (i = 0; module_names[i] != NULL; i++) {
		/* Allow giving the module names also in non-base form. */
		module_names[i] = module_file_get_name(module_names[i]);
	}

 	for (i = 0; module_names[i] != NULL; i++) {
		struct sieve_plugin *plugin;
		const char *name = module_names[i];
		sieve_plugin_load_func_t load_func;

		/* Find the module */
		module = sieve_plugin_module_find(name);
		i_assert(module != NULL);

		/* Check whether the plugin is already loaded in this instance */
		plugin = svinst->plugins;
		while ( plugin != NULL ) {
			if ( plugin->module == module )
				break;
			plugin = plugin->next;
		}

		/* Skip it if it is loaded already */
		if ( plugin != NULL )
			continue;

		/* Create plugin list item */
		plugin = p_new(svinst->pool, struct sieve_plugin, 1);
		plugin->module = module;

		/* Call load function */
		load_func = (sieve_plugin_load_func_t) module_get_symbol
			(module, t_strdup_printf("%s_load", module->name));
		if ( load_func != NULL ) {
			load_func(svinst, &plugin->context);
		}

		/* Add plugin to the instance */
		if ( svinst->plugins == NULL )
			svinst->plugins = plugin;
		else {
			struct sieve_plugin *plugin_last;

			plugin_last = svinst->plugins;
			while ( plugin_last->next != NULL )
				plugin_last = plugin_last->next;

			plugin_last->next = plugin;
		}
	}
}