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.

166 lines
3.4 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 //LOCAL
  47. //
  48. // Check for malformed arguments from malicious clients
  49. //
  50. if( (lpValueName == NULL) ||
  51. (lpValueName->Length < sizeof(UNICODE_NULL)) ||
  52. ((lpValueName->Length % sizeof(WCHAR)) != 0) ) {
  53. return(ERROR_INVALID_PARAMETER);
  54. }
  55. hkDelete = hKey;
  56. //
  57. // Subtract the NULL from the string length. This was added
  58. // by the client so that RPC would transmit the whole thing.
  59. //
  60. lpValueName->Length -= sizeof( UNICODE_NULL );
  61. //
  62. // Call the Nt Api to delete the value, map the NTSTATUS code to a
  63. // Win32 Registry error code and return.
  64. //
  65. #ifdef LOCAL
  66. if (gpfnTermsrvDeleteValue) {
  67. //
  68. // Remove the value from the Terminal Server registry tracking database
  69. //
  70. gpfnTermsrvDeleteValue(hKey, lpValueName);
  71. }
  72. #endif
  73. #ifdef LOCAL
  74. if (REG_CLASS_IS_SPECIAL_KEY(hKey)) {
  75. Status = BaseRegGetUserAndMachineClass(
  76. NULL,
  77. hkDelete,
  78. MAXIMUM_ALLOWED,
  79. &hkMachineClasses,
  80. &hkUserClasses);
  81. if (!NT_SUCCESS(Status)) {
  82. return (error_status_t)RtlNtStatusToDosError(Status);
  83. }
  84. }
  85. if (hkUserClasses && hkMachineClasses) {
  86. hkDelete = hkUserClasses;
  87. }
  88. #endif
  89. Status = NtDeleteValueKey(
  90. hkDelete,
  91. lpValueName
  92. );
  93. #ifdef LOCAL
  94. //
  95. // For class keys, try again with machine if there were
  96. // two keys of the same name
  97. //
  98. if (REG_CLASS_IS_SPECIAL_KEY(hKey)) {
  99. if ((STATUS_OBJECT_NAME_NOT_FOUND == Status) &&
  100. (hkUserClasses && hkMachineClasses)) {
  101. Status = NtDeleteValueKey(
  102. hkMachineClasses,
  103. lpValueName
  104. );
  105. }
  106. }
  107. if (hkUserClasses && hkMachineClasses) {
  108. if (hkUserClasses != hKey) {
  109. NtClose(hkUserClasses);
  110. } else {
  111. NtClose(hkMachineClasses);
  112. }
  113. }
  114. #endif // LOCAL
  115. return (error_status_t)RtlNtStatusToDosError(Status);
  116. }