Lemonldap/NG/Handler/Main/Reload.pm

filter: Statementstmt 77.8% 257 / 330 Branchbran 61.9% 78 / 126 Conditioncond 56.5% 43 / 76 MC/DCmcdc 34.0% 15 / 44 Subroutinesub 81.5% 31 / 38 Podpod 0.0% 0 / 19 totaltotal 66.9% 424 / 633 CC 109 SCAR 29.9
CC
109
Cov
71%
postUrlInit
45.5
checkConf
40.1
sessionStorageInit
35.1
CRAP 19.8
« Lemonldap/NG/Handler/Main/Jail.pm ↑ Summary Lemonldap/NG/Handler/ApacheMP2.pm »
1 package Lemonldap::NG::Handler::Main::Reload;
2  
3 29 our $VERSION = '2.23.0';
4  
5 package Lemonldap::NG::Handler::Main;
6  
7 55 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use Digest::SHA qw(sha256_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 29 ▶use Lemonldap::NG::Common::Conf::Constants; #inherits
Subroutine BEGIN: called CC=1 SCAR=0.0
10 29 ▶use Lemonldap::NG::Common::Crypto;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 29 ▶use Lemonldap::NG::Common::Safelib; #link protected safe Safe object
Subroutine BEGIN: called CC=1 SCAR=0.0
12 29 ▶use Lemonldap::NG::Handler::Main::Jail;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 29 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 29 ▶use constant UNPROTECT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 29 ▶use constant SKIP => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 29 ▶use constant MAYSKIP => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 29 our @_onReload;
20  
21 1 ▶sub onReload {
Subroutine onReload: called CC=3 SCAR=13.0
Pod undocumented
22 1 my ( $class, $obj, $sub ) = @_;
23 1 ▶ unless ( ref($obj) and $sub ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $obj and $sub) 0 1 1
Condition33%1/3
ref $obj and $sub
!ll&&!rl&&r
001
MC/DC0%0/2
ref $obj and $sub
ref $obj $sub
Truth table33%1/3
A and B
A= ref $objB= $sub
ABresult
0X0
100
111
24 0 $class->logger->error(
25 'onReload called with invalid arguments, skipping');
26 0 return;
27 }
28 1 my $entry = [ $obj, $sub ];
29 1 weaken( $entry->[0] );
30 1 push @_onReload, $entry;
31 }
32  
33 # CONFIGURATION UPDATE
34  
35 ## @rmethod protected int checkConf(boolean force)
36 # Check if configuration is up to date, and reload it if needed.
37 # If the optional boolean $force is set to true,
38 # * cached configuration is ignored
39 # * and checkConf returns false if it fails to load remote config
40 # @param $force boolean
41 # @return true if config is up to date or if reload config succeeded
42 64 ▶sub checkConf {
Subroutine checkConf: called CC=24 SCAR=36.9
Pod undocumented
43 64 my ( $class, $force ) = @_;
44 64 $class->logger->debug("Check configuration for $class");
45 64 my $prm = { local => !$force, localPrm => $class->localConfig };
46 64 my $cfgNum = $class->confAcc->lastCfg();
47 64 ▶ $prm->{local} = 0 if $class->cfgNum and $cfgNum != $class->cfgNum;
Branch: 1 branch
BranchTrueFalseTotal
if $class->cfgNum and $cfgNum != $class->cfgNum 4 60 64
Condition100%3/3
$class->cfgNum and $cfgNum != $class->cfgNum
!ll&&!rl&&r
28324
MC/DC100%2/2
$class->cfgNum and $cfgNum != $class->cfgNum
$class->cfgNum $cfgNum != $class->cfgNum
Truth table100%3/3
A and B
A= $class->cfgNumB= $cfgNum != $class->cfgNum
ABresult
0X0
100
111
48 64 my $conf = $class->confAcc->getConf($prm);
49 64 chomp $Lemonldap::NG::Common::Conf::msg;
50  
51 64 ▶ unless ( ref($conf) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $conf) 5 59 64
52 5 $class->logger->error(
53 "$class: Unable to load configuration: $Lemonldap::NG::Common::Conf::msg"
54 );
55 5 ▶ return $force ? 0 : $class->cfgNum ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$force ? : 3 2 5
$class->cfgNum ? : 0 2 2
56 }
57  
58 59 ▶ if ($Lemonldap::NG::Common::Conf::msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lemonldap::NG::Common::Conf::msg) 59 0 59
59 59 ▶ if ( $Lemonldap::NG::Common::Conf::msg =~ /Error:/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Lemonldap::NG::Common::Conf::msg =~ /Error:/) { } 1 58 59
elsif ($Lemonldap::NG::Common::Conf::msg =~ /Warn:/) { } 0 58 58
60 1 $class->logger->error($Lemonldap::NG::Common::Conf::msg);
61 }
62 elsif ( $Lemonldap::NG::Common::Conf::msg =~ /Warn:/ ) {
63 0 $class->logger->warn($Lemonldap::NG::Common::Conf::msg);
64 }
65 else {
66 58 $class->logger->debug($Lemonldap::NG::Common::Conf::msg);
67 }
68 }
69 59 $Lemonldap::NG::Common::Conf::msg = '';
70  
71 59 ▶ if ( $force
Branch: 1 branch
BranchTrueFalseTotal
if ($force or not $class->cfgNum or not $class->cfgDate or $class->cfgNum != $conf->{"cfgNum"} or $class->cfgDate != $conf->{"cfgDate"}) 49 10 59
Condition75%9/12
$force or not $class->cfgNum or not $class->cfgDate or $class->cfgNum != $conf->{"cfgNum"} or $class->cfgDate != $conf->{"cfgDate"}
l!l&&r!l&&!r
49010
$force or not $class->cfgNum or not $class->cfgDate or $class->cfgNum != $conf->{"cfgNum"}
l!l&&r!l&&!r
45410
$force or not $class->cfgNum or not $class->cfgDate
l!l&&r!l&&!r
45014
$force or not $class->cfgNum
l!l&&r!l&&!r
45014
MC/DC40%2/5
$force or not $class->cfgNum or not $class->cfgDate or $class->cfgNum != $conf->{"cfgNum"} or $class->cfgDate != $conf->{"cfgDate"}
$force not $class->cfgNum not $class->cfgDate $class->cfgNum != $conf->{"cfgNum"} $class->cfgDate != $conf->{"cfgDate"}
Truth table50%3/6
A or not(B) or not(C) or D or E
A= $forceB= not $class->cfgNumC= not $class->cfgDateD= $class->cfgNum != $conf->{"cfgNum"}E= $class->cfgDate != $conf->{"cfgDate"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
72 or !$class->cfgNum
73 or !$class->cfgDate
74 or $class->cfgNum != $conf->{cfgNum}
75 or $class->cfgDate != $conf->{cfgDate} )
76 {
77 49 $class->logger->debug(
78 "Get configuration $conf->{cfgNum} aged $conf->{cfgDate}");
79 49 ▶ unless ( $class->cfgNum( $conf->{cfgNum} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->cfgNum($conf->{"cfgNum"}) and $class->cfgDate($conf->{"cfgDate"})) 0 49 49
Condition33%1/3
$class->cfgNum($conf->{"cfgNum"}) and $class->cfgDate($conf->{"cfgDate"})
!ll&&!rl&&r
0049
MC/DC0%0/2
$class->cfgNum($conf->{"cfgNum"}) and $class->cfgDate($conf->{"cfgDate"})
$class->cfgNum($conf->{"cfgNum"}) $class->cfgDate($conf->{"cfgDate"})
Truth table33%1/3
A and B
A= $class->cfgNum($conf->{"cfgNum"})B= $class->cfgDate($conf->{"cfgDate"})
ABresult
0X0
100
111
80 && $class->cfgDate( $conf->{cfgDate} ) )
81 {
82 0 $class->logger->error('No configuration available');
83 0 return 0;
84 }
85 49 $class->configReload($conf);
86 49 foreach (@_onReload) {
87 1 ▶ unless ( ref($_) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "ARRAY") 0 1 1
88 0 ▶ $class->logger->error(
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
89 "Corrupted entry in _onReload: expected ARRAY ref, got "
90 . ( defined $_ ? "'$_'" : 'undef' ) );
91 0 next;
92 }
93 1 my ( $obj, $sub ) = @$_;
94 1 ▶ if ($obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) 1 0 1
95 1 $class->logger->debug(
96 'Launching ' . ref($obj) . "->$sub(conf)" );
97 1 ▶ unless ( $obj->$sub($conf) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->$sub($conf)) 0 1 1
98 0 $class->logger->error( "Underlying object can't load conf ("
99 . ref($obj)
100 . "->$sub)" );
101 0 ▶ if ( $obj->can('error') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->can("error")) 0 0 0
102 0 $Lemonldap::NG::Common::Conf::msg = $obj->error;
103 }
104 0 return 0;
105 }
106 }
107 }
108 }
109 59 ▶ $class->checkTime( $conf->{checkTime} ) if $conf->{checkTime};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"checkTime"} 59 0 59
110 59 ▶ $class->checkMsg( $conf->{checkMsg} ) if $conf->{checkMsg};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"checkMsg"} 59 0 59
111 59 $class->lastCheck( time() );
112 59 $class->logger->debug("$class: configuration is up to date");
113 59 return 1;
114 }
115  
116 # RELOAD SYSTEM
117  
118 ## @rmethod int reload
119 # Launch checkConf() with $local=0, so remote configuration is tested.
120 # Then build a simple HTTP response that just returns "200 OK" or
121 # "500 Server Error".
122 # @return Apache constant ($class->OK or $class->SERVER_ERROR)
123 1 ▶sub reload {
Subroutine reload: called CC=2 SCAR=7.1
Pod undocumented
124 1 my $class = shift;
125 1 $class->logger->notice("Request for configuration reload");
126 1 ▶ return $class->checkConf(1) ? $class->DONE : $class->SERVER_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
$class->checkConf(1) ? : 1 0 1
127 }
128  
129 29 *refresh = *reload;
130  
131 # INTERNAL METHODS
132  
133 ## @imethod void configReload(hashRef conf, hashRef tsv)
134 # Given a Lemonldap::NG configuration $conf, computes values used to
135 # handle requests and store them in a thread shared object called $tsv
136 #
137 # methods called by configReload, and thread shared values computed, are:
138 # - jailInit():
139 # - jail
140 # - defaultValuesInit():
141 # (scalars for global options)
142 # - cookieExpiration # warning: absent from default Conf
143 # - cookieName
144 # - securedCookie,
145 # - httpOnly
146 # - whatToTrace
147 # - customFunctions
148 # - timeoutActivity
149 # - timeoutActivityInterval
150 # - useRedirectOnError
151 # - useRedirectOnForbidden
152 # - useRedirectAjaxOnUnauthorized
153 # - useSafeJail
154 # (objects)
155 # - cipher # Lemonldap::NG::Common::Crypto object
156 # (hashrefs for vhost options)
157 # - https
158 # - port
159 # - maintenance
160 # - portalInit():
161 # - portal (functions that returns portal URL)
162 # - locationRulesInit():
163 # - locationCount
164 # - defaultCondition
165 # - defaultProtection
166 # - locationCondition
167 # - locationProtection
168 # - locationRegexp
169 # - locationConditionText
170 # - sessionStorageInit():
171 # - sessionStorageModule
172 # - sessionStorageOptions
173 # - sessionCacheModule
174 # - sessionCacheOptions
175 # - headersInit():
176 # - headerList
177 # - forgeHeaders
178 # - postUrlInit():
179 # - inputPostData
180 # - outputPostData
181 # - aliasInit():
182 # - vhostAlias
183 # - oauth2Init():
184 # - oauth2Options
185 # - msgBrokerInit():
186 # - msgBrokerWriter
187 # - msgBrokerReader
188 #
189 # The *Init() methods can be run in any order,
190 # but jailInit must be run first because $tsv->{jail}
191 # is used by locationRulesInit, headersInit and postUrlInit.
192  
193 # @param $conf reference to the configuration hash
194 # @param $tsv reference to the thread-shared parameters conf
195 53 ▶sub configReload {
Subroutine configReload: called CC=2 SCAR=6.9
Pod undocumented
196 53 my ( $class, $conf ) = @_;
197 53 $class->logger->info(
198 "Loading configuration $conf->{cfgNum} for process $$");
199  
200 53 foreach my $sub (
201 qw( defaultValuesInit jailInit portalInit locationRulesInit
202 sessionStorageInit headersInit postUrlInit aliasInit
203 oauth2Init msgBrokerInit )
204 )
205 {
206 530 $class->logger->debug("Process $$ calls $sub");
207 530 $class->$sub($conf);
208 }
209 53 return 1;
210 }
211  
212 ## @imethod protected void jailInit(hashRef args)
213 # Set default values for non-customized variables
214 # @param $args reference to the configuration hash
215 54 ▶sub jailInit {
Subroutine jailInit: called CC=1 SCAR=0.0
Pod undocumented
216 54 my ( $class, $conf ) = @_;
217  
218 $class->tsv->{jail} = Lemonldap::NG::Handler::Main::Jail->new( {
219 useSafeJail => $conf->{useSafeJail},
220 customFunctions => $conf->{customFunctions},
221 multiValuesSeparator => $conf->{multiValuesSeparator},
222 }
223 54 );
224 $class->tsv->{jail}
225 54 ->build_jail( $class, $conf->{require}, $conf->{requireDontDie} );
226 }
227  
228 ## @imethod protected void defaultValuesInit(hashRef args)
229 # Set default values for non-customized variables
230 # @param $args reference to the configuration hash
231 54 ▶sub defaultValuesInit {
Subroutine defaultValuesInit: called CC=11 SCAR=24.0
Pod undocumented
232 54 my ( $class, $conf ) = @_;
233  
234 $class->tsv->{$_} = $conf->{$_}
235 54 foreach ( qw(
236 cookieExpiration cookieName customFunctions
237 securedCookie timeout timeoutActivity
238 timeoutActivityInterval useRedirectOnError useRedirectOnForbidden
239 useSafeJail httpOnly whatToTrace handlerInternalCache
240 handlerServiceTokenTTL customToTrace lwpOpts lwpSslOpts
241 authChoiceAuthBasic authChoiceParam upgradeSession
242 hashedSessionStore eventQueueName eventStatus
243 statusQueueName useRedirectAjaxOnUnauthorized
244 )
245 );
246  
247 54 $class->tsv->{cipher} = Lemonldap::NG::Common::Crypto->new( $conf->{key} );
248 54 $class->tsv->{keyH} = sha256_hex( $conf->{key} );
249  
250 54 foreach my $opt (qw(https port maintenance)) {
251  
252 # Record default value in key '_'
253 162 $class->tsv->{$opt} = { _ => $conf->{$opt} };
254  
255 # Override with vhost options
256 162 ▶ if ( $conf->{vhostOptions} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"vhostOptions"}) 153 9 162
257 153 my $name = 'vhost' . ucfirst($opt);
258 153 foreach my $vhost ( sort keys %{ $conf->{vhostOptions} } ) {
259 276 ▶ $conf->{vhostOptions}->{$vhost} ||= {};
Condition50%1/2
$conf->{"vhostOptions"}{$vhost} ||= {}
l!l
2760
MC/DC0%0/1
$conf->{"vhostOptions"}{$vhost} ||= {}
$conf->{"vhostOptions"}{$vhost}
Truth table50%1/2
A
A= $conf->{"vhostOptions"}{$vhost}
Aresult
11
00
260 276 my $val = $conf->{vhostOptions}->{$vhost}->{$name};
261  
262 # Keep global value if $val is negative
263 276 ▶ if ( defined $val and $val >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val >= 0) 85 191 276
Condition66%2/3
defined $val and $val >= 0
!ll&&!rl&&r
191085
MC/DC50%1/2
defined $val and $val >= 0
defined $val $val >= 0
Truth table66%2/3
A and B
A= defined $valB= $val >= 0
ABresult
0X0
100
111
264 85 $class->logger->debug(
265 "Options $opt for vhost $vhost: $val");
266 85 $class->tsv->{$opt}->{$vhost} = $val;
267 }
268 }
269 }
270 }
271 54 ▶ if ( $conf->{vhostOptions} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"vhostOptions"}) 51 3 54
272 51 foreach my $vhost ( sort keys %{ $conf->{vhostOptions} } ) {
273 $class->tsv->{type}->{$vhost} =
274 92 $conf->{vhostOptions}->{$vhost}->{vhostType};
275 $class->tsv->{authnLevel}->{$vhost} =
276 $conf->{vhostOptions}->{$vhost}->{vhostAuthnLevel}
277 92 ▶ || $conf->{defaultAuthnLevel};
Condition100%3/3
$conf->{'vhostOptions'}{$vhost}{'vhostAuthnLevel'} || $conf->{'defaultAuthnLevel'}
l!l&&r!l&&!r
33257
MC/DC100%2/2
$conf->{'vhostOptions'}{$vhost}{'vhostAuthnLevel'} || $conf->{'defaultAuthnLevel'}
$conf->{'vhostOptions'}{$vhost}{'vhostAuthnLevel'} $conf->{'defaultAuthnLevel'}
Truth table100%3/3
A || B
A= $conf->{'vhostOptions'}{$vhost}{'vhostAuthnLevel'}B= $conf->{'defaultAuthnLevel'}
ABresult
1X1
011
000
278 $class->tsv->{serviceTokenTTL}->{$vhost} =
279 92 $conf->{vhostOptions}->{$vhost}->{vhostServiceTokenTTL};
280 $class->tsv->{accessToTrace}->{$vhost} =
281 92 $conf->{vhostOptions}->{$vhost}->{vhostAccessToTrace};
282 $class->tsv->{devOpsRulesUrl}->{$vhost} =
283 92 $conf->{vhostOptions}->{$vhost}->{vhostDevOpsRulesUrl};
284 }
285 }
286 54 return 1;
287 }
288  
289 ## @imethod protected void portalInit(hashRef args)
290 # Verify that portal variable exists. Die unless
291 # @param $args reference to the configuration hash
292 53 ▶sub portalInit {
Subroutine portalInit: called CC=3 SCAR=12.6
Pod undocumented
293 53 my ( $class, $conf ) = @_;
294 53 ▶ unless ( $conf->{portal} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conf->{"portal"}) 0 53 53
295 0 $class->logger->error("portal parameter required");
296 0 return 0;
297 }
298 53 ▶ if ( $conf->{portal} =~ /[\$\(&\|"']/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{'portal'} =~ /[\$\(&\|"']/) { } 0 53 53
299 ( $class->tsv->{portal} ) =
300 0 $class->conditionSub( $conf->{portal} );
301 }
302 else {
303 53 ▶ $class->tsv->{portal} = sub { return $conf->{portal} };
Subroutine __ANON__: called CC=1 SCAR=0.0
304 }
305 53 return 1;
306 }
307  
308 ## @imethod void locationRulesInit(hashRef args)
309 # Compile rules.
310 # Rules are stored in $args->{locationRules}->{<virtualhost>} that contains
311 # regexp=>test expressions where :
312 # - regexp is used to test URIs
313 # - test contains an expression used to grant the user
314 #
315 # This function creates 2 hashRef containing :
316 # - one list of the compiled regular expressions for each virtual host
317 # - one list of the compiled functions (compiled with conditionSub()) for each
318 # virtual host
319 # @param $args reference to the configuration hash
320 58 ▶sub locationRulesInit {
Subroutine locationRulesInit: called CC=24 SCAR=34.4
Pod undocumented
321 58 my ( $class, $conf, $orules ) = @_;
322  
323 58 ▶ $orules ||= $conf->{locationRules};
Condition66%2/3
$orules ||= $conf->{"locationRules"}
l!l&&r!l&&!r
5530
MC/DC0%0/2
$orules ||= $conf->{"locationRules"}
$orules $conf->{"locationRules"}
Truth table66%2/3
A ||= B
A= $orulesB= $conf->{"locationRules"}
ABresult
1X1
011
000
324 58 $class->tsv->{vhostReg} = [];
325 58 my @lastReg;
326  
327 58 foreach my $vhost ( keys %$orules ) {
328 353 my $rules = $orules->{$vhost};
329 353 ▶ if ( $vhost =~ /[\%\*]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vhost =~ /[\%\*]/) 168 185 353
330 my $expr = join '[^\.]*', map {
331 168 my $elt = $_;
332 210 join '.*', map { quotemeta $_ } split /\*/, $elt;
333 } split /\%/, $vhost;
334 168 ▶ if ($expr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr) { } 168 0 168
335 168 push @{ $class->tsv->{vhostReg} }, [ qr/^$expr$/, $vhost ];
336 }
337 else {
338 0 push @lastReg, [ qr/.+/, $vhost ];
339 }
340 }
341 353 $class->tsv->{locationCount}->{$vhost} = 0;
342 353 $class->tsv->{locationCondition}->{$vhost} = [];
343 353 $class->tsv->{locationProtection}->{$vhost} = [];
344 353 $class->tsv->{locationRegexp}->{$vhost} = [];
345 353 $class->tsv->{locationConditionText}->{$vhost} = [];
346 353 $class->tsv->{locationAuthnLevel}->{$vhost} = [];
347  
348 353 foreach my $url ( sort keys %{$rules} ) {
349 1101 my ( $cond, $prot ) = $class->conditionSub( $rules->{$url} );
350 1101 ▶ unless ($cond) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cond) 0 1101 1101
351 0 $class->tsv->{maintenance}->{$vhost} = 1;
352 $class->logger->error(
353 "Unable to build rule '$rules->{$url}': "
354 0 . $class->tsv->{jail}->error );
355 0 next;
356 }
357  
358 # The path of the URL is tested against its canonical form
359 # (decoded and normalized), so percent-encoded characters can't
360 # match any more there. The query string is left untouched, so
361 # only look at the part before the '?' of the rule, which is
362 # escaped since rules are regular expressions (see canonicalUri())
363 1101 my $rulePath = $url;
364 1101 $rulePath =~ s/\\\?.*$//s;
365 1101 ▶ if ( $rulePath =~ /%[0-9A-Fa-f]{2}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rulePath =~ /%[0-9A-Fa-f]{2}/) 0 1101 1101
366 0 $class->logger->warn(
367 "Rule '$url' of virtual host $vhost contains "
368 . "percent-encoded characters in its path: it can't "
369 . "match, rules are tested against the decoded URL" );
370 }
371  
372 1101 ▶ if ( $url eq 'default' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url eq 'default') { } 353 748 1101
373 353 $class->tsv->{defaultCondition}->{$vhost} = $cond;
374 353 $class->tsv->{defaultProtection}->{$vhost} = $prot;
375 }
376 else {
377 748 push @{ $class->tsv->{locationCondition}->{$vhost} }, $cond;
378 748 push @{ $class->tsv->{locationProtection}->{$vhost} }, $prot;
379 748 push @{ $class->tsv->{locationRegexp}->{$vhost} }, qr/$url/;
380 748 ▶ push @{ $class->tsv->{locationAuthnLevel}->{$vhost} },
Branch: 1 branch
BranchTrueFalseTotal
$url =~ /\(\?#AuthnLevel=(-?\d+)\)/ ? : 126 622 748
381 $url =~ /\(\?#AuthnLevel=(-?\d+)\)/
382 ? $1
383 : undef;
384 748 ▶ push @{ $class->tsv->{locationConditionText}->{$vhost} },
Branch: 2 branches
BranchTrueFalseTotal
$url =~ /^\(\?#(.*?)\)/ ? : 132 616 748
$url =~ /^(.*?)##(.+)$/ ? : 0 616 616
385 $url =~ /^\(\?#(.*?)\)/ ? $1
386 : $url =~ /^(.*?)##(.+)$/ ? $2
387 : $url;
388 748 $class->tsv->{locationCount}->{$vhost}++;
389 }
390 }
391  
392 # Default policy set to 'accept'
393 353 ▶ unless ( $class->tsv->{defaultCondition}->{$vhost} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->tsv->{"defaultCondition"}{$vhost}) 0 353 353
394 0 ▶ $class->tsv->{defaultCondition}->{$vhost} = sub { 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
395 0 $class->tsv->{defaultProtection}->{$vhost} = 0;
396 }
397 }
398 42 @{ $class->tsv->{vhostReg} } = sort {
399 199 my $av = $a->[1];
400 199 my $bv = $b->[1];
401 199 ▶ return 1 if $av =~ /^\*/ and $bv !~ /^\*/;
Branch: 1 branch
BranchTrueFalseTotal
if $av =~ /^\*/ and not $bv =~ /^\*/ 40 159 199
Condition66%2/3
$av =~ /^\*/ and not $bv =~ /^\*/
!ll&&!rl&&r
159040
MC/DC50%1/2
$av =~ /^\*/ and not $bv =~ /^\*/
$av =~ /^\*/ not $bv =~ /^\*/
Truth table66%2/3
A and not(B)
A= $av =~ /^\*/B= not $bv =~ /^\*/
ABresult
0X0
100
111
402 159 ▶ return -1 if $bv =~ /^\*/ and $av !~ /^\*/;
Branch: 1 branch
BranchTrueFalseTotal
if $bv =~ /^\*/ and not $av =~ /^\*/ 46 113 159
Condition66%2/3
$bv =~ /^\*/ and not $av =~ /^\*/
!ll&&!rl&&r
113046
MC/DC50%1/2
$bv =~ /^\*/ and not $av =~ /^\*/
$bv =~ /^\*/ not $av =~ /^\*/
Truth table66%2/3
A and not(B)
A= $bv =~ /^\*/B= not $av =~ /^\*/
ABresult
0X0
100
111
403 113 ▶ return 1 if $av =~ /^\%/ and $bv !~ /^\%/;
Branch: 1 branch
BranchTrueFalseTotal
if $av =~ /^\%/ and not $bv =~ /^\%/ 0 113 113
Condition33%1/3
$av =~ /^\%/ and not $bv =~ /^\%/
!ll&&!rl&&r
11300
MC/DC0%0/2
$av =~ /^\%/ and not $bv =~ /^\%/
$av =~ /^\%/ not $bv =~ /^\%/
Truth table33%1/3
A and not(B)
A= $av =~ /^\%/B= not $bv =~ /^\%/
ABresult
0X0
100
111
404 113 ▶ return -1 if $bv =~ /^\%/ and $av !~ /^\%/;
Branch: 1 branch
BranchTrueFalseTotal
if $bv =~ /^\%/ and not $av =~ /^\%/ 0 113 113
Condition33%1/3
$bv =~ /^\%/ and not $av =~ /^\%/
!ll&&!rl&&r
11300
MC/DC0%0/2
$bv =~ /^\%/ and not $av =~ /^\%/
$bv =~ /^\%/ not $av =~ /^\%/
Truth table33%1/3
A and not(B)
A= $bv =~ /^\%/B= not $av =~ /^\%/
ABresult
0X0
100
111
405 113 ▶ return length($bv) <=> length($av) || $av cmp $bv;
Condition33%1/3
length $bv <=> length $av || $av cmp $bv
l!l&&r!l&&!r
11300
MC/DC0%0/2
length $bv <=> length $av || $av cmp $bv
length $bv <=> length $av $av cmp $bv
Truth table33%1/3
A || B
A= length $bv <=> length $avB= $av cmp $bv
ABresult
1X1
011
000
406 58 ▶ } @{ $class->tsv->{vhostReg} } if @{ $class->tsv->{vhostReg} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$class->tsv->{"vhostReg"};} 42 16 58
407 0 ▶ push @{ $class->tsv->{vhostReg} }, @lastReg if @lastReg;
Branch: 1 branch
BranchTrueFalseTotal
if @lastReg 0 58 58
408 58 return 1;
409 }
410  
411 ## @imethod protected void sessionStorageInit(hashRef args)
412 # Initialize the Apache::Session::* module choosed to share user's variables
413 # and the Cache::Cache module chosen to cache sessions
414 # @param $args reference to the configuration hash
415 53 ▶sub sessionStorageInit {
Subroutine sessionStorageInit: called CC=10 SCAR=35.6
Pod undocumented
416 53 my ( $class, $conf ) = @_;
417  
418 # Global session storage
419 53 ▶ unless ( $class->tsv->{sessionStorageModule} = $conf->{globalStorage} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->tsv->{"sessionStorageModule"} = $conf->{"globalStorage"}) 0 53 53
420 0 $class->logger->error("globalStorage required");
421 0 return 0;
422 }
423 25 ▶ eval "use " . $class->tsv->{sessionStorageModule};
Subroutine BEGIN: called CC=1 SCAR=0.0
424 53 ▶ die($@) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 53 53
425 53 $class->tsv->{sessionStorageOptions} = $conf->{globalStorageOptions};
426  
427 # OIDC session storage
428 53 ▶ if ( $conf->{oidcStorage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{'oidcStorage'}) { } 0 53 53
429 0 eval "use " . $conf->{oidcStorage};
430 0 ▶ die($@) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
431 0 $class->tsv->{oidcStorageModule} = $conf->{oidcStorage};
432 0 $class->tsv->{oidcStorageOptions} = $conf->{oidcStorageOptions};
433  
434 }
435 else {
436 53 $class->tsv->{oidcStorageModule} = $conf->{globalStorage};
437 53 $class->tsv->{oidcStorageOptions} = $conf->{globalStorageOptions};
438 }
439  
440 # Local session storage
441 53 ▶ if ( $conf->{localSessionStorage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"localSessionStorage"}) 0 53 53
442 0 $class->tsv->{sessionCacheModule} = $conf->{localSessionStorage};
443 $class->tsv->{sessionCacheOptions} =
444 0 $conf->{localSessionStorageOptions};
445 0 ▶ $class->tsv->{sessionCacheOptions}->{default_expires_in} ||= 600;
Condition0%0/2
$class->tsv->{"sessionCacheOptions"}{"default_expires_in"} ||= 600
l!l
00
MC/DC0%0/1
$class->tsv->{"sessionCacheOptions"}{"default_expires_in"} ||= 600
$class->tsv->{"sessionCacheOptions"}{"default_expires_in"}
Truth table0%0/2
A
A= $class->tsv->{"sessionCacheOptions"}{"default_expires_in"}
Aresult
11
00
446  
447 0 ▶ if ( $conf->{status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"status"}) 0 0 0
448 0 my $params = "";
449 0 ▶ if ( $class->tsv->{sessionCacheModule} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->tsv->{"sessionCacheModule"}) 0 0 0
450 $params = $class->tsv->{sessionCacheModule} . ',{' . join(
451 ',',
452 map {
453 "$_ => '"
454 0 . $class->tsv->{sessionCacheOptions}->{$_} . "'"
455 }
456 0 ▶ keys %{ $class->tsv->{sessionCacheOptions} // {} }
Condition0%0/2
$class->tsv->{"sessionCacheOptions"} // {}
l!l
00
MC/DC0%0/1
$class->tsv->{"sessionCacheOptions"} // {}
$class->tsv->{"sessionCacheOptions"}
Truth table0%0/2
A
A= $class->tsv->{"sessionCacheOptions"}
Aresult
11
00
457 ) . '}';
458 }
459 }
460 }
461 53 return 1;
462 }
463  
464 ## @imethod void headersInit(hashRef args)
465 # Create the subroutines used to insert headers into the HTTP request.
466 # @param $args reference to the configuration hash
467 58 ▶sub headersInit {
Subroutine headersInit: called CC=8 SCAR=21.7
Pod undocumented
468 58 my ( $class, $conf, $headers ) = @_;
469 58 ▶ $headers ||= $conf->{exportedHeaders};
Condition100%3/3
$headers ||= $conf->{"exportedHeaders"}
l!l&&r!l&&!r
5503
MC/DC100%2/2
$headers ||= $conf->{"exportedHeaders"}
$headers $conf->{"exportedHeaders"}
Truth table100%3/3
A ||= B
A= $headersB= $conf->{"exportedHeaders"}
ABresult
1X1
011
000
470  
471 # Creation of the subroutine which will generate headers
472 58 foreach my $vhost ( keys %{$headers} ) {
473 114 ▶ unless ($vhost) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vhost) 0 114 114
474 0 $class->logger->warn('Empty vhost in headers, skipping');
475 0 next;
476 }
477 114 ▶ $headers->{$vhost} ||= {};
Condition50%1/2
$headers->{$vhost} ||= {}
l!l
1140
MC/DC0%0/1
$headers->{$vhost} ||= {}
$headers->{$vhost}
Truth table50%1/2
A
A= $headers->{$vhost}
Aresult
11
00
478 114 my %headers = %{ $headers->{$vhost} };
479 114 $class->tsv->{headerList}->{$vhost} = [ keys %headers ];
480 114 my $sub = '';
481 114 foreach ( keys %headers ) {
482 140 ▶ $headers{$_} ||= "''";
Condition100%2/2
$headers{$_} ||= "''"
l!l
1346
MC/DC100%1/1
$headers{$_} ||= "''"
$headers{$_}
Truth table100%2/2
A
A= $headers{$_}
Aresult
11
00
483 140 my $val = $class->substitute( $headers{$_} ) . " // ''";
484 140 $sub .= "('$_' => $val),";
485 }
486  
487 114 ▶ unless ( $class->tsv->{forgeHeaders}->{$vhost} =
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->tsv->{"forgeHeaders"}{$vhost} = $class->buildSub($sub)) 0 114 114
488 $class->buildSub($sub) )
489 {
490 0 $class->tsv->{maintenance}->{$vhost} = 1;
491 $class->logger->error( "$class Unable to forge $vhost headers: "
492 0 . $class->tsv->{jail}->error );
493 }
494 }
495 58 return 1;
496 }
497  
498 ## @imethod protected void postUrlInit()
499 # Prepare methods to post form attributes
500 53 ▶sub postUrlInit {
Subroutine postUrlInit: called CC=9 SCAR=38.2
Pod undocumented
501 53 my ( $class, $conf ) = @_;
502 53 ▶ return unless ( $conf->{post} );
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->{"post"} 50 3 53
503  
504 # Browse all vhost
505 3 foreach my $vhost ( keys %{ $conf->{post} } ) {
506  
507 # Browse all POST URI
508 0 ▶ foreach my $url ( keys %{ $conf->{post}->{$vhost} || {} } ) {
Condition0%0/2
$conf->{'post'}{$vhost} || {}
l!l
00
MC/DC0%0/1
$conf->{'post'}{$vhost} || {}
$conf->{'post'}{$vhost}
Truth table0%0/2
A
A= $conf->{'post'}{$vhost}
Aresult
11
00
509 0 my $d = $conf->{post}->{$vhost}->{$url};
510 0 $class->logger->debug("Compiling POST data for $url");
511  
512 # Where to POST
513 0 ▶ $d->{target} ||= $url;
Condition0%0/3
$d->{"target"} ||= $url
l!l&&r!l&&!r
000
MC/DC0%0/2
$d->{"target"} ||= $url
$d->{"target"} $url
Truth table0%0/3
A ||= B
A= $d->{"target"}B= $url
ABresult
1X1
011
000
514 0 my $sub;
515 0 ▶ $d->{vars} ||= [];
Condition0%0/2
$d->{"vars"} ||= []
l!l
00
MC/DC0%0/1
$d->{"vars"} ||= []
$d->{"vars"}
Truth table0%0/2
A
A= $d->{"vars"}
Aresult
11
00
516 0 foreach my $input ( @{ delete $d->{vars} } ) {
517 0 $sub .=
518 "'$input->[0]' => " . $class->substitute( $input->[1] ) . ",";
519 }
520 0 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->tsv->{"inputPostData"}{$vhost}{delete $d->{"target"}} = $class->tsv->{"outputPostData"}{$vhost}{$url} = $class->buildSub($sub)) 0 0 0
521 $class->tsv->{inputPostData}->{$vhost}->{ delete $d->{target} }
522 = $class->tsv->{outputPostData}->{$vhost}->{$url} =
523 $class->buildSub($sub) )
524 {
525 0 $class->tsv->{maintenance}->{$vhost} = 1;
526 $class->logger->error( "$class: Unable to build post data: "
527 0 . $class->tsv->{jail}->error );
528 }
529  
530 0 $class->tsv->{postFormParams}->{$vhost}->{$url} = $d;
531 }
532 }
533 3 return 1;
534 }
535  
536 ## @imethod protected codeRef conditionSub(string cond)
537 # Returns a compiled function used to grant users (used by
538 # locationRulesInit(). The second value returned is a non null
539 # constant if URL is not protected (by "unprotect" or "skip"), 0 else.
540 # @param $cond The boolean expression to use
541 # @param $mainClass optional
542 # @return array (ref(sub), int)
543 1101 ▶sub conditionSub {
Subroutine conditionSub: called CC=11 SCAR=26.4
Pod undocumented
544 1101 my ( $class, $cond ) = @_;
545 1101 $cond =~ s/\(\?#(\d+)\)$//;
546 1101 ▶ my ( $OK, $NOK ) = ( sub { 1 }, sub { 0 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
547  
548 # Simple cases : accept and deny
549 1101 ▶ return ( $OK, 0 )
Branch: 1 branch
BranchTrueFalseTotal
if $cond =~ /^accept$/i 399 702 1101
550 if ( $cond =~ /^accept$/i );
551 702 ▶ return ( $NOK, 0 )
Branch: 1 branch
BranchTrueFalseTotal
if $cond =~ /^deny$/i 139 563 702
552 if ( $cond =~ /^deny$/i );
553  
554 # Cases unprotect and skip : 2nd value is 1 or 2
555 563 ▶ return ( $OK, UNPROTECT )
Branch: 1 branch
BranchTrueFalseTotal
if $cond =~ /^unprotect$/i 0 563 563
556 if ( $cond =~ /^unprotect$/i );
557 563 ▶ return ( $OK, SKIP )
Branch: 1 branch
BranchTrueFalseTotal
if $cond =~ /^skip$/i 42 521 563
558 if ( $cond =~ /^skip$/i );
559  
560 # Case logout
561 521 ▶ if ( $cond =~ /^logout(?:_sso)?(?:\s+(.*))?$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cond =~ /^logout(?:_sso)?(?:\s+(.*))?$/i) 84 437 521
562 84 my $url = $1;
563 return (
564 $url
565 ? (
566 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
567 0 my ( $req, $session ) = @_;
568 0 $session->{_logout} = $url;
569 0 return 0;
570 },
571 0
572 )
573 : (
574 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
575 0 my ( $req, $session ) = @_;
576 0 $session->{_logout} = $class->tsv->{portal}->($req);
577 0 return 0;
578 },
579 84 ▶ 0
Branch: 1 branch
BranchTrueFalseTotal
$url ? : 0 84 84
580 )
581 );
582 }
583  
584 # logout_app
585 437 ▶ if ( $cond =~ /^logout_app(?:\s+(.*))?$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cond =~ /^logout_app(?:\s+(.*))?$/i) { } 0 437 437
elsif ($cond =~ /^logout_app_sso(?:\s+(.*))?$/i) { } 0 437 437
586 0 return $class->logout_app($1);
587 }
588  
589 # logout_app_sso
590 elsif ( $cond =~ /^logout_app_sso(?:\s+(.*))?$/i ) {
591 0 return $class->logout_app_sso($1);
592 }
593  
594 437 my $mayskip = 0;
595 437 ▶ $mayskip = MAYSKIP if $cond =~ /\bskip\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $cond =~ /\bskip\b/ 42 395 437
596  
597 # Replace some strings in condition
598 437 $cond = $class->substitute($cond);
599 437 my $sub;
600 437 ▶ unless ( $sub = $class->buildSub($cond) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sub = $class->buildSub($cond)) 0 437 437
601 $class->logger->error( "$class: Unable to build condition ($cond): "
602 0 . $class->tsv->{jail}->error );
603 }
604  
605 # Return sub and protected flag
606 437 return ( $sub, $mayskip );
607 }
608  
609 ## These methods should be overriden in subclasses
610 0 ▶sub logout_app {
Subroutine logout_app: not called CC=1 SCAR=6.9
Pod undocumented
611 0 ▶ return ( sub { 1 }, 0 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
612 }
613  
614 0 ▶sub logout_app_sso {
Subroutine logout_app_sso: not called CC=1 SCAR=6.9
Pod undocumented
615 0 ▶ return ( sub { 1 }, 0 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
616 }
617  
618 ## @method arrayref aliasInit
619 # @param options vhostOptions configuration item
620 # @return arrayref of vhost and aliases
621 53 ▶sub aliasInit {
Subroutine aliasInit: called CC=5 SCAR=17.5
Pod undocumented
622 53 my ( $class, $conf ) = @_;
623  
624 53 delete $class->tsv->{vhostAlias};
625 53 ▶ foreach my $vhost ( keys %{ $conf->{vhostOptions} || {} } ) {
Condition100%2/2
$conf->{'vhostOptions'} || {}
l!l
503
MC/DC100%1/1
$conf->{'vhostOptions'} || {}
$conf->{'vhostOptions'}
Truth table100%2/2
A
A= $conf->{'vhostOptions'}
Aresult
11
00
626 91 ▶ if ( my $aliases = $conf->{vhostOptions}->{$vhost}->{vhostAliases} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $aliases = $conf->{"vhostOptions"}{$vhost}{"vhostAliases"}) 0 91 91
627 0 foreach ( split /\s+/, $aliases ) {
628 0 $class->tsv->{vhostAlias}->{$_} = $vhost;
629 0 $class->logger->debug("Registering $_ as alias of $vhost");
630 }
631 }
632 }
633 53 return 1;
634 }
635  
636 # TODO: support wildcards in aliases
637  
638 ## @method arrayref oauth2Init
639 # @param options vhostOptions configuration item
640 # @return arrayref of vhost and aliases
641 53 ▶sub oauth2Init {
Subroutine oauth2Init: called CC=5 SCAR=16.7
Pod undocumented
642 53 my ( $class, $conf ) = @_;
643  
644 53 ▶ foreach my $rp ( keys %{ $conf->{oidcRPMetaDataOptions} || {} } ) {
Condition100%2/2
$conf->{'oidcRPMetaDataOptions'} || {}
l!l
251
MC/DC100%1/1
$conf->{'oidcRPMetaDataOptions'} || {}
$conf->{'oidcRPMetaDataOptions'}
Truth table100%2/2
A
A= $conf->{'oidcRPMetaDataOptions'}
Aresult
11
00
645 4 ▶ if ( $conf->{oidcRPMetaDataOptions}->{$rp}
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"oidcRPMetaDataOptions"}{$rp} and $conf->{"oidcRPMetaDataOptions"}{$rp}{"oidcRPMetaDataOptionsClientID"}) 4 0 4
Condition33%1/3
$conf->{"oidcRPMetaDataOptions"}{$rp} and $conf->{"oidcRPMetaDataOptions"}{$rp}{"oidcRPMetaDataOptionsClientID"}
!ll&&!rl&&r
004
MC/DC0%0/2
$conf->{"oidcRPMetaDataOptions"}{$rp} and $conf->{"oidcRPMetaDataOptions"}{$rp}{"oidcRPMetaDataOptionsClientID"}
$conf->{"oidcRPMetaDataOptions"}{$rp} $conf->{"oidcRPMetaDataOptions"}{$rp}{"oidcRPMetaDataOptionsClientID"}
Truth table33%1/3
A and B
A= $conf->{"oidcRPMetaDataOptions"}{$rp}B= $conf->{"oidcRPMetaDataOptions"}{$rp}{"oidcRPMetaDataOptionsClientID"}
ABresult
0X0
100
111
646 and $conf->{oidcRPMetaDataOptions}->{$rp}
647 ->{oidcRPMetaDataOptionsClientID} )
648 {
649 $class->tsv->{oauth2Options}->{$rp}->{clientId} =
650 $conf->{oidcRPMetaDataOptions}->{$rp}
651 4 ->{oidcRPMetaDataOptionsClientID};
652 }
653 }
654 53 return 1;
655 }
656  
657 53 ▶sub msgBrokerInit {
Subroutine msgBrokerInit: called CC=3 SCAR=11.1
Pod undocumented
658 53 my ( $class, $conf ) = @_;
659  
660 53 ▶ my $brokerClass = $conf->{messageBroker} || '::NoBroker';
Condition50%1/2
$conf->{'messageBroker'} || '::NoBroker'
l!l
053
MC/DC0%0/1
$conf->{'messageBroker'} || '::NoBroker'
$conf->{'messageBroker'}
Truth table50%1/2
A
A= $conf->{'messageBroker'}
Aresult
11
00
661 53 $brokerClass =~ s/^::/Lemonldap::NG::Common::MessageBroker::/;
662 53 eval "require $brokerClass";
663 53 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 53 53
664 53 $class->tsv->{msgBrokerReader} = $brokerClass->new( $conf, $class->logger );
665 53 $class->tsv->{msgBrokerReader}->subscribe( $conf->{eventQueueName} );
666 53 $class->tsv->{msgBrokerWriter} = $brokerClass->new( $conf, $class->logger );
667 }
668  
669 604 ▶sub substitute {
Subroutine substitute: called CC=2 SCAR=6.9
Pod undocumented
670 604 my ( $class, $expr ) = @_;
671 604 ▶ $expr //= '';
Condition100%2/2
$expr //= ""
l!l
6022
MC/DC100%1/1
$expr //= ""
$expr
Truth table100%2/2
A
A= $expr
Aresult
11
00
672  
673 # substitute special vars, just for retro-compatibility
674 604 $expr =~ s/\$date\b/&date/sg;
675 604 $expr =~ s/\$vhost\b/\$ENV{HTTP_HOST}/sg;
676 604 $expr =~ s/\$ip\b/\$ENV{REMOTE_ADDR}/sg;
677  
678 # substitute vars with session data, excepts special vars $_ and $\d+
679 604 $expr =~ s/\$(?!(?:ENV|env)\b)(_\w+|[a-zA-Z]\w*)/\$s->{$1}/sg;
680 604 $expr =~ s/\$ENV\{/\$r->{env}->\{/g;
681 604 $expr =~ s/\$env->\{/\$r->{env}->\{/g;
682 604 $expr =~ s/\bskip\b/q\{999_SKIP\}/g;
683  
684 # handle inGroup
685 604 $expr =~ s/\binGroup\(([^)]*)\)/listMatch(\$s->{'hGroups'},$1,1)/g;
686  
687 # handle has2f
688 604 $expr =~ s/\bhas2f\(([^),]*)\)/has2f_internal(\$s,$1)/g;
689  
690 # handle inSubnet
691 604 $expr =~ s/\binSubnet\(([^)]*)\)/ipInSubnet(\$r->{env}->{REMOTE_ADDR},$1)/g;
692  
693 # handle inSubnet
694 604 $expr =~
695 s/\binDomain\(([^)]*)\)/inDomain_internal(\$r->{env}->{HTTP_HOST},$1)/g;
696  
697 604 return $expr;
698 }
699  
700 578 ▶sub buildSub {
Subroutine buildSub: called CC=2 SCAR=7.4
Pod undocumented
701 578 my ( $class, $val ) = @_;
702 my $res =
703 $class->tsv->{jail}
704 578 ->jail_reval("sub{my (\$r,\$s)=\@_; local *_;return($val)}");
705 578 ▶ unless ($res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 578 578
706 0 $class->logger->error( $class->tsv->{jail}->error );
707 }
708 578 return $res;
709 }
710  
711 29 1;
« Lemonldap/NG/Handler/Main/Jail.pm ↑ Summary Lemonldap/NG/Handler/ApacheMP2.pm »