Update of /cvsroot/tmda/tmda/contrib/cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv1555
Modified Files:
Authenticate.py
Log Message:
Logging in with debug mode (append a ?debug=1 to the end of the URL) will
display a helpful error message on failure. This mode will help debug file
permission errors that prevent login.
Index: Authenticate.py
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/cgi/Authenticate.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Authenticate.py 29 Nov 2002 17:12:38 -0000 1.3
+++ Authenticate.py 30 Nov 2002 18:14:18 -0000 1.4
@@ -21,6 +21,7 @@
"Password checker for tmda-cgi."
+import CgiUtil
import crypt
import os
import os.path
@@ -31,14 +32,18 @@
def ComparePassword(Filename, User, Password):
"""Checks password against a given filename.
-ComparePassword returns 1 if the password can be authenticated. It returns None
-if it couldn't be."""
+Returns:
+ 1: File read, user found, password authenticated
+ 0: File read, user found, login deactivated
+ -1: File read, user found, password wrong
+ -2: File read, user not found
+ -3: File couldn't be read"""
try:
- F = open(Filename)
- except:
- return None
+ F = open(Filename)
+ except IOError:
+ return -3
- RetVal = None
+ RetVal = -2
while (1):
PasswordRecord = F.readline()
@@ -49,16 +54,24 @@
# Have we found the correct user record?
if Temp[0] == User:
- if Temp[1] == "": raise "Login disabled"
+ if Temp[1] == "":
+ RetVal = 0
+ break
Perm = os.stat(Filename)[0] & 07777
# Is the password in the file encrypted?
if (Perm != 0400) and (Perm != 0600):
- if crypt.crypt(Password, Temp[1][:2]) == Temp[1]: RetVal = 1
+ if crypt.crypt(Password, Temp[1][:2]) == Temp[1]:
+ RetVal = 1
+ else:
+ RetVal = -1
break
else:
- if Temp[1] == Password: RetVal = 1
+ if Temp[1] == Password:
+ RetVal = 1
+ else:
+ RetVal = -1
break
F.close()
return RetVal
@@ -76,7 +89,37 @@
else:
# No given location, try ~/.tmda/tmda-cgi
FN = os.path.expanduser("~/.tmda/tmda-cgi")
+
+ # Login succeed?
+ RetVal = ComparePassword(FN, Form["user"].value, Form["password"].value)
+ if RetVal > 0:
+ return RetVal
+
+ # Login help?
+ if int(Form["debug"].value):
+ Errors = ["Logins for user %(user)s have been deactivated in file
+<tt>%(file)s</tt>",
+ "Password incorrect for user %(user)s in file <tt>%(file)s</tt>",
+ "User %(user)s was not found in file <tt>%(file)s</tt>",
+ "Could not read file <tt>%(file)s</tt>"]
+ Err = Errors[-RetVal] % {"user": Form["user"].value, "file": FN}
+ Err += "<br>" + CgiUtil.FileDetails("Local password", FN)
+ if RetVal > -2:
+ CgiUtil.TermError("Login failed", "Bad pass / login disabled.", "validate
+password",
+ Err, "Correct entry for %s in file <tt>%s</tt>" % (Form["user"].value, FN))
+ if RetVal > -2:
+ return RetVal
+
+ # Login succeed?
+ FN = "/etc/tmda-cgi"
RetVal = ComparePassword(FN, Form["user"].value, Form["password"].value)
- if RetVal: return RetVal
- return ComparePassword("/etc/tmda-cgi", Form["user"].value, \
- Form["password"].value)
+ if RetVal > 0:
+ return RetVal
+
+ # Login help?
+ if int(Form["debug"].value):
+ Err += "<br>" + Errors[-RetVal] % {"user": Form["user"].value, "file": FN}
+ Err += "<br>" + CgiUtil.FileDetails("Global password", FN)
+ CgiUtil.TermError("Login failed", "Password / password file error.",
+ "validate password", Err, "Reset password or correct file permissions")
+ return RetVal
+
\ No newline at end of file
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs