]> Joshua Wise's Git repositories - netwatch.git/blame_incremental - lwip/src/netif/ppp/auth.c
Merge nyus.joshuawise.com:/storage/git/netwatch
[netwatch.git] / lwip / src / netif / ppp / auth.c
... / ...
CommitLineData
1/*****************************************************************************
2* auth.c - Network Authentication and Phase Control program file.
3*
4* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
5* Copyright (c) 1997 by Global Election Systems Inc. All rights reserved.
6*
7* The authors hereby grant permission to use, copy, modify, distribute,
8* and license this software and its documentation for any purpose, provided
9* that existing copyright notices are retained in all copies and that this
10* notice and the following disclaimer are included verbatim in any
11* distributions. No written agreement, license, or royalty fee is required
12* for any of the authorized uses.
13*
14* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25******************************************************************************
26* REVISION HISTORY
27*
28* 03-01-01 Marc Boucher <marc@mbsi.ca>
29* Ported to lwIP.
30* 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
31* Ported from public pppd code.
32*****************************************************************************/
33/*
34 * auth.c - PPP authentication and phase control.
35 *
36 * Copyright (c) 1993 The Australian National University.
37 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms are permitted
40 * provided that the above copyright notice and this paragraph are
41 * duplicated in all such forms and that any documentation,
42 * advertising materials, and other materials related to such
43 * distribution and use acknowledge that the software was developed
44 * by the Australian National University. The name of the University
45 * may not be used to endorse or promote products derived from this
46 * software without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
50 *
51 * Copyright (c) 1989 Carnegie Mellon University.
52 * All rights reserved.
53 *
54 * Redistribution and use in source and binary forms are permitted
55 * provided that the above copyright notice and this paragraph are
56 * duplicated in all such forms and that any documentation,
57 * advertising materials, and other materials related to such
58 * distribution and use acknowledge that the software was developed
59 * by Carnegie Mellon University. The name of the
60 * University may not be used to endorse or promote products derived
61 * from this software without specific prior written permission.
62 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
63 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
64 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
65 */
66
67#include "lwip/opt.h"
68
69#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
70
71#include "ppp.h"
72#include "pppdebug.h"
73
74#include "fsm.h"
75#include "lcp.h"
76#include "pap.h"
77#include "chap.h"
78#include "auth.h"
79#include "ipcp.h"
80
81#if CBCP_SUPPORT
82#include "cbcp.h"
83#endif /* CBCP_SUPPORT */
84
85/*************************/
86/*** LOCAL DEFINITIONS ***/
87/*************************/
88
89/* Bits in auth_pending[] */
90#define PAP_WITHPEER 1
91#define PAP_PEER 2
92#define CHAP_WITHPEER 4
93#define CHAP_PEER 8
94
95
96/************************/
97/*** LOCAL DATA TYPES ***/
98/************************/
99/* Used for storing a sequence of words. Usually malloced. */
100struct wordlist {
101 struct wordlist *next;
102 char word[1];
103};
104
105
106/***********************************/
107/*** LOCAL FUNCTION DECLARATIONS ***/
108/***********************************/
109extern char *crypt (const char *, const char *);
110
111/* Prototypes for procedures local to this file. */
112
113static void network_phase (int);
114static void check_idle (void *);
115static void connect_time_expired (void *);
116#if 0
117static int login (char *, char *, char **, int *);
118#endif
119static void logout (void);
120static int null_login (int);
121static int get_pap_passwd (int, char *, char *);
122static int have_pap_secret (void);
123static int have_chap_secret (char *, char *, u32_t);
124static int ip_addr_check (u32_t, struct wordlist *);
125#if 0 /* PAP_SUPPORT || CHAP_SUPPORT */
126static void set_allowed_addrs(int unit, struct wordlist *addrs);
127static void free_wordlist (struct wordlist *);
128#endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */
129#if CBCP_SUPPORT
130static void callback_phase (int);
131#endif /* CBCP_SUPPORT */
132
133
134/******************************/
135/*** PUBLIC DATA STRUCTURES ***/
136/******************************/
137
138
139/*****************************/
140/*** LOCAL DATA STRUCTURES ***/
141/*****************************/
142#if PAP_SUPPORT || CHAP_SUPPORT
143/* The name by which the peer authenticated itself to us. */
144static char peer_authname[MAXNAMELEN];
145#endif /* PAP_SUPPORT || CHAP_SUPPORT */
146
147/* Records which authentication operations haven't completed yet. */
148static int auth_pending[NUM_PPP];
149
150/* Set if we have successfully called login() */
151static int logged_in;
152
153/* Set if we have run the /etc/ppp/auth-up script. */
154static int did_authup;
155
156/* List of addresses which the peer may use. */
157static struct wordlist *addresses[NUM_PPP];
158
159/* Number of network protocols which we have opened. */
160static int num_np_open;
161
162/* Number of network protocols which have come up. */
163static int num_np_up;
164
165#if PAP_SUPPORT || CHAP_SUPPORT
166/* Set if we got the contents of passwd[] from the pap-secrets file. */
167static int passwd_from_file;
168#endif /* PAP_SUPPORT || CHAP_SUPPORT */
169
170
171/***********************************/
172/*** PUBLIC FUNCTION DEFINITIONS ***/
173/***********************************/
174/*
175 * An Open on LCP has requested a change from Dead to Establish phase.
176 * Do what's necessary to bring the physical layer up.
177 */
178void
179link_required(int unit)
180{
181 LWIP_UNUSED_ARG(unit);
182
183 AUTHDEBUG((LOG_INFO, "link_required: %d\n", unit));
184}
185
186/*
187 * LCP has terminated the link; go to the Dead phase and take the
188 * physical layer down.
189 */
190void
191link_terminated(int unit)
192{
193 AUTHDEBUG((LOG_INFO, "link_terminated: %d\n", unit));
194 if (lcp_phase[unit] == PHASE_DEAD) {
195 return;
196 }
197 if (logged_in) {
198 logout();
199 }
200 lcp_phase[unit] = PHASE_DEAD;
201 AUTHDEBUG((LOG_NOTICE, "Connection terminated.\n"));
202 pppLinkTerminated(unit);
203}
204
205/*
206 * LCP has gone down; it will either die or try to re-establish.
207 */
208void
209link_down(int unit)
210{
211 int i;
212 struct protent *protp;
213
214 AUTHDEBUG((LOG_INFO, "link_down: %d\n", unit));
215 if (did_authup) {
216 /* XXX Do link down processing. */
217 did_authup = 0;
218 }
219 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
220 if (!protp->enabled_flag) {
221 continue;
222 }
223 if (protp->protocol != PPP_LCP && protp->lowerdown != NULL) {
224 (*protp->lowerdown)(unit);
225 }
226 if (protp->protocol < 0xC000 && protp->close != NULL) {
227 (*protp->close)(unit, "LCP down");
228 }
229 }
230 num_np_open = 0;
231 num_np_up = 0;
232 if (lcp_phase[unit] != PHASE_DEAD) {
233 lcp_phase[unit] = PHASE_TERMINATE;
234 }
235 pppLinkDown(unit);
236}
237
238/*
239 * The link is established.
240 * Proceed to the Dead, Authenticate or Network phase as appropriate.
241 */
242void
243link_established(int unit)
244{
245 int auth;
246 int i;
247 struct protent *protp;
248 lcp_options *wo = &lcp_wantoptions[unit];
249 lcp_options *go = &lcp_gotoptions[unit];
250#if PAP_SUPPORT || CHAP_SUPPORT
251 lcp_options *ho = &lcp_hisoptions[unit];
252#endif /* PAP_SUPPORT || CHAP_SUPPORT */
253
254 AUTHDEBUG((LOG_INFO, "link_established: %d\n", unit));
255 /*
256 * Tell higher-level protocols that LCP is up.
257 */
258 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
259 if (protp->protocol != PPP_LCP && protp->enabled_flag && protp->lowerup != NULL) {
260 (*protp->lowerup)(unit);
261 }
262 }
263 if (ppp_settings.auth_required && !(go->neg_chap || go->neg_upap)) {
264 /*
265 * We wanted the peer to authenticate itself, and it refused:
266 * treat it as though it authenticated with PAP using a username
267 * of "" and a password of "". If that's not OK, boot it out.
268 */
269 if (!wo->neg_upap || !null_login(unit)) {
270 AUTHDEBUG((LOG_WARNING, "peer refused to authenticate\n"));
271 lcp_close(unit, "peer refused to authenticate");
272 return;
273 }
274 }
275
276 lcp_phase[unit] = PHASE_AUTHENTICATE;
277 auth = 0;
278#if CHAP_SUPPORT
279 if (go->neg_chap) {
280 ChapAuthPeer(unit, ppp_settings.our_name, go->chap_mdtype);
281 auth |= CHAP_PEER;
282 }
283#endif /* CHAP_SUPPORT */
284#if PAP_SUPPORT && CHAP_SUPPORT
285 else
286#endif /* PAP_SUPPORT && CHAP_SUPPORT */
287#if PAP_SUPPORT
288 if (go->neg_upap) {
289 upap_authpeer(unit);
290 auth |= PAP_PEER;
291 }
292#endif /* PAP_SUPPORT */
293#if CHAP_SUPPORT
294 if (ho->neg_chap) {
295 ChapAuthWithPeer(unit, ppp_settings.user, ho->chap_mdtype);
296 auth |= CHAP_WITHPEER;
297 }
298#endif /* CHAP_SUPPORT */
299#if PAP_SUPPORT && CHAP_SUPPORT
300 else
301#endif /* PAP_SUPPORT && CHAP_SUPPORT */
302#if PAP_SUPPORT
303 if (ho->neg_upap) {
304 if (ppp_settings.passwd[0] == 0) {
305 passwd_from_file = 1;
306 if (!get_pap_passwd(unit, ppp_settings.user, ppp_settings.passwd)) {
307 AUTHDEBUG((LOG_ERR, "No secret found for PAP login\n"));
308 }
309 }
310 upap_authwithpeer(unit, ppp_settings.user, ppp_settings.passwd);
311 auth |= PAP_WITHPEER;
312 }
313#endif /* PAP_SUPPORT */
314 auth_pending[unit] = auth;
315
316 if (!auth) {
317 network_phase(unit);
318 }
319}
320
321/*
322 * The peer has failed to authenticate himself using `protocol'.
323 */
324void
325auth_peer_fail(int unit, u16_t protocol)
326{
327 LWIP_UNUSED_ARG(protocol);
328
329 AUTHDEBUG((LOG_INFO, "auth_peer_fail: %d proto=%X\n", unit, protocol));
330 /*
331 * Authentication failure: take the link down
332 */
333 lcp_close(unit, "Authentication failed");
334}
335
336
337#if PAP_SUPPORT || CHAP_SUPPORT
338/*
339 * The peer has been successfully authenticated using `protocol'.
340 */
341void
342auth_peer_success(int unit, u16_t protocol, char *name, int namelen)
343{
344 int pbit;
345
346 AUTHDEBUG((LOG_INFO, "auth_peer_success: %d proto=%X\n", unit, protocol));
347 switch (protocol) {
348 case PPP_CHAP:
349 pbit = CHAP_PEER;
350 break;
351 case PPP_PAP:
352 pbit = PAP_PEER;
353 break;
354 default:
355 AUTHDEBUG((LOG_WARNING, "auth_peer_success: unknown protocol %x\n", protocol));
356 return;
357 }
358
359 /*
360 * Save the authenticated name of the peer for later.
361 */
362 if (namelen > sizeof(peer_authname) - 1) {
363 namelen = sizeof(peer_authname) - 1;
364 }
365 BCOPY(name, peer_authname, namelen);
366 peer_authname[namelen] = 0;
367
368 /*
369 * If there is no more authentication still to be done,
370 * proceed to the network (or callback) phase.
371 */
372 if ((auth_pending[unit] &= ~pbit) == 0) {
373 network_phase(unit);
374 }
375}
376
377/*
378 * We have failed to authenticate ourselves to the peer using `protocol'.
379 */
380void
381auth_withpeer_fail(int unit, u16_t protocol)
382{
383 int errCode = PPPERR_AUTHFAIL;
384
385 LWIP_UNUSED_ARG(protocol);
386
387 AUTHDEBUG((LOG_INFO, "auth_withpeer_fail: %d proto=%X\n", unit, protocol));
388 if (passwd_from_file) {
389 BZERO(ppp_settings.passwd, MAXSECRETLEN);
390 }
391 /*
392 * XXX Warning: the unit number indicates the interface which is
393 * not necessarily the PPP connection. It works here as long
394 * as we are only supporting PPP interfaces.
395 */
396 pppIOCtl(unit, PPPCTLS_ERRCODE, &errCode);
397
398 /*
399 * We've failed to authenticate ourselves to our peer.
400 * He'll probably take the link down, and there's not much
401 * we can do except wait for that.
402 */
403}
404
405/*
406 * We have successfully authenticated ourselves with the peer using `protocol'.
407 */
408void
409auth_withpeer_success(int unit, u16_t protocol)
410{
411 int pbit;
412
413 AUTHDEBUG((LOG_INFO, "auth_withpeer_success: %d proto=%X\n", unit, protocol));
414 switch (protocol) {
415 case PPP_CHAP:
416 pbit = CHAP_WITHPEER;
417 break;
418 case PPP_PAP:
419 if (passwd_from_file) {
420 BZERO(ppp_settings.passwd, MAXSECRETLEN);
421 }
422 pbit = PAP_WITHPEER;
423 break;
424 default:
425 AUTHDEBUG((LOG_WARNING, "auth_peer_success: unknown protocol %x\n", protocol));
426 pbit = 0;
427 }
428
429 /*
430 * If there is no more authentication still being done,
431 * proceed to the network (or callback) phase.
432 */
433 if ((auth_pending[unit] &= ~pbit) == 0) {
434 network_phase(unit);
435 }
436}
437#endif /* PAP_SUPPORT || CHAP_SUPPORT */
438
439
440/*
441 * np_up - a network protocol has come up.
442 */
443void
444np_up(int unit, u16_t proto)
445{
446 LWIP_UNUSED_ARG(unit);
447 LWIP_UNUSED_ARG(proto);
448
449 AUTHDEBUG((LOG_INFO, "np_up: %d proto=%X\n", unit, proto));
450 if (num_np_up == 0) {
451 AUTHDEBUG((LOG_INFO, "np_up: maxconnect=%d idle_time_limit=%d\n",ppp_settings.maxconnect,ppp_settings.idle_time_limit));
452 /*
453 * At this point we consider that the link has come up successfully.
454 */
455 if (ppp_settings.idle_time_limit > 0) {
456 TIMEOUT(check_idle, NULL, ppp_settings.idle_time_limit);
457 }
458
459 /*
460 * Set a timeout to close the connection once the maximum
461 * connect time has expired.
462 */
463 if (ppp_settings.maxconnect > 0) {
464 TIMEOUT(connect_time_expired, 0, ppp_settings.maxconnect);
465 }
466 }
467 ++num_np_up;
468}
469
470/*
471 * np_down - a network protocol has gone down.
472 */
473void
474np_down(int unit, u16_t proto)
475{
476 LWIP_UNUSED_ARG(unit);
477 LWIP_UNUSED_ARG(proto);
478
479 AUTHDEBUG((LOG_INFO, "np_down: %d proto=%X\n", unit, proto));
480 if (--num_np_up == 0 && ppp_settings.idle_time_limit > 0) {
481 UNTIMEOUT(check_idle, NULL);
482 }
483}
484
485/*
486 * np_finished - a network protocol has finished using the link.
487 */
488void
489np_finished(int unit, u16_t proto)
490{
491 LWIP_UNUSED_ARG(unit);
492 LWIP_UNUSED_ARG(proto);
493
494 AUTHDEBUG((LOG_INFO, "np_finished: %d proto=%X\n", unit, proto));
495 if (--num_np_open <= 0) {
496 /* no further use for the link: shut up shop. */
497 lcp_close(0, "No network protocols running");
498 }
499}
500
501/*
502 * auth_reset - called when LCP is starting negotiations to recheck
503 * authentication options, i.e. whether we have appropriate secrets
504 * to use for authenticating ourselves and/or the peer.
505 */
506void
507auth_reset(int unit)
508{
509 lcp_options *go = &lcp_gotoptions[unit];
510 lcp_options *ao = &lcp_allowoptions[0];
511 ipcp_options *ipwo = &ipcp_wantoptions[0];
512 u32_t remote;
513
514 AUTHDEBUG((LOG_INFO, "auth_reset: %d\n", unit));
515 ao->neg_upap = !ppp_settings.refuse_pap && (ppp_settings.passwd[0] != 0 || get_pap_passwd(unit, NULL, NULL));
516 ao->neg_chap = !ppp_settings.refuse_chap && ppp_settings.passwd[0] != 0 /*have_chap_secret(ppp_settings.user, ppp_settings.remote_name, (u32_t)0)*/;
517
518 if (go->neg_upap && !have_pap_secret()) {
519 go->neg_upap = 0;
520 }
521 if (go->neg_chap) {
522 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
523 if (!have_chap_secret(ppp_settings.remote_name, ppp_settings.our_name, remote)) {
524 go->neg_chap = 0;
525 }
526 }
527}
528
529#if PAP_SUPPORT
530/*
531 * check_passwd - Check the user name and passwd against the PAP secrets
532 * file. If requested, also check against the system password database,
533 * and login the user if OK.
534 *
535 * returns:
536 * UPAP_AUTHNAK: Authentication failed.
537 * UPAP_AUTHACK: Authentication succeeded.
538 * In either case, msg points to an appropriate message.
539 */
540int
541check_passwd( int unit, char *auser, int userlen, char *apasswd, int passwdlen, char **msg, int *msglen)
542{
543#if 1
544 LWIP_UNUSED_ARG(unit);
545 LWIP_UNUSED_ARG(auser);
546 LWIP_UNUSED_ARG(userlen);
547 LWIP_UNUSED_ARG(apasswd);
548 LWIP_UNUSED_ARG(passwdlen);
549 LWIP_UNUSED_ARG(msglen);
550 *msg = (char *) 0;
551 return UPAP_AUTHACK; /* XXX Assume all entries OK. */
552#else
553 int ret = 0;
554 struct wordlist *addrs = NULL;
555 char passwd[256], user[256];
556 char secret[MAXWORDLEN];
557 static u_short attempts = 0;
558
559 /*
560 * Make copies of apasswd and auser, then null-terminate them.
561 */
562 BCOPY(apasswd, passwd, passwdlen);
563 passwd[passwdlen] = '\0';
564 BCOPY(auser, user, userlen);
565 user[userlen] = '\0';
566 *msg = (char *) 0;
567
568 /* XXX Validate user name and password. */
569 ret = UPAP_AUTHACK; /* XXX Assume all entries OK. */
570
571 if (ret == UPAP_AUTHNAK) {
572 if (*msg == (char *) 0) {
573 *msg = "Login incorrect";
574 }
575 *msglen = strlen(*msg);
576 /*
577 * Frustrate passwd stealer programs.
578 * Allow 10 tries, but start backing off after 3 (stolen from login).
579 * On 10'th, drop the connection.
580 */
581 if (attempts++ >= 10) {
582 AUTHDEBUG((LOG_WARNING, "%d LOGIN FAILURES BY %s\n", attempts, user));
583 /*ppp_panic("Excess Bad Logins");*/
584 }
585 if (attempts > 3) {
586 sys_msleep((attempts - 3) * 5);
587 }
588 if (addrs != NULL) {
589 free_wordlist(addrs);
590 }
591 } else {
592 attempts = 0; /* Reset count */
593 if (*msg == (char *) 0) {
594 *msg = "Login ok";
595 }
596 *msglen = strlen(*msg);
597 set_allowed_addrs(unit, addrs);
598 }
599
600 BZERO(passwd, sizeof(passwd));
601 BZERO(secret, sizeof(secret));
602
603 return ret;
604#endif
605}
606#endif /* PAP_SUPPORT */
607
608
609/*
610 * auth_ip_addr - check whether the peer is authorized to use
611 * a given IP address. Returns 1 if authorized, 0 otherwise.
612 */
613int
614auth_ip_addr(int unit, u32_t addr)
615{
616 return ip_addr_check(addr, addresses[unit]);
617}
618
619/*
620 * bad_ip_adrs - return 1 if the IP address is one we don't want
621 * to use, such as an address in the loopback net or a multicast address.
622 * addr is in network byte order.
623 */
624int
625bad_ip_adrs(u32_t addr)
626{
627 addr = ntohl(addr);
628 return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
629 || IN_MULTICAST(addr) || IN_BADCLASS(addr);
630}
631
632
633#if CHAP_SUPPORT
634/*
635 * get_secret - open the CHAP secret file and return the secret
636 * for authenticating the given client on the given server.
637 * (We could be either client or server).
638 */
639int get_secret( int unit, char *client, char *server, char *secret, int *secret_len, int save_addrs)
640{
641#if 1
642 int len;
643 struct wordlist *addrs;
644
645 LWIP_UNUSED_ARG(unit);
646 LWIP_UNUSED_ARG(server);
647 LWIP_UNUSED_ARG(save_addrs);
648
649 addrs = NULL;
650
651 if(!client || !client[0] || strcmp(client, ppp_settings.user)) {
652 return 0;
653 }
654
655 len = strlen(ppp_settings.passwd);
656 if (len > MAXSECRETLEN) {
657 AUTHDEBUG((LOG_ERR, "Secret for %s on %s is too long\n", client, server));
658 len = MAXSECRETLEN;
659 }
660
661 BCOPY(ppp_settings.passwd, secret, len);
662 *secret_len = len;
663
664 return 1;
665#else
666 int ret = 0, len;
667 struct wordlist *addrs;
668 char secbuf[MAXWORDLEN];
669
670 addrs = NULL;
671 secbuf[0] = 0;
672
673 /* XXX Find secret. */
674 if (ret < 0) {
675 return 0;
676 }
677
678 if (save_addrs) {
679 set_allowed_addrs(unit, addrs);
680 }
681
682 len = strlen(secbuf);
683 if (len > MAXSECRETLEN) {
684 AUTHDEBUG((LOG_ERR, "Secret for %s on %s is too long\n", client, server));
685 len = MAXSECRETLEN;
686 }
687
688 BCOPY(secbuf, secret, len);
689 BZERO(secbuf, sizeof(secbuf));
690 *secret_len = len;
691
692 return 1;
693#endif
694}
695#endif /* CHAP_SUPPORT */
696
697
698#if 0 /* UNUSED */
699/*
700 * auth_check_options - called to check authentication options.
701 */
702void
703auth_check_options(void)
704{
705 lcp_options *wo = &lcp_wantoptions[0];
706 int can_auth;
707 ipcp_options *ipwo = &ipcp_wantoptions[0];
708 u32_t remote;
709
710 /* Default our_name to hostname, and user to our_name */
711 if (ppp_settings.our_name[0] == 0 || ppp_settings.usehostname) {
712 strcpy(ppp_settings.our_name, ppp_settings.hostname);
713 }
714
715 if (ppp_settings.user[0] == 0) {
716 strcpy(ppp_settings.user, ppp_settings.our_name);
717 }
718
719 /* If authentication is required, ask peer for CHAP or PAP. */
720 if (ppp_settings.auth_required && !wo->neg_chap && !wo->neg_upap) {
721 wo->neg_chap = 1;
722 wo->neg_upap = 1;
723 }
724
725 /*
726 * Check whether we have appropriate secrets to use
727 * to authenticate the peer.
728 */
729 can_auth = wo->neg_upap && have_pap_secret();
730 if (!can_auth && wo->neg_chap) {
731 remote = ipwo->accept_remote? 0: ipwo->hisaddr;
732 can_auth = have_chap_secret(ppp_settings.remote_name, ppp_settings.our_name, remote);
733 }
734
735 if (ppp_settings.auth_required && !can_auth) {
736 ppp_panic("No auth secret");
737 }
738}
739#endif
740
741
742/**********************************/
743/*** LOCAL FUNCTION DEFINITIONS ***/
744/**********************************/
745/*
746 * Proceed to the network phase.
747 */
748static void
749network_phase(int unit)
750{
751 int i;
752 struct protent *protp;
753 lcp_options *go = &lcp_gotoptions[unit];
754
755 /*
756 * If the peer had to authenticate, run the auth-up script now.
757 */
758 if ((go->neg_chap || go->neg_upap) && !did_authup) {
759 /* XXX Do setup for peer authentication. */
760 did_authup = 1;
761 }
762
763#if CBCP_SUPPORT
764 /*
765 * If we negotiated callback, do it now.
766 */
767 if (go->neg_cbcp) {
768 lcp_phase[unit] = PHASE_CALLBACK;
769 (*cbcp_protent.open)(unit);
770 return;
771 }
772#endif /* CBCP_SUPPORT */
773
774 lcp_phase[unit] = PHASE_NETWORK;
775 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
776 if (protp->protocol < 0xC000 && protp->enabled_flag && protp->open != NULL) {
777 (*protp->open)(unit);
778 if (protp->protocol != PPP_CCP) {
779 ++num_np_open;
780 }
781 }
782 }
783
784 if (num_np_open == 0) {
785 /* nothing to do */
786 lcp_close(0, "No network protocols running");
787 }
788}
789
790/*
791 * check_idle - check whether the link has been idle for long
792 * enough that we can shut it down.
793 */
794static void
795check_idle(void *arg)
796{
797 struct ppp_idle idle;
798 u_short itime;
799
800 LWIP_UNUSED_ARG(arg);
801 if (!get_idle_time(0, &idle)) {
802 return;
803 }
804 itime = LWIP_MIN(idle.xmit_idle, idle.recv_idle);
805 if (itime >= ppp_settings.idle_time_limit) {
806 /* link is idle: shut it down. */
807 AUTHDEBUG((LOG_INFO, "Terminating connection due to lack of activity.\n"));
808 lcp_close(0, "Link inactive");
809 } else {
810 TIMEOUT(check_idle, NULL, ppp_settings.idle_time_limit - itime);
811 }
812}
813
814/*
815 * connect_time_expired - log a message and close the connection.
816 */
817static void
818connect_time_expired(void *arg)
819{
820 LWIP_UNUSED_ARG(arg);
821
822 AUTHDEBUG((LOG_INFO, "Connect time expired\n"));
823 lcp_close(0, "Connect time expired"); /* Close connection */
824}
825
826#if 0
827/*
828 * login - Check the user name and password against the system
829 * password database, and login the user if OK.
830 *
831 * returns:
832 * UPAP_AUTHNAK: Login failed.
833 * UPAP_AUTHACK: Login succeeded.
834 * In either case, msg points to an appropriate message.
835 */
836static int
837login(char *user, char *passwd, char **msg, int *msglen)
838{
839 /* XXX Fail until we decide that we want to support logins. */
840 return (UPAP_AUTHNAK);
841}
842#endif
843
844/*
845 * logout - Logout the user.
846 */
847static void
848logout(void)
849{
850 logged_in = 0;
851}
852
853/*
854 * null_login - Check if a username of "" and a password of "" are
855 * acceptable, and iff so, set the list of acceptable IP addresses
856 * and return 1.
857 */
858static int
859null_login(int unit)
860{
861 LWIP_UNUSED_ARG(unit);
862 /* XXX Fail until we decide that we want to support logins. */
863 return 0;
864}
865
866/*
867 * get_pap_passwd - get a password for authenticating ourselves with
868 * our peer using PAP. Returns 1 on success, 0 if no suitable password
869 * could be found.
870 */
871static int
872get_pap_passwd(int unit, char *user, char *passwd)
873{
874 LWIP_UNUSED_ARG(unit);
875/* normally we would reject PAP if no password is provided,
876 but this causes problems with some providers (like CHT in Taiwan)
877 who incorrectly request PAP and expect a bogus/empty password, so
878 always provide a default user/passwd of "none"/"none"
879*/
880 if(user) {
881 strcpy(user, "none");
882 }
883 if(passwd) {
884 strcpy(passwd, "none");
885 }
886 return 1;
887}
888
889/*
890 * have_pap_secret - check whether we have a PAP file with any
891 * secrets that we could possibly use for authenticating the peer.
892 */
893static int
894have_pap_secret(void)
895{
896 /* XXX Fail until we set up our passwords. */
897 return 0;
898}
899
900/*
901 * have_chap_secret - check whether we have a CHAP file with a
902 * secret that we could possibly use for authenticating `client'
903 * on `server'. Either can be the null string, meaning we don't
904 * know the identity yet.
905 */
906static int
907have_chap_secret(char *client, char *server, u32_t remote)
908{
909 LWIP_UNUSED_ARG(client);
910 LWIP_UNUSED_ARG(server);
911 LWIP_UNUSED_ARG(remote);
912 /* XXX Fail until we set up our passwords. */
913 return 0;
914}
915
916#if 0 /* PAP_SUPPORT || CHAP_SUPPORT */
917/*
918 * set_allowed_addrs() - set the list of allowed addresses.
919 */
920static void
921set_allowed_addrs(int unit, struct wordlist *addrs)
922{
923 if (addresses[unit] != NULL) {
924 free_wordlist(addresses[unit]);
925 }
926 addresses[unit] = addrs;
927
928#if 0
929 /*
930 * If there's only one authorized address we might as well
931 * ask our peer for that one right away
932 */
933 if (addrs != NULL && addrs->next == NULL) {
934 char *p = addrs->word;
935 struct ipcp_options *wo = &ipcp_wantoptions[unit];
936 u32_t a;
937 struct hostent *hp;
938
939 if (wo->hisaddr == 0 && *p != '!' && *p != '-' && strchr(p, '/') == NULL) {
940 hp = gethostbyname(p);
941 if (hp != NULL && hp->h_addrtype == AF_INET) {
942 a = *(u32_t *)hp->h_addr;
943 } else {
944 a = inet_addr(p);
945 }
946 if (a != (u32_t) -1) {
947 wo->hisaddr = a;
948 }
949 }
950 }
951#endif
952}
953#endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */
954
955static int
956ip_addr_check(u32_t addr, struct wordlist *addrs)
957{
958 /* don't allow loopback or multicast address */
959 if (bad_ip_adrs(addr)) {
960 return 0;
961 }
962
963 if (addrs == NULL) {
964 return !ppp_settings.auth_required; /* no addresses authorized */
965 }
966
967 /* XXX All other addresses allowed. */
968 return 1;
969}
970
971#if 0 /* PAP_SUPPORT || CHAP_SUPPORT */
972/*
973 * free_wordlist - release memory allocated for a wordlist.
974 */
975static void
976free_wordlist(struct wordlist *wp)
977{
978 struct wordlist *next;
979
980 while (wp != NULL) {
981 next = wp->next;
982 free(wp);
983 wp = next;
984 }
985}
986#endif /* 0 */ /* PAP_SUPPORT || CHAP_SUPPORT */
987
988#endif /* PPP_SUPPORT */
This page took 0.036137 seconds and 4 git commands to generate.