void *arg);
int cbtls_verify(int ok, X509_STORE_CTX *ctx);
+/* threads.c */
+int tls_mutexes_init(void);
+
/* TLS */
-void tls_global_init(void);
+int tls_global_init(bool spawn_flag, bool check);
#ifdef ENABLE_OPENSSL_VERSION_CHECK
int tls_global_version_check(char const *acknowledged);
#endif
* Initialising OpenSSL once, here, is safer than having individual modules do it.
*/
#ifdef HAVE_OPENSSL_CRYPTO_H
- tls_global_init();
+ if (tls_global_init(spawn_flag, check_config) < 0) exit(EXIT_FAILURE);
#endif
/*
}
#endif
-static int setup_ssl_mutexes(void)
+/*
+ * Create the TLS mutexes.
+ */
+int tls_mutexes_init(void)
{
int i;
ssl_mutexes = rad_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
if (!ssl_mutexes) {
ERROR("Error allocating memory for SSL mutexes!");
- return 0;
+ return -1;
}
for (i = 0; i < CRYPTO_num_locks(); i++) {
CRYPTO_set_locking_callback(ssl_locking_function);
#endif
- return 1;
+ return 0;
}
#endif
}
#endif
-#ifdef HAVE_OPENSSL_CRYPTO_H
- /*
- * If we're linking with OpenSSL too, then we need
- * to set up the mutexes and enable the thread callbacks.
- */
- if (!setup_ssl_mutexes()) {
- ERROR("FATAL: Failed to set up SSL mutexes");
- return -1;
- }
-#endif
-
-
#ifndef WITH_GCD
/*
* Create a number of waiting threads.
* This should be called exactly once from main, before reading the main config
* or initialising any modules.
*/
-void tls_global_init(void)
+int tls_global_init(bool spawn_flag, bool check)
{
SSL_load_error_strings(); /* readable error messages (examples show call before library_init) */
SSL_library_init(); /* initialize library */
* Initialize the index for the certificates.
*/
fr_tls_ex_index_certs = SSL_SESSION_get_ex_new_index(0, NULL, NULL, NULL, sess_free_certs);
+
+ /*
+ * If we're linking with OpenSSL too, then we need
+ * to set up the mutexes and enable the thread callbacks.
+ *
+ * 'check' and not 'check_config' because it's a global,
+ * and we don't want to have tls.c depend on globals.
+ */
+ if (spawn_flag && !check && (tls_mutexes_init() < 0)) {
+ ERROR("FATAL: Failed to set up SSL mutexes");
+ return -1;
+ }
+
+ return 0;
}
#ifdef ENABLE_OPENSSL_VERSION_CHECK
* Initialising OpenSSL once, here, is safer than having individual modules do it.
*/
#ifdef HAVE_OPENSSL_CRYPTO_H
- tls_global_init();
+ tls_global_init(false, false);
#endif
if (xlat_register("poke", xlat_poke, NULL, NULL) < 0) {