Skip to content

Commit

Permalink
firewall: minor simplification for old firewall.xml loading
Browse files Browse the repository at this point in the history
Have `default_policy_is_accept` variable of type bool, instead of
`policy`, which is only compared to a constant value (`accept`).
Suggested by @woju
  • Loading branch information
marmarek committed Jun 26, 2017
1 parent 2b963be commit 2abdbc4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions qubes/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,7 @@ def load_v1(self, xml_root):
'''Load old (Qubes < 4.0) firewall XML format'''
policy_v1 = xml_root.get('policy')
assert policy_v1 in ('allow', 'deny')
if policy_v1 == 'allow':
policy = Action('accept')
else:
policy = Action('drop')
default_policy_is_accept = (policy_v1 == 'allow')

def _translate_action(key):
if xml_root.get(key, policy_v1) == 'allow':
Expand All @@ -524,15 +521,15 @@ def _translate_action(key):
action=_translate_action('icmp'),
proto=Proto.icmp))

if policy == Action.accept:
if default_policy_is_accept:
rule_action = Action.drop
else:
rule_action = Action.accept

for element in xml_root:
rule = Rule.from_xml_v1(element, rule_action)
self.rules.append(rule)
if policy == Action.accept:
if default_policy_is_accept:
self.rules.append(Rule(None, action='accept'))

def load_v2(self, xml_root):
Expand Down

0 comments on commit 2abdbc4

Please sign in to comment.