pop3.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

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