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.

390 lines
8.0 KiB

  1. //***************************************************************************
  2. //
  3. // File:
  4. //
  5. // Module: MS SNMP Provider
  6. //
  7. // Purpose:
  8. //
  9. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. #include <provexpt.h>
  14. #include <snmptempl.h>
  15. #include <snmpmt.h>
  16. #include <typeinfo.h>
  17. #include <process.h>
  18. #include <objbase.h>
  19. #include <stdio.h>
  20. #include <wbemidl.h>
  21. #include "classfac.h"
  22. #include "guids.h"
  23. #include <snmpcont.h>
  24. #include <snmpevt.h>
  25. #include <snmpthrd.h>
  26. #include <snmplog.h>
  27. #include <snmpcl.h>
  28. #include <instpath.h>
  29. #include <snmptype.h>
  30. #include <snmpauto.h>
  31. #include <snmpobj.h>
  32. #include <genlex.h>
  33. #include <sql_1.h>
  34. #include <objpath.h>
  35. #include "propprov.h"
  36. #include "propsnmp.h"
  37. #include "propget.h"
  38. #include "propset.h"
  39. #include "propdel.h"
  40. #include "snmpget.h"
  41. #include "snmpset.h"
  42. #include "snmpqset.h"
  43. void DeleteInstanceAsyncEventObject :: ReceiveComplete ()
  44. {
  45. DebugMacro3(
  46. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  47. __FILE__,__LINE__,
  48. L"SnmpUpdateAsyncEventObject :: ReceiveComplete ()"
  49. ) ;
  50. )
  51. BOOL t_Status = TRUE ;
  52. if ( m_SnmpTooBig )
  53. {
  54. m_errorObject.SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  55. m_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  56. m_errorObject.SetMessage ( L"Agent could not process Set Request because SNMP PDU was too big" ) ;
  57. }
  58. DebugMacro3(
  59. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  60. __FILE__,__LINE__,
  61. L"SnmpUpdateAsyncEventObject :: SetComplete ()"
  62. ) ;
  63. )
  64. if ( SUCCEEDED ( m_errorObject.GetWbemStatus () ) )
  65. {
  66. DebugMacro3(
  67. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  68. __FILE__,__LINE__,
  69. L"Update Succeeded"
  70. ) ;
  71. )
  72. }
  73. /*
  74. * Remove worker object from worker thread container
  75. */
  76. DebugMacro3(
  77. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  78. __FILE__,__LINE__,
  79. L"Reaping Task"
  80. ) ;
  81. )
  82. SetOperation *t_operation = operation ;
  83. DebugMacro3(
  84. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  85. __FILE__,__LINE__,
  86. L"Deleting (this)"
  87. ) ;
  88. )
  89. Complete () ;
  90. DebugMacro3(
  91. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  92. __FILE__,__LINE__,
  93. L"Destroying SNMPCL operation"
  94. ) ;
  95. )
  96. if ( t_operation )
  97. t_operation->DestroyOperation () ;
  98. DebugMacro3(
  99. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  100. __FILE__,__LINE__,
  101. L"Returning from DeleteInstanceAsyncEventObject :: ReceiveComplete ()"
  102. ) ;
  103. )
  104. }
  105. void DeleteInstanceAsyncEventObject :: SnmpTooBig ()
  106. {
  107. DebugMacro3(
  108. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  109. __FILE__,__LINE__,
  110. L"DeleteInstanceAsyncEventObject :: SnmpTooBig ()"
  111. ) ;
  112. )
  113. m_SnmpTooBig = TRUE ;
  114. DebugMacro3(
  115. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  116. __FILE__,__LINE__,
  117. L"Returning from DeleteInstanceAsyncEventObject :: SnmpTooBig ()"
  118. ) ;
  119. )
  120. }
  121. BOOL DeleteInstanceAsyncEventObject :: Delete ( WbemSnmpErrorObject &a_errorObject )
  122. {
  123. DebugMacro3(
  124. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  125. __FILE__,__LINE__,
  126. L"DeleteInstanceAsyncEventObject :: Delete ( WbemSnmpErrorObject &a_errorObject )"
  127. ) ;
  128. )
  129. BOOL status = TRUE ;
  130. HRESULT t_WBEM_result = WBEM_S_NO_ERROR ;
  131. IWbemClassObject *t_ClassObject = NULL ;
  132. IWbemServices *t_Serv = provider->GetServer();
  133. HRESULT result = WBEM_E_FAILED;
  134. if (t_Serv)
  135. {
  136. VARIANT variant ;
  137. VariantInit ( & variant ) ;
  138. variant.bstrVal = SysAllocString ( m_ObjectPath ) ;
  139. result = t_Serv->GetObject (
  140. variant.bstrVal ,
  141. 0 ,
  142. m_Context ,
  143. & t_ClassObject ,
  144. NULL
  145. ) ;
  146. VariantClear ( & variant ) ;
  147. t_Serv->Release () ;
  148. }
  149. if ( SUCCEEDED ( result ) )
  150. {
  151. if ( status = GetNamespaceObject ( a_errorObject ) )
  152. {
  153. status = snmpObject.Set ( a_errorObject , t_ClassObject ) ;
  154. if ( status )
  155. {
  156. status = snmpObject.Check ( a_errorObject ) ;
  157. if ( status )
  158. {
  159. if ( ! snmpObject.RowStatusSpecified () )
  160. {
  161. WbemSnmpProperty *t_Property ;
  162. snmpObject.ResetProperty () ;
  163. while ( t_Property = snmpObject.NextProperty () )
  164. {
  165. if ( typeid ( *t_Property->GetValue () ) == typeid ( SnmpRowStatusType ) )
  166. {
  167. t_Property->SetTag ( FALSE ) ;
  168. SnmpRowStatusType *t_RowStatus = new SnmpRowStatusType ( SnmpRowStatusType :: SnmpRowStatusEnum :: destroy ) ;
  169. t_Property->SetValue ( t_RowStatus ) ;
  170. }
  171. }
  172. status = SendSnmp ( m_errorObject , 0 ) ;
  173. }
  174. else
  175. {
  176. status = FALSE ;
  177. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_CLASS ) ;
  178. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  179. a_errorObject.SetMessage ( L"Deletion of an instance requires the specification of a RowStatus class definition" ) ;
  180. }
  181. }
  182. else
  183. {
  184. DebugMacro3(
  185. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  186. __FILE__,__LINE__,
  187. L"Failed During Merge : Class definition did not conform to mapping"
  188. ) ;
  189. )
  190. }
  191. }
  192. else
  193. {
  194. DebugMacro3(
  195. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  196. __FILE__,__LINE__,
  197. L"Failed During Set : Class definition did not conform to mapping"
  198. ) ;
  199. )
  200. }
  201. }
  202. t_ClassObject->Release () ;
  203. }
  204. DebugMacro3(
  205. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  206. __FILE__,__LINE__,
  207. L"Returning from DeleteInstanceAsyncEventObject :: Delete ( WbemSnmpErrorObject &a_errorObject ) with Result (%lx)" ,
  208. a_errorObject.GetWbemStatus ()
  209. ) ;
  210. )
  211. return status ;
  212. }
  213. BOOL DeleteInstanceAsyncEventObject :: DeleteInstance ( WbemSnmpErrorObject &a_ErrorObject )
  214. {
  215. BOOL t_Status;
  216. int iParseResult = m_ObjectPathParser.Parse ( m_ObjectPath , &m_ParsedObjectPath ) ;
  217. if ( CObjectPathParser::NoError == iParseResult )
  218. {
  219. t_Status = Delete ( a_ErrorObject ) ;
  220. }
  221. else
  222. {
  223. t_Status = FALSE ;
  224. a_ErrorObject.SetStatus ( WBEM_SNMP_E_INVALID_CLASS ) ;
  225. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  226. a_ErrorObject.SetMessage ( L"Unknown Class" ) ;
  227. }
  228. return t_Status ;
  229. }
  230. DeleteInstanceAsyncEventObject :: DeleteInstanceAsyncEventObject (
  231. CImpPropProv *a_Provider ,
  232. BSTR a_ObjectPath ,
  233. ULONG a_OperationFlag ,
  234. IWbemObjectSink *a_NotificationHandler ,
  235. IWbemContext *a_Ctx
  236. ) : SnmpSetResponseEventObject ( a_Provider , NULL , a_Ctx , 0 ) ,
  237. m_NotificationHandler ( a_NotificationHandler ) ,
  238. m_Class ( NULL ) ,
  239. m_State ( 0 ),
  240. m_ObjectPath ( NULL ) ,
  241. #pragma warning (disable:4355)
  242. snmpObject ( this )
  243. #pragma warning (default:4355)
  244. {
  245. m_NotificationHandler->AddRef () ;
  246. m_ObjectPath = UnicodeStringDuplicate ( a_ObjectPath ) ;
  247. }
  248. DeleteInstanceAsyncEventObject :: ~DeleteInstanceAsyncEventObject ()
  249. {
  250. // Get Status object
  251. delete [] m_ObjectPath ;
  252. if (m_NotificationHandler)
  253. {
  254. if ( FAILED ( m_errorObject.GetWbemStatus () ) )
  255. {
  256. IWbemClassObject *t_NotifyStatus = NULL ;
  257. BOOL t_Status = GetSnmpNotifyStatusObject ( &t_NotifyStatus ) ;
  258. if ( t_Status )
  259. {
  260. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0 , m_errorObject.GetWbemStatus () , NULL , t_NotifyStatus ) ;
  261. t_NotifyStatus->Release () ;
  262. }
  263. else
  264. {
  265. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0 , m_errorObject.GetWbemStatus () , NULL , NULL ) ;
  266. }
  267. }
  268. else
  269. {
  270. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0 , m_errorObject.GetWbemStatus () , NULL , NULL ) ;
  271. }
  272. m_NotificationHandler->Release();
  273. }
  274. }
  275. void DeleteInstanceAsyncEventObject :: ProcessComplete ()
  276. {
  277. if ( SUCCEEDED ( m_errorObject.GetWbemStatus () ) )
  278. {
  279. }
  280. else
  281. {
  282. }
  283. /*
  284. * Remove worker object from worker thread container
  285. */
  286. Complete () ;
  287. }
  288. void DeleteInstanceAsyncEventObject :: Process ()
  289. {
  290. switch ( m_State )
  291. {
  292. case 0:
  293. {
  294. BOOL t_Status = DeleteInstance ( m_errorObject ) ;
  295. if ( t_Status )
  296. {
  297. }
  298. else
  299. {
  300. ProcessComplete () ;
  301. }
  302. }
  303. break ;
  304. default:
  305. {
  306. }
  307. break ;
  308. }
  309. }