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.

1476 lines
31 KiB

  1. //***************************************************************************
  2. //
  3. // MINISERV.CPP
  4. //
  5. // Module: OLE MS SNMP Property Provider
  6. //
  7. // Purpose: Implementation for the CImpClasProv class.
  8. //
  9. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. #include <provexpt.h>
  14. #include <snmpstd.h>
  15. #include <snmpmt.h>
  16. #include <snmptempl.h>
  17. #include <objbase.h>
  18. #include <typeinfo.h>
  19. #include <wbemidl.h>
  20. #include <snmpcont.h>
  21. #include <snmpevt.h>
  22. #include <snmpthrd.h>
  23. #include <snmplog.h>
  24. #include <instpath.h>
  25. #include <snmpcl.h>
  26. #include <snmptype.h>
  27. #include <snmpobj.h>
  28. #include <smir.h>
  29. #include <correlat.h>
  30. #include <genlex.h>
  31. #include <objpath.h>
  32. #include <cominit.h>
  33. #include "classfac.h"
  34. #include "clasprov.h"
  35. #include "creclass.h"
  36. #include "guids.h"
  37. extern void ProviderStartup () ;
  38. extern void ProviderClosedown () ;
  39. BOOL CImpClasProv :: s_Initialised = FALSE ;
  40. void SnmpClassDefaultThreadObject::Initialise ()
  41. {
  42. InitializeCom () ;
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // Functions constructor, destructor and IUnknown
  46. //***************************************************************************
  47. //
  48. // CImpClasProv::CImpClasProv
  49. // CImpClasProv::~CImpClasProv
  50. //
  51. //***************************************************************************
  52. CImpClasProv::CImpClasProv ()
  53. : ipAddressString ( NULL ) ,
  54. parentServer ( NULL ) ,
  55. server ( NULL ) ,
  56. m_InitSink ( NULL ) ,
  57. propertyProvider ( NULL ) ,
  58. m_notificationClassObject ( NULL ) ,
  59. m_snmpNotificationClassObject ( NULL ) ,
  60. thisNamespace ( NULL )
  61. {
  62. m_referenceCount = 0 ;
  63. /*
  64. * Place code in critical section
  65. */
  66. InterlockedIncrement ( & CClasProvClassFactory :: objectsInProgress ) ;
  67. /*
  68. * Implementation
  69. */
  70. initialised = FALSE ;
  71. ipAddressValue = NULL ;
  72. m_getNotifyCalled = FALSE ;
  73. m_getSnmpNotifyCalled = FALSE ;
  74. }
  75. CImpClasProv::~CImpClasProv(void)
  76. {
  77. /*
  78. * Implementation
  79. */
  80. delete [] ipAddressString ;
  81. free ( ipAddressValue ) ;
  82. if ( parentServer )
  83. parentServer->Release () ;
  84. if ( server )
  85. server->Release () ;
  86. if ( m_InitSink )
  87. m_InitSink->Release () ;
  88. if ( propertyProvider )
  89. propertyProvider->Release () ;
  90. if ( m_notificationClassObject )
  91. m_notificationClassObject->Release () ;
  92. if ( m_snmpNotificationClassObject )
  93. m_snmpNotificationClassObject->Release () ;
  94. delete [] thisNamespace ;
  95. /*
  96. * Place code in critical section
  97. */
  98. InterlockedDecrement ( & CClasProvClassFactory :: objectsInProgress ) ;
  99. }
  100. //***************************************************************************
  101. //
  102. // CImpClasProv::QueryInterface
  103. // CImpClasProv::AddRef
  104. // CImpClasProv::Release
  105. //
  106. // Purpose: IUnknown members for CImpClasProv object.
  107. //***************************************************************************
  108. STDMETHODIMP CImpClasProv::QueryInterface (
  109. REFIID iid ,
  110. LPVOID FAR *iplpv
  111. )
  112. {
  113. SetStructuredExceptionHandler seh;
  114. try
  115. {
  116. *iplpv = NULL ;
  117. if ( iid == IID_IUnknown )
  118. {
  119. *iplpv = ( LPVOID ) ( IWbemProviderInit * ) this ;
  120. }
  121. else if ( iid == IID_IWbemServices )
  122. {
  123. *iplpv = ( LPVOID ) ( IWbemServices * ) this ;
  124. }
  125. else if ( iid == IID_IWbemProviderInit )
  126. {
  127. *iplpv = ( LPVOID ) ( IWbemProviderInit * ) this ;
  128. }
  129. if ( *iplpv )
  130. {
  131. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  132. return ResultFromScode ( S_OK ) ;
  133. }
  134. else
  135. {
  136. return ResultFromScode ( E_NOINTERFACE ) ;
  137. }
  138. }
  139. catch(Structured_Exception e_SE)
  140. {
  141. return E_UNEXPECTED;
  142. }
  143. catch(Heap_Exception e_HE)
  144. {
  145. return E_OUTOFMEMORY;
  146. }
  147. catch(...)
  148. {
  149. return E_UNEXPECTED;
  150. }
  151. }
  152. STDMETHODIMP_(ULONG) CImpClasProv::AddRef(void)
  153. {
  154. SetStructuredExceptionHandler seh;
  155. try
  156. {
  157. return InterlockedIncrement ( & m_referenceCount ) ;
  158. }
  159. catch(Structured_Exception e_SE)
  160. {
  161. return 0;
  162. }
  163. catch(Heap_Exception e_HE)
  164. {
  165. return 0;
  166. }
  167. catch(...)
  168. {
  169. return 0;
  170. }
  171. }
  172. STDMETHODIMP_(ULONG) CImpClasProv::Release(void)
  173. {
  174. SetStructuredExceptionHandler seh;
  175. try
  176. {
  177. LONG ref ;
  178. if ( ( ref = InterlockedDecrement ( & m_referenceCount ) ) == 0 )
  179. {
  180. delete this ;
  181. return 0 ;
  182. }
  183. else
  184. {
  185. return ref ;
  186. }
  187. }
  188. catch(Structured_Exception e_SE)
  189. {
  190. return 0;
  191. }
  192. catch(Heap_Exception e_HE)
  193. {
  194. return 0;
  195. }
  196. catch(...)
  197. {
  198. return 0;
  199. }
  200. }
  201. HRESULT CImpClasProv :: SetServer ( IWbemServices *serverArg )
  202. {
  203. server = serverArg ;
  204. server->AddRef () ;
  205. //don't change anything but the cloaking...
  206. return WbemSetProxyBlanket(server,
  207. RPC_C_AUTHN_DEFAULT,
  208. RPC_C_AUTHZ_DEFAULT,
  209. COLE_DEFAULT_PRINCIPAL,
  210. RPC_C_AUTHN_LEVEL_DEFAULT,
  211. RPC_C_IMP_LEVEL_DEFAULT,
  212. NULL,
  213. EOAC_DYNAMIC_CLOAKING);
  214. }
  215. HRESULT CImpClasProv :: SetParentServer ( IWbemServices *parentServerArg )
  216. {
  217. parentServer = parentServerArg ;
  218. parentServer->AddRef () ;
  219. //don't change anything but the cloaking...
  220. return WbemSetProxyBlanket(parentServer,
  221. RPC_C_AUTHN_DEFAULT,
  222. RPC_C_AUTHZ_DEFAULT,
  223. COLE_DEFAULT_PRINCIPAL,
  224. RPC_C_AUTHN_LEVEL_DEFAULT,
  225. RPC_C_IMP_LEVEL_DEFAULT,
  226. NULL,
  227. EOAC_DYNAMIC_CLOAKING);
  228. }
  229. void CImpClasProv :: SetProvider ( IWbemServices *provider )
  230. {
  231. propertyProvider = provider ;
  232. }
  233. IWbemServices *CImpClasProv :: GetParentServer ()
  234. {
  235. return ( IWbemServices * ) parentServer ;
  236. }
  237. IWbemServices *CImpClasProv :: GetServer ()
  238. {
  239. return ( IWbemServices * ) server ;
  240. }
  241. WbemNamespacePath *CImpClasProv :: GetNamespacePath ()
  242. {
  243. return & namespacePath ;
  244. }
  245. IWbemClassObject *CImpClasProv :: GetNotificationObject ( WbemSnmpErrorObject &a_errorObject )
  246. {
  247. if ( m_notificationClassObject )
  248. {
  249. m_notificationClassObject->AddRef () ;
  250. }
  251. return m_notificationClassObject ;
  252. }
  253. IWbemClassObject *CImpClasProv :: GetSnmpNotificationObject ( WbemSnmpErrorObject &a_errorObject )
  254. {
  255. if ( m_snmpNotificationClassObject )
  256. {
  257. m_snmpNotificationClassObject->AddRef () ;
  258. }
  259. return m_snmpNotificationClassObject ;
  260. }
  261. wchar_t *CImpClasProv :: GetThisNamespace ()
  262. {
  263. return thisNamespace ;
  264. }
  265. void CImpClasProv :: SetThisNamespace ( wchar_t *thisNamespaceArg )
  266. {
  267. thisNamespace = UnicodeStringDuplicate ( thisNamespaceArg ) ;
  268. }
  269. BOOL CImpClasProv:: FetchSnmpNotificationObject (
  270. WbemSnmpErrorObject &a_errorObject ,
  271. IWbemContext *a_Ctx
  272. )
  273. {
  274. m_snmpNotificationLock.Lock();
  275. BOOL status = TRUE ;
  276. if ( m_getSnmpNotifyCalled )
  277. {
  278. if ( ! m_snmpNotificationClassObject )
  279. status = FALSE ;
  280. }
  281. else
  282. {
  283. m_getSnmpNotifyCalled = TRUE ;
  284. IWbemClassObject *classObject = NULL ;
  285. ISmirInterrogator *smirInterrogator = NULL ;
  286. HRESULT result = CoCreateInstance (
  287. CLSID_SMIR_Database ,
  288. NULL ,
  289. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  290. IID_ISMIR_Interrogative ,
  291. ( void ** ) &smirInterrogator
  292. );
  293. if ( SUCCEEDED ( result ) )
  294. {
  295. ISMIRWbemConfiguration *smirConfiguration = NULL ;
  296. result = smirInterrogator->QueryInterface ( IID_ISMIRWbemConfiguration , ( void ** ) & smirConfiguration ) ;
  297. if ( SUCCEEDED ( result ) )
  298. {
  299. smirConfiguration->SetContext ( a_Ctx) ;
  300. smirConfiguration->Release () ;
  301. result = smirInterrogator->GetWBEMClass ( &m_snmpNotificationClassObject , WBEM_CLASS_SNMPNOTIFYSTATUS ) ;
  302. if ( ! SUCCEEDED ( result ) )
  303. {
  304. status = FALSE ;
  305. m_snmpNotificationClassObject = NULL ;
  306. }
  307. }
  308. else
  309. {
  310. status = FALSE ;
  311. m_snmpNotificationClassObject = NULL ;
  312. }
  313. smirInterrogator->Release () ;
  314. }
  315. }
  316. m_snmpNotificationLock.Unlock();
  317. return status ;
  318. }
  319. BOOL CImpClasProv:: FetchNotificationObject (
  320. WbemSnmpErrorObject &a_errorObject ,
  321. IWbemContext *a_Ctx
  322. )
  323. {
  324. m_notificationLock.Lock();
  325. BOOL status = TRUE ;
  326. if ( m_getNotifyCalled )
  327. {
  328. if ( ! m_notificationClassObject )
  329. status = FALSE ;
  330. }
  331. else
  332. {
  333. m_getNotifyCalled = TRUE ;
  334. BSTR t_Class = SysAllocString ( WBEM_CLASS_EXTENDEDSTATUS ) ;
  335. HRESULT result = server->GetObject (
  336. t_Class ,
  337. 0 ,
  338. a_Ctx ,
  339. & m_notificationClassObject ,
  340. NULL
  341. ) ;
  342. SysFreeString ( t_Class ) ;
  343. if ( ! SUCCEEDED ( result ) )
  344. {
  345. status = FALSE ;
  346. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_OBJECT ) ;
  347. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  348. a_errorObject.SetMessage ( L"Failed to get __ExtendedStatus" ) ;
  349. }
  350. }
  351. m_notificationLock.Unlock();
  352. return status ;
  353. }
  354. BOOL CImpClasProv::AttachParentServer (
  355. WbemSnmpErrorObject &a_errorObject ,
  356. BSTR ObjectPath,
  357. IWbemContext *pCtx
  358. )
  359. {
  360. DebugMacro0(
  361. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  362. __FILE__,__LINE__,
  363. L"CImpClasProv::AttachParentServer ( (%s) )" ,
  364. ObjectPath
  365. ) ;
  366. )
  367. BOOL status = TRUE ;
  368. IWbemLocator *locator = NULL ;
  369. IWbemServices *t_server = NULL ;
  370. // Get Parent Namespace Path
  371. WbemNamespacePath *namespacePath = GetNamespacePath () ;
  372. ULONG count = namespacePath->GetCount () ;
  373. wchar_t *path = NULL ;
  374. if ( namespacePath->GetServer () )
  375. {
  376. path = UnicodeStringDuplicate ( L"\\\\" ) ;
  377. wchar_t *concatPath = UnicodeStringAppend ( path , namespacePath->GetServer () ) ;
  378. delete [] path ;
  379. path = concatPath ;
  380. }
  381. if ( ! namespacePath->Relative () )
  382. {
  383. wchar_t *concatPath = UnicodeStringAppend ( path , L"\\" ) ;
  384. delete [] path ;
  385. path = concatPath ;
  386. }
  387. ULONG pathIndex = 0 ;
  388. wchar_t *pathComponent ;
  389. namespacePath->Reset () ;
  390. while ( ( pathIndex < count - 1 ) && ( pathComponent = namespacePath->Next () ) )
  391. {
  392. wchar_t *concatPath = UnicodeStringAppend ( path , pathComponent ) ;
  393. delete [] path ;
  394. path = concatPath ;
  395. if ( pathIndex < count - 2 )
  396. {
  397. concatPath = UnicodeStringAppend ( path , L"\\" ) ;
  398. delete [] path ;
  399. path = concatPath ;
  400. }
  401. pathIndex ++ ;
  402. }
  403. if ( pathComponent = namespacePath->Next () )
  404. {
  405. SetThisNamespace ( pathComponent ) ;
  406. }
  407. DebugMacro0(
  408. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  409. __FILE__,__LINE__,
  410. L"Calling ConnectServer ( (%s) )" ,
  411. path
  412. ) ;
  413. )
  414. // Connect to parent namespace
  415. HRESULT result = CoCreateInstance (
  416. CLSID_WbemLocator ,
  417. NULL ,
  418. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  419. IID_IWbemLocator ,
  420. ( void ** ) & locator
  421. );
  422. if ( SUCCEEDED ( result ) )
  423. {
  424. result = locator->ConnectServer (
  425. path ,
  426. NULL ,
  427. NULL ,
  428. NULL ,
  429. 0 ,
  430. NULL,
  431. pCtx,
  432. ( IWbemServices ** ) & t_server
  433. ) ;
  434. if ( SUCCEEDED ( result ) )
  435. {
  436. result = SetParentServer ( t_server ) ;
  437. t_server->Release();
  438. if ( FAILED ( result ) && result != E_NOINTERFACE ) //implies there is no prxy security - inproc.
  439. {
  440. status = FALSE ;
  441. a_errorObject.SetStatus ( WBEM_SNMP_E_PROVIDER_FAILURE ) ;
  442. a_errorObject.SetWbemStatus ( WBEM_E_PROVIDER_FAILURE ) ;
  443. a_errorObject.SetMessage ( L"Failed to secure proxy to this namespace's parent namespace" ) ;
  444. }
  445. }
  446. else
  447. {
  448. status = FALSE ;
  449. a_errorObject.SetStatus ( WBEM_SNMP_E_PROVIDER_FAILURE ) ;
  450. a_errorObject.SetWbemStatus ( WBEM_E_PROVIDER_FAILURE ) ;
  451. a_errorObject.SetMessage ( L"Failed to connect to this namespace's parent namespace" ) ;
  452. }
  453. locator->Release () ;
  454. }
  455. else
  456. {
  457. status = FALSE ;
  458. a_errorObject.SetStatus ( WBEM_SNMP_E_PROVIDER_FAILURE ) ;
  459. a_errorObject.SetWbemStatus ( WBEM_E_PROVIDER_FAILURE ) ;
  460. a_errorObject.SetMessage ( L"Failed to CoCreateInstance on IID_IWbemLocator" ) ;
  461. }
  462. delete [] path ;
  463. DebugMacro0(
  464. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  465. __FILE__,__LINE__,
  466. L"CImpClasProv::AttachParentServer ( (%s) ) with result" ,
  467. ObjectPath ,
  468. a_errorObject.GetWbemStatus ()
  469. ) ;
  470. )
  471. return status ;
  472. }
  473. BOOL CImpClasProv::ObtainCachedIpAddress ( WbemSnmpErrorObject &a_errorObject )
  474. {
  475. DebugMacro0(
  476. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  477. __FILE__,__LINE__,
  478. L"CImpClasProv::ObtainCachedIpAddress ()"
  479. ) ;
  480. )
  481. BOOL status = TRUE ;
  482. IWbemClassObject *namespaceObject = NULL ;
  483. wchar_t *objectPathPrefix = UnicodeStringAppend ( WBEM_NAMESPACE_EQUALS , GetThisNamespace () ) ;
  484. wchar_t *objectPath = UnicodeStringAppend ( objectPathPrefix , WBEM_NAMESPACE_QUOTE ) ;
  485. delete [] objectPathPrefix ;
  486. BSTR t_Path = SysAllocString ( objectPath ) ;
  487. HRESULT result = parentServer->GetObject (
  488. t_Path ,
  489. 0 ,
  490. NULL ,
  491. &namespaceObject ,
  492. NULL
  493. ) ;
  494. SysFreeString(t_Path);
  495. delete [] objectPath ;
  496. if ( SUCCEEDED ( result ) )
  497. {
  498. IWbemQualifierSet *classQualifierObject ;
  499. result = namespaceObject->GetQualifierSet ( &classQualifierObject ) ;
  500. if ( SUCCEEDED ( result ) )
  501. {
  502. VARIANT variant ;
  503. VariantInit ( & variant ) ;
  504. LONG attributeType ;
  505. result = classQualifierObject->Get (
  506. WBEM_QUALIFIER_AGENTTRANSPORT ,
  507. 0,
  508. &variant ,
  509. & attributeType
  510. ) ;
  511. if ( SUCCEEDED ( result ) )
  512. {
  513. if ( variant.vt == VT_BSTR )
  514. {
  515. if ( _wcsicmp ( variant.bstrVal , L"IP" ) == 0 )
  516. {
  517. VARIANT variant ;
  518. VariantInit ( & variant ) ;
  519. LONG attributeType ;
  520. result = classQualifierObject->Get (
  521. WBEM_QUALIFIER_AGENTADDRESS ,
  522. 0,
  523. &variant ,
  524. & attributeType
  525. ) ;
  526. if ( SUCCEEDED ( result ) )
  527. {
  528. if ( variant.vt == VT_BSTR )
  529. {
  530. ipAddressString = UnicodeToDbcsString ( variant.bstrVal ) ;
  531. if ( ipAddressString )
  532. {
  533. SnmpTransportIpAddress transportAddress (
  534. ipAddressString ,
  535. SNMP_ADDRESS_RESOLVE_NAME | SNMP_ADDRESS_RESOLVE_VALUE
  536. ) ;
  537. if ( transportAddress () )
  538. {
  539. ipAddressValue = _strdup ( transportAddress.GetAddress () ) ;
  540. }
  541. else
  542. {
  543. delete [] ipAddressString ;
  544. ipAddressString = NULL ;
  545. /*
  546. * Invalid Transport Address.
  547. */
  548. status = FALSE ;
  549. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  550. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  551. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentAddress" ) ;
  552. }
  553. }
  554. else
  555. {
  556. status = FALSE ;
  557. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  558. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  559. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentAddress" ) ;
  560. }
  561. }
  562. else
  563. {
  564. status = FALSE ;
  565. a_errorObject.SetStatus ( WBEM_SNMP_E_TYPE_MISMATCH ) ;
  566. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  567. a_errorObject.SetMessage ( L"Type mismatch for qualifier: AgentAddress" ) ;
  568. }
  569. }
  570. else
  571. {
  572. /*
  573. * Transport Address not specified, ignore it
  574. */
  575. }
  576. VariantClear ( &variant ) ;
  577. }
  578. else if ( _wcsicmp ( variant.bstrVal , L"IPX" ) == 0 )
  579. {
  580. }
  581. else
  582. {
  583. // Unknown transport type
  584. status = FALSE ;
  585. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORT ) ;
  586. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  587. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentTransport" ) ;
  588. }
  589. }
  590. else
  591. {
  592. /*
  593. * Transport qualifier was not a string value
  594. */
  595. status = FALSE ;
  596. a_errorObject.SetStatus ( WBEM_SNMP_E_TYPE_MISMATCH ) ;
  597. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  598. a_errorObject.SetMessage ( L"Type mismatch for qualifier: AgentTransport" ) ;
  599. }
  600. }
  601. else
  602. {
  603. LONG attributeType ;
  604. result = classQualifierObject->Get (
  605. WBEM_QUALIFIER_AGENTADDRESS ,
  606. 0,
  607. &variant ,
  608. & attributeType
  609. ) ;
  610. if ( SUCCEEDED ( result ) )
  611. {
  612. if ( variant.vt == VT_BSTR )
  613. {
  614. ipAddressString = UnicodeToDbcsString ( variant.bstrVal ) ;
  615. if ( ipAddressString )
  616. {
  617. SnmpTransportIpAddress transportAddress (
  618. ipAddressString ,
  619. SNMP_ADDRESS_RESOLVE_NAME | SNMP_ADDRESS_RESOLVE_VALUE
  620. ) ;
  621. if ( transportAddress () )
  622. {
  623. ipAddressValue = _strdup ( transportAddress.GetAddress () ) ;
  624. }
  625. else
  626. {
  627. delete [] ipAddressString ;
  628. ipAddressString = NULL ;
  629. /*
  630. * Invalid Transport Address.
  631. */
  632. status = FALSE ;
  633. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  634. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  635. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentAddress" ) ;
  636. }
  637. }
  638. else
  639. {
  640. status = FALSE ;
  641. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_TRANSPORTCONTEXT ) ;
  642. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  643. a_errorObject.SetMessage ( L"Illegal value for qualifier: AgentAddress" ) ;
  644. }
  645. }
  646. else
  647. {
  648. status = FALSE ;
  649. a_errorObject.SetStatus ( WBEM_SNMP_E_INVALID_QUALIFIER ) ;
  650. a_errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  651. a_errorObject.SetMessage ( L"Type mismatch for qualifier: AgentAddress" ) ;
  652. }
  653. }
  654. else
  655. {
  656. /*
  657. * Transport Address not specified, ignore it
  658. */
  659. }
  660. VariantClear ( &variant ) ;
  661. }
  662. VariantClear ( & variant );
  663. }
  664. namespaceObject->Release () ;
  665. }
  666. DebugMacro0(
  667. wchar_t *t_UnicodeString = ipAddressValue ? DbcsToUnicodeString ( ipAddressValue ) : NULL ;
  668. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  669. __FILE__,__LINE__,
  670. L"Returning from CImpClasProv::ObtainCachedIpAddress () with IP Address (%s)",
  671. t_UnicodeString ? t_UnicodeString : L"NULL"
  672. ) ;
  673. delete [] t_UnicodeString ;
  674. )
  675. return status ;
  676. }
  677. HRESULT STDMETHODCALLTYPE CImpClasProv::OpenNamespace (
  678. const BSTR ObjectPath,
  679. long lFlags,
  680. IWbemContext FAR* pCtx,
  681. IWbemServices FAR* FAR* pNewContext,
  682. IWbemCallResult FAR* FAR* ppErrorObject
  683. )
  684. {
  685. return WBEM_E_NOT_AVAILABLE ;
  686. }
  687. HRESULT CImpClasProv :: CancelAsyncCall (
  688. IWbemObjectSink __RPC_FAR *pSink
  689. )
  690. {
  691. return WBEM_E_NOT_AVAILABLE ;
  692. }
  693. HRESULT CImpClasProv :: QueryObjectSink (
  694. long lFlags,
  695. IWbemObjectSink FAR* FAR* ppResponseHandler
  696. )
  697. {
  698. return WBEM_E_NOT_AVAILABLE ;
  699. }
  700. HRESULT CImpClasProv :: GetObject (
  701. const BSTR ObjectPath,
  702. long lFlags,
  703. IWbemContext FAR *pCtx,
  704. IWbemClassObject FAR* FAR *ppObject,
  705. IWbemCallResult FAR* FAR *ppCallResult
  706. )
  707. {
  708. return WBEM_E_NOT_AVAILABLE ;
  709. }
  710. HRESULT CImpClasProv :: GetObjectAsync (
  711. const BSTR ObjectPath,
  712. long lFlags,
  713. IWbemContext FAR *pCtx,
  714. IWbemObjectSink FAR* pHandler
  715. )
  716. {
  717. SetStructuredExceptionHandler seh;
  718. try
  719. {
  720. HRESULT result = WbemCoImpersonateClient();
  721. DebugMacro0(
  722. SnmpDebugLog :: s_SnmpDebugLog->Write (
  723. L"\r\n"
  724. ) ;
  725. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  726. __FILE__,__LINE__,
  727. L"CImpClasProv::GetObjectAsync ( (%s) )" ,
  728. ObjectPath
  729. ) ;
  730. )
  731. if (SUCCEEDED(result))
  732. {
  733. WbemSnmpErrorObject errorObject ;
  734. ParsedObjectPath *t_ParsedObjectPath = NULL ;
  735. CObjectPathParser t_ObjectPathParser ;
  736. BOOL status = t_ObjectPathParser.Parse ( ObjectPath , &t_ParsedObjectPath ) ;
  737. if ( status == 0 )
  738. {
  739. // Class requested
  740. wchar_t *Class = t_ParsedObjectPath->m_pClass ;
  741. /*
  742. * Create Asynchronous Class object
  743. */
  744. SnmpClassGetAsyncEventObject aSyncEvent ( this , Class, pHandler , pCtx ) ;
  745. aSyncEvent.Process () ;
  746. aSyncEvent.Wait ( TRUE ) ;
  747. status = TRUE ;
  748. errorObject.SetStatus ( WBEM_SNMP_NO_ERROR ) ;
  749. errorObject.SetWbemStatus ( WBEM_NO_ERROR ) ;
  750. errorObject.SetMessage ( L"" ) ;
  751. delete t_ParsedObjectPath ;
  752. }
  753. else
  754. {
  755. // Parse Failure
  756. status = FALSE ;
  757. errorObject.SetStatus ( WBEM_SNMP_E_INVALID_PATH ) ;
  758. errorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  759. errorObject.SetMessage ( L"Failed to parse object path" ) ;
  760. }
  761. // Check validity of server/namespace path and validity of request
  762. result = errorObject.GetWbemStatus () ;
  763. WbemCoRevertToSelf();
  764. }
  765. else
  766. {
  767. result = WBEM_E_ACCESS_DENIED;
  768. }
  769. DebugMacro0(
  770. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  771. __FILE__,__LINE__,
  772. L"Returning from CImpClasProv::GetObjectAsync ( (%s) ) with Result = (%lx)" ,
  773. ObjectPath ,
  774. result
  775. ) ;
  776. )
  777. return result ;
  778. }
  779. catch(Structured_Exception e_SE)
  780. {
  781. WbemCoRevertToSelf();
  782. return WBEM_E_UNEXPECTED;
  783. }
  784. catch(Heap_Exception e_HE)
  785. {
  786. WbemCoRevertToSelf();
  787. return WBEM_E_OUT_OF_MEMORY;
  788. }
  789. catch(...)
  790. {
  791. WbemCoRevertToSelf();
  792. return WBEM_E_UNEXPECTED;
  793. }
  794. }
  795. HRESULT CImpClasProv :: PutClass (
  796. IWbemClassObject FAR* pObject,
  797. long lFlags,
  798. IWbemContext FAR *pCtx,
  799. IWbemCallResult FAR* FAR* ppCallResult
  800. )
  801. {
  802. return WBEM_E_NOT_AVAILABLE ;
  803. }
  804. HRESULT CImpClasProv :: PutClassAsync (
  805. IWbemClassObject FAR* pObject,
  806. long lFlags,
  807. IWbemContext FAR *pCtx,
  808. IWbemObjectSink FAR* pResponseHandler
  809. )
  810. {
  811. return WBEM_E_NOT_AVAILABLE ;
  812. }
  813. HRESULT CImpClasProv :: DeleteClass (
  814. const BSTR Class,
  815. long lFlags,
  816. IWbemContext FAR *pCtx,
  817. IWbemCallResult FAR* FAR* ppCallResult
  818. )
  819. {
  820. return WBEM_E_NOT_AVAILABLE ;
  821. }
  822. HRESULT CImpClasProv :: DeleteClassAsync (
  823. const BSTR Class,
  824. long lFlags,
  825. IWbemContext FAR *pCtx,
  826. IWbemObjectSink FAR* pResponseHandler
  827. )
  828. {
  829. return WBEM_E_NOT_AVAILABLE ;
  830. }
  831. HRESULT CImpClasProv :: CreateClassEnum (
  832. const BSTR Superclass,
  833. long lFlags,
  834. IWbemContext FAR *pCtx,
  835. IEnumWbemClassObject FAR *FAR *ppEnum
  836. )
  837. {
  838. return WBEM_E_NOT_AVAILABLE ;
  839. }
  840. SCODE CImpClasProv :: CreateClassEnumAsync (
  841. const BSTR Superclass,
  842. long lFlags,
  843. IWbemContext FAR* pCtx,
  844. IWbemObjectSink FAR* pHandler
  845. )
  846. {
  847. SetStructuredExceptionHandler seh;
  848. try
  849. {
  850. HRESULT result = WbemCoImpersonateClient();
  851. DebugMacro0(
  852. SnmpDebugLog :: s_SnmpDebugLog->Write (
  853. L"\r\n"
  854. ) ;
  855. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  856. __FILE__,__LINE__,
  857. L"CImpClasProv::CreateClassEnumAsync ( (%s) )" ,
  858. Superclass
  859. ) ;
  860. )
  861. if (SUCCEEDED(result))
  862. {
  863. /*
  864. * Create Synchronous Enum Instance object
  865. */
  866. SnmpClassEnumAsyncEventObject aSyncEvent ( this , Superclass, lFlags , pHandler , pCtx ) ;
  867. aSyncEvent.Process () ;
  868. /*`
  869. * Wait for worker object to complete processing
  870. */
  871. aSyncEvent.Wait ( TRUE ) ;
  872. WbemCoRevertToSelf();
  873. }
  874. else
  875. {
  876. result = WBEM_E_ACCESS_DENIED;
  877. }
  878. DebugMacro0(
  879. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  880. __FILE__,__LINE__,
  881. L"Returning From CImpClasProv::CreateClassEnumAsync ( (%s) ) with Result = (%lx)" ,
  882. Superclass ,
  883. result
  884. ) ;
  885. )
  886. return result ;
  887. }
  888. catch(Structured_Exception e_SE)
  889. {
  890. WbemCoRevertToSelf();
  891. return WBEM_E_UNEXPECTED;
  892. }
  893. catch(Heap_Exception e_HE)
  894. {
  895. WbemCoRevertToSelf();
  896. return WBEM_E_OUT_OF_MEMORY;
  897. }
  898. catch(...)
  899. {
  900. WbemCoRevertToSelf();
  901. return WBEM_E_UNEXPECTED;
  902. }
  903. }
  904. HRESULT CImpClasProv :: PutInstance (
  905. IWbemClassObject FAR *pInst,
  906. long lFlags,
  907. IWbemContext FAR *pCtx,
  908. IWbemCallResult FAR *FAR *ppCallResult
  909. )
  910. {
  911. return WBEM_E_NOT_AVAILABLE ;
  912. }
  913. HRESULT CImpClasProv :: PutInstanceAsync (
  914. IWbemClassObject FAR* pInst,
  915. long lFlags,
  916. IWbemContext FAR *pCtx,
  917. IWbemObjectSink FAR* pHandler
  918. )
  919. {
  920. return WBEM_E_NOT_AVAILABLE ;
  921. }
  922. HRESULT CImpClasProv :: DeleteInstance (
  923. const BSTR ObjectPath,
  924. long lFlags,
  925. IWbemContext FAR *pCtx,
  926. IWbemCallResult FAR *FAR *ppCallResult
  927. )
  928. {
  929. return WBEM_E_NOT_AVAILABLE ;
  930. }
  931. HRESULT CImpClasProv :: DeleteInstanceAsync (
  932. const BSTR ObjectPath,
  933. long lFlags,
  934. IWbemContext __RPC_FAR *pCtx,
  935. IWbemObjectSink __RPC_FAR *pResponseHandler
  936. )
  937. {
  938. return WBEM_E_NOT_AVAILABLE ;
  939. }
  940. HRESULT CImpClasProv :: CreateInstanceEnum (
  941. const BSTR Class,
  942. long lFlags,
  943. IWbemContext FAR *pCtx,
  944. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  945. )
  946. {
  947. return WBEM_E_NOT_AVAILABLE ;
  948. }
  949. HRESULT CImpClasProv :: CreateInstanceEnumAsync (
  950. const BSTR Class,
  951. long lFlags,
  952. IWbemContext __RPC_FAR *pCtx,
  953. IWbemObjectSink FAR* pHandler
  954. )
  955. {
  956. return WBEM_E_NOT_AVAILABLE ;
  957. }
  958. HRESULT CImpClasProv :: ExecQuery (
  959. const BSTR QueryLanguage,
  960. const BSTR Query,
  961. long lFlags,
  962. IWbemContext FAR *pCtx,
  963. IEnumWbemClassObject FAR *FAR *ppEnum
  964. )
  965. {
  966. return WBEM_E_NOT_AVAILABLE ;
  967. }
  968. HRESULT CImpClasProv :: ExecQueryAsync (
  969. const BSTR QueryFormat,
  970. const BSTR Query,
  971. long lFlags,
  972. IWbemContext FAR* pCtx,
  973. IWbemObjectSink FAR* pHandler
  974. )
  975. {
  976. return WBEM_E_NOT_AVAILABLE ;
  977. }
  978. HRESULT CImpClasProv :: ExecNotificationQuery (
  979. const BSTR QueryLanguage,
  980. const BSTR Query,
  981. long lFlags,
  982. IWbemContext __RPC_FAR *pCtx,
  983. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  984. )
  985. {
  986. return WBEM_E_NOT_AVAILABLE ;
  987. }
  988. HRESULT CImpClasProv :: ExecNotificationQueryAsync (
  989. const BSTR QueryLanguage,
  990. const BSTR Query,
  991. long lFlags,
  992. IWbemContext __RPC_FAR *pCtx,
  993. IWbemObjectSink __RPC_FAR *pResponseHandler
  994. )
  995. {
  996. return WBEM_E_NOT_AVAILABLE ;
  997. }
  998. HRESULT STDMETHODCALLTYPE CImpClasProv :: ExecMethod(
  999. const BSTR ObjectPath,
  1000. const BSTR MethodName,
  1001. long lFlags,
  1002. IWbemContext FAR *pCtx,
  1003. IWbemClassObject FAR *pInParams,
  1004. IWbemClassObject FAR *FAR *ppOutParams,
  1005. IWbemCallResult FAR *FAR *ppCallResult
  1006. )
  1007. {
  1008. return WBEM_E_NOT_AVAILABLE ;
  1009. }
  1010. HRESULT STDMETHODCALLTYPE CImpClasProv :: ExecMethodAsync (
  1011. const BSTR ObjectPath,
  1012. const BSTR MethodName,
  1013. long lFlags,
  1014. IWbemContext FAR *pCtx,
  1015. IWbemClassObject FAR *pInParams,
  1016. IWbemObjectSink FAR *pResponseHandler
  1017. )
  1018. {
  1019. return WBEM_E_NOT_AVAILABLE ;
  1020. }
  1021. HRESULT CImpClasProv :: Initialize(
  1022. LPWSTR pszUser,
  1023. LONG lFlags,
  1024. LPWSTR pszNamespace,
  1025. LPWSTR pszLocale,
  1026. IWbemServices *pCIMOM, // For anybody
  1027. IWbemContext *pCtx,
  1028. IWbemProviderInitSink *pInitSink // For init signals
  1029. )
  1030. {
  1031. SetStructuredExceptionHandler seh;
  1032. try
  1033. {
  1034. HRESULT result = WbemCoImpersonateClient(); //cimom is the client - LocalSystem
  1035. if (SUCCEEDED(result))
  1036. {
  1037. BOOL bEnteredCritSec = FALSE;
  1038. BOOL status = TRUE ;
  1039. try
  1040. {
  1041. EnterCriticalSection ( & s_ProviderCriticalSection ) ;
  1042. bEnteredCritSec = TRUE;
  1043. namespacePath.SetNamespacePath ( pszNamespace ) ;
  1044. if ( ! CImpClasProv :: s_Initialised )
  1045. {
  1046. ProviderStartup () ;
  1047. SnmpThreadObject :: Startup () ;
  1048. try
  1049. {
  1050. SnmpDebugLog :: Startup () ;
  1051. }
  1052. catch ( ... )
  1053. {
  1054. // we do not want to left s_Reference count up
  1055. SnmpThreadObject :: Closedown () ;
  1056. ProviderClosedown () ;
  1057. throw;
  1058. }
  1059. try
  1060. {
  1061. status = SnmpClassLibrary :: Startup () ;
  1062. }
  1063. catch ( ... )
  1064. {
  1065. // we do not want to left s_Reference count up
  1066. SnmpDebugLog :: Closedown () ;
  1067. SnmpThreadObject :: Closedown () ;
  1068. ProviderClosedown () ;
  1069. throw;
  1070. }
  1071. if ( status == FALSE )
  1072. {
  1073. SnmpDebugLog :: Closedown () ;
  1074. SnmpThreadObject :: Closedown () ;
  1075. ProviderClosedown () ;
  1076. }
  1077. else
  1078. {
  1079. CImpClasProv :: s_Initialised = TRUE ;
  1080. }
  1081. }
  1082. LeaveCriticalSection ( & s_ProviderCriticalSection ) ;
  1083. bEnteredCritSec = FALSE;
  1084. }
  1085. catch ( ... )
  1086. {
  1087. if ( bEnteredCritSec )
  1088. {
  1089. LeaveCriticalSection ( & s_ProviderCriticalSection ) ;
  1090. bEnteredCritSec = FALSE;
  1091. }
  1092. throw;
  1093. }
  1094. WbemSnmpErrorObject errorObject ;
  1095. result = SetServer(pCIMOM) ;
  1096. if ( FAILED ( result ) && result != E_NOINTERFACE ) //implies there is no prxy security - inproc.
  1097. {
  1098. status = FALSE ;
  1099. errorObject.SetStatus ( WBEM_SNMP_E_PROVIDER_FAILURE ) ;
  1100. errorObject.SetWbemStatus ( WBEM_E_PROVIDER_FAILURE ) ;
  1101. errorObject.SetMessage ( L"Failed to secure proxy to this namespace" ) ;
  1102. }
  1103. wchar_t *t_ObjectPath = namespacePath.GetNamespacePath () ;
  1104. BSTR t_Path = SysAllocString ( t_ObjectPath ) ;
  1105. status = AttachParentServer (
  1106. errorObject ,
  1107. t_Path ,
  1108. pCtx
  1109. ) ;
  1110. SysFreeString ( t_Path ) ;
  1111. delete [] t_ObjectPath ;
  1112. if ( status )
  1113. {
  1114. ObtainCachedIpAddress ( errorObject ) ;
  1115. }
  1116. else
  1117. {
  1118. status = FALSE ;
  1119. errorObject.SetStatus ( WBEM_SNMP_E_PROVIDER_FAILURE ) ;
  1120. errorObject.SetWbemStatus ( WBEM_E_PROVIDER_FAILURE ) ;
  1121. errorObject.SetMessage ( L"Failed to CoCreateInstance on IID_IWbemServices" ) ;
  1122. }
  1123. status = FetchSnmpNotificationObject ( errorObject , pCtx ) ;
  1124. status = FetchNotificationObject ( errorObject , pCtx ) ;
  1125. //doing this here hangs cimom so delay until classes are asked for
  1126. #ifdef CORRELATOR_INIT
  1127. //prime the correlator....
  1128. if (status)
  1129. {
  1130. ISmirInterrogator *t_Interrogator = NULL;
  1131. HRESULT result = CoCreateInstance (
  1132. CLSID_SMIR_Database ,
  1133. NULL ,
  1134. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  1135. IID_ISMIR_Interrogative ,
  1136. ( void ** ) &t_Interrogator
  1137. );
  1138. if ( SUCCEEDED ( result ) )
  1139. {
  1140. ISMIRWbemConfiguration *smirConfiguration = NULL ;
  1141. result = t_Interrogator->QueryInterface ( IID_ISMIRWbemConfiguration , ( void ** ) & smirConfiguration ) ;
  1142. if ( SUCCEEDED ( result ) )
  1143. {
  1144. smirConfiguration->SetContext ( pCtx ) ;
  1145. CCorrelator::StartUp(t_Interrogator);
  1146. smirConfiguration->Release () ;
  1147. }
  1148. else
  1149. {
  1150. errorObject.SetStatus ( WBEM_SNMP_E_PROVIDER_FAILURE ) ;
  1151. errorObject.SetWbemStatus ( WBEM_E_PROVIDER_FAILURE ) ;
  1152. errorObject.SetMessage ( L"QueryInterface on ISmirInterrogator Failed" ) ;
  1153. }
  1154. t_Interrogator->Release();
  1155. }
  1156. else
  1157. {
  1158. errorObject.SetStatus ( WBEM_SNMP_E_PROVIDER_FAILURE ) ;
  1159. errorObject.SetWbemStatus ( WBEM_E_PROVIDER_FAILURE ) ;
  1160. errorObject.SetMessage ( L"CoCreateInstance on ISmirInterrogator Failed" ) ;
  1161. }
  1162. }
  1163. #endif //CORRELATOR_INIT
  1164. result = errorObject.GetWbemStatus () ;
  1165. pInitSink->SetStatus ( (result == WBEM_NO_ERROR) ? (LONG)WBEM_S_INITIALIZED : (LONG)WBEM_E_FAILED , 0 ) ;
  1166. WbemCoRevertToSelf();
  1167. }
  1168. else
  1169. {
  1170. result = WBEM_E_ACCESS_DENIED;
  1171. }
  1172. DebugMacro2(
  1173. SnmpDebugLog :: s_SnmpDebugLog->WriteFileAndLine (
  1174. __FILE__,__LINE__,
  1175. L"Returning From CImpClasProv::Initialize with Result = (%lx)" ,
  1176. result
  1177. ) ;
  1178. )
  1179. return result ;
  1180. }
  1181. catch(Structured_Exception e_SE)
  1182. {
  1183. WbemCoRevertToSelf();
  1184. return WBEM_E_UNEXPECTED;
  1185. }
  1186. catch(Heap_Exception e_HE)
  1187. {
  1188. WbemCoRevertToSelf();
  1189. return WBEM_E_OUT_OF_MEMORY;
  1190. }
  1191. catch(...)
  1192. {
  1193. WbemCoRevertToSelf();
  1194. return WBEM_E_UNEXPECTED;
  1195. }
  1196. }