2004-09-30 20:23:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* ReactOS kernel
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
*/
|
2007-12-12 11:41:38 +00:00
|
|
|
|
/*
|
2004-01-13 12:34:09 +00:00
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
|
* PROJECT: ReactOS system libraries
|
2013-10-24 20:16:20 +00:00
|
|
|
|
* FILE: dll/win32/userenv/profile.c
|
2004-01-13 12:34:09 +00:00
|
|
|
|
* PURPOSE: User profile code
|
2007-12-12 11:41:38 +00:00
|
|
|
|
* PROGRAMMERS: Eric Kohl
|
|
|
|
|
* Herv<EFBFBD> Poussineau
|
2004-01-13 12:34:09 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
|
#include "precomp.h"
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2014-01-25 22:24:43 +00:00
|
|
|
|
#include <sddl.h>
|
|
|
|
|
|
2006-01-11 22:40:31 +00:00
|
|
|
|
#define NDEBUG
|
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
2004-01-13 12:34:09 +00:00
|
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
|
2004-01-16 15:31:53 +00:00
|
|
|
|
BOOL
|
2009-02-18 16:34:10 +00:00
|
|
|
|
AppendSystemPostfix(LPWSTR lpName,
|
|
|
|
|
DWORD dwMaxLength)
|
2004-01-16 15:31:53 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WCHAR szSystemRoot[MAX_PATH];
|
|
|
|
|
LPWSTR lpszPostfix;
|
|
|
|
|
LPWSTR lpszPtr;
|
|
|
|
|
|
|
|
|
|
/* Build profile name postfix */
|
|
|
|
|
if (!ExpandEnvironmentStringsW(L"%SystemRoot%",
|
|
|
|
|
szSystemRoot,
|
|
|
|
|
MAX_PATH))
|
2004-01-16 15:31:53 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
return FALSE;
|
2004-01-16 15:31:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
_wcsupr(szSystemRoot);
|
2004-01-16 15:31:53 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Get name postfix */
|
|
|
|
|
szSystemRoot[2] = L'.';
|
|
|
|
|
lpszPostfix = &szSystemRoot[2];
|
|
|
|
|
lpszPtr = lpszPostfix;
|
|
|
|
|
while (*lpszPtr != (WCHAR)0)
|
2004-01-16 15:31:53 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (*lpszPtr == L'\\')
|
|
|
|
|
*lpszPtr = '_';
|
|
|
|
|
lpszPtr++;
|
2004-01-16 15:31:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (wcslen(lpName) + wcslen(lpszPostfix) + 1 >= dwMaxLength)
|
2004-01-16 15:31:53 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: buffer overflow\n");
|
|
|
|
|
SetLastError(ERROR_BUFFER_OVERFLOW);
|
|
|
|
|
return FALSE;
|
2004-01-16 15:31:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
wcscat(lpName, lpszPostfix);
|
2004-01-16 15:31:53 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return TRUE;
|
2004-01-16 15:31:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
static
|
|
|
|
|
BOOL
|
|
|
|
|
AcquireRemoveRestorePrivilege(IN BOOL bAcquire)
|
2007-12-12 11:41:38 +00:00
|
|
|
|
{
|
2012-07-07 10:11:21 +00:00
|
|
|
|
BOOL bRet = FALSE;
|
2007-12-12 11:41:38 +00:00
|
|
|
|
HANDLE Token;
|
2012-07-07 10:11:21 +00:00
|
|
|
|
TOKEN_PRIVILEGES TokenPriv;
|
2007-12-12 11:41:38 +00:00
|
|
|
|
|
|
|
|
|
DPRINT("AcquireRemoveRestorePrivilege(%d)\n", bAcquire);
|
|
|
|
|
|
2012-07-07 10:11:21 +00:00
|
|
|
|
if (OpenProcessToken(GetCurrentProcess(),
|
|
|
|
|
TOKEN_ADJUST_PRIVILEGES,
|
|
|
|
|
&Token))
|
2007-12-12 11:41:38 +00:00
|
|
|
|
{
|
2012-07-07 10:11:21 +00:00
|
|
|
|
TokenPriv.PrivilegeCount = 1;
|
|
|
|
|
TokenPriv.Privileges[0].Attributes = (bAcquire ? SE_PRIVILEGE_ENABLED : 0);
|
|
|
|
|
|
|
|
|
|
if (LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &TokenPriv.Privileges[0].Luid))
|
|
|
|
|
{
|
|
|
|
|
bRet = AdjustTokenPrivileges(Token, FALSE, &TokenPriv, 0, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (!bRet)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("AdjustTokenPrivileges() failed with error %lu\n", GetLastError());
|
|
|
|
|
}
|
|
|
|
|
else if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("AdjustTokenPrivileges() succeeded, but with not all privileges assigned\n");
|
|
|
|
|
bRet = FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("LookupPrivilegeValue() failed with error %lu\n", GetLastError());
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-12 11:41:38 +00:00
|
|
|
|
CloseHandle(Token);
|
|
|
|
|
}
|
2012-07-07 10:11:21 +00:00
|
|
|
|
else
|
2007-12-12 11:41:38 +00:00
|
|
|
|
{
|
2012-07-07 10:11:21 +00:00
|
|
|
|
DPRINT1("OpenProcessToken() failed with error %lu\n", GetLastError());
|
2007-12-12 11:41:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 10:11:21 +00:00
|
|
|
|
return bRet;
|
2007-12-12 11:41:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 21:23:22 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
CreateUserProfileA(PSID Sid,
|
|
|
|
|
LPCSTR lpUserName)
|
|
|
|
|
{
|
|
|
|
|
UNICODE_STRING UserName;
|
|
|
|
|
BOOL bResult;
|
|
|
|
|
|
|
|
|
|
if (!RtlCreateUnicodeStringFromAsciiz(&UserName,
|
|
|
|
|
(LPSTR)lpUserName))
|
|
|
|
|
{
|
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bResult = CreateUserProfileW(Sid, UserName.Buffer);
|
|
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&UserName);
|
|
|
|
|
|
|
|
|
|
return bResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
CreateUserProfileW(PSID Sid,
|
|
|
|
|
LPCWSTR lpUserName)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WCHAR szRawProfilesPath[MAX_PATH];
|
|
|
|
|
WCHAR szProfilesPath[MAX_PATH];
|
|
|
|
|
WCHAR szUserProfilePath[MAX_PATH];
|
|
|
|
|
WCHAR szDefaultUserPath[MAX_PATH];
|
2010-05-05 22:30:14 +00:00
|
|
|
|
WCHAR szUserProfileName[MAX_PATH];
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
|
LPWSTR SidString;
|
|
|
|
|
DWORD dwLength;
|
|
|
|
|
DWORD dwDisposition;
|
2010-05-05 22:30:14 +00:00
|
|
|
|
UINT i;
|
2009-02-18 16:34:10 +00:00
|
|
|
|
HKEY hKey;
|
2012-07-07 10:11:21 +00:00
|
|
|
|
BOOL bRet = TRUE;
|
2009-02-18 16:34:10 +00:00
|
|
|
|
LONG Error;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("CreateUserProfileW() called\n");
|
|
|
|
|
|
|
|
|
|
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
|
|
|
|
|
0,
|
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
|
&hKey);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Get profiles path */
|
|
|
|
|
dwLength = MAX_PATH * sizeof(WCHAR);
|
|
|
|
|
Error = RegQueryValueExW(hKey,
|
|
|
|
|
L"ProfilesDirectory",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
(LPBYTE)szRawProfilesPath,
|
|
|
|
|
&dwLength);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-01-15 14:59:06 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Expand it */
|
|
|
|
|
if (!ExpandEnvironmentStringsW(szRawProfilesPath,
|
|
|
|
|
szProfilesPath,
|
|
|
|
|
MAX_PATH))
|
2008-05-12 16:59:06 +00:00
|
|
|
|
{
|
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2008-05-12 16:59:06 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* create the profiles directory if it does not yet exist */
|
|
|
|
|
if (!CreateDirectoryW(szProfilesPath, NULL))
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Get default user path */
|
|
|
|
|
dwLength = MAX_PATH * sizeof(WCHAR);
|
|
|
|
|
Error = RegQueryValueExW(hKey,
|
|
|
|
|
L"DefaultUserProfile",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
(LPBYTE)szBuffer,
|
|
|
|
|
&dwLength);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegCloseKey (hKey);
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2010-05-05 22:30:14 +00:00
|
|
|
|
wcscpy(szUserProfileName, lpUserName);
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
wcscpy(szUserProfilePath, szProfilesPath);
|
|
|
|
|
wcscat(szUserProfilePath, L"\\");
|
2010-05-05 22:30:14 +00:00
|
|
|
|
wcscat(szUserProfilePath, szUserProfileName);
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
wcscpy(szDefaultUserPath, szProfilesPath);
|
|
|
|
|
wcscat(szDefaultUserPath, L"\\");
|
|
|
|
|
wcscat(szDefaultUserPath, szBuffer);
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Create user profile directory */
|
|
|
|
|
if (!CreateDirectoryW(szUserProfilePath, NULL))
|
2004-01-15 14:59:06 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2010-05-05 22:30:14 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++)
|
|
|
|
|
{
|
|
|
|
|
swprintf(szUserProfileName, L"%s.%03u", lpUserName, i);
|
|
|
|
|
|
|
|
|
|
wcscpy(szUserProfilePath, szProfilesPath);
|
|
|
|
|
wcscat(szUserProfilePath, L"\\");
|
|
|
|
|
wcscat(szUserProfilePath, szUserProfileName);
|
|
|
|
|
|
|
|
|
|
if (CreateDirectoryW(szUserProfilePath, NULL))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Copy default user directory */
|
|
|
|
|
if (!CopyDirectory(szUserProfilePath, szDefaultUserPath))
|
2004-01-15 14:59:06 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
return FALSE;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Add profile to profile list */
|
|
|
|
|
if (!ConvertSidToStringSidW(Sid,
|
|
|
|
|
&SidString))
|
2004-01-15 14:59:06 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
return FALSE;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
wcscpy(szBuffer,
|
|
|
|
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
|
|
|
|
|
wcscat(szBuffer, SidString);
|
|
|
|
|
|
|
|
|
|
/* Create user profile key */
|
|
|
|
|
Error = RegCreateKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
|
szBuffer,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
|
NULL,
|
|
|
|
|
&hKey,
|
|
|
|
|
&dwDisposition);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-01-15 14:59:06 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
2012-07-07 10:11:21 +00:00
|
|
|
|
bRet = FALSE;
|
|
|
|
|
goto Done;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Create non-expanded user profile path */
|
|
|
|
|
wcscpy(szBuffer, szRawProfilesPath);
|
|
|
|
|
wcscat(szBuffer, L"\\");
|
2010-05-05 22:30:14 +00:00
|
|
|
|
wcscat(szBuffer, szUserProfileName);
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Set 'ProfileImagePath' value (non-expanded) */
|
|
|
|
|
Error = RegSetValueExW(hKey,
|
|
|
|
|
L"ProfileImagePath",
|
|
|
|
|
0,
|
|
|
|
|
REG_EXPAND_SZ,
|
|
|
|
|
(LPBYTE)szBuffer,
|
|
|
|
|
(wcslen (szBuffer) + 1) * sizeof(WCHAR));
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
2012-07-07 10:11:21 +00:00
|
|
|
|
bRet = FALSE;
|
|
|
|
|
goto Done;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Set 'Sid' value */
|
|
|
|
|
Error = RegSetValueExW(hKey,
|
|
|
|
|
L"Sid",
|
|
|
|
|
0,
|
|
|
|
|
REG_BINARY,
|
|
|
|
|
Sid,
|
|
|
|
|
GetLengthSid(Sid));
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
2012-07-07 10:11:21 +00:00
|
|
|
|
bRet = FALSE;
|
|
|
|
|
goto Done;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 10:11:21 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Create user hive name */
|
|
|
|
|
wcscpy(szBuffer, szUserProfilePath);
|
|
|
|
|
wcscat(szBuffer, L"\\ntuser.dat");
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Acquire restore privilege */
|
|
|
|
|
if (!AcquireRemoveRestorePrivilege(TRUE))
|
2007-12-12 11:41:38 +00:00
|
|
|
|
{
|
2012-07-07 10:11:21 +00:00
|
|
|
|
Error = GetLastError();
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
2012-07-07 10:11:21 +00:00
|
|
|
|
bRet = FALSE;
|
|
|
|
|
goto Done;
|
2007-12-12 11:41:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Create new user hive */
|
|
|
|
|
Error = RegLoadKeyW(HKEY_USERS,
|
|
|
|
|
SidString,
|
|
|
|
|
szBuffer);
|
|
|
|
|
AcquireRemoveRestorePrivilege(FALSE);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-01-15 14:59:06 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
2012-07-07 10:11:21 +00:00
|
|
|
|
bRet = FALSE;
|
|
|
|
|
goto Done;
|
2004-01-15 14:59:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Initialize user hive */
|
|
|
|
|
if (!CreateUserHive(SidString, szUserProfilePath))
|
2004-01-16 15:31:53 +00:00
|
|
|
|
{
|
2012-07-07 10:11:21 +00:00
|
|
|
|
Error = GetLastError();
|
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
bRet = FALSE;
|
2004-01-16 15:31:53 +00:00
|
|
|
|
}
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2012-07-07 10:11:21 +00:00
|
|
|
|
/* Unload the hive */
|
|
|
|
|
AcquireRemoveRestorePrivilege(TRUE);
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RegUnLoadKeyW(HKEY_USERS, SidString);
|
2012-07-07 10:11:21 +00:00
|
|
|
|
AcquireRemoveRestorePrivilege(FALSE);
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2012-07-07 10:11:21 +00:00
|
|
|
|
Done:
|
2009-02-18 16:34:10 +00:00
|
|
|
|
LocalFree((HLOCAL)SidString);
|
2012-07-07 10:11:21 +00:00
|
|
|
|
SetLastError((DWORD)Error);
|
2004-01-15 14:59:06 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("CreateUserProfileW() done\n");
|
2004-02-28 11:30:59 +00:00
|
|
|
|
|
2012-07-07 10:11:21 +00:00
|
|
|
|
return bRet;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-15 21:23:22 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
CreateUserProfileExA(IN PSID pSid,
|
|
|
|
|
IN LPCSTR lpUserName,
|
|
|
|
|
IN LPCSTR lpUserHive OPTIONAL,
|
|
|
|
|
OUT LPSTR lpProfileDir OPTIONAL,
|
|
|
|
|
IN DWORD dwDirSize,
|
|
|
|
|
IN BOOL bWin9xUpg)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("CreateUserProfileExA() not implemented!\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
CreateUserProfileExW(IN PSID pSid,
|
|
|
|
|
IN LPCWSTR lpUserName,
|
|
|
|
|
IN LPCWSTR lpUserHive OPTIONAL,
|
|
|
|
|
OUT LPWSTR lpProfileDir OPTIONAL,
|
|
|
|
|
IN DWORD dwDirSize,
|
|
|
|
|
IN BOOL bWin9xUpg)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("CreateUserProfileExW() not implemented!\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetAllUsersProfileDirectoryA(LPSTR lpProfileDir,
|
|
|
|
|
LPDWORD lpcchSize)
|
2004-05-03 12:05:44 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
LPWSTR lpBuffer;
|
|
|
|
|
BOOL bResult;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
lpBuffer = GlobalAlloc(GMEM_FIXED,
|
|
|
|
|
*lpcchSize * sizeof(WCHAR));
|
|
|
|
|
if (lpBuffer == NULL)
|
|
|
|
|
return FALSE;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
bResult = GetAllUsersProfileDirectoryW(lpBuffer,
|
|
|
|
|
lpcchSize);
|
|
|
|
|
if (bResult)
|
2004-05-03 12:05:44 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WideCharToMultiByte(CP_ACP,
|
|
|
|
|
0,
|
|
|
|
|
lpBuffer,
|
|
|
|
|
-1,
|
|
|
|
|
lpProfileDir,
|
|
|
|
|
*lpcchSize,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2004-05-03 12:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
GlobalFree(lpBuffer);
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return bResult;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetAllUsersProfileDirectoryW(LPWSTR lpProfileDir,
|
|
|
|
|
LPDWORD lpcchSize)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WCHAR szProfilePath[MAX_PATH];
|
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
|
DWORD dwLength;
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
LONG Error;
|
|
|
|
|
|
|
|
|
|
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
|
|
|
|
|
0,
|
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
|
&hKey);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Get profiles path */
|
|
|
|
|
dwLength = sizeof(szBuffer);
|
|
|
|
|
Error = RegQueryValueExW(hKey,
|
|
|
|
|
L"ProfilesDirectory",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
(LPBYTE)szBuffer,
|
|
|
|
|
&dwLength);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Expand it */
|
|
|
|
|
if (!ExpandEnvironmentStringsW(szBuffer,
|
|
|
|
|
szProfilePath,
|
|
|
|
|
MAX_PATH))
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Get 'AllUsersProfile' name */
|
|
|
|
|
dwLength = sizeof(szBuffer);
|
|
|
|
|
Error = RegQueryValueExW(hKey,
|
|
|
|
|
L"AllUsersProfile",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
(LPBYTE)szBuffer,
|
|
|
|
|
&dwLength);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RegCloseKey (hKey);
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
wcscat(szProfilePath, L"\\");
|
|
|
|
|
wcscat(szProfilePath, szBuffer);
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
dwLength = wcslen(szProfilePath) + 1;
|
|
|
|
|
if (lpProfileDir != NULL)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (*lpcchSize < dwLength)
|
|
|
|
|
{
|
|
|
|
|
*lpcchSize = dwLength;
|
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wcscpy(lpProfileDir, szProfilePath);
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
*lpcchSize = dwLength;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return TRUE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetDefaultUserProfileDirectoryA(LPSTR lpProfileDir,
|
|
|
|
|
LPDWORD lpcchSize)
|
2004-05-03 12:05:44 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
LPWSTR lpBuffer;
|
|
|
|
|
BOOL bResult;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
lpBuffer = GlobalAlloc(GMEM_FIXED,
|
|
|
|
|
*lpcchSize * sizeof(WCHAR));
|
|
|
|
|
if (lpBuffer == NULL)
|
|
|
|
|
return FALSE;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
bResult = GetDefaultUserProfileDirectoryW(lpBuffer,
|
|
|
|
|
lpcchSize);
|
|
|
|
|
if (bResult)
|
2004-05-03 12:05:44 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WideCharToMultiByte(CP_ACP,
|
|
|
|
|
0,
|
|
|
|
|
lpBuffer,
|
|
|
|
|
-1,
|
|
|
|
|
lpProfileDir,
|
|
|
|
|
*lpcchSize,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2004-05-03 12:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
GlobalFree(lpBuffer);
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return bResult;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetDefaultUserProfileDirectoryW(LPWSTR lpProfileDir,
|
|
|
|
|
LPDWORD lpcchSize)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WCHAR szProfilePath[MAX_PATH];
|
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
|
DWORD dwLength;
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
LONG Error;
|
|
|
|
|
|
|
|
|
|
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
|
|
|
|
|
0,
|
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
|
&hKey);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Get profiles path */
|
|
|
|
|
dwLength = sizeof(szBuffer);
|
|
|
|
|
Error = RegQueryValueExW(hKey,
|
|
|
|
|
L"ProfilesDirectory",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
(LPBYTE)szBuffer,
|
|
|
|
|
&dwLength);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Expand it */
|
|
|
|
|
if (!ExpandEnvironmentStringsW(szBuffer,
|
|
|
|
|
szProfilePath,
|
|
|
|
|
MAX_PATH))
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Get 'DefaultUserProfile' name */
|
|
|
|
|
dwLength = sizeof(szBuffer);
|
|
|
|
|
Error = RegQueryValueExW(hKey,
|
|
|
|
|
L"DefaultUserProfile",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
(LPBYTE)szBuffer,
|
|
|
|
|
&dwLength);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
wcscat(szProfilePath, L"\\");
|
|
|
|
|
wcscat(szProfilePath, szBuffer);
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
dwLength = wcslen(szProfilePath) + 1;
|
|
|
|
|
if (lpProfileDir != NULL)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (*lpcchSize < dwLength)
|
|
|
|
|
{
|
|
|
|
|
*lpcchSize = dwLength;
|
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wcscpy(lpProfileDir, szProfilePath);
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
*lpcchSize = dwLength;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return TRUE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetProfilesDirectoryA(LPSTR lpProfileDir,
|
|
|
|
|
LPDWORD lpcchSize)
|
2004-05-03 12:05:44 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
LPWSTR lpBuffer;
|
|
|
|
|
BOOL bResult;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
lpBuffer = GlobalAlloc(GMEM_FIXED,
|
|
|
|
|
*lpcchSize * sizeof(WCHAR));
|
|
|
|
|
if (lpBuffer == NULL)
|
|
|
|
|
return FALSE;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
bResult = GetProfilesDirectoryW(lpBuffer,
|
|
|
|
|
lpcchSize);
|
|
|
|
|
if (bResult)
|
2004-05-03 12:05:44 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WideCharToMultiByte(CP_ACP,
|
|
|
|
|
0,
|
|
|
|
|
lpBuffer,
|
|
|
|
|
-1,
|
|
|
|
|
lpProfileDir,
|
|
|
|
|
*lpcchSize,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2004-05-03 12:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
GlobalFree(lpBuffer);
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return bResult;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetProfilesDirectoryW(LPWSTR lpProfilesDir,
|
|
|
|
|
LPDWORD lpcchSize)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WCHAR szProfilesPath[MAX_PATH];
|
|
|
|
|
WCHAR szBuffer[MAX_PATH];
|
|
|
|
|
DWORD dwLength;
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
LONG Error;
|
|
|
|
|
|
|
|
|
|
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
|
|
|
|
|
0,
|
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
|
&hKey);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Get profiles path */
|
|
|
|
|
dwLength = sizeof(szBuffer);
|
|
|
|
|
Error = RegQueryValueExW(hKey,
|
|
|
|
|
L"ProfilesDirectory",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
(LPBYTE)szBuffer,
|
|
|
|
|
&dwLength);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Expand it */
|
|
|
|
|
if (!ExpandEnvironmentStringsW(szBuffer,
|
|
|
|
|
szProfilesPath,
|
|
|
|
|
MAX_PATH))
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", GetLastError());
|
|
|
|
|
return FALSE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
dwLength = wcslen (szProfilesPath) + 1;
|
|
|
|
|
if (lpProfilesDir != NULL)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (*lpcchSize < dwLength)
|
|
|
|
|
{
|
|
|
|
|
*lpcchSize = dwLength;
|
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wcscpy(lpProfilesDir, szProfilesPath);
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
*lpcchSize = dwLength;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return TRUE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetUserProfileDirectoryA(HANDLE hToken,
|
|
|
|
|
LPSTR lpProfileDir,
|
|
|
|
|
LPDWORD lpcchSize)
|
2004-05-03 12:05:44 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
LPWSTR lpBuffer;
|
|
|
|
|
BOOL bResult;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
lpBuffer = GlobalAlloc(GMEM_FIXED,
|
|
|
|
|
*lpcchSize * sizeof(WCHAR));
|
|
|
|
|
if (lpBuffer == NULL)
|
|
|
|
|
return FALSE;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
bResult = GetUserProfileDirectoryW(hToken,
|
|
|
|
|
lpBuffer,
|
|
|
|
|
lpcchSize);
|
|
|
|
|
if (bResult)
|
2004-05-03 12:05:44 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
WideCharToMultiByte(CP_ACP,
|
|
|
|
|
0,
|
|
|
|
|
lpBuffer,
|
|
|
|
|
-1,
|
|
|
|
|
lpProfileDir,
|
|
|
|
|
*lpcchSize,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2004-05-03 12:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
GlobalFree(lpBuffer);
|
2004-05-03 12:05:44 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return bResult;
|
2004-05-03 12:05:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetUserProfileDirectoryW(HANDLE hToken,
|
|
|
|
|
LPWSTR lpProfileDir,
|
|
|
|
|
LPDWORD lpcchSize)
|
2004-01-13 12:34:09 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
UNICODE_STRING SidString;
|
|
|
|
|
WCHAR szKeyName[MAX_PATH];
|
|
|
|
|
WCHAR szRawImagePath[MAX_PATH];
|
|
|
|
|
WCHAR szImagePath[MAX_PATH];
|
|
|
|
|
DWORD dwLength;
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
LONG Error;
|
|
|
|
|
|
2013-11-02 14:45:26 +00:00
|
|
|
|
if (!GetUserSidStringFromToken(hToken,
|
|
|
|
|
&SidString))
|
2004-03-14 18:15:59 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("GetUserSidFromToken() failed\n");
|
|
|
|
|
return FALSE;
|
2004-03-14 18:15:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("SidString: '%wZ'\n", &SidString);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
wcscpy(szKeyName,
|
|
|
|
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\");
|
|
|
|
|
wcscat(szKeyName,
|
|
|
|
|
SidString.Buffer);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("KeyName: '%S'\n", szKeyName);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
|
|
|
|
szKeyName,
|
|
|
|
|
0,
|
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
|
&hKey);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-03-14 18:15:59 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-03-14 18:15:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
dwLength = sizeof(szRawImagePath);
|
|
|
|
|
Error = RegQueryValueExW(hKey,
|
|
|
|
|
L"ProfileImagePath",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
(LPBYTE)szRawImagePath,
|
|
|
|
|
&dwLength);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2006-01-12 00:11:14 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("Error: %lu\n", Error);
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-03-14 18:15:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("RawImagePath: '%S'\n", szRawImagePath);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
/* Expand it */
|
|
|
|
|
if (!ExpandEnvironmentStringsW(szRawImagePath,
|
|
|
|
|
szImagePath,
|
|
|
|
|
MAX_PATH))
|
2004-03-14 18:15:59 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1 ("Error: %lu\n", GetLastError());
|
|
|
|
|
return FALSE;
|
2004-03-14 18:15:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("ImagePath: '%S'\n", szImagePath);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
dwLength = wcslen (szImagePath) + 1;
|
|
|
|
|
if (*lpcchSize < dwLength)
|
2004-03-14 18:15:59 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
*lpcchSize = dwLength;
|
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
|
return FALSE;
|
2004-03-14 18:15:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
*lpcchSize = dwLength;
|
|
|
|
|
wcscpy(lpProfileDir, szImagePath);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return TRUE;
|
2004-03-17 14:46:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
static
|
|
|
|
|
BOOL
|
|
|
|
|
CheckForLoadedProfile(HANDLE hToken)
|
2004-03-17 14:46:23 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
UNICODE_STRING SidString;
|
|
|
|
|
HKEY hKey;
|
2004-03-17 14:46:23 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("CheckForLoadedProfile() called\n");
|
2004-03-17 14:46:23 +00:00
|
|
|
|
|
2013-11-02 14:45:26 +00:00
|
|
|
|
if (!GetUserSidStringFromToken(hToken,
|
|
|
|
|
&SidString))
|
2004-03-17 14:46:23 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("GetUserSidFromToken() failed\n");
|
|
|
|
|
return FALSE;
|
2004-03-17 14:46:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (RegOpenKeyExW(HKEY_USERS,
|
|
|
|
|
SidString.Buffer,
|
|
|
|
|
0,
|
|
|
|
|
MAXIMUM_ALLOWED,
|
|
|
|
|
&hKey))
|
2004-03-17 14:46:23 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("Profile not loaded\n");
|
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
|
|
|
|
return FALSE;
|
2004-03-17 14:46:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2004-03-17 14:46:23 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
2004-03-17 14:46:23 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("Profile already loaded\n");
|
2004-03-17 14:46:23 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return TRUE;
|
2004-01-13 12:34:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-02-28 11:30:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
2012-07-08 15:39:14 +00:00
|
|
|
|
LoadUserProfileA(IN HANDLE hToken,
|
|
|
|
|
IN OUT LPPROFILEINFOA lpProfileInfo)
|
2004-04-29 14:41:26 +00:00
|
|
|
|
{
|
2012-07-08 15:39:14 +00:00
|
|
|
|
BOOL bResult = FALSE;
|
|
|
|
|
PROFILEINFOW ProfileInfoW = {0};
|
|
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
DPRINT("LoadUserProfileA() called\n");
|
|
|
|
|
|
|
|
|
|
/* Check profile info */
|
|
|
|
|
if (!lpProfileInfo || (lpProfileInfo->dwSize != sizeof(PROFILEINFOA)) ||
|
|
|
|
|
(lpProfileInfo->lpUserName == NULL) || (lpProfileInfo->lpUserName[0] == 0))
|
|
|
|
|
{
|
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert the structure to UNICODE... */
|
|
|
|
|
ProfileInfoW.dwSize = sizeof(PROFILEINFOW);
|
|
|
|
|
ProfileInfoW.dwFlags = lpProfileInfo->dwFlags;
|
|
|
|
|
|
|
|
|
|
if (lpProfileInfo->lpUserName)
|
|
|
|
|
{
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpUserName, -1, NULL, 0);
|
|
|
|
|
ProfileInfoW.lpUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
|
if (!ProfileInfoW.lpUserName)
|
|
|
|
|
{
|
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpUserName, -1, ProfileInfoW.lpUserName, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lpProfileInfo->lpProfilePath)
|
|
|
|
|
{
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpProfilePath, -1, NULL, 0);
|
|
|
|
|
ProfileInfoW.lpProfilePath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
|
if (!ProfileInfoW.lpProfilePath)
|
|
|
|
|
{
|
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpProfilePath, -1, ProfileInfoW.lpProfilePath, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lpProfileInfo->lpDefaultPath)
|
|
|
|
|
{
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpDefaultPath, -1, NULL, 0);
|
|
|
|
|
ProfileInfoW.lpDefaultPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
|
if (!ProfileInfoW.lpDefaultPath)
|
|
|
|
|
{
|
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpDefaultPath, -1, ProfileInfoW.lpDefaultPath, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lpProfileInfo->lpServerName)
|
|
|
|
|
{
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpServerName, -1, NULL, 0);
|
|
|
|
|
ProfileInfoW.lpServerName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
|
if (!ProfileInfoW.lpServerName)
|
|
|
|
|
{
|
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpServerName, -1, ProfileInfoW.lpServerName, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((ProfileInfoW.dwFlags & PI_APPLYPOLICY) != 0 && lpProfileInfo->lpPolicyPath)
|
|
|
|
|
{
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpPolicyPath, -1, NULL, 0);
|
|
|
|
|
ProfileInfoW.lpPolicyPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
|
if (!ProfileInfoW.lpPolicyPath)
|
|
|
|
|
{
|
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpPolicyPath, -1, ProfileInfoW.lpPolicyPath, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ... and call the UNICODE function */
|
|
|
|
|
bResult = LoadUserProfileW(hToken, &ProfileInfoW);
|
|
|
|
|
|
|
|
|
|
/* Save the returned value */
|
|
|
|
|
lpProfileInfo->hProfile = ProfileInfoW.hProfile;
|
|
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
/* Memory cleanup */
|
|
|
|
|
if (ProfileInfoW.lpUserName)
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpUserName);
|
|
|
|
|
|
|
|
|
|
if (ProfileInfoW.lpProfilePath)
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpProfilePath);
|
|
|
|
|
|
|
|
|
|
if (ProfileInfoW.lpDefaultPath)
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpDefaultPath);
|
|
|
|
|
|
|
|
|
|
if (ProfileInfoW.lpServerName)
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpServerName);
|
|
|
|
|
|
|
|
|
|
if ((ProfileInfoW.dwFlags & PI_APPLYPOLICY) != 0 && ProfileInfoW.lpPolicyPath)
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpPolicyPath);
|
|
|
|
|
|
|
|
|
|
return bResult;
|
2004-04-29 14:41:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
LoadUserProfileW(IN HANDLE hToken,
|
|
|
|
|
IN OUT LPPROFILEINFOW lpProfileInfo)
|
2004-02-28 11:30:59 +00:00
|
|
|
|
{
|
2007-08-08 08:26:44 +00:00
|
|
|
|
WCHAR szUserHivePath[MAX_PATH];
|
|
|
|
|
LPWSTR UserName = NULL, Domain = NULL;
|
|
|
|
|
DWORD UserNameLength = 0, DomainLength = 0;
|
|
|
|
|
PTOKEN_USER UserSid = NULL;
|
|
|
|
|
SID_NAME_USE AccountType;
|
2008-12-03 17:33:13 +00:00
|
|
|
|
UNICODE_STRING SidString = { 0, 0, NULL };
|
2007-08-08 08:26:44 +00:00
|
|
|
|
LONG Error;
|
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
DWORD dwLength = sizeof(szUserHivePath) / sizeof(szUserHivePath[0]);
|
|
|
|
|
|
|
|
|
|
DPRINT("LoadUserProfileW() called\n");
|
|
|
|
|
|
|
|
|
|
/* Check profile info */
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (!lpProfileInfo || (lpProfileInfo->dwSize != sizeof(PROFILEINFOW)) ||
|
|
|
|
|
(lpProfileInfo->lpUserName == NULL) || (lpProfileInfo->lpUserName[0] == 0))
|
2004-02-28 11:30:59 +00:00
|
|
|
|
{
|
2007-08-08 08:26:44 +00:00
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2012-07-08 15:39:14 +00:00
|
|
|
|
return FALSE;
|
2004-02-28 11:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
/* Don't load a profile twice */
|
|
|
|
|
if (CheckForLoadedProfile(hToken))
|
2004-03-13 20:49:07 +00:00
|
|
|
|
{
|
2007-08-08 08:26:44 +00:00
|
|
|
|
DPRINT ("Profile already loaded\n");
|
|
|
|
|
lpProfileInfo->hProfile = NULL;
|
|
|
|
|
return TRUE;
|
2004-03-13 20:49:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-13 14:18:49 +00:00
|
|
|
|
if (lpProfileInfo->lpProfilePath)
|
2004-03-13 20:49:07 +00:00
|
|
|
|
{
|
2007-08-13 14:18:49 +00:00
|
|
|
|
wcscpy(szUserHivePath, lpProfileInfo->lpProfilePath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: check if MS Windows allows lpProfileInfo->lpProfilePath to be NULL */
|
|
|
|
|
if (!GetProfilesDirectoryW(szUserHivePath, &dwLength))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("GetProfilesDirectoryW() failed (error %ld)\n", GetLastError());
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2004-03-13 20:49:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-05 22:30:14 +00:00
|
|
|
|
/* Create user hive name */
|
2007-08-08 08:26:44 +00:00
|
|
|
|
wcscat(szUserHivePath, L"\\");
|
|
|
|
|
wcscat(szUserHivePath, lpProfileInfo->lpUserName);
|
|
|
|
|
wcscat(szUserHivePath, L"\\ntuser.dat");
|
|
|
|
|
DPRINT("szUserHivePath: %S\n", szUserHivePath);
|
2004-03-13 20:49:07 +00:00
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
/* Create user profile directory if needed */
|
|
|
|
|
if (GetFileAttributesW(szUserHivePath) == INVALID_FILE_ATTRIBUTES)
|
2004-03-13 20:49:07 +00:00
|
|
|
|
{
|
2007-08-08 08:26:44 +00:00
|
|
|
|
/* Get user sid */
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (GetTokenInformation(hToken, TokenUser, NULL, 0, &dwLength) ||
|
|
|
|
|
GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
2007-08-08 08:26:44 +00:00
|
|
|
|
{
|
|
|
|
|
DPRINT1 ("GetTokenInformation() failed\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2009-02-18 16:34:10 +00:00
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
UserSid = (PTOKEN_USER)HeapAlloc(GetProcessHeap(), 0, dwLength);
|
|
|
|
|
if (!UserSid)
|
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("HeapAlloc() failed\n");
|
2007-08-08 08:26:44 +00:00
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
2009-02-18 16:34:10 +00:00
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
if (!GetTokenInformation(hToken, TokenUser, UserSid, dwLength, &dwLength))
|
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("GetTokenInformation() failed\n");
|
2007-08-08 08:26:44 +00:00
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get user name */
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (UserNameLength > 0)
|
|
|
|
|
{
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, UserName);
|
|
|
|
|
UserName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, UserNameLength * sizeof(WCHAR));
|
|
|
|
|
if (!UserName)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("HeapAlloc() failed\n");
|
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (DomainLength > 0)
|
|
|
|
|
{
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, Domain);
|
|
|
|
|
Domain = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, DomainLength * sizeof(WCHAR));
|
|
|
|
|
if (!Domain)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("HeapAlloc() failed\n");
|
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-02-18 16:34:10 +00:00
|
|
|
|
ret = LookupAccountSidW(NULL,
|
|
|
|
|
UserSid->User.Sid,
|
|
|
|
|
UserName,
|
|
|
|
|
&UserNameLength,
|
|
|
|
|
Domain,
|
|
|
|
|
&DomainLength,
|
|
|
|
|
&AccountType);
|
2007-08-08 08:26:44 +00:00
|
|
|
|
} while (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("LookupAccountSidW() failed\n");
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create profile */
|
|
|
|
|
/* FIXME: ignore Domain? */
|
|
|
|
|
DPRINT("UserName %S, Domain %S\n", UserName, Domain);
|
|
|
|
|
ret = CreateUserProfileW(UserSid->User.Sid, UserName);
|
|
|
|
|
if (!ret)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("CreateUserProfileW() failed\n");
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
2004-03-13 20:49:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
/* Get user SID string */
|
2013-11-02 14:45:26 +00:00
|
|
|
|
ret = GetUserSidStringFromToken(hToken, &SidString);
|
2007-08-08 08:26:44 +00:00
|
|
|
|
if (!ret)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("GetUserSidFromToken() failed\n");
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
ret = FALSE;
|
2004-03-13 20:49:07 +00:00
|
|
|
|
|
2007-12-12 11:41:38 +00:00
|
|
|
|
/* Acquire restore privilege */
|
|
|
|
|
if (!AcquireRemoveRestorePrivilege(TRUE))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("AcquireRemoveRestorePrivilege() failed (Error %ld)\n", GetLastError());
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
/* Load user registry hive */
|
|
|
|
|
Error = RegLoadKeyW(HKEY_USERS,
|
|
|
|
|
SidString.Buffer,
|
|
|
|
|
szUserHivePath);
|
2007-12-12 11:41:38 +00:00
|
|
|
|
AcquireRemoveRestorePrivilege(FALSE);
|
2013-11-01 14:41:06 +00:00
|
|
|
|
|
|
|
|
|
/* HACK: Do not fail if the profile has already been loaded! */
|
|
|
|
|
if (Error == ERROR_SHARING_VIOLATION)
|
|
|
|
|
Error = ERROR_SUCCESS;
|
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-03-13 20:49:07 +00:00
|
|
|
|
{
|
2007-08-08 08:26:44 +00:00
|
|
|
|
DPRINT1("RegLoadKeyW() failed (Error %ld)\n", Error);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
goto cleanup;
|
2004-03-13 20:49:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
/* Open future HKEY_CURRENT_USER */
|
|
|
|
|
Error = RegOpenKeyExW(HKEY_USERS,
|
|
|
|
|
SidString.Buffer,
|
|
|
|
|
0,
|
|
|
|
|
MAXIMUM_ALLOWED,
|
|
|
|
|
(PHKEY)&lpProfileInfo->hProfile);
|
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-03-14 18:15:59 +00:00
|
|
|
|
{
|
2007-08-08 08:26:44 +00:00
|
|
|
|
DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
goto cleanup;
|
2004-03-14 18:15:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
ret = TRUE;
|
2004-03-13 20:49:07 +00:00
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
cleanup:
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, UserSid);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, UserName);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, Domain);
|
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
2004-03-13 20:49:07 +00:00
|
|
|
|
|
2007-08-08 08:26:44 +00:00
|
|
|
|
DPRINT("LoadUserProfileW() done\n");
|
|
|
|
|
return ret;
|
2004-03-13 20:49:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
UnloadUserProfile(HANDLE hToken,
|
|
|
|
|
HANDLE hProfile)
|
2004-03-13 20:49:07 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
UNICODE_STRING SidString;
|
|
|
|
|
LONG Error;
|
2004-03-13 20:49:07 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("UnloadUserProfile() called\n");
|
2004-03-13 20:49:07 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (hProfile == NULL)
|
2004-03-14 18:15:59 +00:00
|
|
|
|
{
|
2012-07-08 15:39:14 +00:00
|
|
|
|
DPRINT1("Invalid profile handle\n");
|
2009-02-18 16:34:10 +00:00
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
|
return FALSE;
|
2004-03-14 18:15:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RegCloseKey(hProfile);
|
2004-03-14 18:15:59 +00:00
|
|
|
|
|
2013-11-02 14:45:26 +00:00
|
|
|
|
if (!GetUserSidStringFromToken(hToken,
|
|
|
|
|
&SidString))
|
2004-03-13 20:49:07 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("GetUserSidFromToken() failed\n");
|
|
|
|
|
return FALSE;
|
2004-03-13 20:49:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("SidString: '%wZ'\n", &SidString);
|
2004-03-13 20:49:07 +00:00
|
|
|
|
|
2010-05-05 22:30:14 +00:00
|
|
|
|
/* Acquire restore privilege */
|
|
|
|
|
if (!AcquireRemoveRestorePrivilege(TRUE))
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("AcquireRemoveRestorePrivilege() failed (Error %ld)\n", GetLastError());
|
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unload the hive */
|
2009-02-18 16:34:10 +00:00
|
|
|
|
Error = RegUnLoadKeyW(HKEY_USERS,
|
|
|
|
|
SidString.Buffer);
|
2010-05-05 22:30:14 +00:00
|
|
|
|
|
|
|
|
|
/* Remove restore privilege */
|
|
|
|
|
AcquireRemoveRestorePrivilege(FALSE);
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
if (Error != ERROR_SUCCESS)
|
2004-03-13 20:49:07 +00:00
|
|
|
|
{
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT1("RegUnLoadKeyW() failed (Error %ld)\n", Error);
|
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
|
|
|
|
SetLastError((DWORD)Error);
|
|
|
|
|
return FALSE;
|
2004-03-13 20:49:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
2004-03-13 20:49:07 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
DPRINT("UnloadUserProfile() done\n");
|
2004-02-28 11:30:59 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
return TRUE;
|
2004-02-28 11:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-08 15:39:14 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
2009-02-07 18:31:01 +00:00
|
|
|
|
DeleteProfileW(LPCWSTR lpSidString,
|
|
|
|
|
LPCWSTR lpProfilePath,
|
|
|
|
|
LPCWSTR lpComputerName)
|
|
|
|
|
{
|
2012-07-08 15:39:14 +00:00
|
|
|
|
DPRINT1("DeleteProfileW() not implemented!\n");
|
|
|
|
|
return FALSE;
|
2009-02-07 18:31:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-08 15:39:14 +00:00
|
|
|
|
|
2009-02-18 16:34:10 +00:00
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
2009-02-07 18:31:01 +00:00
|
|
|
|
DeleteProfileA(LPCSTR lpSidString,
|
|
|
|
|
LPCSTR lpProfilePath,
|
|
|
|
|
LPCSTR lpComputerName)
|
|
|
|
|
{
|
2012-07-08 15:39:14 +00:00
|
|
|
|
BOOL bResult;
|
|
|
|
|
UNICODE_STRING SidString, ProfilePath, ComputerName;
|
|
|
|
|
|
|
|
|
|
DPRINT("DeleteProfileA() called\n");
|
|
|
|
|
|
|
|
|
|
/* Conversion to UNICODE */
|
|
|
|
|
if (lpSidString)
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&SidString,
|
|
|
|
|
(LPSTR)lpSidString);
|
|
|
|
|
|
|
|
|
|
if (lpProfilePath)
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&ProfilePath,
|
|
|
|
|
(LPSTR)lpProfilePath);
|
|
|
|
|
|
|
|
|
|
if (lpComputerName)
|
|
|
|
|
RtlCreateUnicodeStringFromAsciiz(&ComputerName,
|
|
|
|
|
(LPSTR)lpComputerName);
|
|
|
|
|
|
|
|
|
|
/* Call the UNICODE function */
|
|
|
|
|
bResult = DeleteProfileW(SidString.Buffer,
|
|
|
|
|
ProfilePath.Buffer,
|
|
|
|
|
ComputerName.Buffer);
|
|
|
|
|
|
|
|
|
|
/* Memory cleanup */
|
|
|
|
|
if (lpSidString)
|
|
|
|
|
RtlFreeUnicodeString(&SidString);
|
|
|
|
|
|
|
|
|
|
if (lpProfilePath)
|
|
|
|
|
RtlFreeUnicodeString(&ProfilePath);
|
|
|
|
|
|
|
|
|
|
if (lpComputerName)
|
|
|
|
|
RtlFreeUnicodeString(&ComputerName);
|
|
|
|
|
|
|
|
|
|
return bResult;
|
2009-02-07 18:31:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-15 21:23:22 +00:00
|
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
|
WINAPI
|
|
|
|
|
GetProfileType(OUT PDWORD pdwFlags)
|
|
|
|
|
{
|
|
|
|
|
DPRINT1("GetProfileType() not implemented!\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-13 12:34:09 +00:00
|
|
|
|
/* EOF */
|