Hi list, could someone help me in understanding what the SampleLDAP.pm perl module do in its search routine?
This is the code: -------- sub search { my $this = shift; my ( $base, $scope, $deref, $sizeLim, $timeLim, $filterStr, $attrOnly, @attrs ) = @_; print {*STDERR} "====$filterStr====\n"; $filterStr =~ s/(|)//gm; $filterStr =~ s/=/: /m;
my @match_dn = (); for my $dn ( *keys %{$this}* ) { if ( $this->{$dn} =~ /$filterStr/imx ) { push @match_dn, $dn; last if ( scalar @match_dn == $sizeLim );
} }
my @match_entries = ();
for my $dn (@match_dn) { push @match_entries, $this->{$dn}; }
return ( 0, @match_entries );
} --------
I'm interested in knowing what "keys %{$this}" should contain and why, in trying to use this sample perl module I cannot see any "key" of the array variable $this.
I configured the database in this way:
database perl suffix "dc=perl,dc=com" perlModulePath /tmp/appoggio/ perlModule SampleLDAP
Thanks in advance Marco
Marco Pizzoli writes:
sub search { my $this = shift; (...) for my $dn ( *keys %{$this}* ) { (...)
I'm interested in knowing what "keys %{$this}" should contain and why, in trying to use this sample perl module I cannot see any "key" of the array variable $this.
$this should be the return value from sub new. It's a blessed reference to a hash table, thus %{$this} (or just %$this) is the hash table.
That said, get latest version or the one in OpenLDAP 2.3. SampleLDAP.pm was buggy in OpenLDAP 2.4.<up to 23>.
Hi Hallward, thanks for the answer.
I saw that you made a correction to the comment included in the source. But forgive me, I continue to not understand.
In the comment you wrote: <quote> # This demo module keeps an in-memory hash {"DN" => "LDIF entry", ...} </quote>
How could I populate manually (in the Perl code) those entries?
In this way? $this { "uid=pippo,dc=ciao,dc=it" => "objectClass: uidObject\nuid: pippo" }
I'm not able to extract my entry....
--------------------
I tried to use the add operation. slapd told me that I had to do a bind to do that operation:
<quote> [root@Fedora14 overlays]# ldapadd -x -h 127.0.0.1 -p 389 dn: uid=marco,dc=perl,dc=com objectClass: top objectClass: uidObject uid: marco
adding new entry "uid=marco,dc=perl,dc=com" ldap_add: Strong(er) authentication required (8) additional info: modifications require authentication </quote>
So I need to do a bind. Is it correct that bind() function is not documented on "man slapd-perl" ? I tried to define a bind() function in the SampleLDAP.pm module and it went over that step.
Problem I was having was that the connection(?) was not released... I had my prompt hung waiting...
I started my slapd in debug mode and saw that "operation" seemed to be done...
It was my fault or I found another bug?
Thanks again! Marco
On Fri, Mar 18, 2011 at 2:49 PM, Hallvard B Furuseth < h.b.furuseth@usit.uio.no> wrote:
I wrote:
$this should be the return value from sub new. It's a blessed reference to a hash table, thus %{$this} (or just %$this) is the hash table.
Oops, I lost the final sentence:
%$this is a {dn: entry} hash, filled in by sub add & co.
-- Hallvard
Marco Pizzoli writes:
(...) How could I populate manually (in the Perl code) those entries?
In this way?
In sub new:
$this { "uid=pippo,dc=ciao,dc=it" => "objectClass: uidObject\nuid: pippo" }
I think like this, but I have not tried:
my $dn = "uid=pippo,dc=ciao,dc=it" my $this ={ $dn => "dn: $dn\nobjectClass: uidObject\nuid: pippo\n" };
I'm not able to extract my entry....
I tried to use the add operation. slapd told me that I had to do a bind to do that operation:
So you do. You could e.g. set the database's rootdn and rootpw so you have something to bind as.
openldap-technical@openldap.org