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.

197 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. adtutil.c - Security Auditing - Utility Routines
  5. Abstract:
  6. This Module contains miscellaneous utility routines private to the
  7. Security Auditing Component.
  8. Author:
  9. Robert Reichel (robertre) September 10, 1991
  10. Environment:
  11. Kernel Mode
  12. Revision History:
  13. --*/
  14. #include "pch.h"
  15. #pragma hdrstop
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text(PAGE,SepRegQueryDwordValue)
  18. #endif
  19. NTSTATUS
  20. SepRegQueryHelper(
  21. IN PCWSTR KeyName,
  22. IN PCWSTR ValueName,
  23. IN ULONG ValueType,
  24. IN ULONG ValueLength,
  25. OUT PVOID ValueBuffer,
  26. OUT PULONG LengthRequired
  27. )
  28. /*++
  29. Routine Description:
  30. Open regkey KeyName, read the value specified by ValueName
  31. and return the value.
  32. Arguments:
  33. KeyName - name of key to open
  34. ValueName - name of value to read
  35. ValueType - type of value to read (REG_DWORD etc.)
  36. ValueLength - size in bytes of the value to read
  37. ValueBuffer - pointer to returned value
  38. LengthRequired - if the passed buffer is not sufficient to hold
  39. the value, this param will return the actual size
  40. in bytes required.
  41. Return Value:
  42. NTSTATUS - Standard Nt Result Code
  43. Notes:
  44. --*/
  45. {
  46. UNICODE_STRING usKey, usValue;
  47. OBJECT_ATTRIBUTES ObjectAttributes = { 0 };
  48. //
  49. // we will read-in data upto 64 bytes in stack buffer
  50. //
  51. CHAR KeyInfo[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 64];
  52. PKEY_VALUE_PARTIAL_INFORMATION pKeyInfo;
  53. HANDLE hKey = NULL;
  54. NTSTATUS Status = STATUS_SUCCESS;
  55. NTSTATUS CloseStatus;
  56. ULONG ResultLength;
  57. PAGED_CODE();
  58. RtlInitUnicodeString( &usKey, KeyName );
  59. InitializeObjectAttributes(
  60. &ObjectAttributes,
  61. &usKey,
  62. OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
  63. NULL,
  64. NULL
  65. );
  66. Status = ZwOpenKey(
  67. &hKey,
  68. KEY_QUERY_VALUE | OBJ_KERNEL_HANDLE,
  69. &ObjectAttributes
  70. );
  71. if (NT_SUCCESS( Status ))
  72. {
  73. RtlInitUnicodeString( &usValue, ValueName );
  74. Status = ZwQueryValueKey(
  75. hKey,
  76. &usValue,
  77. KeyValuePartialInformation,
  78. KeyInfo,
  79. sizeof(KeyInfo),
  80. &ResultLength
  81. );
  82. if (NT_SUCCESS( Status ))
  83. {
  84. pKeyInfo = (PKEY_VALUE_PARTIAL_INFORMATION)KeyInfo;
  85. if (( pKeyInfo->Type == ValueType) &&
  86. ( pKeyInfo->DataLength == ValueLength ))
  87. {
  88. switch (ValueType)
  89. {
  90. case REG_DWORD:
  91. *((PULONG)ValueBuffer) = *((PULONG) (pKeyInfo->Data));
  92. break;
  93. case REG_BINARY:
  94. RtlCopyMemory( ValueBuffer, pKeyInfo->Data, ValueLength );
  95. break;
  96. default:
  97. Status = STATUS_INVALID_PARAMETER;
  98. break;
  99. }
  100. }
  101. else
  102. {
  103. Status = STATUS_OBJECT_TYPE_MISMATCH;
  104. }
  105. }
  106. CloseStatus = ZwClose(hKey);
  107. ASSERT( NT_SUCCESS( CloseStatus ));
  108. }
  109. return Status;
  110. }
  111. NTSTATUS
  112. SepRegQueryDwordValue(
  113. IN PCWSTR KeyName,
  114. IN PCWSTR ValueName,
  115. OUT PULONG Value
  116. )
  117. /*++
  118. Routine Description:
  119. Open regkey KeyName, read a REG_DWORD value specified by ValueName
  120. and return the value.
  121. Arguments:
  122. KeyName - name of key to open
  123. ValueName - name of value to read
  124. Value - pointer to returned value
  125. Return Value:
  126. NTSTATUS - Standard Nt Result Code
  127. Notes:
  128. --*/
  129. {
  130. return SepRegQueryHelper(
  131. KeyName,
  132. ValueName,
  133. REG_DWORD,
  134. sizeof(ULONG),
  135. Value,
  136. NULL
  137. );
  138. }