Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Jul 2010 10:07:19 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Jens Rehsack <rehsack@googlemail.com>
Cc:        Ashish SHUKLA <ashish@freebsd.org>, freebsd-questions@freebsd.org
Subject:   Re: getpwent bug?
Message-ID:  <20100716150719.GG5485@dan.emsphone.com>
In-Reply-To: <AANLkTilSum3vumQhv4qtOQhCaSHo832Ub3b9bEhP0zSt@mail.gmail.com>
References:  <AANLkTin5RGYfu_Xt5HWxKFO8GMTOi3YWQ8dyr95ZDW-Y@mail.gmail.com> <20100715172615.GC5485@dan.emsphone.com> <86tyo0qd19.fsf@chateau.d.if> <20100716043056.GF5485@dan.emsphone.com> <AANLkTilSum3vumQhv4qtOQhCaSHo832Ub3b9bEhP0zSt@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jul 16), Jens Rehsack said:
> 2010/7/16 Dan Nelson <dnelson@allantgroup.com>:
> > 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100716150719.GG5485>