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