X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fauth.c;h=b9c28fcafb6abc38ca789436c308831fb9d02799;hp=cdeb2b6b7874daa292c32b23082f89c4134eae93;hb=1b9f7635dd45d643b2fb7cf496f67789892897c5;hpb=0b63a24d54ba4708c88e31bdd74b0145956c1478 diff --git a/pppd/auth.c b/pppd/auth.c index cdeb2b6..b9c28fc 100644 --- a/pppd/auth.c +++ b/pppd/auth.c @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: auth.c,v 1.1 1993/11/11 03:54:25 paulus Exp $"; +static char rcsid[] = "$Id: auth.c,v 1.9 1994/09/01 00:12:52 paulus Exp $"; #endif #include @@ -55,14 +55,11 @@ static char rcsid[] = "$Id: auth.c,v 1.1 1993/11/11 03:54:25 paulus Exp $"; #include "upap.h" #include "chap.h" #include "ipcp.h" +#include "ccp.h" #include "pathnames.h" #ifdef sparc #include -#ifndef __GNUC__ -/* why alloca.h doesn't define what alloca() returns is a mystery */ -char *alloca __ARGS((int)); -#endif /*__GNUC__*/ #endif /*sparc*/ /* Used for storing a sequence of words. Usually malloced. */ @@ -80,16 +77,6 @@ struct wordlist { #define FALSE 0 #define TRUE 1 -extern char user[]; -extern char passwd[]; -extern char devname[]; -extern char our_name[]; -extern char remote_name[]; -extern char hostname[]; -extern int uselogin; -extern int usehostname; -extern int auth_required; - /* Records which authentication operations haven't completed yet. */ static int auth_pending[NPPP]; static int logged_in; @@ -104,8 +91,10 @@ static struct wordlist *addresses[NPPP]; /* Prototypes */ void check_access __ARGS((FILE *, char *)); +static void network_phase __ARGS((int)); static int login __ARGS((char *, char *, char **, int *)); static void logout __ARGS((void)); +static int null_login __ARGS((int)); static int get_upap_passwd __ARGS((void)); static int have_upap_secret __ARGS((void)); static int have_chap_secret __ARGS((char *, char *)); @@ -133,13 +122,24 @@ void link_terminated(unit) int unit; { + if (phase == PHASE_DEAD) + return; if (logged_in) logout(); - if (lcp_wantoptions[unit].restart) { - lcp_lowerdown(unit); - lcp_lowerup(unit); - } else - EXIT(unit); + phase = PHASE_DEAD; + syslog(LOG_NOTICE, "Connection terminated."); +} + +/* + * LCP has gone down; it will either die or try to re-establish. + */ +void +link_down(unit) + int unit; +{ + ipcp_close(0); + ccp_close(0); + phase = PHASE_TERMINATE; } /* @@ -157,14 +157,19 @@ link_established(unit) if (auth_required && !(go->neg_chap || go->neg_upap)) { /* - * We wanted the peer to authenticate himself, and he refused: - * tell him to go away. + * We wanted the peer to authenticate itself, and it refused: + * treat it as though it authenticated with PAP using a username + * of "" and a password of "". If that's not OK, boot it out. */ - syslog(LOG_WARNING, "peer refused to authenticate"); - lcp_close(unit); - return; + if (wo->neg_upap && !null_login(unit)) { + syslog(LOG_WARNING, "peer refused to authenticate"); + lcp_close(unit); + phase = PHASE_TERMINATE; + return; + } } + phase = PHASE_AUTHENTICATE; auth = 0; if (go->neg_chap) { ChapAuthPeer(unit, our_name, go->chap_mdtype); @@ -183,7 +188,19 @@ link_established(unit) auth_pending[unit] = auth; if (!auth) - ipcp_open(unit); + network_phase(unit); +} + +/* + * Proceed to the network phase. + */ +static void +network_phase(unit) + int unit; +{ + phase = PHASE_NETWORK; + ipcp_open(unit); + ccp_open(unit); } /* @@ -197,6 +214,7 @@ auth_peer_fail(unit, protocol) * Authentication failure: take the link down */ lcp_close(unit); + phase = PHASE_TERMINATE; } /* @@ -225,8 +243,11 @@ auth_peer_success(unit, protocol) * If there is no more authentication still to be done, * proceed to the network phase. */ - if ((auth_pending[unit] &= ~bit) == 0) + if ((auth_pending[unit] &= ~bit) == 0) { + phase = PHASE_NETWORK; ipcp_open(unit); + ccp_open(unit); + } } /* @@ -262,6 +283,7 @@ auth_withpeer_success(unit, protocol) default: syslog(LOG_WARNING, "auth_peer_success: unknown protocol %x", protocol); + bit = 0; } /* @@ -269,7 +291,7 @@ auth_withpeer_success(unit, protocol) * proceed to the network phase. */ if ((auth_pending[unit] &= ~bit) == 0) - ipcp_open(unit); + network_phase(unit); } @@ -394,7 +416,7 @@ check_passwd(unit, auser, userlen, apasswd, passwdlen, msg, msglen) */ if (attempts++ >= 10) { syslog(LOG_WARNING, "%d LOGIN FAILURES ON %s, %s", - attempts, devname, user); + attempts, devnam, user); quit(); } if (attempts > 3) @@ -456,9 +478,9 @@ login(user, passwd, msg, msglen) /* * Write a wtmp entry for this user. */ - tty = strrchr(devname, '/'); + tty = strrchr(devnam, '/'); if (tty == NULL) - tty = devname; + tty = devnam; else tty++; logwtmp(tty, user, ""); /* Add wtmp login entry */ @@ -475,9 +497,9 @@ logout() { char *tty; - tty = strrchr(devname, '/'); + tty = strrchr(devnam, '/'); if (tty == NULL) - tty = devname; + tty = devnam; else tty++; logwtmp(tty, "", ""); /* Wipe out wtmp logout entry */ @@ -485,6 +507,46 @@ logout() } +/* + * null_login - Check if a username of "" and a password of "" are + * acceptable, and iff so, set the list of acceptable IP addresses + * and return 1. + */ +static int +null_login(unit) + int unit; +{ + char *filename; + FILE *f; + int i, ret; + struct wordlist *addrs; + char secret[MAXWORDLEN]; + + /* + * Open the file of upap secrets and scan for a suitable secret. + * We don't accept a wildcard client. + */ + filename = _PATH_UPAPFILE; + addrs = NULL; + f = fopen(filename, "r"); + if (f == NULL) + return 0; + check_access(f, filename); + + i = scan_authfile(f, "", our_name, secret, &addrs, filename); + ret = i >= 0 && (i & NONWILD_CLIENT) != 0 && secret[0] == 0; + + if (ret) { + if (addresses[unit] != NULL) + free_wordlist(addresses[unit]); + addresses[unit] = addrs; + } + + fclose(f); + return ret; +} + + /* * get_upap_passwd - get a password for authenticating ourselves with * our peer using PAP. Returns 1 on success, 0 if no suitable password @@ -543,7 +605,7 @@ have_upap_secret() * on `server'. Either can be the null string, meaning we don't * know the identity yet. */ -int +static int have_chap_secret(client, server) char *client; char *server; @@ -583,6 +645,7 @@ get_secret(unit, client, server, secret, secret_len, save_addrs) char *server; char *secret; int *secret_len; + int save_addrs; { FILE *f; int ret, len; @@ -630,12 +693,16 @@ get_secret(unit, client, server, secret, secret_len, save_addrs) int auth_ip_addr(unit, addr) int unit; - u_long addr; + uint32 addr; { - u_long a; + uint32 a; struct hostent *hp; struct wordlist *addrs; + /* don't allow loopback or multicast address */ + if (bad_ip_adrs(addr)) + return 0; + if ((addrs = addresses[unit]) == NULL) return 1; /* no restriction */ @@ -649,7 +716,7 @@ auth_ip_addr(unit, addr) addrs->word); continue; } else - a = *(u_long *)hp->h_addr; + a = *(uint32 *)hp->h_addr; } if (addr == a) return 1; @@ -657,6 +724,20 @@ auth_ip_addr(unit, addr) return 0; /* not in list => can't have it */ } +/* + * bad_ip_adrs - return 1 if the IP address is one we don't want + * to use, such as an address in the loopback net or a multicast address. + * addr is in network byte order. + */ +int +bad_ip_adrs(addr) + uint32 addr; +{ + addr = ntohl(addr); + return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET + || IN_MULTICAST(addr) || IN_BADCLASS(addr); +} + /* * check_access - complain if a secret file has too-liberal permissions. */ @@ -783,7 +864,7 @@ scan_authfile(f, client, server, secret, addrs, filename) */ if (addr_list) free_wordlist(addr_list); - addr_list = NULL; + addr_list = addr_last = NULL; for (;;) { if (!getword(f, word, &newline, filename) || newline) break;