From 68669f0ebca6c7412c5ca9d547d231d26be7568c Mon Sep 17 00:00:00 2001 From: Matthew Grooms Date: Wed, 17 Sep 2008 05:44:01 +0000 Subject: Add a new OpenVPN client configuration and installer export package. It will create and export a config file or pre-configured windows installer based on the server configuration and user information. --- .../openvpn-client-export/source/procchain.cpp | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 packages/openvpn-client-export/source/procchain.cpp (limited to 'packages/openvpn-client-export/source/procchain.cpp') diff --git a/packages/openvpn-client-export/source/procchain.cpp b/packages/openvpn-client-export/source/procchain.cpp new file mode 100755 index 00000000..b95536cc --- /dev/null +++ b/packages/openvpn-client-export/source/procchain.cpp @@ -0,0 +1,80 @@ + +/* + * Copyright (c) 2008 + * Shrew Soft Inc. All rights reserved. + * + * AUTHOR : Matthew Grooms + * mgrooms@shrew.net + * + */ + +#include +#include + +bool runproc( char * path ) +{ + STARTUPINFO si; + memset( &si, 0, sizeof( si ) ); + si.cb = sizeof( si ); + + PROCESS_INFORMATION pi; + memset( &pi, 0, sizeof( pi ) ); + + // Start the child process. + if( !CreateProcess( + NULL, // No module name (use command line). + path, // Command line. + NULL, // Process handle not inheritable. + NULL, // Thread handle not inheritable. + FALSE, // Set handle inheritance to FALSE. + 0, // No creation flags. + NULL, // Use parent's environment block. + NULL, // Use parent's starting directory. + &si, // Pointer to STARTUPINFO structure. + &pi ) ) // Pointer to PROCESS_INFORMATION structure. + { + return false; + } + + // Wait until child process exits. + WaitForSingleObject( pi.hProcess, INFINITE ); + + // Get the exit code + DWORD ExitCode; + GetExitCodeProcess( pi.hProcess, &ExitCode ); + + // Close process and thread handles. + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + + return ( ExitCode == 0 ); +} + +int APIENTRY WinMain( + HINSTANCE hinstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow ) +{ + FILE * fp; + if( fopen_s( &fp, lpCmdLine, "r" ) ) + return -1; + + while( true ) + { + char cmd[ MAX_PATH ]; + memset( cmd, 0, MAX_PATH ); + if( fgets( cmd, MAX_PATH, fp ) == NULL ) + break; + + char * term = strchr( cmd, '\n' ); + if( term != NULL ) + *term = 0; + + if( !runproc( cmd ) ) + return -2; + } + + return 0; +} + -- cgit v1.2.3