|
|
@ -43,159 +43,174 @@ struct regkey_str {
|
|
|
|
int len;
|
|
|
|
int len;
|
|
|
|
const WCHAR *value;
|
|
|
|
const WCHAR *value;
|
|
|
|
} regkey_str[] = {
|
|
|
|
} regkey_str[] = {
|
|
|
|
{L"config_dir", o.config_dir, _countof(o.config_dir), L"%USERPROFILE%\\OpenVPN\\config"},
|
|
|
|
{L"config_dir", o.config_dir, _countof(o.config_dir), L"%USERPROFILE%\\OpenVPN\\config"},
|
|
|
|
{L"config_ext", o.ext_string, _countof(o.ext_string), L"ovpn"},
|
|
|
|
{L"config_ext", o.ext_string, _countof(o.ext_string), L"ovpn"},
|
|
|
|
{L"log_dir", o.log_dir, _countof(o.log_dir), L"%USERPROFILE%\\OpenVPN\\log"}
|
|
|
|
{L"log_dir", o.log_dir, _countof(o.log_dir), L"%USERPROFILE%\\OpenVPN\\log"}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct regkey_int {
|
|
|
|
struct regkey_int {
|
|
|
|
const WCHAR *name;
|
|
|
|
const WCHAR *name;
|
|
|
|
DWORD *var;
|
|
|
|
DWORD *var;
|
|
|
|
DWORD value;
|
|
|
|
DWORD value;
|
|
|
|
} regkey_int[] = {
|
|
|
|
} regkey_int[] = {
|
|
|
|
{L"log_append", &o.log_append, 0},
|
|
|
|
{L"log_append", &o.log_append, 0},
|
|
|
|
{L"iservice_admin", &o.iservice_admin, 1},
|
|
|
|
{L"iservice_admin", &o.iservice_admin, 1},
|
|
|
|
{L"show_balloon", &o.show_balloon, 1},
|
|
|
|
{L"show_balloon", &o.show_balloon, 1},
|
|
|
|
{L"silent_connection", &o.silent_connection, 0},
|
|
|
|
{L"silent_connection", &o.silent_connection, 0},
|
|
|
|
{L"preconnectscript_timeout", &o.preconnectscript_timeout, 10},
|
|
|
|
{L"preconnectscript_timeout", &o.preconnectscript_timeout, 10},
|
|
|
|
{L"connectscript_timeout", &o.connectscript_timeout, 30},
|
|
|
|
{L"connectscript_timeout", &o.connectscript_timeout, 30},
|
|
|
|
{L"disconnectscript_timeout", &o.disconnectscript_timeout, 10},
|
|
|
|
{L"disconnectscript_timeout", &o.disconnectscript_timeout, 10},
|
|
|
|
{L"show_script_window", &o.show_script_window, 0},
|
|
|
|
{L"show_script_window", &o.show_script_window, 0},
|
|
|
|
{L"config_menu_view", &o.config_menu_view, CONFIG_VIEW_AUTO},
|
|
|
|
{L"config_menu_view", &o.config_menu_view, CONFIG_VIEW_AUTO},
|
|
|
|
{L"popup_mute_interval", &o.popup_mute_interval, 24},
|
|
|
|
{L"popup_mute_interval", &o.popup_mute_interval, 24},
|
|
|
|
{L"disable_popup_messages", &o.disable_popup_messages, 0},
|
|
|
|
{L"disable_popup_messages", &o.disable_popup_messages, 0},
|
|
|
|
{L"management_port_offset", &o.mgmt_port_offset, 25340},
|
|
|
|
{L"management_port_offset", &o.mgmt_port_offset, 25340},
|
|
|
|
{L"enable_peristent_connections", &o.enable_persistent, 2},
|
|
|
|
{L"enable_peristent_connections", &o.enable_persistent, 2},
|
|
|
|
{L"enable_auto_restart", &o.enable_auto_restart, 1},
|
|
|
|
{L"enable_auto_restart", &o.enable_auto_restart, 1},
|
|
|
|
{L"ovpn_engine", &o.ovpn_engine, OPENVPN_ENGINE_OVPN2}
|
|
|
|
{L"ovpn_engine", &o.ovpn_engine, OPENVPN_ENGINE_OVPN2}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
static int
|
|
|
|
RegValueExists (HKEY regkey, const WCHAR *name)
|
|
|
|
RegValueExists(HKEY regkey, const WCHAR *name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (RegQueryValueEx (regkey, name, NULL, NULL, NULL, NULL) == ERROR_SUCCESS);
|
|
|
|
return (RegQueryValueEx(regkey, name, NULL, NULL, NULL, NULL) == ERROR_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
static int
|
|
|
|
GetGlobalRegistryKeys()
|
|
|
|
GetGlobalRegistryKeys()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TCHAR windows_dir[MAX_PATH];
|
|
|
|
TCHAR windows_dir[MAX_PATH];
|
|
|
|
HKEY regkey;
|
|
|
|
HKEY regkey;
|
|
|
|
|
|
|
|
|
|
|
|
if (!GetWindowsDirectory(windows_dir, _countof(windows_dir))) {
|
|
|
|
if (!GetWindowsDirectory(windows_dir, _countof(windows_dir)))
|
|
|
|
/* can't get windows dir */
|
|
|
|
{
|
|
|
|
ShowLocalizedMsg(IDS_ERR_GET_WINDOWS_DIR);
|
|
|
|
/* can't get windows dir */
|
|
|
|
/* Use a default value */
|
|
|
|
ShowLocalizedMsg(IDS_ERR_GET_WINDOWS_DIR);
|
|
|
|
_sntprintf_0(windows_dir, L"C:\\Windows");
|
|
|
|
/* Use a default value */
|
|
|
|
}
|
|
|
|
_sntprintf_0(windows_dir, L"C:\\Windows");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set default editor and log_viewer as a fallback for opening config/log files */
|
|
|
|
/* set default editor and log_viewer as a fallback for opening config/log files */
|
|
|
|
_sntprintf_0(o.editor, L"%ls\\%ls", windows_dir, L"System32\\notepad.exe");
|
|
|
|
_sntprintf_0(o.editor, L"%ls\\%ls", windows_dir, L"System32\\notepad.exe");
|
|
|
|
_sntprintf_0(o.log_viewer, L"%ls", o.editor);
|
|
|
|
_sntprintf_0(o.log_viewer, L"%ls", o.editor);
|
|
|
|
|
|
|
|
|
|
|
|
/* Get path to OpenVPN installation. */
|
|
|
|
/* Get path to OpenVPN installation. */
|
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\OpenVPN"), 0, KEY_READ, ®key)
|
|
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\OpenVPN"), 0, KEY_READ, ®key)
|
|
|
|
!= ERROR_SUCCESS)
|
|
|
|
!= ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* registry key not found */
|
|
|
|
/* registry key not found */
|
|
|
|
regkey = NULL;
|
|
|
|
regkey = NULL;
|
|
|
|
ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY);
|
|
|
|
ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T(""), o.install_path, _countof(o.install_path))
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T(""), o.install_path, _countof(o.install_path))
|
|
|
|
|| _tcslen(o.install_path) == 0)
|
|
|
|
|| _tcslen(o.install_path) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* error reading registry value */
|
|
|
|
/* error reading registry value */
|
|
|
|
if (regkey)
|
|
|
|
if (regkey)
|
|
|
|
ShowLocalizedMsg(IDS_ERR_READING_REGISTRY);
|
|
|
|
{
|
|
|
|
/* Use a sane default value */
|
|
|
|
ShowLocalizedMsg(IDS_ERR_READING_REGISTRY);
|
|
|
|
_sntprintf_0(o.install_path, _T("%ls"), _T("C:\\Program Files\\OpenVPN\\"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use a sane default value */
|
|
|
|
|
|
|
|
_sntprintf_0(o.install_path, _T("%ls"), _T("C:\\Program Files\\OpenVPN\\"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (o.install_path[_tcslen(o.install_path) - 1] != _T('\\'))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_tcscat(o.install_path, _T("\\"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (o.install_path[_tcslen(o.install_path) - 1] != _T('\\'))
|
|
|
|
|
|
|
|
_tcscat(o.install_path, _T("\\"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* an admin-defined global config dir defined in HKLM\OpenVPN\config_dir */
|
|
|
|
/* an admin-defined global config dir defined in HKLM\OpenVPN\config_dir */
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("config_dir"), o.global_config_dir, _countof(o.global_config_dir)))
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("config_dir"), o.global_config_dir, _countof(o.global_config_dir)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* use default = openvpnpath\config */
|
|
|
|
/* use default = openvpnpath\config */
|
|
|
|
_sntprintf_0(o.global_config_dir, _T("%lsconfig"), o.install_path);
|
|
|
|
_sntprintf_0(o.global_config_dir, _T("%lsconfig"), o.install_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("autostart_config_dir"), o.config_auto_dir, _countof(o.config_auto_dir)))
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("autostart_config_dir"), o.config_auto_dir, _countof(o.config_auto_dir)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* use default = openvpnpath\config-auto */
|
|
|
|
/* use default = openvpnpath\config-auto */
|
|
|
|
_sntprintf_0(o.config_auto_dir, L"%lsconfig-auto", o.install_path);
|
|
|
|
_sntprintf_0(o.config_auto_dir, L"%lsconfig-auto", o.install_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("log_dir"), o.global_log_dir, _countof(o.global_log_dir)))
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("log_dir"), o.global_log_dir, _countof(o.global_log_dir)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* use default = openvpnpath\log */
|
|
|
|
/* use default = openvpnpath\log */
|
|
|
|
_sntprintf_0(o.global_log_dir, L"%lslog", o.install_path);
|
|
|
|
_sntprintf_0(o.global_log_dir, L"%lslog", o.install_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("ovpn_admin_group"), o.ovpn_admin_group, _countof(o.ovpn_admin_group)))
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("ovpn_admin_group"), o.ovpn_admin_group, _countof(o.ovpn_admin_group)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_tcsncpy(o.ovpn_admin_group, OVPN_ADMIN_GROUP, _countof(o.ovpn_admin_group)-1);
|
|
|
|
_tcsncpy(o.ovpn_admin_group, OVPN_ADMIN_GROUP, _countof(o.ovpn_admin_group)-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("exe_path"), o.exe_path, _countof(o.exe_path)))
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("exe_path"), o.exe_path, _countof(o.exe_path)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_sntprintf_0(o.exe_path, _T("%lsbin\\openvpn.exe"), o.install_path);
|
|
|
|
_sntprintf_0(o.exe_path, _T("%lsbin\\openvpn.exe"), o.install_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("priority"), o.priority_string, _countof(o.priority_string)))
|
|
|
|
if (!regkey || !GetRegistryValue(regkey, _T("priority"), o.priority_string, _countof(o.priority_string)))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_tcsncpy(o.priority_string, _T("NORMAL_PRIORITY_CLASS"), _countof(o.priority_string)-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!regkey || !GetRegistryValueNumeric(regkey, _T("disable_save_passwords"), &o.disable_save_passwords))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_tcsncpy(o.priority_string, _T("NORMAL_PRIORITY_CLASS"), _countof(o.priority_string)-1);
|
|
|
|
o.disable_save_passwords = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!regkey || !GetRegistryValueNumeric(regkey, _T("disable_save_passwords"), &o.disable_save_passwords))
|
|
|
|
if (regkey)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
o.disable_save_passwords = 0;
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (regkey)
|
|
|
|
return true;
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
|
GetRegistryKeys ()
|
|
|
|
GetRegistryKeys()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HKEY regkey;
|
|
|
|
HKEY regkey;
|
|
|
|
DWORD status;
|
|
|
|
DWORD status;
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
if (!GetGlobalRegistryKeys())
|
|
|
|
if (!GetGlobalRegistryKeys())
|
|
|
|
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status = RegOpenKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, KEY_READ, ®key);
|
|
|
|
status = RegOpenKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, KEY_READ, ®key);
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0 ; i < (int) _countof (regkey_str); ++i)
|
|
|
|
for (i = 0; i < (int) _countof(regkey_str); ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( status != ERROR_SUCCESS ||
|
|
|
|
if (status != ERROR_SUCCESS
|
|
|
|
!GetRegistryValue (regkey, regkey_str[i].name, regkey_str[i].var, regkey_str[i].len))
|
|
|
|
|| !GetRegistryValue(regkey, regkey_str[i].name, regkey_str[i].var, regkey_str[i].len))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* no value found in registry, use the default */
|
|
|
|
/* no value found in registry, use the default */
|
|
|
|
wcsncpy (regkey_str[i].var, regkey_str[i].value, regkey_str[i].len);
|
|
|
|
wcsncpy(regkey_str[i].var, regkey_str[i].value, regkey_str[i].len);
|
|
|
|
regkey_str[i].var[regkey_str[i].len-1] = L'\0';
|
|
|
|
regkey_str[i].var[regkey_str[i].len-1] = L'\0';
|
|
|
|
PrintDebug(L"default: %ls = %ls", regkey_str[i].name, regkey_str[i].var);
|
|
|
|
PrintDebug(L"default: %ls = %ls", regkey_str[i].name, regkey_str[i].var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
PrintDebug(L"from registry: %ls = %ls", regkey_str[i].name, regkey_str[i].var);
|
|
|
|
PrintDebug(L"from registry: %ls = %ls", regkey_str[i].name, regkey_str[i].var);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0 ; i < (int) _countof (regkey_int); ++i)
|
|
|
|
for (i = 0; i < (int) _countof(regkey_int); ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( status != ERROR_SUCCESS ||
|
|
|
|
if (status != ERROR_SUCCESS
|
|
|
|
!GetRegistryValueNumeric (regkey, regkey_int[i].name, regkey_int[i].var))
|
|
|
|
|| !GetRegistryValueNumeric(regkey, regkey_int[i].name, regkey_int[i].var))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* no value found in registry, use the default */
|
|
|
|
/* no value found in registry, use the default */
|
|
|
|
*regkey_int[i].var = regkey_int[i].value;
|
|
|
|
*regkey_int[i].var = regkey_int[i].value;
|
|
|
|
PrintDebug(L"default: %ls = %lu", regkey_int[i].name, *regkey_int[i].var);
|
|
|
|
PrintDebug(L"default: %ls = %lu", regkey_int[i].name, *regkey_int[i].var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
PrintDebug(L"from registry: %ls = %lu", regkey_int[i].name, *regkey_int[i].var);
|
|
|
|
PrintDebug(L"from registry: %ls = %lu", regkey_int[i].name, *regkey_int[i].var);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( status == ERROR_SUCCESS)
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
RegCloseKey (regkey);
|
|
|
|
{
|
|
|
|
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((o.disconnectscript_timeout == 0))
|
|
|
|
if ((o.disconnectscript_timeout == 0))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -229,12 +244,12 @@ GetRegistryKeys ()
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExpandOptions ();
|
|
|
|
ExpandOptions();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
|
SaveRegistryKeys ()
|
|
|
|
SaveRegistryKeys()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HKEY regkey;
|
|
|
|
HKEY regkey;
|
|
|
|
DWORD status;
|
|
|
|
DWORD status;
|
|
|
@ -245,27 +260,31 @@ SaveRegistryKeys ()
|
|
|
|
KEY_WRITE|KEY_READ, NULL, ®key, NULL);
|
|
|
|
KEY_WRITE|KEY_READ, NULL, ®key, NULL);
|
|
|
|
if (status != ERROR_SUCCESS)
|
|
|
|
if (status != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ShowLocalizedMsg (IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
|
|
|
|
ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
|
|
|
|
goto out;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0 ; i < (int) _countof (regkey_str); ++i)
|
|
|
|
for (i = 0; i < (int) _countof(regkey_str); ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* save only if the value differs from default or already present in registry */
|
|
|
|
/* save only if the value differs from default or already present in registry */
|
|
|
|
if ( CompareStringExpanded (regkey_str[i].var, regkey_str[i].value) != 0 ||
|
|
|
|
if (CompareStringExpanded(regkey_str[i].var, regkey_str[i].value) != 0
|
|
|
|
RegValueExists(regkey, regkey_str[i].name) )
|
|
|
|
|| RegValueExists(regkey, regkey_str[i].name) )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!SetRegistryValue (regkey, regkey_str[i].name, regkey_str[i].var))
|
|
|
|
if (!SetRegistryValue(regkey, regkey_str[i].name, regkey_str[i].var))
|
|
|
|
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0 ; i < (int) _countof (regkey_int); ++i)
|
|
|
|
for (i = 0; i < (int) _countof(regkey_int); ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( *regkey_int[i].var != regkey_int[i].value ||
|
|
|
|
if (*regkey_int[i].var != regkey_int[i].value
|
|
|
|
RegValueExists(regkey, regkey_int[i].name) )
|
|
|
|
|| RegValueExists(regkey, regkey_int[i].name) )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!SetRegistryValueNumeric (regkey, regkey_int[i].name, *regkey_int[i].var))
|
|
|
|
if (!SetRegistryValueNumeric(regkey, regkey_int[i].name, *regkey_int[i].var))
|
|
|
|
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = true;
|
|
|
|
ret = true;
|
|
|
@ -273,29 +292,33 @@ SaveRegistryKeys ()
|
|
|
|
out:
|
|
|
|
out:
|
|
|
|
|
|
|
|
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
|
|
|
|
{
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
static BOOL
|
|
|
|
GetRegistryVersion (version_t *v)
|
|
|
|
GetRegistryVersion(version_t *v)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HKEY regkey;
|
|
|
|
HKEY regkey;
|
|
|
|
CLEAR (*v);
|
|
|
|
CLEAR(*v);
|
|
|
|
DWORD len = sizeof(*v);
|
|
|
|
DWORD len = sizeof(*v);
|
|
|
|
|
|
|
|
|
|
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, KEY_READ, ®key) == ERROR_SUCCESS)
|
|
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, KEY_READ, ®key) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (RegGetValueW (regkey, NULL, L"version", RRF_RT_REG_BINARY, NULL, v, &len)
|
|
|
|
if (RegGetValueW(regkey, NULL, L"version", RRF_RT_REG_BINARY, NULL, v, &len)
|
|
|
|
!= ERROR_SUCCESS)
|
|
|
|
!= ERROR_SUCCESS)
|
|
|
|
CLEAR (*v);
|
|
|
|
{
|
|
|
|
|
|
|
|
CLEAR(*v);
|
|
|
|
|
|
|
|
}
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
static BOOL
|
|
|
|
SetRegistryVersion (const version_t *v)
|
|
|
|
SetRegistryVersion(const version_t *v)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
HKEY regkey;
|
|
|
|
HKEY regkey;
|
|
|
|
DWORD status;
|
|
|
|
DWORD status;
|
|
|
@ -305,12 +328,16 @@ SetRegistryVersion (const version_t *v)
|
|
|
|
KEY_WRITE, NULL, ®key, NULL);
|
|
|
|
KEY_WRITE, NULL, ®key, NULL);
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (RegSetValueEx(regkey, L"version", 0, REG_BINARY, (const BYTE*) v, sizeof(*v)) == ERROR_SUCCESS)
|
|
|
|
if (RegSetValueEx(regkey, L"version", 0, REG_BINARY, (const BYTE *) v, sizeof(*v)) == ERROR_SUCCESS)
|
|
|
|
|
|
|
|
{
|
|
|
|
ret = true;
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
PrintDebug (L"Eror opening/creating 'HKCU\\%ls' registry key", GUI_REGKEY_HKCU);
|
|
|
|
{
|
|
|
|
|
|
|
|
PrintDebug(L"Eror opening/creating 'HKCU\\%ls' registry key", GUI_REGKEY_HKCU);
|
|
|
|
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -322,16 +349,18 @@ MigrateNilingsKeys()
|
|
|
|
HKEY regkey, regkey_proxy, regkey_nilings;
|
|
|
|
HKEY regkey, regkey_proxy, regkey_nilings;
|
|
|
|
|
|
|
|
|
|
|
|
status = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Nilings\\OpenVPN-GUI", 0,
|
|
|
|
status = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Nilings\\OpenVPN-GUI", 0,
|
|
|
|
KEY_READ, ®key_nilings);
|
|
|
|
KEY_READ, ®key_nilings);
|
|
|
|
if (status != ERROR_SUCCESS)
|
|
|
|
if (status != ERROR_SUCCESS)
|
|
|
|
|
|
|
|
{
|
|
|
|
return true; /* No old keys to migrate */
|
|
|
|
return true; /* No old keys to migrate */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
status = RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, NULL, REG_OPTION_NON_VOLATILE,
|
|
|
|
status = RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, NULL, REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS, NULL, ®key, NULL);
|
|
|
|
KEY_ALL_ACCESS, NULL, ®key, NULL);
|
|
|
|
if (status != ERROR_SUCCESS)
|
|
|
|
if (status != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ShowLocalizedMsg (IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
|
|
|
|
ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
|
|
|
|
RegCloseKey (regkey_nilings);
|
|
|
|
RegCloseKey(regkey_nilings);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -343,112 +372,132 @@ MigrateNilingsKeys()
|
|
|
|
DWORD ui_lang;
|
|
|
|
DWORD ui_lang;
|
|
|
|
/* Move language setting from Nilings to GUI_REGKEY_HKCU */
|
|
|
|
/* Move language setting from Nilings to GUI_REGKEY_HKCU */
|
|
|
|
if (GetRegistryValueNumeric(regkey_nilings, L"ui_language", &ui_lang))
|
|
|
|
if (GetRegistryValueNumeric(regkey_nilings, L"ui_language", &ui_lang))
|
|
|
|
SetRegistryValueNumeric (regkey, L"ui_language", ui_lang);
|
|
|
|
{
|
|
|
|
|
|
|
|
SetRegistryValueNumeric(regkey, L"ui_language", ui_lang);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status = RegCopyTree (regkey_nilings, NULL, regkey_proxy);
|
|
|
|
status = RegCopyTree(regkey_nilings, NULL, regkey_proxy);
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RegDeleteValue (regkey_proxy, L"ui_language"); /* in case copied here */
|
|
|
|
RegDeleteValue(regkey_proxy, L"ui_language"); /* in case copied here */
|
|
|
|
ret = true;
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey (regkey_proxy);
|
|
|
|
RegCloseKey(regkey_proxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
PrintDebug (L"Error creating key 'proxy' in HKCU\\%ls", GUI_REGKEY_HKCU);
|
|
|
|
{
|
|
|
|
|
|
|
|
PrintDebug(L"Error creating key 'proxy' in HKCU\\%ls", GUI_REGKEY_HKCU);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RegCloseKey (regkey);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
RegCloseKey (regkey_nilings);
|
|
|
|
RegCloseKey(regkey_nilings);
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
|
UpdateRegistry (void)
|
|
|
|
UpdateRegistry(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
version_t v;
|
|
|
|
version_t v;
|
|
|
|
|
|
|
|
|
|
|
|
GetRegistryVersion (&v);
|
|
|
|
GetRegistryVersion(&v);
|
|
|
|
|
|
|
|
|
|
|
|
if (memcmp(&v, &o.version, sizeof(v)) == 0)
|
|
|
|
if (memcmp(&v, &o.version, sizeof(v)) == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (v.major)
|
|
|
|
switch (v.major)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case 0: /* Cleanup GUI_REGKEY_HKCU and migrate any values under Nilings */
|
|
|
|
case 0: /* Cleanup GUI_REGKEY_HKCU and migrate any values under Nilings */
|
|
|
|
|
|
|
|
|
|
|
|
RegDeleteTree (HKEY_CURRENT_USER, GUI_REGKEY_HKCU); /* delete all values and subkeys */
|
|
|
|
RegDeleteTree(HKEY_CURRENT_USER, GUI_REGKEY_HKCU); /* delete all values and subkeys */
|
|
|
|
|
|
|
|
|
|
|
|
if (!MigrateNilingsKeys())
|
|
|
|
if (!MigrateNilingsKeys())
|
|
|
|
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* fall through to handle further updates */
|
|
|
|
/* fall through to handle further updates */
|
|
|
|
case 11:
|
|
|
|
case 11:
|
|
|
|
/* current version -- nothing to do */
|
|
|
|
/* current version -- nothing to do */
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SetRegistryVersion (&o.version);
|
|
|
|
SetRegistryVersion(&o.version);
|
|
|
|
PrintDebug (L"Registry updated to version %hu.%hu", o.version.major, o.version.minor);
|
|
|
|
PrintDebug(L"Registry updated to version %hu.%hu", o.version.major, o.version.minor);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LONG GetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data, DWORD len)
|
|
|
|
LONG
|
|
|
|
|
|
|
|
GetRegistryValue(HKEY regkey, const TCHAR *name, TCHAR *data, DWORD len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LONG status;
|
|
|
|
LONG status;
|
|
|
|
DWORD type;
|
|
|
|
DWORD type;
|
|
|
|
DWORD data_len;
|
|
|
|
DWORD data_len;
|
|
|
|
|
|
|
|
|
|
|
|
data_len = len * sizeof(*data);
|
|
|
|
data_len = len * sizeof(*data);
|
|
|
|
|
|
|
|
|
|
|
|
/* get a registry string */
|
|
|
|
/* get a registry string */
|
|
|
|
status = RegQueryValueEx(regkey, name, NULL, &type, (byte *) data, &data_len);
|
|
|
|
status = RegQueryValueEx(regkey, name, NULL, &type, (byte *) data, &data_len);
|
|
|
|
if (status != ERROR_SUCCESS || type != REG_SZ)
|
|
|
|
if (status != ERROR_SUCCESS || type != REG_SZ)
|
|
|
|
return(0);
|
|
|
|
{
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data_len /= sizeof(*data);
|
|
|
|
data_len /= sizeof(*data);
|
|
|
|
if (data_len > 0)
|
|
|
|
if (data_len > 0)
|
|
|
|
data[data_len - 1] = L'\0'; /* REG_SZ strings are not guaranteed to be null-terminated */
|
|
|
|
{
|
|
|
|
else
|
|
|
|
data[data_len - 1] = L'\0'; /* REG_SZ strings are not guaranteed to be null-terminated */
|
|
|
|
data[0] = L'\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
data[0] = L'\0';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return(data_len);
|
|
|
|
return(data_len);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LONG
|
|
|
|
LONG
|
|
|
|
GetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD *data)
|
|
|
|
GetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD *data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
DWORD type;
|
|
|
|
DWORD size = sizeof(*data);
|
|
|
|
DWORD size = sizeof(*data);
|
|
|
|
LONG status = RegQueryValueEx(regkey, name, NULL, &type, (PBYTE) data, &size);
|
|
|
|
LONG status = RegQueryValueEx(regkey, name, NULL, &type, (PBYTE) data, &size);
|
|
|
|
return (type == REG_DWORD && status == ERROR_SUCCESS) ? 1 : 0;
|
|
|
|
return (type == REG_DWORD && status == ERROR_SUCCESS) ? 1 : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SetRegistryValue(HKEY regkey, const TCHAR *name, const TCHAR *data)
|
|
|
|
int
|
|
|
|
|
|
|
|
SetRegistryValue(HKEY regkey, const TCHAR *name, const TCHAR *data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* set a registry string */
|
|
|
|
/* set a registry string */
|
|
|
|
DWORD size = (_tcslen(data) + 1) * sizeof(*data);
|
|
|
|
DWORD size = (_tcslen(data) + 1) * sizeof(*data);
|
|
|
|
if(RegSetValueEx(regkey, name, 0, REG_SZ, (PBYTE) data, size) != ERROR_SUCCESS)
|
|
|
|
if (RegSetValueEx(regkey, name, 0, REG_SZ, (PBYTE) data, size) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Error writing registry value */
|
|
|
|
/* Error writing registry value */
|
|
|
|
ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name);
|
|
|
|
ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name);
|
|
|
|
return(0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
|
SetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD data)
|
|
|
|
SetRegistryValueNumeric(HKEY regkey, const TCHAR *name, DWORD data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LONG status = RegSetValueEx(regkey, name, 0, REG_DWORD, (PBYTE) &data, sizeof(data));
|
|
|
|
LONG status = RegSetValueEx(regkey, name, 0, REG_DWORD, (PBYTE) &data, sizeof(data));
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
return 1;
|
|
|
|
{
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name);
|
|
|
|
ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, GUI_REGKEY_HKCU, name);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -464,18 +513,24 @@ OpenConfigRegistryKey(const WCHAR *config_name, HKEY *regkey, BOOL create)
|
|
|
|
WCHAR *name = malloc(count * sizeof(WCHAR));
|
|
|
|
WCHAR *name = malloc(count * sizeof(WCHAR));
|
|
|
|
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
if (!name)
|
|
|
|
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_snwprintf(name, count, fmt, config_name);
|
|
|
|
_snwprintf(name, count, fmt, config_name);
|
|
|
|
name[count-1] = L'\0';
|
|
|
|
name[count-1] = L'\0';
|
|
|
|
|
|
|
|
|
|
|
|
if (!create)
|
|
|
|
if (!create)
|
|
|
|
status = RegOpenKeyEx (HKEY_CURRENT_USER, name, 0, KEY_READ | KEY_WRITE, regkey);
|
|
|
|
{
|
|
|
|
|
|
|
|
status = RegOpenKeyEx(HKEY_CURRENT_USER, name, 0, KEY_READ | KEY_WRITE, regkey);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
/* create if key doesn't exist */
|
|
|
|
{
|
|
|
|
status = RegCreateKeyEx(HKEY_CURRENT_USER, name, 0, NULL,
|
|
|
|
/* create if key doesn't exist */
|
|
|
|
REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, regkey, NULL);
|
|
|
|
status = RegCreateKeyEx(HKEY_CURRENT_USER, name, 0, NULL,
|
|
|
|
free (name);
|
|
|
|
REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, regkey, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
|
|
|
|
return (status == ERROR_SUCCESS);
|
|
|
|
return (status == ERROR_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -487,7 +542,9 @@ SetConfigRegistryValueBinary(const WCHAR *config_name, const WCHAR *name, const
|
|
|
|
DWORD status;
|
|
|
|
DWORD status;
|
|
|
|
|
|
|
|
|
|
|
|
if (!OpenConfigRegistryKey(config_name, ®key, TRUE))
|
|
|
|
if (!OpenConfigRegistryKey(config_name, ®key, TRUE))
|
|
|
|
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
status = RegSetValueEx(regkey, name, 0, REG_BINARY, data, len);
|
|
|
|
status = RegSetValueEx(regkey, name, 0, REG_BINARY, data, len);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
|
|
|
|
|
|
|
@ -507,13 +564,19 @@ GetConfigRegistryValue(const WCHAR *config_name, const WCHAR *name, BYTE *data,
|
|
|
|
HKEY regkey;
|
|
|
|
HKEY regkey;
|
|
|
|
|
|
|
|
|
|
|
|
if (!OpenConfigRegistryKey(config_name, ®key, FALSE))
|
|
|
|
if (!OpenConfigRegistryKey(config_name, ®key, FALSE))
|
|
|
|
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
status = RegQueryValueEx(regkey, name, NULL, &type, data, &len);
|
|
|
|
status = RegQueryValueEx(regkey, name, NULL, &type, data, &len);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
|
|
|
|
{
|
|
|
|
return len;
|
|
|
|
return len;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
@ -523,7 +586,9 @@ DeleteConfigRegistryValue(const WCHAR *config_name, const WCHAR *name)
|
|
|
|
HKEY regkey;
|
|
|
|
HKEY regkey;
|
|
|
|
|
|
|
|
|
|
|
|
if (!OpenConfigRegistryKey(config_name, ®key, FALSE))
|
|
|
|
if (!OpenConfigRegistryKey(config_name, ®key, FALSE))
|
|
|
|
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
status = RegDeleteValue(regkey, name);
|
|
|
|
status = RegDeleteValue(regkey, name);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
RegCloseKey(regkey);
|
|
|
|
|
|
|
|
|
|
|
|