From 28e33dbb3b8ea33b80539162edb14bb0b41c6b6f Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 12 Jan 2005 03:35:34 +0000 Subject: [PATCH] Use pw_gensalt() instead of using the cipher functions directly. Simplifies the code a lot. --- usr.bin/pwhash/Makefile | 3 +-- usr.bin/pwhash/pwhash.c | 40 ++++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/usr.bin/pwhash/Makefile b/usr.bin/pwhash/Makefile index 2eba80ebb720..9ad6bb94b447 100644 --- a/usr.bin/pwhash/Makefile +++ b/usr.bin/pwhash/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 2005/01/12 01:21:14 christos Exp $ +# $NetBSD: Makefile,v 1.5 2005/01/12 03:35:34 christos Exp $ # from: @(#)Makefile 8.3 (Berkeley) 4/2/94 .include @@ -6,7 +6,6 @@ PROG= pwhash CPPFLAGS+=-I${.CURDIR} -DLOGIN_CAP -CPPFLAGS+= -I${.CURDIR}/../../lib/libcrypt DPADD+= ${LIBCRYPT} ${LIBUTIL} LDADD+= -lcrypt -lutil diff --git a/usr.bin/pwhash/pwhash.c b/usr.bin/pwhash/pwhash.c index 87bdb2e103c2..3f7ee262f3d0 100644 --- a/usr.bin/pwhash/pwhash.c +++ b/usr.bin/pwhash/pwhash.c @@ -1,4 +1,4 @@ -/* $NetBSD: pwhash.c,v 1.10 2005/01/11 22:56:19 christos Exp $ */ +/* $NetBSD: pwhash.c,v 1.11 2005/01/12 03:35:34 christos Exp $ */ /* $OpenBSD: encrypt.c,v 1.16 2002/02/16 21:27:45 millert Exp $ */ /* @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: pwhash.c,v 1.10 2005/01/11 22:56:19 christos Exp $"); +__RCSID("$NetBSD: pwhash.c,v 1.11 2005/01/12 03:35:34 christos Exp $"); #endif #include @@ -40,9 +40,9 @@ __RCSID("$NetBSD: pwhash.c,v 1.10 2005/01/11 22:56:19 christos Exp $"); #include #include #include +#include #include - -#include +#include /* * Very simple little program, for encrypting passwords from the command @@ -83,11 +83,12 @@ trim(char *line) } static void -print_passwd(char *string, int operation, void *extra) +print_passwd(char *string, int operation, const char *extra) { - char msalt[3], *salt; - struct passwd pwd; + char msalt[3]; + const char *salt; char buf[_PASSWORD_LEN]; + char option[LINE_MAX], *key, *opt; int error; salt = buf; @@ -107,15 +108,18 @@ print_passwd(char *string, int operation, void *extra) break; case DO_MD5: - error = __gensalt_md5(buf, sizeof(buf), *(int *)extra); + error = pw_gensalt(buf, _PASSWORD_LEN, "md5", NULL); + salt = buf; break; case DO_SHA1: - error = __gensalt_sha1(buf, sizeof(buf), *(int *)extra); + error = pw_gensalt(buf, _PASSWORD_LEN, "sha1", NULL); + salt = buf; break; case DO_BLF: - error = __gensalt_blowfish(buf, sizeof(buf), *(int *)extra); + error = pw_gensalt(buf, _PASSWORD_LEN, "blowfish", NULL); + salt = buf; break; case DO_DES: @@ -124,8 +128,10 @@ print_passwd(char *string, int operation, void *extra) break; default: - pwd.pw_name = "default"; - error = pw_gensalt(buf, _PASSWORD_LEN, &pwd, 'l'); + pw_getconf(option, sizeof(option), "default", "localcipher"); + opt = option; + key = strsep(&opt, ","); + error = pw_gensalt(buf, _PASSWORD_LEN, key, opt); salt = buf; break; } @@ -142,8 +148,7 @@ main(int argc, char **argv) int opt; int operation = -1; int prompt = 0; - int rounds; - void *extra; /* Store salt or number of rounds */ + char *extra; /* Store salt or number of rounds */ setprogname(argv[0]); @@ -162,6 +167,7 @@ main(int argc, char **argv) if (operation != -1) usage(); operation = DO_MD5; + extra = NULL; break; case 'p': @@ -174,8 +180,7 @@ main(int argc, char **argv) if (operation != -1) usage(); operation = DO_SHA1; - rounds = atoi(optarg); - extra = &rounds; + extra = optarg; break; case 's': /* Unix crypt (DES) */ @@ -189,8 +194,7 @@ main(int argc, char **argv) if (operation != -1) usage(); operation = DO_BLF; - rounds = atoi(optarg); - extra = &rounds; + extra = optarg; break; default: