wininet: Handle NULL lpBuffersIn in HttpSendRequestExW.
[wine/multimedia.git] / dlls / ntdll / reg.c
blobd05d9c7deb9509783e49e3354d51e2bf764ae24a
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 TRACE( "(%p,%s,%s,%lx,%lx,%p)\n", attr->RootDirectory, debugstr_us(attr->ObjectName),
59 debugstr_us(class), options, access, retkey );
61 if (attr->ObjectName->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
62 if (!retkey) return STATUS_INVALID_PARAMETER;
64 SERVER_START_REQ( create_key )
66 req->parent = attr->RootDirectory;
67 req->access = access;
68 req->attributes = attr->Attributes;
69 req->options = options;
70 req->modif = 0;
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 = 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 memcpy( &oa, attr, sizeof oa );
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,%lx,%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 = 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 = 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 = 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 = 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 default:
221 FIXME( "Information class %d not implemented\n", info_class );
222 return STATUS_INVALID_PARAMETER;
224 fixed_size = (char *)data_ptr - (char *)info;
226 SERVER_START_REQ( enum_key )
228 req->hkey = handle;
229 req->index = index;
230 req->info_class = info_class;
231 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
232 if (!(ret = wine_server_call( req )))
234 LARGE_INTEGER modif;
236 RtlSecondsSince1970ToTime( reply->modif, &modif );
238 switch(info_class)
240 case KeyBasicInformation:
242 KEY_BASIC_INFORMATION keyinfo;
243 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
244 keyinfo.LastWriteTime = modif;
245 keyinfo.TitleIndex = 0;
246 keyinfo.NameLength = reply->namelen;
247 memcpy( info, &keyinfo, min( length, fixed_size ) );
249 break;
250 case KeyFullInformation:
252 KEY_FULL_INFORMATION keyinfo;
253 fixed_size = (char *)keyinfo.Class - (char *)&keyinfo;
254 keyinfo.LastWriteTime = modif;
255 keyinfo.TitleIndex = 0;
256 keyinfo.ClassLength = wine_server_reply_size(reply);
257 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size : -1;
258 keyinfo.SubKeys = reply->subkeys;
259 keyinfo.MaxNameLen = reply->max_subkey;
260 keyinfo.MaxClassLen = reply->max_class;
261 keyinfo.Values = reply->values;
262 keyinfo.MaxValueNameLen = reply->max_value;
263 keyinfo.MaxValueDataLen = reply->max_data;
264 memcpy( info, &keyinfo, min( length, fixed_size ) );
266 break;
267 case KeyNodeInformation:
269 KEY_NODE_INFORMATION keyinfo;
270 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
271 keyinfo.LastWriteTime = modif;
272 keyinfo.TitleIndex = 0;
273 keyinfo.ClassLength = max( 0, wine_server_reply_size(reply) - reply->namelen );
274 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size + reply->namelen : -1;
275 keyinfo.NameLength = reply->namelen;
276 memcpy( info, &keyinfo, min( length, fixed_size ) );
278 break;
280 *result_len = fixed_size + reply->total;
281 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
284 SERVER_END_REQ;
285 return ret;
290 /******************************************************************************
291 * NtEnumerateKey [NTDLL.@]
292 * ZwEnumerateKey [NTDLL.@]
294 * NOTES
295 * the name copied into the buffer is NOT 0-terminated
297 NTSTATUS WINAPI NtEnumerateKey( HANDLE handle, ULONG index, KEY_INFORMATION_CLASS info_class,
298 void *info, DWORD length, DWORD *result_len )
300 /* -1 means query key, so avoid it here */
301 if (index == (ULONG)-1) return STATUS_NO_MORE_ENTRIES;
302 return enumerate_key( handle, index, info_class, info, length, result_len );
306 /******************************************************************************
307 * RtlpNtEnumerateSubKey [NTDLL.@]
310 NTSTATUS WINAPI RtlpNtEnumerateSubKey( HANDLE handle, UNICODE_STRING *out, ULONG index )
312 KEY_BASIC_INFORMATION *info;
313 DWORD dwLen, dwResultLen;
314 NTSTATUS ret;
316 if (out->Length)
318 dwLen = out->Length + sizeof(KEY_BASIC_INFORMATION);
319 info = (KEY_BASIC_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
320 if (!info)
321 return STATUS_NO_MEMORY;
323 else
325 dwLen = 0;
326 info = NULL;
329 ret = NtEnumerateKey( handle, index, KeyBasicInformation, info, dwLen, &dwResultLen );
330 dwResultLen -= sizeof(KEY_BASIC_INFORMATION);
332 if (ret == STATUS_BUFFER_OVERFLOW)
333 out->Length = dwResultLen;
334 else if (!ret)
336 if (out->Length < info->NameLength)
338 out->Length = dwResultLen;
339 ret = STATUS_BUFFER_OVERFLOW;
341 else
343 out->Length = info->NameLength;
344 memcpy(out->Buffer, info->Name, info->NameLength);
348 if (info)
349 RtlFreeHeap( GetProcessHeap(), 0, info );
350 return ret;
353 /******************************************************************************
354 * NtQueryKey [NTDLL.@]
355 * ZwQueryKey [NTDLL.@]
357 NTSTATUS WINAPI NtQueryKey( HANDLE handle, KEY_INFORMATION_CLASS info_class,
358 void *info, DWORD length, DWORD *result_len )
360 return enumerate_key( handle, -1, info_class, info, length, result_len );
364 /* fill the key value info structure for a specific info class */
365 static void copy_key_value_info( KEY_VALUE_INFORMATION_CLASS info_class, void *info,
366 DWORD length, int type, int name_len, int data_len )
368 switch(info_class)
370 case KeyValueBasicInformation:
372 KEY_VALUE_BASIC_INFORMATION keyinfo;
373 keyinfo.TitleIndex = 0;
374 keyinfo.Type = type;
375 keyinfo.NameLength = name_len;
376 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
377 memcpy( info, &keyinfo, length );
378 break;
380 case KeyValueFullInformation:
382 KEY_VALUE_FULL_INFORMATION keyinfo;
383 keyinfo.TitleIndex = 0;
384 keyinfo.Type = type;
385 keyinfo.DataOffset = (char *)keyinfo.Name - (char *)&keyinfo + name_len;
386 keyinfo.DataLength = data_len;
387 keyinfo.NameLength = name_len;
388 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
389 memcpy( info, &keyinfo, length );
390 break;
392 case KeyValuePartialInformation:
394 KEY_VALUE_PARTIAL_INFORMATION keyinfo;
395 keyinfo.TitleIndex = 0;
396 keyinfo.Type = type;
397 keyinfo.DataLength = data_len;
398 length = min( length, (char *)keyinfo.Data - (char *)&keyinfo );
399 memcpy( info, &keyinfo, length );
400 break;
402 default:
403 break;
408 /******************************************************************************
409 * NtEnumerateValueKey [NTDLL.@]
410 * ZwEnumerateValueKey [NTDLL.@]
412 NTSTATUS WINAPI NtEnumerateValueKey( HANDLE handle, ULONG index,
413 KEY_VALUE_INFORMATION_CLASS info_class,
414 void *info, DWORD length, DWORD *result_len )
416 NTSTATUS ret;
417 void *ptr;
418 size_t fixed_size;
420 TRACE( "(%p,%lu,%d,%p,%ld)\n", handle, index, info_class, info, length );
422 /* compute the length we want to retrieve */
423 switch(info_class)
425 case KeyValueBasicInformation: ptr = ((KEY_VALUE_BASIC_INFORMATION *)info)->Name; break;
426 case KeyValueFullInformation: ptr = ((KEY_VALUE_FULL_INFORMATION *)info)->Name; break;
427 case KeyValuePartialInformation: ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data; break;
428 default:
429 FIXME( "Information class %d not implemented\n", info_class );
430 return STATUS_INVALID_PARAMETER;
432 fixed_size = (char *)ptr - (char *)info;
434 SERVER_START_REQ( enum_key_value )
436 req->hkey = handle;
437 req->index = index;
438 req->info_class = info_class;
439 if (length > fixed_size) wine_server_set_reply( req, ptr, length - fixed_size );
440 if (!(ret = wine_server_call( req )))
442 copy_key_value_info( info_class, info, length, reply->type, reply->namelen,
443 wine_server_reply_size(reply) - reply->namelen );
444 *result_len = fixed_size + reply->total;
445 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
448 SERVER_END_REQ;
449 return ret;
453 /******************************************************************************
454 * NtQueryValueKey [NTDLL.@]
455 * ZwQueryValueKey [NTDLL.@]
457 * NOTES
458 * the name in the KeyValueInformation is never set
460 NTSTATUS WINAPI NtQueryValueKey( HANDLE handle, const UNICODE_STRING *name,
461 KEY_VALUE_INFORMATION_CLASS info_class,
462 void *info, DWORD length, DWORD *result_len )
464 NTSTATUS ret;
465 UCHAR *data_ptr;
466 unsigned int fixed_size = 0;
468 TRACE( "(%p,%s,%d,%p,%ld)\n", handle, debugstr_us(name), info_class, info, length );
470 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
472 /* compute the length we want to retrieve */
473 switch(info_class)
475 case KeyValueBasicInformation:
476 fixed_size = (char *)((KEY_VALUE_BASIC_INFORMATION *)info)->Name - (char *)info;
477 data_ptr = NULL;
478 break;
479 case KeyValueFullInformation:
480 data_ptr = (UCHAR *)((KEY_VALUE_FULL_INFORMATION *)info)->Name;
481 fixed_size = (char *)data_ptr - (char *)info;
482 break;
483 case KeyValuePartialInformation:
484 data_ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data;
485 fixed_size = (char *)data_ptr - (char *)info;
486 break;
487 default:
488 FIXME( "Information class %d not implemented\n", info_class );
489 return STATUS_INVALID_PARAMETER;
492 SERVER_START_REQ( get_key_value )
494 req->hkey = handle;
495 wine_server_add_data( req, name->Buffer, name->Length );
496 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
497 if (!(ret = wine_server_call( req )))
499 copy_key_value_info( info_class, info, length, reply->type,
500 0, wine_server_reply_size(reply) );
501 *result_len = fixed_size + reply->total;
502 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
505 SERVER_END_REQ;
506 return ret;
509 /******************************************************************************
510 * RtlpNtQueryValueKey [NTDLL.@]
513 NTSTATUS WINAPI RtlpNtQueryValueKey( HANDLE handle, ULONG *result_type, PBYTE dest,
514 DWORD *result_len )
516 KEY_VALUE_PARTIAL_INFORMATION *info;
517 UNICODE_STRING name;
518 NTSTATUS ret;
519 DWORD dwResultLen;
520 DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + result_len ? *result_len : 0;
522 info = (KEY_VALUE_PARTIAL_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
523 if (!info)
524 return STATUS_NO_MEMORY;
526 name.Length = 0;
527 ret = NtQueryValueKey( handle, &name, KeyValuePartialInformation, info, dwLen, &dwResultLen );
529 if (!ret || ret == STATUS_BUFFER_OVERFLOW)
531 if (result_len)
532 *result_len = info->DataLength;
534 if (result_type)
535 *result_type = info->Type;
537 if (ret != STATUS_BUFFER_OVERFLOW)
538 memcpy( dest, info->Data, info->DataLength );
541 RtlFreeHeap( GetProcessHeap(), 0, info );
542 return ret;
545 /******************************************************************************
546 * NtFlushKey [NTDLL.@]
547 * ZwFlushKey [NTDLL.@]
549 NTSTATUS WINAPI NtFlushKey(HANDLE key)
551 NTSTATUS ret;
553 TRACE("key=%p\n", key);
555 SERVER_START_REQ( flush_key )
557 req->hkey = key;
558 ret = wine_server_call( req );
560 SERVER_END_REQ;
562 return ret;
565 /******************************************************************************
566 * NtLoadKey [NTDLL.@]
567 * ZwLoadKey [NTDLL.@]
569 NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, OBJECT_ATTRIBUTES *file )
571 NTSTATUS ret;
572 HANDLE hive;
573 IO_STATUS_BLOCK io;
575 TRACE("(%p,%p)\n", attr, file);
577 ret = NtCreateFile(&hive, GENERIC_READ, file, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
578 OPEN_EXISTING, 0, NULL, 0);
579 if (ret) return ret;
581 SERVER_START_REQ( load_registry )
583 req->hkey = attr->RootDirectory;
584 req->file = hive;
585 wine_server_add_data(req, attr->ObjectName->Buffer, attr->ObjectName->Length);
586 ret = wine_server_call( req );
588 SERVER_END_REQ;
590 NtClose(hive);
592 return ret;
595 /******************************************************************************
596 * NtNotifyChangeKey [NTDLL.@]
597 * ZwNotifyChangeKey [NTDLL.@]
599 NTSTATUS WINAPI NtNotifyChangeKey(
600 IN HANDLE KeyHandle,
601 IN HANDLE Event,
602 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
603 IN PVOID ApcContext OPTIONAL,
604 OUT PIO_STATUS_BLOCK IoStatusBlock,
605 IN ULONG CompletionFilter,
606 IN BOOLEAN Asynchronous,
607 OUT PVOID ChangeBuffer,
608 IN ULONG Length,
609 IN BOOLEAN WatchSubtree)
611 NTSTATUS ret;
613 TRACE("(%p,%p,%p,%p,%p,0x%08lx, 0x%08x,%p,0x%08lx,0x%08x)\n",
614 KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
615 Asynchronous, ChangeBuffer, Length, WatchSubtree);
617 if (ApcRoutine || ApcContext || ChangeBuffer || Length)
618 FIXME("Unimplemented optional parameter\n");
620 if (!Asynchronous)
622 OBJECT_ATTRIBUTES attr;
623 InitializeObjectAttributes( &attr, NULL, 0, NULL, NULL );
624 ret = NtCreateEvent( &Event, EVENT_ALL_ACCESS, &attr, FALSE, FALSE );
625 if (ret != STATUS_SUCCESS)
626 return ret;
629 SERVER_START_REQ( set_registry_notification )
631 req->hkey = KeyHandle;
632 req->event = Event;
633 req->subtree = WatchSubtree;
634 req->filter = CompletionFilter;
635 ret = wine_server_call( req );
637 SERVER_END_REQ;
639 if (!Asynchronous)
641 if (ret == STATUS_SUCCESS)
642 NtWaitForSingleObject( Event, FALSE, NULL );
643 NtClose( Event );
646 return STATUS_SUCCESS;
649 /******************************************************************************
650 * NtQueryMultipleValueKey [NTDLL]
651 * ZwQueryMultipleValueKey
654 NTSTATUS WINAPI NtQueryMultipleValueKey(
655 HANDLE KeyHandle,
656 PKEY_MULTIPLE_VALUE_INFORMATION ListOfValuesToQuery,
657 ULONG NumberOfItems,
658 PVOID MultipleValueInformation,
659 ULONG Length,
660 PULONG ReturnLength)
662 FIXME("(%p,%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
663 KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
664 Length,ReturnLength);
665 return STATUS_SUCCESS;
668 /******************************************************************************
669 * NtReplaceKey [NTDLL.@]
670 * ZwReplaceKey [NTDLL.@]
672 NTSTATUS WINAPI NtReplaceKey(
673 IN POBJECT_ATTRIBUTES ObjectAttributes,
674 IN HANDLE Key,
675 IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
677 FIXME("(%p),stub!\n", Key);
678 dump_ObjectAttributes(ObjectAttributes);
679 dump_ObjectAttributes(ReplacedObjectAttributes);
680 return STATUS_SUCCESS;
682 /******************************************************************************
683 * NtRestoreKey [NTDLL.@]
684 * ZwRestoreKey [NTDLL.@]
686 NTSTATUS WINAPI NtRestoreKey(
687 HANDLE KeyHandle,
688 HANDLE FileHandle,
689 ULONG RestoreFlags)
691 FIXME("(%p,%p,0x%08lx) stub\n",
692 KeyHandle, FileHandle, RestoreFlags);
693 return STATUS_SUCCESS;
695 /******************************************************************************
696 * NtSaveKey [NTDLL.@]
697 * ZwSaveKey [NTDLL.@]
699 NTSTATUS WINAPI NtSaveKey(IN HANDLE KeyHandle, IN HANDLE FileHandle)
701 NTSTATUS ret;
703 TRACE("(%p,%p)\n", KeyHandle, FileHandle);
705 SERVER_START_REQ( save_registry )
707 req->hkey = KeyHandle;
708 req->file = FileHandle;
709 ret = wine_server_call( req );
711 SERVER_END_REQ;
713 return ret;
715 /******************************************************************************
716 * NtSetInformationKey [NTDLL.@]
717 * ZwSetInformationKey [NTDLL.@]
719 NTSTATUS WINAPI NtSetInformationKey(
720 IN HANDLE KeyHandle,
721 IN const int KeyInformationClass,
722 IN PVOID KeyInformation,
723 IN ULONG KeyInformationLength)
725 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
726 KeyHandle, KeyInformationClass, KeyInformation, KeyInformationLength);
727 return STATUS_SUCCESS;
731 /******************************************************************************
732 * NtSetValueKey [NTDLL.@]
733 * ZwSetValueKey [NTDLL.@]
735 * NOTES
736 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
737 * NT does definitely care (aj)
739 NTSTATUS WINAPI NtSetValueKey( HANDLE hkey, const UNICODE_STRING *name, ULONG TitleIndex,
740 ULONG type, const void *data, ULONG count )
742 NTSTATUS ret;
744 TRACE( "(%p,%s,%ld,%p,%ld)\n", hkey, debugstr_us(name), type, data, count );
746 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
748 SERVER_START_REQ( set_key_value )
750 req->hkey = hkey;
751 req->type = type;
752 req->namelen = name->Length;
753 wine_server_add_data( req, name->Buffer, name->Length );
754 wine_server_add_data( req, data, count );
755 ret = wine_server_call( req );
757 SERVER_END_REQ;
758 return ret;
761 /******************************************************************************
762 * RtlpNtSetValueKey [NTDLL.@]
765 NTSTATUS WINAPI RtlpNtSetValueKey( HANDLE hkey, ULONG type, const void *data,
766 ULONG count )
768 UNICODE_STRING name;
770 name.Length = 0;
771 return NtSetValueKey( hkey, &name, 0, type, data, count );
774 /******************************************************************************
775 * NtUnloadKey [NTDLL.@]
776 * ZwUnloadKey [NTDLL.@]
778 NTSTATUS WINAPI NtUnloadKey(IN HANDLE KeyHandle)
780 NTSTATUS ret;
782 TRACE("(%p)\n", KeyHandle);
784 SERVER_START_REQ( unload_registry )
786 req->hkey = KeyHandle;
787 ret = wine_server_call(req);
789 SERVER_END_REQ;
791 return ret;
794 /******************************************************************************
795 * RtlFormatCurrentUserKeyPath [NTDLL.@]
798 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
800 static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
801 HANDLE token;
802 NTSTATUS status;
804 status = NtOpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token);
805 if (status == STATUS_NO_TOKEN)
806 status = NtOpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token);
807 if (status == STATUS_SUCCESS)
809 char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
810 DWORD len = sizeof(buffer);
812 status = NtQueryInformationToken(token, TokenUser, buffer, len, &len);
813 if (status == STATUS_SUCCESS)
815 KeyPath->MaximumLength = 0;
816 status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
817 if (status == STATUS_BUFFER_OVERFLOW)
819 PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
820 sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
821 if (buf)
823 memcpy(buf, pathW, sizeof(pathW));
824 KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
825 KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
826 status = RtlConvertSidToUnicodeString(KeyPath,
827 ((TOKEN_USER *)buffer)->User.Sid, FALSE);
828 KeyPath->Buffer = (PWCHAR)buf;
829 KeyPath->Length += sizeof(pathW);
830 KeyPath->MaximumLength += sizeof(pathW);
832 else
833 status = STATUS_NO_MEMORY;
836 NtClose(token);
838 return status;
841 /******************************************************************************
842 * RtlOpenCurrentUser [NTDLL.@]
844 * NOTES
845 * If we return just HKEY_CURRENT_USER the advapi tries to find a remote
846 * registry (odd handle) and fails.
848 NTSTATUS WINAPI RtlOpenCurrentUser(
849 IN ACCESS_MASK DesiredAccess, /* [in] */
850 OUT PHANDLE KeyHandle) /* [out] handle of HKEY_CURRENT_USER */
852 OBJECT_ATTRIBUTES ObjectAttributes;
853 UNICODE_STRING ObjectName;
854 NTSTATUS ret;
856 TRACE("(0x%08lx, %p)\n",DesiredAccess, KeyHandle);
858 if ((ret = RtlFormatCurrentUserKeyPath(&ObjectName))) return ret;
859 InitializeObjectAttributes(&ObjectAttributes,&ObjectName,OBJ_CASE_INSENSITIVE,0, NULL);
860 ret = NtCreateKey(KeyHandle, DesiredAccess, &ObjectAttributes, 0, NULL, 0, NULL);
861 RtlFreeUnicodeString(&ObjectName);
862 return ret;
866 static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo,
867 PRTL_QUERY_REGISTRY_TABLE pQuery, PVOID pContext, PVOID pEnvironment)
869 PUNICODE_STRING str;
870 UNICODE_STRING src, dst;
871 LONG *bin;
872 ULONG offset;
873 PWSTR wstr;
874 DWORD res;
875 NTSTATUS status = STATUS_SUCCESS;
876 ULONG len;
877 LPWSTR String;
878 INT count = 0;
880 if (pInfo == NULL)
882 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
883 return STATUS_INVALID_PARAMETER;
884 else
886 status = pQuery->QueryRoutine(pQuery->Name, pQuery->DefaultType, pQuery->DefaultData,
887 pQuery->DefaultLength, pContext, pQuery->EntryContext);
889 return status;
891 len = pInfo->DataLength;
893 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
895 str = (PUNICODE_STRING)pQuery->EntryContext;
897 switch(pInfo->Type)
899 case REG_EXPAND_SZ:
900 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
902 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
903 res = 0;
904 dst.MaximumLength = 0;
905 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
906 dst.Length = 0;
907 dst.MaximumLength = res;
908 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
909 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
910 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
911 dst.Length, pContext, pQuery->EntryContext);
912 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
915 case REG_SZ:
916 case REG_LINK:
917 if (str->Buffer == NULL)
918 RtlCreateUnicodeString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
919 else
920 RtlAppendUnicodeToString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
921 break;
923 case REG_MULTI_SZ:
924 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
925 return STATUS_INVALID_PARAMETER;
927 if (str->Buffer == NULL)
929 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
930 str->MaximumLength = len;
932 len = min(len, str->MaximumLength);
933 memcpy(str->Buffer, ((CHAR*)pInfo) + pInfo->DataOffset, len);
934 str->Length = len;
935 break;
937 default:
938 bin = (LONG*)pQuery->EntryContext;
939 if (pInfo->DataLength <= sizeof(ULONG))
940 memcpy(bin, ((CHAR*)pInfo) + pInfo->DataOffset,
941 pInfo->DataLength);
942 else
944 if (bin[0] <= sizeof(ULONG))
946 memcpy(&bin[1], ((CHAR*)pInfo) + pInfo->DataOffset,
947 min(-bin[0], pInfo->DataLength));
949 else
951 len = min(bin[0], pInfo->DataLength);
952 bin[1] = len;
953 bin[2] = pInfo->Type;
954 memcpy(&bin[3], ((CHAR*)pInfo) + pInfo->DataOffset, len);
957 break;
960 else
962 if((pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND) ||
963 (pInfo->Type != REG_EXPAND_SZ && pInfo->Type != REG_MULTI_SZ))
965 status = pQuery->QueryRoutine(pInfo->Name, pInfo->Type,
966 ((CHAR*)pInfo) + pInfo->DataOffset, pInfo->DataLength,
967 pContext, pQuery->EntryContext);
969 else if (pInfo->Type == REG_EXPAND_SZ)
971 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
972 res = 0;
973 dst.MaximumLength = 0;
974 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
975 dst.Length = 0;
976 dst.MaximumLength = res;
977 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
978 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
979 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
980 dst.Length, pContext, pQuery->EntryContext);
981 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
983 else /* REG_MULTI_SZ */
985 if(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND)
987 for (offset = 0; offset <= pInfo->DataLength; offset += len + sizeof(WCHAR))
989 wstr = (WCHAR*)(((CHAR*)pInfo) + offset);
990 len = strlenW(wstr) * sizeof(WCHAR);
991 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, wstr, len,
992 pContext, pQuery->EntryContext);
993 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
994 return status;
997 else
999 while(count<=pInfo->DataLength)
1001 String = (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset)+count;
1002 count+=strlenW(String)+1;
1003 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
1004 res = 0;
1005 dst.MaximumLength = 0;
1006 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1007 dst.Length = 0;
1008 dst.MaximumLength = res;
1009 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
1010 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1011 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
1012 dst.Length, pContext, pQuery->EntryContext);
1013 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
1014 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1015 return status;
1020 return status;
1024 static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHANDLE handle)
1026 UNICODE_STRING KeyString;
1027 OBJECT_ATTRIBUTES regkey;
1028 PCWSTR base;
1029 INT len;
1030 NTSTATUS status;
1032 static const WCHAR empty[] = {0};
1033 static const WCHAR control[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e',
1034 '\\','S','y','s','t','e','m','\\','C','u','r','r','e','n','t',' ','C','o','n','t','r','o','l','S','e','t','\\',
1035 'C','o','n','t','r','o','l','\\',0};
1037 static const WCHAR devicemap[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1038 'H','a','r','d','w','a','r','e','\\','D','e','v','i','c','e','M','a','p','\\',0};
1040 static const WCHAR services[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1041 'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1042 'S','e','r','v','i','c','e','s','\\',0};
1044 static const WCHAR user[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\',
1045 'C','u','r','r','e','n','t','U','s','e','r','\\',0};
1047 static const WCHAR windows_nt[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1048 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1049 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',0};
1051 switch (RelativeTo & 0xff)
1053 case RTL_REGISTRY_ABSOLUTE:
1054 base = empty;
1055 break;
1057 case RTL_REGISTRY_CONTROL:
1058 base = control;
1059 break;
1061 case RTL_REGISTRY_DEVICEMAP:
1062 base = devicemap;
1063 break;
1065 case RTL_REGISTRY_SERVICES:
1066 base = services;
1067 break;
1069 case RTL_REGISTRY_USER:
1070 base = user;
1071 break;
1073 case RTL_REGISTRY_WINDOWS_NT:
1074 base = windows_nt;
1075 break;
1077 default:
1078 return STATUS_INVALID_PARAMETER;
1081 len = (strlenW(base) + strlenW(Path) + 1) * sizeof(WCHAR);
1082 KeyString.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
1083 if (KeyString.Buffer == NULL)
1084 return STATUS_NO_MEMORY;
1086 strcpyW(KeyString.Buffer, base);
1087 strcatW(KeyString.Buffer, Path);
1088 KeyString.Length = len - sizeof(WCHAR);
1089 KeyString.MaximumLength = len;
1090 InitializeObjectAttributes(&regkey, &KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL);
1091 status = NtOpenKey(handle, KEY_ALL_ACCESS, &regkey);
1092 RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer);
1093 return status;
1096 /*************************************************************************
1097 * RtlQueryRegistryValues [NTDLL.@]
1099 * Query multiple registry values with a signle call.
1101 * PARAMS
1102 * RelativeTo [I] Registry path that Path refers to
1103 * Path [I] Path to key
1104 * QueryTable [I] Table of key values to query
1105 * Context [I] Paremeter to pass to the application defined QueryRoutine function
1106 * Environment [I] Optional parameter to use when performing expantion
1108 * RETURNS
1109 * STATUS_SUCCESS or an appropriate NTSTATUS error code.
1111 NTSTATUS WINAPI RtlQueryRegistryValues(IN ULONG RelativeTo, IN PCWSTR Path,
1112 IN PRTL_QUERY_REGISTRY_TABLE QueryTable, IN PVOID Context,
1113 IN PVOID Environment OPTIONAL)
1115 UNICODE_STRING Value;
1116 HANDLE handle, topkey;
1117 PKEY_VALUE_FULL_INFORMATION pInfo = NULL;
1118 ULONG len, buflen = 0;
1119 NTSTATUS status=STATUS_SUCCESS, ret = STATUS_SUCCESS;
1120 INT i;
1122 TRACE("(%ld, %s, %p, %p, %p)\n", RelativeTo, debugstr_w(Path), QueryTable, Context, Environment);
1124 if(Path == NULL)
1125 return STATUS_INVALID_PARAMETER;
1127 /* get a valid handle */
1128 if (RelativeTo & RTL_REGISTRY_HANDLE)
1129 topkey = handle = (HANDLE)Path;
1130 else
1132 status = RTL_GetKeyHandle(RelativeTo, Path, &topkey);
1133 handle = topkey;
1135 if(status != STATUS_SUCCESS)
1136 return status;
1138 /* Process query table entries */
1139 for (; QueryTable->QueryRoutine != NULL || QueryTable->Name != NULL; ++QueryTable)
1141 if (QueryTable->Flags &
1142 (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY))
1144 /* topkey must be kept open just in case we will reuse it later */
1145 if (handle != topkey)
1146 NtClose(handle);
1148 if (QueryTable->Flags & RTL_QUERY_REGISTRY_SUBKEY)
1150 handle = 0;
1151 status = RTL_GetKeyHandle((ULONG)QueryTable->Name, Path, &handle);
1152 if(status != STATUS_SUCCESS)
1154 ret = status;
1155 goto out;
1158 else
1159 handle = topkey;
1162 if (QueryTable->Flags & RTL_QUERY_REGISTRY_NOVALUE)
1164 QueryTable->QueryRoutine(QueryTable->Name, REG_NONE, NULL, 0,
1165 Context, QueryTable->EntryContext);
1166 continue;
1169 if (!handle)
1171 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1173 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1174 goto out;
1176 continue;
1179 if (QueryTable->Name == NULL)
1181 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT)
1183 ret = STATUS_INVALID_PARAMETER;
1184 goto out;
1187 /* Report all subkeys */
1188 for (i = 0;; ++i)
1190 status = NtEnumerateValueKey(handle, i,
1191 KeyValueFullInformation, pInfo, buflen, &len);
1192 if (status == STATUS_NO_MORE_ENTRIES)
1193 break;
1194 if (status == STATUS_BUFFER_OVERFLOW ||
1195 status == STATUS_BUFFER_TOO_SMALL)
1197 buflen = len;
1198 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1199 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1200 GetProcessHeap(), 0, buflen);
1201 NtEnumerateValueKey(handle, i, KeyValueFullInformation,
1202 pInfo, buflen, &len);
1205 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1206 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1208 ret = status;
1209 goto out;
1211 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1213 RtlInitUnicodeString(&Value, pInfo->Name);
1214 NtDeleteValueKey(handle, &Value);
1218 if (i == 0 && (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED))
1220 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1221 goto out;
1224 else
1226 RtlInitUnicodeString(&Value, QueryTable->Name);
1227 status = NtQueryValueKey(handle, &Value, KeyValueFullInformation,
1228 pInfo, buflen, &len);
1229 if (status == STATUS_BUFFER_OVERFLOW ||
1230 status == STATUS_BUFFER_TOO_SMALL)
1232 buflen = len;
1233 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1234 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1235 GetProcessHeap(), 0, buflen);
1236 status = NtQueryValueKey(handle, &Value,
1237 KeyValueFullInformation, pInfo, buflen, &len);
1239 if (status != STATUS_SUCCESS)
1241 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1243 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1244 goto out;
1246 status = RTL_ReportRegistryValue(NULL, QueryTable, Context, Environment);
1247 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1249 ret = status;
1250 goto out;
1253 else
1255 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1256 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1258 ret = status;
1259 goto out;
1261 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1262 NtDeleteValueKey(handle, &Value);
1267 out:
1268 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1269 if (handle != topkey)
1270 NtClose(handle);
1271 NtClose(topkey);
1272 return ret;
1275 /*************************************************************************
1276 * RtlCheckRegistryKey [NTDLL.@]
1278 * Query multiple registry values with a signle call.
1280 * PARAMS
1281 * RelativeTo [I] Registry path that Path refers to
1282 * Path [I] Path to key
1284 * RETURNS
1285 * STATUS_SUCCESS if the specified key exists, or an NTSTATUS error code.
1287 NTSTATUS WINAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
1289 HANDLE handle;
1290 NTSTATUS status;
1292 TRACE("(%ld, %s)\n", RelativeTo, debugstr_w(Path));
1294 if((!RelativeTo) && Path == NULL)
1295 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1296 if(RelativeTo & RTL_REGISTRY_HANDLE)
1297 return STATUS_SUCCESS;
1299 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1300 if (handle) NtClose(handle);
1301 if (status == STATUS_INVALID_HANDLE) status = STATUS_OBJECT_NAME_NOT_FOUND;
1302 return status;
1305 /*************************************************************************
1306 * RtlDeleteRegistryValue [NTDLL.@]
1308 * Query multiple registry values with a signle call.
1310 * PARAMS
1311 * RelativeTo [I] Registry path that Path refers to
1312 * Path [I] Path to key
1313 * ValueName [I] Name of the value to delete
1315 * RETURNS
1316 * STATUS_SUCCESS if the specified key is successfully deleted, or an NTSTATUS error code.
1318 NTSTATUS WINAPI RtlDeleteRegistryValue(IN ULONG RelativeTo, IN PCWSTR Path, IN PCWSTR ValueName)
1320 NTSTATUS status;
1321 HANDLE handle;
1322 UNICODE_STRING Value;
1324 TRACE("(%ld, %s, %s)\n", RelativeTo, debugstr_w(Path), debugstr_w(ValueName));
1326 RtlInitUnicodeString(&Value, ValueName);
1327 if(RelativeTo == RTL_REGISTRY_HANDLE)
1329 return NtDeleteValueKey((HANDLE)Path, &Value);
1331 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1332 if (status) return status;
1333 status = NtDeleteValueKey(handle, &Value);
1334 NtClose(handle);
1335 return status;