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.

186 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. NtHard.c
  5. Abstract:
  6. Author:
  7. Revision History:
  8. --*/
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. #if defined(i386)
  12. #define REGISTRY_HARDWARE_DESCRIPTION \
  13. TEXT("\\Registry\\Machine\\Hardware\\DESCRIPTION\\System")
  14. #define REGISTRY_MACHINE_IDENTIFIER \
  15. TEXT("Identifier")
  16. #define FUJITSU_FMR_NAME TEXT("FUJITSU FMR-")
  17. #define NEC_PC98_NAME TEXT("NEC PC-98")
  18. #define KEY_WORK_AREA ((sizeof(KEY_VALUE_FULL_INFORMATION) + \
  19. sizeof(ULONG)) + 256)
  20. NTSTATUS
  21. NtGetMachineIdentifierValue(
  22. IN OUT PULONG Value
  23. )
  24. /*++
  25. Routine Description:
  26. Given a unicode value name this routine will go into the registry
  27. location for the machine identifier information and get the
  28. value.
  29. Arguments:
  30. ValueName - the unicode name for the registry value located in the
  31. identifier location of the registry.
  32. Value - a pointer to the ULONG for the result.
  33. Return Value:
  34. NTSTATUS
  35. If STATUS_SUCCESSFUL is returned, the location *Value will be
  36. updated with the DWORD value from the registry. If any failing
  37. status is returned, this value is untouched.
  38. --*/
  39. {
  40. HANDLE Handle;
  41. NTSTATUS Status;
  42. ULONG RequestLength;
  43. ULONG ResultLength;
  44. UCHAR Buffer[KEY_WORK_AREA];
  45. UNICODE_STRING KeyName;
  46. UNICODE_STRING ValueName;
  47. OBJECT_ATTRIBUTES ObjectAttributes;
  48. PKEY_VALUE_FULL_INFORMATION KeyValueInformation;
  49. //
  50. // Set default as PC/AT
  51. //
  52. *Value = MACHINEID_MS_PCAT;
  53. KeyName.Buffer = REGISTRY_HARDWARE_DESCRIPTION;
  54. KeyName.Length = sizeof(REGISTRY_HARDWARE_DESCRIPTION) - sizeof(WCHAR);
  55. KeyName.MaximumLength = sizeof(REGISTRY_HARDWARE_DESCRIPTION);
  56. InitializeObjectAttributes(&ObjectAttributes,
  57. &KeyName,
  58. OBJ_CASE_INSENSITIVE,
  59. NULL,
  60. NULL);
  61. Status = NtOpenKey(&Handle,
  62. KEY_READ,
  63. &ObjectAttributes);
  64. if (!NT_SUCCESS(Status)) {
  65. return Status;
  66. }
  67. ValueName.Buffer = REGISTRY_MACHINE_IDENTIFIER;
  68. ValueName.Length = sizeof(REGISTRY_MACHINE_IDENTIFIER) - sizeof(WCHAR);
  69. ValueName.MaximumLength = sizeof(REGISTRY_MACHINE_IDENTIFIER);
  70. RequestLength = KEY_WORK_AREA;
  71. KeyValueInformation = (PKEY_VALUE_FULL_INFORMATION)Buffer;
  72. Status = NtQueryValueKey(Handle,
  73. &ValueName,
  74. KeyValueFullInformation,
  75. KeyValueInformation,
  76. RequestLength,
  77. &ResultLength);
  78. ASSERT( Status != STATUS_BUFFER_OVERFLOW );
  79. NtClose(Handle);
  80. if (NT_SUCCESS(Status)) {
  81. if (KeyValueInformation->DataLength != 0) {
  82. PWCHAR DataPtr;
  83. UNICODE_STRING DetectedString, TargetString1, TargetString2;
  84. //
  85. // Return contents to the caller.
  86. //
  87. DataPtr = (PWCHAR)
  88. ((PUCHAR)KeyValueInformation + KeyValueInformation->DataOffset);
  89. //
  90. // Initialize strings.
  91. //
  92. RtlInitUnicodeString( &DetectedString, DataPtr );
  93. RtlInitUnicodeString( &TargetString1, FUJITSU_FMR_NAME );
  94. RtlInitUnicodeString( &TargetString2, NEC_PC98_NAME );
  95. //
  96. // Check the hardware platform
  97. //
  98. if (RtlPrefixUnicodeString( &TargetString1 , &DetectedString , TRUE)) {
  99. //
  100. // Fujitsu FMR Series.
  101. //
  102. *Value = MACHINEID_FUJITSU_FMR;
  103. } else if (RtlPrefixUnicodeString( &TargetString2 , &DetectedString , TRUE)) {
  104. //
  105. // NEC PC-9800 Seriss
  106. //
  107. *Value = MACHINEID_NEC_PC98;
  108. } else {
  109. //
  110. // Standard PC/AT comapatibles
  111. //
  112. *Value = MACHINEID_MS_PCAT;
  113. }
  114. } else {
  115. //
  116. // Treat as if no value was found
  117. //
  118. Status = STATUS_OBJECT_NAME_NOT_FOUND;
  119. }
  120. }
  121. return Status;
  122. }
  123. #endif // defined(i386)