make it work when compiled as unicode

pull/1/head
Heiko Hund 2010-03-21 10:07:14 +01:00
parent f542c42738
commit 61cb987f4d
18 changed files with 410 additions and 373 deletions

View File

@ -69,7 +69,7 @@ GetGUILanguage(void)
LONG status = RegOpenKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, KEY_READ, &regkey); LONG status = RegOpenKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, KEY_READ, &regkey);
if (status == ERROR_SUCCESS) if (status == ERROR_SUCCESS)
GetRegistryValueNumeric(regkey, "ui_language", &value); GetRegistryValueNumeric(regkey, _T("ui_language"), &value);
gui_language = ( value != 0 ? value : LANGIDFROMLCID(GetThreadLocale()) ); gui_language = ( value != 0 ? value : LANGIDFROMLCID(GetThreadLocale()) );
return gui_language; return gui_language;
@ -82,9 +82,9 @@ SetGUILanguage(LANGID langId)
HKEY regkey; HKEY regkey;
if (RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, NULL, 0, if (RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, NULL, 0,
KEY_WRITE, NULL, &regkey, NULL) != ERROR_SUCCESS ) KEY_WRITE, NULL, &regkey, NULL) != ERROR_SUCCESS )
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU); ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
SetRegistryValueNumeric(regkey, "ui_language", langId); SetRegistryValueNumeric(regkey, _T("ui_language"), langId);
gui_language = langId; gui_language = langId;
} }
@ -175,11 +175,11 @@ LoadLocalizedStringBuf(PTSTR buffer, int bufferSize, const UINT stringId, ...)
void void
ShowLocalizedMsg(const PTSTR caption, const UINT stringId, ...) ShowLocalizedMsg(const UINT stringId, ...)
{ {
va_list args; va_list args;
va_start(args, stringId); va_start(args, stringId);
MessageBox(NULL, __LoadLocalizedString(stringId, args), caption, MB_OK | MB_SETFOREGROUND); MessageBox(NULL, __LoadLocalizedString(stringId, args), _T(PACKAGE_NAME), MB_OK | MB_SETFOREGROUND);
va_end(args); va_end(args);
} }

View File

@ -24,7 +24,7 @@
PTSTR LoadLocalizedString(const UINT, ...); PTSTR LoadLocalizedString(const UINT, ...);
int LoadLocalizedStringBuf(PTSTR, const int, const UINT, ...); int LoadLocalizedStringBuf(PTSTR, const int, const UINT, ...);
void ShowLocalizedMsg(const PTSTR, const UINT, ...); void ShowLocalizedMsg(const UINT, ...);
HICON LoadLocalizedIcon(const UINT); HICON LoadLocalizedIcon(const UINT);
LPCDLGTEMPLATE LocalizedDialogResource(const UINT); LPCDLGTEMPLATE LocalizedDialogResource(const UINT);
INT_PTR LocalizedDialogBoxParam(const UINT, DLGPROC, const LPARAM); INT_PTR LocalizedDialogBoxParam(const UINT, DLGPROC, const LPARAM);

26
main.c
View File

@ -50,15 +50,15 @@ static void ShowSettingsDialog();
void CloseApplication(HWND hwnd); void CloseApplication(HWND hwnd);
/* Class name and window title */ /* Class name and window title */
char szClassName[ ] = "OpenVPN-GUI"; TCHAR szClassName[ ] = _T("OpenVPN-GUI");
char szTitleText[ ] = "OpenVPN"; TCHAR szTitleText[ ] = _T("OpenVPN");
/* Options structure */ /* Options structure */
struct options o; struct options o;
int WINAPI WinMain (HINSTANCE hThisInstance, int WINAPI WinMain (HINSTANCE hThisInstance,
UNUSED HINSTANCE hPrevInstance, UNUSED HINSTANCE hPrevInstance,
LPSTR lpszArgument, UNUSED LPSTR lpszArgument,
UNUSED int nCmdShow) UNUSED int nCmdShow)
{ {
HWND hwnd; /* This is the handle for our window */ HWND hwnd; /* This is the handle for our window */
@ -75,7 +75,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
if (!(o.debug_fp = fopen(DEBUG_FILE, "w"))) if (!(o.debug_fp = fopen(DEBUG_FILE, "w")))
{ {
/* can't open debug file */ /* can't open debug file */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_DEBUG_FILE, DEBUG_FILE); ShowLocalizedMsg(IDS_ERR_OPEN_DEBUG_FILE, DEBUG_FILE);
exit(1); exit(1);
} }
PrintDebug("Starting OpenVPN GUI v%s", PACKAGE_VERSION); PrintDebug("Starting OpenVPN GUI v%s", PACKAGE_VERSION);
@ -84,23 +84,23 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
o.hInstance = hThisInstance; o.hInstance = hThisInstance;
if(!GetModuleHandle("RICHED20.DLL")) if(!GetModuleHandle(_T("RICHED20.DLL")))
{ {
LoadLibrary("RICHED20.DLL"); LoadLibrary(_T("RICHED20.DLL"));
} }
else else
{ {
/* can't load riched20.dll */ /* can't load riched20.dll */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_LOAD_RICHED20); ShowLocalizedMsg(IDS_ERR_LOAD_RICHED20);
exit(1); exit(1);
} }
/* Check version of shell32.dll */ /* Check version of shell32.dll */
shell32_version=GetDllVersion("shell32.dll"); shell32_version=GetDllVersion(_T("shell32.dll"));
if (shell32_version < PACKVERSION(5,0)) if (shell32_version < PACKVERSION(5,0))
{ {
/* shell32.dll version to low */ /* shell32.dll version to low */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_SHELL_DLL_VERSION, shell32_version); ShowLocalizedMsg(IDS_ERR_SHELL_DLL_VERSION, shell32_version);
exit(1); exit(1);
} }
#ifdef DEBUG #ifdef DEBUG
@ -109,13 +109,13 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
/* Parse command-line options */ /* Parse command-line options */
Createargcargv(&o, lpszArgument); Createargcargv(&o, GetCommandLine());
/* Check if a previous instance is already running. */ /* Check if a previous instance is already running. */
if ((FindWindow (szClassName, NULL)) != NULL) if ((FindWindow (szClassName, NULL)) != NULL)
{ {
/* GUI already running */ /* GUI already running */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GUI_ALREADY_RUNNING); ShowLocalizedMsg(IDS_ERR_GUI_ALREADY_RUNNING);
exit(1); exit(1);
} }
@ -396,7 +396,7 @@ void CloseApplication(HWND hwnd)
if (o.service_running == SERVICE_CONNECTED) if (o.service_running == SERVICE_CONNECTED)
{ {
if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_SERVICE_ACTIVE_EXIT), "Exit OpenVPN", MB_YESNO) == IDNO) if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_SERVICE_ACTIVE_EXIT), _T("Exit OpenVPN"), MB_YESNO) == IDNO)
{ {
return; return;
} }
@ -410,7 +410,7 @@ void CloseApplication(HWND hwnd)
} }
if (ask_exit) { if (ask_exit) {
/* aks for confirmation */ /* aks for confirmation */
if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_ACTIVE_CONN_EXIT), "Exit OpenVPN", MB_YESNO) == IDNO) if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_ACTIVE_CONN_EXIT), _T("Exit OpenVPN"), MB_YESNO) == IDNO)
{ {
return; return;
} }

21
main.h
View File

@ -34,10 +34,10 @@
//#define DISABLE_CHANGE_PASSWORD //#define DISABLE_CHANGE_PASSWORD
/* Registry key for User Settings */ /* Registry key for User Settings */
#define GUI_REGKEY_HKCU "Software\\Nilings\\OpenVPN-GUI" #define GUI_REGKEY_HKCU _T("Software\\Nilings\\OpenVPN-GUI")
/* Registry key for Global Settings */ /* Registry key for Global Settings */
#define GUI_REGKEY_HKLM "SOFTWARE\\OpenVPN-GUI" #define GUI_REGKEY_HKLM _T("SOFTWARE\\OpenVPN-GUI")
#define MAX_LOG_LINES 500 /* Max number of lines in LogWindow */ #define MAX_LOG_LINES 500 /* Max number of lines in LogWindow */
#define DEL_LOG_LINES 10 /* Number of lines to delete from LogWindow */ #define DEL_LOG_LINES 10 /* Number of lines to delete from LogWindow */
@ -84,6 +84,23 @@ __sntprintf_0(TCHAR *buf, size_t size, TCHAR *format, ...)
return i; return i;
} }
/* _snprintf with guaranteed \0 termination */
#define _snprintf_0(buf, ...) \
do { \
__snprintf_0(buf, sizeof(buf), __VA_ARGS__); \
} while(0);
static inline int
__snprintf_0(char *buf, size_t size, char *format, ...)
{
int i;
va_list args;
va_start(args, format);
i = _vsnprintf(buf, size, format, args);
buf[size - 1] = '\0';
va_end(args);
return i;
}
#ifdef DEBUG #ifdef DEBUG
/* Print Debug Message */ /* Print Debug Message */
#define PrintDebug(...) \ #define PrintDebug(...) \

100
openvpn.c
View File

@ -65,12 +65,12 @@ int CreateExitEvent(int config)
if (GetLastError() == ERROR_ACCESS_DENIED) if (GetLastError() == ERROR_ACCESS_DENIED)
{ {
/* service mustn't be running, while using old version */ /* service mustn't be running, while using old version */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_STOP_SERV_OLD_VER); ShowLocalizedMsg(IDS_ERR_STOP_SERV_OLD_VER);
} }
else else
{ {
/* error creating exit event */ /* error creating exit event */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_EVENT, o.cnn[config].exit_event_name); ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.cnn[config].exit_event_name);
} }
return(false); return(false);
} }
@ -85,7 +85,7 @@ int CreateExitEvent(int config)
if (o.cnn[config].exit_event == NULL) if (o.cnn[config].exit_event == NULL)
{ {
/* error creating exit event */ /* error creating exit event */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_EVENT, o.cnn[config].exit_event_name); ShowLocalizedMsg(IDS_ERR_CREATE_EVENT, o.cnn[config].exit_event_name);
return(false); return(false);
} }
} }
@ -102,20 +102,20 @@ int SetProcessPriority(DWORD *priority)
/* set process priority */ /* set process priority */
*priority = NORMAL_PRIORITY_CLASS; *priority = NORMAL_PRIORITY_CLASS;
if (!strcmp (o.priority_string, "IDLE_PRIORITY_CLASS")) if (!_tcscmp(o.priority_string, _T("IDLE_PRIORITY_CLASS")))
*priority = IDLE_PRIORITY_CLASS; *priority = IDLE_PRIORITY_CLASS;
else if (!strcmp (o.priority_string, "BELOW_NORMAL_PRIORITY_CLASS")) else if (!_tcscmp(o.priority_string, _T("BELOW_NORMAL_PRIORITY_CLASS")))
*priority = BELOW_NORMAL_PRIORITY_CLASS; *priority = BELOW_NORMAL_PRIORITY_CLASS;
else if (!strcmp (o.priority_string, "NORMAL_PRIORITY_CLASS")) else if (!_tcscmp(o.priority_string, _T("NORMAL_PRIORITY_CLASS")))
*priority = NORMAL_PRIORITY_CLASS; *priority = NORMAL_PRIORITY_CLASS;
else if (!strcmp (o.priority_string, "ABOVE_NORMAL_PRIORITY_CLASS")) else if (!_tcscmp(o.priority_string, _T("ABOVE_NORMAL_PRIORITY_CLASS")))
*priority = ABOVE_NORMAL_PRIORITY_CLASS; *priority = ABOVE_NORMAL_PRIORITY_CLASS;
else if (!strcmp (o.priority_string, "HIGH_PRIORITY_CLASS")) else if (!_tcscmp(o.priority_string, _T("HIGH_PRIORITY_CLASS")))
*priority = HIGH_PRIORITY_CLASS; *priority = HIGH_PRIORITY_CLASS;
else else
{ {
/* unknown priority */ /* unknown priority */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_UNKNOWN_PRIORITY, o.priority_string); ShowLocalizedMsg(IDS_ERR_UNKNOWN_PRIORITY, o.priority_string);
return (false); return (false);
} }
@ -144,8 +144,8 @@ int StartOpenVPN(int config)
PROCESS_INFORMATION proc_info; PROCESS_INFORMATION proc_info;
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; SECURITY_DESCRIPTOR sd;
char command_line[256]; TCHAR command_line[256];
char proxy_string[100]; TCHAR proxy_string[100];
int i, is_connected=0; int i, is_connected=0;
CLEAR (start_info); CLEAR (start_info);
@ -169,7 +169,7 @@ int StartOpenVPN(int config)
if (is_connected) if (is_connected)
{ {
/* only one simultanious connection on old version */ /* only one simultanious connection on old version */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONE_CONN_OLD_VER); ShowLocalizedMsg(IDS_ERR_ONE_CONN_OLD_VER);
return(false); return(false);
} }
} }
@ -178,7 +178,7 @@ int StartOpenVPN(int config)
if ((ConfigFileOptionExist(config, "log ")) || if ((ConfigFileOptionExist(config, "log ")) ||
(ConfigFileOptionExist(config, "log-append "))) (ConfigFileOptionExist(config, "log-append ")))
{ {
if (MessageBox(NULL, LoadLocalizedString(IDS_ERR_OPTION_LOG_IN_CONFIG), PACKAGE_NAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING) != IDYES) if (MessageBox(NULL, LoadLocalizedString(IDS_ERR_OPTION_LOG_IN_CONFIG), _T(PACKAGE_NAME), MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING) != IDYES)
return(false); return(false);
} }
@ -198,12 +198,12 @@ int StartOpenVPN(int config)
if ((o.append_string[0] != '0') && (o.append_string[0] != '1')) if ((o.append_string[0] != '0') && (o.append_string[0] != '1'))
{ {
/* append_log must be 0 or 1 */ /* append_log must be 0 or 1 */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_LOG_APPEND_BOOL, o.append_string); ShowLocalizedMsg(IDS_ERR_LOG_APPEND_BOOL, o.append_string);
goto failed; goto failed;
} }
/* construct proxy string to append to command line */ /* construct proxy string to append to command line */
ConstructProxyCmdLine(proxy_string, sizeof(proxy_string)); ConstructProxyCmdLine(proxy_string, _tsizeof(proxy_string));
/* construct command line */ /* construct command line */
if (o.oldversion == 1) if (o.oldversion == 1)
@ -228,13 +228,13 @@ int StartOpenVPN(int config)
if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION)) if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION))
{ {
/* Init Sec. Desc. failed */ /* Init Sec. Desc. failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_INIT_SEC_DESC); ShowLocalizedMsg(IDS_ERR_INIT_SEC_DESC);
goto failed; goto failed;
} }
if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE)) if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE))
{ {
/* set Dacl failed */ /* set Dacl failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_SET_SEC_DESC_ACL); ShowLocalizedMsg(IDS_ERR_SET_SEC_DESC_ACL);
goto failed; goto failed;
} }
@ -243,7 +243,7 @@ int StartOpenVPN(int config)
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0)) if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0))
{ {
/* CreatePipe failed. */ /* CreatePipe failed. */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PIPE_OUTPUT); ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_OUTPUT);
goto failed; goto failed;
} }
@ -255,7 +255,7 @@ int StartOpenVPN(int config)
TRUE,DUPLICATE_SAME_ACCESS)) TRUE,DUPLICATE_SAME_ACCESS))
{ {
/* DuplicateHandle failed. */ /* DuplicateHandle failed. */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_ERR_WRITE); ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_ERR_WRITE);
goto failed; goto failed;
} }
@ -263,7 +263,7 @@ int StartOpenVPN(int config)
if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0)) if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0))
{ {
/* CreatePipe failed. */ /* CreatePipe failed. */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PIPE_INPUT); ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_INPUT);
goto failed; goto failed;
} }
@ -278,7 +278,7 @@ int StartOpenVPN(int config)
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
/* Duplicate Handle failed. */ /* Duplicate Handle failed. */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_OUT_READ); ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_OUT_READ);
goto failed; goto failed;
} }
@ -289,7 +289,7 @@ int StartOpenVPN(int config)
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
/* DuplicateHandle failed */ /* DuplicateHandle failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_IN_WRITE); ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_IN_WRITE);
goto failed; goto failed;
} }
@ -297,7 +297,7 @@ int StartOpenVPN(int config)
if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp)) if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp))
{ {
/* Close Handle failed */ /* Close Handle failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CLOSE_HANDLE_TMP); ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE_TMP);
CloseHandle (o.cnn[config].exit_event); CloseHandle (o.cnn[config].exit_event);
return(0); return(0);
} }
@ -328,7 +328,7 @@ int StartOpenVPN(int config)
&proc_info)) &proc_info))
{ {
/* CreateProcess failed */ /* CreateProcess failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_PROCESS, ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS,
o.exe_path, o.exe_path,
command_line, command_line,
o.cnn[config].config_dir); o.cnn[config].config_dir);
@ -346,7 +346,7 @@ int StartOpenVPN(int config)
!CloseHandle (hErrorWrite)) !CloseHandle (hErrorWrite))
{ {
/* CloseHandle failed */ /* CloseHandle failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CLOSE_HANDLE); ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE);
CloseHandle (o.cnn[config].exit_event); CloseHandle (o.cnn[config].exit_event);
return(false); return(false);
} }
@ -370,7 +370,7 @@ int StartOpenVPN(int config)
if (hThread == NULL) if (hThread == NULL)
{ {
/* CreateThread failed */ /* CreateThread failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_THREAD_STATUS); ShowLocalizedMsg(IDS_ERR_CREATE_THREAD_STATUS);
goto failed; goto failed;
} }
@ -469,7 +469,7 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
if (!hwndLogWindow) if (!hwndLogWindow)
{ {
/* Create RichEd LogWindow Failed */ /* Create RichEd LogWindow Failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_EDIT_LOGWINDOW); ShowLocalizedMsg(IDS_ERR_CREATE_EDIT_LOGWINDOW);
return FALSE; return FALSE;
} }
@ -479,10 +479,10 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED; CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED;
charformat.dwEffects = 0; charformat.dwEffects = 0;
charformat.yHeight = 100; charformat.yHeight = 100;
strcpy(charformat.szFaceName, "MS Sans Serif"); _tcscpy(charformat.szFaceName, _T("MS Sans Serif"));
if ((SendMessage(hwndLogWindow, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM) &charformat) && CFM_SIZE) == 0) { if ((SendMessage(hwndLogWindow, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM) &charformat) && CFM_SIZE) == 0) {
/* set size failed */ /* set size failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_SET_SIZE); ShowLocalizedMsg(IDS_ERR_SET_SIZE);
} }
/* Set Size and Posision of controls */ /* Set Size and Posision of controls */
@ -604,7 +604,7 @@ int VerifyAutoConnections()
match = false; match = false;
for (j=0; j < MAX_CONFIGS; j++) for (j=0; j < MAX_CONFIGS; j++)
{ {
if (strcasecmp(o.cnn[j].config_file, o.auto_connect[i]) == 0) if (_tcsicmp(o.cnn[j].config_file, o.auto_connect[i]) == 0)
{ {
match=true; match=true;
break; break;
@ -613,7 +613,7 @@ int VerifyAutoConnections()
if (match == false) if (match == false)
{ {
/* autostart config not found */ /* autostart config not found */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_AUTOSTART_CONF, o.auto_connect[i]); ShowLocalizedMsg(IDS_ERR_AUTOSTART_CONF, o.auto_connect[i]);
return false; return false;
} }
} }
@ -636,9 +636,9 @@ int CheckVersion()
PROCESS_INFORMATION proc_info; PROCESS_INFORMATION proc_info;
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; SECURITY_DESCRIPTOR sd;
char command_line[256]; TCHAR command_line[256];
char line[1024]; char line[1024];
char bin_path[MAX_PATH]; TCHAR bin_path[MAX_PATH];
char *p; char *p;
int oldversion, i; int oldversion, i;
@ -647,7 +647,7 @@ int CheckVersion()
CLEAR (sa); CLEAR (sa);
CLEAR (sd); CLEAR (sd);
exit_event = CreateEvent (NULL, TRUE, FALSE, "openvpn_exit"); exit_event = CreateEvent (NULL, TRUE, FALSE, _T("openvpn_exit"));
if (exit_event == NULL) if (exit_event == NULL)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -663,7 +663,7 @@ int CheckVersion()
else else
{ {
/* CreateEvent failed */ /* CreateEvent failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_VERSION_CREATE_EVENT); ShowLocalizedMsg(IDS_ERR_VERSION_CREATE_EVENT);
return(false); return(false);
} }
} }
@ -676,8 +676,8 @@ int CheckVersion()
_sntprintf_0(command_line, _T("openvpn --version")); _sntprintf_0(command_line, _T("openvpn --version"));
/* construct bin path */ /* construct bin path */
strncpy(bin_path, o.exe_path, sizeof(bin_path)); _tcsncpy(bin_path, o.exe_path, _tsizeof(bin_path));
for (i=strlen(bin_path) - 1; i > 0; i--) for (i=_tcslen(bin_path) - 1; i > 0; i--)
if (bin_path[i] == '\\') break; if (bin_path[i] == '\\') break;
bin_path[i] = '\0'; bin_path[i] = '\0';
@ -689,13 +689,13 @@ int CheckVersion()
if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION)) if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION))
{ {
/* Init Sec. Desc. failed */ /* Init Sec. Desc. failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_INIT_SEC_DESC); ShowLocalizedMsg(IDS_ERR_INIT_SEC_DESC);
return(0); return(0);
} }
if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE)) if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE))
{ {
/* Set Dacl failed */ /* Set Dacl failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_SET_SEC_DESC_ACL); ShowLocalizedMsg(IDS_ERR_SET_SEC_DESC_ACL);
return(0); return(0);
} }
@ -703,7 +703,7 @@ int CheckVersion()
if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0)) if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0))
{ {
/* create pipe failed */ /* create pipe failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PIPE_IN_READ); ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_IN_READ);
return(0); return(0);
} }
@ -711,7 +711,7 @@ int CheckVersion()
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0)) if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0))
{ {
/* CreatePipe failed */ /* CreatePipe failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PIPE_OUTPUT); ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_OUTPUT);
return(0); return(0);
} }
@ -722,7 +722,7 @@ int CheckVersion()
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
/* DuplicateHandle failed */ /* DuplicateHandle failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_OUT_READ); ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_OUT_READ);
return(0); return(0);
} }
@ -733,7 +733,7 @@ int CheckVersion()
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
/* DuplicateHandle failed */ /* DuplicateHandle failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_IN_WRITE); ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_IN_WRITE);
return(0); return(0);
} }
@ -742,7 +742,7 @@ int CheckVersion()
if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp)) if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp))
{ {
/* CloseHandle failed */ /* CloseHandle failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CLOSE_HANDLE_TMP); ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE_TMP);
return(0); return(0);
} }
@ -768,7 +768,7 @@ int CheckVersion()
&proc_info)) &proc_info))
{ {
/* CreateProcess failed */ /* CreateProcess failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_PROCESS, ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS,
o.exe_path, o.exe_path,
command_line, command_line,
bin_path); bin_path);
@ -851,7 +851,7 @@ int CheckVersion()
|| !CloseHandle (hInputRead) || !CloseHandle(exit_event)) || !CloseHandle (hInputRead) || !CloseHandle(exit_event))
{ {
/* CloseHandle failed */ /* CloseHandle failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CLOSE_HANDLE); ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE);
return(0); return(0);
} }
@ -899,14 +899,14 @@ void CheckAndSetTrayIcon()
void ThreadOpenVPNStatus(int config) void ThreadOpenVPNStatus(int config)
{ {
char conn_name[200]; TCHAR conn_name[200];
HANDLE hThread; HANDLE hThread;
DWORD IDThread; DWORD IDThread;
MSG messages; MSG messages;
/* Cut of extention from config filename. */ /* Cut of extention from config filename. */
strncpy(conn_name, o.cnn[config].config_file, sizeof(conn_name)); _tcsncpy(conn_name, o.cnn[config].config_file, _tsizeof(conn_name));
conn_name[strlen(conn_name) - (strlen(o.ext_string)+1)]=0; conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0;
if (o.cnn[config].restart) if (o.cnn[config].restart)
{ {
@ -941,7 +941,7 @@ void ThreadOpenVPNStatus(int config)
if (hThread == NULL) if (hThread == NULL)
{ {
/* CreateThread failed */ /* CreateThread failed */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_THREAD_READ_STDOUT); ShowLocalizedMsg(IDS_ERR_THREAD_READ_STDOUT);
ExitThread(0); ExitThread(0);
} }

View File

@ -123,7 +123,7 @@ int AddConfigFileToList(int config, TCHAR filename[], TCHAR config_dir[])
if (!modext(log_file, _tsizeof(log_file), o.cnn[config].config_file, _T("log"))) if (!modext(log_file, _tsizeof(log_file), o.cnn[config].config_file, _T("log")))
{ {
/* cannot construct logfile-name */ /* cannot construct logfile-name */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_LOG_CONSTRUCT, o.cnn[config].config_file); ShowLocalizedMsg(IDS_ERR_LOG_CONSTRUCT, o.cnn[config].config_file);
return(false); return(false);
} }
_sntprintf_0(o.cnn[config].log_path, _T("%s\\%s"), o.log_dir, log_file); _sntprintf_0(o.cnn[config].log_path, _T("%s\\%s"), o.log_dir, log_file);
@ -172,7 +172,7 @@ BuildFileList()
if (o.num_configs >= MAX_CONFIGS) if (o.num_configs >= MAX_CONFIGS)
{ {
/* too many configs */ /* too many configs */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS);
break; break;
} }
@ -221,7 +221,7 @@ BuildFileList()
if (o.num_configs >= MAX_CONFIGS) if (o.num_configs >= MAX_CONFIGS)
{ {
/* too many configs */ /* too many configs */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS);
FindClose (find_handle); FindClose (find_handle);
return(true); return(true);
} }
@ -238,7 +238,7 @@ BuildFileList()
else else
{ {
/* Config filename already exists */ /* Config filename already exists */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CONFIG_EXIST, find_obj.cFileName); ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName);
} }
} }

View File

@ -92,7 +92,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char *line)
else else
{ {
/* error reading from pipe */ /* error reading from pipe */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READ_STDOUT_PIPE); ShowLocalizedMsg(IDS_ERR_READ_STDOUT_PIPE);
return(-1); return(-1);
} }
} }
@ -151,7 +151,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char *line)
else else
{ {
/* error reading from pipe */ /* error reading from pipe */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READ_STDOUT_PIPE); ShowLocalizedMsg(IDS_ERR_READ_STDOUT_PIPE);
return(-1); return(-1);
} }
} }
@ -192,7 +192,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char *line)
*/ */
void monitor_openvpnlog_while_connecting(int config, char *line) void monitor_openvpnlog_while_connecting(int config, char *line)
{ {
char msg[200]; TCHAR msg[200];
unsigned int i; unsigned int i;
char *linepos; char *linepos;
@ -222,14 +222,14 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
/* Show Tray Balloon msg */ /* Show Tray Balloon msg */
if (o.show_balloon[0] != '0') if (o.show_balloon[0] != '0')
{ {
LoadLocalizedStringBuf(msg, sizeof(msg)/sizeof(*msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name);
if (strlen(o.cnn[config].ip) > 0) if (_tcslen(o.cnn[config].ip) > 0)
{ {
ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip)); ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip));
} }
else else
{ {
ShowTrayBalloon(msg, " "); ShowTrayBalloon(msg, _T(""));
} }
} }
@ -254,7 +254,7 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
{ {
StopOpenVPN(config); StopOpenVPN(config);
/* Cert expired... */ /* Cert expired... */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CERT_EXPIRED); ShowLocalizedMsg(IDS_ERR_CERT_EXPIRED);
} }
/* Check for "certificate is not yet valid" message */ /* Check for "certificate is not yet valid" message */
@ -262,16 +262,29 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
{ {
StopOpenVPN(config); StopOpenVPN(config);
/* Cert not yet valid */ /* Cert not yet valid */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CERT_NOT_YET_VALID); ShowLocalizedMsg(IDS_ERR_CERT_NOT_YET_VALID);
} }
/* Check for "Notified TAP-Win32 driver to set a DHCP IP" message */ /* Check for "Notified TAP-Win32 driver to set a DHCP IP" message */
if (((linepos=strstr(line, "Notified TAP-Win32 driver to set a DHCP IP")) != NULL)) if (((linepos=strstr(line, "Notified TAP-Win32 driver to set a DHCP IP")) != NULL))
{ {
strncpy(o.cnn[config].ip, linepos+54, 15); /* Copy IP address */ char ip_addr[40];
for (i=0; i < strlen(o.cnn[config].ip); i++)
if (o.cnn[config].ip[i] == '/' || o.cnn[config].ip[i] == ' ') break; strncpy(ip_addr, linepos+54, sizeof(ip_addr)); /* Copy IP address */
o.cnn[config].ip[i] = '\0'; for (i = 0; i < sizeof(ip_addr) - 1; ++i)
{
if (ip_addr[i] == '/' || ip_addr[i] == ' ')
break;
}
ip_addr[i] = '\0';
#ifdef _UNICODE
/* Convert the IP address to Unicode */
o.cnn[config].ip[0] = _T('\0');
MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.cnn[config].ip, _tsizeof(o.cnn[config].ip));
#else
strncpy(o.cnn[config].ip, ip_addr, sizeof(o.cnn[config].ip));
#endif
} }
} }
@ -299,7 +312,7 @@ void monitor_openvpnlog_while_connected(int config, char *line)
*/ */
void monitor_openvpnlog_while_reconnecting(int config, char *line) void monitor_openvpnlog_while_reconnecting(int config, char *line)
{ {
char msg[200]; TCHAR msg[200];
char *linepos; char *linepos;
size_t i; size_t i;
@ -316,14 +329,14 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
/* Show Tray Balloon msg */ /* Show Tray Balloon msg */
if (o.show_balloon[0] == '2') if (o.show_balloon[0] == '2')
{ {
LoadLocalizedStringBuf(msg, sizeof(msg)/sizeof(*msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name);
if (strlen(o.cnn[config].ip) > 0) if (_tcslen(o.cnn[config].ip) > 0)
{ {
ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip)); ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip));
} }
else else
{ {
ShowTrayBalloon(msg, " "); ShowTrayBalloon(msg, _T(""));
} }
} }
} }
@ -345,7 +358,7 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
{ {
/* Cert expired */ /* Cert expired */
StopOpenVPN(config); StopOpenVPN(config);
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CERT_EXPIRED); ShowLocalizedMsg(IDS_ERR_CERT_EXPIRED);
} }
/* Check for "certificate is not yet valid" message */ /* Check for "certificate is not yet valid" message */
@ -353,16 +366,29 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
{ {
StopOpenVPN(config); StopOpenVPN(config);
/* Cert not yet valid */ /* Cert not yet valid */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CERT_NOT_YET_VALID); ShowLocalizedMsg(IDS_ERR_CERT_NOT_YET_VALID);
} }
/* Check for "Notified TAP-Win32 driver to set a DHCP IP" message */ /* Check for "Notified TAP-Win32 driver to set a DHCP IP" message */
if (((linepos=strstr(line, "Notified TAP-Win32 driver to set a DHCP IP")) != NULL)) if (((linepos=strstr(line, "Notified TAP-Win32 driver to set a DHCP IP")) != NULL))
{ {
strncpy(o.cnn[config].ip, linepos+54, 15); /* Copy IP address */ char ip_addr[40];
for (i=0; i < strlen(o.cnn[config].ip); i++)
if (o.cnn[config].ip[i] == '/' || o.cnn[config].ip[i] == ' ') break; strncpy(ip_addr, linepos+54, sizeof(ip_addr)); /* Copy IP address */
o.cnn[config].ip[i] = '\0'; for (i = 0; i < sizeof(ip_addr) - 1; ++i)
{
if (ip_addr[i] == '/' || ip_addr[i] == ' ')
break;
}
ip_addr[i] = '\0';
#ifdef _UNICODE
/* Convert the IP address to Unicode */
o.cnn[config].ip[0] = _T('\0');
MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.cnn[config].ip, _tsizeof(o.cnn[config].ip));
#else
strncpy(o.cnn[config].ip, ip_addr, sizeof(o.cnn[config].ip));
#endif
} }
} }
@ -379,7 +405,7 @@ void WatchOpenVPNProcess(int config)
{ {
char line[1024]; char line[1024];
int ret; int ret;
char filemode[2] = "w\0"; TCHAR filemode[] = _T("w");
FILE *fd; FILE *fd;
int LogLines = 0; int LogLines = 0;
int logpos; int logpos;
@ -387,7 +413,7 @@ void WatchOpenVPNProcess(int config)
/* set log file append/truncate filemode */ /* set log file append/truncate filemode */
if (o.append_string[0] == '1') if (o.append_string[0] == '1')
filemode[0] = 'a'; filemode[0] = _T('a');
/* Set Connect_Status = "Connecting" */ /* Set Connect_Status = "Connecting" */
o.cnn[config].connect_status = CONNECTING; o.cnn[config].connect_status = CONNECTING;
@ -402,8 +428,8 @@ void WatchOpenVPNProcess(int config)
o.cnn[config].failed_psw = 0; o.cnn[config].failed_psw = 0;
/* Open log file */ /* Open log file */
if ((fd=fopen(o.cnn[config].log_path, filemode)) == NULL) if ((fd=_tfopen(o.cnn[config].log_path, filemode)) == NULL)
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_OPEN_LOG_WRITE, o.cnn[config].log_path); ShowLocalizedMsg(IDS_ERR_OPEN_LOG_WRITE, o.cnn[config].log_path);
LogWindow = GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG); LogWindow = GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG);
while(TRUE) while(TRUE)
@ -428,14 +454,20 @@ void WatchOpenVPNProcess(int config)
{ {
logpos = SendMessage(LogWindow, EM_LINEINDEX, DEL_LOG_LINES, 0); logpos = SendMessage(LogWindow, EM_LINEINDEX, DEL_LOG_LINES, 0);
SendMessage(LogWindow, EM_SETSEL, 0, logpos); SendMessage(LogWindow, EM_SETSEL, 0, logpos);
SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) ""); SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) _T(""));
LogLines -= DEL_LOG_LINES; LogLines -= DEL_LOG_LINES;
} }
/* Write line to LogWindow */ /* Write line to LogWindow */
strcat(line, "\r\n"); strcat(line, "\r\n");
SendMessage(LogWindow, EM_SETSEL, (WPARAM) -1, (LPARAM) -1); SendMessage(LogWindow, EM_SETSEL, (WPARAM) -1, (LPARAM) -1);
#ifdef _UNICODE
TCHAR wide_line[1024];
MultiByteToWideChar(CP_ACP, 0, line, -1, wide_line, _tsizeof(wide_line));
SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) wide_line);
#else
SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) line); SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) line);
#endif
if (o.cnn[config].connect_status == CONNECTING) /* Connecting state */ if (o.cnn[config].connect_status == CONNECTING) /* Connecting state */
monitor_openvpnlog_while_connecting(config, line); monitor_openvpnlog_while_connecting(config, line);
@ -489,7 +521,7 @@ void WatchOpenVPNProcess(int config)
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE);
SetForegroundWindow(o.cnn[config].hwndStatus); SetForegroundWindow(o.cnn[config].hwndStatus);
ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); ShowWindow(o.cnn[config].hwndStatus, SW_SHOW);
ShowLocalizedMsg(PACKAGE_NAME, IDS_NFO_CONN_TERMINATED, o.cnn[config].config_name); ShowLocalizedMsg(IDS_NFO_CONN_TERMINATED, o.cnn[config].config_name);
/* Close Status Window */ /* Close Status Window */
SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0);
@ -524,7 +556,7 @@ void WatchOpenVPNProcess(int config)
/* Zero psw attempt counter */ /* Zero psw attempt counter */
o.cnn[config].failed_psw_attempts = 0; o.cnn[config].failed_psw_attempts = 0;
ShowLocalizedMsg(PACKAGE_NAME, IDS_NFO_CONN_FAILED, o.cnn[config].config_name); ShowLocalizedMsg(IDS_NFO_CONN_FAILED, o.cnn[config].config_name);
/* Set connect_status = "Not Connected" */ /* Set connect_status = "Not Connected" */
o.cnn[config].connect_status=DISCONNECTED; o.cnn[config].connect_status=DISCONNECTED;
@ -567,7 +599,7 @@ void WatchOpenVPNProcess(int config)
/* Zero psw attempt counter */ /* Zero psw attempt counter */
o.cnn[config].failed_psw_attempts = 0; o.cnn[config].failed_psw_attempts = 0;
ShowLocalizedMsg(PACKAGE_NAME, IDS_NFO_RECONN_FAILED, o.cnn[config].config_name); ShowLocalizedMsg(IDS_NFO_RECONN_FAILED, o.cnn[config].config_name);
/* Set connect_status = "Not Connected" */ /* Set connect_status = "Not Connected" */
o.cnn[config].connect_status=DISCONNECTED; o.cnn[config].connect_status=DISCONNECTED;

142
options.c
View File

@ -39,18 +39,18 @@ init_options (struct options *opt)
CLEAR (*opt); CLEAR (*opt);
} }
int Createargcargv(struct options* options, char* command_line) int Createargcargv(struct options *options, TCHAR *command_line)
{ {
int argc; int argc;
char** argv; TCHAR **argv;
char* arg; TCHAR* arg;
int myindex; int myindex;
// count the arguments // count the arguments
argc = 1; argc = 0;
arg = command_line; arg = command_line;
while (arg[0] != 0) { while (arg[0] != 0) {
@ -78,10 +78,10 @@ int Createargcargv(struct options* options, char* command_line)
} }
// tokenize the arguments // tokenize the arguments
argv = (char**)malloc(argc * sizeof(char*)); argv = (TCHAR**) malloc(argc * sizeof(TCHAR*));
arg = command_line; arg = command_line;
myindex = 1; myindex = 0;
while (arg[0] != 0) { while (arg[0] != 0) {
@ -123,12 +123,6 @@ int Createargcargv(struct options* options, char* command_line)
} }
// put the program name into argv[0]
char filename[_MAX_PATH];
GetModuleFileName(NULL, filename, _MAX_PATH);
argv[0] = filename;
parse_argv(options, argc, argv); parse_argv(options, argc, argv);
free(argv); free(argv);
@ -139,137 +133,137 @@ int Createargcargv(struct options* options, char* command_line)
static int static int
add_option (struct options *options, add_option (struct options *options,
int i, int i,
char *p[]) TCHAR *p[])
{ {
if (streq (p[0], "help")) if (streq (p[0], _T("help")))
{ {
TCHAR usagecaption[200]; TCHAR usagecaption[200];
LoadLocalizedStringBuf(usagecaption, sizeof(usagecaption)/sizeof(*usagecaption), IDS_NFO_USAGECAPTION); LoadLocalizedStringBuf(usagecaption, _tsizeof(usagecaption), IDS_NFO_USAGECAPTION);
MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), usagecaption, MB_OK); MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), usagecaption, MB_OK);
exit(0); exit(0);
} }
else if (streq (p[0], "connect") && p[1]) else if (streq (p[0], _T("connect")) && p[1])
{ {
++i; ++i;
static int auto_connect_nr=0; static int auto_connect_nr=0;
if (auto_connect_nr == MAX_CONFIGS) if (auto_connect_nr == MAX_CONFIGS)
{ {
/* Too many configs */ /* Too many configs */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS);
exit(1); exit(1);
} }
options->auto_connect[auto_connect_nr] = p[1]; options->auto_connect[auto_connect_nr] = p[1];
auto_connect_nr++; auto_connect_nr++;
} }
else if (streq (p[0], "exe_path") && p[1]) else if (streq (p[0], _T("exe_path")) && p[1])
{ {
++i; ++i;
strncpy(options->exe_path, p[1], sizeof(options->exe_path) - 1); _tcsncpy(options->exe_path, p[1], _tsizeof(options->exe_path) - 1);
} }
else if (streq (p[0], "config_dir") && p[1]) else if (streq (p[0], _T("config_dir")) && p[1])
{ {
++i; ++i;
strncpy(options->config_dir, p[1], sizeof(options->config_dir) - 1); _tcsncpy(options->config_dir, p[1], _tsizeof(options->config_dir) - 1);
} }
else if (streq (p[0], "ext_string") && p[1]) else if (streq (p[0], _T("ext_string")) && p[1])
{ {
++i; ++i;
strncpy(options->ext_string, p[1], sizeof(options->ext_string) - 1); _tcsncpy(options->ext_string, p[1], _tsizeof(options->ext_string) - 1);
} }
else if (streq (p[0], "log_dir") && p[1]) else if (streq (p[0], _T("log_dir")) && p[1])
{ {
++i; ++i;
strncpy(options->log_dir, p[1], sizeof(options->log_dir) - 1); _tcsncpy(options->log_dir, p[1], _tsizeof(options->log_dir) - 1);
} }
else if (streq (p[0], "priority_string") && p[1]) else if (streq (p[0], _T("priority_string")) && p[1])
{ {
++i; ++i;
strncpy(options->priority_string, p[1], sizeof(options->priority_string) - 1); _tcsncpy(options->priority_string, p[1], _tsizeof(options->priority_string) - 1);
} }
else if (streq (p[0], "append_string") && p[1]) else if (streq (p[0], _T("append_string")) && p[1])
{ {
++i; ++i;
strncpy(options->append_string, p[1], sizeof(options->append_string) - 1); _tcsncpy(options->append_string, p[1], _tsizeof(options->append_string) - 1);
} }
else if (streq (p[0], "log_viewer") && p[1]) else if (streq (p[0], _T("log_viewer")) && p[1])
{ {
++i; ++i;
strncpy(options->log_viewer, p[1], sizeof(options->log_viewer) - 1); _tcsncpy(options->log_viewer, p[1], _tsizeof(options->log_viewer) - 1);
} }
else if (streq (p[0], "editor") && p[1]) else if (streq (p[0], _T("editor")) && p[1])
{ {
++i; ++i;
strncpy(options->editor, p[1], sizeof(options->editor) - 1); _tcsncpy(options->editor, p[1], _tsizeof(options->editor) - 1);
} }
else if (streq (p[0], "allow_edit") && p[1]) else if (streq (p[0], _T("allow_edit")) && p[1])
{ {
++i; ++i;
strncpy(options->allow_edit, p[1], sizeof(options->allow_edit) - 1); _tcsncpy(options->allow_edit, p[1], _tsizeof(options->allow_edit) - 1);
} }
else if (streq (p[0], "allow_service") && p[1]) else if (streq (p[0], _T("allow_service")) && p[1])
{ {
++i; ++i;
strncpy(options->allow_service, p[1], sizeof(options->allow_service) - 1); _tcsncpy(options->allow_service, p[1], _tsizeof(options->allow_service) - 1);
} }
else if (streq (p[0], "allow_password") && p[1]) else if (streq (p[0], _T("allow_password")) && p[1])
{ {
++i; ++i;
strncpy(options->allow_password, p[1], sizeof(options->allow_password) - 1); _tcsncpy(options->allow_password, p[1], _tsizeof(options->allow_password) - 1);
} }
else if (streq (p[0], "allow_proxy") && p[1]) else if (streq (p[0], _T("allow_proxy")) && p[1])
{ {
++i; ++i;
strncpy(options->allow_proxy, p[1], sizeof(options->allow_proxy) - 1); _tcsncpy(options->allow_proxy, p[1], _tsizeof(options->allow_proxy) - 1);
} }
else if (streq (p[0], "show_balloon") && p[1]) else if (streq (p[0], _T("show_balloon")) && p[1])
{ {
++i; ++i;
strncpy(options->show_balloon, p[1], sizeof(options->show_balloon) - 1); _tcsncpy(options->show_balloon, p[1], _tsizeof(options->show_balloon) - 1);
} }
else if (streq (p[0], "service_only") && p[1]) else if (streq (p[0], _T("service_only")) && p[1])
{ {
++i; ++i;
strncpy(options->service_only, p[1], sizeof(options->service_only) - 1); _tcsncpy(options->service_only, p[1], _tsizeof(options->service_only) - 1);
} }
else if (streq (p[0], "show_script_window") && p[1]) else if (streq (p[0], _T("show_script_window")) && p[1])
{ {
++i; ++i;
strncpy(options->show_script_window, p[1], sizeof(options->show_script_window) - 1); _tcsncpy(options->show_script_window, p[1], _tsizeof(options->show_script_window) - 1);
} }
else if (streq (p[0], "silent_connection") && p[1]) else if (streq (p[0], _T("silent_connection")) && p[1])
{ {
++i; ++i;
strncpy(options->silent_connection, p[1], sizeof(options->silent_connection) - 1); _tcsncpy(options->silent_connection, p[1], _tsizeof(options->silent_connection) - 1);
} }
else if (streq (p[0], "passphrase_attempts") && p[1]) else if (streq (p[0], _T("passphrase_attempts")) && p[1])
{ {
++i; ++i;
strncpy(options->psw_attempts_string, p[1], sizeof(options->psw_attempts_string) - 1); _tcsncpy(options->psw_attempts_string, p[1], _tsizeof(options->psw_attempts_string) - 1);
} }
else if (streq (p[0], "connectscript_timeout") && p[1]) else if (streq (p[0], _T("connectscript_timeout")) && p[1])
{ {
++i; ++i;
strncpy(options->connectscript_timeout_string, p[1], sizeof(options->connectscript_timeout_string) - 1); _tcsncpy(options->connectscript_timeout_string, p[1], _tsizeof(options->connectscript_timeout_string) - 1);
} }
else if (streq (p[0], "disconnectscript_timeout") && p[1]) else if (streq (p[0], _T("disconnectscript_timeout")) && p[1])
{ {
++i; ++i;
strncpy(options->disconnectscript_timeout_string, p[1], _tcsncpy(options->disconnectscript_timeout_string, p[1],
sizeof(options->disconnectscript_timeout_string) - 1); _tsizeof(options->disconnectscript_timeout_string) - 1);
} }
else if (streq (p[0], "preconnectscript_timeout") && p[1]) else if (streq (p[0], _T("preconnectscript_timeout")) && p[1])
{ {
++i; ++i;
strncpy(options->preconnectscript_timeout_string, p[1], _tcsncpy(options->preconnectscript_timeout_string, p[1],
sizeof(options->preconnectscript_timeout_string) - 1); _tsizeof(options->preconnectscript_timeout_string) - 1);
} }
else else
{ {
/* Unrecognized option or missing parameter */ /* Unrecognized option or missing parameter */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_BAD_OPTION, p[0]); ShowLocalizedMsg(IDS_ERR_BAD_OPTION, p[0]);
exit(1); exit(1);
} }
return i; return i;
@ -278,20 +272,20 @@ add_option (struct options *options,
void void
parse_argv (struct options* options, parse_argv (struct options* options,
int argc, int argc,
char *argv[]) TCHAR *argv[])
{ {
int i, j; int i, j;
/* parse command line */ /* parse command line */
for (i = 1; i < argc; ++i) for (i = 1; i < argc; ++i)
{ {
char *p[MAX_PARMS]; TCHAR *p[MAX_PARMS];
CLEAR (p); CLEAR (p);
p[0] = argv[i]; p[0] = argv[i];
if (strncmp(p[0], "--", 2)) if (_tcsncmp(p[0], _T("--"), 2))
{ {
/* Missing -- before option. */ /* Missing -- before option. */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_BAD_PARAMETER, p[0]); ShowLocalizedMsg(IDS_ERR_BAD_PARAMETER, p[0]);
exit(0); exit(0);
} }
else else
@ -301,8 +295,8 @@ parse_argv (struct options* options,
{ {
if (i + j < argc) if (i + j < argc)
{ {
char *arg = argv[i + j]; TCHAR *arg = argv[i + j];
if (strncmp (arg, "--", 2)) if (_tcsncmp (arg, _T("--"), 2))
p[j] = arg; p[j] = arg;
else else
break; break;
@ -319,18 +313,18 @@ int ConfigFileOptionExist(int config, const char *option)
{ {
FILE *fp; FILE *fp;
char line[256]; char line[256];
char configfile_path[MAX_PATH]; TCHAR configfile_path[MAX_PATH];
strncpy(configfile_path, o.cnn[config].config_dir, sizeof(configfile_path)); _tcsncpy(configfile_path, o.cnn[config].config_dir, _tsizeof(configfile_path));
if (!(configfile_path[strlen(configfile_path)-1] == '\\')) if (configfile_path[_tcslen(configfile_path) - 1] != _T('\\'))
strcat(configfile_path, "\\"); _tcscat(configfile_path, _T("\\"));
strncat(configfile_path, o.cnn[config].config_file, _tcsncat(configfile_path, o.cnn[config].config_file,
sizeof(configfile_path) - strlen(configfile_path) - 1); _tsizeof(configfile_path) - _tcslen(configfile_path) - 1);
if (!(fp=fopen(configfile_path, "r"))) if (!(fp=_tfopen(configfile_path, _T("r"))))
{ {
/* can't open config file */ /* can't open config file */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_CONFIG, configfile_path); ShowLocalizedMsg(IDS_ERR_OPEN_CONFIG, configfile_path);
return(0); return(0);
} }

View File

@ -49,12 +49,12 @@
/* Connections parameters */ /* Connections parameters */
struct connections struct connections
{ {
char config_file[MAX_PATH]; /* Name of the config file */ TCHAR config_file[MAX_PATH]; /* Name of the config file */
char config_name[MAX_PATH]; /* Name of the connection */ TCHAR config_name[MAX_PATH]; /* Name of the connection */
char config_dir[MAX_PATH]; /* Path to this configs dir */ TCHAR config_dir[MAX_PATH]; /* Path to this configs dir */
char log_path[MAX_PATH]; /* Path to Logfile */ TCHAR log_path[MAX_PATH]; /* Path to Logfile */
char ip[16]; /* Assigned IP address for this connection */ TCHAR ip[16]; /* Assigned IP address for this connection */
char exit_event_name[50]; /* Exit Event name for this connection */ TCHAR exit_event_name[50]; /* Exit Event name for this connection */
int connect_status; /* 0=Not Connected 1=Connecting int connect_status; /* 0=Not Connected 1=Connecting
2=Connected 3=Reconnecting 4=Disconnecting */ 2=Connected 3=Reconnecting 4=Disconnecting */
int auto_connect; /* true=AutoConnect at startup */ int auto_connect; /* true=AutoConnect at startup */
@ -74,7 +74,7 @@ struct connections
struct options struct options
{ {
/* Array of configs to autostart */ /* Array of configs to autostart */
const char *auto_connect[MAX_CONFIGS]; const TCHAR *auto_connect[MAX_CONFIGS];
/* Connection parameters */ /* Connection parameters */
struct connections cnn[MAX_CONFIGS]; /* Connection structure */ struct connections cnn[MAX_CONFIGS]; /* Connection structure */
@ -91,37 +91,37 @@ struct options
HINSTANCE hInstance; HINSTANCE hInstance;
/* Registry values */ /* Registry values */
char exe_path[MAX_PATH]; TCHAR exe_path[MAX_PATH];
char config_dir[MAX_PATH]; TCHAR config_dir[MAX_PATH];
char ext_string[16]; TCHAR ext_string[16];
char log_dir[MAX_PATH]; TCHAR log_dir[MAX_PATH];
char priority_string[64]; TCHAR priority_string[64];
char append_string[2]; TCHAR append_string[2];
char log_viewer[MAX_PATH]; TCHAR log_viewer[MAX_PATH];
char editor[MAX_PATH]; TCHAR editor[MAX_PATH];
char allow_edit[2]; TCHAR allow_edit[2];
char allow_service[2]; TCHAR allow_service[2];
char allow_password[2]; TCHAR allow_password[2];
char allow_proxy[2]; TCHAR allow_proxy[2];
char silent_connection[2]; TCHAR silent_connection[2];
char service_only[2]; TCHAR service_only[2];
char show_balloon[2]; TCHAR show_balloon[2];
char show_script_window[2]; TCHAR show_script_window[2];
char psw_attempts_string[2]; TCHAR psw_attempts_string[2];
char disconnect_on_suspend[2]; TCHAR disconnect_on_suspend[2];
char connectscript_timeout_string[4]; TCHAR connectscript_timeout_string[4];
char disconnectscript_timeout_string[4]; TCHAR disconnectscript_timeout_string[4];
char preconnectscript_timeout_string[4]; TCHAR preconnectscript_timeout_string[4];
/* Proxy Settings */ /* Proxy Settings */
int proxy_source; /* 0=OpenVPN config, 1=IE, 2=Manual */ int proxy_source; /* 0=OpenVPN config, 1=IE, 2=Manual */
int proxy_type; /* 0=HTTP, 1=SOCKS */ int proxy_type; /* 0=HTTP, 1=SOCKS */
int proxy_http_auth; /* 0=Auth Disabled, 1=Auth Enabled */ int proxy_http_auth; /* 0=Auth Disabled, 1=Auth Enabled */
char proxy_http_address[100]; /* HTTP Proxy Address */ TCHAR proxy_http_address[100]; /* HTTP Proxy Address */
char proxy_http_port[6]; /* HTTP Proxy Port */ TCHAR proxy_http_port[6]; /* HTTP Proxy Port */
char proxy_socks_address[100]; /* SOCKS Proxy Address */ TCHAR proxy_socks_address[100]; /* SOCKS Proxy Address */
char proxy_socks_port[6]; /* SOCKS Proxy Address */ TCHAR proxy_socks_port[6]; /* SOCKS Proxy Address */
char proxy_authfile[100]; /* Path to proxy auth file */ TCHAR proxy_authfile[100]; /* Path to proxy auth file */
/* Debug file pointer */ /* Debug file pointer */
#ifdef DEBUG #ifdef DEBUG
@ -129,8 +129,8 @@ struct options
#endif #endif
}; };
#define streq(x, y) (!strcmp((x), (y))) #define streq(x, y) (!_tcscmp((x), (y)))
void init_options (struct options *o); void init_options (struct options *o);
int Createargcargv(struct options* options, char* command_line); int Createargcargv(struct options* options, TCHAR* command_line);
void parse_argv (struct options* options, int argc, char *argv[]); void parse_argv (struct options* options, int argc, TCHAR *argv[]);
int ConfigFileOptionExist(int config, const char *option); int ConfigFileOptionExist(int config, const char *option);

View File

@ -89,14 +89,14 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
strlen(passphrase_ascii), &nCharsWritten, NULL)) strlen(passphrase_ascii), &nCharsWritten, NULL))
{ {
/* PassPhrase -> stdin failed */ /* PassPhrase -> stdin failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PASSPHRASE2STDIN); ShowLocalizedMsg(IDS_ERR_PASSPHRASE2STDIN);
} }
} }
if (!WriteFile(o.cnn[config].hStdIn, "\r\n", if (!WriteFile(o.cnn[config].hStdIn, "\r\n",
2, &nCharsWritten, NULL)) 2, &nCharsWritten, NULL))
{ {
/* CR -> stdin failed */ /* CR -> stdin failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CR2STDIN); ShowLocalizedMsg(IDS_ERR_CR2STDIN);
} }
/* Remove Passphrase prompt from lastline buffer */ /* Remove Passphrase prompt from lastline buffer */
line[0]='\0'; line[0]='\0';
@ -124,7 +124,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
strlen(passphrase_ascii), &nCharsWritten, NULL)) strlen(passphrase_ascii), &nCharsWritten, NULL))
{ {
/* PassPhrase -> stdin failed */ /* PassPhrase -> stdin failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PASSPHRASE2STDIN); ShowLocalizedMsg(IDS_ERR_PASSPHRASE2STDIN);
} }
} }
else else
@ -133,7 +133,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
/* CR -> stdin failed */ /* CR -> stdin failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CR2STDIN); ShowLocalizedMsg(IDS_ERR_CR2STDIN);
} }
} }
/* Remove Passphrase prompt from lastline buffer */ /* Remove Passphrase prompt from lastline buffer */
@ -166,7 +166,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (!WriteFile(o.cnn[config].hStdIn, user_auth.username, if (!WriteFile(o.cnn[config].hStdIn, user_auth.username,
strlen(user_auth.username), &nCharsWritten, NULL)) strlen(user_auth.username), &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_AUTH_USERNAME2STDIN); ShowLocalizedMsg(IDS_ERR_AUTH_USERNAME2STDIN);
} }
} }
else else
@ -174,7 +174,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (!WriteFile(o.cnn[config].hStdIn, "\n", if (!WriteFile(o.cnn[config].hStdIn, "\n",
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CR2STDIN); ShowLocalizedMsg(IDS_ERR_CR2STDIN);
} }
} }
@ -183,7 +183,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (!WriteFile(o.cnn[config].hStdIn, user_auth.password, if (!WriteFile(o.cnn[config].hStdIn, user_auth.password,
strlen(user_auth.password), &nCharsWritten, NULL)) strlen(user_auth.password), &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_AUTH_PASSWORD2STDIN); ShowLocalizedMsg(IDS_ERR_AUTH_PASSWORD2STDIN);
} }
} }
else else
@ -191,7 +191,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (!WriteFile(o.cnn[config].hStdIn, "\n", if (!WriteFile(o.cnn[config].hStdIn, "\n",
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CR2STDIN); ShowLocalizedMsg(IDS_ERR_CR2STDIN);
} }
} }
@ -219,7 +219,7 @@ void CheckAuthPasswordPrompt (char *line)
BOOL CALLBACK PassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam) BOOL CALLBACK PassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam)
{ {
static char empty_string[100]; static TCHAR empty_string[100];
switch (msg) { switch (msg) {
@ -255,7 +255,7 @@ BOOL CALLBACK PassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSE
BOOL CALLBACK AuthPasswordDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) BOOL CALLBACK AuthPasswordDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
static struct user_auth *user_auth; static struct user_auth *user_auth;
static char empty_string[100]; static TCHAR empty_string[100];
WCHAR username_unicode[50]; WCHAR username_unicode[50];
WCHAR password_unicode[50]; WCHAR password_unicode[50];
@ -316,7 +316,7 @@ void ShowChangePassphraseDialog(int config)
if (hThread == NULL) if (hThread == NULL)
{ {
/* error creating thread */ /* error creating thread */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_PASS_THREAD); ShowLocalizedMsg(IDS_ERR_CREATE_PASS_THREAD);
return; return;
} }
@ -326,16 +326,16 @@ void ChangePassphraseThread(int config)
{ {
HWND hwndChangePSW; HWND hwndChangePSW;
MSG messages; MSG messages;
char conn_name[100]; TCHAR conn_name[100];
char keyfilename[MAX_PATH]; TCHAR keyfilename[MAX_PATH];
int keyfile_format=0; int keyfile_format=0;
/* Cut of extention from config filename. */ /* Cut of extention from config filename. */
strncpy(conn_name, o.cnn[config].config_file, sizeof(conn_name)); _tcsncpy(conn_name, o.cnn[config].config_file, _tsizeof(conn_name));
conn_name[strlen(conn_name) - (strlen(o.ext_string)+1)]=0; conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0;
/* Get Key filename from config file */ /* Get Key filename from config file */
if (!GetKeyFilename(config, keyfilename, sizeof(keyfilename), &keyfile_format)) if (!GetKeyFilename(config, keyfilename, _tsizeof(keyfilename), &keyfile_format))
{ {
ExitThread(1); ExitThread(1);
} }
@ -368,7 +368,7 @@ void ChangePassphraseThread(int config)
BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam) BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam)
{ {
HICON hIcon; HICON hIcon;
char keyfile[MAX_PATH]; TCHAR keyfile[MAX_PATH];
int keyfile_format; int keyfile_format;
BOOL Translated; BOOL Translated;
@ -391,25 +391,25 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam,
if (!ConfirmNewPassword (hwndDlg)) if (!ConfirmNewPassword (hwndDlg))
{ {
/* passwords don't match */ /* passwords don't match */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PWD_DONT_MATCH); ShowLocalizedMsg(IDS_ERR_PWD_DONT_MATCH);
break; break;
} }
/* Check minimum length of password */ /* Check minimum length of password */
if (NewPasswordLengh(hwndDlg) < MIN_PASSWORD_LEN) if (NewPasswordLengh(hwndDlg) < MIN_PASSWORD_LEN)
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PWD_TO_SHORT, MIN_PASSWORD_LEN); ShowLocalizedMsg(IDS_ERR_PWD_TO_SHORT, MIN_PASSWORD_LEN);
break; break;
} }
/* Check if the new password is empty. */ /* Check if the new password is empty. */
if (NewPasswordLengh(hwndDlg) == 0) if (NewPasswordLengh(hwndDlg) == 0)
{ {
if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_EMPTY_PWD), PACKAGE_NAME, MB_YESNO) != IDYES) if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_EMPTY_PWD), _T(PACKAGE_NAME), MB_YESNO) != IDYES)
break; break;
} }
GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, sizeof(keyfile) - 1); GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, _tsizeof(keyfile) - 1);
keyfile_format=GetDlgItemInt(hwndDlg, ID_TXT_KEYFORMAT, &Translated, FALSE); keyfile_format=GetDlgItemInt(hwndDlg, ID_TXT_KEYFORMAT, &Translated, FALSE);
if (keyfile_format == KEYFILE_FORMAT_PEM) if (keyfile_format == KEYFILE_FORMAT_PEM)
{ {
@ -426,7 +426,7 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam,
else else
{ {
/* Unknown key format */ /* Unknown key format */
ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_UNKNOWN_KEYFILE_FORMAT); ShowLocalizedMsg(IDS_ERR_UNKNOWN_KEYFILE_FORMAT);
} }
DestroyWindow(hwndDlg); DestroyWindow(hwndDlg);
@ -456,13 +456,13 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam,
/* Return TRUE if new passwords match */ /* Return TRUE if new passwords match */
int ConfirmNewPassword(HWND hwndDlg) int ConfirmNewPassword(HWND hwndDlg)
{ {
char newpsw[50]; TCHAR newpsw[50];
char newpsw2[50]; TCHAR newpsw2[50];
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, sizeof(newpsw) - 1); GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, _tsizeof(newpsw) - 1);
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW2, newpsw2, sizeof(newpsw2) - 1); GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW2, newpsw2, _tsizeof(newpsw2) - 1);
if (strncmp(newpsw, newpsw2, sizeof(newpsw)) == 0) if (_tcsncmp(newpsw, newpsw2, _tsizeof(newpsw)) == 0)
return true; return true;
else else
return false; return false;
@ -471,14 +471,14 @@ int ConfirmNewPassword(HWND hwndDlg)
/* Return lengh of the new password */ /* Return lengh of the new password */
int NewPasswordLengh(HWND hwndDlg) int NewPasswordLengh(HWND hwndDlg)
{ {
char newpsw[50]; TCHAR newpsw[50];
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, sizeof(newpsw) - 1); GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, _tsizeof(newpsw) - 1);
return (strlen(newpsw)); return (_tcslen(newpsw));
} }
int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilenamesize, char *line) int ParseKeyFilenameLine(int config, TCHAR *keyfilename, size_t keyfilenamesize, char *line)
{ {
const int STATE_INITIAL = 0; const int STATE_INITIAL = 0;
const int STATE_READING_QUOTED_PARM = 1; const int STATE_READING_QUOTED_PARM = 1;
@ -487,7 +487,7 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename
unsigned int j=0; unsigned int j=0;
int state = STATE_INITIAL; int state = STATE_INITIAL;
int backslash=0; int backslash=0;
char temp_filename[MAX_PATH]; TCHAR temp_filename[MAX_PATH];
while(line[i] != '\0') while(line[i] != '\0')
{ {
@ -584,7 +584,7 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename
if (j >= (keyfilenamesize - 1)) if (j >= (keyfilenamesize - 1))
{ {
/* key filename to long */ /* key filename to long */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_KEY_FILENAME_TO_LONG); ShowLocalizedMsg(IDS_ERR_KEY_FILENAME_TO_LONG);
return(0); return(0);
} }
i++; i++;
@ -594,12 +594,12 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename
/* Prepend filename with configdir path if needed */ /* Prepend filename with configdir path if needed */
if ((keyfilename[0] != '\\') && (keyfilename[0] != '/') && (keyfilename[1] != ':')) if ((keyfilename[0] != '\\') && (keyfilename[0] != '/') && (keyfilename[1] != ':'))
{ {
strncpy(temp_filename, o.cnn[config].config_dir, sizeof(temp_filename)); _tcsncpy(temp_filename, o.cnn[config].config_dir, _tsizeof(temp_filename));
if (temp_filename[strlen(temp_filename) - 1] != '\\') if (temp_filename[_tcslen(temp_filename) - 1] != '\\')
strcat(temp_filename, "\\"); _tcscat(temp_filename, _T("\\"));
strncat(temp_filename, keyfilename, _tcsncat(temp_filename, keyfilename,
sizeof(temp_filename) - strlen(temp_filename) - 1); _tsizeof(temp_filename) - _tcslen(temp_filename) - 1);
strncpy(keyfilename, temp_filename, keyfilenamesize - 1); _tcsncpy(keyfilename, temp_filename, keyfilenamesize - 1);
} }
return(1); return(1);
@ -613,7 +613,7 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename
*/ */
int ChangePasswordPEM(HWND hwndDlg) int ChangePasswordPEM(HWND hwndDlg)
{ {
char keyfile[MAX_PATH]; TCHAR keyfile[MAX_PATH];
char oldpsw[50]; char oldpsw[50];
char newpsw[50]; char newpsw[50];
WCHAR oldpsw_unicode[50]; WCHAR oldpsw_unicode[50];
@ -623,7 +623,7 @@ int ChangePasswordPEM(HWND hwndDlg)
EVP_PKEY *privkey; EVP_PKEY *privkey;
/* Get filename, old_psw and new_psw from Dialog */ /* Get filename, old_psw and new_psw from Dialog */
GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, sizeof(keyfile) - 1); GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, _tsizeof(keyfile) - 1);
GetDlgItemTextW(hwndDlg, ID_EDT_PASS_CUR, oldpsw_unicode, sizeof(oldpsw_unicode)/2 - 1); GetDlgItemTextW(hwndDlg, ID_EDT_PASS_CUR, oldpsw_unicode, sizeof(oldpsw_unicode)/2 - 1);
GetDlgItemTextW(hwndDlg, ID_EDT_PASS_NEW, newpsw_unicode, sizeof(newpsw_unicode)/2 - 1); GetDlgItemTextW(hwndDlg, ID_EDT_PASS_NEW, newpsw_unicode, sizeof(newpsw_unicode)/2 - 1);
@ -631,17 +631,17 @@ int ChangePasswordPEM(HWND hwndDlg)
ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw)); ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw));
if (!ConvertUnicode2Ascii(newpsw_unicode, newpsw, sizeof(newpsw))) if (!ConvertUnicode2Ascii(newpsw_unicode, newpsw, sizeof(newpsw)))
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_INVALID_CHARS_IN_PSW); ShowLocalizedMsg(IDS_ERR_INVALID_CHARS_IN_PSW);
return(-1); return(-1);
} }
privkey = EVP_PKEY_new(); privkey = EVP_PKEY_new();
/* Open old keyfile for reading */ /* Open old keyfile for reading */
if (! (fp = fopen (keyfile, "r"))) if (! (fp = _tfopen (keyfile, _T("r"))))
{ {
/* can't open key file */ /* can't open key file */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_PRIVATE_KEY_FILE, keyfile); ShowLocalizedMsg(IDS_ERR_OPEN_PRIVATE_KEY_FILE, keyfile);
return(0); return(0);
} }
@ -649,7 +649,7 @@ int ChangePasswordPEM(HWND hwndDlg)
if (! (privkey = PEM_read_PrivateKey (fp, NULL, NULL, oldpsw))) if (! (privkey = PEM_read_PrivateKey (fp, NULL, NULL, oldpsw)))
{ {
/* wrong password */ /* wrong password */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OLD_PWD_INCORRECT); ShowLocalizedMsg(IDS_ERR_OLD_PWD_INCORRECT);
fclose(fp); fclose(fp);
return(-1); return(-1);
} }
@ -657,10 +657,10 @@ int ChangePasswordPEM(HWND hwndDlg)
fclose(fp); fclose(fp);
/* Open keyfile for writing */ /* Open keyfile for writing */
if (! (fp = fopen (keyfile, "w"))) if (! (fp = _tfopen (keyfile, _T("w"))))
{ {
/* can't open file rw */ /* can't open file rw */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_WRITE_KEY, keyfile); ShowLocalizedMsg(IDS_ERR_OPEN_WRITE_KEY, keyfile);
EVP_PKEY_free(privkey); EVP_PKEY_free(privkey);
return(0); return(0);
} }
@ -674,7 +674,7 @@ int ChangePasswordPEM(HWND hwndDlg)
0, 0, NULL))) 0, 0, NULL)))
{ {
/* error writing new key */ /* error writing new key */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_WRITE_NEW_KEY, keyfile); ShowLocalizedMsg(IDS_ERR_WRITE_NEW_KEY, keyfile);
EVP_PKEY_free(privkey); EVP_PKEY_free(privkey);
fclose(fp); fclose(fp);
return(0); return(0);
@ -688,7 +688,7 @@ int ChangePasswordPEM(HWND hwndDlg)
(UCHAR*) newpsw, (int) strlen(newpsw), 0, NULL))) (UCHAR*) newpsw, (int) strlen(newpsw), 0, NULL)))
{ {
/* can't write new key */ /* can't write new key */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_WRITE_NEW_KEY, keyfile); ShowLocalizedMsg(IDS_ERR_WRITE_NEW_KEY, keyfile);
EVP_PKEY_free(privkey); EVP_PKEY_free(privkey);
fclose(fp); fclose(fp);
return(0); return(0);
@ -699,7 +699,7 @@ int ChangePasswordPEM(HWND hwndDlg)
fclose(fp); fclose(fp);
/* signal success to user */ /* signal success to user */
ShowLocalizedMsg(PACKAGE_NAME, IDS_NFO_PWD_CHANGED); ShowLocalizedMsg(IDS_NFO_PWD_CHANGED);
return(1); return(1);
} }
@ -711,7 +711,7 @@ int ChangePasswordPEM(HWND hwndDlg)
*/ */
int ChangePasswordPKCS12(HWND hwndDlg) int ChangePasswordPKCS12(HWND hwndDlg)
{ {
char keyfile[MAX_PATH]; TCHAR keyfile[MAX_PATH];
char oldpsw[50]; char oldpsw[50];
char newpsw[50]; char newpsw[50];
WCHAR oldpsw_unicode[50]; WCHAR oldpsw_unicode[50];
@ -725,7 +725,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
char *alias; char *alias;
/* Get filename, old_psw and new_psw from Dialog */ /* Get filename, old_psw and new_psw from Dialog */
GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, sizeof(keyfile) - 1); GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, _tsizeof(keyfile) - 1);
GetDlgItemTextW(hwndDlg, ID_EDT_PASS_CUR, oldpsw_unicode, sizeof(oldpsw_unicode)/2 - 1); GetDlgItemTextW(hwndDlg, ID_EDT_PASS_CUR, oldpsw_unicode, sizeof(oldpsw_unicode)/2 - 1);
GetDlgItemTextW(hwndDlg, ID_EDT_PASS_NEW, newpsw_unicode, sizeof(newpsw_unicode)/2 - 1); GetDlgItemTextW(hwndDlg, ID_EDT_PASS_NEW, newpsw_unicode, sizeof(newpsw_unicode)/2 - 1);
@ -733,15 +733,15 @@ int ChangePasswordPKCS12(HWND hwndDlg)
ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw)); ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw));
if (!ConvertUnicode2Ascii(newpsw_unicode, newpsw, sizeof(newpsw))) if (!ConvertUnicode2Ascii(newpsw_unicode, newpsw, sizeof(newpsw)))
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_INVALID_CHARS_IN_PSW); ShowLocalizedMsg(IDS_ERR_INVALID_CHARS_IN_PSW);
return(-1); return(-1);
} }
/* Load the PKCS #12 file */ /* Load the PKCS #12 file */
if (!(fp = fopen(keyfile, "rb"))) if (!(fp = _tfopen(keyfile, _T("rb"))))
{ {
/* error opening file */ /* error opening file */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_PRIVATE_KEY_FILE, keyfile); ShowLocalizedMsg(IDS_ERR_OPEN_PRIVATE_KEY_FILE, keyfile);
return(0); return(0);
} }
p12 = d2i_PKCS12_fp(fp, NULL); p12 = d2i_PKCS12_fp(fp, NULL);
@ -749,7 +749,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
if (!p12) if (!p12)
{ {
/* error reading PKCS #12 */ /* error reading PKCS #12 */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READ_PKCS12, keyfile); ShowLocalizedMsg(IDS_ERR_READ_PKCS12, keyfile);
return(0); return(0);
} }
@ -757,7 +757,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
if (!PKCS12_parse(p12, oldpsw, &privkey, &cert, &ca)) if (!PKCS12_parse(p12, oldpsw, &privkey, &cert, &ca))
{ {
/* old password incorrect */ /* old password incorrect */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OLD_PWD_INCORRECT); ShowLocalizedMsg(IDS_ERR_OLD_PWD_INCORRECT);
PKCS12_free(p12); PKCS12_free(p12);
return(-1); return(-1);
} }
@ -773,7 +773,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
if (!p12) if (!p12)
{ {
/* create failed */ /* create failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PKCS12); ShowLocalizedMsg(IDS_ERR_CREATE_PKCS12);
return(0); return(0);
} }
@ -783,9 +783,9 @@ int ChangePasswordPKCS12(HWND hwndDlg)
sk_X509_pop_free(ca, X509_free); sk_X509_pop_free(ca, X509_free);
/* Open keyfile for writing */ /* Open keyfile for writing */
if (!(fp = fopen(keyfile, "wb"))) if (!(fp = _tfopen(keyfile, _T("wb"))))
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_WRITE_KEY, keyfile); ShowLocalizedMsg(IDS_ERR_OPEN_WRITE_KEY, keyfile);
PKCS12_free(p12); PKCS12_free(p12);
return(0); return(0);
} }
@ -796,7 +796,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
PKCS12_free(p12); PKCS12_free(p12);
fclose(fp); fclose(fp);
/* signal success to user */ /* signal success to user */
ShowLocalizedMsg(PACKAGE_NAME, IDS_NFO_PWD_CHANGED); ShowLocalizedMsg(IDS_NFO_PWD_CHANGED);
return(1); return(1);
} }
@ -812,24 +812,24 @@ int LineBeginsWith(char *line, const char *keyword, const unsigned int len)
return false; return false;
} }
int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize, int *keyfile_format) int GetKeyFilename(int config, TCHAR *keyfilename, size_t keyfilenamesize, int *keyfile_format)
{ {
FILE *fp; FILE *fp;
char line[256]; char line[256];
int found_key=0; int found_key=0;
int found_pkcs12=0; int found_pkcs12=0;
char configfile_path[MAX_PATH]; TCHAR configfile_path[MAX_PATH];
strncpy(configfile_path, o.cnn[config].config_dir, sizeof(configfile_path)); _tcsncpy(configfile_path, o.cnn[config].config_dir, _tsizeof(configfile_path));
if (!(configfile_path[strlen(configfile_path)-1] == '\\')) if (!(configfile_path[_tcslen(configfile_path)-1] == '\\'))
strcat(configfile_path, "\\"); _tcscat(configfile_path, _T("\\"));
strncat(configfile_path, o.cnn[config].config_file, _tcsncat(configfile_path, o.cnn[config].config_file,
sizeof(configfile_path) - strlen(configfile_path) - 1); _tsizeof(configfile_path) - _tcslen(configfile_path) - 1);
if (!(fp=fopen(configfile_path, "r"))) if (!(fp=_tfopen(configfile_path, _T("r"))))
{ {
/* can't open config file */ /* can't open config file */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_CONFIG, configfile_path); ShowLocalizedMsg(IDS_ERR_OPEN_CONFIG, configfile_path);
return(0); return(0);
} }
@ -840,13 +840,13 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize,
if (found_key) if (found_key)
{ {
/* only one key option */ /* only one key option */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONLY_ONE_KEY_OPTION); ShowLocalizedMsg(IDS_ERR_ONLY_ONE_KEY_OPTION);
return(0); return(0);
} }
if (found_pkcs12) if (found_pkcs12)
{ {
/* key XOR pkcs12 */ /* key XOR pkcs12 */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONLY_KEY_OR_PKCS12); ShowLocalizedMsg(IDS_ERR_ONLY_KEY_OR_PKCS12);
return(0); return(0);
} }
found_key=1; found_key=1;
@ -859,13 +859,13 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize,
if (found_pkcs12) if (found_pkcs12)
{ {
/* only one pkcs12 option */ /* only one pkcs12 option */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONLY_ONE_PKCS12_OPTION); ShowLocalizedMsg(IDS_ERR_ONLY_ONE_PKCS12_OPTION);
return(0); return(0);
} }
if (found_key) if (found_key)
{ {
/* only key XOR pkcs12 */ /* only key XOR pkcs12 */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONLY_KEY_OR_PKCS12); ShowLocalizedMsg(IDS_ERR_ONLY_KEY_OR_PKCS12);
return(0); return(0);
} }
found_pkcs12=1; found_pkcs12=1;
@ -878,7 +878,7 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize,
if ((!found_key) && (!found_pkcs12)) if ((!found_key) && (!found_pkcs12))
{ {
/* must have key or pkcs12 option */ /* must have key or pkcs12 option */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_HAVE_KEY_OR_PKCS12); ShowLocalizedMsg(IDS_ERR_HAVE_KEY_OR_PKCS12);
return(0); return(0);
} }

View File

@ -39,5 +39,5 @@ int ConfirmNewPassword(HWND hwndDlg);
int NewPasswordLengh(HWND hwndDlg); int NewPasswordLengh(HWND hwndDlg);
int ChangePasswordPEM(HWND hwndDlg); int ChangePasswordPEM(HWND hwndDlg);
int ChangePasswordPKCS12(HWND hwndDlg); int ChangePasswordPKCS12(HWND hwndDlg);
int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize, int *keyfile_format); int GetKeyFilename(int config, TCHAR *keyfilename, size_t keyfilenamesize, int *keyfile_format);

20
proxy.c
View File

@ -154,7 +154,7 @@ int CheckProxySettings(HWND hwndDlg)
if (_tcslen(text) == 0) if (_tcslen(text) == 0)
{ {
/* proxy address not specified */ /* proxy address not specified */
ShowLocalizedMsg(PACKAGE_NAME, (http ? IDS_ERR_HTTP_PROXY_ADDRESS : IDS_ERR_SOCKS_PROXY_ADDRESS)); ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_ADDRESS : IDS_ERR_SOCKS_PROXY_ADDRESS));
return(0); return(0);
} }
@ -162,15 +162,15 @@ int CheckProxySettings(HWND hwndDlg)
if (_tcslen(text) == 0) if (_tcslen(text) == 0)
{ {
/* proxy port not specified */ /* proxy port not specified */
ShowLocalizedMsg(PACKAGE_NAME, (http ? IDS_ERR_HTTP_PROXY_PORT : IDS_ERR_SOCKS_PROXY_PORT)); ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_PORT : IDS_ERR_SOCKS_PROXY_PORT));
return(0); return(0);
} }
long port = strtol(text, NULL, 10); long port = _tcstol(text, NULL, 10);
if ((port < 1) || (port > 65535)) if ((port < 1) || (port > 65535))
{ {
/* proxy port range error */ /* proxy port range error */
ShowLocalizedMsg(PACKAGE_NAME, (http ? IDS_ERR_HTTP_PROXY_PORT_RANGE : IDS_ERR_SOCKS_PROXY_PORT_RANGE)); ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_PORT_RANGE : IDS_ERR_SOCKS_PROXY_PORT_RANGE));
return(0); return(0);
} }
} }
@ -268,7 +268,7 @@ void SaveProxySettings(HWND hwndDlg)
&dwDispos) != ERROR_SUCCESS) &dwDispos) != ERROR_SUCCESS)
{ {
/* error creating Registry-Key */ /* error creating Registry-Key */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU); ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
return; return;
} }
@ -297,7 +297,7 @@ void GetProxyRegistrySettings()
if (!GetTempPath(_tsizeof(temp_path) - 1, temp_path)) if (!GetTempPath(_tsizeof(temp_path) - 1, temp_path))
{ {
/* Error getting TempPath - using C:\ */ /* Error getting TempPath - using C:\ */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GET_TEMP_PATH); ShowLocalizedMsg(IDS_ERR_GET_TEMP_PATH);
_tcscpy(temp_path, _T("C:\\")); _tcscpy(temp_path, _T("C:\\"));
} }
_tcsncat(temp_path, _T("openvpn_authfile.txt"), _tcsncat(temp_path, _T("openvpn_authfile.txt"),
@ -368,13 +368,13 @@ BOOL CALLBACK ProxyAuthDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED
if (!(fp = _tfopen(o.proxy_authfile, _T("w")))) if (!(fp = _tfopen(o.proxy_authfile, _T("w"))))
{ {
/* error creating AUTH file */ /* error creating AUTH file */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_AUTH_FILE, o.proxy_authfile); ShowLocalizedMsg(IDS_ERR_CREATE_AUTH_FILE, o.proxy_authfile);
EndDialog(hwndDlg, LOWORD(wParam)); EndDialog(hwndDlg, LOWORD(wParam));
} }
_fputts(username, fp); _fputts(username, fp);
_fputts("\n", fp); _fputts(_T("\n"), fp);
_fputts(password, fp); _fputts(password, fp);
_fputts("\n", fp); _fputts(_T("\n"), fp);
fclose(fp); fclose(fp);
EndDialog(hwndDlg, LOWORD(wParam)); EndDialog(hwndDlg, LOWORD(wParam));
return TRUE; return TRUE;
@ -410,7 +410,7 @@ GetIeHttpProxy(TCHAR *host, size_t *hostlen, TCHAR *port, size_t *portlen)
if (!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, (LPVOID) &pinfo, &psize)) if (!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, (LPVOID) &pinfo, &psize))
{ {
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GET_MSIE_PROXY); ShowLocalizedMsg(IDS_ERR_GET_MSIE_PROXY);
return FALSE; return FALSE;
} }

View File

@ -44,7 +44,7 @@ GetRegistryKeys()
if (!GetWindowsDirectory(windows_dir, _tsizeof(windows_dir))) { if (!GetWindowsDirectory(windows_dir, _tsizeof(windows_dir))) {
/* can't get windows dir */ /* can't get windows dir */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GET_WINDOWS_DIR); ShowLocalizedMsg(IDS_ERR_GET_WINDOWS_DIR);
return(false); return(false);
} }
@ -53,13 +53,13 @@ GetRegistryKeys()
!= ERROR_SUCCESS) != ERROR_SUCCESS)
{ {
/* registry key not found */ /* registry key not found */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_REGISTRY); ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY);
return(false); return(false);
} }
if (!GetRegistryValue(regkey, _T(""), openvpn_path, _tsizeof(openvpn_path))) if (!GetRegistryValue(regkey, _T(""), openvpn_path, _tsizeof(openvpn_path)))
{ {
/* error reading registry value */ /* error reading registry value */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READING_REGISTRY); ShowLocalizedMsg(IDS_ERR_READING_REGISTRY);
return(false); return(false);
} }
if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\')) if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\'))
@ -114,41 +114,41 @@ GetRegistryKeys()
if (!GetRegKey(_T("passphrase_attempts"), o.psw_attempts_string, _T("3"), if (!GetRegKey(_T("passphrase_attempts"), o.psw_attempts_string, _T("3"),
_tsizeof(o.psw_attempts_string))) return(false); _tsizeof(o.psw_attempts_string))) return(false);
o.psw_attempts = atoi(o.psw_attempts_string); o.psw_attempts = _ttoi(o.psw_attempts_string);
if ((o.psw_attempts < 1) || (o.psw_attempts > 9)) if ((o.psw_attempts < 1) || (o.psw_attempts > 9))
{ {
/* 0 <= passphrase_attempts <= 9 */ /* 0 <= passphrase_attempts <= 9 */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PASSPHRASE_ATTEMPTS); ShowLocalizedMsg(IDS_ERR_PASSPHRASE_ATTEMPTS);
return(false); return(false);
} }
if (!GetRegKey(_T("connectscript_timeout"), o.connectscript_timeout_string, _T("15"), if (!GetRegKey(_T("connectscript_timeout"), o.connectscript_timeout_string, _T("15"),
_tsizeof(o.connectscript_timeout_string))) return(false); _tsizeof(o.connectscript_timeout_string))) return(false);
o.connectscript_timeout = atoi(o.connectscript_timeout_string); o.connectscript_timeout = _ttoi(o.connectscript_timeout_string);
if ((o.connectscript_timeout < 0) || (o.connectscript_timeout > 99)) if ((o.connectscript_timeout < 0) || (o.connectscript_timeout > 99))
{ {
/* 0 <= connectscript_timeout <= 99 */ /* 0 <= connectscript_timeout <= 99 */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CONN_SCRIPT_TIMEOUT); ShowLocalizedMsg(IDS_ERR_CONN_SCRIPT_TIMEOUT);
return(false); return(false);
} }
if (!GetRegKey(_T("disconnectscript_timeout"), o.disconnectscript_timeout_string, _T("10"), if (!GetRegKey(_T("disconnectscript_timeout"), o.disconnectscript_timeout_string, _T("10"),
_tsizeof(o.disconnectscript_timeout_string))) return(false); _tsizeof(o.disconnectscript_timeout_string))) return(false);
o.disconnectscript_timeout = atoi(o.disconnectscript_timeout_string); o.disconnectscript_timeout = _ttoi(o.disconnectscript_timeout_string);
if ((o.disconnectscript_timeout <= 0) || (o.disconnectscript_timeout > 99)) if ((o.disconnectscript_timeout <= 0) || (o.disconnectscript_timeout > 99))
{ {
/* 0 < disconnectscript_timeout <= 99 */ /* 0 < disconnectscript_timeout <= 99 */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DISCONN_SCRIPT_TIMEOUT); ShowLocalizedMsg(IDS_ERR_DISCONN_SCRIPT_TIMEOUT);
return(false); return(false);
} }
if (!GetRegKey(_T("preconnectscript_timeout"), o.preconnectscript_timeout_string, _T("10"), if (!GetRegKey(_T("preconnectscript_timeout"), o.preconnectscript_timeout_string, _T("10"),
_tsizeof(o.preconnectscript_timeout_string))) return(false); _tsizeof(o.preconnectscript_timeout_string))) return(false);
o.preconnectscript_timeout = atoi(o.preconnectscript_timeout_string); o.preconnectscript_timeout = _ttoi(o.preconnectscript_timeout_string);
if ((o.preconnectscript_timeout <= 0) || (o.preconnectscript_timeout > 99)) if ((o.preconnectscript_timeout <= 0) || (o.preconnectscript_timeout > 99))
{ {
/* 0 < disconnectscript_timeout <= 99 */ /* 0 < disconnectscript_timeout <= 99 */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PRECONN_SCRIPT_TIMEOUT); ShowLocalizedMsg(IDS_ERR_PRECONN_SCRIPT_TIMEOUT);
return(false); return(false);
} }
@ -164,10 +164,8 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
HKEY openvpn_key_write; HKEY openvpn_key_write;
DWORD dwDispos; DWORD dwDispos;
TCHAR expanded_string[MAX_PATH]; TCHAR expanded_string[MAX_PATH];
DWORD max_len; DWORD size = len * sizeof(*data);
DWORD max_len = len - 1;
/* Save maximum string length */
max_len=len;
/* If option is already set via cmd-line, return */ /* If option is already set via cmd-line, return */
if (data[0] != 0) if (data[0] != 0)
@ -197,14 +195,14 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
&dwDispos) != ERROR_SUCCESS) &dwDispos) != ERROR_SUCCESS)
{ {
/* error creating registry key */ /* error creating registry key */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_REG_KEY); ShowLocalizedMsg(IDS_ERR_CREATE_REG_KEY);
return(false); return(false);
} }
} }
/* get a registry string */ /* get a registry string */
status = RegQueryValueEx(openvpn_key, name, NULL, &type, (byte *) data, &len); status = RegQueryValueEx(openvpn_key, name, NULL, &type, (byte *) data, &size);
if (status != ERROR_SUCCESS || type != REG_SZ) if (status != ERROR_SUCCESS || type != REG_SZ)
{ {
/* key did not exist - set default value */ /* key did not exist - set default value */
@ -216,18 +214,12 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
if (status != ERROR_SUCCESS) { if (status != ERROR_SUCCESS) {
/* can't open registry for writing */ /* can't open registry for writing */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_WRITE_REG); ShowLocalizedMsg(IDS_ERR_OPEN_WRITE_REG);
return(false); return(false);
} }
if(RegSetValueEx(openvpn_key_write, if(!SetRegistryValue(openvpn_key_write, name, default_data))
name,
0,
REG_SZ,
(const PBYTE) default_data,
_tcslen(default_data)+1))
{ {
/* cant read / set reg-key */ /* cant read / set reg-key */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READ_SET_KEY, name);
return(false); return(false);
} }
_tcsncpy(data, default_data, max_len); _tcsncpy(data, default_data, max_len);
@ -250,14 +242,14 @@ LONG GetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data, DWORD len)
DWORD type; DWORD type;
DWORD data_len; DWORD data_len;
data_len = len; data_len = len * sizeof(*data);
/* get a registry string */ /* get a registry string */
status = RegQueryValueEx(regkey, name, NULL, &type, (byte *) data, &data_len); status = RegQueryValueEx(regkey, name, NULL, &type, (byte *) data, &data_len);
if (status != ERROR_SUCCESS || type != REG_SZ) if (status != ERROR_SUCCESS || type != REG_SZ)
return(0); return(0);
return(data_len); return(data_len / sizeof(*data));
} }
@ -270,13 +262,14 @@ GetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD *data)
return (type == REG_DWORD ? status : ERROR_FILE_NOT_FOUND); return (type == REG_DWORD ? status : ERROR_FILE_NOT_FOUND);
} }
int SetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data) int SetRegistryValue(HKEY regkey, const TCHAR *name, const TCHAR *data)
{ {
/* set a registry string */ /* set a registry string */
if(RegSetValueEx(regkey, name, 0, REG_SZ, (PBYTE) data, _tcslen(data) + 1) != ERROR_SUCCESS) DWORD size = (_tcslen(data) + 1) * sizeof(*data);
if(RegSetValueEx(regkey, name, 0, REG_SZ, (PBYTE) data, size) != ERROR_SUCCESS)
{ {
/* Error writing registry value */ /* Error writing registry value */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name); ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name);
return(0); return(0);
} }
@ -291,6 +284,6 @@ SetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD data)
if (status == ERROR_SUCCESS) if (status == ERROR_SUCCESS)
return 1; return 1;
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name); ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name);
return 0; return 0;
} }

View File

@ -26,7 +26,7 @@ int GetRegistryKeys();
int GetRegKey(const TCHAR name[], TCHAR data[], const TCHAR default_data[], DWORD len); int GetRegKey(const TCHAR name[], TCHAR data[], const TCHAR default_data[], DWORD len);
LONG GetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data, DWORD len); LONG GetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data, DWORD len);
LONG GetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD *data); LONG GetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD *data);
int SetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data); int SetRegistryValue(HKEY regkey, const TCHAR *name, const TCHAR *data);
int SetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD data); int SetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD data);
#endif #endif

View File

@ -21,6 +21,7 @@
#include <windows.h> #include <windows.h>
#include <process.h> #include <process.h>
#include <tchar.h>
#include "config.h" #include "config.h"
#include "main.h" #include "main.h"
@ -38,15 +39,15 @@ void RunConnectScript(int config, int run_as_service)
PROCESS_INFORMATION proc_info; PROCESS_INFORMATION proc_info;
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; SECURITY_DESCRIPTOR sd;
char command_line[256]; TCHAR command_line[256];
char batch_file[100]; TCHAR batch_file[100];
DWORD ExitCode; DWORD ExitCode;
int i, TimeOut; int i, TimeOut;
/* Cut of extention from config filename and add "_up.bat". */ /* Cut of extention from config filename and add "_up.bat". */
strncpy(batch_file, o.cnn[config].config_file, sizeof(batch_file)); _tcsncpy(batch_file, o.cnn[config].config_file, _tsizeof(batch_file));
batch_file[strlen(batch_file) - (strlen(o.ext_string)+1)]=0; batch_file[_tcslen(batch_file) - (_tcslen(o.ext_string)+1)]=0;
strncat(batch_file, "_up.bat", sizeof(batch_file) - strlen(batch_file) - 1); _tcsncat(batch_file, _T("_up.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1);
_sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); _sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file);
@ -91,7 +92,7 @@ void RunConnectScript(int config, int run_as_service)
&proc_info)) &proc_info))
{ {
/* Running Script failed */ /* Running Script failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_RUN_CONN_SCRIPT, command_line); ShowLocalizedMsg(IDS_ERR_RUN_CONN_SCRIPT, command_line);
return; return;
} }
@ -108,7 +109,7 @@ void RunConnectScript(int config, int run_as_service)
if (!GetExitCodeProcess(proc_info.hProcess, &ExitCode)) if (!GetExitCodeProcess(proc_info.hProcess, &ExitCode))
{ {
/* failed to get ExitCode */ /* failed to get ExitCode */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GET_EXIT_CODE, command_line); ShowLocalizedMsg(IDS_ERR_GET_EXIT_CODE, command_line);
return; return;
} }
@ -117,7 +118,7 @@ void RunConnectScript(int config, int run_as_service)
if (ExitCode != 0) if (ExitCode != 0)
{ {
/* ConnectScript failed */ /* ConnectScript failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CONN_SCRIPT_FAILED, ExitCode); ShowLocalizedMsg(IDS_ERR_CONN_SCRIPT_FAILED, ExitCode);
return; return;
} }
return; return;
@ -127,7 +128,7 @@ void RunConnectScript(int config, int run_as_service)
} }
/* UserInfo: Timeout */ /* UserInfo: Timeout */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_RUN_CONN_SCRIPT_TIMEOUT, TimeOut); ShowLocalizedMsg(IDS_ERR_RUN_CONN_SCRIPT_TIMEOUT, TimeOut);
} }
@ -139,14 +140,14 @@ void RunDisconnectScript(int config, int run_as_service)
PROCESS_INFORMATION proc_info; PROCESS_INFORMATION proc_info;
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; SECURITY_DESCRIPTOR sd;
char command_line[256]; TCHAR command_line[256];
char batch_file[100]; TCHAR batch_file[100];
DWORD ExitCode; DWORD ExitCode;
int i, TimeOut; int i, TimeOut;
/* Append "_down.bat" to config name. */ /* Append "_down.bat" to config name. */
strncpy(batch_file, o.cnn[config].config_name, sizeof(batch_file)); _tcsncpy(batch_file, o.cnn[config].config_name, _tsizeof(batch_file));
strncat(batch_file, "_down.bat", sizeof(batch_file) - strlen(batch_file) - 1); _tcsncat(batch_file, _T("_down.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1);
_sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); _sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file);
@ -219,14 +220,14 @@ void RunPreconnectScript(int config)
PROCESS_INFORMATION proc_info; PROCESS_INFORMATION proc_info;
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd; SECURITY_DESCRIPTOR sd;
char command_line[256]; TCHAR command_line[256];
char batch_file[100]; TCHAR batch_file[100];
DWORD ExitCode; DWORD ExitCode;
int i, TimeOut; int i, TimeOut;
/* Append "_pre.bat" to config name. */ /* Append "_pre.bat" to config name. */
strncpy(batch_file, o.cnn[config].config_name, sizeof(batch_file)); _tcsncpy(batch_file, o.cnn[config].config_name, _tsizeof(batch_file));
strncat(batch_file, "_pre.bat", sizeof(batch_file) - strlen(batch_file) - 1); _tcsncat(batch_file, _T("_pre.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1);
_sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); _sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file);

View File

@ -58,18 +58,18 @@ int MyStartService()
if (NULL == schSCManager) { if (NULL == schSCManager) {
/* open SC manager failed */ /* open SC manager failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_SCMGR); ShowLocalizedMsg(IDS_ERR_OPEN_SCMGR);
goto failed; goto failed;
} }
schService = OpenService( schService = OpenService(
schSCManager, // SCM database schSCManager, // SCM database
"OpenVPNService", // service name _T("OpenVPNService"), // service name
SERVICE_START | SERVICE_QUERY_STATUS); SERVICE_START | SERVICE_QUERY_STATUS);
if (schService == NULL) { if (schService == NULL) {
/* can't open VPN service */ /* can't open VPN service */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_VPN_SERVICE); ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE);
goto failed; goto failed;
} }
@ -83,7 +83,7 @@ int MyStartService()
NULL) ) // no arguments NULL) ) // no arguments
{ {
/* can't start */ /* can't start */
ShowLocalizedMsg(NULL, IDS_ERR_START_SERVICE); ShowLocalizedMsg(IDS_ERR_START_SERVICE);
goto failed; goto failed;
} }
else else
@ -97,7 +97,7 @@ int MyStartService()
&ssStatus) ) // address of status information structure &ssStatus) ) // address of status information structure
{ {
/* query failed */ /* query failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_QUERY_SERVICE); ShowLocalizedMsg(IDS_ERR_QUERY_SERVICE);
goto failed; goto failed;
} }
@ -148,7 +148,7 @@ int MyStartService()
if (ssStatus.dwCurrentState != SERVICE_RUNNING) if (ssStatus.dwCurrentState != SERVICE_RUNNING)
{ {
/* service hasn't started */ /* service hasn't started */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_SERVICE_START_FAILED); ShowLocalizedMsg(IDS_ERR_SERVICE_START_FAILED);
goto failed; goto failed;
} }
@ -162,7 +162,7 @@ int MyStartService()
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
/* Show "OpenVPN Service Started" Tray Balloon msg */ /* Show "OpenVPN Service Started" Tray Balloon msg */
ShowTrayBalloon(LoadLocalizedString(IDS_NFO_SERVICE_STARTED), " "); ShowTrayBalloon(LoadLocalizedString(IDS_NFO_SERVICE_STARTED), _T(""));
return(true); return(true);
@ -191,18 +191,18 @@ int MyStopService()
if (NULL == schSCManager) { if (NULL == schSCManager) {
/* can't open SCManager */ /* can't open SCManager */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_SCMGR, (int) GetLastError()); ShowLocalizedMsg(IDS_ERR_OPEN_SCMGR, (int) GetLastError());
return(false); return(false);
} }
schService = OpenService( schService = OpenService(
schSCManager, // SCM database schSCManager, // SCM database
"OpenVPNService", // service name _T("OpenVPNService"), // service name
SERVICE_STOP); SERVICE_STOP);
if (schService == NULL) { if (schService == NULL) {
/* can't open vpn service */ /* can't open vpn service */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_VPN_SERVICE); ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE);
return(false); return(false);
} }
@ -216,7 +216,7 @@ int MyStopService()
&ssStatus) ) // address of status info &ssStatus) ) // address of status info
{ {
/* stop failed */ /* stop failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_STOP_SERVICE); ShowLocalizedMsg(IDS_ERR_STOP_SERVICE);
return(false); return(false);
} }
@ -260,12 +260,12 @@ int CheckServiceStatus()
schService = OpenService( schService = OpenService(
schSCManager, // SCM database schSCManager, // SCM database
"OpenVPNService", // service name _T("OpenVPNService"), // service name
SERVICE_QUERY_STATUS); SERVICE_QUERY_STATUS);
if (schService == NULL) { if (schService == NULL) {
/* open vpn service failed */ /* open vpn service failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_VPN_SERVICE); ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE);
o.service_running = SERVICE_NOACCESS; o.service_running = SERVICE_NOACCESS;
SetServiceMenuStatus(); SetServiceMenuStatus();
return(false); return(false);
@ -276,7 +276,7 @@ int CheckServiceStatus()
&ssStatus) ) // address of status information structure &ssStatus) ) // address of status information structure
{ {
/* query failed */ /* query failed */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_QUERY_SERVICE); ShowLocalizedMsg(IDS_ERR_QUERY_SERVICE);
return(false); return(false);
} }

6
tray.c
View File

@ -89,7 +89,7 @@ void OnNotifyTray(LPARAM lParam)
else if (o.service_running == SERVICE_CONNECTED) else if (o.service_running == SERVICE_CONNECTED)
{ {
/* Stop OpenVPN service */ /* Stop OpenVPN service */
if (MessageBox(NULL, LoadLocalizedString(IDS_MENU_ASK_STOP_SERVICE), PACKAGE_NAME, MB_YESNO | MB_SETFOREGROUND) == IDYES) if (MessageBox(NULL, LoadLocalizedString(IDS_MENU_ASK_STOP_SERVICE), _T(PACKAGE_NAME), MB_YESNO | MB_SETFOREGROUND) == IDYES)
{ {
MyStopService(); MyStopService();
} }
@ -359,7 +359,7 @@ void SetTrayIcon(int connected)
if (first_conn) if (first_conn)
_tcsncat(msg, msg_connected, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, msg_connected, _tsizeof(msg) - _tcslen(msg) - 1);
else else
_tcsncat(msg, ", ", _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, _T(", "), _tsizeof(msg) - _tcslen(msg) - 1);
_tcsncat(msg, o.cnn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, o.cnn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1);
first_conn=0; first_conn=0;
config=i; config=i;
@ -376,7 +376,7 @@ void SetTrayIcon(int connected)
if (first_conn) if (first_conn)
_tcsncat(msg, msg_connecting, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, msg_connecting, _tsizeof(msg) - _tcslen(msg) - 1);
else else
_tcsncat(msg, ", ", _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, _T(", "), _tsizeof(msg) - _tcslen(msg) - 1);
_tcsncat(msg, o.cnn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, o.cnn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1);
first_conn=0; first_conn=0;
} }

View File

@ -34,7 +34,7 @@ extern struct options o;
void ViewLog(int config) void ViewLog(int config)
{ {
char filename[200]; TCHAR filename[200];
STARTUPINFO start_info; STARTUPINFO start_info;
PROCESS_INFORMATION proc_info; PROCESS_INFORMATION proc_info;
@ -68,7 +68,7 @@ void ViewLog(int config)
&proc_info)) &proc_info))
{ {
/* could not start log viewer */ /* could not start log viewer */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_START_LOG_VIEWER, o.log_viewer); ShowLocalizedMsg(IDS_ERR_START_LOG_VIEWER, o.log_viewer);
} }
} }
@ -76,7 +76,7 @@ void ViewLog(int config)
void EditConfig(int config) void EditConfig(int config)
{ {
char filename[200]; TCHAR filename[200];
STARTUPINFO start_info; STARTUPINFO start_info;
PROCESS_INFORMATION proc_info; PROCESS_INFORMATION proc_info;
@ -110,7 +110,7 @@ void EditConfig(int config)
&proc_info)) &proc_info))
{ {
/* could not start editor */ /* could not start editor */
ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_START_CONF_EDITOR, o.editor); ShowLocalizedMsg(IDS_ERR_START_CONF_EDITOR, o.editor);
} }
} }