mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 16:35:02 +01:00
[20/38] Re-add '(N)ew' to aa-logprof
This brings back the edit option for the path of file rules. Also add it to aa-mergeprof to keep ask_the_questions() in sync. Note: aa-mergeprof will ask about path mismatchs basically always. That's because AARE is too careful on the matching - something to be fixed in a later patch. Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
parent
0fe9ed8960
commit
875f9cf7d9
2 changed files with 47 additions and 0 deletions
|
@ -738,6 +738,28 @@ class Merge(object):
|
|||
globbed_rule_obj.glob_ext()
|
||||
options, default_option = add_to_options(options, globbed_rule_obj.get_raw())
|
||||
|
||||
elif ans == 'CMD_NEW':
|
||||
if not re_match_include(selection):
|
||||
edit_rule_obj = selection_to_rule_obj(rule_obj, selection)
|
||||
prompt, oldpath = edit_rule_obj.edit_header()
|
||||
|
||||
newpath = aaui.UI_GetString(prompt, oldpath)
|
||||
if newpath:
|
||||
try:
|
||||
input_matches_path = rule_obj.validate_edit(newpath) # note that we check against the original rule_obj here, not edit_rule_obj (which might be based on a globbed path)
|
||||
except AppArmorException:
|
||||
aaui.UI_Important(_('The path you entered is invalid (not starting with / or a variable)!'))
|
||||
continue
|
||||
|
||||
if not input_matches_path:
|
||||
ynprompt = _('The specified path does not match this log entry:\n\n Log Entry: %(path)s\n Entered Path: %(ans)s\nDo you really want to use this path?') % { 'path': oldpath, 'ans': newpath }
|
||||
key = aaui.UI_YesNo(ynprompt, 'n')
|
||||
if key == 'n':
|
||||
continue
|
||||
|
||||
edit_rule_obj.store_edit(newpath)
|
||||
options, default_option = add_to_options(options, edit_rule_obj.get_raw())
|
||||
|
||||
else:
|
||||
done = False
|
||||
|
||||
|
|
|
@ -1621,6 +1621,28 @@ def ask_the_questions():
|
|||
globbed_rule_obj.glob_ext()
|
||||
options, default_option = add_to_options(options, globbed_rule_obj.get_raw())
|
||||
|
||||
elif ans == 'CMD_NEW':
|
||||
if not re_match_include(selection):
|
||||
edit_rule_obj = selection_to_rule_obj(rule_obj, selection)
|
||||
prompt, oldpath = edit_rule_obj.edit_header()
|
||||
|
||||
newpath = aaui.UI_GetString(prompt, oldpath)
|
||||
if newpath:
|
||||
try:
|
||||
input_matches_path = rule_obj.validate_edit(newpath) # note that we check against the original rule_obj here, not edit_rule_obj (which might be based on a globbed path)
|
||||
except AppArmorException:
|
||||
aaui.UI_Important(_('The path you entered is invalid (not starting with / or a variable)!'))
|
||||
continue
|
||||
|
||||
if not input_matches_path:
|
||||
ynprompt = _('The specified path does not match this log entry:\n\n Log Entry: %(path)s\n Entered Path: %(ans)s\nDo you really want to use this path?') % { 'path': oldpath, 'ans': newpath }
|
||||
key = aaui.UI_YesNo(ynprompt, 'n')
|
||||
if key == 'n':
|
||||
continue
|
||||
|
||||
edit_rule_obj.store_edit(newpath)
|
||||
options, default_option = add_to_options(options, edit_rule_obj.get_raw())
|
||||
|
||||
else:
|
||||
done = False
|
||||
# END of code (mostly) shared with aa-mergeprof
|
||||
|
@ -1940,6 +1962,9 @@ def available_buttons(rule_obj):
|
|||
if rule_obj.can_glob_ext:
|
||||
buttons += ['CMD_GLOBEXT']
|
||||
|
||||
if rule_obj.can_edit:
|
||||
buttons += ['CMD_NEW']
|
||||
|
||||
if rule_obj.audit:
|
||||
buttons += ['CMD_AUDIT_OFF']
|
||||
else:
|
||||
|
|
Loading…
Add table
Reference in a new issue