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.

136 lines
3.2 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Module: registry.c
  4. //
  5. // Description:
  6. //
  7. //
  8. //@@BEGIN_MSINTERNAL
  9. // Development Team:
  10. // Mike McLaughlin
  11. //
  12. // History: Date Author Comment
  13. //
  14. // To Do: Date Author Comment
  15. //
  16. //@@END_MSINTERNAL
  17. //
  18. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  19. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  20. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  21. // PURPOSE.
  22. //
  23. // Copyright (c) 1996-1999 Microsoft Corporation. All Rights Reserved.
  24. //
  25. //---------------------------------------------------------------------------
  26. #include "common.h"
  27. //===========================================================================
  28. //===========================================================================
  29. //
  30. // OpenRegistryKeyForRead
  31. //
  32. NTSTATUS
  33. OpenRegistryKeyForRead(
  34. PCWSTR pcwstr,
  35. PHANDLE pHandle,
  36. HANDLE hRootDir
  37. )
  38. {
  39. UNICODE_STRING UnicodeDeviceString;
  40. OBJECT_ATTRIBUTES ObjectAttributes;
  41. RtlInitUnicodeString(&UnicodeDeviceString, pcwstr);
  42. //
  43. // SECURITY NOTE:
  44. // This function is called from AddFilter notification function
  45. // which runs under system process.
  46. // Therefore OBJ_KERNEL_HANDLE is not necessary.
  47. //
  48. InitializeObjectAttributes(
  49. &ObjectAttributes,
  50. &UnicodeDeviceString,
  51. OBJ_CASE_INSENSITIVE,
  52. hRootDir,
  53. NULL);
  54. return(ZwOpenKey(
  55. pHandle,
  56. KEY_READ,
  57. &ObjectAttributes));
  58. } // OpenRegistryKeyForRead
  59. NTSTATUS
  60. QueryRegistryValue(
  61. HANDLE hkey,
  62. PCWSTR pcwstrValueName,
  63. PKEY_VALUE_FULL_INFORMATION *ppkvfi
  64. )
  65. {
  66. UNICODE_STRING ustrValueName;
  67. NTSTATUS Status;
  68. ULONG cbValue;
  69. ASSERT(pcwstrValueName);
  70. ASSERT(ppkvfi);
  71. *ppkvfi = NULL;
  72. RtlInitUnicodeString(&ustrValueName, pcwstrValueName);
  73. //
  74. // Get the size of buffer required to read the registry key.
  75. //
  76. Status = ZwQueryValueKey(
  77. hkey,
  78. &ustrValueName,
  79. KeyValueFullInformation,
  80. NULL,
  81. 0,
  82. &cbValue);
  83. //
  84. // SECURITY NOTE:
  85. // If the above ZwQueryValueKey function returns STATUS_SUCCESS, the callers
  86. // will get pkvfi = NULL. And eventually crash.
  87. // The good news is that ZwQueryValueKey will never return STATUS_SUCCESS
  88. // with KeyValueFullInformation.
  89. //
  90. ASSERT(!(NT_SUCCESS(Status)));
  91. if(Status != STATUS_BUFFER_OVERFLOW &&
  92. Status != STATUS_BUFFER_TOO_SMALL) {
  93. goto exit;
  94. }
  95. //
  96. // Allocate the data buffer.
  97. //
  98. *ppkvfi = (PKEY_VALUE_FULL_INFORMATION) new BYTE[cbValue];
  99. if(*ppkvfi == NULL) {
  100. Status = STATUS_INSUFFICIENT_RESOURCES;
  101. goto exit;
  102. }
  103. //
  104. // Read the actual data and associated type information.
  105. //
  106. Status = ZwQueryValueKey(
  107. hkey,
  108. &ustrValueName,
  109. KeyValueFullInformation,
  110. *ppkvfi,
  111. cbValue,
  112. &cbValue);
  113. if(!NT_SUCCESS(Status)) {
  114. delete *ppkvfi;
  115. *ppkvfi = NULL;
  116. goto exit;
  117. }
  118. exit:
  119. return(Status);
  120. }