當前位置: 首頁>>代碼示例>>Python>>正文


Python spwd.getspall方法代碼示例

本文整理匯總了Python中spwd.getspall方法的典型用法代碼示例。如果您正苦於以下問題:Python spwd.getspall方法的具體用法?Python spwd.getspall怎麽用?Python spwd.getspall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在spwd的用法示例。


在下文中一共展示了spwd.getspall方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import spwd [as 別名]
# 或者: from spwd import getspall [as 別名]
def __init__(self, anonymous_user=None):
            if os.geteuid() != 0 or not spwd.getspall():
                raise AuthorizerError("super user privileges are required")
            self.anonymous_user = anonymous_user

            if self.anonymous_user is not None:
                try:
                    pwd.getpwnam(self.anonymous_user).pw_dir
                except KeyError:
                    raise AuthorizerError('no such user %s' % anonymous_user)

        # --- overridden / private API 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:14,代碼來源:authorizers.py

示例2: check_for_default_passwords

# 需要導入模塊: import spwd [as 別名]
# 或者: from spwd import getspall [as 別名]
def check_for_default_passwords(config_path):
    """
    Check if the 'pi' user current password hash is in our list of default password hashes.
    """
    base_dir = Path(config_path)
    pass_hashes_file_path = base_dir.joinpath('pass_hashes.txt')  # For deb installation.
    if not pass_hashes_file_path.is_file():
        base_dir = Path(__file__).resolve().parent.parent
        pass_hashes_file_path = base_dir.joinpath('misc/pass_hashes.txt')
    with pass_hashes_file_path.open() as f:
        read_data = f.read()

    known_passwords = {}
    for username_password in read_data.splitlines():
        username, password = username_password.split(':', maxsplit=1)
        pw = known_passwords.get(username, [])
        pw.append(password)
        known_passwords[username] = pw

    def hash_matches(pwdp, plaintext_password):
        i = pwdp.rfind('$')
        salt = pwdp[:i]
        crypted = crypt.crypt(plaintext_password, salt)
        return crypted == pwdp

    usernames = set()
    for shadow in spwd.getspall():
        encrypted_password = shadow.sp_pwdp

        for password in known_passwords.get(shadow.sp_namp, []):
            if hash_matches(encrypted_password, password):
                usernames.add(shadow.sp_namp)

    return list(usernames) 
開發者ID:WoTTsecurity,項目名稱:agent,代碼行數:36,代碼來源:security_helper.py

示例3: test_accounts_nopassword

# 需要導入模塊: import spwd [as 別名]
# 或者: from spwd import getspall [as 別名]
def test_accounts_nopassword():
    try:
        import spwd
    except ImportError:
        logger.info("Import of spwd failed ")
        return TestResult(Result.SKIP, "Unable to import 'spwd' module")

    disabled = []
    locked = []
    passworded = []
    no_password = []

    shadow_entries = spwd.getspall()

    for entry in shadow_entries:
        # passwords which start with ! have been locked
        if entry.sp_pwd.startswith('!'):
            locked.append(entry.sp_nam)
        # passwords which start with * have been disabled
        elif entry.sp_pwd.startswith('*'):
            disabled.append(entry.sp_nam)
        # blank passwords are bad!
        elif entry.sp_pwd == "":
            no_password.append(entry.sp_nam)
        # otherwise the account has a password
        else:
            passworded.append(entry.sp_nam)

    if len(no_password) > 0:
        notes = "Account(s) { " + str(no_password) + " } have no password!"
        test_result = Result.FAIL
    else:
        notes = ("Disabled: " + str(len(disabled)) + ", Locked: " +
                 str(len(locked)) + ", Password: " + str(len(passworded)) +
                 ", No Password: " + str(len(no_password)))
        test_result = Result.PASS

    return TestResult(test_result, notes) 
開發者ID:HewlettPackard,項目名稱:reconbf,代碼行數:40,代碼來源:test_users.py


注:本文中的spwd.getspall方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。