Do authentication at the datalink level, not the bundle level.

The bundle doesn't get a LayerUp 'till we're authenticated.

Introduce DATALINK_LCP and DATALINK_AUTH phases.
This commit is contained in:
Brian Somers 1998-03-01 01:07:49 +00:00
parent 5454ccd9e0
commit e2ebb036fd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=33934
17 changed files with 252 additions and 154 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: auth.c,v 1.27.2.8 1998/02/13 05:10:05 brian Exp $
* $Id: auth.c,v 1.27.2.9 1998/02/21 01:44:57 brian Exp $
*
* TODO:
* o Implement check against with registered IP addresses.
@ -205,36 +205,36 @@ AuthGetSecret(struct bundle *bundle, const char *fname, const char *system,
static void
AuthTimeout(void *vauthp)
{
struct pppTimer *tp;
struct authinfo *authp = (struct authinfo *)vauthp;
tp = &authp->authtimer;
StopTimer(tp);
StopTimer(&authp->authtimer);
if (--authp->retry > 0) {
StartTimer(tp);
(authp->ChallengeFunc) (++authp->id, authp->physical);
StartTimer(&authp->authtimer);
(*authp->ChallengeFunc)(authp, ++authp->id, authp->physical);
}
}
void
StartAuthChallenge(struct authinfo *authp, struct physical *physical)
authinfo_Init(struct authinfo *authinfo)
{
struct pppTimer *tp;
assert(authp->physical == NULL);
memset(authinfo, '\0', sizeof(struct authinfo));
}
void
StartAuthChallenge(struct authinfo *authp, struct physical *physical,
void (*fn)(struct authinfo *, int, struct physical *))
{
authp->ChallengeFunc = fn;
authp->physical = physical;
tp = &authp->authtimer;
StopTimer(tp);
tp->func = AuthTimeout;
tp->load = VarRetryTimeout * SECTICKS;
tp->state = TIMER_STOPPED;
tp->arg = (void *) authp;
StartTimer(tp);
StopTimer(&authp->authtimer);
authp->authtimer.func = AuthTimeout;
authp->authtimer.load = VarRetryTimeout * SECTICKS;
authp->authtimer.state = TIMER_STOPPED;
authp->authtimer.arg = (void *) authp;
authp->retry = 3;
authp->id = 1;
(authp->ChallengeFunc) (authp->id, physical);
(*authp->ChallengeFunc)(authp, authp->id, physical);
StartTimer(&authp->authtimer);
}
void

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: auth.h,v 1.10.2.2 1998/02/02 19:32:01 brian Exp $
* $Id: auth.h,v 1.10.2.3 1998/02/07 20:49:20 brian Exp $
*
* TODO:
*/
@ -29,17 +29,20 @@ typedef enum {
} LOCAL_AUTH_VALID;
struct authinfo {
void (*ChallengeFunc) (int, struct physical *);
void (*ChallengeFunc)(struct authinfo *, int, struct physical *);
struct pppTimer authtimer;
int retry;
int id;
struct physical *physical;
};
extern void authinfo_Init(struct authinfo *);
extern const char *Auth2Nam(u_short);
extern LOCAL_AUTH_VALID LocalAuthValidate(const char *, const char *, const char *);
extern void StopAuthTimer(struct authinfo *);
extern void StartAuthChallenge(struct authinfo *, struct physical *);
extern void StartAuthChallenge(struct authinfo *, struct physical *,
void (*fn)(struct authinfo *, int, struct physical *));
extern void LocalAuthInit(void);
extern int AuthValidate(struct bundle *, const char *, const char *,
const char *, struct physical *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.16 1998/02/23 00:38:16 brian Exp $
* $Id: bundle.c,v 1.1.2.17 1998/02/27 01:22:16 brian Exp $
*/
#include <sys/param.h>
@ -95,8 +95,8 @@ bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new)
if (new == bundle->phase)
return;
if (new <= PHASE_NETWORK)
LogPrintf(LogPHASE, "bundle_NewPhase: %s\n", PhaseNames[new]);
if (new <= PHASE_TERMINATE)
LogPrintf(LogPHASE, "bundle: %s\n", PhaseNames[new]);
switch (new) {
case PHASE_DEAD:
@ -108,20 +108,8 @@ bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new)
break;
case PHASE_AUTHENTICATE:
LcpInfo.auth_ineed = LcpInfo.want_auth;
LcpInfo.auth_iwait = LcpInfo.his_auth;
if (LcpInfo.his_auth || LcpInfo.want_auth) {
LogPrintf(LogPHASE, " his = %s, mine = %s\n",
Auth2Nam(LcpInfo.his_auth), Auth2Nam(LcpInfo.want_auth));
/* XXX-ML AuthPapInfo and AuthChapInfo must be allocated! */
if (LcpInfo.his_auth == PROTO_PAP)
StartAuthChallenge(&AuthPapInfo, physical);
if (LcpInfo.want_auth == PROTO_CHAP)
StartAuthChallenge(&AuthChapInfo, physical);
bundle->phase = new;
prompt_Display(&prompt, bundle);
} else
bundle_NewPhase(bundle, physical, PHASE_NETWORK);
bundle->phase = new;
prompt_Display(&prompt, bundle);
break;
case PHASE_NETWORK:
@ -195,14 +183,14 @@ bundle_LayerUp(void *v, struct fsm *fp)
{
/*
* The given fsm is now up
* If it's a datalink, authenticate.
* If it's a datalink, enter network phase
* If it's an NCP, tell our background mode parent to go away.
*/
struct bundle *bundle = (struct bundle *)v;
if (fp == &LcpInfo.fsm)
bundle_NewPhase(bundle, link2physical(fp->link), PHASE_AUTHENTICATE);
if (fp->proto == PROTO_LCP)
bundle_NewPhase(bundle, link2physical(fp->link), PHASE_NETWORK);
if (fp == &IpcpInfo.fsm)
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
@ -667,6 +655,24 @@ bundle2ccp(struct bundle *bundle, const char *name)
return NULL;
}
struct authinfo *
bundle2pap(struct bundle *bundle, const char *name)
{
struct datalink *dl = bundle2datalink(bundle, name);
if (dl)
return &dl->pap;
return NULL;
}
struct chap *
bundle2chap(struct bundle *bundle, const char *name)
{
struct datalink *dl = bundle2datalink(bundle, name);
if (dl)
return &dl->chap;
return NULL;
}
struct link *
bundle2link(struct bundle *bundle, const char *name)
{

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.10 1998/02/21 01:44:59 brian Exp $
* $Id: bundle.h,v 1.1.2.11 1998/02/27 01:22:17 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -70,4 +70,6 @@ extern int bundle_ShowLinks(struct cmdargs const *);
extern struct link *bundle2link(struct bundle *, const char *);
extern struct physical *bundle2physical(struct bundle *, const char *);
extern struct datalink *bundle2datalink(struct bundle *, const char *);
extern struct authinfo *bundle2pap(struct bundle *, const char *);
extern struct chap *bundle2chap(struct bundle *, const char *);
extern struct ccp *bundle2ccp(struct bundle *, const char *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ccp.c,v 1.30.2.15 1998/02/27 01:22:18 brian Exp $
* $Id: ccp.c,v 1.30.2.16 1998/02/27 21:46:20 brian Exp $
*
* TODO:
* o Support other compression protocols
@ -49,6 +49,8 @@
#include "throughput.h"
#include "link.h"
#include "chat.h"
#include "auth.h"
#include "chap.h"
#include "datalink.h"
static void CcpSendConfigReq(struct fsm *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: chap.c,v 1.28.2.9 1998/02/15 23:59:43 brian Exp $
* $Id: chap.c,v 1.28.2.10 1998/02/19 02:08:42 brian Exp $
*
* TODO:
*/
@ -48,7 +48,6 @@
#include "defs.h"
#include "timer.h"
#include "fsm.h"
#include "chap.h"
#include "chap_ms.h"
#include "lcpproto.h"
#include "lcp.h"
@ -56,6 +55,7 @@
#include "loadalias.h"
#include "vars.h"
#include "auth.h"
#include "chap.h"
#include "async.h"
#include "throughput.h"
#include "link.h"
@ -63,6 +63,9 @@
#include "physical.h"
#include "bundle.h"
#include "id.h"
#include "ccp.h"
#include "chat.h"
#include "datalink.h"
static const char *chapcodes[] = {
"???", "CHALLENGE", "RESPONSE", "SUCCESS", "FAILURE"
@ -89,36 +92,30 @@ ChapOutput(struct physical *physical, u_int code, u_int id,
HdlcOutput(physical2link(physical), PRI_LINK, PROTO_CHAP, bp);
}
static char challenge_data[80];
static int challenge_len;
static void
SendChapChallenge(int chapid, struct physical *physical)
void
SendChapChallenge(struct authinfo *auth, int chapid, struct physical *physical)
{
struct chap *chap = auth2chap(auth);
int len, i;
char *cp;
randinit();
cp = challenge_data;
*cp++ = challenge_len = random() % 32 + 16;
for (i = 0; i < challenge_len; i++)
cp = chap->challenge_data;
*cp++ = chap->challenge_len = random() % 32 + 16;
for (i = 0; i < chap->challenge_len; i++)
*cp++ = random() & 0xff;
len = strlen(VarAuthName);
memcpy(cp, VarAuthName, len);
cp += len;
ChapOutput(physical, CHAP_CHALLENGE, chapid, challenge_data,
cp - challenge_data);
ChapOutput(physical, CHAP_CHALLENGE, chapid, chap->challenge_data,
cp - chap->challenge_data);
}
struct authinfo AuthChapInfo = {
SendChapChallenge,
};
static void
RecvChapTalk(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
struct physical *physical)
{
struct datalink *dl = bundle2datalink(bundle, physical->link.name);
int valsize, len;
int arglen, keylen, namelen;
char *cp, *argp, *ap, *name, *digest;
@ -227,7 +224,8 @@ RecvChapTalk(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
ap += keylen;
MD5Init(&MD5context);
MD5Update(&MD5context, answer, ap - answer);
MD5Update(&MD5context, challenge_data + 1, challenge_len);
MD5Update(&MD5context, dl->chap.challenge_data + 1,
dl->chap.challenge_len);
MD5Final(cdigest, &MD5context);
LogDumpBuff(LogDEBUG, "got", cp, 16);
LogDumpBuff(LogDEBUG, "expect", cdigest, 16);
@ -257,7 +255,7 @@ RecvChapTalk(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
* Either I didn't need to authenticate, or I've already been
* told that I got the answer right.
*/
bundle_NewPhase(bundle, physical, PHASE_NETWORK);
datalink_AuthOk(dl);
break;
}
@ -267,7 +265,7 @@ RecvChapTalk(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
* Peer is not registerd, or response digest is wrong.
*/
ChapOutput(physical, CHAP_FAILURE, chp->id, "Invalid!!", 9);
link_Close(&physical->link, bundle, 1, 1);
datalink_AuthNotOk(dl);
break;
}
}
@ -276,6 +274,7 @@ static void
RecvChapResult(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
struct physical *physical)
{
struct datalink *dl = bundle2datalink(bundle, physical->link.name);
int len;
len = ntohs(chp->length);
@ -289,11 +288,13 @@ RecvChapResult(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
* If we're not expecting the peer to authenticate (or he already
* has), proceed to network phase.
*/
bundle_NewPhase(bundle, physical, PHASE_NETWORK);
datalink_AuthOk(dl);
}
} else
} else {
/* CHAP failed - it's not going to get any better */
link_Close(&physical->link, bundle, 1, 1);
LogPrintf(LogPHASE, "Received CHAP_FAILURE\n");
datalink_AuthNotOk(dl);
}
}
void
@ -314,7 +315,7 @@ ChapInput(struct bundle *bundle, struct mbuf *bp, struct physical *physical)
switch (chp->code) {
case CHAP_RESPONSE:
StopAuthTimer(&AuthChapInfo);
StopAuthTimer(&bundle2datalink(bundle, physical->link.name)->chap.auth);
/* Fall into.. */
case CHAP_CHALLENGE:
RecvChapTalk(bundle, chp, bp, physical);

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: chap.h,v 1.9.2.1 1998/01/29 00:49:14 brian Exp $
* $Id: chap.h,v 1.9.2.2 1998/02/02 19:32:03 brian Exp $
*
* TODO:
*/
@ -27,6 +27,13 @@ struct physical;
#define CHAP_SUCCESS 3
#define CHAP_FAILURE 4
extern struct authinfo AuthChapInfo;
struct chap {
struct authinfo auth;
char challenge_data[80];
int challenge_len;
};
#define auth2chap(a) ((struct chap *)(a))
extern void ChapInput(struct bundle *, struct mbuf *, struct physical *);
extern void SendChapChallenge(struct authinfo *, int, struct physical *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.28 1998/02/21 01:45:04 brian Exp $
* $Id: command.c,v 1.131.2.29 1998/02/23 00:38:25 brian Exp $
*
*/
#include <sys/param.h>
@ -78,6 +78,7 @@
#include "server.h"
#include "prompt.h"
#include "chat.h"
#include "chap.h"
#include "datalink.h"
struct in_addr ifnetmask;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.14 1998/02/26 17:53:15 brian Exp $
* $Id: datalink.c,v 1.1.2.15 1998/02/27 01:22:20 brian Exp $
*/
#include <sys/param.h>
@ -53,12 +53,16 @@
#include "bundle.h"
#include "chat.h"
#include "ccp.h"
#include "datalink.h"
#include "auth.h"
#include "main.h"
#include "modem.h"
#include "iplist.h"
#include "ipcp.h"
#include "prompt.h"
#include "lcpproto.h"
#include "pap.h"
#include "chap.h"
#include "datalink.h"
static const char *datalink_State(struct datalink *);
@ -140,12 +144,12 @@ datalink_LoginDone(struct datalink *dl)
datalink_HangupDone(dl);
} else {
dl->dial_tries = -1;
LogPrintf(LogPHASE, "%s: Entering OPEN state\n", dl->name);
dl->state = DATALINK_OPEN;
lcp_Setup(&LcpInfo, dl->state == DATALINK_READY ? 0 : VarOpenMode);
ccp_Setup(&dl->ccp);
LogPrintf(LogPHASE, "%s: Entering LCP state\n", dl->name);
dl->state = DATALINK_LCP;
FsmUp(&LcpInfo.fsm);
FsmOpen(&LcpInfo.fsm);
}
@ -238,6 +242,8 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
break;
case DATALINK_READY:
case DATALINK_LCP:
case DATALINK_AUTH:
case DATALINK_OPEN:
result = descriptor_UpdateSet(&dl->physical->desc, r, w, e, n);
break;
@ -261,6 +267,8 @@ datalink_IsSet(struct descriptor *d, fd_set *fdset)
return descriptor_IsSet(&dl->chat.desc, fdset);
case DATALINK_READY:
case DATALINK_LCP:
case DATALINK_AUTH:
case DATALINK_OPEN:
return descriptor_IsSet(&dl->physical->desc, fdset);
}
@ -284,6 +292,8 @@ datalink_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
break;
case DATALINK_READY:
case DATALINK_LCP:
case DATALINK_AUTH:
case DATALINK_OPEN:
descriptor_Read(&dl->physical->desc, bundle, fdset);
break;
@ -307,18 +317,41 @@ datalink_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
break;
case DATALINK_READY:
case DATALINK_LCP:
case DATALINK_AUTH:
case DATALINK_OPEN:
descriptor_Write(&dl->physical->desc, bundle, fdset);
break;
}
}
static void
datalink_ComeDown(struct datalink *dl, int stay)
{
if (stay) {
dl->dial_tries = -1;
dl->reconnect_tries = 0;
}
if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) {
modem_Offline(dl->physical);
if (dl->script.run && dl->state != DATALINK_OPENING) {
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1);
} else
datalink_HangupDone(dl);
}
}
static void
datalink_LayerStart(void *v, struct fsm *fp)
{
/* The given FSM is about to start up ! */
struct datalink *dl = (struct datalink *)v;
return (*dl->parent->LayerStart)(dl->parent->object, fp);
if (fp == &LcpInfo.fsm) {
struct datalink *dl = (struct datalink *)v;
(*dl->parent->LayerStart)(dl->parent->object, fp);
}
}
static void
@ -328,22 +361,58 @@ datalink_LayerUp(void *v, struct fsm *fp)
struct datalink *dl = (struct datalink *)v;
if (fp == &LcpInfo.fsm) {
(*dl->parent->LayerUp)(dl->parent->object, fp);
FsmUp(&dl->ccp.fsm);
FsmOpen(&dl->ccp.fsm);
LcpInfo.auth_ineed = LcpInfo.want_auth;
LcpInfo.auth_iwait = LcpInfo.his_auth;
if (LcpInfo.his_auth || LcpInfo.want_auth) {
if (dl->bundle->phase == PHASE_DEAD ||
dl->bundle->phase == PHASE_ESTABLISH)
bundle_NewPhase(dl->bundle, dl->physical, PHASE_AUTHENTICATE);
LogPrintf(LogPHASE, "%s: his = %s, mine = %s\n", dl->name,
Auth2Nam(LcpInfo.his_auth), Auth2Nam(LcpInfo.want_auth));
if (LcpInfo.his_auth == PROTO_PAP)
StartAuthChallenge(&dl->pap, dl->physical, SendPapChallenge);
if (LcpInfo.want_auth == PROTO_CHAP)
StartAuthChallenge(&dl->chap.auth, dl->physical, SendChapChallenge);
} else
datalink_AuthOk(dl);
}
}
void
datalink_AuthOk(struct datalink *dl)
{
FsmUp(&dl->ccp.fsm);
FsmOpen(&dl->ccp.fsm);
dl->state = DATALINK_OPEN;
(*dl->parent->LayerUp)(dl->parent->object, &LcpInfo.fsm);
}
void
datalink_AuthNotOk(struct datalink *dl)
{
dl->state = DATALINK_LCP;
FsmClose(&LcpInfo.fsm);
}
static void
datalink_LayerDown(void *v, struct fsm *fp)
{
/* The given FSM has been told to come down */
struct datalink *dl = (struct datalink *)v;
if (fp == &LcpInfo.fsm) {
FsmDown(fp);
FsmClose(fp);
switch (dl->state) {
case DATALINK_OPEN:
FsmDown(&dl->ccp.fsm);
FsmClose(&dl->ccp.fsm);
(*dl->parent->LayerDown)(dl->parent->object, fp);
/* fall through */
case DATALINK_AUTH:
StopTimer(&dl->pap.authtimer);
StopTimer(&dl->chap.auth.authtimer);
}
dl->state = DATALINK_LCP;
}
return (*dl->parent->LayerDown)(dl->parent->object, fp);
}
static void
@ -354,10 +423,7 @@ datalink_LayerFinish(void *v, struct fsm *fp)
if (fp == &LcpInfo.fsm) {
(*dl->parent->LayerFinish)(dl->parent->object, fp);
if (link_IsActive(fp->link))
link_Close(fp->link, dl->bundle, 0, 0); /* clean shutdown */
/* And wait for the LinkLost() */
datalink_ComeDown(dl, 0);
}
}
@ -418,6 +484,9 @@ datalink_Create(const char *name, struct bundle *bundle,
lcp_Init(&LcpInfo, dl->bundle, dl->physical, &dl->fsm);
ccp_Init(&dl->ccp, dl->bundle, &dl->physical->link, &dl->fsm);
authinfo_Init(&dl->pap);
authinfo_Init(&dl->chap.auth);
LogPrintf(LogPHASE, "%s: Created in CLOSED state\n", dl->name);
return dl;
@ -471,55 +540,52 @@ datalink_Up(struct datalink *dl, int runscripts, int packetmode)
}
}
static void
datalink_ComeDown(struct datalink *dl, int stay)
{
if (stay) {
dl->dial_tries = -1;
dl->reconnect_tries = 0;
}
if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) {
modem_Offline(dl->physical);
if (dl->script.run && dl->state != DATALINK_OPENING) {
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1);
} else
datalink_HangupDone(dl);
}
}
void
datalink_Close(struct datalink *dl, int stay)
{
/* Please close */
if (dl->state == DATALINK_OPEN) {
FsmClose(&dl->ccp.fsm);
FsmClose(&LcpInfo.fsm);
if (stay) {
dl->dial_tries = -1;
dl->reconnect_tries = 0;
}
} else
datalink_ComeDown(dl, stay);
switch (dl->state) {
case DATALINK_OPEN:
FsmDown(&dl->ccp.fsm);
FsmClose(&dl->ccp.fsm);
/* fall through */
case DATALINK_AUTH:
case DATALINK_LCP:
FsmClose(&LcpInfo.fsm);
if (stay) {
dl->dial_tries = -1;
dl->reconnect_tries = 0;
}
break;
default:
datalink_ComeDown(dl, stay);
}
}
void
datalink_Down(struct datalink *dl, int stay)
{
/* Carrier is lost */
if (dl->state == DATALINK_OPEN) {
FsmDown(&dl->ccp.fsm);
FsmClose(&dl->ccp.fsm);
FsmDown(&LcpInfo.fsm);
if (stay)
FsmClose(&LcpInfo.fsm);
else
FsmOpen(&dl->ccp.fsm);
}
switch (dl->state) {
case DATALINK_OPEN:
FsmDown(&dl->ccp.fsm);
FsmClose(&dl->ccp.fsm);
/* fall through */
datalink_ComeDown(dl, stay);
case DATALINK_AUTH:
case DATALINK_LCP:
FsmDown(&LcpInfo.fsm);
if (stay)
FsmClose(&LcpInfo.fsm);
else
FsmOpen(&dl->ccp.fsm);
/* fall through */
default:
datalink_ComeDown(dl, stay);
}
}
void
@ -541,6 +607,8 @@ static char *states[] = {
"DIAL",
"LOGIN",
"READY",
"LCP"
"AUTH"
"OPEN"
};

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.h,v 1.1.2.8 1998/02/23 00:38:27 brian Exp $
* $Id: datalink.h,v 1.1.2.9 1998/02/27 01:22:21 brian Exp $
*/
#define DATALINK_CLOSED (0)
@ -32,7 +32,9 @@
#define DATALINK_DIAL (3)
#define DATALINK_LOGIN (4)
#define DATALINK_READY (5)
#define DATALINK_OPEN (6)
#define DATALINK_LCP (6)
#define DATALINK_AUTH (7)
#define DATALINK_OPEN (8)
struct datalink {
struct descriptor desc; /* We play either a physical or a chat */
@ -73,6 +75,9 @@ struct datalink {
#endif
struct ccp ccp; /* Our compression FSM */
struct authinfo pap; /* Authentication using pap */
struct chap chap; /* Authentication using chap */
struct bundle *bundle; /* for the moment */
struct datalink *next; /* Next in the list */
};
@ -89,3 +94,5 @@ extern void datalink_Close(struct datalink *, int);
extern void datalink_Down(struct datalink *, int);
extern void datalink_StayDown(struct datalink *);
extern void datalink_Show(struct datalink *);
extern void datalink_AuthOk(struct datalink *);
extern void datalink_AuthNotOk(struct datalink *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: hdlc.c,v 1.28.2.13 1998/02/21 01:45:09 brian Exp $
* $Id: hdlc.c,v 1.28.2.14 1998/02/23 00:38:30 brian Exp $
*
* TODO:
*/
@ -41,6 +41,7 @@
#include "ipcp.h"
#include "ip.h"
#include "vjcomp.h"
#include "auth.h"
#include "pap.h"
#include "chap.h"
#include "lcp.h"

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lcp.c,v 1.55.2.21 1998/02/27 01:22:30 brian Exp $
* $Id: lcp.c,v 1.55.2.22 1998/02/27 21:46:26 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -383,8 +383,6 @@ static void
StopAllTimers(void)
{
StopIdleTimer();
StopTimer(&AuthPapInfo.authtimer);
StopTimer(&AuthChapInfo.authtimer);
StopLqrTimer();
}
@ -394,7 +392,6 @@ LcpLayerFinish(struct fsm *fp)
/* We're now down */
LogPrintf(LogLCP, "LcpLayerFinish\n");
StopAllTimers();
LogPrintf(LogPHASE, "%s disconnected!\n", fp->link->name);
}
static void

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.121.2.27 1998/02/21 01:45:19 brian Exp $
* $Id: main.c,v 1.121.2.28 1998/02/23 00:38:35 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -80,6 +80,7 @@
#include "server.h"
#include "prompt.h"
#include "chat.h"
#include "chap.h"
#include "datalink.h"
#ifndef O_NONBLOCK

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.c,v 1.77.2.25 1998/02/23 00:38:36 brian Exp $
* $Id: modem.c,v 1.77.2.26 1998/02/27 21:46:00 brian Exp $
*
* TODO:
*/
@ -66,6 +66,8 @@
#include "prompt.h"
#include "chat.h"
#include "ccp.h"
#include "auth.h"
#include "chap.h"
#include "datalink.h"
@ -787,6 +789,7 @@ modem_Offline(struct physical *modem)
tcsetattr(modem->fd, TCSANOW, &tio);
/* nointr_sleep(1); */
}
LogPrintf(LogPHASE, "%s disconnected!\n", modem->link.name);
}
}
@ -799,8 +802,6 @@ modem_Close(struct physical *modem)
if (modem->fd < 0)
return;
modem_Offline(modem);
if (!isatty(modem->fd)) {
modem_PhysicalClose(modem);
return;

View File

@ -18,7 +18,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: pap.c,v 1.20.2.9 1998/02/16 00:00:54 brian Exp $
* $Id: pap.c,v 1.20.2.10 1998/02/19 02:08:53 brian Exp $
*
* TODO:
*/
@ -45,12 +45,12 @@
#include "timer.h"
#include "fsm.h"
#include "lcp.h"
#include "auth.h"
#include "pap.h"
#include "loadalias.h"
#include "vars.h"
#include "hdlc.h"
#include "lcpproto.h"
#include "auth.h"
#include "async.h"
#include "throughput.h"
#include "link.h"
@ -58,11 +58,15 @@
#include "physical.h"
#include "bundle.h"
#include "id.h"
#include "chat.h"
#include "ccp.h"
#include "chap.h"
#include "datalink.h"
static const char *papcodes[] = { "???", "REQUEST", "ACK", "NAK" };
static void
SendPapChallenge(int papid, struct physical *physical)
void
SendPapChallenge(struct authinfo *auth, int papid, struct physical *physical)
{
struct fsmheader lh;
struct mbuf *bp;
@ -93,10 +97,6 @@ SendPapChallenge(int papid, struct physical *physical)
HdlcOutput(physical2link(physical), PRI_LINK, PROTO_PAP, bp);
}
struct authinfo AuthPapInfo = {
SendPapChallenge,
};
static void
SendPapCode(int id, int code, const char *message, struct physical *physical)
{
@ -154,6 +154,7 @@ PapValidate(struct bundle *bundle, u_char *name, u_char *key,
void
PapInput(struct bundle *bundle, struct mbuf *bp, struct physical *physical)
{
struct datalink *dl = bundle2datalink(bundle, physical->link.name);
int len = plength(bp);
struct fsmheader *php;
u_char *cp;
@ -191,15 +192,15 @@ PapInput(struct bundle *bundle, struct mbuf *bp, struct physical *physical)
* Either I didn't need to authenticate, or I've already been
* told that I got the answer right.
*/
bundle_NewPhase(bundle, physical, PHASE_NETWORK);
datalink_AuthOk(dl);
} else {
SendPapCode(php->id, PAP_NAK, "Login incorrect", physical);
link_Close(&physical->link, bundle, 1, 1);
datalink_AuthNotOk(dl);
}
break;
case PAP_ACK:
StopAuthTimer(&AuthPapInfo);
StopAuthTimer(&dl->pap);
cp = (u_char *) (php + 1);
len = *cp++;
cp[len] = 0;
@ -212,16 +213,16 @@ PapInput(struct bundle *bundle, struct mbuf *bp, struct physical *physical)
* If we're not expecting the peer to authenticate (or he already
* has), proceed to network phase.
*/
bundle_NewPhase(bundle, physical, PHASE_NETWORK);
datalink_AuthOk(dl);
}
break;
case PAP_NAK:
StopAuthTimer(&AuthPapInfo);
StopAuthTimer(&dl->pap);
cp = (u_char *) (php + 1);
len = *cp++;
cp[len] = 0;
LogPrintf(LogPHASE, "Received PAP_NAK (%s)\n", cp);
link_Close(&physical->link, bundle, 1, 1);
datalink_AuthNotOk(dl);
break;
}
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: pap.h,v 1.5.2.1 1998/01/29 00:49:28 brian Exp $
* $Id: pap.h,v 1.5.2.2 1998/02/02 19:32:13 brian Exp $
*
* TODO:
*/
@ -24,6 +24,5 @@
#define PAP_ACK 2
#define PAP_NAK 3
extern struct authinfo AuthPapInfo;
extern void PapInput(struct bundle *, struct mbuf *, struct physical *);
extern void SendPapChallenge(struct authinfo *, int, struct physical *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: prompt.c,v 1.1.2.8 1998/02/23 00:38:41 brian Exp $
* $Id: prompt.c,v 1.1.2.9 1998/02/27 01:22:37 brian Exp $
*/
#include <sys/param.h>
@ -59,6 +59,7 @@
#include "physical.h"
#include "chat.h"
#include "ccp.h"
#include "chap.h"
#include "datalink.h"
static int prompt_nonewline = 1;