]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Panic if doveadm_print_header() is called too late
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 24 Feb 2023 14:39:14 +0000 (16:39 +0200)
committerMarco Bettini <marco.bettini@open-xchange.com>
Thu, 9 Mar 2023 12:32:39 +0000 (12:32 +0000)
Otherwise it's not noticed unless the doveadm command is called for multiple
users (-A, -F).

src/doveadm/doveadm-mail.c
src/doveadm/doveadm-print.c
src/doveadm/doveadm-print.h

index 82a07012f4553ecff97a710cb0014898116e2356..e524f378e6856711aa0caf4014bf1ec797eb1106 100644 (file)
@@ -509,6 +509,7 @@ int doveadm_mail_single_user(struct doveadm_mail_cmd_context *ctx,
        T_BEGIN {
                ctx->v.init(ctx);
        } T_END;
+       doveadm_print_header_disallow(TRUE);
        if (hook_doveadm_mail_init != NULL)
                hook_doveadm_mail_init(ctx);
 
@@ -533,6 +534,7 @@ doveadm_mail_all_users(struct doveadm_mail_cmd_context *ctx,
        T_BEGIN {
                ctx->v.init(ctx);
        } T_END;
+       doveadm_print_header_disallow(TRUE);
 
        if (wildcard_user != NULL) {
                mail_storage_service_all_init_mask(ctx->storage_service,
index 70e9ae11d2e9ea62d18d1b8bd14e10da230e340b..7cad3265ca3b2589c1767ac74afd2d23cb26fcfd 100644 (file)
@@ -26,6 +26,7 @@ struct ostream *doveadm_print_ostream = NULL;
 
 static struct doveadm_print_context *ctx;
 static bool doveadm_print_init_disallowed = FALSE;
+static bool doveadm_print_header_disallowed = FALSE;
 
 bool doveadm_print_is_initialized(void)
 {
@@ -40,6 +41,9 @@ void doveadm_print_header(const char *key, const char *title,
 
        i_assert(title != NULL);
 
+       if (doveadm_print_header_disallowed)
+               i_panic("doveadm_print_header() is called in wrong place");
+
        i_zero(&hdr);
        hdr.key = key;
        hdr.title = title;
@@ -203,9 +207,15 @@ void doveadm_print_deinit(void)
        ctx = NULL;
 
        doveadm_print_init_disallowed = FALSE;
+       doveadm_print_header_disallowed = FALSE;
 }
 
 void doveadm_print_init_disallow(bool disallow)
 {
        doveadm_print_init_disallowed = disallow;
 }
+
+void doveadm_print_header_disallow(bool disallow)
+{
+       doveadm_print_header_disallowed = disallow;
+}
index 7edbe73c0dea1b345e10c68f8adc22e23d1e9177..81509ac70d887305795b45b88886b468bbfa8f0e 100644 (file)
@@ -47,6 +47,9 @@ void doveadm_print_deinit(void);
 /* Panic if doveadm_print_init() is attempted to be called. This is reset also
    by doveadm_print_deinit(). */
 void doveadm_print_init_disallow(bool disallow);
+/* Panic is doveadm_print_header*() is attempted to be called. This is reset
+   also by doveadm_print_deinit(). */
+void doveadm_print_header_disallow(bool disallow);
 
 void doveadm_print_formatted_set_format(const char *format);