/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: 2009-04-17 01:16:37 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090417011637-bcqjpm7fskm4370v
Code cleanup and one bug fix.

* mandos (Client.enable): Bug fix: Do not enable if already enabled.
  (MandosServer.__init__): Create empty set of clients if none passed.
  (main): Do not create clients set; do not pass a clients set to
          MandosServer.  Use tcp_server.clients throughout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
312
312
    
313
313
    def enable(self):
314
314
        """Start this client's checker and timeout hooks"""
 
315
        if getattr(self, u"enabled", False):
 
316
            # Already enabled
 
317
            return
315
318
        self.last_enabled = datetime.datetime.utcnow()
316
319
        # Schedule a new checker to be started an 'interval' from now,
317
320
        # and every interval from then on.
990
993
                 gnutls_priority=None, use_dbus=True):
991
994
        self.enabled = False
992
995
        self.clients = clients
 
996
        if self.clients is None:
 
997
            self.clients = set()
993
998
        self.use_dbus = use_dbus
994
999
        self.gnutls_priority = gnutls_priority
995
1000
        IPv6_TCPServer.__init__(self, server_address,
1274
1279
    global mandos_dbus_service
1275
1280
    mandos_dbus_service = None
1276
1281
    
1277
 
    clients = set()
1278
1282
    tcp_server = MandosServer((server_settings[u"address"],
1279
1283
                               server_settings[u"port"]),
1280
1284
                              ClientHandler,
1281
1285
                              interface=server_settings[u"interface"],
1282
1286
                              use_ipv6=use_ipv6,
1283
 
                              clients=clients,
1284
1287
                              gnutls_priority=
1285
1288
                              server_settings[u"priority"],
1286
1289
                              use_dbus=use_dbus)
1343
1346
    client_class = Client
1344
1347
    if use_dbus:
1345
1348
        client_class = functools.partial(ClientDBus, bus = bus)
1346
 
    clients.update(set(
 
1349
    tcp_server.clients.update(set(
1347
1350
            client_class(name = section,
1348
1351
                         config= dict(client_config.items(section)))
1349
1352
            for section in client_config.sections()))
1350
 
    if not clients:
 
1353
    if not tcp_server.clients:
1351
1354
        logger.warning(u"No clients defined")
1352
1355
    
1353
1356
    if debug:
1379
1382
        "Cleanup function; run on exit"
1380
1383
        service.cleanup()
1381
1384
        
1382
 
        while clients:
1383
 
            client = clients.pop()
 
1385
        while tcp_server.clients:
 
1386
            client = tcp_server.clients.pop()
1384
1387
            client.disable_hook = None
1385
1388
            client.disable()
1386
1389
    
1416
1419
            @dbus.service.method(_interface, out_signature=u"ao")
1417
1420
            def GetAllClients(self):
1418
1421
                "D-Bus method"
1419
 
                return dbus.Array(c.dbus_object_path for c in clients)
 
1422
                return dbus.Array(c.dbus_object_path
 
1423
                                  for c in tcp_server.clients)
1420
1424
            
1421
1425
            @dbus.service.method(_interface,
1422
1426
                                 out_signature=u"a{oa{sv}}")
1424
1428
                "D-Bus method"
1425
1429
                return dbus.Dictionary(
1426
1430
                    ((c.dbus_object_path, c.GetAllProperties())
1427
 
                     for c in clients),
 
1431
                     for c in tcp_server.clients),
1428
1432
                    signature=u"oa{sv}")
1429
1433
            
1430
1434
            @dbus.service.method(_interface, in_signature=u"o")
1431
1435
            def RemoveClient(self, object_path):
1432
1436
                "D-Bus method"
1433
 
                for c in clients:
 
1437
                for c in tcp_server.clients:
1434
1438
                    if c.dbus_object_path == object_path:
1435
 
                        clients.remove(c)
 
1439
                        tcp_server.clients.remove(c)
1436
1440
                        c.remove_from_connection()
1437
1441
                        # Don't signal anything except ClientRemoved
1438
1442
                        c.disable(signal=False)
1445
1449
        
1446
1450
        mandos_dbus_service = MandosDBusService()
1447
1451
    
1448
 
    for client in clients:
 
1452
    for client in tcp_server.clients:
1449
1453
        if use_dbus:
1450
1454
            # Emit D-Bus signal
1451
1455
            mandos_dbus_service.ClientAdded(client.dbus_object_path,