add launch tool

This commit is contained in:
Roy Olav Purser 2024-02-09 00:01:58 +01:00
parent 17ff670104
commit dedaf9d8ef
Signed by: roypur
GPG Key ID: 063DAA01D56E28CB

36
src/enter_vpn.c Normal file
View File

@ -0,0 +1,36 @@
#define _GNU_SOURCE
#include <sched.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
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;
}