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.

204 lines
5.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: wxsrv.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 4-18-97 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <wxlpc.h>
  21. #include <wxlpcp.h>
  22. NTSTATUS
  23. WxpHandleRequest(
  24. HANDLE Client,
  25. PWXLPC_MESSAGE Message
  26. )
  27. {
  28. WXLPC_GETKEYDATA * GetKey ;
  29. WXLPC_REPORTRESULTS * ReportResults ;
  30. switch ( Message->Api )
  31. {
  32. case WxGetKeyDataApi:
  33. GetKey = & Message->Parameters.GetKeyData ;
  34. if ( ( GetKey->ExpectedAuth != WxNone ) &&
  35. ( GetKey->ExpectedAuth != WxStored ) &&
  36. ( GetKey->ExpectedAuth != WxPrompt ) &&
  37. ( GetKey->ExpectedAuth != WxDisk ) )
  38. {
  39. Message->Status = STATUS_INVALID_PARAMETER ;
  40. break;
  41. }
  42. if ( GetKey->BufferSize > 16 )
  43. {
  44. Message->Status = STATUS_INVALID_PARAMETER ;
  45. break;
  46. }
  47. Message->Status = WxGetKeyData( NULL,
  48. GetKey->ExpectedAuth,
  49. GetKey->BufferSize,
  50. GetKey->Buffer,
  51. &GetKey->BufferData
  52. );
  53. break;
  54. case WxReportResultsApi:
  55. ReportResults = &Message->Parameters.ReportResults ;
  56. Message->Status = WxReportResults( NULL,
  57. ReportResults->Status
  58. );
  59. break;
  60. default:
  61. Message->Status = STATUS_NOT_IMPLEMENTED ;
  62. break;
  63. }
  64. return NtReplyPort( Client, &Message->Message );
  65. }
  66. NTSTATUS
  67. WxServerThread(
  68. PVOID Ignored
  69. )
  70. {
  71. HANDLE Port ;
  72. HANDLE ClientPort = NULL ;
  73. HANDLE RejectPort ;
  74. OBJECT_ATTRIBUTES Obja ;
  75. UNICODE_STRING PortName ;
  76. NTSTATUS Status ;
  77. WXLPC_MESSAGE Message ;
  78. PVOID Context ;
  79. //
  80. // Initialize the port:
  81. //
  82. RtlInitUnicodeString( &PortName, WX_PORT_NAME );
  83. InitializeObjectAttributes( &Obja,
  84. &PortName,
  85. 0,
  86. NULL,
  87. NULL );
  88. Status = NtCreatePort( &Port,
  89. &Obja,
  90. sizeof( ULONG ),
  91. sizeof( WXLPC_MESSAGE ),
  92. sizeof( WXLPC_MESSAGE )
  93. );
  94. if ( !NT_SUCCESS( Status ) )
  95. {
  96. return Status ;
  97. }
  98. //
  99. // Now, wait for a connection:
  100. //
  101. Context = NULL ;
  102. while ( Port )
  103. {
  104. Status = NtReplyWaitReceivePort(Port,
  105. &Context,
  106. NULL,
  107. &Message.Message );
  108. if ( !NT_SUCCESS( Status ) )
  109. {
  110. NtClose( Port );
  111. break;
  112. }
  113. switch ( Message.Message.u2.s2.Type )
  114. {
  115. case LPC_REQUEST:
  116. //DbgPrint( "Received request\n" );
  117. WxpHandleRequest( ClientPort, &Message );
  118. break;
  119. case LPC_PORT_CLOSED:
  120. //DbgPrint( "Received Port Close\n" );
  121. NtClose( ClientPort );
  122. NtClose( Port );
  123. WxClientDisconnect( NULL );
  124. Port = NULL ;
  125. break;
  126. case LPC_CONNECTION_REQUEST:
  127. //DbgPrint( "Received connection request\n" );
  128. if ( Context != NULL )
  129. {
  130. Status = NtAcceptConnectPort(
  131. &RejectPort,
  132. NULL,
  133. (PPORT_MESSAGE) &Message,
  134. FALSE,
  135. NULL,
  136. NULL);
  137. break;
  138. }
  139. else
  140. {
  141. Status = NtAcceptConnectPort(
  142. &ClientPort,
  143. &ClientPort,
  144. &Message.Message,
  145. TRUE,
  146. NULL,
  147. NULL );
  148. if ( NT_SUCCESS( Status ) )
  149. {
  150. NtCompleteConnectPort( ClientPort );
  151. }
  152. }
  153. default:
  154. break;
  155. }
  156. }
  157. return Status;
  158. }