summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/conf/conf_sap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/conf/conf_sap.c')
-rw-r--r--src/lib/libcrypto/conf/conf_sap.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c
index a29acea7c1..f1844f69f4 100644
--- a/src/lib/libcrypto/conf/conf_sap.c
+++ b/src/lib/libcrypto/conf/conf_sap.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_sap.c,v 1.11 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: conf_sap.c,v 1.12 2018/03/17 16:20:01 beck Exp $ */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL 2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -56,6 +56,7 @@
56 * 56 *
57 */ 57 */
58 58
59#include <pthread.h>
59#include <stdio.h> 60#include <stdio.h>
60 61
61#include <openssl/opensslconf.h> 62#include <openssl/opensslconf.h>
@@ -75,23 +76,24 @@
75 * unless this is overridden by calling OPENSSL_no_config() 76 * unless this is overridden by calling OPENSSL_no_config()
76 */ 77 */
77 78
78static int openssl_configured = 0; 79static pthread_once_t openssl_configured = PTHREAD_ONCE_INIT;
79 80
80void 81static const char *openssl_config_name;
81OPENSSL_config(const char *config_name)
82{
83 if (openssl_configured)
84 return;
85 82
83void ENGINE_load_builtin_engines_internal(void);
84
85static void
86OPENSSL_config_internal(void)
87{
86 OPENSSL_load_builtin_modules(); 88 OPENSSL_load_builtin_modules();
87#ifndef OPENSSL_NO_ENGINE 89#ifndef OPENSSL_NO_ENGINE
88 /* Need to load ENGINEs */ 90 /* Need to load ENGINEs */
89 ENGINE_load_builtin_engines(); 91 ENGINE_load_builtin_engines_internal();
90#endif 92#endif
91 /* Add others here? */ 93 /* Add others here? */
92 94
93 ERR_clear_error(); 95 ERR_clear_error();
94 if (CONF_modules_load_file(NULL, config_name, 96 if (CONF_modules_load_file(NULL, openssl_config_name,
95 CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) { 97 CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
96 BIO *bio_err; 98 BIO *bio_err;
97 ERR_load_crypto_strings(); 99 ERR_load_crypto_strings();
@@ -107,7 +109,31 @@ OPENSSL_config(const char *config_name)
107} 109}
108 110
109void 111void
112OPENSSL_config(const char *config_name)
113{
114 /* Don't override if NULL */
115 /*
116 * Note - multiple threads calling this with *different* config names
117 * is probably not advisable. One thread will win, but you don't know
118 * if it will be the same thread as wins the pthread_once.
119 */
120 if (config_name != NULL)
121 openssl_config_name = config_name;
122
123 (void) OPENSSL_init_crypto(0, NULL);
124
125 (void) pthread_once(&openssl_configured, OPENSSL_config_internal);
126
127 return;
128}
129
130static void
131OPENSSL_no_config_internal(void)
132{
133}
134
135void
110OPENSSL_no_config(void) 136OPENSSL_no_config(void)
111{ 137{
112 openssl_configured = 1; 138 (void) pthread_once(&openssl_configured, OPENSSL_no_config_internal);
113} 139}