~ubuntu-branches/ubuntu/hardy/wpasupplicant/hardy

« back to all changes in this revision

Viewing changes to src/eap_server/eap_identity.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler, Alexander Sack
  • Date: 2007-08-26 16:06:57 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070826160657-2m8pxoweuxe8f93t
Tags: 0.6.0+0.5.8-0ubuntu1
* New upstream release
* remove patch 11_erroneous_manpage_ref, applied upstream
* remove patch 25_wpas_dbus_unregister_iface_fix, applied upstream

[ Alexander Sack ]
* bumping upstream version to replace development version 0.6.0 with
  this package from stable release branch.
* attempt to fix wierd timeout and high latency issues by going
  back to stable upstream version (0.5.9) (LP: #140763,
  LP: #141233).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * hostapd / EAP-Identity
3
 
 * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License version 2 as
7
 
 * published by the Free Software Foundation.
8
 
 *
9
 
 * Alternatively, this software may be distributed under the terms of BSD
10
 
 * license.
11
 
 *
12
 
 * See README and COPYING for more details.
13
 
 */
14
 
 
15
 
#include "includes.h"
16
 
 
17
 
#include "common.h"
18
 
#include "eap_i.h"
19
 
 
20
 
 
21
 
struct eap_identity_data {
22
 
        enum { CONTINUE, SUCCESS, FAILURE } state;
23
 
        int pick_up;
24
 
};
25
 
 
26
 
 
27
 
static void * eap_identity_init(struct eap_sm *sm)
28
 
{
29
 
        struct eap_identity_data *data;
30
 
 
31
 
        data = os_zalloc(sizeof(*data));
32
 
        if (data == NULL)
33
 
                return NULL;
34
 
        data->state = CONTINUE;
35
 
 
36
 
        return data;
37
 
}
38
 
 
39
 
 
40
 
static void * eap_identity_initPickUp(struct eap_sm *sm)
41
 
{
42
 
        struct eap_identity_data *data;
43
 
        data = eap_identity_init(sm);
44
 
        if (data) {
45
 
                data->pick_up = 1;
46
 
        }
47
 
        return data;
48
 
}
49
 
 
50
 
 
51
 
static void eap_identity_reset(struct eap_sm *sm, void *priv)
52
 
{
53
 
        struct eap_identity_data *data = priv;
54
 
        free(data);
55
 
}
56
 
 
57
 
 
58
 
static u8 * eap_identity_buildReq(struct eap_sm *sm, void *priv, int id,
59
 
                                  size_t *reqDataLen)
60
 
{
61
 
        struct eap_identity_data *data = priv;
62
 
        struct eap_hdr *req;
63
 
        u8 *pos;
64
 
        const char *req_data;
65
 
        size_t req_data_len;
66
 
 
67
 
        if (sm->eapol_cb->get_eap_req_id_text) {
68
 
                req_data = sm->eapol_cb->get_eap_req_id_text(sm->eapol_ctx,
69
 
                                                             &req_data_len);
70
 
        } else {
71
 
                req_data = NULL;
72
 
                req_data_len = 0;
73
 
        }
74
 
        req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, reqDataLen,
75
 
                            req_data_len, EAP_CODE_REQUEST, id, &pos);
76
 
        if (req == NULL) {
77
 
                wpa_printf(MSG_ERROR, "EAP-Identity: Failed to allocate "
78
 
                           "memory for request");
79
 
                data->state = FAILURE;
80
 
                return NULL;
81
 
        }
82
 
 
83
 
        if (req_data)
84
 
                memcpy(pos, req_data, req_data_len);
85
 
 
86
 
        return (u8 *) req;
87
 
}
88
 
 
89
 
 
90
 
static Boolean eap_identity_check(struct eap_sm *sm, void *priv,
91
 
                             u8 *respData, size_t respDataLen)
92
 
{
93
 
        const u8 *pos;
94
 
        size_t len;
95
 
 
96
 
        pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
97
 
                               respData, respDataLen, &len);
98
 
        if (pos == NULL) {
99
 
                wpa_printf(MSG_INFO, "EAP-Identity: Invalid frame");
100
 
                return TRUE;
101
 
        }
102
 
 
103
 
        return FALSE;
104
 
}
105
 
 
106
 
 
107
 
static void eap_identity_process(struct eap_sm *sm, void *priv,
108
 
                            u8 *respData, size_t respDataLen)
109
 
{
110
 
        struct eap_identity_data *data = priv;
111
 
        const u8 *pos;
112
 
        size_t len;
113
 
 
114
 
        if (data->pick_up) {
115
 
                if (eap_identity_check(sm, data, respData, respDataLen)) {
116
 
                        wpa_printf(MSG_DEBUG, "EAP-Identity: failed to pick "
117
 
                                   "up already started negotiation");
118
 
                        data->state = FAILURE;
119
 
                        return;
120
 
                }
121
 
                data->pick_up = 0;
122
 
        }
123
 
 
124
 
        pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
125
 
                               respData, respDataLen, &len);
126
 
        if (pos == NULL)
127
 
                return; /* Should not happen - frame already validated */
128
 
 
129
 
        wpa_hexdump_ascii(MSG_DEBUG, "EAP-Identity: Peer identity", pos, len);
130
 
        free(sm->identity);
131
 
        sm->identity = malloc(len);
132
 
        if (sm->identity == NULL) {
133
 
                data->state = FAILURE;
134
 
        } else {
135
 
                memcpy(sm->identity, pos, len);
136
 
                sm->identity_len = len;
137
 
                data->state = SUCCESS;
138
 
        }
139
 
}
140
 
 
141
 
 
142
 
static Boolean eap_identity_isDone(struct eap_sm *sm, void *priv)
143
 
{
144
 
        struct eap_identity_data *data = priv;
145
 
        return data->state != CONTINUE;
146
 
}
147
 
 
148
 
 
149
 
static Boolean eap_identity_isSuccess(struct eap_sm *sm, void *priv)
150
 
{
151
 
        struct eap_identity_data *data = priv;
152
 
        return data->state == SUCCESS;
153
 
}
154
 
 
155
 
 
156
 
int eap_server_identity_register(void)
157
 
{
158
 
        struct eap_method *eap;
159
 
        int ret;
160
 
 
161
 
        eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
162
 
                                      EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
163
 
                                      "Identity");
164
 
        if (eap == NULL)
165
 
                return -1;
166
 
 
167
 
        eap->init = eap_identity_init;
168
 
        eap->initPickUp = eap_identity_initPickUp;
169
 
        eap->reset = eap_identity_reset;
170
 
        eap->buildReq = eap_identity_buildReq;
171
 
        eap->check = eap_identity_check;
172
 
        eap->process = eap_identity_process;
173
 
        eap->isDone = eap_identity_isDone;
174
 
        eap->isSuccess = eap_identity_isSuccess;
175
 
 
176
 
        ret = eap_server_method_register(eap);
177
 
        if (ret)
178
 
                eap_server_method_free(eap);
179
 
        return ret;
180
 
}