/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

* plugins.d/mandos-client.c (SYNOPSIS, OPTIONS): Document
                                                 "--network-hook-dir"
                                                 option.

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@fukt.bsnet.se>.
 
31
# Contact the authors at <mandos@recompile.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.3.1"
 
86
version = "1.4.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.GetAlternativeServiceName(self.name))
 
163
        self.name = unicode(self.server
 
164
                            .GetAlternativeServiceName(self.name))
164
165
        logger.info("Changing Zeroconf service name to %r ...",
165
166
                    self.name)
166
167
        syslogger.setFormatter(logging.Formatter
321
322
    
322
323
    def extended_timeout_milliseconds(self):
323
324
        "Return the 'extended_timeout' attribute in milliseconds"
324
 
        return _timedelta_to_milliseconds(self.extended_timeout)    
 
325
        return _timedelta_to_milliseconds(self.extended_timeout)
325
326
    
326
327
    def interval_milliseconds(self):
327
328
        "Return the 'interval' attribute in milliseconds"
361
362
        self.last_enabled = None
362
363
        self.last_checked_ok = None
363
364
        self.timeout = string_to_delta(config["timeout"])
364
 
        self.extended_timeout = string_to_delta(config["extended_timeout"])
 
365
        self.extended_timeout = string_to_delta(config
 
366
                                                ["extended_timeout"])
365
367
        self.interval = string_to_delta(config["interval"])
366
368
        self.disable_hook = disable_hook
367
369
        self.checker = None
380
382
            config["approval_delay"])
381
383
        self.approval_duration = string_to_delta(
382
384
            config["approval_duration"])
383
 
        self.changedstate = multiprocessing_manager.Condition(multiprocessing_manager.Lock())
 
385
        self.changedstate = (multiprocessing_manager
 
386
                             .Condition(multiprocessing_manager
 
387
                                        .Lock()))
384
388
    
385
389
    def send_changedstate(self):
386
390
        self.changedstate.acquire()
387
391
        self.changedstate.notify_all()
388
392
        self.changedstate.release()
389
 
        
 
393
    
390
394
    def enable(self):
391
395
        """Start this client's checker and timeout hooks"""
392
396
        if getattr(self, "enabled", False):
460
464
        if timeout is None:
461
465
            timeout = self.timeout
462
466
        self.last_checked_ok = datetime.datetime.utcnow()
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))
 
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
468
474
    
469
475
    def need_approval(self):
470
476
        self.last_approval_request = datetime.datetime.utcnow()
629
635
        """
630
636
        return ((prop.__get__(self)._dbus_name, prop.__get__(self))
631
637
                for cls in self.__class__.__mro__
632
 
                for name, prop in inspect.getmembers(cls, self._is_dbus_property))
 
638
                for name, prop in
 
639
                inspect.getmembers(cls, self._is_dbus_property))
633
640
    
634
641
    def _get_dbus_property(self, interface_name, property_name):
635
642
        """Returns a bound method if one exists which is a D-Bus
636
643
        property with the specified name and interface.
637
644
        """
638
645
        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:
 
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):
641
650
                    return value.__get__(self)
642
651
        
643
652
        # No such property
754
763
    return dbus.String(dt.isoformat(),
755
764
                       variant_level=variant_level)
756
765
 
757
 
class transitional_dbus_metaclass(DBusObjectWithProperties.__metaclass__):
 
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
771
    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
 
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)))
811
861
        return type.__new__(mcs, name, bases, attr)
812
862
 
813
863
class ClientDBus(Client, DBusObjectWithProperties):
840
890
    def notifychangeproperty(transform_func,
841
891
                             dbus_name, type_func=lambda x: x,
842
892
                             variant_level=1):
843
 
        """ Modify a variable so that its a property that announce its
844
 
        changes to DBus.
845
 
        transform_fun: Function that takes a value and transform it to
846
 
                       DBus type.
847
 
        dbus_name: DBus name of the variable
 
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
848
899
        type_func: Function that transform the value before sending it
849
 
                   to DBus
850
 
        variant_level: DBus variant level. default: 1
 
900
                   to the D-Bus.  Default: no transform
 
901
        variant_level: D-Bus variant level.  Default: 1
851
902
        """
852
 
        real_value = [None,]
 
903
        attrname = "_{0}".format(dbus_name)
853
904
        def setter(self, value):
854
 
            old_value = real_value[0]
855
 
            real_value[0] = value
856
905
            if hasattr(self, "dbus_object_path"):
857
 
                if type_func(old_value) != type_func(real_value[0]):
858
 
                    dbus_value = transform_func(type_func(real_value[0]),
859
 
                                                variant_level)
 
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)
860
912
                    self.PropertyChanged(dbus.String(dbus_name),
861
913
                                         dbus_value)
 
914
            setattr(self, attrname, value)
862
915
        
863
 
        return property(lambda self: real_value[0], setter)
 
916
        return property(lambda self: getattr(self, attrname), setter)
864
917
    
865
918
    
866
919
    expires = notifychangeproperty(datetime_to_dbus, "Expires")
871
924
    last_enabled = notifychangeproperty(datetime_to_dbus,
872
925
                                        "LastEnabled")
873
926
    checker = notifychangeproperty(dbus.Boolean, "CheckerRunning",
874
 
                                   type_func = lambda checker: checker is not None)
 
927
                                   type_func = lambda checker:
 
928
                                       checker is not None)
875
929
    last_checked_ok = notifychangeproperty(datetime_to_dbus,
876
930
                                           "LastCheckedOK")
877
 
    last_approval_request = notifychangeproperty(datetime_to_dbus,
878
 
                                                 "LastApprovalRequest")
 
931
    last_approval_request = notifychangeproperty(
 
932
        datetime_to_dbus, "LastApprovalRequest")
879
933
    approved_by_default = notifychangeproperty(dbus.Boolean,
880
934
                                               "ApprovedByDefault")
881
 
    approval_delay = notifychangeproperty(dbus.UInt16, "ApprovalDelay",
882
 
                                          type_func = _timedelta_to_milliseconds)
883
 
    approval_duration = notifychangeproperty(dbus.UInt16, "ApprovalDuration",
884
 
                                             type_func = _timedelta_to_milliseconds)
 
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)
885
942
    host = notifychangeproperty(dbus.String, "Host")
886
943
    timeout = notifychangeproperty(dbus.UInt16, "Timeout",
887
 
                                   type_func = _timedelta_to_milliseconds)
888
 
    extended_timeout = notifychangeproperty(dbus.UInt16, "ExtendedTimeout",
889
 
                                            type_func = _timedelta_to_milliseconds)
890
 
    interval = notifychangeproperty(dbus.UInt16, "Interval",
891
 
                                    type_func = _timedelta_to_milliseconds)
 
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)
892
953
    checker_command = notifychangeproperty(dbus.String, "Checker")
893
954
    
894
955
    del notifychangeproperty
948
1009
    
949
1010
    
950
1011
    ## D-Bus methods, signals & properties
951
 
    _interface = "se.bsnet.fukt.Mandos.Client"
 
1012
    _interface = "se.recompile.Mandos.Client"
952
1013
    
953
1014
    ## Signals
954
1015
    
1129
1190
        gobject.source_remove(self.disable_initiator_tag)
1130
1191
        self.disable_initiator_tag = None
1131
1192
        self.expires = None
1132
 
        time_to_die = (self.
1133
 
                       _timedelta_to_milliseconds((self
1134
 
                                                   .last_checked_ok
1135
 
                                                   + self.timeout)
1136
 
                                                  - datetime.datetime
1137
 
                                                  .utcnow()))
 
1193
        time_to_die = _timedelta_to_milliseconds((self
 
1194
                                                  .last_checked_ok
 
1195
                                                  + self.timeout)
 
1196
                                                 - datetime.datetime
 
1197
                                                 .utcnow())
1138
1198
        if time_to_die <= 0:
1139
1199
            # The timeout has passed
1140
1200
            self.disable()
1141
1201
        else:
1142
1202
            self.expires = (datetime.datetime.utcnow()
1143
 
                            + datetime.timedelta(milliseconds = time_to_die))
 
1203
                            + datetime.timedelta(milliseconds =
 
1204
                                                 time_to_die))
1144
1205
            self.disable_initiator_tag = (gobject.timeout_add
1145
1206
                                          (time_to_die, self.disable))
1146
1207
    
1226
1287
        self._pipe.send(('setattr', name, value))
1227
1288
 
1228
1289
class ClientDBusTransitional(ClientDBus):
1229
 
    __metaclass__ = transitional_dbus_metaclass
 
1290
    __metaclass__ = AlternateDBusNamesMetaclass
1230
1291
 
1231
1292
class ClientHandler(socketserver.BaseRequestHandler, object):
1232
1293
    """A class to handle client connections.
1312
1373
                                       client.name)
1313
1374
                        if self.server.use_dbus:
1314
1375
                            # Emit D-Bus signal
1315
 
                            client.Rejected("Disabled")                    
 
1376
                            client.Rejected("Disabled")
1316
1377
                        return
1317
1378
                    
1318
1379
                    if client._approved or not client.approval_delay:
1335
1396
                        return
1336
1397
                    
1337
1398
                    #wait until timeout or approved
1338
 
                    #x = float(client._timedelta_to_milliseconds(delay))
1339
1399
                    time = datetime.datetime.now()
1340
1400
                    client.changedstate.acquire()
1341
 
                    client.changedstate.wait(float(client._timedelta_to_milliseconds(delay) / 1000))
 
1401
                    (client.changedstate.wait
 
1402
                     (float(client._timedelta_to_milliseconds(delay)
 
1403
                            / 1000)))
1342
1404
                    client.changedstate.release()
1343
1405
                    time2 = datetime.datetime.now()
1344
1406
                    if (time2 - time) >= delay:
1368
1430
                    sent_size += sent
1369
1431
                
1370
1432
                logger.info("Sending secret to %s", client.name)
1371
 
                # bump the timeout as if seen
 
1433
                # bump the timeout using extended_timeout
1372
1434
                client.checked_ok(client.extended_timeout)
1373
1435
                if self.server.use_dbus:
1374
1436
                    # Emit D-Bus signal
1454
1516
        except:
1455
1517
            self.handle_error(request, address)
1456
1518
        self.close_request(request)
1457
 
            
 
1519
    
1458
1520
    def process_request(self, request, address):
1459
1521
        """Start a new process to process the request."""
1460
 
        multiprocessing.Process(target = self.sub_process_main,
1461
 
                                args = (request, address)).start()
 
1522
        proc = multiprocessing.Process(target = self.sub_process_main,
 
1523
                                       args = (request,
 
1524
                                               address))
 
1525
        proc.start()
 
1526
        return proc
1462
1527
 
1463
1528
 
1464
1529
class MultiprocessingMixInWithPipe(MultiprocessingMixIn, object):
1470
1535
        """
1471
1536
        parent_pipe, self.child_pipe = multiprocessing.Pipe()
1472
1537
        
1473
 
        super(MultiprocessingMixInWithPipe,
1474
 
              self).process_request(request, client_address)
 
1538
        proc = MultiprocessingMixIn.process_request(self, request,
 
1539
                                                    client_address)
1475
1540
        self.child_pipe.close()
1476
 
        self.add_pipe(parent_pipe)
 
1541
        self.add_pipe(parent_pipe, proc)
1477
1542
    
1478
 
    def add_pipe(self, parent_pipe):
 
1543
    def add_pipe(self, parent_pipe, proc):
1479
1544
        """Dummy function; override as necessary"""
1480
1545
        raise NotImplementedError
1481
1546
 
1569
1634
    def server_activate(self):
1570
1635
        if self.enabled:
1571
1636
            return socketserver.TCPServer.server_activate(self)
 
1637
    
1572
1638
    def enable(self):
1573
1639
        self.enabled = True
1574
 
    def add_pipe(self, parent_pipe):
 
1640
    
 
1641
    def add_pipe(self, parent_pipe, proc):
1575
1642
        # Call "handle_ipc" for both data and EOF events
1576
1643
        gobject.io_add_watch(parent_pipe.fileno(),
1577
1644
                             gobject.IO_IN | gobject.IO_HUP,
1578
1645
                             functools.partial(self.handle_ipc,
1579
 
                                               parent_pipe = parent_pipe))
1580
 
        
 
1646
                                               parent_pipe =
 
1647
                                               parent_pipe,
 
1648
                                               proc = proc))
 
1649
    
1581
1650
    def handle_ipc(self, source, condition, parent_pipe=None,
1582
 
                   client_object=None):
 
1651
                   proc = None, client_object=None):
1583
1652
        condition_names = {
1584
1653
            gobject.IO_IN: "IN",   # There is data to read.
1585
1654
            gobject.IO_OUT: "OUT", # Data can be written (without
1594
1663
                                       for cond, name in
1595
1664
                                       condition_names.iteritems()
1596
1665
                                       if cond & condition)
1597
 
        # error or the other end of multiprocessing.Pipe has closed
 
1666
        # error, or the other end of multiprocessing.Pipe has closed
1598
1667
        if condition & (gobject.IO_ERR | condition & gobject.IO_HUP):
 
1668
            # Wait for other process to exit
 
1669
            proc.join()
1599
1670
            return False
1600
1671
        
1601
1672
        # Read a request from the child
1615
1686
                            "dress: %s", fpr, address)
1616
1687
                if self.use_dbus:
1617
1688
                    # Emit D-Bus signal
1618
 
                    mandos_dbus_service.ClientNotFound(fpr, address[0])
 
1689
                    mandos_dbus_service.ClientNotFound(fpr,
 
1690
                                                       address[0])
1619
1691
                parent_pipe.send(False)
1620
1692
                return False
1621
1693
            
1622
1694
            gobject.io_add_watch(parent_pipe.fileno(),
1623
1695
                                 gobject.IO_IN | gobject.IO_HUP,
1624
1696
                                 functools.partial(self.handle_ipc,
1625
 
                                                   parent_pipe = parent_pipe,
1626
 
                                                   client_object = client))
 
1697
                                                   parent_pipe =
 
1698
                                                   parent_pipe,
 
1699
                                                   proc = proc,
 
1700
                                                   client_object =
 
1701
                                                   client))
1627
1702
            parent_pipe.send(True)
1628
 
            # remove the old hook in favor of the new above hook on same fileno
 
1703
            # remove the old hook in favor of the new above hook on
 
1704
            # same fileno
1629
1705
            return False
1630
1706
        if command == 'funcall':
1631
1707
            funcname = request[1]
1632
1708
            args = request[2]
1633
1709
            kwargs = request[3]
1634
1710
            
1635
 
            parent_pipe.send(('data', getattr(client_object, funcname)(*args, **kwargs)))
 
1711
            parent_pipe.send(('data', getattr(client_object,
 
1712
                                              funcname)(*args,
 
1713
                                                         **kwargs)))
1636
1714
        
1637
1715
        if command == 'getattr':
1638
1716
            attrname = request[1]
1639
1717
            if callable(client_object.__getattribute__(attrname)):
1640
1718
                parent_pipe.send(('function',))
1641
1719
            else:
1642
 
                parent_pipe.send(('data', client_object.__getattribute__(attrname)))
 
1720
                parent_pipe.send(('data', client_object
 
1721
                                  .__getattribute__(attrname)))
1643
1722
        
1644
1723
        if command == 'setattr':
1645
1724
            attrname = request[1]
1936
2015
        try:
1937
2016
            bus_name = dbus.service.BusName("se.recompile.Mandos",
1938
2017
                                            bus, do_not_queue=True)
1939
 
            bus_name_transitional = dbus.service.BusName("se.bsnet.fukt.Mandos",
1940
 
                                                         bus, do_not_queue=True)
 
2018
            old_bus_name = (dbus.service.BusName
 
2019
                            ("se.bsnet.fukt.Mandos", bus,
 
2020
                             do_not_queue=True))
1941
2021
        except dbus.exceptions.NameExistsException as e:
1942
2022
            logger.error(unicode(e) + ", disabling D-Bus")
1943
2023
            use_dbus = False
1956
2036
    
1957
2037
    client_class = Client
1958
2038
    if use_dbus:
1959
 
        client_class = functools.partial(ClientDBusTransitional, bus = bus)        
 
2039
        client_class = functools.partial(ClientDBusTransitional,
 
2040
                                         bus = bus)
1960
2041
    def client_config_items(config, section):
1961
2042
        special_settings = {
1962
2043
            "approved_by_default":
2001
2082
            """A D-Bus proxy object"""
2002
2083
            def __init__(self):
2003
2084
                dbus.service.Object.__init__(self, bus, "/")
2004
 
            _interface = "se.bsnet.fukt.Mandos"
 
2085
            _interface = "se.recompile.Mandos"
2005
2086
            
2006
2087
            @dbus.service.signal(_interface, signature="o")
2007
2088
            def ClientAdded(self, objpath):
2050
2131
            del _interface
2051
2132
        
2052
2133
        class MandosDBusServiceTransitional(MandosDBusService):
2053
 
            __metaclass__ = transitional_dbus_metaclass
 
2134
            __metaclass__ = AlternateDBusNamesMetaclass
2054
2135
        mandos_dbus_service = MandosDBusServiceTransitional()
2055
2136
    
2056
2137
    def cleanup():
2057
2138
        "Cleanup function; run on exit"
2058
2139
        service.cleanup()
2059
2140
        
 
2141
        multiprocessing.active_children()
2060
2142
        while tcp_server.clients:
2061
2143
            client = tcp_server.clients.pop()
2062
2144
            if use_dbus:
2066
2148
            client.disable(quiet=True)
2067
2149
            if use_dbus:
2068
2150
                # Emit D-Bus signal
2069
 
                mandos_dbus_service.ClientRemoved(client.dbus_object_path,
 
2151
                mandos_dbus_service.ClientRemoved(client
 
2152
                                                  .dbus_object_path,
2070
2153
                                                  client.name)
2071
2154
    
2072
2155
    atexit.register(cleanup)