/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-03-05 21:47:03 UTC
  • Revision ID: teddy@recompile.se-20140305214703-c5ulnh1c9i51yzl9
* Makefile (WARN): Re-add "-Wunreachable-code".
  (.PHONY): Update; add "mostlyclean", "maintainer-clean",
            "install-html", and "install-client-nokey".

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
    except ImportError:
89
89
        SO_BINDTODEVICE = None
90
90
 
91
 
version = "1.6.6"
 
91
version = "1.6.4"
92
92
stored_state_file = "clients.pickle"
93
93
 
94
94
logger = logging.getLogger()
114
114
def initlogger(debug, level=logging.WARNING):
115
115
    """init logger and add loglevel"""
116
116
    
117
 
    global syslogger
118
117
    syslogger = (logging.handlers.SysLogHandler
119
118
                 (facility =
120
119
                  logging.handlers.SysLogHandler.LOG_DAEMON,
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
    
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: