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.2 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. NTSTATUS Status;
  103. #if DBG
  104. if ( BreakPointOnEntry ) {
  105. DbgBreakPoint();
  106. }
  107. #endif
  108. if( lpKeyName == NULL ) {
  109. return ERROR_INVALID_PARAMETER;
  110. }
  111. //
  112. // Limit the capabilities associated with HKEY_PERFORMANCE_DATA.
  113. //
  114. if( hKey == HKEY_PERFORMANCE_DATA ) {
  115. return ERROR_INVALID_HANDLE;
  116. }
  117. hKey = MapPredefinedHandle( hKey, &TempHandle );
  118. // ASSERT( hKey != NULL );
  119. if( hKey == NULL ) {
  120. Result = ERROR_INVALID_HANDLE;
  121. goto ExitCleanup;
  122. }
  123. //
  124. // Convert the Key name to a counted Unicode string.
  125. // This also acounts for the NULL we are adding at the end
  126. //
  127. Status = RtlInitUnicodeStringEx(&KeyName, lpKeyName);
  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. KeyName.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)LocalBaseRegDeleteKey (
  142. hKey,
  143. &KeyName
  144. );
  145. } else {
  146. Result = (LONG)BaseRegDeleteKey (
  147. DereferenceRemoteHandle( hKey ),
  148. &KeyName
  149. );
  150. }
  151. ExitCleanup:
  152. CLOSE_LOCAL_HANDLE(TempHandle);
  153. return Result;
  154. }