Migrated eap-radius plugin to INIT/METHOD macros
This commit is contained in:
@@ -145,10 +145,8 @@ static bool radius2ike(private_eap_radius_t *this,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(eap_method_t, initiate, status_t,
|
||||||
* Implementation of eap_method_t.initiate
|
private_eap_radius_t *this, eap_payload_t **out)
|
||||||
*/
|
|
||||||
static status_t initiate(private_eap_radius_t *this, eap_payload_t **out)
|
|
||||||
{
|
{
|
||||||
radius_message_t *request, *response;
|
radius_message_t *request, *response;
|
||||||
status_t status = FAILED;
|
status_t status = FAILED;
|
||||||
@@ -218,11 +216,8 @@ static void process_class(private_eap_radius_t *this, radius_message_t *msg)
|
|||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(eap_method_t, process, status_t,
|
||||||
* Implementation of eap_method_t.process
|
private_eap_radius_t *this, eap_payload_t *in, eap_payload_t **out)
|
||||||
*/
|
|
||||||
static status_t process(private_eap_radius_t *this,
|
|
||||||
eap_payload_t *in, eap_payload_t **out)
|
|
||||||
{
|
{
|
||||||
radius_message_t *request, *response;
|
radius_message_t *request, *response;
|
||||||
status_t status = FAILED;
|
status_t status = FAILED;
|
||||||
@@ -274,19 +269,15 @@ static status_t process(private_eap_radius_t *this,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(eap_method_t, get_type, eap_type_t,
|
||||||
* Implementation of eap_method_t.get_type.
|
private_eap_radius_t *this, u_int32_t *vendor)
|
||||||
*/
|
|
||||||
static eap_type_t get_type(private_eap_radius_t *this, u_int32_t *vendor)
|
|
||||||
{
|
{
|
||||||
*vendor = this->vendor;
|
*vendor = this->vendor;
|
||||||
return this->type;
|
return this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(eap_method_t, get_msk, status_t,
|
||||||
* Implementation of eap_method_t.get_msk.
|
private_eap_radius_t *this, chunk_t *msk)
|
||||||
*/
|
|
||||||
static status_t get_msk(private_eap_radius_t *this, chunk_t *msk)
|
|
||||||
{
|
{
|
||||||
if (this->msk.ptr)
|
if (this->msk.ptr)
|
||||||
{
|
{
|
||||||
@@ -296,10 +287,8 @@ static status_t get_msk(private_eap_radius_t *this, chunk_t *msk)
|
|||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(eap_method_t, is_mutual, bool,
|
||||||
* Implementation of eap_method_t.is_mutual.
|
private_eap_radius_t *this)
|
||||||
*/
|
|
||||||
static bool is_mutual(private_eap_radius_t *this)
|
|
||||||
{
|
{
|
||||||
switch (this->type)
|
switch (this->type)
|
||||||
{
|
{
|
||||||
@@ -311,10 +300,8 @@ static bool is_mutual(private_eap_radius_t *this)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(eap_method_t, destroy, void,
|
||||||
* Implementation of eap_method_t.destroy.
|
private_eap_radius_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_eap_radius_t *this)
|
|
||||||
{
|
{
|
||||||
this->peer->destroy(this->peer);
|
this->peer->destroy(this->peer);
|
||||||
this->server->destroy(this->server);
|
this->server->destroy(this->server);
|
||||||
@@ -328,15 +315,26 @@ static void destroy(private_eap_radius_t *this)
|
|||||||
*/
|
*/
|
||||||
eap_radius_t *eap_radius_create(identification_t *server, identification_t *peer)
|
eap_radius_t *eap_radius_create(identification_t *server, identification_t *peer)
|
||||||
{
|
{
|
||||||
private_eap_radius_t *this = malloc_thing(private_eap_radius_t);
|
private_eap_radius_t *this;
|
||||||
|
|
||||||
this->public.eap_method_interface.initiate = (status_t(*)(eap_method_t*,eap_payload_t**))initiate;
|
|
||||||
this->public.eap_method_interface.process = (status_t(*)(eap_method_t*,eap_payload_t*,eap_payload_t**))process;
|
|
||||||
this->public.eap_method_interface.get_type = (eap_type_t(*)(eap_method_t*,u_int32_t*))get_type;
|
|
||||||
this->public.eap_method_interface.is_mutual = (bool(*)(eap_method_t*))is_mutual;
|
|
||||||
this->public.eap_method_interface.get_msk = (status_t(*)(eap_method_t*,chunk_t*))get_msk;
|
|
||||||
this->public.eap_method_interface.destroy = (void(*)(eap_method_t*))destroy;
|
|
||||||
|
|
||||||
|
INIT(this,
|
||||||
|
.public.eap_method_interface = {
|
||||||
|
.initiate = _initiate,
|
||||||
|
.process = _process,
|
||||||
|
.get_type = _get_type,
|
||||||
|
.is_mutual = _is_mutual,
|
||||||
|
.get_msk = _get_msk,
|
||||||
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
/* initially EAP_RADIUS, but is set to the method selected by RADIUS */
|
||||||
|
.type = EAP_RADIUS,
|
||||||
|
.eap_start = lib->settings->get_bool(lib->settings,
|
||||||
|
"charon.plugins.eap-radius.eap_start", FALSE),
|
||||||
|
.id_prefix = lib->settings->get_str(lib->settings,
|
||||||
|
"charon.plugins.eap-radius.id_prefix", ""),
|
||||||
|
.class_group = lib->settings->get_bool(lib->settings,
|
||||||
|
"charon.plugins.eap-radius.class_group", FALSE),
|
||||||
|
);
|
||||||
this->client = radius_client_create();
|
this->client = radius_client_create();
|
||||||
if (!this->client)
|
if (!this->client)
|
||||||
{
|
{
|
||||||
@@ -345,16 +343,6 @@ eap_radius_t *eap_radius_create(identification_t *server, identification_t *peer
|
|||||||
}
|
}
|
||||||
this->peer = peer->clone(peer);
|
this->peer = peer->clone(peer);
|
||||||
this->server = server->clone(server);
|
this->server = server->clone(server);
|
||||||
/* initially EAP_RADIUS, but is set to the method selected by RADIUS */
|
|
||||||
this->type = EAP_RADIUS;
|
|
||||||
this->vendor = 0;
|
|
||||||
this->msk = chunk_empty;
|
|
||||||
this->eap_start = lib->settings->get_bool(lib->settings,
|
|
||||||
"charon.plugins.eap-radius.eap_start", FALSE);
|
|
||||||
this->id_prefix = lib->settings->get_str(lib->settings,
|
|
||||||
"charon.plugins.eap-radius.id_prefix", "");
|
|
||||||
this->class_group = lib->settings->get_bool(lib->settings,
|
|
||||||
"charon.plugins.eap-radius.class_group", FALSE);
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,8 @@
|
|||||||
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
|
|
||||||
/**
|
METHOD(plugin_t, destroy, void,
|
||||||
* Implementation of plugin_t.destroy
|
eap_radius_plugin_t *this)
|
||||||
*/
|
|
||||||
static void destroy(eap_radius_plugin_t *this)
|
|
||||||
{
|
{
|
||||||
charon->eap->remove_method(charon->eap, (eap_constructor_t)eap_radius_create);
|
charon->eap->remove_method(charon->eap, (eap_constructor_t)eap_radius_create);
|
||||||
radius_client_cleanup();
|
radius_client_cleanup();
|
||||||
@@ -43,8 +41,9 @@ plugin_t *eap_radius_plugin_create()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
this = malloc_thing(eap_radius_plugin_t);
|
INIT(this,
|
||||||
this->plugin.destroy = (void(*)(plugin_t*))destroy;
|
.plugin.destroy = _destroy,
|
||||||
|
);
|
||||||
|
|
||||||
charon->eap->add_method(charon->eap, EAP_RADIUS, 0,
|
charon->eap->add_method(charon->eap, EAP_RADIUS, 0,
|
||||||
EAP_SERVER, (eap_constructor_t)eap_radius_create);
|
EAP_SERVER, (eap_constructor_t)eap_radius_create);
|
||||||
|
|||||||
@@ -261,11 +261,8 @@ static void save_state(private_radius_client_t *this, radius_message_t *msg)
|
|||||||
chunk_free(&this->state);
|
chunk_free(&this->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_client_t, request, radius_message_t*,
|
||||||
* Implementation of radius_client_t.request
|
private_radius_client_t *this, radius_message_t *req)
|
||||||
*/
|
|
||||||
static radius_message_t* request(private_radius_client_t *this,
|
|
||||||
radius_message_t *req)
|
|
||||||
{
|
{
|
||||||
char virtual[] = {0x00,0x00,0x00,0x05};
|
char virtual[] = {0x00,0x00,0x00,0x05};
|
||||||
entry_t *socket;
|
entry_t *socket;
|
||||||
@@ -419,11 +416,9 @@ static chunk_t decrypt_mppe_key(private_radius_client_t *this, u_int16_t salt,
|
|||||||
return chunk_clone(chunk_create(P.ptr + 1, *P.ptr));
|
return chunk_clone(chunk_create(P.ptr + 1, *P.ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_client_t, decrypt_msk, chunk_t,
|
||||||
* Implementation of radius_client_t.decrypt_msk
|
private_radius_client_t *this, radius_message_t *response,
|
||||||
*/
|
radius_message_t *request)
|
||||||
static chunk_t decrypt_msk(private_radius_client_t *this,
|
|
||||||
radius_message_t *response, radius_message_t *request)
|
|
||||||
{
|
{
|
||||||
struct {
|
struct {
|
||||||
u_int32_t id;
|
u_int32_t id;
|
||||||
@@ -468,10 +463,8 @@ static chunk_t decrypt_msk(private_radius_client_t *this,
|
|||||||
return chunk_empty;
|
return chunk_empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_client_t, destroy, void,
|
||||||
* Implementation of radius_client_t.destroy.
|
private_radius_client_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_radius_client_t *this)
|
|
||||||
{
|
{
|
||||||
free(this->state.ptr);
|
free(this->state.ptr);
|
||||||
free(this);
|
free(this);
|
||||||
@@ -482,13 +475,15 @@ static void destroy(private_radius_client_t *this)
|
|||||||
*/
|
*/
|
||||||
radius_client_t *radius_client_create()
|
radius_client_t *radius_client_create()
|
||||||
{
|
{
|
||||||
private_radius_client_t *this = malloc_thing(private_radius_client_t);
|
private_radius_client_t *this;
|
||||||
|
|
||||||
this->public.request = (radius_message_t*(*)(radius_client_t*, radius_message_t *msg))request;
|
INIT(this,
|
||||||
this->public.decrypt_msk = (chunk_t(*)(radius_client_t*, radius_message_t *, radius_message_t *))decrypt_msk;
|
.public = {
|
||||||
this->public.destroy = (void(*)(radius_client_t*))destroy;
|
.request = _request,
|
||||||
|
.decrypt_msk = _decrypt_msk,
|
||||||
this->state = chunk_empty;
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,13 +215,8 @@ typedef struct {
|
|||||||
int left;
|
int left;
|
||||||
} attribute_enumerator_t;
|
} attribute_enumerator_t;
|
||||||
|
|
||||||
|
METHOD(enumerator_t, attribute_enumerate, bool,
|
||||||
/**
|
attribute_enumerator_t *this, int *type, chunk_t *data)
|
||||||
* Implementation of attribute_enumerator_t.enumerate
|
|
||||||
*/
|
|
||||||
static bool attribute_enumerate(attribute_enumerator_t *this,
|
|
||||||
int *type, chunk_t *data)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
if (this->left == 0)
|
if (this->left == 0)
|
||||||
{
|
{
|
||||||
@@ -241,10 +236,8 @@ static bool attribute_enumerate(attribute_enumerator_t *this,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, create_enumerator, enumerator_t*,
|
||||||
* Implementation of radius_message_t.create_enumerator
|
private_radius_message_t *this)
|
||||||
*/
|
|
||||||
static enumerator_t* create_enumerator(private_radius_message_t *this)
|
|
||||||
{
|
{
|
||||||
attribute_enumerator_t *e;
|
attribute_enumerator_t *e;
|
||||||
|
|
||||||
@@ -252,20 +245,19 @@ static enumerator_t* create_enumerator(private_radius_message_t *this)
|
|||||||
{
|
{
|
||||||
return enumerator_create_empty();
|
return enumerator_create_empty();
|
||||||
}
|
}
|
||||||
|
INIT(e,
|
||||||
e = malloc_thing(attribute_enumerator_t);
|
.public = {
|
||||||
e->public.enumerate = (void*)attribute_enumerate;
|
.enumerate = (void*)_attribute_enumerate,
|
||||||
e->public.destroy = (void*)free;
|
.destroy = (void*)free,
|
||||||
e->next = (rattr_t*)this->msg->attributes;
|
},
|
||||||
e->left = ntohs(this->msg->length) - sizeof(rmsg_t);
|
.next = (rattr_t*)this->msg->attributes,
|
||||||
|
.left = ntohs(this->msg->length) - sizeof(rmsg_t),
|
||||||
|
);
|
||||||
return &e->public;
|
return &e->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, add, void,
|
||||||
* Implementation of radius_message_t.add
|
private_radius_message_t *this, radius_attribute_type_t type, chunk_t data)
|
||||||
*/
|
|
||||||
static void add(private_radius_message_t *this, radius_attribute_type_t type,
|
|
||||||
chunk_t data)
|
|
||||||
{
|
{
|
||||||
rattr_t *attribute;
|
rattr_t *attribute;
|
||||||
|
|
||||||
@@ -279,10 +271,8 @@ static void add(private_radius_message_t *this, radius_attribute_type_t type,
|
|||||||
this->msg->length = htons(ntohs(this->msg->length) + attribute->length);
|
this->msg->length = htons(ntohs(this->msg->length) + attribute->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, sign, void,
|
||||||
* Implementation of radius_message_t.sign
|
private_radius_message_t *this, rng_t *rng, signer_t *signer)
|
||||||
*/
|
|
||||||
static void sign(private_radius_message_t *this, rng_t *rng, signer_t *signer)
|
|
||||||
{
|
{
|
||||||
char buf[HASH_SIZE_MD5];
|
char buf[HASH_SIZE_MD5];
|
||||||
|
|
||||||
@@ -297,11 +287,9 @@ static void sign(private_radius_message_t *this, rng_t *rng, signer_t *signer)
|
|||||||
((u_char*)this->msg) + ntohs(this->msg->length) - HASH_SIZE_MD5);
|
((u_char*)this->msg) + ntohs(this->msg->length) - HASH_SIZE_MD5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, verify, bool,
|
||||||
* Implementation of radius_message_t.verify
|
private_radius_message_t *this, u_int8_t *req_auth, chunk_t secret,
|
||||||
*/
|
hasher_t *hasher, signer_t *signer)
|
||||||
static bool verify(private_radius_message_t *this, u_int8_t *req_auth,
|
|
||||||
chunk_t secret, hasher_t *hasher, signer_t *signer)
|
|
||||||
{
|
{
|
||||||
char buf[HASH_SIZE_MD5], res_auth[HASH_SIZE_MD5];
|
char buf[HASH_SIZE_MD5], res_auth[HASH_SIZE_MD5];
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
@@ -369,51 +357,39 @@ static bool verify(private_radius_message_t *this, u_int8_t *req_auth,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, get_code, radius_message_code_t,
|
||||||
* Implementation of radius_message_t.get_code
|
private_radius_message_t *this)
|
||||||
*/
|
|
||||||
static radius_message_code_t get_code(private_radius_message_t *this)
|
|
||||||
{
|
{
|
||||||
return this->msg->code;
|
return this->msg->code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, get_identifier, u_int8_t,
|
||||||
* Implementation of radius_message_t.get_identifier
|
private_radius_message_t *this)
|
||||||
*/
|
|
||||||
static u_int8_t get_identifier(private_radius_message_t *this)
|
|
||||||
{
|
{
|
||||||
return this->msg->identifier;
|
return this->msg->identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, set_identifier, void,
|
||||||
* Implementation of radius_message_t.set_identifier
|
private_radius_message_t *this, u_int8_t identifier)
|
||||||
*/
|
|
||||||
static void set_identifier(private_radius_message_t *this, u_int8_t identifier)
|
|
||||||
{
|
{
|
||||||
this->msg->identifier = identifier;
|
this->msg->identifier = identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, get_authenticator, u_int8_t*,
|
||||||
* Implementation of radius_message_t.get_authenticator
|
private_radius_message_t *this)
|
||||||
*/
|
|
||||||
static u_int8_t* get_authenticator(private_radius_message_t *this)
|
|
||||||
{
|
{
|
||||||
return this->msg->authenticator;
|
return this->msg->authenticator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, get_encoding, chunk_t,
|
||||||
* Implementation of radius_message_t.get_encoding
|
private_radius_message_t *this)
|
||||||
*/
|
|
||||||
static chunk_t get_encoding(private_radius_message_t *this)
|
|
||||||
{
|
{
|
||||||
return chunk_create((u_char*)this->msg, ntohs(this->msg->length));
|
return chunk_create((u_char*)this->msg, ntohs(this->msg->length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(radius_message_t, destroy, void,
|
||||||
* Implementation of radius_message_t.destroy.
|
private_radius_message_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_radius_message_t *this)
|
|
||||||
{
|
{
|
||||||
free(this->msg);
|
free(this->msg);
|
||||||
free(this);
|
free(this);
|
||||||
@@ -424,18 +400,22 @@ static void destroy(private_radius_message_t *this)
|
|||||||
*/
|
*/
|
||||||
static private_radius_message_t *radius_message_create()
|
static private_radius_message_t *radius_message_create()
|
||||||
{
|
{
|
||||||
private_radius_message_t *this = malloc_thing(private_radius_message_t);
|
private_radius_message_t *this;
|
||||||
|
|
||||||
this->public.create_enumerator = (enumerator_t*(*)(radius_message_t*))create_enumerator;
|
INIT(this,
|
||||||
this->public.add = (void(*)(radius_message_t*, radius_attribute_type_t,chunk_t))add;
|
.public = {
|
||||||
this->public.get_code = (radius_message_code_t(*)(radius_message_t*))get_code;
|
.create_enumerator = _create_enumerator,
|
||||||
this->public.get_identifier = (u_int8_t(*)(radius_message_t*))get_identifier;
|
.add = _add,
|
||||||
this->public.set_identifier = (void(*)(radius_message_t*, u_int8_t identifier))set_identifier;
|
.get_code = _get_code,
|
||||||
this->public.get_authenticator = (u_int8_t*(*)(radius_message_t*))get_authenticator;
|
.get_identifier = _get_identifier,
|
||||||
this->public.get_encoding = (chunk_t(*)(radius_message_t*))get_encoding;
|
.set_identifier = _set_identifier,
|
||||||
this->public.sign = (void(*)(radius_message_t*, rng_t *rng, signer_t *signer))sign;
|
.get_authenticator = _get_authenticator,
|
||||||
this->public.verify = (bool(*)(radius_message_t*, u_int8_t *req_auth, chunk_t secret, hasher_t *hasher, signer_t *signer))verify;
|
.get_encoding = _get_encoding,
|
||||||
this->public.destroy = (void(*)(radius_message_t*))destroy;
|
.sign = _sign,
|
||||||
|
.verify = _verify,
|
||||||
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -447,10 +427,11 @@ radius_message_t *radius_message_create_request()
|
|||||||
{
|
{
|
||||||
private_radius_message_t *this = radius_message_create();
|
private_radius_message_t *this = radius_message_create();
|
||||||
|
|
||||||
this->msg = malloc_thing(rmsg_t);
|
INIT(this->msg,
|
||||||
this->msg->code = RMC_ACCESS_REQUEST;
|
.code = RMC_ACCESS_REQUEST,
|
||||||
this->msg->identifier = 0;
|
.identifier = 0,
|
||||||
this->msg->length = htons(sizeof(rmsg_t));
|
.length = htons(sizeof(rmsg_t)),
|
||||||
|
);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user