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.

313 lines
8.8 KiB

  1. //***************************************************************************
  2. //
  3. // NTEVTPUT.CPP
  4. //
  5. // Module: WBEM NT EVENT PROVIDER
  6. //
  7. // Purpose: Contains the PutObject implementation
  8. //
  9. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. BOOL PutInstanceAsyncEventObject :: PutInstance ( WbemProvErrorObject &a_ErrorObject )
  14. {
  15. DebugOut(
  16. CNTEventProvider::g_NTEvtDebugLog->Write (
  17. _T(__FILE__),__LINE__,
  18. L"PutInstanceAsyncEventObject :: PutInstance\r\n"
  19. ) ;
  20. )
  21. if (FAILED(m_ErrorObject.GetWbemStatus()))
  22. {
  23. return FALSE;
  24. }
  25. VARIANT v;
  26. VariantInit (&v);
  27. BOOL t_Status = SUCCEEDED(m_InstObject->Get(CLASS_PROP, 0, &v, NULL, NULL));
  28. if (( t_Status ) && (VT_BSTR == v.vt))
  29. {
  30. if ( _wcsicmp ( v.bstrVal , NTEVTLOG_CLASS) == 0 )
  31. {
  32. if ( t_Status )
  33. {
  34. t_Status = Dispatch_EventLog ( a_ErrorObject ) ;
  35. if ( t_Status )
  36. {
  37. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE ;
  38. }
  39. }
  40. else
  41. {
  42. }
  43. }
  44. /*
  45. else if ( _wcsicmp ( v.bstrVal , some_other_class) == 0 )
  46. {
  47. if ( t_Status )
  48. {
  49. t_Status = Dispatch_some_other_class ( a_ErrorObject ) ;
  50. if ( t_Status )
  51. {
  52. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE ;
  53. }
  54. }
  55. else
  56. {
  57. }
  58. }
  59. */
  60. else
  61. {
  62. t_Status = FALSE ;
  63. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_CLASS ) ;
  64. a_ErrorObject.SetWbemStatus ( WBEM_E_PROVIDER_NOT_CAPABLE ) ;
  65. a_ErrorObject.SetMessage ( L"Dynamic NT Eventlog Provider does not support WRITE for this class" ) ;
  66. DebugOut(
  67. CNTEventProvider::g_NTEvtDebugLog->Write (
  68. _T(__FILE__),__LINE__,
  69. L"PutInstanceAsyncEventObject :: PutInstance:Dynamic NT Eventlog Provider does not support WRITE for this class\r\n"
  70. ) ;
  71. )
  72. }
  73. }
  74. else
  75. {
  76. t_Status = FALSE ;
  77. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_CLASS ) ;
  78. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_OBJECT ) ;
  79. a_ErrorObject.SetMessage ( L"Unable to obtain class name from object." ) ;
  80. DebugOut(
  81. CNTEventProvider::g_NTEvtDebugLog->Write (
  82. _T(__FILE__),__LINE__,
  83. L"PutInstanceAsyncEventObject :: PutInstance:Unable to obtain class name from object.\r\n"
  84. ) ;
  85. )
  86. }
  87. VariantClear(&v);
  88. DebugOut(
  89. CNTEventProvider::g_NTEvtDebugLog->Write (
  90. _T(__FILE__),__LINE__,
  91. L"PutInstanceAsyncEventObject :: PutInstance:returning %lx\r\n",
  92. t_Status
  93. ) ;
  94. )
  95. return t_Status ;
  96. }
  97. BOOL PutInstanceAsyncEventObject :: Dispatch_EventLog ( WbemProvErrorObject &a_ErrorObject )
  98. {
  99. if (WBEM_FLAG_CREATE_ONLY == (m_OperationFlag & WBEM_FLAG_CREATE_ONLY))
  100. {
  101. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_OPERATION ) ;
  102. a_ErrorObject.SetWbemStatus ( WBEM_E_PROVIDER_NOT_CAPABLE ) ;
  103. a_ErrorObject.SetMessage ( L"WBEM_FLAG_CREATE_ONLY is unsupported, modify only!" ) ;
  104. DebugOut(
  105. CNTEventProvider::g_NTEvtDebugLog->Write (
  106. _T(__FILE__),__LINE__,
  107. L"PutInstanceAsyncEventObject :: PutInstance:WBEM_FLAG_CREATE_ONLY is unsupported, modify only!\r\n"
  108. ) ;
  109. )
  110. return FALSE ;
  111. }
  112. DebugOut(
  113. CNTEventProvider::g_NTEvtDebugLog->Write (
  114. _T(__FILE__),__LINE__,
  115. L"PutInstanceAsyncEventObject :: PutInstance\r\n"
  116. ) ;
  117. )
  118. VARIANT v;
  119. VariantInit(&v);
  120. BOOL t_Status = SUCCEEDED(m_InstObject->Get(PROP_NAME, 0, &v, NULL, NULL));
  121. if (( t_Status ) && (VT_BSTR == v.vt))
  122. {
  123. CStringW log = CEventLogFile::GetLogName(v.bstrVal);
  124. if (log.IsEmpty())
  125. {
  126. t_Status = FALSE ;
  127. a_ErrorObject.SetStatus (WBEM_PROV_E_INVALID_CLASS ) ;
  128. a_ErrorObject.SetWbemStatus (WBEM_E_INVALID_OBJECT ) ;
  129. a_ErrorObject.SetMessage (L"Unable to find log file specified.");
  130. DebugOut(
  131. CNTEventProvider::g_NTEvtDebugLog->Write (
  132. _T(__FILE__),__LINE__,
  133. L"PutInstanceAsyncEventObject :: PutInstance:Unable to find log file specified.\r\n"
  134. ) ;
  135. )
  136. }
  137. else
  138. {
  139. VariantClear(&v);
  140. VariantInit(&v);
  141. t_Status = SUCCEEDED(m_InstObject->Get(PROP_LOGNAME, 0, &v, NULL, NULL));
  142. if (( t_Status ) && (VT_BSTR == v.vt) && (0 == _wcsicmp(log, v.bstrVal)))
  143. {
  144. CEventlogFileAttributes evtLog(log);
  145. DWORD dwR = evtLog.UpdateRegistry(m_InstObject);
  146. if (ERROR_SUCCESS != dwR)
  147. {
  148. t_Status = FALSE;
  149. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  150. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  151. wchar_t* buff = NULL;
  152. if (0 == FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  153. NULL, dwR, 0, (LPWSTR) &buff, 80, NULL))
  154. {
  155. DWORD x = GetLastError();
  156. a_ErrorObject.SetMessage (L"Failed to write some (maybe all) data.");
  157. DebugOut(
  158. CNTEventProvider::g_NTEvtDebugLog->Write (
  159. _T(__FILE__),__LINE__,
  160. L"PutInstanceAsyncEventObject :: PutInstance:Failed to write some (maybe all) data.\r\n"
  161. ) ;
  162. )
  163. }
  164. else
  165. {
  166. a_ErrorObject.SetMessage (buff) ;
  167. DebugOut(
  168. CNTEventProvider::g_NTEvtDebugLog->Write (
  169. _T(__FILE__),__LINE__,
  170. L"PutInstanceAsyncEventObject :: PutInstance:%s.\r\n",
  171. buff
  172. ) ;
  173. )
  174. LocalFree(buff);
  175. }
  176. }
  177. }
  178. else
  179. {
  180. t_Status = FALSE;
  181. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  182. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  183. a_ErrorObject.SetMessage (L"Logfilename doesn't match name property (key)") ;
  184. DebugOut(
  185. CNTEventProvider::g_NTEvtDebugLog->Write (
  186. _T(__FILE__),__LINE__,
  187. L"PutInstanceAsyncEventObject :: PutInstance:Logfilename doesn't match name property (key)\r\n"
  188. ) ;
  189. )
  190. }
  191. }
  192. }
  193. else
  194. {
  195. t_Status = FALSE ;
  196. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_CLASS ) ;
  197. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_OBJECT ) ;
  198. a_ErrorObject.SetMessage ( L"Unable to obtain key property from object." ) ;
  199. DebugOut(
  200. CNTEventProvider::g_NTEvtDebugLog->Write (
  201. _T(__FILE__),__LINE__,
  202. L"PutInstanceAsyncEventObject :: PutInstance:Unable to obtain key property from object.\r\n"
  203. ) ;
  204. )
  205. }
  206. VariantClear(&v);
  207. DebugOut(
  208. CNTEventProvider::g_NTEvtDebugLog->Write (
  209. _T(__FILE__),__LINE__,
  210. L"PutInstanceAsyncEventObject :: PutInstance:returning %lx\r\n",
  211. t_Status
  212. ) ;
  213. )
  214. return t_Status ;
  215. }
  216. PutInstanceAsyncEventObject :: PutInstanceAsyncEventObject (
  217. CImpNTEvtProv *a_Provider ,
  218. IWbemClassObject* a_Inst ,
  219. ULONG a_OperationFlag ,
  220. IWbemObjectSink *a_NotificationHandler ,
  221. IWbemContext *a_Ctx
  222. ) : WbemTaskObject ( a_Provider , a_NotificationHandler , a_OperationFlag , a_Ctx ) ,
  223. m_InstObject ( NULL )
  224. {
  225. m_InstObject = a_Inst ;
  226. if (m_InstObject != NULL)
  227. {
  228. m_InstObject->AddRef();
  229. }
  230. }
  231. PutInstanceAsyncEventObject :: ~PutInstanceAsyncEventObject ()
  232. {
  233. // Get Status object
  234. IWbemClassObject *t_NotifyStatus = NULL ;
  235. BOOL t_Status = TRUE;
  236. if (WBEM_NO_ERROR != m_ErrorObject.GetWbemStatus ())
  237. {
  238. t_Status = GetExtendedNotifyStatusObject ( &t_NotifyStatus ) ;
  239. }
  240. if ( t_Status )
  241. {
  242. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0 , m_ErrorObject.GetWbemStatus () , 0 , t_NotifyStatus ) ;
  243. if (t_NotifyStatus)
  244. {
  245. t_NotifyStatus->Release () ;
  246. }
  247. }
  248. else
  249. {
  250. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0 , m_ErrorObject.GetWbemStatus () , 0 , NULL ) ;
  251. }
  252. if (m_InstObject != NULL)
  253. {
  254. m_InstObject->Release();
  255. }
  256. }
  257. void PutInstanceAsyncEventObject :: Process ()
  258. {
  259. PutInstance ( m_ErrorObject ) ;
  260. }