Date: Thu, 15 Jul 2010 23:30:56 -0500 From: Dan Nelson <dnelson@allantgroup.com> To: Ashish SHUKLA <ashish@FreeBSD.org> Cc: Jens Rehsack <rehsack@googlemail.com>, freebsd-questions@FreeBSD.org Subject: Re: getpwent bug? Message-ID: <20100716043056.GF5485@dan.emsphone.com> In-Reply-To: <86tyo0qd19.fsf@chateau.d.if> References: <AANLkTin5RGYfu_Xt5HWxKFO8GMTOi3YWQ8dyr95ZDW-Y@mail.gmail.com> <20100715172615.GC5485@dan.emsphone.com> <86tyo0qd19.fsf@chateau.d.if>
next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jul 16), Ashish SHUKLA said:
> Dan Nelson writes:
> > In the last episode (Jul 15), Jens Rehsack said:
> >> Hi all,
> >>
> >> I detected an issue with getpwent on my FreeBSD test box:
> >>
> >> perl -MData::Dumper -e 'my @e = getpwent(); print Dumper(\@e); endpwent(); @e = getpwent(); print Dumper(\@e); endpwent(); @e = getpwent(); print Dumper(\@e); endpwent();'
> >> $VAR1 = [ 'root', '', 0, 0, 0, '', 'Charlie &', '/root', '/bin/csh', 0 ];
> >> $VAR1 = [ 'toor', '*', 0, 0, 0, '', 'Bourne-again Superuser', '/root', '', 0 ];
> >> $VAR1 = [ 'daemon', '*', 1, 1, 0, '', 'Owner of many system processes', '/root', '/usr/sbin/nologin', 0 ];
> >>
> >> I'm using FreeBSD waldorf.muppets.liwing.de 7.3-PRERELEASE FreeBSD 7.3-PRERELEASE #0: Fri Mar 12 11:31:18 UTC 2010 root@waldorf.muppets.liwing.de:/usr/obj/usr/src/sys/WALDORF amd64
>
> > The above output looks perfect, and should match the top three lines in
> > /your etc/passwd files.
>
> 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.
> 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. Try the following patch:
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?20100716043056.GF5485>
