#include "doveadm-print.h"
#include "hex-binary.h"
+#define DOVEADM_MCP_SUCCESS "\xE2\x9C\x93" /* emits a utf-8 CHECK MARK (U+2713) */
+#define DOVEADM_MCP_FAIL "x"
+#define DOVEADM_MCP_USERKEY "<userkey>"
+
struct generated_key {
const char *name;
const char *id;
const char *old_password;
const char *new_password;
+ unsigned int matched_keys;
+
bool userkey_only:1;
bool recrypt_box_keys:1;
bool force:1;
res->success = FALSE;
} else {
res = array_append_space(result);
- res->name = "";
+ res->name = DOVEADM_MCP_USERKEY;
res->id = p_strdup(_ctx->pool, pubid);
res->success = TRUE;
/* don't do it again later on */
dcrypt_key_unref_private(&pair.priv);
}
if (ret < 0) return ret;
+ ctx->matched_keys++;
}
if (ret == 1 && ctx->force &&
dcrypt_key_unref_public(&user_key);
/* regen user key */
res = array_append_space(result);
- res->name = "";
+ res->name = DOVEADM_MCP_USERKEY;
if (mail_crypt_user_generate_keypair(user, &pair, &pubid,
&error) < 0) {
res->success = FALSE;
res->id = p_strdup(_ctx->pool, pubid);
user_key = pair.pub;
dcrypt_key_unref_private(&pair.priv);
+ ctx->matched_keys++;
}
if (ctx->userkey_only)
mcp_update_shared_keys(box, user, pubid, pair.priv);
} T_END;
dcrypt_keypair_unref(&pair);
+ ctx->matched_keys++;
}
mailbox_free(&box);
}
static int cmd_mcp_keypair_generate_run(struct doveadm_mail_cmd_context *_ctx,
struct mail_user *user)
{
+ struct mcp_cmd_context *ctx =
+ (struct mcp_cmd_context *)_ctx;
+
int ret = 0;
ARRAY_TYPE(generated_keys) result;
array_foreach(&result, res) {
if (res->success)
- doveadm_print("\xE2\x9C\x93");
+ doveadm_print(DOVEADM_MCP_SUCCESS);
else {
_ctx->exit_code = EX_DATAERR;
ret = -1;
- doveadm_print("x");
+ doveadm_print(DOVEADM_MCP_FAIL);
}
doveadm_print(res->name);
if (!res->success)
doveadm_print(res->id);
}
+ if (ctx->matched_keys == 0)
+ i_warning("mailbox cryptokey generate: Nothing was matched. "
+ "Use -U or specify mask?");
return ret;
}
key.name = "";
key.box = box;
callback(&key, context);
+ ctx->matched_keys++;
}
if (mailbox_attribute_iter_deinit(&iter) < 0)
i_error("mailbox_attribute_iter_deinit(%s) failed: %s",
key.active = FALSE;
key.box = box;
callback(&key, context);
+ ctx->matched_keys++;
}
}
mailbox_free(&box);
doveadm_print(key->active ? "yes" : "no");
doveadm_print(key->id);
}
+
+ if (ctx->matched_keys == 0)
+ i_warning("mailbox cryptokey list: Nothing was matched. "
+ "Use -U or specify mask?");
+
return 0;
}