The Telnet proxy can enable/disable the use of the options and their suboptions within the session. Changing the default policy
can be done using the option
multi-dimensional hash,
indexed by the option and the suboption (optional). If the suboption is specified, the lookup precedence described in Section 2.1.2, Response codes is used.
The possible action codes are listed in the table below.
Action | Description |
---|---|
TELNET_OPT_ACCEPT |
Allow the option. |
TELNET_OPT_DROP |
Reject the option. |
TELNET_OPT_ABORT |
Reject the option and terminate the Telnet session. |
TELNET_OPT_POLICY |
Call the function specified to make a decision about the event. The function receives two parameters: self, and option (an integer). See Section 2.1, Policies for requests and responses for details. |
Table 4.26. Action codes for Telnet options
Example 4.20. Example for disabling the Telnet X Display Location option |
---|
class MyTelnetProxy(TelnetProxy): def config(self): TelnetProxy.config(self) self.option[TELNET_X_DISPLAY_LOCATION] = (TELNET_OPT_REJECT) |
Constants have been defined for the easier use of TELNET options and suboptions. These are listed in Table A.1, TELNET options and suboptions.
Policy callback functions can be used to make decisions based on the
content of the suboption negotiation sequence. For example, the suboption negotiation sequences of the Telnet
Environment option transfer environment
variables. The low level proxy implementation parses these variables, and
passes their name and value to the callback function one-by-one. These
values can also be manipulated during transfer, by changing the current_var_name
and
current_var_value
attributes of the proxy class.
Example 4.21. Rewriting the DISPLAY environment variable |
---|
class MyRewritingTelnetProxy(TelnetProxy): def config(self): TelnetProxy.config() self.option[TELNET_ENVIRONMENT, TELNET_SB_IS] = (TELNET_OPTION_POLICY, self.rewriteVar) def rewriteVar(self, option, name, value): if name == "DISPLAY": self.current_var_value = "rewritten_value:0" return TELNET_OPTION_ACCEPT |
In the Telnet protocol, options and the actual commands are represented on one byte. In order to be able to use a command in a session, the option (and its suboptions if there are any) corresponding to the command has to be negotiated between the client and the server. Usually the command and the option is represented by the same value, e.g.: the TELNET_STATUS
command and option are both represented by the value "5". However, this is not always the case. The negotiation
hash is indexed by the code of the command, and contains the code of the option to be negotiated for the given command (or the TELNET_NEG_NONE
when no negotation is needed).
Currently the only command where the code of the command differs from the related option is self.negotiation["239"] = int(TELNET_EOR)
.
Published on June 04, 2020
© 2007-2019 BalaSys
Send your comments to support@balasys.hu