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; +}