| 1 | package Net::LDAP::SimpleServer::ProtocolHandler; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: LDAP protocol handler used with Net::LDAP::SimpleServer | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 40 | our $VERSION = '0.0.21'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use constant MD5_PREFIX => '{md5}'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | ▶ | use Net::LDAP::Server; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 40 | ▶ | use base 'Net::LDAP::Server'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | use fields | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 40 | ▶ | qw(store root_dn root_pw allow_anon user_passwords user_id_attr user_pw_attr user_filter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 40 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 40 | ▶ | use Net::LDAP::LDIF; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | ▶ | use Net::LDAP::Util qw{canonical_dn}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 40 | ▶ | use Net::LDAP::Filter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 40 | ▶ | use Net::LDAP::FilterMatch; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 40 | ▶ | use Net::LDAP::Constant qw/ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | LDAP_SUCCESS LDAP_INVALID_CREDENTIALS LDAP_AUTH_METHOD_NOT_SUPPORTED | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 40 | LDAP_INVALID_SYNTAX LDAP_NO_SUCH_OBJECT LDAP_INVALID_DN_SYNTAX/; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 40 | ▶ | use Net::LDAP::SimpleServer::LDIFStore; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 40 | ▶ | use Net::LDAP::SimpleServer::Constant; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 40 | ▶ | use Scalar::Util qw{reftype}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 40 | ▶ | use UNIVERSAL::isa; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 40 | ▶ | use Digest::MD5 qw/md5/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 40 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 26 | ▶ | sub _make_result { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_result: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 26 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 26 | ▶ | my $dn = shift // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // ""
MC/DC100%1/1
shift() // ""
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 26 | ▶ | my $msg = shift // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // ""
MC/DC100%1/1
shift() // ""
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 26 | matchedDN => $dn, | |||||||||||||||||||||||||||||||||||||||||
| 43 | errorMessage => $msg, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | resultCode => $code, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 20 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 20 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 20 | ▶ | my $params = shift || croak 'Must pass parameters!'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || croak('Must pass parameters!')
MC/DC100%1/1
shift() || croak('Must pass parameters!')
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 19 | ▶ | croak 'Parameter must be a HASHREF' unless reftype($params) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 17 | for my $p (qw/store root_dn sock/) { | |||||||||||||||||||||||||||||||||||||||||
| 54 | 45 | ▶ | croak 'Must pass option {' . $p . '}' unless exists $params->{$p}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | croak 'Not a LDIFStore' | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 13 | ▶ | unless $params->{store}->isa('Net::LDAP::SimpleServer::LDIFStore'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 13 | ▶ | croak 'Option {root_dn} can not be empty' unless $params->{root_dn}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | croak 'Invalid root DN' | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 13 | ▶ | unless my $canon_dn = canonical_dn( $params->{root_dn} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 13 | my $self = $class->SUPER::new( $params->{sock} ); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | $self->{store} = $params->{store}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | $self->{root_dn} = $canon_dn; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 13 | $self->{root_pw} = $params->{root_pw}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 13 | $self->{allow_anon} = $params->{allow_anon}; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 13 | $self->{user_passwords} = $params->{user_passwords}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | $self->{user_id_attr} = $params->{user_id_attr}; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 13 | $self->{user_pw_attr} = $params->{user_pw_attr}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | $self->{user_filter} = $params->{user_filter}; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | chomp( $self->{root_pw} ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | chomp( $self->{user_passwords} ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 13 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | ▶ | sub unbind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unbind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | $self->{store} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | $self->{root_dn} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 10 | $self->{root_pw} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 10 | return _make_result(LDAP_SUCCESS); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | sub _find_user_dn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_user_dn: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | my ( $self, $username ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | my $filter = | ||||||||||||||||||||||||||||||||||||||||||
| 92 | Net::LDAP::Filter->new( '(&' | ||||||||||||||||||||||||||||||||||||||||||
| 93 | . $self->{user_filter} . '(' | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | . $self->{user_id_attr} . '=' | |||||||||||||||||||||||||||||||||||||||||
| 95 | . $username | ||||||||||||||||||||||||||||||||||||||||||
| 96 | . '))' ); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | return _match( $filter, $self->{store}->list() ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | sub _encode_password { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_password: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | my $plain = shift; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $hashpw = encode_base64( md5($plain), '' ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | return MD5_PREFIX . $hashpw; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | ▶ | sub bind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind: called CC=15 SCAR=27.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | ## no critic (ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 12 | my ( $self, $request ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | # anonymous bind | ||||||||||||||||||||||||||||||||||||||||||
| 112 | return _make_result(LDAP_SUCCESS) | ||||||||||||||||||||||||||||||||||||||||||
| 113 | if ( $self->{allow_anon} | ||||||||||||||||||||||||||||||||||||||||||
| 114 | and not $request->{name} | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 12 | ▶ | and exists $request->{authentication}->{simple} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"allow_anon"} and not $request->{"name"} and exists $request->{"authentication"}{"simple"}
$self->{"allow_anon"} and not $request->{"name"}
MC/DC33%1/3
$self->{"allow_anon"} and not $request->{"name"} and exists $request->{"authentication"}{"simple"}
$self->{"allow_anon"}
not $request->{"name"}
exists $request->{"authentication"}{"simple"}
Truth table50%2/4
A and not(B) and C
A= $self->{"allow_anon"}B= not $request->{"name"}C= exists $request->{"authentication"}{"simple"}
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | # As of now, accepts only simple authentication | ||||||||||||||||||||||||||||||||||||||||||
| 118 | return _make_result(LDAP_AUTH_METHOD_NOT_SUPPORTED) | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | ▶ | unless exists $request->{authentication}->{simple}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 7 | my $bind_pw = $request->{authentication}->{simple}; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | chomp($bind_pw); | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 7 | my $bind_dn = canonical_dn( $request->{name} ); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | ▶ | unless ($bind_dn) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | my $search_user_result = $self->_find_user_dn( $request->{name} ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | my $size = scalar( @{$search_user_result} ); | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | return _make_result( LDAP_INVALID_DN_SYNTAX, '', | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 'Cannot find user: ' . $request->{name} ) | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | ▶ | if $size == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | return _make_result( LDAP_INVALID_DN_SYNTAX, '', | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 'Cannot retrieve an unique user entry for id: ' . $request->{name} ) | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | if $size > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | $bind_dn = $search_user_result->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | elsif ( uc($bind_dn) ne uc( $self->{root_dn} ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 139 | my $search_dn_result = | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | $self->{store}->list_with_dn_scope( $bind_dn, SCOPE_BASEOBJ ); | |||||||||||||||||||||||||||||||||||||||||
| 141 | return _make_result( LDAP_INVALID_DN_SYNTAX, '', | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 'Cannot find user: ' . $request->{name} ) | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | unless $search_dn_result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | $bind_dn = $search_dn_result->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | ▶ | if ( $bind_dn->isa('Net::LDAP::Entry') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # user was not a dn, but it was found | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | my $entry_pw = $bind_dn->get_value( $self->{user_pw_attr} ); | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | my $regexp = '^' . MD5_PREFIX; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | ▶ | $entry_pw = _encode_password($entry_pw) if $entry_pw =~ /$regexp/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | return _make_result( LDAP_INVALID_CREDENTIALS, undef, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 'entry dn: ' . $bind_dn->dn() ) | ||||||||||||||||||||||||||||||||||||||||||
| 158 | unless $entry_pw eq $bind_pw; | ||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | elsif ( uc($bind_dn) eq uc( $self->{root_dn} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | return _make_result( LDAP_INVALID_CREDENTIALS, undef, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 'bind dn: ' . $bind_dn ) | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | unless $bind_pw eq $self->{root_pw}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | return _make_result( LDAP_INVALID_DN_SYNTAX, '', | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | 'Cannot find user: ' . $request->{name} ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | return _make_result(LDAP_SUCCESS); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 6 | ▶ | sub _match { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_match: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 6 | my ( $filter_spec, $elems ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | my $f = bless $filter_spec, 'Net::LDAP::Filter'; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 6 | return [ grep { $f->match($_) } @{$elems} ]; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | sub _encode_pw_attr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_pw_attr: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | my ( $pw_attr, $entry ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | ▶ | return $entry unless grep { /person/ } $entry->get_value('objectclass'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | return $entry unless $entry->exists($pw_attr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | my $clone = $entry->clone(); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | my @pwlist = (); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | my $regexp = '^' . MD5_PREFIX; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | foreach ( $clone->get_value($pw_attr) ) { | |||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | ▶ | next if /$regexp/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | push @pwlist, _encode_password($_); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | $clone->delete($pw_attr); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | $clone->add( $pw_attr => [@pwlist] ); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | return $clone; | |||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | sub _remove_pw_attr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_pw_attr: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | my ( $pw_attr, $entry ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | my $clone = $entry->clone(); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | $clone->delete($pw_attr) if $clone->exists($pw_attr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | return $clone; | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 3 | ▶ | sub _filter_attrs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filter_attrs: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | my ( $self, $list ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # TODO find a better way to keep the store read-only but not costly to return searches with filtered attributes | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 3 | ▶ | return $list if $self->{user_passwords} eq USER_PW_ALL; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | return [ map { _remove_pw_attr( $self->{user_pw_attr}, $_ ) } @{$list} ] | |||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | ▶ | if $self->{user_passwords} eq USER_PW_NONE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | return [ map { _encode_pw_attr( $self->{user_pw_attr}, $_ ) } @{$list} ] | |||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | if $self->{user_passwords} eq USER_PW_MD5; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 4 | ▶ | sub search { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | my ( $self, $request ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 4 | my $list; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | ▶ | if ( defined( $request->{baseObject} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | my $basedn = canonical_dn( $request->{baseObject} ); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 4 | ▶ | my $scope = $request->{scope} || SCOPE_SUBTREE; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$request->{'scope'} || 2
MC/DC0%0/1
$request->{'scope'} || 2
$request->{'scope'}
Truth table50%1/2
A
A= $request->{'scope'}
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | $list = $self->{store}->list_with_dn_scope( $basedn, $scope ); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | ▶ | return _make_result( LDAP_NO_SUCH_OBJECT, '', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 'Cannot find BaseDN "' . $basedn . '"' ) | ||||||||||||||||||||||||||||||||||||||||||
| 231 | unless defined($list); | ||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $list = $self->{store}->list(); | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 3 | my $match = $self->_filter_attrs( _match( $request->{filter}, $list ) ); | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | return ( _make_result(LDAP_SUCCESS), @{$match} ); | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 40 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | __END__ | ||||||||||||||||||||||||||||||||||||||||||