From 178cef3eeef588e98849c2a3a97e3616dd0dee4a Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Wed, 17 Feb 2016 19:09:51 +0000 Subject: [PATCH] Include customFunctions in all Perl expr (#820) --- .../lib/Lemonldap/NG/Manager/Attributes.pm | 100 +++++++++++++++++- .../Lemonldap/NG/Manager/Build/Attributes.pm | 14 ++- 2 files changed, 108 insertions(+), 6 deletions(-) diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm index 744037ba0..5883971b4 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm @@ -22,7 +22,25 @@ sub types { 'boolOrExpr' => { 'msgFail' => '__notAValidPerlExpression__', 'test' => sub { - my $s = eval $_[0]; + my ( $val, $conf ) = @_; + my $s = ''; + my (@cf) = ( + 'encode_base64', 'checkLogonHours', + 'date', 'checkDate', + 'basic', 'unicode2iso', + 'iso2unicode', 'groupMatch' + ); + push @cf, defined $conf->{'customFunctions'} + ? map( { + my $f = $_; + $f =~ s/\w+:://g; + $f, $_; + } split( /\s+/, $conf->{'customFunctions'}, 0 ) ) + : (); + foreach my $f (@cf) { + $s = "sub $f {1} $s"; + } + eval "$s $val"; return $@ ? ( 0, "__badExpression__: $@" ) : 1; } }, @@ -814,7 +832,25 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0- }, 'grantSessionRules' => { 'keyTest' => sub { - my $s = eval $_[0]; + my ( $val, $conf ) = @_; + my $s = ''; + my (@cf) = ( + 'encode_base64', 'checkLogonHours', + 'date', 'checkDate', + 'basic', 'unicode2iso', + 'iso2unicode', 'groupMatch' + ); + push @cf, defined $conf->{'customFunctions'} + ? map( { + my $f = $_; + $f =~ s/\w+:://g; + $f, $_; + } split( /\s+/, $conf->{'customFunctions'}, 0 ) ) + : (); + foreach my $f (@cf) { + $s = "sub $f {1} $s"; + } + eval "$s $val"; return $@ ? ( 0, "__badExpression__: $@" ) : 1; }, 'test' => sub { @@ -825,7 +861,25 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0- 'groups' => { 'default' => {}, 'test' => sub { - my $s = eval $_[0]; + my ( $val, $conf ) = @_; + my $s = ''; + my (@cf) = ( + 'encode_base64', 'checkLogonHours', + 'date', 'checkDate', + 'basic', 'unicode2iso', + 'iso2unicode', 'groupMatch' + ); + push @cf, defined $conf->{'customFunctions'} + ? map( { + my $f = $_; + $f =~ s/\w+:://g; + $f, $_; + } split( /\s+/, $conf->{'customFunctions'}, 0 ) ) + : (); + foreach my $f (@cf) { + $s = "sub $f {1} $s"; + } + eval "$s $val"; return $@ ? ( 0, "__badExpression__: $@" ) : 1; }, 'type' => 'keyTextContainer' @@ -1121,7 +1175,25 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0- 'default' => {}, 'keyTest' => qr/^[_a-zA-Z][a-zA-Z0-9_]*$/, 'test' => sub { - my $s = eval $_[0]; + my ( $val, $conf ) = @_; + my $s = ''; + my (@cf) = ( + 'encode_base64', 'checkLogonHours', + 'date', 'checkDate', + 'basic', 'unicode2iso', + 'iso2unicode', 'groupMatch' + ); + push @cf, defined $conf->{'customFunctions'} + ? map( { + my $f = $_; + $f =~ s/\w+:://g; + $f, $_; + } split( /\s+/, $conf->{'customFunctions'}, 0 ) ) + : (); + foreach my $f (@cf) { + $s = "sub $f {1} $s"; + } + eval "$s $val"; return $@ ? ( 0, "__badExpression__: $@" ) : 1; }, 'type' => 'keyTextContainer' @@ -1718,7 +1790,25 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0- }, 'portalSkinRules' => { 'keyTest' => sub { - my $s = eval $_[0]; + my ( $val, $conf ) = @_; + my $s = ''; + my (@cf) = ( + 'encode_base64', 'checkLogonHours', + 'date', 'checkDate', + 'basic', 'unicode2iso', + 'iso2unicode', 'groupMatch' + ); + push @cf, defined $conf->{'customFunctions'} + ? map( { + my $f = $_; + $f =~ s/\w+:://g; + $f, $_; + } split( /\s+/, $conf->{'customFunctions'}, 0 ) ) + : (); + foreach my $f (@cf) { + $s = "sub $f {1} $s"; + } + eval "$s $val"; return $@ ? ( 0, "__badExpression__: $@" ) : 1; }, 'msgFail' => '__badValue__', diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm index 2b69d045e..9490f7562 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm @@ -11,7 +11,19 @@ use strict; use Regexp::Common qw/URI/; my $perlExpr = sub { - my $s = eval $_[0]; + my ( $val, $conf ) = @_; + my $s = ''; + my @cf = + qw(encode_base64 checkLogonHours date checkDate basic unicode2iso iso2unicode groupMatch); + push @cf, + defined $conf->{customFunctions} + ? map { my $f = $_; $f =~ s/\w+:://g; ( $f, $_ ) } + split( /\s+/, $conf->{customFunctions} ) + : (); + foreach my $f (@cf) { + $s = "sub $f {1} $s"; + } + eval "$s $val"; return $@ ? ( 0, "__badExpression__: $@" ) : (1); };