Skip to contentSkip to conversation

Fix Windows script execution when called from script hooks

PATCH In review Josh Cepek 3 participants 5 messages May 11, 2013 – May 19, 2013

lore
Share & tools
lore

Josh Cepek

author
#0 lore raw

PATCH 1/1 Fix Windows script execution when called from script hooks

Console applications under Windows, such as batch scripts, require the CREATE_NO_WINDOW process flag when run without an actual console window present. This change allows such scripts to execute and impact the hook status by way of their return code.

Fixes bug #240.

---
 src/openvpn/win32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/openvpn/win32.c +4 -1
index 2db96a8..291124e 100644
@@ -879,7 +879,10 @@ openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned i
           start_info.dwFlags = STARTF_USESHOWWINDOW;
           start_info.wShowWindow = SW_HIDE;
 
-          if (CreateProcessW (cmd, cl, NULL, NULL, FALSE, 0, env, NULL, &start_info, &proc_info))
+          /* this allows console programs to run, and is ignored otherwise */
+          unsigned int proc_flags = CREATE_NO_WINDOW;
+
+          if (CreateProcessW (cmd, cl, NULL, NULL, FALSE, proc_flags, env, NULL, &start_info, &proc_info))
             {
               DWORD exit_status = 0;
               CloseHandle (proc_info.hThread);
Signature · 1 line
1.8.1.5
#1 lore raw
Quoted 1 line · On Saturday 11 May 2013 14:00:24 Josh Cepek wrote:

/* this allows console programs to run, and is ignored otherwise */

ACK, because it's the truth. =)

Quoted 1 line

unsigned int proc_flags = CREATE_NO_WINDOW;

However, this should be a DWORD instead of unsigned int.

Regards
Heiko

Signature · 2 lines
Heiko Hund | Sr. Software Engineer | Tel +49-721-25516-237 | Fax -200
SOPHOS NSG | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
author
#2 lore raw

Console applications under Windows, such as batch scripts, require the CREATE_NO_WINDOW process flag when run without an actual console window present. This change allows such scripts to execute and impact the hook status by way of their return code.

Fixes bug #240.

---
 src/openvpn/win32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/openvpn/win32.c +4 -1
index 2db96a8..178e2c3 100644
@@ -879,7 +879,10 @@ openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned i
           start_info.dwFlags = STARTF_USESHOWWINDOW;
           start_info.wShowWindow = SW_HIDE;
 
-          if (CreateProcessW (cmd, cl, NULL, NULL, FALSE, 0, env, NULL, &start_info, &proc_info))
+          /* this allows console programs to run, and is ignored otherwise */
+          DWORD proc_flags = CREATE_NO_WINDOW;
+
+          if (CreateProcessW (cmd, cl, NULL, NULL, FALSE, proc_flags, env, NULL, &start_info, &proc_info))
             {
               DWORD exit_status = 0;
               CloseHandle (proc_info.hThread);
Signature · 1 line
1.8.1.5
#3 lore raw
Quoted 4 lines · On Thursday 16 May 2013 09:09:23 Josh Cepek wrote:

Console applications under Windows, such as batch scripts, require the CREATE_NO_WINDOW process flag when run without an actual console window present. This change allows such scripts to execute and impact the hook status by way of their return code.

OK from my side for this.

Heiko

Signature · 2 lines
Heiko Hund | Sr. Software Engineer | Tel +49-721-25516-237 | Fax -200
SOPHOS NSG | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
#4 lore raw
In reply to Josh Cepek

Your patch has been applied to the master and release/2.3 branch.

commit a19e35a95bf4a0177ae115535a3755d3acd894e9 (master) commit 93ec740f94867e10980c8a87bd3c2a037b221f31 (release/2.3)

Author: Josh Cepek
Date:   Thu May 16 09:09:23 2013 -0500
     Fix Windows script execution when called from script hooks

     Signed-off-by: Josh Cepek <[email protected]...>
     Acked-by: Heiko Hund <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/7594
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering