device/wifi: cleanup supplicant_iface_wps_credentials_cb()

Restructure code to return early and free resources with nm_auto.
This commit is contained in:
Thomas Haller 2019-08-22 11:02:59 +02:00
parent 81816ebffa
commit 7bf8c45b19

View file

@ -1755,10 +1755,11 @@ supplicant_iface_wps_credentials_cb (NMSupplicantInterface *iface,
NMDeviceWifi *self) NMDeviceWifi *self)
{ {
NMActRequest *req; NMActRequest *req;
GVariant *val, *secrets = NULL; gs_unref_variant GVariant *val_key = NULL;
gs_unref_variant GVariant *secrets = NULL;
gs_free_error GError *error = NULL;
const char *array; const char *array;
gsize psk_len = 0; gsize psk_len = 0;
GError *error = NULL;
if (nm_device_get_state (NM_DEVICE (self)) != NM_DEVICE_STATE_NEED_AUTH) { if (nm_device_get_state (NM_DEVICE (self)) != NM_DEVICE_STATE_NEED_AUTH) {
_LOGI (LOGD_DEVICE | LOGD_WIFI, "WPS: The connection can't be updated with credentials"); _LOGI (LOGD_DEVICE | LOGD_WIFI, "WPS: The connection can't be updated with credentials");
@ -1770,11 +1771,11 @@ supplicant_iface_wps_credentials_cb (NMSupplicantInterface *iface,
req = nm_device_get_act_request (NM_DEVICE (self)); req = nm_device_get_act_request (NM_DEVICE (self));
g_return_if_fail (NM_IS_ACT_REQUEST (req)); g_return_if_fail (NM_IS_ACT_REQUEST (req));
val = g_variant_lookup_value (credentials, "Key", G_VARIANT_TYPE_BYTESTRING); val_key = g_variant_lookup_value (credentials, "Key", G_VARIANT_TYPE_BYTESTRING);
if (val) { if (val_key) {
char psk[64]; char psk[64];
array = g_variant_get_fixed_array (val, &psk_len, 1); array = g_variant_get_fixed_array (val_key, &psk_len, 1);
if (psk_len >= 8 && psk_len <= 63) { if (psk_len >= 8 && psk_len <= 63) {
memcpy (psk, array, psk_len); memcpy (psk, array, psk_len);
psk[psk_len] = '\0'; psk[psk_len] = '\0';
@ -1787,22 +1788,22 @@ supplicant_iface_wps_credentials_cb (NMSupplicantInterface *iface,
} }
if (!secrets) if (!secrets)
_LOGW (LOGD_DEVICE | LOGD_WIFI, "WPS: ignore invalid PSK"); _LOGW (LOGD_DEVICE | LOGD_WIFI, "WPS: ignore invalid PSK");
g_variant_unref (val);
} }
if (secrets) {
if (nm_settings_connection_new_secrets (nm_act_request_get_settings_connection (req), if (!secrets)
nm_act_request_get_applied_connection (req), return;
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
secrets, if (!nm_settings_connection_new_secrets (nm_act_request_get_settings_connection (req),
&error)) { nm_act_request_get_applied_connection (req),
wifi_secrets_cancel (self); NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self)); secrets,
} else { &error)) {
_LOGW (LOGD_DEVICE | LOGD_WIFI, "WPS: Could not update the connection with credentials: %s", error->message); _LOGW (LOGD_DEVICE | LOGD_WIFI, "WPS: Could not update the connection with credentials: %s", error->message);
g_error_free (error); return;
}
g_variant_unref (secrets);
} }
wifi_secrets_cancel (self);
nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self));
} }
static gboolean static gboolean