From e075ffc9a7e9832775e84894d83dcd09b8d9be53 Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Sat, 16 Dec 1995 09:45:17 +0000 Subject: [PATCH] 1) Fix local_passwd to co-operate with dual-personality crypt(3). Changing a local passwd will now keep the encryption type that was originally used to encrypt the password, so folks adding DES to their systems will not be irritated/confused by having MD5'ed passwords in their master.passwd. Coming later is an option to allow the user to choose the encryption type. 2) Fix a bunch of compiler warnings announced by turning on -Wall. I did not get them all, that will come a bit later. --- usr.bin/passwd/local_passwd.c | 22 +++++++++++++++++----- usr.bin/passwd/passwd.c | 11 ++++++++--- usr.bin/passwd/yp_passwd.c | 3 +-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/usr.bin/passwd/local_passwd.c b/usr.bin/passwd/local_passwd.c index b98bba3f30f..aefd9afbede 100644 --- a/usr.bin/passwd/local_passwd.c +++ b/usr.bin/passwd/local_passwd.c @@ -29,10 +29,12 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id$ */ #ifndef lint -static char sccsid[] = "@(#)local_passwd.c 8.3 (Berkeley) 4/2/94"; +static const char sccsid[] = "@(#)local_passwd.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #include @@ -124,11 +126,21 @@ getnewpasswd(pw, nis) salt[9] = '\0'; #else /* Make a good size salt for algoritms that can use it. */ - to64(&salt[0], random(), 3); gettimeofday(&tv,0); - to64(&salt[3], tv.tv_usec, 3); - to64(&salt[6], tv.tv_sec, 2); - salt[8] = '\0'; + if (strncmp(pw->pw_passwd, "$1$", 3)) { + /* DES Salt */ + to64(&salt[0], random(), 3); + to64(&salt[3], tv.tv_usec, 3); + to64(&salt[6], tv.tv_sec, 2); + salt[8] = '\0'; + } + else { + /* MD5 Salt */ + strncpy(&salt[0], "$1$", 3); + to64(&salt[3], random(), 3); + to64(&salt[6], tv.tv_usec, 3); + salt[8] = '\0'; + } #endif return (crypt(buf, salt)); } diff --git a/usr.bin/passwd/passwd.c b/usr.bin/passwd/passwd.c index 31e005d3572..92dd895ea64 100644 --- a/usr.bin/passwd/passwd.c +++ b/usr.bin/passwd/passwd.c @@ -29,18 +29,21 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $id$ + * */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1988, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "From: @(#)passwd.c 8.3 (Berkeley) 4/2/94"; +static const char sccsid[] = "From: @(#)passwd.c 8.3 (Berkeley) 4/2/94"; static const char rcsid[] = - "$Id: passwd.c,v 1.5 1995/08/13 16:07:35 wpaul Exp $"; + "$Id$"; #endif /* not lint */ #include @@ -48,12 +51,14 @@ static const char rcsid[] = #include #include #include +#include #ifdef YP #include #include char *prog_name; int __use_yp = 0; +int yp_passwd(char *user); #endif #ifdef KERBEROS diff --git a/usr.bin/passwd/yp_passwd.c b/usr.bin/passwd/yp_passwd.c index 86811e378f2..fc6b0e4cbad 100644 --- a/usr.bin/passwd/yp_passwd.c +++ b/usr.bin/passwd/yp_passwd.c @@ -91,7 +91,7 @@ yp_passwd(char *user) struct passwd *pw; CLIENT *clnt; char *master; - int c, err, status; + int err, status; char *s; if ((master = getserver()) == NULL) { @@ -136,7 +136,6 @@ yp_passwd(char *user) /* Get old password */ if(pw->pw_passwd[0]) { - char prompt[40]; s = getpass ("Old password: "); if( strcmp(crypt(s, pw->pw_passwd), pw->pw_passwd)) {