summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-27 22:24:33 -0400
committerJune McEnroe <june@causal.agency>2020-07-31 12:12:53 -0400
commit6e5bff1a29b3f93334acd86ca8ab8f10ec61411b (patch)
tree6ebc9d667a15698402f8563d8a85e21d0c89423b
parenttls_server: #include <string.h> (diff)
downloadlibretls-6e5bff1a29b3f93334acd86ca8ab8f10ec61411b.tar.gz
libretls-6e5bff1a29b3f93334acd86ca8ab8f10ec61411b.zip
tls_bio_cb: Use public BIO interfaces
Diffstat (limited to '')
-rw-r--r--tls_bio_cb.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/tls_bio_cb.c b/tls_bio_cb.c
index 0091808..8adbf55 100644
--- a/tls_bio_cb.c
+++ b/tls_bio_cb.c
@@ -17,6 +17,7 @@
 
 #include <fcntl.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <openssl/bio.h>
@@ -29,19 +30,28 @@ static int bio_cb_read(BIO *bio, char *buf, int size);
 static int bio_cb_puts(BIO *bio, const char *str);
 static long bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr);
 
-static BIO_METHOD bio_cb_method = {
-	.type = BIO_TYPE_MEM,
-	.name = "libtls_callbacks",
-	.bwrite = bio_cb_write,
-	.bread = bio_cb_read,
-	.bputs = bio_cb_puts,
-	.ctrl = bio_cb_ctrl,
-};
+static BIO_METHOD *bio_cb_method;
+
+static pthread_once_t bio_cb_init_once = PTHREAD_ONCE_INIT;
+
+static void
+bio_s_cb_init(void)
+{
+	bio_cb_method = BIO_meth_new(BIO_TYPE_MEM, "libtls_callbacks");
+	if (bio_cb_method == NULL)
+		return;
+
+	BIO_meth_set_write(bio_cb_method, bio_cb_write);
+	BIO_meth_set_read(bio_cb_method, bio_cb_read);
+	BIO_meth_set_puts(bio_cb_method, bio_cb_puts);
+	BIO_meth_set_ctrl(bio_cb_method, bio_cb_ctrl);
+}
 
 static BIO_METHOD *
 bio_s_cb(void)
 {
-	return (&bio_cb_method);
+	pthread_once(&bio_cb_init_once, bio_s_cb_init);
+	return bio_cb_method;
 }
 
 static int
@@ -57,10 +67,10 @@ bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr)
 
 	switch (cmd) {
 	case BIO_CTRL_GET_CLOSE:
-		ret = (long)bio->shutdown;
+		ret = (long)BIO_get_shutdown(bio);
 		break;
 	case BIO_CTRL_SET_CLOSE:
-		bio->shutdown = (int)num;
+		BIO_set_shutdown(bio, (int)num);
 		break;
 	case BIO_CTRL_DUP:
 	case BIO_CTRL_FLUSH:
@@ -69,7 +79,7 @@ bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr)
 	case BIO_CTRL_GET:
 	case BIO_CTRL_SET:
 	default:
-		ret = BIO_ctrl(bio->next_bio, cmd, num, ptr);
+		ret = BIO_ctrl(BIO_next(bio), cmd, num, ptr);
 	}
 
 	return (ret);
@@ -78,7 +88,7 @@ bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr)
 static int
 bio_cb_write(BIO *bio, const char *buf, int num)
 {
-	struct tls *ctx = bio->ptr;
+	struct tls *ctx = BIO_get_data(bio);
 	int rv;
 
 	BIO_clear_retry_flags(bio);
@@ -96,7 +106,7 @@ bio_cb_write(BIO *bio, const char *buf, int num)
 static int
 bio_cb_read(BIO *bio, char *buf, int size)
 {
-	struct tls *ctx = bio->ptr;
+	struct tls *ctx = BIO_get_data(bio);
 	int rv;
 
 	BIO_clear_retry_flags(bio);
@@ -131,8 +141,8 @@ tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb,
 		tls_set_errorx(ctx, "failed to create callback i/o");
 		goto err;
 	}
-	bio->ptr = ctx;
-	bio->init = 1;
+	BIO_set_data(bio, ctx);
+	BIO_set_init(bio, 1);
 
 	SSL_set_bio(ctx->ssl_conn, bio, bio);
 
b545a42c38f2568055cb886c&follow=1'>Add -w to upJune McEnroe 2022-07-13Set push.autoSetupRemoteJune McEnroe 2022-07-08Remove TOURJune McEnroe There is not that much distinct stuff here anymore. 2022-07-03Add The Bone Shard EmperorJune McEnroe Suffers a little bit from middle book but I really enjoyed it. Read it faster than the first one too, despite its length. 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe Mixed bag like most collections of short stories. Some of them are pretty good. The author of the worst written story also has the worst written bio. 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe Absolutely indiscriminately. 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe