wined3d: Report post pixelshader blending on WINED3DFMT_A16B16G16R16F.
[wine/gsoc_dplay.git] / dlls / ntdll / reg.c
blob425ddf848909f9b7dc81edf5c1a7218040050624
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 = attr->RootDirectory;
68 req->access = access;
69 req->attributes = attr->Attributes;
70 req->options = options;
71 req->modif = 0;
72 req->namelen = attr->ObjectName->Length;
73 wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
74 if (class) wine_server_add_data( req, class->Buffer, class->Length );
75 if (!(ret = wine_server_call( req )))
77 *retkey = reply->hkey;
78 if (dispos) *dispos = reply->created ? REG_CREATED_NEW_KEY : REG_OPENED_EXISTING_KEY;
81 SERVER_END_REQ;
82 TRACE("<- %p\n", *retkey);
83 return ret;
86 /******************************************************************************
87 * RtlpNtCreateKey [NTDLL.@]
89 * See NtCreateKey.
91 NTSTATUS WINAPI RtlpNtCreateKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
92 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
93 PULONG dispos )
95 OBJECT_ATTRIBUTES oa;
97 if (attr)
99 oa = *attr;
100 oa.Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
101 attr = &oa;
104 return NtCreateKey(retkey, access, attr, 0, NULL, 0, dispos);
107 /******************************************************************************
108 * NtOpenKey [NTDLL.@]
109 * ZwOpenKey [NTDLL.@]
111 * OUT HANDLE retkey (returns 0 when failure)
112 * IN ACCESS_MASK access
113 * IN POBJECT_ATTRIBUTES attr
115 NTSTATUS WINAPI NtOpenKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
117 NTSTATUS ret;
118 DWORD len = attr->ObjectName->Length;
120 TRACE( "(%p,%s,%x,%p)\n", attr->RootDirectory,
121 debugstr_us(attr->ObjectName), access, retkey );
123 if (len > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
124 if (!retkey) return STATUS_INVALID_PARAMETER;
126 SERVER_START_REQ( open_key )
128 req->parent = attr->RootDirectory;
129 req->access = access;
130 req->attributes = attr->Attributes;
131 wine_server_add_data( req, attr->ObjectName->Buffer, len );
132 ret = wine_server_call( req );
133 *retkey = reply->hkey;
135 SERVER_END_REQ;
136 TRACE("<- %p\n", *retkey);
137 return ret;
140 /******************************************************************************
141 * RtlpNtOpenKey [NTDLL.@]
143 * See NtOpenKey.
145 NTSTATUS WINAPI RtlpNtOpenKey( PHANDLE retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr )
147 if (attr)
148 attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
149 return NtOpenKey(retkey, access, attr);
152 /******************************************************************************
153 * NtDeleteKey [NTDLL.@]
154 * ZwDeleteKey [NTDLL.@]
156 NTSTATUS WINAPI NtDeleteKey( HANDLE hkey )
158 NTSTATUS ret;
160 TRACE( "(%p)\n", hkey );
162 SERVER_START_REQ( delete_key )
164 req->hkey = hkey;
165 ret = wine_server_call( req );
167 SERVER_END_REQ;
168 return ret;
171 /******************************************************************************
172 * RtlpNtMakeTemporaryKey [NTDLL.@]
174 * See NtDeleteKey.
176 NTSTATUS WINAPI RtlpNtMakeTemporaryKey( HANDLE hkey )
178 return NtDeleteKey(hkey);
181 /******************************************************************************
182 * NtDeleteValueKey [NTDLL.@]
183 * ZwDeleteValueKey [NTDLL.@]
185 NTSTATUS WINAPI NtDeleteValueKey( HANDLE hkey, const UNICODE_STRING *name )
187 NTSTATUS ret;
189 TRACE( "(%p,%s)\n", hkey, debugstr_us(name) );
190 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
192 SERVER_START_REQ( delete_key_value )
194 req->hkey = hkey;
195 wine_server_add_data( req, name->Buffer, name->Length );
196 ret = wine_server_call( req );
198 SERVER_END_REQ;
199 return ret;
203 /******************************************************************************
204 * enumerate_key
206 * Implementation of NtQueryKey and NtEnumerateKey
208 static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS info_class,
209 void *info, DWORD length, DWORD *result_len )
212 NTSTATUS ret;
213 void *data_ptr;
214 size_t fixed_size;
216 switch(info_class)
218 case KeyBasicInformation: data_ptr = ((KEY_BASIC_INFORMATION *)info)->Name; break;
219 case KeyFullInformation: data_ptr = ((KEY_FULL_INFORMATION *)info)->Class; break;
220 case KeyNodeInformation: data_ptr = ((KEY_NODE_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 = 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 LARGE_INTEGER modif;
237 RtlSecondsSince1970ToTime( reply->modif, &modif );
239 switch(info_class)
241 case KeyBasicInformation:
243 KEY_BASIC_INFORMATION keyinfo;
244 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
245 keyinfo.LastWriteTime = modif;
246 keyinfo.TitleIndex = 0;
247 keyinfo.NameLength = reply->namelen;
248 memcpy( info, &keyinfo, min( length, fixed_size ) );
250 break;
251 case KeyFullInformation:
253 KEY_FULL_INFORMATION keyinfo;
254 fixed_size = (char *)keyinfo.Class - (char *)&keyinfo;
255 keyinfo.LastWriteTime = modif;
256 keyinfo.TitleIndex = 0;
257 keyinfo.ClassLength = wine_server_reply_size(reply);
258 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size : -1;
259 keyinfo.SubKeys = reply->subkeys;
260 keyinfo.MaxNameLen = reply->max_subkey;
261 keyinfo.MaxClassLen = reply->max_class;
262 keyinfo.Values = reply->values;
263 keyinfo.MaxValueNameLen = reply->max_value;
264 keyinfo.MaxValueDataLen = reply->max_data;
265 memcpy( info, &keyinfo, min( length, fixed_size ) );
267 break;
268 case KeyNodeInformation:
270 KEY_NODE_INFORMATION keyinfo;
271 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
272 keyinfo.LastWriteTime = modif;
273 keyinfo.TitleIndex = 0;
274 if (reply->namelen < wine_server_reply_size(reply))
276 keyinfo.ClassLength = wine_server_reply_size(reply) - reply->namelen;
277 keyinfo.ClassOffset = fixed_size + reply->namelen;
279 else
281 keyinfo.ClassLength = 0;
282 keyinfo.ClassOffset = -1;
284 keyinfo.NameLength = reply->namelen;
285 memcpy( info, &keyinfo, min( length, fixed_size ) );
287 break;
289 *result_len = fixed_size + reply->total;
290 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
293 SERVER_END_REQ;
294 return ret;
299 /******************************************************************************
300 * NtEnumerateKey [NTDLL.@]
301 * ZwEnumerateKey [NTDLL.@]
303 * NOTES
304 * the name copied into the buffer is NOT 0-terminated
306 NTSTATUS WINAPI NtEnumerateKey( HANDLE handle, ULONG index, KEY_INFORMATION_CLASS info_class,
307 void *info, DWORD length, DWORD *result_len )
309 /* -1 means query key, so avoid it here */
310 if (index == (ULONG)-1) return STATUS_NO_MORE_ENTRIES;
311 return enumerate_key( handle, index, info_class, info, length, result_len );
315 /******************************************************************************
316 * RtlpNtEnumerateSubKey [NTDLL.@]
319 NTSTATUS WINAPI RtlpNtEnumerateSubKey( HANDLE handle, UNICODE_STRING *out, ULONG index )
321 KEY_BASIC_INFORMATION *info;
322 DWORD dwLen, dwResultLen;
323 NTSTATUS ret;
325 if (out->Length)
327 dwLen = out->Length + sizeof(KEY_BASIC_INFORMATION);
328 info = (KEY_BASIC_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
329 if (!info)
330 return STATUS_NO_MEMORY;
332 else
334 dwLen = 0;
335 info = NULL;
338 ret = NtEnumerateKey( handle, index, KeyBasicInformation, info, dwLen, &dwResultLen );
339 dwResultLen -= sizeof(KEY_BASIC_INFORMATION);
341 if (ret == STATUS_BUFFER_OVERFLOW)
342 out->Length = dwResultLen;
343 else if (!ret)
345 if (out->Length < info->NameLength)
347 out->Length = dwResultLen;
348 ret = STATUS_BUFFER_OVERFLOW;
350 else
352 out->Length = info->NameLength;
353 memcpy(out->Buffer, info->Name, info->NameLength);
357 RtlFreeHeap( GetProcessHeap(), 0, info );
358 return ret;
361 /******************************************************************************
362 * NtQueryKey [NTDLL.@]
363 * ZwQueryKey [NTDLL.@]
365 NTSTATUS WINAPI NtQueryKey( HANDLE handle, KEY_INFORMATION_CLASS info_class,
366 void *info, DWORD length, DWORD *result_len )
368 return enumerate_key( handle, -1, info_class, info, length, result_len );
372 /* fill the key value info structure for a specific info class */
373 static void copy_key_value_info( KEY_VALUE_INFORMATION_CLASS info_class, void *info,
374 DWORD length, int type, int name_len, int data_len )
376 switch(info_class)
378 case KeyValueBasicInformation:
380 KEY_VALUE_BASIC_INFORMATION keyinfo;
381 keyinfo.TitleIndex = 0;
382 keyinfo.Type = type;
383 keyinfo.NameLength = name_len;
384 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
385 memcpy( info, &keyinfo, length );
386 break;
388 case KeyValueFullInformation:
390 KEY_VALUE_FULL_INFORMATION keyinfo;
391 keyinfo.TitleIndex = 0;
392 keyinfo.Type = type;
393 keyinfo.DataOffset = (char *)keyinfo.Name - (char *)&keyinfo + name_len;
394 keyinfo.DataLength = data_len;
395 keyinfo.NameLength = name_len;
396 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
397 memcpy( info, &keyinfo, length );
398 break;
400 case KeyValuePartialInformation:
402 KEY_VALUE_PARTIAL_INFORMATION keyinfo;
403 keyinfo.TitleIndex = 0;
404 keyinfo.Type = type;
405 keyinfo.DataLength = data_len;
406 length = min( length, (char *)keyinfo.Data - (char *)&keyinfo );
407 memcpy( info, &keyinfo, length );
408 break;
410 default:
411 break;
416 /******************************************************************************
417 * NtEnumerateValueKey [NTDLL.@]
418 * ZwEnumerateValueKey [NTDLL.@]
420 NTSTATUS WINAPI NtEnumerateValueKey( HANDLE handle, ULONG index,
421 KEY_VALUE_INFORMATION_CLASS info_class,
422 void *info, DWORD length, DWORD *result_len )
424 NTSTATUS ret;
425 void *ptr;
426 size_t fixed_size;
428 TRACE( "(%p,%u,%d,%p,%d)\n", handle, index, info_class, info, length );
430 /* compute the length we want to retrieve */
431 switch(info_class)
433 case KeyValueBasicInformation: ptr = ((KEY_VALUE_BASIC_INFORMATION *)info)->Name; break;
434 case KeyValueFullInformation: ptr = ((KEY_VALUE_FULL_INFORMATION *)info)->Name; break;
435 case KeyValuePartialInformation: ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data; break;
436 default:
437 FIXME( "Information class %d not implemented\n", info_class );
438 return STATUS_INVALID_PARAMETER;
440 fixed_size = (char *)ptr - (char *)info;
442 SERVER_START_REQ( enum_key_value )
444 req->hkey = handle;
445 req->index = index;
446 req->info_class = info_class;
447 if (length > fixed_size) wine_server_set_reply( req, ptr, length - fixed_size );
448 if (!(ret = wine_server_call( req )))
450 copy_key_value_info( info_class, info, length, reply->type, reply->namelen,
451 wine_server_reply_size(reply) - reply->namelen );
452 *result_len = fixed_size + reply->total;
453 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
456 SERVER_END_REQ;
457 return ret;
461 /******************************************************************************
462 * NtQueryValueKey [NTDLL.@]
463 * ZwQueryValueKey [NTDLL.@]
465 * NOTES
466 * the name in the KeyValueInformation is never set
468 NTSTATUS WINAPI NtQueryValueKey( HANDLE handle, const UNICODE_STRING *name,
469 KEY_VALUE_INFORMATION_CLASS info_class,
470 void *info, DWORD length, DWORD *result_len )
472 NTSTATUS ret;
473 UCHAR *data_ptr;
474 unsigned int fixed_size = 0;
476 TRACE( "(%p,%s,%d,%p,%d)\n", handle, debugstr_us(name), info_class, info, length );
478 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
480 /* compute the length we want to retrieve */
481 switch(info_class)
483 case KeyValueBasicInformation:
485 KEY_VALUE_BASIC_INFORMATION *basic_info = info;
486 if (FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) < length)
488 memcpy(basic_info->Name, name->Buffer,
489 min(length - FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name), name->Length));
491 fixed_size = FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) + name->Length;
492 data_ptr = NULL;
493 break;
495 case KeyValueFullInformation:
497 KEY_VALUE_FULL_INFORMATION *full_info = info;
498 if (FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name) < length)
500 memcpy(full_info->Name, name->Buffer,
501 min(length - FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name), name->Length));
503 data_ptr = (UCHAR *)full_info->Name + name->Length;
504 fixed_size = (char *)data_ptr - (char *)info;
505 break;
507 case KeyValuePartialInformation:
508 data_ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data;
509 fixed_size = (char *)data_ptr - (char *)info;
510 break;
511 default:
512 FIXME( "Information class %d not implemented\n", info_class );
513 return STATUS_INVALID_PARAMETER;
516 SERVER_START_REQ( get_key_value )
518 req->hkey = handle;
519 wine_server_add_data( req, name->Buffer, name->Length );
520 if (length > fixed_size && data_ptr) wine_server_set_reply( req, data_ptr, length - fixed_size );
521 if (!(ret = wine_server_call( req )))
523 copy_key_value_info( info_class, info, length, reply->type,
524 name->Length, reply->total );
525 *result_len = fixed_size + (info_class == KeyValueBasicInformation ? 0 : reply->total);
526 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
529 SERVER_END_REQ;
530 return ret;
533 /******************************************************************************
534 * RtlpNtQueryValueKey [NTDLL.@]
537 NTSTATUS WINAPI RtlpNtQueryValueKey( HANDLE handle, ULONG *result_type, PBYTE dest,
538 DWORD *result_len )
540 KEY_VALUE_PARTIAL_INFORMATION *info;
541 UNICODE_STRING name;
542 NTSTATUS ret;
543 DWORD dwResultLen;
544 DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + (result_len ? *result_len : 0);
546 info = (KEY_VALUE_PARTIAL_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
547 if (!info)
548 return STATUS_NO_MEMORY;
550 name.Length = 0;
551 ret = NtQueryValueKey( handle, &name, KeyValuePartialInformation, info, dwLen, &dwResultLen );
553 if (!ret || ret == STATUS_BUFFER_OVERFLOW)
555 if (result_len)
556 *result_len = info->DataLength;
558 if (result_type)
559 *result_type = info->Type;
561 if (ret != STATUS_BUFFER_OVERFLOW)
562 memcpy( dest, info->Data, info->DataLength );
565 RtlFreeHeap( GetProcessHeap(), 0, info );
566 return ret;
569 /******************************************************************************
570 * NtFlushKey [NTDLL.@]
571 * ZwFlushKey [NTDLL.@]
573 NTSTATUS WINAPI NtFlushKey(HANDLE key)
575 NTSTATUS ret;
577 TRACE("key=%p\n", key);
579 SERVER_START_REQ( flush_key )
581 req->hkey = key;
582 ret = wine_server_call( req );
584 SERVER_END_REQ;
586 return ret;
589 /******************************************************************************
590 * NtLoadKey [NTDLL.@]
591 * ZwLoadKey [NTDLL.@]
593 NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, OBJECT_ATTRIBUTES *file )
595 NTSTATUS ret;
596 HANDLE hive;
597 IO_STATUS_BLOCK io;
599 TRACE("(%p,%p)\n", attr, file);
601 ret = NtCreateFile(&hive, GENERIC_READ, file, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
602 FILE_OPEN, 0, NULL, 0);
603 if (ret) return ret;
605 SERVER_START_REQ( load_registry )
607 req->hkey = attr->RootDirectory;
608 req->file = hive;
609 wine_server_add_data(req, attr->ObjectName->Buffer, attr->ObjectName->Length);
610 ret = wine_server_call( req );
612 SERVER_END_REQ;
614 NtClose(hive);
616 return ret;
619 /******************************************************************************
620 * NtNotifyChangeKey [NTDLL.@]
621 * ZwNotifyChangeKey [NTDLL.@]
623 NTSTATUS WINAPI NtNotifyChangeKey(
624 IN HANDLE KeyHandle,
625 IN HANDLE Event,
626 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
627 IN PVOID ApcContext OPTIONAL,
628 OUT PIO_STATUS_BLOCK IoStatusBlock,
629 IN ULONG CompletionFilter,
630 IN BOOLEAN Asynchronous,
631 OUT PVOID ChangeBuffer,
632 IN ULONG Length,
633 IN BOOLEAN WatchSubtree)
635 NTSTATUS ret;
637 TRACE("(%p,%p,%p,%p,%p,0x%08x, 0x%08x,%p,0x%08x,0x%08x)\n",
638 KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
639 Asynchronous, ChangeBuffer, Length, WatchSubtree);
641 if (ApcRoutine || ApcContext || ChangeBuffer || Length)
642 FIXME("Unimplemented optional parameter\n");
644 if (!Asynchronous)
646 OBJECT_ATTRIBUTES attr;
647 InitializeObjectAttributes( &attr, NULL, 0, NULL, NULL );
648 ret = NtCreateEvent( &Event, EVENT_ALL_ACCESS, &attr, FALSE, FALSE );
649 if (ret != STATUS_SUCCESS)
650 return ret;
653 SERVER_START_REQ( set_registry_notification )
655 req->hkey = KeyHandle;
656 req->event = Event;
657 req->subtree = WatchSubtree;
658 req->filter = CompletionFilter;
659 ret = wine_server_call( req );
661 SERVER_END_REQ;
663 if (!Asynchronous)
665 if (ret == STATUS_SUCCESS)
666 NtWaitForSingleObject( Event, FALSE, NULL );
667 NtClose( Event );
670 return STATUS_SUCCESS;
673 /******************************************************************************
674 * NtQueryMultipleValueKey [NTDLL]
675 * ZwQueryMultipleValueKey
678 NTSTATUS WINAPI NtQueryMultipleValueKey(
679 HANDLE KeyHandle,
680 PKEY_MULTIPLE_VALUE_INFORMATION ListOfValuesToQuery,
681 ULONG NumberOfItems,
682 PVOID MultipleValueInformation,
683 ULONG Length,
684 PULONG ReturnLength)
686 FIXME("(%p,%p,0x%08x,%p,0x%08x,%p) stub!\n",
687 KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
688 Length,ReturnLength);
689 return STATUS_SUCCESS;
692 /******************************************************************************
693 * NtReplaceKey [NTDLL.@]
694 * ZwReplaceKey [NTDLL.@]
696 NTSTATUS WINAPI NtReplaceKey(
697 IN POBJECT_ATTRIBUTES ObjectAttributes,
698 IN HANDLE Key,
699 IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
701 FIXME("(%p),stub!\n", Key);
702 dump_ObjectAttributes(ObjectAttributes);
703 dump_ObjectAttributes(ReplacedObjectAttributes);
704 return STATUS_SUCCESS;
706 /******************************************************************************
707 * NtRestoreKey [NTDLL.@]
708 * ZwRestoreKey [NTDLL.@]
710 NTSTATUS WINAPI NtRestoreKey(
711 HANDLE KeyHandle,
712 HANDLE FileHandle,
713 ULONG RestoreFlags)
715 FIXME("(%p,%p,0x%08x) stub\n",
716 KeyHandle, FileHandle, RestoreFlags);
717 return STATUS_SUCCESS;
719 /******************************************************************************
720 * NtSaveKey [NTDLL.@]
721 * ZwSaveKey [NTDLL.@]
723 NTSTATUS WINAPI NtSaveKey(IN HANDLE KeyHandle, IN HANDLE FileHandle)
725 NTSTATUS ret;
727 TRACE("(%p,%p)\n", KeyHandle, FileHandle);
729 SERVER_START_REQ( save_registry )
731 req->hkey = KeyHandle;
732 req->file = FileHandle;
733 ret = wine_server_call( req );
735 SERVER_END_REQ;
737 return ret;
739 /******************************************************************************
740 * NtSetInformationKey [NTDLL.@]
741 * ZwSetInformationKey [NTDLL.@]
743 NTSTATUS WINAPI NtSetInformationKey(
744 IN HANDLE KeyHandle,
745 IN const int KeyInformationClass,
746 IN PVOID KeyInformation,
747 IN ULONG KeyInformationLength)
749 FIXME("(%p,0x%08x,%p,0x%08x) stub\n",
750 KeyHandle, KeyInformationClass, KeyInformation, KeyInformationLength);
751 return STATUS_SUCCESS;
755 /******************************************************************************
756 * NtSetValueKey [NTDLL.@]
757 * ZwSetValueKey [NTDLL.@]
759 * NOTES
760 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
761 * NT does definitely care (aj)
763 NTSTATUS WINAPI NtSetValueKey( HANDLE hkey, const UNICODE_STRING *name, ULONG TitleIndex,
764 ULONG type, const void *data, ULONG count )
766 NTSTATUS ret;
768 TRACE( "(%p,%s,%d,%p,%d)\n", hkey, debugstr_us(name), type, data, count );
770 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
772 SERVER_START_REQ( set_key_value )
774 req->hkey = hkey;
775 req->type = type;
776 req->namelen = name->Length;
777 wine_server_add_data( req, name->Buffer, name->Length );
778 wine_server_add_data( req, data, count );
779 ret = wine_server_call( req );
781 SERVER_END_REQ;
782 return ret;
785 /******************************************************************************
786 * RtlpNtSetValueKey [NTDLL.@]
789 NTSTATUS WINAPI RtlpNtSetValueKey( HANDLE hkey, ULONG type, const void *data,
790 ULONG count )
792 UNICODE_STRING name;
794 name.Length = 0;
795 return NtSetValueKey( hkey, &name, 0, type, data, count );
798 /******************************************************************************
799 * NtUnloadKey [NTDLL.@]
800 * ZwUnloadKey [NTDLL.@]
802 NTSTATUS WINAPI NtUnloadKey(IN POBJECT_ATTRIBUTES attr)
804 NTSTATUS ret;
806 TRACE("(%p)\n", attr);
808 SERVER_START_REQ( unload_registry )
810 req->hkey = attr->RootDirectory;
811 ret = wine_server_call(req);
813 SERVER_END_REQ;
815 return ret;
818 /******************************************************************************
819 * RtlFormatCurrentUserKeyPath [NTDLL.@]
822 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
824 static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
825 HANDLE token;
826 NTSTATUS status;
828 status = NtOpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token);
829 if (status == STATUS_NO_TOKEN)
830 status = NtOpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token);
831 if (status == STATUS_SUCCESS)
833 char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
834 DWORD len = sizeof(buffer);
836 status = NtQueryInformationToken(token, TokenUser, buffer, len, &len);
837 if (status == STATUS_SUCCESS)
839 KeyPath->MaximumLength = 0;
840 status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
841 if (status == STATUS_BUFFER_OVERFLOW)
843 PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
844 sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
845 if (buf)
847 memcpy(buf, pathW, sizeof(pathW));
848 KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
849 KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
850 status = RtlConvertSidToUnicodeString(KeyPath,
851 ((TOKEN_USER *)buffer)->User.Sid, FALSE);
852 KeyPath->Buffer = buf;
853 KeyPath->Length += sizeof(pathW);
854 KeyPath->MaximumLength += sizeof(pathW);
856 else
857 status = STATUS_NO_MEMORY;
860 NtClose(token);
862 return status;
865 /******************************************************************************
866 * RtlOpenCurrentUser [NTDLL.@]
868 * NOTES
869 * If we return just HKEY_CURRENT_USER the advapi tries to find a remote
870 * registry (odd handle) and fails.
872 NTSTATUS WINAPI RtlOpenCurrentUser(
873 IN ACCESS_MASK DesiredAccess, /* [in] */
874 OUT PHANDLE KeyHandle) /* [out] handle of HKEY_CURRENT_USER */
876 OBJECT_ATTRIBUTES ObjectAttributes;
877 UNICODE_STRING ObjectName;
878 NTSTATUS ret;
880 TRACE("(0x%08x, %p)\n",DesiredAccess, KeyHandle);
882 if ((ret = RtlFormatCurrentUserKeyPath(&ObjectName))) return ret;
883 InitializeObjectAttributes(&ObjectAttributes,&ObjectName,OBJ_CASE_INSENSITIVE,0, NULL);
884 ret = NtCreateKey(KeyHandle, DesiredAccess, &ObjectAttributes, 0, NULL, 0, NULL);
885 RtlFreeUnicodeString(&ObjectName);
886 return ret;
890 static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo,
891 PRTL_QUERY_REGISTRY_TABLE pQuery, PVOID pContext, PVOID pEnvironment)
893 PUNICODE_STRING str;
894 UNICODE_STRING src, dst;
895 LONG *bin;
896 ULONG offset;
897 PWSTR wstr;
898 DWORD res;
899 NTSTATUS status = STATUS_SUCCESS;
900 ULONG len;
901 LPWSTR String;
902 INT count = 0;
904 if (pInfo == NULL)
906 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
907 return STATUS_INVALID_PARAMETER;
908 else
910 status = pQuery->QueryRoutine(pQuery->Name, pQuery->DefaultType, pQuery->DefaultData,
911 pQuery->DefaultLength, pContext, pQuery->EntryContext);
913 return status;
915 len = pInfo->DataLength;
917 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
919 str = (PUNICODE_STRING)pQuery->EntryContext;
921 switch(pInfo->Type)
923 case REG_EXPAND_SZ:
924 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
926 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
927 res = 0;
928 dst.MaximumLength = 0;
929 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
930 dst.Length = 0;
931 dst.MaximumLength = res;
932 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
933 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
934 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
935 dst.Length, pContext, pQuery->EntryContext);
936 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
939 case REG_SZ:
940 case REG_LINK:
941 if (str->Buffer == NULL)
942 RtlCreateUnicodeString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
943 else
944 RtlAppendUnicodeToString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
945 break;
947 case REG_MULTI_SZ:
948 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
949 return STATUS_INVALID_PARAMETER;
951 if (str->Buffer == NULL)
953 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
954 str->MaximumLength = len;
956 len = min(len, str->MaximumLength);
957 memcpy(str->Buffer, ((CHAR*)pInfo) + pInfo->DataOffset, len);
958 str->Length = len;
959 break;
961 default:
962 bin = (LONG*)pQuery->EntryContext;
963 if (pInfo->DataLength <= sizeof(ULONG))
964 memcpy(bin, ((CHAR*)pInfo) + pInfo->DataOffset,
965 pInfo->DataLength);
966 else
968 if (bin[0] <= sizeof(ULONG))
970 memcpy(&bin[1], ((CHAR*)pInfo) + pInfo->DataOffset,
971 min(-bin[0], pInfo->DataLength));
973 else
975 len = min(bin[0], pInfo->DataLength);
976 bin[1] = len;
977 bin[2] = pInfo->Type;
978 memcpy(&bin[3], ((CHAR*)pInfo) + pInfo->DataOffset, len);
981 break;
984 else
986 if((pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND) ||
987 (pInfo->Type != REG_EXPAND_SZ && pInfo->Type != REG_MULTI_SZ))
989 status = pQuery->QueryRoutine(pInfo->Name, pInfo->Type,
990 ((CHAR*)pInfo) + pInfo->DataOffset, pInfo->DataLength,
991 pContext, pQuery->EntryContext);
993 else if (pInfo->Type == REG_EXPAND_SZ)
995 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
996 res = 0;
997 dst.MaximumLength = 0;
998 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
999 dst.Length = 0;
1000 dst.MaximumLength = res;
1001 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
1002 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1003 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
1004 dst.Length, pContext, pQuery->EntryContext);
1005 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
1007 else /* REG_MULTI_SZ */
1009 if(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND)
1011 for (offset = 0; offset <= pInfo->DataLength; offset += len + sizeof(WCHAR))
1013 wstr = (WCHAR*)(((CHAR*)pInfo) + offset);
1014 len = strlenW(wstr) * sizeof(WCHAR);
1015 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, wstr, len,
1016 pContext, pQuery->EntryContext);
1017 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1018 return status;
1021 else
1023 while(count<=pInfo->DataLength)
1025 String = (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset)+count;
1026 count+=strlenW(String)+1;
1027 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
1028 res = 0;
1029 dst.MaximumLength = 0;
1030 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1031 dst.Length = 0;
1032 dst.MaximumLength = res;
1033 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
1034 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1035 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
1036 dst.Length, pContext, pQuery->EntryContext);
1037 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
1038 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1039 return status;
1044 return status;
1048 static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHANDLE handle)
1050 UNICODE_STRING KeyString;
1051 OBJECT_ATTRIBUTES regkey;
1052 PCWSTR base;
1053 INT len;
1054 NTSTATUS status;
1056 static const WCHAR empty[] = {0};
1057 static const WCHAR control[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e',
1058 '\\','S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1059 'C','o','n','t','r','o','l','\\',0};
1061 static const WCHAR devicemap[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1062 'H','a','r','d','w','a','r','e','\\','D','e','v','i','c','e','M','a','p','\\',0};
1064 static const WCHAR services[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1065 'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1066 'S','e','r','v','i','c','e','s','\\',0};
1068 static const WCHAR user[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\',
1069 'C','u','r','r','e','n','t','U','s','e','r','\\',0};
1071 static const WCHAR windows_nt[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1072 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1073 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',0};
1075 switch (RelativeTo & 0xff)
1077 case RTL_REGISTRY_ABSOLUTE:
1078 base = empty;
1079 break;
1081 case RTL_REGISTRY_CONTROL:
1082 base = control;
1083 break;
1085 case RTL_REGISTRY_DEVICEMAP:
1086 base = devicemap;
1087 break;
1089 case RTL_REGISTRY_SERVICES:
1090 base = services;
1091 break;
1093 case RTL_REGISTRY_USER:
1094 base = user;
1095 break;
1097 case RTL_REGISTRY_WINDOWS_NT:
1098 base = windows_nt;
1099 break;
1101 default:
1102 return STATUS_INVALID_PARAMETER;
1105 len = (strlenW(base) + strlenW(Path) + 1) * sizeof(WCHAR);
1106 KeyString.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
1107 if (KeyString.Buffer == NULL)
1108 return STATUS_NO_MEMORY;
1110 strcpyW(KeyString.Buffer, base);
1111 strcatW(KeyString.Buffer, Path);
1112 KeyString.Length = len - sizeof(WCHAR);
1113 KeyString.MaximumLength = len;
1114 InitializeObjectAttributes(&regkey, &KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL);
1115 status = NtOpenKey(handle, KEY_ALL_ACCESS, &regkey);
1116 RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer);
1117 return status;
1120 /*************************************************************************
1121 * RtlQueryRegistryValues [NTDLL.@]
1123 * Query multiple registry values with a signle call.
1125 * PARAMS
1126 * RelativeTo [I] Registry path that Path refers to
1127 * Path [I] Path to key
1128 * QueryTable [I] Table of key values to query
1129 * Context [I] Parameter to pass to the application defined QueryRoutine function
1130 * Environment [I] Optional parameter to use when performing expansion
1132 * RETURNS
1133 * STATUS_SUCCESS or an appropriate NTSTATUS error code.
1135 NTSTATUS WINAPI RtlQueryRegistryValues(IN ULONG RelativeTo, IN PCWSTR Path,
1136 IN PRTL_QUERY_REGISTRY_TABLE QueryTable, IN PVOID Context,
1137 IN PVOID Environment OPTIONAL)
1139 UNICODE_STRING Value;
1140 HANDLE handle, topkey;
1141 PKEY_VALUE_FULL_INFORMATION pInfo = NULL;
1142 ULONG len, buflen = 0;
1143 NTSTATUS status=STATUS_SUCCESS, ret = STATUS_SUCCESS;
1144 INT i;
1146 TRACE("(%d, %s, %p, %p, %p)\n", RelativeTo, debugstr_w(Path), QueryTable, Context, Environment);
1148 if(Path == NULL)
1149 return STATUS_INVALID_PARAMETER;
1151 /* get a valid handle */
1152 if (RelativeTo & RTL_REGISTRY_HANDLE)
1153 topkey = handle = (HANDLE)Path;
1154 else
1156 status = RTL_GetKeyHandle(RelativeTo, Path, &topkey);
1157 handle = topkey;
1159 if(status != STATUS_SUCCESS)
1160 return status;
1162 /* Process query table entries */
1163 for (; QueryTable->QueryRoutine != NULL || QueryTable->Name != NULL; ++QueryTable)
1165 if (QueryTable->Flags &
1166 (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY))
1168 /* topkey must be kept open just in case we will reuse it later */
1169 if (handle != topkey)
1170 NtClose(handle);
1172 if (QueryTable->Flags & RTL_QUERY_REGISTRY_SUBKEY)
1174 handle = 0;
1175 status = RTL_GetKeyHandle(PtrToUlong(QueryTable->Name), Path, &handle);
1176 if(status != STATUS_SUCCESS)
1178 ret = status;
1179 goto out;
1182 else
1183 handle = topkey;
1186 if (QueryTable->Flags & RTL_QUERY_REGISTRY_NOVALUE)
1188 QueryTable->QueryRoutine(QueryTable->Name, REG_NONE, NULL, 0,
1189 Context, QueryTable->EntryContext);
1190 continue;
1193 if (!handle)
1195 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1197 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1198 goto out;
1200 continue;
1203 if (QueryTable->Name == NULL)
1205 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT)
1207 ret = STATUS_INVALID_PARAMETER;
1208 goto out;
1211 /* Report all subkeys */
1212 for (i = 0;; ++i)
1214 status = NtEnumerateValueKey(handle, i,
1215 KeyValueFullInformation, pInfo, buflen, &len);
1216 if (status == STATUS_NO_MORE_ENTRIES)
1217 break;
1218 if (status == STATUS_BUFFER_OVERFLOW ||
1219 status == STATUS_BUFFER_TOO_SMALL)
1221 buflen = len;
1222 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1223 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1224 GetProcessHeap(), 0, buflen);
1225 NtEnumerateValueKey(handle, i, KeyValueFullInformation,
1226 pInfo, buflen, &len);
1229 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1230 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1232 ret = status;
1233 goto out;
1235 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1237 RtlInitUnicodeString(&Value, pInfo->Name);
1238 NtDeleteValueKey(handle, &Value);
1242 if (i == 0 && (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED))
1244 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1245 goto out;
1248 else
1250 RtlInitUnicodeString(&Value, QueryTable->Name);
1251 status = NtQueryValueKey(handle, &Value, KeyValueFullInformation,
1252 pInfo, buflen, &len);
1253 if (status == STATUS_BUFFER_OVERFLOW ||
1254 status == STATUS_BUFFER_TOO_SMALL)
1256 buflen = len;
1257 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1258 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1259 GetProcessHeap(), 0, buflen);
1260 status = NtQueryValueKey(handle, &Value,
1261 KeyValueFullInformation, pInfo, buflen, &len);
1263 if (status != STATUS_SUCCESS)
1265 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1267 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1268 goto out;
1270 status = RTL_ReportRegistryValue(NULL, QueryTable, Context, Environment);
1271 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1273 ret = status;
1274 goto out;
1277 else
1279 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1280 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1282 ret = status;
1283 goto out;
1285 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1286 NtDeleteValueKey(handle, &Value);
1291 out:
1292 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1293 if (handle != topkey)
1294 NtClose(handle);
1295 NtClose(topkey);
1296 return ret;
1299 /*************************************************************************
1300 * RtlCheckRegistryKey [NTDLL.@]
1302 * Query multiple registry values with a signle call.
1304 * PARAMS
1305 * RelativeTo [I] Registry path that Path refers to
1306 * Path [I] Path to key
1308 * RETURNS
1309 * STATUS_SUCCESS if the specified key exists, or an NTSTATUS error code.
1311 NTSTATUS WINAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
1313 HANDLE handle;
1314 NTSTATUS status;
1316 TRACE("(%d, %s)\n", RelativeTo, debugstr_w(Path));
1318 if((!RelativeTo) && Path == NULL)
1319 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1320 if(RelativeTo & RTL_REGISTRY_HANDLE)
1321 return STATUS_SUCCESS;
1323 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1324 if (handle) NtClose(handle);
1325 if (status == STATUS_INVALID_HANDLE) status = STATUS_OBJECT_NAME_NOT_FOUND;
1326 return status;
1329 /*************************************************************************
1330 * RtlDeleteRegistryValue [NTDLL.@]
1332 * Query multiple registry values with a signle call.
1334 * PARAMS
1335 * RelativeTo [I] Registry path that Path refers to
1336 * Path [I] Path to key
1337 * ValueName [I] Name of the value to delete
1339 * RETURNS
1340 * STATUS_SUCCESS if the specified key is successfully deleted, or an NTSTATUS error code.
1342 NTSTATUS WINAPI RtlDeleteRegistryValue(IN ULONG RelativeTo, IN PCWSTR Path, IN PCWSTR ValueName)
1344 NTSTATUS status;
1345 HANDLE handle;
1346 UNICODE_STRING Value;
1348 TRACE("(%d, %s, %s)\n", RelativeTo, debugstr_w(Path), debugstr_w(ValueName));
1350 RtlInitUnicodeString(&Value, ValueName);
1351 if(RelativeTo == RTL_REGISTRY_HANDLE)
1353 return NtDeleteValueKey((HANDLE)Path, &Value);
1355 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1356 if (status) return status;
1357 status = NtDeleteValueKey(handle, &Value);
1358 NtClose(handle);
1359 return status;
1362 /*************************************************************************
1363 * RtlWriteRegistryValue [NTDLL.@]
1365 * Sets the registry value with provided data.
1367 * PARAMS
1368 * RelativeTo [I] Registry path that path parameter refers to
1369 * path [I] Path to the key (or handle - see RTL_GetKeyHandle)
1370 * name [I] Name of the registry value to set
1371 * type [I] Type of the registry key to set
1372 * data [I] Pointer to the user data to be set
1373 * length [I] Length of the user data pointed by data
1375 * RETURNS
1376 * STATUS_SUCCESS if the specified key is successfully set,
1377 * or an NTSTATUS error code.
1379 NTSTATUS WINAPI RtlWriteRegistryValue( ULONG RelativeTo, PCWSTR path, PCWSTR name,
1380 ULONG type, PVOID data, ULONG length )
1382 HANDLE hkey;
1383 NTSTATUS status;
1384 UNICODE_STRING str;
1386 TRACE( "(%d, %s, %s) -> %d: %p [%d]\n", RelativeTo, debugstr_w(path), debugstr_w(name),
1387 type, data, length );
1389 RtlInitUnicodeString( &str, name );
1391 if (RelativeTo == RTL_REGISTRY_HANDLE)
1392 return NtSetValueKey( (HANDLE)path, &str, 0, type, data, length );
1394 status = RTL_GetKeyHandle( RelativeTo, path, &hkey );
1395 if (status != STATUS_SUCCESS) return status;
1397 status = NtSetValueKey( hkey, &str, 0, type, data, length );
1398 NtClose( hkey );
1400 return status;