Go to the documentation of this file.
65 buf_printf(&out,
"disallowed by script-security setting");
70 buf_printf(&out,
"external program did not execute -- ");
74 buf_printf(&out,
"returned error code %d", stat);
79 buf_printf(&out,
"external program fork failed");
85 buf_printf(&out,
"external program did not exit normally");
89 const int cmd_ret = WEXITSTATUS(stat);
92 buf_printf(&out,
"external program exited normally");
96 buf_printf(&out,
"could not execute external program");
100 buf_printf(&out,
"external program exited with error status: %d", cmd_ret);
106 return (
const char *)out.
data;
136 static bool warn_shown =
false;
140 #if defined(ENABLE_FEATURE_EXECVE)
143 const char *cmd = a->
argv[0];
151 execve(cmd,
argv, envp);
154 else if (pid < (pid_t)0)
156 msg(
M_ERR,
"openvpn_execve: unable to fork");
160 if (waitpid(pid, &ret, 0) != pid)
176 msg(
M_WARN,
"openvpn_execve: execve function not available");
181 msg(
M_FATAL,
"openvpn_execve: called with empty argv");
237 #if defined(ENABLE_FEATURE_EXECVE)
238 static bool warn_shown =
false;
241 const char *cmd = a->
argv[0];
247 if (pipe(pipe_stdout) == 0)
252 close(pipe_stdout[0]);
253 dup2(pipe_stdout[1], 1);
254 execve(cmd,
argv, envp);
257 else if (pid > (pid_t)0)
261 close(pipe_stdout[1]);
263 ret = pipe_stdout[0];
267 close(pipe_stdout[0]);
268 close(pipe_stdout[1]);
269 msg(
M_ERR,
"openvpn_popen: unable to fork %s", cmd);
274 msg(
M_WARN,
"openvpn_popen: unable to create stdout pipe for %s", cmd);
284 msg(
M_WARN,
"openvpn_popen: execve function not available");
289 msg(
M_FATAL,
"openvpn_popen: called with empty argv");
static struct gc_arena gc_new(void)
void script_security_set(int level)
#define OPENVPN_EXECVE_ERROR
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
int openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
static const char * system_error_message(int stat, struct gc_arena *gc)
#define OPENVPN_EXECVE_NOT_ALLOWED
static int script_security_level
Wrapper structure for dynamically allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
bool openvpn_execve_allowed(const unsigned int flags)
#define S_EXITCODE
Instead of returning 1/0 for success/fail, return exit code when between 0 and 255 and -1 otherwise.
static SERVICE_STATUS status
static void gc_free(struct gc_arena *a)
int openvpn_popen(const struct argv *a, const struct env_set *es)
#define SCRIPT_SECURITY_WARNING
#define OPENVPN_EXECVE_FAILURE
const char ** make_env_array(const struct env_set *es, const bool check_allowed, struct gc_arena *gc)
bool buf_printf(struct buffer *buf, const char *format,...)
int openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags)
int script_security(void)
uint8_t * data
Pointer to the allocated memory.