* Define a structure for our module configuration.
*/
typedef struct rlm_sql_log_t {
- char *name;
char *path;
char *postauth_query;
char *sql_user_name;
*/
static int sql_log_instantiate(CONF_SECTION *conf, void **instance)
{
- const char *name;
rlm_sql_log_t *inst;
/*
}
/*
- * 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;
}
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.
*/
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);
/* 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;
}
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;
}
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;
}
}
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;
}
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);
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,