Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.5 KiB

  1. // IoHandler.h : This file contains the
  2. // Created: Feb '98
  3. // Author : a-rakeba
  4. // History:
  5. // Copyright (C) 1998 Microsoft Corporation
  6. // All rights reserved.
  7. // Microsoft Confidential
  8. #if !defined( _IOHANDLER_H_ )
  9. #define _IOHANDLER_H_
  10. #include <cmnhdr.h>
  11. #include <windows.h>
  12. #include <winsock2.h>
  13. #define SECURITY_WIN32
  14. #include <sspi.h>
  15. #include <TlntUtils.h>
  16. #include <Ipc.h>
  17. #define AVAILABE_BUFFER_SIZE( p, c ) ( sizeof( p ) - ( c - p ) )
  18. #define FOOTER L"\r\n"
  19. #define NEED_HEADER 1
  20. #define NO_HEADER 0
  21. #define SIZEOF_ARROWKEY_SEQ 3
  22. #define PVA_SUCCESS 0
  23. #define PVA_NODATA -1
  24. #define PVA_BADFORMAT -2
  25. #define PVA_GUEST -3
  26. #define PVA_NOMEMORY -4
  27. #define PVA_INVALIDACCOUNT -5
  28. #define PVA_OTHERERROR -6
  29. class CSession;
  30. class CIoHandler
  31. {
  32. public:
  33. CIoHandler();
  34. virtual ~CIoHandler();
  35. typedef DWORD IO_OPERATIONS;
  36. friend struct CRFCProtocol;
  37. friend class CScraper;
  38. private:
  39. int ParseAndValidateAccount(void);
  40. int AuthenticateUser( void );
  41. int CheckLicense( void );
  42. bool WriteToServer ( UCHAR, DWORD, LPVOID );
  43. bool StartNTLMAuth( void );
  44. bool DoNTLMAuth( PUCHAR, DWORD, PUCHAR* );
  45. bool IsTimedOut ( );
  46. bool GetAndSetSocket ( );
  47. bool HandlePipeData ( );
  48. bool SendDetailsAndAskForLicense ();
  49. bool HandleOperatorMessage();
  50. bool GetHeaderMessage( LPWSTR* );
  51. bool RemoveArrowKeysFromBuffer( PDWORD ,PDWORD);
  52. bool ProcessUserDataReadFromSocket( DWORD );
  53. IO_OPERATIONS ProcessDataFromSocket( DWORD );
  54. IO_OPERATIONS ProcessCommandLine( PDWORD, PDWORD, IO_OPERATIONS );
  55. IO_OPERATIONS ProcessAuthenticationLine( PDWORD, PDWORD, IO_OPERATIONS );
  56. IO_OPERATIONS OnDataFromSocket ( );
  57. protected:
  58. typedef enum {
  59. STATE_INIT,
  60. STATE_NTLMAUTH,
  61. STATE_SESSION,
  62. STATE_BANNER_FOR_AUTH,
  63. STATE_WAIT_FOR_ENV_OPTION,
  64. STATE_LOGIN_PROMPT,
  65. STATE_AUTH_NAME,
  66. STATE_AUTH_PASSWORD,
  67. STATE_CHECK_LICENSE,
  68. STATE_LICENSE_AVAILABILITY_KNOWN,
  69. STATE_VTERM_INIT_NEGO,
  70. STATE_VTERM,
  71. STATE_TERMINATE } CONTROL_STATE;
  72. CONTROL_STATE m_SocketControlState;
  73. enum { WRITE_TO_SOCKET = 0x00000001, READ_FROM_SOCKET = 0x0000002,
  74. LOGON_COMMAND = 0x00000010, LOGON_DATA_UNFINISHED = 0x00000100,
  75. IO_FAIL = 0x00001000 };
  76. typedef enum {
  77. NOT_MEMBER_OF_TELNETCLIENTS_GROUP = 3,
  78. DENY_LICENSE = 4,
  79. ISSUE_LICENSE = 5,
  80. WAIT_FOR_SERVER_REPLY = 6,
  81. #if BETA
  82. LICENSE_EXPIRED
  83. #endif
  84. } LICENSE_LIMIT;
  85. CtxtHandle m_hContext;
  86. OVERLAPPED m_oWriteToSocket;
  87. UCHAR m_WriteToSocketBuff[ MAX_WRITE_SOCKET_BUFFER ];
  88. DWORD m_dwWriteToSocketIoLength;
  89. WSAPROTOCOL_INFO m_protocolInfo;
  90. bool m_bOnlyOnce;
  91. bool m_bWaitForEnvOptionOver;
  92. OVERLAPPED m_oWriteToPipe;
  93. OVERLAPPED m_oReadFromSocket;
  94. UCHAR m_ReadFromSocketBuffer[ MAX_READ_SOCKET_BUFFER ];
  95. PUCHAR m_pReadFromSocketBufferCursor;
  96. DWORD m_dwReadFromSocketIoLength;
  97. OVERLAPPED m_oReadFromPipe;
  98. UCHAR m_ReadFromPipeBuffer[ IPC_HEADER_SIZE ];
  99. UCHAR *m_pucReadBuffer;
  100. DWORD m_dwReadFromPipeIoLength;
  101. DWORD m_dwRequestedSize;
  102. bool m_bIpcHeader;
  103. SOCKET m_sSocket;
  104. HANDLE m_hReadPipe;
  105. HANDLE m_hWritePipe;
  106. bool m_fFirstReadFromPipe;
  107. bool m_fShutDownAfterIO;
  108. BOOL m_fLogonUserResult;
  109. bool m_bNTLMAuthenticated;
  110. bool fDoNTLMAuthFirstTime;
  111. CredHandle m_hCredential;
  112. PSecPkgInfo m_pspi;
  113. CSession *m_pSession;
  114. int m_iResult;
  115. bool m_bInvalidAccount;
  116. bool GetUserName();
  117. bool WriteToSocket(PUCHAR, DWORD );
  118. bool Init( CSession * );
  119. void Shutdown( void );
  120. bool IssueReadOnPipe( );
  121. bool IssueFirstReadOnPipe ( );
  122. bool WriteToClient ( );
  123. bool IssueReadFromSocket ( );
  124. bool OnReadFromPipeCompletion ( );
  125. bool OnReadFromSocketCompletion ( );
  126. void DisplayOnClientNow();
  127. void SendMessageToClient( LPWSTR, bool );
  128. void WriteMessageToClientDirectly( LPWSTR );
  129. void SendTerminateString( char *);
  130. void UpdateIdleTime( UCHAR );
  131. };
  132. #endif // _IOHANDLER_H_