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.

186 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. sbreqst.c
  5. Abstract:
  6. This module contains the Server Request thread procedure for the Sb
  7. API calls exported by the Server side of the Client-Server Runtime
  8. Subsystem to the Session Manager SubSystem.
  9. Author:
  10. Steve Wood (stevewo) 8-Oct-1990
  11. Revision History:
  12. --*/
  13. #include "csrsrv.h"
  14. PSB_API_ROUTINE CsrServerSbApiDispatch[ SbMaxApiNumber+1 ] = {
  15. CsrSbCreateSession,
  16. CsrSbTerminateSession,
  17. CsrSbForeignSessionComplete,
  18. CsrSbCreateProcess,
  19. NULL
  20. };
  21. #if DBG
  22. PSZ CsrServerSbApiName[ SbMaxApiNumber+1 ] = {
  23. "SbCreateSession",
  24. "SbTerminateSession",
  25. "SbForeignSessionComplete",
  26. "SbCreateProcess",
  27. "Unknown Csr Sb Api Number"
  28. };
  29. #endif // DBG
  30. NTSTATUS
  31. CsrSbApiHandleConnectionRequest(
  32. IN PSBAPIMSG Message
  33. );
  34. #if _MSC_FULL_VER >= 13008827
  35. #pragma warning(push)
  36. #pragma warning(disable:4715) // Not all control paths return (due to infinite loop)
  37. #endif
  38. NTSTATUS
  39. CsrSbApiRequestThread(
  40. IN PVOID Parameter
  41. )
  42. {
  43. NTSTATUS Status;
  44. SBAPIMSG ReceiveMsg;
  45. PSBAPIMSG ReplyMsg;
  46. HANDLE hConnectionPort;
  47. ReplyMsg = NULL;
  48. while (TRUE) {
  49. Status = NtReplyWaitReceivePort( CsrSbApiPort,
  50. (PVOID)(&hConnectionPort),
  51. (PPORT_MESSAGE)ReplyMsg,
  52. (PPORT_MESSAGE)&ReceiveMsg
  53. );
  54. if (Status != 0) {
  55. if (NT_SUCCESS( Status )) {
  56. continue; // Try again if alerted or a failure
  57. }
  58. else {
  59. IF_DEBUG {
  60. DbgPrint( "CSRSS: ReceivePort failed - Status == %X\n", Status );
  61. }
  62. ReplyMsg = NULL;
  63. continue;
  64. }
  65. }
  66. //
  67. // Check to see if this is a connection request and handle
  68. //
  69. if (ReceiveMsg.h.u2.s2.Type == LPC_CONNECTION_REQUEST) {
  70. CsrSbApiHandleConnectionRequest( &ReceiveMsg );
  71. ReplyMsg = NULL;
  72. continue;
  73. }
  74. if (ReceiveMsg.h.u2.s2.Type == LPC_CLIENT_DIED ) {
  75. ReplyMsg = NULL;
  76. continue;
  77. }
  78. if (ReceiveMsg.h.u2.s2.Type == LPC_PORT_CLOSED ) {
  79. //
  80. // Close the handle to the connection's server communication port object
  81. //
  82. if (hConnectionPort != NULL) {
  83. NtClose( hConnectionPort );
  84. }
  85. ReplyMsg = NULL;
  86. continue;
  87. }
  88. if ((ULONG)ReceiveMsg.ApiNumber >= SbMaxApiNumber) {
  89. IF_DEBUG {
  90. DbgPrint( "CSRSS: %lx is invalid Sb ApiNumber\n",
  91. ReceiveMsg.ApiNumber
  92. );
  93. }
  94. ReceiveMsg.ApiNumber = SbMaxApiNumber;
  95. }
  96. ReplyMsg = &ReceiveMsg;
  97. if (ReceiveMsg.ApiNumber < SbMaxApiNumber) {
  98. if (!(*CsrServerSbApiDispatch[ ReceiveMsg.ApiNumber ])( &ReceiveMsg )) {
  99. ReplyMsg = NULL;
  100. }
  101. }
  102. else {
  103. ReplyMsg->ReturnedStatus = STATUS_NOT_IMPLEMENTED;
  104. }
  105. }
  106. NtTerminateThread( NtCurrentThread(), Status );
  107. return( Status ); // Remove no return value warning.
  108. Parameter; // Remove unreferenced parameter warning.
  109. }
  110. #if _MSC_FULL_VER >= 13008827
  111. #pragma warning(pop)
  112. #endif
  113. NTSTATUS
  114. CsrSbApiHandleConnectionRequest(
  115. IN PSBAPIMSG Message
  116. )
  117. {
  118. NTSTATUS st;
  119. REMOTE_PORT_VIEW ClientView;
  120. HANDLE CommunicationPort;
  121. //
  122. // The protocol for a subsystem is to connect to the session manager,
  123. // then to listen and accept a connection from the session manager
  124. //
  125. ClientView.Length = sizeof(ClientView);
  126. st = NtAcceptConnectPort(
  127. &CommunicationPort,
  128. NULL,
  129. (PPORT_MESSAGE)Message,
  130. TRUE,
  131. NULL,
  132. &ClientView
  133. );
  134. if ( !NT_SUCCESS(st) ) {
  135. KdPrint(("CSRSS: Sb Accept Connection failed %lx\n",st));
  136. return st;
  137. }
  138. st = NtCompleteConnectPort(CommunicationPort);
  139. if ( !NT_SUCCESS(st) ) {
  140. KdPrint(("CSRSS: Sb Complete Connection failed %lx\n",st));
  141. }
  142. return st;
  143. }