Use new debugging functions (RDEBUG, radlog_request)
authorAlan T. DeKok <aland@freeradius.org>
Sun, 17 Aug 2008 07:50:06 +0000 (09:50 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 17 Aug 2008 07:50:06 +0000 (09:50 +0200)
src/modules/rlm_sql_log/rlm_sql_log.c

index 076f680..ff9fdcd 100644 (file)
@@ -44,7 +44,6 @@ static int sql_log_postauth(void *instance, REQUEST *request);
  *     Define a structure for our module configuration.
  */
 typedef struct rlm_sql_log_t {
-       char            *name;
        char            *path;
        char            *postauth_query;
        char            *sql_user_name;
@@ -83,7 +82,6 @@ static char *allowed_chars = NULL;
  */
 static int sql_log_instantiate(CONF_SECTION *conf, void **instance)
 {
-       const char      *name;
        rlm_sql_log_t   *inst;
 
         /*
@@ -96,22 +94,11 @@ static int sql_log_instantiate(CONF_SECTION *conf, void **instance)
         }
 
        /*
-        *      Get the name of the current section in the conf file.
-        */
-       name = cf_section_name2(conf);
-       if (name == NULL)
-               name = cf_section_name1(conf);
-       if (name == NULL)
-               name = "sql_log";
-       inst->name = strdup(name);
-
-       /*
         *      If the configuration parameters can't be parsed,
         *      then fail.
         */
        if (cf_section_parse(conf, inst, module_config) < 0) {
-               radlog(L_ERR, "rlm_sql_log (%s): Unable to parse parameters",
-                      inst->name);
+               radlog(L_ERR, "rlm_sql_log: Unable to parse parameters");
                sql_log_detach(inst);
                return -1;
        }
@@ -131,11 +118,6 @@ static int sql_log_detach(void *instance)
        char **p;
        rlm_sql_log_t *inst = (rlm_sql_log_t *)instance;
 
-       if (inst->name) {
-               free(inst->name);
-               inst->name = NULL;
-       }
-
        /*
         *      Free up dynamically allocated string pointers.
         */
@@ -236,8 +218,7 @@ static int sql_set_user(rlm_sql_log_t *inst, REQUEST *request, char *sqlusername
 
        if (tmpuser[0] != '\0') {
                strlcpy(sqlusername, tmpuser, sizeof(tmpuser));
-               DEBUG2("rlm_sql_log (%s): sql_set_user escaped user --> '%s'",
-                      inst->name, sqlusername);
+               RDEBUG2("sql_set_user escaped user --> '%s'", sqlusername);
                vp = pairmake("SQL-User-Name", sqlusername, 0);
                if (vp == NULL) {
                        radlog(L_ERR, "%s", librad_errstr);
@@ -263,8 +244,8 @@ static int sql_xlat_query(rlm_sql_log_t *inst, REQUEST *request, const char *que
 
        /* Add attribute 'SQL-User-Name' */
        if (sql_set_user(inst, request, sqlusername, NULL) <0) {
-               radlog(L_ERR, "rlm_sql_log (%s): Couldn't add SQL-User-Name attribute",
-                              inst->name);
+               radlog_request(L_ERR, 0, request, 
+                              "Couldn't add SQL-User-Name attribute");
                return RLM_MODULE_FAIL;
        }
 
@@ -272,8 +253,8 @@ static int sql_xlat_query(rlm_sql_log_t *inst, REQUEST *request, const char *que
        xlat_query[0] = '\0';
        radius_xlat(xlat_query, len, query, request, sql_escape_func);
        if (xlat_query[0] == '\0') {
-               radlog(L_ERR, "rlm_sql_log (%s): Couldn't xlat the query %s",
-                      inst->name, query);
+               radlog_request(L_ERR, 0, request, "Couldn't xlat the query %s",
+                      query);
                return RLM_MODULE_FAIL;
        }
 
@@ -313,25 +294,25 @@ static int sql_log_write(rlm_sql_log_t *inst, REQUEST *request, const char *line
 
        while (!locked) {
                if ((fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0666)) < 0) {
-                       radlog(L_ERR, "rlm_sql_log (%s): Couldn't open file %s: %s",
-                              inst->name, path, strerror(errno));
+                       radlog_request(L_ERR, 0, request, "Couldn't open file %s: %s",
+                                      path, strerror(errno));
                        return RLM_MODULE_FAIL;
                }
                if (setlock(fd) != 0) {
-                       radlog(L_ERR, "rlm_sql_log (%s): Couldn't lock file %s: %s",
-                              inst->name, path, strerror(errno));
+                       radlog_request(L_ERR, 0, request, "Couldn't lock file %s: %s",
+                                      path, strerror(errno));
                        close(fd);
                        return RLM_MODULE_FAIL;
                }
                if (fstat(fd, &st) != 0) {
-                       radlog(L_ERR, "rlm_sql_log (%s): Couldn't stat file %s: %s",
-                              inst->name, path, strerror(errno));
+                       radlog_request(L_ERR, 0, request, "Couldn't stat file %s: %s",
+                                      path, strerror(errno));
                        close(fd);
                        return RLM_MODULE_FAIL;
                }
                if (st.st_nlink == 0) {
-                       DEBUG("rlm_sql_log (%s): File %s removed by another program, retrying",
-                             inst->name, path);
+                       RDEBUG("File %s removed by another program, retrying",
+                             path);
                        close(fd);
                        continue;
                }
@@ -339,8 +320,8 @@ static int sql_log_write(rlm_sql_log_t *inst, REQUEST *request, const char *line
        }
 
        if ((fp = fdopen(fd, "a")) == NULL) {
-               radlog(L_ERR, "rlm_sql_log (%s): Couldn't associate a stream with file %s: %s",
-                      inst->name, path, strerror(errno));
+               radlog_request(L_ERR, 0, request, "Couldn't associate a stream with file %s: %s",
+                              path, strerror(errno));
                close(fd);
                return RLM_MODULE_FAIL;
        }
@@ -363,24 +344,23 @@ static int sql_log_accounting(void *instance, REQUEST *request)
        DICT_VALUE      *dval;
        CONF_PAIR       *cp;
 
-       DEBUG("rlm_sql_log (%s): Processing sql_log_accounting", inst->name);
+       RDEBUG("Processing sql_log_accounting");
 
        /* Find the Acct Status Type. */
        if ((pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) == NULL) {
-               radlog(L_ERR, "rlm_sql_log (%s): Packet has no account status type",
-                      inst->name);
+               radlog_request(L_ERR, 0, request, "Packet has no account status type");
                return RLM_MODULE_INVALID;
        }
 
        /* Search the query in conf section of the module */
        if ((dval = dict_valbyattr(PW_ACCT_STATUS_TYPE, pair->vp_integer)) == NULL) {
-               radlog(L_ERR, "rlm_sql_log (%s): Unsupported Acct-Status-Type = %d",
-                      inst->name, pair->vp_integer);
+               radlog_request(L_ERR, 0, request, "Unsupported Acct-Status-Type = %d",
+                              pair->vp_integer);
                return RLM_MODULE_NOOP;
        }
        if ((cp = cf_pair_find(inst->conf_section, dval->name)) == NULL) {
-               DEBUG("rlm_sql_log (%s): Couldn't find an entry %s in the config section",
-                     inst->name, dval->name);
+               RDEBUG("Couldn't find an entry %s in the config section",
+                      dval->name);
                return RLM_MODULE_NOOP;
        }
        cfquery = cf_pair_value(cp);
@@ -403,7 +383,7 @@ static int sql_log_postauth(void *instance, REQUEST *request)
        char            querystr[MAX_QUERY_LEN];
        rlm_sql_log_t   *inst = (rlm_sql_log_t *)instance;
 
-       DEBUG("rlm_sql_log (%s): Processing sql_log_postauth", inst->name);
+       RDEBUG("Processing sql_log_postauth");
 
        /* Xlat the query */
        ret = sql_xlat_query(inst, request, inst->postauth_query,