/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: Björn Påhlsson
  • Date: 2011-10-02 19:33:45 UTC
  • mfrom: (24.1.186 mandos)
  • Revision ID: belorn@fukt.bsnet.se-20111002193345-83fdvai1j7phep7j
The domain name has changed, so the D-Bus bus and interface names must
change.  This commit adds support for both the old and new names.

The new domain name is "recompile.se", so the new D-Bus bus name will
be "se.recompile.Mandos".

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
import functools
63
63
import cPickle as pickle
64
64
import multiprocessing
 
65
import types
65
66
 
66
67
import dbus
67
68
import dbus.service
626
627
    def _get_all_dbus_properties(self):
627
628
        """Returns a generator of (name, attribute) pairs
628
629
        """
629
 
        return ((prop._dbus_name, prop)
630
 
                for name, prop in
631
 
                inspect.getmembers(self, self._is_dbus_property))
 
630
        return ((prop.__get__(self)._dbus_name, prop.__get__(self))
 
631
                for cls in self.__class__.__mro__
 
632
                for name, prop in inspect.getmembers(cls, self._is_dbus_property))
632
633
    
633
634
    def _get_dbus_property(self, interface_name, property_name):
634
635
        """Returns a bound method if one exists which is a D-Bus
635
636
        property with the specified name and interface.
636
637
        """
637
 
        for name in (property_name,
638
 
                     property_name + "_dbus_property"):
639
 
            prop = getattr(self, name, None)
640
 
            if (prop is None
641
 
                or not self._is_dbus_property(prop)
642
 
                or prop._dbus_name != property_name
643
 
                or (interface_name and prop._dbus_interface
644
 
                    and interface_name != prop._dbus_interface)):
645
 
                continue
646
 
            return prop
 
638
        for cls in  self.__class__.__mro__:
 
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:
 
641
                    return value.__get__(self)
 
642
        
647
643
        # No such property
648
644
        raise DBusPropertyNotFound(self.dbus_object_path + ":"
649
645
                                   + interface_name + "."
758
754
    return dbus.String(dt.isoformat(),
759
755
                       variant_level=variant_level)
760
756
 
 
757
class transitional_dbus_metaclass(DBusObjectWithProperties.__metaclass__):
 
758
    def __new__(mcs, name, bases, attr):
 
759
        for attrname, old_dbusobj in inspect.getmembers(bases[0]):
 
760
            new_interface = getattr(old_dbusobj, "_dbus_interface", "").replace("se.bsnet.fukt.", "se.recompile.")
 
761
            if (getattr(old_dbusobj, "_dbus_is_signal", False)
 
762
                and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
 
763
                unwrappedfunc = dict(zip(old_dbusobj.func_code.co_freevars,
 
764
                                    old_dbusobj.__closure__))["func"].cell_contents
 
765
                newfunc = types.FunctionType(unwrappedfunc.func_code,
 
766
                                             unwrappedfunc.func_globals,
 
767
                                             unwrappedfunc.func_name,
 
768
                                             unwrappedfunc.func_defaults,
 
769
                                             unwrappedfunc.func_closure)
 
770
                new_dbusfunc = dbus.service.signal(
 
771
                    new_interface, old_dbusobj._dbus_signature)(newfunc)            
 
772
                attr["_transitional_" + attrname] = new_dbusfunc
 
773
 
 
774
                def fixscope(func1, func2):
 
775
                    def newcall(*args, **kwargs):
 
776
                        func1(*args, **kwargs)
 
777
                        func2(*args, **kwargs)
 
778
                    return newcall
 
779
 
 
780
                attr[attrname] = fixscope(old_dbusobj, new_dbusfunc)
 
781
            
 
782
            elif (getattr(old_dbusobj, "_dbus_is_method", False)
 
783
                and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
 
784
                new_dbusfunc = (dbus.service.method
 
785
                                (new_interface,
 
786
                                 old_dbusobj._dbus_in_signature,
 
787
                                 old_dbusobj._dbus_out_signature)
 
788
                                (types.FunctionType
 
789
                                 (old_dbusobj.func_code,
 
790
                                  old_dbusobj.func_globals,
 
791
                                  old_dbusobj.func_name,
 
792
                                  old_dbusobj.func_defaults,
 
793
                                  old_dbusobj.func_closure)))
 
794
 
 
795
                attr[attrname] = new_dbusfunc
 
796
            elif (getattr(old_dbusobj, "_dbus_is_property", False)
 
797
                  and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
 
798
                new_dbusfunc = (dbus_service_property
 
799
                                (new_interface,
 
800
                                 old_dbusobj._dbus_signature,
 
801
                                 old_dbusobj._dbus_access,
 
802
                                 old_dbusobj._dbus_get_args_options["byte_arrays"])
 
803
                                (types.FunctionType
 
804
                                 (old_dbusobj.func_code,
 
805
                                  old_dbusobj.func_globals,
 
806
                                  old_dbusobj.func_name,
 
807
                                  old_dbusobj.func_defaults,
 
808
                                  old_dbusobj.func_closure)))
 
809
 
 
810
                attr[attrname] = new_dbusfunc
 
811
        return type.__new__(mcs, name, bases, attr)
761
812
 
762
813
class ClientDBus(Client, DBusObjectWithProperties):
763
814
    """A Client class using D-Bus
1174
1225
            return super(ProxyClient, self).__setattr__(name, value)
1175
1226
        self._pipe.send(('setattr', name, value))
1176
1227
 
 
1228
class ClientDBusTransitional(ClientDBus):
 
1229
    __metaclass__ = transitional_dbus_metaclass
1177
1230
 
1178
1231
class ClientHandler(socketserver.BaseRequestHandler, object):
1179
1232
    """A class to handle client connections.
1881
1934
    # End of Avahi example code
1882
1935
    if use_dbus:
1883
1936
        try:
1884
 
            bus_name = dbus.service.BusName("se.bsnet.fukt.Mandos",
 
1937
            bus_name = dbus.service.BusName("se.recompile.Mandos",
1885
1938
                                            bus, do_not_queue=True)
 
1939
            bus_name_transitional = dbus.service.BusName("se.bsnet.fukt.Mandos",
 
1940
                                                         bus, do_not_queue=True)
1886
1941
        except dbus.exceptions.NameExistsException as e:
1887
1942
            logger.error(unicode(e) + ", disabling D-Bus")
1888
1943
            use_dbus = False
1901
1956
    
1902
1957
    client_class = Client
1903
1958
    if use_dbus:
1904
 
        client_class = functools.partial(ClientDBus, bus = bus)
 
1959
        client_class = functools.partial(ClientDBusTransitional, bus = bus)        
1905
1960
    def client_config_items(config, section):
1906
1961
        special_settings = {
1907
1962
            "approved_by_default":
1994
2049
            
1995
2050
            del _interface
1996
2051
        
1997
 
        mandos_dbus_service = MandosDBusService()
 
2052
        class MandosDBusServiceTransitional(MandosDBusService):
 
2053
            __metaclass__ = transitional_dbus_metaclass
 
2054
        mandos_dbus_service = MandosDBusServiceTransitional()
1998
2055
    
1999
2056
    def cleanup():
2000
2057
        "Cleanup function; run on exit"