From 865f523b1fdf0eb934e1f85a263ed52017eec243 Mon Sep 17 00:00:00 2001 From: Chris PeBenito Date: Mon, 27 Mar 2023 09:30:26 -0400 Subject: [PATCH] Set warnings filter on CLI programs. Signed-off-by: Chris PeBenito --- apol | 11 +++++++++++ sechecker | 7 +++++++ sediff | 7 +++++++ sedta | 7 +++++++ seinfo | 7 +++++++ seinfoflow | 7 +++++++ sesearch | 7 +++++++ 7 files changed, 53 insertions(+) diff --git a/apol b/apol index 4008321..12daf24 100755 --- a/apol +++ b/apol @@ -7,6 +7,7 @@ import sys import argparse import logging +import warnings from PyQt5.QtWidgets import QApplication import setools @@ -30,13 +31,23 @@ if args.debug: console_handler.setLevel(logging.DEBUG) console_handler.setFormatter( logging.Formatter('%(asctime)s|%(levelname)s|%(name)s|%(message)s')) + + if not sys.warnoptions: + warnings.simplefilter("default") + elif args.verbose: console_handler.setLevel(logging.INFO) console_handler.setFormatter(logging.Formatter('%(message)s')) + + if not sys.warnoptions: + warnings.simplefilter("default") else: console_handler.setLevel(logging.WARNING) console_handler.setFormatter(logging.Formatter('%(message)s')) + if not sys.warnoptions: + warnings.simplefilter("ignore") + logging.getLogger().addHandler(console_handler) try: diff --git a/sechecker b/sechecker index f5da803..60bdace 100755 --- a/sechecker +++ b/sechecker @@ -9,6 +9,7 @@ import argparse import sys import logging import signal +import warnings signal.signal(signal.SIGPIPE, signal.SIG_DFL) @@ -26,10 +27,16 @@ args = parser.parse_args() if args.debug: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s|%(levelname)s|%(name)s|%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") elif args.verbose: logging.basicConfig(level=logging.INFO, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") else: logging.basicConfig(level=logging.WARNING, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("ignore") try: p = setools.SELinuxPolicy(args.policy) diff --git a/sediff b/sediff index fb0d9a4..dfaa319 100755 --- a/sediff +++ b/sediff @@ -9,6 +9,7 @@ import argparse import sys import logging import signal +import warnings from itertools import chain from contextlib import suppress from typing import List @@ -115,10 +116,16 @@ all_differences = not any((args.class_, args.common, args.type_, args.attribute, if args.debug: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s|%(levelname)s|%(name)s|%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") elif args.verbose: logging.basicConfig(level=logging.INFO, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") else: logging.basicConfig(level=logging.WARNING, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("ignore") try: p1 = setools.SELinuxPolicy(args.POLICY1[0]) diff --git a/sedta b/sedta index ffd9ede..97658fb 100755 --- a/sedta +++ b/sedta @@ -8,6 +8,7 @@ import sys import argparse import logging import signal +import warnings import setools @@ -97,10 +98,16 @@ if args.target and not (args.shortest_path or args.all_paths): if args.debug: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s|%(levelname)s|%(name)s|%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") elif args.verbose: logging.basicConfig(level=logging.INFO, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") else: logging.basicConfig(level=logging.WARNING, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("ignore") try: p = setools.SELinuxPolicy(args.policy) diff --git a/seinfo b/seinfo index cecc9f0..6d551e2 100755 --- a/seinfo +++ b/seinfo @@ -11,6 +11,7 @@ import sys import logging import signal import ipaddress +import warnings from typing import Callable, List, Tuple @@ -102,10 +103,16 @@ args = parser.parse_args() if args.debug: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s|%(levelname)s|%(name)s|%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") elif args.verbose: logging.basicConfig(level=logging.INFO, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") else: logging.basicConfig(level=logging.WARNING, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("ignore") try: p = setools.SELinuxPolicy(args.policy) diff --git a/seinfoflow b/seinfoflow index 5f4e764..7dfec4a 100755 --- a/seinfoflow +++ b/seinfoflow @@ -9,6 +9,7 @@ import argparse import sys import logging import signal +import warnings from typing import Dict, Optional signal.signal(signal.SIGPIPE, signal.SIG_DFL) @@ -66,10 +67,16 @@ if args.limit_flows < 0: if args.debug: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s|%(levelname)s|%(name)s|%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") elif args.verbose: logging.basicConfig(level=logging.INFO, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") else: logging.basicConfig(level=logging.WARNING, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("ignore") booleans: Optional[Dict[str, bool]] = None if args.booleans == 'default': diff --git a/sesearch b/sesearch index f2df629..ba6a727 100755 --- a/sesearch +++ b/sesearch @@ -9,6 +9,7 @@ import argparse import sys import logging import signal +import warnings signal.signal(signal.SIGPIPE, signal.SIG_DFL) @@ -125,10 +126,16 @@ if not args.tertypes and not args.mlsrtypes and not args.rbacrtypes: if args.debug: logging.basicConfig(level=logging.DEBUG, format='%(asctime)s|%(levelname)s|%(name)s|%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") elif args.verbose: logging.basicConfig(level=logging.INFO, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("default") else: logging.basicConfig(level=logging.WARNING, format='%(message)s') + if not sys.warnoptions: + warnings.simplefilter("ignore") try: p = setools.SELinuxPolicy(args.policy)