summaryrefslogtreecommitdiffstats
path: root/contrib/hostapd/eap_gtc.c
diff options
context:
space:
mode:
authorsam <sam@FreeBSD.org>2007-07-09 16:15:06 +0000
committersam <sam@FreeBSD.org>2007-07-09 16:15:06 +0000
commit1bf2fd00c50865c26197a0fb9ce70f417b9fa121 (patch)
treec6f336fc28b042f00efc2373c71fceadfa394e52 /contrib/hostapd/eap_gtc.c
parent620bfba12034be7d2ad4a357063d609ff5b6e63a (diff)
downloadFreeBSD-src-1bf2fd00c50865c26197a0fb9ce70f417b9fa121.zip
FreeBSD-src-1bf2fd00c50865c26197a0fb9ce70f417b9fa121.tar.gz
Import of hostapd 0.5.8
Diffstat (limited to 'contrib/hostapd/eap_gtc.c')
-rw-r--r--contrib/hostapd/eap_gtc.c82
1 files changed, 42 insertions, 40 deletions
diff --git a/contrib/hostapd/eap_gtc.c b/contrib/hostapd/eap_gtc.c
index 674f837..42e4cd3 100644
--- a/contrib/hostapd/eap_gtc.c
+++ b/contrib/hostapd/eap_gtc.c
@@ -1,6 +1,6 @@
/*
* hostapd / EAP-GTC (RFC 3748)
- * Copyright (c) 2004, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -12,10 +12,7 @@
* See README and COPYING for more details.
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <netinet/in.h>
+#include "includes.h"
#include "hostapd.h"
#include "common.h"
@@ -31,10 +28,9 @@ static void * eap_gtc_init(struct eap_sm *sm)
{
struct eap_gtc_data *data;
- data = malloc(sizeof(*data));
+ data = wpa_zalloc(sizeof(*data));
if (data == NULL)
- return data;
- memset(data, 0, sizeof(*data));
+ return NULL;
data->state = CONTINUE;
return data;
@@ -58,8 +54,8 @@ static u8 * eap_gtc_buildReq(struct eap_sm *sm, void *priv, int id,
size_t msg_len;
msg_len = strlen(msg);
- *reqDataLen = sizeof(*req) + 1 + msg_len;
- req = malloc(*reqDataLen);
+ req = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_GTC, reqDataLen,
+ msg_len, EAP_CODE_REQUEST, id, &pos);
if (req == NULL) {
wpa_printf(MSG_ERROR, "EAP-GTC: Failed to allocate memory for "
"request");
@@ -67,11 +63,6 @@ static u8 * eap_gtc_buildReq(struct eap_sm *sm, void *priv, int id,
return NULL;
}
- req->code = EAP_CODE_REQUEST;
- req->identifier = id;
- req->length = htons(*reqDataLen);
- pos = (u8 *) (req + 1);
- *pos++ = EAP_TYPE_GTC;
memcpy(pos, msg, msg_len);
data->state = CONTINUE;
@@ -83,14 +74,12 @@ static u8 * eap_gtc_buildReq(struct eap_sm *sm, void *priv, int id,
static Boolean eap_gtc_check(struct eap_sm *sm, void *priv,
u8 *respData, size_t respDataLen)
{
- struct eap_hdr *resp;
- u8 *pos;
+ const u8 *pos;
size_t len;
- resp = (struct eap_hdr *) respData;
- pos = (u8 *) (resp + 1);
- if (respDataLen < sizeof(*resp) + 2 || *pos != EAP_TYPE_GTC ||
- (len = ntohs(resp->length)) > respDataLen) {
+ pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC,
+ respData, respDataLen, &len);
+ if (pos == NULL || len < 1) {
wpa_printf(MSG_INFO, "EAP-GTC: Invalid frame");
return TRUE;
}
@@ -103,20 +92,22 @@ static void eap_gtc_process(struct eap_sm *sm, void *priv,
u8 *respData, size_t respDataLen)
{
struct eap_gtc_data *data = priv;
- struct eap_hdr *resp;
- u8 *pos;
+ const u8 *pos;
size_t rlen;
- if (sm->user == NULL || sm->user->password == NULL) {
- wpa_printf(MSG_INFO, "EAP-GTC: Password not configured");
+ if (sm->user == NULL || sm->user->password == NULL ||
+ sm->user->password_hash) {
+ wpa_printf(MSG_INFO, "EAP-GTC: Plaintext password not "
+ "configured");
data->state = FAILURE;
return;
}
- resp = (struct eap_hdr *) respData;
- pos = (u8 *) (resp + 1);
- pos++;
- rlen = ntohs(resp->length) - sizeof(*resp) - 1;
+ pos = eap_hdr_validate(EAP_VENDOR_IETF, EAP_TYPE_GTC,
+ respData, respDataLen, &rlen);
+ if (pos == NULL || rlen < 1)
+ return; /* Should not happen - frame already validated */
+
wpa_hexdump_key(MSG_MSGDUMP, "EAP-GTC: Response", pos, rlen);
if (rlen != sm->user->password_len ||
@@ -144,15 +135,26 @@ static Boolean eap_gtc_isSuccess(struct eap_sm *sm, void *priv)
}
-const struct eap_method eap_method_gtc =
+int eap_server_gtc_register(void)
{
- .method = EAP_TYPE_GTC,
- .name = "GTC",
- .init = eap_gtc_init,
- .reset = eap_gtc_reset,
- .buildReq = eap_gtc_buildReq,
- .check = eap_gtc_check,
- .process = eap_gtc_process,
- .isDone = eap_gtc_isDone,
- .isSuccess = eap_gtc_isSuccess,
-};
+ struct eap_method *eap;
+ int ret;
+
+ eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
+ EAP_VENDOR_IETF, EAP_TYPE_GTC, "GTC");
+ if (eap == NULL)
+ return -1;
+
+ eap->init = eap_gtc_init;
+ eap->reset = eap_gtc_reset;
+ eap->buildReq = eap_gtc_buildReq;
+ eap->check = eap_gtc_check;
+ eap->process = eap_gtc_process;
+ eap->isDone = eap_gtc_isDone;
+ eap->isSuccess = eap_gtc_isSuccess;
+
+ ret = eap_server_method_register(eap);
+ if (ret)
+ eap_server_method_free(eap);
+ return ret;
+}
OpenPOWER on IntegriCloud