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

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