Win32-pwent

 view release on metacpan or  search on metacpan

lib/Win32/pwent.pm  view on Meta::CPAN

package Win32::pwent;

use warnings;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK);

use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw();
@EXPORT_OK = qw(getpwent endpwent setpwent getpwnam getpwuid getgrent entgrent setgrent getgrnam getgrgid);

use File::Spec;

use Win32;
use Win32::NetAdmin;
use Win32::TieRegistry Delimiter => "/";
use Win32API::Net 0.13; # for USER_INFO_4 structure

=head1 NAME

lib/Win32/pwent.pm  view on Meta::CPAN


Win32::pwent should help building a bridge for Perl scripts running on
Unix like systems to Win32.

It supports reading access to LanManager User-Info structures via the
well known pwent and grent functions.

=head1 EXPORT

Win32::pwent doesn't export anything by default. Following function can
be imported explicitely: C<endgrent>, C<getpwent>, C<getpwnam>, C<getpwuid>,
C<entgrent>, C<getgrent>, C<getgrnam>, C<getgrgid>

=head1 SUBROUTINES/METHODS

All exported subroutines behaves as the same ones for Unix-like systems
provided by Perl itself. See L<http://perldoc.perl.org/>.

=head2 getpwent

Returns the next entry from user list got from LANMAN user database.

lib/Win32/pwent.pm  view on Meta::CPAN

Rewind the pointer for the next user entry.

see L<http://perldoc.perl.org/functions/setpwent.html>

=head2 getpwnam

Fetches the user (by name) entry from LANMAN user database and return it

see L<http://perldoc.perl.org/functions/getpwnam.html>

=head2 getpwuid

fetches the user (by user id) entry from LANMAN user database and return it

see L<http://perldoc.perl.org/functions/getpwuid.html>

=head2 getgrent

Return the next group entry from LANMAN group database. If this is the first
call to C<getgrent> (or the first call after an C<endgrent> call), a group
cache based on the LANMAN database using the functions C<GroupEnum> and
C<GroupGetInfo> from the module L<Win32API::Net> is created.

see L<http://perldoc.perl.org/functions/getgrent.html>

lib/Win32/pwent.pm  view on Meta::CPAN


sub endpwent { $pwents = $pwents_pos = undef; }

sub getpwnam
{
    my $userName = $_[0];
    my $pwent = _fillpwent( $userName );
    return wantarray ? @$pwent : $pwent->[2];
}

sub getpwuid
{
    my $uid = $_[0];
    my $pwents = _fillpwents();
    my @uid_pwents = grep { $uid == $_->[2] } @$pwents;
    my @pwent = @{$uid_pwents[0]} if( 1 <= scalar(@uid_pwents) );
    return wantarray ? @pwent : $pwent[0];
}

sub _fillgrent
{

t/01-pwent.t  view on Meta::CPAN


my $pwentries = 0;
while( @pwent = Win32::pwent::getpwent() )
{
    ++$pwentries;
}
Win32::pwent::endpwent();

ok( $pwentries > 0, 'getpwent' );

my $userName = Win32::pwent::getpwuid($uid);
is( $userName, $loginName, 'getpwnam' );

my $grentries = 0;
while( @grent = Win32::pwent::getgrent() )
{
    ++$grentries;
}
Win32::pwent::endgrent();

ok( $grentries > 0, 'getgrent' );



( run in 0.231 second using v1.01-cache-2.11-cpan-454fe037f31 )