/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2013-06-23 15:13:06 UTC
  • Revision ID: teddy@recompile.se-20130623151306-3y4zwy76d95hcvpq
* mandos: Bug fix: Make boolean options work from the config file
          again.
          Bug fix: Make --no-ipv6 work again.
          Bug fix: Add extra magic to GnuTLS priority to make it work
          with current version of GnuTLS.
* mandos-options.xml (priority): Document new default value.
* mandos.conf (priority): - '' -
* plugins.d/mandos-client.xml (EXAMPLE): Minor grammar fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
# "AvahiService" class, and some lines in "main".
12
12
13
13
# Everything else is
14
 
# Copyright © 2008-2014 Teddy Hogeborn
15
 
# Copyright © 2008-2014 Björn Påhlsson
 
14
# Copyright © 2008-2012 Teddy Hogeborn
 
15
# Copyright © 2008-2012 Björn Påhlsson
16
16
17
17
# This program is free software: you can redistribute it and/or modify
18
18
# it under the terms of the GNU General Public License as published by
88
88
    except ImportError:
89
89
        SO_BINDTODEVICE = None
90
90
 
91
 
version = "1.6.4"
 
91
version = "1.6.0"
92
92
stored_state_file = "clients.pickle"
93
93
 
94
94
logger = logging.getLogger()
95
 
syslogger = None
 
95
syslogger = (logging.handlers.SysLogHandler
 
96
             (facility = logging.handlers.SysLogHandler.LOG_DAEMON,
 
97
              address = str("/dev/log")))
96
98
 
97
99
try:
98
100
    if_nametoindex = (ctypes.cdll.LoadLibrary
114
116
def initlogger(debug, level=logging.WARNING):
115
117
    """init logger and add loglevel"""
116
118
    
117
 
    syslogger = (logging.handlers.SysLogHandler
118
 
                 (facility =
119
 
                  logging.handlers.SysLogHandler.LOG_DAEMON,
120
 
                  address = str("/dev/log")))
121
119
    syslogger.setFormatter(logging.Formatter
122
120
                           ('Mandos [%(process)d]: %(levelname)s:'
123
121
                            ' %(message)s'))
174
172
    def password_encode(self, password):
175
173
        # Passphrase can not be empty and can not contain newlines or
176
174
        # NUL bytes.  So we prefix it and hex encode it.
177
 
        encoded = b"mandos" + binascii.hexlify(password)
178
 
        if len(encoded) > 2048:
179
 
            # GnuPG can't handle long passwords, so encode differently
180
 
            encoded = (b"mandos" + password.replace(b"\\", b"\\\\")
181
 
                       .replace(b"\n", b"\\n")
182
 
                       .replace(b"\0", b"\\x00"))
183
 
        return encoded
 
175
        return b"mandos" + binascii.hexlify(password)
184
176
    
185
177
    def encrypt(self, data, password):
186
178
        passphrase = self.password_encode(password)
692
684
        # If a checker exists, make sure it is not a zombie
693
685
        try:
694
686
            pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
695
 
        except AttributeError:
696
 
            pass
697
 
        except OSError as error:
698
 
            if error.errno != errno.ECHILD:
699
 
                raise
 
687
        except (AttributeError, OSError) as error:
 
688
            if (isinstance(error, OSError)
 
689
                and error.errno != errno.ECHILD):
 
690
                raise error
700
691
        else:
701
692
            if pid:
702
693
                logger.warning("Checker was a zombie")
936
927
            # The byte_arrays option is not supported yet on
937
928
            # signatures other than "ay".
938
929
            if prop._dbus_signature != "ay":
939
 
                raise ValueError("Byte arrays not supported for non-"
940
 
                                 "'ay' signature {0!r}"
941
 
                                 .format(prop._dbus_signature))
 
930
                raise ValueError
942
931
            value = dbus.ByteArray(b''.join(chr(byte)
943
932
                                            for byte in value))
944
933
        prop(value)
1352
1341
                                       *args, **kwargs)
1353
1342
    
1354
1343
    def start_checker(self, *args, **kwargs):
1355
 
        old_checker_pid = getattr(self.checker, "pid", None)
 
1344
        old_checker = self.checker
 
1345
        if self.checker is not None:
 
1346
            old_checker_pid = self.checker.pid
 
1347
        else:
 
1348
            old_checker_pid = None
1356
1349
        r = Client.start_checker(self, *args, **kwargs)
1357
1350
        # Only if new checker process was started
1358
1351
        if (self.checker is not None
1703
1696
            logger.debug("Protocol version: %r", line)
1704
1697
            try:
1705
1698
                if int(line.strip().split()[0]) > 1:
1706
 
                    raise RuntimeError(line)
 
1699
                    raise RuntimeError
1707
1700
            except (ValueError, IndexError, RuntimeError) as error:
1708
1701
                logger.error("Unknown protocol version: %s", error)
1709
1702
                return
1916
1909
    
1917
1910
    def add_pipe(self, parent_pipe, proc):
1918
1911
        """Dummy function; override as necessary"""
1919
 
        raise NotImplementedError()
 
1912
        raise NotImplementedError
1920
1913
 
1921
1914
 
1922
1915
class IPv6_TCPServer(MultiprocessingMixInWithPipe,
2259
2252
            else:
2260
2253
                raise ValueError("Unknown suffix {0!r}"
2261
2254
                                 .format(suffix))
2262
 
        except IndexError as e:
 
2255
        except (ValueError, IndexError) as e:
2263
2256
            raise ValueError(*(e.args))
2264
2257
        timevalue += delta
2265
2258
    return timevalue
2341
2334
    
2342
2335
    if options.check:
2343
2336
        import doctest
2344
 
        fail_count, test_count = doctest.testmod()
2345
 
        sys.exit(os.EX_OK if fail_count == 0 else 1)
 
2337
        doctest.testmod()
 
2338
        sys.exit()
2346
2339
    
2347
2340
    # Default values for config file for server-global settings
2348
2341
    server_defaults = { "interface": "",
2350
2343
                        "port": "",
2351
2344
                        "debug": "False",
2352
2345
                        "priority":
2353
 
                        "SECURE256:!CTYPE-X.509:+CTYPE-OPENPGP:+SIGN-RSA-SHA224:+SIGN-RSA-RMD160",
 
2346
                        "SECURE256:!CTYPE-X.509:+CTYPE-OPENPGP:+SIGN-RSA-SHA224",
2354
2347
                        "servicename": "Mandos",
2355
2348
                        "use_dbus": "True",
2356
2349
                        "use_ipv6": "True",
2457
2450
                              socketfd=(server_settings["socket"]
2458
2451
                                        or None))
2459
2452
    if not foreground:
2460
 
        pidfilename = "/run/mandos.pid"
2461
 
        if not os.path.isdir("/run/."):
2462
 
            pidfilename = "/var/run/mandos.pid"
 
2453
        pidfilename = "/var/run/mandos.pid"
2463
2454
        pidfile = None
2464
2455
        try:
2465
2456
            pidfile = open(pidfilename, "w")
2482
2473
        os.setuid(uid)
2483
2474
    except OSError as error:
2484
2475
        if error.errno != errno.EPERM:
2485
 
            raise
 
2476
            raise error
2486
2477
    
2487
2478
    if debug:
2488
2479
        # Enable all possible GnuTLS debugging
2793
2784
            else:
2794
2785
                logger.warning("Could not save persistent state:",
2795
2786
                               exc_info=e)
2796
 
                raise
 
2787
                raise e
2797
2788
        
2798
2789
        # Delete all clients, and settings from config
2799
2790
        while tcp_server.clients: