mirror of
https://github.com/SELinuxProject/setools
synced 2025-04-01 14:48:07 +00:00
83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
# Copyright 2014, Tresys Technology, LLC
|
|
#
|
|
# This file is part of SETools.
|
|
#
|
|
# SETools is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Lesser General Public License as
|
|
# published by the Free Software Foundation, either version 2.1 of
|
|
# the License, or (at your option) any later version.
|
|
#
|
|
# SETools is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with SETools. If not, see
|
|
# <http://www.gnu.org/licenses/>.
|
|
#
|
|
import compquery
|
|
import contextquery
|
|
|
|
|
|
class InitialSIDQuery(compquery.ComponentQuery, contextquery.ContextQuery):
|
|
|
|
"""Initial SID (context) query."""
|
|
|
|
def __init__(self, policy,
|
|
name="", name_regex=False,
|
|
user="", user_regex=False,
|
|
role="", role_regex=False,
|
|
type_="", type_regex=False,
|
|
range_=""):
|
|
"""
|
|
Parameters:
|
|
policy The policy to query.
|
|
|
|
user The criteria to match the context's user.
|
|
user_regex If true, regular expression matching
|
|
will be used on the user.
|
|
role The criteria to match the context's role.
|
|
role_regex If true, regular expression matching
|
|
will be used on the role.
|
|
type_ The criteria to match the context's type.
|
|
type_regex If true, regular expression matching
|
|
will be used on the type.
|
|
range_ The criteria to match the context's range.
|
|
"""
|
|
|
|
self.policy = policy
|
|
|
|
self.set_name(name, regex=name_regex)
|
|
self.set_user(user, regex=user_regex)
|
|
self.set_role(role, regex=role_regex)
|
|
self.set_type(type_, regex=type_regex)
|
|
self.set_range(range_)
|
|
|
|
def results(self):
|
|
"""Generator which yields all matching initial SIDs."""
|
|
|
|
for i in self.policy.initialsids():
|
|
if self.name and not self._match_regex(
|
|
i,
|
|
self.name,
|
|
self.name_regex,
|
|
self.name_cmp):
|
|
continue
|
|
|
|
if not self._match_context(
|
|
i.context,
|
|
self.user,
|
|
self.user_regex,
|
|
self.user_cmp,
|
|
self.role,
|
|
self.role_regex,
|
|
self.role_cmp,
|
|
self.type_,
|
|
self.type_regex,
|
|
self.type_cmp,
|
|
self.range_):
|
|
continue
|
|
|
|
yield i
|