Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 114 additions & 10 deletions dll/win32/kernel32/client/session.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* PROJECT: ReactOS Win32 Base API
* LICENSE: GPL - See COPYING in the top level directory
* FILE: dll/win32/kernel32/client/session.c
* PURPOSE: Session Support APIs
* PROGRAMMERS: Alex Ionescu ([email protected])
* PROJECT: ReactOS Win32 Base API
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Session Support APIs
* COPYRIGHT: Copyright 2011 Alex Ionescu <[email protected]>
* Copyright 2025 Jiayu Ge <[email protected]>
*/

/* INCLUDES *******************************************************************/
Expand All @@ -16,28 +16,132 @@
/* FUNCTIONS ******************************************************************/

/*
* @unimplemented
* @implemented
*/
DWORD
WINAPI
DosPathToSessionPathW(IN DWORD SessionID,
IN LPWSTR InPath,
OUT LPWSTR *OutPath)
{
UNIMPLEMENTED;
DWORD LastError = ERROR_SUCCESS;
if (InPath == NULL)
{
LastError = ERROR_INVALID_PARAMETER;
}
else
{
size_t InPathLength = wcslen(InPath);
size_t OutPathLength = 0;
LPWSTR SessionPath = NULL;
if (!BaseStaticServerData->LUIDDeviceMapsEnabled)
{
if (SessionID == 0)
{
OutPathLength += wcslen(L"GLOBALROOT\\DosDevices\\");
OutPathLength += InPathLength;
}
else
{
OutPathLength += wcslen(L"GLOBALROOT\\Sessions\\");
OutPathLength += 10; // Length of SessionID(char)
OutPathLength += wcslen(L"\\DosDevices\\");
OutPathLength += InPathLength;
}
}
else
{
OutPathLength += InPathLength;
}
OutPathLength += 1; // \0 termination
SessionPath = (LPWSTR)LocalAlloc(LMEM_FIXED, OutPathLength * sizeof(WCHAR));
if (SessionPath)
{
if (BaseStaticServerData->LUIDDeviceMapsEnabled)
{
RtlStringCchPrintfW(SessionPath, OutPathLength, L"%ws", InPath);
}
else if (SessionID == 0)
{
// GLOBALROOT\DosDevices\$InPath
RtlStringCchPrintfW(SessionPath, OutPathLength, L"GLOBALROOT\\DosDevices\\%ws", InPath);
}
else
{
// GLOBALROOT\Sessions\$SessionID\DosDevices\$InPath
RtlStringCchPrintfW(SessionPath, OutPathLength, L"GLOBALROOT\\Sessions\\%u\\DosDevices\\%ws", SessionID, InPath);
}
*OutPath = SessionPath;
return 1;
}
else
{
LastError = ERROR_NOT_ENOUGH_MEMORY;
}
}
RtlSetLastWin32Error(LastError);
return 0;
}

/*
* @unimplemented
* @implemented
*/
DWORD
WINAPI
DosPathToSessionPathA(IN DWORD SessionId,
DosPathToSessionPathA(IN DWORD SessionID,
IN LPSTR InPath,
OUT LPSTR *OutPath)
{
UNIMPLEMENTED;
DWORD LastError = ERROR_SUCCESS;
if (InPath == NULL)
{
LastError = ERROR_INVALID_PARAMETER;
}
else
{ // AnsiPath: InPath(ANSI) -> UnicodePath: InPath(Unicode) -> wcOutPath: OutPath(wide-char) -> UnicodePath: OutPath(Unicode) -> AnsiPath: OutPath(ANSI)
STRING AnsiPath = { 0 };
RtlInitAnsiString(&AnsiPath, InPath);
UNICODE_STRING UnicodePath;
NTSTATUS status = RtlAnsiStringToUnicodeString(&UnicodePath, &AnsiPath, TRUE); // UnicodePath = InPath(Unicode)
if (!NT_SUCCESS(status))
{
BaseSetLastNTError(status);
return 0;
}
LPWSTR wcOutPath = NULL; // OutPath(wide-char)
if (!DosPathToSessionPathW(SessionID, UnicodePath.Buffer, &wcOutPath))
{
RtlFreeUnicodeString(&UnicodePath);
return 0;
}
RtlFreeUnicodeString(&UnicodePath);
RtlInitUnicodeString(&UnicodePath, wcOutPath); // UnicodePath = OutPath(Unicode)
status = RtlUnicodeStringToAnsiString(&AnsiPath, &UnicodePath, TRUE);
if (!NT_SUCCESS(status))
{
BaseSetLastNTError(status);
LocalFree(wcOutPath);
return 0;
}
size_t AnsiOutPathLen = strlen(AnsiPath.Buffer);
AnsiOutPathLen += 1;
char *SessionPath = LocalAlloc(LMEM_FIXED, AnsiOutPathLen * sizeof(CHAR));
if (SessionPath != NULL)
{
RtlStringCchCopyA(SessionPath, AnsiOutPathLen, AnsiPath.Buffer);
*OutPath = SessionPath;
LocalFree(wcOutPath);
RtlFreeAnsiString(&AnsiPath);
return 1;
}
else
{
LocalFree(wcOutPath);
RtlFreeAnsiString(&AnsiPath);
LastError = ERROR_NOT_ENOUGH_MEMORY;
}
}
RtlSetLastWin32Error(LastError);
return 0;
}

Expand Down