views:

682

answers:

2

Perl has several built-in functions for accessing /etc/passwd on Unix systems (and elsewhere when supported) for user and group information. For instance,

my $name = getpwuid($uid);

will return the user name given the user ID, or undef if there is no such user.

If a Perl script needs to be portable and run on Unices and Windows, how should one access user and group information? ActivePerl seems to support User::grent and User::pwent modules, which provide by-field access to /etc/passwd -- even in Windows. Curiously they do not support the built-in functions getpw* and getgr*. What other alternatives are there?

+5  A: 

You could use the Win32::NetAdmin module.

UserGetAttributes and GroupIsMember look like they do what you need.

Dave Webb
A: 

Oddly enough, Interix's build of Perl that ships with Microsoft's Services for Unix does support getpw* and friends.

MkV