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.

765 lines
22 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. enum.cpp
  5. Abstract:
  6. Enumerates metabase tree.
  7. Author:
  8. ???
  9. Revision History:
  10. Mohit Srivastava 18-Dec-00
  11. --*/
  12. #include "iisprov.h"
  13. #include "enum.h"
  14. #include "ipsecurity.h"
  15. #include "adminacl.h"
  16. #include "WbemObjectSink.h"
  17. #include "instancehelper.h"
  18. #include "SmartPointer.h"
  19. #include <adserr.h>
  20. extern CDynSchema* g_pDynSch;
  21. ///////////////////////////////////////
  22. //
  23. // CEnum class
  24. //
  25. ///////////////////////////////////////
  26. CEnum::CEnum()
  27. {
  28. m_pInstMgr = NULL;
  29. m_pNamespace = NULL;
  30. m_pAssociation = NULL;
  31. m_pParsedObject = NULL;
  32. m_hKey = NULL;
  33. }
  34. CEnum::~CEnum()
  35. {
  36. if(m_hKey)
  37. m_metabase.CloseKey(m_hKey);
  38. delete m_pInstMgr;
  39. }
  40. void CEnum::Init(
  41. IWbemObjectSink FAR* a_pHandler,
  42. CWbemServices* a_pNamespace,
  43. ParsedObjectPath* a_pParsedObject,
  44. LPWSTR a_pszKey,
  45. WMI_ASSOCIATION* a_pAssociation,
  46. SQL_LEVEL_1_RPN_EXPRESSION_EXT* a_pExp) // default(NULL)
  47. {
  48. if (!a_pHandler || !a_pNamespace || !a_pParsedObject)
  49. throw WBEM_E_FAILED;
  50. m_pInstMgr = new CWbemObjectSink(a_pHandler);
  51. if(!m_pInstMgr)
  52. {
  53. THROW_ON_ERROR(WBEM_E_OUT_OF_MEMORY);
  54. }
  55. m_pNamespace = a_pNamespace;
  56. m_pAssociation = a_pAssociation;
  57. m_pParsedObject = a_pParsedObject;
  58. m_pExp = a_pExp;
  59. m_hKey = m_metabase.OpenKey(a_pszKey, false); // read only
  60. }
  61. void CEnum::SetObjectPath(
  62. LPCWSTR a_pszPropertyName,
  63. LPCWSTR a_pszObjectPath,
  64. IWbemClassObject* a_pObj
  65. )
  66. {
  67. _bstr_t bstr(a_pszPropertyName);
  68. _variant_t v(a_pszObjectPath);
  69. HRESULT hr = a_pObj->Put(bstr, 0, &v, 0);
  70. THROW_ON_ERROR(hr);
  71. }
  72. void CEnum::PingObject()
  73. {
  74. CComPtr<IWbemClassObject> spObj;
  75. CInstanceHelper InstanceHelper(m_pParsedObject, m_pNamespace);
  76. DBG_ASSERT(!InstanceHelper.IsAssoc());
  77. try
  78. {
  79. InstanceHelper.GetInstance(false, &m_metabase, &spObj, m_pExp);
  80. }
  81. catch(HRESULT hr)
  82. {
  83. if(hr != E_ADS_PROPERTY_NOT_SUPPORTED && hr != WBEM_E_NOT_FOUND)
  84. {
  85. throw;
  86. }
  87. }
  88. if(spObj != NULL)
  89. {
  90. m_pInstMgr->Indicate(spObj);
  91. }
  92. }
  93. void CEnum::PingAssociation(
  94. LPCWSTR a_pszLeftKeyPath
  95. )
  96. {
  97. HRESULT hr;
  98. CComPtr<IWbemClassObject> spObj;
  99. CComPtr<IWbemClassObject> spClass;
  100. TSmartPointerArray<WCHAR> swszObjectPath;
  101. CObjectPathParser PathParser(e_ParserAcceptRelativeNamespace);
  102. if( m_pAssociation->pType != &WMI_ASSOCIATION_TYPE_DATA::s_ElementSetting &&
  103. m_pAssociation->pType != &WMI_ASSOCIATION_TYPE_DATA::s_Component )
  104. {
  105. return;
  106. }
  107. hr = m_pNamespace->GetObject(
  108. m_pAssociation->pszAssociationName,
  109. 0,
  110. NULL,
  111. &spClass,
  112. NULL
  113. );
  114. THROW_ON_ERROR(hr);
  115. hr = spClass->SpawnInstance(0, &spObj);
  116. THROW_ON_ERROR(hr);
  117. //
  118. // first right side
  119. //
  120. if (!m_pParsedObject->SetClassName(m_pAssociation->pcRight->pszClassName))
  121. throw WBEM_E_FAILED;
  122. if (PathParser.Unparse(m_pParsedObject,&swszObjectPath))
  123. throw WBEM_E_FAILED;
  124. SetObjectPath(m_pAssociation->pType->pszRight, swszObjectPath, spObj);
  125. swszObjectPath.Delete();
  126. //
  127. // then left side
  128. //
  129. if (m_pAssociation->pType == &WMI_ASSOCIATION_TYPE_DATA::s_Component)
  130. {
  131. // clear keyref first
  132. m_pParsedObject->ClearKeys();
  133. // add a keyref
  134. _variant_t vt;
  135. if(m_pAssociation->pcLeft->pkt == &METABASE_KEYTYPE_DATA::s_IIsComputer)
  136. vt = L"LM"; // IIsComputer.Name = "LM"
  137. else
  138. vt = a_pszLeftKeyPath;
  139. THROW_ON_FALSE(m_pParsedObject->AddKeyRef(m_pAssociation->pcLeft->pszKeyName,&vt));
  140. }
  141. if (!m_pParsedObject->SetClassName(m_pAssociation->pcLeft->pszClassName))
  142. throw WBEM_E_FAILED;
  143. if (PathParser.Unparse(m_pParsedObject,&swszObjectPath))
  144. throw WBEM_E_FAILED;
  145. SetObjectPath(m_pAssociation->pType->pszLeft, swszObjectPath, spObj);
  146. swszObjectPath.Delete();
  147. m_pInstMgr->Indicate(spObj);
  148. }
  149. void CEnum::DoPing(
  150. LPCWSTR a_pszKeyName,
  151. LPCWSTR a_pszKeyPath,
  152. LPCWSTR a_pszParentKeyPath
  153. )
  154. {
  155. // add keyref
  156. _variant_t v(a_pszKeyPath);
  157. THROW_ON_FALSE(m_pParsedObject->AddKeyRef(a_pszKeyName,&v));
  158. // ping
  159. if (!m_pAssociation)
  160. PingObject();
  161. else
  162. PingAssociation(a_pszParentKeyPath);
  163. // clear keyref
  164. m_pParsedObject->ClearKeys();
  165. }
  166. void CEnum::Recurse(
  167. LPCWSTR a_pszMetabasePath, // Current metabase location relative to m_hKey
  168. METABASE_KEYTYPE* a_pktParentKeyType,// Current keytype
  169. LPCWSTR a_pszLeftPath,
  170. LPCWSTR a_pszWmiPrimaryKey,// "Name" - WMI only - nothing to do with MB
  171. METABASE_KEYTYPE* a_pktSearch // the kt we are looking for
  172. )
  173. {
  174. DWORD i = 0;
  175. HRESULT hr;
  176. WCHAR szSubKey[METADATA_MAX_NAME_LEN];
  177. METABASE_KEYTYPE* pktCurrent;
  178. DBGPRINTF((DBG_CONTEXT, "Recurse (Path = %ws, Left = %ws)\n", a_pszMetabasePath, a_pszLeftPath));
  179. do
  180. {
  181. pktCurrent = a_pktSearch;
  182. //
  183. // Enumerate all subkeys of a_pszMetabasePath until we find a potential
  184. // (grand*)parent of pktCurrent
  185. //
  186. hr = m_metabase.EnumKeys(
  187. m_hKey,
  188. a_pszMetabasePath,
  189. szSubKey,
  190. &i,
  191. pktCurrent
  192. );
  193. i++;
  194. if( hr == ERROR_SUCCESS)
  195. {
  196. _bstr_t bstrMetabasePath;
  197. if(a_pszMetabasePath)
  198. {
  199. bstrMetabasePath = a_pszMetabasePath;
  200. bstrMetabasePath += L"/";
  201. }
  202. bstrMetabasePath += szSubKey;
  203. //
  204. // With the exception of AdminACL, AdminACE, IPSecurity, we will only
  205. // ping the object if we have found a keytype match in the metabase.
  206. //
  207. if( pktCurrent == a_pktSearch &&
  208. !( m_pAssociation &&
  209. m_pAssociation->pType == &WMI_ASSOCIATION_TYPE_DATA::s_Component &&
  210. m_pAssociation->pcLeft->pkt != a_pktParentKeyType
  211. )
  212. )
  213. {
  214. DoPing(a_pszWmiPrimaryKey, bstrMetabasePath, a_pszLeftPath);
  215. }
  216. else if( a_pktSearch == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL || // AdminACL
  217. a_pktSearch == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE
  218. )
  219. {
  220. if( (m_pAssociation == NULL || // should never be
  221. m_pAssociation->pType != &WMI_ASSOCIATION_TYPE_DATA::s_AdminACL ||
  222. m_pAssociation->pcLeft->pkt == pktCurrent ||
  223. m_pAssociation == &WMI_ASSOCIATION_DATA::s_AdminACLToACE) )
  224. {
  225. DoPingAdminACL(a_pktSearch, a_pszWmiPrimaryKey, bstrMetabasePath);
  226. }
  227. }
  228. else if( a_pktSearch == &METABASE_KEYTYPE_DATA::s_TYPE_IPSecurity ) // IPSecurity
  229. {
  230. if( !(m_pAssociation &&
  231. m_pAssociation->pType == &WMI_ASSOCIATION_TYPE_DATA::s_IPSecurity &&
  232. m_pAssociation->pcLeft->pkt != pktCurrent
  233. )
  234. )
  235. {
  236. DoPingIPSecurity(a_pktSearch, a_pszWmiPrimaryKey, bstrMetabasePath);
  237. }
  238. }
  239. // recusive
  240. if(ContinueRecurse(pktCurrent, a_pktSearch))
  241. {
  242. Recurse(
  243. bstrMetabasePath,
  244. pktCurrent,
  245. bstrMetabasePath,
  246. a_pszWmiPrimaryKey,
  247. a_pktSearch);
  248. }
  249. }
  250. }while(hr == ERROR_SUCCESS);
  251. DBGPRINTF((DBG_CONTEXT, "Recurse Exited\n"));
  252. }
  253. // DESC: You are looking for a_eKeyType by traversing thru the tree. You are
  254. // currently at a_eParentKeyType and need to determine if you should keep
  255. // on going.
  256. // COMM: This seems very similar to CMetabase::CheckKey
  257. bool CEnum::ContinueRecurse(
  258. METABASE_KEYTYPE* a_pktParentKeyType,
  259. METABASE_KEYTYPE* a_pktKeyType
  260. )
  261. {
  262. bool bRet = false;
  263. if( a_pktKeyType == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL ||
  264. a_pktKeyType == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE ||
  265. a_pktKeyType == &METABASE_KEYTYPE_DATA::s_TYPE_IPSecurity )
  266. {
  267. return true;
  268. }
  269. return g_pDynSch->IsContainedUnder(a_pktParentKeyType, a_pktKeyType);
  270. /*switch(a_pktKeyType)
  271. {
  272. case &METABASE_KEYTYPE_DATA::s_IIsLogModule:
  273. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsLogModules )
  274. bRet = true;
  275. break;
  276. case &METABASE_KEYTYPE_DATA::s_IIsFtpInfo:
  277. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpService )
  278. bRet = true;
  279. break;
  280. case &METABASE_KEYTYPE_DATA::s_IIsFtpServer:
  281. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpService )
  282. bRet = true;
  283. break;
  284. case &METABASE_KEYTYPE_DATA::s_IIsFtpVirtualDir:
  285. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpService ||
  286. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpServer ||
  287. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpVirtualDir
  288. )
  289. bRet = true;
  290. break;
  291. case &METABASE_KEYTYPE_DATA::s_IIsWebInfo:
  292. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService )
  293. bRet = true;
  294. break;
  295. case &METABASE_KEYTYPE_DATA::s_IIsFilters:
  296. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  297. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer
  298. )
  299. bRet = true;
  300. break;
  301. case &METABASE_KEYTYPE_DATA::s_IIsFilter:
  302. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  303. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  304. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFilters
  305. )
  306. bRet = true;
  307. break;
  308. case &METABASE_KEYTYPE_DATA::s_IIsCompressionSchemes:
  309. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  310. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  311. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFilters
  312. )
  313. bRet = true;
  314. break;
  315. case &METABASE_KEYTYPE_DATA::s_IIsCompressionScheme:
  316. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  317. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  318. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFilters ||
  319. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsCompressionSchemes )
  320. bRet = true;
  321. break;
  322. case &METABASE_KEYTYPE_DATA::s_IIsWebServer:
  323. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService )
  324. bRet = true;
  325. break;
  326. case &METABASE_KEYTYPE_DATA::s_IIsCertMapper:
  327. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  328. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer
  329. )
  330. bRet = true;
  331. break;
  332. case &METABASE_KEYTYPE_DATA::s_IIsWebVirtualDir:
  333. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  334. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  335. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebVirtualDir ||
  336. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebDirectory
  337. )
  338. bRet = true;
  339. break;
  340. case &METABASE_KEYTYPE_DATA::s_IIsWebDirectory:
  341. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  342. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  343. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebVirtualDir ||
  344. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebDirectory
  345. )
  346. bRet = true;
  347. break;
  348. case &METABASE_KEYTYPE_DATA::s_IIsWebFile:
  349. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  350. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  351. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebVirtualDir ||
  352. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebDirectory
  353. )
  354. bRet = true;
  355. break;
  356. case TYPE_AdminACL:
  357. case TYPE_AdminACE:
  358. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  359. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  360. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebVirtualDir ||
  361. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebDirectory ||
  362. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpService ||
  363. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpServer ||
  364. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpVirtualDir
  365. )
  366. bRet = true;
  367. break;
  368. case TYPE_IPSecurity:
  369. if( a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebService ||
  370. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebServer ||
  371. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebVirtualDir ||
  372. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsWebDirectory ||
  373. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpService ||
  374. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpServer ||
  375. a_pktParentKeyType == &METABASE_KEYTYPE_DATA::s_IIsFtpVirtualDir
  376. )
  377. bRet = true;
  378. break;
  379. default:
  380. break;
  381. }*/
  382. //return bRet;
  383. //return true;
  384. }
  385. void CEnum::DoPingAdminACL(
  386. METABASE_KEYTYPE* a_pktKeyType, // Search key
  387. LPCWSTR a_pszKeyName, // Wmi Primary key - nothing to do with MB
  388. LPCWSTR a_pszKeyPath // Current metabase path relative to m_hKey
  389. )
  390. {
  391. // add keyref
  392. _variant_t v(a_pszKeyPath);
  393. THROW_ON_FALSE(m_pParsedObject->AddKeyRef(a_pszKeyName,&v));
  394. if(a_pktKeyType == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACE)
  395. {
  396. EnumACE(a_pszKeyPath);
  397. }
  398. else if(a_pktKeyType == &METABASE_KEYTYPE_DATA::s_TYPE_AdminACL)
  399. {
  400. // ping
  401. if (!m_pAssociation)
  402. PingObject();
  403. else
  404. PingAssociationAdminACL(a_pszKeyPath);
  405. }
  406. // clear keyref
  407. m_pParsedObject->ClearKeys();
  408. }
  409. // for AdminACL
  410. void CEnum::EnumACE(
  411. LPCWSTR pszKeyPath
  412. )
  413. {
  414. HRESULT hr = S_OK;
  415. _variant_t var;
  416. CComPtr<IEnumVARIANT> spEnum;
  417. ULONG lFetch;
  418. CComBSTR bstrTrustee;
  419. IDispatch* pDisp = NULL;
  420. CComPtr<IADsAccessControlEntry> spACE;
  421. _bstr_t bstrMbPath;
  422. WMI_CLASS* pWMIClass;
  423. // get the metabase path of the object
  424. BOOL fClass = FALSE;
  425. if(m_pAssociation)
  426. fClass = CUtils::GetClass(m_pAssociation->pcLeft->pszClassName,&pWMIClass);
  427. else
  428. fClass = CUtils::GetClass(m_pParsedObject->m_pClass,&pWMIClass);
  429. if(!fClass)
  430. return;
  431. CUtils::GetMetabasePath(NULL,m_pParsedObject,pWMIClass,bstrMbPath);
  432. // open ADSI
  433. CAdminACL objACL;
  434. hr = objACL.OpenSD(bstrMbPath, m_metabase);
  435. if(SUCCEEDED(hr))
  436. hr = objACL.GetACEEnum(&spEnum);
  437. if ( FAILED(hr) )
  438. return;
  439. //////////////////////////////////////////////
  440. // Enumerate ACEs
  441. //////////////////////////////////////////////
  442. hr = spEnum->Next( 1, &var, &lFetch );
  443. while( hr == S_OK )
  444. {
  445. if ( lFetch == 1 )
  446. {
  447. if ( VT_DISPATCH != V_VT(&var) )
  448. {
  449. break;
  450. }
  451. pDisp = V_DISPATCH(&var);
  452. /////////////////////////////
  453. // Get the individual ACE
  454. /////////////////////////////
  455. hr = pDisp->QueryInterface(
  456. IID_IADsAccessControlEntry,
  457. (void**)&spACE
  458. );
  459. if ( SUCCEEDED(hr) )
  460. {
  461. hr = spACE->get_Trustee(&bstrTrustee);
  462. if( SUCCEEDED(hr) )
  463. {
  464. // add keyref
  465. _variant_t v(bstrTrustee);
  466. //m_pParsedObject->RemoveKeyRef(L"Trustee");
  467. THROW_ON_FALSE(m_pParsedObject->AddKeyRefEx(L"Trustee",&v));
  468. // ping
  469. if (!m_pAssociation)
  470. PingObject();
  471. else
  472. PingAssociationAdminACL(pszKeyPath);
  473. }
  474. bstrTrustee = (LPWSTR)NULL;
  475. spACE = NULL;
  476. }
  477. }
  478. hr = spEnum->Next( 1, &var, &lFetch );
  479. }
  480. }
  481. void CEnum::PingAssociationAdminACL(
  482. LPCWSTR a_pszLeftKeyPath
  483. )
  484. {
  485. HRESULT hr;
  486. CComPtr<IWbemClassObject> spObj;
  487. CComPtr<IWbemClassObject> spClass;
  488. TSmartPointerArray<WCHAR> swszObjectPath;
  489. CObjectPathParser PathParser(e_ParserAcceptRelativeNamespace);
  490. _bstr_t bstrMbPath;
  491. WMI_CLASS* pWMIClass;
  492. if(m_pAssociation->pType != &WMI_ASSOCIATION_TYPE_DATA::s_AdminACL)
  493. {
  494. return;
  495. }
  496. // get the metabase path of the object
  497. if (CUtils::GetClass(m_pAssociation->pcLeft->pszClassName,&pWMIClass))
  498. {
  499. CUtils::GetMetabasePath(NULL,m_pParsedObject,pWMIClass,bstrMbPath);
  500. }
  501. else
  502. {
  503. return;
  504. }
  505. // check if AdminACL existed
  506. CAdminACL objACL;
  507. hr = objACL.OpenSD(bstrMbPath, m_metabase);
  508. objACL.CloseSD();
  509. if(FAILED(hr))
  510. {
  511. return;
  512. }
  513. hr = m_pNamespace->GetObject(
  514. m_pAssociation->pszAssociationName,
  515. 0,
  516. NULL,
  517. &spClass,
  518. NULL
  519. );
  520. THROW_ON_ERROR(hr);
  521. hr = spClass->SpawnInstance(0, &spObj);
  522. THROW_ON_ERROR(hr);
  523. //
  524. // first right side
  525. //
  526. if (!m_pParsedObject->SetClassName(m_pAssociation->pcRight->pszClassName))
  527. {
  528. throw WBEM_E_FAILED;
  529. }
  530. if (PathParser.Unparse(m_pParsedObject,&swszObjectPath))
  531. {
  532. throw WBEM_E_FAILED;
  533. }
  534. SetObjectPath(m_pAssociation->pType->pszRight, swszObjectPath, spObj);
  535. swszObjectPath.Delete();
  536. //
  537. // then left side
  538. //
  539. if(m_pAssociation == &WMI_ASSOCIATION_DATA::s_AdminACLToACE)
  540. {
  541. // clear keyref first
  542. m_pParsedObject->ClearKeys();
  543. // add a keyref
  544. _variant_t vt = a_pszLeftKeyPath;
  545. THROW_ON_FALSE(m_pParsedObject->AddKeyRef(m_pAssociation->pcLeft->pszKeyName,&vt));
  546. }
  547. if (!m_pParsedObject->SetClassName(m_pAssociation->pcLeft->pszClassName))
  548. {
  549. throw WBEM_E_FAILED;
  550. }
  551. if (PathParser.Unparse(m_pParsedObject,&swszObjectPath))
  552. {
  553. throw WBEM_E_FAILED;
  554. }
  555. SetObjectPath(m_pAssociation->pType->pszLeft, swszObjectPath, spObj);
  556. swszObjectPath.Delete();
  557. m_pInstMgr->Indicate(spObj);
  558. }
  559. // for IPSecurity
  560. void CEnum::DoPingIPSecurity(
  561. METABASE_KEYTYPE* a_pktKeyType,
  562. LPCWSTR a_pszKeyName,
  563. LPCWSTR a_pszKeyPath
  564. )
  565. {
  566. // add keyref
  567. _variant_t v(a_pszKeyPath);
  568. THROW_ON_FALSE(m_pParsedObject->AddKeyRef(a_pszKeyName,&v));
  569. // ping
  570. if (!m_pAssociation)
  571. PingObject();
  572. else
  573. PingAssociationIPSecurity(a_pszKeyPath);
  574. // clear keyref
  575. m_pParsedObject->ClearKeys();
  576. }
  577. // for IPSecurity
  578. void CEnum::PingAssociationIPSecurity(
  579. LPCWSTR a_pszLeftKeyPath
  580. )
  581. {
  582. HRESULT hr;
  583. CComPtr<IWbemClassObject> spObj;
  584. CComPtr<IWbemClassObject> spClass;
  585. TSmartPointerArray<WCHAR> swszObjectPath;
  586. CObjectPathParser PathParser(e_ParserAcceptRelativeNamespace);
  587. _bstr_t bstrMbPath;
  588. WMI_CLASS* pWMIClass;
  589. if(m_pAssociation->pType != &WMI_ASSOCIATION_TYPE_DATA::s_IPSecurity)
  590. return;
  591. // get the metabase path of the object
  592. if (CUtils::GetClass(m_pAssociation->pcLeft->pszClassName,&pWMIClass))
  593. {
  594. CUtils::GetMetabasePath(NULL,m_pParsedObject,pWMIClass,bstrMbPath);
  595. }
  596. else
  597. return;
  598. // check if IPSecurity existed
  599. CIPSecurity objIPsec;
  600. hr = objIPsec.OpenSD(bstrMbPath, m_metabase);
  601. objIPsec.CloseSD();
  602. if(FAILED(hr))
  603. return;
  604. hr = m_pNamespace->GetObject(
  605. m_pAssociation->pszAssociationName,
  606. 0,
  607. NULL,
  608. &spClass,
  609. NULL
  610. );
  611. THROW_ON_ERROR(hr);
  612. hr = spClass->SpawnInstance(0, &spObj);
  613. THROW_ON_ERROR(hr);
  614. //
  615. // first right side
  616. //
  617. if (!m_pParsedObject->SetClassName(m_pAssociation->pcRight->pszClassName))
  618. throw WBEM_E_FAILED;
  619. if (PathParser.Unparse(m_pParsedObject,&swszObjectPath))
  620. {
  621. throw WBEM_E_FAILED;
  622. }
  623. SetObjectPath(m_pAssociation->pType->pszRight, swszObjectPath, spObj);
  624. swszObjectPath.Delete();
  625. //
  626. // then left side
  627. //
  628. if (!m_pParsedObject->SetClassName(m_pAssociation->pcLeft->pszClassName))
  629. throw WBEM_E_FAILED;
  630. if (PathParser.Unparse(m_pParsedObject,&swszObjectPath))
  631. throw WBEM_E_FAILED;
  632. SetObjectPath(m_pAssociation->pType->pszLeft, swszObjectPath, spObj);
  633. swszObjectPath.Delete();
  634. m_pInstMgr->Indicate(spObj);
  635. }