diff --git a/password.pl b/password.pl new file mode 100644 index 0000000..de7e8f5 --- /dev/null +++ b/password.pl @@ -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" ; +} +