Exemplo n.º 1
0
def initDB(dsn=None, backend=None, host="localhost", port=None, username=None,
        password=None, database=None):
    """
    Initialize the database.

    For Oracle connections: provide just a string dsn argument, or a username,
    password, and database. (sid in this case)
    """

    if backend == None:
        backend=CFG.DB_BACKEND

    if not SUPPORTED_BACKENDS.has_key(backend):
        raise rhnException("Unsupported database backend", backend)

    if backend == ORACLE:
        # For Oracle, must provide either dsn or username, password,
        # and database.
        if not dsn and not (username and password and database):
            # Grab the default from the config file:
            dsn = CFG.DEFAULT_DB

        if dsn:
            # split the dsn up into username/pass/sid so we can call the rest of
            # the code in a uniform fashion for all database backends:
            (username, temp) = dsn.split("/")
            (password, database) = temp.split("@")

    if backend == POSTGRESQL:
        host = None
        port = None
        dsn = CFG.DEFAULT_DB
        (username, temp) = dsn.split("/")
        (password, dsn) = temp.split("@")
        for i in dsn.split(';'):
            (k, v) = i.split('=')
            if k == 'dbname':
                database = v
            elif k == 'host':
                host = v
            elif k == 'port':
                port = int(v)
            else:
                raise rhnException("Unknown piece in default_db string", i)

    # Hide the password
    add_to_seclist(dsn)
    try:
        __init__DB(backend, host, port, username, password, database)
#    except (rhnException, SQLError):
#        raise # pass on, we know those ones
#    except (KeyboardInterrupt, SystemExit):
#        raise
    except:
        raise
        #e_type, e_value = sys.exc_info()[:2]
        #raise rhnException("Could not initialize Oracle database connection",
        #                   str(e_type), str(e_value))
    return 0
Exemplo n.º 2
0
def getUserGroups(login, password):
    # Authenticates a user and returns the list of groups it belongs
    # to, and the org id
    add_to_seclist(password)
    log_debug(4, login)
    user = rhnUser.search(login)

    if not user:
        log_debug("rhnUser.search failed")
        raise rhnFault(2)

    # Check the user's password
    if not user.check_password(password):
        log_debug("user.check_password failed")
        raise rhnFault(2)

    return getUserGroupsFromUserInstance(user)
Exemplo n.º 3
0
 def auth(self, login, password):
     add_to_seclist(password)
     self.groups, self.org_id, self.user_id = getUserGroups(login, password)
     log_debug(4, "Groups: %s; org_id: %s; user_id: %s" % (
         self.groups, self.org_id, self.user_id))