| 1 | package App::LDAP::Command::Passwd; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | with qw( App::LDAP::Role::Command | |||||||||||||||||||||||||||
| 8 | App::LDAP::Role::Bindable ); | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | has lock => ( | |||||||||||||||||||||||||||
| 11 | is => "rw", | ||||||||||||||||||||||||||||
| 12 | isa => "Bool", | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | has unlock => ( | |||||||||||||||||||||||||||
| 16 | is => "rw", | ||||||||||||||||||||||||||||
| 17 | isa => "Bool", | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 0 | my ($self,) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | my $name = $self->extra_argv->[1]; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $user = $name ? find_user(uid => $name) : current_user(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ( $< == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | $self->distinguish->($user); | |||||||||||||||||||||||||||
| 29 | } else { | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($name and ( find_user(uid => $name)->dn ne current_user->dn ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name and find_user("uid", $name)->dn ne "current_user"->dn
MC/DC0%0/2
$name and find_user("uid", $name)->dn ne "current_user"->dn
$name
find_user("uid", $name)->dn ne "current_user"->dn
Truth table0%0/3
A and B
A= $nameB= find_user("uid", $name)->dn ne "current_user"->dn
| |||||||||||||||||||||||||||||
| 31 | 0 | die "you may not view or modify password information for " . $user->dn; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 0 | $self->distinguish->($user); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub distinguish { | ||||||||||||||||||||||||||
|
Subroutine
distinguish: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($self->lock && $self->unlock) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->lock and $self->unlock
MC/DC0%0/2
$self->lock and $self->unlock
$self->lock
$self->unlock
Truth table0%0/3
A and B
A= $self->lockB= $self->unlock
| |||||||||||||||||||||||||||||
| 41 | 0 | say "I'm dazzled with your key :p"; | |||||||||||||||||||||||||||
| 42 | 0 | exit; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ($self->unlock) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return \&unlock_user if $> == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | die "Permission denied"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($self->lock) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return \&lock_user if $> == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | die "Permission denied"; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | return \&change_password; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub change_password { | ||||||||||||||||||||||||||
|
Subroutine
change_password: not called CC=1 SCAR=0.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 59 | 1 | ▶ | use Date::Calc qw(Today Delta_Days); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 0 | $user->replace( | |||||||||||||||||||||||||||
| 61 | userPassword => encrypt(new_password()), | ||||||||||||||||||||||||||||
| 62 | shadowLastChange => Delta_Days(1970, 1, 1, Today()), | ||||||||||||||||||||||||||||
| 63 | )->update(ldap()); | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub lock_user { | ||||||||||||||||||||||||||
|
Subroutine
lock_user: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 68 | 0 | my $password = $user->get_value("userPassword"); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $password =~ s{{crypt}\$}{{crypt}!\$}; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | $user->replace( | |||||||||||||||||||||||||||
| 73 | userPassword => $password, | ||||||||||||||||||||||||||||
| 74 | )->update(ldap()); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub unlock_user { | ||||||||||||||||||||||||||
|
Subroutine
unlock_user: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 79 | 0 | my $password = $user->get_value("userPassword"); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | $password =~ s{{crypt}!\$}{{crypt}\$}; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | $user->replace( | |||||||||||||||||||||||||||
| 84 | userPassword => $password, | ||||||||||||||||||||||||||||
| 85 | )->update(ldap()); | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | use Net::LDAP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | use Net::LDAP::Extension::WhoAmI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub current_user { | ||||||||||||||||||||||||||
|
Subroutine
current_user: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 0 | my $dn = ldap()->who_am_i->response; | |||||||||||||||||||||||||||
| 92 | 0 | $dn =~ s{dn:}{}; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my $search = ldap()->search( | |||||||||||||||||||||||||||
| 95 | base => $dn, | ||||||||||||||||||||||||||||
| 96 | scope => "base", | ||||||||||||||||||||||||||||
| 97 | filter => "objectClass=*", | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($search->count > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | return $search->entry(0); | |||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||
| 103 | 0 | die "$dn not found"; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 108 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 1 | 1; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =pod | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 NAME | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | App::LDAP::Command::Passwd - manage the password in LDAP server | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | $ ldap passwd # change your own password | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | $ sudo ldap passwd # change password of ldap admin | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | $ sudo ldap passwd shelling # sudo the privilege of admin to change password of shelling | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | $ sudo ldap passwd shelling -l # lock shelling | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | $ sudo ldap passwd shelling -u # unlock shelling | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||