Code

SSL utils: Added init() and shutdown() functions for global setup/shutdown.
authorSebastian Harl <sh@tokkee.org>
Mon, 9 Feb 2015 17:43:39 +0000 (18:43 +0100)
committerSebastian Harl <sh@tokkee.org>
Mon, 9 Feb 2015 17:43:39 +0000 (18:43 +0100)
Use those functions in sysdb and sysdbd instead of calling the OpenSSL
functions directly.

src/include/utils/ssl.h
src/tools/sysdb/main.c
src/tools/sysdbd/main.c
src/utils/ssl.c

index 5379bc9ebf7f15af9b93844b9c78e6fc3c045a38..f15d3fab362cdbf3bc63ccf2a0d0ab776fc78c3c 100644 (file)
@@ -67,6 +67,16 @@ typedef struct sdb_ssl_server sdb_ssl_server_t;
 struct sdb_ssl_session;
 typedef struct sdb_ssl_session sdb_ssl_session_t;
 
+/*
+ * sdb_ssl_init, sdb_ssl_shutdown:
+ * Global setup and shutdown of SSL/TLS. This is required before any other
+ * function can be used.
+ */
+void
+sdb_ssl_init(void);
+void
+sdb_ssl_shutdown(void);
+
 /*
  * sdb_ssl_client_create:
  * Allocate and initialize a TLS/SSL client using the specified options. If no
index e9e2202635d1d89dcb238a6e6c18dd7b295695cb..c58c735675106da0ebc33afd94680cc7478dfc89 100644 (file)
@@ -38,6 +38,7 @@
 #include "utils/llist.h"
 #include "utils/strbuf.h"
 #include "utils/os.h"
+#include "utils/ssl.h"
 
 #include <errno.h>
 
@@ -77,9 +78,6 @@
 #      endif
 #endif /* READLINEs */
 
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-
 #ifndef DEFAULT_SOCKET
 #      define DEFAULT_SOCKET "unix:"LOCALSTATEDIR"/run/sysdbd.sock"
 #endif
@@ -299,8 +297,7 @@ main(int argc, char **argv)
        if (! input.user)
                exit(1);
 
-       SSL_load_error_strings();
-       OpenSSL_add_ssl_algorithms();
+       sdb_ssl_init();
 
        input.client = sdb_client_create(host);
        if (! input.client) {
@@ -372,8 +369,7 @@ main(int argc, char **argv)
        }
 
        sdb_input_reset(&input);
-
-       ERR_free_strings();
+       sdb_ssl_shutdown();
        return 0;
 } /* main */
 
index 25f6499feecc4817903a4ccf13105c43d81ad08c..179ec791ab97302fbac8fc422b3e0f3651678f85 100644 (file)
@@ -33,6 +33,7 @@
 #include "core/plugin.h"
 #include "core/store.h"
 #include "utils/error.h"
+#include "utils/ssl.h"
 
 #include "frontend/connection.h"
 #include "frontend/sock.h"
@@ -60,9 +61,6 @@
 
 #include <pthread.h>
 
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-
 #ifndef CONFIGFILE
 #      define CONFIGFILE SYSCONFDIR"/sysdb/sysdbd.conf"
 #endif
@@ -370,9 +368,7 @@ main(int argc, char **argv)
                if (daemonize())
                        exit(1);
 
-       SSL_load_error_strings();
-       OpenSSL_add_ssl_algorithms();
-
+       sdb_ssl_init();
        sdb_plugin_init_all();
        plugin_main_loop.default_interval = SECS_TO_SDB_TIME(60);
 
@@ -397,8 +393,7 @@ main(int argc, char **argv)
                        SDB_VERSION_EXTRA" (pid %i)", (int)getpid());
        sdb_plugin_shutdown_all();
        sdb_plugin_unregister_all();
-
-       ERR_free_strings();
+       sdb_ssl_shutdown();
        return status;
 } /* main */
 
index 723df2115600d404c3bf127c4d985e0fcc537203..fe509d05c3dd461e5e0d79620070abdeb5d97444 100644 (file)
@@ -171,6 +171,19 @@ copy_options(sdb_ssl_options_t *dst, const sdb_ssl_options_t *src)
  * public API
  */
 
+void
+sdb_ssl_init(void)
+{
+       SSL_load_error_strings();
+       OpenSSL_add_ssl_algorithms();
+} /* sdb_ssl_init */
+
+void
+sdb_ssl_shutdown(void)
+{
+       ERR_free_strings();
+} /* sdb_ssl_shutdown */
+
 sdb_ssl_client_t *
 sdb_ssl_client_create(const sdb_ssl_options_t *opts)
 {