- Fix a typo in RegGetKeySecurity().
[reactos.git] / reactos / lib / advapi32 / reg / reg.c
index fcd8907..6712214 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: reg.c,v 1.48 2004/07/02 21:20:51 gvg Exp $
+/* $Id: reg.c,v 1.56 2004/09/13 11:41:26 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
 
 /* INCLUDES *****************************************************************/
 
-#define NTOS_MODE_USER
-#include <ntos.h>
-#include <ddk/ntddk.h>
-#include <rosrtl/string.h>
-#include <ntdll/rtl.h>
-#include <windows.h>
-#include <wchar.h>
-
+#include "advapi32.h"
 #define NDEBUG
 #include <debug.h>
 
@@ -27,7 +20,7 @@
 
 #define MAX_DEFAULT_HANDLES   6
 #define REG_MAX_NAME_SIZE     256
-#define REG_MAX_DATA_SIZE     2048     
+#define REG_MAX_DATA_SIZE     2048
 
 /* GLOBALS ******************************************************************/
 
@@ -865,7 +858,7 @@ RegEnumKeyExA (HKEY hKey,
   ANSI_STRING StringA;
   LONG ErrorCode = ERROR_SUCCESS;
   DWORD NameLength;
-  DWORD ClassLength;
+  DWORD ClassLength = 0;
   DWORD BufferSize;
   DWORD ResultSize;
   HANDLE KeyHandle;
@@ -1042,7 +1035,7 @@ RegEnumKeyExW (HKEY hKey,
   ULONG BufferSize;
   ULONG ResultSize;
   ULONG NameLength;
-  ULONG ClassLength;
+  ULONG ClassLength = 0;
   HANDLE KeyHandle;
   LONG ErrorCode = ERROR_SUCCESS;
   NTSTATUS Status;
@@ -1193,7 +1186,7 @@ RegEnumValueA (HKEY hKey,
 
   ULONG NameLength;
   ULONG BufferSize;
-  ULONG DataLength;
+  ULONG DataLength = 0;
   ULONG ResultSize;
   HANDLE KeyHandle;
   LONG ErrorCode;
@@ -1360,7 +1353,7 @@ RegEnumValueW (HKEY hKey,
 
   ULONG NameLength;
   ULONG BufferSize;
-  ULONG DataLength;
+  ULONG DataLength = 0;
   ULONG ResultSize;
   HANDLE KeyHandle;
   LONG ErrorCode;
@@ -1451,6 +1444,7 @@ RegEnumValueW (HKEY hKey,
              *lpcbValueName = (DWORD)(ValueInfo->Basic.NameLength / sizeof(WCHAR));
              lpValueName[*lpcbValueName] = 0;
            }
+          *lpcbData = (DWORD)ValueInfo->Full.DataLength;
        }
 
       if (ErrorCode == ERROR_SUCCESS && lpType != NULL)
@@ -1513,47 +1507,48 @@ RegFlushKey(HKEY hKey)
 /************************************************************************
  *  RegGetKeySecurity
  *
- * @unimplemented
+ * @implemented
  */
 LONG STDCALL
-RegGetKeySecurity (HKEY hKey,
-                  SECURITY_INFORMATION SecurityInformation,
-                  PSECURITY_DESCRIPTOR pSecurityDescriptor,
-                  LPDWORD lpcbSecurityDescriptor)
+RegGetKeySecurity(HKEY hKey,
+                 SECURITY_INFORMATION SecurityInformation,
+                 PSECURITY_DESCRIPTOR pSecurityDescriptor,
+                 LPDWORD lpcbSecurityDescriptor)
 {
-#if 0
-  HKEY KeyHandle;
+  HANDLE KeyHandle;
   LONG ErrorCode;
   NTSTATUS Status;
 
-  if (hKey = HKEY_PERFORMANCE_DATA)
+  if (hKey == HKEY_PERFORMANCE_DATA)
     {
+      SetLastError(ERROR_INVALID_HANDLE);
       return ERROR_INVALID_HANDLE;
     }
 
-  Status = MapDefaultKey (&KeyHandle,
-                         hKey);
+  Status = MapDefaultKey(&KeyHandle,
+                        hKey);
   if (!NT_SUCCESS(Status))
     {
-      ErrorCode = RtlNtStatusToDosError (Status);
-      SetLastError (ErrorCode);
+      DPRINT("MapDefaultKey() failed (Status %lx)\n", Status);
+      ErrorCode = RtlNtStatusToDosError(Status);
+      SetLastError(ErrorCode);
       return ErrorCode;
     }
 
-  Status = NtQuerySecurityObject ()
+  Status = NtQuerySecurityObject(KeyHandle,
+                                SecurityInformation,
+                                pSecurityDescriptor,
+                                *lpcbSecurityDescriptor,
+                                lpcbSecurityDescriptor);
   if (!NT_SUCCESS(Status))
     {
-      ErrorCode = RtlNtStatusToDosError (Status);
-      SetLastError (ErrorCode);
+      DPRINT("NtQuerySecurityObject() failed (Status %lx)\n", Status);
+      ErrorCode = RtlNtStatusToDosError(Status);
+      SetLastError(ErrorCode);
       return ErrorCode;
     }
 
   return ERROR_SUCCESS;
-#endif
-
-  UNIMPLEMENTED;
-  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-  return ERROR_CALL_NOT_IMPLEMENTED;
 }
 
 
@@ -1607,6 +1602,7 @@ RegLoadKeyW (HKEY hKey,
 
   if (hKey == HKEY_PERFORMANCE_DATA)
     {
+      SetLastError(ERROR_INVALID_HANDLE);
       return ERROR_INVALID_HANDLE;
     }
 
@@ -1729,7 +1725,6 @@ RegOpenKeyA (HKEY hKey,
   LONG ErrorCode;
   NTSTATUS Status;
 
-DPRINT1("RegOpenKeyA hKey 0x%x subkey %s\n", hKey, lpSubKey);
   Status = MapDefaultKey (&KeyHandle,
                          hKey);
   if (!NT_SUCCESS(Status))
@@ -1998,7 +1993,7 @@ RegQueryInfoKeyW (HKEY hKey,
   KEY_FULL_INFORMATION FullInfoBuffer;
   PKEY_FULL_INFORMATION FullInfo;
   ULONG FullInfoSize;
-  ULONG ClassLength;
+  ULONG ClassLength = 0;
   HANDLE KeyHandle;
   NTSTATUS Status;
   LONG ErrorCode = ERROR_SUCCESS;
@@ -2249,7 +2244,7 @@ RegQueryValueExW (HKEY hKey,
   ULONG BufferSize;
   ULONG ResultSize;
   HANDLE KeyHandle;
-  ULONG MaxCopy = lpcbData ? *lpcbData : 0;
+  ULONG MaxCopy = lpcbData != NULL && lpData != NULL ? *lpcbData : 0;
 
   DPRINT("hKey 0x%X  lpValueName %S  lpData 0x%X  lpcbData %d\n",
         hKey, lpValueName, lpData, lpcbData ? *lpcbData : 0);
@@ -3000,6 +2995,7 @@ RegSetKeySecurity (HKEY hKey,
 
   if (hKey == HKEY_PERFORMANCE_DATA)
     {
+      SetLastError(ERROR_INVALID_HANDLE);
       return ERROR_INVALID_HANDLE;
     }
 
@@ -3338,7 +3334,10 @@ RegUnLoadKeyW (HKEY hKey,
   NTSTATUS Status;
 
   if (hKey == HKEY_PERFORMANCE_DATA)
-    return ERROR_INVALID_HANDLE;
+    {
+      SetLastError(ERROR_INVALID_HANDLE);
+      return ERROR_INVALID_HANDLE;
+    }
 
   Status = MapDefaultKey (&KeyHandle, hKey);
   if (!NT_SUCCESS(Status))