LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-24-2006, 09:53 AM   #1
jonlake
Member
 
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Rep: Reputation: 31
perl and net::ldap how to return dn from a search


It seems like this should be so obvious that I'm looking right past it. What I'm trying to do is have a user enter their uid and password, and then bind to the directory server as themself. However, if I do a search for that person
Code:
my $ldap = Net::LDAP->new( '127.0.0.1:4389') or die "$@";
my $base = "ou=people,dc=usfccorp,dc=com";
my $filter = "(&(objectclass=usfperson)(uid=$user))";
$ldap ->bind;
my $user_search = $ldap->search( base=> $base,
                                 filter=> $filter,
);
and then try to get the dn (since nothing is returned, I'm guessing this is something that net::ldap doesn't return)
Code:
foreach my $entry ($user_search->entries) {
  my $userdn = $entry->get_value('dn');
  print "$userdn \n";
}
$ldap->unbind;
I have looked at the cpan pages and done some google searching and haven't found what I'm looking for. It seems to me that this should be so obvious that I'm looking right past it.
 
Old 02-24-2006, 12:02 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

Shouldn't this:

$ldap ->bind;

be something like this:

$ldap ->bind (dn=>$User, password=>$Passwd);

The reason why you don't get anything back ([login]error) is still unclear to me, but it also happens when using SUN's ldap (I'm guessing you are using openLDAP).

Hope this helps.

Last edited by druuna; 02-24-2006 at 12:06 PM.
 
Old 02-24-2006, 12:46 PM   #3
jonlake
Member
 
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Original Poster
Rep: Reputation: 31
Ok, I figured it out. I knew it was something obvious I was missing. The attribute name I needed was entrydn. I had to request it when doing the search. The code should look like this.

Code:
#!/usr/bin/perl

use Net::LDAP;
use strict;

#initialize variables
my $entry;
my @uids;
my $number;
my @sorted;


my $ldap = Net::LDAP->new('10.128.12.48:4389') or die "$@";
$ldap-> bind;

my $root = "dc=usfccorp,dc=com";
my $mesg = $ldap->search( base => $root,
             filter => '(uid=jlake)',
             attrs => ['*','entrydn'], # this is where I had to request to return the entrydn
             );
$mesg->code && die $mesg->error;

foreach $entry ($mesg->entries) {
        my $tmpnum = $entry->get_value('entrydn');
        @uids = (@uids,$tmpnum);
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perl ignore return codes twistedpair Programming 5 02-14-2006 04:54 PM
Do Perl functions usually modify variables, or return modified copies? Why? johnMG Programming 3 02-06-2005 10:22 PM
LDAP bind instead of search request corbis_demon Linux - Newbie 0 07-02-2004 11:35 AM
perl-ldap package for redhat 7.3 mayankjohri Linux - Distributions 0 11-20-2002 03:15 AM
unescaping a carriage return in perl acid_kewpie Programming 10 09-20-2002 02:20 PM


All times are GMT -5. The time now is 07:42 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration