Skip to content

Commit

Permalink
Ignore Telnet options. Addresses issue Juniper#44.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stacywsmith committed Jun 29, 2016
1 parent 6acb880 commit 731b83b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/netconify/tty_telnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 731b83b

Please sign in to comment.