mirror of
https://github.com/reactos/reactos.git
synced 2024-06-30 01:42:30 +00:00
[USERENV]
- Implement GetUserSid() (based on GetUserSidFromToken()) - Remove GetUserSidFromToken() and use new exported function - Move SID functions to sid.c - SetUserEnvironmentVariable should not fail, if can't get the short path. Instead, a long path - Setup environment variables from Session Manager * This fixes all winetests for userenv.dll (+20 passed tests) svn path=/trunk/; revision=72066
This commit is contained in:
parent
2c2bd66efd
commit
96fe018e77
|
@ -10,6 +10,7 @@ list(APPEND SOURCE
|
|||
profile.c
|
||||
registry.c
|
||||
setup.c
|
||||
sid.c
|
||||
userenv.c
|
||||
precomp.h)
|
||||
|
||||
|
|
|
@ -82,17 +82,15 @@ SetUserEnvironmentVariable(LPVOID *Environment,
|
|||
|
||||
if (!_wcsicmp(lpName, L"temp") || !_wcsicmp(lpName, L"tmp"))
|
||||
{
|
||||
if (!GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH))
|
||||
if (GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH))
|
||||
{
|
||||
DPRINT1("GetShortPathNameW() failed for %S (Error %lu)\n", DstValue.Buffer, GetLastError());
|
||||
if (Buffer)
|
||||
LocalFree(Buffer);
|
||||
return FALSE;
|
||||
DPRINT("GetShortPathNameW() failed for %S (Error %lu)\n", DstValue.Buffer, GetLastError());
|
||||
|
||||
RtlInitUnicodeString(&DstValue,
|
||||
ShortName);
|
||||
}
|
||||
|
||||
DPRINT("Buffer: %S\n", ShortName);
|
||||
RtlInitUnicodeString(&DstValue,
|
||||
ShortName);
|
||||
}
|
||||
|
||||
RtlInitUnicodeString(&Name,
|
||||
|
@ -214,10 +212,10 @@ GetUserAndDomainName(IN HANDLE hToken,
|
|||
SID_NAME_USE SidNameUse;
|
||||
BOOL bRet = TRUE;
|
||||
|
||||
if (!GetUserSidFromToken(hToken,
|
||||
&Sid))
|
||||
Sid = GetUserSid(hToken);
|
||||
if (Sid == NULL)
|
||||
{
|
||||
DPRINT1("GetUserSidFromToken() failed\n");
|
||||
DPRINT1("GetUserSid() failed\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -363,29 +361,40 @@ SetUserEnvironment(LPVOID *lpEnvironment,
|
|||
{
|
||||
dwValueNameLength = dwMaxValueNameLength;
|
||||
dwValueDataLength = dwMaxValueDataLength;
|
||||
RegEnumValueW(hEnvKey,
|
||||
i,
|
||||
lpValueName,
|
||||
&dwValueNameLength,
|
||||
NULL,
|
||||
&dwType,
|
||||
(LPBYTE)lpValueData,
|
||||
&dwValueDataLength);
|
||||
|
||||
if (!_wcsicmp (lpValueName, L"path"))
|
||||
Error = RegEnumValueW(hEnvKey,
|
||||
i,
|
||||
lpValueName,
|
||||
&dwValueNameLength,
|
||||
NULL,
|
||||
&dwType,
|
||||
(LPBYTE)lpValueData,
|
||||
&dwValueDataLength);
|
||||
if (Error == ERROR_SUCCESS)
|
||||
{
|
||||
/* Append 'Path' environment variable */
|
||||
AppendUserEnvironmentVariable(lpEnvironment,
|
||||
lpValueName,
|
||||
lpValueData);
|
||||
if (!_wcsicmp (lpValueName, L"path"))
|
||||
{
|
||||
/* Append 'Path' environment variable */
|
||||
AppendUserEnvironmentVariable(lpEnvironment,
|
||||
lpValueName,
|
||||
lpValueData);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set environment variable */
|
||||
SetUserEnvironmentVariable(lpEnvironment,
|
||||
lpValueName,
|
||||
lpValueData,
|
||||
(dwType == REG_EXPAND_SZ));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set environment variable */
|
||||
SetUserEnvironmentVariable(lpEnvironment,
|
||||
lpValueName,
|
||||
lpValueData,
|
||||
(dwType == REG_EXPAND_SZ));
|
||||
LocalFree(lpValueData);
|
||||
LocalFree(lpValueName);
|
||||
RegCloseKey(hEnvKey);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,6 +463,11 @@ CreateEnvironmentBlock(LPVOID *lpEnvironment,
|
|||
FALSE);
|
||||
}
|
||||
|
||||
/* Set variables from System Manager */
|
||||
SetUserEnvironment(lpEnvironment,
|
||||
HKEY_LOCAL_MACHINE,
|
||||
L"System\\CurrentControlSet\\Control\\Session Manager\\Environment");
|
||||
|
||||
/* Set 'COMPUTERNAME' variable */
|
||||
Length = MAX_PATH;
|
||||
if (GetComputerNameW(Buffer,
|
||||
|
|
|
@ -73,14 +73,6 @@ UnloadDynamicImports(PDYN_FUNCS DynFuncs);
|
|||
LPWSTR
|
||||
AppendBackslash(LPWSTR String);
|
||||
|
||||
BOOL
|
||||
GetUserSidFromToken(HANDLE hToken,
|
||||
PSID *Sid);
|
||||
|
||||
BOOL
|
||||
GetUserSidStringFromToken(HANDLE hToken,
|
||||
PUNICODE_STRING SidString);
|
||||
|
||||
PSECURITY_DESCRIPTOR
|
||||
CreateDefaultSecurityDescriptor(VOID);
|
||||
|
||||
|
@ -99,6 +91,11 @@ BOOL
|
|||
UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath,
|
||||
HKEY hUserKey);
|
||||
|
||||
/* sid.c */
|
||||
BOOL
|
||||
GetUserSidStringFromToken(HANDLE hToken,
|
||||
PUNICODE_STRING SidString);
|
||||
|
||||
/* userenv.c */
|
||||
extern HINSTANCE hInstance;
|
||||
|
||||
|
|
|
@ -53,141 +53,6 @@ AppendBackslash(LPWSTR String)
|
|||
}
|
||||
|
||||
|
||||
BOOL
|
||||
GetUserSidFromToken(HANDLE hToken,
|
||||
PSID *Sid)
|
||||
{
|
||||
PTOKEN_USER UserBuffer, nsb;
|
||||
PSID pSid = NULL;
|
||||
ULONG Length;
|
||||
NTSTATUS Status;
|
||||
|
||||
Length = 256;
|
||||
UserBuffer = LocalAlloc(LPTR, Length);
|
||||
if (UserBuffer == NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = NtQueryInformationToken(hToken,
|
||||
TokenUser,
|
||||
(PVOID)UserBuffer,
|
||||
Length,
|
||||
&Length);
|
||||
if (Status == STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
nsb = LocalReAlloc(UserBuffer, Length, LMEM_MOVEABLE);
|
||||
if (nsb == NULL)
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UserBuffer = nsb;
|
||||
Status = NtQueryInformationToken(hToken,
|
||||
TokenUser,
|
||||
(PVOID)UserBuffer,
|
||||
Length,
|
||||
&Length);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS (Status))
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Length = RtlLengthSid(UserBuffer->User.Sid);
|
||||
|
||||
pSid = LocalAlloc(LPTR, Length);
|
||||
if (pSid == NULL)
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = RtlCopySid(Length, pSid, UserBuffer->User.Sid);
|
||||
|
||||
LocalFree(UserBuffer);
|
||||
|
||||
if (!NT_SUCCESS (Status))
|
||||
{
|
||||
LocalFree(pSid);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*Sid = pSid;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL
|
||||
GetUserSidStringFromToken(HANDLE hToken,
|
||||
PUNICODE_STRING SidString)
|
||||
{
|
||||
PTOKEN_USER UserBuffer, nsb;
|
||||
ULONG Length;
|
||||
NTSTATUS Status;
|
||||
|
||||
Length = 256;
|
||||
UserBuffer = LocalAlloc(LPTR, Length);
|
||||
if (UserBuffer == NULL)
|
||||
return FALSE;
|
||||
|
||||
Status = NtQueryInformationToken(hToken,
|
||||
TokenUser,
|
||||
(PVOID)UserBuffer,
|
||||
Length,
|
||||
&Length);
|
||||
if (Status == STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
nsb = LocalReAlloc(UserBuffer,
|
||||
Length,
|
||||
LMEM_MOVEABLE);
|
||||
if (nsb == NULL)
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UserBuffer = nsb;
|
||||
Status = NtQueryInformationToken(hToken,
|
||||
TokenUser,
|
||||
(PVOID)UserBuffer,
|
||||
Length,
|
||||
&Length);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS (Status))
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
SetLastError(RtlNtStatusToDosError(Status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DPRINT("SidLength: %lu\n", RtlLengthSid (UserBuffer->User.Sid));
|
||||
|
||||
Status = RtlConvertSidToUnicodeString(SidString,
|
||||
UserBuffer->User.Sid,
|
||||
TRUE);
|
||||
|
||||
LocalFree(UserBuffer);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastError(RtlNtStatusToDosError(Status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DPRINT("SidString.Length: %lu\n", SidString->Length);
|
||||
DPRINT("SidString.MaximumLength: %lu\n", SidString->MaximumLength);
|
||||
DPRINT("SidString: '%wZ'\n", SidString);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
PSECURITY_DESCRIPTOR
|
||||
CreateDefaultSecurityDescriptor(VOID)
|
||||
{
|
||||
|
|
164
reactos/dll/win32/userenv/sid.c
Normal file
164
reactos/dll/win32/userenv/sid.c
Normal file
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: dll/win32/userenv/sid.c
|
||||
* PURPOSE: User profile code
|
||||
* PROGRAMMER: Eric Kohl
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
#include <ndk/sefuncs.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
PSID
|
||||
WINAPI
|
||||
GetUserSid(HANDLE hToken)
|
||||
{
|
||||
PTOKEN_USER UserBuffer;
|
||||
PTOKEN_USER TempBuffer;
|
||||
NTSTATUS Status;
|
||||
ULONG Length;
|
||||
PSID pSid;
|
||||
|
||||
Length = 256;
|
||||
UserBuffer = LocalAlloc(LPTR, Length);
|
||||
if (UserBuffer == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Status = NtQueryInformationToken(hToken,
|
||||
TokenUser,
|
||||
(PVOID)UserBuffer,
|
||||
Length,
|
||||
&Length);
|
||||
if (Status == STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
TempBuffer = LocalReAlloc(UserBuffer, Length, LMEM_MOVEABLE);
|
||||
if (TempBuffer == NULL)
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UserBuffer = TempBuffer;
|
||||
Status = NtQueryInformationToken(hToken,
|
||||
TokenUser,
|
||||
(PVOID)UserBuffer,
|
||||
Length,
|
||||
&Length);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Length = RtlLengthSid(UserBuffer->User.Sid);
|
||||
|
||||
pSid = LocalAlloc(LPTR, Length);
|
||||
if (pSid == NULL)
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Status = RtlCopySid(Length, pSid, UserBuffer->User.Sid);
|
||||
|
||||
LocalFree(UserBuffer);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
LocalFree(pSid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pSid;
|
||||
}
|
||||
|
||||
BOOL
|
||||
GetUserSidStringFromToken(HANDLE hToken,
|
||||
PUNICODE_STRING SidString)
|
||||
{
|
||||
PTOKEN_USER UserBuffer, nsb;
|
||||
ULONG Length;
|
||||
NTSTATUS Status;
|
||||
|
||||
Length = 256;
|
||||
UserBuffer = LocalAlloc(LPTR, Length);
|
||||
if (UserBuffer == NULL)
|
||||
return FALSE;
|
||||
|
||||
Status = NtQueryInformationToken(hToken,
|
||||
TokenUser,
|
||||
(PVOID)UserBuffer,
|
||||
Length,
|
||||
&Length);
|
||||
if (Status == STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
nsb = LocalReAlloc(UserBuffer,
|
||||
Length,
|
||||
LMEM_MOVEABLE);
|
||||
if (nsb == NULL)
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UserBuffer = nsb;
|
||||
Status = NtQueryInformationToken(hToken,
|
||||
TokenUser,
|
||||
(PVOID)UserBuffer,
|
||||
Length,
|
||||
&Length);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS (Status))
|
||||
{
|
||||
LocalFree(UserBuffer);
|
||||
SetLastError(RtlNtStatusToDosError(Status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DPRINT("SidLength: %lu\n", RtlLengthSid (UserBuffer->User.Sid));
|
||||
|
||||
Status = RtlConvertSidToUnicodeString(SidString,
|
||||
UserBuffer->User.Sid,
|
||||
TRUE);
|
||||
|
||||
LocalFree(UserBuffer);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastError(RtlNtStatusToDosError(Status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DPRINT("SidString.Length: %lu\n", SidString->Length);
|
||||
DPRINT("SidString.MaximumLength: %lu\n", SidString->MaximumLength);
|
||||
DPRINT("SidString: '%wZ'\n", SidString);
|
||||
|
||||
return TRUE;
|
||||
}
|
|
@ -85,7 +85,7 @@
|
|||
139 stub -noname CreateLinkFileExW #stdcall -noname CreateLinkFileExW(48)
|
||||
140 stub -noname InitializeUserProfile #stdcall -noname InitializeUserProfile()
|
||||
#141 cdecl -noname RsopSidsFromToken@@YGJPAXPAPAU_TOKEN_GROUPS@@@Z
|
||||
142 stub -noname GetUserSid #stdcall -noname GetUserSid(4)
|
||||
142 stdcall -noname GetUserSid(ptr)
|
||||
143 stub -noname SecureUserProfiles #stdcall -noname SecureUserProfiles()
|
||||
144 stub -noname EnterUserProfileLock #stdcall -noname EnterUserProfileLock(4)
|
||||
145 stub -noname LeaveUserProfileLock #stdcall -noname LeaveUserProfileLock(4)
|
||||
|
|
|
@ -103,6 +103,7 @@ BOOL WINAPI DeleteItemA (LPCSTR, BOOL, LPCSTR, BOOL);
|
|||
BOOL WINAPI DeleteItemW (LPCWSTR, BOOL, LPCWSTR, BOOL);
|
||||
BOOL WINAPI CopyProfileDirectoryA(LPCSTR, LPCSTR, DWORD);
|
||||
BOOL WINAPI CopyProfileDirectoryW(LPCWSTR, LPCWSTR, DWORD);
|
||||
PSID WINAPI GetUserSid(HANDLE);
|
||||
/* end private */
|
||||
BOOL WINAPI LoadUserProfileA (HANDLE, LPPROFILEINFOA);
|
||||
BOOL WINAPI LoadUserProfileW (HANDLE, LPPROFILEINFOW);
|
||||
|
|
Loading…
Reference in a new issue