/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release

« back to all changes in this revision

Viewing changes to mandos

* initramfs-tools-hook: Set DEVICE for network hooks.

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()
627
633
    def _get_all_dbus_properties(self):
628
634
        """Returns a generator of (name, attribute) pairs
629
635
        """
630
 
        return ((prop._dbus_name, prop)
 
636
        return ((prop.__get__(self)._dbus_name, prop.__get__(self))
 
637
                for cls in self.__class__.__mro__
631
638
                for name, prop in
632
 
                inspect.getmembers(self, self._is_dbus_property))
 
639
                inspect.getmembers(cls, self._is_dbus_property))
633
640
    
634
 
#    def _get_dbus_property(self, interface_name, property_name):
635
 
#        """Returns a bound method if one exists which is a D-Bus
636
 
#        property with the specified name and interface.
637
 
#        """
638
 
#        print("get_property({0!r}, {1!r}".format(interface_name, property_name),file=sys.stderr)
639
 
#        print(dir(self), sys.stderr)
640
 
#        for name in (property_name,
641
 
#                     property_name + "_dbus_property"):
642
 
#            prop = getattr(self, name, None)
643
 
#            if (prop is None
644
 
#                or not self._is_dbus_property(prop)
645
 
#                or prop._dbus_name != property_name
646
 
#                or (interface_name and prop._dbus_interface
647
 
#                    and interface_name != prop._dbus_interface)):
648
 
#                continue
649
 
#            return prop
650
 
#        # No such property
651
 
#        raise DBusPropertyNotFound(self.dbus_object_path + ":"
652
 
#                                   + interface_name + "."
653
 
#                                   + property_name)
654
 
 
655
641
    def _get_dbus_property(self, interface_name, property_name):
656
642
        """Returns a bound method if one exists which is a D-Bus
657
643
        property with the specified name and interface.
658
644
        """
659
 
        for name, value in inspect.getmembers(self, self._is_dbus_property):
660
 
            if value._dbus_name == property_name and value._dbus_interface == interface_name:
661
 
                return value
 
645
        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):
 
650
                    return value.__get__(self)
662
651
        
663
652
        # No such property
664
653
        raise DBusPropertyNotFound(self.dbus_object_path + ":"
665
654
                                   + interface_name + "."
666
655
                                   + property_name)
667
 
 
668
656
    
669
657
    @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature="ss",
670
658
                         out_signature="v")
775
763
    return dbus.String(dt.isoformat(),
776
764
                       variant_level=variant_level)
777
765
 
778
 
class transitional_clientdbus(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
    """
779
771
    def __new__(mcs, name, bases, attr):
780
 
        for key, old_dbusobj in attr.items():
781
 
            new_interface = getattr(old_dbusobj, "_dbus_interface", "").replace("se.bsnet.fukt.", "se.recompile.")
782
 
            if getattr(old_dbusobj, "_dbus_is_signal", False):
783
 
                unwrappedfunc = dict(zip(old_dbusobj.func_code.co_freevars,
784
 
                                    old_dbusobj.__closure__))["func"].cell_contents
785
 
                newfunc = types.FunctionType(unwrappedfunc.func_code,
786
 
                                             unwrappedfunc.func_globals,
787
 
                                             unwrappedfunc.func_name,
788
 
                                             unwrappedfunc.func_defaults,
789
 
                                             unwrappedfunc.func_closure)
790
 
                new_dbusfunc = dbus.service.signal(
791
 
                    new_interface, old_dbusobj._dbus_signature)(newfunc)            
792
 
                attr["_transitional_{0}_1".format(key)] = new_dbusfunc
793
 
                attr["_transitional_{0}_0".format(key)] = old_dbusobj                
794
 
                def fixscope(func1, func2):
795
 
                    def newcall(*args, **kwargs):
796
 
                        func1(*args, **kwargs)
797
 
                        func2(*args, **kwargs)
798
 
                    return newcall
799
 
 
800
 
                attr[key] = fixscope(
801
 
                    old_dbusobj, attr["_transitional_{0}_1".format(key)])
802
 
            
803
 
            if getattr(old_dbusobj, "_dbus_is_method", False):
804
 
                new_dbusfunc = (dbus.service.method
805
 
                                (new_interface,
806
 
                                 old_dbusobj._dbus_in_signature,
807
 
                                 old_dbusobj._dbus_out_signature)
808
 
                                (types.FunctionType
809
 
                                 (old_dbusobj.func_code,
810
 
                                  old_dbusobj.func_globals,
811
 
                                  old_dbusobj.func_name,
812
 
                                  old_dbusobj.func_defaults,
813
 
                                  old_dbusobj.func_closure)))
814
 
 
815
 
                attr["_transitional_{0}".format(key)] = new_dbusfunc
816
 
            if getattr(old_dbusobj, "_dbus_is_property", False):
817
 
                new_dbusfunc = (dbus_service_property
818
 
                                (new_interface,
819
 
                                 old_dbusobj._dbus_signature,
820
 
                                 old_dbusobj._dbus_access,
821
 
                                 old_dbusobj._dbus_get_args_options["byte_arrays"])
822
 
                                (types.FunctionType
823
 
                                 (old_dbusobj.func_code,
824
 
                                  old_dbusobj.func_globals,
825
 
                                  old_dbusobj.func_name,
826
 
                                  old_dbusobj.func_defaults,
827
 
                                  old_dbusobj.func_closure)))
828
 
 
829
 
                attr["_transitional_{0}".format(key)] = 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)))
830
861
        return type.__new__(mcs, name, bases, attr)
831
862
 
832
863
class ClientDBus(Client, DBusObjectWithProperties):
839
870
    
840
871
    runtime_expansions = (Client.runtime_expansions
841
872
                          + ("dbus_object_path",))
842
 
 
843
 
    __metaclass__ = transitional_clientdbus
844
873
    
845
874
    # dbus.service.Object doesn't use super(), so we can't either.
846
875
    
861
890
    def notifychangeproperty(transform_func,
862
891
                             dbus_name, type_func=lambda x: x,
863
892
                             variant_level=1):
864
 
        """ Modify a variable so that its a property that announce its
865
 
        changes to DBus.
866
 
        transform_fun: Function that takes a value and transform it to
867
 
                       DBus type.
868
 
        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
869
899
        type_func: Function that transform the value before sending it
870
 
                   to DBus
871
 
        variant_level: DBus variant level. default: 1
 
900
                   to the D-Bus.  Default: no transform
 
901
        variant_level: D-Bus variant level.  Default: 1
872
902
        """
873
 
        real_value = [None,]
 
903
        attrname = "_{0}".format(dbus_name)
874
904
        def setter(self, value):
875
 
            old_value = real_value[0]
876
 
            real_value[0] = value
877
905
            if hasattr(self, "dbus_object_path"):
878
 
                if type_func(old_value) != type_func(real_value[0]):
879
 
                    dbus_value = transform_func(type_func(real_value[0]),
880
 
                                                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)
881
912
                    self.PropertyChanged(dbus.String(dbus_name),
882
913
                                         dbus_value)
 
914
            setattr(self, attrname, value)
883
915
        
884
 
        return property(lambda self: real_value[0], setter)
 
916
        return property(lambda self: getattr(self, attrname), setter)
885
917
    
886
918
    
887
919
    expires = notifychangeproperty(datetime_to_dbus, "Expires")
892
924
    last_enabled = notifychangeproperty(datetime_to_dbus,
893
925
                                        "LastEnabled")
894
926
    checker = notifychangeproperty(dbus.Boolean, "CheckerRunning",
895
 
                                   type_func = lambda checker: checker is not None)
 
927
                                   type_func = lambda checker:
 
928
                                       checker is not None)
896
929
    last_checked_ok = notifychangeproperty(datetime_to_dbus,
897
930
                                           "LastCheckedOK")
898
 
    last_approval_request = notifychangeproperty(datetime_to_dbus,
899
 
                                                 "LastApprovalRequest")
 
931
    last_approval_request = notifychangeproperty(
 
932
        datetime_to_dbus, "LastApprovalRequest")
900
933
    approved_by_default = notifychangeproperty(dbus.Boolean,
901
934
                                               "ApprovedByDefault")
902
 
    approval_delay = notifychangeproperty(dbus.UInt16, "ApprovalDelay",
903
 
                                          type_func = _timedelta_to_milliseconds)
904
 
    approval_duration = notifychangeproperty(dbus.UInt16, "ApprovalDuration",
905
 
                                             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)
906
942
    host = notifychangeproperty(dbus.String, "Host")
907
943
    timeout = notifychangeproperty(dbus.UInt16, "Timeout",
908
 
                                   type_func = _timedelta_to_milliseconds)
909
 
    extended_timeout = notifychangeproperty(dbus.UInt16, "ExtendedTimeout",
910
 
                                            type_func = _timedelta_to_milliseconds)
911
 
    interval = notifychangeproperty(dbus.UInt16, "Interval",
912
 
                                    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)
913
953
    checker_command = notifychangeproperty(dbus.String, "Checker")
914
954
    
915
955
    del notifychangeproperty
969
1009
    
970
1010
    
971
1011
    ## D-Bus methods, signals & properties
972
 
    _interface = "se.bsnet.fukt.Mandos.Client"
973
 
 
 
1012
    _interface = "se.recompile.Mandos.Client"
 
1013
    
974
1014
    ## Signals
975
1015
    
976
1016
    # CheckerCompleted - signal
1150
1190
        gobject.source_remove(self.disable_initiator_tag)
1151
1191
        self.disable_initiator_tag = None
1152
1192
        self.expires = None
1153
 
        time_to_die = (self.
1154
 
                       _timedelta_to_milliseconds((self
1155
 
                                                   .last_checked_ok
1156
 
                                                   + self.timeout)
1157
 
                                                  - datetime.datetime
1158
 
                                                  .utcnow()))
 
1193
        time_to_die = _timedelta_to_milliseconds((self
 
1194
                                                  .last_checked_ok
 
1195
                                                  + self.timeout)
 
1196
                                                 - datetime.datetime
 
1197
                                                 .utcnow())
1159
1198
        if time_to_die <= 0:
1160
1199
            # The timeout has passed
1161
1200
            self.disable()
1162
1201
        else:
1163
1202
            self.expires = (datetime.datetime.utcnow()
1164
 
                            + datetime.timedelta(milliseconds = time_to_die))
 
1203
                            + datetime.timedelta(milliseconds =
 
1204
                                                 time_to_die))
1165
1205
            self.disable_initiator_tag = (gobject.timeout_add
1166
1206
                                          (time_to_die, self.disable))
1167
1207
    
1246
1286
            return super(ProxyClient, self).__setattr__(name, value)
1247
1287
        self._pipe.send(('setattr', name, value))
1248
1288
 
 
1289
class ClientDBusTransitional(ClientDBus):
 
1290
    __metaclass__ = AlternateDBusNamesMetaclass
1249
1291
 
1250
1292
class ClientHandler(socketserver.BaseRequestHandler, object):
1251
1293
    """A class to handle client connections.
1331
1373
                                       client.name)
1332
1374
                        if self.server.use_dbus:
1333
1375
                            # Emit D-Bus signal
1334
 
                            client.Rejected("Disabled")                    
 
1376
                            client.Rejected("Disabled")
1335
1377
                        return
1336
1378
                    
1337
1379
                    if client._approved or not client.approval_delay:
1354
1396
                        return
1355
1397
                    
1356
1398
                    #wait until timeout or approved
1357
 
                    #x = float(client._timedelta_to_milliseconds(delay))
1358
1399
                    time = datetime.datetime.now()
1359
1400
                    client.changedstate.acquire()
1360
 
                    client.changedstate.wait(float(client._timedelta_to_milliseconds(delay) / 1000))
 
1401
                    (client.changedstate.wait
 
1402
                     (float(client._timedelta_to_milliseconds(delay)
 
1403
                            / 1000)))
1361
1404
                    client.changedstate.release()
1362
1405
                    time2 = datetime.datetime.now()
1363
1406
                    if (time2 - time) >= delay:
1387
1430
                    sent_size += sent
1388
1431
                
1389
1432
                logger.info("Sending secret to %s", client.name)
1390
 
                # bump the timeout as if seen
 
1433
                # bump the timeout using extended_timeout
1391
1434
                client.checked_ok(client.extended_timeout)
1392
1435
                if self.server.use_dbus:
1393
1436
                    # Emit D-Bus signal
1473
1516
        except:
1474
1517
            self.handle_error(request, address)
1475
1518
        self.close_request(request)
1476
 
            
 
1519
    
1477
1520
    def process_request(self, request, address):
1478
1521
        """Start a new process to process the request."""
1479
 
        multiprocessing.Process(target = self.sub_process_main,
1480
 
                                args = (request, address)).start()
 
1522
        proc = multiprocessing.Process(target = self.sub_process_main,
 
1523
                                       args = (request,
 
1524
                                               address))
 
1525
        proc.start()
 
1526
        return proc
1481
1527
 
1482
1528
 
1483
1529
class MultiprocessingMixInWithPipe(MultiprocessingMixIn, object):
1489
1535
        """
1490
1536
        parent_pipe, self.child_pipe = multiprocessing.Pipe()
1491
1537
        
1492
 
        super(MultiprocessingMixInWithPipe,
1493
 
              self).process_request(request, client_address)
 
1538
        proc = MultiprocessingMixIn.process_request(self, request,
 
1539
                                                    client_address)
1494
1540
        self.child_pipe.close()
1495
 
        self.add_pipe(parent_pipe)
 
1541
        self.add_pipe(parent_pipe, proc)
1496
1542
    
1497
 
    def add_pipe(self, parent_pipe):
 
1543
    def add_pipe(self, parent_pipe, proc):
1498
1544
        """Dummy function; override as necessary"""
1499
1545
        raise NotImplementedError
1500
1546
 
1588
1634
    def server_activate(self):
1589
1635
        if self.enabled:
1590
1636
            return socketserver.TCPServer.server_activate(self)
 
1637
    
1591
1638
    def enable(self):
1592
1639
        self.enabled = True
1593
 
    def add_pipe(self, parent_pipe):
 
1640
    
 
1641
    def add_pipe(self, parent_pipe, proc):
1594
1642
        # Call "handle_ipc" for both data and EOF events
1595
1643
        gobject.io_add_watch(parent_pipe.fileno(),
1596
1644
                             gobject.IO_IN | gobject.IO_HUP,
1597
1645
                             functools.partial(self.handle_ipc,
1598
 
                                               parent_pipe = parent_pipe))
1599
 
        
 
1646
                                               parent_pipe =
 
1647
                                               parent_pipe,
 
1648
                                               proc = proc))
 
1649
    
1600
1650
    def handle_ipc(self, source, condition, parent_pipe=None,
1601
 
                   client_object=None):
 
1651
                   proc = None, client_object=None):
1602
1652
        condition_names = {
1603
1653
            gobject.IO_IN: "IN",   # There is data to read.
1604
1654
            gobject.IO_OUT: "OUT", # Data can be written (without
1613
1663
                                       for cond, name in
1614
1664
                                       condition_names.iteritems()
1615
1665
                                       if cond & condition)
1616
 
        # error or the other end of multiprocessing.Pipe has closed
 
1666
        # error, or the other end of multiprocessing.Pipe has closed
1617
1667
        if condition & (gobject.IO_ERR | condition & gobject.IO_HUP):
 
1668
            # Wait for other process to exit
 
1669
            proc.join()
1618
1670
            return False
1619
1671
        
1620
1672
        # Read a request from the child
1634
1686
                            "dress: %s", fpr, address)
1635
1687
                if self.use_dbus:
1636
1688
                    # Emit D-Bus signal
1637
 
                    mandos_dbus_service.ClientNotFound(fpr, address[0])
 
1689
                    mandos_dbus_service.ClientNotFound(fpr,
 
1690
                                                       address[0])
1638
1691
                parent_pipe.send(False)
1639
1692
                return False
1640
1693
            
1641
1694
            gobject.io_add_watch(parent_pipe.fileno(),
1642
1695
                                 gobject.IO_IN | gobject.IO_HUP,
1643
1696
                                 functools.partial(self.handle_ipc,
1644
 
                                                   parent_pipe = parent_pipe,
1645
 
                                                   client_object = client))
 
1697
                                                   parent_pipe =
 
1698
                                                   parent_pipe,
 
1699
                                                   proc = proc,
 
1700
                                                   client_object =
 
1701
                                                   client))
1646
1702
            parent_pipe.send(True)
1647
 
            # 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
1648
1705
            return False
1649
1706
        if command == 'funcall':
1650
1707
            funcname = request[1]
1651
1708
            args = request[2]
1652
1709
            kwargs = request[3]
1653
1710
            
1654
 
            parent_pipe.send(('data', getattr(client_object, funcname)(*args, **kwargs)))
 
1711
            parent_pipe.send(('data', getattr(client_object,
 
1712
                                              funcname)(*args,
 
1713
                                                         **kwargs)))
1655
1714
        
1656
1715
        if command == 'getattr':
1657
1716
            attrname = request[1]
1658
1717
            if callable(client_object.__getattribute__(attrname)):
1659
1718
                parent_pipe.send(('function',))
1660
1719
            else:
1661
 
                parent_pipe.send(('data', client_object.__getattribute__(attrname)))
 
1720
                parent_pipe.send(('data', client_object
 
1721
                                  .__getattribute__(attrname)))
1662
1722
        
1663
1723
        if command == 'setattr':
1664
1724
            attrname = request[1]
1953
2013
    # End of Avahi example code
1954
2014
    if use_dbus:
1955
2015
        try:
1956
 
            bus_name = dbus.service.BusName("se.bsnet.fukt.Mandos",
1957
 
                                            bus, do_not_queue=True)
1958
 
            bus_name2 = dbus.service.BusName("se.recompile.Mandos",
1959
 
                                            bus, do_not_queue=True)
 
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))
1960
2021
        except dbus.exceptions.NameExistsException as e:
1961
2022
            logger.error(unicode(e) + ", disabling D-Bus")
1962
2023
            use_dbus = False
1975
2036
    
1976
2037
    client_class = Client
1977
2038
    if use_dbus:
1978
 
        client_class = functools.partial(ClientDBus, bus = bus)
 
2039
        client_class = functools.partial(ClientDBusTransitional,
 
2040
                                         bus = bus)
1979
2041
    def client_config_items(config, section):
1980
2042
        special_settings = {
1981
2043
            "approved_by_default":
2020
2082
            """A D-Bus proxy object"""
2021
2083
            def __init__(self):
2022
2084
                dbus.service.Object.__init__(self, bus, "/")
2023
 
            _interface = "se.bsnet.fukt.Mandos"
 
2085
            _interface = "se.recompile.Mandos"
2024
2086
            
2025
2087
            @dbus.service.signal(_interface, signature="o")
2026
2088
            def ClientAdded(self, objpath):
2068
2130
            
2069
2131
            del _interface
2070
2132
        
2071
 
        mandos_dbus_service = MandosDBusService()
 
2133
        class MandosDBusServiceTransitional(MandosDBusService):
 
2134
            __metaclass__ = AlternateDBusNamesMetaclass
 
2135
        mandos_dbus_service = MandosDBusServiceTransitional()
2072
2136
    
2073
2137
    def cleanup():
2074
2138
        "Cleanup function; run on exit"
2075
2139
        service.cleanup()
2076
2140
        
 
2141
        multiprocessing.active_children()
2077
2142
        while tcp_server.clients:
2078
2143
            client = tcp_server.clients.pop()
2079
2144
            if use_dbus:
2083
2148
            client.disable(quiet=True)
2084
2149
            if use_dbus:
2085
2150
                # Emit D-Bus signal
2086
 
                mandos_dbus_service.ClientRemoved(client.dbus_object_path,
 
2151
                mandos_dbus_service.ClientRemoved(client
 
2152
                                                  .dbus_object_path,
2087
2153
                                                  client.name)
2088
2154
    
2089
2155
    atexit.register(cleanup)