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.

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