Exemplo n.º 1
0
def validate_overrides(path):
    """
    Raise RuntimeError if the file at 'path' provides a password and is not private to owner.

    :param path: Full path to the file to check. Assumed the file exists.
    :type path: basestring

    :raises: RuntimeError if file is not private and contains a password
    """
    valid_private_perms = [400, 600, 700]
    file_perm = int(oct(os.stat(path).st_mode & 0777))

    cfg = Config(path)
    if cfg.has_option("auth", "password"):
        if file_perm not in valid_private_perms:
            runtime_dict = {'path': path, 'file_perm': file_perm,
                            'valid_private_perms': valid_private_perms}
            raise RuntimeError(_(
                "File %(path)s contains a password and has incorrect permissions: %(file_perm)d, "
                "It should be one of %(valid_private_perms)s.") % runtime_dict)