Merge pull request #197 from selvanair/registry-optional

Add a default for openvpnpath

Acked-by: Илья Шипицин <chipitsine@gmail.com>
Acked-by: Samuli Seppänen <samuli@openvpn.net>
pull/199/head
Selva Nair 2017-12-05 10:12:21 -05:00 committed by GitHub
commit cf2d1a8632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 11 deletions

View File

@ -93,44 +93,46 @@ GetGlobalRegistryKeys()
!= ERROR_SUCCESS) != ERROR_SUCCESS)
{ {
/* registry key not found */ /* registry key not found */
regkey = NULL;
ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY); ShowLocalizedMsg(IDS_ERR_OPEN_REGISTRY);
return(false);
} }
if (!GetRegistryValue(regkey, _T(""), openvpn_path, _countof(openvpn_path))) if (!regkey || !GetRegistryValue(regkey, _T(""), openvpn_path, _countof(openvpn_path)))
{ {
/* error reading registry value */ /* error reading registry value */
if (regkey)
ShowLocalizedMsg(IDS_ERR_READING_REGISTRY); ShowLocalizedMsg(IDS_ERR_READING_REGISTRY);
RegCloseKey(regkey); /* Use a sane default value */
return(false); _sntprintf_0(openvpn_path, _T("%s"), _T("C:\\Program Files\\OpenVPN\\"));
} }
if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\')) if (openvpn_path[_tcslen(openvpn_path) - 1] != _T('\\'))
_tcscat(openvpn_path, _T("\\")); _tcscat(openvpn_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 (!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("%sconfig"), openvpn_path); _sntprintf_0(o.global_config_dir, _T("%sconfig"), openvpn_path);
} }
if (!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 (!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("%sbin\\openvpn.exe"), openvpn_path); _sntprintf_0(o.exe_path, _T("%sbin\\openvpn.exe"), openvpn_path);
} }
if (!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); _tcsncpy(o.priority_string, _T("NORMAL_PRIORITY_CLASS"), _countof(o.priority_string)-1);
} }
if (!GetRegistryValueNumeric(regkey, _T("disable_save_passwords"), &o.disable_save_passwords)) if (!regkey || !GetRegistryValueNumeric(regkey, _T("disable_save_passwords"), &o.disable_save_passwords))
{ {
o.disable_save_passwords = 0; o.disable_save_passwords = 0;
} }
if (regkey)
RegCloseKey(regkey); RegCloseKey(regkey);
return true; return true;
} }