From yasuf@big.or.jp Mon Jul 26 19:44:09 1999
Return-Path: <yasuf@big.or.jp>
Received: from smtp.teleway.ne.jp (smtp.teleway.ne.jp [203.140.129.13])
	by hub.freebsd.org (Postfix) with ESMTP id 9AA16150D9
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Jul 1999 19:44:02 -0700 (PDT)
	(envelope-from yasuf@big.or.jp)
Received: from post1a.po.teleway.ne.jp (post1a.teleway.ne.jp [203.140.129.22])
	by smtp.teleway.ne.jp (8.9.3+3.2W/3.7W) with ESMTP id LAA01276
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 27 Jul 1999 11:44:01 +0900 (JST)
	(envelope-from yasuf@big.or.jp)
Received: from localhost ([210.234.51.51]) by post1a.po.teleway.ne.jp
          (Post.Office MTA v3.0 release "turbo_2"
          ID# 110-55583U50000L50000S0V35) with ESMTP id AAA8951
          for <FreeBSD-gnats-submit@freebsd.org>;
          Tue, 27 Jul 1999 11:43:58 +0900
Message-Id: <19990727114358W.yasuf@big.or.jp>
Date: Tue, 27 Jul 1999 11:43:58 +0900
From: yasuf@big.or.jp
Reply-To: yasuf@big.or.jp
To: FreeBSD-gnats-submit@freebsd.org
Subject: passwd(1) doesn't recognize comments
X-Send-Pr-Version: 3.2

>Number:         12828
>Category:       bin
>Synopsis:       passwd(1) doesn't recognize comments
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    sheldonh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 26 19:50:00 PDT 1999
>Closed-Date:    Thu Jul 29 09:37:46 PDT 1999
>Last-Modified:  Thu Jul 29 09:40:34 PDT 1999
>Originator:     Yasuhiro Fukuma
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
>Environment:

FreeBSD smoove.ouchi-net.jp 4.0-CURRENT FreeBSD 4.0-CURRENT #10: Sun Jul  4 13:44:45 JST 1999     yasuf@smoove.ouchi-net.jp:/usr/src/sys/compile/ARMADILLO  i386

>Description:

Passwd(5) manpage says:
|    Lines whose first non-whitespace character is a pound-sign (#) are com-
|    ments, and are ignored.  Blank lines which consist only of spaces, tabs
|    or newlines are also ignored.

but passwd(1) (, chpass(1), etc.) seems not to support these features
correctly.

>How-To-Repeat:

  # tail -3 /etc/master.passwd
  user1:*:9999:9999::0:0:some user:/home/user1:
  # comment
  user2:*:9998:9998::0:0:other user:/home/user2:

  # passwd user1
  Changing local password for user1.
  New password:
  Retype new password:
  passwd: updating the database...
  passwd: done

  # passwd user2
  Changing local password for user2.
  New password:
  Retype new password:
  passwd: /etc/master.passwd: corrupted entry
  passwd: /etc/master.passwd: unchanged

>Fix:
Index: usr.bin/chpass/pw_copy.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/chpass/pw_copy.c,v
retrieving revision 1.7
diff -u -r1.7 pw_copy.c
--- pw_copy.c	1999/04/25 22:37:56	1.7
+++ pw_copy.c	1999/07/23 04:56:26
@@ -85,6 +85,15 @@
 				goto err;
 			continue;
 		}
+		for (p = buf; *p != '\n'; p++)
+			if (*p != ' ' && *p != '\t')
+				break;
+		if (*p == '#' || *p == '\n') {
+			(void)fprintf(to, "%s", buf);
+			if (ferror(to))
+				goto err;
+			continue;
+		}
 		if (!(p = strchr(buf, ':'))) {
 			warnx("%s: corrupted entry", _PATH_MASTERPASSWD);
 			pw_error(NULL, 0, 1);

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Jul 27 02:48:34 PDT 1999 
Responsible-Changed-Why:  
You're right. vipw handles comments and blank lines correctly, but  
passwd does not. I'll take a look. 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/12828: passwd(1) doesn't recognize comments 
Date: Wed, 28 Jul 1999 13:07:52 +0200

 On Tue, 27 Jul 1999 02:49:49 MST, sheldonh@FreeBSD.org wrote:
 
 > Responsible-Changed-Why: 
 > You're right. vipw handles comments and blank lines correctly, but 
 > passwd does not. I'll take a look.
 
 Your patch works. I like the fact that you take care to maintain the
 optimization centered around (done). I'd prefer the following, though.
 Happy with it?
 
 Ciao,
 Sheldon.
 
 Index: pw_copy.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/chpass/pw_copy.c,v
 retrieving revision 1.7
 diff -u -d -r1.7 pw_copy.c
 --- pw_copy.c	1999/04/25 22:37:56	1.7
 +++ pw_copy.c	1999/07/28 11:02:37
 @@ -40,6 +40,7 @@
   * record, by chpass(1) and passwd(1).
   */
  
 +#include <ctype.h>
  #include <err.h>
  #include <pwd.h>
  #include <stdio.h>
 @@ -80,6 +81,14 @@
  			pw_error(NULL, 0, 1);
  		}
  		if (done) {
 +			(void)fprintf(to, "%s", buf);
 +			if (ferror(to))
 +				goto err;
 +			continue;
 +		}
 +		for (p = buf; isspace(*p); p++)
 +			;	/* nothing */
 +		if (*p == '#' || *p == '\0') {
  			(void)fprintf(to, "%s", buf);
  			if (ferror(to))
  				goto err;
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: freebsd-gnats-submit@freebsd.org
Cc: markm@freebsd.org
Subject: Re: bin/12828: passwd(1) doesn't recognize comments
Date: Thu, 29 Jul 1999 12:28:54 +0200

 While checking for the performance hit of my code on a 100000 entry
 passwd file, I noticed pwd_mkdb is also broken with respect to the
 passwd(5) manpage. There may be others.
 
 Expect delays, not because I'm not looking at it, but because I'd prefer
 to get everything inline at once, having done some decent testing
 and with a unified review. I don't want piecemeal commits on this if
 possible.
 
 Ciao,
 Sheldon.
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: freebsd-gnats-submit@freebsd.org
Cc: markm@freebsd.org
Subject: Re: bin/12828: passwd(1) doesn't recognize comments 
Date: Thu, 29 Jul 1999 16:22:22 +0200

 On Thu, 29 Jul 1999 12:28:54 +0200, Sheldon Hearn wrote:
 
 > While checking for the performance hit of my code on a 100000 entry
 > passwd file, [...]
 
 I must have made some peculiar mistake when doing my first lot of tests.
 The patch on this PR shows no significant performance hit on a 50000
 entry passwd file. Therefore, the complexity of the alternative that I
 came up with (not posted to the PR) is unjustified.
 
 I'll post a patch for pwd_mkdb when it's done.
 
 Ciao,
 Sheldon.
 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Thu Jul 29 09:37:46 PDT 1999 
State-Changed-Why:  
I've used your patch after all, since it matches more closely the code 
used in pwd_mkdb.c . Can you believe that we support usernames with spaces 
in them? :-)    I haven't touched pwd_mkdb, since the USHRT_MAX  
comparison generates warnings, not failures. 
>Unformatted:
