Skip to content

Commit

Permalink
lib-ssl-iostream: Use more standard _init() & _deinit() to initialize…
Browse files Browse the repository at this point in the history
… SSL plugin

This is mainly to make it easier for test programs to link to the plugin
directly.
  • Loading branch information
sirainen committed Oct 13, 2016
1 parent 41f4efe commit a8fce6a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
14 changes: 11 additions & 3 deletions src/lib-ssl-iostream/iostream-openssl.c
Expand Up @@ -719,9 +719,7 @@ openssl_iostream_get_last_error(struct ssl_iostream *ssl_io)
return ssl_io->last_error;
}

const struct iostream_ssl_vfuncs ssl_vfuncs = {
openssl_iostream_global_deinit,

static const struct iostream_ssl_vfuncs ssl_vfuncs = {
openssl_iostream_context_init_client,
openssl_iostream_context_init_server,
openssl_iostream_context_deinit,
Expand All @@ -747,3 +745,13 @@ const struct iostream_ssl_vfuncs ssl_vfuncs = {
openssl_iostream_get_security_string,
openssl_iostream_get_last_error
};

void iostream_openssl_init(void)
{
iostream_ssl_module_init(&ssl_vfuncs);
}

void iostream_openssl_deinit(void)
{
openssl_iostream_global_deinit();
}
3 changes: 3 additions & 0 deletions src/lib-ssl-iostream/iostream-openssl.h
Expand Up @@ -101,4 +101,7 @@ int openssl_iostream_context_import_params(struct ssl_iostream_context *ctx,
const buffer_t *input);
void openssl_iostream_context_free_params(struct ssl_iostream_context *ctx);

void iostream_openssl_init(void);
void iostream_openssl_deinit(void);

#endif
3 changes: 2 additions & 1 deletion src/lib-ssl-iostream/iostream-ssl-private.h
Expand Up @@ -4,7 +4,6 @@
#include "iostream-ssl.h"

struct iostream_ssl_vfuncs {
void (*global_deinit)(void);
int (*context_init_client)(const struct ssl_iostream_settings *set,
struct ssl_iostream_context **ctx_r,
const char **error_r);
Expand Down Expand Up @@ -42,4 +41,6 @@ struct iostream_ssl_vfuncs {
const char *(*get_last_error)(struct ssl_iostream *ssl_io);
};

void iostream_ssl_module_init(const struct iostream_ssl_vfuncs *vfuncs);

#endif
22 changes: 14 additions & 8 deletions src/lib-ssl-iostream/iostream-ssl.c
Expand Up @@ -14,12 +14,16 @@ static const struct iostream_ssl_vfuncs *ssl_vfuncs = NULL;
#ifdef HAVE_SSL
static void ssl_module_unload(void)
{
module_dir_deinit(ssl_module);
ssl_vfuncs->global_deinit();
module_dir_unload(&ssl_module);
}
#endif

void iostream_ssl_module_init(const struct iostream_ssl_vfuncs *vfuncs)
{
ssl_vfuncs = vfuncs;
ssl_module_loaded = TRUE;
}

static int ssl_module_load(const char **error_r)
{
#ifdef HAVE_SSL
Expand All @@ -29,12 +33,15 @@ static int ssl_module_load(const char **error_r)
memset(&mod_set, 0, sizeof(mod_set));
mod_set.abi_version = DOVECOT_ABI_VERSION;
mod_set.setting_name = "<built-in lib-ssl-iostream lookup>";
mod_set.require_init_funcs = TRUE;
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);
if (module_dir_try_load_missing(&ssl_module, MODULE_DIR, plugin_name,
&mod_set, error_r) < 0)
return -1;
if (!ssl_module_loaded) {
*error_r = t_strdup_printf(
"%s didn't call iostream_ssl_module_init() - SSL not initialized",
plugin_name);
module_dir_unload(&ssl_module);
return -1;
}
Expand All @@ -43,7 +50,6 @@ static int ssl_module_load(const char **error_r)
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";
Expand Down

0 comments on commit a8fce6a

Please sign in to comment.