From: Marco Bettini Date: Thu, 30 Jun 2022 14:05:26 +0000 (+0000) Subject: config: Inject category=auth into log_debug when auth_debug=yes X-Git-Tag: 2.4.0~3740 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dec1e939e067b35f8a2e68b39ac0d037e00a888;p=thirdparty%2Fdovecot%2Fcore.git config: Inject category=auth into log_debug when auth_debug=yes Restores the (deprecated) behavior for auth_debug=yes to before d49f5b30. Note that module loading debug lines will NOT appear anymore. --- diff --git a/src/config/config-parser.c b/src/config/config-parser.c index e555767093..a81a98b9de 100644 --- a/src/config/config-parser.c +++ b/src/config/config-parser.c @@ -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) diff --git a/src/config/old-set-parser.c b/src/config/old-set-parser.c index 6d8399cd64..8a920d09b4 100644 --- a/src/config/old-set-parser.c +++ b/src/config/old-set-parser.c @@ -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 +#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); diff --git a/src/config/old-set-parser.h b/src/config/old-set-parser.h index ce136cbc48..c21be96966 100644 --- a/src/config/old-set-parser.h +++ b/src/config/old-set-parser.h @@ -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);