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.

120 lines
3.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // EAPState.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class EAPState.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 01/15/1998 Original version.
  16. // 08/26/1998 Consolidated into a single class.
  17. // 01/25/2000 User IASGetHostByName.
  18. //
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #include <ias.h>
  21. #include <iastlutl.h>
  22. #include <sdoias.h>
  23. #include <lmcons.h>
  24. #include <winsock2.h>
  25. #include <eapstate.h>
  26. //////////
  27. // Current version of the state attribute.
  28. //////////
  29. const WORD IAS_STATE_VERSION = 1;
  30. //////////
  31. // Stores invariant fields of the state attribute. Computed during
  32. // initialization.
  33. //////////
  34. EAPState::Layout invariant;
  35. bool EAPState::isValid() const throw ()
  36. {
  37. //////////
  38. // State attribute must have:
  39. // (1) The correct length.
  40. // (2) Same invariants.
  41. // (3) A valid checksum.
  42. //////////
  43. return dwLength == sizeof(Layout) &&
  44. memcmp(get().vendorID, invariant.vendorID, 14) == 0 &&
  45. getChecksum() == IASAdler32(
  46. get().vendorID,
  47. sizeof(Layout) - FIELD_OFFSET(Layout, vendorID)
  48. );
  49. }
  50. void EAPState::initialize() throw ()
  51. {
  52. // Null everything out.
  53. memset(&invariant, 0, sizeof(invariant));
  54. // Set the vendor ID and version.
  55. IASInsertDWORD(invariant.vendorID, IAS_VENDOR_MICROSOFT);
  56. IASInsertWORD (invariant.version, IAS_STATE_VERSION);
  57. // Try to set the server IP address. We don't care if this fails since
  58. // we may be running on a computer without IP installed.
  59. WCHAR computerName[CNLEN + 1];
  60. DWORD nchar = CNLEN + 1;
  61. if (GetComputerNameW(computerName, &nchar))
  62. {
  63. PHOSTENT hostEnt = IASGetHostByName(computerName);
  64. if (hostEnt)
  65. {
  66. memcpy(invariant.serverAddress, hostEnt->h_addr, 4);
  67. LocalFree(hostEnt);
  68. }
  69. }
  70. // Set the source ID.
  71. IASInsertDWORD(invariant.sourceID, IASAllocateUniqueID());
  72. }
  73. PIASATTRIBUTE EAPState::createAttribute(DWORD sessionID)
  74. {
  75. //////////
  76. // Start with the parts that never change.
  77. //////////
  78. Layout value(invariant);
  79. //////////
  80. // Set the unique session ID.
  81. //////////
  82. IASInsertDWORD(value.sessionID, sessionID);
  83. //////////
  84. // Compute and insert the checksum.
  85. //////////
  86. IASInsertDWORD(
  87. value.checksum,
  88. IASAdler32(
  89. value.vendorID,
  90. sizeof(Layout) - FIELD_OFFSET(Layout, vendorID)
  91. )
  92. );
  93. //////////
  94. // Fill in the attribute fields.
  95. //////////
  96. IASTL::IASAttribute attr(true);
  97. attr->dwId = RADIUS_ATTRIBUTE_STATE;
  98. attr->dwFlags = IAS_INCLUDE_IN_CHALLENGE;
  99. attr.setOctetString(sizeof(value), (const BYTE*)&value);
  100. return attr.detach();
  101. }