/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-11-19 18:31:28 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091119183128-ttstewh61xmtnil1
* Makefile (LINK_FORTIFY_LD): Bug fix: removed "-fPIE".
* mandos-keygen: Bug fix: Fix quoting for the "--password" option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
        SO_BINDTODEVICE = None
80
80
 
81
81
 
82
 
version = "1.0.12"
 
82
version = "1.0.14"
83
83
 
84
84
logger = logging.Logger(u'mandos')
85
85
syslogger = (logging.handlers.SysLogHandler
325
325
        self.checker_initiator_tag = (gobject.timeout_add
326
326
                                      (self.interval_milliseconds(),
327
327
                                       self.start_checker))
328
 
        # Also start a new checker *right now*.
329
 
        self.start_checker()
330
328
        # Schedule a disable() when 'timeout' has passed
331
329
        self.disable_initiator_tag = (gobject.timeout_add
332
330
                                   (self.timeout_milliseconds(),
333
331
                                    self.disable))
334
332
        self.enabled = True
 
333
        # Also start a new checker *right now*.
 
334
        self.start_checker()
335
335
    
336
 
    def disable(self):
 
336
    def disable(self, quiet=True):
337
337
        """Disable this client."""
338
338
        if not getattr(self, "enabled", False):
339
339
            return False
340
 
        logger.info(u"Disabling client %s", self.name)
 
340
        if not quiet:
 
341
            logger.info(u"Disabling client %s", self.name)
341
342
        if getattr(self, u"disable_initiator_tag", False):
342
343
            gobject.source_remove(self.disable_initiator_tag)
343
344
            self.disable_initiator_tag = None
467
468
        logger.debug(u"Stopping checker for %(name)s", vars(self))
468
469
        try:
469
470
            os.kill(self.checker.pid, signal.SIGTERM)
470
 
            #os.sleep(0.5)
 
471
            #time.sleep(0.5)
471
472
            #if self.checker.poll() is None:
472
473
            #    os.kill(self.checker.pid, signal.SIGKILL)
473
474
        except OSError, error:
705
706
                                       variant_level=1))
706
707
        return r
707
708
    
708
 
    def disable(self, signal = True):
 
709
    def disable(self, quiet = False):
709
710
        oldstate = getattr(self, u"enabled", False)
710
 
        r = Client.disable(self)
711
 
        if signal and oldstate != self.enabled:
 
711
        r = Client.disable(self, quiet=quiet)
 
712
        if not quiet and oldstate != self.enabled:
712
713
            # Emit D-Bus signal
713
714
            self.PropertyChanged(dbus.String(u"enabled"),
714
715
                                 dbus.Boolean(False, variant_level=1))
1279
1280
        cmd, args = cmdline.rstrip(u"\r\n").split(None, 1)
1280
1281
        
1281
1282
        if cmd == u"NOTFOUND":
1282
 
            logger.warning(u"Client not found for fingerprint: %s",
1283
 
                           args)
 
1283
            fpr, address = args.split(None, 1)
 
1284
            logger.warning(u"Client not found for fingerprint: %s, ad"
 
1285
                           u"dress: %s", fpr, address)
1284
1286
            if self.use_dbus:
1285
1287
                # Emit D-Bus signal
1286
 
                mandos_dbus_service.ClientNotFound(args)
 
1288
                mandos_dbus_service.ClientNotFound(fpr, address)
1287
1289
        elif cmd == u"INVALID":
1288
1290
            for client in self.clients:
1289
1291
                if client.name == args:
1345
1347
            elif suffix == u"w":
1346
1348
                delta = datetime.timedelta(0, 0, 0, 0, 0, 0, value)
1347
1349
            else:
1348
 
                raise ValueError
1349
 
        except (ValueError, IndexError):
1350
 
            raise ValueError
 
1350
                raise ValueError(u"Unknown suffix %r" % suffix)
 
1351
        except (ValueError, IndexError), e:
 
1352
            raise ValueError(e.message)
1351
1353
        timevalue += delta
1352
1354
    return timevalue
1353
1355
 
1566
1568
    bus = dbus.SystemBus()
1567
1569
    # End of Avahi example code
1568
1570
    if use_dbus:
1569
 
        bus_name = dbus.service.BusName(u"se.bsnet.fukt.Mandos", bus)
 
1571
        try:
 
1572
            bus_name = dbus.service.BusName(u"se.bsnet.fukt.Mandos",
 
1573
                                            bus, do_not_queue=True)
 
1574
        except dbus.exceptions.NameExistsException, e:
 
1575
            logger.error(unicode(e) + u", disabling D-Bus")
 
1576
            use_dbus = False
 
1577
            server_settings[u"use_dbus"] = False
 
1578
            tcp_server.use_dbus = False
1570
1579
    protocol = avahi.PROTO_INET6 if use_ipv6 else avahi.PROTO_INET
1571
1580
    service = AvahiService(name = server_settings[u"servicename"],
1572
1581
                           servicetype = u"_mandos._tcp",
1610
1619
        pass
1611
1620
    del pidfilename
1612
1621
    
1613
 
    def cleanup():
1614
 
        "Cleanup function; run on exit"
1615
 
        service.cleanup()
1616
 
        
1617
 
        while tcp_server.clients:
1618
 
            client = tcp_server.clients.pop()
1619
 
            client.disable_hook = None
1620
 
            client.disable()
1621
 
    
1622
 
    atexit.register(cleanup)
1623
 
    
1624
1622
    if not debug:
1625
1623
        signal.signal(signal.SIGINT, signal.SIG_IGN)
1626
1624
    signal.signal(signal.SIGHUP, lambda signum, frame: sys.exit())
1638
1636
                "D-Bus signal"
1639
1637
                pass
1640
1638
            
1641
 
            @dbus.service.signal(_interface, signature=u"s")
1642
 
            def ClientNotFound(self, fingerprint):
 
1639
            @dbus.service.signal(_interface, signature=u"ss")
 
1640
            def ClientNotFound(self, fingerprint, address):
1643
1641
                "D-Bus signal"
1644
1642
                pass
1645
1643
            
1671
1669
                        tcp_server.clients.remove(c)
1672
1670
                        c.remove_from_connection()
1673
1671
                        # Don't signal anything except ClientRemoved
1674
 
                        c.disable(signal=False)
 
1672
                        c.disable(quiet=True)
1675
1673
                        # Emit D-Bus signal
1676
1674
                        self.ClientRemoved(object_path, c.name)
1677
1675
                        return
1678
 
                raise KeyError
 
1676
                raise KeyError(object_path)
1679
1677
            
1680
1678
            del _interface
1681
1679
        
1682
1680
        mandos_dbus_service = MandosDBusService()
1683
1681
    
 
1682
    def cleanup():
 
1683
        "Cleanup function; run on exit"
 
1684
        service.cleanup()
 
1685
        
 
1686
        while tcp_server.clients:
 
1687
            client = tcp_server.clients.pop()
 
1688
            if use_dbus:
 
1689
                client.remove_from_connection()
 
1690
            client.disable_hook = None
 
1691
            # Don't signal anything except ClientRemoved
 
1692
            client.disable(quiet=True)
 
1693
            if use_dbus:
 
1694
                # Emit D-Bus signal
 
1695
                mandos_dbus_service.ClientRemoved(client.dbus_object_path,
 
1696
                                                  client.name)
 
1697
    
 
1698
    atexit.register(cleanup)
 
1699
    
1684
1700
    for client in tcp_server.clients:
1685
1701
        if use_dbus:
1686
1702
            # Emit D-Bus signal
1709
1725
            service.activate()
1710
1726
        except dbus.exceptions.DBusException, error:
1711
1727
            logger.critical(u"DBusException: %s", error)
 
1728
            cleanup()
1712
1729
            sys.exit(1)
1713
1730
        # End of Avahi example code
1714
1731
        
1721
1738
        main_loop.run()
1722
1739
    except AvahiError, error:
1723
1740
        logger.critical(u"AvahiError: %s", error)
 
1741
        cleanup()
1724
1742
        sys.exit(1)
1725
1743
    except KeyboardInterrupt:
1726
1744
        if debug:
1727
1745
            print >> sys.stderr
1728
1746
        logger.debug(u"Server received KeyboardInterrupt")
1729
1747
    logger.debug(u"Server exiting")
 
1748
    # Must run before the D-Bus bus name gets deregistered
 
1749
    cleanup()
1730
1750
 
1731
1751
if __name__ == '__main__':
1732
1752
    main()