Created ovpnpermit project to wrap openvpn with a setuid executable.
[ovpnpermit.git] / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5
6 // This program will execute the openvpn executable
7 // passing in through the command line parameters
8 // The purpose is to allow openvpn to be executed
9 // as a different user (e.g. root)
10
11 int main (int argc, char *argv[]) {
12 char * const command = "openvpn";
13 char ** newargv = malloc (sizeof(char*) * (argc + 1));
14 int arg;
15
16 // Transfer the arguments passed in to a new argument array
17 for (arg = 0; arg < argc; arg++) {
18 newargv[arg] = argv[arg];
19 }
20 // Ensure the argument list is NULL terminated (for execvp)
21 newargv[argc] = NULL;
22 // Ensure the first argument matches the command
23 newargv[0] = command;
24
25 // Execute the external command
26 //setuid (0);
27 execvp (command, newargv);
28
29 // This part of the code shouldn't be reached
30 printf ("Error executing openvpn\n");
31
32 free (newargv);
33 return 0;
34 }
35