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.

145 lines
4.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // mschaperror.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class MSChapErrorReporter.
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #include <ias.h>
  15. #include <blob.h>
  16. #include <mschaperror.h>
  17. /////////
  18. // Returns the PPP CHAP Identifier for the request.
  19. /////////
  20. BYTE
  21. WINAPI
  22. GetMSChapIdent(
  23. IAttributesRaw* request
  24. ) throw ()
  25. {
  26. PIASATTRIBUTE attr;
  27. /////////
  28. // Check the attributes in decreasing order of probability.
  29. /////////
  30. attr = IASPeekAttribute(
  31. request,
  32. MS_ATTRIBUTE_CHAP_RESPONSE,
  33. IASTYPE_OCTET_STRING
  34. );
  35. if (attr && attr->Value.OctetString.dwLength > 0)
  36. {
  37. return *(attr->Value.OctetString.lpValue);
  38. }
  39. attr = IASPeekAttribute(
  40. request,
  41. MS_ATTRIBUTE_CHAP_CPW2,
  42. IASTYPE_OCTET_STRING
  43. );
  44. if (attr && attr->Value.OctetString.dwLength > 1)
  45. {
  46. return *(attr->Value.OctetString.lpValue + 1);
  47. }
  48. attr = IASPeekAttribute(
  49. request,
  50. MS_ATTRIBUTE_CHAP_CPW1,
  51. IASTYPE_OCTET_STRING
  52. );
  53. if (attr && attr->Value.OctetString.dwLength > 1)
  54. {
  55. return *(attr->Value.OctetString.lpValue + 1);
  56. }
  57. // If we can't read the identifier, we'll just use zero.
  58. return (BYTE)0;
  59. }
  60. IASREQUESTSTATUS MSChapErrorReporter::onSyncRequest(
  61. IRequest* pRequest
  62. ) throw ()
  63. {
  64. try
  65. {
  66. IASRequest request(pRequest);
  67. PIASATTRIBUTE attr;
  68. // If it doesn't have an MS-CHAP-Challenge then we're not interested.
  69. attr = IASPeekAttribute(
  70. request,
  71. MS_ATTRIBUTE_CHAP_CHALLENGE,
  72. IASTYPE_OCTET_STRING
  73. );
  74. if (!attr) { return IAS_REQUEST_STATUS_CONTINUE; }
  75. // If it already has an MS-CHAP-Error, then there's nothing to do.
  76. attr = IASPeekAttribute(
  77. request,
  78. MS_ATTRIBUTE_CHAP_ERROR,
  79. IASTYPE_OCTET_STRING
  80. );
  81. if (attr) { return IAS_REQUEST_STATUS_CONTINUE; }
  82. // Map the reason code to an MS-CHAP error code.
  83. DWORD errorCode;
  84. switch (request.get_Reason())
  85. {
  86. case IAS_INVALID_LOGON_HOURS:
  87. errorCode = 646; // ERROR_RESTRICTED_LOGON_HOURS
  88. break;
  89. case IAS_ACCOUNT_DISABLED:
  90. errorCode = 647; // ERROR_ACCT_DISABLED
  91. break;
  92. case IAS_PASSWORD_MUST_CHANGE:
  93. errorCode = 648; // ERROR_PASSWD_EXPIRED
  94. break;
  95. case IAS_LM_NOT_ALLOWED:
  96. case IAS_NO_POLICY_MATCH:
  97. case IAS_DIALIN_LOCKED_OUT:
  98. case IAS_DIALIN_DISABLED:
  99. case IAS_INVALID_AUTH_TYPE:
  100. case IAS_INVALID_CALLING_STATION:
  101. case IAS_INVALID_DIALIN_HOURS:
  102. case IAS_INVALID_CALLED_STATION:
  103. case IAS_INVALID_PORT_TYPE:
  104. case IAS_DIALIN_RESTRICTION:
  105. case IAS_CPW_NOT_ALLOWED:
  106. errorCode = 649; // ERROR_NO_DIALIN_PERMISSION
  107. break;
  108. case IAS_CHANGE_PASSWORD_FAILURE:
  109. errorCode = 709; // ERROR_CHANGING_PASSWORD;
  110. break;
  111. default:
  112. errorCode = 691; // ERROR_AUTHENTICATION_FAILURE
  113. }
  114. // Insert the MS-CHAP-Error VSA.
  115. MSChapError::insert(request, GetMSChapIdent(request), errorCode);
  116. }
  117. catch (const _com_error& ce)
  118. {
  119. IASTraceExcept();
  120. // If we can't populate the MS-CHAP-Error VSA, then we can't send a
  121. // compliant response, so we should abort.
  122. pRequest->SetResponse(IAS_RESPONSE_DISCARD_PACKET, ce.Error());
  123. }
  124. return IAS_REQUEST_STATUS_CONTINUE;
  125. }