in reply to Re: Using Perl LDAP
in thread Using Perl LDAP

thanks for that, but i'm still having trouble using it:
#! /usr/bin/perl sub DN () { 'cn=admin,dc=foo,dc=com' } sub PASSWORD () { 'mypass' } sub SERVER () { 'localhost' } use Carp; use Net::LDAP; # Create connection to the LDAP server and bind authoratively using # administrator credentials my $ldap = Net::LDAP->new( SERVER ); unless ( defined $ldap ) { croak( 'Cannot create connection to LDAP server -- ', $! ); } $ldap->bind ( 'dn' => DN, 'password' => PASSWORD ); my $result = $ldap->add ( 'cn=foo,ou=v_domains,ou=postfix,ou=system_services,dc=foo,dc=com', 'attr' => [ 'cn' => 'foo', 'objectClass' => 'inetLocalMailRecipient', 'mailLocalAddress' => 'test001@foo.com, xmbox.com', 'mailRoutingAddress' => 'foo' ] ); $ldap->unbind;

Replies are listed 'Best First'.
Re: Re: Re: Using Perl LDAP
by Cmdr_Tofu (Scribe) on Jul 18, 2003 at 10:10 UTC
    Hey, I've started to work with LDAP in the last few months, and have been banging my head on problems like this for a while now. One tool I found amazingly useful (which helped me write my Net::LDAP code) was the Java LDAP browser. (http://www.iit.edu/~gawojar/ldap/) That may help you debug your queries.

    The book _LDAP_System_Administration_ is also quite useful (as much as perldoc Net::LDAP) and has become a part of my Safari bookshelf.

    Also, please add some errorchecking (you can do this on the bind too):
    die $result->error if $result->code;
    Maybe that will help debugging it? I also like the following shell command:
    ldapadd -x -D cn=mycn -w mypassword < myldiffile.ldif
    Good luck!

    Rohit
Re: Re: Re: Using Perl LDAP
by Excalibor (Pilgrim) on Jul 18, 2003 at 09:46 UTC

    Hi there,

    I've been using Net::LDAP intensively and extensively for the last year in a project that makes heavy use of the LDAP Directory Server.

    The code above looks good to me.

    Sometimes it's easier to make a search of the user you want to work on, this way you get an Entry object pointing to hir, and there are many things that are more easily done with an entry than with the whole LDAP object (even a kind of transactional nature on your addings/updatings...)

    Good luck,

    --
    our $Perl6 is Fantastic;

Re: Re: Re: Using Perl LDAP
by blue_cowdawg (Monsignor) on Jul 18, 2003 at 10:11 UTC

    thanks for that, but i'm still having trouble using it:

    Can you be more specific? What sorts of errors are you seeing? What kind of results or lack thereof are you seeing?

    I use Net::LDAP and its friend Net::LDAPS all the time with great success. I even do evil things like populate Active Directory <shudder!> from an Oracle database


    Peter L. BergholdBrewer of Belgian Ales
    Peter@Berghold.Netwww.berghold.net
    Unix Professional
      Hi There, I am not seeing the data get entered when i run the above.

          I am not seeing the data get entered when i run the above.

        • What sorts of errors are you getting back from LDAP? I hope you are catching errors...
        • What means are you using to verify your results (or in this case lack thereof)?
        Two words: problem definition.


        Peter L. BergholdBrewer of Belgian Ales
        Peter@Berghold.Netwww.berghold.net
        Unix Professional
Re: Re: Re: Using Perl LDAP
by hiddenlinux (Acolyte) on Jul 18, 2003 at 12:04 UTC
    Its saying that the entry already exists. Even tho, when i use LDAP Browser, i cannot see the entry in there.
      this is how a successfull entry is listed in my db:
      dn: cn=test1,cn=foo.com,ou=v_domains,ou=postfix,ou=system_services, dc +=foo,dc=com mailRoutingAddress: test1 objectClass: inetLocalMailRecipient mailLocalAddress: test1@foo.com