This patch changes the hasher() into a class based nested dict so it is
FAR easier to debug. Also I wrote a __str__() method that prints the
contents nice and pretty.
Using this, I managed to find other problems, possibly the one I was
trying to solve. Here is a snippet of printing out the aa[profile][hat]
which has lots of "include"s that are mixed in by mistake. This patch
does not fix this problem (see next patch in another thread), only
changes the hasher so it is easy to track.
pm DEBUG: rematchfrag, allow = allow, path =
/etc/bash.bashrc, frag = {
# this is the junk...
abstractions/gnome: {}
tunables/kernelvars: {}
local/usr.sbin.ntpd: {}
abstractions/bash: {}
tunables/multiarch: {}
tunables/global: {}
abstractions/apparmor_api/examine: {}
abstractions/private-files: {}
abstractions/base: {}
abstractions/postfix-common: {}
abstractions/mysql: {}
[...LOTS more lines...]
local/usr.sbin.smbldap-useradd: {}
include: { # probably useful
abstractions/base: True
}
allow: { # This part is useful
path_regex: {
/home/*/tmp/: {
audit: set([])
mode: set(['r', '::r'])
}
/usr/share/**/: {
audit: set([])
mode: set(['r', '::r'])
}
}
diff -ur orig/aa.py p2/aa.py
--- orig/aa.py 2014-10-16 22:03:42.000000000 +0200
+++ p2/aa.py 2014-11-24 23:01:33.955379718 +0100
@@ -86,8 +86,8 @@
### Were our
t = hasher() # dict()
transitions = hasher()
-aa = hasher() # Profiles originally in sd, replace by aa
-original_aa = hasher()
+aa = hasher("aa") # Profiles originally in sd, replace by aa
+original_aa = hasher("original_aa")
extras = hasher() # Inactive profiles from extras
### end our
log = []
diff -ur orig/common.py p2/common.py
--- orig/common.py 2014-10-14 12:54:39.000000000 +0200
+++ p2/common.py 2014-11-24 23:17:52.234275246 +0100
@@ -197,12 +197,60 @@
return ch
-def hasher():
- '''A neat alternative to perl's hash reference'''
- # Creates a dictionary for any depth and returns empty dictionary otherwise
- # WARNING: when reading non-existing sub-dicts, empty dicts will be added.
- # This might cause strange effects when using .keys()
- return collections.defaultdict(hasher)
+#def hasher():
+# '''A neat alternative to perl's hash reference'''
+# # Creates a dictionary for any depth and returns empty dictionary otherwise
+# # WARNING: when reading non-existing sub-dicts, empty dicts will be added.
+# # This might cause strange effects when using .keys()
+# return collections.defaultdict(hasher)
+
+
+hasher_debug_count = 0
+
+# same as the old hasher, but lets you customize a bit, and place breakpoints (eg. to find out where a sub-hasher is implicitly created)
+# implements __str__ for pretty debugging output
+class Hasher(dict):
+ def __init__(self, name=None):
+ self.name = name
+
+ # auto-creates the next level if it isn't there
+ def __getitem__(self, key):
+ global hasher_debug_count
+
+ if key in self:
+ return super(Hasher, self).__getitem__(key)
+ ret = Hasher("%s|%s" % (self.name, key))
+ self[key] = ret
+
+# use this to find out where something wrong was created implicitly
+# this prints things to use below to make a conditional breakpoint
+# print("pm DEBUG: name = %s, creating new hasher for key = %s" % (self.name, key))
+# this prints the trace
+# if (self.name == None and key == "/dev/tty"):
+# if hasher_debug_count == 3:
+# raise Exception("Where is this")
+# hasher_debug_count+=1
+
+ return ret
+
+ def __str__(self):
+ if len(self) == 0:
+ return "{}"
+ ret = "{\n"
+ for key in self.keys():
+ value = self[key]
+ valuestr = "%s: %s\n" % (key, value)
+
+ # indent the lines
+ for line in valuestr.splitlines(True):
+ if len(line.strip()) == 0:
+ continue
+ ret += " %s" % line
+ ret += "}"
+ return ret
+
+def hasher(name=None):
+ return Hasher(name)
def convert_regexp(regexp):
regex_paren = re.compile('^(.*){([^}]*)}(.*)$')
Only in p2: common.py.orig
--
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/apparmor