mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 08:24:42 +01:00
extend add_or_remove_flag() to handle str for old flags
If the old flags are given as str (or None), call split_flags() to
convert them to a list.
This allows to simplify change_profile_flags() which now doesn't need to
call split_flags() on its own.
Also add some tests with a str for the old flags
(cherry picked from commit e80caa130a
+
conflict resolution)
This commit is contained in:
parent
41eae89869
commit
267c18e725
3 changed files with 10 additions and 5 deletions
|
@ -49,7 +49,7 @@ from apparmor.regex import (RE_PROFILE_START, RE_PROFILE_END, RE_PROFILE_LINK,
|
|||
RE_PROFILE_UNIX, RE_RULE_HAS_COMMA, RE_HAS_COMMENT_SPLIT,
|
||||
strip_quotes, parse_profile_start_line, re_match_include )
|
||||
|
||||
from apparmor.profile_storage import ProfileStorage, add_or_remove_flag, split_flags, ruletypes
|
||||
from apparmor.profile_storage import ProfileStorage, add_or_remove_flag, ruletypes
|
||||
|
||||
import apparmor.rules as aarules
|
||||
|
||||
|
@ -625,9 +625,7 @@ def get_profile_flags(filename, program):
|
|||
def change_profile_flags(filename, program, flag, set_flag):
|
||||
old_flags = get_profile_flags(filename, program)
|
||||
|
||||
newflags = split_flags(old_flags)
|
||||
|
||||
newflags = add_or_remove_flag(newflags, flag, set_flag)
|
||||
newflags = add_or_remove_flag(old_flags, flag, set_flag)
|
||||
|
||||
newflags = ','.join(newflags)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# ----------------------------------------------------------------------
|
||||
|
||||
|
||||
from apparmor.common import AppArmorBug, hasher
|
||||
from apparmor.common import AppArmorBug, hasher, type_is_str
|
||||
|
||||
from apparmor.rule.capability import CapabilityRuleset
|
||||
from apparmor.rule.change_profile import ChangeProfileRuleset
|
||||
|
@ -120,6 +120,9 @@ def split_flags(flags):
|
|||
def add_or_remove_flag(flags, flag_to_change, set_flag):
|
||||
'''add (if set_flag == True) or remove the given flag_to_change to flags'''
|
||||
|
||||
if type_is_str(flags) or flags is None:
|
||||
flags = split_flags(flags)
|
||||
|
||||
if set_flag:
|
||||
if flag_to_change not in flags:
|
||||
flags.append(flag_to_change)
|
||||
|
|
|
@ -46,6 +46,10 @@ class AaTest_add_or_remove_flag(AATest):
|
|||
([ [], 'audit', False ], [] ),
|
||||
([ ['complain'], 'audit', True ], ['audit', 'complain'] ),
|
||||
([ ['complain'], 'audit', False ], ['complain'] ),
|
||||
([ '', 'audit', True ], ['audit'] ),
|
||||
([ None, 'audit', False ], [] ),
|
||||
([ 'complain', 'audit', True ], ['audit', 'complain'] ),
|
||||
([ ' complain ', 'audit', False ], ['complain'] ),
|
||||
]
|
||||
|
||||
def _run_test(self, params, expected):
|
||||
|
|
Loading…
Add table
Reference in a new issue