From 71fc6d7b6eae8a53f8684d65003bcd8988daa978 Mon Sep 17 00:00:00 2001 From: Eugeni Dodonov Date: Thu, 5 Feb 2009 21:22:28 +0000 Subject: Implemented quiet mode. --- src/msec/libmsec.py | 11 ++++++++++- src/msec/msec.py | 10 +++++++--- src/msec/msecperms.py | 10 +++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/msec/libmsec.py b/src/msec/libmsec.py index 6786519..b32d5b4 100755 --- a/src/msec/libmsec.py +++ b/src/msec/libmsec.py @@ -187,7 +187,8 @@ class Log: log_facility=SysLogHandler.LOG_AUTHPRIV, syslog_address="/dev/log", log_path="/var/log/msec.log", - interactive=True): + interactive=True, + quiet=False): self.log_facility = log_facility self.log_path = log_path @@ -197,6 +198,8 @@ class Log: # common logging stuff self.logger = logging.getLogger(app_name) + self.quiet = quiet + # syslog if log_syslog: try: @@ -230,6 +233,9 @@ class Log: def info(self, message): """Informative message (normal msec operation)""" + if self.quiet: + # skip informative messages in quiet mode + return if self.buffer: self.buffer["info"].append(message) else: @@ -258,6 +264,9 @@ class Log: def warn(self, message): """Warning message (slight security change, permissions change, etc)""" + if self.quiet: + # skip warning messages in quiet mode + return if self.buffer: self.buffer["warn"].append(message) else: diff --git a/src/msec/msec.py b/src/msec/msec.py index ef93281..0e8e5ce 100755 --- a/src/msec/msec.py +++ b/src/msec/msec.py @@ -53,6 +53,7 @@ Arguments to msec: actions. Use this to see what operations msec will perform. -r, --root path to use as root + -q, --quiet run quietly """ % version # }}} @@ -62,10 +63,11 @@ if __name__ == "__main__": log_level = logging.INFO commit = True root = '' + quiet = False # parse command line try: - opt, args = getopt.getopt(sys.argv[1:], 'hl:f:dpr:', ['help', 'list=', 'force=', 'debug', 'pretend', 'root=']) + opt, args = getopt.getopt(sys.argv[1:], 'hl:f:dpr:q', ['help', 'list=', 'force=', 'debug', 'pretend', 'root=', 'quiet']) except getopt.error: usage() sys.exit(1) @@ -99,6 +101,8 @@ if __name__ == "__main__": # check-only mode elif o[0] == '-p' or o[0] == '--pretend': commit = False + elif o[0] == '-q' or o[0] == '--quiet': + quiet = True # verifying use id if os.geteuid() != 0: @@ -111,11 +115,11 @@ if __name__ == "__main__": interactive = sys.stdin.isatty() if interactive: # logs to file and to terminal - log = Log(log_path="%s%s" % (root, config.SECURITYLOG), interactive=True, log_syslog=False, log_level=log_level) + log = Log(log_path="%s%s" % (root, config.SECURITYLOG), interactive=True, log_syslog=False, log_level=log_level, quiet=quiet) else: # TODO: review logging messages #log_level = logging.WARN - log = Log(log_path="%s%s" % (root, config.SECURITYLOG), interactive=False, log_syslog=False, log_level=log_level) + log = Log(log_path="%s%s" % (root, config.SECURITYLOG), interactive=False, log_syslog=False, log_level=log_level, quiet=quiet) # loading initial config msec_config = config.MsecConfig(log, config="%s%s" % (root, config.SECURITYCONF)) diff --git a/src/msec/msecperms.py b/src/msec/msecperms.py index f6744ea..5a948e2 100755 --- a/src/msec/msecperms.py +++ b/src/msec/msecperms.py @@ -65,6 +65,7 @@ Available parameters: actions. Use this to see what operations msec will perform. -r, --root path to use as root + -q, --quiet run quietly """ % (version, config.PERMCONF, config.PERMCONF) # }}} @@ -74,11 +75,12 @@ if __name__ == "__main__": force_level = False commit = True enforce = False + quiet = False root = '' # parse command line try: - opt, args = getopt.getopt(sys.argv[1:], 'hel:f:dpr:', ['help', 'enforce', 'list=', 'force=', 'debug', 'pretend', 'root=']) + opt, args = getopt.getopt(sys.argv[1:], 'hel:f:dpr:q', ['help', 'enforce', 'list=', 'force=', 'debug', 'pretend', 'root=', 'quiet']) except getopt.error: usage() sys.exit(1) @@ -118,6 +120,8 @@ if __name__ == "__main__": # check-only mode elif o[0] == '-p' or o[0] == '--pretend': commit = False + elif o[0] == '-q' or o[0] == '--quiet': + quiet = True # verifying use id if os.geteuid() != 0: @@ -130,10 +134,10 @@ if __name__ == "__main__": interactive = sys.stdin.isatty() if interactive: # logs to file and to terminal - log = Log(log_path="%s%s" % (root, config.SECURITYLOG), interactive=True, log_syslog=False, log_level=log_level) + log = Log(log_path="%s%s" % (root, config.SECURITYLOG), interactive=True, log_syslog=False, log_level=log_level, quiet=quiet) else: log_level = logging.WARN - log = Log(log_path="%s%s" % (root, config.SECURITYLOG), interactive=True, log_syslog=False, log_level=log_level) + log = Log(log_path="%s%s" % (root, config.SECURITYLOG), interactive=True, log_syslog=False, log_level=log_level, quiet=quiet) # loading permissions permconf = config.PermConfig(log, config="%s%s" % (root, config.PERMCONF)) -- cgit v1.2.1