Date: Fri, 16 Jul 2010 09:43:54 +0530 From: ashish@FreeBSD.org (Ashish SHUKLA) To: Dan Nelson <dnelson@allantgroup.com> Cc: Jens Rehsack <rehsack@googlemail.com>, freebsd-questions@freebsd.org Subject: Re: getpwent bug? Message-ID: <86tyo0qd19.fsf@chateau.d.if> In-Reply-To: <20100715172615.GC5485@dan.emsphone.com> (Dan Nelson's message of "Thu, 15 Jul 2010 12:26:15 -0500") References: <AANLkTin5RGYfu_Xt5HWxKFO8GMTOi3YWQ8dyr95ZDW-Y@mail.gmail.com> <20100715172615.GC5485@dan.emsphone.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
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.
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.
#v+
#include <pwd.h>
#include <stdio.h>
int
main()
{
struct passwd* pw;
int i;
char ch;
for(i = 0; i < 3; i++)
{
printf("Doing getpwent(). Press any key to continue...");
while(getchar() != '\n');
pw = getpwent();
printf("%s:%d:%d\n", pw->pw_name, pw->pw_uid, pw->pw_gid);
endpwent();
}
}
#v-
Output on FreeBSD 8.1-RC2:
#v+
%./pwent
Doing getpwent(). Press any key to continue...
root:0:0
Doing getpwent(). Press any key to continue...
toor:0:0
Doing getpwent(). Press any key to continue...
daemon:1:1
#v-
Output on GNU/Linux:
#v+
% ./pwent
Doing getpwent(). Press any key to continue...
root:0:0
Doing getpwent(). Press any key to continue...
root:0:0
Doing getpwent(). Press any key to continue...
root:0:0
#v-
HTH
--
Ashish SHUKLA | GPG: F682 CDCC 39DC 0FEA E116 20B6 C746 CFA9 E74F A4B0
freebsd.org!ashish | http://people.freebsd.org/~ashish/
“How can I possibly put a new idea into your heads, if I do not first
remove your delusions?” (Robert A. Heinlein, "Life-Line", 1939)
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
iQIcBAEBCgAGBQJMP9yCAAoJEMdGz6nnT6SwBMMP/2V01XdDlQmypmtHhK7bavKg
MXerodcCXsK1whk1YBHdfzlXj464w6PAlXa4g1LVIqTpcBXjQ5MLApofnO+eqtgh
aitgL9J21ZZGxZeMvvI1Ykdsq7UsxMYj6KwAg3fdifPQz/y0mZIZH/YAFiykoO1e
jq4+yVwDQ2gf0zHf/g1eQtn/MpnokEyb1WxrxLL3rKD0JVFAGjoVSGGS4lVScjhI
x5QpoVMaa8Y5W5lwwjvfmktw/0Ei6sZkiZOskvmrQtCExn7Jt8wWApRNKWjppmdd
UODNLoFlflMmrpYEqjkVBROJMMRqwCRjxG5wPa6lXolysE2JNrfgfwUVvtSv8AtQ
UI+9mcszWSRJSM+HIgeK1mNQ8jvcOitRIUQO+grj8dvfaJqyO4ocyZej4Airg9ad
lKc1haBsqf+hyRG0+/LmunG/vLXHAcDq90M9PqgvRXn33d+X2sC+I4euCGyBSdDl
TSMxlMIbHr7sxAgSyK/FY9WpZJTWc+vcNZyNkNKZUR4kgrET9Jyh0Oip5Q06RaxD
pgTUuLYkUHfzwSETZolbCcu0MymlJDQkOkWI0/XKOc6jBYiGqDVp8uDpY0iOT/Oh
XQiJod/53hbgUyXGqEjpYEs+5jzdMlC9b2t1zNIhgLoPd+haXs6mItd+xvwdUWNS
JUf6sT7dDUvQWF0Fbwpx
=c9wh
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86tyo0qd19.fsf>
