X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fplugins%2Fradius%2Fradius.c;h=3c773cb2c49137eeb8923b12772e2469d1d6a46e;hp=c9cd4095ba27d43626014a6d03c7828e55997374;hb=e227ca9c99af2e3320e1a41be3fd140429c2a995;hpb=da29a8c46351a93fcbab4026ced5fffd960f9e57 diff --git a/pppd/plugins/radius/radius.c b/pppd/plugins/radius/radius.c index c9cd409..3c773cb 100644 --- a/pppd/plugins/radius/radius.c +++ b/pppd/plugins/radius/radius.c @@ -24,10 +24,10 @@ * ***********************************************************************/ static char const RCSID[] = -"$Id: radius.c,v 1.13 2002/07/25 16:29:15 dfs Exp $"; +"$Id: radius.c,v 1.31 2006/05/22 00:01:40 paulus Exp $"; #include "pppd.h" -#include "chap.h" +#include "chap-new.h" #ifdef CHAPMS #include "chap_ms.h" #ifdef MPPE @@ -40,13 +40,29 @@ static char const RCSID[] = #include #include #include +#include +#include +#include #define BUF_LEN 1024 +#define MD5_HASH_SIZE 16 + static char *config_file = NULL; +static int add_avp(char **); +static struct avpopt { + char *vpstr; + struct avpopt *next; +} *avpopt = NULL; +static bool portnummap = 0; static option_t Options[] = { { "radius-config-file", o_string, &config_file }, + { "avpair", o_special, add_avp }, + { "map-to-ttyname", o_bool, &portnummap, + "Set Radius NAS-Port attribute value via libradiusclient library", OPT_PRIO | 1 }, + { "map-to-ifname", o_bool, &portnummap, + "Set Radius NAS-Port attribute to number as in interface name (Default)", OPT_PRIOSUB | 0 }, { NULL } }; @@ -56,16 +72,19 @@ static int radius_pap_auth(char *user, char **msgp, struct wordlist **paddrs, struct wordlist **popts); -static int radius_chap_auth(char *user, - u_char *remmd, - int remmd_len, - chap_state *cstate); +static int radius_chap_verify(char *user, char *ourname, int id, + struct chap_digest_type *digest, + unsigned char *challenge, + unsigned char *response, + char *message, int message_space); static void radius_ip_up(void *opaque, int arg); static void radius_ip_down(void *opaque, int arg); static void make_username_realm(char *user); -static int radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, - REQUEST_INFO *req_info); +static int radius_setparams(VALUE_PAIR *vp, char *msg, REQUEST_INFO *req_info, + struct chap_digest_type *digest, + unsigned char *challenge, + char *message, int message_space); static void radius_choose_ip(u_int32_t *addrp); static int radius_init(char *msg); static int get_client_port(char *ifname); @@ -73,7 +92,7 @@ static int radius_allowed_address(u_int32_t addr); static void radius_acct_interim(void *); #ifdef MPPE static int radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info, - chap_state *); + unsigned char *); static int radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info); #endif @@ -81,6 +100,10 @@ static int radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info); #define MAXSESSIONID 32 #endif +#ifndef MAXCLASSLEN +#define MAXCLASSLEN 500 +#endif + struct radius_state { int accounting_started; int initialized; @@ -96,6 +119,9 @@ struct radius_state { int acct_interim_interval; SERVER *authserver; /* Authentication server to use */ SERVER *acctserver; /* Accounting server to use */ + int class_len; + char class[MAXCLASSLEN]; + VALUE_PAIR *avp; /* Additional (user supplied) vp's to send to server */ }; void (*radius_attributes_hook)(VALUE_PAIR *) = NULL; @@ -126,7 +152,7 @@ plugin_init(void) pap_auth_hook = radius_pap_auth; chap_check_hook = radius_secret_check; - chap_auth_hook = radius_chap_auth; + chap_verify_hook = radius_chap_verify; ip_choose_hook = radius_choose_ip; allowed_address_hook = radius_allowed_address; @@ -144,6 +170,28 @@ plugin_init(void) info("RADIUS plugin initialized."); } +/********************************************************************** +* %FUNCTION: add_avp +* %ARGUMENTS: +* argv -- the pair to add +* %RETURNS: +* 1 +* %DESCRIPTION: +* Adds an av pair to be passed on to the RADIUS server on each request. +***********************************************************************/ +static int +add_avp(char **argv) +{ + struct avpopt *p = malloc(sizeof(struct avpopt)); + + /* Append to a list of vp's for later parsing */ + p->vpstr = strdup(*argv); + p->next = avpopt; + avpopt = p; + + return 1; +} + /********************************************************************** * %FUNCTION: radius_secret_check * %ARGUMENTS: @@ -223,7 +271,7 @@ radius_pap_auth(char *user, /* Hack... the "port" is the ppp interface number. Should really be the tty */ - rstate.client_port = get_client_port(ifname); + rstate.client_port = get_client_port(portnummap ? devnam : ifname); av_type = PW_FRAMED; rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE); @@ -236,7 +284,12 @@ radius_pap_auth(char *user, if (*remote_number) { rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0, VENDOR_NONE); - } + } else if (ipparam) + rc_avpair_add(&send, PW_CALLING_STATION_ID, ipparam, 0, VENDOR_NONE); + + /* Add user specified vp's */ + if (rstate.avp) + rc_avpair_insert(&send, NULL, rc_avpair_copy(rstate.avp)); if (rstate.authserver) { result = rc_auth_using_server(rstate.authserver, @@ -247,7 +300,7 @@ radius_pap_auth(char *user, } if (result == OK_RC) { - if (radius_setparams(NULL, received, radius_msg, NULL) < 0) { + if (radius_setparams(received, radius_msg, NULL, NULL, NULL, NULL, 0) < 0) { result = ERROR_RC; } } @@ -260,28 +313,33 @@ radius_pap_auth(char *user, } /********************************************************************** -* %FUNCTION: radius_chap_auth +* %FUNCTION: radius_chap_verify * %ARGUMENTS: -* user -- user-name of peer -* remmd -- hash received from peer -* remmd_len -- length of remmd -* cstate -- pppd's chap_state structure +* user -- name of the peer +* ourname -- name for this machine +* id -- the ID byte in the challenge +* digest -- points to the structure representing the digest type +* challenge -- the challenge string we sent (length in first byte) +* response -- the response (hash) the peer sent back (length in 1st byte) +* message -- space for a message to be returned to the peer +* message_space -- number of bytes available at *message. * %RETURNS: -* CHAP_SUCCESS if we can authenticate, CHAP_FAILURE if we cannot. +* 1 if the response is good, 0 if it is bad * %DESCRIPTION: * Performs CHAP, MS-CHAP and MS-CHAPv2 authentication using RADIUS. ***********************************************************************/ static int -radius_chap_auth(char *user, - u_char *remmd, - int remmd_len, - chap_state *cstate) +radius_chap_verify(char *user, char *ourname, int id, + struct chap_digest_type *digest, + unsigned char *challenge, unsigned char *response, + char *message, int message_space) { VALUE_PAIR *send, *received; UINT4 av_type; static char radius_msg[BUF_LEN]; int result; - u_char cpassword[MAX_RESPONSE_LENGTH + 1]; + int challenge_len, response_len; + u_char cpassword[MAX_RESPONSE_LEN + 1]; #ifdef MPPE /* Need the RADIUS secret and Request Authenticator to decode MPPE */ REQUEST_INFO request_info, *req_info = &request_info; @@ -289,28 +347,31 @@ radius_chap_auth(char *user, REQUEST_INFO *req_info = NULL; #endif + challenge_len = *challenge++; + response_len = *response++; + radius_msg[0] = 0; if (radius_init(radius_msg) < 0) { error("%s", radius_msg); - return CHAP_FAILURE; + return 0; } /* return error for types we can't handle */ - if ((cstate->chal_type != CHAP_DIGEST_MD5) + if ((digest->code != CHAP_MD5) #ifdef CHAPMS - && (cstate->chal_type != CHAP_MICROSOFT) - && (cstate->chal_type != CHAP_MICROSOFT_V2) + && (digest->code != CHAP_MICROSOFT) + && (digest->code != CHAP_MICROSOFT_V2) #endif ) { - error("RADIUS: Challenge type %u unsupported", cstate->chal_type); - return CHAP_FAILURE; + error("RADIUS: Challenge type %u unsupported", digest->code); + return 0; } /* Put user with potentially realm added in rstate.user */ if (!rstate.done_chap_once) { make_username_realm(user); - rstate.client_port = get_client_port (ifname); + rstate.client_port = get_client_port (portnummap ? devnam : ifname); if (radius_pre_auth_hook) { radius_pre_auth_hook(rstate.user, &rstate.authserver, @@ -331,35 +392,35 @@ radius_chap_auth(char *user, /* * add the challenge and response fields */ - switch (cstate->chal_type) { - case CHAP_DIGEST_MD5: + switch (digest->code) { + case CHAP_MD5: /* CHAP-Challenge and CHAP-Password */ - cpassword[0] = cstate->chal_id; - memcpy(&cpassword[1], remmd, MD5_SIGNATURE_SIZE); + if (response_len != MD5_HASH_SIZE) + return 0; + cpassword[0] = id; + memcpy(&cpassword[1], response, MD5_HASH_SIZE); rc_avpair_add(&send, PW_CHAP_CHALLENGE, - cstate->challenge, cstate->chal_len, VENDOR_NONE); + challenge, challenge_len, VENDOR_NONE); rc_avpair_add(&send, PW_CHAP_PASSWORD, - cpassword, MD5_SIGNATURE_SIZE + 1, VENDOR_NONE); + cpassword, MD5_HASH_SIZE + 1, VENDOR_NONE); break; #ifdef CHAPMS case CHAP_MICROSOFT: { /* MS-CHAP-Challenge and MS-CHAP-Response */ - MS_ChapResponse *rmd = (MS_ChapResponse *) remmd; u_char *p = cpassword; - *p++ = cstate->chal_id; + if (response_len != MS_CHAP_RESPONSE_LEN) + return 0; + *p++ = id; /* The idiots use a different field order in RADIUS than PPP */ - memcpy(p, rmd->UseNT, sizeof(rmd->UseNT)); - p += sizeof(rmd->UseNT); - memcpy(p, rmd->LANManResp, sizeof(rmd->LANManResp)); - p += sizeof(rmd->LANManResp); - memcpy(p, rmd->NTResp, sizeof(rmd->NTResp)); + *p++ = response[MS_CHAP_USENT]; + memcpy(p, response, MS_CHAP_LANMANRESP_LEN + MS_CHAP_NTRESP_LEN); rc_avpair_add(&send, PW_MS_CHAP_CHALLENGE, - cstate->challenge, cstate->chal_len, VENDOR_MICROSOFT); + challenge, challenge_len, VENDOR_MICROSOFT); rc_avpair_add(&send, PW_MS_CHAP_RESPONSE, cpassword, MS_CHAP_RESPONSE_LEN + 1, VENDOR_MICROSOFT); break; @@ -368,29 +429,35 @@ radius_chap_auth(char *user, case CHAP_MICROSOFT_V2: { /* MS-CHAP-Challenge and MS-CHAP2-Response */ - MS_Chap2Response *rmd = (MS_Chap2Response *) remmd; u_char *p = cpassword; - *p++ = cstate->chal_id; + if (response_len != MS_CHAP2_RESPONSE_LEN) + return 0; + *p++ = id; /* The idiots use a different field order in RADIUS than PPP */ - memcpy(p, rmd->Flags, sizeof(rmd->Flags)); - p += sizeof(rmd->Flags); - memcpy(p, rmd->PeerChallenge, sizeof(rmd->PeerChallenge)); - p += sizeof(rmd->PeerChallenge); - memcpy(p, rmd->Reserved, sizeof(rmd->Reserved)); - p += sizeof(rmd->Reserved); - memcpy(p, rmd->NTResp, sizeof(rmd->NTResp)); + *p++ = response[MS_CHAP2_FLAGS]; + memcpy(p, response, (MS_CHAP2_PEER_CHAL_LEN + MS_CHAP2_RESERVED_LEN + + MS_CHAP2_NTRESP_LEN)); rc_avpair_add(&send, PW_MS_CHAP_CHALLENGE, - cstate->challenge, cstate->chal_len, VENDOR_MICROSOFT); + challenge, challenge_len, VENDOR_MICROSOFT); rc_avpair_add(&send, PW_MS_CHAP2_RESPONSE, cpassword, MS_CHAP2_RESPONSE_LEN + 1, VENDOR_MICROSOFT); break; } #endif - } + if (*remote_number) { + rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0, + VENDOR_NONE); + } else if (ipparam) + rc_avpair_add(&send, PW_CALLING_STATION_ID, ipparam, 0, VENDOR_NONE); + + /* Add user specified vp's */ + if (rstate.avp) + rc_avpair_insert(&send, NULL, rc_avpair_copy(rstate.avp)); + /* * make authentication with RADIUS server */ @@ -404,9 +471,12 @@ radius_chap_auth(char *user, req_info); } + strlcpy(message, radius_msg, message_space); + if (result == OK_RC) { if (!rstate.done_chap_once) { - if (radius_setparams(cstate, received, radius_msg, req_info) < 0) { + if (radius_setparams(received, radius_msg, req_info, digest, + challenge, message, message_space) < 0) { error("%s", radius_msg); result = ERROR_RC; } else { @@ -417,7 +487,7 @@ radius_chap_auth(char *user, rc_avpair_free(received); rc_avpair_free (send); - return (result == OK_RC) ? CHAP_SUCCESS : CHAP_FAILURE; + return (result == OK_RC); } /********************************************************************** @@ -454,7 +524,6 @@ make_username_realm(char *user) /********************************************************************** * %FUNCTION: radius_setparams * %ARGUMENTS: -* cstate -- pppd's chap_state structure * vp -- received value-pairs * msg -- buffer in which to place error message. Holds up to BUF_LEN chars * %RETURNS: @@ -463,11 +532,17 @@ make_username_realm(char *user) * Parses attributes sent by RADIUS server and sets them in pppd. ***********************************************************************/ static int -radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, - REQUEST_INFO *req_info) +radius_setparams(VALUE_PAIR *vp, char *msg, REQUEST_INFO *req_info, + struct chap_digest_type *digest, unsigned char *challenge, + char *message, int message_space) { u_int32_t remote; int ms_chap2_success = 0; +#ifdef MPPE + int mppe_enc_keys = 0; /* whether or not these were received */ + int mppe_enc_policy = 0; + int mppe_enc_types = 0; +#endif /* Send RADIUS attributes to anyone else who might be interested */ if (radius_attributes_hook) { @@ -513,7 +588,7 @@ radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, break; case PW_OCTETS_DIRECTION: /* Session traffic limit direction check */ - maxoctets_dir = ( vp->lvalue > 4 ) 0 : vp->lvalue ; + maxoctets_dir = ( vp->lvalue > 4 ) ? 0 : vp->lvalue ; break; #endif case PW_ACCT_INTERIM_INTERVAL: @@ -544,7 +619,16 @@ radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, rstate.ip_addr = remote; } break; + case PW_CLASS: + /* Save Class attribute to pass it in accounting request */ + if (vp->lvalue <= MAXCLASSLEN) { + rstate.class_len=vp->lvalue; + memcpy(rstate.class, vp->strvalue, rstate.class_len); + } /* else too big for our buffer - ignore it */ + break; } + + #ifdef CHAPMS } else if (vp->vendorcode == VENDOR_MICROSOFT) { switch (vp->attribute) { @@ -553,19 +637,19 @@ radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, slprintf(msg,BUF_LEN,"RADIUS: bad MS-CHAP2-Success packet"); return -1; } - memcpy(cstate->saresponse, vp->strvalue + 3, - MS_AUTH_RESPONSE_LENGTH); - cstate->saresponse[MS_AUTH_RESPONSE_LENGTH] = '\0'; + if (message != NULL) + strlcpy(message, vp->strvalue + 1, message_space); ms_chap2_success = 1; break; #ifdef MPPE case PW_MS_CHAP_MPPE_KEYS: - if (radius_setmppekeys(vp, req_info, cstate) < 0) { + if (radius_setmppekeys(vp, req_info, challenge) < 0) { slprintf(msg, BUF_LEN, "RADIUS: bad MS-CHAP-MPPE-Keys attribute"); return -1; } + mppe_enc_keys = 1; break; case PW_MS_MPPE_SEND_KEY: @@ -577,11 +661,19 @@ radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, "Send": "Recv"); return -1; } + mppe_enc_keys = 1; break; -#endif /* MPPE */ -#if 0 + case PW_MS_MPPE_ENCRYPTION_POLICY: + mppe_enc_policy = vp->lvalue; /* save for later */ + break; + case PW_MS_MPPE_ENCRYPTION_TYPES: + mppe_enc_types = vp->lvalue; /* save for later */ + break; + +#endif /* MPPE */ +#if 0 case PW_MS_PRIMARY_DNS_SERVER: case PW_MS_SECONDARY_DNS_SERVER: case PW_MS_PRIMARY_NBNS_SERVER: @@ -595,9 +687,22 @@ radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, } /* Require a valid MS-CHAP2-SUCCESS for MS-CHAPv2 auth */ - if (cstate && (cstate->chal_type == CHAP_MICROSOFT_V2) && !ms_chap2_success) + if (digest && (digest->code == CHAP_MICROSOFT_V2) && !ms_chap2_success) return -1; +#ifdef MPPE + /* + * Require both policy and key attributes to indicate a valid key. + * Note that if the policy value was '0' we don't set the key! + */ + if (mppe_enc_policy && mppe_enc_keys) { + mppe_keys_set = 1; + /* Set/modify allowed encryption types. */ + if (mppe_enc_types) + set_mppe_enc_types(mppe_enc_policy, mppe_enc_types); + } +#endif + return 0; } @@ -607,7 +712,6 @@ radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, * %ARGUMENTS: * vp -- value pair holding MS-CHAP-MPPE-KEYS attribute * req_info -- radius request information used for encryption -* cstate -- chap_state structure for challenge info * %RETURNS: * >= 0 on success; -1 on failure * %DESCRIPTION: @@ -615,7 +719,8 @@ radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg, * See RFC 2548. ***********************************************************************/ static int -radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info, chap_state *cstate) +radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info, + unsigned char *challenge) { int i; MD5_CTX Context; @@ -630,18 +735,18 @@ radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info, chap_state *cstate) memcpy(plain, vp->strvalue, sizeof(plain)); - MD5Init(&Context); - MD5Update(&Context, req_info->secret, strlen(req_info->secret)); - MD5Update(&Context, req_info->request_vector, AUTH_VECTOR_LEN); - MD5Final(buf, &Context); + MD5_Init(&Context); + MD5_Update(&Context, req_info->secret, strlen(req_info->secret)); + MD5_Update(&Context, req_info->request_vector, AUTH_VECTOR_LEN); + MD5_Final(buf, &Context); for (i = 0; i < 16; i++) plain[i] ^= buf[i]; - MD5Init(&Context); - MD5Update(&Context, req_info->secret, strlen(req_info->secret)); - MD5Update(&Context, vp->strvalue, 16); - MD5Final(buf, &Context); + MD5_Init(&Context); + MD5_Update(&Context, req_info->secret, strlen(req_info->secret)); + MD5_Update(&Context, vp->strvalue, 16); + MD5_Final(buf, &Context); for(i = 0; i < 16; i++) plain[i + 16] ^= buf[i]; @@ -651,7 +756,7 @@ radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info, chap_state *cstate) * the NAS (us) doesn't need; we only need the start key. So we have * to generate the start key, sigh. NB: We do not support the LM-Key. */ - mppe_set_keys(cstate->challenge, &plain[8]); + mppe_set_keys(challenge, &plain[8]); return 0; } @@ -675,7 +780,7 @@ radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info) u_char *salt = vp->strvalue; u_char *crypt = vp->strvalue + 2; u_char plain[32]; - u_char buf[MD5_SIGNATURE_SIZE]; + u_char buf[MD5_HASH_SIZE]; char *type = "Send"; if (vp->attribute == PW_MS_MPPE_RECV_KEY) @@ -694,11 +799,11 @@ radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info) memcpy(plain, crypt, 32); - MD5Init(&Context); - MD5Update(&Context, req_info->secret, strlen(req_info->secret)); - MD5Update(&Context, req_info->request_vector, AUTH_VECTOR_LEN); - MD5Update(&Context, salt, 2); - MD5Final(buf, &Context); + MD5_Init(&Context); + MD5_Update(&Context, req_info->secret, strlen(req_info->secret)); + MD5_Update(&Context, req_info->request_vector, AUTH_VECTOR_LEN); + MD5_Update(&Context, salt, 2); + MD5_Final(buf, &Context); for (i = 0; i < 16; i++) plain[i] ^= buf[i]; @@ -709,10 +814,10 @@ radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info) return -1; } - MD5Init(&Context); - MD5Update(&Context, req_info->secret, strlen(req_info->secret)); - MD5Update(&Context, crypt, 16); - MD5Final(buf, &Context); + MD5_Init(&Context); + MD5_Update(&Context, req_info->secret, strlen(req_info->secret)); + MD5_Update(&Context, crypt, 16); + MD5_Final(buf, &Context); plain[16] ^= buf[0]; /* only need the first byte */ @@ -756,6 +861,10 @@ radius_acct_start(void) rc_avpair_add(&send, PW_USER_NAME, rstate.user, 0, VENDOR_NONE); + if (rstate.class_len > 0) + rc_avpair_add(&send, PW_CLASS, + rstate.class, rstate.class_len, VENDOR_NONE); + av_type = PW_STATUS_START; rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE); @@ -768,19 +877,24 @@ radius_acct_start(void) if (*remote_number) { rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0, VENDOR_NONE); - } + } else if (ipparam) + rc_avpair_add(&send, PW_CALLING_STATION_ID, ipparam, 0, VENDOR_NONE); av_type = PW_RADIUS; rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE); - av_type = PW_ASYNC; + av_type = ( using_pty ? PW_VIRTUAL : ( sync_serial ? PW_SYNC : PW_ASYNC ) ); rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE); hisaddr = ho->hisaddr; av_type = htonl(hisaddr); rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE); + /* Add user specified vp's */ + if (rstate.avp) + rc_avpair_insert(&send, NULL, rc_avpair_copy(rstate.avp)); + if (rstate.acctserver) { result = rc_acct_using_server(rstate.acctserver, rstate.client_port, send); @@ -868,15 +982,71 @@ radius_acct_stop(void) if (*remote_number) { rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0, VENDOR_NONE); - } + } else if (ipparam) + rc_avpair_add(&send, PW_CALLING_STATION_ID, ipparam, 0, VENDOR_NONE); - av_type = PW_ASYNC; + av_type = ( using_pty ? PW_VIRTUAL : ( sync_serial ? PW_SYNC : PW_ASYNC ) ); rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE); + av_type = PW_NAS_ERROR; + switch( status ) { + case EXIT_OK: + case EXIT_USER_REQUEST: + av_type = PW_USER_REQUEST; + break; + + case EXIT_HANGUP: + case EXIT_PEER_DEAD: + case EXIT_CONNECT_FAILED: + av_type = PW_LOST_CARRIER; + break; + + case EXIT_INIT_FAILED: + case EXIT_OPEN_FAILED: + case EXIT_LOCK_FAILED: + case EXIT_PTYCMD_FAILED: + av_type = PW_PORT_ERROR; + break; + + case EXIT_PEER_AUTH_FAILED: + case EXIT_AUTH_TOPEER_FAILED: + case EXIT_NEGOTIATION_FAILED: + case EXIT_CNID_AUTH_FAILED: + av_type = PW_SERVICE_UNAVAILABLE; + break; + + case EXIT_IDLE_TIMEOUT: + av_type = PW_ACCT_IDLE_TIMEOUT; + break; + + case EXIT_CALLBACK: + av_type = PW_CALLBACK; + break; + + case EXIT_CONNECT_TIME: + av_type = PW_ACCT_SESSION_TIMEOUT; + break; + +#ifdef MAXOCTETS + case EXIT_TRAFFIC_LIMIT: + av_type = PW_NAS_REQUEST; + break; +#endif + + default: + av_type = PW_NAS_ERROR; + break; + } + rc_avpair_add(&send, PW_ACCT_TERMINATE_CAUSE, &av_type, 0, VENDOR_NONE); + hisaddr = ho->hisaddr; av_type = htonl(hisaddr); rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE); + /* Add user specified vp's */ + if (rstate.avp) + rc_avpair_insert(&send, NULL, rc_avpair_copy(rstate.avp)); + if (rstate.acctserver) { result = rc_acct_using_server(rstate.acctserver, rstate.client_port, send); @@ -960,15 +1130,20 @@ radius_acct_interim(void *ignored) if (*remote_number) { rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0, VENDOR_NONE); - } + } else if (ipparam) + rc_avpair_add(&send, PW_CALLING_STATION_ID, ipparam, 0, VENDOR_NONE); - av_type = PW_ASYNC; + av_type = ( using_pty ? PW_VIRTUAL : ( sync_serial ? PW_SYNC : PW_ASYNC ) ); rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE); hisaddr = ho->hisaddr; av_type = htonl(hisaddr); rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE); + /* Add user specified vp's */ + if (rstate.avp) + rc_avpair_insert(&send, NULL, rc_avpair_copy(rstate.avp)); + if (rstate.acctserver) { result = rc_acct_using_server(rstate.acctserver, rstate.client_port, send); @@ -1058,6 +1233,16 @@ radius_init(char *msg) rc_conf_str("mapfile")); return -1; } + + /* Add av pairs saved during option parsing */ + while (avpopt) { + struct avpopt *n = avpopt->next; + + rc_avpair_parse(avpopt->vpstr, &rstate.avp); + free(avpopt->vpstr); + free(avpopt); + avpopt = n; + } return 0; }