[SMLIB][SMSS] Implement SmLoadDeferedSubsystem() client and server-side. (#4821)

Loosely based on the deprecated ReactOS-specific SmExecuteProgram().
On server-side, we lookup into the list of deferred subsystems that
has been initialized at init time.

Dedicated to Justin Miller (The_DarkFire) work on reviving the
POSIX subsystem!
This commit is contained in:
Hermès Bélusca-Maïto 2022-10-26 17:35:03 +02:00
parent 8fea507d9b
commit 9f48c69231
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 122 additions and 11 deletions

View file

@ -295,6 +295,58 @@ SmExecPgm(
return Status;
}
/**
* @brief
* This function is used to make the SM start an environment
* subsystem server process.
*
* @param[in] SmApiPort
* Port handle returned by SmConnectToSm().
*
* @param[in] DeferedSubsystem
* Name of the subsystem to start. This must be one of the subsystems
* listed by value's name in the SM registry key
* \Registry\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems
* (used by the SM to lookup the corresponding image name).
* Default valid names are: "Debug", "Windows", "Posix", "Os2".
*
* @return
* Success status as handed by the SM reply; otherwise a failure
* status code.
**/
NTSTATUS
NTAPI
SmLoadDeferedSubsystem(
_In_ HANDLE SmApiPort,
_In_ PUNICODE_STRING DeferedSubsystem)
{
SM_API_MSG SmApiMsg = {0};
PSM_LOAD_DEFERED_SUBSYSTEM_MSG LoadDefered = &SmApiMsg.u.LoadDefered;
#if 0 //def _WIN64
/* 64-bit SMSS needs to talk to 32-bit processes so do the LPC conversion */
if (SmpIsWow64Process())
{
return SmpWow64LoadDeferedSubsystem(SmApiPort, DeferedSubsystem);
}
#endif
/* Validate DeferedSubsystem's length */
if (DeferedSubsystem->Length > sizeof(LoadDefered->Buffer))
return STATUS_INVALID_PARAMETER;
/* Set the message data */
/* Buffer stores a counted non-NULL-terminated UNICODE string */
LoadDefered->Length = DeferedSubsystem->Length;
RtlCopyMemory(LoadDefered->Buffer,
DeferedSubsystem->Buffer,
DeferedSubsystem->Length);
/* Send the message and wait for a reply */
SmApiMsg.ApiNumber = SmpLoadDeferedSubsystemApi;
return SmSendMsgToSm(SmApiPort, &SmApiMsg);
}
/**
* @brief
* Requests the SM to create a new Terminal Services session