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?”

[/problem]

[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.

Perl LDAP to SQL – Traverses LDAP trees and spits out SQL:
Now on github

Please leave a comment if you want help with this.

[/solution]

If you have found my website useful, please consider buying me a coffee below 😉

6 Replies to “LDAP to SQL Perl code”

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

  2. 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.

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

    For example:

    ldapsearch …. ‘objectclass=*’ userPassword sambaLMPassword

  4. 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 ?

  5. 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 *