2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

move quote_if_needed() to apparmor.rule

quote_if_needed() will be used by the upcoming ChangeProfileRule class,
which means it must be moved out of aa.py to avoid an import loop.
rule/__init__.py looks like a better place.

Also re-import quote_if_needed() into aa.py because it's still needed
there by various functions.


Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
Christian Boltz
2015-05-09 13:20:57 +02:00
parent 7167632350
commit 481de7e655
2 changed files with 8 additions and 7 deletions

View File

@@ -55,7 +55,7 @@ import apparmor.rules as aarules
from apparmor.rule.capability import CapabilityRuleset, CapabilityRule
from apparmor.rule.network import NetworkRuleset, NetworkRule
from apparmor.rule import parse_modifiers
from apparmor.rule import parse_modifiers, quote_if_needed
from apparmor.yasti import SendDataToYast, GetDataFromYast, shutdown_yast
@@ -3210,12 +3210,6 @@ def store_list_var(var, list_var, value, var_operation, filename):
raise AppArmorException(_('Unknown variable operation %(operation)s for variable %(variable)s in %(file)s') % { 'operation': var_operation, 'variable': list_var, 'file': filename })
def quote_if_needed(data):
# quote data if it contains whitespace
if ' ' in data:
data = '"' + data + '"'
return data
def escape(escape):
escape = strip_quotes(escape)
escape = re.sub('((?<!\\))"', r'\1\\', escape)

View File

@@ -316,3 +316,10 @@ def parse_modifiers(matches):
comment = ' %s' % matches.group('comment')
return (audit, deny, allow_keyword, comment)
def quote_if_needed(data):
'''quote data if it contains whitespace'''
if ' ' in data:
data = '"' + data + '"'
return data