working on updating password - it works but is not able to detect if password is not already encrypted

This commit is contained in:
2019-10-17 21:16:39 +02:00
parent 91b47f700c
commit df9a4b0098

42
password.pl Normal file
View 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" ;
}