From 8b6b7405d3844271f7bff56e527bfeb1a4872975 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Thu, 11 Mar 2010 11:15:36 +0000 Subject: Document the new -x flag in one useful location and make it a bit better at argument checking to avoid ugly (even though harmless) segfaults. Also skip any md5: prefix that may be present when checking hashes. --- unix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'unix.c') diff --git a/unix.c b/unix.c index 00bea6c8..7088d0f8 100644 --- a/unix.c +++ b/unix.c @@ -172,7 +172,8 @@ static int crypt_main( int argc, char *argv[] ) int pass_len; unsigned char *pass_cr, *pass_cl; - if( argc < 3 ) + if( argc < 4 || ( strcmp( argv[2], "hash" ) != 0 && + strcmp( argv[2], "unhash" ) != 0 && argc < 5 ) ) { printf( "Supported:\n" " %s -x enc \n" @@ -213,7 +214,8 @@ static int crypt_main( int argc, char *argv[] ) } else if( strcmp( argv[2], "chkhash" ) == 0 ) { - int st = md5_verify_password( argv[4], argv[3] ); + char *hash = strncmp( argv[3], "md5:", 4 ) == 0 ? argv[3] + 4 : argv[3]; + int st = md5_verify_password( argv[4], hash ); printf( "Hash %s given password.\n", st == 0 ? "matches" : "does not match" ); -- cgit v1.2.3