#if __GNUC__ >= 3
#define RDEBUG(fmt, ...) if(request && request->radlog) request->radlog(L_DBG, 1, request, fmt, ## __VA_ARGS__)
+#define RDEBUGI(fmt, ...) if(request && request->radlog) request->radlog(L_INFO, 1, request, fmt, ## __VA_ARGS__)
#define RDEBUGW(fmt, ...) if(request && request->radlog) request->radlog(L_DBG_WARN, 1, request, fmt, ## __VA_ARGS__)
#define RDEBUGE(fmt, ...) do { if(request) { \
module_failure_msg(request, fmt, ## __VA_ARGS__); \
VALUE_PAIR *check)
{
- rlm_rcode_t rcode = RLM_MODULE_NOTFOUND;
ldap_rcode_t status;
char base_dn[LDAP_MAX_DN_STR_LEN + 1];
* rlm_ldap_find_user does this, too. Oh well.
*/
if (radius_xlat(base_dn, sizeof(base_dn), request, inst->groupobj_base_dn,
- rlm_ldap_escape_func, NULL) < 0) {
- rcode = RLM_MODULE_INVALID;
-
+ rlm_ldap_escape_func, NULL) < 0) {
RDEBUGE("Failed creating base_dn");
return RLM_MODULE_INVALID;
ssize_t rlm_ldap_xlat_filter(REQUEST *request, const char **sub, size_t sublen, char *out, size_t outlen)
{
char buffer[LDAP_MAX_FILTER_STR_LEN + 1];
- const char *in;
+ const char *in = NULL;
char *p = buffer;
ssize_t len = 0;
if (fd >= 0) {
strcat(line, "\n");
- write(fd, line, strlen(line));
+ if (write(fd, line, strlen(line)) < 0) {
+ DEBUGE("rlm_linelog: Failed writing: %s", strerror(errno));
+
+ return RLM_MODULE_FAIL;
+ }
+
close(fd);
#ifdef HAVE_SYSLOG_H
/*
* Zap all users on a NAS from the radutmp file.
*/
-static int radutmp_zap(REQUEST *request,
- const char *filename,
- uint32_t nasaddr,
- time_t t)
+static rlm_rcode_t radutmp_zap(REQUEST *request, const char *filename, uint32_t nasaddr, time_t t)
{
struct radutmp u;
int fd;
fd = open(filename, O_RDWR);
if (fd < 0) {
- RDEBUGE("Error accessing file %s: %s",
- filename, strerror(errno));
+ RDEBUGE("Error accessing file %s: %s", filename, strerror(errno));
return RLM_MODULE_FAIL;
}
/*
- * Lock the utmp file, prefer lockf() over flock().
- */
+ * Lock the utmp file, prefer lockf() over flock().
+ */
if (rad_lockfd(fd, LOCK_LEN) < 0) {
- RDEBUGE("Failed to acquire lock on file %s:"
- " %s", filename, strerror(errno));
+ RDEBUGE("Failed to acquire lock on file %s: %s", filename, strerror(errno));
close(fd);
return RLM_MODULE_FAIL;
}
/*
- * Find the entry for this NAS / portno combination.
- */
+ * Find the entry for this NAS / portno combination.
+ */
while (read(fd, &u, sizeof(u)) == sizeof(u)) {
- if ((nasaddr != 0 && nasaddr != u.nas_address) ||
- u.type != P_LOGIN)
- continue;
- /*
- * Match. Zap it.
- */
- if (lseek(fd, -(off_t)sizeof(u), SEEK_CUR) < 0) {
- RDEBUGE("radutmp_zap: negative lseek!");
- lseek(fd, (off_t)0, SEEK_SET);
- }
- u.type = P_IDLE;
- u.time = t;
- write(fd, &u, sizeof(u));
+ if ((nasaddr != 0 && nasaddr != u.nas_address) || u.type != P_LOGIN) {
+ continue;
+ }
+ /*
+ * Match. Zap it.
+ */
+ if (lseek(fd, -(off_t)sizeof(u), SEEK_CUR) < 0) {
+ RDEBUGE("radutmp_zap: negative lseek!");
+ lseek(fd, (off_t)0, SEEK_SET);
+ }
+ u.type = P_IDLE;
+ u.time = t;
+
+ if (write(fd, &u, sizeof(u)) < 0) {
+ RDEBUGE("Failed writing: %s", strerror(errno));
+
+ close(fd);
+ return RLM_MODULE_FAIL;
+ }
}
close(fd); /* and implicitely release the locks */
- return 0;
+ return RLM_MODULE_OK;
}
/*
* UDP packets out of order.
*/
if (status == PW_STATUS_ACCOUNTING_ON && (ut.nas_address != htonl(INADDR_NONE))) {
- radlog(L_INFO, "rlm_radutmp: NAS %s restarted (Accounting-On packet seen)", nas);
- radutmp_zap(request, filename, ut.nas_address, ut.time);
- rcode = RLM_MODULE_OK;
+ RDEBUGI("NAS %s restarted (Accounting-On packet seen)", nas);
+ rcode = radutmp_zap(request, filename, ut.nas_address, ut.time);
goto finish;
}
if (status == PW_STATUS_ACCOUNTING_OFF && (ut.nas_address != htonl(INADDR_NONE))) {
- radlog(L_INFO, "rlm_radutmp: NAS %s rebooted (Accounting-Off packet seen)", nas);
- radutmp_zap(request, filename, ut.nas_address, ut.time);
- rcode = RLM_MODULE_OK;
+ RDEBUGI("NAS %s rebooted (Accounting-Off packet seen)", nas);
+ rcode = radutmp_zap(request, filename, ut.nas_address, ut.time);
goto finish;
}
}
ut.type = P_LOGIN;
- write(fd, &ut, sizeof(u));
+ if (write(fd, &ut, sizeof(u)) < 0) {
+ RDEBUGE("Failed writing: %s", strerror(errno));
+
+ rcode = RLM_MODULE_FAIL;
+ goto finish;
+ }
}
/*
u.type = P_IDLE;
u.time = ut.time;
u.delay = ut.delay;
- write(fd, &u, sizeof(u));
+ if (write(fd, &u, sizeof(u)) < 0) {
+ RDEBUGE("Failed writing: %s", strerror(errno));
+
+ rcode = RLM_MODULE_FAIL;
+ goto finish;
+ }
} else if (r == 0) {
RDEBUGW("Logout for NAS %s port %u, but no Login record", nas, ut.nas_port);
}
close(fd); /* and implicitely release the locks */
}
- return RLM_MODULE_OK;
+ return rcode;
}
#endif
case SQLITE_FULL:
case SQLITE_CONSTRAINT:
case SQLITE_MISMATCH:
- DEBUGE("rlm_sql_sqlite: Error (%d): %s", error, sqlite3_errmsg(db));
+ radlog(L_ERR, "rlm_sql_sqlite: Error (%d): %s", error, sqlite3_errmsg(db));
return -1;
break;
* Errors with the handle, that probably require reinitialisation
*/
default:
- DEBUGE("rlm_sql_sqlite: Handle is unusable, error (%d): %s", error, sqlite3_errmsg(db));
+ radlog(L_ERR, "rlm_sql_sqlite: Handle is unusable, error (%d): %s", error, sqlite3_errmsg(db));
return SQL_DOWN;
break;
}
f = fopen(filename, "r");
if (!f) {
- DEBUGE("rlm_sql_sqlite: Failed opening SQL file \"%s\": %s", filename,
+ radlog(L_ERR, "rlm_sql_sqlite: Failed opening SQL file \"%s\": %s", filename,
strerror(errno));
return -1;
}
if (fstat(fileno(f), &finfo) < 0) {
- DEBUGE("rlm_sql_sqlite: Failed stating SQL file \"%s\": %s", filename,
+ radlog(L_ERR, "rlm_sql_sqlite: Failed stating SQL file \"%s\": %s", filename,
strerror(errno));
fclose(f);
if (finfo.st_size > BOOTSTRAP_MAX) {
too_big:
- DEBUGE("rlm_sql_sqlite: Size of SQL (%zu) file exceeds limit (%uk)",
+ radlog(L_ERR, "rlm_sql_sqlite: Size of SQL (%zu) file exceeds limit (%uk)",
(size_t) finfo.st_size / 1024, BOOTSTRAP_MAX / 1024);
fclose(f);
if (!len) {
if (ferror(f)) {
- DEBUGE("rlm_sql_sqlite: Error reading SQL file: %s", strerror(errno));
+ radlog(L_ERR, "rlm_sql_sqlite: Error reading SQL file: %s", strerror(errno));
fclose(f);
talloc_free(buffer);
return -1;
}
- DEBUG("rlm_sql_sqlite: Ignoring empty SQL file");
+ radlog(L_DBG, "rlm_sql_sqlite: Ignoring empty SQL file");
fclose(f);
talloc_free(buffer);
}
if ((p - buffer) != len) {
- DEBUGE("rlm_sql_sqlite: Bootstrap file contains non-UTF8 char at offset %zu", p - buffer);
+ radlog(L_ERR, "rlm_sql_sqlite: Bootstrap file contains non-UTF8 char at offset %zu", p - buffer);
talloc_free(buffer);
return -1;
}
exists = rad_file_exists(driver->filename);
if (exists < 0) {
- DEBUGE("rlm_sql_sqlite: Database exists, but couldn't be opened: %s", strerror(errno));
+ radlog(L_ERR, "rlm_sql_sqlite: Database exists, but couldn't be opened: %s", strerror(errno));
return -1;
}
}
if (rad_mkdir(buff, 0700) < 0) {
- DEBUGE("rlm_sql_sqlite: Failed creating directory for SQLite database");
+ radlog(L_ERR, "rlm_sql_sqlite: Failed creating directory for SQLite database");
talloc_free(buff);
status = sqlite3_open_v2(driver->filename, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (!db) {
- DEBUGE("rlm_sql_sqlite: Failed creating opening/creating SQLite database, error "
+ radlog(L_ERR, "rlm_sql_sqlite: Failed creating opening/creating SQLite database, error "
"code (%u)", status);
goto unlink;
status = sqlite3_close(db);
if (status != SQLITE_OK) {
- DEBUGE("rlm_sql_sqlite: Error closing SQLite handle, error code (%u)", status);
+ radlog(L_ERR, "rlm_sql_sqlite: Error closing SQLite handle, error code (%u)", status);
goto unlink;
}
if (ret < 0) {
unlink:
if (unlink(driver->filename) < 0) {
- DEBUGE("rlm_sql_sqlite: Error removing partially initialised database: %s",
+ radlog(L_ERR, "rlm_sql_sqlite: Error removing partially initialised database: %s",
strerror(errno));
}
return -1;
status = sqlite3_open(driver->filename, &(conn->db));
#endif
if (!conn->db) {
- DEBUGE("rlm_sql_sqlite: Failed creating opening/creating SQLite database error code (%u)",
+ radlog(L_ERR, "rlm_sql_sqlite: Failed creating opening/creating SQLite database error code (%u)",
status);
return -1;