2004-09-30 20:23:00 +00:00
|
|
|
/*
|
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2004 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-09-30 20:23:00 +00:00
|
|
|
*/
|
2005-01-06 13:34:15 +00:00
|
|
|
/* $Id$
|
2004-01-16 15:31:53 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/userenv/registry.c
|
|
|
|
* PURPOSE: User profile code
|
|
|
|
* PROGRAMMER: Eric Kohl
|
|
|
|
*/
|
|
|
|
|
2005-08-27 23:35:51 +00:00
|
|
|
#include <precomp.h>
|
2004-01-16 15:31:53 +00:00
|
|
|
|
2006-01-11 22:40:31 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2004-01-16 15:31:53 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
2004-02-28 11:30:59 +00:00
|
|
|
static BOOL
|
|
|
|
CopyKey (HKEY hDstKey,
|
|
|
|
HKEY hSrcKey)
|
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
LONG Error;
|
|
|
|
|
|
|
|
#if (_WIN32_WINNT >= 0x0600)
|
|
|
|
Error = RegCopyTreeW(hSrcKey,
|
|
|
|
NULL,
|
|
|
|
hDstKey);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
#else
|
2004-02-28 11:30:59 +00:00
|
|
|
FILETIME LastWrite;
|
|
|
|
DWORD dwSubKeys;
|
|
|
|
DWORD dwValues;
|
|
|
|
DWORD dwType;
|
|
|
|
DWORD dwMaxSubKeyNameLength;
|
|
|
|
DWORD dwSubKeyNameLength;
|
|
|
|
DWORD dwMaxValueNameLength;
|
|
|
|
DWORD dwValueNameLength;
|
|
|
|
DWORD dwMaxValueLength;
|
|
|
|
DWORD dwValueLength;
|
|
|
|
DWORD dwDisposition;
|
|
|
|
DWORD i;
|
|
|
|
LPWSTR lpNameBuffer;
|
|
|
|
LPBYTE lpDataBuffer;
|
|
|
|
HKEY hDstSubKey;
|
|
|
|
HKEY hSrcSubKey;
|
|
|
|
|
|
|
|
DPRINT ("CopyKey() called \n");
|
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
Error = RegQueryInfoKey (hSrcKey,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&dwSubKeys,
|
|
|
|
&dwMaxSubKeyNameLength,
|
|
|
|
NULL,
|
|
|
|
&dwValues,
|
|
|
|
&dwMaxValueNameLength,
|
|
|
|
&dwMaxValueLength,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-02-28 11:30:59 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
DPRINT1 ("RegQueryInfoKey() failed (Error %lu)\n", Error);
|
|
|
|
SetLastError((DWORD)Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT ("dwSubKeys %lu\n", dwSubKeys);
|
|
|
|
DPRINT ("dwMaxSubKeyNameLength %lu\n", dwMaxSubKeyNameLength);
|
|
|
|
DPRINT ("dwValues %lu\n", dwValues);
|
|
|
|
DPRINT ("dwMaxValueNameLength %lu\n", dwMaxValueNameLength);
|
|
|
|
DPRINT ("dwMaxValueLength %lu\n", dwMaxValueLength);
|
|
|
|
|
|
|
|
/* Copy subkeys */
|
|
|
|
if (dwSubKeys != 0)
|
|
|
|
{
|
|
|
|
lpNameBuffer = HeapAlloc (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
dwMaxSubKeyNameLength * sizeof(WCHAR));
|
|
|
|
if (lpNameBuffer == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("Buffer allocation failed\n");
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dwSubKeys; i++)
|
|
|
|
{
|
|
|
|
dwSubKeyNameLength = dwMaxSubKeyNameLength;
|
2006-01-12 00:11:14 +00:00
|
|
|
Error = RegEnumKeyExW (hSrcKey,
|
|
|
|
i,
|
|
|
|
lpNameBuffer,
|
|
|
|
&dwSubKeyNameLength,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&LastWrite);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-02-28 11:30:59 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
DPRINT1 ("Subkey enumeration failed (Error %lu)\n", Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError((DWORD)Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
Error = RegCreateKeyExW (hDstKey,
|
|
|
|
lpNameBuffer,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_WRITE,
|
|
|
|
NULL,
|
|
|
|
&hDstSubKey,
|
|
|
|
&dwDisposition);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-02-28 11:30:59 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
DPRINT1 ("Subkey creation failed (Error %lu)\n", Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError((DWORD)Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
Error = RegOpenKeyExW (hSrcKey,
|
|
|
|
lpNameBuffer,
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&hSrcSubKey);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-02-28 11:30:59 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
DPRINT1 ("Error: %lu\n", Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
RegCloseKey (hDstSubKey);
|
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError((DWORD)Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CopyKey (hDstSubKey,
|
|
|
|
hSrcSubKey))
|
|
|
|
{
|
2004-03-16 11:34:51 +00:00
|
|
|
DPRINT1 ("Error: %lu\n", GetLastError());
|
2004-02-28 11:30:59 +00:00
|
|
|
RegCloseKey (hSrcSubKey);
|
|
|
|
RegCloseKey (hDstSubKey);
|
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey (hSrcSubKey);
|
|
|
|
RegCloseKey (hDstSubKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy values */
|
|
|
|
if (dwValues != 0)
|
|
|
|
{
|
|
|
|
lpNameBuffer = HeapAlloc (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
dwMaxValueNameLength * sizeof(WCHAR));
|
|
|
|
if (lpNameBuffer == NULL)
|
|
|
|
{
|
2004-03-16 11:34:51 +00:00
|
|
|
DPRINT1 ("Buffer allocation failed\n");
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpDataBuffer = HeapAlloc (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
dwMaxValueLength);
|
|
|
|
if (lpDataBuffer == NULL)
|
|
|
|
{
|
2004-03-16 11:34:51 +00:00
|
|
|
DPRINT1 ("Buffer allocation failed\n");
|
2004-02-28 11:30:59 +00:00
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dwValues; i++)
|
|
|
|
{
|
|
|
|
dwValueNameLength = dwMaxValueNameLength;
|
|
|
|
dwValueLength = dwMaxValueLength;
|
2006-01-12 00:11:14 +00:00
|
|
|
Error = RegEnumValueW (hSrcKey,
|
|
|
|
i,
|
|
|
|
lpNameBuffer,
|
|
|
|
&dwValueNameLength,
|
|
|
|
NULL,
|
|
|
|
&dwType,
|
|
|
|
lpDataBuffer,
|
|
|
|
&dwValueLength);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-02-28 11:30:59 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
DPRINT1("Error: %lu\n", Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpDataBuffer);
|
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError((DWORD)Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
Error = RegSetValueExW (hDstKey,
|
|
|
|
lpNameBuffer,
|
|
|
|
0,
|
|
|
|
dwType,
|
|
|
|
lpDataBuffer,
|
|
|
|
dwValueLength);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-02-28 11:30:59 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
DPRINT1("Error: %lu\n", Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpDataBuffer);
|
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError((DWORD)Error);
|
2004-02-28 11:30:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpDataBuffer);
|
|
|
|
|
|
|
|
HeapFree (GetProcessHeap (),
|
|
|
|
0,
|
|
|
|
lpNameBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT ("CopyKey() done \n");
|
|
|
|
|
|
|
|
return TRUE;
|
2006-01-12 00:11:14 +00:00
|
|
|
#endif
|
2004-02-28 11:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-16 15:31:53 +00:00
|
|
|
BOOL
|
2004-10-03 09:27:22 +00:00
|
|
|
CreateUserHive (LPCWSTR lpKeyName,
|
|
|
|
LPCWSTR lpProfilePath)
|
2004-01-16 15:31:53 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
HKEY hDefaultKey = NULL;
|
|
|
|
HKEY hUserKey = NULL;
|
|
|
|
LONG Error;
|
|
|
|
BOOL Ret = FALSE;
|
2004-01-16 15:31:53 +00:00
|
|
|
|
2004-02-28 11:30:59 +00:00
|
|
|
DPRINT ("CreateUserHive(%S) called\n", lpKeyName);
|
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
Error = RegOpenKeyExW (HKEY_USERS,
|
|
|
|
L".Default",
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&hDefaultKey);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-02-28 11:30:59 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
goto Cleanup;
|
2004-02-28 11:30:59 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
Error = RegOpenKeyExW (HKEY_USERS,
|
|
|
|
lpKeyName,
|
|
|
|
0,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&hUserKey);
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-02-28 11:30:59 +00:00
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
goto Cleanup;
|
2004-02-28 11:30:59 +00:00
|
|
|
}
|
|
|
|
|
2004-10-03 09:27:22 +00:00
|
|
|
if (!CopyKey(hUserKey, hDefaultKey))
|
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
goto Cleanup;
|
2004-10-03 09:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!UpdateUsersShellFolderSettings(lpProfilePath,
|
|
|
|
hUserKey))
|
|
|
|
{
|
2006-01-12 00:11:14 +00:00
|
|
|
goto Cleanup;
|
2004-10-03 09:27:22 +00:00
|
|
|
}
|
2004-02-28 11:30:59 +00:00
|
|
|
|
2004-03-16 11:34:51 +00:00
|
|
|
RegFlushKey (hUserKey);
|
2006-01-12 00:11:14 +00:00
|
|
|
Ret = TRUE;
|
2004-03-16 11:34:51 +00:00
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
Cleanup:
|
|
|
|
if (hUserKey != NULL)
|
|
|
|
RegCloseKey (hUserKey);
|
2004-02-28 11:30:59 +00:00
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
if (hDefaultKey != NULL)
|
|
|
|
RegCloseKey (hDefaultKey);
|
2004-02-28 11:30:59 +00:00
|
|
|
|
2006-01-12 00:11:14 +00:00
|
|
|
return Ret;
|
2004-01-16 15:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|