summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Nelson <pete.nelson@unitedlex.com>2016-02-11 19:03:59 -0500
committerPete Nelson <pete.nelson@unitedlex.com>2016-02-11 19:03:59 -0500
commit792fa6373244c732d97ff69799b7739326774784 (patch)
tree5f3b8196519a4d95de4858d95bb7337994dacda6
parent0de3b331ec8daceb9f3785baeb7301b3df688087 (diff)
downloadopenvpn-duo-plugin-792fa6373244c732d97ff69799b7739326774784.tar.gz
openvpn-duo-plugin-792fa6373244c732d97ff69799b7739326774784.zip
add second fork for proper daemonize
-rw-r--r--duo_openvpn.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/duo_openvpn.c b/duo_openvpn.c
index d7db313..b4ba6eb 100644
--- a/duo_openvpn.c
+++ b/duo_openvpn.c
@@ -67,10 +67,32 @@ auth_user_pass_verify(struct context *ctx, const char *args[], const char *envp[
}
if (pid > 0) {
+ int status;
+
+ /* openvpn process forked ok, wait for first child to exit and return its status */
+ pid = waitpid(pid, &status, 0);
+ if (pid < 0) {
+ return OPENVPN_PLUGIN_FUNC_ERROR;
+ }
+
+ if (WIFEXITED(status)) {
+ return WEXITSTATUS(status);
+ }
+
+ return OPENVPN_PLUGIN_FUNC_ERROR;
+ }
+
+ pid = fork();
+ if (pid < 0) {
+ return OPENVPN_PLUGIN_FUNC_ERROR;
+ }
+
+ if (pid > 0) {
+ /* first child forked ok, pass deferred return up to parent openvpn process */
return OPENVPN_PLUGIN_FUNC_DEFERRED;
}
- /* daemonize so PID 1 can reap */
+ /* second child daemonizes so PID 1 can reap */
umask(0);
setsid();
chdir("/");