From: Marco Bettini Date: Tue, 28 Feb 2023 16:49:53 +0000 (+0000) Subject: mail-crypt: Move doveadm_print_init/header() eariler X-Git-Tag: 2.4.0~2946 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1994055742c5a03dd7650e8c026e1128a2e95e0;p=thirdparty%2Fdovecot%2Fcore.git mail-crypt: Move doveadm_print_init/header() eariler Otherwise the newly introduced checks trigger faults --- diff --git a/src/plugins/mail-crypt/doveadm-mail-crypt.c b/src/plugins/mail-crypt/doveadm-mail-crypt.c index 23c4d86950..81d77cfcb0 100644 --- a/src/plugins/mail-crypt/doveadm-mail-crypt.c +++ b/src/plugins/mail-crypt/doveadm-mail-crypt.c @@ -446,6 +446,14 @@ static int mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx, return 0; } +static void +cmd_mcp_keypair_generate_init(struct doveadm_mail_cmd_context *ctx ATTR_UNUSED) +{ + doveadm_print_header("success", " ", 0); + doveadm_print_header("box", "Folder", 0); + doveadm_print_header("pubid", "Public ID", 0); +} + static int cmd_mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) { @@ -466,11 +474,6 @@ static int cmd_mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx, if (mcp_keypair_generate_run(_ctx, user, &result) < 0) _ctx->exit_code = EX_DATAERR; - doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); - doveadm_print_header("success", " ", 0); - doveadm_print_header("box", "Folder", 0); - doveadm_print_header("pubid", "Public ID", 0); - const struct generated_key *res; array_foreach(&result, res) { @@ -620,6 +623,14 @@ static void cmd_mcp_key_list_cb(const struct generated_key *_key, void *context) key->active = _key->active; } +static void +cmd_mcp_key_list_init(struct doveadm_mail_cmd_context *_ctx ATTR_UNUSED) +{ + doveadm_print_header("box", "Folder", 0); + doveadm_print_header("active", "Active", 0); + doveadm_print_header("pubid", "Public ID", 0); +} + static int cmd_mcp_key_list_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) { @@ -637,11 +648,6 @@ static int cmd_mcp_key_list_run(struct doveadm_mail_cmd_context *_ctx, mcp_key_list(ctx, user, cmd_mcp_key_list_cb, &iter_ctx); - doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); - doveadm_print_header("box", "Folder", 0); - doveadm_print_header("active", "Active", 0); - doveadm_print_header("pubid", "Public ID", 0); - const struct generated_key *key; array_foreach(&iter_ctx.keys, key) { doveadm_print(key->name); @@ -691,6 +697,14 @@ static void cmd_mcp_key_export_cb(const struct generated_key *key, dcrypt_key_unref_private(&pkey); } } +static void +cmd_mcp_key_export_init(struct doveadm_mail_cmd_context *_ctx ATTR_UNUSED) +{ + doveadm_print_header("box", "Folder", 0); + doveadm_print_header("name", "Public ID", 0); + doveadm_print_header("error", "Error", 0); + doveadm_print_header("key", "Key", 0); +} static int cmd_mcp_key_export_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) @@ -702,17 +716,17 @@ static int cmd_mcp_key_export_run(struct doveadm_mail_cmd_context *_ctx, ctx->userkey_only = doveadm_cmd_param_flag(cctx, "user-key"); (void)doveadm_cmd_param_str(cctx, "mailbox", &ctx->mailbox); - doveadm_print_init(DOVEADM_PRINT_TYPE_PAGER); - doveadm_print_header("box", "Folder", 0); - doveadm_print_header("name", "Public ID", 0); - doveadm_print_header("error", "Error", 0); - doveadm_print_header("key", "Key", 0); - mcp_key_list(ctx, user, cmd_mcp_key_export_cb, NULL); return 0; } +static void +cmd_mcp_key_password_init(struct doveadm_mail_cmd_context *_ctx ATTR_UNUSED) +{ + doveadm_print_header_simple("result"); +} + static int cmd_mcp_key_password_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) { @@ -736,10 +750,6 @@ static int cmd_mcp_key_password_run(struct doveadm_mail_cmd_context *_ctx, ARRAY(struct raw_key) raw_keys; - doveadm_print_init(DOVEADM_PRINT_TYPE_PAGER); - - doveadm_print_header_simple("result"); - if (ctx->ask_old_password) { if (ctx->old_password != NULL) { doveadm_print("old password specified, cannot ask for it"); @@ -913,6 +923,8 @@ static struct doveadm_mail_cmd_context *cmd_mcp_keypair_generate_alloc(void) ctx = doveadm_mail_cmd_alloc(struct mcp_cmd_context); ctx->ctx.v.run = cmd_mcp_keypair_generate_run; + ctx->ctx.v.init = cmd_mcp_keypair_generate_init; + doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); return &ctx->ctx; } @@ -922,6 +934,8 @@ static struct doveadm_mail_cmd_context *cmd_mcp_key_list_alloc(void) ctx = doveadm_mail_cmd_alloc(struct mcp_cmd_context); ctx->ctx.v.run = cmd_mcp_key_list_run; + ctx->ctx.v.init = cmd_mcp_key_list_init; + doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); return &ctx->ctx; } @@ -931,6 +945,8 @@ static struct doveadm_mail_cmd_context *cmd_mcp_key_export_alloc(void) ctx = doveadm_mail_cmd_alloc(struct mcp_cmd_context); ctx->ctx.v.run = cmd_mcp_key_export_run; + ctx->ctx.v.init = cmd_mcp_key_export_init; + doveadm_print_init(DOVEADM_PRINT_TYPE_PAGER); return &ctx->ctx; } @@ -940,6 +956,8 @@ static struct doveadm_mail_cmd_context *cmd_mcp_key_password_alloc(void) ctx = doveadm_mail_cmd_alloc(struct mcp_cmd_context); ctx->ctx.v.run = cmd_mcp_key_password_run; + ctx->ctx.v.init = cmd_mcp_key_password_init; + doveadm_print_init(DOVEADM_PRINT_TYPE_PAGER); return &ctx->ctx; }