comparison src/plugins/mail-crypt/doveadm-mail-crypt.c @ 22592:8dc7e629897a

doveadm-mail-crypt: Print existing folder key hash when aborting generate
author Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
date Fri, 06 Oct 2017 12:47:06 +0300
parents dafc46a5c6e5
children ec7c7ceca87b
comparison
equal deleted inserted replaced
22591:dafc46a5c6e5 22592:8dc7e629897a
249 struct mailbox_transaction_context *t = 249 struct mailbox_transaction_context *t =
250 mailbox_transaction_begin(box, 0); 250 mailbox_transaction_begin(box, 0);
251 251
252 if ((ret = mail_crypt_box_get_public_key(t, &pair.pub, error_r)) < 0) { 252 if ((ret = mail_crypt_box_get_public_key(t, &pair.pub, error_r)) < 0) {
253 ret = -1; 253 ret = -1;
254 } else if (ret == 1 && (!ctx->force || ctx->recrypt_box_keys)) { 254 } else if (ret == 1 && !ctx->force) {
255 i_info("Folder key exists. Use -f to generate a new one");
256 buffer_t *key_id = t_str_new(MAIL_CRYPT_HASH_BUF_SIZE);
257 const char *error;
258 if (!dcrypt_key_id_public(pair.pub,
259 MAIL_CRYPT_KEY_ID_ALGORITHM,
260 key_id, &error)) {
261 i_error("dcrypt_key_id_public() failed: %s",
262 error);
263 return -1;
264 }
265 *pubid_r = p_strdup(ctx->ctx.pool, binary_to_hex(key_id->data,
266 key_id->used));
267 *pair_r = pair;
268 return 1;
269 } else if (ret == 1 && ctx->recrypt_box_keys) {
255 /* do nothing, because force isn't being used *OR* 270 /* do nothing, because force isn't being used *OR*
256 we are recrypting box keys and force refers to 271 we are recrypting box keys and force refers to
257 user keypair. 272 user keypair.
258 273
259 FIXME: this could be less confusing altogether */ 274 FIXME: this could be less confusing altogether */
411 res->success = TRUE; 426 res->success = TRUE;
412 res->id = pubid; 427 res->id = pubid;
413 T_BEGIN { 428 T_BEGIN {
414 mcp_update_shared_keys(box, user, pubid, pair.priv); 429 mcp_update_shared_keys(box, user, pubid, pair.priv);
415 } T_END; 430 } T_END;
416 dcrypt_keypair_unref(&pair); 431 if (pair.pub != NULL)
432 dcrypt_key_unref_public(&pair.pub);
433 if (pair.priv != NULL)
434 dcrypt_key_unref_private(&pair.priv);
417 ctx->matched_keys++; 435 ctx->matched_keys++;
418 } 436 }
419 mailbox_free(&box); 437 mailbox_free(&box);
420 } 438 }
421 439