=== modified file 'mandos' --- mandos 2012-11-13 21:45:10 +0000 +++ mandos 2013-05-22 20:00:18 +0000 @@ -440,6 +440,7 @@ runtime_expansions: Allowed attributes for runtime expansion. expires: datetime.datetime(); time (UTC) when a client will be disabled, or None + server_settings: The server_settings dict from main() """ runtime_expansions = ("approval_delay", "approval_duration", @@ -520,8 +521,11 @@ return settings - def __init__(self, settings, name = None): + def __init__(self, settings, name = None, server_settings=None): self.name = name + if server_settings is None: + server_settings = {} + self.server_settings = server_settings # adding all client settings for setting, value in settings.iteritems(): setattr(self, setting, value) @@ -711,9 +715,18 @@ # in normal mode, that is already done by daemon(), # and in debug mode we don't want to. (Stdin is # always replaced by /dev/null.) + # The exception is when not debugging but nevertheless + # running in the foreground; use the previously + # created wnull. + popen_args = {} + if (not self.server_settings["debug"] + and self.server_settings["foreground"]): + popen_args.update({"stdout": wnull, + "stderr": wnull }) self.checker = subprocess.Popen(command, close_fds=True, - shell=True, cwd="/") + shell=True, cwd="/", + **popen_args) except OSError as error: logger.error("Failed to start subprocess", exc_info=error) @@ -2524,6 +2537,14 @@ old_client_settings = {} clients_data = {} + # This is used to redirect stdout and stderr for checker processes + global wnull + wnull = open(os.devnull, "w") # A writable /dev/null + # Only used if server is running in foreground but not in debug + # mode + if debug or not foreground: + wnull.close() + # Get client data and settings from last running state. if server_settings["restore"]: try: @@ -2545,6 +2566,10 @@ with PGPEngine() as pgp: for client_name, client in clients_data.iteritems(): + # Skip removed clients + if client_name not in client_settings: + continue + # Decide which value to use after restoring saved state. # We have three different values: Old config file, # new config file, and saved state. @@ -2612,7 +2637,8 @@ # Create all client objects for client_name, client in clients_data.iteritems(): tcp_server.clients[client_name] = client_class( - name = client_name, settings = client) + name = client_name, settings = client, + server_settings = server_settings) if not tcp_server.clients: logger.warning("No clients defined") @@ -2701,6 +2727,7 @@ service.cleanup() multiprocessing.active_children() + wnull.close() if not (tcp_server.clients or client_settings): return @@ -2718,7 +2745,7 @@ # A list of attributes that can not be pickled # + secret. exclude = set(("bus", "changedstate", "secret", - "checker")) + "checker", "server_settings")) for name, typ in (inspect.getmembers (dbus.service.Object)): exclude.add(name) === modified file 'mandos-monitor' --- mandos-monitor 2012-11-14 21:03:24 +0000 +++ mandos-monitor 2013-05-22 20:00:18 +0000 @@ -25,8 +25,10 @@ from __future__ import (division, absolute_import, print_function, unicode_literals) - -from future_builtins import * +try: + from future_builtins import * +except ImportError: + pass import sys import os @@ -38,14 +40,18 @@ import urwid from dbus.mainloop.glib import DBusGMainLoop -import gobject +try: + import gobject +except ImportError: + from gi.repository import GObject as gobject import dbus -import UserList - import locale +if sys.version_info[0] == 2: + str = unicode + locale.setlocale(locale.LC_ALL, '') import logging @@ -57,14 +63,6 @@ client_interface = domain + '.Mandos.Client' version = "1.6.0" -# Always run in monochrome mode -urwid.curses_display.curses.has_colors = lambda : False - -# Urwid doesn't support blinking, but we want it. Since we have no -# use for underline on its own, we make underline also always blink. -urwid.curses_display.curses.A_UNDERLINE |= ( - urwid.curses_display.curses.A_BLINK) - def isoformat_to_datetime(iso): "Parse an ISO 8601 date string to a datetime.datetime()" if not iso: @@ -210,7 +208,7 @@ to log in the future. """ #self.logger('Client {0} started checker "{1}"' # .format(self.properties["Name"], - # unicode(command))) + # str(command))) pass def got_secret(self): @@ -279,7 +277,7 @@ message = "Approval in {0}. (d)eny?" else: message = "Denial in {0}. (a)pprove?" - message = message.format(unicode(timer).rsplit(".", 1)[0]) + message = message.format(str(timer).rsplit(".", 1)[0]) self.using_timer(True) elif self.properties["LastCheckerStatus"] != 0: # When checker has failed, show timer until client expires @@ -293,7 +291,7 @@ datetime.timedelta()) message = ('A checker has failed! Time until client' ' gets disabled: {0}' - .format(unicode(timer).rsplit(".", 1)[0])) + .format(str(timer).rsplit(".", 1)[0])) self.using_timer(True) else: message = "enabled" @@ -382,7 +380,7 @@ def property_changed(self, property=None, **kwargs): """Call self.update() if old value is not new value. This overrides the method from MandosClientPropertyCache""" - property_name = unicode(property) + property_name = str(property) old_value = self.properties.get(property_name) super(MandosClientWidget, self).property_changed( property=property, **kwargs) @@ -415,20 +413,21 @@ ("normal", "default", "default", None), ("bold", - "default", "default", "bold"), + "bold", "default", "bold"), ("underline-blink", - "default", "default", "underline"), + "underline,blink", "default", "underline,blink"), ("standout", - "default", "default", "standout"), + "standout", "default", "standout"), ("bold-underline-blink", - "default", "default", ("bold", "underline")), + "bold,underline,blink", "default", "bold,underline,blink"), ("bold-standout", - "default", "default", ("bold", "standout")), + "bold,standout", "default", "bold,standout"), ("underline-blink-standout", - "default", "default", ("underline", "standout")), + "underline,blink,standout", "default", + "underline,blink,standout"), ("bold-underline-blink-standout", - "default", "default", ("bold", "underline", - "standout")), + "bold,underline,blink,standout", "default", + "bold,underline,blink,standout"), )) if urwid.supports_unicode(): @@ -508,7 +507,7 @@ self.log_visible = not self.log_visible self.rebuild() #self.log_message("Log visibility changed to: " - # + unicode(self.log_visible)) + # + str(self.log_visible)) def change_log_display(self): """Change type of log display. @@ -554,7 +553,7 @@ if path is None: path = client.proxy.object_path self.clients_dict[path] = client - self.clients.sort(None, lambda c: c.properties["Name"]) + self.clients.sort(key=lambda c: c.properties["Name"]) self.refresh() def remove_client(self, client, path=None): @@ -562,11 +561,6 @@ if path is None: path = client.proxy.object_path del self.clients_dict[path] - if not self.clients_dict: - # Work around bug in Urwid 0.9.8.3 - if a SimpleListWalker - # is completely emptied, we need to recreate it. - self.clients = urwid.SimpleListWalker([]) - self.rebuild() self.refresh() def refresh(self): @@ -606,7 +600,7 @@ self.client_not_found, dbus_interface=server_interface, byte_arrays=True)) - for path, client in mandos_clients.iteritems(): + for path, client in mandos_clients.items(): client_proxy_object = self.bus.get_object(self.busname, path) self.add_client(MandosClientWidget(server_proxy_object @@ -724,7 +718,7 @@ ui.run() except KeyboardInterrupt: ui.screen.stop() -except Exception, e: - ui.log_message(unicode(e)) +except Exception as e: + ui.log_message(str(e)) ui.screen.stop() raise