[prev in list] [next in list] [prev in thread] [next in thread]
List: freeradius-devel
Subject: PATCH - rlm_sql accounting fixes
From: Randy Moore <ramoore () axion-it ! net>
Date: 2002-01-27 20:05:27
[Download RAW message or body]
Hi,
This patch fixes a couple of problems processing Accounting packets with SQL.
First, I've fixed several error log messages that all claimed to be about
ALIVE packets when they were really other types.
Second, I've fixed two cases where 'sql_finish' was called before we were
done with the returned query results.
Third, I adjusted the logic for processing STOP packets so that if the
Query did not run, we don't try to process the results of the Query.
This patch should be applied against:
src/modules/rlm_sql/rlm_sql.c
The patch is also available for download from:
http://www.axion-it.net/download/sql_accounting.patch
Oh, and the CISCO ACCOUNTING HACK patch submitted by "Kevin C. Miller"
<kevinm@andrew.cmu.edu> on Jan 22nd needs to be applied *before* applying
this one.
Any comments or questions?
--- rlm_sql.c.orig Sun Jan 27 11:09:45 2002
+++ rlm_sql.c Sun Jan 27 11:30:55 2002
@@ -444,7 +444,7 @@
if (querystr) {
if ((inst->module->sql_query)(sqlsocket,
inst->config, querystr) < 0)
- radlog(L_ERR, "rlm_sql: Couldn't
update SQL accounting for ALIVE packet - %s", (char
*)(inst->module->sql_error)(sqlsocket, inst->config));
+ radlog(L_ERR, "rlm_sql: Couldn't
update SQL accounting for Acct On/Off packet - %s", (char
*)(inst->module->sql_error)(sqlsocket, inst->config));
(inst->module->sql_finish_query)(sqlsocket,
inst->config);
}
@@ -484,8 +484,7 @@
if (querystr) {
if ((inst->module->sql_query)(sqlsocket,
inst->config, querystr) < 0) {
- radlog(L_ERR, "rlm_sql: Couldn't
update SQL accounting" " for ALIVE packet - %s", (char
*)(inst->module->sql_error)(sqlsocket, inst->config));
-
(inst->module->sql_finish_query)(sqlsocket, inst->config);
+ radlog(L_ERR, "rlm_sql: Couldn't
update SQL accounting" " for START packet - %s", (char
*)(inst->module->sql_error)(sqlsocket, inst->config));
/*
* We failed the insert
above. It's probably because
@@ -502,6 +501,7 @@
(inst->module->sql_finish_query)(sqlsocket,
inst->config);
}
}
+ (inst->module->sql_finish_query)(sqlsocket,
inst->config);
}
break;
@@ -523,46 +523,47 @@
if (querystr) {
if ((inst->module->sql_query)(sqlsocket,
inst->config, querystr) < 0) {
- radlog(L_ERR, "rlm_sql: Couldn't
update SQL accounting START record - %s", (char
*)(inst->module->sql_error)(sqlsocket, inst->config));
+ radlog(L_ERR, "rlm_sql: Couldn't
update SQL accounting STOP record - %s", (char
*)(inst->module->sql_error)(sqlsocket, inst->config));
}
- (inst->module->sql_finish_query)(sqlsocket,
inst->config);
- }
-
- numaffected =
(inst->module->sql_affected_rows)(sqlsocket, inst->config);
- if (numaffected < 1) {
- /*
- * If our update above didn't match anything
- * we assume it's because we haven't seen a
- * matching Start record. So we have to
- * insert this stop rather than do an update
- */
+ else {
+ numaffected =
(inst->module->sql_affected_rows)(sqlsocket, inst->config);
+ if (numaffected < 1) {
+ /*
+ * If our update above
didn't match anything
+ * we assume it's because
we haven't seen a
+ * matching Start
record. So we have to
+ * insert this stop rather
than do an update
+ */
#ifdef CISCO_ACCOUNTING_HACK
- /*
- * If stop but zero session length AND no
previous
- * session found, drop it as in invalid packet
- * This is to fix CISCO's aaa from filling our
- * table with bogus crap
- */
- if ((pair = pairfind(request->packet->vps,
PW_ACCT_SESSION_TIME)) != NULL)
- acctsessiontime = pair->lvalue;
-
- if (acctsessiontime <= 0) {
- radius_xlat(logstr, MAX_QUERY_LEN,
"rlm_sql: Stop packet with zero session length. (user '%{User-Name}', nas
'%{NAS-IP-Address}')", request, NULL);
- radlog(L_ERR, logstr);
- sql_release_socket(inst, sqlsocket);
- return RLM_MODULE_FAIL;
- }
+ /*
+ * If stop but zero session
length AND no previous
+ * session found, drop it
as in invalid packet
+ * This is to fix CISCO's
aaa from filling our
+ * table with bogus crap
+ */
+ if ((pair =
pairfind(request->packet->vps, PW_ACCT_SESSION_TIME)) != NULL)
+ acctsessiontime =
pair->lvalue;
+
+ if (acctsessiontime <= 0) {
+ radius_xlat(logstr,
MAX_QUERY_LEN, "rlm_sql: Stop packet with zero session length. (user
'%{User-Name}', nas '%{NAS-IP-Address}')", request, NULL);
+ radlog(L_ERR, logstr);
+
sql_release_socket(inst, sqlsocket);
+ return RLM_MODULE_FAIL;
+ }
#endif
- radius_xlat(querystr, MAX_QUERY_LEN,
inst->config->accounting_stop_query_alt, request, NULL);
- query_log(inst, querystr);
+ radius_xlat(querystr,
MAX_QUERY_LEN, inst->config->accounting_stop_query_alt, request, NULL);
+ query_log(inst, querystr);
- if (querystr) {
- if
((inst->module->sql_query)(sqlsocket, inst->config, querystr) < 0) {
- radlog(L_ERR, "rlm_sql:
Couldn't insert SQL accounting STOP record - %s", (char
*)(inst->module->sql_error)(sqlsocket, inst->config));
+ if (querystr) {
+ if
((inst->module->sql_query)(sqlsocket, inst->config, querystr) < 0) {
+
radlog(L_ERR, "rlm_sql: Couldn't insert SQL accounting STOP record - %s",
(char *)(inst->module->sql_error)(sqlsocket, inst->config));
+ }
+
(inst->module->sql_finish_query)(sqlsocket, inst->config);
+ }
}
-
(inst->module->sql_finish_query)(sqlsocket, inst->config);
}
+ (inst->module->sql_finish_query)(sqlsocket,
inst->config);
}
break;
}
Randy Moore
Axion Information Technologies, Inc.
email ramoore@axion-it.net
phone 301-408-1200
fax 301-445-3947
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/devel.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic