session CHANGE init/destroy functions unified
What exactly to init and destroy is now
determined internally for the user.
diff --git a/src/session.c b/src/session.c
index 28a61c4..49f0591 100644
--- a/src/session.c
+++ b/src/session.c
@@ -877,7 +877,7 @@
#ifdef NC_ENABLED_SSH
-API void
+static void
nc_ssh_init(void)
{
ssh_threads_set_callbacks(ssh_threads_get_pthread());
@@ -885,9 +885,10 @@
ssh_set_log_level(verbose_level);
}
-API void
+static void
nc_ssh_destroy(void)
{
+ FIPS_mode_set(0);
ENGINE_cleanup();
CONF_modules_unload(1);
nc_thread_destroy();
@@ -898,28 +899,10 @@
#ifdef NC_ENABLED_TLS
-static pthread_mutex_t *tls_locks;
-
struct CRYPTO_dynlock_value {
pthread_mutex_t lock;
};
-static void
-tls_thread_locking_func(int mode, int n, const char *UNUSED(file), int UNUSED(line))
-{
- if (mode & CRYPTO_LOCK) {
- pthread_mutex_lock(tls_locks + n);
- } else {
- pthread_mutex_unlock(tls_locks + n);
- }
-}
-
-static void
-tls_thread_id_func(CRYPTO_THREADID *tid)
-{
- CRYPTO_THREADID_set_numeric(tid, (unsigned long)pthread_self());
-}
-
static struct CRYPTO_dynlock_value *
tls_dyn_create_func(const char *UNUSED(file), int UNUSED(line))
{
@@ -954,7 +937,29 @@
free(l);
}
-API void
+#endif /* NC_ENABLED_TLS */
+
+#if defined(NC_ENABLED_TLS) && !defined(NC_ENABLED_SSH)
+
+static pthread_mutex_t *tls_locks;
+
+static void
+tls_thread_locking_func(int mode, int n, const char *UNUSED(file), int UNUSED(line))
+{
+ if (mode & CRYPTO_LOCK) {
+ pthread_mutex_lock(tls_locks + n);
+ } else {
+ pthread_mutex_unlock(tls_locks + n);
+ }
+}
+
+static void
+tls_thread_id_func(CRYPTO_THREADID *tid)
+{
+ CRYPTO_THREADID_set_numeric(tid, (unsigned long)pthread_self());
+}
+
+static void
nc_tls_init(void)
{
int i;
@@ -976,11 +981,12 @@
CRYPTO_set_dynlock_destroy_callback(tls_dyn_destroy_func);
}
-API void
+static void
nc_tls_destroy(void)
{
int i;
+ FIPS_mode_set(0);
CRYPTO_cleanup_all_ex_data();
nc_thread_destroy();
EVP_cleanup();
@@ -999,26 +1005,11 @@
CRYPTO_set_dynlock_destroy_callback(NULL);
}
-#endif /* NC_ENABLED_TLS */
-
-#if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS)
-
-API void
-nc_thread_destroy(void) {
- CRYPTO_THREADID crypto_tid;
-
- /* caused data-races and seems not neccessary for avoiding valgrind reachable memory */
- //CRYPTO_cleanup_all_ex_data();
-
- CRYPTO_THREADID_current(&crypto_tid);
- ERR_remove_thread_state(&crypto_tid);
-}
-
-#endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */
+#endif /* NC_ENABLED_TLS && !NC_ENABLED_SSH */
#if defined(NC_ENABLED_SSH) && defined(NC_ENABLED_TLS)
-API void
+static void
nc_ssh_tls_init(void)
{
SSL_load_error_strings();
@@ -1032,7 +1023,7 @@
CRYPTO_set_dynlock_destroy_callback(tls_dyn_destroy_func);
}
-API void
+static void
nc_ssh_tls_destroy(void)
{
ERR_free_strings();
@@ -1046,3 +1037,43 @@
}
#endif /* NC_ENABLED_SSH && NC_ENABLED_TLS */
+
+#if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS)
+
+API void
+nc_thread_destroy(void)
+{
+ CRYPTO_THREADID crypto_tid;
+
+ /* caused data-races and seems not neccessary for avoiding valgrind reachable memory */
+ //CRYPTO_cleanup_all_ex_data();
+
+ CRYPTO_THREADID_current(&crypto_tid);
+ ERR_remove_thread_state(&crypto_tid);
+}
+
+API void
+nc_init(void)
+{
+#if defined(NC_ENABLED_SSH) && defined(NC_ENABLED_TLS)
+ nc_ssh_tls_init();
+#elif defined(NC_ENABLED_SSH)
+ nc_ssh_init();
+#elif defined(NC_ENABLED_TLS)
+ nc_tls_init();
+#endif
+}
+
+API void
+nc_destroy(void)
+{
+#if defined(NC_ENABLED_SSH) && defined(NC_ENABLED_TLS)
+ nc_ssh_tls_destroy();
+#elif defined(NC_ENABLED_SSH)
+ nc_ssh_destroy();
+#elif defined(NC_ENABLED_TLS)
+ nc_tls_destroy();
+#endif
+}
+
+#endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */