2001-06-13 21:52:19 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
|
|
|
|
* Internet Initiative Japan, Inc (IIJ)
|
|
|
|
* All rights reserved.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
2001-06-13 21:52:19 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <sys/param.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netinet/in.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
2001-08-14 16:05:52 +00:00
|
|
|
#include <sys/socket.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <sys/un.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1999-02-11 10:14:08 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1998-05-21 22:55:08 +00:00
|
|
|
#include <md4.h>
|
1998-06-27 14:18:15 +00:00
|
|
|
#endif
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <md5.h>
|
1999-02-11 10:14:08 +00:00
|
|
|
#include <paths.h>
|
|
|
|
#include <signal.h>
|
1999-08-17 14:59:05 +00:00
|
|
|
#include <stdio.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <stdlib.h>
|
1999-02-18 00:52:15 +00:00
|
|
|
#include <string.h>
|
1999-02-11 10:14:08 +00:00
|
|
|
#include <sys/wait.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <termios.h>
|
1999-02-11 10:14:08 +00:00
|
|
|
#include <unistd.h>
|
1997-09-25 00:52:37 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "layer.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"
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "proto.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "lqr.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "hdlc.h"
|
2000-07-19 02:10:35 +00:00
|
|
|
#include "lcp.h"
|
1995-02-26 12:18:08 +00:00
|
|
|
#include "auth.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "async.h"
|
|
|
|
#include "throughput.h"
|
|
|
|
#include "descriptor.h"
|
1999-02-11 10:14:08 +00:00
|
|
|
#include "chap.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "iplist.h"
|
|
|
|
#include "slcompress.h"
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ncpaddr.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "ipcp.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#include "ccp.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "physical.h"
|
|
|
|
#include "mp.h"
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
#include "radius.h"
|
|
|
|
#endif
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ipv6cp.h"
|
|
|
|
#include "ncp.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "bundle.h"
|
|
|
|
#include "chat.h"
|
1998-08-07 18:42:51 +00:00
|
|
|
#include "cbcp.h"
|
1999-02-11 10:14:08 +00:00
|
|
|
#include "command.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "datalink.h"
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1998-05-21 22:55:08 +00:00
|
|
|
#include "chap_ms.h"
|
2000-10-30 00:15:04 +00:00
|
|
|
#include "mppe.h"
|
1998-06-27 14:18:15 +00:00
|
|
|
#endif
|
1999-12-30 03:40:29 +00:00
|
|
|
#include "id.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-12-27 11:54:57 +00:00
|
|
|
static const char * const chapcodes[] = {
|
1996-11-19 11:08:27 +00:00
|
|
|
"???", "CHALLENGE", "RESPONSE", "SUCCESS", "FAILURE"
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
1999-02-06 02:54:47 +00:00
|
|
|
#define MAXCHAPCODE (sizeof chapcodes / sizeof chapcodes[0] - 1)
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
ChapOutput(struct physical *physical, u_int code, u_int id,
|
1999-02-06 02:54:47 +00:00
|
|
|
const u_char *ptr, int count, const char *text)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int plen;
|
|
|
|
struct fsmheader lh;
|
|
|
|
struct mbuf *bp;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
plen = sizeof(struct fsmheader) + count;
|
1995-01-31 06:29:58 +00:00
|
|
|
lh.code = code;
|
|
|
|
lh.id = id;
|
|
|
|
lh.length = htons(plen);
|
1999-12-20 20:29:47 +00:00
|
|
|
bp = m_get(plen, MB_CHAPOUT);
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
|
1995-01-31 06:29:58 +00:00
|
|
|
if (count)
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_DumpBp(LogDEBUG, "ChapOutput", bp);
|
1998-07-28 21:54:30 +00:00
|
|
|
if (text == NULL)
|
|
|
|
log_Printf(LogPHASE, "Chap Output: %s\n", chapcodes[code]);
|
|
|
|
else
|
|
|
|
log_Printf(LogPHASE, "Chap Output: %s (%s)\n", chapcodes[code], text);
|
1999-05-08 11:07:56 +00:00
|
|
|
link_PushPacket(&physical->link, bp, physical->dl->bundle,
|
1999-09-04 00:00:21 +00:00
|
|
|
LINK_QUEUES(&physical->link) - 1, PROTO_CHAP);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
static char *
|
1999-02-18 19:45:06 +00:00
|
|
|
chap_BuildAnswer(char *name, char *key, u_char id, char *challenge, u_char type
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2000-10-30 00:15:04 +00:00
|
|
|
, char *peerchallenge, char *authresponse, int lanman
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
|
|
|
)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1999-02-06 02:54:47 +00:00
|
|
|
char *result, *digest;
|
|
|
|
size_t nlen, klen;
|
|
|
|
|
|
|
|
nlen = strlen(name);
|
|
|
|
klen = strlen(key);
|
|
|
|
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
if (type == 0x80) {
|
1999-02-06 02:54:47 +00:00
|
|
|
char expkey[AUTHLEN << 2];
|
|
|
|
MD4_CTX MD4context;
|
|
|
|
int f;
|
|
|
|
|
|
|
|
if ((result = malloc(1 + nlen + MS_CHAP_RESPONSE_LEN)) == NULL)
|
|
|
|
return result;
|
|
|
|
|
1999-02-18 00:52:15 +00:00
|
|
|
digest = result; /* the response */
|
|
|
|
*digest++ = MS_CHAP_RESPONSE_LEN; /* 49 */
|
|
|
|
memcpy(digest + MS_CHAP_RESPONSE_LEN, name, nlen);
|
|
|
|
if (lanman) {
|
|
|
|
memset(digest + 24, '\0', 25);
|
|
|
|
mschap_LANMan(digest, challenge + 1, key); /* LANMan response */
|
|
|
|
} else {
|
|
|
|
memset(digest, '\0', 25);
|
|
|
|
digest += 24;
|
1999-02-06 02:54:47 +00:00
|
|
|
|
1999-02-18 00:52:15 +00:00
|
|
|
for (f = 0; f < klen; f++) {
|
|
|
|
expkey[2*f] = key[f];
|
|
|
|
expkey[2*f+1] = '\0';
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* -----------
|
|
|
|
* expkey = | k\0e\0y\0 |
|
|
|
|
* -----------
|
|
|
|
*/
|
|
|
|
MD4Init(&MD4context);
|
|
|
|
MD4Update(&MD4context, expkey, klen << 1);
|
|
|
|
MD4Final(digest, &MD4context);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ---- -------- ---------------- ------- ------
|
|
|
|
* result = | 49 | LANMan | 16 byte digest | 9 * ? | name |
|
|
|
|
* ---- -------- ---------------- ------- ------
|
|
|
|
*/
|
|
|
|
mschap_NT(digest, challenge + 1);
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
/*
|
1999-02-18 00:52:15 +00:00
|
|
|
* ---- -------- ------------- ----- ------
|
|
|
|
* | | struct MS_ChapResponse24 | |
|
|
|
|
* result = | 49 | LANMan | NT digest | 0/1 | name |
|
|
|
|
* ---- -------- ------------- ----- ------
|
|
|
|
* where only one of LANMan & NT digest are set.
|
1999-02-06 02:54:47 +00:00
|
|
|
*/
|
2000-10-30 00:15:04 +00:00
|
|
|
} else if (type == 0x81) {
|
|
|
|
char expkey[AUTHLEN << 2];
|
|
|
|
char pwdhash[CHAP81_HASH_LEN];
|
|
|
|
char pwdhashhash[CHAP81_HASH_LEN];
|
|
|
|
char *ntresponse;
|
|
|
|
int f;
|
|
|
|
|
|
|
|
if ((result = malloc(1 + nlen + CHAP81_RESPONSE_LEN)) == NULL)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
memset(result, 0, 1 + nlen + CHAP81_RESPONSE_LEN);
|
|
|
|
|
|
|
|
digest = result;
|
|
|
|
*digest++ = CHAP81_RESPONSE_LEN; /* value size */
|
|
|
|
|
|
|
|
/* Copy our challenge */
|
|
|
|
memcpy(digest, peerchallenge + 1, CHAP81_CHALLENGE_LEN);
|
|
|
|
|
|
|
|
/* Expand password to Unicode XXX */
|
|
|
|
for (f = 0; f < klen; f++) {
|
|
|
|
expkey[2*f] = key[f];
|
|
|
|
expkey[2*f+1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
ntresponse = digest + CHAP81_NTRESPONSE_OFF;
|
|
|
|
|
|
|
|
/* Get some needed hashes */
|
|
|
|
NtPasswordHash(expkey, klen * 2, pwdhash);
|
|
|
|
HashNtPasswordHash(pwdhash, pwdhashhash);
|
|
|
|
|
|
|
|
/* Generate NTRESPONSE to respond on challenge call */
|
|
|
|
GenerateNTResponse(challenge + 1, peerchallenge + 1, name, nlen,
|
|
|
|
expkey, klen * 2, ntresponse);
|
|
|
|
|
|
|
|
/* Generate MPPE MASTERKEY */
|
2000-11-07 23:19:11 +00:00
|
|
|
GetMasterKey(pwdhashhash, ntresponse, MPPE_MasterKey); /* XXX Global ! */
|
2000-10-30 00:15:04 +00:00
|
|
|
|
|
|
|
/* Generate AUTHRESPONSE to verify on auth success */
|
2002-06-15 08:03:30 +00:00
|
|
|
GenerateAuthenticatorResponse(expkey, klen * 2, ntresponse,
|
2000-10-30 00:15:04 +00:00
|
|
|
peerchallenge + 1, challenge + 1, name, nlen,
|
|
|
|
authresponse);
|
|
|
|
|
|
|
|
authresponse[CHAP81_AUTHRESPONSE_LEN] = 0;
|
|
|
|
|
|
|
|
memcpy(digest + CHAP81_RESPONSE_LEN, name, nlen);
|
1999-02-06 02:54:47 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if ((result = malloc(nlen + 17)) != NULL) {
|
|
|
|
/* Normal MD5 stuff */
|
|
|
|
MD5_CTX MD5context;
|
|
|
|
|
|
|
|
digest = result;
|
|
|
|
*digest++ = 16; /* value size */
|
|
|
|
|
|
|
|
MD5Init(&MD5context);
|
|
|
|
MD5Update(&MD5context, &id, 1);
|
|
|
|
MD5Update(&MD5context, key, klen);
|
|
|
|
MD5Update(&MD5context, challenge + 1, *challenge);
|
|
|
|
MD5Final(digest, &MD5context);
|
|
|
|
|
|
|
|
memcpy(digest + 16, name, nlen);
|
|
|
|
/*
|
|
|
|
* ---- -------- ------
|
|
|
|
* result = | 16 | digest | name |
|
|
|
|
* ---- -------- ------
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-02-11 10:14:08 +00:00
|
|
|
static void
|
|
|
|
chap_StartChild(struct chap *chap, char *prog, const char *name)
|
|
|
|
{
|
|
|
|
char *argv[MAXARGS], *nargv[MAXARGS];
|
|
|
|
int argc, fd;
|
|
|
|
int in[2], out[2];
|
1999-06-09 08:47:36 +00:00
|
|
|
pid_t pid;
|
1999-02-11 10:14:08 +00:00
|
|
|
|
|
|
|
if (chap->child.fd != -1) {
|
|
|
|
log_Printf(LogWARN, "Chap: %s: Program already running\n", prog);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pipe(in) == -1) {
|
|
|
|
log_Printf(LogERROR, "Chap: pipe: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pipe(out) == -1) {
|
|
|
|
log_Printf(LogERROR, "Chap: pipe: %s\n", strerror(errno));
|
|
|
|
close(in[0]);
|
|
|
|
close(in[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-06-09 08:47:36 +00:00
|
|
|
pid = getpid();
|
1999-02-11 10:14:08 +00:00
|
|
|
switch ((chap->child.pid = fork())) {
|
|
|
|
case -1:
|
|
|
|
log_Printf(LogERROR, "Chap: fork: %s\n", strerror(errno));
|
|
|
|
close(in[0]);
|
|
|
|
close(in[1]);
|
|
|
|
close(out[0]);
|
|
|
|
close(out[1]);
|
|
|
|
chap->child.pid = 0;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
timer_TermService();
|
1999-12-20 20:30:02 +00:00
|
|
|
|
|
|
|
if ((argc = command_Interpret(prog, strlen(prog), argv)) <= 0) {
|
|
|
|
if (argc < 0) {
|
|
|
|
log_Printf(LogWARN, "CHAP: Invalid command syntax\n");
|
|
|
|
_exit(255);
|
|
|
|
}
|
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
|
1999-02-11 10:14:08 +00:00
|
|
|
close(in[1]);
|
|
|
|
close(out[0]);
|
1999-08-17 14:59:05 +00:00
|
|
|
if (out[1] == STDIN_FILENO)
|
|
|
|
out[1] = dup(out[1]);
|
1999-02-11 10:14:08 +00:00
|
|
|
dup2(in[0], STDIN_FILENO);
|
|
|
|
dup2(out[1], STDOUT_FILENO);
|
1999-08-17 14:59:05 +00:00
|
|
|
close(STDERR_FILENO);
|
|
|
|
if (open(_PATH_DEVNULL, O_RDWR) != STDERR_FILENO) {
|
1999-02-11 10:14:08 +00:00
|
|
|
log_Printf(LogALERT, "Chap: Failed to open %s: %s\n",
|
|
|
|
_PATH_DEVNULL, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
1999-08-17 14:59:05 +00:00
|
|
|
for (fd = getdtablesize(); fd > STDERR_FILENO; fd--)
|
|
|
|
fcntl(fd, F_SETFD, 1);
|
2000-08-18 00:01:44 +00:00
|
|
|
#ifndef NOSUID
|
1999-12-30 03:36:11 +00:00
|
|
|
setuid(ID0realuid());
|
2000-08-18 00:01:44 +00:00
|
|
|
#endif
|
1999-02-11 10:14:08 +00:00
|
|
|
command_Expand(nargv, argc, (char const *const *)argv,
|
1999-06-09 08:47:36 +00:00
|
|
|
chap->auth.physical->dl->bundle, 0, pid);
|
1999-02-11 10:14:08 +00:00
|
|
|
execvp(nargv[0], nargv);
|
1999-08-17 14:59:05 +00:00
|
|
|
printf("exec() of %s failed: %s\n", nargv[0], strerror(errno));
|
|
|
|
_exit(255);
|
1999-02-11 10:14:08 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
close(in[0]);
|
|
|
|
close(out[1]);
|
|
|
|
chap->child.fd = out[0];
|
|
|
|
chap->child.buf.len = 0;
|
|
|
|
write(in[1], chap->auth.in.name, strlen(chap->auth.in.name));
|
|
|
|
write(in[1], "\n", 1);
|
1999-04-21 08:03:51 +00:00
|
|
|
write(in[1], chap->challenge.peer + 1, *chap->challenge.peer);
|
1999-02-11 10:14:08 +00:00
|
|
|
write(in[1], "\n", 1);
|
|
|
|
write(in[1], name, strlen(name));
|
|
|
|
write(in[1], "\n", 1);
|
|
|
|
close(in[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chap_Cleanup(struct chap *chap, int sig)
|
|
|
|
{
|
|
|
|
if (chap->child.pid) {
|
|
|
|
int status;
|
|
|
|
|
|
|
|
close(chap->child.fd);
|
|
|
|
chap->child.fd = -1;
|
|
|
|
if (sig)
|
|
|
|
kill(chap->child.pid, SIGTERM);
|
|
|
|
chap->child.pid = 0;
|
|
|
|
chap->child.buf.len = 0;
|
|
|
|
|
|
|
|
if (wait(&status) == -1)
|
|
|
|
log_Printf(LogERROR, "Chap: wait: %s\n", strerror(errno));
|
|
|
|
else if (WIFSIGNALED(status))
|
|
|
|
log_Printf(LogWARN, "Chap: Child received signal %d\n", WTERMSIG(status));
|
|
|
|
else if (WIFEXITED(status) && WEXITSTATUS(status))
|
|
|
|
log_Printf(LogERROR, "Chap: Child exited %d\n", WEXITSTATUS(status));
|
|
|
|
}
|
1999-04-21 08:03:51 +00:00
|
|
|
*chap->challenge.local = *chap->challenge.peer = '\0';
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
chap->peertries = 0;
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
1999-02-11 10:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-02-18 19:45:06 +00:00
|
|
|
chap_Respond(struct chap *chap, char *name, char *key, u_char type
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 19:45:06 +00:00
|
|
|
, int lm
|
|
|
|
#endif
|
|
|
|
)
|
1999-02-11 10:14:08 +00:00
|
|
|
{
|
1999-02-18 00:52:15 +00:00
|
|
|
u_char *ans;
|
1999-02-11 10:14:08 +00:00
|
|
|
|
1999-04-21 08:03:51 +00:00
|
|
|
ans = chap_BuildAnswer(name, key, chap->auth.id, chap->challenge.peer, type
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2000-10-30 00:15:04 +00:00
|
|
|
, chap->challenge.local, chap->authresponse, lm
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
|
|
|
);
|
1999-02-11 10:14:08 +00:00
|
|
|
|
|
|
|
if (ans) {
|
|
|
|
ChapOutput(chap->auth.physical, CHAP_RESPONSE, chap->auth.id,
|
|
|
|
ans, *ans + 1 + strlen(name), name);
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
chap->NTRespSent = !lm;
|
2000-11-07 23:19:11 +00:00
|
|
|
MPPE_IsServer = 0; /* XXX Global ! */
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
1999-02-11 10:14:08 +00:00
|
|
|
free(ans);
|
|
|
|
} else
|
|
|
|
ChapOutput(chap->auth.physical, CHAP_FAILURE, chap->auth.id,
|
|
|
|
"Out of memory!", 14, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
chap_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
|
1999-02-11 10:14:08 +00:00
|
|
|
{
|
|
|
|
struct chap *chap = descriptor2chap(d);
|
|
|
|
|
|
|
|
if (r && chap && chap->child.fd != -1) {
|
|
|
|
FD_SET(chap->child.fd, r);
|
|
|
|
if (*n < chap->child.fd + 1)
|
|
|
|
*n = chap->child.fd + 1;
|
|
|
|
log_Printf(LogTIMER, "Chap: fdset(r) %d\n", chap->child.fd);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
chap_IsSet(struct fdescriptor *d, const fd_set *fdset)
|
1999-02-11 10:14:08 +00:00
|
|
|
{
|
|
|
|
struct chap *chap = descriptor2chap(d);
|
|
|
|
|
|
|
|
return chap && chap->child.fd != -1 && FD_ISSET(chap->child.fd, fdset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-03-14 01:46:09 +00:00
|
|
|
chap_Read(struct fdescriptor *d, struct bundle *bundle, const fd_set *fdset)
|
1999-02-11 10:14:08 +00:00
|
|
|
{
|
|
|
|
struct chap *chap = descriptor2chap(d);
|
|
|
|
int got;
|
|
|
|
|
|
|
|
got = read(chap->child.fd, chap->child.buf.ptr + chap->child.buf.len,
|
|
|
|
sizeof chap->child.buf.ptr - chap->child.buf.len - 1);
|
|
|
|
if (got == -1) {
|
|
|
|
log_Printf(LogERROR, "Chap: Read: %s\n", strerror(errno));
|
|
|
|
chap_Cleanup(chap, SIGTERM);
|
|
|
|
} else if (got == 0) {
|
|
|
|
log_Printf(LogWARN, "Chap: Read: Child terminated connection\n");
|
|
|
|
chap_Cleanup(chap, SIGTERM);
|
|
|
|
} else {
|
|
|
|
char *name, *key, *end;
|
|
|
|
|
|
|
|
chap->child.buf.len += got;
|
|
|
|
chap->child.buf.ptr[chap->child.buf.len] = '\0';
|
|
|
|
name = chap->child.buf.ptr;
|
|
|
|
name += strspn(name, " \t");
|
|
|
|
if ((key = strchr(name, '\n')) == NULL)
|
|
|
|
end = NULL;
|
|
|
|
else
|
|
|
|
end = strchr(++key, '\n');
|
|
|
|
|
|
|
|
if (end == NULL) {
|
|
|
|
if (chap->child.buf.len == sizeof chap->child.buf.ptr - 1) {
|
|
|
|
log_Printf(LogWARN, "Chap: Read: Input buffer overflow\n");
|
|
|
|
chap_Cleanup(chap, SIGTERM);
|
|
|
|
}
|
|
|
|
} else {
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
int lanman = chap->auth.physical->link.lcp.his_authtype == 0x80 &&
|
|
|
|
((chap->NTRespSent &&
|
|
|
|
IsAccepted(chap->auth.physical->link.lcp.cfg.chap80lm)) ||
|
|
|
|
!IsAccepted(chap->auth.physical->link.lcp.cfg.chap80nt));
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
1999-02-18 00:52:15 +00:00
|
|
|
|
1999-02-11 10:14:08 +00:00
|
|
|
while (end >= name && strchr(" \t\r\n", *end))
|
|
|
|
*end-- = '\0';
|
|
|
|
end = key - 1;
|
|
|
|
while (end >= name && strchr(" \t\r\n", *end))
|
|
|
|
*end-- = '\0';
|
|
|
|
key += strspn(key, " \t");
|
|
|
|
|
1999-02-18 19:45:06 +00:00
|
|
|
chap_Respond(chap, name, key, chap->auth.physical->link.lcp.his_authtype
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 19:45:06 +00:00
|
|
|
, lanman
|
|
|
|
#endif
|
|
|
|
);
|
1999-02-11 10:14:08 +00:00
|
|
|
chap_Cleanup(chap, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
chap_Write(struct fdescriptor *d, struct bundle *bundle, const fd_set *fdset)
|
1999-02-11 10:14:08 +00:00
|
|
|
{
|
|
|
|
/* We never want to write here ! */
|
|
|
|
log_Printf(LogALERT, "chap_Write: Internal error: Bad call !\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
static void
|
2000-10-30 00:15:04 +00:00
|
|
|
chap_ChallengeInit(struct authinfo *authp)
|
1999-02-06 02:54:47 +00:00
|
|
|
{
|
|
|
|
struct chap *chap = auth2chap(authp);
|
1996-01-10 21:28:04 +00:00
|
|
|
int len, i;
|
1995-01-31 06:29:58 +00:00
|
|
|
char *cp;
|
|
|
|
|
1999-02-11 10:14:08 +00:00
|
|
|
len = strlen(authp->physical->dl->bundle->cfg.auth.name);
|
|
|
|
|
1999-04-21 08:03:51 +00:00
|
|
|
if (!*chap->challenge.local) {
|
1999-02-11 10:14:08 +00:00
|
|
|
randinit();
|
1999-04-21 08:03:51 +00:00
|
|
|
cp = chap->challenge.local;
|
1999-01-29 22:46:31 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
1999-02-11 10:14:08 +00:00
|
|
|
if (*authp->physical->dl->bundle->radius.cfg.file) {
|
|
|
|
/* For radius, our challenge is 16 readable NUL terminated bytes :*/
|
|
|
|
*cp++ = 16;
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
*cp++ = (random() % 10) + '0';
|
|
|
|
} else
|
1999-01-28 01:56:34 +00:00
|
|
|
#endif
|
1999-02-11 10:14:08 +00:00
|
|
|
{
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
if (authp->physical->link.lcp.want_authtype == 0x80)
|
|
|
|
*cp++ = 8; /* MS does 8 byte callenges :-/ */
|
2000-10-30 00:15:04 +00:00
|
|
|
else if (authp->physical->link.lcp.want_authtype == 0x81)
|
|
|
|
*cp++ = 16; /* MS-CHAP-V2 does 16 bytes challenges */
|
1999-02-18 00:52:15 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
*cp++ = random() % (CHAPCHALLENGELEN-16) + 16;
|
1999-04-21 08:03:51 +00:00
|
|
|
for (i = 0; i < *chap->challenge.local; i++)
|
1999-02-11 10:14:08 +00:00
|
|
|
*cp++ = random() & 0xff;
|
|
|
|
}
|
|
|
|
memcpy(cp, authp->physical->dl->bundle->cfg.auth.name, len);
|
1999-01-28 01:56:34 +00:00
|
|
|
}
|
2000-10-30 00:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chap_Challenge(struct authinfo *authp)
|
|
|
|
{
|
|
|
|
struct chap *chap = auth2chap(authp);
|
|
|
|
int len;
|
|
|
|
|
2000-10-30 00:15:29 +00:00
|
|
|
log_Printf(LogDEBUG, "CHAP%02X: Challenge\n",
|
|
|
|
authp->physical->link.lcp.want_authtype);
|
2000-10-30 00:15:04 +00:00
|
|
|
|
|
|
|
len = strlen(authp->physical->dl->bundle->cfg.auth.name);
|
|
|
|
|
|
|
|
/* Generate new local challenge value */
|
|
|
|
if (!*chap->challenge.local)
|
|
|
|
chap_ChallengeInit(authp);
|
|
|
|
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2000-10-30 00:15:04 +00:00
|
|
|
if (authp->physical->link.lcp.want_authtype == 0x81)
|
|
|
|
ChapOutput(authp->physical, CHAP_CHALLENGE, authp->id,
|
|
|
|
chap->challenge.local, 1 + *chap->challenge.local, NULL);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
ChapOutput(authp->physical, CHAP_CHALLENGE, authp->id,
|
|
|
|
chap->challenge.local, 1 + *chap->challenge.local + len, NULL);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1999-02-06 02:54:47 +00:00
|
|
|
chap_Success(struct authinfo *authp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
2002-05-10 03:11:35 +00:00
|
|
|
struct bundle *bundle = authp->physical->dl->bundle;
|
2000-10-30 00:15:29 +00:00
|
|
|
const char *msg;
|
2002-05-10 03:11:35 +00:00
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
datalink_GotAuthname(authp->physical->dl, authp->in.name);
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2000-10-30 00:15:04 +00:00
|
|
|
if (authp->physical->link.lcp.want_authtype == 0x81) {
|
2002-05-16 13:34:20 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (*bundle->radius.cfg.file && bundle->radius.msrepstr)
|
|
|
|
msg = bundle->radius.msrepstr;
|
|
|
|
else
|
|
|
|
#endif
|
2002-05-16 14:28:32 +00:00
|
|
|
msg = auth2chap(authp)->authresponse;
|
2000-11-07 23:19:11 +00:00
|
|
|
MPPE_MasterKeyValid = 1; /* XXX Global ! */
|
2000-10-30 00:15:04 +00:00
|
|
|
} else
|
2002-05-10 03:11:35 +00:00
|
|
|
#endif
|
|
|
|
#ifndef NORADIUS
|
|
|
|
if (*bundle->radius.cfg.file && bundle->radius.repstr)
|
|
|
|
msg = bundle->radius.repstr;
|
|
|
|
else
|
2000-10-30 00:15:04 +00:00
|
|
|
#endif
|
|
|
|
msg = "Welcome!!";
|
|
|
|
|
2001-07-31 21:36:00 +00:00
|
|
|
ChapOutput(authp->physical, CHAP_SUCCESS, authp->id, msg, strlen(msg),
|
2000-10-30 00:15:04 +00:00
|
|
|
NULL);
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
authp->physical->link.lcp.auth_ineed = 0;
|
2002-05-10 03:11:35 +00:00
|
|
|
if (Enabled(bundle, OPT_UTMP))
|
1999-02-06 02:54:47 +00:00
|
|
|
physical_Login(authp->physical, authp->in.name);
|
1997-09-25 00:52:37 +00:00
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
if (authp->physical->link.lcp.auth_iwait == 0)
|
1997-11-09 03:55:27 +00:00
|
|
|
/*
|
1999-02-06 02:54:47 +00:00
|
|
|
* Either I didn't need to authenticate, or I've already been
|
|
|
|
* told that I got the answer right.
|
1997-11-09 03:55:27 +00:00
|
|
|
*/
|
1999-02-06 02:54:47 +00:00
|
|
|
datalink_AuthOk(authp->physical->dl);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1999-02-06 02:54:47 +00:00
|
|
|
chap_Failure(struct authinfo *authp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2002-05-10 03:11:35 +00:00
|
|
|
char buf[1024], *ptr;
|
2000-10-30 00:15:04 +00:00
|
|
|
#endif
|
2000-10-30 00:15:29 +00:00
|
|
|
const char *msg;
|
2000-10-30 00:15:04 +00:00
|
|
|
|
2002-05-10 03:11:35 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
struct bundle *bundle = authp->physical->link.lcp.fsm.bundle;
|
|
|
|
if (*bundle->radius.cfg.file && bundle->radius.errstr)
|
|
|
|
msg = bundle->radius.errstr;
|
|
|
|
else
|
|
|
|
#endif
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2002-05-10 03:11:35 +00:00
|
|
|
if (authp->physical->link.lcp.want_authtype == 0x80) {
|
|
|
|
sprintf(buf, "E=691 R=1 M=Invalid!");
|
|
|
|
msg = buf;
|
|
|
|
} else if (authp->physical->link.lcp.want_authtype == 0x81) {
|
2000-10-30 00:15:04 +00:00
|
|
|
int i;
|
|
|
|
|
2000-10-30 00:15:29 +00:00
|
|
|
ptr = buf;
|
|
|
|
ptr += sprintf(buf, "E=691 R=0 C=");
|
2000-10-30 00:15:04 +00:00
|
|
|
for (i=0; i<16; i++)
|
2000-10-30 00:15:29 +00:00
|
|
|
ptr += sprintf(ptr, "%02X", *(auth2chap(authp)->challenge.local+1+i));
|
2002-06-15 08:03:30 +00:00
|
|
|
|
2000-10-30 00:15:29 +00:00
|
|
|
sprintf(ptr, " V=3 M=Invalid!");
|
2000-10-30 00:15:04 +00:00
|
|
|
msg = buf;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
msg = "Invalid!!";
|
|
|
|
|
|
|
|
ChapOutput(authp->physical, CHAP_FAILURE, authp->id, msg, strlen(msg) + 1,
|
|
|
|
NULL);
|
1999-02-06 02:54:47 +00:00
|
|
|
datalink_AuthNotOk(authp->physical->dl);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1999-02-18 00:52:15 +00:00
|
|
|
static int
|
1999-02-18 19:45:06 +00:00
|
|
|
chap_Cmp(u_char type, char *myans, int mylen, char *hisans, int hislen
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 19:45:06 +00:00
|
|
|
, int lm
|
|
|
|
#endif
|
|
|
|
)
|
1999-02-18 00:52:15 +00:00
|
|
|
{
|
2003-11-10 21:56:02 +00:00
|
|
|
int off;
|
|
|
|
|
1999-02-18 00:52:15 +00:00
|
|
|
if (mylen != hislen)
|
|
|
|
return 0;
|
|
|
|
|
2003-11-10 21:56:02 +00:00
|
|
|
off = 0;
|
|
|
|
|
|
|
|
#ifndef NODES
|
|
|
|
if (type == 0x80) {
|
|
|
|
off = lm ? 0 : 24;
|
|
|
|
mylen = 24;
|
1999-02-18 19:45:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
2003-11-10 21:56:02 +00:00
|
|
|
|
|
|
|
for (; mylen; off++, mylen--)
|
|
|
|
if (toupper(myans[off]) != toupper(hisans[off]))
|
|
|
|
return 0;
|
1999-02-18 00:52:15 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
static int
|
|
|
|
chap_HaveAnotherGo(struct chap *chap)
|
|
|
|
{
|
|
|
|
if (++chap->peertries < 3) {
|
|
|
|
/* Give the peer another shot */
|
1999-04-21 08:03:51 +00:00
|
|
|
*chap->challenge.local = '\0';
|
1999-02-18 00:52:15 +00:00
|
|
|
chap_Challenge(&chap->auth);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
1999-02-18 00:52:15 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1999-02-06 02:54:47 +00:00
|
|
|
chap_Init(struct chap *chap, struct physical *p)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1999-02-11 10:14:08 +00:00
|
|
|
chap->desc.type = CHAP_DESCRIPTOR;
|
|
|
|
chap->desc.UpdateSet = chap_UpdateSet;
|
|
|
|
chap->desc.IsSet = chap_IsSet;
|
|
|
|
chap->desc.Read = chap_Read;
|
|
|
|
chap->desc.Write = chap_Write;
|
|
|
|
chap->child.pid = 0;
|
|
|
|
chap->child.fd = -1;
|
1999-02-06 02:54:47 +00:00
|
|
|
auth_Init(&chap->auth, p, chap_Challenge, chap_Success, chap_Failure);
|
1999-04-21 08:03:51 +00:00
|
|
|
*chap->challenge.local = *chap->challenge.peer = '\0';
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
chap->NTRespSent = 0;
|
|
|
|
chap->peertries = 0;
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
1999-02-11 10:14:08 +00:00
|
|
|
void
|
|
|
|
chap_ReInit(struct chap *chap)
|
|
|
|
{
|
|
|
|
chap_Cleanup(chap, SIGTERM);
|
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
struct mbuf *
|
|
|
|
chap_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
|
1999-02-06 02:54:47 +00:00
|
|
|
{
|
1999-05-08 11:07:56 +00:00
|
|
|
struct physical *p = link2physical(l);
|
1999-02-06 02:54:47 +00:00
|
|
|
struct chap *chap = &p->dl->chap;
|
1999-02-18 00:52:15 +00:00
|
|
|
char *name, *key, *ans;
|
1999-02-18 19:45:06 +00:00
|
|
|
int len, nlen;
|
1999-07-15 02:02:51 +00:00
|
|
|
u_char alen;
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 19:45:06 +00:00
|
|
|
int lanman;
|
|
|
|
#endif
|
1999-02-06 02:54:47 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
log_Printf(LogERROR, "chap_Input: Not a physical link - dropped\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bundle_Phase(bundle) != PHASE_NETWORK &&
|
|
|
|
bundle_Phase(bundle) != PHASE_AUTHENTICATE) {
|
1999-04-01 11:05:23 +00:00
|
|
|
log_Printf(LogPHASE, "Unexpected chap input - dropped !\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1999-04-01 11:05:23 +00:00
|
|
|
}
|
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(bp, MB_CHAPIN);
|
1999-02-20 01:12:45 +00:00
|
|
|
if ((bp = auth_ReadHeader(&chap->auth, bp)) == NULL &&
|
|
|
|
ntohs(chap->auth.in.hdr.length) == 0)
|
|
|
|
log_Printf(LogWARN, "Chap Input: Truncated header !\n");
|
1999-02-06 02:54:47 +00:00
|
|
|
else if (chap->auth.in.hdr.code == 0 || chap->auth.in.hdr.code > MAXCHAPCODE)
|
|
|
|
log_Printf(LogPHASE, "Chap Input: %d: Bad CHAP code !\n",
|
|
|
|
chap->auth.in.hdr.code);
|
|
|
|
else {
|
1999-12-20 20:29:47 +00:00
|
|
|
len = m_length(bp);
|
1999-02-06 02:54:47 +00:00
|
|
|
ans = NULL;
|
|
|
|
|
|
|
|
if (chap->auth.in.hdr.code != CHAP_CHALLENGE &&
|
|
|
|
chap->auth.id != chap->auth.in.hdr.id &&
|
1999-05-08 11:07:56 +00:00
|
|
|
Enabled(bundle, OPT_IDCHECK)) {
|
1999-02-06 02:54:47 +00:00
|
|
|
/* Wrong conversation dude ! */
|
|
|
|
log_Printf(LogPHASE, "Chap Input: %s dropped (got id %d, not %d)\n",
|
|
|
|
chapcodes[chap->auth.in.hdr.code], chap->auth.in.hdr.id,
|
|
|
|
chap->auth.id);
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
chap->auth.id = chap->auth.in.hdr.id; /* We respond with this id */
|
|
|
|
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
lanman = 0;
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
1999-02-06 02:54:47 +00:00
|
|
|
switch (chap->auth.in.hdr.code) {
|
|
|
|
case CHAP_CHALLENGE:
|
1999-02-18 00:52:15 +00:00
|
|
|
bp = mbuf_Read(bp, &alen, 1);
|
|
|
|
len -= alen + 1;
|
1999-02-06 02:54:47 +00:00
|
|
|
if (len < 0) {
|
|
|
|
log_Printf(LogERROR, "Chap Input: Truncated challenge !\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
1999-04-21 08:03:51 +00:00
|
|
|
*chap->challenge.peer = alen;
|
|
|
|
bp = mbuf_Read(bp, chap->challenge.peer + 1, alen);
|
1999-02-06 02:54:47 +00:00
|
|
|
bp = auth_ReadName(&chap->auth, bp, len);
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
lanman = p->link.lcp.his_authtype == 0x80 &&
|
|
|
|
((chap->NTRespSent && IsAccepted(p->link.lcp.cfg.chap80lm)) ||
|
|
|
|
!IsAccepted(p->link.lcp.cfg.chap80nt));
|
2000-10-30 00:15:04 +00:00
|
|
|
|
|
|
|
/* Generate local challenge value */
|
|
|
|
chap_ChallengeInit(&chap->auth);
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
1999-02-06 02:54:47 +00:00
|
|
|
break;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case CHAP_RESPONSE:
|
1999-02-06 02:54:47 +00:00
|
|
|
auth_StopTimer(&chap->auth);
|
|
|
|
bp = mbuf_Read(bp, &alen, 1);
|
|
|
|
len -= alen + 1;
|
|
|
|
if (len < 0) {
|
|
|
|
log_Printf(LogERROR, "Chap Input: Truncated response !\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
2002-06-17 01:12:38 +00:00
|
|
|
if ((ans = malloc(alen + 1)) == NULL) {
|
1999-02-06 02:54:47 +00:00
|
|
|
log_Printf(LogERROR, "Chap Input: Out of memory !\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
*ans = chap->auth.id;
|
|
|
|
bp = mbuf_Read(bp, ans + 1, alen);
|
|
|
|
bp = auth_ReadName(&chap->auth, bp, len);
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2002-06-15 08:03:30 +00:00
|
|
|
lanman = p->link.lcp.want_authtype == 0x80 &&
|
2000-10-30 00:15:04 +00:00
|
|
|
alen == 49 && ans[alen] == 0;
|
1999-02-18 19:45:06 +00:00
|
|
|
#endif
|
1999-02-06 02:54:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHAP_SUCCESS:
|
|
|
|
case CHAP_FAILURE:
|
|
|
|
/* chap->auth.in.name is already set up at CHALLENGE time */
|
|
|
|
if ((ans = malloc(len + 1)) == NULL) {
|
|
|
|
log_Printf(LogERROR, "Chap Input: Out of memory !\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
bp = mbuf_Read(bp, ans, len);
|
|
|
|
ans[len] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (chap->auth.in.hdr.code) {
|
1995-02-26 12:18:08 +00:00
|
|
|
case CHAP_CHALLENGE:
|
1999-02-06 02:54:47 +00:00
|
|
|
case CHAP_RESPONSE:
|
|
|
|
if (*chap->auth.in.name)
|
1999-02-18 00:52:15 +00:00
|
|
|
log_Printf(LogPHASE, "Chap Input: %s (%d bytes from %s%s)\n",
|
|
|
|
chapcodes[chap->auth.in.hdr.code], alen,
|
|
|
|
chap->auth.in.name,
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
|
1999-02-18 19:45:06 +00:00
|
|
|
" - lanman" :
|
|
|
|
#endif
|
|
|
|
"");
|
1999-02-06 02:54:47 +00:00
|
|
|
else
|
1999-02-18 00:52:15 +00:00
|
|
|
log_Printf(LogPHASE, "Chap Input: %s (%d bytes%s)\n",
|
|
|
|
chapcodes[chap->auth.in.hdr.code], alen,
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 00:52:15 +00:00
|
|
|
lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
|
1999-02-18 19:45:06 +00:00
|
|
|
" - lanman" :
|
|
|
|
#endif
|
|
|
|
"");
|
1999-02-06 02:54:47 +00:00
|
|
|
break;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case CHAP_SUCCESS:
|
|
|
|
case CHAP_FAILURE:
|
1999-02-06 02:54:47 +00:00
|
|
|
if (*ans)
|
|
|
|
log_Printf(LogPHASE, "Chap Input: %s (%s)\n",
|
|
|
|
chapcodes[chap->auth.in.hdr.code], ans);
|
|
|
|
else
|
|
|
|
log_Printf(LogPHASE, "Chap Input: %s\n",
|
|
|
|
chapcodes[chap->auth.in.hdr.code]);
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1999-02-06 02:54:47 +00:00
|
|
|
|
|
|
|
switch (chap->auth.in.hdr.code) {
|
|
|
|
case CHAP_CHALLENGE:
|
2000-08-09 19:29:50 +00:00
|
|
|
if (*bundle->cfg.auth.key == '!' && bundle->cfg.auth.key[1] != '!')
|
1999-05-08 11:07:56 +00:00
|
|
|
chap_StartChild(chap, bundle->cfg.auth.key + 1,
|
|
|
|
bundle->cfg.auth.name);
|
1999-02-11 10:14:08 +00:00
|
|
|
else
|
2000-08-09 19:29:50 +00:00
|
|
|
chap_Respond(chap, bundle->cfg.auth.name, bundle->cfg.auth.key +
|
|
|
|
(*bundle->cfg.auth.key == '!' ? 1 : 0),
|
|
|
|
p->link.lcp.his_authtype
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 19:45:06 +00:00
|
|
|
, lanman
|
|
|
|
#endif
|
|
|
|
);
|
1999-02-06 02:54:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHAP_RESPONSE:
|
|
|
|
name = chap->auth.in.name;
|
|
|
|
nlen = strlen(name);
|
2002-05-16 13:34:20 +00:00
|
|
|
#ifndef NODES
|
|
|
|
if (p->link.lcp.want_authtype == 0x81) {
|
2002-06-17 01:12:38 +00:00
|
|
|
struct MSCHAPv2_resp *resp = (struct MSCHAPv2_resp *)(ans + 1);
|
|
|
|
|
|
|
|
chap->challenge.peer[0] = sizeof resp->PeerChallenge;
|
|
|
|
memcpy(chap->challenge.peer + 1, resp->PeerChallenge,
|
|
|
|
sizeof resp->PeerChallenge);
|
2002-05-16 13:34:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
#ifndef NORADIUS
|
2002-05-16 13:34:20 +00:00
|
|
|
if (*bundle->radius.cfg.file) {
|
|
|
|
if (!radius_Authenticate(&bundle->radius, &chap->auth,
|
|
|
|
chap->auth.in.name, ans, alen + 1,
|
|
|
|
chap->challenge.local + 1,
|
2002-06-17 01:12:38 +00:00
|
|
|
*chap->challenge.local))
|
2002-05-16 13:34:20 +00:00
|
|
|
chap_Failure(&chap->auth);
|
|
|
|
} else
|
1999-02-06 02:54:47 +00:00
|
|
|
#endif
|
|
|
|
{
|
2002-06-17 01:12:38 +00:00
|
|
|
if (p->link.lcp.want_authtype == 0x81 && ans[alen] != '\0' &&
|
|
|
|
alen == sizeof(struct MSCHAPv2_resp)) {
|
|
|
|
struct MSCHAPv2_resp *resp = (struct MSCHAPv2_resp *)(ans + 1);
|
|
|
|
|
|
|
|
log_Printf(LogWARN, "%s: Compensating for corrupt (Win98/WinME?) "
|
|
|
|
"CHAP81 RESPONSE\n", l->name);
|
|
|
|
resp->Flags = '\0'; /* rfc2759 says it *MUST* be zero */
|
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
key = auth_GetSecret(bundle, name, nlen, p);
|
1999-02-06 02:54:47 +00:00
|
|
|
if (key) {
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2000-10-30 00:15:04 +00:00
|
|
|
if (p->link.lcp.want_authtype == 0x80 &&
|
|
|
|
lanman && !IsEnabled(p->link.lcp.cfg.chap80lm)) {
|
1999-02-18 00:52:15 +00:00
|
|
|
log_Printf(LogPHASE, "Auth failure: LANMan not enabled\n");
|
|
|
|
if (chap_HaveAnotherGo(chap))
|
|
|
|
break;
|
|
|
|
key = NULL;
|
2000-10-30 00:15:04 +00:00
|
|
|
} else if (p->link.lcp.want_authtype == 0x80 &&
|
|
|
|
!lanman && !IsEnabled(p->link.lcp.cfg.chap80nt)) {
|
1999-02-18 00:52:15 +00:00
|
|
|
log_Printf(LogPHASE, "Auth failure: mschap not enabled\n");
|
|
|
|
if (chap_HaveAnotherGo(chap))
|
|
|
|
break;
|
1999-02-06 02:54:47 +00:00
|
|
|
key = NULL;
|
2000-10-30 00:15:04 +00:00
|
|
|
} else if (p->link.lcp.want_authtype == 0x81 &&
|
|
|
|
!IsEnabled(p->link.lcp.cfg.chap81)) {
|
|
|
|
log_Printf(LogPHASE, "Auth failure: CHAP81 not enabled\n");
|
|
|
|
key = NULL;
|
1999-02-18 19:45:06 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2002-06-17 01:12:38 +00:00
|
|
|
char *myans = chap_BuildAnswer(name, key, chap->auth.id,
|
|
|
|
chap->challenge.local,
|
1999-02-18 19:45:06 +00:00
|
|
|
p->link.lcp.want_authtype
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2000-10-30 00:15:04 +00:00
|
|
|
, chap->challenge.peer,
|
2000-11-07 23:19:11 +00:00
|
|
|
chap->authresponse, lanman);
|
|
|
|
MPPE_IsServer = 1; /* XXX Global ! */
|
|
|
|
#else
|
1999-02-18 19:45:06 +00:00
|
|
|
);
|
2000-11-07 23:19:11 +00:00
|
|
|
#endif
|
1999-02-18 00:52:15 +00:00
|
|
|
if (myans == NULL)
|
1999-02-06 02:54:47 +00:00
|
|
|
key = NULL;
|
1999-02-18 00:52:15 +00:00
|
|
|
else {
|
1999-02-18 19:45:06 +00:00
|
|
|
if (!chap_Cmp(p->link.lcp.want_authtype, myans + 1, *myans,
|
|
|
|
ans + 1, alen
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
1999-02-18 19:45:06 +00:00
|
|
|
, lanman
|
|
|
|
#endif
|
|
|
|
))
|
1999-02-18 00:52:15 +00:00
|
|
|
key = NULL;
|
|
|
|
free(myans);
|
|
|
|
}
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key)
|
|
|
|
chap_Success(&chap->auth);
|
|
|
|
else
|
|
|
|
chap_Failure(&chap->auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHAP_SUCCESS:
|
|
|
|
if (p->link.lcp.auth_iwait == PROTO_CHAP) {
|
|
|
|
p->link.lcp.auth_iwait = 0;
|
2000-10-30 00:15:04 +00:00
|
|
|
if (p->link.lcp.auth_ineed == 0) {
|
2002-03-30 12:30:09 +00:00
|
|
|
#ifndef NODES
|
2000-10-30 00:15:04 +00:00
|
|
|
if (p->link.lcp.his_authtype == 0x81) {
|
2002-07-30 08:09:26 +00:00
|
|
|
if (strncasecmp(ans, chap->authresponse, 42)) {
|
2000-10-30 00:15:04 +00:00
|
|
|
datalink_AuthNotOk(p->dl);
|
2001-08-03 09:28:21 +00:00
|
|
|
log_Printf(LogWARN, "CHAP81: AuthenticatorResponse: (%.42s)"
|
|
|
|
" != ans: (%.42s)\n", chap->authresponse, ans);
|
2002-06-15 08:03:30 +00:00
|
|
|
|
2000-10-30 00:15:04 +00:00
|
|
|
} else {
|
|
|
|
/* Successful login */
|
2000-11-07 23:19:11 +00:00
|
|
|
MPPE_MasterKeyValid = 1; /* XXX Global ! */
|
2000-10-30 00:15:04 +00:00
|
|
|
datalink_AuthOk(p->dl);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
1999-02-06 02:54:47 +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.
|
|
|
|
*/
|
|
|
|
datalink_AuthOk(p->dl);
|
2000-10-30 00:15:04 +00:00
|
|
|
}
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHAP_FAILURE:
|
|
|
|
datalink_AuthNotOk(p->dl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(ans);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1999-02-06 02:54:47 +00:00
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|