Skip to content

Commit

Permalink
Merge pull request #820 from dsugar100/python3_9_support
Browse files Browse the repository at this point in the history
Changes to support python 3.9 (RHEL9)
  • Loading branch information
pebenito authored Oct 16, 2024
2 parents e627b48 + d520a7e commit 7c0f511
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions support/validate-appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ class ContextValidator:

"""Validate contexts using security_check_context or chkcon"""

def __init__(self, /, policy_path: str | None = None, *,
chkcon_path: str | None = None) -> None:
def __init__(self, /, policy_path: typing.Optional[str]= None, *,
chkcon_path: typing.Optional[str] = None) -> None:

self.log = logging.getLogger(__name__).getChild(self.__class__.__name__)
self.selinux_enabled = libselinux.is_selinux_enabled() == 1
self.policy_path = policy_path
self.chkcon_path: Path | str | None = self._find_chkcon(chkcon_path)

self.chkcon_path: typing.Optional[Path, str, None] = self._find_chkcon(chkcon_path)
try:
self.policy = setools.SELinuxPolicy(policy_path) \
if self.selinux_enabled or policy_path else None
Expand All @@ -75,14 +74,18 @@ def __init__(self, /, policy_path: str | None = None, *,
self.dta = None
self.rbacrq = None
self.log.warning(f"SETools not available. {sys.path=}")
except AttributeError:
self.dta = None
self.rbacrq = None
self.log.warning(f"Old SETools Available - partial analysis only. {sys.path=}")

self.log.debug(f"{self.__class__.__name__}: "
f"{self.selinux_enabled=}, "
f"{self.policy_path=}, "
f"{self.policy=}, "
f"{self.chkcon_path=}")

def _find_chkcon(self, /, path: Path | str | None) -> Path | str | None:
def _find_chkcon(self, /, path: typing.Union[Path, str, None]) -> typing.Union[Path, str, None]:
if path:
self.log.debug(f"Checking access on provided chkcon path {path}")
if os.access(path, os.X_OK):
Expand Down Expand Up @@ -588,8 +591,8 @@ def validate_default_contexts(validator: ContextValidator, default_contexts: Pat


def validate_appconfig_files(conf_dir: str, /, *,
policy_path: str | None = None,
chkcon_path: str | None = None,
policy_path: typing.Optional[str] = None,
chkcon_path: typing.Optional[str] = None,
lxc: bool = True,
sepgsql: bool = True,
virt: bool = True,
Expand Down

0 comments on commit 7c0f511

Please sign in to comment.