mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-01 14:55:10 +00:00
Improve performance in aamode.py (saving 10-17% time):
- replace MODE_MAP_RE regex with MODE_MAP_SET set - change sub_str_to_mode() to use MODE_MAP_SET set instead of MODE_MAP_RE - change split_log_mode to use split() instead of a regex Patch by Peter Maloney <peter.maloney@brockmann-consult.de> Acked-by: Christian Boltz <apparmor@cboltz.de> split_log_mode() change also Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
@@ -68,7 +68,7 @@ MODE_HASH = {'x': AA_MAY_EXEC, 'X': AA_MAY_EXEC,
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_MODE_RE = re.compile('(r|w|l|m|k|a|x|ix|ux|px|pux|cx|nx|pix|cix|Ux|Px|PUx|Cx|Nx|Pix|Cix)')
|
LOG_MODE_RE = re.compile('(r|w|l|m|k|a|x|ix|ux|px|pux|cx|nx|pix|cix|Ux|Px|PUx|Cx|Nx|Pix|Cix)')
|
||||||
MODE_MAP_RE = re.compile('(r|w|l|m|k|a|x|i|u|p|c|n|I|U|P|C|N)')
|
MODE_MAP_SET = {"r", "w", "l", "m", "k", "a", "x", "i", "u", "p", "c", "n", "I", "U", "P", "C", "N"}
|
||||||
|
|
||||||
def str_to_mode(string):
|
def str_to_mode(string):
|
||||||
if not string:
|
if not string:
|
||||||
@@ -88,26 +88,22 @@ def str_to_mode(string):
|
|||||||
def sub_str_to_mode(string):
|
def sub_str_to_mode(string):
|
||||||
mode = set()
|
mode = set()
|
||||||
|
|
||||||
while string:
|
for mode_char in string:
|
||||||
tmp = MODE_MAP_RE.search(string)
|
if mode_char not in MODE_MAP_SET:
|
||||||
if not tmp:
|
|
||||||
break
|
break
|
||||||
string = MODE_MAP_RE.sub('', string, 1)
|
|
||||||
|
|
||||||
mode_char = tmp.groups()[0]
|
|
||||||
if MODE_HASH.get(mode_char, False):
|
if MODE_HASH.get(mode_char, False):
|
||||||
mode |= MODE_HASH[mode_char]
|
mode |= MODE_HASH[mode_char]
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return mode
|
return mode
|
||||||
|
|
||||||
def split_log_mode(mode):
|
def split_log_mode(mode):
|
||||||
|
#if the mode has a "::", then the left side is the user mode, and the right side is the other mode
|
||||||
|
#if not, then the mode is both the user and other mode
|
||||||
user = ''
|
user = ''
|
||||||
other = ''
|
other = ''
|
||||||
match = re.search('(.*?)::(.*)', mode)
|
|
||||||
if match:
|
if "::" in mode:
|
||||||
user, other = match.groups()
|
user, other = mode.split("::")
|
||||||
else:
|
else:
|
||||||
user = mode
|
user = mode
|
||||||
other = mode
|
other = mode
|
||||||
|
Reference in New Issue
Block a user