summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorderaadt <>2018-03-07 19:07:14 +0000
committerderaadt <>2018-03-07 19:07:14 +0000
commit9778eb4189459056db4eb41f2366a9f43289f0ff (patch)
treeb450311fa656b4b01f13e6e5f2558849d539ace3
parente6135660e4e7cb53ac89d814a7cfe8e97df34068 (diff)
downloadopenbsd-9778eb4189459056db4eb41f2366a9f43289f0ff.tar.gz
openbsd-9778eb4189459056db4eb41f2366a9f43289f0ff.tar.bz2
openbsd-9778eb4189459056db4eb41f2366a9f43289f0ff.zip
backout. diff was not tested comprehensively, resulting in a broken tree.
-rw-r--r--src/lib/libtls/man/tls_init.34
-rw-r--r--src/lib/libtls/tls.c32
2 files changed, 14 insertions, 22 deletions
diff --git a/src/lib/libtls/man/tls_init.3 b/src/lib/libtls/man/tls_init.3
index fe8847d0ac..5fb9cdd802 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.8 2018/03/07 17:17:47 beck Exp $ 1.\" $OpenBSD: tls_init.3,v 1.9 2018/03/07 19:07:14 deraadt 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>
@@ -46,7 +46,7 @@ The
46.Fn tls_init 46.Fn tls_init
47function initializes global data structures. 47function initializes global data structures.
48It should be called once before any other functions. 48It should be called once before any other functions.
49It may be called more than once, and may be called concurrently. 49It may be called more than once, but not concurrently.
50.Pp 50.Pp
51Before a connection is created, a configuration must be created. 51Before a connection is created, a configuration must be created.
52The 52The
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c
index 4a9db289bd..c0430d7cd1 100644
--- a/src/lib/libtls/tls.c
+++ b/src/lib/libtls/tls.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls.c,v 1.76 2018/03/07 17:17:47 beck Exp $ */ 1/* $OpenBSD: tls.c,v 1.77 2018/03/07 19:07:13 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -19,7 +19,6 @@
19 19
20#include <errno.h> 20#include <errno.h>
21#include <limits.h> 21#include <limits.h>
22#include <pthread.h>
23#include <stdlib.h> 22#include <stdlib.h>
24#include <unistd.h> 23#include <unistd.h>
25 24
@@ -36,35 +35,28 @@
36 35
37static struct tls_config *tls_config_default; 36static struct tls_config *tls_config_default;
38 37
39static int tls_init_rv = -1; 38int
40 39tls_init(void)
41static void
42tls_do_init(void)
43{ 40{
41 static int tls_initialised = 0;
42
43 if (tls_initialised)
44 return (0);
45
44 SSL_load_error_strings(); 46 SSL_load_error_strings();
45 SSL_library_init(); 47 SSL_library_init();
46 48
47 if (BIO_sock_init() != 1) 49 if (BIO_sock_init() != 1)
48 return; 50 return (-1);
49 51
50 if ((tls_config_default = tls_config_new()) == NULL) 52 if ((tls_config_default = tls_config_new()) == NULL)
51 return; 53 return (-1);
52 54
53 tls_config_default->refcount++; 55 tls_config_default->refcount++;
54 56
55 tls_init_rv = 0; 57 tls_initialised = 1;
56 return;
57}
58
59int
60tls_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 58
67 return tls_init_rv; 59 return (0);
68} 60}
69 61
70const char * 62const char *