Move hostapd_parse_radius_attr() into ap_config.c
We will want to parse RADIUS attributes in config file format when retrieving them from an SQLite database. Signed-off-by: Terry Burton <tez@terryburton.co.uk>
This commit is contained in:
parent
1e5ea68d1f
commit
74707def8f
3 changed files with 70 additions and 77 deletions
|
@ -476,6 +476,75 @@ hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
|
|||
}
|
||||
|
||||
|
||||
struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
|
||||
{
|
||||
const char *pos;
|
||||
char syntax;
|
||||
struct hostapd_radius_attr *attr;
|
||||
size_t len;
|
||||
|
||||
attr = os_zalloc(sizeof(*attr));
|
||||
if (!attr)
|
||||
return NULL;
|
||||
|
||||
attr->type = atoi(value);
|
||||
|
||||
pos = os_strchr(value, ':');
|
||||
if (!pos) {
|
||||
attr->val = wpabuf_alloc(1);
|
||||
if (!attr->val) {
|
||||
os_free(attr);
|
||||
return NULL;
|
||||
}
|
||||
wpabuf_put_u8(attr->val, 0);
|
||||
return attr;
|
||||
}
|
||||
|
||||
pos++;
|
||||
if (pos[0] == '\0' || pos[1] != ':') {
|
||||
os_free(attr);
|
||||
return NULL;
|
||||
}
|
||||
syntax = *pos++;
|
||||
pos++;
|
||||
|
||||
switch (syntax) {
|
||||
case 's':
|
||||
attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
|
||||
break;
|
||||
case 'x':
|
||||
len = os_strlen(pos);
|
||||
if (len & 1)
|
||||
break;
|
||||
len /= 2;
|
||||
attr->val = wpabuf_alloc(len);
|
||||
if (!attr->val)
|
||||
break;
|
||||
if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
|
||||
wpabuf_free(attr->val);
|
||||
os_free(attr);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
attr->val = wpabuf_alloc(4);
|
||||
if (attr->val)
|
||||
wpabuf_put_be32(attr->val, atoi(pos));
|
||||
break;
|
||||
default:
|
||||
os_free(attr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!attr->val) {
|
||||
os_free(attr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return attr;
|
||||
}
|
||||
|
||||
|
||||
static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
|
||||
{
|
||||
struct hostapd_radius_attr *prev;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue