network: Fix syncing the PSK on 1st connection

The previous change did not consider the case of the PSK being written
for the very first time.  In this case storage_network_open would return
NULL and an empty file would be written.

Change this so that if storage_network_open fails, then the current
network settings are written to disk and not a temporary.
This commit is contained in:
Denis Kenzior 2018-08-10 11:42:31 -05:00
parent cb24b622ae
commit c38b77d0c0
1 changed files with 12 additions and 5 deletions

View File

@ -434,15 +434,22 @@ void network_sync_psk(struct network *network)
network->update_psk = false;
fs_settings = storage_network_open(SECURITY_PSK, network->info->ssid);
hex = l_util_hexstring(network->psk, 32);
l_settings_set_value(network->settings, "Security",
"PreSharedKey", hex);
l_settings_set_value(fs_settings, "Security", "PreSharedKey", hex);
l_free(hex);
storage_network_sync(SECURITY_PSK, network->info->ssid, fs_settings);
l_settings_free(fs_settings);
fs_settings = storage_network_open(SECURITY_PSK, network->info->ssid);
if (fs_settings) {
l_settings_set_value(fs_settings, "Security",
"PreSharedKey", hex);
storage_network_sync(SECURITY_PSK, network->info->ssid,
fs_settings);
l_settings_free(fs_settings);
} else
storage_network_sync(SECURITY_PSK, network->info->ssid,
network->settings);
l_free(hex);
}
int network_autoconnect(struct network *network, struct scan_bss *bss)