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.

1151 lines
27 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 "snmpget.h"
  39. SnmpGetClassObject :: SnmpGetClassObject ( SnmpResponseEventObject *parentOperation ) : SnmpClassObject ( parentOperation )
  40. {
  41. }
  42. SnmpGetClassObject :: ~SnmpGetClassObject ()
  43. {
  44. }
  45. BOOL SnmpGetClassObject :: Check ( WbemSnmpErrorObject &a_errorObject )
  46. {
  47. // Check Class Object, used in a Get Request, for validity
  48. BOOL status = TRUE ;
  49. snmpVersion = m_parentOperation->SetAgentVersion ( a_errorObject ) ;
  50. if ( snmpVersion == 0 )
  51. {
  52. status = FALSE ;
  53. }
  54. // Check all Properties for validity
  55. WbemSnmpProperty *property ;
  56. ResetProperty () ;
  57. while ( status && ( property = NextProperty () ) )
  58. {
  59. status = CheckProperty ( a_errorObject , property ) ;
  60. }
  61. // Check properties defined as keys have valid key order
  62. if ( status )
  63. {
  64. if ( ! m_accessible )
  65. {
  66. status = FALSE ;
  67. a_errorObject.SetStatus ( WBEM_SNMP_E_NOREADABLEPROPERTIES ) ;
  68. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  69. a_errorObject.SetMessage ( L"Class must contain at least one property which is accessible" ) ;
  70. }
  71. }
  72. return status ;
  73. }
  74. BOOL SnmpGetClassObject :: CheckProperty ( WbemSnmpErrorObject &a_errorObject , WbemSnmpProperty *property )
  75. {
  76. // Check property validity
  77. BOOL status = TRUE ;
  78. if ( ( snmpVersion == 1 ) && property->IsSNMPV1Type () && property->IsReadable () )
  79. {
  80. m_accessible = TRUE ;
  81. }
  82. else if ( ( snmpVersion == 2 ) && property->IsSNMPV2CType () && property->IsReadable () )
  83. {
  84. m_accessible = TRUE ;
  85. }
  86. return status ;
  87. }
  88. SnmpGetResponseEventObject :: SnmpGetResponseEventObject (
  89. CImpPropProv *providerArg ,
  90. IWbemClassObject *classObjectArg ,
  91. IWbemContext *a_Context
  92. ) : SnmpResponseEventObject ( providerArg , a_Context ) ,
  93. classObject ( classObjectArg ) ,
  94. instanceObject ( NULL ) ,
  95. session ( NULL ) ,
  96. operation ( NULL ) ,
  97. processComplete ( FALSE ) ,
  98. #pragma warning( disable : 4355 )
  99. snmpObject ( this )
  100. #pragma warning( default : 4355 )
  101. {
  102. if ( classObject )
  103. classObject->AddRef () ;
  104. }
  105. SnmpGetResponseEventObject :: ~SnmpGetResponseEventObject ()
  106. {
  107. if ( instanceObject )
  108. instanceObject->Release () ;
  109. if ( classObject )
  110. classObject->Release () ;
  111. }
  112. BOOL SnmpGetResponseEventObject :: SendSnmp ( WbemSnmpErrorObject &a_errorObject )
  113. {
  114. DebugMacro3(
  115. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  116. __FILE__,__LINE__,
  117. L"SnmpGetEventObject :: SendSnmp ( WbemSnmpErrorObject &a_errorObject )"
  118. ) ;
  119. )
  120. BOOL status = TRUE ;
  121. IWbemQualifierSet *classQualifierObject ;
  122. HRESULT result = m_namespaceObject->GetQualifierSet ( &classQualifierObject ) ;
  123. if ( SUCCEEDED ( result ) )
  124. {
  125. wchar_t *agentAddress = NULL ;
  126. wchar_t *agentTransport = NULL ;
  127. wchar_t *agentReadCommunityName = NULL ;
  128. ULONG agentRetryCount ;
  129. ULONG agentRetryTimeout ;
  130. ULONG agentMaxVarBindsPerPdu ;
  131. ULONG agentFlowControlWindowSize ;
  132. status = SetAgentVersion ( m_errorObject ) ;
  133. if ( status ) status = GetAgentAddress ( m_errorObject , classQualifierObject , agentAddress ) ;
  134. if ( status ) status = GetAgentTransport ( m_errorObject , classQualifierObject , agentTransport ) ;
  135. if ( status ) status = GetAgentReadCommunityName ( m_errorObject , classQualifierObject , agentReadCommunityName ) ;
  136. if ( status ) status = GetAgentRetryCount ( m_errorObject , classQualifierObject , agentRetryCount ) ;
  137. if ( status ) status = GetAgentRetryTimeout ( m_errorObject , classQualifierObject , agentRetryTimeout ) ;
  138. if ( status ) status = GetAgentMaxVarBindsPerPdu ( m_errorObject , classQualifierObject , agentMaxVarBindsPerPdu ) ;
  139. if ( status ) status = GetAgentFlowControlWindowSize ( m_errorObject , classQualifierObject , agentFlowControlWindowSize ) ;
  140. if ( status )
  141. {
  142. char *dbcsAgentAddress = UnicodeToDbcsString ( agentAddress ) ;
  143. if ( dbcsAgentAddress )
  144. {
  145. char *dbcsAgentReadCommunityName = UnicodeToDbcsString ( agentReadCommunityName ) ;
  146. if ( dbcsAgentReadCommunityName )
  147. {
  148. if ( _wcsicmp ( agentTransport , WBEM_AGENTIPTRANSPORT ) == 0 )
  149. {
  150. char *t_Address ;
  151. if ( provider->GetIpAddressString () && provider->GetIpAddressValue () && _stricmp ( provider->GetIpAddressString () , dbcsAgentAddress ) == 0 )
  152. {
  153. t_Address = provider->GetIpAddressValue () ;
  154. }
  155. else
  156. {
  157. if ( SnmpTransportIpAddress :: ValidateAddress ( dbcsAgentAddress , SNMP_ADDRESS_RESOLVE_VALUE ) )
  158. {
  159. t_Address = dbcsAgentAddress ;
  160. }
  161. else
  162. {
  163. if ( SnmpTransportIpAddress :: ValidateAddress ( dbcsAgentAddress , SNMP_ADDRESS_RESOLVE_NAME ) )
  164. {
  165. t_Address = dbcsAgentAddress ;
  166. }
  167. else
  168. {
  169. status = FALSE ;
  170. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  171. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  172. a_errorObject.SetMessage ( L"Illegal IP address value or unresolvable name for AgentAddress" ) ;
  173. }
  174. }
  175. }
  176. if ( status )
  177. {
  178. if ( m_agentVersion == 1 )
  179. {
  180. session = new SnmpV1OverIp (
  181. t_Address ,
  182. SNMP_ADDRESS_RESOLVE_NAME | SNMP_ADDRESS_RESOLVE_VALUE ,
  183. dbcsAgentReadCommunityName ,
  184. agentRetryCount ,
  185. agentRetryTimeout ,
  186. agentMaxVarBindsPerPdu ,
  187. agentFlowControlWindowSize
  188. );
  189. if ( ! (*session)() )
  190. {
  191. DebugMacro3(
  192. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  193. __FILE__,__LINE__,
  194. L"SNMPCL Session could not be created"
  195. ) ;
  196. )
  197. delete session ;
  198. session = NULL ;
  199. status = FALSE ;
  200. a_errorObject.SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  201. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  202. a_errorObject.SetMessage ( L"Failed to get transport resources" ) ;
  203. }
  204. }
  205. else if ( m_agentVersion == 2 )
  206. {
  207. session = new SnmpV2COverIp (
  208. t_Address ,
  209. SNMP_ADDRESS_RESOLVE_NAME | SNMP_ADDRESS_RESOLVE_VALUE ,
  210. dbcsAgentReadCommunityName ,
  211. agentRetryCount ,
  212. agentRetryTimeout ,
  213. agentMaxVarBindsPerPdu ,
  214. agentFlowControlWindowSize
  215. );
  216. if ( ! (*session)() )
  217. {
  218. DebugMacro3(
  219. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  220. __FILE__,__LINE__,
  221. L"SNMPCL Session could not be created"
  222. ) ;
  223. )
  224. delete session ;
  225. session = NULL ;
  226. status = FALSE ;
  227. a_errorObject.SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  228. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  229. a_errorObject.SetMessage ( L"Failed to get transport resources" ) ;
  230. }
  231. }
  232. else
  233. {
  234. status = FALSE ;
  235. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  236. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  237. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentSnmpVersion" ) ;
  238. }
  239. }
  240. }
  241. else if ( _wcsicmp ( agentTransport , WBEM_AGENTIPXTRANSPORT ) == 0 )
  242. {
  243. if ( m_agentVersion == 1 )
  244. {
  245. session = new SnmpV1OverIpx (
  246. dbcsAgentAddress ,
  247. dbcsAgentReadCommunityName ,
  248. agentRetryCount ,
  249. agentRetryTimeout ,
  250. agentMaxVarBindsPerPdu ,
  251. agentFlowControlWindowSize
  252. );
  253. if ( ! (*session)() )
  254. {
  255. DebugMacro3(
  256. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  257. __FILE__,__LINE__,
  258. L"SNMPCL Session could not be created"
  259. ) ;
  260. )
  261. delete session ;
  262. session = NULL ;
  263. status = FALSE ;
  264. a_errorObject.SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  265. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  266. a_errorObject.SetMessage ( L"Failed to get transport resources" ) ;
  267. }
  268. }
  269. else if ( m_agentVersion == 2 )
  270. {
  271. session = new SnmpV2COverIpx (
  272. dbcsAgentAddress ,
  273. dbcsAgentReadCommunityName ,
  274. agentRetryCount ,
  275. agentRetryTimeout ,
  276. agentMaxVarBindsPerPdu ,
  277. agentFlowControlWindowSize
  278. );
  279. if ( ! (*session)() )
  280. {
  281. DebugMacro3(
  282. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  283. __FILE__,__LINE__,
  284. L"SNMPCL Session could not be created"
  285. ) ;
  286. )
  287. delete session ;
  288. session = NULL ;
  289. status = FALSE ;
  290. a_errorObject.SetStatus ( WBEM_SNMP_E_TRANSPORT_ERROR ) ;
  291. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  292. a_errorObject.SetMessage ( L"Failed to get transport resources" ) ;
  293. }
  294. }
  295. else
  296. {
  297. status = FALSE ;
  298. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  299. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  300. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentSnmpVersion" ) ;
  301. }
  302. }
  303. else
  304. {
  305. status = FALSE ;
  306. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  307. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  308. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentTransport" ) ;
  309. }
  310. delete [] dbcsAgentReadCommunityName ;
  311. }
  312. else
  313. {
  314. status = FALSE ;
  315. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  316. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  317. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentReadCommunityName" ) ;
  318. }
  319. delete [] dbcsAgentAddress ;
  320. if ( status )
  321. {
  322. operation = new GetOperation(*session,this);
  323. operation->Send () ;
  324. }
  325. }
  326. else
  327. {
  328. status = FALSE ;
  329. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  330. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  331. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentAddress" ) ;
  332. }
  333. }
  334. else
  335. {
  336. DebugMacro1(
  337. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  338. __FILE__,__LINE__,
  339. L" TransportInformation settings invalid"
  340. ) ;
  341. )
  342. }
  343. delete [] agentTransport ;
  344. delete [] agentAddress ;
  345. delete [] agentReadCommunityName ;
  346. classQualifierObject->Release () ;
  347. }
  348. else
  349. {
  350. status = FALSE ;
  351. a_errorObject.SetStatus ( WBEM_SNMP_ERROR_CRITICAL_ERROR ) ;
  352. a_errorObject.SetWbemStatus ( WBEM_ERROR_CRITICAL_ERROR ) ;
  353. a_errorObject.SetMessage ( L"Failed to get class qualifier set" ) ;
  354. }
  355. return status ;
  356. }
  357. SnmpGetEventObject :: SnmpGetEventObject (
  358. CImpPropProv *providerArg ,
  359. wchar_t *ObjectPathArg ,
  360. IWbemContext *a_Context
  361. ) : SnmpGetResponseEventObject ( providerArg , NULL , a_Context ) , objectPath ( NULL )
  362. {
  363. ULONG length = wcslen ( ObjectPathArg ) ;
  364. objectPath = new wchar_t [ length + 1 ] ;
  365. wcscpy ( objectPath , ObjectPathArg ) ;
  366. }
  367. SnmpGetEventObject :: ~SnmpGetEventObject ()
  368. {
  369. DebugMacro3(
  370. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  371. __FILE__,__LINE__,
  372. L"SnmpGetEventObject :: ~SnmpGetEventObject()"
  373. ) ;
  374. )
  375. delete [] objectPath ;
  376. }
  377. BOOL SnmpGetEventObject :: ParseObjectPath ( WbemSnmpErrorObject &a_errorObject )
  378. {
  379. DebugMacro3(
  380. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  381. __FILE__,__LINE__,
  382. L"SnmpGetEventObject :: ParseObjectPath ( WbemSnmpErrorObject &a_errorObject )"
  383. ) ;
  384. )
  385. // Check Validity of instance path
  386. ParsedObjectPath *t_ParsedObjectPath = NULL ;
  387. CObjectPathParser t_ObjectPathParser ;
  388. BOOL status = t_ObjectPathParser.Parse ( objectPath , &t_ParsedObjectPath ) ;
  389. if ( status == 0 )
  390. {
  391. // Check validity of path
  392. status = DispatchObjectPath ( a_errorObject , t_ParsedObjectPath ) ;
  393. }
  394. else
  395. {
  396. // Parse Failure
  397. status = FALSE ;
  398. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_PATH ) ;
  399. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  400. a_errorObject.SetMessage ( L"Failed to parse object path" ) ;
  401. }
  402. delete t_ParsedObjectPath ;
  403. return status ;
  404. }
  405. BOOL SnmpGetEventObject :: DispatchObjectPath ( WbemSnmpErrorObject &a_errorObject , ParsedObjectPath *t_ParsedObjectPath )
  406. {
  407. // Check validity of server/namespace path and validity of request
  408. BOOL status = TRUE ;
  409. status = DispatchObjectReference ( a_errorObject , t_ParsedObjectPath ) ;
  410. return status ;
  411. }
  412. BOOL SnmpGetEventObject :: DispatchObjectReference ( WbemSnmpErrorObject &a_errorObject , ParsedObjectPath *t_ParsedObjectPath )
  413. {
  414. DebugMacro3(
  415. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  416. __FILE__,__LINE__,
  417. L"SnmpGetEventObject :: DispatchObjectReference ( WbemSnmpErrorObject &a_errorObject , ParsedObjectPath *t_ParsedObjectPath )"
  418. ) ;
  419. )
  420. // Check validity of request
  421. BOOL status = TRUE ;
  422. // Get type of request
  423. if ( t_ParsedObjectPath->m_bSingletonObj )
  424. {
  425. // Class requested
  426. status = DispatchKeyLessClass ( a_errorObject , t_ParsedObjectPath->m_pClass ) ;
  427. }
  428. else if ( t_ParsedObjectPath->m_dwNumKeys == 0 )
  429. {
  430. // Class requested
  431. status = FALSE ;
  432. a_errorObject.SetStatus ( WBEM_SNMP_E_PROVIDER_NOT_CAPABLE ) ;
  433. a_errorObject.SetWbemStatus ( WBEM_E_PROVIDER_NOT_CAPABLE ) ;
  434. a_errorObject.SetMessage ( L"Unexpected Path parameter" ) ;
  435. }
  436. else
  437. {
  438. // General instance requested
  439. status = DispatchInstanceSpec ( a_errorObject , t_ParsedObjectPath ) ;
  440. }
  441. return status ;
  442. }
  443. BOOL SnmpGetEventObject :: GetInstanceClass ( WbemSnmpErrorObject &a_errorObject , BSTR Class )
  444. {
  445. DebugMacro3(
  446. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  447. __FILE__,__LINE__,
  448. L"SnmpGetEventObject :: GetInstanceClass ( WbemSnmpErrorObject &a_errorObject , BSTR Class (%s) )" ,
  449. Class
  450. ) ;
  451. )
  452. // Get OLE MS class definition
  453. BOOL status = TRUE ;
  454. IWbemServices *t_Serv = provider->GetServer();
  455. HRESULT result = WBEM_E_FAILED;
  456. if (t_Serv)
  457. {
  458. result = t_Serv->GetObject (
  459. Class ,
  460. 0 ,
  461. m_Context ,
  462. & classObject ,
  463. NULL
  464. ) ;
  465. t_Serv->Release () ;
  466. }
  467. // Clone object
  468. if ( SUCCEEDED ( result ) )
  469. {
  470. result = classObject->SpawnInstance ( 0 , & instanceObject ) ;
  471. if ( SUCCEEDED ( result ) )
  472. {
  473. if ( status = GetNamespaceObject ( a_errorObject ) )
  474. {
  475. }
  476. }
  477. }
  478. else
  479. {
  480. // Class definition unknown
  481. status = FALSE ;
  482. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_CLASS ) ;
  483. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  484. a_errorObject.SetMessage ( L"Unexpected Path parameter" ) ;
  485. }
  486. return status ;
  487. }
  488. BOOL SnmpGetEventObject :: DispatchKeyLessClass ( WbemSnmpErrorObject &a_errorObject , wchar_t *a_Class )
  489. {
  490. DebugMacro3(
  491. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  492. __FILE__,__LINE__,
  493. L"SnmpGetEventObject :: DispatchKeyLessClass ( WbemSnmpErrorObject &a_errorObject , wchar_t *a_Class (%s) )",
  494. a_Class
  495. ) ;
  496. )
  497. BOOL status = TRUE ;
  498. status = GetInstanceClass ( a_errorObject , a_Class ) ;
  499. if ( status )
  500. {
  501. status = snmpObject.Set ( a_errorObject , GetClassObject () , FALSE ) ;
  502. if ( status )
  503. {
  504. status = snmpObject.Check ( a_errorObject ) ;
  505. if ( status )
  506. {
  507. status = SendSnmp ( a_errorObject ) ;
  508. }
  509. else
  510. {
  511. // Class definition syntactically incorrect
  512. }
  513. }
  514. else
  515. {
  516. // Class definition syntactically incorrect
  517. }
  518. }
  519. else
  520. {
  521. // Class definition unknown
  522. }
  523. return status ;
  524. }
  525. BOOL SnmpGetEventObject :: SetProperty ( WbemSnmpErrorObject &a_errorObject , WbemSnmpProperty *property , KeyRef *a_KeyReference )
  526. {
  527. DebugMacro3(
  528. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  529. __FILE__,__LINE__,
  530. L"SnmpGetEventObject :: SetProperty ( WbemSnmpErrorObject &a_errorObject , WbemSnmpProperty *property (%s) , KeyRef *a_KeyReference )",
  531. property->GetName ()
  532. ) ;
  533. )
  534. // Set keyed property value used for instance retrieval using path specification
  535. BOOL status = TRUE ;
  536. if ( a_KeyReference->m_vValue.vt == VT_I4 )
  537. {
  538. // property value is an integer type
  539. if ( property->SetValue ( a_KeyReference->m_vValue , property->GetCimType () ) )
  540. {
  541. }
  542. else
  543. {
  544. // Property value doesn't correspond with property syntax
  545. status = FALSE ;
  546. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_PATHKEYPARAMETER ) ;
  547. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  548. wchar_t *temp = UnicodeStringDuplicate ( L"Path parameter is inconsistent with keyed property: " ) ;
  549. wchar_t *stringBuffer = UnicodeStringAppend ( temp , property->GetName () ) ;
  550. delete [] temp ;
  551. a_errorObject.SetMessage ( stringBuffer ) ;
  552. delete [] stringBuffer ;
  553. }
  554. }
  555. else if ( a_KeyReference->m_vValue.vt == VT_BSTR )
  556. {
  557. // property value is an string type
  558. if ( property->SetValue ( a_KeyReference->m_vValue , property->GetCimType () ) )
  559. {
  560. }
  561. else
  562. {
  563. // Property value doesn't correspond with property syntax
  564. status = FALSE ;
  565. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_PATHKEYPARAMETER ) ;
  566. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  567. wchar_t *temp = UnicodeStringDuplicate ( L"Path parameter is inconsistent with keyed property: " ) ;
  568. wchar_t *stringBuffer = UnicodeStringAppend ( temp , property->GetName () ) ;
  569. delete [] temp ;
  570. a_errorObject.SetMessage ( stringBuffer ) ;
  571. delete [] stringBuffer ;
  572. }
  573. }
  574. else
  575. {
  576. status = FALSE ;
  577. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_PATHKEYPARAMETER ) ;
  578. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  579. a_errorObject.SetMessage ( L"Path parameter is inconsistent with keyed property" ) ;
  580. }
  581. return status ;
  582. }
  583. BOOL SnmpGetEventObject :: SetInstanceSpecKeys ( WbemSnmpErrorObject &a_errorObject , ParsedObjectPath *a_ParsedObjectPath )
  584. {
  585. DebugMacro3(
  586. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  587. __FILE__,__LINE__,
  588. L"SnmpGetEventObject :: SetInstanceSpecKeys ( WbemSnmpErrorObject &a_errorObject , ParsedObjectPath *a_ParsedObjectPath )"
  589. ) ;
  590. )
  591. // Get Instance based on general request
  592. BOOL status = TRUE ;
  593. // Clear Tag for all keyed properties
  594. WbemSnmpProperty *property ;
  595. snmpObject.ResetKeyProperty () ;
  596. while ( property = snmpObject.NextKeyProperty () )
  597. {
  598. property->SetTag ( FALSE ) ;
  599. }
  600. // Check request doesn't contain duplicate property names
  601. if ( snmpObject.GetKeyPropertyCount () == 1 )
  602. {
  603. // Class contains exactly one keyed property
  604. WbemSnmpProperty *property ;
  605. snmpObject.ResetKeyProperty () ;
  606. if ( property = snmpObject.NextKeyProperty () )
  607. {
  608. // Set Key property value
  609. KeyRef *t_PropertyReference = a_ParsedObjectPath->m_paKeys [ 0 ] ;
  610. status = SetProperty ( a_errorObject , property , t_PropertyReference ) ;
  611. }
  612. }
  613. else if ( snmpObject.GetKeyPropertyCount () != 0 )
  614. {
  615. // Iterate through list of key assignments in request
  616. ULONG t_Index = 0 ;
  617. while ( t_Index < a_ParsedObjectPath->m_dwNumKeys )
  618. {
  619. KeyRef *t_PropertyReference = a_ParsedObjectPath->m_paKeys [ t_Index ] ;
  620. WbemSnmpProperty *property ;
  621. if ( property = snmpObject.FindKeyProperty ( t_PropertyReference->m_pName ) )
  622. {
  623. if ( property->GetTag () )
  624. {
  625. // key value already specified in request
  626. status = FALSE ;
  627. a_errorObject.SetStatus ( WBEM_SNMP_E_DUPLICATEPATHKEYPARAMETER ) ;
  628. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  629. a_errorObject.SetMessage ( L"Path definition specified duplicate key parameter" ) ;
  630. break ;
  631. }
  632. else
  633. {
  634. // Set property based on request value
  635. property->SetTag () ;
  636. status = SetProperty ( a_errorObject , property , t_PropertyReference ) ;
  637. if ( status )
  638. {
  639. }
  640. else
  641. {
  642. // Illegal key value specified
  643. break ;
  644. }
  645. }
  646. }
  647. else
  648. {
  649. // Property request is not a valid keyed property
  650. status = FALSE ;
  651. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_PATHKEYPARAMETER ) ;
  652. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  653. a_errorObject.SetMessage ( L"Path definition specified invalid key parameter name" ) ;
  654. break ;
  655. }
  656. t_Index ++ ;
  657. }
  658. // Check all keyed properties values have been specified
  659. if ( status )
  660. {
  661. WbemSnmpProperty *property ;
  662. snmpObject.ResetKeyProperty () ;
  663. while ( status && ( property = snmpObject.NextKeyProperty () ) )
  664. {
  665. if ( property->GetTag () )
  666. {
  667. }
  668. else
  669. {
  670. // One of the keyed properties has not been specified
  671. status = FALSE ;
  672. a_errorObject.SetStatus ( WBEM_SNMP_E_MISSINGPATHKEYPARAMETER ) ;
  673. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  674. a_errorObject.SetMessage ( L"Path definition did not specify all key parameter values" ) ;
  675. break ;
  676. }
  677. }
  678. }
  679. }
  680. else
  681. {
  682. // Class contains zero keyed properties, has already have been checked
  683. status = FALSE ;
  684. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_OBJECT ) ;
  685. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  686. a_errorObject.SetMessage ( L"Path definition specified key parameters for keyless class" ) ;
  687. }
  688. return status ;
  689. }
  690. BOOL SnmpGetEventObject :: DispatchInstanceSpec ( WbemSnmpErrorObject &a_errorObject , ParsedObjectPath *a_ParsedObjectPath )
  691. {
  692. DebugMacro3(
  693. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  694. __FILE__,__LINE__,
  695. L"SnmpGetEventObject :: DispatchInstanceSpec ( WbemSnmpErrorObject &a_errorObject , ParsedObjectPath *a_ParsedObjectPath )"
  696. ) ;
  697. )
  698. BOOL status = TRUE ;
  699. status = GetInstanceClass ( a_errorObject , a_ParsedObjectPath->m_pClass ) ;
  700. if ( status )
  701. {
  702. status = snmpObject.Set ( a_errorObject , GetClassObject () , FALSE ) ;
  703. if ( status )
  704. {
  705. status = snmpObject.Check ( a_errorObject ) ;
  706. if ( status )
  707. {
  708. status = SetInstanceSpecKeys ( a_errorObject , a_ParsedObjectPath ) ;
  709. if ( status )
  710. {
  711. status = SendSnmp ( a_errorObject ) ;
  712. }
  713. else
  714. {
  715. // Requested Property value definitions illegal
  716. DebugMacro3(
  717. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  718. __FILE__,__LINE__,
  719. L"Key Specification was illegal"
  720. ) ;
  721. )
  722. }
  723. }
  724. else
  725. {
  726. // Class definition syntactically incorrect
  727. DebugMacro3(
  728. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  729. __FILE__,__LINE__,
  730. L"Failed During Check :Class definition did not conform to mapping"
  731. ) ;
  732. )
  733. }
  734. }
  735. else
  736. {
  737. // Class definition syntactically incorrect
  738. DebugMacro3(
  739. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  740. __FILE__,__LINE__,
  741. L"Failed During Set : Class definition did not conform to mapping"
  742. ) ;
  743. )
  744. }
  745. }
  746. else
  747. {
  748. DebugMacro3(
  749. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  750. __FILE__,__LINE__,
  751. L"Class definition unknown"
  752. ) ;
  753. status = FALSE ;
  754. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_CLASS ) ;
  755. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  756. a_errorObject.SetMessage ( L"Unknown Class" ) ;
  757. )
  758. // Class definition unknown
  759. }
  760. return status ;
  761. }
  762. SnmpGetAsyncEventObject :: SnmpGetAsyncEventObject (
  763. CImpPropProv *providerArg ,
  764. wchar_t *ObjectPathArg ,
  765. IWbemObjectSink *notify ,
  766. IWbemContext *a_Context
  767. ) : SnmpGetEventObject ( providerArg , ObjectPathArg , a_Context ) , notificationHandler ( notify ) , state ( 0 )
  768. {
  769. DebugMacro3(
  770. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  771. __FILE__,__LINE__,
  772. L"SnmpGetAsyncEventObject :: SnmpGetAsyncEventObject ()"
  773. ) ;
  774. )
  775. notify->AddRef () ;
  776. }
  777. SnmpGetAsyncEventObject :: ~SnmpGetAsyncEventObject ()
  778. {
  779. DebugMacro3(
  780. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  781. __FILE__,__LINE__,
  782. L"SnmpGetAsyncEventObject :: ~SnmpGetAsyncEventObject ()"
  783. ) ;
  784. )
  785. if ( FAILED ( m_errorObject.GetWbemStatus () ) )
  786. {
  787. // Get Status object
  788. IWbemClassObject *notifyStatus = NULL ;
  789. BOOL status = GetSnmpNotifyStatusObject ( &notifyStatus ) ;
  790. if ( status )
  791. {
  792. DebugMacro3(
  793. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  794. __FILE__,__LINE__,
  795. L"Sending Status"
  796. ) ;
  797. )
  798. HRESULT result = notificationHandler->SetStatus ( 0 , m_errorObject.GetWbemStatus () , NULL , notifyStatus ) ;
  799. notifyStatus->Release () ;
  800. }
  801. }
  802. else
  803. {
  804. HRESULT result = notificationHandler->SetStatus ( 0 , m_errorObject.GetWbemStatus () , NULL , NULL ) ;
  805. }
  806. notificationHandler->Release () ;
  807. DebugMacro3(
  808. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  809. __FILE__,__LINE__,
  810. L"Returning from SnmpGetAsyncEventObject :: ~SnmpGetAsyncEventObject ()"
  811. ) ;
  812. )
  813. }
  814. void SnmpGetAsyncEventObject :: ReceiveComplete ()
  815. {
  816. DebugMacro3(
  817. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  818. __FILE__,__LINE__,
  819. L"SnmpGetAsyncEventObject :: ReceiveComplete ()"
  820. ) ;
  821. )
  822. if ( SUCCEEDED ( m_errorObject.GetWbemStatus () ) )
  823. {
  824. if ( notificationHandler )
  825. {
  826. DebugMacro3(
  827. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  828. __FILE__,__LINE__,
  829. L"Sending Object"
  830. ) ;
  831. )
  832. notificationHandler->Indicate ( 1 , & instanceObject ) ;
  833. if ( ! HasNonNullKeys ( instanceObject ) )
  834. {
  835. m_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_OBJECT ) ;
  836. m_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  837. m_errorObject.SetMessage ( L"The SNMP Agent queried returned an instance with NULL key(s)" ) ;
  838. }
  839. }
  840. else
  841. {
  842. }
  843. }
  844. else
  845. {
  846. }
  847. /*
  848. * Remove worker object from worker thread container
  849. */
  850. DebugMacro3(
  851. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  852. __FILE__,__LINE__,
  853. L"Reaping Task"
  854. ) ;
  855. )
  856. GetOperation *t_operation = operation ;
  857. DebugMacro3(
  858. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  859. __FILE__,__LINE__,
  860. L"Deleting (this)"
  861. ) ;
  862. )
  863. Complete () ;
  864. DebugMacro3(
  865. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  866. __FILE__,__LINE__,
  867. L"Destroying SNMPCL operation"
  868. ) ;
  869. )
  870. if ( t_operation )
  871. t_operation->DestroyOperation () ;
  872. DebugMacro3(
  873. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  874. __FILE__,__LINE__,
  875. L"Returning from SnmpGetAsyncEventObject :: ReceiveComplete ()"
  876. ) ;
  877. )
  878. }
  879. void SnmpGetAsyncEventObject :: Process ()
  880. {
  881. DebugMacro3(
  882. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  883. __FILE__,__LINE__,
  884. L"SnmpGetAsyncEventObject :: Process ()"
  885. ) ;
  886. )
  887. switch ( state )
  888. {
  889. case 0:
  890. {
  891. BOOL status = ParseObjectPath ( m_errorObject ) ;
  892. if ( status )
  893. {
  894. if ( processComplete )
  895. {
  896. ReceiveComplete () ;
  897. }
  898. }
  899. else
  900. {
  901. ReceiveComplete () ;
  902. }
  903. }
  904. break ;
  905. default:
  906. {
  907. }
  908. break ;
  909. }
  910. DebugMacro3(
  911. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  912. __FILE__,__LINE__,
  913. L"Returning from SnmpGetAsyncEventObject :: Process ()"
  914. ) ;
  915. )
  916. }