/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

Change "fukt.bsnet.se" to "recompile.se" throughout.

* README: - '' -
* debian/control: - '' -
* debian/copyright: - '' -
* debian/mandos-client.README.Debian: - '' - and some rewriting.
* debian/mandos.README.Debian: - '' -
* debian/watch: Change "fukt.bsnet.se" to "recompile.se".
* init.d-mandos: - '' -
* intro.xml: - '' -
* mandos: - '' -
* mandos-clients.conf.xml: - '' -
* mandos-ctl: - '' -
* mandos-ctl.xml: - '' -
* mandos-keygen: - '' -
* mandos-keygen.xml: - '' -
* mandos-monitor: - '' -
* mandos-monitor.xml: - '' -
* mandos.conf.xml: - '' -
* mandos.lsm: - '' -
* mandos.xml: - '' -
* plugin-runner.c: - '' -
* plugin-runner.xml: - '' -
* plugins.d/askpass-fifo.c: - '' -
* plugins.d/askpass-fifo.xml: - '' -
* plugins.d/mandos-client.c: - '' -
* plugins.d/mandos-client.xml: - '' -
* plugins.d/password-prompt.c: - '' -
* plugins.d/password-prompt.xml: - '' -
* plugins.d/plymouth.c: - '' -
* plugins.d/plymouth.xml: - '' -
* plugins.d/splashy.c: - '' -
* plugins.d/splashy.xml: - '' -
* plugins.d/usplash.c: - '' -
* plugins.d/usplash.xml: - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
                            " after %i retries, exiting.",
161
161
                            self.rename_count)
162
162
            raise AvahiServiceError("Too many renames")
163
 
        self.name = unicode(self.server
164
 
                            .GetAlternativeServiceName(self.name))
 
163
        self.name = unicode(self.server.GetAlternativeServiceName(self.name))
165
164
        logger.info("Changing Zeroconf service name to %r ...",
166
165
                    self.name)
167
166
        syslogger.setFormatter(logging.Formatter
322
321
    
323
322
    def extended_timeout_milliseconds(self):
324
323
        "Return the 'extended_timeout' attribute in milliseconds"
325
 
        return _timedelta_to_milliseconds(self.extended_timeout)
 
324
        return _timedelta_to_milliseconds(self.extended_timeout)    
326
325
    
327
326
    def interval_milliseconds(self):
328
327
        "Return the 'interval' attribute in milliseconds"
362
361
        self.last_enabled = None
363
362
        self.last_checked_ok = None
364
363
        self.timeout = string_to_delta(config["timeout"])
365
 
        self.extended_timeout = string_to_delta(config
366
 
                                                ["extended_timeout"])
 
364
        self.extended_timeout = string_to_delta(config["extended_timeout"])
367
365
        self.interval = string_to_delta(config["interval"])
368
366
        self.disable_hook = disable_hook
369
367
        self.checker = None
382
380
            config["approval_delay"])
383
381
        self.approval_duration = string_to_delta(
384
382
            config["approval_duration"])
385
 
        self.changedstate = (multiprocessing_manager
386
 
                             .Condition(multiprocessing_manager
387
 
                                        .Lock()))
 
383
        self.changedstate = multiprocessing_manager.Condition(multiprocessing_manager.Lock())
388
384
    
389
385
    def send_changedstate(self):
390
386
        self.changedstate.acquire()
391
387
        self.changedstate.notify_all()
392
388
        self.changedstate.release()
393
 
    
 
389
        
394
390
    def enable(self):
395
391
        """Start this client's checker and timeout hooks"""
396
392
        if getattr(self, "enabled", False):
467
463
        gobject.source_remove(self.disable_initiator_tag)
468
464
        self.expires = datetime.datetime.utcnow() + timeout
469
465
        self.disable_initiator_tag = (gobject.timeout_add
470
 
                                      (_timedelta_to_milliseconds
471
 
                                       (timeout), self.disable))
 
466
                                      (_timedelta_to_milliseconds(timeout),
 
467
                                       self.disable))
472
468
    
473
469
    def need_approval(self):
474
470
        self.last_approval_request = datetime.datetime.utcnow()
633
629
        """
634
630
        return ((prop.__get__(self)._dbus_name, prop.__get__(self))
635
631
                for cls in self.__class__.__mro__
636
 
                for name, prop in
637
 
                inspect.getmembers(cls, self._is_dbus_property))
 
632
                for name, prop in inspect.getmembers(cls, self._is_dbus_property))
638
633
    
639
634
    def _get_dbus_property(self, interface_name, property_name):
640
635
        """Returns a bound method if one exists which is a D-Bus
641
636
        property with the specified name and interface.
642
637
        """
643
638
        for cls in  self.__class__.__mro__:
644
 
            for name, value in (inspect.getmembers
645
 
                                (cls, self._is_dbus_property)):
646
 
                if (value._dbus_name == property_name
647
 
                    and value._dbus_interface == interface_name):
 
639
            for name, value in inspect.getmembers(cls, self._is_dbus_property):
 
640
                if value._dbus_name == property_name and value._dbus_interface == interface_name:
648
641
                    return value.__get__(self)
649
642
        
650
643
        # No such property
761
754
    return dbus.String(dt.isoformat(),
762
755
                       variant_level=variant_level)
763
756
 
764
 
class AlternateDBusNamesMetaclass(DBusObjectWithProperties
765
 
                                  .__metaclass__):
 
757
class AlternateDBusNamesMetaclass(DBusObjectWithProperties.__metaclass__):
766
758
    """Applied to an empty subclass of a D-Bus object, this metaclass
767
759
    will add additional D-Bus attributes matching a certain pattern.
768
760
    """
898
890
                   to the D-Bus.  Default: no transform
899
891
        variant_level: D-Bus variant level.  Default: 1
900
892
        """
901
 
        attrname = "_{0}".format(dbus_name)
 
893
        real_value = [None,]
902
894
        def setter(self, value):
 
895
            old_value = real_value[0]
 
896
            real_value[0] = value
903
897
            if hasattr(self, "dbus_object_path"):
904
 
                if (not hasattr(self, attrname) or
905
 
                    type_func(getattr(self, attrname, None))
906
 
                    != type_func(value)):
907
 
                    dbus_value = transform_func(type_func(value),
 
898
                if type_func(old_value) != type_func(real_value[0]):
 
899
                    dbus_value = transform_func(type_func(real_value[0]),
908
900
                                                variant_level)
909
901
                    self.PropertyChanged(dbus.String(dbus_name),
910
902
                                         dbus_value)
911
 
            setattr(self, attrname, value)
912
903
        
913
 
        return property(lambda self: getattr(self, attrname), setter)
 
904
        return property(lambda self: real_value[0], setter)
914
905
    
915
906
    
916
907
    expires = notifychangeproperty(datetime_to_dbus, "Expires")
921
912
    last_enabled = notifychangeproperty(datetime_to_dbus,
922
913
                                        "LastEnabled")
923
914
    checker = notifychangeproperty(dbus.Boolean, "CheckerRunning",
924
 
                                   type_func = lambda checker:
925
 
                                       checker is not None)
 
915
                                   type_func = lambda checker: checker is not None)
926
916
    last_checked_ok = notifychangeproperty(datetime_to_dbus,
927
917
                                           "LastCheckedOK")
928
 
    last_approval_request = notifychangeproperty(
929
 
        datetime_to_dbus, "LastApprovalRequest")
 
918
    last_approval_request = notifychangeproperty(datetime_to_dbus,
 
919
                                                 "LastApprovalRequest")
930
920
    approved_by_default = notifychangeproperty(dbus.Boolean,
931
921
                                               "ApprovedByDefault")
932
 
    approval_delay = notifychangeproperty(dbus.UInt16,
933
 
                                          "ApprovalDelay",
934
 
                                          type_func =
935
 
                                          _timedelta_to_milliseconds)
936
 
    approval_duration = notifychangeproperty(
937
 
        dbus.UInt16, "ApprovalDuration",
938
 
        type_func = _timedelta_to_milliseconds)
 
922
    approval_delay = notifychangeproperty(dbus.UInt16, "ApprovalDelay",
 
923
                                          type_func = _timedelta_to_milliseconds)
 
924
    approval_duration = notifychangeproperty(dbus.UInt16, "ApprovalDuration",
 
925
                                             type_func = _timedelta_to_milliseconds)
939
926
    host = notifychangeproperty(dbus.String, "Host")
940
927
    timeout = notifychangeproperty(dbus.UInt16, "Timeout",
941
 
                                   type_func =
942
 
                                   _timedelta_to_milliseconds)
943
 
    extended_timeout = notifychangeproperty(
944
 
        dbus.UInt16, "ExtendedTimeout",
945
 
        type_func = _timedelta_to_milliseconds)
946
 
    interval = notifychangeproperty(dbus.UInt16,
947
 
                                    "Interval",
948
 
                                    type_func =
949
 
                                    _timedelta_to_milliseconds)
 
928
                                   type_func = _timedelta_to_milliseconds)
 
929
    extended_timeout = notifychangeproperty(dbus.UInt16, "ExtendedTimeout",
 
930
                                            type_func = _timedelta_to_milliseconds)
 
931
    interval = notifychangeproperty(dbus.UInt16, "Interval",
 
932
                                    type_func = _timedelta_to_milliseconds)
950
933
    checker_command = notifychangeproperty(dbus.String, "Checker")
951
934
    
952
935
    del notifychangeproperty
1198
1181
            self.disable()
1199
1182
        else:
1200
1183
            self.expires = (datetime.datetime.utcnow()
1201
 
                            + datetime.timedelta(milliseconds =
1202
 
                                                 time_to_die))
 
1184
                            + datetime.timedelta(milliseconds = time_to_die))
1203
1185
            self.disable_initiator_tag = (gobject.timeout_add
1204
1186
                                          (time_to_die, self.disable))
1205
1187
    
1371
1353
                                       client.name)
1372
1354
                        if self.server.use_dbus:
1373
1355
                            # Emit D-Bus signal
1374
 
                            client.Rejected("Disabled")
 
1356
                            client.Rejected("Disabled")                    
1375
1357
                        return
1376
1358
                    
1377
1359
                    if client._approved or not client.approval_delay:
1394
1376
                        return
1395
1377
                    
1396
1378
                    #wait until timeout or approved
1397
 
                    #x = float(client
1398
 
                    #          ._timedelta_to_milliseconds(delay))
 
1379
                    #x = float(client._timedelta_to_milliseconds(delay))
1399
1380
                    time = datetime.datetime.now()
1400
1381
                    client.changedstate.acquire()
1401
 
                    (client.changedstate.wait
1402
 
                     (float(client._timedelta_to_milliseconds(delay)
1403
 
                            / 1000)))
 
1382
                    client.changedstate.wait(float(client._timedelta_to_milliseconds(delay) / 1000))
1404
1383
                    client.changedstate.release()
1405
1384
                    time2 = datetime.datetime.now()
1406
1385
                    if (time2 - time) >= delay:
1638
1617
        gobject.io_add_watch(parent_pipe.fileno(),
1639
1618
                             gobject.IO_IN | gobject.IO_HUP,
1640
1619
                             functools.partial(self.handle_ipc,
1641
 
                                               parent_pipe =
1642
 
                                               parent_pipe))
 
1620
                                               parent_pipe = parent_pipe))
1643
1621
        
1644
1622
    def handle_ipc(self, source, condition, parent_pipe=None,
1645
1623
                   client_object=None):
1678
1656
                            "dress: %s", fpr, address)
1679
1657
                if self.use_dbus:
1680
1658
                    # Emit D-Bus signal
1681
 
                    mandos_dbus_service.ClientNotFound(fpr,
1682
 
                                                       address[0])
 
1659
                    mandos_dbus_service.ClientNotFound(fpr, address[0])
1683
1660
                parent_pipe.send(False)
1684
1661
                return False
1685
1662
            
1686
1663
            gobject.io_add_watch(parent_pipe.fileno(),
1687
1664
                                 gobject.IO_IN | gobject.IO_HUP,
1688
1665
                                 functools.partial(self.handle_ipc,
1689
 
                                                   parent_pipe =
1690
 
                                                   parent_pipe,
1691
 
                                                   client_object =
1692
 
                                                   client))
 
1666
                                                   parent_pipe = parent_pipe,
 
1667
                                                   client_object = client))
1693
1668
            parent_pipe.send(True)
1694
 
            # remove the old hook in favor of the new above hook on
1695
 
            # same fileno
 
1669
            # remove the old hook in favor of the new above hook on same fileno
1696
1670
            return False
1697
1671
        if command == 'funcall':
1698
1672
            funcname = request[1]
1699
1673
            args = request[2]
1700
1674
            kwargs = request[3]
1701
1675
            
1702
 
            parent_pipe.send(('data', getattr(client_object,
1703
 
                                              funcname)(*args,
1704
 
                                                         **kwargs)))
 
1676
            parent_pipe.send(('data', getattr(client_object, funcname)(*args, **kwargs)))
1705
1677
        
1706
1678
        if command == 'getattr':
1707
1679
            attrname = request[1]
1708
1680
            if callable(client_object.__getattribute__(attrname)):
1709
1681
                parent_pipe.send(('function',))
1710
1682
            else:
1711
 
                parent_pipe.send(('data', client_object
1712
 
                                  .__getattribute__(attrname)))
 
1683
                parent_pipe.send(('data', client_object.__getattribute__(attrname)))
1713
1684
        
1714
1685
        if command == 'setattr':
1715
1686
            attrname = request[1]
2006
1977
        try:
2007
1978
            bus_name = dbus.service.BusName("se.recompile.Mandos",
2008
1979
                                            bus, do_not_queue=True)
2009
 
            old_bus_name = (dbus.service.BusName
2010
 
                            ("se.bsnet.fukt.Mandos", bus,
2011
 
                             do_not_queue=True))
 
1980
            old_bus_name = dbus.service.BusName("se.bsnet.fukt.Mandos",
 
1981
                                                bus, do_not_queue=True)
2012
1982
        except dbus.exceptions.NameExistsException as e:
2013
1983
            logger.error(unicode(e) + ", disabling D-Bus")
2014
1984
            use_dbus = False
2027
1997
    
2028
1998
    client_class = Client
2029
1999
    if use_dbus:
2030
 
        client_class = functools.partial(ClientDBusTransitional,
2031
 
                                         bus = bus)
 
2000
        client_class = functools.partial(ClientDBusTransitional, bus = bus)        
2032
2001
    def client_config_items(config, section):
2033
2002
        special_settings = {
2034
2003
            "approved_by_default":
2138
2107
            client.disable(quiet=True)
2139
2108
            if use_dbus:
2140
2109
                # Emit D-Bus signal
2141
 
                mandos_dbus_service.ClientRemoved(client
2142
 
                                                  .dbus_object_path,
 
2110
                mandos_dbus_service.ClientRemoved(client.dbus_object_path,
2143
2111
                                                  client.name)
2144
2112
    
2145
2113
    atexit.register(cleanup)