diff --git a/parser/tst/caching.py b/parser/tst/caching.py index 9bbae7c23..4a56aab41 100755 --- a/parser/tst/caching.py +++ b/parser/tst/caching.py @@ -137,11 +137,13 @@ class AAParserCachingCommon(testlib.AATestTemplate): with open(features_path) as f: features = f.read() if expected: - self.assertEqual(expected_output, features, - "features contents differ, expected:\n%s\nresult:\n%s" % (expected_output, features)) + self.assertEqual( + expected_output, features, + "features contents differ, expected:\n%s\nresult:\n%s" % (expected_output, features)) else: - self.assertNotEqual(expected_output, features, - "features contents equal, expected:\n%s\nresult:\n%s" % (expected_output, features)) + self.assertNotEqual( + expected_output, features, + "features contents equal, expected:\n%s\nresult:\n%s" % (expected_output, features)) class AAParserBasicCachingTests(AAParserCachingCommon): diff --git a/utils/aa-easyprof b/utils/aa-easyprof index 735f45629..a58245470 100755 --- a/utils/aa-easyprof +++ b/utils/aa-easyprof @@ -100,8 +100,7 @@ if __name__ == "__main__": apparmor.easyprof.print_files(files) sys.exit(0) - elif binary is None and not options.profile_name and \ - not options.manifest: + elif binary is None and not options.profile_name and not options.manifest: error("Must specify binary and/or profile name\n%s" % m) params = apparmor.easyprof.gen_policy_params(binary, options) diff --git a/utils/apparmor/easyprof.py b/utils/apparmor/easyprof.py index b96bd5a99..d26395143 100644 --- a/utils/apparmor/easyprof.py +++ b/utils/apparmor/easyprof.py @@ -282,9 +282,9 @@ class AppArmorEasyProfile: if opt.templates_dir and os.path.isdir(opt.templates_dir): self.dirs['templates'] = os.path.abspath(opt.templates_dir) elif not opt.templates_dir and \ - opt.template and \ - os.path.isfile(opt.template) and \ - valid_path(opt.template): + opt.template and \ + os.path.isfile(opt.template) and \ + valid_path(opt.template): # If we specified the template and it is an absolute path, just set # the templates directory to the parent of the template so we don't # have to require --template-dir with absolute paths. @@ -521,18 +521,20 @@ class AppArmorEasyProfile: return rule - def gen_policy(self, name, - binary=None, - profile_name=None, - template_var=[], - abstractions=None, - policy_groups=None, - read_path=[], - write_path=[], - author=None, - comment=None, - copyright=None, - no_verify=False): + def gen_policy( + self, + name, + binary=None, + profile_name=None, + template_var=[], + abstractions=None, + policy_groups=None, + read_path=[], + write_path=[], + author=None, + comment=None, + copyright=None, + no_verify=False): def find_prefix(t, s): '''Calculate whitespace prefix based on occurrence of s in t''' pat = re.compile(r'^ *%s' % s) diff --git a/utils/apparmor/rule/__init__.py b/utils/apparmor/rule/__init__.py index 18060bca3..8aa0ae398 100644 --- a/utils/apparmor/rule/__init__.py +++ b/utils/apparmor/rule/__init__.py @@ -80,12 +80,14 @@ class BaseRule: return None, True elif type(rulepart) is str: if len(rulepart.strip()) == 0: - raise AppArmorBug('Passed empty %(partname)s to %(classname)s: %(rulepart)s' % - {'partname': partname, 'classname': self.__class__.__name__, 'rulepart': str(rulepart)}) + raise AppArmorBug( + 'Passed empty %(partname)s to %(classname)s: %(rulepart)s' + % {'partname': partname, 'classname': self.__class__.__name__, 'rulepart': str(rulepart)}) return AARE(rulepart, is_path=is_path, log_event=log_event), False else: - raise AppArmorBug('Passed unknown %(partname)s to %(classname)s: %(rulepart)s' - % {'partname': partname, 'classname': self.__class__.__name__, 'rulepart': str(rulepart)}) + raise AppArmorBug( + 'Passed unknown %(partname)s to %(classname)s: %(rulepart)s' + % {'partname': partname, 'classname': self.__class__.__name__, 'rulepart': str(rulepart)}) def __repr__(self): classname = self.__class__.__name__ @@ -506,14 +508,16 @@ def check_and_split_list(lst, allowed_keywords, all_obj, classname, keyword_name elif type(lst) in (list, tuple, set) and (len(lst) > 0 or allow_empty_list): result_list = set(lst) else: - raise AppArmorBug('Passed unknown %(type)s object to %(classname)s: %(unknown_object)s' % - {'type': type(lst), 'classname': classname, 'unknown_object': str(lst)}) + raise AppArmorBug( + 'Passed unknown %(type)s object to %(classname)s: %(unknown_object)s' % + {'type': type(lst), 'classname': classname, 'unknown_object': str(lst)}) unknown_items = set() for item in result_list: if not item.strip(): - raise AppArmorBug('Passed empty %(keyword_name)s to %(classname)s' % - {'keyword_name': keyword_name, 'classname': classname}) + raise AppArmorBug( + 'Passed empty %(keyword_name)s to %(classname)s' % + {'keyword_name': keyword_name, 'classname': classname}) if item not in allowed_keywords: unknown_items.add(item) diff --git a/utils/apparmor/rule/alias.py b/utils/apparmor/rule/alias.py index 613791a1f..781385428 100644 --- a/utils/apparmor/rule/alias.py +++ b/utils/apparmor/rule/alias.py @@ -72,8 +72,8 @@ class AliasRule(BaseRule): orig_path = strip_quotes(matches.group('orig_path').strip()) target = strip_quotes(matches.group('target').strip()) - return AliasRule(orig_path, target, - audit=False, deny=False, allow_keyword=False, comment=comment) + return AliasRule( + orig_path, target, audit=False, deny=False, allow_keyword=False, comment=comment) def get_clean(self, depth=0): '''return rule (in clean/default formatting)''' diff --git a/utils/apparmor/rule/dbus.py b/utils/apparmor/rule/dbus.py index 5b721372e..6273e313b 100644 --- a/utils/apparmor/rule/dbus.py +++ b/utils/apparmor/rule/dbus.py @@ -190,7 +190,7 @@ class DbusRule(BaseRule): peerlabel = DbusRule.ALL return DbusRule(access, bus, path, name, interface, member, peername, peerlabel, - audit=audit, deny=deny, allow_keyword=allow_keyword, comment=comment) + audit=audit, deny=deny, allow_keyword=allow_keyword, comment=comment) def get_clean(self, depth=0): '''return rule (in clean/default formatting)''' diff --git a/utils/apparmor/rule/file.py b/utils/apparmor/rule/file.py index 1ddcfdfc6..2dbc7ae1c 100644 --- a/utils/apparmor/rule/file.py +++ b/utils/apparmor/rule/file.py @@ -188,7 +188,7 @@ class FileRule(BaseRule): file_keyword = bool(matches.group('file_keyword')) return FileRule(path, perms, exec_perms, target, owner, file_keyword, leading_perms, - audit=audit, deny=deny, allow_keyword=allow_keyword, comment=comment) + audit=audit, deny=deny, allow_keyword=allow_keyword, comment=comment) def get_clean(self, depth=0): '''return rule (in clean/default formatting)''' diff --git a/utils/apparmor/rule/include.py b/utils/apparmor/rule/include.py index fdba29c5a..d697baeb7 100644 --- a/utils/apparmor/rule/include.py +++ b/utils/apparmor/rule/include.py @@ -69,8 +69,7 @@ class IncludeRule(BaseRule): # TODO: move re_match_include_parse() from regex.py to this class after converting all code to use IncludeRule path, ifexists, ismagic = re_match_include_parse(raw_rule, cls.rule_name) - return cls(path, ifexists, ismagic, - audit=False, deny=False, allow_keyword=False, comment=comment) + return cls(path, ifexists, ismagic, audit=False, deny=False, allow_keyword=False, comment=comment) def get_clean(self, depth=0): '''return rule (in clean/default formatting)''' diff --git a/utils/apparmor/rule/ptrace.py b/utils/apparmor/rule/ptrace.py index de7b1bcac..b091cd024 100644 --- a/utils/apparmor/rule/ptrace.py +++ b/utils/apparmor/rule/ptrace.py @@ -56,7 +56,7 @@ class PtraceRule(BaseRule): comment='', log_event=None): super().__init__(audit=audit, deny=deny, allow_keyword=allow_keyword, - comment=comment, log_event=log_event) + comment=comment, log_event=log_event) self.access, self.all_access, unknown_items = check_and_split_list(access, access_keywords, PtraceRule.ALL, 'PtraceRule', 'access') if unknown_items: @@ -104,8 +104,8 @@ class PtraceRule(BaseRule): access = PtraceRule.ALL peer = PtraceRule.ALL - return PtraceRule(access, peer, - audit=audit, deny=deny, allow_keyword=allow_keyword, comment=comment) + return PtraceRule( + access, peer, audit=audit, deny=deny, allow_keyword=allow_keyword, comment=comment) def get_clean(self, depth=0): '''return rule (in clean/default formatting)''' diff --git a/utils/apparmor/rule/rlimit.py b/utils/apparmor/rule/rlimit.py index b5a3f1b33..1afa0fb5f 100644 --- a/utils/apparmor/rule/rlimit.py +++ b/utils/apparmor/rule/rlimit.py @@ -131,8 +131,7 @@ class RlimitRule(BaseRule): else: raise AppArmorException(_("Invalid rlimit rule '%s' - value missing") % raw_rule) # pragma: no cover - would need breaking the regex - return RlimitRule(rlimit, value, - comment=comment) + return RlimitRule(rlimit, value, comment=comment) def get_clean(self, depth=0): '''return rule (in clean/default formatting)''' diff --git a/utils/apparmor/rule/signal.py b/utils/apparmor/rule/signal.py index 6456da5ca..708104ae3 100644 --- a/utils/apparmor/rule/signal.py +++ b/utils/apparmor/rule/signal.py @@ -143,7 +143,7 @@ class SignalRule(BaseRule): peer = SignalRule.ALL return SignalRule(access, signal, peer, - audit=audit, deny=deny, allow_keyword=allow_keyword, comment=comment) + audit=audit, deny=deny, allow_keyword=allow_keyword, comment=comment) def get_clean(self, depth=0): '''return rule (in clean/default formatting)''' diff --git a/utils/apparmor/sandbox.py b/utils/apparmor/sandbox.py index a949afa36..78fa27dab 100644 --- a/utils/apparmor/sandbox.py +++ b/utils/apparmor/sandbox.py @@ -101,8 +101,7 @@ def parse_args(args=None, parser=None): def gen_policy_name(binary): '''Generate a temporary policy based on the binary name''' - return "sandbox-%s%s" % (pwd.getpwuid(os.geteuid())[0], - re.sub(r'/', '_', binary)) + return "sandbox-%s%s" % (pwd.getpwuid(os.geteuid())[0], re.sub(r'/', '_', binary)) def set_environ(env): keys = env.keys() @@ -169,10 +168,7 @@ def run_sandbox(command, opt): return rc, report class SandboxXserver(): - def __init__(self, title, geometry=None, - driver=None, - xauth=None, - clipboard=False): + def __init__(self, title, geometry=None, driver=None, xauth=None, clipboard=False): self.geometry = geometry self.title = title self.pids = [] @@ -673,17 +669,14 @@ def run_xsandbox(command, opt): # first, start X if opt.xserver.lower() == "xephyr": - x = SandboxXephyr(command[0], geometry=opt.xephyr_geometry, - xauth=opt.xauthority) + x = SandboxXephyr(command[0], geometry=opt.xephyr_geometry, xauth=opt.xauthority) elif opt.xserver.lower() == "xpra3d": - x = SandboxXpra(command[0], geometry=None, - driver="xdummy", - xauth=opt.xauthority, - clipboard=opt.with_clipboard) + x = SandboxXpra( + command[0], geometry=None, driver="xdummy", xauth=opt.xauthority, + clipboard=opt.with_clipboard) else: - x = SandboxXpra(command[0], geometry=None, - xauth=opt.xauthority, - clipboard=opt.with_clipboard) + x = SandboxXpra( + command[0], geometry=None, xauth=opt.xauthority, clipboard=opt.with_clipboard) x.verify_host_setup() diff --git a/utils/test/test-change_profile.py b/utils/test/test-change_profile.py index ff41e051a..646eea525 100644 --- a/utils/test/test-change_profile.py +++ b/utils/test/test-change_profile.py @@ -144,8 +144,7 @@ class ChangeProfileFromInit(ChangeProfileTest): (ChangeProfileRule('unsafe', '/foo', '/bar') , exp(False, False, False, '' , 'unsafe', '/foo', False, '/bar' , False)), (ChangeProfileRule(None , '/foo', ChangeProfileRule.ALL) , exp(False, False, False, '' , None , '/foo', False, None , True )), (ChangeProfileRule(None , ChangeProfileRule.ALL, '/bar') , exp(False, False, False, '' , None , None , True , '/bar' , False)), - (ChangeProfileRule(None , ChangeProfileRule.ALL, - ChangeProfileRule.ALL) , exp(False, False, False, '' , None, None , True , None , True )), + (ChangeProfileRule(None , ChangeProfileRule.ALL, ChangeProfileRule.ALL), exp(False, False, False, '' , None, None , True , None , True )), ) def _run_test(self, obj, expected): diff --git a/utils/test/test-regex_matches.py b/utils/test/test-regex_matches.py index 8584ac174..f6cd39bc1 100644 --- a/utils/test/test-regex_matches.py +++ b/utils/test/test-regex_matches.py @@ -269,8 +269,7 @@ class AARegexSignal(AARegexTest): (' signal (send, receive),', (None, None, 'signal (send, receive),', '(send, receive)', None)), (' audit signal (receive),', ('audit', None, 'signal (receive),', '(receive)', None)), (' signal (send, receive) set=(usr1 usr2),', (None, None, 'signal (send, receive) set=(usr1 usr2),', '(send, receive) set=(usr1 usr2)', None)), - (' signal send set=(hup, quit) peer=/usr/sbin/daemon,', (None, None, 'signal send set=(hup, quit) peer=/usr/sbin/daemon,', - 'send set=(hup, quit) peer=/usr/sbin/daemon', None)), + (' signal send set=(hup, quit) peer=/usr/sbin/daemon,', (None, None, 'signal send set=(hup, quit) peer=/usr/sbin/daemon,', 'send set=(hup, quit) peer=/usr/sbin/daemon', None)), (' signalling,', False), (' audit signalling,', False),