From dedaf9d8ef531e583809b29af785159b6d2a41d8 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 9 Feb 2024 00:01:58 +0100 Subject: [PATCH] add launch tool --- src/enter_vpn.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/enter_vpn.c diff --git a/src/enter_vpn.c b/src/enter_vpn.c new file mode 100644 index 0000000..fdc1a1c --- /dev/null +++ b/src/enter_vpn.c @@ -0,0 +1,36 @@ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include + +int main() { + char shell[128] = {0}; + + struct passwd *pw = getpwent(); + strlcpy(shell, pw->pw_shell, sizeof(shell)); + + endpwent(); + + int fd = open("/run/vpn/net", 0); + + if(fd > 0) { + int failure = setns(fd, CLONE_NEWNET); + if(failure) { + perror("setns /run/vpn/net"); + } + close(fd); + if(failure) { + return 1; + } + } else { + perror("open /run/vpn/net"); + return 1; + } + execl(shell, shell, NULL); + perror(NULL); + return 0; +}