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.

209 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Regdval.c
  5. Abstract:
  6. This module contains the client side wrappers for the Win32 Registry
  7. APIs to delete values from a key. That is:
  8. - RegDeleteValueA
  9. - RegDeleteValueW
  10. Author:
  11. David J. Gilman (davegi) 18-Mar-1992
  12. Notes:
  13. See the notes in server\regdval.c.
  14. --*/
  15. #include <rpc.h>
  16. #include "regrpc.h"
  17. #include "client.h"
  18. #if defined(_WIN64)
  19. #include <wow64reg.h>
  20. #endif
  21. LONG
  22. APIENTRY
  23. RegDeleteValueA (
  24. HKEY hKey,
  25. LPCSTR lpValueName
  26. )
  27. /*++
  28. Routine Description:
  29. Win32 ANSI RPC wrapper for deleting a value.
  30. RegDeleteValueA converts the lpValueName argument to a counted Unicode
  31. string and then calls BaseRegDeleteValue.
  32. --*/
  33. {
  34. UNICODE_STRING ValueName;
  35. NTSTATUS Status;
  36. HKEY TempHandle = NULL;
  37. LONG Result;
  38. #if DBG
  39. if ( BreakPointOnEntry ) {
  40. DbgBreakPoint();
  41. }
  42. #endif
  43. //
  44. // Limit the capabilities associated with HKEY_PERFORMANCE_DATA.
  45. //
  46. if( hKey == HKEY_PERFORMANCE_DATA ) {
  47. return ERROR_INVALID_HANDLE;
  48. }
  49. hKey = MapPredefinedHandle( hKey, &TempHandle );
  50. if( hKey == NULL ) {
  51. Result = ERROR_INVALID_HANDLE;
  52. goto ExitCleanup;
  53. }
  54. //
  55. // Convert the value name to a counted Unicode
  56. //
  57. if( !RtlCreateUnicodeStringFromAsciiz(&ValueName,lpValueName) ) {
  58. Status = STATUS_NO_MEMORY;
  59. Result = RtlNtStatusToDosError( Status );
  60. goto ExitCleanup;
  61. }
  62. //
  63. // Add terminating NULL to Length so that RPC transmits it
  64. //
  65. ValueName.Length += sizeof( UNICODE_NULL );
  66. //
  67. // Call the Base API, passing it the supplied parameters and the
  68. // counted Unicode strings.
  69. //
  70. if( IsLocalHandle( hKey )) {
  71. Result = (LONG)LocalBaseRegDeleteValue (
  72. hKey,
  73. &ValueName
  74. );
  75. #if defined(_WIN64)
  76. if ( Result == 0) //only set dirty if operation succeed
  77. Wow64RegSetKeyDirty (hKey);
  78. #endif
  79. } else {
  80. Result = (LONG)BaseRegDeleteValue (
  81. DereferenceRemoteHandle( hKey ),
  82. &ValueName
  83. );
  84. }
  85. RtlFreeUnicodeString( &ValueName );
  86. ExitCleanup:
  87. CLOSE_LOCAL_HANDLE(TempHandle);
  88. return Result;
  89. }
  90. LONG
  91. APIENTRY
  92. RegDeleteValueW (
  93. HKEY hKey,
  94. LPCWSTR lpValueName
  95. )
  96. /*++
  97. Routine Description:
  98. Win32 Unicode RPC wrapper for deleting a value.
  99. RegDeleteValueW converts the lpValueName argument to a counted Unicode
  100. string and then calls BaseRegDeleteValue.
  101. --*/
  102. {
  103. UNICODE_STRING ValueName;
  104. HKEY TempHandle = NULL;
  105. LONG Result;
  106. NTSTATUS Status;
  107. #if DBG
  108. if ( BreakPointOnEntry ) {
  109. DbgBreakPoint();
  110. }
  111. #endif
  112. //
  113. // Limit the capabilities associated with HKEY_PERFORMANCE_DATA.
  114. //
  115. if( hKey == HKEY_PERFORMANCE_DATA ) {
  116. return ERROR_INVALID_HANDLE;
  117. }
  118. hKey = MapPredefinedHandle( hKey, &TempHandle );
  119. if( hKey == NULL ) {
  120. Result = ERROR_INVALID_HANDLE;
  121. goto ExitCleanup;
  122. }
  123. //
  124. // Convert the value name to a counted Unicode string.
  125. // This also acounts for the NULL we are adding at the end
  126. //
  127. Status = RtlInitUnicodeStringEx(&ValueName, lpValueName);
  128. if( !NT_SUCCESS(Status) ) {
  129. Result = RtlNtStatusToDosError( Status );
  130. goto ExitCleanup;
  131. }
  132. //
  133. // Add terminating NULL to Length so that RPC transmits it
  134. //
  135. ValueName.Length += sizeof( UNICODE_NULL );
  136. //
  137. // Call the Base API, passing it the supplied parameters and the
  138. // counted Unicode strings.
  139. //
  140. if( IsLocalHandle( hKey )) {
  141. Result = (LONG)LocalBaseRegDeleteValue (
  142. hKey,
  143. &ValueName
  144. );
  145. #if defined(_WIN64)
  146. if ( Result == 0) //only set dirty if operation succeed
  147. Wow64RegSetKeyDirty (hKey);
  148. #endif
  149. } else {
  150. Result = (LONG)BaseRegDeleteValue (
  151. DereferenceRemoteHandle( hKey ),
  152. &ValueName
  153. );
  154. }
  155. ExitCleanup:
  156. CLOSE_LOCAL_HANDLE(TempHandle);
  157. return Result;
  158. }