Moved RADIUS Class attribute helpers into RADIUS module

This commit is contained in:
Jouni Malinen 2009-01-13 20:01:29 +02:00
parent 93ea8ed034
commit 010dc06853
6 changed files with 64 additions and 68 deletions

View file

@ -16,6 +16,7 @@
#define EAPOL_SM_H
#include "defs.h"
#include "radius/radius.h"
/* IEEE Std 802.1X-2004, Ch. 8.2 */
@ -27,16 +28,6 @@ typedef unsigned int Counter;
struct eap_sm;
struct radius_attr_data {
u8 *data;
size_t len;
};
struct radius_class_data {
struct radius_attr_data *attr;
size_t count;
};
struct eapol_auth_config {
int eap_reauth_period;

View file

@ -908,47 +908,6 @@ void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
}
void ieee802_1x_free_radius_class(struct radius_class_data *class)
{
size_t i;
if (class == NULL)
return;
for (i = 0; i < class->count; i++)
os_free(class->attr[i].data);
os_free(class->attr);
class->attr = NULL;
class->count = 0;
}
int ieee802_1x_copy_radius_class(struct radius_class_data *dst,
const struct radius_class_data *src)
{
size_t i;
if (src->attr == NULL)
return 0;
dst->attr = os_zalloc(src->count * sizeof(struct radius_attr_data));
if (dst->attr == NULL)
return -1;
dst->count = 0;
for (i = 0; i < src->count; i++) {
dst->attr[i].data = os_malloc(src->attr[i].len);
if (dst->attr[i].data == NULL)
break;
dst->count++;
os_memcpy(dst->attr[i].data, src->attr[i].data,
src->attr[i].len);
dst->attr[i].len = src->attr[i].len;
}
return 0;
}
void ieee802_1x_free_station(struct sta_info *sta)
{
struct eapol_state_machine *sm = sta->eapol_sm;
@ -963,10 +922,10 @@ void ieee802_1x_free_station(struct sta_info *sta)
radius_msg_free(sm->last_recv_radius);
os_free(sm->last_recv_radius);
}
radius_free_class(&sm->radius_class);
#endif /* CONFIG_NO_RADIUS */
os_free(sm->identity);
ieee802_1x_free_radius_class(&sm->radius_class);
eapol_auth_free(sm);
}
@ -1108,7 +1067,7 @@ static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
sm == NULL)
return;
ieee802_1x_free_radius_class(&sm->radius_class);
radius_free_class(&sm->radius_class);
count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
if (count <= 0)
return;

View file

@ -78,12 +78,6 @@ int ieee802_1x_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
void hostapd_get_ntp_timestamp(u8 *buf);
char *eap_type_text(u8 type);
struct radius_class_data;
void ieee802_1x_free_radius_class(struct radius_class_data *class);
int ieee802_1x_copy_radius_class(struct radius_class_data *dst,
const struct radius_class_data *src);
const char *radius_mode_txt(struct hostapd_data *hapd);
int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta);

View file

@ -21,7 +21,6 @@
#include "eloop.h"
#include "sha1.h"
#include "sha256.h"
#include "ieee802_1x.h"
#include "eapol_sm.h"
#include "pmksa_cache.h"
@ -83,7 +82,7 @@ static void _pmksa_cache_free_entry(struct rsn_pmksa_cache_entry *entry)
if (entry == NULL)
return;
os_free(entry->identity);
ieee802_1x_free_radius_class(&entry->radius_class);
radius_free_class(&entry->radius_class);
os_free(entry);
}
@ -177,8 +176,7 @@ static void pmksa_cache_from_eapol_data(struct rsn_pmksa_cache_entry *entry,
}
}
ieee802_1x_copy_radius_class(&entry->radius_class,
&eapol->radius_class);
radius_copy_class(&entry->radius_class, &eapol->radius_class);
entry->eap_type_authsrv = eapol->eap_type_authsrv;
entry->vlan_id = eapol->sta->vlan_id;
@ -203,9 +201,8 @@ void pmksa_cache_to_eapol_data(struct rsn_pmksa_cache_entry *entry,
eapol->identity, eapol->identity_len);
}
ieee802_1x_free_radius_class(&eapol->radius_class);
ieee802_1x_copy_radius_class(&eapol->radius_class,
&entry->radius_class);
radius_free_class(&eapol->radius_class);
radius_copy_class(&eapol->radius_class, &entry->radius_class);
if (eapol->radius_class.attr) {
wpa_printf(MSG_DEBUG, "Copied %lu Class attribute(s) from "
"PMKSA", (unsigned long) eapol->radius_class.count);
@ -337,8 +334,7 @@ pmksa_cache_add_okc(struct rsn_pmksa_cache *pmksa,
old_entry->identity_len);
}
}
ieee802_1x_copy_radius_class(&entry->radius_class,
&old_entry->radius_class);
radius_copy_class(&entry->radius_class, &old_entry->radius_class);
entry->eap_type_authsrv = old_entry->eap_type_authsrv;
entry->vlan_id = old_entry->vlan_id;
entry->opportunistic = 1;

View file

@ -1232,3 +1232,44 @@ int radius_msg_get_vlanid(struct radius_msg *msg)
return -1;
}
void radius_free_class(struct radius_class_data *c)
{
size_t i;
if (c == NULL)
return;
for (i = 0; i < c->count; i++)
os_free(c->attr[i].data);
os_free(c->attr);
c->attr = NULL;
c->count = 0;
}
int radius_copy_class(struct radius_class_data *dst,
const struct radius_class_data *src)
{
size_t i;
if (src->attr == NULL)
return 0;
dst->attr = os_zalloc(src->count * sizeof(struct radius_attr_data));
if (dst->attr == NULL)
return -1;
dst->count = 0;
for (i = 0; i < src->count; i++) {
dst->attr[i].data = os_malloc(src->attr[i].len);
if (dst->attr[i].data == NULL)
break;
dst->count++;
os_memcpy(dst->attr[i].data, src->attr[i].data,
src->attr[i].len);
dst->attr[i].len = src->attr[i].len;
}
return 0;
}

View file

@ -269,4 +269,19 @@ int radius_msg_get_attr_ptr(struct radius_msg *msg, u8 type, u8 **buf,
size_t *len, const u8 *start);
int radius_msg_count_attr(struct radius_msg *msg, u8 type, int min_len);
struct radius_attr_data {
u8 *data;
size_t len;
};
struct radius_class_data {
struct radius_attr_data *attr;
size_t count;
};
void radius_free_class(struct radius_class_data *c);
int radius_copy_class(struct radius_class_data *dst,
const struct radius_class_data *src);
#endif /* RADIUS_H */