I am writing a script (currently a command line utility, but it will be
a CGI in final form) where the user can change their password in an
LDAP directory. (The ultimate target is Novell's eDirectory, but for
development purposes I am using Netscape's directory server 4.16.) Here
is my code:
#!/usr/local/bin/perl
use warnings;
use strict;
use Mozilla::LDAP::Conn;
my $username = $ARGV[0];
my $currentUserPassword = $ARGV[1];
my $newpassword = $ARGV[2];
print "username = $username \n";
print "Password = $currentUserPassword \n";
print "new password = $newpassword\n";
my $baseDN = "o=jdnet";
my $AdminbindDN = "cn=admin,o=jdnet";
my $AdminbindDNpassword = "password";
my $LDAPServer = "seawolf";
my $LDAPPort = "389";
#first, do an anonymous bind to find the user's DN
print "Define anonymous connection.\n";
my $kent = new Mozilla::LDAP::Conn($LDAPServer,
$LDAPPort);
print "Starting search\n";
my $entry = $kent->search($baseDN, "sub", "(cn=$username)") or die
"Cannot search directory: $!";
print "Search done\n";
#my $userDN = $entry->{dn};
my $userDN = "";
if ((! $entry)) {
die "User not found: $!";
} else {
while ($entry) {
my $currentuserDN = $entry->{dn};
#print "currenentuserDN is $currentuserDN\n";
my @dn = split(/,/,$currentuserDN);
#print "dn[1] is $dn[1]\n";
if ($dn[1] !~ /Citrix/) {
$userDN = lc($currentuserDN);
}
$entry = $kent->nextEntry();
}
}
$kent->close;
#print "UserDN = $userDN\n";
die "No userDN" unless ($userDN);
print "LDAPServer is $LDAPServer
LDAPPort is $LDAPPort
userDN is $userDN
Password is $currentUserPassword";
my $changeconn = new Mozilla::LDAP::Conn($LDAPServer,
$LDAPPort,
$userDN,
$currentUserPassword);
die "Cannot bind: $!" unless($changeconn);
my $changeentry = $changeconn->search($baseDN, "sub", "($userDN)");
$changeentry->{userPassword} = [$newpassword];
die "Cannot update password" unless($changeconn->update($changeentry));
print "Password updated\n";
$changeconn->close;
I get an error on the line where I try to set the userPassword to the
new password. The error I get is:
[~/jd]$ ./ldapchange jt950001 win98 a
username = jt950001
Password = win98
new password = a
Define anonymous connection.
Starting search
Search done
LDAPServer is seawolf
LDAPPort is 389
userDN is uid=jt950001,ou=people, o=jdnet
Can't use string ("") as a HASH ref while "strict refs" in use at
./ldapchange line 58.
Password is win98[~/jd]$
[~/jd]$
Is this an ldap error, perLDAP error or an error in my code? If it is
an error in my code, then how do I fix it?
Kent