Branch data Line data Source code
1 : : // $Id: NCP.h 6219 2008-10-01 05:39:07Z vern $
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : : #ifndef ncp_h
6 : : #define ncp_h
7 : :
8 : : // A very crude analyzer for NCP (Netware Core Protocol)
9 : : //
10 : : // For a brief introduction to NCP, take a look at:
11 : : //
12 : : // http://www.protocols.com/pbook/testcss.htm
13 : : //
14 : : // For list of function codes:
15 : : //
16 : : // http://faydoc.tripod.com/structures/20/2095.htm
17 : : //
18 : : // And for layout of individual request/reply packets, look at the following
19 : : // pages under http://faydoc.tripod.com/structures/, such as:
20 : : //
21 : : // http://faydoc.tripod.com/structures/21/2149.htm
22 : :
23 : : #include "NetVar.h"
24 : : #include "TCP.h"
25 : :
26 : : #include "ncp_pac.h"
27 : :
28 : : // Create a general NCP_Session class so that it can be used in
29 : : // case the RPC conversation is tunneled through other connections,
30 : : // e.g., through an SMB session.
31 : :
32 : : class NCP_Session {
33 : : public:
34 : : NCP_Session(Analyzer* analyzer);
35 [ # # ][ # # ]: 0 : virtual ~NCP_Session() {}
36 : :
37 : : virtual void Deliver(int is_orig, int len, const u_char* data);
38 : :
39 : 1 : static bool any_ncp_event()
40 : : {
41 [ + - ][ - + ]: 1 : return ncp_request || ncp_reply;
42 : : }
43 : :
44 : : protected:
45 : : void DeliverFrame(const binpac::NCP::ncp_frame* frame);
46 : :
47 : : Analyzer* analyzer;
48 : : int req_frame_type;
49 : : int req_func;
50 : : };
51 : :
52 : : class FrameBuffer {
53 : : public:
54 : : FrameBuffer(int header_length);
55 : : virtual ~FrameBuffer();
56 : :
57 : : // Returns true if a frame is ready
58 : : bool Deliver(int& len, const u_char* &data);
59 : :
60 : : void Reset();
61 : :
62 : 0 : const u_char* Data() const { return msg_buf; }
63 : 0 : int Len() const { return msg_len; }
64 : 0 : bool empty() const { return buf_n == 0; }
65 : :
66 : : protected:
67 : : virtual void compute_msg_length() = 0;
68 : :
69 : : int hdr_len;
70 : : u_char* msg_buf;
71 : : int msg_len;
72 : : int buf_n; // number of bytes in msg_buf
73 : : int buf_len; // size off msg_buf
74 : : };
75 : :
76 : : #define NCP_TCPIP_HEADER_LENGTH 8
77 : :
78 [ # # ][ # # ]: 0 : class NCP_FrameBuffer : public FrameBuffer {
79 : : public:
80 : 0 : NCP_FrameBuffer() : FrameBuffer(NCP_TCPIP_HEADER_LENGTH) {}
81 : :
82 : : protected:
83 : : void compute_msg_length();
84 : : };
85 : :
86 : : class Contents_NCP_Analyzer : public TCP_SupportAnalyzer {
87 : : public:
88 : : Contents_NCP_Analyzer(Connection* conn, bool orig, NCP_Session* session);
89 : : ~Contents_NCP_Analyzer();
90 : :
91 : : protected:
92 : : virtual void DeliverStream(int len, const u_char* data, bool orig);
93 : : virtual void Undelivered(int seq, int len, bool orig);
94 : :
95 : : NCP_FrameBuffer buffer;
96 : : NCP_Session* session;
97 : :
98 : : // Re-sync for partial connections (or after a content gap).
99 : : bool resync;
100 : : };
101 : :
102 : : class NCP_Analyzer : public TCP_ApplicationAnalyzer {
103 : : public:
104 : : NCP_Analyzer(Connection* conn);
105 : : virtual ~NCP_Analyzer();
106 : :
107 : 0 : static Analyzer* InstantiateAnalyzer(Connection* conn)
108 : 0 : { return new NCP_Analyzer(conn); }
109 : :
110 : 1 : static bool Available() { return NCP_Session::any_ncp_event(); }
111 : :
112 : : protected:
113 : :
114 : : NCP_Session* session;
115 : : Contents_NCP_Analyzer * o_ncp;
116 : : Contents_NCP_Analyzer * r_ncp;
117 : : };
118 : :
119 : : #endif /* ncp_h */
|