Source code of Windows XP (NT5)
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.

4794 lines
144 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // Microsoft WMIOLE DB Provider
  3. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // CWBEMWRAP.CPP | CWbem* class implementation. These are classes talking to WMI
  6. //
  7. // NTRaid:: 139685 Transaction support removed
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #define _WIN32_DCOM
  10. #include "headers.h"
  11. //#include <wbemprov.h>
  12. #define CLASSSEPARATOR L"."
  13. #define WBEMERROR_QUALIFIER_NOT_FOUND 0x80043000
  14. #define WBEMERROR_PROPERTY_NOT_FOUND 0x80043001
  15. #define WBEMERROR_QUALIFER_TOBE_FETCHED 0x80043001
  16. #define NUMBEROFINSTANCESTOBEFETCHED 50
  17. #define LOCALESTRING_MAXSIZE 40
  18. #define SEARCHPREFERENCE_NAMESIZE 128
  19. const WCHAR szSelectCountQry[] = L"select __PATH from ";
  20. const WCHAR szWhereClause[] = L" WHERE __CLASS=\"";
  21. const WCHAR szDoubleQuotes[] = L"\"";
  22. const WCHAR szReferenceOfQry[] = L"REFERENCES";
  23. const WCHAR szAssociatersQry[] = L"ASSOCIATORS";
  24. const WCHAR szWQL[] = L"WQL";
  25. const WCHAR szLDAP[] = L"LDAP";
  26. const WCHAR szLDAPSQL[] = L"SQL";
  27. const WCHAR szInstance[] = L"WMIInstance";
  28. const WCHAR szCollection[] = L"Collection";
  29. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  30. BOOL AllocateAndCopy( WCHAR *& pwcsDestination, WCHAR * pwcsSource )
  31. {
  32. BOOL fRc = FALSE;
  33. if( wcslen( pwcsSource ) > 0){
  34. pwcsDestination = new WCHAR[wcslen(pwcsSource)+2];
  35. wcscpy(pwcsDestination,pwcsSource);
  36. fRc = TRUE;
  37. }
  38. return fRc;
  39. }
  40. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. HRESULT MapWbemErrorToOLEDBError(HRESULT hrToMap)
  42. {
  43. HRESULT hr = E_FAIL;
  44. switch( hrToMap ){
  45. case WBEM_S_NO_MORE_DATA:
  46. hr = WBEM_S_NO_MORE_DATA;
  47. break;
  48. case S_OK:
  49. hr = S_OK;
  50. break;
  51. case WBEM_E_ACCESS_DENIED :
  52. hr = DB_SEC_E_PERMISSIONDENIED;
  53. LogMessage("Access denied to do this operation" , hr);
  54. break;
  55. case WBEM_E_CANNOT_BE_KEY:
  56. hr = DB_E_ERRORSOCCURRED;
  57. LogMessage("Error in setting a property as Key" , hr);
  58. break;
  59. case WBEM_E_NOT_FOUND :
  60. hr = E_UNEXPECTED;
  61. LogMessage("Object not found" , hr);
  62. break;
  63. case WBEM_E_INVALID_CLASS :
  64. hr = DB_E_NOTABLE;
  65. LogMessage("The class specified is not present" , hr);
  66. break;
  67. case WBEMERROR_PROPERTY_NOT_FOUND :
  68. hr = DB_E_BADCOLUMNID;
  69. LogMessage("Object not found" , hr);
  70. break;
  71. case WBEM_E_INVALID_OPERATION :
  72. hr = DB_E_DROPRESTRICTED;
  73. LogMessage("Provider not able to drop do the operation as the operation is invalid" , hr);
  74. break;
  75. case WBEMERROR_QUALIFIER_NOT_FOUND :
  76. hr = DB_E_BADCOLUMNID;
  77. LogMessage("Qualifier does not exist" , hr);
  78. break;
  79. case WBEM_E_PROPAGATED_PROPERTY :
  80. hr = DB_E_DROPRESTRICTED;
  81. LogMessage("Error due to attempt to delete a property that was not owned" , hr);
  82. break;
  83. case WBEM_E_INVALID_NAMESPACE:
  84. hr = DB_E_ERRORSOCCURRED;
  85. LogMessage("Invalid Namespace" , hr);
  86. break;
  87. case E_ACCESSDENIED:
  88. hr = DB_SEC_E_PERMISSIONDENIED;
  89. LogMessage("Acess Denied" , hr);
  90. break;
  91. case WBEM_E_INVALID_QUERY:
  92. hr = DB_E_ERRORSINCOMMAND;
  93. LogMessage("Error in the query string" , hr);
  94. break;
  95. case WBEM_E_PROVIDER_NOT_CAPABLE:
  96. hr = WBEM_E_PROVIDER_NOT_CAPABLE;
  97. break;
  98. case DB_E_ALREADYINITIALIZED:
  99. hr = DB_E_ALREADYINITIALIZED;
  100. break;
  101. case WBEM_E_OUT_OF_MEMORY:
  102. case E_OUTOFMEMORY:
  103. hr = E_OUTOFMEMORY;
  104. break;
  105. //NTRaid 138547
  106. case WBEM_E_LOCAL_CREDENTIALS:
  107. hr = DB_E_ERRORSOCCURRED;
  108. LogMessage("User Name and password cannot be given for local machine" , hr);
  109. break;
  110. // NTRaid:144995
  111. case WBEM_E_TRANSPORT_FAILURE:
  112. case HRESULT_FROM_WIN32(RPC_S_CALL_FAILED_DNE):
  113. case HRESULT_FROM_WIN32(RPC_S_CALL_FAILED):
  114. case HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE):
  115. hr = E_FAIL;
  116. LogMessage("Connection broken due to RPC failure" , hr);
  117. break;
  118. case WBEM_E_INVALID_QUERY_TYPE:
  119. hr = DB_E_ERRORSINCOMMAND;
  120. LogMessage("Invalid Query Type" , hr);
  121. break;
  122. case S_FALSE:
  123. hr = S_FALSE;
  124. break;
  125. default:
  126. hr = E_UNEXPECTED;
  127. }
  128. return hr;
  129. }
  130. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  131. CWbemConnectionWrapper::CWbemConnectionWrapper()
  132. {
  133. // HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
  134. // CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, 0 );
  135. InitVars();
  136. }
  137. HRESULT CWbemConnectionWrapper::FInit(CWbemConnectionWrapper *pWrap , WCHAR *pstrPath,INSTANCELISTTYPE instListType )
  138. {
  139. HRESULT hr = S_OK;
  140. InitVars();
  141. CBSTR strPath(pstrPath);
  142. IWbemServicesEx *pSerEx = NULL;
  143. LONG lFlag = instListType == SCOPE ? WBEM_FLAG_OPEN_SCOPE : WBEM_FLAG_OPEN_COLLECTION;
  144. // Call the function to initialize the
  145. hr = m_PrivelagesToken.FInit();
  146. if(SUCCEEDED(hr) && SUCCEEDED(pWrap->GetServicesPtr()->QueryInterface(IID_IWbemServicesEx,(void **)&pSerEx)))
  147. {
  148. if(pstrPath)
  149. {
  150. IWbemServicesEx *pCollectionEx = NULL;
  151. if(SUCCEEDED(hr =pSerEx->Open(strPath,NULL,lFlag,NULL,&pCollectionEx,NULL)))
  152. {
  153. if(SUCCEEDED(hr = pCollectionEx->QueryInterface(IID_IWbemServices,(void **)&m_pIWbemServices)))
  154. {
  155. m_pDataSourceCon = pWrap;
  156. }
  157. }
  158. }
  159. else
  160. {
  161. hr = pSerEx->QueryInterface(IID_IWbemServices,(void **)&m_pIWbemServices);
  162. }
  163. SAFE_RELEASE_PTR(pSerEx);
  164. }
  165. return hr;
  166. }
  167. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  168. CWbemConnectionWrapper::~CWbemConnectionWrapper()
  169. {
  170. // CoUninitialize();
  171. SAFE_RELEASE_PTR(m_pIWbemServices);
  172. SAFE_RELEASE_PTR(m_pCtx);
  173. if(m_strUser)
  174. {
  175. SysFreeString(m_strUser);
  176. }
  177. if(m_strPassword)
  178. {
  179. SysFreeString(m_strPassword);
  180. }
  181. if(m_strLocale)
  182. {
  183. SysFreeString(m_strLocale);
  184. }
  185. if(m_strAuthority)
  186. {
  187. SysFreeString(m_strAuthority);
  188. }
  189. }
  190. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  191. void CWbemConnectionWrapper::InitVars()
  192. {
  193. m_vNamespace.SetStr(DEFAULT_NAMESPACE);
  194. m_pIWbemServices = NULL;
  195. m_pCtx = NULL;
  196. m_dwAuthnLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
  197. m_dwImpLevel = RPC_C_AUTHN_LEVEL_CONNECT;
  198. m_strUser = NULL;
  199. m_strPassword = NULL;
  200. m_strLocale = NULL;
  201. m_pDataSourceCon = NULL;
  202. m_strAuthority = NULL;
  203. }
  204. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  205. BOOL CWbemConnectionWrapper::ValidConnection()
  206. {
  207. BOOL bRet = FALSE;
  208. if( m_pIWbemServices ){
  209. bRet = TRUE;
  210. }
  211. if( S_OK == GetConnectionToWbem() ){
  212. bRet = TRUE;
  213. }
  214. return bRet;
  215. }
  216. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  217. void CWbemConnectionWrapper::SetValidNamespace(VARIANT * v)
  218. {
  219. if((V_VT(v) == VT_NULL ) || (V_VT(v) == VT_EMPTY )){
  220. m_vNamespace.SetStr(DEFAULT_NAMESPACE);
  221. }
  222. else{
  223. m_vNamespace.SetStr(V_BSTR(v));
  224. }
  225. }
  226. void CWbemConnectionWrapper::SetUserInfo(BSTR strUser,BSTR strPassword,BSTR strAuthority)
  227. {
  228. m_strUser = Wmioledb_SysAllocString(strUser);
  229. m_strPassword = Wmioledb_SysAllocString(strPassword);
  230. m_strAuthority = Wmioledb_SysAllocString(strAuthority);
  231. }
  232. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  233. HRESULT CWbemConnectionWrapper::GetConnectionToWbem( void )
  234. {
  235. HRESULT hr = S_OK;
  236. IWbemLocator *pLoc = 0;
  237. IWbemServicesEx *pSer = NULL;
  238. hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
  239. if(SUCCEEDED(hr )){
  240. hr = pLoc->ConnectServer(m_vNamespace,m_strUser, m_strPassword, m_strLocale,0, m_strAuthority, 0, &m_pIWbemServices );
  241. if( SUCCEEDED(hr)){
  242. IClientSecurity *pClientSecurity = NULL;
  243. if(SUCCEEDED(m_pIWbemServices->QueryInterface(IID_IClientSecurity,(void **)&pClientSecurity)))
  244. {
  245. hr = CoSetProxyBlanket( m_pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHN_NONE, NULL,
  246. m_dwAuthnLevel, m_dwImpLevel, NULL, EOAC_NONE );
  247. pClientSecurity->Release();
  248. }
  249. HRESULT hr1 = m_pIWbemServices->QueryInterface(IID_IWbemServicesEx,(void **)&pSer);
  250. SAFE_RELEASE_PTR(pSer);
  251. }
  252. pLoc->Release();
  253. }
  254. if(SUCCEEDED(hr) && !g_pIWbemCtxClassFac)
  255. {
  256. CoGetClassObject(CLSID_WbemContext,CLSCTX_INPROC_SERVER,NULL,IID_IClassFactory,(void **)&g_pIWbemCtxClassFac);
  257. }
  258. if(hr == WBEM_E_NOT_FOUND)
  259. {
  260. hr = WBEM_E_INVALID_NAMESPACE;
  261. }
  262. return MapWbemErrorToOLEDBError(hr);
  263. }
  264. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  265. // Set the conneciton attributes for the connection
  266. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  267. void CWbemConnectionWrapper::SetConnAttributes(DWORD dwAuthnLevel , DWORD dwImpLevel)
  268. {
  269. m_dwAuthnLevel = dwAuthnLevel;
  270. m_dwImpLevel = dwImpLevel;
  271. }
  272. //////////////////////////////////////////////////////////////////////////////////////////////////
  273. HRESULT CWbemConnectionWrapper::DeleteClass(BSTR strClassName)
  274. {
  275. HRESULT hr = m_pIWbemServices->DeleteClass(strClassName, 0,NULL,NULL);
  276. if(hr == WBEM_E_NOT_FOUND)
  277. {
  278. hr = WBEM_E_INVALID_CLASS;
  279. }
  280. return MapWbemErrorToOLEDBError(hr);
  281. }
  282. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  283. // Begin a transaction
  284. // Removing transaction support as per alanbos mail ( core is removing the support)
  285. // 06/30/2000
  286. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  287. HRESULT CWbemConnectionWrapper::BeginTransaction(ULONG uTimeout,ULONG uFlags,GUID *pTransGUID)
  288. {
  289. HRESULT hr = S_OK;
  290. /* IWbemTransaction * pWbemTrans = NULL;
  291. IWbemServicesEx *pTest = NULL;
  292. if(SUCCEEDED(hr = GetServicesPtr()->QueryInterface(IID_IWbemTransaction,(void **)&pWbemTrans)))
  293. {
  294. hr = pWbemTrans->Begin(uTimeout,uFlags,pTransGUID);
  295. }
  296. SAFE_RELEASE_PTR(pWbemTrans);
  297. */
  298. return hr;
  299. }
  300. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  301. // Commit/Rollback a transaction
  302. // Removing transaction support as per alanbos mail ( core is removing the support)
  303. // 06/30/2000
  304. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  305. HRESULT CWbemConnectionWrapper::CompleteTransaction(BOOL bRollBack,ULONG uFlags)
  306. {
  307. HRESULT hr = S_OK;
  308. /* IWbemTransaction * pWbemTrans = NULL;
  309. if(SUCCEEDED(hr = GetServicesPtr()->QueryInterface(IID_IWbemTransaction,(void **)&pWbemTrans)))
  310. {
  311. if(bRollBack)
  312. {
  313. hr = pWbemTrans->Rollback(uFlags);
  314. }
  315. else
  316. {
  317. hr = pWbemTrans->Commit(uFlags);
  318. }
  319. }
  320. SAFE_RELEASE_PTR(pWbemTrans);
  321. */
  322. return hr;
  323. }
  324. IWbemServices* CWbemConnectionWrapper::GetServicesPtr()
  325. {
  326. return m_pIWbemServices;
  327. }
  328. WCHAR * CWbemConnectionWrapper::GetNamespace()
  329. {
  330. WCHAR *pNameSpace = NULL;
  331. if(!m_pDataSourceCon)
  332. {
  333. pNameSpace = m_vNamespace.GetStr();
  334. }
  335. else
  336. {
  337. pNameSpace = m_pDataSourceCon->GetNamespace();
  338. }
  339. return pNameSpace;
  340. }
  341. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  342. // Set the Locale Identifier
  343. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  344. void CWbemConnectionWrapper::SetLocale(LONG lLocaleID)
  345. {
  346. WCHAR wstrLocale[LOCALESTRING_MAXSIZE];
  347. swprintf(wstrLocale,L"MS_%x",lLocaleID);
  348. m_strLocale = Wmioledb_SysAllocString(wstrLocale);
  349. }
  350. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  351. // Create an new namespace and initialize the wrapper
  352. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  353. HRESULT CWbemConnectionWrapper::CreateNameSpace()
  354. {
  355. HRESULT hr = S_OK;
  356. BSTR strNameSpace = NULL;
  357. BSTR strParentNameSpace = NULL;
  358. CURLParser urlParser;
  359. if(m_pIWbemServices)
  360. {
  361. hr = DB_E_ALREADYINITIALIZED;
  362. }
  363. else
  364. {
  365. VARIANT varTemp;
  366. VariantInit(&varTemp);
  367. varTemp.vt = VT_BSTR;
  368. urlParser.SetPath(m_vNamespace.GetStr());
  369. if(SUCCEEDED(hr = urlParser.ParseNameSpace(strParentNameSpace,strNameSpace)))
  370. {
  371. varTemp.bstrVal = strParentNameSpace;
  372. SetValidNamespace(&varTemp);
  373. // connect to the Parent namespace
  374. if(SUCCEEDED(hr =GetConnectionToWbem()))
  375. {
  376. IWbemClassObject *pClass = NULL;
  377. CBSTR strNamespaceClass(L"__NameSpace");
  378. if(SUCCEEDED(hr = m_pIWbemServices->GetObject((BSTR)strNamespaceClass,WBEM_FLAG_RETURN_WBEM_COMPLETE,NULL,&pClass,NULL)))
  379. {
  380. // Create the namespace instance and save the object
  381. // after saving the name
  382. IWbemClassObject *pNewInstance = NULL;
  383. if(SUCCEEDED(hr = pClass->SpawnInstance(0,&pNewInstance)))
  384. {
  385. varTemp.bstrVal = strNameSpace;
  386. if(SUCCEEDED(hr = pNewInstance->Put(L"Name",0,&varTemp,CIM_STRING)) &&
  387. SUCCEEDED(hr = m_pIWbemServices->PutInstance(pNewInstance,WBEM_FLAG_CREATE_ONLY,NULL,NULL)))
  388. {
  389. // Open the namespace and replace the IWbemServices pointer to point to new namespcee
  390. IWbemServices *pTempSer = NULL;
  391. if(SUCCEEDED(hr = m_pIWbemServices->OpenNamespace(strNameSpace,WBEM_FLAG_RETURN_WBEM_COMPLETE,m_pCtx,&pTempSer,NULL)))
  392. {
  393. SAFE_RELEASE_PTR(m_pIWbemServices);
  394. pTempSer->QueryInterface(IID_IWbemServices,(void **)&m_pIWbemServices);
  395. SAFE_RELEASE_PTR(pTempSer);
  396. }
  397. }
  398. }
  399. SAFE_RELEASE_PTR(pNewInstance);
  400. }
  401. }
  402. SysFreeString(strParentNameSpace);
  403. SysFreeString(strNameSpace);
  404. urlParser.GetNameSpace(strNameSpace);
  405. varTemp.bstrVal = strNameSpace;
  406. // Set the correct namespace
  407. SetValidNamespace(&varTemp);
  408. SysFreeString(strNameSpace);
  409. hr = MapWbemErrorToOLEDBError(hr);
  410. }
  411. }
  412. if(FAILED(hr))
  413. {
  414. SAFE_DELETE_PTR(m_pIWbemServices);
  415. }
  416. return hr;
  417. }
  418. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  419. // Delete a namespace
  420. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  421. HRESULT CWbemConnectionWrapper::DeleteNameSpace()
  422. {
  423. HRESULT hr = S_OK;
  424. BSTR strNameSpace = NULL;
  425. BSTR strParentNameSpace = NULL;
  426. CURLParser urlParser;
  427. if(m_pIWbemServices == NULL)
  428. {
  429. hr = E_UNEXPECTED;
  430. }
  431. else
  432. {
  433. VARIANT varTemp;
  434. VariantInit(&varTemp);
  435. varTemp.vt = VT_BSTR;
  436. urlParser.SetPath(m_vNamespace.GetStr());
  437. if(SUCCEEDED(hr = urlParser.ParseNameSpace(strParentNameSpace,strNameSpace)))
  438. {
  439. // Store the pointer in temporary variable
  440. IWbemServices *pSerTemp = NULL;
  441. m_pIWbemServices->QueryInterface(IID_IWbemServices,(void **)&pSerTemp);
  442. SAFE_RELEASE_PTR(m_pIWbemServices);
  443. varTemp.bstrVal = strParentNameSpace;
  444. SetValidNamespace(&varTemp);
  445. // connect to the Parent namespace
  446. if(SUCCEEDED(hr =GetConnectionToWbem()))
  447. {
  448. WCHAR strNameSpaceObject[PATH_MAXLENGTH];
  449. wcscpy(strNameSpaceObject,L"");
  450. swprintf(strNameSpaceObject,L"__NAMESPACE.Name=\"%s\"",strNameSpace);
  451. CBSTR strNameSpacePath(strNameSpaceObject);
  452. // Delete the namespace instance
  453. if(FAILED(hr = m_pIWbemServices->DeleteInstance(strNameSpacePath,WBEM_FLAG_RETURN_WBEM_COMPLETE,m_pCtx,NULL)))
  454. {
  455. SAFE_RELEASE_PTR(m_pIWbemServices);
  456. strNameSpacePath.Clear();
  457. urlParser.GetNameSpace((BSTR &)strNameSpacePath);
  458. varTemp.bstrVal = (BSTR)strNameSpacePath;
  459. // Set the correct namespace
  460. SetValidNamespace(&varTemp);
  461. pSerTemp->QueryInterface(IID_IWbemServices, (void **)&m_pIWbemServices);
  462. }
  463. else
  464. {
  465. SAFE_RELEASE_PTR(m_pIWbemServices);
  466. }
  467. }
  468. SAFE_RELEASE_PTR(pSerTemp);
  469. SysFreeString(strParentNameSpace);
  470. SysFreeString(strNameSpace);
  471. }
  472. hr = MapWbemErrorToOLEDBError(hr);
  473. }
  474. return hr;
  475. }
  476. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  477. // Delete a namespace
  478. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  479. HRESULT CWbemConnectionWrapper::GetObjectAccessRights(BSTR strPath,
  480. ULONG *pcAccessEntries,
  481. EXPLICIT_ACCESS_W **prgAccessEntries,
  482. ULONG ulAccessEntries,
  483. EXPLICIT_ACCESS_W *pAccessEntries)
  484. {
  485. IWbemServicesEx *pSerEx = NULL;
  486. IWbemRawSdAccessor *pSdAccessor = NULL;
  487. HRESULT hr = S_OK;
  488. SECURITY_DESCRIPTOR sd;
  489. InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
  490. *pcAccessEntries = 0;
  491. *prgAccessEntries = NULL;
  492. if(m_pIWbemServices == NULL)
  493. {
  494. hr = E_UNEXPECTED;
  495. }
  496. else
  497. {
  498. CWbemSecurityDescriptor wbemSD;
  499. if(SUCCEEDED(hr = wbemSD.Init(m_pIWbemServices,strPath,GetContext())))
  500. {
  501. PACL pDacl;
  502. BOOL bDacl = TRUE;
  503. BOOL bDefaultDacl = TRUE;
  504. if(GetSecurityDescriptorDacl(wbemSD.GetSecurityDescriptor(),&bDacl,&pDacl,&bDefaultDacl) && bDacl )
  505. {
  506. hr = GetExplicitEntriesFromAclW(pDacl,pcAccessEntries,prgAccessEntries);
  507. }
  508. else
  509. // DACL for SD was null
  510. if(bDacl == FALSE)
  511. {
  512. hr = FALSE;
  513. }
  514. }
  515. else
  516. if(hr == WBEM_E_NULL_SECURITY_DESCRIPTOR)
  517. {
  518. hr = S_OK;
  519. }
  520. }
  521. return hr;
  522. }
  523. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  524. // Delete a namespace
  525. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  526. HRESULT CWbemConnectionWrapper::SetObjectAccessRights(BSTR strPath,
  527. ULONG ulAccessEntries,
  528. EXPLICIT_ACCESS_W *pAccessEntries)
  529. {
  530. HRESULT hr = S_OK;
  531. if(m_pIWbemServices == NULL)
  532. {
  533. hr = E_UNEXPECTED;
  534. }
  535. else
  536. {
  537. CWbemSecurityDescriptor wbemSD;
  538. if(SUCCEEDED(hr = wbemSD.Init(m_pIWbemServices,strPath,GetContext())))
  539. {
  540. PACL pDacl;
  541. BOOL bDacl = TRUE;
  542. BOOL bDefaultDacl = TRUE;
  543. // Get the security descriptor DACL for the given Security descriptor
  544. if(GetSecurityDescriptorDacl(wbemSD.GetSecurityDescriptor(),&bDacl,&pDacl,&bDefaultDacl) && bDacl )
  545. {
  546. PACL pNewDacl;
  547. BOOL bRet = SetEntriesInAclW(ulAccessEntries,pAccessEntries,pDacl,&pNewDacl);
  548. if(bRet)
  549. {
  550. if(SetSecurityDescriptorDacl(wbemSD.GetSecurityDescriptor(),TRUE,pNewDacl,TRUE))
  551. {
  552. hr = wbemSD.PutSD();
  553. }
  554. }
  555. else
  556. {
  557. hr = E_FAIL;
  558. }
  559. }
  560. else
  561. // DACL for SD was null
  562. if(bDacl == FALSE)
  563. {
  564. hr = FALSE;
  565. }
  566. }
  567. else
  568. if(hr == WBEM_E_NULL_SECURITY_DESCRIPTOR)
  569. {
  570. hr = S_OK;
  571. }
  572. }
  573. return hr;
  574. }
  575. HRESULT CWbemConnectionWrapper::SetObjectOwner(BSTR strPath,TRUSTEE_W *pOwner)
  576. {
  577. HRESULT hr = S_OK;
  578. if(m_pIWbemServices == NULL)
  579. {
  580. hr = E_UNEXPECTED;
  581. }
  582. else
  583. {
  584. CWbemSecurityDescriptor wbemSD;
  585. if(SUCCEEDED(hr = wbemSD.Init(m_pIWbemServices,strPath,GetContext())))
  586. {
  587. PSID psid;
  588. if(!wbemSD.GetSID(pOwner,psid))
  589. {
  590. hr = E_FAIL;
  591. }
  592. else
  593. if(SetSecurityDescriptorOwner(wbemSD.GetSecurityDescriptor(),psid,TRUE))
  594. {
  595. // set the Security descriptor for the object
  596. hr = wbemSD.PutSD();
  597. }
  598. else
  599. {
  600. hr = E_FAIL;
  601. }
  602. }
  603. else
  604. if(hr == WBEM_E_NULL_SECURITY_DESCRIPTOR)
  605. {
  606. hr = S_OK;
  607. }
  608. }
  609. return hr;
  610. }
  611. HRESULT CWbemConnectionWrapper::GetObjectOwner( BSTR strPath,TRUSTEE_W ** ppOwner)
  612. {
  613. HRESULT hr = S_OK;
  614. if(m_pIWbemServices == NULL)
  615. {
  616. hr = E_UNEXPECTED;
  617. }
  618. else
  619. {
  620. CWbemSecurityDescriptor wbemSD;
  621. if(SUCCEEDED(hr = wbemSD.Init(m_pIWbemServices,strPath,GetContext())))
  622. {
  623. PSID psid;
  624. BOOL bOwnerDefaulted = TRUE;
  625. if(!GetSecurityDescriptorOwner(wbemSD.GetSecurityDescriptor(),&psid,&bOwnerDefaulted))
  626. {
  627. hr = E_FAIL;
  628. }
  629. else
  630. if(psid == NULL)
  631. {
  632. hr = SEC_E_NOOWNER;
  633. }
  634. else
  635. BuildTrusteeWithSidW(*ppOwner,psid);
  636. }
  637. else
  638. if(hr == WBEM_E_NULL_SECURITY_DESCRIPTOR)
  639. {
  640. hr = S_OK;
  641. }
  642. }
  643. return hr;
  644. }
  645. HRESULT CWbemConnectionWrapper::IsObjectAccessAllowed( BSTR strPath,EXPLICIT_ACCESS_W *pAccessEntry,BOOL *pfResult)
  646. {
  647. HRESULT hr = S_OK;
  648. *pfResult = FALSE;
  649. if(m_pIWbemServices == NULL)
  650. {
  651. hr = E_UNEXPECTED;
  652. }
  653. else
  654. {
  655. CWbemSecurityDescriptor wbemSD;
  656. if(SUCCEEDED(hr = wbemSD.Init(m_pIWbemServices,strPath,GetContext())))
  657. {
  658. PACL pDacl;
  659. BOOL bDacl = TRUE;
  660. BOOL bDefaultDacl = TRUE;
  661. ACCESS_MASK AccMask;
  662. // Get the security descriptor DACL for the given Security descriptor
  663. if(GetSecurityDescriptorDacl(wbemSD.GetSecurityDescriptor(),&bDacl,&pDacl,&bDefaultDacl) && bDacl )
  664. {
  665. // Get the permissions for a particular trustee
  666. if(ERROR_SUCCESS == (hr = GetEffectiveRightsFromAclW(pDacl,&(pAccessEntry->Trustee),&AccMask)))
  667. {
  668. ACCESS_MASK AccMaskTemp;
  669. AccMaskTemp = AccMask & pAccessEntry->grfAccessPermissions;
  670. if(AccMaskTemp >= pAccessEntry->grfAccessPermissions)
  671. {
  672. *pfResult = TRUE;
  673. }
  674. }
  675. }
  676. }
  677. else
  678. if(hr == WBEM_E_NULL_SECURITY_DESCRIPTOR)
  679. {
  680. hr = S_OK;
  681. }
  682. }
  683. return hr;
  684. }
  685. BOOL CWbemConnectionWrapper::IsValidObject(BSTR strPath)
  686. {
  687. HRESULT hr = S_OK;
  688. BOOL bRet = FALSE;
  689. if(m_pIWbemServices == NULL)
  690. {
  691. hr = E_UNEXPECTED;
  692. }
  693. else
  694. {
  695. if(SUCCEEDED(hr = m_pIWbemServices->GetObject(strPath,WBEM_FLAG_RETURN_WBEM_COMPLETE,GetContext(),NULL,NULL)))
  696. {
  697. bRet = TRUE;
  698. }
  699. }
  700. return bRet;
  701. }
  702. HRESULT CWbemConnectionWrapper::GetParameters(BSTR strPath,BSTR &strClassName,BSTR *strNameSpace)
  703. {
  704. HRESULT hr = S_OK;
  705. IWbemLocator *pLoc = NULL;
  706. IWbemServices *pSer = NULL;
  707. IWbemClassObject *pObject = NULL;
  708. VARIANT varProp;
  709. VariantInit(&varProp);
  710. hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
  711. if(SUCCEEDED(hr ))
  712. {
  713. hr = pLoc->ConnectServer(strNameSpace ? *strNameSpace : strPath,
  714. m_strUser, m_strPassword, m_strLocale,0, m_strAuthority, 0, &pSer);
  715. if( SUCCEEDED(hr))
  716. {
  717. IClientSecurity *pClientSecurity = NULL;
  718. hr = pSer->QueryInterface(IID_IClientSecurity,(void **)&pClientSecurity);
  719. if(SUCCEEDED(hr))
  720. {
  721. hr = CoSetProxyBlanket( pSer,RPC_C_AUTHN_WINNT, RPC_C_AUTHN_NONE, NULL,
  722. m_dwAuthnLevel, m_dwImpLevel, NULL, EOAC_NONE );
  723. SAFE_RELEASE_PTR(pClientSecurity);
  724. }
  725. else
  726. {
  727. hr = S_OK;
  728. }
  729. if(strNameSpace)
  730. {
  731. hr = pSer->GetObject(strPath,0,NULL,&pObject,NULL);
  732. }
  733. else
  734. {
  735. hr = pSer->QueryInterface(IID_IWbemClassObject , (void **)&pObject);
  736. }
  737. if(SUCCEEDED(hr) && SUCCEEDED(hr = pObject->Get(L"__CLASS",0,&varProp,NULL,NULL)))
  738. {
  739. strClassName = Wmioledb_SysAllocString(varProp.bstrVal);
  740. VariantClear(&varProp);
  741. }
  742. SAFE_RELEASE_PTR(pObject);
  743. SAFE_RELEASE_PTR(pSer);
  744. }
  745. SAFE_RELEASE_PTR(pLoc);
  746. }
  747. if(hr == WBEM_E_NOT_FOUND)
  748. {
  749. hr = WBEM_E_INVALID_NAMESPACE;
  750. }
  751. return MapWbemErrorToOLEDBError(hr);
  752. }
  753. // get the class name of the object pointed by the classname
  754. // NTRaid : 134967
  755. // 07/12/00
  756. HRESULT CWbemConnectionWrapper::GetClassName(BSTR strPath,BSTR &strClassName)
  757. {
  758. HRESULT hr = S_OK;
  759. IWbemClassObject *pObject = NULL;
  760. if(SUCCEEDED(hr = m_pIWbemServices->GetObject(strPath,WBEM_FLAG_RETURN_WBEM_COMPLETE,GetContext(),&pObject,NULL)))
  761. {
  762. VARIANT varVal;
  763. VariantInit(&varVal);
  764. if(SUCCEEDED(hr = pObject->Get(L"__CLASS",0,&varVal,NULL,NULL)))
  765. {
  766. strClassName = Wmioledb_SysAllocString(varVal.bstrVal);
  767. }
  768. VariantClear(&varVal);
  769. }
  770. SAFE_RELEASE_PTR(pObject);
  771. return MapWbemErrorToOLEDBError(hr);
  772. }
  773. // 07/12/2000
  774. // NTRaid : 142348
  775. // function which executes Action queries
  776. HRESULT CWbemConnectionWrapper::ExecuteQuery(CQuery *pQuery)
  777. {
  778. HRESULT hr = S_OK;
  779. IEnumWbemClassObject *pEnumObject = NULL;
  780. CBSTR stQryLanguage(pQuery->GetQueryLang());
  781. CBSTR strQuery(pQuery->GetQuery());
  782. hr = m_pIWbemServices->ExecQuery(stQryLanguage,strQuery,0,GetContext(),&pEnumObject);
  783. SAFE_RELEASE_PTR(pEnumObject);
  784. return MapWbemErrorToOLEDBError(hr);
  785. }
  786. // function which gets the pointer to the the object for which it is pointing
  787. // If the connection doesn not point to object then this returns the namespace
  788. HRESULT CWbemConnectionWrapper::GetNodeName(BSTR &strNode)
  789. {
  790. HRESULT hr = S_OK;
  791. IWbemClassObject *pObject = NULL;
  792. if(SUCCEEDED(hr = m_pIWbemServices->QueryInterface(IID_IWbemClassObject,(void **)&pObject)))
  793. {
  794. VARIANT var;
  795. VariantInit(&var);
  796. if(FAILED(hr = pObject->Get(L"__URL",0,&var,NULL,NULL)))
  797. {
  798. hr = pObject->Get(L"__PATH",0,&var,NULL,NULL);
  799. }
  800. if(SUCCEEDED(hr))
  801. {
  802. strNode = Wmioledb_SysAllocString(var.bstrVal);
  803. }
  804. SAFE_RELEASE_PTR(pObject);
  805. VariantClear(&var);
  806. }
  807. else
  808. {
  809. strNode = Wmioledb_SysAllocString(GetNamespace());
  810. hr = S_OK;
  811. }
  812. return hr;
  813. }
  814. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  815. //*********************************************************************************************************************
  816. //
  817. // CWbemClassParameters
  818. //
  819. //*********************************************************************************************************************
  820. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  821. CWbemClassParameters::CWbemClassParameters(DWORD dwFlags,WCHAR * pClassName,CWbemConnectionWrapper * pWrap )
  822. {
  823. m_dwNavFlags = 0;
  824. m_dwFlags = dwFlags;
  825. m_dwQueryFlags = WBEM_FLAG_SHALLOW;
  826. m_pConnection = pWrap;
  827. m_pwcsClassName = NULL;
  828. m_bSystemProperties = FALSE;
  829. m_pwcsClassName = NULL;
  830. m_pwcsParentClassName = NULL;
  831. m_pIContext = NULL;
  832. }
  833. /*
  834. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  835. CWbemClassParameters::CWbemClassParameters(DWORD dwFlags,IDispatch *pDisp,CWbemConnectionWrapper * pWrap )
  836. {
  837. m_dwNavFlags = 0;
  838. m_dwFlags = dwFlags;
  839. m_pConnection = pWrap;
  840. m_pwcsClassName = NULL;
  841. m_bSystemProperties = FALSE;
  842. m_pwcsParentClassName = NULL;
  843. // GetClassNameForWbemObject(pDisp);
  844. }
  845. */
  846. /////////////////////////////////////////////////////////////////////////////////////////////
  847. // Destructor
  848. /////////////////////////////////////////////////////////////////////////////////////////////
  849. CWbemClassParameters::~CWbemClassParameters()
  850. {
  851. DeleteClassName();
  852. SAFE_RELEASE_PTR(m_pIContext);
  853. SAFE_DELETE_ARRAY(m_pwcsClassName);
  854. }
  855. /////////////////////////////////////////////////////////////////////////////////////////////
  856. // Function to get the class name and copy it to the member variable from
  857. // the instance pointed by the IDispatch pointer
  858. /////////////////////////////////////////////////////////////////////////////////////////////
  859. HRESULT CWbemClassParameters::GetClassNameForWbemObject(IWbemClassObject *pInstance )
  860. {
  861. HRESULT hr = 0;
  862. BSTR strClassPropName;
  863. VARIANT varClassName;
  864. VariantInit(&varClassName);
  865. strClassPropName = Wmioledb_SysAllocString(L"__CLASS");
  866. hr = pInstance->Get(strClassPropName,0,&varClassName,NULL, NULL);
  867. if( hr == S_OK )
  868. {
  869. SAFE_DELETE_ARRAY(m_pwcsClassName)
  870. m_pwcsClassName = new WCHAR[SysStringLen(varClassName.bstrVal)];
  871. wcscpy(m_pwcsClassName,(WCHAR *)varClassName.bstrVal);
  872. }
  873. VariantClear(&varClassName);
  874. SysFreeString(strClassPropName);
  875. return hr;
  876. }
  877. /////////////////////////////////////////////////////////////////////////////////////////////
  878. // function to set the enumerator flags
  879. /////////////////////////////////////////////////////////////////////////////////////////////
  880. void CWbemClassParameters::SetEnumeratorFlags(DWORD dwFlags)
  881. {
  882. m_dwNavFlags |= dwFlags;
  883. }
  884. /////////////////////////////////////////////////////////////////////////////////////////////
  885. // function to set the enumerator flags
  886. /////////////////////////////////////////////////////////////////////////////////////////////
  887. void CWbemClassParameters::SetQueryFlags(DWORD dwFlags)
  888. {
  889. m_dwQueryFlags = dwFlags;
  890. }
  891. /////////////////////////////////////////////////////////////////////////////////////////////
  892. // function which seperates class name and its
  893. // parent classname if present in the name
  894. /////////////////////////////////////////////////////////////////////////////////////////////
  895. HRESULT CWbemClassParameters::ParseClassName()
  896. {
  897. WCHAR *pTemp = NULL;
  898. pTemp = wcsstr(m_pwcsClassName,CLASSSEPARATOR);
  899. HRESULT hr = S_OK;
  900. if(pTemp != NULL)
  901. {
  902. m_pwcsParentClassName = new WCHAR[pTemp - m_pwcsClassName + 1];
  903. //NTRaid:111763 & NTRaid:111764
  904. // 06/07/00
  905. if(m_pwcsParentClassName)
  906. {
  907. memset(m_pwcsParentClassName , 0,(pTemp - m_pwcsClassName + 1) * sizeof(WCHAR));
  908. memcpy(m_pwcsParentClassName,m_pwcsClassName,(pTemp - m_pwcsClassName) * sizeof(WCHAR));
  909. pTemp += wcslen(CLASSSEPARATOR);
  910. wcscpy(m_pwcsClassName,pTemp);
  911. }
  912. else
  913. {
  914. hr = E_OUTOFMEMORY;
  915. }
  916. }
  917. else
  918. {
  919. m_pwcsParentClassName = NULL;
  920. }
  921. return hr;
  922. }
  923. /////////////////////////////////////////////////////////////////////////////////////////////
  924. // Function to get class Name
  925. /////////////////////////////////////////////////////////////////////////////////////////////
  926. WCHAR * CWbemClassParameters::GetClassName()
  927. {
  928. return m_pwcsClassName;
  929. }
  930. /////////////////////////////////////////////////////////////////////////////////////////////
  931. // Function to remove an object from a container
  932. /////////////////////////////////////////////////////////////////////////////////////////////
  933. HRESULT CWbemClassParameters::RemoveObjectFromContainer(BSTR strContainerObj,BSTR strObject)
  934. {
  935. HRESULT hr = S_OK;
  936. IWbemServicesEx * pServicesEx = NULL;
  937. IWbemServicesEx * pContainerServicesEx = NULL;
  938. if(SUCCEEDED(hr = GetServicesPtr()->QueryInterface(IID_IWbemServicesEx,(void **)&pServicesEx)))
  939. {
  940. if(SUCCEEDED(hr =pServicesEx->Open(strContainerObj,NULL,WBEM_FLAG_OPEN_COLLECTION,NULL,&pContainerServicesEx,NULL)))
  941. {
  942. hr = pContainerServicesEx->Remove(strObject,0,NULL,NULL);
  943. SAFE_RELEASE_PTR(pContainerServicesEx);
  944. }
  945. SAFE_RELEASE_PTR(pServicesEx);
  946. }
  947. return MapWbemErrorToOLEDBError(hr);
  948. }
  949. /////////////////////////////////////////////////////////////////////////////////////////////
  950. // Function to add an object to a container
  951. /////////////////////////////////////////////////////////////////////////////////////////////
  952. HRESULT CWbemClassParameters::AddObjectFromContainer(BSTR strContainerObj,BSTR strObject)
  953. {
  954. HRESULT hr = S_OK;
  955. IWbemServicesEx * pServicesEx = NULL;
  956. IWbemServicesEx * pContainerServicesEx = NULL;
  957. if(SUCCEEDED(hr = GetServicesPtr()->QueryInterface(IID_IWbemServicesEx,(void **)&pServicesEx)))
  958. {
  959. if(SUCCEEDED(hr =pServicesEx->Open(strContainerObj,NULL,WBEM_FLAG_OPEN_COLLECTION,NULL,&pContainerServicesEx,NULL)))
  960. {
  961. hr = pContainerServicesEx->Add(strObject,0,NULL,NULL);
  962. SAFE_RELEASE_PTR(pContainerServicesEx);
  963. }
  964. SAFE_RELEASE_PTR(pServicesEx);
  965. }
  966. return MapWbemErrorToOLEDBError(hr);
  967. }
  968. ///////////////////////////////////////////////////////////////////////////////////////////
  969. // Function to clone an object from one scope to another
  970. ///////////////////////////////////////////////////////////////////////////////////////////
  971. HRESULT CWbemClassParameters::CloneAndAddNewObjectInScope(CWbemClassWrapper *pClass,BSTR strObj,WCHAR *& pstrNewPath)
  972. {
  973. HRESULT hr = S_OK;
  974. IWbemServicesEx * pServicesEx = NULL;
  975. IWbemServicesEx * pContainerServicesEx = NULL;
  976. IWbemClassObject* pNewObject = NULL;
  977. if(SUCCEEDED( hr = ((CWbemClassInstanceWrapper *)pClass)->CloneInstance(pNewObject)))
  978. {
  979. if(SUCCEEDED(hr = GetServicesPtr()->QueryInterface(IID_IWbemServicesEx,(void **)&pServicesEx)))
  980. {
  981. // Open object as scope
  982. if(SUCCEEDED(hr =pServicesEx->Open(strObj,NULL,WBEM_FLAG_OPEN_SCOPE,NULL,&pContainerServicesEx,NULL)))
  983. {
  984. if(SUCCEEDED(hr = pContainerServicesEx->PutInstance(pNewObject,WBEM_FLAG_CREATE_ONLY,GetContext(),NULL)))
  985. {
  986. CVARIANT var;
  987. CBSTR strProp;
  988. strProp.SetStr(L"__PATH");
  989. HRESULT hr = pNewObject->Get(L"__PATH",0,var,NULL,NULL);
  990. if( hr == S_OK )
  991. {
  992. try
  993. {
  994. pstrNewPath = new WCHAR[wcslen(var.GetStr()) + 1];
  995. }
  996. catch(...)
  997. {
  998. SAFE_DELETE_ARRAY(pstrNewPath);
  999. SAFE_RELEASE_PTR(pContainerServicesEx);
  1000. SAFE_RELEASE_PTR(pServicesEx);
  1001. SAFE_RELEASE_PTR(pNewObject);
  1002. throw;
  1003. }
  1004. if(pstrNewPath)
  1005. {
  1006. wcscpy(pstrNewPath,var.GetStr());
  1007. }
  1008. else
  1009. {
  1010. hr = E_OUTOFMEMORY;
  1011. }
  1012. }
  1013. }
  1014. SAFE_RELEASE_PTR(pContainerServicesEx);
  1015. }
  1016. SAFE_RELEASE_PTR(pServicesEx);
  1017. }
  1018. SAFE_RELEASE_PTR(pNewObject);
  1019. }
  1020. return MapWbemErrorToOLEDBError(hr);
  1021. }
  1022. ///////////////////////////////////////////////////////////////////////////////////////////
  1023. // Set the search preferences for DS provider
  1024. ///////////////////////////////////////////////////////////////////////////////////////////
  1025. HRESULT CWbemClassParameters::SetSearchPreferences(ULONG cProps , DBPROP rgProp[])
  1026. {
  1027. HRESULT hr = S_OK;
  1028. UINT nStrId = 0;
  1029. WCHAR wcsPreferenceName[SEARCHPREFERENCE_NAMESIZE];
  1030. VARIANT varValue;
  1031. memset(wcsPreferenceName,0,SEARCHPREFERENCE_NAMESIZE * sizeof(WCHAR));
  1032. VariantInit(&varValue);
  1033. for(ULONG i = 0 ; i < cProps ; i++)
  1034. {
  1035. nStrId = 0;
  1036. if(!m_pIContext)
  1037. {
  1038. hr = g_pIWbemCtxClassFac->CreateInstance(NULL,IID_IWbemContext,(void **)&m_pIContext);
  1039. }
  1040. else
  1041. {
  1042. m_pIContext->DeleteAll();
  1043. }
  1044. if(SUCCEEDED(hr))
  1045. {
  1046. switch(rgProp[i].dwPropertyID)
  1047. {
  1048. case DBPROP_WMIOLEDB_DS_DEREFALIAS :
  1049. nStrId = IDS_DS_DEREFALIAS;
  1050. varValue.vt = VT_I4;
  1051. varValue.lVal = rgProp[i].vValue.lVal;
  1052. break;
  1053. case DBPROP_WMIOLEDB_DS_SIZELIMIT :
  1054. nStrId = IDS_DS_SIZELIMIT;
  1055. varValue.vt = VT_I4;
  1056. varValue.lVal = rgProp[i].vValue.lVal;
  1057. break;
  1058. case DBPROP_WMIOLEDB_DS_PAGEDTIMELIMIT:
  1059. nStrId = IDS_DS_PAGEDTIMELIMIT;
  1060. varValue.vt = VT_I4;
  1061. varValue.lVal = rgProp[i].vValue.lVal;
  1062. break;
  1063. case DBPROP_WMIOLEDB_DS_ASYNCH:
  1064. nStrId = IDS_DS_ASYNC;
  1065. varValue.vt = VT_BOOL;
  1066. varValue.lVal = rgProp[i].vValue.boolVal;
  1067. break;
  1068. case DBPROP_WMIOLEDB_DS_ATTRIBONLY:
  1069. nStrId = IDS_DS_ATTRIBONLY;
  1070. varValue.vt = VT_BOOL;
  1071. varValue.lVal = rgProp[i].vValue.boolVal;
  1072. break;
  1073. case DBPROP_WMIOLEDB_DS_TOMBSTONE:
  1074. nStrId = IDS_DS_TOMBSTONE;
  1075. varValue.vt = VT_BOOL;
  1076. varValue.lVal = rgProp[i].vValue.boolVal;
  1077. break;
  1078. case DBPROP_WMIOLEDB_DS_SEARCHSCOPE:
  1079. nStrId = IDS_DS_SEARCHSCOPE;
  1080. varValue.vt = VT_I4;
  1081. varValue.lVal = rgProp[i].vValue.lVal;
  1082. break;
  1083. case DBPROP_WMIOLEDB_DS_TIMEOUT:
  1084. nStrId = IDS_DS_TIMEOUT;
  1085. varValue.vt = VT_I4;
  1086. varValue.lVal = rgProp[i].vValue.lVal;
  1087. break;
  1088. case DBPROP_WMIOLEDB_DS_PAGESIZE:
  1089. nStrId = IDS_DS_PAGESIZE;
  1090. varValue.vt = VT_I4;
  1091. varValue.lVal = rgProp[i].vValue.lVal;
  1092. break;
  1093. case DBPROP_WMIOLEDB_DS_TIMELIMIT:
  1094. nStrId = IDS_DS_TIMELIMIT;
  1095. varValue.vt = VT_I4;
  1096. varValue.lVal = rgProp[i].vValue.lVal;
  1097. break;
  1098. case DBPROP_WMIOLEDB_DS_CHASEREF:
  1099. nStrId = IDS_DS_CHASEREF;
  1100. varValue.vt = VT_I4;
  1101. varValue.lVal = rgProp[i].vValue.lVal;
  1102. break;
  1103. case DBPROP_WMIOLEDB_DS_FILTER:
  1104. nStrId = IDS_DS_FILTER;
  1105. varValue.vt = VT_BSTR;
  1106. varValue.bstrVal = rgProp[i].vValue.bstrVal;
  1107. break;
  1108. case DBPROP_WMIOLEDB_DS_ATTRIBUTES:
  1109. nStrId = IDS_DS_ATTRIBUTES;
  1110. varValue.vt = VT_BSTR;
  1111. varValue.bstrVal = rgProp[i].vValue.bstrVal;
  1112. break;
  1113. case DBPROP_WMIOLEDB_DS_CACHERESULTS:
  1114. nStrId = IDS_DS_CACHERESULTS;
  1115. varValue.vt = VT_BOOL;
  1116. varValue.lVal = rgProp[i].vValue.boolVal;
  1117. break;
  1118. }
  1119. }
  1120. WMIOledb_LoadStringW(nStrId,wcsPreferenceName,SEARCHPREFERENCE_NAMESIZE * sizeof(WCHAR));
  1121. m_pIContext->SetValue(wcsPreferenceName,0,&varValue);
  1122. VariantClear(&varValue);
  1123. wcscpy(wcsPreferenceName,L"");
  1124. }
  1125. return MapWbemErrorToOLEDBError(hr);
  1126. }
  1127. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1128. //************************************************************************************************
  1129. //
  1130. // Common base class functions in dealing with a class definition or an instance
  1131. //
  1132. //************************************************************************************************
  1133. //////////////////////////////////////////////////////////////////////////////////////////////////
  1134. CWbemClassWrapper::CWbemClassWrapper( CWbemClassParameters * p )
  1135. {
  1136. m_pParms = p;
  1137. m_pClass = NULL;
  1138. m_pIWbemClassQualifierSet = NULL;
  1139. m_pIWbemPropertyQualifierSet = NULL;
  1140. }
  1141. //////////////////////////////////////////////////////////////////////////////////////////////////
  1142. CWbemClassWrapper::~CWbemClassWrapper( )
  1143. {
  1144. m_pPropQualifList.RemoveAll();
  1145. if( m_pIWbemClassQualifierSet != NULL)
  1146. {
  1147. m_pIWbemClassQualifierSet->EndEnumeration();
  1148. }
  1149. SAFE_RELEASE_PTR(m_pClass);
  1150. SAFE_RELEASE_PTR(m_pIWbemClassQualifierSet);
  1151. SAFE_RELEASE_PTR(m_pIWbemPropertyQualifierSet);
  1152. }
  1153. //////////////////////////////////////////////////////////////////////////////////////////////////
  1154. // funciton to check if the pointer to IWbemQualiferSet for property qualifer is valid
  1155. // If not then it will get the pointer to it
  1156. //////////////////////////////////////////////////////////////////////////////////////////////////
  1157. HRESULT CWbemClassWrapper::IsValidPropertyQualifier(BSTR strProperty)
  1158. {
  1159. HRESULT hr = S_OK;
  1160. IWbemQualifierSet *pQualifierSet = NULL;
  1161. if(NULL == m_pPropQualifList.GetPropertyQualifierSet(strProperty))
  1162. {
  1163. if(S_OK ==(hr = m_pClass->GetPropertyQualifierSet(strProperty, &pQualifierSet)))
  1164. {
  1165. //NTRaid:111779
  1166. // 06/13/00
  1167. hr = m_pPropQualifList.Add(pQualifierSet,strProperty);
  1168. }
  1169. }
  1170. return hr;
  1171. }
  1172. //////////////////////////////////////////////////////////////////////////////////////////////////
  1173. // funciton to check if the pointer to IWbemQualiferSet for class qualifer is valid
  1174. // If not then it will get the pointer to it and starts the enumeration on the qualiferset
  1175. //////////////////////////////////////////////////////////////////////////////////////////////////
  1176. HRESULT CWbemClassWrapper::IsValidClassQualifier()
  1177. {
  1178. HRESULT hr = S_OK;
  1179. if(NULL == m_pIWbemClassQualifierSet)
  1180. {
  1181. if(S_OK == (hr = m_pClass->GetQualifierSet(&m_pIWbemClassQualifierSet)))
  1182. hr = m_pIWbemClassQualifierSet->BeginEnumeration(0);
  1183. }
  1184. return hr;
  1185. }
  1186. //////////////////////////////////////////////////////////////////////////////////////////////////
  1187. HRESULT CWbemClassWrapper::GetPropertyQualifier(BSTR pPropertyQualifier, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1188. {
  1189. HRESULT hr;
  1190. // if( S_OK == (hr = IsValidPropertyQualifier(pPropertyQualifier)))
  1191. {
  1192. hr = m_pIWbemPropertyQualifierSet->Get(pPropertyQualifier,0, vValue, plFlavor);
  1193. //hr = m_pPropQualifList.GetPropertyQualifierSet(pPropertyQualifier)->Get(pPropertyQualifier,0, vValue, plFlavor);
  1194. }
  1195. return hr;
  1196. }
  1197. //////////////////////////////////////////////////////////////////////////////////////////////////
  1198. HRESULT CWbemClassWrapper::ValidClass( )
  1199. {
  1200. CBSTR bstrClassName(m_pParms->m_pwcsClassName);
  1201. IWbemClassObject *pClass = NULL;
  1202. HRESULT hr = 0;
  1203. //==========================================================
  1204. // NOTE: This is simply a utility class, we MUST have
  1205. // a valid pointer set when this class is constructed
  1206. //==========================================================
  1207. if( m_pClass == NULL ){
  1208. hr = m_pParms->GetServicesPtr()->GetObject(bstrClassName, 0, NULL, &pClass, NULL);
  1209. if( hr == WBEM_E_NOT_FOUND || hr == WBEM_E_INVALID_OBJECT_PATH)
  1210. return DB_E_NOTABLE;
  1211. else
  1212. if( hr == S_OK)
  1213. pClass->Release();
  1214. return MapWbemErrorToOLEDBError(hr);
  1215. }
  1216. return S_OK;
  1217. }
  1218. //////////////////////////////////////////////////////////////////////////////////////////////////
  1219. HRESULT CWbemClassWrapper::SetProperty(BSTR pProperty, VARIANT * vValue,CIMTYPE lType )
  1220. {
  1221. HRESULT hr = S_OK;
  1222. if(lType == -1)
  1223. {
  1224. hr = m_pClass->Put(pProperty,0, vValue,NULL);
  1225. }
  1226. else
  1227. {
  1228. hr = m_pClass->Put(pProperty,0, vValue,lType);
  1229. }
  1230. return MapWbemErrorToOLEDBError(hr);
  1231. }
  1232. //////////////////////////////////////////////////////////////////////////////////////////////////
  1233. HRESULT CWbemClassWrapper::SetPropertyQualifier(BSTR pProperty, BSTR Qualifier, VARIANT * vValue, LONG lQualifierFlags )
  1234. {
  1235. HRESULT hr;
  1236. //==============================================================
  1237. // If coming thru here the first time, get the qualifier set
  1238. // otherwise, just use it
  1239. //==============================================================
  1240. // hr = m_pClass->GetPropertyQualifierSet(pProperty, &m_pIWbemPropertyQualifierSet);
  1241. if( S_OK == (hr = IsValidPropertyQualifier(pProperty)))
  1242. {
  1243. hr = m_pPropQualifList.GetPropertyQualifierSet(pProperty)->Put(Qualifier, vValue, lQualifierFlags);
  1244. }
  1245. return MapWbemErrorToOLEDBError(hr);
  1246. }
  1247. //////////////////////////////////////////////////////////////////////////////////////////////////
  1248. HRESULT CWbemClassWrapper::DeletePropertyQualifier(BSTR pProperty, BSTR Qualifier )
  1249. {
  1250. HRESULT hr;
  1251. //==============================================================
  1252. // If coming thru here the first time, get the qualifier set
  1253. // otherwise, just use it
  1254. //==============================================================
  1255. // hr = m_pClass->GetPropertyQualifierSet(pProperty, &m_pIWbemPropertyQualifierSet);
  1256. if( S_OK == (hr = IsValidPropertyQualifier(pProperty)))
  1257. {
  1258. hr = m_pPropQualifList.GetPropertyQualifierSet(pProperty)->Delete(Qualifier);
  1259. }
  1260. if(hr == WBEM_E_NOT_FOUND)
  1261. {
  1262. hr = WBEMERROR_QUALIFIER_NOT_FOUND;
  1263. }
  1264. return MapWbemErrorToOLEDBError(hr);
  1265. }
  1266. //////////////////////////////////////////////////////////////////////////////////////////////////
  1267. HRESULT CWbemClassWrapper::BeginPropertyEnumeration()
  1268. {
  1269. LONG lFlags = (m_pParms->m_bSystemProperties == TRUE)? 0 : WBEM_FLAG_NONSYSTEM_ONLY;
  1270. HRESULT hr = m_pClass->BeginEnumeration(lFlags);
  1271. return MapWbemErrorToOLEDBError(hr);
  1272. }
  1273. //////////////////////////////////////////////////////////////////////////////////////////////////
  1274. HRESULT CWbemClassWrapper::EndPropertyEnumeration()
  1275. {
  1276. HRESULT hr = S_OK;
  1277. m_pClass->EndEnumeration();
  1278. return MapWbemErrorToOLEDBError(hr);
  1279. }
  1280. //////////////////////////////////////////////////////////////////////////////////////////////////
  1281. HRESULT CWbemClassWrapper::TotalPropertiesInClass(ULONG & ulPropCount, ULONG & ulSysPropCount)
  1282. {
  1283. HRESULT hr;
  1284. ulPropCount = 0L;
  1285. ulSysPropCount = 0;
  1286. LONG lFlavour = 0;
  1287. if( S_OK == (hr = BeginPropertyEnumeration())){
  1288. while( S_OK == (hr = GetNextProperty(NULL,NULL,NULL,&lFlavour))){
  1289. // If the property is system property increment the systemproperty count
  1290. if(lFlavour == WBEM_FLAVOR_ORIGIN_SYSTEM)
  1291. ulSysPropCount++;
  1292. else
  1293. ulPropCount ++;
  1294. }
  1295. if ( WBEM_S_NO_MORE_DATA == hr ){
  1296. hr = S_OK;
  1297. }
  1298. EndPropertyEnumeration();
  1299. }
  1300. return MapWbemErrorToOLEDBError(hr);
  1301. }
  1302. //////////////////////////////////////////////////////////////////////////////////////////////////
  1303. HRESULT CWbemClassWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1304. {
  1305. HRESULT hr;
  1306. if( !pProperty ){
  1307. hr = m_pClass->Next(0,NULL,NULL,pType,plFlavor);
  1308. }
  1309. else{
  1310. hr = m_pClass->Next(0,pProperty, vValue, pType, plFlavor);
  1311. }
  1312. return MapWbemErrorToOLEDBError(hr);
  1313. }
  1314. //////////////////////////////////////////////////////////////////////////////////////////////////
  1315. HRESULT CWbemClassWrapper::GetProperty(BSTR pProperty, VARIANT * var,CIMTYPE * pType , LONG * plFlavor )
  1316. {
  1317. HRESULT hr;
  1318. hr = m_pClass->Get(pProperty,0,var,pType,plFlavor);
  1319. return MapWbemErrorToOLEDBError(hr);
  1320. }
  1321. //////////////////////////////////////////////////////////////////////////////////////////////////
  1322. HRESULT CWbemClassWrapper::DeleteProperty(BSTR pProperty )
  1323. {
  1324. HRESULT hr;
  1325. hr = m_pClass->Delete(pProperty);
  1326. if( hr == WBEM_E_NOT_FOUND)
  1327. hr = WBEMERROR_PROPERTY_NOT_FOUND;
  1328. return MapWbemErrorToOLEDBError(hr);
  1329. }
  1330. //////////////////////////////////////////////////////////////////////////////////////////////////
  1331. // Function to get the number of qualifer for a property
  1332. HRESULT CWbemClassWrapper::TotalPropertyQualifier(BSTR strPropName , ULONG & ulCount )
  1333. {
  1334. HRESULT hr;
  1335. ulCount = 0L;
  1336. if( S_OK == (hr = BeginPropertyQualifierEnumeration(strPropName)))
  1337. {
  1338. while( S_OK == (hr = m_pIWbemPropertyQualifierSet->Next(0,NULL,NULL,NULL)))
  1339. {
  1340. ulCount ++;
  1341. }
  1342. if ( WBEM_S_NO_MORE_DATA == hr ){
  1343. hr = S_OK;
  1344. }
  1345. EndPropertyQualifierEnumeration();
  1346. }
  1347. return MapWbemErrorToOLEDBError(hr);
  1348. }
  1349. //////////////////////////////////////////////////////////////////////////////////////////////////
  1350. //Get the property qualifier and begin the enumeration
  1351. HRESULT CWbemClassWrapper::BeginPropertyQualifierEnumeration(BSTR strPropName)
  1352. {
  1353. HRESULT hr = S_OK;
  1354. //Release the previous quality Qualifier
  1355. if(m_pIWbemPropertyQualifierSet)
  1356. {
  1357. m_pIWbemPropertyQualifierSet->Release();
  1358. m_pIWbemPropertyQualifierSet = NULL;
  1359. }
  1360. if( S_OK == (hr = m_pClass->GetPropertyQualifierSet(strPropName,&m_pIWbemPropertyQualifierSet)))
  1361. hr = m_pIWbemPropertyQualifierSet->BeginEnumeration(0);
  1362. return MapWbemErrorToOLEDBError(hr);
  1363. }
  1364. HRESULT CWbemClassWrapper::GetPropertyQualifier(BSTR pProperty,BSTR PropertyQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor )
  1365. {
  1366. HRESULT hr = S_OK;
  1367. IWbemQualifierSet *pQualiferSet = NULL;
  1368. if( S_OK == (hr = IsValidPropertyQualifier(pProperty)))
  1369. {
  1370. pQualiferSet = m_pPropQualifList.GetPropertyQualifierSet(pProperty);
  1371. hr = pQualiferSet->Get(PropertyQualifier, 0,vValue, plFlavor);
  1372. }
  1373. return MapWbemErrorToOLEDBError(hr);
  1374. }
  1375. //////////////////////////////////////////////////////////////////////////////////////////////////
  1376. //Get the property qualifier and begin the enumeration
  1377. HRESULT CWbemClassWrapper::GetNextPropertyQualifier(BSTR pProperty, BSTR * pPropertyQualifier, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1378. {
  1379. HRESULT hr = S_OK;
  1380. IWbemQualifierSet * pQualiferSet = NULL;
  1381. WCHAR * pStrQualiferTemp = NULL;
  1382. DBROWOFFSET lRelativePos = 1;
  1383. if( S_OK == (hr = IsValidPropertyQualifier(pProperty)))
  1384. {
  1385. // IF the direction has changed compared to the previous fetch then
  1386. // the first fetch will be the last one fetched
  1387. if( m_pPropQualifList.GetQualiferPosObject(pProperty)->GetDirFlag() == FALSE)
  1388. lRelativePos = 0;
  1389. // Check if the qualifer is already fetched
  1390. hr = m_pPropQualifList.GetQualiferPosObject(pProperty)->GetRelative(lRelativePos,pStrQualiferTemp);
  1391. if( hr == WBEMERROR_QUALIFER_TOBE_FETCHED)
  1392. {
  1393. pQualiferSet = m_pPropQualifList.GetPropertyQualifierSet(pProperty);
  1394. if(S_OK ==(hr = pQualiferSet->Next(0,pPropertyQualifier, vValue, plFlavor)))
  1395. //NTRaid:111779
  1396. // 06/13/00
  1397. hr = m_pPropQualifList.GetQualiferPosObject(pProperty)->Add(*pPropertyQualifier);
  1398. }
  1399. // If already fetched get the qualifier name from the QualiferPosList
  1400. else
  1401. if( hr = S_OK)
  1402. {
  1403. *pPropertyQualifier = Wmioledb_SysAllocString(pStrQualiferTemp);
  1404. m_pPropQualifList.GetQualiferPosObject(pProperty)->SetRelPos(lRelativePos);
  1405. hr = GetPropertyQualifier(pProperty,*pPropertyQualifier,vValue,pType,plFlavor);
  1406. m_pPropQualifList.GetQualiferPosObject(pProperty)->SetDirFlag(FETCHDIRFORWARD);
  1407. }
  1408. }
  1409. return MapWbemErrorToOLEDBError(hr);
  1410. }
  1411. //////////////////////////////////////////////////////////////////////////////////////////////////
  1412. //Get the property qualifier
  1413. HRESULT CWbemClassWrapper::GetPrevPropertyQualifier(BSTR pProperty, BSTR * pPropertyQualifier, VARIANT * vValue,CIMTYPE * pType , LONG * plFlavor )
  1414. {
  1415. HRESULT hr = S_OK;
  1416. WCHAR *pStrQualiferTemp = NULL;
  1417. DBROWOFFSET lRelativePos = -1;
  1418. if( S_OK == (hr = IsValidPropertyQualifier(pProperty)))
  1419. {
  1420. // IF the direction has changed compared to the previous fetch then
  1421. // the first fetch will be the last one fetched
  1422. if( m_pPropQualifList.GetQualiferPosObject(pProperty)->GetDirFlag() == TRUE)
  1423. lRelativePos = 0;
  1424. // Get the name of the qualifier previous in the list
  1425. hr = m_pPropQualifList.GetQualiferPosObject(pProperty)->GetRelative(lRelativePos,pStrQualiferTemp);
  1426. if( hr == DB_E_BADSTARTPOSITION)
  1427. {
  1428. hr = DB_S_ENDOFROWSET;
  1429. }
  1430. if(hr == S_OK)
  1431. {
  1432. *pPropertyQualifier = Wmioledb_SysAllocString(pStrQualiferTemp);
  1433. m_pPropQualifList.GetQualiferPosObject(pProperty)->SetRelPos(lRelativePos);
  1434. hr = GetPropertyQualifier(pProperty,*pPropertyQualifier,vValue,pType,plFlavor);
  1435. m_pPropQualifList.GetQualiferPosObject(pProperty)->SetDirFlag(FETCHDIRBACKWARD);
  1436. }
  1437. }
  1438. return MapWbemErrorToOLEDBError(hr);
  1439. }
  1440. //////////////////////////////////////////////////////////////////////////////////////////////////
  1441. // End the property qualifer enumeration and release the pointers
  1442. HRESULT CWbemClassWrapper::EndPropertyQualifierEnumeration()
  1443. {
  1444. HRESULT hr = S_OK;
  1445. m_pIWbemPropertyQualifierSet->EndEnumeration();
  1446. m_pIWbemPropertyQualifierSet->Release();
  1447. m_pIWbemPropertyQualifierSet = NULL;
  1448. return MapWbemErrorToOLEDBError(hr);
  1449. }
  1450. //////////////////////////////////////////////////////////////////////////////////////////////////
  1451. HRESULT CWbemClassWrapper::SetClass( IWbemClassObject * pPtr)
  1452. {
  1453. HRESULT hr = S_OK;
  1454. if( pPtr ){
  1455. SAFE_RELEASE_PTR(m_pClass);
  1456. m_pClass = pPtr;
  1457. m_pClass->AddRef();
  1458. hr = S_OK;
  1459. }
  1460. return MapWbemErrorToOLEDBError(hr);
  1461. }
  1462. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1463. // if strPath parameter is NULL then the object to be obtained is same as the object represented by the
  1464. // connection. THis is because GetObject is not working for absolute UMI paths
  1465. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1466. CWbemClassWrapper * CWbemClassWrapper::GetInstance(BSTR strPath)
  1467. {
  1468. CWbemClassInstanceWrapper * pInst = NULL;
  1469. HRESULT hr = S_OK;
  1470. IWbemClassObject * pClass = NULL;
  1471. //============================================================
  1472. // Get the required instance
  1473. //============================================================
  1474. if(strPath == NULL)
  1475. {
  1476. hr = (m_pParms->GetServicesPtr())->QueryInterface(IID_IWbemClassObject,(void **)&pClass);
  1477. }
  1478. else
  1479. {
  1480. hr = (m_pParms->GetServicesPtr())->GetObject(strPath,0,m_pParms->GetContext(),&pClass ,NULL);
  1481. }
  1482. if( hr == S_OK )
  1483. {
  1484. pInst = new CWbemClassInstanceWrapper(m_pParms);
  1485. //NTRaid:111778
  1486. // 06/07/00
  1487. if(pInst)
  1488. {
  1489. pInst->SetClass(pClass );
  1490. }
  1491. SAFE_RELEASE_PTR(pClass);
  1492. }
  1493. return (CWbemClassWrapper *)pInst;
  1494. }
  1495. // Get the key properties
  1496. HRESULT CWbemClassWrapper::GetKeyPropertyNames( SAFEARRAY **ppsaNames)
  1497. {
  1498. HRESULT hr = S_OK;
  1499. hr = m_pClass->GetNames(NULL,WBEM_FLAG_ALWAYS | WBEM_FLAG_KEYS_ONLY , NULL, ppsaNames);
  1500. return MapWbemErrorToOLEDBError(hr);
  1501. }
  1502. //////////////////////////////////////////////////////////////////////////////////////////////////
  1503. // Function to get a next class/instance qualifer
  1504. //////////////////////////////////////////////////////////////////////////////////////////////////
  1505. HRESULT CWbemClassWrapper::GetNextClassQualifier(BSTR * pClassQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor )
  1506. {
  1507. HRESULT hr = S_OK;
  1508. WCHAR * pStrQualifierTemp = NULL;
  1509. DBROWOFFSET lRelativePos = 1;
  1510. if( S_OK == (hr = IsValidClassQualifier()))
  1511. {
  1512. // IF the direction has changed compared to the previous fetch then
  1513. // the first fetch will be the last one fetched
  1514. if( m_QualifierPos.GetDirFlag() == FALSE)
  1515. lRelativePos = 0;
  1516. // Check if the qualifer is already fetched
  1517. hr = m_QualifierPos.GetRelative(lRelativePos,pStrQualifierTemp);
  1518. if( hr == WBEMERROR_QUALIFER_TOBE_FETCHED)
  1519. {
  1520. if(S_OK ==( hr = m_pIWbemClassQualifierSet->Next(0,pClassQualifier, vValue, plFlavor)))
  1521. //NTRaid:111779
  1522. // 06/13/00
  1523. hr = m_QualifierPos.Add(*pClassQualifier);
  1524. }
  1525. else
  1526. if( hr == S_OK)
  1527. {
  1528. *pClassQualifier = Wmioledb_SysAllocString(pStrQualifierTemp);
  1529. m_QualifierPos.SetRelPos(lRelativePos);
  1530. hr = GetClassQualifier(*pClassQualifier,vValue,pType,plFlavor);
  1531. m_QualifierPos.SetDirFlag(FETCHDIRFORWARD);
  1532. }
  1533. }
  1534. return MapWbemErrorToOLEDBError(hr);
  1535. }
  1536. //////////////////////////////////////////////////////////////////////////////////////////////////
  1537. //Get the property qualifier and begin the enumeration
  1538. HRESULT CWbemClassWrapper::GetPrevClassQualifier(BSTR * pClassQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor )
  1539. {
  1540. HRESULT hr = S_OK;
  1541. WCHAR * pStrQualiferTemp = NULL;
  1542. DBROWOFFSET lRelativePos = 1;
  1543. if( S_OK == (hr = IsValidClassQualifier()))
  1544. {
  1545. // IF the direction has changed compared to the previous fetch then
  1546. // the first fetch will be the last one fetched
  1547. if( m_QualifierPos.GetDirFlag() == TRUE)
  1548. lRelativePos = 0;
  1549. // Get the name of the qualifier previous in the list
  1550. hr = m_QualifierPos.GetRelative(lRelativePos,pStrQualiferTemp);
  1551. if( hr == DB_E_BADSTARTPOSITION)
  1552. {
  1553. hr = DB_S_ENDOFROWSET;
  1554. }
  1555. if(hr == S_OK)
  1556. {
  1557. *pClassQualifier = Wmioledb_SysAllocString(pStrQualiferTemp);
  1558. m_QualifierPos.SetRelPos(lRelativePos);
  1559. hr = GetClassQualifier(*pClassQualifier,vValue,pType,plFlavor);
  1560. m_QualifierPos.SetDirFlag(FETCHDIRBACKWARD);
  1561. }
  1562. }
  1563. return MapWbemErrorToOLEDBError(hr);
  1564. }
  1565. //////////////////////////////////////////////////////////////////////////////////////////////////
  1566. // Function to get a particular class/instance qualifer
  1567. //////////////////////////////////////////////////////////////////////////////////////////////////
  1568. HRESULT CWbemClassWrapper::GetClassQualifier(BSTR ClassQualifier, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor )
  1569. {
  1570. HRESULT hr;
  1571. if( S_OK == (hr = IsValidClassQualifier()))
  1572. {
  1573. hr = m_pIWbemClassQualifierSet->Get(ClassQualifier,0, vValue, plFlavor);
  1574. }
  1575. return hr;
  1576. }
  1577. HRESULT CWbemClassWrapper::ReleaseClassQualifier()
  1578. {
  1579. HRESULT hr = S_OK;
  1580. if(m_pIWbemClassQualifierSet != NULL)
  1581. {
  1582. m_pIWbemClassQualifierSet->EndEnumeration();
  1583. m_pIWbemClassQualifierSet->Release();
  1584. m_pIWbemClassQualifierSet = NULL;
  1585. m_QualifierPos.RemoveAll();
  1586. }
  1587. return hr;
  1588. }
  1589. void CWbemClassWrapper::ReleasePropertyQualifier(BSTR strQualifier)
  1590. {
  1591. m_pPropQualifList.Remove(strQualifier);
  1592. }
  1593. // If qualifername parameter is null, then the class qualifer has
  1594. // to be positioned
  1595. HRESULT CWbemClassWrapper::SetQualifierRelPos(DBROWOFFSET lRelPos ,BSTR strPropertyName)
  1596. {
  1597. HRESULT hr = E_FAIL;
  1598. BSTR strQualifier;
  1599. if(strPropertyName != NULL)
  1600. {
  1601. if( S_OK == (hr = IsValidPropertyQualifier(strPropertyName)))
  1602. {
  1603. hr = m_pPropQualifList.GetQualiferPosObject(strPropertyName)->SetRelPos(lRelPos);
  1604. if(hr == WBEMERROR_QUALIFER_TOBE_FETCHED)
  1605. {
  1606. do
  1607. {
  1608. if(S_OK != (hr =m_pPropQualifList.GetPropertyQualifierSet(strPropertyName)->Next(0,&strQualifier, NULL, NULL)))
  1609. break;
  1610. else
  1611. {
  1612. //NTRaid:111779
  1613. // 06/13/00
  1614. if(FAILED(hr = m_pPropQualifList.GetQualiferPosObject(strPropertyName)->Add(strQualifier)))
  1615. {
  1616. SAFE_FREE_SYSSTRING(strQualifier);
  1617. break;
  1618. }
  1619. SAFE_FREE_SYSSTRING(strQualifier);
  1620. lRelPos--;
  1621. }
  1622. }while(hr == WBEMERROR_QUALIFER_TOBE_FETCHED || lRelPos != 0);
  1623. }
  1624. }
  1625. }
  1626. else
  1627. if( S_OK == (hr = IsValidClassQualifier()))
  1628. {
  1629. hr = m_QualifierPos.SetRelPos(lRelPos);
  1630. if(hr == WBEMERROR_QUALIFER_TOBE_FETCHED)
  1631. {
  1632. do
  1633. {
  1634. if(S_OK != (hr =m_pIWbemClassQualifierSet->Next(0,&strQualifier, NULL, NULL)))
  1635. break;
  1636. else
  1637. {
  1638. //NTRaid:111779
  1639. // 06/13/00
  1640. if(FAILED(hr = m_QualifierPos.Add(strQualifier)))
  1641. {
  1642. break;
  1643. SAFE_FREE_SYSSTRING(strQualifier);
  1644. }
  1645. lRelPos--;
  1646. SAFE_FREE_SYSSTRING(strQualifier);
  1647. }
  1648. }while(hr == WBEMERROR_QUALIFER_TOBE_FETCHED || lRelPos != 0);
  1649. }
  1650. }
  1651. if( hr == WBEM_E_NOT_FOUND)
  1652. {
  1653. hr = DB_E_BADSTARTPOSITION;
  1654. }
  1655. return hr;
  1656. }
  1657. //////////////////////////////////////////////////////////////////////////////////////////////////
  1658. HRESULT CWbemClassWrapper::SetClassQualifier(BSTR Qualifier, VARIANT * vValue, LONG lQualifierFlags )
  1659. {
  1660. HRESULT hr;
  1661. //==============================================================
  1662. // call this function to get the qualifer set if not obtained
  1663. //==============================================================
  1664. hr = IsValidClassQualifier();
  1665. if ( SUCCEEDED(hr) ){
  1666. hr = m_pIWbemClassQualifierSet->Put(Qualifier, vValue, lQualifierFlags);
  1667. }
  1668. return MapWbemErrorToOLEDBError(hr);
  1669. }
  1670. //////////////////////////////////////////////////////////////////////////////////////////////////
  1671. //************************************************************************************************
  1672. //
  1673. // Deal with a class definition
  1674. //
  1675. //************************************************************************************************
  1676. //////////////////////////////////////////////////////////////////////////////////////////////////
  1677. CWbemClassDefinitionWrapper::CWbemClassDefinitionWrapper( CWbemClassParameters * p,BOOL bGetClass ): CWbemClassWrapper(p)
  1678. { m_bSchema = FALSE;
  1679. if(bGetClass)
  1680. {
  1681. GetClass();
  1682. }
  1683. }
  1684. //////////////////////////////////////////////////////////////////////////////////////////////////
  1685. CWbemClassDefinitionWrapper::~CWbemClassDefinitionWrapper( )
  1686. {
  1687. }
  1688. //////////////////////////////////////////////////////////////////////////////////////////////////
  1689. HRESULT CWbemClassDefinitionWrapper::GetEmptyWbemClass( )
  1690. {
  1691. HRESULT hr;
  1692. SAFE_RELEASE_PTR(m_pClass);
  1693. hr = m_pParms->GetServicesPtr()->GetObject( NULL, 0, NULL, &m_pClass, NULL);
  1694. if( hr == S_OK ){
  1695. m_pClass->AddRef();
  1696. }
  1697. return MapWbemErrorToOLEDBError(hr);
  1698. }
  1699. //////////////////////////////////////////////////////////////////////////////////////////////////
  1700. HRESULT CWbemClassDefinitionWrapper::DeleteClass()
  1701. {
  1702. HRESULT hr = m_pParms->GetServicesPtr()->DeleteClass(m_pParms->m_pwcsClassName, WBEM_FLAG_RETURN_IMMEDIATELY,NULL,NULL);
  1703. return MapWbemErrorToOLEDBError(hr);
  1704. }
  1705. //////////////////////////////////////////////////////////////////////////////////////////////////
  1706. HRESULT CWbemClassDefinitionWrapper::GetClass( )
  1707. {
  1708. HRESULT hr = S_OK;
  1709. SAFE_RELEASE_PTR(m_pClass);
  1710. if(m_pParms->m_pwcsClassName != NULL)
  1711. {
  1712. CBSTR bstrClassName(m_pParms->m_pwcsClassName);
  1713. hr = m_pParms->GetServicesPtr()->GetObject(bstrClassName, 0, NULL, &m_pClass, NULL);
  1714. if( hr == S_OK ){
  1715. m_pClass->AddRef();
  1716. }
  1717. }
  1718. return MapWbemErrorToOLEDBError(hr);
  1719. }
  1720. //////////////////////////////////////////////////////////////////////////////////////////////////
  1721. HRESULT CWbemClassDefinitionWrapper::CreateClass()
  1722. {
  1723. HRESULT hr;
  1724. CBSTR bstrName(L"__Class");
  1725. CBSTR bstrClassName,bstrSuperClassName;
  1726. CVARIANT NameVal;
  1727. IWbemClassObject *pNewClass = NULL;
  1728. // Parse the class name if it contains the parent class name from which
  1729. // it is to be derived from
  1730. //NTRaid:111763 & NTRaid:111764
  1731. // 06/07/00
  1732. if( S_OK == (hr = m_pParms->ParseClassName()))
  1733. {
  1734. bstrClassName.SetStr(m_pParms->GetClassName());
  1735. bstrSuperClassName.SetStr( m_pParms->GetSuperClassName());
  1736. NameVal.SetStr(bstrClassName);
  1737. if( S_OK == (hr = m_pParms->GetServicesPtr()->GetObject(bstrSuperClassName, 0, NULL, &pNewClass, NULL)))
  1738. {
  1739. if(m_pParms->GetSuperClassName() != NULL)
  1740. hr = pNewClass->SpawnDerivedClass(0, &m_pClass);
  1741. else
  1742. hr = pNewClass->QueryInterface(IID_IWbemClassObject, (void **)&m_pClass);
  1743. SAFE_RELEASE_PTR(pNewClass);
  1744. // Set the name of the class
  1745. hr = m_pClass->Put((BSTR)bstrName, 0, &NameVal, CIM_STRING);
  1746. }
  1747. if( hr == WBEM_E_NOT_FOUND)
  1748. hr = WBEM_E_INVALID_CLASS;
  1749. }
  1750. return MapWbemErrorToOLEDBError(hr);
  1751. }
  1752. //////////////////////////////////////////////////////////////////////////////////////////////////
  1753. HRESULT CWbemClassDefinitionWrapper::DeleteClassQualifier(BSTR Qualifier)
  1754. {
  1755. HRESULT hr;
  1756. //==============================================================
  1757. // call this function to get the qualifer set if not obtained
  1758. //==============================================================
  1759. hr = IsValidClassQualifier();
  1760. if ( SUCCEEDED(hr) ){
  1761. hr = m_pIWbemClassQualifierSet->Delete(Qualifier);
  1762. }
  1763. if( hr == WBEM_E_NOT_FOUND)
  1764. {
  1765. hr = WBEMERROR_QUALIFIER_NOT_FOUND;
  1766. }
  1767. return MapWbemErrorToOLEDBError(hr);
  1768. }
  1769. //////////////////////////////////////////////////////////////////////////////////////////////////
  1770. // Method to change the class name to which the classdefination class points to
  1771. // NOTE:This method is to be called before fetching any instance
  1772. //////////////////////////////////////////////////////////////////////////////////////////////////
  1773. HRESULT CWbemClassDefinitionWrapper::SetClass( WCHAR *pClassName)
  1774. {
  1775. if(m_pParms->m_pwcsClassName != NULL)
  1776. delete [] m_pParms->m_pwcsClassName;
  1777. m_pParms->m_pwcsClassName = new WCHAR[wcslen(pClassName)+2];
  1778. wcscpy(m_pParms->m_pwcsClassName,pClassName);
  1779. SAFE_RELEASE_PTR(m_pClass);
  1780. HRESULT hr = S_OK;
  1781. CBSTR bstrClassName(m_pParms->m_pwcsClassName);
  1782. hr = m_pParms->GetServicesPtr()->GetObject(bstrClassName, 0, NULL, &m_pClass, NULL);
  1783. if( hr == S_OK ){
  1784. m_pClass->AddRef();
  1785. }
  1786. return MapWbemErrorToOLEDBError(hr);
  1787. }
  1788. //////////////////////////////////////////////////////////////////////////////////////////////////
  1789. // Method to save the the class defination into WMI
  1790. //////////////////////////////////////////////////////////////////////////////////////////////////
  1791. HRESULT CWbemClassDefinitionWrapper::SaveClass(BOOL bNewClass)
  1792. {
  1793. LONG lFlag = 0;
  1794. HRESULT hr = S_OK;
  1795. if(bNewClass == TRUE)
  1796. lFlag = WBEM_FLAG_CREATE_ONLY;
  1797. else
  1798. lFlag = WBEM_FLAG_UPDATE_ONLY;
  1799. hr = m_pParms->GetServicesPtr()->PutClass(m_pClass,lFlag,NULL,NULL);
  1800. return MapWbemErrorToOLEDBError(hr);
  1801. }
  1802. //////////////////////////////////////////////////////////////////////////////////////////////////
  1803. // Method to get the number of instances of a class
  1804. // This function executes a query "select __path from class" , so that time is reduced in
  1805. // getting the count
  1806. //////////////////////////////////////////////////////////////////////////////////////////////////
  1807. HRESULT CWbemClassDefinitionWrapper::GetInstanceCount(ULONG_PTR &cInstance)
  1808. {
  1809. HRESULT hr = E_FAIL;
  1810. cInstance = -1;
  1811. IEnumWbemClassObject *pEnum = NULL;
  1812. LONG_PTR lObjectsReturned = 0;
  1813. LONG_PTR lInstance = 0;
  1814. BSTR strWQL,strQry;
  1815. int nBuffSize = 0;
  1816. if(ValidClass() == S_OK)
  1817. {
  1818. nBuffSize = wcslen(szSelectCountQry) + wcslen(GetClassName()) + 1;
  1819. // If the query is not deep then add the where clause for the query
  1820. // to get just the instances of the class
  1821. if(WBEM_FLAG_DEEP != m_pParms->m_dwQueryFlags)
  1822. {
  1823. nBuffSize = nBuffSize + wcslen(szWhereClause) + wcslen(GetClassName()) + wcslen(szDoubleQuotes);
  1824. }
  1825. WCHAR *szCountQry = new WCHAR[nBuffSize];
  1826. //NTRaid:111773
  1827. // 06/07/00
  1828. if(szCountQry)
  1829. {
  1830. strWQL = Wmioledb_SysAllocString(szWQL);
  1831. // frame the query
  1832. wcscpy(szCountQry , szSelectCountQry);
  1833. wcscat(szCountQry , GetClassName());
  1834. // If the query is not deep then add the where clause for the query
  1835. // to get just the instances of the class
  1836. if(WBEM_FLAG_DEEP != m_pParms->m_dwQueryFlags)
  1837. {
  1838. wcscat(szCountQry,szWhereClause);
  1839. wcscat(szCountQry,GetClassName());
  1840. wcscat(szCountQry,szDoubleQuotes);
  1841. }
  1842. strQry = Wmioledb_SysAllocString(szCountQry);
  1843. // free the memory
  1844. delete [] szCountQry;
  1845. // Execute the query just to get the __Path property of the instances
  1846. hr = m_pParms->GetServicesPtr()->ExecQuery(strWQL, strQry,WBEM_FLAG_FORWARD_ONLY , m_pParms->GetContext(),&pEnum);
  1847. }
  1848. else
  1849. {
  1850. hr = E_OUTOFMEMORY;
  1851. }
  1852. if(hr == S_OK)
  1853. {
  1854. lInstance = 0;
  1855. do
  1856. {
  1857. // get NUMBEROFINSTANCESTOBEFETCHED at once and increment the count accordingly
  1858. CCOMPointer<IWbemClassObject > pObjects[NUMBEROFINSTANCESTOBEFETCHED];
  1859. hr = pEnum->Next(WBEM_INFINITE ,NUMBEROFINSTANCESTOBEFETCHED,(IWbemClassObject **)pObjects,(ULONG *)&lObjectsReturned);
  1860. if(!FAILED(hr))
  1861. {
  1862. lInstance += lObjectsReturned;
  1863. }
  1864. if(lObjectsReturned < NUMBEROFINSTANCESTOBEFETCHED)
  1865. {
  1866. break;
  1867. }
  1868. }
  1869. while(hr != WBEM_S_FALSE || !FAILED(hr));
  1870. hr = hr == WBEM_S_FALSE ? S_OK : hr;
  1871. // Release interfaces and free the string
  1872. pEnum->Release();
  1873. SysFreeString(strWQL);
  1874. SysFreeString(strQry);
  1875. }
  1876. }
  1877. else
  1878. {
  1879. hr = WBEM_E_INVALID_CLASS;
  1880. }
  1881. if( hr == S_OK)
  1882. cInstance = lInstance;
  1883. return MapWbemErrorToOLEDBError(hr);
  1884. }
  1885. //////////////////////////////////////////////////////////////////////////////////////////////////
  1886. //************************************************************************************************
  1887. //
  1888. // Deal with a class instance
  1889. //
  1890. //************************************************************************************************
  1891. //////////////////////////////////////////////////////////////////////////////////////////////////
  1892. CWbemClassInstanceWrapper::CWbemClassInstanceWrapper( CWbemClassParameters * p ): CWbemClassWrapper(p)
  1893. {
  1894. m_lPos = 0;
  1895. m_dwStatus = DBSTATUS_S_OK;
  1896. }
  1897. //////////////////////////////////////////////////////////////////////////////////////////////////
  1898. CWbemClassInstanceWrapper::~CWbemClassInstanceWrapper( )
  1899. {
  1900. }
  1901. //////////////////////////////////////////////////////////////////////////////////////////////////
  1902. HRESULT CWbemClassInstanceWrapper::GetKey(CBSTR & Key)
  1903. {
  1904. CVARIANT var;
  1905. HRESULT hr = S_OK;
  1906. if(FAILED(hr = GetProperty(L"__URL",var )))
  1907. {
  1908. hr = GetProperty(L"__PATH",var );
  1909. }
  1910. if( hr == S_OK ){
  1911. Key.SetStr(var.GetStr());
  1912. }
  1913. return MapWbemErrorToOLEDBError(hr);
  1914. }
  1915. //////////////////////////////////////////////////////////////////////////////////////////////////
  1916. HRESULT CWbemClassInstanceWrapper::ResetInstanceFromKey(CBSTR Key)
  1917. {
  1918. HRESULT hr;
  1919. SAFE_RELEASE_PTR(m_pClass);
  1920. hr = m_pParms->GetServicesPtr()->GetObject(Key, 0, NULL, &m_pClass, NULL);
  1921. if( hr == S_OK ){
  1922. m_pClass->AddRef();
  1923. }
  1924. return MapWbemErrorToOLEDBError(hr);
  1925. }
  1926. // Refresh the internal pointer of the instance
  1927. // Object is refreshed by getting object by __PATH for WMI object
  1928. // and __URL property for WMI objects returned by UMI Providers
  1929. HRESULT CWbemClassInstanceWrapper::RefreshInstance()
  1930. {
  1931. CBSTR strPath;
  1932. HRESULT hr = S_OK;
  1933. hr = GetKey(strPath);
  1934. if( hr == S_OK){
  1935. m_pClass->Release();
  1936. m_pClass = NULL;
  1937. hr = (m_pParms->GetServicesPtr())->GetObject(strPath,0,m_pParms->GetContext(),&m_pClass ,NULL);
  1938. }
  1939. if(hr == S_OK)
  1940. {
  1941. m_dwStatus = DBSTATUS_S_OK;
  1942. }
  1943. else
  1944. {
  1945. m_dwStatus = DBSTATUS_E_UNAVAILABLE;
  1946. }
  1947. return MapWbemErrorToOLEDBError(hr);
  1948. }
  1949. ////////////////////////////////////////////////////////////////////////////////////////////
  1950. // Get the name of the class to which the instance belongs
  1951. // THe returned pointer is to be cleaned by the callee
  1952. ////////////////////////////////////////////////////////////////////////////////////////////
  1953. WCHAR * CWbemClassInstanceWrapper::GetClassName()
  1954. {
  1955. WCHAR *pClass = NULL;
  1956. BSTR strPropName;
  1957. HRESULT hr = 0;
  1958. strPropName = Wmioledb_SysAllocString(L"__Class");
  1959. VARIANT varClassName;
  1960. VariantInit(&varClassName);
  1961. // Get the class name
  1962. hr = m_pClass->Get(strPropName,0, &varClassName , NULL , NULL);
  1963. SysFreeString(strPropName);
  1964. if( hr == S_OK)
  1965. {
  1966. AllocateAndCopy(pClass,varClassName.bstrVal);
  1967. VariantClear(&varClassName);
  1968. }
  1969. return pClass;
  1970. }
  1971. HRESULT CWbemClassInstanceWrapper::CloneInstance(IWbemClassObject *& pInstance)
  1972. {
  1973. HRESULT hr = S_OK;
  1974. pInstance = NULL;
  1975. hr = m_pClass->Clone(&pInstance);
  1976. return MapWbemErrorToOLEDBError(hr);
  1977. }
  1978. // function which get the RElative path
  1979. // Gets __RELURL property for objects of UMI
  1980. // gets the __RELPATH for normal WMI objects ( as __RELURL property fetching fails)
  1981. HRESULT CWbemClassInstanceWrapper::GetRelativePath(WCHAR *& pstrRelPath)
  1982. {
  1983. HRESULT hr = S_OK;
  1984. VARIANT varRelPath;
  1985. VariantInit(&varRelPath);
  1986. LONG nStringLen = 0;
  1987. if(FAILED(hr = m_pClass->Get(L"__RELURL",0,&varRelPath,NULL,NULL)))
  1988. {
  1989. hr = m_pClass->Get(L"__RELPATH",0,&varRelPath,NULL,NULL);
  1990. }
  1991. if(SUCCEEDED(hr))
  1992. {
  1993. if(varRelPath.vt == VT_BSTR && varRelPath.bstrVal != NULL)
  1994. {
  1995. nStringLen = (SysStringLen(varRelPath.bstrVal) +1) * sizeof(WCHAR);
  1996. pstrRelPath = NULL;
  1997. pstrRelPath = new WCHAR[nStringLen];
  1998. if(pstrRelPath)
  1999. {
  2000. memset(pstrRelPath,0, nStringLen);
  2001. memcpy(pstrRelPath,varRelPath.bstrVal,nStringLen-sizeof(WCHAR));
  2002. }
  2003. else
  2004. {
  2005. hr = E_OUTOFMEMORY;
  2006. }
  2007. }
  2008. else
  2009. {
  2010. E_FAIL;
  2011. }
  2012. VariantClear(&varRelPath);
  2013. }
  2014. return MapWbemErrorToOLEDBError(hr);
  2015. }
  2016. //////////////////////////////////////////////////////////////////////////////////////////////////
  2017. //************************************************************************************************
  2018. //
  2019. // Manage class instance list
  2020. //
  2021. //************************************************************************************************
  2022. //////////////////////////////////////////////////////////////////////////////////////////////////
  2023. CWbemInstanceList::CWbemInstanceList(CWbemClassParameters * pParms)
  2024. {
  2025. m_pParms = pParms;
  2026. m_ppEnum = NULL;
  2027. m_lCurrentPos = 0;
  2028. m_FetchDir = FETCHDIRNONE;
  2029. m_nBaseType = FALSE;
  2030. m_cTotalInstancesInEnum = 0;
  2031. InitializeCriticalSection(&m_InstanceCs);
  2032. }
  2033. //////////////////////////////////////////////////////////////////////////////////////////////////
  2034. CWbemInstanceList::~CWbemInstanceList()
  2035. {
  2036. ReleaseAllInstances();
  2037. DeleteCriticalSection(&m_InstanceCs);
  2038. SAFE_RELEASE_PTR(m_ppEnum);
  2039. }
  2040. //////////////////////////////////////////////////////////////////////////////////////////////////
  2041. HRESULT CWbemInstanceList::ReleaseAllInstances()
  2042. {
  2043. HRESULT hr = S_OK;
  2044. //==========================================================================
  2045. // Enter the critical section
  2046. //==========================================================================
  2047. Enter();
  2048. //==========================================================================
  2049. // Go through the instances one at a time and close them, then delete them
  2050. //==========================================================================
  2051. int nSize = m_List.Size();
  2052. if( nSize > 0 ){
  2053. for(int i = 0; i < nSize; i++){
  2054. CWbemClassInstanceWrapper * pClass = (CWbemClassInstanceWrapper*) m_List[i];
  2055. SAFE_DELETE_PTR(pClass);
  2056. }
  2057. m_List.Empty();
  2058. }
  2059. m_lCurrentPos = 0;
  2060. //==========================================================================
  2061. // Leave Critical Section
  2062. //==========================================================================
  2063. Leave();
  2064. return MapWbemErrorToOLEDBError(hr);
  2065. }
  2066. //////////////////////////////////////////////////////////////////////////////////////////////////
  2067. HRESULT CWbemInstanceList::DeleteInstance( CWbemClassInstanceWrapper *& pClass )
  2068. {
  2069. HRESULT hr;
  2070. CBSTR strPath;
  2071. pClass->GetKey(strPath);
  2072. //=======================================================================
  2073. // Delete the instance from CIMOM
  2074. //=======================================================================
  2075. hr = (m_pParms->GetServicesPtr())->DeleteInstance((BSTR)strPath,0,m_pParms->GetContext(),NULL);
  2076. if( hr == S_OK ){
  2077. // hr = ReleaseInstance(pClass);
  2078. pClass->SetStatus(DBROWSTATUS_E_DELETED);
  2079. if(m_cTotalInstancesInEnum)
  2080. m_cTotalInstancesInEnum--;
  2081. }
  2082. return MapWbemErrorToOLEDBError(hr);
  2083. }
  2084. //////////////////////////////////////////////////////////////////////////////////////////////////
  2085. HRESULT CWbemInstanceList::AddInstance( CWbemClassInstanceWrapper * pClass )
  2086. {
  2087. //==========================================================================
  2088. // Enter Critical Section
  2089. //==========================================================================
  2090. Enter();
  2091. //==========================================================================
  2092. // Add it to the list
  2093. //==========================================================================
  2094. m_List.Add(pClass);
  2095. //==========================================================================
  2096. // Leave Critical Section
  2097. //==========================================================================
  2098. Leave();
  2099. return MapWbemErrorToOLEDBError(S_OK);
  2100. }
  2101. ////////////////////////////////////////////////////////////////////////////////////////////////
  2102. HRESULT CWbemInstanceList::ReleaseInstance(CWbemClassInstanceWrapper *& pClass)
  2103. {
  2104. //========================================================================
  2105. // Enter the critical section
  2106. //========================================================================
  2107. Enter();
  2108. //========================================================================
  2109. // Look for it in the list
  2110. //========================================================================
  2111. HRESULT hr = DB_E_NOTFOUND;
  2112. int n = 0;
  2113. for(int i = 0; i < m_List.Size(); i++){
  2114. CWbemClassInstanceWrapper * pClassInList = (CWbemClassInstanceWrapper * ) m_List[i];
  2115. if(pClass == pClassInList){
  2116. n = i;
  2117. hr = S_OK;
  2118. break;
  2119. }
  2120. }
  2121. //========================================================================
  2122. // If we found it, then delete it from the list.
  2123. // The deconstructor will release the wbem class object
  2124. //========================================================================
  2125. if( S_OK == hr ){
  2126. m_List.RemoveAt(n);
  2127. delete pClass;
  2128. pClass = NULL;
  2129. }
  2130. //========================================================================
  2131. // Leave critical section
  2132. //========================================================================
  2133. Leave();
  2134. return MapWbemErrorToOLEDBError(hr);
  2135. }
  2136. ////////////////////////////////////////////////////////////////////////////////////////////////
  2137. HRESULT CWbemInstanceList::NextInstance( CBSTR & Key, CWbemClassInstanceWrapper ** pInst)
  2138. {
  2139. LONG lRelativePos = 1;
  2140. HRESULT hr = E_FAIL;
  2141. //============================================================
  2142. // Now, enumerate all of the instances
  2143. //============================================================
  2144. if( m_ppEnum ){
  2145. // IF the direction has changed compared to the previous fetch then
  2146. // the first fetch will be the last one fetched
  2147. if( m_FetchDir == FETCHDIRBACKWARD)
  2148. lRelativePos = 0;
  2149. // Check if the instance is already fetched
  2150. *pInst = GetInstance(m_lCurrentPos +lRelativePos);
  2151. if( *pInst == NULL){
  2152. unsigned long u;
  2153. IWbemClassObject * pClass = NULL;
  2154. hr = m_ppEnum->Next(0,1,&pClass,&u);
  2155. if( hr == S_OK ){
  2156. switch( m_nBaseType )
  2157. {
  2158. case COMMAND_ROWSET:
  2159. *pInst = new CWbemCommandInstanceWrapper(m_pParms,((CWbemCommandParameters*)m_pParms)->GetCommandManagerPtr());
  2160. break;
  2161. case SOURCES_ROWSET:
  2162. *pInst = (CWbemSchemaSourcesInstanceWrapper *) new CWbemSchemaSourcesInstanceWrapper(m_pParms);
  2163. break;
  2164. case PROVIDER_TYPES_ROWSET:
  2165. *pInst = (CWbemSchemaProviderTypesInstanceWrapper *) new CWbemSchemaProviderTypesInstanceWrapper(m_pParms);
  2166. break;
  2167. case CATALOGS_ROWSET:
  2168. *pInst = (CWbemSchemaCatalogsInstanceWrapper *) new CWbemSchemaCatalogsInstanceWrapper(m_pParms);
  2169. break;
  2170. case COLUMNS_ROWSET:
  2171. *pInst = (CWbemSchemaColumnsInstanceWrapper *) new CWbemSchemaColumnsInstanceWrapper(m_pParms);
  2172. break;
  2173. case TABLES_ROWSET:
  2174. *pInst = (CWbemSchemaTablesInstanceWrapper *) new CWbemSchemaTablesInstanceWrapper(m_pParms);
  2175. break;
  2176. case PRIMARY_KEYS_ROWSET:
  2177. *pInst = (CWbemSchemaPrimaryKeysInstanceWrapper *) new CWbemSchemaPrimaryKeysInstanceWrapper(m_pParms);
  2178. break;
  2179. case TABLES_INFO_ROWSET:
  2180. *pInst = (CWbemSchemaTablesInfoInstanceWrapper *) new CWbemSchemaTablesInfoInstanceWrapper(m_pParms);
  2181. break;
  2182. default:
  2183. *pInst = new CWbemClassInstanceWrapper(m_pParms);
  2184. }
  2185. //NTRaid:111798 & 111799
  2186. // 06/07/00
  2187. if(*pInst)
  2188. {
  2189. (*pInst)->SetClass(pClass);
  2190. (*pInst)->SetPos(++m_lCurrentPos);
  2191. AddInstance(*pInst);
  2192. (*pInst)->GetKey(Key);
  2193. }
  2194. else
  2195. {
  2196. hr = E_OUTOFMEMORY;
  2197. }
  2198. }
  2199. SAFE_RELEASE_PTR(pClass);
  2200. }
  2201. else
  2202. {
  2203. // Adjust the enumerator to position to the current positon
  2204. if(( m_lCurrentPos +lRelativePos) > m_lCurrentPos)
  2205. hr = m_ppEnum->Skip(WBEM_INFINITE ,(LONG)lRelativePos);
  2206. m_lCurrentPos += lRelativePos;
  2207. m_FetchDir = FETCHDIRFORWARD;
  2208. (*pInst)->GetKey(Key);
  2209. hr = S_OK;
  2210. }
  2211. }
  2212. return hr;
  2213. }
  2214. ////////////////////////////////////////////////////////////////////////////////////////////////
  2215. HRESULT CWbemInstanceList::UpdateInstance(CWbemClassInstanceWrapper * pInstance, BOOL bNewInst)
  2216. {
  2217. HRESULT hr;
  2218. LONG lFlag = 0;
  2219. if(bNewInst == TRUE)
  2220. lFlag = WBEM_FLAG_CREATE_ONLY;
  2221. else
  2222. lFlag = WBEM_FLAG_UPDATE_ONLY;
  2223. hr = (m_pParms->GetServicesPtr())->PutInstance(pInstance->GetClassObject(),lFlag,m_pParms->GetContext(),NULL);
  2224. return MapWbemErrorToOLEDBError(hr);
  2225. }
  2226. //////////////////////////////////////////////////////////////////////////////////////////////////
  2227. HRESULT CWbemInstanceList::Reset()
  2228. {
  2229. HRESULT hr = E_UNEXPECTED;
  2230. BOOL bGetInstanceEnum = TRUE;
  2231. //============================================================
  2232. // If we already got an enumeration, reset it, otherwise
  2233. // don't
  2234. //============================================================
  2235. if( m_ppEnum ){
  2236. if(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags)
  2237. {
  2238. ReleaseAllInstances();
  2239. m_ppEnum->Release();
  2240. m_ppEnum = NULL;
  2241. }
  2242. else
  2243. {
  2244. hr = m_ppEnum->Reset();
  2245. //ReleaseAllInstances();
  2246. bGetInstanceEnum = FALSE;
  2247. }
  2248. }
  2249. if(bGetInstanceEnum == TRUE)
  2250. {
  2251. CBSTR bstrClassName(m_pParms->m_pwcsClassName);
  2252. hr = (m_pParms->GetServicesPtr())->CreateInstanceEnum(bstrClassName,
  2253. m_pParms->m_dwNavFlags | m_pParms->m_dwQueryFlags,
  2254. m_pParms->GetContext(),
  2255. &m_ppEnum);
  2256. if( hr == S_OK)
  2257. m_cTotalInstancesInEnum = 0;
  2258. }
  2259. if(hr == S_OK)
  2260. {
  2261. m_lCurrentPos = 0;
  2262. // m_FetchDir = FETCHDIRFORWARD;
  2263. }
  2264. return MapWbemErrorToOLEDBError(hr);
  2265. }
  2266. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2267. HRESULT CWbemInstanceList::AddNewInstance(CWbemClassWrapper *pClassWrappper, CWbemClassInstanceWrapper ** ppNewClass )
  2268. {
  2269. IWbemClassObject *pInstClassObject = NULL;
  2270. CWbemClassInstanceWrapper * pInst = NULL;
  2271. HRESULT hr = S_OK;
  2272. //==========================================================================
  2273. // Enter Critical Section
  2274. //==========================================================================
  2275. Enter();
  2276. //==========================================================================
  2277. // create a new instance
  2278. //==========================================================================
  2279. hr = pClassWrappper->GetClass()->SpawnInstance(0, &pInstClassObject);
  2280. if( hr == S_OK ){
  2281. *ppNewClass = new CWbemClassInstanceWrapper(m_pParms);
  2282. //NTRaid:111776 & NTRaid:111777
  2283. // 06/07/00
  2284. if(*ppNewClass)
  2285. {
  2286. (*ppNewClass)->SetClass(pInstClassObject);
  2287. (*ppNewClass)->SetPos(++m_lCurrentPos);
  2288. AddInstance(*ppNewClass);
  2289. if(m_cTotalInstancesInEnum)
  2290. m_cTotalInstancesInEnum++;
  2291. }
  2292. else
  2293. {
  2294. hr = E_OUTOFMEMORY;
  2295. }
  2296. SAFE_RELEASE_PTR(pInstClassObject);
  2297. }
  2298. //==========================================================================
  2299. // Leave Critical Section
  2300. //==========================================================================
  2301. Leave();
  2302. return MapWbemErrorToOLEDBError(hr);
  2303. }
  2304. /*/////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2305. // Function called for instances embededed in another instance.
  2306. // This function adds the instance pointed by dispatch to the CWbemInstanceList
  2307. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2308. CWbemClassInstanceWrapper * CWbemInstanceList::AddInstanceToList( IUnknown *pDisp,CBSTR & Key)
  2309. {
  2310. IWbemClassObject * pClassObj = NULL;
  2311. HRESULT hr = S_OK;
  2312. CWbemClassInstanceWrapper * pInst = NULL;
  2313. hr = pDisp->QueryInterface(IID_IWbemClassObject , (void **) &pClassObj);
  2314. if( hr == S_OK)
  2315. {
  2316. pInst = new CWbemClassInstanceWrapper(m_pParms);
  2317. //NTRaid:111774 & NTRaid:111775
  2318. // 06/07/00
  2319. if(pInst)
  2320. {
  2321. pInst->SetClass(pClassObj);
  2322. pInst->SetPos(++m_lCurrentPos);
  2323. AddInstance(pInst);
  2324. pInst->GetKey(Key);
  2325. }
  2326. SAFE_RELEASE_PTR(pClassObj);;
  2327. }
  2328. return pInst;
  2329. }
  2330. */
  2331. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2332. // Function to get a previous instance in the enumerator
  2333. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2334. HRESULT CWbemInstanceList::PrevInstance( CBSTR & Key,CWbemClassInstanceWrapper *& pInst )
  2335. {
  2336. HRESULT hr = S_OK;
  2337. DBROWOFFSET lRelativePos = -1;
  2338. IWbemClassObject * pClass = NULL;
  2339. ULONG u = 0;
  2340. pInst = NULL;
  2341. BOOL bResetDone = FALSE;
  2342. // if the first call after initialization / restartPositon of rowset is getting
  2343. // instance in reverse direction then
  2344. if( !(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags) && m_lCurrentPos == 0 && m_FetchDir == FETCHDIRFORWARD)
  2345. {
  2346. if(!m_cTotalInstancesInEnum)
  2347. if(S_OK != (hr = GetNumberOfInstanceInEnumerator()))
  2348. return MapWbemErrorToOLEDBError(hr);
  2349. if((LONG)(m_cTotalInstancesInEnum - lRelativePos) > 0)
  2350. {
  2351. m_lCurrentPos = m_cTotalInstancesInEnum;
  2352. }
  2353. else
  2354. hr = E_FAIL;
  2355. }
  2356. else
  2357. if( (m_lCurrentPos + lRelativePos) == 0 && m_FetchDir == FETCHDIRBACKWARD)
  2358. return E_FAIL;
  2359. else
  2360. {
  2361. // IF the direction has changed compared to the previous fetch then
  2362. // the first fetch will be the last one fetched
  2363. if( m_FetchDir == FETCHDIRFORWARD)
  2364. lRelativePos = 0;
  2365. // Reset the position to the so that
  2366. // NextInstance function gives the instance required
  2367. hr = ResetRelPosition(lRelativePos);
  2368. }
  2369. pInst = GetInstance(m_lCurrentPos);
  2370. if(pInst == NULL)
  2371. {
  2372. bResetDone = TRUE;
  2373. // restore the original position
  2374. if(!(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags))
  2375. {
  2376. m_ppEnum->Reset();
  2377. m_ppEnum->Skip(WBEM_INFINITE,(LONG)(m_lCurrentPos - 1));
  2378. hr = m_ppEnum->Next(0,1,&pClass,&u);
  2379. if( hr == S_OK )
  2380. {
  2381. switch( m_nBaseType ){
  2382. case COMMAND_ROWSET:
  2383. pInst = (CWbemClassInstanceWrapper *) new CWbemCommandInstanceWrapper(m_pParms,((CWbemCommandParameters*)m_pParms)->GetCommandManagerPtr());
  2384. break;
  2385. case SOURCES_ROWSET:
  2386. pInst = (CWbemClassInstanceWrapper *) new CWbemSchemaSourcesInstanceWrapper(m_pParms);
  2387. break;
  2388. case PROVIDER_TYPES_ROWSET:
  2389. pInst = (CWbemClassInstanceWrapper *) new CWbemSchemaProviderTypesInstanceWrapper(m_pParms);
  2390. break;
  2391. case CATALOGS_ROWSET:
  2392. pInst = (CWbemSchemaCatalogsInstanceWrapper *) new CWbemSchemaCatalogsInstanceWrapper(m_pParms);
  2393. break;
  2394. case COLUMNS_ROWSET:
  2395. pInst = (CWbemSchemaColumnsInstanceWrapper *) new CWbemSchemaColumnsInstanceWrapper(m_pParms);
  2396. break;
  2397. case TABLES_ROWSET:
  2398. pInst = (CWbemSchemaTablesInstanceWrapper *) new CWbemSchemaTablesInstanceWrapper(m_pParms);
  2399. break;
  2400. case PRIMARY_KEYS_ROWSET:
  2401. pInst = (CWbemSchemaPrimaryKeysInstanceWrapper *) new CWbemSchemaPrimaryKeysInstanceWrapper(m_pParms);
  2402. break;
  2403. case TABLES_INFO_ROWSET:
  2404. pInst = (CWbemSchemaTablesInfoInstanceWrapper *) new CWbemSchemaTablesInfoInstanceWrapper(m_pParms);
  2405. break;
  2406. default:
  2407. pInst = new CWbemClassInstanceWrapper(m_pParms);
  2408. }
  2409. //NTRaid:111796-111797
  2410. // 06/07/00
  2411. if(pInst)
  2412. {
  2413. (pInst)->SetClass(pClass);
  2414. (pInst)->SetPos(m_lCurrentPos);
  2415. AddInstance(pInst);
  2416. // (pInst)->GetKey(Key);
  2417. }
  2418. else
  2419. {
  2420. hr = E_OUTOFMEMORY;
  2421. }
  2422. }
  2423. SAFE_RELEASE_PTR(pClass);
  2424. }
  2425. }
  2426. if(pInst != NULL)
  2427. {
  2428. pInst->GetKey(Key);
  2429. m_FetchDir = FETCHDIRBACKWARD; // setting that the last fetch was backwards
  2430. // m_lCurrentPos = m_lCurrentPos + lRelativePos;
  2431. }
  2432. else
  2433. {
  2434. if(bResetDone)
  2435. hr = ResetRelPosition(lRelativePos * (-1));
  2436. hr = E_OUTOFMEMORY;
  2437. }
  2438. return hr;
  2439. }
  2440. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2441. // Function which returns the instance pointer given the position if already retrieved
  2442. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2443. CWbemClassInstanceWrapper * CWbemInstanceList::GetInstance( ULONG_PTR lPos )
  2444. {
  2445. CWbemClassInstanceWrapper * pInst = NULL ;
  2446. for(int i = 0; i < m_List.Size(); i++)
  2447. {
  2448. CWbemClassInstanceWrapper *pTempInst = (CWbemClassInstanceWrapper * ) m_List[i];
  2449. if(pTempInst->GetPos() == lPos)
  2450. {
  2451. pInst = pTempInst;
  2452. break;
  2453. }
  2454. }
  2455. return pInst;
  2456. }
  2457. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2458. // Function to reset the positon by the number of instance specified
  2459. // so that the NextInstance function gives the instance required
  2460. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2461. HRESULT CWbemInstanceList::ResetRelPosition( DBROWOFFSET lPos )
  2462. {
  2463. DBROWOFFSET lPosRequired = 0;
  2464. HRESULT hr = E_FAIL;
  2465. CWbemClassInstanceWrapper * pInst = NULL;
  2466. // Get the position at which the enumerator to be pointed to
  2467. lPosRequired = m_lCurrentPos + lPos;
  2468. if( lPosRequired > 0)
  2469. {
  2470. // If skipping is forward then skip by the number of positions
  2471. if(lPos > 0)
  2472. {
  2473. if(S_OK == (hr = m_ppEnum->Skip(WBEM_INFINITE ,(LONG)lPos)))
  2474. m_lCurrentPos = lPosRequired;
  2475. else
  2476. // restore the original position
  2477. if(!(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags))
  2478. {
  2479. m_ppEnum->Reset();
  2480. hr = m_ppEnum->Skip(WBEM_INFINITE,(LONG)m_lCurrentPos);
  2481. hr = E_FAIL;
  2482. }
  2483. }
  2484. // Else if skipping is negative , then
  2485. else
  2486. if( lPos < 0)
  2487. {
  2488. // If enumerator is not forward only then skip Reset
  2489. // the begining and spip to the position required
  2490. if(!(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags))
  2491. {
  2492. if(S_OK == (hr = m_ppEnum->Reset()))
  2493. {
  2494. if(S_OK == (hr = m_ppEnum->Skip(WBEM_INFINITE ,(LONG)lPosRequired)))
  2495. m_lCurrentPos = lPosRequired;
  2496. else
  2497. {
  2498. m_ppEnum->Reset();
  2499. hr = m_ppEnum->Skip(WBEM_INFINITE,(LONG)m_lCurrentPos);
  2500. hr = E_FAIL;
  2501. }
  2502. }
  2503. }
  2504. // other wise if the enumerator is forward only return
  2505. // error
  2506. else
  2507. hr = E_FAIL;
  2508. }
  2509. else
  2510. hr = S_OK;
  2511. }
  2512. else
  2513. if(lPosRequired == 0 && !(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags))
  2514. {
  2515. hr = m_ppEnum->Reset();
  2516. m_lCurrentPos = lPosRequired;
  2517. }
  2518. else
  2519. // if the initial position is negative when the enumerator is at the begining then
  2520. if(lPosRequired < 0 && !(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags) && m_lCurrentPos == 0)
  2521. {
  2522. if(!m_cTotalInstancesInEnum)
  2523. if(S_OK != (hr = GetNumberOfInstanceInEnumerator()))
  2524. return MapWbemErrorToOLEDBError(hr);
  2525. if((LONG)(m_cTotalInstancesInEnum + lPos) > 0)
  2526. {
  2527. hr = m_ppEnum->Reset();
  2528. if(S_OK == (hr = m_ppEnum->Skip(WBEM_INFINITE,(LONG)(m_cTotalInstancesInEnum + lPos))))
  2529. m_lCurrentPos = m_cTotalInstancesInEnum + lPos;
  2530. }
  2531. else
  2532. hr = E_FAIL;
  2533. }
  2534. return MapWbemErrorToOLEDBError(hr);
  2535. }
  2536. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2537. // Function to get the number of instances in a enumerator
  2538. //
  2539. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2540. HRESULT CWbemInstanceList::GetNumberOfInstanceInEnumerator(ULONG_PTR *pcInstance)
  2541. {
  2542. ULONG ulObj = 0;
  2543. HRESULT hr = S_OK;
  2544. m_cTotalInstancesInEnum = 0;
  2545. int i = 0;
  2546. if(S_OK == (hr = m_ppEnum->Reset()))
  2547. {
  2548. // Calculate the number of instance in the enumerator
  2549. while(S_OK == hr)
  2550. {
  2551. {
  2552. CCOMPointer<IWbemClassObject > pObjects[NUMBEROFINSTANCESTOBEFETCHED];
  2553. hr = m_ppEnum->Next(0,NUMBEROFINSTANCESTOBEFETCHED,(IWbemClassObject **)pObjects , &ulObj);
  2554. }
  2555. if( hr == S_OK || hr == WBEM_S_FALSE)
  2556. m_cTotalInstancesInEnum += ulObj;
  2557. }
  2558. // Bring back to the original position
  2559. if((S_OK == (hr = m_ppEnum->Reset())) && m_lCurrentPos != 0)
  2560. hr = m_ppEnum->Skip(WBEM_INFINITE ,(LONG)m_lCurrentPos);
  2561. }
  2562. if(SUCCEEDED(hr) && &pcInstance)
  2563. {
  2564. *pcInstance = m_cTotalInstancesInEnum;
  2565. }
  2566. return hr;
  2567. }
  2568. /***********************************************************************************************************
  2569. Class CWbemPropertyQualifierList implementation
  2570. /***********************************************************************************************************/
  2571. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2572. // Destructor
  2573. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2574. CWbemPropertyQualifierList::~CWbemPropertyQualifierList()
  2575. {
  2576. RemoveAll();
  2577. }
  2578. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2579. // Remove all elements from the list
  2580. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2581. void CWbemPropertyQualifierList::RemoveAll()
  2582. {
  2583. CWbemPropertyQualifierWrapper *pQualifWrap = NULL;
  2584. int nSize = m_QualifierList.Size();
  2585. if(m_QualifierList.Size() > 0)
  2586. for( int nIndex = nSize-1 ; nIndex >= 0 ; nIndex--)
  2587. {
  2588. pQualifWrap = (CWbemPropertyQualifierWrapper *)m_QualifierList[nIndex];
  2589. m_QualifierList.RemoveAt(nIndex);
  2590. pQualifWrap->m_pIWbemPropertyQualifierSet->EndEnumeration();
  2591. SAFE_DELETE_PTR(pQualifWrap);
  2592. }
  2593. }
  2594. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2595. // add a Element to the list
  2596. //NTRaid:111779
  2597. // 06/13/00
  2598. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2599. HRESULT CWbemPropertyQualifierList::Add(IWbemQualifierSet* pQualifierSet,WCHAR *pwstrPropertyName)
  2600. {
  2601. CWbemPropertyQualifierWrapper *pNewQualifWrap = NULL;
  2602. pNewQualifWrap = new CWbemPropertyQualifierWrapper;
  2603. HRESULT hr = S_OK;
  2604. // NTRaid:111779 & NTRaid:111780
  2605. // 06/07/00
  2606. if(pNewQualifWrap)
  2607. {
  2608. pNewQualifWrap->m_pIWbemPropertyQualifierSet = pQualifierSet;
  2609. pNewQualifWrap->m_pwstrPropertyName = new WCHAR[wcslen(pwstrPropertyName) + 1];
  2610. if(pNewQualifWrap->m_pwstrPropertyName)
  2611. {
  2612. wcscpy(pNewQualifWrap->m_pwstrPropertyName,pwstrPropertyName);
  2613. //NTRaid:111779
  2614. // 06/13/00
  2615. if(SUCCEEDED(hr = m_QualifierList.Add(pNewQualifWrap)))
  2616. {
  2617. hr = pQualifierSet->BeginEnumeration(0);
  2618. }
  2619. else
  2620. {
  2621. SAFE_DELETE_ARRAY(pNewQualifWrap->m_pwstrPropertyName)
  2622. SAFE_DELETE_PTR(pNewQualifWrap)
  2623. }
  2624. }
  2625. else
  2626. {
  2627. SAFE_DELETE_PTR(pNewQualifWrap);
  2628. hr = E_OUTOFMEMORY;
  2629. }
  2630. }
  2631. else
  2632. {
  2633. hr = E_OUTOFMEMORY;
  2634. }
  2635. return hr;
  2636. }
  2637. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2638. // Remove a Element from the list
  2639. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2640. void CWbemPropertyQualifierList::Remove(WCHAR *pwstrPropertyName)
  2641. {
  2642. CWbemPropertyQualifierWrapper *pQualifWrap = NULL;
  2643. for( int nIndex = 0 ; nIndex < m_QualifierList.Size(); nIndex++)
  2644. {
  2645. if(0 == wbem_wcsicmp(((CWbemPropertyQualifierWrapper *)m_QualifierList[nIndex])->m_pwstrPropertyName,pwstrPropertyName))
  2646. {
  2647. pQualifWrap = (CWbemPropertyQualifierWrapper *)m_QualifierList[nIndex];
  2648. m_QualifierList.RemoveAt(nIndex);
  2649. pQualifWrap->m_pIWbemPropertyQualifierSet->EndEnumeration();
  2650. SAFE_DELETE_PTR(pQualifWrap);
  2651. }
  2652. }
  2653. }
  2654. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2655. // Get the IWbemQualifierSet pointer to the required property
  2656. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2657. IWbemQualifierSet* CWbemPropertyQualifierList::GetPropertyQualifierSet(WCHAR *pwstrPropertyName)
  2658. {
  2659. for( int nIndex = 0 ; nIndex < m_QualifierList.Size(); nIndex++)
  2660. {
  2661. if(0 == wbem_wcsicmp(((CWbemPropertyQualifierWrapper *)m_QualifierList[nIndex])->m_pwstrPropertyName,pwstrPropertyName))
  2662. return ((CWbemPropertyQualifierWrapper *)m_QualifierList[nIndex])->m_pIWbemPropertyQualifierSet;
  2663. }
  2664. return NULL;
  2665. }
  2666. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2667. // Get the CQualiferPos pointer for a property
  2668. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2669. CQualiferPos *CWbemPropertyQualifierList::GetQualiferPosObject(WCHAR *pwcsProperty)
  2670. {
  2671. for( int nIndex = 0 ; nIndex < m_QualifierList.Size(); nIndex++)
  2672. {
  2673. if(0 == wbem_wcsicmp(((CWbemPropertyQualifierWrapper *)m_QualifierList[nIndex])->m_pwstrPropertyName,pwcsProperty))
  2674. return &(((CWbemPropertyQualifierWrapper *)m_QualifierList[nIndex])->m_QualifierPos);
  2675. }
  2676. return NULL;
  2677. }
  2678. /***********************************************************************************************************
  2679. Class CQualifier implementation
  2680. /***********************************************************************************************************/
  2681. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2682. // Constructor
  2683. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2684. CQualiferPos::CQualiferPos()
  2685. {
  2686. m_lPos = -1;
  2687. m_FetchDir = FETCHDIRNONE;
  2688. }
  2689. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2690. // Destructor
  2691. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2692. CQualiferPos::~CQualiferPos()
  2693. {
  2694. RemoveAll();
  2695. m_lPos = -1;
  2696. }
  2697. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2698. // Remove all the elements from the list
  2699. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2700. void CQualiferPos::RemoveAll()
  2701. {
  2702. WCHAR *pChar = NULL;
  2703. int nSize = m_QualifierPos.Size();
  2704. if(m_QualifierPos.Size() > 0)
  2705. for( int nIndex = nSize-1 ; nIndex >= 0 ; nIndex--)
  2706. {
  2707. if ( NULL != (pChar = (WCHAR *)m_QualifierPos[nIndex]))
  2708. {
  2709. delete [] pChar;
  2710. pChar = NULL;
  2711. }
  2712. m_QualifierPos.RemoveAt(nIndex);
  2713. }
  2714. }
  2715. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2716. // Remove a qualifier from the list
  2717. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2718. void CQualiferPos::Remove(WCHAR *pwcsQualifier)
  2719. {
  2720. int nSize = m_QualifierPos.Size();
  2721. if(m_QualifierPos.Size() > 0)
  2722. for( int nIndex = nSize-1 ; nIndex >= 0 ; nIndex--)
  2723. {
  2724. if(wbem_wcsicmp((WCHAR *)m_QualifierPos[nIndex],pwcsQualifier) == 0)
  2725. {
  2726. m_QualifierPos.RemoveAt(nIndex);
  2727. m_lPos--;
  2728. }
  2729. }
  2730. }
  2731. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2732. // Get qualifier at a particula position
  2733. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2734. WCHAR * CQualiferPos::operator [] (DBORDINAL nIndex)
  2735. {
  2736. if( nIndex <= (ULONG_PTR)m_QualifierPos.Size())
  2737. return (WCHAR *)m_QualifierPos[(int)nIndex];
  2738. return NULL;
  2739. }
  2740. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2741. // Get the qualifier at a relation positon from the current position
  2742. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2743. HRESULT CQualiferPos::GetRelative (DBROWOFFSET lRelPos, WCHAR *&pwcsQualifier)
  2744. {
  2745. HRESULT hr = S_OK;
  2746. LONG lSize = m_QualifierPos.Size();
  2747. if( lSize > 0)
  2748. {
  2749. if( (m_lPos + lRelPos) >= lSize)
  2750. {
  2751. hr = WBEMERROR_QUALIFER_TOBE_FETCHED;
  2752. }
  2753. else
  2754. if( (m_lPos + lRelPos) < 0)
  2755. {
  2756. hr = DB_E_BADSTARTPOSITION;
  2757. }
  2758. else
  2759. {
  2760. pwcsQualifier = (WCHAR *)m_QualifierPos[(int)(m_lPos + lRelPos)];
  2761. }
  2762. }
  2763. else
  2764. hr = lRelPos > 0 ? WBEMERROR_QUALIFER_TOBE_FETCHED :DB_E_BADSTARTPOSITION;
  2765. return hr;
  2766. }
  2767. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2768. // Add qualifier to the list
  2769. //NTRaid:111779
  2770. // 06/13/00
  2771. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2772. HRESULT CQualiferPos::Add(WCHAR *pwcsQualifier)
  2773. {
  2774. WCHAR *pstrTemp = NULL;
  2775. HRESULT hr = S_OK;
  2776. pstrTemp = new WCHAR[wcslen(pwcsQualifier) +1];
  2777. if(pstrTemp)
  2778. {
  2779. wcscpy(pstrTemp,pwcsQualifier);
  2780. if(SUCCEEDED(hr = m_QualifierPos.Add(pstrTemp)))
  2781. {
  2782. m_lPos++;
  2783. }
  2784. else
  2785. {
  2786. SAFE_DELETE_ARRAY(pstrTemp);
  2787. }
  2788. }
  2789. else
  2790. {
  2791. hr = E_OUTOFMEMORY;
  2792. }
  2793. return hr;
  2794. }
  2795. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2796. // Set relation position
  2797. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2798. HRESULT CQualiferPos::SetRelPos(DBROWOFFSET lRelPos)
  2799. {
  2800. HRESULT hr = S_OK;
  2801. if( m_QualifierPos.Size() > 0)
  2802. {
  2803. if( (m_lPos + lRelPos) >= m_QualifierPos.Size())
  2804. {
  2805. hr = WBEMERROR_QUALIFER_TOBE_FETCHED;
  2806. }
  2807. else
  2808. if( (m_lPos + lRelPos) < -1)
  2809. {
  2810. hr = DB_E_BADSTARTPOSITION;
  2811. }
  2812. else
  2813. {
  2814. m_lPos = m_lPos + lRelPos;
  2815. }
  2816. }
  2817. else
  2818. hr = lRelPos > 0 ? WBEMERROR_QUALIFER_TOBE_FETCHED :DB_E_BADSTARTPOSITION;
  2819. return hr;
  2820. }
  2821. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  2822. //*****************************************************************************************************
  2823. //
  2824. //
  2825. // The COMMAND classes
  2826. //
  2827. //
  2828. //*****************************************************************************************************
  2829. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2830. //*************************************************************************************************
  2831. // The Command Manager, manages all the command interfaces
  2832. //*************************************************************************************************
  2833. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2834. CWbemCommandManager::CWbemCommandManager(CQuery * p)
  2835. {
  2836. m_pClassDefinition = NULL;
  2837. m_pInstanceList = NULL;
  2838. m_pInstance = NULL;
  2839. m_pParms = NULL;
  2840. m_pQuery = p;
  2841. }
  2842. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2843. CWbemCommandManager::~CWbemCommandManager()
  2844. {
  2845. // These pointers are all deleted elsewhere, so do not delete, this class is simply a pass-through class
  2846. }
  2847. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2848. void CWbemCommandManager::Init(CWbemCommandInstanceList * InstanceList, CWbemCommandParameters * pParms,
  2849. CWbemCommandClassDefinitionWrapper* pDef)
  2850. {
  2851. m_pInstanceList = InstanceList;
  2852. m_pParms = pParms;
  2853. m_pClassDefinition = pDef;
  2854. }
  2855. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2856. BOOL CWbemCommandManager::ValidQuery()
  2857. {
  2858. if( m_pQuery ){
  2859. return TRUE;
  2860. }
  2861. return FALSE;
  2862. }
  2863. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2864. HRESULT CWbemCommandManager::ValidQueryResults()
  2865. {
  2866. HRESULT hr = E_FAIL;
  2867. if( ValidQuery() ){
  2868. m_pQuery->m_pcsQuery->Enter();
  2869. if ( !(m_pQuery->GetStatus() & CMD_EXECUTED_ONCE)){
  2870. if ( m_pQuery->GetStatus() & CMD_READY){
  2871. if( m_pInstanceList ){
  2872. if(SUCCEEDED(hr = m_pInstanceList->SetQuery(m_pQuery->GetQuery(),m_pQuery->GetDialectGuid(),m_pQuery->GetQueryLang())) &&
  2873. SUCCEEDED(hr = m_pClassDefinition->SetQueryType(m_pQuery->GetQuery(),m_pQuery->GetDialectGuid(),m_pQuery->GetQueryLang())) )
  2874. // if( hr == S_OK )
  2875. {
  2876. hr = m_pInstanceList->Reset();
  2877. if( hr == S_OK ){
  2878. m_pQuery->ClearStatus(CMD_READY);
  2879. m_pQuery->SetStatus(CMD_EXECUTED_ONCE);
  2880. }
  2881. }
  2882. }
  2883. }
  2884. }
  2885. m_pQuery->m_pcsQuery->Leave();
  2886. }
  2887. return hr;
  2888. }
  2889. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2890. HRESULT CWbemCommandManager::GetClassDefinitionForQueryResults()
  2891. {
  2892. CWbemClassInstanceWrapper *pInst = NULL;
  2893. CBSTR strKey;
  2894. HRESULT hr = S_OK;
  2895. CBSTR stQryLanguage(m_pInstanceList->GetQueryLanguage());
  2896. CBSTR strQuery(m_pInstanceList->GetQuery());
  2897. IEnumWbemClassObject *pEnum = NULL;
  2898. IWbemClassObject *p = NULL;
  2899. ULONG cElem = 0;
  2900. if(NORMAL == GetObjListType())
  2901. {
  2902. // Execute the query just to get the class defination
  2903. if(SUCCEEDED(hr = (m_pParms->GetServicesPtr())->ExecQuery(stQryLanguage, strQuery, WBEM_FLAG_PROTOTYPE,m_pParms->GetContext(),&pEnum)))
  2904. {
  2905. if(SUCCEEDED(hr = pEnum->Next(0,1,&p,&cElem)) && cElem > 0)
  2906. {
  2907. pEnum->Release();
  2908. ((CWbemClassWrapper*)(m_pClassDefinition))->SetClass(p);
  2909. }
  2910. SAFE_RELEASE_PTR(p);
  2911. }
  2912. else
  2913. {
  2914. hr = E_FAIL;
  2915. }
  2916. }
  2917. return hr;
  2918. }
  2919. INSTANCELISTTYPE CWbemCommandManager::GetObjListType()
  2920. {
  2921. return m_pClassDefinition->GetObjListType();
  2922. }
  2923. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2924. //*************************************************************************************************
  2925. // The Command parameters
  2926. //*************************************************************************************************
  2927. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2928. CWbemCommandParameters::CWbemCommandParameters(DWORD dwFlags,CWbemConnectionWrapper * Connect,CWbemCommandManager * p) :
  2929. CWbemClassParameters(dwFlags,(WCHAR*)NULL,Connect)
  2930. {
  2931. m_pwcsClassName = new WCHAR [wcslen(szInstance) + 1];
  2932. wcscpy(m_pwcsClassName,szInstance);
  2933. m_pCmdManager = p;
  2934. }
  2935. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2936. CWbemCommandParameters::~CWbemCommandParameters()
  2937. {
  2938. }
  2939. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2940. //*************************************************************************************************
  2941. // The Command class definition
  2942. //*************************************************************************************************
  2943. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2944. CWbemCommandClassDefinitionWrapper::CWbemCommandClassDefinitionWrapper( CWbemClassParameters * p,CWbemCommandManager * pCmd )
  2945. : CWbemClassDefinitionWrapper(p)
  2946. {
  2947. m_nMaxColumns = 0;
  2948. m_pCmdManager = pCmd;
  2949. m_objListType = NORMAL;
  2950. }
  2951. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  2952. CWbemCommandClassDefinitionWrapper::~CWbemCommandClassDefinitionWrapper()
  2953. {
  2954. }
  2955. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  2956. HRESULT CWbemCommandClassDefinitionWrapper::ValidClass()
  2957. {
  2958. if( ! m_pCmdManager->ValidQuery() ) {
  2959. return E_FAIL;
  2960. }
  2961. return S_OK;
  2962. }
  2963. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  2964. // Function to get the total number of columns for a resultset on executing a command
  2965. // NTRaid:142133
  2966. // 07/11/2000
  2967. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  2968. HRESULT CWbemCommandClassDefinitionWrapper::TotalPropertiesInClass(ULONG & ulPropCount, ULONG &ulSysPropCount)
  2969. {
  2970. HRESULT hr = E_FAIL;
  2971. hr = m_pCmdManager->ValidQueryResults();
  2972. if( hr == S_OK ){
  2973. hr = m_pCmdManager->GetClassDefinitionForQueryResults();
  2974. if(hr == S_OK){
  2975. switch(m_pCmdManager->GetObjListType())
  2976. {
  2977. case NORMAL:
  2978. {
  2979. hr = CWbemClassWrapper::TotalPropertiesInClass(ulPropCount,ulSysPropCount);
  2980. }
  2981. break;
  2982. case MIXED:
  2983. {
  2984. // if it is a heterogenous objects then just have column for
  2985. // only the __PATH
  2986. ulPropCount = 0;
  2987. ulSysPropCount = 1;
  2988. hr = S_OK;
  2989. }
  2990. break;
  2991. }
  2992. }
  2993. else
  2994. // this means that the query was unable to get return any object or unable
  2995. // to get the prototype of the resultant object for query execution
  2996. if(SUCCEEDED(hr))
  2997. {
  2998. ulPropCount = 0;
  2999. ulSysPropCount = 0;
  3000. hr = S_FALSE;
  3001. }
  3002. }
  3003. return MapWbemErrorToOLEDBError(hr);
  3004. }
  3005. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3006. // Function to set the query type after looking for "ASSOCIATORS OF" and "REFERENCES OF" in the query
  3007. //
  3008. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3009. HRESULT CWbemCommandClassDefinitionWrapper::SetQueryType(LPCWSTR strQry,GUID QryDialect,LPCWSTR strQryLang)
  3010. {
  3011. HRESULT hr = S_OK;
  3012. BOOL bLDAPQry = FALSE;
  3013. if((strQryLang != NULL && _wcsicmp(strQryLang,szWQL) == 0) &&
  3014. (!wbem_wcsincmp(strQry,szReferenceOfQry,wcslen(szReferenceOfQry)) ||
  3015. !wbem_wcsincmp(strQry,szAssociatersQry,wcslen(szAssociatersQry))) )
  3016. {
  3017. m_objListType = MIXED;
  3018. }
  3019. else
  3020. if((QryDialect == DBGUID_DEFAULT || QryDialect == DBGUID_WQL) &&
  3021. (!wbem_wcsincmp(strQry,szReferenceOfQry,wcslen(szReferenceOfQry)) ||
  3022. !wbem_wcsincmp(strQry,szAssociatersQry,wcslen(szAssociatersQry))) )
  3023. {
  3024. m_objListType = MIXED;
  3025. }
  3026. else
  3027. if((strQryLang != NULL && _wcsicmp(strQryLang,szWQL)) ||
  3028. (QryDialect != DBGUID_DEFAULT && QryDialect != DBGUID_WQL) )
  3029. {
  3030. hr = E_FAIL;
  3031. if(strQryLang != NULL)
  3032. {
  3033. if(_wcsicmp(strQryLang,szLDAP) == 0)
  3034. {
  3035. bLDAPQry = TRUE;
  3036. m_objListType = MIXED;
  3037. hr = S_OK;
  3038. }
  3039. else
  3040. if(_wcsicmp(strQryLang,szLDAPSQL) == 0)
  3041. {
  3042. bLDAPQry = FALSE;
  3043. hr = S_OK;
  3044. }
  3045. else
  3046. {
  3047. hr = E_FAIL;
  3048. }
  3049. }
  3050. else
  3051. if(QryDialect == DBGUID_LDAP)
  3052. {
  3053. bLDAPQry = TRUE;
  3054. m_objListType = MIXED;
  3055. hr = S_OK;
  3056. }
  3057. if(QryDialect == DBGUID_LDAPSQL)
  3058. {
  3059. bLDAPQry = FALSE;
  3060. m_objListType = MIXED;
  3061. hr = S_OK;
  3062. }
  3063. }
  3064. if(SUCCEEDED(hr) && bLDAPQry == FALSE)
  3065. {
  3066. // check if the query is "SELECT * FROM" type of query
  3067. // if so then set the query type to MIXED
  3068. WCHAR *pStrQry = NULL;
  3069. WCHAR *strToken = NULL;
  3070. WCHAR strSeparator[] = L" ";
  3071. pStrQry = new WCHAR[wcslen(strQry) + 1];
  3072. if(pStrQry)
  3073. {
  3074. // by default query is MIXED for LDAP and SQL Queries
  3075. // except that if it is select col1,col2 from ...
  3076. m_objListType = MIXED;
  3077. memset(pStrQry,0,sizeof(WCHAR) * wcslen(strQry) + 1);
  3078. wcscpy(pStrQry,strQry);
  3079. strToken = wcstok( pStrQry, strSeparator );
  3080. if(strToken && _wcsicmp(L"Select",strToken) == 0)
  3081. {
  3082. m_objListType = NORMAL;
  3083. strToken = wcstok( NULL, strSeparator );
  3084. if(strToken && _wcsicmp(L"*",strToken) == 0)
  3085. {
  3086. strToken = wcstok( NULL, strSeparator );
  3087. if(strToken && _wcsicmp(L"FROM",strToken) == 0)
  3088. {
  3089. m_objListType = MIXED;
  3090. }
  3091. }
  3092. }
  3093. }
  3094. else
  3095. {
  3096. hr = E_OUTOFMEMORY;
  3097. }
  3098. SAFE_DELETE_ARRAY(pStrQry);
  3099. }
  3100. return hr;
  3101. }
  3102. /*///////////////////////////////////////////////////////////////////////////////////////////////////////
  3103. HRESULT CWbemCommandClassDefinitionWrapper::BeginPropertyEnumeration()
  3104. {
  3105. return CWbemClassWrapper::BeginPropertyEnumeration();
  3106. }
  3107. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3108. HRESULT CWbemCommandClassDefinitionWrapper::EndPropertyEnumeration()
  3109. {
  3110. return CWbemClassWrapper::EndPropertyEnumeration();
  3111. }
  3112. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3113. HRESULT CWbemCommandClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor )
  3114. {
  3115. return CWbemClassWrapper::GetNextProperty(pProperty,vValue,pType,plFlavor);
  3116. }
  3117. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3118. HRESULT CWbemCommandClassDefinitionWrapper::BeginPropertyQualifierEnumeration(BSTR strPropName)
  3119. {
  3120. return CWbemClassWrapper::BeginPropertyQualifierEnumeration(strPropName);
  3121. }*/
  3122. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3123. //*************************************************************************************************
  3124. // The Command instance list
  3125. //*************************************************************************************************
  3126. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3127. CWbemCommandInstanceList::CWbemCommandInstanceList(CWbemClassParameters * p,CWbemCommandManager * pCmd): CWbemInstanceList(p)
  3128. {
  3129. m_pCmdManager = pCmd;
  3130. m_pParms = p;
  3131. m_nBaseType = COMMAND_ROWSET;
  3132. m_pwstrQueryLanguage = NULL;
  3133. }
  3134. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3135. CWbemCommandInstanceList::~CWbemCommandInstanceList()
  3136. {
  3137. SAFE_DELETE_ARRAY(m_pwstrQueryLanguage);
  3138. }
  3139. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3140. HRESULT CWbemCommandInstanceList::Reset()
  3141. {
  3142. HRESULT hr = E_FAIL;
  3143. CBSTR strQryLanguage(m_pwstrQueryLanguage);
  3144. CBSTR strQuery(m_pwstrQuery);
  3145. BOOL bExecQuery = TRUE;
  3146. LONG lFlags = m_pParms->m_dwNavFlags | m_pParms->m_dwQueryFlags | WBEM_FLAG_ENSURE_LOCATABLE;
  3147. if(m_ppEnum != NULL)
  3148. {
  3149. if(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags)
  3150. {
  3151. ReleaseAllInstances();
  3152. m_ppEnum->Release();
  3153. m_ppEnum = NULL;
  3154. }
  3155. else
  3156. {
  3157. hr = m_ppEnum->Reset();
  3158. bExecQuery = FALSE;
  3159. }
  3160. }
  3161. if( bExecQuery)
  3162. {
  3163. hr = (m_pParms->GetServicesPtr())->ExecQuery(strQryLanguage,
  3164. strQuery,
  3165. lFlags,
  3166. m_pParms->GetContext(),
  3167. &m_ppEnum);
  3168. m_lCurrentPos = 0;
  3169. }
  3170. if(hr == S_OK)
  3171. {
  3172. m_lCurrentPos = 0;
  3173. // m_FetchDir = FETCHDIRFORWARD;
  3174. }
  3175. return hr;
  3176. }
  3177. HRESULT CWbemCommandInstanceList::SetQuery( LPWSTR p,GUID QryDialect,LPCWSTR strQryLang)
  3178. {
  3179. HRESULT hr = E_OUTOFMEMORY;
  3180. m_pwstrQuery = p;
  3181. SAFE_DELETE_ARRAY(m_pwstrQueryLanguage);
  3182. if(strQryLang == NULL)
  3183. {
  3184. if(QryDialect == DBGUID_WQL || QryDialect == DBGUID_DEFAULT)
  3185. {
  3186. m_pwstrQueryLanguage = new WCHAR[wcslen(szWQL) + 1];
  3187. if(m_pwstrQueryLanguage)
  3188. {
  3189. wcscpy(m_pwstrQueryLanguage,szWQL);
  3190. hr = S_OK;
  3191. }
  3192. }
  3193. else
  3194. if(QryDialect == DBGUID_LDAP)
  3195. {
  3196. // MOdify the string here to be passed for executing
  3197. // LDAP queries
  3198. m_pwstrQueryLanguage = new WCHAR[wcslen(szLDAP) + 1];
  3199. if(m_pwstrQueryLanguage)
  3200. {
  3201. wcscpy(m_pwstrQueryLanguage,szLDAP);
  3202. hr = S_OK;
  3203. }
  3204. }
  3205. else
  3206. if(QryDialect == DBGUID_LDAPSQL)
  3207. {
  3208. // MOdify the string here to be passed for executing
  3209. // LDAP queries
  3210. m_pwstrQueryLanguage = new WCHAR[wcslen(szLDAPSQL) + 1];
  3211. if(m_pwstrQueryLanguage)
  3212. {
  3213. wcscpy(m_pwstrQueryLanguage,szLDAPSQL);
  3214. hr = S_OK;
  3215. }
  3216. }
  3217. else
  3218. if(QryDialect == DBGUID_WMI_METHOD)
  3219. {
  3220. hr = S_OK;
  3221. }
  3222. else
  3223. {
  3224. hr = E_FAIL;
  3225. }
  3226. }
  3227. else
  3228. {
  3229. m_pwstrQueryLanguage = new WCHAR[wcslen(strQryLang) + 1];
  3230. if(m_pwstrQueryLanguage)
  3231. {
  3232. wcscpy(m_pwstrQueryLanguage,strQryLang);
  3233. hr = S_OK;
  3234. }
  3235. }
  3236. return hr;
  3237. }
  3238. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3239. //*************************************************************************************************
  3240. // The Command instance wrapper list
  3241. //*************************************************************************************************
  3242. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3243. CWbemCommandInstanceWrapper::CWbemCommandInstanceWrapper(CWbemClassParameters * p, CWbemCommandManager * pCmd ): CWbemClassInstanceWrapper(p)
  3244. {
  3245. m_pCmdManager = pCmd;
  3246. }
  3247. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3248. CWbemCommandInstanceWrapper::~CWbemCommandInstanceWrapper()
  3249. {
  3250. }
  3251. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3252. WCHAR * CWbemCommandInstanceWrapper::GetClassName()
  3253. {
  3254. WCHAR *pClass = NULL;
  3255. BSTR strPropName;
  3256. HRESULT hr = 0;
  3257. // Get the class name only if query is mixed
  3258. // meaning heteregenous objects are requested
  3259. if(MIXED == m_pCmdManager->GetObjListType())
  3260. {
  3261. strPropName = Wmioledb_SysAllocString(L"__Class");
  3262. VARIANT varClassName;
  3263. VariantInit(&varClassName);
  3264. // Get the class name
  3265. hr = m_pClass->Get(strPropName,0, &varClassName , NULL , NULL);
  3266. SysFreeString(strPropName);
  3267. if( hr == S_OK)
  3268. {
  3269. AllocateAndCopy(pClass,varClassName.bstrVal);
  3270. VariantClear(&varClassName);
  3271. }
  3272. }
  3273. return pClass;
  3274. }
  3275. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3276. // Function to get __PATH of the instance
  3277. // __PATH property makes sense only when REFERENCES OF or ASSOCIATERS OF query is run
  3278. // otherwise __PATH property will be NULL string
  3279. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3280. HRESULT CWbemCommandInstanceWrapper::GetKey(CBSTR & Key)
  3281. {
  3282. CVARIANT var;
  3283. HRESULT hr = E_FAIL;
  3284. // NTRaid: 130047
  3285. // Get the Key name only if query is mixed
  3286. // meaning heteregenous objects are requested
  3287. // if(MIXED == m_pCmdManager->GetObjListType())
  3288. {
  3289. if(FAILED(hr = GetProperty(L"__URL",var)))
  3290. {
  3291. hr = GetProperty(L"__PATH",var );
  3292. }
  3293. if( hr == S_OK )
  3294. {
  3295. Key.SetStr(var.GetStr());
  3296. }
  3297. }
  3298. return MapWbemErrorToOLEDBError(hr);
  3299. }
  3300. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3301. // This method applies only for instances obtained from REFERENCES OF or ASSOCIATERS OF query
  3302. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3303. HRESULT CWbemCommandInstanceWrapper::RefreshInstance()
  3304. {
  3305. HRESULT hr = S_OK;
  3306. // Get the Key name only if query is mixed
  3307. // meaning heteregenous objects are requested
  3308. if(MIXED == m_pCmdManager->GetObjListType())
  3309. {
  3310. hr = CWbemClassInstanceWrapper::RefreshInstance();
  3311. }
  3312. return hr;
  3313. }
  3314. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3315. //*************************************************************************************************
  3316. // The Method class definition
  3317. //*************************************************************************************************
  3318. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3319. // The Method parameters
  3320. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3321. CWbemMethodParameters::CWbemMethodParameters(CQuery * p, DWORD dwFlags,CWbemConnectionWrapper * Connect) :
  3322. CWbemClassParameters(dwFlags,(WCHAR*)NULL,Connect)
  3323. {
  3324. m_pwcsClassName = new WCHAR [wcslen(szInstance) + 1];
  3325. wcscpy(m_pwcsClassName,szInstance);
  3326. m_pQuery = p;
  3327. m_pwcsInstance=NULL;
  3328. m_pwcsMethod=NULL;
  3329. }
  3330. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3331. CWbemMethodParameters::~CWbemMethodParameters()
  3332. {
  3333. SAFE_DELETE_PTR(m_pwcsInstance);
  3334. SAFE_DELETE_PTR(m_pwcsMethod);
  3335. }
  3336. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3337. HRESULT CWbemMethodParameters::ExtractNamesFromQuery()
  3338. {
  3339. HRESULT hr = DB_E_ERRORSINCOMMAND;
  3340. WCHAR * wcsQuery = m_pQuery->GetQuery();
  3341. //=======================================================================
  3342. // The purpose of this function is to extract the class name and
  3343. // method name from the query string. This query is in the format of:
  3344. // Win32_Process.Handle="20".GetOwner
  3345. //=======================================================================
  3346. DeleteClassName();
  3347. SAFE_DELETE_PTR(m_pwcsInstance);
  3348. SAFE_DELETE_PTR(m_pwcsMethod);
  3349. int nMax = wcslen(wcsQuery);
  3350. // NTRaid: 136429
  3351. // 07/05/00
  3352. WCHAR *pTmp1 = NULL;
  3353. WCHAR *pTmp2 = NULL;
  3354. WCHAR *pTmp3 = NULL;
  3355. WCHAR *pTmp4 = NULL;
  3356. pTmp1 = new WCHAR[nMax];
  3357. pTmp2 = new WCHAR[nMax];
  3358. pTmp3 = new WCHAR[nMax];
  3359. pTmp4 = new WCHAR[nMax];
  3360. if( pTmp1 && pTmp2 && pTmp3 && pTmp4 ){
  3361. memset(pTmp1,0,nMax * sizeof(WCHAR));
  3362. memset(pTmp2,0,nMax * sizeof(WCHAR));
  3363. memset(pTmp3,0,nMax * sizeof(WCHAR));
  3364. memset(pTmp4,0,nMax * sizeof(WCHAR));
  3365. swscanf(wcsQuery,L"%[^.].%[^=]=%[^.].%s",pTmp1,pTmp2,pTmp3,pTmp4);
  3366. //============================================================
  3367. // Win32_Process.Handle="20" .GetOwner
  3368. //============================================================
  3369. if(wcslen(pTmp4) == 0 || wcslen(pTmp3) == 0)
  3370. {
  3371. swscanf(wcsQuery,L"%[^=].%s",pTmp1,pTmp2);
  3372. }
  3373. else
  3374. {
  3375. swscanf(wcsQuery,L"%[^.].%s",pTmp1,pTmp2);
  3376. }
  3377. _wcsrev(wcsQuery);
  3378. swscanf(wcsQuery,L"%[^.].%s",pTmp4,pTmp2);
  3379. _wcsrev(wcsQuery);
  3380. if(wcslen(pTmp4) > 0 && wcslen(pTmp2) > 0 && wcslen(pTmp1) &&
  3381. wcscmp(pTmp1,pTmp4) != 0)
  3382. {
  3383. _wcsrev(pTmp4);
  3384. _wcsrev(pTmp2);
  3385. hr = S_OK;
  3386. }
  3387. else
  3388. {
  3389. hr = DB_E_ERRORSINCOMMAND;
  3390. }
  3391. if(SUCCEEDED(hr))
  3392. {
  3393. // swscanf(wcsQuery,L"%[^.].%[^=]=\"%[^\"]\".%s",pTmp1,pTmp2,pTmp3,pTmp4);
  3394. if( pTmp1 && pTmp2 && pTmp4)
  3395. {
  3396. SetClassName(pTmp1);
  3397. AllocateAndCopy(m_pwcsMethod,pTmp4);
  3398. AllocateAndCopy(m_pwcsInstance,pTmp2);
  3399. hr = S_OK;
  3400. }
  3401. /*
  3402. swscanf(wcsQuery,L"%[^.].%[^=]=\"%[^\"]\".%s",pTmp1,pTmp2,pTmp3,pTmp4);
  3403. if( pTmp1 && pTmp2 && pTmp3 && pTmp4){
  3404. SetClassName(pTmp1);
  3405. AllocateAndCopy(m_pwcsMethod,pTmp4);
  3406. AllocateAndCopy(m_pwcsInstance,wcsQuery);
  3407. m_pwcsInstance = new WCHAR[nMax];
  3408. if( m_pwcsInstance ){
  3409. swprintf(m_pwcsInstance,L"%s.%s=\"%s\"",pTmp1,pTmp2,pTmp3);
  3410. hr = S_OK;
  3411. }
  3412. }
  3413. */ }
  3414. }
  3415. else{
  3416. hr = E_OUTOFMEMORY;
  3417. }
  3418. SAFE_DELETE_PTR(pTmp1);
  3419. SAFE_DELETE_PTR(pTmp2);
  3420. SAFE_DELETE_PTR(pTmp3);
  3421. SAFE_DELETE_PTR(pTmp4);
  3422. return hr;
  3423. }
  3424. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3425. HRESULT CWbemMethodParameters::ValidMethod()
  3426. {
  3427. HRESULT hr = E_FAIL;
  3428. if( GetClassName() && m_pwcsInstance && m_pwcsMethod ){
  3429. hr = S_OK;
  3430. }
  3431. return hr;
  3432. }
  3433. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3434. // The class definition for method
  3435. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3436. CWbemMethodClassDefinitionWrapper::CWbemMethodClassDefinitionWrapper(CWbemMethodParameters * parm )
  3437. : CWbemClassDefinitionWrapper(parm)
  3438. {
  3439. m_nMaxColumns = 0;
  3440. m_nCount = 0;
  3441. m_pInClass = NULL;
  3442. }
  3443. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3444. CWbemMethodClassDefinitionWrapper::~CWbemMethodClassDefinitionWrapper()
  3445. {
  3446. SAFE_RELEASE_PTR( m_pInClass );
  3447. }
  3448. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3449. HRESULT CWbemMethodClassDefinitionWrapper::Init()
  3450. {
  3451. HRESULT hr = DB_E_ERRORSINCOMMAND;
  3452. //=======================================================================
  3453. // The purpose of this function is to extract the class name and
  3454. // method name from the query string. This query is in the format of:
  3455. // Win32_ProcessHandle="20".GetOwner
  3456. //=======================================================================
  3457. hr = ((CWbemMethodParameters*) m_pParms)->ExtractNamesFromQuery();
  3458. //=======================================================================
  3459. // Any other initialization?
  3460. //=======================================================================
  3461. return hr;
  3462. }
  3463. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3464. HRESULT CWbemMethodClassDefinitionWrapper::ValidClass()
  3465. {
  3466. return ((CWbemMethodParameters*) m_pParms)->ValidMethod();
  3467. }
  3468. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3469. HRESULT CWbemMethodClassDefinitionWrapper::TotalPropertiesInClass(ULONG & ulPropCount, ULONG &ulSysPropCount)
  3470. {
  3471. //=======================================================================
  3472. // Since we are return the output parameters are the rowset, we are
  3473. // intereseted in the properties of the output parameter class
  3474. //=======================================================================
  3475. HRESULT hr = E_FAIL;
  3476. IWbemClassObject * pClass = NULL;
  3477. CBSTR bstrClass(((CWbemMethodParameters*) m_pParms)->GetClassName());
  3478. CBSTR bstrMethod(((CWbemMethodParameters*) m_pParms)->GetMethodName());
  3479. CBSTR bstrInstance(((CWbemMethodParameters*) m_pParms)->GetInstanceName());
  3480. hr = (m_pParms->GetServicesPtr())->GetObject(bstrClass, 0,m_pParms->GetContext(), &pClass, NULL);
  3481. if( hr == S_OK ){
  3482. //==========================================================
  3483. // Now, get the list of Input and Output parameters
  3484. //==========================================================
  3485. hr = pClass->GetMethod(bstrMethod, 0, &m_pInClass, &m_pClass);
  3486. if( hr == S_OK ){
  3487. hr = CWbemClassWrapper::TotalPropertiesInClass(ulPropCount,ulSysPropCount);
  3488. }
  3489. }
  3490. SAFE_RELEASE_PTR(pClass);
  3491. return hr;
  3492. }
  3493. /*///////////////////////////////////////////////////////////////////////////////////////////////////////
  3494. HRESULT CWbemMethodClassDefinitionWrapper::BeginPropertyEnumeration()
  3495. {
  3496. }
  3497. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3498. HRESULT CWbemMethodClassDefinitionWrapper::EndPropertyEnumeration()
  3499. {
  3500. m_nCount = 0;
  3501. return S_OK;
  3502. }
  3503. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3504. HRESULT CWbemMethodClassDefinitionWrapper::GetNextProperty(BSTR * pProperty, VARIANT * vValue, CIMTYPE * pType ,LONG * plFlavor )
  3505. {
  3506. HRESULT hr = WBEM_S_NO_MORE_DATA;
  3507. if( m_nCount == 1 ){
  3508. *plFlavor = 0l;
  3509. *pType = CIM_BOOLEAN;
  3510. *pProperty = Wmioledb_SysAllocString(L"SUCCESS");
  3511. }
  3512. return hr;
  3513. }
  3514. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  3515. HRESULT CWbemMethodClassDefinitionWrapper::BeginPropertyQualifierEnumeration(BSTR strPropName)
  3516. {
  3517. return S_OK;
  3518. }*/
  3519. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3520. //*************************************************************************************************
  3521. // The Method instance list
  3522. //*************************************************************************************************
  3523. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3524. CWbemMethodInstanceList::CWbemMethodInstanceList(CWbemMethodParameters * p,CWbemMethodClassDefinitionWrapper * pDef): CWbemInstanceList(p)
  3525. {
  3526. m_pParms = p;
  3527. m_pClassDefinition = pDef;
  3528. m_nBaseType = METHOD_ROWSET;
  3529. }
  3530. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3531. CWbemMethodInstanceList::~CWbemMethodInstanceList()
  3532. {
  3533. }
  3534. HRESULT CWbemMethodInstanceList::GetInputParameterName(IWbemClassObject *pObject,DBORDINAL iOrdinal , BSTR &strPropName)
  3535. {
  3536. HRESULT hr = S_OK;
  3537. if(SUCCEEDED(hr = pObject->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY)))
  3538. {
  3539. for(DBORDINAL i = 0 ; i < iOrdinal && SUCCEEDED(hr); i++)
  3540. {
  3541. hr = pObject->Next(0,&strPropName,NULL,NULL,NULL);
  3542. if(i != iOrdinal && SUCCEEDED(hr))
  3543. {
  3544. SysFreeString(strPropName);
  3545. }
  3546. }
  3547. pObject->EndEnumeration();
  3548. }
  3549. return hr;
  3550. }
  3551. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3552. // Function gets the input parameter values and puts it to a input parameters object which it returns
  3553. HRESULT CWbemMethodInstanceList::ProcessInputParameters(IWbemClassObject **ppParamInput)
  3554. {
  3555. HRESULT hr = S_OK;
  3556. IWbemClassObject *pParamInput = NULL;
  3557. LONG lType = 0;
  3558. CDataMap map;
  3559. VARIANT varParamValue;
  3560. VariantInit(&varParamValue);
  3561. //===========================================================
  3562. // Enumerate the properties, read them from the parameter
  3563. // list and put them in the input class
  3564. //===========================================================
  3565. if( m_pClassDefinition->GetInputClassPtr() ){
  3566. ((CWbemMethodParameters*)m_pParms)->m_pQuery->m_pcsQuery->Enter();
  3567. PPARAMINFO pParamInfo;
  3568. ULONG iParam;
  3569. ULONG uCount = ((CWbemMethodParameters*)m_pParms)->m_pQuery->GetParamCount();
  3570. // Spawn an instance of input paramter object
  3571. hr = m_pClassDefinition->GetInputClassPtr()->SpawnInstance(0,&pParamInput);
  3572. for (iParam = 0; iParam <uCount; iParam++){
  3573. VariantClear(&varParamValue);
  3574. pParamInfo = (PPARAMINFO)((CWbemMethodParameters*)m_pParms)->m_pQuery->GetParam(iParam);
  3575. if (pParamInfo && (pParamInfo->dwFlags & DBPARAMFLAGS_ISINPUT)){
  3576. CBSTR bstrProperty(pParamInfo->pwszParamName);
  3577. if(pParamInfo->pwszParamName == NULL)
  3578. {
  3579. GetInputParameterName(pParamInput,pParamInfo->iOrdinal,(BSTR&)bstrProperty);
  3580. }
  3581. if(S_OK == (hr = pParamInput->Get(bstrProperty,0,NULL,&lType,NULL)))
  3582. {
  3583. // Call this function to convert the OLEDB bound type to CIMTYPE of the parameter
  3584. hr = map.ConvertToCIMType(pParamInfo->pbData,pParamInfo->wOLEDBType,pParamInfo->cbColLength,lType,varParamValue);
  3585. // if the value is not empty put the value of the parameter
  3586. if( varParamValue.vt != VT_EMPTY && varParamValue.vt != VT_NULL)
  3587. hr = pParamInput->Put(bstrProperty,0,&varParamValue,0);
  3588. if( S_OK != hr ){
  3589. break;
  3590. }
  3591. else
  3592. {
  3593. *ppParamInput = NULL;
  3594. hr = pParamInput->QueryInterface(IID_IWbemClassObject , (void **)ppParamInput);
  3595. }
  3596. }
  3597. }
  3598. }
  3599. VariantClear(&varParamValue);
  3600. SAFE_RELEASE_PTR(pParamInput);
  3601. ((CWbemMethodParameters*)m_pParms)->m_pQuery->m_pcsQuery->Leave();
  3602. }
  3603. return hr;
  3604. }
  3605. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3606. HRESULT CWbemMethodInstanceList::ProcessOutputParameters()
  3607. {
  3608. HRESULT hr = WBEM_E_NOT_FOUND;
  3609. IWbemClassObject * pClass = ((CWbemClassWrapper*) m_pClassDefinition)->GetClass();
  3610. VARIANT varValue;
  3611. VariantInit(&varValue);
  3612. //===========================================================
  3613. // Enumerate the properties, read them and update the values
  3614. // in the parameter list
  3615. //===========================================================
  3616. if( pClass ){
  3617. hr = S_OK;
  3618. ((CWbemMethodParameters*)m_pParms)->m_pQuery->m_pcsQuery->Enter();
  3619. PPARAMINFO pParamInfo;
  3620. ULONG iParam;
  3621. ULONG uCount = ((CWbemMethodParameters*)m_pParms)->m_pQuery->GetParamCount();
  3622. for (iParam = 0; iParam <uCount; iParam++){
  3623. pParamInfo = (PPARAMINFO)((CWbemMethodParameters*)m_pParms)->m_pQuery->GetParam(iParam);
  3624. if (pParamInfo && (pParamInfo->dwFlags & DBPARAMFLAGS_ISOUTPUT))
  3625. {
  3626. CBSTR bstrProperty(pParamInfo->pwszParamName);
  3627. hr = pClass->Get(bstrProperty,0,&varValue,&(pParamInfo)->CIMType,&(pParamInfo)->Flavor);
  3628. if( hr == S_OK)
  3629. {
  3630. CDataMap map;
  3631. DWORD dwStatus = 0;
  3632. // set the size to the maximum available
  3633. pParamInfo->cbColLength = pParamInfo->ulParamSize;
  3634. hr = map.AllocateAndConvertToOLEDBType(varValue,pParamInfo->CIMType , pParamInfo->wOLEDBType ,
  3635. pParamInfo->pbData , pParamInfo->cbColLength , pParamInfo->dwStatus);
  3636. }
  3637. if( S_OK != hr ){
  3638. break;
  3639. }
  3640. VariantClear(&varValue);
  3641. }
  3642. }
  3643. ((CWbemMethodParameters*)m_pParms)->m_pQuery->m_pcsQuery->Leave();
  3644. }
  3645. return hr;
  3646. }
  3647. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3648. HRESULT CWbemMethodInstanceList::Reset()
  3649. {
  3650. HRESULT hr = E_FAIL;
  3651. CBSTR bstrMethod(((CWbemMethodParameters*) m_pParms)->GetMethodName());
  3652. CBSTR bstrInstance(((CWbemMethodParameters*) m_pParms)->GetInstanceName());
  3653. IWbemClassObject ** ppClass = ((CWbemClassWrapper*) m_pClassDefinition)->GetClassPtr();
  3654. IWbemClassObject *pParamInput = NULL;
  3655. hr = ProcessInputParameters(&pParamInput);
  3656. if( S_OK == hr ){
  3657. hr = (m_pParms->GetServicesPtr())->ExecMethod( bstrInstance,bstrMethod, 0,
  3658. m_pParms->GetContext(),
  3659. m_pClassDefinition->GetInputClassPtr(),
  3660. ppClass, NULL);
  3661. //====================================================================
  3662. // We should update the DBPARAMS array as well as put these results
  3663. // in a rowset
  3664. //====================================================================
  3665. if( S_OK == hr ){
  3666. hr = ProcessOutputParameters();
  3667. }
  3668. }
  3669. SAFE_RELEASE_PTR(pParamInput);
  3670. return MapWbemErrorToOLEDBError(hr);
  3671. }
  3672. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3673. HRESULT CWbemMethodInstanceList::NextInstance(CBSTR & Key, CWbemClassInstanceWrapper ** pInst)
  3674. {
  3675. LONG lRelativePos = 1;
  3676. HRESULT hr = E_FAIL;
  3677. //============================================================
  3678. // Now, we only have one instance of output parameters
  3679. //============================================================
  3680. if( m_lCurrentPos == 0 )
  3681. {
  3682. // IF the direction has changed compared to the previous fetch then
  3683. // the first fetch will be the last one fetched
  3684. if( m_FetchDir == FETCHDIRBACKWARD)
  3685. lRelativePos = 0;
  3686. // Check if the instance is already fetched
  3687. *pInst = GetInstance(m_lCurrentPos +lRelativePos);
  3688. if( *pInst == NULL)
  3689. {
  3690. *pInst = new CWbemMethodInstanceWrapper((CWbemMethodParameters*)m_pParms);
  3691. if( *pInst ){
  3692. IWbemClassObject * pClass = ((CWbemClassWrapper*) m_pClassDefinition)->GetClass();
  3693. (*pInst)->SetClass(pClass);
  3694. (*pInst)->SetPos(++m_lCurrentPos);
  3695. AddInstance(*pInst);
  3696. (*pInst)->GetKey(Key);
  3697. hr = S_OK;
  3698. }
  3699. else
  3700. {
  3701. hr = E_OUTOFMEMORY;
  3702. }
  3703. }
  3704. else
  3705. {
  3706. m_lCurrentPos += lRelativePos;
  3707. m_FetchDir = FETCHDIRFORWARD;
  3708. (*pInst)->GetKey(Key);
  3709. hr = S_OK;
  3710. }
  3711. }
  3712. else
  3713. {
  3714. hr = WBEM_S_NO_MORE_DATA;
  3715. }
  3716. return hr;
  3717. }
  3718. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3719. HRESULT CWbemMethodInstanceList::PrevInstance( CBSTR & Key, CWbemClassInstanceWrapper *& pInst)
  3720. {
  3721. HRESULT hr = S_OK;
  3722. DBROWOFFSET lRelativePos = -1;
  3723. // IF the direction has changed compared to the previous fetch then
  3724. // the first fetch will be the last one fetched
  3725. if( m_FetchDir == FETCHDIRFORWARD)
  3726. lRelativePos = 0;
  3727. // Reset the position to the so that
  3728. // NextInstance function gives the instance required
  3729. hr = ResetRelPosition(lRelativePos);
  3730. pInst = GetInstance(m_lCurrentPos);
  3731. if(pInst != NULL)
  3732. pInst->GetKey(Key);
  3733. m_FetchDir = FETCHDIRBACKWARD;
  3734. return hr;
  3735. }
  3736. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3737. //*************************************************************************************************
  3738. // The Method instance wrapper list
  3739. //*************************************************************************************************
  3740. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3741. CWbemMethodInstanceWrapper::CWbemMethodInstanceWrapper(CWbemMethodParameters * p): CWbemClassInstanceWrapper(p)
  3742. {
  3743. // m_nBaseType = METHOD_ROWSET; // METHOD_ROWSET
  3744. }
  3745. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3746. CWbemMethodInstanceWrapper::~CWbemMethodInstanceWrapper()
  3747. {
  3748. }
  3749. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3750. HRESULT CWbemMethodInstanceWrapper::ResetInstanceFromKey(CBSTR Key)
  3751. {
  3752. // This doesn't really apply to methods
  3753. return S_OK;
  3754. }
  3755. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3756. HRESULT CWbemMethodInstanceWrapper::RefreshInstance()
  3757. {
  3758. // This doesn't really apply to methods
  3759. return S_OK;
  3760. }
  3761. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3762. WCHAR * CWbemMethodInstanceWrapper::GetClassName()
  3763. {
  3764. return m_pParms->GetClassName();
  3765. }
  3766. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3767. HRESULT CWbemMethodInstanceWrapper::GetKey(CBSTR & Key)
  3768. {
  3769. HRESULT hr = S_OK;
  3770. Key.SetStr(L"OutputParameters");
  3771. return hr;
  3772. }
  3773. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3774. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3775. // CWbemCollectionClassDefinitionWrapper class implementation
  3776. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3777. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3778. CWbemCollectionClassDefinitionWrapper::CWbemCollectionClassDefinitionWrapper(CWbemClassParameters * p,
  3779. WCHAR * pstrPath,
  3780. INSTANCELISTTYPE objListType)
  3781. :CWbemClassDefinitionWrapper(p,
  3782. ((pstrPath == NULL) || (pstrPath != NULL && wcscmp(pstrPath,OPENCOLLECTION) == 0)) ? FALSE : TRUE)
  3783. {
  3784. m_pstrPath = NULL;
  3785. if((pstrPath == NULL) || (pstrPath != NULL && wcscmp(pstrPath,OPENCOLLECTION) == 0))
  3786. {
  3787. m_objListType = objListType;
  3788. }
  3789. else
  3790. {
  3791. m_objListType = NORMAL;
  3792. }
  3793. }
  3794. HRESULT CWbemCollectionClassDefinitionWrapper::Initialize(WCHAR * pstrPath)
  3795. {
  3796. HRESULT hr = S_OK;
  3797. WCHAR *pStrTemp = (WCHAR *)OPENCOLLECTION;
  3798. if(pstrPath != NULL)
  3799. {
  3800. pStrTemp = pstrPath;
  3801. }
  3802. m_pstrPath = new WCHAR[wcslen(pStrTemp) + 1];
  3803. if(m_pstrPath)
  3804. {
  3805. wcscpy(m_pstrPath,pStrTemp);
  3806. // function to get the class defination object if required
  3807. hr = Init(m_objListType == NORMAL);
  3808. }
  3809. else
  3810. {
  3811. hr = E_OUTOFMEMORY;
  3812. }
  3813. return hr;
  3814. }
  3815. CWbemCollectionClassDefinitionWrapper::~CWbemCollectionClassDefinitionWrapper()
  3816. {
  3817. SAFE_DELETE_ARRAY(m_pstrPath);
  3818. }
  3819. HRESULT CWbemCollectionClassDefinitionWrapper::ValidClass()
  3820. {
  3821. return S_OK;
  3822. }
  3823. HRESULT CWbemCollectionClassDefinitionWrapper::TotalPropertiesInClass(ULONG & ulPropCount, ULONG &ulSysPropCount)
  3824. {
  3825. HRESULT hr = S_OK;
  3826. // if the rowset refers to a mixed rowset then
  3827. // there is only one column in the row
  3828. if(m_objListType != NORMAL)
  3829. {
  3830. ulPropCount = 0;
  3831. ulSysPropCount = 1;
  3832. }
  3833. else
  3834. {
  3835. hr = CWbemClassDefinitionWrapper::TotalPropertiesInClass(ulPropCount,ulSysPropCount);
  3836. }
  3837. return hr;
  3838. }
  3839. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3840. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3841. // CWbemCollectionInstanceList class implementation
  3842. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3843. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3844. CWbemCollectionInstanceList::CWbemCollectionInstanceList(CWbemClassParameters * p,CWbemCollectionManager * pCollectionMgr)
  3845. :CWbemInstanceList(p)
  3846. {
  3847. m_pColMgr = pCollectionMgr;
  3848. }
  3849. CWbemCollectionInstanceList::~CWbemCollectionInstanceList()
  3850. {
  3851. }
  3852. HRESULT CWbemCollectionInstanceList::Reset()
  3853. {
  3854. HRESULT hr = E_UNEXPECTED;
  3855. BOOL bGetInstanceEnum = TRUE;
  3856. //============================================================
  3857. // If we already got an enumeration, reset it, otherwise
  3858. // don't
  3859. //============================================================
  3860. if( m_ppEnum ){
  3861. if(WBEM_FLAG_FORWARD_ONLY & m_pParms->m_dwNavFlags)
  3862. {
  3863. ReleaseAllInstances();
  3864. m_ppEnum->Release();
  3865. m_ppEnum = NULL;
  3866. }
  3867. else
  3868. {
  3869. hr = m_ppEnum->Reset();
  3870. bGetInstanceEnum = FALSE;
  3871. }
  3872. }
  3873. if(bGetInstanceEnum == TRUE)
  3874. {
  3875. IWbemServicesEx *pServicesEx = NULL;
  3876. if(SUCCEEDED(hr = m_pParms->GetServicesPtr()->QueryInterface(IID_IWbemServicesEx,(void **)&pServicesEx)))
  3877. {
  3878. long lFlags = 0;
  3879. CBSTR strPath;
  3880. strPath.SetStr(m_pColMgr->GetObjectPath());
  3881. INSTANCELISTTYPE colType = m_pColMgr->GetObjListType();
  3882. hr = pServicesEx->CreateInstanceEnum(strPath,
  3883. m_pParms->m_dwNavFlags | m_pParms->m_dwQueryFlags,
  3884. m_pParms->GetContext(),
  3885. &m_ppEnum);
  3886. SAFE_RELEASE_PTR(pServicesEx);
  3887. }
  3888. if( hr == S_OK)
  3889. {
  3890. m_cTotalInstancesInEnum = 0;
  3891. }
  3892. }
  3893. if(hr == S_OK)
  3894. {
  3895. m_lCurrentPos = 0;
  3896. }
  3897. return MapWbemErrorToOLEDBError(hr);
  3898. }
  3899. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3900. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3901. // CWbemCollectionParameters class implementation
  3902. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3903. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3904. CWbemCollectionParameters::CWbemCollectionParameters(DWORD dwFlags,CWbemConnectionWrapper * pWrap ,WCHAR *pClassName)
  3905. : CWbemClassParameters(dwFlags,NULL,pWrap)
  3906. {
  3907. m_pServices = NULL;
  3908. m_pwcsClassName = NULL;
  3909. }
  3910. CWbemCollectionParameters::~CWbemCollectionParameters()
  3911. {
  3912. SAFE_RELEASE_PTR(m_pServices);
  3913. }
  3914. HRESULT CWbemCollectionParameters::Init(BSTR strPath,CWbemConnectionWrapper * pWrap)
  3915. {
  3916. HRESULT hr = S_OK;
  3917. WCHAR * pStrTemp = NULL;
  3918. if(strPath == NULL || (strPath != NULL && wcscmp(strPath,OPENCOLLECTION) == 0))
  3919. {
  3920. pStrTemp = (WCHAR *)szInstance;
  3921. }
  3922. else
  3923. {
  3924. pStrTemp = strPath;
  3925. }
  3926. m_pwcsClassName = new WCHAR [wcslen(pStrTemp) + 1];
  3927. if(m_pwcsClassName)
  3928. {
  3929. wcscpy(m_pwcsClassName,pStrTemp);
  3930. hr = pWrap->GetServicesPtr()->QueryInterface(IID_IWbemServices,(void **)&m_pServices);
  3931. }
  3932. else
  3933. {
  3934. hr = E_OUTOFMEMORY;
  3935. }
  3936. return MapWbemErrorToOLEDBError(hr);
  3937. }
  3938. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3939. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3940. // CWbemCollectionInstanceList class implementation
  3941. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3942. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3943. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3944. // Constructor
  3945. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3946. CWbemCollectionManager::CWbemCollectionManager()
  3947. {
  3948. m_pClassDefinition = NULL;
  3949. m_pInstanceList = NULL;
  3950. m_pInstance = NULL;
  3951. m_pParms = NULL;
  3952. }
  3953. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3954. // Destructor
  3955. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3956. CWbemCollectionManager::~CWbemCollectionManager()
  3957. {
  3958. }
  3959. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3960. // Initialization function
  3961. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3962. void CWbemCollectionManager::Init(CWbemCollectionInstanceList * InstanceList, CWbemCollectionParameters * pParms,CWbemCollectionClassDefinitionWrapper* pDef)
  3963. {
  3964. m_pClassDefinition = pDef;
  3965. m_pInstanceList = InstanceList;
  3966. m_pInstance = NULL;
  3967. m_pParms = pParms;
  3968. CBSTR strPath;
  3969. strPath.SetStr(GetObjectPath());
  3970. INSTANCELISTTYPE colType = GetObjListType();
  3971. }
  3972. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3973. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3974. // CWbemCollectionInstanceWrapper class implementation
  3975. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3976. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3977. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3978. // Consturctor
  3979. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3980. CWbemCollectionInstanceWrapper::CWbemCollectionInstanceWrapper(CWbemClassParameters * p,CWbemCollectionManager * pWbemColMgr)
  3981. :CWbemClassInstanceWrapper(p)
  3982. {
  3983. m_pColMgr = pWbemColMgr;
  3984. }
  3985. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3986. // Destructor
  3987. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3988. CWbemCollectionInstanceWrapper::~CWbemCollectionInstanceWrapper()
  3989. {
  3990. }
  3991. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3992. // Get classname of the object
  3993. ///////////////////////////////////////////////////////////////////////////////////////////////////
  3994. WCHAR * CWbemCollectionInstanceWrapper::GetClassName()
  3995. {
  3996. WCHAR *pClass = NULL;
  3997. BSTR strPropName;
  3998. HRESULT hr = 0;
  3999. strPropName = Wmioledb_SysAllocString(L"__Class");
  4000. VARIANT varClassName;
  4001. VariantInit(&varClassName);
  4002. // Get the class name
  4003. hr = m_pClass->Get(strPropName,0, &varClassName , NULL , NULL);
  4004. SysFreeString(strPropName);
  4005. if( hr == S_OK)
  4006. {
  4007. AllocateAndCopy(pClass,varClassName.bstrVal);
  4008. VariantClear(&varClassName);
  4009. }
  4010. return pClass;
  4011. }
  4012. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4013. // Refreshing the instance
  4014. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4015. HRESULT CWbemCollectionInstanceWrapper::GetKey(CBSTR & Key)
  4016. {
  4017. CVARIANT var;
  4018. HRESULT hr = E_FAIL;
  4019. if(FAILED(hr = GetProperty(L"__URL",&var)))
  4020. {
  4021. hr = GetProperty(L"__PATH",var );
  4022. }
  4023. if( hr == S_OK )
  4024. {
  4025. Key.SetStr(var.GetStr());
  4026. }
  4027. return MapWbemErrorToOLEDBError(hr);
  4028. }
  4029. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4030. // Refreshing the instance
  4031. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4032. HRESULT CWbemCollectionInstanceWrapper::RefreshInstance()
  4033. {
  4034. return CWbemClassInstanceWrapper::RefreshInstance();
  4035. }
  4036. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  4037. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  4038. // CWbemSecurityDescriptor class implementaion
  4039. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  4040. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  4041. CWbemSecurityDescriptor::CWbemSecurityDescriptor()
  4042. {
  4043. m_strPath = NULL;
  4044. m_pISerEx = NULL;
  4045. m_lSdSize = 0;
  4046. m_pAccessor = NULL;
  4047. m_pIContext = NULL;
  4048. InitializeSecurityDescriptor(&m_sd,SECURITY_DESCRIPTOR_REVISION);
  4049. }
  4050. HRESULT CWbemSecurityDescriptor::Init(IWbemServices *pSer,BSTR strPath,IWbemContext *pContext)
  4051. {
  4052. ULONG lSDSize = 0;
  4053. HRESULT hr = S_OK;
  4054. if(SUCCEEDED(hr = pSer->QueryInterface(IID_IWbemServicesEx , (void**)&m_pISerEx)))
  4055. {
  4056. if(SUCCEEDED(hr = m_pISerEx->GetObject(strPath,0,m_pIContext,&m_pAccessor,NULL)))
  4057. {
  4058. CIMTYPE lType = 0;
  4059. hr = m_pAccessor->Get(CBSTR(L"__SD"),0,&m_sd,&lType,NULL);
  4060. }
  4061. }
  4062. m_pIContext = pContext;
  4063. if(m_pIContext)
  4064. {
  4065. m_pIContext->AddRef();
  4066. }
  4067. return hr;
  4068. }
  4069. CWbemSecurityDescriptor::~CWbemSecurityDescriptor()
  4070. {
  4071. SAFE_RELEASE_PTR(m_pISerEx);
  4072. SAFE_RELEASE_PTR(m_pAccessor);
  4073. SAFE_RELEASE_PTR(m_pIContext);
  4074. SAFE_FREE_SYSSTRING(m_strPath);
  4075. }
  4076. HRESULT CWbemSecurityDescriptor::PutSD()
  4077. {
  4078. HRESULT hr;
  4079. if(SUCCEEDED(hr = m_pAccessor->Put(CBSTR(L"__SD"),0,&m_sd,VT_ARRAY|VT_UI1)))
  4080. {
  4081. hr = m_pISerEx->PutInstance(m_pAccessor,0,m_pIContext,NULL);
  4082. }
  4083. return hr;
  4084. }
  4085. BOOL CWbemSecurityDescriptor::GetSID(TRUSTEE_W *pTrustee, PSID & psid)
  4086. {
  4087. WCHAR *pName = NULL;
  4088. BOOL bLookUp = FALSE;
  4089. PSID psidTemp = NULL;
  4090. ULONG lSID = 0;
  4091. BOOL bRet = TRUE;
  4092. BYTE *pMem = NULL;
  4093. switch(GetTrusteeFormW(pTrustee))
  4094. {
  4095. case TRUSTEE_IS_NAME:
  4096. pName = GetTrusteeNameW(pTrustee);
  4097. bLookUp = TRUE;
  4098. break;
  4099. // THis is only in windows 2000
  4100. case TRUSTEE_IS_OBJECTS_AND_NAME:
  4101. pName = ((OBJECTS_AND_NAME_W *)GetTrusteeNameW(pTrustee))->ptstrName;
  4102. bLookUp = TRUE;
  4103. break;
  4104. case TRUSTEE_IS_OBJECTS_AND_SID:
  4105. psidTemp = ((OBJECTS_AND_SID *)GetTrusteeNameW(pTrustee))->pSid;
  4106. break;
  4107. case TRUSTEE_IS_SID :
  4108. psidTemp = (PSID)GetTrusteeNameW(pTrustee);
  4109. break;
  4110. }
  4111. if(bLookUp)
  4112. {
  4113. SID_NAME_USE sidNameUseTemp;
  4114. ULONG lDomainName = NULL;
  4115. // Get the length of SID to be allocated
  4116. if(LookupAccountNameW(NULL,pName,NULL,(LPDWORD)&lSID,NULL,(LPDWORD)&lDomainName,&sidNameUseTemp))
  4117. {
  4118. try
  4119. {
  4120. pMem = new BYTE[lSID];
  4121. }
  4122. catch(...)
  4123. {
  4124. SAFE_DELETE_ARRAY(pMem);
  4125. throw;;
  4126. }
  4127. psid = (PSID)pMem;
  4128. bRet = LookupAccountNameW(NULL,pName,psid,(LPDWORD)&lSID,NULL,(LPDWORD)&lDomainName,&sidNameUseTemp);
  4129. }
  4130. }
  4131. else
  4132. {
  4133. lSID = (ULONG)GetLengthSid(psidTemp);
  4134. try
  4135. {
  4136. pMem = new BYTE[lSID];
  4137. }
  4138. catch(...)
  4139. {
  4140. SAFE_DELETE_ARRAY(pMem);
  4141. throw;;
  4142. }
  4143. psid = (PSID)pMem;
  4144. bRet = CopySid(lSID,psid,psidTemp);
  4145. }
  4146. if(!bRet)
  4147. {
  4148. SAFE_DELETE_ARRAY(pMem);
  4149. psid = NULL;
  4150. }
  4151. return bRet;
  4152. }