4 * Copyright (C) 1999 Juergen Schmied
5 * Copyright (C) 2000 Alexandre Julliard
6 * Copyright 2005 Ivan Leo Puoti, Laurent Pinchart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * HKEY_LOCAL_MACHINE \\REGISTRY\\MACHINE
24 * HKEY_USERS \\REGISTRY\\USER
25 * HKEY_CURRENT_CONFIG \\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\HARDWARE PROFILES\\CURRENT
26 * HKEY_CLASSES \\REGISTRY\\MACHINE\\SOFTWARE\\CLASSES
30 #include "wine/port.h"
37 #include "wine/library.h"
39 #include "ntdll_misc.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(reg);
45 /* maximum length of a key/value name in bytes (without terminating null) */
46 #define MAX_NAME_LENGTH ((MAX_PATH-1) * sizeof(WCHAR))
48 /******************************************************************************
49 * NtCreateKey [NTDLL.@]
50 * ZwCreateKey [NTDLL.@]
52 NTSTATUS WINAPI NtCreateKey( PHKEY retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
53 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
58 TRACE( "(%p,%s,%s,%lx,%lx,%p)\n", attr->RootDirectory, debugstr_us(attr->ObjectName),
59 debugstr_us(class), options, access, retkey );
61 if (attr->ObjectName->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
62 if (!retkey) return STATUS_INVALID_PARAMETER;
64 SERVER_START_REQ( create_key )
66 req->parent = attr->RootDirectory;
68 req->options = options;
70 req->namelen = attr->ObjectName->Length;
71 wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
72 if (class) wine_server_add_data( req, class->Buffer, class->Length );
73 if (!(ret = wine_server_call( req )))
75 *retkey = reply->hkey;
76 if (dispos) *dispos = reply->created ? REG_CREATED_NEW_KEY : REG_OPENED_EXISTING_KEY;
80 TRACE("<- %p\n", *retkey);
84 /******************************************************************************
85 * RtlpNtCreateKey [NTDLL.@]
89 NTSTATUS WINAPI RtlpNtCreateKey( PHKEY retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr,
90 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
94 attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
96 return NtCreateKey(retkey, access, attr, 0, NULL, 0, dispos);
99 /******************************************************************************
100 * NtOpenKey [NTDLL.@]
101 * ZwOpenKey [NTDLL.@]
103 * OUT PHKEY retkey (returns 0 when failure)
104 * IN ACCESS_MASK access
105 * IN POBJECT_ATTRIBUTES attr
107 NTSTATUS WINAPI NtOpenKey( PHKEY retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
110 DWORD len = attr->ObjectName->Length;
112 TRACE( "(%p,%s,%lx,%p)\n", attr->RootDirectory,
113 debugstr_us(attr->ObjectName), access, retkey );
115 if (len > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
116 if (!retkey) return STATUS_INVALID_PARAMETER;
118 SERVER_START_REQ( open_key )
120 req->parent = attr->RootDirectory;
121 req->access = access;
122 wine_server_add_data( req, attr->ObjectName->Buffer, len );
123 ret = wine_server_call( req );
124 *retkey = reply->hkey;
127 TRACE("<- %p\n", *retkey);
131 /******************************************************************************
132 * RtlpNtOpenKey [NTDLL.@]
136 NTSTATUS WINAPI RtlpNtOpenKey( PHKEY retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr )
139 attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
140 return NtOpenKey(retkey, access, attr);
143 /******************************************************************************
144 * NtDeleteKey [NTDLL.@]
145 * ZwDeleteKey [NTDLL.@]
147 NTSTATUS WINAPI NtDeleteKey( HKEY hkey )
151 TRACE( "(%p)\n", hkey );
153 SERVER_START_REQ( delete_key )
156 ret = wine_server_call( req );
162 /******************************************************************************
163 * RtlpNtMakeTemporaryKey [NTDLL.@]
167 NTSTATUS WINAPI RtlpNtMakeTemporaryKey( HKEY hkey )
169 return NtDeleteKey(hkey);
172 /******************************************************************************
173 * NtDeleteValueKey [NTDLL.@]
174 * ZwDeleteValueKey [NTDLL.@]
176 NTSTATUS WINAPI NtDeleteValueKey( HKEY hkey, const UNICODE_STRING *name )
180 TRACE( "(%p,%s)\n", hkey, debugstr_us(name) );
181 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
183 SERVER_START_REQ( delete_key_value )
186 wine_server_add_data( req, name->Buffer, name->Length );
187 ret = wine_server_call( req );
194 /******************************************************************************
197 * Implementation of NtQueryKey and NtEnumerateKey
199 static NTSTATUS enumerate_key( HKEY handle, int index, KEY_INFORMATION_CLASS info_class,
200 void *info, DWORD length, DWORD *result_len )
209 case KeyBasicInformation: data_ptr = ((KEY_BASIC_INFORMATION *)info)->Name; break;
210 case KeyFullInformation: data_ptr = ((KEY_FULL_INFORMATION *)info)->Class; break;
211 case KeyNodeInformation: data_ptr = ((KEY_NODE_INFORMATION *)info)->Name; break;
213 FIXME( "Information class %d not implemented\n", info_class );
214 return STATUS_INVALID_PARAMETER;
216 fixed_size = (char *)data_ptr - (char *)info;
218 SERVER_START_REQ( enum_key )
222 req->info_class = info_class;
223 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
224 if (!(ret = wine_server_call( req )))
228 RtlSecondsSince1970ToTime( reply->modif, &modif );
232 case KeyBasicInformation:
234 KEY_BASIC_INFORMATION keyinfo;
235 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
236 keyinfo.LastWriteTime = modif;
237 keyinfo.TitleIndex = 0;
238 keyinfo.NameLength = reply->namelen;
239 memcpy( info, &keyinfo, min( length, fixed_size ) );
242 case KeyFullInformation:
244 KEY_FULL_INFORMATION keyinfo;
245 fixed_size = (char *)keyinfo.Class - (char *)&keyinfo;
246 keyinfo.LastWriteTime = modif;
247 keyinfo.TitleIndex = 0;
248 keyinfo.ClassLength = wine_server_reply_size(reply);
249 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size : -1;
250 keyinfo.SubKeys = reply->subkeys;
251 keyinfo.MaxNameLen = reply->max_subkey;
252 keyinfo.MaxClassLen = reply->max_class;
253 keyinfo.Values = reply->values;
254 keyinfo.MaxValueNameLen = reply->max_value;
255 keyinfo.MaxValueDataLen = reply->max_data;
256 memcpy( info, &keyinfo, min( length, fixed_size ) );
259 case KeyNodeInformation:
261 KEY_NODE_INFORMATION keyinfo;
262 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
263 keyinfo.LastWriteTime = modif;
264 keyinfo.TitleIndex = 0;
265 keyinfo.ClassLength = max( 0, wine_server_reply_size(reply) - reply->namelen );
266 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size + reply->namelen : -1;
267 keyinfo.NameLength = reply->namelen;
268 memcpy( info, &keyinfo, min( length, fixed_size ) );
272 *result_len = fixed_size + reply->total;
273 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
282 /******************************************************************************
283 * NtEnumerateKey [NTDLL.@]
284 * ZwEnumerateKey [NTDLL.@]
287 * the name copied into the buffer is NOT 0-terminated
289 NTSTATUS WINAPI NtEnumerateKey( HKEY handle, ULONG index, KEY_INFORMATION_CLASS info_class,
290 void *info, DWORD length, DWORD *result_len )
292 /* -1 means query key, so avoid it here */
293 if (index == (ULONG)-1) return STATUS_NO_MORE_ENTRIES;
294 return enumerate_key( handle, index, info_class, info, length, result_len );
298 /******************************************************************************
299 * RtlpNtEnumerateSubKey [NTDLL.@]
302 NTSTATUS WINAPI RtlpNtEnumerateSubKey( HKEY handle, UNICODE_STRING *out, ULONG index )
304 KEY_BASIC_INFORMATION *info;
305 DWORD dwLen, dwResultLen;
310 dwLen = out->Length + sizeof(KEY_BASIC_INFORMATION);
311 info = (KEY_BASIC_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
313 return STATUS_NO_MEMORY;
321 ret = NtEnumerateKey( handle, index, KeyBasicInformation, info, dwLen, &dwResultLen );
322 dwResultLen -= sizeof(KEY_BASIC_INFORMATION);
324 if (ret == STATUS_BUFFER_OVERFLOW)
325 out->Length = dwResultLen;
328 if (out->Length < info->NameLength)
330 out->Length = dwResultLen;
331 ret = STATUS_BUFFER_OVERFLOW;
335 out->Length = info->NameLength;
336 memcpy(out->Buffer, info->Name, info->NameLength);
341 RtlFreeHeap( GetProcessHeap(), 0, info );
345 /******************************************************************************
346 * NtQueryKey [NTDLL.@]
347 * ZwQueryKey [NTDLL.@]
349 NTSTATUS WINAPI NtQueryKey( HKEY handle, KEY_INFORMATION_CLASS info_class,
350 void *info, DWORD length, DWORD *result_len )
352 return enumerate_key( handle, -1, info_class, info, length, result_len );
356 /* fill the key value info structure for a specific info class */
357 static void copy_key_value_info( KEY_VALUE_INFORMATION_CLASS info_class, void *info,
358 DWORD length, int type, int name_len, int data_len )
362 case KeyValueBasicInformation:
364 KEY_VALUE_BASIC_INFORMATION keyinfo;
365 keyinfo.TitleIndex = 0;
367 keyinfo.NameLength = name_len;
368 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
369 memcpy( info, &keyinfo, length );
372 case KeyValueFullInformation:
374 KEY_VALUE_FULL_INFORMATION keyinfo;
375 keyinfo.TitleIndex = 0;
377 keyinfo.DataOffset = (char *)keyinfo.Name - (char *)&keyinfo + name_len;
378 keyinfo.DataLength = data_len;
379 keyinfo.NameLength = name_len;
380 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
381 memcpy( info, &keyinfo, length );
384 case KeyValuePartialInformation:
386 KEY_VALUE_PARTIAL_INFORMATION keyinfo;
387 keyinfo.TitleIndex = 0;
389 keyinfo.DataLength = data_len;
390 length = min( length, (char *)keyinfo.Data - (char *)&keyinfo );
391 memcpy( info, &keyinfo, length );
400 /******************************************************************************
401 * NtEnumerateValueKey [NTDLL.@]
402 * ZwEnumerateValueKey [NTDLL.@]
404 NTSTATUS WINAPI NtEnumerateValueKey( HKEY handle, ULONG index,
405 KEY_VALUE_INFORMATION_CLASS info_class,
406 void *info, DWORD length, DWORD *result_len )
412 TRACE( "(%p,%lu,%d,%p,%ld)\n", handle, index, info_class, info, length );
414 /* compute the length we want to retrieve */
417 case KeyValueBasicInformation: ptr = ((KEY_VALUE_BASIC_INFORMATION *)info)->Name; break;
418 case KeyValueFullInformation: ptr = ((KEY_VALUE_FULL_INFORMATION *)info)->Name; break;
419 case KeyValuePartialInformation: ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data; break;
421 FIXME( "Information class %d not implemented\n", info_class );
422 return STATUS_INVALID_PARAMETER;
424 fixed_size = (char *)ptr - (char *)info;
426 SERVER_START_REQ( enum_key_value )
430 req->info_class = info_class;
431 if (length > fixed_size) wine_server_set_reply( req, ptr, length - fixed_size );
432 if (!(ret = wine_server_call( req )))
434 copy_key_value_info( info_class, info, length, reply->type, reply->namelen,
435 wine_server_reply_size(reply) - reply->namelen );
436 *result_len = fixed_size + reply->total;
437 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
445 /******************************************************************************
446 * NtQueryValueKey [NTDLL.@]
447 * ZwQueryValueKey [NTDLL.@]
450 * the name in the KeyValueInformation is never set
452 NTSTATUS WINAPI NtQueryValueKey( HKEY handle, const UNICODE_STRING *name,
453 KEY_VALUE_INFORMATION_CLASS info_class,
454 void *info, DWORD length, DWORD *result_len )
458 unsigned int fixed_size = 0;
460 TRACE( "(%p,%s,%d,%p,%ld)\n", handle, debugstr_us(name), info_class, info, length );
462 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
464 /* compute the length we want to retrieve */
467 case KeyValueBasicInformation:
468 fixed_size = (char *)((KEY_VALUE_BASIC_INFORMATION *)info)->Name - (char *)info;
471 case KeyValueFullInformation:
472 data_ptr = (UCHAR *)((KEY_VALUE_FULL_INFORMATION *)info)->Name;
473 fixed_size = (char *)data_ptr - (char *)info;
475 case KeyValuePartialInformation:
476 data_ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data;
477 fixed_size = (char *)data_ptr - (char *)info;
480 FIXME( "Information class %d not implemented\n", info_class );
481 return STATUS_INVALID_PARAMETER;
484 SERVER_START_REQ( get_key_value )
487 wine_server_add_data( req, name->Buffer, name->Length );
488 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
489 if (!(ret = wine_server_call( req )))
491 copy_key_value_info( info_class, info, length, reply->type,
492 0, wine_server_reply_size(reply) );
493 *result_len = fixed_size + reply->total;
494 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
501 /******************************************************************************
502 * RtlpNtQueryValueKey [NTDLL.@]
505 NTSTATUS WINAPI RtlpNtQueryValueKey( HKEY handle, ULONG *result_type, PBYTE dest,
508 KEY_VALUE_PARTIAL_INFORMATION *info;
512 DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + result_len ? *result_len : 0;
514 info = (KEY_VALUE_PARTIAL_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
516 return STATUS_NO_MEMORY;
519 ret = NtQueryValueKey( handle, &name, KeyValuePartialInformation, info, dwLen, &dwResultLen );
521 if (!ret || ret == STATUS_BUFFER_OVERFLOW)
524 *result_len = info->DataLength;
527 *result_type = info->Type;
529 if (ret != STATUS_BUFFER_OVERFLOW)
530 memcpy( dest, info->Data, info->DataLength );
533 RtlFreeHeap( GetProcessHeap(), 0, info );
537 /******************************************************************************
538 * NtFlushKey [NTDLL.@]
539 * ZwFlushKey [NTDLL.@]
541 NTSTATUS WINAPI NtFlushKey(HKEY key)
545 TRACE("key=%p\n", key);
547 SERVER_START_REQ( flush_key )
550 ret = wine_server_call( req );
557 /******************************************************************************
558 * NtLoadKey [NTDLL.@]
559 * ZwLoadKey [NTDLL.@]
561 NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, OBJECT_ATTRIBUTES *file )
567 TRACE("(%p,%p)\n", attr, file);
569 ret = NtCreateFile(&hive, GENERIC_READ, file, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
570 OPEN_EXISTING, 0, NULL, 0);
573 SERVER_START_REQ( load_registry )
575 req->hkey = attr->RootDirectory;
577 wine_server_add_data(req, attr->ObjectName->Buffer, attr->ObjectName->Length);
578 ret = wine_server_call( req );
587 /******************************************************************************
588 * NtNotifyChangeKey [NTDLL.@]
589 * ZwNotifyChangeKey [NTDLL.@]
591 NTSTATUS WINAPI NtNotifyChangeKey(
594 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
595 IN PVOID ApcContext OPTIONAL,
596 OUT PIO_STATUS_BLOCK IoStatusBlock,
597 IN ULONG CompletionFilter,
598 IN BOOLEAN Asynchroneous,
599 OUT PVOID ChangeBuffer,
601 IN BOOLEAN WatchSubtree)
603 FIXME("(%p,%p,%p,%p,%p,0x%08lx, 0x%08x,%p,0x%08lx,0x%08x) stub!\n",
604 KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
605 Asynchroneous, ChangeBuffer, Length, WatchSubtree);
606 return STATUS_SUCCESS;
609 /******************************************************************************
610 * NtQueryMultipleValueKey [NTDLL]
611 * ZwQueryMultipleValueKey
614 NTSTATUS WINAPI NtQueryMultipleValueKey(
616 PVALENTW ListOfValuesToQuery,
618 PVOID MultipleValueInformation,
622 FIXME("(%p,%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
623 KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
624 Length,ReturnLength);
625 return STATUS_SUCCESS;
628 /******************************************************************************
629 * NtReplaceKey [NTDLL.@]
630 * ZwReplaceKey [NTDLL.@]
632 NTSTATUS WINAPI NtReplaceKey(
633 IN POBJECT_ATTRIBUTES ObjectAttributes,
635 IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
637 FIXME("(%p),stub!\n", Key);
638 dump_ObjectAttributes(ObjectAttributes);
639 dump_ObjectAttributes(ReplacedObjectAttributes);
640 return STATUS_SUCCESS;
642 /******************************************************************************
643 * NtRestoreKey [NTDLL.@]
644 * ZwRestoreKey [NTDLL.@]
646 NTSTATUS WINAPI NtRestoreKey(
651 FIXME("(%p,%p,0x%08lx) stub\n",
652 KeyHandle, FileHandle, RestoreFlags);
653 return STATUS_SUCCESS;
655 /******************************************************************************
656 * NtSaveKey [NTDLL.@]
657 * ZwSaveKey [NTDLL.@]
659 NTSTATUS WINAPI NtSaveKey(IN HKEY KeyHandle, IN HANDLE FileHandle)
663 TRACE("(%p,%p)\n", KeyHandle, FileHandle);
665 SERVER_START_REQ( save_registry )
667 req->hkey = KeyHandle;
668 req->file = FileHandle;
669 ret = wine_server_call( req );
675 /******************************************************************************
676 * NtSetInformationKey [NTDLL.@]
677 * ZwSetInformationKey [NTDLL.@]
679 NTSTATUS WINAPI NtSetInformationKey(
681 IN const int KeyInformationClass,
682 IN PVOID KeyInformation,
683 IN ULONG KeyInformationLength)
685 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
686 KeyHandle, KeyInformationClass, KeyInformation, KeyInformationLength);
687 return STATUS_SUCCESS;
691 /******************************************************************************
692 * NtSetValueKey [NTDLL.@]
693 * ZwSetValueKey [NTDLL.@]
696 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
697 * NT does definitely care (aj)
699 NTSTATUS WINAPI NtSetValueKey( HKEY hkey, const UNICODE_STRING *name, ULONG TitleIndex,
700 ULONG type, const void *data, ULONG count )
704 TRACE( "(%p,%s,%ld,%p,%ld)\n", hkey, debugstr_us(name), type, data, count );
706 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
708 SERVER_START_REQ( set_key_value )
712 req->namelen = name->Length;
713 wine_server_add_data( req, name->Buffer, name->Length );
714 wine_server_add_data( req, data, count );
715 ret = wine_server_call( req );
721 /******************************************************************************
722 * RtlpNtSetValueKey [NTDLL.@]
725 NTSTATUS WINAPI RtlpNtSetValueKey( HKEY hkey, ULONG type, const void *data,
731 return NtSetValueKey( hkey, &name, 0, type, data, count );
734 /******************************************************************************
735 * NtUnloadKey [NTDLL.@]
736 * ZwUnloadKey [NTDLL.@]
738 NTSTATUS WINAPI NtUnloadKey(IN HKEY KeyHandle)
742 TRACE("(%p)\n", KeyHandle);
744 SERVER_START_REQ( unload_registry )
746 req->hkey = KeyHandle;
747 ret = wine_server_call(req);
754 /******************************************************************************
755 * RtlFormatCurrentUserKeyPath [NTDLL.@]
757 * NOTE: under NT the user name part of the path is an SID.
759 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
761 static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
762 const char *user = wine_get_user_name();
763 int len = ntdll_umbstowcs( 0, user, strlen(user)+1, NULL, 0 );
765 KeyPath->MaximumLength = sizeof(pathW) + len * sizeof(WCHAR);
766 KeyPath->Length = KeyPath->MaximumLength - sizeof(WCHAR);
767 if (!(KeyPath->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, KeyPath->MaximumLength )))
768 return STATUS_NO_MEMORY;
769 memcpy( KeyPath->Buffer, pathW, sizeof(pathW) );
770 ntdll_umbstowcs( 0, user, strlen(user)+1, KeyPath->Buffer + sizeof(pathW)/sizeof(WCHAR), len );
771 return STATUS_SUCCESS;
774 /******************************************************************************
775 * RtlOpenCurrentUser [NTDLL.@]
777 * if we return just HKEY_CURRENT_USER the advapi tries to find a remote
778 * registry (odd handle) and fails
781 DWORD WINAPI RtlOpenCurrentUser(
782 IN ACCESS_MASK DesiredAccess, /* [in] */
783 OUT PHKEY KeyHandle) /* [out] handle of HKEY_CURRENT_USER */
785 OBJECT_ATTRIBUTES ObjectAttributes;
786 UNICODE_STRING ObjectName;
789 TRACE("(0x%08lx, %p) stub\n",DesiredAccess, KeyHandle);
791 RtlFormatCurrentUserKeyPath(&ObjectName);
792 InitializeObjectAttributes(&ObjectAttributes,&ObjectName,OBJ_CASE_INSENSITIVE,0, NULL);
793 ret = NtCreateKey(KeyHandle, DesiredAccess, &ObjectAttributes, 0, NULL, 0, NULL);
794 RtlFreeUnicodeString(&ObjectName);
799 static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo,
800 PRTL_QUERY_REGISTRY_TABLE pQuery, PVOID pContext, PVOID pEnvironment)
803 UNICODE_STRING src, dst;
808 NTSTATUS status = STATUS_SUCCESS;
815 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
816 return STATUS_INVALID_PARAMETER;
819 status = pQuery->QueryRoutine(pQuery->Name, pQuery->DefaultType, pQuery->DefaultData,
820 pQuery->DefaultLength, pContext, pQuery->EntryContext);
824 len = pInfo->DataLength;
826 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
828 str = (PUNICODE_STRING)pQuery->EntryContext;
833 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
835 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
837 dst.MaximumLength = 0;
838 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
840 dst.MaximumLength = res;
841 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
842 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
843 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
844 dst.Length, pContext, pQuery->EntryContext);
845 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
850 if (str->Buffer == NULL)
851 RtlCreateUnicodeString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
853 RtlAppendUnicodeToString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
857 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
858 return STATUS_INVALID_PARAMETER;
860 if (str->Buffer == NULL)
862 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
863 str->MaximumLength = len;
865 len = min(len, str->MaximumLength);
866 memcpy(str->Buffer, ((CHAR*)pInfo) + pInfo->DataOffset, len);
871 bin = (LONG*)pQuery->EntryContext;
872 if (pInfo->DataLength <= sizeof(ULONG))
873 memcpy(bin, ((CHAR*)pInfo) + pInfo->DataOffset,
877 if (bin[0] <= sizeof(ULONG))
879 memcpy(&bin[1], ((CHAR*)pInfo) + pInfo->DataOffset,
880 min(-bin[0], pInfo->DataLength));
884 len = min(bin[0], pInfo->DataLength);
886 bin[2] = pInfo->Type;
887 memcpy(&bin[3], ((CHAR*)pInfo) + pInfo->DataOffset, len);
895 if((pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND) ||
896 (pInfo->Type != REG_EXPAND_SZ && pInfo->Type != REG_MULTI_SZ))
898 status = pQuery->QueryRoutine(pInfo->Name, pInfo->Type,
899 ((CHAR*)pInfo) + pInfo->DataOffset, pInfo->DataLength,
900 pContext, pQuery->EntryContext);
902 else if (pInfo->Type == REG_EXPAND_SZ)
904 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
906 dst.MaximumLength = 0;
907 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
909 dst.MaximumLength = res;
910 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
911 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
912 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
913 dst.Length, pContext, pQuery->EntryContext);
914 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
916 else /* REG_MULTI_SZ */
918 if(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND)
920 for (offset = 0; offset <= pInfo->DataLength; offset += len + sizeof(WCHAR))
922 wstr = (WCHAR*)(((CHAR*)pInfo) + offset);
923 len = strlenW(wstr) * sizeof(WCHAR);
924 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, wstr, len,
925 pContext, pQuery->EntryContext);
926 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
932 while(count<=pInfo->DataLength)
934 String = (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset)+count;
935 count+=strlenW(String)+1;
936 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
938 dst.MaximumLength = 0;
939 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
941 dst.MaximumLength = res;
942 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
943 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
944 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
945 dst.Length, pContext, pQuery->EntryContext);
946 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
947 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
957 static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHKEY handle)
959 UNICODE_STRING KeyString;
960 OBJECT_ATTRIBUTES regkey;
965 static const WCHAR empty[] = {0};
966 static const WCHAR control[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e',
967 '\\','S','y','s','t','e','m','\\','C','u','r','r','e','n','t',' ','C','o','n','t','r','o','l','S','e','t','\\',
968 'C','o','n','t','r','o','l','\\',0};
970 static const WCHAR devicemap[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
971 'H','a','r','d','w','a','r','e','\\','D','e','v','i','c','e','M','a','p','\\',0};
973 static const WCHAR services[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
974 'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
975 'S','e','r','v','i','c','e','s','\\',0};
977 static const WCHAR user[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\',
978 'C','u','r','r','e','n','t','U','s','e','r','\\',0};
980 static const WCHAR windows_nt[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
981 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
982 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',0};
984 switch (RelativeTo & 0xff)
986 case RTL_REGISTRY_ABSOLUTE:
990 case RTL_REGISTRY_CONTROL:
994 case RTL_REGISTRY_DEVICEMAP:
998 case RTL_REGISTRY_SERVICES:
1002 case RTL_REGISTRY_USER:
1006 case RTL_REGISTRY_WINDOWS_NT:
1011 return STATUS_INVALID_PARAMETER;
1014 len = (strlenW(base) + strlenW(Path) + 1) * sizeof(WCHAR);
1015 KeyString.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
1016 if (KeyString.Buffer == NULL)
1017 return STATUS_NO_MEMORY;
1019 strcpyW(KeyString.Buffer, base);
1020 strcatW(KeyString.Buffer, Path);
1021 KeyString.Length = len - sizeof(WCHAR);
1022 KeyString.MaximumLength = len;
1023 InitializeObjectAttributes(®key, &KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL);
1024 status = NtOpenKey(handle, KEY_ALL_ACCESS, ®key);
1025 RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer);
1029 /*************************************************************************
1030 * RtlQueryRegistryValues [NTDLL.@]
1032 * Query multiple registry values with a signle call.
1035 * RelativeTo [I] Registry path that Path refers to
1036 * Path [I] Path to key
1037 * QueryTable [I] Table of key values to query
1038 * Context [I] Paremeter to pass to the application defined QueryRoutine function
1039 * Environment [I] Optional parameter to use when performing expantion
1042 * STATUS_SUCCESS or an appropriate NTSTATUS error code.
1044 NTSTATUS WINAPI RtlQueryRegistryValues(IN ULONG RelativeTo, IN PCWSTR Path,
1045 IN PRTL_QUERY_REGISTRY_TABLE QueryTable, IN PVOID Context,
1046 IN PVOID Environment OPTIONAL)
1048 UNICODE_STRING Value;
1049 HKEY handle, topkey;
1050 PKEY_VALUE_FULL_INFORMATION pInfo = NULL;
1051 ULONG len, buflen = 0;
1052 NTSTATUS status=STATUS_SUCCESS, ret = STATUS_SUCCESS;
1055 TRACE("(%ld, %s, %p, %p, %p)\n", RelativeTo, debugstr_w(Path), QueryTable, Context, Environment);
1058 return STATUS_INVALID_PARAMETER;
1060 /* get a valid handle */
1061 if (RelativeTo & RTL_REGISTRY_HANDLE)
1062 topkey = handle = (HANDLE)Path;
1065 status = RTL_GetKeyHandle(RelativeTo, Path, &topkey);
1068 if(status != STATUS_SUCCESS)
1071 /* Process query table entries */
1072 for (; QueryTable->QueryRoutine != NULL || QueryTable->Name != NULL; ++QueryTable)
1074 if (QueryTable->Flags &
1075 (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY))
1077 /* topkey must be kept open just in case we will reuse it later */
1078 if (handle != topkey)
1081 if (QueryTable->Flags & RTL_QUERY_REGISTRY_SUBKEY)
1084 status = RTL_GetKeyHandle((ULONG)QueryTable->Name, Path, &handle);
1085 if(status != STATUS_SUCCESS)
1095 if (QueryTable->Flags & RTL_QUERY_REGISTRY_NOVALUE)
1097 QueryTable->QueryRoutine(QueryTable->Name, REG_NONE, NULL, 0,
1098 Context, QueryTable->EntryContext);
1104 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1106 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1112 if (QueryTable->Name == NULL)
1114 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT)
1116 ret = STATUS_INVALID_PARAMETER;
1120 /* Report all subkeys */
1123 status = NtEnumerateValueKey(handle, i,
1124 KeyValueFullInformation, pInfo, buflen, &len);
1125 if (status == STATUS_NO_MORE_ENTRIES)
1127 if (status == STATUS_BUFFER_OVERFLOW ||
1128 status == STATUS_BUFFER_TOO_SMALL)
1131 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1132 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1133 GetProcessHeap(), 0, buflen);
1134 NtEnumerateValueKey(handle, i, KeyValueFullInformation,
1135 pInfo, buflen, &len);
1138 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1139 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1144 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1146 RtlInitUnicodeString(&Value, pInfo->Name);
1147 NtDeleteValueKey(handle, &Value);
1151 if (i == 0 && (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED))
1153 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1159 RtlInitUnicodeString(&Value, QueryTable->Name);
1160 status = NtQueryValueKey(handle, &Value, KeyValueFullInformation,
1161 pInfo, buflen, &len);
1162 if (status == STATUS_BUFFER_OVERFLOW ||
1163 status == STATUS_BUFFER_TOO_SMALL)
1166 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1167 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1168 GetProcessHeap(), 0, buflen);
1169 status = NtQueryValueKey(handle, &Value,
1170 KeyValueFullInformation, pInfo, buflen, &len);
1172 if (status != STATUS_SUCCESS)
1174 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1176 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1179 status = RTL_ReportRegistryValue(NULL, QueryTable, Context, Environment);
1180 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1188 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1189 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1194 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1195 NtDeleteValueKey(handle, &Value);
1201 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1202 if (handle != topkey)
1208 /*************************************************************************
1209 * RtlCheckRegistryKey [NTDLL.@]
1211 * Query multiple registry values with a signle call.
1214 * RelativeTo [I] Registry path that Path refers to
1215 * Path [I] Path to key
1218 * STATUS_SUCCESS if the specified key exists, or an NTSTATUS error code.
1220 NTSTATUS WINAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
1225 TRACE("(%ld, %s)\n", RelativeTo, debugstr_w(Path));
1227 if((!RelativeTo) && Path == NULL)
1228 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1229 if(RelativeTo & RTL_REGISTRY_HANDLE)
1230 return STATUS_SUCCESS;
1232 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1233 if (handle) NtClose(handle);
1234 if (status == STATUS_INVALID_HANDLE) status = STATUS_OBJECT_NAME_NOT_FOUND;
1238 /*************************************************************************
1239 * RtlDeleteRegistryValue [NTDLL.@]
1241 * Query multiple registry values with a signle call.
1244 * RelativeTo [I] Registry path that Path refers to
1245 * Path [I] Path to key
1246 * ValueName [I] Name of the value to delete
1249 * STATUS_SUCCESS if the specified key is successfully deleted, or an NTSTATUS error code.
1251 NTSTATUS WINAPI RtlDeleteRegistryValue(IN ULONG RelativeTo, IN PCWSTR Path, IN PCWSTR ValueName)
1255 UNICODE_STRING Value;
1257 TRACE("(%ld, %s, %s)\n", RelativeTo, debugstr_w(Path), debugstr_w(ValueName));
1259 RtlInitUnicodeString(&Value, ValueName);
1260 if(RelativeTo == RTL_REGISTRY_HANDLE)
1262 return NtDeleteValueKey((HKEY)Path, &Value);
1264 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1265 if (status) return status;
1266 status = NtDeleteValueKey(handle, &Value);