X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=login.cgi;h=1e04ef48e5f513befb9e5c10f1b5c6e407dfbb05;hb=f1af5002f6710b37cf3d2b3903ef3103a34424a6;hp=cf5a138923547525c69599d39517801f6c00a93d;hpb=14f0717050a65ff19a217d014bb59c5cdf95f871;p=mirror%2Fuserdir-ldap-cgi.git diff --git a/login.cgi b/login.cgi index cf5a138..1e04ef4 100755 --- a/login.cgi +++ b/login.cgi @@ -1,6 +1,6 @@ #!/usr/bin/perl -# $Id: login.cgi,v 1.3 1999/12/09 02:18:14 tausq Exp $ +# $Id: login.cgi,v 1.9 2006/06/27 04:37:45 rmurray Exp $ # (c) 1999 Randolph Chung. Licensed under the GPL. use lib '.'; @@ -17,8 +17,8 @@ my %config = &Util::ReadConfigFile; my $query = new CGI; my $proto = ($ENV{HTTPS} ? "https" : "http"); -if (!($query->param('username')) || !($query->param('password'))) { - print "Location: $proto://$ENV{SERVER_NAME}/$config{webloginurl}\n\n"; +if ($proto eq "http" || !($query->param('username')) || !($query->param('password'))) { + print "Location: https://$ENV{SERVER_NAME}/$config{webloginurl}\n\n"; exit; } @@ -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')) { @@ -43,11 +62,13 @@ if ($mesg->code == LDAP_SUCCESS) { $url .= uri_escape("uid=$username,$config{basedn}", "\x00-\x40\x7f-\xff"); print "Location: $url\n\n"; } else { - print "Location: $proto://$ENV{SERVER_NAME}/$config{websearchurl}?id=$username&authtoken=$cryptid,$hrkey\n\n"; + my $url = "$proto://$ENV{SERVER_NAME}/$config{websearchurl}?id=$username&authtoken=$cryptid,$hrkey"; + print "Location: $url\n\n"; } $ldap->unbind; } else { - print "Content-type: text/html\n\n"; + print "Content-type: text/html; charset=utf-8\n\n"; print "

Not authenticated

\n"; } +