Added support for ANAT (Anadyr Standard Time) to TZ_INFO.
[wine] / dlls / ntdll / reg.c
1 /*
2  * Registry functions
3  *
4  * Copyright (C) 1999 Juergen Schmied
5  * Copyright (C) 2000 Alexandre Julliard
6  * Copyright 2005 Ivan Leo Puoti, Laurent Pinchart
7  *
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.
12  *
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.
17  *
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
21  *
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
27  */
28
29 #include "config.h"
30 #include "wine/port.h"
31
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <string.h>
35
36 #include "winerror.h"
37 #include "wine/library.h"
38 #include "winreg.h"
39 #include "ntdll_misc.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(reg);
44
45 /* maximum length of a key/value name in bytes (without terminating null) */
46 #define MAX_NAME_LENGTH ((MAX_PATH-1) * sizeof(WCHAR))
47
48 /******************************************************************************
49  * NtCreateKey [NTDLL.@]
50  * ZwCreateKey [NTDLL.@]
51  */
52 NTSTATUS WINAPI NtCreateKey( PHKEY retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
53                              ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
54                              PULONG dispos )
55 {
56     NTSTATUS ret;
57
58     TRACE( "(%p,%s,%s,%lx,%lx,%p)\n", attr->RootDirectory, debugstr_us(attr->ObjectName),
59            debugstr_us(class), options, access, retkey );
60
61     if (attr->ObjectName->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
62     if (!retkey) return STATUS_INVALID_PARAMETER;
63
64     SERVER_START_REQ( create_key )
65     {
66         req->parent  = attr->RootDirectory;
67         req->access  = access;
68         req->options = options;
69         req->modif   = 0;
70         req->namelen = attr->ObjectName->Length;
71         wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
72         if (class) wine_server_add_data( req, class->Buffer, class->Length );
73         if (!(ret = wine_server_call( req )))
74         {
75             *retkey = reply->hkey;
76             if (dispos) *dispos = reply->created ? REG_CREATED_NEW_KEY : REG_OPENED_EXISTING_KEY;
77         }
78     }
79     SERVER_END_REQ;
80     TRACE("<- %p\n", *retkey);
81     return ret;
82 }
83
84 /******************************************************************************
85  *  RtlpNtCreateKey [NTDLL.@]
86  *
87  *  See NtCreateKey.
88  */
89 NTSTATUS WINAPI RtlpNtCreateKey( PHKEY retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr,
90                                  ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
91                                  PULONG dispos )
92 {
93     if (attr)
94         attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
95
96     return NtCreateKey(retkey, access, attr, 0, NULL, 0, dispos);
97 }
98
99 /******************************************************************************
100  * NtOpenKey [NTDLL.@]
101  * ZwOpenKey [NTDLL.@]
102  *
103  *   OUT        PHKEY                   retkey (returns 0 when failure)
104  *   IN         ACCESS_MASK             access
105  *   IN         POBJECT_ATTRIBUTES      attr
106  */
107 NTSTATUS WINAPI NtOpenKey( PHKEY retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
108 {
109     NTSTATUS ret;
110     DWORD len = attr->ObjectName->Length;
111
112     TRACE( "(%p,%s,%lx,%p)\n", attr->RootDirectory,
113            debugstr_us(attr->ObjectName), access, retkey );
114
115     if (len > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
116     if (!retkey) return STATUS_INVALID_PARAMETER;
117
118     SERVER_START_REQ( open_key )
119     {
120         req->parent = attr->RootDirectory;
121         req->access = access;
122         wine_server_add_data( req, attr->ObjectName->Buffer, len );
123         ret = wine_server_call( req );
124         *retkey = reply->hkey;
125     }
126     SERVER_END_REQ;
127     TRACE("<- %p\n", *retkey);
128     return ret;
129 }
130
131 /******************************************************************************
132  * RtlpNtOpenKey [NTDLL.@]
133  *
134  * See NtOpenKey.
135  */
136 NTSTATUS WINAPI RtlpNtOpenKey( PHKEY retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr )
137 {
138     if (attr)
139         attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
140     return NtOpenKey(retkey, access, attr);
141 }
142
143 /******************************************************************************
144  * NtDeleteKey [NTDLL.@]
145  * ZwDeleteKey [NTDLL.@]
146  */
147 NTSTATUS WINAPI NtDeleteKey( HKEY hkey )
148 {
149     NTSTATUS ret;
150
151     TRACE( "(%p)\n", hkey );
152
153     SERVER_START_REQ( delete_key )
154     {
155         req->hkey = hkey;
156         ret = wine_server_call( req );
157     }
158     SERVER_END_REQ;
159     return ret;
160 }
161
162 /******************************************************************************
163  * RtlpNtMakeTemporaryKey [NTDLL.@]
164  *
165  *  See NtDeleteKey.
166  */
167 NTSTATUS WINAPI RtlpNtMakeTemporaryKey( HKEY hkey )
168 {
169     return NtDeleteKey(hkey);
170 }
171
172 /******************************************************************************
173  * NtDeleteValueKey [NTDLL.@]
174  * ZwDeleteValueKey [NTDLL.@]
175  */
176 NTSTATUS WINAPI NtDeleteValueKey( HKEY hkey, const UNICODE_STRING *name )
177 {
178     NTSTATUS ret;
179
180     TRACE( "(%p,%s)\n", hkey, debugstr_us(name) );
181     if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
182
183     SERVER_START_REQ( delete_key_value )
184     {
185         req->hkey = hkey;
186         wine_server_add_data( req, name->Buffer, name->Length );
187         ret = wine_server_call( req );
188     }
189     SERVER_END_REQ;
190     return ret;
191 }
192
193
194 /******************************************************************************
195  *     enumerate_key
196  *
197  * Implementation of NtQueryKey and NtEnumerateKey
198  */
199 static NTSTATUS enumerate_key( HKEY handle, int index, KEY_INFORMATION_CLASS info_class,
200                                void *info, DWORD length, DWORD *result_len )
201
202 {
203     NTSTATUS ret;
204     void *data_ptr;
205     size_t fixed_size;
206
207     switch(info_class)
208     {
209     case KeyBasicInformation: data_ptr = ((KEY_BASIC_INFORMATION *)info)->Name; break;
210     case KeyFullInformation:  data_ptr = ((KEY_FULL_INFORMATION *)info)->Class; break;
211     case KeyNodeInformation:  data_ptr = ((KEY_NODE_INFORMATION *)info)->Name;  break;
212     default:
213         FIXME( "Information class %d not implemented\n", info_class );
214         return STATUS_INVALID_PARAMETER;
215     }
216     fixed_size = (char *)data_ptr - (char *)info;
217
218     SERVER_START_REQ( enum_key )
219     {
220         req->hkey       = handle;
221         req->index      = index;
222         req->info_class = info_class;
223         if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
224         if (!(ret = wine_server_call( req )))
225         {
226             LARGE_INTEGER modif;
227
228             RtlSecondsSince1970ToTime( reply->modif, &modif );
229
230             switch(info_class)
231             {
232             case KeyBasicInformation:
233                 {
234                     KEY_BASIC_INFORMATION keyinfo;
235                     fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
236                     keyinfo.LastWriteTime = modif;
237                     keyinfo.TitleIndex = 0;
238                     keyinfo.NameLength = reply->namelen;
239                     memcpy( info, &keyinfo, min( length, fixed_size ) );
240                 }
241                 break;
242             case KeyFullInformation:
243                 {
244                     KEY_FULL_INFORMATION keyinfo;
245                     fixed_size = (char *)keyinfo.Class - (char *)&keyinfo;
246                     keyinfo.LastWriteTime = modif;
247                     keyinfo.TitleIndex = 0;
248                     keyinfo.ClassLength = wine_server_reply_size(reply);
249                     keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size : -1;
250                     keyinfo.SubKeys = reply->subkeys;
251                     keyinfo.MaxNameLen = reply->max_subkey;
252                     keyinfo.MaxClassLen = reply->max_class;
253                     keyinfo.Values = reply->values;
254                     keyinfo.MaxValueNameLen = reply->max_value;
255                     keyinfo.MaxValueDataLen = reply->max_data;
256                     memcpy( info, &keyinfo, min( length, fixed_size ) );
257                 }
258                 break;
259             case KeyNodeInformation:
260                 {
261                     KEY_NODE_INFORMATION keyinfo;
262                     fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
263                     keyinfo.LastWriteTime = modif;
264                     keyinfo.TitleIndex = 0;
265                     keyinfo.ClassLength = max( 0, wine_server_reply_size(reply) - reply->namelen );
266                     keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size + reply->namelen : -1;
267                     keyinfo.NameLength = reply->namelen;
268                     memcpy( info, &keyinfo, min( length, fixed_size ) );
269                 }
270                 break;
271             }
272             *result_len = fixed_size + reply->total;
273             if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
274         }
275     }
276     SERVER_END_REQ;
277     return ret;
278 }
279
280
281
282 /******************************************************************************
283  * NtEnumerateKey [NTDLL.@]
284  * ZwEnumerateKey [NTDLL.@]
285  *
286  * NOTES
287  *  the name copied into the buffer is NOT 0-terminated
288  */
289 NTSTATUS WINAPI NtEnumerateKey( HKEY handle, ULONG index, KEY_INFORMATION_CLASS info_class,
290                                 void *info, DWORD length, DWORD *result_len )
291 {
292     /* -1 means query key, so avoid it here */
293     if (index == (ULONG)-1) return STATUS_NO_MORE_ENTRIES;
294     return enumerate_key( handle, index, info_class, info, length, result_len );
295 }
296
297
298 /******************************************************************************
299  * RtlpNtEnumerateSubKey [NTDLL.@]
300  *
301  */
302 NTSTATUS WINAPI RtlpNtEnumerateSubKey( HKEY handle, UNICODE_STRING *out, ULONG index )
303 {
304   KEY_BASIC_INFORMATION *info;
305   DWORD dwLen, dwResultLen;
306   NTSTATUS ret;
307
308   if (out->Length)
309   {
310     dwLen = out->Length + sizeof(KEY_BASIC_INFORMATION);
311     info = (KEY_BASIC_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
312     if (!info)
313       return STATUS_NO_MEMORY;
314   }
315   else
316   {
317     dwLen = 0;
318     info = NULL;
319   }
320
321   ret = NtEnumerateKey( handle, index, KeyBasicInformation, info, dwLen, &dwResultLen );
322   dwResultLen -= sizeof(KEY_BASIC_INFORMATION);
323
324   if (ret == STATUS_BUFFER_OVERFLOW)
325     out->Length = dwResultLen;
326   else if (!ret)
327   {
328     if (out->Length < info->NameLength)
329     {
330       out->Length = dwResultLen;
331       ret = STATUS_BUFFER_OVERFLOW;
332     }
333     else
334     {
335       out->Length = info->NameLength;
336       memcpy(out->Buffer, info->Name, info->NameLength);
337     }
338   }
339
340   if (info)
341     RtlFreeHeap( GetProcessHeap(), 0, info );
342   return ret;
343 }
344
345 /******************************************************************************
346  * NtQueryKey [NTDLL.@]
347  * ZwQueryKey [NTDLL.@]
348  */
349 NTSTATUS WINAPI NtQueryKey( HKEY handle, KEY_INFORMATION_CLASS info_class,
350                             void *info, DWORD length, DWORD *result_len )
351 {
352     return enumerate_key( handle, -1, info_class, info, length, result_len );
353 }
354
355
356 /* fill the key value info structure for a specific info class */
357 static void copy_key_value_info( KEY_VALUE_INFORMATION_CLASS info_class, void *info,
358                                  DWORD length, int type, int name_len, int data_len )
359 {
360     switch(info_class)
361     {
362     case KeyValueBasicInformation:
363         {
364             KEY_VALUE_BASIC_INFORMATION keyinfo;
365             keyinfo.TitleIndex = 0;
366             keyinfo.Type       = type;
367             keyinfo.NameLength = name_len;
368             length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
369             memcpy( info, &keyinfo, length );
370             break;
371         }
372     case KeyValueFullInformation:
373         {
374             KEY_VALUE_FULL_INFORMATION keyinfo;
375             keyinfo.TitleIndex = 0;
376             keyinfo.Type       = type;
377             keyinfo.DataOffset = (char *)keyinfo.Name - (char *)&keyinfo + name_len;
378             keyinfo.DataLength = data_len;
379             keyinfo.NameLength = name_len;
380             length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
381             memcpy( info, &keyinfo, length );
382             break;
383         }
384     case KeyValuePartialInformation:
385         {
386             KEY_VALUE_PARTIAL_INFORMATION keyinfo;
387             keyinfo.TitleIndex = 0;
388             keyinfo.Type       = type;
389             keyinfo.DataLength = data_len;
390             length = min( length, (char *)keyinfo.Data - (char *)&keyinfo );
391             memcpy( info, &keyinfo, length );
392             break;
393         }
394     default:
395         break;
396     }
397 }
398
399
400 /******************************************************************************
401  *  NtEnumerateValueKey [NTDLL.@]
402  *  ZwEnumerateValueKey [NTDLL.@]
403  */
404 NTSTATUS WINAPI NtEnumerateValueKey( HKEY handle, ULONG index,
405                                      KEY_VALUE_INFORMATION_CLASS info_class,
406                                      void *info, DWORD length, DWORD *result_len )
407 {
408     NTSTATUS ret;
409     void *ptr;
410     size_t fixed_size;
411
412     TRACE( "(%p,%lu,%d,%p,%ld)\n", handle, index, info_class, info, length );
413
414     /* compute the length we want to retrieve */
415     switch(info_class)
416     {
417     case KeyValueBasicInformation:   ptr = ((KEY_VALUE_BASIC_INFORMATION *)info)->Name; break;
418     case KeyValueFullInformation:    ptr = ((KEY_VALUE_FULL_INFORMATION *)info)->Name; break;
419     case KeyValuePartialInformation: ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data; break;
420     default:
421         FIXME( "Information class %d not implemented\n", info_class );
422         return STATUS_INVALID_PARAMETER;
423     }
424     fixed_size = (char *)ptr - (char *)info;
425
426     SERVER_START_REQ( enum_key_value )
427     {
428         req->hkey       = handle;
429         req->index      = index;
430         req->info_class = info_class;
431         if (length > fixed_size) wine_server_set_reply( req, ptr, length - fixed_size );
432         if (!(ret = wine_server_call( req )))
433         {
434             copy_key_value_info( info_class, info, length, reply->type, reply->namelen,
435                                  wine_server_reply_size(reply) - reply->namelen );
436             *result_len = fixed_size + reply->total;
437             if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
438         }
439     }
440     SERVER_END_REQ;
441     return ret;
442 }
443
444
445 /******************************************************************************
446  * NtQueryValueKey [NTDLL.@]
447  * ZwQueryValueKey [NTDLL.@]
448  *
449  * NOTES
450  *  the name in the KeyValueInformation is never set
451  */
452 NTSTATUS WINAPI NtQueryValueKey( HKEY handle, const UNICODE_STRING *name,
453                                  KEY_VALUE_INFORMATION_CLASS info_class,
454                                  void *info, DWORD length, DWORD *result_len )
455 {
456     NTSTATUS ret;
457     UCHAR *data_ptr;
458     unsigned int fixed_size = 0;
459
460     TRACE( "(%p,%s,%d,%p,%ld)\n", handle, debugstr_us(name), info_class, info, length );
461
462     if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
463
464     /* compute the length we want to retrieve */
465     switch(info_class)
466     {
467     case KeyValueBasicInformation:
468         fixed_size = (char *)((KEY_VALUE_BASIC_INFORMATION *)info)->Name - (char *)info;
469         data_ptr = NULL;
470         break;
471     case KeyValueFullInformation:
472         data_ptr = (UCHAR *)((KEY_VALUE_FULL_INFORMATION *)info)->Name;
473         fixed_size = (char *)data_ptr - (char *)info;
474         break;
475     case KeyValuePartialInformation:
476         data_ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data;
477         fixed_size = (char *)data_ptr - (char *)info;
478         break;
479     default:
480         FIXME( "Information class %d not implemented\n", info_class );
481         return STATUS_INVALID_PARAMETER;
482     }
483
484     SERVER_START_REQ( get_key_value )
485     {
486         req->hkey = handle;
487         wine_server_add_data( req, name->Buffer, name->Length );
488         if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
489         if (!(ret = wine_server_call( req )))
490         {
491             copy_key_value_info( info_class, info, length, reply->type,
492                                  0, wine_server_reply_size(reply) );
493             *result_len = fixed_size + reply->total;
494             if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
495         }
496     }
497     SERVER_END_REQ;
498     return ret;
499 }
500
501 /******************************************************************************
502  * RtlpNtQueryValueKey [NTDLL.@]
503  *
504  */
505 NTSTATUS WINAPI RtlpNtQueryValueKey( HKEY handle, ULONG *result_type, PBYTE dest,
506                                      DWORD *result_len )
507 {
508     KEY_VALUE_PARTIAL_INFORMATION *info;
509     UNICODE_STRING name;
510     NTSTATUS ret;
511     DWORD dwResultLen;
512     DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + result_len ? *result_len : 0;
513
514     info = (KEY_VALUE_PARTIAL_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
515     if (!info)
516       return STATUS_NO_MEMORY;
517
518     name.Length = 0;
519     ret = NtQueryValueKey( handle, &name, KeyValuePartialInformation, info, dwLen, &dwResultLen );
520
521     if (!ret || ret == STATUS_BUFFER_OVERFLOW)
522     {
523         if (result_len)
524             *result_len = info->DataLength;
525
526         if (result_type)
527             *result_type = info->Type;
528
529         if (ret != STATUS_BUFFER_OVERFLOW)
530             memcpy( dest, info->Data, info->DataLength );
531     }
532
533     RtlFreeHeap( GetProcessHeap(), 0, info );
534     return ret;
535 }
536
537 /******************************************************************************
538  *  NtFlushKey  [NTDLL.@]
539  *  ZwFlushKey  [NTDLL.@]
540  */
541 NTSTATUS WINAPI NtFlushKey(HKEY key)
542 {
543     NTSTATUS ret;
544
545     TRACE("key=%p\n", key);
546
547     SERVER_START_REQ( flush_key )
548     {
549         req->hkey = key;
550         ret = wine_server_call( req );
551     }
552     SERVER_END_REQ;
553     
554     return ret;
555 }
556
557 /******************************************************************************
558  *  NtLoadKey   [NTDLL.@]
559  *  ZwLoadKey   [NTDLL.@]
560  */
561 NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, const OBJECT_ATTRIBUTES *file )
562 {
563     FIXME("stub!\n");
564     dump_ObjectAttributes(attr);
565     dump_ObjectAttributes(file);
566     return STATUS_SUCCESS;
567 }
568
569 /******************************************************************************
570  *  NtNotifyChangeKey   [NTDLL.@]
571  *  ZwNotifyChangeKey   [NTDLL.@]
572  */
573 NTSTATUS WINAPI NtNotifyChangeKey(
574         IN HKEY KeyHandle,
575         IN HANDLE Event,
576         IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
577         IN PVOID ApcContext OPTIONAL,
578         OUT PIO_STATUS_BLOCK IoStatusBlock,
579         IN ULONG CompletionFilter,
580         IN BOOLEAN Asynchroneous,
581         OUT PVOID ChangeBuffer,
582         IN ULONG Length,
583         IN BOOLEAN WatchSubtree)
584 {
585         FIXME("(%p,%p,%p,%p,%p,0x%08lx, 0x%08x,%p,0x%08lx,0x%08x) stub!\n",
586         KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
587         Asynchroneous, ChangeBuffer, Length, WatchSubtree);
588         return STATUS_SUCCESS;
589 }
590
591 /******************************************************************************
592  * NtQueryMultipleValueKey [NTDLL]
593  * ZwQueryMultipleValueKey
594  */
595
596 NTSTATUS WINAPI NtQueryMultipleValueKey(
597         HKEY KeyHandle,
598         PVALENTW ListOfValuesToQuery,
599         ULONG NumberOfItems,
600         PVOID MultipleValueInformation,
601         ULONG Length,
602         PULONG  ReturnLength)
603 {
604         FIXME("(%p,%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
605         KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
606         Length,ReturnLength);
607         return STATUS_SUCCESS;
608 }
609
610 /******************************************************************************
611  * NtReplaceKey [NTDLL.@]
612  * ZwReplaceKey [NTDLL.@]
613  */
614 NTSTATUS WINAPI NtReplaceKey(
615         IN POBJECT_ATTRIBUTES ObjectAttributes,
616         IN HKEY Key,
617         IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
618 {
619         FIXME("(%p),stub!\n", Key);
620         dump_ObjectAttributes(ObjectAttributes);
621         dump_ObjectAttributes(ReplacedObjectAttributes);
622         return STATUS_SUCCESS;
623 }
624 /******************************************************************************
625  * NtRestoreKey [NTDLL.@]
626  * ZwRestoreKey [NTDLL.@]
627  */
628 NTSTATUS WINAPI NtRestoreKey(
629         HKEY KeyHandle,
630         HANDLE FileHandle,
631         ULONG RestoreFlags)
632 {
633         FIXME("(%p,%p,0x%08lx) stub\n",
634         KeyHandle, FileHandle, RestoreFlags);
635         return STATUS_SUCCESS;
636 }
637 /******************************************************************************
638  * NtSaveKey [NTDLL.@]
639  * ZwSaveKey [NTDLL.@]
640  */
641 NTSTATUS WINAPI NtSaveKey(
642         IN HKEY KeyHandle,
643         IN HANDLE FileHandle)
644 {
645         FIXME("(%p,%p) stub\n",
646         KeyHandle, FileHandle);
647         return STATUS_SUCCESS;
648 }
649 /******************************************************************************
650  * NtSetInformationKey [NTDLL.@]
651  * ZwSetInformationKey [NTDLL.@]
652  */
653 NTSTATUS WINAPI NtSetInformationKey(
654         IN HKEY KeyHandle,
655         IN const int KeyInformationClass,
656         IN PVOID KeyInformation,
657         IN ULONG KeyInformationLength)
658 {
659         FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
660         KeyHandle, KeyInformationClass, KeyInformation, KeyInformationLength);
661         return STATUS_SUCCESS;
662 }
663
664
665 /******************************************************************************
666  * NtSetValueKey [NTDLL.@]
667  * ZwSetValueKey [NTDLL.@]
668  *
669  * NOTES
670  *   win95 does not care about count for REG_SZ and finds out the len by itself (js)
671  *   NT does definitely care (aj)
672  */
673 NTSTATUS WINAPI NtSetValueKey( HKEY hkey, const UNICODE_STRING *name, ULONG TitleIndex,
674                                ULONG type, const void *data, ULONG count )
675 {
676     NTSTATUS ret;
677
678     TRACE( "(%p,%s,%ld,%p,%ld)\n", hkey, debugstr_us(name), type, data, count );
679
680     if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
681
682     SERVER_START_REQ( set_key_value )
683     {
684         req->hkey    = hkey;
685         req->type    = type;
686         req->namelen = name->Length;
687         wine_server_add_data( req, name->Buffer, name->Length );
688         wine_server_add_data( req, data, count );
689         ret = wine_server_call( req );
690     }
691     SERVER_END_REQ;
692     return ret;
693 }
694
695 /******************************************************************************
696  * RtlpNtSetValueKey [NTDLL.@]
697  *
698  */
699 NTSTATUS WINAPI RtlpNtSetValueKey( HKEY hkey, ULONG type, const void *data,
700                                    ULONG count )
701 {
702     UNICODE_STRING name;
703
704     name.Length = 0;
705     return NtSetValueKey( hkey, &name, 0, type, data, count );
706 }
707
708 /******************************************************************************
709  * NtUnloadKey [NTDLL.@]
710  * ZwUnloadKey [NTDLL.@]
711  */
712 NTSTATUS WINAPI NtUnloadKey(
713         IN HKEY KeyHandle)
714 {
715         FIXME("(%p) stub\n",
716         KeyHandle);
717         return STATUS_SUCCESS;
718 }
719
720 /******************************************************************************
721  *  RtlFormatCurrentUserKeyPath         [NTDLL.@]
722  *
723  * NOTE: under NT the user name part of the path is an SID.
724  */
725 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
726 {
727     static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
728     const char *user = wine_get_user_name();
729     int len = ntdll_umbstowcs( 0, user, strlen(user)+1, NULL, 0 );
730
731     KeyPath->MaximumLength = sizeof(pathW) + len * sizeof(WCHAR);
732     KeyPath->Length = KeyPath->MaximumLength - sizeof(WCHAR);
733     if (!(KeyPath->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, KeyPath->MaximumLength )))
734         return STATUS_NO_MEMORY;
735     memcpy( KeyPath->Buffer, pathW, sizeof(pathW) );
736     ntdll_umbstowcs( 0, user, strlen(user)+1, KeyPath->Buffer + sizeof(pathW)/sizeof(WCHAR), len );
737     return STATUS_SUCCESS;
738 }
739
740 /******************************************************************************
741  *  RtlOpenCurrentUser          [NTDLL.@]
742  *
743  * if we return just HKEY_CURRENT_USER the advapi tries to find a remote
744  * registry (odd handle) and fails
745  *
746  */
747 DWORD WINAPI RtlOpenCurrentUser(
748         IN ACCESS_MASK DesiredAccess, /* [in] */
749         OUT PHKEY KeyHandle)          /* [out] handle of HKEY_CURRENT_USER */
750 {
751         OBJECT_ATTRIBUTES ObjectAttributes;
752         UNICODE_STRING ObjectName;
753         NTSTATUS ret;
754
755         TRACE("(0x%08lx, %p) stub\n",DesiredAccess, KeyHandle);
756
757         RtlFormatCurrentUserKeyPath(&ObjectName);
758         InitializeObjectAttributes(&ObjectAttributes,&ObjectName,OBJ_CASE_INSENSITIVE,0, NULL);
759         ret = NtCreateKey(KeyHandle, DesiredAccess, &ObjectAttributes, 0, NULL, 0, NULL);
760         RtlFreeUnicodeString(&ObjectName);
761         return ret;
762 }
763
764
765 static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo,
766                                         PRTL_QUERY_REGISTRY_TABLE pQuery, PVOID pContext, PVOID pEnvironment)
767 {
768     PUNICODE_STRING str;
769     UNICODE_STRING src, dst;
770     LONG *bin;
771     ULONG offset;
772     PWSTR wstr;
773     DWORD res;
774     NTSTATUS status = STATUS_SUCCESS;
775     ULONG len;
776     LPWSTR String;
777     INT count = 0;
778
779     if (pInfo == NULL)
780     {
781         if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
782             return STATUS_INVALID_PARAMETER;
783         else
784         {
785             status = pQuery->QueryRoutine(pQuery->Name, pQuery->DefaultType, pQuery->DefaultData,
786                                           pQuery->DefaultLength, pContext, pQuery->EntryContext);
787         }
788         return status;
789     }
790     len = pInfo->DataLength;
791
792     if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
793     {
794         str = (PUNICODE_STRING)pQuery->EntryContext;
795  
796         switch(pInfo->Type)
797         {
798         case REG_EXPAND_SZ:
799             if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
800             {
801                 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
802                 res = 0;
803                 dst.MaximumLength = 0;
804                 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
805                 dst.Length = 0;
806                 dst.MaximumLength = res;
807                 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
808                 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
809                 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
810                                      dst.Length, pContext, pQuery->EntryContext);
811                 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
812             }
813
814         case REG_SZ:
815         case REG_LINK:
816             if (str->Buffer == NULL)
817                 RtlCreateUnicodeString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
818             else
819                 RtlAppendUnicodeToString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
820             break;
821
822         case REG_MULTI_SZ:
823             if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
824                 return STATUS_INVALID_PARAMETER;
825
826             if (str->Buffer == NULL)
827             {
828                 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
829                 str->MaximumLength = len;
830             }
831             len = min(len, str->MaximumLength);
832             memcpy(str->Buffer, ((CHAR*)pInfo) + pInfo->DataOffset, len);
833             str->Length = len;
834             break;
835
836         default:
837             bin = (LONG*)pQuery->EntryContext;
838             if (pInfo->DataLength <= sizeof(ULONG))
839                 memcpy(bin, ((CHAR*)pInfo) + pInfo->DataOffset,
840                     pInfo->DataLength);
841             else
842             {
843                 if (bin[0] <= sizeof(ULONG))
844                 {
845                     memcpy(&bin[1], ((CHAR*)pInfo) + pInfo->DataOffset,
846                     min(-bin[0], pInfo->DataLength));
847                 }
848                 else
849                 {
850                    len = min(bin[0], pInfo->DataLength);
851                     bin[1] = len;
852                     bin[2] = pInfo->Type;
853                     memcpy(&bin[3], ((CHAR*)pInfo) + pInfo->DataOffset, len);
854                 }
855            }
856            break;
857         }
858     }
859     else
860     {
861         if((pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND) ||
862            (pInfo->Type != REG_EXPAND_SZ && pInfo->Type != REG_MULTI_SZ))
863         {
864             status = pQuery->QueryRoutine(pInfo->Name, pInfo->Type,
865                 ((CHAR*)pInfo) + pInfo->DataOffset, pInfo->DataLength,
866                 pContext, pQuery->EntryContext);
867         }
868         else if (pInfo->Type == REG_EXPAND_SZ)
869         {
870             RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
871             res = 0;
872             dst.MaximumLength = 0;
873             RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
874             dst.Length = 0;
875             dst.MaximumLength = res;
876             dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
877             RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
878             status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
879                                           dst.Length, pContext, pQuery->EntryContext);
880             RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
881         }
882         else /* REG_MULTI_SZ */
883         {
884             if(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND)
885             {
886                 for (offset = 0; offset <= pInfo->DataLength; offset += len + sizeof(WCHAR))
887                     {
888                     wstr = (WCHAR*)(((CHAR*)pInfo) + offset);
889                     len = strlenW(wstr) * sizeof(WCHAR);
890                     status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, wstr, len,
891                         pContext, pQuery->EntryContext);
892                     if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
893                         return status;
894                     }
895             }
896             else
897             {
898                 while(count<=pInfo->DataLength)
899                 {
900                     String = (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset)+count;
901                     count+=strlenW(String)+1;
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);
913                     if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
914                         return status;
915                 }
916             }
917         }
918     }
919     return status;
920 }
921
922
923 static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHKEY handle)
924 {
925     UNICODE_STRING KeyString;
926     OBJECT_ATTRIBUTES regkey;
927     PCWSTR base;
928     INT len;
929     NTSTATUS status;
930
931     static const WCHAR empty[] = {0};
932     static const WCHAR control[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e',
933     '\\','S','y','s','t','e','m','\\','C','u','r','r','e','n','t',' ','C','o','n','t','r','o','l','S','e','t','\\',
934     'C','o','n','t','r','o','l','\\',0};
935
936     static const WCHAR devicemap[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
937     'H','a','r','d','w','a','r','e','\\','D','e','v','i','c','e','M','a','p','\\',0};
938
939     static const WCHAR services[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
940     'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
941     'S','e','r','v','i','c','e','s','\\',0};
942
943     static const WCHAR user[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\',
944     'C','u','r','r','e','n','t','U','s','e','r','\\',0};
945
946     static const WCHAR windows_nt[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
947     'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
948     'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',0};
949
950     switch (RelativeTo & 0xff)
951     {
952     case RTL_REGISTRY_ABSOLUTE:
953         base = empty;
954         break;
955
956     case RTL_REGISTRY_CONTROL:
957         base = control;
958         break;
959
960     case RTL_REGISTRY_DEVICEMAP:
961         base = devicemap;
962         break;
963
964     case RTL_REGISTRY_SERVICES:
965         base = services;
966         break;
967
968     case RTL_REGISTRY_USER:
969         base = user;
970         break;
971
972     case RTL_REGISTRY_WINDOWS_NT:
973         base = windows_nt;
974         break;
975
976     default:
977         return STATUS_INVALID_PARAMETER;
978     }
979
980     len = (strlenW(base) + strlenW(Path) + 1) * sizeof(WCHAR);
981     KeyString.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
982     if (KeyString.Buffer == NULL)
983         return STATUS_NO_MEMORY;
984
985     strcpyW(KeyString.Buffer, base);
986     strcatW(KeyString.Buffer, Path);
987     KeyString.Length = len - sizeof(WCHAR);
988     KeyString.MaximumLength = len;
989     InitializeObjectAttributes(&regkey, &KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL);
990     status = NtOpenKey(handle, KEY_ALL_ACCESS, &regkey);
991     RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer);
992     return status;
993 }
994
995 /*************************************************************************
996  * RtlQueryRegistryValues   [NTDLL.@]
997  *
998  * Query multiple registry values with a signle call.
999  *
1000  * PARAMS
1001  *  RelativeTo  [I] Registry path that Path refers to
1002  *  Path        [I] Path to key
1003  *  QueryTable  [I] Table of key values to query
1004  *  Context     [I] Paremeter to pass to the application defined QueryRoutine function
1005  *  Environment [I] Optional parameter to use when performing expantion
1006  *
1007  * RETURNS
1008  *  STATUS_SUCCESS or an appropriate NTSTATUS error code.
1009  */
1010 NTSTATUS WINAPI RtlQueryRegistryValues(IN ULONG RelativeTo, IN PCWSTR Path,
1011                                        IN PRTL_QUERY_REGISTRY_TABLE QueryTable, IN PVOID Context,
1012                                        IN PVOID Environment OPTIONAL)
1013 {
1014     UNICODE_STRING Value;
1015     HKEY handle, topkey;
1016     PKEY_VALUE_FULL_INFORMATION pInfo = NULL;
1017     ULONG len, buflen = 0;
1018     NTSTATUS status=STATUS_SUCCESS, ret = STATUS_SUCCESS;
1019     INT i;
1020
1021     TRACE("(%ld, %s, %p, %p, %p)\n", RelativeTo, debugstr_w(Path), QueryTable, Context, Environment);
1022
1023     if(Path == NULL)
1024         return STATUS_INVALID_PARAMETER;
1025
1026     /* get a valid handle */
1027     if (RelativeTo & RTL_REGISTRY_HANDLE)
1028         topkey = handle = (HANDLE)Path;
1029     else
1030     {
1031         status = RTL_GetKeyHandle(RelativeTo, Path, &topkey);
1032         handle = topkey;
1033     }
1034     if(status != STATUS_SUCCESS)
1035         return status;
1036
1037     /* Process query table entries */
1038     for (; QueryTable->QueryRoutine != NULL || QueryTable->Name != NULL; ++QueryTable)
1039     {
1040         if (QueryTable->Flags &
1041             (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY))
1042         {
1043             /* topkey must be kept open just in case we will reuse it later */
1044             if (handle != topkey)
1045                 NtClose(handle);
1046
1047             if (QueryTable->Flags & RTL_QUERY_REGISTRY_SUBKEY)
1048             {
1049                 handle = 0;
1050                 status = RTL_GetKeyHandle((ULONG)QueryTable->Name, Path, &handle);
1051                 if(status != STATUS_SUCCESS)
1052                 {
1053                     ret = status;
1054                     goto out;
1055                 }
1056             }
1057             else
1058                 handle = topkey;
1059         }
1060
1061         if (QueryTable->Flags & RTL_QUERY_REGISTRY_NOVALUE)
1062         {
1063             QueryTable->QueryRoutine(QueryTable->Name, REG_NONE, NULL, 0,
1064                 Context, QueryTable->EntryContext);
1065             continue;
1066         }
1067
1068         if (!handle)
1069         {
1070             if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1071             {
1072                 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1073                 goto out;
1074             }
1075             continue;
1076         }
1077
1078         if (QueryTable->Name == NULL)
1079         {
1080             if (QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT)
1081             {
1082                 ret = STATUS_INVALID_PARAMETER;
1083                 goto out;
1084             }
1085
1086             /* Report all subkeys */
1087             for (i = 0;; ++i)
1088             {
1089                 status = NtEnumerateValueKey(handle, i,
1090                     KeyValueFullInformation, pInfo, buflen, &len);
1091                 if (status == STATUS_NO_MORE_ENTRIES)
1092                     break;
1093                 if (status == STATUS_BUFFER_OVERFLOW ||
1094                     status == STATUS_BUFFER_TOO_SMALL)
1095                 {
1096                     buflen = len;
1097                     RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1098                     pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1099                         GetProcessHeap(), 0, buflen);
1100                     NtEnumerateValueKey(handle, i, KeyValueFullInformation,
1101                         pInfo, buflen, &len);
1102                 }
1103
1104                 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1105                 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1106                 {
1107                     ret = status;
1108                     goto out;
1109                 }
1110                 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1111                 {
1112                     RtlInitUnicodeString(&Value, pInfo->Name);
1113                     NtDeleteValueKey(handle, &Value);
1114                 }
1115             }
1116
1117             if (i == 0  && (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED))
1118             {
1119                 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1120                 goto out;
1121             }
1122         }
1123         else
1124         {
1125             RtlInitUnicodeString(&Value, QueryTable->Name);
1126             status = NtQueryValueKey(handle, &Value, KeyValueFullInformation,
1127                 pInfo, buflen, &len);
1128             if (status == STATUS_BUFFER_OVERFLOW ||
1129                 status == STATUS_BUFFER_TOO_SMALL)
1130             {
1131                 buflen = len;
1132                 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1133                 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1134                     GetProcessHeap(), 0, buflen);
1135                 status = NtQueryValueKey(handle, &Value,
1136                     KeyValueFullInformation, pInfo, buflen, &len);
1137             }
1138             if (status != STATUS_SUCCESS)
1139             {
1140                 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1141                 {
1142                     ret = STATUS_OBJECT_NAME_NOT_FOUND;
1143                     goto out;
1144                 }
1145                 status = RTL_ReportRegistryValue(NULL, QueryTable, Context, Environment);
1146                 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1147                 {
1148                     ret = status;
1149                     goto out;
1150                 }
1151             }
1152             else
1153             {
1154                 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1155                 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1156                 {
1157                     ret = status;
1158                     goto out;
1159                 }
1160                 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1161                     NtDeleteValueKey(handle, &Value);
1162             }
1163         }
1164     }
1165
1166 out:
1167     RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1168     if (handle != topkey)
1169         NtClose(handle);
1170     NtClose(topkey);
1171     return ret;
1172 }
1173
1174 /*************************************************************************
1175  * RtlCheckRegistryKey   [NTDLL.@]
1176  *
1177  * Query multiple registry values with a signle call.
1178  *
1179  * PARAMS
1180  *  RelativeTo [I] Registry path that Path refers to
1181  *  Path       [I] Path to key
1182  *
1183  * RETURNS
1184  *  STATUS_SUCCESS if the specified key exists, or an NTSTATUS error code.
1185  */
1186 NTSTATUS WINAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
1187 {
1188     HKEY handle;
1189     NTSTATUS status;
1190
1191     TRACE("(%ld, %s)\n", RelativeTo, debugstr_w(Path));
1192
1193     if((!RelativeTo) && Path == NULL)
1194         return STATUS_OBJECT_PATH_SYNTAX_BAD;
1195     if(RelativeTo & RTL_REGISTRY_HANDLE)
1196         return STATUS_SUCCESS;
1197
1198     status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1199     if (handle) NtClose(handle);
1200     if (status == STATUS_INVALID_HANDLE) status = STATUS_OBJECT_NAME_NOT_FOUND;
1201     return status;
1202 }
1203
1204 /*************************************************************************
1205  * RtlDeleteRegistryValue   [NTDLL.@]
1206  *
1207  * Query multiple registry values with a signle call.
1208  *
1209  * PARAMS
1210  *  RelativeTo [I] Registry path that Path refers to
1211  *  Path       [I] Path to key
1212  *  ValueName  [I] Name of the value to delete
1213  *
1214  * RETURNS
1215  *  STATUS_SUCCESS if the specified key is successfully deleted, or an NTSTATUS error code.
1216  */
1217 NTSTATUS WINAPI RtlDeleteRegistryValue(IN ULONG RelativeTo, IN PCWSTR Path, IN PCWSTR ValueName)
1218 {
1219     NTSTATUS status;
1220     HKEY handle;
1221     UNICODE_STRING Value;
1222
1223     TRACE("(%ld, %s, %s)\n", RelativeTo, debugstr_w(Path), debugstr_w(ValueName));
1224
1225     RtlInitUnicodeString(&Value, ValueName);
1226     if(RelativeTo == RTL_REGISTRY_HANDLE)
1227     {
1228         return NtDeleteValueKey((HKEY)Path, &Value);
1229     }
1230     status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1231     if (status) return status;
1232     status = NtDeleteValueKey(handle, &Value);
1233     NtClose(handle);
1234     return status;
1235 }