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.

221 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. if( ValueName.Length == 0 ) {
  67. //
  68. // overflow in RtlInitUnicodeString
  69. //
  70. Result = ERROR_INVALID_PARAMETER;
  71. goto ExitCleanup;
  72. }
  73. //
  74. // Call the Base API, passing it the supplied parameters and the
  75. // counted Unicode strings.
  76. //
  77. if( IsLocalHandle( hKey )) {
  78. Result = (LONG)LocalBaseRegDeleteValue (
  79. hKey,
  80. &ValueName
  81. );
  82. #if defined(_WIN64)
  83. if ( Result == 0) //only set dirty if operation succeed
  84. Wow64RegSetKeyDirty (hKey);
  85. #endif
  86. } else {
  87. Result = (LONG)BaseRegDeleteValue (
  88. DereferenceRemoteHandle( hKey ),
  89. &ValueName
  90. );
  91. }
  92. RtlFreeUnicodeString( &ValueName );
  93. ExitCleanup:
  94. CLOSE_LOCAL_HANDLE(TempHandle);
  95. return Result;
  96. }
  97. LONG
  98. APIENTRY
  99. RegDeleteValueW (
  100. HKEY hKey,
  101. LPCWSTR lpValueName
  102. )
  103. /*++
  104. Routine Description:
  105. Win32 Unicode RPC wrapper for deleting a value.
  106. RegDeleteValueW converts the lpValueName argument to a counted Unicode
  107. string and then calls BaseRegDeleteValue.
  108. --*/
  109. {
  110. UNICODE_STRING ValueName;
  111. HKEY TempHandle = NULL;
  112. LONG Result;
  113. #if DBG
  114. if ( BreakPointOnEntry ) {
  115. DbgBreakPoint();
  116. }
  117. #endif
  118. //
  119. // Limit the capabilities associated with HKEY_PERFORMANCE_DATA.
  120. //
  121. if( hKey == HKEY_PERFORMANCE_DATA ) {
  122. return ERROR_INVALID_HANDLE;
  123. }
  124. hKey = MapPredefinedHandle( hKey, &TempHandle );
  125. if( hKey == NULL ) {
  126. Result = ERROR_INVALID_HANDLE;
  127. goto ExitCleanup;
  128. }
  129. //
  130. // Convert the value name to a counted Unicode string.
  131. //
  132. RtlInitUnicodeString( &ValueName, lpValueName );
  133. //
  134. // Add terminating NULL to Length so that RPC transmits it
  135. //
  136. ValueName.Length += sizeof( UNICODE_NULL );
  137. if( ValueName.Length == 0 ) {
  138. //
  139. // overflow in RtlInitUnicodeString
  140. //
  141. Result = ERROR_INVALID_PARAMETER;
  142. goto ExitCleanup;
  143. }
  144. //
  145. // Call the Base API, passing it the supplied parameters and the
  146. // counted Unicode strings.
  147. //
  148. if( IsLocalHandle( hKey )) {
  149. Result = (LONG)LocalBaseRegDeleteValue (
  150. hKey,
  151. &ValueName
  152. );
  153. #if defined(_WIN64)
  154. if ( Result == 0) //only set dirty if operation succeed
  155. Wow64RegSetKeyDirty (hKey);
  156. #endif
  157. } else {
  158. Result = (LONG)BaseRegDeleteValue (
  159. DereferenceRemoteHandle( hKey ),
  160. &ValueName
  161. );
  162. }
  163. ExitCleanup:
  164. CLOSE_LOCAL_HANDLE(TempHandle);
  165. return Result;
  166. }