From owner-freebsd-questions@FreeBSD.ORG Fri Jul 16 15:07:25 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0C3781065672 for ; Fri, 16 Jul 2010 15:07:25 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email1.allantgroup.com (email1.emsphone.com [199.67.51.115]) by mx1.freebsd.org (Postfix) with ESMTP id C13758FC20 for ; Fri, 16 Jul 2010 15:07:24 +0000 (UTC) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by email1.allantgroup.com (8.14.0/8.14.0) with ESMTP id o6GF7KwQ044259 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 16 Jul 2010 10:07:21 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.4/8.14.4) with ESMTP id o6GF7K1d006934 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 16 Jul 2010 10:07:20 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.4/8.14.3/Submit) id o6GF7KPo006932; Fri, 16 Jul 2010 10:07:20 -0500 (CDT) (envelope-from dan) Date: Fri, 16 Jul 2010 10:07:19 -0500 From: Dan Nelson To: Jens Rehsack Message-ID: <20100716150719.GG5485@dan.emsphone.com> References: <20100715172615.GC5485@dan.emsphone.com> <86tyo0qd19.fsf@chateau.d.if> <20100716043056.GF5485@dan.emsphone.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: FreeBSD 8.1-PRERELEASE User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: clamav-milter 0.96 at email1.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (email1.allantgroup.com [199.67.51.78]); Fri, 16 Jul 2010 10:07:21 -0500 (CDT) X-Scanned-By: MIMEDefang 2.45 Cc: Ashish SHUKLA , freebsd-questions@freebsd.org Subject: Re: getpwent bug? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jul 2010 15:07:25 -0000 In the last episode (Jul 16), Jens Rehsack said: > 2010/7/16 Dan Nelson : > > In the last episode (Jul 16), Ashish SHUKLA said: > >> Well, OP is also invoking 'endpwent()' after every 'getpwent()' > >> invocation which according to GNU/Linux's glibc and NetBSD's libc (as > >> OP mentioned) should rewind the position in passwd database to the > >> beginning. > > > > Ah. I missed the endpwent calls. > > Was difficult for me to format the single liner ;) > > >> To me it definitely looks like a bug in FreeBSD's getpw*() family of > >> functions. > >> > >> As tested using sysutils/lsof, in the following program in FreeBSD, the > >> descriptor corresponding to '/etc/pwd.db' is closed on endpwent(3) but > >> position in database is never rewinded as shown in the output. > > > > It looks like the *pwent functions keep an internal counter that > > endpwent doesn't reset. > > Could you please take a look to my other mail (getgrent related) - there > seems another bug ... Do you have another one-liner that will reproduce it? A simple "/usr/bin/getent group" doesn't return dupes for me. Oddly enough, the *grent code doesn't use an internal counter, so the bug you found in endpwent doesn't exist in endgrent (afaik; the nsswitch code isn't that easy to read). > > Try the following patch: > > Can I do this without a full world rebuild? (I do not develop in FBSD > actively). Assuming your test programs are dynamically linked, you only need to rebuld libc. > > Index: gen/getpwent.c > > =================================================================== > > --- gen/getpwent.c      (revision 210157) > > +++ gen/getpwent.c      (working copy) > > @@ -794,6 +794,7 @@ files_setpwent(void *retval, void *mdata, va_list > >                        (void)st->db->close(st->db); > >                        st->db = NULL; > >                } > > +               st->keynum = 0; > >                break; > >        default: > >                break; > > > > -- Dan Nelson dnelson@allantgroup.com