App-LDAP
view release on metacpan or search on metacpan
lib/App/LDAP/Command/Passwd.pm view on Meta::CPAN
package App::LDAP::Command::Passwd;
use Modern::Perl;
use Moose;
with qw( App::LDAP::Role::Command
App::LDAP::Role::Bindable );
has lock => (
is => "rw",
isa => "Bool",
);
has unlock => (
is => "rw",
isa => "Bool",
);
sub run {
my ($self,) = @_;
my $name = $self->extra_argv->[1];
my $user = $name ? find_user(uid => $name) : current_user();
if ( $< == 0 ) {
$self->distinguish->($user);
} else {
if ($name and ( find_user(uid => $name)->dn ne current_user->dn ) ) {
die "you may not view or modify password information for " . $user->dn;
}
$self->distinguish->($user);
}
}
sub distinguish {
my $self = shift;
if ($self->lock && $self->unlock) {
say "I'm dazzled with your key :p";
exit;
}
if ($self->unlock) {
return \&unlock_user if $> == 0;
die "Permission denied";
}
if ($self->lock) {
return \&lock_user if $> == 0;
die "Permission denied";
}
return \&change_password;
}
sub change_password {
my $user = shift;
use Date::Calc qw(Today Delta_Days);
$user->replace(
userPassword => encrypt(new_password()),
shadowLastChange => Delta_Days(1970, 1, 1, Today()),
)->update(ldap());
( run in 0.874 second using v1.01-cache-2.11-cpan-97f6503c9c8 )