/* INCLUDES *****************************************************************/
#include <advapi32.h>
+
+#include <ndk/cmfuncs.h>
#include <pseh/pseh2.h>
+
+#include "reg.h"
+
WINE_DEFAULT_DEBUG_CHANNEL(reg);
/* DEFINES ******************************************************************/
static NTSTATUS
-OpenClassesRootKey(PHANDLE KeyHandle)
+OpenClassesRootKey(_Out_ PHANDLE KeyHandle)
{
OBJECT_ATTRIBUTES Attributes;
UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\CLASSES");
+ NTSTATUS Status;
TRACE("OpenClassesRootKey()\n");
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
- return NtOpenKey(KeyHandle,
- MAXIMUM_ALLOWED,
- &Attributes);
+ Status = NtOpenKey(KeyHandle,
+ MAXIMUM_ALLOWED,
+ &Attributes);
+
+ if (!NT_SUCCESS(Status))
+ return Status;
+
+ /* Mark it as HKCR */
+ MakeHKCRKey((HKEY*)KeyHandle);
+
+ return Status;
}
* @implemented
*/
LONG WINAPI
-RegCreateKeyExA(HKEY hKey,
- LPCSTR lpSubKey,
- DWORD Reserved,
- LPSTR lpClass,
- DWORD dwOptions,
- REGSAM samDesired,
- LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- PHKEY phkResult,
- LPDWORD lpdwDisposition)
+RegCreateKeyExA(
+ _In_ HKEY hKey,
+ _In_ LPCSTR lpSubKey,
+ _In_ DWORD Reserved,
+ _In_ LPSTR lpClass,
+ _In_ DWORD dwOptions,
+ _In_ REGSAM samDesired,
+ _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+ _Out_ PHKEY phkResult,
+ _Out_ LPDWORD lpdwDisposition)
{
UNICODE_STRING SubKeyString;
UNICODE_STRING ClassString;
- OBJECT_ATTRIBUTES ObjectAttributes;
- HANDLE ParentKey;
- ULONG Attributes = OBJ_CASE_INSENSITIVE;
- NTSTATUS Status;
-
- TRACE("RegCreateKeyExA() called\n");
-
- if (lpSecurityAttributes && lpSecurityAttributes->nLength != sizeof(SECURITY_ATTRIBUTES))
- return ERROR_INVALID_USER_BUFFER;
-
- /* get the real parent key */
- Status = MapDefaultKey(&ParentKey,
- hKey);
- if (!NT_SUCCESS(Status))
- {
- return RtlNtStatusToDosError(Status);
- }
-
- TRACE("ParentKey %p\n", ParentKey);
+ DWORD ErrorCode;
- if (lpClass != NULL)
- {
- RtlCreateUnicodeStringFromAsciiz(&ClassString,
- lpClass);
- }
+ RtlCreateUnicodeStringFromAsciiz(&ClassString, lpClass);
+ RtlCreateUnicodeStringFromAsciiz(&SubKeyString, (LPSTR)lpSubKey);
- if (dwOptions & REG_OPTION_OPEN_LINK)
- Attributes |= OBJ_OPENLINK;
+ ErrorCode = RegCreateKeyExW(
+ hKey,
+ SubKeyString.Buffer,
+ Reserved,
+ ClassString.Buffer,
+ dwOptions,
+ samDesired,
+ lpSecurityAttributes,
+ phkResult,
+ lpdwDisposition);
- RtlCreateUnicodeStringFromAsciiz(&SubKeyString,
- (LPSTR)lpSubKey);
- InitializeObjectAttributes(&ObjectAttributes,
- &SubKeyString,
- Attributes,
- (HANDLE)ParentKey,
- lpSecurityAttributes ? (PSECURITY_DESCRIPTOR)lpSecurityAttributes->lpSecurityDescriptor : NULL);
- Status = CreateNestedKey(phkResult,
- &ObjectAttributes,
- (lpClass == NULL)? NULL : &ClassString,
- dwOptions,
- samDesired,
- lpdwDisposition);
RtlFreeUnicodeString(&SubKeyString);
- if (lpClass != NULL)
- {
- RtlFreeUnicodeString(&ClassString);
- }
-
- ClosePredefKey(ParentKey);
+ RtlFreeUnicodeString(&ClassString);
- TRACE("Status %x\n", Status);
- if (!NT_SUCCESS(Status))
- {
- return RtlNtStatusToDosError(Status);
- }
-
- return ERROR_SUCCESS;
+ return ErrorCode;
}
return RtlNtStatusToDosError(Status);
}
-#if 0
Status = NtQuerySecurityObject(KeyHandle,
SecurityInformation,
pSecurityDescriptor,
*lpcbSecurityDescriptor,
lpcbSecurityDescriptor);
-#endif
ClosePredefKey(KeyHandle);
* @implemented
*/
LONG WINAPI
-RegOpenKeyExA(HKEY hKey,
- LPCSTR lpSubKey,
- DWORD ulOptions,
- REGSAM samDesired,
- PHKEY phkResult)
+RegOpenKeyExA(
+ _In_ HKEY hKey,
+ _In_ LPCSTR lpSubKey,
+ _In_ DWORD ulOptions,
+ _In_ REGSAM samDesired,
+ _Out_ PHKEY phkResult)
{
- OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING SubKeyString;
- HANDLE KeyHandle;
- NTSTATUS Status;
- ULONG Attributes = OBJ_CASE_INSENSITIVE;
- LONG ErrorCode = ERROR_SUCCESS;
+ LONG ErrorCode;
TRACE("RegOpenKeyExA hKey 0x%x lpSubKey %s ulOptions 0x%x samDesired 0x%x phkResult %p\n",
hKey, lpSubKey, ulOptions, samDesired, phkResult);
- if (!phkResult)
- {
- return ERROR_INVALID_PARAMETER;
- }
-
- Status = MapDefaultKey(&KeyHandle,
- hKey);
- if (!NT_SUCCESS(Status))
- {
- return RtlNtStatusToDosError(Status);
- }
-
- if (ulOptions & REG_OPTION_OPEN_LINK)
- Attributes |= OBJ_OPENLINK;
RtlCreateUnicodeStringFromAsciiz(&SubKeyString,
(LPSTR)lpSubKey);
- InitializeObjectAttributes(&ObjectAttributes,
- &SubKeyString,
- Attributes,
- KeyHandle,
- NULL);
- Status = NtOpenKey((PHANDLE)phkResult,
- samDesired,
- &ObjectAttributes);
- RtlFreeUnicodeString(&SubKeyString);
- if (!NT_SUCCESS(Status))
- {
- ErrorCode = RtlNtStatusToDosError(Status);
- }
+ ErrorCode = RegOpenKeyExW(hKey, SubKeyString.Buffer, ulOptions, samDesired, phkResult);
- ClosePredefKey(KeyHandle);
+ RtlFreeUnicodeString(&SubKeyString);
return ErrorCode;
}
return RtlNtStatusToDosError(Status);
}
+ if (IsHKCRKey(KeyHandle))
+ return OpenHKCRKey(KeyHandle, lpSubKey, ulOptions, samDesired, phkResult);
+
if (ulOptions & REG_OPTION_OPEN_LINK)
Attributes |= OBJ_OPENLINK;
Status = NtOpenKey((PHANDLE)phkResult,
samDesired,
&ObjectAttributes);
+
if (!NT_SUCCESS(Status))
{
ErrorCode = RtlNtStatusToDosError(Status);
}
+
ClosePredefKey(KeyHandle);
return ErrorCode;
*lpcbMaxValueLen = FullInfo->MaxValueDataLen;
}
-#if 0
if (lpcbSecurityDescriptor != NULL)
{
Status = NtQuerySecurityObject(KeyHandle,
NULL,
0,
lpcbSecurityDescriptor);
- if (!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL)
{
if (lpClass != NULL)
{
goto Cleanup;
}
}
-#endif
if (lpftLastWriteTime != NULL)
{