Source code of Windows XP (NT5)
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.

181 lines
4.8 KiB

  1. /*****************************************************************************
  2. *
  3. * nntp.c
  4. *
  5. * Copyright (c) 1997 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * Abstract:
  8. *
  9. * Dumb layer that opens the socket to the server.
  10. *
  11. *****************************************************************************/
  12. #include "msnspa.h"
  13. #define PROXY_PORT1 119 /* I listen to this */
  14. #define PROXY_DEST1 119 /* And talk to this */
  15. #define PROXY_HOST1 "msnnews.msn.com" /* And I talk to him */
  16. #define PROTOCOL "MSN" /* with this protocol */
  17. #define PROXY_PORT2 120 /* I listen to this */
  18. #define PROXY_DEST2 119 /* And talk to this */
  19. #define PROXY_HOST2 "netnews.msn.com" /* And I talk to him */
  20. BOOL CALLBACK NNTP_Negotiate(SOCKET s);
  21. /*****************************************************************************
  22. *
  23. * PROXYINFO for NNTP
  24. *
  25. *****************************************************************************/
  26. #pragma BEGIN_CONST_DATA
  27. PROXYINFO g_proxyNntp1 = {
  28. PROXY_PORT1, /* localport */
  29. PROXY_DEST1, /* serverport */
  30. PROXY_HOST1, /* remote server */
  31. &g_cNewsUsers, /* Usage counter */
  32. NNTP_Negotiate, /* Negotiation function */
  33. "400 Server inaccessible\r\n", /* Failed to connect */
  34. "400 Authentication failed\r\n", /* Password problem */
  35. "200 MSN Secure Password Authentication Proxy\r\n", /* Generic happy */
  36. "", /* First 4-char command to ignore */
  37. "", /* Second 4-char command to ignore */
  38. };
  39. PROXYINFO g_proxyNntp2 = {
  40. PROXY_PORT2, /* localport */
  41. PROXY_DEST2, /* serverport */
  42. PROXY_HOST2, /* remote server */
  43. &g_cNewsUsers, /* Usage counter */
  44. NNTP_Negotiate, /* Negotiation function */
  45. "400 Server inaccessible\r\n", /* Failed to connect */
  46. "400 Authentication failed\r\n", /* Password problem */
  47. "200 MSN Secure Password Authentication Proxy\r\n", /* Generic happy */
  48. "", /* First 4-char command to ignore */
  49. "", /* Second 4-char command to ignore */
  50. };
  51. /*****************************************************************************
  52. *
  53. * NNTP_Negotiate
  54. *
  55. * Perform an authenticated MSN logon.
  56. *
  57. *****************************************************************************/
  58. BOOL CALLBACK
  59. NNTP_Negotiate(SOCKET ssfd)
  60. {
  61. WIN32AUTHSTATE was;
  62. char buf[BUFSIZE+1];
  63. int cb;
  64. /*
  65. * Wait for the greeting.
  66. */
  67. cb = recv(ssfd, buf, BUFSIZE, 0); /* read a hunk */
  68. #ifdef CHATTY
  69. if (cb >= 0) {
  70. buf[cb] = 0;
  71. Squirt("<%s\r\n", buf);
  72. }
  73. #endif
  74. if (cb <= 0 || buf[0] != '2') {
  75. return FALSE;
  76. }
  77. /*
  78. * Tell the server to go into authentication mode.
  79. */
  80. sendsz(ssfd, "AUTHINFO TRANSACT " PROTOCOL "\r\n");
  81. #ifdef CHATTY
  82. Squirt(">AUTHINFO TRANSACT " PROTOCOL "\r\n");
  83. #endif
  84. /*
  85. * Wait for the Proceed.
  86. */
  87. cb = recv(ssfd, buf, BUFSIZE, 0); /* read a hunk */
  88. #ifdef CHATTY
  89. if (cb >= 0) {
  90. buf[cb] = 0;
  91. Squirt("<%s\r\n", buf);
  92. }
  93. #endif
  94. if (cb <= 0 || buf[0] != '3') {
  95. return FALSE;
  96. }
  97. if (!Security_AcquireCredentials(&was, TEXT(PROTOCOL))) {
  98. Die(TEXT("Cannot acquire credentials handle"));
  99. }
  100. if (!Security_GetNegotiation(&was)) {
  101. Die(TEXT("Cannot get negotiation string"));
  102. }
  103. /*
  104. * Now send the initial cookie.
  105. */
  106. sendsz(ssfd, "AUTHINFO TRANSACT ");
  107. sendsz(ssfd, was.szBuffer);
  108. sendsz(ssfd, "\r\n");
  109. #ifdef CHATTY
  110. Squirt(">AUTHINFO TRANSACT %s\r\n", was.szBuffer);
  111. #endif
  112. /*
  113. * Response should be
  114. *
  115. * 381 <challenge>
  116. */
  117. cb = recv(ssfd, buf, BUFSIZE, 0);
  118. if (cb <= 0 || buf[0] != '3') {
  119. return FALSE;
  120. }
  121. #ifdef CHATTY
  122. buf[cb] = 0;
  123. Squirt("<%s", buf);
  124. #endif
  125. /*
  126. * Parse the server response and build our response.
  127. */
  128. if (!Security_GetResponse(&was, buf + 4)) {
  129. Die(TEXT("Cannot build response"));
  130. }
  131. /*
  132. * Now send our response.
  133. */
  134. sendsz(ssfd, "AUTHINFO TRANSACT ");
  135. sendsz(ssfd, was.szBuffer);
  136. sendsz(ssfd, "\r\n");
  137. #ifdef CHATTY
  138. Squirt(">AUTHINFO TRANSACT %s\r\n", was.szBuffer);
  139. #endif
  140. Security_ReleaseCredentials(&was);
  141. /*
  142. * Now see how that worked. Response should be
  143. *
  144. * 281 OK
  145. */
  146. cb = recv(ssfd, buf, BUFSIZE, 0);
  147. if (cb <= 0 || buf[0] != '2') {
  148. return FALSE;
  149. }
  150. return TRUE;
  151. }