[apparmor] [patch] Move check_and_split_list() to BaseRule
Christian Boltz
apparmor at cboltz.de
Thu Dec 3 21:12:06 UTC 2015
Hello,
$subject.
We'll need this function in more rule classes ;-)
[ 25-move-check_and_split_list-to-baserule.diff ]
=== modified file ./utils/apparmor/rule/__init__.py
--- utils/apparmor/rule/__init__.py 2015-11-19 17:42:26.325879118 +0100
+++ utils/apparmor/rule/__init__.py 2015-11-23 21:43:24.431985210 +0100
@@ -343,6 +343,29 @@
raise NotImplementedError("get_glob_ext is not available for this rule type!")
+def check_and_split_list(lst, allowed_keywords, all_obj, classname, keyword_name):
+ '''check if lst is all_obj or contains only items listed in allowed_keywords'''
+
+ if lst == all_obj:
+ return None, True, None
+ elif type(lst) == str:
+ result_list = {lst}
+ elif (type(lst) == list or type(lst) == tuple) and len(lst) > 0:
+ result_list = set(lst)
+ else:
+ raise AppArmorBug('Passed unknown %(type)s object to %(classname)s: %(unknown_object)s' %
+ {'type': type(lst), 'classname': classname, 'unknown_object': str(lst)})
+
+ unknown_items = set()
+ for item in result_list:
+ if not item.strip():
+ raise AppArmorBug('Passed empty %(keyword_name)s to %(classname)s' %
+ {'keyword_name': keyword_name, 'classname': classname})
+ if item not in allowed_keywords:
+ unknown_items.add(item)
+
+ return result_list, False, unknown_items
+
def parse_comment(matches):
'''returns the comment (with a leading space) from the matches object'''
comment = ''
=== modified file ./utils/apparmor/rule/signal.py
--- utils/apparmor/rule/signal.py 2015-11-19 18:17:06.944324889 +0100
+++ utils/apparmor/rule/signal.py 2015-11-23 21:43:00.892169194 +0100
@@ -17,7 +17,7 @@
from apparmor.aare import AARE
from apparmor.regex import RE_PROFILE_SIGNAL, RE_PROFILE_NAME
from apparmor.common import AppArmorBug, AppArmorException
-from apparmor.rule import BaseRule, BaseRuleset, parse_modifiers, quote_if_needed
+from apparmor.rule import BaseRule, BaseRuleset, check_and_split_list, parse_modifiers, quote_if_needed
# setup module translations
from apparmor.translations import init_translation
@@ -274,27 +274,3 @@
# XXX only remove one part, not all
return 'signal,'
-
-def check_and_split_list(lst, allowed_keywords, all_obj, classname, keyword_name):
- '''check if lst is all_obj or contains only items listed in allowed_keywords'''
-
- if lst == all_obj:
- return None, True, None
- elif type(lst) == str:
- result_list = {lst}
- elif (type(lst) == list or type(lst) == tuple) and len(lst) > 0:
- result_list = set(lst)
- else:
- raise AppArmorBug('Passed unknown %(type)s object to %(classname)s: %(unknown_object)s' %
- {'type': type(lst), 'classname': classname, 'unknown_object': str(lst)})
-
- unknown_items = set()
- for item in result_list:
- if not item.strip():
- raise AppArmorBug('Passed empty %(keyword_name)s to %(classname)s' %
- {'keyword_name': keyword_name, 'classname': classname})
- if item not in allowed_keywords:
- unknown_items.add(item)
-
- return result_list, False, unknown_items
-
Regards,
Christian Boltz
--
Life used to be simpler when apple and blackberry were just fruits!
[from https://bugzilla.novell.com/quips.cgi]
More information about the AppArmor
mailing list