]> git.ozlabs.org Git - ppp.git/blob - pppd/plugins/radius/radius.c
fa638d0327d4fced1d478aba858d1d3515673bea
[ppp.git] / pppd / plugins / radius / radius.c
1 /***********************************************************************
2 *
3 * radius.c
4 *
5 * RADIUS plugin for pppd.  Performs PAP and CHAP authentication using
6 * RADIUS.
7 *
8 * Copyright (C) 2002 Roaring Penguin Software Inc.
9 *
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>
14 *
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.
18 *
19 * This plugin may be distributed according to the terms of the GNU
20 * General Public License, version 2 or (at your option) any later version.
21 *
22 ***********************************************************************/
23 static char const RCSID[] =
24 "$Id: radius.c,v 1.4 2002/03/01 15:16:51 dfs Exp $";
25
26 #include "pppd.h"
27 #include "chap.h"
28 #include "radiusclient.h"
29 #include "fsm.h"
30 #include "ipcp.h"
31 #include <syslog.h>
32 #include <sys/types.h>
33 #include <sys/time.h>
34
35 #define BUF_LEN 1024
36
37 static char *config_file = NULL;
38
39 static option_t Options[] = {
40     { "radius-config-file", o_string, &config_file },
41     { NULL }
42 };
43
44 static int radius_secret_check(void);
45 static int radius_pap_auth(char *user,
46                            char *passwd,
47                            char **msgp,
48                            struct wordlist **paddrs,
49                            struct wordlist **popts);
50 static int radius_chap_auth(char *user,
51                             u_char *remmd,
52                             int remmd_len,
53                             chap_state *cstate);
54
55 static void radius_ip_up(void *opaque, int arg);
56 static void radius_ip_down(void *opaque, int arg);
57 static void make_username_realm(char *user);
58 static int radius_setparams(VALUE_PAIR *vp, char *msg);
59 static void radius_choose_ip(u_int32_t *addrp);
60 static int radius_init(char *msg);
61 static int get_client_port(char *ifname);
62 static int radius_allowed_address(u_int32_t addr);
63
64 #ifndef MAXSESSIONID
65 #define MAXSESSIONID 32
66 #endif
67
68 struct radius_state {
69     int accounting_started;
70     int initialized;
71     int client_port;
72     int choose_ip;
73     int any_ip_addr_ok;
74     int done_chap_once;
75     u_int32_t ip_addr;
76     char user[MAXNAMELEN];
77     char config_file[MAXPATHLEN];
78     char session_id[MAXSESSIONID + 1];
79     time_t start_time;
80     SERVER *authserver;         /* Authentication server to use */
81     SERVER *acctserver;         /* Accounting server to use */
82 };
83
84 void (*radius_attributes_hook)(VALUE_PAIR *) = NULL;
85
86 /* The pre_auth_hook MAY set authserver and acctserver if it wants.
87    In that case, they override the values in the radiusclient.conf file */
88 void (*radius_pre_auth_hook)(char const *user,
89                              SERVER **authserver,
90                              SERVER **acctserver) = NULL;
91
92 static struct radius_state rstate;
93
94 char pppd_version[] = VERSION;
95
96 /**********************************************************************
97 * %FUNCTION: plugin_init
98 * %ARGUMENTS:
99 *  None
100 * %RETURNS:
101 *  Nothing
102 * %DESCRIPTION:
103 *  Initializes RADIUS plugin.
104 ***********************************************************************/
105 void
106 plugin_init(void)
107 {
108     pap_check_hook = radius_secret_check;
109     pap_auth_hook = radius_pap_auth;
110
111     chap_check_hook = radius_secret_check;
112     chap_auth_hook = radius_chap_auth;
113
114     ip_choose_hook = radius_choose_ip;
115     allowed_address_hook = radius_allowed_address;
116
117     add_notifier(&ip_up_notifier, radius_ip_up, NULL);
118     add_notifier(&ip_down_notifier, radius_ip_down, NULL);
119
120     memset(&rstate, 0, sizeof(rstate));
121
122     strlcpy(rstate.config_file, "/etc/radiusclient/radiusclient.conf",
123             sizeof(rstate.config_file));
124
125     add_options(Options);
126
127     info("RADIUS plugin initialized.");
128 }
129
130 /**********************************************************************
131 * %FUNCTION: radius_secret_check
132 * %ARGUMENTS:
133 *  None
134 * %RETURNS:
135 *  1 -- we are ALWAYS willing to supply a secret. :-)
136 * %DESCRIPTION:
137 * Tells pppd that we will try to authenticate the peer, and not to
138 * worry about looking in /etc/ppp/*-secrets
139 ***********************************************************************/
140 static int
141 radius_secret_check(void)
142 {
143     return 1;
144 }
145
146 /**********************************************************************
147 * %FUNCTION: radius_choose_ip
148 * %ARGUMENTS:
149 *  addrp -- where to store the IP address
150 * %RETURNS:
151 *  Nothing
152 * %DESCRIPTION:
153 *  If RADIUS server has specified an IP address, it is stored in *addrp.
154 ***********************************************************************/
155 static void
156 radius_choose_ip(u_int32_t *addrp)
157 {
158     if (rstate.choose_ip) {
159         *addrp = rstate.ip_addr;
160     }
161 }
162
163 /**********************************************************************
164 * %FUNCTION: radius_pap_auth
165 * %ARGUMENTS:
166 *  user -- user-name of peer
167 *  passwd -- password supplied by peer
168 *  msgp -- Message which will be sent in PAP response
169 *  paddrs -- set to a list of possible peer IP addresses
170 *  popts -- set to a list of additional pppd options
171 * %RETURNS:
172 *  1 if we can authenticate, -1 if we cannot.
173 * %DESCRIPTION:
174 * Performs PAP authentication using RADIUS
175 ***********************************************************************/
176 static int
177 radius_pap_auth(char *user,
178                 char *passwd,
179                 char **msgp,
180                 struct wordlist **paddrs,
181                 struct wordlist **popts)
182 {
183     VALUE_PAIR *send, *received;
184     UINT4 av_type;
185     int result;
186     static char radius_msg[BUF_LEN];
187
188     radius_msg[0] = 0;
189     *msgp = radius_msg;
190
191     if (radius_init(radius_msg) < 0) {
192         return 0;
193     }
194
195     /* Put user with potentially realm added in rstate.user */
196     make_username_realm(user);
197
198     if (radius_pre_auth_hook) {
199         radius_pre_auth_hook(rstate.user,
200                              &rstate.authserver,
201                              &rstate.acctserver);
202     }
203
204     send = NULL;
205     received = NULL;
206
207     /* Hack... the "port" is the ppp interface number.  Should really be
208        the tty */
209     rstate.client_port = get_client_port(ifname);
210
211     av_type = PW_FRAMED;
212     rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
213
214     av_type = PW_PPP;
215     rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
216
217     rc_avpair_add(&send, PW_USER_NAME, rstate.user , 0, VENDOR_NONE);
218     rc_avpair_add(&send, PW_USER_PASSWORD, passwd, 0, VENDOR_NONE);
219     if (*remote_number) {
220         rc_avpair_add(&send, PW_CALLING_STATION_ID, remote_number, 0,
221                        VENDOR_NONE);
222     }
223
224     if (rstate.authserver) {
225         result = rc_auth_using_server(rstate.authserver,
226                                       rstate.client_port, send,
227                                       &received, radius_msg);
228     } else {
229         result = rc_auth(rstate.client_port, send, &received, radius_msg);
230     }
231
232     if (result == OK_RC) {
233         if (radius_setparams(received, radius_msg) < 0) {
234             result = ERROR_RC;
235         }
236     }
237
238     /* free value pairs */
239     rc_avpair_free(received);
240     rc_avpair_free(send);
241
242     return (result == OK_RC) ? 1 : 0;
243 }
244
245 /**********************************************************************
246 * %FUNCTION: radius_chap_auth
247 * %ARGUMENTS:
248 *  user -- user-name of peer
249 *  remmd -- hash received from peer
250 *  remmd_len -- length of remmd
251 *  cstate -- pppd's chap_state structure
252 * %RETURNS:
253 *  CHAP_SUCCESS if we can authenticate, CHAP_FAILURE if we cannot.
254 * %DESCRIPTION:
255 * Performs CHAP authentication using RADIUS
256 ***********************************************************************/
257 static int
258 radius_chap_auth(char *user,
259                  u_char *remmd,
260                  int remmd_len,
261                  chap_state *cstate)
262 {
263     VALUE_PAIR *send, *received;
264     UINT4 av_type;
265     static char radius_msg[BUF_LEN];
266     int result;
267     u_char cpassword[MD5_SIGNATURE_SIZE+1];
268     radius_msg[0] = 0;
269
270     if (radius_init(radius_msg) < 0) {
271         error("%s", radius_msg);
272         return CHAP_FAILURE;
273     }
274
275     /* we handle md5 digest at the moment */
276     if (cstate->chal_type != CHAP_DIGEST_MD5) {
277         error("RADIUS: Challenge type not MD5");
278         return CHAP_FAILURE;
279     }
280
281     /* Put user with potentially realm added in rstate.user */
282     if (!rstate.done_chap_once) {
283         make_username_realm(user);
284         rstate.client_port = get_client_port (ifname);
285         if (radius_pre_auth_hook) {
286             radius_pre_auth_hook(rstate.user,
287                                  &rstate.authserver,
288                                  &rstate.acctserver);
289         }
290     }
291
292     send = received = NULL;
293
294     av_type = PW_FRAMED;
295     rc_avpair_add (&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
296
297     av_type = PW_PPP;
298     rc_avpair_add (&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
299
300     rc_avpair_add (&send, PW_USER_NAME, rstate.user , 0, VENDOR_NONE);
301
302     /*
303      * add the CHAP-Password and CHAP-Challenge fields
304      */
305
306     cpassword[0] = cstate->chal_id;
307
308     memcpy(&cpassword[1], remmd, MD5_SIGNATURE_SIZE);
309
310     rc_avpair_add(&send, PW_CHAP_PASSWORD, cpassword, MD5_SIGNATURE_SIZE + 1, VENDOR_NONE);
311
312     rc_avpair_add(&send, PW_CHAP_CHALLENGE, cstate->challenge, cstate->chal_len, VENDOR_NONE);
313
314     /*
315      * make authentication with RADIUS server
316      */
317
318     if (rstate.authserver) {
319         result = rc_auth_using_server(rstate.authserver,
320                                       rstate.client_port, send,
321                                       &received, radius_msg);
322     } else {
323         result = rc_auth(rstate.client_port, send, &received, radius_msg);
324     }
325
326     if (result == OK_RC) {
327         if (!rstate.done_chap_once) {
328             if (radius_setparams(received, radius_msg) < 0) {
329                 error("%s", radius_msg);
330                 result = ERROR_RC;
331             } else {
332                 rstate.done_chap_once = 1;
333             }
334         }
335     }
336
337     rc_avpair_free(received);
338     rc_avpair_free (send);
339     return (result == OK_RC) ? CHAP_SUCCESS : CHAP_FAILURE;
340 }
341
342 /**********************************************************************
343 * %FUNCTION: make_username_realm
344 * %ARGUMENTS:
345 *  user -- the user given to pppd
346 * %RETURNS:
347 *  Nothing
348 * %DESCRIPTION:
349 *  Copies user into rstate.user.  If it lacks a realm (no "@domain" part),
350 * then the default realm from the radiusclient config file is added.
351 ***********************************************************************/
352 static void
353 make_username_realm(char *user)
354 {
355     char *default_realm;
356
357     if ( user != NULL ) {
358         strlcpy(rstate.user, user, sizeof(rstate.user));
359     }  else {
360         rstate.user[0] = 0;
361     }
362
363     default_realm = rc_conf_str("default_realm");
364
365     if (!strchr(rstate.user, '@') &&
366         default_realm &&
367         (*default_realm != '\0')) {
368         strlcat(rstate.user, "@", sizeof(rstate.user));
369         strlcat(rstate.user, default_realm, sizeof(rstate.user));
370     }
371 }
372
373 /**********************************************************************
374 * %FUNCTION: radius_setparams
375 * %ARGUMENTS:
376 *  vp -- received value-pairs
377 *  msg -- buffer in which to place error message.  Holds up to BUF_LEN chars
378 * %RETURNS:
379 *  >= 0 on success; -1 on failure
380 * %DESCRIPTION:
381 *  Parses attributes sent by RADIUS server and sets them in pppd.  Currently,
382 *  used only to set IP address.
383 ***********************************************************************/
384 static int
385 radius_setparams(VALUE_PAIR *vp, char *msg)
386 {
387     u_int32_t remote;
388
389     /* Send RADIUS attributes to anyone else who might be interested */
390     if (radius_attributes_hook) {
391         (*radius_attributes_hook)(vp);
392     }
393
394     /*
395      * service type (if not framed then quit),
396      * new IP address (RADIUS can define static IP for some users),
397      */
398
399     while (vp) {
400         if (vp->vendorcode == VENDOR_NONE) {
401             switch (vp->attribute) {
402             case PW_SERVICE_TYPE:
403                 /* check for service type       */
404                 /* if not FRAMED then exit      */
405                 if (vp->lvalue != PW_FRAMED) {
406                     slprintf(msg, BUF_LEN, "RADIUS: wrong service type %ld for %s",
407                              vp->lvalue, rstate.user);
408                     return -1;
409                 }
410                 break;
411             case PW_FRAMED_PROTOCOL:
412                 /* check for framed protocol type       */
413                 /* if not PPP then also exit            */
414                 if (vp->lvalue != PW_PPP) {
415                     slprintf(msg, BUF_LEN, "RADIUS: wrong framed protocol %ld for %s",
416                              vp->lvalue, rstate.user);
417                     return -1;
418                 }
419                 break;
420
421             case PW_FRAMED_IP_ADDRESS:
422                 /* seting up remote IP addresses */
423                 remote = vp->lvalue;
424                 if (remote == 0xffffffff) {
425                     /* 0xffffffff means user should be allowed to select one */
426                     rstate.any_ip_addr_ok = 1;
427                 } else if (remote != 0xfffffffe) {
428                     /* 0xfffffffe means NAS should select an ip address */
429                     remote = htonl(vp->lvalue);
430                     if (bad_ip_adrs (remote)) {
431                         slprintf(msg, BUF_LEN, "RADIUS: bad remote IP address %I for %s",
432                                  remote, rstate.user);
433                         return -1;
434                     }
435                     rstate.choose_ip = 1;
436                     rstate.ip_addr = remote;
437                 }
438             break;
439             }
440         }
441         vp = vp->next;
442     }
443     return 0;
444 }
445
446 /**********************************************************************
447 * %FUNCTION: radius_acct_start
448 * %ARGUMENTS:
449 *  None
450 * %RETURNS:
451 *  Nothing
452 * %DESCRIPTION:
453 *  Sends a "start" accounting message to the RADIUS server.
454 ***********************************************************************/
455 static void
456 radius_acct_start(void)
457 {
458     UINT4 av_type;
459     int result;
460     VALUE_PAIR *send = NULL;
461     ipcp_options *ho = &ipcp_hisoptions[0];
462     u_int32_t hisaddr;
463
464     if (!rstate.initialized) {
465         return;
466     }
467
468     rstate.start_time = time(NULL);
469
470     strncpy(rstate.session_id, rc_mksid(), sizeof(rstate.session_id));
471
472     rc_avpair_add(&send, PW_ACCT_SESSION_ID,
473                    rstate.session_id, 0, VENDOR_NONE);
474     rc_avpair_add(&send, PW_USER_NAME,
475                    rstate.user, 0, VENDOR_NONE);
476
477     av_type = PW_STATUS_START;
478     rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE);
479
480     av_type = PW_FRAMED;
481     rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
482
483     av_type = PW_PPP;
484     rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
485
486     if (*remote_number) {
487         rc_avpair_add(&send, PW_CALLING_STATION_ID,
488                        remote_number, 0, VENDOR_NONE);
489     }
490
491     av_type = PW_RADIUS;
492     rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
493
494
495     av_type = PW_ASYNC;
496     rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
497
498     hisaddr = ho->hisaddr;
499     av_type = htonl(hisaddr);
500     rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE);
501
502     if (rstate.acctserver) {
503         result = rc_acct_using_server(rstate.acctserver,
504                                       rstate.client_port, send);
505     } else {
506         result = rc_acct(rstate.client_port, send);
507     }
508
509     rc_avpair_free(send);
510
511     if (result != OK_RC) {
512         /* RADIUS server could be down so make this a warning */
513         syslog(LOG_WARNING,
514                 "Accounting START failed for %s", rstate.user);
515     } else {
516         rstate.accounting_started = 1;
517     }
518 }
519
520 /**********************************************************************
521 * %FUNCTION: radius_acct_stop
522 * %ARGUMENTS:
523 *  None
524 * %RETURNS:
525 *  Nothing
526 * %DESCRIPTION:
527 *  Sends a "stop" accounting message to the RADIUS server.
528 ***********************************************************************/
529 static void
530 radius_acct_stop(void)
531 {
532     UINT4 av_type;
533     VALUE_PAIR *send = NULL;
534     ipcp_options *ho = &ipcp_hisoptions[0];
535     u_int32_t hisaddr;
536     int result;
537
538     if (!rstate.initialized) {
539         return;
540     }
541
542     if (!rstate.accounting_started) {
543         return;
544     }
545
546     rstate.accounting_started = 0;
547     rc_avpair_add(&send, PW_ACCT_SESSION_ID, rstate.session_id,
548                    0, VENDOR_NONE);
549
550     rc_avpair_add(&send, PW_USER_NAME, rstate.user, 0, VENDOR_NONE);
551
552     av_type = PW_STATUS_STOP;
553     rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE);
554
555     av_type = PW_FRAMED;
556     rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
557
558     av_type = PW_PPP;
559     rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
560
561     av_type = PW_RADIUS;
562     rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
563
564
565     if (link_stats_valid) {
566         av_type = link_connect_time;
567         rc_avpair_add(&send, PW_ACCT_SESSION_TIME, &av_type, 0, VENDOR_NONE);
568
569         av_type = link_stats.bytes_out;
570         rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);
571
572         av_type = link_stats.bytes_in;
573         rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);
574
575         av_type = link_stats.pkts_out;
576         rc_avpair_add(&send, PW_ACCT_OUTPUT_PACKETS, &av_type, 0, VENDOR_NONE);
577
578         av_type = link_stats.pkts_in;
579         rc_avpair_add(&send, PW_ACCT_INPUT_PACKETS, &av_type, 0, VENDOR_NONE);
580     }
581
582     if (*remote_number) {
583         rc_avpair_add(&send, PW_CALLING_STATION_ID,
584                        remote_number, 0, VENDOR_NONE);
585     }
586
587     av_type = PW_ASYNC;
588     rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
589
590     hisaddr = ho->hisaddr;
591     av_type = htonl(hisaddr);
592     rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE);
593
594     if (rstate.acctserver) {
595         result = rc_acct_using_server(rstate.acctserver,
596                                       rstate.client_port, send);
597     } else {
598         result = rc_acct(rstate.client_port, send);
599     }
600
601     if (result != OK_RC) {
602         /* RADIUS server could be down so make this a warning */
603         syslog(LOG_WARNING,
604                 "Accounting STOP failed for %s", rstate.user);
605     }
606     rc_avpair_free(send);
607 }
608
609 /**********************************************************************
610 * %FUNCTION: radius_ip_up
611 * %ARGUMENTS:
612 *  opaque -- ignored
613 *  arg -- ignored
614 * %RETURNS:
615 *  Nothing
616 * %DESCRIPTION:
617 *  Called when IPCP is up.  We'll do a start-accounting record.
618 ***********************************************************************/
619 static void
620 radius_ip_up(void *opaque, int arg)
621 {
622     radius_acct_start();
623 }
624
625 /**********************************************************************
626 * %FUNCTION: radius_ip_down
627 * %ARGUMENTS:
628 *  opaque -- ignored
629 *  arg -- ignored
630 * %RETURNS:
631 *  Nothing
632 * %DESCRIPTION:
633 *  Called when IPCP is down.  We'll do a stop-accounting record.
634 ***********************************************************************/
635 static void
636 radius_ip_down(void *opaque, int arg)
637 {
638     radius_acct_stop();
639 }
640
641 /**********************************************************************
642 * %FUNCTION: radius_init
643 * %ARGUMENTS:
644 *  msg -- buffer of size BUF_LEN for error message
645 * %RETURNS:
646 *  negative on failure; non-negative on success
647 * %DESCRIPTION:
648 *  Initializes radiusclient library
649 ***********************************************************************/
650 static int
651 radius_init(char *msg)
652 {
653     if (rstate.initialized) {
654         return 0;
655     }
656
657     if (config_file && *config_file) {
658         strlcpy(rstate.config_file, config_file, MAXPATHLEN-1);
659     }
660
661     rstate.initialized = 1;
662
663     if (rc_read_config(rstate.config_file) != 0) {
664         slprintf(msg, BUF_LEN, "RADIUS: Can't read config file %s",
665                  rstate.config_file);
666         return -1;
667     }
668
669     if (rc_read_dictionary(rc_conf_str("dictionary")) != 0) {
670         slprintf(msg, BUF_LEN, "RADIUS: Can't read dictionary file %s",
671                  rc_conf_str("dictionary"));
672         return -1;
673     }
674
675     if (rc_read_mapfile(rc_conf_str("mapfile")) != 0)   {
676         slprintf(msg, BUF_LEN, "RADIUS: Can't read map file %s",
677                  rc_conf_str("mapfile"));
678         return -1;
679     }
680     return 0;
681 }
682
683 /**********************************************************************
684 * %FUNCTION: get_client_port
685 * %ARGUMENTS:
686 *  ifname -- PPP interface name (e.g. "ppp7")
687 * %RETURNS:
688 *  The NAS port number (e.g. 7)
689 * %DESCRIPTION:
690 *  Extracts the port number from the interface name
691 ***********************************************************************/
692 static int
693 get_client_port(char *ifname)
694 {
695     int port;
696     if (sscanf(ifname, "ppp%d", &port) == 1) {
697         return port;
698     }
699     return rc_map2id(ifname);
700 }
701
702 /**********************************************************************
703 * %FUNCTION: radius_allowed_address
704 * %ARGUMENTS:
705 *  addr -- IP address
706 * %RETURNS:
707 *  1 if we're allowed to use that IP address; 0 if not; -1 if we do
708 *  not know.
709 ***********************************************************************/
710 static int
711 radius_allowed_address(u_int32_t addr)
712 {
713     ipcp_options *wo = &ipcp_wantoptions[0];
714
715     if (!rstate.choose_ip) {
716         /* If RADIUS server said any address is OK, then fine... */
717         if (rstate.any_ip_addr_ok) {
718             return 1;
719         }
720
721         /* Sigh... if an address was supplied for remote host in pppd
722            options, it has to match that.  */
723         if (wo->hisaddr != 0 && wo->hisaddr == addr) {
724             return 1;
725         }
726
727         return 0;
728     }
729     if (addr == rstate.ip_addr) return 1;
730     return 0;
731 }
732
733 /* Useful for other plugins */
734 char *radius_logged_in_user(void)
735 {
736     return rstate.user;
737 }