/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-12-31 16:02:18 UTC
  • Revision ID: teddy@recompile.se-20131231160218-plmmb0o0iifkd5l2
Specify BusName in systemd service file.

* mandos.service (BusName): Uncommented.

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-2013 Teddy Hogeborn
 
15
# Copyright © 2008-2013 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.5"
 
91
version = "1.6.2"
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
 
    global syslogger
118
 
    syslogger = (logging.handlers.SysLogHandler
119
 
                 (facility =
120
 
                  logging.handlers.SysLogHandler.LOG_DAEMON,
121
 
                  address = str("/dev/log")))
122
119
    syslogger.setFormatter(logging.Formatter
123
120
                           ('Mandos [%(process)d]: %(levelname)s:'
124
121
                            ' %(message)s'))
937
934
            # The byte_arrays option is not supported yet on
938
935
            # signatures other than "ay".
939
936
            if prop._dbus_signature != "ay":
940
 
                raise ValueError("Byte arrays not supported for non-"
941
 
                                 "'ay' signature {0!r}"
942
 
                                 .format(prop._dbus_signature))
 
937
                raise ValueError
943
938
            value = dbus.ByteArray(b''.join(chr(byte)
944
939
                                            for byte in value))
945
940
        prop(value)
1353
1348
                                       *args, **kwargs)
1354
1349
    
1355
1350
    def start_checker(self, *args, **kwargs):
1356
 
        old_checker_pid = getattr(self.checker, "pid", None)
 
1351
        old_checker = self.checker
 
1352
        if self.checker is not None:
 
1353
            old_checker_pid = self.checker.pid
 
1354
        else:
 
1355
            old_checker_pid = None
1357
1356
        r = Client.start_checker(self, *args, **kwargs)
1358
1357
        # Only if new checker process was started
1359
1358
        if (self.checker is not None
2337
2336
                        help="Directory to save/restore state in")
2338
2337
    parser.add_argument("--foreground", action="store_true",
2339
2338
                        help="Run in foreground", default=None)
2340
 
    parser.add_argument("--no-zeroconf", action="store_false",
2341
 
                        dest="zeroconf", help="Do not use Zeroconf",
2342
 
                        default=None)
2343
2339
    
2344
2340
    options = parser.parse_args()
2345
2341
    
2346
2342
    if options.check:
2347
2343
        import doctest
2348
 
        fail_count, test_count = doctest.testmod()
2349
 
        sys.exit(os.EX_OK if fail_count == 0 else 1)
 
2344
        doctest.testmod()
 
2345
        sys.exit()
2350
2346
    
2351
2347
    # Default values for config file for server-global settings
2352
2348
    server_defaults = { "interface": "",
2363
2359
                        "socket": "",
2364
2360
                        "statedir": "/var/lib/mandos",
2365
2361
                        "foreground": "False",
2366
 
                        "zeroconf": "True",
2367
2362
                        }
2368
2363
    
2369
2364
    # Parse config file for server-global settings
2396
2391
    for option in ("interface", "address", "port", "debug",
2397
2392
                   "priority", "servicename", "configdir",
2398
2393
                   "use_dbus", "use_ipv6", "debuglevel", "restore",
2399
 
                   "statedir", "socket", "foreground", "zeroconf"):
 
2394
                   "statedir", "socket", "foreground"):
2400
2395
        value = getattr(options, option)
2401
2396
        if value is not None:
2402
2397
            server_settings[option] = value
2407
2402
            server_settings[option] = unicode(server_settings[option])
2408
2403
    # Force all boolean options to be boolean
2409
2404
    for option in ("debug", "use_dbus", "use_ipv6", "restore",
2410
 
                   "foreground", "zeroconf"):
 
2405
                   "foreground"):
2411
2406
        server_settings[option] = bool(server_settings[option])
2412
2407
    # Debug implies foreground
2413
2408
    if server_settings["debug"]:
2416
2411
    
2417
2412
    ##################################################################
2418
2413
    
2419
 
    if (not server_settings["zeroconf"] and
2420
 
        not (server_settings["port"]
2421
 
             or server_settings["socket"] != "")):
2422
 
            parser.error("Needs port or socket to work without"
2423
 
                         " Zeroconf")
2424
 
    
2425
2414
    # For convenience
2426
2415
    debug = server_settings["debug"]
2427
2416
    debuglevel = server_settings["debuglevel"]
2430
2419
    stored_state_path = os.path.join(server_settings["statedir"],
2431
2420
                                     stored_state_file)
2432
2421
    foreground = server_settings["foreground"]
2433
 
    zeroconf = server_settings["zeroconf"]
2434
2422
    
2435
2423
    if debug:
2436
2424
        initlogger(debug, logging.DEBUG)
2457
2445
    global mandos_dbus_service
2458
2446
    mandos_dbus_service = None
2459
2447
    
2460
 
    socketfd = None
2461
 
    if server_settings["socket"] != "":
2462
 
        socketfd = server_settings["socket"]
2463
2448
    tcp_server = MandosServer((server_settings["address"],
2464
2449
                               server_settings["port"]),
2465
2450
                              ClientHandler,
2469
2454
                              gnutls_priority=
2470
2455
                              server_settings["priority"],
2471
2456
                              use_dbus=use_dbus,
2472
 
                              socketfd=socketfd)
 
2457
                              socketfd=(server_settings["socket"]
 
2458
                                        or None))
2473
2459
    if not foreground:
2474
2460
        pidfilename = "/run/mandos.pid"
2475
2461
        if not os.path.isdir("/run/."):
2545
2531
            use_dbus = False
2546
2532
            server_settings["use_dbus"] = False
2547
2533
            tcp_server.use_dbus = False
2548
 
    if zeroconf:
2549
 
        protocol = avahi.PROTO_INET6 if use_ipv6 else avahi.PROTO_INET
2550
 
        service = AvahiServiceToSyslog(name =
2551
 
                                       server_settings["servicename"],
2552
 
                                       servicetype = "_mandos._tcp",
2553
 
                                       protocol = protocol, bus = bus)
2554
 
        if server_settings["interface"]:
2555
 
            service.interface = (if_nametoindex
2556
 
                                 (str(server_settings["interface"])))
 
2534
    protocol = avahi.PROTO_INET6 if use_ipv6 else avahi.PROTO_INET
 
2535
    service = AvahiServiceToSyslog(name =
 
2536
                                   server_settings["servicename"],
 
2537
                                   servicetype = "_mandos._tcp",
 
2538
                                   protocol = protocol, bus = bus)
 
2539
    if server_settings["interface"]:
 
2540
        service.interface = (if_nametoindex
 
2541
                             (str(server_settings["interface"])))
2557
2542
    
2558
2543
    global multiprocessing_manager
2559
2544
    multiprocessing_manager = multiprocessing.Manager()
2753
2738
    
2754
2739
    def cleanup():
2755
2740
        "Cleanup function; run on exit"
2756
 
        if zeroconf:
2757
 
            service.cleanup()
 
2741
        service.cleanup()
2758
2742
        
2759
2743
        multiprocessing.active_children()
2760
2744
        wnull.close()
2839
2823
    tcp_server.server_activate()
2840
2824
    
2841
2825
    # Find out what port we got
2842
 
    if zeroconf:
2843
 
        service.port = tcp_server.socket.getsockname()[1]
 
2826
    service.port = tcp_server.socket.getsockname()[1]
2844
2827
    if use_ipv6:
2845
2828
        logger.info("Now listening on address %r, port %d,"
2846
2829
                    " flowinfo %d, scope_id %d",
2852
2835
    #service.interface = tcp_server.socket.getsockname()[3]
2853
2836
    
2854
2837
    try:
2855
 
        if zeroconf:
2856
 
            # From the Avahi example code
2857
 
            try:
2858
 
                service.activate()
2859
 
            except dbus.exceptions.DBusException as error:
2860
 
                logger.critical("D-Bus Exception", exc_info=error)
2861
 
                cleanup()
2862
 
                sys.exit(1)
2863
 
            # End of Avahi example code
 
2838
        # From the Avahi example code
 
2839
        try:
 
2840
            service.activate()
 
2841
        except dbus.exceptions.DBusException as error:
 
2842
            logger.critical("D-Bus Exception", exc_info=error)
 
2843
            cleanup()
 
2844
            sys.exit(1)
 
2845
        # End of Avahi example code
2864
2846
        
2865
2847
        gobject.io_add_watch(tcp_server.fileno(), gobject.IO_IN,
2866
2848
                             lambda *args, **kwargs: