From 5d38ea056c82221a0ddc206cd57dd7c1852a3159 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sun, 4 Dec 2016 13:44:23 +0000 Subject: Remove s6-tls* dependency to libs6net. Improve gen-deps to make dynlinking easier. --- src/stls/deps-lib/stls | 2 +- src/stls/stls-internal.h | 10 ++++++++++ src/stls/stls_clean_tls_and_spawn.c | 21 +++++++++++++++++++++ src/stls/stls_s6tlsc.c | 13 ++----------- src/stls/stls_s6tlsd.c | 4 ++-- 5 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 src/stls/stls-internal.h create mode 100644 src/stls/stls_clean_tls_and_spawn.c (limited to 'src/stls') diff --git a/src/stls/deps-lib/stls b/src/stls/deps-lib/stls index f215998..03cebfa 100644 --- a/src/stls/deps-lib/stls +++ b/src/stls/deps-lib/stls @@ -1,6 +1,6 @@ +stls_clean_tls_and_spawn.o stls_run.o stls_s6tlsc.o stls_s6tlsd.o -ltls --ls6net -lskarnet diff --git a/src/stls/stls-internal.h b/src/stls/stls-internal.h new file mode 100644 index 0000000..85fc825 --- /dev/null +++ b/src/stls/stls-internal.h @@ -0,0 +1,10 @@ +/* ISC license. */ + +#ifndef STLS_INTERNAL_H +#define STLS_INTERNAL_H + +#include + +extern pid_t stls_clean_tls_and_spawn (char const *const *, char const *const *, int *, uint32_t) ; + +#endif diff --git a/src/stls/stls_clean_tls_and_spawn.c b/src/stls/stls_clean_tls_and_spawn.c new file mode 100644 index 0000000..37ea619 --- /dev/null +++ b/src/stls/stls_clean_tls_and_spawn.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include +#include +#include +#include "stls-internal.h" + +pid_t stls_clean_tls_and_spawn (char const *const *argv, char const *const *envp, int *fds, uint32_t options) +{ + if (!(options & 1)) return child_spawn2(argv[0], argv, envp, fds) ; + else + { + char const modifs[] = "CADIR\0CAFILE\0KEYFILE\0CERTFILE\0TLS_UID\0TLS_GID" ; + size_t modiflen = sizeof(modifs) ; + size_t n = env_len(envp) ; + char const *newenv[n + 7] ; + size_t newenvlen = env_merge(newenv, n+7, envp, n, modifs, modiflen) ; + if (!newenvlen) return 0 ; + return child_spawn2(argv[0], argv, newenv, fds) ; + } +} diff --git a/src/stls/stls_s6tlsc.c b/src/stls/stls_s6tlsc.c index bafc2b8..9c30b60 100644 --- a/src/stls/stls_s6tlsc.c +++ b/src/stls/stls_s6tlsc.c @@ -8,21 +8,12 @@ #include #include #include -#include #include +#include "stls-internal.h" #define diecfg(cfg, s) strerr_diefu3x(96, (s), ": ", tls_config_error(cfg)) #define diectx(e, ctx, s) strerr_diefu3x(e, (s), ": ", tls_error(ctx)) -#ifdef DEBUG -# include -# include -# include -# define PLM(...) (bprintf(buffer_2, "%s: debug: ", PROG), bprintf(buffer_2, __VA_ARGS__), buffer_putflush(buffer_2, "\n", 1)) -#else -# define PLM(...) -#endif - int stls_s6tlsc (char const *const *argv, char const *const *envp, tain_t const *tto, uint32_t preoptions, uint32_t options, uid_t uid, gid_t gid, unsigned int verbosity, char const *servername, int *sfd) { int fds[4] = { sfd[0], sfd[1], sfd[0], sfd[1] } ; @@ -83,7 +74,7 @@ int stls_s6tlsc (char const *const *argv, char const *const *envp, tain_t const if (!ctx) strerr_diefu1sys(111, "tls_client") ; if (tls_configure(ctx, cfg) < 0) diectx(97, ctx, "tls_configure") ; - pid = s6net_clean_tls_and_spawn(argv, envp, fds, !!(preoptions & 2)) ; + pid = stls_clean_tls_and_spawn(argv, envp, fds, !!(preoptions & 2)) ; if (!pid) strerr_diefu2sys(111, "spawn ", argv[0]) ; if (gid && setgid(gid) < 0) strerr_diefu1sys(111, "setgid") ; if (uid && setuid(uid) < 0) strerr_diefu1sys(111, "setuid") ; diff --git a/src/stls/stls_s6tlsd.c b/src/stls/stls_s6tlsd.c index 64cf01f..0e82ab0 100644 --- a/src/stls/stls_s6tlsd.c +++ b/src/stls/stls_s6tlsd.c @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include "stls-internal.h" #define diecfg(cfg, s) strerr_diefu3x(96, (s), ": ", tls_config_error(cfg)) #define diectx(e, ctx, s) strerr_diefu3x(e, (s), ": ", tls_error(ctx)) @@ -71,7 +71,7 @@ int stls_s6tlsd (char const *const *argv, char const *const *envp, tain_t const if (tls_configure(ctx, cfg) < 0) diectx(97, ctx, "tls_configure") ; tls_config_free(cfg) ; - pid = s6net_clean_tls_and_spawn(argv, envp, fds, !!(preoptions & 2)) ; + pid = stls_clean_tls_and_spawn(argv, envp, fds, !!(preoptions & 2)) ; if (!pid) strerr_diefu2sys(111, "spawn ", argv[0]) ; if (gid && setgid(gid) < 0) strerr_diefu1sys(111, "setgid") ; if (uid && setuid(uid) < 0) strerr_diefu1sys(111, "setuid") ; -- cgit v1.2.3