| 1 | package Web::Session::LDAP; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Apache::Session; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Apache::Session::Lock::Null; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Web::Session::Store::LDAP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Web::Session::Generate::SHA256; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Web::Session::Serialize::JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Web::Session::_common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | use Net::LDAP::Constant | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | qw(LDAP_CONTROL_PAGED LDAP_NO_SUCH_OBJECT LDAP_ASSERTION_FAILED | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | LDAP_UNAVAILABLE_CRITICAL_EXT); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Net::LDAP::Control::Assertion; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Net::LDAP::Control::Paged; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Net::LDAP::Util qw(escape_filter_value); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = '1.0.0'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | our @ISA = qw(Apache::Session Web::Session::_common); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Page size of searches that may return many entries | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | our $PageSize = 500; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $numRe = qr/^(-?)([0-9]+)(?:\.([0-9]+))?\z/; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub populate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
populate: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $self->{object_store} = new Web::Session::Store::LDAP $self; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $self->{lock_manager} = new Apache::Session::Lock::Null $self; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $self->{generate} = \&Web::Session::Generate::SHA256::generate; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $self->{validate} = \&Web::Session::Generate::SHA256::validate; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $self->{serialize} = \&Web::Session::Serialize::JSON::serialize; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $self->{unserialize} = \&Web::Session::Serialize::JSON::unserialize; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub unserialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unserialize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $session = shift; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $tmp = { serialized => $session }; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | Web::Session::Serialize::JSON::unserialize($tmp); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return $tmp->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub searchOn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
searchOn: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ( $class, $args, $selectField, $value, @fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | my $index = | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( grep { $_ eq $selectField } @$index ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ( $selectField, $value ) = escape_filter_value( $selectField, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return $class->_query( $args, $selectField, $value, @fields ); | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return $class->SUPER::searchOn( $args, $selectField, $value, @fields ); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub searchOnExpr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
searchOnExpr: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ( $class, $args, $selectField, $value, @fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | my $index = | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( grep { $_ eq $selectField } @$index ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ( $selectField, $value ) = escape_filter_value( $selectField, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $value =~ s/\\2a/\*/gi; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $class->_query( $args, $selectField, $value, @fields ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return $class->SUPER::searchOn( $args, $selectField, $value, @fields ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub searchLt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
searchLt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return $class->_searchCmp( -1, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub searchGt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
searchGt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return $class->_searchCmp( 1, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # The index attribute has no ordering rule and a substring filter can't bound | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # the length of a number, so the index only restricts the search to sessions | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # having the field. Values are compared in Perl; sessions without the field or | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # where it isn't a number are skipped. LDAP errors return an empty result: | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # Lemonldap::NG purge doesn't catch them. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub _searchCmp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_searchCmp: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my ( $class, $sign, $args, $selectField, $value, @fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $name = 'search' . ( $sign < 0 ? 'Lt' : 'Gt' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $value =~ s/^\s+|\s+$//g if ( defined $value ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | unless ( defined $value and $value =~ $numRe ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $value and $value =~ /$numRe/
MC/DC0%0/2
defined $value and $value =~ /$numRe/
defined $value
$value =~ /$numRe/
Truth table0%0/3
A and B
A= defined $valueB= $value =~ /$numRe/
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | print STDERR "$name: value must be a number\n"; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $class->_defaults($args); | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $filter = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | $class->_fieldIsIndexed( $args, $selectField ) | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ? $class->_presenceFilter( $args, $selectField ) | ||||||||||||||||||||||||||||||||||||||||||
| 103 | : "($args->{ldapAttributeId}=*)"; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my %res = (); | |||||||||||||||||||||||||||||||||||||||||
| 105 | my $ldap = | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | eval { Web::Session::Store::LDAP->new($args)->ldap }; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | unless ($ldap) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | print STDERR "$name: unable to connect: $@\n"; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | my $msg = $class->_pagedSearch( | ||||||||||||||||||||||||||||||||||||||||||
| 112 | $ldap, | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $entry = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | my $id = $entry->get_value( $args->{ldapAttributeId} ) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $tmp = $entry->get_value( $args->{ldapAttributeContent} ); | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return unless $tmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | eval { $tmp = unserialize($tmp); }; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $cmp = $class->_cmpNum( $tmp->{$selectField}, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | return unless ( defined $cmp and $cmp == $sign ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cmp and $cmp == $sign
MC/DC0%0/2
defined $cmp and $cmp == $sign
defined $cmp
$cmp == $sign
Truth table0%0/3
A and B
A= defined $cmpB= $cmp == $sign
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if (@fields) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $res{$id}->{$_} = $tmp->{$_} foreach (@fields); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $res{$id} = $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | base => $args->{ldapConfBase}, | ||||||||||||||||||||||||||||||||||||||||||
| 131 | scope => 'one', | ||||||||||||||||||||||||||||||||||||||||||
| 132 | filter => "(&(objectClass=$args->{ldapObjectClass})$filter)", | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | attrs => [ $args->{ldapAttributeId}, $args->{ldapAttributeContent} ], | |||||||||||||||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $ldap->unbind(); | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $ldap->disconnect(); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ($msg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | print STDERR "$name: LDAP error " | |||||||||||||||||||||||||||||||||||||||||
| 139 | . $msg->code . ': ' | ||||||||||||||||||||||||||||||||||||||||||
| 140 | . $msg->error . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub _query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_query: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my ( $class, $args, $selectField, $value, @fields ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my %res = (); | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $args->{ldapObjectClass} ||= 'applicationProcess'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"ldapObjectClass"} ||= "applicationProcess"
MC/DC0%0/1
$args->{"ldapObjectClass"} ||= "applicationProcess"
$args->{"ldapObjectClass"}
Truth table0%0/2
A
A= $args->{"ldapObjectClass"}
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $args->{ldapAttributeId} ||= 'cn'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"ldapAttributeId"} ||= "cn"
MC/DC0%0/1
$args->{"ldapAttributeId"} ||= "cn"
$args->{"ldapAttributeId"}
Truth table0%0/2
A
A= $args->{"ldapAttributeId"}
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | $args->{ldapAttributeContent} ||= 'description'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"ldapAttributeContent"} ||= "description"
MC/DC0%0/1
$args->{"ldapAttributeContent"} ||= "description"
$args->{"ldapAttributeContent"}
Truth table0%0/2
A
A= $args->{"ldapAttributeContent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $args->{ldapAttributeIndex} ||= 'ou'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"ldapAttributeIndex"} ||= "ou"
MC/DC0%0/1
$args->{"ldapAttributeIndex"} ||= "ou"
$args->{"ldapAttributeIndex"}
Truth table0%0/2
A
A= $args->{"ldapAttributeIndex"}
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $obj = Web::Session::Store::LDAP->new($args); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $ldap = $obj->ldap(); | |||||||||||||||||||||||||||||||||||||||||
| 157 | my $msg = $class->_pagedSearch( | ||||||||||||||||||||||||||||||||||||||||||
| 158 | $ldap, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $entry = shift; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $id = $entry->get_value( $args->{ldapAttributeId} ) or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $tmp = $entry->get_value( $args->{ldapAttributeContent} ); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return unless $tmp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | eval { $tmp = unserialize($tmp); }; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return if ($@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if (@fields) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $res{$id}->{$_} = $tmp->{$_} foreach (@fields); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $res{$id} = $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | base => $args->{ldapConfBase}, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | scope => 'one', | ||||||||||||||||||||||||||||||||||||||||||
| 175 | filter => "(&(objectClass=" | ||||||||||||||||||||||||||||||||||||||||||
| 176 | . $args->{ldapObjectClass} . ")(" | ||||||||||||||||||||||||||||||||||||||||||
| 177 | . $args->{ldapAttributeIndex} | ||||||||||||||||||||||||||||||||||||||||||
| 178 | . "=${selectField}_$value))", | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | attrs => [ $args->{ldapAttributeContent}, $args->{ldapAttributeId} ], | |||||||||||||||||||||||||||||||||||||||||
| 180 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $ldap->unbind(); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $ldap->disconnect(); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $obj->logError($msg) if $msg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub get_key_from_all_sessions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_key_from_all_sessions: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | $args->{ldapObjectClass} ||= 'applicationProcess'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"ldapObjectClass"} ||= "applicationProcess"
MC/DC0%0/1
$args->{"ldapObjectClass"} ||= "applicationProcess"
$args->{"ldapObjectClass"}
Truth table0%0/2
A
A= $args->{"ldapObjectClass"}
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | $args->{ldapAttributeId} ||= 'cn'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"ldapAttributeId"} ||= "cn"
MC/DC0%0/1
$args->{"ldapAttributeId"} ||= "cn"
$args->{"ldapAttributeId"}
Truth table0%0/2
A
A= $args->{"ldapAttributeId"}
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | $args->{ldapAttributeContent} ||= 'description'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"ldapAttributeContent"} ||= "description"
MC/DC0%0/1
$args->{"ldapAttributeContent"} ||= "description"
$args->{"ldapAttributeContent"}
Truth table0%0/2
A
A= $args->{"ldapAttributeContent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | $args->{ldapAttributeIndex} ||= 'ou'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"ldapAttributeIndex"} ||= "ou"
MC/DC0%0/1
$args->{"ldapAttributeIndex"} ||= "ou"
$args->{"ldapAttributeIndex"}
Truth table0%0/2
A
A= $args->{"ldapAttributeIndex"}
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my %res = (); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $obj = Web::Session::Store::LDAP->new($args); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $ldap = $obj->ldap(); | |||||||||||||||||||||||||||||||||||||||||
| 200 | my $msg = $class->_pagedSearch( | ||||||||||||||||||||||||||||||||||||||||||
| 201 | $ldap, | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $entry = shift; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my $id = $entry->get_value( $args->{ldapAttributeId} ) or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $tmp = $entry->get_value( $args->{ldapAttributeContent} ); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return unless ($tmp); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | eval { $tmp = unserialize($tmp); }; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ( ref($data) eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $res{$id} = &$data( $tmp, $id ); | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | elsif ($data) { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $data = [$data] unless ( ref($data) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $res{$id}->{$_} = $tmp->{$_} foreach (@$data); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $res{$id} = $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | base => $args->{ldapConfBase}, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | scope => 'one', | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # VERY STRANGE BUG ! With this filter, description isn't base64 encoded !!! | ||||||||||||||||||||||||||||||||||||||||||
| 224 | #filter => '(objectClass=applicationProcess)', | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | # Sessions without any indexed value have no index attribute | ||||||||||||||||||||||||||||||||||||||||||
| 227 | filter => '(&(objectClass=' | ||||||||||||||||||||||||||||||||||||||||||
| 228 | . $args->{ldapObjectClass} . ')(' | ||||||||||||||||||||||||||||||||||||||||||
| 229 | . $args->{ldapAttributeId} . '=*))', | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | attrs => [ $args->{ldapAttributeId}, $args->{ldapAttributeContent} ], | |||||||||||||||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $ldap->unbind(); | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $ldap->disconnect(); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $obj->logError($msg) if $msg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return \%res; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | # Only index values are read: candidates are selected by the directory, then | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # checked in Perl. Returns false if the rule can't be evaluated this way (the | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # caller then falls back to a full scan), true on success; in list context, | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # also the number of deleted sessions: 0 when it returns false, otherwise the | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # number deleted, or already deleted if an error stops the deletions. | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 5 | ▶ | sub deleteIfLowerThan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleteIfLowerThan: called CC=15 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 5 | my ( $class, $args, $rule ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 5 | ▶ | my $filter = $class->_lowerThanFilter( $args, $rule ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | or return wantarray ? ( 0, 0 ) : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | my $ldap = | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 3 | eval { Web::Session::Store::LDAP->new($args)->ldap }; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | ▶ | unless ($ldap) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | print STDERR "deleteIfLowerThan: unable to connect: $@\n"; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | return wantarray ? ( 0, 0 ) : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | # Collect first: nothing is deleted if the search fails | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | my @found; | |||||||||||||||||||||||||||||||||||||||||
| 259 | my $msg = $class->_pagedSearch( | ||||||||||||||||||||||||||||||||||||||||||
| 260 | $ldap, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 6 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 6 | my $entry = shift; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | my @values = $entry->get_value( $args->{ldapAttributeIndex} ); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 6 | ▶ | push @found, [ $entry->dn, @values ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | if $class->_matchLowerThan( $rule, @values ); | ||||||||||||||||||||||||||||||||||||||||||
| 266 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 267 | base => $args->{ldapConfBase}, | ||||||||||||||||||||||||||||||||||||||||||
| 268 | scope => 'one', | ||||||||||||||||||||||||||||||||||||||||||
| 269 | filter => $filter, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | attrs => [ $args->{ldapAttributeIndex} ], | |||||||||||||||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | my ( $ok, $deleted ) = ( 1, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | ▶ | foreach ( $msg ? () : @found ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 5 | my ( $dn, @values ) = @$_; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 5 | my $keep; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 5 | ( $keep, $msg ) = | |||||||||||||||||||||||||||||||||||||||||
| 277 | $class->_notInContent( $ldap, $args, $rule, $dn, @values ); | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | ▶ | last if $msg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | ▶ | next if $keep; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | # Don't delete sessions updated since the search. The control is | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # critical: a server ignoring it would delete refreshed sessions | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | my $res = $ldap->delete( | |||||||||||||||||||||||||||||||||||||||||
| 284 | $dn, | ||||||||||||||||||||||||||||||||||||||||||
| 285 | control => [ | ||||||||||||||||||||||||||||||||||||||||||
| 286 | Net::LDAP::Control::Assertion->new( | ||||||||||||||||||||||||||||||||||||||||||
| 287 | critical => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | assertion => | ||||||||||||||||||||||||||||||||||||||||||
| 289 | $class->_lowerThanAssertion( $args, $rule, @values ) | ||||||||||||||||||||||||||||||||||||||||||
| 290 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 291 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 292 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 4 | ▶ | if ( !$res->code ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 2 | $deleted++; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | # Already removed (by a logout for example) or updated | ||||||||||||||||||||||||||||||||||||||||||
| 298 | ▶ | elsif ( $res->code != LDAP_NO_SUCH_OBJECT | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$res->code != 32 and $res->code != 122
MC/DC0%0/2
$res->code != 32 and $res->code != 122
$res->code != 32
$res->code != 122
Truth table33%1/3
A and B
A= $res->code != 32B= $res->code != 122
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | and $res->code != LDAP_ASSERTION_FAILED ) | ||||||||||||||||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | $msg = $res; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 3 | ▶ | if ($msg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | print STDERR 'deleteIfLowerThan: LDAP error ' | |||||||||||||||||||||||||||||||||||||||||
| 307 | . $msg->code . ': ' | ||||||||||||||||||||||||||||||||||||||||||
| 308 | . $msg->error . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 3 | ▶ | print STDERR "deleteIfLowerThan: the server doesn't support the " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | . "assertion control (RFC 4528), giving up\n" | ||||||||||||||||||||||||||||||||||||||||||
| 311 | if ( $msg->code == LDAP_UNAVAILABLE_CRITICAL_EXT ); | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 3 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 3 | $ldap->unbind(); | |||||||||||||||||||||||||||||||||||||||||
| 315 | 3 | $ldap->disconnect(); | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 3 | ▶ | return wantarray ? ( $ok, $deleted ) : $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | # A session written before a "not" field was added to Index has no index | ||||||||||||||||||||||||||||||||||||||||||
| 321 | # value for it: read its content. Returns true if the session must be kept, | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # and the failed LDAP message if any | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 5 | ▶ | sub _notInContent { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_notInContent: called CC=9 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | my ( $class, $ldap, $args, $rule, $dn, @values ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | ▶ | my $not = $rule->{not} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rule->{'not'} || {}
MC/DC100%1/1
$rule->{'not'} || {}
$rule->{'not'}
Truth table100%2/2
A
A= $rule->{'not'}
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | my @stale = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 5 | my $prefix = "${_}_"; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | !grep { index( $_, $prefix ) == 0 } @values | |||||||||||||||||||||||||||||||||||||||||
| 329 | } sort keys %$not; | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 5 | ▶ | return 0 unless @stale; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | my $msg = $ldap->search( | ||||||||||||||||||||||||||||||||||||||||||
| 333 | base => $dn, | ||||||||||||||||||||||||||||||||||||||||||
| 334 | scope => 'base', | ||||||||||||||||||||||||||||||||||||||||||
| 335 | filter => '(objectClass=*)', | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | attrs => [ $args->{ldapAttributeContent} ], | |||||||||||||||||||||||||||||||||||||||||
| 337 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | ▶ | return ( 1, $msg ) if ( $msg->code and $msg->code != LDAP_NO_SUCH_OBJECT ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$msg->code and $msg->code != 32
MC/DC0%0/2
$msg->code and $msg->code != 32
$msg->code
$msg->code != 32
Truth table33%1/3
A and B
A= $msg->codeB= $msg->code != 32
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $data = eval { | |||||||||||||||||||||||||||||||||||||||||
| 340 | unserialize( | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $msg->shift_entry->get_value( $args->{ldapAttributeContent} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 342 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | # Removed meanwhile or unreadable: keep it | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | return 1 unless ( ref $data eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | foreach (@stale) { | |||||||||||||||||||||||||||||||||||||||||
| 347 | return 1 | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( defined $data->{$_} and lc( $data->{$_} ) eq lc( $not->{$_} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $data->{$_} and lc $data->{$_} eq lc $not->{$_}
MC/DC0%0/2
defined $data->{$_} and lc $data->{$_} eq lc $not->{$_}
defined $data->{$_}
lc $data->{$_} eq lc $not->{$_}
Truth table0%0/3
A and B
A= defined $data->{$_}B= lc $data->{$_} eq lc $not->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | # Assertion checking that the index values used to select a session are | ||||||||||||||||||||||||||||||||||||||||||
| 354 | # unchanged: the observed rule values are still there, "not" values still | ||||||||||||||||||||||||||||||||||||||||||
| 355 | # missing | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 6 | ▶ | sub _lowerThanAssertion { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lowerThanAssertion: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 6 | my ( $class, $args, $rule, @values ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 6 | my $ou = $args->{ldapAttributeIndex}; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 6 | ▶ | my $lt = $rule->{ exists $rule->{or} ? 'or' : 'and' }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 6 | ▶ | my $not = $rule->{not} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rule->{'not'} || {}
MC/DC100%1/1
$rule->{'not'} || {}
$rule->{'not'}
Truth table100%2/2
A
A= $rule->{'not'}
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 6 | my $res = ''; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 6 | foreach my $f ( sort keys %$lt ) { | |||||||||||||||||||||||||||||||||||||||||
| 363 | $res .= "($ou=" . escape_filter_value($_) . ')' | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 7 | foreach ( grep { index( $_, "${f}_" ) == 0 } @values ); | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | $res .= "(!($ou=" . escape_filter_value("${_}_$not->{$_}") . '))' | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 6 | foreach ( sort keys %$not ); | |||||||||||||||||||||||||||||||||||||||||
| 368 | 6 | return "(&$res)"; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | # $rule: { or|and => { field => number, ... }, not => { field => value, ... } } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | # Returns the filter selecting candidate entries: those having the "or"/"and" | ||||||||||||||||||||||||||||||||||||||||||
| 373 | # fields and none of the "not" values. Every field must be indexed. | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 29 | ▶ | sub _lowerThanFilter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lowerThanFilter: called CC=20 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 29 | my ( $class, $args, $rule ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 29 | ▶ | return unless ( ref $rule eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 28 | my @op = grep { exists $rule->{$_} } qw(or and); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 28 | ▶ | return unless ( @op == 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 25 | my $lt = $rule->{ $op[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 25 | ▶ | my $not = $rule->{not} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rule->{'not'} || {}
MC/DC100%1/1
$rule->{'not'} || {}
$rule->{'not'}
Truth table100%2/2
A
A= $rule->{'not'}
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 25 | ▶ | return unless ( ref $lt eq 'HASH' and %$lt and ref $not eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
ref $lt eq "HASH" and %$lt and ref $not eq "HASH"
ref $lt eq "HASH" and %$lt
MC/DC100%3/3
ref $lt eq "HASH" and %$lt and ref $not eq "HASH"
ref $lt eq "HASH"
%$lt
ref $not eq "HASH"
Truth table100%4/4
A and B and C
A= ref $lt eq "HASH"B= %$ltC= ref $not eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 22 | foreach my $v ( values %$lt ) { | |||||||||||||||||||||||||||||||||||||||||
| 383 | 24 | ▶ | my $t = ( defined $v and !ref $v ) ? $v : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $v and not ref $v
MC/DC50%1/2
defined $v and not ref $v
defined $v
not ref $v
Truth table66%2/3
A and not(B)
A= defined $vB= not ref $v
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 24 | $t =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 24 | ▶ | unless ( $t =~ $numRe ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 5 | print STDERR "deleteIfLowerThan: threshold must be a number\n"; | |||||||||||||||||||||||||||||||||||||||||
| 387 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | # Empty and "0" values aren't indexed, so "not" can't exclude them | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 17 | foreach ( values %$not ) { | |||||||||||||||||||||||||||||||||||||||||
| 393 | 7 | ▶ | return unless ( defined $_ and !ref $_ and $_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $_ and not ref $_ and $_
defined $_ and not ref $_
MC/DC33%1/3
defined $_ and not ref $_ and $_
defined $_
not ref $_
$_
Truth table50%2/4
A and not(B) and C
A= defined $_B= not ref $_C= $_
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 14 | foreach ( keys %$lt, keys %$not ) { | |||||||||||||||||||||||||||||||||||||||||
| 396 | 20 | ▶ | return unless $class->_fieldIsIndexed( $args, $_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 10 | $class->_defaults($args); | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 10 | my @terms = map { $class->_presenceFilter( $args, $_ ) } sort keys %$lt; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 10 | my $filter = join '', @terms; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 10 | ▶ | $filter = ( $op[0] eq 'or' ? '(|' : '(&' ) . "$filter)" if ( @terms > 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 10 | foreach ( sort keys %$not ) { | |||||||||||||||||||||||||||||||||||||||||
| 404 | 3 | $filter .= "(!($args->{ldapAttributeIndex}=" | |||||||||||||||||||||||||||||||||||||||||
| 405 | . escape_filter_value("${_}_$not->{$_}") . '))'; | ||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 10 | return "(&(objectClass=$args->{ldapObjectClass})$filter)"; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | # Checks a rule accepted by _lowerThanFilter() against the index values of an | ||||||||||||||||||||||||||||||||||||||||||
| 411 | # entry. A field is lower only if it has numeric values, all lower. | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 26 | ▶ | sub _matchLowerThan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_matchLowerThan: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 26 | my ( $class, $rule, @values ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 26 | ▶ | my $not = $rule->{not} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rule->{'not'} || {}
MC/DC100%1/1
$rule->{'not'} || {}
$rule->{'not'}
Truth table100%2/2
A
A= $rule->{'not'}
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 26 | foreach my $f ( keys %$not ) { | |||||||||||||||||||||||||||||||||||||||||
| 416 | 19 | ▶ | return 0 if grep { $_ eq "${f}_$not->{$f}" } @values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 25 | my $or = exists $rule->{or}; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 25 | ▶ | my $lt = $rule->{ $or ? 'or' : 'and' }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 25 | foreach my $f ( keys %$lt ) { | |||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | # Same parsing as searchLt(): surrounding spaces are ignored | ||||||||||||||||||||||||||||||||||||||||||
| 423 | my @nums = | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 24 | grep { defined $class->_cmpNum( $_, $lt->{$f} ) } | |||||||||||||||||||||||||||||||||||||||||
| 425 | 41 | ▶ | map { /^\Q$f\E_(.*)\z/s ? $1 : () } @values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 41 | ▶ | my $low = @nums ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 41 | foreach (@nums) { | |||||||||||||||||||||||||||||||||||||||||
| 428 | 21 | ▶ | $low = 0 unless ( $class->_cmpNum( $_, $lt->{$f} ) < 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 41 | ▶ | return 1 if ( $low and $or ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$low and $or
MC/DC100%2/2
$low and $or
$low
$or
Truth table100%3/3
A and B
A= $lowB= $or
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 27 | ▶ | return 0 if ( !$low and !$or ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$low or $or
MC/DC100%2/2
$low or $or
$low
$or
Truth table100%3/3
A or B
A= $lowB= $or
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 9 | ▶ | return $or ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 10 | ▶ | sub _defaults { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_defaults: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 10 | my ( $class, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 10 | ▶ | $args->{ldapObjectClass} ||= 'applicationProcess'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"ldapObjectClass"} ||= "applicationProcess"
MC/DC100%1/1
$args->{"ldapObjectClass"} ||= "applicationProcess"
$args->{"ldapObjectClass"}
Truth table100%2/2
A
A= $args->{"ldapObjectClass"}
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 10 | ▶ | $args->{ldapAttributeId} ||= 'cn'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"ldapAttributeId"} ||= "cn"
MC/DC0%0/1
$args->{"ldapAttributeId"} ||= "cn"
$args->{"ldapAttributeId"}
Truth table50%1/2
A
A= $args->{"ldapAttributeId"}
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 10 | ▶ | $args->{ldapAttributeContent} ||= 'description'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"ldapAttributeContent"} ||= "description"
MC/DC0%0/1
$args->{"ldapAttributeContent"} ||= "description"
$args->{"ldapAttributeContent"}
Truth table50%1/2
A
A= $args->{"ldapAttributeContent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 10 | ▶ | $args->{ldapAttributeIndex} ||= 'ou'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"ldapAttributeIndex"} ||= "ou"
MC/DC100%1/1
$args->{"ldapAttributeIndex"} ||= "ou"
$args->{"ldapAttributeIndex"}
Truth table100%2/2
A
A= $args->{"ldapAttributeIndex"}
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | # Matches entries having an index value for $field. It may also match other | ||||||||||||||||||||||||||||||||||||||||||
| 445 | # fields whose name starts with "${field}_": callers check values in Perl | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 14 | ▶ | sub _presenceFilter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_presenceFilter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 14 | my ( $class, $args, $field ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 448 | return | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 14 | "($args->{ldapAttributeIndex}=" . escape_filter_value("${field}_") . '*)'; | |||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | # Calls $cb on each entry, page by page to avoid server size limits. Returns | ||||||||||||||||||||||||||||||||||||||||||
| 453 | # the failed LDAP message, or nothing on success | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 7 | ▶ | sub _pagedSearch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pagedSearch: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 7 | my ( $class, $ldap, $cb, %search ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 7 | my $page = Net::LDAP::Control::Paged->new( size => $PageSize ); | |||||||||||||||||||||||||||||||||||||||||
| 457 | 7 | my $cookie; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 7 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 459 | 10 | my $msg = $ldap->search( %search, control => [$page] ); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 10 | ▶ | return $msg if $msg->code; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 10 | $cb->($_) foreach ( $msg->entries ); | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 10 | my ($resp) = $msg->control(LDAP_CONTROL_PAGED); | |||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | # Servers without paged results support return everything at once, but | ||||||||||||||||||||||||||||||||||||||||||
| 466 | # a full page may hide a truncated result | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 10 | ▶ | unless ($resp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 5 | ▶ | print STDERR | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cookie or $msg->count >= $Web::Session::LDAP::PageSize
MC/DC50%1/2
defined $cookie or $msg->count >= $Web::Session::LDAP::PageSize
defined $cookie
$msg->count >= $Web::Session::LDAP::PageSize
Truth table66%2/3
A or B
A= defined $cookieB= $msg->count >= $Web::Session::LDAP::PageSize
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | "paged search: no paged results control in the response, " | ||||||||||||||||||||||||||||||||||||||||||
| 470 | . "results may be truncated\n" | ||||||||||||||||||||||||||||||||||||||||||
| 471 | if ( defined $cookie or $msg->count >= $PageSize ); | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 5 | ▶ | return unless ( $resp->cookie ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | # A server or proxy returning a constant cookie would loop forever | ||||||||||||||||||||||||||||||||||||||||||
| 477 | 4 | ▶ | if ( defined $cookie and $resp->cookie eq $cookie ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $cookie and $resp->cookie eq $cookie
MC/DC100%2/2
defined $cookie and $resp->cookie eq $cookie
defined $cookie
$resp->cookie eq $cookie
Truth table100%3/3
A and B
A= defined $cookieB= $resp->cookie eq $cookie
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | 1 | print STDERR "paged search: cookie didn't change, stopping\n"; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 3 | $page->cookie( $cookie = $resp->cookie ); | |||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | # Exact comparison of two decimal numbers given as strings (no float | ||||||||||||||||||||||||||||||||||||||||||
| 486 | # rounding), surrounding spaces ignored: returns -1, 0 or 1, undef if one of | ||||||||||||||||||||||||||||||||||||||||||
| 487 | # them isn't a number | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 70 | ▶ | sub _cmpNum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmpNum: called CC=12 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 70 | my ( $class, @v ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 70 | foreach (@v) { | |||||||||||||||||||||||||||||||||||||||||
| 491 | 126 | ▶ | return undef unless ( defined $_ and !ref $_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_ and not ref $_
MC/DC100%2/2
defined $_ and not ref $_
defined $_
not ref $_
Truth table100%3/3
A and not(B)
A= defined $_B= not ref $_
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 124 | s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 124 | ▶ | return undef unless ( $_ =~ $numRe ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 112 | ▶ | my ( $sign, $int, $frac ) = ( $1 ? -1 : 1, $2, defined $3 ? $3 : '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 112 | $int =~ s/^0+//; | |||||||||||||||||||||||||||||||||||||||||
| 496 | 112 | $frac =~ s/0+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 112 | ▶ | $sign = 1 unless ( length $int or length $frac ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $int or length $frac
MC/DC100%2/2
length $int or length $frac
length $int
length $frac
Truth table100%3/3
A or B
A= length $intB= length $frac
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 112 | $_ = [ $sign, $int, $frac ]; | |||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 56 | my ( $x, $y ) = @v; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 56 | ▶ | return $x->[0] <=> $y->[0] if ( $x->[0] != $y->[0] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 55 | ▶ | my $cmp = | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
length $x->[1] <=> length $y->[1] || $x->[1] cmp $y->[1] || $x->[2] cmp $y->[2]
length $x->[1] <=> length $y->[1] or $x->[1] cmp $y->[1]
MC/DC100%3/3
length $x->[1] <=> length $y->[1] || $x->[1] cmp $y->[1] || $x->[2] cmp $y->[2]
length $x->[1] <=> length $y->[1]
$x->[1] cmp $y->[1]
$x->[2] cmp $y->[2]
Truth table100%4/4
A or B || C
A= length $x->[1] <=> length $y->[1]B= $x->[1] cmp $y->[1]C= $x->[2] cmp $y->[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | length( $x->[1] ) <=> length( $y->[1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 504 | || $x->[1] cmp $y->[1] | ||||||||||||||||||||||||||||||||||||||||||
| 505 | || $x->[2] cmp $y->[2]; | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 55 | return $x->[0] * $cmp; | |||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | Web::Session::LDAP - An implementation of Apache::Session::LDAP | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | use Web::Session::LDAP; | ||||||||||||||||||||||||||||||||||||||||||
| 520 | tie %hash, 'Web::Session::LDAP', $id, { | ||||||||||||||||||||||||||||||||||||||||||
| 521 | ldapServer => 'ldap://localhost:389', | ||||||||||||||||||||||||||||||||||||||||||
| 522 | ldapConfBase => 'dmdName=applications,dc=example,dc=com', | ||||||||||||||||||||||||||||||||||||||||||
| 523 | ldapBindDN => 'cn=admin,dc=example,dc=com', | ||||||||||||||||||||||||||||||||||||||||||
| 524 | ldapBindPassword => 'pass', | ||||||||||||||||||||||||||||||||||||||||||
| 525 | Index => 'uid ipAddr', | ||||||||||||||||||||||||||||||||||||||||||
| 526 | ldapObjectClass => 'applicationProcess', | ||||||||||||||||||||||||||||||||||||||||||
| 527 | ldapAttributeId => 'cn', | ||||||||||||||||||||||||||||||||||||||||||
| 528 | ldapAttributeContent => 'description', | ||||||||||||||||||||||||||||||||||||||||||
| 529 | ldapAttributeIndex => 'ou', | ||||||||||||||||||||||||||||||||||||||||||
| 530 | ldapVerify => 'require', | ||||||||||||||||||||||||||||||||||||||||||
| 531 | ldapCAFile => '/etc/ssl/certs/ca-certificates.crt', | ||||||||||||||||||||||||||||||||||||||||||
| 532 | ldapTimeout => 10, | ||||||||||||||||||||||||||||||||||||||||||
| 533 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | This module is an implementation of Apache::Session. It uses an LDAP directory | ||||||||||||||||||||||||||||||||||||||||||
| 538 | to store datas. | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | See L<Web::Session::Store::LDAP> for the available options. | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | Each session is an entry named C<ldapAttributeId=id,ldapConfBase> (default | ||||||||||||||||||||||||||||||||||||||||||
| 543 | objectClass C<applicationProcess>, available in the core schema). The session | ||||||||||||||||||||||||||||||||||||||||||
| 544 | is serialized in JSON into C<ldapAttributeContent>, and each field listed in | ||||||||||||||||||||||||||||||||||||||||||
| 545 | C<Index> and set in the session is stored as a C<field_value> value of | ||||||||||||||||||||||||||||||||||||||||||
| 546 | C<ldapAttributeIndex>. Fields whose value is empty or C<0> are not indexed. | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | The directory should index C<ldapAttributeIndex> for equality and substring | ||||||||||||||||||||||||||||||||||||||||||
| 549 | searches (OpenLDAP: C<index ou eq,sub>). | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | =head2 searchLt() and searchGt() | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | # Refresh tokens not updated since 1 hour | ||||||||||||||||||||||||||||||||||||||||||
| 554 | my $hash = Web::Session::LDAP->searchLt( $args, | ||||||||||||||||||||||||||||||||||||||||||
| 555 | '_oidcRtUpdate', time - 3600 ); | ||||||||||||||||||||||||||||||||||||||||||
| 556 | my $hash = Web::Session::LDAP->searchGt( $args, | ||||||||||||||||||||||||||||||||||||||||||
| 557 | '_utime', time - 3600, 'uid', 'ipAddr' ); | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | Return sessions whose field is strictly lower (or greater) than the given | ||||||||||||||||||||||||||||||||||||||||||
| 560 | number, like searchOn(). Sessions without the field, or where it isn't a | ||||||||||||||||||||||||||||||||||||||||||
| 561 | number, are skipped. The value must be a decimal number | ||||||||||||||||||||||||||||||||||||||||||
| 562 | (C</^-?[0-9]+(?:\.[0-9]+)?$/>), otherwise an empty result is returned with a | ||||||||||||||||||||||||||||||||||||||||||
| 563 | warning. LDAP errors also return an empty result with a warning. | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | The index attribute has no ordering matching rule, and substring filters | ||||||||||||||||||||||||||||||||||||||||||
| 566 | can't bound the length of a number, so the directory can't select the lower | ||||||||||||||||||||||||||||||||||||||||||
| 567 | values. When the field is indexed, only sessions having it are read; otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 568 | all sessions are read. Numbers are then compared in Perl. Lemonldap::NG purge | ||||||||||||||||||||||||||||||||||||||||||
| 569 | calls searchLt() on C<_oidcRtUpdate> when a refresh token activity timeout is | ||||||||||||||||||||||||||||||||||||||||||
| 570 | set: add it to C<Index>. | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | When the field is indexed, sessions are found through their index values: | ||||||||||||||||||||||||||||||||||||||||||
| 573 | sessions whose value is C<0> or empty, or written before the field was added | ||||||||||||||||||||||||||||||||||||||||||
| 574 | to C<Index>, are missed until they are rewritten. | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | Differences with the SQL backends (searchLt(), searchGt() and | ||||||||||||||||||||||||||||||||||||||||||
| 577 | deleteIfLowerThan()): | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | =item * Values which aren't numbers are ignored here, whereas SQL backends | ||||||||||||||||||||||||||||||||||||||||||
| 582 | compare them as C<0> or by their numeric prefix (C<12abc> is C<12>). | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | =item * Fields whose value is C<0> or empty are not indexed, so they are | ||||||||||||||||||||||||||||||||||||||||||
| 585 | missed when the field is indexed, whereas SQL backends find them. | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | =head2 deleteIfLowerThan() | ||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | my ( $ok, $count ) = Web::Session::LDAP->deleteIfLowerThan( | ||||||||||||||||||||||||||||||||||||||||||
| 592 | $args, | ||||||||||||||||||||||||||||||||||||||||||
| 593 | { | ||||||||||||||||||||||||||||||||||||||||||
| 594 | not => { _session_kind => 'Persistent' }, | ||||||||||||||||||||||||||||||||||||||||||
| 595 | or => { _utime => time - 7200, _lastSeen => time - 3600 }, | ||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | Deletes sessions where one (C<or>) or all (C<and>) of the given fields are | ||||||||||||||||||||||||||||||||||||||||||
| 600 | strictly lower than their threshold, and where each C<not> field is missing | ||||||||||||||||||||||||||||||||||||||||||
| 601 | or has another value. Exactly one of C<or> and C<and> must be given, and | ||||||||||||||||||||||||||||||||||||||||||
| 602 | thresholds must be decimal numbers (surrounding spaces are ignored). A missing | ||||||||||||||||||||||||||||||||||||||||||
| 603 | field, or one which isn't a number, is never lower. | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | Only the index is used: every field of the rule must be listed in C<Index>. | ||||||||||||||||||||||||||||||||||||||||||
| 606 | For Lemonldap::NG sessions purge, index C<_session_kind> and C<_utime>, plus | ||||||||||||||||||||||||||||||||||||||||||
| 607 | C<_lastSeen> when "timeoutActivity" is set and C<_oidcRtUpdate> for | ||||||||||||||||||||||||||||||||||||||||||
| 608 | searchLt() (see above), for example: | ||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | Index => '_whatToTrace _session_kind _utime _lastSeen _oidcRtUpdate ipAddr' | ||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||
| 612 | The directory selects the sessions having the C<or>/C<and> fields and none of | ||||||||||||||||||||||||||||||||||||||||||
| 613 | the C<not> values, for example: | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | (&(objectClass=applicationProcess)(|(ou=_lastSeen_*)(ou=_utime_*)) | ||||||||||||||||||||||||||||||||||||||||||
| 616 | (!(ou=_session_kind_Persistent))) | ||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | Only their DN and index values are read; numbers are compared in Perl, then | ||||||||||||||||||||||||||||||||||||||||||
| 619 | the matching entries are deleted. As with searchLt(), no filter can select | ||||||||||||||||||||||||||||||||||||||||||
| 620 | lower numbers: C<ou> has no ordering rule, and a substring filter can't tell | ||||||||||||||||||||||||||||||||||||||||||
| 621 | C<99> from C<9900000000>. So the index values of all the candidate sessions | ||||||||||||||||||||||||||||||||||||||||||
| 622 | are read, but much less data than the full scan used otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | The serialized session is only read when a matching session has no index | ||||||||||||||||||||||||||||||||||||||||||
| 625 | value for a C<not> field (written before this field was added to C<Index>): | ||||||||||||||||||||||||||||||||||||||||||
| 626 | it is kept if its content has the C<not> value. | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | Each deletion carries an assertion control (RFC 4528) checking that the index | ||||||||||||||||||||||||||||||||||||||||||
| 629 | values seen by the search haven't changed: a session updated in the meantime | ||||||||||||||||||||||||||||||||||||||||||
| 630 | is not deleted. The control is critical: if the server (or a proxy) doesn't | ||||||||||||||||||||||||||||||||||||||||||
| 631 | support it, the deletion fails with LDAP error 12, and deleteIfLowerThan() | ||||||||||||||||||||||||||||||||||||||||||
| 632 | stops and returns false (see below) so that no refreshed session is deleted. | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | Limits: | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||
| 638 | =item * The rule fields are read from the index: after adding a field to | ||||||||||||||||||||||||||||||||||||||||||
| 639 | C<Index>, sessions written before are ignored until they are rewritten. | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | =item * C<not> values are compared with the equality rule of the index | ||||||||||||||||||||||||||||||||||||||||||
| 642 | attribute: case-insensitive for C<ou>, so C<persistent> is also kept. | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | =item * Fields whose value is empty or C<0> aren't indexed: they are | ||||||||||||||||||||||||||||||||||||||||||
| 645 | considered missing, and a C<not> value empty or C<0> is refused. | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | Returns false, deleting nothing (0 in list context), if the rule can't be | ||||||||||||||||||||||||||||||||||||||||||
| 650 | handled this way (non indexed field, invalid threshold...) or if the | ||||||||||||||||||||||||||||||||||||||||||
| 651 | connection or the search fails: Lemonldap::NG then falls back to reading all | ||||||||||||||||||||||||||||||||||||||||||
| 652 | sessions. Otherwise returns true and, in list context, the number of deleted | ||||||||||||||||||||||||||||||||||||||||||
| 653 | sessions (sessions removed or updated meanwhile aren't counted). If a deletion | ||||||||||||||||||||||||||||||||||||||||||
| 654 | fails, stops and returns false, and in list context the number of sessions | ||||||||||||||||||||||||||||||||||||||||||
| 655 | already deleted. | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | =head2 Size limits | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | Searches returning many sessions (get_key_from_all_sessions(), searchOn(), | ||||||||||||||||||||||||||||||||||||||||||
| 660 | searchOnExpr(), searchLt(), searchGt(), deleteIfLowerThan()) use the paged | ||||||||||||||||||||||||||||||||||||||||||
| 661 | results control. With OpenLDAP, if the bind DN isn't the rootdn, allow it to | ||||||||||||||||||||||||||||||||||||||||||
| 662 | read all sessions, for example with | ||||||||||||||||||||||||||||||||||||||||||
| 663 | C<limits dn.exact="E<lt>bind DNE<gt>" size=unlimited> (this covers paged and | ||||||||||||||||||||||||||||||||||||||||||
| 664 | unpaged searches). | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | =item 2009-2026 by Xavier Guimard | ||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | =item 2013-2025 by Clément Oudot | ||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||
| 676 | =item 2019-2025 by Maxime Besson | ||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | =item 2013-2025 by Worteks | ||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | =item 2023-2026 by Linagora | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 685 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||||||||||||||||||||||||||||||||||||||||||
| 686 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | L<Apache::Session> | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | =cut | ||||||||||||||||||||||||||||||||||||||||||