mirror of https://github.com/OpenVPN/openvpn-gui
use CRT's _countof instead of proprietary _tsizeof
parent
c9eb68c77f
commit
f420d7dcbb
|
@ -149,7 +149,7 @@ __LoadLocalizedString(const UINT stringId, va_list args)
|
||||||
{
|
{
|
||||||
static TCHAR msg[512];
|
static TCHAR msg[512];
|
||||||
msg[0] = 0;
|
msg[0] = 0;
|
||||||
LoadStringLang(stringId, GetGUILanguage(), msg, _tsizeof(msg), args);
|
LoadStringLang(stringId, GetGUILanguage(), msg, _countof(msg), args);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ LangListEntry(const UINT stringId, const LANGID langId, ...)
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, langId);
|
va_start(args, langId);
|
||||||
LoadStringLang(stringId, langId, str, _tsizeof(str), args);
|
LoadStringLang(stringId, langId, str, _countof(str), args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
2
main.c
2
main.c
|
@ -507,7 +507,7 @@ void PrintDebugMsg(TCHAR *msg)
|
||||||
|
|
||||||
log_time = time(NULL);
|
log_time = time(NULL);
|
||||||
time_struct = localtime(&log_time);
|
time_struct = localtime(&log_time);
|
||||||
_sntprintf(date, _tsizeof(date), _T("%d-%.2d-%.2d %.2d:%.2d:%.2d"),
|
_sntprintf(date, _countof(date), _T("%d-%.2d-%.2d %.2d:%.2d:%.2d"),
|
||||||
time_struct->tm_year + 1900,
|
time_struct->tm_year + 1900,
|
||||||
time_struct->tm_mon + 1,
|
time_struct->tm_mon + 1,
|
||||||
time_struct->tm_mday,
|
time_struct->tm_mday,
|
||||||
|
|
6
main.h
6
main.h
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
/* Define this to enable DEBUG build */
|
/* Define this to enable DEBUG build */
|
||||||
|
@ -61,16 +62,13 @@ struct security_attributes
|
||||||
SECURITY_DESCRIPTOR sd;
|
SECURITY_DESCRIPTOR sd;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Return the number of elements in a TCHAR array */
|
|
||||||
#define _tsizeof(x) (sizeof(x) / sizeof(*x))
|
|
||||||
|
|
||||||
/* clear an object */
|
/* clear an object */
|
||||||
#define CLEAR(x) memset(&(x), 0, sizeof(x))
|
#define CLEAR(x) memset(&(x), 0, sizeof(x))
|
||||||
|
|
||||||
/* _sntprintf with guaranteed \0 termination */
|
/* _sntprintf with guaranteed \0 termination */
|
||||||
#define _sntprintf_0(buf, ...) \
|
#define _sntprintf_0(buf, ...) \
|
||||||
do { \
|
do { \
|
||||||
__sntprintf_0(buf, _tsizeof(buf), __VA_ARGS__); \
|
__sntprintf_0(buf, _countof(buf), __VA_ARGS__); \
|
||||||
} while(0);
|
} while(0);
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
|
20
openvpn.c
20
openvpn.c
|
@ -155,14 +155,14 @@ OnStateChange(connection_t *c, char *data)
|
||||||
*pos = '\0';
|
*pos = '\0';
|
||||||
|
|
||||||
/* Convert the IP address to Unicode */
|
/* Convert the IP address to Unicode */
|
||||||
MultiByteToWideChar(CP_ACP, 0, local_ip, -1, c->ip, _tsizeof(c->ip));
|
MultiByteToWideChar(CP_ACP, 0, local_ip, -1, c->ip, _countof(c->ip));
|
||||||
|
|
||||||
/* Show connection tray balloon */
|
/* Show connection tray balloon */
|
||||||
if ((c->state == connecting && o.show_balloon[0] != '0')
|
if ((c->state == connecting && o.show_balloon[0] != '0')
|
||||||
|| (c->state == reconnecting && o.show_balloon[0] == '2'))
|
|| (c->state == reconnecting && o.show_balloon[0] == '2'))
|
||||||
{
|
{
|
||||||
TCHAR msg[256];
|
TCHAR msg[256];
|
||||||
LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, c->config_name);
|
LoadLocalizedStringBuf(msg, _countof(msg), IDS_NFO_NOW_CONNECTED, c->config_name);
|
||||||
ShowTrayBalloon(msg, (_tcslen(c->ip) ? LoadLocalizedString(IDS_NFO_ASSIGN_IP, c->ip) : _T("")));
|
ShowTrayBalloon(msg, (_tcslen(c->ip) ? LoadLocalizedString(IDS_NFO_ASSIGN_IP, c->ip) : _T("")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ UserAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
switch (LOWORD(wParam))
|
switch (LOWORD(wParam))
|
||||||
{
|
{
|
||||||
case IDOK:
|
case IDOK:
|
||||||
username_len = GetDlgItemText(hwndDlg, ID_EDT_AUTH_USER, buf, _tsizeof(buf));
|
username_len = GetDlgItemText(hwndDlg, ID_EDT_AUTH_USER, buf, _countof(buf));
|
||||||
if (username_len == 0)
|
if (username_len == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
length = WideCharToMultiByte(CP_UTF8, 0, buf, -1, cmd + 17, sizeof(cmd) - 17, NULL, NULL);
|
length = WideCharToMultiByte(CP_UTF8, 0, buf, -1, cmd + 17, sizeof(cmd) - 17, NULL, NULL);
|
||||||
|
@ -230,14 +230,14 @@ UserAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
ManagementCommand(c, cmd, NULL, regular);
|
ManagementCommand(c, cmd, NULL, regular);
|
||||||
|
|
||||||
memcpy(cmd, "password", 8);
|
memcpy(cmd, "password", 8);
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_AUTH_PASS, buf, _tsizeof(buf));
|
GetDlgItemText(hwndDlg, ID_EDT_AUTH_PASS, buf, _countof(buf));
|
||||||
length = WideCharToMultiByte(CP_UTF8, 0, buf, -1, cmd + 17, sizeof(cmd) - 17, NULL, NULL);
|
length = WideCharToMultiByte(CP_UTF8, 0, buf, -1, cmd + 17, sizeof(cmd) - 17, NULL, NULL);
|
||||||
memcpy(cmd + length + 16, "\"\0", 2);
|
memcpy(cmd + length + 16, "\"\0", 2);
|
||||||
ManagementCommand(c, cmd, NULL, regular);
|
ManagementCommand(c, cmd, NULL, regular);
|
||||||
|
|
||||||
/* Clear buffers */
|
/* Clear buffers */
|
||||||
memset(buf, 'x', sizeof(buf));
|
memset(buf, 'x', sizeof(buf));
|
||||||
buf[_tsizeof(buf) - 1] = _T('\0');
|
buf[_countof(buf) - 1] = _T('\0');
|
||||||
SetDlgItemText(hwndDlg, ID_EDT_AUTH_USER, buf);
|
SetDlgItemText(hwndDlg, ID_EDT_AUTH_USER, buf);
|
||||||
SetDlgItemText(hwndDlg, ID_EDT_AUTH_PASS, buf);
|
SetDlgItemText(hwndDlg, ID_EDT_AUTH_PASS, buf);
|
||||||
|
|
||||||
|
@ -287,14 +287,14 @@ PrivKeyPassDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
switch (LOWORD(wParam))
|
switch (LOWORD(wParam))
|
||||||
{
|
{
|
||||||
case IDOK:
|
case IDOK:
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PASSPHRASE, buf, _tsizeof(buf));
|
GetDlgItemText(hwndDlg, ID_EDT_PASSPHRASE, buf, _countof(buf));
|
||||||
length = WideCharToMultiByte(CP_UTF8, 0, buf, -1, cmd + 24, sizeof(cmd) - 24, NULL, NULL);
|
length = WideCharToMultiByte(CP_UTF8, 0, buf, -1, cmd + 24, sizeof(cmd) - 24, NULL, NULL);
|
||||||
memcpy(cmd + length + 23, "\"\0", 2);
|
memcpy(cmd + length + 23, "\"\0", 2);
|
||||||
ManagementCommand(c, cmd, NULL, regular);
|
ManagementCommand(c, cmd, NULL, regular);
|
||||||
|
|
||||||
/* Clear buffer */
|
/* Clear buffer */
|
||||||
memset(buf, 'x', sizeof(buf));
|
memset(buf, 'x', sizeof(buf));
|
||||||
buf[_tsizeof(buf) - 1] = _T('\0');
|
buf[_countof(buf) - 1] = _T('\0');
|
||||||
SetDlgItemText(hwndDlg, ID_EDT_PASSPHRASE, buf);
|
SetDlgItemText(hwndDlg, ID_EDT_PASSPHRASE, buf);
|
||||||
|
|
||||||
EndDialog(hwndDlg, LOWORD(wParam));
|
EndDialog(hwndDlg, LOWORD(wParam));
|
||||||
|
@ -555,7 +555,7 @@ ThreadOpenVPNStatus(void *p)
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
/* Cut of extention from config filename. */
|
/* Cut of extention from config filename. */
|
||||||
_tcsncpy(conn_name, c->config_file, _tsizeof(conn_name));
|
_tcsncpy(conn_name, c->config_file, _countof(conn_name));
|
||||||
conn_name[_tcslen(conn_name) - _tcslen(o.ext_string) - 1] = _T('\0');
|
conn_name[_tcslen(conn_name) - _tcslen(o.ext_string) - 1] = _T('\0');
|
||||||
|
|
||||||
c->state = connecting;
|
c->state = connecting;
|
||||||
|
@ -686,7 +686,7 @@ StartOpenVPN(connection_t *c)
|
||||||
GetRandomPassword(c->manage.password, sizeof(c->manage.password) - 1);
|
GetRandomPassword(c->manage.password, sizeof(c->manage.password) - 1);
|
||||||
|
|
||||||
/* Construct proxy string to append to command line */
|
/* Construct proxy string to append to command line */
|
||||||
ConstructProxyCmdLine(proxy_string, _tsizeof(proxy_string));
|
ConstructProxyCmdLine(proxy_string, _countof(proxy_string));
|
||||||
|
|
||||||
/* Construct command line */
|
/* Construct command line */
|
||||||
_sntprintf_0(cmdline, _T("openvpn "
|
_sntprintf_0(cmdline, _T("openvpn "
|
||||||
|
@ -945,7 +945,7 @@ CheckVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Construct the process' working directory */
|
/* Construct the process' working directory */
|
||||||
_tcsncpy(pwd, o.exe_path, _tsizeof(pwd));
|
_tcsncpy(pwd, o.exe_path, _countof(pwd));
|
||||||
p = _tcsrchr(pwd, _T('\\'));
|
p = _tcsrchr(pwd, _T('\\'));
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
*p = _T('\0');
|
*p = _T('\0');
|
||||||
|
|
|
@ -81,9 +81,9 @@ AddConfigFileToList(int config, TCHAR *filename, TCHAR *config_dir)
|
||||||
connection_t *conn = &o.conn[config];
|
connection_t *conn = &o.conn[config];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
_tcsncpy(conn->config_file, filename, _tsizeof(conn->config_file) - 1);
|
_tcsncpy(conn->config_file, filename, _countof(conn->config_file) - 1);
|
||||||
_tcsncpy(conn->config_dir, config_dir, _tsizeof(conn->config_dir) - 1);
|
_tcsncpy(conn->config_dir, config_dir, _countof(conn->config_dir) - 1);
|
||||||
_tcsncpy(conn->config_name, conn->config_file, _tsizeof(conn->config_name) - 1);
|
_tcsncpy(conn->config_name, conn->config_file, _countof(conn->config_name) - 1);
|
||||||
conn->config_name[_tcslen(conn->config_name) - _tcslen(o.ext_string) - 1] = _T('\0');
|
conn->config_name[_tcslen(conn->config_name) - _tcslen(o.ext_string) - 1] = _T('\0');
|
||||||
_sntprintf_0(conn->log_path, _T("%s\\%s.log"), o.log_dir, conn->config_name);
|
_sntprintf_0(conn->log_path, _T("%s\\%s.log"), o.log_dir, conn->config_name);
|
||||||
conn->manage.sk = INVALID_SOCKET;
|
conn->manage.sk = INVALID_SOCKET;
|
||||||
|
@ -194,10 +194,10 @@ ConfigFileOptionExist(int config, const char *option)
|
||||||
char line[256];
|
char line[256];
|
||||||
TCHAR path[MAX_PATH];
|
TCHAR path[MAX_PATH];
|
||||||
|
|
||||||
_tcsncpy(path, o.conn[config].config_dir, _tsizeof(path));
|
_tcsncpy(path, o.conn[config].config_dir, _countof(path));
|
||||||
if (path[_tcslen(path) - 1] != _T('\\'))
|
if (path[_tcslen(path) - 1] != _T('\\'))
|
||||||
_tcscat(path, _T("\\"));
|
_tcscat(path, _T("\\"));
|
||||||
_tcsncat(path, o.conn[config].config_file, _tsizeof(path) - _tcslen(path) - 1);
|
_tcsncat(path, o.conn[config].config_file, _countof(path) - _tcslen(path) - 1);
|
||||||
|
|
||||||
fp = _tfopen(path, _T("r"));
|
fp = _tfopen(path, _T("r"));
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
|
|
42
options.c
42
options.c
|
@ -45,7 +45,7 @@ add_option(options_t *options, int i, TCHAR **p)
|
||||||
if (streq(p[0], _T("help")))
|
if (streq(p[0], _T("help")))
|
||||||
{
|
{
|
||||||
TCHAR caption[200];
|
TCHAR caption[200];
|
||||||
LoadLocalizedStringBuf(caption, _tsizeof(caption), IDS_NFO_USAGECAPTION);
|
LoadLocalizedStringBuf(caption, _countof(caption), IDS_NFO_USAGECAPTION);
|
||||||
MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), caption, MB_OK);
|
MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), caption, MB_OK);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -64,102 +64,102 @@ add_option(options_t *options, int i, TCHAR **p)
|
||||||
else if (streq(p[0], _T("exe_path")) && p[1])
|
else if (streq(p[0], _T("exe_path")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->exe_path, p[1], _tsizeof(options->exe_path) - 1);
|
_tcsncpy(options->exe_path, p[1], _countof(options->exe_path) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("config_dir")) && p[1])
|
else if (streq(p[0], _T("config_dir")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->config_dir, p[1], _tsizeof(options->config_dir) - 1);
|
_tcsncpy(options->config_dir, p[1], _countof(options->config_dir) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("ext_string")) && p[1])
|
else if (streq(p[0], _T("ext_string")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->ext_string, p[1], _tsizeof(options->ext_string) - 1);
|
_tcsncpy(options->ext_string, p[1], _countof(options->ext_string) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("log_dir")) && p[1])
|
else if (streq(p[0], _T("log_dir")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->log_dir, p[1], _tsizeof(options->log_dir) - 1);
|
_tcsncpy(options->log_dir, p[1], _countof(options->log_dir) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("priority_string")) && p[1])
|
else if (streq(p[0], _T("priority_string")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->priority_string, p[1], _tsizeof(options->priority_string) - 1);
|
_tcsncpy(options->priority_string, p[1], _countof(options->priority_string) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("append_string")) && p[1])
|
else if (streq(p[0], _T("append_string")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->append_string, p[1], _tsizeof(options->append_string) - 1);
|
_tcsncpy(options->append_string, p[1], _countof(options->append_string) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("log_viewer")) && p[1])
|
else if (streq(p[0], _T("log_viewer")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->log_viewer, p[1], _tsizeof(options->log_viewer) - 1);
|
_tcsncpy(options->log_viewer, p[1], _countof(options->log_viewer) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("editor")) && p[1])
|
else if (streq(p[0], _T("editor")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->editor, p[1], _tsizeof(options->editor) - 1);
|
_tcsncpy(options->editor, p[1], _countof(options->editor) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("allow_edit")) && p[1])
|
else if (streq(p[0], _T("allow_edit")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->allow_edit, p[1], _tsizeof(options->allow_edit) - 1);
|
_tcsncpy(options->allow_edit, p[1], _countof(options->allow_edit) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("allow_service")) && p[1])
|
else if (streq(p[0], _T("allow_service")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->allow_service, p[1], _tsizeof(options->allow_service) - 1);
|
_tcsncpy(options->allow_service, p[1], _countof(options->allow_service) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("allow_password")) && p[1])
|
else if (streq(p[0], _T("allow_password")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->allow_password, p[1], _tsizeof(options->allow_password) - 1);
|
_tcsncpy(options->allow_password, p[1], _countof(options->allow_password) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("allow_proxy")) && p[1])
|
else if (streq(p[0], _T("allow_proxy")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->allow_proxy, p[1], _tsizeof(options->allow_proxy) - 1);
|
_tcsncpy(options->allow_proxy, p[1], _countof(options->allow_proxy) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("show_balloon")) && p[1])
|
else if (streq(p[0], _T("show_balloon")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->show_balloon, p[1], _tsizeof(options->show_balloon) - 1);
|
_tcsncpy(options->show_balloon, p[1], _countof(options->show_balloon) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("service_only")) && p[1])
|
else if (streq(p[0], _T("service_only")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->service_only, p[1], _tsizeof(options->service_only) - 1);
|
_tcsncpy(options->service_only, p[1], _countof(options->service_only) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("show_script_window")) && p[1])
|
else if (streq(p[0], _T("show_script_window")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->show_script_window, p[1], _tsizeof(options->show_script_window) - 1);
|
_tcsncpy(options->show_script_window, p[1], _countof(options->show_script_window) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("silent_connection")) && p[1])
|
else if (streq(p[0], _T("silent_connection")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->silent_connection, p[1], _tsizeof(options->silent_connection) - 1);
|
_tcsncpy(options->silent_connection, p[1], _countof(options->silent_connection) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("passphrase_attempts")) && p[1])
|
else if (streq(p[0], _T("passphrase_attempts")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->psw_attempts_string, p[1], _tsizeof(options->psw_attempts_string) - 1);
|
_tcsncpy(options->psw_attempts_string, p[1], _countof(options->psw_attempts_string) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("connectscript_timeout")) && p[1])
|
else if (streq(p[0], _T("connectscript_timeout")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->connectscript_timeout_string, p[1], _tsizeof(options->connectscript_timeout_string) - 1);
|
_tcsncpy(options->connectscript_timeout_string, p[1], _countof(options->connectscript_timeout_string) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("disconnectscript_timeout")) && p[1])
|
else if (streq(p[0], _T("disconnectscript_timeout")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->disconnectscript_timeout_string, p[1], _tsizeof(options->disconnectscript_timeout_string) - 1);
|
_tcsncpy(options->disconnectscript_timeout_string, p[1], _countof(options->disconnectscript_timeout_string) - 1);
|
||||||
}
|
}
|
||||||
else if (streq(p[0], _T("preconnectscript_timeout")) && p[1])
|
else if (streq(p[0], _T("preconnectscript_timeout")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
_tcsncpy(options->preconnectscript_timeout_string, p[1], _tsizeof(options->preconnectscript_timeout_string) - 1);
|
_tcsncpy(options->preconnectscript_timeout_string, p[1], _countof(options->preconnectscript_timeout_string) - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
26
passphrase.c
26
passphrase.c
|
@ -86,10 +86,10 @@ ConfirmNewPassword(HWND hwndDlg)
|
||||||
TCHAR newpsw[50];
|
TCHAR newpsw[50];
|
||||||
TCHAR newpsw2[50];
|
TCHAR newpsw2[50];
|
||||||
|
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, _tsizeof(newpsw) - 1);
|
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, _countof(newpsw) - 1);
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW2, newpsw2, _tsizeof(newpsw2) - 1);
|
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW2, newpsw2, _countof(newpsw2) - 1);
|
||||||
|
|
||||||
if (_tcsncmp(newpsw, newpsw2, _tsizeof(newpsw)) == 0)
|
if (_tcsncmp(newpsw, newpsw2, _countof(newpsw)) == 0)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -104,7 +104,7 @@ NewPasswordLengh(HWND hwndDlg)
|
||||||
{
|
{
|
||||||
TCHAR newpsw[50];
|
TCHAR newpsw[50];
|
||||||
|
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, _tsizeof(newpsw) - 1);
|
GetDlgItemText(hwndDlg, ID_EDT_PASS_NEW, newpsw, _countof(newpsw) - 1);
|
||||||
|
|
||||||
return (_tcslen(newpsw));
|
return (_tcslen(newpsw));
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ 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, _tsizeof(keyfile) - 1);
|
GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, _countof(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);
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ 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, _tsizeof(keyfile) - 1);
|
GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, _countof(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);
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ ChangePassphraseDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, _tsizeof(keyfile) - 1);
|
GetDlgItemText(hwndDlg, ID_TXT_KEYFILE, keyfile, _countof(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)
|
||||||
{
|
{
|
||||||
|
@ -558,11 +558,11 @@ ParseKeyFilenameLine(connection_t *c, TCHAR *keyfilename, size_t keyfilenamesize
|
||||||
/* 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] != ':'))
|
||||||
{
|
{
|
||||||
_tcsncpy(temp_filename, c->config_dir, _tsizeof(temp_filename));
|
_tcsncpy(temp_filename, c->config_dir, _countof(temp_filename));
|
||||||
if (temp_filename[_tcslen(temp_filename) - 1] != '\\')
|
if (temp_filename[_tcslen(temp_filename) - 1] != '\\')
|
||||||
_tcscat(temp_filename, _T("\\"));
|
_tcscat(temp_filename, _T("\\"));
|
||||||
_tcsncat(temp_filename, keyfilename,
|
_tcsncat(temp_filename, keyfilename,
|
||||||
_tsizeof(temp_filename) - _tcslen(temp_filename) - 1);
|
_countof(temp_filename) - _tcslen(temp_filename) - 1);
|
||||||
_tcsncpy(keyfilename, temp_filename, keyfilenamesize - 1);
|
_tcsncpy(keyfilename, temp_filename, keyfilenamesize - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,11 +579,11 @@ GetKeyFilename(connection_t *c, TCHAR *keyfilename, size_t keyfilenamesize, int
|
||||||
int found_pkcs12=0;
|
int found_pkcs12=0;
|
||||||
TCHAR configfile_path[MAX_PATH];
|
TCHAR configfile_path[MAX_PATH];
|
||||||
|
|
||||||
_tcsncpy(configfile_path, c->config_dir, _tsizeof(configfile_path));
|
_tcsncpy(configfile_path, c->config_dir, _countof(configfile_path));
|
||||||
if (!(configfile_path[_tcslen(configfile_path)-1] == '\\'))
|
if (!(configfile_path[_tcslen(configfile_path)-1] == '\\'))
|
||||||
_tcscat(configfile_path, _T("\\"));
|
_tcscat(configfile_path, _T("\\"));
|
||||||
_tcsncat(configfile_path, c->config_file,
|
_tcsncat(configfile_path, c->config_file,
|
||||||
_tsizeof(configfile_path) - _tcslen(configfile_path) - 1);
|
_countof(configfile_path) - _tcslen(configfile_path) - 1);
|
||||||
|
|
||||||
if (!(fp=_tfopen(configfile_path, _T("r"))))
|
if (!(fp=_tfopen(configfile_path, _T("r"))))
|
||||||
{
|
{
|
||||||
|
@ -656,11 +656,11 @@ ChangePassphraseThread(LPVOID data)
|
||||||
connection_t *c = data;
|
connection_t *c = data;
|
||||||
|
|
||||||
/* Cut of extention from config filename. */
|
/* Cut of extention from config filename. */
|
||||||
_tcsncpy(conn_name, c->config_file, _tsizeof(conn_name));
|
_tcsncpy(conn_name, c->config_file, _countof(conn_name));
|
||||||
conn_name[_tcslen(conn_name) - (_tcslen(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(c, keyfilename, _tsizeof(keyfilename), &keyfile_format))
|
if (!GetKeyFilename(c, keyfilename, _countof(keyfilename), &keyfile_format))
|
||||||
{
|
{
|
||||||
ExitThread(1);
|
ExitThread(1);
|
||||||
}
|
}
|
||||||
|
|
30
proxy.c
30
proxy.c
|
@ -153,7 +153,7 @@ CheckProxySettings(HWND hwndDlg)
|
||||||
TCHAR text[100];
|
TCHAR text[100];
|
||||||
BOOL http = (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_HTTP) == BST_CHECKED);
|
BOOL http = (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_HTTP) == BST_CHECKED);
|
||||||
|
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, text, _tsizeof(text));
|
GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, text, _countof(text));
|
||||||
if (_tcslen(text) == 0)
|
if (_tcslen(text) == 0)
|
||||||
{
|
{
|
||||||
/* proxy address not specified */
|
/* proxy address not specified */
|
||||||
|
@ -161,7 +161,7 @@ CheckProxySettings(HWND hwndDlg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, text, _tsizeof(text));
|
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, text, _countof(text));
|
||||||
if (_tcslen(text) == 0)
|
if (_tcslen(text) == 0)
|
||||||
{
|
{
|
||||||
/* proxy port not specified */
|
/* proxy port not specified */
|
||||||
|
@ -247,9 +247,9 @@ SaveProxySettings(HWND hwndDlg)
|
||||||
proxy_type_string[0] = _T('0');
|
proxy_type_string[0] = _T('0');
|
||||||
|
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address,
|
GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address,
|
||||||
_tsizeof(o.proxy_http_address));
|
_countof(o.proxy_http_address));
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, o.proxy_http_port,
|
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, o.proxy_http_port,
|
||||||
_tsizeof(o.proxy_http_port));
|
_countof(o.proxy_http_port));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -257,9 +257,9 @@ SaveProxySettings(HWND hwndDlg)
|
||||||
proxy_type_string[0] = _T('1');
|
proxy_type_string[0] = _T('1');
|
||||||
|
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_socks_address,
|
GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_socks_address,
|
||||||
_tsizeof(o.proxy_socks_address));
|
_countof(o.proxy_socks_address));
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, o.proxy_socks_port,
|
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, o.proxy_socks_port,
|
||||||
_tsizeof(o.proxy_socks_port));
|
_countof(o.proxy_socks_port));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open Registry for writing */
|
/* Open Registry for writing */
|
||||||
|
@ -297,12 +297,12 @@ GetProxyRegistrySettings()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* get registry settings */
|
/* get registry settings */
|
||||||
GetRegistryValue(regkey, _T("proxy_http_address"), o.proxy_http_address, _tsizeof(o.proxy_http_address));
|
GetRegistryValue(regkey, _T("proxy_http_address"), o.proxy_http_address, _countof(o.proxy_http_address));
|
||||||
GetRegistryValue(regkey, _T("proxy_http_port"), o.proxy_http_port, _tsizeof(o.proxy_http_port));
|
GetRegistryValue(regkey, _T("proxy_http_port"), o.proxy_http_port, _countof(o.proxy_http_port));
|
||||||
GetRegistryValue(regkey, _T("proxy_socks_address"), o.proxy_socks_address, _tsizeof(o.proxy_socks_address));
|
GetRegistryValue(regkey, _T("proxy_socks_address"), o.proxy_socks_address, _countof(o.proxy_socks_address));
|
||||||
GetRegistryValue(regkey, _T("proxy_socks_port"), o.proxy_socks_port, _tsizeof(o.proxy_socks_port));
|
GetRegistryValue(regkey, _T("proxy_socks_port"), o.proxy_socks_port, _countof(o.proxy_socks_port));
|
||||||
GetRegistryValue(regkey, _T("proxy_source"), proxy_source_string, _tsizeof(proxy_source_string));
|
GetRegistryValue(regkey, _T("proxy_source"), proxy_source_string, _countof(proxy_source_string));
|
||||||
GetRegistryValue(regkey, _T("proxy_type"), proxy_type_string, _tsizeof(proxy_type_string));
|
GetRegistryValue(regkey, _T("proxy_type"), proxy_type_string, _countof(proxy_type_string));
|
||||||
|
|
||||||
if (proxy_source_string[0] == _T('0'))
|
if (proxy_source_string[0] == _T('0'))
|
||||||
{
|
{
|
||||||
|
@ -345,7 +345,7 @@ ProxyAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
case IDOK:
|
case IDOK:
|
||||||
c = (connection_t *) GetProp(hwndDlg, cfgProp);
|
c = (connection_t *) GetProp(hwndDlg, cfgProp);
|
||||||
username_len = GetDlgItemText(hwndDlg, ID_EDT_PROXY_USER, buf, _tsizeof(buf));
|
username_len = GetDlgItemText(hwndDlg, ID_EDT_PROXY_USER, buf, _countof(buf));
|
||||||
if (username_len == 0)
|
if (username_len == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
length = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, buf, -1, cmd + 23, sizeof(cmd) - 23, "_", NULL);
|
length = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, buf, -1, cmd + 23, sizeof(cmd) - 23, "_", NULL);
|
||||||
|
@ -353,14 +353,14 @@ ProxyAuthDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
ManagementCommand(c, cmd, NULL, regular);
|
ManagementCommand(c, cmd, NULL, regular);
|
||||||
|
|
||||||
memcpy(cmd, "password", 8);
|
memcpy(cmd, "password", 8);
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PASS, buf, _tsizeof(buf));
|
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PASS, buf, _countof(buf));
|
||||||
length = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, buf, -1, cmd + 23, sizeof(cmd) - 23, "_", NULL);
|
length = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, buf, -1, cmd + 23, sizeof(cmd) - 23, "_", NULL);
|
||||||
memcpy(cmd + length + 22, "\"\0", 2);
|
memcpy(cmd + length + 22, "\"\0", 2);
|
||||||
ManagementCommand(c, cmd, NULL, regular);
|
ManagementCommand(c, cmd, NULL, regular);
|
||||||
|
|
||||||
/* Clear buffers */
|
/* Clear buffers */
|
||||||
memset(buf, 'x', sizeof(buf));
|
memset(buf, 'x', sizeof(buf));
|
||||||
buf[_tsizeof(buf) - 1] = _T('\0');
|
buf[_countof(buf) - 1] = _T('\0');
|
||||||
SetDlgItemText(hwndDlg, ID_EDT_PROXY_USER, buf);
|
SetDlgItemText(hwndDlg, ID_EDT_PROXY_USER, buf);
|
||||||
SetDlgItemText(hwndDlg, ID_EDT_PROXY_PASS, buf);
|
SetDlgItemText(hwndDlg, ID_EDT_PROXY_PASS, buf);
|
||||||
|
|
||||||
|
|
50
registry.c
50
registry.c
|
@ -44,7 +44,7 @@ GetRegistryKeys()
|
||||||
TCHAR openvpn_path[MAX_PATH];
|
TCHAR openvpn_path[MAX_PATH];
|
||||||
HKEY regkey;
|
HKEY regkey;
|
||||||
|
|
||||||
if (!GetWindowsDirectory(windows_dir, _tsizeof(windows_dir))) {
|
if (!GetWindowsDirectory(windows_dir, _countof(windows_dir))) {
|
||||||
/* can't get windows dir */
|
/* can't get windows dir */
|
||||||
ShowLocalizedMsg(IDS_ERR_GET_WINDOWS_DIR);
|
ShowLocalizedMsg(IDS_ERR_GET_WINDOWS_DIR);
|
||||||
return(false);
|
return(false);
|
||||||
|
@ -58,7 +58,7 @@ GetRegistryKeys()
|
||||||
ShowLocalizedMsg(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, _countof(openvpn_path)))
|
||||||
{
|
{
|
||||||
/* error reading registry value */
|
/* error reading registry value */
|
||||||
ShowLocalizedMsg(IDS_ERR_READING_REGISTRY);
|
ShowLocalizedMsg(IDS_ERR_READING_REGISTRY);
|
||||||
|
@ -70,52 +70,52 @@ GetRegistryKeys()
|
||||||
|
|
||||||
_sntprintf_0(temp_path, _T("%sconfig"), openvpn_path);
|
_sntprintf_0(temp_path, _T("%sconfig"), openvpn_path);
|
||||||
if (!GetRegKey(_T("config_dir"), o.config_dir,
|
if (!GetRegKey(_T("config_dir"), o.config_dir,
|
||||||
temp_path, _tsizeof(o.config_dir))) return(false);
|
temp_path, _countof(o.config_dir))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("config_ext"), o.ext_string, _T("ovpn"), _tsizeof(o.ext_string))) return(false);
|
if (!GetRegKey(_T("config_ext"), o.ext_string, _T("ovpn"), _countof(o.ext_string))) return(false);
|
||||||
|
|
||||||
_sntprintf_0(temp_path, _T("%sbin\\openvpn.exe"), openvpn_path);
|
_sntprintf_0(temp_path, _T("%sbin\\openvpn.exe"), openvpn_path);
|
||||||
if (!GetRegKey(_T("exe_path"), o.exe_path,
|
if (!GetRegKey(_T("exe_path"), o.exe_path,
|
||||||
temp_path, _tsizeof(o.exe_path))) return(false);
|
temp_path, _countof(o.exe_path))) return(false);
|
||||||
|
|
||||||
_sntprintf_0(temp_path, _T("%slog"), openvpn_path);
|
_sntprintf_0(temp_path, _T("%slog"), openvpn_path);
|
||||||
if (!GetRegKey(_T("log_dir"), o.log_dir,
|
if (!GetRegKey(_T("log_dir"), o.log_dir,
|
||||||
temp_path, _tsizeof(o.log_dir))) return(false);
|
temp_path, _countof(o.log_dir))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("log_append"), o.append_string, _T("0"), _tsizeof(o.append_string))) return(false);
|
if (!GetRegKey(_T("log_append"), o.append_string, _T("0"), _countof(o.append_string))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("priority"), o.priority_string,
|
if (!GetRegKey(_T("priority"), o.priority_string,
|
||||||
_T("NORMAL_PRIORITY_CLASS"), _tsizeof(o.priority_string))) return(false);
|
_T("NORMAL_PRIORITY_CLASS"), _countof(o.priority_string))) return(false);
|
||||||
|
|
||||||
_sntprintf_0(temp_path, _T("%s\\notepad.exe"), windows_dir);
|
_sntprintf_0(temp_path, _T("%s\\notepad.exe"), windows_dir);
|
||||||
if (!GetRegKey(_T("log_viewer"), o.log_viewer,
|
if (!GetRegKey(_T("log_viewer"), o.log_viewer,
|
||||||
temp_path, _tsizeof(o.log_viewer))) return(false);
|
temp_path, _countof(o.log_viewer))) return(false);
|
||||||
|
|
||||||
_sntprintf_0(temp_path, _T("%s\\notepad.exe"), windows_dir);
|
_sntprintf_0(temp_path, _T("%s\\notepad.exe"), windows_dir);
|
||||||
if (!GetRegKey(_T("editor"), o.editor,
|
if (!GetRegKey(_T("editor"), o.editor,
|
||||||
temp_path, _tsizeof(o.editor))) return(false);
|
temp_path, _countof(o.editor))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("allow_edit"), o.allow_edit, _T("1"), _tsizeof(o.allow_edit))) return(false);
|
if (!GetRegKey(_T("allow_edit"), o.allow_edit, _T("1"), _countof(o.allow_edit))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("allow_service"), o.allow_service, _T("0"), _tsizeof(o.allow_service))) return(false);
|
if (!GetRegKey(_T("allow_service"), o.allow_service, _T("0"), _countof(o.allow_service))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("allow_password"), o.allow_password, _T("1"), _tsizeof(o.allow_password))) return(false);
|
if (!GetRegKey(_T("allow_password"), o.allow_password, _T("1"), _countof(o.allow_password))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("allow_proxy"), o.allow_proxy, _T("1"), _tsizeof(o.allow_proxy))) return(false);
|
if (!GetRegKey(_T("allow_proxy"), o.allow_proxy, _T("1"), _countof(o.allow_proxy))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("service_only"), o.service_only, _T("0"), _tsizeof(o.service_only))) return(false);
|
if (!GetRegKey(_T("service_only"), o.service_only, _T("0"), _countof(o.service_only))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("show_balloon"), o.show_balloon, _T("1"), _tsizeof(o.show_balloon))) return(false);
|
if (!GetRegKey(_T("show_balloon"), o.show_balloon, _T("1"), _countof(o.show_balloon))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("silent_connection"), o.silent_connection, _T("0"), _tsizeof(o.silent_connection))) return(false);
|
if (!GetRegKey(_T("silent_connection"), o.silent_connection, _T("0"), _countof(o.silent_connection))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("show_script_window"), o.show_script_window, _T("1"), _tsizeof(o.show_script_window))) return(false);
|
if (!GetRegKey(_T("show_script_window"), o.show_script_window, _T("1"), _countof(o.show_script_window))) return(false);
|
||||||
|
|
||||||
if (!GetRegKey(_T("disconnect_on_suspend"), o.disconnect_on_suspend, _T("1"),
|
if (!GetRegKey(_T("disconnect_on_suspend"), o.disconnect_on_suspend, _T("1"),
|
||||||
_tsizeof(o.disconnect_on_suspend))) return(false);
|
_countof(o.disconnect_on_suspend))) return(false);
|
||||||
|
|
||||||
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);
|
_countof(o.psw_attempts_string))) return(false);
|
||||||
o.psw_attempts = _ttoi(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))
|
||||||
{
|
{
|
||||||
|
@ -125,7 +125,7 @@ GetRegistryKeys()
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
_countof(o.connectscript_timeout_string))) return(false);
|
||||||
o.connectscript_timeout = _ttoi(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))
|
||||||
{
|
{
|
||||||
|
@ -135,7 +135,7 @@ GetRegistryKeys()
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
_countof(o.disconnectscript_timeout_string))) return(false);
|
||||||
o.disconnectscript_timeout = _ttoi(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))
|
||||||
{
|
{
|
||||||
|
@ -145,7 +145,7 @@ GetRegistryKeys()
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
_countof(o.preconnectscript_timeout_string))) return(false);
|
||||||
o.preconnectscript_timeout = _ttoi(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))
|
||||||
{
|
{
|
||||||
|
@ -173,7 +173,7 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
|
||||||
if (data[0] != 0)
|
if (data[0] != 0)
|
||||||
{
|
{
|
||||||
// Expand environment variables inside the string.
|
// Expand environment variables inside the string.
|
||||||
ExpandEnvironmentStrings(data, expanded_string, _tsizeof(expanded_string));
|
ExpandEnvironmentStrings(data, expanded_string, _countof(expanded_string));
|
||||||
_tcsncpy(data, expanded_string, max_len);
|
_tcsncpy(data, expanded_string, max_len);
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
|
||||||
RegCloseKey(openvpn_key);
|
RegCloseKey(openvpn_key);
|
||||||
|
|
||||||
// Expand environment variables inside the string.
|
// Expand environment variables inside the string.
|
||||||
ExpandEnvironmentStrings(data, expanded_string, _tsizeof(expanded_string));
|
ExpandEnvironmentStrings(data, expanded_string, _countof(expanded_string));
|
||||||
_tcsncpy(data, expanded_string, max_len);
|
_tcsncpy(data, expanded_string, max_len);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
|
|
30
tray.c
30
tray.c
|
@ -249,7 +249,7 @@ ShowTrayIcon()
|
||||||
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
||||||
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
||||||
ni.hIcon = LoadLocalizedIcon(ID_ICO_DISCONNECTED);
|
ni.hIcon = LoadLocalizedIcon(ID_ICO_DISCONNECTED);
|
||||||
_tcsncpy(ni.szTip, LoadLocalizedString(IDS_TIP_DEFAULT), _tsizeof(ni.szTip));
|
_tcsncpy(ni.szTip, LoadLocalizedString(IDS_TIP_DEFAULT), _countof(ni.szTip));
|
||||||
|
|
||||||
Shell_NotifyIcon(NIM_ADD, &ni);
|
Shell_NotifyIcon(NIM_ADD, &ni);
|
||||||
}
|
}
|
||||||
|
@ -265,16 +265,16 @@ SetTrayIcon(conn_state_t state)
|
||||||
BOOL first_conn;
|
BOOL first_conn;
|
||||||
UINT icon_id;
|
UINT icon_id;
|
||||||
|
|
||||||
_tcsncpy(msg, LoadLocalizedString(IDS_TIP_DEFAULT), _tsizeof(ni.szTip));
|
_tcsncpy(msg, LoadLocalizedString(IDS_TIP_DEFAULT), _countof(ni.szTip));
|
||||||
_tcsncpy(msg_connected, LoadLocalizedString(IDS_TIP_CONNECTED), _tsizeof(msg_connected));
|
_tcsncpy(msg_connected, LoadLocalizedString(IDS_TIP_CONNECTED), _countof(msg_connected));
|
||||||
_tcsncpy(msg_connecting, LoadLocalizedString(IDS_TIP_CONNECTING), _tsizeof(msg_connecting));
|
_tcsncpy(msg_connecting, LoadLocalizedString(IDS_TIP_CONNECTING), _countof(msg_connecting));
|
||||||
|
|
||||||
first_conn = TRUE;
|
first_conn = TRUE;
|
||||||
for (i = 0; i < o.num_configs; i++) {
|
for (i = 0; i < o.num_configs; i++) {
|
||||||
if (o.conn[i].state == connected) {
|
if (o.conn[i].state == connected) {
|
||||||
/* Append connection name to Icon Tip Msg */
|
/* Append connection name to Icon Tip Msg */
|
||||||
_tcsncat(msg, (first_conn ? msg_connected : _T(", ")), _tsizeof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, (first_conn ? msg_connected : _T(", ")), _countof(msg) - _tcslen(msg) - 1);
|
||||||
_tcsncat(msg, o.conn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, o.conn[i].config_name, _countof(msg) - _tcslen(msg) - 1);
|
||||||
first_conn = FALSE;
|
first_conn = FALSE;
|
||||||
config = i;
|
config = i;
|
||||||
}
|
}
|
||||||
|
@ -284,23 +284,23 @@ SetTrayIcon(conn_state_t state)
|
||||||
for (i = 0; i < o.num_configs; i++) {
|
for (i = 0; i < o.num_configs; i++) {
|
||||||
if (o.conn[i].state == connecting || o.conn[i].state == reconnecting) {
|
if (o.conn[i].state == connecting || o.conn[i].state == reconnecting) {
|
||||||
/* Append connection name to Icon Tip Msg */
|
/* Append connection name to Icon Tip Msg */
|
||||||
_tcsncat(msg, (first_conn ? msg_connecting : _T(", ")), _tsizeof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, (first_conn ? msg_connecting : _T(", ")), _countof(msg) - _tcslen(msg) - 1);
|
||||||
_tcsncat(msg, o.conn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, o.conn[i].config_name, _countof(msg) - _tcslen(msg) - 1);
|
||||||
first_conn = FALSE;
|
first_conn = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CountConnState(connected) == 1) {
|
if (CountConnState(connected) == 1) {
|
||||||
/* Append "Connected since and assigned IP" to message */
|
/* Append "Connected since and assigned IP" to message */
|
||||||
_tcsftime(connected_since, _tsizeof(connected_since), _T("%b %d, %H:%M"),
|
_tcsftime(connected_since, _countof(connected_since), _T("%b %d, %H:%M"),
|
||||||
localtime(&o.conn[config].connected_since));
|
localtime(&o.conn[config].connected_since));
|
||||||
|
|
||||||
_tcsncat(msg, LoadLocalizedString(IDS_TIP_CONNECTED_SINCE), _tsizeof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, LoadLocalizedString(IDS_TIP_CONNECTED_SINCE), _countof(msg) - _tcslen(msg) - 1);
|
||||||
_tcsncat(msg, connected_since, _tsizeof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, connected_since, _countof(msg) - _tcslen(msg) - 1);
|
||||||
|
|
||||||
if (_tcslen(o.conn[config].ip) > 0) {
|
if (_tcslen(o.conn[config].ip) > 0) {
|
||||||
TCHAR *assigned_ip = LoadLocalizedString(IDS_TIP_ASSIGNED_IP, o.conn[config].ip);
|
TCHAR *assigned_ip = LoadLocalizedString(IDS_TIP_ASSIGNED_IP, o.conn[config].ip);
|
||||||
_tcsncat(msg, assigned_ip, _tsizeof(msg) - _tcslen(msg) - 1);
|
_tcsncat(msg, assigned_ip, _countof(msg) - _tcslen(msg) - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ SetTrayIcon(conn_state_t state)
|
||||||
ni.hIcon = LoadLocalizedIcon(icon_id);
|
ni.hIcon = LoadLocalizedIcon(icon_id);
|
||||||
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
|
||||||
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
ni.uCallbackMessage = WM_NOTIFYICONTRAY;
|
||||||
_tcsncpy(ni.szTip, msg, _tsizeof(ni.szTip));
|
_tcsncpy(ni.szTip, msg, _countof(ni.szTip));
|
||||||
|
|
||||||
Shell_NotifyIcon(NIM_MODIFY, &ni);
|
Shell_NotifyIcon(NIM_MODIFY, &ni);
|
||||||
}
|
}
|
||||||
|
@ -355,8 +355,8 @@ ShowTrayBalloon(TCHAR *infotitle_msg, TCHAR *info_msg)
|
||||||
ni.uFlags = NIF_INFO;
|
ni.uFlags = NIF_INFO;
|
||||||
ni.uTimeout = 5000;
|
ni.uTimeout = 5000;
|
||||||
ni.dwInfoFlags = NIIF_INFO;
|
ni.dwInfoFlags = NIIF_INFO;
|
||||||
_tcsncpy(ni.szInfo, info_msg, _tsizeof(ni.szInfo));
|
_tcsncpy(ni.szInfo, info_msg, _countof(ni.szInfo));
|
||||||
_tcsncpy(ni.szInfoTitle, infotitle_msg, _tsizeof(ni.szInfoTitle));
|
_tcsncpy(ni.szInfoTitle, infotitle_msg, _countof(ni.szInfoTitle));
|
||||||
|
|
||||||
Shell_NotifyIcon(NIM_MODIFY, &ni);
|
Shell_NotifyIcon(NIM_MODIFY, &ni);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue