aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/pppd/chap.c
diff options
context:
space:
mode:
authorPeter Wemm <peter@FreeBSD.org>1995-10-31 21:21:51 +0000
committerPeter Wemm <peter@FreeBSD.org>1995-10-31 21:21:51 +0000
commit60f531a365ae3ea74e34b0c4f1f9482da86d03a0 (patch)
tree4d3d1e7e23ca53f41a20a9c41f78068854a5325f /usr.sbin/pppd/chap.c
parente046098fa9daa1381e7180ae5d3ad3cd36402368 (diff)
downloadsrc-60f531a365ae3ea74e34b0c4f1f9482da86d03a0.tar.gz
src-60f531a365ae3ea74e34b0c4f1f9482da86d03a0.zip
Bring pppd from ppp-2.2 onto the mainline..
(more work needs to be done here, I'm trying to beat the supscan)
Notes
Notes: svn path=/head/; revision=11983
Diffstat (limited to 'usr.sbin/pppd/chap.c')
-rw-r--r--usr.sbin/pppd/chap.c118
1 files changed, 50 insertions, 68 deletions
diff --git a/usr.sbin/pppd/chap.c b/usr.sbin/pppd/chap.c
index 14b28b16b3d4..d72c36d4a989 100644
--- a/usr.sbin/pppd/chap.c
+++ b/usr.sbin/pppd/chap.c
@@ -19,7 +19,7 @@
*/
#ifndef lint
-static char rcsid[] = "$Id: chap.c,v 1.2 1994/09/25 02:31:54 wollman Exp $";
+static char rcsid[] = "$Id: chap.c,v 1.8 1995/07/04 12:32:26 paulus Exp $";
#endif
/*
@@ -27,30 +27,30 @@ static char rcsid[] = "$Id: chap.c,v 1.2 1994/09/25 02:31:54 wollman Exp $";
*/
#include <stdio.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
#include <syslog.h>
-#include "ppp.h"
#include "pppd.h"
#include "chap.h"
#include "md5.h"
-chap_state chap[NPPP]; /* CHAP state; one for each unit */
+chap_state chap[NUM_PPP]; /* CHAP state; one for each unit */
-static void ChapChallengeTimeout __ARGS((caddr_t));
-static void ChapResponseTimeout __ARGS((caddr_t));
-static void ChapReceiveChallenge __ARGS((chap_state *, u_char *, int, int));
-static void ChapReceiveResponse __ARGS((chap_state *, u_char *, int, int));
-static void ChapReceiveSuccess __ARGS((chap_state *, u_char *, int, int));
-static void ChapReceiveFailure __ARGS((chap_state *, u_char *, int, int));
-static void ChapSendStatus __ARGS((chap_state *, int));
-static void ChapSendChallenge __ARGS((chap_state *));
-static void ChapSendResponse __ARGS((chap_state *));
-static void ChapGenChallenge __ARGS((chap_state *));
+static void ChapChallengeTimeout __P((caddr_t));
+static void ChapResponseTimeout __P((caddr_t));
+static void ChapReceiveChallenge __P((chap_state *, u_char *, int, int));
+static void ChapReceiveResponse __P((chap_state *, u_char *, int, int));
+static void ChapReceiveSuccess __P((chap_state *, u_char *, int, int));
+static void ChapReceiveFailure __P((chap_state *, u_char *, int, int));
+static void ChapSendStatus __P((chap_state *, int));
+static void ChapSendChallenge __P((chap_state *));
+static void ChapSendResponse __P((chap_state *));
+static void ChapGenChallenge __P((chap_state *));
-extern double drand48 __ARGS((void));
-extern void srand48 __ARGS((long));
+extern double drand48 __P((void));
+extern void srand48 __P((long));
/*
* ChapInit - Initialize a CHAP unit.
@@ -67,7 +67,7 @@ ChapInit(unit)
cstate->serverstate = CHAPSS_INITIAL;
cstate->timeouttime = CHAP_DEFTIMEOUT;
cstate->max_transmits = CHAP_DEFTRANSMITS;
- srand48((long) time(NULL)); /* joggle random number generator */
+ /* random number generator is initialized in magic_init */
}
@@ -95,7 +95,7 @@ ChapAuthWithPeer(unit, our_name, digest)
/*
* We get here as a result of LCP coming up.
- * So even if CHAP was open before, we will
+ * So even if CHAP was open before, we will
* have to re-authenticate ourselves.
*/
cstate->clientstate = CHAPCS_LISTEN;
@@ -112,7 +112,7 @@ ChapAuthPeer(unit, our_name, digest)
int digest;
{
chap_state *cstate = &chap[unit];
-
+
cstate->chal_name = our_name;
cstate->chal_type = digest;
@@ -137,7 +137,7 @@ ChapChallengeTimeout(arg)
caddr_t arg;
{
chap_state *cstate = (chap_state *) arg;
-
+
/* if we aren't sending challenges, don't worry. then again we */
/* probably shouldn't be here either */
if (cstate->serverstate != CHAPSS_INITIAL_CHAL &&
@@ -148,7 +148,7 @@ ChapChallengeTimeout(arg)
/* give up on peer */
syslog(LOG_ERR, "Peer failed to respond to CHAP challenge");
cstate->serverstate = CHAPSS_BADAUTH;
- auth_peer_fail(cstate->unit, CHAP);
+ auth_peer_fail(cstate->unit, PPP_CHAP);
return;
}
@@ -189,9 +189,6 @@ ChapRechallenge(arg)
ChapGenChallenge(cstate);
ChapSendChallenge(cstate);
cstate->serverstate = CHAPSS_RECHALLENGE;
-
- if (cstate->chal_interval != 0)
- TIMEOUT(ChapRechallenge, (caddr_t) cstate, cstate->chal_interval);
}
@@ -205,7 +202,7 @@ ChapLowerUp(unit)
int unit;
{
chap_state *cstate = &chap[unit];
-
+
if (cstate->clientstate == CHAPCS_INITIAL)
cstate->clientstate = CHAPCS_CLOSED;
else if (cstate->clientstate == CHAPCS_PENDING)
@@ -231,7 +228,7 @@ ChapLowerDown(unit)
int unit;
{
chap_state *cstate = &chap[unit];
-
+
/* Timeout(s) pending? Cancel if so. */
if (cstate->serverstate == CHAPSS_INITIAL_CHAL ||
cstate->serverstate == CHAPSS_RECHALLENGE)
@@ -258,10 +255,10 @@ ChapProtocolReject(unit)
if (cstate->serverstate != CHAPSS_INITIAL &&
cstate->serverstate != CHAPSS_CLOSED)
- auth_peer_fail(unit, CHAP);
+ auth_peer_fail(unit, PPP_CHAP);
if (cstate->clientstate != CHAPCS_INITIAL &&
cstate->clientstate != CHAPCS_CLOSED)
- auth_withpeer_fail(unit, CHAP);
+ auth_withpeer_fail(unit, PPP_CHAP);
ChapLowerDown(unit); /* shutdown chap */
}
@@ -279,7 +276,7 @@ ChapInput(unit, inpacket, packet_len)
u_char *inp;
u_char code, id;
int len;
-
+
/*
* Parse header (code, id and length).
* If packet too short, drop it.
@@ -301,7 +298,7 @@ ChapInput(unit, inpacket, packet_len)
return;
}
len -= CHAP_HEADERLEN;
-
+
/*
* Action depends on code (as in fact it usually does :-).
*/
@@ -309,11 +306,11 @@ ChapInput(unit, inpacket, packet_len)
case CHAP_CHALLENGE:
ChapReceiveChallenge(cstate, inp, id, len);
break;
-
+
case CHAP_RESPONSE:
ChapReceiveResponse(cstate, inp, id, len);
break;
-
+
case CHAP_FAILURE:
ChapReceiveFailure(cstate, inp, id, len);
break;
@@ -345,7 +342,7 @@ ChapReceiveChallenge(cstate, inp, id, len)
char secret[MAXSECRETLEN];
char rhostname[256];
MD5_CTX mdContext;
-
+
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: Rcvd id %d.", id));
if (cstate->clientstate == CHAPCS_CLOSED ||
cstate->clientstate == CHAPCS_PENDING) {
@@ -392,7 +389,7 @@ ChapReceiveChallenge(cstate, inp, id, len)
cstate->resp_transmits = 0;
/* generate MD based on negotiated type */
- switch (cstate->resp_type) {
+ switch (cstate->resp_type) {
case CHAP_DIGEST_MD5: /* only MD5 is defined for now */
MD5Init(&mdContext);
@@ -494,7 +491,7 @@ ChapReceiveResponse(cstate, inp, id, len)
} else {
/* generate MD based on negotiated type */
- switch (cstate->chal_type) {
+ switch (cstate->chal_type) {
case CHAP_DIGEST_MD5: /* only MD5 is defined for now */
if (remmd_len != MD5_SIGNATURE_SIZE)
@@ -503,10 +500,10 @@ ChapReceiveResponse(cstate, inp, id, len)
MD5Update(&mdContext, &cstate->chal_id, 1);
MD5Update(&mdContext, secret, secret_len);
MD5Update(&mdContext, cstate->challenge, cstate->chal_len);
- MD5Final(&mdContext);
+ MD5Final(&mdContext);
/* compare local and remote MDs and send the appropriate status */
- if (bcmp (mdContext.digest, remmd, MD5_SIGNATURE_SIZE) == 0)
+ if (memcmp (mdContext.digest, remmd, MD5_SIGNATURE_SIZE) == 0)
code = CHAP_SUCCESS; /* they are the same! */
break;
@@ -521,7 +518,7 @@ ChapReceiveResponse(cstate, inp, id, len)
old_state = cstate->serverstate;
cstate->serverstate = CHAPSS_OPEN;
if (old_state == CHAPSS_INITIAL_CHAL) {
- auth_peer_success(cstate->unit, CHAP);
+ auth_peer_success(cstate->unit, PPP_CHAP);
}
if (cstate->chal_interval != 0)
TIMEOUT(ChapRechallenge, (caddr_t) cstate, cstate->chal_interval);
@@ -529,7 +526,7 @@ ChapReceiveResponse(cstate, inp, id, len)
} else {
syslog(LOG_ERR, "CHAP peer authentication failed");
cstate->serverstate = CHAPSS_BADAUTH;
- auth_peer_fail(cstate->unit, CHAP);
+ auth_peer_fail(cstate->unit, PPP_CHAP);
}
}
@@ -567,7 +564,7 @@ ChapReceiveSuccess(cstate, inp, id, len)
cstate->clientstate = CHAPCS_OPEN;
- auth_withpeer_success(cstate->unit, CHAP);
+ auth_withpeer_success(cstate->unit, PPP_CHAP);
}
@@ -583,7 +580,7 @@ ChapReceiveFailure(cstate, inp, id, len)
{
u_char msglen;
u_char *msg;
-
+
CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: Rcvd id %d.", id));
if (cstate->clientstate != CHAPCS_RESPONSE) {
@@ -602,7 +599,7 @@ ChapReceiveFailure(cstate, inp, id, len)
PRINTMSG(inp, len);
syslog(LOG_ERR, "CHAP authentication failed");
- auth_withpeer_fail(cstate->unit, CHAP);
+ auth_withpeer_fail(cstate->unit, PPP_CHAP);
}
@@ -622,7 +619,7 @@ ChapSendChallenge(cstate)
outlen = CHAP_HEADERLEN + sizeof (u_char) + chal_len + name_len;
outp = outpacket_buf;
- MAKEHEADER(outp, CHAP); /* paste in a CHAP header */
+ MAKEHEADER(outp, PPP_CHAP); /* paste in a CHAP header */
PUTCHAR(CHAP_CHALLENGE, outp);
PUTCHAR(cstate->chal_id, outp);
@@ -634,8 +631,8 @@ ChapSendChallenge(cstate)
BCOPY(cstate->chal_name, outp, name_len); /* append hostname */
- output(cstate->unit, outpacket_buf, outlen + DLLHEADERLEN);
-
+ output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
+
CHAPDEBUG((LOG_INFO, "ChapSendChallenge: Sent id %d.", cstate->chal_id));
TIMEOUT(ChapChallengeTimeout, (caddr_t) cstate, cstate->timeouttime);
@@ -664,14 +661,14 @@ ChapSendStatus(cstate, code)
outlen = CHAP_HEADERLEN + msglen;
outp = outpacket_buf;
- MAKEHEADER(outp, CHAP); /* paste in a header */
-
+ MAKEHEADER(outp, PPP_CHAP); /* paste in a header */
+
PUTCHAR(code, outp);
PUTCHAR(cstate->chal_id, outp);
PUTSHORT(outlen, outp);
BCOPY(msg, outp, msglen);
- output(cstate->unit, outpacket_buf, outlen + DLLHEADERLEN);
-
+ output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
+
CHAPDEBUG((LOG_INFO, "ChapSendStatus: Sent code %d, id %d.", code,
cstate->chal_id));
}
@@ -691,8 +688,8 @@ ChapGenChallenge(cstate)
u_char *ptr = cstate->challenge;
unsigned int i;
- /* pick a random challenge length between MIN_CHALLENGE_LENGTH and
- MAX_CHALLENGE_LENGTH */
+ /* pick a random challenge length between MIN_CHALLENGE_LENGTH and
+ MAX_CHALLENGE_LENGTH */
chal_len = (unsigned) ((drand48() *
(MAX_CHALLENGE_LENGTH - MIN_CHALLENGE_LENGTH)) +
MIN_CHALLENGE_LENGTH);
@@ -722,7 +719,7 @@ ChapSendResponse(cstate)
outlen = CHAP_HEADERLEN + sizeof (u_char) + md_len + name_len;
outp = outpacket_buf;
- MAKEHEADER(outp, CHAP);
+ MAKEHEADER(outp, PPP_CHAP);
PUTCHAR(CHAP_RESPONSE, outp); /* we are a response */
PUTCHAR(cstate->resp_id, outp); /* copy id from challenge packet */
@@ -735,7 +732,7 @@ ChapSendResponse(cstate)
BCOPY(cstate->resp_name, outp, name_len); /* append our name */
/* send the packet */
- output(cstate->unit, outpacket_buf, outlen + DLLHEADERLEN);
+ output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
cstate->clientstate = CHAPCS_RESPONSE;
TIMEOUT(ChapResponseTimeout, (caddr_t) cstate, cstate->timeouttime);
@@ -753,7 +750,7 @@ int
ChapPrintPkt(p, plen, printer, arg)
u_char *p;
int plen;
- void (*printer) __ARGS((void *, char *, ...));
+ void (*printer) __P((void *, char *, ...));
void *arg;
{
int code, id, len;
@@ -806,18 +803,3 @@ ChapPrintPkt(p, plen, printer, arg)
return len + CHAP_HEADERLEN;
}
-
-#ifdef NO_DRAND48
-
-double drand48()
-{
- return (double)random() / (double)0x7fffffffL; /* 2**31-1 */
-}
-
-void srand48(seedval)
-long seedval;
-{
- srand((int)seedval);
-}
-
-#endif