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.

205 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Regdkey.c
  5. Abstract:
  6. This module contains the client side wrappers for the Win32 Registry
  7. APIs to delete a key. That is:
  8. - RegDeleteKeyA
  9. - RegDeleteKeyW
  10. Author:
  11. David J. Gilman (davegi) 18-Mar-1992
  12. Notes:
  13. See the notes in server\regdkey.c.
  14. --*/
  15. #include <rpc.h>
  16. #include "regrpc.h"
  17. #include "client.h"
  18. LONG
  19. APIENTRY
  20. RegDeleteKeyA (
  21. HKEY hKey,
  22. LPCSTR lpKeyName
  23. )
  24. /*++
  25. Routine Description:
  26. Win32 ANSI RPC wrapper for deleting a Key.
  27. RegDeleteKeyA converts the lpKeyName argument to a counted Unicode string
  28. and then calls BaseRegDeleteKey.
  29. --*/
  30. {
  31. UNICODE_STRING KeyName;
  32. NTSTATUS Status;
  33. HKEY TempHandle = NULL;
  34. LONG Result;
  35. #if DBG
  36. if ( BreakPointOnEntry ) {
  37. DbgBreakPoint();
  38. }
  39. #endif
  40. if( lpKeyName == NULL ) {
  41. return ERROR_INVALID_PARAMETER;
  42. }
  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 Key name to a counted Unicode string
  56. //
  57. if( !RtlCreateUnicodeStringFromAsciiz(&KeyName,lpKeyName) ) {
  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. KeyName.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)LocalBaseRegDeleteKey (
  72. hKey,
  73. &KeyName
  74. );
  75. } else {
  76. Result = (LONG)BaseRegDeleteKey (
  77. DereferenceRemoteHandle( hKey ),
  78. &KeyName
  79. );
  80. }
  81. RtlFreeUnicodeString( &KeyName );
  82. ExitCleanup:
  83. CLOSE_LOCAL_HANDLE(TempHandle);
  84. return Result;
  85. }
  86. LONG
  87. APIENTRY
  88. RegDeleteKeyW (
  89. HKEY hKey,
  90. LPCWSTR lpKeyName
  91. )
  92. /*++
  93. Routine Description:
  94. Win32 Unicode RPC wrapper for deleting a Key.
  95. RegDeleteKeyW converts the lpKeyName argument to a counted Unicode string
  96. and then calls BaseRegDeleteKey.
  97. --*/
  98. {
  99. UNICODE_STRING KeyName;
  100. HKEY TempHandle = NULL;
  101. LONG Result;
  102. #if DBG
  103. if ( BreakPointOnEntry ) {
  104. DbgBreakPoint();
  105. }
  106. #endif
  107. if( lpKeyName == NULL ) {
  108. return ERROR_INVALID_PARAMETER;
  109. }
  110. //
  111. // Limit the capabilities associated with HKEY_PERFORMANCE_DATA.
  112. //
  113. if( hKey == HKEY_PERFORMANCE_DATA ) {
  114. return ERROR_INVALID_HANDLE;
  115. }
  116. hKey = MapPredefinedHandle( hKey, &TempHandle );
  117. // ASSERT( hKey != NULL );
  118. if( hKey == NULL ) {
  119. Result = ERROR_INVALID_HANDLE;
  120. goto ExitCleanup;
  121. }
  122. //
  123. // Convert the Key name to a counted Unicode string.
  124. //
  125. RtlInitUnicodeString( &KeyName, lpKeyName );
  126. //
  127. // Add terminating NULL to Length so that RPC transmits it
  128. //
  129. KeyName.Length += sizeof( UNICODE_NULL );
  130. //
  131. // Call the Base API, passing it the supplied parameters and the
  132. // counted Unicode strings.
  133. //
  134. if( IsLocalHandle( hKey )) {
  135. Result = (LONG)LocalBaseRegDeleteKey (
  136. hKey,
  137. &KeyName
  138. );
  139. } else {
  140. Result = (LONG)BaseRegDeleteKey (
  141. DereferenceRemoteHandle( hKey ),
  142. &KeyName
  143. );
  144. }
  145. ExitCleanup:
  146. CLOSE_LOCAL_HANDLE(TempHandle);
  147. return Result;
  148. }