LDAP to SQL Perl code

Problem

Whilst working on the automatic production of web statistics – came across the following problem:

“How do I get relational data from an Hierarchical structure?”



Solution

It didn’t take long to realize – I’d have to use PHP to talk to LDAP, pull off records & upload into a series of tables, using the cn as primary key. Which then could be queried relationally. Pulling off large, queries and repeatedly transcending LDAP trees is pretty slow – so I built my LDAP to SQL engine, by flattening dns into table names. Then used PHP scripts to query produce
daily snap shots.

This is the Perl port of the PHP version. Requires some setting up on db side, but invaluable once implemented.

Please leave a comment if you want help with this.



Example


Perl LDAP to SQL
[freeware]

UNIX

Traverses LDAP trees and spits out SQL.


Windows



Reference

[tags]LDAP, SQL, Perl, PHP[/tags]



Next Post

Comments (6)

  1. Mac

    Hi there ! very nice blog, it would be possible to get your php source of LDAP to SQL ??? thanks a lot.

  2. Hi Mac,

    Try this (one of my old sites) http://goldenfeather.darlingranges.com/ldap/php/ and let me know how you go.

    Cheers,

    Mark

  3. Mac

    Thanks a lot for your source code !
    I tried it for my usage, it work fine but i have a question on some attributs which don’t seems to be read …

    attributs like userPassword, homePostalAddress, sambaLMPassword … i think it’s about ACL but i do ldap searches with an admin account ….

    Maybe an idea ? thanks.

    Mac.

  4. Some attributes are specifically hidden, such as userPassword. If you specifically request them, ldapsearch will return them.

    For example:

    ldapsearch …. ‘objectclass=*’ userPassword sambaLMPassword

  5. Mac

    i do this but it still doesn’t work …

    i tryed on the console : ldapsearch -x -D “cn=admin,dc=xxxx,dc=fr” -w “xxxxx” -b”ou=people,dc=xxxx,dc=fr” ‘(objectclass=person)’

    this line work fine … but when i do it in PHP … still can’t see userPassword …

    $dn = “ou=people,dc=xxxx,dc=fr”;
    $filter=”(objectClass=person)”;
    $sr=ldap_search($ldapconn, $dn, $filter);

    for ($i=0; $i”;}

    for this i got the good one (all the objectClass) but can’t see userPassword or other things …

    i verified ACL in slapd.conf it look ok for admin, read / write access …

    no idea for how to do it rigth, for your line ldapsearch …. ‘objectclass=*’ userPassword sambaLMPassword ===> $filter=”(objectClass=*)”; where do you specify userPassword ?

  6. Mac

    It’s ok for UserPassword, it was about ACL …
    but now i got a problem on reading “structuralObjectClass”
    i can read it with LDAP Browser on Windows, but nothing with php or in console mode … i bind with admin account so i don’t see how to do …

Leave a Reply

Your email address will not be published. Required fields are marked *