eap-radius: export function to build common attributes of Access-Request
This commit is contained in:
@@ -75,11 +75,6 @@ struct private_eap_radius_t {
|
|||||||
* Prefix to prepend to EAP identity
|
* Prefix to prepend to EAP identity
|
||||||
*/
|
*/
|
||||||
char *id_prefix;
|
char *id_prefix;
|
||||||
|
|
||||||
/**
|
|
||||||
* Format string we use for Called/Calling-Station-Id for a host
|
|
||||||
*/
|
|
||||||
char *station_id_fmt;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,21 +148,16 @@ static bool radius2ike(private_eap_radius_t *this,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a set of RADIUS attributes to a request message
|
* See header.
|
||||||
*/
|
*/
|
||||||
static void add_radius_request_attrs(private_eap_radius_t *this,
|
void eap_radius_build_attributes(radius_message_t *request)
|
||||||
radius_message_t *request)
|
|
||||||
{
|
{
|
||||||
ike_sa_t *ike_sa;
|
ike_sa_t *ike_sa;
|
||||||
host_t *host;
|
host_t *host;
|
||||||
char buf[40];
|
char buf[40], *station_id_fmt;;
|
||||||
u_int32_t value;
|
u_int32_t value;
|
||||||
chunk_t chunk;
|
chunk_t chunk;
|
||||||
|
|
||||||
chunk = chunk_from_str(this->id_prefix);
|
|
||||||
chunk = chunk_cata("cc", chunk, this->peer->get_encoding(this->peer));
|
|
||||||
request->add(request, RAT_USER_NAME, chunk);
|
|
||||||
|
|
||||||
/* virtual NAS-Port-Type */
|
/* virtual NAS-Port-Type */
|
||||||
value = htonl(5);
|
value = htonl(5);
|
||||||
request->add(request, RAT_NAS_PORT_TYPE, chunk_from_thing(value));
|
request->add(request, RAT_NAS_PORT_TYPE, chunk_from_thing(value));
|
||||||
@@ -195,13 +185,37 @@ static void add_radius_request_attrs(private_eap_radius_t *this,
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf(buf, sizeof(buf), this->station_id_fmt, host);
|
if (lib->settings->get_bool(lib->settings,
|
||||||
|
"%s.plugins.eap-radius.station_id_with_port",
|
||||||
|
TRUE, charon->name))
|
||||||
|
{
|
||||||
|
station_id_fmt = "%#H";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
station_id_fmt = "%H";
|
||||||
|
}
|
||||||
|
snprintf(buf, sizeof(buf), station_id_fmt, host);
|
||||||
request->add(request, RAT_CALLED_STATION_ID, chunk_from_str(buf));
|
request->add(request, RAT_CALLED_STATION_ID, chunk_from_str(buf));
|
||||||
host = ike_sa->get_other_host(ike_sa);
|
host = ike_sa->get_other_host(ike_sa);
|
||||||
snprintf(buf, sizeof(buf), this->station_id_fmt, host);
|
snprintf(buf, sizeof(buf), station_id_fmt, host);
|
||||||
request->add(request, RAT_CALLING_STATION_ID, chunk_from_str(buf));
|
request->add(request, RAT_CALLING_STATION_ID, chunk_from_str(buf));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a set of RADIUS attributes to a request message
|
||||||
|
*/
|
||||||
|
static void add_radius_request_attrs(private_eap_radius_t *this,
|
||||||
|
radius_message_t *request)
|
||||||
|
{
|
||||||
|
chunk_t chunk;
|
||||||
|
|
||||||
|
chunk = chunk_from_str(this->id_prefix);
|
||||||
|
chunk = chunk_cata("cc", chunk, this->peer->get_encoding(this->peer));
|
||||||
|
request->add(request, RAT_USER_NAME, chunk);
|
||||||
|
|
||||||
|
eap_radius_build_attributes(request);
|
||||||
eap_radius_forward_from_ike(request);
|
eap_radius_forward_from_ike(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,15 +605,6 @@ eap_radius_t *eap_radius_create(identification_t *server, identification_t *peer
|
|||||||
"%s.plugins.eap-radius.id_prefix", "",
|
"%s.plugins.eap-radius.id_prefix", "",
|
||||||
charon->name),
|
charon->name),
|
||||||
);
|
);
|
||||||
if (lib->settings->get_bool(lib->settings,
|
|
||||||
"%s.plugins.eap-radius.station_id_with_port", TRUE, charon->name))
|
|
||||||
{
|
|
||||||
this->station_id_fmt = "%#H";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->station_id_fmt = "%H";
|
|
||||||
}
|
|
||||||
this->client = eap_radius_create_client();
|
this->client = eap_radius_create_client();
|
||||||
if (!this->client)
|
if (!this->client)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,4 +57,14 @@ eap_radius_t *eap_radius_create(identification_t *server, identification_t *peer
|
|||||||
*/
|
*/
|
||||||
void eap_radius_process_attributes(radius_message_t *message);
|
void eap_radius_process_attributes(radius_message_t *message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build additional attributes for an Access-Request.
|
||||||
|
*
|
||||||
|
* Adds additional RADIUS attributes to use with Access-Request, such as
|
||||||
|
* different NAS specific attributes.
|
||||||
|
*
|
||||||
|
* @param message Access-Request message to add attributes to
|
||||||
|
*/
|
||||||
|
void eap_radius_build_attributes(radius_message_t *message);
|
||||||
|
|
||||||
#endif /** EAP_RADIUS_H_ @}*/
|
#endif /** EAP_RADIUS_H_ @}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user