2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 22:35:35 +00:00

utils: rewrite parse_profile_start()

Merge from trunk revision 2990

Rewrite parse_profile_start() in aa.py to a more readable version.
The behaviour remains unchanged (and is covered by tests).

Acked-by: Kshitij Gupta <kgupta8592@gmail.com>
This commit is contained in:
Christian Boltz
2015-04-13 18:49:37 -07:00
committed by Steve Beattie
parent 5390777e45
commit 8d5569f20b

View File

@@ -2633,31 +2633,31 @@ def attach_profile_data(profiles, profile_data):
def parse_profile_start(line, file, lineno, profile, hat):
matches = parse_profile_start_line(line, file)
pps_set_profile = False
pps_set_hat_external = False
if profile: # we are inside a profile, so we expect a child profile
if not matches['profile_keyword']:
raise AppArmorException(_('%(profile)s profile in %(file)s contains syntax errors in line %(line)s: missing "profile" keyword.') % {
'profile': profile, 'file': file, 'line': lineno + 1 })
if profile != hat:
# nesting limit reached - a child profile can't contain another child profile
raise AppArmorException(_('%(profile)s profile in %(file)s contains syntax errors in line %(line)s: a child profile inside another child profile is not allowed.') % {
'profile': profile, 'file': file, 'line': lineno + 1 })
if profile:
#print(profile, hat)
if profile != hat or not matches['profile_keyword']:
raise AppArmorException(_('%(profile)s profile in %(file)s contains syntax errors in line: %(line)s.') % { 'profile': profile, 'file': file, 'line': lineno + 1 })
# Keep track of the start of a profile
if profile and profile == hat and matches['profile_keyword']:
# local profile
hat = matches['profile']
in_contained_hat = True
pps_set_profile = True
else:
pps_set_hat_external = False
else: # stand-alone profile
profile = matches['profile']
#print(profile)
if len(profile.split('//')) >= 2:
profile, hat = profile.split('//')[:2]
else:
hat = None
in_contained_hat = False
if hat:
pps_set_hat_external = True
else:
hat = profile
pps_set_hat_external = False
in_contained_hat = False
pps_set_profile = False
attachment = matches['attachment']
flags = matches['flags']