/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: 2014-02-16 14:22:03 UTC
  • Revision ID: teddy@recompile.se-20140216142203-48mkrnoin5bly7l2
* mandos.lsm: Fix formatting to be acceptable by the LSM Robot.

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-2013 Teddy Hogeborn
15
 
# Copyright © 2008-2013 Björn Påhlsson
 
14
# Copyright © 2008-2014 Teddy Hogeborn
 
15
# Copyright © 2008-2014 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.1"
 
91
version = "1.6.4"
92
92
stored_state_file = "clients.pickle"
93
93
 
94
94
logger = logging.getLogger()
95
 
syslogger = (logging.handlers.SysLogHandler
96
 
             (facility = logging.handlers.SysLogHandler.LOG_DAEMON,
97
 
              address = str("/dev/log")))
 
95
syslogger = None
98
96
 
99
97
try:
100
98
    if_nametoindex = (ctypes.cdll.LoadLibrary
116
114
def initlogger(debug, level=logging.WARNING):
117
115
    """init logger and add loglevel"""
118
116
    
 
117
    syslogger = (logging.handlers.SysLogHandler
 
118
                 (facility =
 
119
                  logging.handlers.SysLogHandler.LOG_DAEMON,
 
120
                  address = str("/dev/log")))
119
121
    syslogger.setFormatter(logging.Formatter
120
122
                           ('Mandos [%(process)d]: %(levelname)s:'
121
123
                            ' %(message)s'))
172
174
    def password_encode(self, password):
173
175
        # Passphrase can not be empty and can not contain newlines or
174
176
        # NUL bytes.  So we prefix it and hex encode it.
175
 
        return b"mandos" + binascii.hexlify(password)
 
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
176
184
    
177
185
    def encrypt(self, data, password):
178
186
        passphrase = self.password_encode(password)
684
692
        # If a checker exists, make sure it is not a zombie
685
693
        try:
686
694
            pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
687
 
        except (AttributeError, OSError) as error:
688
 
            if (isinstance(error, OSError)
689
 
                and error.errno != errno.ECHILD):
690
 
                raise error
 
695
        except AttributeError:
 
696
            pass
 
697
        except OSError as error:
 
698
            if error.errno != errno.ECHILD:
 
699
                raise
691
700
        else:
692
701
            if pid:
693
702
                logger.warning("Checker was a zombie")
927
936
            # The byte_arrays option is not supported yet on
928
937
            # signatures other than "ay".
929
938
            if prop._dbus_signature != "ay":
930
 
                raise ValueError
 
939
                raise ValueError("Byte arrays not supported for non-"
 
940
                                 "'ay' signature {0!r}"
 
941
                                 .format(prop._dbus_signature))
931
942
            value = dbus.ByteArray(b''.join(chr(byte)
932
943
                                            for byte in value))
933
944
        prop(value)
1696
1707
            logger.debug("Protocol version: %r", line)
1697
1708
            try:
1698
1709
                if int(line.strip().split()[0]) > 1:
1699
 
                    raise RuntimeError
 
1710
                    raise RuntimeError(line)
1700
1711
            except (ValueError, IndexError, RuntimeError) as error:
1701
1712
                logger.error("Unknown protocol version: %s", error)
1702
1713
                return
1909
1920
    
1910
1921
    def add_pipe(self, parent_pipe, proc):
1911
1922
        """Dummy function; override as necessary"""
1912
 
        raise NotImplementedError
 
1923
        raise NotImplementedError()
1913
1924
 
1914
1925
 
1915
1926
class IPv6_TCPServer(MultiprocessingMixInWithPipe,
2252
2263
            else:
2253
2264
                raise ValueError("Unknown suffix {0!r}"
2254
2265
                                 .format(suffix))
2255
 
        except (ValueError, IndexError) as e:
 
2266
        except IndexError as e:
2256
2267
            raise ValueError(*(e.args))
2257
2268
        timevalue += delta
2258
2269
    return timevalue
2334
2345
    
2335
2346
    if options.check:
2336
2347
        import doctest
2337
 
        doctest.testmod()
2338
 
        sys.exit()
 
2348
        fail_count, test_count = doctest.testmod()
 
2349
        sys.exit(os.EX_OK if fail_count == 0 else 1)
2339
2350
    
2340
2351
    # Default values for config file for server-global settings
2341
2352
    server_defaults = { "interface": "",
2343
2354
                        "port": "",
2344
2355
                        "debug": "False",
2345
2356
                        "priority":
2346
 
                        "SECURE256:!CTYPE-X.509:+CTYPE-OPENPGP",
 
2357
                        "SECURE256:!CTYPE-X.509:+CTYPE-OPENPGP:+SIGN-RSA-SHA224:+SIGN-RSA-RMD160",
2347
2358
                        "servicename": "Mandos",
2348
2359
                        "use_dbus": "True",
2349
2360
                        "use_ipv6": "True",
2451
2462
                                        or None))
2452
2463
    if not foreground:
2453
2464
        pidfilename = "/run/mandos.pid"
 
2465
        if not os.path.isdir("/run/."):
 
2466
            pidfilename = "/var/run/mandos.pid"
2454
2467
        pidfile = None
2455
2468
        try:
2456
2469
            pidfile = open(pidfilename, "w")
2473
2486
        os.setuid(uid)
2474
2487
    except OSError as error:
2475
2488
        if error.errno != errno.EPERM:
2476
 
            raise error
 
2489
            raise
2477
2490
    
2478
2491
    if debug:
2479
2492
        # Enable all possible GnuTLS debugging
2784
2797
            else:
2785
2798
                logger.warning("Could not save persistent state:",
2786
2799
                               exc_info=e)
2787
 
                raise e
 
2800
                raise
2788
2801
        
2789
2802
        # Delete all clients, and settings from config
2790
2803
        while tcp_server.clients: