37
37
#include "config.h"
39
39
#define KEY_ROOT HKEY_LOCAL_MACHINE
40
#define KEY_PREFIX "SOFTWARE\\wpa_supplicant"
40
#define KEY_PREFIX TEXT("SOFTWARE\\wpa_supplicant")
43
49
static int wpa_config_read_blobs(struct wpa_config *config, HKEY hk)
51
ret = RegOpenKeyEx(hk, "blobs", 0, KEY_QUERY_VALUE, &bhk);
57
ret = RegOpenKeyEx(hk, TEXT("blobs"), 0, KEY_QUERY_VALUE, &bhk);
52
58
if (ret != ERROR_SUCCESS) {
53
59
wpa_printf(MSG_DEBUG, "Could not open wpa_supplicant config "
58
64
for (i = 0; ; i++) {
59
char name[255], data[4096];
60
68
DWORD namelen, datalen, type;
62
namelen = sizeof(name);
63
71
datalen = sizeof(data);
64
72
ret = RegEnumValue(bhk, i, name, &namelen, NULL, &type,
73
(LPBYTE) data, &datalen);
67
75
if (ret == ERROR_NO_MORE_ITEMS)
76
if (namelen >= sizeof(name))
77
namelen = sizeof(name) - 1;
84
if (namelen >= TNAMELEN)
85
namelen = TNAMELEN - 1;
86
name[namelen] = TEXT('\0');
87
wpa_unicode2ascii_inplace(name);
80
89
if (datalen >= sizeof(data))
81
90
datalen = sizeof(data) - 1;
84
92
wpa_printf(MSG_MSGDUMP, "blob %d: field='%s' len %d",
85
93
(int) i, name, (int) datalen);
92
blob->name = strdup(name);
100
blob->name = strdup((char *) name);
93
101
blob->data = malloc(datalen);
94
102
if (blob->name == NULL || blob->data == NULL) {
95
103
wpa_config_free_blob(blob);
128
static char * wpa_config_read_reg_string(HKEY hk, const char *name)
136
static char * wpa_config_read_reg_string(HKEY hk, const TCHAR *name)
135
143
ret = RegQueryValueEx(hk, name, NULL, NULL, NULL, &buflen);
136
144
if (ret != ERROR_SUCCESS)
138
val = malloc(buflen + 1);
146
val = malloc(buflen);
143
150
ret = RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE) val, &buflen);
144
151
if (ret != ERROR_SUCCESS) {
149
wpa_printf(MSG_DEBUG, "%s=%s", name, val);
156
wpa_unicode2ascii_inplace(val);
157
wpa_printf(MSG_DEBUG, "%s=%s", name, (char *) val);
158
wpa_config_read_reg_dword(hk, "ap_scan", &config->ap_scan);
159
wpa_config_read_reg_dword(hk, "fast_reauth", &config->fast_reauth);
160
wpa_config_read_reg_dword(hk, "dot11RSNAConfigPMKLifetime",
166
wpa_config_read_reg_dword(hk, TEXT("ap_scan"), &config->ap_scan);
167
wpa_config_read_reg_dword(hk, TEXT("fast_reauth"),
168
&config->fast_reauth);
169
wpa_config_read_reg_dword(hk, TEXT("dot11RSNAConfigPMKLifetime"),
161
170
&config->dot11RSNAConfigPMKLifetime);
162
wpa_config_read_reg_dword(hk, "dot11RSNAConfigPMKReauthThreshold",
171
wpa_config_read_reg_dword(hk,
172
TEXT("dot11RSNAConfigPMKReauthThreshold"),
163
173
&config->dot11RSNAConfigPMKReauthThreshold);
164
wpa_config_read_reg_dword(hk, "dot11RSNAConfigSATimeout",
174
wpa_config_read_reg_dword(hk, TEXT("dot11RSNAConfigSATimeout"),
165
175
&config->dot11RSNAConfigSATimeout);
166
wpa_config_read_reg_dword(hk, "update_config", &config->update_config);
176
wpa_config_read_reg_dword(hk, TEXT("update_config"),
177
&config->update_config);
168
if (wpa_config_read_reg_dword(hk, "eapol_version",
179
if (wpa_config_read_reg_dword(hk, TEXT("eapol_version"),
169
180
&config->eapol_version) == 0) {
170
181
if (config->eapol_version < 1 ||
171
182
config->eapol_version > 2) {
178
config->ctrl_interface = wpa_config_read_reg_string(hk,
189
config->ctrl_interface = wpa_config_read_reg_string(
190
hk, TEXT("ctrl_interface"));
181
192
return errors ? -1 : 0;
185
static struct wpa_ssid * wpa_config_read_network(HKEY hk, const char *netw,
196
static struct wpa_ssid * wpa_config_read_network(HKEY hk, const TCHAR *netw,
194
205
ret = RegOpenKeyEx(hk, netw, 0, KEY_QUERY_VALUE, &nhk);
195
206
if (ret != ERROR_SUCCESS) {
196
207
wpa_printf(MSG_DEBUG, "Could not open wpa_supplicant config "
197
"network '%s'", netw);
208
"network '" TSTR "'", netw);
201
wpa_printf(MSG_MSGDUMP, "Start of a new network '%s'", netw);
212
wpa_printf(MSG_MSGDUMP, "Start of a new network '" TSTR "'", netw);
202
213
ssid = wpa_zalloc(sizeof(*ssid));
203
214
if (ssid == NULL) {
204
215
RegCloseKey(nhk);
213
224
DWORD namelen, datalen, type;
227
datalen = sizeof(data);
217
228
ret = RegEnumValue(nhk, i, name, &namelen, NULL, &type,
229
(LPBYTE) data, &datalen);
220
231
if (ret == ERROR_NO_MORE_ITEMS)
229
240
if (namelen >= 255)
230
241
namelen = 255 - 1;
231
name[namelen] = '\0';
242
name[namelen] = TEXT('\0');
233
244
if (datalen >= 1024)
234
245
datalen = 1024 - 1;
235
data[datalen] = '\0';
246
data[datalen] = TEXT('\0');
237
if (wpa_config_set(ssid, name, data, 0) < 0)
248
wpa_unicode2ascii_inplace(name);
249
wpa_unicode2ascii_inplace(data);
250
if (wpa_config_set(ssid, (char *) name, (char *) data, 0) < 0)
243
256
if (ssid->passphrase) {
244
257
if (ssid->psk_set) {
245
258
wpa_printf(MSG_ERROR, "Both PSK and passphrase "
246
"configured for network '%s'.", netw);
259
"configured for network '" TSTR "'.", netw);
249
262
wpa_config_update_psk(ssid);
252
265
if ((ssid->key_mgmt & WPA_KEY_MGMT_PSK) && !ssid->psk_set) {
253
266
wpa_printf(MSG_ERROR, "WPA-PSK accepted for key management, "
254
"but no PSK configured for network '%s'.", netw);
267
"but no PSK configured for network '" TSTR "'.",
261
275
/* Group cipher cannot be stronger than the pairwise cipher. */
262
276
wpa_printf(MSG_DEBUG, "Removed CCMP from group cipher "
263
277
"list since it was not allowed for pairwise "
264
"cipher for network '%s'.", netw);
278
"cipher for network '" TSTR "'.", netw);
265
279
ssid->group_cipher &= ~WPA_CIPHER_CCMP;
285
ret = RegOpenKeyEx(hk, "networks", 0, KEY_ENUMERATE_SUB_KEYS, &nhk);
299
ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_ENUMERATE_SUB_KEYS,
286
301
if (ret != ERROR_SUCCESS) {
287
302
wpa_printf(MSG_ERROR, "Could not open wpa_supplicant networks "
355
370
wpa_printf(MSG_DEBUG, "Reading configuration profile '%s'", name);
357
snprintf(buf, sizeof(buf), KEY_PREFIX "\\configs\\%s", name);
373
_snwprintf(buf, 256, KEY_PREFIX TEXT("\\configs\\%S"), name);
375
snprintf(buf, 256, KEY_PREFIX TEXT("\\configs\\%s"), name);
358
378
ret = RegOpenKeyEx(KEY_ROOT, buf, 0, KEY_QUERY_VALUE, &hk);
359
379
if (ret != ERROR_SUCCESS) {
360
380
wpa_printf(MSG_ERROR, "Could not open wpa_supplicant "
398
static int wpa_config_write_reg_dword(HKEY hk, const char *name, int val,
418
static int wpa_config_write_reg_dword(HKEY hk, const TCHAR *name, int val,
447
_name = wpa_strdup_tchar(name);
426
451
if (val == NULL) {
427
RegDeleteValue(hk, name);
452
RegDeleteValue(hk, _name);
431
ret = RegSetValueEx(hk, name, 0, REG_SZ, val, strlen(val) + 1);
457
_val = wpa_strdup_tchar(val);
462
ret = RegSetValueEx(hk, _name, 0, REG_SZ, (BYTE *) _val, (strlen(val) + 1) * sizeof(TCHAR));
432
463
if (ret != ERROR_SUCCESS) {
433
464
wpa_printf(MSG_ERROR, "WINREG: Failed to set %s='%s': "
434
465
"error %d", name, val, (int) GetLastError());
446
481
config->ctrl_interface);
447
482
#endif /* CONFIG_CTRL_IFACE */
449
wpa_config_write_reg_dword(hk, "eapol_version", config->eapol_version,
484
wpa_config_write_reg_dword(hk, TEXT("eapol_version"),
485
config->eapol_version,
450
486
DEFAULT_EAPOL_VERSION);
451
wpa_config_write_reg_dword(hk, "ap_scan", config->ap_scan,
487
wpa_config_write_reg_dword(hk, TEXT("ap_scan"), config->ap_scan,
452
488
DEFAULT_AP_SCAN);
453
wpa_config_write_reg_dword(hk, "fast_reauth", config->fast_reauth,
454
DEFAULT_FAST_REAUTH);
455
wpa_config_write_reg_dword(hk, "dot11RSNAConfigPMKLifetime",
489
wpa_config_write_reg_dword(hk, TEXT("fast_reauth"),
490
config->fast_reauth, DEFAULT_FAST_REAUTH);
491
wpa_config_write_reg_dword(hk, TEXT("dot11RSNAConfigPMKLifetime"),
456
492
config->dot11RSNAConfigPMKLifetime, 0);
457
wpa_config_write_reg_dword(hk, "dot11RSNAConfigPMKReauthThreshold",
493
wpa_config_write_reg_dword(hk,
494
TEXT("dot11RSNAConfigPMKReauthThreshold"),
458
495
config->dot11RSNAConfigPMKReauthThreshold,
460
wpa_config_write_reg_dword(hk, "dot11RSNAConfigSATimeout",
497
wpa_config_write_reg_dword(hk, TEXT("dot11RSNAConfigSATimeout"),
461
498
config->dot11RSNAConfigSATimeout, 0);
462
wpa_config_write_reg_dword(hk, "update_config", config->update_config,
499
wpa_config_write_reg_dword(hk, TEXT("update_config"),
500
config->update_config,
469
static int wpa_config_delete_subkeys(HKEY hk, const char *key)
507
static int wpa_config_delete_subkeys(HKEY hk, const TCHAR *key)
472
510
int i, errors = 0;
475
513
ret = RegOpenKeyEx(hk, key, 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &nhk);
476
514
if (ret != ERROR_SUCCESS) {
477
wpa_printf(MSG_DEBUG, "WINREG: Could not open key '%s' for "
478
"subkey deletion: error 0x%x (%d)", key,
515
wpa_printf(MSG_DEBUG, "WINREG: Could not open key '" TSTR
516
"' for subkey deletion: error 0x%x (%d)", key,
479
517
(unsigned int) ret, (int) GetLastError());
669
707
int i, errors = 0;
674
ret = RegOpenKeyEx(hk, "networks", 0, KEY_CREATE_SUB_KEY, &nhk);
712
ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_CREATE_SUB_KEY, &nhk);
675
713
if (ret != ERROR_SUCCESS) {
676
714
wpa_printf(MSG_DEBUG, "WINREG: Could not open networks key "
677
715
"for subkey addition: error 0x%x (%d)",
721
wsprintf(name, L"%04d", id);
682
723
snprintf(name, sizeof(name), "%04d", id);
683
725
ret = RegCreateKeyEx(nhk, name, 0, NULL, 0, KEY_WRITE, NULL, &netw,
685
727
RegCloseKey(nhk);
764
ret = RegCreateKeyEx(hk, "blobs", 0, NULL, 0, KEY_WRITE, NULL, &bhk,
810
ret = RegCreateKeyEx(hk, TEXT("blobs"), 0, NULL, 0, KEY_WRITE, NULL,
766
812
if (ret != ERROR_SUCCESS) {
767
813
wpa_printf(MSG_DEBUG, "WINREG: Could not add blobs key: "
768
814
"error 0x%x (%d)",
773
ret = RegSetValueEx(bhk, blob->name, 0, REG_BINARY, blob->data,
819
name = wpa_strdup_tchar(blob->name);
820
ret = RegSetValueEx(bhk, name, 0, REG_BINARY, blob->data,
775
822
if (ret != ERROR_SUCCESS) {
776
823
wpa_printf(MSG_ERROR, "WINREG: Failed to set blob %s': "
777
824
"error 0x%x (%d)", blob->name, (unsigned int) ret,
778
825
(int) GetLastError());
779
826
RegCloseKey(bhk);
783
832
RegCloseKey(bhk);
799
848
wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
801
snprintf(buf, sizeof(buf), KEY_PREFIX "\\configs\\%s", name);
851
_snwprintf(buf, 256, KEY_PREFIX TEXT("\\configs\\%S"), name);
853
snprintf(buf, 256, KEY_PREFIX TEXT("\\configs\\%s"), name);
802
856
ret = RegOpenKeyEx(KEY_ROOT, buf, 0, KEY_SET_VALUE | DELETE, &hk);
803
857
if (ret != ERROR_SUCCESS) {
804
858
wpa_printf(MSG_ERROR, "Could not open wpa_supplicant "
816
wpa_config_delete_subkeys(hk, "networks");
870
wpa_config_delete_subkeys(hk, TEXT("networks"));
817
871
for (ssid = config->ssid, id = 0; ssid; ssid = ssid->next, id++) {
818
872
if (wpa_config_write_network(hk, ssid, id))
822
RegDeleteKey(hk, "blobs");
876
RegDeleteKey(hk, TEXT("blobs"));
823
877
for (blob = config->blobs; blob; blob = blob->next) {
824
878
if (wpa_config_write_blob(hk, blob))