summaryrefslogtreecommitdiff
path: root/src/stls/stls_drop.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-11-21 02:22:09 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-11-21 02:22:09 +0000
commit5c2880becc94141b8035b3488b6bd60696011308 (patch)
tree51e177122b50e248075dae441e4a76d68fd33081 /src/stls/stls_drop.c
parent5715c21a077ee1c2fe8957cb4adcea14fd2eda6b (diff)
downloads6-networking-5c2880becc94141b8035b3488b6bd60696011308.tar.xz
Privs can only be dropped after reading key files.
Diffstat (limited to 'src/stls/stls_drop.c')
-rw-r--r--src/stls/stls_drop.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/stls/stls_drop.c b/src/stls/stls_drop.c
new file mode 100644
index 0000000..d1e6831
--- /dev/null
+++ b/src/stls/stls_drop.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <skalibs/strerr2.h>
+#include <skalibs/types.h>
+
+#include "stls-internal.h"
+
+void stls_drop (void)
+{
+ if (!getuid())
+ {
+ uid_t uid ;
+ gid_t gid ;
+ char const *x = getenv("TLS_UID") ;
+ if (x && !uid0_scan(x, &uid)) strerr_dieinvalid(100, "TLS_UID") ;
+ x = getenv("TLS_GID") ;
+ if (x && !gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ;
+ if (gid && setgid(gid) < 0) strerr_diefu1sys(111, "setgid") ;
+ if (uid && setuid(uid) < 0) strerr_diefu1sys(111, "setuid") ;
+ }
+}