diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libtls/man/tls_init.3 | 6 | ||||
| -rw-r--r-- | src/lib/libtls/tls.c | 32 |
2 files changed, 23 insertions, 15 deletions
diff --git a/src/lib/libtls/man/tls_init.3 b/src/lib/libtls/man/tls_init.3 index 5fb9cdd802..dfafa612c1 100644 --- a/src/lib/libtls/man/tls_init.3 +++ b/src/lib/libtls/man/tls_init.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: tls_init.3,v 1.9 2018/03/07 19:07:14 deraadt Exp $ | 1 | .\" $OpenBSD: tls_init.3,v 1.10 2018/03/08 16:12:00 beck Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 3 | .\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
| 4 | .\" Copyright (c) 2016 Joel Sing <jsing@openbsd.org> | 4 | .\" Copyright (c) 2016 Joel Sing <jsing@openbsd.org> |
| @@ -16,7 +16,7 @@ | |||
| 16 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 16 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 17 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 17 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 18 | .\" | 18 | .\" |
| 19 | .Dd $Mdocdate: March 7 2018 $ | 19 | .Dd $Mdocdate: March 8 2018 $ |
| 20 | .Dt TLS_INIT 3 | 20 | .Dt TLS_INIT 3 |
| 21 | .Os | 21 | .Os |
| 22 | .Sh NAME | 22 | .Sh NAME |
| @@ -46,7 +46,7 @@ The | |||
| 46 | .Fn tls_init | 46 | .Fn tls_init |
| 47 | function initializes global data structures. | 47 | function initializes global data structures. |
| 48 | It should be called once before any other functions. | 48 | It should be called once before any other functions. |
| 49 | It may be called more than once, but not concurrently. | 49 | It may be called more than once, and may be called concurrently. |
| 50 | .Pp | 50 | .Pp |
| 51 | Before a connection is created, a configuration must be created. | 51 | Before a connection is created, a configuration must be created. |
| 52 | The | 52 | The |
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c index c0430d7cd1..e7a485bcec 100644 --- a/src/lib/libtls/tls.c +++ b/src/lib/libtls/tls.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls.c,v 1.77 2018/03/07 19:07:13 deraadt Exp $ */ | 1 | /* $OpenBSD: tls.c,v 1.78 2018/03/08 16:12:00 beck Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -19,6 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | #include <errno.h> | 20 | #include <errno.h> |
| 21 | #include <limits.h> | 21 | #include <limits.h> |
| 22 | #include <pthread.h> | ||
| 22 | #include <stdlib.h> | 23 | #include <stdlib.h> |
| 23 | #include <unistd.h> | 24 | #include <unistd.h> |
| 24 | 25 | ||
| @@ -35,28 +36,35 @@ | |||
| 35 | 36 | ||
| 36 | static struct tls_config *tls_config_default; | 37 | static struct tls_config *tls_config_default; |
| 37 | 38 | ||
| 38 | int | 39 | static int tls_init_rv = -1; |
| 39 | tls_init(void) | ||
| 40 | { | ||
| 41 | static int tls_initialised = 0; | ||
| 42 | |||
| 43 | if (tls_initialised) | ||
| 44 | return (0); | ||
| 45 | 40 | ||
| 41 | static void | ||
| 42 | tls_do_init(void) | ||
| 43 | { | ||
| 46 | SSL_load_error_strings(); | 44 | SSL_load_error_strings(); |
| 47 | SSL_library_init(); | 45 | SSL_library_init(); |
| 48 | 46 | ||
| 49 | if (BIO_sock_init() != 1) | 47 | if (BIO_sock_init() != 1) |
| 50 | return (-1); | 48 | return; |
| 51 | 49 | ||
| 52 | if ((tls_config_default = tls_config_new()) == NULL) | 50 | if ((tls_config_default = tls_config_new()) == NULL) |
| 53 | return (-1); | 51 | return; |
| 54 | 52 | ||
| 55 | tls_config_default->refcount++; | 53 | tls_config_default->refcount++; |
| 56 | 54 | ||
| 57 | tls_initialised = 1; | 55 | tls_init_rv = 0; |
| 56 | return; | ||
| 57 | } | ||
| 58 | 58 | ||
| 59 | return (0); | 59 | int |
| 60 | tls_init(void) | ||
| 61 | { | ||
| 62 | static pthread_once_t once = PTHREAD_ONCE_INIT; | ||
| 63 | |||
| 64 | if (pthread_once(&once, tls_do_init) != 0) | ||
| 65 | return -1; | ||
| 66 | |||
| 67 | return tls_init_rv; | ||
| 60 | } | 68 | } |
| 61 | 69 | ||
| 62 | const char * | 70 | const char * |
