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.

160 lines
3.8 KiB

  1. /*++
  2. Module Name:
  3. registry.c
  4. Abstract:
  5. This module contains the code that is used to get values from the
  6. registry and to manipulate entries in the registry.
  7. Environment:
  8. Kernel mode
  9. Revision History :
  10. --*/
  11. #include <ntddk.h>
  12. #include <ntddser.h>
  13. #include "mxenum.h"
  14. #ifdef ALLOC_PRAGMA
  15. #pragma alloc_text(PAGE,MxenumGetRegistryKeyValue)
  16. #pragma alloc_text(PAGE,MxenumPutRegistryKeyValue)
  17. #endif // ALLOC_PRAGMA
  18. NTSTATUS
  19. MxenumGetRegistryKeyValue (
  20. IN HANDLE Handle,
  21. IN PWCHAR KeyNameString,
  22. IN ULONG KeyNameStringLength,
  23. IN PVOID Data,
  24. IN ULONG DataLength, // Optional
  25. OUT PULONG ActualLength)
  26. /*++
  27. Routine Description:
  28. Reads a registry key value from an already opened registry key.
  29. Arguments:
  30. Handle Handle to the opened registry key
  31. KeyNameString ANSI string to the desired key
  32. KeyNameStringLength Length of the KeyNameString
  33. Data Buffer to place the key value in
  34. DataLength Length of the data buffer
  35. Return Value:
  36. STATUS_SUCCESS if all works, otherwise status of system call that
  37. went wrong.
  38. --*/
  39. {
  40. UNICODE_STRING keyName;
  41. ULONG length;
  42. PKEY_VALUE_FULL_INFORMATION fullInfo;
  43. NTSTATUS ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  44. PAGED_CODE();
  45. RtlInitUnicodeString (&keyName, KeyNameString);
  46. length = sizeof(KEY_VALUE_FULL_INFORMATION) + KeyNameStringLength
  47. + DataLength;
  48. fullInfo = ExAllocatePool(PagedPool, length);
  49. if (fullInfo) {
  50. ntStatus = ZwQueryValueKey (Handle,
  51. &keyName,
  52. KeyValueFullInformation,
  53. fullInfo,
  54. length,
  55. &length);
  56. if (NT_SUCCESS(ntStatus)) {
  57. //
  58. // If there is enough room in the data buffer, copy the output
  59. //
  60. if (DataLength >= fullInfo->DataLength) {
  61. RtlCopyMemory (Data,
  62. ((PUCHAR) fullInfo) + fullInfo->DataOffset,
  63. fullInfo->DataLength);
  64. }
  65. if (ActualLength) {
  66. *ActualLength = fullInfo->DataLength;
  67. }
  68. }
  69. ExFreePool(fullInfo);
  70. }
  71. return ntStatus;
  72. }
  73. NTSTATUS
  74. MxenumPutRegistryKeyValue(IN HANDLE Handle, IN PWCHAR PKeyNameString,
  75. IN ULONG KeyNameStringLength, IN ULONG Dtype,
  76. IN PVOID PData, IN ULONG DataLength)
  77. /*++
  78. Routine Description:
  79. Writes a registry key value to an already opened registry key.
  80. Arguments:
  81. Handle Handle to the opened registry key
  82. PKeyNameString ANSI string to the desired key
  83. KeyNameStringLength Length of the KeyNameString
  84. Dtype REG_XYZ value type
  85. PData Buffer to place the key value in
  86. DataLength Length of the data buffer
  87. Return Value:
  88. STATUS_SUCCESS if all works, otherwise status of system call that
  89. went wrong.
  90. --*/
  91. {
  92. NTSTATUS status;
  93. UNICODE_STRING keyname;
  94. PAGED_CODE();
  95. RtlInitUnicodeString(&keyname, NULL);
  96. keyname.MaximumLength = (USHORT)(KeyNameStringLength + sizeof(WCHAR));
  97. keyname.Buffer = ExAllocatePool(PagedPool, keyname.MaximumLength);
  98. if (keyname.Buffer == NULL) {
  99. return STATUS_INSUFFICIENT_RESOURCES;
  100. }
  101. RtlAppendUnicodeToString(&keyname, PKeyNameString);
  102. status = ZwSetValueKey(Handle, &keyname, 0, Dtype, PData, DataLength);
  103. ExFreePool(keyname.Buffer);
  104. return status;
  105. }