* EAP-Starts.
*/
if ((eap_msg->length == 0) || (eap_msg->length == 2)) {
- EAP_DS *eap_ds;
- eap_handler_t handler;
-
/*
* It's a valid EAP-Start, but the request
* was marked as being proxied. So we don't
}
RDEBUG2("Got EAP_START message");
- if ((eap_ds = eap_ds_alloc()) == NULL) {
- RDEBUG2("EAP Start failed in allocation");
- return EAP_FAIL;
- }
+ vp = paircreate(request->reply, PW_EAP_MESSAGE, 0);
+ if (!vp) return EAP_FAIL;
+ pairadd(&request->reply->vps, vp);
/*
- * It's an EAP-Start packet. Tell them to stop wasting
- * our time, and give us an EAP-Identity packet.
- *
- * Hmm... we should probably check the contents of the
- * EAP-Start packet for something...
+ * Manually create an EAP Identity request
*/
- eap_ds->request->code = PW_EAP_REQUEST;
- eap_ds->request->type.num = PW_EAP_IDENTITY;
-
- /*
- * We don't have a handler, but eap_compose needs one,
- * (for various reasons), so we fake it out here.
- */
- memset(&handler, 0, sizeof(handler));
- handler.request = request;
- handler.eap_ds = eap_ds;
-
- eap_compose(&handler);
+ vp->vp_octets[0] = PW_EAP_REQUEST;
+ vp->vp_octets[1] = 0; /* ID */
+ vp->vp_octets[2] = 0;
+ vp->vp_octets[3] = 5; /* length */
+ vp->vp_octets[4] = PW_EAP_IDENTITY;
+ vp->length = 5;
- eap_ds_free(&eap_ds);
return EAP_FOUND;
} /* end of handling EAP-Start */
pairdelete(&handler->request->reply->vps, PW_STATE, 0, TAG_ANY);
eap_packet_free(&handler->eap_ds->request);
- handler->eap_ds->request = eap_packet_alloc();
+ handler->eap_ds->request = eap_packet_alloc(handler->eap_ds);
handler->eap_ds->request->code = PW_EAP_FAILURE;
eap_compose(handler);
/*
* Create our Request-Response data structure with the eap packet
*/
-static EAP_DS *eap_buildds(eap_packet_raw_t **eap_packet_p)
+static EAP_DS *eap_buildds(eap_handler_t *handler,
+ eap_packet_raw_t **eap_packet_p)
{
EAP_DS *eap_ds = NULL;
eap_packet_raw_t *eap_packet = *eap_packet_p;
int typelen;
uint16_t len;
- if ((eap_ds = eap_ds_alloc()) == NULL) {
+ if ((eap_ds = eap_ds_alloc(handler)) == NULL) {
return NULL;
}
}
}
- handler->eap_ds = eap_buildds(eap_packet_p);
+ handler->eap_ds = eap_buildds(handler, eap_packet_p);
if (handler->eap_ds == NULL) {
free(*eap_packet_p);
*eap_packet_p = NULL;
#endif
/*
- * Allocate a new eap_packet_t
+ * Allocate a new eap_packet_t
*/
-eap_packet_t *eap_packet_alloc(void)
+eap_packet_t *eap_packet_alloc(EAP_DS *eap_ds)
{
- eap_packet_t *rp;
-
- rp = rad_malloc(sizeof(eap_packet_t));
- memset(rp, 0, sizeof(eap_packet_t));
- return rp;
+ return talloc_zero(eap_ds, eap_packet_t);
}
/*
- * Free eap_packet_t
+ * Free eap_packet_t
*/
void eap_packet_free(eap_packet_t **eap_packet_ptr)
{
eap_packet->packet = NULL;
}
- free(eap_packet);
+ talloc_free(eap_packet);
*eap_packet_ptr = NULL;
}
/*
* Allocate a new eap_packet_t
*/
-EAP_DS *eap_ds_alloc(void)
+EAP_DS *eap_ds_alloc(eap_handler_t *handler)
{
EAP_DS *eap_ds;
- eap_ds = rad_malloc(sizeof(EAP_DS));
- memset(eap_ds, 0, sizeof(EAP_DS));
- if ((eap_ds->response = eap_packet_alloc()) == NULL) {
+ eap_ds = talloc_zero(handler, EAP_DS);
+ if ((eap_ds->response = eap_packet_alloc(eap_ds)) == NULL) {
eap_ds_free(&eap_ds);
return NULL;
}
- if ((eap_ds->request = eap_packet_alloc()) == NULL) {
+ if ((eap_ds->request = eap_packet_alloc(eap_ds)) == NULL) {
eap_ds_free(&eap_ds);
return NULL;
}
if (eap_ds->response) eap_packet_free(&(eap_ds->response));
if (eap_ds->request) eap_packet_free(&(eap_ds->request));
- free(eap_ds);
+ talloc_free(eap_ds);
*eap_ds_p = NULL;
}
{
eap_handler_t *handler;
- handler = rad_malloc(sizeof(eap_handler_t));
- memset(handler, 0, sizeof(eap_handler_t));
+ PTHREAD_MUTEX_LOCK(&(inst->handler_mutex));
+ handler = talloc_zero(inst, eap_handler_t);
if (inst->handler_tree) {
- PTHREAD_MUTEX_LOCK(&(inst->handler_mutex));
rbtree_insert(inst->handler_tree, handler);
- PTHREAD_MUTEX_UNLOCK(&(inst->handler_mutex));
-
}
+ PTHREAD_MUTEX_UNLOCK(&(inst->handler_mutex));
+
return handler;
}
if (!handler)
return;
- if (inst->handler_tree) {
- PTHREAD_MUTEX_LOCK(&(inst->handler_mutex));
- rbtree_deletebydata(inst->handler_tree, handler);
- PTHREAD_MUTEX_UNLOCK(&(inst->handler_mutex));
- }
-
if (handler->identity) {
free(handler->identity);
handler->identity = NULL;
if (handler->certs) pairfree(&handler->certs);
- free(handler);
+ PTHREAD_MUTEX_LOCK(&(inst->handler_mutex));
+ if (inst->handler_tree) {
+ rbtree_deletebydata(inst->handler_tree, handler);
+ }
+ talloc_free(handler);
+ PTHREAD_MUTEX_UNLOCK(&(inst->handler_mutex));
}
eap_handler_t *eap_handler(rlm_eap_t *inst, eap_packet_raw_t **eap_msg, REQUEST *request);
/* Memory Management */
-eap_packet_t *eap_packet_alloc(void);
-EAP_DS *eap_ds_alloc(void);
+eap_packet_t *eap_packet_alloc(EAP_DS *eap_ds);
+EAP_DS *eap_ds_alloc(eap_handler_t *handler);
eap_handler_t *eap_handler_alloc(rlm_eap_t *inst);
void eap_packet_free(eap_packet_t **eap_packet);
void eap_ds_free(EAP_DS **eap_ds);
/*
* Set connection ID
*/
- handler->opaque = talloc(NULL, TNC_ConnectionID);
+ handler->opaque = talloc(handler, TNC_ConnectionID);
memcpy(handler->opaque, &conn_id, sizeof(TNC_ConnectionID));
handler->free_opaque = tnc_free;