2013-08-26 00:23:59 +05:30
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
import apparmor.aa as apparmor
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Cleanup the profiles for the given programs')
|
|
|
|
parser.add_argument('-d', type=str, help='path to profiles')
|
|
|
|
parser.add_argument('program', type=str, nargs='+', help='name of program')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
profiling = args.program
|
|
|
|
profiledir = args.d
|
|
|
|
|
|
|
|
if profiledir:
|
|
|
|
apparmor.profile_dir = apparmor.get_full_path(profiledir)
|
|
|
|
if not os.path.isdir(apparmor.profile_dir):
|
2013-08-26 00:41:15 +05:30
|
|
|
raise apparmor.AppArmorException("%s is not a directory."%profiledir)
|
2013-08-26 00:23:59 +05:30
|
|
|
|
2013-08-26 00:41:15 +05:30
|
|
|
for p in sorted(profiling):
|
2013-08-26 00:23:59 +05:30
|
|
|
if not p:
|
|
|
|
continue
|
|
|
|
|
|
|
|
program = None
|
|
|
|
if os.path.exists(p):
|
|
|
|
program = apparmor.get_full_path(p).strip()
|
|
|
|
else:
|
|
|
|
which = apparmor.which(p)
|
|
|
|
if which:
|
|
|
|
program = apparmor.get_full_path(which)
|
|
|
|
|
|
|
|
if os.path.exists(program):
|
|
|
|
apparmor.read_profiles()
|
|
|
|
filename = apparmor.get_profile_filename(program)
|
2013-08-26 00:41:15 +05:30
|
|
|
if filename:
|
|
|
|
apparmor.write_profile_ui_feedback(program)
|
|
|
|
apparmor.reload_base(program)
|
2013-08-26 00:23:59 +05:30
|
|
|
else:
|
2013-08-26 00:41:15 +05:30
|
|
|
raise apparmor.AppArmorException(_('The profile for %s does not exists. Nothing to clean.')%p)
|
|
|
|
|