aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSARL ENR 68 <david@david.david>2015-08-28 19:58:30 +0200
committerSARL ENR 68 <david@david.david>2015-08-28 19:58:30 +0200
commit73a2738eba0625fa9befcaeed690e035b12ab91e (patch)
treedc3d89fc33da63e2e4e354a74f8c219092f32f07 /src
parent935d128177eac9d72b19c68bab8d7682a89c11d5 (diff)
downloadmsec-73a2738eba0625fa9befcaeed690e035b12ab91e.tar
msec-73a2738eba0625fa9befcaeed690e035b12ab91e.tar.gz
msec-73a2738eba0625fa9befcaeed690e035b12ab91e.tar.bz2
msec-73a2738eba0625fa9befcaeed690e035b12ab91e.tar.xz
msec-73a2738eba0625fa9befcaeed690e035b12ab91e.zip
Adaptation to python3 using 2to3-3.4 (mga#16524)
- by papoteur: https://bugs.mageia.org/attachment.cgi?id=6898
Diffstat (limited to 'src')
-rwxr-xr-xsrc/msec/compile.py2
-rwxr-xr-xsrc/msec/config.py26
-rwxr-xr-xsrc/msec/help_draksec.py18
-rwxr-xr-xsrc/msec/libmsec.py58
-rwxr-xr-xsrc/msec/man.py10
-rwxr-xr-xsrc/msec/msec.py16
-rwxr-xr-xsrc/msec/msecgui.py44
-rwxr-xr-xsrc/msec/msecperms.py18
-rwxr-xr-xsrc/msec/plugins/audit.py2
-rwxr-xr-xsrc/msec/plugins/log.py2
-rwxr-xr-xsrc/msec/plugins/msec.py6
-rwxr-xr-xsrc/msec/plugins/network.py2
-rwxr-xr-xsrc/msec/plugins/pam.py2
-rwxr-xr-xsrc/msec/plugins/sectool.py2
-rwxr-xr-xsrc/msec/plugins/sudo.py2
-rwxr-xr-xsrc/msec/tools.py6
16 files changed, 108 insertions, 108 deletions
diff --git a/src/msec/compile.py b/src/msec/compile.py
index b85e3f9..150a180 100755
--- a/src/msec/compile.py
+++ b/src/msec/compile.py
@@ -15,7 +15,7 @@ for f in sys.argv[2:]:
try:
py_compile.compile(f, f+"o", sys.argv[1] + f)
except:
- print("Cannot compile", f)
+ print(("Cannot compile", f))
pass
# compile.py ends here
diff --git a/src/msec/config.py b/src/msec/config.py
index 9f41998..8caacfc 100755
--- a/src/msec/config.py
+++ b/src/msec/config.py
@@ -38,7 +38,7 @@ SECURITYLOG = '/var/log/msec.log'
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
@@ -267,7 +267,7 @@ class MsecConfig:
def list_options(self):
"""Sorts and returns configuration parameters"""
- sortedparams = self.options.keys()
+ sortedparams = list(self.options.keys())
if sortedparams:
sortedparams.sort()
return sortedparams
@@ -280,10 +280,10 @@ class MsecConfig:
try:
fd = open(self.config, "w")
except:
- self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_value)))
+ self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_info()[1])))
return False
for comment in self.comments:
- print >>fd, comment
+ print(comment, file=fd)
# sorting keys
for option in self.list_options():
value = self.options[option]
@@ -310,7 +310,7 @@ class MsecConfig:
pass
else:
value = '"%s"' % value
- print >>fd, "%s=%s" % (option, value)
+ print("%s=%s" % (option, value), file=fd)
return True
# }}}
@@ -373,7 +373,7 @@ class ExceptionConfig:
def set(self, pos, value):
"""Sets a configuration option"""
if pos > 0:
- print "Pos: %d" % pos
+ print("Pos: %d" % pos)
self.options[pos] = value
else:
self.options.append(value)
@@ -393,17 +393,17 @@ class ExceptionConfig:
try:
fd = open(self.config, "w")
except:
- self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_value)))
+ self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_info()[1])))
return False
for comment in self.comments:
- print >>fd, comment
+ print(comment, file=fd)
# sorting keys
for option,value in self.options:
# TODO: integrate with remove()
if value == None or value == OPTION_DISABLED:
self.log.debug("Skipping %s" % option)
else:
- print >>fd, "%s %s" % (option, value)
+ print("%s %s" % (option, value), file=fd)
return True
# }}}
@@ -443,7 +443,7 @@ class PermConfig(MsecConfig):
try:
fd = open(self.config)
except:
- self.log.error(_("Unable to load configuration file %s: %s") % (self.config, Narg(sys.exc_value)))
+ self.log.error(_("Unable to load configuration file %s: %s") % (self.config, Narg(sys.exc_info()[1])))
return False
for line in fd.readlines():
line = line.strip()
@@ -488,10 +488,10 @@ class PermConfig(MsecConfig):
try:
fd = open(self.config, "w")
except:
- self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_value)))
+ self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_info()[1])))
return False
for comment in self.comments:
- print >>fd, comment
+ print(comment, file=fd)
# sorting keys
for file in self.options_order:
value = self.options[file]
@@ -509,6 +509,6 @@ class PermConfig(MsecConfig):
force = "\tforce"
else:
force = ""
- print >>fd, "%s\t%s.%s\t%s%s\t%s" % (file, user, group, perm, force, acl)
+ print("%s\t%s.%s\t%s%s\t%s" % (file, user, group, perm, force, acl), file=fd)
return True
# }}}
diff --git a/src/msec/help_draksec.py b/src/msec/help_draksec.py
index 3eb4a6d..f4536a3 100755
--- a/src/msec/help_draksec.py
+++ b/src/msec/help_draksec.py
@@ -81,20 +81,20 @@ help_wiki = open(help_wiki_file, "w")
log = Log(log_syslog=False, log_file=False)
msec = MSEC(log, plugins='plugins')
-print >>help_perl, header_perl
-print >>help_python, header_python
-print >>help_wiki, header_wiki
+print(header_perl, file=help_perl)
+print(header_python, file=help_python)
+print(header_wiki, file=help_wiki)
for variable in config.SETTINGS:
callback, params = config.SETTINGS[variable]
func = msec.get_action(callback)
if func:
- print >>help_perl, function_str_perl % (variable, func.__doc__.strip())
- print >>help_python, function_str_python % (variable, func.__doc__.strip())
- print >>help_wiki, function_str_wiki % (variable, func.__doc__.strip())
+ print(function_str_perl % (variable, func.__doc__.strip()), file=help_perl)
+ print(function_str_python % (variable, func.__doc__.strip()), file=help_python)
+ print(function_str_wiki % (variable, func.__doc__.strip()), file=help_wiki)
-print >>help_perl, footer_perl
-print >>help_python, footer_python
-print >>help_wiki, footer_wiki
+print(footer_perl, file=help_perl)
+print(footer_python, file=help_python)
+print(footer_wiki, file=help_wiki)
# draksec_help.py ends here
diff --git a/src/msec/libmsec.py b/src/msec/libmsec.py
index 593c46a..79a1ff7 100755
--- a/src/msec/libmsec.py
+++ b/src/msec/libmsec.py
@@ -40,7 +40,7 @@ import gettext
import pwd
import re
import string
-import commands
+import subprocess
import time
import stat
import traceback
@@ -57,7 +57,7 @@ from config import Narg
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
@@ -81,7 +81,7 @@ def move(old, new):
try:
os.rename(old, new)
except:
- error('rename %s %s: %s' % (old, new, str(sys.exc_value)))
+ error('rename %s %s: %s' % (old, new, str(sys.exc_info()[1])))
def substitute_re_result(res, s):
for idx in range(0, (res.lastindex or 0) + 1):
@@ -123,7 +123,7 @@ class Log:
self.syslog_h.setFormatter(formatter)
self.logger.addHandler(self.syslog_h)
except:
- print >>sys.stderr, "Logging to syslog not available: %s" % (sys.exc_value[1])
+ print("Logging to syslog not available: %s" % (sys.exc_value[1]), file=sys.stderr)
interactive = True
# log to file
@@ -134,7 +134,7 @@ class Log:
self.file_h.setFormatter(formatter)
self.logger.addHandler(self.file_h)
except:
- print >>sys.stderr, "Logging to '%s' not available: %s" % (self.log_path, sys.exc_value[1])
+ print("Logging to '%s' not available: %s" % (self.log_path, sys.exc_value[1]), file=sys.stderr)
interactive = True
# interactive logging
@@ -247,7 +247,7 @@ class ConfigFiles:
def write_files(self, commit=True):
"""Writes all files back to disk"""
- for f in self.files.values():
+ for f in list(self.files.values()):
self.log.debug("Attempting to write %s" % f.path)
if commit:
f.write()
@@ -264,7 +264,7 @@ class ConfigFiles:
s = substitute_re_result(res, a[1])
if commit:
self.log.info(_('%s modified so launched command: %s') % (Narg(f), Narg(s)))
- cmd = commands.getstatusoutput(s)
+ cmd = subprocess.getstatusoutput(s)
cmd = [0, '']
if cmd[0] == 0:
if cmd[1]:
@@ -368,7 +368,7 @@ class ConfigFile:
return link
def write(self):
- if not (type(self.path) == unicode):
+ if not (type(self.path) == str):
self.pathN = Narg(self.path)
else:
self.pathN = self.path
@@ -378,20 +378,20 @@ class ConfigFile:
try:
os.unlink(self.path)
except:
- error('unlink %s: %s' % (self.pathN, str(sys.exc_value)))
+ error('unlink %s: %s' % (self.pathN, str(sys.exc_info()[1])))
self.log.info(_('deleted %s') % (self.pathN,))
elif self.is_touched:
if os.path.exists(self.path):
try:
os.utime(self.path, None)
except:
- self.log.error('utime %s: %s' % (self.pathN, str(sys.exc_value)))
+ self.log.error('utime %s: %s' % (self.pathN, str(sys.exc_info()[1])))
elif self.suffix and os.path.exists(self.path + self.suffix):
move(self.path + self.suffix, self.path)
try:
os.utime(self.path, None)
except:
- self.log.error('utime %s: %s' % (self.pathN, str(sys.exc_value)))
+ self.log.error('utime %s: %s' % (self.pathN, str(sys.exc_info()[1])))
else:
self.lines = []
self.is_modified = 1
@@ -399,7 +399,7 @@ class ConfigFile:
file.close()
self.log.info(_('touched file %s') % (self.pathN,))
elif self.sym_link:
- if not (type(self.sym_link) == unicode):
+ if not (type(self.sym_link) == str):
self.sym_linkN = Narg(self.sym_link)
else:
self.sym_linkN = self.sym_link
@@ -414,16 +414,16 @@ class ConfigFile:
try:
os.unlink(self.path)
except:
- self.log.error('unlink %s: %s' % (self.pathN, str(sys.exc_value)))
+ self.log.error('unlink %s: %s' % (self.pathN, str(sys.exc_info()[1])))
self.log.info(_('deleted %s') % (self.pathN,))
if not done:
try:
os.symlink(self.sym_link, self.path)
except:
- self.log.error('symlink %s %s: %s' % (self.sym_linkN, self.path, str(sys.exc_value)))
+ self.log.error('symlink %s %s: %s' % (self.sym_linkN, self.path, str(sys.exc_info()[1])))
self.log.info(_('made symbolic link from %s to %s') % (self.sym_linkN, self.path))
elif self.is_moved:
- if not (type(self.suffix) == unicode):
+ if not (type(self.suffix) == str):
self.suffixN = Narg(self.suffix)
else:
self.suffixN = self.suffix
@@ -696,7 +696,7 @@ class MSEC:
self.plugins[plugin_name] = plugin
self.log.debug("Loaded plugin '%s'" % plugin_f)
except:
- self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, Narg(sys.exc_value)))
+ self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, Narg(sys.exc_info()[1])))
def reset(self):
"""Resets the configuration"""
@@ -885,7 +885,7 @@ class PERMS:
try:
os.chown(file, newuser, -1)
except:
- self.log.error(_("Error changing user on %s: %s") % (file, Narg(sys.exc_value)))
+ self.log.error(_("Error changing user on %s: %s") % (file, Narg(sys.exc_info()[1])))
else:
self.log.warn(_("Wrong owner of %s: should be %s") % (file, self.get_user_name(newuser)))
if newgroup != None:
@@ -894,7 +894,7 @@ class PERMS:
try:
os.chown(file, -1, newgroup)
except:
- self.log.error(_("Error changing group on %s: %s") % (file, Narg(sys.exc_value)))
+ self.log.error(_("Error changing group on %s: %s") % (file, Narg(sys.exc_info()[1])))
else:
self.log.warn(_("Wrong group of %s: should be %s") % (file, self.get_group_name(newgroup)))
# permissions should be last, as chown resets them
@@ -905,7 +905,7 @@ class PERMS:
try:
os.chmod(file, newperm)
except:
- self.log.error(_("Error changing permissions on %s: %s") % (file, Narg(sys.exc_value)))
+ self.log.error(_("Error changing permissions on %s: %s") % (file, Narg(sys.exc_info()[1])))
else:
self.log.warn(_("Wrong permissions of %s: should be %o") % (file, newperm))
@@ -919,7 +919,7 @@ class PERMS:
users = newacl.split(",")
for acluser in users :
if acluser.split(":")[0] == "": # clean root from list
- print acluser
+ print(acluser)
continue
# make the acl rule stick
ret = os.system('setfacl -m u:%s %s' % (acluser, file))
@@ -927,7 +927,7 @@ class PERMS:
# problem setting setfacl
self.log.error(_("Unable to add filesystem-specific ACL %s to %s") % (acluser, file))
except:
- self.log.error(_("Error changing acl on %s: %s") % (file, Narg(str(sys.exc_value))))
+ self.log.error(_("Error changing acl on %s: %s") % (file, Narg(str(sys.exc_info()[1]))))
else:
self.log.warn(_("Wrong acl of %s") % (file))
@@ -978,12 +978,12 @@ class PERMS:
mode = stat.S_IMODE(full[stat.ST_MODE])
if perm != -1 and stat.S_ISDIR(full[stat.ST_MODE]):
- if curperm & 0400:
- curperm = curperm | 0100
- if curperm & 0040:
- curperm = curperm | 0010
- if curperm & 0004:
- curperm = curperm | 0001
+ if curperm & 0o400:
+ curperm = curperm | 0o100
+ if curperm & 0o040:
+ curperm = curperm | 0o010
+ if curperm & 0o004:
+ curperm = curperm | 0o001
curuser = full[stat.ST_UID]
curgroup = full[stat.ST_GID]
@@ -1022,7 +1022,7 @@ class PERMS:
paths_to_check.extend(glob.glob(f))
paths_to_check = set(paths_to_check)
# remove unneeded entries from self.files
- for f in self.files.keys():
+ for f in list(self.files.keys()):
if f not in paths_to_check:
del self.files[f]
return self.files
@@ -1030,5 +1030,5 @@ class PERMS:
if __name__ == "__main__":
# this should never ever be run directly
- print >>sys.stderr, """This file should not be run directly."""
+ print("""This file should not be run directly.""", file=sys.stderr)
diff --git a/src/msec/man.py b/src/msec/man.py
index cc1a2f0..a937b07 100755
--- a/src/msec/man.py
+++ b/src/msec/man.py
@@ -288,12 +288,12 @@ msec = MSEC(log)
#print >>sys.stderr, dir(msec.create_server_link)
-print header
+print(header)
# sorting settings according to plugin
callbacks = []
settings_rev = {}
-for entry in config.SETTINGS.keys():
+for entry in list(config.SETTINGS.keys()):
callback, params = config.SETTINGS[entry]
callbacks.append(callback)
settings_rev[callback] = (entry, params)
@@ -304,11 +304,11 @@ for callback in callbacks:
variable, params = settings_rev[callback]
func = msec.get_action(callback)
if func:
- print function_str % (callback, func.__doc__.strip(), variable, ", ".join(params))
+ print(function_str % (callback, func.__doc__.strip(), variable, ", ".join(params)))
if variable in config.CHECKS_WITH_EXCEPTIONS:
# this check supports exceptions
- print """(This check supports exceptions via %s variable defined in \\fB/etc/security/msec/exceptions\\fP file)""" % variable
+ print("""(This check supports exceptions via %s variable defined in \\fB/etc/security/msec/exceptions\\fP file)""" % variable)
-print footer
+print(footer)
# man.py ends here
diff --git a/src/msec/msec.py b/src/msec/msec.py
index bbcd4b6..f98a793 100755
--- a/src/msec/msec.py
+++ b/src/msec/msec.py
@@ -28,14 +28,14 @@ import logging
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
# {{{ usage
def usage():
"""Prints help message"""
- print """Msec: Mageia Security Center (%s).
+ print("""Msec: Mageia Security Center (%s).
When run without parameters, msec will read the configuration from
/etc/security/msec/msec.conf, and enforce the specified security settings.
@@ -54,7 +54,7 @@ Arguments to msec:
-r, --root <path> path to use as root
-q, --quiet run quietly
-s, --save <level> save current configuration as a new security level
-""" % version
+""" % version)
# }}}
if __name__ == "__main__":
@@ -84,10 +84,10 @@ if __name__ == "__main__":
levelconf = config.load_defaults(log, level)
params = levelconf.list_options()
if not params:
- print >>sys.stderr, _("Invalid security level '%s'.") % level
+ print(_("Invalid security level '%s'.") % level, file=sys.stderr)
sys.exit(1)
for item in params:
- print "%s=%s" % (item, levelconf.get(item) )
+ print("%s=%s" % (item, levelconf.get(item) ))
sys.exit(0)
# force new level
elif o[0] == '-f' or o[0] == '--force':
@@ -111,9 +111,9 @@ if __name__ == "__main__":
# verifying use id
if os.geteuid() != 0:
- print >>sys.stderr, _("Msec: Mageia Security Center (%s)\n") % version
- print >>sys.stderr, _("Error: This application must be executed by root!")
- print >>sys.stderr, _("Run with --help to get help.")
+ print(_("Msec: Mageia Security Center (%s)\n") % version, file=sys.stderr)
+ print(_("Error: This application must be executed by root!"), file=sys.stderr)
+ print(_("Run with --help to get help."), file=sys.stderr)
sys.exit(1)
# configuring logging
diff --git a/src/msec/msecgui.py b/src/msec/msecgui.py
index d468b15..765681d 100755
--- a/src/msec/msecgui.py
+++ b/src/msec/msecgui.py
@@ -9,7 +9,7 @@ import string
import getopt
import signal
import traceback
-import Queue
+import queue
from textwrap import wrap
from threading import Thread
import time
@@ -26,9 +26,9 @@ try:
import gi
from gi.repository import GObject
from gi.repository import Pango
-except Warning, e:
- print "ERROR: %s" % e
- print "Exiting.."
+except Warning as e:
+ print("ERROR: %s" % e)
+ print("Exiting..")
sys.exit(1)
warnings.resetwarnings()
@@ -51,7 +51,7 @@ import logging
# localization
import gettext
try:
- gettext.install("msec", unicode=1)
+ gettext.install("msec", str=1)
except IOError:
_ = str
@@ -120,21 +120,21 @@ class BackgroundRunner(Thread):
def run(self):
"""Installs tomoyo policy"""
- print "Running %s" % self.program
+ print("Running %s" % self.program)
try:
res = os.system(self.program)
self.finish.put(res)
except:
- print "Aborted: %s" % sys.exc_value
+ print("Aborted: %s" % sys.exc_info()[1])
self.finish.put(-1)
class MsecGui:
"""Msec GUI"""
# common columns
- (COLUMN_LEVEL, COLUMN_LEVEL_DESCR, COLUMN_LEVEL_CURRENT) = range(3)
- (COLUMN_OPTION, COLUMN_DESCR, COLUMN_VALUE, COLUMN_CUSTOM) = range(4)
- (COLUMN_PATH, COLUMN_USER, COLUMN_GROUP, COLUMN_PERM, COLUMN_FORCE, COLUMN_ACL) = range(6)
- (COLUMN_EXCEPTION, COLUMN_EXCEPTION_VALUE, COLUMN_POS) = range(3)
+ (COLUMN_LEVEL, COLUMN_LEVEL_DESCR, COLUMN_LEVEL_CURRENT) = list(range(3))
+ (COLUMN_OPTION, COLUMN_DESCR, COLUMN_VALUE, COLUMN_CUSTOM) = list(range(4))
+ (COLUMN_PATH, COLUMN_USER, COLUMN_GROUP, COLUMN_PERM, COLUMN_FORCE, COLUMN_ACL) = list(range(6))
+ (COLUMN_EXCEPTION, COLUMN_EXCEPTION_VALUE, COLUMN_POS) = list(range(3))
def __init__(self, log, msec, perms, msecconfig, permconfig, exceptions, embed=None):
"""Initializes gui"""
@@ -239,7 +239,7 @@ class MsecGui:
banner.pack_start(label, False, False, 0)
main_vbox.pack_start(banner, False, False, 0)
except:
- print "Banner %s Not found" % ("%s/%s" % (config.MSEC_DIR, BANNER))
+ print("Banner %s Not found" % ("%s/%s" % (config.MSEC_DIR, BANNER)))
# creating main UI
self.main_notebook = Gtk.Notebook()
@@ -271,7 +271,7 @@ class MsecGui:
self.toggle_level(self.base_level)
# pending signals
- self.signals = Queue.Queue()
+ self.signals = queue.Queue()
GLib.timeout_add(500, self.check_signals)
self.window.show_all()
@@ -280,7 +280,7 @@ class MsecGui:
"""Switches to a new security level"""
iter = model.get_iter(path)
level = model.get_value(iter, self.COLUMN_LEVEL)
- print "Switching to %s" % level
+ print("Switching to %s" % level)
self.toggle_level(level, force=True)
def check_signals(self):
@@ -524,7 +524,7 @@ class MsecGui:
for option in options:
# retreiving option description
- if not config.SETTINGS.has_key(option):
+ if option not in config.SETTINGS:
# invalid option
self.log.error(_("Invalid option '%s'!") % option)
continue
@@ -585,7 +585,7 @@ class MsecGui:
banner.pack_start(image, False, False, 0)
table.attach(banner, 0, 1, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, 0, 0, 0)
except:
- print "Unable to load icon %s: %s" % (icon, sys.exc_value)
+ print("Unable to load icon %s: %s" % (icon, sys.exc_info()[1]))
label = Gtk.Label(label=text)
label.set_property("xalign", 0.0)
label.modify_font(Pango.FontDescription("12"))
@@ -693,7 +693,7 @@ class MsecGui:
with open(logfile, "r") as fd:
data = fd.readlines()
except:
- data = [_("Unable to read log file: %s") % Narg(sys.exc_value)]
+ data = [_("Unable to read log file: %s") % Narg(sys.exc_info()[1])]
dialog = Gtk.Dialog(_("Periodic check results"),
self.window,
0,
@@ -753,7 +753,7 @@ class MsecGui:
self.process_events()
# queue to signal that job is finished
- q = Queue.Queue()
+ q = queue.Queue()
if check == "manual":
program = "/usr/share/msec/security.sh"
@@ -1741,13 +1741,13 @@ class MsecGui:
# {{{ usage
def usage():
"""Prints help message"""
- print """Msec: Mandriva Security Center (%s).
+ print("""Msec: Mandriva Security Center (%s).
Arguments to msecgui:
-h, --help displays this helpful message.
-d enable debugging messages.
-e, --embedded <XID> embed in MCC.
-""" % version
+""" % version)
# }}}
if __name__ == "__main__":
@@ -1770,9 +1770,9 @@ if __name__ == "__main__":
log_level = logging.DEBUG
elif o[0] == '-e' or o[0] == '--embedded':
try:
- PlugWindowID = long(o[1])
+ PlugWindowID = int(o[1])
except:
- print >>sys.stderr, "Error: bad master window XID (%s)!" % o[1]
+ print("Error: bad master window XID (%s)!" % o[1], file=sys.stderr)
sys.exit(1)
# configuring logging
diff --git a/src/msec/msecperms.py b/src/msec/msecperms.py
index a52315a..73a3533 100755
--- a/src/msec/msecperms.py
+++ b/src/msec/msecperms.py
@@ -18,7 +18,7 @@ import getopt
import gettext
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
@@ -37,7 +37,7 @@ from libmsec import Log, PERMS
# {{{ usage
def usage():
"""Prints help message"""
- print """Msec: Mageia Security Center (%s).
+ print("""Msec: Mageia Security Center (%s).
This applications verifies and (when required) enforces permissions
of certain files and directories.
@@ -64,7 +64,7 @@ Available parameters:
will perform.
-r, --root <path> path to use as root
-q, --quiet run quietly
-""" % (version, config.PERMCONF, config.PERMCONF)
+""" % (version, config.PERMCONF, config.PERMCONF))
# }}}
if __name__ == "__main__":
@@ -93,13 +93,13 @@ if __name__ == "__main__":
permconf = config.load_default_perms(log, level)
params = permconf.list_options()
if not params:
- print >>sys.stderr, _("Invalid security level '%s'.") % level
+ print(_("Invalid security level '%s'.") % level, file=sys.stderr)
sys.exit(1)
for file in params:
user, group, perm, force = permconf.get(file)
if force:
- print "!! forcing permissions on %s" % file
- print "%s: %s.%s perm %s" % (file, user, group, perm)
+ print("!! forcing permissions on %s" % file)
+ print("%s: %s.%s perm %s" % (file, user, group, perm))
sys.exit(0)
# debugging
elif o[0] == '-d' or o[0] == '--debug':
@@ -118,9 +118,9 @@ if __name__ == "__main__":
# verifying use id
if os.geteuid() != 0:
- print >>sys.stderr, _("Msec: Mageia Security Center (%s)\n") % version
- print >>sys.stderr, _("Error: This application must be executed by root!")
- print >>sys.stderr, _("Run with --help to get help.")
+ print(_("Msec: Mageia Security Center (%s)\n") % version, file=sys.stderr)
+ print(_("Error: This application must be executed by root!"), file=sys.stderr)
+ print(_("Run with --help to get help."), file=sys.stderr)
sys.exit(1)
# configuring logging
diff --git a/src/msec/plugins/audit.py b/src/msec/plugins/audit.py
index 2a68aa2..cbc82cc 100755
--- a/src/msec/plugins/audit.py
+++ b/src/msec/plugins/audit.py
@@ -10,7 +10,7 @@ import config
import gettext
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
diff --git a/src/msec/plugins/log.py b/src/msec/plugins/log.py
index b7465c7..06d210f 100755
--- a/src/msec/plugins/log.py
+++ b/src/msec/plugins/log.py
@@ -12,7 +12,7 @@ import config
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
diff --git a/src/msec/plugins/msec.py b/src/msec/plugins/msec.py
index 16deef2..554574c 100755
--- a/src/msec/plugins/msec.py
+++ b/src/msec/plugins/msec.py
@@ -17,7 +17,7 @@ import config
import gettext
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
@@ -434,12 +434,12 @@ class msec:
liloconf = self.configfiles.get_config_file(LILOCONF)
liloconf.exists() and (liloconf.replace_line_matching('^password=', 'password="' + value + '"', 0, 1) or \
liloconf.insert_after('^boot=', 'password="' + value + '"')) and \
- Perms.chmod(liloconf.path, 0600)
+ Perms.chmod(liloconf.path, 0o600)
# TODO encrypt password in grub
menulst = self.configfiles.get_config_file(MENULST)
menulst.exists() and (menulst.replace_line_matching('^password\s', 'password "' + value + '"') or \
menulst.insert_at(0, 'password "' + value + '"')) and \
- Perms.chmod(menulst.path, 0600)
+ Perms.chmod(menulst.path, 0o600)
# TODO add yaboot support
def nopassword_loader(self):
diff --git a/src/msec/plugins/network.py b/src/msec/plugins/network.py
index cbee32d..307ea87 100755
--- a/src/msec/plugins/network.py
+++ b/src/msec/plugins/network.py
@@ -17,7 +17,7 @@ import config
import gettext
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
diff --git a/src/msec/plugins/pam.py b/src/msec/plugins/pam.py
index 353fa2a..c534d5a 100755
--- a/src/msec/plugins/pam.py
+++ b/src/msec/plugins/pam.py
@@ -14,7 +14,7 @@ import config
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
diff --git a/src/msec/plugins/sectool.py b/src/msec/plugins/sectool.py
index 392c5c3..62dc341 100755
--- a/src/msec/plugins/sectool.py
+++ b/src/msec/plugins/sectool.py
@@ -14,7 +14,7 @@ import config
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
diff --git a/src/msec/plugins/sudo.py b/src/msec/plugins/sudo.py
index b61a078..6ab68d8 100755
--- a/src/msec/plugins/sudo.py
+++ b/src/msec/plugins/sudo.py
@@ -14,7 +14,7 @@ import config
# localization
try:
- gettext.install('msec', unicode=1)
+ gettext.install('msec', str=1)
except IOError:
_ = str
diff --git a/src/msec/tools.py b/src/msec/tools.py
index cb9d1bf..61e3846 100755
--- a/src/msec/tools.py
+++ b/src/msec/tools.py
@@ -14,7 +14,7 @@ from config import Narg, SYS_ENC
# localization
import gettext
try:
- gettext.install("msec", unicode=1)
+ gettext.install("msec", str=1)
except IOError:
_ = str
@@ -32,7 +32,7 @@ def find_firewall_info(log):
if l[:3] == "-A ":
firewall_entries.append(l.strip())
except:
- log.error(_("Unable to parse firewall configuration: %s") % Narg(sys.exc_value))
+ log.error(_("Unable to parse firewall configuration: %s") % Narg(sys.exc_info()[1]))
# not find out if the firewall is enabled
if len(firewall_entries) == 0:
firewall_status = _("Disabled")
@@ -48,7 +48,7 @@ def get_updates_status(log, updatedir="/var/lib/urpmi"):
updated = time.localtime(ret[stat.ST_MTIME])
status = _("Last updated: %s") % Narg(updated_s)
except:
- log.error(_("Unable to access %s: %s") % (updatedir, Narg(sys.exc_value)))
+ log.error(_("Unable to access %s: %s") % (updatedir, Narg(sys.exc_info()[1])))
status = _("Unable to determine update status")
return status