From root@visi.gothic.net.au  Thu Jun 27 03:03:38 2002
Return-Path: <root@visi.gothic.net.au>
Received: from visi.gothic.net.au (visi.gothic.net.au [202.182.69.51])
	by hub.freebsd.org (Postfix) with ESMTP id B49D637B406
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Jun 2002 03:03:37 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1])
	by visi.gothic.net.au (Postfix) with ESMTP id DAAF9A6A81
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Jun 2002 20:03:35 +1000 (EST)
Received: by visi.gothic.net.au (Postfix, from userid 0)
	id C6CBAA6A01; Thu, 27 Jun 2002 20:03:30 +1000 (EST)
Message-Id: <20020627100330.C6CBAA6A01@visi.gothic.net.au>
Date: Thu, 27 Jun 2002 20:03:30 +1000 (EST)
From: Sean Winn <sean@gothic.net.au>
Reply-To: Sean Winn <sean@gothic.net.au>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: chpass no longer edits existing entries
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         39919
>Category:       bin
>Synopsis:       chpass no longer edits existing entries
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    cjc
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 27 03:10:01 PDT 2002
>Closed-Date:    Thu Jul 11 22:35:32 PDT 2002
>Last-Modified:  Thu Jul 11 22:35:32 PDT 2002
>Originator:     Sean Winn
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
>Environment:
System: FreeBSD visi.gothic.net.au 4.6-STABLE FreeBSD 4.6-STABLE #0: Tue Jun 25 01:04:00 EST 2002 sean@visi.gothic.net.au:/usr/obj/usr/src/sys/VISI i386


>Description:

chpass has the ability to replace entire password file entries as
the super user, which is great for scripts - they grab the existing
password file entry, change as needed, then hand off to chpass to do the
ugly copy/update/pwd_mkdb work. This worked fine for 4.5, but fails under
4.6R

In change 1.9.2.2 of usr.bin/chpass/pw_copy.c, internal consistency checks
were added to the copy loop; this relies on old_pw being set correctly in
chpass.c; however, chpass.c does not initialise old_pw in all circumstances
- the 'a' case specifically ('a' is considered LOADENTRY, and LOADENTRY
doen't need to load an old entry - we're replacing unconditionally). This
doesn't stop pw_copy being called with an uninitialised old_pw though, and
the consistency checks fail.


>How-To-Repeat:

19:44 root@visi [~] grep mysql /etc/master.passwd
mysql:*:88:88::0:0:MySQL Daemon:/var/db/mysql:/sbin/nologin
19:44 root@visi [~] chpass -a 'mysql:*:88:88::0:0:MySQL Daemon:/var/db/mysql:/sbin/nologin'
chpass: /etc/master.passwd: entry inconsistent
chpass: /etc/master.passwd: unchanged
>Fix:

--- usr.bin/chpass/chpass.c.orig        Thu Jun 27 19:58:35 2002
+++ usr.bin/chpass/chpass.c     Thu Jun 27 20:00:05 2002
@@ -268,7 +268,7 @@
        } else {
 #endif /* YP */
        pfd = pw_lock();
-       pw_copy(pfd, tfd, pw, &old_pw);
+       pw_copy(pfd, tfd, pw, (op == LOADENTRY)? NULL : &old_pw );

        if (!pw_mkdb(username))
                pw_error((char *)NULL, 0, 1);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->cjc 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Sat Jul 6 13:16:20 PDT 2002 
Responsible-Changed-Why:  

Over to the author of that revision of pw_copy.c

http://www.freebsd.org/cgi/query-pr.cgi?pr=39919 

From: "Crist J. Clark" <crist.clark@attbi.com>
To: Doug Barton <dougb@freebsd.org>
Cc: freebsd-bugs@freebsd.org
Subject: Re: bin/39919: chpass no longer edits existing entries
Date: Thu, 11 Jul 2002 12:31:50 -0700

 The included patch fixes your problem, but leaves you open to
 locking problems. You need to load any existing password entry into
 old_pw.
 -- 
 Crist J. Clark                     |     cjclark@alum.mit.edu
                                    |     cjclark@jhu.edu
 http://people.freebsd.org/~cjc/    |     cjc@freebsd.org

From: "Crist J. Clark" <crist.clark@attbi.com>
To: Doug Barton <dougb@freebsd.org>
Cc: freebsd-bugs@freebsd.org
Subject: Re: bin/39919: chpass no longer edits existing entries
Date: Thu, 11 Jul 2002 12:50:12 -0700

 How does this patch look?
 
 Index: chpass.c
 ===================================================================
 RCS file: /export/freebsd/ncvs/src/usr.bin/chpass/chpass.c,v
 retrieving revision 1.16.2.2
 diff -u -r1.16.2.2 chpass.c
 --- chpass.c	24 Mar 2002 09:00:03 -0000	1.16.2.2
 +++ chpass.c	11 Jul 2002 19:45:28 -0000
 @@ -40,7 +40,7 @@
  #ifndef lint
  static const char sccsid[] = "From: @(#)chpass.c	8.4 (Berkeley) 4/2/94";
  static const char rcsid[] =
 -  "$FreeBSD: src/usr.bin/chpass/chpass.c,v 1.16.2.2 2002/03/24 09:00:03 cjc Exp $";
 +  "$FreeBSD: src/usr.bin/chpass/chpass.c,v 1.16.2.2 2002/03/24 05:35:51 cjc Exp $";
  #endif /* not lint */
  
  #include <sys/param.h>
 @@ -83,7 +83,7 @@
  	char **argv;
  {
  	enum { NEWSH, LOADENTRY, EDITENTRY, NEWPW, NEWEXP } op;
 -	struct passwd *pw = NULL, lpw, old_pw;
 +	struct passwd *pw = NULL, lpw, old_pw, *pold_pw;
  	char *username = NULL;
  	int ch, pfd, tfd;
  	char *arg = NULL;
 @@ -190,6 +190,7 @@
  		/* Make a copy for later verification */
  		old_pw = *pw;
  		old_pw.pw_gecos = strdup(old_pw.pw_gecos);
 +		pold_pw = &old_pw;
  	}
  
  	if (op == NEWSH) {
 @@ -213,6 +214,10 @@
  		pw = &lpw;
  		if (!pw_scan(arg, pw))
  			exit(1);
 +		if ((pold_pw = getpwnam(pw->pw_name)) != NULL) {
 +			old_pw = *pold_pw;
 +			old_pw.pw_gecos = strdup(old_pw.pw_gecos);
 +		}
  	}
  	username = pw->pw_name;
  
 @@ -268,7 +273,7 @@
  	} else {
  #endif /* YP */
  	pfd = pw_lock();
 -	pw_copy(pfd, tfd, pw, &old_pw);
 +	pw_copy(pfd, tfd, pw, pold_pw);
  
  	if (!pw_mkdb(username))
  		pw_error((char *)NULL, 0, 1);
 
 -- 
 Crist J. Clark                     |     cjclark@alum.mit.edu
                                    |     cjclark@jhu.edu
 http://people.freebsd.org/~cjc/    |     cjc@freebsd.org
State-Changed-From-To: open->closed 
State-Changed-By: cjc 
State-Changed-When: Thu Jul 11 22:33:50 PDT 2002 
State-Changed-Why:  
Fixed in -STABLE. -CURRENT may have some other issues, but that's 
another issue. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=39919 
>Unformatted:
