diff --git a/Tools/aa-audit b/Tools/aa-audit index 92138dc4d..5bf1d038e 100644 --- a/Tools/aa-audit +++ b/Tools/aa-audit @@ -13,13 +13,16 @@ # # ---------------------------------------------------------------------- import argparse +import gettext import traceback -from apparmor.common import init_translations -init_translations() - +from apparmor.common import TRANSLATION_DOMAIN import apparmor.tools +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_('Switch the given programs to audit mode')) parser.add_argument('-d', '--dir', type=str, help=_('path to profiles')) parser.add_argument('-r', '--remove', action='store_true', help=_('remove audit mode')) diff --git a/Tools/aa-autodep b/Tools/aa-autodep index 8f789db14..bc4ec1466 100644 --- a/Tools/aa-autodep +++ b/Tools/aa-autodep @@ -13,12 +13,16 @@ # # ---------------------------------------------------------------------- import argparse +import gettext -from apparmor.common import init_translations -init_translations() +from apparmor.common import TRANSLATION_DOMAIN import apparmor.tools +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_('Generate a basic AppArmor profile by guessing requirements')) parser.add_argument('--force', type=str, help=_('overwrite existing profile')) parser.add_argument('-d', '--dir', type=str, help=_('path to profiles')) @@ -27,4 +31,4 @@ args = parser.parse_args() autodep = apparmor.tools.aa_tools('autodep', args) -autodep.act() \ No newline at end of file +autodep.act() diff --git a/Tools/aa-cleanprof b/Tools/aa-cleanprof index cc70f0aec..75e42b9c7 100644 --- a/Tools/aa-cleanprof +++ b/Tools/aa-cleanprof @@ -13,12 +13,16 @@ # # ---------------------------------------------------------------------- import argparse +import gettext -from apparmor.common import init_translations -init_translations() +from apparmor.common import TRANSLATION_DOMAIN import apparmor.tools +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_('Cleanup the profiles for the given programs')) parser.add_argument('-d', '--dir', type=str, help=_('path to profiles')) parser.add_argument('program', type=str, nargs='+', help=_('name of program')) @@ -27,4 +31,4 @@ args = parser.parse_args() clean = apparmor.tools.aa_tools('cleanprof', args) -clean.act() \ No newline at end of file +clean.act() diff --git a/Tools/aa-complain b/Tools/aa-complain index 34c04cf8c..efba399fa 100644 --- a/Tools/aa-complain +++ b/Tools/aa-complain @@ -13,12 +13,16 @@ # # ---------------------------------------------------------------------- import argparse +import gettext -from apparmor.common import init_translations -init_translations() +from apparmor.common import TRANSLATION_DOMAIN import apparmor.tools +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_('Switch the given program to complain mode')) parser.add_argument('-d', '--dir', type=str, help=_('path to profiles')) parser.add_argument('-r', '--remove', action='store_true', help=_('remove complain mode')) diff --git a/Tools/aa-disable b/Tools/aa-disable index 67dd46226..878eb7ef8 100644 --- a/Tools/aa-disable +++ b/Tools/aa-disable @@ -13,12 +13,16 @@ # # ---------------------------------------------------------------------- import argparse +import gettext -from apparmor.common import init_translations -init_translations() +from apparmor.common import TRANSLATION_DOMAIN import apparmor.tools +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_('Disable the profile for the given programs')) parser.add_argument('-d', '--dir', type=str, help=_('path to profiles')) parser.add_argument('-r', '--revert', action='store_true', help=_('enable the profile for the given programs')) diff --git a/Tools/aa-enforce b/Tools/aa-enforce index 8d427f155..790bcac57 100644 --- a/Tools/aa-enforce +++ b/Tools/aa-enforce @@ -13,12 +13,16 @@ # # ---------------------------------------------------------------------- import argparse +import gettext -from apparmor.common import init_translations -init_translations() +from apparmor.common import TRANSLATION_DOMAIN import apparmor.tools +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_('Switch the given program to enforce mode')) parser.add_argument('-d', '--dir', type=str, help=_('path to profiles')) parser.add_argument('-r', '--remove', action='store_true', help=_('switch to complain mode')) diff --git a/Tools/aa-genprof b/Tools/aa-genprof index 292cdaf83..9918ff46f 100644 --- a/Tools/aa-genprof +++ b/Tools/aa-genprof @@ -14,16 +14,20 @@ # ---------------------------------------------------------------------- import argparse import atexit +import gettext import os import re import subprocess import sys from apparmor.common import init_translations -init_translations() import apparmor.aa as apparmor +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + def sysctl_read(path): value = None with open(path, 'r') as f_in: diff --git a/Tools/aa-logprof b/Tools/aa-logprof index 26f892f39..c95a2ace3 100644 --- a/Tools/aa-logprof +++ b/Tools/aa-logprof @@ -13,13 +13,17 @@ # # ---------------------------------------------------------------------- import argparse +import gettext import os -from apparmor.common import init_translations -init_translations() +from apparmor.common import TRANSLATION_DOMAIN import apparmor.aa as apparmor +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_('Process log entries to generate profiles')) parser.add_argument('-d', '--dir', type=str, help=_('path to profiles')) parser.add_argument('-f', '--file', type=str, help=_('path to logfile')) diff --git a/Tools/aa-mergeprof b/Tools/aa-mergeprof index 255c96dea..90001d1dc 100644 --- a/Tools/aa-mergeprof +++ b/Tools/aa-mergeprof @@ -13,16 +13,20 @@ # # ---------------------------------------------------------------------- import argparse +import gettext import sys -from apparmor.common import init_translations -init_translations() +from apparmor.common import TRANSLATION_DOMAIN import apparmor.aa import apparmor.aamode import apparmor.severity import apparmor.cleanprofile as cleanprofile +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_('Perform a 3way merge on the given profiles')) parser.add_argument('mine', type=str, help=_('your profile')) parser.add_argument('base', type=str, help=_('base profile')) diff --git a/Tools/aa-unconfined b/Tools/aa-unconfined index ca17a03e4..d1adbfa2a 100644 --- a/Tools/aa-unconfined +++ b/Tools/aa-unconfined @@ -13,15 +13,19 @@ # # ---------------------------------------------------------------------- import argparse +import gettext import os import re import sys -from apparmor.common import init_translations -init_translations() +from apparmor.common import TRANSLATION_DOMAIN import apparmor.aa as apparmor +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + parser = argparse.ArgumentParser(description=_("Lists unconfined processes having tcp or udp ports")) parser.add_argument("--paranoid", action="store_true", help=_("scan all processes from /proc")) args = parser.parse_args() diff --git a/apparmor/__init__.py b/apparmor/__init__.py index 3f93c45c8..94f439406 100644 --- a/apparmor/__init__.py +++ b/apparmor/__init__.py @@ -1,24 +1,9 @@ # ------------------------------------------------------------------ # # Copyright (C) 2011-2012 Canonical Ltd. -# Copyright (C) 2013 Kshitij Gupta # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License published by the Free Software Foundation. # # ------------------------------------------------------------------ -import gettext -import locale - -def init_localisation(): - locale.setlocale(locale.LC_ALL, '') - #If a correct locale has been provided set filename else let an IOError be raised - filename = '/usr/share/locale/%s/LC_MESSAGES/apparmor-utils.mo' % locale.getlocale()[0] - try: - trans = gettext.GNUTranslations(open(filename, 'rb')) - except IOError: - trans = gettext.NullTranslations() - trans.install() - -init_localisation() diff --git a/apparmor/aa.py b/apparmor/aa.py index 2cbaed4ed..64cc6ff3b 100644 --- a/apparmor/aa.py +++ b/apparmor/aa.py @@ -13,6 +13,7 @@ # ---------------------------------------------------------------------- # No old version logs, only 2.6 + supported from __future__ import with_statement +import gettext import inspect import os import re @@ -33,13 +34,17 @@ import LibAppArmor from copy import deepcopy from apparmor.common import (AppArmorException, error, debug, msg, cmd, - open_file_read, valid_path, + open_file_read, valid_path, TRANSLATION_DOMAIN, hasher, open_file_write, convert_regexp, DebugLogger) from apparmor.ui import * from apparmor.aamode import * +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + # Setup logging incase of debugging is enabled debug_logger = DebugLogger('aa') diff --git a/apparmor/common.py b/apparmor/common.py index 51fbe857d..66f556938 100644 --- a/apparmor/common.py +++ b/apparmor/common.py @@ -11,7 +11,6 @@ from __future__ import print_function import codecs import collections -import gettext import glob import logging import os @@ -22,6 +21,8 @@ import termios import tty DEBUGGING = False +TRANSLATION_DOMAIN = 'apparmor-utils' + # # Utility classes @@ -166,13 +167,6 @@ def hasher(): # Creates a dictionary for any depth and returns empty dictionary otherwise return collections.defaultdict(hasher) -def init_translations(domain='apparmor-utils'): - """Installs the translations for the given domain, defaults to apparmor-utils domain""" - #Setup Translation - gettext.translation(domain, fallback=True) - gettext.install(domain) - - def convert_regexp(regexp): regex_paren = re.compile('^(.*){([^}]*)}(.*)$') regexp = regexp.strip() diff --git a/apparmor/logparser.py b/apparmor/logparser.py index 1db358ceb..47c5caa83 100644 --- a/apparmor/logparser.py +++ b/apparmor/logparser.py @@ -11,17 +11,22 @@ # GNU General Public License for more details. # # ---------------------------------------------------------------------- +import gettext import os import re import sys import time import LibAppArmor from apparmor.common import (AppArmorException, error, debug, msg, - open_file_read, valid_path, + open_file_read, valid_path, TRANSLATION_DOMAIN, hasher, open_file_write, convert_regexp, DebugLogger) from apparmor.aamode import * +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext + class ReadLog: RE_LOG_v2_6_syslog = re.compile('kernel:\s+(\[[\d\.\s]+\]\s+)?type=\d+\s+audit\([\d\.\:]+\):\s+apparmor=') RE_LOG_v2_6_audit = re.compile('type=AVC\s+(msg=)?audit\([\d\.\:]+\):\s+apparmor=') @@ -392,4 +397,4 @@ class ReadLog: profile = "profile_" + profile profile = profile.replace('/', '.') full_profilename = self.profile_dir + '/' + profile - return full_profilename \ No newline at end of file + return full_profilename diff --git a/apparmor/tools.py b/apparmor/tools.py index ac06f708a..347b9087f 100644 --- a/apparmor/tools.py +++ b/apparmor/tools.py @@ -11,11 +11,16 @@ # GNU General Public License for more details. # # ---------------------------------------------------------------------- +import gettext import os import sys import apparmor.aa as apparmor -from apparmor.common import user_perm +from apparmor.common import user_perm, TRANSLATION_DOMAIN + +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext class aa_tools: def __init__(self, tool_name, args): @@ -177,4 +182,4 @@ class aa_tools: apparmor.delete_symlink('disable', filename) def disable_profile(self, filename): - apparmor.create_symlink('disable', filename) \ No newline at end of file + apparmor.create_symlink('disable', filename) diff --git a/apparmor/ui.py b/apparmor/ui.py index df9b892cc..7a11f7288 100644 --- a/apparmor/ui.py +++ b/apparmor/ui.py @@ -11,12 +11,17 @@ # GNU General Public License for more details. # # ---------------------------------------------------------------------- +import gettext import sys import os import re from apparmor.yasti import yastLog, SendDataToYast, GetDataFromYast -from apparmor.common import readkey, AppArmorException, DebugLogger, msg +from apparmor.common import readkey, AppArmorException, DebugLogger, msg, TRANSLATION_DOMAIN + +# setup module translations +t = gettext.translation(TRANSLATION_DOMAIN, fallback=True) +_ = t.gettext # Set up UI logger for separate messages from UI module debug_logger = DebugLogger('UI')