push d9aedd737acdcfb2677a6d114f631e203c9c484f
[wine/hacks.git] / dlls / ntdll / reg.c
blob8b724ec4b48d41f4dd8779773068ede2425e02b3
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 memcpy( &oa, attr, sizeof oa );
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:
484 fixed_size = (char *)((KEY_VALUE_BASIC_INFORMATION *)info)->Name - (char *)info;
485 data_ptr = NULL;
486 break;
487 case KeyValueFullInformation:
488 data_ptr = (UCHAR *)((KEY_VALUE_FULL_INFORMATION *)info)->Name;
489 fixed_size = (char *)data_ptr - (char *)info;
490 break;
491 case KeyValuePartialInformation:
492 data_ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data;
493 fixed_size = (char *)data_ptr - (char *)info;
494 break;
495 default:
496 FIXME( "Information class %d not implemented\n", info_class );
497 return STATUS_INVALID_PARAMETER;
500 SERVER_START_REQ( get_key_value )
502 req->hkey = handle;
503 wine_server_add_data( req, name->Buffer, name->Length );
504 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
505 if (!(ret = wine_server_call( req )))
507 copy_key_value_info( info_class, info, length, reply->type,
508 0, wine_server_reply_size(reply) );
509 *result_len = fixed_size + reply->total;
510 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
513 SERVER_END_REQ;
514 return ret;
517 /******************************************************************************
518 * RtlpNtQueryValueKey [NTDLL.@]
521 NTSTATUS WINAPI RtlpNtQueryValueKey( HANDLE handle, ULONG *result_type, PBYTE dest,
522 DWORD *result_len )
524 KEY_VALUE_PARTIAL_INFORMATION *info;
525 UNICODE_STRING name;
526 NTSTATUS ret;
527 DWORD dwResultLen;
528 DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + (result_len ? *result_len : 0);
530 info = (KEY_VALUE_PARTIAL_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
531 if (!info)
532 return STATUS_NO_MEMORY;
534 name.Length = 0;
535 ret = NtQueryValueKey( handle, &name, KeyValuePartialInformation, info, dwLen, &dwResultLen );
537 if (!ret || ret == STATUS_BUFFER_OVERFLOW)
539 if (result_len)
540 *result_len = info->DataLength;
542 if (result_type)
543 *result_type = info->Type;
545 if (ret != STATUS_BUFFER_OVERFLOW)
546 memcpy( dest, info->Data, info->DataLength );
549 RtlFreeHeap( GetProcessHeap(), 0, info );
550 return ret;
553 /******************************************************************************
554 * NtFlushKey [NTDLL.@]
555 * ZwFlushKey [NTDLL.@]
557 NTSTATUS WINAPI NtFlushKey(HANDLE key)
559 NTSTATUS ret;
561 TRACE("key=%p\n", key);
563 SERVER_START_REQ( flush_key )
565 req->hkey = key;
566 ret = wine_server_call( req );
568 SERVER_END_REQ;
570 return ret;
573 /******************************************************************************
574 * NtLoadKey [NTDLL.@]
575 * ZwLoadKey [NTDLL.@]
577 NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, OBJECT_ATTRIBUTES *file )
579 NTSTATUS ret;
580 HANDLE hive;
581 IO_STATUS_BLOCK io;
583 TRACE("(%p,%p)\n", attr, file);
585 ret = NtCreateFile(&hive, GENERIC_READ, file, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
586 FILE_OPEN, 0, NULL, 0);
587 if (ret) return ret;
589 SERVER_START_REQ( load_registry )
591 req->hkey = attr->RootDirectory;
592 req->file = hive;
593 wine_server_add_data(req, attr->ObjectName->Buffer, attr->ObjectName->Length);
594 ret = wine_server_call( req );
596 SERVER_END_REQ;
598 NtClose(hive);
600 return ret;
603 /******************************************************************************
604 * NtNotifyChangeKey [NTDLL.@]
605 * ZwNotifyChangeKey [NTDLL.@]
607 NTSTATUS WINAPI NtNotifyChangeKey(
608 IN HANDLE KeyHandle,
609 IN HANDLE Event,
610 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
611 IN PVOID ApcContext OPTIONAL,
612 OUT PIO_STATUS_BLOCK IoStatusBlock,
613 IN ULONG CompletionFilter,
614 IN BOOLEAN Asynchronous,
615 OUT PVOID ChangeBuffer,
616 IN ULONG Length,
617 IN BOOLEAN WatchSubtree)
619 NTSTATUS ret;
621 TRACE("(%p,%p,%p,%p,%p,0x%08x, 0x%08x,%p,0x%08x,0x%08x)\n",
622 KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
623 Asynchronous, ChangeBuffer, Length, WatchSubtree);
625 if (ApcRoutine || ApcContext || ChangeBuffer || Length)
626 FIXME("Unimplemented optional parameter\n");
628 if (!Asynchronous)
630 OBJECT_ATTRIBUTES attr;
631 InitializeObjectAttributes( &attr, NULL, 0, NULL, NULL );
632 ret = NtCreateEvent( &Event, EVENT_ALL_ACCESS, &attr, FALSE, FALSE );
633 if (ret != STATUS_SUCCESS)
634 return ret;
637 SERVER_START_REQ( set_registry_notification )
639 req->hkey = KeyHandle;
640 req->event = Event;
641 req->subtree = WatchSubtree;
642 req->filter = CompletionFilter;
643 ret = wine_server_call( req );
645 SERVER_END_REQ;
647 if (!Asynchronous)
649 if (ret == STATUS_SUCCESS)
650 NtWaitForSingleObject( Event, FALSE, NULL );
651 NtClose( Event );
654 return STATUS_SUCCESS;
657 /******************************************************************************
658 * NtQueryMultipleValueKey [NTDLL]
659 * ZwQueryMultipleValueKey
662 NTSTATUS WINAPI NtQueryMultipleValueKey(
663 HANDLE KeyHandle,
664 PKEY_MULTIPLE_VALUE_INFORMATION ListOfValuesToQuery,
665 ULONG NumberOfItems,
666 PVOID MultipleValueInformation,
667 ULONG Length,
668 PULONG ReturnLength)
670 FIXME("(%p,%p,0x%08x,%p,0x%08x,%p) stub!\n",
671 KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
672 Length,ReturnLength);
673 return STATUS_SUCCESS;
676 /******************************************************************************
677 * NtReplaceKey [NTDLL.@]
678 * ZwReplaceKey [NTDLL.@]
680 NTSTATUS WINAPI NtReplaceKey(
681 IN POBJECT_ATTRIBUTES ObjectAttributes,
682 IN HANDLE Key,
683 IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
685 FIXME("(%p),stub!\n", Key);
686 dump_ObjectAttributes(ObjectAttributes);
687 dump_ObjectAttributes(ReplacedObjectAttributes);
688 return STATUS_SUCCESS;
690 /******************************************************************************
691 * NtRestoreKey [NTDLL.@]
692 * ZwRestoreKey [NTDLL.@]
694 NTSTATUS WINAPI NtRestoreKey(
695 HANDLE KeyHandle,
696 HANDLE FileHandle,
697 ULONG RestoreFlags)
699 FIXME("(%p,%p,0x%08x) stub\n",
700 KeyHandle, FileHandle, RestoreFlags);
701 return STATUS_SUCCESS;
703 /******************************************************************************
704 * NtSaveKey [NTDLL.@]
705 * ZwSaveKey [NTDLL.@]
707 NTSTATUS WINAPI NtSaveKey(IN HANDLE KeyHandle, IN HANDLE FileHandle)
709 NTSTATUS ret;
711 TRACE("(%p,%p)\n", KeyHandle, FileHandle);
713 SERVER_START_REQ( save_registry )
715 req->hkey = KeyHandle;
716 req->file = FileHandle;
717 ret = wine_server_call( req );
719 SERVER_END_REQ;
721 return ret;
723 /******************************************************************************
724 * NtSetInformationKey [NTDLL.@]
725 * ZwSetInformationKey [NTDLL.@]
727 NTSTATUS WINAPI NtSetInformationKey(
728 IN HANDLE KeyHandle,
729 IN const int KeyInformationClass,
730 IN PVOID KeyInformation,
731 IN ULONG KeyInformationLength)
733 FIXME("(%p,0x%08x,%p,0x%08x) stub\n",
734 KeyHandle, KeyInformationClass, KeyInformation, KeyInformationLength);
735 return STATUS_SUCCESS;
739 /******************************************************************************
740 * NtSetValueKey [NTDLL.@]
741 * ZwSetValueKey [NTDLL.@]
743 * NOTES
744 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
745 * NT does definitely care (aj)
747 NTSTATUS WINAPI NtSetValueKey( HANDLE hkey, const UNICODE_STRING *name, ULONG TitleIndex,
748 ULONG type, const void *data, ULONG count )
750 NTSTATUS ret;
752 TRACE( "(%p,%s,%d,%p,%d)\n", hkey, debugstr_us(name), type, data, count );
754 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
756 SERVER_START_REQ( set_key_value )
758 req->hkey = hkey;
759 req->type = type;
760 req->namelen = name->Length;
761 wine_server_add_data( req, name->Buffer, name->Length );
762 wine_server_add_data( req, data, count );
763 ret = wine_server_call( req );
765 SERVER_END_REQ;
766 return ret;
769 /******************************************************************************
770 * RtlpNtSetValueKey [NTDLL.@]
773 NTSTATUS WINAPI RtlpNtSetValueKey( HANDLE hkey, ULONG type, const void *data,
774 ULONG count )
776 UNICODE_STRING name;
778 name.Length = 0;
779 return NtSetValueKey( hkey, &name, 0, type, data, count );
782 /******************************************************************************
783 * NtUnloadKey [NTDLL.@]
784 * ZwUnloadKey [NTDLL.@]
786 NTSTATUS WINAPI NtUnloadKey(IN POBJECT_ATTRIBUTES attr)
788 NTSTATUS ret;
790 TRACE("(%p)\n", attr);
792 SERVER_START_REQ( unload_registry )
794 req->hkey = attr->RootDirectory;
795 ret = wine_server_call(req);
797 SERVER_END_REQ;
799 return ret;
802 /******************************************************************************
803 * RtlFormatCurrentUserKeyPath [NTDLL.@]
806 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
808 static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
809 HANDLE token;
810 NTSTATUS status;
812 status = NtOpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token);
813 if (status == STATUS_NO_TOKEN)
814 status = NtOpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token);
815 if (status == STATUS_SUCCESS)
817 char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
818 DWORD len = sizeof(buffer);
820 status = NtQueryInformationToken(token, TokenUser, buffer, len, &len);
821 if (status == STATUS_SUCCESS)
823 KeyPath->MaximumLength = 0;
824 status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
825 if (status == STATUS_BUFFER_OVERFLOW)
827 PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
828 sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
829 if (buf)
831 memcpy(buf, pathW, sizeof(pathW));
832 KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
833 KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
834 status = RtlConvertSidToUnicodeString(KeyPath,
835 ((TOKEN_USER *)buffer)->User.Sid, FALSE);
836 KeyPath->Buffer = (PWCHAR)buf;
837 KeyPath->Length += sizeof(pathW);
838 KeyPath->MaximumLength += sizeof(pathW);
840 else
841 status = STATUS_NO_MEMORY;
844 NtClose(token);
846 return status;
849 /******************************************************************************
850 * RtlOpenCurrentUser [NTDLL.@]
852 * NOTES
853 * If we return just HKEY_CURRENT_USER the advapi tries to find a remote
854 * registry (odd handle) and fails.
856 NTSTATUS WINAPI RtlOpenCurrentUser(
857 IN ACCESS_MASK DesiredAccess, /* [in] */
858 OUT PHANDLE KeyHandle) /* [out] handle of HKEY_CURRENT_USER */
860 OBJECT_ATTRIBUTES ObjectAttributes;
861 UNICODE_STRING ObjectName;
862 NTSTATUS ret;
864 TRACE("(0x%08x, %p)\n",DesiredAccess, KeyHandle);
866 if ((ret = RtlFormatCurrentUserKeyPath(&ObjectName))) return ret;
867 InitializeObjectAttributes(&ObjectAttributes,&ObjectName,OBJ_CASE_INSENSITIVE,0, NULL);
868 ret = NtCreateKey(KeyHandle, DesiredAccess, &ObjectAttributes, 0, NULL, 0, NULL);
869 RtlFreeUnicodeString(&ObjectName);
870 return ret;
874 static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo,
875 PRTL_QUERY_REGISTRY_TABLE pQuery, PVOID pContext, PVOID pEnvironment)
877 PUNICODE_STRING str;
878 UNICODE_STRING src, dst;
879 LONG *bin;
880 ULONG offset;
881 PWSTR wstr;
882 DWORD res;
883 NTSTATUS status = STATUS_SUCCESS;
884 ULONG len;
885 LPWSTR String;
886 INT count = 0;
888 if (pInfo == NULL)
890 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
891 return STATUS_INVALID_PARAMETER;
892 else
894 status = pQuery->QueryRoutine(pQuery->Name, pQuery->DefaultType, pQuery->DefaultData,
895 pQuery->DefaultLength, pContext, pQuery->EntryContext);
897 return status;
899 len = pInfo->DataLength;
901 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
903 str = (PUNICODE_STRING)pQuery->EntryContext;
905 switch(pInfo->Type)
907 case REG_EXPAND_SZ:
908 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
910 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
911 res = 0;
912 dst.MaximumLength = 0;
913 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
914 dst.Length = 0;
915 dst.MaximumLength = res;
916 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
917 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
918 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
919 dst.Length, pContext, pQuery->EntryContext);
920 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
923 case REG_SZ:
924 case REG_LINK:
925 if (str->Buffer == NULL)
926 RtlCreateUnicodeString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
927 else
928 RtlAppendUnicodeToString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
929 break;
931 case REG_MULTI_SZ:
932 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
933 return STATUS_INVALID_PARAMETER;
935 if (str->Buffer == NULL)
937 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
938 str->MaximumLength = len;
940 len = min(len, str->MaximumLength);
941 memcpy(str->Buffer, ((CHAR*)pInfo) + pInfo->DataOffset, len);
942 str->Length = len;
943 break;
945 default:
946 bin = (LONG*)pQuery->EntryContext;
947 if (pInfo->DataLength <= sizeof(ULONG))
948 memcpy(bin, ((CHAR*)pInfo) + pInfo->DataOffset,
949 pInfo->DataLength);
950 else
952 if (bin[0] <= sizeof(ULONG))
954 memcpy(&bin[1], ((CHAR*)pInfo) + pInfo->DataOffset,
955 min(-bin[0], pInfo->DataLength));
957 else
959 len = min(bin[0], pInfo->DataLength);
960 bin[1] = len;
961 bin[2] = pInfo->Type;
962 memcpy(&bin[3], ((CHAR*)pInfo) + pInfo->DataOffset, len);
965 break;
968 else
970 if((pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND) ||
971 (pInfo->Type != REG_EXPAND_SZ && pInfo->Type != REG_MULTI_SZ))
973 status = pQuery->QueryRoutine(pInfo->Name, pInfo->Type,
974 ((CHAR*)pInfo) + pInfo->DataOffset, pInfo->DataLength,
975 pContext, pQuery->EntryContext);
977 else if (pInfo->Type == REG_EXPAND_SZ)
979 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
980 res = 0;
981 dst.MaximumLength = 0;
982 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
983 dst.Length = 0;
984 dst.MaximumLength = res;
985 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
986 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
987 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
988 dst.Length, pContext, pQuery->EntryContext);
989 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
991 else /* REG_MULTI_SZ */
993 if(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND)
995 for (offset = 0; offset <= pInfo->DataLength; offset += len + sizeof(WCHAR))
997 wstr = (WCHAR*)(((CHAR*)pInfo) + offset);
998 len = strlenW(wstr) * sizeof(WCHAR);
999 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, wstr, len,
1000 pContext, pQuery->EntryContext);
1001 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1002 return status;
1005 else
1007 while(count<=pInfo->DataLength)
1009 String = (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset)+count;
1010 count+=strlenW(String)+1;
1011 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
1012 res = 0;
1013 dst.MaximumLength = 0;
1014 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1015 dst.Length = 0;
1016 dst.MaximumLength = res;
1017 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
1018 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1019 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
1020 dst.Length, pContext, pQuery->EntryContext);
1021 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
1022 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1023 return status;
1028 return status;
1032 static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHANDLE handle)
1034 UNICODE_STRING KeyString;
1035 OBJECT_ATTRIBUTES regkey;
1036 PCWSTR base;
1037 INT len;
1038 NTSTATUS status;
1040 static const WCHAR empty[] = {0};
1041 static const WCHAR control[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e',
1042 '\\','S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1043 'C','o','n','t','r','o','l','\\',0};
1045 static const WCHAR devicemap[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1046 'H','a','r','d','w','a','r','e','\\','D','e','v','i','c','e','M','a','p','\\',0};
1048 static const WCHAR services[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1049 'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1050 'S','e','r','v','i','c','e','s','\\',0};
1052 static const WCHAR user[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\',
1053 'C','u','r','r','e','n','t','U','s','e','r','\\',0};
1055 static const WCHAR windows_nt[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1056 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1057 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',0};
1059 switch (RelativeTo & 0xff)
1061 case RTL_REGISTRY_ABSOLUTE:
1062 base = empty;
1063 break;
1065 case RTL_REGISTRY_CONTROL:
1066 base = control;
1067 break;
1069 case RTL_REGISTRY_DEVICEMAP:
1070 base = devicemap;
1071 break;
1073 case RTL_REGISTRY_SERVICES:
1074 base = services;
1075 break;
1077 case RTL_REGISTRY_USER:
1078 base = user;
1079 break;
1081 case RTL_REGISTRY_WINDOWS_NT:
1082 base = windows_nt;
1083 break;
1085 default:
1086 return STATUS_INVALID_PARAMETER;
1089 len = (strlenW(base) + strlenW(Path) + 1) * sizeof(WCHAR);
1090 KeyString.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
1091 if (KeyString.Buffer == NULL)
1092 return STATUS_NO_MEMORY;
1094 strcpyW(KeyString.Buffer, base);
1095 strcatW(KeyString.Buffer, Path);
1096 KeyString.Length = len - sizeof(WCHAR);
1097 KeyString.MaximumLength = len;
1098 InitializeObjectAttributes(&regkey, &KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL);
1099 status = NtOpenKey(handle, KEY_ALL_ACCESS, &regkey);
1100 RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer);
1101 return status;
1104 /*************************************************************************
1105 * RtlQueryRegistryValues [NTDLL.@]
1107 * Query multiple registry values with a signle call.
1109 * PARAMS
1110 * RelativeTo [I] Registry path that Path refers to
1111 * Path [I] Path to key
1112 * QueryTable [I] Table of key values to query
1113 * Context [I] Paremeter to pass to the application defined QueryRoutine function
1114 * Environment [I] Optional parameter to use when performing expantion
1116 * RETURNS
1117 * STATUS_SUCCESS or an appropriate NTSTATUS error code.
1119 NTSTATUS WINAPI RtlQueryRegistryValues(IN ULONG RelativeTo, IN PCWSTR Path,
1120 IN PRTL_QUERY_REGISTRY_TABLE QueryTable, IN PVOID Context,
1121 IN PVOID Environment OPTIONAL)
1123 UNICODE_STRING Value;
1124 HANDLE handle, topkey;
1125 PKEY_VALUE_FULL_INFORMATION pInfo = NULL;
1126 ULONG len, buflen = 0;
1127 NTSTATUS status=STATUS_SUCCESS, ret = STATUS_SUCCESS;
1128 INT i;
1130 TRACE("(%d, %s, %p, %p, %p)\n", RelativeTo, debugstr_w(Path), QueryTable, Context, Environment);
1132 if(Path == NULL)
1133 return STATUS_INVALID_PARAMETER;
1135 /* get a valid handle */
1136 if (RelativeTo & RTL_REGISTRY_HANDLE)
1137 topkey = handle = (HANDLE)Path;
1138 else
1140 status = RTL_GetKeyHandle(RelativeTo, Path, &topkey);
1141 handle = topkey;
1143 if(status != STATUS_SUCCESS)
1144 return status;
1146 /* Process query table entries */
1147 for (; QueryTable->QueryRoutine != NULL || QueryTable->Name != NULL; ++QueryTable)
1149 if (QueryTable->Flags &
1150 (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY))
1152 /* topkey must be kept open just in case we will reuse it later */
1153 if (handle != topkey)
1154 NtClose(handle);
1156 if (QueryTable->Flags & RTL_QUERY_REGISTRY_SUBKEY)
1158 handle = 0;
1159 status = RTL_GetKeyHandle(PtrToUlong(QueryTable->Name), Path, &handle);
1160 if(status != STATUS_SUCCESS)
1162 ret = status;
1163 goto out;
1166 else
1167 handle = topkey;
1170 if (QueryTable->Flags & RTL_QUERY_REGISTRY_NOVALUE)
1172 QueryTable->QueryRoutine(QueryTable->Name, REG_NONE, NULL, 0,
1173 Context, QueryTable->EntryContext);
1174 continue;
1177 if (!handle)
1179 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1181 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1182 goto out;
1184 continue;
1187 if (QueryTable->Name == NULL)
1189 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT)
1191 ret = STATUS_INVALID_PARAMETER;
1192 goto out;
1195 /* Report all subkeys */
1196 for (i = 0;; ++i)
1198 status = NtEnumerateValueKey(handle, i,
1199 KeyValueFullInformation, pInfo, buflen, &len);
1200 if (status == STATUS_NO_MORE_ENTRIES)
1201 break;
1202 if (status == STATUS_BUFFER_OVERFLOW ||
1203 status == STATUS_BUFFER_TOO_SMALL)
1205 buflen = len;
1206 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1207 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1208 GetProcessHeap(), 0, buflen);
1209 NtEnumerateValueKey(handle, i, KeyValueFullInformation,
1210 pInfo, buflen, &len);
1213 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1214 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1216 ret = status;
1217 goto out;
1219 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1221 RtlInitUnicodeString(&Value, pInfo->Name);
1222 NtDeleteValueKey(handle, &Value);
1226 if (i == 0 && (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED))
1228 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1229 goto out;
1232 else
1234 RtlInitUnicodeString(&Value, QueryTable->Name);
1235 status = NtQueryValueKey(handle, &Value, KeyValueFullInformation,
1236 pInfo, buflen, &len);
1237 if (status == STATUS_BUFFER_OVERFLOW ||
1238 status == STATUS_BUFFER_TOO_SMALL)
1240 buflen = len;
1241 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1242 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1243 GetProcessHeap(), 0, buflen);
1244 status = NtQueryValueKey(handle, &Value,
1245 KeyValueFullInformation, pInfo, buflen, &len);
1247 if (status != STATUS_SUCCESS)
1249 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1251 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1252 goto out;
1254 status = RTL_ReportRegistryValue(NULL, QueryTable, Context, Environment);
1255 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1257 ret = status;
1258 goto out;
1261 else
1263 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1264 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1266 ret = status;
1267 goto out;
1269 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1270 NtDeleteValueKey(handle, &Value);
1275 out:
1276 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1277 if (handle != topkey)
1278 NtClose(handle);
1279 NtClose(topkey);
1280 return ret;
1283 /*************************************************************************
1284 * RtlCheckRegistryKey [NTDLL.@]
1286 * Query multiple registry values with a signle call.
1288 * PARAMS
1289 * RelativeTo [I] Registry path that Path refers to
1290 * Path [I] Path to key
1292 * RETURNS
1293 * STATUS_SUCCESS if the specified key exists, or an NTSTATUS error code.
1295 NTSTATUS WINAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
1297 HANDLE handle;
1298 NTSTATUS status;
1300 TRACE("(%d, %s)\n", RelativeTo, debugstr_w(Path));
1302 if((!RelativeTo) && Path == NULL)
1303 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1304 if(RelativeTo & RTL_REGISTRY_HANDLE)
1305 return STATUS_SUCCESS;
1307 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1308 if (handle) NtClose(handle);
1309 if (status == STATUS_INVALID_HANDLE) status = STATUS_OBJECT_NAME_NOT_FOUND;
1310 return status;
1313 /*************************************************************************
1314 * RtlDeleteRegistryValue [NTDLL.@]
1316 * Query multiple registry values with a signle call.
1318 * PARAMS
1319 * RelativeTo [I] Registry path that Path refers to
1320 * Path [I] Path to key
1321 * ValueName [I] Name of the value to delete
1323 * RETURNS
1324 * STATUS_SUCCESS if the specified key is successfully deleted, or an NTSTATUS error code.
1326 NTSTATUS WINAPI RtlDeleteRegistryValue(IN ULONG RelativeTo, IN PCWSTR Path, IN PCWSTR ValueName)
1328 NTSTATUS status;
1329 HANDLE handle;
1330 UNICODE_STRING Value;
1332 TRACE("(%d, %s, %s)\n", RelativeTo, debugstr_w(Path), debugstr_w(ValueName));
1334 RtlInitUnicodeString(&Value, ValueName);
1335 if(RelativeTo == RTL_REGISTRY_HANDLE)
1337 return NtDeleteValueKey((HANDLE)Path, &Value);
1339 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1340 if (status) return status;
1341 status = NtDeleteValueKey(handle, &Value);
1342 NtClose(handle);
1343 return status;
1346 /*************************************************************************
1347 * RtlWriteRegistryValue [NTDLL.@]
1349 * Sets the registry value with provided data.
1351 * PARAMS
1352 * RelativeTo [I] Registry path that path parameter refers to
1353 * path [I] Path to the key (or handle - see RTL_GetKeyHandle)
1354 * name [I] Name of the registry value to set
1355 * type [I] Type of the registry key to set
1356 * data [I] Pointer to the user data to be set
1357 * length [I] Length of the user data pointed by data
1359 * RETURNS
1360 * STATUS_SUCCESS if the specified key is successfully set,
1361 * or an NTSTATUS error code.
1363 NTSTATUS WINAPI RtlWriteRegistryValue( ULONG RelativeTo, PCWSTR path, PCWSTR name,
1364 ULONG type, PVOID data, ULONG length )
1366 HANDLE hkey;
1367 NTSTATUS status;
1368 UNICODE_STRING str;
1370 TRACE( "(%d, %s, %s) -> %d: %p [%d]\n", RelativeTo, debugstr_w(path), debugstr_w(name),
1371 type, data, length );
1373 RtlInitUnicodeString( &str, name );
1375 if (RelativeTo == RTL_REGISTRY_HANDLE)
1376 return NtSetValueKey( (HANDLE)path, &str, 0, type, data, length );
1378 status = RTL_GetKeyHandle( RelativeTo, path, &hkey );
1379 if (status != STATUS_SUCCESS) return status;
1381 status = NtSetValueKey( hkey, &str, 0, type, data, length );
1382 NtClose( hkey );
1384 return status;