2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 18:17:09 +00:00

utils: make read_profiles robust against profiles it doesn't understand

This will allow the other tools to continue working on other profiles, even
if some of them use syntax that the utils currently can't handle.

Signed-off-by: Ryan Lee <ryan.lee@canonical.com>
This commit is contained in:
Ryan Lee 2025-02-27 16:04:40 -08:00
parent bf2054d963
commit e71e27be70
2 changed files with 12 additions and 3 deletions

View File

@ -1627,7 +1627,10 @@ def read_profiles(ui_msg=False, skip_profiles=()):
aaui.UI_Info("skipping profile %s" % full_file) aaui.UI_Info("skipping profile %s" % full_file)
continue continue
else: else:
try:
read_profile(full_file, True) read_profile(full_file, True)
except AppArmorException as e:
aaui.UI_Info("skipping unparseable profile %s (%s)" % (full_file, e.value))
def read_inactive_profiles(skip_profiles=()): def read_inactive_profiles(skip_profiles=()):

View File

@ -81,7 +81,10 @@ class TestLogprof(AATest):
for line in jlog: for line in jlog:
if line.startswith('o '): # read from stdout if line.startswith('o '): # read from stdout
while True:
output = self.process.stdout.readline().decode("utf-8").strip() output = self.process.stdout.readline().decode("utf-8").strip()
if "skipping unparseable" not in output:
break
self.assertEqual(output, line[2:]) self.assertEqual(output, line[2:])
elif line.startswith('i '): # send to stdin elif line.startswith('i '): # send to stdin
@ -124,7 +127,10 @@ class TestLogprof(AATest):
self.process = self._startLogprof(auditlog, 'allow-all') self.process = self._startLogprof(auditlog, 'allow-all')
for line in slog: for line in slog:
while True:
output = self.process.stdout.readline().decode("utf-8").strip() output = self.process.stdout.readline().decode("utf-8").strip()
if not output.startswith("skipping unparseable"):
break
self.assertEqual(output, line) self.assertEqual(output, line)
# give logprof some time to write the updated profile and terminate # give logprof some time to write the updated profile and terminate
self.process.wait(timeout=0.3) self.process.wait(timeout=0.3)