/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:18:24 UTC
  • mto: This revision was merged to the branch mainline in revision 505.
  • Revision ID: belorn@fukt.bsnet.se-20111002191824-eweh4pvneeg3qzia
transitional stuff actually working
documented change to D-Bus API

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
# along with this program.  If not, see
29
29
# <http://www.gnu.org/licenses/>.
30
30
31
 
# Contact the authors at <mandos@recompile.se>.
 
31
# Contact the authors at <mandos@fukt.bsnet.se>.
32
32
33
33
 
34
34
from __future__ import (division, absolute_import, print_function,
83
83
        SO_BINDTODEVICE = None
84
84
 
85
85
 
86
 
version = "1.4.0"
 
86
version = "1.3.1"
87
87
 
88
88
#logger = logging.getLogger('mandos')
89
89
logger = logging.Logger('mandos')
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):
465
461
            timeout = self.timeout
466
462
        self.last_checked_ok = datetime.datetime.utcnow()
467
463
        gobject.source_remove(self.disable_initiator_tag)
468
 
        self.disable_initiator_tag = (gobject.timeout_add
469
 
                                      (_timedelta_to_milliseconds
470
 
                                       (timeout), self.disable))
471
464
        self.expires = datetime.datetime.utcnow() + timeout
 
465
        self.disable_initiator_tag = (gobject.timeout_add
 
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
651
644
        raise DBusPropertyNotFound(self.dbus_object_path + ":"
652
645
                                   + interface_name + "."
653
646
                                   + property_name)
 
647
 
654
648
    
655
649
    @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature="ss",
656
650
                         out_signature="v")
761
755
    return dbus.String(dt.isoformat(),
762
756
                       variant_level=variant_level)
763
757
 
764
 
class AlternateDBusNamesMetaclass(DBusObjectWithProperties
765
 
                                  .__metaclass__):
766
 
    """Applied to an empty subclass of a D-Bus object, this metaclass
767
 
    will add additional D-Bus attributes matching a certain pattern.
768
 
    """
 
758
class transitional_dbus_metaclass(DBusObjectWithProperties.__metaclass__):
769
759
    def __new__(mcs, name, bases, attr):
770
 
        # Go through all the base classes which could have D-Bus
771
 
        # methods, signals, or properties in them
772
 
        for base in (b for b in bases
773
 
                     if issubclass(b, dbus.service.Object)):
774
 
            # Go though all attributes of the base class
775
 
            for attrname, attribute in inspect.getmembers(base):
776
 
                # Ignore non-D-Bus attributes, and D-Bus attributes
777
 
                # with the wrong interface name
778
 
                if (not hasattr(attribute, "_dbus_interface")
779
 
                    or not attribute._dbus_interface
780
 
                    .startswith("se.recompile.Mandos")):
781
 
                    continue
782
 
                # Create an alternate D-Bus interface name based on
783
 
                # the current name
784
 
                alt_interface = (attribute._dbus_interface
785
 
                                 .replace("se.recompile.Mandos",
786
 
                                          "se.bsnet.fukt.Mandos"))
787
 
                # Is this a D-Bus signal?
788
 
                if getattr(attribute, "_dbus_is_signal", False):
789
 
                    # Extract the original non-method function by
790
 
                    # black magic
791
 
                    nonmethod_func = (dict(
792
 
                            zip(attribute.func_code.co_freevars,
793
 
                                attribute.__closure__))["func"]
794
 
                                      .cell_contents)
795
 
                    # Create a new, but exactly alike, function
796
 
                    # object, and decorate it to be a new D-Bus signal
797
 
                    # with the alternate D-Bus interface name
798
 
                    new_function = (dbus.service.signal
799
 
                                    (alt_interface,
800
 
                                     attribute._dbus_signature)
801
 
                                    (types.FunctionType(
802
 
                                nonmethod_func.func_code,
803
 
                                nonmethod_func.func_globals,
804
 
                                nonmethod_func.func_name,
805
 
                                nonmethod_func.func_defaults,
806
 
                                nonmethod_func.func_closure)))
807
 
                    # Define a creator of a function to call both the
808
 
                    # old and new functions, so both the old and new
809
 
                    # signals gets sent when the function is called
810
 
                    def fixscope(func1, func2):
811
 
                        """This function is a scope container to pass
812
 
                        func1 and func2 to the "call_both" function
813
 
                        outside of its arguments"""
814
 
                        def call_both(*args, **kwargs):
815
 
                            """This function will emit two D-Bus
816
 
                            signals by calling func1 and func2"""
817
 
                            func1(*args, **kwargs)
818
 
                            func2(*args, **kwargs)
819
 
                        return call_both
820
 
                    # Create the "call_both" function and add it to
821
 
                    # the class
822
 
                    attr[attrname] = fixscope(attribute,
823
 
                                              new_function)
824
 
                # Is this a D-Bus method?
825
 
                elif getattr(attribute, "_dbus_is_method", False):
826
 
                    # Create a new, but exactly alike, function
827
 
                    # object.  Decorate it to be a new D-Bus method
828
 
                    # with the alternate D-Bus interface name.  Add it
829
 
                    # to the class.
830
 
                    attr[attrname] = (dbus.service.method
831
 
                                      (alt_interface,
832
 
                                       attribute._dbus_in_signature,
833
 
                                       attribute._dbus_out_signature)
834
 
                                      (types.FunctionType
835
 
                                       (attribute.func_code,
836
 
                                        attribute.func_globals,
837
 
                                        attribute.func_name,
838
 
                                        attribute.func_defaults,
839
 
                                        attribute.func_closure)))
840
 
                # Is this a D-Bus property?
841
 
                elif getattr(attribute, "_dbus_is_property", False):
842
 
                    # Create a new, but exactly alike, function
843
 
                    # object, and decorate it to be a new D-Bus
844
 
                    # property with the alternate D-Bus interface
845
 
                    # name.  Add it to the class.
846
 
                    attr[attrname] = (dbus_service_property
847
 
                                      (alt_interface,
848
 
                                       attribute._dbus_signature,
849
 
                                       attribute._dbus_access,
850
 
                                       attribute
851
 
                                       ._dbus_get_args_options
852
 
                                       ["byte_arrays"])
853
 
                                      (types.FunctionType
854
 
                                       (attribute.func_code,
855
 
                                        attribute.func_globals,
856
 
                                        attribute.func_name,
857
 
                                        attribute.func_defaults,
858
 
                                        attribute.func_closure)))
 
760
        for attrname, old_dbusobj in inspect.getmembers(bases[0]):
 
761
            new_interface = getattr(old_dbusobj, "_dbus_interface", "").replace("se.bsnet.fukt.", "se.recompile.")
 
762
            if (getattr(old_dbusobj, "_dbus_is_signal", False)
 
763
                and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
 
764
                unwrappedfunc = dict(zip(old_dbusobj.func_code.co_freevars,
 
765
                                    old_dbusobj.__closure__))["func"].cell_contents
 
766
                newfunc = types.FunctionType(unwrappedfunc.func_code,
 
767
                                             unwrappedfunc.func_globals,
 
768
                                             unwrappedfunc.func_name,
 
769
                                             unwrappedfunc.func_defaults,
 
770
                                             unwrappedfunc.func_closure)
 
771
                new_dbusfunc = dbus.service.signal(
 
772
                    new_interface, old_dbusobj._dbus_signature)(newfunc)            
 
773
                attr["_transitional_" + attrname] = new_dbusfunc
 
774
 
 
775
                def fixscope(func1, func2):
 
776
                    def newcall(*args, **kwargs):
 
777
                        func1(*args, **kwargs)
 
778
                        func2(*args, **kwargs)
 
779
                    return newcall
 
780
 
 
781
                attr[attrname] = fixscope(old_dbusobj, new_dbusfunc)
 
782
            
 
783
            elif (getattr(old_dbusobj, "_dbus_is_method", False)
 
784
                and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
 
785
                new_dbusfunc = (dbus.service.method
 
786
                                (new_interface,
 
787
                                 old_dbusobj._dbus_in_signature,
 
788
                                 old_dbusobj._dbus_out_signature)
 
789
                                (types.FunctionType
 
790
                                 (old_dbusobj.func_code,
 
791
                                  old_dbusobj.func_globals,
 
792
                                  old_dbusobj.func_name,
 
793
                                  old_dbusobj.func_defaults,
 
794
                                  old_dbusobj.func_closure)))
 
795
 
 
796
                attr[attrname] = new_dbusfunc
 
797
            elif (getattr(old_dbusobj, "_dbus_is_property", False)
 
798
                  and old_dbusobj._dbus_interface.startswith("se.bsnet.fukt.Mandos")):
 
799
                new_dbusfunc = (dbus_service_property
 
800
                                (new_interface,
 
801
                                 old_dbusobj._dbus_signature,
 
802
                                 old_dbusobj._dbus_access,
 
803
                                 old_dbusobj._dbus_get_args_options["byte_arrays"])
 
804
                                (types.FunctionType
 
805
                                 (old_dbusobj.func_code,
 
806
                                  old_dbusobj.func_globals,
 
807
                                  old_dbusobj.func_name,
 
808
                                  old_dbusobj.func_defaults,
 
809
                                  old_dbusobj.func_closure)))
 
810
 
 
811
                attr[attrname] = new_dbusfunc
859
812
        return type.__new__(mcs, name, bases, attr)
860
813
 
861
814
class ClientDBus(Client, DBusObjectWithProperties):
888
841
    def notifychangeproperty(transform_func,
889
842
                             dbus_name, type_func=lambda x: x,
890
843
                             variant_level=1):
891
 
        """ Modify a variable so that it's a property which announces
892
 
        its changes to DBus.
893
 
 
894
 
        transform_fun: Function that takes a value and transforms it
895
 
                       to a D-Bus type.
896
 
        dbus_name: D-Bus name of the variable
 
844
        """ Modify a variable so that its a property that announce its
 
845
        changes to DBus.
 
846
        transform_fun: Function that takes a value and transform it to
 
847
                       DBus type.
 
848
        dbus_name: DBus name of the variable
897
849
        type_func: Function that transform the value before sending it
898
 
                   to the D-Bus.  Default: no transform
899
 
        variant_level: D-Bus variant level.  Default: 1
 
850
                   to DBus
 
851
        variant_level: DBus variant level. default: 1
900
852
        """
901
 
        attrname = "_{0}".format(dbus_name)
 
853
        real_value = [None,]
902
854
        def setter(self, value):
 
855
            old_value = real_value[0]
 
856
            real_value[0] = value
903
857
            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),
 
858
                if type_func(old_value) != type_func(real_value[0]):
 
859
                    dbus_value = transform_func(type_func(real_value[0]),
908
860
                                                variant_level)
909
861
                    self.PropertyChanged(dbus.String(dbus_name),
910
862
                                         dbus_value)
911
 
            setattr(self, attrname, value)
912
863
        
913
 
        return property(lambda self: getattr(self, attrname), setter)
 
864
        return property(lambda self: real_value[0], setter)
914
865
    
915
866
    
916
867
    expires = notifychangeproperty(datetime_to_dbus, "Expires")
921
872
    last_enabled = notifychangeproperty(datetime_to_dbus,
922
873
                                        "LastEnabled")
923
874
    checker = notifychangeproperty(dbus.Boolean, "CheckerRunning",
924
 
                                   type_func = lambda checker:
925
 
                                       checker is not None)
 
875
                                   type_func = lambda checker: checker is not None)
926
876
    last_checked_ok = notifychangeproperty(datetime_to_dbus,
927
877
                                           "LastCheckedOK")
928
 
    last_approval_request = notifychangeproperty(
929
 
        datetime_to_dbus, "LastApprovalRequest")
 
878
    last_approval_request = notifychangeproperty(datetime_to_dbus,
 
879
                                                 "LastApprovalRequest")
930
880
    approved_by_default = notifychangeproperty(dbus.Boolean,
931
881
                                               "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)
 
882
    approval_delay = notifychangeproperty(dbus.UInt16, "ApprovalDelay",
 
883
                                          type_func = _timedelta_to_milliseconds)
 
884
    approval_duration = notifychangeproperty(dbus.UInt16, "ApprovalDuration",
 
885
                                             type_func = _timedelta_to_milliseconds)
939
886
    host = notifychangeproperty(dbus.String, "Host")
940
887
    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)
 
888
                                   type_func = _timedelta_to_milliseconds)
 
889
    extended_timeout = notifychangeproperty(dbus.UInt16, "ExtendedTimeout",
 
890
                                            type_func = _timedelta_to_milliseconds)
 
891
    interval = notifychangeproperty(dbus.UInt16, "Interval",
 
892
                                    type_func = _timedelta_to_milliseconds)
950
893
    checker_command = notifychangeproperty(dbus.String, "Checker")
951
894
    
952
895
    del notifychangeproperty
1006
949
    
1007
950
    
1008
951
    ## D-Bus methods, signals & properties
1009
 
    _interface = "se.recompile.Mandos.Client"
1010
 
    
 
952
    _interface = "se.bsnet.fukt.Mandos.Client"
 
953
 
1011
954
    ## Signals
1012
955
    
1013
956
    # CheckerCompleted - signal
1198
1141
            self.disable()
1199
1142
        else:
1200
1143
            self.expires = (datetime.datetime.utcnow()
1201
 
                            + datetime.timedelta(milliseconds =
1202
 
                                                 time_to_die))
 
1144
                            + datetime.timedelta(milliseconds = time_to_die))
1203
1145
            self.disable_initiator_tag = (gobject.timeout_add
1204
1146
                                          (time_to_die, self.disable))
1205
1147
    
1285
1227
        self._pipe.send(('setattr', name, value))
1286
1228
 
1287
1229
class ClientDBusTransitional(ClientDBus):
1288
 
    __metaclass__ = AlternateDBusNamesMetaclass
 
1230
    __metaclass__ = transitional_dbus_metaclass
1289
1231
 
1290
1232
class ClientHandler(socketserver.BaseRequestHandler, object):
1291
1233
    """A class to handle client connections.
1371
1313
                                       client.name)
1372
1314
                        if self.server.use_dbus:
1373
1315
                            # Emit D-Bus signal
1374
 
                            client.Rejected("Disabled")
 
1316
                            client.Rejected("Disabled")                    
1375
1317
                        return
1376
1318
                    
1377
1319
                    if client._approved or not client.approval_delay:
1394
1336
                        return
1395
1337
                    
1396
1338
                    #wait until timeout or approved
 
1339
                    #x = float(client._timedelta_to_milliseconds(delay))
1397
1340
                    time = datetime.datetime.now()
1398
1341
                    client.changedstate.acquire()
1399
 
                    (client.changedstate.wait
1400
 
                     (float(client._timedelta_to_milliseconds(delay)
1401
 
                            / 1000)))
 
1342
                    client.changedstate.wait(float(client._timedelta_to_milliseconds(delay) / 1000))
1402
1343
                    client.changedstate.release()
1403
1344
                    time2 = datetime.datetime.now()
1404
1345
                    if (time2 - time) >= delay:
1428
1369
                    sent_size += sent
1429
1370
                
1430
1371
                logger.info("Sending secret to %s", client.name)
1431
 
                # bump the timeout using extended_timeout
 
1372
                # bump the timeout as if seen
1432
1373
                client.checked_ok(client.extended_timeout)
1433
1374
                if self.server.use_dbus:
1434
1375
                    # Emit D-Bus signal
1514
1455
        except:
1515
1456
            self.handle_error(request, address)
1516
1457
        self.close_request(request)
1517
 
    
 
1458
            
1518
1459
    def process_request(self, request, address):
1519
1460
        """Start a new process to process the request."""
1520
 
        proc = multiprocessing.Process(target = self.sub_process_main,
1521
 
                                       args = (request,
1522
 
                                               address))
1523
 
        proc.start()
1524
 
        return proc
 
1461
        multiprocessing.Process(target = self.sub_process_main,
 
1462
                                args = (request, address)).start()
1525
1463
 
1526
1464
 
1527
1465
class MultiprocessingMixInWithPipe(MultiprocessingMixIn, object):
1533
1471
        """
1534
1472
        parent_pipe, self.child_pipe = multiprocessing.Pipe()
1535
1473
        
1536
 
        proc = MultiprocessingMixIn.process_request(self, request,
1537
 
                                                    client_address)
 
1474
        super(MultiprocessingMixInWithPipe,
 
1475
              self).process_request(request, client_address)
1538
1476
        self.child_pipe.close()
1539
 
        self.add_pipe(parent_pipe, proc)
 
1477
        self.add_pipe(parent_pipe)
1540
1478
    
1541
 
    def add_pipe(self, parent_pipe, proc):
 
1479
    def add_pipe(self, parent_pipe):
1542
1480
        """Dummy function; override as necessary"""
1543
1481
        raise NotImplementedError
1544
1482
 
1632
1570
    def server_activate(self):
1633
1571
        if self.enabled:
1634
1572
            return socketserver.TCPServer.server_activate(self)
1635
 
    
1636
1573
    def enable(self):
1637
1574
        self.enabled = True
1638
 
    
1639
 
    def add_pipe(self, parent_pipe, proc):
 
1575
    def add_pipe(self, parent_pipe):
1640
1576
        # Call "handle_ipc" for both data and EOF events
1641
1577
        gobject.io_add_watch(parent_pipe.fileno(),
1642
1578
                             gobject.IO_IN | gobject.IO_HUP,
1643
1579
                             functools.partial(self.handle_ipc,
1644
 
                                               parent_pipe =
1645
 
                                               parent_pipe,
1646
 
                                               proc = proc))
1647
 
    
 
1580
                                               parent_pipe = parent_pipe))
 
1581
        
1648
1582
    def handle_ipc(self, source, condition, parent_pipe=None,
1649
 
                   proc = None, client_object=None):
 
1583
                   client_object=None):
1650
1584
        condition_names = {
1651
1585
            gobject.IO_IN: "IN",   # There is data to read.
1652
1586
            gobject.IO_OUT: "OUT", # Data can be written (without
1661
1595
                                       for cond, name in
1662
1596
                                       condition_names.iteritems()
1663
1597
                                       if cond & condition)
1664
 
        # error, or the other end of multiprocessing.Pipe has closed
 
1598
        # error or the other end of multiprocessing.Pipe has closed
1665
1599
        if condition & (gobject.IO_ERR | condition & gobject.IO_HUP):
1666
 
            # Wait for other process to exit
1667
 
            proc.join()
1668
1600
            return False
1669
1601
        
1670
1602
        # Read a request from the child
1684
1616
                            "dress: %s", fpr, address)
1685
1617
                if self.use_dbus:
1686
1618
                    # Emit D-Bus signal
1687
 
                    mandos_dbus_service.ClientNotFound(fpr,
1688
 
                                                       address[0])
 
1619
                    mandos_dbus_service.ClientNotFound(fpr, address[0])
1689
1620
                parent_pipe.send(False)
1690
1621
                return False
1691
1622
            
1692
1623
            gobject.io_add_watch(parent_pipe.fileno(),
1693
1624
                                 gobject.IO_IN | gobject.IO_HUP,
1694
1625
                                 functools.partial(self.handle_ipc,
1695
 
                                                   parent_pipe =
1696
 
                                                   parent_pipe,
1697
 
                                                   proc = proc,
1698
 
                                                   client_object =
1699
 
                                                   client))
 
1626
                                                   parent_pipe = parent_pipe,
 
1627
                                                   client_object = client))
1700
1628
            parent_pipe.send(True)
1701
 
            # remove the old hook in favor of the new above hook on
1702
 
            # same fileno
 
1629
            # remove the old hook in favor of the new above hook on same fileno
1703
1630
            return False
1704
1631
        if command == 'funcall':
1705
1632
            funcname = request[1]
1706
1633
            args = request[2]
1707
1634
            kwargs = request[3]
1708
1635
            
1709
 
            parent_pipe.send(('data', getattr(client_object,
1710
 
                                              funcname)(*args,
1711
 
                                                         **kwargs)))
 
1636
            parent_pipe.send(('data', getattr(client_object, funcname)(*args, **kwargs)))
1712
1637
        
1713
1638
        if command == 'getattr':
1714
1639
            attrname = request[1]
1715
1640
            if callable(client_object.__getattribute__(attrname)):
1716
1641
                parent_pipe.send(('function',))
1717
1642
            else:
1718
 
                parent_pipe.send(('data', client_object
1719
 
                                  .__getattribute__(attrname)))
 
1643
                parent_pipe.send(('data', client_object.__getattribute__(attrname)))
1720
1644
        
1721
1645
        if command == 'setattr':
1722
1646
            attrname = request[1]
2011
1935
    # End of Avahi example code
2012
1936
    if use_dbus:
2013
1937
        try:
2014
 
            bus_name = dbus.service.BusName("se.recompile.Mandos",
2015
 
                                            bus, do_not_queue=True)
2016
 
            old_bus_name = (dbus.service.BusName
2017
 
                            ("se.bsnet.fukt.Mandos", bus,
2018
 
                             do_not_queue=True))
 
1938
            bus_name = dbus.service.BusName("se.bsnet.fukt.Mandos",
 
1939
                                            bus, do_not_queue=True)
 
1940
            bus_name2 = dbus.service.BusName("se.recompile.Mandos",
 
1941
                                            bus, do_not_queue=True)
2019
1942
        except dbus.exceptions.NameExistsException as e:
2020
1943
            logger.error(unicode(e) + ", disabling D-Bus")
2021
1944
            use_dbus = False
2034
1957
    
2035
1958
    client_class = Client
2036
1959
    if use_dbus:
2037
 
        client_class = functools.partial(ClientDBusTransitional,
2038
 
                                         bus = bus)
 
1960
        client_class = functools.partial(ClientDBusTransitional, bus = bus)        
2039
1961
    def client_config_items(config, section):
2040
1962
        special_settings = {
2041
1963
            "approved_by_default":
2080
2002
            """A D-Bus proxy object"""
2081
2003
            def __init__(self):
2082
2004
                dbus.service.Object.__init__(self, bus, "/")
2083
 
            _interface = "se.recompile.Mandos"
 
2005
            _interface = "se.bsnet.fukt.Mandos"
2084
2006
            
2085
2007
            @dbus.service.signal(_interface, signature="o")
2086
2008
            def ClientAdded(self, objpath):
2129
2051
            del _interface
2130
2052
        
2131
2053
        class MandosDBusServiceTransitional(MandosDBusService):
2132
 
            __metaclass__ = AlternateDBusNamesMetaclass
 
2054
            __metaclass__ = transitional_dbus_metaclass
2133
2055
        mandos_dbus_service = MandosDBusServiceTransitional()
2134
2056
    
2135
2057
    def cleanup():
2136
2058
        "Cleanup function; run on exit"
2137
2059
        service.cleanup()
2138
2060
        
2139
 
        multiprocessing.active_children()
2140
2061
        while tcp_server.clients:
2141
2062
            client = tcp_server.clients.pop()
2142
2063
            if use_dbus:
2146
2067
            client.disable(quiet=True)
2147
2068
            if use_dbus:
2148
2069
                # Emit D-Bus signal
2149
 
                mandos_dbus_service.ClientRemoved(client
2150
 
                                                  .dbus_object_path,
 
2070
                mandos_dbus_service.ClientRemoved(client.dbus_object_path,
2151
2071
                                                  client.name)
2152
2072
    
2153
2073
    atexit.register(cleanup)