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 ...",
167
166
syslogger.setFormatter(logging.Formatter
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)
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
383
self.changedstate = multiprocessing_manager.Condition(multiprocessing_manager.Lock())
389
385
def send_changedstate(self):
390
386
self.changedstate.acquire()
391
387
self.changedstate.notify_all()
392
388
self.changedstate.release()
394
390
def enable(self):
395
391
"""Start this client's checker and timeout hooks"""
396
392
if getattr(self, "enabled", False):
467
463
gobject.source_remove(self.disable_initiator_tag)
468
464
self.expires = datetime.datetime.utcnow() + timeout
469
465
self.disable_initiator_tag = (gobject.timeout_add
470
(_timedelta_to_milliseconds
471
(timeout), self.disable))
466
(_timedelta_to_milliseconds(timeout),
473
469
def need_approval(self):
474
470
self.last_approval_request = datetime.datetime.utcnow()
634
630
return ((prop.__get__(self)._dbus_name, prop.__get__(self))
635
631
for cls in self.__class__.__mro__
637
inspect.getmembers(cls, self._is_dbus_property))
632
for name, prop in inspect.getmembers(cls, self._is_dbus_property))
639
634
def _get_dbus_property(self, interface_name, property_name):
640
635
"""Returns a bound method if one exists which is a D-Bus
641
636
property with the specified name and interface.
643
638
for cls in self.__class__.__mro__:
644
for name, value in (inspect.getmembers
645
(cls, self._is_dbus_property)):
646
if (value._dbus_name == property_name
647
and value._dbus_interface == interface_name):
639
for name, value in inspect.getmembers(cls, self._is_dbus_property):
640
if value._dbus_name == property_name and value._dbus_interface == interface_name:
648
641
return value.__get__(self)
650
643
# No such property
761
754
return dbus.String(dt.isoformat(),
762
755
variant_level=variant_level)
764
class AlternateDBusNamesMetaclass(DBusObjectWithProperties
757
class AlternateDBusNamesMetaclass(DBusObjectWithProperties.__metaclass__):
766
758
"""Applied to an empty subclass of a D-Bus object, this metaclass
767
759
will add additional D-Bus attributes matching a certain pattern.
898
890
to the D-Bus. Default: no transform
899
891
variant_level: D-Bus variant level. Default: 1
901
attrname = "_{0}".format(dbus_name)
902
894
def setter(self, value):
895
old_value = real_value[0]
896
real_value[0] = value
903
897
if hasattr(self, "dbus_object_path"):
904
if (not hasattr(self, attrname) or
905
type_func(getattr(self, attrname, None))
906
!= type_func(value)):
907
dbus_value = transform_func(type_func(value),
898
if type_func(old_value) != type_func(real_value[0]):
899
dbus_value = transform_func(type_func(real_value[0]),
909
901
self.PropertyChanged(dbus.String(dbus_name),
911
setattr(self, attrname, value)
913
return property(lambda self: getattr(self, attrname), setter)
904
return property(lambda self: real_value[0], setter)
916
907
expires = notifychangeproperty(datetime_to_dbus, "Expires")
921
912
last_enabled = notifychangeproperty(datetime_to_dbus,
923
914
checker = notifychangeproperty(dbus.Boolean, "CheckerRunning",
924
type_func = lambda checker:
915
type_func = lambda checker: checker is not None)
926
916
last_checked_ok = notifychangeproperty(datetime_to_dbus,
928
last_approval_request = notifychangeproperty(
929
datetime_to_dbus, "LastApprovalRequest")
918
last_approval_request = notifychangeproperty(datetime_to_dbus,
919
"LastApprovalRequest")
930
920
approved_by_default = notifychangeproperty(dbus.Boolean,
931
921
"ApprovedByDefault")
932
approval_delay = notifychangeproperty(dbus.UInt16,
935
_timedelta_to_milliseconds)
936
approval_duration = notifychangeproperty(
937
dbus.UInt16, "ApprovalDuration",
938
type_func = _timedelta_to_milliseconds)
922
approval_delay = notifychangeproperty(dbus.UInt16, "ApprovalDelay",
923
type_func = _timedelta_to_milliseconds)
924
approval_duration = notifychangeproperty(dbus.UInt16, "ApprovalDuration",
925
type_func = _timedelta_to_milliseconds)
939
926
host = notifychangeproperty(dbus.String, "Host")
940
927
timeout = notifychangeproperty(dbus.UInt16, "Timeout",
942
_timedelta_to_milliseconds)
943
extended_timeout = notifychangeproperty(
944
dbus.UInt16, "ExtendedTimeout",
945
type_func = _timedelta_to_milliseconds)
946
interval = notifychangeproperty(dbus.UInt16,
949
_timedelta_to_milliseconds)
928
type_func = _timedelta_to_milliseconds)
929
extended_timeout = notifychangeproperty(dbus.UInt16, "ExtendedTimeout",
930
type_func = _timedelta_to_milliseconds)
931
interval = notifychangeproperty(dbus.UInt16, "Interval",
932
type_func = _timedelta_to_milliseconds)
950
933
checker_command = notifychangeproperty(dbus.String, "Checker")
952
935
del notifychangeproperty
1200
1183
self.expires = (datetime.datetime.utcnow()
1201
+ datetime.timedelta(milliseconds =
1184
+ datetime.timedelta(milliseconds = time_to_die))
1203
1185
self.disable_initiator_tag = (gobject.timeout_add
1204
1186
(time_to_die, self.disable))
1396
1378
#wait until timeout or approved
1398
# ._timedelta_to_milliseconds(delay))
1379
#x = float(client._timedelta_to_milliseconds(delay))
1399
1380
time = datetime.datetime.now()
1400
1381
client.changedstate.acquire()
1401
(client.changedstate.wait
1402
(float(client._timedelta_to_milliseconds(delay)
1382
client.changedstate.wait(float(client._timedelta_to_milliseconds(delay) / 1000))
1404
1383
client.changedstate.release()
1405
1384
time2 = datetime.datetime.now()
1406
1385
if (time2 - time) >= delay:
1638
1617
gobject.io_add_watch(parent_pipe.fileno(),
1639
1618
gobject.IO_IN | gobject.IO_HUP,
1640
1619
functools.partial(self.handle_ipc,
1620
parent_pipe = parent_pipe))
1644
1622
def handle_ipc(self, source, condition, parent_pipe=None,
1645
1623
client_object=None):
1678
1656
"dress: %s", fpr, address)
1679
1657
if self.use_dbus:
1680
1658
# Emit D-Bus signal
1681
mandos_dbus_service.ClientNotFound(fpr,
1659
mandos_dbus_service.ClientNotFound(fpr, address[0])
1683
1660
parent_pipe.send(False)
1686
1663
gobject.io_add_watch(parent_pipe.fileno(),
1687
1664
gobject.IO_IN | gobject.IO_HUP,
1688
1665
functools.partial(self.handle_ipc,
1666
parent_pipe = parent_pipe,
1667
client_object = client))
1693
1668
parent_pipe.send(True)
1694
# remove the old hook in favor of the new above hook on
1669
# remove the old hook in favor of the new above hook on same fileno
1697
1671
if command == 'funcall':
1698
1672
funcname = request[1]
1699
1673
args = request[2]
1700
1674
kwargs = request[3]
1702
parent_pipe.send(('data', getattr(client_object,
1676
parent_pipe.send(('data', getattr(client_object, funcname)(*args, **kwargs)))
1706
1678
if command == 'getattr':
1707
1679
attrname = request[1]
1708
1680
if callable(client_object.__getattribute__(attrname)):
1709
1681
parent_pipe.send(('function',))
1711
parent_pipe.send(('data', client_object
1712
.__getattribute__(attrname)))
1683
parent_pipe.send(('data', client_object.__getattribute__(attrname)))
1714
1685
if command == 'setattr':
1715
1686
attrname = request[1]
2007
1978
bus_name = dbus.service.BusName("se.recompile.Mandos",
2008
1979
bus, do_not_queue=True)
2009
old_bus_name = (dbus.service.BusName
2010
("se.bsnet.fukt.Mandos", bus,
1980
old_bus_name = dbus.service.BusName("se.bsnet.fukt.Mandos",
1981
bus, do_not_queue=True)
2012
1982
except dbus.exceptions.NameExistsException as e:
2013
1983
logger.error(unicode(e) + ", disabling D-Bus")
2014
1984
use_dbus = False