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.

481 lines
14 KiB

  1. //---------------------------------------------------------------------------
  2. // ThemeLdr.cpp - entrypoints for routines declared in ThemeLdr.h
  3. //---------------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include "Services.h"
  6. #include "ThemeServer.h"
  7. #include "loader.h"
  8. //---------------------------------------------------------------------------
  9. // --------------------------------------------------------------------------
  10. // InjectedThreadDispatcherExceptionFilter
  11. //
  12. // Arguments: pExceptionInfo = Exception that happened.
  13. //
  14. // Returns: LONG
  15. //
  16. // Purpose: Filters exceptions that occur when executing injected threads
  17. // into another process context to prevent the process from
  18. // terminating due to unforeseen exceptions.
  19. //
  20. // History: 2000-10-13 vtan created
  21. // 2001-05-18 vtan copied from theme service LPC
  22. // --------------------------------------------------------------------------
  23. LONG WINAPI InjectedThreadExceptionFilter (struct _EXCEPTION_POINTERS *pExceptionInfo)
  24. {
  25. (LONG)RtlUnhandledExceptionFilter(pExceptionInfo);
  26. return(EXCEPTION_EXECUTE_HANDLER);
  27. }
  28. // --------------------------------------------------------------------------
  29. // ::SessionAllocate
  30. //
  31. // Arguments: hProcess = Winlogon process for the session.
  32. // dwServerChangeNumber = Server base change number.
  33. // pfnRegister = Address of register function.
  34. // pfnUnregister = Address of unregister function.
  35. //
  36. // Returns: void*
  37. //
  38. // Purpose: Allocates a CThemeServer object that contains information
  39. // for a theme session. Wrapped in try/except because of
  40. // critical section initialization.
  41. //
  42. // History: 2000-11-11 vtan created
  43. // --------------------------------------------------------------------------
  44. EXTERN_C void* WINAPI SessionAllocate (HANDLE hProcess, DWORD dwServerChangeNumber, void *pfnRegister, void *pfnUnregister, void *pfnClearStockObjects, DWORD dwStackSizeReserve, DWORD dwStackSizeCommit)
  45. {
  46. CThemeServer *pvContext;
  47. __try
  48. {
  49. pvContext = new CThemeServer(hProcess, dwServerChangeNumber, pfnRegister, pfnUnregister, pfnClearStockObjects, dwStackSizeReserve, dwStackSizeCommit);
  50. }
  51. __except (EXCEPTION_EXECUTE_HANDLER)
  52. {
  53. pvContext = NULL;
  54. }
  55. return(pvContext);
  56. }
  57. // --------------------------------------------------------------------------
  58. // ::SessionFree
  59. //
  60. // Arguments: pvContext = CThemeServer this object.
  61. //
  62. // Returns: <none>
  63. //
  64. // Purpose: Destroys the CThemeServer object when the session goes away.
  65. //
  66. // History: 2000-11-11 vtan created
  67. // --------------------------------------------------------------------------
  68. EXTERN_C void WINAPI SessionFree (void *pvContext)
  69. {
  70. delete static_cast<CThemeServer*>(pvContext);
  71. }
  72. // --------------------------------------------------------------------------
  73. // ::ThemeHooksOn
  74. //
  75. // Arguments: pvContext = CThemeServer this object.
  76. //
  77. // Returns: HRESULT
  78. //
  79. // Purpose: Pass thru function.
  80. //
  81. // History: 2000-11-11 vtan created
  82. // --------------------------------------------------------------------------
  83. EXTERN_C HRESULT WINAPI ThemeHooksOn (void *pvContext)
  84. {
  85. return(static_cast<CThemeServer*>(pvContext)->ThemeHooksOn());
  86. }
  87. // --------------------------------------------------------------------------
  88. // ::ThemeHooksOff
  89. //
  90. // Arguments: pvContext = CThemeServer this object.
  91. //
  92. // Returns: HRESULT
  93. //
  94. // Purpose: Pass thru function.
  95. //
  96. // History: 2000-11-11 vtan created
  97. // --------------------------------------------------------------------------
  98. EXTERN_C HRESULT WINAPI ThemeHooksOff (void *pvContext)
  99. {
  100. (HRESULT)static_cast<CThemeServer*>(pvContext)->ThemeHooksOff();
  101. return(S_OK);
  102. }
  103. // --------------------------------------------------------------------------
  104. // ::AreThemeHooksActive
  105. //
  106. // Arguments: pvContext = CThemeServer this object.
  107. //
  108. // Returns: BOOL
  109. //
  110. // Purpose: Pass thru function.
  111. //
  112. // History: 2000-11-11 vtan created
  113. // --------------------------------------------------------------------------
  114. EXTERN_C BOOL WINAPI AreThemeHooksActive (void *pvContext)
  115. {
  116. return(static_cast<CThemeServer*>(pvContext)->AreThemeHooksActive());
  117. }
  118. // --------------------------------------------------------------------------
  119. // ::GetCurrentChangeNumber
  120. //
  121. // Arguments: pvContext = CThemeServer this object.
  122. //
  123. // Returns: int
  124. //
  125. // Purpose: Pass thru function.
  126. //
  127. // History: 2000-11-11 vtan created
  128. // --------------------------------------------------------------------------
  129. EXTERN_C int WINAPI GetCurrentChangeNumber (void *pvContext)
  130. {
  131. return(static_cast<CThemeServer*>(pvContext)->GetCurrentChangeNumber());
  132. }
  133. // --------------------------------------------------------------------------
  134. // ::GetNewChangeNumber
  135. //
  136. // Arguments: pvContext = CThemeServer this object.
  137. //
  138. // Returns: int
  139. //
  140. // Purpose: Pass thru function.
  141. //
  142. // History: 2000-11-11 vtan created
  143. // --------------------------------------------------------------------------
  144. EXTERN_C int WINAPI GetNewChangeNumber (void *pvContext)
  145. {
  146. return(static_cast<CThemeServer*>(pvContext)->GetNewChangeNumber());
  147. }
  148. // --------------------------------------------------------------------------
  149. // ::SetGlobalTheme
  150. //
  151. // Arguments: pvContext = CThemeServer this object.
  152. //
  153. // Returns: HRESULT
  154. //
  155. // Purpose: Pass thru function.
  156. //
  157. // History: 2000-11-11 vtan created
  158. // --------------------------------------------------------------------------
  159. EXTERN_C HRESULT WINAPI SetGlobalTheme (void *pvContext, HANDLE hSection)
  160. {
  161. return(static_cast<CThemeServer*>(pvContext)->SetGlobalTheme(hSection));
  162. }
  163. // --------------------------------------------------------------------------
  164. // ::GetGlobalTheme
  165. //
  166. // Arguments: pvContext = CThemeServer this object.
  167. //
  168. // Returns: HRESULT
  169. //
  170. // Purpose: Pass thru function.
  171. //
  172. // History: 2000-11-11 vtan created
  173. // --------------------------------------------------------------------------
  174. EXTERN_C HRESULT WINAPI GetGlobalTheme (void *pvContext, HANDLE *phSection)
  175. {
  176. return(static_cast<CThemeServer*>(pvContext)->GetGlobalTheme(phSection));
  177. }
  178. // --------------------------------------------------------------------------
  179. // ::LoadTheme
  180. //
  181. // Arguments: pvContext = CThemeServer this object.
  182. //
  183. // Returns: HRESULT
  184. //
  185. // Purpose: Pass thru function.
  186. //
  187. // History: 2000-11-11 vtan created
  188. // --------------------------------------------------------------------------
  189. EXTERN_C HRESULT WINAPI LoadTheme (
  190. void *pvContext,
  191. HANDLE hSection,
  192. HANDLE *phSection,
  193. LPCWSTR pszName,
  194. LPCWSTR pszColor,
  195. LPCWSTR pszSize,
  196. OPTIONAL DWORD dwFlags )
  197. {
  198. return(static_cast<CThemeServer*>(pvContext)->LoadTheme(
  199. hSection, phSection, pszName, pszColor, pszSize, dwFlags));
  200. }
  201. // --------------------------------------------------------------------------
  202. // ::InitUserTheme
  203. //
  204. // Arguments: BOOL
  205. //
  206. // Returns: HRESULT
  207. //
  208. // Purpose: Pass thru function.
  209. //
  210. // History: 2000-11-11 vtan created
  211. // --------------------------------------------------------------------------
  212. EXTERN_C HRESULT WINAPI InitUserTheme (BOOL fPolicyCheckOnly)
  213. {
  214. return(CThemeServices::InitUserTheme(fPolicyCheckOnly));
  215. }
  216. // --------------------------------------------------------------------------
  217. // ::InitUserRegistry
  218. //
  219. // Arguments: <none>
  220. //
  221. // Returns: HRESULT
  222. //
  223. // Purpose: Pass thru function.
  224. //
  225. // History: 2000-11-15 vtan created
  226. // --------------------------------------------------------------------------
  227. EXTERN_C HRESULT WINAPI InitUserRegistry (void)
  228. {
  229. return(CThemeServices::InitUserRegistry());
  230. }
  231. // --------------------------------------------------------------------------
  232. // ::ReestablishServerConnection
  233. //
  234. // Arguments: <none>
  235. //
  236. // Returns: <none>
  237. //
  238. // Purpose: Pass thru function.
  239. //
  240. // History: 2000-11-17 vtan created
  241. // --------------------------------------------------------------------------
  242. EXTERN_C HRESULT WINAPI ReestablishServerConnection (void)
  243. {
  244. return(CThemeServices::ReestablishServerConnection());
  245. }
  246. // --------------------------------------------------------------------------
  247. // ::ThemeHooksInstall
  248. //
  249. // Arguments: pvContext = Unused.
  250. //
  251. // Returns: DWORD
  252. //
  253. // Purpose: Pass thru function.
  254. //
  255. // History: 2000-11-11 vtan created
  256. // --------------------------------------------------------------------------
  257. EXTERN_C DWORD WINAPI ThemeHooksInstall (void *pvContext)
  258. {
  259. UNREFERENCED_PARAMETER(pvContext);
  260. DWORD dwResult;
  261. __try
  262. {
  263. dwResult = CThemeServer::ThemeHooksInstall();
  264. }
  265. __except (InjectedThreadExceptionFilter(GetExceptionInformation()))
  266. {
  267. dwResult = 0;
  268. }
  269. ExitThread(dwResult);
  270. }
  271. // --------------------------------------------------------------------------
  272. // ::ThemeHooksRemove
  273. //
  274. // Arguments: pvContext = Unused.
  275. //
  276. // Returns: DWORD
  277. //
  278. // Purpose: Pass thru function.
  279. //
  280. // History: 2000-11-11 vtan created
  281. // --------------------------------------------------------------------------
  282. EXTERN_C DWORD WINAPI ThemeHooksRemove (void *pvContext)
  283. {
  284. UNREFERENCED_PARAMETER(pvContext);
  285. DWORD dwResult;
  286. __try
  287. {
  288. dwResult = CThemeServer::ThemeHooksRemove();
  289. }
  290. __except (InjectedThreadExceptionFilter(GetExceptionInformation()))
  291. {
  292. dwResult = 0;
  293. }
  294. ExitThread(dwResult);
  295. }
  296. // --------------------------------------------------------------------------
  297. // ::ServerClearStockObjects
  298. //
  299. // Arguments: pvContext = ptr to section
  300. //
  301. // Returns: <none>
  302. //
  303. // Purpose: Pass thru function.
  304. //
  305. // History: 2001-05-01 rfernand created
  306. // --------------------------------------------------------------------------
  307. EXTERN_C void WINAPI ServerClearStockObjects (void *pvContext)
  308. {
  309. DWORD dwResult;
  310. __try
  311. {
  312. dwResult = CThemeServer::ClearStockObjects(HANDLE(pvContext));
  313. }
  314. __except (InjectedThreadExceptionFilter(GetExceptionInformation()))
  315. {
  316. dwResult = 0;
  317. }
  318. ExitThread(dwResult);
  319. }
  320. // --------------------------------------------------------------------------
  321. // ::ServiceClearStockObjects
  322. //
  323. // Arguments: pvContext = CThemeServer this object.
  324. // hSection = Theme section handle containing
  325. //
  326. // Returns: <none>
  327. //
  328. // Purpose: Pass thru function. This function differs from
  329. // ::ServerClearStockObjects in that it is intended to be called
  330. // from the theme service, which can't clean stock bitmaps
  331. // itself (not on the winsta that created the bitmaps).
  332. //
  333. // History: 2002-03-11 scotthan created
  334. // --------------------------------------------------------------------------
  335. EXTERN_C HRESULT ServiceClearStockObjects(PVOID pvContext, HANDLE hSection )
  336. {
  337. return (static_cast<CThemeServer*>(pvContext)->InjectStockObjectCleanupThread(hSection));
  338. }
  339. //---------------------------------------------------------------------------
  340. // --------------------------------------------------------------------------
  341. // ::ClearTheme
  342. //
  343. // Arguments: hSection = Theme section to clear.
  344. //
  345. // Returns: HRESULT
  346. //
  347. // Purpose: Clears stock bitmaps in the theme section data and closes it.
  348. //
  349. // History: 2000-11-21 vtan created
  350. // --------------------------------------------------------------------------
  351. HRESULT WINAPI ClearTheme (HANDLE hSection, BOOL fForce)
  352. {
  353. HRESULT hr;
  354. if (hSection != NULL)
  355. {
  356. hr = CThemeServices::ClearStockObjects(hSection, fForce);
  357. }
  358. else
  359. {
  360. hr = S_OK;
  361. }
  362. //---- always close the handle ----
  363. CloseHandle(hSection);
  364. return(hr);
  365. }
  366. // --------------------------------------------------------------------------
  367. // ::MarkSection
  368. //
  369. // Arguments: hSection = Section to change
  370. // dwAdd, dwRemove = Flags to set or clear in the header.
  371. // See loader.h.
  372. //
  373. // Returns: void
  374. //
  375. // Purpose: Update the global section state.
  376. //
  377. // History: 2001-05-08 lmouton created
  378. // --------------------------------------------------------------------------
  379. EXTERN_C void WINAPI MarkSection (HANDLE hSection, DWORD dwAdd, DWORD dwRemove)
  380. {
  381. Log(LOG_TMLOAD, L"MarkSection: Add %d and remove %d on %X", dwAdd, dwRemove, hSection);
  382. void *pV = MapViewOfFile(hSection,
  383. FILE_MAP_WRITE,
  384. 0,
  385. 0,
  386. 0);
  387. if (pV != NULL)
  388. {
  389. THEMEHDR *hdr = reinterpret_cast<THEMEHDR*>(pV);
  390. // Do some validation
  391. if (0 == memcmp(hdr->szSignature, kszBeginCacheFileSignature, kcbBeginSignature)
  392. && hdr->dwVersion == THEMEDATA_VERSION)
  393. {
  394. // Only allow this flag for now
  395. if (dwRemove == SECTION_HASSTOCKOBJECTS)
  396. {
  397. Log(LOG_TMLOAD, L"MarkSection: Previous flags were %d", hdr->dwFlags);
  398. hdr->dwFlags &= ~dwRemove;
  399. }
  400. }
  401. UnmapViewOfFile(pV);
  402. }
  403. #ifdef DEBUG
  404. else
  405. {
  406. Log(LOG_TMLOAD, L"MarkSection: Failed to open write handle for %X", hSection);
  407. }
  408. #endif
  409. }