LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-26-2006, 10:14 AM   #1
Registered: Aug 2003
Location: Romania
Distribution: Solaris 10
Posts: 78

Rep: Reputation: 15
perl + ldap + userPassword hash

hello all

i might need some help with the LDAP perl modules/libraries
im trying to get (remotely) the users password hash from an LDAP server where the password is encrypted. I need this to be able to copy the users information and his hash to my local LDAP server.
I did not figured out how i can do this
i was trying to get some information about the users with
but i dont see any argument that would give me the users password hash
maybe NET::LDAP can do the trick

the thing is like this locally when i exec the command
ldapsearch -D "cn=directory manager" -w secretpass -b "ou=people,dc=home,dc=com" uid=*

i get the list of users with that field named userPassword
dn: uid=wagner,ou=People,dc=home,dc=com
loginShell: /bin/ksh
gidNumber: 1001
objectClass: top
objectClass: account
objectClass: person
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: posixAccount
objectClass: shadowaccount
homeDirectory: /home/*****
cn: ****
givenName: ****
uidNumber: *****
gecos: *****
sn: *****
uid: ****
userPassword: {SSHA}oEx4GlxT+q16S/D3TGZAK50mdMhwZlBGtgiTEw==
im interested how i can get this fields userPassword value with some Perl libraries/functions not with ldapsearch

Last edited by ANU; 10-31-2006 at 04:12 AM.
Old 10-26-2006, 11:49 AM   #2
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381

You can indeed use Net::LDAP.

Basically you need to set up the connections first, something like this:
# ------------------------------------------------------------------ #
# - connectToLdap - Open a connection to ldap instance
# ------------------------------------------------------------------ #
sub connectToLdap {
  # connect to instance
  $ldapConn = Net::LDAP->new ($confValues{localAdminIP},
  # ooops
  die "Can't connect to $instanceName" unless $ldapConn;

  # bind with credentials
  $ldapConn->bind (dn=>$confValues{ldapBindDn},
Then you can do your searches/modifications.
A search example:
# ------------------------------------------------------------------ #
# - Search - Search connection tree for given attribute
# ------------------------------------------------------------------ #
sub conTreeSearch {
  # search db
  $ctsResult = $ldapConn->search (base   => "$confValues{ldapBase}",
                                  scope  => "sub",
                                  filter => "(attribute=$_)",
                                  attrs  => ["otherattribute"]);
  $ctEntry = $ctsResult->entry(0);
And finally you close the connection again:
 # close session
As you probably noticed $confValues{<sometoken>} is filled with the actual entries .

Hope this helps.


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
Using hash value as key for other hash in Perl scuzzman Programming 6 02-14-2006 06:08 PM
Perl and Hash automatic PB0711 Programming 3 09-23-2005 03:14 AM
Perl: hash tying amnesty_puppy Programming 1 01-18-2005 12:03 AM
LDAP Authentication(UserPassword validation) joeyBig Linux - General 4 09-21-2004 06:50 PM
Hash-sort like in PERL in C++ nyk Programming 4 06-11-2004 09:40 AM

All times are GMT -5. The time now is 07:02 PM.

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