From e9b08da87ed222059c1f1f0c0de7cc760f485552 Mon Sep 17 00:00:00 2001 From: Petr Lautrbach Date: Thu, 4 Apr 2019 23:02:56 +0200 Subject: [PATCH] python/semanage: Do not traceback when the default policy is not available "import seobject" causes "import sepolicy" which crashes when the system policy is not available. It's better to provide an error message instead. Signed-off-by: Petr Lautrbach --- python/semanage/semanage | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/python/semanage/semanage b/python/semanage/semanage index 56db3e0d..4c766ae3 100644 --- a/python/semanage/semanage +++ b/python/semanage/semanage @@ -25,7 +25,6 @@ import traceback import argparse -import seobject import sys PROGNAME = "selinux-python" try: @@ -129,21 +128,6 @@ class SetImportFile(argparse.Action): sys.exit(1) setattr(namespace, self.dest, values) -# define dictonary for seobject OBEJCTS -object_dict = { - 'login': seobject.loginRecords, - 'user': seobject.seluserRecords, - 'port': seobject.portRecords, - 'module': seobject.moduleRecords, - 'interface': seobject.interfaceRecords, - 'node': seobject.nodeRecords, - 'fcontext': seobject.fcontextRecords, - 'boolean': seobject.booleanRecords, - 'permissive': seobject.permissiveRecords, - 'dontaudit': seobject.dontauditClass, - 'ibpkey': seobject.ibpkeyRecords, - 'ibendport': seobject.ibendportRecords -} def generate_custom_usage(usage_text, usage_dict): # generate custom usage from given text and dictonary @@ -608,6 +592,7 @@ def setupInterfaceParser(subparsers): def handleModule(args): + import seobject OBJECT = seobject.moduleRecords(args) if args.action_add: OBJECT.add(args.action_add[0], args.priority) @@ -846,6 +831,7 @@ def mkargv(line): def handleImport(args): + import seobject trans = seobject.semanageRecords(args) trans.start() @@ -887,6 +873,25 @@ def createCommandParser(): #To add a new subcommand define the parser for it in a function above and call it here. subparsers = commandParser.add_subparsers(dest='subcommand') subparsers.required = True + + import seobject + # define dictonary for seobject OBEJCTS + global object_dict + object_dict = { + 'login': seobject.loginRecords, + 'user': seobject.seluserRecords, + 'port': seobject.portRecords, + 'module': seobject.moduleRecords, + 'interface': seobject.interfaceRecords, + 'node': seobject.nodeRecords, + 'fcontext': seobject.fcontextRecords, + 'boolean': seobject.booleanRecords, + 'permissive': seobject.permissiveRecords, + 'dontaudit': seobject.dontauditClass, + 'ibpkey': seobject.ibpkeyRecords, + 'ibendport': seobject.ibendportRecords + } + setupImportParser(subparsers) setupExportParser(subparsers) setupLoginParser(subparsers) -- 2.22.0