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