From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [PATCH v2 3/3] sepolgen-ifgen: refactor default policy path retrieval
Date: Thu, 28 May 2020 14:51:28 +0200 [thread overview]
Message-ID: <20200528125128.26915-3-cgzones@googlemail.com> (raw)
In-Reply-To: <20200528125128.26915-1-cgzones@googlemail.com>
On a SELinux disabled system `selinux.security_policyvers()` will fail;
do not bailout but use a fallback policy version to check if a binary
policy file with that extension exists.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
python/audit2allow/sepolgen-ifgen | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/python/audit2allow/sepolgen-ifgen b/python/audit2allow/sepolgen-ifgen
index 4a71cda4..48e60f1d 100644
--- a/python/audit2allow/sepolgen-ifgen
+++ b/python/audit2allow/sepolgen-ifgen
@@ -69,7 +69,11 @@ def get_policy():
p = selinux.selinux_current_policy_path()
if p and os.path.exists(p):
return p
- i = selinux.security_policyvers()
+ try:
+ i = selinux.security_policyvers()
+ except OSError:
+ # SELinux Disabled Machine
+ i = 50 # some high enough default value
p = selinux.selinux_binary_policy_path() + "." + str(i)
while i > 0 and not os.path.exists(p):
i = i - 1
@@ -80,18 +84,16 @@ def get_policy():
def get_attrs(policy_path, attr_helper):
+ if not policy_path:
+ policy_path = get_policy()
+ if not policy_path:
+ sys.stderr.write("No installed policy to check\n")
+ return None
+
try:
- if not policy_path:
- policy_path = get_policy()
- if not policy_path:
- sys.stderr.write("No installed policy to check\n")
- return None
outfile = tempfile.NamedTemporaryFile()
except IOError as e:
- sys.stderr.write("could not open attribute output file\n")
- return None
- except OSError:
- # SELinux Disabled Machine
+ sys.stderr.write("could not open attribute output file: %s\n" % e)
return None
fd = open("/dev/null", "w")
--
2.27.0.rc2
next prev parent reply other threads:[~2020-05-28 12:51 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 19:01 [PATCH] sepolgen: parse gen_tunable as bool Christian Göttsche
2020-05-27 15:04 ` Stephen Smalley
2020-05-28 12:51 ` [PATCH v2 1/3] " Christian Göttsche
2020-05-28 12:51 ` [PATCH v2 2/3] refparser: add missing newline after error message Christian Göttsche
2020-05-29 14:35 ` Stephen Smalley
2020-05-28 12:51 ` Christian Göttsche [this message]
2020-05-29 14:45 ` [PATCH v2 3/3] sepolgen-ifgen: refactor default policy path retrieval Stephen Smalley
2020-05-28 14:23 ` [PATCH v2 1/3] sepolgen: parse gen_tunable as bool Stephen Smalley
2020-05-28 14:51 ` Christian Göttsche
2020-06-04 20:26 ` Stephen Smalley
2020-06-05 14:49 ` [PATCH v3 " Christian Göttsche
2020-06-05 14:49 ` [PATCH v3 2/3] refparser: add missing newline after error message Christian Göttsche
2020-06-08 15:28 ` Stephen Smalley
2020-06-05 14:49 ` [PATCH v3 3/3] sepolgen-ifgen: refactor default policy path retrieval Christian Göttsche
2020-06-08 15:51 ` Stephen Smalley
2020-06-08 15:27 ` [PATCH v3 1/3] sepolgen: parse gen_tunable as bool Stephen Smalley
2020-06-11 13:53 ` [PATCH v4 " Christian Göttsche
2020-06-11 13:53 ` [PATCH v4 2/3] refparser: add missing newline after error message Christian Göttsche
2020-06-11 13:53 ` [PATCH v4 3/3] sepolgen-ifgen: refactor default policy path retrieval Christian Göttsche
2020-06-11 14:03 ` Stephen Smalley
2020-06-15 14:19 ` [PATCH v5 " Christian Göttsche
2020-06-15 15:07 ` [PATCH v6 " Christian Göttsche
2020-06-15 16:30 ` Stephen Smalley
2020-06-18 19:32 ` Petr Lautrbach
2020-05-28 12:54 ` [PATCH] sepolgen: parse gen_tunable as bool Christian Göttsche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200528125128.26915-3-cgzones@googlemail.com \
--to=cgzones@googlemail.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox