]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: Inject category=auth into log_debug when auth_debug=yes
authorMarco Bettini <marco.bettini@open-xchange.com>
Thu, 30 Jun 2022 14:05:26 +0000 (14:05 +0000)
committerMarco Bettini <marco.bettini@open-xchange.com>
Fri, 22 Jul 2022 07:07:09 +0000 (07:07 +0000)
Restores the (deprecated) behavior for auth_debug=yes to before
d49f5b30. Note that module loading debug lines will NOT appear anymore.

src/config/config-parser.c
src/config/old-set-parser.c
src/config/old-set-parser.h

index e555767093195314598f1ad3a896e407fb8aded2..a81a98b9de02090c1908e0b163b4cc098d8a1801 100644 (file)
@@ -1089,6 +1089,7 @@ prevfile:
        if (line == NULL && ctx.cur_input != NULL)
                goto prevfile;
 
+       old_settings_handle_post(&ctx);
        hash_table_destroy(&ctx.seen_settings);
        str_free(&full_line);
        if (ret == 0)
index 6d8399cd6426024b0a44bbfc4a9299ae1474da9a..8a920d09b40eb8468ba75cf52e31257ba178f901 100644 (file)
@@ -5,10 +5,12 @@
 #include "settings-parser.h"
 #include "config-parser-private.h"
 #include "old-set-parser.h"
+#include "event-filter.h"
 #include "istream.h"
 #include "base64.h"
 #include <stdio.h>
 
+#define LOG_DEBUG_KEY "log_debug"
 #define config_apply_line (void)config_apply_line
 
 struct socket_set {
@@ -18,12 +20,14 @@ struct socket_set {
 
 struct old_set_parser {
        const char *base_dir;
+       const char *post_log_debug;
        /* 1 when in auth {} section, >1 when inside auth { .. { .. } } */
        unsigned int auth_section;
        /* 1 when in socket listen {}, >1 when inside more of its sections */
        unsigned int socket_listen_section;
-       bool seen_auth_section;
        struct socket_set socket_set;
+       bool seen_auth_section:1;
+       bool post_auth_debug:1;
 };
 
 static const struct config_filter any_filter = {
@@ -289,8 +293,19 @@ old_settings_handle_root(struct config_parser_context *ctx,
                return TRUE;
        }
        if (strcmp(key, "auth_debug") == 0) {
-               obsolete(ctx, "%s will be removed in a future version, consider using log_debug = \"category=auth\" instead", key);
-               return TRUE;
+               const char *error ATTR_UNUSED;
+               bool auth_debug;
+               if (settings_get_bool(value, &auth_debug, &error) == 0 &&
+                   auth_debug)
+                       ctx->old->post_auth_debug = auth_debug;
+               obsolete(ctx, "%s will be removed in a future version%s",
+                        key, ctx->old->post_auth_debug ?
+                               ", consider using log_debug = \"category=auth\" instead" : "");
+               return TRUE;
+       }
+       if (strcmp(key, LOG_DEBUG_KEY) == 0) {
+               ctx->old->post_log_debug = p_strdup(ctx->pool, value);
+               return FALSE;
        }
        if (strcmp(key, "login_access_sockets") == 0) {
                if (value != NULL && *value != '\0')
@@ -761,6 +776,48 @@ bool old_settings_handle(struct config_parser_context *ctx,
        return FALSE;
 }
 
+static void old_settings_handle_post_log_debug(struct config_parser_context *ctx)
+{
+       static const char *category_auth = "category=auth";
+       const char *error ATTR_UNUSED;
+       const char *prev = ctx->old->post_log_debug;
+
+       if (!ctx->old->post_auth_debug)
+               return;
+
+       if (prev == NULL || *prev == '\0') {
+               config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
+                                        LOG_DEBUG_KEY, category_auth);
+               return;
+       }
+
+       struct event_filter *filter = event_filter_create();
+       if (event_filter_parse(prev, filter, &error) != 0) {
+               /* ignore, it will be handled later when actually
+                  parsing/applying the configuration */
+               event_filter_unref(&filter);
+               return;
+       }
+
+       struct event_filter *auth_filter = event_filter_create();
+       if (event_filter_parse(category_auth, auth_filter, &error) != 0)
+               i_unreached();
+
+       string_t *merged = t_str_new(128);
+       event_filter_merge(auth_filter, filter);
+       event_filter_export(filter, merged);
+       event_filter_unref(&auth_filter);
+       event_filter_unref(&filter);
+
+       config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
+                                LOG_DEBUG_KEY, str_c(merged));
+}
+
+void old_settings_handle_post(struct config_parser_context *ctx)
+{
+       old_settings_handle_post_log_debug(ctx);
+}
+
 void old_settings_init(struct config_parser_context *ctx)
 {
        ctx->old = p_new(ctx->pool, struct old_set_parser, 1);
index ce136cbc48f988223aff68a28ca5c233140fd378..c21be969661c4b37d85f2aee6f0c39a7ff78dcc3 100644 (file)
@@ -8,6 +8,7 @@ struct config_parser_context;
 bool old_settings_handle(struct config_parser_context *ctx,
                         enum config_line_type type,
                         const char *key, const char *value);
+void old_settings_handle_post(struct config_parser_context *ctx);
 void old_settings_init(struct config_parser_context *ctx);
 void old_settings_deinit_global(void);