Skip Menu |

This queue is for tickets about the Net-LDAP-SimpleServer CPAN distribution.

Report information
The Basics
Id: 101365
Status: resolved
Priority: 0/
Queue: Net-LDAP-SimpleServer

People
Owner: RUSSOZ [...] cpan.org
Requestors: ipuleston [...] sonicwall
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.0.17
Fixed in: 0.0.19



Subject: Add support for baseObject DN and scope in searches
This module would be a lot more useful if it supported the baseObject DN and scope in a search request, especially for using it as a back-end server for testing LDAP clients against. These fields are present in the request passed from Net::LDAP::Server to the search() function, but it currently ignores them and applies the search filter to the entire content of the data store. This is really an enhancement request, but it could be argued that the baseObject and scope are inherent parts of the search request and so ignoring them as it does now could be seen as a bug. Adding support for these in the search() function is not difficult and I have attached a simple patch that makes the necessary additions.
Subject: add-srch-scope.patch
diff -Naur Net-LDAP-SimpleServer-0.0.17-1/lib/Net/LDAP/SimpleServer/ProtocolHandler.pm Net-LDAP-SimpleServer-0.0.17/lib/Net/LDAP/SimpleServer/ProtocolHandler.pm --- Net-LDAP-SimpleServer-0.0.17-1/lib/Net/LDAP/SimpleServer/ProtocolHandler.pm 2015-01-06 18:04:15.349728581 -0800 +++ Net-LDAP-SimpleServer-0.0.17/lib/Net/LDAP/SimpleServer/ProtocolHandler.pm 2015-01-06 18:02:11.966306605 -0800 @@ -118,17 +118,55 @@ return [ grep { $f->match($_) } @{$elems} ]; } +sub _in_scope { + my ($dn, $basedn, $scope) = @_; + + my $in_scope = 0; + if ($scope eq 'baseObj') { + $in_scope = ($dn eq $basedn); + } elsif ($scope eq 'oneLevel') { + if ($dn =~ m/([^,]*),(.*)$/) { + my $locn = $2; + $in_scope = ($locn eq $basedn); + } + } + elsif ($scope eq 'subTree') { + my $tail_len = length($basedn) * -1; + $in_scope = (substr($dn, $tail_len) eq $basedn); + } + + return $in_scope; +} + +sub _elem_in_scope { + my ($elem, $uc_basedn, $scope) = @_; + + return _in_scope(uc($elem->{asn}->{'objectName'}), $uc_basedn, $scope); +} + sub search { my ( $self, $request ) = @_; my $list = $self->{store}->list; - #my $basedn = $request->{baseObject}; + my @scopes = qw(baseObj oneLevel subTree); + + my $basedn = $request->{baseObject}; + my $scope = $scopes[ (defined $request->{scope} && $request->{scope} <= 2) ? $request->{scope} : 2 ]; #print STDERR '=' x 50 . "\n"; #print STDERR Dumper($request); #print STDERR Dumper($list); + if (defined($basedn)) + { + my $uc_basedn = uc($basedn); + my @sublist = grep { _elem_in_scope($_, $uc_basedn, $scope) } @{$list}; + + #print STDERR Dumper(@sublist); + $list = [ @sublist ]; + } + my $res = _match( $request->{filter}, $list ); #print STDERR Dumper($res); @@ -190,6 +228,9 @@ Performs a search in the data store. +The search filter, baseObject and scope are supported, with other search fields +currently being ignored. + =head1 SEE ALSO Please see those modules/websites for more information related to this module.
Subject: [rt.cpan.org #101365]
Date: Wed, 7 Jan 2015 10:31:52 -0800
To: Bugs in Net-LDAP-SimpleServer via RT <bug-Net-LDAP-SimpleServer [...] rt.cpan.org>
From: Ian Puleston <ipuleston [...] SonicWALL.com>
I forgot to say, to apply the patch during installation, after unpacking Net-LDAP-SimpleServer-0.0.17.tar.gz, cd into the Net-LDAP-SimpleServer-0.0.17 directory and type 'patch -p1 <path-to-it>/add-srch-scope.patch'. Then continue the install as normal.
Subject: RE: [rt.cpan.org #101365]
Date: Wed, 7 Jan 2015 11:38:03 -0800
To: Bugs in Net-LDAP-SimpleServer via RT <bug-Net-LDAP-SimpleServer [...] rt.cpan.org>
From: Ian Puleston <ipuleston [...] SonicWALL.com>
Correction, that should say 'patch -p1 <path-to-it/add-srch-scope.patch'.
Fixed in v0.0.19