Пример #1
0
def list_keys(username):
    db = AuthorizedKeysDB(disable_lock=True)
    try:
        subuser = db.subusers[username]
    except KeyError:
        subssh.writeln("%s has no keys" % username)
    else:
        for i, (key, (type, comment)) in enumerate(subuser.pubkeys.items()):
            subssh.writeln("%s. %s key: %s %s" %
                          (i+1, comment, type , key))

    db.close()
Пример #2
0
def add_key(username, key_input, comment):
    if username == config.ADMIN:
        raise Unauthorized("Cannot set admin's key over xmlrpc!")
    
    # Cannot use stdin from xmlprc
    if key_input == '-':
        raise PubKeyException("Invalid public key")
        
    
    db = AuthorizedKeysDB()
    try:
        key = get_key_from_input(key_input)
        db.add_key_from_str(username, key, comment)
    except (PubKeyException, urllib2.HTTPError), e:
        db.close()
        logger.warning("%s failed to add key. comment: %s key: %s" 
                       % (username, comment, key_input))
        raise e
Пример #3
0
def remove_user(username):
    db = AuthorizedKeysDB()
    try:
        db.remove_user(username)
    except KeyError:
        subssh.errln("No such user '%s'" % username)
    else:
        db.commit()
    db.close()
Пример #4
0
def rewrite_authorized_keys():
    db = AuthorizedKeysDB()
    db.commit()
    db.close()
    return 0
Пример #5
0
def list_users():
    db = AuthorizedKeysDB(disable_lock=True)
    for user in db.subusers.values():
        print "%s with %s keys" % (user.username, len(user.pubkeys))
    db.close()
Пример #6
0
    if not username_pattern.search(username):
        subssh.writeln("User name \"%s\" contains restricted characters" % username)
        return 1

    try:
        key = get_key_from_input(" ".join(args))
    except (urllib2.HTTPError, IOError, OSError), e:
        if len(e.args) > 1:
            subssh.errln(e.args[1])
        else:
            subssh.errln(e.args[0])
        return 1

    exit_status = 0

    db = AuthorizedKeysDB()
    try:
        db.add_key_from_str(username, key, comment)
    except (PubKeyException, AuthorizedKeysException), e:
        subssh.errln(e.args[0])
        exit_status = 1
    else:
        db.commit()
    db.close()


    return exit_status

def list_keys(username):
    db = AuthorizedKeysDB(disable_lock=True)
    try: