EAP server: Simplify EAP method registration call

Free the allocated structure in error cases to remove need for each EAP
method to handle the error cases separately. Each registration function
can simply do "return eap_server_method_register(eap);" in the end of
the function.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2016-01-13 23:35:53 +02:00 committed by Jouni Malinen
parent 49a26bb3e3
commit 814f43cff5
22 changed files with 33 additions and 122 deletions

View file

@ -15,7 +15,6 @@ const struct eap_method * eap_server_get_eap_method(int vendor,
EapType method);
struct eap_method * eap_server_method_alloc(int version, int vendor,
EapType method, const char *name);
void eap_server_method_free(struct eap_method *method);
int eap_server_method_register(struct eap_method *method);
EapType eap_server_get_type(const char *name, int *vendor);

View file

@ -1319,7 +1319,6 @@ static u8 * eap_aka_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_aka_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_AKA, "AKA");
@ -1337,10 +1336,7 @@ int eap_server_aka_register(void)
eap->get_emsk = eap_aka_get_emsk;
eap->getSessionId = eap_aka_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}
@ -1348,7 +1344,6 @@ int eap_server_aka_register(void)
int eap_server_aka_prime_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME,
@ -1367,10 +1362,6 @@ int eap_server_aka_prime_register(void)
eap->get_emsk = eap_aka_get_emsk;
eap->getSessionId = eap_aka_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}
#endif /* EAP_SERVER_AKA_PRIME */

View file

@ -792,7 +792,6 @@ static u8 * eap_eke_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_eke_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_EKE, "EKE");
@ -810,8 +809,5 @@ int eap_server_eke_register(void)
eap->get_emsk = eap_eke_get_emsk;
eap->getSessionId = eap_eke_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -1620,7 +1620,6 @@ static u8 * eap_fast_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_fast_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_FAST, "FAST");
@ -1638,8 +1637,5 @@ int eap_server_fast_register(void)
eap->isSuccess = eap_fast_isSuccess;
eap->getSessionId = eap_fast_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -631,7 +631,6 @@ static u8 * eap_gpsk_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_gpsk_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_GPSK, "GPSK");
@ -649,8 +648,5 @@ int eap_server_gpsk_register(void)
eap->get_emsk = eap_gpsk_get_emsk;
eap->getSessionId = eap_gpsk_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -202,7 +202,6 @@ static Boolean eap_gtc_isSuccess(struct eap_sm *sm, void *priv)
int eap_server_gtc_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_GTC, "GTC");
@ -217,8 +216,5 @@ int eap_server_gtc_register(void)
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;
return eap_server_method_register(eap);
}

View file

@ -157,7 +157,6 @@ static Boolean eap_identity_isSuccess(struct eap_sm *sm, void *priv)
int eap_server_identity_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_IDENTITY,
@ -174,8 +173,5 @@ int eap_server_identity_register(void)
eap->isDone = eap_identity_isDone;
eap->isSuccess = eap_identity_isSuccess;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -550,7 +550,6 @@ static u8 * eap_ikev2_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_ikev2_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_IKEV2,
@ -569,8 +568,5 @@ int eap_server_ikev2_register(void)
eap->get_emsk = eap_ikev2_get_emsk;
eap->getSessionId = eap_ikev2_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -153,7 +153,6 @@ static Boolean eap_md5_isSuccess(struct eap_sm *sm, void *priv)
int eap_server_md5_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_MD5, "MD5");
@ -168,8 +167,5 @@ int eap_server_md5_register(void)
eap->isDone = eap_md5_isDone;
eap->isSuccess = eap_md5_isSuccess;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -87,7 +87,7 @@ struct eap_method * eap_server_method_alloc(int version, int vendor,
* eap_server_method_free - Free EAP server method structure
* @method: Method structure allocated with eap_server_method_alloc()
*/
void eap_server_method_free(struct eap_method *method)
static void eap_server_method_free(struct eap_method *method)
{
os_free(method);
}
@ -95,26 +95,31 @@ void eap_server_method_free(struct eap_method *method)
/**
* eap_server_method_register - Register an EAP server method
* @method: EAP method to register
* @method: EAP method to register from eap_server_method_alloc()
* 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
* supported EAP method.
* supported EAP method. The caller must not free the allocated method data
* regardless of the return value.
*/
int eap_server_method_register(struct eap_method *method)
{
struct eap_method *m, *last = NULL;
if (method == NULL || method->name == NULL ||
method->version != EAP_SERVER_METHOD_INTERFACE_VERSION)
method->version != EAP_SERVER_METHOD_INTERFACE_VERSION) {
eap_server_method_free(method);
return -1;
}
for (m = eap_methods; m; m = m->next) {
if ((m->vendor == method->vendor &&
m->method == method->method) ||
os_strcmp(m->name, method->name) == 0)
os_strcmp(m->name, method->name) == 0) {
eap_server_method_free(method);
return -2;
}
last = m;
}

View file

@ -571,7 +571,6 @@ static Boolean eap_mschapv2_isSuccess(struct eap_sm *sm, void *priv)
int eap_server_mschapv2_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_MSCHAPV2,
@ -588,8 +587,5 @@ int eap_server_mschapv2_register(void)
eap->getKey = eap_mschapv2_getKey;
eap->isSuccess = eap_mschapv2_isSuccess;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -565,7 +565,6 @@ static u8 * eap_pax_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_pax_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_PAX, "PAX");
@ -583,8 +582,5 @@ int eap_server_pax_register(void)
eap->get_emsk = eap_pax_get_emsk;
eap->getSessionId = eap_pax_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -1363,7 +1363,6 @@ static u8 * eap_peap_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_peap_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_PEAP, "PEAP");
@ -1380,8 +1379,5 @@ int eap_server_peap_register(void)
eap->isSuccess = eap_peap_isSuccess;
eap->getSessionId = eap_peap_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -510,7 +510,6 @@ static u8 * eap_psk_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_psk_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_PSK, "PSK");
@ -528,8 +527,5 @@ int eap_server_psk_register(void)
eap->get_emsk = eap_psk_get_emsk;
eap->getSessionId = eap_psk_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -1094,7 +1094,6 @@ static u8 * eap_pwd_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_pwd_register(void)
{
struct eap_method *eap;
int ret;
struct timeval tp;
struct timezone tz;
u32 sr;
@ -1121,9 +1120,6 @@ int eap_server_pwd_register(void)
eap->isSuccess = eap_pwd_is_success;
eap->getSessionId = eap_pwd_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -520,7 +520,6 @@ static u8 * eap_sake_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_sake_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_SAKE, "SAKE");
@ -538,8 +537,5 @@ int eap_server_sake_register(void)
eap->get_emsk = eap_sake_get_emsk;
eap->getSessionId = eap_sake_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -846,7 +846,6 @@ static u8 * eap_sim_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_sim_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_SIM, "SIM");
@ -864,8 +863,5 @@ int eap_server_sim_register(void)
eap->get_emsk = eap_sim_get_emsk;
eap->getSessionId = eap_sim_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -375,7 +375,6 @@ static u8 * eap_tls_get_session_id(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_tls_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_TLS, "TLS");
@ -393,10 +392,7 @@ int eap_server_tls_register(void)
eap->get_emsk = eap_tls_get_emsk;
eap->getSessionId = eap_tls_get_session_id;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}
@ -404,7 +400,6 @@ int eap_server_tls_register(void)
int eap_server_unauth_tls_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_UNAUTH_TLS,
@ -423,10 +418,7 @@ int eap_server_unauth_tls_register(void)
eap->isSuccess = eap_tls_isSuccess;
eap->get_emsk = eap_tls_get_emsk;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}
#endif /* EAP_SERVER_UNAUTH_TLS */
@ -435,7 +427,6 @@ int eap_server_unauth_tls_register(void)
int eap_server_wfa_unauth_tls_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_WFA_NEW,
@ -454,9 +445,6 @@ int eap_server_wfa_unauth_tls_register(void)
eap->isSuccess = eap_tls_isSuccess;
eap->get_emsk = eap_tls_get_emsk;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}
#endif /* CONFIG_HS20 */

View file

@ -554,7 +554,6 @@ static Boolean eap_tnc_isSuccess(struct eap_sm *sm, void *priv)
int eap_server_tnc_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_TNC, "TNC");
@ -569,8 +568,5 @@ int eap_server_tnc_register(void)
eap->isDone = eap_tnc_isDone;
eap->isSuccess = eap_tnc_isSuccess;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -1335,7 +1335,6 @@ static u8 * eap_ttls_get_emsk(struct eap_sm *sm, void *priv, size_t *len)
int eap_server_ttls_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_IETF, EAP_TYPE_TTLS, "TTLS");
@ -1353,8 +1352,5 @@ int eap_server_ttls_register(void)
eap->getSessionId = eap_ttls_get_session_id;
eap->get_emsk = eap_ttls_get_emsk;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -168,7 +168,6 @@ static Boolean eap_vendor_test_isSuccess(struct eap_sm *sm, void *priv)
int eap_server_vendor_test_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_ID, EAP_VENDOR_TYPE,
@ -185,8 +184,5 @@ int eap_server_vendor_test_register(void)
eap->getKey = eap_vendor_test_getKey;
eap->isSuccess = eap_vendor_test_isSuccess;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}

View file

@ -488,7 +488,6 @@ static int eap_wsc_getTimeout(struct eap_sm *sm, void *priv)
int eap_server_wsc_register(void)
{
struct eap_method *eap;
int ret;
eap = eap_server_method_alloc(EAP_SERVER_METHOD_INTERFACE_VERSION,
EAP_VENDOR_WFA, EAP_VENDOR_TYPE_WSC,
@ -505,8 +504,5 @@ int eap_server_wsc_register(void)
eap->isSuccess = eap_wsc_isSuccess;
eap->getTimeout = eap_wsc_getTimeout;
ret = eap_server_method_register(eap);
if (ret)
eap_server_method_free(eap);
return ret;
return eap_server_method_register(eap);
}