From stephane@lituus.fr  Sun Aug 30 08:12:58 1998
Received: from lituussun (irc.ladapt.org [195.25.51.6])
          by hub.freebsd.org (8.8.8/8.8.8) with SMTP id IAA28536
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 30 Aug 1998 08:12:56 -0700 (PDT)
          (envelope-from stephane@lituus.fr)
Received: from (sequoia.lituus.fr) [193.252.136.18] 
	by lituussun with esmtp (Exim 1.82 #1)
	id 0zDA0c-00013L-00; Sun, 30 Aug 1998 17:07:19 +0100
Received: (from root@localhost)
	by sequoia.lituus.fr (8.9.1/8.9.1) id RAA11886;
	Sun, 30 Aug 1998 17:06:25 +0200 (CEST)
	(envelope-from root)
Message-Id: <199808301506.RAA11886@sequoia.lituus.fr>
Date: Sun, 30 Aug 1998 17:06:25 +0200 (CEST)
From: Stephane Legrand <stephane@lituus.fr>
To: FreeBSD-gnats-submit@freebsd.org
Subject: Problem with setpassent(), getpwnam() and getpwuid() functions in libc

>Number:         7781
>Category:       kern
>Synopsis:       Problem with setpassent(), getpwnam() and getpwuid() functions in libc
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 30 08:20:00 PDT 1998
>Closed-Date:    Sun Oct 17 03:35:41 PDT 1999
>Last-Modified:  Sun Oct 17 03:37:42 PDT 1999
>Originator:     Stephane Legrand
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:
>Description:

The manual page for the setpassent(int stayopen) function says :

"The setpassent() function accomplishes two purposes.  First, it
causes getpwent() to ``rewind'' to the beginning of the database.
Additionally, if stayopen is non-zero, file descriptors are left open,
significantly speeding up subsequent accesses for all of the routines.
(This latter functionality is unnecessary for getpwent() as it doesn't
close its file descriptors by default.)"

The problem is that in the file getpwent.c which implements the
setpassent() function in the libc, the stayopen variable seems not
used. And then, code like setpassent(1) doesn't work as expected.

This problem is particularly annoying with ProFTPD
(/usr/ports/net/proftpd) which uses a such code.


>How-To-Repeat:
>Fix:
	
A patch has been proposed by Adam Mackler
(mackler@barter.dewline.com). It adds a "if" to check the value of
"_pw_stayopen" BEFORE calling "endpwent()".

	
Adam Mackler writes:
 > > Date: Thu, 6 Aug 1998 17:50:08 -0400
 > > From: Floody <flood@evcom.net>
 > > Reply-To: proftpd-l@evcom.net
 > > To: Karl Pielorz <kpielorz@tdx.co.uk>
 > > Cc: proftpd-l@evcom.net
 > > Subject: Re: [proftpd-l] New ProFTPd user - Security, Incoming and pwd.db?
 > > 
 > > Ok.  I put up a test FreeBSD 2.2.7 system.  There appears to be a libc
 > > problem with the setpassent() function, which doesn't work on FreeBSD as
 > > documented in the man pages (or on any other BSD).  This is the heart of
 > > the problem.  There is no workaround until libc is fixed.
 > 
 > Hi:
 > 
 > I think the following patch may fix the problem, but I'm afraid
 > I don't know how to rebuild my c library.  If you find out if this
 > works can you let me know?  Thanks.
 > 
 > 
 > *** getpwent.c  Wed Aug 19 02:00:13 1998
 > --- getpwent.c.dist     Wed Aug 19 01:58:33 1998
 > ***************
 > *** 194,201 ****
 >         if (rval && (_pw_passwd.pw_name[0] == '+'||
 >                         _pw_passwd.pw_name[0] == '-')) rval = 0;
 >   
 > !       if (!_pw_stayopen)
 > !         endpwent();
 >         return(rval ? &_pw_passwd : (struct passwd *)NULL);
 >   }
 >   
 > --- 194,200 ----
 >         if (rval && (_pw_passwd.pw_name[0] == '+'||
 >                         _pw_passwd.pw_name[0] == '-')) rval = 0;
 >   
 > !       endpwent();
 >         return(rval ? &_pw_passwd : (struct passwd *)NULL);
 >   }
 >   
 > 
 > -- 
 > Adam Mackler
 > Dewline Communications, LLC
 > 212-505-9149
 > 
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ache 
State-Changed-When: Sun Oct 17 03:35:41 PDT 1999 
State-Changed-Why:  
Fix applied 
>Unformatted:

