diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-11-21 11:51:08 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-11-21 11:51:08 +0000 |
commit | 7f2cd05720e721c7e8131d4a4762d97a29fbf7b4 (patch) | |
tree | 0c9f5e4647b8e63c295a05f0439bd1c54c5bbbeb /src/conn-tools | |
parent | 2269af1457817b7a3b9b51cc0512d5f29e1fc7a5 (diff) | |
download | s6-networking-7f2cd05720e721c7e8131d4a4762d97a29fbf7b4.tar.xz |
Add s6-ucspitlsc
Diffstat (limited to 'src/conn-tools')
-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 |
9 files changed, 201 insertions, 78 deletions
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) ; +} |