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