Problem with getpwnam() syscall

T

Thomas Keller

Hello there!

I have a small problem while setting up a chrooted cvs
server which returns "No such system user" when I try
to do some action on it (e.g. "cvs co module").
I tracked the problem down to the getpwnam syscall
somewhere inside the CVS code and tried to chroot
into my server's environment myself to see whats up.

Since I'm (not yet) very comfortable with Perl I wrote
a very small script which does nothing else than

#!/usr/bin/perl

print getpwnam("tommyd"),"\n";

Outside the chrooted environment it returns the
proper information. Inside the chroot it does not.

I have a small directory tree for the cvs environment
created by following the instructions in [0],
a /etc/passwd file exists in there, here it is:

cvs::6000:6000::/:/sbin/nologin
tommyd:0m6PRAVWkfIZg:6000:6000::/:/sbin/nologin

The pl-script returns NULL when calling getpwnam, which
means, according to perldoc, that the user does not
exists. I read somewhere that this is only particularily
right since there could popup other error codes.

Final PERL-related question: How can I retrieve these
error codes and what do they mean? Has anybody experienced
similar problems like me with the getpwnam function?

Thanks in advance for any answers!

Thomas "TommyD" Keller.

[0] http://www.unixtools.org/cvs/server-how-to.html
 
A

Anno Siegel

Thomas Keller said:
Hello there!

I have a small problem while setting up a chrooted cvs
server which returns "No such system user" when I try
to do some action on it (e.g. "cvs co module").
I tracked the problem down to the getpwnam syscall
somewhere inside the CVS code and tried to chroot
into my server's environment myself to see whats up.

Since I'm (not yet) very comfortable with Perl I wrote
a very small script which does nothing else than

#!/usr/bin/perl

print getpwnam("tommyd"),"\n";
[...]

Final PERL-related question: How can I retrieve these
error codes and what do they mean? Has anybody experienced
similar problems like me with the getpwnam function?

Thanks in advance for any answers!

for ( qw( tommyd gibsnich) ) {
print getpwnam( $_) ? "$_ okay\n" : "$_: $!\n";
}

However, I doubt that the system error in $! contains anything
meaningful after a failed lookup. Not finding the requested user
is considered a normal reply, not a system error.

Anno
 
B

Brian McCauley

Thomas Keller said:
Hello there!

I have a small problem while setting up a chrooted cvs
server which returns "No such system user" when I try
to do some action on it (e.g. "cvs co module").
I tracked the problem down to the getpwnam syscall
somewhere inside the CVS code and tried to chroot
into my server's environment myself to see whats up.

Since I'm (not yet) very comfortable with Perl

I doubt your problem is Perl-related.
I wrote
a very small script which does nothing else than

#!/usr/bin/perl

print getpwnam("tommyd"),"\n";

Outside the chrooted environment it returns the
proper information. Inside the chroot it does not.

I have a small directory tree for the cvs environment
created by following the instructions in [0],
a /etc/passwd file exists in there, here it is:

cvs::6000:6000::/:/sbin/nologin
tommyd:0m6PRAVWkfIZg:6000:6000::/:/sbin/nologin

I suspect you'd see the same calling getpwnam() in any language. This
is likely to be interaction between the getpw* stuff on your OS and
chroot.

getpwnam() on modern Unicies may actually use many files
(e.g. /etc/nsswitch.conf). In the normal course of events it even not
access the files directly at all and talk to nscd via a Unix domain
socket - although I'd expect it to fall back on direct file access if
the daemon is not reachable.

I suggest you strace (or whatever the tool is called on your OS) to
see what other files it's looking at.
The pl-script returns NULL when calling getpwnam, which
means, according to perldoc, that the user does not
exists. I read somewhere that this is only particularily
right since there could popup other error codes.

Final PERL-related question: How can I retrieve these
error codes and what do they mean? Has anybody experienced
similar problems like me with the getpwnam function?

I'm not sure what you are asking. The most recent OS kernel error
(C's errno) is in $! which is magically both a string and a number.
If you want to handle $! programmatically use the Errno module.

For library rather than kernel calls the errno may not be so helpfull.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
J

Josef Möllers

Thomas said:
#!/usr/bin/perl

print getpwnam("tommyd"),"\n";

Outside the chrooted environment it returns the
proper information. Inside the chroot it does not.

Your problem may not be related to Perl.
Try "strace <testprogram>" if you're on a linux box or any other command
which traces execution. Your getwpnam() may fail due to some resource
missing.
 
T

Thomas Keller

Josef said:
Your problem may not be related to Perl.
Try "strace <testprogram>" if you're on a linux box or any other command
which traces execution. Your getwpnam() may fail due to some resource
missing.

Thanks a bunch for this tip!!! I saw in the output that after the syscall it
was tried to load the file libnss_compat.so.2 which failed (since it was
not in the chroot environment), after I copied it there it worked like a
charm!

Damn, whereever I did a $ ldd progname this library wasn't linked and even
in the HOWTO I mentioned [0] it wasn't described that this file is needed!


Thanks again, this problem bugged me several days!!!

Thomas.

[0] http://www.unixtools.org/cvs/server-how-to.html
 
B

Ben Morrow

I saw in the output that after the syscall it was tried to load the
file libnss_compat.so.2 which failed (since it was not in the chroot
environment), after I copied it there it worked like a charm!

Damn, whereever I did a $ ldd progname this library wasn't linked and even
in the HOWTO I mentioned [0] it wasn't described that this file is needed!

Any (glibc) program which performs name lookups will need (in general)
all of /lib/libnss*. See info "(libc)Name Service Switch" for more
info. You may want to submit a bug to the howto you were reading about
this.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top