65 buf_printf(&out,
"disallowed by script-security setting");
70 buf_printf(&out,
"external program did not execute -- ");
79 buf_printf(&out,
"external program fork failed");
85 buf_printf(&out,
"external program did not exit normally");
92 buf_printf(&out,
"external program exited normally");
96 buf_printf(&out,
"could not execute external program");
106 return (
const char *)out.
data;
130 msg(msglevel,
"%scould not execute external program (exit code 127)",
135 msg(msglevel,
"%sexternal program exited with error status: %d",
142 msg(msglevel,
"%sexternal program received signal %d",
177 static bool warn_shown =
false;
181#if defined(ENABLE_FEATURE_EXECVE)
184 const char *cmd = a->
argv[0];
192 execve(cmd,
argv, envp);
195 else if (pid < (pid_t)0)
197 msg(
M_ERR,
"openvpn_execve: unable to fork");
205 if (waitpid(pid, &ret, 0) != pid)
221 msg(
M_WARN,
"openvpn_execve: execve function not available");
226 msg(
M_FATAL,
"openvpn_execve: called with empty argv");
287#if defined(ENABLE_FEATURE_EXECVE)
288 static bool warn_shown =
false;
291 const char *cmd = a->
argv[0];
297 if (pipe(pipe_stdout) == 0)
302 close(pipe_stdout[0]);
303 dup2(pipe_stdout[1], 1);
304 execve(cmd,
argv, envp);
307 else if (pid > (pid_t)0)
311 close(pipe_stdout[1]);
313 ret = pipe_stdout[0];
317 close(pipe_stdout[0]);
318 close(pipe_stdout[1]);
319 msg(
M_ERR,
"openvpn_popen: unable to fork %s", cmd);
324 msg(
M_WARN,
"openvpn_popen: unable to create stdout pipe for %s", cmd);
334 msg(
M_WARN,
"openvpn_popen: execve function not available");
339 msg(
M_FATAL,
"openvpn_popen: called with empty argv");
bool buf_printf(struct buffer *buf, const char *format,...)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
static void gc_free(struct gc_arena *a)
static struct gc_arena gc_new(void)
#define SCRIPT_SECURITY_WARNING
const char ** make_env_array(const struct env_set *es, const bool check_allowed, struct gc_arena *gc)
static SERVICE_STATUS status
bool openvpn_execve_allowed(const unsigned int flags)
void script_security_set(int level)
int openvpn_popen(const struct argv *a, const struct env_set *es)
static const char * system_error_message(int stat, struct gc_arena *gc)
bool openvpn_waitpid_check(pid_t pid, const char *msg_prefix, int msglevel)
Checks if a running process is still running.
int openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
int script_security(void)
static int script_security_level
#define S_EXITCODE
Instead of returning 1/0 for success/fail, return exit code when between 0 and 255 and -1 otherwise.
#define OPENVPN_EXECVE_ERROR
#define OPENVPN_EXECVE_NOT_ALLOWED
#define S_NOWAITPID
instead of waiting for child process to exit and report the status, return the pid of the child proce...
#define OPENVPN_EXECVE_FAILURE
Wrapper structure for dynamically allocated memory.
uint8_t * data
Pointer to the allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
int openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags)