|
|
10e4bd |
From 25373db5cac520b85350db91b8a7ed0737d3316c Mon Sep 17 00:00:00 2001
|
|
|
10e4bd |
From: Vit Mojzis <vmojzis@redhat.com>
|
|
|
10e4bd |
Date: Tue, 24 Jan 2023 21:05:05 +0100
|
|
|
10e4bd |
Subject: [PATCH] python/sepolicy: Cache conditional rule queries
|
|
|
10e4bd |
|
|
|
10e4bd |
Commit 7506771e4b630fe0ab853f96574e039055cb72eb
|
|
|
10e4bd |
"add missing booleans to man pages" dramatically slowed down
|
|
|
10e4bd |
"sepolicy manpage -a" by removing caching of setools rule query.
|
|
|
10e4bd |
Re-add said caching and update the query to only return conditional
|
|
|
10e4bd |
rules.
|
|
|
10e4bd |
|
|
|
10e4bd |
Before commit 7506771e:
|
|
|
10e4bd |
#time sepolicy manpage -a
|
|
|
10e4bd |
real 1m43.153s
|
|
|
10e4bd |
# time sepolicy manpage -d httpd_t
|
|
|
10e4bd |
real 0m4.493s
|
|
|
10e4bd |
|
|
|
10e4bd |
After commit 7506771e:
|
|
|
10e4bd |
#time sepolicy manpage -a
|
|
|
10e4bd |
real 1h56m43.153s
|
|
|
10e4bd |
# time sepolicy manpage -d httpd_t
|
|
|
10e4bd |
real 0m8.352s
|
|
|
10e4bd |
|
|
|
10e4bd |
After this commit:
|
|
|
10e4bd |
#time sepolicy manpage -a
|
|
|
10e4bd |
real 1m41.074s
|
|
|
10e4bd |
# time sepolicy manpage -d httpd_t
|
|
|
10e4bd |
real 0m7.358s
|
|
|
10e4bd |
|
|
|
10e4bd |
Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
|
|
|
10e4bd |
---
|
|
|
10e4bd |
python/sepolicy/sepolicy/__init__.py | 11 ++++++++++-
|
|
|
10e4bd |
1 file changed, 10 insertions(+), 1 deletion(-)
|
|
|
10e4bd |
|
|
|
10e4bd |
diff --git a/python/sepolicy/sepolicy/__init__.py b/python/sepolicy/sepolicy/__init__.py
|
|
|
10e4bd |
index 0f51174d..f48231e9 100644
|
|
|
10e4bd |
--- a/python/sepolicy/sepolicy/__init__.py
|
|
|
10e4bd |
+++ b/python/sepolicy/sepolicy/__init__.py
|
|
|
10e4bd |
@@ -114,6 +114,7 @@ all_attributes = None
|
|
|
10e4bd |
booleans = None
|
|
|
10e4bd |
booleans_dict = None
|
|
|
10e4bd |
all_allow_rules = None
|
|
|
10e4bd |
+all_bool_rules = None
|
|
|
10e4bd |
all_transitions = None
|
|
|
10e4bd |
|
|
|
10e4bd |
|
|
|
10e4bd |
@@ -1119,6 +1120,14 @@ def get_all_allow_rules():
|
|
|
10e4bd |
all_allow_rules = search([ALLOW])
|
|
|
10e4bd |
return all_allow_rules
|
|
|
10e4bd |
|
|
|
10e4bd |
+def get_all_bool_rules():
|
|
|
10e4bd |
+ global all_bool_rules
|
|
|
10e4bd |
+ if not all_bool_rules:
|
|
|
10e4bd |
+ q = setools.TERuleQuery(_pol, boolean=".*", boolean_regex=True,
|
|
|
10e4bd |
+ ruletype=[ALLOW, DONTAUDIT])
|
|
|
10e4bd |
+ all_bool_rules = [_setools_rule_to_dict(x) for x in q.results()]
|
|
|
10e4bd |
+ return all_bool_rules
|
|
|
10e4bd |
+
|
|
|
10e4bd |
def get_all_transitions():
|
|
|
10e4bd |
global all_transitions
|
|
|
10e4bd |
if not all_transitions:
|
|
|
10e4bd |
@@ -1129,7 +1138,7 @@ def get_bools(setype):
|
|
|
10e4bd |
bools = []
|
|
|
10e4bd |
domainbools = []
|
|
|
10e4bd |
domainname, short_name = gen_short_name(setype)
|
|
|
10e4bd |
- for i in map(lambda x: x['booleans'], filter(lambda x: 'booleans' in x and x['source'] == setype, search([ALLOW, DONTAUDIT]))):
|
|
|
10e4bd |
+ for i in map(lambda x: x['booleans'], filter(lambda x: 'booleans' in x and x['source'] == setype, get_all_bool_rules())):
|
|
|
10e4bd |
for b in i:
|
|
|
10e4bd |
if not isinstance(b, tuple):
|
|
|
10e4bd |
continue
|
|
|
10e4bd |
--
|
|
|
10e4bd |
2.37.3
|
|
|
10e4bd |
|