Problem with getpwnam() syscall

Discussion in 'Perl Misc' started by Thomas Keller, Jan 20, 2004.

  1. 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
     
    Thomas Keller, Jan 20, 2004
    #1
    1. Advertising

  2. Thomas Keller

    Anno Siegel Guest

    Thomas Keller <> 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
     
    Anno Siegel, Jan 20, 2004
    #2
    1. Advertising

  3. Thomas Keller <> 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\\
     
    Brian McCauley, Jan 20, 2004
    #3
  4. 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
     
    Josef Möllers, Jan 20, 2004
    #4
  5. 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
     
    Thomas Keller, Jan 20, 2004
    #5
  6. Thomas Keller

    Ben Morrow Guest

    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
     
    Ben Morrow, Jan 20, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Keller

    Problem with getpwnam() syscall

    Thomas Keller, Jan 19, 2004, in forum: Perl
    Replies:
    1
    Views:
    1,398
    Joe Smith
    Jan 20, 2004
  2. Jason Williard

    Using getpwnam() with CGI

    Jason Williard, Apr 22, 2005, in forum: Perl
    Replies:
    0
    Views:
    2,737
    Jason Williard
    Apr 22, 2005
  3. gga
    Replies:
    1
    Views:
    319
    Daniel Berger
    Mar 8, 2005
  4. Jason Williard

    Using getpwnam() with CGI

    Jason Williard, Apr 23, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    217
    Alan J. Flavell
    Apr 24, 2005
  5. perlUSER

    getpwnam question

    perlUSER, Nov 25, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    169
    Anno Siegel
    Nov 29, 2005
Loading...

Share This Page