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)
11 int main (int argc
, char *argv
[]) {
12 char * const command
= "openvpn";
13 char ** newargv
= malloc (sizeof(char*) * (argc
+ 1));
16 if (newargv
!= NULL
) {
17 // Transfer the arguments passed in to a new argument array
18 for (arg
= 0; arg
< argc
; arg
++) {
19 newargv
[arg
] = argv
[arg
];
21 // Ensure the argument list is NULL terminated (for execvp)
23 // Ensure the first argument matches the command
26 // Execute the external command
28 execvp (command
, newargv
);
30 // This part of the code shouldn't be reached unless there was a problem
31 fprintf (stderr
, "Error executing openvpn\n");
36 // There was a problem with thee malloc call
37 fprintf (stderr
, "Error allocating memory for command argument list\n");