From: tausq <> Date: Sat, 6 May 2000 04:10:05 +0000 (+0000) Subject: Added a hack to update passwords to md5 when a user logs in. X-Git-Tag: release-0.3.33~136 X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap-cgi.git;a=commitdiff_plain;h=b62107bcdbc4fb5311f981999d838de38243e46f Added a hack to update passwords to md5 when a user logs in. --- diff --git a/Util.pm b/Util.pm index 0ec02cd..371aae9 100644 --- a/Util.pm +++ b/Util.pm @@ -301,4 +301,20 @@ sub ReadConfigFile { return %config; } +sub LDAPUpdate { + my $ldap = shift; + my $dn = shift; + my $attr = shift; + my $val = shift; + my $mesg; + + if (!$val) { + $mesg = $ldap->modify($dn, delete => { $attr => [] }); + } else { + $val = [ $val ] if (!ref($val)); + $mesg = $ldap->modify($dn, replace => { $attr => $val }); + $mesg->code && &Util::HTMLError("error updating $attr: ".$mesg->error); + } +} + 1; diff --git a/login.cgi b/login.cgi index 243c427..60358a6 100755 --- a/login.cgi +++ b/login.cgi @@ -1,6 +1,6 @@ #!/usr/bin/perl -# $Id: login.cgi,v 1.5 1999/12/13 05:03:47 tausq Exp $ +# $Id: login.cgi,v 1.6 2000/05/06 06:10:05 tausq Exp $ # (c) 1999 Randolph Chung. Licensed under the GPL. use lib '.'; @@ -36,6 +36,25 @@ my $mesg = $ldap->bind($binddn, password => $password); $mesg->sync; if ($mesg->code == LDAP_SUCCESS) { + # HACK HACK HACK + # Check for md5 password, and update as necessary + $mesg = $ldap->search(base => $config{basedn}, + filter => "(uid=$username)"); + $mesg->code && &Util::HTMLError($mesg->error); + my $entries = $mesg->as_struct; + my $dn = (keys %$entries)[0]; + my $oldpassword = $entries->{$dn}->{userpassword}->[0]; + if ($oldpassword !~ /^{crypt}\$1\$/) { + # Update their password to md5 + open (LOG, ">$config{weblogfile}"); + print LOG scalar(localtime); + print LOG ": Updating MD5 password for $dn\n"; + close LOG; + my $newpassword = '{crypt}'.crypt($password, &Util::CreateCryptSalt(1)); + &Util::LDAPUpdate($ldap, $dn, 'userPassword', $newpassword); + } + ## END HACK HACK HACK + my $cryptid = &Util::SavePasswordToFile($username, $password, $cipher); if ($query->param('update')) { diff --git a/update.cgi b/update.cgi index 7dd4fc5..1a92dce 100755 --- a/update.cgi +++ b/update.cgi @@ -1,6 +1,6 @@ #!/usr/bin/perl -# $Id: update.cgi,v 1.6 2000/03/26 22:13:25 tausq Exp $ +# $Id: update.cgi,v 1.7 2000/05/06 06:10:05 tausq Exp $ # (c) 1999 Randolph Chung. Licensed under the GPL. use lib '.'; @@ -107,7 +107,7 @@ if (!($query->param('doupdate'))) { # create a md5 crypted password $newpassword = '{crypt}'.crypt($query->param('newpass'), &Util::CreateCryptSalt(1)); - LDAPUpdate($ldap, $editdn, 'userPassword', $newpassword); + &Util::LDAPUpdate($ldap, $editdn, 'userPassword', $newpassword); &Util::UpdateAuthToken($authtoken, $query->param('newpass')); } @@ -118,21 +118,21 @@ if (!($query->param('doupdate'))) { ($lat, $long) = &Util::CheckLatLong($query->param('latitude'), $query->param('longitude')); - LDAPUpdate($ldap, $editdn, 'postalAddress', $newstaddress); - LDAPUpdate($ldap, $editdn, 'l', $query->param('l')); - LDAPUpdate($ldap, $editdn, 'latitude', $lat); - LDAPUpdate($ldap, $editdn, 'longitude', $long); - LDAPUpdate($ldap, $editdn, 'c', $query->param('country')); - LDAPUpdate($ldap, $editdn, 'postalcode', $query->param('postalcode')); - LDAPUpdate($ldap, $editdn, 'telephoneNumber', $query->param('telephonenumber')); - LDAPUpdate($ldap, $editdn, 'facsimileTelephoneNumber', $query->param('facsimiletelephonenumber')); - LDAPUpdate($ldap, $editdn, 'loginShell', $query->param('loginshell')); - LDAPUpdate($ldap, $editdn, 'emailForward', $query->param('email')); - LDAPUpdate($ldap, $editdn, 'privatesub', $query->param('privatesub')); - LDAPUpdate($ldap, $editdn, 'ircNick', $query->param('ircnick')); - LDAPUpdate($ldap, $editdn, 'icquin', $query->param('icquin')); - LDAPUpdate($ldap, $editdn, 'labeledUrl', $query->param('labeledurl')); - LDAPUpdate($ldap, $editdn, 'onvacation', $query->param('onvacation')); + &Util::LDAPUpdate($ldap, $editdn, 'postalAddress', $newstaddress); + &Util::LDAPUpdate($ldap, $editdn, 'l', $query->param('l')); + &Util::LDAPUpdate($ldap, $editdn, 'latitude', $lat); + &Util::LDAPUpdate($ldap, $editdn, 'longitude', $long); + &Util::LDAPUpdate($ldap, $editdn, 'c', $query->param('country')); + &Util::LDAPUpdate($ldap, $editdn, 'postalcode', $query->param('postalcode')); + &Util::LDAPUpdate($ldap, $editdn, 'telephoneNumber', $query->param('telephonenumber')); + &Util::LDAPUpdate($ldap, $editdn, 'facsimileTelephoneNumber', $query->param('facsimiletelephonenumber')); + &Util::LDAPUpdate($ldap, $editdn, 'loginShell', $query->param('loginshell')); + &Util::LDAPUpdate($ldap, $editdn, 'emailForward', $query->param('email')); + &Util::LDAPUpdate($ldap, $editdn, 'privatesub', $query->param('privatesub')); + &Util::LDAPUpdate($ldap, $editdn, 'ircNick', $query->param('ircnick')); + &Util::LDAPUpdate($ldap, $editdn, 'icquin', $query->param('icquin')); + &Util::LDAPUpdate($ldap, $editdn, 'labeledUrl', $query->param('labeledurl')); + &Util::LDAPUpdate($ldap, $editdn, 'onvacation', $query->param('onvacation')); # when we are done, reload the page with the updated details. my $url = "$proto://$ENV{SERVER_NAME}/$config{webupdateurl}?id=$id&authtoken=$authtoken&editdn="; @@ -142,18 +142,3 @@ if (!($query->param('doupdate'))) { $ldap->unbind; -sub LDAPUpdate { - my $ldap = shift; - my $dn = shift; - my $attr = shift; - my $val = shift; - my $mesg; - - if (!$val) { - $mesg = $ldap->modify($dn, delete => { $attr => [] }); - } else { - $val = [ $val ] if (!ref($val)); - $mesg = $ldap->modify($dn, replace => { $attr => $val }); - $mesg->code && &Util::HTMLError("error updating $attr: ".$mesg->error); - } -}