* @param fmt printf style format string.
* @param ... printf arguments.
*/
- #define ROPTIONAL(_l_request, _l_global, fmt, ...) \
+ #define MOD_ROPTIONAL(_l_request, _l_global, fmt, ...) \
do {\
if (request) {\
_l_request(fmt, ## __VA_ARGS__);\
}\
} while (0)
+/** Use different logging functions depending on whether request is NULL or not.
+ *
+ * This is useful for areas of code which are run on server startup, and when
+ * processing requests.
+ *
+ * @param _l_prefix added to global messages.
+ * @param _l_request The name of a R* logging macro e.g. RDEBUG3.
+ * @param _l_global The name of a global logging macro e.g. DEBUG3.
+ * @param fmt printf style format string.
+ * @param ... printf arguments.
+ */
+ #define ROPTIONAL(_l_request, _l_global, _l_prefix, fmt, ...) \
+do {\
+ if (request) {\
+ _l_request(fmt, ## __VA_ARGS__);\
+ } else {\
+ _l_global(_l_prefix ": " fmt, ## __VA_ARGS__);\
+ }\
+} while (0)
+
#define RATE_LIMIT_ENABLED rate_limit_enabled() //!< True if rate limiting is enabled.
/** Rate limit messages
*
# endif
# include <openssl/ssl.h>
-#define MOD_PREFIX "tls"
+#define LOG_PREFIX "tls"
#ifdef ENABLE_OPENSSL_VERSION_CHECK
typedef struct libssl_defect {
if ((l = ERR_get_error()) != 0) {
char const *p = ERR_error_string(l, NULL);
- if (p) ROPTIONAL(REDEBUG, ERROR, "SSL says: %s", p);
+ if (p) ROPTIONAL(REDEBUG, ERROR, LOG_PREFIX, "SSL says: %s", p);
}
e = SSL_get_error(s, ret);
* being regarded as "dead".
*/
case SSL_ERROR_SYSCALL:
- ROPTIONAL(REDEBUG, ERROR, "%s failed in a system call (%d), TLS session failed", text, ret);
+ ROPTIONAL(REDEBUG, ERROR, LOG_PREFIX, "%s failed in a system call (%d), TLS session failed", text, ret);
return 0;
case SSL_ERROR_SSL:
- ROPTIONAL(REDEBUG, ERROR, "%s failed inside of TLS (%d), TLS session failed", text, ret);
+ ROPTIONAL(REDEBUG, ERROR, LOG_PREFIX, "%s failed inside of TLS (%d), TLS session failed", text, ret);
return 0;
default:
* them - so "politely inform" the caller that
* the code needs updating here.
*/
- ROPTIONAL(REDEBUG, ERROR, "FATAL SSL error: %d", e);
+ ROPTIONAL(REDEBUG, ERROR, LOG_PREFIX, "FATAL SSL error: %d", e);
return 0;
}
return 1;
}
- if (!int_ssl_check(request, ssn->ssl, err, "SSL_read")) {
- return 0;
- }
+ if (!int_ssl_check(request, ssn->ssl, err, "SSL_read")) return 0;
/* Some Extra STATE information for easy debugging */
if (SSL_is_init_finished(ssn->ssl)) RDEBUG2("SSL Connection Established");
*/
ret = (inst->module->sql_fetch_row)(*handle, inst->config);
if (ret < 0) {
- ROPTIONAL(RERROR, ERROR, "Error fetching row");
+ MOD_ROPTIONAL(RERROR, ERROR, "Error fetching row");
rlm_sql_print_error(inst, request, *handle, false);
}
num = (inst->module->sql_error)(handle->log_ctx, log, (sizeof(log) / sizeof(*log)), handle, inst->config);
if (num == 0) {
- ROPTIONAL(RERROR, ERROR, "Unknown error");
+ MOD_ROPTIONAL(RERROR, ERROR, "Unknown error");
return;
}
switch (log[i].type) {
case L_ERR:
- ROPTIONAL(RERROR, ERROR, "%s: %s", driver, log[i].msg);
+ MOD_ROPTIONAL(RERROR, ERROR, "%s: %s", driver, log[i].msg);
break;
case L_WARN:
- ROPTIONAL(RWARN, WARN, "%s: %s", driver, log[i].msg);
+ MOD_ROPTIONAL(RWARN, WARN, "%s: %s", driver, log[i].msg);
break;
case L_INFO:
- ROPTIONAL(RINFO, INFO, "%s: %s", driver, log[i].msg);
+ MOD_ROPTIONAL(RINFO, INFO, "%s: %s", driver, log[i].msg);
break;
case L_DBG:
default:
debug:
- ROPTIONAL(RDEBUG, DEBUG, "%s: %s", driver, log[i].msg);
+ MOD_ROPTIONAL(RDEBUG, DEBUG, "%s: %s", driver, log[i].msg);
break;
}
}
* a new connection, then give up.
*/
for (i = 0; i < (count + 1); i++) {
- ROPTIONAL(RDEBUG2, DEBUG2, "Executing query: %s", query);
+ MOD_ROPTIONAL(RDEBUG2, DEBUG2, "Executing query: %s", query);
ret = (inst->module->sql_query)(*handle, inst->config, query);
switch (ret) {
return ret;
}
- ROPTIONAL(RERROR, ERROR, "Hit reconnection limit");
+ MOD_ROPTIONAL(RERROR, ERROR, "Hit reconnection limit");
return RLM_SQL_ERROR;
}
* For sanity, for when no connections are viable, and we can't make a new one
*/
for (i = 0; i < (count + 1); i++) {
- ROPTIONAL(RDEBUG2, DEBUG2, "Executing select query: %s", query);
+ MOD_ROPTIONAL(RDEBUG2, DEBUG2, "Executing select query: %s", query);
ret = (inst->module->sql_select_query)(*handle, inst->config, query);
switch (ret) {
return ret;
}
- ROPTIONAL(RERROR, ERROR, "Hit reconnection limit");
+ MOD_ROPTIONAL(RERROR, ERROR, "Hit reconnection limit");
return RLM_SQL_ERROR;
}