working on updating password - it works but is not able to detect if password is not already encrypted
This commit is contained in:
42
password.pl
Normal file
42
password.pl
Normal file
@@ -0,0 +1,42 @@
|
||||
#/usr/bin/perl
|
||||
|
||||
# Script to crypt all password in ldap
|
||||
use strict;
|
||||
use Net::LDAP;
|
||||
|
||||
my $ldapserver = "localhost";
|
||||
my $binddn = "cn=manager,o=od";
|
||||
my $bindpw = "123Soleil" ;
|
||||
|
||||
my $ldap = Net::LDAP->new( $ldapserver ) or die "$@" ;
|
||||
|
||||
my $base = 'ou=test,o=od' ;
|
||||
|
||||
my $mesg = $ldap->bind( $binddn,
|
||||
password => $bindpw
|
||||
);
|
||||
|
||||
$mesg->code and die $mesg->error; # check for errors
|
||||
|
||||
$mesg = $ldap->search(
|
||||
base=> $base,
|
||||
filter=>"(&(objectClass=person)(userpassword=*))",
|
||||
attribute=>"userPassword",
|
||||
);
|
||||
$mesg->code and die $mesg->error; # check for errors
|
||||
if( $mesg-> count() == 0 ) { exit(0) ; }
|
||||
|
||||
foreach my $entry ( $mesg-> entries ){
|
||||
my $userPassword = $entry->get_value('userPassword') ;
|
||||
my $sshaPassword = `slappasswd -n -s $userPassword` ;
|
||||
print $userPassword."\t".$sshaPassword."\n" ;
|
||||
if( ($userPassword cmp $sshaPassword)==0 ) {
|
||||
print $entry->dn() . "alteady crypted\n" ;
|
||||
next ; }
|
||||
$entry -> replace (
|
||||
userPassword => $sshaPassword,
|
||||
);
|
||||
$entry-> update($ldap) ;
|
||||
print $entry->dn() . " updated \n" ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user