diff options
-rw-r--r-- | package/deps.mak | 14 | ||||
-rw-r--r-- | package/modes | 1 | ||||
-rw-r--r-- | package/targets.mak | 2 | ||||
-rw-r--r-- | src/conn-tools/deps-exe/s6-ucspitlsc | 3 | ||||
-rw-r--r-- | src/conn-tools/deps-lib/s6tls | 3 | ||||
-rw-r--r-- | src/conn-tools/s6-tlsc.c | 41 | ||||
-rw-r--r-- | src/conn-tools/s6-tlsd.c | 27 | ||||
-rw-r--r-- | src/conn-tools/s6-ucspitlsc.c | 109 | ||||
-rw-r--r-- | src/conn-tools/s6-ucspitlsd.c | 53 | ||||
-rw-r--r-- | src/conn-tools/s6tls-internal.h | 3 | ||||
-rw-r--r-- | src/conn-tools/s6tls_sync_and_exec_app.c (renamed from src/conn-tools/s6tls_wait_and_exec_app.c) | 4 | ||||
-rw-r--r-- | src/conn-tools/s6tls_ucspi_exec_app.c | 36 |
12 files changed, 212 insertions, 84 deletions
diff --git a/package/deps.mak b/package/deps.mak index ceff750..9f779b9 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -12,7 +12,7 @@ src/clock/s6-taiclockd.o src/clock/s6-taiclockd.lo: src/clock/s6-taiclockd.c src/conn-tools/s6-getservbyname.o src/conn-tools/s6-getservbyname.lo: src/conn-tools/s6-getservbyname.c src/conn-tools/s6-ident-client.o src/conn-tools/s6-ident-client.lo: src/conn-tools/s6-ident-client.c src/include/s6-networking/ident.h src/conn-tools/s6-tcpclient.o src/conn-tools/s6-tcpclient.lo: src/conn-tools/s6-tcpclient.c src/include/s6-networking/ident.h -src/conn-tools/s6-tcpserver-access.o src/conn-tools/s6-tcpserver-access.lo: src/conn-tools/s6-tcpserver-access.c src/include/s6-networking/ident.h +src/conn-tools/s6-tcpserver-access.o src/conn-tools/s6-tcpserver-access.lo: src/conn-tools/s6-tcpserver-access.c src/include/s6-networking/config.h src/include/s6-networking/ident.h src/conn-tools/s6-tcpserver.o src/conn-tools/s6-tcpserver.lo: src/conn-tools/s6-tcpserver.c src/include/s6-networking/config.h src/conn-tools/s6-tcpserver4-socketbinder.o src/conn-tools/s6-tcpserver4-socketbinder.lo: src/conn-tools/s6-tcpserver4-socketbinder.c src/conn-tools/s6-tcpserver4.o src/conn-tools/s6-tcpserver4.lo: src/conn-tools/s6-tcpserver4.c src/include/s6-networking/config.h @@ -26,10 +26,12 @@ src/conn-tools/s6-tlsclient.o src/conn-tools/s6-tlsclient.lo: src/conn-tools/s6- 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_wait_and_exec_app.o src/conn-tools/s6tls_wait_and_exec_app.lo: src/conn-tools/s6tls_wait_and_exec_app.c 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 @@ -90,12 +92,12 @@ 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_wait_and_exec_app.o +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_wait_and_exec_app.lo +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_wait_and_exec_app.lo +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} @@ -130,6 +132,8 @@ 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)),) diff --git a/package/modes b/package/modes index d2ff2d3..1bbc527 100644 --- a/package/modes +++ b/package/modes @@ -21,4 +21,5 @@ s6-tlsc-io 0755 s6-tlsserver 0755 s6-tlsd 0755 s6-tlsd-io 0755 +s6-ucspitlsc 0755 s6-ucspitlsd 0755 diff --git a/package/targets.mak b/package/targets.mak index 47d4636..474ea2d 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -32,7 +32,7 @@ src/minidentd/mgetuid.c: src/minidentd/mgetuid-linux.c src/minidentd/mgetuid-def ifneq ($(SSL_IMPL),) -BIN_TARGETS += s6-tlsclient s6-tlsc s6-tlsc-io s6-tlsserver s6-tlsd s6-tlsd-io s6-ucspitlsd +BIN_TARGETS += s6-tlsclient s6-tlsc s6-tlsc-io s6-tlsserver s6-tlsd s6-tlsd-io s6-ucspitlsc s6-ucspitlsd INTERNAL_LIBS += libs6tls.a.xyzzy ifeq ($(SSL_IMPL),tls) diff --git a/src/conn-tools/deps-exe/s6-ucspitlsc b/src/conn-tools/deps-exe/s6-ucspitlsc new file mode 100644 index 0000000..ac1b327 --- /dev/null +++ b/src/conn-tools/deps-exe/s6-ucspitlsc @@ -0,0 +1,3 @@ +libs6tls.a.xyzzy +-lskarnet +${SOCKET_LIB} diff --git a/src/conn-tools/deps-lib/s6tls b/src/conn-tools/deps-lib/s6tls index ce4f507..f392de5 100644 --- a/src/conn-tools/deps-lib/s6tls +++ b/src/conn-tools/deps-lib/s6tls @@ -1,3 +1,4 @@ s6tls_exec_tlscio.o s6tls_exec_tlsdio.o -s6tls_wait_and_exec_app.o +s6tls_sync_and_exec_app.o +s6tls_ucspi_exec_app.o diff --git a/src/conn-tools/s6-tlsc.c b/src/conn-tools/s6-tlsc.c index 5a15315..5b2e7dc 100644 --- a/src/conn-tools/s6-tlsc.c +++ b/src/conn-tools/s6-tlsc.c @@ -13,32 +13,31 @@ #include "s6tls-internal.h" -#define USAGE "s6-tlsc [ -S | -s ] [ -Y | -y ] [ -v verbosity ] [ -K timeout ] [ -k servername ] [ -Z | -z ] [ -6 rfd ] [ -7 wfd ] prog..." +#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 [3][2], int, int, uint32_t, unsigned int, unsigned int, char const *) gccattr_noreturn ; -static void child (int const p[3][2], int fdr, int fdw, uint32_t options, unsigned int verbosity, unsigned int kimeout, char const *servername) +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, fdr) < 0 || fd_move(1, fdw) < 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) { - int fds[2] = { 6, 7 } ; - char const *servername = 0 ; unsigned int verbosity = 1 ; unsigned int kimeout = 0 ; - int p[3][2] ; - uint32_t options = 0 ; - int cleanenv = 1 ; + int p[4][2] ; + uint32_t coptions = 0 ; + uint32_t poptions = 1 ; pid_t pid ; + char const *servername = 0 ; PROG = "s6-tlsc" ; { @@ -49,27 +48,27 @@ int main (int argc, char const *const *argv) if (opt == -1) break ; switch (opt) { - case 'S' : options &= ~4 ; break ; - case 's' : options |= 4 ; break ; - case 'Y' : options &= ~1 ; break ; - case 'y' : options |= 1 ; break ; + 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' : cleanenv = 0 ; break ; - case 'z' : cleanenv = 1 ; break ; + case 'Z' : poptions &= ~1 ; break ; + case 'z' : poptions |= 1 ; break ; case '6' : { unsigned int fd ; if (!uint0_scan(l.arg, &fd)) dieusage() ; - fds[0] = fd ; + p[3][0] = fd ; break ; } case '7' : { unsigned int fd ; if (!uint0_scan(l.arg, &fd)) dieusage() ; - fds[1] = fd ; + p[3][1] = fd ; break ; } default : dieusage() ; @@ -79,17 +78,17 @@ int main (int argc, char const *const *argv) } if (!argc) dieusage() ; fd_sanitize() ; - if (fcntl(fds[0], F_GETFD) < 0 || fcntl(fds[1], F_GETFD) < 0) + 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, fds[0], fds[1], options, verbosity, kimeout, servername) ; + case 0 : child(p, coptions, verbosity, kimeout, servername) ; default : break ; } - - s6tls_wait_and_exec_app(argv, p, pid, fds[0], fds[1], cleanenv ? 1 : 0) ; + s6tls_sync_and_exec_app(argv, p, pid, poptions) ; } diff --git a/src/conn-tools/s6-tlsd.c b/src/conn-tools/s6-tlsd.c index e048a49..361502e 100644 --- a/src/conn-tools/s6-tlsd.c +++ b/src/conn-tools/s6-tlsd.c @@ -15,8 +15,8 @@ #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 [3][2], uint32_t, unsigned int, unsigned int) gccattr_noreturn ; -static void child (int const p[3][2], uint32_t options, unsigned int verbosity, unsigned int kimeout) +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)" ; @@ -30,9 +30,9 @@ int main (int argc, char const *const *argv) { unsigned int verbosity = 1 ; unsigned int kimeout = 0 ; - int p[3][2] ; - uint32_t options = 0 ; - int cleanenv = 1 ; + int p[4][2] = { [3] = { 0, 1 } } ; + uint32_t coptions = 0 ; + uint32_t poptions = 1 ; pid_t pid ; PROG = "s6-tlsd (parent)" ; @@ -44,14 +44,14 @@ int main (int argc, char const *const *argv) if (opt == -1) break ; switch (opt) { - case 'S' : options |= 4 ; break ; - case 's' : options &= ~4 ; break ; - case 'Y' : options |= 1 ; options &= ~2 ; break ; - case 'y' : options |= 3 ; break ; + 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' : cleanenv = 0 ; break ; - case 'z' : cleanenv = 1 ; break ; + case 'Z' : poptions &= ~1 ; break ; + case 'z' : poptions |= 1 ; break ; default : dieusage() ; } } @@ -65,9 +65,8 @@ int main (int argc, char const *const *argv) switch (pid) { case -1 : strerr_diefu1sys(111, "fork") ; - case 0 : child(p, options, verbosity, kimeout) ; + case 0 : child(p, coptions, verbosity, kimeout) ; default : break ; } - - s6tls_wait_and_exec_app(argv, p, pid, 0, 1, cleanenv ? 1 : 0) ; + s6tls_sync_and_exec_app(argv, p, pid, poptions) ; } diff --git a/src/conn-tools/s6-ucspitlsc.c b/src/conn-tools/s6-ucspitlsc.c new file mode 100644 index 0000000..92660eb --- /dev/null +++ b/src/conn-tools/s6-ucspitlsc.c @@ -0,0 +1,109 @@ +/* ISC license. */ + +#include <fcntl.h> +#include <stdint.h> +#include <unistd.h> + +#include <skalibs/gccattributes.h> +#include <skalibs/types.h> +#include <skalibs/sgetopt.h> +#include <skalibs/strerr2.h> +#include <skalibs/djbunix.h> +#include <skalibs/webipc.h> + +#include <s6-networking/config.h> +#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 index 2ce24ba..4bfa253 100644 --- a/src/conn-tools/s6-ucspitlsd.c +++ b/src/conn-tools/s6-ucspitlsd.c @@ -1,15 +1,12 @@ /* ISC license. */ #include <stdint.h> -#include <string.h> #include <unistd.h> -#include <stdlib.h> #include <skalibs/gccattributes.h> #include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> -#include <skalibs/env.h> #include <skalibs/djbunix.h> #include <skalibs/webipc.h> @@ -19,8 +16,8 @@ #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 [3][2], uint32_t, unsigned int, unsigned int) gccattr_noreturn ; -static inline void child (int p[3][2], uint32_t options, unsigned int verbosity, unsigned int kimeout) +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 ; @@ -48,11 +45,11 @@ static inline void child (int p[3][2], uint32_t options, unsigned int verbosity, int main (int argc, char const *const *argv, char const *const *envp) { - unsigned int kimeout = 0 ; unsigned int verbosity = 1 ; - uint32_t options = 0 ; - int cleanenv = 1 ; - int p[3][2] ; + unsigned int kimeout = 0 ; + int p[4][2] = { [3] = { 0, 1 } } ; + uint32_t coptions = 0 ; + uint32_t poptions = 1 ; PROG = "s6-ucspitlsd (parent)" ; { @@ -63,14 +60,14 @@ int main (int argc, char const *const *argv, char const *const *envp) if (opt == -1) break ; switch (opt) { - case 'S' : options |= 4 ; break ; - case 's' : options &= ~4 ; break ; - case 'Y' : options |= 1 ; options &= ~2 ; break ; - case 'y' : options |= 3 ; break ; + 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' : cleanenv = 0 ; break ; - case 'z' : cleanenv = 1 ; break ; + case 'Z' : poptions &= ~1 ; break ; + case 'z' : poptions |= 1 ; break ; default : dieusage() ; } } @@ -84,30 +81,8 @@ int main (int argc, char const *const *argv, char const *const *envp) switch (fork()) { case -1 : strerr_diefu1sys(111, "fork") ; - case 0 : child(p, options, verbosity, kimeout) ; + case 0 : child(p, coptions, verbosity, kimeout) ; default : break ; } - - { - 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 (cleanenv) - { - 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, envp, env_len(envp), modif, m) ; - } + s6tls_ucspi_exec_app(argv, p, poptions) ; } diff --git a/src/conn-tools/s6tls-internal.h b/src/conn-tools/s6tls-internal.h index be22e25..09be544 100644 --- a/src/conn-tools/s6tls-internal.h +++ b/src/conn-tools/s6tls-internal.h @@ -12,6 +12,7 @@ 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_wait_and_exec_app (char const *const *, int const [3][2], pid_t, int, int, uint32_t) 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_wait_and_exec_app.c b/src/conn-tools/s6tls_sync_and_exec_app.c index 20828f6..4ae63fa 100644 --- a/src/conn-tools/s6tls_wait_and_exec_app.c +++ b/src/conn-tools/s6tls_sync_and_exec_app.c @@ -12,7 +12,7 @@ #define MAXENVSIZE 2048 -void s6tls_wait_and_exec_app (char const *const *argv, int const p[3][2], pid_t pid, int fdr, int fdw, uint32_t options) +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 ; @@ -20,7 +20,7 @@ void s6tls_wait_and_exec_app (char const *const *argv, int const p[3][2], pid_t close(p[2][1]) ; close(p[1][1]) ; close(p[0][0]) ; - if (fd_move(fdr, p[1][0]) < 0 || fd_move(fdw, p[0][1]) < 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) { diff --git a/src/conn-tools/s6tls_ucspi_exec_app.c b/src/conn-tools/s6tls_ucspi_exec_app.c new file mode 100644 index 0000000..f4b52ef --- /dev/null +++ b/src/conn-tools/s6tls_ucspi_exec_app.c @@ -0,0 +1,36 @@ +/* ISC license. */ + +#include <stdint.h> +#include <string.h> +#include <unistd.h> + +#include <skalibs/posixplz.h> +#include <skalibs/types.h> +#include <skalibs/env.h> +#include <skalibs/djbunix.h> + +#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) ; +} |