314
313
"created", "enabled", "fingerprint",
315
314
"host", "interval", "last_checked_ok",
316
315
"last_enabled", "name", "timeout")
318
317
def timeout_milliseconds(self):
319
318
"Return the 'timeout' attribute in milliseconds"
320
319
return _timedelta_to_milliseconds(self.timeout)
322
321
def extended_timeout_milliseconds(self):
323
322
"Return the 'extended_timeout' attribute in milliseconds"
324
323
return _timedelta_to_milliseconds(self.extended_timeout)
627
625
def _get_all_dbus_properties(self):
628
626
"""Returns a generator of (name, attribute) pairs
630
return ((prop.__get__(self)._dbus_name, prop.__get__(self))
631
for cls in self.__class__.__mro__
632
for name, prop in inspect.getmembers(cls, self._is_dbus_property))
628
return ((prop._dbus_name, prop)
630
inspect.getmembers(self, self._is_dbus_property))
634
632
def _get_dbus_property(self, interface_name, property_name):
635
633
"""Returns a bound method if one exists which is a D-Bus
636
634
property with the specified name and interface.
638
for cls in self.__class__.__mro__:
639
for name, value in inspect.getmembers(cls, self._is_dbus_property):
640
if value._dbus_name == property_name and value._dbus_interface == interface_name:
641
return value.__get__(self)
636
for name in (property_name,
637
property_name + "_dbus_property"):
638
prop = getattr(self, name, None)
640
or not self._is_dbus_property(prop)
641
or prop._dbus_name != property_name
642
or (interface_name and prop._dbus_interface
643
and interface_name != prop._dbus_interface)):
643
646
# No such property
644
647
raise DBusPropertyNotFound(self.dbus_object_path + ":"
645
648
+ interface_name + "."
649
651
@dbus.service.method(dbus.PROPERTIES_IFACE, in_signature="ss",
650
652
out_signature="v")
755
757
return dbus.String(dt.isoformat(),
756
758
variant_level=variant_level)
758
class transitional_dbus_metaclass(DBusObjectWithProperties.__metaclass__):
759
def __new__(mcs, name, bases, attr):
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
775
def fixscope(func1, func2):
776
def newcall(*args, **kwargs):
777
func1(*args, **kwargs)
778
func2(*args, **kwargs)
781
attr[attrname] = fixscope(old_dbusobj, new_dbusfunc)
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
787
old_dbusobj._dbus_in_signature,
788
old_dbusobj._dbus_out_signature)
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)))
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
801
old_dbusobj._dbus_signature,
802
old_dbusobj._dbus_access,
803
old_dbusobj._dbus_get_args_options["byte_arrays"])
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)))
811
attr[attrname] = new_dbusfunc
812
return type.__new__(mcs, name, bases, attr)
814
760
class ClientDBus(Client, DBusObjectWithProperties):
815
761
"""A Client class using D-Bus
1220
1166
self._pipe.send(('funcall', name, args, kwargs))
1221
1167
return self._pipe.recv()[1]
1224
1170
def __setattr__(self, name, value):
1225
1171
if(name == '_pipe'):
1226
1172
return super(ProxyClient, self).__setattr__(name, value)
1227
1173
self._pipe.send(('setattr', name, value))
1229
class ClientDBusTransitional(ClientDBus):
1230
__metaclass__ = transitional_dbus_metaclass
1232
1176
class ClientHandler(socketserver.BaseRequestHandler, object):
1233
1177
"""A class to handle client connections.
1241
1185
unicode(self.client_address))
1242
1186
logger.debug("Pipe FD: %d",
1243
1187
self.server.child_pipe.fileno())
1245
1189
session = (gnutls.connection
1246
1190
.ClientSession(self.request,
1247
1191
gnutls.connection
1248
1192
.X509Credentials()))
1250
1194
# Note: gnutls.connection.X509Credentials is really a
1251
1195
# generic GnuTLS certificate credentials object so long as
1252
1196
# no X.509 keys are added to it. Therefore, we can use it
1253
1197
# here despite using OpenPGP certificates.
1255
1199
#priority = ':'.join(("NONE", "+VERS-TLS1.1",
1256
1200
# "+AES-256-CBC", "+SHA1",
1257
1201
# "+COMP-NULL", "+CTYPE-OPENPGP",
1470
1413
This function creates a new pipe in self.pipe
1472
1415
parent_pipe, self.child_pipe = multiprocessing.Pipe()
1474
1417
super(MultiprocessingMixInWithPipe,
1475
1418
self).process_request(request, client_address)
1476
1419
self.child_pipe.close()
1477
1420
self.add_pipe(parent_pipe)
1479
1422
def add_pipe(self, parent_pipe):
1480
1423
"""Dummy function; override as necessary"""
1481
1424
raise NotImplementedError
1484
1426
class IPv6_TCPServer(MultiprocessingMixInWithPipe,
1485
1427
socketserver.TCPServer, object):
1486
1428
"""IPv6-capable TCP server. Accepts 'None' as address and/or port