« blib/lib/Lemonldap/NG/Portal/Lib/Radius.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/2F/Register/Generic.pm »
| 1 | ##@file | ||||||||||||||||||||||||||||||||
| 2 | # Slave common functions | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | ##@class | ||||||||||||||||||||||||||||||||
| 5 | # Slave common functions | ||||||||||||||||||||||||||||||||
| 6 | package Lemonldap::NG::Portal::Lib::Slave; | ||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Net::CIDR; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 6 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | # RUNNING METHODS | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | ## @method Lemonldap::NG::Portal::_Slave checkIP() | ||||||||||||||||||||||||||||||||
| 17 | # @return true if remote IP is accredited in LL::NG conf | ||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | sub checkIP { | ||||||||||||||||||||||||||||||
|
Subroutine
checkIP: called CC=8 SCAR=38.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 19 | 3 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||
| 20 | 3 | my ( @networks, @IPs ); | |||||||||||||||||||||||||||||||
| 21 | 3 | my $remoteIP = $req->address; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | return 1 | ||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | unless $self->conf->{slaveMasterIP}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | @IPs = grep { | ||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ( m#/# && Net::CIDR::cidrvalidate($_) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
m[/] and Net::CIDR::cidrvalidate($_)
MC/DC0%0/2
m[/] and Net::CIDR::cidrvalidate($_)
m[/]
Net::CIDR::cidrvalidate($_)
Truth table0%0/3
A and B
A= m[/]B= Net::CIDR::cidrvalidate($_)
| |||||||||||||||||||||||||||||||||
| 28 | 0 | push @networks, $_; | |||||||||||||||||||||||||||||||
| 29 | 0 | $self->logger->debug("Found netblock: $_"); | |||||||||||||||||||||||||||||||
| 30 | 0 | 0; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | elsif ( Net::CIDR::cidrvalidate($_) ) { | ||||||||||||||||||||||||||||||||
| 33 | 0 | $self->logger->debug("Found IP address: $_"); | |||||||||||||||||||||||||||||||
| 34 | 0 | 1; | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | else { | ||||||||||||||||||||||||||||||||
| 37 | 0 | $self->logger->warn("Found a non valid IP: $_"); | |||||||||||||||||||||||||||||||
| 38 | 0 | 0; | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | 0 | } split /[,\s]/, $self->conf->{slaveMasterIP}; | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | foreach (@IPs) { | |||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return 1 | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | if $remoteIP eq $_; | ||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return 1 if Net::CIDR::cidrlookup( $remoteIP, @networks ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | $self->userLogger->warn('Client IP not accredited for Slave module'); | |||||||||||||||||||||||||||||||
| 49 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | ## @method Lemonldap::NG::Portal::_Slave checkHeader() | ||||||||||||||||||||||||||||||||
| 53 | # @return true if header content matches LL::NG conf | ||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | sub checkHeader { | ||||||||||||||||||||||||||||||
|
Subroutine
checkHeader: called CC=6 SCAR=32.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 55 | 3 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||
| 56 | return 1 | ||||||||||||||||||||||||||||||||
| 57 | unless ( $self->conf->{slaveHeaderName} | ||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | && $self->conf->{slaveHeaderContent} ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"slaveHeaderName"} and $self->conf->{"slaveHeaderContent"}
MC/DC0%0/2
$self->conf->{"slaveHeaderName"} and $self->conf->{"slaveHeaderContent"}
$self->conf->{"slaveHeaderName"}
$self->conf->{"slaveHeaderContent"}
Truth table33%1/3
A and B
A= $self->conf->{"slaveHeaderName"}B= $self->conf->{"slaveHeaderContent"}
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | my $slave_header = 'HTTP_' . uc( $self->conf->{slaveHeaderName} ); | |||||||||||||||||||||||||||||||
| 61 | 0 | $slave_header =~ s/\-/_/g; | |||||||||||||||||||||||||||||||
| 62 | 0 | my $headerContent = $req->env->{$slave_header}; | |||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( $headerContent && length $headerContent ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$headerContent and length $headerContent
MC/DC0%0/2
$headerContent and length $headerContent
$headerContent
length $headerContent
Truth table0%0/3
A and B
A= $headerContentB= length $headerContent
| |||||||||||||||||||||||||||||||||
| 64 | 0 | $self->logger->debug( | |||||||||||||||||||||||||||||||
| 65 | "Required Slave header: $self->{conf}->{slaveHeaderName}" | ||||||||||||||||||||||||||||||||
| 66 | . "\nReceived Slave header content: $headerContent" ); | ||||||||||||||||||||||||||||||||
| 67 | return 1 | ||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( $self->conf->{slaveHeaderContent} =~ /\b$headerContent\b/ ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||
| 71 | 0 | $self->logger->notice("No Slave header content received"); | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 0 | $self->userLogger->warn('Matching header not found for Slave module'); | |||||||||||||||||||||||||||||||
| 75 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | ## @method Lemonldap::NG::Portal::_Slave checkCertificate() | ||||||||||||||||||||||||||||||||
| 79 | # @return true if value matches LL::NG conf | ||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | sub checkCertificate { | ||||||||||||||||||||||||||||||
|
Subroutine
checkCertificate: called CC=6 SCAR=32.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 81 | 3 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||
| 82 | return 1 | ||||||||||||||||||||||||||||||||
| 83 | unless ( $self->conf->{slaveCertificateField} | ||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | && $self->conf->{slaveCertificateRegexp} ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"slaveCertificateField"} and $self->conf->{"slaveCertificateRegexp"}
MC/DC0%0/2
$self->conf->{"slaveCertificateField"} and $self->conf->{"slaveCertificateRegexp"}
$self->conf->{"slaveCertificateField"}
$self->conf->{"slaveCertificateRegexp"}
Truth table33%1/3
A and B
A= $self->conf->{"slaveCertificateField"}B= $self->conf->{"slaveCertificateRegexp"}
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | my $regexp = $self->conf->{slaveCertificateRegexp}; | |||||||||||||||||||||||||||||||
| 87 | 0 | my $value = $req->env->{ $self->conf->{slaveCertificateField} }; | |||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ( $value && length $value ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$value and length $value
MC/DC0%0/2
$value and length $value
$value
length $value
Truth table0%0/3
A and B
A= $valueB= length $value
| |||||||||||||||||||||||||||||||||
| 89 | 0 | $self->logger->debug( | |||||||||||||||||||||||||||||||
| 90 | "Required Slave field: $self->{conf}->{slaveCertificateField}" | ||||||||||||||||||||||||||||||||
| 91 | . "\nReceived Slave value: $value" ); | ||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return 1 | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | if ( $value =~ qr/$regexp/ ); | ||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||||||
| 96 | 0 | $self->logger->notice( | |||||||||||||||||||||||||||||||
| 97 | "No subject found in certificate, check your configuration"); | ||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | $self->userLogger->warn( | |||||||||||||||||||||||||||||||
| 101 | 'Client certificate not accredited for Slave module'); | ||||||||||||||||||||||||||||||||
| 102 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 6 | 1; | |||||||||||||||||||||||||||||||