Revert "drop overrids - LDAP has it on its own"
[mirror/userdir-ldap-cgi.git] / login.cgi
index 60358a6..d820af2 100755 (executable)
--- a/login.cgi
+++ b/login.cgi
@@ -1,7 +1,8 @@
 #!/usr/bin/perl
 
-# $Id: login.cgi,v 1.6 2000/05/06 06:10:05 tausq Exp $
+# $Id: login.cgi,v 1.10 2006/12/22 08:58:50 rmurray Exp $
 # (c) 1999 Randolph Chung. Licensed under the GPL. <tausq@debian.org>
+# (c) 2006 Ryan Murray. Licensed under the GPL. <rmurray@debian.org>
 
 use lib '.';
 use strict;
@@ -10,15 +11,15 @@ use CGI;
 use Util;
 use URI::Escape;
 use Crypt::Blowfish;
-use Net::LDAP qw(:all);
+use Net::LDAP qw(LDAP_SUCCESS LDAP_PROTOCOL_ERROR);
 
 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{webloginhtml}\n\n";
   exit;
 }
 
@@ -27,6 +28,7 @@ my $hrkey = unpack("H".($config{blowfishkeylen}*2), $key);
 my $cipher = new Crypt::Blowfish $key;
 
 my $ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!);
+&Util::UpgradeConnection($ldap) unless $config{usessl} eq 'False';
 
 my $username = $query->param('username');
 my $password = $query->param('password');
@@ -46,7 +48,7 @@ if ($mesg->code == LDAP_SUCCESS) {
   my $oldpassword = $entries->{$dn}->{userpassword}->[0];
   if ($oldpassword !~ /^{crypt}\$1\$/) {
     # Update their password to md5
-    open (LOG, ">$config{weblogfile}");
+    open (LOG, ">>$config{weblogfile}");
     print LOG scalar(localtime);
     print LOG ": Updating MD5 password for $dn\n";
     close LOG;
@@ -68,7 +70,7 @@ if ($mesg->code == LDAP_SUCCESS) {
 
   $ldap->unbind;
 } else {
-  print "Content-type: text/html\n\n";
+  print "Content-type: text/html; charset=utf-8\n\n";
   print "<html><body><h1>Not authenticated</h1></body></html>\n";
 }