insaniac has asked for the wisdom of the Perl Monks concerning the following question:

hi fellas and felines,

I've got the weirdest situation problem. Last week, I've started playing with DBD::LDAP together with Class::DBI. Well, I want to use DBD::LDAP as datasource for Class::DBI because I was creating a web based LDAP browser. I'm using the Class::DBI since I was too lazy to create all the search and search_like subs.

So, OKAY, all goes perfect and smoothly and jiggy when I query a OpenLDAP server. It even works very fast!
But here it comes: when I try to query a Netscape LDAP server (that's the one their using at my work), it returns very weird stuff.

Some more information. I'm building the webpages with Template. I can see when I use the retrieve() method of Class::DBI that it retrieves that uid I've asked for

eval { $vars->{user} = MVG::User->retrieve( %data ) ; }; # %data contains keys/values from q->params # MVG::User isa class with Class::DBI as base # $vars->{user} is the var I'm passing to Template

This works! The object passed to the template looks like this (in Dumper):
$VAR1 = bless( { 'uid' => 'someuid' }, 'MVG::User' );
So, in both cases (OpenLDAP, Netscape LDAP), this goes perfect.

Now here it comes: in the template I do stuff like this:

[% FOREACH method IN user.columns.sort -%] <tr> <th> [% method -%]: </th> [%- IF method == "mail"-%] <td> <a href="mailto:[% user.$method || "&nbsp;" -%]"> +[% user.$method || "&nbsp;" -%] </td> [%- ELSE -%] <td> [% user.$method || "&nbsp;" -%] </td> [%- END -%] </tr> [%- END -%]
Like I said before, the template code works perfect for OpenLDAP, for Netscape LDAP wicked stuff happens!
Lemme elaborate:

I've been testing and testing for about 4 days now.. and I haven't got a clue what's wrong!

Oh yeah: you need to patch/hack the DBD::LDAP (mostly JLdap.pm) a little bit before it works nicely with Class::DBI.. a lot of the match and substitute actions need an extra i (case insensitive) at the end ;-) I've mailed the author about this, but he's not reacting on my mails..

So.. if someone can think of some more test I can do, maybe some experiences he had about this... ANYTHING is welcome! I just don't understand why the code works perfect on a OpenLDAP server, and it doesn't on Netscape (well, it does according to Ethereal..).

Sorry for the very long post... but i needed to talk to someone.
Many thanks in advance for bearing with me..

to ask a question is a moment of shame
to remain ignorant is a lifelong shame

Replies are listed 'Best First'.
Re: DBD::LDAP and Class::DBI situation
by g0n (Priest) on Apr 07, 2005 at 14:29 UTC
    Possibly this will not help you a great deal, but I strongly, strongly recommend you use Net::LDAP. It is very well documented and supported, very widely used, and has an active mailing list on which the author is a regular contributor.

    Failing that, its notable that the UID is the only attribute in your list that is defined as single valued. Check that you aren't being fed an array/arrayref with a single value in it, rather than a single scalar.

    Update: Whoops, no, there are a few single valued attribs there.

    g0n, backpropagated monk
      uhm.. DBD::LDAP uses Net::LDAP for retrieving/inserting/.. the information. And when I examine these values (in the DBD::LDAP code), I can see it fetches the data correctly.

      I just wanted to use the Class::DBI interface..

      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame

        It occurs to me that IIRC UID is the default naming attribute of inetOrgPerson objects in Netscape. You could try creating an object named with a cn rather than a UID to see if theres an undocumented assumption there.

        g0n, backpropagated monk
Re: DBD::LDAP and Class::DBI situation
by perrin (Chancellor) on Apr 07, 2005 at 16:33 UTC
    Two ideas. First, try setting $Class::DBI::Weaken_Is_Available = 0 after loading Class::DBI. Second, is there more than one object with the same UID? Class::DBI will not handle that. You must have truly unique IDs to use Class::DBI.
      okay thanks, i will have to try that tomorrow, i'm not at work anymore.

      but to answer your second question:

    • if there's more than one object, they all have unique UID (cuz those are unix logins)
    • it also doesn't work if there's only one object

      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame

      Hi,
      so the Weaken_Is_Available does not change a thing, sadly enough. Thanks anyway ;-)

      Today I've read (in O'reilly's Perl Template Toolkit) about how to debug the Template::Parser and Template::Stash, so maybe I'll discover some more..

      Thanks anyhow..

      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame

Re: DBD::LDAP and Class::DBI situation
by insaniac (Friar) on Apr 07, 2005 at 15:03 UTC
    I'll add some logging.. to make it easier maybe:

    When the template above gets executed, this happens in DBD::LDAP:

    sql_string: SELECT objectclass, cn, mobile, departement, postaladdress +, mail, ou, telephonenumber, name, description, givenname, employeenu +mber, sn, title, dn, roomnumber FROM users WHERE uid='verhamma' ref @resv: iter0 - found: [12] iter1 -- found: [top; person; organizationalPerson; inetOrgPerson; mailRecip +ient; linpersonlolita; gatewayCcMailUser; gatewayMSMailUser; gatewayP +erson; mvgperson; nsCalUser; posixaccount; shadowaccount; inetmailuse +r; inetlocalmailrecipient] -- found: [VERHAMME, Marc] -- found: [] -- found: [LIN] -- found: [some postal address] -- found: [some emailaddress] -- found: [LIN] -- found: [] -- found: [] -- found: [] -- found: [Marc] -- found: [17258] -- found: [VERHAMME] -- found: [] -- found: [cn="VERHAMME, Marc",ou=Personeel,ou=LIN,o=Vlaanderen,c=BE] -- found: [ ]
    So.. the data arrived in the module!

    The following is a Dumper.dump of the user variable in the Template code (which is above):

    $VAR1 = bless( { 'objectclass' => undef, 'cn' => undef, 'mobile' => undef, 'departement' => undef, 'postaladdress' => undef, 'mail' => undef, 'ou' => undef, 'uid' => 'verhamma', 'telephonenumber' => undef, 'name' => undef, 'description' => undef, 'givenname' => undef, 'employeenumber' => undef, 'sn' => undef, 'title' => undef, 'dn' => undef, 'roomnumber' => undef }, 'MVG::User' );
    So why are the values there in the module but eventually not in the object? :-/ it just blows my socks

    so it seems the template variable I use (in the template it's user) does not get "updated" (this probably not the correct word)

    thanks..

    to ask a question is a moment of shame
    to remain ignorant is a lifelong shame

Re: DBD::LDAP and Class::DBI situation
by insaniac (Friar) on Apr 07, 2005 at 18:11 UTC
    okay.. i've added some of the code in my scratchpad, if someone's interested. (insaniac's scratchpad)

    to ask a question is a moment of shame
    to remain ignorant is a lifelong shame