add launch tool
This commit is contained in:
parent
17ff670104
commit
dedaf9d8ef
36
src/enter_vpn.c
Normal file
36
src/enter_vpn.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user