Add extended functions in locationRules test (may close #924)

This commit is contained in:
Xavier Guimard 2016-02-09 22:17:42 +00:00
parent 2dc1750ce7
commit ae7febe69d
2 changed files with 31 additions and 15 deletions

View File

@ -1082,15 +1082,23 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-
my ( $val, $conf ) = @_; my ( $val, $conf ) = @_;
my $s = $val; my $s = $val;
$s =~ s/\b(accept|deny)\b/1/g; $s =~ s/\b(accept|deny)\b/1/g;
if ( $conf->{'customFunctions'} ) {
foreach my $f ( foreach my $f (
split( /\s+/, $conf->{'customFunctions'}, 0 ) ) split(
/\s+/,
(
defined $conf->{'customFunctions'}
? "$conf->{'customFunctions'} "
: ''
)
. 'checkLogonHours date checkDate basic unicode2iso iso2unicode groupMatch',
0
)
)
{ {
return 0, "__badCustomFuncName__ $f" return 0, "__badCustomFuncName__ $f"
unless $f =~ /^\w+$/; unless $f =~ /^[a-zA-Z]\w*$/;
$s = "sub $f {1} $s"; $s = "sub $f {1} $s";
} }
}
eval $s; eval $s;
return $@ ? ( 0, "__badExpression__: $@" ) : 1; return $@ ? ( 0, "__badExpression__: $@" ) : 1;
} }

View File

@ -884,14 +884,22 @@ sub attributes {
my ( $val, $conf ) = @_; my ( $val, $conf ) = @_;
my $s = $val; my $s = $val;
$s =~ s/\b(accept|deny)\b/1/g; $s =~ s/\b(accept|deny)\b/1/g;
if ( $conf->{customFunctions} ) { foreach my $f (
foreach my $f ( split /\s+/, $conf->{customFunctions} ) split(
/\s+/,
(
defined $conf->{customFunctions}
? "$conf->{customFunctions} "
: ''
)
. 'checkLogonHours date checkDate basic unicode2iso iso2unicode groupMatch',
)
)
{ {
return ( 0, "__badCustomFuncName__ $f" ) return ( 0, "__badCustomFuncName__ $f" )
unless ( $f =~ /^\w+$/ ); unless ( $f =~ /^[a-zA-Z]\w*$/ );
$s = "sub $f {1} $s"; $s = "sub $f {1} $s";
} }
}
eval $s; eval $s;
return $@ ? ( 0, "__badExpression__: $@" ) : (1); return $@ ? ( 0, "__badExpression__: $@" ) : (1);
}, },