| 1 | package Mojolicious::Plugin::BasicAuthPlus; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Mojo::ByteStream; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Authen::Simple::Password; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Authen::Simple::Passwd; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Net::LDAP; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | our $VERSION = '1.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my ($plugin, $app) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | $app->renderer->add_helper( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 25 | ▶ | basic_auth => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # Sent credentials | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 25 | ▶ | my $auth = $self->req->url->to_abs->userinfo || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->req->url->to_abs->userinfo || ''
MC/DC100%1/1
$self->req->url->to_abs->userinfo || ''
$self->req->url->to_abs->userinfo
Truth table100%2/2
A
A= $self->req->url->to_abs->userinfo
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 25 | my ($hash_ref, $status) = $plugin->_check_auth($self, $auth, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 25 | ▶ | if ($status) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 18 | return ($hash_ref, $status); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Not verified | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | my $realm = $hash_ref->{realm}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | return $plugin->_password_prompt($self, $realm); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 25 | ▶ | sub _check_auth { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_auth: called CC=20 SCAR=31.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 25 | my ($plugin, $c, $auth, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Required credentials | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 25 | my ($realm, $password, $username) = $plugin->_expected_auth(@params); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 25 | ▶ | my $callback = $password if ref $password eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 25 | ▶ | my $params = $password if ref $password eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # No credentials entered | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 25 | ▶ | return {realm => $realm} if !$auth and !$callback and !$params; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$auth or $callback or $params
$auth or $callback
MC/DC100%3/3
$auth or $callback or $params
$auth
$callback
$params
Truth table100%4/4
A or B or C
A= $authB= $callbackC= $params
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 24 | my ($auth_username, $auth_password) = _split_auth($auth); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Hash for return data | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 24 | my %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 24 | ▶ | $data{username} = $auth_username if $auth_username; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Verification within callback | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 24 | ▶ | return (\%data, 1) if $callback and $callback->(_split_auth($auth)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$callback and &$callback(_split_auth($auth))
MC/DC100%2/2
$callback and &$callback(_split_auth($auth))
$callback
&$callback(_split_auth($auth))
Truth table100%3/3
A and B
A= $callbackB= &$callback(_split_auth($auth))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Verified with realm => username => password syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 19 | ▶ | return (\%data, 1) if $auth eq ($username || '') . ":$password"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$username || ''
MC/DC100%1/1
$username || ''
$username
Truth table100%2/2
A
A= $username
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # Verified via simple, passwd file, LDAP, or Active Directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 13 | ▶ | if ($auth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | ▶ | if ($params->{'username'} and $params->{'password'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$params->{"username"} and $params->{"password"}
MC/DC50%1/2
$params->{"username"} and $params->{"password"}
$params->{"username"}
$params->{"password"}
Truth table66%2/3
A and B
A= $params->{"username"}B= $params->{"password"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | ▶ | return (\%data, 1) if $plugin->_check_simple($c, $auth, $params); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | elsif ($params->{'path'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | return (\%data, 1) if $plugin->_check_passwd($c, $auth, $params); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | elsif ($params->{'host'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my ($ok, $ldap) = $plugin->_check_ldap($c, $auth, $params); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($ldap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $data{ldap} = $ldap; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return (\%data, 1) if $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # Not verified | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 6 | return {realm => $realm}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 25 | ▶ | sub _expected_auth { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expected_auth: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 25 | my $realm = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 25 | ▶ | return @$realm{qw/ realm password username /} if ref $realm eq "HASH"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # realm, pass, user || realm, pass, undef || realm, callback | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 25 | return $realm, reverse @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 7 | ▶ | sub _password_prompt { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_password_prompt: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 7 | my ($self, $c, $realm) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | $c->res->headers->www_authenticate("Basic realm=\"$realm\""); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 7 | $c->res->code(401); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | $c->rendered; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 39 | ▶ | sub _split_auth { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_auth: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Split $auth into username and password (which may contain ":") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 39 | my ($username, $password) = split ':', $_[0], 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 39 | ▶ | $username = '' unless defined $username; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 39 | ▶ | $password = '' unless defined $password; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 39 | return ($username, $password); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | ▶ | sub _check_simple { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_simple: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 5 | my ($self, $c, $auth, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | my ($username, $password) = _split_auth($auth); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | return 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | if $username eq $params->{'username'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 5 | ▶ | and Authen::Simple::Password->check($password, $params->{'password'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$username eq $params->{"username"} and "Authen::Simple::Password"->check($password, $params->{"password"})
MC/DC0%0/2
$username eq $params->{"username"} and "Authen::Simple::Password"->check($password, $params->{"password"})
$username eq $params->{"username"}
"Authen::Simple::Password"->check($password, $params->{"password"})
Truth table33%1/3
A and B
A= $username eq $params->{"username"}B= "Authen::Simple::Password"->check($password, $params->{"password"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub _check_ldap { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_ldap: not called CC=35 SCAR=71.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my ($self, $c, $auth, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my ($username, $password) = _split_auth($auth); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my $logging = $params->{logging} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params->{"logging"} // 0
MC/DC0%0/1
$params->{"logging"} // 0
$params->{"logging"}
Truth table0%0/2
A
A= $params->{"logging"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return 0 unless defined $password; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | my $ldap = Net::LDAP->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | $params->{host}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | port => $params->{port} // 389, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | scheme => $params->{scheme} // 'ldap', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | debug => $params->{debug} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | timeout => $params->{timeout} // 120, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | version => $params->{version} // 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/10
$params->{"port"} // 389
$params->{"scheme"} // "ldap"
$params->{"debug"} // 0
$params->{"timeout"} // 120
$params->{"version"} // 3
MC/DC0%0/1
$params->{"port"} // 389
$params->{"port"}
MC/DC0%0/1
$params->{"scheme"} // "ldap"
$params->{"scheme"}
MC/DC0%0/1
$params->{"debug"} // 0
$params->{"debug"}
MC/DC0%0/1
$params->{"timeout"} // 120
$params->{"timeout"}
MC/DC0%0/1
$params->{"version"} // 3
$params->{"version"}
Truth table0%0/2
A
A= $params->{"port"}
Truth table0%0/2
A
A= $params->{"scheme"}
Truth table0%0/2
A
A= $params->{"debug"}
Truth table0%0/2
A
A= $params->{"timeout"}
Truth table0%0/2
A
A= $params->{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | unless ($ldap) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $c->app->log->warn("Connection to $params->{host} failed: $@") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $socket_type = ref $ldap->{net_ldap_socket}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $c->app->log->warn("LDAP socket type: $socket_type") if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$socket_type eq "IO::Socket::SSL" or defined $params->{"start_tls"} and $params->{"start_tls"} == 0
defined $params->{"start_tls"} and $params->{"start_tls"} == 0
MC/DC0%0/3
$socket_type eq "IO::Socket::SSL" or defined $params->{"start_tls"} and $params->{"start_tls"} == 0
$socket_type eq "IO::Socket::SSL"
defined $params->{"start_tls"}
$params->{"start_tls"} == 0
Truth table0%0/4
A or B and C
A= $socket_type eq "IO::Socket::SSL"B= defined $params->{"start_tls"}C= $params->{"start_tls"} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # SSL connection already established | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ($socket_type eq 'IO::Socket::SSL') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # Or user doesn't want TLS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | || (defined($params->{start_tls}) && $params->{start_tls} == 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $dse = $ldap->root_dse(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $has_tls = $dse->supported_extension('1.3.6.1.4.1.1466.20037'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ($has_tls) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | my $mesg = $ldap->start_tls( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | verify => $params->{tls_verify} // 'optional', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | cafile => $params->{cafile} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$params->{"tls_verify"} // "optional"
$params->{"cafile"} // ""
MC/DC0%0/1
$params->{"tls_verify"} // "optional"
$params->{"tls_verify"}
MC/DC0%0/1
$params->{"cafile"} // ""
$params->{"cafile"}
Truth table0%0/2
A
A= $params->{"tls_verify"}
Truth table0%0/2
A
A= $params->{"cafile"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ($mesg->is_error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ($logging) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | my $text = sprintf 'start_tls() failed for %s [%s] %s: %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | $params->{host}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $mesg->code, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $mesg->error_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | $mesg->error_text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $c->app->log->warn($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $ldap->unbind; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $socket_type = ref $ldap->{net_ldap_socket}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $c->app->log->warn("LDAP socket type after start_tls(): $socket_type") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | my @credentials | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | = $params->{binddn} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | ? ($params->{binddn}, password => $params->{bindpw}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $mesg = $ldap->bind(@credentials); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ($mesg->is_error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | $c->app->log->warn("LDAP bind failed" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | . ($params->{binddn} ? " for $params->{binddn}: " : ": ") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | . $mesg->error) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $ldap->unbind; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $count = () = $params->{filter} =~ /%s/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $filter = sprintf($params->{filter}, ($username) x $count); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $scope = $params->{scope} // 'sub'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params->{"scope"} // "sub"
MC/DC0%0/1
$params->{"scope"} // "sub"
$params->{"scope"}
Truth table0%0/2
A
A= $params->{"scope"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | my $search = $ldap->search( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | base => $params->{basedn}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | scope => $scope, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | filter => $filter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | attrs => ['1.1'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ($search->is_error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $c->app->log->warn("LDAP search failed: " . $search->error) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $ldap->unbind; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ($search->count == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | $c->app->log->warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | qq{User '$username' not found with filter '$filter' and scope '$scope'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ) if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $ldap->unbind; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if ($search->count > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | $c->app->log->warn("Found " | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | . $search->count | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | . qq{ matching entries for $username with filter '$filter'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $entry = $search->entry(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $dn = $entry->dn; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $mesg = $ldap->bind($dn, password => $password); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if ($mesg->is_error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $c->app->log->warn( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | qq{LDAP failed to authenticate user '$username' with dn '$dn': } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | . $mesg->error) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $ldap->unbind; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | $c->app->log->info( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | qq{LDAP successfully authenticated user '$username' with dn '$dn'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | ) if $logging; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($params->{return_ldap_handle}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | return (1, $ldap); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $ldap->unbind; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | ▶ | sub _check_passwd { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_passwd: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | my ($self, $c, $auth, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | my ($username, $password) = _split_auth($auth); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | my $passwd = Authen::Simple::Passwd->new(%$params); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | ▶ | return 1 if $passwd->authenticate($username, $password); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||