comctl32/treeview: Avoid a NULL pointer dereference.
[wine.git] / dlls / ntdll / reg.c
blob7d24a9b6b4169111ec69446ed729053e36d32420
1 /*
2 * Registry functions
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES:
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
29 #include "config.h"
30 #include "wine/port.h"
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <string.h>
36 #include "ntstatus.h"
37 #define WIN32_NO_STATUS
38 #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( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
53 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
54 PULONG dispos )
56 NTSTATUS ret;
58 if (!retkey || !attr) return STATUS_ACCESS_VIOLATION;
59 if (attr->Length > sizeof(OBJECT_ATTRIBUTES)) return STATUS_INVALID_PARAMETER;
60 if (attr->ObjectName->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
62 TRACE( "(%p,%s,%s,%x,%x,%p)\n", attr->RootDirectory, debugstr_us(attr->ObjectName),
63 debugstr_us(class), options, access, retkey );
65 SERVER_START_REQ( create_key )
67 req->parent = wine_server_obj_handle( attr->RootDirectory );
68 req->access = access;
69 req->attributes = attr->Attributes;
70 req->options = options;
71 req->namelen = attr->ObjectName->Length;
72 wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
73 if (class) wine_server_add_data( req, class->Buffer, class->Length );
74 if (!(ret = wine_server_call( req )))
76 *retkey = wine_server_ptr_handle( reply->hkey );
77 if (dispos) *dispos = reply->created ? REG_CREATED_NEW_KEY : REG_OPENED_EXISTING_KEY;
80 SERVER_END_REQ;
81 TRACE("<- %p\n", *retkey);
82 return ret;
85 /******************************************************************************
86 * RtlpNtCreateKey [NTDLL.@]
88 * See NtCreateKey.
90 NTSTATUS WINAPI RtlpNtCreateKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
91 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
92 PULONG dispos )
94 OBJECT_ATTRIBUTES oa;
96 if (attr)
98 oa = *attr;
99 oa.Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
100 attr = &oa;
103 return NtCreateKey(retkey, access, attr, 0, NULL, 0, dispos);
106 /******************************************************************************
107 * NtOpenKey [NTDLL.@]
108 * ZwOpenKey [NTDLL.@]
110 * OUT HANDLE retkey (returns 0 when failure)
111 * IN ACCESS_MASK access
112 * IN POBJECT_ATTRIBUTES attr
114 NTSTATUS WINAPI NtOpenKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
116 NTSTATUS ret;
117 DWORD len = attr->ObjectName->Length;
119 TRACE( "(%p,%s,%x,%p)\n", attr->RootDirectory,
120 debugstr_us(attr->ObjectName), access, retkey );
122 if (len > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
123 if (!retkey) return STATUS_INVALID_PARAMETER;
125 SERVER_START_REQ( open_key )
127 req->parent = wine_server_obj_handle( attr->RootDirectory );
128 req->access = access;
129 req->attributes = attr->Attributes;
130 wine_server_add_data( req, attr->ObjectName->Buffer, len );
131 ret = wine_server_call( req );
132 *retkey = wine_server_ptr_handle( reply->hkey );
134 SERVER_END_REQ;
135 TRACE("<- %p\n", *retkey);
136 return ret;
139 /******************************************************************************
140 * RtlpNtOpenKey [NTDLL.@]
142 * See NtOpenKey.
144 NTSTATUS WINAPI RtlpNtOpenKey( PHANDLE retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr )
146 if (attr)
147 attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
148 return NtOpenKey(retkey, access, attr);
151 /******************************************************************************
152 * NtDeleteKey [NTDLL.@]
153 * ZwDeleteKey [NTDLL.@]
155 NTSTATUS WINAPI NtDeleteKey( HANDLE hkey )
157 NTSTATUS ret;
159 TRACE( "(%p)\n", hkey );
161 SERVER_START_REQ( delete_key )
163 req->hkey = wine_server_obj_handle( hkey );
164 ret = wine_server_call( req );
166 SERVER_END_REQ;
167 return ret;
170 /******************************************************************************
171 * RtlpNtMakeTemporaryKey [NTDLL.@]
173 * See NtDeleteKey.
175 NTSTATUS WINAPI RtlpNtMakeTemporaryKey( HANDLE hkey )
177 return NtDeleteKey(hkey);
180 /******************************************************************************
181 * NtDeleteValueKey [NTDLL.@]
182 * ZwDeleteValueKey [NTDLL.@]
184 NTSTATUS WINAPI NtDeleteValueKey( HANDLE hkey, const UNICODE_STRING *name )
186 NTSTATUS ret;
188 TRACE( "(%p,%s)\n", hkey, debugstr_us(name) );
189 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
191 SERVER_START_REQ( delete_key_value )
193 req->hkey = wine_server_obj_handle( hkey );
194 wine_server_add_data( req, name->Buffer, name->Length );
195 ret = wine_server_call( req );
197 SERVER_END_REQ;
198 return ret;
202 /******************************************************************************
203 * enumerate_key
205 * Implementation of NtQueryKey and NtEnumerateKey
207 static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS info_class,
208 void *info, DWORD length, DWORD *result_len )
211 NTSTATUS ret;
212 void *data_ptr;
213 size_t fixed_size;
215 switch(info_class)
217 case KeyBasicInformation: data_ptr = ((KEY_BASIC_INFORMATION *)info)->Name; break;
218 case KeyFullInformation: data_ptr = ((KEY_FULL_INFORMATION *)info)->Class; break;
219 case KeyNodeInformation: data_ptr = ((KEY_NODE_INFORMATION *)info)->Name; break;
220 case KeyNameInformation: data_ptr = ((KEY_NAME_INFORMATION *)info)->Name; break;
221 default:
222 FIXME( "Information class %d not implemented\n", info_class );
223 return STATUS_INVALID_PARAMETER;
225 fixed_size = (char *)data_ptr - (char *)info;
227 SERVER_START_REQ( enum_key )
229 req->hkey = wine_server_obj_handle( handle );
230 req->index = index;
231 req->info_class = info_class;
232 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
233 if (!(ret = wine_server_call( req )))
235 switch(info_class)
237 case KeyBasicInformation:
239 KEY_BASIC_INFORMATION keyinfo;
240 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
241 keyinfo.LastWriteTime.QuadPart = reply->modif;
242 keyinfo.TitleIndex = 0;
243 keyinfo.NameLength = reply->namelen;
244 memcpy( info, &keyinfo, min( length, fixed_size ) );
246 break;
247 case KeyFullInformation:
249 KEY_FULL_INFORMATION keyinfo;
250 fixed_size = (char *)keyinfo.Class - (char *)&keyinfo;
251 keyinfo.LastWriteTime.QuadPart = reply->modif;
252 keyinfo.TitleIndex = 0;
253 keyinfo.ClassLength = wine_server_reply_size(reply);
254 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size : -1;
255 keyinfo.SubKeys = reply->subkeys;
256 keyinfo.MaxNameLen = reply->max_subkey;
257 keyinfo.MaxClassLen = reply->max_class;
258 keyinfo.Values = reply->values;
259 keyinfo.MaxValueNameLen = reply->max_value;
260 keyinfo.MaxValueDataLen = reply->max_data;
261 memcpy( info, &keyinfo, min( length, fixed_size ) );
263 break;
264 case KeyNodeInformation:
266 KEY_NODE_INFORMATION keyinfo;
267 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
268 keyinfo.LastWriteTime.QuadPart = reply->modif;
269 keyinfo.TitleIndex = 0;
270 if (reply->namelen < wine_server_reply_size(reply))
272 keyinfo.ClassLength = wine_server_reply_size(reply) - reply->namelen;
273 keyinfo.ClassOffset = fixed_size + reply->namelen;
275 else
277 keyinfo.ClassLength = 0;
278 keyinfo.ClassOffset = -1;
280 keyinfo.NameLength = reply->namelen;
281 memcpy( info, &keyinfo, min( length, fixed_size ) );
283 break;
284 case KeyNameInformation:
286 KEY_NAME_INFORMATION keyinfo;
287 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
288 keyinfo.NameLength = reply->namelen;
289 memcpy( info, &keyinfo, min( length, fixed_size ) );
291 break;
293 *result_len = fixed_size + reply->total;
294 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
297 SERVER_END_REQ;
298 return ret;
303 /******************************************************************************
304 * NtEnumerateKey [NTDLL.@]
305 * ZwEnumerateKey [NTDLL.@]
307 * NOTES
308 * the name copied into the buffer is NOT 0-terminated
310 NTSTATUS WINAPI NtEnumerateKey( HANDLE handle, ULONG index, KEY_INFORMATION_CLASS info_class,
311 void *info, DWORD length, DWORD *result_len )
313 /* -1 means query key, so avoid it here */
314 if (index == (ULONG)-1) return STATUS_NO_MORE_ENTRIES;
315 return enumerate_key( handle, index, info_class, info, length, result_len );
319 /******************************************************************************
320 * RtlpNtEnumerateSubKey [NTDLL.@]
323 NTSTATUS WINAPI RtlpNtEnumerateSubKey( HANDLE handle, UNICODE_STRING *out, ULONG index )
325 KEY_BASIC_INFORMATION *info;
326 DWORD dwLen, dwResultLen;
327 NTSTATUS ret;
329 if (out->Length)
331 dwLen = out->Length + sizeof(KEY_BASIC_INFORMATION);
332 info = RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
333 if (!info)
334 return STATUS_NO_MEMORY;
336 else
338 dwLen = 0;
339 info = NULL;
342 ret = NtEnumerateKey( handle, index, KeyBasicInformation, info, dwLen, &dwResultLen );
343 dwResultLen -= sizeof(KEY_BASIC_INFORMATION);
345 if (ret == STATUS_BUFFER_OVERFLOW)
346 out->Length = dwResultLen;
347 else if (!ret)
349 if (out->Length < info->NameLength)
351 out->Length = dwResultLen;
352 ret = STATUS_BUFFER_OVERFLOW;
354 else
356 out->Length = info->NameLength;
357 memcpy(out->Buffer, info->Name, info->NameLength);
361 RtlFreeHeap( GetProcessHeap(), 0, info );
362 return ret;
365 /******************************************************************************
366 * NtQueryKey [NTDLL.@]
367 * ZwQueryKey [NTDLL.@]
369 NTSTATUS WINAPI NtQueryKey( HANDLE handle, KEY_INFORMATION_CLASS info_class,
370 void *info, DWORD length, DWORD *result_len )
372 return enumerate_key( handle, -1, info_class, info, length, result_len );
376 /* fill the key value info structure for a specific info class */
377 static void copy_key_value_info( KEY_VALUE_INFORMATION_CLASS info_class, void *info,
378 DWORD length, int type, int name_len, int data_len )
380 switch(info_class)
382 case KeyValueBasicInformation:
384 KEY_VALUE_BASIC_INFORMATION keyinfo;
385 keyinfo.TitleIndex = 0;
386 keyinfo.Type = type;
387 keyinfo.NameLength = name_len;
388 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
389 memcpy( info, &keyinfo, length );
390 break;
392 case KeyValueFullInformation:
394 KEY_VALUE_FULL_INFORMATION keyinfo;
395 keyinfo.TitleIndex = 0;
396 keyinfo.Type = type;
397 keyinfo.DataOffset = (char *)keyinfo.Name - (char *)&keyinfo + name_len;
398 keyinfo.DataLength = data_len;
399 keyinfo.NameLength = name_len;
400 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
401 memcpy( info, &keyinfo, length );
402 break;
404 case KeyValuePartialInformation:
406 KEY_VALUE_PARTIAL_INFORMATION keyinfo;
407 keyinfo.TitleIndex = 0;
408 keyinfo.Type = type;
409 keyinfo.DataLength = data_len;
410 length = min( length, (char *)keyinfo.Data - (char *)&keyinfo );
411 memcpy( info, &keyinfo, length );
412 break;
414 default:
415 break;
420 /******************************************************************************
421 * NtEnumerateValueKey [NTDLL.@]
422 * ZwEnumerateValueKey [NTDLL.@]
424 NTSTATUS WINAPI NtEnumerateValueKey( HANDLE handle, ULONG index,
425 KEY_VALUE_INFORMATION_CLASS info_class,
426 void *info, DWORD length, DWORD *result_len )
428 NTSTATUS ret;
429 void *ptr;
430 size_t fixed_size;
432 TRACE( "(%p,%u,%d,%p,%d)\n", handle, index, info_class, info, length );
434 /* compute the length we want to retrieve */
435 switch(info_class)
437 case KeyValueBasicInformation: ptr = ((KEY_VALUE_BASIC_INFORMATION *)info)->Name; break;
438 case KeyValueFullInformation: ptr = ((KEY_VALUE_FULL_INFORMATION *)info)->Name; break;
439 case KeyValuePartialInformation: ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data; break;
440 default:
441 FIXME( "Information class %d not implemented\n", info_class );
442 return STATUS_INVALID_PARAMETER;
444 fixed_size = (char *)ptr - (char *)info;
446 SERVER_START_REQ( enum_key_value )
448 req->hkey = wine_server_obj_handle( handle );
449 req->index = index;
450 req->info_class = info_class;
451 if (length > fixed_size) wine_server_set_reply( req, ptr, length - fixed_size );
452 if (!(ret = wine_server_call( req )))
454 copy_key_value_info( info_class, info, length, reply->type, reply->namelen,
455 wine_server_reply_size(reply) - reply->namelen );
456 *result_len = fixed_size + reply->total;
457 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
460 SERVER_END_REQ;
461 return ret;
465 /******************************************************************************
466 * NtQueryValueKey [NTDLL.@]
467 * ZwQueryValueKey [NTDLL.@]
469 * NOTES
470 * the name in the KeyValueInformation is never set
472 NTSTATUS WINAPI NtQueryValueKey( HANDLE handle, const UNICODE_STRING *name,
473 KEY_VALUE_INFORMATION_CLASS info_class,
474 void *info, DWORD length, DWORD *result_len )
476 NTSTATUS ret;
477 UCHAR *data_ptr;
478 unsigned int fixed_size = 0;
480 TRACE( "(%p,%s,%d,%p,%d)\n", handle, debugstr_us(name), info_class, info, length );
482 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
484 /* compute the length we want to retrieve */
485 switch(info_class)
487 case KeyValueBasicInformation:
489 KEY_VALUE_BASIC_INFORMATION *basic_info = info;
490 if (FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) < length)
492 memcpy(basic_info->Name, name->Buffer,
493 min(length - FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name), name->Length));
495 fixed_size = FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) + name->Length;
496 data_ptr = NULL;
497 break;
499 case KeyValueFullInformation:
501 KEY_VALUE_FULL_INFORMATION *full_info = info;
502 if (FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name) < length)
504 memcpy(full_info->Name, name->Buffer,
505 min(length - FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name), name->Length));
507 data_ptr = (UCHAR *)full_info->Name + name->Length;
508 fixed_size = (char *)data_ptr - (char *)info;
509 break;
511 case KeyValuePartialInformation:
512 data_ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data;
513 fixed_size = (char *)data_ptr - (char *)info;
514 break;
515 default:
516 FIXME( "Information class %d not implemented\n", info_class );
517 return STATUS_INVALID_PARAMETER;
520 SERVER_START_REQ( get_key_value )
522 req->hkey = wine_server_obj_handle( handle );
523 wine_server_add_data( req, name->Buffer, name->Length );
524 if (length > fixed_size && data_ptr) wine_server_set_reply( req, data_ptr, length - fixed_size );
525 if (!(ret = wine_server_call( req )))
527 copy_key_value_info( info_class, info, length, reply->type,
528 name->Length, reply->total );
529 *result_len = fixed_size + (info_class == KeyValueBasicInformation ? 0 : reply->total);
530 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
533 SERVER_END_REQ;
534 return ret;
537 /******************************************************************************
538 * RtlpNtQueryValueKey [NTDLL.@]
541 NTSTATUS WINAPI RtlpNtQueryValueKey( HANDLE handle, ULONG *result_type, PBYTE dest,
542 DWORD *result_len, void *unknown )
544 KEY_VALUE_PARTIAL_INFORMATION *info;
545 UNICODE_STRING name;
546 NTSTATUS ret;
547 DWORD dwResultLen;
548 DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + (result_len ? *result_len : 0);
550 info = RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
551 if (!info)
552 return STATUS_NO_MEMORY;
554 name.Length = 0;
555 ret = NtQueryValueKey( handle, &name, KeyValuePartialInformation, info, dwLen, &dwResultLen );
557 if (!ret || ret == STATUS_BUFFER_OVERFLOW)
559 if (result_len)
560 *result_len = info->DataLength;
562 if (result_type)
563 *result_type = info->Type;
565 if (ret != STATUS_BUFFER_OVERFLOW)
566 memcpy( dest, info->Data, info->DataLength );
569 RtlFreeHeap( GetProcessHeap(), 0, info );
570 return ret;
573 /******************************************************************************
574 * NtFlushKey [NTDLL.@]
575 * ZwFlushKey [NTDLL.@]
577 NTSTATUS WINAPI NtFlushKey(HANDLE key)
579 NTSTATUS ret;
581 TRACE("key=%p\n", key);
583 SERVER_START_REQ( flush_key )
585 req->hkey = wine_server_obj_handle( key );
586 ret = wine_server_call( req );
588 SERVER_END_REQ;
590 return ret;
593 /******************************************************************************
594 * NtLoadKey [NTDLL.@]
595 * ZwLoadKey [NTDLL.@]
597 NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, OBJECT_ATTRIBUTES *file )
599 NTSTATUS ret;
600 HANDLE hive;
601 IO_STATUS_BLOCK io;
603 TRACE("(%p,%p)\n", attr, file);
605 ret = NtCreateFile(&hive, GENERIC_READ, file, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
606 FILE_OPEN, 0, NULL, 0);
607 if (ret) return ret;
609 SERVER_START_REQ( load_registry )
611 req->hkey = wine_server_obj_handle( attr->RootDirectory );
612 req->file = wine_server_obj_handle( hive );
613 wine_server_add_data(req, attr->ObjectName->Buffer, attr->ObjectName->Length);
614 ret = wine_server_call( req );
616 SERVER_END_REQ;
618 NtClose(hive);
620 return ret;
623 /******************************************************************************
624 * NtNotifyChangeKey [NTDLL.@]
625 * ZwNotifyChangeKey [NTDLL.@]
627 NTSTATUS WINAPI NtNotifyChangeKey(
628 IN HANDLE KeyHandle,
629 IN HANDLE Event,
630 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
631 IN PVOID ApcContext OPTIONAL,
632 OUT PIO_STATUS_BLOCK IoStatusBlock,
633 IN ULONG CompletionFilter,
634 IN BOOLEAN Asynchronous,
635 OUT PVOID ChangeBuffer,
636 IN ULONG Length,
637 IN BOOLEAN WatchSubtree)
639 NTSTATUS ret;
641 TRACE("(%p,%p,%p,%p,%p,0x%08x, 0x%08x,%p,0x%08x,0x%08x)\n",
642 KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
643 Asynchronous, ChangeBuffer, Length, WatchSubtree);
645 if (ApcRoutine || ApcContext || ChangeBuffer || Length)
646 FIXME("Unimplemented optional parameter\n");
648 if (!Asynchronous)
650 OBJECT_ATTRIBUTES attr;
651 InitializeObjectAttributes( &attr, NULL, 0, NULL, NULL );
652 ret = NtCreateEvent( &Event, EVENT_ALL_ACCESS, &attr, FALSE, FALSE );
653 if (ret != STATUS_SUCCESS)
654 return ret;
657 SERVER_START_REQ( set_registry_notification )
659 req->hkey = wine_server_obj_handle( KeyHandle );
660 req->event = wine_server_obj_handle( Event );
661 req->subtree = WatchSubtree;
662 req->filter = CompletionFilter;
663 ret = wine_server_call( req );
665 SERVER_END_REQ;
667 if (!Asynchronous)
669 if (ret == STATUS_SUCCESS)
670 NtWaitForSingleObject( Event, FALSE, NULL );
671 NtClose( Event );
674 return STATUS_SUCCESS;
677 /******************************************************************************
678 * NtQueryMultipleValueKey [NTDLL]
679 * ZwQueryMultipleValueKey
682 NTSTATUS WINAPI NtQueryMultipleValueKey(
683 HANDLE KeyHandle,
684 PKEY_MULTIPLE_VALUE_INFORMATION ListOfValuesToQuery,
685 ULONG NumberOfItems,
686 PVOID MultipleValueInformation,
687 ULONG Length,
688 PULONG ReturnLength)
690 FIXME("(%p,%p,0x%08x,%p,0x%08x,%p) stub!\n",
691 KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
692 Length,ReturnLength);
693 return STATUS_SUCCESS;
696 /******************************************************************************
697 * NtReplaceKey [NTDLL.@]
698 * ZwReplaceKey [NTDLL.@]
700 NTSTATUS WINAPI NtReplaceKey(
701 IN POBJECT_ATTRIBUTES ObjectAttributes,
702 IN HANDLE Key,
703 IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
705 FIXME("(%s,%p,%s),stub!\n", debugstr_ObjectAttributes(ObjectAttributes), Key,
706 debugstr_ObjectAttributes(ReplacedObjectAttributes) );
707 return STATUS_SUCCESS;
709 /******************************************************************************
710 * NtRestoreKey [NTDLL.@]
711 * ZwRestoreKey [NTDLL.@]
713 NTSTATUS WINAPI NtRestoreKey(
714 HANDLE KeyHandle,
715 HANDLE FileHandle,
716 ULONG RestoreFlags)
718 FIXME("(%p,%p,0x%08x) stub\n",
719 KeyHandle, FileHandle, RestoreFlags);
720 return STATUS_SUCCESS;
722 /******************************************************************************
723 * NtSaveKey [NTDLL.@]
724 * ZwSaveKey [NTDLL.@]
726 NTSTATUS WINAPI NtSaveKey(IN HANDLE KeyHandle, IN HANDLE FileHandle)
728 NTSTATUS ret;
730 TRACE("(%p,%p)\n", KeyHandle, FileHandle);
732 SERVER_START_REQ( save_registry )
734 req->hkey = wine_server_obj_handle( KeyHandle );
735 req->file = wine_server_obj_handle( FileHandle );
736 ret = wine_server_call( req );
738 SERVER_END_REQ;
740 return ret;
742 /******************************************************************************
743 * NtSetInformationKey [NTDLL.@]
744 * ZwSetInformationKey [NTDLL.@]
746 NTSTATUS WINAPI NtSetInformationKey(
747 IN HANDLE KeyHandle,
748 IN const int KeyInformationClass,
749 IN PVOID KeyInformation,
750 IN ULONG KeyInformationLength)
752 FIXME("(%p,0x%08x,%p,0x%08x) stub\n",
753 KeyHandle, KeyInformationClass, KeyInformation, KeyInformationLength);
754 return STATUS_SUCCESS;
758 /******************************************************************************
759 * NtSetValueKey [NTDLL.@]
760 * ZwSetValueKey [NTDLL.@]
762 * NOTES
763 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
764 * NT does definitely care (aj)
766 NTSTATUS WINAPI NtSetValueKey( HANDLE hkey, const UNICODE_STRING *name, ULONG TitleIndex,
767 ULONG type, const void *data, ULONG count )
769 NTSTATUS ret;
771 TRACE( "(%p,%s,%d,%p,%d)\n", hkey, debugstr_us(name), type, data, count );
773 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
775 SERVER_START_REQ( set_key_value )
777 req->hkey = wine_server_obj_handle( hkey );
778 req->type = type;
779 req->namelen = name->Length;
780 wine_server_add_data( req, name->Buffer, name->Length );
781 wine_server_add_data( req, data, count );
782 ret = wine_server_call( req );
784 SERVER_END_REQ;
785 return ret;
788 /******************************************************************************
789 * RtlpNtSetValueKey [NTDLL.@]
792 NTSTATUS WINAPI RtlpNtSetValueKey( HANDLE hkey, ULONG type, const void *data,
793 ULONG count )
795 UNICODE_STRING name;
797 name.Length = 0;
798 return NtSetValueKey( hkey, &name, 0, type, data, count );
801 /******************************************************************************
802 * NtUnloadKey [NTDLL.@]
803 * ZwUnloadKey [NTDLL.@]
805 NTSTATUS WINAPI NtUnloadKey(IN POBJECT_ATTRIBUTES attr)
807 NTSTATUS ret;
809 TRACE("(%p)\n", attr);
811 SERVER_START_REQ( unload_registry )
813 req->hkey = wine_server_obj_handle( attr->RootDirectory );
814 ret = wine_server_call(req);
816 SERVER_END_REQ;
818 return ret;
821 /******************************************************************************
822 * RtlFormatCurrentUserKeyPath [NTDLL.@]
825 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
827 static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
828 HANDLE token;
829 NTSTATUS status;
831 status = NtOpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token);
832 if (status == STATUS_NO_TOKEN)
833 status = NtOpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token);
834 if (status == STATUS_SUCCESS)
836 char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
837 DWORD len = sizeof(buffer);
839 status = NtQueryInformationToken(token, TokenUser, buffer, len, &len);
840 if (status == STATUS_SUCCESS)
842 KeyPath->MaximumLength = 0;
843 status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
844 if (status == STATUS_BUFFER_OVERFLOW)
846 PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
847 sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
848 if (buf)
850 memcpy(buf, pathW, sizeof(pathW));
851 KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
852 KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
853 status = RtlConvertSidToUnicodeString(KeyPath,
854 ((TOKEN_USER *)buffer)->User.Sid, FALSE);
855 KeyPath->Buffer = buf;
856 KeyPath->Length += sizeof(pathW);
857 KeyPath->MaximumLength += sizeof(pathW);
859 else
860 status = STATUS_NO_MEMORY;
863 NtClose(token);
865 return status;
868 /******************************************************************************
869 * RtlOpenCurrentUser [NTDLL.@]
871 * NOTES
872 * If we return just HKEY_CURRENT_USER the advapi tries to find a remote
873 * registry (odd handle) and fails.
875 NTSTATUS WINAPI RtlOpenCurrentUser(
876 IN ACCESS_MASK DesiredAccess, /* [in] */
877 OUT PHANDLE KeyHandle) /* [out] handle of HKEY_CURRENT_USER */
879 OBJECT_ATTRIBUTES ObjectAttributes;
880 UNICODE_STRING ObjectName;
881 NTSTATUS ret;
883 TRACE("(0x%08x, %p)\n",DesiredAccess, KeyHandle);
885 if ((ret = RtlFormatCurrentUserKeyPath(&ObjectName))) return ret;
886 InitializeObjectAttributes(&ObjectAttributes,&ObjectName,OBJ_CASE_INSENSITIVE,0, NULL);
887 ret = NtCreateKey(KeyHandle, DesiredAccess, &ObjectAttributes, 0, NULL, 0, NULL);
888 RtlFreeUnicodeString(&ObjectName);
889 return ret;
893 static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo,
894 PRTL_QUERY_REGISTRY_TABLE pQuery, PVOID pContext, PVOID pEnvironment)
896 PUNICODE_STRING str;
897 UNICODE_STRING src, dst;
898 LONG *bin;
899 ULONG offset;
900 PWSTR wstr;
901 DWORD res;
902 NTSTATUS status = STATUS_SUCCESS;
903 ULONG len;
904 LPWSTR String;
905 ULONG count = 0;
907 if (pInfo == NULL)
909 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
910 return STATUS_INVALID_PARAMETER;
911 else
913 status = pQuery->QueryRoutine(pQuery->Name, pQuery->DefaultType, pQuery->DefaultData,
914 pQuery->DefaultLength, pContext, pQuery->EntryContext);
916 return status;
918 len = pInfo->DataLength;
920 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
922 str = pQuery->EntryContext;
924 switch(pInfo->Type)
926 case REG_EXPAND_SZ:
927 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
929 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
930 res = 0;
931 dst.MaximumLength = 0;
932 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
933 dst.Length = 0;
934 dst.MaximumLength = res;
935 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
936 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
937 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
938 dst.Length, pContext, pQuery->EntryContext);
939 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
942 case REG_SZ:
943 case REG_LINK:
944 if (str->Buffer == NULL)
945 RtlCreateUnicodeString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
946 else
947 RtlAppendUnicodeToString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
948 break;
950 case REG_MULTI_SZ:
951 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
952 return STATUS_INVALID_PARAMETER;
954 if (str->Buffer == NULL)
956 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
957 str->MaximumLength = len;
959 len = min(len, str->MaximumLength);
960 memcpy(str->Buffer, ((CHAR*)pInfo) + pInfo->DataOffset, len);
961 str->Length = len;
962 break;
964 default:
965 bin = pQuery->EntryContext;
966 if (pInfo->DataLength <= sizeof(ULONG))
967 memcpy(bin, ((CHAR*)pInfo) + pInfo->DataOffset,
968 pInfo->DataLength);
969 else
971 if (bin[0] <= sizeof(ULONG))
973 memcpy(&bin[1], ((CHAR*)pInfo) + pInfo->DataOffset,
974 min(-bin[0], pInfo->DataLength));
976 else
978 len = min(bin[0], pInfo->DataLength);
979 bin[1] = len;
980 bin[2] = pInfo->Type;
981 memcpy(&bin[3], ((CHAR*)pInfo) + pInfo->DataOffset, len);
984 break;
987 else
989 if((pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND) ||
990 (pInfo->Type != REG_EXPAND_SZ && pInfo->Type != REG_MULTI_SZ))
992 status = pQuery->QueryRoutine(pInfo->Name, pInfo->Type,
993 ((CHAR*)pInfo) + pInfo->DataOffset, pInfo->DataLength,
994 pContext, pQuery->EntryContext);
996 else if (pInfo->Type == REG_EXPAND_SZ)
998 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
999 res = 0;
1000 dst.MaximumLength = 0;
1001 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1002 dst.Length = 0;
1003 dst.MaximumLength = res;
1004 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
1005 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1006 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
1007 dst.Length, pContext, pQuery->EntryContext);
1008 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
1010 else /* REG_MULTI_SZ */
1012 if(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND)
1014 for (offset = 0; offset <= pInfo->DataLength; offset += len + sizeof(WCHAR))
1016 wstr = (WCHAR*)(((CHAR*)pInfo) + offset);
1017 len = strlenW(wstr) * sizeof(WCHAR);
1018 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, wstr, len,
1019 pContext, pQuery->EntryContext);
1020 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1021 return status;
1024 else
1026 while(count<=pInfo->DataLength)
1028 String = (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset)+count;
1029 count+=strlenW(String)+1;
1030 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
1031 res = 0;
1032 dst.MaximumLength = 0;
1033 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1034 dst.Length = 0;
1035 dst.MaximumLength = res;
1036 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
1037 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1038 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
1039 dst.Length, pContext, pQuery->EntryContext);
1040 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
1041 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1042 return status;
1047 return status;
1051 static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHANDLE handle)
1053 UNICODE_STRING KeyString;
1054 OBJECT_ATTRIBUTES regkey;
1055 PCWSTR base;
1056 INT len;
1057 NTSTATUS status;
1059 static const WCHAR empty[] = {0};
1060 static const WCHAR control[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e',
1061 '\\','S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1062 'C','o','n','t','r','o','l','\\',0};
1064 static const WCHAR devicemap[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1065 'H','a','r','d','w','a','r','e','\\','D','e','v','i','c','e','M','a','p','\\',0};
1067 static const WCHAR services[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1068 'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1069 'S','e','r','v','i','c','e','s','\\',0};
1071 static const WCHAR user[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\',
1072 'C','u','r','r','e','n','t','U','s','e','r','\\',0};
1074 static const WCHAR windows_nt[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1075 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1076 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',0};
1078 switch (RelativeTo & 0xff)
1080 case RTL_REGISTRY_ABSOLUTE:
1081 base = empty;
1082 break;
1084 case RTL_REGISTRY_CONTROL:
1085 base = control;
1086 break;
1088 case RTL_REGISTRY_DEVICEMAP:
1089 base = devicemap;
1090 break;
1092 case RTL_REGISTRY_SERVICES:
1093 base = services;
1094 break;
1096 case RTL_REGISTRY_USER:
1097 base = user;
1098 break;
1100 case RTL_REGISTRY_WINDOWS_NT:
1101 base = windows_nt;
1102 break;
1104 default:
1105 return STATUS_INVALID_PARAMETER;
1108 len = (strlenW(base) + strlenW(Path) + 1) * sizeof(WCHAR);
1109 KeyString.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
1110 if (KeyString.Buffer == NULL)
1111 return STATUS_NO_MEMORY;
1113 strcpyW(KeyString.Buffer, base);
1114 strcatW(KeyString.Buffer, Path);
1115 KeyString.Length = len - sizeof(WCHAR);
1116 KeyString.MaximumLength = len;
1117 InitializeObjectAttributes(&regkey, &KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL);
1118 status = NtOpenKey(handle, KEY_ALL_ACCESS, &regkey);
1119 RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer);
1120 return status;
1123 /*************************************************************************
1124 * RtlQueryRegistryValues [NTDLL.@]
1126 * Query multiple registry values with a signle call.
1128 * PARAMS
1129 * RelativeTo [I] Registry path that Path refers to
1130 * Path [I] Path to key
1131 * QueryTable [I] Table of key values to query
1132 * Context [I] Parameter to pass to the application defined QueryRoutine function
1133 * Environment [I] Optional parameter to use when performing expansion
1135 * RETURNS
1136 * STATUS_SUCCESS or an appropriate NTSTATUS error code.
1138 NTSTATUS WINAPI RtlQueryRegistryValues(IN ULONG RelativeTo, IN PCWSTR Path,
1139 IN PRTL_QUERY_REGISTRY_TABLE QueryTable, IN PVOID Context,
1140 IN PVOID Environment OPTIONAL)
1142 UNICODE_STRING Value;
1143 HANDLE handle, topkey;
1144 PKEY_VALUE_FULL_INFORMATION pInfo = NULL;
1145 ULONG len, buflen = 0;
1146 NTSTATUS status=STATUS_SUCCESS, ret = STATUS_SUCCESS;
1147 INT i;
1149 TRACE("(%d, %s, %p, %p, %p)\n", RelativeTo, debugstr_w(Path), QueryTable, Context, Environment);
1151 if(Path == NULL)
1152 return STATUS_INVALID_PARAMETER;
1154 /* get a valid handle */
1155 if (RelativeTo & RTL_REGISTRY_HANDLE)
1156 topkey = handle = (HANDLE)Path;
1157 else
1159 status = RTL_GetKeyHandle(RelativeTo, Path, &topkey);
1160 handle = topkey;
1162 if(status != STATUS_SUCCESS)
1163 return status;
1165 /* Process query table entries */
1166 for (; QueryTable->QueryRoutine != NULL || QueryTable->Name != NULL; ++QueryTable)
1168 if (QueryTable->Flags &
1169 (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY))
1171 /* topkey must be kept open just in case we will reuse it later */
1172 if (handle != topkey)
1173 NtClose(handle);
1175 if (QueryTable->Flags & RTL_QUERY_REGISTRY_SUBKEY)
1177 handle = 0;
1178 status = RTL_GetKeyHandle(PtrToUlong(QueryTable->Name), Path, &handle);
1179 if(status != STATUS_SUCCESS)
1181 ret = status;
1182 goto out;
1185 else
1186 handle = topkey;
1189 if (QueryTable->Flags & RTL_QUERY_REGISTRY_NOVALUE)
1191 QueryTable->QueryRoutine(QueryTable->Name, REG_NONE, NULL, 0,
1192 Context, QueryTable->EntryContext);
1193 continue;
1196 if (!handle)
1198 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1200 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1201 goto out;
1203 continue;
1206 if (QueryTable->Name == NULL)
1208 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT)
1210 ret = STATUS_INVALID_PARAMETER;
1211 goto out;
1214 /* Report all subkeys */
1215 for (i = 0;; ++i)
1217 status = NtEnumerateValueKey(handle, i,
1218 KeyValueFullInformation, pInfo, buflen, &len);
1219 if (status == STATUS_NO_MORE_ENTRIES)
1220 break;
1221 if (status == STATUS_BUFFER_OVERFLOW ||
1222 status == STATUS_BUFFER_TOO_SMALL)
1224 buflen = len;
1225 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1226 pInfo = RtlAllocateHeap(GetProcessHeap(), 0, buflen);
1227 NtEnumerateValueKey(handle, i, KeyValueFullInformation,
1228 pInfo, buflen, &len);
1231 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1232 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1234 ret = status;
1235 goto out;
1237 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1239 RtlInitUnicodeString(&Value, pInfo->Name);
1240 NtDeleteValueKey(handle, &Value);
1244 if (i == 0 && (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED))
1246 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1247 goto out;
1250 else
1252 RtlInitUnicodeString(&Value, QueryTable->Name);
1253 status = NtQueryValueKey(handle, &Value, KeyValueFullInformation,
1254 pInfo, buflen, &len);
1255 if (status == STATUS_BUFFER_OVERFLOW ||
1256 status == STATUS_BUFFER_TOO_SMALL)
1258 buflen = len;
1259 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1260 pInfo = RtlAllocateHeap(GetProcessHeap(), 0, buflen);
1261 status = NtQueryValueKey(handle, &Value,
1262 KeyValueFullInformation, pInfo, buflen, &len);
1264 if (status != STATUS_SUCCESS)
1266 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1268 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1269 goto out;
1271 status = RTL_ReportRegistryValue(NULL, QueryTable, Context, Environment);
1272 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1274 ret = status;
1275 goto out;
1278 else
1280 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1281 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1283 ret = status;
1284 goto out;
1286 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1287 NtDeleteValueKey(handle, &Value);
1292 out:
1293 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1294 if (handle != topkey)
1295 NtClose(handle);
1296 NtClose(topkey);
1297 return ret;
1300 /*************************************************************************
1301 * RtlCheckRegistryKey [NTDLL.@]
1303 * Query multiple registry values with a signle call.
1305 * PARAMS
1306 * RelativeTo [I] Registry path that Path refers to
1307 * Path [I] Path to key
1309 * RETURNS
1310 * STATUS_SUCCESS if the specified key exists, or an NTSTATUS error code.
1312 NTSTATUS WINAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
1314 HANDLE handle;
1315 NTSTATUS status;
1317 TRACE("(%d, %s)\n", RelativeTo, debugstr_w(Path));
1319 if((!RelativeTo) && Path == NULL)
1320 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1321 if(RelativeTo & RTL_REGISTRY_HANDLE)
1322 return STATUS_SUCCESS;
1324 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1325 if (handle) NtClose(handle);
1326 if (status == STATUS_INVALID_HANDLE) status = STATUS_OBJECT_NAME_NOT_FOUND;
1327 return status;
1330 /*************************************************************************
1331 * RtlDeleteRegistryValue [NTDLL.@]
1333 * Query multiple registry values with a signle call.
1335 * PARAMS
1336 * RelativeTo [I] Registry path that Path refers to
1337 * Path [I] Path to key
1338 * ValueName [I] Name of the value to delete
1340 * RETURNS
1341 * STATUS_SUCCESS if the specified key is successfully deleted, or an NTSTATUS error code.
1343 NTSTATUS WINAPI RtlDeleteRegistryValue(IN ULONG RelativeTo, IN PCWSTR Path, IN PCWSTR ValueName)
1345 NTSTATUS status;
1346 HANDLE handle;
1347 UNICODE_STRING Value;
1349 TRACE("(%d, %s, %s)\n", RelativeTo, debugstr_w(Path), debugstr_w(ValueName));
1351 RtlInitUnicodeString(&Value, ValueName);
1352 if(RelativeTo == RTL_REGISTRY_HANDLE)
1354 return NtDeleteValueKey((HANDLE)Path, &Value);
1356 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1357 if (status) return status;
1358 status = NtDeleteValueKey(handle, &Value);
1359 NtClose(handle);
1360 return status;
1363 /*************************************************************************
1364 * RtlWriteRegistryValue [NTDLL.@]
1366 * Sets the registry value with provided data.
1368 * PARAMS
1369 * RelativeTo [I] Registry path that path parameter refers to
1370 * path [I] Path to the key (or handle - see RTL_GetKeyHandle)
1371 * name [I] Name of the registry value to set
1372 * type [I] Type of the registry key to set
1373 * data [I] Pointer to the user data to be set
1374 * length [I] Length of the user data pointed by data
1376 * RETURNS
1377 * STATUS_SUCCESS if the specified key is successfully set,
1378 * or an NTSTATUS error code.
1380 NTSTATUS WINAPI RtlWriteRegistryValue( ULONG RelativeTo, PCWSTR path, PCWSTR name,
1381 ULONG type, PVOID data, ULONG length )
1383 HANDLE hkey;
1384 NTSTATUS status;
1385 UNICODE_STRING str;
1387 TRACE( "(%d, %s, %s) -> %d: %p [%d]\n", RelativeTo, debugstr_w(path), debugstr_w(name),
1388 type, data, length );
1390 RtlInitUnicodeString( &str, name );
1392 if (RelativeTo == RTL_REGISTRY_HANDLE)
1393 return NtSetValueKey( (HANDLE)path, &str, 0, type, data, length );
1395 status = RTL_GetKeyHandle( RelativeTo, path, &hkey );
1396 if (status != STATUS_SUCCESS) return status;
1398 status = NtSetValueKey( hkey, &str, 0, type, data, length );
1399 NtClose( hkey );
1401 return status;