hash mot de passe ldap fonctionnel.

This commit is contained in:
2019-10-18 17:55:28 +02:00
parent df9a4b0098
commit 57a336603c

View File

@@ -1,17 +1,18 @@
#/usr/bin/perl #/usr/bin/perl
#
# This script will look for any ldap object of type person, with attribute
# userPassword set, check wether it's already been hashed and hash it if not
# Script to crypt all password in ldap
use strict; use strict;
use Net::LDAP; use Net::LDAP;
my $ldapserver = "localhost"; my $ldapserver = "localhost";
my $binddn = "cn=manager,o=od"; my $binddn = "cn=manager,o=od";
my $bindpw = "123Soleil" ; my $bindpw = "123Soleil" ;
my $base = 'ou=peopleEnt,o=od' ;
my $ldap = Net::LDAP->new( $ldapserver ) or die "$@" ; my $ldap = Net::LDAP->new( $ldapserver ) or die "$@" ;
my $base = 'ou=test,o=od' ;
my $mesg = $ldap->bind( $binddn, my $mesg = $ldap->bind( $binddn,
password => $bindpw password => $bindpw
); );
@@ -29,9 +30,8 @@ if( $mesg-> count() == 0 ) { exit(0) ; }
foreach my $entry ( $mesg-> entries ){ foreach my $entry ( $mesg-> entries ){
my $userPassword = $entry->get_value('userPassword') ; my $userPassword = $entry->get_value('userPassword') ;
my $sshaPassword = `slappasswd -n -s $userPassword` ; my $sshaPassword = `slappasswd -n -s $userPassword` ;
print $userPassword."\t".$sshaPassword."\n" ; if( $userPassword =~ /^{SSHA/ ) {
if( ($userPassword cmp $sshaPassword)==0 ) { print $entry->dn() . " already hashed\n" ;
print $entry->dn() . "alteady crypted\n" ;
next ; } next ; }
$entry -> replace ( $entry -> replace (
userPassword => $sshaPassword, userPassword => $sshaPassword,