2008-02-28 02:34:43 +01:00
|
|
|
/*
|
2009-11-29 17:57:15 +01:00
|
|
|
* EAP server method registration
|
|
|
|
* Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
|
2008-02-28 02:34:43 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "eap_i.h"
|
|
|
|
#include "eap_methods.h"
|
|
|
|
|
|
|
|
|
|
|
|
static struct eap_method *eap_methods;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eap_server_get_eap_method - Get EAP method based on type number
|
|
|
|
* @vendor: EAP Vendor-Id (0 = IETF)
|
|
|
|
* @method: EAP type number
|
|
|
|
* Returns: Pointer to EAP method or %NULL if not found
|
|
|
|
*/
|
|
|
|
const struct eap_method * eap_server_get_eap_method(int vendor, EapType method)
|
|
|
|
{
|
|
|
|
struct eap_method *m;
|
|
|
|
for (m = eap_methods; m; m = m->next) {
|
|
|
|
if (m->vendor == vendor && m->method == method)
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eap_server_get_type - Get EAP type for the given EAP method name
|
|
|
|
* @name: EAP method name, e.g., TLS
|
|
|
|
* @vendor: Buffer for returning EAP Vendor-Id
|
|
|
|
* Returns: EAP method type or %EAP_TYPE_NONE if not found
|
|
|
|
*
|
|
|
|
* This function maps EAP type names into EAP type numbers based on the list of
|
|
|
|
* EAP methods included in the build.
|
|
|
|
*/
|
|
|
|
EapType eap_server_get_type(const char *name, int *vendor)
|
|
|
|
{
|
|
|
|
struct eap_method *m;
|
|
|
|
for (m = eap_methods; m; m = m->next) {
|
|
|
|
if (os_strcmp(m->name, name) == 0) {
|
|
|
|
*vendor = m->vendor;
|
|
|
|
return m->method;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*vendor = EAP_VENDOR_IETF;
|
|
|
|
return EAP_TYPE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eap_server_method_alloc - Allocate EAP server method structure
|
|
|
|
* @version: Version of the EAP server method interface (set to
|
|
|
|
* EAP_SERVER_METHOD_INTERFACE_VERSION)
|
|
|
|
* @vendor: EAP Vendor-ID (EAP_VENDOR_*) (0 = IETF)
|
|
|
|
* @method: EAP type number (EAP_TYPE_*)
|
2009-01-02 21:28:04 +01:00
|
|
|
* @name: Name of the method (e.g., "TLS")
|
2008-02-28 02:34:43 +01:00
|
|
|
* Returns: Allocated EAP method structure or %NULL on failure
|
|
|
|
*
|
|
|
|
* The returned structure should be freed with eap_server_method_free() when it
|
|
|
|
* is not needed anymore.
|
|
|
|
*/
|
|
|
|
struct eap_method * eap_server_method_alloc(int version, int vendor,
|
|
|
|
EapType method, const char *name)
|
|
|
|
{
|
|
|
|
struct eap_method *eap;
|
|
|
|
eap = os_zalloc(sizeof(*eap));
|
|
|
|
if (eap == NULL)
|
|
|
|
return NULL;
|
|
|
|
eap->version = version;
|
|
|
|
eap->vendor = vendor;
|
|
|
|
eap->method = method;
|
|
|
|
eap->name = name;
|
|
|
|
return eap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eap_server_method_free - Free EAP server method structure
|
|
|
|
* @method: Method structure allocated with eap_server_method_alloc()
|
|
|
|
*/
|
2016-01-13 22:35:53 +01:00
|
|
|
static void eap_server_method_free(struct eap_method *method)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
os_free(method);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eap_server_method_register - Register an EAP server method
|
2016-01-13 22:35:53 +01:00
|
|
|
* @method: EAP method to register from eap_server_method_alloc()
|
2008-02-28 02:34:43 +01:00
|
|
|
* Returns: 0 on success, -1 on invalid method, or -2 if a matching EAP method
|
|
|
|
* has already been registered
|
|
|
|
*
|
|
|
|
* Each EAP server method needs to call this function to register itself as a
|
2016-01-13 22:35:53 +01:00
|
|
|
* supported EAP method. The caller must not free the allocated method data
|
|
|
|
* regardless of the return value.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
int eap_server_method_register(struct eap_method *method)
|
|
|
|
{
|
|
|
|
struct eap_method *m, *last = NULL;
|
|
|
|
|
|
|
|
if (method == NULL || method->name == NULL ||
|
2016-01-13 22:35:53 +01:00
|
|
|
method->version != EAP_SERVER_METHOD_INTERFACE_VERSION) {
|
|
|
|
eap_server_method_free(method);
|
2008-02-28 02:34:43 +01:00
|
|
|
return -1;
|
2016-01-13 22:35:53 +01:00
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
for (m = eap_methods; m; m = m->next) {
|
|
|
|
if ((m->vendor == method->vendor &&
|
|
|
|
m->method == method->method) ||
|
2016-01-13 22:35:53 +01:00
|
|
|
os_strcmp(m->name, method->name) == 0) {
|
|
|
|
eap_server_method_free(method);
|
2008-02-28 02:34:43 +01:00
|
|
|
return -2;
|
2016-01-13 22:35:53 +01:00
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
last = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last)
|
|
|
|
last->next = method;
|
|
|
|
else
|
|
|
|
eap_methods = method;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eap_server_unregister_methods - Unregister EAP server methods
|
|
|
|
*
|
|
|
|
* This function is called at program termination to unregister all EAP server
|
|
|
|
* methods.
|
|
|
|
*/
|
|
|
|
void eap_server_unregister_methods(void)
|
|
|
|
{
|
|
|
|
struct eap_method *m;
|
|
|
|
|
|
|
|
while (eap_methods) {
|
|
|
|
m = eap_methods;
|
|
|
|
eap_methods = eap_methods->next;
|
|
|
|
|
|
|
|
if (m->free)
|
|
|
|
m->free(m);
|
|
|
|
else
|
|
|
|
eap_server_method_free(m);
|
|
|
|
}
|
|
|
|
}
|
2009-11-29 17:57:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eap_server_get_name - Get EAP method name for the given EAP type
|
|
|
|
* @vendor: EAP Vendor-Id (0 = IETF)
|
|
|
|
* @type: EAP method type
|
2015-01-19 05:56:43 +01:00
|
|
|
* Returns: EAP method name, e.g., TLS, or "unknown" if not found
|
2009-11-29 17:57:15 +01:00
|
|
|
*
|
|
|
|
* This function maps EAP type numbers into EAP type names based on the list of
|
|
|
|
* EAP methods included in the build.
|
|
|
|
*/
|
|
|
|
const char * eap_server_get_name(int vendor, EapType type)
|
|
|
|
{
|
|
|
|
struct eap_method *m;
|
2011-08-28 18:23:16 +02:00
|
|
|
if (vendor == EAP_VENDOR_IETF && type == EAP_TYPE_EXPANDED)
|
|
|
|
return "expanded";
|
2009-11-29 17:57:15 +01:00
|
|
|
for (m = eap_methods; m; m = m->next) {
|
|
|
|
if (m->vendor == vendor && m->method == type)
|
|
|
|
return m->name;
|
|
|
|
}
|
2015-01-19 05:56:43 +01:00
|
|
|
return "unknown";
|
2009-11-29 17:57:15 +01:00
|
|
|
}
|