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.

229 lines
7.3 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: BadApplicationAPIServer.cpp
  3. //
  4. // Copyright (c) 2000, Microsoft Corporation
  5. //
  6. // This file contains several classes that implemention virtual functions
  7. // for complete LPC functionality.
  8. //
  9. // History: 2000-08-25 vtan created
  10. // --------------------------------------------------------------------------
  11. #ifdef _X86_
  12. #include "StandardHeader.h"
  13. #include "BadApplicationAPIServer.h"
  14. #include <lpcfus.h>
  15. #include "BadApplicationDispatcher.h"
  16. #include "BadApplicationService.h"
  17. // --------------------------------------------------------------------------
  18. // CBadApplicationAPIServer::CBadApplicationAPIServer
  19. //
  20. // Arguments: <none>
  21. //
  22. // Returns: <none>
  23. //
  24. // Purpose: Constructor for the CBadApplicationAPIServer class.
  25. //
  26. // History: 2000-08-25 vtan created
  27. // --------------------------------------------------------------------------
  28. CBadApplicationAPIServer::CBadApplicationAPIServer (void)
  29. {
  30. }
  31. // --------------------------------------------------------------------------
  32. // CBadApplicationAPIServer::~CBadApplicationAPIServer
  33. //
  34. // Arguments: <none>
  35. //
  36. // Returns: <none>
  37. //
  38. // Purpose: Destructor for the CBadApplicationAPIServer class.
  39. //
  40. // History: 2000-08-25 vtan created
  41. // --------------------------------------------------------------------------
  42. CBadApplicationAPIServer::~CBadApplicationAPIServer (void)
  43. {
  44. }
  45. // --------------------------------------------------------------------------
  46. // CBadApplicationAPIServer::StrToInt
  47. //
  48. // Arguments: pszString = String to convert to a DWORD
  49. //
  50. // Returns: DWORD
  51. //
  52. // Purpose: Converts the string to a DWORD - UNSIGNED.
  53. //
  54. // History: 2000-11-07 vtan created
  55. // --------------------------------------------------------------------------
  56. DWORD CBadApplicationAPIServer::StrToInt (const WCHAR *pszString)
  57. {
  58. DWORD dwProcessID;
  59. WCHAR c;
  60. // Convert inline from decimal WCHAR string to int.
  61. dwProcessID = 0;
  62. c = *pszString++;
  63. while (c != L'\0')
  64. {
  65. dwProcessID *= 10;
  66. ASSERTMSG((c >= L'0') && (c <= L'9'), "Invalid decimal digit in CBadApplicationAPIServer::StrToInt");
  67. dwProcessID += (c - L'0');
  68. c = *pszString++;
  69. }
  70. return(dwProcessID);
  71. }
  72. // --------------------------------------------------------------------------
  73. // CBadApplicationAPIServer::GetPortName
  74. //
  75. // Arguments: <none>
  76. //
  77. // Returns: const WCHAR*
  78. //
  79. // Purpose: Returns a unicode string (const pointer) to the name of the
  80. // port for this server that supports multiple API sets.
  81. //
  82. // History: 2000-08-25 vtan created
  83. // --------------------------------------------------------------------------
  84. const WCHAR* CBadApplicationAPIServer::GetPortName (void)
  85. {
  86. return(FUS_PORT_NAME);
  87. }
  88. // --------------------------------------------------------------------------
  89. // CBadApplicationAPIServer::GetPortName
  90. //
  91. // Arguments: <none>
  92. //
  93. // Returns: const TCHAR*
  94. //
  95. // Purpose: Uses a common routine to get the theme service name.
  96. //
  97. // History: 2000-12-04 vtan created
  98. // --------------------------------------------------------------------------
  99. const TCHAR* CBadApplicationAPIServer::GetServiceName (void)
  100. {
  101. return(CBadApplicationService::GetName());
  102. }
  103. // --------------------------------------------------------------------------
  104. // CBadApplicationAPIServer::ConnectionAccepted
  105. //
  106. // Arguments: portMessage = PORT_MESSAGE from client.
  107. //
  108. // Returns: bool
  109. //
  110. // Purpose: Accepts or rejects a port connection request. Accepts all
  111. // connections currently.
  112. //
  113. // History: 2000-08-25 vtan created
  114. // --------------------------------------------------------------------------
  115. bool CBadApplicationAPIServer::ConnectionAccepted (const CPortMessage& portMessage)
  116. {
  117. return(lstrcmpW(reinterpret_cast<const WCHAR*>(portMessage.GetData()), FUS_CONNECTION_REQUEST) == 0);
  118. }
  119. // --------------------------------------------------------------------------
  120. // CBadApplicationAPIServer::CreateDispatchThread
  121. //
  122. // Arguments: portMessage = PORT_MESSAGE from client.
  123. //
  124. // Returns: CAPIDispatcher*
  125. //
  126. // Purpose: Called by the LPC connection request handler to create a new
  127. // thread to handle client requests.
  128. //
  129. // History: 2000-08-25 vtan created
  130. // --------------------------------------------------------------------------
  131. CAPIDispatcher* CBadApplicationAPIServer::CreateDispatcher (const CPortMessage& portMessage)
  132. {
  133. HANDLE hClientProcess;
  134. OBJECT_ATTRIBUTES objectAttributes;
  135. CLIENT_ID clientID;
  136. CAPIDispatcher *pAPIDispatcher;
  137. pAPIDispatcher = NULL;
  138. InitializeObjectAttributes(&objectAttributes,
  139. NULL,
  140. 0,
  141. NULL,
  142. NULL);
  143. clientID.UniqueProcess = portMessage.GetUniqueProcess();
  144. clientID.UniqueThread = NULL;
  145. // Open a handle to the client process. The handle must have PROCESS_DUP_HANDLE
  146. // for the server to be able to deliver handles to the client. It also needs
  147. // PROCESS_VM_READ | PROCESS_VM_WRITE if it's to read and write the client
  148. // address space to store data that's too big for the LPC port.
  149. // That handle is stored by the thread handler. It's not closed here.
  150. if (NT_SUCCESS(NtOpenProcess(&hClientProcess,
  151. PROCESS_QUERY_INFORMATION | PROCESS_DUP_HANDLE | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
  152. &objectAttributes,
  153. &clientID)))
  154. {
  155. pAPIDispatcher = new CBadApplicationDispatcher(hClientProcess);
  156. }
  157. return(pAPIDispatcher);
  158. }
  159. // --------------------------------------------------------------------------
  160. // CBadApplicationAPIServer::Connect
  161. //
  162. // Arguments: phPort = Handle to the port received on connection.
  163. //
  164. // Returns: NTSTATUS
  165. //
  166. // Purpose: Connects to the server.
  167. //
  168. // History: 2000-12-04 vtan created
  169. // --------------------------------------------------------------------------
  170. NTSTATUS CBadApplicationAPIServer::Connect (HANDLE* phPort)
  171. {
  172. ULONG ulConnectionInfoLength;
  173. UNICODE_STRING portName;
  174. SECURITY_QUALITY_OF_SERVICE sqos;
  175. WCHAR szConnectionInfo[64];
  176. RtlInitUnicodeString(&portName, GetPortName());
  177. sqos.Length = sizeof(sqos);
  178. sqos.ImpersonationLevel = SecurityImpersonation;
  179. sqos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  180. sqos.EffectiveOnly = TRUE;
  181. lstrcpyW(szConnectionInfo, FUS_CONNECTION_REQUEST);
  182. ulConnectionInfoLength = sizeof(szConnectionInfo);
  183. return(NtConnectPort(phPort,
  184. &portName,
  185. &sqos,
  186. NULL,
  187. NULL,
  188. NULL,
  189. szConnectionInfo,
  190. &ulConnectionInfoLength));
  191. }
  192. #endif /* _X86_ */