From: Sven Baars sbaars@codeweavers.com
--- dlls/kernelbase/registry.c | 101 ++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 40 deletions(-)
diff --git a/dlls/kernelbase/registry.c b/dlls/kernelbase/registry.c index 757ced4f00a..64d6e4a0ae9 100644 --- a/dlls/kernelbase/registry.c +++ b/dlls/kernelbase/registry.c @@ -239,12 +239,61 @@ static NTSTATUS open_key( HKEY *retkey, DWORD options, ACCESS_MASK access, OBJEC return status; }
+static NTSTATUS create_subkey( HKEY *subkey, HKEY root, UNICODE_STRING *name, DWORD options, ACCESS_MASK access, + const UNICODE_STRING *class, PULONG dispos ) +{ + DWORD i = 0, len = name->Length / sizeof(WCHAR); + WCHAR *buffer = name->Buffer; + OBJECT_ATTRIBUTES attr; + UNICODE_STRING str; + NTSTATUS status; + + attr.Length = sizeof(attr); + attr.RootDirectory = (HANDLE)root; + attr.ObjectName = &str; + attr.Attributes = 0; + attr.SecurityDescriptor = NULL; + attr.SecurityQualityOfService = NULL; + + if (i < len && buffer[i] == '\') return STATUS_OBJECT_PATH_INVALID; + while (i < len && buffer[i] != '\') i++; + + str.Buffer = name->Buffer; + str.Length = i * sizeof(WCHAR); + + if (i == len) + { + if (options & REG_OPTION_OPEN_LINK) attr.Attributes |= OBJ_OPENLINK; + } + else + { + options &= ~REG_OPTION_CREATE_LINK; + } + + status = NtCreateKey( (HANDLE *)subkey, access, &attr, 0, class, options, dispos ); + if (status == STATUS_PREDEFINED_HANDLE) + { + *subkey = get_perflib_key( *subkey ); + status = STATUS_SUCCESS; + } + + if (!status) + { + while (i < len && buffer[i] == '\') i++; + + name->Buffer += i; + name->Length -= i * sizeof(WCHAR); + } + + return status; +} + /* wrapper for NtCreateKey that creates the key recursively if necessary */ static NTSTATUS create_key( HKEY *retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr, const UNICODE_STRING *class, ULONG options, PULONG dispos ) { - NTSTATUS status = STATUS_OBJECT_NAME_NOT_FOUND; HKEY subkey, root = attr->RootDirectory, subkey_root = root; + NTSTATUS status = STATUS_OBJECT_NAME_NOT_FOUND; UNICODE_STRING name;
if (!(is_win64 && (access & KEY_WOW64_32KEY))) @@ -261,6 +310,8 @@ static NTSTATUS create_key( HKEY *retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES return status; }
+ *retkey = NULL; + name.Buffer = attr->ObjectName->Buffer; name.Length = attr->ObjectName->Length;
@@ -271,7 +322,6 @@ static NTSTATUS create_key( HKEY *retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES if (subkey_root && subkey_root != root) NtClose( subkey_root ); subkey_root = subkey; } - attr->RootDirectory = subkey_root;
if (!status && (options & REG_OPTION_CREATE_LINK)) { @@ -284,47 +334,18 @@ static NTSTATUS create_key( HKEY *retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES
if (status == STATUS_OBJECT_NAME_NOT_FOUND) { - WCHAR *buffer = name.Buffer; - DWORD attrs, i = 0, len = name.Length / sizeof(WCHAR); - UNICODE_STRING str; - - attrs = attr->Attributes; - attr->ObjectName = &str; - - while (len) + status = STATUS_SUCCESS; + while (!status && name.Length) { - i = 0; - if (buffer[0] == '\') return STATUS_OBJECT_PATH_INVALID; - while (i < len && buffer[i] != '\') i++; - - str.Buffer = buffer; - str.Length = i * sizeof(WCHAR); - - if (i == len) - { - attr->Attributes = attrs; - status = NtCreateKey( (HANDLE *)&subkey, access, attr, 0, class, options, dispos ); - } - else - { - attr->Attributes = attrs & ~OBJ_OPENLINK; - status = NtCreateKey( (HANDLE *)&subkey, access, attr, 0, class, - options & ~REG_OPTION_CREATE_LINK, dispos ); - } - if (attr->RootDirectory != root) NtClose( attr->RootDirectory ); - if (!NT_SUCCESS(status)) return status; - attr->RootDirectory = subkey; - while (i < len && buffer[i] == '\') i++; - buffer += i; - len -= i; + status = create_subkey( &subkey, subkey_root, &name, options, access, class, dispos ); + if (subkey_root && subkey_root != root) NtClose( subkey_root ); + subkey_root = subkey; } } - if (status == STATUS_PREDEFINED_HANDLE) - { - attr->RootDirectory = get_perflib_key( attr->RootDirectory ); - status = STATUS_SUCCESS; - } - *retkey = attr->RootDirectory; + + if (!status) + *retkey = subkey_root; + return status; }