[SEC] [CRITICAL] Forbid RPC calls w/o credentials.

This is a major security fix.

bzr revid: p_christ@hol.gr-20090813081646-yr0ghe5uu80my7d3
This commit is contained in:
P. Christeas
2009-08-13 11:16:46 +03:00
parent cdfece0377
commit c6e4214daa
+17 -5
View File
@@ -25,6 +25,13 @@ import tools
_uid_cache = {}
# When rejecting a password, we need to give as little info as possible
class ExceptionNoTb(Exception):
def __init__(self, msg ):
# self.message = msg # No need in Python 2.6
self.traceback = ('','','')
self.args = (msg, '')
def login(db, login, password):
cr = pooler.get_db(db).cursor()
if password:
@@ -42,10 +49,10 @@ def check_super(passwd):
if passwd == tools.config['admin_passwd']:
return True
else:
raise Exception('AccessDenied')
raise ExceptionNoTb('AccessDenied')
def check(db, uid, passwd):
if _uid_cache.get(db, {}).get(uid) == passwd:
def check_creds(db, uid, passwd):
if _uid_cache.get(db, {}).get(uid) and _uid_cache.get(db, {}).get(uid) == passwd:
return True
cr = pooler.get_db(db).cursor()
if passwd:
@@ -55,7 +62,7 @@ def check(db, uid, passwd):
res = cr.fetchone()[0]
cr.close()
if not bool(res):
raise Exception('AccessDenied')
raise ExceptionNoTb('AccessDenied')
if res:
if _uid_cache.has_key(db):
ulist = _uid_cache[db]
@@ -73,8 +80,13 @@ def access(db, uid, passwd, sec_level, ids):
res = cr.fetchone()
cr.close()
if not res:
raise Exception('Bad username or password')
raise ExceptionNoTb('Bad username or password')
return res[0]
def check(db, uid, passwd):
if not check_creds(db,uid,passwd):
raise ExceptionNoTb('Bad username or password')
pass
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: