1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP PAP Module
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993-94, Internet Initiative Japan, Inc.
|
|
|
|
* All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan, Inc. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1998-06-27 23:48:54 +00:00
|
|
|
* $Id: pap.c,v 1.23 1998/05/21 21:47:18 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO:
|
|
|
|
*/
|
1998-04-07 00:54:26 +00:00
|
|
|
#include <sys/types.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netinet/in.h>
|
1998-03-16 22:54:35 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <sys/un.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-06-27 23:48:54 +00:00
|
|
|
#include <string.h>
|
1998-02-02 19:33:40 +00:00
|
|
|
#include <termios.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcp.h"
|
1998-03-01 01:07:49 +00:00
|
|
|
#include "auth.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "pap.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "hdlc.h"
|
|
|
|
#include "lcpproto.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#include "async.h"
|
|
|
|
#include "throughput.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "ccp.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#include "link.h"
|
1998-02-09 19:21:11 +00:00
|
|
|
#include "descriptor.h"
|
1998-01-29 00:49:32 +00:00
|
|
|
#include "physical.h"
|
1998-03-13 21:07:46 +00:00
|
|
|
#include "iplist.h"
|
1998-03-16 22:54:35 +00:00
|
|
|
#include "slcompress.h"
|
1998-03-13 21:07:46 +00:00
|
|
|
#include "ipcp.h"
|
1998-03-16 22:52:54 +00:00
|
|
|
#include "filter.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "mp.h"
|
1998-02-07 20:50:08 +00:00
|
|
|
#include "bundle.h"
|
1998-03-01 01:07:49 +00:00
|
|
|
#include "chat.h"
|
|
|
|
#include "chap.h"
|
|
|
|
#include "datalink.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-22 03:37:54 +00:00
|
|
|
static const char *papcodes[] = { "???", "REQUEST", "ACK", "NAK" };
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-03-01 01:07:49 +00:00
|
|
|
void
|
1998-05-01 19:26:12 +00:00
|
|
|
pap_SendChallenge(struct authinfo *auth, int papid, struct physical *physical)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct fsmheader lh;
|
|
|
|
struct mbuf *bp;
|
|
|
|
u_char *cp;
|
|
|
|
int namelen, keylen, plen;
|
|
|
|
|
1998-04-03 19:24:49 +00:00
|
|
|
namelen = strlen(physical->dl->bundle->cfg.auth.name);
|
|
|
|
keylen = strlen(physical->dl->bundle->cfg.auth.key);
|
1995-01-31 06:29:58 +00:00
|
|
|
plen = namelen + keylen + 2;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogDEBUG, "pap_SendChallenge: namelen = %d, keylen = %d\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
namelen, keylen);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "PAP: %s\n", physical->dl->bundle->cfg.auth.name);
|
1995-01-31 06:29:58 +00:00
|
|
|
lh.code = PAP_REQUEST;
|
1995-02-26 12:18:08 +00:00
|
|
|
lh.id = papid;
|
1995-01-31 06:29:58 +00:00
|
|
|
lh.length = htons(plen + sizeof(struct fsmheader));
|
1998-05-01 19:26:12 +00:00
|
|
|
bp = mbuf_Alloc(plen + sizeof(struct fsmheader), MB_FSM);
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
|
1995-01-31 06:29:58 +00:00
|
|
|
cp = MBUF_CTOP(bp) + sizeof(struct fsmheader);
|
|
|
|
*cp++ = namelen;
|
1998-04-03 19:24:49 +00:00
|
|
|
memcpy(cp, physical->dl->bundle->cfg.auth.name, namelen);
|
1995-01-31 06:29:58 +00:00
|
|
|
cp += namelen;
|
|
|
|
*cp++ = keylen;
|
1998-04-03 19:24:49 +00:00
|
|
|
memcpy(cp, physical->dl->bundle->cfg.auth.key, keylen);
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
hdlc_Output(&physical->link, PRI_LINK, PROTO_PAP, bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-29 00:49:32 +00:00
|
|
|
SendPapCode(int id, int code, const char *message, struct physical *physical)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct fsmheader lh;
|
|
|
|
struct mbuf *bp;
|
|
|
|
u_char *cp;
|
|
|
|
int plen, mlen;
|
|
|
|
|
|
|
|
lh.code = code;
|
|
|
|
lh.id = id;
|
|
|
|
mlen = strlen(message);
|
|
|
|
plen = mlen + 1;
|
|
|
|
lh.length = htons(plen + sizeof(struct fsmheader));
|
1998-05-01 19:26:12 +00:00
|
|
|
bp = mbuf_Alloc(plen + sizeof(struct fsmheader), MB_FSM);
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
|
1995-01-31 06:29:58 +00:00
|
|
|
cp = MBUF_CTOP(bp) + sizeof(struct fsmheader);
|
|
|
|
*cp++ = mlen;
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(cp, message, mlen);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "PapOutput: %s\n", papcodes[code]);
|
|
|
|
hdlc_Output(&physical->link, PRI_LINK, PROTO_PAP, bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate given username and passwrd against with secret table
|
|
|
|
*/
|
|
|
|
static int
|
1998-02-02 19:32:16 +00:00
|
|
|
PapValidate(struct bundle *bundle, u_char *name, u_char *key,
|
|
|
|
struct physical *physical)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int nlen, klen;
|
|
|
|
|
|
|
|
nlen = *name++;
|
|
|
|
klen = *key;
|
|
|
|
*key++ = 0;
|
|
|
|
key[klen] = 0;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogDEBUG, "PapValidate: name %s (%d), key %s (%d)\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
name, nlen, key, klen);
|
1996-10-06 13:32:37 +00:00
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
return auth_Validate(bundle, name, key, physical);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-01 19:26:12 +00:00
|
|
|
pap_Input(struct bundle *bundle, struct mbuf *bp, struct physical *physical)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
int len = mbuf_Length(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
struct fsmheader *php;
|
|
|
|
u_char *cp;
|
|
|
|
|
|
|
|
if (len >= sizeof(struct fsmheader)) {
|
1997-08-25 00:29:32 +00:00
|
|
|
php = (struct fsmheader *) MBUF_CTOP(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (len >= ntohs(php->length)) {
|
|
|
|
if (php->code < PAP_REQUEST || php->code > PAP_NAK)
|
|
|
|
php->code = 0;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "pap_Input: %s\n", papcodes[php->code]);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (php->code) {
|
|
|
|
case PAP_REQUEST:
|
|
|
|
cp = (u_char *) (php + 1);
|
1998-02-02 19:32:16 +00:00
|
|
|
if (PapValidate(bundle, cp, cp + *cp + 1, physical)) {
|
1998-04-24 19:16:15 +00:00
|
|
|
datalink_GotAuthname(physical->dl, cp+1, *cp);
|
1998-01-29 00:49:32 +00:00
|
|
|
SendPapCode(php->id, PAP_ACK, "Greetings!!", physical);
|
1998-04-03 19:26:29 +00:00
|
|
|
physical->link.lcp.auth_ineed = 0;
|
1998-04-16 00:26:21 +00:00
|
|
|
if (Enabled(bundle, OPT_UTMP))
|
1998-05-01 19:26:12 +00:00
|
|
|
physical_Login(physical, cp + 1);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-04-03 19:26:29 +00:00
|
|
|
if (physical->link.lcp.auth_iwait == 0)
|
1998-02-07 20:50:08 +00:00
|
|
|
/*
|
|
|
|
* Either I didn't need to authenticate, or I've already been
|
|
|
|
* told that I got the answer right.
|
|
|
|
*/
|
1998-04-03 19:26:29 +00:00
|
|
|
datalink_AuthOk(physical->dl);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1998-01-29 00:49:32 +00:00
|
|
|
SendPapCode(php->id, PAP_NAK, "Login incorrect", physical);
|
1998-04-03 19:26:29 +00:00
|
|
|
datalink_AuthNotOk(physical->dl);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PAP_ACK:
|
1998-05-01 19:26:12 +00:00
|
|
|
auth_StopTimer(&physical->dl->pap);
|
1997-08-25 00:29:32 +00:00
|
|
|
cp = (u_char *) (php + 1);
|
1995-01-31 06:29:58 +00:00
|
|
|
len = *cp++;
|
|
|
|
cp[len] = 0;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "Received PAP_ACK (%s)\n", cp);
|
1998-04-03 19:26:29 +00:00
|
|
|
if (physical->link.lcp.auth_iwait == PROTO_PAP) {
|
|
|
|
physical->link.lcp.auth_iwait = 0;
|
|
|
|
if (physical->link.lcp.auth_ineed == 0)
|
1998-02-07 20:50:08 +00:00
|
|
|
/*
|
|
|
|
* We've succeeded in our ``login''
|
|
|
|
* If we're not expecting the peer to authenticate (or he already
|
|
|
|
* has), proceed to network phase.
|
|
|
|
*/
|
1998-04-03 19:26:29 +00:00
|
|
|
datalink_AuthOk(physical->dl);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PAP_NAK:
|
1998-05-01 19:26:12 +00:00
|
|
|
auth_StopTimer(&physical->dl->pap);
|
1997-08-25 00:29:32 +00:00
|
|
|
cp = (u_char *) (php + 1);
|
1995-01-31 06:29:58 +00:00
|
|
|
len = *cp++;
|
|
|
|
cp[len] = 0;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "Received PAP_NAK (%s)\n", cp);
|
1998-04-03 19:26:29 +00:00
|
|
|
datalink_AuthNotOk(physical->dl);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-05-01 19:26:12 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|