-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[KERNEL32] Implement DosPathToSessionPath functions #8436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CNMrSunshine
wants to merge
5
commits into
reactos:master
Choose a base branch
from
CNMrSunshine:Imp-Kernel32-session-funcs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f0ecdd9
Implement DosPathToSessionPath functions
CNMrSunshine 69a26e0
Refactor session path handling for NULL checks
CNMrSunshine 2cd1677
Fixed coding style issue
CNMrSunshine 08d7dfd
Update header per coding style doc
binarymaster a6f9f83
Fixed bug
CNMrSunshine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 *******************************************************************/ | ||
|
|
@@ -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; | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.