/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-06-15 02:48:49 UTC
  • Revision ID: teddy@recompile.se-20140615024849-68x3q8g4yzadl33s
mandos: New "--no-zeroconf" option.  Also make "--socket=0" work.

* mandos (main): New "--no-zeroconf" option.  Also do not interpret
                 socket=0 as no socket.
* mandos-options.xml (zeroconf): New.
* mandos.conf (socket, zeroconf): New.
* mandos.xml (SYNOPSIS, OPTIONS): Added "--no-zeroconf".

Show diffs side-by-side

added added

removed removed

Lines of Context:
2337
2337
                        help="Directory to save/restore state in")
2338
2338
    parser.add_argument("--foreground", action="store_true",
2339
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)
2340
2343
    
2341
2344
    options = parser.parse_args()
2342
2345
    
2360
2363
                        "socket": "",
2361
2364
                        "statedir": "/var/lib/mandos",
2362
2365
                        "foreground": "False",
 
2366
                        "zeroconf": "True",
2363
2367
                        }
2364
2368
    
2365
2369
    # Parse config file for server-global settings
2392
2396
    for option in ("interface", "address", "port", "debug",
2393
2397
                   "priority", "servicename", "configdir",
2394
2398
                   "use_dbus", "use_ipv6", "debuglevel", "restore",
2395
 
                   "statedir", "socket", "foreground"):
 
2399
                   "statedir", "socket", "foreground", "zeroconf"):
2396
2400
        value = getattr(options, option)
2397
2401
        if value is not None:
2398
2402
            server_settings[option] = value
2403
2407
            server_settings[option] = unicode(server_settings[option])
2404
2408
    # Force all boolean options to be boolean
2405
2409
    for option in ("debug", "use_dbus", "use_ipv6", "restore",
2406
 
                   "foreground"):
 
2410
                   "foreground", "zeroconf"):
2407
2411
        server_settings[option] = bool(server_settings[option])
2408
2412
    # Debug implies foreground
2409
2413
    if server_settings["debug"]:
2412
2416
    
2413
2417
    ##################################################################
2414
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
    
2415
2425
    # For convenience
2416
2426
    debug = server_settings["debug"]
2417
2427
    debuglevel = server_settings["debuglevel"]
2420
2430
    stored_state_path = os.path.join(server_settings["statedir"],
2421
2431
                                     stored_state_file)
2422
2432
    foreground = server_settings["foreground"]
 
2433
    zeroconf = server_settings["zeroconf"]
2423
2434
    
2424
2435
    if debug:
2425
2436
        initlogger(debug, logging.DEBUG)
2446
2457
    global mandos_dbus_service
2447
2458
    mandos_dbus_service = None
2448
2459
    
 
2460
    socketfd = None
 
2461
    if server_settings["socket"] != "":
 
2462
        socketfd = server_settings["socket"]
2449
2463
    tcp_server = MandosServer((server_settings["address"],
2450
2464
                               server_settings["port"]),
2451
2465
                              ClientHandler,
2455
2469
                              gnutls_priority=
2456
2470
                              server_settings["priority"],
2457
2471
                              use_dbus=use_dbus,
2458
 
                              socketfd=(server_settings["socket"]
2459
 
                                        or None))
 
2472
                              socketfd=socketfd)
2460
2473
    if not foreground:
2461
2474
        pidfilename = "/run/mandos.pid"
2462
2475
        if not os.path.isdir("/run/."):
2532
2545
            use_dbus = False
2533
2546
            server_settings["use_dbus"] = False
2534
2547
            tcp_server.use_dbus = False
2535
 
    protocol = avahi.PROTO_INET6 if use_ipv6 else avahi.PROTO_INET
2536
 
    service = AvahiServiceToSyslog(name =
2537
 
                                   server_settings["servicename"],
2538
 
                                   servicetype = "_mandos._tcp",
2539
 
                                   protocol = protocol, bus = bus)
2540
 
    if server_settings["interface"]:
2541
 
        service.interface = (if_nametoindex
2542
 
                             (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"])))
2543
2557
    
2544
2558
    global multiprocessing_manager
2545
2559
    multiprocessing_manager = multiprocessing.Manager()
2739
2753
    
2740
2754
    def cleanup():
2741
2755
        "Cleanup function; run on exit"
2742
 
        service.cleanup()
 
2756
        if zeroconf:
 
2757
            service.cleanup()
2743
2758
        
2744
2759
        multiprocessing.active_children()
2745
2760
        wnull.close()
2824
2839
    tcp_server.server_activate()
2825
2840
    
2826
2841
    # Find out what port we got
2827
 
    service.port = tcp_server.socket.getsockname()[1]
 
2842
    if zeroconf:
 
2843
        service.port = tcp_server.socket.getsockname()[1]
2828
2844
    if use_ipv6:
2829
2845
        logger.info("Now listening on address %r, port %d,"
2830
2846
                    " flowinfo %d, scope_id %d",
2836
2852
    #service.interface = tcp_server.socket.getsockname()[3]
2837
2853
    
2838
2854
    try:
2839
 
        # From the Avahi example code
2840
 
        try:
2841
 
            service.activate()
2842
 
        except dbus.exceptions.DBusException as error:
2843
 
            logger.critical("D-Bus Exception", exc_info=error)
2844
 
            cleanup()
2845
 
            sys.exit(1)
2846
 
        # 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
2847
2864
        
2848
2865
        gobject.io_add_watch(tcp_server.fileno(), gobject.IO_IN,
2849
2866
                             lambda *args, **kwargs: