App-Slaughter
view release on metacpan or search on metacpan
lib/Slaughter/API/freebsd.pm view on Meta::CPAN
#
return ( $params{ $variable } );
}
}
#
# If the GCos field isn't set then define it.
#
$params{ 'Gcos' } = $params{ 'Login' } if ( !$params{ 'Gcos' } );
# name:uid:gid:class:change:expire:gecos:home_dir:shell:password
my $line =
"$params{ 'Login' }:$params{ 'UID' }:::::$params{ 'Gcos' }::/bin/sh:";
my $cmd = "echo $line | adduser -G wheel -q -w random -f -";
RunCommand( Cmd => $cmd );
}
1;
lib/Slaughter/API/generic.pm view on Meta::CPAN
my $file = $params{ 'File' } || return;
my $group = $params{ 'Group' } || undef;
my $owner = $params{ 'Owner' } || undef;
my $mode = $params{ 'Mode' } || undef;
# file missing is an error
return (-1) if ( !-e $file );
# Numeric values
my $uid = undef;
my $gid = undef;
# invalid user?
if ( defined($owner) )
{
$uid = getpwnam($owner);
return -2 if ( !defined($uid) );
$::verbose && print "Owner:$owner -> UID:$uid\n";
}
# invalid group?
if ( defined($group) )
{
$gid = getgrnam($group);
return -2 if ( !defined($gid) );
$::verbose && print "Group:$group -> GID:$gid\n";
}
my $changed = 0;
if ( $params{ 'Owner' } )
{
#
# Find the current UID/GID of the file, so we
# can change just the owner.
#
my ( $dev, $ino, $mode, $nlink, $orig_uid,
$orig_gid, $rdev, $size, $atime, $mtime,
$ctime, $blksize, $blocks
)
= stat($file);
$::verbose && print "\tSetting owner to $owner/$uid\n";
chown( $uid, $orig_gid, $file );
$changed += 1;
}
if ( $params{ 'Group' } )
{
#
# Find the current UID/GID of the file, so we
# can change just the group.
#
my ( $dev, $ino, $mode, $nlink, $orig_uid,
$orig_gid, $rdev, $size, $atime, $mtime,
$ctime, $blksize, $blocks
)
= stat($file);
$::verbose && print "\tSetting group to $group/$gid\n";
chown( $orig_uid, $gid, $file );
$changed += 1;
}
if ( $params{ 'Mode' } )
{
$::verbose && print "\tSetting mode to $mode\n";
my $mode = $params{ 'Mode' };
if ( $mode !~ /^0/ )
{
$mode = oct("0$mode");
lib/Slaughter/API/generic.pm view on Meta::CPAN
Undef will be returned on failure.
=cut
sub UserDetails
{
my (%params) = (@_);
my ( $name, $pwcode, $uid, $gid, $quota, $comment, $gcos, $home, $logprog )
= getpwnam( $params{ 'User' } );
#
# This is undef.
#
return $name if ( !defined($name) );
#
# Return the values as a hash
#
return (
{ Home => $home,
UID => $uid,
GID => $gid,
Quota => $quota,
Comment => $comment,
Shell => $logprog,
Login => $name
} );
}
=head2 UserExists
lib/Slaughter/API/generic.pm view on Meta::CPAN
The return value of this function is 1 if the user exists, and 0 otherwise.
=cut
sub UserExists
{
my (%params) = (@_);
my ( $login, $pass, $uid, $gid ) = getpwnam( $params{ 'User' } );
if ( !defined($login) )
{
return 0;
}
else
{
return 1;
}
}
lib/Slaughter/API/linux.pm view on Meta::CPAN
#
# The user-addition command.
#
my $cmd =
"useradd -c \"$params{ 'Gcos' }\"" . " -G adm" .
" -g $params{ 'Login' }" . " -m" . " -u $params{ 'UID' }" .
" -s /bin/bash" . " $params{ 'Login' }";
# Ensure the group exists first.
RunCommand( Cmd => "addgroup --gid $params{ 'UID' } $params{ 'Login' }" );
# useradd -c name -d /home/user -g adm -m -u 801 user
RunCommand( Cmd => $cmd );
}
1;
( run in 2.310 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )