/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2014-07-13 20:37:44 UTC
  • mfrom: (237.7.258 trunk)
  • Revision ID: teddy@recompile.se-20140713203744-538hqhk81vw9dixv
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
def initlogger(debug, level=logging.WARNING):
115
115
    """init logger and add loglevel"""
116
116
    
 
117
    global syslogger
117
118
    syslogger = (logging.handlers.SysLogHandler
118
119
                 (facility =
119
120
                  logging.handlers.SysLogHandler.LOG_DAEMON,
2336
2337
                        help="Directory to save/restore state in")
2337
2338
    parser.add_argument("--foreground", action="store_true",
2338
2339
                        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)
2339
2343
    
2340
2344
    options = parser.parse_args()
2341
2345
    
2359
2363
                        "socket": "",
2360
2364
                        "statedir": "/var/lib/mandos",
2361
2365
                        "foreground": "False",
 
2366
                        "zeroconf": "True",
2362
2367
                        }
2363
2368
    
2364
2369
    # Parse config file for server-global settings
2391
2396
    for option in ("interface", "address", "port", "debug",
2392
2397
                   "priority", "servicename", "configdir",
2393
2398
                   "use_dbus", "use_ipv6", "debuglevel", "restore",
2394
 
                   "statedir", "socket", "foreground"):
 
2399
                   "statedir", "socket", "foreground", "zeroconf"):
2395
2400
        value = getattr(options, option)
2396
2401
        if value is not None:
2397
2402
            server_settings[option] = value
2402
2407
            server_settings[option] = unicode(server_settings[option])
2403
2408
    # Force all boolean options to be boolean
2404
2409
    for option in ("debug", "use_dbus", "use_ipv6", "restore",
2405
 
                   "foreground"):
 
2410
                   "foreground", "zeroconf"):
2406
2411
        server_settings[option] = bool(server_settings[option])
2407
2412
    # Debug implies foreground
2408
2413
    if server_settings["debug"]:
2411
2416
    
2412
2417
    ##################################################################
2413
2418
    
 
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
    
2414
2425
    # For convenience
2415
2426
    debug = server_settings["debug"]
2416
2427
    debuglevel = server_settings["debuglevel"]
2419
2430
    stored_state_path = os.path.join(server_settings["statedir"],
2420
2431
                                     stored_state_file)
2421
2432
    foreground = server_settings["foreground"]
 
2433
    zeroconf = server_settings["zeroconf"]
2422
2434
    
2423
2435
    if debug:
2424
2436
        initlogger(debug, logging.DEBUG)
2445
2457
    global mandos_dbus_service
2446
2458
    mandos_dbus_service = None
2447
2459
    
 
2460
    socketfd = None
 
2461
    if server_settings["socket"] != "":
 
2462
        socketfd = server_settings["socket"]
2448
2463
    tcp_server = MandosServer((server_settings["address"],
2449
2464
                               server_settings["port"]),
2450
2465
                              ClientHandler,
2454
2469
                              gnutls_priority=
2455
2470
                              server_settings["priority"],
2456
2471
                              use_dbus=use_dbus,
2457
 
                              socketfd=(server_settings["socket"]
2458
 
                                        or None))
 
2472
                              socketfd=socketfd)
2459
2473
    if not foreground:
2460
2474
        pidfilename = "/run/mandos.pid"
2461
2475
        if not os.path.isdir("/run/."):
2531
2545
            use_dbus = False
2532
2546
            server_settings["use_dbus"] = False
2533
2547
            tcp_server.use_dbus = False
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"])))
 
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"])))
2542
2557
    
2543
2558
    global multiprocessing_manager
2544
2559
    multiprocessing_manager = multiprocessing.Manager()
2738
2753
    
2739
2754
    def cleanup():
2740
2755
        "Cleanup function; run on exit"
2741
 
        service.cleanup()
 
2756
        if zeroconf:
 
2757
            service.cleanup()
2742
2758
        
2743
2759
        multiprocessing.active_children()
2744
2760
        wnull.close()
2823
2839
    tcp_server.server_activate()
2824
2840
    
2825
2841
    # Find out what port we got
2826
 
    service.port = tcp_server.socket.getsockname()[1]
 
2842
    if zeroconf:
 
2843
        service.port = tcp_server.socket.getsockname()[1]
2827
2844
    if use_ipv6:
2828
2845
        logger.info("Now listening on address %r, port %d,"
2829
2846
                    " flowinfo %d, scope_id %d",
2835
2852
    #service.interface = tcp_server.socket.getsockname()[3]
2836
2853
    
2837
2854
    try:
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
 
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
2846
2864
        
2847
2865
        gobject.io_add_watch(tcp_server.fileno(), gobject.IO_IN,
2848
2866
                             lambda *args, **kwargs: