[Fedora-directory-users] Script to Change Passwords?
Fabrice Durand
oeufdure at gmail.com
Tue Dec 4 17:39:39 UTC 2007
A kind of perl script that i use to change the user password from an sql
database, but It's easy with perl to parse a csv file.
use Net::LDAP;
use DBI();
use Encode;
use MIME::Base64;
use SHA;
my $dbh = DBI->connect("DBI:mysql:database=user;host=localhost","admin",
"password",{RaiseError => 1});
$ldup = Net::LDAP->new( 'ldap.server.com' ) or die "$@";
$masg = $ldup->bind ; # an anonymous bind
$masg = $ldup->search( # perform a search
base =>
"ou=People,dc=test,dc=com",
scope => 'sub',
filter => "(uid=*)",
attrs => ['uid']
);
$masg->code && die $masg->error;
foreach $entry ($masg->entries)
{
$uid="NULL";
$dn=$entry->dn();
foreach $attr ($entry->attributes)
{
if($attr eq uid)
{
$uid=$entry->get_value($attr);
# print "\n".$uid;
}
}
$az=$dbh->prepare("select * from passwd where nom = \"$uid\"
ORDER BY stamptime DESC");
$az->execute;
$passwd = $az->fetchrow_hashref;
if ($passwd->{passwd}) {
$sha = new SHA;
$salt = (shift, pack ("H*", shift));
$label = "{SSHA}";
$hash = $sha->hash ($passwd->{passwd} . $salt);
$hashpass = $label. encode_base64 ($hash . $salt,
"");
$ldop = Net::LDAP->new( 'ldap.server.com' );
$misg = $ldop->bind( 'cn=directory manager',password
=> 'password');
$misg = $ldop->modify( $dn, delete => [userPassword]
);
$misg = $ldop->modify( $dn, add => { userPassword =>
$hashpass } );
undef $hashpass;
$misg->code && warn "failed to add entry: ",
$misg->error ;
$misg = $ldop->unbind;
print $uid.":".$passwd->{passwd}."\n";
}
}
$mesg = $ldup->unbind; # take down session
Fabrice
2007/12/4, Glenn <glenn at mail.txwes.edu>:
>
> Howdy, Guys - I need a shell script that will read a file of user IDs and
> passwords and enter the passwords into Fedora Directory. The users are
> already in FD; we just need to change all their passwords at once. The
> file
> will be formatted so the user ID is in column one and the password is in
> column two. We have about 8,000 users. Any help appreciated. Thanks.
> -
> Glenn.
>
> --
> Fedora-directory-users mailing list
> Fedora-directory-users at redhat.com
> https://www.redhat.com/mailman/listinfo/fedora-directory-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/fedora-directory-users/attachments/20071204/c615e19e/attachment.htm>
More information about the Fedora-directory-users
mailing list