Allow rlm_sql_null, and minor fixes to the sql logging
authorAlan T. DeKok <aland@freeradius.org>
Fri, 10 Aug 2012 13:47:12 +0000 (15:47 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 11 Aug 2012 07:24:39 +0000 (09:24 +0200)
So that we can avoid the "sql_log" module

src/modules/rlm_sql/all.mk
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sql/rlm_sql.h
src/modules/rlm_sql/sql.c

index 779aeea..053fbb5 100644 (file)
@@ -1,3 +1,5 @@
 TARGET         = rlm_sql.a
 SOURCES                = rlm_sql.c sql.c
 # this uses the RLM_CFLAGS and RLM_LIBS and SOURCES defs to make TARGET.
+
+SUBMAKEFILES := drivers/rlm_sql_null/all.mk
index 2cc898d..7469019 100644 (file)
@@ -73,6 +73,8 @@ static const CONF_PARSER module_config[] = {
         offsetof(SQL_CONFIG,deletestalesessions), NULL, "yes"},
        {"sql_user_name", PW_TYPE_STRING_PTR,
         offsetof(SQL_CONFIG,query_user), NULL, ""},
+       {"logfile", PW_TYPE_STRING_PTR,
+        offsetof(SQL_CONFIG,logfile), NULL, NULL},
        {"default_user_profile", PW_TYPE_STRING_PTR,
         offsetof(SQL_CONFIG,default_profile), NULL, ""},
        {"nas_query", PW_TYPE_STRING_PTR,
@@ -164,7 +166,7 @@ static int sql_xlat(void *instance, REQUEST *request,
        if (sqlsocket == NULL)
                return 0;
 
-       query_log(inst, request, NULL, querystr);
+       rlm_sql_query_log(inst, request, NULL, querystr);
 
        /*
         *      If the query starts with any of the following prefixes,
@@ -900,14 +902,6 @@ static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
                        
                goto error;
        }
-       /*
-        *      Sanity check for crazy people.
-        */
-       if (strncmp(inst->config->sql_driver, "rlm_sql_", 8) != 0) {
-               radlog(L_ERR, "\"%s\" is NOT an SQL driver!",
-                      inst->config->sql_driver);       
-               goto error;
-       }
 
        xlat_name = cf_section_name2(conf);
        if (xlat_name == NULL) {
@@ -956,6 +950,15 @@ static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
        xlat_register(xlat_name, (RAD_XLAT_FUNC)sql_xlat, inst);
                
        /*
+        *      Sanity check for crazy people.
+        */
+       if (strncmp(inst->config->sql_driver, "rlm_sql_", 8) != 0) {
+               radlog(L_ERR, "\"%s\" is NOT an SQL driver!",
+                      inst->config->sql_driver);
+               goto error;
+       }
+
+       /*
         *      Load the appropriate driver for our database
         */
        inst->handle = lt_dlopenext(inst->config->sql_driver);
@@ -1250,7 +1253,7 @@ static int rlm_sql_redundant(SQL_INST *inst, REQUEST *request,
        pair = cf_itemtopair(item);
        attr = cf_pair_attr(pair);
        
-       RDEBUG2("Failing between pairs with name '%s'", attr);
+       RDEBUG2("Using query template '%s'", attr);
        
        sqlsocket = sql_get_socket(inst);
        if (sqlsocket == NULL)
@@ -1266,7 +1269,7 @@ static int rlm_sql_redundant(SQL_INST *inst, REQUEST *request,
                if (!*querystr)
                        goto null_query;
                
-               query_log(inst, request, section, querystr);
+               rlm_sql_query_log(inst, request, section, querystr);
                
                sql_ret = rlm_sql_query(&sqlsocket, inst, querystr);    
                if (sql_ret == SQL_DOWN)
index 9fbaa78..ee140ff 100644 (file)
@@ -129,7 +129,7 @@ int     sql_getvpdata(SQL_INST * inst, SQLSOCK ** sqlsocket, VALUE_PAIR **pair,
 int     sql_read_naslist(SQLSOCK * sqlsocket);
 int     sql_read_clients(SQLSOCK * sqlsocket);
 int     sql_dict_init(SQLSOCK * sqlsocket);
-void   query_log(SQL_INST *inst, REQUEST *request,
+void   rlm_sql_query_log(SQL_INST *inst, REQUEST *request,
                          rlm_sql_config_section_t *section, char *querystr);
 int    rlm_sql_select_query(SQLSOCK **sqlsocket, SQL_INST *inst, char *query);
 int    rlm_sql_query(SQLSOCK **sqlsocket, SQL_INST *inst, char *query);
index e3a5d23..f4a7aed 100644 (file)
@@ -408,18 +408,16 @@ int sql_getvpdata(SQL_INST * inst, SQLSOCK **sqlsocket, VALUE_PAIR **pair, char
 /*
  *     Log the query to a file.
  */
-void query_log(SQL_INST *inst, REQUEST *request,
-              rlm_sql_config_section_t *section, char *query)
+void rlm_sql_query_log(SQL_INST *inst, REQUEST *request,
+                      rlm_sql_config_section_t *section, char *query)
 {
        int fd;
-       const char *filename;
+       const char *filename = NULL;
        char buffer[8192];
 
-       if (section) {
-               filename = section->logfile;
-       } else {
-               filename = inst->config->logfile;
-       }
+       if (section) filename = section->logfile;
+
+       if (!filename) filename = inst->config->logfile;
 
        if (!filename) return;