blib/lib/Lemonldap/NG/Portal/Lib/Net/LDAP.pm

filter: Statementstmt 11.8% 38 / 320 Branchbran 0.0% 0 / 204 Conditioncond 0.0% 0 / 92 MC/DCmcdc 0.0% 0 / 57 Subroutinesub 54.5% 12 / 22 Podpod 30.0% 3 / 10 totaltotal 7.5% 53 / 705 CC 139 SCAR 71.7
CC
139
Cov
6%
userModifyPassword
3071.4
new
870.0
searchGroups
210.0
CRAP 1294.0
↑ Summary blib/lib/Lemonldap/NG/Portal/Main/Display.pm »
1 #@file
2 # Extends Net::LDAP
3 package Lemonldap::NG::Portal::Lib::Net::LDAP;
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Net::LDAP; #inherits
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Net::LDAP::Util qw(escape_filter_value);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use base qw(Net::LDAP);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Lemonldap::NG::Portal::Main::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Net::LDAP::Control::PasswordPolicy;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use IO::Socket::Timeout;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Net::LDAP qw(LDAP_PP_PASSWORD_EXPIRED LDAP_PP_ACCOUNT_LOCKED
Subroutine BEGIN: called CC=1 SCAR=0.0
16 LDAP_PP_CHANGE_AFTER_RESET LDAP_PP_PASSWORD_MOD_NOT_ALLOWED
17 LDAP_PP_MUST_SUPPLY_OLD_PASSWORD LDAP_PP_INSUFFICIENT_PASSWORD_QUALITY
18 LDAP_PP_PASSWORD_TOO_SHORT LDAP_PP_PASSWORD_TOO_YOUNG
19 3 LDAP_PP_PASSWORD_IN_HISTORY );
20  
21 3 our $VERSION = '2.23.1';
22  
23 # INITIALIZATION
24  
25 # Build a Net::LDAP object using parameters issued from $portal
26 0 ▶sub new {
Subroutine new: not called CC=29 SCAR=67.7
Pod documented
27 0 my ( $class, $args ) = @_;
28 0 ▶ my $portal = $args->{p} or die "$class: p argument is required!";
Branch: 1 branch
BranchTrueFalseTotal
my $portal = $args->{"p"} or die "${class}: p argument is required!" 0 0 0
29 0 ▶ my $conf = $args->{conf} or die "$class: conf argument is required!";
Branch: 1 branch
BranchTrueFalseTotal
my $conf = $args->{"conf"} or die "${class}: conf argument is required!" 0 0 0
30 0 my ( $self, @servers, %tlsParams );
31 0 my $useStartTls = 0;
32  
33 0 foreach my $server ( split /[\s,]+/, $conf->{ldapServer} ) {
34 0 ▶ if ( $server =~ m{^ldap\+tls://([^/]+)/?\??(.*)$} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($server =~ m[^ldap\+tls://([^/]+)/?\??(.*)$]) { } 0 0 0
elsif ($server =~ m[^(ldaps://[^/]+)/?\??(.*)$]) { } 0 0 0
35 0 $useStartTls = 1;
36 0 $server = $1;
37 0 ▶ %tlsParams = split( /[&=]/, $2 || "" );
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
38 }
39 elsif ( $server =~ m{^(ldaps://[^/]+)/?\??(.*)$} ) {
40 0 $useStartTls = 0;
41 0 $server = $1;
42 0 ▶ %tlsParams = split( /[&=]/, $2 || "" );
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
43 }
44 else {
45 0 $useStartTls = 0;
46 }
47 0 push @servers, $server;
48 }
49 0 ▶ $tlsParams{cafile} ||= $conf->{ldapCAFile} if $conf->{ldapCAFile};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"ldapCAFile"} 0 0 0
Condition0%0/3
$tlsParams{"cafile"} ||= $conf->{"ldapCAFile"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tlsParams{"cafile"} ||= $conf->{"ldapCAFile"}
$tlsParams{"cafile"} $conf->{"ldapCAFile"}
Truth table0%0/3
A ||= B
A= $tlsParams{"cafile"}B= $conf->{"ldapCAFile"}
ABresult
1X1
011
000
50 0 ▶ $tlsParams{capath} ||= $conf->{ldapCAPath} if $conf->{ldapCAPath};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"ldapCAPath"} 0 0 0
Condition0%0/3
$tlsParams{"capath"} ||= $conf->{"ldapCAPath"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tlsParams{"capath"} ||= $conf->{"ldapCAPath"}
$tlsParams{"capath"} $conf->{"ldapCAPath"}
Truth table0%0/3
A ||= B
A= $tlsParams{"capath"}B= $conf->{"ldapCAPath"}
ABresult
1X1
011
000
51 0 ▶ $tlsParams{verify} ||= $conf->{ldapVerify} if $conf->{ldapVerify};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"ldapVerify"} 0 0 0
Condition0%0/3
$tlsParams{"verify"} ||= $conf->{"ldapVerify"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tlsParams{"verify"} ||= $conf->{"ldapVerify"}
$tlsParams{"verify"} $conf->{"ldapVerify"}
Truth table0%0/3
A ||= B
A= $tlsParams{"verify"}B= $conf->{"ldapVerify"}
ABresult
1X1
011
000
52 $tlsParams{clientcert} ||= $conf->{ldapClientCert}
53 0 ▶ if $conf->{ldapClientCert};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"ldapClientCert"} 0 0 0
Condition0%0/3
$tlsParams{"clientcert"} ||= $conf->{"ldapClientCert"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tlsParams{"clientcert"} ||= $conf->{"ldapClientCert"}
$tlsParams{"clientcert"} $conf->{"ldapClientCert"}
Truth table0%0/3
A ||= B
A= $tlsParams{"clientcert"}B= $conf->{"ldapClientCert"}
ABresult
1X1
011
000
54 $tlsParams{clientkey} ||= $conf->{ldapClientKey}
55 0 ▶ if $conf->{ldapClientKey};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"ldapClientKey"} 0 0 0
Condition0%0/3
$tlsParams{"clientkey"} ||= $conf->{"ldapClientKey"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tlsParams{"clientkey"} ||= $conf->{"ldapClientKey"}
$tlsParams{"clientkey"} $conf->{"ldapClientKey"}
Truth table0%0/3
A ||= B
A= $tlsParams{"clientkey"}B= $conf->{"ldapClientKey"}
ABresult
1X1
011
000
56 0 ▶ require Authen::SASL if $conf->{ldapClientCert};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"ldapClientCert"} 0 0 0
57 $self = Net::LDAP->new(
58 \@servers,
59 onerror => undef,
60 keepalive => 1,
61 %tlsParams,
62 ( $conf->{ldapPort} ? ( port => $conf->{ldapPort} ) : () ),
63 ( $conf->{ldapTimeout} ? ( timeout => $conf->{ldapTimeout} ) : () ),
64 ( $conf->{ldapVersion} ? ( version => $conf->{ldapVersion} ) : () ),
65 0 ▶ ( $conf->{ldapRaw} ? ( raw => $conf->{ldapRaw} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
$conf->{'ldapPort'} ? : 0 0 0
$conf->{'ldapTimeout'} ? : 0 0 0
$conf->{'ldapVersion'} ? : 0 0 0
$conf->{'ldapRaw'} ? : 0 0 0
66 );
67 0 ▶ unless ($self) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self) { } 0 0 0
if (do { $Net::LDAP::VERSION < "0.64" }) 0 0 0
68 0 $portal->logger->error( "LDAP initialization error: " . $@ );
69 0 return 0;
70 }
71 0 elsif ( $Net::LDAP::VERSION < '0.64' ) {
72  
73 # CentOS7 has a bug in which IO::Socket::SSL will return a broken
74 # socket when certificate validation fails. Net::LDAP does not catch
75 # it, and the process ends up crashing.
76 # As a precaution, make sure the underlying socket is doing fine:
77 0 ▶ if ( $self->socket->isa('IO::Socket::SSL')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->socket->isa("IO::Socket::SSL") and $self->socket->errstr < 0) 0 0 0
Condition0%0/3
$self->socket->isa("IO::Socket::SSL") and $self->socket->errstr < 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->socket->isa("IO::Socket::SSL") and $self->socket->errstr < 0
$self->socket->isa("IO::Socket::SSL") $self->socket->errstr < 0
Truth table0%0/3
A and B
A= $self->socket->isa("IO::Socket::SSL")B= $self->socket->errstr < 0
ABresult
0X0
100
111
78 and $self->socket->errstr < 0 )
79 {
80 0 $portal->logger->error(
81 "LDAP SSL connection failed: " . $self->socket->errstr );
82 0 return 0;
83 }
84 }
85 0 bless $self, $class;
86  
87 # Set socket timeouts
88 0 my $socket = $self->socket;
89 0 IO::Socket::Timeout->enable_timeouts_on($socket);
90 0 $socket->read_timeout( $conf->{ldapIOTimeout} );
91 0 $socket->write_timeout( $conf->{ldapIOTimeout} );
92  
93 0 ▶ if ($useStartTls) {
Branch: 1 branch
BranchTrueFalseTotal
if ($useStartTls) 0 0 0
94 0 my $mesg = $self->start_tls(%tlsParams);
95 0 ▶ if ( $mesg->code ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code) 0 0 0
96 0 $portal->logger->error( 'LDAP StartTLS failed: ' . $mesg->error );
97 0 return 0;
98 }
99 }
100 0 $self->{portal} = $portal;
101 0 $self->{conf} = $conf;
102 0 weaken $self->{portal};
103  
104 # Setting default LDAP password storage encoding to utf-8
105 0 return $self;
106 }
107  
108 # RUNNING METHODS
109  
110 ## @method Net::LDAP::Message bind(string dn, hash args)
111 # Reimplementation of Net::LDAP::bind(). Connection is done :
112 # - with $dn and $args->{password} as dn/password if defined,
113 # - or with Lemonldap::NG account,
114 # - or with mTLS,
115 # - or with an anonymous bind.
116 # @param $dn LDAP distinguish name
117 # @param %args See Net::LDAP(3) manpage for more
118 # @return Net::LDAP::Message
119 0 ▶sub bind {
Subroutine bind: not called CC=12 SCAR=50.5
Pod documented
120 0 my ( $self, $dn, %args ) = @_;
121 0 my $mesg;
122  
123 0 ▶ $self->{portal}->logger->debug("Call bind for $dn") if $dn;
Branch: 1 branch
BranchTrueFalseTotal
if $dn 0 0 0
124 0 ▶ unless ($dn) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dn) 0 0 0
125 0 $dn = $self->{conf}->{managerDn};
126 $args{password} =
127 0 decode( 'utf-8', $self->{conf}->{managerPassword} );
128 }
129 0 ▶ if ( $dn && $args{password} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dn and $args{'password'}) { } 0 0 0
elsif ($self->{'conf'}{'ldapClientCert'} and $self->{'conf'}{'ldapClientKey'}) { } 0 0 0
Condition0%0/3
$dn and $args{"password"}
!ll&&!rl&&r
000
MC/DC0%0/2
$dn and $args{"password"}
$dn $args{"password"}
Truth table0%0/3
A and B
A= $dnB= $args{"password"}
ABresult
0X0
100
111
130 0 ▶ if ( $self->{conf}->{ldapPwdEnc} ne 'utf-8' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"conf"}{"ldapPwdEnc"} ne "utf-8") 0 0 0
131 0 eval {
132 my $tmp = encode(
133 $self->{conf}->{ldapPwdEnc},
134 decode( 'utf-8', $args{password} )
135 0 );
136 0 $args{password} = $tmp;
137 };
138 0 ▶ print STDERR "$@\n" if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
139 }
140  
141 0 ▶ if ( $self->{conf}->{ldapPpolicyControl} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"conf"}{"ldapPpolicyControl"}) 0 0 0
142 0 my $pp = Net::LDAP::Control::PasswordPolicy->new();
143 0 $args{control} = [$pp];
144 }
145  
146 0 $mesg = $self->SUPER::bind( $dn, %args );
147  
148 0 ▶ if ( $mesg->code ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code) 0 0 0
149 0 my ($resp) = $mesg->control("1.3.6.1.4.1.42.2.27.8.5.1");
150  
151 # Check for ppolicy error
152 0 my ( $llng_code, $ppolicy_error_code, $ppolicy_error_msg ) =
153 $self->check_ppolicy($resp);
154 0 ▶ if ( $llng_code != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($llng_code != 0) { } 0 0 0
155 $self->{portal}->logger->error(
156 0 "Error when service account $dn binding to LDAP server: "
157 . $mesg->error
158 . " | extended ppolicy control response error: $ppolicy_error_msg"
159 );
160 }
161 else {
162 $self->{portal}->logger->error(
163 0 "Error when binding to LDAP server: " . $mesg->error );
164 }
165 }
166 }
167 ▶ elsif ( $self->{conf}->{ldapClientCert} && $self->{conf}->{ldapClientKey} )
Condition0%0/3
$self->{"conf"}{"ldapClientCert"} and $self->{"conf"}{"ldapClientKey"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"conf"}{"ldapClientCert"} and $self->{"conf"}{"ldapClientKey"}
$self->{"conf"}{"ldapClientCert"} $self->{"conf"}{"ldapClientKey"}
Truth table0%0/3
A and B
A= $self->{"conf"}{"ldapClientCert"}B= $self->{"conf"}{"ldapClientKey"}
ABresult
0X0
100
111
168 {
169 0 $self->{portal}->logger->debug('Call mTLS bind');
170 0 my $sasl = Authen::SASL->new(
171 mechanism => 'EXTERNAL',
172 callback => { user => '' }
173 );
174 0 $mesg = $self->SUPER::bind( undef, sasl => $sasl );
175 }
176 else {
177 0 $self->{portal}->logger->debug('Call anonymous bind');
178 0 $mesg = $self->SUPER::bind();
179 }
180 0 return $mesg;
181 }
182  
183 # Check_password policy error code thanks to ldap response
184 # input: ldap response
185 # return: ( llng_code, ppolicy_error_code, ppolicy_error_msg )
186 0 ▶sub check_ppolicy {
Subroutine check_ppolicy: not called CC=4 SCAR=30.0
Pod undocumented
187 0 my $self = shift;
188 0 my $resp = shift;
189 0 ▶ return ( PE_OK, undef, undef ) unless ( defined($resp) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $resp 0 0 0
190  
191 0 my $PPOLICY_ERRORS = {
192 LDAP_PP_PASSWORD_EXPIRED() =>
193 [ PE_PP_PASSWORD_EXPIRED, "password expired" ],
194 LDAP_PP_ACCOUNT_LOCKED() => [ PE_PP_ACCOUNT_LOCKED, "account locked" ],
195 LDAP_PP_CHANGE_AFTER_RESET() =>
196 [ PE_PP_CHANGE_AFTER_RESET, "change after reset" ],
197 LDAP_PP_PASSWORD_MOD_NOT_ALLOWED() =>
198 [ PE_PP_PASSWORD_MOD_NOT_ALLOWED, "password mod not allowed" ],
199 LDAP_PP_MUST_SUPPLY_OLD_PASSWORD() =>
200 [ PE_PP_MUST_SUPPLY_OLD_PASSWORD, "supply old password" ],
201 LDAP_PP_INSUFFICIENT_PASSWORD_QUALITY() => [
202 PE_PP_INSUFFICIENT_PASSWORD_QUALITY,
203 "insufficient password quality"
204 ],
205 LDAP_PP_PASSWORD_TOO_SHORT() =>
206 [ PE_PP_PASSWORD_TOO_SHORT, "password too short" ],
207 LDAP_PP_PASSWORD_TOO_YOUNG() =>
208 [ PE_PP_PASSWORD_TOO_YOUNG, "password too young" ],
209 LDAP_PP_PASSWORD_IN_HISTORY() =>
210 [ PE_PP_PASSWORD_IN_HISTORY, "password in history" ]
211 };
212  
213 0 my $ppolicy_error_code = $resp->pp_error;
214  
215 0 ▶ if ( defined $ppolicy_error_code
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ppolicy_error_code and $PPOLICY_ERRORS->{$ppolicy_error_code}) 0 0 0
Condition0%0/3
defined $ppolicy_error_code and $PPOLICY_ERRORS->{$ppolicy_error_code}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ppolicy_error_code and $PPOLICY_ERRORS->{$ppolicy_error_code}
defined $ppolicy_error_code $PPOLICY_ERRORS->{$ppolicy_error_code}
Truth table0%0/3
A and B
A= defined $ppolicy_error_codeB= $PPOLICY_ERRORS->{$ppolicy_error_code}
ABresult
0X0
100
111
216 and $PPOLICY_ERRORS->{$ppolicy_error_code} )
217 {
218  
219 # return: ( llng_code, ppolicy_error_code, ppolicy_error_msg )
220 return ( $PPOLICY_ERRORS->{$ppolicy_error_code}->[0],
221 0 $ppolicy_error_code, $PPOLICY_ERRORS->{$ppolicy_error_code}->[1] );
222 }
223 0 return ( PE_OK, undef, undef );
224 }
225  
226 ## @method Net::LDAP::Message unbind()
227 # Reimplementation of Net::LDAP::unbind() to force call to disconnect()
228 # @return Net::LDAP::Message
229 0 ▶sub unbind {
Subroutine unbind: not called CC=1 SCAR=6.9
Pod documented
230 0 my $self = shift;
231 0 my $ldap_uri = $self->uri;
232  
233 0 $self->{portal}->logger->debug("Unbind and disconnect from $ldap_uri");
234  
235 0 my $mesg = $self->SUPER::unbind();
236 0 $self->SUPER::disconnect();
237  
238 0 return $mesg;
239 }
240  
241 ## @method protected int userBind(string dn, hash args)
242 # Call bind() with dn/password and return
243 # @param $dn LDAP distinguish name
244 # @param %args See Net::LDAP(3) manpage for more
245 # @return Lemonldap::NG portal error code
246 0 ▶sub userBind {
Subroutine userBind: not called CC=12 SCAR=50.5
Pod undocumented
247 0 my $self = shift;
248 0 my $req = shift;
249  
250 0 ▶ if ( $self->{conf}->{ldapPpolicyControl} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'conf'}{'ldapPpolicyControl'}) { } 0 0 0
251  
252 # Create Control object
253 0 my $pp = Net::LDAP::Control::PasswordPolicy->new();
254  
255 # Bind with user credentials
256 0 my $mesg = $self->bind( @_, control => [$pp] );
257  
258 # Get server control response
259 0 my ($resp) = $mesg->control("1.3.6.1.4.1.42.2.27.8.5.1");
260  
261 # Return direct unless control response
262 0 ▶ unless ( defined $resp ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $resp) 0 0 0
263 0 ▶ if ( $mesg->code == 49 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mesg->code == 49) { } 0 0 0
elsif ($mesg->code == 0) { } 0 0 0
264 $self->{portal}->userLogger->warn(
265 0 "Bad password for $req->{user} (" . $req->address . ")" );
266 0 return PE_BADCREDENTIALS;
267 }
268 elsif ( $mesg->code == 0 ) {
269 0 return PE_OK;
270 }
271 else {
272 0 $self->{portal}->logger->error( "Bind failed with error "
273 . $mesg->code . ": "
274 . $mesg->error );
275 0 return PE_LDAPERROR;
276 }
277 }
278  
279 # Check for ppolicy error
280 0 my ( $llng_code, $ppolicy_error_code, $ppolicy_error_msg ) =
281 $self->check_ppolicy($resp);
282 0 ▶ if ( $llng_code != 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($llng_code != 0) { } 0 0 0
elsif ($mesg->code == 0) { } 0 0 0
283 $self->{portal}->userLogger->error(
284 0 "Password policy error $ppolicy_error_code ($ppolicy_error_msg) for "
285 . $req->user );
286 0 return $llng_code;
287 }
288 elsif ( $mesg->code == 0 ) {
289  
290 # Get expiration warning and graces
291 0 ▶ if ( defined( $resp->grace_authentications_remaining ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resp->grace_authentications_remaining) 0 0 0
292 $self->{portal}->logger->debug(
293 0 "LDAP password policy - grace authentications remaining: "
294 . $resp->grace_authentications_remaining );
295 $req->info(
296 $self->{portal}->loadTemplate(
297 0 $req,
298 'ldapPpGrace',
299 params => {
300 number => $resp->grace_authentications_remaining
301 }
302 )
303 );
304 }
305  
306 0 ▶ if ( my $time_before_exp = $resp->time_before_expiration ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $time_before_exp = $resp->time_before_expiration) 0 0 0
307 $self->{portal}->logger->debug(
308 0 "LDAP password policy - time before expiration: "
309 . $time_before_exp );
310 0 ▶ if ( $self->{conf}->{ldapForcePasswordChangeExpirationWarning}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"} and $time_before_exp < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}) 0 0 0
Condition0%0/3
$self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"} and $time_before_exp < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"} and $time_before_exp < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}
$self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"} $time_before_exp < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}
Truth table0%0/3
A and B
A= $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}B= $time_before_exp < $self->{"conf"}{"ldapForcePasswordChangeExpirationWarning"}
ABresult
0X0
100
111
311 and $time_before_exp <
312 $self->{conf}->{ldapForcePasswordChangeExpirationWarning} )
313 {
314 $self->{portal}->logger->debug(
315 0 "Force password change on expiration warning");
316 0 return PE_PP_PASSWORD_EXPIRES_SOON;
317 }
318 $req->info(
319 $self->{portal}->loadTemplate(
320 0 $req,
321 'simpleInfo',
322 params => {
323 trspan => 'pwdWillExpire,'
324 . join( ',', $self->convertSec($time_before_exp) )
325 }
326 )
327 );
328 }
329  
330 0 return PE_OK;
331 }
332 }
333 else {
334 0 my $mesg = $self->bind(@_);
335 0 ▶ if ( $mesg->code == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code == 0) { } 0 0 0
336 0 return PE_OK;
337 }
338 else {
339 0 $req->data->{ldapError} = $mesg->error;
340 }
341 }
342 $self->{portal}->userLogger->warn(
343 0 "Bad password for $req->{user} (" . $req->address . ")" );
344 0 return PE_BADCREDENTIALS;
345 }
346  
347 ## @method int userModifyPassword(string dn, string newpassword, string oldpassword, boolean ad, boolean requireOldPassword)
348 # Change user's password.
349 # @param $dn DN
350 # @param $newpassword New password
351 # @param $oldpassword Current password
352 # @param $ad Active Directory mode
353 # @param $requireOldPassword Old password is needed to update
354 # @return Lemonldap::NG::Portal constant
355 0 ▶sub userModifyPassword {
Subroutine userModifyPassword: not called CC=56 SCAR=80.3
Pod undocumented
356 0 my ( $self, $dn, $newpassword, $oldpassword, $ad, $requireOldPassword ) =
357 @_;
358 0 my $ppolicyControl = $self->{conf}->{ldapPpolicyControl};
359 0 my $setPassword = $self->{conf}->{ldapSetPassword};
360 0 my $asUser = $self->{conf}->{ldapChangePasswordAsUser};
361 0 my $passwordAttribute = "userPassword";
362 0 my $err;
363 my $mesg;
364  
365 0 utf8::downgrade($dn);
366 0 $self->{portal}->logger->debug("Call modify password for $dn");
367  
368 # Adjust configuration for AD
369 0 ▶ if ($ad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ad) 0 0 0
370 0 $ppolicyControl = 0;
371 0 $setPassword = 0;
372 0 $passwordAttribute = "unicodePwd";
373  
374 # Encode password for AD
375 0 $newpassword = encode( "UTF-16LE",
376 decode( "UTF-8", chr(34) . $newpassword . chr(34) ) );
377 0 ▶ if ( $oldpassword and $asUser ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldpassword and $asUser) 0 0 0
Condition0%0/3
$oldpassword and $asUser
!ll&&!rl&&r
000
MC/DC0%0/2
$oldpassword and $asUser
$oldpassword $asUser
Truth table0%0/3
A and B
A= $oldpasswordB= $asUser
ABresult
0X0
100
111
378 0 $oldpassword = encode( "UTF-16LE",
379 decode( "UTF-8", chr(34) . $oldpassword . chr(34) ) );
380 }
381 0 $self->{portal}->logger->debug("Active Directory mode enabled");
382  
383 }
384  
385 # First case: no ppolicy
386 0 ▶ if ( !$ppolicyControl ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ppolicyControl) { } 0 0 0
387  
388 0 ▶ if ($setPassword) {
Branch: 1 branch
BranchTrueFalseTotal
if ($setPassword) { } 0 0 0
389  
390 # Bind as user if oldpassword and ldapChangePasswordAsUser
391 0 ▶ if ( $oldpassword and $asUser ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldpassword and $asUser) 0 0 0
Condition0%0/3
$oldpassword and $asUser
!ll&&!rl&&r
000
MC/DC0%0/2
$oldpassword and $asUser
$oldpassword $asUser
Truth table0%0/3
A and B
A= $oldpasswordB= $asUser
ABresult
0X0
100
111
392  
393 0 $mesg = $self->bind( $dn, password => $oldpassword );
394 0 ▶ if ( $mesg->code != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code != 0) 0 0 0
395 0 $self->{portal}->userLogger->notice("Bad old password");
396 0 return PE_BADOLDPASSWORD;
397 }
398 }
399  
400 # Use SetPassword extended operation
401 0 require Net::LDAP::Extension::SetPassword;
402 0 ▶ $mesg =
Branch: 1 branch
BranchTrueFalseTotal
$oldpassword ? : 0 0 0
403 ($oldpassword)
404 ? $self->set_password(
405 user => $dn,
406 oldpasswd => $oldpassword,
407 newpasswd => $newpassword
408 )
409 : $self->set_password(
410 user => $dn,
411 newpasswd => $newpassword
412 );
413  
414 # Catch the "Unwilling to perform" error
415 0 ▶ if ( $mesg->code == 53 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code == 53) 0 0 0
416 0 $self->{portal}->userLogger->notice("Bad old password");
417 0 return PE_BADOLDPASSWORD;
418 }
419 }
420 else {
421  
422 # AD specific
423 # Change password as user with a delete/add modification
424 0 ▶ if ( $ad and $oldpassword and $asUser ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ad and $oldpassword and $asUser) { } 0 0 0
Condition0%0/6
$ad and $oldpassword and $asUser
!ll&&!rl&&r
000
$ad and $oldpassword
!ll&&!rl&&r
000
MC/DC0%0/3
$ad and $oldpassword and $asUser
$ad $oldpassword $asUser
Truth table0%0/4
A and B and C
A= $adB= $oldpasswordC= $asUser
ABCresult
0XX0
10X0
1100
1111
425 0 $mesg = $self->modify(
426 $dn,
427 changes => [
428 delete => [ $passwordAttribute => $oldpassword ],
429 add => [ $passwordAttribute => $newpassword ]
430 ]
431 );
432 }
433  
434 else {
435 0 ▶ if ($requireOldPassword) {
Branch: 1 branch
BranchTrueFalseTotal
if ($requireOldPassword) 0 0 0
436  
437 0 ▶ return PE_MUST_SUPPLY_OLD_PASSWORD if ( !$oldpassword );
Branch: 1 branch
BranchTrueFalseTotal
unless $oldpassword 0 0 0
438  
439 # Check old password with a bind
440 0 $mesg = $self->bind( $dn, password => $oldpassword );
441  
442 # For AD password expiration to work:
443 # ppolicy must be desactivated,
444 # and "change as user" must be desactivated
445 0 ▶ if ($ad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ad) { } 0 0 0
446 0 ▶ if ( $mesg->error =~ /LdapErr: .* data ([^,]+),.*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->error =~ /LdapErr: .* data ([^,]+),.*/) 0 0 0
447  
448 # extended data message code:
449 # 532: password expired (but provided password is correct)
450 # 773: must change password at next connection (but provided password is correct)
451 # 52e: password is incorrect
452 0 ▶ unless ( ( $1 eq '532' ) || ( $1 eq '773' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($1 eq 532 or $1 eq 773) 0 0 0
Condition0%0/3
$1 eq 532 or $1 eq 773
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 eq 532 or $1 eq 773
$1 eq 532 $1 eq 773
Truth table0%0/3
A or B
A= $1 eq 532B= $1 eq 773
ABresult
1X1
011
000
453 $self->{portal}
454 0 ->userLogger->warn("Bad old password");
455 0 return PE_BADOLDPASSWORD;
456 }
457 }
458  
459 # if error message has not been catched, then it IS a success
460 }
461 else
462 { # this is not AD, a 0 error code means good old password
463 0 ▶ if ( $mesg->code != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code != 0) 0 0 0
464 $self->{portal}
465 0 ->userLogger->warn('Bad old password');
466 0 return PE_BADOLDPASSWORD;
467 }
468 }
469  
470 # Rebind as Manager only if user is not granted to change its password
471 0 ▶ $self->bind() unless $asUser;
Branch: 1 branch
BranchTrueFalseTotal
unless $asUser 0 0 0
472 }
473  
474 # Use standard modification
475 $mesg =
476 0 $self->modify( $dn,
477 replace => { $passwordAttribute => $newpassword } );
478 }
479 }
480 $self->{portal}
481 0 ->logger->debug( 'Modification return code: ' . $mesg->code );
482 $self->{portal}
483 0 ->logger->debug( 'Modification return error: ' . $mesg->error );
484  
485 # Manage specific errors for IBM Tivoli DS
486 0 ▶ if ( $self->{conf}->{ldapITDS} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"conf"}{"ldapITDS"}) 0 0 0
487 0 my $itds_code = $self->getITDSError($mesg);
488 0 ▶ return $itds_code unless ( $itds_code == PE_PASSWORD_OK );
Branch: 1 branch
BranchTrueFalseTotal
unless $itds_code == 35 0 0 0
489 }
490  
491 # Manage specific errors for Active Directory
492 0 ▶ if ($ad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ad) 0 0 0
493 0 ▶ return PE_PP_INSUFFICIENT_PASSWORD_QUALITY
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 53 0 0 0
494 if ( $mesg->code == 53 );
495 0 ▶ return PE_PP_PASSWORD_MOD_NOT_ALLOWED
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 19 0 0 0
496 if ( $mesg->code == 19 );
497 }
498  
499 # Standard errors
500 0 ▶ return PE_WRONGMANAGERACCOUNT
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 50 or $mesg->code == 8 0 0 0
Condition0%0/3
$mesg->code == 50 or $mesg->code == 8
l!l&&r!l&&!r
000
MC/DC0%0/2
$mesg->code == 50 or $mesg->code == 8
$mesg->code == 50 $mesg->code == 8
Truth table0%0/3
A or B
A= $mesg->code == 50B= $mesg->code == 8
ABresult
1X1
011
000
501 if ( $mesg->code == 50 || $mesg->code == 8 );
502 0 ▶ unless ( $mesg->code == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mesg->code == 0) 0 0 0
503 $self->{portal}
504 0 ->logger->error( "Password modification failed with LDAP error "
505 . $mesg->code . ": "
506 . $mesg->error );
507 0 return PE_LDAPERROR;
508 }
509  
510 0 $self->{portal}->logger->notice("Password changed for $dn");
511  
512 # Rebind as manager for next LDAP operations if we were bound as user
513 0 ▶ $self->bind() if $asUser;
Branch: 1 branch
BranchTrueFalseTotal
if $asUser 0 0 0
514  
515 0 return PE_PASSWORD_OK;
516 }
517 else {
518  
519 # Create Control object
520 0 my $pp = Net::LDAP::Control::PasswordPolicy->new;
521  
522 0 ▶ if ($setPassword) {
Branch: 1 branch
BranchTrueFalseTotal
if ($setPassword) { } 0 0 0
523  
524 # Bind as user if oldpassword and ldapChangePasswordAsUser
525 0 ▶ if ( $oldpassword and $asUser ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldpassword and $asUser) 0 0 0
Condition0%0/3
$oldpassword and $asUser
!ll&&!rl&&r
000
MC/DC0%0/2
$oldpassword and $asUser
$oldpassword $asUser
Truth table0%0/3
A and B
A= $oldpasswordB= $asUser
ABresult
0X0
100
111
526  
527 0 $mesg = $self->bind(
528 $dn,
529 password => $oldpassword,
530 control => [$pp]
531 );
532 0 my ($bind_resp) = $mesg->control("1.3.6.1.4.1.42.2.27.8.5.1");
533  
534 0 ▶ unless ( defined $bind_resp ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bind_resp) { } 0 0 0
535 0 ▶ if ( $mesg->code != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code != 0) 0 0 0
536 0 $self->{portal}->logger->debug("Bad old password");
537 0 return PE_BADOLDPASSWORD;
538 }
539 }
540 else {
541  
542 # Check if password is expired
543 0 my $pp_error = $bind_resp->pp_error;
544 0 ▶ if ( defined $pp_error
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pp_error and $pp_error == 0 and $self->{'conf'}{'ldapAllowResetExpiredPassword'}) { } 0 0 0
Condition0%0/6
defined $pp_error and $pp_error == 0 and $self->{"conf"}{"ldapAllowResetExpiredPassword"}
!ll&&!rl&&r
000
defined $pp_error and $pp_error == 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $pp_error and $pp_error == 0 and $self->{"conf"}{"ldapAllowResetExpiredPassword"}
defined $pp_error $pp_error == 0 $self->{"conf"}{"ldapAllowResetExpiredPassword"}
Truth table0%0/4
A and B and C
A= defined $pp_errorB= $pp_error == 0C= $self->{"conf"}{"ldapAllowResetExpiredPassword"}
ABCresult
0XX0
10X0
1100
1111
545 and $pp_error == 0
546 and $self->{conf}->{ldapAllowResetExpiredPassword} )
547 {
548 $self->{portal}->logger->debug(
549 0 "Password is expired but user is allowed to change it"
550 );
551 }
552 else {
553 0 ▶ if ( $mesg->code != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code != 0) 0 0 0
554 0 $self->{portal}->logger->debug("Bad old password");
555 0 return PE_BADOLDPASSWORD;
556 }
557 }
558 }
559 }
560  
561 # Use SetPassword extended operation
562 # Warning: need a patch on Perl-LDAP
563 # See http://groups.google.com/group/perl.ldap/browse_thread/thread/5703a41ccb17b221/377a68f872cc2bb4?lnk=gst&q=setpassword#377a68f872cc2bb4
564 3 ▶ use Net::LDAP::Extension::SetPassword;
Subroutine BEGIN: called CC=1 SCAR=0.0
565 0 ▶ $mesg =
Branch: 1 branch
BranchTrueFalseTotal
$oldpassword ? : 0 0 0
566 ($oldpassword)
567 ? $self->set_password(
568 user => $dn,
569 oldpasswd => $oldpassword,
570 newpasswd => $newpassword,
571 control => [$pp]
572 )
573 : $self->set_password(
574 user => $dn,
575 newpasswd => $newpassword,
576 control => [$pp]
577 );
578  
579 # Catch the "Unwilling to perform" error
580 0 ▶ if ( $mesg->code == 53 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code == 53) 0 0 0
581 0 $self->{portal}->logger->debug("Bad old password");
582 0 return PE_BADOLDPASSWORD;
583 }
584 }
585 else {
586 0 ▶ if ($oldpassword) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldpassword) 0 0 0
587  
588 # Check old password with a bind
589 0 $mesg = $self->bind(
590 $dn,
591 password => $oldpassword,
592 control => [$pp]
593 );
594 0 my ($bind_resp) = $mesg->control("1.3.6.1.4.1.42.2.27.8.5.1");
595  
596 0 ▶ unless ( defined $bind_resp ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bind_resp) { } 0 0 0
597 0 ▶ if ( $mesg->code != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code != 0) 0 0 0
598 0 $self->{portal}->logger->debug("Bad old password");
599 0 return PE_BADOLDPASSWORD;
600 }
601 }
602 else {
603  
604 # Check if password is expired
605 0 my $pp_error = $bind_resp->pp_error;
606 0 ▶ if ( defined $pp_error
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pp_error and $pp_error == 0 and $self->{'conf'}{'ldapAllowResetExpiredPassword'}) { } 0 0 0
Condition0%0/6
defined $pp_error and $pp_error == 0 and $self->{"conf"}{"ldapAllowResetExpiredPassword"}
!ll&&!rl&&r
000
defined $pp_error and $pp_error == 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $pp_error and $pp_error == 0 and $self->{"conf"}{"ldapAllowResetExpiredPassword"}
defined $pp_error $pp_error == 0 $self->{"conf"}{"ldapAllowResetExpiredPassword"}
Truth table0%0/4
A and B and C
A= defined $pp_errorB= $pp_error == 0C= $self->{"conf"}{"ldapAllowResetExpiredPassword"}
ABCresult
0XX0
10X0
1100
1111
607 and $pp_error == 0
608 and $self->{conf}->{ldapAllowResetExpiredPassword} )
609 {
610 $self->{portal}->logger->debug(
611 0 "Password is expired but user is allowed to change it"
612 );
613 }
614 else {
615 0 ▶ if ( $mesg->code != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code != 0) 0 0 0
616 0 $self->{portal}->logger->debug("Bad old password");
617 0 return PE_BADOLDPASSWORD;
618 }
619 }
620 }
621  
622 # Rebind as Manager only if user is not granted to change its password
623 0 ▶ $self->bind()
Branch: 1 branch
BranchTrueFalseTotal
unless $asUser 0 0 0
624 unless $asUser;
625 }
626  
627 # Use standard modification
628 0 $mesg = $self->modify(
629 $dn,
630 replace => { $passwordAttribute => $newpassword },
631 control => [$pp]
632 );
633 }
634  
635 # Get server control response
636 0 my ($resp) = $mesg->control("1.3.6.1.4.1.42.2.27.8.5.1");
637  
638 $self->{portal}
639 0 ->logger->debug( "Modification return code: " . $mesg->code );
640 0 ▶ return PE_WRONGMANAGERACCOUNT
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 50 or $mesg->code == 8 0 0 0
Condition0%0/3
$mesg->code == 50 or $mesg->code == 8
l!l&&r!l&&!r
000
MC/DC0%0/2
$mesg->code == 50 or $mesg->code == 8
$mesg->code == 50 $mesg->code == 8
Truth table0%0/3
A or B
A= $mesg->code == 50B= $mesg->code == 8
ABresult
1X1
011
000
641 if ( $mesg->code == 50 || $mesg->code == 8 );
642 0 ▶ if ( $mesg->code == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code == 0) 0 0 0
643 0 $self->{portal}->logger->notice("Password changed for $dn");
644  
645 # Rebind as manager for next LDAP operations if we were bound as user
646 0 ▶ $self->bind() if $asUser;
Branch: 1 branch
BranchTrueFalseTotal
if $asUser 0 0 0
647  
648 0 return PE_PASSWORD_OK;
649 }
650  
651 0 ▶ if ( defined $resp ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resp) { } 0 0 0
652 0 my $pp_error = $resp->pp_error;
653 0 ▶ if ( defined $pp_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pp_error) 0 0 0
654 $self->{portal}
655 0 ->logger->error("Password policy error $pp_error");
656 return [
657 0 PE_PP_PASSWORD_EXPIRED,
658 PE_PP_ACCOUNT_LOCKED,
659 PE_PP_CHANGE_AFTER_RESET,
660 PE_PP_PASSWORD_MOD_NOT_ALLOWED,
661 PE_PP_MUST_SUPPLY_OLD_PASSWORD,
662 PE_PP_INSUFFICIENT_PASSWORD_QUALITY,
663 PE_PP_PASSWORD_TOO_SHORT,
664 PE_PP_PASSWORD_TOO_YOUNG,
665 PE_PP_PASSWORD_IN_HISTORY,
666 ]->[$pp_error];
667 }
668 }
669 else {
670 $self->{portal}->logger->error(
671 0 "Missing PPolicy control from server response. Code: "
672 . $mesg->code );
673 0 return PE_LDAPERROR;
674 }
675 }
676 }
677  
678 ## @method string searchGroups(string base, string key, string value, string attributes, hashref dupcheck)
679 # Get groups from LDAP directory
680 # @param base LDAP search base
681 # @param key Attribute name in group containing searched value
682 # @param value Searched value
683 # @param attributes to get from found groups (array ref)
684 # @param dupcheck to get from found groups (hash ref)
685 # @return hashRef groups
686 0 ▶sub searchGroups {
Subroutine searchGroups: not called CC=14 SCAR=53.5
Pod undocumented
687 0 my ( $self, $base, $key, $value, $attributes, $dupcheck ) = @_;
688  
689 0 ▶ $dupcheck ||= {};
Condition0%0/2
$dupcheck ||= {}
l!l
00
MC/DC0%0/1
$dupcheck ||= {}
$dupcheck
Truth table0%0/2
A
A= $dupcheck
Aresult
11
00
690 0 my $groups = {};
691  
692 # Creating search filter
693 my $groupSearchFilter = $self->{conf}->{groupLDAPFilter}
694 0 ▶ || "(objectClass=" . $self->{conf}->{ldapGroupObjectClass} . ")";
Condition0%0/2
$self->{'conf'}{'groupLDAPFilter'} || '(objectClass=' . $self->{'conf'}{'ldapGroupObjectClass'} . ')'
l!l
00
MC/DC0%0/1
$self->{'conf'}{'groupLDAPFilter'} || '(objectClass=' . $self->{'conf'}{'ldapGroupObjectClass'} . ')'
$self->{'conf'}{'groupLDAPFilter'}
Truth table0%0/2
A
A= $self->{'conf'}{'groupLDAPFilter'}
Aresult
11
00
695 0 my $searchFilter = "(&" . $groupSearchFilter . "(|";
696 0 foreach ( split( $self->{conf}->{multiValuesSeparator}, $value ) ) {
697 0 $searchFilter .= "(" . $key . "=" . escape_filter_value($_) . ")";
698 }
699 0 $searchFilter .= "))";
700  
701 0 $self->{portal}->logger->debug("Group search filter: $searchFilter");
702  
703 # Search
704 0 my $mesg = $self->search(
705 base => $base,
706 filter => $searchFilter,
707 attrs => $attributes,
708 );
709  
710 # Browse results
711 0 ▶ if ( $mesg->code() == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mesg->code == 0) 0 0 0
712  
713 0 foreach my $entry ( $mesg->all_entries ) {
714  
715 $self->{portal}
716 0 ->logger->debug( "Matching group " . $entry->dn() . " found" );
717  
718 # If recursive search is activated, do it here
719 0 ▶ if ( $self->{conf}->{ldapGroupRecursive} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"conf"}{"ldapGroupRecursive"}) 0 0 0
720  
721 # Get searched value
722 my $group_value =
723 $self->getLdapValue( $entry,
724 0 $self->{conf}->{ldapGroupAttributeNameGroup} );
725  
726 # Launch group search
727 0 ▶ if ($group_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group_value) 0 0 0
728 0 ▶ if ( $self->{conf}->{ldapGroupDecodeSearchedValue} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"conf"}{"ldapGroupDecodeSearchedValue"}) 0 0 0
729 0 utf8::decode($group_value);
730 }
731  
732 0 ▶ if ( $dupcheck->{$group_value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dupcheck->{$group_value}) { } 0 0 0
733 $self->{portal}->logger->debug(
734 0 "Disable search for $group_value, as it was already searched"
735 );
736 }
737 else {
738 0 $dupcheck->{$group_value} = 1;
739 $self->{portal}
740 0 ->logger->debug("Recursive search for $group_value");
741  
742 0 my $recursive_groups =
743 $self->searchGroups( $base, $key, $group_value,
744 $attributes, $dupcheck );
745  
746 0 ▶ my %allGroups = ( %$groups, %$recursive_groups )
Branch: 1 branch
BranchTrueFalseTotal
if ref $recursive_groups 0 0 0
747 if ( ref $recursive_groups );
748 0 $groups = \%allGroups;
749  
750 }
751 }
752 }
753  
754 # Use first attribute as group name
755 0 my $groupName = $entry->get_value( $attributes->[0] );
756 0 $groups->{$groupName}->{name} = $groupName;
757  
758 # Now parse attributes
759 0 foreach (@$attributes) {
760  
761 # Next if group attribute value
762 next
763 0 ▶ if ( $_ eq $self->{conf}->{ldapGroupAttributeValueGroup} );
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $self->{"conf"}{"ldapGroupAttributeValueGroup"} 0 0 0
764  
765 0 my $data = $entry->get_value( $_, asref => 1 );
766  
767 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
768 $self->{portal}
769 0 ->logger->debug("Store values of $_ in group $groupName");
770 0 $groups->{$groupName}->{$_} = $data;
771 }
772 }
773 }
774 }
775  
776 0 return $groups;
777 }
778  
779 ## @method string getLdapValue(Net::LDAP::Entry entry, string attribute)
780 # Get the dn, or the attribute value with a separator for multi-valuated attributes
781 # @param entry LDAP entry
782 # @param attribute Attribute name
783 # @return string value
784 0 ▶sub getLdapValue {
Subroutine getLdapValue: not called CC=2 SCAR=17.9
Pod undocumented
785 0 my ( $self, $entry, $attribute ) = @_;
786  
787 0 ▶ return $entry->dn() if ( $attribute eq "dn" );
Branch: 1 branch
BranchTrueFalseTotal
if $attribute eq "dn" 0 0 0
788  
789 return join(
790 $self->{conf}->{multiValuesSeparator},
791 0 $entry->get_value($attribute)
792 );
793 }
794  
795 # Convert seconds to hours, minutes, seconds
796 0 ▶sub convertSec {
Subroutine convertSec: not called CC=4 SCAR=30.0
Pod undocumented
797 0 my ( $self, $sec ) = @_;
798 0 my ( $day, $hrs, $min ) = ( 0, 0, 0 );
799  
800 # Calculate the minutes
801 0 ▶ if ( $sec > 60 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec > 60) 0 0 0
802 0 $min = $sec / 60, $sec %= 60;
803 0 $min = int($min);
804 }
805  
806 # Calculate the hours
807 0 ▶ if ( $min > 60 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min > 60) 0 0 0
808 0 $hrs = $min / 60, $min %= 60;
809 0 $hrs = int($hrs);
810 }
811  
812 # Calculate the days
813 0 ▶ if ( $hrs > 24 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hrs > 24) 0 0 0
814 0 $day = $hrs / 24, $hrs %= 24;
815 0 $day = int($day);
816 }
817  
818 # Return the date
819 0 return ( $day, $hrs, $min, $sec );
820 }
821  
822 ## @method int getITDSError(Net::LDAP::Message mesg)
823 # Check error message to return according error code
824 # @param mesg Modification return message
825 # @return portal error code
826 0 ▶sub getITDSError {
Subroutine getITDSError: not called CC=14 SCAR=53.5
Pod undocumented
827 0 my ( $self, $mesg ) = @_;
828  
829 0 ▶ return PE_PP_MUST_SUPPLY_OLD_PASSWORD
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 53 and $mesg->error =~ /Must supply old password/i 0 0 0
Condition0%0/3
$mesg->code == 53 and $mesg->error =~ /Must supply old password/i
!ll&&!rl&&r
000
MC/DC0%0/2
$mesg->code == 53 and $mesg->error =~ /Must supply old password/i
$mesg->code == 53 $mesg->error =~ /Must supply old password/i
Truth table0%0/3
A and B
A= $mesg->code == 53B= $mesg->error =~ /Must supply old password/i
ABresult
0X0
100
111
830 if ( $mesg->code == 53 && $mesg->error =~ /Must supply old password/i );
831 0 ▶ return PE_PP_CHANGE_AFTER_RESET
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 53 and $mesg->error =~ /Password must be changed after reset/i 0 0 0
Condition0%0/3
$mesg->code == 53 and $mesg->error =~ /Password must be changed after reset/i
!ll&&!rl&&r
000
MC/DC0%0/2
$mesg->code == 53 and $mesg->error =~ /Password must be changed after reset/i
$mesg->code == 53 $mesg->error =~ /Password must be changed after reset/i
Truth table0%0/3
A and B
A= $mesg->code == 53B= $mesg->error =~ /Password must be changed after reset/i
ABresult
0X0
100
111
832 if ( $mesg->code == 53
833 && $mesg->error =~ /Password must be changed after reset/i );
834 0 ▶ return PE_PP_PASSWORD_MOD_NOT_ALLOWED
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 53 and $mesg->error =~ /Password may not be modified/i 0 0 0
Condition0%0/3
$mesg->code == 53 and $mesg->error =~ /Password may not be modified/i
!ll&&!rl&&r
000
MC/DC0%0/2
$mesg->code == 53 and $mesg->error =~ /Password may not be modified/i
$mesg->code == 53 $mesg->error =~ /Password may not be modified/i
Truth table0%0/3
A and B
A= $mesg->code == 53B= $mesg->error =~ /Password may not be modified/i
ABresult
0X0
100
111
835 if ( $mesg->code == 53
836 && $mesg->error =~ /Password may not be modified/i );
837 0 ▶ return PE_PP_PASSWORD_TOO_YOUNG
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 19 and $mesg->error =~ /Password too young/i 0 0 0
Condition0%0/3
$mesg->code == 19 and $mesg->error =~ /Password too young/i
!ll&&!rl&&r
000
MC/DC0%0/2
$mesg->code == 19 and $mesg->error =~ /Password too young/i
$mesg->code == 19 $mesg->error =~ /Password too young/i
Truth table0%0/3
A and B
A= $mesg->code == 19B= $mesg->error =~ /Password too young/i
ABresult
0X0
100
111
838 if ( $mesg->code == 19 && $mesg->error =~ /Password too young/i );
839 0 ▶ return PE_PP_PASSWORD_TOO_SHORT
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 19 and $mesg->error =~ /Password too short/i 0 0 0
Condition0%0/3
$mesg->code == 19 and $mesg->error =~ /Password too short/i
!ll&&!rl&&r
000
MC/DC0%0/2
$mesg->code == 19 and $mesg->error =~ /Password too short/i
$mesg->code == 19 $mesg->error =~ /Password too short/i
Truth table0%0/3
A and B
A= $mesg->code == 19B= $mesg->error =~ /Password too short/i
ABresult
0X0
100
111
840 if ( $mesg->code == 19 && $mesg->error =~ /Password too short/i );
841 0 ▶ return PE_PP_PASSWORD_IN_HISTORY
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 19 and $mesg->error =~ /Password in History/i 0 0 0
Condition0%0/3
$mesg->code == 19 and $mesg->error =~ /Password in History/i
!ll&&!rl&&r
000
MC/DC0%0/2
$mesg->code == 19 and $mesg->error =~ /Password in History/i
$mesg->code == 19 $mesg->error =~ /Password in History/i
Truth table0%0/3
A and B
A= $mesg->code == 19B= $mesg->error =~ /Password in History/i
ABresult
0X0
100
111
842 if ( $mesg->code == 19 && $mesg->error =~ /Password in History/i );
843 0 ▶ return PE_PP_INSUFFICIENT_PASSWORD_QUALITY if ( $mesg->code == 19 );
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->code == 19 0 0 0
844  
845 0 return PE_PASSWORD_OK;
846 }
847  
848 3 1;
↑ Summary blib/lib/Lemonldap/NG/Portal/Main/Display.pm »