464
464
if timeout is None:
465
465
timeout = self.timeout
466
466
self.last_checked_ok = datetime.datetime.utcnow()
467
gobject.source_remove(self.disable_initiator_tag)
468
self.expires = datetime.datetime.utcnow() + timeout
469
self.disable_initiator_tag = (gobject.timeout_add
470
(_timedelta_to_milliseconds
471
(timeout), 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
473
475
def need_approval(self):
474
476
self.last_approval_request = datetime.datetime.utcnow()
891
893
""" Modify a variable so that it's a property which announces
892
894
its changes to DBus.
894
transform_fun: Function that takes a value and transforms it
896
transform_fun: Function that takes a value and a variant_level
897
and transforms it to a D-Bus type.
896
898
dbus_name: D-Bus name of the variable
897
899
type_func: Function that transform the value before sending it
898
900
to the D-Bus. Default: no transform
899
901
variant_level: D-Bus variant level. Default: 1
903
attrname = "_{0}".format(dbus_name)
902
904
def setter(self, value):
903
old_value = real_value[0]
904
real_value[0] = value
905
905
if hasattr(self, "dbus_object_path"):
906
if type_func(old_value) != type_func(real_value[0]):
907
dbus_value = transform_func(type_func
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
912
self.PropertyChanged(dbus.String(dbus_name),
914
setattr(self, attrname, value)
913
return property(lambda self: real_value[0], setter)
916
return property(lambda self: getattr(self, attrname), setter)
916
919
expires = notifychangeproperty(datetime_to_dbus, "Expires")
1396
1398
#wait until timeout or approved
1398
# ._timedelta_to_milliseconds(delay))
1399
1399
time = datetime.datetime.now()
1400
1400
client.changedstate.acquire()
1401
1401
(client.changedstate.wait
1430
1430
sent_size += sent
1432
1432
logger.info("Sending secret to %s", client.name)
1433
# bump the timeout as if seen
1433
# bump the timeout using extended_timeout
1434
1434
client.checked_ok(client.extended_timeout)
1435
1435
if self.server.use_dbus:
1436
1436
# Emit D-Bus signal
1517
1517
self.handle_error(request, address)
1518
1518
self.close_request(request)
1520
1520
def process_request(self, request, address):
1521
1521
"""Start a new process to process the request."""
1522
multiprocessing.Process(target = self.sub_process_main,
1523
args = (request, address)).start()
1522
proc = multiprocessing.Process(target = self.sub_process_main,
1526
1529
class MultiprocessingMixInWithPipe(MultiprocessingMixIn, object):
1533
1536
parent_pipe, self.child_pipe = multiprocessing.Pipe()
1535
super(MultiprocessingMixInWithPipe,
1536
self).process_request(request, client_address)
1538
proc = MultiprocessingMixIn.process_request(self, request,
1537
1540
self.child_pipe.close()
1538
self.add_pipe(parent_pipe)
1541
self.add_pipe(parent_pipe, proc)
1540
def add_pipe(self, parent_pipe):
1543
def add_pipe(self, parent_pipe, proc):
1541
1544
"""Dummy function; override as necessary"""
1542
1545
raise NotImplementedError
1631
1634
def server_activate(self):
1632
1635
if self.enabled:
1633
1636
return socketserver.TCPServer.server_activate(self)
1634
1638
def enable(self):
1635
1639
self.enabled = True
1636
def add_pipe(self, parent_pipe):
1641
def add_pipe(self, parent_pipe, proc):
1637
1642
# Call "handle_ipc" for both data and EOF events
1638
1643
gobject.io_add_watch(parent_pipe.fileno(),
1639
1644
gobject.IO_IN | gobject.IO_HUP,
1640
1645
functools.partial(self.handle_ipc,
1644
1650
def handle_ipc(self, source, condition, parent_pipe=None,
1645
client_object=None):
1651
proc = None, client_object=None):
1646
1652
condition_names = {
1647
1653
gobject.IO_IN: "IN", # There is data to read.
1648
1654
gobject.IO_OUT: "OUT", # Data can be written (without
1657
1663
for cond, name in
1658
1664
condition_names.iteritems()
1659
1665
if cond & condition)
1660
# error or the other end of multiprocessing.Pipe has closed
1666
# error, or the other end of multiprocessing.Pipe has closed
1661
1667
if condition & (gobject.IO_ERR | condition & gobject.IO_HUP):
1668
# Wait for other process to exit
1664
1672
# Read a request from the child