OSDN Git Service

Accumulative patch from commit dc013f1e37df3462085cf01a13f0c432f146ad7a
[android-x86/external-wpa_supplicant_8.git] / wpa_supplicant / eapol_test.c
index 7d63c1b..87e399c 100644 (file)
@@ -21,7 +21,6 @@
 #include "eloop.h"
 #include "utils/base64.h"
 #include "rsn_supp/wpa.h"
-#include "eap_peer/eap_i.h"
 #include "wpa_supplicant_i.h"
 #include "radius/radius.h"
 #include "radius/radius_client.h"
@@ -98,7 +97,7 @@ static int add_extra_attr(struct radius_msg *msg,
        size_t len;
        char *pos;
        u32 val;
-       char buf[128];
+       char buf[RADIUS_MAX_ATTR_LEN + 1];
 
        switch (attr->syntax) {
        case 's':
@@ -114,7 +113,7 @@ static int add_extra_attr(struct radius_msg *msg,
                if (pos[0] == '0' && pos[1] == 'x')
                        pos += 2;
                len = os_strlen(pos);
-               if ((len & 1) || (len / 2) > sizeof(buf)) {
+               if ((len & 1) || (len / 2) > RADIUS_MAX_ATTR_LEN) {
                        printf("Invalid extra attribute hexstring\n");
                        return -1;
                }
@@ -171,7 +170,7 @@ static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
                                          const u8 *eap, size_t len)
 {
        struct radius_msg *msg;
-       char buf[128];
+       char buf[RADIUS_MAX_ATTR_LEN + 1];
        const struct eap_hdr *hdr;
        const u8 *pos;
 
@@ -429,6 +428,37 @@ static void eapol_test_cert_cb(void *ctx, int depth, const char *subject,
 }
 
 
+static void eapol_test_set_anon_id(void *ctx, const u8 *id, size_t len)
+{
+       struct eapol_test_data *e = ctx;
+       struct wpa_supplicant *wpa_s = e->wpa_s;
+       char *str;
+       int res;
+
+       wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
+                         id, len);
+
+       if (wpa_s->current_ssid == NULL)
+               return;
+
+       if (id == NULL) {
+               if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
+                                  "NULL", 0) < 0)
+                       return;
+       } else {
+               str = os_malloc(len * 2 + 1);
+               if (str == NULL)
+                       return;
+               wpa_snprintf_hex(str, len * 2 + 1, id, len);
+               res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
+                                    str, 0);
+               os_free(str);
+               if (res < 0)
+                       return;
+       }
+}
+
+
 static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
                      struct wpa_ssid *ssid)
 {
@@ -456,6 +486,7 @@ static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
        ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
        ctx->cert_cb = eapol_test_cert_cb;
        ctx->cert_in_cb = 1;
+       ctx->set_anon_id = eapol_test_set_anon_id;
 
        wpa_s->eapol = eapol_sm_init(ctx);
        if (wpa_s->eapol == NULL) {
@@ -1141,7 +1172,7 @@ int main(int argc, char *argv[])
                        wait_for_monitor++;
                        break;
                case 'N':
-                       p1 = os_zalloc(sizeof(p1));
+                       p1 = os_zalloc(sizeof(*p1));
                        if (p1 == NULL)
                                break;
                        if (!p)