def validate_tor_port(tor_port, description):
'''
Validate a single Tor ORPort or DirPort entry, using description as
the port type in any log messages.
tor_port is an ORPort or DirPort config line.
Some can be IPv6 *Ports, which have an IPv6 address and a port.
Others include options, such as NoListen.
'''
# Do some basic validation of the port
# There isn't much we can do here, because port lines vary so much
if len(tor_port) < 1 or len(tor_port) > 200:
logging.warning("Bad %s length %d: %s",
description, len(tor_port), tor_port)
return False
if not all(c in string.printable for c in tor_port):
logging.warning("Bad %s characters: %s", description, tor_port)
return False
return True
评论列表
文章目录