1999-01-28 01:56:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1999 Internet Business Solutions Ltd., Switzerland
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1999-01-28 01:56:34 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-19 21:00:42 +00:00
|
|
|
#include <stdint.h>
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <sys/param.h>
|
2002-06-12 00:33:17 +00:00
|
|
|
|
2000-03-14 01:46:44 +00:00
|
|
|
#include <sys/socket.h>
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/un.h>
|
2000-03-14 01:46:44 +00:00
|
|
|
#include <net/route.h>
|
1999-01-28 01:56:34 +00:00
|
|
|
|
2000-03-14 01:47:02 +00:00
|
|
|
#ifdef LOCALRAD
|
|
|
|
#include "radlib.h"
|
2002-05-10 03:11:35 +00:00
|
|
|
#include "radlib_vs.h"
|
2000-03-14 01:47:02 +00:00
|
|
|
#else
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <radlib.h>
|
2002-05-10 03:11:35 +00:00
|
|
|
#include <radlib_vs.h>
|
2000-03-14 01:47:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
2002-06-12 00:33:17 +00:00
|
|
|
#ifndef NODES
|
|
|
|
#include <md5.h>
|
|
|
|
#endif
|
2002-08-27 20:11:58 +00:00
|
|
|
#include <stdarg.h>
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-02-06 02:54:47 +00:00
|
|
|
#include <sys/time.h>
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <termios.h>
|
1999-09-03 10:31:34 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <netdb.h>
|
1999-01-28 01:56:34 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "layer.h"
|
1999-01-28 01:56:34 +00:00
|
|
|
#include "defs.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "descriptor.h"
|
|
|
|
#include "prompt.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "iplist.h"
|
|
|
|
#include "slcompress.h"
|
|
|
|
#include "throughput.h"
|
|
|
|
#include "lqr.h"
|
|
|
|
#include "hdlc.h"
|
|
|
|
#include "mbuf.h"
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ncpaddr.h"
|
|
|
|
#include "ip.h"
|
1999-01-28 01:56:34 +00:00
|
|
|
#include "ipcp.h"
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ipv6cp.h"
|
1999-01-28 01:56:34 +00:00
|
|
|
#include "route.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "ccp.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "mp.h"
|
|
|
|
#include "radius.h"
|
1999-02-06 02:54:47 +00:00
|
|
|
#include "auth.h"
|
|
|
|
#include "async.h"
|
|
|
|
#include "physical.h"
|
|
|
|
#include "chat.h"
|
|
|
|
#include "cbcp.h"
|
|
|
|
#include "chap.h"
|
|
|
|
#include "datalink.h"
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ncp.h"
|
1999-01-28 01:56:34 +00:00
|
|
|
#include "bundle.h"
|
2002-05-10 03:11:35 +00:00
|
|
|
#include "proto.h"
|
|
|
|
|
|
|
|
#ifndef NODES
|
2002-05-16 13:34:20 +00:00
|
|
|
struct mschap_response {
|
2002-05-10 03:11:35 +00:00
|
|
|
u_char ident;
|
|
|
|
u_char flags;
|
|
|
|
u_char lm_response[24];
|
|
|
|
u_char nt_response[24];
|
|
|
|
};
|
2002-05-16 13:34:20 +00:00
|
|
|
|
|
|
|
struct mschap2_response {
|
|
|
|
u_char ident;
|
|
|
|
u_char flags;
|
|
|
|
u_char pchallenge[16];
|
|
|
|
u_char reserved[8];
|
|
|
|
u_char response[24];
|
|
|
|
};
|
2002-06-12 00:33:17 +00:00
|
|
|
|
|
|
|
#define AUTH_LEN 16
|
|
|
|
#define SALT_LEN 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
radius_policyname(int policy)
|
|
|
|
{
|
|
|
|
switch(policy) {
|
|
|
|
case MPPE_POLICY_ALLOWED:
|
|
|
|
return "Allowed";
|
|
|
|
case MPPE_POLICY_REQUIRED:
|
|
|
|
return "Required";
|
|
|
|
}
|
|
|
|
return NumStr(policy, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
radius_typesname(int types)
|
|
|
|
{
|
|
|
|
switch(types) {
|
|
|
|
case MPPE_TYPE_40BIT:
|
|
|
|
return "40 bit";
|
|
|
|
case MPPE_TYPE_128BIT:
|
|
|
|
return "128 bit";
|
|
|
|
case MPPE_TYPE_40BIT|MPPE_TYPE_128BIT:
|
|
|
|
return "40 or 128 bit";
|
|
|
|
}
|
|
|
|
return NumStr(types, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NODES
|
|
|
|
static void
|
|
|
|
demangle(struct radius *r, const void *mangled, size_t mlen,
|
|
|
|
char **buf, size_t *len)
|
|
|
|
{
|
|
|
|
char R[AUTH_LEN]; /* variable names as per rfc2548 */
|
|
|
|
const char *S;
|
|
|
|
u_char b[16];
|
|
|
|
const u_char *A, *C;
|
|
|
|
MD5_CTX Context;
|
|
|
|
int Slen, i, Clen, Ppos;
|
|
|
|
u_char *P;
|
|
|
|
|
|
|
|
if (mlen % 16 != SALT_LEN) {
|
|
|
|
log_Printf(LogWARN, "Cannot interpret mangled data of length %ld\n",
|
|
|
|
(u_long)mlen);
|
|
|
|
*buf = NULL;
|
|
|
|
*len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need the RADIUS Request-Authenticator */
|
|
|
|
if (rad_request_authenticator(r->cx.rad, R, sizeof R) != AUTH_LEN) {
|
|
|
|
log_Printf(LogWARN, "Cannot obtain the RADIUS request authenticator\n");
|
|
|
|
*buf = NULL;
|
|
|
|
*len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
A = (const u_char *)mangled; /* Salt comes first */
|
|
|
|
C = (const u_char *)mangled + SALT_LEN; /* Then the ciphertext */
|
|
|
|
Clen = mlen - SALT_LEN;
|
|
|
|
S = rad_server_secret(r->cx.rad); /* We need the RADIUS secret */
|
|
|
|
Slen = strlen(S);
|
|
|
|
P = alloca(Clen); /* We derive our plaintext */
|
|
|
|
|
|
|
|
MD5Init(&Context);
|
|
|
|
MD5Update(&Context, S, Slen);
|
|
|
|
MD5Update(&Context, R, AUTH_LEN);
|
|
|
|
MD5Update(&Context, A, SALT_LEN);
|
|
|
|
MD5Final(b, &Context);
|
|
|
|
Ppos = 0;
|
|
|
|
|
|
|
|
while (Clen) {
|
|
|
|
Clen -= 16;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
P[Ppos++] = C[i] ^ b[i];
|
|
|
|
|
|
|
|
if (Clen) {
|
|
|
|
MD5Init(&Context);
|
|
|
|
MD5Update(&Context, S, Slen);
|
|
|
|
MD5Update(&Context, C, 16);
|
|
|
|
MD5Final(b, &Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
C += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The resulting plain text consists of a one-byte length, the text and
|
|
|
|
* maybe some padding.
|
|
|
|
*/
|
|
|
|
*len = *P;
|
|
|
|
if (*len > mlen - 1) {
|
|
|
|
log_Printf(LogWARN, "Mangled data seems to be garbage\n");
|
|
|
|
*buf = NULL;
|
|
|
|
*len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-11 09:45:58 +00:00
|
|
|
if ((*buf = malloc(*len)) == NULL) {
|
|
|
|
log_Printf(LogWARN, "demangle: Out of memory (%lu bytes)\n", (u_long)*len);
|
|
|
|
*len = 0;
|
|
|
|
} else
|
|
|
|
memcpy(*buf, P + 1, *len);
|
2002-06-12 00:33:17 +00:00
|
|
|
}
|
2002-05-10 03:11:35 +00:00
|
|
|
#endif
|
1999-01-28 01:56:34 +00:00
|
|
|
|
2003-06-20 16:15:59 +00:00
|
|
|
/* XXX: This should go into librarius. */
|
|
|
|
#ifndef NOINET6
|
|
|
|
static uint8_t *
|
|
|
|
rad_cvt_ipv6prefix(const void *data, size_t len)
|
|
|
|
{
|
|
|
|
const size_t ipv6len = sizeof(struct in6_addr) + 2;
|
|
|
|
uint8_t *s;
|
|
|
|
|
|
|
|
if (len > ipv6len)
|
|
|
|
return NULL;
|
|
|
|
s = malloc(ipv6len);
|
|
|
|
if (s != NULL) {
|
|
|
|
memset(s, 0, ipv6len);
|
|
|
|
memcpy(s, data, len);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
/*
|
|
|
|
* rad_continue_send_request() has given us `got' (non-zero). Deal with it.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
radius_Process(struct radius *r, int got)
|
1999-01-28 01:56:34 +00:00
|
|
|
{
|
|
|
|
char *argv[MAXARGS], *nuke;
|
1999-02-06 02:54:47 +00:00
|
|
|
struct bundle *bundle;
|
2002-05-10 03:11:35 +00:00
|
|
|
int argc, addrs, res, width;
|
1999-04-21 08:13:25 +00:00
|
|
|
size_t len;
|
2001-08-14 16:05:52 +00:00
|
|
|
struct ncprange dest;
|
|
|
|
struct ncpaddr gw;
|
1999-02-06 02:54:47 +00:00
|
|
|
const void *data;
|
2001-02-04 01:08:26 +00:00
|
|
|
const char *stype;
|
2002-05-10 03:11:35 +00:00
|
|
|
u_int32_t ipaddr, vendor;
|
2001-08-14 16:05:52 +00:00
|
|
|
struct in_addr ip;
|
2003-06-19 18:19:31 +00:00
|
|
|
#ifndef NOINET6
|
2003-06-20 16:15:59 +00:00
|
|
|
uint8_t ipv6addr[INET6_ADDRSTRLEN];
|
2003-06-19 18:19:31 +00:00
|
|
|
struct in6_addr ip6;
|
|
|
|
#endif
|
1999-01-28 01:56:34 +00:00
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
r->cx.fd = -1; /* Stop select()ing */
|
2001-02-04 01:08:26 +00:00
|
|
|
stype = r->cx.auth ? "auth" : "acct";
|
1999-01-28 01:56:34 +00:00
|
|
|
|
|
|
|
switch (got) {
|
|
|
|
case RAD_ACCESS_ACCEPT:
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
"Radius(%s): ACCEPT received\n", stype);
|
2001-02-04 01:08:26 +00:00
|
|
|
if (!r->cx.auth) {
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
1999-01-28 01:56:34 +00:00
|
|
|
break;
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
case RAD_ACCESS_REJECT:
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
"Radius(%s): REJECT received\n", stype);
|
2002-05-10 03:11:35 +00:00
|
|
|
if (!r->cx.auth) {
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
1999-02-06 02:54:47 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
case RAD_ACCESS_CHALLENGE:
|
|
|
|
/* we can't deal with this (for now) ! */
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
"Radius: CHALLENGE received (can't handle yet)\n");
|
2001-02-04 01:08:26 +00:00
|
|
|
if (r->cx.auth)
|
|
|
|
auth_Failure(r->cx.auth);
|
1999-02-06 02:54:47 +00:00
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
1999-01-28 01:56:34 +00:00
|
|
|
|
2000-08-28 22:44:54 +00:00
|
|
|
case RAD_ACCOUNTING_RESPONSE:
|
2004-07-17 01:07:53 +00:00
|
|
|
/*
|
|
|
|
* It's probably not ideal to log this at PHASE level as we'll see
|
|
|
|
* too much stuff going to the log when ``set rad_alive'' is used.
|
|
|
|
* So we differ from older behaviour (ppp version 3.1 and before)
|
|
|
|
* and just log accounting responses to LogRADIUS.
|
|
|
|
*/
|
|
|
|
log_Printf(LogRADIUS, "Radius(%s): Accounting response received\n",
|
|
|
|
stype);
|
2001-02-04 01:08:26 +00:00
|
|
|
if (r->cx.auth)
|
|
|
|
auth_Failure(r->cx.auth); /* unexpected !!! */
|
|
|
|
|
2000-08-28 22:44:54 +00:00
|
|
|
/* No further processing for accounting requests, please */
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
case -1:
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
"radius(%s): %s\n", stype, rad_strerror(r->cx.rad));
|
2001-02-04 01:08:26 +00:00
|
|
|
if (r->cx.auth)
|
|
|
|
auth_Failure(r->cx.auth);
|
1999-02-06 02:54:47 +00:00
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
1999-01-28 01:56:34 +00:00
|
|
|
|
|
|
|
default:
|
2001-02-04 01:08:26 +00:00
|
|
|
log_Printf(LogERROR, "rad_send_request(%s): Failed %d: %s\n", stype,
|
1999-02-06 02:54:47 +00:00
|
|
|
got, rad_strerror(r->cx.rad));
|
2001-02-04 01:08:26 +00:00
|
|
|
if (r->cx.auth)
|
|
|
|
auth_Failure(r->cx.auth);
|
1999-02-06 02:54:47 +00:00
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
1999-01-28 01:56:34 +00:00
|
|
|
}
|
|
|
|
|
2002-05-10 03:11:35 +00:00
|
|
|
/* Let's see what we've got in our reply */
|
1999-01-28 01:56:34 +00:00
|
|
|
r->ip.s_addr = r->mask.s_addr = INADDR_NONE;
|
|
|
|
r->mtu = 0;
|
|
|
|
r->vj = 0;
|
2002-05-10 03:11:35 +00:00
|
|
|
while ((res = rad_get_attr(r->cx.rad, &data, &len)) > 0) {
|
|
|
|
switch (res) {
|
1999-01-28 01:56:34 +00:00
|
|
|
case RAD_FRAMED_IP_ADDRESS:
|
|
|
|
r->ip = rad_cvt_addr(data);
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" IP %s\n", inet_ntoa(r->ip));
|
1999-01-28 01:56:34 +00:00
|
|
|
break;
|
|
|
|
|
2002-05-07 10:06:54 +00:00
|
|
|
case RAD_FILTER_ID:
|
|
|
|
free(r->filterid);
|
|
|
|
if ((r->filterid = rad_cvt_string(data, len)) == NULL) {
|
|
|
|
log_Printf(LogERROR, "rad_cvt_string: %s\n", rad_strerror(r->cx.rad));
|
2002-05-10 03:11:35 +00:00
|
|
|
auth_Failure(r->cx.auth);
|
2002-05-07 10:06:54 +00:00
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" Filter \"%s\"\n", r->filterid);
|
2002-05-07 10:06:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RAD_SESSION_TIMEOUT:
|
|
|
|
r->sessiontime = rad_cvt_int(data);
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" Session-Timeout %lu\n", r->sessiontime);
|
2002-05-07 10:06:54 +00:00
|
|
|
break;
|
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
case RAD_FRAMED_IP_NETMASK:
|
|
|
|
r->mask = rad_cvt_addr(data);
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" Netmask %s\n", inet_ntoa(r->mask));
|
1999-01-28 01:56:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RAD_FRAMED_MTU:
|
|
|
|
r->mtu = rad_cvt_int(data);
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" MTU %lu\n", r->mtu);
|
1999-01-28 01:56:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RAD_FRAMED_ROUTING:
|
|
|
|
/* Disabled for now - should we automatically set up some filters ? */
|
|
|
|
/* rad_cvt_int(data); */
|
|
|
|
/* bit 1 = Send routing packets */
|
|
|
|
/* bit 2 = Receive routing packets */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RAD_FRAMED_COMPRESSION:
|
|
|
|
r->vj = rad_cvt_int(data) == 1 ? 1 : 0;
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" VJ %sabled\n", r->vj ? "en" : "dis");
|
1999-01-28 01:56:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RAD_FRAMED_ROUTE:
|
|
|
|
/*
|
|
|
|
* We expect a string of the format ``dest[/bits] gw [metrics]''
|
|
|
|
* Any specified metrics are ignored. MYADDR and HISADDR are
|
|
|
|
* understood for ``dest'' and ``gw'' and ``0.0.0.0'' is the same
|
|
|
|
* as ``HISADDR''.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((nuke = rad_cvt_string(data, len)) == NULL) {
|
1999-02-06 02:54:47 +00:00
|
|
|
log_Printf(LogERROR, "rad_cvt_string: %s\n", rad_strerror(r->cx.rad));
|
2002-05-10 03:11:35 +00:00
|
|
|
auth_Failure(r->cx.auth);
|
1999-02-06 02:54:47 +00:00
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
1999-01-28 01:56:34 +00:00
|
|
|
}
|
|
|
|
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" Route: %s\n", nuke);
|
1999-02-06 02:54:47 +00:00
|
|
|
bundle = r->cx.auth->physical->dl->bundle;
|
2001-08-14 16:05:52 +00:00
|
|
|
ip.s_addr = INADDR_ANY;
|
2003-06-19 18:19:31 +00:00
|
|
|
ncpaddr_setip4(&gw, ip);
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_setip4host(&dest, ip);
|
1999-01-28 01:56:34 +00:00
|
|
|
argc = command_Interpret(nuke, strlen(nuke), argv);
|
1999-12-20 20:30:02 +00:00
|
|
|
if (argc < 0)
|
|
|
|
log_Printf(LogWARN, "radius: %s: Syntax error\n",
|
|
|
|
argc == 1 ? argv[0] : "\"\"");
|
|
|
|
else if (argc < 2)
|
1999-01-28 01:56:34 +00:00
|
|
|
log_Printf(LogWARN, "radius: %s: Invalid route\n",
|
|
|
|
argc == 1 ? argv[0] : "\"\"");
|
|
|
|
else if ((strcasecmp(argv[0], "default") != 0 &&
|
2001-08-14 16:05:52 +00:00
|
|
|
!ncprange_aton(&dest, &bundle->ncp, argv[0])) ||
|
|
|
|
!ncpaddr_aton(&gw, &bundle->ncp, argv[1]))
|
1999-01-28 01:56:34 +00:00
|
|
|
log_Printf(LogWARN, "radius: %s %s: Invalid route\n",
|
|
|
|
argv[0], argv[1]);
|
|
|
|
else {
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_getwidth(&dest, &width);
|
|
|
|
if (width == 32 && strchr(argv[0], '/') == NULL) {
|
1999-01-28 01:56:34 +00:00
|
|
|
/* No mask specified - use the natural mask */
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_getip4addr(&dest, &ip);
|
|
|
|
ncprange_setip4mask(&dest, addr2mask(ip));
|
|
|
|
}
|
1999-01-28 01:56:34 +00:00
|
|
|
addrs = 0;
|
|
|
|
|
|
|
|
if (!strncasecmp(argv[0], "HISADDR", 7))
|
|
|
|
addrs = ROUTE_DSTHISADDR;
|
|
|
|
else if (!strncasecmp(argv[0], "MYADDR", 6))
|
|
|
|
addrs = ROUTE_DSTMYADDR;
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (ncpaddr_getip4addr(&gw, &ipaddr) && ipaddr == INADDR_ANY) {
|
1999-01-28 01:56:34 +00:00
|
|
|
addrs |= ROUTE_GWHISADDR;
|
2001-08-14 16:05:52 +00:00
|
|
|
ncpaddr_setip4(&gw, bundle->ncp.ipcp.peer_ip);
|
1999-01-28 01:56:34 +00:00
|
|
|
} else if (strcasecmp(argv[1], "HISADDR") == 0)
|
|
|
|
addrs |= ROUTE_GWHISADDR;
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
route_Add(&r->routes, addrs, &dest, &gw);
|
1999-01-28 01:56:34 +00:00
|
|
|
}
|
|
|
|
free(nuke);
|
|
|
|
break;
|
2002-05-10 03:11:35 +00:00
|
|
|
|
|
|
|
case RAD_REPLY_MESSAGE:
|
|
|
|
free(r->repstr);
|
|
|
|
if ((r->repstr = rad_cvt_string(data, len)) == NULL) {
|
|
|
|
log_Printf(LogERROR, "rad_cvt_string: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
auth_Failure(r->cx.auth);
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" Reply-Message \"%s\"\n", r->repstr);
|
2002-05-10 03:11:35 +00:00
|
|
|
break;
|
|
|
|
|
2003-06-19 18:19:31 +00:00
|
|
|
#ifndef NOINET6
|
2003-06-20 16:15:59 +00:00
|
|
|
case RAD_FRAMED_IPV6_PREFIX:
|
|
|
|
free(r->ipv6prefix);
|
|
|
|
r->ipv6prefix = rad_cvt_ipv6prefix(data, len);
|
|
|
|
inet_ntop(AF_INET6, &r->ipv6prefix[2], ipv6addr, sizeof(ipv6addr));
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" IPv6 %s/%d\n", ipv6addr, r->ipv6prefix[1]);
|
2003-06-20 16:15:59 +00:00
|
|
|
break;
|
|
|
|
|
2003-06-19 18:19:31 +00:00
|
|
|
case RAD_FRAMED_IPV6_ROUTE:
|
|
|
|
/*
|
|
|
|
* We expect a string of the format ``dest[/bits] gw [metrics]''
|
|
|
|
* Any specified metrics are ignored. MYADDR6 and HISADDR6 are
|
|
|
|
* understood for ``dest'' and ``gw'' and ``::'' is the same
|
|
|
|
* as ``HISADDR6''.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((nuke = rad_cvt_string(data, len)) == NULL) {
|
|
|
|
log_Printf(LogERROR, "rad_cvt_string: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
auth_Failure(r->cx.auth);
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" IPv6 Route: %s\n", nuke);
|
2003-06-19 18:19:31 +00:00
|
|
|
bundle = r->cx.auth->physical->dl->bundle;
|
|
|
|
ncpaddr_setip6(&gw, &in6addr_any);
|
|
|
|
ncprange_set(&dest, &gw, 0);
|
|
|
|
argc = command_Interpret(nuke, strlen(nuke), argv);
|
|
|
|
if (argc < 0)
|
|
|
|
log_Printf(LogWARN, "radius: %s: Syntax error\n",
|
|
|
|
argc == 1 ? argv[0] : "\"\"");
|
|
|
|
else if (argc < 2)
|
|
|
|
log_Printf(LogWARN, "radius: %s: Invalid route\n",
|
|
|
|
argc == 1 ? argv[0] : "\"\"");
|
|
|
|
else if ((strcasecmp(argv[0], "default") != 0 &&
|
|
|
|
!ncprange_aton(&dest, &bundle->ncp, argv[0])) ||
|
|
|
|
!ncpaddr_aton(&gw, &bundle->ncp, argv[1]))
|
|
|
|
log_Printf(LogWARN, "radius: %s %s: Invalid route\n",
|
|
|
|
argv[0], argv[1]);
|
|
|
|
else {
|
|
|
|
addrs = 0;
|
|
|
|
|
|
|
|
if (!strncasecmp(argv[0], "HISADDR6", 8))
|
|
|
|
addrs = ROUTE_DSTHISADDR6;
|
|
|
|
else if (!strncasecmp(argv[0], "MYADDR6", 7))
|
|
|
|
addrs = ROUTE_DSTMYADDR6;
|
|
|
|
|
|
|
|
if (ncpaddr_getip6(&gw, &ip6) && IN6_IS_ADDR_UNSPECIFIED(&ip6)) {
|
|
|
|
addrs |= ROUTE_GWHISADDR6;
|
|
|
|
ncpaddr_copy(&gw, &bundle->ncp.ipv6cp.hisaddr);
|
|
|
|
} else if (strcasecmp(argv[1], "HISADDR6") == 0)
|
|
|
|
addrs |= ROUTE_GWHISADDR6;
|
|
|
|
|
|
|
|
route_Add(&r->ipv6routes, addrs, &dest, &gw);
|
|
|
|
}
|
|
|
|
free(nuke);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2002-05-10 03:11:35 +00:00
|
|
|
case RAD_VENDOR_SPECIFIC:
|
|
|
|
if ((res = rad_get_vendor_attr(&vendor, &data, &len)) <= 0) {
|
|
|
|
log_Printf(LogERROR, "rad_get_vendor_attr: %s (failing!)\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
auth_Failure(r->cx.auth);
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (vendor) {
|
|
|
|
case RAD_VENDOR_MICROSOFT:
|
|
|
|
switch (res) {
|
2002-06-12 00:33:17 +00:00
|
|
|
#ifndef NODES
|
2002-05-10 03:11:35 +00:00
|
|
|
case RAD_MICROSOFT_MS_CHAP_ERROR:
|
|
|
|
free(r->errstr);
|
2002-06-12 21:36:07 +00:00
|
|
|
if (len == 0)
|
|
|
|
r->errstr = NULL;
|
|
|
|
else {
|
2002-06-23 23:38:06 +00:00
|
|
|
if (len < 3 || ((const char *)data)[1] != '=') {
|
|
|
|
/*
|
|
|
|
* Only point at the String field if we don't think the
|
|
|
|
* peer has misformatted the response.
|
|
|
|
*/
|
2004-07-28 07:20:04 +00:00
|
|
|
data = (const char *)data + 1;
|
2002-06-23 23:38:06 +00:00
|
|
|
len--;
|
2002-06-28 09:18:15 +00:00
|
|
|
} else
|
|
|
|
log_Printf(LogWARN, "Warning: The MS-CHAP-Error "
|
|
|
|
"attribute is mis-formatted. Compensating\n");
|
2002-06-23 23:38:06 +00:00
|
|
|
if ((r->errstr = rad_cvt_string((const char *)data,
|
|
|
|
len)) == NULL) {
|
2002-06-12 21:36:07 +00:00
|
|
|
log_Printf(LogERROR, "rad_cvt_string: %s\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
auth_Failure(r->cx.auth);
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" MS-CHAP-Error \"%s\"\n", r->errstr);
|
2002-05-10 03:11:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-05-16 13:34:20 +00:00
|
|
|
|
|
|
|
case RAD_MICROSOFT_MS_CHAP2_SUCCESS:
|
|
|
|
free(r->msrepstr);
|
2002-06-12 21:36:07 +00:00
|
|
|
if (len == 0)
|
|
|
|
r->msrepstr = NULL;
|
|
|
|
else {
|
2002-06-23 23:38:06 +00:00
|
|
|
if (len < 3 || ((const char *)data)[1] != '=') {
|
|
|
|
/*
|
|
|
|
* Only point at the String field if we don't think the
|
|
|
|
* peer has misformatted the response.
|
|
|
|
*/
|
2004-07-28 07:20:04 +00:00
|
|
|
data = (const char *)data + 1;
|
2002-06-23 23:38:06 +00:00
|
|
|
len--;
|
2002-06-28 09:18:15 +00:00
|
|
|
} else
|
|
|
|
log_Printf(LogWARN, "Warning: The MS-CHAP2-Success "
|
|
|
|
"attribute is mis-formatted. Compensating\n");
|
2002-06-23 23:38:06 +00:00
|
|
|
if ((r->msrepstr = rad_cvt_string((const char *)data,
|
|
|
|
len)) == NULL) {
|
2002-06-12 21:36:07 +00:00
|
|
|
log_Printf(LogERROR, "rad_cvt_string: %s\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
auth_Failure(r->cx.auth);
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" MS-CHAP2-Success \"%s\"\n", r->msrepstr);
|
2002-05-16 13:34:20 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-06-15 08:03:30 +00:00
|
|
|
|
2002-06-12 00:33:17 +00:00
|
|
|
case RAD_MICROSOFT_MS_MPPE_ENCRYPTION_POLICY:
|
|
|
|
r->mppe.policy = rad_cvt_int(data);
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" MS-MPPE-Encryption-Policy %s\n",
|
2002-06-12 00:33:17 +00:00
|
|
|
radius_policyname(r->mppe.policy));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RAD_MICROSOFT_MS_MPPE_ENCRYPTION_TYPES:
|
|
|
|
r->mppe.types = rad_cvt_int(data);
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" MS-MPPE-Encryption-Types %s\n",
|
2002-06-12 00:33:17 +00:00
|
|
|
radius_typesname(r->mppe.types));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RAD_MICROSOFT_MS_MPPE_RECV_KEY:
|
|
|
|
free(r->mppe.recvkey);
|
|
|
|
demangle(r, data, len, &r->mppe.recvkey, &r->mppe.recvkeylen);
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" MS-MPPE-Recv-Key ********\n");
|
2002-06-12 00:33:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RAD_MICROSOFT_MS_MPPE_SEND_KEY:
|
|
|
|
demangle(r, data, len, &r->mppe.sendkey, &r->mppe.sendkeylen);
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
" MS-MPPE-Send-Key ********\n");
|
2002-06-12 00:33:17 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2002-05-10 03:11:35 +00:00
|
|
|
default:
|
|
|
|
log_Printf(LogDEBUG, "Dropping MICROSOFT vendor specific "
|
|
|
|
"RADIUS attribute %d\n", res);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_Printf(LogDEBUG, "Dropping vendor %lu RADIUS attribute %d\n",
|
|
|
|
(unsigned long)vendor, res);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log_Printf(LogDEBUG, "Dropping RADIUS attribute %d\n", res);
|
|
|
|
break;
|
1999-01-28 01:56:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-10 03:11:35 +00:00
|
|
|
if (res == -1) {
|
1999-02-06 02:54:47 +00:00
|
|
|
log_Printf(LogERROR, "rad_get_attr: %s (failing!)\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
auth_Failure(r->cx.auth);
|
2002-05-10 03:11:35 +00:00
|
|
|
} else if (got == RAD_ACCESS_REJECT)
|
|
|
|
auth_Failure(r->cx.auth);
|
|
|
|
else {
|
1999-02-06 02:54:47 +00:00
|
|
|
r->valid = 1;
|
|
|
|
auth_Success(r->cx.auth);
|
|
|
|
}
|
2002-05-10 03:11:35 +00:00
|
|
|
rad_close(r->cx.rad);
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-03-14 01:47:07 +00:00
|
|
|
* We've either timed out or select()ed on the read descriptor
|
1999-02-06 02:54:47 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
radius_Continue(struct radius *r, int sel)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
int got;
|
|
|
|
|
|
|
|
timer_Stop(&r->cx.timer);
|
|
|
|
if ((got = rad_continue_send_request(r->cx.rad, sel, &r->cx.fd, &tv)) == 0) {
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
"Radius: Request re-sent\n");
|
1999-02-06 02:54:47 +00:00
|
|
|
r->cx.timer.load = tv.tv_usec / TICKUNIT + tv.tv_sec * SECTICKS;
|
|
|
|
timer_Start(&r->cx.timer);
|
|
|
|
return;
|
1999-01-28 01:56:34 +00:00
|
|
|
}
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
radius_Process(r, got);
|
|
|
|
}
|
1999-01-28 01:56:34 +00:00
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
/*
|
|
|
|
* Time to call rad_continue_send_request() - timed out.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
radius_Timeout(void *v)
|
|
|
|
{
|
|
|
|
radius_Continue((struct radius *)v, 0);
|
1999-01-28 01:56:34 +00:00
|
|
|
}
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
/*
|
|
|
|
* Time to call rad_continue_send_request() - something to read.
|
|
|
|
*/
|
|
|
|
static void
|
2004-09-05 01:46:52 +00:00
|
|
|
radius_Read(struct fdescriptor *d, struct bundle *bundle __unused,
|
|
|
|
const fd_set *fdset __unused)
|
1999-02-06 02:54:47 +00:00
|
|
|
{
|
|
|
|
radius_Continue(descriptor2radius(d), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-03-14 01:47:07 +00:00
|
|
|
* Behave as a struct fdescriptor (descriptor.h)
|
1999-02-06 02:54:47 +00:00
|
|
|
*/
|
|
|
|
static int
|
2004-09-05 01:46:52 +00:00
|
|
|
radius_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w __unused,
|
|
|
|
fd_set *e __unused, int *n)
|
1999-02-06 02:54:47 +00:00
|
|
|
{
|
|
|
|
struct radius *rad = descriptor2radius(d);
|
|
|
|
|
|
|
|
if (r && rad->cx.fd != -1) {
|
|
|
|
FD_SET(rad->cx.fd, r);
|
|
|
|
if (*n < rad->cx.fd + 1)
|
|
|
|
*n = rad->cx.fd + 1;
|
|
|
|
log_Printf(LogTIMER, "Radius: fdset(r) %d\n", rad->cx.fd);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-03-14 01:47:07 +00:00
|
|
|
* Behave as a struct fdescriptor (descriptor.h)
|
1999-02-06 02:54:47 +00:00
|
|
|
*/
|
|
|
|
static int
|
2000-03-14 01:46:09 +00:00
|
|
|
radius_IsSet(struct fdescriptor *d, const fd_set *fdset)
|
1999-02-06 02:54:47 +00:00
|
|
|
{
|
|
|
|
struct radius *r = descriptor2radius(d);
|
|
|
|
|
|
|
|
return r && r->cx.fd != -1 && FD_ISSET(r->cx.fd, fdset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-03-14 01:47:07 +00:00
|
|
|
* Behave as a struct fdescriptor (descriptor.h)
|
1999-02-06 02:54:47 +00:00
|
|
|
*/
|
|
|
|
static int
|
2004-09-05 01:46:52 +00:00
|
|
|
radius_Write(struct fdescriptor *d __unused, struct bundle *bundle __unused,
|
|
|
|
const fd_set *fdset __unused)
|
1999-02-06 02:54:47 +00:00
|
|
|
{
|
|
|
|
/* We never want to write here ! */
|
|
|
|
log_Printf(LogALERT, "radius_Write: Internal error: Bad call !\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise ourselves
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
radius_Init(struct radius *r)
|
|
|
|
{
|
|
|
|
r->desc.type = RADIUS_DESCRIPTOR;
|
|
|
|
r->desc.UpdateSet = radius_UpdateSet;
|
|
|
|
r->desc.IsSet = radius_IsSet;
|
|
|
|
r->desc.Read = radius_Read;
|
|
|
|
r->desc.Write = radius_Write;
|
2002-05-10 03:11:35 +00:00
|
|
|
r->cx.fd = -1;
|
|
|
|
r->cx.rad = NULL;
|
1999-02-06 02:54:47 +00:00
|
|
|
memset(&r->cx.timer, '\0', sizeof r->cx.timer);
|
2002-05-10 03:11:35 +00:00
|
|
|
r->cx.auth = NULL;
|
|
|
|
r->valid = 0;
|
|
|
|
r->vj = 0;
|
|
|
|
r->ip.s_addr = INADDR_ANY;
|
|
|
|
r->mask.s_addr = INADDR_NONE;
|
|
|
|
r->routes = NULL;
|
|
|
|
r->mtu = DEF_MTU;
|
2002-05-16 13:34:20 +00:00
|
|
|
r->msrepstr = NULL;
|
2002-05-10 03:11:35 +00:00
|
|
|
r->repstr = NULL;
|
2003-06-19 18:19:31 +00:00
|
|
|
#ifndef NOINET6
|
2003-06-20 16:15:59 +00:00
|
|
|
r->ipv6prefix = NULL;
|
2003-06-19 18:19:31 +00:00
|
|
|
r->ipv6routes = NULL;
|
|
|
|
#endif
|
2002-05-10 03:11:35 +00:00
|
|
|
r->errstr = NULL;
|
2002-06-12 00:33:17 +00:00
|
|
|
r->mppe.policy = 0;
|
|
|
|
r->mppe.types = 0;
|
|
|
|
r->mppe.recvkey = NULL;
|
|
|
|
r->mppe.recvkeylen = 0;
|
|
|
|
r->mppe.sendkey = NULL;
|
|
|
|
r->mppe.sendkeylen = 0;
|
2002-05-10 03:11:35 +00:00
|
|
|
*r->cfg.file = '\0';;
|
2000-08-28 22:44:54 +00:00
|
|
|
log_Printf(LogDEBUG, "Radius: radius_Init\n");
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Forget everything and go back to initialised state.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
radius_Destroy(struct radius *r)
|
|
|
|
{
|
|
|
|
r->valid = 0;
|
2000-08-28 22:44:54 +00:00
|
|
|
log_Printf(LogDEBUG, "Radius: radius_Destroy\n");
|
1999-02-06 02:54:47 +00:00
|
|
|
timer_Stop(&r->cx.timer);
|
|
|
|
route_DeleteAll(&r->routes);
|
2003-06-19 18:19:31 +00:00
|
|
|
#ifndef NOINET6
|
|
|
|
route_DeleteAll(&r->ipv6routes);
|
|
|
|
#endif
|
2002-05-07 10:06:54 +00:00
|
|
|
free(r->filterid);
|
|
|
|
r->filterid = NULL;
|
2002-05-16 13:34:20 +00:00
|
|
|
free(r->msrepstr);
|
|
|
|
r->msrepstr = NULL;
|
2002-05-10 03:11:35 +00:00
|
|
|
free(r->repstr);
|
|
|
|
r->repstr = NULL;
|
2003-06-20 16:15:59 +00:00
|
|
|
#ifndef NOINET6
|
|
|
|
free(r->ipv6prefix);
|
|
|
|
r->ipv6prefix = NULL;
|
|
|
|
#endif
|
2002-05-10 03:11:35 +00:00
|
|
|
free(r->errstr);
|
|
|
|
r->errstr = NULL;
|
2002-06-12 00:33:17 +00:00
|
|
|
free(r->mppe.recvkey);
|
|
|
|
r->mppe.recvkey = NULL;
|
|
|
|
r->mppe.recvkeylen = 0;
|
|
|
|
free(r->mppe.sendkey);
|
|
|
|
r->mppe.sendkey = NULL;
|
|
|
|
r->mppe.sendkeylen = 0;
|
1999-02-06 02:54:47 +00:00
|
|
|
if (r->cx.fd != -1) {
|
|
|
|
r->cx.fd = -1;
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-14 12:55:39 +00:00
|
|
|
static int
|
|
|
|
radius_put_physical_details(struct rad_handle *rad, struct physical *p)
|
|
|
|
{
|
|
|
|
int slot, type;
|
|
|
|
|
|
|
|
type = RAD_VIRTUAL;
|
|
|
|
if (p->handler)
|
|
|
|
switch (p->handler->type) {
|
|
|
|
case I4B_DEVICE:
|
|
|
|
type = RAD_ISDN_SYNC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TTY_DEVICE:
|
|
|
|
type = RAD_ASYNC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ETHER_DEVICE:
|
|
|
|
type = RAD_ETHERNET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TCP_DEVICE:
|
|
|
|
case UDP_DEVICE:
|
|
|
|
case EXEC_DEVICE:
|
|
|
|
case ATM_DEVICE:
|
|
|
|
case NG_DEVICE:
|
|
|
|
type = RAD_VIRTUAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rad_put_int(rad, RAD_NAS_PORT_TYPE, type) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: rad_put_int: %s\n", rad_strerror(rad));
|
|
|
|
rad_close(rad);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((slot = physical_Slot(p)) >= 0)
|
|
|
|
if (rad_put_int(rad, RAD_NAS_PORT, slot) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: rad_put_int: %s\n", rad_strerror(rad));
|
|
|
|
rad_close(rad);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
/*
|
|
|
|
* Start an authentication request to the RADIUS server.
|
|
|
|
*/
|
2002-05-16 13:34:20 +00:00
|
|
|
int
|
1999-02-06 02:54:47 +00:00
|
|
|
radius_Authenticate(struct radius *r, struct authinfo *authp, const char *name,
|
2002-05-16 13:34:20 +00:00
|
|
|
const char *key, int klen, const char *nchallenge,
|
2002-06-17 01:12:38 +00:00
|
|
|
int nclen)
|
1999-02-06 02:54:47 +00:00
|
|
|
{
|
2004-09-05 01:46:52 +00:00
|
|
|
char hostname[MAXHOSTNAMELEN];
|
1999-02-06 02:54:47 +00:00
|
|
|
struct timeval tv;
|
2004-09-05 01:46:52 +00:00
|
|
|
const char *what = "questionable"; /* silence warnings! */
|
|
|
|
char *mac_addr;
|
2002-05-14 12:55:39 +00:00
|
|
|
int got;
|
2002-06-02 14:27:02 +00:00
|
|
|
#if 0
|
1999-09-03 10:31:34 +00:00
|
|
|
struct hostent *hp;
|
|
|
|
struct in_addr hostaddr;
|
2002-06-12 00:33:17 +00:00
|
|
|
#endif
|
2002-05-10 03:11:35 +00:00
|
|
|
#ifndef NODES
|
2002-05-16 13:34:20 +00:00
|
|
|
struct mschap_response msresp;
|
|
|
|
struct mschap2_response msresp2;
|
2002-06-17 01:12:38 +00:00
|
|
|
const struct MSCHAPv2_resp *keyv2;
|
2002-05-10 03:11:35 +00:00
|
|
|
#endif
|
1999-02-06 02:54:47 +00:00
|
|
|
|
|
|
|
if (!*r->cfg.file)
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
1999-02-06 02:54:47 +00:00
|
|
|
|
|
|
|
if (r->cx.fd != -1)
|
|
|
|
/*
|
|
|
|
* We assume that our name/key/challenge is the same as last time,
|
|
|
|
* and just continue to wait for the RADIUS server(s).
|
|
|
|
*/
|
2002-05-16 13:34:20 +00:00
|
|
|
return 1;
|
1999-02-06 02:54:47 +00:00
|
|
|
|
|
|
|
radius_Destroy(r);
|
|
|
|
|
2000-08-28 22:44:54 +00:00
|
|
|
if ((r->cx.rad = rad_auth_open()) == NULL) {
|
|
|
|
log_Printf(LogERROR, "rad_auth_open: %s\n", strerror(errno));
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rad_config(r->cx.rad, r->cfg.file) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_config: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rad_create_request(r->cx.rad, RAD_ACCESS_REQUEST) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_create_request: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
2002-07-04 23:33:35 +00:00
|
|
|
if (rad_put_string(r->cx.rad, RAD_USER_NAME, name) != 0 ||
|
1999-02-06 02:54:47 +00:00
|
|
|
rad_put_int(r->cx.rad, RAD_SERVICE_TYPE, RAD_FRAMED) != 0 ||
|
|
|
|
rad_put_int(r->cx.rad, RAD_FRAMED_PROTOCOL, RAD_PPP) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
2002-05-10 03:11:35 +00:00
|
|
|
switch (authp->physical->link.lcp.want_auth) {
|
|
|
|
case PROTO_PAP:
|
|
|
|
/* We're talking PAP */
|
|
|
|
if (rad_put_attr(r->cx.rad, RAD_USER_PASSWORD, key, klen) != 0) {
|
|
|
|
log_Printf(LogERROR, "PAP: rad_put_string: %s\n",
|
1999-02-06 02:54:47 +00:00
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
2004-07-17 01:07:53 +00:00
|
|
|
what = "PAP";
|
2002-05-10 03:11:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROTO_CHAP:
|
|
|
|
switch (authp->physical->link.lcp.want_authtype) {
|
|
|
|
case 0x5:
|
|
|
|
if (rad_put_attr(r->cx.rad, RAD_CHAP_PASSWORD, key, klen) != 0 ||
|
2002-05-16 13:34:20 +00:00
|
|
|
rad_put_attr(r->cx.rad, RAD_CHAP_CHALLENGE, nchallenge, nclen) != 0) {
|
2002-05-10 03:11:35 +00:00
|
|
|
log_Printf(LogERROR, "CHAP: rad_put_string: %s\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
2002-05-10 03:11:35 +00:00
|
|
|
}
|
2004-07-17 01:07:53 +00:00
|
|
|
what = "CHAP";
|
2002-05-10 03:11:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifndef NODES
|
|
|
|
case 0x80:
|
|
|
|
if (klen != 50) {
|
2002-05-16 13:34:20 +00:00
|
|
|
log_Printf(LogERROR, "CHAP80: Unrecognised key length %d\n", klen);
|
2002-05-10 03:11:35 +00:00
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
2002-05-10 03:11:35 +00:00
|
|
|
}
|
2002-05-16 13:34:20 +00:00
|
|
|
|
2002-05-10 03:11:35 +00:00
|
|
|
rad_put_vendor_attr(r->cx.rad, RAD_VENDOR_MICROSOFT,
|
2002-05-16 13:34:20 +00:00
|
|
|
RAD_MICROSOFT_MS_CHAP_CHALLENGE, nchallenge, nclen);
|
|
|
|
msresp.ident = *key;
|
|
|
|
msresp.flags = 0x01;
|
|
|
|
memcpy(msresp.lm_response, key + 1, 24);
|
|
|
|
memcpy(msresp.nt_response, key + 25, 24);
|
2002-05-10 03:11:35 +00:00
|
|
|
rad_put_vendor_attr(r->cx.rad, RAD_VENDOR_MICROSOFT,
|
2002-05-16 13:34:20 +00:00
|
|
|
RAD_MICROSOFT_MS_CHAP_RESPONSE, &msresp,
|
|
|
|
sizeof msresp);
|
2004-07-17 01:07:53 +00:00
|
|
|
what = "MSCHAP";
|
2002-05-10 03:11:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x81:
|
2002-06-17 01:12:38 +00:00
|
|
|
if (klen != sizeof(*keyv2) + 1) {
|
2002-05-16 13:34:20 +00:00
|
|
|
log_Printf(LogERROR, "CHAP81: Unrecognised key length %d\n", klen);
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-17 01:12:38 +00:00
|
|
|
keyv2 = (const struct MSCHAPv2_resp *)(key + 1);
|
2002-05-16 13:34:20 +00:00
|
|
|
rad_put_vendor_attr(r->cx.rad, RAD_VENDOR_MICROSOFT,
|
|
|
|
RAD_MICROSOFT_MS_CHAP_CHALLENGE, nchallenge, nclen);
|
|
|
|
msresp2.ident = *key;
|
2002-06-17 01:12:38 +00:00
|
|
|
msresp2.flags = keyv2->Flags;
|
|
|
|
memcpy(msresp2.response, keyv2->NTResponse, sizeof msresp2.response);
|
2002-05-16 13:34:20 +00:00
|
|
|
memset(msresp2.reserved, '\0', sizeof msresp2.reserved);
|
2002-06-17 01:12:38 +00:00
|
|
|
memcpy(msresp2.pchallenge, keyv2->PeerChallenge,
|
|
|
|
sizeof msresp2.pchallenge);
|
2002-05-16 13:34:20 +00:00
|
|
|
rad_put_vendor_attr(r->cx.rad, RAD_VENDOR_MICROSOFT,
|
|
|
|
RAD_MICROSOFT_MS_CHAP2_RESPONSE, &msresp2,
|
|
|
|
sizeof msresp2);
|
2004-07-17 01:07:53 +00:00
|
|
|
what = "MSCHAPv2";
|
2002-05-16 13:34:20 +00:00
|
|
|
break;
|
2002-05-10 03:11:35 +00:00
|
|
|
#endif
|
|
|
|
default:
|
2002-06-15 08:03:30 +00:00
|
|
|
log_Printf(LogERROR, "CHAP: Unrecognised type 0x%02x\n",
|
2002-05-10 03:11:35 +00:00
|
|
|
authp->physical->link.lcp.want_authtype);
|
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
2002-05-10 03:11:35 +00:00
|
|
|
}
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
1999-09-03 10:31:34 +00:00
|
|
|
if (gethostname(hostname, sizeof hostname) != 0)
|
|
|
|
log_Printf(LogERROR, "rad_put: gethostname(): %s\n", strerror(errno));
|
|
|
|
else {
|
2002-06-02 14:27:02 +00:00
|
|
|
#if 0
|
1999-09-03 10:31:34 +00:00
|
|
|
if ((hp = gethostbyname(hostname)) != NULL) {
|
|
|
|
hostaddr.s_addr = *(u_long *)hp->h_addr;
|
|
|
|
if (rad_put_addr(r->cx.rad, RAD_NAS_IP_ADDRESS, hostaddr) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: rad_put_string: %s\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
1999-09-03 10:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-02 14:27:02 +00:00
|
|
|
#endif
|
1999-09-03 10:31:34 +00:00
|
|
|
if (rad_put_string(r->cx.rad, RAD_NAS_IDENTIFIER, hostname) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: rad_put_string: %s\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
2002-05-16 13:34:20 +00:00
|
|
|
return 0;
|
1999-09-03 10:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-26 01:02:31 +00:00
|
|
|
if ((mac_addr = getenv("HISMACADDR")) != NULL &&
|
|
|
|
rad_put_string(r->cx.rad, RAD_CALLING_STATION_ID, mac_addr) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
2004-09-05 01:46:52 +00:00
|
|
|
return 0;
|
2004-06-26 01:02:31 +00:00
|
|
|
}
|
|
|
|
|
2002-05-14 12:55:39 +00:00
|
|
|
radius_put_physical_details(r->cx.rad, authp->physical);
|
1999-09-03 10:31:34 +00:00
|
|
|
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(LogRADIUS, "Radius(auth): %s data sent for %s\n", what, name);
|
|
|
|
|
2001-02-04 01:08:26 +00:00
|
|
|
r->cx.auth = authp;
|
1999-02-06 02:54:47 +00:00
|
|
|
if ((got = rad_init_send_request(r->cx.rad, &r->cx.fd, &tv)))
|
|
|
|
radius_Process(r, got);
|
|
|
|
else {
|
2004-07-17 01:07:53 +00:00
|
|
|
log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
|
|
|
|
"Radius: Request sent\n");
|
1999-02-06 02:54:47 +00:00
|
|
|
log_Printf(LogDEBUG, "Using radius_Timeout [%p]\n", radius_Timeout);
|
|
|
|
r->cx.timer.load = tv.tv_usec / TICKUNIT + tv.tv_sec * SECTICKS;
|
|
|
|
r->cx.timer.func = radius_Timeout;
|
2001-02-04 01:08:26 +00:00
|
|
|
r->cx.timer.name = "radius auth";
|
1999-02-06 02:54:47 +00:00
|
|
|
r->cx.timer.arg = r;
|
|
|
|
timer_Start(&r->cx.timer);
|
|
|
|
}
|
2002-05-16 13:34:20 +00:00
|
|
|
|
|
|
|
return 1;
|
1999-02-06 02:54:47 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 18:55:49 +00:00
|
|
|
/* Fetch IP, netmask from IPCP */
|
|
|
|
void
|
|
|
|
radius_Account_Set_Ip(struct radacct *ac, struct in_addr *peer_ip,
|
|
|
|
struct in_addr *netmask)
|
|
|
|
{
|
|
|
|
ac->proto = PROTO_IPCP;
|
2003-06-28 15:37:04 +00:00
|
|
|
memcpy(&ac->peer.ip.addr, peer_ip, sizeof(ac->peer.ip.addr));
|
|
|
|
memcpy(&ac->peer.ip.mask, netmask, sizeof(ac->peer.ip.mask));
|
2003-06-19 18:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NOINET6
|
|
|
|
/* Fetch interface-id from IPV6CP */
|
|
|
|
void
|
|
|
|
radius_Account_Set_Ipv6(struct radacct *ac, u_char *ifid)
|
|
|
|
{
|
|
|
|
ac->proto = PROTO_IPV6CP;
|
2003-06-28 15:37:04 +00:00
|
|
|
memcpy(&ac->peer.ipv6.ifid, ifid, sizeof(ac->peer.ipv6.ifid));
|
2003-06-19 18:55:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-08-28 22:44:54 +00:00
|
|
|
/*
|
|
|
|
* Send an accounting request to the RADIUS server
|
|
|
|
*/
|
|
|
|
void
|
2002-06-15 08:03:30 +00:00
|
|
|
radius_Account(struct radius *r, struct radacct *ac, struct datalink *dl,
|
2003-06-19 18:55:49 +00:00
|
|
|
int acct_type, struct pppThroughput *stats)
|
2000-08-28 22:44:54 +00:00
|
|
|
{
|
|
|
|
struct timeval tv;
|
2002-05-14 12:55:39 +00:00
|
|
|
int got;
|
2001-03-09 20:31:02 +00:00
|
|
|
char hostname[MAXHOSTNAMELEN];
|
2004-06-26 01:02:31 +00:00
|
|
|
char *mac_addr;
|
2002-06-02 14:27:02 +00:00
|
|
|
#if 0
|
2000-08-28 22:44:54 +00:00
|
|
|
struct hostent *hp;
|
|
|
|
struct in_addr hostaddr;
|
2002-06-12 00:33:17 +00:00
|
|
|
#endif
|
2000-08-28 22:44:54 +00:00
|
|
|
|
|
|
|
if (!*r->cfg.file)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (r->cx.fd != -1)
|
|
|
|
/*
|
|
|
|
* We assume that our name/key/challenge is the same as last time,
|
|
|
|
* and just continue to wait for the RADIUS server(s).
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
|
2002-06-12 00:33:17 +00:00
|
|
|
timer_Stop(&r->cx.timer);
|
2000-08-28 22:44:54 +00:00
|
|
|
|
2000-10-15 01:05:57 +00:00
|
|
|
if ((r->cx.rad = rad_acct_open()) == NULL) {
|
2000-08-28 22:44:54 +00:00
|
|
|
log_Printf(LogERROR, "rad_auth_open: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rad_config(r->cx.rad, r->cfg.file) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_config: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rad_create_request(r->cx.rad, RAD_ACCOUNTING_REQUEST) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_create_request: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Grab some accounting data and initialize structure */
|
|
|
|
if (acct_type == RAD_START) {
|
|
|
|
ac->rad_parent = r;
|
|
|
|
/* Fetch username from datalink */
|
2002-07-04 23:33:35 +00:00
|
|
|
strncpy(ac->user_name, dl->peer.authname, sizeof ac->user_name);
|
2000-08-28 22:44:54 +00:00
|
|
|
ac->user_name[AUTHLEN-1] = '\0';
|
|
|
|
|
|
|
|
ac->authentic = 2; /* Assume RADIUS verified auth data */
|
2002-06-15 08:03:30 +00:00
|
|
|
|
2000-08-28 22:44:54 +00:00
|
|
|
/* Generate a session ID */
|
2002-06-06 01:39:46 +00:00
|
|
|
snprintf(ac->session_id, sizeof ac->session_id, "%s%ld-%s%lu",
|
|
|
|
dl->bundle->cfg.auth.name, (long)getpid(),
|
2002-07-04 23:33:35 +00:00
|
|
|
dl->peer.authname, (unsigned long)stats->uptime);
|
2000-08-28 22:44:54 +00:00
|
|
|
|
|
|
|
/* And grab our MP socket name */
|
|
|
|
snprintf(ac->multi_session_id, sizeof ac->multi_session_id, "%s",
|
|
|
|
dl->bundle->ncp.mp.active ?
|
|
|
|
dl->bundle->ncp.mp.server.socket.sun_path : "");
|
|
|
|
};
|
|
|
|
|
|
|
|
if (rad_put_string(r->cx.rad, RAD_USER_NAME, ac->user_name) != 0 ||
|
|
|
|
rad_put_int(r->cx.rad, RAD_SERVICE_TYPE, RAD_FRAMED) != 0 ||
|
2003-06-19 18:55:49 +00:00
|
|
|
rad_put_int(r->cx.rad, RAD_FRAMED_PROTOCOL, RAD_PPP) != 0) {
|
2000-08-28 22:44:54 +00:00
|
|
|
log_Printf(LogERROR, "rad_put: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
2003-06-19 18:55:49 +00:00
|
|
|
switch (ac->proto) {
|
|
|
|
case PROTO_IPCP:
|
2003-06-28 15:37:04 +00:00
|
|
|
if (rad_put_addr(r->cx.rad, RAD_FRAMED_IP_ADDRESS,
|
2004-07-14 13:31:17 +00:00
|
|
|
ac->peer.ip.addr) != 0 ||
|
2003-06-28 15:37:04 +00:00
|
|
|
rad_put_addr(r->cx.rad, RAD_FRAMED_IP_NETMASK,
|
|
|
|
ac->peer.ip.mask) != 0) {
|
2003-06-19 18:55:49 +00:00
|
|
|
log_Printf(LogERROR, "rad_put: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifndef NOINET6
|
|
|
|
case PROTO_IPV6CP:
|
2003-06-28 15:37:04 +00:00
|
|
|
if (rad_put_attr(r->cx.rad, RAD_FRAMED_INTERFACE_ID, ac->peer.ipv6.ifid,
|
|
|
|
sizeof(ac->peer.ipv6.ifid)) != 0) {
|
2003-06-19 18:55:49 +00:00
|
|
|
log_Printf(LogERROR, "rad_put_attr: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
2003-06-20 16:15:59 +00:00
|
|
|
if (r->ipv6prefix) {
|
|
|
|
/*
|
|
|
|
* Since PPP doesn't delegate an IPv6 prefix to a peer,
|
|
|
|
* Framed-IPv6-Prefix may be not used, actually.
|
|
|
|
*/
|
|
|
|
if (rad_put_attr(r->cx.rad, RAD_FRAMED_IPV6_PREFIX, r->ipv6prefix,
|
|
|
|
sizeof(struct in6_addr) + 2) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put_attr: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2003-06-19 18:55:49 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* We don't log any protocol specific information */
|
|
|
|
break;
|
|
|
|
}
|
2000-08-28 22:44:54 +00:00
|
|
|
|
2004-06-26 01:02:31 +00:00
|
|
|
if ((mac_addr = getenv("HISMACADDR")) != NULL &&
|
|
|
|
rad_put_string(r->cx.rad, RAD_CALLING_STATION_ID, mac_addr) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-08-28 22:44:54 +00:00
|
|
|
if (gethostname(hostname, sizeof hostname) != 0)
|
|
|
|
log_Printf(LogERROR, "rad_put: gethostname(): %s\n", strerror(errno));
|
|
|
|
else {
|
2002-06-02 14:27:02 +00:00
|
|
|
#if 0
|
2000-08-28 22:44:54 +00:00
|
|
|
if ((hp = gethostbyname(hostname)) != NULL) {
|
|
|
|
hostaddr.s_addr = *(u_long *)hp->h_addr;
|
|
|
|
if (rad_put_addr(r->cx.rad, RAD_NAS_IP_ADDRESS, hostaddr) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: rad_put_string: %s\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-06-02 14:27:02 +00:00
|
|
|
#endif
|
2000-08-28 22:44:54 +00:00
|
|
|
if (rad_put_string(r->cx.rad, RAD_NAS_IDENTIFIER, hostname) != 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: rad_put_string: %s\n",
|
|
|
|
rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-14 12:55:39 +00:00
|
|
|
radius_put_physical_details(r->cx.rad, dl->physical);
|
2000-08-28 22:44:54 +00:00
|
|
|
|
|
|
|
if (rad_put_int(r->cx.rad, RAD_ACCT_STATUS_TYPE, acct_type) != 0 ||
|
2002-06-15 08:03:30 +00:00
|
|
|
rad_put_string(r->cx.rad, RAD_ACCT_SESSION_ID, ac->session_id) != 0 ||
|
2000-08-28 22:44:54 +00:00
|
|
|
rad_put_string(r->cx.rad, RAD_ACCT_MULTI_SESSION_ID,
|
|
|
|
ac->multi_session_id) != 0 ||
|
2002-06-15 08:03:30 +00:00
|
|
|
rad_put_int(r->cx.rad, RAD_ACCT_DELAY_TIME, 0) != 0) {
|
2000-08-28 22:44:54 +00:00
|
|
|
/* XXX ACCT_DELAY_TIME should be increased each time a packet is waiting */
|
|
|
|
log_Printf(LogERROR, "rad_put: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-17 01:07:53 +00:00
|
|
|
if (acct_type == RAD_STOP || acct_type == RAD_ALIVE)
|
|
|
|
/* Show some statistics */
|
2004-05-19 21:00:42 +00:00
|
|
|
if (rad_put_int(r->cx.rad, RAD_ACCT_INPUT_OCTETS, stats->OctetsIn % UINT32_MAX) != 0 ||
|
|
|
|
rad_put_int(r->cx.rad, RAD_ACCT_INPUT_GIGAWORDS, stats->OctetsIn / UINT32_MAX) != 0 ||
|
2000-08-28 22:44:54 +00:00
|
|
|
rad_put_int(r->cx.rad, RAD_ACCT_INPUT_PACKETS, stats->PacketsIn) != 0 ||
|
2004-05-19 21:00:42 +00:00
|
|
|
rad_put_int(r->cx.rad, RAD_ACCT_OUTPUT_OCTETS, stats->OctetsOut % UINT32_MAX) != 0 ||
|
|
|
|
rad_put_int(r->cx.rad, RAD_ACCT_OUTPUT_GIGAWORDS, stats->OctetsOut / UINT32_MAX) != 0 ||
|
2000-08-28 22:44:54 +00:00
|
|
|
rad_put_int(r->cx.rad, RAD_ACCT_OUTPUT_PACKETS, stats->PacketsOut)
|
|
|
|
!= 0 ||
|
|
|
|
rad_put_int(r->cx.rad, RAD_ACCT_SESSION_TIME, throughput_uptime(stats))
|
|
|
|
!= 0) {
|
|
|
|
log_Printf(LogERROR, "rad_put: %s\n", rad_strerror(r->cx.rad));
|
|
|
|
rad_close(r->cx.rad);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-17 01:07:53 +00:00
|
|
|
if (log_IsKept(LogPHASE) || log_IsKept(LogRADIUS)) {
|
2004-09-05 01:46:52 +00:00
|
|
|
const char *what;
|
2004-07-17 01:07:53 +00:00
|
|
|
int level;
|
|
|
|
|
|
|
|
switch (acct_type) {
|
|
|
|
case RAD_START:
|
|
|
|
what = "START";
|
|
|
|
level = log_IsKept(LogPHASE) ? LogPHASE : LogRADIUS;
|
|
|
|
break;
|
|
|
|
case RAD_STOP:
|
|
|
|
what = "STOP";
|
|
|
|
level = log_IsKept(LogPHASE) ? LogPHASE : LogRADIUS;
|
|
|
|
break;
|
|
|
|
case RAD_ALIVE:
|
|
|
|
what = "ALIVE";
|
|
|
|
level = LogRADIUS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
what = "<unknown>";
|
|
|
|
level = log_IsKept(LogPHASE) ? LogPHASE : LogRADIUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
log_Printf(level, "Radius(acct): %s data sent\n", what);
|
|
|
|
}
|
|
|
|
|
2001-02-04 01:08:26 +00:00
|
|
|
r->cx.auth = NULL; /* Not valid for accounting requests */
|
2000-08-28 22:44:54 +00:00
|
|
|
if ((got = rad_init_send_request(r->cx.rad, &r->cx.fd, &tv)))
|
|
|
|
radius_Process(r, got);
|
|
|
|
else {
|
|
|
|
log_Printf(LogDEBUG, "Using radius_Timeout [%p]\n", radius_Timeout);
|
|
|
|
r->cx.timer.load = tv.tv_usec / TICKUNIT + tv.tv_sec * SECTICKS;
|
|
|
|
r->cx.timer.func = radius_Timeout;
|
2001-02-04 01:08:26 +00:00
|
|
|
r->cx.timer.name = "radius acct";
|
2000-08-28 22:44:54 +00:00
|
|
|
r->cx.timer.arg = r;
|
|
|
|
timer_Start(&r->cx.timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-06 02:54:47 +00:00
|
|
|
/*
|
|
|
|
* How do things look at the moment ?
|
|
|
|
*/
|
1999-01-28 01:56:34 +00:00
|
|
|
void
|
|
|
|
radius_Show(struct radius *r, struct prompt *p)
|
|
|
|
{
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(p, " Radius config: %s",
|
|
|
|
*r->cfg.file ? r->cfg.file : "none");
|
1999-01-28 01:56:34 +00:00
|
|
|
if (r->valid) {
|
2001-01-26 01:41:34 +00:00
|
|
|
prompt_Printf(p, "\n IP: %s\n", inet_ntoa(r->ip));
|
|
|
|
prompt_Printf(p, " Netmask: %s\n", inet_ntoa(r->mask));
|
|
|
|
prompt_Printf(p, " MTU: %lu\n", r->mtu);
|
|
|
|
prompt_Printf(p, " VJ: %sabled\n", r->vj ? "en" : "dis");
|
2002-05-10 03:11:35 +00:00
|
|
|
prompt_Printf(p, " Message: %s\n", r->repstr ? r->repstr : "");
|
2002-06-12 00:33:17 +00:00
|
|
|
prompt_Printf(p, " MPPE Enc Policy: %s\n",
|
|
|
|
radius_policyname(r->mppe.policy));
|
|
|
|
prompt_Printf(p, " MPPE Enc Types: %s\n",
|
|
|
|
radius_typesname(r->mppe.types));
|
|
|
|
prompt_Printf(p, " MPPE Recv Key: %seceived\n",
|
|
|
|
r->mppe.recvkey ? "R" : "Not r");
|
|
|
|
prompt_Printf(p, " MPPE Send Key: %seceived\n",
|
|
|
|
r->mppe.sendkey ? "R" : "Not r");
|
2002-05-16 13:34:20 +00:00
|
|
|
prompt_Printf(p, " MS-CHAP2-Response: %s\n",
|
|
|
|
r->msrepstr ? r->msrepstr : "");
|
2002-05-10 03:11:35 +00:00
|
|
|
prompt_Printf(p, " Error Message: %s\n", r->errstr ? r->errstr : "");
|
1999-01-28 01:56:34 +00:00
|
|
|
if (r->routes)
|
2001-01-26 01:41:34 +00:00
|
|
|
route_ShowSticky(p, r->routes, " Routes", 16);
|
2003-06-19 18:19:31 +00:00
|
|
|
#ifndef NOINET6
|
|
|
|
if (r->ipv6routes)
|
|
|
|
route_ShowSticky(p, r->ipv6routes, " IPv6 Routes", 16);
|
|
|
|
#endif
|
1999-01-28 01:56:34 +00:00
|
|
|
} else
|
|
|
|
prompt_Printf(p, " (not authenticated)\n");
|
|
|
|
}
|
2004-07-17 01:07:53 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
radius_alive(void *v)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = (struct bundle *)v;
|
|
|
|
|
|
|
|
timer_Stop(&bundle->radius.alive.timer);
|
|
|
|
bundle->radius.alive.timer.load = bundle->radius.alive.interval * SECTICKS;
|
|
|
|
if (bundle->radius.alive.timer.load) {
|
|
|
|
radius_Account(&bundle->radius, &bundle->radacct,
|
|
|
|
bundle->links, RAD_ALIVE, &bundle->ncp.ipcp.throughput);
|
|
|
|
timer_Start(&bundle->radius.alive.timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
radius_StartTimer(struct bundle *bundle)
|
|
|
|
{
|
|
|
|
if (bundle->radius.cfg.file && bundle->radius.alive.interval) {
|
|
|
|
bundle->radius.alive.timer.func = radius_alive;
|
|
|
|
bundle->radius.alive.timer.name = "radius alive";
|
|
|
|
bundle->radius.alive.timer.load = bundle->radius.alive.interval * SECTICKS;
|
|
|
|
bundle->radius.alive.timer.arg = bundle;
|
|
|
|
radius_alive(bundle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
radius_StopTimer(struct radius *r)
|
|
|
|
{
|
|
|
|
timer_Stop(&r->alive.timer);
|
|
|
|
}
|