From owner-freebsd-questions@FreeBSD.ORG Fri Jul 16 16:22:44 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 BB40F1065672; Fri, 16 Jul 2010 16:22:44 +0000 (UTC) (envelope-from rehsack@googlemail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 141408FC19; Fri, 16 Jul 2010 16:22:43 +0000 (UTC) Received: by bwz12 with SMTP id 12so1434512bwz.13 for ; Fri, 16 Jul 2010 09:22:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=SneZbpE1u4qaduw4bVtYmnv2k+4J0+wpQONoYU5XUfA=; b=tg8gkDlwC/Aez2XOXqUe51bT2t/KZ5GFvXKzWsU2rVwOK3wfBdxOtZjzrtA8ICvB1u rJ/gH+CdE9gXrBcSq23cFw8BuBu5iuYBEoGJNM8kwoNAjk81Ubg9byg8qUzEbTHHF7wg BcW+xzLcUwpxOs+3vq5o3/KC5aoEjTXn4W3Dw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=KTf7eZ3WjxLzkGWycDHrDKvwkF7MalmV74bfI0HcwQ5NYIYHZ+j/vll7T6ir4HosMY kJYl+zVPNjZwoXu+nYjFP44RFo3luvln7rnGxDV61Y1bxbeXwYjjAU9WstKzws45P/JW XIIYkDX6T+S7cvl5rjKh+eutKM6KWe1Rg6qsQ= Received: by 10.204.84.92 with SMTP id i28mr1101842bkl.57.1279297362992; Fri, 16 Jul 2010 09:22:42 -0700 (PDT) Received: from waldorf.muppets.liwing.de (p4FF86EBD.dip.t-dialin.net [79.248.110.189]) by mx.google.com with ESMTPS id 24sm11560982bkr.19.2010.07.16.09.22.41 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 16 Jul 2010 09:22:42 -0700 (PDT) Message-ID: <4C408744.3030409@netbsd.org> Date: Fri, 16 Jul 2010 16:22:28 +0000 From: Jens Rehsack User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.1.9) Gecko/20100409 Thunderbird/3.0.4 MIME-Version: 1.0 To: Dan Nelson 0 References: <20100715172615.GC5485@dan.emsphone.com> <86tyo0qd19.fsf@chateau.d.if> <20100716043056.GF5485@dan.emsphone.com> <20100716150719.GG5485@dan.emsphone.com> In-Reply-To: <20100716150719.GG5485@dan.emsphone.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 16:22:44 -0000 On 07/16/10 15:07, Dan Nelson wrote: > 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). Not really a one-liner: perl -MData::Dumper -e 'setgrent; my %dupchk; while( my ( $name, $grpass, $gid, $members ) = getgrent() ) { print "$name is returned more than once (No $dupchk{$name} comes here)\n" if( $dupchk{$name}++ ); print Dumper( [ $name, $grpass, $gid, $members ] ) };' setgrent() doesn't work here. Best regards, Jens