]> git.ozlabs.org Git - ppp.git/blob - pppd/plugins/radius/radius.c
Large patch from Frank Cusack <fcusack@fcusack.com> to add proper
[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.3 2002/03/01 14:39:18 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         switch (vp->attribute) {
401         case PW_SERVICE_TYPE:
402             /* check for service type       */
403             /* if not FRAMED then exit      */
404             if (vp->lvalue != PW_FRAMED) {
405                 slprintf(msg, BUF_LEN, "RADIUS: wrong service type %ld for %s",
406                          vp->lvalue, rstate.user);
407                 return -1;
408             }
409             break;
410         case PW_FRAMED_PROTOCOL:
411             /* check for framed protocol type       */
412             /* if not PPP then also exit            */
413             if (vp->lvalue != PW_PPP) {
414                 slprintf(msg, BUF_LEN, "RADIUS: wrong framed protocol %ld for %s",
415                          vp->lvalue, rstate.user);
416                 return -1;
417             }
418             break;
419
420         case PW_FRAMED_IP_ADDRESS:
421             /* seting up remote IP addresses */
422             remote = vp->lvalue;
423             if (remote == 0xffffffff) {
424                 /* 0xffffffff means user should be allowed to select one */
425                 rstate.any_ip_addr_ok = 1;
426             } else if (remote != 0xfffffffe) {
427                 /* 0xfffffffe means NAS should select an ip address */
428                 remote = htonl(vp->lvalue);
429                 if (bad_ip_adrs (remote)) {
430                     slprintf(msg, BUF_LEN, "RADIUS: bad remote IP address %I for %s",
431                              remote, rstate.user);
432                     return -1;
433                 }
434                 rstate.choose_ip = 1;
435                 rstate.ip_addr = remote;
436             }
437             break;
438         }
439         vp = vp->next;
440     }
441     return 0;
442 }
443
444 /**********************************************************************
445 * %FUNCTION: radius_acct_start
446 * %ARGUMENTS:
447 *  None
448 * %RETURNS:
449 *  Nothing
450 * %DESCRIPTION:
451 *  Sends a "start" accounting message to the RADIUS server.
452 ***********************************************************************/
453 static void
454 radius_acct_start(void)
455 {
456     UINT4 av_type;
457     int result;
458     VALUE_PAIR *send = NULL;
459     ipcp_options *ho = &ipcp_hisoptions[0];
460     u_int32_t hisaddr;
461
462     if (!rstate.initialized) {
463         return;
464     }
465
466     rstate.start_time = time(NULL);
467
468     strncpy(rstate.session_id, rc_mksid(), sizeof(rstate.session_id));
469
470     rc_avpair_add(&send, PW_ACCT_SESSION_ID,
471                    rstate.session_id, 0, VENDOR_NONE);
472     rc_avpair_add(&send, PW_USER_NAME,
473                    rstate.user, 0, VENDOR_NONE);
474
475     av_type = PW_STATUS_START;
476     rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE);
477
478     av_type = PW_FRAMED;
479     rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
480
481     av_type = PW_PPP;
482     rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
483
484     if (*remote_number) {
485         rc_avpair_add(&send, PW_CALLING_STATION_ID,
486                        remote_number, 0, VENDOR_NONE);
487     }
488
489     av_type = PW_RADIUS;
490     rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
491
492
493     av_type = PW_ASYNC;
494     rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
495
496     hisaddr = ho->hisaddr;
497     av_type = htonl(hisaddr);
498     rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE);
499
500     if (rstate.acctserver) {
501         result = rc_acct_using_server(rstate.acctserver,
502                                       rstate.client_port, send);
503     } else {
504         result = rc_acct(rstate.client_port, send);
505     }
506
507     rc_avpair_free(send);
508
509     if (result != OK_RC) {
510         /* RADIUS server could be down so make this a warning */
511         syslog(LOG_WARNING,
512                 "Accounting START failed for %s", rstate.user);
513     } else {
514         rstate.accounting_started = 1;
515     }
516 }
517
518 /**********************************************************************
519 * %FUNCTION: radius_acct_stop
520 * %ARGUMENTS:
521 *  None
522 * %RETURNS:
523 *  Nothing
524 * %DESCRIPTION:
525 *  Sends a "stop" accounting message to the RADIUS server.
526 ***********************************************************************/
527 static void
528 radius_acct_stop(void)
529 {
530     UINT4 av_type;
531     VALUE_PAIR *send = NULL;
532     ipcp_options *ho = &ipcp_hisoptions[0];
533     u_int32_t hisaddr;
534     int result;
535
536     if (!rstate.initialized) {
537         return;
538     }
539
540     if (!rstate.accounting_started) {
541         return;
542     }
543
544     rstate.accounting_started = 0;
545     rc_avpair_add(&send, PW_ACCT_SESSION_ID, rstate.session_id,
546                    0, VENDOR_NONE);
547
548     rc_avpair_add(&send, PW_USER_NAME, rstate.user, 0, VENDOR_NONE);
549
550     av_type = PW_STATUS_STOP;
551     rc_avpair_add(&send, PW_ACCT_STATUS_TYPE, &av_type, 0, VENDOR_NONE);
552
553     av_type = PW_FRAMED;
554     rc_avpair_add(&send, PW_SERVICE_TYPE, &av_type, 0, VENDOR_NONE);
555
556     av_type = PW_PPP;
557     rc_avpair_add(&send, PW_FRAMED_PROTOCOL, &av_type, 0, VENDOR_NONE);
558
559     av_type = PW_RADIUS;
560     rc_avpair_add(&send, PW_ACCT_AUTHENTIC, &av_type, 0, VENDOR_NONE);
561
562
563     if (link_stats_valid) {
564         av_type = link_connect_time;
565         rc_avpair_add(&send, PW_ACCT_SESSION_TIME, &av_type, 0, VENDOR_NONE);
566
567         av_type = link_stats.bytes_out;
568         rc_avpair_add(&send, PW_ACCT_OUTPUT_OCTETS, &av_type, 0, VENDOR_NONE);
569
570         av_type = link_stats.bytes_in;
571         rc_avpair_add(&send, PW_ACCT_INPUT_OCTETS, &av_type, 0, VENDOR_NONE);
572
573         av_type = link_stats.pkts_out;
574         rc_avpair_add(&send, PW_ACCT_OUTPUT_PACKETS, &av_type, 0, VENDOR_NONE);
575
576         av_type = link_stats.pkts_in;
577         rc_avpair_add(&send, PW_ACCT_INPUT_PACKETS, &av_type, 0, VENDOR_NONE);
578     }
579
580     if (*remote_number) {
581         rc_avpair_add(&send, PW_CALLING_STATION_ID,
582                        remote_number, 0, VENDOR_NONE);
583     }
584
585     av_type = PW_ASYNC;
586     rc_avpair_add(&send, PW_NAS_PORT_TYPE, &av_type, 0, VENDOR_NONE);
587
588     hisaddr = ho->hisaddr;
589     av_type = htonl(hisaddr);
590     rc_avpair_add(&send, PW_FRAMED_IP_ADDRESS , &av_type , 0, VENDOR_NONE);
591
592     if (rstate.acctserver) {
593         result = rc_acct_using_server(rstate.acctserver,
594                                       rstate.client_port, send);
595     } else {
596         result = rc_acct(rstate.client_port, send);
597     }
598
599     if (result != OK_RC) {
600         /* RADIUS server could be down so make this a warning */
601         syslog(LOG_WARNING,
602                 "Accounting STOP failed for %s", rstate.user);
603     }
604     rc_avpair_free(send);
605 }
606
607 /**********************************************************************
608 * %FUNCTION: radius_ip_up
609 * %ARGUMENTS:
610 *  opaque -- ignored
611 *  arg -- ignored
612 * %RETURNS:
613 *  Nothing
614 * %DESCRIPTION:
615 *  Called when IPCP is up.  We'll do a start-accounting record.
616 ***********************************************************************/
617 static void
618 radius_ip_up(void *opaque, int arg)
619 {
620     radius_acct_start();
621 }
622
623 /**********************************************************************
624 * %FUNCTION: radius_ip_down
625 * %ARGUMENTS:
626 *  opaque -- ignored
627 *  arg -- ignored
628 * %RETURNS:
629 *  Nothing
630 * %DESCRIPTION:
631 *  Called when IPCP is down.  We'll do a stop-accounting record.
632 ***********************************************************************/
633 static void
634 radius_ip_down(void *opaque, int arg)
635 {
636     radius_acct_stop();
637 }
638
639 /**********************************************************************
640 * %FUNCTION: radius_init
641 * %ARGUMENTS:
642 *  msg -- buffer of size BUF_LEN for error message
643 * %RETURNS:
644 *  negative on failure; non-negative on success
645 * %DESCRIPTION:
646 *  Initializes radiusclient library
647 ***********************************************************************/
648 static int
649 radius_init(char *msg)
650 {
651     if (rstate.initialized) {
652         return 0;
653     }
654
655     if (config_file && *config_file) {
656         strlcpy(rstate.config_file, config_file, MAXPATHLEN-1);
657     }
658
659     rstate.initialized = 1;
660
661     if (rc_read_config(rstate.config_file) != 0) {
662         slprintf(msg, BUF_LEN, "RADIUS: Can't read config file %s",
663                  rstate.config_file);
664         return -1;
665     }
666
667     if (rc_read_dictionary(rc_conf_str("dictionary")) != 0) {
668         slprintf(msg, BUF_LEN, "RADIUS: Can't read dictionary file %s",
669                  rc_conf_str("dictionary"));
670         return -1;
671     }
672
673     if (rc_read_mapfile(rc_conf_str("mapfile")) != 0)   {
674         slprintf(msg, BUF_LEN, "RADIUS: Can't read map file %s",
675                  rc_conf_str("mapfile"));
676         return -1;
677     }
678     return 0;
679 }
680
681 /**********************************************************************
682 * %FUNCTION: get_client_port
683 * %ARGUMENTS:
684 *  ifname -- PPP interface name (e.g. "ppp7")
685 * %RETURNS:
686 *  The NAS port number (e.g. 7)
687 * %DESCRIPTION:
688 *  Extracts the port number from the interface name
689 ***********************************************************************/
690 static int
691 get_client_port(char *ifname)
692 {
693     int port;
694     if (sscanf(ifname, "ppp%d", &port) == 1) {
695         return port;
696     }
697     return rc_map2id(ifname);
698 }
699
700 /**********************************************************************
701 * %FUNCTION: radius_allowed_address
702 * %ARGUMENTS:
703 *  addr -- IP address
704 * %RETURNS:
705 *  1 if we're allowed to use that IP address; 0 if not; -1 if we do
706 *  not know.
707 ***********************************************************************/
708 static int
709 radius_allowed_address(u_int32_t addr)
710 {
711     ipcp_options *wo = &ipcp_wantoptions[0];
712
713     if (!rstate.choose_ip) {
714         /* If RADIUS server said any address is OK, then fine... */
715         if (rstate.any_ip_addr_ok) {
716             return 1;
717         }
718
719         /* Sigh... if an address was supplied for remote host in pppd
720            options, it has to match that.  */
721         if (wo->hisaddr != 0 && wo->hisaddr == addr) {
722             return 1;
723         }
724
725         return 0;
726     }
727     if (addr == rstate.ip_addr) return 1;
728     return 0;
729 }
730
731 /* Useful for other plugins */
732 char *radius_logged_in_user(void)
733 {
734     return rstate.user;
735 }
736