Not all installations need registry values such as log_dir and
config_dir especially if automatic service is not in use.
This patch provides reasonable defaults for registry values.
- Read the default value of HKLM\Software\PACKAGE_NAME to get the
install path and construct defaults for exe_path, config_dir,
log_dir from it. Use "ovpn", "0", NORMAL_PRIORITY as the defaults
for config file extension, log-append flag and process priority.
The only remaining required registry entry is the root key (usually
HKLM\Software\OpenVPN) whose default value should be set to the
installation path.
Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1511026858-23281-2-git-send-email-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15892.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -89,6 +89,8 @@ GetOpenvpnSettings(settings_t *s) |
89 | 89 |
TCHAR append[2]; |
90 | 90 |
DWORD error; |
91 | 91 |
HKEY key; |
92 |
+ TCHAR install_path[MAX_PATH]; |
|
93 |
+ TCHAR default_value[MAX_PATH]; |
|
92 | 94 |
|
93 | 95 |
openvpn_sntprintf(reg_path, _countof(reg_path), TEXT("SOFTWARE\\" PACKAGE_NAME "%s"), service_instance); |
94 | 96 |
|
... | ... |
@@ -99,37 +101,50 @@ GetOpenvpnSettings(settings_t *s) |
99 | 99 |
return MsgToEventLog(M_SYSERR, TEXT("Could not open Registry key HKLM\\%s not found"), reg_path); |
100 | 100 |
} |
101 | 101 |
|
102 |
- error = GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->exe_path), NULL); |
|
102 |
+ /* The default value of REG_KEY is the install path */ |
|
103 |
+ if (GetRegString(key, NULL, install_path, sizeof(install_path), NULL) != ERROR_SUCCESS) |
|
104 |
+ { |
|
105 |
+ goto out; |
|
106 |
+ } |
|
107 |
+ |
|
108 |
+ openvpn_sntprintf(default_value, _countof(default_value), TEXT("%s\\bin\\openvpn.exe"), |
|
109 |
+ install_path); |
|
110 |
+ error = GetRegString(key, TEXT("exe_path"), s->exe_path, sizeof(s->exe_path), default_value); |
|
103 | 111 |
if (error != ERROR_SUCCESS) |
104 | 112 |
{ |
105 | 113 |
goto out; |
106 | 114 |
} |
107 | 115 |
|
108 |
- error = GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(s->config_dir), NULL); |
|
116 |
+ openvpn_sntprintf(default_value, _countof(default_value), TEXT("%s\\config"), install_path); |
|
117 |
+ error = GetRegString(key, TEXT("config_dir"), s->config_dir, sizeof(s->config_dir), |
|
118 |
+ default_value); |
|
109 | 119 |
if (error != ERROR_SUCCESS) |
110 | 120 |
{ |
111 | 121 |
goto out; |
112 | 122 |
} |
113 | 123 |
|
114 |
- error = GetRegString(key, TEXT("config_ext"), s->ext_string, sizeof(s->ext_string), NULL); |
|
124 |
+ error = GetRegString(key, TEXT("config_ext"), s->ext_string, sizeof(s->ext_string), |
|
125 |
+ TEXT(".ovpn")); |
|
115 | 126 |
if (error != ERROR_SUCCESS) |
116 | 127 |
{ |
117 | 128 |
goto out; |
118 | 129 |
} |
119 | 130 |
|
120 |
- error = GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log_dir), NULL); |
|
131 |
+ openvpn_sntprintf(default_value, _countof(default_value), TEXT("%s\\log"), install_path); |
|
132 |
+ error = GetRegString(key, TEXT("log_dir"), s->log_dir, sizeof(s->log_dir), default_value); |
|
121 | 133 |
if (error != ERROR_SUCCESS) |
122 | 134 |
{ |
123 | 135 |
goto out; |
124 | 136 |
} |
125 | 137 |
|
126 |
- error = GetRegString(key, TEXT("priority"), priority, sizeof(priority), NULL); |
|
138 |
+ error = GetRegString(key, TEXT("priority"), priority, sizeof(priority), |
|
139 |
+ TEXT("NORMAL_PRIORITY_CLASS")); |
|
127 | 140 |
if (error != ERROR_SUCCESS) |
128 | 141 |
{ |
129 | 142 |
goto out; |
130 | 143 |
} |
131 | 144 |
|
132 |
- error = GetRegString(key, TEXT("log_append"), append, sizeof(append), NULL); |
|
145 |
+ error = GetRegString(key, TEXT("log_append"), append, sizeof(append), TEXT("0")); |
|
133 | 146 |
if (error != ERROR_SUCCESS) |
134 | 147 |
{ |
135 | 148 |
goto out; |