]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
HS 2.0: Remove temporary network block on cred block removal
authorJouni Malinen <jouni@qca.qualcomm.com>
Thu, 22 Nov 2012 15:53:27 +0000 (17:53 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 24 Nov 2012 10:24:34 +0000 (12:24 +0200)
If the credential that was used to create a temporary HS 2.0 network
block is removed, remove the network block, too.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

wpa_supplicant/config_ssid.h
wpa_supplicant/ctrl_iface.c
wpa_supplicant/interworking.c

index 2d4d91453f266f8725eb53a15434c9eb655ba5c7..99f37663b69498f9aee831cb6393434e9a57473c 100644 (file)
@@ -542,6 +542,15 @@ struct wpa_ssid {
         * disabled_until - Network block disabled until this time if non-zero
         */
        struct os_time disabled_until;
+
+       /**
+        * parent_cred - Pointer to parent wpa_cred entry
+        *
+        * This pointer can be used to delete temporary networks when a wpa_cred
+        * that was used to create them is removed. This pointer should not be
+        * dereferences since it may not be updated in all cases.
+        */
+       void *parent_cred;
 };
 
 #endif /* CONFIG_SSID_H */
index 4b480cf39f5d10e97aa12a4a29d1dc936b58e8cb..85f18e456f5ab76ac1002eae23333a8f25097fbb 100644 (file)
@@ -2306,20 +2306,48 @@ static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
 }
 
 
+static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
+                                struct wpa_cred *cred)
+{
+       struct wpa_ssid *ssid;
+       char str[20];
+
+       if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
+               wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
+               return -1;
+       }
+
+       /* Remove any network entry created based on the removed credential */
+       ssid = wpa_s->conf->ssid;
+       while (ssid) {
+               if (ssid->parent_cred == cred) {
+                       wpa_printf(MSG_DEBUG, "Remove network id %d since it "
+                                  "used the removed credential", ssid->id);
+                       os_snprintf(str, sizeof(str), "%d", ssid->id);
+                       ssid = ssid->next;
+                       wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
+               } else
+                       ssid = ssid->next;
+       }
+
+       return 0;
+}
+
+
 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
                                                 char *cmd)
 {
        int id;
-       struct wpa_cred *cred;
+       struct wpa_cred *cred, *prev;
 
        /* cmd: "<cred id>" or "all" */
        if (os_strcmp(cmd, "all") == 0) {
                wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
                cred = wpa_s->conf->cred;
                while (cred) {
-                       id = cred->id;
+                       prev = cred;
                        cred = cred->next;
-                       wpa_config_remove_cred(wpa_s->conf, id);
+                       wpas_ctrl_remove_cred(wpa_s, prev);
                }
                return 0;
        }
@@ -2328,14 +2356,7 @@ static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
        wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
 
        cred = wpa_config_get_cred(wpa_s->conf, id);
-       if (cred == NULL ||
-           wpa_config_remove_cred(wpa_s->conf, id) < 0) {
-               wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
-                          id);
-               return -1;
-       }
-
-       return 0;
+       return wpas_ctrl_remove_cred(wpa_s, cred);
 }
 
 
index 6281c73f78c9faf31f92c2b9cde78db58b03347c..2f11f2023326c06ea76317f3b08596b4a2d1ad10 100644 (file)
@@ -786,6 +786,7 @@ static int interworking_connect_3gpp(struct wpa_supplicant *wpa_s,
        ssid = wpa_config_add_network(wpa_s->conf);
        if (ssid == NULL)
                return -1;
+       ssid->parent_cred = cred;
 
        wpas_notify_network_added(wpa_s, ssid);
        wpa_config_set_network_defaults(ssid);
@@ -1095,6 +1096,7 @@ static int interworking_connect_roaming_consortium(
        ssid = wpa_config_add_network(wpa_s->conf);
        if (ssid == NULL)
                return -1;
+       ssid->parent_cred = cred;
        wpas_notify_network_added(wpa_s, ssid);
        wpa_config_set_network_defaults(ssid);
        ssid->priority = cred->priority;
@@ -1209,6 +1211,7 @@ int interworking_connect(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
                nai_realm_free(realm, count);
                return -1;
        }
+       ssid->parent_cred = cred;
        wpas_notify_network_added(wpa_s, ssid);
        wpa_config_set_network_defaults(ssid);
        ssid->priority = cred->priority;