Author: dchapyshev
Date: Sun Jul 31 13:46:23 2016
New Revision: 72066
URL:
http://svn.reactos.org/svn/reactos?rev=72066&view=rev
Log:
[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)
Added:
trunk/reactos/dll/win32/userenv/sid.c (with props)
Modified:
trunk/reactos/dll/win32/userenv/CMakeLists.txt
trunk/reactos/dll/win32/userenv/environment.c
trunk/reactos/dll/win32/userenv/internal.h
trunk/reactos/dll/win32/userenv/misc.c
trunk/reactos/dll/win32/userenv/userenv.spec
trunk/reactos/sdk/include/psdk/userenv.h
Modified: trunk/reactos/dll/win32/userenv/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/CMakeLis…
==============================================================================
--- trunk/reactos/dll/win32/userenv/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/userenv/CMakeLists.txt [iso-8859-1] Sun Jul 31 13:46:23 2016
@@ -10,6 +10,7 @@
profile.c
registry.c
setup.c
+ sid.c
userenv.c
precomp.h)
Modified: trunk/reactos/dll/win32/userenv/environment.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/environm…
==============================================================================
--- trunk/reactos/dll/win32/userenv/environment.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/userenv/environment.c [iso-8859-1] Sun Jul 31 13:46:23 2016
@@ -82,17 +82,15 @@
if (!_wcsicmp(lpName, L"temp") || !_wcsicmp(lpName, L"tmp"))
{
- if (!GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH))
- {
- DPRINT1("GetShortPathNameW() failed for %S (Error %lu)\n",
DstValue.Buffer, GetLastError());
- if (Buffer)
- LocalFree(Buffer);
- return FALSE;
+ if (GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH))
+ {
+ 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 @@
SID_NAME_USE SidNameUse;
BOOL bRet = TRUE;
- if (!GetUserSidFromToken(hToken,
- &Sid))
- {
- DPRINT1("GetUserSidFromToken() failed\n");
+ Sid = GetUserSid(hToken);
+ if (Sid == NULL)
+ {
+ DPRINT1("GetUserSid() failed\n");
return FALSE;
}
@@ -363,29 +361,40 @@
{
dwValueNameLength = dwMaxValueNameLength;
dwValueDataLength = dwMaxValueDataLength;
- RegEnumValueW(hEnvKey,
- i,
- lpValueName,
- &dwValueNameLength,
- NULL,
- &dwType,
- (LPBYTE)lpValueData,
- &dwValueDataLength);
-
- if (!_wcsicmp (lpValueName, L"path"))
- {
- /* Append 'Path' environment variable */
- AppendUserEnvironmentVariable(lpEnvironment,
- lpValueName,
- lpValueData);
+
+ Error = RegEnumValueW(hEnvKey,
+ i,
+ lpValueName,
+ &dwValueNameLength,
+ NULL,
+ &dwType,
+ (LPBYTE)lpValueData,
+ &dwValueDataLength);
+ if (Error == ERROR_SUCCESS)
+ {
+ 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 @@
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,
Modified: trunk/reactos/dll/win32/userenv/internal.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/internal…
==============================================================================
--- trunk/reactos/dll/win32/userenv/internal.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/userenv/internal.h [iso-8859-1] Sun Jul 31 13:46:23 2016
@@ -73,14 +73,6 @@
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 @@
UpdateUsersShellFolderSettings(LPCWSTR lpUserProfilePath,
HKEY hUserKey);
+/* sid.c */
+BOOL
+GetUserSidStringFromToken(HANDLE hToken,
+ PUNICODE_STRING SidString);
+
/* userenv.c */
extern HINSTANCE hInstance;
Modified: trunk/reactos/dll/win32/userenv/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/misc.c?r…
==============================================================================
--- trunk/reactos/dll/win32/userenv/misc.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/userenv/misc.c [iso-8859-1] Sun Jul 31 13:46:23 2016
@@ -53,141 +53,6 @@
}
-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)
{
Added: trunk/reactos/dll/win32/userenv/sid.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/sid.c?re…
==============================================================================
--- trunk/reactos/dll/win32/userenv/sid.c (added)
+++ trunk/reactos/dll/win32/userenv/sid.c [iso-8859-1] Sun Jul 31 13:46:23 2016
@@ -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;
+}
Propchange: trunk/reactos/dll/win32/userenv/sid.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/dll/win32/userenv/userenv.spec
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/userenv.…
==============================================================================
--- trunk/reactos/dll/win32/userenv/userenv.spec [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/userenv/userenv.spec [iso-8859-1] Sun Jul 31 13:46:23 2016
@@ -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)
Modified: trunk/reactos/sdk/include/psdk/userenv.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/include/psdk/userenv.h…
==============================================================================
--- trunk/reactos/sdk/include/psdk/userenv.h [iso-8859-1] (original)
+++ trunk/reactos/sdk/include/psdk/userenv.h [iso-8859-1] Sun Jul 31 13:46:23 2016
@@ -103,6 +103,7 @@
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);