mirror of https://github.com/OpenVPN/openvpn-gui
remove support for openvpn version < 2.0
parent
e16665bee6
commit
7c4bea3f7e
|
@ -226,7 +226,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "Erstellen des RichEdit LogWindow fehlgeschlagen!!"
|
||||
IDS_ERR_SET_SIZE "Setzen der Grösse ist fehlgeschlagen!"
|
||||
IDS_ERR_AUTOSTART_CONF "Kann gewünschte Konfigurationdatei für Autostart nicht finden: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() beim überprüfen der OpenVPN version fehlgeschlagen."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe an hInputRead fehlgeschlagen."
|
||||
IDS_NFO_STATE_CONNECTING "Aktueller Status: Verbinden"
|
||||
IDS_NFO_CONNECTION_XXX "OpenVPN Verbindung (%s)"
|
||||
|
|
|
@ -221,7 +221,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "Creating RichEdit LogWindow Failed!!"
|
||||
IDS_ERR_SET_SIZE "Set Size failed!"
|
||||
IDS_ERR_AUTOSTART_CONF "Cannot find requested config to autostart: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() failed when checking openvpn version."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe on hInputRead failed."
|
||||
IDS_NFO_STATE_CONNECTING "Current State: Connecting"
|
||||
IDS_NFO_CONNECTION_XXX "OpenVPN Connection (%s)"
|
||||
|
|
|
@ -208,7 +208,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "La creación de RichEdit LogWindow falló!!"
|
||||
IDS_ERR_SET_SIZE "Set Size falló!"
|
||||
IDS_ERR_AUTOSTART_CONF "No se encuentra la configuración requerida para el autoinicio: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() falló al chequear la versión de OpenVPN."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe on hInputRead falló."
|
||||
IDS_NFO_STATE_CONNECTING "Estado actual: Conectando"
|
||||
IDS_NFO_CONNECTION_XXX "Conexión OpenVPN (%s)"
|
||||
|
|
|
@ -221,7 +221,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "RichEdit LogWindowin luonti epäonnistui!"
|
||||
IDS_ERR_SET_SIZE "Koon määrittäminen epäonnistui!"
|
||||
IDS_ERR_AUTOSTART_CONF "Ei löydetty automaattisesti käynnistettävää asetustiedostoa %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() failed when checking openvpn version."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe on hInputRead failed."
|
||||
IDS_NFO_STATE_CONNECTING "Tila: Yhdistetään"
|
||||
IDS_NFO_CONNECTION_XXX "OpenVPN-yhteys (%s)"
|
||||
|
|
|
@ -219,7 +219,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "Creating RichEdit LogWindow échoué !"
|
||||
IDS_ERR_SET_SIZE "Set Size échoué !"
|
||||
IDS_ERR_AUTOSTART_CONF "Impossible de trouver la configuration pour démarrer automatiquement: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() échoué après vérification de la version OpenVPN."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe sur hInputRead échoué."
|
||||
IDS_NFO_STATE_CONNECTING "Etat actuel: En cours de connexion"
|
||||
IDS_NFO_CONNECTION_XXX "Connexion OpenVPN (%s)"
|
||||
|
|
|
@ -207,7 +207,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "Creazione RichEdit LogWindow Fallita!!"
|
||||
IDS_ERR_SET_SIZE "Set Size fallita!"
|
||||
IDS_ERR_AUTOSTART_CONF "Non riesco a trovare una configurazione per partire in automatico: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() fallito quando ha cercato la versione di openvpn."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe on hInputRead falito."
|
||||
IDS_NFO_STATE_CONNECTING "Stato corrente: Connessione in corso"
|
||||
IDS_NFO_CONNECTION_XXX "Connessione OpenVPN (%s)"
|
||||
|
|
|
@ -207,7 +207,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "Creatie van RichEdit LogWindow mislukt!"
|
||||
IDS_ERR_SET_SIZE "Instellen afmetingen mislukt!"
|
||||
IDS_ERR_AUTOSTART_CONF "Kan opgegeven configuratie voor automatische verbinding niet vinden: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() mislukt tijdens verificatie OpenVPN versie."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe tijdens hInputRead mislukt."
|
||||
IDS_NFO_STATE_CONNECTING "Huidige Status: Verbinden"
|
||||
IDS_NFO_CONNECTION_XXX "OpenVPN Verbinding (%s)"
|
||||
|
|
|
@ -212,7 +212,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "Opprettelse av RichEdit LogWindow feilet!!"
|
||||
IDS_ERR_SET_SIZE "Set Size feilet!"
|
||||
IDS_ERR_AUTOSTART_CONF "Følgende konfig kunne ikke starte automatisk: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() feilet under sjekk av openvpn version."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe på hInputRead feilet."
|
||||
IDS_NFO_STATE_CONNECTING "Status: Kobler til"
|
||||
IDS_NFO_CONNECTION_XXX "OpenVPN Tilkoblet (%s)"
|
||||
|
|
|
@ -208,7 +208,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "Creating RichEdit LogWindow falhou!!"
|
||||
IDS_ERR_SET_SIZE "Set Size falhou!"
|
||||
IDS_ERR_AUTOSTART_CONF "Impossível encontrar configurações para autostart: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() falhou ao verificar a versão do openvpn."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe em hInputRead falhou."
|
||||
IDS_NFO_STATE_CONNECTING "Estado atual: Conectando"
|
||||
IDS_NFO_CONNECTION_XXX "Conexão OpenVPN (%s)"
|
||||
|
|
|
@ -213,7 +213,6 @@ BEGIN
|
|||
IDS_ERR_CREATE_EDIT_LOGWINDOW "Skapande av RichEdit LogWindow misslyckades!!"
|
||||
IDS_ERR_SET_SIZE "Set Size misslyckades!"
|
||||
IDS_ERR_AUTOSTART_CONF "Följande konfig gick inte att automatiskt starta: %s"
|
||||
IDS_ERR_VERSION_CREATE_EVENT "CreateEvent() misslyckades vid kontroll av openvpn version."
|
||||
IDS_ERR_CREATE_PIPE_IN_READ "CreatePipe på hInputRead misslyckades."
|
||||
IDS_NFO_STATE_CONNECTING "Status: Ansluter"
|
||||
IDS_NFO_CONNECTION_XXX "OpenVPN Anslutning (%s)"
|
||||
|
|
|
@ -152,7 +152,6 @@
|
|||
#define IDS_ERR_CREATE_EDIT_LOGWINDOW 1236
|
||||
#define IDS_ERR_SET_SIZE 1237
|
||||
#define IDS_ERR_AUTOSTART_CONF 1238
|
||||
#define IDS_ERR_VERSION_CREATE_EVENT 1239
|
||||
#define IDS_ERR_CREATE_PIPE_IN_READ 1240
|
||||
#define IDS_NFO_STATE_CONNECTING 1241
|
||||
#define IDS_NFO_CONNECTION_XXX 1242
|
||||
|
|
503
openvpn.c
503
openvpn.c
|
@ -2,6 +2,7 @@
|
|||
* OpenVPN-GUI -- A Windows GUI for OpenVPN.
|
||||
*
|
||||
* Copyright (C) 2004 Mathias Sundman <mathias@nilings.se>
|
||||
* 2010 Heiko Hund <heikoh@users.sf.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -23,7 +24,6 @@
|
|||
* <jim@yonan.net>.
|
||||
*/
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -48,50 +48,20 @@
|
|||
extern options_t o;
|
||||
|
||||
/*
|
||||
* Creates a unique exit_event name based on the
|
||||
* Creates a unique exit_event name based on the
|
||||
* config file number.
|
||||
*/
|
||||
int CreateExitEvent(int config)
|
||||
static BOOL
|
||||
CreateExitEvent(int config)
|
||||
{
|
||||
o.conn[config].exit_event = NULL;
|
||||
if (o.oldversion == 1)
|
||||
{
|
||||
_sntprintf_0(o.conn[config].exit_event_name, _T("openvpn_exit"));
|
||||
o.conn[config].exit_event = CreateEvent (NULL,
|
||||
TRUE,
|
||||
FALSE,
|
||||
o.conn[config].exit_event_name);
|
||||
if (o.conn[config].exit_event == NULL)
|
||||
{
|
||||
if (GetLastError() == ERROR_ACCESS_DENIED)
|
||||
{
|
||||
/* service mustn't be running, while using old version */
|
||||
ShowLocalizedMsg(IDS_ERR_STOP_SERV_OLD_VER);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* error creating exit event */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.conn[config].exit_event_name);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
_sntprintf_0(o.conn[config].exit_event_name, _T("openvpngui_exit_event_%d"), config);
|
||||
o.conn[config].exit_event = CreateEvent(NULL, TRUE, FALSE, o.conn[config].exit_event_name);
|
||||
if (o.conn[config].exit_event == NULL) {
|
||||
/* error creating exit event */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.conn[config].exit_event_name);
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
_sntprintf_0(o.conn[config].exit_event_name, _T("openvpngui_exit_event_%d"), config);
|
||||
o.conn[config].exit_event = CreateEvent (NULL,
|
||||
TRUE,
|
||||
FALSE,
|
||||
o.conn[config].exit_event_name);
|
||||
if (o.conn[config].exit_event == NULL)
|
||||
{
|
||||
/* error creating exit event */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.conn[config].exit_event_name);
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
return(true);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,16 +94,69 @@ int SetProcessPriority(DWORD *priority)
|
|||
}
|
||||
|
||||
|
||||
static BOOL
|
||||
GetPipeHandles(PHANDLE phInputRead, PHANDLE phInputWrite,
|
||||
PHANDLE phOutputRead, PHANDLE phOutputWrite)
|
||||
{
|
||||
HANDLE hProc = GetCurrentProcess();
|
||||
HANDLE hOutputReadTmp, hInputWriteTmp;
|
||||
SECURITY_DESCRIPTOR sd;
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
|
||||
CLEAR(sa);
|
||||
CLEAR(sd);
|
||||
|
||||
/* Make security attributes for the pipes so they can be inherited */
|
||||
sa.nLength = sizeof(sa);
|
||||
sa.lpSecurityDescriptor = &sd;
|
||||
sa.bInheritHandle = TRUE;
|
||||
if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) {
|
||||
ShowLocalizedMsg(IDS_ERR_INIT_SEC_DESC);
|
||||
return FALSE;
|
||||
}
|
||||
if (!SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE)) {
|
||||
ShowLocalizedMsg(IDS_ERR_SET_SEC_DESC_ACL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Create the stdin pipe with uninheritable write end */
|
||||
if (!CreatePipe(phInputRead, &hInputWriteTmp, &sa, 0)) {
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_IN_READ);
|
||||
return FALSE;
|
||||
}
|
||||
if (!DuplicateHandle(hProc, hInputWriteTmp, hProc, phInputWrite, 0, FALSE,
|
||||
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
|
||||
ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_IN_WRITE);
|
||||
CloseHandle(*phInputRead);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Create the stdout pipe with uninheritable read end */
|
||||
if (!CreatePipe(&hOutputReadTmp, phOutputWrite, &sa, 0)) {
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_OUTPUT);
|
||||
CloseHandle(*phInputRead);
|
||||
CloseHandle(*phInputWrite);
|
||||
return FALSE;
|
||||
}
|
||||
if (!DuplicateHandle(hProc, hOutputReadTmp, hProc, phOutputRead, 0, FALSE,
|
||||
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
|
||||
ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_OUT_READ);
|
||||
CloseHandle(*phInputRead);
|
||||
CloseHandle(*phInputWrite);
|
||||
CloseHandle(*phOutputWrite);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Launch an OpenVPN process
|
||||
*/
|
||||
int StartOpenVPN(int config)
|
||||
{
|
||||
|
||||
HANDLE hOutputReadTmp = NULL;
|
||||
HANDLE hOutputRead = NULL;
|
||||
HANDLE hOutputWrite = NULL;
|
||||
HANDLE hInputWriteTmp = NULL;
|
||||
HANDLE hInputRead = NULL;
|
||||
HANDLE hInputWrite = NULL;
|
||||
HANDLE hErrorWrite = NULL;
|
||||
|
@ -143,37 +166,11 @@ int StartOpenVPN(int config)
|
|||
DWORD priority;
|
||||
STARTUPINFO start_info;
|
||||
PROCESS_INFORMATION proc_info;
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
SECURITY_DESCRIPTOR sd;
|
||||
TCHAR command_line[256];
|
||||
TCHAR proxy_string[100];
|
||||
int i, is_connected=0;
|
||||
|
||||
CLEAR (start_info);
|
||||
CLEAR (proc_info);
|
||||
CLEAR (sa);
|
||||
CLEAR (sd);
|
||||
|
||||
|
||||
/* If oldversion, allow only ONE connection */
|
||||
if (o.oldversion == 1)
|
||||
{
|
||||
for (i=0; i < o.num_configs; i++)
|
||||
{
|
||||
if ((o.conn[i].state != disconnected) &&
|
||||
(o.conn[i].state != disconnecting))
|
||||
{
|
||||
is_connected=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_connected)
|
||||
{
|
||||
/* only one simultanious connection on old version */
|
||||
ShowLocalizedMsg(IDS_ERR_ONE_CONN_OLD_VER);
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
/* Warn if "log" or "log-append" option is found in config file */
|
||||
if ((ConfigFileOptionExist(config, "log ")) ||
|
||||
|
@ -207,46 +204,13 @@ int StartOpenVPN(int config)
|
|||
ConstructProxyCmdLine(proxy_string, _tsizeof(proxy_string));
|
||||
|
||||
/* construct command line */
|
||||
if (o.oldversion == 1)
|
||||
{
|
||||
_sntprintf_0(command_line, _T("openvpn --config \"%s\" %s"),
|
||||
o.conn[config].config_file, proxy_string);
|
||||
}
|
||||
else
|
||||
{
|
||||
_sntprintf_0(command_line, _T("openvpn --service %s 0 --config \"%s\" %s"),
|
||||
o.conn[config].exit_event_name,
|
||||
o.conn[config].config_file,
|
||||
proxy_string);
|
||||
}
|
||||
_sntprintf_0(command_line, _T("openvpn --service %s 0 --config \"%s\" %s"),
|
||||
o.conn[config].exit_event_name,
|
||||
o.conn[config].config_file,
|
||||
proxy_string);
|
||||
|
||||
|
||||
/* Make security attributes struct for logfile handle so it can
|
||||
be inherited. */
|
||||
sa.nLength = sizeof (sa);
|
||||
sa.lpSecurityDescriptor = &sd;
|
||||
sa.bInheritHandle = TRUE;
|
||||
if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION))
|
||||
{
|
||||
/* Init Sec. Desc. failed */
|
||||
ShowLocalizedMsg(IDS_ERR_INIT_SEC_DESC);
|
||||
goto failed;
|
||||
}
|
||||
if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE))
|
||||
{
|
||||
/* set Dacl failed */
|
||||
ShowLocalizedMsg(IDS_ERR_SET_SEC_DESC_ACL);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
||||
/* Create the child output pipe. */
|
||||
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0))
|
||||
{
|
||||
/* CreatePipe failed. */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_OUTPUT);
|
||||
goto failed;
|
||||
}
|
||||
if (!GetPipeHandles(&hInputRead, &hInputWrite, &hOutputRead, &hOutputWrite))
|
||||
return false;
|
||||
|
||||
// Create a duplicate of the output write handle for the std error
|
||||
// write handle. This is necessary in case the child application
|
||||
|
@ -260,50 +224,6 @@ int StartOpenVPN(int config)
|
|||
goto failed;
|
||||
}
|
||||
|
||||
// Create the child input pipe.
|
||||
if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0))
|
||||
{
|
||||
/* CreatePipe failed. */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_INPUT);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
// Create new output read handle and the input write handles. Set
|
||||
// the Properties to FALSE. Otherwise, the child inherits the
|
||||
// properties and, as a result, non-closeable handles to the pipes
|
||||
// are created.
|
||||
if (!DuplicateHandle(GetCurrentProcess(),hOutputReadTmp,
|
||||
GetCurrentProcess(),
|
||||
&hOutputRead, // Address of new handle.
|
||||
0,FALSE, // Make it uninheritable.
|
||||
DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
/* Duplicate Handle failed. */
|
||||
ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_OUT_READ);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (!DuplicateHandle(GetCurrentProcess(),hInputWriteTmp,
|
||||
GetCurrentProcess(),
|
||||
&hInputWrite, // Address of new handle.
|
||||
0,FALSE, // Make it uninheritable.
|
||||
DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
/* DuplicateHandle failed */
|
||||
ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_IN_WRITE);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
/* Close inheritable copies of the handles */
|
||||
if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp))
|
||||
{
|
||||
/* Close Handle failed */
|
||||
ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE_TMP);
|
||||
CloseHandle (o.conn[config].exit_event);
|
||||
return(0);
|
||||
}
|
||||
hOutputReadTmp=NULL;
|
||||
hInputWriteTmp=NULL;
|
||||
|
||||
/* fill in STARTUPINFO struct */
|
||||
GetStartupInfo(&start_info);
|
||||
|
@ -623,242 +543,67 @@ int VerifyAutoConnections()
|
|||
}
|
||||
|
||||
|
||||
int CheckVersion()
|
||||
BOOL
|
||||
CheckVersion()
|
||||
{
|
||||
HANDLE hOutputReadTmp = NULL;
|
||||
HANDLE hOutputRead = NULL;
|
||||
HANDLE hOutputWrite = NULL;
|
||||
HANDLE hInputWriteTmp = NULL;
|
||||
HANDLE hInputRead = NULL;
|
||||
HANDLE hInputWrite = NULL;
|
||||
HANDLE exit_event;
|
||||
HANDLE hOutputRead;
|
||||
HANDLE hOutputWrite;
|
||||
HANDLE hInputRead;
|
||||
HANDLE hInputWrite;
|
||||
|
||||
STARTUPINFO start_info;
|
||||
PROCESS_INFORMATION proc_info;
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
SECURITY_DESCRIPTOR sd;
|
||||
TCHAR command_line[256];
|
||||
char line[1024];
|
||||
TCHAR bin_path[MAX_PATH];
|
||||
char *p;
|
||||
int oldversion, i;
|
||||
BOOL retval = FALSE;
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
TCHAR cmdline[] = _T("openvpn --version");
|
||||
char match_version[] = "OpenVPN 2.";
|
||||
TCHAR pwd[MAX_PATH];
|
||||
char line[1024];
|
||||
TCHAR *p;
|
||||
|
||||
CLEAR (start_info);
|
||||
CLEAR (proc_info);
|
||||
CLEAR (sa);
|
||||
CLEAR (sd);
|
||||
|
||||
exit_event = CreateEvent (NULL, TRUE, FALSE, _T("openvpn_exit"));
|
||||
if (exit_event == NULL)
|
||||
{
|
||||
CLEAR(si);
|
||||
CLEAR(pi);
|
||||
|
||||
if (!GetPipeHandles(&hInputRead, &hInputWrite, &hOutputRead, &hOutputWrite))
|
||||
return FALSE;
|
||||
|
||||
/* Construct the process' working directory */
|
||||
_tcsncpy(pwd, o.exe_path, _tsizeof(pwd));
|
||||
p = _tcsrchr(pwd, _T('\\'));
|
||||
if (p != NULL)
|
||||
*p = _T('\0');
|
||||
|
||||
/* Fill in STARTUPINFO struct */
|
||||
si.cb = sizeof(si);
|
||||
si.dwFlags = STARTF_USESTDHANDLES;
|
||||
si.hStdInput = hInputRead;
|
||||
si.hStdOutput = hOutputWrite;
|
||||
si.hStdError = hOutputWrite;
|
||||
|
||||
/* Start OpenVPN to check version */
|
||||
if (!CreateProcess(o.exe_path, cmdline, NULL, NULL, TRUE,
|
||||
CREATE_NO_WINDOW, NULL, pwd, &si, &pi)) {
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS, o.exe_path, cmdline, pwd);
|
||||
}
|
||||
else if (ReadLineFromStdOut(hOutputRead, 0, line)) {
|
||||
#ifdef DEBUG
|
||||
PrintErrorDebug("CreateEvent(openvpn_exit) failed.");
|
||||
PrintDebug("VersionString: %s", line);
|
||||
#endif
|
||||
if (GetLastError() == ERROR_ACCESS_DENIED)
|
||||
{
|
||||
/* Assume we're running OpenVPN 1.5/1.6 and the service is started. */
|
||||
o.oldversion=1;
|
||||
strncpy(o.connect_string, "Successful ARP Flush", sizeof(o.connect_string));
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* CreateEvent failed */
|
||||
ShowLocalizedMsg(IDS_ERR_VERSION_CREATE_EVENT);
|
||||
return(false);
|
||||
}
|
||||
CloseHandle(pi.hThread);
|
||||
CloseHandle(pi.hProcess);
|
||||
|
||||
/* OpenVPN version 2.x */
|
||||
if (strstr(line, match_version))
|
||||
retval = TRUE;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
PrintErrorDebug("CreateEvent(openvpn_exit) succeded.");
|
||||
#endif
|
||||
if (!CloseHandle(hInputRead) || !CloseHandle(hInputWrite)
|
||||
|| !CloseHandle(hOutputRead) || !CloseHandle(hOutputWrite))
|
||||
ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE);
|
||||
|
||||
/* construct command line */
|
||||
_sntprintf_0(command_line, _T("openvpn --version"));
|
||||
|
||||
/* construct bin path */
|
||||
_tcsncpy(bin_path, o.exe_path, _tsizeof(bin_path));
|
||||
for (i=_tcslen(bin_path) - 1; i > 0; i--)
|
||||
if (bin_path[i] == '\\') break;
|
||||
bin_path[i] = '\0';
|
||||
|
||||
/* Make security attributes struct for logfile handle so it can
|
||||
be inherited. */
|
||||
sa.nLength = sizeof (sa);
|
||||
sa.lpSecurityDescriptor = &sd;
|
||||
sa.bInheritHandle = TRUE;
|
||||
if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION))
|
||||
{
|
||||
/* Init Sec. Desc. failed */
|
||||
ShowLocalizedMsg(IDS_ERR_INIT_SEC_DESC);
|
||||
return(0);
|
||||
}
|
||||
if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE))
|
||||
{
|
||||
/* Set Dacl failed */
|
||||
ShowLocalizedMsg(IDS_ERR_SET_SEC_DESC_ACL);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Create the child input pipe. */
|
||||
if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0))
|
||||
{
|
||||
/* create pipe failed */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_IN_READ);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Create the child output pipe. */
|
||||
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0))
|
||||
{
|
||||
/* CreatePipe failed */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_OUTPUT);
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (!DuplicateHandle(GetCurrentProcess(),hOutputReadTmp,
|
||||
GetCurrentProcess(),
|
||||
&hOutputRead, // Address of new handle.
|
||||
0,FALSE, // Make it uninheritable.
|
||||
DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
/* DuplicateHandle failed */
|
||||
ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_OUT_READ);
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (!DuplicateHandle(GetCurrentProcess(),hInputWriteTmp,
|
||||
GetCurrentProcess(),
|
||||
&hInputWrite, // Address of new handle.
|
||||
0,FALSE, // Make it uninheritable.
|
||||
DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
/* DuplicateHandle failed */
|
||||
ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_IN_WRITE);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/* Close inheritable copies of the handles */
|
||||
if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp))
|
||||
{
|
||||
/* CloseHandle failed */
|
||||
ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE_TMP);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* fill in STARTUPINFO struct */
|
||||
GetStartupInfo(&start_info);
|
||||
start_info.cb = sizeof(start_info);
|
||||
start_info.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||
start_info.wShowWindow = SW_HIDE;
|
||||
start_info.hStdInput = hInputRead;
|
||||
start_info.hStdOutput = hOutputWrite;
|
||||
start_info.hStdError = hOutputWrite;
|
||||
|
||||
/* Start OpenVPN to check version */
|
||||
if (!CreateProcess(o.exe_path,
|
||||
command_line,
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE,
|
||||
CREATE_NEW_CONSOLE,
|
||||
NULL,
|
||||
bin_path,
|
||||
&start_info,
|
||||
&proc_info))
|
||||
{
|
||||
/* CreateProcess failed */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS,
|
||||
o.exe_path,
|
||||
command_line,
|
||||
bin_path);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Default value for oldversion */
|
||||
oldversion=0;
|
||||
|
||||
/* Default string to look for to report "Connected". */
|
||||
strncpy(o.connect_string, "Successful ARP Flush", sizeof(o.connect_string));
|
||||
|
||||
if (ReadLineFromStdOut(hOutputRead, 0, line) == 1)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
PrintDebug("VersionString: %s", line);
|
||||
#endif
|
||||
if (line[8] == '2') /* Majorversion = 2 */
|
||||
{
|
||||
if (line[10] == '0') /* Minorversion = 0 */
|
||||
{
|
||||
p=strstr(line, "beta");
|
||||
if (p != NULL)
|
||||
{
|
||||
if (p[5] == ' ') /* 2.0-beta1 - 2.0-beta9 */
|
||||
{
|
||||
if (p[4] >= '6') /* 2.0-beta6 - 2.0-beta9 */
|
||||
{
|
||||
oldversion=0;
|
||||
}
|
||||
else /* < 2.0-beta6 */
|
||||
{
|
||||
oldversion=1;
|
||||
}
|
||||
}
|
||||
else /* >= 2.0-beta10 */
|
||||
{
|
||||
if (strncmp(&p[6], "ms", 2) == 0) /* 2.0-betaXXms */
|
||||
strncpy(o.connect_string, "Initialization Sequence Completed",
|
||||
sizeof(o.connect_string));
|
||||
if ( !((p[4] == 1) && (p[5] == 0)) ) /* >= 2.0-beta11 */
|
||||
strncpy(o.connect_string, "Initialization Sequence Completed",
|
||||
sizeof(o.connect_string));
|
||||
|
||||
oldversion=0;
|
||||
}
|
||||
}
|
||||
else /* 2.0 non-beta */
|
||||
{
|
||||
strncpy(o.connect_string, "Initialization Sequence Completed",
|
||||
sizeof(o.connect_string));
|
||||
oldversion=0;
|
||||
}
|
||||
}
|
||||
else /* > 2.0 */
|
||||
{
|
||||
strncpy(o.connect_string, "Initialization Sequence Completed",
|
||||
sizeof(o.connect_string));
|
||||
oldversion=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (line[8] == '1') /* Majorversion = 1 */
|
||||
{
|
||||
oldversion=1;
|
||||
}
|
||||
else /* Majorversion != (1 || 2) */
|
||||
{
|
||||
oldversion=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else return(0);
|
||||
|
||||
o.oldversion = oldversion;
|
||||
|
||||
|
||||
if(!CloseHandle (proc_info.hThread) || !CloseHandle (hOutputWrite)
|
||||
|| !CloseHandle (hInputRead) || !CloseHandle(exit_event))
|
||||
{
|
||||
/* CloseHandle failed */
|
||||
ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE);
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(1);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
void CheckAndSetTrayIcon()
|
||||
{
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char line[1024]);
|
|||
BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
int AutoStartConnections();
|
||||
int VerifyAutoConnections();
|
||||
int CheckVersion();
|
||||
BOOL CheckVersion();
|
||||
void CheckAndSetTrayIcon();
|
||||
void SetStatusWinIcon(HWND hwndDlg, int IconID);
|
||||
void ThreadOpenVPNStatus(int status) __attribute__ ((noreturn));
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
|
||||
extern options_t o;
|
||||
|
||||
static const char connect_string[] = "Initialization Sequence Completed";
|
||||
|
||||
/* Wait for a complete line (CR/LF) and return it.
|
||||
* Return values:
|
||||
* 1 - Successful. Line is available in *line.
|
||||
|
@ -197,7 +199,7 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
|
|||
char *linepos;
|
||||
|
||||
/* Check for Connected message */
|
||||
if (strstr(line, o.connect_string) != NULL)
|
||||
if (strstr(line, connect_string) != NULL)
|
||||
{
|
||||
/* Run Connect Script */
|
||||
RunConnectScript(config, false);
|
||||
|
@ -317,7 +319,7 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
|
|||
size_t i;
|
||||
|
||||
/* Check for Connected message */
|
||||
if (strstr(line, o.connect_string) != NULL)
|
||||
if (strstr(line, connect_string) != NULL)
|
||||
{
|
||||
o.conn[config].state = connected;
|
||||
SetTrayIcon(connected);
|
||||
|
|
|
@ -97,9 +97,7 @@ typedef struct {
|
|||
connection_t conn[MAX_CONFIGS]; /* Connection structure */
|
||||
int num_configs; /* Number of configs */
|
||||
|
||||
BOOL oldversion; /* OpenVPN version below 2.0-beta6 if TRUE */
|
||||
service_state_t service_state; /* State of the OpenVPN Service */
|
||||
char connect_string[100]; /* String to look for to report connected */
|
||||
int psw_attempts; /* Number of psw attemps to allow */
|
||||
int connectscript_timeout; /* Connect Script execution timeout (sec) */
|
||||
int disconnectscript_timeout; /* Disconnect Script execution timeout (sec) */
|
||||
|
|
Loading…
Reference in New Issue