]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-ssl-iostream: Use more standard _init() & _deinit() to initialize SSL plugin
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 16 Sep 2016 05:35:55 +0000 (08:35 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 16 Sep 2016 05:43:16 +0000 (08:43 +0300)
This is mainly to make it easier for test programs to link to the plugin
directly.

src/lib-ssl-iostream/iostream-openssl.c
src/lib-ssl-iostream/iostream-openssl.h
src/lib-ssl-iostream/iostream-ssl-private.h
src/lib-ssl-iostream/iostream-ssl.c

index 61dd34117d0d04c8fc771e7a6bb2d498e57d343a..89dc15079cc3450bf1766fe49fbdb691d9fb6da5 100644 (file)
@@ -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,
@@ -744,3 +742,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();
+}
index 78c4548a4e94d065306e23c9c4666b5244d987df..586f49754a31c35b2bca46adaf922a43851dc635 100644 (file)
@@ -95,4 +95,7 @@ const char *
 openssl_iostream_use_certificate_error(const char *cert, const char *set_name);
 void openssl_iostream_clear_errors(void);
 
+void iostream_openssl_init(void);
+void iostream_openssl_deinit(void);
+
 #endif
index 9be2bbd1e9979f0482ab1ce003cf85454d176ca6..7a997175a06e139d872ea81c0ccdcb1e1621ed9e 100644 (file)
@@ -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);
@@ -37,4 +36,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
index 77349b6c588fee6a3105d01dc41d1583b6182cc8..a02558b8e2c8f4883f875998c4bcad074c1be2a7 100644 (file)
@@ -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
@@ -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;
        }
@@ -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";