aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/s6-tlsc-io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tls/s6-tlsc-io.c')
-rw-r--r--src/tls/s6-tlsc-io.c91
1 files changed, 59 insertions, 32 deletions
diff --git a/src/tls/s6-tlsc-io.c b/src/tls/s6-tlsc-io.c
index 25347b7..9098fdc 100644
--- a/src/tls/s6-tlsc-io.c
+++ b/src/tls/s6-tlsc-io.c
@@ -3,10 +3,10 @@
#include <stdint.h>
#include <signal.h>
+#include <skalibs/uint64.h>
#include <skalibs/gccattributes.h>
#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/strerr.h>
+#include <skalibs/envexec.h>
#include <skalibs/tai.h>
#include <skalibs/sig.h>
#include <skalibs/djbunix.h>
@@ -16,6 +16,23 @@
#define USAGE "s6-tlsc-io [ -v verbosity ] [ -d notif ] [ -S | -s ] [ -J | -j ] [ -Y | -y ] [ -K timeout ] [ -k servername ] fdr fdw"
#define dieusage() strerr_dieusage(100, USAGE)
+enum golb_e
+{
+ GOLB_CLOSENOTIFY = 0x01,
+ GOLB_STRICTCN = 0x02,
+ GOLB_CLIENTCERT = 0x10,
+ GOLB_NOVERIFY = 0x20,
+} ;
+
+enum gola_e
+{
+ GOLA_VERBOSITY,
+ GOLA_KIMEOUT,
+ GOLA_SERVERNAME,
+ GOLA_NOTIF,
+ GOLA_N
+} ;
+
static inline void doit (int *, tain const *tto, uint32_t, uint32_t, unsigned int, char const *, unsigned int) gccattr_noreturn ;
#ifdef S6_NETWORKING_USE_TLS
@@ -67,41 +84,51 @@ static inline void doit (int *fds, tain const *tto, uint32_t preoptions, uint32_
int main (int argc, char const *const *argv, char const *const *envp)
{
- char const *servername = 0 ;
- tain tto ;
+ static gol_bool const rgolb[] =
+ {
+ { .so = 's', .lo = "no-close-notify", .clear = GOLB_CLOSENOTIFY, .set = 0 },
+ { .so = 'S', .lo = "close-notify", .clear = 0, .set = GOLB_CLOSENOTIFY },
+ { .so = 'j', .lo = "no-enforce-close-notify", .clear = GOLB_STRICTCN, .set = 0 },
+ { .so = 'J', .lo = "enforce-close-notify", .clear = 0, .set = GOLB_STRICTCN },
+ { .so = 'Y', .lo = "no-client-cert", .clear = GOLB_CLIENTCERT, .set = 0 },
+ { .so = 'y', .lo = "client-cert", .clear = 0, .set = GOLB_CLIENTCERT },
+ { .so = 0, .lo = "verify-cert", .clear = GOLB_NOVERIFY, .set = 0 },
+ { .so = 0, .lo = "no-verify-cert", .clear = 0, .set = GOLB_NOVERIFY },
+ } ;
+ static gol_arg const rgola[] =
+ {
+ { .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY },
+ { .so = 'K', .lo = "kimeout", .i = GOLA_KIMEOUT },
+ { .so = 'k', .lo = "servername", .i = GOLA_SERVERNAME },
+ { .so = 'd', .lo = "notification-fd", .i = GOLA_NOTIF },
+ } ;
int fds[4] = { 0, 1 } ;
+ tain tto = TAIN_INFINITE_RELATIVE ;
unsigned int verbosity = 1 ;
unsigned int notif = 0 ;
- uint32_t preoptions = 0 ;
- uint32_t options = 0 ;
-
+ uint64_t wgolb = 0 ;
+ char const *wgola[GOLA_N] = { 0 } ;
+ unsigned int golc ;
PROG = "s6-tlsc-io" ;
+
+ golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
+ argc -= golc ; argv += golc ;
+ if (argc < 2) dieusage() ;
+
+ if (wgola[GOLA_VERBOSITY])
+ if (!uint0_scan(wgola[GOLA_VERBOSITY], &verbosity))
+ strerr_dief2x(100, "verbosity", " must be an unsigned integer") ;
+ if (wgola[GOLA_KIMEOUT])
{
- subgetopt l = SUBGETOPT_ZERO ;
- unsigned int t = 0 ;
- for (;;)
- {
- int opt = subgetopt_r(argc, argv, "d:SsJjYyv: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, &notif)) dieusage() ; break ;
- case 'S' : options |= 1 ; break ;
- case 's' : options &= ~1 ; break ;
- case 'J' : options |= 2 ; break ;
- case 'j' : options &= ~2 ; 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 ;
+ unsigned int kimeout ;
+ if (!uint0_scan(wgola[GOLA_KIMEOUT], &kimeout))
+ strerr_dief2x(100, "kimeout", " must be an unsigned integer") ;
+ if (kimeout) tain_from_millisecs(&tto, kimeout) ;
}
- if (argc < 2) dieusage() ;
+ if (wgola[GOLA_NOTIF])
+ if (!uint0_scan(wgola[GOLA_NOTIF], &notif))
+ strerr_dief2x(100, "notification-fd", " must be an unsigned integer") ;
+
{
unsigned int u ;
if (!uint0_scan(argv[0], &u)) dieusage() ;
@@ -112,5 +139,5 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (!sig_ignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ;
tain_now_set_stopwatch_g() ;
- doit(fds, &tto, preoptions, options, verbosity, servername, notif) ;
+ doit(fds, &tto, wgolb >> 4, wgolb & 0xf, verbosity, wgola[GOLA_SERVERNAME], notif) ;
}