]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Clean up SQL "tracefile" code
authorAlan T. DeKok <aland@freeradius.org>
Fri, 10 Aug 2012 10:45:37 +0000 (12:45 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 11 Aug 2012 07:24:39 +0000 (09:24 +0200)
There is now just a "logfile" configuration.  There is no need
to have "trace=yes" and "tracefile".

Since the logfile also locks the file, we can probably get rid of
the sql_log module.

Also document the "logfile" directive in the dialup.conf files

raddb/sql/mssql/dialup.conf
raddb/sql/mysql/dialup.conf
raddb/sql/oracle/dialup.conf
raddb/sql/postgresql/dialup.conf
src/modules/rlm_sql/rlm_sql.h
src/modules/rlm_sql/sql.c

index 6bedf69a99f441aba2c83e32cd455c4e2a336092..1c3e295bc27664eb0bda29bc6c71bd9a63e8cf8f 100644 (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 = "\
index e87e7d728a9d1da22c469f25fecd892ef7ee260c..a5b445ede9c3389a2eda7186f70ce7dc94aaaed5 100644 (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
+
                column_list = "\
                        acctsessionid,          acctuniqueid,           username, \
                        realm,                  nasipaddress,           nasportid, \
index 76fc6eccead27b010b3229db17bd7d9707612925..36d7a1dccf200862fd90cf56a76bd20414d69882 100644 (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 = "\
                 '%{%{User-Password}:-%{Chap-Password}}', \
                 '%{reply:Packet-Type}', \
                 TO_TIMESTAMP('%S','YYYY-MM-DDHH24:MI:SS'))"
-       }
\ No newline at end of file
+       }
index b235a96773832171c3f0b573d52d7748da7bf68f..a214e9f12feb1466be2525a9415b849699738bf0 100644 (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 = "\
index 1a6bbad15d0057a46b12659873394aa5c7dcbe1b..9fbaa78bf157a112aa81c4173814ab3daa00ffae 100644 (file)
@@ -30,8 +30,7 @@ typedef struct rlm_sql_config_section {
        
        char    *reference;
        
-       int             sqltrace;
-       char    *tracefile;
+       char    *logfile;
 } rlm_sql_config_section_t;
 
 typedef struct sql_config {
@@ -52,10 +51,9 @@ 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;
index d6d46f3c2e74717308d3a97ab1218c3fc2c8d768..e3a5d234c480e3e2a74f1ab48b85257bb148f687 100644 (file)
@@ -405,35 +405,39 @@ int sql_getvpdata(SQL_INST * inst, SQLSOCK **sqlsocket, VALUE_PAIR **pair, char
        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 */
 }