Source code of Windows XP (NT5)
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.

158 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. Regdval.c
  5. Abstract:
  6. This module contains the server side implementation for the Win32
  7. Registry API to delete values from keys. That is:
  8. - BaseRegDeleteValue
  9. Author:
  10. David J. Gilman (davegi) 15-Nov-1991
  11. Notes:
  12. See the Notes in Regkey.c.
  13. --*/
  14. #include <rpc.h>
  15. #include "regrpc.h"
  16. #include "localreg.h"
  17. #ifdef LOCAL
  18. #include "tsappcmp.h"
  19. #include "regclass.h"
  20. #endif
  21. error_status_t
  22. BaseRegDeleteValue (
  23. HKEY hKey,
  24. PUNICODE_STRING lpValueName
  25. )
  26. /*++
  27. Routine Description:
  28. Remove the named value from the specified key.
  29. Arguments:
  30. hKey - Supplies a handle to the open key.
  31. lpValueName - Supplies the name of the value to remove. lpValueName
  32. may be NULL.
  33. Return Value:
  34. Returns ERROR_SUCCESS (0) for success; error-code for failure.
  35. Notes:
  36. hKey must have been opened for KEY_SET_VALUE.
  37. --*/
  38. {
  39. HKEY hkDelete;
  40. NTSTATUS Status;
  41. #ifdef LOCAL
  42. HKEY hkUserClasses;
  43. HKEY hkMachineClasses;
  44. hkUserClasses = NULL;
  45. hkMachineClasses = NULL;
  46. #endif
  47. hkDelete = hKey;
  48. //
  49. // Subtract the NULL from the string length. This was added
  50. // by the client so that RPC would transmit the whole thing.
  51. //
  52. lpValueName->Length -= sizeof( UNICODE_NULL );
  53. //
  54. // Call the Nt Api to delete the value, map the NTSTATUS code to a
  55. // Win32 Registry error code and return.
  56. //
  57. #ifdef LOCAL
  58. if (gpfnTermsrvDeleteValue) {
  59. //
  60. // Remove the value from the Terminal Server registry tracking database
  61. //
  62. gpfnTermsrvDeleteValue(hKey, lpValueName);
  63. }
  64. #endif
  65. #ifdef LOCAL
  66. if (REG_CLASS_IS_SPECIAL_KEY(hKey)) {
  67. Status = BaseRegGetUserAndMachineClass(
  68. NULL,
  69. hkDelete,
  70. MAXIMUM_ALLOWED,
  71. &hkMachineClasses,
  72. &hkUserClasses);
  73. if (!NT_SUCCESS(Status)) {
  74. return (error_status_t)RtlNtStatusToDosError(Status);
  75. }
  76. }
  77. if (hkUserClasses && hkMachineClasses) {
  78. hkDelete = hkUserClasses;
  79. }
  80. #endif
  81. Status = NtDeleteValueKey(
  82. hkDelete,
  83. lpValueName
  84. );
  85. #ifdef LOCAL
  86. //
  87. // For class keys, try again with machine if there were
  88. // two keys of the same name
  89. //
  90. if (REG_CLASS_IS_SPECIAL_KEY(hKey)) {
  91. if ((STATUS_OBJECT_NAME_NOT_FOUND == Status) &&
  92. (hkUserClasses && hkMachineClasses)) {
  93. Status = NtDeleteValueKey(
  94. hkMachineClasses,
  95. lpValueName
  96. );
  97. }
  98. }
  99. if (hkUserClasses && hkMachineClasses) {
  100. if (hkUserClasses != hKey) {
  101. NtClose(hkUserClasses);
  102. } else {
  103. NtClose(hkMachineClasses);
  104. }
  105. }
  106. #endif // LOCAL
  107. return (error_status_t)RtlNtStatusToDosError(Status);
  108. }