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