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.

346 lines
8.0 KiB

  1. //*************************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation 1998
  4. // All rights reserved
  5. //
  6. // events.cxx
  7. //
  8. //*************************************************************
  9. #include "appmgext.hxx"
  10. void
  11. CEvents::Assign(
  12. DWORD ErrorStatus,
  13. CAppInfo * pAppInfo
  14. )
  15. {
  16. WCHAR wszStatus[12];
  17. if ( ErrorStatus != ERROR_SUCCESS )
  18. {
  19. DwordToString( ErrorStatus, wszStatus );
  20. Report(
  21. EVENT_APPMGMT_ASSIGN_FAILED,
  22. ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED == ErrorStatus,
  23. 3,
  24. pAppInfo->_pwszDeploymentName,
  25. pAppInfo->_pwszGPOName,
  26. wszStatus );
  27. SetRsopFailureStatus(
  28. pAppInfo,
  29. ErrorStatus,
  30. EVENT_APPMGMT_ASSIGN_FAILED);
  31. }
  32. else
  33. {
  34. Report(
  35. EVENT_APPMGMT_ASSIGN,
  36. FALSE,
  37. 2,
  38. pAppInfo->_pwszDeploymentName,
  39. pAppInfo->_pwszGPOName );
  40. }
  41. }
  42. void
  43. CEvents::Reinstall(
  44. DWORD ErrorStatus,
  45. CAppInfo * pAppInfo
  46. )
  47. {
  48. WCHAR wszStatus[12];
  49. if ( ErrorStatus != ERROR_SUCCESS )
  50. {
  51. DwordToString( ErrorStatus, wszStatus );
  52. Report(
  53. EVENT_APPMGMT_REINSTALL_FAILED,
  54. ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED == ErrorStatus,
  55. 3,
  56. pAppInfo->_pwszDeploymentName,
  57. pAppInfo->_pwszGPOName,
  58. wszStatus );
  59. SetRsopFailureStatus(
  60. pAppInfo,
  61. ErrorStatus,
  62. EVENT_APPMGMT_REINSTALL_FAILED);
  63. }
  64. else
  65. {
  66. Report(
  67. EVENT_APPMGMT_REINSTALL,
  68. FALSE,
  69. 2,
  70. pAppInfo->_pwszDeploymentName,
  71. pAppInfo->_pwszGPOName );
  72. }
  73. }
  74. void
  75. CEvents::Unassign(
  76. DWORD ErrorStatus,
  77. CAppInfo * pAppInfo
  78. )
  79. {
  80. WCHAR wszStatus[12];
  81. if ( ErrorStatus != ERROR_SUCCESS )
  82. {
  83. DwordToString( ErrorStatus, wszStatus );
  84. Report(
  85. EVENT_APPMGMT_UNASSIGN_FAILED,
  86. ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED == ErrorStatus,
  87. 3,
  88. pAppInfo->_pwszDeploymentName,
  89. pAppInfo->_pwszGPOName,
  90. wszStatus );
  91. SetRsopFailureStatus(
  92. pAppInfo,
  93. ErrorStatus,
  94. EVENT_APPMGMT_UNASSIGN_FAILED);
  95. }
  96. else
  97. {
  98. Report(
  99. EVENT_APPMGMT_UNASSIGN,
  100. FALSE,
  101. 2,
  102. pAppInfo->_pwszDeploymentName,
  103. pAppInfo->_pwszGPOName );
  104. }
  105. }
  106. void
  107. CEvents::Upgrade(
  108. CAppInfo * pNewApp,
  109. CAppInfo * pOldApp,
  110. BOOL bForceUninstall
  111. )
  112. {
  113. DWORD EventId;
  114. EventId = bForceUninstall ? EVENT_APPMGMT_HARD_UPGRADE : EVENT_APPMGMT_SOFT_UPGRADE;
  115. Report(
  116. EventId,
  117. FALSE,
  118. 4,
  119. pNewApp->_pwszDeploymentName,
  120. pNewApp->_pwszGPOName,
  121. pOldApp->_pwszDeploymentName,
  122. pOldApp->_pwszGPOName );
  123. }
  124. void
  125. CEvents::UpgradeAbort(
  126. DWORD ErrorStatus,
  127. CAppInfo * pNewApp,
  128. CAppInfo * pOldApp,
  129. BOOL bOldFailed
  130. )
  131. {
  132. WCHAR wszStatus[12];
  133. DwordToString( ErrorStatus, wszStatus );
  134. Report(
  135. bOldFailed ? EVENT_APPMGMT_UPGRADE_ABORT : EVENT_APPMGMT_UPGRADE_ABORT2,
  136. ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED == ErrorStatus,
  137. 5,
  138. pNewApp->_pwszDeploymentName,
  139. pNewApp->_pwszGPOName,
  140. pOldApp->_pwszDeploymentName,
  141. pOldApp->_pwszGPOName,
  142. wszStatus );
  143. SetRsopFailureStatus(
  144. pNewApp,
  145. ErrorStatus,
  146. bOldFailed ? EVENT_APPMGMT_UPGRADE_ABORT : EVENT_APPMGMT_UPGRADE_ABORT2);
  147. }
  148. void
  149. CEvents::UpgradeComplete(
  150. CAppInfo * pNewApp,
  151. CAppInfo * pOldApp
  152. )
  153. {
  154. Report(
  155. EVENT_APPMGMT_UPGRADE_COMPLETE,
  156. FALSE,
  157. 4,
  158. pNewApp->_pwszDeploymentName,
  159. pNewApp->_pwszGPOName,
  160. pOldApp->_pwszDeploymentName,
  161. pOldApp->_pwszGPOName );
  162. }
  163. void
  164. CEvents::RemoveUnmanaged(
  165. CAppInfo * pAppInfo
  166. )
  167. {
  168. Report(
  169. EVENT_APPMGMT_REMOVE_UNMANAGED,
  170. FALSE,
  171. 2,
  172. pAppInfo->_pwszDeploymentName,
  173. pAppInfo->_pwszGPOName );
  174. }
  175. void
  176. CEvents::PolicyStatus(
  177. DWORD ErrorStatus,
  178. DWORD ErrorReason
  179. )
  180. {
  181. WCHAR wszStatus[12];
  182. WCHAR wszReason[192];
  183. DWORD Size;
  184. int Status;
  185. if ( ErrorStatus != ERROR_SUCCESS )
  186. {
  187. if ( ! LoadLoadString() )
  188. return;
  189. DwordToString( ErrorStatus, wszStatus );
  190. wszReason[0] = 0;
  191. Size = sizeof(wszReason) / sizeof(WCHAR);
  192. switch ( ErrorReason )
  193. {
  194. case ERRORREASON_CSPATH :
  195. (*pfnLoadStringW)( ghDllInstance, IDS_ERRORREASON_CSPATH, wszReason, Size );
  196. break;
  197. case ERRORREASON_ENUM :
  198. (*pfnLoadStringW)( ghDllInstance, IDS_ERRORREASON_ENUM, wszReason, Size );
  199. break;
  200. case ERRORREASON_LOCAL :
  201. (*pfnLoadStringW)( ghDllInstance, IDS_ERRORREASON_LOCAL, wszReason, Size );
  202. break;
  203. case ERRORREASON_PROCESS :
  204. if ( ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED != ErrorStatus )
  205. {
  206. (*pfnLoadStringW)( ghDllInstance, IDS_ERRORREASON_PROCESS, wszReason, Size );
  207. }
  208. else
  209. {
  210. //
  211. // When we fail due to the need for a sync foreground refresh, we log
  212. // a special warning event that makes the situation very clear
  213. //
  214. //
  215. // The message depends on whether this is user or machine policy, so we
  216. // load different messages in those cases
  217. //
  218. if ( _hUserToken )
  219. {
  220. (*pfnLoadStringW)( ghDllInstance, IDS_ERRORREASON_ASYNC_USER, wszReason, Size );
  221. }
  222. else
  223. {
  224. (*pfnLoadStringW)( ghDllInstance, IDS_ERRORREASON_ASYNC_MACHINE, wszReason, Size );
  225. }
  226. }
  227. break;
  228. }
  229. Report(
  230. EVENT_APPMGMT_POLICY_FAILED,
  231. ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED == ErrorStatus,
  232. 2,
  233. wszReason,
  234. wszStatus);
  235. }
  236. else
  237. {
  238. Report( EVENT_APPMGMT_POLICY, FALSE, 0 );
  239. }
  240. }
  241. void
  242. CEvents::PolicyAbort()
  243. {
  244. Report( EVENT_APPMGMT_POLICY_ABORT, FALSE, 0 );
  245. }
  246. void
  247. CEvents::Install(
  248. DWORD ErrorStatus,
  249. CAppInfo* pAppInfo
  250. )
  251. {
  252. ( (CEventsBase*) this)->Install(
  253. ErrorStatus,
  254. pAppInfo->_pwszDeploymentName,
  255. pAppInfo->_pwszGPOName);
  256. SetRsopFailureStatus(
  257. pAppInfo,
  258. ErrorStatus,
  259. EVENT_APPMGMT_INSTALL_FAILED);
  260. }
  261. void
  262. CEvents::Uninstall(
  263. DWORD ErrorStatus,
  264. CAppInfo* pAppInfo
  265. )
  266. {
  267. ( (CEventsBase*) this)->Uninstall(
  268. ErrorStatus,
  269. pAppInfo->_pwszDeploymentName,
  270. pAppInfo->_pwszGPOName);
  271. SetRsopFailureStatus(
  272. pAppInfo,
  273. ErrorStatus,
  274. EVENT_APPMGMT_UNINSTALL_FAILED);
  275. }
  276. void
  277. CEvents::RsopLoggingStatus( HRESULT hrStatus )
  278. {
  279. WCHAR wszStatus[12];
  280. DwordToString( (DWORD) hrStatus, wszStatus );
  281. Report( EVENT_APPMGMT_RSOP_FAILED, FALSE, 1, wszStatus );
  282. }
  283. void
  284. CEvents::SetRsopFailureStatus(
  285. CAppInfo* pAppInfo,
  286. DWORD dwStatus,
  287. DWORD dwEventId)
  288. {
  289. //
  290. // We only log failure status in logging (diagnostic) mode
  291. //
  292. if ( ! pAppInfo->_pManApp->GetRsopContext()->IsDiagnosticModeEnabled() )
  293. {
  294. return;
  295. }
  296. //
  297. // Now set the app's failure status
  298. //
  299. pAppInfo->SetRsopFailureStatus(
  300. dwStatus,
  301. dwEventId);
  302. }