Merge lp:~mdeslaur/apport/machooks into lp:~apport-hackers/apport/trunk

Proposed by Marc Deslauriers
Status: Merged
Merged at revision: 1915
Proposed branch: lp:~mdeslaur/apport/machooks
Merge into: lp:~apport-hackers/apport/trunk
Diff against target: 55 lines (+33/-2)
1 file modified
apport/hookutils.py (+33/-2)
To merge this branch: bzr merge lp:~mdeslaur/apport/machooks
Reviewer Review Type Date Requested Status
Martin Pitt (community) Approve
Review via email: mp+67716@code.launchpad.net

Description of the change

This adds MAC (AppArmor) hooks into Apport so they can be removed from each individual package that ships an AppArmor profile.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apport/hookutils.py'
2--- apport/hookutils.py 2011-06-30 10:00:29 +0000
3+++ apport/hookutils.py 2011-07-12 15:33:13 +0000
4@@ -335,12 +335,19 @@
5
6 def recent_syslog(pattern):
7 '''Extract recent messages from syslog which match a regex.
8-
9+
10+ pattern should be a "re" object.
11+ '''
12+ return recent_logfile('/var/log/syslog', pattern)
13+
14+def recent_logfile(logfile, pattern):
15+ '''Extract recent messages from a logfile which match a regex.
16+
17 pattern should be a "re" object.
18 '''
19 lines = ''
20 try:
21- for line in open('/var/log/syslog'):
22+ for line in open(logfile):
23 if pattern.search(line):
24 lines += line
25 except IOError:
26@@ -512,6 +519,30 @@
27 'cupsys-driver-gutenprint', 'gimp-gutenprint', 'gutenprint-doc',
28 'gutenprint-locales', 'system-config-printer-common', 'kdeprint')
29
30+def attach_mac_events(report):
31+ '''Attach MAC information and events to the report.'''
32+ mac_regex = 'audit\(|apparmor|selinux|security'
33+ mac_re = re.compile(mac_regex, re.IGNORECASE)
34+ aa_denied_regex = 'apparmor="DENIED"'
35+ aa_denied_re = re.compile(aa_denied_regex, re.IGNORECASE)
36+
37+ if os.path.exists('/var/log/kern.log'):
38+ report['KernLog'] = recent_logfile('/var/log/kern.log',mac_re)
39+ elif os.path.exists('/var/log/messages'):
40+ report['KernLog'] = recent_logfile('/var/log/messages',mac_re)
41+
42+ if os.path.exists('/var/log/audit/audit.log'):
43+ attach_root_command_outputs(report, {'AuditLog': 'grep "' + mac_regex + '" /var/log/audit/audit.log'})
44+
45+ attach_file(report, '/proc/version_signature', 'ProcVersionSignature')
46+ attach_file(report, '/proc/cmdline', 'ProcCmdline')
47+
48+ if re.search(aa_denied_re, report.get('KernLog', '')) or re.search(aa_denied_re, report.get('AuditLog', '')):
49+ tags = report.get('Tags', '')
50+ if tags:
51+ tags += ' '
52+ report['Tags'] = tags + 'apparmor'
53+
54 def attach_related_packages(report, packages):
55 '''Attach version information for related packages
56

Subscribers

People subscribed via source and target branches