]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Try to fix the mess with read only flag
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 25 Jul 2022 21:18:32 +0000 (22:18 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 25 Jul 2022 22:17:44 +0000 (23:17 +0100)
Issue: #4219

src/controller.c
src/libserver/worker_util.h

index d199b88bcf67b6a2225dbe1dad4d492b6f49e1b2..765aa16239dc913452bc1f514f24f2bf6ccd29f9 100644 (file)
@@ -515,19 +515,22 @@ rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
                use_enable = FALSE;
        const struct rspamd_controller_pbkdf *pbkdf = NULL;
 
+       /* Fail-safety */
+       session->is_read_only = TRUE;
+
        /* Access list logic */
        if (rspamd_inet_address_get_af (session->from_addr) == AF_UNIX) {
                ret = rspamd_controller_check_forwarded (session, msg, ctx);
 
                if (ret == 1) {
-                       session->is_enable = TRUE;
+                       session->is_read_only = FALSE;
 
                        return TRUE;
                }
                else if (ret == 0) {
                        /* No forwarded found */
                        msg_info_session ("allow unauthorized connection from a unix socket");
-                       session->is_enable = TRUE;
+                       session->is_read_only = FALSE;
 
                        return TRUE;
                }
@@ -538,7 +541,7 @@ rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
                ret = rspamd_controller_check_forwarded (session, msg, ctx);
 
                if (ret == 1) {
-                       session->is_enable = TRUE;
+                       session->is_read_only = FALSE;
 
                        return TRUE;
                }
@@ -546,7 +549,7 @@ rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
                        /* No forwarded found */
                        msg_info_session ("allow unauthorized connection from a trusted IP %s",
                                                        rspamd_inet_address_to_string (session->from_addr));
-                       session->is_enable = TRUE;
+                       session->is_read_only = FALSE;
 
                        return TRUE;
                }
@@ -572,7 +575,7 @@ rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
                        }
                        else if (is_enable && (ctx->password == NULL &&
                                        ctx->enable_password == NULL)) {
-                               session->is_enable = TRUE;
+                               session->is_read_only = FALSE;
                                return TRUE;
                        }
                }
@@ -625,7 +628,7 @@ rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
                        }
 
                        if (ret) {
-                               session->is_enable = TRUE;
+                               session->is_read_only = FALSE;
                        }
                }
                else {
@@ -648,6 +651,13 @@ rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
                                                        check, pbkdf, FALSE);
                                }
 
+                               if (check_normal) {
+                                       if (ctx->enable_password == NULL) {
+                                               /* We have passed password check and no enable password is specified (*/
+                                               session->is_read_only = FALSE;
+                                       }
+                               }
+
                        }
                        else {
                                check_normal = FALSE;
@@ -674,6 +684,11 @@ rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
                        else {
                                check_enable = FALSE;
                        }
+
+                       if (check_enable) {
+                               /* We have passed enable password check, not a read-only mode */
+                               session->is_read_only = FALSE;
+                       }
                }
        }
 
@@ -749,7 +764,7 @@ rspamd_controller_handle_auth (struct rspamd_http_connection_entry *conn_ent,
                        st.messages_scanned), "scanned",  0, false);
        ucl_object_insert_key (obj,        ucl_object_fromint (
                        st.messages_learned), "learned",  0, false);
-       ucl_object_insert_key (obj, ucl_object_frombool (!session->is_enable),
+       ucl_object_insert_key (obj, ucl_object_frombool (session->is_read_only),
                        "read_only", 0, false);
        ucl_object_insert_key (obj, ucl_object_fromstring (session->ctx->cfg->checksum),
                        "config_id", 0, false);
@@ -2665,7 +2680,7 @@ rspamd_controller_handle_stat_common (
        uptime = ev_time () - session->ctx->start_time;
        ucl_object_insert_key (top, ucl_object_fromint (
                        uptime), "uptime", 0, false);
-       ucl_object_insert_key (top, ucl_object_frombool (!session->is_enable),
+       ucl_object_insert_key (top, ucl_object_frombool (session->is_read_only),
                        "read_only", 0, false);
        ucl_object_insert_key (top, ucl_object_fromint (
                        stat->messages_scanned), "scanned", 0, false);
@@ -3106,7 +3121,7 @@ rspamd_controller_handle_metrics_common (
                        uptime), "uptime", 0, false);
        ucl_object_insert_key (top, ucl_object_fromint (
                        session->ctx->start_time), "start_time", 0, false);
-       ucl_object_insert_key (top, ucl_object_frombool (!session->is_enable),
+       ucl_object_insert_key (top, ucl_object_frombool (session->is_read_only),
                        "read_only", 0, false);
        ucl_object_insert_key (top, ucl_object_fromint (
                        stat->messages_scanned), "scanned", 0, false);
index 12f73aa4ca7d338cde3c09bf7e12a04ad536a0bc..ed7ada3d307699440f381e20c3580aa3c49cce5c 100644 (file)
@@ -106,7 +106,7 @@ struct rspamd_controller_session {
        struct rspamd_config *cfg;
        struct rspamd_lang_detector *lang_det;
        gboolean is_spam;
-       gboolean is_enable;
+       gboolean is_read_only;
 };
 
 /**