mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 12:40:33 +00:00
[USERENV]
- Move functionality from CreateUserProfileW to CreateUserProfileExW. - Implement CreateUserProfileExA and fix CreateUserProfileA. svn path=/trunk/; revision=73493
This commit is contained in:
parent
e01de74720
commit
2c10751e87
1 changed files with 151 additions and 47 deletions
|
@ -125,22 +125,35 @@ AcquireRemoveRestorePrivilege(IN BOOL bAcquire)
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
WINAPI
|
WINAPI
|
||||||
CreateUserProfileA(PSID Sid,
|
CreateUserProfileA(
|
||||||
LPCSTR lpUserName)
|
_In_ PSID pSid,
|
||||||
|
_In_ LPCSTR lpUserName)
|
||||||
{
|
{
|
||||||
UNICODE_STRING UserName;
|
LPWSTR pUserNameW = NULL;
|
||||||
|
INT nLength;
|
||||||
BOOL bResult;
|
BOOL bResult;
|
||||||
|
|
||||||
if (!RtlCreateUnicodeStringFromAsciiz(&UserName,
|
DPRINT("CreateUserProfileA(%p %s)\n", pSid, lpUserName);
|
||||||
(LPSTR)lpUserName))
|
|
||||||
|
/* Convert lpUserName to Unicode */
|
||||||
|
nLength = MultiByteToWideChar(CP_ACP, 0, lpUserName, -1, NULL, 0);
|
||||||
|
pUserNameW = HeapAlloc(GetProcessHeap(), 0, nLength * sizeof(WCHAR));
|
||||||
|
if (pUserNameW == NULL)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, lpUserName, -1, pUserNameW, nLength);
|
||||||
|
|
||||||
bResult = CreateUserProfileW(Sid, UserName.Buffer);
|
/* Call the Ex function */
|
||||||
|
bResult = CreateUserProfileExW(pSid,
|
||||||
|
pUserNameW,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
FALSE);
|
||||||
|
|
||||||
RtlFreeUnicodeString(&UserName);
|
HeapFree(GetProcessHeap(), 0, pUserNameW);
|
||||||
|
|
||||||
return bResult;
|
return bResult;
|
||||||
}
|
}
|
||||||
|
@ -148,8 +161,120 @@ CreateUserProfileA(PSID Sid,
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
WINAPI
|
WINAPI
|
||||||
CreateUserProfileW(PSID Sid,
|
CreateUserProfileW(
|
||||||
LPCWSTR lpUserName)
|
_In_ PSID pSid,
|
||||||
|
_In_ LPCWSTR lpUserName)
|
||||||
|
{
|
||||||
|
DPRINT("CreateUserProfileW(%p %S)\n", pSid, lpUserName);
|
||||||
|
|
||||||
|
/* Call the Ex function */
|
||||||
|
return CreateUserProfileExW(pSid,
|
||||||
|
lpUserName,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOL
|
||||||
|
WINAPI
|
||||||
|
CreateUserProfileExA(
|
||||||
|
_In_ PSID pSid,
|
||||||
|
_In_ LPCSTR lpUserName,
|
||||||
|
_In_opt_ LPCSTR lpUserHive,
|
||||||
|
_Out_opt_ LPSTR lpProfileDir,
|
||||||
|
_In_ DWORD dwDirSize,
|
||||||
|
_In_ BOOL bWin9xUpg)
|
||||||
|
{
|
||||||
|
LPWSTR pUserNameW = NULL;
|
||||||
|
LPWSTR pUserHiveW = NULL;
|
||||||
|
LPWSTR pProfileDirW = NULL;
|
||||||
|
INT nLength;
|
||||||
|
BOOL bResult = FALSE;
|
||||||
|
|
||||||
|
DPRINT("CreateUserProfileExA(%p %s %s %p %lu %d)\n",
|
||||||
|
pSid, lpUserName, lpUserHive, lpProfileDir, dwDirSize, bWin9xUpg);
|
||||||
|
|
||||||
|
/* Check the parameters */
|
||||||
|
if (lpProfileDir != NULL && dwDirSize == 0)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert lpUserName to Unicode */
|
||||||
|
nLength = MultiByteToWideChar(CP_ACP, 0, lpUserName, -1, NULL, 0);
|
||||||
|
pUserNameW = HeapAlloc(GetProcessHeap(), 0, nLength * sizeof(WCHAR));
|
||||||
|
if (pUserNameW == NULL)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, lpUserName, -1, pUserNameW, nLength);
|
||||||
|
|
||||||
|
/* Convert lpUserHive to Unicode */
|
||||||
|
if (lpUserHive != NULL)
|
||||||
|
{
|
||||||
|
nLength = MultiByteToWideChar(CP_ACP, 0, lpUserHive, -1, NULL, 0);
|
||||||
|
pUserHiveW = HeapAlloc(GetProcessHeap(), 0, nLength * sizeof(WCHAR));
|
||||||
|
if (pUserHiveW == NULL)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, lpUserHive, -1, pUserHiveW, nLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate a Unicode buffer for lpProfileDir */
|
||||||
|
if (lpProfileDir != NULL)
|
||||||
|
{
|
||||||
|
pProfileDirW = HeapAlloc(GetProcessHeap(), 0, dwDirSize * sizeof(WCHAR));
|
||||||
|
if (pProfileDirW == NULL)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call the Unicode function */
|
||||||
|
bResult = CreateUserProfileExW(pSid,
|
||||||
|
(LPCWSTR)pUserNameW,
|
||||||
|
(LPCWSTR)pUserHiveW,
|
||||||
|
pProfileDirW,
|
||||||
|
dwDirSize,
|
||||||
|
bWin9xUpg);
|
||||||
|
|
||||||
|
/* Convert the profile path to ANSI */
|
||||||
|
if (bResult && lpProfileDir != NULL)
|
||||||
|
{
|
||||||
|
WideCharToMultiByte(CP_ACP, 0, pProfileDirW, -1, lpProfileDir, dwDirSize, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
/* Free the buffers */
|
||||||
|
if (pProfileDirW != NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, pProfileDirW);
|
||||||
|
|
||||||
|
if (pUserHiveW != NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, pUserHiveW);
|
||||||
|
|
||||||
|
if (pUserNameW != NULL)
|
||||||
|
HeapFree(GetProcessHeap(), 0, pUserNameW);
|
||||||
|
|
||||||
|
return bResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOL
|
||||||
|
WINAPI
|
||||||
|
CreateUserProfileExW(
|
||||||
|
_In_ PSID pSid,
|
||||||
|
_In_ LPCWSTR lpUserName,
|
||||||
|
_In_opt_ LPCWSTR lpUserHive,
|
||||||
|
_Out_opt_ LPWSTR lpProfileDir,
|
||||||
|
_In_ DWORD dwDirSize,
|
||||||
|
_In_ BOOL bWin9xUpg)
|
||||||
{
|
{
|
||||||
WCHAR szRawProfilesPath[MAX_PATH];
|
WCHAR szRawProfilesPath[MAX_PATH];
|
||||||
WCHAR szProfilesPath[MAX_PATH];
|
WCHAR szProfilesPath[MAX_PATH];
|
||||||
|
@ -165,7 +290,14 @@ CreateUserProfileW(PSID Sid,
|
||||||
BOOL bRet = TRUE;
|
BOOL bRet = TRUE;
|
||||||
LONG Error;
|
LONG Error;
|
||||||
|
|
||||||
DPRINT("CreateUserProfileW() called\n");
|
DPRINT("CreateUserProfileExW(%p %S %S %p %lu %d)\n",
|
||||||
|
pSid, lpUserName, lpUserHive, lpProfileDir, dwDirSize, bWin9xUpg);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO:
|
||||||
|
* - Add support for lpUserHive, lpProfileDir.
|
||||||
|
* - bWin9xUpg is obsolete. Don't waste your time implementing this.
|
||||||
|
*/
|
||||||
|
|
||||||
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||||
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
|
||||||
|
@ -279,7 +411,7 @@ CreateUserProfileW(PSID Sid,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add profile to profile list */
|
/* Add profile to profile list */
|
||||||
if (!ConvertSidToStringSidW(Sid,
|
if (!ConvertSidToStringSidW(pSid,
|
||||||
&SidString))
|
&SidString))
|
||||||
{
|
{
|
||||||
DPRINT1("Error: %lu\n", GetLastError());
|
DPRINT1("Error: %lu\n", GetLastError());
|
||||||
|
@ -304,7 +436,7 @@ CreateUserProfileW(PSID Sid,
|
||||||
{
|
{
|
||||||
DPRINT1("Error: %lu\n", Error);
|
DPRINT1("Error: %lu\n", Error);
|
||||||
bRet = FALSE;
|
bRet = FALSE;
|
||||||
goto Done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create non-expanded user profile path */
|
/* Create non-expanded user profile path */
|
||||||
|
@ -324,7 +456,7 @@ CreateUserProfileW(PSID Sid,
|
||||||
DPRINT1("Error: %lu\n", Error);
|
DPRINT1("Error: %lu\n", Error);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
bRet = FALSE;
|
bRet = FALSE;
|
||||||
goto Done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set 'Sid' value */
|
/* Set 'Sid' value */
|
||||||
|
@ -332,14 +464,14 @@ CreateUserProfileW(PSID Sid,
|
||||||
L"Sid",
|
L"Sid",
|
||||||
0,
|
0,
|
||||||
REG_BINARY,
|
REG_BINARY,
|
||||||
Sid,
|
pSid,
|
||||||
GetLengthSid(Sid));
|
GetLengthSid(pSid));
|
||||||
if (Error != ERROR_SUCCESS)
|
if (Error != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
DPRINT1("Error: %lu\n", Error);
|
DPRINT1("Error: %lu\n", Error);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
bRet = FALSE;
|
bRet = FALSE;
|
||||||
goto Done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
@ -354,7 +486,7 @@ CreateUserProfileW(PSID Sid,
|
||||||
Error = GetLastError();
|
Error = GetLastError();
|
||||||
DPRINT1("Error: %lu\n", Error);
|
DPRINT1("Error: %lu\n", Error);
|
||||||
bRet = FALSE;
|
bRet = FALSE;
|
||||||
goto Done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create new user hive */
|
/* Create new user hive */
|
||||||
|
@ -366,7 +498,7 @@ CreateUserProfileW(PSID Sid,
|
||||||
{
|
{
|
||||||
DPRINT1("Error: %lu\n", Error);
|
DPRINT1("Error: %lu\n", Error);
|
||||||
bRet = FALSE;
|
bRet = FALSE;
|
||||||
goto Done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize user hive */
|
/* Initialize user hive */
|
||||||
|
@ -382,7 +514,7 @@ CreateUserProfileW(PSID Sid,
|
||||||
RegUnLoadKeyW(HKEY_USERS, SidString);
|
RegUnLoadKeyW(HKEY_USERS, SidString);
|
||||||
AcquireRemoveRestorePrivilege(FALSE);
|
AcquireRemoveRestorePrivilege(FALSE);
|
||||||
|
|
||||||
Done:
|
done:
|
||||||
LocalFree((HLOCAL)SidString);
|
LocalFree((HLOCAL)SidString);
|
||||||
SetLastError((DWORD)Error);
|
SetLastError((DWORD)Error);
|
||||||
|
|
||||||
|
@ -392,34 +524,6 @@ Done:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
WINAPI
|
WINAPI
|
||||||
GetAllUsersProfileDirectoryA(LPSTR lpProfileDir,
|
GetAllUsersProfileDirectoryA(LPSTR lpProfileDir,
|
||||||
|
|
Loading…
Reference in a new issue