#define PATH_STAT_RESET "/statreset"
#define PATH_COUNTERS "/counters"
+#define msg_err_session(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \
+ session->pool->tag.tagname, session->pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_warn_session(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \
+ session->pool->tag.tagname, session->pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_info_session(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \
+ session->pool->tag.tagname, session->pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_debug_session(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
+ session->pool->tag.tagname, session->pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_err_ctx(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \
+ "controller", ctx->cfg->cfg_pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_warn_ctx(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \
+ "controller", ctx->cfg->cfg_pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_info_ctx(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \
+ "controller", ctx->cfg->cfg_pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_debug_ctx(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
+ "controller", ctx->cfg->cfg_pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+
/* Graph colors */
#define COLOR_CLEAN "#58A458"
#define COLOR_PROBABLE_SPAM "#D67E7E"
return str;
}
-static gboolean rspamd_check_encrypted_password (const GString * password,
- const gchar * check, const struct rspamd_controller_pbkdf *pbkdf)
+static gboolean
+rspamd_check_encrypted_password (struct rspamd_controller_worker_ctx *ctx,
+ const GString * password, const gchar * check,
+ const struct rspamd_controller_pbkdf *pbkdf)
{
const gchar *salt, *hash;
gchar *salt_decoded, *key_decoded;
if (salt_decoded == NULL || salt_len != pbkdf->salt_len) {
/* We have some unknown salt here */
- msg_info ("incorrect salt: %z, while %z expected",
+ msg_info_ctx ("incorrect salt: %z, while %z expected",
salt_len, pbkdf->salt_len);
return FALSE;
}
if (key_decoded == NULL || key_len != pbkdf->key_len) {
/* We have some unknown salt here */
- msg_info ("incorrect key: %z, while %z expected",
+ msg_info_ctx ("incorrect key: %z, while %z expected",
key_len, pbkdf->key_len);
return FALSE;
}
local_key, pbkdf->key_len, pbkdf->rounds);
if (!rspamd_constant_memcmp (key_decoded, local_key, pbkdf->key_len)) {
- msg_info ("incorrect or absent password has been specified");
+ msg_info_ctx ("incorrect or absent password has been specified");
ret = FALSE;
}
/* Access list logic */
if (rspamd_inet_address_get_af (session->from_addr) == AF_UNIX) {
- msg_info ("allow unauthorized connection from a unix socket");
+ msg_info_session ("allow unauthorized connection from a unix socket");
return TRUE;
}
else if (ctx->secure_map
&& radix_find_compressed_addr (ctx->secure_map, session->from_addr)
!= RADIX_NO_VALUE) {
- msg_info ("allow unauthorized connection from a trusted IP %s",
+ msg_info_session ("allow unauthorized connection from a trusted IP %s",
rspamd_inet_address_to_string (session->from_addr));
return TRUE;
}
return TRUE;
}
}
- msg_info ("absent password has been specified");
+ msg_info_session ("absent password has been specified");
ret = FALSE;
}
else {
ret = rspamd_constant_memcmp (password->str, check, password->len);
}
else {
- ret = rspamd_check_encrypted_password (password, check,
+ ret = rspamd_check_encrypted_password (ctx, password, check,
pbkdf);
}
}
else {
- msg_warn (
+ msg_warn_session (
"no password to check while executing a privileged command");
if (ctx->secure_map) {
msg_info("deny unauthorized connection");
password->len);
}
else {
- check_normal = rspamd_check_encrypted_password (password,
+ check_normal = rspamd_check_encrypted_password (ctx,
+ password,
check, pbkdf);
}
password->len);
}
else {
- check_enable = rspamd_check_encrypted_password (password,
+ check_enable = rspamd_check_encrypted_password (ctx,
+ password,
check, pbkdf);
}
}
idstr = rspamd_http_message_find_header (msg, "Map");
if (idstr == NULL) {
- msg_info ("absent map id");
+ msg_info_session ("absent map id");
rspamd_controller_send_error (conn_ent, 400, "400 id header missing");
return 0;
}
id = strtoul (idstr->str, &errstr, 10);
if (*errstr != '\0' && !g_ascii_isspace (*errstr)) {
- msg_info ("invalid map id");
+ msg_info_session ("invalid map id");
rspamd_controller_send_error (conn_ent, 400, "400 invalid map id");
return 0;
}
}
if (!found) {
- msg_info ("map not found");
+ msg_info_session ("map not found");
rspamd_controller_send_error (conn_ent, 404, "404 map not found");
return 0;
}
if (stat (map->uri, &st) == -1 || (fd = open (map->uri, O_RDONLY)) == -1) {
- msg_err ("cannot open map %s: %s", map->uri, strerror (errno));
+ msg_err_session ("cannot open map %s: %s", map->uri, strerror (errno));
rspamd_controller_send_error (conn_ent, 500, "500 map open error");
return 0;
}
if (read (fd, reply->body->str, st.st_size) == -1) {
close (fd);
rspamd_http_message_free (reply);
- msg_err ("cannot read map %s: %s", map->uri, strerror (errno));
+ msg_err_session ("cannot read map %s: %s", map->uri, strerror (errno));
rspamd_controller_send_error (conn_ent, 500, "500 map read error");
return 0;
}
if (rspamd_learn_task_spam (session->cl, task, session->is_spam, &err) ==
RSPAMD_STAT_PROCESS_ERROR) {
- msg_info ("cannot learn <%s>: %e", task->message_id, err);
+ msg_info_session ("cannot learn <%s>: %e", task->message_id, err);
rspamd_controller_send_error (conn_ent, err->code, err->message);
return TRUE;
}
/* Successful learn */
- msg_info ("<%s> learned message as %s: %s",
+ msg_info_session ("<%s> learned message as %s: %s",
rspamd_inet_address_to_string (session->from_addr),
session->is_spam ? "spam" : "ham",
task->message_id);
}
if (msg->body == NULL || msg->body->len == 0) {
- msg_err ("got zero length body, cannot continue");
+ msg_err_session ("got zero length body, cannot continue");
rspamd_controller_send_error (conn_ent,
400,
"Empty body is not permitted");
}
if (!rspamd_task_process (task, RSPAMD_TASK_PROCESS_LEARN)) {
- msg_warn ("message cannot be processed for %s", task->message_id);
+ msg_warn_session ("message cannot be processed for %s", task->message_id);
rspamd_controller_send_error (conn_ent, task->err->code, task->err->message);
rspamd_session_destroy (task->s);
return 0;
}
if (msg->body == NULL || msg->body->len == 0) {
- msg_err ("got zero length body, cannot continue");
+ msg_err_session ("got zero length body, cannot continue");
rspamd_controller_send_error (conn_ent,
400,
"Empty body is not permitted");
}
if (!rspamd_task_process (task, RSPAMD_TASK_PROCESS_ALL)) {
- msg_warn ("message cannot be processed for %s", task->message_id);
+ msg_warn_session ("message cannot be processed for %s", task->message_id);
rspamd_controller_send_error (conn_ent, task->err->code, task->err->message);
rspamd_session_destroy (task->s);
return 0;
}
if (msg->body == NULL || msg->body->len == 0) {
- msg_err ("got zero length body, cannot continue");
+ msg_err_session ("got zero length body, cannot continue");
rspamd_controller_send_error (conn_ent,
400,
"Empty body is not permitted");
metric = g_hash_table_lookup (ctx->cfg->metrics, DEFAULT_METRIC);
if (metric == NULL) {
- msg_err ("cannot find default metric");
+ msg_err_session ("cannot find default metric");
rspamd_controller_send_error (conn_ent, 500,
"Default metric is absent");
return 0;
/* Now check for dynamic config */
if (!ctx->cfg->dynamic_conf) {
- msg_err ("dynamic conf has not been defined");
+ msg_err_session ("dynamic conf has not been defined");
rspamd_controller_send_error (conn_ent,
500,
"No dynamic_rules setting defined");
ucl_parser_add_chunk (parser, msg->body->str, msg->body->len);
if ((error = ucl_parser_get_error (parser)) != NULL) {
- msg_err ("cannot parse input: %s", error);
+ msg_err_session ("cannot parse input: %s", error);
rspamd_controller_send_error (conn_ent, 400, "Cannot parse input");
ucl_parser_free (parser);
return 0;
ucl_parser_free (parser);
if (obj->type != UCL_ARRAY || obj->len != 3) {
- msg_err ("input is not an array of 3 elements");
+ msg_err_session ("input is not an array of 3 elements");
rspamd_controller_send_error (conn_ent, 400, "Cannot parse input");
ucl_object_unref (obj);
return 0;
}
if (dump_dynamic_config (ctx->cfg)) {
- msg_info ("<%s> modified %d actions",
+ msg_info_session ("<%s> modified %d actions",
rspamd_inet_address_to_string (session->from_addr),
added);
}
if (msg->body == NULL || msg->body->len == 0) {
- msg_err ("got zero length body, cannot continue");
+ msg_err_session ("got zero length body, cannot continue");
rspamd_controller_send_error (conn_ent,
400,
"Empty body is not permitted");
metric = g_hash_table_lookup (ctx->cfg->metrics, DEFAULT_METRIC);
if (metric == NULL) {
- msg_err ("cannot find default metric");
+ msg_err_session ("cannot find default metric");
rspamd_controller_send_error (conn_ent, 500,
"Default metric is absent");
return 0;
/* Now check for dynamic config */
if (!ctx->cfg->dynamic_conf) {
- msg_err ("dynamic conf has not been defined");
+ msg_err_session ("dynamic conf has not been defined");
rspamd_controller_send_error (conn_ent,
500,
"No dynamic_rules setting defined");
ucl_parser_add_chunk (parser, msg->body->str, msg->body->len);
if ((error = ucl_parser_get_error (parser)) != NULL) {
- msg_err ("cannot parse input: %s", error);
+ msg_err_session ("cannot parse input: %s", error);
rspamd_controller_send_error (conn_ent, 400, "Cannot parse input");
ucl_parser_free (parser);
return 0;
ucl_parser_free (parser);
if (obj->type != UCL_ARRAY) {
- msg_err ("input is not an array");
+ msg_err_session ("input is not an array");
rspamd_controller_send_error (conn_ent, 400, "Cannot parse input");
ucl_object_unref (obj);
return 0;
while ((cur = ucl_iterate_object (obj, &iter, true))) {
if (cur->type != UCL_OBJECT) {
- msg_err ("json array data error");
+ msg_err_session ("json array data error");
rspamd_controller_send_error (conn_ent, 400, "Cannot parse input");
ucl_object_unref (obj);
return 0;
if (sym && fabs (*sym->weight_ptr - val) > 0.01) {
if (!add_dynamic_symbol (ctx->cfg, DEFAULT_METRIC,
ucl_object_tostring (jname), val)) {
- msg_err ("add symbol failed for %s",
+ msg_err_session ("add symbol failed for %s",
ucl_object_tostring (jname));
rspamd_controller_send_error (conn_ent, 506,
"Add symbol failed");
if (added > 0) {
if (dump_dynamic_config (ctx->cfg)) {
- msg_info ("<%s> modified %d symbols",
+ msg_info_session ("<%s> modified %d symbols",
rspamd_inet_address_to_string (session->from_addr),
added);
}
}
else {
- msg_err ("no symbols to save");
+ msg_err_session ("no symbols to save");
rspamd_controller_send_error (conn_ent, 404, "No symbols to save");
}
}
if (msg->body == NULL || msg->body->len == 0) {
- msg_err ("got zero length body, cannot continue");
+ msg_err_session ("got zero length body, cannot continue");
rspamd_controller_send_error (conn_ent,
400,
"Empty body is not permitted");
idstr = rspamd_http_message_find_header (msg, "Map");
if (idstr == NULL) {
- msg_info ("absent map id");
+ msg_info_session ("absent map id");
rspamd_controller_send_error (conn_ent, 400, "Map id not specified");
return 0;
}
id = strtoul (idstr->str, &errstr, 10);
if (*errstr != '\0' && !g_ascii_isspace (*errstr)) {
- msg_info ("invalid map id: %V", idstr);
+ msg_info_session ("invalid map id: %V", idstr);
rspamd_controller_send_error (conn_ent, 400, "Map id is invalid");
return 0;
}
}
if (!found) {
- msg_info ("map not found: %d", id);
+ msg_info_session ("map not found: %d", id);
rspamd_controller_send_error (conn_ent, 404, "Map id not found");
return 0;
}
if (g_atomic_int_get (map->locked)) {
- msg_info ("map locked: %s", map->uri);
+ msg_info_session ("map locked: %s", map->uri);
rspamd_controller_send_error (conn_ent, 404, "Map is locked");
return 0;
}
fd = open (map->uri, O_WRONLY | O_TRUNC);
if (fd == -1) {
g_atomic_int_set (map->locked, 0);
- msg_info ("map %s open error: %s", map->uri, strerror (errno));
+ msg_info_session ("map %s open error: %s", map->uri, strerror (errno));
rspamd_controller_send_error (conn_ent, 404, "Map id not found");
return 0;
}
if (write (fd, msg->body->str, msg->body->len) == -1) {
- msg_info ("map %s write error: %s", map->uri, strerror (errno));
+ msg_info_session ("map %s write error: %s", map->uri, strerror (errno));
close (fd);
g_atomic_int_set (map->locked, 0);
rspamd_controller_send_error (conn_ent, 500, "Map write error");
return 0;
}
- msg_info ("<%s>, map %s saved",
+ msg_info_session ("<%s>, map %s saved",
rspamd_inet_address_to_string (session->from_addr),
map->uri);
/* Close and unlock */
return 0;
}
- msg_info ("<%s> reset stat",
+ msg_info_session ("<%s> reset stat",
rspamd_inet_address_to_string (session->from_addr));
return rspamd_controller_handle_stat_common (conn_ent, msg, TRUE);
}
cmd = g_hash_table_lookup (session->ctx->custom_commands, msg->url->str);
if (cmd == NULL || cmd->handler == NULL) {
- msg_err ("custom command %V has not been found", msg->url);
+ msg_err_session ("custom command %V has not been found", msg->url);
rspamd_controller_send_error (conn_ent, 404, "No command associated");
return 0;
}
return 0;
}
if (cmd->require_message && (msg->body == NULL || msg->body->len == 0)) {
- msg_err ("got zero length body, cannot continue");
+ msg_err_session ("got zero length body, cannot continue");
rspamd_controller_send_error (conn_ent,
400,
"Empty body is not permitted");
rspamd_controller_error_handler (struct rspamd_http_connection_entry *conn_ent,
GError *err)
{
- msg_err ("http error occurred: %s", err->message);
+ struct rspamd_controller_session *session = conn_ent->ud;
+
+ msg_err_session ("http error occurred: %s", err->message);
}
static void
{
struct rspamd_worker *worker = (struct rspamd_worker *) arg;
struct rspamd_controller_worker_ctx *ctx;
- struct rspamd_controller_session *nsession;
+ struct rspamd_controller_session *session;
rspamd_inet_addr_t *addr;
gint nfd;
if ((nfd =
rspamd_accept_from_socket (fd, &addr)) == -1) {
- msg_warn ("accept failed: %s", strerror (errno));
+ msg_warn_ctx ("accept failed: %s", strerror (errno));
return;
}
/* Check for EAGAIN */
return;
}
- nsession = g_slice_alloc0 (sizeof (struct rspamd_controller_session));
- nsession->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
- nsession->ctx = ctx;
+ session = g_slice_alloc0 (sizeof (struct rspamd_controller_session));
+ session->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
+ "csession");
+ session->ctx = ctx;
- nsession->from_addr = addr;
+ session->from_addr = addr;
- rspamd_http_router_handle_socket (ctx->http, nfd, nsession);
+ rspamd_http_router_handle_socket (ctx->http, nfd, session);
}
static void
-rspamd_controller_password_sane (const gchar *password, const gchar *type)
+rspamd_controller_password_sane (struct rspamd_controller_worker_ctx *ctx,
+ const gchar *password, const gchar *type)
{
const struct rspamd_controller_pbkdf *pbkdf = &pbkdf_list[0];
GString *msg;
gchar *encoded_salt, *encoded_key;
if (password == NULL) {
- msg_warn ("%s is not set, so you should filter controller availability "
+ msg_warn_ctx ("%s is not set, so you should filter controller "
+ "availability "
"by using of firewall or `secure_ip` option", type);
return;
}
rspamd_printf_gstring (msg, "$%d$%s$%s", pbkdf->id, encoded_salt,
encoded_key);
- msg_warn ("%v", msg);
+ msg_warn_ctx ("%v", msg);
g_string_free (msg, TRUE);
g_free (encoded_salt);
/* Fallback to the plain IP */
if (!radix_add_generic_iplist (secure_ip,
&ctx->secure_map)) {
- msg_warn ("cannot load or parse ip list from '%s'",
+ msg_warn_ctx ("cannot load or parse ip list from '%s'",
secure_ip);
}
}
}
}
- rspamd_controller_password_sane (ctx->password, "normal password");
- rspamd_controller_password_sane (ctx->enable_password, "enable password");
+ rspamd_controller_password_sane (ctx, ctx->password, "normal password");
+ rspamd_controller_password_sane (ctx, ctx->enable_password, "enable "
+ "password");
/* Accept event */
cache = rspamd_keypair_cache_new (256);
SOCK_STREAM /* TCP socket */
};
+#define msg_err_ctx(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \
+ "controller", ctx->cfg->cfg_pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_warn_ctx(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \
+ "controller", ctx->cfg->cfg_pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_info_ctx(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \
+ "controller", ctx->cfg->cfg_pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+#define msg_debug_ctx(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \
+ "controller", ctx->cfg->cfg_pool->tag.uid, \
+ G_STRFUNC, \
+ __VA_ARGS__)
+
/*
* Worker's context
*/
gpointer key;
/* Keys cache */
struct rspamd_keypair_cache *keys_cache;
+ /* Configuration */
+ struct rspamd_config *cfg;
};
/*
ctx = task->worker->ctx;
if (!rspamd_protocol_handle_request (task, msg)) {
- msg_err ("cannot handle request: %e", task->err);
+ msg_err_task ("cannot handle request: %e", task->err);
task->flags |= RSPAMD_TASK_FLAG_SKIP;
}
else {
}
else {
if (!rspamd_task_load_message (task, msg, chunk, len)) {
- msg_err ("cannot load message: %e", task->err);
+ msg_err_task ("cannot load message: %e", task->err);
task->flags |= RSPAMD_TASK_FLAG_SKIP;
}
}
{
struct rspamd_task *task = (struct rspamd_task *) conn->ud;
- msg_info ("abnormally closing connection from: %s, error: %e",
+ msg_info_task ("abnormally closing connection from: %s, error: %e",
rspamd_inet_address_to_string (task->client_addr), err);
/* Terminate session immediately */
rspamd_session_destroy (task->s);
if (task->processed_stages & RSPAMD_TASK_STAGE_REPLIED) {
/* We are done here */
- msg_debug ("normally closing connection from: %s",
+ msg_debug_task ("normally closing connection from: %s",
rspamd_inet_address_to_string (task->client_addr));
rspamd_session_destroy (task->s);
}
{
struct rspamd_worker *worker = (struct rspamd_worker *) arg;
struct rspamd_worker_ctx *ctx;
- struct rspamd_task *new_task;
+ struct rspamd_task *task;
rspamd_inet_addr_t *addr;
gint nfd;
ctx = worker->ctx;
if (ctx->max_tasks != 0 && ctx->tasks > ctx->max_tasks) {
- msg_info ("current tasks is now: %uD while maximum is: %uD",
+ msg_info_ctx ("current tasks is now: %uD while maximum is: %uD",
ctx->tasks,
ctx->max_tasks);
return;
if ((nfd =
rspamd_accept_from_socket (fd, &addr)) == -1) {
- msg_warn ("accept failed: %s", strerror (errno));
+ msg_warn_ctx ("accept failed: %s", strerror (errno));
return;
}
/* Check for EAGAIN */
return;
}
- new_task = rspamd_task_new (worker);
+ task = rspamd_task_new (worker);
- msg_info ("accepted connection from %s port %d",
+ msg_info_task ("accepted connection from %s port %d",
rspamd_inet_address_to_string (addr),
rspamd_inet_address_get_port (addr));
/* Copy some variables */
if (ctx->is_mime) {
- new_task->flags |= RSPAMD_TASK_FLAG_MIME;
+ task->flags |= RSPAMD_TASK_FLAG_MIME;
}
else {
- new_task->flags &= ~RSPAMD_TASK_FLAG_MIME;
+ task->flags &= ~RSPAMD_TASK_FLAG_MIME;
}
- new_task->sock = nfd;
- new_task->client_addr = addr;
+ task->sock = nfd;
+ task->client_addr = addr;
worker->srv->stat->connections_count++;
- new_task->resolver = ctx->resolver;
+ task->resolver = ctx->resolver;
- new_task->http_conn = rspamd_http_connection_new (
+ task->http_conn = rspamd_http_connection_new (
rspamd_worker_body_handler,
rspamd_worker_error_handler,
rspamd_worker_finish_handler,
0,
RSPAMD_HTTP_SERVER,
ctx->keys_cache);
- new_task->ev_base = ctx->ev_base;
+ task->ev_base = ctx->ev_base;
ctx->tasks++;
- rspamd_mempool_add_destructor (new_task->task_pool,
+ rspamd_mempool_add_destructor (task->task_pool,
(rspamd_mempool_destruct_t)reduce_tasks_count, &ctx->tasks);
/* Set up async session */
- new_task->s = rspamd_session_create (new_task->task_pool, rspamd_task_fin,
- rspamd_task_restore, rspamd_task_free_hard, new_task);
+ task->s = rspamd_session_create (task->task_pool, rspamd_task_fin,
+ rspamd_task_restore, rspamd_task_free_hard, task);
if (ctx->key) {
- rspamd_http_connection_set_key (new_task->http_conn, ctx->key);
+ rspamd_http_connection_set_key (task->http_conn, ctx->key);
}
- rspamd_http_connection_read_message (new_task->http_conn,
- new_task,
+ rspamd_http_connection_read_message (task->http_conn,
+ task,
nfd,
&ctx->io_tv,
ctx->ev_base);
ctx->is_mime = TRUE;
ctx->timeout = DEFAULT_WORKER_IO_TIMEOUT;
+ ctx->cfg = cfg;
rspamd_rcl_register_worker_option (cfg, type, "mime",
rspamd_rcl_parse_struct_boolean, ctx,
rspamd_keypair_cache_destroy (ctx->keys_cache);
exit (EXIT_SUCCESS);
-}
-
-/*
- * vi:ts=4
- */
+}
\ No newline at end of file