From: Vsevolod Stakhov Date: Thu, 26 Sep 2024 14:21:41 +0000 (+0100) Subject: [Rework] Remove control block support X-Git-Tag: 3.10.0~5^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F5160%2Fhead;p=rspamd.git [Rework] Remove control block support It has been buggy and never really used by anyone I suppose. --- diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index ee2192913..a86111ff2 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -720,12 +720,6 @@ rspamd_protocol_handle_headers(struct rspamd_task *task, break; case 'm': case 'M': - IF_HEADER(MLEN_HEADER) - { - msg_debug_protocol("read message length header, value: %T", - hv_tok); - task->protocol_flags |= RSPAMD_TASK_PROTOCOL_FLAG_HAS_CONTROL; - } IF_HEADER(MTA_TAG_HEADER) { char *mta_tag; @@ -782,120 +776,6 @@ if (!has_ip) { return TRUE; } -#define BOOL_TO_FLAG(val, flags, flag) \ - do { \ - if ((val)) (flags) |= (flag); \ - else \ - (flags) &= ~(flag); \ - } while (0) - -gboolean -rspamd_protocol_parse_task_flags(rspamd_mempool_t *pool, - const ucl_object_t *obj, - gpointer ud, - struct rspamd_rcl_section *section, - GError **err) -{ - struct rspamd_rcl_struct_parser *pd = ud; - int *target; - const char *key; - gboolean value; - - target = (int *) (((char *) pd->user_struct) + pd->offset); - key = ucl_object_key(obj); - value = ucl_object_toboolean(obj); - - if (key != NULL) { - if (g_ascii_strcasecmp(key, "pass_all") == 0) { - BOOL_TO_FLAG(value, *target, RSPAMD_TASK_FLAG_PASS_ALL); - } - else if (g_ascii_strcasecmp(key, "no_log") == 0) { - BOOL_TO_FLAG(value, *target, RSPAMD_TASK_FLAG_NO_LOG); - } - } - - return TRUE; -} - -static struct rspamd_rcl_sections_map *control_parser = NULL; - -RSPAMD_CONSTRUCTOR(rspamd_protocol_control_parser_ctor) -{ - - struct rspamd_rcl_section *sub = rspamd_rcl_add_section(&control_parser, NULL, - "*", - NULL, - NULL, - UCL_OBJECT, - FALSE, - TRUE); - /* Default handlers */ - rspamd_rcl_add_default_handler(sub, - "ip", - rspamd_rcl_parse_struct_addr, - G_STRUCT_OFFSET(struct rspamd_task, from_addr), - 0, - NULL); - rspamd_rcl_add_default_handler(sub, - "from", - rspamd_rcl_parse_struct_mime_addr, - G_STRUCT_OFFSET(struct rspamd_task, from_envelope), - 0, - NULL); - rspamd_rcl_add_default_handler(sub, - "rcpt", - rspamd_rcl_parse_struct_mime_addr, - G_STRUCT_OFFSET(struct rspamd_task, rcpt_envelope), - 0, - NULL); - rspamd_rcl_add_default_handler(sub, - "helo", - rspamd_rcl_parse_struct_string, - G_STRUCT_OFFSET(struct rspamd_task, helo), - 0, - NULL); - rspamd_rcl_add_default_handler(sub, - "user", - rspamd_rcl_parse_struct_string, - G_STRUCT_OFFSET(struct rspamd_task, auth_user), - 0, - NULL); - rspamd_rcl_add_default_handler(sub, - "pass_all", - rspamd_protocol_parse_task_flags, - G_STRUCT_OFFSET(struct rspamd_task, flags), - 0, - NULL); - rspamd_rcl_add_default_handler(sub, - "json", - rspamd_protocol_parse_task_flags, - G_STRUCT_OFFSET(struct rspamd_task, flags), - 0, - NULL); -} - -RSPAMD_DESTRUCTOR(rspamd_protocol_control_parser_dtor) -{ - rspamd_rcl_sections_free(control_parser); -} - -gboolean -rspamd_protocol_handle_control(struct rspamd_task *task, - const ucl_object_t *control) -{ - GError *err = NULL; - - if (!rspamd_rcl_parse(control_parser, task->cfg, task, task->task_pool, - control, &err)) { - msg_warn_protocol("cannot parse control block: %e", err); - g_error_free(err); - - return FALSE; - } - - return TRUE; -} - gboolean rspamd_protocol_handle_request(struct rspamd_task *task, struct rspamd_http_message *msg) diff --git a/src/libserver/protocol_internal.h b/src/libserver/protocol_internal.h index e55e54851..11f21430e 100644 --- a/src/libserver/protocol_internal.h +++ b/src/libserver/protocol_internal.h @@ -79,7 +79,6 @@ extern "C" { #define DELIVER_TO_HEADER "Deliver-To" #define NO_LOG_HEADER "Log" #define LOG_TAG_HEADER "Log-Tag" -#define MLEN_HEADER "Message-Length" #define USER_AGENT_HEADER "User-Agent" #define MTA_TAG_HEADER "MTA-Tag" #define PROFILE_HEADER "Profile" diff --git a/src/libserver/task.c b/src/libserver/task.c index 637f401a9..833046470 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -323,9 +323,6 @@ gboolean rspamd_task_load_message(struct rspamd_task *task, struct rspamd_http_message *msg, const char *start, gsize len) { - unsigned int control_len, r; - struct ucl_parser *parser; - ucl_object_t *control_obj; char filepath[PATH_MAX], *fp; int fd, flen; gulong offset = 0, shmem_size = 0; @@ -349,8 +346,8 @@ rspamd_task_load_message(struct rspamd_task *task, if (tok) { /* Shared memory part */ - r = rspamd_strlcpy(filepath, tok->begin, - MIN(sizeof(filepath), tok->len + 1)); + size_t r = rspamd_strlcpy(filepath, tok->begin, + MIN(sizeof(filepath), tok->len + 1)); rspamd_url_decode(filepath, filepath, r + 1); flen = strlen(filepath); @@ -448,8 +445,8 @@ rspamd_task_load_message(struct rspamd_task *task, if (tok) { debug_task("want to scan file %T", tok); - r = rspamd_strlcpy(filepath, tok->begin, - MIN(sizeof(filepath), tok->len + 1)); + size_t r = rspamd_strlcpy(filepath, tok->begin, + MIN(sizeof(filepath), tok->len + 1)); rspamd_url_decode(filepath, filepath, r + 1); flen = strlen(filepath); @@ -626,41 +623,6 @@ rspamd_task_load_message(struct rspamd_task *task, task->flags |= RSPAMD_TASK_FLAG_EMPTY; } - if (task->protocol_flags & RSPAMD_TASK_PROTOCOL_FLAG_HAS_CONTROL) { - rspamd_ftok_t *hv = rspamd_task_get_request_header(task, MLEN_HEADER); - gulong message_len = 0; - - if (!hv || !rspamd_strtoul(hv->begin, hv->len, &message_len) || - task->msg.len < message_len) { - msg_warn_task("message has invalid message length: %ul and total len: %ul", - message_len, task->msg.len); - g_set_error(&task->err, rspamd_task_quark(), RSPAMD_PROTOCOL_ERROR, - "Invalid length"); - return FALSE; - } - - control_len = task->msg.len - message_len; - - if (control_len > 0) { - parser = ucl_parser_new(UCL_PARSER_KEY_LOWERCASE); - - if (!ucl_parser_add_chunk(parser, task->msg.begin, control_len)) { - msg_warn_task("processing of control chunk failed: %s", - ucl_parser_get_error(parser)); - ucl_parser_free(parser); - } - else { - control_obj = ucl_parser_get_object(parser); - ucl_parser_free(parser); - rspamd_protocol_handle_control(task, control_obj); - ucl_object_unref(control_obj); - } - - task->msg.begin += control_len; - task->msg.len -= control_len; - } - } - return TRUE; } diff --git a/src/libserver/task.h b/src/libserver/task.h index 7e6341a84..6be350098 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -115,9 +115,6 @@ enum rspamd_task_stage { #define RSPAMD_TASK_FLAG_MESSAGE_REWRITE (1u << 24u) #define RSPAMD_TASK_FLAG_MAX_SHIFT (24u) - -/* Request has a JSON control block */ -#define RSPAMD_TASK_PROTOCOL_FLAG_HAS_CONTROL (1u << 0u) /* Request has been done by a local client */ #define RSPAMD_TASK_PROTOCOL_FLAG_LOCAL_CLIENT (1u << 1u) /* Request has been sent via milter */