From 731b83b3dbe22db9e015b226cf757237e60d9420 Mon Sep 17 00:00:00 2001 From: Stacy Smith Date: Wed, 29 Jun 2016 13:13:53 -0600 Subject: [PATCH] Ignore Telnet options. Addresses issue #44. If no option negotiation callback function is set, telnetlib will pass Telnet options back to netconify in the data stream. This is especially problematic for the AUTHENTICATION (0x25) option. 0x25 is an ASCII % character and confuses the login state machine into thinking that it is at the shell prompt. This function simply receives and ignores Telnet options. This prevents the options from appearing in the data stream and confusing the login state machine. --- lib/netconify/tty_telnet.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/netconify/tty_telnet.py b/lib/netconify/tty_telnet.py index f86f1a5..720b751 100644 --- a/lib/netconify/tty_telnet.py +++ b/lib/netconify/tty_telnet.py @@ -7,6 +7,20 @@ # Terminal connection over TELNET CONSOLE # ------------------------------------------------------------------------- +def _ignore_options(socket, command, option): + """ + Used as a Telnet.set_option_negotiation_callback() function. + + If no option negotiation callback function is set, telnetlib + will pass Telnet options back to netconify in the data stream. + This is especially problematic for the AUTHENTICATION (0x25) option. + 0x25 is an ASCII % character and confuses the login state machine into + thinking that it is at the shell prompt. + This function simply receives and ignores Telnet options. This prevents + the options from appearing in the data stream and confusing the + login state machine. + """ + pass class Telnet(Terminal): RETRY_OPEN = 3 # number of attempts to open TTY @@ -41,6 +55,7 @@ def __init__(self, host, port, **kvargs): def _tty_open(self): retry = self.RETRY_OPEN + self._tn.set_option_negotiation_callback(_ignore_options) while retry > 0: try: self._tn.open(self.host, self.port, self.timeout)