selinux/python/sepolicy/sepolicy
Petr Lautrbach be065c4b44
sepolicy: Do not try to load policy on import
When a policy is inaccessible, scripts fail right "import sepolicy". With
this change we let the "sepolicy" module to import and move the policy
initialization before it's used for the first time.

Fixes:
    >>> import seobject
    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/sepolicy/__init__.py", line 171, in policy
        _pol = setools.SELinuxPolicy(policy_file)
      File "setools/policyrep/selinuxpolicy.pxi", line 73, in setools.policyrep.SELinuxPolicy.__cinit__
      File "setools/policyrep/selinuxpolicy.pxi", line 695, in setools.policyrep.SELinuxPolicy._load_policy
    PermissionError: [Errno 13] Permission denied: '//etc/selinux/targeted/policy/policy.33'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.9/site-packages/seobject.py", line 33, in <module>
        import sepolicy
      File "/usr/lib/python3.9/site-packages/sepolicy/__init__.py", line 186, in <module>
        raise e
      File "/usr/lib/python3.9/site-packages/sepolicy/__init__.py", line 183, in <module>
        policy(policy_file)
      File "/usr/lib/python3.9/site-packages/sepolicy/__init__.py", line 173, in policy
        raise ValueError(_("Failed to read %s policy file") % policy_file)
    ValueError: Failed to read //etc/selinux/targeted/policy/policy.33 policy file

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
2021-02-27 21:38:24 +01:00
..
help python/sepolicy: add missing % in network tab help text 2018-08-15 23:00:08 +02:00
templates Fix typo in executable.py template. 2017-05-05 11:52:19 -04:00
__init__.py sepolicy: Do not try to load policy on import 2021-02-27 21:38:24 +01:00
booleans.py Fix many misspellings 2019-09-18 22:47:35 +02:00
communicate.py Fix many misspellings 2019-09-18 22:47:35 +02:00
generate.py sepolicy: fix some typos and port definitions 2020-05-04 10:31:44 +02:00
gui.py Fix many misspellings 2019-09-18 22:47:35 +02:00
interface.py python/sepolicy: Use xml.etree.ElementTree.Element.iter() 2020-06-18 19:29:21 +02:00
manpage.py python/sepolicy: allow to override manpage date 2020-11-13 10:53:59 +01:00
network.py sepolicy: fix some typos and port definitions 2020-05-04 10:31:44 +02:00
sedbus.py Move policycoreutils/{sepolicy,audit2allow,semanage,scripts/chcat*} and sepolgen to python. 2016-11-16 11:19:50 -05:00
sepolicy.glade sepolicy-gui: fix columns in transitions view 2020-05-04 10:31:39 +02:00
transition.py Fix many misspellings 2019-09-18 22:47:35 +02:00