[apparmor] [patch] fix and improve recursive_print()

Steve Beattie steve at nxnw.org
Fri Nov 14 23:53:50 UTC 2014


On Tue, Nov 11, 2014 at 08:09:35PM +0100, Christian Boltz wrote:
> Hello,
> 
> Am Dienstag, 11. November 2014 schrieb Christian Boltz:
> > this patch for recursive_print() in common.py fixes printing dicts
> > with py3. It also replaced the tabs() lambda function with a plain
> > string, and the brace() lambda function with a simple formatstring to
> > make the code easier to understand.
> 
> The updated version adds support for nested lists - for the start of 
> each list, print a *. Without that, you get a long list of items without 
> an indicator if/when a new parent list starts.

Acked-by: Steve Beattie <steve at nxnw.org>, though maybe instead of just
printing a '*', printing an opening '[' and closing ']', instead?

Also, what do think of the following patch to get rid of output like:

          - <apparmor.rules.Raw_DBUS_Rule object at 0x7fb797813da0>

when handling any of the raw rules objects (formatting improvements
welcome)?

Signed-off-by: Steve Beattie <steve at nxnw.org>
---
 utils/apparmor/common.py |    3 +++
 utils/apparmor/rules.py  |    6 ++++++
 2 files changed, 9 insertions(+)

Index: b/utils/apparmor/common.py
===================================================================
--- a/utils/apparmor/common.py
+++ b/utils/apparmor/common.py
@@ -20,6 +20,7 @@ import subprocess
 import sys
 import termios
 import tty
+import apparmor.rules as rules
 
 DEBUGGING = False
 
@@ -96,6 +97,8 @@ def recursive_print(src, dpth = 0, key =
             empty = False
         if empty:
             print (tabs + '[--- empty ---]')
+    elif isinstance(src, rules._Raw_Rule):
+        src.recursive_print(dpth)
     else:
         if key:
             print (tabs + '%s = %s' % (key, src))
Index: b/utils/apparmor/rules.py
===================================================================
--- a/utils/apparmor/rules.py
+++ b/utils/apparmor/rules.py
@@ -56,6 +56,12 @@ class _Raw_Rule(object):
                            'deny '  if self.deny else '',
                            self.rule)
 
+    def recursive_print(self, depth):
+        tabs = ' ' * depth * 4
+        print('%saudit = %s' % (tabs, self.audit))
+        print('%sdeny = %s' % (tabs, self.deny))
+        print('%sraw rule = %s' % (tabs, self.rule))
+
 class Raw_DBUS_Rule(_Raw_Rule):
     pass
 
-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20141114/724dfad3/attachment-0001.pgp>


More information about the AppArmor mailing list