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