1999-11-23 19:41:34 +00:00
/*
* Registry management
*
* Copyright ( C ) 1999 Alexandre Julliard
*
* Based on misc / registry . c code
* Copyright ( C ) 1996 Marcus Meissner
* Copyright ( C ) 1998 Matthew Becker
* Copyright ( C ) 1999 Sylvain St - Germain
*
* This file is concerned about handle management and interaction with the Wine server .
* Registry file I / O is in misc / registry . c .
2002-03-09 23:29:33 +00:00
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
1999-11-23 19:41:34 +00:00
*/
# include <stdlib.h>
2003-09-05 23:08:26 +00:00
# include <stdarg.h>
2000-02-10 22:15:21 +00:00
# include <stdio.h>
1999-11-23 19:41:34 +00:00
2003-09-05 23:08:26 +00:00
# include "windef.h"
1999-11-23 19:41:34 +00:00
# include "winbase.h"
# include "winreg.h"
# include "winerror.h"
2003-09-05 23:08:26 +00:00
# include "ntstatus.h"
2000-08-14 14:41:19 +00:00
# include "wine/unicode.h"
2001-07-19 00:39:09 +00:00
# include "wine/server.h"
2002-03-09 23:29:33 +00:00
# include "wine/debug.h"
2003-01-20 23:23:12 +00:00
# include "winternl.h"
1999-11-23 19:41:34 +00:00
2002-03-09 23:29:33 +00:00
WINE_DEFAULT_DEBUG_CHANNEL ( reg ) ;
1999-11-23 19:41:34 +00:00
2002-09-13 21:42:28 +00:00
/* allowed bits for access mask */
# define KEY_ACCESS_MASK (KEY_ALL_ACCESS | MAXIMUM_ALLOWED)
# define HKEY_SPECIAL_ROOT_FIRST HKEY_CLASSES_ROOT
# define HKEY_SPECIAL_ROOT_LAST HKEY_DYN_DATA
# define NB_SPECIAL_ROOT_KEYS ((UINT)HKEY_SPECIAL_ROOT_LAST - (UINT)HKEY_SPECIAL_ROOT_FIRST + 1)
static HKEY special_root_keys [ NB_SPECIAL_ROOT_KEYS ] ;
static const WCHAR name_CLASSES_ROOT [ ] =
{ ' M ' , ' a ' , ' c ' , ' h ' , ' i ' , ' n ' , ' e ' , ' \\ ' ,
' S ' , ' o ' , ' f ' , ' t ' , ' w ' , ' a ' , ' r ' , ' e ' , ' \\ ' ,
' C ' , ' l ' , ' a ' , ' s ' , ' s ' , ' e ' , ' s ' , 0 } ;
static const WCHAR name_LOCAL_MACHINE [ ] =
{ ' M ' , ' a ' , ' c ' , ' h ' , ' i ' , ' n ' , ' e ' , 0 } ;
static const WCHAR name_USERS [ ] =
{ ' U ' , ' s ' , ' e ' , ' r ' , 0 } ;
static const WCHAR name_PERFORMANCE_DATA [ ] =
{ ' P ' , ' e ' , ' r ' , ' f ' , ' D ' , ' a ' , ' t ' , ' a ' , 0 } ;
static const WCHAR name_CURRENT_CONFIG [ ] =
{ ' M ' , ' a ' , ' c ' , ' h ' , ' i ' , ' n ' , ' e ' , ' \\ ' ,
' S ' , ' y ' , ' s ' , ' t ' , ' e ' , ' m ' , ' \\ ' ,
' C ' , ' u ' , ' r ' , ' r ' , ' e ' , ' n ' , ' t ' , ' C ' , ' o ' , ' n ' , ' t ' , ' r ' , ' o ' , ' l ' , ' S ' , ' e ' , ' t ' , ' \\ ' ,
2004-08-26 18:22:58 +00:00
' H ' , ' a ' , ' r ' , ' d ' , ' w ' , ' a ' , ' r ' , ' e ' , ' ' , ' P ' , ' r ' , ' o ' , ' f ' , ' i ' , ' l ' , ' e ' , ' s ' , ' \\ ' ,
2002-09-13 21:42:28 +00:00
' C ' , ' u ' , ' r ' , ' r ' , ' e ' , ' n ' , ' t ' , 0 } ;
static const WCHAR name_DYN_DATA [ ] =
{ ' D ' , ' y ' , ' n ' , ' D ' , ' a ' , ' t ' , ' a ' , 0 } ;
# define DECL_STR(key) { sizeof(name_##key)-sizeof(WCHAR), sizeof(name_##key), (LPWSTR)name_##key }
static UNICODE_STRING root_key_names [ NB_SPECIAL_ROOT_KEYS ] =
{
DECL_STR ( CLASSES_ROOT ) ,
{ 0 , 0 , NULL } , /* HKEY_CURRENT_USER is determined dynamically */
DECL_STR ( LOCAL_MACHINE ) ,
DECL_STR ( USERS ) ,
DECL_STR ( PERFORMANCE_DATA ) ,
DECL_STR ( CURRENT_CONFIG ) ,
DECL_STR ( DYN_DATA )
} ;
# undef DECL_STR
1999-11-23 19:41:34 +00:00
/* check if value type needs string conversion (Ansi<->Unicode) */
2002-03-21 01:24:52 +00:00
inline static int is_string ( DWORD type )
1999-11-23 19:41:34 +00:00
{
return ( type = = REG_SZ ) | | ( type = = REG_EXPAND_SZ ) | | ( type = = REG_MULTI_SZ ) ;
}
2002-03-21 01:24:52 +00:00
/* check if current version is NT or Win95 */
inline static int is_version_nt ( void )
{
return ! ( GetVersion ( ) & 0x80000000 ) ;
}
1999-11-23 19:41:34 +00:00
2002-09-13 21:42:28 +00:00
/* create one of the HKEY_* special root keys */
static HKEY create_special_root_hkey ( HKEY hkey , DWORD access )
{
HKEY ret = 0 ;
int idx = ( UINT ) hkey - ( UINT ) HKEY_SPECIAL_ROOT_FIRST ;
if ( hkey = = HKEY_CURRENT_USER )
{
if ( RtlOpenCurrentUser ( access , & hkey ) ) return 0 ;
2002-10-25 19:17:33 +00:00
TRACE ( " HKEY_CURRENT_USER -> %p \n " , hkey ) ;
2002-09-13 21:42:28 +00:00
}
else
{
OBJECT_ATTRIBUTES attr ;
attr . Length = sizeof ( attr ) ;
attr . RootDirectory = 0 ;
attr . ObjectName = & root_key_names [ idx ] ;
attr . Attributes = 0 ;
attr . SecurityDescriptor = NULL ;
attr . SecurityQualityOfService = NULL ;
if ( NtCreateKey ( & hkey , access , & attr , 0 , NULL , 0 , NULL ) ) return 0 ;
2002-10-25 19:17:33 +00:00
TRACE ( " %s -> %p \n " , debugstr_w ( attr . ObjectName - > Buffer ) , hkey ) ;
2002-09-13 21:42:28 +00:00
}
2002-10-25 19:17:33 +00:00
if ( ! ( ret = InterlockedCompareExchangePointer ( ( void * * ) & special_root_keys [ idx ] , hkey , 0 ) ) )
2002-09-13 21:42:28 +00:00
ret = hkey ;
else
NtClose ( hkey ) ; /* somebody beat us to it */
return ret ;
}
/* map the hkey from special root to normal key if necessary */
inline static HKEY get_special_root_hkey ( HKEY hkey )
{
HKEY ret = hkey ;
if ( ( hkey > = HKEY_SPECIAL_ROOT_FIRST ) & & ( hkey < = HKEY_SPECIAL_ROOT_LAST ) )
{
if ( ! ( ret = special_root_keys [ ( UINT ) hkey - ( UINT ) HKEY_SPECIAL_ROOT_FIRST ] ) )
ret = create_special_root_hkey ( hkey , KEY_ALL_ACCESS ) ;
}
return ret ;
}
2002-05-09 19:39:10 +00:00
1999-11-23 19:41:34 +00:00
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegCreateKeyExW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
2004-04-23 21:32:34 +00:00
* See RegCreateKeyExA .
1999-11-23 19:41:34 +00:00
*/
2003-10-21 23:44:37 +00:00
DWORD WINAPI RegCreateKeyExW ( HKEY hkey , LPCWSTR name , DWORD reserved , LPCWSTR class ,
2002-05-31 23:06:46 +00:00
DWORD options , REGSAM access , SECURITY_ATTRIBUTES * sa ,
2002-10-03 19:46:27 +00:00
PHKEY retkey , LPDWORD dispos )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
OBJECT_ATTRIBUTES attr ;
UNICODE_STRING nameW , classW ;
1999-11-23 19:41:34 +00:00
if ( reserved ) return ERROR_INVALID_PARAMETER ;
2002-05-09 19:39:10 +00:00
if ( ! ( access & KEY_ACCESS_MASK ) | | ( access & ~ KEY_ACCESS_MASK ) ) return ERROR_ACCESS_DENIED ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
2000-10-01 01:44:50 +00:00
attr . Length = sizeof ( attr ) ;
attr . RootDirectory = hkey ;
attr . ObjectName = & nameW ;
attr . Attributes = 0 ;
attr . SecurityDescriptor = NULL ;
attr . SecurityQualityOfService = NULL ;
RtlInitUnicodeString ( & nameW , name ) ;
RtlInitUnicodeString ( & classW , class ) ;
return RtlNtStatusToDosError ( NtCreateKey ( retkey , access , & attr , 0 ,
& classW , options , dispos ) ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegCreateKeyExA [ ADVAPI32 . @ ]
2002-05-09 19:39:10 +00:00
*
2004-04-23 21:32:34 +00:00
* Open a registry key , creating it if it doesn ' t exist .
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of the parent registry key
* name [ I ] Name of the new key to open or create
* reserved [ I ] Reserved , pass 0
* class [ I ] The object type of the new key
* options [ I ] Flags controlling the key creation ( REG_OPTION_ * flags from " winnt.h " )
* access [ I ] Access level desired
* sa [ I ] Security attributes for the key
* retkey [ O ] Destination for the resulting handle
* dispos [ O ] Receives REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY
2004-04-23 21:32:34 +00:00
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS .
* Failure : A standard Win32 error code . retkey remains untouched .
2004-04-23 21:32:34 +00:00
*
* FIXME
2004-07-13 23:33:14 +00:00
* MAXIMUM_ALLOWED in access mask not supported by server
1999-11-23 19:41:34 +00:00
*/
2003-10-21 23:44:37 +00:00
DWORD WINAPI RegCreateKeyExA ( HKEY hkey , LPCSTR name , DWORD reserved , LPCSTR class ,
2002-05-31 23:06:46 +00:00
DWORD options , REGSAM access , SECURITY_ATTRIBUTES * sa ,
2002-10-03 19:46:27 +00:00
PHKEY retkey , LPDWORD dispos )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
OBJECT_ATTRIBUTES attr ;
2001-03-23 19:12:01 +00:00
UNICODE_STRING classW ;
2000-10-01 01:44:50 +00:00
ANSI_STRING nameA , classA ;
NTSTATUS status ;
1999-11-23 19:41:34 +00:00
if ( reserved ) return ERROR_INVALID_PARAMETER ;
2002-03-21 01:24:52 +00:00
if ( ! is_version_nt ( ) ) access = KEY_ALL_ACCESS ; /* Win95 ignores the access mask */
2002-05-09 19:39:10 +00:00
else if ( ! ( access & KEY_ACCESS_MASK ) | | ( access & ~ KEY_ACCESS_MASK ) ) return ERROR_ACCESS_DENIED ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
2000-10-01 01:44:50 +00:00
attr . Length = sizeof ( attr ) ;
attr . RootDirectory = hkey ;
2001-03-23 19:12:01 +00:00
attr . ObjectName = & NtCurrentTeb ( ) - > StaticUnicodeString ;
2000-10-01 01:44:50 +00:00
attr . Attributes = 0 ;
attr . SecurityDescriptor = NULL ;
attr . SecurityQualityOfService = NULL ;
RtlInitAnsiString ( & nameA , name ) ;
RtlInitAnsiString ( & classA , class ) ;
2001-03-23 19:12:01 +00:00
if ( ! ( status = RtlAnsiStringToUnicodeString ( & NtCurrentTeb ( ) - > StaticUnicodeString ,
& nameA , FALSE ) ) )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
if ( ! ( status = RtlAnsiStringToUnicodeString ( & classW , & classA , TRUE ) ) )
{
status = NtCreateKey ( retkey , access , & attr , 0 , & classW , options , dispos ) ;
RtlFreeUnicodeString ( & classW ) ;
}
1999-11-23 19:41:34 +00:00
}
2000-10-01 01:44:50 +00:00
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegCreateKeyW [ ADVAPI32 . @ ]
*
* Creates the specified reg key .
*
* PARAMS
* hKey [ I ] Handle to an open key .
* lpSubKey [ I ] Name of a key that will be opened or created .
* phkResult [ O ] Receives a handle to the opened or created key .
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code defined in Winerror . h
1999-11-23 19:41:34 +00:00
*/
2004-07-13 23:33:14 +00:00
DWORD WINAPI RegCreateKeyW ( HKEY hkey , LPCWSTR lpSubKey , PHKEY phkResult )
1999-11-23 19:41:34 +00:00
{
/* FIXME: previous implementation converted ERROR_INVALID_HANDLE to ERROR_BADKEY, */
/* but at least my version of NT (4.0 SP5) doesn't do this. -- AJ */
2004-07-13 23:33:14 +00:00
return RegCreateKeyExW ( hkey , lpSubKey , 0 , NULL , REG_OPTION_NON_VOLATILE ,
KEY_ALL_ACCESS , NULL , phkResult , NULL ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegCreateKeyA [ ADVAPI32 . @ ]
*
* see RegCreateKeyW
1999-11-23 19:41:34 +00:00
*/
2004-07-13 23:33:14 +00:00
DWORD WINAPI RegCreateKeyA ( HKEY hkey , LPCSTR lpSubKey , PHKEY phkResult )
1999-11-23 19:41:34 +00:00
{
2004-07-13 23:33:14 +00:00
return RegCreateKeyExA ( hkey , lpSubKey , 0 , NULL , REG_OPTION_NON_VOLATILE ,
KEY_ALL_ACCESS , NULL , phkResult , NULL ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegOpenKeyExW [ ADVAPI32 . @ ]
*
2004-04-23 21:32:34 +00:00
* See RegOpenKeyExA .
1999-11-23 19:41:34 +00:00
*/
2002-10-03 19:46:27 +00:00
DWORD WINAPI RegOpenKeyExW ( HKEY hkey , LPCWSTR name , DWORD reserved , REGSAM access , PHKEY retkey )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
OBJECT_ATTRIBUTES attr ;
UNICODE_STRING nameW ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2000-10-01 01:44:50 +00:00
attr . Length = sizeof ( attr ) ;
attr . RootDirectory = hkey ;
attr . ObjectName = & nameW ;
attr . Attributes = 0 ;
attr . SecurityDescriptor = NULL ;
attr . SecurityQualityOfService = NULL ;
RtlInitUnicodeString ( & nameW , name ) ;
return RtlNtStatusToDosError ( NtOpenKey ( retkey , access , & attr ) ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegOpenKeyExA [ ADVAPI32 . @ ]
2004-04-23 21:32:34 +00:00
*
* Open a registry key .
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of open key
* name [ I ] Name of subkey to open
* reserved [ I ] Reserved - must be zero
* access [ I ] Security access mask
* retkey [ O ] Handle to open key
2004-04-23 21:32:34 +00:00
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS
* Failure : A standard Win32 error code . retkey is set to 0.
2004-04-23 21:32:34 +00:00
*
* NOTES
2004-07-13 23:33:14 +00:00
* Unlike RegCreateKeyExA ( ) , this function will not create the key if it
* does not exist .
1999-11-23 19:41:34 +00:00
*/
2002-10-03 19:46:27 +00:00
DWORD WINAPI RegOpenKeyExA ( HKEY hkey , LPCSTR name , DWORD reserved , REGSAM access , PHKEY retkey )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
OBJECT_ATTRIBUTES attr ;
STRING nameA ;
NTSTATUS status ;
2002-03-21 01:24:52 +00:00
if ( ! is_version_nt ( ) ) access = KEY_ALL_ACCESS ; /* Win95 ignores the access mask */
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2000-10-01 01:44:50 +00:00
attr . Length = sizeof ( attr ) ;
attr . RootDirectory = hkey ;
2001-03-23 19:12:01 +00:00
attr . ObjectName = & NtCurrentTeb ( ) - > StaticUnicodeString ;
2000-10-01 01:44:50 +00:00
attr . Attributes = 0 ;
attr . SecurityDescriptor = NULL ;
attr . SecurityQualityOfService = NULL ;
RtlInitAnsiString ( & nameA , name ) ;
2001-03-23 19:12:01 +00:00
if ( ! ( status = RtlAnsiStringToUnicodeString ( & NtCurrentTeb ( ) - > StaticUnicodeString ,
& nameA , FALSE ) ) )
2000-10-01 01:44:50 +00:00
{
status = NtOpenKey ( retkey , access , & attr ) ;
}
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegOpenKeyW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
2004-04-23 21:32:34 +00:00
* See RegOpenKeyA .
1999-11-23 19:41:34 +00:00
*/
2002-10-03 19:46:27 +00:00
DWORD WINAPI RegOpenKeyW ( HKEY hkey , LPCWSTR name , PHKEY retkey )
1999-11-23 19:41:34 +00:00
{
2005-02-25 16:52:10 +00:00
if ( ! name | | ! * name )
{
* retkey = hkey ;
return ERROR_SUCCESS ;
}
1999-11-23 19:41:34 +00:00
return RegOpenKeyExW ( hkey , name , 0 , KEY_ALL_ACCESS , retkey ) ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegOpenKeyA [ ADVAPI32 . @ ]
2004-04-23 21:32:34 +00:00
*
* Open a registry key .
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of parent key to open the new key under
* name [ I ] Name of the key under hkey to open
* retkey [ O ] Destination for the resulting Handle
2004-04-23 21:32:34 +00:00
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS
* Failure : A standard Win32 error code . retkey is set to 0.
1999-11-23 19:41:34 +00:00
*/
2002-10-03 19:46:27 +00:00
DWORD WINAPI RegOpenKeyA ( HKEY hkey , LPCSTR name , PHKEY retkey )
1999-11-23 19:41:34 +00:00
{
2005-02-25 16:52:10 +00:00
if ( ! name | | ! * name )
{
* retkey = hkey ;
return ERROR_SUCCESS ;
}
1999-11-23 19:41:34 +00:00
return RegOpenKeyExA ( hkey , name , 0 , KEY_ALL_ACCESS , retkey ) ;
}
2000-10-29 01:24:54 +00:00
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegOpenCurrentUser [ ADVAPI32 . @ ]
*
2000-10-29 01:24:54 +00:00
* FIXME : This function is supposed to retrieve a handle to the
* HKEY_CURRENT_USER for the user the current thread is impersonating .
* Since Wine does not currently allow threads to impersonate other users ,
* this stub should work fine .
*/
DWORD WINAPI RegOpenCurrentUser ( REGSAM access , PHKEY retkey )
{
return RegOpenKeyExA ( HKEY_CURRENT_USER , " " , 0 , access , retkey ) ;
}
1999-11-23 19:41:34 +00:00
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegEnumKeyExW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle to key to enumerate
* index [ I ] Index of subkey to enumerate
* name [ O ] Buffer for subkey name
* name_len [ O ] Size of subkey buffer
* reserved [ I ] Reserved
* class [ O ] Buffer for class string
* class_len [ O ] Size of class buffer
* ft [ O ] Time key last written to
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : System error code . If there are no more subkeys available , the
* function returns ERROR_NO_MORE_ITEMS .
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegEnumKeyExW ( HKEY hkey , DWORD index , LPWSTR name , LPDWORD name_len ,
LPDWORD reserved , LPWSTR class , LPDWORD class_len , FILETIME * ft )
{
2000-10-02 03:46:58 +00:00
NTSTATUS status ;
char buffer [ 256 ] , * buf_ptr = buffer ;
KEY_NODE_INFORMATION * info = ( KEY_NODE_INFORMATION * ) buffer ;
DWORD total_size ;
1999-11-23 19:41:34 +00:00
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%ld,%p,%p(%ld),%p,%p,%p,%p) \n " , hkey , index , name , name_len ,
1999-11-23 19:41:34 +00:00
name_len ? * name_len : - 1 , reserved , class , class_len , ft ) ;
if ( reserved ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2002-07-05 01:21:13 +00:00
2000-10-02 03:46:58 +00:00
status = NtEnumerateKey ( hkey , index , KeyNodeInformation ,
buffer , sizeof ( buffer ) , & total_size ) ;
1999-11-23 19:41:34 +00:00
2000-10-02 03:46:58 +00:00
while ( status = = STATUS_BUFFER_OVERFLOW )
{
/* retry with a dynamically allocated buffer */
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
if ( ! ( buf_ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , total_size ) ) )
return ERROR_NOT_ENOUGH_MEMORY ;
info = ( KEY_NODE_INFORMATION * ) buf_ptr ;
status = NtEnumerateKey ( hkey , index , KeyNodeInformation ,
buf_ptr , total_size , & total_size ) ;
}
1999-11-23 19:41:34 +00:00
2000-10-02 03:46:58 +00:00
if ( ! status )
1999-11-23 19:41:34 +00:00
{
2000-10-02 03:46:58 +00:00
DWORD len = info - > NameLength / sizeof ( WCHAR ) ;
DWORD cls_len = info - > ClassLength / sizeof ( WCHAR ) ;
2001-11-23 18:44:43 +00:00
if ( ft ) * ft = * ( FILETIME * ) & info - > LastWriteTime ;
2000-10-02 03:46:58 +00:00
2002-02-05 19:45:55 +00:00
if ( len > = * name_len | | ( class & & class_len & & ( cls_len > = * class_len ) ) )
2000-10-02 03:46:58 +00:00
status = STATUS_BUFFER_OVERFLOW ;
else
{
* name_len = len ;
memcpy ( name , info - > Name , info - > NameLength ) ;
name [ len ] = 0 ;
if ( class_len )
{
* class_len = cls_len ;
if ( class )
{
memcpy ( class , buf_ptr + info - > ClassOffset , info - > ClassLength ) ;
class [ cls_len ] = 0 ;
}
}
}
1999-11-23 19:41:34 +00:00
}
2000-10-02 03:46:58 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegEnumKeyExA [ ADVAPI32 . @ ]
*
* see RegEnumKeyExW
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegEnumKeyExA ( HKEY hkey , DWORD index , LPSTR name , LPDWORD name_len ,
LPDWORD reserved , LPSTR class , LPDWORD class_len , FILETIME * ft )
{
2000-10-02 03:46:58 +00:00
NTSTATUS status ;
char buffer [ 256 ] , * buf_ptr = buffer ;
KEY_NODE_INFORMATION * info = ( KEY_NODE_INFORMATION * ) buffer ;
DWORD total_size ;
1999-11-23 19:41:34 +00:00
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%ld,%p,%p(%ld),%p,%p,%p,%p) \n " , hkey , index , name , name_len ,
1999-11-23 19:41:34 +00:00
name_len ? * name_len : - 1 , reserved , class , class_len , ft ) ;
if ( reserved ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2002-07-05 01:21:13 +00:00
2000-10-02 03:46:58 +00:00
status = NtEnumerateKey ( hkey , index , KeyNodeInformation ,
buffer , sizeof ( buffer ) , & total_size ) ;
1999-11-23 19:41:34 +00:00
2000-10-02 03:46:58 +00:00
while ( status = = STATUS_BUFFER_OVERFLOW )
{
/* retry with a dynamically allocated buffer */
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
if ( ! ( buf_ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , total_size ) ) )
return ERROR_NOT_ENOUGH_MEMORY ;
info = ( KEY_NODE_INFORMATION * ) buf_ptr ;
status = NtEnumerateKey ( hkey , index , KeyNodeInformation ,
buf_ptr , total_size , & total_size ) ;
}
1999-11-23 19:41:34 +00:00
2000-10-02 03:46:58 +00:00
if ( ! status )
1999-11-23 19:41:34 +00:00
{
2001-12-05 22:18:48 +00:00
DWORD len , cls_len ;
2000-10-02 03:46:58 +00:00
2001-12-05 22:18:48 +00:00
RtlUnicodeToMultiByteSize ( & len , info - > Name , info - > NameLength ) ;
RtlUnicodeToMultiByteSize ( & cls_len , ( WCHAR * ) ( buf_ptr + info - > ClassOffset ) ,
info - > ClassLength ) ;
2001-11-23 18:44:43 +00:00
if ( ft ) * ft = * ( FILETIME * ) & info - > LastWriteTime ;
2000-10-02 03:46:58 +00:00
2002-02-05 19:45:55 +00:00
if ( len > = * name_len | | ( class & & class_len & & ( cls_len > = * class_len ) ) )
2000-10-02 03:46:58 +00:00
status = STATUS_BUFFER_OVERFLOW ;
else
{
* name_len = len ;
2001-12-05 22:18:48 +00:00
RtlUnicodeToMultiByteN ( name , len , NULL , info - > Name , info - > NameLength ) ;
2000-10-02 03:46:58 +00:00
name [ len ] = 0 ;
if ( class_len )
{
* class_len = cls_len ;
if ( class )
{
2001-12-05 22:18:48 +00:00
RtlUnicodeToMultiByteN ( class , cls_len , NULL ,
( WCHAR * ) ( buf_ptr + info - > ClassOffset ) ,
info - > ClassLength ) ;
2000-10-02 03:46:58 +00:00
class [ cls_len ] = 0 ;
}
}
}
1999-11-23 19:41:34 +00:00
}
2000-10-02 03:46:58 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegEnumKeyW [ ADVAPI32 . @ ]
*
* Enumerates subkyes of the specified open reg key .
*
* PARAMS
* hKey [ I ] Handle to an open key .
* dwIndex [ I ] Index of the subkey of hKey to retrieve .
* lpName [ O ] Name of the subkey .
* cchName [ I ] Size of lpName in TCHARS .
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : system error code . If there are no more subkeys available , the
* function returns ERROR_NO_MORE_ITEMS .
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegEnumKeyW ( HKEY hkey , DWORD index , LPWSTR name , DWORD name_len )
{
return RegEnumKeyExW ( hkey , index , name , & name_len , NULL , NULL , NULL , NULL ) ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegEnumKeyA [ ADVAPI32 . @ ]
*
* see RegEnumKeyW
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegEnumKeyA ( HKEY hkey , DWORD index , LPSTR name , DWORD name_len )
{
return RegEnumKeyExA ( hkey , index , name , & name_len , NULL , NULL , NULL , NULL ) ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegQueryInfoKeyW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
* PARAMS
* hkey [ I ] Handle to key to query
* class [ O ] Buffer for class string
* class_len [ O ] Size of class string buffer
* reserved [ I ] Reserved
* subkeys [ O ] Buffer for number of subkeys
* max_subkey [ O ] Buffer for longest subkey name length
* max_class [ O ] Buffer for longest class string length
* values [ O ] Buffer for number of value entries
* max_value [ O ] Buffer for longest value name length
* max_data [ O ] Buffer for longest value data length
* security [ O ] Buffer for security descriptor length
* modif [ O ] Modification time
*
2002-05-31 23:06:46 +00:00
* - win95 allows class to be valid and class_len to be NULL
1999-11-23 19:41:34 +00:00
* - winnt returns ERROR_INVALID_PARAMETER if class is valid and class_len is NULL
2002-05-31 23:06:46 +00:00
* - both allow class to be NULL and class_len to be NULL
1999-11-23 19:41:34 +00:00
* ( it ' s hard to test validity , so test ! NULL instead )
*/
DWORD WINAPI RegQueryInfoKeyW ( HKEY hkey , LPWSTR class , LPDWORD class_len , LPDWORD reserved ,
LPDWORD subkeys , LPDWORD max_subkey , LPDWORD max_class ,
LPDWORD values , LPDWORD max_value , LPDWORD max_data ,
LPDWORD security , FILETIME * modif )
{
2000-10-02 03:46:58 +00:00
NTSTATUS status ;
char buffer [ 256 ] , * buf_ptr = buffer ;
KEY_FULL_INFORMATION * info = ( KEY_FULL_INFORMATION * ) buffer ;
DWORD total_size ;
1999-11-23 19:41:34 +00:00
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p) \n " , hkey , class , class_len ? * class_len : 0 ,
1999-11-23 19:41:34 +00:00
reserved , subkeys , max_subkey , values , max_value , max_data , security , modif ) ;
2002-03-21 01:24:52 +00:00
if ( class & & ! class_len & & is_version_nt ( ) ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
2000-10-02 03:46:58 +00:00
status = NtQueryKey ( hkey , KeyFullInformation , buffer , sizeof ( buffer ) , & total_size ) ;
2001-02-14 21:45:52 +00:00
if ( status & & status ! = STATUS_BUFFER_OVERFLOW ) goto done ;
1999-11-23 19:41:34 +00:00
if ( class )
{
2000-10-02 03:46:58 +00:00
/* retry with a dynamically allocated buffer */
while ( status = = STATUS_BUFFER_OVERFLOW )
1999-11-23 19:41:34 +00:00
{
2000-10-02 03:46:58 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
if ( ! ( buf_ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , total_size ) ) )
return ERROR_NOT_ENOUGH_MEMORY ;
info = ( KEY_FULL_INFORMATION * ) buf_ptr ;
status = NtQueryKey ( hkey , KeyFullInformation , buf_ptr , total_size , & total_size ) ;
}
2001-02-14 21:45:52 +00:00
if ( status ) goto done ;
if ( class_len & & ( info - > ClassLength / sizeof ( WCHAR ) + 1 > * class_len ) )
2000-10-02 03:46:58 +00:00
{
2001-02-14 21:45:52 +00:00
status = STATUS_BUFFER_OVERFLOW ;
}
else
{
memcpy ( class , buf_ptr + info - > ClassOffset , info - > ClassLength ) ;
class [ info - > ClassLength / sizeof ( WCHAR ) ] = 0 ;
1999-11-23 19:41:34 +00:00
}
}
2001-02-14 21:45:52 +00:00
else status = STATUS_SUCCESS ;
2000-10-02 03:46:58 +00:00
2001-02-14 21:45:52 +00:00
if ( class_len ) * class_len = info - > ClassLength / sizeof ( WCHAR ) ;
if ( subkeys ) * subkeys = info - > SubKeys ;
if ( max_subkey ) * max_subkey = info - > MaxNameLen ;
if ( max_class ) * max_class = info - > MaxClassLen ;
if ( values ) * values = info - > Values ;
if ( max_value ) * max_value = info - > MaxValueNameLen ;
if ( max_data ) * max_data = info - > MaxValueDataLen ;
2001-11-23 18:44:43 +00:00
if ( modif ) * modif = * ( FILETIME * ) & info - > LastWriteTime ;
2000-10-02 03:46:58 +00:00
2001-02-14 21:45:52 +00:00
done :
2000-10-02 03:46:58 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
2002-07-20 20:02:55 +00:00
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegQueryMultipleValuesA [ ADVAPI32 . @ ]
*
* Retrieves the type and data for a list of value names associated with a key .
*
* PARAMS
* hKey [ I ] Handle to an open key .
* val_list [ O ] Array of VALENT structures that describes the entries .
* num_vals [ I ] Number of elements in val_list .
* lpValueBuf [ O ] Pointer to a buffer that receives the data for each value .
* ldwTotsize [ I / O ] Size of lpValueBuf .
*
* RETURNS
* Success : ERROR_SUCCESS . ldwTotsize contains num bytes copied .
* Failure : nonzero error code from Winerror . h ldwTotsize contains num needed
* bytes .
2002-07-20 20:02:55 +00:00
*/
DWORD WINAPI RegQueryMultipleValuesA ( HKEY hkey , PVALENTA val_list , DWORD num_vals ,
LPSTR lpValueBuf , LPDWORD ldwTotsize )
{
2004-09-02 23:00:53 +00:00
unsigned int i ;
2002-07-20 20:02:55 +00:00
DWORD maxBytes = * ldwTotsize ;
HRESULT status ;
LPSTR bufptr = lpValueBuf ;
* ldwTotsize = 0 ;
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%p,%ld,%p,%p=%ld) \n " , hkey , val_list , num_vals , lpValueBuf , ldwTotsize , * ldwTotsize ) ;
2002-07-20 20:02:55 +00:00
for ( i = 0 ; i < num_vals ; + + i )
{
val_list [ i ] . ve_valuelen = 0 ;
status = RegQueryValueExA ( hkey , val_list [ i ] . ve_valuename , NULL , NULL , NULL , & val_list [ i ] . ve_valuelen ) ;
if ( status ! = ERROR_SUCCESS )
{
return status ;
}
if ( lpValueBuf ! = NULL & & * ldwTotsize + val_list [ i ] . ve_valuelen < = maxBytes )
{
status = RegQueryValueExA ( hkey , val_list [ i ] . ve_valuename , NULL , & val_list [ i ] . ve_type ,
bufptr , & val_list [ i ] . ve_valuelen ) ;
if ( status ! = ERROR_SUCCESS )
{
return status ;
}
val_list [ i ] . ve_valueptr = ( DWORD_PTR ) bufptr ;
bufptr + = val_list [ i ] . ve_valuelen ;
}
* ldwTotsize + = val_list [ i ] . ve_valuelen ;
}
return lpValueBuf ! = NULL & & * ldwTotsize < = maxBytes ? ERROR_SUCCESS : ERROR_MORE_DATA ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegQueryMultipleValuesW [ ADVAPI32 . @ ]
*
* see RegQueryMultipleValuesA
2002-07-20 20:02:55 +00:00
*/
DWORD WINAPI RegQueryMultipleValuesW ( HKEY hkey , PVALENTW val_list , DWORD num_vals ,
LPWSTR lpValueBuf , LPDWORD ldwTotsize )
{
2004-09-02 23:00:53 +00:00
unsigned int i ;
2002-07-20 20:02:55 +00:00
DWORD maxBytes = * ldwTotsize ;
HRESULT status ;
LPSTR bufptr = ( LPSTR ) lpValueBuf ;
* ldwTotsize = 0 ;
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%p,%ld,%p,%p=%ld) \n " , hkey , val_list , num_vals , lpValueBuf , ldwTotsize , * ldwTotsize ) ;
2002-07-20 20:02:55 +00:00
for ( i = 0 ; i < num_vals ; + + i )
{
val_list [ i ] . ve_valuelen = 0 ;
status = RegQueryValueExW ( hkey , val_list [ i ] . ve_valuename , NULL , NULL , NULL , & val_list [ i ] . ve_valuelen ) ;
if ( status ! = ERROR_SUCCESS )
{
return status ;
}
if ( lpValueBuf ! = NULL & & * ldwTotsize + val_list [ i ] . ve_valuelen < = maxBytes )
{
status = RegQueryValueExW ( hkey , val_list [ i ] . ve_valuename , NULL , & val_list [ i ] . ve_type ,
bufptr , & val_list [ i ] . ve_valuelen ) ;
if ( status ! = ERROR_SUCCESS )
{
return status ;
}
val_list [ i ] . ve_valueptr = ( DWORD_PTR ) bufptr ;
bufptr + = val_list [ i ] . ve_valuelen ;
}
* ldwTotsize + = val_list [ i ] . ve_valuelen ;
}
return lpValueBuf ! = NULL & & * ldwTotsize < = maxBytes ? ERROR_SUCCESS : ERROR_MORE_DATA ;
}
1999-11-23 19:41:34 +00:00
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegQueryInfoKeyA [ ADVAPI32 . @ ]
*
* Retrieves information about a registry key .
*
* PARAMS
* hKey [ I ] Handle to an open key .
* lpClass [ O ] Class string of the key .
* lpcClass [ I / O ] size of lpClass .
* lpReserved [ I ] Reserved ; must be NULL .
* lpcSubKeys [ O ] Number of subkeys contained by the key .
* lpcMaxSubKeyLen [ O ] Size of the key ' s subkey with the longest name .
* lpcMaxClassLen [ O ] Size of the longest string specifying a subkey
* class in TCHARS .
* lpcValues [ O ] Number of values associated with the key .
* lpcMaxValueNameLen [ O ] Size of the key ' s longest value name in TCHARS .
* lpcMaxValueLen [ O ] Longest data component among the key ' s values
* lpcbSecurityDescriptor [ O ] Size of the key ' s security descriptor .
* lpftLastWriteTime [ O ] FILETIME strucutre that is the last write time .
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegQueryInfoKeyA ( HKEY hkey , LPSTR class , LPDWORD class_len , LPDWORD reserved ,
LPDWORD subkeys , LPDWORD max_subkey , LPDWORD max_class ,
LPDWORD values , LPDWORD max_value , LPDWORD max_data ,
LPDWORD security , FILETIME * modif )
{
2000-10-02 03:46:58 +00:00
NTSTATUS status ;
char buffer [ 256 ] , * buf_ptr = buffer ;
KEY_FULL_INFORMATION * info = ( KEY_FULL_INFORMATION * ) buffer ;
2001-02-14 21:45:52 +00:00
DWORD total_size , len ;
1999-11-23 19:41:34 +00:00
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p) \n " , hkey , class , class_len ? * class_len : 0 ,
1999-11-23 19:41:34 +00:00
reserved , subkeys , max_subkey , values , max_value , max_data , security , modif ) ;
2002-03-21 01:24:52 +00:00
if ( class & & ! class_len & & is_version_nt ( ) ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
2000-10-02 03:46:58 +00:00
status = NtQueryKey ( hkey , KeyFullInformation , buffer , sizeof ( buffer ) , & total_size ) ;
2001-02-14 21:45:52 +00:00
if ( status & & status ! = STATUS_BUFFER_OVERFLOW ) goto done ;
1999-11-23 19:41:34 +00:00
2000-10-02 03:46:58 +00:00
if ( class | | class_len )
1999-11-23 19:41:34 +00:00
{
2000-10-02 03:46:58 +00:00
/* retry with a dynamically allocated buffer */
while ( status = = STATUS_BUFFER_OVERFLOW )
{
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
if ( ! ( buf_ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , total_size ) ) )
return ERROR_NOT_ENOUGH_MEMORY ;
info = ( KEY_FULL_INFORMATION * ) buf_ptr ;
status = NtQueryKey ( hkey , KeyFullInformation , buf_ptr , total_size , & total_size ) ;
}
2001-02-14 21:45:52 +00:00
if ( status ) goto done ;
2001-12-05 22:18:48 +00:00
RtlUnicodeToMultiByteSize ( & len , ( WCHAR * ) ( buf_ptr + info - > ClassOffset ) , info - > ClassLength ) ;
2001-02-14 21:45:52 +00:00
if ( class_len )
1999-11-23 19:41:34 +00:00
{
2001-02-14 21:45:52 +00:00
if ( len + 1 > * class_len ) status = STATUS_BUFFER_OVERFLOW ;
* class_len = len ;
}
if ( class & & ! status )
{
2001-12-05 22:18:48 +00:00
RtlUnicodeToMultiByteN ( class , len , NULL , ( WCHAR * ) ( buf_ptr + info - > ClassOffset ) ,
info - > ClassLength ) ;
2001-02-14 21:45:52 +00:00
class [ len ] = 0 ;
1999-11-23 19:41:34 +00:00
}
}
2001-02-14 21:45:52 +00:00
else status = STATUS_SUCCESS ;
2000-10-02 03:46:58 +00:00
2001-02-14 21:45:52 +00:00
if ( subkeys ) * subkeys = info - > SubKeys ;
if ( max_subkey ) * max_subkey = info - > MaxNameLen ;
if ( max_class ) * max_class = info - > MaxClassLen ;
if ( values ) * values = info - > Values ;
if ( max_value ) * max_value = info - > MaxValueNameLen ;
if ( max_data ) * max_data = info - > MaxValueDataLen ;
2001-11-23 18:44:43 +00:00
if ( modif ) * modif = * ( FILETIME * ) & info - > LastWriteTime ;
2000-10-02 03:46:58 +00:00
2001-02-14 21:45:52 +00:00
done :
2000-10-02 03:46:58 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegCloseKey [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
2004-04-23 21:32:34 +00:00
* Close an open registry key .
1999-11-23 19:41:34 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of key to close
1999-11-23 19:41:34 +00:00
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS
* Failure : Error code
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegCloseKey ( HKEY hkey )
{
2005-02-25 16:52:10 +00:00
if ( ! hkey ) return ERROR_INVALID_HANDLE ;
2005-02-21 20:37:26 +00:00
if ( hkey > = ( HKEY ) 0x80000000 ) return ERROR_SUCCESS ;
2000-10-01 01:44:50 +00:00
return RtlNtStatusToDosError ( NtClose ( hkey ) ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegDeleteKeyW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
2004-04-23 21:32:34 +00:00
* See RegDeleteKeyA .
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegDeleteKeyW ( HKEY hkey , LPCWSTR name )
{
DWORD ret ;
2000-10-01 01:44:50 +00:00
HKEY tmp ;
1999-11-23 19:41:34 +00:00
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2002-06-14 23:35:37 +00:00
if ( ! name | | ! * name )
2000-10-01 01:44:50 +00:00
{
2002-06-14 23:35:37 +00:00
ret = RtlNtStatusToDosError ( NtDeleteKey ( hkey ) ) ;
}
2002-09-12 20:47:14 +00:00
else if ( ! ( ret = RegOpenKeyExW ( hkey , name , 0 , KEY_ENUMERATE_SUB_KEYS , & tmp ) ) )
2002-06-14 23:35:37 +00:00
{
2000-10-01 01:44:50 +00:00
ret = RtlNtStatusToDosError ( NtDeleteKey ( tmp ) ) ;
RegCloseKey ( tmp ) ;
}
2002-06-14 23:35:37 +00:00
TRACE ( " %s ret=%08lx \n " , debugstr_w ( name ) , ret ) ;
2000-10-01 01:44:50 +00:00
return ret ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegDeleteKeyA [ ADVAPI32 . @ ]
2004-04-23 21:32:34 +00:00
*
* Delete a registry key .
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle to parent key containing the key to delete
* name [ I ] Name of the key user hkey to delete
2004-04-23 21:32:34 +00:00
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS
* Failure : Error code
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegDeleteKeyA ( HKEY hkey , LPCSTR name )
{
DWORD ret ;
2000-10-01 01:44:50 +00:00
HKEY tmp ;
1999-11-23 19:41:34 +00:00
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2002-06-14 23:35:37 +00:00
if ( ! name | | ! * name )
2000-10-01 01:44:50 +00:00
{
2002-06-14 23:35:37 +00:00
ret = RtlNtStatusToDosError ( NtDeleteKey ( hkey ) ) ;
}
2002-09-12 20:47:14 +00:00
else if ( ! ( ret = RegOpenKeyExA ( hkey , name , 0 , KEY_ENUMERATE_SUB_KEYS , & tmp ) ) )
2002-06-14 23:35:37 +00:00
{
if ( ! is_version_nt ( ) ) /* win95 does recursive key deletes */
{
CHAR name [ MAX_PATH ] ;
2003-06-18 19:45:22 +00:00
while ( ! RegEnumKeyA ( tmp , 0 , name , sizeof ( name ) ) )
2002-06-14 23:35:37 +00:00
{
if ( RegDeleteKeyA ( tmp , name ) ) /* recurse */
break ;
}
}
2000-10-01 01:44:50 +00:00
ret = RtlNtStatusToDosError ( NtDeleteKey ( tmp ) ) ;
RegCloseKey ( tmp ) ;
}
2002-06-14 23:35:37 +00:00
TRACE ( " %s ret=%08lx \n " , debugstr_a ( name ) , ret ) ;
2000-10-01 01:44:50 +00:00
return ret ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegSetValueExW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
2004-04-23 21:32:34 +00:00
* Set the data and contents of a registry value .
1999-11-23 19:41:34 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of key to set value for
* name [ I ] Name of value to set
* reserved [ I ] Reserved , must be zero
* type [ I ] Type of the value being set
* data [ I ] The new contents of the value to set
* count [ I ] Size of data
1999-11-23 19:41:34 +00:00
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS
* Failure : Error code
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegSetValueExW ( HKEY hkey , LPCWSTR name , DWORD reserved ,
DWORD type , CONST BYTE * data , DWORD count )
{
2000-10-01 01:44:50 +00:00
UNICODE_STRING nameW ;
1999-11-23 19:41:34 +00:00
2004-07-24 02:32:50 +00:00
/* no need for version check, not implemented on win9x anyway */
if ( count & & is_string ( type ) )
1999-11-23 19:41:34 +00:00
{
LPCWSTR str = ( LPCWSTR ) data ;
/* if user forgot to count terminating null, add it (yes NT does this) */
if ( str [ count / sizeof ( WCHAR ) - 1 ] & & ! str [ count / sizeof ( WCHAR ) ] )
count + = sizeof ( WCHAR ) ;
}
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2000-05-14 22:57:57 +00:00
2000-10-01 01:44:50 +00:00
RtlInitUnicodeString ( & nameW , name ) ;
return RtlNtStatusToDosError ( NtSetValueKey ( hkey , & nameW , 0 , type , data , count ) ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegSetValueExA [ ADVAPI32 . @ ]
*
* see RegSetValueExW
2004-07-24 02:32:50 +00:00
*
* NOTES
* win95 does not care about count for REG_SZ and finds out the len by itself ( js )
* NT does definitely care ( aj )
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegSetValueExA ( HKEY hkey , LPCSTR name , DWORD reserved , DWORD type ,
2000-10-01 01:44:50 +00:00
CONST BYTE * data , DWORD count )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
ANSI_STRING nameA ;
WCHAR * dataW = NULL ;
NTSTATUS status ;
1999-11-23 19:41:34 +00:00
2002-03-21 01:24:52 +00:00
if ( ! is_version_nt ( ) ) /* win95 */
2001-04-10 21:30:24 +00:00
{
2004-07-24 02:32:50 +00:00
if ( type = = REG_SZ )
{
if ( ! data ) return ERROR_INVALID_PARAMETER ;
count = strlen ( data ) + 1 ;
}
2001-04-10 21:30:24 +00:00
}
else if ( count & & is_string ( type ) )
1999-11-23 19:41:34 +00:00
{
/* if user forgot to count terminating null, add it (yes NT does this) */
if ( data [ count - 1 ] & & ! data [ count ] ) count + + ;
}
2000-05-14 22:57:57 +00:00
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2000-10-01 01:44:50 +00:00
if ( is_string ( type ) ) /* need to convert to Unicode */
2000-05-14 22:57:57 +00:00
{
2001-12-05 22:18:48 +00:00
DWORD lenW ;
RtlMultiByteToUnicodeSize ( & lenW , data , count ) ;
if ( ! ( dataW = HeapAlloc ( GetProcessHeap ( ) , 0 , lenW ) ) ) return ERROR_OUTOFMEMORY ;
RtlMultiByteToUnicodeN ( dataW , lenW , NULL , data , count ) ;
count = lenW ;
2000-10-01 01:44:50 +00:00
data = ( BYTE * ) dataW ;
}
2000-05-14 22:57:57 +00:00
2000-10-01 01:44:50 +00:00
RtlInitAnsiString ( & nameA , name ) ;
2001-03-23 19:12:01 +00:00
if ( ! ( status = RtlAnsiStringToUnicodeString ( & NtCurrentTeb ( ) - > StaticUnicodeString ,
& nameA , FALSE ) ) )
2000-10-01 01:44:50 +00:00
{
2001-03-23 19:12:01 +00:00
status = NtSetValueKey ( hkey , & NtCurrentTeb ( ) - > StaticUnicodeString , 0 , type , data , count ) ;
2000-05-14 22:57:57 +00:00
}
2004-12-23 17:06:43 +00:00
HeapFree ( GetProcessHeap ( ) , 0 , dataW ) ;
2000-10-01 01:44:50 +00:00
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegSetValueW [ ADVAPI32 . @ ]
*
* Sets the data for the default or unnamed value of a reg key .
*
* PARAMS
* hKey [ I ] Handle to an open key .
* lpSubKey [ I ] Name of a subkey of hKey .
* dwType [ I ] Type of information to store .
* lpData [ I ] String that contains the data to set for the default value .
* cbData [ I ] Size of lpData .
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegSetValueW ( HKEY hkey , LPCWSTR name , DWORD type , LPCWSTR data , DWORD count )
{
HKEY subkey = hkey ;
DWORD ret ;
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%s,%ld,%s,%ld) \n " , hkey , debugstr_w ( name ) , type , debugstr_w ( data ) , count ) ;
1999-11-23 19:41:34 +00:00
if ( type ! = REG_SZ ) return ERROR_INVALID_PARAMETER ;
if ( name & & name [ 0 ] ) /* need to create the subkey */
{
if ( ( ret = RegCreateKeyW ( hkey , name , & subkey ) ) ! = ERROR_SUCCESS ) return ret ;
}
2004-11-30 21:38:57 +00:00
ret = RegSetValueExW ( subkey , NULL , 0 , REG_SZ , ( const BYTE * ) data ,
2000-08-14 14:41:19 +00:00
( strlenW ( data ) + 1 ) * sizeof ( WCHAR ) ) ;
1999-11-23 19:41:34 +00:00
if ( subkey ! = hkey ) RegCloseKey ( subkey ) ;
return ret ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegSetValueA [ ADVAPI32 . @ ]
*
* see RegSetValueW
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegSetValueA ( HKEY hkey , LPCSTR name , DWORD type , LPCSTR data , DWORD count )
{
HKEY subkey = hkey ;
DWORD ret ;
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%s,%ld,%s,%ld) \n " , hkey , debugstr_a ( name ) , type , debugstr_a ( data ) , count ) ;
1999-11-23 19:41:34 +00:00
if ( type ! = REG_SZ ) return ERROR_INVALID_PARAMETER ;
if ( name & & name [ 0 ] ) /* need to create the subkey */
{
if ( ( ret = RegCreateKeyA ( hkey , name , & subkey ) ) ! = ERROR_SUCCESS ) return ret ;
}
2004-11-30 21:38:57 +00:00
ret = RegSetValueExA ( subkey , NULL , 0 , REG_SZ , ( const BYTE * ) data , strlen ( data ) + 1 ) ;
1999-11-23 19:41:34 +00:00
if ( subkey ! = hkey ) RegCloseKey ( subkey ) ;
return ret ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegQueryValueExW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
2004-04-23 21:32:34 +00:00
* See RegQueryValueExA .
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegQueryValueExW ( HKEY hkey , LPCWSTR name , LPDWORD reserved , LPDWORD type ,
2000-10-01 01:44:50 +00:00
LPBYTE data , LPDWORD count )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
NTSTATUS status ;
UNICODE_STRING name_str ;
DWORD total_size ;
2000-10-02 03:46:58 +00:00
char buffer [ 256 ] , * buf_ptr = buffer ;
2000-10-01 01:44:50 +00:00
KEY_VALUE_PARTIAL_INFORMATION * info = ( KEY_VALUE_PARTIAL_INFORMATION * ) buffer ;
2002-07-05 21:30:38 +00:00
static const int info_size = offsetof ( KEY_VALUE_PARTIAL_INFORMATION , Data ) ;
1999-11-23 19:41:34 +00:00
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%s,%p,%p,%p,%p=%ld) \n " ,
2003-12-13 01:34:40 +00:00
hkey , debugstr_w ( name ) , reserved , type , data , count ,
( count & & data ) ? * count : 0 ) ;
1999-11-23 19:41:34 +00:00
1999-11-25 22:05:46 +00:00
if ( ( data & & ! count ) | | reserved ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
2000-10-01 01:44:50 +00:00
RtlInitUnicodeString ( & name_str , name ) ;
if ( data ) total_size = min ( sizeof ( buffer ) , * count + info_size ) ;
else total_size = info_size ;
status = NtQueryValueKey ( hkey , & name_str , KeyValuePartialInformation ,
buffer , total_size , & total_size ) ;
if ( status & & status ! = STATUS_BUFFER_OVERFLOW ) goto done ;
2000-05-14 22:57:57 +00:00
if ( data )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
/* retry with a dynamically allocated buffer */
while ( status = = STATUS_BUFFER_OVERFLOW & & total_size - info_size < = * count )
2000-05-14 22:57:57 +00:00
{
2000-10-01 01:44:50 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
if ( ! ( buf_ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , total_size ) ) )
2000-10-02 03:46:58 +00:00
return ERROR_NOT_ENOUGH_MEMORY ;
info = ( KEY_VALUE_PARTIAL_INFORMATION * ) buf_ptr ;
status = NtQueryValueKey ( hkey , & name_str , KeyValuePartialInformation ,
buf_ptr , total_size , & total_size ) ;
2000-10-01 01:44:50 +00:00
}
if ( ! status )
{
memcpy ( data , buf_ptr + info_size , total_size - info_size ) ;
/* if the type is REG_SZ and data is not 0-terminated
* and there is enough space in the buffer NT appends a \ 0 */
if ( total_size - info_size < = * count - sizeof ( WCHAR ) & & is_string ( info - > Type ) )
2000-05-14 22:57:57 +00:00
{
2000-10-01 01:44:50 +00:00
WCHAR * ptr = ( WCHAR * ) ( data + total_size - info_size ) ;
if ( ptr > ( WCHAR * ) data & & ptr [ - 1 ] ) * ptr = 0 ;
2000-05-14 22:57:57 +00:00
}
}
2000-10-02 03:46:58 +00:00
else if ( status ! = STATUS_BUFFER_OVERFLOW ) goto done ;
1999-11-23 19:41:34 +00:00
}
2001-02-14 21:45:52 +00:00
else status = STATUS_SUCCESS ;
2000-10-01 01:44:50 +00:00
if ( type ) * type = info - > Type ;
if ( count ) * count = total_size - info_size ;
done :
2000-10-02 03:46:58 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
2000-10-01 01:44:50 +00:00
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegQueryValueExA [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
2004-04-23 21:32:34 +00:00
* Get the type and contents of a specified value under with a key .
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of the key to query
* name [ I ] Name of value under hkey to query
* reserved [ I ] Reserved - must be NULL
* type [ O ] Destination for the value type , or NULL if not required
* data [ O ] Destination for the values contents , or NULL if not required
* count [ I / O ] Size of data , updated with the number of bytes returned
2004-04-23 21:32:34 +00:00
*
* RETURNS
* Success : ERROR_SUCCESS . * count is updated with the number of bytes copied to data .
* Failure : ERROR_INVALID_HANDLE , if hkey is invalid .
* ERROR_INVALID_PARAMETER , if any other parameter is invalid .
* ERROR_MORE_DATA , if on input * count is too small to hold the contents .
*
* NOTES
* MSDN states that if data is too small it is partially filled . In reality
* it remains untouched .
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegQueryValueExA ( HKEY hkey , LPCSTR name , LPDWORD reserved , LPDWORD type ,
2000-10-01 01:44:50 +00:00
LPBYTE data , LPDWORD count )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
NTSTATUS status ;
ANSI_STRING nameA ;
DWORD total_size ;
2000-10-02 03:46:58 +00:00
char buffer [ 256 ] , * buf_ptr = buffer ;
2000-10-01 01:44:50 +00:00
KEY_VALUE_PARTIAL_INFORMATION * info = ( KEY_VALUE_PARTIAL_INFORMATION * ) buffer ;
2002-07-05 21:30:38 +00:00
static const int info_size = offsetof ( KEY_VALUE_PARTIAL_INFORMATION , Data ) ;
1999-11-23 19:41:34 +00:00
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%s,%p,%p,%p,%p=%ld) \n " ,
1999-11-23 19:41:34 +00:00
hkey , debugstr_a ( name ) , reserved , type , data , count , count ? * count : 0 ) ;
1999-11-25 22:05:46 +00:00
if ( ( data & & ! count ) | | reserved ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
2000-10-01 01:44:50 +00:00
RtlInitAnsiString ( & nameA , name ) ;
2001-03-23 19:12:01 +00:00
if ( ( status = RtlAnsiStringToUnicodeString ( & NtCurrentTeb ( ) - > StaticUnicodeString ,
& nameA , FALSE ) ) )
2000-10-02 03:46:58 +00:00
return RtlNtStatusToDosError ( status ) ;
2000-05-14 22:57:57 +00:00
2001-03-23 19:12:01 +00:00
status = NtQueryValueKey ( hkey , & NtCurrentTeb ( ) - > StaticUnicodeString ,
KeyValuePartialInformation , buffer , sizeof ( buffer ) , & total_size ) ;
2000-10-01 01:44:50 +00:00
if ( status & & status ! = STATUS_BUFFER_OVERFLOW ) goto done ;
2000-05-14 22:57:57 +00:00
2000-10-01 01:44:50 +00:00
/* we need to fetch the contents for a string type even if not requested,
* because we need to compute the length of the ASCII string . */
if ( data | | is_string ( info - > Type ) )
1999-11-23 19:41:34 +00:00
{
2000-10-01 01:44:50 +00:00
/* retry with a dynamically allocated buffer */
while ( status = = STATUS_BUFFER_OVERFLOW )
2000-05-14 22:57:57 +00:00
{
2000-10-01 01:44:50 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
if ( ! ( buf_ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , total_size ) ) )
2000-10-02 03:46:58 +00:00
{
2000-10-01 01:44:50 +00:00
status = STATUS_NO_MEMORY ;
2000-10-02 03:46:58 +00:00
goto done ;
}
info = ( KEY_VALUE_PARTIAL_INFORMATION * ) buf_ptr ;
2001-03-23 19:12:01 +00:00
status = NtQueryValueKey ( hkey , & NtCurrentTeb ( ) - > StaticUnicodeString ,
KeyValuePartialInformation , buf_ptr , total_size , & total_size ) ;
2000-10-01 01:44:50 +00:00
}
2001-02-14 21:45:52 +00:00
if ( status ) goto done ;
if ( is_string ( info - > Type ) )
2000-10-01 01:44:50 +00:00
{
2001-12-05 22:18:48 +00:00
DWORD len ;
RtlUnicodeToMultiByteSize ( & len , ( WCHAR * ) ( buf_ptr + info_size ) ,
total_size - info_size ) ;
2001-02-14 21:45:52 +00:00
if ( data & & len )
2000-05-14 22:57:57 +00:00
{
2001-02-14 21:45:52 +00:00
if ( len > * count ) status = STATUS_BUFFER_OVERFLOW ;
else
2000-10-01 01:44:50 +00:00
{
2001-12-05 22:18:48 +00:00
RtlUnicodeToMultiByteN ( data , len , NULL , ( WCHAR * ) ( buf_ptr + info_size ) ,
total_size - info_size ) ;
2001-02-14 21:45:52 +00:00
/* if the type is REG_SZ and data is not 0-terminated
* and there is enough space in the buffer NT appends a \ 0 */
if ( len < * count & & data [ len - 1 ] ) data [ len ] = 0 ;
2000-10-01 01:44:50 +00:00
}
2000-10-15 00:40:25 +00:00
}
2001-02-14 21:45:52 +00:00
total_size = len + info_size ;
}
else if ( data )
{
if ( total_size - info_size > * count ) status = STATUS_BUFFER_OVERFLOW ;
else memcpy ( data , buf_ptr + info_size , total_size - info_size ) ;
2000-05-14 22:57:57 +00:00
}
1999-11-23 19:41:34 +00:00
}
2001-02-14 21:45:52 +00:00
else status = STATUS_SUCCESS ;
2000-05-14 22:57:57 +00:00
2000-10-01 01:44:50 +00:00
if ( type ) * type = info - > Type ;
if ( count ) * count = total_size - info_size ;
done :
2000-10-02 03:46:58 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
2000-10-01 01:44:50 +00:00
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegQueryValueW [ ADVAPI32 . @ ]
*
* Retrieves the data associated with the default or unnamed value of a key .
*
* PARAMS
2004-10-19 21:14:09 +00:00
* hkey [ I ] Handle to an open key .
* name [ I ] Name of the subkey of hKey .
* data [ O ] Receives the string associated with the default value
2004-07-13 23:33:14 +00:00
* of the key .
2004-10-19 21:14:09 +00:00
* count [ I / O ] Size of lpValue in bytes .
2004-07-13 23:33:14 +00:00
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegQueryValueW ( HKEY hkey , LPCWSTR name , LPWSTR data , LPLONG count )
{
DWORD ret ;
HKEY subkey = hkey ;
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%s,%p,%ld) \n " , hkey , debugstr_w ( name ) , data , count ? * count : 0 ) ;
1999-11-23 19:41:34 +00:00
if ( name & & name [ 0 ] )
{
if ( ( ret = RegOpenKeyW ( hkey , name , & subkey ) ) ! = ERROR_SUCCESS ) return ret ;
}
ret = RegQueryValueExW ( subkey , NULL , NULL , NULL , ( LPBYTE ) data , count ) ;
if ( subkey ! = hkey ) RegCloseKey ( subkey ) ;
if ( ret = = ERROR_FILE_NOT_FOUND )
{
/* return empty string if default value not found */
if ( data ) * data = 0 ;
2004-10-19 21:14:09 +00:00
if ( count ) * count = sizeof ( WCHAR ) ;
1999-11-23 19:41:34 +00:00
ret = ERROR_SUCCESS ;
}
return ret ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegQueryValueA [ ADVAPI32 . @ ]
*
* see RegQueryValueW
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegQueryValueA ( HKEY hkey , LPCSTR name , LPSTR data , LPLONG count )
{
DWORD ret ;
HKEY subkey = hkey ;
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%s,%p,%ld) \n " , hkey , debugstr_a ( name ) , data , count ? * count : 0 ) ;
1999-11-23 19:41:34 +00:00
if ( name & & name [ 0 ] )
{
if ( ( ret = RegOpenKeyA ( hkey , name , & subkey ) ) ! = ERROR_SUCCESS ) return ret ;
}
ret = RegQueryValueExA ( subkey , NULL , NULL , NULL , ( LPBYTE ) data , count ) ;
if ( subkey ! = hkey ) RegCloseKey ( subkey ) ;
if ( ret = = ERROR_FILE_NOT_FOUND )
{
/* return empty string if default value not found */
if ( data ) * data = 0 ;
if ( count ) * count = 1 ;
ret = ERROR_SUCCESS ;
}
return ret ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegEnumValueW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle to key to query
* index [ I ] Index of value to query
* value [ O ] Value string
* val_count [ I / O ] Size of value buffer ( in wchars )
* reserved [ I ] Reserved
* type [ O ] Type code
* data [ O ] Value data
* count [ I / O ] Size of data buffer ( in bytes )
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegEnumValueW ( HKEY hkey , DWORD index , LPWSTR value , LPDWORD val_count ,
LPDWORD reserved , LPDWORD type , LPBYTE data , LPDWORD count )
{
2000-12-15 20:57:00 +00:00
NTSTATUS status ;
DWORD total_size ;
char buffer [ 256 ] , * buf_ptr = buffer ;
KEY_VALUE_FULL_INFORMATION * info = ( KEY_VALUE_FULL_INFORMATION * ) buffer ;
2002-07-05 21:30:38 +00:00
static const int info_size = offsetof ( KEY_VALUE_FULL_INFORMATION , Name ) ;
1999-11-23 19:41:34 +00:00
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%ld,%p,%p,%p,%p,%p,%p) \n " ,
1999-11-23 19:41:34 +00:00
hkey , index , value , val_count , reserved , type , data , count ) ;
/* NT only checks count, not val_count */
1999-11-25 22:05:46 +00:00
if ( ( data & & ! count ) | | reserved ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
2000-12-15 20:57:00 +00:00
total_size = info_size + ( MAX_PATH + 1 ) * sizeof ( WCHAR ) ;
if ( data ) total_size + = * count ;
total_size = min ( sizeof ( buffer ) , total_size ) ;
1999-11-23 19:41:34 +00:00
2000-12-15 20:57:00 +00:00
status = NtEnumerateValueKey ( hkey , index , KeyValueFullInformation ,
buffer , total_size , & total_size ) ;
if ( status & & status ! = STATUS_BUFFER_OVERFLOW ) goto done ;
1999-11-23 19:41:34 +00:00
2000-12-15 20:57:00 +00:00
if ( value | | data )
2000-05-14 22:57:57 +00:00
{
2000-12-15 20:57:00 +00:00
/* retry with a dynamically allocated buffer */
while ( status = = STATUS_BUFFER_OVERFLOW )
{
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
if ( ! ( buf_ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , total_size ) ) )
return ERROR_NOT_ENOUGH_MEMORY ;
info = ( KEY_VALUE_FULL_INFORMATION * ) buf_ptr ;
status = NtEnumerateValueKey ( hkey , index , KeyValueFullInformation ,
buf_ptr , total_size , & total_size ) ;
}
if ( status ) goto done ;
if ( value )
{
if ( info - > NameLength / sizeof ( WCHAR ) > = * val_count )
{
status = STATUS_BUFFER_OVERFLOW ;
2002-07-10 03:27:35 +00:00
goto overflow ;
2000-12-15 20:57:00 +00:00
}
memcpy ( value , info - > Name , info - > NameLength ) ;
* val_count = info - > NameLength / sizeof ( WCHAR ) ;
value [ * val_count ] = 0 ;
}
if ( data )
2000-05-14 22:57:57 +00:00
{
2000-12-15 20:57:00 +00:00
if ( total_size - info - > DataOffset > * count )
2000-05-14 22:57:57 +00:00
{
2000-12-15 20:57:00 +00:00
status = STATUS_BUFFER_OVERFLOW ;
2002-07-10 03:27:35 +00:00
goto overflow ;
2000-12-15 20:57:00 +00:00
}
memcpy ( data , buf_ptr + info - > DataOffset , total_size - info - > DataOffset ) ;
if ( total_size - info - > DataOffset < = * count - sizeof ( WCHAR ) & & is_string ( info - > Type ) )
{
/* if the type is REG_SZ and data is not 0-terminated
* and there is enough space in the buffer NT appends a \ 0 */
WCHAR * ptr = ( WCHAR * ) ( data + total_size - info - > DataOffset ) ;
if ( ptr > ( WCHAR * ) data & & ptr [ - 1 ] ) * ptr = 0 ;
2000-05-14 22:57:57 +00:00
}
}
}
2001-02-14 21:45:52 +00:00
else status = STATUS_SUCCESS ;
2000-12-15 20:57:00 +00:00
2002-07-10 03:27:35 +00:00
overflow :
2000-12-15 20:57:00 +00:00
if ( type ) * type = info - > Type ;
if ( count ) * count = info - > DataLength ;
done :
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegEnumValueA [ ADVAPI32 . @ ]
*
* see RegEnumValueW
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegEnumValueA ( HKEY hkey , DWORD index , LPSTR value , LPDWORD val_count ,
LPDWORD reserved , LPDWORD type , LPBYTE data , LPDWORD count )
{
2000-12-15 20:57:00 +00:00
NTSTATUS status ;
DWORD total_size ;
char buffer [ 256 ] , * buf_ptr = buffer ;
KEY_VALUE_FULL_INFORMATION * info = ( KEY_VALUE_FULL_INFORMATION * ) buffer ;
2002-07-05 21:30:38 +00:00
static const int info_size = offsetof ( KEY_VALUE_FULL_INFORMATION , Name ) ;
1999-11-23 19:41:34 +00:00
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%ld,%p,%p,%p,%p,%p,%p) \n " ,
1999-11-23 19:41:34 +00:00
hkey , index , value , val_count , reserved , type , data , count ) ;
/* NT only checks count, not val_count */
1999-11-25 22:05:46 +00:00
if ( ( data & & ! count ) | | reserved ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
2000-12-15 20:57:00 +00:00
total_size = info_size + ( MAX_PATH + 1 ) * sizeof ( WCHAR ) ;
if ( data ) total_size + = * count ;
total_size = min ( sizeof ( buffer ) , total_size ) ;
1999-11-23 19:41:34 +00:00
2000-12-15 20:57:00 +00:00
status = NtEnumerateValueKey ( hkey , index , KeyValueFullInformation ,
buffer , total_size , & total_size ) ;
if ( status & & status ! = STATUS_BUFFER_OVERFLOW ) goto done ;
2000-05-14 22:57:57 +00:00
2000-12-15 20:57:00 +00:00
/* we need to fetch the contents for a string type even if not requested,
* because we need to compute the length of the ASCII string . */
if ( value | | data | | is_string ( info - > Type ) )
2000-05-14 22:57:57 +00:00
{
2000-12-15 20:57:00 +00:00
/* retry with a dynamically allocated buffer */
while ( status = = STATUS_BUFFER_OVERFLOW )
2000-05-14 22:57:57 +00:00
{
2000-12-15 20:57:00 +00:00
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
if ( ! ( buf_ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , total_size ) ) )
return ERROR_NOT_ENOUGH_MEMORY ;
info = ( KEY_VALUE_FULL_INFORMATION * ) buf_ptr ;
status = NtEnumerateValueKey ( hkey , index , KeyValueFullInformation ,
buf_ptr , total_size , & total_size ) ;
}
if ( status ) goto done ;
if ( is_string ( info - > Type ) )
{
2001-12-05 22:18:48 +00:00
DWORD len ;
RtlUnicodeToMultiByteSize ( & len , ( WCHAR * ) ( buf_ptr + info - > DataOffset ) ,
total_size - info - > DataOffset ) ;
2000-12-15 20:57:00 +00:00
if ( data & & len )
{
2002-07-10 03:27:35 +00:00
if ( len > * count ) status = STATUS_BUFFER_OVERFLOW ;
else
2000-12-15 20:57:00 +00:00
{
2002-07-10 03:27:35 +00:00
RtlUnicodeToMultiByteN ( data , len , NULL , ( WCHAR * ) ( buf_ptr + info - > DataOffset ) ,
total_size - info - > DataOffset ) ;
/* if the type is REG_SZ and data is not 0-terminated
* and there is enough space in the buffer NT appends a \ 0 */
if ( len < * count & & data [ len - 1 ] ) data [ len ] = 0 ;
2000-12-15 20:57:00 +00:00
}
2000-05-14 22:57:57 +00:00
}
2000-12-15 20:57:00 +00:00
info - > DataLength = len ;
}
else if ( data )
{
if ( total_size - info - > DataOffset > * count ) status = STATUS_BUFFER_OVERFLOW ;
else memcpy ( data , buf_ptr + info - > DataOffset , total_size - info - > DataOffset ) ;
2000-05-14 22:57:57 +00:00
}
2002-07-10 03:27:35 +00:00
if ( value & & ! status )
{
DWORD len ;
RtlUnicodeToMultiByteSize ( & len , info - > Name , info - > NameLength ) ;
if ( len > = * val_count )
{
status = STATUS_BUFFER_OVERFLOW ;
if ( * val_count )
{
len = * val_count - 1 ;
RtlUnicodeToMultiByteN ( value , len , NULL , info - > Name , info - > NameLength ) ;
value [ len ] = 0 ;
}
}
else
{
RtlUnicodeToMultiByteN ( value , len , NULL , info - > Name , info - > NameLength ) ;
value [ len ] = 0 ;
* val_count = len ;
}
}
2000-05-14 22:57:57 +00:00
}
2001-02-14 21:45:52 +00:00
else status = STATUS_SUCCESS ;
2000-05-14 22:57:57 +00:00
2000-12-15 20:57:00 +00:00
if ( type ) * type = info - > Type ;
if ( count ) * count = info - > DataLength ;
done :
if ( buf_ptr ! = buffer ) HeapFree ( GetProcessHeap ( ) , 0 , buf_ptr ) ;
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegDeleteValueW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
2003-03-18 18:35:48 +00:00
* See RegDeleteValueA .
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegDeleteValueW ( HKEY hkey , LPCWSTR name )
{
2000-10-01 01:44:50 +00:00
UNICODE_STRING nameW ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2000-10-01 01:44:50 +00:00
RtlInitUnicodeString ( & nameW , name ) ;
return RtlNtStatusToDosError ( NtDeleteValueKey ( hkey , & nameW ) ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegDeleteValueA [ ADVAPI32 . @ ]
2003-03-18 18:35:48 +00:00
*
* Delete a value from the registry .
*
* PARAMS
* hkey [ I ] Registry handle of the key holding the value
* name [ I ] Name of the value under hkey to delete
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
1999-11-23 19:41:34 +00:00
*/
DWORD WINAPI RegDeleteValueA ( HKEY hkey , LPCSTR name )
{
2000-10-01 01:44:50 +00:00
STRING nameA ;
NTSTATUS status ;
1999-11-23 19:41:34 +00:00
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
2000-10-01 01:44:50 +00:00
RtlInitAnsiString ( & nameA , name ) ;
2001-03-23 19:12:01 +00:00
if ( ! ( status = RtlAnsiStringToUnicodeString ( & NtCurrentTeb ( ) - > StaticUnicodeString ,
& nameA , FALSE ) ) )
status = NtDeleteValueKey ( hkey , & NtCurrentTeb ( ) - > StaticUnicodeString ) ;
2000-10-01 01:44:50 +00:00
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegLoadKeyW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of open key
* subkey [ I ] Address of name of subkey
* filename [ I ] Address of filename for registry information
*
* RETURNS
* Success : ERROR_SUCCES
* Failure : nonzero error code from Winerror . h
1999-11-23 19:41:34 +00:00
*/
LONG WINAPI RegLoadKeyW ( HKEY hkey , LPCWSTR subkey , LPCWSTR filename )
{
2005-03-29 11:38:58 +00:00
OBJECT_ATTRIBUTES destkey , file ;
UNICODE_STRING subkeyW , filenameW ;
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
destkey . Length = sizeof ( destkey ) ;
destkey . RootDirectory = hkey ; /* root key: HKLM or HKU */
destkey . ObjectName = & subkeyW ; /* name of the key */
destkey . Attributes = 0 ;
destkey . SecurityDescriptor = NULL ;
destkey . SecurityQualityOfService = NULL ;
RtlInitUnicodeString ( & subkeyW , subkey ) ;
file . Length = sizeof ( file ) ;
file . RootDirectory = NULL ;
file . ObjectName = & filenameW ; /* file containing the hive */
file . Attributes = OBJ_CASE_INSENSITIVE ;
file . SecurityDescriptor = NULL ;
file . SecurityQualityOfService = NULL ;
RtlDosPathNameToNtPathName_U ( filename , & filenameW , NULL , NULL ) ;
return RtlNtStatusToDosError ( NtLoadKey ( & destkey , & file ) ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegLoadKeyA [ ADVAPI32 . @ ]
*
* see RegLoadKeyW
1999-11-23 19:41:34 +00:00
*/
LONG WINAPI RegLoadKeyA ( HKEY hkey , LPCSTR subkey , LPCSTR filename )
{
2005-03-29 11:38:58 +00:00
UNICODE_STRING subkeyW , filenameW ;
STRING subkeyA , filenameA ;
NTSTATUS status ;
2000-10-15 00:40:25 +00:00
2005-03-29 11:38:58 +00:00
RtlInitAnsiString ( & subkeyA , subkey ) ;
RtlInitAnsiString ( & filenameA , filename ) ;
2000-10-15 00:40:25 +00:00
2005-03-29 11:38:58 +00:00
if ( ( status = RtlAnsiStringToUnicodeString ( & subkeyW , & subkeyA , TRUE ) ) )
return RtlNtStatusToDosError ( status ) ;
2002-11-13 19:45:27 +00:00
2005-03-29 11:38:58 +00:00
if ( ( status = RtlAnsiStringToUnicodeString ( & filenameW , & filenameA , TRUE ) ) )
return RtlNtStatusToDosError ( status ) ;
1999-11-23 19:41:34 +00:00
2005-03-29 11:38:58 +00:00
return RegLoadKeyW ( hkey , subkeyW . Buffer , filenameW . Buffer ) ;
1999-11-23 19:41:34 +00:00
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegSaveKeyW [ ADVAPI32 . @ ]
1999-11-23 19:41:34 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of key where save begins
* lpFile [ I ] Address of filename to save to
* sa [ I ] Address of security structure
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
1999-11-23 19:41:34 +00:00
*/
2003-03-14 04:50:34 +00:00
LONG WINAPI RegSaveKeyW ( HKEY hkey , LPCWSTR file , LPSECURITY_ATTRIBUTES sa )
1999-11-23 19:41:34 +00:00
{
2003-03-14 04:50:34 +00:00
static const WCHAR format [ ] =
{ ' r ' , ' e ' , ' g ' , ' % ' , ' 0 ' , ' 4 ' , ' x ' , ' . ' , ' t ' , ' m ' , ' p ' , 0 } ;
WCHAR buffer [ MAX_PATH ] ;
1999-11-23 19:41:34 +00:00
int count = 0 ;
2003-03-14 04:50:34 +00:00
LPWSTR nameW ;
1999-11-23 19:41:34 +00:00
DWORD ret , err ;
2002-07-31 19:26:03 +00:00
HANDLE handle ;
1999-11-23 19:41:34 +00:00
2003-03-14 04:50:34 +00:00
TRACE ( " (%p,%s,%p) \n " , hkey , debugstr_w ( file ) , sa ) ;
1999-11-23 19:41:34 +00:00
if ( ! file | | ! * file ) return ERROR_INVALID_PARAMETER ;
2002-09-13 21:42:28 +00:00
if ( ! ( hkey = get_special_root_hkey ( hkey ) ) ) return ERROR_INVALID_HANDLE ;
1999-11-23 19:41:34 +00:00
err = GetLastError ( ) ;
2003-03-14 04:50:34 +00:00
GetFullPathNameW ( file , sizeof ( buffer ) / sizeof ( WCHAR ) , buffer , & nameW ) ;
1999-11-23 19:41:34 +00:00
for ( ; ; )
{
2003-03-14 04:50:34 +00:00
snprintfW ( nameW , 16 , format , count + + ) ;
handle = CreateFileW ( buffer , GENERIC_WRITE , 0 , NULL ,
2001-01-06 01:29:18 +00:00
CREATE_NEW , FILE_ATTRIBUTE_NORMAL , 0 ) ;
1999-11-23 19:41:34 +00:00
if ( handle ! = INVALID_HANDLE_VALUE ) break ;
2000-03-26 18:18:03 +00:00
if ( ( ret = GetLastError ( ) ) ! = ERROR_ALREADY_EXISTS ) goto done ;
2000-05-09 22:31:43 +00:00
/* Something gone haywire ? Please report if this happens abnormally */
if ( count > = 100 )
2003-03-14 04:50:34 +00:00
MESSAGE ( " Wow, we are already fiddling with a temp file %s with an ordinal as high as %d ! \n You might want to delete all corresponding temp files in that directory. \n " , debugstr_w ( buffer ) , count ) ;
1999-11-23 19:41:34 +00:00
}
2001-02-27 02:09:16 +00:00
SERVER_START_REQ ( save_registry )
2000-10-15 00:40:25 +00:00
{
req - > hkey = hkey ;
req - > file = handle ;
2001-11-30 18:46:42 +00:00
ret = RtlNtStatusToDosError ( wine_server_call ( req ) ) ;
2000-10-15 00:40:25 +00:00
}
SERVER_END_REQ ;
1999-11-23 19:41:34 +00:00
CloseHandle ( handle ) ;
if ( ! ret )
{
2003-03-14 04:50:34 +00:00
if ( ! MoveFileExW ( buffer , file , MOVEFILE_REPLACE_EXISTING ) )
1999-11-23 19:41:34 +00:00
{
2003-03-14 04:50:34 +00:00
ERR ( " Failed to move %s to %s \n " , debugstr_w ( buffer ) ,
debugstr_w ( file ) ) ;
1999-11-23 19:41:34 +00:00
ret = GetLastError ( ) ;
}
}
2003-03-14 04:50:34 +00:00
if ( ret ) DeleteFileW ( buffer ) ;
1999-11-23 19:41:34 +00:00
done :
SetLastError ( err ) ; /* restore last error code */
return ret ;
}
/******************************************************************************
2004-07-13 23:33:14 +00:00
* RegSaveKeyA [ ADVAPI32 . @ ]
*
* see RegSaveKeyW
1999-11-23 19:41:34 +00:00
*/
2003-03-14 04:50:34 +00:00
LONG WINAPI RegSaveKeyA ( HKEY hkey , LPCSTR file , LPSECURITY_ATTRIBUTES sa )
1999-11-23 19:41:34 +00:00
{
2003-03-14 04:50:34 +00:00
UNICODE_STRING * fileW = & NtCurrentTeb ( ) - > StaticUnicodeString ;
NTSTATUS status ;
STRING fileA ;
RtlInitAnsiString ( & fileA , file ) ;
if ( ( status = RtlAnsiStringToUnicodeString ( fileW , & fileA , FALSE ) ) )
return RtlNtStatusToDosError ( status ) ;
return RegSaveKeyW ( hkey , fileW - > Buffer , sa ) ;
1999-11-23 19:41:34 +00:00
}
2000-11-30 20:31:41 +00:00
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegRestoreKeyW [ ADVAPI32 . @ ]
2000-11-30 20:31:41 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of key where restore begins
* lpFile [ I ] Address of filename containing saved tree
* dwFlags [ I ] Optional flags
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
2000-11-30 20:31:41 +00:00
*/
LONG WINAPI RegRestoreKeyW ( HKEY hkey , LPCWSTR lpFile , DWORD dwFlags )
{
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%s,%ld) \n " , hkey , debugstr_w ( lpFile ) , dwFlags ) ;
2000-11-30 20:31:41 +00:00
/* It seems to do this check before the hkey check */
if ( ! lpFile | | ! * lpFile )
return ERROR_INVALID_PARAMETER ;
2002-10-25 19:17:33 +00:00
FIXME ( " (%p,%s,%ld): stub \n " , hkey , debugstr_w ( lpFile ) , dwFlags ) ;
2000-11-30 20:31:41 +00:00
/* Check for file existence */
return ERROR_SUCCESS ;
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegRestoreKeyA [ ADVAPI32 . @ ]
2004-07-13 23:33:14 +00:00
*
* see RegRestoreKeyW
2000-11-30 20:31:41 +00:00
*/
LONG WINAPI RegRestoreKeyA ( HKEY hkey , LPCSTR lpFile , DWORD dwFlags )
{
2003-01-20 23:23:12 +00:00
UNICODE_STRING lpFileW ;
LONG ret ;
RtlCreateUnicodeStringFromAsciiz ( & lpFileW , lpFile ) ;
ret = RegRestoreKeyW ( hkey , lpFileW . Buffer , dwFlags ) ;
RtlFreeUnicodeString ( & lpFileW ) ;
2000-11-30 20:31:41 +00:00
return ret ;
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegUnLoadKeyW [ ADVAPI32 . @ ]
2000-11-30 20:31:41 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of open key
* lpSubKey [ I ] Address of name of subkey to unload
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
2000-11-30 20:31:41 +00:00
*/
LONG WINAPI RegUnLoadKeyW ( HKEY hkey , LPCWSTR lpSubKey )
{
2003-08-19 03:08:17 +00:00
DWORD ret ;
HKEY shkey ;
TRACE ( " (%p,%s) \n " , hkey , debugstr_w ( lpSubKey ) ) ;
ret = RegOpenKeyW ( hkey , lpSubKey , & shkey ) ;
if ( ret )
return ERROR_INVALID_PARAMETER ;
SERVER_START_REQ ( unload_registry )
{
req - > hkey = shkey ;
ret = RtlNtStatusToDosError ( wine_server_call ( req ) ) ;
}
SERVER_END_REQ ;
RegCloseKey ( shkey ) ;
return ret ;
2000-11-30 20:31:41 +00:00
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegUnLoadKeyA [ ADVAPI32 . @ ]
2004-07-13 23:33:14 +00:00
*
* see RegUnLoadKeyW
2000-11-30 20:31:41 +00:00
*/
LONG WINAPI RegUnLoadKeyA ( HKEY hkey , LPCSTR lpSubKey )
{
2003-01-20 23:23:12 +00:00
UNICODE_STRING lpSubKeyW ;
LONG ret ;
RtlCreateUnicodeStringFromAsciiz ( & lpSubKeyW , lpSubKey ) ;
ret = RegUnLoadKeyW ( hkey , lpSubKeyW . Buffer ) ;
RtlFreeUnicodeString ( & lpSubKeyW ) ;
2000-11-30 20:31:41 +00:00
return ret ;
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegReplaceKeyW [ ADVAPI32 . @ ]
2000-11-30 20:31:41 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of open key
* lpSubKey [ I ] Address of name of subkey
* lpNewFile [ I ] Address of filename for file with new data
* lpOldFile [ I ] Address of filename for backup file
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
2000-11-30 20:31:41 +00:00
*/
LONG WINAPI RegReplaceKeyW ( HKEY hkey , LPCWSTR lpSubKey , LPCWSTR lpNewFile ,
LPCWSTR lpOldFile )
{
2002-10-25 19:17:33 +00:00
FIXME ( " (%p,%s,%s,%s): stub \n " , hkey , debugstr_w ( lpSubKey ) ,
2000-11-30 20:31:41 +00:00
debugstr_w ( lpNewFile ) , debugstr_w ( lpOldFile ) ) ;
return ERROR_SUCCESS ;
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegReplaceKeyA [ ADVAPI32 . @ ]
2004-07-13 23:33:14 +00:00
*
* see RegReplaceKeyW
2000-11-30 20:31:41 +00:00
*/
LONG WINAPI RegReplaceKeyA ( HKEY hkey , LPCSTR lpSubKey , LPCSTR lpNewFile ,
LPCSTR lpOldFile )
{
2003-01-20 23:23:12 +00:00
UNICODE_STRING lpSubKeyW ;
UNICODE_STRING lpNewFileW ;
UNICODE_STRING lpOldFileW ;
LONG ret ;
RtlCreateUnicodeStringFromAsciiz ( & lpSubKeyW , lpSubKey ) ;
RtlCreateUnicodeStringFromAsciiz ( & lpOldFileW , lpOldFile ) ;
RtlCreateUnicodeStringFromAsciiz ( & lpNewFileW , lpNewFile ) ;
ret = RegReplaceKeyW ( hkey , lpSubKeyW . Buffer , lpNewFileW . Buffer , lpOldFileW . Buffer ) ;
RtlFreeUnicodeString ( & lpOldFileW ) ;
RtlFreeUnicodeString ( & lpNewFileW ) ;
RtlFreeUnicodeString ( & lpSubKeyW ) ;
2000-11-30 20:31:41 +00:00
return ret ;
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegSetKeySecurity [ ADVAPI32 . @ ]
2000-11-30 20:31:41 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Open handle of key to set
* SecurityInfo [ I ] Descriptor contents
* pSecurityDesc [ I ] Address of descriptor for key
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
2000-11-30 20:31:41 +00:00
*/
LONG WINAPI RegSetKeySecurity ( HKEY hkey , SECURITY_INFORMATION SecurityInfo ,
PSECURITY_DESCRIPTOR pSecurityDesc )
{
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%ld,%p) \n " , hkey , SecurityInfo , pSecurityDesc ) ;
2000-11-30 20:31:41 +00:00
/* It seems to perform this check before the hkey check */
if ( ( SecurityInfo & OWNER_SECURITY_INFORMATION ) | |
( SecurityInfo & GROUP_SECURITY_INFORMATION ) | |
( SecurityInfo & DACL_SECURITY_INFORMATION ) | |
( SecurityInfo & SACL_SECURITY_INFORMATION ) ) {
/* Param OK */
} else
return ERROR_INVALID_PARAMETER ;
if ( ! pSecurityDesc )
return ERROR_INVALID_PARAMETER ;
2002-10-25 19:17:33 +00:00
FIXME ( " :(%p,%ld,%p): stub \n " , hkey , SecurityInfo , pSecurityDesc ) ;
2000-11-30 20:31:41 +00:00
return ERROR_SUCCESS ;
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegGetKeySecurity [ ADVAPI32 . @ ]
2004-04-23 21:32:34 +00:00
*
* Get a copy of the security descriptor for a given registry key .
2000-11-30 20:31:41 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Open handle of key to set
* SecurityInformation [ I ] Descriptor contents
* pSecurityDescriptor [ O ] Address of descriptor for key
* lpcbSecurityDescriptor [ I / O ] Address of size of buffer and description
2000-11-30 20:31:41 +00:00
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS
* Failure : Error code
2000-11-30 20:31:41 +00:00
*/
LONG WINAPI RegGetKeySecurity ( HKEY hkey , SECURITY_INFORMATION SecurityInformation ,
PSECURITY_DESCRIPTOR pSecurityDescriptor ,
LPDWORD lpcbSecurityDescriptor )
{
2002-10-25 19:17:33 +00:00
TRACE ( " (%p,%ld,%p,%ld) \n " , hkey , SecurityInformation , pSecurityDescriptor ,
2000-11-30 20:31:41 +00:00
lpcbSecurityDescriptor ? * lpcbSecurityDescriptor : 0 ) ;
/* FIXME: Check for valid SecurityInformation values */
if ( * lpcbSecurityDescriptor < sizeof ( SECURITY_DESCRIPTOR ) )
return ERROR_INSUFFICIENT_BUFFER ;
2002-10-25 19:17:33 +00:00
FIXME ( " (%p,%ld,%p,%ld): stub \n " , hkey , SecurityInformation ,
2000-11-30 20:31:41 +00:00
pSecurityDescriptor , lpcbSecurityDescriptor ? * lpcbSecurityDescriptor : 0 ) ;
2002-04-02 02:41:27 +00:00
/* Do not leave security descriptor filled with garbage */
RtlCreateSecurityDescriptor ( pSecurityDescriptor , SECURITY_DESCRIPTOR_REVISION ) ;
2000-11-30 20:31:41 +00:00
return ERROR_SUCCESS ;
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegFlushKey [ ADVAPI32 . @ ]
2004-04-23 21:32:34 +00:00
*
* Immediately write a registry key to registry .
2000-11-30 20:31:41 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of key to write
2000-11-30 20:31:41 +00:00
*
* RETURNS
2004-07-13 23:33:14 +00:00
* Success : ERROR_SUCCESS
* Failure : Error code
2000-11-30 20:31:41 +00:00
*/
DWORD WINAPI RegFlushKey ( HKEY hkey )
{
2004-01-03 00:38:30 +00:00
hkey = get_special_root_hkey ( hkey ) ;
if ( ! hkey ) return ERROR_INVALID_HANDLE ;
return RtlNtStatusToDosError ( NtFlushKey ( hkey ) ) ;
2000-11-30 20:31:41 +00:00
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegConnectRegistryW [ ADVAPI32 . @ ]
2000-11-30 20:31:41 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* lpMachineName [ I ] Address of name of remote computer
* hHey [ I ] Predefined registry handle
* phkResult [ I ] Address of buffer for remote registry handle
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
2000-11-30 20:31:41 +00:00
*/
2002-05-31 23:06:46 +00:00
LONG WINAPI RegConnectRegistryW ( LPCWSTR lpMachineName , HKEY hKey ,
2002-10-03 19:46:27 +00:00
PHKEY phkResult )
2000-11-30 20:31:41 +00:00
{
2004-03-18 01:34:23 +00:00
LONG ret ;
2002-10-25 19:17:33 +00:00
TRACE ( " (%s,%p,%p): stub \n " , debugstr_w ( lpMachineName ) , hKey , phkResult ) ;
2000-11-30 20:31:41 +00:00
if ( ! lpMachineName | | ! * lpMachineName ) {
/* Use the local machine name */
2004-03-18 01:34:23 +00:00
ret = RegOpenKeyW ( hKey , NULL , phkResult ) ;
2000-11-30 20:31:41 +00:00
}
2004-03-18 01:34:23 +00:00
else if ( lpMachineName [ 0 ] ! = ' \\ ' | | lpMachineName [ 1 ] ! = ' \\ ' )
ret = ERROR_BAD_NETPATH ;
else
{
WCHAR compName [ MAX_COMPUTERNAME_LENGTH + 1 ] ;
DWORD len = sizeof ( compName ) / sizeof ( WCHAR ) ;
2000-11-30 20:31:41 +00:00
2004-03-18 01:34:23 +00:00
if ( GetComputerNameW ( compName , & len ) )
{
if ( ! strcmpiW ( lpMachineName + 2 , compName ) )
ret = RegOpenKeyW ( hKey , NULL , phkResult ) ;
else
{
FIXME ( " Cannot connect to %s \n " , debugstr_w ( lpMachineName ) ) ;
ret = ERROR_BAD_NETPATH ;
}
}
else
ret = GetLastError ( ) ;
}
return ret ;
2000-11-30 20:31:41 +00:00
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegConnectRegistryA [ ADVAPI32 . @ ]
2004-07-13 23:33:14 +00:00
*
* see RegConnectRegistryW
2000-11-30 20:31:41 +00:00
*/
2002-10-03 19:46:27 +00:00
LONG WINAPI RegConnectRegistryA ( LPCSTR machine , HKEY hkey , PHKEY reskey )
2000-11-30 20:31:41 +00:00
{
2003-01-20 23:23:12 +00:00
UNICODE_STRING machineW ;
LONG ret ;
RtlCreateUnicodeStringFromAsciiz ( & machineW , machine ) ;
ret = RegConnectRegistryW ( machineW . Buffer , hkey , reskey ) ;
RtlFreeUnicodeString ( & machineW ) ;
2000-11-30 20:31:41 +00:00
return ret ;
}
/******************************************************************************
2001-02-14 23:11:17 +00:00
* RegNotifyChangeKeyValue [ ADVAPI32 . @ ]
2000-11-30 20:31:41 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hkey [ I ] Handle of key to watch
* fWatchSubTree [ I ] Flag for subkey notification
* fdwNotifyFilter [ I ] Changes to be reported
* hEvent [ I ] Handle of signaled event
* fAsync [ I ] Flag for asynchronous reporting
*
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
2000-11-30 20:31:41 +00:00
*/
2002-05-31 23:06:46 +00:00
LONG WINAPI RegNotifyChangeKeyValue ( HKEY hkey , BOOL fWatchSubTree ,
2000-11-30 20:31:41 +00:00
DWORD fdwNotifyFilter , HANDLE hEvent ,
BOOL fAsync )
{
2002-11-25 02:47:32 +00:00
LONG ret ;
TRACE ( " (%p,%i,%ld,%p,%i) \n " , hkey , fWatchSubTree , fdwNotifyFilter ,
2000-11-30 20:31:41 +00:00
hEvent , fAsync ) ;
2002-11-25 02:47:32 +00:00
if ( ! fAsync )
2005-01-07 15:40:09 +00:00
hEvent = CreateEventW ( NULL , 0 , 0 , NULL ) ;
2002-11-25 02:47:32 +00:00
SERVER_START_REQ ( set_registry_notification )
{
req - > hkey = hkey ;
req - > event = hEvent ;
req - > subtree = fWatchSubTree ;
req - > filter = fdwNotifyFilter ;
ret = RtlNtStatusToDosError ( wine_server_call ( req ) ) ;
}
SERVER_END_REQ ;
if ( ! fAsync )
{
if ( ret = = ERROR_SUCCESS )
WaitForSingleObject ( hEvent , INFINITE ) ;
CloseHandle ( hEvent ) ;
}
return ret ;
2000-11-30 20:31:41 +00:00
}
2004-01-16 04:40:33 +00:00
/******************************************************************************
* RegOpenUserClassesRoot [ ADVAPI32 . @ ]
2004-04-23 21:32:34 +00:00
*
* Open the HKEY_CLASSES_ROOT key for a user .
2004-01-16 04:40:33 +00:00
*
* PARAMS
2004-07-13 23:33:14 +00:00
* hToken [ I ] Handle of token representing the user
* dwOptions [ I ] Reserved , nust be 0
* samDesired [ I ] Desired access rights
* phkResult [ O ] Destination for the resulting key handle
2004-01-16 04:40:33 +00:00
*
2004-07-13 23:33:14 +00:00
* RETURNS
* Success : ERROR_SUCCESS
* Failure : nonzero error code from Winerror . h
*
2004-04-23 21:32:34 +00:00
* NOTES
2004-07-13 23:33:14 +00:00
* On Windows 2000 and upwards the HKEY_CLASSES_ROOT key is a view of the
* " HKEY_LOCAL_MACHINE \ Software \ Classes " and the
* " HKEY_CURRENT_USER \ Software \ Classes " keys merged together .
2004-01-16 04:40:33 +00:00
*/
LONG WINAPI RegOpenUserClassesRoot (
HANDLE hToken ,
DWORD dwOptions ,
REGSAM samDesired ,
PHKEY phkResult
)
{
FIXME ( " (%p, 0x%lx, 0x%lx, %p) semi-stub \n " , hToken , dwOptions , samDesired , phkResult ) ;
* phkResult = HKEY_CLASSES_ROOT ;
return ERROR_SUCCESS ;
}