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.

1522 lines
30 KiB

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