mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 18:17:09 +00:00
Convert to using python's modular translations interface. This allows
the utility python modules to be used inside another tool with another textdomain binding and still have the translations for that tool and the stuff internal to the apparmor module convert properly.
This commit is contained in:
parent
395c429cb1
commit
35e1936202
@ -13,13 +13,16 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.tools
|
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 = argparse.ArgumentParser(description=_('Switch the given programs to audit mode'))
|
||||||
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
||||||
parser.add_argument('-r', '--remove', action='store_true', help=_('remove audit mode'))
|
parser.add_argument('-r', '--remove', action='store_true', help=_('remove audit mode'))
|
||||||
|
@ -13,12 +13,16 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.tools
|
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 = argparse.ArgumentParser(description=_('Generate a basic AppArmor profile by guessing requirements'))
|
||||||
parser.add_argument('--force', type=str, help=_('overwrite existing profile'))
|
parser.add_argument('--force', type=str, help=_('overwrite existing profile'))
|
||||||
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
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 = apparmor.tools.aa_tools('autodep', args)
|
||||||
|
|
||||||
autodep.act()
|
autodep.act()
|
||||||
|
@ -13,12 +13,16 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.tools
|
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 = argparse.ArgumentParser(description=_('Cleanup the profiles for the given programs'))
|
||||||
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
||||||
parser.add_argument('program', type=str, nargs='+', help=_('name of program'))
|
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 = apparmor.tools.aa_tools('cleanprof', args)
|
||||||
|
|
||||||
clean.act()
|
clean.act()
|
||||||
|
@ -13,12 +13,16 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.tools
|
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 = argparse.ArgumentParser(description=_('Switch the given program to complain mode'))
|
||||||
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
||||||
parser.add_argument('-r', '--remove', action='store_true', help=_('remove complain mode'))
|
parser.add_argument('-r', '--remove', action='store_true', help=_('remove complain mode'))
|
||||||
|
@ -13,12 +13,16 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.tools
|
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 = argparse.ArgumentParser(description=_('Disable the profile for the given programs'))
|
||||||
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
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'))
|
parser.add_argument('-r', '--revert', action='store_true', help=_('enable the profile for the given programs'))
|
||||||
|
@ -13,12 +13,16 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.tools
|
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 = argparse.ArgumentParser(description=_('Switch the given program to enforce mode'))
|
||||||
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
||||||
parser.add_argument('-r', '--remove', action='store_true', help=_('switch to complain mode'))
|
parser.add_argument('-r', '--remove', action='store_true', help=_('switch to complain mode'))
|
||||||
|
@ -14,16 +14,20 @@
|
|||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
import atexit
|
import atexit
|
||||||
|
import gettext
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import init_translations
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.aa as apparmor
|
import apparmor.aa as apparmor
|
||||||
|
|
||||||
|
# setup module translations
|
||||||
|
t = gettext.translation(TRANSLATION_DOMAIN, fallback=True)
|
||||||
|
_ = t.gettext
|
||||||
|
|
||||||
def sysctl_read(path):
|
def sysctl_read(path):
|
||||||
value = None
|
value = None
|
||||||
with open(path, 'r') as f_in:
|
with open(path, 'r') as f_in:
|
||||||
|
@ -13,13 +13,17 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.aa as apparmor
|
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 = argparse.ArgumentParser(description=_('Process log entries to generate profiles'))
|
||||||
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
parser.add_argument('-d', '--dir', type=str, help=_('path to profiles'))
|
||||||
parser.add_argument('-f', '--file', type=str, help=_('path to logfile'))
|
parser.add_argument('-f', '--file', type=str, help=_('path to logfile'))
|
||||||
|
@ -13,16 +13,20 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.aa
|
import apparmor.aa
|
||||||
import apparmor.aamode
|
import apparmor.aamode
|
||||||
import apparmor.severity
|
import apparmor.severity
|
||||||
import apparmor.cleanprofile as cleanprofile
|
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 = argparse.ArgumentParser(description=_('Perform a 3way merge on the given profiles'))
|
||||||
parser.add_argument('mine', type=str, help=_('your profile'))
|
parser.add_argument('mine', type=str, help=_('your profile'))
|
||||||
parser.add_argument('base', type=str, help=_('base profile'))
|
parser.add_argument('base', type=str, help=_('base profile'))
|
||||||
|
@ -13,15 +13,19 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
import argparse
|
import argparse
|
||||||
|
import gettext
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from apparmor.common import init_translations
|
from apparmor.common import TRANSLATION_DOMAIN
|
||||||
init_translations()
|
|
||||||
|
|
||||||
import apparmor.aa as apparmor
|
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 = argparse.ArgumentParser(description=_("Lists unconfined processes having tcp or udp ports"))
|
||||||
parser.add_argument("--paranoid", action="store_true", help=_("scan all processes from /proc"))
|
parser.add_argument("--paranoid", action="store_true", help=_("scan all processes from /proc"))
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -1,24 +1,9 @@
|
|||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Copyright (C) 2011-2012 Canonical Ltd.
|
# Copyright (C) 2011-2012 Canonical Ltd.
|
||||||
# Copyright (C) 2013 Kshitij Gupta <kgupta8592@gmail.com>
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of version 2 of the GNU General Public
|
# modify it under the terms of version 2 of the GNU General Public
|
||||||
# License published by the Free Software Foundation.
|
# 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()
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
# No old version logs, only 2.6 + supported
|
# No old version logs, only 2.6 + supported
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
import gettext
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -33,13 +34,17 @@ import LibAppArmor
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from apparmor.common import (AppArmorException, error, debug, msg, cmd,
|
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)
|
hasher, open_file_write, convert_regexp, DebugLogger)
|
||||||
|
|
||||||
from apparmor.ui import *
|
from apparmor.ui import *
|
||||||
|
|
||||||
from apparmor.aamode import *
|
from apparmor.aamode import *
|
||||||
|
|
||||||
|
# setup module translations
|
||||||
|
t = gettext.translation(TRANSLATION_DOMAIN, fallback=True)
|
||||||
|
_ = t.gettext
|
||||||
|
|
||||||
# Setup logging incase of debugging is enabled
|
# Setup logging incase of debugging is enabled
|
||||||
debug_logger = DebugLogger('aa')
|
debug_logger = DebugLogger('aa')
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import codecs
|
import codecs
|
||||||
import collections
|
import collections
|
||||||
import gettext
|
|
||||||
import glob
|
import glob
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -22,6 +21,8 @@ import termios
|
|||||||
import tty
|
import tty
|
||||||
|
|
||||||
DEBUGGING = False
|
DEBUGGING = False
|
||||||
|
TRANSLATION_DOMAIN = 'apparmor-utils'
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Utility classes
|
# Utility classes
|
||||||
@ -166,13 +167,6 @@ def hasher():
|
|||||||
# Creates a dictionary for any depth and returns empty dictionary otherwise
|
# Creates a dictionary for any depth and returns empty dictionary otherwise
|
||||||
return collections.defaultdict(hasher)
|
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):
|
def convert_regexp(regexp):
|
||||||
regex_paren = re.compile('^(.*){([^}]*)}(.*)$')
|
regex_paren = re.compile('^(.*){([^}]*)}(.*)$')
|
||||||
regexp = regexp.strip()
|
regexp = regexp.strip()
|
||||||
|
@ -11,17 +11,22 @@
|
|||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
import gettext
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import LibAppArmor
|
import LibAppArmor
|
||||||
from apparmor.common import (AppArmorException, error, debug, msg,
|
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)
|
hasher, open_file_write, convert_regexp, DebugLogger)
|
||||||
|
|
||||||
from apparmor.aamode import *
|
from apparmor.aamode import *
|
||||||
|
|
||||||
|
# setup module translations
|
||||||
|
t = gettext.translation(TRANSLATION_DOMAIN, fallback=True)
|
||||||
|
_ = t.gettext
|
||||||
|
|
||||||
class ReadLog:
|
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_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=')
|
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_" + profile
|
||||||
profile = profile.replace('/', '.')
|
profile = profile.replace('/', '.')
|
||||||
full_profilename = self.profile_dir + '/' + profile
|
full_profilename = self.profile_dir + '/' + profile
|
||||||
return full_profilename
|
return full_profilename
|
||||||
|
@ -11,11 +11,16 @@
|
|||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
import gettext
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import apparmor.aa as apparmor
|
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:
|
class aa_tools:
|
||||||
def __init__(self, tool_name, args):
|
def __init__(self, tool_name, args):
|
||||||
@ -177,4 +182,4 @@ class aa_tools:
|
|||||||
apparmor.delete_symlink('disable', filename)
|
apparmor.delete_symlink('disable', filename)
|
||||||
|
|
||||||
def disable_profile(self, filename):
|
def disable_profile(self, filename):
|
||||||
apparmor.create_symlink('disable', filename)
|
apparmor.create_symlink('disable', filename)
|
||||||
|
@ -11,12 +11,17 @@
|
|||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
import gettext
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from apparmor.yasti import yastLog, SendDataToYast, GetDataFromYast
|
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
|
# Set up UI logger for separate messages from UI module
|
||||||
debug_logger = DebugLogger('UI')
|
debug_logger = DebugLogger('UI')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user