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.

162 lines
3.9 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 "precomp.h"
  12. NTSTATUS
  13. MoxaGetRegistryKeyValue (
  14. IN HANDLE Handle,
  15. IN PWCHAR KeyNameString,
  16. IN ULONG KeyNameStringLength,
  17. IN PVOID Data,
  18. IN ULONG DataLength,
  19. OUT PULONG ActualLength)
  20. /*++
  21. Routine Description:
  22. Reads a registry key value from an already opened registry key.
  23. Arguments:
  24. Handle Handle to the opened registry key
  25. KeyNameString ANSI string to the desired key
  26. KeyNameStringLength Length of the KeyNameString
  27. Data Buffer to place the key value in
  28. DataLength Length of the data buffer
  29. Return Value:
  30. STATUS_SUCCESS if all works, otherwise status of system call that
  31. went wrong.
  32. --*/
  33. {
  34. UNICODE_STRING keyName;
  35. ULONG length;
  36. PKEY_VALUE_FULL_INFORMATION fullInfo;
  37. NTSTATUS ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  38. MoxaKdPrint (MX_DBG_TRACE, ("Enter SerialGetRegistryKeyValue\n"));
  39. if (ActualLength) {
  40. *ActualLength = 0;
  41. }
  42. RtlInitUnicodeString (&keyName, KeyNameString);
  43. length = sizeof(KEY_VALUE_FULL_INFORMATION) + KeyNameStringLength
  44. + DataLength;
  45. fullInfo = ExAllocatePool(PagedPool, length);
  46. if (fullInfo) {
  47. ntStatus = ZwQueryValueKey (Handle,
  48. &keyName,
  49. KeyValueFullInformation,
  50. fullInfo,
  51. length,
  52. &length);
  53. if (NT_SUCCESS(ntStatus)) {
  54. //
  55. // If there is enough room in the data buffer, copy the output
  56. //
  57. if (DataLength >= fullInfo->DataLength) {
  58. RtlCopyMemory (Data,
  59. ((PUCHAR) fullInfo) + fullInfo->DataOffset,
  60. fullInfo->DataLength);
  61. if (ActualLength) {
  62. *ActualLength = fullInfo->DataLength;
  63. }
  64. }
  65. }
  66. else {
  67. MoxaKdPrint (MX_DBG_TRACE, ("GetRegistryKeyValue fail (%x)\n",ntStatus));
  68. }
  69. ExFreePool(fullInfo);
  70. }
  71. return ntStatus;
  72. }
  73. NTSTATUS
  74. MoxaPutRegistryKeyValue(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. MoxaKdPrint (MX_DBG_TRACE,("Enter MoxaPutRegistryKeyValue\n"));
  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. }