#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 (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;