Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Problem with getpwnam() syscall

Reply
Thread Tools

Problem with getpwnam() syscall

 
 
Thomas Keller
Guest
Posts: n/a
 
      01-20-2004
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

--
»insert random joke here«
PGP Public Key: http://www.thomaskeller.biz/pgp/thomas-keller.pkr
Developer on http://www.musicmademe.com - Your lyrics site on the net
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      01-20-2004
Thomas Keller <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> 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
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      01-20-2004
Thomas Keller <(E-Mail Removed)> writes:

> 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\\
 
Reply With Quote
 
Josef Möllers
Guest
Posts: n/a
 
      01-20-2004
Thomas Keller wrote:

> #!/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.

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
 
Reply With Quote
 
Thomas Keller
Guest
Posts: n/a
 
      01-20-2004
Josef Möllers wrote:

> Thomas Keller wrote:
>
>> #!/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.


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

--
»insert random joke here«
PGP Public Key: http://www.thomaskeller.biz/pgp/thomas-keller.pkr
Developer on http://www.musicmademe.com - Your lyrics site on the net
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      01-20-2004

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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

--
The cosmos, at best, is like a rubbish heap scattered at random.
- Heraclitus
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why does select syscall returns evenif no data in serial port buffer alok C Programming 2 06-18-2007 11:45 AM
Syscall problem ? yezi C Programming 9 11-01-2005 09:33 PM
Ruby/HPUX/syscall problem/bug tad.bochan@bnpparibas.com Ruby 3 09-07-2004 02:48 PM
[ANN] Tracery - a ruby interface to ptrace syscall on linux Basile Starynkevitch [news] Ruby 0 01-29-2004 08:35 PM
Problem with getpwnam() syscall Thomas Keller Perl 1 01-20-2004 11:17 AM



Advertisments