Пример #1
0
def info(setype, name=None):
    if setype == TYPE:
        q = setools.TypeQuery(_pol)
        q.name = name
        results = list(q.results())

        if name and len(results) < 1:
            # type not found, try alias
            q.name = None
            q.alias = name
            results = list(q.results())

        return ({
            'aliases': list(map(str, x.aliases())),
            'name': str(x),
            'permissive': bool(x.ispermissive),
            'attributes': list(map(str, x.attributes()))
        } for x in results)

    elif setype == ROLE:
        q = setools.RoleQuery(_pol)
        if name:
            q.name = name

        return ({
            'name': str(x),
            'roles': list(map(str, x.expand())),
            'types': list(map(str, x.types())),
        } for x in q.results())

    elif setype == ATTRIBUTE:
        q = setools.TypeAttributeQuery(_pol)
        if name:
            q.name = name

        return ({
            'name': str(x),
            'types': list(map(str, x.expand())),
        } for x in q.results())

    elif setype == PORT:
        q = setools.PortconQuery(_pol)
        if name:
            ports = [int(i) for i in name.split("-")]
            if len(ports) == 2:
                q.ports = ports
            elif len(ports) == 1:
                q.ports = (ports[0], ports[0])

        if _pol.mls:
            return ({
                'high': x.ports.high,
                'protocol': str(x.protocol),
                'range': str(x.context.range_),
                'type': str(x.context.type_),
                'low': x.ports.low,
            } for x in q.results())
        return ({
            'high': x.ports.high,
            'protocol': str(x.protocol),
            'type': str(x.context.type_),
            'low': x.ports.low,
        } for x in q.results())

    elif setype == USER:
        q = setools.UserQuery(_pol)
        if name:
            q.name = name

        if _pol.mls:
            return ({
                'range': str(x.mls_range),
                'name': str(x),
                'roles': list(map(str, x.roles)),
                'level': str(x.mls_level),
            } for x in q.results())
        return ({
            'name': str(x),
            'roles': list(map(str, x.roles)),
        } for x in q.results())

    elif setype == BOOLEAN:
        q = setools.BoolQuery(_pol)
        if name:
            q.name = name

        return ({
            'name': str(x),
            'state': x.state,
        } for x in q.results())

    elif setype == TCLASS:
        q = setools.ObjClassQuery(_pol)
        if name:
            q.name = name

        return ({
            'name': str(x),
            'permlist': list(x.perms),
        } for x in q.results())

    else:
        raise ValueError("Invalid type")
if args.debug:
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s|%(levelname)s|%(name)s|%(message)s')
elif args.verbose:
    logging.basicConfig(level=logging.INFO, format='%(message)s')
else:
    logging.basicConfig(level=logging.WARNING, format='%(message)s')

try:
    p = setools.SELinuxPolicy(args.policy)
    components = []

    if args.boolquery or args.all:
        q = setools.BoolQuery(p)
        if isinstance(args.boolquery, str):
            q.name = args.boolquery

        components.append(("Booleans", q, lambda x: x.statement()))

    if args.mlscatsquery or args.all:
        q = setools.CategoryQuery(p)
        if isinstance(args.mlscatsquery, str):
            q.name = args.mlscatsquery

        components.append(("Categories", q, lambda x: x.statement()))

    if args.classquery or args.all:
        q = setools.ObjClassQuery(p)
        if isinstance(args.classquery, str):