From fb76faf56aca9b79648d776896a4a4fae7c978cf Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 21 Nov 2020 11:58:44 +0000 Subject: Move all tls stuff into its own subdir --- package/deps.mak | 70 ++++----- src/conn-tools/deps-exe/s6-tlsc | 2 - src/conn-tools/deps-exe/s6-tlsc-io | 5 - src/conn-tools/deps-exe/s6-tlsclient | 1 - src/conn-tools/deps-exe/s6-tlsd | 2 - src/conn-tools/deps-exe/s6-tlsd-io | 5 - src/conn-tools/deps-exe/s6-tlsserver | 1 - src/conn-tools/deps-exe/s6-ucspitlsc | 3 - src/conn-tools/deps-exe/s6-ucspitlsd | 3 - src/conn-tools/deps-lib/s6tls | 4 - src/conn-tools/s6-tlsc-io.c | 128 ---------------- src/conn-tools/s6-tlsc.c | 94 ------------ src/conn-tools/s6-tlsclient.c | 202 ------------------------ src/conn-tools/s6-tlsd-io.c | 126 --------------- src/conn-tools/s6-tlsd.c | 72 --------- src/conn-tools/s6-tlsserver.c | 255 ------------------------------- src/conn-tools/s6-ucspitlsc.c | 109 ------------- src/conn-tools/s6-ucspitlsd.c | 88 ----------- src/conn-tools/s6tls-internal.h | 18 --- src/conn-tools/s6tls_exec_tlscio.c | 53 ------- src/conn-tools/s6tls_exec_tlsdio.c | 49 ------ src/conn-tools/s6tls_sync_and_exec_app.c | 43 ------ src/conn-tools/s6tls_ucspi_exec_app.c | 36 ----- src/tls/deps-exe/s6-tlsc | 2 + src/tls/deps-exe/s6-tlsc-io | 5 + src/tls/deps-exe/s6-tlsclient | 1 + src/tls/deps-exe/s6-tlsd | 2 + src/tls/deps-exe/s6-tlsd-io | 5 + src/tls/deps-exe/s6-tlsserver | 1 + src/tls/deps-exe/s6-ucspitlsc | 3 + src/tls/deps-exe/s6-ucspitlsd | 3 + src/tls/deps-lib/s6tls | 4 + src/tls/s6-tlsc-io.c | 128 ++++++++++++++++ src/tls/s6-tlsc.c | 94 ++++++++++++ src/tls/s6-tlsclient.c | 202 ++++++++++++++++++++++++ src/tls/s6-tlsd-io.c | 126 +++++++++++++++ src/tls/s6-tlsd.c | 72 +++++++++ src/tls/s6-tlsserver.c | 255 +++++++++++++++++++++++++++++++ src/tls/s6-ucspitlsc.c | 109 +++++++++++++ src/tls/s6-ucspitlsd.c | 88 +++++++++++ src/tls/s6tls-internal.h | 18 +++ src/tls/s6tls_exec_tlscio.c | 53 +++++++ src/tls/s6tls_exec_tlsdio.c | 49 ++++++ src/tls/s6tls_sync_and_exec_app.c | 43 ++++++ src/tls/s6tls_ucspi_exec_app.c | 36 +++++ 45 files changed, 1334 insertions(+), 1334 deletions(-) delete mode 100644 src/conn-tools/deps-exe/s6-tlsc delete mode 100644 src/conn-tools/deps-exe/s6-tlsc-io delete mode 100644 src/conn-tools/deps-exe/s6-tlsclient delete mode 100644 src/conn-tools/deps-exe/s6-tlsd delete mode 100644 src/conn-tools/deps-exe/s6-tlsd-io delete mode 100644 src/conn-tools/deps-exe/s6-tlsserver delete mode 100644 src/conn-tools/deps-exe/s6-ucspitlsc delete mode 100644 src/conn-tools/deps-exe/s6-ucspitlsd delete mode 100644 src/conn-tools/deps-lib/s6tls delete mode 100644 src/conn-tools/s6-tlsc-io.c delete mode 100644 src/conn-tools/s6-tlsc.c delete mode 100644 src/conn-tools/s6-tlsclient.c delete mode 100644 src/conn-tools/s6-tlsd-io.c delete mode 100644 src/conn-tools/s6-tlsd.c delete mode 100644 src/conn-tools/s6-tlsserver.c delete mode 100644 src/conn-tools/s6-ucspitlsc.c delete mode 100644 src/conn-tools/s6-ucspitlsd.c delete mode 100644 src/conn-tools/s6tls-internal.h delete mode 100644 src/conn-tools/s6tls_exec_tlscio.c delete mode 100644 src/conn-tools/s6tls_exec_tlsdio.c delete mode 100644 src/conn-tools/s6tls_sync_and_exec_app.c delete mode 100644 src/conn-tools/s6tls_ucspi_exec_app.c create mode 100644 src/tls/deps-exe/s6-tlsc create mode 100644 src/tls/deps-exe/s6-tlsc-io create mode 100644 src/tls/deps-exe/s6-tlsclient create mode 100644 src/tls/deps-exe/s6-tlsd create mode 100644 src/tls/deps-exe/s6-tlsd-io create mode 100644 src/tls/deps-exe/s6-tlsserver create mode 100644 src/tls/deps-exe/s6-ucspitlsc create mode 100644 src/tls/deps-exe/s6-ucspitlsd create mode 100644 src/tls/deps-lib/s6tls create mode 100644 src/tls/s6-tlsc-io.c create mode 100644 src/tls/s6-tlsc.c create mode 100644 src/tls/s6-tlsclient.c create mode 100644 src/tls/s6-tlsd-io.c create mode 100644 src/tls/s6-tlsd.c create mode 100644 src/tls/s6-tlsserver.c create mode 100644 src/tls/s6-ucspitlsc.c create mode 100644 src/tls/s6-ucspitlsd.c create mode 100644 src/tls/s6tls-internal.h create mode 100644 src/tls/s6tls_exec_tlscio.c create mode 100644 src/tls/s6tls_exec_tlsdio.c create mode 100644 src/tls/s6tls_sync_and_exec_app.c create mode 100644 src/tls/s6tls_ucspi_exec_app.c diff --git a/package/deps.mak b/package/deps.mak index 9f779b9..adfe397 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -20,18 +20,6 @@ src/conn-tools/s6-tcpserver4d.o src/conn-tools/s6-tcpserver4d.lo: src/conn-tools src/conn-tools/s6-tcpserver6-socketbinder.o src/conn-tools/s6-tcpserver6-socketbinder.lo: src/conn-tools/s6-tcpserver6-socketbinder.c src/conn-tools/s6-tcpserver6.o src/conn-tools/s6-tcpserver6.lo: src/conn-tools/s6-tcpserver6.c src/include/s6-networking/config.h src/conn-tools/s6-tcpserver6d.o src/conn-tools/s6-tcpserver6d.lo: src/conn-tools/s6-tcpserver6d.c -src/conn-tools/s6-tlsc-io.o src/conn-tools/s6-tlsc-io.lo: src/conn-tools/s6-tlsc-io.c src/include/s6-networking/config.h src/include/s6-networking/sbearssl.h src/include/s6-networking/stls.h -src/conn-tools/s6-tlsc.o src/conn-tools/s6-tlsc.lo: src/conn-tools/s6-tlsc.c src/conn-tools/s6tls-internal.h -src/conn-tools/s6-tlsclient.o src/conn-tools/s6-tlsclient.lo: src/conn-tools/s6-tlsclient.c src/include/s6-networking/config.h -src/conn-tools/s6-tlsd-io.o src/conn-tools/s6-tlsd-io.lo: src/conn-tools/s6-tlsd-io.c src/include/s6-networking/config.h src/include/s6-networking/sbearssl.h src/include/s6-networking/stls.h -src/conn-tools/s6-tlsd.o src/conn-tools/s6-tlsd.lo: src/conn-tools/s6-tlsd.c src/conn-tools/s6tls-internal.h -src/conn-tools/s6-tlsserver.o src/conn-tools/s6-tlsserver.lo: src/conn-tools/s6-tlsserver.c src/include/s6-networking/config.h -src/conn-tools/s6-ucspitlsc.o src/conn-tools/s6-ucspitlsc.lo: src/conn-tools/s6-ucspitlsc.c src/include/s6-networking/config.h src/conn-tools/s6tls-internal.h -src/conn-tools/s6-ucspitlsd.o src/conn-tools/s6-ucspitlsd.lo: src/conn-tools/s6-ucspitlsd.c src/include/s6-networking/config.h src/conn-tools/s6tls-internal.h -src/conn-tools/s6tls_exec_tlscio.o src/conn-tools/s6tls_exec_tlscio.lo: src/conn-tools/s6tls_exec_tlscio.c src/include/s6-networking/config.h src/conn-tools/s6tls-internal.h -src/conn-tools/s6tls_exec_tlsdio.o src/conn-tools/s6tls_exec_tlsdio.lo: src/conn-tools/s6tls_exec_tlsdio.c src/include/s6-networking/config.h src/conn-tools/s6tls-internal.h -src/conn-tools/s6tls_sync_and_exec_app.o src/conn-tools/s6tls_sync_and_exec_app.lo: src/conn-tools/s6tls_sync_and_exec_app.c src/conn-tools/s6tls-internal.h -src/conn-tools/s6tls_ucspi_exec_app.o src/conn-tools/s6tls_ucspi_exec_app.lo: src/conn-tools/s6tls_ucspi_exec_app.c src/conn-tools/s6tls-internal.h src/libs6net/s6net_ident_client.o src/libs6net/s6net_ident_client.lo: src/libs6net/s6net_ident_client.c src/include/s6-networking/ident.h src/libs6net/s6net_ident_error.o src/libs6net/s6net_ident_error.lo: src/libs6net/s6net_ident_error.c src/include/s6-networking/ident.h src/libs6net/s6net_ident_reply_get.o src/libs6net/s6net_ident_reply_get.lo: src/libs6net/s6net_ident_reply_get.c src/include/s6-networking/ident.h @@ -80,6 +68,18 @@ src/stls/stls_client_init_and_handshake.o src/stls/stls_client_init_and_handshak src/stls/stls_drop.o src/stls/stls_drop.lo: src/stls/stls_drop.c src/stls/stls-internal.h src/stls/stls_run.o src/stls/stls_run.lo: src/stls/stls_run.c src/include/s6-networking/stls.h src/stls/stls_server_init_and_handshake.o src/stls/stls_server_init_and_handshake.lo: src/stls/stls_server_init_and_handshake.c src/include/s6-networking/stls.h src/stls/stls-internal.h +src/tls/s6-tlsc-io.o src/tls/s6-tlsc-io.lo: src/tls/s6-tlsc-io.c src/include/s6-networking/config.h src/include/s6-networking/sbearssl.h src/include/s6-networking/stls.h +src/tls/s6-tlsc.o src/tls/s6-tlsc.lo: src/tls/s6-tlsc.c src/tls/s6tls-internal.h +src/tls/s6-tlsclient.o src/tls/s6-tlsclient.lo: src/tls/s6-tlsclient.c src/include/s6-networking/config.h +src/tls/s6-tlsd-io.o src/tls/s6-tlsd-io.lo: src/tls/s6-tlsd-io.c src/include/s6-networking/config.h src/include/s6-networking/sbearssl.h src/include/s6-networking/stls.h +src/tls/s6-tlsd.o src/tls/s6-tlsd.lo: src/tls/s6-tlsd.c src/tls/s6tls-internal.h +src/tls/s6-tlsserver.o src/tls/s6-tlsserver.lo: src/tls/s6-tlsserver.c src/include/s6-networking/config.h +src/tls/s6-ucspitlsc.o src/tls/s6-ucspitlsc.lo: src/tls/s6-ucspitlsc.c src/include/s6-networking/config.h src/tls/s6tls-internal.h +src/tls/s6-ucspitlsd.o src/tls/s6-ucspitlsd.lo: src/tls/s6-ucspitlsd.c src/include/s6-networking/config.h src/tls/s6tls-internal.h +src/tls/s6tls_exec_tlscio.o src/tls/s6tls_exec_tlscio.lo: src/tls/s6tls_exec_tlscio.c src/include/s6-networking/config.h src/tls/s6tls-internal.h +src/tls/s6tls_exec_tlsdio.o src/tls/s6tls_exec_tlsdio.lo: src/tls/s6tls_exec_tlsdio.c src/include/s6-networking/config.h src/tls/s6tls-internal.h +src/tls/s6tls_sync_and_exec_app.o src/tls/s6tls_sync_and_exec_app.lo: src/tls/s6tls_sync_and_exec_app.c src/tls/s6tls-internal.h +src/tls/s6tls_ucspi_exec_app.o src/tls/s6tls_ucspi_exec_app.lo: src/tls/s6tls_ucspi_exec_app.c src/tls/s6tls-internal.h s6-clockadd: EXTRA_LIBS := -lskarnet ${SYSCLOCK_LIB} s6-clockadd: src/clock/s6-clockadd.o @@ -91,13 +91,6 @@ s6-taiclock: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} s6-taiclock: src/clock/s6-taiclock.o s6-taiclockd: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} s6-taiclockd: src/clock/s6-taiclockd.o -ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) -libs6tls.a.xyzzy: src/conn-tools/s6tls_exec_tlscio.o src/conn-tools/s6tls_exec_tlsdio.o src/conn-tools/s6tls_sync_and_exec_app.o src/conn-tools/s6tls_ucspi_exec_app.o -else -libs6tls.a.xyzzy: src/conn-tools/s6tls_exec_tlscio.lo src/conn-tools/s6tls_exec_tlsdio.lo src/conn-tools/s6tls_sync_and_exec_app.lo src/conn-tools/s6tls_ucspi_exec_app.lo -endif -libs6tls.so.xyzzy: EXTRA_LIBS := -libs6tls.so.xyzzy: src/conn-tools/s6tls_exec_tlscio.lo src/conn-tools/s6tls_exec_tlsdio.lo src/conn-tools/s6tls_sync_and_exec_app.lo src/conn-tools/s6tls_ucspi_exec_app.lo s6-getservbyname: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} s6-getservbyname: src/conn-tools/s6-getservbyname.o s6-ident-client: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} @@ -120,22 +113,6 @@ s6-tcpserver6-socketbinder: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} s6-tcpserver6-socketbinder: src/conn-tools/s6-tcpserver6-socketbinder.o s6-tcpserver6d: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} s6-tcpserver6d: src/conn-tools/s6-tcpserver6d.o -s6-tlsc: EXTRA_LIBS := -lskarnet -s6-tlsc: src/conn-tools/s6-tlsc.o libs6tls.a.xyzzy -s6-tlsc-io: EXTRA_LIBS := -lskarnet ${CRYPTO_LIB} ${SOCKET_LIB} ${SYSCLOCK_LIB} -s6-tlsc-io: src/conn-tools/s6-tlsc-io.o ${LIBCRYPTOSUPPORT} -s6-tlsclient: EXTRA_LIBS := -lskarnet -s6-tlsclient: src/conn-tools/s6-tlsclient.o -s6-tlsd: EXTRA_LIBS := -lskarnet -s6-tlsd: src/conn-tools/s6-tlsd.o libs6tls.a.xyzzy -s6-tlsd-io: EXTRA_LIBS := -lskarnet ${CRYPTO_LIB} ${SOCKET_LIB} ${SYSCLOCK_LIB} -s6-tlsd-io: src/conn-tools/s6-tlsd-io.o ${LIBCRYPTOSUPPORT} -s6-tlsserver: EXTRA_LIBS := -lskarnet -s6-tlsserver: src/conn-tools/s6-tlsserver.o -s6-ucspitlsc: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} -s6-ucspitlsc: src/conn-tools/s6-ucspitlsc.o libs6tls.a.xyzzy -s6-ucspitlsd: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} -s6-ucspitlsd: src/conn-tools/s6-ucspitlsd.o libs6tls.a.xyzzy ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) libs6net.a.xyzzy: src/libs6net/s6net_ident_client.o src/libs6net/s6net_ident_reply_get.o src/libs6net/s6net_ident_reply_parse.o src/libs6net/s6net_ident_error.o else @@ -159,3 +136,26 @@ libstls.a.xyzzy: src/stls/stls_drop.lo src/stls/stls_run.lo src/stls/stls_client endif libstls.so.xyzzy: EXTRA_LIBS := ${CRYPTO_LIB} -lskarnet libstls.so.xyzzy: src/stls/stls_drop.lo src/stls/stls_run.lo src/stls/stls_client_init_and_handshake.lo src/stls/stls_server_init_and_handshake.lo +ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) +libs6tls.a.xyzzy: src/tls/s6tls_exec_tlscio.o src/tls/s6tls_exec_tlsdio.o src/tls/s6tls_sync_and_exec_app.o src/tls/s6tls_ucspi_exec_app.o +else +libs6tls.a.xyzzy: src/tls/s6tls_exec_tlscio.lo src/tls/s6tls_exec_tlsdio.lo src/tls/s6tls_sync_and_exec_app.lo src/tls/s6tls_ucspi_exec_app.lo +endif +libs6tls.so.xyzzy: EXTRA_LIBS := +libs6tls.so.xyzzy: src/tls/s6tls_exec_tlscio.lo src/tls/s6tls_exec_tlsdio.lo src/tls/s6tls_sync_and_exec_app.lo src/tls/s6tls_ucspi_exec_app.lo +s6-tlsc: EXTRA_LIBS := -lskarnet +s6-tlsc: src/tls/s6-tlsc.o libs6tls.a.xyzzy +s6-tlsc-io: EXTRA_LIBS := -lskarnet ${CRYPTO_LIB} ${SOCKET_LIB} ${SYSCLOCK_LIB} +s6-tlsc-io: src/tls/s6-tlsc-io.o ${LIBCRYPTOSUPPORT} +s6-tlsclient: EXTRA_LIBS := -lskarnet +s6-tlsclient: src/tls/s6-tlsclient.o +s6-tlsd: EXTRA_LIBS := -lskarnet +s6-tlsd: src/tls/s6-tlsd.o libs6tls.a.xyzzy +s6-tlsd-io: EXTRA_LIBS := -lskarnet ${CRYPTO_LIB} ${SOCKET_LIB} ${SYSCLOCK_LIB} +s6-tlsd-io: src/tls/s6-tlsd-io.o ${LIBCRYPTOSUPPORT} +s6-tlsserver: EXTRA_LIBS := -lskarnet +s6-tlsserver: src/tls/s6-tlsserver.o +s6-ucspitlsc: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} +s6-ucspitlsc: src/tls/s6-ucspitlsc.o libs6tls.a.xyzzy +s6-ucspitlsd: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} +s6-ucspitlsd: src/tls/s6-ucspitlsd.o libs6tls.a.xyzzy diff --git a/src/conn-tools/deps-exe/s6-tlsc b/src/conn-tools/deps-exe/s6-tlsc deleted file mode 100644 index 37405fd..0000000 --- a/src/conn-tools/deps-exe/s6-tlsc +++ /dev/null @@ -1,2 +0,0 @@ -libs6tls.a.xyzzy --lskarnet diff --git a/src/conn-tools/deps-exe/s6-tlsc-io b/src/conn-tools/deps-exe/s6-tlsc-io deleted file mode 100644 index 3e2653d..0000000 --- a/src/conn-tools/deps-exe/s6-tlsc-io +++ /dev/null @@ -1,5 +0,0 @@ -${LIBCRYPTOSUPPORT} --lskarnet -${CRYPTO_LIB} -${SOCKET_LIB} -${SYSCLOCK_LIB} diff --git a/src/conn-tools/deps-exe/s6-tlsclient b/src/conn-tools/deps-exe/s6-tlsclient deleted file mode 100644 index e7187fe..0000000 --- a/src/conn-tools/deps-exe/s6-tlsclient +++ /dev/null @@ -1 +0,0 @@ --lskarnet diff --git a/src/conn-tools/deps-exe/s6-tlsd b/src/conn-tools/deps-exe/s6-tlsd deleted file mode 100644 index 37405fd..0000000 --- a/src/conn-tools/deps-exe/s6-tlsd +++ /dev/null @@ -1,2 +0,0 @@ -libs6tls.a.xyzzy --lskarnet diff --git a/src/conn-tools/deps-exe/s6-tlsd-io b/src/conn-tools/deps-exe/s6-tlsd-io deleted file mode 100644 index 3e2653d..0000000 --- a/src/conn-tools/deps-exe/s6-tlsd-io +++ /dev/null @@ -1,5 +0,0 @@ -${LIBCRYPTOSUPPORT} --lskarnet -${CRYPTO_LIB} -${SOCKET_LIB} -${SYSCLOCK_LIB} diff --git a/src/conn-tools/deps-exe/s6-tlsserver b/src/conn-tools/deps-exe/s6-tlsserver deleted file mode 100644 index e7187fe..0000000 --- a/src/conn-tools/deps-exe/s6-tlsserver +++ /dev/null @@ -1 +0,0 @@ --lskarnet diff --git a/src/conn-tools/deps-exe/s6-ucspitlsc b/src/conn-tools/deps-exe/s6-ucspitlsc deleted file mode 100644 index ac1b327..0000000 --- a/src/conn-tools/deps-exe/s6-ucspitlsc +++ /dev/null @@ -1,3 +0,0 @@ -libs6tls.a.xyzzy --lskarnet -${SOCKET_LIB} diff --git a/src/conn-tools/deps-exe/s6-ucspitlsd b/src/conn-tools/deps-exe/s6-ucspitlsd deleted file mode 100644 index ac1b327..0000000 --- a/src/conn-tools/deps-exe/s6-ucspitlsd +++ /dev/null @@ -1,3 +0,0 @@ -libs6tls.a.xyzzy --lskarnet -${SOCKET_LIB} diff --git a/src/conn-tools/deps-lib/s6tls b/src/conn-tools/deps-lib/s6tls deleted file mode 100644 index f392de5..0000000 --- a/src/conn-tools/deps-lib/s6tls +++ /dev/null @@ -1,4 +0,0 @@ -s6tls_exec_tlscio.o -s6tls_exec_tlsdio.o -s6tls_sync_and_exec_app.o -s6tls_ucspi_exec_app.o diff --git a/src/conn-tools/s6-tlsc-io.c b/src/conn-tools/s6-tlsc-io.c deleted file mode 100644 index 79dd25d..0000000 --- a/src/conn-tools/s6-tlsc-io.c +++ /dev/null @@ -1,128 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define HANDSHAKE_BANNER "SSL_PROTOCOL=TLSv1\0" - -static inline void doit (int *, tain_t const *tto, uint32_t, uint32_t, unsigned int, char const *, unsigned int) gccattr_noreturn ; - -#ifdef S6_NETWORKING_USE_TLS - -#include - -static inline void doit (int *fds, tain_t const *tto, uint32_t preoptions, uint32_t options, unsigned int verbosity, char const *servername, unsigned int notif) -{ - struct tls *ctx = stls_client_init_and_handshake(fds + 2, preoptions, servername) ; - if (notif) - { - if (allwrite(notif, HANDSHAKE_BANNER, sizeof(HANDSHAKE_BANNER)) < sizeof(HANDSHAKE_BANNER)) - strerr_diefu1sys(111, "write post-handshake data") ; - fd_close(notif) ; - } - stls_run(ctx, fds, tto, options, verbosity) ; -} - -#else -#ifdef S6_NETWORKING_USE_BEARSSL - -#include - -#include - -static int handshake_cb_nop (br_ssl_engine_context *ctx, sbearssl_handshake_cb_context_t *cbarg) -{ - (void)ctx ; - (void)cbarg ; - return 1 ; -} - -static int handshake_cb_sendvars (br_ssl_engine_context *ctx, sbearssl_handshake_cb_context_t *cbarg) -{ - if (allwrite(cbarg->notif, HANDSHAKE_BANNER, sizeof(HANDSHAKE_BANNER)) < sizeof(HANDSHAKE_BANNER)) - return 0 ; - fd_close(cbarg->notif) ; - return 1 ; -} - -static inline void doit (int *fds, tain_t const *tto, uint32_t preoptions, uint32_t options, unsigned int verbosity, char const *servername, unsigned int notif) -{ - if (ndelay_on(fds[0]) < 0 || ndelay_on(fds[1]) < 0) - strerr_diefu1sys(111, "set local fds non-blocking") ; - if (!random_init()) strerr_diefu1sys(111, "initialize random device") ; - sbearssl_client_init_and_run(fds, tto, preoptions, options, verbosity, servername, notif ? &handshake_cb_sendvars : &handshake_cb_nop, notif) ; -} - -#else - -#error No SSL backend configured. - -#endif -#endif - - -#define USAGE "s6-tlsc-io [ -v verbosity ] [ -d notif ] [ -S | -s ] [ -Y | -y ] [ -K timeout ] [ -k servername ] fdr fdw" -#define dieusage() strerr_dieusage(100, USAGE) - -int main (int argc, char const *const *argv, char const *const *envp) -{ - char const *servername = 0 ; - tain_t tto ; - int fds[4] = { 0, 1, 0, 1 } ; - unsigned int verbosity = 1 ; - unsigned int notif = 0 ; - uint32_t preoptions = 0 ; - uint32_t options = 1 ; - - PROG = "s6-tlsc-io" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - unsigned int t = 0 ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "d:SsYyv:K:k:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; - case 'd' : if (!uint0_scan(l.arg, ¬if)) dieusage() ; break ; - case 'S' : options &= ~1 ; break ; - case 's' : options |= 1 ; break ; - case 'Y' : preoptions &= ~1 ; break ; - case 'y' : preoptions |= 1 ; break ; - case 'K' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; - case 'k' : servername = l.arg ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - if (t) tain_from_millisecs(&tto, t) ; else tto = tain_infinite_relative ; - } - if (argc < 2) dieusage() ; - { - unsigned int u ; - if (!uint0_scan(argv[0], &u)) dieusage() ; - fds[0] = u ; - if (!uint0_scan(argv[1], &u)) dieusage() ; - fds[1] = u ; - } - - if (ndelay_on(0) < 0 || ndelay_on(1) < 0) - strerr_diefu1sys(111, "set stdin/stdout non-blocking") ; - if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ; - tain_now_set_stopwatch_g() ; - doit(fds, &tto, preoptions, options, verbosity, servername, notif) ; -} diff --git a/src/conn-tools/s6-tlsc.c b/src/conn-tools/s6-tlsc.c deleted file mode 100644 index 5b2e7dc..0000000 --- a/src/conn-tools/s6-tlsc.c +++ /dev/null @@ -1,94 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "s6tls-internal.h" - -#define USAGE "s6-tlsc [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -k servername ] [ -Z | -z ] [ -6 fdr ] [ -7 fdw ] prog..." -#define dieusage() strerr_dieusage(100, USAGE) - -static void child (int const [4][2], uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ; -static void child (int const p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername) -{ - int fds[3] = { p[0][0], p[1][1], p[2][1] } ; - PROG = "s6-tlsc (child)" ; - close(p[2][0]) ; - close(p[0][1]) ; - close(p[1][0]) ; - if (fd_move(0, p[3][0]) < 0 || fd_move(1, p[3][1]) < 0) - strerr_diefu1sys(111, "move network fds to stdin/stdout") ; - s6tls_exec_tlscio(fds, options, verbosity, kimeout, servername) ; -} - -int main (int argc, char const *const *argv) -{ - unsigned int verbosity = 1 ; - unsigned int kimeout = 0 ; - int p[4][2] ; - uint32_t coptions = 0 ; - uint32_t poptions = 1 ; - pid_t pid ; - char const *servername = 0 ; - - PROG = "s6-tlsc" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "SsYyv:K:k:Zz6:7:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'S' : coptions &= ~4 ; break ; - case 's' : coptions |= 4 ; break ; - case 'Y' : coptions &= ~1 ; break ; - case 'y' : coptions |= 1 ; break ; - case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; - case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; - case 'k' : servername = l.arg ; break ; - case 'Z' : poptions &= ~1 ; break ; - case 'z' : poptions |= 1 ; break ; - case '6' : - { - unsigned int fd ; - if (!uint0_scan(l.arg, &fd)) dieusage() ; - p[3][0] = fd ; - break ; - } - case '7' : - { - unsigned int fd ; - if (!uint0_scan(l.arg, &fd)) dieusage() ; - p[3][1] = fd ; - break ; - } - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (!argc) dieusage() ; - fd_sanitize() ; - if (fcntl(p[3][0], F_GETFD) < 0 || fcntl(p[3][1], F_GETFD) < 0) - strerr_diefu1sys(111, "check network fds") ; - - if (pipe(p[0]) < 0 || pipe(p[1]) < 0 || pipe(p[2]) < 0) - strerr_diefu1sys(111, "pipe") ; - pid = fork() ; - switch (pid) - { - case -1 : strerr_diefu1sys(111, "fork") ; - case 0 : child(p, coptions, verbosity, kimeout, servername) ; - default : break ; - } - s6tls_sync_and_exec_app(argv, p, pid, poptions) ; -} diff --git a/src/conn-tools/s6-tlsclient.c b/src/conn-tools/s6-tlsclient.c deleted file mode 100644 index 267f457..0000000 --- a/src/conn-tools/s6-tlsclient.c +++ /dev/null @@ -1,202 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define USAGE "s6-tlsclient [ options ] host port prog...\n" \ -"s6-tcpclient options: [ -q | -Q | -v ] [ -4 | -6 ] [ -d | -D ] [ -r | -R ] [ -h | -H ] [ -n | -N ] [ -t timeout ] [ -l localname ] [ -T timeoutconn ] [ -i localip ] [ -p localport ]\n" \ -"s6-tlsc options: [ -S | -s ] [ -Y | -y ] [ -K timeout ] [ -k servername ] [ -Z | -z ]" - -#define dieusage() strerr_dieusage(100, USAGE) - -typedef struct options_s options_t, *options_t_ref ; -struct options_s -{ - char const *localname ; - char const *servername ; - unsigned int timeout ; - unsigned int ximeout ; - unsigned int yimeout ; - unsigned int kimeout ; - uint16_t localport ; - ip46full_t localip ; - unsigned int verbosity : 2 ; - unsigned int flag4 : 1 ; - unsigned int flag6 : 1 ; - unsigned int flagD : 1 ; - unsigned int flagH : 1 ; - unsigned int flagr : 1 ; - unsigned int flagN : 1 ; - unsigned int flagS : 1 ; - unsigned int flagy : 1 ; - unsigned int flagZ : 1 ; - unsigned int doxy : 1 ; -} ; - -#define OPTIONS_ZERO \ -{ \ - .localname = 0, \ - .servername = 0, \ - .timeout = 0, \ - .ximeout = 2, \ - .yimeout = 58, \ - .kimeout = 0, \ - .localport = 0, \ - .localip = IP46FULL_ZERO, \ - .verbosity = 1, \ - .flag4 = 0, \ - .flag6 = 0, \ - .flagD = 0, \ - .flagH = 0, \ - .flagr = 0, \ - .flagN = 0, \ - .flagS = 0, \ - .flagy = 0, \ - .flagZ = 0, \ - .doxy = 0 \ -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - options_t o = OPTIONS_ZERO ; - PROG = "s6-tlsclient" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "qQv46DdHhRrnNt:l:T:i:p:SsYyK:k:Zz", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'q' : o.verbosity = 0 ; break ; - case 'Q' : o.verbosity = 1 ; break ; - case 'v' : o.verbosity = 2 ; break ; - case '4' : o.flag4 = 1 ; break ; - case '6' : o.flag6 = 1 ; break ; - case 'D' : o.flagD = 1 ; break ; - case 'd' : o.flagD = 0 ; break ; - case 'H' : o.flagH = 1 ; break ; - case 'h' : o.flagH = 0 ; break ; - case 'R' : o.flagr = 0 ; break ; - case 'r' : o.flagr = 1 ; break ; - case 'n' : o.flagN = 0 ; break ; - case 'N' : o.flagN = 1 ; break ; - case 't' : if (!uint0_scan(l.arg, &o.timeout)) dieusage() ; break ; - case 'l' : o.localname = l.arg ; break ; - case 'T' : - { - size_t n = uint_scan(l.arg, &o.ximeout) ; - if (!n) dieusage() ; - o.doxy = 1 ; - if (!l.arg[n]) - { - o.yimeout = 0 ; - break ; - } - if (l.arg[n] != '+') dieusage() ; - if (!uint0_scan(l.arg + n + 1, &o.yimeout)) dieusage() ; - break ; - } - case 'i' : if (!ip46full_scan(l.arg, &o.localip)) dieusage() ; break ; - case 'p' : if (!uint160_scan(l.arg, &o.localport)) dieusage() ; break ; - case 'S' : o.flagS = 1 ; break ; - case 's' : o.flagS = 0 ; break ; - case 'Y' : o.flagy = 0 ; break ; - case 'y' : o.flagy = 1 ; break ; - case 'K' : if (!uint0_scan(l.arg, &o.kimeout)) dieusage() ; break ; - case 'k' : o.servername = l.arg ; break ; - case 'Z' : o.flagZ = 1 ; break ; - case 'z' : o.flagZ = 0 ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - if (argc < 3) dieusage() ; - } - - if (!o.servername && !o.flagH) - { - ip46full_t ip ; - if (!ip46full_scan(argv[0], &ip)) - o.servername = argv[0] ; - } - - { - size_t pos = 0 ; - unsigned int m = 0 ; - char fmt[UINT_FMT * 4 + UINT16_FMT + IP46_FMT] ; - char const *newargv[29 + argc] ; - newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpclient" ; - if (o.verbosity != 1) newargv[m++] = o.verbosity ? "-v" : "-q" ; - if (o.flag4) newargv[m++] = "-4" ; - if (o.flag6) newargv[m++] = "-6" ; - if (o.flagD) newargv[m++] = "-D" ; - if (o.flagH) newargv[m++] = "-H" ; - if (o.flagr) newargv[m++] = "-r" ; - if (o.flagN) newargv[m++] = "-N" ; - if (o.timeout) - { - newargv[m++] = "-t" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, o.timeout) ; - fmt[pos++] = 0 ; - } - if (o.localname) - { - newargv[m++] = "-l" ; - newargv[m++] = o.localname ; - } - if (o.doxy) - { - newargv[m++] = "-T" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, o.ximeout) ; - fmt[pos++] = '+' ; - pos += uint_fmt(fmt + pos, o.yimeout) ; - fmt[pos++] = 0 ; - } - if (memcmp(o.localip.ip, IP6_ANY, 16)) - { - newargv[m++] = "-i" ; - newargv[m++] = fmt + pos ; - pos += ip46full_fmt(fmt + pos, &o.localip) ; - fmt[pos++] = 0 ; - } - if (o.localport) - { - newargv[m++] = "-p" ; - newargv[m++] = fmt + pos ; - pos += uint16_fmt(fmt + pos, o.localport) ; - fmt[pos++] = 0 ; - } - newargv[m++] = "--" ; - newargv[m++] = *argv++ ; - newargv[m++] = *argv++ ; - newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsc" ; - if (o.flagS) newargv[m++] = "-S" ; - if (o.flagy) newargv[m++] = "-y" ; - if (o.kimeout) - { - newargv[m++] = "-K" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, o.kimeout) ; - fmt[pos++] = 0 ; - } - if (o.servername) - { - newargv[m++] = "-k" ; - newargv[m++] = o.servername ; - } - if (o.flagZ) newargv[m++] = "-Z" ; - newargv[m++] = "--" ; - while (*argv) newargv[m++] = *argv++ ; - newargv[m++] = 0 ; - xpathexec_run(newargv[0], newargv, envp) ; - } -} diff --git a/src/conn-tools/s6-tlsd-io.c b/src/conn-tools/s6-tlsd-io.c deleted file mode 100644 index 0b42b3b..0000000 --- a/src/conn-tools/s6-tlsd-io.c +++ /dev/null @@ -1,126 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define HANDSHAKE_BANNER "SSL_PROTOCOL=TLSv1\0" - -static inline void doit (int *, tain_t const *tto, uint32_t, uint32_t, unsigned int, unsigned int) gccattr_noreturn ; - -#ifdef S6_NETWORKING_USE_TLS - -#include - -static inline void doit (int *fds, tain_t const *tto, uint32_t preoptions, uint32_t options, unsigned int verbosity, unsigned int notif) -{ - struct tls *ctx = stls_server_init_and_handshake(fds + 2, preoptions) ; - if (notif) - { - if (allwrite(notif, HANDSHAKE_BANNER, sizeof(HANDSHAKE_BANNER)) < sizeof(HANDSHAKE_BANNER)) - strerr_diefu1sys(111, "write post-handshake data") ; - fd_close(notif) ; - } - stls_run(ctx, fds, tto, options, verbosity) ; -} - -#else -#ifdef S6_NETWORKING_USE_BEARSSL - -#include - -#include - -static int handshake_cb_nop (br_ssl_engine_context *ctx, sbearssl_handshake_cb_context_t *cbarg) -{ - (void)ctx ; - (void)cbarg ; - return 1 ; -} - -static int handshake_cb_sendvars (br_ssl_engine_context *ctx, sbearssl_handshake_cb_context_t *cbarg) -{ - if (allwrite(cbarg->notif, HANDSHAKE_BANNER, sizeof(HANDSHAKE_BANNER)) < sizeof(HANDSHAKE_BANNER)) - return 0 ; - fd_close(cbarg->notif) ; - return 1 ; -} - -static inline void doit (int *fds, tain_t const *tto, uint32_t preoptions, uint32_t options, unsigned int verbosity, unsigned int notif) -{ - if (ndelay_on(fds[0]) < 0 || ndelay_on(fds[1]) < 0) - strerr_diefu1sys(111, "set local fds non-blocking") ; - if (!random_init()) strerr_diefu1sys(111, "initialize random device") ; - sbearssl_server_init_and_run(fds, tto, preoptions, options, verbosity, notif ? &handshake_cb_sendvars : &handshake_cb_nop, notif) ; -} - -#else - -#error No SSL backend configured. - -#endif -#endif - - -#define USAGE "s6-tlsd-io [ -v verbosity ] [ -d notif ] [ -S | -s ] [ -Y | -y ] [ -K timeout ] fdr fdw" -#define dieusage() strerr_dieusage(100, USAGE) - -int main (int argc, char const *const *argv, char const *const *envp) -{ - tain_t tto ; - int fds[4] = { 0, 1, 0, 1 } ; - unsigned int verbosity = 1 ; - unsigned int notif = 0 ; - uint32_t preoptions = 0 ; - uint32_t options = 1 ; - - PROG = "s6-tlsd-io" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - unsigned int t = 0 ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "d:SsYyv:K:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; - case 'd' : if (!uint0_scan(l.arg, ¬if)) dieusage() ; break ; - case 'S' : options &= ~1 ; break ; - case 's' : options |= 1 ; break ; - case 'Y' : preoptions |= 1 ; preoptions &= ~2 ; break ; - case 'y' : preoptions |= 3 ; break ; - case 'K' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - if (t) tain_from_millisecs(&tto, t) ; else tto = tain_infinite_relative ; - } - if (argc < 2) dieusage() ; - { - unsigned int u ; - if (!uint0_scan(argv[0], &u)) dieusage() ; - fds[0] = u ; - if (!uint0_scan(argv[1], &u)) dieusage() ; - fds[1] = u ; - } - - if (ndelay_on(0) < 0 || ndelay_on(1) < 0) - strerr_diefu1sys(111, "set stdin/stdout non-blocking") ; - if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ; - tain_now_set_stopwatch_g() ; - doit(fds, &tto, preoptions, options, verbosity, notif) ; -} diff --git a/src/conn-tools/s6-tlsd.c b/src/conn-tools/s6-tlsd.c deleted file mode 100644 index 361502e..0000000 --- a/src/conn-tools/s6-tlsd.c +++ /dev/null @@ -1,72 +0,0 @@ -/* ISC license. */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "s6tls-internal.h" - -#define USAGE "s6-tlsd [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] prog..." -#define dieusage() strerr_dieusage(100, USAGE) - -static void child (int const [4][2], uint32_t, unsigned int, unsigned int) gccattr_noreturn ; -static void child (int const p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout) -{ - int fds[3] = { p[0][0], p[1][1], p[2][1] } ; - PROG = "s6-tlsd (child)" ; - close(p[2][0]) ; - close(p[0][1]) ; - close(p[1][0]) ; - s6tls_exec_tlsdio(fds, options, verbosity, kimeout) ; -} - -int main (int argc, char const *const *argv) -{ - unsigned int verbosity = 1 ; - unsigned int kimeout = 0 ; - int p[4][2] = { [3] = { 0, 1 } } ; - uint32_t coptions = 0 ; - uint32_t poptions = 1 ; - pid_t pid ; - - PROG = "s6-tlsd (parent)" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "SsYyv:K:Zz", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'S' : coptions |= 4 ; break ; - case 's' : coptions &= ~4 ; break ; - case 'Y' : coptions |= 1 ; coptions &= ~2 ; break ; - case 'y' : coptions |= 3 ; break ; - case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; - case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; - case 'Z' : poptions &= ~1 ; break ; - case 'z' : poptions |= 1 ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (!argc) dieusage() ; - - if (pipe(p[0]) < 0 || pipe(p[1]) < 0 || pipe(p[2]) < 0) - strerr_diefu1sys(111, "pipe") ; - pid = fork() ; - switch (pid) - { - case -1 : strerr_diefu1sys(111, "fork") ; - case 0 : child(p, coptions, verbosity, kimeout) ; - default : break ; - } - s6tls_sync_and_exec_app(argv, p, pid, poptions) ; -} diff --git a/src/conn-tools/s6-tlsserver.c b/src/conn-tools/s6-tlsserver.c deleted file mode 100644 index fb899eb..0000000 --- a/src/conn-tools/s6-tlsserver.c +++ /dev/null @@ -1,255 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define USAGE "s6-tlsserver [ -e ] [ options ] ip port prog...\n" \ -"s6-tcpserver options: [ -q | -Q | -v ] [ -4 | -6 ] [ -1 ] [ -c maxconn ] [ -C localmaxconn ] [ -b backlog ] [ -G gidlist ] [ -g gid ] [ -u uid ] [ -U ]\n" \ -"s6-tcpserver-access options: [ -W | -w ] [ -D | -d ] [ -H | -h ] [ -R | -r ] [ -P | -p ] [ -l localname ] [ -B banner ] [ -t timeout ] [ -i rulesdir | -x rulesfile ]\n" \ -"s6-tlsd options: [ -S | -s ] [ -Y | -y ] [ -K timeout ] [ -Z | -z ]" - -#define dieusage() strerr_dieusage(100, USAGE) - -typedef struct options_s options_t, *options_t_ref ; -struct options_s -{ - char const *localname ; - char const *banner ; - char const *rules ; - gid_t gids[NGROUPS_MAX] ; - size_t gidn ; - uid_t uid ; - gid_t gid ; - unsigned int maxconn ; - unsigned int localmaxconn ; - unsigned int backlog ; - unsigned int timeout ; - unsigned int kimeout ; - unsigned int verbosity : 2 ; - unsigned int flag46 : 2 ; - unsigned int flag1 : 1 ; - unsigned int flagU : 1 ; - unsigned int flagw : 1 ; - unsigned int flagD : 1 ; - unsigned int flagH : 1 ; - unsigned int flagr : 1 ; - unsigned int flagp : 1 ; - unsigned int ruleswhat : 2 ; - unsigned int flagS : 1 ; - unsigned int flagy : 1 ; - unsigned int flagZ : 1 ; - unsigned int onlyvars : 1 ; - unsigned int doaccess : 1 ; - unsigned int doapply : 1 ; -} ; - -#define OPTIONS_ZERO \ -{ \ - .localname = 0, \ - .banner = 0, \ - .rules = 0, \ - .backlog = (unsigned int)-1, \ - .gidn = (size_t)-1, \ - .uid = 0, \ - .gid = 0, \ - .maxconn = 0, \ - .localmaxconn = 0, \ - .timeout = 0, \ - .kimeout = 0, \ - .verbosity = 1, \ - .flag46 = 0, \ - .flag1 = 0, \ - .flagU = 0, \ - .flagw = 0, \ - .flagD = 0, \ - .flagH = 0, \ - .flagr = 0, \ - .flagp = 0, \ - .ruleswhat = 0, \ - .flagS = 0, \ - .flagy = 0, \ - .flagZ = 0, \ - .onlyvars = 0, \ - .doaccess = 0, \ - .doapply = 0 \ -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - options_t o = OPTIONS_ZERO ; - PROG = "s6-tlsserver" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "qQv461c:C:b:G:g:u:UWwDdHhRrPpleB:t:i:x:SsYyK:Zz", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'q' : o.verbosity = 0 ; break ; - case 'Q' : o.verbosity = 1 ; break ; - case 'v' : o.verbosity = 2 ; break ; - case '4' : o.flag46 = 1 ; break ; - case '6' : o.flag46 = 2 ; break ; - case '1' : o.flag1 = 1 ; break ; - case 'c' : if (!uint0_scan(l.arg, &o.maxconn)) dieusage() ; if (!o.maxconn) o.maxconn = 1 ; break ; - case 'C' : if (!uint0_scan(l.arg, &o.localmaxconn)) dieusage() ; if (!o.localmaxconn) o.localmaxconn = 1 ; break ; - case 'b' : if (!uint0_scan(l.arg, &o.backlog)) dieusage() ; break ; - case 'G' : if (!gid_scanlist(o.gids, NGROUPS_MAX, l.arg, &o.gidn) && *l.arg) dieusage() ; o.doapply = 1 ; break ; - case 'g' : if (!gid0_scan(l.arg, &o.gid)) dieusage() ; o.doapply = 1 ; break ; - case 'u' : if (!uid0_scan(l.arg, &o.uid)) dieusage() ; o.doapply = 1 ; break ; - case 'U' : o.flagU = 1 ; o.uid = 0 ; o.gid = 0 ; o.gidn = (size_t)-1 ; o.doapply = 1 ; break ; - case 'W' : o.flagw = 0 ; break ; - case 'w' : o.flagw = 1 ; break ; - case 'D' : o.flagD = 1 ; o.doaccess = 1 ; break ; - case 'd' : o.flagD = 0 ; break ; - case 'H' : o.flagH = 1 ; o.doaccess = 1 ; break ; - case 'h' : o.flagH = 0 ; break ; - case 'R' : o.flagr = 0 ; break ; - case 'r' : o.flagr = 1 ; o.doaccess = 1 ; break ; - case 'P' : o.flagp = 0 ; break ; - case 'p' : o.flagp = 1 ; o.doaccess = 1 ; break ; - case 'l' : o.localname = l.arg ; o.doaccess = 1 ; break ; - case 'e' : o.onlyvars = 1 ; o.doaccess = 1 ; break ; - case 'B' : o.banner = l.arg ; o.doaccess = 1 ; break ; - case 't' : if (!uint0_scan(l.arg, &o.timeout)) dieusage() ; break ; - case 'i' : o.rules = l.arg ; o.ruleswhat = 1 ; o.doaccess = 1 ; break ; - case 'x' : o.rules = l.arg ; o.ruleswhat = 2 ; o.doaccess = 1 ; break ; - case 'S' : o.flagS = 1 ; break ; - case 's' : o.flagS = 0 ; break ; - case 'Y' : o.flagy = 0 ; break ; - case 'y' : o.flagy = 1 ; break ; - case 'K' : if (!uint0_scan(l.arg, &o.kimeout)) dieusage() ; break ; - case 'Z' : o.flagZ = 1 ; break ; - case 'z' : o.flagZ = 0 ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - if (argc < 3) dieusage() ; - } - - { - size_t pos = 0 ; - unsigned int m = 0 ; - char fmt[UINT_FMT * 5 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; - char const *newargv[45 + argc] ; - newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver" ; - if (o.verbosity != 1) newargv[m++] = o.verbosity ? "-v" : "-q" ; - if (o.flag46) newargv[m++] = o.flag46 == 1 ? "-4" : "-6" ; - if (o.flag1) newargv[m++] = "-1" ; - if (o.maxconn) - { - newargv[m++] = "-c" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, o.maxconn) ; - fmt[pos++] = 0 ; - } - if (o.localmaxconn) - { - newargv[m++] = "-C" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, o.localmaxconn) ; - fmt[pos++] = 0 ; - } - if (o.backlog != (unsigned int)-1) - { - newargv[m++] = "-b" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, o.backlog) ; - fmt[pos++] = 0 ; - } - newargv[m++] = "--" ; - newargv[m++] = *argv++ ; - newargv[m++] = *argv++ ; - if (o.doaccess) - { - newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver-access" ; - if (o.verbosity) - { - if (o.verbosity > 1 && (!o.onlyvars || o.ruleswhat)) - newargv[m++] = "-v2" ; - } - else newargv[m++] = "-v0" ; - - if (o.flagw) newargv[m++] = "-w" ; - if (o.flagD) newargv[m++] = "-D" ; - if (o.flagH) newargv[m++] = "-H" ; - if (o.flagr) newargv[m++] = "-r" ; - if (o.flagp) newargv[m++] = "-p" ; - if (o.localname) - { - newargv[m++] = "-l" ; - newargv[m++] = o.localname ; - } - if (o.banner) - { - newargv[m++] = "-B" ; - newargv[m++] = o.banner ; - } - if (o.timeout) - { - newargv[m++] = "-t" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, o.timeout) ; - fmt[pos++] = 0 ; - } - if (o.ruleswhat) - { - newargv[m++] = o.ruleswhat == 1 ? "-i" : "-x" ; - newargv[m++] = o.rules ; - } - newargv[m++] = "--" ; - } - newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsd" ; - if (o.verbosity != 1) - newargv[m++] = o.verbosity ? "-v2" : "-v0" ; - if (o.flagS) newargv[m++] = "-S" ; - if (o.flagy) newargv[m++] = "-y" ; - if (o.kimeout) - { - newargv[m++] = "-K" ; - newargv[m++] = fmt + pos ; - pos += uint_fmt(fmt + pos, o.kimeout) ; - fmt[pos++] = 0 ; - } - if (o.flagZ) newargv[m++] = "-Z" ; - newargv[m++] = "--" ; - if (o.doapply) - { - newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ; - if (o.gidn != (size_t)-1) - { - newargv[m++] = "-G" ; - newargv[m++] = fmt + pos ; - pos += gid_fmtlist(fmt + pos, o.gids, o.gidn) ; - fmt[pos++] = 0 ; - } - if (o.gid) - { - newargv[m++] = "-g" ; - newargv[m++] = fmt + pos ; - pos += gid_fmt(fmt + pos, o.gid) ; - fmt[pos++] = 0 ; - } - if (o.uid) - { - newargv[m++] = "-u" ; - newargv[m++] = fmt + pos ; - pos += uid_fmt(fmt + pos, o.uid) ; - fmt[pos++] = 0 ; - } - if (o.flagU) newargv[m++] = "-Uz" ; - newargv[m++] = "--" ; - } - while (*argv) newargv[m++] = *argv++ ; - newargv[m++] = 0 ; - xpathexec_run(newargv[0], newargv, envp) ; - } -} diff --git a/src/conn-tools/s6-ucspitlsc.c b/src/conn-tools/s6-ucspitlsc.c deleted file mode 100644 index 92660eb..0000000 --- a/src/conn-tools/s6-ucspitlsc.c +++ /dev/null @@ -1,109 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include "s6tls-internal.h" - -#define USAGE "s6-ucspitlsc [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] [ -k servername ] [ -6 fdr ] [ -7 fdw ] prog..." -#define dieusage() strerr_dieusage(100, USAGE) - -static inline void child (int [4][2], uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ; -static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername) -{ - int fds[3] = { p[0][0], p[1][1], p[2][1] } ; - ssize_t r ; - char c ; - PROG = "s6-ucspitlsc" ; - close(p[2][0]) ; - close(p[0][1]) ; - close(p[1][0]) ; - if (fd_move(0, p[3][0]) < 0 || fd_move(1, p[3][1]) < 0) - strerr_diefu1sys(111, "move network fds to stdin/stdout") ; - r = read(p[2][1], &c, 1) ; - if (r < 0) strerr_diefu1sys(111, "read from control socket") ; - if (!r) _exit(0) ; - switch (c) - { - case 'y' : - close(p[2][1]) ; - p[2][1] = 0 ; /* we know 0 is open so it's a correct invalid value */ - case 'Y' : - fd_shutdown(p[2][1], 0) ; - break ; - default : - strerr_dief1x(100, "unrecognized command on control socket") ; - } - s6tls_exec_tlscio(fds, options, verbosity, kimeout, servername) ; -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - unsigned int verbosity = 1 ; - unsigned int kimeout = 0 ; - int p[4][2] = { [3] = { 6, 7 } } ; - uint32_t coptions = 0 ; - uint32_t poptions = 1 ; - char const *servername = 0 ; - - PROG = "s6-ucspitlsc (parent)" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "SsYyv:K:Zzk:6:7:", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'S' : coptions |= 4 ; break ; - case 's' : coptions &= ~4 ; break ; - case 'Y' : coptions |= 1 ; coptions &= ~2 ; break ; - case 'y' : coptions |= 3 ; break ; - case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; - case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; - case 'Z' : poptions &= ~1 ; break ; - case 'z' : poptions |= 1 ; break ; - case 'k' : servername = l.arg ; break ; - case '6' : - { - unsigned int fd ; - if (!uint0_scan(l.arg, &fd)) dieusage() ; - p[3][0] = fd ; - break ; - } - case '7' : - { - unsigned int fd ; - if (!uint0_scan(l.arg, &fd)) dieusage() ; - p[3][1] = fd ; - break ; - } - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (!argc) dieusage() ; - fd_sanitize() ; - if (fcntl(p[3][0], F_GETFD) < 0 || fcntl(p[3][1], F_GETFD) < 0) - strerr_diefu1sys(111, "check network fds") ; - - if (ipc_pair_b(p[2]) < 0) strerr_diefu1sys(111, "ipc_pair") ; - if (pipe(p[0]) < 0 || pipe(p[1]) < 0) strerr_diefu1sys(111, "pipe") ; - switch (fork()) - { - case -1 : strerr_diefu1sys(111, "fork") ; - case 0 : child(p, coptions, verbosity, kimeout, servername) ; - default : break ; - } - s6tls_ucspi_exec_app(argv, p, poptions) ; -} diff --git a/src/conn-tools/s6-ucspitlsd.c b/src/conn-tools/s6-ucspitlsd.c deleted file mode 100644 index 4bfa253..0000000 --- a/src/conn-tools/s6-ucspitlsd.c +++ /dev/null @@ -1,88 +0,0 @@ -/* ISC license. */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include "s6tls-internal.h" - -#define USAGE "s6-ucspitlsd [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] prog..." -#define dieusage() strerr_dieusage(100, USAGE) - -static inline void child (int [4][2], uint32_t, unsigned int, unsigned int) gccattr_noreturn ; -static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout) -{ - int fds[3] = { p[0][0], p[1][1], p[2][1] } ; - ssize_t r ; - char c ; - PROG = "s6-ucspitlsd" ; - close(p[2][0]) ; - close(p[0][1]) ; - close(p[1][0]) ; - r = read(p[2][1], &c, 1) ; - if (r < 0) strerr_diefu1sys(111, "read from control socket") ; - if (!r) _exit(0) ; - switch (c) - { - case 'y' : - close(p[2][1]) ; - p[2][1] = 0 ; /* we know 0 is open so it's a correct invalid value */ - case 'Y' : - fd_shutdown(p[2][1], 0) ; - break ; - default : - strerr_dief1x(100, "unrecognized command on control socket") ; - } - s6tls_exec_tlsdio(fds, options, verbosity, kimeout) ; -} - -int main (int argc, char const *const *argv, char const *const *envp) -{ - unsigned int verbosity = 1 ; - unsigned int kimeout = 0 ; - int p[4][2] = { [3] = { 0, 1 } } ; - uint32_t coptions = 0 ; - uint32_t poptions = 1 ; - - PROG = "s6-ucspitlsd (parent)" ; - { - subgetopt_t l = SUBGETOPT_ZERO ; - for (;;) - { - int opt = subgetopt_r(argc, argv, "SsYyv:K:Zz", &l) ; - if (opt == -1) break ; - switch (opt) - { - case 'S' : coptions |= 4 ; break ; - case 's' : coptions &= ~4 ; break ; - case 'Y' : coptions |= 1 ; coptions &= ~2 ; break ; - case 'y' : coptions |= 3 ; break ; - case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; - case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; - case 'Z' : poptions &= ~1 ; break ; - case 'z' : poptions |= 1 ; break ; - default : dieusage() ; - } - } - argc -= l.ind ; argv += l.ind ; - } - if (!argc) dieusage() ; - - if (ipc_pair_b(p[2]) < 0) strerr_diefu1sys(111, "ipc_pair") ; - if (pipe(p[0]) < 0 || pipe(p[1]) < 0) strerr_diefu1sys(111, "pipe") ; - - switch (fork()) - { - case -1 : strerr_diefu1sys(111, "fork") ; - case 0 : child(p, coptions, verbosity, kimeout) ; - default : break ; - } - s6tls_ucspi_exec_app(argv, p, poptions) ; -} diff --git a/src/conn-tools/s6tls-internal.h b/src/conn-tools/s6tls-internal.h deleted file mode 100644 index 09be544..0000000 --- a/src/conn-tools/s6tls-internal.h +++ /dev/null @@ -1,18 +0,0 @@ -/* ISC license */ - -#ifndef S6TLS_INTERNAL_H -#define S6TLS_INTERNAL_H - -#include -#include - -#include - -#define s6tls_envvars "CADIR\0CAFILE\0KEYFILE\0CERTFILE\0TLS_UID\0TLS_GID" - -extern void s6tls_exec_tlscio (int const *, uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ; -extern void s6tls_exec_tlsdio (int const *, uint32_t, unsigned int, unsigned int) gccattr_noreturn ; -extern void s6tls_sync_and_exec_app (char const *const *, int const [4][2], pid_t, uint32_t) gccattr_noreturn ; -extern void s6tls_ucspi_exec_app (char const *const *, int const [4][2], uint32_t) gccattr_noreturn ; - -#endif diff --git a/src/conn-tools/s6tls_exec_tlscio.c b/src/conn-tools/s6tls_exec_tlscio.c deleted file mode 100644 index ad00ecd..0000000 --- a/src/conn-tools/s6tls_exec_tlscio.c +++ /dev/null @@ -1,53 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -#include -#include "s6tls-internal.h" - -void s6tls_exec_tlscio (int const *fds, uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername) -{ - char const *newargv[15] ; - unsigned int m = 0 ; - char fmtv[UINT_FMT] ; - char fmtd[UINT_FMT] ; - char fmtk[UINT_FMT] ; - char fmtr[UINT_FMT] ; - char fmtw[UINT_FMT] ; - - newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsc-io" ; - if (verbosity != 1) - { - newargv[m++] = "-v" ; - newargv[m++] = fmtv ; - fmtv[uint_fmt(fmtv, verbosity)] = 0 ; - } - if (fds[2]) - { - newargv[m++] = "-d" ; - newargv[m++] = fmtd ; - fmtd[uint_fmt(fmtd, fds[2])] = 0 ; - } - newargv[m++] = options & 4 ? "-S" : "-s" ; - newargv[m++] = options & 1 ? "-y" : "-Y" ; - if (kimeout) - { - newargv[m++] = "-K" ; - newargv[m++] = fmtk ; - fmtk[uint_fmt(fmtk, kimeout)] = 0 ; - } - if (servername) - { - newargv[m++] = "-k" ; - newargv[m++] = servername ; - } - newargv[m++] = "--" ; - newargv[m++] = fmtr ; - fmtr[uint_fmt(fmtr, fds[0])] = 0 ; - newargv[m++] = fmtw ; - fmtw[uint_fmt(fmtw, fds[1])] = 0 ; - newargv[m++] = 0 ; - xpathexec_run(newargv[0], newargv, (char const *const *)environ) ; -} diff --git a/src/conn-tools/s6tls_exec_tlsdio.c b/src/conn-tools/s6tls_exec_tlsdio.c deleted file mode 100644 index b00adb2..0000000 --- a/src/conn-tools/s6tls_exec_tlsdio.c +++ /dev/null @@ -1,49 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -#include -#include "s6tls-internal.h" - -void s6tls_exec_tlsdio (int const *fds, uint32_t options, unsigned int verbosity, unsigned int kimeout) -{ - char const *newargv[13] ; - unsigned int m = 0 ; - char fmtv[UINT_FMT] ; - char fmtd[UINT_FMT] ; - char fmtk[UINT_FMT] ; - char fmtr[UINT_FMT] ; - char fmtw[UINT_FMT] ; - - newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsd-io" ; - if (verbosity != 1) - { - newargv[m++] = "-v" ; - newargv[m++] = fmtv ; - fmtv[uint_fmt(fmtv, verbosity)] = 0 ; - } - if (fds[2]) - { - newargv[m++] = "-d" ; - newargv[m++] = fmtd ; - fmtd[uint_fmt(fmtd, fds[2])] = 0 ; - } - newargv[m++] = options & 4 ? "-S" : "-s" ; - if (options & 1) - newargv[m++] = options & 2 ? "-y" : "-Y" ; - if (kimeout) - { - newargv[m++] = "-K" ; - newargv[m++] = fmtk ; - fmtk[uint_fmt(fmtk, kimeout)] = 0 ; - } - newargv[m++] = "--" ; - newargv[m++] = fmtr ; - fmtr[uint_fmt(fmtr, fds[0])] = 0 ; - newargv[m++] = fmtw ; - fmtw[uint_fmt(fmtw, fds[1])] = 0 ; - newargv[m++] = 0 ; - xpathexec_run(newargv[0], newargv, (char const *const *)environ) ; -} diff --git a/src/conn-tools/s6tls_sync_and_exec_app.c b/src/conn-tools/s6tls_sync_and_exec_app.c deleted file mode 100644 index 4ae63fa..0000000 --- a/src/conn-tools/s6tls_sync_and_exec_app.c +++ /dev/null @@ -1,43 +0,0 @@ -/* ISC license. */ - -#include -#include - -#include -#include -#include -#include - -#include "s6tls-internal.h" - -#define MAXENVSIZE 2048 - -void s6tls_sync_and_exec_app (char const *const *argv, int const p[4][2], pid_t pid, uint32_t options) -{ - char buf[sizeof(s6tls_envvars) + MAXENVSIZE] ; - size_t m = 0 ; - ssize_t r ; - close(p[2][1]) ; - close(p[1][1]) ; - close(p[0][0]) ; - if (fd_move(p[3][0], p[1][0]) < 0 || fd_move(p[3][1], p[0][1]) < 0) - strerr_diefu1sys(111, "move file descriptors") ; - if (options & 1) - { - memcpy(buf + m, s6tls_envvars, sizeof(s6tls_envvars)) ; - m += sizeof(s6tls_envvars) ; - } - r = read(p[2][0], buf + m, MAXENVSIZE) ; - if (r < 0) strerr_diefu1sys(111, "read from handshake notification pipe") ; - if (!r) - { - int wstat ; - if (wait_pid(pid, &wstat) < 0) - strerr_diefu1sys(111, "wait") ; - _exit(wait_estatus(wstat)) ; - } - if (r >= MAXENVSIZE) - strerr_dief1x(100, "SSL data too large") ; - m += r - 1 ; - xpathexec_r(argv, (char const *const *)environ, env_len((char const *const *)environ), buf, m) ; -} diff --git a/src/conn-tools/s6tls_ucspi_exec_app.c b/src/conn-tools/s6tls_ucspi_exec_app.c deleted file mode 100644 index f4b52ef..0000000 --- a/src/conn-tools/s6tls_ucspi_exec_app.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -#include -#include -#include -#include - -#include "s6tls-internal.h" - -void s6tls_ucspi_exec_app (char const *const *argv, int const p[4][2], uint32_t options) -{ - size_t m = 0 ; - char modif[sizeof(s6tls_envvars) + 33 + 3 * UINT_FMT] ; - close(p[2][1]) ; - close(p[1][1]) ; - close(p[0][0]) ; - if (options & 1) - { - memcpy(modif + m, s6tls_envvars, sizeof(s6tls_envvars)) ; - m += sizeof(s6tls_envvars) ; - } - memcpy(modif + m, "SSLCTLFD=", 9) ; m += 9 ; - m += uint_fmt(modif + m, p[2][0]) ; - modif[m++] = 0 ; - memcpy(modif + m, "SSLREADFD=", 10) ; m += 10 ; - m += uint_fmt(modif + m, p[1][0]) ; - modif[m++] = 0 ; - memcpy(modif + m, "SSLWRITEFD=", 11) ; m += 11 ; - m += uint_fmt(modif + m, p[0][1]) ; - modif[m++] = 0 ; - xpathexec_r(argv, (char const *const *)environ, env_len((char const* const *)environ), modif, m) ; -} diff --git a/src/tls/deps-exe/s6-tlsc b/src/tls/deps-exe/s6-tlsc new file mode 100644 index 0000000..37405fd --- /dev/null +++ b/src/tls/deps-exe/s6-tlsc @@ -0,0 +1,2 @@ +libs6tls.a.xyzzy +-lskarnet diff --git a/src/tls/deps-exe/s6-tlsc-io b/src/tls/deps-exe/s6-tlsc-io new file mode 100644 index 0000000..3e2653d --- /dev/null +++ b/src/tls/deps-exe/s6-tlsc-io @@ -0,0 +1,5 @@ +${LIBCRYPTOSUPPORT} +-lskarnet +${CRYPTO_LIB} +${SOCKET_LIB} +${SYSCLOCK_LIB} diff --git a/src/tls/deps-exe/s6-tlsclient b/src/tls/deps-exe/s6-tlsclient new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/tls/deps-exe/s6-tlsclient @@ -0,0 +1 @@ +-lskarnet diff --git a/src/tls/deps-exe/s6-tlsd b/src/tls/deps-exe/s6-tlsd new file mode 100644 index 0000000..37405fd --- /dev/null +++ b/src/tls/deps-exe/s6-tlsd @@ -0,0 +1,2 @@ +libs6tls.a.xyzzy +-lskarnet diff --git a/src/tls/deps-exe/s6-tlsd-io b/src/tls/deps-exe/s6-tlsd-io new file mode 100644 index 0000000..3e2653d --- /dev/null +++ b/src/tls/deps-exe/s6-tlsd-io @@ -0,0 +1,5 @@ +${LIBCRYPTOSUPPORT} +-lskarnet +${CRYPTO_LIB} +${SOCKET_LIB} +${SYSCLOCK_LIB} diff --git a/src/tls/deps-exe/s6-tlsserver b/src/tls/deps-exe/s6-tlsserver new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/tls/deps-exe/s6-tlsserver @@ -0,0 +1 @@ +-lskarnet diff --git a/src/tls/deps-exe/s6-ucspitlsc b/src/tls/deps-exe/s6-ucspitlsc new file mode 100644 index 0000000..ac1b327 --- /dev/null +++ b/src/tls/deps-exe/s6-ucspitlsc @@ -0,0 +1,3 @@ +libs6tls.a.xyzzy +-lskarnet +${SOCKET_LIB} diff --git a/src/tls/deps-exe/s6-ucspitlsd b/src/tls/deps-exe/s6-ucspitlsd new file mode 100644 index 0000000..ac1b327 --- /dev/null +++ b/src/tls/deps-exe/s6-ucspitlsd @@ -0,0 +1,3 @@ +libs6tls.a.xyzzy +-lskarnet +${SOCKET_LIB} diff --git a/src/tls/deps-lib/s6tls b/src/tls/deps-lib/s6tls new file mode 100644 index 0000000..f392de5 --- /dev/null +++ b/src/tls/deps-lib/s6tls @@ -0,0 +1,4 @@ +s6tls_exec_tlscio.o +s6tls_exec_tlsdio.o +s6tls_sync_and_exec_app.o +s6tls_ucspi_exec_app.o diff --git a/src/tls/s6-tlsc-io.c b/src/tls/s6-tlsc-io.c new file mode 100644 index 0000000..79dd25d --- /dev/null +++ b/src/tls/s6-tlsc-io.c @@ -0,0 +1,128 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define HANDSHAKE_BANNER "SSL_PROTOCOL=TLSv1\0" + +static inline void doit (int *, tain_t const *tto, uint32_t, uint32_t, unsigned int, char const *, unsigned int) gccattr_noreturn ; + +#ifdef S6_NETWORKING_USE_TLS + +#include + +static inline void doit (int *fds, tain_t const *tto, uint32_t preoptions, uint32_t options, unsigned int verbosity, char const *servername, unsigned int notif) +{ + struct tls *ctx = stls_client_init_and_handshake(fds + 2, preoptions, servername) ; + if (notif) + { + if (allwrite(notif, HANDSHAKE_BANNER, sizeof(HANDSHAKE_BANNER)) < sizeof(HANDSHAKE_BANNER)) + strerr_diefu1sys(111, "write post-handshake data") ; + fd_close(notif) ; + } + stls_run(ctx, fds, tto, options, verbosity) ; +} + +#else +#ifdef S6_NETWORKING_USE_BEARSSL + +#include + +#include + +static int handshake_cb_nop (br_ssl_engine_context *ctx, sbearssl_handshake_cb_context_t *cbarg) +{ + (void)ctx ; + (void)cbarg ; + return 1 ; +} + +static int handshake_cb_sendvars (br_ssl_engine_context *ctx, sbearssl_handshake_cb_context_t *cbarg) +{ + if (allwrite(cbarg->notif, HANDSHAKE_BANNER, sizeof(HANDSHAKE_BANNER)) < sizeof(HANDSHAKE_BANNER)) + return 0 ; + fd_close(cbarg->notif) ; + return 1 ; +} + +static inline void doit (int *fds, tain_t const *tto, uint32_t preoptions, uint32_t options, unsigned int verbosity, char const *servername, unsigned int notif) +{ + if (ndelay_on(fds[0]) < 0 || ndelay_on(fds[1]) < 0) + strerr_diefu1sys(111, "set local fds non-blocking") ; + if (!random_init()) strerr_diefu1sys(111, "initialize random device") ; + sbearssl_client_init_and_run(fds, tto, preoptions, options, verbosity, servername, notif ? &handshake_cb_sendvars : &handshake_cb_nop, notif) ; +} + +#else + +#error No SSL backend configured. + +#endif +#endif + + +#define USAGE "s6-tlsc-io [ -v verbosity ] [ -d notif ] [ -S | -s ] [ -Y | -y ] [ -K timeout ] [ -k servername ] fdr fdw" +#define dieusage() strerr_dieusage(100, USAGE) + +int main (int argc, char const *const *argv, char const *const *envp) +{ + char const *servername = 0 ; + tain_t tto ; + int fds[4] = { 0, 1, 0, 1 } ; + unsigned int verbosity = 1 ; + unsigned int notif = 0 ; + uint32_t preoptions = 0 ; + uint32_t options = 1 ; + + PROG = "s6-tlsc-io" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + unsigned int t = 0 ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "d:SsYyv:K:k:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; + case 'd' : if (!uint0_scan(l.arg, ¬if)) dieusage() ; break ; + case 'S' : options &= ~1 ; break ; + case 's' : options |= 1 ; break ; + case 'Y' : preoptions &= ~1 ; break ; + case 'y' : preoptions |= 1 ; break ; + case 'K' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; + case 'k' : servername = l.arg ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + if (t) tain_from_millisecs(&tto, t) ; else tto = tain_infinite_relative ; + } + if (argc < 2) dieusage() ; + { + unsigned int u ; + if (!uint0_scan(argv[0], &u)) dieusage() ; + fds[0] = u ; + if (!uint0_scan(argv[1], &u)) dieusage() ; + fds[1] = u ; + } + + if (ndelay_on(0) < 0 || ndelay_on(1) < 0) + strerr_diefu1sys(111, "set stdin/stdout non-blocking") ; + if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ; + tain_now_set_stopwatch_g() ; + doit(fds, &tto, preoptions, options, verbosity, servername, notif) ; +} diff --git a/src/tls/s6-tlsc.c b/src/tls/s6-tlsc.c new file mode 100644 index 0000000..5b2e7dc --- /dev/null +++ b/src/tls/s6-tlsc.c @@ -0,0 +1,94 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "s6tls-internal.h" + +#define USAGE "s6-tlsc [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -k servername ] [ -Z | -z ] [ -6 fdr ] [ -7 fdw ] prog..." +#define dieusage() strerr_dieusage(100, USAGE) + +static void child (int const [4][2], uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ; +static void child (int const p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername) +{ + int fds[3] = { p[0][0], p[1][1], p[2][1] } ; + PROG = "s6-tlsc (child)" ; + close(p[2][0]) ; + close(p[0][1]) ; + close(p[1][0]) ; + if (fd_move(0, p[3][0]) < 0 || fd_move(1, p[3][1]) < 0) + strerr_diefu1sys(111, "move network fds to stdin/stdout") ; + s6tls_exec_tlscio(fds, options, verbosity, kimeout, servername) ; +} + +int main (int argc, char const *const *argv) +{ + unsigned int verbosity = 1 ; + unsigned int kimeout = 0 ; + int p[4][2] ; + uint32_t coptions = 0 ; + uint32_t poptions = 1 ; + pid_t pid ; + char const *servername = 0 ; + + PROG = "s6-tlsc" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "SsYyv:K:k:Zz6:7:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'S' : coptions &= ~4 ; break ; + case 's' : coptions |= 4 ; break ; + case 'Y' : coptions &= ~1 ; break ; + case 'y' : coptions |= 1 ; break ; + case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; + case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; + case 'k' : servername = l.arg ; break ; + case 'Z' : poptions &= ~1 ; break ; + case 'z' : poptions |= 1 ; break ; + case '6' : + { + unsigned int fd ; + if (!uint0_scan(l.arg, &fd)) dieusage() ; + p[3][0] = fd ; + break ; + } + case '7' : + { + unsigned int fd ; + if (!uint0_scan(l.arg, &fd)) dieusage() ; + p[3][1] = fd ; + break ; + } + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (!argc) dieusage() ; + fd_sanitize() ; + if (fcntl(p[3][0], F_GETFD) < 0 || fcntl(p[3][1], F_GETFD) < 0) + strerr_diefu1sys(111, "check network fds") ; + + if (pipe(p[0]) < 0 || pipe(p[1]) < 0 || pipe(p[2]) < 0) + strerr_diefu1sys(111, "pipe") ; + pid = fork() ; + switch (pid) + { + case -1 : strerr_diefu1sys(111, "fork") ; + case 0 : child(p, coptions, verbosity, kimeout, servername) ; + default : break ; + } + s6tls_sync_and_exec_app(argv, p, pid, poptions) ; +} diff --git a/src/tls/s6-tlsclient.c b/src/tls/s6-tlsclient.c new file mode 100644 index 0000000..267f457 --- /dev/null +++ b/src/tls/s6-tlsclient.c @@ -0,0 +1,202 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define USAGE "s6-tlsclient [ options ] host port prog...\n" \ +"s6-tcpclient options: [ -q | -Q | -v ] [ -4 | -6 ] [ -d | -D ] [ -r | -R ] [ -h | -H ] [ -n | -N ] [ -t timeout ] [ -l localname ] [ -T timeoutconn ] [ -i localip ] [ -p localport ]\n" \ +"s6-tlsc options: [ -S | -s ] [ -Y | -y ] [ -K timeout ] [ -k servername ] [ -Z | -z ]" + +#define dieusage() strerr_dieusage(100, USAGE) + +typedef struct options_s options_t, *options_t_ref ; +struct options_s +{ + char const *localname ; + char const *servername ; + unsigned int timeout ; + unsigned int ximeout ; + unsigned int yimeout ; + unsigned int kimeout ; + uint16_t localport ; + ip46full_t localip ; + unsigned int verbosity : 2 ; + unsigned int flag4 : 1 ; + unsigned int flag6 : 1 ; + unsigned int flagD : 1 ; + unsigned int flagH : 1 ; + unsigned int flagr : 1 ; + unsigned int flagN : 1 ; + unsigned int flagS : 1 ; + unsigned int flagy : 1 ; + unsigned int flagZ : 1 ; + unsigned int doxy : 1 ; +} ; + +#define OPTIONS_ZERO \ +{ \ + .localname = 0, \ + .servername = 0, \ + .timeout = 0, \ + .ximeout = 2, \ + .yimeout = 58, \ + .kimeout = 0, \ + .localport = 0, \ + .localip = IP46FULL_ZERO, \ + .verbosity = 1, \ + .flag4 = 0, \ + .flag6 = 0, \ + .flagD = 0, \ + .flagH = 0, \ + .flagr = 0, \ + .flagN = 0, \ + .flagS = 0, \ + .flagy = 0, \ + .flagZ = 0, \ + .doxy = 0 \ +} + +int main (int argc, char const *const *argv, char const *const *envp) +{ + options_t o = OPTIONS_ZERO ; + PROG = "s6-tlsclient" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "qQv46DdHhRrnNt:l:T:i:p:SsYyK:k:Zz", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'q' : o.verbosity = 0 ; break ; + case 'Q' : o.verbosity = 1 ; break ; + case 'v' : o.verbosity = 2 ; break ; + case '4' : o.flag4 = 1 ; break ; + case '6' : o.flag6 = 1 ; break ; + case 'D' : o.flagD = 1 ; break ; + case 'd' : o.flagD = 0 ; break ; + case 'H' : o.flagH = 1 ; break ; + case 'h' : o.flagH = 0 ; break ; + case 'R' : o.flagr = 0 ; break ; + case 'r' : o.flagr = 1 ; break ; + case 'n' : o.flagN = 0 ; break ; + case 'N' : o.flagN = 1 ; break ; + case 't' : if (!uint0_scan(l.arg, &o.timeout)) dieusage() ; break ; + case 'l' : o.localname = l.arg ; break ; + case 'T' : + { + size_t n = uint_scan(l.arg, &o.ximeout) ; + if (!n) dieusage() ; + o.doxy = 1 ; + if (!l.arg[n]) + { + o.yimeout = 0 ; + break ; + } + if (l.arg[n] != '+') dieusage() ; + if (!uint0_scan(l.arg + n + 1, &o.yimeout)) dieusage() ; + break ; + } + case 'i' : if (!ip46full_scan(l.arg, &o.localip)) dieusage() ; break ; + case 'p' : if (!uint160_scan(l.arg, &o.localport)) dieusage() ; break ; + case 'S' : o.flagS = 1 ; break ; + case 's' : o.flagS = 0 ; break ; + case 'Y' : o.flagy = 0 ; break ; + case 'y' : o.flagy = 1 ; break ; + case 'K' : if (!uint0_scan(l.arg, &o.kimeout)) dieusage() ; break ; + case 'k' : o.servername = l.arg ; break ; + case 'Z' : o.flagZ = 1 ; break ; + case 'z' : o.flagZ = 0 ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + if (argc < 3) dieusage() ; + } + + if (!o.servername && !o.flagH) + { + ip46full_t ip ; + if (!ip46full_scan(argv[0], &ip)) + o.servername = argv[0] ; + } + + { + size_t pos = 0 ; + unsigned int m = 0 ; + char fmt[UINT_FMT * 4 + UINT16_FMT + IP46_FMT] ; + char const *newargv[29 + argc] ; + newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpclient" ; + if (o.verbosity != 1) newargv[m++] = o.verbosity ? "-v" : "-q" ; + if (o.flag4) newargv[m++] = "-4" ; + if (o.flag6) newargv[m++] = "-6" ; + if (o.flagD) newargv[m++] = "-D" ; + if (o.flagH) newargv[m++] = "-H" ; + if (o.flagr) newargv[m++] = "-r" ; + if (o.flagN) newargv[m++] = "-N" ; + if (o.timeout) + { + newargv[m++] = "-t" ; + newargv[m++] = fmt + pos ; + pos += uint_fmt(fmt + pos, o.timeout) ; + fmt[pos++] = 0 ; + } + if (o.localname) + { + newargv[m++] = "-l" ; + newargv[m++] = o.localname ; + } + if (o.doxy) + { + newargv[m++] = "-T" ; + newargv[m++] = fmt + pos ; + pos += uint_fmt(fmt + pos, o.ximeout) ; + fmt[pos++] = '+' ; + pos += uint_fmt(fmt + pos, o.yimeout) ; + fmt[pos++] = 0 ; + } + if (memcmp(o.localip.ip, IP6_ANY, 16)) + { + newargv[m++] = "-i" ; + newargv[m++] = fmt + pos ; + pos += ip46full_fmt(fmt + pos, &o.localip) ; + fmt[pos++] = 0 ; + } + if (o.localport) + { + newargv[m++] = "-p" ; + newargv[m++] = fmt + pos ; + pos += uint16_fmt(fmt + pos, o.localport) ; + fmt[pos++] = 0 ; + } + newargv[m++] = "--" ; + newargv[m++] = *argv++ ; + newargv[m++] = *argv++ ; + newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsc" ; + if (o.flagS) newargv[m++] = "-S" ; + if (o.flagy) newargv[m++] = "-y" ; + if (o.kimeout) + { + newargv[m++] = "-K" ; + newargv[m++] = fmt + pos ; + pos += uint_fmt(fmt + pos, o.kimeout) ; + fmt[pos++] = 0 ; + } + if (o.servername) + { + newargv[m++] = "-k" ; + newargv[m++] = o.servername ; + } + if (o.flagZ) newargv[m++] = "-Z" ; + newargv[m++] = "--" ; + while (*argv) newargv[m++] = *argv++ ; + newargv[m++] = 0 ; + xpathexec_run(newargv[0], newargv, envp) ; + } +} diff --git a/src/tls/s6-tlsd-io.c b/src/tls/s6-tlsd-io.c new file mode 100644 index 0000000..0b42b3b --- /dev/null +++ b/src/tls/s6-tlsd-io.c @@ -0,0 +1,126 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define HANDSHAKE_BANNER "SSL_PROTOCOL=TLSv1\0" + +static inline void doit (int *, tain_t const *tto, uint32_t, uint32_t, unsigned int, unsigned int) gccattr_noreturn ; + +#ifdef S6_NETWORKING_USE_TLS + +#include + +static inline void doit (int *fds, tain_t const *tto, uint32_t preoptions, uint32_t options, unsigned int verbosity, unsigned int notif) +{ + struct tls *ctx = stls_server_init_and_handshake(fds + 2, preoptions) ; + if (notif) + { + if (allwrite(notif, HANDSHAKE_BANNER, sizeof(HANDSHAKE_BANNER)) < sizeof(HANDSHAKE_BANNER)) + strerr_diefu1sys(111, "write post-handshake data") ; + fd_close(notif) ; + } + stls_run(ctx, fds, tto, options, verbosity) ; +} + +#else +#ifdef S6_NETWORKING_USE_BEARSSL + +#include + +#include + +static int handshake_cb_nop (br_ssl_engine_context *ctx, sbearssl_handshake_cb_context_t *cbarg) +{ + (void)ctx ; + (void)cbarg ; + return 1 ; +} + +static int handshake_cb_sendvars (br_ssl_engine_context *ctx, sbearssl_handshake_cb_context_t *cbarg) +{ + if (allwrite(cbarg->notif, HANDSHAKE_BANNER, sizeof(HANDSHAKE_BANNER)) < sizeof(HANDSHAKE_BANNER)) + return 0 ; + fd_close(cbarg->notif) ; + return 1 ; +} + +static inline void doit (int *fds, tain_t const *tto, uint32_t preoptions, uint32_t options, unsigned int verbosity, unsigned int notif) +{ + if (ndelay_on(fds[0]) < 0 || ndelay_on(fds[1]) < 0) + strerr_diefu1sys(111, "set local fds non-blocking") ; + if (!random_init()) strerr_diefu1sys(111, "initialize random device") ; + sbearssl_server_init_and_run(fds, tto, preoptions, options, verbosity, notif ? &handshake_cb_sendvars : &handshake_cb_nop, notif) ; +} + +#else + +#error No SSL backend configured. + +#endif +#endif + + +#define USAGE "s6-tlsd-io [ -v verbosity ] [ -d notif ] [ -S | -s ] [ -Y | -y ] [ -K timeout ] fdr fdw" +#define dieusage() strerr_dieusage(100, USAGE) + +int main (int argc, char const *const *argv, char const *const *envp) +{ + tain_t tto ; + int fds[4] = { 0, 1, 0, 1 } ; + unsigned int verbosity = 1 ; + unsigned int notif = 0 ; + uint32_t preoptions = 0 ; + uint32_t options = 1 ; + + PROG = "s6-tlsd-io" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + unsigned int t = 0 ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "d:SsYyv:K:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; + case 'd' : if (!uint0_scan(l.arg, ¬if)) dieusage() ; break ; + case 'S' : options &= ~1 ; break ; + case 's' : options |= 1 ; break ; + case 'Y' : preoptions |= 1 ; preoptions &= ~2 ; break ; + case 'y' : preoptions |= 3 ; break ; + case 'K' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + if (t) tain_from_millisecs(&tto, t) ; else tto = tain_infinite_relative ; + } + if (argc < 2) dieusage() ; + { + unsigned int u ; + if (!uint0_scan(argv[0], &u)) dieusage() ; + fds[0] = u ; + if (!uint0_scan(argv[1], &u)) dieusage() ; + fds[1] = u ; + } + + if (ndelay_on(0) < 0 || ndelay_on(1) < 0) + strerr_diefu1sys(111, "set stdin/stdout non-blocking") ; + if (sig_ignore(SIGPIPE) < 0) strerr_diefu1sys(111, "ignore SIGPIPE") ; + tain_now_set_stopwatch_g() ; + doit(fds, &tto, preoptions, options, verbosity, notif) ; +} diff --git a/src/tls/s6-tlsd.c b/src/tls/s6-tlsd.c new file mode 100644 index 0000000..361502e --- /dev/null +++ b/src/tls/s6-tlsd.c @@ -0,0 +1,72 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "s6tls-internal.h" + +#define USAGE "s6-tlsd [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] prog..." +#define dieusage() strerr_dieusage(100, USAGE) + +static void child (int const [4][2], uint32_t, unsigned int, unsigned int) gccattr_noreturn ; +static void child (int const p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout) +{ + int fds[3] = { p[0][0], p[1][1], p[2][1] } ; + PROG = "s6-tlsd (child)" ; + close(p[2][0]) ; + close(p[0][1]) ; + close(p[1][0]) ; + s6tls_exec_tlsdio(fds, options, verbosity, kimeout) ; +} + +int main (int argc, char const *const *argv) +{ + unsigned int verbosity = 1 ; + unsigned int kimeout = 0 ; + int p[4][2] = { [3] = { 0, 1 } } ; + uint32_t coptions = 0 ; + uint32_t poptions = 1 ; + pid_t pid ; + + PROG = "s6-tlsd (parent)" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "SsYyv:K:Zz", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'S' : coptions |= 4 ; break ; + case 's' : coptions &= ~4 ; break ; + case 'Y' : coptions |= 1 ; coptions &= ~2 ; break ; + case 'y' : coptions |= 3 ; break ; + case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; + case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; + case 'Z' : poptions &= ~1 ; break ; + case 'z' : poptions |= 1 ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (!argc) dieusage() ; + + if (pipe(p[0]) < 0 || pipe(p[1]) < 0 || pipe(p[2]) < 0) + strerr_diefu1sys(111, "pipe") ; + pid = fork() ; + switch (pid) + { + case -1 : strerr_diefu1sys(111, "fork") ; + case 0 : child(p, coptions, verbosity, kimeout) ; + default : break ; + } + s6tls_sync_and_exec_app(argv, p, pid, poptions) ; +} diff --git a/src/tls/s6-tlsserver.c b/src/tls/s6-tlsserver.c new file mode 100644 index 0000000..fb899eb --- /dev/null +++ b/src/tls/s6-tlsserver.c @@ -0,0 +1,255 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define USAGE "s6-tlsserver [ -e ] [ options ] ip port prog...\n" \ +"s6-tcpserver options: [ -q | -Q | -v ] [ -4 | -6 ] [ -1 ] [ -c maxconn ] [ -C localmaxconn ] [ -b backlog ] [ -G gidlist ] [ -g gid ] [ -u uid ] [ -U ]\n" \ +"s6-tcpserver-access options: [ -W | -w ] [ -D | -d ] [ -H | -h ] [ -R | -r ] [ -P | -p ] [ -l localname ] [ -B banner ] [ -t timeout ] [ -i rulesdir | -x rulesfile ]\n" \ +"s6-tlsd options: [ -S | -s ] [ -Y | -y ] [ -K timeout ] [ -Z | -z ]" + +#define dieusage() strerr_dieusage(100, USAGE) + +typedef struct options_s options_t, *options_t_ref ; +struct options_s +{ + char const *localname ; + char const *banner ; + char const *rules ; + gid_t gids[NGROUPS_MAX] ; + size_t gidn ; + uid_t uid ; + gid_t gid ; + unsigned int maxconn ; + unsigned int localmaxconn ; + unsigned int backlog ; + unsigned int timeout ; + unsigned int kimeout ; + unsigned int verbosity : 2 ; + unsigned int flag46 : 2 ; + unsigned int flag1 : 1 ; + unsigned int flagU : 1 ; + unsigned int flagw : 1 ; + unsigned int flagD : 1 ; + unsigned int flagH : 1 ; + unsigned int flagr : 1 ; + unsigned int flagp : 1 ; + unsigned int ruleswhat : 2 ; + unsigned int flagS : 1 ; + unsigned int flagy : 1 ; + unsigned int flagZ : 1 ; + unsigned int onlyvars : 1 ; + unsigned int doaccess : 1 ; + unsigned int doapply : 1 ; +} ; + +#define OPTIONS_ZERO \ +{ \ + .localname = 0, \ + .banner = 0, \ + .rules = 0, \ + .backlog = (unsigned int)-1, \ + .gidn = (size_t)-1, \ + .uid = 0, \ + .gid = 0, \ + .maxconn = 0, \ + .localmaxconn = 0, \ + .timeout = 0, \ + .kimeout = 0, \ + .verbosity = 1, \ + .flag46 = 0, \ + .flag1 = 0, \ + .flagU = 0, \ + .flagw = 0, \ + .flagD = 0, \ + .flagH = 0, \ + .flagr = 0, \ + .flagp = 0, \ + .ruleswhat = 0, \ + .flagS = 0, \ + .flagy = 0, \ + .flagZ = 0, \ + .onlyvars = 0, \ + .doaccess = 0, \ + .doapply = 0 \ +} + +int main (int argc, char const *const *argv, char const *const *envp) +{ + options_t o = OPTIONS_ZERO ; + PROG = "s6-tlsserver" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "qQv461c:C:b:G:g:u:UWwDdHhRrPpleB:t:i:x:SsYyK:Zz", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'q' : o.verbosity = 0 ; break ; + case 'Q' : o.verbosity = 1 ; break ; + case 'v' : o.verbosity = 2 ; break ; + case '4' : o.flag46 = 1 ; break ; + case '6' : o.flag46 = 2 ; break ; + case '1' : o.flag1 = 1 ; break ; + case 'c' : if (!uint0_scan(l.arg, &o.maxconn)) dieusage() ; if (!o.maxconn) o.maxconn = 1 ; break ; + case 'C' : if (!uint0_scan(l.arg, &o.localmaxconn)) dieusage() ; if (!o.localmaxconn) o.localmaxconn = 1 ; break ; + case 'b' : if (!uint0_scan(l.arg, &o.backlog)) dieusage() ; break ; + case 'G' : if (!gid_scanlist(o.gids, NGROUPS_MAX, l.arg, &o.gidn) && *l.arg) dieusage() ; o.doapply = 1 ; break ; + case 'g' : if (!gid0_scan(l.arg, &o.gid)) dieusage() ; o.doapply = 1 ; break ; + case 'u' : if (!uid0_scan(l.arg, &o.uid)) dieusage() ; o.doapply = 1 ; break ; + case 'U' : o.flagU = 1 ; o.uid = 0 ; o.gid = 0 ; o.gidn = (size_t)-1 ; o.doapply = 1 ; break ; + case 'W' : o.flagw = 0 ; break ; + case 'w' : o.flagw = 1 ; break ; + case 'D' : o.flagD = 1 ; o.doaccess = 1 ; break ; + case 'd' : o.flagD = 0 ; break ; + case 'H' : o.flagH = 1 ; o.doaccess = 1 ; break ; + case 'h' : o.flagH = 0 ; break ; + case 'R' : o.flagr = 0 ; break ; + case 'r' : o.flagr = 1 ; o.doaccess = 1 ; break ; + case 'P' : o.flagp = 0 ; break ; + case 'p' : o.flagp = 1 ; o.doaccess = 1 ; break ; + case 'l' : o.localname = l.arg ; o.doaccess = 1 ; break ; + case 'e' : o.onlyvars = 1 ; o.doaccess = 1 ; break ; + case 'B' : o.banner = l.arg ; o.doaccess = 1 ; break ; + case 't' : if (!uint0_scan(l.arg, &o.timeout)) dieusage() ; break ; + case 'i' : o.rules = l.arg ; o.ruleswhat = 1 ; o.doaccess = 1 ; break ; + case 'x' : o.rules = l.arg ; o.ruleswhat = 2 ; o.doaccess = 1 ; break ; + case 'S' : o.flagS = 1 ; break ; + case 's' : o.flagS = 0 ; break ; + case 'Y' : o.flagy = 0 ; break ; + case 'y' : o.flagy = 1 ; break ; + case 'K' : if (!uint0_scan(l.arg, &o.kimeout)) dieusage() ; break ; + case 'Z' : o.flagZ = 1 ; break ; + case 'z' : o.flagZ = 0 ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + if (argc < 3) dieusage() ; + } + + { + size_t pos = 0 ; + unsigned int m = 0 ; + char fmt[UINT_FMT * 5 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ; + char const *newargv[45 + argc] ; + newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver" ; + if (o.verbosity != 1) newargv[m++] = o.verbosity ? "-v" : "-q" ; + if (o.flag46) newargv[m++] = o.flag46 == 1 ? "-4" : "-6" ; + if (o.flag1) newargv[m++] = "-1" ; + if (o.maxconn) + { + newargv[m++] = "-c" ; + newargv[m++] = fmt + pos ; + pos += uint_fmt(fmt + pos, o.maxconn) ; + fmt[pos++] = 0 ; + } + if (o.localmaxconn) + { + newargv[m++] = "-C" ; + newargv[m++] = fmt + pos ; + pos += uint_fmt(fmt + pos, o.localmaxconn) ; + fmt[pos++] = 0 ; + } + if (o.backlog != (unsigned int)-1) + { + newargv[m++] = "-b" ; + newargv[m++] = fmt + pos ; + pos += uint_fmt(fmt + pos, o.backlog) ; + fmt[pos++] = 0 ; + } + newargv[m++] = "--" ; + newargv[m++] = *argv++ ; + newargv[m++] = *argv++ ; + if (o.doaccess) + { + newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver-access" ; + if (o.verbosity) + { + if (o.verbosity > 1 && (!o.onlyvars || o.ruleswhat)) + newargv[m++] = "-v2" ; + } + else newargv[m++] = "-v0" ; + + if (o.flagw) newargv[m++] = "-w" ; + if (o.flagD) newargv[m++] = "-D" ; + if (o.flagH) newargv[m++] = "-H" ; + if (o.flagr) newargv[m++] = "-r" ; + if (o.flagp) newargv[m++] = "-p" ; + if (o.localname) + { + newargv[m++] = "-l" ; + newargv[m++] = o.localname ; + } + if (o.banner) + { + newargv[m++] = "-B" ; + newargv[m++] = o.banner ; + } + if (o.timeout) + { + newargv[m++] = "-t" ; + newargv[m++] = fmt + pos ; + pos += uint_fmt(fmt + pos, o.timeout) ; + fmt[pos++] = 0 ; + } + if (o.ruleswhat) + { + newargv[m++] = o.ruleswhat == 1 ? "-i" : "-x" ; + newargv[m++] = o.rules ; + } + newargv[m++] = "--" ; + } + newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsd" ; + if (o.verbosity != 1) + newargv[m++] = o.verbosity ? "-v2" : "-v0" ; + if (o.flagS) newargv[m++] = "-S" ; + if (o.flagy) newargv[m++] = "-y" ; + if (o.kimeout) + { + newargv[m++] = "-K" ; + newargv[m++] = fmt + pos ; + pos += uint_fmt(fmt + pos, o.kimeout) ; + fmt[pos++] = 0 ; + } + if (o.flagZ) newargv[m++] = "-Z" ; + newargv[m++] = "--" ; + if (o.doapply) + { + newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ; + if (o.gidn != (size_t)-1) + { + newargv[m++] = "-G" ; + newargv[m++] = fmt + pos ; + pos += gid_fmtlist(fmt + pos, o.gids, o.gidn) ; + fmt[pos++] = 0 ; + } + if (o.gid) + { + newargv[m++] = "-g" ; + newargv[m++] = fmt + pos ; + pos += gid_fmt(fmt + pos, o.gid) ; + fmt[pos++] = 0 ; + } + if (o.uid) + { + newargv[m++] = "-u" ; + newargv[m++] = fmt + pos ; + pos += uid_fmt(fmt + pos, o.uid) ; + fmt[pos++] = 0 ; + } + if (o.flagU) newargv[m++] = "-Uz" ; + newargv[m++] = "--" ; + } + while (*argv) newargv[m++] = *argv++ ; + newargv[m++] = 0 ; + xpathexec_run(newargv[0], newargv, envp) ; + } +} diff --git a/src/tls/s6-ucspitlsc.c b/src/tls/s6-ucspitlsc.c new file mode 100644 index 0000000..92660eb --- /dev/null +++ b/src/tls/s6-ucspitlsc.c @@ -0,0 +1,109 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include "s6tls-internal.h" + +#define USAGE "s6-ucspitlsc [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] [ -k servername ] [ -6 fdr ] [ -7 fdw ] prog..." +#define dieusage() strerr_dieusage(100, USAGE) + +static inline void child (int [4][2], uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ; +static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername) +{ + int fds[3] = { p[0][0], p[1][1], p[2][1] } ; + ssize_t r ; + char c ; + PROG = "s6-ucspitlsc" ; + close(p[2][0]) ; + close(p[0][1]) ; + close(p[1][0]) ; + if (fd_move(0, p[3][0]) < 0 || fd_move(1, p[3][1]) < 0) + strerr_diefu1sys(111, "move network fds to stdin/stdout") ; + r = read(p[2][1], &c, 1) ; + if (r < 0) strerr_diefu1sys(111, "read from control socket") ; + if (!r) _exit(0) ; + switch (c) + { + case 'y' : + close(p[2][1]) ; + p[2][1] = 0 ; /* we know 0 is open so it's a correct invalid value */ + case 'Y' : + fd_shutdown(p[2][1], 0) ; + break ; + default : + strerr_dief1x(100, "unrecognized command on control socket") ; + } + s6tls_exec_tlscio(fds, options, verbosity, kimeout, servername) ; +} + +int main (int argc, char const *const *argv, char const *const *envp) +{ + unsigned int verbosity = 1 ; + unsigned int kimeout = 0 ; + int p[4][2] = { [3] = { 6, 7 } } ; + uint32_t coptions = 0 ; + uint32_t poptions = 1 ; + char const *servername = 0 ; + + PROG = "s6-ucspitlsc (parent)" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "SsYyv:K:Zzk:6:7:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'S' : coptions |= 4 ; break ; + case 's' : coptions &= ~4 ; break ; + case 'Y' : coptions |= 1 ; coptions &= ~2 ; break ; + case 'y' : coptions |= 3 ; break ; + case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; + case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; + case 'Z' : poptions &= ~1 ; break ; + case 'z' : poptions |= 1 ; break ; + case 'k' : servername = l.arg ; break ; + case '6' : + { + unsigned int fd ; + if (!uint0_scan(l.arg, &fd)) dieusage() ; + p[3][0] = fd ; + break ; + } + case '7' : + { + unsigned int fd ; + if (!uint0_scan(l.arg, &fd)) dieusage() ; + p[3][1] = fd ; + break ; + } + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (!argc) dieusage() ; + fd_sanitize() ; + if (fcntl(p[3][0], F_GETFD) < 0 || fcntl(p[3][1], F_GETFD) < 0) + strerr_diefu1sys(111, "check network fds") ; + + if (ipc_pair_b(p[2]) < 0) strerr_diefu1sys(111, "ipc_pair") ; + if (pipe(p[0]) < 0 || pipe(p[1]) < 0) strerr_diefu1sys(111, "pipe") ; + switch (fork()) + { + case -1 : strerr_diefu1sys(111, "fork") ; + case 0 : child(p, coptions, verbosity, kimeout, servername) ; + default : break ; + } + s6tls_ucspi_exec_app(argv, p, poptions) ; +} diff --git a/src/tls/s6-ucspitlsd.c b/src/tls/s6-ucspitlsd.c new file mode 100644 index 0000000..4bfa253 --- /dev/null +++ b/src/tls/s6-ucspitlsd.c @@ -0,0 +1,88 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include "s6tls-internal.h" + +#define USAGE "s6-ucspitlsd [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -Z | -z ] prog..." +#define dieusage() strerr_dieusage(100, USAGE) + +static inline void child (int [4][2], uint32_t, unsigned int, unsigned int) gccattr_noreturn ; +static inline void child (int p[4][2], uint32_t options, unsigned int verbosity, unsigned int kimeout) +{ + int fds[3] = { p[0][0], p[1][1], p[2][1] } ; + ssize_t r ; + char c ; + PROG = "s6-ucspitlsd" ; + close(p[2][0]) ; + close(p[0][1]) ; + close(p[1][0]) ; + r = read(p[2][1], &c, 1) ; + if (r < 0) strerr_diefu1sys(111, "read from control socket") ; + if (!r) _exit(0) ; + switch (c) + { + case 'y' : + close(p[2][1]) ; + p[2][1] = 0 ; /* we know 0 is open so it's a correct invalid value */ + case 'Y' : + fd_shutdown(p[2][1], 0) ; + break ; + default : + strerr_dief1x(100, "unrecognized command on control socket") ; + } + s6tls_exec_tlsdio(fds, options, verbosity, kimeout) ; +} + +int main (int argc, char const *const *argv, char const *const *envp) +{ + unsigned int verbosity = 1 ; + unsigned int kimeout = 0 ; + int p[4][2] = { [3] = { 0, 1 } } ; + uint32_t coptions = 0 ; + uint32_t poptions = 1 ; + + PROG = "s6-ucspitlsd (parent)" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "SsYyv:K:Zz", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'S' : coptions |= 4 ; break ; + case 's' : coptions &= ~4 ; break ; + case 'Y' : coptions |= 1 ; coptions &= ~2 ; break ; + case 'y' : coptions |= 3 ; break ; + case 'v' : if (!uint0_scan(l.arg, &verbosity)) dieusage() ; break ; + case 'K' : if (!uint0_scan(l.arg, &kimeout)) dieusage() ; break ; + case 'Z' : poptions &= ~1 ; break ; + case 'z' : poptions |= 1 ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (!argc) dieusage() ; + + if (ipc_pair_b(p[2]) < 0) strerr_diefu1sys(111, "ipc_pair") ; + if (pipe(p[0]) < 0 || pipe(p[1]) < 0) strerr_diefu1sys(111, "pipe") ; + + switch (fork()) + { + case -1 : strerr_diefu1sys(111, "fork") ; + case 0 : child(p, coptions, verbosity, kimeout) ; + default : break ; + } + s6tls_ucspi_exec_app(argv, p, poptions) ; +} diff --git a/src/tls/s6tls-internal.h b/src/tls/s6tls-internal.h new file mode 100644 index 0000000..09be544 --- /dev/null +++ b/src/tls/s6tls-internal.h @@ -0,0 +1,18 @@ +/* ISC license */ + +#ifndef S6TLS_INTERNAL_H +#define S6TLS_INTERNAL_H + +#include +#include + +#include + +#define s6tls_envvars "CADIR\0CAFILE\0KEYFILE\0CERTFILE\0TLS_UID\0TLS_GID" + +extern void s6tls_exec_tlscio (int const *, uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ; +extern void s6tls_exec_tlsdio (int const *, uint32_t, unsigned int, unsigned int) gccattr_noreturn ; +extern void s6tls_sync_and_exec_app (char const *const *, int const [4][2], pid_t, uint32_t) gccattr_noreturn ; +extern void s6tls_ucspi_exec_app (char const *const *, int const [4][2], uint32_t) gccattr_noreturn ; + +#endif diff --git a/src/tls/s6tls_exec_tlscio.c b/src/tls/s6tls_exec_tlscio.c new file mode 100644 index 0000000..ad00ecd --- /dev/null +++ b/src/tls/s6tls_exec_tlscio.c @@ -0,0 +1,53 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include "s6tls-internal.h" + +void s6tls_exec_tlscio (int const *fds, uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername) +{ + char const *newargv[15] ; + unsigned int m = 0 ; + char fmtv[UINT_FMT] ; + char fmtd[UINT_FMT] ; + char fmtk[UINT_FMT] ; + char fmtr[UINT_FMT] ; + char fmtw[UINT_FMT] ; + + newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsc-io" ; + if (verbosity != 1) + { + newargv[m++] = "-v" ; + newargv[m++] = fmtv ; + fmtv[uint_fmt(fmtv, verbosity)] = 0 ; + } + if (fds[2]) + { + newargv[m++] = "-d" ; + newargv[m++] = fmtd ; + fmtd[uint_fmt(fmtd, fds[2])] = 0 ; + } + newargv[m++] = options & 4 ? "-S" : "-s" ; + newargv[m++] = options & 1 ? "-y" : "-Y" ; + if (kimeout) + { + newargv[m++] = "-K" ; + newargv[m++] = fmtk ; + fmtk[uint_fmt(fmtk, kimeout)] = 0 ; + } + if (servername) + { + newargv[m++] = "-k" ; + newargv[m++] = servername ; + } + newargv[m++] = "--" ; + newargv[m++] = fmtr ; + fmtr[uint_fmt(fmtr, fds[0])] = 0 ; + newargv[m++] = fmtw ; + fmtw[uint_fmt(fmtw, fds[1])] = 0 ; + newargv[m++] = 0 ; + xpathexec_run(newargv[0], newargv, (char const *const *)environ) ; +} diff --git a/src/tls/s6tls_exec_tlsdio.c b/src/tls/s6tls_exec_tlsdio.c new file mode 100644 index 0000000..b00adb2 --- /dev/null +++ b/src/tls/s6tls_exec_tlsdio.c @@ -0,0 +1,49 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include "s6tls-internal.h" + +void s6tls_exec_tlsdio (int const *fds, uint32_t options, unsigned int verbosity, unsigned int kimeout) +{ + char const *newargv[13] ; + unsigned int m = 0 ; + char fmtv[UINT_FMT] ; + char fmtd[UINT_FMT] ; + char fmtk[UINT_FMT] ; + char fmtr[UINT_FMT] ; + char fmtw[UINT_FMT] ; + + newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tlsd-io" ; + if (verbosity != 1) + { + newargv[m++] = "-v" ; + newargv[m++] = fmtv ; + fmtv[uint_fmt(fmtv, verbosity)] = 0 ; + } + if (fds[2]) + { + newargv[m++] = "-d" ; + newargv[m++] = fmtd ; + fmtd[uint_fmt(fmtd, fds[2])] = 0 ; + } + newargv[m++] = options & 4 ? "-S" : "-s" ; + if (options & 1) + newargv[m++] = options & 2 ? "-y" : "-Y" ; + if (kimeout) + { + newargv[m++] = "-K" ; + newargv[m++] = fmtk ; + fmtk[uint_fmt(fmtk, kimeout)] = 0 ; + } + newargv[m++] = "--" ; + newargv[m++] = fmtr ; + fmtr[uint_fmt(fmtr, fds[0])] = 0 ; + newargv[m++] = fmtw ; + fmtw[uint_fmt(fmtw, fds[1])] = 0 ; + newargv[m++] = 0 ; + xpathexec_run(newargv[0], newargv, (char const *const *)environ) ; +} diff --git a/src/tls/s6tls_sync_and_exec_app.c b/src/tls/s6tls_sync_and_exec_app.c new file mode 100644 index 0000000..4ae63fa --- /dev/null +++ b/src/tls/s6tls_sync_and_exec_app.c @@ -0,0 +1,43 @@ +/* ISC license. */ + +#include +#include + +#include +#include +#include +#include + +#include "s6tls-internal.h" + +#define MAXENVSIZE 2048 + +void s6tls_sync_and_exec_app (char const *const *argv, int const p[4][2], pid_t pid, uint32_t options) +{ + char buf[sizeof(s6tls_envvars) + MAXENVSIZE] ; + size_t m = 0 ; + ssize_t r ; + close(p[2][1]) ; + close(p[1][1]) ; + close(p[0][0]) ; + if (fd_move(p[3][0], p[1][0]) < 0 || fd_move(p[3][1], p[0][1]) < 0) + strerr_diefu1sys(111, "move file descriptors") ; + if (options & 1) + { + memcpy(buf + m, s6tls_envvars, sizeof(s6tls_envvars)) ; + m += sizeof(s6tls_envvars) ; + } + r = read(p[2][0], buf + m, MAXENVSIZE) ; + if (r < 0) strerr_diefu1sys(111, "read from handshake notification pipe") ; + if (!r) + { + int wstat ; + if (wait_pid(pid, &wstat) < 0) + strerr_diefu1sys(111, "wait") ; + _exit(wait_estatus(wstat)) ; + } + if (r >= MAXENVSIZE) + strerr_dief1x(100, "SSL data too large") ; + m += r - 1 ; + xpathexec_r(argv, (char const *const *)environ, env_len((char const *const *)environ), buf, m) ; +} diff --git a/src/tls/s6tls_ucspi_exec_app.c b/src/tls/s6tls_ucspi_exec_app.c new file mode 100644 index 0000000..f4b52ef --- /dev/null +++ b/src/tls/s6tls_ucspi_exec_app.c @@ -0,0 +1,36 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include +#include + +#include "s6tls-internal.h" + +void s6tls_ucspi_exec_app (char const *const *argv, int const p[4][2], uint32_t options) +{ + size_t m = 0 ; + char modif[sizeof(s6tls_envvars) + 33 + 3 * UINT_FMT] ; + close(p[2][1]) ; + close(p[1][1]) ; + close(p[0][0]) ; + if (options & 1) + { + memcpy(modif + m, s6tls_envvars, sizeof(s6tls_envvars)) ; + m += sizeof(s6tls_envvars) ; + } + memcpy(modif + m, "SSLCTLFD=", 9) ; m += 9 ; + m += uint_fmt(modif + m, p[2][0]) ; + modif[m++] = 0 ; + memcpy(modif + m, "SSLREADFD=", 10) ; m += 10 ; + m += uint_fmt(modif + m, p[1][0]) ; + modif[m++] = 0 ; + memcpy(modif + m, "SSLWRITEFD=", 11) ; m += 11 ; + m += uint_fmt(modif + m, p[0][1]) ; + modif[m++] = 0 ; + xpathexec_r(argv, (char const *const *)environ, env_len((char const* const *)environ), modif, m) ; +} -- cgit v1.2.3