示例#1
0
文件: users.py 项目: ntrrgc/blockwart
    def get_status(self):
        # verify content of /etc/passwd
        passwd_grep_result = self.node.run(
            "grep -e '^{}:' /etc/passwd".format(self.name),
            may_fail=True,
        )
        if passwd_grep_result.return_code != 0:
            return ItemStatus(
                correct=self.attributes['delete'],
                info={'exists': False},
            )
        elif self.attributes['delete']:
            return ItemStatus(correct=False, info={'exists': True})

        status = ItemStatus(correct=True, info={'exists': True})
        status.info.update(_parse_passwd_line(passwd_grep_result.stdout))

        if passwd_grep_result.stdout.strip() != self.line_passwd:
            status.correct = False

        if self.attributes['use_shadow']:
            # verify content of /etc/shadow
            shadow_grep_result = self.node.run(
                "grep -e '^{}:' /etc/shadow".format(self.name),
                may_fail=True,
            )
            if shadow_grep_result.return_code != 0:
                status.correct = False
                status.info['shadow_hash'] = None
            else:
                status.info['shadow_hash'] = shadow_grep_result.stdout.split(":")[1]
                if status.info['shadow_hash'] != self.attributes['password_hash']:
                    status.correct = False
        else:
            if status.info['passwd_hash'] != self.attributes['password_hash']:
                status.correct = False

        # verify content of /etc/group
        status.info['groups'] = _groups_for_user(self.node, self.name)
        if set(self.attributes['groups']) != set(status.info['groups']):
            status.correct = False

        return status
示例#2
0
    def get_status(self):
        # verify content of /etc/group
        grep_result = self.node.run(
            "grep -e '^{}:' /etc/group".format(self.name),
            may_fail=True,
        )
        if grep_result.return_code != 0:
            return ItemStatus(correct=self.attributes['delete'], info={'exists': False})

        status = ItemStatus(correct=not self.attributes['delete'], info={'exists': True})
        status.info.update(_parse_group_line(grep_result.stdout))

        if status.info['gid'] != self.attributes['gid']:
            status.correct = False

        return status