Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant / Configuration backend: Windows registry |
| 3 | * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi> |
| 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | * |
| 8 | * This file implements a configuration backend for Windows registry. All the |
| 9 | * configuration information is stored in the registry and the format for |
| 10 | * network configuration fields is same as described in the sample |
| 11 | * configuration file, wpa_supplicant.conf. |
| 12 | * |
| 13 | * Configuration data is in |
| 14 | * \a HKEY_LOCAL_MACHINE\\SOFTWARE\\%wpa_supplicant\\configs |
| 15 | * key. Each configuration profile has its own key under this. In terms of text |
| 16 | * files, each profile would map to a separate text file with possibly multiple |
| 17 | * networks. Under each profile, there is a networks key that lists all |
| 18 | * networks as a subkey. Each network has set of values in the same way as |
| 19 | * network block in the configuration file. In addition, blobs subkey has |
| 20 | * possible blobs as values. |
| 21 | * |
| 22 | * Example network configuration block: |
| 23 | * \verbatim |
| 24 | HKEY_LOCAL_MACHINE\SOFTWARE\wpa_supplicant\configs\test\networks\0000 |
| 25 | ssid="example" |
| 26 | key_mgmt=WPA-PSK |
| 27 | \endverbatim |
| 28 | */ |
| 29 | |
| 30 | #include "includes.h" |
| 31 | |
| 32 | #include "common.h" |
| 33 | #include "uuid.h" |
| 34 | #include "config.h" |
| 35 | |
| 36 | #ifndef WPA_KEY_ROOT |
| 37 | #define WPA_KEY_ROOT HKEY_LOCAL_MACHINE |
| 38 | #endif |
| 39 | #ifndef WPA_KEY_PREFIX |
| 40 | #define WPA_KEY_PREFIX TEXT("SOFTWARE\\wpa_supplicant") |
| 41 | #endif |
| 42 | |
| 43 | #ifdef UNICODE |
| 44 | #define TSTR "%S" |
| 45 | #else /* UNICODE */ |
| 46 | #define TSTR "%s" |
| 47 | #endif /* UNICODE */ |
| 48 | |
| 49 | |
| 50 | static int wpa_config_read_blobs(struct wpa_config *config, HKEY hk) |
| 51 | { |
| 52 | struct wpa_config_blob *blob; |
| 53 | int errors = 0; |
| 54 | HKEY bhk; |
| 55 | LONG ret; |
| 56 | DWORD i; |
| 57 | |
| 58 | ret = RegOpenKeyEx(hk, TEXT("blobs"), 0, KEY_QUERY_VALUE, &bhk); |
| 59 | if (ret != ERROR_SUCCESS) { |
| 60 | wpa_printf(MSG_DEBUG, "Could not open wpa_supplicant config " |
| 61 | "blobs key"); |
| 62 | return 0; /* assume no blobs */ |
| 63 | } |
| 64 | |
| 65 | for (i = 0; ; i++) { |
| 66 | #define TNAMELEN 255 |
| 67 | TCHAR name[TNAMELEN]; |
| 68 | char data[4096]; |
| 69 | DWORD namelen, datalen, type; |
| 70 | |
| 71 | namelen = TNAMELEN; |
| 72 | datalen = sizeof(data); |
| 73 | ret = RegEnumValue(bhk, i, name, &namelen, NULL, &type, |
| 74 | (LPBYTE) data, &datalen); |
| 75 | |
| 76 | if (ret == ERROR_NO_MORE_ITEMS) |
| 77 | break; |
| 78 | |
| 79 | if (ret != ERROR_SUCCESS) { |
| 80 | wpa_printf(MSG_DEBUG, "RegEnumValue failed: 0x%x", |
| 81 | (unsigned int) ret); |
| 82 | break; |
| 83 | } |
| 84 | |
| 85 | if (namelen >= TNAMELEN) |
| 86 | namelen = TNAMELEN - 1; |
| 87 | name[namelen] = TEXT('\0'); |
| 88 | wpa_unicode2ascii_inplace(name); |
| 89 | |
| 90 | if (datalen >= sizeof(data)) |
| 91 | datalen = sizeof(data) - 1; |
| 92 | |
| 93 | wpa_printf(MSG_MSGDUMP, "blob %d: field='%s' len %d", |
| 94 | (int) i, name, (int) datalen); |
| 95 | |
| 96 | blob = os_zalloc(sizeof(*blob)); |
| 97 | if (blob == NULL) { |
| 98 | errors++; |
| 99 | break; |
| 100 | } |
| 101 | blob->name = os_strdup((char *) name); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 102 | blob->data = os_memdup(data, datalen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 103 | if (blob->name == NULL || blob->data == NULL) { |
| 104 | wpa_config_free_blob(blob); |
| 105 | errors++; |
| 106 | break; |
| 107 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 108 | blob->len = datalen; |
| 109 | |
| 110 | wpa_config_set_blob(config, blob); |
| 111 | } |
| 112 | |
| 113 | RegCloseKey(bhk); |
| 114 | |
| 115 | return errors ? -1 : 0; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | static int wpa_config_read_reg_dword(HKEY hk, const TCHAR *name, int *_val) |
| 120 | { |
| 121 | DWORD val, buflen; |
| 122 | LONG ret; |
| 123 | |
| 124 | buflen = sizeof(val); |
| 125 | ret = RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE) &val, &buflen); |
| 126 | if (ret == ERROR_SUCCESS && buflen == sizeof(val)) { |
| 127 | wpa_printf(MSG_DEBUG, TSTR "=%d", name, (int) val); |
| 128 | *_val = val; |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | return -1; |
| 133 | } |
| 134 | |
| 135 | |
| 136 | static char * wpa_config_read_reg_string(HKEY hk, const TCHAR *name) |
| 137 | { |
| 138 | DWORD buflen; |
| 139 | LONG ret; |
| 140 | TCHAR *val; |
| 141 | |
| 142 | buflen = 0; |
| 143 | ret = RegQueryValueEx(hk, name, NULL, NULL, NULL, &buflen); |
| 144 | if (ret != ERROR_SUCCESS) |
| 145 | return NULL; |
| 146 | val = os_malloc(buflen); |
| 147 | if (val == NULL) |
| 148 | return NULL; |
| 149 | |
| 150 | ret = RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE) val, &buflen); |
| 151 | if (ret != ERROR_SUCCESS) { |
| 152 | os_free(val); |
| 153 | return NULL; |
| 154 | } |
| 155 | |
| 156 | wpa_unicode2ascii_inplace(val); |
| 157 | wpa_printf(MSG_DEBUG, TSTR "=%s", name, (char *) val); |
| 158 | return (char *) val; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | #ifdef CONFIG_WPS |
| 163 | static int wpa_config_read_global_uuid(struct wpa_config *config, HKEY hk) |
| 164 | { |
| 165 | char *str; |
| 166 | int ret = 0; |
| 167 | |
| 168 | str = wpa_config_read_reg_string(hk, TEXT("uuid")); |
| 169 | if (str == NULL) |
| 170 | return 0; |
| 171 | |
| 172 | if (uuid_str2bin(str, config->uuid)) |
| 173 | ret = -1; |
| 174 | |
| 175 | os_free(str); |
| 176 | |
| 177 | return ret; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | static int wpa_config_read_global_os_version(struct wpa_config *config, |
| 182 | HKEY hk) |
| 183 | { |
| 184 | char *str; |
| 185 | int ret = 0; |
| 186 | |
| 187 | str = wpa_config_read_reg_string(hk, TEXT("os_version")); |
| 188 | if (str == NULL) |
| 189 | return 0; |
| 190 | |
| 191 | if (hexstr2bin(str, config->os_version, 4)) |
| 192 | ret = -1; |
| 193 | |
| 194 | os_free(str); |
| 195 | |
| 196 | return ret; |
| 197 | } |
| 198 | #endif /* CONFIG_WPS */ |
| 199 | |
| 200 | |
| 201 | static int wpa_config_read_global(struct wpa_config *config, HKEY hk) |
| 202 | { |
| 203 | int errors = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 204 | int val; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 205 | |
| 206 | wpa_config_read_reg_dword(hk, TEXT("ap_scan"), &config->ap_scan); |
| 207 | wpa_config_read_reg_dword(hk, TEXT("fast_reauth"), |
| 208 | &config->fast_reauth); |
| 209 | wpa_config_read_reg_dword(hk, TEXT("dot11RSNAConfigPMKLifetime"), |
| 210 | (int *) &config->dot11RSNAConfigPMKLifetime); |
| 211 | wpa_config_read_reg_dword(hk, |
| 212 | TEXT("dot11RSNAConfigPMKReauthThreshold"), |
| 213 | (int *) |
| 214 | &config->dot11RSNAConfigPMKReauthThreshold); |
| 215 | wpa_config_read_reg_dword(hk, TEXT("dot11RSNAConfigSATimeout"), |
| 216 | (int *) &config->dot11RSNAConfigSATimeout); |
| 217 | wpa_config_read_reg_dword(hk, TEXT("update_config"), |
| 218 | &config->update_config); |
| 219 | |
| 220 | if (wpa_config_read_reg_dword(hk, TEXT("eapol_version"), |
| 221 | &config->eapol_version) == 0) { |
| 222 | if (config->eapol_version < 1 || |
| 223 | config->eapol_version > 2) { |
| 224 | wpa_printf(MSG_ERROR, "Invalid EAPOL version (%d)", |
| 225 | config->eapol_version); |
| 226 | errors++; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | config->ctrl_interface = wpa_config_read_reg_string( |
| 231 | hk, TEXT("ctrl_interface")); |
| 232 | |
| 233 | #ifdef CONFIG_WPS |
| 234 | if (wpa_config_read_global_uuid(config, hk)) |
| 235 | errors++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 236 | wpa_config_read_reg_dword(hk, TEXT("auto_uuid"), &config->auto_uuid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 237 | config->device_name = wpa_config_read_reg_string( |
| 238 | hk, TEXT("device_name")); |
| 239 | config->manufacturer = wpa_config_read_reg_string( |
| 240 | hk, TEXT("manufacturer")); |
| 241 | config->model_name = wpa_config_read_reg_string( |
| 242 | hk, TEXT("model_name")); |
| 243 | config->serial_number = wpa_config_read_reg_string( |
| 244 | hk, TEXT("serial_number")); |
| 245 | { |
| 246 | char *t = wpa_config_read_reg_string( |
| 247 | hk, TEXT("device_type")); |
| 248 | if (t && wps_dev_type_str2bin(t, config->device_type)) |
| 249 | errors++; |
| 250 | os_free(t); |
| 251 | } |
| 252 | config->config_methods = wpa_config_read_reg_string( |
| 253 | hk, TEXT("config_methods")); |
| 254 | if (wpa_config_read_global_os_version(config, hk)) |
| 255 | errors++; |
| 256 | wpa_config_read_reg_dword(hk, TEXT("wps_cred_processing"), |
| 257 | &config->wps_cred_processing); |
| 258 | #endif /* CONFIG_WPS */ |
| 259 | #ifdef CONFIG_P2P |
| 260 | config->p2p_ssid_postfix = wpa_config_read_reg_string( |
| 261 | hk, TEXT("p2p_ssid_postfix")); |
| 262 | wpa_config_read_reg_dword(hk, TEXT("p2p_group_idle"), |
| 263 | (int *) &config->p2p_group_idle); |
| 264 | #endif /* CONFIG_P2P */ |
| 265 | |
| 266 | wpa_config_read_reg_dword(hk, TEXT("bss_max_count"), |
| 267 | (int *) &config->bss_max_count); |
| 268 | wpa_config_read_reg_dword(hk, TEXT("filter_ssids"), |
| 269 | &config->filter_ssids); |
| 270 | wpa_config_read_reg_dword(hk, TEXT("max_num_sta"), |
| 271 | (int *) &config->max_num_sta); |
| 272 | wpa_config_read_reg_dword(hk, TEXT("disassoc_low_ack"), |
| 273 | (int *) &config->disassoc_low_ack); |
| 274 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 275 | wpa_config_read_reg_dword(hk, TEXT("okc"), &config->okc); |
| 276 | wpa_config_read_reg_dword(hk, TEXT("pmf"), &val); |
| 277 | config->pmf = val; |
| 278 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 279 | return errors ? -1 : 0; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | static struct wpa_ssid * wpa_config_read_network(HKEY hk, const TCHAR *netw, |
| 284 | int id) |
| 285 | { |
| 286 | HKEY nhk; |
| 287 | LONG ret; |
| 288 | DWORD i; |
| 289 | struct wpa_ssid *ssid; |
| 290 | int errors = 0; |
| 291 | |
| 292 | ret = RegOpenKeyEx(hk, netw, 0, KEY_QUERY_VALUE, &nhk); |
| 293 | if (ret != ERROR_SUCCESS) { |
| 294 | wpa_printf(MSG_DEBUG, "Could not open wpa_supplicant config " |
| 295 | "network '" TSTR "'", netw); |
| 296 | return NULL; |
| 297 | } |
| 298 | |
| 299 | wpa_printf(MSG_MSGDUMP, "Start of a new network '" TSTR "'", netw); |
| 300 | ssid = os_zalloc(sizeof(*ssid)); |
| 301 | if (ssid == NULL) { |
| 302 | RegCloseKey(nhk); |
| 303 | return NULL; |
| 304 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 305 | dl_list_init(&ssid->psk_list); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 306 | ssid->id = id; |
| 307 | |
| 308 | wpa_config_set_network_defaults(ssid); |
| 309 | |
| 310 | for (i = 0; ; i++) { |
| 311 | TCHAR name[255], data[1024]; |
| 312 | DWORD namelen, datalen, type; |
| 313 | |
| 314 | namelen = 255; |
| 315 | datalen = sizeof(data); |
| 316 | ret = RegEnumValue(nhk, i, name, &namelen, NULL, &type, |
| 317 | (LPBYTE) data, &datalen); |
| 318 | |
| 319 | if (ret == ERROR_NO_MORE_ITEMS) |
| 320 | break; |
| 321 | |
| 322 | if (ret != ERROR_SUCCESS) { |
| 323 | wpa_printf(MSG_ERROR, "RegEnumValue failed: 0x%x", |
| 324 | (unsigned int) ret); |
| 325 | break; |
| 326 | } |
| 327 | |
| 328 | if (namelen >= 255) |
| 329 | namelen = 255 - 1; |
| 330 | name[namelen] = TEXT('\0'); |
| 331 | |
| 332 | if (datalen >= 1024) |
| 333 | datalen = 1024 - 1; |
| 334 | data[datalen] = TEXT('\0'); |
| 335 | |
| 336 | wpa_unicode2ascii_inplace(name); |
| 337 | wpa_unicode2ascii_inplace(data); |
| 338 | if (wpa_config_set(ssid, (char *) name, (char *) data, 0) < 0) |
| 339 | errors++; |
| 340 | } |
| 341 | |
| 342 | RegCloseKey(nhk); |
| 343 | |
| 344 | if (ssid->passphrase) { |
| 345 | if (ssid->psk_set) { |
| 346 | wpa_printf(MSG_ERROR, "Both PSK and passphrase " |
| 347 | "configured for network '" TSTR "'.", netw); |
| 348 | errors++; |
| 349 | } |
| 350 | wpa_config_update_psk(ssid); |
| 351 | } |
| 352 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 353 | if ((ssid->group_cipher & WPA_CIPHER_CCMP) && |
| 354 | !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) && |
| 355 | !(ssid->pairwise_cipher & WPA_CIPHER_NONE)) { |
| 356 | /* Group cipher cannot be stronger than the pairwise cipher. */ |
| 357 | wpa_printf(MSG_DEBUG, "Removed CCMP from group cipher " |
| 358 | "list since it was not allowed for pairwise " |
| 359 | "cipher for network '" TSTR "'.", netw); |
| 360 | ssid->group_cipher &= ~WPA_CIPHER_CCMP; |
| 361 | } |
| 362 | |
| 363 | if (errors) { |
| 364 | wpa_config_free_ssid(ssid); |
| 365 | ssid = NULL; |
| 366 | } |
| 367 | |
| 368 | return ssid; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | static int wpa_config_read_networks(struct wpa_config *config, HKEY hk) |
| 373 | { |
| 374 | HKEY nhk; |
| 375 | struct wpa_ssid *ssid, *tail = NULL, *head = NULL; |
| 376 | int errors = 0; |
| 377 | LONG ret; |
| 378 | DWORD i; |
| 379 | |
| 380 | ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_ENUMERATE_SUB_KEYS, |
| 381 | &nhk); |
| 382 | if (ret != ERROR_SUCCESS) { |
| 383 | wpa_printf(MSG_ERROR, "Could not open wpa_supplicant networks " |
| 384 | "registry key"); |
| 385 | return -1; |
| 386 | } |
| 387 | |
| 388 | for (i = 0; ; i++) { |
| 389 | TCHAR name[255]; |
| 390 | DWORD namelen; |
| 391 | |
| 392 | namelen = 255; |
| 393 | ret = RegEnumKeyEx(nhk, i, name, &namelen, NULL, NULL, NULL, |
| 394 | NULL); |
| 395 | |
| 396 | if (ret == ERROR_NO_MORE_ITEMS) |
| 397 | break; |
| 398 | |
| 399 | if (ret != ERROR_SUCCESS) { |
| 400 | wpa_printf(MSG_DEBUG, "RegEnumKeyEx failed: 0x%x", |
| 401 | (unsigned int) ret); |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | if (namelen >= 255) |
| 406 | namelen = 255 - 1; |
| 407 | name[namelen] = '\0'; |
| 408 | |
| 409 | ssid = wpa_config_read_network(nhk, name, i); |
| 410 | if (ssid == NULL) { |
| 411 | wpa_printf(MSG_ERROR, "Failed to parse network " |
| 412 | "profile '%s'.", name); |
| 413 | errors++; |
| 414 | continue; |
| 415 | } |
| 416 | if (head == NULL) { |
| 417 | head = tail = ssid; |
| 418 | } else { |
| 419 | tail->next = ssid; |
| 420 | tail = ssid; |
| 421 | } |
| 422 | if (wpa_config_add_prio_network(config, ssid)) { |
| 423 | wpa_printf(MSG_ERROR, "Failed to add network profile " |
| 424 | "'%s' to priority list.", name); |
| 425 | errors++; |
| 426 | continue; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | RegCloseKey(nhk); |
| 431 | |
| 432 | config->ssid = head; |
| 433 | |
| 434 | return errors ? -1 : 0; |
| 435 | } |
| 436 | |
| 437 | |
Dmitry Shmidt | 64f47c5 | 2013-04-16 10:41:54 -0700 | [diff] [blame] | 438 | struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 439 | { |
| 440 | TCHAR buf[256]; |
| 441 | int errors = 0; |
| 442 | struct wpa_config *config; |
| 443 | HKEY hk; |
| 444 | LONG ret; |
| 445 | |
Dmitry Shmidt | 64f47c5 | 2013-04-16 10:41:54 -0700 | [diff] [blame] | 446 | if (name == NULL) |
| 447 | return NULL; |
| 448 | if (cfgp) |
| 449 | config = cfgp; |
| 450 | else |
| 451 | config = wpa_config_alloc_empty(NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 452 | if (config == NULL) |
| 453 | return NULL; |
| 454 | wpa_printf(MSG_DEBUG, "Reading configuration profile '%s'", name); |
| 455 | |
| 456 | #ifdef UNICODE |
| 457 | _snwprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%S"), name); |
| 458 | #else /* UNICODE */ |
| 459 | os_snprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%s"), name); |
| 460 | #endif /* UNICODE */ |
| 461 | |
| 462 | ret = RegOpenKeyEx(WPA_KEY_ROOT, buf, 0, KEY_QUERY_VALUE, &hk); |
| 463 | if (ret != ERROR_SUCCESS) { |
| 464 | wpa_printf(MSG_ERROR, "Could not open wpa_supplicant " |
| 465 | "configuration registry HKLM\\" TSTR, buf); |
| 466 | os_free(config); |
| 467 | return NULL; |
| 468 | } |
| 469 | |
| 470 | if (wpa_config_read_global(config, hk)) |
| 471 | errors++; |
| 472 | |
| 473 | if (wpa_config_read_networks(config, hk)) |
| 474 | errors++; |
| 475 | |
| 476 | if (wpa_config_read_blobs(config, hk)) |
| 477 | errors++; |
| 478 | |
| 479 | wpa_config_debug_dump_networks(config); |
| 480 | |
| 481 | RegCloseKey(hk); |
| 482 | |
| 483 | if (errors) { |
| 484 | wpa_config_free(config); |
| 485 | config = NULL; |
| 486 | } |
| 487 | |
| 488 | return config; |
| 489 | } |
| 490 | |
| 491 | |
| 492 | static int wpa_config_write_reg_dword(HKEY hk, const TCHAR *name, int val, |
| 493 | int def) |
| 494 | { |
| 495 | LONG ret; |
| 496 | DWORD _val = val; |
| 497 | |
| 498 | if (val == def) { |
| 499 | RegDeleteValue(hk, name); |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | ret = RegSetValueEx(hk, name, 0, REG_DWORD, (LPBYTE) &_val, |
| 504 | sizeof(_val)); |
| 505 | if (ret != ERROR_SUCCESS) { |
| 506 | wpa_printf(MSG_ERROR, "WINREG: Failed to set %s=%d: error %d", |
| 507 | name, val, (int) GetLastError()); |
| 508 | return -1; |
| 509 | } |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | |
| 515 | static int wpa_config_write_reg_string(HKEY hk, const char *name, |
| 516 | const char *val) |
| 517 | { |
| 518 | LONG ret; |
| 519 | TCHAR *_name, *_val; |
| 520 | |
| 521 | _name = wpa_strdup_tchar(name); |
| 522 | if (_name == NULL) |
| 523 | return -1; |
| 524 | |
| 525 | if (val == NULL) { |
| 526 | RegDeleteValue(hk, _name); |
| 527 | os_free(_name); |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | _val = wpa_strdup_tchar(val); |
| 532 | if (_val == NULL) { |
| 533 | os_free(_name); |
| 534 | return -1; |
| 535 | } |
| 536 | ret = RegSetValueEx(hk, _name, 0, REG_SZ, (BYTE *) _val, |
| 537 | (os_strlen(val) + 1) * sizeof(TCHAR)); |
| 538 | if (ret != ERROR_SUCCESS) { |
| 539 | wpa_printf(MSG_ERROR, "WINREG: Failed to set %s='%s': " |
| 540 | "error %d", name, val, (int) GetLastError()); |
| 541 | os_free(_name); |
| 542 | os_free(_val); |
| 543 | return -1; |
| 544 | } |
| 545 | |
| 546 | os_free(_name); |
| 547 | os_free(_val); |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | |
| 552 | static int wpa_config_write_global(struct wpa_config *config, HKEY hk) |
| 553 | { |
| 554 | #ifdef CONFIG_CTRL_IFACE |
| 555 | wpa_config_write_reg_string(hk, "ctrl_interface", |
| 556 | config->ctrl_interface); |
| 557 | #endif /* CONFIG_CTRL_IFACE */ |
| 558 | |
| 559 | wpa_config_write_reg_dword(hk, TEXT("eapol_version"), |
| 560 | config->eapol_version, |
| 561 | DEFAULT_EAPOL_VERSION); |
| 562 | wpa_config_write_reg_dword(hk, TEXT("ap_scan"), config->ap_scan, |
| 563 | DEFAULT_AP_SCAN); |
| 564 | wpa_config_write_reg_dword(hk, TEXT("fast_reauth"), |
| 565 | config->fast_reauth, DEFAULT_FAST_REAUTH); |
| 566 | wpa_config_write_reg_dword(hk, TEXT("dot11RSNAConfigPMKLifetime"), |
| 567 | config->dot11RSNAConfigPMKLifetime, 0); |
| 568 | wpa_config_write_reg_dword(hk, |
| 569 | TEXT("dot11RSNAConfigPMKReauthThreshold"), |
| 570 | config->dot11RSNAConfigPMKReauthThreshold, |
| 571 | 0); |
| 572 | wpa_config_write_reg_dword(hk, TEXT("dot11RSNAConfigSATimeout"), |
| 573 | config->dot11RSNAConfigSATimeout, 0); |
| 574 | wpa_config_write_reg_dword(hk, TEXT("update_config"), |
| 575 | config->update_config, |
| 576 | 0); |
| 577 | #ifdef CONFIG_WPS |
| 578 | if (!is_nil_uuid(config->uuid)) { |
| 579 | char buf[40]; |
| 580 | uuid_bin2str(config->uuid, buf, sizeof(buf)); |
| 581 | wpa_config_write_reg_string(hk, "uuid", buf); |
| 582 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 583 | wpa_config_write_reg_dword(hk, TEXT("auto_uuid"), config->auto_uuid, |
| 584 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 585 | wpa_config_write_reg_string(hk, "device_name", config->device_name); |
| 586 | wpa_config_write_reg_string(hk, "manufacturer", config->manufacturer); |
| 587 | wpa_config_write_reg_string(hk, "model_name", config->model_name); |
| 588 | wpa_config_write_reg_string(hk, "model_number", config->model_number); |
| 589 | wpa_config_write_reg_string(hk, "serial_number", |
| 590 | config->serial_number); |
| 591 | { |
| 592 | char _buf[WPS_DEV_TYPE_BUFSIZE], *buf; |
| 593 | buf = wps_dev_type_bin2str(config->device_type, |
| 594 | _buf, sizeof(_buf)); |
| 595 | wpa_config_write_reg_string(hk, "device_type", buf); |
| 596 | } |
| 597 | wpa_config_write_reg_string(hk, "config_methods", |
| 598 | config->config_methods); |
| 599 | if (WPA_GET_BE32(config->os_version)) { |
| 600 | char vbuf[10]; |
| 601 | os_snprintf(vbuf, sizeof(vbuf), "%08x", |
| 602 | WPA_GET_BE32(config->os_version)); |
| 603 | wpa_config_write_reg_string(hk, "os_version", vbuf); |
| 604 | } |
| 605 | wpa_config_write_reg_dword(hk, TEXT("wps_cred_processing"), |
| 606 | config->wps_cred_processing, 0); |
| 607 | #endif /* CONFIG_WPS */ |
| 608 | #ifdef CONFIG_P2P |
| 609 | wpa_config_write_reg_string(hk, "p2p_ssid_postfix", |
| 610 | config->p2p_ssid_postfix); |
| 611 | wpa_config_write_reg_dword(hk, TEXT("p2p_group_idle"), |
| 612 | config->p2p_group_idle, 0); |
| 613 | #endif /* CONFIG_P2P */ |
| 614 | |
| 615 | wpa_config_write_reg_dword(hk, TEXT("bss_max_count"), |
| 616 | config->bss_max_count, |
| 617 | DEFAULT_BSS_MAX_COUNT); |
| 618 | wpa_config_write_reg_dword(hk, TEXT("filter_ssids"), |
| 619 | config->filter_ssids, 0); |
| 620 | wpa_config_write_reg_dword(hk, TEXT("max_num_sta"), |
| 621 | config->max_num_sta, DEFAULT_MAX_NUM_STA); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame^] | 622 | wpa_config_write_reg_dword(hk, TEXT("ap_isolate"), |
| 623 | config->ap_isolate, DEFAULT_AP_ISOLATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 624 | wpa_config_write_reg_dword(hk, TEXT("disassoc_low_ack"), |
| 625 | config->disassoc_low_ack, 0); |
| 626 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 627 | wpa_config_write_reg_dword(hk, TEXT("okc"), config->okc, 0); |
| 628 | wpa_config_write_reg_dword(hk, TEXT("pmf"), config->pmf, 0); |
| 629 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 630 | wpa_config_write_reg_dword(hk, TEXT("external_sim"), |
| 631 | config->external_sim, 0); |
| 632 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | |
| 637 | static int wpa_config_delete_subkeys(HKEY hk, const TCHAR *key) |
| 638 | { |
| 639 | HKEY nhk; |
| 640 | int i, errors = 0; |
| 641 | LONG ret; |
| 642 | |
| 643 | ret = RegOpenKeyEx(hk, key, 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &nhk); |
| 644 | if (ret != ERROR_SUCCESS) { |
| 645 | wpa_printf(MSG_DEBUG, "WINREG: Could not open key '" TSTR |
| 646 | "' for subkey deletion: error 0x%x (%d)", key, |
| 647 | (unsigned int) ret, (int) GetLastError()); |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | for (i = 0; ; i++) { |
| 652 | TCHAR name[255]; |
| 653 | DWORD namelen; |
| 654 | |
| 655 | namelen = 255; |
| 656 | ret = RegEnumKeyEx(nhk, i, name, &namelen, NULL, NULL, NULL, |
| 657 | NULL); |
| 658 | |
| 659 | if (ret == ERROR_NO_MORE_ITEMS) |
| 660 | break; |
| 661 | |
| 662 | if (ret != ERROR_SUCCESS) { |
| 663 | wpa_printf(MSG_DEBUG, "RegEnumKeyEx failed: 0x%x (%d)", |
| 664 | (unsigned int) ret, (int) GetLastError()); |
| 665 | break; |
| 666 | } |
| 667 | |
| 668 | if (namelen >= 255) |
| 669 | namelen = 255 - 1; |
| 670 | name[namelen] = TEXT('\0'); |
| 671 | |
| 672 | ret = RegDeleteKey(nhk, name); |
| 673 | if (ret != ERROR_SUCCESS) { |
| 674 | wpa_printf(MSG_DEBUG, "RegDeleteKey failed: 0x%x (%d)", |
| 675 | (unsigned int) ret, (int) GetLastError()); |
| 676 | errors++; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | RegCloseKey(nhk); |
| 681 | |
| 682 | return errors ? -1 : 0; |
| 683 | } |
| 684 | |
| 685 | |
| 686 | static void write_str(HKEY hk, const char *field, struct wpa_ssid *ssid) |
| 687 | { |
| 688 | char *value = wpa_config_get(ssid, field); |
| 689 | if (value == NULL) |
| 690 | return; |
| 691 | wpa_config_write_reg_string(hk, field, value); |
| 692 | os_free(value); |
| 693 | } |
| 694 | |
| 695 | |
| 696 | static void write_int(HKEY hk, const char *field, int value, int def) |
| 697 | { |
| 698 | char val[20]; |
| 699 | if (value == def) |
| 700 | return; |
| 701 | os_snprintf(val, sizeof(val), "%d", value); |
| 702 | wpa_config_write_reg_string(hk, field, val); |
| 703 | } |
| 704 | |
| 705 | |
| 706 | static void write_bssid(HKEY hk, struct wpa_ssid *ssid) |
| 707 | { |
| 708 | char *value = wpa_config_get(ssid, "bssid"); |
| 709 | if (value == NULL) |
| 710 | return; |
| 711 | wpa_config_write_reg_string(hk, "bssid", value); |
| 712 | os_free(value); |
| 713 | } |
| 714 | |
| 715 | |
| 716 | static void write_psk(HKEY hk, struct wpa_ssid *ssid) |
| 717 | { |
| 718 | char *value = wpa_config_get(ssid, "psk"); |
| 719 | if (value == NULL) |
| 720 | return; |
| 721 | wpa_config_write_reg_string(hk, "psk", value); |
| 722 | os_free(value); |
| 723 | } |
| 724 | |
| 725 | |
| 726 | static void write_proto(HKEY hk, struct wpa_ssid *ssid) |
| 727 | { |
| 728 | char *value; |
| 729 | |
| 730 | if (ssid->proto == DEFAULT_PROTO) |
| 731 | return; |
| 732 | |
| 733 | value = wpa_config_get(ssid, "proto"); |
| 734 | if (value == NULL) |
| 735 | return; |
| 736 | if (value[0]) |
| 737 | wpa_config_write_reg_string(hk, "proto", value); |
| 738 | os_free(value); |
| 739 | } |
| 740 | |
| 741 | |
| 742 | static void write_key_mgmt(HKEY hk, struct wpa_ssid *ssid) |
| 743 | { |
| 744 | char *value; |
| 745 | |
| 746 | if (ssid->key_mgmt == DEFAULT_KEY_MGMT) |
| 747 | return; |
| 748 | |
| 749 | value = wpa_config_get(ssid, "key_mgmt"); |
| 750 | if (value == NULL) |
| 751 | return; |
| 752 | if (value[0]) |
| 753 | wpa_config_write_reg_string(hk, "key_mgmt", value); |
| 754 | os_free(value); |
| 755 | } |
| 756 | |
| 757 | |
| 758 | static void write_pairwise(HKEY hk, struct wpa_ssid *ssid) |
| 759 | { |
| 760 | char *value; |
| 761 | |
| 762 | if (ssid->pairwise_cipher == DEFAULT_PAIRWISE) |
| 763 | return; |
| 764 | |
| 765 | value = wpa_config_get(ssid, "pairwise"); |
| 766 | if (value == NULL) |
| 767 | return; |
| 768 | if (value[0]) |
| 769 | wpa_config_write_reg_string(hk, "pairwise", value); |
| 770 | os_free(value); |
| 771 | } |
| 772 | |
| 773 | |
| 774 | static void write_group(HKEY hk, struct wpa_ssid *ssid) |
| 775 | { |
| 776 | char *value; |
| 777 | |
| 778 | if (ssid->group_cipher == DEFAULT_GROUP) |
| 779 | return; |
| 780 | |
| 781 | value = wpa_config_get(ssid, "group"); |
| 782 | if (value == NULL) |
| 783 | return; |
| 784 | if (value[0]) |
| 785 | wpa_config_write_reg_string(hk, "group", value); |
| 786 | os_free(value); |
| 787 | } |
| 788 | |
| 789 | |
| 790 | static void write_auth_alg(HKEY hk, struct wpa_ssid *ssid) |
| 791 | { |
| 792 | char *value; |
| 793 | |
| 794 | if (ssid->auth_alg == 0) |
| 795 | return; |
| 796 | |
| 797 | value = wpa_config_get(ssid, "auth_alg"); |
| 798 | if (value == NULL) |
| 799 | return; |
| 800 | if (value[0]) |
| 801 | wpa_config_write_reg_string(hk, "auth_alg", value); |
| 802 | os_free(value); |
| 803 | } |
| 804 | |
| 805 | |
| 806 | #ifdef IEEE8021X_EAPOL |
| 807 | static void write_eap(HKEY hk, struct wpa_ssid *ssid) |
| 808 | { |
| 809 | char *value; |
| 810 | |
| 811 | value = wpa_config_get(ssid, "eap"); |
| 812 | if (value == NULL) |
| 813 | return; |
| 814 | |
| 815 | if (value[0]) |
| 816 | wpa_config_write_reg_string(hk, "eap", value); |
| 817 | os_free(value); |
| 818 | } |
| 819 | #endif /* IEEE8021X_EAPOL */ |
| 820 | |
| 821 | |
| 822 | static void write_wep_key(HKEY hk, int idx, struct wpa_ssid *ssid) |
| 823 | { |
| 824 | char field[20], *value; |
| 825 | |
| 826 | os_snprintf(field, sizeof(field), "wep_key%d", idx); |
| 827 | value = wpa_config_get(ssid, field); |
| 828 | if (value) { |
| 829 | wpa_config_write_reg_string(hk, field, value); |
| 830 | os_free(value); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | |
| 835 | static int wpa_config_write_network(HKEY hk, struct wpa_ssid *ssid, int id) |
| 836 | { |
| 837 | int i, errors = 0; |
| 838 | HKEY nhk, netw; |
| 839 | LONG ret; |
| 840 | TCHAR name[5]; |
| 841 | |
| 842 | ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_CREATE_SUB_KEY, &nhk); |
| 843 | if (ret != ERROR_SUCCESS) { |
| 844 | wpa_printf(MSG_DEBUG, "WINREG: Could not open networks key " |
| 845 | "for subkey addition: error 0x%x (%d)", |
| 846 | (unsigned int) ret, (int) GetLastError()); |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | #ifdef UNICODE |
| 851 | wsprintf(name, L"%04d", id); |
| 852 | #else /* UNICODE */ |
| 853 | os_snprintf(name, sizeof(name), "%04d", id); |
| 854 | #endif /* UNICODE */ |
| 855 | ret = RegCreateKeyEx(nhk, name, 0, NULL, 0, KEY_WRITE, NULL, &netw, |
| 856 | NULL); |
| 857 | RegCloseKey(nhk); |
| 858 | if (ret != ERROR_SUCCESS) { |
| 859 | wpa_printf(MSG_DEBUG, "WINREG: Could not add network key '%s':" |
| 860 | " error 0x%x (%d)", |
| 861 | name, (unsigned int) ret, (int) GetLastError()); |
| 862 | return -1; |
| 863 | } |
| 864 | |
| 865 | #define STR(t) write_str(netw, #t, ssid) |
| 866 | #define INT(t) write_int(netw, #t, ssid->t, 0) |
| 867 | #define INTe(t) write_int(netw, #t, ssid->eap.t, 0) |
| 868 | #define INT_DEF(t, def) write_int(netw, #t, ssid->t, def) |
| 869 | #define INT_DEFe(t, def) write_int(netw, #t, ssid->eap.t, def) |
| 870 | |
| 871 | STR(ssid); |
| 872 | INT(scan_ssid); |
| 873 | write_bssid(netw, ssid); |
| 874 | write_psk(netw, ssid); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 875 | STR(sae_password); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame^] | 876 | STR(sae_password_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 877 | write_proto(netw, ssid); |
| 878 | write_key_mgmt(netw, ssid); |
| 879 | write_pairwise(netw, ssid); |
| 880 | write_group(netw, ssid); |
| 881 | write_auth_alg(netw, ssid); |
| 882 | #ifdef IEEE8021X_EAPOL |
| 883 | write_eap(netw, ssid); |
| 884 | STR(identity); |
| 885 | STR(anonymous_identity); |
Jouni Malinen | a3cb6f0 | 2017-12-08 17:05:40 +0200 | [diff] [blame] | 886 | STR(imsi_identity); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 887 | STR(password); |
| 888 | STR(ca_cert); |
| 889 | STR(ca_path); |
| 890 | STR(client_cert); |
| 891 | STR(private_key); |
| 892 | STR(private_key_passwd); |
| 893 | STR(dh_file); |
| 894 | STR(subject_match); |
| 895 | STR(altsubject_match); |
| 896 | STR(ca_cert2); |
| 897 | STR(ca_path2); |
| 898 | STR(client_cert2); |
| 899 | STR(private_key2); |
| 900 | STR(private_key2_passwd); |
| 901 | STR(dh_file2); |
| 902 | STR(subject_match2); |
| 903 | STR(altsubject_match2); |
| 904 | STR(phase1); |
| 905 | STR(phase2); |
| 906 | STR(pcsc); |
| 907 | STR(pin); |
| 908 | STR(engine_id); |
| 909 | STR(key_id); |
| 910 | STR(cert_id); |
| 911 | STR(ca_cert_id); |
| 912 | STR(key2_id); |
| 913 | STR(pin2); |
| 914 | STR(engine2_id); |
| 915 | STR(cert2_id); |
| 916 | STR(ca_cert2_id); |
| 917 | INTe(engine); |
| 918 | INTe(engine2); |
| 919 | INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS); |
| 920 | #endif /* IEEE8021X_EAPOL */ |
| 921 | for (i = 0; i < 4; i++) |
| 922 | write_wep_key(netw, i, ssid); |
| 923 | INT(wep_tx_keyidx); |
| 924 | INT(priority); |
| 925 | #ifdef IEEE8021X_EAPOL |
| 926 | INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND); |
| 927 | STR(pac_file); |
| 928 | INT_DEFe(fragment_size, DEFAULT_FRAGMENT_SIZE); |
| 929 | #endif /* IEEE8021X_EAPOL */ |
| 930 | INT(mode); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 931 | write_int(netw, "proactive_key_caching", ssid->proactive_key_caching, |
| 932 | -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 933 | INT(disabled); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 934 | #ifdef CONFIG_IEEE80211W |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 935 | write_int(netw, "ieee80211w", ssid->ieee80211w, |
| 936 | MGMT_FRAME_PROTECTION_DEFAULT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 937 | #endif /* CONFIG_IEEE80211W */ |
| 938 | STR(id_str); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 939 | #ifdef CONFIG_HS20 |
| 940 | INT(update_identifier); |
| 941 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 942 | INT(group_rekey); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 943 | |
| 944 | #undef STR |
| 945 | #undef INT |
| 946 | #undef INT_DEF |
| 947 | |
| 948 | RegCloseKey(netw); |
| 949 | |
| 950 | return errors ? -1 : 0; |
| 951 | } |
| 952 | |
| 953 | |
| 954 | static int wpa_config_write_blob(HKEY hk, struct wpa_config_blob *blob) |
| 955 | { |
| 956 | HKEY bhk; |
| 957 | LONG ret; |
| 958 | TCHAR *name; |
| 959 | |
| 960 | ret = RegCreateKeyEx(hk, TEXT("blobs"), 0, NULL, 0, KEY_WRITE, NULL, |
| 961 | &bhk, NULL); |
| 962 | if (ret != ERROR_SUCCESS) { |
| 963 | wpa_printf(MSG_DEBUG, "WINREG: Could not add blobs key: " |
| 964 | "error 0x%x (%d)", |
| 965 | (unsigned int) ret, (int) GetLastError()); |
| 966 | return -1; |
| 967 | } |
| 968 | |
| 969 | name = wpa_strdup_tchar(blob->name); |
| 970 | ret = RegSetValueEx(bhk, name, 0, REG_BINARY, blob->data, |
| 971 | blob->len); |
| 972 | if (ret != ERROR_SUCCESS) { |
| 973 | wpa_printf(MSG_ERROR, "WINREG: Failed to set blob %s': " |
| 974 | "error 0x%x (%d)", blob->name, (unsigned int) ret, |
| 975 | (int) GetLastError()); |
| 976 | RegCloseKey(bhk); |
| 977 | os_free(name); |
| 978 | return -1; |
| 979 | } |
| 980 | os_free(name); |
| 981 | |
| 982 | RegCloseKey(bhk); |
| 983 | |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | |
| 988 | int wpa_config_write(const char *name, struct wpa_config *config) |
| 989 | { |
| 990 | TCHAR buf[256]; |
| 991 | HKEY hk; |
| 992 | LONG ret; |
| 993 | int errors = 0; |
| 994 | struct wpa_ssid *ssid; |
| 995 | struct wpa_config_blob *blob; |
| 996 | int id; |
| 997 | |
| 998 | wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name); |
| 999 | |
| 1000 | #ifdef UNICODE |
| 1001 | _snwprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%S"), name); |
| 1002 | #else /* UNICODE */ |
| 1003 | os_snprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%s"), name); |
| 1004 | #endif /* UNICODE */ |
| 1005 | |
| 1006 | ret = RegOpenKeyEx(WPA_KEY_ROOT, buf, 0, KEY_SET_VALUE | DELETE, &hk); |
| 1007 | if (ret != ERROR_SUCCESS) { |
| 1008 | wpa_printf(MSG_ERROR, "Could not open wpa_supplicant " |
| 1009 | "configuration registry %s: error %d", buf, |
| 1010 | (int) GetLastError()); |
| 1011 | return -1; |
| 1012 | } |
| 1013 | |
| 1014 | if (wpa_config_write_global(config, hk)) { |
| 1015 | wpa_printf(MSG_ERROR, "Failed to write global configuration " |
| 1016 | "data"); |
| 1017 | errors++; |
| 1018 | } |
| 1019 | |
| 1020 | wpa_config_delete_subkeys(hk, TEXT("networks")); |
| 1021 | for (ssid = config->ssid, id = 0; ssid; ssid = ssid->next, id++) { |
| 1022 | if (ssid->key_mgmt == WPA_KEY_MGMT_WPS) |
| 1023 | continue; /* do not save temporary WPS networks */ |
| 1024 | if (wpa_config_write_network(hk, ssid, id)) |
| 1025 | errors++; |
| 1026 | } |
| 1027 | |
| 1028 | RegDeleteKey(hk, TEXT("blobs")); |
| 1029 | for (blob = config->blobs; blob; blob = blob->next) { |
| 1030 | if (wpa_config_write_blob(hk, blob)) |
| 1031 | errors++; |
| 1032 | } |
| 1033 | |
| 1034 | RegCloseKey(hk); |
| 1035 | |
| 1036 | wpa_printf(MSG_DEBUG, "Configuration '%s' written %ssuccessfully", |
| 1037 | name, errors ? "un" : ""); |
| 1038 | return errors ? -1 : 0; |
| 1039 | } |