Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

The getpwnam function is unimplemented (in Windows)

by Becky (Beadle)
on Jan 19, 2004 at 18:11 UTC ( #322402=perlquestion: print w/ replies, xml ) Need Help??
Becky has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I've been given a perl program that a colleague runs perfectly well on unix. It says it's fine to run on windows but I get the following error:

The getpwnam function is unimplemented

I've done a bit of searching and it seems that getpwnam isn't implemented with ActivePerl.

Another website said that the equivalent of getpwnam on windows is NetUserGetInfo(). Is this correct or is there a way I can get getpwnam?

Thanks!

Edit by tye, title, some P tags

Comment on The getpwnam function is unimplemented (in Windows)
Re: getpwnam
by jweed (Chaplain) on Jan 19, 2004 at 18:20 UTC

      I'm afraid that that isn't going to help being, as it says on the tin, a " by-name interface to Perl's built-in getpw*() functions".

      I think making a wrapper round some Win32::* modules method so it has the same interface as getpwnam() will be the way to go.

      /J\

Re: getpwnam
by JamesNC (Chaplain) on Jan 19, 2004 at 18:29 UTC
    Try:
    use Win32; my $userName = Win32::LoginName(); print "Current User: ", $userName, "\n";
      Good one...I tried this and it worked like a charm !!! Thanks !!!
Re: getpwnam
by derby (Abbot) on Jan 19, 2004 at 18:45 UTC
    It's hard to say what the correct way is. getpwnam returns the password structure (and that's different things on different *Nixes but basically user name, user id, group id, encrypted password, real name, home directory, and shell). Exactly what do you need for your script?

    -derby

      The only place it's called is in the following subroutine:

      sub map_user_group { if( ! defined( $uid ) ){ if( $user =~ /^\d+$/ ){ # User is just a number - presume it is the uid $uid = $user; } else { $uid = (getpwnam( $user ))[ 2 ]; } } if( ! defined( $gid ) ){ if( $group =~ /\d+$/ ){ # Group is just a number - presume it is the gid $gid = $group; } else { $gid = (getgrnam( $group ))[ 2 ]; } } }

      Any ideas would be much appreciated!

        that snippet of code sets the userid and groupid ... concepts that are foreign to a lot of windows systems. It's not so much that ActivePerl doesn't implement getpwnam (and getgrnam) but that there's no need for it on a windows platform. Exactly what is the script doing with $uid and $gid?

        -derby

Re: The getpwnam function is unimplemented (in Windows)
by ysth (Canon) on Jan 20, 2004 at 00:32 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://322402]
Approved by jweed
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-10-20 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (92 votes), past polls