Leaked source code of windows server 2003
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.

198 lines
4.9 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. while (1) {
  50. Status = NtReplyWaitReceivePort (CsrSbApiPort,
  51. (PVOID)(&hConnectionPort),
  52. (PPORT_MESSAGE)ReplyMsg,
  53. (PPORT_MESSAGE)&ReceiveMsg);
  54. if (Status == STATUS_NO_MEMORY) {
  55. LARGE_INTEGER DelayTime;
  56. if (ReplyMsg != NULL) {
  57. KdPrint (("CSRSS: Failed to reply to calling thread, retrying.\n"));
  58. }
  59. DelayTime.QuadPart = Int32x32To64 (5000, -10000);
  60. NtDelayExecution (FALSE, &DelayTime);
  61. continue;
  62. }
  63. break;
  64. }
  65. if (Status != 0) {
  66. if (NT_SUCCESS( Status )) {
  67. continue; // Try again if alerted or a failure
  68. }
  69. else {
  70. IF_DEBUG {
  71. DbgPrint( "CSRSS: ReceivePort failed - Status == %X\n", Status );
  72. }
  73. ReplyMsg = NULL;
  74. continue;
  75. }
  76. }
  77. //
  78. // Check to see if this is a connection request and handle
  79. //
  80. if (ReceiveMsg.h.u2.s2.Type == LPC_CONNECTION_REQUEST) {
  81. CsrSbApiHandleConnectionRequest( &ReceiveMsg );
  82. ReplyMsg = NULL;
  83. continue;
  84. }
  85. if (ReceiveMsg.h.u2.s2.Type == LPC_CLIENT_DIED ) {
  86. ReplyMsg = NULL;
  87. continue;
  88. }
  89. if (ReceiveMsg.h.u2.s2.Type == LPC_PORT_CLOSED ) {
  90. //
  91. // Close the handle to the connection's server communication port object
  92. //
  93. if (hConnectionPort != NULL) {
  94. NtClose( hConnectionPort );
  95. }
  96. ReplyMsg = NULL;
  97. continue;
  98. }
  99. if ((ULONG)ReceiveMsg.ApiNumber >= SbMaxApiNumber) {
  100. IF_DEBUG {
  101. DbgPrint( "CSRSS: %lx is invalid Sb ApiNumber\n",
  102. ReceiveMsg.ApiNumber
  103. );
  104. }
  105. ReceiveMsg.ApiNumber = SbMaxApiNumber;
  106. }
  107. ReplyMsg = &ReceiveMsg;
  108. if (ReceiveMsg.ApiNumber < SbMaxApiNumber) {
  109. if (!(*CsrServerSbApiDispatch[ ReceiveMsg.ApiNumber ])( &ReceiveMsg )) {
  110. ReplyMsg = NULL;
  111. }
  112. }
  113. else {
  114. ReplyMsg->ReturnedStatus = STATUS_NOT_IMPLEMENTED;
  115. }
  116. }
  117. NtTerminateThread( NtCurrentThread(), Status );
  118. return( Status ); // Remove no return value warning.
  119. Parameter; // Remove unreferenced parameter warning.
  120. }
  121. #if _MSC_FULL_VER >= 13008827
  122. #pragma warning(pop)
  123. #endif
  124. NTSTATUS
  125. CsrSbApiHandleConnectionRequest(
  126. IN PSBAPIMSG Message
  127. )
  128. {
  129. NTSTATUS st;
  130. REMOTE_PORT_VIEW ClientView;
  131. HANDLE CommunicationPort;
  132. //
  133. // The protocol for a subsystem is to connect to the session manager,
  134. // then to listen and accept a connection from the session manager
  135. //
  136. ClientView.Length = sizeof(ClientView);
  137. st = NtAcceptConnectPort(
  138. &CommunicationPort,
  139. NULL,
  140. (PPORT_MESSAGE)Message,
  141. TRUE,
  142. NULL,
  143. &ClientView
  144. );
  145. if ( !NT_SUCCESS(st) ) {
  146. KdPrint(("CSRSS: Sb Accept Connection failed %lx\n",st));
  147. return st;
  148. }
  149. st = NtCompleteConnectPort(CommunicationPort);
  150. if ( !NT_SUCCESS(st) ) {
  151. KdPrint(("CSRSS: Sb Complete Connection failed %lx\n",st));
  152. }
  153. return st;
  154. }