1 /***********************************************************************
5 * RADIUS plugin for pppd. Performs PAP, CHAP, MS-CHAP, MS-CHAPv2
6 * authentication using RADIUS.
8 * Copyright (C) 2002 Roaring Penguin Software Inc.
10 * Based on a patch for ipppd, which is:
11 * Copyright (C) 1996, Matjaz Godec <gody@elgo.si>
12 * Copyright (C) 1996, Lars Fenneberg <in5y050@public.uni-hamburg.de>
13 * Copyright (C) 1997, Miguel A.L. Paraz <map@iphil.net>
15 * Uses radiusclient library, which is:
16 * Copyright (C) 1995,1996,1997,1998 Lars Fenneberg <lf@elemental.net>
17 * Copyright (C) 2002 Roaring Penguin Software Inc.
19 * MPPE support is by Ralf Hofmann, <ralf.hofmann@elvido.net>, with
20 * modification from Frank Cusack, <frank@google.com>.
22 * This plugin may be distributed according to the terms of the GNU
23 * General Public License, version 2 or (at your option) any later version.
25 ***********************************************************************/
26 static char const RCSID[] =
27 "$Id: radius.c,v 1.11 2002/07/15 11:04:18 kad Exp $";
37 #include "radiusclient.h"
41 #include <sys/types.h>
46 static char *config_file = NULL;
48 static option_t Options[] = {
49 { "radius-config-file", o_string, &config_file },
53 static int radius_secret_check(void);
54 static int radius_pap_auth(char *user,
57 struct wordlist **paddrs,
58 struct wordlist **popts);
59 static int radius_chap_auth(char *user,
64 static void radius_ip_up(void *opaque, int arg);
65 static void radius_ip_down(void *opaque, int arg);
66 static void make_username_realm(char *user);
67 static int radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg,
68 REQUEST_INFO *req_info);
69 static void radius_choose_ip(u_int32_t *addrp);
70 static int radius_init(char *msg);
71 static int get_client_port(char *ifname);
72 static int radius_allowed_address(u_int32_t addr);
74 static int radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info,
76 static int radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info);
80 #define MAXSESSIONID 32
84 int accounting_started;
91 char user[MAXNAMELEN];
92 char config_file[MAXPATHLEN];
93 char session_id[MAXSESSIONID + 1];
95 SERVER *authserver; /* Authentication server to use */
96 SERVER *acctserver; /* Accounting server to use */
99 void (*radius_attributes_hook)(VALUE_PAIR *) = NULL;
101 /* The pre_auth_hook MAY set authserver and acctserver if it wants.
102 In that case, they override the values in the radiusclient.conf file */
103 void (*radius_pre_auth_hook)(char const *user,
105 SERVER **acctserver) = NULL;
107 static struct radius_state rstate;
109 char pppd_version[] = VERSION;
111 /**********************************************************************
112 * %FUNCTION: plugin_init
118 * Initializes RADIUS plugin.
119 ***********************************************************************/
123 pap_check_hook = radius_secret_check;
124 pap_auth_hook = radius_pap_auth;
126 chap_check_hook = radius_secret_check;
127 chap_auth_hook = radius_chap_auth;
129 ip_choose_hook = radius_choose_ip;
130 allowed_address_hook = radius_allowed_address;
132 add_notifier(&ip_up_notifier, radius_ip_up, NULL);
133 add_notifier(&ip_down_notifier, radius_ip_down, NULL);
135 memset(&rstate, 0, sizeof(rstate));
137 strlcpy(rstate.config_file, "/etc/radiusclient/radiusclient.conf",
138 sizeof(rstate.config_file));
140 add_options(Options);
142 info("RADIUS plugin initialized.");
145 /**********************************************************************
146 * %FUNCTION: radius_secret_check
150 * 1 -- we are ALWAYS willing to supply a secret. :-)
152 * Tells pppd that we will try to authenticate the peer, and not to
153 * worry about looking in /etc/ppp/*-secrets
154 ***********************************************************************/
156 radius_secret_check(void)
161 /**********************************************************************
162 * %FUNCTION: radius_choose_ip
164 * addrp -- where to store the IP address
168 * If RADIUS server has specified an IP address, it is stored in *addrp.
169 ***********************************************************************/
171 radius_choose_ip(u_int32_t *addrp)
173 if (rstate.choose_ip) {
174 *addrp = rstate.ip_addr;
178 /**********************************************************************
179 * %FUNCTION: radius_pap_auth
181 * user -- user-name of peer
182 * passwd -- password supplied by peer
183 * msgp -- Message which will be sent in PAP response
184 * paddrs -- set to a list of possible peer IP addresses
185 * popts -- set to a list of additional pppd options
187 * 1 if we can authenticate, -1 if we cannot.
189 * Performs PAP authentication using RADIUS
190 ***********************************************************************/
192 radius_pap_auth(char *user,
195 struct wordlist **paddrs,
196 struct wordlist **popts)
198 VALUE_PAIR *send, *received;
201 static char radius_msg[BUF_LEN];
206 if (radius_init(radius_msg) < 0) {
210 /* Put user with potentially realm added in rstate.user */
211 make_username_realm(user);
213 if (radius_pre_auth_hook) {
214 radius_pre_auth_hook(rstate.user,
222 /* Hack... the "port" is the ppp interface number. Should really be
224 rstate.client_port = get_client_port(ifname);
227 rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
230 rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
232 rc_avpair_add(&send, PW_USER_NAME, rstate.user , 0, VENDOR_NONE);
233 rc_avpair_add(&send, PW_USER_PASSWORD, passwd, 0, VENDOR_NONE);
234 if (*remote_number) {
235 rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0,
239 if (rstate.authserver) {
240 result = rc_auth_using_server(rstate.authserver,
241 rstate.client_port, send,
242 &received, radius_msg, NULL);
244 result = rc_auth(rstate.client_port, send, &received, radius_msg, NULL);
247 if (result == OK_RC) {
248 if (radius_setparams(NULL, received, radius_msg, NULL) < 0) {
253 /* free value pairs */
254 rc_avpair_free(received);
255 rc_avpair_free(send);
257 return (result == OK_RC) ? 1 : 0;
260 /**********************************************************************
261 * %FUNCTION: radius_chap_auth
263 * user -- user-name of peer
264 * remmd -- hash received from peer
265 * remmd_len -- length of remmd
266 * cstate -- pppd's chap_state structure
268 * CHAP_SUCCESS if we can authenticate, CHAP_FAILURE if we cannot.
270 * Performs CHAP, MS-CHAP and MS-CHAPv2 authentication using RADIUS.
271 ***********************************************************************/
273 radius_chap_auth(char *user,
278 VALUE_PAIR *send, *received;
280 static char radius_msg[BUF_LEN];
282 u_char cpassword[MAX_RESPONSE_LENGTH + 1];
284 /* Need the RADIUS secret and Request Authenticator to decode MPPE */
285 REQUEST_INFO request_info, *req_info = &request_info;
287 REQUEST_INFO *req_info = NULL;
292 if (radius_init(radius_msg) < 0) {
293 error("%s", radius_msg);
297 /* return error for types we can't handle */
298 if ((cstate->chal_type != CHAP_DIGEST_MD5)
300 && (cstate->chal_type != CHAP_MICROSOFT)
301 && (cstate->chal_type != CHAP_MICROSOFT_V2)
304 error("RADIUS: Challenge type %u unsupported", cstate->chal_type);
308 /* Put user with potentially realm added in rstate.user */
309 if (!rstate.done_chap_once) {
310 make_username_realm(user);
311 rstate.client_port = get_client_port (ifname);
312 if (radius_pre_auth_hook) {
313 radius_pre_auth_hook(rstate.user,
319 send = received = NULL;
322 rc_avpair_add (&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
325 rc_avpair_add (&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
327 rc_avpair_add (&send, PW_USER_NAME, rstate.user , 0, VENDOR_NONE);
330 * add the challenge and response fields
332 switch (cstate->chal_type) {
333 case CHAP_DIGEST_MD5:
334 /* CHAP-Challenge and CHAP-Password */
335 cpassword[0] = cstate->chal_id;
336 memcpy(&cpassword[1], remmd, MD5_SIGNATURE_SIZE);
338 rc_avpair_add(&send, PW_CHAP_CHALLENGE,
339 cstate->challenge, cstate->chal_len, VENDOR_NONE);
340 rc_avpair_add(&send, PW_CHAP_PASSWORD,
341 cpassword, MD5_SIGNATURE_SIZE + 1, VENDOR_NONE);
347 /* MS-CHAP-Challenge and MS-CHAP-Response */
348 MS_ChapResponse *rmd = (MS_ChapResponse *) remmd;
349 u_char *p = cpassword;
351 *p++ = cstate->chal_id;
352 /* The idiots use a different field order in RADIUS than PPP */
353 memcpy(p, rmd->UseNT, sizeof(rmd->UseNT));
354 p += sizeof(rmd->UseNT);
355 memcpy(p, rmd->LANManResp, sizeof(rmd->LANManResp));
356 p += sizeof(rmd->LANManResp);
357 memcpy(p, rmd->NTResp, sizeof(rmd->NTResp));
359 rc_avpair_add(&send, PW_MS_CHAP_CHALLENGE,
360 cstate->challenge, cstate->chal_len, VENDOR_MICROSOFT);
361 rc_avpair_add(&send, PW_MS_CHAP_RESPONSE,
362 cpassword, MS_CHAP_RESPONSE_LEN + 1, VENDOR_MICROSOFT);
366 case CHAP_MICROSOFT_V2:
368 /* MS-CHAP-Challenge and MS-CHAP2-Response */
369 MS_Chap2Response *rmd = (MS_Chap2Response *) remmd;
370 u_char *p = cpassword;
372 *p++ = cstate->chal_id;
373 /* The idiots use a different field order in RADIUS than PPP */
374 memcpy(p, rmd->Flags, sizeof(rmd->Flags));
375 p += sizeof(rmd->Flags);
376 memcpy(p, rmd->PeerChallenge, sizeof(rmd->PeerChallenge));
377 p += sizeof(rmd->PeerChallenge);
378 memcpy(p, rmd->Reserved, sizeof(rmd->Reserved));
379 p += sizeof(rmd->Reserved);
380 memcpy(p, rmd->NTResp, sizeof(rmd->NTResp));
382 rc_avpair_add(&send, PW_MS_CHAP_CHALLENGE,
383 cstate->challenge, cstate->chal_len, VENDOR_MICROSOFT);
384 rc_avpair_add(&send, PW_MS_CHAP2_RESPONSE,
385 cpassword, MS_CHAP2_RESPONSE_LEN + 1, VENDOR_MICROSOFT);
393 * make authentication with RADIUS server
396 if (rstate.authserver) {
397 result = rc_auth_using_server(rstate.authserver,
398 rstate.client_port, send,
399 &received, radius_msg, req_info);
401 result = rc_auth(rstate.client_port, send, &received, radius_msg,
405 if (result == OK_RC) {
406 if (!rstate.done_chap_once) {
407 if (radius_setparams(cstate, received, radius_msg, req_info) < 0) {
408 error("%s", radius_msg);
411 rstate.done_chap_once = 1;
416 rc_avpair_free(received);
417 rc_avpair_free (send);
418 return (result == OK_RC) ? CHAP_SUCCESS : CHAP_FAILURE;
421 /**********************************************************************
422 * %FUNCTION: make_username_realm
424 * user -- the user given to pppd
428 * Copies user into rstate.user. If it lacks a realm (no "@domain" part),
429 * then the default realm from the radiusclient config file is added.
430 ***********************************************************************/
432 make_username_realm(char *user)
436 if ( user != NULL ) {
437 strlcpy(rstate.user, user, sizeof(rstate.user));
442 default_realm = rc_conf_str("default_realm");
444 if (!strchr(rstate.user, '@') &&
446 (*default_realm != '\0')) {
447 strlcat(rstate.user, "@", sizeof(rstate.user));
448 strlcat(rstate.user, default_realm, sizeof(rstate.user));
452 /**********************************************************************
453 * %FUNCTION: radius_setparams
455 * cstate -- pppd's chap_state structure
456 * vp -- received value-pairs
457 * msg -- buffer in which to place error message. Holds up to BUF_LEN chars
459 * >= 0 on success; -1 on failure
461 * Parses attributes sent by RADIUS server and sets them in pppd.
462 ***********************************************************************/
464 radius_setparams(chap_state *cstate, VALUE_PAIR *vp, char *msg,
465 REQUEST_INFO *req_info)
468 int ms_chap2_success = 0;
470 /* Send RADIUS attributes to anyone else who might be interested */
471 if (radius_attributes_hook) {
472 (*radius_attributes_hook)(vp);
476 * service type (if not framed then quit),
477 * new IP address (RADIUS can define static IP for some users),
481 if (vp->vendorcode == VENDOR_NONE) {
482 switch (vp->attribute) {
483 case PW_SERVICE_TYPE:
484 /* check for service type */
485 /* if not FRAMED then exit */
486 if (vp->lvalue != PW_FRAMED) {
487 slprintf(msg, BUF_LEN, "RADIUS: wrong service type %ld for %s",
488 vp->lvalue, rstate.user);
493 case PW_FRAMED_PROTOCOL:
494 /* check for framed protocol type */
495 /* if not PPP then also exit */
496 if (vp->lvalue != PW_PPP) {
497 slprintf(msg, BUF_LEN, "RADIUS: wrong framed protocol %ld for %s",
498 vp->lvalue, rstate.user);
503 case PW_SESSION_TIMEOUT:
504 /* Session timeout */
505 maxconnect = vp->lvalue;
508 case PW_SESSION_OCTETS_LIMIT:
509 /* Session traffic limit */
510 maxoctets = vp->lvalue;
512 case PW_OCTETS_DIRECTION:
513 /* Session traffic limit direction check */
514 maxoctets_dir = ( vp->lvalue > 4 ) 0 : vp->lvalue ;
517 case PW_FRAMED_IP_ADDRESS:
518 /* seting up remote IP addresses */
520 if (remote == 0xffffffff) {
521 /* 0xffffffff means user should be allowed to select one */
522 rstate.any_ip_addr_ok = 1;
523 } else if (remote != 0xfffffffe) {
524 /* 0xfffffffe means NAS should select an ip address */
525 remote = htonl(vp->lvalue);
526 if (bad_ip_adrs (remote)) {
527 slprintf(msg, BUF_LEN, "RADIUS: bad remote IP address %I for %s",
528 remote, rstate.user);
531 rstate.choose_ip = 1;
532 rstate.ip_addr = remote;
537 } else if (vp->vendorcode == VENDOR_MICROSOFT) {
538 switch (vp->attribute) {
539 case PW_MS_CHAP2_SUCCESS:
540 if ((vp->lvalue != 43) || strncmp(vp->strvalue + 1, "S=", 2)) {
541 slprintf(msg,BUF_LEN,"RADIUS: bad MS-CHAP2-Success packet");
544 memcpy(cstate->saresponse, vp->strvalue + 3,
545 MS_AUTH_RESPONSE_LENGTH);
546 cstate->saresponse[MS_AUTH_RESPONSE_LENGTH] = '\0';
547 ms_chap2_success = 1;
551 case PW_MS_CHAP_MPPE_KEYS:
552 if (radius_setmppekeys(vp, req_info, cstate) < 0) {
553 slprintf(msg, BUF_LEN,
554 "RADIUS: bad MS-CHAP-MPPE-Keys attribute");
559 case PW_MS_MPPE_SEND_KEY:
560 case PW_MS_MPPE_RECV_KEY:
561 if (radius_setmppekeys2(vp, req_info) < 0) {
562 slprintf(msg, BUF_LEN,
563 "RADIUS: bad MS-MPPE-%s-Key attribute",
564 (vp->attribute == PW_MS_MPPE_SEND_KEY)?
571 case PW_MS_MPPE_ENCRYPTION_POLICY:
572 case PW_MS_MPPE_ENCRYPTION_TYPES:
573 case PW_MS_PRIMARY_DNS_SERVER:
574 case PW_MS_SECONDARY_DNS_SERVER:
575 case PW_MS_PRIMARY_NBNS_SERVER:
576 case PW_MS_SECONDARY_NBNS_SERVER:
585 /* Require a valid MS-CHAP2-SUCCESS for MS-CHAPv2 auth */
586 if (cstate && (cstate->chal_type == CHAP_MICROSOFT_V2) && !ms_chap2_success)
593 /**********************************************************************
594 * %FUNCTION: radius_setmppekeys
596 * vp -- value pair holding MS-CHAP-MPPE-KEYS attribute
597 * req_info -- radius request information used for encryption
598 * cstate -- chap_state structure for challenge info
600 * >= 0 on success; -1 on failure
602 * Decrypt the "key" provided by the RADIUS server for MPPE encryption.
604 ***********************************************************************/
606 radius_setmppekeys(VALUE_PAIR *vp, REQUEST_INFO *req_info, chap_state *cstate)
613 if (vp->lvalue != 32) {
614 error("RADIUS: Incorrect attribute length (%d) for MS-CHAP-MPPE-Keys",
619 memcpy(plain, vp->strvalue, sizeof(plain));
622 MD5Update(&Context, req_info->secret, strlen(req_info->secret));
623 MD5Update(&Context, req_info->request_vector, AUTH_VECTOR_LEN);
624 MD5Final(buf, &Context);
626 for (i = 0; i < 16; i++)
630 MD5Update(&Context, req_info->secret, strlen(req_info->secret));
631 MD5Update(&Context, vp->strvalue, 16);
632 MD5Final(buf, &Context);
634 for(i = 0; i < 16; i++)
635 plain[i + 16] ^= buf[i];
638 * Annoying. The "key" returned is just the NTPasswordHashHash, which
639 * the NAS (us) doesn't need; we only need the start key. So we have
640 * to generate the start key, sigh. NB: We do not support the LM-Key.
642 mppe_set_keys(cstate->challenge, &plain[8]);
647 /**********************************************************************
648 * %FUNCTION: radius_setmppekeys2
650 * vp -- value pair holding MS-MPPE-SEND-KEY or MS-MPPE-RECV-KEY attribute
651 * req_info -- radius request information used for encryption
653 * >= 0 on success; -1 on failure
655 * Decrypt the key provided by the RADIUS server for MPPE encryption.
657 ***********************************************************************/
659 radius_setmppekeys2(VALUE_PAIR *vp, REQUEST_INFO *req_info)
663 u_char *salt = vp->strvalue;
664 u_char *crypt = vp->strvalue + 2;
666 u_char buf[MD5_SIGNATURE_SIZE];
669 if (vp->attribute == PW_MS_MPPE_RECV_KEY)
672 if (vp->lvalue != 34) {
673 error("RADIUS: Incorrect attribute length (%d) for MS-MPPE-%s-Key",
678 if ((salt[0] & 0x80) == 0) {
679 error("RADIUS: Illegal salt value for MS-MPPE-%s-Key attribute", type);
683 memcpy(plain, crypt, 32);
686 MD5Update(&Context, req_info->secret, strlen(req_info->secret));
687 MD5Update(&Context, req_info->request_vector, AUTH_VECTOR_LEN);
688 MD5Update(&Context, salt, 2);
689 MD5Final(buf, &Context);
691 for (i = 0; i < 16; i++)
694 if (plain[0] != sizeof(mppe_send_key) /* 16 */) {
695 error("RADIUS: Incorrect key length (%d) for MS-MPPE-%s-Key attribute",
696 (int) plain[0], type);
701 MD5Update(&Context, req_info->secret, strlen(req_info->secret));
702 MD5Update(&Context, crypt, 16);
703 MD5Final(buf, &Context);
705 plain[16] ^= buf[0]; /* only need the first byte */
707 if (vp->attribute == PW_MS_MPPE_SEND_KEY)
708 memcpy(mppe_send_key, plain + 1, 16);
710 memcpy(mppe_recv_key, plain + 1, 16);
716 /**********************************************************************
717 * %FUNCTION: radius_acct_start
723 * Sends a "start" accounting message to the RADIUS server.
724 ***********************************************************************/
726 radius_acct_start(void)
730 VALUE_PAIR *send = NULL;
731 ipcp_options *ho = &ipcp_hisoptions[0];
734 if (!rstate.initialized) {
738 rstate.start_time = time(NULL);
740 strncpy(rstate.session_id, rc_mksid(), sizeof(rstate.session_id));
742 rc_avpair_add(&send, PW_ACCT_SESSION_ID,
743 rstate.session_id, 0, VENDOR_NONE);
744 rc_avpair_add(&send, PW_USER_NAME,
745 rstate.user, 0, VENDOR_NONE);
747 av_type = PW_STATUS_START;
748 rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE);
751 rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
754 rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
756 if (*remote_number) {
757 rc_avpair_add(&send, PW_CALLING_STATION_ID,
758 remote_number, 0, VENDOR_NONE);
762 rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
766 rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
768 hisaddr = ho->hisaddr;
769 av_type = htonl(hisaddr);
770 rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE);
772 if (rstate.acctserver) {
773 result = rc_acct_using_server(rstate.acctserver,
774 rstate.client_port, send);
776 result = rc_acct(rstate.client_port, send);
779 rc_avpair_free(send);
781 if (result != OK_RC) {
782 /* RADIUS server could be down so make this a warning */
784 "Accounting START failed for %s", rstate.user);
786 rstate.accounting_started = 1;
790 /**********************************************************************
791 * %FUNCTION: radius_acct_stop
797 * Sends a "stop" accounting message to the RADIUS server.
798 ***********************************************************************/
800 radius_acct_stop(void)
803 VALUE_PAIR *send = NULL;
804 ipcp_options *ho = &ipcp_hisoptions[0];
808 if (!rstate.initialized) {
812 if (!rstate.accounting_started) {
816 rstate.accounting_started = 0;
817 rc_avpair_add(&send, PW_ACCT_SESSION_ID, rstate.session_id,
820 rc_avpair_add(&send, PW_USER_NAME, rstate.user, 0, VENDOR_NONE);
822 av_type = PW_STATUS_STOP;
823 rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE);
826 rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
829 rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
832 rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
835 if (link_stats_valid) {
836 av_type = link_connect_time;
837 rc_avpair_add(&send, PW_ACCT_SESSION_TIME, &av_type, 0, VENDOR_NONE);
839 av_type = link_stats.bytes_out;
840 rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);
842 av_type = link_stats.bytes_in;
843 rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);
845 av_type = link_stats.pkts_out;
846 rc_avpair_add(&send, PW_ACCT_OUTPUT_PACKETS, &av_type, 0, VENDOR_NONE);
848 av_type = link_stats.pkts_in;
849 rc_avpair_add(&send, PW_ACCT_INPUT_PACKETS, &av_type, 0, VENDOR_NONE);
852 if (*remote_number) {
853 rc_avpair_add(&send, PW_CALLING_STATION_ID,
854 remote_number, 0, VENDOR_NONE);
858 rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
860 hisaddr = ho->hisaddr;
861 av_type = htonl(hisaddr);
862 rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE);
864 if (rstate.acctserver) {
865 result = rc_acct_using_server(rstate.acctserver,
866 rstate.client_port, send);
868 result = rc_acct(rstate.client_port, send);
871 if (result != OK_RC) {
872 /* RADIUS server could be down so make this a warning */
874 "Accounting STOP failed for %s", rstate.user);
876 rc_avpair_free(send);
879 /**********************************************************************
880 * %FUNCTION: radius_ip_up
887 * Called when IPCP is up. We'll do a start-accounting record.
888 ***********************************************************************/
890 radius_ip_up(void *opaque, int arg)
895 /**********************************************************************
896 * %FUNCTION: radius_ip_down
903 * Called when IPCP is down. We'll do a stop-accounting record.
904 ***********************************************************************/
906 radius_ip_down(void *opaque, int arg)
911 /**********************************************************************
912 * %FUNCTION: radius_init
914 * msg -- buffer of size BUF_LEN for error message
916 * negative on failure; non-negative on success
918 * Initializes radiusclient library
919 ***********************************************************************/
921 radius_init(char *msg)
923 if (rstate.initialized) {
927 if (config_file && *config_file) {
928 strlcpy(rstate.config_file, config_file, MAXPATHLEN-1);
931 rstate.initialized = 1;
933 if (rc_read_config(rstate.config_file) != 0) {
934 slprintf(msg, BUF_LEN, "RADIUS: Can't read config file %s",
939 if (rc_read_dictionary(rc_conf_str("dictionary")) != 0) {
940 slprintf(msg, BUF_LEN, "RADIUS: Can't read dictionary file %s",
941 rc_conf_str("dictionary"));
945 if (rc_read_mapfile(rc_conf_str("mapfile")) != 0) {
946 slprintf(msg, BUF_LEN, "RADIUS: Can't read map file %s",
947 rc_conf_str("mapfile"));
953 /**********************************************************************
954 * %FUNCTION: get_client_port
956 * ifname -- PPP interface name (e.g. "ppp7")
958 * The NAS port number (e.g. 7)
960 * Extracts the port number from the interface name
961 ***********************************************************************/
963 get_client_port(char *ifname)
966 if (sscanf(ifname, "ppp%d", &port) == 1) {
969 return rc_map2id(ifname);
972 /**********************************************************************
973 * %FUNCTION: radius_allowed_address
977 * 1 if we're allowed to use that IP address; 0 if not; -1 if we do
979 ***********************************************************************/
981 radius_allowed_address(u_int32_t addr)
983 ipcp_options *wo = &ipcp_wantoptions[0];
985 if (!rstate.choose_ip) {
986 /* If RADIUS server said any address is OK, then fine... */
987 if (rstate.any_ip_addr_ok) {
991 /* Sigh... if an address was supplied for remote host in pppd
992 options, it has to match that. */
993 if (wo->hisaddr != 0 && wo->hisaddr == addr) {
999 if (addr == rstate.ip_addr) return 1;
1003 /* Useful for other plugins */
1004 char *radius_logged_in_user(void)