LDAP/Command/Passwd.pm

filter: Statementstmt 39.6% 23 / 58 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 6 totaltotal 27.8% 29 / 104 CC 12 SCAR 32.0
CC
12
Cov
28%
distinguish
56.0
run
30.0
current_user
6.0
CRAP 24.6
« LDAP/Command/Export.pm ↑ Summary LDAP/Command/Add/Sudoer.pm »
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
BranchTrueFalseTotal
$name ? : 0 0 0
26  
27 0 ▶ if ( $< == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($< == 0) { } 0 0 0
28 0 $self->distinguish->($user);
29 } else {
30 0 ▶ if ($name and ( find_user(uid => $name)->dn ne current_user->dn ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name and find_user("uid", $name)->dn ne "current_user"->dn) 0 0 0
Condition0%0/3
$name and find_user("uid", $name)->dn ne "current_user"->dn
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->lock and $self->unlock) 0 0 0
Condition0%0/3
$self->lock and $self->unlock
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
41 0 say "I'm dazzled with your key :p";
42 0 exit;
43 }
44  
45 0 ▶ if ($self->unlock) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->unlock) 0 0 0
46 0 ▶ return \&unlock_user if $> == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $> == 0 0 0 0
47 0 die "Permission denied";
48 }
49  
50 0 ▶ if ($self->lock) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lock) 0 0 0
51 0 ▶ return \&lock_user if $> == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $> == 0 0 0 0
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
BranchTrueFalseTotal
if ($search->count > 0) { } 0 0 0
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  
« LDAP/Command/Export.pm ↑ Summary LDAP/Command/Add/Sudoer.pm »