diff --git a/localization.c b/localization.c index aff8abd..3b95f35 100644 --- a/localization.c +++ b/localization.c @@ -69,7 +69,7 @@ GetGUILanguage(void) LONG status = RegOpenKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, KEY_READ, ®key); if (status == ERROR_SUCCESS) - GetRegistryValueNumeric(regkey, "ui_language", &value); + GetRegistryValueNumeric(regkey, _T("ui_language"), &value); gui_language = ( value != 0 ? value : LANGIDFROMLCID(GetThreadLocale()) ); return gui_language; @@ -82,9 +82,9 @@ SetGUILanguage(LANGID langId) HKEY regkey; if (RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, NULL, 0, KEY_WRITE, NULL, ®key, 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; } @@ -175,11 +175,11 @@ LoadLocalizedStringBuf(PTSTR buffer, int bufferSize, const UINT stringId, ...) void -ShowLocalizedMsg(const PTSTR caption, const UINT stringId, ...) +ShowLocalizedMsg(const UINT stringId, ...) { va_list args; 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); } diff --git a/localization.h b/localization.h index b9b7597..3082117 100644 --- a/localization.h +++ b/localization.h @@ -24,7 +24,7 @@ PTSTR LoadLocalizedString(const UINT, ...); int LoadLocalizedStringBuf(PTSTR, const int, const UINT, ...); -void ShowLocalizedMsg(const PTSTR, const UINT, ...); +void ShowLocalizedMsg(const UINT, ...); HICON LoadLocalizedIcon(const UINT); LPCDLGTEMPLATE LocalizedDialogResource(const UINT); INT_PTR LocalizedDialogBoxParam(const UINT, DLGPROC, const LPARAM); diff --git a/main.c b/main.c index 9161835..404ddee 100644 --- a/main.c +++ b/main.c @@ -50,15 +50,15 @@ static void ShowSettingsDialog(); void CloseApplication(HWND hwnd); /* Class name and window title */ -char szClassName[ ] = "OpenVPN-GUI"; -char szTitleText[ ] = "OpenVPN"; +TCHAR szClassName[ ] = _T("OpenVPN-GUI"); +TCHAR szTitleText[ ] = _T("OpenVPN"); /* Options structure */ struct options o; int WINAPI WinMain (HINSTANCE hThisInstance, UNUSED HINSTANCE hPrevInstance, - LPSTR lpszArgument, + UNUSED LPSTR lpszArgument, UNUSED int nCmdShow) { 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"))) { /* 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); } PrintDebug("Starting OpenVPN GUI v%s", PACKAGE_VERSION); @@ -84,23 +84,23 @@ int WINAPI WinMain (HINSTANCE hThisInstance, o.hInstance = hThisInstance; - if(!GetModuleHandle("RICHED20.DLL")) + if(!GetModuleHandle(_T("RICHED20.DLL"))) { - LoadLibrary("RICHED20.DLL"); + LoadLibrary(_T("RICHED20.DLL")); } else { /* can't load riched20.dll */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_LOAD_RICHED20); + ShowLocalizedMsg(IDS_ERR_LOAD_RICHED20); exit(1); } /* Check version of shell32.dll */ - shell32_version=GetDllVersion("shell32.dll"); + shell32_version=GetDllVersion(_T("shell32.dll")); if (shell32_version < PACKVERSION(5,0)) { /* 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); } #ifdef DEBUG @@ -109,13 +109,13 @@ int WINAPI WinMain (HINSTANCE hThisInstance, /* Parse command-line options */ - Createargcargv(&o, lpszArgument); + Createargcargv(&o, GetCommandLine()); /* Check if a previous instance is already running. */ if ((FindWindow (szClassName, NULL)) != NULL) { /* GUI already running */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GUI_ALREADY_RUNNING); + ShowLocalizedMsg(IDS_ERR_GUI_ALREADY_RUNNING); exit(1); } @@ -396,7 +396,7 @@ void CloseApplication(HWND hwnd) 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; } @@ -410,7 +410,7 @@ void CloseApplication(HWND hwnd) } if (ask_exit) { /* 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; } diff --git a/main.h b/main.h index b6bf797..4d04cac 100644 --- a/main.h +++ b/main.h @@ -34,10 +34,10 @@ //#define DISABLE_CHANGE_PASSWORD /* 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 */ -#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 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; } +/* _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 /* Print Debug Message */ #define PrintDebug(...) \ diff --git a/openvpn.c b/openvpn.c index 636c384..59a684b 100644 --- a/openvpn.c +++ b/openvpn.c @@ -65,12 +65,12 @@ int CreateExitEvent(int config) if (GetLastError() == ERROR_ACCESS_DENIED) { /* 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 { /* 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); } @@ -85,7 +85,7 @@ int CreateExitEvent(int config) if (o.cnn[config].exit_event == NULL) { /* 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); } } @@ -102,20 +102,20 @@ int SetProcessPriority(DWORD *priority) /* set process priority */ *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; - 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; - else if (!strcmp (o.priority_string, "NORMAL_PRIORITY_CLASS")) + else if (!_tcscmp(o.priority_string, _T("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; - else if (!strcmp (o.priority_string, "HIGH_PRIORITY_CLASS")) + else if (!_tcscmp(o.priority_string, _T("HIGH_PRIORITY_CLASS"))) *priority = HIGH_PRIORITY_CLASS; else { /* unknown priority */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_UNKNOWN_PRIORITY, o.priority_string); + ShowLocalizedMsg(IDS_ERR_UNKNOWN_PRIORITY, o.priority_string); return (false); } @@ -144,8 +144,8 @@ int StartOpenVPN(int config) PROCESS_INFORMATION proc_info; SECURITY_ATTRIBUTES sa; SECURITY_DESCRIPTOR sd; - char command_line[256]; - char proxy_string[100]; + TCHAR command_line[256]; + TCHAR proxy_string[100]; int i, is_connected=0; CLEAR (start_info); @@ -169,7 +169,7 @@ int StartOpenVPN(int config) if (is_connected) { /* 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); } } @@ -178,7 +178,7 @@ int StartOpenVPN(int config) if ((ConfigFileOptionExist(config, "log ")) || (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); } @@ -198,12 +198,12 @@ int StartOpenVPN(int config) if ((o.append_string[0] != '0') && (o.append_string[0] != '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; } /* construct proxy string to append to command line */ - ConstructProxyCmdLine(proxy_string, sizeof(proxy_string)); + ConstructProxyCmdLine(proxy_string, _tsizeof(proxy_string)); /* construct command line */ if (o.oldversion == 1) @@ -228,13 +228,13 @@ int StartOpenVPN(int config) if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION)) { /* Init Sec. Desc. failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_INIT_SEC_DESC); + ShowLocalizedMsg(IDS_ERR_INIT_SEC_DESC); goto failed; } if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE)) { /* set Dacl failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_SET_SEC_DESC_ACL); + ShowLocalizedMsg(IDS_ERR_SET_SEC_DESC_ACL); goto failed; } @@ -243,7 +243,7 @@ int StartOpenVPN(int config) if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0)) { /* CreatePipe failed. */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PIPE_OUTPUT); + ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_OUTPUT); goto failed; } @@ -255,7 +255,7 @@ int StartOpenVPN(int config) TRUE,DUPLICATE_SAME_ACCESS)) { /* DuplicateHandle failed. */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_ERR_WRITE); + ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_ERR_WRITE); goto failed; } @@ -263,7 +263,7 @@ int StartOpenVPN(int config) if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0)) { /* CreatePipe failed. */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PIPE_INPUT); + ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_INPUT); goto failed; } @@ -278,7 +278,7 @@ int StartOpenVPN(int config) DUPLICATE_SAME_ACCESS)) { /* Duplicate Handle failed. */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_OUT_READ); + ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_OUT_READ); goto failed; } @@ -289,7 +289,7 @@ int StartOpenVPN(int config) DUPLICATE_SAME_ACCESS)) { /* DuplicateHandle failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_IN_WRITE); + ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_IN_WRITE); goto failed; } @@ -297,7 +297,7 @@ int StartOpenVPN(int config) if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp)) { /* Close Handle failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CLOSE_HANDLE_TMP); + ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE_TMP); CloseHandle (o.cnn[config].exit_event); return(0); } @@ -328,7 +328,7 @@ int StartOpenVPN(int config) &proc_info)) { /* CreateProcess failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_PROCESS, + ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS, o.exe_path, command_line, o.cnn[config].config_dir); @@ -346,7 +346,7 @@ int StartOpenVPN(int config) !CloseHandle (hErrorWrite)) { /* CloseHandle failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CLOSE_HANDLE); + ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE); CloseHandle (o.cnn[config].exit_event); return(false); } @@ -370,7 +370,7 @@ int StartOpenVPN(int config) if (hThread == NULL) { /* CreateThread failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_THREAD_STATUS); + ShowLocalizedMsg(IDS_ERR_CREATE_THREAD_STATUS); goto failed; } @@ -469,7 +469,7 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (!hwndLogWindow) { /* Create RichEd LogWindow Failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_EDIT_LOGWINDOW); + ShowLocalizedMsg(IDS_ERR_CREATE_EDIT_LOGWINDOW); return FALSE; } @@ -479,10 +479,10 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED; charformat.dwEffects = 0; 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) { /* set size failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_SET_SIZE); + ShowLocalizedMsg(IDS_ERR_SET_SIZE); } /* Set Size and Posision of controls */ @@ -604,7 +604,7 @@ int VerifyAutoConnections() match = false; 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; break; @@ -613,7 +613,7 @@ int VerifyAutoConnections() if (match == false) { /* 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; } } @@ -636,9 +636,9 @@ int CheckVersion() PROCESS_INFORMATION proc_info; SECURITY_ATTRIBUTES sa; SECURITY_DESCRIPTOR sd; - char command_line[256]; + TCHAR command_line[256]; char line[1024]; - char bin_path[MAX_PATH]; + TCHAR bin_path[MAX_PATH]; char *p; int oldversion, i; @@ -647,7 +647,7 @@ int CheckVersion() CLEAR (sa); CLEAR (sd); - exit_event = CreateEvent (NULL, TRUE, FALSE, "openvpn_exit"); + exit_event = CreateEvent (NULL, TRUE, FALSE, _T("openvpn_exit")); if (exit_event == NULL) { #ifdef DEBUG @@ -663,7 +663,7 @@ int CheckVersion() else { /* CreateEvent failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_VERSION_CREATE_EVENT); + ShowLocalizedMsg(IDS_ERR_VERSION_CREATE_EVENT); return(false); } } @@ -676,8 +676,8 @@ int CheckVersion() _sntprintf_0(command_line, _T("openvpn --version")); /* construct bin path */ - strncpy(bin_path, o.exe_path, sizeof(bin_path)); - for (i=strlen(bin_path) - 1; i > 0; i--) + _tcsncpy(bin_path, o.exe_path, _tsizeof(bin_path)); + for (i=_tcslen(bin_path) - 1; i > 0; i--) if (bin_path[i] == '\\') break; bin_path[i] = '\0'; @@ -689,13 +689,13 @@ int CheckVersion() if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION)) { /* Init Sec. Desc. failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_INIT_SEC_DESC); + ShowLocalizedMsg(IDS_ERR_INIT_SEC_DESC); return(0); } if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE)) { /* Set Dacl failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_SET_SEC_DESC_ACL); + ShowLocalizedMsg(IDS_ERR_SET_SEC_DESC_ACL); return(0); } @@ -703,7 +703,7 @@ int CheckVersion() if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0)) { /* create pipe failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PIPE_IN_READ); + ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_IN_READ); return(0); } @@ -711,7 +711,7 @@ int CheckVersion() if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0)) { /* CreatePipe failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PIPE_OUTPUT); + ShowLocalizedMsg(IDS_ERR_CREATE_PIPE_OUTPUT); return(0); } @@ -722,7 +722,7 @@ int CheckVersion() DUPLICATE_SAME_ACCESS)) { /* DuplicateHandle failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_OUT_READ); + ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_OUT_READ); return(0); } @@ -733,7 +733,7 @@ int CheckVersion() DUPLICATE_SAME_ACCESS)) { /* DuplicateHandle failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DUP_HANDLE_IN_WRITE); + ShowLocalizedMsg(IDS_ERR_DUP_HANDLE_IN_WRITE); return(0); } @@ -742,7 +742,7 @@ int CheckVersion() if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp)) { /* CloseHandle failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CLOSE_HANDLE_TMP); + ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE_TMP); return(0); } @@ -768,7 +768,7 @@ int CheckVersion() &proc_info)) { /* CreateProcess failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_PROCESS, + ShowLocalizedMsg(IDS_ERR_CREATE_PROCESS, o.exe_path, command_line, bin_path); @@ -851,7 +851,7 @@ int CheckVersion() || !CloseHandle (hInputRead) || !CloseHandle(exit_event)) { /* CloseHandle failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CLOSE_HANDLE); + ShowLocalizedMsg(IDS_ERR_CLOSE_HANDLE); return(0); } @@ -899,14 +899,14 @@ void CheckAndSetTrayIcon() void ThreadOpenVPNStatus(int config) { - char conn_name[200]; + TCHAR conn_name[200]; HANDLE hThread; DWORD IDThread; MSG messages; /* Cut of extention from config filename. */ - strncpy(conn_name, o.cnn[config].config_file, sizeof(conn_name)); - conn_name[strlen(conn_name) - (strlen(o.ext_string)+1)]=0; + _tcsncpy(conn_name, o.cnn[config].config_file, _tsizeof(conn_name)); + conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0; if (o.cnn[config].restart) { @@ -941,7 +941,7 @@ void ThreadOpenVPNStatus(int config) if (hThread == NULL) { /* CreateThread failed */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_THREAD_READ_STDOUT); + ShowLocalizedMsg(IDS_ERR_THREAD_READ_STDOUT); ExitThread(0); } diff --git a/openvpn_config.c b/openvpn_config.c index 5166a13..07c3e3e 100644 --- a/openvpn_config.c +++ b/openvpn_config.c @@ -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"))) { /* 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); } _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) { /* too many configs */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); + ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); break; } @@ -221,7 +221,7 @@ BuildFileList() if (o.num_configs >= MAX_CONFIGS) { /* too many configs */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); + ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); FindClose (find_handle); return(true); } @@ -238,7 +238,7 @@ BuildFileList() else { /* Config filename already exists */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CONFIG_EXIST, find_obj.cFileName); + ShowLocalizedMsg(IDS_ERR_CONFIG_EXIST, find_obj.cFileName); } } diff --git a/openvpn_monitor_process.c b/openvpn_monitor_process.c index b0f25e8..625d358 100644 --- a/openvpn_monitor_process.c +++ b/openvpn_monitor_process.c @@ -92,7 +92,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char *line) else { /* error reading from pipe */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READ_STDOUT_PIPE); + ShowLocalizedMsg(IDS_ERR_READ_STDOUT_PIPE); return(-1); } } @@ -151,7 +151,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char *line) else { /* error reading from pipe */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READ_STDOUT_PIPE); + ShowLocalizedMsg(IDS_ERR_READ_STDOUT_PIPE); return(-1); } } @@ -192,7 +192,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char *line) */ void monitor_openvpnlog_while_connecting(int config, char *line) { - char msg[200]; + TCHAR msg[200]; unsigned int i; char *linepos; @@ -222,14 +222,14 @@ void monitor_openvpnlog_while_connecting(int config, char *line) /* Show Tray Balloon msg */ if (o.show_balloon[0] != '0') { - LoadLocalizedStringBuf(msg, sizeof(msg)/sizeof(*msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); - if (strlen(o.cnn[config].ip) > 0) + LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); + if (_tcslen(o.cnn[config].ip) > 0) { ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip)); } else { - ShowTrayBalloon(msg, " "); + ShowTrayBalloon(msg, _T("")); } } @@ -254,7 +254,7 @@ void monitor_openvpnlog_while_connecting(int config, char *line) { StopOpenVPN(config); /* Cert expired... */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CERT_EXPIRED); + ShowLocalizedMsg(IDS_ERR_CERT_EXPIRED); } /* Check for "certificate is not yet valid" message */ @@ -262,16 +262,29 @@ void monitor_openvpnlog_while_connecting(int config, char *line) { StopOpenVPN(config); /* 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 */ 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 */ - for (i=0; i < strlen(o.cnn[config].ip); i++) - if (o.cnn[config].ip[i] == '/' || o.cnn[config].ip[i] == ' ') break; - o.cnn[config].ip[i] = '\0'; + char ip_addr[40]; + + strncpy(ip_addr, linepos+54, sizeof(ip_addr)); /* Copy IP address */ + 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) { - char msg[200]; + TCHAR msg[200]; char *linepos; size_t i; @@ -316,14 +329,14 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line) /* Show Tray Balloon msg */ if (o.show_balloon[0] == '2') { - LoadLocalizedStringBuf(msg, sizeof(msg)/sizeof(*msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); - if (strlen(o.cnn[config].ip) > 0) + LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); + if (_tcslen(o.cnn[config].ip) > 0) { ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip)); } else { - ShowTrayBalloon(msg, " "); + ShowTrayBalloon(msg, _T("")); } } } @@ -345,7 +358,7 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line) { /* Cert expired */ StopOpenVPN(config); - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CERT_EXPIRED); + ShowLocalizedMsg(IDS_ERR_CERT_EXPIRED); } /* Check for "certificate is not yet valid" message */ @@ -353,16 +366,29 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line) { StopOpenVPN(config); /* 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 */ 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 */ - for (i=0; i < strlen(o.cnn[config].ip); i++) - if (o.cnn[config].ip[i] == '/' || o.cnn[config].ip[i] == ' ') break; - o.cnn[config].ip[i] = '\0'; + char ip_addr[40]; + + strncpy(ip_addr, linepos+54, sizeof(ip_addr)); /* Copy IP address */ + 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]; int ret; - char filemode[2] = "w\0"; + TCHAR filemode[] = _T("w"); FILE *fd; int LogLines = 0; int logpos; @@ -387,7 +413,7 @@ void WatchOpenVPNProcess(int config) /* set log file append/truncate filemode */ if (o.append_string[0] == '1') - filemode[0] = 'a'; + filemode[0] = _T('a'); /* Set Connect_Status = "Connecting" */ o.cnn[config].connect_status = CONNECTING; @@ -402,8 +428,8 @@ void WatchOpenVPNProcess(int config) o.cnn[config].failed_psw = 0; /* Open log file */ - if ((fd=fopen(o.cnn[config].log_path, filemode)) == NULL) - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_OPEN_LOG_WRITE, o.cnn[config].log_path); + if ((fd=_tfopen(o.cnn[config].log_path, filemode)) == NULL) + ShowLocalizedMsg(IDS_ERR_OPEN_LOG_WRITE, o.cnn[config].log_path); LogWindow = GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG); while(TRUE) @@ -428,14 +454,20 @@ void WatchOpenVPNProcess(int config) { logpos = SendMessage(LogWindow, EM_LINEINDEX, DEL_LOG_LINES, 0); SendMessage(LogWindow, EM_SETSEL, 0, logpos); - SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) ""); + SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) _T("")); LogLines -= DEL_LOG_LINES; } /* Write line to LogWindow */ strcat(line, "\r\n"); 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); +#endif if (o.cnn[config].connect_status == CONNECTING) /* Connecting state */ monitor_openvpnlog_while_connecting(config, line); @@ -489,7 +521,7 @@ void WatchOpenVPNProcess(int config) EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); SetForegroundWindow(o.cnn[config].hwndStatus); 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 */ SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); @@ -524,7 +556,7 @@ void WatchOpenVPNProcess(int config) /* Zero psw attempt counter */ 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" */ o.cnn[config].connect_status=DISCONNECTED; @@ -567,7 +599,7 @@ void WatchOpenVPNProcess(int config) /* Zero psw attempt counter */ 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" */ o.cnn[config].connect_status=DISCONNECTED; diff --git a/options.c b/options.c index b89b92e..4577e66 100644 --- a/options.c +++ b/options.c @@ -39,18 +39,18 @@ init_options (struct options *opt) CLEAR (*opt); } -int Createargcargv(struct options* options, char* command_line) +int Createargcargv(struct options *options, TCHAR *command_line) { - int argc; - char** argv; + int argc; + TCHAR **argv; - char* arg; - int myindex; + TCHAR* arg; + int myindex; // count the arguments - argc = 1; + argc = 0; arg = command_line; while (arg[0] != 0) { @@ -78,10 +78,10 @@ int Createargcargv(struct options* options, char* command_line) } // tokenize the arguments - argv = (char**)malloc(argc * sizeof(char*)); + argv = (TCHAR**) malloc(argc * sizeof(TCHAR*)); arg = command_line; - myindex = 1; + myindex = 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); free(argv); @@ -139,137 +133,137 @@ int Createargcargv(struct options* options, char* command_line) static int add_option (struct options *options, int i, - char *p[]) + TCHAR *p[]) { - if (streq (p[0], "help")) + if (streq (p[0], _T("help"))) { 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); exit(0); } - else if (streq (p[0], "connect") && p[1]) + else if (streq (p[0], _T("connect")) && p[1]) { ++i; static int auto_connect_nr=0; if (auto_connect_nr == MAX_CONFIGS) { /* Too many configs */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); + ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); exit(1); } options->auto_connect[auto_connect_nr] = p[1]; auto_connect_nr++; } - else if (streq (p[0], "exe_path") && p[1]) + else if (streq (p[0], _T("exe_path")) && p[1]) { ++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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - 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; - strncpy(options->disconnectscript_timeout_string, p[1], - sizeof(options->disconnectscript_timeout_string) - 1); + _tcsncpy(options->disconnectscript_timeout_string, p[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; - strncpy(options->preconnectscript_timeout_string, p[1], - sizeof(options->preconnectscript_timeout_string) - 1); + _tcsncpy(options->preconnectscript_timeout_string, p[1], + _tsizeof(options->preconnectscript_timeout_string) - 1); } else { /* Unrecognized option or missing parameter */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_BAD_OPTION, p[0]); + ShowLocalizedMsg(IDS_ERR_BAD_OPTION, p[0]); exit(1); } return i; @@ -278,20 +272,20 @@ add_option (struct options *options, void parse_argv (struct options* options, int argc, - char *argv[]) + TCHAR *argv[]) { int i, j; /* parse command line */ for (i = 1; i < argc; ++i) { - char *p[MAX_PARMS]; + TCHAR *p[MAX_PARMS]; CLEAR (p); p[0] = argv[i]; - if (strncmp(p[0], "--", 2)) + if (_tcsncmp(p[0], _T("--"), 2)) { /* Missing -- before option. */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_BAD_PARAMETER, p[0]); + ShowLocalizedMsg(IDS_ERR_BAD_PARAMETER, p[0]); exit(0); } else @@ -301,8 +295,8 @@ parse_argv (struct options* options, { if (i + j < argc) { - char *arg = argv[i + j]; - if (strncmp (arg, "--", 2)) + TCHAR *arg = argv[i + j]; + if (_tcsncmp (arg, _T("--"), 2)) p[j] = arg; else break; @@ -319,18 +313,18 @@ int ConfigFileOptionExist(int config, const char *option) { FILE *fp; char line[256]; - char configfile_path[MAX_PATH]; + TCHAR configfile_path[MAX_PATH]; - strncpy(configfile_path, o.cnn[config].config_dir, sizeof(configfile_path)); - if (!(configfile_path[strlen(configfile_path)-1] == '\\')) - strcat(configfile_path, "\\"); - strncat(configfile_path, o.cnn[config].config_file, - sizeof(configfile_path) - strlen(configfile_path) - 1); + _tcsncpy(configfile_path, o.cnn[config].config_dir, _tsizeof(configfile_path)); + if (configfile_path[_tcslen(configfile_path) - 1] != _T('\\')) + _tcscat(configfile_path, _T("\\")); + _tcsncat(configfile_path, o.cnn[config].config_file, + _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 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_CONFIG, configfile_path); + ShowLocalizedMsg(IDS_ERR_OPEN_CONFIG, configfile_path); return(0); } diff --git a/options.h b/options.h index 75faac2..1da3cf0 100644 --- a/options.h +++ b/options.h @@ -49,12 +49,12 @@ /* Connections parameters */ struct connections { - char config_file[MAX_PATH]; /* Name of the config file */ - char config_name[MAX_PATH]; /* Name of the connection */ - char config_dir[MAX_PATH]; /* Path to this configs dir */ - char log_path[MAX_PATH]; /* Path to Logfile */ - char ip[16]; /* Assigned IP address for this connection */ - char exit_event_name[50]; /* Exit Event name for this connection */ + TCHAR config_file[MAX_PATH]; /* Name of the config file */ + TCHAR config_name[MAX_PATH]; /* Name of the connection */ + TCHAR config_dir[MAX_PATH]; /* Path to this configs dir */ + TCHAR log_path[MAX_PATH]; /* Path to Logfile */ + TCHAR ip[16]; /* Assigned IP address for this connection */ + TCHAR exit_event_name[50]; /* Exit Event name for this connection */ int connect_status; /* 0=Not Connected 1=Connecting 2=Connected 3=Reconnecting 4=Disconnecting */ int auto_connect; /* true=AutoConnect at startup */ @@ -74,7 +74,7 @@ struct connections struct options { /* Array of configs to autostart */ - const char *auto_connect[MAX_CONFIGS]; + const TCHAR *auto_connect[MAX_CONFIGS]; /* Connection parameters */ struct connections cnn[MAX_CONFIGS]; /* Connection structure */ @@ -91,37 +91,37 @@ struct options HINSTANCE hInstance; /* Registry values */ - char exe_path[MAX_PATH]; - char config_dir[MAX_PATH]; - char ext_string[16]; - char log_dir[MAX_PATH]; - char priority_string[64]; - char append_string[2]; - char log_viewer[MAX_PATH]; - char editor[MAX_PATH]; - char allow_edit[2]; - char allow_service[2]; - char allow_password[2]; - char allow_proxy[2]; - char silent_connection[2]; - char service_only[2]; - char show_balloon[2]; - char show_script_window[2]; - char psw_attempts_string[2]; - char disconnect_on_suspend[2]; - char connectscript_timeout_string[4]; - char disconnectscript_timeout_string[4]; - char preconnectscript_timeout_string[4]; + TCHAR exe_path[MAX_PATH]; + TCHAR config_dir[MAX_PATH]; + TCHAR ext_string[16]; + TCHAR log_dir[MAX_PATH]; + TCHAR priority_string[64]; + TCHAR append_string[2]; + TCHAR log_viewer[MAX_PATH]; + TCHAR editor[MAX_PATH]; + TCHAR allow_edit[2]; + TCHAR allow_service[2]; + TCHAR allow_password[2]; + TCHAR allow_proxy[2]; + TCHAR silent_connection[2]; + TCHAR service_only[2]; + TCHAR show_balloon[2]; + TCHAR show_script_window[2]; + TCHAR psw_attempts_string[2]; + TCHAR disconnect_on_suspend[2]; + TCHAR connectscript_timeout_string[4]; + TCHAR disconnectscript_timeout_string[4]; + TCHAR preconnectscript_timeout_string[4]; /* Proxy Settings */ int proxy_source; /* 0=OpenVPN config, 1=IE, 2=Manual */ int proxy_type; /* 0=HTTP, 1=SOCKS */ int proxy_http_auth; /* 0=Auth Disabled, 1=Auth Enabled */ - char proxy_http_address[100]; /* HTTP Proxy Address */ - char proxy_http_port[6]; /* HTTP Proxy Port */ - char proxy_socks_address[100]; /* SOCKS Proxy Address */ - char proxy_socks_port[6]; /* SOCKS Proxy Address */ - char proxy_authfile[100]; /* Path to proxy auth file */ + TCHAR proxy_http_address[100]; /* HTTP Proxy Address */ + TCHAR proxy_http_port[6]; /* HTTP Proxy Port */ + TCHAR proxy_socks_address[100]; /* SOCKS Proxy Address */ + TCHAR proxy_socks_port[6]; /* SOCKS Proxy Address */ + TCHAR proxy_authfile[100]; /* Path to proxy auth file */ /* Debug file pointer */ #ifdef DEBUG @@ -129,8 +129,8 @@ struct options #endif }; -#define streq(x, y) (!strcmp((x), (y))) +#define streq(x, y) (!_tcscmp((x), (y))) void init_options (struct options *o); -int Createargcargv(struct options* options, char* command_line); -void parse_argv (struct options* options, int argc, char *argv[]); +int Createargcargv(struct options* options, TCHAR* command_line); +void parse_argv (struct options* options, int argc, TCHAR *argv[]); int ConfigFileOptionExist(int config, const char *option); diff --git a/passphrase.c b/passphrase.c index 2c99222..f2eb6f6 100644 --- a/passphrase.c +++ b/passphrase.c @@ -89,14 +89,14 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config) strlen(passphrase_ascii), &nCharsWritten, NULL)) { /* PassPhrase -> stdin failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PASSPHRASE2STDIN); + ShowLocalizedMsg(IDS_ERR_PASSPHRASE2STDIN); } } if (!WriteFile(o.cnn[config].hStdIn, "\r\n", 2, &nCharsWritten, NULL)) { /* CR -> stdin failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CR2STDIN); + ShowLocalizedMsg(IDS_ERR_CR2STDIN); } /* Remove Passphrase prompt from lastline buffer */ line[0]='\0'; @@ -124,7 +124,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config) strlen(passphrase_ascii), &nCharsWritten, NULL)) { /* PassPhrase -> stdin failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PASSPHRASE2STDIN); + ShowLocalizedMsg(IDS_ERR_PASSPHRASE2STDIN); } } else @@ -133,7 +133,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config) 1, &nCharsWritten, NULL)) { /* CR -> stdin failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CR2STDIN); + ShowLocalizedMsg(IDS_ERR_CR2STDIN); } } /* 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, strlen(user_auth.username), &nCharsWritten, NULL)) { - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_AUTH_USERNAME2STDIN); + ShowLocalizedMsg(IDS_ERR_AUTH_USERNAME2STDIN); } } else @@ -174,7 +174,7 @@ void CheckAuthUsernamePrompt (char *line, int config) if (!WriteFile(o.cnn[config].hStdIn, "\n", 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, strlen(user_auth.password), &nCharsWritten, NULL)) { - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_AUTH_PASSWORD2STDIN); + ShowLocalizedMsg(IDS_ERR_AUTH_PASSWORD2STDIN); } } else @@ -191,7 +191,7 @@ void CheckAuthUsernamePrompt (char *line, int config) if (!WriteFile(o.cnn[config].hStdIn, "\n", 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) { - static char empty_string[100]; + static TCHAR empty_string[100]; 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) { static struct user_auth *user_auth; - static char empty_string[100]; + static TCHAR empty_string[100]; WCHAR username_unicode[50]; WCHAR password_unicode[50]; @@ -316,7 +316,7 @@ void ShowChangePassphraseDialog(int config) if (hThread == NULL) { /* error creating thread */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_CREATE_PASS_THREAD); + ShowLocalizedMsg(IDS_ERR_CREATE_PASS_THREAD); return; } @@ -326,16 +326,16 @@ void ChangePassphraseThread(int config) { HWND hwndChangePSW; MSG messages; - char conn_name[100]; - char keyfilename[MAX_PATH]; + TCHAR conn_name[100]; + TCHAR keyfilename[MAX_PATH]; int keyfile_format=0; /* Cut of extention from config filename. */ - strncpy(conn_name, o.cnn[config].config_file, sizeof(conn_name)); - conn_name[strlen(conn_name) - (strlen(o.ext_string)+1)]=0; + _tcsncpy(conn_name, o.cnn[config].config_file, _tsizeof(conn_name)); + conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0; /* Get Key filename from config file */ - if (!GetKeyFilename(config, keyfilename, sizeof(keyfilename), &keyfile_format)) + if (!GetKeyFilename(config, keyfilename, _tsizeof(keyfilename), &keyfile_format)) { ExitThread(1); } @@ -368,7 +368,7 @@ void ChangePassphraseThread(int config) BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam) { HICON hIcon; - char keyfile[MAX_PATH]; + TCHAR keyfile[MAX_PATH]; int keyfile_format; BOOL Translated; @@ -391,25 +391,25 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, if (!ConfirmNewPassword (hwndDlg)) { /* passwords don't match */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PWD_DONT_MATCH); + ShowLocalizedMsg(IDS_ERR_PWD_DONT_MATCH); break; } /* Check minimum length of password */ 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; } /* Check if the new password is empty. */ 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; } - 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); if (keyfile_format == KEYFILE_FORMAT_PEM) { @@ -426,7 +426,7 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, else { /* Unknown key format */ - ShowLocalizedMsg (PACKAGE_NAME, IDS_ERR_UNKNOWN_KEYFILE_FORMAT); + ShowLocalizedMsg(IDS_ERR_UNKNOWN_KEYFILE_FORMAT); } DestroyWindow(hwndDlg); @@ -456,13 +456,13 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, /* Return TRUE if new passwords match */ int ConfirmNewPassword(HWND hwndDlg) { - char newpsw[50]; - char newpsw2[50]; + TCHAR newpsw[50]; + TCHAR newpsw2[50]; - GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, sizeof(newpsw) - 1); - GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW2, newpsw2, sizeof(newpsw2) - 1); + GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, _tsizeof(newpsw) - 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; else return false; @@ -471,14 +471,14 @@ int ConfirmNewPassword(HWND hwndDlg) /* Return lengh of the new password */ 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_READING_QUOTED_PARM = 1; @@ -487,7 +487,7 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename unsigned int j=0; int state = STATE_INITIAL; int backslash=0; - char temp_filename[MAX_PATH]; + TCHAR temp_filename[MAX_PATH]; while(line[i] != '\0') { @@ -584,7 +584,7 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename if (j >= (keyfilenamesize - 1)) { /* key filename to long */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_KEY_FILENAME_TO_LONG); + ShowLocalizedMsg(IDS_ERR_KEY_FILENAME_TO_LONG); return(0); } i++; @@ -594,12 +594,12 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename /* Prepend filename with configdir path if needed */ if ((keyfilename[0] != '\\') && (keyfilename[0] != '/') && (keyfilename[1] != ':')) { - strncpy(temp_filename, o.cnn[config].config_dir, sizeof(temp_filename)); - if (temp_filename[strlen(temp_filename) - 1] != '\\') - strcat(temp_filename, "\\"); - strncat(temp_filename, keyfilename, - sizeof(temp_filename) - strlen(temp_filename) - 1); - strncpy(keyfilename, temp_filename, keyfilenamesize - 1); + _tcsncpy(temp_filename, o.cnn[config].config_dir, _tsizeof(temp_filename)); + if (temp_filename[_tcslen(temp_filename) - 1] != '\\') + _tcscat(temp_filename, _T("\\")); + _tcsncat(temp_filename, keyfilename, + _tsizeof(temp_filename) - _tcslen(temp_filename) - 1); + _tcsncpy(keyfilename, temp_filename, keyfilenamesize - 1); } return(1); @@ -613,7 +613,7 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename */ int ChangePasswordPEM(HWND hwndDlg) { - char keyfile[MAX_PATH]; + TCHAR keyfile[MAX_PATH]; char oldpsw[50]; char newpsw[50]; WCHAR oldpsw_unicode[50]; @@ -623,7 +623,7 @@ int ChangePasswordPEM(HWND hwndDlg) EVP_PKEY *privkey; /* 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_NEW, newpsw_unicode, sizeof(newpsw_unicode)/2 - 1); @@ -631,17 +631,17 @@ int ChangePasswordPEM(HWND hwndDlg) ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw)); 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); } privkey = EVP_PKEY_new(); /* Open old keyfile for reading */ - if (! (fp = fopen (keyfile, "r"))) + if (! (fp = _tfopen (keyfile, _T("r")))) { /* 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); } @@ -649,7 +649,7 @@ int ChangePasswordPEM(HWND hwndDlg) if (! (privkey = PEM_read_PrivateKey (fp, NULL, NULL, oldpsw))) { /* wrong password */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OLD_PWD_INCORRECT); + ShowLocalizedMsg(IDS_ERR_OLD_PWD_INCORRECT); fclose(fp); return(-1); } @@ -657,10 +657,10 @@ int ChangePasswordPEM(HWND hwndDlg) fclose(fp); /* Open keyfile for writing */ - if (! (fp = fopen (keyfile, "w"))) + if (! (fp = _tfopen (keyfile, _T("w")))) { /* 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); return(0); } @@ -674,7 +674,7 @@ int ChangePasswordPEM(HWND hwndDlg) 0, 0, NULL))) { /* error writing new key */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_WRITE_NEW_KEY, keyfile); + ShowLocalizedMsg(IDS_ERR_WRITE_NEW_KEY, keyfile); EVP_PKEY_free(privkey); fclose(fp); return(0); @@ -688,7 +688,7 @@ int ChangePasswordPEM(HWND hwndDlg) (UCHAR*) newpsw, (int) strlen(newpsw), 0, NULL))) { /* 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); fclose(fp); return(0); @@ -699,7 +699,7 @@ int ChangePasswordPEM(HWND hwndDlg) fclose(fp); /* signal success to user */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_NFO_PWD_CHANGED); + ShowLocalizedMsg(IDS_NFO_PWD_CHANGED); return(1); } @@ -711,7 +711,7 @@ int ChangePasswordPEM(HWND hwndDlg) */ int ChangePasswordPKCS12(HWND hwndDlg) { - char keyfile[MAX_PATH]; + TCHAR keyfile[MAX_PATH]; char oldpsw[50]; char newpsw[50]; WCHAR oldpsw_unicode[50]; @@ -725,7 +725,7 @@ int ChangePasswordPKCS12(HWND hwndDlg) char *alias; /* 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_NEW, newpsw_unicode, sizeof(newpsw_unicode)/2 - 1); @@ -733,15 +733,15 @@ int ChangePasswordPKCS12(HWND hwndDlg) ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw)); 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); } /* Load the PKCS #12 file */ - if (!(fp = fopen(keyfile, "rb"))) + if (!(fp = _tfopen(keyfile, _T("rb")))) { /* error opening file */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_PRIVATE_KEY_FILE, keyfile); + ShowLocalizedMsg(IDS_ERR_OPEN_PRIVATE_KEY_FILE, keyfile); return(0); } p12 = d2i_PKCS12_fp(fp, NULL); @@ -749,7 +749,7 @@ int ChangePasswordPKCS12(HWND hwndDlg) if (!p12) { /* error reading PKCS #12 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READ_PKCS12, keyfile); + ShowLocalizedMsg(IDS_ERR_READ_PKCS12, keyfile); return(0); } @@ -757,7 +757,7 @@ int ChangePasswordPKCS12(HWND hwndDlg) if (!PKCS12_parse(p12, oldpsw, &privkey, &cert, &ca)) { /* old password incorrect */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OLD_PWD_INCORRECT); + ShowLocalizedMsg(IDS_ERR_OLD_PWD_INCORRECT); PKCS12_free(p12); return(-1); } @@ -773,7 +773,7 @@ int ChangePasswordPKCS12(HWND hwndDlg) if (!p12) { /* create failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_PKCS12); + ShowLocalizedMsg(IDS_ERR_CREATE_PKCS12); return(0); } @@ -783,9 +783,9 @@ int ChangePasswordPKCS12(HWND hwndDlg) sk_X509_pop_free(ca, X509_free); /* 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); return(0); } @@ -796,7 +796,7 @@ int ChangePasswordPKCS12(HWND hwndDlg) PKCS12_free(p12); fclose(fp); /* signal success to user */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_NFO_PWD_CHANGED); + ShowLocalizedMsg(IDS_NFO_PWD_CHANGED); return(1); } @@ -812,24 +812,24 @@ int LineBeginsWith(char *line, const char *keyword, const unsigned int len) 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; char line[256]; int found_key=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)); - if (!(configfile_path[strlen(configfile_path)-1] == '\\')) - strcat(configfile_path, "\\"); - strncat(configfile_path, o.cnn[config].config_file, - sizeof(configfile_path) - strlen(configfile_path) - 1); + _tcsncpy(configfile_path, o.cnn[config].config_dir, _tsizeof(configfile_path)); + if (!(configfile_path[_tcslen(configfile_path)-1] == '\\')) + _tcscat(configfile_path, _T("\\")); + _tcsncat(configfile_path, o.cnn[config].config_file, + _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 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_CONFIG, configfile_path); + ShowLocalizedMsg(IDS_ERR_OPEN_CONFIG, configfile_path); return(0); } @@ -840,13 +840,13 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize, if (found_key) { /* only one key option */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONLY_ONE_KEY_OPTION); + ShowLocalizedMsg(IDS_ERR_ONLY_ONE_KEY_OPTION); return(0); } if (found_pkcs12) { /* key XOR pkcs12 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONLY_KEY_OR_PKCS12); + ShowLocalizedMsg(IDS_ERR_ONLY_KEY_OR_PKCS12); return(0); } found_key=1; @@ -859,13 +859,13 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize, if (found_pkcs12) { /* only one pkcs12 option */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONLY_ONE_PKCS12_OPTION); + ShowLocalizedMsg(IDS_ERR_ONLY_ONE_PKCS12_OPTION); return(0); } if (found_key) { /* only key XOR pkcs12 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_ONLY_KEY_OR_PKCS12); + ShowLocalizedMsg(IDS_ERR_ONLY_KEY_OR_PKCS12); return(0); } found_pkcs12=1; @@ -878,7 +878,7 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize, if ((!found_key) && (!found_pkcs12)) { /* must have key or pkcs12 option */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_HAVE_KEY_OR_PKCS12); + ShowLocalizedMsg(IDS_ERR_HAVE_KEY_OR_PKCS12); return(0); } diff --git a/passphrase.h b/passphrase.h index 1d311b7..8470970 100644 --- a/passphrase.h +++ b/passphrase.h @@ -39,5 +39,5 @@ int ConfirmNewPassword(HWND hwndDlg); int NewPasswordLengh(HWND hwndDlg); int ChangePasswordPEM(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); diff --git a/proxy.c b/proxy.c index 79857cf..028f892 100644 --- a/proxy.c +++ b/proxy.c @@ -154,7 +154,7 @@ int CheckProxySettings(HWND hwndDlg) if (_tcslen(text) == 0) { /* 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); } @@ -162,15 +162,15 @@ int CheckProxySettings(HWND hwndDlg) if (_tcslen(text) == 0) { /* 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); } - long port = strtol(text, NULL, 10); + long port = _tcstol(text, NULL, 10); if ((port < 1) || (port > 65535)) { /* 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); } } @@ -268,7 +268,7 @@ void SaveProxySettings(HWND hwndDlg) &dwDispos) != ERROR_SUCCESS) { /* 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; } @@ -297,7 +297,7 @@ void GetProxyRegistrySettings() if (!GetTempPath(_tsizeof(temp_path) - 1, temp_path)) { /* Error getting TempPath - using C:\ */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GET_TEMP_PATH); + ShowLocalizedMsg(IDS_ERR_GET_TEMP_PATH); _tcscpy(temp_path, _T("C:\\")); } _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")))) { /* 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)); } _fputts(username, fp); - _fputts("\n", fp); + _fputts(_T("\n"), fp); _fputts(password, fp); - _fputts("\n", fp); + _fputts(_T("\n"), fp); fclose(fp); EndDialog(hwndDlg, LOWORD(wParam)); 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)) { - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GET_MSIE_PROXY); + ShowLocalizedMsg(IDS_ERR_GET_MSIE_PROXY); return FALSE; } diff --git a/registry.c b/registry.c index 9ffe0cb..1f00136 100644 --- a/registry.c +++ b/registry.c @@ -44,7 +44,7 @@ GetRegistryKeys() if (!GetWindowsDirectory(windows_dir, _tsizeof(windows_dir))) { /* can't get windows dir */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GET_WINDOWS_DIR); + ShowLocalizedMsg(IDS_ERR_GET_WINDOWS_DIR); return(false); } @@ -53,13 +53,13 @@ GetRegistryKeys() != ERROR_SUCCESS) { /* registry key not found */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_REGISTRY); + ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY); return(false); } if (!GetRegistryValue(regkey, _T(""), openvpn_path, _tsizeof(openvpn_path))) { /* error reading registry value */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READING_REGISTRY); + ShowLocalizedMsg(IDS_ERR_READING_REGISTRY); return(false); } if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\')) @@ -114,41 +114,41 @@ GetRegistryKeys() if (!GetRegKey(_T("passphrase_attempts"), o.psw_attempts_string, _T("3"), _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)) { /* 0 <= passphrase_attempts <= 9 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PASSPHRASE_ATTEMPTS); + ShowLocalizedMsg(IDS_ERR_PASSPHRASE_ATTEMPTS); return(false); } if (!GetRegKey(_T("connectscript_timeout"), o.connectscript_timeout_string, _T("15"), _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)) { /* 0 <= connectscript_timeout <= 99 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CONN_SCRIPT_TIMEOUT); + ShowLocalizedMsg(IDS_ERR_CONN_SCRIPT_TIMEOUT); return(false); } if (!GetRegKey(_T("disconnectscript_timeout"), o.disconnectscript_timeout_string, _T("10"), _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)) { /* 0 < disconnectscript_timeout <= 99 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_DISCONN_SCRIPT_TIMEOUT); + ShowLocalizedMsg(IDS_ERR_DISCONN_SCRIPT_TIMEOUT); return(false); } if (!GetRegKey(_T("preconnectscript_timeout"), o.preconnectscript_timeout_string, _T("10"), _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)) { /* 0 < disconnectscript_timeout <= 99 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_PRECONN_SCRIPT_TIMEOUT); + ShowLocalizedMsg(IDS_ERR_PRECONN_SCRIPT_TIMEOUT); return(false); } @@ -164,10 +164,8 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD HKEY openvpn_key_write; DWORD dwDispos; TCHAR expanded_string[MAX_PATH]; - DWORD max_len; - - /* Save maximum string length */ - max_len=len; + DWORD size = len * sizeof(*data); + DWORD max_len = len - 1; /* If option is already set via cmd-line, return */ if (data[0] != 0) @@ -197,14 +195,14 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD &dwDispos) != ERROR_SUCCESS) { /* error creating registry key */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CREATE_REG_KEY); + ShowLocalizedMsg(IDS_ERR_CREATE_REG_KEY); return(false); } } /* 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) { /* 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) { /* can't open registry for writing */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_WRITE_REG); + ShowLocalizedMsg(IDS_ERR_OPEN_WRITE_REG); return(false); } - if(RegSetValueEx(openvpn_key_write, - name, - 0, - REG_SZ, - (const PBYTE) default_data, - _tcslen(default_data)+1)) + if(!SetRegistryValue(openvpn_key_write, name, default_data)) { /* cant read / set reg-key */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_READ_SET_KEY, name); return(false); } _tcsncpy(data, default_data, max_len); @@ -250,14 +242,14 @@ LONG GetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data, DWORD len) DWORD type; DWORD data_len; - data_len = len; + data_len = len * sizeof(*data); /* get a registry string */ status = RegQueryValueEx(regkey, name, NULL, &type, (byte *) data, &data_len); if (status != ERROR_SUCCESS || type != REG_SZ) 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); } -int SetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data) +int SetRegistryValue(HKEY regkey, const TCHAR *name, const TCHAR *data) { /* 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 */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name); + ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name); return(0); } @@ -291,6 +284,6 @@ SetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD data) if (status == ERROR_SUCCESS) return 1; - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name); + ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name); return 0; } diff --git a/registry.h b/registry.h index 6ed6793..136ae88 100644 --- a/registry.h +++ b/registry.h @@ -26,7 +26,7 @@ int GetRegistryKeys(); 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 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); #endif diff --git a/scripts.c b/scripts.c index bdeba0d..9aad6ec 100644 --- a/scripts.c +++ b/scripts.c @@ -21,6 +21,7 @@ #include #include +#include #include "config.h" #include "main.h" @@ -38,15 +39,15 @@ void RunConnectScript(int config, int run_as_service) PROCESS_INFORMATION proc_info; SECURITY_ATTRIBUTES sa; SECURITY_DESCRIPTOR sd; - char command_line[256]; - char batch_file[100]; + TCHAR command_line[256]; + TCHAR batch_file[100]; DWORD ExitCode; int i, TimeOut; /* Cut of extention from config filename and add "_up.bat". */ - strncpy(batch_file, o.cnn[config].config_file, sizeof(batch_file)); - batch_file[strlen(batch_file) - (strlen(o.ext_string)+1)]=0; - strncat(batch_file, "_up.bat", sizeof(batch_file) - strlen(batch_file) - 1); + _tcsncpy(batch_file, o.cnn[config].config_file, _tsizeof(batch_file)); + batch_file[_tcslen(batch_file) - (_tcslen(o.ext_string)+1)]=0; + _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); @@ -91,7 +92,7 @@ void RunConnectScript(int config, int run_as_service) &proc_info)) { /* Running Script failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_RUN_CONN_SCRIPT, command_line); + ShowLocalizedMsg(IDS_ERR_RUN_CONN_SCRIPT, command_line); return; } @@ -108,7 +109,7 @@ void RunConnectScript(int config, int run_as_service) if (!GetExitCodeProcess(proc_info.hProcess, &ExitCode)) { /* failed to get ExitCode */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_GET_EXIT_CODE, command_line); + ShowLocalizedMsg(IDS_ERR_GET_EXIT_CODE, command_line); return; } @@ -117,7 +118,7 @@ void RunConnectScript(int config, int run_as_service) if (ExitCode != 0) { /* ConnectScript failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_CONN_SCRIPT_FAILED, ExitCode); + ShowLocalizedMsg(IDS_ERR_CONN_SCRIPT_FAILED, ExitCode); return; } return; @@ -127,7 +128,7 @@ void RunConnectScript(int config, int run_as_service) } /* 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; SECURITY_ATTRIBUTES sa; SECURITY_DESCRIPTOR sd; - char command_line[256]; - char batch_file[100]; + TCHAR command_line[256]; + TCHAR batch_file[100]; DWORD ExitCode; int i, TimeOut; /* Append "_down.bat" to config name. */ - strncpy(batch_file, o.cnn[config].config_name, sizeof(batch_file)); - strncat(batch_file, "_down.bat", sizeof(batch_file) - strlen(batch_file) - 1); + _tcsncpy(batch_file, o.cnn[config].config_name, _tsizeof(batch_file)); + _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); @@ -219,14 +220,14 @@ void RunPreconnectScript(int config) PROCESS_INFORMATION proc_info; SECURITY_ATTRIBUTES sa; SECURITY_DESCRIPTOR sd; - char command_line[256]; - char batch_file[100]; + TCHAR command_line[256]; + TCHAR batch_file[100]; DWORD ExitCode; int i, TimeOut; /* Append "_pre.bat" to config name. */ - strncpy(batch_file, o.cnn[config].config_name, sizeof(batch_file)); - strncat(batch_file, "_pre.bat", sizeof(batch_file) - strlen(batch_file) - 1); + _tcsncpy(batch_file, o.cnn[config].config_name, _tsizeof(batch_file)); + _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); diff --git a/service.c b/service.c index 925cd1d..e75a339 100644 --- a/service.c +++ b/service.c @@ -58,18 +58,18 @@ int MyStartService() if (NULL == schSCManager) { /* open SC manager failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_SCMGR); + ShowLocalizedMsg(IDS_ERR_OPEN_SCMGR); goto failed; } schService = OpenService( schSCManager, // SCM database - "OpenVPNService", // service name + _T("OpenVPNService"), // service name SERVICE_START | SERVICE_QUERY_STATUS); if (schService == NULL) { /* can't open VPN service */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_VPN_SERVICE); + ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE); goto failed; } @@ -83,7 +83,7 @@ int MyStartService() NULL) ) // no arguments { /* can't start */ - ShowLocalizedMsg(NULL, IDS_ERR_START_SERVICE); + ShowLocalizedMsg(IDS_ERR_START_SERVICE); goto failed; } else @@ -97,7 +97,7 @@ int MyStartService() &ssStatus) ) // address of status information structure { /* query failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_QUERY_SERVICE); + ShowLocalizedMsg(IDS_ERR_QUERY_SERVICE); goto failed; } @@ -148,7 +148,7 @@ int MyStartService() if (ssStatus.dwCurrentState != SERVICE_RUNNING) { /* service hasn't started */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_SERVICE_START_FAILED); + ShowLocalizedMsg(IDS_ERR_SERVICE_START_FAILED); goto failed; } @@ -162,7 +162,7 @@ int MyStartService() CheckAndSetTrayIcon(); /* Show "OpenVPN Service Started" Tray Balloon msg */ - ShowTrayBalloon(LoadLocalizedString(IDS_NFO_SERVICE_STARTED), " "); + ShowTrayBalloon(LoadLocalizedString(IDS_NFO_SERVICE_STARTED), _T("")); return(true); @@ -191,18 +191,18 @@ int MyStopService() if (NULL == schSCManager) { /* can't open SCManager */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_SCMGR, (int) GetLastError()); + ShowLocalizedMsg(IDS_ERR_OPEN_SCMGR, (int) GetLastError()); return(false); } schService = OpenService( schSCManager, // SCM database - "OpenVPNService", // service name + _T("OpenVPNService"), // service name SERVICE_STOP); if (schService == NULL) { /* can't open vpn service */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_VPN_SERVICE); + ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE); return(false); } @@ -216,7 +216,7 @@ int MyStopService() &ssStatus) ) // address of status info { /* stop failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_STOP_SERVICE); + ShowLocalizedMsg(IDS_ERR_STOP_SERVICE); return(false); } @@ -260,12 +260,12 @@ int CheckServiceStatus() schService = OpenService( schSCManager, // SCM database - "OpenVPNService", // service name + _T("OpenVPNService"), // service name SERVICE_QUERY_STATUS); if (schService == NULL) { /* open vpn service failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_OPEN_VPN_SERVICE); + ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE); o.service_running = SERVICE_NOACCESS; SetServiceMenuStatus(); return(false); @@ -276,7 +276,7 @@ int CheckServiceStatus() &ssStatus) ) // address of status information structure { /* query failed */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_QUERY_SERVICE); + ShowLocalizedMsg(IDS_ERR_QUERY_SERVICE); return(false); } diff --git a/tray.c b/tray.c index 95d3d51..33e525a 100644 --- a/tray.c +++ b/tray.c @@ -89,7 +89,7 @@ void OnNotifyTray(LPARAM lParam) else if (o.service_running == SERVICE_CONNECTED) { /* 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(); } @@ -359,7 +359,7 @@ void SetTrayIcon(int connected) if (first_conn) _tcsncat(msg, msg_connected, _tsizeof(msg) - _tcslen(msg) - 1); 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); first_conn=0; config=i; @@ -376,7 +376,7 @@ void SetTrayIcon(int connected) if (first_conn) _tcsncat(msg, msg_connecting, _tsizeof(msg) - _tcslen(msg) - 1); 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); first_conn=0; } diff --git a/viewlog.c b/viewlog.c index e703c9b..3aa3f53 100644 --- a/viewlog.c +++ b/viewlog.c @@ -34,7 +34,7 @@ extern struct options o; void ViewLog(int config) { - char filename[200]; + TCHAR filename[200]; STARTUPINFO start_info; PROCESS_INFORMATION proc_info; @@ -68,7 +68,7 @@ void ViewLog(int config) &proc_info)) { /* 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) { - char filename[200]; + TCHAR filename[200]; STARTUPINFO start_info; PROCESS_INFORMATION proc_info; @@ -110,7 +110,7 @@ void EditConfig(int config) &proc_info)) { /* could not start editor */ - ShowLocalizedMsg(PACKAGE_NAME, IDS_ERR_START_CONF_EDITOR, o.editor); + ShowLocalizedMsg(IDS_ERR_START_CONF_EDITOR, o.editor); } }