Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

NVT.h

Go to the documentation of this file.
00001 // $Id: NVT.h,v 1.2 2005/09/07 17:20:10 vern Exp $
00002 //
00003 // Copyright (c) 1999, 2001, 2002, 2003
00004 //      The Regents of the University of California.  All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that: (1) source code distributions
00008 // retain the above copyright notice and this paragraph in its entirety, (2)
00009 // distributions including binary code include the above copyright notice and
00010 // this paragraph in its entirety in the documentation or other materials
00011 // provided with the distribution, and (3) all advertising materials mentioning
00012 // features or use of this software display the following acknowledgement:
00013 // ``This product includes software developed by the University of California,
00014 // Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
00015 // the University nor the names of its contributors may be used to endorse
00016 // or promote products derived from this software without specific prior
00017 // written permission.
00018 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
00019 // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 
00022 #ifndef nvt_h
00023 #define nvt_h
00024 
00025 #include "TCP.h"
00026 
00027 
00028 #define TELNET_OPTION_BINARY 0
00029 #define TELNET_OPTION_TERMINAL 24
00030 #define TELNET_OPTION_AUTHENTICATE 37
00031 #define TELNET_OPTION_ENCRYPT 38
00032 #define TELNET_OPTION_ENVIRON 39
00033 #define NUM_TELNET_OPTIONS 5
00034 
00035 class TCP_NVT;
00036 
00037 
00038 class TelnetOption {
00039 public:
00040         TelnetOption(TCP_NVT* endp, unsigned int code);
00041 
00042 // Whether we told the other side WILL/WONT/DO/DONT.
00043 #define OPT_SAID_WILL 0x1
00044 #define OPT_SAID_WONT 0x2
00045 #define OPT_SAID_DO 0x4
00046 #define OPT_SAID_DONT 0x8
00047 
00048         unsigned int Code() const       { return code; }
00049 
00050         int IsActive() const            { return active; }
00051 
00052         int SaidWill() const    { return flags & OPT_SAID_WILL; }
00053         int SaidWont() const    { return flags & OPT_SAID_WONT; }
00054         int SaidDo() const      { return flags & OPT_SAID_DO; }
00055         int SaidDont() const    { return flags & OPT_SAID_DONT; }
00056 
00057         void SetWill()  { flags |= OPT_SAID_WILL; }
00058         void SetWont()  { flags |= OPT_SAID_WONT; }
00059         void SetDo()    { flags |= OPT_SAID_DO; }
00060         void SetDont()  { flags |= OPT_SAID_DONT; }
00061 
00062         void RecvOption(unsigned int type);
00063         virtual void RecvSubOption(u_char* data, int len);
00064 
00065         virtual void SetActive(int is_active);
00066 
00067         const TCP_NVT* Endpoint() const { return endp; }
00068 
00069 protected:
00070         friend class TCP_NVT;
00071         virtual void InconsistentOption(unsigned int type);
00072         virtual void BadOption();
00073 
00074         TCP_NVT* endp;
00075         unsigned int code;
00076         int flags;
00077         int active;
00078 };
00079 
00080 class TelnetTerminalOption : public TelnetOption {
00081 public:
00082         TelnetTerminalOption(TCP_NVT* arg_endp)
00083                 : TelnetOption(arg_endp, TELNET_OPTION_TERMINAL)        { }
00084 
00085         void RecvSubOption(u_char* data, int len);
00086 };
00087 
00088 class TelnetEncryptOption : public TelnetOption {
00089 public:
00090         TelnetEncryptOption(TCP_NVT* arg_endp)
00091                 : TelnetOption(arg_endp, TELNET_OPTION_ENCRYPT)
00092                         { did_encrypt_request = doing_encryption = 0; }
00093 
00094         void RecvSubOption(u_char* data, int len);
00095 
00096         int DidRequest() const          { return did_encrypt_request; }
00097         int DoingEncryption() const     { return doing_encryption; }
00098 
00099 protected:
00100         friend class TCP_NVT;
00101         int did_encrypt_request, doing_encryption;
00102 };
00103 
00104 class TelnetAuthenticateOption : public TelnetOption {
00105 public:
00106         TelnetAuthenticateOption(TCP_NVT* arg_endp)
00107                 : TelnetOption(arg_endp, TELNET_OPTION_AUTHENTICATE)
00108                         { authentication_requested = 0; }
00109 
00110         void RecvSubOption(u_char* data, int len);
00111 
00112         int DidRequestAuthentication() const
00113                 { return authentication_requested; }
00114 
00115 protected:
00116         friend class TCP_NVT;
00117         int authentication_requested;
00118 };
00119 
00120 class TelnetEnvironmentOption : public TelnetOption {
00121 public:
00122         TelnetEnvironmentOption(TCP_NVT* arg_endp)
00123                 : TelnetOption(arg_endp, TELNET_OPTION_ENVIRON)
00124                         { }
00125 
00126         void RecvSubOption(u_char* data, int len);
00127 
00128 protected:
00129         char* ExtractEnv(u_char*& data, int& len, int& code);
00130 };
00131 
00132 class TelnetBinaryOption : public TelnetOption {
00133 public:
00134         TelnetBinaryOption(TCP_NVT* arg_endp)
00135                 : TelnetOption(arg_endp, TELNET_OPTION_BINARY)
00136                         { }
00137 
00138         void SetActive(int is_active);
00139 
00140 protected:
00141         void InconsistentOption(unsigned int type);
00142 };
00143 
00144 class TCP_NVT : public TCP_ContentLine {
00145 public:
00146         TCP_NVT(TCP_Endpoint* endp, int is_NUL_sensitive, int skip_partial,
00147                 int CR_LF_as_EOL = LF_as_EOL);
00148         ~TCP_NVT();
00149 
00150         TelnetOption* FindOption(unsigned int code);
00151         TelnetOption* FindPeerOption(unsigned int code);
00152 
00153         void AuthenticationAccepted();
00154         void AuthenticationRejected();
00155 
00156         void SetTerminal(const u_char* terminal, int len);
00157         void SetBinaryMode(int mode)    { binary_mode = mode; }
00158         void SetEncrypting(int mode);
00159         void SetAuthName(char* arg_auth_name)   { auth_name = arg_auth_name; }
00160 
00161         void SetPeer(TCP_NVT* arg_peer)         { peer = arg_peer; }
00162 
00163         const char* AuthName() const    { return auth_name; }
00164         int AuthenticationHasBeenAccepted() const
00165                 { return authentication_has_been_accepted; }
00166 
00167 protected:
00168         TCP_NVT()       {}
00169 
00170         DECLARE_SERIAL(TCP_NVT)
00171 
00172         void DoDeliver(int seq, int len, const u_char* data);
00173 
00174         void ScanOption(int seq, int len, const u_char* data);
00175         virtual void SawOption(unsigned int code);
00176         virtual void SawOption(unsigned int code, unsigned int subcode);
00177         virtual void SawSubOption(const char* opt, int len);
00178         virtual void BadOptionTermination(unsigned int code);
00179         const char* PeerAuthName() const;
00180 
00181         TCP_NVT* peer;
00182 
00183         int pending_IAC;        // true if we're working on an option/IAC
00184         int IAC_pos;            // where the IAC was seen
00185         int is_suboption;       // true if current option is suboption
00186         int last_was_IAC;       // for scanning suboptions
00187 
00188         int binary_mode, encrypting_mode;
00189         int authentication_has_been_accepted;   // if true, we accepted peer's authentication
00190         char* auth_name;
00191 
00192         TelnetOption* options[NUM_TELNET_OPTIONS];
00193         int num_options;
00194 };
00195 
00196 #endif

Generated on Wed Sep 14 02:56:17 2005 for bro_docs by doxygen 1.3.5