Using Net::LDAP perl Module

Hi All, this post is related to using Net::LDAP perl module to register, search and delete the users in OID (oracle internet directory). I have been struggling to get this perl code for me. Finally I was able to create a perl script for doing the same.

Initially I tried the same thing using ldapadd command (for adding users in OID). But this has some dependencies. Like for using ldapadd command you need AS10g Oracle home installed where you can reference to these commands. Even if AS10g home is not present you can still use the perl binaries for LDAP. But this again depends on our perl installation. Not all perl installation is having these binaries installed.

So best approach is to use Net::LDAP module for the same. Remember there is a URI::LDAP module also. But this cannot be used, we need Net::LDAP module. You can check if this module is present in your perl installation or not Possibly this should be present as a file in one of the location present in @INC). If the module is not present then you can install the same by following the below simple steps.

You can download the Net::LDAP perl module from CPAN

Instruction for install 

Unzip the module and run the following steps

  • perl Makefile.PL
  • make
  • make test
  • su root
  • make install

Once you install the module you can connect to LDAP server and add the user. Below is the perl script I have used for the same.

Perl script for using Net::LDAP 

#!/local/bin/perl -I /oracle/iAS/perl_modules/lib/perl5/site_perl/5.8.0
#use strict;
#use warnings;
use Net::LDAP;

$ldap = Net::LDAP->new("") or die "$@";
$mesg = $ldap->bind("cn=orcladmin", password=>"welcome1");

%mon = ("Jan","01","Feb","02","Mar","03","Apr","04","May","05","Jun","06","Jul","07","Aug","08","Sep","09","Oct","10","Nov","11","Dec","12");

my $gen_time= localtime();
my @TimeStamp = split(/ /, $gen_time);
my $TimeStamp=$TimeStamp[4].$mon{$TimeStamp[1]}.$TimeStamp[2]."000000z";

$arg = "$ARGV[$0]";


$mesg = $ldap->search(filter=>"(uid=$uid)", base=>"dc=ap6059rt,dc=us,dc=oracle,dc=com");
$mesg->count && $ldap->delete($dn);

$result = $ldap->add($dn, 
                attr => [ 'uid' => $uid,
                          'cn' => $cn,
                          'sn' => $sn,
                          'mail' => $mail,
                          'givenName' => $givenName,
                          'userpassword' => $userpassword,  
                          'orcltimezone' =>  $orcltimezone,      
                          'orclactivestartdate' => $TimeStamp,     
                          'orclisenabled' => $orclisenabled,            
                          'objectclass' => [ 'person', 'inetOrgPerson', 'organizationalperson', 'orcluser', 'orcluserv2', 'ctCalUser', 'orclUserProvStatus']
$result->code && warn "error: ", $result->error;


You need to just pass the username which you want to register in OID and this script will register the same.

/oracle/iAS/perl_modules/lib/perl5/site_perl/5.8.0 is the location where my Net::LDAP module is installed and I am including the same in my script as first line using -I option.

Hope this helps !!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s