home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / apport / package-hooks / source_apparmor.py < prev    next >
Encoding:
Python Source  |  2009-04-08  |  1.7 KB  |  55 lines

  1. '''apport package hook for apparmor
  2.  
  3. (c) 2009 Canonical Ltd.
  4. Author: Steve Beattie <sbeattie@ubuntu.com>
  5. '''
  6.  
  7. from apport.hookutils import *
  8. from os import path
  9. import re
  10.  
  11. def recent_kernlog(pattern):
  12.     '''Extract recent messages from kern.log or message which match a regex.
  13.  
  14.        pattern should be a "re" object.  '''
  15.     lines = ''
  16.     if os.path.exists('/var/log/kern.log'):
  17.         file = '/var/log/kern.log'
  18.     elif os.path.exists('/var/log/messages'):
  19.         file = '/var/log/messages'
  20.     else:
  21.         return lines
  22.  
  23.     for line in open(file):
  24.         if pattern.search(line):
  25.             lines += line
  26.     return lines
  27.  
  28. def add_info(report):
  29.     attach_file(report, '/proc/version_signature', 'ProcVersionSignature')
  30.     attach_file(report, '/proc/cmdline', 'ProcCmdline')
  31.  
  32.     sec_re = re.compile('audit\(|apparmor|selinux|security', re.IGNORECASE)
  33.     report['KernLog'] = recent_kernlog(sec_re)
  34.  
  35.     packages=['apparmor', 'apparmor-utils', 'libapparmor1',
  36.     'libapparmor-dev', 'libapparmor-perl', 'apparmor-utils',
  37.     'apparmor-docs', 'apparmor-profiles', 'libapache2-mod-apparmor',
  38.     'libpam-apparmor', 'auditd', 'libaudit0']
  39.  
  40.     versions = ''
  41.     for package in packages:
  42.         try:
  43.             version = packaging.get_version(package)
  44.         except ValueError:
  45.             version = 'N/A'
  46.         if version is None:
  47.             version = 'N/A'
  48.         versions += '%s %s\n' % (package, version)
  49.     report['ApparmorPackages'] = versions
  50.  
  51.     # These need to be run as root
  52.     report['ApparmorStatusOutput'] = command_output('/usr/sbin/apparmor_status')
  53.     report['PstreeP'] = command_output(['/usr/bin/pstree', '-p'])
  54.     attach_file_if_exists(report, '/var/log/audit/audit.log', 'audit.log')
  55.