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.

151 lines
3.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // classattr.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class IASClass.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 08/06/1998 Original version.
  16. // 01/25/2000 Use IASGetHostByName.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <iasattr.h>
  21. #include <sdoias.h>
  22. #include <lmcons.h>
  23. #include <winsock2.h>
  24. #include <classattr.h>
  25. const DWORD IAS_CLASS_VERSION = 1;
  26. //////////
  27. // Global variables computed during initialization.
  28. //////////
  29. IASClass invariant; // Stores invariant fields of the class attribute.
  30. LONG nextSerialNumber; // Next serial number to be assigned.
  31. // Returns TRUE if the class attribute is in Microsoft format.
  32. BOOL IASClass::isMicrosoft(DWORD actualLength) const throw ()
  33. {
  34. return actualLength >= sizeof(IASClass) &&
  35. getVendorID() == IAS_VENDOR_MICROSOFT &&
  36. getVersion() == IAS_CLASS_VERSION &&
  37. getChecksum() == IASAdler32(
  38. vendorID,
  39. actualLength - offsetof(IASClass, vendorID)
  40. );
  41. }
  42. void IASClass::initialize() throw ()
  43. {
  44. // Null everything out.
  45. memset(&invariant, 0, sizeof(invariant));
  46. // Set the vendor ID and version.
  47. IASInsertDWORD(invariant.vendorID, IAS_VENDOR_MICROSOFT);
  48. IASInsertWORD (invariant.version, IAS_CLASS_VERSION);
  49. // Try to set the server IP address. We don't care if this fails since
  50. // we may be running on a computer without IP installed.
  51. WCHAR computerName[CNLEN + 1];
  52. DWORD nchar = CNLEN + 1;
  53. if (GetComputerNameW(computerName, &nchar))
  54. {
  55. PHOSTENT hostEnt = IASGetHostByName(computerName);
  56. if (hostEnt)
  57. {
  58. memcpy(invariant.serverAddress, hostEnt->h_addr, 4);
  59. LocalFree(hostEnt);
  60. }
  61. }
  62. // Set the boot time.
  63. FILETIME ft;
  64. GetSystemTimeAsFileTime(&ft);
  65. IASInsertDWORD(invariant.lastReboot, ft.dwHighDateTime);
  66. IASInsertDWORD(invariant.lastReboot + 4, ft.dwLowDateTime);
  67. // Reset the serial number.
  68. nextSerialNumber = 0;
  69. }
  70. PIASATTRIBUTE IASClass::createAttribute(const IAS_OCTET_STRING* tag) throw ()
  71. {
  72. //////////
  73. // Allocate an attribute.
  74. //////////
  75. PIASATTRIBUTE attr;
  76. if (IASAttributeAlloc(1, &attr) != NO_ERROR)
  77. {
  78. return NULL;
  79. }
  80. //////////
  81. // Allocate memory for the value.
  82. //////////
  83. DWORD len = sizeof(IASClass) + (tag ? tag->dwLength : 0);
  84. IASClass* cl = (IASClass*)CoTaskMemAlloc(len);
  85. if (cl == NULL)
  86. {
  87. IASAttributeRelease(attr);
  88. return NULL;
  89. }
  90. //////////
  91. // Copy in the parts that never change.
  92. //////////
  93. memcpy(cl->vendorID, invariant.vendorID, 22);
  94. //////////
  95. // Set the unique serial number.
  96. //////////
  97. IASInsertDWORD(cl->serialNumber + 4,
  98. InterlockedIncrement(&nextSerialNumber));
  99. //////////
  100. // Add the profile string (if any).
  101. //////////
  102. if (tag)
  103. {
  104. memcpy(cl->serialNumber + 8, tag->lpValue, tag->dwLength);
  105. }
  106. //////////
  107. // Compute and insert the checksum.
  108. //////////
  109. IASInsertDWORD(
  110. cl->checksum,
  111. IASAdler32(
  112. cl->vendorID,
  113. len - offsetof(IASClass, vendorID)
  114. )
  115. );
  116. //////////
  117. // Fill in the attribute fields.
  118. //////////
  119. attr->dwId = RADIUS_ATTRIBUTE_CLASS;
  120. attr->dwFlags = IAS_INCLUDE_IN_ACCEPT;
  121. attr->Value.itType = IASTYPE_OCTET_STRING;
  122. attr->Value.OctetString.lpValue = (PBYTE)cl;
  123. attr->Value.OctetString.dwLength = len;
  124. return attr;
  125. }