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.

210 lines
6.6 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: ThemeManagerAPIServer.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-10-10 vtan created
  10. // --------------------------------------------------------------------------
  11. #include "StandardHeader.h"
  12. #include "ThemeManagerAPIServer.h"
  13. #include <lpcthemes.h>
  14. #include "ThemeManagerDispatcher.h"
  15. #include "ThemeManagerService.h"
  16. // --------------------------------------------------------------------------
  17. // CThemeManagerAPIServer::CThemeManagerAPIServer
  18. //
  19. // Arguments: <none>
  20. //
  21. // Returns: <none>
  22. //
  23. // Purpose: Constructor for the CThemeManagerAPIServer class.
  24. //
  25. // History: 2000-10-10 vtan created
  26. // --------------------------------------------------------------------------
  27. CThemeManagerAPIServer::CThemeManagerAPIServer (void)
  28. {
  29. }
  30. // --------------------------------------------------------------------------
  31. // CThemeManagerAPIServer::~CThemeManagerAPIServer
  32. //
  33. // Arguments: <none>
  34. //
  35. // Returns: <none>
  36. //
  37. // Purpose: Destructor for the CThemeManagerAPIServer class.
  38. //
  39. // History: 2000-10-10 vtan created
  40. // --------------------------------------------------------------------------
  41. CThemeManagerAPIServer::~CThemeManagerAPIServer (void)
  42. {
  43. }
  44. // --------------------------------------------------------------------------
  45. // CThemeManagerAPIServer::ConnectToServer
  46. //
  47. // Arguments: phPort = Handle to the port received on connection.
  48. //
  49. // Returns: NTSTATUS
  50. //
  51. // Purpose: Connects to the server.
  52. //
  53. // History: 2000-10-10 vtan created
  54. // --------------------------------------------------------------------------
  55. NTSTATUS CThemeManagerAPIServer::ConnectToServer (HANDLE *phPort)
  56. {
  57. ULONG ulConnectionInfoLength;
  58. UNICODE_STRING portName;
  59. SECURITY_QUALITY_OF_SERVICE sqos;
  60. WCHAR szConnectionInfo[64];
  61. RtlInitUnicodeString(&portName, GetPortName());
  62. sqos.Length = sizeof(sqos);
  63. sqos.ImpersonationLevel = SecurityImpersonation;
  64. sqos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  65. sqos.EffectiveOnly = TRUE;
  66. lstrcpyW(szConnectionInfo, THEMES_CONNECTION_REQUEST);
  67. ulConnectionInfoLength = sizeof(szConnectionInfo);
  68. return(NtConnectPort(phPort,
  69. &portName,
  70. &sqos,
  71. NULL,
  72. NULL,
  73. NULL,
  74. szConnectionInfo,
  75. &ulConnectionInfoLength));
  76. }
  77. // --------------------------------------------------------------------------
  78. // CThemeManagerAPIServer::GetPortName
  79. //
  80. // Arguments: <none>
  81. //
  82. // Returns: const WCHAR*
  83. //
  84. // Purpose: Uses a common routine to get the theme API port name.
  85. //
  86. // History: 2000-10-10 vtan created
  87. // --------------------------------------------------------------------------
  88. const WCHAR* CThemeManagerAPIServer::GetPortName (void)
  89. {
  90. return(THEMES_PORT_NAME);
  91. }
  92. // --------------------------------------------------------------------------
  93. // CThemeManagerAPIServer::GetPortName
  94. //
  95. // Arguments: <none>
  96. //
  97. // Returns: const TCHAR*
  98. //
  99. // Purpose: Uses a common routine to get the theme service name.
  100. //
  101. // History: 2000-11-29 vtan created
  102. // --------------------------------------------------------------------------
  103. const TCHAR* CThemeManagerAPIServer::GetServiceName (void)
  104. {
  105. return(CThemeManagerService::GetName());
  106. }
  107. // --------------------------------------------------------------------------
  108. // CThemeManagerAPIServer::ConnectionAccepted
  109. //
  110. // Arguments: portMessage = PORT_MESSAGE from client.
  111. //
  112. // Returns: bool
  113. //
  114. // Purpose: Accepts or rejects a port connection request. Accepts all
  115. // connections currently.
  116. //
  117. // History: 2000-10-10 vtan created
  118. // --------------------------------------------------------------------------
  119. bool CThemeManagerAPIServer::ConnectionAccepted (const CPortMessage& portMessage)
  120. {
  121. return(lstrcmpW(reinterpret_cast<const WCHAR*>(portMessage.GetData()), THEMES_CONNECTION_REQUEST) == 0);
  122. }
  123. // --------------------------------------------------------------------------
  124. // CThemeManagerAPIServer::CreateDispatcher
  125. //
  126. // Arguments: portMessage = PORT_MESSAGE from client.
  127. //
  128. // Returns: CAPIDispatcher*
  129. //
  130. // Purpose: Called by the LPC connection request handler to create a new
  131. // thread to handle client requests.
  132. //
  133. // History: 2000-10-10 vtan created
  134. // --------------------------------------------------------------------------
  135. CAPIDispatcher* CThemeManagerAPIServer::CreateDispatcher (const CPortMessage& portMessage)
  136. {
  137. HANDLE hClientProcess;
  138. OBJECT_ATTRIBUTES objectAttributes;
  139. CLIENT_ID clientID;
  140. CAPIDispatcher *pAPIDispatcher;
  141. pAPIDispatcher = NULL;
  142. InitializeObjectAttributes(&objectAttributes,
  143. NULL,
  144. 0,
  145. NULL,
  146. NULL);
  147. clientID.UniqueProcess = portMessage.GetUniqueProcess();
  148. clientID.UniqueThread = NULL;
  149. // Open a handle to the client process. The handle must have PROCESS_DUP_HANDLE
  150. // for the server to be able to deliver handles to the client. It also needs
  151. // PROCESS_VM_READ | PROCESS_VM_WRITE if it's to read and write the client
  152. // address space to store data that's too big for the LPC port.
  153. // That handle is stored by the thread handler. It's not closed here.
  154. if (NT_SUCCESS(NtOpenProcess(&hClientProcess,
  155. PROCESS_QUERY_INFORMATION | PROCESS_DUP_HANDLE | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
  156. &objectAttributes,
  157. &clientID)))
  158. {
  159. pAPIDispatcher = new CThemeManagerDispatcher(hClientProcess);
  160. }
  161. return(pAPIDispatcher);
  162. }
  163. // --------------------------------------------------------------------------
  164. // CThemeManagerAPIServer::Connect
  165. //
  166. // Arguments: phPort = Connection port returned.
  167. //
  168. // Returns: NTSTATUS
  169. //
  170. // Purpose: Connects to the server.
  171. //
  172. // History: 2000-10-13 vtan created
  173. // --------------------------------------------------------------------------
  174. NTSTATUS CThemeManagerAPIServer::Connect (HANDLE* phPort)
  175. {
  176. return(ConnectToServer(phPort));
  177. }