1 |
/* This file is part of GNU RADIUS. |
/* This file is part of GNU Radius. |
2 |
Copyright (C) 2000,2001, Sergey Poznyakoff |
Copyright (C) 2000,2001, Sergey Poznyakoff |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Radius is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
7 |
(at your option) any later version. |
(at your option) any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Radius is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
GNU General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software Foundation, |
along with GNU Radius; if not, write to the Free Software Foundation, |
16 |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
18 |
#define RADIUS_MODULE_ACCT_C |
#define RADIUS_MODULE_ACCT_C |
19 |
|
|
|
#ifndef lint |
|
|
static char rcsid[] = |
|
|
"@(#) $Id$"; |
|
|
#endif |
|
20 |
#define LOG_EMPTY_USERNAME |
#define LOG_EMPTY_USERNAME |
21 |
|
|
22 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
60 |
|
|
61 |
/* Zap a user, or all users on a NAS, from the radutmp file. */ |
/* Zap a user, or all users on a NAS, from the radutmp file. */ |
62 |
int |
int |
63 |
radzap(nasaddr, port, user, t) |
radzap(UINT4 nasaddr, int port, char *user, time_t t) |
|
UINT4 nasaddr; |
|
|
int port; |
|
|
char *user; |
|
|
time_t t; |
|
64 |
{ |
{ |
65 |
struct radutmp *up; |
struct radutmp *up; |
66 |
radut_file_t file; |
radut_file_t file; |
91 |
} |
} |
92 |
|
|
93 |
static void |
static void |
94 |
store_session_id(buffer, len, id, idlen) |
store_session_id(char *buffer, int len, char *id, int idlen) |
|
char *buffer; |
|
|
int len; |
|
|
char *id; |
|
|
int idlen; |
|
95 |
{ |
{ |
96 |
int off = idlen - len; |
int off = idlen - len; |
97 |
if (off < 0) |
if (off < 0) |
101 |
} |
} |
102 |
|
|
103 |
int |
int |
104 |
write_wtmp(ut) |
write_wtmp(struct radutmp *ut) |
|
struct radutmp *ut; |
|
105 |
{ |
{ |
106 |
return radwtmp_putent(radwtmp_path, ut); |
return radwtmp_putent(radwtmp_path, ut); |
107 |
} |
} |
108 |
|
|
109 |
void |
void |
110 |
backslashify(dst, src, len) |
backslashify(char *dst, char *src, int len) |
|
char *dst; |
|
|
char *src; |
|
|
int len; |
|
111 |
{ |
{ |
112 |
#define CHECK(l,m) \ |
#define CHECK(l,m) \ |
113 |
if (l <= m) goto end; else l -= m |
if (l <= m) goto end; else l -= m |
152 |
} |
} |
153 |
|
|
154 |
int |
int |
155 |
check_attribute(check_pairs, pair_attr, pair_value, def) |
check_attribute(VALUE_PAIR *check_pairs, int pair_attr, |
156 |
VALUE_PAIR *check_pairs; |
int pair_value, int def) |
|
int pair_attr; |
|
|
int pair_value; |
|
|
int def; |
|
157 |
{ |
{ |
158 |
VALUE_PAIR *pair; |
VALUE_PAIR *pair; |
159 |
|
|
176 |
|
|
177 |
/* Store logins in the RADIUS utmp file. */ |
/* Store logins in the RADIUS utmp file. */ |
178 |
int |
int |
179 |
rad_acct_system(radreq, dowtmp) |
rad_acct_system(RADIUS_REQ *radreq, int dowtmp) |
|
RADIUS_REQ *radreq; |
|
|
int dowtmp; |
|
180 |
{ |
{ |
181 |
struct radutmp ut; |
struct radutmp ut; |
182 |
VALUE_PAIR *vp; |
VALUE_PAIR *vp; |
432 |
} |
} |
433 |
|
|
434 |
int |
int |
435 |
write_detail(radreq, authtype, f) |
write_detail(RADIUS_REQ *radreq, int authtype, char *f) |
|
RADIUS_REQ *radreq; |
|
|
int authtype; |
|
|
char *f; |
|
436 |
{ |
{ |
437 |
FILE *outfd; |
FILE *outfd; |
438 |
char nasname[MAX_LONGNAME]; |
char nasname[MAX_LONGNAME]; |
546 |
} |
} |
547 |
|
|
548 |
int |
int |
549 |
rad_acct_db(radreq, authtype) |
rad_acct_db(RADIUS_REQ *radreq, int authtype) |
|
RADIUS_REQ *radreq; |
|
|
int authtype; |
|
550 |
{ |
{ |
551 |
int rc = 0; |
int rc = 0; |
552 |
|
|
560 |
} |
} |
561 |
|
|
562 |
int |
int |
563 |
rad_acct_ext(radreq) |
rad_acct_ext(RADIUS_REQ *radreq) |
|
RADIUS_REQ *radreq; |
|
564 |
{ |
{ |
565 |
VALUE_PAIR *p; |
VALUE_PAIR *p; |
566 |
|
|
587 |
|
|
588 |
/* run accounting modules */ |
/* run accounting modules */ |
589 |
int |
int |
590 |
rad_accounting(radreq, activefd) |
rad_accounting(RADIUS_REQ *radreq, int activefd, int verified) |
|
RADIUS_REQ *radreq; |
|
|
int activefd; |
|
591 |
{ |
{ |
|
int auth; |
|
|
|
|
592 |
log_open(L_ACCT); |
log_open(L_ACCT); |
|
/* See if we know this client, then check the request authenticator. */ |
|
|
auth = calc_acctdigest(radreq); |
|
|
if (auth == REQ_AUTH_BAD) |
|
|
stat_inc(acct, radreq->ipaddr, num_bad_sign); |
|
593 |
|
|
594 |
huntgroup_access(radreq); |
huntgroup_access(radreq); |
595 |
|
|
596 |
#if defined(RT_ASCEND_EVENT_REQUEST) && defined(RT_ASCEND_EVENT_RESPONSE) |
#if defined(RT_ASCEND_EVENT_REQUEST) && defined(RT_ASCEND_EVENT_RESPONSE) |
597 |
/* Special handling for Ascend-Event-Request */ |
/* Special handling for Ascend-Event-Request */ |
598 |
if (radreq->code == RT_ASCEND_EVENT_REQUEST) { |
if (radreq->code == RT_ASCEND_EVENT_REQUEST) { |
599 |
write_detail(radreq, auth, "detail"); |
write_detail(radreq, verified, "detail"); |
600 |
rad_send_reply(RT_ASCEND_EVENT_RESPONSE, |
radius_send_reply(RT_ASCEND_EVENT_RESPONSE, |
601 |
radreq, NULL, NULL, activefd); |
radreq, NULL, NULL, activefd); |
602 |
stat_inc(acct, radreq->ipaddr, num_resp); |
stat_inc(acct, radreq->ipaddr, num_resp); |
603 |
return 0; |
return 0; |
604 |
} |
} |
605 |
#endif |
#endif |
606 |
|
|
607 |
if (rad_acct_system(radreq, doradwtmp) == 0 && |
if (rad_acct_system(radreq, doradwtmp) == 0 && |
608 |
rad_acct_db(radreq, auth) == 0 && |
rad_acct_db(radreq, verified) == 0 && |
609 |
rad_acct_ext(radreq) == 0) { |
rad_acct_ext(radreq) == 0) { |
610 |
/* Now send back an ACK to the NAS. */ |
/* Now send back an ACK to the NAS. */ |
611 |
rad_send_reply(RT_ACCOUNTING_RESPONSE, |
radius_send_reply(RT_ACCOUNTING_RESPONSE, |
612 |
radreq, NULL, NULL, activefd); |
radreq, NULL, NULL, activefd); |
613 |
stat_inc(acct, radreq->ipaddr, num_resp); |
stat_inc(acct, radreq->ipaddr, num_resp); |
614 |
return 0; |
return 0; |
623 |
0 if user is not logged in */ |
0 if user is not logged in */ |
624 |
|
|
625 |
static int |
static int |
626 |
rad_check_ts(ut) |
rad_check_ts(struct radutmp *ut) |
|
struct radutmp *ut; |
|
627 |
{ |
{ |
628 |
int result; |
int result; |
629 |
|
|
649 |
/* Return value: that of CHECKRAD process, i.e. 1 means true (user FOUND) |
/* Return value: that of CHECKRAD process, i.e. 1 means true (user FOUND) |
650 |
0 means false (user NOT found) */ |
0 means false (user NOT found) */ |
651 |
static int |
static int |
652 |
check_ts(ut) |
check_ts(struct radutmp *ut) |
|
struct radutmp *ut; |
|
653 |
{ |
{ |
654 |
NAS *nas; |
NAS *nas; |
655 |
|
|
669 |
} |
} |
670 |
|
|
671 |
int |
int |
672 |
rad_check_realm(realm) |
rad_check_realm(REALM *realm) |
|
REALM *realm; |
|
673 |
{ |
{ |
674 |
int count; |
int count; |
675 |
struct radutmp *up; |
struct radutmp *up; |
728 |
0 == OK, |
0 == OK, |
729 |
1 == user exceeds its simultaneous-use parameter */ |
1 == user exceeds its simultaneous-use parameter */ |
730 |
int |
int |
731 |
rad_check_multi(name, request, maxsimul, pcount) |
rad_check_multi(char *name, VALUE_PAIR *request, int maxsimul, int *pcount) |
|
char *name; |
|
|
VALUE_PAIR *request; |
|
|
int maxsimul; |
|
|
int *pcount; |
|
732 |
{ |
{ |
733 |
radut_file_t file; |
radut_file_t file; |
734 |
int count; |
int count; |
796 |
} |
} |
797 |
|
|
798 |
int |
int |
799 |
write_nas_restart(status, addr) |
write_nas_restart(int status, UINT4 addr) |
|
int status; |
|
|
UINT4 addr; |
|
800 |
{ |
{ |
801 |
struct radutmp ut; |
struct radutmp ut; |
802 |
|
|