perlquestion
srinivas_rocks
Hi Perl Monks, <p>
I have been working with LDAP server configurations from some time and now I want to integrate the LDAP in my project. <p>
I want to use LDAP to authenticate the users when they login to my portal. <p>
I found <b>Net::LDAP </b> as a good perl module that can be used to serve my purpose. <p>
I was successful in executing search statements and here is the code <p>
<code>
#! /usr/bin/perl
use Net::LDAP;
$ldap = Net::LDAP->new ( "<ip address>" ) or die "Connection Failed $@";
$mesg = $ldap->bind ( "<user name>",
password => "<password>",
version => 3 );
$base = "dc=example,dc=com";
$mesg = $ldap->search ( # perform a search
base => $base,
filter => "(objectclass=*)"
);
$mesg->code && die $mesg->error;
foreach $entry ($mesg->all_entries) { $entry->dump; }
</code>
for the above code I got the following correct output:
<code>
------------------------------------------------------------------------
dn:dc=example,dc=com
dc: example
description: Root LDAP entry for example.com
objectClass: dcObject
organizationalUnit
ou: rootobject
------------------------------------------------------------------------
dn:ou=People,dc=example,dc=com
ou: People
description: All people in organisation
objectClass: organizationalUnit
------------------------------------------------------------------------
dn:uid=srinivas,ou=People,dc=example,dc=com
uid: srinivas
cn: srinivas
objectClass: account
posixAccount
top
shadowAccount
userPassword: {crypt}$1$zYwJ/asE$DsYRb6CXjzJihNyTV2lC9.
shadowLastChange: 13986
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 503
gidNumber: 100
homeDirectory: /home/srinivas
</code>
now when I am trying to execute compare function whose code is
<code>
$mesg = $ldap->compare( $base,
attr => "uid",
value => "srinivas"
);
$mesg->code && die $mesg->error;
foreach $entry ($mesg->all_entries) { $entry->dump; }
</code>
I am getting following error when I execute the above script
<code>
No such attribute at ldap_compare.pl line 34, <DATA> line 259.
</code>
Can any one suggest whether there are any additional attributed that are to be added or any other why that I can compare my username and password for authentication.
Any suggestion will be helpful.<p>
Thanks in Advance.<p>
Srinivas.