241
240
if "secret" in config:
242
241
self.secret = config["secret"].decode(u"base64")
243
242
elif "secfile" in config:
244
with closing(open(os.path.expanduser
246
(config["secfile"])))) \
248
self.secret = secfile.read()
243
secfile = open(os.path.expanduser(os.path.expandvars
244
(config["secfile"])))
245
self.secret = secfile.read()
250
248
raise TypeError(u"No secret or secfile for client %s"
300
298
def checker_callback(self, pid, condition):
301
299
"""The checker has completed, so take appropriate actions."""
300
now = datetime.datetime.now()
302
301
self.checker_callback_tag = None
303
302
self.checker = None
304
303
if os.WIFEXITED(condition) \
305
304
and (os.WEXITSTATUS(condition) == 0):
306
305
logger.info(u"Checker for %(name)s succeeded",
307
self.last_checked_ok = now
308
gobject.source_remove(self.stop_initiator_tag)
309
self.stop_initiator_tag = gobject.timeout_add\
310
(self._timeout_milliseconds,
309
312
elif not os.WIFEXITED(condition):
310
313
logger.warning(u"Checker for %(name)s crashed?",
313
316
logger.info(u"Checker for %(name)s failed",
315
def bump_timeout(self):
316
"""Bump up the timeout for this client.
317
This should only be called when the client has been seen,
320
self.last_checked_ok = datetime.datetime.now()
321
gobject.source_remove(self.stop_initiator_tag)
322
self.stop_initiator_tag = gobject.timeout_add\
323
(self._timeout_milliseconds, self.stop)
324
318
def start_checker(self):
325
319
"""Start a new checker subprocess if one is not running.
326
320
If a checker already exists, leave it running and do
454
448
def handle(self):
455
449
logger.info(u"TCP connection from: %s",
456
unicode(self.client_address))
450
unicode(self.client_address))
457
451
session = gnutls.connection.ClientSession\
458
452
(self.request, gnutls.connection.X509Credentials())
474
468
#priority = ':'.join(("NONE", "+VERS-TLS1.1", "+AES-256-CBC",
475
469
# "+SHA1", "+COMP-NULL", "+CTYPE-OPENPGP",
477
# Use a fallback default, since this MUST be set.
478
priority = self.server.settings.get("priority", "NORMAL")
471
priority = "NORMAL" # Fallback default, since this
473
if self.server.settings["priority"]:
474
priority = self.server.settings["priority"]
479
475
gnutls.library.functions.gnutls_priority_set_direct\
480
476
(session._c_object, priority, None)
526
class IPv6_TCPServer(SocketServer.ForkingMixIn,
527
SocketServer.TCPServer, object):
520
class IPv6_TCPServer(SocketServer.ForkingTCPServer, object):
528
521
"""IPv6 TCP server. Accepts 'None' as address and/or port.
530
523
settings: Server settings
659
652
def if_nametoindex(interface):
660
653
"Get an interface index the hard way, i.e. using fcntl()"
661
654
SIOCGIFINDEX = 0x8933 # From /usr/include/linux/sockios.h
662
with closing(socket.socket()) as s:
663
ifreq = fcntl.ioctl(s, SIOCGIFINDEX,
664
struct.pack("16s16x", interface))
656
ifreq = fcntl.ioctl(s, SIOCGIFINDEX,
657
struct.pack("16s16x", interface))
665
659
interface_index = struct.unpack("I", ifreq[16:20])[0]
666
660
return interface_index
667
661
return if_nametoindex(interface)