Tidy all the code (make tidy)

This commit is contained in:
Clément Oudot 2012-02-29 13:19:57 +00:00
parent 8f576d09c2
commit 979d1abe62
16 changed files with 120 additions and 122 deletions

View File

@ -335,6 +335,7 @@ sub extract_lang {
my @langs = split /,\s*/, ( $ENV{HTTP_ACCEPT_LANGUAGE} || "" );
my @res = ();
foreach (@langs) {
# languages are supposed to be sorted by preference
# only 2-letters lang tags are considered
my $lang = ( split /;/ )[0];

View File

@ -58,9 +58,7 @@ sub encrypt {
my $l = bytes::length($data) % 16;
$data .= "\0" x ( 16 - $l ) unless ( $l == 0 );
eval {
$data = encode_base64( $self->_getCipher->encrypt( $data ) );
};
eval { $data = encode_base64( $self->_getCipher->encrypt($data) ); };
if ($@) {
$msg = "Crypt::Rijndael error : $@";
return undef;
@ -105,7 +103,7 @@ sub decrypt {
# @return encrypted datas in hexadecimal data
sub encryptHex {
my ( $self, $data, $key ) = @_;
return _cryptHex($self, $data, $key, "encrypt")
return _cryptHex( $self, $data, $key, "encrypt" );
}
## @method string decryptHex(string data, string key)
@ -117,7 +115,7 @@ sub encryptHex {
# @return decrypted datas in hexadecimal data
sub decryptHex {
my ( $self, $data, $key ) = @_;
return _cryptHex($self, $data, $key, "decrypt")
return _cryptHex( $self, $data, $key, "decrypt" );
}
## @method private string _cryptHex (string data, string key, string sub)
@ -129,13 +127,16 @@ sub decryptHex {
sub _cryptHex {
my ( $self, $data, $key, $sub ) = @_;
unless ( $data =~ /^([0-9a-fA-F]{2})*$/ ) {
$msg = "Lemonldap::NG::Common::Crypto::${sub}Hex error : data is not hexadecimal";
$msg =
"Lemonldap::NG::Common::Crypto::${sub}Hex error : data is not hexadecimal";
return undef;
}
# $data's length must be multiple of 32,
# since Rijndael requires data length multiple of 16
unless ( bytes::length($data) % 32 == 0 ) {
$msg = "Lemonldap::NG::Common::Crypto::${sub}Hex error : data length must be multiple of 32";
$msg =
"Lemonldap::NG::Common::Crypto::${sub}Hex error : data length must be multiple of 32";
return undef;
}
$data = pack "H*", $data;

View File

@ -36,8 +36,6 @@ foreach my $i ( 1 .. 17 ) {
my $data = md5_hex(rand);
my $secondKey = md5(rand);
ok(
$c->decryptHex(
$c->encryptHex( $data, $secondKey ),
$secondKey ) eq $data,
$c->decryptHex( $c->encryptHex( $data, $secondKey ), $secondKey ) eq $data,
"Test of hexadecimal encrypting"
);

View File

@ -658,8 +658,9 @@ sub defaultValuesInit {
# These values should be erased by global configuration!
$cookieName = $args->{cookieName} || $cookieName || 'lemonldap';
$securedCookie =
defined( $args->{securedCookie} ) ? $args->{securedCookie} :
defined($securedCookie) ? $securedCookie : 1;
defined( $args->{securedCookie} ) ? $args->{securedCookie}
: defined($securedCookie) ? $securedCookie
: 1;
$whatToTrace = $args->{whatToTrace} || $whatToTrace || 'uid';
$whatToTrace =~ s/\$//g;
$https = defined($https) ? $https : $args->{https};
@ -683,6 +684,7 @@ sub defaultValuesInit {
: $args->{useSafeJail};
$key ||= 'lemonldap-ng-key';
$cipher ||= Lemonldap::NG::Common::Crypto->new($key);
if ( $args->{key} && ( $args->{key} ne $key ) ) {
$key = $args->{key};
$cipher = Lemonldap::NG::Common::Crypto->new($key);
@ -858,11 +860,11 @@ sub goToPortal {
# @return Value of the cookie if found, 0 else
sub fetchId {
my $t = lmHeaderIn( $apacheRequest, 'Cookie' );
my $lookForHttpCookie =
$securedCookie =~ /^(2|3)$/ && $https->{_} == 0 ;
my $value = $lookForHttpCookie ?
( $t =~ /${cookieName}http=([^,; ]+)/o ? $1 : 0 ) :
( $t =~ /$cookieName=([^,; ]+)/o ? $1 : 0 ) ;
my $lookForHttpCookie = $securedCookie =~ /^(2|3)$/ && $https->{_} == 0;
my $value =
$lookForHttpCookie
? ( $t =~ /${cookieName}http=([^,; ]+)/o ? $1 : 0 )
: ( $t =~ /$cookieName=([^,; ]+)/o ? $1 : 0 );
$value = $cipher->decryptHex( $value, "http" )
if ( $value && $lookForHttpCookie && $securedCookie == 3 );
@ -967,8 +969,10 @@ sub run ($$) {
}
my $id;
# Try to recover cookie and user session
if ( $id = $class->fetchId and $class->retrieveSession($id) ) {
# AUTHENTICATION done
my $kc = keys %$datas; # in order to detect new local macro
@ -979,7 +983,8 @@ sub run ($$) {
# AUTHORIZATION
return $class->forbidden($uri)
unless ( $class->grant($uri) );
$class->updateStatus( $datas->{$whatToTrace}, $apacheRequest->uri, 'OK' );
$class->updateStatus( $datas->{$whatToTrace},
$apacheRequest->uri, 'OK' );
# ACCOUNTING (2. Inform remote application)
$class->sendHeaders;
@ -994,9 +999,8 @@ sub run ($$) {
$class->hideCookie;
# Log
$apacheRequest->push_handlers(
PerlLogHandler => sub { $class->logGranted( $uri, $datas ); DECLINED },
);
$apacheRequest->push_handlers( PerlLogHandler =>
sub { $class->logGranted( $uri, $datas ); DECLINED }, );
# Catch POST rules
$class->transformUri($uri);
@ -1005,6 +1009,7 @@ sub run ($$) {
}
elsif ( $protection == UNPROTECT ) {
# Ignore unprotected URIs
$class->lmLog( "No valid session but unprotected access", "debug" );
$class->updateStatus( $apacheRequest->connection->remote_ip,
@ -1015,9 +1020,11 @@ sub run ($$) {
}
else {
# Redirect user to the portal
$class->lmLog( "$class: No cookie found", 'info' )
unless ($id);
# if the cookie was fetched, a log is sent by retrieveSession()
$class->updateStatus( $apacheRequest->connection->remote_ip,
$apacheRequest->uri, $id ? 'EXPIRED' : 'REDIRECT' );

View File

@ -150,7 +150,6 @@ sub cleanHeaders {
}
}
## @rmethod protected int isUnprotected()
# @return 0 if URI is protected,
# UNPROTECT if it is unprotected by "unprotect",
@ -193,12 +192,12 @@ sub grant {
sub fetchId {
my $t = lmHeaderIn( $apacheRequest, 'Cookie' );
my $vhost = $apacheRequest->hostname;
my $lookForHttpCookie =
$securedCookie =~ /^(2|3)$/
my $lookForHttpCookie = $securedCookie =~ /^(2|3)$/
&& !( defined( $https->{$vhost} ) ? $https->{$vhost} : $https->{_} );
my $value = $lookForHttpCookie ?
( $t =~ /${cookieName}http=([^,; ]+)/o ? $1 : 0 ) :
( $t =~ /$cookieName=([^,; ]+)/o ? $1 : 0 ) ;
my $value =
$lookForHttpCookie
? ( $t =~ /${cookieName}http=([^,; ]+)/o ? $1 : 0 )
: ( $t =~ /$cookieName=([^,; ]+)/o ? $1 : 0 );
$value = $cipher->decryptHex( $value, "http" )
if ( $value && $lookForHttpCookie && $securedCookie == 3 );

View File

@ -170,8 +170,10 @@ sub confNode {
# be translated
# 2. if a regexp comment or perl expression
# comment exists, it is set as text
my $text = /^\(\?#(.*?)\)/ ? $1 :
/^(.*?)##(.+)$/ ? $2 : $_ ;
my $text =
/^\(\?#(.*?)\)/ ? $1
: /^(.*?)##(.+)$/ ? $2
: $_;
$res .= $self->li($id)
. $self->span(

View File

@ -780,7 +780,8 @@ sub extractFormInfo {
# IDP list
my @list = ();
foreach ( keys %{ $self->{_idpList} } ) {
push @list, {
push @list,
{
val => $_,
name => $self->{_idpList}->{$_}->{name}
};

View File

@ -238,8 +238,7 @@ sub _openIDResponse {
$self->info(
'<h3>'
. sprintf(
$self->msg(PM_OPENID_EXCHANGE),
$data->{trust_root}
$self->msg(PM_OPENID_EXCHANGE), $data->{trust_root}
)
. "</h3>"
);

View File

@ -194,9 +194,9 @@ sub issuerForUnAuthUser {
# Create a back link on SP displayed on login page
my $html =
"<a href=\"" . $self->referer() . "\">"
. $self->msg(PM_BACKTOSP)
. "</a>";
"<a href=\""
. $self->referer() . "\">"
. $self->msg(PM_BACKTOSP) . "</a>";
$self->loginInfo($html);
return PE_OK;
@ -1708,11 +1708,7 @@ sub issuerForAuthUser {
. " width=\"0\" height=\"0\" frameborder=\"0\">"
. "</iframe>";
$self->info(
"<h3>"
. $self->msg(PM_CDC_WRITER)
. "</h3>"
);
$self->info( "<h3>" . $self->msg(PM_CDC_WRITER) . "</h3>" );
$self->info($cdc_iframe);
}

View File

@ -91,8 +91,7 @@ sub sregHook {
);
$self->info(
'<h3>' . sprintf( $self->msg(PM_OPENID_RPNS), $k ) . '</h3>'
);
'<h3>' . sprintf( $self->msg(PM_OPENID_RPNS), $k ) . '</h3>' );
return ( 0, {} );
}
}

View File

@ -168,20 +168,16 @@ sub userBind {
# Get expiration warning and graces
if ( $resp->grace_authentications_remaining ) {
$self->{portal}->info(
"<h3>"
$self->{portal}->info( "<h3>"
. $resp->grace_authentications_remaining . " "
. $self->msg(PM_PP_GRACE)
. "</h3>"
);
. "</h3>" );
}
if ( $resp->time_before_expiration ) {
$self->{portal}->info(
"<h3>"
$self->{portal}->info( "<h3>"
. $resp->time_before_expiration . " "
. $self->msg(PM_PP_EXP_WARNING)
. "</h3>"
);
. "</h3>" );
}
my $pp_error = $resp->pp_error;

View File

@ -2637,8 +2637,7 @@ sub sendLogoutRequestToProviders {
# Header of the block which will be displayed to the user, if needed.
$info .= '<h3>'
. $self->msg (Lemonldap::NG::Portal::Simple::PM_SAML_SPLOGOUT)
. '</h3>'
. $self->msg(Lemonldap::NG::Portal::Simple::PM_SAML_SPLOGOUT) . '</h3>'
. '<table class="sloState">';
# Foreach SP found in session, get it from configuration, and send the