Script to Change Passwords?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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://lists.fedoraproject.org/pipermail/389-users/attachments/20071204/c615e19e/attachment.html 


[Index of Archives]     [Fedora User Discussion]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora News]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora QA]     [Fedora Triage]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Yosemite Photos]     [Linux Apps]     [Maemo Users]     [Gnome Users]     [KDE Users]     [Fedora Tools]     [Fedora Art]     [Fedora Docs]     [Maemo Users]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Fedora ARM]

  Powered by Linux