eap_identity.c

Go to the documentation of this file.
00001 
00016 #include "includes.h"
00017 
00018 #include "common.h"
00019 #include "eap_i.h"
00020 
00021 
00022 struct eap_identity_data {
00023         enum { CONTINUE, SUCCESS, FAILURE } state;
00024         int pick_up;
00025 };
00026 
00027 
00028 static void * eap_identity_init(struct eap_sm *sm)
00029 {
00030         struct eap_identity_data *data;
00031 
00032         data = os_zalloc(sizeof(*data));
00033         if (data == NULL)
00034                 return NULL;
00035         data->state = CONTINUE;
00036 
00037         return data;
00038 }
00039 
00040 
00041 static void * eap_identity_initPickUp(struct eap_sm *sm)
00042 {
00043         struct eap_identity_data *data;
00044         data = eap_identity_init(sm);
00045         if (data) {
00046                 data->pick_up = 1;
00047         }
00048         return data;
00049 }
00050 
00051 
00052 static void eap_identity_reset(struct eap_sm *sm, void *priv)
00053 {
00054         struct eap_identity_data *data = priv;
00055         os_free(data);
00056 }
00057 
00058 
00059 static struct wpabuf * eap_identity_buildReq(struct eap_sm *sm, void *priv,
00060                                              u8 id)
00061 {
00062         struct eap_identity_data *data = priv;
00063         struct wpabuf *req;
00064         const char *req_data;
00065         size_t req_data_len;
00066 
00067         if (sm->eapol_cb->get_eap_req_id_text) {
00068                 req_data = sm->eapol_cb->get_eap_req_id_text(sm->eapol_ctx,
00069                                                              &req_data_len);
00070         } else {
00071                 req_data = NULL;
00072                 req_data_len = 0;
00073         }
00074         req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY, req_data_len,
00075                             EAP_CODE_REQUEST, id);
00076         if (req == NULL) {
00077                 wpa_printf(MSG_ERROR, "EAP-Identity: Failed to allocate "
00078                            "memory for request");
00079                 data->state = FAILURE;
00080                 return NULL;
00081         }
00082 
00083         wpabuf_put_data(req, req_data, req_data_len);
00084 
00085         return req;
00086 }
00087 
00088 
00089 static Boolean eap_identity_check(struct eap_sm *sm, void *priv,
00090                                   struct wpabuf *respData)
00091 {
00092         const u8 *pos;
00093         size_t len;
00094 
00095         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
00096                                respData, &len);
00097         if (pos == NULL) {
00098                 wpa_printf(MSG_INFO, "EAP-Identity: Invalid frame");
00099                 return TRUE;
00100         }
00101 
00102         return FALSE;
00103 }
00104 
00105 
00106 static void eap_identity_process(struct eap_sm *sm, void *priv,
00107                                  struct wpabuf *respData)
00108 {
00109         struct eap_identity_data *data = priv;
00110         const u8 *pos;
00111         size_t len;
00112 
00113         if (data->pick_up) {
00114                 if (eap_identity_check(sm, data, respData)) {
00115                         wpa_printf(MSG_DEBUG, "EAP-Identity: failed to pick "
00116                                    "up already started negotiation");
00117                         data->state = FAILURE;
00118                         return;
00119                 }
00120                 data->pick_up = 0;
00121         }
00122 
00123         pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
00124                                respData, &len);
00125         if (pos == NULL)
00126                 return; /* Should not happen - frame already validated */
00127 
00128         wpa_hexdump_ascii(MSG_DEBUG, "EAP-Identity: Peer identity", pos, len);
00129         if (sm->identity)
00130                 sm->update_user = TRUE;
00131         os_free(sm->identity);
00132         sm->identity = os_malloc(len ? len : 1);
00133         if (sm->identity == NULL) {
00134                 data->state = FAILURE;
00135         } else {
00136                 os_memcpy(sm->identity, pos, len);
00137                 sm->identity_len = len;
00138                 data->state = SUCCESS;
00139         }
00140 }
00141 
00142 
00143 static Boolean eap_identity_isDone(struct eap_sm *sm, void *priv)
00144 {
00145         struct eap_identity_data *data = priv;
00146         return data->state != CONTINUE;
00147 }
00148 
00149 
00150 static Boolean eap_identity_isSuccess(struct eap_sm *sm, void *priv)
00151 {
00152         struct eap_identity_data *data = priv;
00153         return data->state == SUCCESS;
00154 }
00155 
00156 
00157 int eap_server_identity_register(void)
00158 {
00159         struct eap_method *eap;
00160         int ret;
00161 
00162         eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
00163                                       EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
00164                                       "Identity");
00165         if (eap == NULL)
00166                 return -1;
00167 
00168         eap->init = eap_identity_init;
00169         eap->initPickUp = eap_identity_initPickUp;
00170         eap->reset = eap_identity_reset;
00171         eap->buildReq = eap_identity_buildReq;
00172         eap->check = eap_identity_check;
00173         eap->process = eap_identity_process;
00174         eap->isDone = eap_identity_isDone;
00175         eap->isSuccess = eap_identity_isSuccess;
00176 
00177         ret = eap_server_method_register(eap);
00178         if (ret)
00179                 eap_server_method_free(eap);
00180         return ret;
00181 }
00182 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:51 2009 for hostapd by  doxygen 1.6.1