accounting {
reference = "%{tolower:type.%{Acct-Status-Type}.query}"
+ # All SQL statements are logged to this file.
+ # This file is preferred to the "logfile" set in
+ # the mods-enabled/sql file. The filename is dynamically
+ # expanded at run time, so you can use %H, etc., just
+ # as with the detail file.
+# logfile = ${logdir}/accounting.sql
+
type {
accounting-on {
query = "\
accounting {
reference = "%{tolower:type.%{Acct-Status-Type}.query}"
+ # All SQL statements are logged to this file.
+ # This file is preferred to the "logfile" set in
+ # the mods-enabled/sql file. The filename is dynamically
+ # expanded at run time, so you can use %H, etc., just
+ # as with the detail file.
+# logfile = ${logdir}/accounting.sql
+
column_list = "\
acctsessionid, acctuniqueid, username, \
realm, nasipaddress, nasportid, \
accounting {
reference = "%{tolower:type.%{Acct-Status-Type}.query}"
+ # All SQL statements are logged to this file.
+ # This file is preferred to the "logfile" set in
+ # the mods-enabled/sql file. The filename is dynamically
+ # expanded at run time, so you can use %H, etc., just
+ # as with the detail file.
+# logfile = ${logdir}/accounting.sql
+
type {
accounting-on {
query = "\
'%{%{User-Password}:-%{Chap-Password}}', \
'%{reply:Packet-Type}', \
TO_TIMESTAMP('%S','YYYY-MM-DDHH24:MI:SS'))"
- }
\ No newline at end of file
+ }
accounting {
reference = "%{tolower:type.%{Acct-Status-Type}.query}"
+ # All SQL statements are logged to this file.
+ # This file is preferred to the "logfile" set in
+ # the mods-enabled/sql file. The filename is dynamically
+ # expanded at run time, so you can use %H, etc., just
+ # as with the detail file.
+# logfile = ${logdir}/accounting.sql
+
type {
accounting-on {
query = "\
char *reference;
- int sqltrace;
- char *tracefile;
+ char *logfile;
} rlm_sql_config_section_t;
typedef struct sql_config {
char *simul_count_query;
char *simul_verify_query;
char *groupmemb_query;
- int sqltrace;
- int do_clients;
- int read_groups;
- char *tracefile;
+ int do_clients;
+ int read_groups;
+ char *logfile;
char *xlat_name;
int deletestalesessions;
char *allowed_chars;
return rows;
}
+/*
+ * Log the query to a file.
+ */
void query_log(SQL_INST *inst, REQUEST *request,
- rlm_sql_config_section_t *section, char *querystr)
+ rlm_sql_config_section_t *section, char *query)
{
- FILE *sqlfile = NULL;
-
- if (!inst->config->sqltrace && (!section || !section->sqltrace))
- return;
-
+ int fd;
+ const char *filename;
char buffer[8192];
- if (!radius_xlat(buffer, sizeof(buffer),
- section && section->tracefile ? section->tracefile :
- inst->config->tracefile,
- request, NULL)) {
- radlog(L_ERR, "rlm_sql (%s): xlat failed.",
- inst->config->xlat_name);
- return;
+ if (section) {
+ filename = section->logfile;
+ } else {
+ filename = inst->config->logfile;
}
- if ((sqlfile = fopen(buffer, "a")) == (FILE *) NULL) {
- radlog(L_ERR, "rlm_sql (%s): Couldn't open file %s",
- inst->config->xlat_name,
- buffer);
- } else {
- int fd = fileno(sqlfile);
+ if (!filename) return;
+
+ if (!radius_xlat(buffer, sizeof(buffer), filename, request, NULL)) {
+ radlog(L_ERR, "rlm_sql (%s): xlat failed.",
+ inst->config->xlat_name);
+ return;
+ }
- rad_lockfd(fd, MAX_QUERY_LEN);
- fputs(querystr, sqlfile);
- fputs(";\n", sqlfile);
- fclose(sqlfile); /* and release the lock */
+ fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0666);
+ if (fd < 0) {
+ radlog(L_ERR, "rlm_sql (%s): Couldn't open file %s: %s",
+ inst->config->xlat_name, buffer, strerror(errno));
+ return;
}
+
+ rad_lockfd(fd, MAX_QUERY_LEN);
+ write(fd, query, strlen(query));
+ write(fd, ";\n", 2);
+ close(fd); /* and release the lock */
}