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.

142 lines
4.6 KiB

  1. /************************************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. File Name: IOContext.hxx
  4. Abstract: Declare the POP3_CONTEXT Class
  5. Notes:
  6. History: 08/01/2001 Created by Hao Yu (haoyu)
  7. ************************************************************************************************/
  8. #ifndef __POP3_CONTEXT_H__
  9. #define __POP3_CONTEXT_H__
  10. #include <IOContext.h>
  11. #include "Mailbox.h"
  12. #include <NTAuth.h>
  13. #define INIT_STATE 0
  14. #define AUTH_STATE 1
  15. #define TRANS_STATE 2
  16. #define UPDATE_STATE 3
  17. #define MD5_HASH_SIZE 32
  18. #define MAX_INT_LEN 9
  19. #define SZ_NTLM "NTLM"
  20. #define RESP_INVALID_MAIL_NUMBER "-ERR No such message\r\n"
  21. #define RESP_SERVER_NOT_AVAILABLE "-ERR Service is not available\r\n"
  22. #define RESP_UNKNOWN_COMMAND "-ERR Unacceptable command\r\n"
  23. #define RESP_OK "+OK\r\n"
  24. #define RESP_SERVER_ERROR "-ERR server error\r\n"
  25. #define RESP_SERVER_READY "+OK %S %S ready.\r\n"
  26. #define RESP_SERVER_QUIT "+OK %S %S signing off.\r\n"
  27. #define RESP_ACCOUNT_ERROR "-ERR Logon Failure\r\n"
  28. #define RESP_END_OF_MULTILINE "\r\n.\r\n"
  29. #define RESP_END_OF_LIST ".\r\n"
  30. #define RESP_MSG_MARKED_DELETED "+OK Message marked as deleted\r\n"
  31. #define RESP_AUTH_DONE "+OK User successfully logged on\r\n"
  32. #define RESP_AUTH_METHODS "+OK\r\n" SZ_NTLM RESP_END_OF_MULTILINE
  33. #define RESP_CMD_NOT_VALID "-ERR Command not valid\r\n"
  34. #define RESP_CMD_NOT_SUPPORTED "-ERR Command is not valid in this state\r\n"
  35. #define RESP_INVALID_LENGTH "-ERR Invalid message Length\r\n"
  36. #define RESP_RESET "+OK Messages unmarked as deleted\r\n"
  37. #define RESP_NO_USER_NAME "-ERR No username\r\n"
  38. #define RESP_SPA_REQUIRED "-ERR SPA Required, use AUTH or APOP\r\n"
  39. #define RESP_SERVER_GREETING L"Microsoft Windows POP3 Service Version 1.0"
  40. #define ERR_NO_SUCH_MSG 0xf0000001
  41. #define ERR_MSG_ALREADY_DELETED 0xf0000002
  42. #define ERR_CAN_NOT_OPEN_FILE 0xf0000003
  43. #define ERR_CAN_NOT_SET_FILE_CURSOR 0xf0000004
  44. #define AUTH_OTHER 0
  45. #define AUTH_AD 1
  46. #define AUTH_LOCAL_SAM 2
  47. #define MAX_FAILED_AUTH 3
  48. #define COMMAND_SIZE 4
  49. const int ciCommandSize[]={4,4,4,4,4,4,4,4,4,4,4,3,4};
  50. const char cszCommands[][5]={"STAT",
  51. "LIST",
  52. "RETR",
  53. "DELE",
  54. "NOOP",
  55. "RSET",
  56. "QUIT",
  57. "USER",
  58. "PASS",
  59. "UIDL",
  60. "APOP",
  61. "TOP",
  62. "AUTH"};
  63. typedef enum enumCommand
  64. {
  65. CMD_STAT=0,
  66. CMD_LIST=1,
  67. CMD_RETR=2,
  68. CMD_DELE=3,
  69. CMD_NOOP=4,
  70. CMD_RSET=5,
  71. CMD_QUIT=6,
  72. CMD_USER=7,
  73. CMD_PASS=8,
  74. CMD_UIDL=9,
  75. CMD_APOP=10,
  76. CMD_TOP=11,
  77. CMD_AUTH=12,
  78. CMD_UNKNOWN
  79. }POP3_CMD;
  80. class POP3_CONTEXT
  81. {
  82. DWORD m_dwCurrentState;
  83. BOOL m_bFileTransmitPending;
  84. BOOL m_bCommandComplete;
  85. DWORD m_dwCommandSize;
  86. char m_szCommandBuffer[POP3_REQUEST_BUF_SIZE];
  87. WCHAR m_wszUserName[POP3_MAX_ADDRESS_LENGTH];
  88. char m_szDomainName[POP3_MAX_DOMAIN_LENGTH];
  89. char m_szPassword[MAX_PATH];
  90. WCHAR m_wszGreeting[MAX_PATH + 64];
  91. int m_cPswdSize;
  92. CMailBox m_MailBox;
  93. IO_CONTEXT *m_pIoContext;
  94. CAuthServer m_AuthServer;
  95. DWORD m_dwAuthStatus;
  96. DWORD m_dwFailedAuthCount;
  97. public:
  98. POP3_CONTEXT();
  99. ~POP3_CONTEXT();
  100. void TimeOut(IO_CONTEXT *pIoContext);
  101. void ProcessRequest(IO_CONTEXT *pIOContext,
  102. OVERLAPPED *pOverlapped,
  103. DWORD dwBytesRcvd);
  104. void WaitForCommand();
  105. void SendResponse(char *szBuf);
  106. void SendResponse(DWORD dwResult, char *szBuf);
  107. void Reset();
  108. BOOL Unauthenticated();
  109. private:
  110. POP3_CMD ParseCommand();
  111. BOOL ProcessAuthStateCommands(POP3_CMD CurrentCmd,
  112. DWORD dwBytesRcvd);
  113. BOOL ProcessTransStateCommands(POP3_CMD CurrentCmd,
  114. DWORD dwBytesRcvd);
  115. void TerminateConnection(PIO_CONTEXT pIoContext);
  116. BOOL GetNextStringParameter(char *szInput, char *szOutput, DWORD dwOutputSize);
  117. BOOL GetNextNumParameter(char **pszInput, int *piOutout);
  118. BOOL IsEndOfCommand(char *szInput);
  119. };
  120. typedef POP3_CONTEXT * PPOP3_CONTEXT;
  121. #endif //__POP3_CONTEXT_H__