From 6e9dd6494b628639620523f48aeaf2aceed11584 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Thu, 7 May 2020 01:06:05 +0200 Subject: [PATCH 1/2] Split off UI_ShowFile() from UI_Changes UI_ShowFile() is more generic and can be used to display various (text) files, not only diffs. (cherry picked from commit bb3803b931683c841768ba6256c29e16bebd2eeb, adjusted for 2.13 branch) --- utils/apparmor/ui.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/utils/apparmor/ui.py b/utils/apparmor/ui.py index cdb712f3d..11108be0c 100644 --- a/utils/apparmor/ui.py +++ b/utils/apparmor/ui.py @@ -254,14 +254,17 @@ def UI_Changes(oldprofile, newprofile, comments=False): else: difftemp = generate_diff_with_comments(oldprofile, newprofile) header = 'View Changes with comments' - if UI_mode == 'json': - jsonout = {'dialog': 'changes', 'header':header, 'filename': difftemp.name} - write_json(jsonout) - json_response('changes')["response"] # wait for response to delay deletion of difftemp (and ignore response content) - else: - subprocess.call('less %s' % difftemp.name, shell=True) + UI_ShowFile(header, difftemp.name) difftemp.close() +def UI_ShowFile(header, filename): + if UI_mode == 'json': + jsonout = {'dialog': 'changes', 'header': header, 'filename': filename} + write_json(jsonout) + json_response('changes')["response"] # wait for response to delay deletion of filename (and ignore response content) + else: + subprocess.call('less %s' % filename, shell=True) + CMDS = {'CMD_ALLOW': _('(A)llow'), 'CMD_OTHER': _('(M)ore'), 'CMD_AUDIT_NEW': _('Audi(t)'), From da07cdf79c5643878712e5a6e0fb6d7aadf71c61 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Wed, 6 May 2020 23:20:07 +0200 Subject: [PATCH 2/2] Fix showing the local inactive profile in json mode When aa-genprof proposes a local inactive profile, it had a hardcoded call to 'less' to display that profile. Unsurprisingly, this doesn't work in JSON mode and breaks YaST (luckily it's only a case of "the button doesn't work"). References: https://bugzilla.opensuse.org/show_bug.cgi?id=1171315 (cherry picked from commit 68a258b0064d98c376631fa27904a5be1a2e0044) (cherry picked from commit cb95e9a2568b19e2e7601c0af363e0605a6889d9) --- utils/apparmor/aa.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/apparmor/aa.py b/utils/apparmor/aa.py index 3b5ad68f2..92be3592a 100644 --- a/utils/apparmor/aa.py +++ b/utils/apparmor/aa.py @@ -559,8 +559,7 @@ def get_profile(prof_name): p = profile_hash[options[arg]] q.selected = options.index(options[arg]) if ans == 'CMD_VIEW_PROFILE': - pager = get_pager() - subprocess.call([pager, orig_filename]) + aaui.UI_ShowFile(uname, orig_filename) elif ans == 'CMD_USE_PROFILE': if p['profile_type'] == 'INACTIVE_LOCAL': profile_data = p['profile_data']