[ADVAPI32]
authorJérôme Gardou <jerome.gardou@reactos.org>
Tue, 30 Sep 2014 22:05:50 +0000 (22:05 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Tue, 30 Sep 2014 22:05:50 +0000 (22:05 +0000)
 - Centralize RegDeleteKey[Ex]{A,W} implementation into RegDeleteKeyExW
 - Update the HKCR wrapper accordingly.
CORE-8582

svn path=/trunk/; revision=64427

reactos/dll/win32/advapi32/reg/hkcr.c
reactos/dll/win32/advapi32/reg/reg.c
reactos/dll/win32/advapi32/reg/reg.h

index 5180f45..32b12d6 100644 (file)
@@ -272,7 +272,9 @@ LONG
 WINAPI
 DeleteHKCRKey(
     _In_ HKEY hKey,
-    _In_ LPCWSTR lpSubKey)
+    _In_ LPCWSTR lpSubKey,
+    _In_ REGSAM RegSam,
+    _In_ DWORD Reserved)
 {
     HKEY QueriedKey;
     LONG ErrorCode;
@@ -287,7 +289,7 @@ DeleteHKCRKey(
     if (ErrorCode == ERROR_FILE_NOT_FOUND)
     {
         /* The key doesn't exist on HKCU side, no chance for a subkey */
-        return RegDeleteKeyW(hKey, lpSubKey);
+        return RegDeleteKeyExW(hKey, lpSubKey, RegSam, Reserved);
     }
 
     if (ErrorCode != ERROR_SUCCESS)
@@ -296,7 +298,7 @@ DeleteHKCRKey(
         return ErrorCode;
     }
 
-    ErrorCode = RegDeleteKeyW(QueriedKey, lpSubKey);
+    ErrorCode = RegDeleteKeyExW(QueriedKey, lpSubKey, RegSam, Reserved);
 
     /* Close it if we must */
     if (QueriedKey != hKey)
@@ -317,7 +319,7 @@ DeleteHKCRKey(
         return ErrorCode;
     }
 
-    ErrorCode = RegDeleteKeyW(QueriedKey, lpSubKey);
+    ErrorCode = RegDeleteKeyExW(QueriedKey, lpSubKey, RegSam, Reserved);
 
     /* Close it if we must */
     if (QueriedKey != hKey)
index b68337d..3ac7545 100644 (file)
@@ -1181,20 +1181,13 @@ RegCreateKeyW(HKEY hKey,
  *
  * @implemented
  */
-LONG WINAPI
-RegDeleteKeyA(HKEY hKey,
-              LPCSTR lpSubKey)
+LONG
+WINAPI
+RegDeleteKeyA(
+    _In_ HKEY hKey,
+    _In_ LPCSTR lpSubKey)
 {
-    LONG ErrorCode;
-    UNICODE_STRING SubKeyName;
-
-    RtlCreateUnicodeStringFromAsciiz(&SubKeyName, (LPSTR)lpSubKey);
-
-    ErrorCode = RegDeleteKeyW(hKey, SubKeyName.Buffer);
-
-    RtlFreeUnicodeString(&SubKeyName);
-
-    return ErrorCode;
+    return RegDeleteKeyExA(hKey, lpSubKey, 0, 0);
 }
 
 
@@ -1203,60 +1196,13 @@ RegDeleteKeyA(HKEY hKey,
  *
  * @implemented
  */
-LONG WINAPI
-RegDeleteKeyW(HKEY hKey,
-              LPCWSTR lpSubKey)
+LONG
+WINAPI
+RegDeleteKeyW(
+    _In_ HKEY hKey,
+    _In_ LPCWSTR lpSubKey)
 {
-    OBJECT_ATTRIBUTES ObjectAttributes;
-    UNICODE_STRING SubKeyName;
-    HANDLE ParentKey;
-    HANDLE TargetKey;
-    NTSTATUS Status;
-
-    /* Make sure we got a subkey */
-    if (!lpSubKey)
-    {
-        /* Fail */
-        return ERROR_INVALID_PARAMETER;
-    }
-
-    Status = MapDefaultKey(&ParentKey,
-                           hKey);
-    if (!NT_SUCCESS(Status))
-    {
-        return RtlNtStatusToDosError(Status);
-    }
-
-    if (IsHKCRKey(ParentKey))
-        return DeleteHKCRKey(ParentKey, lpSubKey);
-
-    RtlInitUnicodeString(&SubKeyName,
-                         (LPWSTR)lpSubKey);
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &SubKeyName,
-                               OBJ_CASE_INSENSITIVE,
-                               ParentKey,
-                               NULL);
-    Status = NtOpenKey(&TargetKey,
-                       DELETE,
-                       &ObjectAttributes);
-    if (!NT_SUCCESS(Status))
-    {
-        goto Cleanup;
-    }
-
-    Status = NtDeleteKey(TargetKey);
-    NtClose(TargetKey);
-
-Cleanup:
-    ClosePredefKey(ParentKey);
-
-    if (!NT_SUCCESS(Status))
-    {
-        return RtlNtStatusToDosError(Status);
-    }
-
-    return ERROR_SUCCESS;
+    return RegDeleteKeyExW(hKey, lpSubKey, 0, 0);
 }
 
 
@@ -1267,66 +1213,22 @@ Cleanup:
  */
 LONG
 WINAPI
-RegDeleteKeyExA(HKEY hKey,
-                LPCSTR lpSubKey,
-                REGSAM samDesired,
-                DWORD Reserved)
+RegDeleteKeyExA(
+    _In_ HKEY hKey,
+    _In_ LPCSTR lpSubKey,
+    _In_ REGSAM samDesired,
+    _In_ DWORD Reserved)
 {
-    OBJECT_ATTRIBUTES ObjectAttributes;
+    LONG ErrorCode;
     UNICODE_STRING SubKeyName;
-    HANDLE ParentKey;
-    HANDLE TargetKey;
-    NTSTATUS Status;
-
-    /* Make sure we got a subkey */
-    if (!lpSubKey)
-    {
-        /* Fail */
-        return ERROR_INVALID_PARAMETER;
-    }
-
-    Status = MapDefaultKey(&ParentKey,
-                           hKey);
-    if (!NT_SUCCESS(Status))
-    {
-        return RtlNtStatusToDosError(Status);
-    }
-
-    if (samDesired & KEY_WOW64_32KEY)
-        ERR("Wow64 not yet supported!\n");
 
-    if (samDesired & KEY_WOW64_64KEY)
-        ERR("Wow64 not yet supported!\n");
+    RtlCreateUnicodeStringFromAsciiz(&SubKeyName, (LPSTR)lpSubKey);
 
-    RtlCreateUnicodeStringFromAsciiz(&SubKeyName,
-                                     (LPSTR)lpSubKey);
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &SubKeyName,
-                               OBJ_CASE_INSENSITIVE,
-                               ParentKey,
-                               NULL);
+    ErrorCode = RegDeleteKeyExW(hKey, SubKeyName.Buffer, samDesired, Reserved);
 
-    Status = NtOpenKey(&TargetKey,
-                       DELETE,
-                       &ObjectAttributes);
     RtlFreeUnicodeString(&SubKeyName);
-    if (!NT_SUCCESS(Status))
-    {
-        goto Cleanup;
-    }
-
-    Status = NtDeleteKey(TargetKey);
-    NtClose (TargetKey);
 
-Cleanup:
-    ClosePredefKey(ParentKey);
-
-    if (!NT_SUCCESS(Status))
-    {
-        return RtlNtStatusToDosError(Status);
-    }
-
-    return ERROR_SUCCESS;
+    return ErrorCode;
 }
 
 
@@ -1337,10 +1239,11 @@ Cleanup:
  */
 LONG
 WINAPI
-RegDeleteKeyExW(HKEY hKey,
-                LPCWSTR lpSubKey,
-                REGSAM samDesired,
-                DWORD Reserved)
+RegDeleteKeyExW(
+    _In_ HKEY hKey,
+    _In_ LPCWSTR lpSubKey,
+    _In_ REGSAM samDesired,
+    _In_ DWORD Reserved)
 {
     OBJECT_ATTRIBUTES ObjectAttributes;
     UNICODE_STRING SubKeyName;
@@ -1362,6 +1265,9 @@ RegDeleteKeyExW(HKEY hKey,
         return RtlNtStatusToDosError(Status);
     }
 
+    if (IsHKCRKey(ParentKey))
+        return DeleteHKCRKey(ParentKey, lpSubKey, samDesired, Reserved);
+
     if (samDesired & KEY_WOW64_32KEY)
         ERR("Wow64 not yet supported!\n");
 
index 5d0bc25..25f7243 100644 (file)
@@ -35,5 +35,7 @@ LONG
 WINAPI
 DeleteHKCRKey(
     _In_ HKEY hKey,
-    _In_ LPCWSTR lpSubKey);
+    _In_ LPCWSTR lpSubKey,
+    _In_ REGSAM RegSam,
+    _In_ DWORD Reserved);