CfgTie
view release on metacpan or search on metacpan
lib/CfgTie/TieShadow.pm view on Meta::CPAN
#Bug need to consider how vigorously we delete things -r ? /var/mail/me, etc
sub DELETE
{
my $self = shift;
my $name = shift;
#Basically delete the shadow now.
system "$CfgTie::TieShadow_rec'shadowdel $name";
#Remove it from our cache
if (exists $CfgTie::TieShadow_rec'by_name{$name})
{delete $CfgTie::TieShadow_rec'by_name{$name};}
}
package CfgTie::TieShadow_id;
sub status
{
# the information for the /etc/shadow file
stat '/etc/shadow';
}
sub TIEHASH
{
my $self = shift;
my $node = {};
return bless $node, $self;
}
sub FIRSTKEY
{
my $self = shift;
#Rewind outselves to the beginning.
setpwent;
&NEXTKEY($self);
}
sub NEXTKEY
{
my $self = shift;
#Get the next shadow id in the database.
# Get the information from the system and store it for later
my @x = getpwent;
if (! scalar @x) {return;}
&CfgTie::TieShadow_rec'TIEHASH(0,@x);
return $x[2]; #Corresponds to the id
}
sub EXISTS
{
my ($self,$id) = @_;
if (exists $CfgTie::TieShadow_rec'by_id{$id}) {return 1;}
# Get the information from the system and store it for later
my @x = getpwuid $id;
if (! scalar @x) {return 0;}
tie %{$CfgTie::TieShadow_rec'by_name{$x[0]}}, 'CfgTie::TieShadow_rec',@x;
$CfgTie::TieShadow_rec'by_id{$id} = $CfgTie::TieShadow_rec'by_name{$x[0]};
return 1;
}
sub FETCH
{
my ($self,$id) = @_;
#check out our cache first
if (&EXISTS($self,$id)) {return $CfgTie::TieShadow_rec'by_id{$id};}
}
#Bug creating shadows is not supported yet.
sub STORE
{
my ($self,$key,$val) = @_;
# shadowadd or shadowmod, depending
}
#Bug need to consider how vigorously we delete things -r ? /var/mail/me, etc
sub DELETE
{
my ($self,$id) = @_;
if (!exists $CfgTie::TieShadow_rec'by_id{$id})
{
#Try to look up the shadow id
&FETCH($self,$id);
}
if (exists $CfgTie::TieShadow_rec'by_id{$id})
{
#Basically delete the shadow now.
system "$CfgTie::TieShadow_rec'shadowdel $CfgTie::TieShadow_rec'by_id{$id}->{Name}";
#Remove it from out cache
delete $CfgTie::TieShadow_rec'by_id{$id};
}
}
package CfgTie::TieShadow_rec;
# A package used by both shadow_id and shadow to retain record information about
# a person. This is the only way to access shadowmod.
#Two hashes are used for look up
# $by_name{$name}
# $by_id{$id}
sub TIEHASH
{
# Ties a single shadow to a register...
my ($self,$Name,@Rest) = @_;
my $Node;
my $lname = lc($Name);
( run in 2.682 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )