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.

535 lines
12 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. IncidentItem.cpp
  5. Abstract:
  6. File for Implementation of CSAFIncidentItem
  7. Revision History:
  8. Steve Shih created 07/15/99
  9. Davide Massarenti rewrote 12/05/2000
  10. ********************************************************************/
  11. #include "stdafx.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CSAFIncidentItem
  14. CSAFIncidentItem::CSAFIncidentItem()
  15. {
  16. __HCP_FUNC_ENTRY( "CSAFIncidentItem::CSAFIncidentItem" );
  17. // CSAFIncidentRecord m_increc;
  18. m_fDirty = false; // bool m_fDirty;
  19. }
  20. HRESULT CSAFIncidentItem::Import( /*[in] */ const CSAFIncidentRecord& increc )
  21. {
  22. __HCP_FUNC_ENTRY( "CSAFIncidentItem::Import" );
  23. m_increc = increc;
  24. __HCP_FUNC_EXIT(S_OK);
  25. }
  26. HRESULT CSAFIncidentItem::Export( /*[in] */ CSAFIncidentRecord& increc )
  27. {
  28. __HCP_FUNC_ENTRY( "CSAFIncidentItem::Export" );
  29. CSAFChannel *pChan;
  30. Child_GetParent( &pChan );
  31. increc = m_increc;
  32. increc.m_bstrVendorID = pChan->GetVendorID ();
  33. increc.m_bstrProductID = pChan->GetProductID();
  34. pChan->Release();
  35. __HCP_FUNC_EXIT(S_OK);
  36. }
  37. bool CSAFIncidentItem::MatchEnumOption( /*[in]*/ IncidentCollectionOptionEnum opt )
  38. {
  39. bool fRes = false;
  40. DWORD dwGroups = 0;
  41. switch(opt)
  42. {
  43. case pchAllIncidents : case pchAllIncidentsAllUsers : fRes = true ; break;
  44. case pchOpenIncidents : case pchOpenIncidentsAllUsers : fRes = (m_increc.m_iStatus == pchIncidentOpen ); break;
  45. case pchClosedIncidents: case pchClosedIncidentsAllUsers: fRes = (m_increc.m_iStatus == pchIncidentClosed); break;
  46. }
  47. switch(opt)
  48. {
  49. //
  50. // For these options, administrators will see other users' incidents.
  51. //
  52. case pchAllIncidentsAllUsers :
  53. case pchOpenIncidentsAllUsers :
  54. case pchClosedIncidentsAllUsers:
  55. dwGroups = MPC::IDENTITY_SYSTEM | MPC::IDENTITY_ADMIN | MPC::IDENTITY_ADMINS;
  56. break;
  57. }
  58. if(fRes && FAILED(MPC::CheckCallerAgainstPrincipal( /*fImpersonate*/true, m_increc.m_bstrOwner, dwGroups )))
  59. {
  60. fRes = false;
  61. }
  62. return fRes;
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. HRESULT CSAFIncidentItem::VerifyPermissions( /*[in]*/ bool fModify )
  66. {
  67. __HCP_FUNC_ENTRY( "CSAFIncidentItem::VerifyPermissions" );
  68. HRESULT hr;
  69. if(m_increc.m_bstrSecurity.Length())
  70. {
  71. MPC::AccessCheck ac;
  72. BOOL fGranted;
  73. DWORD dwGranted;
  74. __MPC_EXIT_IF_METHOD_FAILS(hr, ac.GetTokenFromImpersonation());
  75. __MPC_EXIT_IF_METHOD_FAILS(hr, ac.Verify( fModify ? ACCESS_WRITE : ACCESS_READ, fGranted, dwGranted, m_increc.m_bstrSecurity ));
  76. if(fGranted == FALSE)
  77. {
  78. __MPC_EXIT_IF_METHOD_FAILS(hr, E_ACCESSDENIED);
  79. }
  80. }
  81. hr = S_OK;
  82. __HCP_FUNC_CLEANUP;
  83. __HCP_FUNC_EXIT(hr);
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. STDMETHODIMP CSAFIncidentItem::get_DisplayString( /*[out, retval]*/ BSTR *pVal )
  87. {
  88. __HCP_BEGIN_PROPERTY_GET("CSAFIncidentItem::get_DisplayString",hr,pVal);
  89. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  90. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_increc.m_bstrDisplay, pVal ));
  91. __HCP_END_PROPERTY(hr);
  92. }
  93. STDMETHODIMP CSAFIncidentItem::put_DisplayString( /*[in]*/ BSTR newVal )
  94. {
  95. __HCP_BEGIN_PROPERTY_PUT("CSAFIncidentItem::put_DisplayString",hr);
  96. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( TRUE ));
  97. m_increc.m_bstrDisplay = newVal;
  98. m_fDirty = true;
  99. __MPC_EXIT_IF_METHOD_FAILS(hr, Save());
  100. __HCP_END_PROPERTY(hr);
  101. }
  102. STDMETHODIMP CSAFIncidentItem::get_URL( /*[out, retval]*/ BSTR *pVal )
  103. {
  104. __HCP_BEGIN_PROPERTY_GET("CSAFIncidentItem::get_URL",hr,pVal);
  105. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  106. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_increc.m_bstrURL, pVal ));
  107. __HCP_END_PROPERTY(hr);
  108. }
  109. STDMETHODIMP CSAFIncidentItem::put_URL( /*[in]*/ BSTR newVal )
  110. {
  111. __HCP_BEGIN_PROPERTY_PUT("CSAFIncidentItem::put_URL",hr);
  112. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( TRUE ));
  113. m_increc.m_bstrURL = newVal;
  114. m_fDirty = true;
  115. __MPC_EXIT_IF_METHOD_FAILS(hr, Save());
  116. __HCP_END_PROPERTY(hr);
  117. }
  118. STDMETHODIMP CSAFIncidentItem::get_Progress( /*[out, retval]*/ BSTR *pVal )
  119. {
  120. __HCP_BEGIN_PROPERTY_GET("CSAFIncidentItem::get_Progress",hr,pVal);
  121. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  122. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_increc.m_bstrProgress, pVal ));
  123. __HCP_END_PROPERTY(hr);
  124. }
  125. STDMETHODIMP CSAFIncidentItem::put_Progress( /*[in]*/ BSTR newVal )
  126. {
  127. __HCP_BEGIN_PROPERTY_PUT("CSAFIncidentItem::put_Progress",hr);
  128. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  129. m_increc.m_bstrProgress = newVal;
  130. m_fDirty = true;
  131. __MPC_EXIT_IF_METHOD_FAILS(hr, Save());
  132. __HCP_END_PROPERTY(hr);
  133. }
  134. STDMETHODIMP CSAFIncidentItem::get_XMLDataFile( /*[out, retval]*/ BSTR *pVal )
  135. {
  136. __HCP_BEGIN_PROPERTY_GET("CSAFIncidentItem::get_XMLDataFile",hr,pVal);
  137. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  138. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_increc.m_bstrXMLDataFile, pVal ));
  139. __HCP_END_PROPERTY(hr);
  140. }
  141. STDMETHODIMP CSAFIncidentItem::put_XMLDataFile( /*[in]*/ BSTR newVal )
  142. {
  143. __HCP_BEGIN_PROPERTY_PUT("CSAFIncidentItem::put_XMLDataFile",hr);
  144. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( TRUE ));
  145. m_increc.m_bstrXMLDataFile = newVal;
  146. m_fDirty = true;
  147. __MPC_EXIT_IF_METHOD_FAILS(hr, Save());
  148. __HCP_END_PROPERTY(hr);
  149. }
  150. STDMETHODIMP CSAFIncidentItem::get_XMLBlob( /*[out, retval]*/ BSTR *pVal )
  151. {
  152. __HCP_BEGIN_PROPERTY_GET("CSAFIncidentItem::get_XMLBlob",hr,pVal);
  153. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  154. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_increc.m_bstrXMLBlob, pVal ));
  155. __HCP_END_PROPERTY(hr);
  156. }
  157. STDMETHODIMP CSAFIncidentItem::put_XMLBlob( /*[in]*/ BSTR newVal )
  158. {
  159. __HCP_BEGIN_PROPERTY_PUT("CSAFIncidentItem::put_XMLBlob",hr);
  160. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( TRUE ));
  161. m_increc.m_bstrXMLBlob = newVal;
  162. m_fDirty = true;
  163. __MPC_EXIT_IF_METHOD_FAILS(hr, Save());
  164. __HCP_END_PROPERTY(hr);
  165. }
  166. STDMETHODIMP CSAFIncidentItem::get_CreationTime( /*[out, retval]*/ DATE *pVal )
  167. {
  168. __HCP_BEGIN_PROPERTY_GET2("CSAFIncidentItem::get_CreationTime",hr,pVal,0);
  169. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  170. *pVal = m_increc.m_dCreatedTime;
  171. __HCP_END_PROPERTY(hr);
  172. }
  173. STDMETHODIMP CSAFIncidentItem::get_ChangedTime( /*[out, retval]*/ DATE *pVal )
  174. {
  175. __HCP_BEGIN_PROPERTY_GET2("CSAFIncidentItem::get_ChangedTime",hr,pVal,0);
  176. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  177. *pVal = m_increc.m_dChangedTime;
  178. __HCP_END_PROPERTY(hr);
  179. }
  180. STDMETHODIMP CSAFIncidentItem::get_ClosedTime( /*[out, retval]*/ DATE *pVal )
  181. {
  182. __HCP_BEGIN_PROPERTY_GET2("CSAFIncidentItem::get_ClosedTime",hr,pVal,0);
  183. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  184. *pVal = m_increc.m_dClosedTime;
  185. __HCP_END_PROPERTY(hr);
  186. }
  187. STDMETHODIMP CSAFIncidentItem::get_Status( /*[out, retval]*/ IncidentStatusEnum *pVal )
  188. {
  189. __HCP_BEGIN_PROPERTY_GET2("CSAFIncidentItem::get_Status",hr,pVal,pchIncidentInvalid);
  190. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( TRUE ));
  191. *pVal = m_increc.m_iStatus;
  192. __HCP_END_PROPERTY(hr);
  193. }
  194. /////////////////////////////////////////////////////////////////////////////
  195. HRESULT CSAFIncidentItem::Save()
  196. {
  197. __HCP_FUNC_ENTRY( "CSAFIncidentItem::Save" );
  198. HRESULT hr;
  199. MPC::SmartLock<_ThreadModel> lock( this );
  200. CIncidentStore* pIStore = NULL;
  201. CSAFChannel * pChan = NULL;
  202. int ilstSize = 0x0;
  203. m_increc.m_dChangedTime = MPC::GetLocalTime();
  204. __MPC_EXIT_IF_METHOD_FAILS(hr, CSAFChannel::OpenIncidentStore( pIStore ));
  205. if(m_increc.m_iStatus == pchIncidentInvalid)
  206. {
  207. __MPC_EXIT_IF_METHOD_FAILS(hr, pIStore->DeleteRec( this ));
  208. }
  209. else
  210. {
  211. __MPC_EXIT_IF_METHOD_FAILS(hr, pIStore->UpdateRec( this ));
  212. }
  213. // Grab the CSAFChannel (parent) of this CSAFIncidentItem
  214. Child_GetParent( &pChan );
  215. // Grab the size of the incident list to fire the event
  216. ilstSize = pChan->GetSizeIncidentList();
  217. // Fire the event EVENT_INCIDENTUPDATED
  218. __MPC_EXIT_IF_METHOD_FAILS(hr, pChan->Fire_NotificationEvent(EVENT_INCIDENTUPDATED,
  219. ilstSize,
  220. pChan,
  221. this,
  222. 0));
  223. m_fDirty = false;
  224. hr = S_OK;
  225. __HCP_FUNC_CLEANUP;
  226. CSAFChannel::CloseIncidentStore( pIStore );
  227. if(pChan) pChan->Release();
  228. __HCP_FUNC_EXIT(hr);
  229. }
  230. /////////////////////////////////////////////////////////////////////////////
  231. STDMETHODIMP CSAFIncidentItem::get_Security( /*[out, retval]*/ IPCHSecurityDescriptor* *pVal )
  232. {
  233. __HCP_FUNC_ENTRY( "CSAFIncidentItem::get_Security" );
  234. HRESULT hr;
  235. MPC::SmartLock<_ThreadModel> lock( this );
  236. __MPC_PARAMCHECK_BEGIN(hr)
  237. __MPC_PARAMCHECK_POINTER_AND_SET(pVal,NULL);
  238. __MPC_PARAMCHECK_END();
  239. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  240. if(m_increc.m_bstrSecurity.Length())
  241. {
  242. CPCHSecurityDescriptorDirect sdd;
  243. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertFromString( m_increc.m_bstrSecurity ));
  244. __MPC_EXIT_IF_METHOD_FAILS(hr, CPCHSecurity::s_GLOBAL->CreateObject_SecurityDescriptor( pVal ));
  245. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertSDToCOM( *pVal ));
  246. }
  247. hr = S_OK;
  248. __HCP_FUNC_CLEANUP;
  249. __HCP_FUNC_EXIT(hr);
  250. }
  251. STDMETHODIMP CSAFIncidentItem::put_Security( /*[in]*/ IPCHSecurityDescriptor* newVal )
  252. {
  253. __HCP_BEGIN_PROPERTY_PUT("CSAFChannel::put_Security",hr);
  254. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( TRUE ));
  255. m_increc.m_bstrSecurity.Empty();
  256. if(newVal)
  257. {
  258. CPCHSecurityDescriptorDirect sdd;
  259. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertSDFromCOM( newVal ));
  260. __MPC_EXIT_IF_METHOD_FAILS(hr, sdd.ConvertToString( &m_increc.m_bstrSecurity ));
  261. }
  262. __MPC_EXIT_IF_METHOD_FAILS(hr, Save());
  263. __HCP_END_PROPERTY(hr);
  264. }
  265. STDMETHODIMP CSAFIncidentItem::get_Owner( /*[out, retval]*/ BSTR *pVal )
  266. {
  267. __HCP_BEGIN_PROPERTY_GET("CSAFIncidentItem::get_Owner",hr,pVal);
  268. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( FALSE ));
  269. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::GetBSTR( m_increc.m_bstrOwner, pVal ));
  270. __HCP_END_PROPERTY(hr);
  271. }
  272. /////////////////////////////////////////////////////////////////////////////
  273. STDMETHODIMP CSAFIncidentItem::CloseIncidentItem()
  274. {
  275. __HCP_FUNC_ENTRY( "CSAFIncidentItem::CloseIncidentItem" );
  276. HRESULT hr;
  277. MPC::SmartLock<_ThreadModel> lock( this );
  278. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( TRUE ));
  279. m_increc.m_dClosedTime = MPC::GetLocalTime();
  280. m_increc.m_iStatus = pchIncidentClosed;
  281. __MPC_EXIT_IF_METHOD_FAILS(hr, Save());
  282. hr = S_OK;
  283. __HCP_FUNC_CLEANUP;
  284. __HCP_FUNC_EXIT(hr);
  285. }
  286. STDMETHODIMP CSAFIncidentItem::DeleteIncidentItem()
  287. {
  288. __HCP_FUNC_ENTRY( "CSAFIncidentItem::DeleteIncidentItem" );
  289. HRESULT hr;
  290. MPC::SmartLock<_ThreadModel> lock( this );
  291. CSAFChannel* pChan = NULL;
  292. __MPC_EXIT_IF_METHOD_FAILS(hr, VerifyPermissions( TRUE ));
  293. Child_GetParent( &pChan );
  294. if(pChan)
  295. {
  296. __MPC_EXIT_IF_METHOD_FAILS(hr, pChan->RemoveIncidentFromList( this ));
  297. }
  298. if(m_increc.m_iStatus != pchIncidentInvalid)
  299. {
  300. m_increc.m_dClosedTime = MPC::GetLocalTime();
  301. m_increc.m_iStatus = pchIncidentInvalid;
  302. __MPC_EXIT_IF_METHOD_FAILS(hr, Save());
  303. }
  304. hr = S_OK;
  305. __HCP_FUNC_CLEANUP;
  306. if(pChan) pChan->Release();
  307. __HCP_FUNC_EXIT(hr);
  308. }