4

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?

brian d foy
  • 129,424
  • 31
  • 207
  • 592

2 Answers2

5

You could use the Win32::NetAdmin module.

UserGetAttributes and GroupIsMember look like they do what you need.

David Webb
  • 190,537
  • 57
  • 313
  • 299
0

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

MkV
  • 3,046
  • 22
  • 16