dovecot-2.1: doveadm pw: Added -t <hash> parameter to test if a ...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Feb 12 02:22:54 EET 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/fffa4d53e901
changeset: 14110:fffa4d53e901
user: Timo Sirainen <tss at iki.fi>
date: Sun Feb 12 02:22:43 2012 +0200
description:
doveadm pw: Added -t <hash> parameter to test if a hash matches to given plaintext.
Based on patch by Jimmy Thrasibule
diffstat:
src/doveadm/doveadm-pw.c | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diffs (65 lines):
diff -r a927b41bf699 -r fffa4d53e901 src/doveadm/doveadm-pw.c
--- a/src/doveadm/doveadm-pw.c Thu Feb 09 21:29:25 2012 +0200
+++ b/src/doveadm/doveadm-pw.c Sun Feb 12 02:22:43 2012 +0200
@@ -21,6 +21,7 @@
const char *user = NULL;
const char *scheme = NULL;
const char *plaintext = NULL;
+ const char *test_hash = NULL;
bool list_schemes = FALSE, reverse_verify = FALSE;
unsigned int rounds = 0;
int c;
@@ -28,7 +29,7 @@
random_init();
password_schemes_init();
- while ((c = getopt(argc, argv, "lp:r:s:u:V")) > 0) {
+ while ((c = getopt(argc, argv, "lp:r:s:t:u:V")) > 0) {
switch (c) {
case 'l':
list_schemes = 1;
@@ -43,6 +44,10 @@
case 's':
scheme = optarg;
break;
+ case 't':
+ test_hash = optarg;
+ reverse_verify = TRUE;
+ break;
case 'u':
user = optarg;
break;
@@ -73,6 +78,8 @@
if (rounds > 0)
password_set_encryption_rounds(rounds);
+ if (test_hash != NULL)
+ plaintext = t_askpass("Enter password to verify: ");
while (plaintext == NULL) {
const char *check;
static int lives = 3;
@@ -96,6 +103,15 @@
size_t size;
const char *error;
+ if (test_hash != NULL) {
+ scheme = password_get_scheme(&test_hash);
+ if (scheme == NULL) {
+ fprintf(stderr, "Missing {scheme} prefix from hash\n");
+ exit(2);
+ }
+ hash = test_hash;
+ }
+
if (password_decode(hash, scheme, &raw_password, &size,
&error) <= 0) {
fprintf(stderr, "reverse decode check failed: %s\n",
@@ -104,7 +120,7 @@
}
if (password_verify(plaintext, user, scheme,
- raw_password, size, &error) != 1) {
+ raw_password, size, &error) <= 0) {
fprintf(stderr,
"reverse password verification check failed: %s\n", error);
exit(2);
More information about the dovecot-cvs
mailing list