Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

352 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. smstub.c
  5. Abstract:
  6. Session Manager Client Support APIs
  7. Author:
  8. Mark Lucovsky (markl) 05-Oct-1989
  9. Revision History:
  10. --*/
  11. #include "smdllp.h"
  12. #include <string.h>
  13. NTSTATUS
  14. SmExecPgm(
  15. IN HANDLE SmApiPort,
  16. IN PRTL_USER_PROCESS_INFORMATION ProcessInformation,
  17. IN BOOLEAN DebugFlag
  18. )
  19. /*++
  20. Routine Description:
  21. This routine allows a process to start a process using the
  22. facilities provided by the NT Session manager.
  23. This function closes all handles passed to it.
  24. Arguments:
  25. SmApiPort - Supplies a handle to a communications port connected
  26. to the Session Manager.
  27. ProcessInformation - Supplies a process description as returned
  28. by RtlCreateUserProcess.
  29. DebugFlag - Supplies and optional parameter which if set indicates
  30. that the caller wants to debug this process and act as its
  31. debug user interface.
  32. Return Value:
  33. TBD.
  34. --*/
  35. {
  36. NTSTATUS st;
  37. SMAPIMSG SmApiMsg;
  38. PSMEXECPGM args;
  39. args = &SmApiMsg.u.ExecPgm;
  40. args->ProcessInformation = *ProcessInformation;
  41. args->DebugFlag = DebugFlag;
  42. SmApiMsg.ApiNumber = SmExecPgmApi;
  43. SmApiMsg.h.u1.s1.DataLength = sizeof(*args) + 8;
  44. SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
  45. SmApiMsg.h.u2.ZeroInit = 0L;
  46. st = NtRequestWaitReplyPort(
  47. SmApiPort,
  48. (PPORT_MESSAGE) &SmApiMsg,
  49. (PPORT_MESSAGE) &SmApiMsg
  50. );
  51. if ( NT_SUCCESS(st) ) {
  52. st = SmApiMsg.ReturnedStatus;
  53. } else {
  54. KdPrint(("SmExecPgm: NtRequestWaitReply Failed %lx\n",st));
  55. }
  56. NtClose(ProcessInformation->Process);
  57. NtClose(ProcessInformation->Thread);
  58. return st;
  59. }
  60. NTSTATUS
  61. NTAPI
  62. SmLoadDeferedSubsystem(
  63. IN HANDLE SmApiPort,
  64. IN PUNICODE_STRING DeferedSubsystem
  65. )
  66. /*++
  67. Routine Description:
  68. This routine allows a process to start a defered subsystem.
  69. Arguments:
  70. SmApiPort - Supplies a handle to a communications port connected
  71. to the Session Manager.
  72. DeferedSubsystem - Supplies the name of the defered subsystem to load.
  73. Return Value:
  74. TBD.
  75. --*/
  76. {
  77. NTSTATUS st;
  78. SMAPIMSG SmApiMsg;
  79. PSMLOADDEFERED args;
  80. if ( DeferedSubsystem->Length >> 1 > SMP_MAXIMUM_SUBSYSTEM_NAME ) {
  81. return STATUS_INVALID_PARAMETER;
  82. }
  83. args = &SmApiMsg.u.LoadDefered;
  84. args->SubsystemNameLength = DeferedSubsystem->Length;
  85. RtlCopyMemory(args->SubsystemName,DeferedSubsystem->Buffer,DeferedSubsystem->Length);
  86. SmApiMsg.ApiNumber = SmLoadDeferedSubsystemApi;
  87. SmApiMsg.h.u1.s1.DataLength = sizeof(*args) + 8;
  88. SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
  89. SmApiMsg.h.u2.ZeroInit = 0L;
  90. st = NtRequestWaitReplyPort(
  91. SmApiPort,
  92. (PPORT_MESSAGE) &SmApiMsg,
  93. (PPORT_MESSAGE) &SmApiMsg
  94. );
  95. if ( NT_SUCCESS(st) ) {
  96. st = SmApiMsg.ReturnedStatus;
  97. } else {
  98. KdPrint(("SmExecPgm: NtRequestWaitReply Failed %lx\n",st));
  99. }
  100. return st;
  101. }
  102. NTSTATUS
  103. SmSessionComplete(
  104. IN HANDLE SmApiPort,
  105. IN ULONG SessionId,
  106. IN NTSTATUS CompletionStatus
  107. )
  108. /*++
  109. Routine Description:
  110. This routine is used to report completion of a session to
  111. the NT Session manager.
  112. Arguments:
  113. SmApiPort - Supplies a handle to a communications port connected
  114. to the Session Manager.
  115. SessionId - Supplies the session id of the session which is now completed.
  116. CompletionStatus - Supplies the completion status of the session.
  117. Return Value:
  118. TBD.
  119. --*/
  120. {
  121. NTSTATUS st;
  122. SMAPIMSG SmApiMsg;
  123. PSMSESSIONCOMPLETE args;
  124. args = &SmApiMsg.u.SessionComplete;
  125. args->SessionId = SessionId;
  126. args->CompletionStatus = CompletionStatus;
  127. SmApiMsg.ApiNumber = SmSessionCompleteApi;
  128. SmApiMsg.h.u1.s1.DataLength = sizeof(*args) + 8;
  129. SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
  130. SmApiMsg.h.u2.ZeroInit = 0L;
  131. st = NtRequestWaitReplyPort(
  132. SmApiPort,
  133. (PPORT_MESSAGE) &SmApiMsg,
  134. (PPORT_MESSAGE) &SmApiMsg
  135. );
  136. if ( NT_SUCCESS(st) ) {
  137. st = SmApiMsg.ReturnedStatus;
  138. } else {
  139. KdPrint(("SmCompleteSession: NtRequestWaitReply Failed %lx\n",st));
  140. }
  141. return st;
  142. }
  143. NTSTATUS
  144. SmStartCsr(
  145. IN HANDLE SmApiPort,
  146. OUT PULONG pMuSessionId,
  147. IN PUNICODE_STRING InitialCommand,
  148. OUT PULONG_PTR pInitialCommandProcessId,
  149. OUT PULONG_PTR pWindowsSubSysProcessId
  150. )
  151. /*++
  152. Routine Description:
  153. This routine allows TERMSRV to start a new CSR.
  154. Arguments:
  155. SmApiPort - Supplies a handle to a communications port connected
  156. to the Session Manager.
  157. MuSessionId - Hydra Terminal Session Id to start CSR in.
  158. InitialCommand - String for Initial Command (for debug)
  159. pInitialCommandProcessId - pointer to Process Id of initial command.
  160. pWindowsSubSysProcessId - pointer to Process Id of Windows subsystem.
  161. Return Value:
  162. Whether it worked.
  163. --*/
  164. {
  165. NTSTATUS st;
  166. SMAPIMSG SmApiMsg;
  167. PSMSTARTCSR args;
  168. args = &SmApiMsg.u.StartCsr;
  169. args->MuSessionId = *pMuSessionId; //Sm will reassign the actuall sessionID
  170. if ( InitialCommand &&
  171. ( InitialCommand->Length >> 1 > SMP_MAXIMUM_INITIAL_COMMAND ) ) {
  172. return STATUS_INVALID_PARAMETER;
  173. }
  174. if ( !InitialCommand ) {
  175. args->InitialCommandLength = 0;
  176. }
  177. else {
  178. args->InitialCommandLength = InitialCommand->Length;
  179. RtlCopyMemory(args->InitialCommand,InitialCommand->Buffer,InitialCommand->Length);
  180. }
  181. SmApiMsg.ApiNumber = SmStartCsrApi;
  182. SmApiMsg.h.u1.s1.DataLength = sizeof(*args) + 8;
  183. SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
  184. SmApiMsg.h.u2.ZeroInit = 0L;
  185. st = NtRequestWaitReplyPort(
  186. SmApiPort,
  187. (PPORT_MESSAGE) &SmApiMsg,
  188. (PPORT_MESSAGE) &SmApiMsg
  189. );
  190. if ( NT_SUCCESS(st) ) {
  191. st = SmApiMsg.ReturnedStatus;
  192. } else {
  193. DbgPrint("SmStartCsr: NtRequestWaitReply Failed %lx\n",st);
  194. }
  195. *pInitialCommandProcessId = args->InitialCommandProcessId;
  196. *pWindowsSubSysProcessId = args->WindowsSubSysProcessId;
  197. *pMuSessionId = args->MuSessionId;
  198. return st;
  199. }
  200. NTSTATUS
  201. SmStopCsr(
  202. IN HANDLE SmApiPort,
  203. IN ULONG MuSessionId
  204. )
  205. /*++
  206. Routine Description:
  207. This routine allows TERMSRV to stop a CSR.
  208. Arguments:
  209. SmApiPort - Supplies a handle to a communications port connected
  210. to the Session Manager.
  211. MuSessionId - Terminal Server Session Id to stop
  212. Return Value:
  213. Whether it worked.
  214. --*/
  215. {
  216. NTSTATUS st;
  217. SMAPIMSG SmApiMsg;
  218. PSMSTOPCSR args;
  219. args = &SmApiMsg.u.StopCsr;
  220. args->MuSessionId = MuSessionId;
  221. SmApiMsg.ApiNumber = SmStopCsrApi;
  222. SmApiMsg.h.u1.s1.DataLength = sizeof(*args) + 8;
  223. SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);
  224. SmApiMsg.h.u2.ZeroInit = 0L;
  225. st = NtRequestWaitReplyPort(
  226. SmApiPort,
  227. (PPORT_MESSAGE) &SmApiMsg,
  228. (PPORT_MESSAGE) &SmApiMsg
  229. );
  230. if ( NT_SUCCESS(st) ) {
  231. st = SmApiMsg.ReturnedStatus;
  232. } else {
  233. DbgPrint("SmStopCsr: NtRequestWaitReply Failed %lx\n",st);
  234. }
  235. return st;
  236. }