=== modified file 'Makefile' --- Makefile 2011-10-15 16:48:03 +0000 +++ Makefile 2011-10-22 00:46:35 +0000 @@ -260,12 +260,6 @@ # Run the server with a local config run-server: confdir/mandos.conf confdir/clients.conf - @echo "#################################################################" - @echo "# NOTE: Please IGNORE the error about \"Could not open file #" - @echo "# u'/var/run/mandos.pid'\" - it is harmless and is caused by #" - @echo "# the server not running as root. Do NOT run \"make run-server\" #" - @echo "# server as root if you didn't also unpack and compile it thus. #" - @echo "#################################################################" ./mandos --debug --no-dbus --configdir=confdir $(SERVERARGS) # Used by run-server === modified file 'TODO' --- TODO 2011-11-09 11:16:17 +0000 +++ TODO 2011-11-09 17:16:03 +0000 @@ -52,8 +52,6 @@ [[info:standards:Option%20Table][Table of Long Options]] ** TODO Implement --socket [[info:standards:Option%20Table][Table of Long Options]] -** TODO Date+time on console log messages :BUGS: - Is this the default? ** TODO [#C] DBusServiceObjectUsingSuper ** TODO [#B] Global enable/disable flag ** TODO [#B] By-client countdown on secrets given === modified file 'mandos' --- mandos 2011-11-09 11:16:17 +0000 +++ mandos 2011-11-09 17:16:03 +0000 @@ -87,10 +87,9 @@ version = "1.4.1" +logger = logging.getLogger() stored_state_path = "/var/lib/mandos/clients.pickle" -#logger = logging.getLogger('mandos') -logger = logging.Logger('mandos') syslogger = (logging.handlers.SysLogHandler (facility = logging.handlers.SysLogHandler.LOG_DAEMON, address = str("/dev/log"))) @@ -100,11 +99,13 @@ logger.addHandler(syslogger) console = logging.StreamHandler() -console.setFormatter(logging.Formatter('%(name)s [%(process)d]:' +console.setFormatter(logging.Formatter('%(asctime)s %(name)s' + ' [%(process)d]:' ' %(levelname)s:' ' %(message)s')) logger.addHandler(console) + class AvahiError(Exception): def __init__(self, value, *args, **kwargs): self.value = value @@ -168,10 +169,6 @@ .GetAlternativeServiceName(self.name)) logger.info("Changing Zeroconf service name to %r ...", self.name) - syslogger.setFormatter(logging.Formatter - ('Mandos (%s) [%%(process)d]:' - ' %%(levelname)s: %%(message)s' - % self.name)) self.remove() try: self.add() @@ -197,7 +194,7 @@ avahi.DBUS_INTERFACE_ENTRY_GROUP) self.entry_group_state_changed_match = ( self.group.connect_to_signal( - 'StateChanged', self .entry_group_state_changed)) + 'StateChanged', self.entry_group_state_changed)) logger.debug("Adding Zeroconf service '%s' of type '%s' ...", self.name, self.type) self.group.AddService( @@ -269,6 +266,15 @@ self.server_state_changed) self.server_state_changed(self.server.GetState()) +class AvahiServiceToSyslog(AvahiService): + def rename(self): + """Add the new name to the syslog messages""" + ret = AvahiService.rename(self) + syslogger.setFormatter(logging.Formatter + ('Mandos (%s) [%%(process)d]:' + ' %%(levelname)s: %%(message)s' + % self.name)) + return ret def _timedelta_to_milliseconds(td): "Convert a datetime.timedelta() to milliseconds" @@ -304,8 +310,9 @@ interval: datetime.timedelta(); How often to start a new checker last_approval_request: datetime.datetime(); (UTC) or None last_checked_ok: datetime.datetime(); (UTC) or None - Last_checker_status: integer between 0 and 255 reflecting exit status - of last checker. -1 reflect crashed checker. + last_checker_status: integer between 0 and 255 reflecting exit status + of last checker. -1 reflect crashed checker, + or None. last_enabled: datetime.datetime(); (UTC) name: string; from the config file, used in log messages and D-Bus identifiers @@ -368,7 +375,7 @@ self.last_approval_request = None self.last_enabled = datetime.datetime.utcnow() self.last_checked_ok = None - self.last_checker_status = 0 + self.last_checker_status = None self.timeout = string_to_delta(config["timeout"]) self.extended_timeout = string_to_delta(config ["extended_timeout"]) @@ -400,11 +407,10 @@ if not name.startswith("_"): self.client_structure.append(name) - + # Send notice to process children that client state has changed def send_changedstate(self): - self.changedstate.acquire() - self.changedstate.notify_all() - self.changedstate.release() + with self.changedstate: + self.changedstate.notify_all() def enable(self): """Start this client's checker and timeout hooks""" @@ -587,7 +593,7 @@ # Encrypts a client secret and stores it in a varible encrypted_secret def encrypt_secret(self, key): - # Encryption-key need to be specific size, so we hash inputed key + # Encryption-key need to be of a specific size, so we hash inputed key hasheng = hashlib.sha256() hasheng.update(key) encryptionkey = hasheng.digest() @@ -606,7 +612,7 @@ # Decrypt a encrypted client secret def decrypt_secret(self, key): - # Decryption-key need to be specific size, so we hash inputed key + # Decryption-key need to be of a specific size, so we hash inputed key hasheng = hashlib.sha256() hasheng.update(key) encryptionkey = hasheng.digest() @@ -1916,7 +1922,7 @@ parser.add_argument("--no-ipv6", action="store_false", dest="use_ipv6", help="Do not use IPv6") parser.add_argument("--no-restore", action="store_false", - dest="restore", help="Do not restore old state", + dest="restore", help="Do not restore stored state", default=True) options = parser.parse_args() @@ -2038,14 +2044,13 @@ raise error if not debug and not debuglevel: - syslogger.setLevel(logging.WARNING) - console.setLevel(logging.WARNING) + logger.setLevel(logging.WARNING) if debuglevel: level = getattr(logging, debuglevel.upper()) - syslogger.setLevel(level) - console.setLevel(level) + logger.setLevel(level) if debug: + logger.setLevel(logging.DEBUG) # Enable all possible GnuTLS debugging # "Use a log level over 10 to enable all debugging options." @@ -2092,9 +2097,10 @@ server_settings["use_dbus"] = False tcp_server.use_dbus = False protocol = avahi.PROTO_INET6 if use_ipv6 else avahi.PROTO_INET - service = AvahiService(name = server_settings["servicename"], - servicetype = "_mandos._tcp", - protocol = protocol, bus = bus) + service = AvahiServiceToSyslog(name = + server_settings["servicename"], + servicetype = "_mandos._tcp", + protocol = protocol, bus = bus) if server_settings["interface"]: service.interface = (if_nametoindex (str(server_settings["interface"]))) @@ -2127,6 +2133,7 @@ old_client_settings = {} clients_data = [] + # Get client data and settings from last running state. if server_settings["restore"]: try: with open(stored_state_path, "rb") as stored_state: @@ -2329,8 +2336,8 @@ if use_dbus: # Emit D-Bus signal mandos_dbus_service.ClientRemoved(client - .dbus_object_path, - client.name) + .dbus_object_path, + client.name) client_settings.clear() atexit.register(cleanup) === modified file 'mandos-options.xml' --- mandos-options.xml 2011-11-09 11:16:17 +0000 +++ mandos-options.xml 2011-11-09 17:16:03 +0000 @@ -88,7 +88,7 @@ This option controls whether the server will restore any state from - last time it ran. The Default is to try restore last state. + last time it ran. Default is to try restore last state. === modified file 'mandos.xml' --- mandos.xml 2011-11-09 11:16:17 +0000 +++ mandos.xml 2011-11-09 17:16:03 +0000 @@ -2,7 +2,7 @@ - + %common; ]> @@ -518,9 +518,6 @@ Debug mode is conflated with running in the foreground. - The console log messages do not show a time stamp. - - This server does not check the expire time of clients’ OpenPGP keys.