2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-29 13:28:19 +00:00

better error messages in aa.py store_list_var()

This patch improves the error messages in aa.py store_list_var() to make
debugging of profile syntax problems easier. It also adds an additional
parameter for the profile filename (used in the error message)

Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
Christian Boltz 2014-06-20 13:36:35 +02:00
parent 7c14d01d7a
commit f77d5666d4

View File

@ -2851,11 +2851,11 @@ def parse_profile_data(data, file, do_include):
if profile:
if not profile_data[profile][hat].get('lvar', False):
profile_data[profile][hat]['lvar'][list_var] = []
store_list_var(profile_data[profile]['lvar'], list_var, value, var_operation)
store_list_var(profile_data[profile]['lvar'], list_var, value, var_operation, file)
else:
if not filelist[file].get('lvar', False):
filelist[file]['lvar'][list_var] = []
store_list_var(filelist[file]['lvar'], list_var, value, var_operation)
store_list_var(filelist[file]['lvar'], list_var, value, var_operation, file)
elif RE_PROFILE_CONDITIONAL.search(line):
# Conditional Boolean
@ -3245,7 +3245,7 @@ def is_active_profile(pname):
else:
return False
def store_list_var(var, list_var, value, var_operation):
def store_list_var(var, list_var, value, var_operation, filename):
"""Store(add new variable or add values to variable) the variables encountered in the given list_var"""
vlist = separate_vars(value)
if var_operation == '=':
@ -3253,14 +3253,14 @@ def store_list_var(var, list_var, value, var_operation):
var[list_var] = set(vlist)
else:
#print('Ignored: New definition for variable for:',list_var,'=', value, 'operation was:',var_operation,'old value=', var[list_var])
raise AppArmorException(_('An existing variable redefined: %s') % list_var)
raise AppArmorException(_('Redefining existing variable %s: %s in %s') % (list_var, value, filename))
elif var_operation == '+=':
if var.get(list_var, False):
var[list_var] = set(var[list_var] + vlist)
else:
raise AppArmorException(_('Values added to a non-existing variable: %s') % list_var)
raise AppArmorException(_('Values added to a non-existing variable %s: %s in %s') % (list_var, value, filename))
else:
raise AppArmorException(_('Unknown variable operation: %s') % var_operation)
raise AppArmorException(_('Unknown variable operation %s for variable %s in %s') % (var_operation, list_var, filename))
def strip_quotes(data):
@ -4097,11 +4097,11 @@ def serialize_profile_from_old_profile(profile_data, name, options):
value = strip_quotes(matches[2])
var_set = hasher()
if profile:
store_list_var(var_set, list_var, value, var_operation)
store_list_var(var_set, list_var, value, var_operation, prof_filename)
if not var_set[list_var] == write_prof_data['lvar'].get(list_var, False):
correct = False
else:
store_list_var(var_set, list_var, value, var_operation)
store_list_var(var_set, list_var, value, var_operation, prof_filename)
if not var_set[list_var] == write_filelist['lvar'].get(list_var, False):
correct = False