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.

234 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. smsmapi.c
  5. Abstract:
  6. Implementation of Session Manager Sm APIs.
  7. Author:
  8. Mark Lucovsky (markl) 04-Oct-1989
  9. Revision History:
  10. --*/
  11. #include "smsrvp.h"
  12. NTSTATUS
  13. SmpCreateForeignSession(
  14. IN PSMAPIMSG SmApiMsg,
  15. IN PSMP_CLIENT_CONTEXT CallingClient,
  16. IN HANDLE CallPort
  17. )
  18. {
  19. UNREFERENCED_PARAMETER (SmApiMsg);
  20. UNREFERENCED_PARAMETER (CallingClient);
  21. UNREFERENCED_PARAMETER (CallPort);
  22. return STATUS_NOT_IMPLEMENTED;
  23. }
  24. NTSTATUS
  25. SmpSessionComplete(
  26. IN PSMAPIMSG SmApiMsg,
  27. IN PSMP_CLIENT_CONTEXT CallingClient,
  28. IN HANDLE CallPort
  29. )
  30. /*++
  31. Routine Description:
  32. This API is called by a subsystem to report that a session is
  33. complete. A check is made to ensure that the calling subsystem
  34. owns the completed session. If so then the session is deleted.
  35. Arguments:
  36. SmApiMsg - Supplies the API message.
  37. CallingClient - Supplies the address of the context block for the calling
  38. client.
  39. CallPort - The port over which the call was received.
  40. Return Value:
  41. NTSTATUS.
  42. --*/
  43. {
  44. PSMPSESSION Session;
  45. PSMSESSIONCOMPLETE args;
  46. NTSTATUS st;
  47. UNREFERENCED_PARAMETER (CallPort);
  48. args = &SmApiMsg->u.SessionComplete;
  49. RtlEnterCriticalSection(&SmpSessionListLock);
  50. Session = SmpSessionIdToSession(args->SessionId);
  51. RtlLeaveCriticalSection(&SmpSessionListLock);
  52. //
  53. // If a session is found, then ensure that calling subsystem is its
  54. // owner.
  55. //
  56. if ( Session ) {
  57. if ( Session->OwningSubsystem == CallingClient->KnownSubSys ) {
  58. SmpDeleteSession(args->SessionId);
  59. st = STATUS_SUCCESS;
  60. } else {
  61. st = STATUS_INVALID_PARAMETER;
  62. }
  63. } else {
  64. st = STATUS_INVALID_PARAMETER;
  65. }
  66. return st;
  67. }
  68. NTSTATUS
  69. SmpTerminateForeignSession(
  70. IN PSMAPIMSG SmApiMsg,
  71. IN PSMP_CLIENT_CONTEXT CallingClient,
  72. IN HANDLE CallPort
  73. )
  74. {
  75. UNREFERENCED_PARAMETER (SmApiMsg);
  76. UNREFERENCED_PARAMETER (CallingClient);
  77. UNREFERENCED_PARAMETER (CallPort);
  78. return STATUS_NOT_IMPLEMENTED;
  79. }
  80. NTSTATUS
  81. SmpExecPgm(
  82. IN PSMAPIMSG SmApiMsg,
  83. IN PSMP_CLIENT_CONTEXT CallingClient,
  84. IN HANDLE CallPort
  85. )
  86. {
  87. NTSTATUS st;
  88. HANDLE SourceProcess;
  89. OBJECT_ATTRIBUTES ObjectAttributes;
  90. PSMEXECPGM args;
  91. RTL_USER_PROCESS_INFORMATION ProcessInformation;
  92. PCLIENT_ID DebugUiClientId;
  93. UNREFERENCED_PARAMETER (CallingClient);
  94. UNREFERENCED_PARAMETER (CallPort);
  95. //
  96. // Open a handle to the calling process so the
  97. // handles that it is passing can be duplicated.
  98. //
  99. InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL );
  100. st = NtOpenProcess(
  101. &SourceProcess,
  102. PROCESS_DUP_HANDLE,
  103. &ObjectAttributes,
  104. &SmApiMsg->h.ClientId
  105. );
  106. if (!NT_SUCCESS(st) ) {
  107. DbgPrint("SmExecPgm: NtOpenProcess Failed %lx\n",st);
  108. return st;
  109. }
  110. args = &SmApiMsg->u.ExecPgm;
  111. ProcessInformation = args->ProcessInformation;
  112. //
  113. // Get all handles in our table.
  114. //
  115. st = NtDuplicateObject(
  116. SourceProcess,
  117. args->ProcessInformation.Process,
  118. NtCurrentProcess(),
  119. &ProcessInformation.Process,
  120. PROCESS_ALL_ACCESS,
  121. 0,
  122. 0
  123. );
  124. if ( !NT_SUCCESS(st) ) {
  125. NtClose(SourceProcess);
  126. DbgPrint("SmExecPgm: NtDuplicateObject (Process) Failed %lx\n",st);
  127. return st;
  128. }
  129. st = NtDuplicateObject(
  130. SourceProcess,
  131. args->ProcessInformation.Thread,
  132. NtCurrentProcess(),
  133. &ProcessInformation.Thread,
  134. THREAD_ALL_ACCESS,
  135. 0,
  136. 0
  137. );
  138. if ( !NT_SUCCESS(st) ) {
  139. NtClose(ProcessInformation.Process);
  140. NtClose(SourceProcess);
  141. DbgPrint("SmExecPgm: NtDuplicateObject (Thread) Failed %lx\n",st);
  142. return st;
  143. }
  144. //
  145. // Done getting the handles, so close our handle to the calling
  146. // process and call the appropriate subsystem to start the process.
  147. //
  148. NtClose(SourceProcess);
  149. //
  150. // All handles passed are closed by SmpSbCreateSession.
  151. //
  152. if ( args->DebugFlag ) {
  153. DebugUiClientId = &SmApiMsg->h.ClientId;
  154. } else {
  155. DebugUiClientId = NULL;
  156. }
  157. st = SmpSbCreateSession(
  158. NULL,
  159. NULL,
  160. &ProcessInformation,
  161. 0L,
  162. DebugUiClientId
  163. );
  164. return st;
  165. }