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.

976 lines
29 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. frswmipv.cpp
  5. Abstract:
  6. This is the implementation of the WMI provider for NTFRS. This file
  7. contains the implementation of the CProvider class.
  8. Author:
  9. Sudarshan Chitre (sudarc) , Mathew George (t-mattg) - 3-Aug-2000
  10. Environment
  11. User mode winnt
  12. --*/
  13. extern "C" {
  14. #include <ntreppch.h>
  15. #include <frs.h>
  16. }
  17. #include <frswmipv.h>
  18. //
  19. // Extern globals from other modules.
  20. //
  21. extern "C" PGEN_TABLE ReplicasByGuid;
  22. extern "C" PCHAR OLPartnerStateNames[];
  23. // const CLSID CLSID_Provider = {0x39143F73,0xFDB1,0x4CF5,0x8C,0xB7,0xC8,0x43,0x9E,0x3F,0x5C,0x20};
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CProvider
  26. //
  27. // Class constructor/destructor
  28. //
  29. CProvider::CProvider()
  30. /*++
  31. Routine Description:
  32. Initializes members of the CProvider class.
  33. Arguments:
  34. None
  35. Return Value:
  36. None
  37. --*/
  38. {
  39. ODS(L"CProvider constructor.\n");
  40. m_NumReplicaSets = 5;
  41. m_dwRef = 0;
  42. m_ipNamespace = NULL;
  43. m_ipMicrosoftFrs_DfsMemberClassDef = NULL;
  44. m_ipMicrosoftFrs_SysVolMemberClassDef = NULL;
  45. m_ipMicrosoftFrs_DfsConnectionClassDef = NULL;
  46. m_ipMicrosoftFrs_SysVolConnectionClassDef = NULL;
  47. m_ipMicrosoftFrs_DfsMemberEventClassDef = NULL;
  48. }
  49. CProvider::~CProvider()
  50. /*++
  51. Routine Description:
  52. Deallocates resources acquired by this object.
  53. Arguments:
  54. None
  55. Return Value:
  56. None
  57. --*/
  58. {
  59. if(m_ipNamespace)
  60. {
  61. m_ipNamespace->Release();
  62. m_ipNamespace = NULL;
  63. }
  64. if(m_ipMicrosoftFrs_DfsMemberClassDef)
  65. {
  66. m_ipMicrosoftFrs_DfsMemberClassDef->Release();
  67. m_ipMicrosoftFrs_DfsMemberClassDef = NULL;
  68. }
  69. if(m_ipMicrosoftFrs_SysVolMemberClassDef)
  70. {
  71. m_ipMicrosoftFrs_SysVolMemberClassDef->Release();
  72. m_ipMicrosoftFrs_SysVolMemberClassDef = NULL;
  73. }
  74. if(m_ipMicrosoftFrs_DfsConnectionClassDef)
  75. {
  76. m_ipMicrosoftFrs_DfsConnectionClassDef->Release();
  77. m_ipMicrosoftFrs_DfsConnectionClassDef = NULL;
  78. }
  79. if(m_ipMicrosoftFrs_SysVolConnectionClassDef)
  80. {
  81. m_ipMicrosoftFrs_SysVolConnectionClassDef->Release();
  82. m_ipMicrosoftFrs_SysVolConnectionClassDef = NULL;
  83. }
  84. if(m_ipMicrosoftFrs_DfsMemberEventClassDef)
  85. {
  86. m_ipMicrosoftFrs_DfsMemberEventClassDef->Release();
  87. m_ipMicrosoftFrs_DfsMemberEventClassDef = NULL;
  88. }
  89. }
  90. //
  91. // Methods for the IUnknown interface
  92. //
  93. ULONG CProvider::AddRef()
  94. /*++
  95. Routine Description:
  96. Increments the reference count of the object.
  97. Arguments:
  98. None
  99. Return Value:
  100. Current reference count. (> 0)
  101. --*/
  102. {
  103. return InterlockedIncrement((LONG *)&m_dwRef);
  104. }
  105. ULONG CProvider::Release()
  106. /*++
  107. Routine Description:
  108. Decrements the reference count of the object. Frees
  109. the object resource when the reference count becomes
  110. zero.
  111. Arguments:
  112. None
  113. Return Value:
  114. New reference count.
  115. --*/
  116. {
  117. ULONG dwRef = InterlockedDecrement((LONG *)&m_dwRef);
  118. if(dwRef == 0)
  119. delete this;
  120. return dwRef;
  121. }
  122. HRESULT CProvider::QueryInterface(REFIID riid, void** ppv)
  123. /*++
  124. Routine Description:
  125. This method is called by COM to obtain pointers to
  126. a given interface. The provider currently supports
  127. the IUnknown, IWbemProviderInit and the IWbemServices
  128. interface.
  129. Arguments:
  130. riid : GUID of the required interface.
  131. ppv : Pointer where the "interface pointer" is returned.
  132. Return Value:
  133. Status of operation. Pointer to the requested interface
  134. is returned in *ppv.
  135. --*/
  136. {
  137. if(riid == IID_IUnknown || riid == IID_IWbemProviderInit)
  138. {
  139. *ppv = (IWbemProviderInit *) this;
  140. AddRef();
  141. return S_OK;
  142. }
  143. else if (riid == IID_IWbemServices)
  144. {
  145. *ppv = (IWbemServices *) this;
  146. AddRef();
  147. return S_OK;
  148. }
  149. else if (riid == IID_IWbemEventProvider)
  150. {
  151. *ppv = (IWbemEventProvider *) this;
  152. AddRef();
  153. return S_OK;
  154. }
  155. else return E_NOINTERFACE;
  156. }
  157. //
  158. // Methods for the IWbemProviderInit interface.
  159. //
  160. STDMETHODIMP CProvider::Initialize(
  161. IN LPWSTR pszUser,
  162. IN LONG lFlags,
  163. IN LPWSTR pszNamespace,
  164. IN LPWSTR pszLocale,
  165. IN IWbemServices *pNamespace,
  166. IN IWbemContext *pCtx,
  167. IN IWbemProviderInitSink *pInitSink
  168. )
  169. /*++
  170. Routine Description:
  171. This method is called to initialize the provider.
  172. We obtain the class defns of the classes we support
  173. from WMI by calling GetObject on the namespace pointer.
  174. Arguments:
  175. wszUser : [in] Pointer to the user name, if per-user initialization was requested
  176. in the __Win32Provider registration instance for this provider. Otherwise, this
  177. will be NULL. Note that this parameter is set to NULL for Event (consumer)
  178. providers regardless of the value of PerUserInitialization.
  179. lFlags : [in] Reserved. It must be zero.
  180. wszNamespace : [in] Namespace name for which the provider is being initialized.
  181. wszLocale : [in] Locale name for which the provider is being initialized. This
  182. is typically a string of the following format, where the hex value is a
  183. Microsoft standard LCID value: "MS_409". This parameter may be NULL.
  184. pNamespace : [in] An IWbemServices pointer back into Windows Management.
  185. This pointer is capable of servicing any requests made by the provider.
  186. The provider should use the IWbemProviderInit::AddRef method on this
  187. pointer if it is going to call back into Windows Management during its
  188. execution.
  189. pCtx : [in] An IWbemContext pointer associated with initialization. This
  190. parameter may be NULL. If the provider will make requests back into Windows
  191. Management before completing initialization, it should use the
  192. IWbemProviderInit::AddRef method on this pointer. For more information,
  193. see Making Calls to WMI.
  194. pInitSink : [in] An IWbemProviderInitSink pointer that is used by the provider
  195. to report initialization status.
  196. Return Value:
  197. The provider should return WBEM_S_NO_ERROR and indicate its status using the
  198. supplied object sink in the pInitSink parameter. However, if a provider
  199. returns WBEM_E_FAILED and does not use the sink, then the provider
  200. initialization will be considered as failed.
  201. --*/
  202. {
  203. // WBEM_VALIDATE_INTF_PTR( pNamespace );
  204. // WBEM_VALIDATE_INTF_PTR( pCtx );
  205. // WBEM_VALIDATE_INTF_PTR( pInitSink );
  206. HRESULT res = WBEM_S_NO_ERROR;
  207. ODS(L"In Initialize().\n");
  208. //
  209. // Fill up our member variables.
  210. //
  211. m_ipNamespace = pNamespace;
  212. m_ipNamespace->AddRef();
  213. BSTR bstrObjectName = SysAllocString(L"MicrosoftFrs_DfsMember");
  214. res = m_ipNamespace->GetObject( bstrObjectName,
  215. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  216. pCtx,
  217. &m_ipMicrosoftFrs_DfsMemberClassDef,
  218. NULL );
  219. if(FAILED(res))
  220. {
  221. ODS(L"\nFailed to get ReplicaSetSummaryInfo class definition.\n");
  222. SysFreeString(bstrObjectName);
  223. m_ipNamespace->Release();
  224. return res;
  225. }
  226. SysReAllocString(&bstrObjectName, L"MicrosoftFrs_SysVolMember");
  227. res = m_ipNamespace->GetObject( bstrObjectName,
  228. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  229. pCtx,
  230. &m_ipMicrosoftFrs_SysVolMemberClassDef,
  231. NULL );
  232. if(FAILED(res))
  233. {
  234. ODS(L"\nFailed to get ReplicaSetSummaryInfo class definition.\n");
  235. SysFreeString(bstrObjectName);
  236. m_ipNamespace->Release();
  237. return res;
  238. }
  239. SysReAllocString(&bstrObjectName, L"MicrosoftFrs_DfsConnection");
  240. ODS(bstrObjectName);
  241. res = m_ipNamespace->GetObject( bstrObjectName,
  242. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  243. pCtx,
  244. &m_ipMicrosoftFrs_DfsConnectionClassDef,
  245. NULL );
  246. if(FAILED(res))
  247. {
  248. ODS(L"\nFailed to get InboundPartnerInfo class definition.\n");
  249. SysFreeString(bstrObjectName);
  250. m_ipNamespace->Release();
  251. return res;
  252. }
  253. SysReAllocString(&bstrObjectName, L"MicrosoftFrs_SysVolConnection");
  254. ODS(bstrObjectName);
  255. res = m_ipNamespace->GetObject( bstrObjectName,
  256. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  257. pCtx,
  258. &m_ipMicrosoftFrs_SysVolConnectionClassDef,
  259. NULL );
  260. if(FAILED(res))
  261. {
  262. ODS(L"\nFailed to get InboundPartnerInfo class definition.\n");
  263. SysFreeString(bstrObjectName);
  264. m_ipNamespace->Release();
  265. return res;
  266. }
  267. SysReAllocString(&bstrObjectName, L"MicrosoftFrs_DfsMemberEvent");
  268. res = m_ipNamespace->GetObject( bstrObjectName,
  269. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  270. pCtx,
  271. &m_ipMicrosoftFrs_DfsMemberEventClassDef,
  272. NULL );
  273. if(FAILED(res))
  274. {
  275. ODS(L"\nFailed to get MicrosoftFrs_DfsMemberEvent class definition.\n");
  276. SysFreeString(bstrObjectName);
  277. m_ipNamespace->Release();
  278. return res;
  279. }
  280. //
  281. // Let winmgmt know that we have initialized.
  282. //
  283. pInitSink->SetStatus( WBEM_S_INITIALIZED, 0 );
  284. ODS(L"Completed IWbemProviderInit::Initialize() \n");
  285. return WBEM_S_NO_ERROR ;
  286. // return WBEM_E_FAILED;
  287. }
  288. STDMETHODIMP CProvider::GetObjectAsync(
  289. IN const BSTR bstrObjectPath,
  290. IN long lFlags,
  291. IN IWbemContext *pCtx,
  292. IN IWbemObjectSink *pResponseHandler)
  293. /*++
  294. Routine Description:
  295. This method is called by WMI to obtain the instance
  296. of a given object. The requested instance is indicated
  297. to WMI using the pResponseHandler interface.
  298. Arguments:
  299. strObjectPath : [in] Path of the object to retrieve. If this is NULL, an empty
  300. object, which can become a new class, is returned.
  301. lFlags : [in] Flags which affect the behavior of this method.
  302. pCtx : [in] Typically NULL. Otherwise, this is a pointer to an IWbemContext
  303. object that may be used by the provider producing the requested class or
  304. instance.
  305. pResponseHandler :[in] Pointer to the caller's implementation of IWbemObjectSink.
  306. This handler receives the requested object when it becomes available through the
  307. IWbemObjectSink::Indicate method.
  308. Return Value:
  309. Status of operation.
  310. --*/
  311. {
  312. /*
  313. HRESULT hRes;
  314. // WBEM_VALIDATE_IN_STRING_PTR( bstrObjectPath );
  315. // TODO : check lFlags?
  316. // WBEM_VALIDATE_INTF_PTR( pCtx );
  317. // WBEM_VALIDATE_INTF_PTR( pResponseHandler );
  318. static LPCWSTR ROOTSTR_MEMBER =
  319. L"Microsoft_NtFrsMemberStatus.ReplicaSetGUID=\"";
  320. static LPCWSTR ROOTSTR_CONNECTION_LIST =
  321. L"Microsoft_NtFrsConnectionStatus.CompositeGUID=\"";
  322. ODS(L"In IWbemServices::GetObjectAsync()\n");
  323. //
  324. // First check whether the given path matches the summary info
  325. // object path.
  326. //
  327. int rootlen = lstrlen(ROOTSTR_MEMBER);
  328. if (lstrlen(bstrObjectPath) > rootlen &&
  329. 0 == _wcsnicmp(bstrObjectPath, ROOTSTR_MEMBER, rootlen))
  330. {
  331. //
  332. // Extract the index/key by removing the prefix.
  333. //
  334. BSTR bstrIndexValue = SysAllocString(
  335. (const OLECHAR *)((BSTR)bstrObjectPath + rootlen));
  336. // remove trailing doublequote
  337. bstrIndexValue[lstrlen(bstrIndexValue)-1] = L'\0';
  338. hRes = EnumNtFrsMemberStatus(pCtx, pResponseHandler, bstrIndexValue );
  339. SysFreeString(bstrIndexValue);
  340. return hRes;
  341. }
  342. //
  343. // else : check for the inbound partner info object path.
  344. //
  345. rootlen = lstrlen(ROOTSTR_CONNECTION_LIST);
  346. if (lstrlen(bstrObjectPath) > rootlen &&
  347. 0 == _wcsnicmp(bstrObjectPath, ROOTSTR_CONNECTION_LIST, rootlen)
  348. )
  349. {
  350. // remove prefix
  351. BSTR bstrIndexValue = SysAllocString(
  352. (const OLECHAR *)((BSTR)bstrObjectPath + rootlen));
  353. // remove trailing doublequote
  354. bstrIndexValue[lstrlen(bstrIndexValue)-1] = L'\0';
  355. hRes = EnumNtFrsConnectionStatus( pCtx, pResponseHandler, bstrIndexValue );
  356. SysFreeString(bstrIndexValue);
  357. return hRes;
  358. }
  359. return WBEM_E_INVALID_OBJECT_PATH;
  360. */
  361. return WBEM_E_INVALID_OBJECT_PATH;
  362. }
  363. STDMETHODIMP CProvider::CreateInstanceEnumAsync(
  364. IN const BSTR bstrClass,
  365. IN long lFlags,
  366. IN IWbemContext *pCtx,
  367. IN IWbemObjectSink *pResponseHandler)
  368. /*++
  369. Routine Description:
  370. This method is called by WMI to enumerate all instances
  371. of a given class. All the instances are indicated to WMI
  372. using the pResponseHandler interface.
  373. Arguments:
  374. strObjectPath : [in] Name of the class whose instances are required.
  375. lFlags : [in] Flags which affect the behavior of this method.
  376. pCtx : [in] Typically NULL. Otherwise, this is a pointer to an IWbemContext
  377. object that may be used by the provider producing the requested class or
  378. instance.
  379. pResponseHandler :[in] Pointer to the caller's implementation of IWbemObjectSink.
  380. This handler receives the requested objects when it becomes available through the
  381. IWbemObjectSink::Indicate method.
  382. Return Value:
  383. Status of operation.
  384. --*/
  385. {
  386. // WBEM_VALIDATE_IN_STRING_PTR( bstrClass );
  387. // TODO : check lFlags?
  388. // WBEM_VALIDATE_INTF_PTR( pCtx );
  389. // WBEM_VALIDATE_INTF_PTR( pResponseHandler );
  390. ODS(L"In IWbemServices::CreateInstanceEnumAsync().\n");
  391. if ( 0 == lstrcmp( bstrClass, L"MicrosoftFrs_DfsMember"))
  392. {
  393. return EnumNtFrsMemberStatus(pCtx, pResponseHandler );
  394. }
  395. else if ( 0 == lstrcmp( bstrClass, L"MicrosoftFrs_DfsConnection") )
  396. {
  397. return EnumNtFrsConnectionStatus( pCtx, pResponseHandler );
  398. }
  399. return WBEM_E_INVALID_OBJECT_PATH;
  400. }
  401. HRESULT CProvider::EnumNtFrsMemberStatus(
  402. IN IWbemContext *pCtx,
  403. IN IWbemObjectSink *pResponseHandler,
  404. IN const BSTR bstrFilterValue
  405. )
  406. /*++
  407. Routine Description:
  408. Enumerates all instances of the Microsoft_NtFrsMemberStatus
  409. class. Instances are indicated using the pResponseHandler
  410. interface.
  411. Arguments:
  412. pCtx : [in] Typically NULL. Otherwise, this is a pointer to an IWbemContext
  413. object that may be used by the provider producing the requested class or
  414. instance.
  415. pResponseHandler : [in] Pointer to the caller's implementation of IWbemObjectSink.
  416. This handler receives the requested objects when it becomes available through the
  417. IWbemObjectSink::Indicate method.
  418. bstrFilterValue : [in] A filter which limits the returned instances to
  419. a subset of the actual instances. If NULL, all instances are returned.
  420. Return Value:
  421. Status of operation.
  422. --*/
  423. {
  424. #undef DEBSUB
  425. #define DEBSUB "CProvider::EnumNtFrsMemberStatus:"
  426. IWbemClassObject *pInstance;
  427. PVOID Key;
  428. PREPLICA Replica;
  429. VARIANT var;
  430. WCHAR GuidWStr[GUID_CHAR_LEN + 1];
  431. PWCHAR TempStr = NULL;
  432. // WBEM_VALIDATE_INTF_PTR( pCtx );
  433. // WBEM_VALIDATE_INTF_PTR( pResponseHandler );
  434. // WBEM_VALIDATE_IN_STRING_PTR_OPTIONAL( bstrFilterValue );
  435. HRESULT hRes = WBEM_S_NO_ERROR;
  436. ODS(L"Enumerating instances.\n");
  437. Key = NULL;
  438. while (Replica = (PREPLICA)GTabNextDatum(ReplicasByGuid, &Key)) {
  439. //
  440. // Spawn an instance of the Microsoft_NtFrsMemberStatus object.
  441. //
  442. if (Replica->ReplicaSetType != FRS_RSTYPE_DOMAIN_SYSVOL) {
  443. m_ipMicrosoftFrs_DfsMemberClassDef->SpawnInstance(0, &pInstance);
  444. } else {
  445. continue;
  446. }
  447. //
  448. // TODO : Fill in the members of this object.
  449. //
  450. // String ReplicaSetGUID;
  451. //
  452. // String ReplicaSetName;
  453. // String ReplicaMemberRoot;
  454. // String ReplicaMemberStage;
  455. // String FileFilter;
  456. // String DirFilter;
  457. // String ReplicaMemberState;
  458. // String ReplicaSetType;
  459. //String ReplicaSetGUID;
  460. /*
  461. V_VT(&var) = VT_BSTR;
  462. GuidToStrW(Replica->ReplicaName->Guid, GuidWStr);
  463. V_BSTR(&var) = SysAllocString(GuidWStr);
  464. hRes = pInstance->Put( L"ReplicaSetGUID", 0, &var, 0 );
  465. VariantClear(&var);
  466. if(hRes != WBEM_S_NO_ERROR)
  467. break;
  468. //String ReplicaSetName;
  469. V_VT(&var) = VT_BSTR;
  470. V_BSTR(&var) = SysAllocString(Replica->ReplicaName->Name);
  471. hRes = pInstance->Put( L"ReplicaSetName", 0, &var, 0 );
  472. VariantClear(&var);
  473. if(hRes != WBEM_S_NO_ERROR)
  474. break;
  475. //String ReplicaMemberRoot;
  476. V_VT(&var) = VT_BSTR;
  477. V_BSTR(&var) = SysAllocString(Replica->Root);
  478. hRes = pInstance->Put( L"ReplicaMemberRoot", 0, &var, 0 );
  479. VariantClear(&var);
  480. if(hRes != WBEM_S_NO_ERROR)
  481. break;
  482. //String ReplicaMemberStage;
  483. V_VT(&var) = VT_BSTR;
  484. V_BSTR(&var) = SysAllocString(Replica->Stage);
  485. hRes = pInstance->Put( L"ReplicaMemberStage", 0, &var, 0 );
  486. VariantClear(&var);
  487. if(hRes != WBEM_S_NO_ERROR)
  488. break;
  489. //String FileFilter;
  490. V_VT(&var) = VT_BSTR;
  491. V_BSTR(&var) = SysAllocString(Replica->FileFilterList);
  492. hRes = pInstance->Put( L"FileFilter", 0, &var, 0 );
  493. VariantClear(&var);
  494. if(hRes != WBEM_S_NO_ERROR)
  495. break;
  496. //String DirFilter;
  497. V_VT(&var) = VT_BSTR;
  498. V_BSTR(&var) = SysAllocString(Replica->DirFilterList);
  499. hRes = pInstance->Put( L"DirFilter", 0, &var, 0 );
  500. VariantClear(&var);
  501. if(hRes != WBEM_S_NO_ERROR)
  502. break;
  503. //String ReplicaMemberState;
  504. V_VT(&var) = VT_BSTR;
  505. TempStr = (PWCHAR)FrsAlloc((strlen(RSS_NAME(Replica->ServiceState)) + 1) * sizeof(WCHAR));
  506. wsprintf(TempStr, L"%hs", RSS_NAME(Replica->ServiceState));
  507. V_BSTR(&var) = SysAllocString(TempStr);
  508. hRes = pInstance->Put( L"ReplicaMemberState", 0, &var, 0 );
  509. TempStr = (PWCHAR)FrsFree(TempStr);
  510. VariantClear(&var);
  511. if(hRes != WBEM_S_NO_ERROR)
  512. break;
  513. //String ReplicaSetType;
  514. V_VT(&var) = VT_BSTR;
  515. V_BSTR(&var) = SysAllocString(FRS_RSTYPE_IS_SYSVOL(Replica->ReplicaSetType)?
  516. L"SYSVOL" : L"DFS");
  517. hRes = pInstance->Put( L"ReplicaSetType", 0, &var, 0 );
  518. VariantClear(&var);
  519. if(hRes != WBEM_S_NO_ERROR)
  520. break;
  521. // Default values for other fields.
  522. */
  523. //
  524. // Send the result to WMI.
  525. //
  526. hRes = pResponseHandler->Indicate(1, &pInstance);
  527. if(hRes != WBEM_S_NO_ERROR)
  528. break;
  529. pInstance->Release();
  530. // TODO : Optimize this by storing all the return objects
  531. // in an array and then indicating all the objects to
  532. // WMI in 1 shot.
  533. }
  534. //
  535. // Indicate to WMI that we are done.
  536. //
  537. ODS(L"Completed instance enumeration. Setting status.\n");
  538. pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hRes, NULL, NULL);
  539. ODS(L"Finished setting status. Returning from EnumNtFrsMemberStatus()\n");
  540. return hRes;
  541. }
  542. HRESULT CProvider::EnumNtFrsConnectionStatus(
  543. IN IWbemContext *pCtx,
  544. IN IWbemObjectSink *pResponseHandler,
  545. IN const BSTR bstrFilterValue)
  546. /*++
  547. Routine Description:
  548. Enumerates all instances of the Microsoft_NtFrsConnectionStatus
  549. class. Instances are indicated using the pResponseHandler
  550. interface.
  551. Arguments:
  552. pCtx : [in] Typically NULL. Otherwise, this is a pointer to an IWbemContext
  553. object that may be used by the provider producing the requested class or
  554. instance.
  555. pResponseHandler : [in] Pointer to the caller's implementation of IWbemObjectSink.
  556. This handler receives the requested objects when it becomes available through the
  557. IWbemObjectSink::Indicate method.
  558. bstrFilterValue : [in] A filter which limits the returned instances to
  559. a subset of the actual instances. If NULL, all instances are returned.
  560. Return Value:
  561. Status of operation.
  562. --*/
  563. {
  564. #undef DEBSUB
  565. #define DEBSUB "CProvider::EnumNtFrsConnectionStatus:"
  566. IWbemClassObject *pInstance;
  567. PVOID Key1;
  568. PVOID Key2;
  569. PREPLICA Replica;
  570. PCXTION Cxtion;
  571. VARIANT var;
  572. WCHAR GuidWStr[GUID_CHAR_LEN + 1];
  573. CHAR TimeStr[TIME_STRING_LENGTH];
  574. PWCHAR TempStr = NULL;
  575. HRESULT hRes = WBEM_S_NO_ERROR;
  576. Key1 = NULL;
  577. while (Replica = (PREPLICA)GTabNextDatum(ReplicasByGuid, &Key1)) {
  578. if (Replica->Cxtions == NULL) {
  579. continue;
  580. }
  581. if (Replica->ReplicaSetType == FRS_RSTYPE_DOMAIN_SYSVOL) {
  582. continue;
  583. }
  584. Key2 = NULL;
  585. while (Cxtion = (PCXTION)GTabNextDatum(Replica->Cxtions, &Key2)) {
  586. if (Cxtion->JrnlCxtion == TRUE) {
  587. continue;
  588. }
  589. //
  590. // Spawn an instance of the Microsoft_NtFrsConnectionStatus object.
  591. //
  592. m_ipMicrosoftFrs_DfsConnectionClassDef->SpawnInstance(0, &pInstance);
  593. //
  594. // TODO : Fill in the members of this object.
  595. //
  596. // String ReplicaSetGUID;
  597. // String PartnerGUID;
  598. //
  599. // String ConnectionName;
  600. // String ConnectionGUID;
  601. // String PartnerDnsName;
  602. // String ConnectionState;
  603. // DATETIME LastJoinTime;
  604. // boolean Inbound;
  605. //
  606. // String OBPartnerState;
  607. // uint32 OBPartnerLeadIndex
  608. // uint32 OBPartnerTrailIndex
  609. // uint32 OBPartnerOutstandingCOs
  610. // uint32 OBPartnerOutstandingQuota
  611. /*
  612. //String ReplicaSetGUID;
  613. if (Replica->ReplicaName != NULL) {
  614. V_VT(&var) = VT_BSTR;
  615. GuidToStrW(Replica->ReplicaName->Guid, GuidWStr);
  616. V_BSTR(&var) = SysAllocString(GuidWStr);
  617. hRes = pInstance->Put( L"ReplicaSetGUID", 0, &var, 0 );
  618. VariantClear(&var);
  619. if(hRes != WBEM_S_NO_ERROR)
  620. break;
  621. }
  622. //String PartnerGUID;
  623. if (Cxtion->Partner != NULL) {
  624. V_VT(&var) = VT_BSTR;
  625. GuidToStrW(Cxtion->Partner->Guid, GuidWStr);
  626. V_BSTR(&var) = SysAllocString(GuidWStr);
  627. hRes = pInstance->Put( L"PartnerGUID", 0, &var, 0 );
  628. VariantClear(&var);
  629. if(hRes != WBEM_S_NO_ERROR)
  630. break;
  631. }
  632. //String ConnectionName;
  633. if (Cxtion->Name != NULL) {
  634. V_VT(&var) = VT_BSTR;
  635. V_BSTR(&var) = SysAllocString(Cxtion->Name->Name);
  636. hRes = pInstance->Put( L"ConnectionName", 0, &var, 0 );
  637. VariantClear(&var);
  638. if(hRes != WBEM_S_NO_ERROR)
  639. break;
  640. //String ConnectionGUID;
  641. V_VT(&var) = VT_BSTR;
  642. GuidToStrW(Cxtion->Name->Guid, GuidWStr);
  643. V_BSTR(&var) = SysAllocString(GuidWStr);
  644. hRes = pInstance->Put( L"ConnectionGUID", 0, &var, 0 );
  645. VariantClear(&var);
  646. if(hRes != WBEM_S_NO_ERROR)
  647. break;
  648. }
  649. //String PartnerDnsName;
  650. V_VT(&var) = VT_BSTR;
  651. V_BSTR(&var) = SysAllocString(Cxtion->PartnerDnsName);
  652. hRes = pInstance->Put( L"PartnerDnsName", 0, &var, 0 );
  653. VariantClear(&var);
  654. if(hRes != WBEM_S_NO_ERROR)
  655. break;
  656. //String ConnectionState;
  657. V_VT(&var) = VT_BSTR;
  658. TempStr = (PWCHAR)FrsAlloc((strlen(CxtionStateNames[Cxtion->State]) + 1) * sizeof(WCHAR));
  659. wsprintf(TempStr, L"%hs", CxtionStateNames[Cxtion->State]);
  660. V_BSTR(&var) = SysAllocString(TempStr);
  661. hRes = pInstance->Put( L"ConnectionState", 0, &var, 0 );
  662. TempStr = (PWCHAR)FrsFree(TempStr);
  663. VariantClear(&var);
  664. if(hRes != WBEM_S_NO_ERROR)
  665. break;
  666. //String LastJoinTime;
  667. V_VT(&var) = VT_BSTR;
  668. FileTimeToString((PFILETIME) &Cxtion->LastJoinTime, TimeStr);
  669. TempStr = (PWCHAR)FrsAlloc((strlen(TimeStr) + 1) * sizeof(WCHAR));
  670. wsprintf(TempStr, L"%hs", TimeStr);
  671. V_BSTR(&var) = SysAllocString(TempStr);
  672. hRes = pInstance->Put( L"LastJoinTime", 0, &var, 0 );
  673. TempStr = (PWCHAR)FrsFree(TempStr);
  674. VariantClear(&var);
  675. if(hRes != WBEM_S_NO_ERROR) {
  676. break;
  677. }
  678. //boolean Inbound;
  679. V_VT(&var) = VT_BOOL;
  680. V_BOOL(&var) = (Cxtion->Inbound)? VARIANT_TRUE : VARIANT_FALSE ;
  681. hRes = pInstance->Put( L"Inbound", 0, &var, 0 );
  682. VariantClear(&var);
  683. if(hRes != WBEM_S_NO_ERROR)
  684. break;
  685. if (Cxtion->Inbound == FALSE && Cxtion->OLCtx != NULL) {
  686. //String OBPartnerState;
  687. V_VT(&var) = VT_BSTR;
  688. TempStr = (PWCHAR)FrsAlloc((strlen(OLPartnerStateNames[Cxtion->OLCtx->State]) + 1) * sizeof(WCHAR));
  689. wsprintf(TempStr, L"%hs", OLPartnerStateNames[Cxtion->OLCtx->State]);
  690. V_BSTR(&var) = SysAllocString(TempStr);
  691. hRes = pInstance->Put( L"OBPartnerState", 0, &var, 0 );
  692. TempStr = (PWCHAR)FrsFree(TempStr);
  693. VariantClear(&var);
  694. if(hRes != WBEM_S_NO_ERROR)
  695. break;
  696. //uint32 OBPartnerleadIndex;
  697. V_VT(&var) = VT_I4;
  698. V_I4(&var) = Cxtion->OLCtx->COLx;
  699. hRes = pInstance->Put( L"OBPartnerLeadIndex", 0, &var, 0 );
  700. VariantClear(&var);
  701. if(hRes != WBEM_S_NO_ERROR)
  702. break;
  703. //uint32 OBPartnerTrailIndex;
  704. V_VT(&var) = VT_I4;
  705. V_I4(&var) = Cxtion->OLCtx->COTx;
  706. hRes = pInstance->Put( L"OBPartnerTrailIndex", 0, &var, 0 );
  707. VariantClear(&var);
  708. if(hRes != WBEM_S_NO_ERROR)
  709. break;
  710. //uint32 OBPartnerOutstandingCOs;
  711. V_VT(&var) = VT_I4;
  712. V_I4(&var) = Cxtion->OLCtx->OutstandingCos;
  713. hRes = pInstance->Put( L"OBPartnerOutstandingCOs", 0, &var, 0 );
  714. VariantClear(&var);
  715. if(hRes != WBEM_S_NO_ERROR)
  716. break;
  717. //uint32 OBPartnerOutstandingQuota;
  718. V_VT(&var) = VT_I4;
  719. V_I4(&var) = Cxtion->OLCtx->OutstandingQuota;
  720. hRes = pInstance->Put( L"OBPartnerOutstandingQuota", 0, &var, 0 );
  721. VariantClear(&var);
  722. if(hRes != WBEM_S_NO_ERROR)
  723. break;
  724. }
  725. */
  726. //
  727. // Send the result to WMI.
  728. //
  729. hRes = pResponseHandler->Indicate(1, &pInstance);
  730. if(hRes != WBEM_S_NO_ERROR)
  731. break;
  732. pInstance->Release();
  733. }
  734. }
  735. //
  736. // Indicate to WMI that we are done.
  737. //
  738. ODS(L"Completed instance enumeration. Setting status.\n");
  739. pResponseHandler->SetStatus(WBEM_STATUS_COMPLETE, hRes, NULL, NULL);
  740. ODS(L"Finished setting status. Returning from EnumNtFrsMemberStatus()\n");
  741. return hRes;
  742. }
  743. //
  744. // IWbemEventProvider interface
  745. //
  746. STDMETHODIMP CProvider::ProvideEvents(
  747. IWbemObjectSink __RPC_FAR *pSink,
  748. long lFlags )
  749. {
  750. ODS(L"IwbemEventProvider::ProvideEvents() called.\n");
  751. pSink->AddRef();
  752. m_pEventSink = pSink;
  753. return WBEM_S_NO_ERROR;
  754. }
  755. //
  756. // TODO : TO send events to the collector, construct an instance of
  757. // the required class and then call CProvider::m_pEventSink->Indicate();
  758. //
  759. // Note that the any objects sent as an event must be derived from
  760. // the class __ExtrinsicEvent.
  761. //