Linux-Shadow

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension Linux::Shadow.

0.05  Thu Apr  6 2017
	- Add overloads for getpwnam, getpwuid and getpwent that will populate
		the expires field if it isn't already populated.

0.04  Wed Apr  5 2017
	- Rename MYMETA files to META files

0.03  Wed Apr  5 2017
	- Add changelog, package the MYMETA files, some more documentation
		cleanup, Backup minimum version to 5.10.1, change to pure
		XS code to simplify things.

lib/Linux/Shadow.pm  view on Meta::CPAN

          SHADOW
          getspnam
          getspent
          setspent
          endspent
          )
    ],
    'getpw' => [
        qw(
          getpwnam
          getpwuid
          getpwent
          )
    ]
);

our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} }, @{ $EXPORT_TAGS{'getpw'} } );

our @EXPORT = qw(
  getspnam
  getspent

lib/Linux/Shadow.pm  view on Meta::CPAN

XSLoader::load( 'Linux::Shadow', $VERSION );

sub getpwnam {

    my ($name) = @_;
    my @pwent = CORE::getpwnam($name);
    return set_pwent_expire(@pwent);

}

sub getpwuid {

    my ($uid) = @_;
    my @pwent = CORE::getpwuid($uid);
    return set_pwent_expire(@pwent);

}

sub getpwent {

    my @pwent = CORE::getpwent();
    return set_pwent_expire(@pwent);

}

lib/Linux/Shadow.pm  view on Meta::CPAN

=head1 SYNOPSIS

  use Linux::Shadow;
  ($name,$passwd,$lstchg,$min,$max,$warn,$inact,$expire,$flag) = getspnam('user');
  ($name,$passwd,$lstchg,$min,$max,$warn,$inact,$expire,$flag) = getspent();
  setspent();
  endspent();
  
  use Linux::Shadow qw(:getpw);
  ($name,$passwd,$uid,$gid, $quota,$comment,$gcos,$dir,$shell,$expire) = getpwnam('user');
  ($name,$passwd,$uid,$gid, $quota,$comment,$gcos,$dir,$shell,$expire) = getpwuid(0);
  ($name,$passwd,$uid,$gid, $quota,$comment,$gcos,$dir,$shell,$expire) = getpwent();

=head1 DESCRIPTION
 
Perl gives access to the user's shadow password itself via getpw*, but the
rest of the shadow entry is not available (expire is theoretically available
if compiled that way, but it isn't universal).  This module provides a Perl
interface to the shadow routines getspnam, getspent, setspent and endspent,
allowing the full shadow password structure to be returned.  Like all access
to the shadow files, root privileges are required to return anything - non-

lib/Linux/Shadow.pm  view on Meta::CPAN

=head2 Overloaded Core Routines

These routines overload the identically named Perl core routines, with the
purpose of populating the $expires field that is not typically compiled into
Perl itself.  These must be explicitly imported to access them.

=over

=item getpwnam(NAME)

=item getpwuid(UID)

=item getpwent

These functions work exactly like the identically named functions documented
in L<perlfunc/perlfunc>, except that if they return the userinfo and can
access the shadow info, the $expires field is guaranteed to be populated.
See L<perlfunc/getpwnam> for details.

=back

t/Linux-Shadow.t  view on Meta::CPAN

# 'make test'. After 'make install' it should work as 'perl Linux-Shadow.t'

#########################

# change 'tests => 2' to 'tests => last_test_to_print';

use strict;
use warnings;

use Test::More tests => 16;
BEGIN { use_ok('Linux::Shadow', qw(SHADOW getspnam getspent setspent endspent getpwnam getpwuid getpwent)) };


my $fail = 0;
foreach my $constname (qw(
	SHADOW)) {
  next if (eval "my \$a = $constname; 1");
  if ($@ =~ /^Your vendor has not defined Linux::Shadow macro $constname/) {
    print "# pass: $@";
  } else {
    print "# fail: $@";

t/Linux-Shadow.t  view on Meta::CPAN

  ok( $fail == 0, 'endspent' );

  my @pwent = getpwnam('root');
  if (!@pwent) {
     $fail = 1;
  } elsif ($#pwent != 9) {
     $fail = 1;
  }
  ok( $fail == 0, 'getpwnam overload' );

  @pwent = getpwuid(0);
  if (!@pwent) {
     $fail = 1;
  } elsif ($#pwent != 9) {
     $fail = 1;
  }
  ok( $fail == 0, 'getpwuid overload' );

  @pwent = getpwent();
  if (!@pwent) {
     $fail = 1;
  } elsif ($#pwent != 9) {
     $fail = 1;
  }
  ok( $fail == 0, 'getpwent overload' );

}



( run in 0.290 second using v1.01-cache-2.11-cpan-8d75d55dd25 )