Branch data Line data Source code
1 : : // $Id: Login.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 login_h
6 : : #define login_h
7 : :
8 : : #include "TCP.h"
9 : :
10 : : typedef enum {
11 : : LOGIN_STATE_AUTHENTICATE, // trying to authenticate
12 : :
13 : : LOGIN_STATE_LOGGED_IN, // successful authentication
14 : : LOGIN_STATE_SKIP, // skip any further processing
15 : : LOGIN_STATE_CONFUSED, // we're confused
16 : : } login_state;
17 : :
18 : : // If no action by this many lines, we're definitely confused.
19 : : #define MAX_AUTHENTICATE_LINES 50
20 : :
21 : : // Maximum # lines look after login for failure.
22 : : #define MAX_LOGIN_LOOKAHEAD 10
23 : :
24 : : class Login_Analyzer : public TCP_ApplicationAnalyzer {
25 : : public:
26 : : Login_Analyzer(AnalyzerTag::Tag tag, Connection* conn);
27 : : ~Login_Analyzer();
28 : :
29 : : virtual void DeliverStream(int len, const u_char* data, bool orig);
30 : :
31 : : virtual void SetEnv(bool orig, char* name, char* val);
32 : :
33 : 0 : login_state LoginState() const { return state; }
34 : 0 : void SetLoginState(login_state s) { state = s; }
35 : :
36 : : virtual void EndpointEOF(bool is_orig);
37 : :
38 : : protected:
39 : : void NewLine(bool orig, char* line);
40 : : void AuthenticationDialog(bool orig, char* line);
41 : :
42 : : void LoginEvent(EventHandlerPtr f, const char* line, int no_user_okay=0);
43 : : const char* GetUsername(const char* line) const;
44 : : void LineEvent(EventHandlerPtr f, const char* line);
45 : : void Confused(const char* msg, const char* addl);
46 : : void ConfusionText(const char* line);
47 : :
48 : : int IsPloy(const char* line);
49 : : int IsSkipAuthentication(const char* line) const;
50 : : const char* IsLoginPrompt(const char* line) const; // nil if not
51 : : int IsDirectLoginPrompt(const char* line) const;
52 : : int IsFailureMsg(const char* line) const;
53 : : int IsSuccessMsg(const char* line) const;
54 : : int IsTimeout(const char* line) const;
55 : : int IsEmpty(const char* line) const;
56 : :
57 : : void AddUserText(const char* line); // complains on overflow
58 : : char* PeekUserText() const; // internal error on underflow
59 : : char* PopUserText(); // internal error on underflow
60 : : Val* PopUserTextVal();
61 : :
62 : : int MatchesTypeahead(const char* line) const;
63 : 0 : int HaveTypeahead() const { return num_user_text > 0; }
64 : : void FlushEmptyTypeahead();
65 : :
66 : : // If we have more user text than this unprocessed, we complain about
67 : : // excessive typeahead.
68 : : #define MAX_USER_TEXT 12
69 : : char* user_text[MAX_USER_TEXT];
70 : : int user_text_first, user_text_last; // indices into user_text
71 : : int num_user_text; // number of entries in user_text
72 : :
73 : : Val* username; // last username reported
74 : : Val* client_name; // rlogin client name (or nil if none)
75 : :
76 : : login_state state;
77 : : int lines_scanned;
78 : : int num_user_lines_seen;
79 : : int last_failure_num_user_lines;
80 : : int login_prompt_line;
81 : : int failure_line;
82 : :
83 : : int is_VMS;
84 : : int saw_ploy;
85 : : };
86 : :
87 : : #endif
|