# This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Copyright 2005 Dan Williams and Red Hat, Inc. import DBManager class User: def __init__(self, email, guest): if not email: raise Exception self.email = email self.guest = guest self.own_jobs = False self.job_admin = False self.user_admin = False self.server_admin = False class Authenticator: """ Talks to a database of users & capabilities """ def __init__(self, db_manager, cfg): self._cfg = cfg self._db_manager = db_manager def new_authed_user(self, email, client_address): if not email: return None try: dbcx = self._db_manager.dbcx() curs = dbcx.cursor() except StandardError, e: del curs, dbcx print "Unable to access user database: '%s'" % str(e) return None user = None curs.execute("SELECT * FROM users WHERE email='%s'" % email) item = dbcx.fetchone(curs) if item: user = User(email, False) user.own_jobs = item['own_jobs'] user.job_admin = item['job_admin'] user.user_admin = item['user_admin'] user.server_admin = item['server_admin'] else: if self._cfg.get_bool("UI", "guest_allowed"): user = User('guest@guest', True) del curs, dbcx return user