Clean up devenum and properly implement DllCanUnloadNow ref counting.
[wine/multimedia.git] / dlls / ntdll / reg.c
blobea9fee60583f84bffcd090105bd2d0af9502afa9
1 /*
2 * Registry functions
4 * Copyright (C) 1999 Juergen Schmied
5 * Copyright (C) 2000 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * NOTES:
22 * HKEY_LOCAL_MACHINE \\REGISTRY\\MACHINE
23 * HKEY_USERS \\REGISTRY\\USER
24 * HKEY_CURRENT_CONFIG \\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\HARDWARE PROFILES\\CURRENT
25 * HKEY_CLASSES \\REGISTRY\\MACHINE\\SOFTWARE\\CLASSES
28 #include "config.h"
29 #include "wine/port.h"
31 #include <stdarg.h>
32 #include <stdio.h>
33 #include <string.h>
35 #include "winerror.h"
36 #include "wine/unicode.h"
37 #include "wine/library.h"
38 #include "wine/server.h"
39 #include "windef.h"
40 #include "winbase.h"
41 #include "winreg.h"
42 #include "winternl.h"
43 #include "ntdll_misc.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(reg);
48 /* maximum length of a key/value name in bytes (without terminating null) */
49 #define MAX_NAME_LENGTH ((MAX_PATH-1) * sizeof(WCHAR))
52 /******************************************************************************
53 * NtCreateKey [NTDLL.@]
54 * ZwCreateKey [NTDLL.@]
56 NTSTATUS WINAPI NtCreateKey( PHKEY retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
57 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
58 PULONG dispos )
60 NTSTATUS ret;
62 TRACE( "(%p,%s,%s,%lx,%lx,%p)\n", attr->RootDirectory, debugstr_us(attr->ObjectName),
63 debugstr_us(class), options, access, retkey );
65 if (attr->ObjectName->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
66 if (!retkey) return STATUS_INVALID_PARAMETER;
68 SERVER_START_REQ( create_key )
70 req->parent = attr->RootDirectory;
71 req->access = access;
72 req->options = options;
73 req->modif = 0;
74 req->namelen = attr->ObjectName->Length;
75 wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
76 if (class) wine_server_add_data( req, class->Buffer, class->Length );
77 if (!(ret = wine_server_call( req )))
79 *retkey = reply->hkey;
80 if (dispos) *dispos = reply->created ? REG_CREATED_NEW_KEY : REG_OPENED_EXISTING_KEY;
83 SERVER_END_REQ;
84 TRACE("<- %p\n", *retkey);
85 return ret;
88 /******************************************************************************
89 * RtlpNtCreateKey [NTDLL.@]
91 * See NtCreateKey.
93 NTSTATUS WINAPI RtlpNtCreateKey( PHKEY retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr,
94 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
95 PULONG dispos )
97 if (attr)
98 attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
100 return NtCreateKey(retkey, access, attr, 0, NULL, 0, dispos);
103 /******************************************************************************
104 * NtOpenKey [NTDLL.@]
105 * ZwOpenKey [NTDLL.@]
107 * OUT PHKEY retkey (returns 0 when failure)
108 * IN ACCESS_MASK access
109 * IN POBJECT_ATTRIBUTES attr
111 NTSTATUS WINAPI NtOpenKey( PHKEY retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
113 NTSTATUS ret;
114 DWORD len = attr->ObjectName->Length;
116 TRACE( "(%p,%s,%lx,%p)\n", attr->RootDirectory,
117 debugstr_us(attr->ObjectName), access, retkey );
119 if (len > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
120 if (!retkey) return STATUS_INVALID_PARAMETER;
122 SERVER_START_REQ( open_key )
124 req->parent = attr->RootDirectory;
125 req->access = access;
126 wine_server_add_data( req, attr->ObjectName->Buffer, len );
127 ret = wine_server_call( req );
128 *retkey = reply->hkey;
130 SERVER_END_REQ;
131 TRACE("<- %p\n", *retkey);
132 return ret;
135 /******************************************************************************
136 * RtlpNtOpenKey [NTDLL.@]
138 * See NtOpenKey.
140 NTSTATUS WINAPI RtlpNtOpenKey( PHKEY retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr )
142 if (attr)
143 attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
144 return NtOpenKey(retkey, access, attr);
147 /******************************************************************************
148 * NtDeleteKey [NTDLL.@]
149 * ZwDeleteKey [NTDLL.@]
151 NTSTATUS WINAPI NtDeleteKey( HKEY hkey )
153 NTSTATUS ret;
155 TRACE( "(%p)\n", hkey );
157 SERVER_START_REQ( delete_key )
159 req->hkey = hkey;
160 ret = wine_server_call( req );
162 SERVER_END_REQ;
163 return ret;
166 /******************************************************************************
167 * RtlpNtMakeTemporaryKey [NTDLL.@]
169 * See NtDeleteKey.
171 NTSTATUS WINAPI RtlpNtMakeTemporaryKey( HKEY hkey )
173 return NtDeleteKey(hkey);
176 /******************************************************************************
177 * NtDeleteValueKey [NTDLL.@]
178 * ZwDeleteValueKey [NTDLL.@]
180 NTSTATUS WINAPI NtDeleteValueKey( HKEY hkey, const UNICODE_STRING *name )
182 NTSTATUS ret;
184 TRACE( "(%p,%s)\n", hkey, debugstr_us(name) );
185 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
187 SERVER_START_REQ( delete_key_value )
189 req->hkey = hkey;
190 wine_server_add_data( req, name->Buffer, name->Length );
191 ret = wine_server_call( req );
193 SERVER_END_REQ;
194 return ret;
198 /******************************************************************************
199 * enumerate_key
201 * Implementation of NtQueryKey and NtEnumerateKey
203 static NTSTATUS enumerate_key( HKEY handle, int index, KEY_INFORMATION_CLASS info_class,
204 void *info, DWORD length, DWORD *result_len )
207 NTSTATUS ret;
208 void *data_ptr;
209 size_t fixed_size;
211 switch(info_class)
213 case KeyBasicInformation: data_ptr = ((KEY_BASIC_INFORMATION *)info)->Name; break;
214 case KeyFullInformation: data_ptr = ((KEY_FULL_INFORMATION *)info)->Class; break;
215 case KeyNodeInformation: data_ptr = ((KEY_NODE_INFORMATION *)info)->Name; break;
216 default:
217 FIXME( "Information class %d not implemented\n", info_class );
218 return STATUS_INVALID_PARAMETER;
220 fixed_size = (char *)data_ptr - (char *)info;
222 SERVER_START_REQ( enum_key )
224 req->hkey = handle;
225 req->index = index;
226 req->info_class = info_class;
227 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
228 if (!(ret = wine_server_call( req )))
230 LARGE_INTEGER modif;
232 RtlSecondsSince1970ToTime( reply->modif, &modif );
234 switch(info_class)
236 case KeyBasicInformation:
238 KEY_BASIC_INFORMATION keyinfo;
239 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
240 keyinfo.LastWriteTime = modif;
241 keyinfo.TitleIndex = 0;
242 keyinfo.NameLength = reply->namelen;
243 memcpy( info, &keyinfo, min( length, fixed_size ) );
245 break;
246 case KeyFullInformation:
248 KEY_FULL_INFORMATION keyinfo;
249 fixed_size = (char *)keyinfo.Class - (char *)&keyinfo;
250 keyinfo.LastWriteTime = modif;
251 keyinfo.TitleIndex = 0;
252 keyinfo.ClassLength = wine_server_reply_size(reply);
253 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size : -1;
254 keyinfo.SubKeys = reply->subkeys;
255 keyinfo.MaxNameLen = reply->max_subkey;
256 keyinfo.MaxClassLen = reply->max_class;
257 keyinfo.Values = reply->values;
258 keyinfo.MaxValueNameLen = reply->max_value;
259 keyinfo.MaxValueDataLen = reply->max_data;
260 memcpy( info, &keyinfo, min( length, fixed_size ) );
262 break;
263 case KeyNodeInformation:
265 KEY_NODE_INFORMATION keyinfo;
266 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
267 keyinfo.LastWriteTime = modif;
268 keyinfo.TitleIndex = 0;
269 keyinfo.ClassLength = max( 0, wine_server_reply_size(reply) - reply->namelen );
270 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size + reply->namelen : -1;
271 keyinfo.NameLength = reply->namelen;
272 memcpy( info, &keyinfo, min( length, fixed_size ) );
274 break;
276 *result_len = fixed_size + reply->total;
277 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
280 SERVER_END_REQ;
281 return ret;
286 /******************************************************************************
287 * NtEnumerateKey [NTDLL.@]
288 * ZwEnumerateKey [NTDLL.@]
290 * NOTES
291 * the name copied into the buffer is NOT 0-terminated
293 NTSTATUS WINAPI NtEnumerateKey( HKEY handle, ULONG index, KEY_INFORMATION_CLASS info_class,
294 void *info, DWORD length, DWORD *result_len )
296 /* -1 means query key, so avoid it here */
297 if (index == (ULONG)-1) return STATUS_NO_MORE_ENTRIES;
298 return enumerate_key( handle, index, info_class, info, length, result_len );
302 /******************************************************************************
303 * RtlpNtEnumerateSubKey [NTDLL.@]
306 NTSTATUS WINAPI RtlpNtEnumerateSubKey( HKEY handle, UNICODE_STRING *out, ULONG index )
308 KEY_BASIC_INFORMATION *info;
309 DWORD dwLen, dwResultLen;
310 NTSTATUS ret;
312 if (out->Length)
314 dwLen = out->Length + sizeof(KEY_BASIC_INFORMATION);
315 info = (KEY_BASIC_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
316 if (!info)
317 return STATUS_NO_MEMORY;
319 else
321 dwLen = 0;
322 info = NULL;
325 ret = NtEnumerateKey( handle, index, KeyBasicInformation, info, dwLen, &dwResultLen );
326 dwResultLen -= sizeof(KEY_BASIC_INFORMATION);
328 if (ret == STATUS_BUFFER_OVERFLOW)
329 out->Length = dwResultLen;
330 else if (!ret)
332 if (out->Length < info->NameLength)
334 out->Length = dwResultLen;
335 ret = STATUS_BUFFER_OVERFLOW;
337 else
339 out->Length = info->NameLength;
340 memcpy(out->Buffer, info->Name, info->NameLength);
344 if (info)
345 RtlFreeHeap( GetProcessHeap(), 0, info );
346 return ret;
349 /******************************************************************************
350 * NtQueryKey [NTDLL.@]
351 * ZwQueryKey [NTDLL.@]
353 NTSTATUS WINAPI NtQueryKey( HKEY handle, KEY_INFORMATION_CLASS info_class,
354 void *info, DWORD length, DWORD *result_len )
356 return enumerate_key( handle, -1, info_class, info, length, result_len );
360 /* fill the key value info structure for a specific info class */
361 static void copy_key_value_info( KEY_VALUE_INFORMATION_CLASS info_class, void *info,
362 DWORD length, int type, int name_len, int data_len )
364 switch(info_class)
366 case KeyValueBasicInformation:
368 KEY_VALUE_BASIC_INFORMATION keyinfo;
369 keyinfo.TitleIndex = 0;
370 keyinfo.Type = type;
371 keyinfo.NameLength = name_len;
372 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
373 memcpy( info, &keyinfo, length );
374 break;
376 case KeyValueFullInformation:
378 KEY_VALUE_FULL_INFORMATION keyinfo;
379 keyinfo.TitleIndex = 0;
380 keyinfo.Type = type;
381 keyinfo.DataOffset = (char *)keyinfo.Name - (char *)&keyinfo + name_len;
382 keyinfo.DataLength = data_len;
383 keyinfo.NameLength = name_len;
384 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
385 memcpy( info, &keyinfo, length );
386 break;
388 case KeyValuePartialInformation:
390 KEY_VALUE_PARTIAL_INFORMATION keyinfo;
391 keyinfo.TitleIndex = 0;
392 keyinfo.Type = type;
393 keyinfo.DataLength = data_len;
394 length = min( length, (char *)keyinfo.Data - (char *)&keyinfo );
395 memcpy( info, &keyinfo, length );
396 break;
398 default:
399 break;
404 /******************************************************************************
405 * NtEnumerateValueKey [NTDLL.@]
406 * ZwEnumerateValueKey [NTDLL.@]
408 NTSTATUS WINAPI NtEnumerateValueKey( HKEY handle, ULONG index,
409 KEY_VALUE_INFORMATION_CLASS info_class,
410 void *info, DWORD length, DWORD *result_len )
412 NTSTATUS ret;
413 void *ptr;
414 size_t fixed_size;
416 TRACE( "(%p,%lu,%d,%p,%ld)\n", handle, index, info_class, info, length );
418 /* compute the length we want to retrieve */
419 switch(info_class)
421 case KeyValueBasicInformation: ptr = ((KEY_VALUE_BASIC_INFORMATION *)info)->Name; break;
422 case KeyValueFullInformation: ptr = ((KEY_VALUE_FULL_INFORMATION *)info)->Name; break;
423 case KeyValuePartialInformation: ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data; break;
424 default:
425 FIXME( "Information class %d not implemented\n", info_class );
426 return STATUS_INVALID_PARAMETER;
428 fixed_size = (char *)ptr - (char *)info;
430 SERVER_START_REQ( enum_key_value )
432 req->hkey = handle;
433 req->index = index;
434 req->info_class = info_class;
435 if (length > fixed_size) wine_server_set_reply( req, ptr, length - fixed_size );
436 if (!(ret = wine_server_call( req )))
438 copy_key_value_info( info_class, info, length, reply->type, reply->namelen,
439 wine_server_reply_size(reply) - reply->namelen );
440 *result_len = fixed_size + reply->total;
441 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
444 SERVER_END_REQ;
445 return ret;
449 /******************************************************************************
450 * NtQueryValueKey [NTDLL.@]
451 * ZwQueryValueKey [NTDLL.@]
453 * NOTES
454 * the name in the KeyValueInformation is never set
456 NTSTATUS WINAPI NtQueryValueKey( HKEY handle, const UNICODE_STRING *name,
457 KEY_VALUE_INFORMATION_CLASS info_class,
458 void *info, DWORD length, DWORD *result_len )
460 NTSTATUS ret;
461 UCHAR *data_ptr;
462 unsigned int fixed_size = 0;
464 TRACE( "(%p,%s,%d,%p,%ld)\n", handle, debugstr_us(name), info_class, info, length );
466 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
468 /* compute the length we want to retrieve */
469 switch(info_class)
471 case KeyValueBasicInformation:
472 fixed_size = (char *)((KEY_VALUE_BASIC_INFORMATION *)info)->Name - (char *)info;
473 data_ptr = NULL;
474 break;
475 case KeyValueFullInformation:
476 data_ptr = (UCHAR *)((KEY_VALUE_FULL_INFORMATION *)info)->Name;
477 fixed_size = (char *)data_ptr - (char *)info;
478 break;
479 case KeyValuePartialInformation:
480 data_ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data;
481 fixed_size = (char *)data_ptr - (char *)info;
482 break;
483 default:
484 FIXME( "Information class %d not implemented\n", info_class );
485 return STATUS_INVALID_PARAMETER;
488 SERVER_START_REQ( get_key_value )
490 req->hkey = handle;
491 wine_server_add_data( req, name->Buffer, name->Length );
492 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
493 if (!(ret = wine_server_call( req )))
495 copy_key_value_info( info_class, info, length, reply->type,
496 0, wine_server_reply_size(reply) );
497 *result_len = fixed_size + reply->total;
498 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
501 SERVER_END_REQ;
502 return ret;
505 /******************************************************************************
506 * RtlpNtQueryValueKey [NTDLL.@]
509 NTSTATUS WINAPI RtlpNtQueryValueKey( HKEY handle, ULONG *result_type, PBYTE dest,
510 DWORD *result_len )
512 KEY_VALUE_PARTIAL_INFORMATION *info;
513 UNICODE_STRING name;
514 NTSTATUS ret;
515 DWORD dwResultLen;
516 DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + result_len ? *result_len : 0;
518 info = (KEY_VALUE_PARTIAL_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
519 if (!info)
520 return STATUS_NO_MEMORY;
522 name.Length = 0;
523 ret = NtQueryValueKey( handle, &name, KeyValuePartialInformation, info, dwLen, &dwResultLen );
525 if (!ret || ret == STATUS_BUFFER_OVERFLOW)
527 if (result_len)
528 *result_len = info->DataLength;
530 if (result_type)
531 *result_type = info->Type;
533 if (ret != STATUS_BUFFER_OVERFLOW)
534 memcpy( dest, info->Data, info->DataLength );
537 RtlFreeHeap( GetProcessHeap(), 0, info );
538 return ret;
541 /******************************************************************************
542 * NtFlushKey [NTDLL.@]
543 * ZwFlushKey [NTDLL.@]
545 NTSTATUS WINAPI NtFlushKey(HKEY key)
547 NTSTATUS ret;
549 TRACE("key=%p\n", key);
551 SERVER_START_REQ( flush_key )
553 req->hkey = key;
554 ret = wine_server_call( req );
556 SERVER_END_REQ;
558 return ret;
561 /******************************************************************************
562 * NtLoadKey [NTDLL.@]
563 * ZwLoadKey [NTDLL.@]
565 NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, const OBJECT_ATTRIBUTES *file )
567 FIXME("stub!\n");
568 dump_ObjectAttributes(attr);
569 dump_ObjectAttributes(file);
570 return STATUS_SUCCESS;
573 /******************************************************************************
574 * NtNotifyChangeKey [NTDLL.@]
575 * ZwNotifyChangeKey [NTDLL.@]
577 NTSTATUS WINAPI NtNotifyChangeKey(
578 IN HKEY KeyHandle,
579 IN HANDLE Event,
580 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
581 IN PVOID ApcContext OPTIONAL,
582 OUT PIO_STATUS_BLOCK IoStatusBlock,
583 IN ULONG CompletionFilter,
584 IN BOOLEAN Asynchroneous,
585 OUT PVOID ChangeBuffer,
586 IN ULONG Length,
587 IN BOOLEAN WatchSubtree)
589 FIXME("(%p,%p,%p,%p,%p,0x%08lx, 0x%08x,%p,0x%08lx,0x%08x) stub!\n",
590 KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
591 Asynchroneous, ChangeBuffer, Length, WatchSubtree);
592 return STATUS_SUCCESS;
595 /******************************************************************************
596 * NtQueryMultipleValueKey [NTDLL]
597 * ZwQueryMultipleValueKey
600 NTSTATUS WINAPI NtQueryMultipleValueKey(
601 HKEY KeyHandle,
602 PVALENTW ListOfValuesToQuery,
603 ULONG NumberOfItems,
604 PVOID MultipleValueInformation,
605 ULONG Length,
606 PULONG ReturnLength)
608 FIXME("(%p,%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
609 KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
610 Length,ReturnLength);
611 return STATUS_SUCCESS;
614 /******************************************************************************
615 * NtReplaceKey [NTDLL.@]
616 * ZwReplaceKey [NTDLL.@]
618 NTSTATUS WINAPI NtReplaceKey(
619 IN POBJECT_ATTRIBUTES ObjectAttributes,
620 IN HKEY Key,
621 IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
623 FIXME("(%p),stub!\n", Key);
624 dump_ObjectAttributes(ObjectAttributes);
625 dump_ObjectAttributes(ReplacedObjectAttributes);
626 return STATUS_SUCCESS;
628 /******************************************************************************
629 * NtRestoreKey [NTDLL.@]
630 * ZwRestoreKey [NTDLL.@]
632 NTSTATUS WINAPI NtRestoreKey(
633 HKEY KeyHandle,
634 HANDLE FileHandle,
635 ULONG RestoreFlags)
637 FIXME("(%p,%p,0x%08lx) stub\n",
638 KeyHandle, FileHandle, RestoreFlags);
639 return STATUS_SUCCESS;
641 /******************************************************************************
642 * NtSaveKey [NTDLL.@]
643 * ZwSaveKey [NTDLL.@]
645 NTSTATUS WINAPI NtSaveKey(
646 IN HKEY KeyHandle,
647 IN HANDLE FileHandle)
649 FIXME("(%p,%p) stub\n",
650 KeyHandle, FileHandle);
651 return STATUS_SUCCESS;
653 /******************************************************************************
654 * NtSetInformationKey [NTDLL.@]
655 * ZwSetInformationKey [NTDLL.@]
657 NTSTATUS WINAPI NtSetInformationKey(
658 IN HKEY KeyHandle,
659 IN const int KeyInformationClass,
660 IN PVOID KeyInformation,
661 IN ULONG KeyInformationLength)
663 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
664 KeyHandle, KeyInformationClass, KeyInformation, KeyInformationLength);
665 return STATUS_SUCCESS;
669 /******************************************************************************
670 * NtSetValueKey [NTDLL.@]
671 * ZwSetValueKey [NTDLL.@]
673 * NOTES
674 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
675 * NT does definitely care (aj)
677 NTSTATUS WINAPI NtSetValueKey( HKEY hkey, const UNICODE_STRING *name, ULONG TitleIndex,
678 ULONG type, const void *data, ULONG count )
680 NTSTATUS ret;
682 TRACE( "(%p,%s,%ld,%p,%ld)\n", hkey, debugstr_us(name), type, data, count );
684 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
686 SERVER_START_REQ( set_key_value )
688 req->hkey = hkey;
689 req->type = type;
690 req->namelen = name->Length;
691 wine_server_add_data( req, name->Buffer, name->Length );
692 wine_server_add_data( req, data, count );
693 ret = wine_server_call( req );
695 SERVER_END_REQ;
696 return ret;
699 /******************************************************************************
700 * RtlpNtSetValueKey [NTDLL.@]
703 NTSTATUS WINAPI RtlpNtSetValueKey( HKEY hkey, ULONG type, const void *data,
704 ULONG count )
706 UNICODE_STRING name;
708 name.Length = 0;
709 return NtSetValueKey( hkey, &name, 0, type, data, count );
712 /******************************************************************************
713 * NtUnloadKey [NTDLL.@]
714 * ZwUnloadKey [NTDLL.@]
716 NTSTATUS WINAPI NtUnloadKey(
717 IN HKEY KeyHandle)
719 FIXME("(%p) stub\n",
720 KeyHandle);
721 return STATUS_SUCCESS;
724 /******************************************************************************
725 * RtlFormatCurrentUserKeyPath [NTDLL.@]
727 * NOTE: under NT the user name part of the path is an SID.
729 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
731 static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
732 const char *user = wine_get_user_name();
733 int len = ntdll_umbstowcs( 0, user, strlen(user)+1, NULL, 0 );
735 KeyPath->MaximumLength = sizeof(pathW) + len * sizeof(WCHAR);
736 KeyPath->Length = KeyPath->MaximumLength - sizeof(WCHAR);
737 if (!(KeyPath->Buffer = RtlAllocateHeap( GetProcessHeap(), 0, KeyPath->MaximumLength )))
738 return STATUS_NO_MEMORY;
739 memcpy( KeyPath->Buffer, pathW, sizeof(pathW) );
740 ntdll_umbstowcs( 0, user, strlen(user)+1, KeyPath->Buffer + sizeof(pathW)/sizeof(WCHAR), len );
741 return STATUS_SUCCESS;
744 /******************************************************************************
745 * RtlOpenCurrentUser [NTDLL.@]
747 * if we return just HKEY_CURRENT_USER the advapi tries to find a remote
748 * registry (odd handle) and fails
751 DWORD WINAPI RtlOpenCurrentUser(
752 IN ACCESS_MASK DesiredAccess, /* [in] */
753 OUT PHKEY KeyHandle) /* [out] handle of HKEY_CURRENT_USER */
755 OBJECT_ATTRIBUTES ObjectAttributes;
756 UNICODE_STRING ObjectName;
757 NTSTATUS ret;
759 TRACE("(0x%08lx, %p) stub\n",DesiredAccess, KeyHandle);
761 RtlFormatCurrentUserKeyPath(&ObjectName);
762 InitializeObjectAttributes(&ObjectAttributes,&ObjectName,OBJ_CASE_INSENSITIVE,0, NULL);
763 ret = NtCreateKey(KeyHandle, DesiredAccess, &ObjectAttributes, 0, NULL, 0, NULL);
764 RtlFreeUnicodeString(&ObjectName);
765 return ret;