Skip to content

Commit

Permalink
FilterMatch.pm: support matching rules for extensibleMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
marschap committed Nov 11, 2012
1 parent 37c702c commit 107b462
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion lib/Net/LDAP/FilterMatch.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use strict;
use Net::LDAP::Filter; use Net::LDAP::Filter;
use Net::LDAP::Schema; use Net::LDAP::Schema;


our $VERSION = '0.21'; our $VERSION = '0.22';


sub import { sub import {
shift; shift;
Expand All @@ -25,6 +25,8 @@ sub import {


package Net::LDAP::Filter; package Net::LDAP::Filter;


use Net::LDAP::Util qw(ldap_explode_dn);

our @approxMatchers = qw( our @approxMatchers = qw(
String::Approx String::Approx
Text::Metaphone Text::Metaphone
Expand Down Expand Up @@ -189,6 +191,57 @@ sub _filterMatch($@)


return eval( "$match".'($assertion,$op,@values)' ) ; return eval( "$match".'($assertion,$op,@values)' ) ;
} }
elsif ($op eq 'extensibleMatch') {
my @attrs = $args->{type} ? ( $args->{type} ) : ();
my $assertion = $args->{matchValue};
my $match;
my @values;

if ($schema) {
my $mr;

# get matchingrule from schema, be sure that matching subs exist for every MR in your schema
if (defined($args->{matchingRule})) {
my $mrhref = $schema->matchingrule($args->{matchingRule});
$mr = $mrhref->{name} if ($mrhref);
# if no attribute was given, get all attribute this matching rule applies to
if (!@attrs) {
my $mruhref = $schema->matchingruleuse($args->{matchingRule});
return undef if (!$mruhref);
@attrs = @{$mruhref->{applies}};
}
}
else {
return undef if (!@attrs);
$mr = $schema->matchingrule_for_attribute($attrs[0], 'equality');
}

return undef if (!$mr);
$match = '_'.$mr;
}
else {
# fall back on build-in logic
$match = '_cis_equalityMatch';
}

if ($args->{dnAttributes}) {
# get matching attributes' values from DN
my $exploded = ldap_explode_dn($entry->dn, casefold => 'lower');
my %dnattrs;
return undef if (!$exploded);
foreach my $elem (@{$exploded}) {
map { push(@{$dnattrs{$_}}, $elem->{$_}) } keys(%{$elem});
}
@values = map { ($dnattrs{$_}) ? @{$dnattrs{$_}} : () } (@attrs) ? @attrs : keys(%dnattrs);
}
else {
# regular case: get matching attributes' values
return undef if (!@attrs);
@values = map { $entry->get_value($_); } @attrs;
}

return eval( "$match".'($assertion,$op,@values)' ) ;
}


return undef; # all other filters => fail with error return undef; # all other filters => fail with error
} }
Expand Down

0 comments on commit 107b462

Please sign in to comment.