how to return dn from a search in perl and net::ldap?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • santhanalakshmi
    New Member
    • May 2009
    • 147

    how to return dn from a search in perl and net::ldap?

    hi,

    Please see my code as given below:
    Code:
    #!c:/perl/bin/perl
    use strict;
    use warnings;
    use CGI qw(:all);    #use for all code
    use Net::LDAP;
    use Net::LDAP::Util qw(ldap_error_name
                           ldap_error_text); #use for Error Handling
    print "Content-type: text/html\n\n";
    print "<body bgcolor=\"#ffcccc\">";
    
    
    my $entry;
    my @uids;
    
    my $serverlogin='administrator';
    my $serverpassword='xxxxx';
    my $LDAP_SERVER="localhost";
    my $LDAP_PORT="389";
    
    my $LDAP_BASE="ou=student,dc=ac,dc=in";
    
    #INITIALIZING
    my $ldap=Net::LDAP->new($LDAP_SERVER,port=>$LDAP_PORT) or die "Unable to connect to LDAP server $LDAP_SERVER: $@\n";
    
    
    
    
    #BINDING
    
    my $studentlogin='CE34';
    my $studentpassword='c6';
    
    my $binddn = "uid=$studentlogin, ou=student, dc=ac,dc=in";
    my $result = $ldap->bind(uid => $binddn, password => $studentpassword,version=>3);
    die $result ->error() if $result ->code();
    
    my $mesg= $ldap->search(filter=>"(&(uid=$studentlogin)(objectClass=student))", 
                            base=>$LDAP_BASE);
    
    
    if ($mesg->count()>0)
    {
        print $mesg->count(),"entries returned.\n";
        foreach $entry($mesg->all_entries())
        {
             $entry->dump();
        }
    }
    print "</body>";
    print "</html>";

    and then try to get the dn (since nothing is returned, I'm guessing this is something that net::ldap doesn't return). My ldap search() is not returning any results. I don't know, whether my program is correct or not. Please help me out.Thanks in advance
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Bear with me as I have never played with this module, but in the example from the CPAN module page, it shows the "base=>" before the "filter=>". When specifying parameters there are a lot of functions that have specific order. Have you tried reversing these?

    Regards,

    Jeff

    Comment

    • santhanalakshmi
      New Member
      • May 2009
      • 147

      #3
      yes, i have tried the same one. what you have told me? Please check my coding, i don't know, what mistake did i made? Please check my BINDING?

      What is meant by an anonymous bind? In my code, i am not using an anonymous bind
      ?

      What is the 'cn', the 'uid' and the 'dn'? What we should use in binding? In my below coding, i have used 'uid'(It means, the students loginname getting from the textbox)
      What is the purpose of 'cn'? How can i check my binding its correct or not ?

      Code:
      my $binddn = "uid=$studentlogin, ou=student, dc=ac,dc=in";
      my $result = $ldap->bind(uid => $binddn, password => $studentpassword,version=>3);
      die $result ->error() if $result ->code();
      Last edited by Niheel; Mar 14 '11, 02:10 PM.

      Comment

      Working...