https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1a1dac04c7697a74765f4c...
commit 1a1dac04c7697a74765f4c42b51246f58ad98e12 Author: Hervé Poussineau hpoussin@reactos.org AuthorDate: Tue May 25 19:02:16 2021 +0200 Commit: Hervé Poussineau hpoussin@reactos.org CommitDate: Tue May 25 19:02:16 2021 +0200
[SMLIB] Implement SmStartCsr and SmStopCsr --- sdk/include/reactos/subsys/sm/smmsg.h | 17 ++++++++ sdk/lib/smlib/smclient.c | 81 +++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+)
diff --git a/sdk/include/reactos/subsys/sm/smmsg.h b/sdk/include/reactos/subsys/sm/smmsg.h index 60a6c2da09d..a5af962fed6 100644 --- a/sdk/include/reactos/subsys/sm/smmsg.h +++ b/sdk/include/reactos/subsys/sm/smmsg.h @@ -263,4 +263,21 @@ SmSessionComplete( IN NTSTATUS SessionStatus );
+NTSTATUS +NTAPI +SmStartCsr( + IN HANDLE SmApiPort, + OUT PULONG pMuSessionId, + IN PUNICODE_STRING CommandLine, + OUT PHANDLE pWindowsSubSysProcessId, + OUT PHANDLE pInitialCommandProcessId +); + +NTSTATUS +NTAPI +SmStopCsr( + IN HANDLE SmApiPort, + IN ULONG SessionId +); + #endif diff --git a/sdk/lib/smlib/smclient.c b/sdk/lib/smlib/smclient.c index 924963d1d0e..d56c8e57d0a 100644 --- a/sdk/lib/smlib/smclient.c +++ b/sdk/lib/smlib/smclient.c @@ -167,3 +167,84 @@ SmSessionComplete(IN HANDLE SmApiPort, /* Return status */ return Status; } + +NTSTATUS +NTAPI +SmStartCsr(IN HANDLE SmApiPort, + OUT PULONG pMuSessionId, + IN PUNICODE_STRING CommandLine, + OUT PHANDLE pWindowsSubSysProcessId, + OUT PHANDLE pInitialCommandProcessId) +{ + NTSTATUS Status; + SM_API_MSG SmApiMsg; + + /* Initialize the generic LPC header */ + RtlZeroMemory(&SmApiMsg, sizeof(SmApiMsg)); + SmApiMsg.h.u1.s1.DataLength = sizeof(SM_EXEC_PGM_MSG) + 8; + SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg); + + /* Initialize this specific API's parameters */ + SmApiMsg.ApiNumber = SmpStartCsrApi; + if (CommandLine) + { + if (CommandLine->Length > ARRAYSIZE(SmApiMsg.u.StartCsr.Buffer)) + { + DPRINT1("SmStartCsr: Command line too long\n"); + return STATUS_INVALID_PARAMETER; + } + RtlCopyMemory(SmApiMsg.u.StartCsr.Buffer, CommandLine->Buffer, CommandLine->Length); + SmApiMsg.u.StartCsr.Length = CommandLine->Length; + } + + /* Send the message to SMSS */ + Status = NtRequestWaitReplyPort(SmApiPort, &SmApiMsg.h, &SmApiMsg.h); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SmStartCsr: NtRequestWaitReply Failed %lx\n", Status); + } + else + { + /* Upon success, we use the API's return value */ + Status = SmApiMsg.ReturnValue; + } + + /* Give back informations to caller */ + *pMuSessionId = SmApiMsg.u.StartCsr.MuSessionId; + *pWindowsSubSysProcessId = SmApiMsg.u.StartCsr.WindowsSubSysProcessId; + *pInitialCommandProcessId = SmApiMsg.u.StartCsr.SmpInitialCommandProcessId; + + return Status; +} + +NTSTATUS +NTAPI +SmStopCsr(IN HANDLE SmApiPort, + IN ULONG SessionId) +{ + NTSTATUS Status; + SM_API_MSG SmApiMsg; + + /* Initialize the generic LPC header */ + RtlZeroMemory(&SmApiMsg, sizeof(SmApiMsg)); + SmApiMsg.h.u1.s1.DataLength = sizeof(SM_EXEC_PGM_MSG) + 8; + SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg); + + /* Initialize this specific API's parameters */ + SmApiMsg.ApiNumber = SmpStopCsrApi; + SmApiMsg.u.StopCsr.MuSessionId = SessionId; + + /* Send the message to SMSS */ + Status = NtRequestWaitReplyPort(SmApiPort, &SmApiMsg.h, &SmApiMsg.h); + if (!NT_SUCCESS(Status)) + { + DPRINT1("SmStopCsr: NtRequestWaitReply Failed %lx\n", Status); + } + else + { + /* Upon success, we use the API's return value */ + Status = SmApiMsg.ReturnValue; + } + + return Status; +}