Added the configure option server-name

If set it will be used to set the NAS_IDENTIFIER in radius.
This commit is contained in:
Nikos Mavrogiannopoulos
2015-02-21 08:20:16 +01:00
parent 4e459c578a
commit c1a6f4730b
10 changed files with 44 additions and 12 deletions
+23 -1
View File
@@ -38,8 +38,9 @@
#define RAD_IPV4_DNS2 ((311<<16)|(29))
static rc_handle *rh = NULL;
static char nas_identifier[64];
static void radius_global_init(void *pool, void *additional)
static void radius_global_init(void *pool, const char *server_name, void *additional)
{
rh = rc_read_config(additional);
if (rh == NULL) {
@@ -47,6 +48,11 @@ static void radius_global_init(void *pool, void *additional)
exit(1);
}
if (server_name)
strlcpy(nas_identifier, server_name, sizeof(nas_identifier));
else
nas_identifier[0] = 0;
if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {
fprintf(stderr, "error reading the radius dictionary\n");
exit(1);
@@ -182,6 +188,16 @@ static int radius_auth_pass(void *ctx, const char *pass, unsigned pass_len)
goto cleanup;
}
if (nas_identifier[0] != 0) {
if (rc_avpair_add(rh, &send, PW_NAS_IDENTIFIER, nas_identifier, -1, 0) == NULL) {
syslog(LOG_ERR,
"%s:%u: user '%s' auth error", __func__, __LINE__,
pctx->username);
ret = ERR_AUTH_FAIL;
goto cleanup;
}
}
if (rc_avpair_add(rh, &send, PW_CALLING_STATION_ID, pctx->remote_ip, -1, 0) == NULL) {
syslog(LOG_ERR,
"%s:%u: user '%s' auth error", __func__, __LINE__,
@@ -347,6 +363,12 @@ static void append_acct_standard(struct radius_ctx_st * pctx, rc_handle *rh,
{
int i;
if (nas_identifier[0] != 0) {
if (rc_avpair_add(rh, send, PW_NAS_IDENTIFIER, nas_identifier, -1, 0) == NULL) {
return;
}
}
if (rc_avpair_add(rh, send, PW_USER_NAME, pctx->username, -1, 0) == NULL) {
return;
}