Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

926 lines
29 KiB

  1. // CheckCheck.cpp: implementation of the CCheckCheck class.
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "CheckCheck.h"
  8. #include "ExtendString.h"
  9. #include "ExtendQuery.h"
  10. //////////////////////////////////////////////////////////////////////
  11. // Construction/Destruction
  12. //////////////////////////////////////////////////////////////////////
  13. CCheckCheck::CCheckCheck(CRequestObject *pObj, IWbemServices *pNamespace,
  14. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  15. {
  16. }
  17. CCheckCheck::~CCheckCheck()
  18. {
  19. }
  20. HRESULT CCheckCheck::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  21. {
  22. HRESULT hr = WBEM_S_NO_ERROR;
  23. CRequestObject *pCheckRObj = NULL;
  24. CRequestObject *pLocationRObj = NULL;
  25. try{
  26. if(atAction != ACTIONTYPE_ENUM)
  27. {
  28. // we are doing GetObject so we need to be reinitialized
  29. hr = WBEM_E_NOT_FOUND;
  30. CHeap_Exception he(CHeap_Exception::E_ALLOCATION_ERROR);
  31. int i;
  32. for(i = 0; i < m_pRequest->m_iPropCount; i++){
  33. if(_wcsicmp(m_pRequest->m_Property[i], L"Location") == 0){
  34. pLocationRObj = new CRequestObject();
  35. if(!pLocationRObj) throw he;
  36. pLocationRObj->Initialize(m_pNamespace);
  37. pLocationRObj->ParsePath(m_pRequest->m_Value[i]);
  38. break;
  39. }
  40. }
  41. for(i = 0; i < m_pRequest->m_iPropCount; i++){
  42. if(_wcsicmp(m_pRequest->m_Property[i], L"CHECK") == 0){
  43. pCheckRObj = new CRequestObject();
  44. if(!pCheckRObj) throw he;
  45. pCheckRObj->Initialize(m_pNamespace);
  46. pCheckRObj->ParsePath(m_pRequest->m_Value[i]);
  47. break;
  48. }
  49. }
  50. }
  51. if((atAction == ACTIONTYPE_ENUM) || ((pLocationRObj && pLocationRObj->m_bstrClass && (_wcsicmp(pLocationRObj->m_bstrClass, L"Win32_DirectorySpecification") == 0) &&
  52. (pCheckRObj && pCheckRObj->m_bstrClass && (_wcsicmp(pCheckRObj->m_bstrClass, L"Win32_IniFileSpecification") == 0)))))
  53. if(FAILED(hr = IniFileDirectory(pHandler, atAction, pCheckRObj, pLocationRObj))){
  54. if(pLocationRObj){
  55. pLocationRObj->Cleanup();
  56. delete pLocationRObj;
  57. pLocationRObj = NULL;
  58. }
  59. if(pCheckRObj){
  60. pCheckRObj->Cleanup();
  61. delete pCheckRObj;
  62. pCheckRObj = NULL;
  63. }
  64. return hr;
  65. }
  66. if((atAction == ACTIONTYPE_ENUM) || ((pLocationRObj && pLocationRObj->m_bstrClass && (_wcsicmp(pLocationRObj->m_bstrClass, L"Win32_DirectorySpecification") == 0) &&
  67. (pCheckRObj && pCheckRObj->m_bstrClass && (_wcsicmp(pCheckRObj->m_bstrClass, L"Win32_DirectorySpecification") == 0)))))
  68. if(FAILED(hr = DirectoryParent(pHandler, atAction, pCheckRObj, pLocationRObj))){
  69. if(pLocationRObj){
  70. pLocationRObj->Cleanup();
  71. delete pLocationRObj;
  72. pLocationRObj = NULL;
  73. }
  74. if(pCheckRObj){
  75. pCheckRObj->Cleanup();
  76. delete pCheckRObj;
  77. pCheckRObj = NULL;
  78. }
  79. return hr;
  80. }
  81. if(pLocationRObj){
  82. pLocationRObj->Cleanup();
  83. delete pLocationRObj;
  84. pLocationRObj = NULL;
  85. }
  86. if(pCheckRObj){
  87. pCheckRObj->Cleanup();
  88. delete pCheckRObj;
  89. pCheckRObj = NULL;
  90. }
  91. }catch(...){
  92. if(pLocationRObj){
  93. pLocationRObj->Cleanup();
  94. delete pLocationRObj;
  95. pLocationRObj = NULL;
  96. }
  97. if(pCheckRObj){
  98. pCheckRObj->Cleanup();
  99. delete pCheckRObj;
  100. pCheckRObj = NULL;
  101. }
  102. }
  103. return hr;
  104. }
  105. HRESULT CCheckCheck::DirectoryParent(IWbemObjectSink *pHandler, ACTIONTYPE atAction,
  106. CRequestObject *pCheckRObj, CRequestObject *pLocationRObj)
  107. {
  108. HRESULT hr = WBEM_S_NO_ERROR;
  109. MSIHANDLE hView = NULL;
  110. MSIHANDLE hRecord = NULL;
  111. MSIHANDLE hDView = NULL;
  112. MSIHANDLE hDRecord = NULL;
  113. MSIHANDLE hPView = NULL;
  114. MSIHANDLE hPRecord = NULL;
  115. int i = -1;
  116. WCHAR wcBuf[BUFF_SIZE];
  117. WCHAR wcParent[BUFF_SIZE];
  118. WCHAR wcProductCode[39];
  119. WCHAR wcCompID[39];
  120. WCHAR wcParentCompID[39];
  121. WCHAR wcTestCode[39];
  122. WCHAR wcFolder[BUFF_SIZE];
  123. DWORD dwBufSize;
  124. bool bMatch = false;
  125. bool bTestCode = false;
  126. UINT uiStatus;
  127. WCHAR wcLocation[BUFF_SIZE];
  128. bool bCheck = false;
  129. bool bLocation = false;
  130. if(atAction != ACTIONTYPE_ENUM)
  131. {
  132. // we are doing GetObject so we need to be reinitialized
  133. hr = WBEM_E_NOT_FOUND;
  134. CHeap_Exception he(CHeap_Exception::E_ALLOCATION_ERROR);
  135. if(pCheckRObj){
  136. for(int i = 0; i < pCheckRObj->m_iPropCount; i++){
  137. if(_wcsicmp(pCheckRObj->m_Property[i], L"CheckID") == 0)
  138. {
  139. if ( ::SysStringLen ( pCheckRObj->m_Value[i] ) < BUFF_SIZE )
  140. {
  141. //Get the action we're looking for
  142. wcscpy(wcBuf, pCheckRObj->m_Value[i]);
  143. // safe operation if wcslen ( wcBuf ) > 38
  144. if ( wcslen ( wcBuf ) > 38 )
  145. {
  146. wcscpy(wcTestCode, &(wcBuf[(wcslen(wcBuf) - 38)]));
  147. }
  148. else
  149. {
  150. // we are not good to go, they have sent us longer string
  151. throw hr;
  152. }
  153. // safe because lenght has been tested already in condition
  154. RemoveFinalGUID(pCheckRObj->m_Value[i], wcFolder);
  155. //we have a componentized directory... do a little more work
  156. if ((wcFolder[wcslen(wcFolder) - 1] == L'}') &&
  157. (wcFolder[wcslen(wcFolder) - 38] == L'{')
  158. )
  159. {
  160. RemoveFinalGUID(wcFolder, wcFolder);
  161. }
  162. bTestCode = true;
  163. bCheck = true;
  164. break;
  165. }
  166. else
  167. {
  168. // we are not good to go, they have sent us longer string
  169. throw hr;
  170. }
  171. }
  172. }
  173. }
  174. if(pLocationRObj){
  175. for(int i = 0; i < pLocationRObj->m_iPropCount; i++){
  176. if(_wcsicmp(pLocationRObj->m_Property[i], L"CheckID") == 0)
  177. {
  178. if ( ::SysStringLen ( pLocationRObj->m_Value[i] ) < BUFF_SIZE )
  179. {
  180. //Get the action we're looking for
  181. wcscpy(wcBuf, pLocationRObj->m_Value[i]);
  182. // safe operation if wcslen ( wcBuf ) > 38
  183. if ( wcslen ( wcBuf ) > 38 )
  184. {
  185. wcscpy(wcTestCode, &(wcBuf[(wcslen(wcBuf) - 38)]));
  186. }
  187. else
  188. {
  189. // we are not good to go, they have sent us longer string
  190. throw hr;
  191. }
  192. // safe because lenght has been tested already in condition
  193. RemoveFinalGUID(pLocationRObj->m_Value[i], wcLocation);
  194. //we have a componentized directory... do a little more work
  195. if ((wcLocation[wcslen(wcLocation) - 1] == L'}') &&
  196. (wcLocation[wcslen(wcLocation) - 38] == L'{')
  197. )
  198. {
  199. RemoveFinalGUID(wcLocation, wcLocation);
  200. }
  201. bTestCode = true;
  202. bLocation = true;
  203. break;
  204. }
  205. else
  206. {
  207. // we are not good to go, they have sent us longer string
  208. throw hr;
  209. }
  210. }
  211. }
  212. }
  213. }
  214. //These will change from class to class
  215. bool bDriver, bAttribute, bDoneFirst, bValidated, bParent, bDir;
  216. CStringExt wcProp;
  217. Query wcQuery;
  218. wcQuery.Append ( 1, L"select distinct `Directory`, `Directory_Parent` from Directory" );
  219. //optimize for GetObject
  220. if ( bCheck || bLocation )
  221. {
  222. if ( bCheck )
  223. {
  224. wcQuery.Append ( 3, L" where `Directory`=\'", wcFolder, L"\'" );
  225. }
  226. if ( bLocation )
  227. {
  228. if ( bCheck )
  229. {
  230. wcQuery.Append ( 3, L" or `Directory_Parent`=\'", wcLocation, L"\'" );
  231. }
  232. else
  233. {
  234. wcQuery.Append ( 3, L" where `Directory_Parent`=\'", wcLocation, L"\'" );
  235. }
  236. }
  237. }
  238. QueryExt wcQuery1 ( L"select distinct `ComponentId` from Component where `Directory_`=\'" );
  239. QueryExt wcQuery2 ( L"select distinct `ComponentId` from Component where `Directory_`=\'" );
  240. LPWSTR Buffer = NULL;
  241. LPWSTR dynBuffer = NULL;
  242. DWORD dwDynBuffer = 0L;
  243. LPWSTR Buffer1 = NULL;
  244. LPWSTR dynBuffer1 = NULL;
  245. DWORD dwDynBuffer1 = 0L;
  246. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  247. {
  248. // safe operation:
  249. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  250. wcscpy(wcProductCode, m_pRequest->Package(i));
  251. if((atAction == ACTIONTYPE_ENUM) ||
  252. (bTestCode && (_wcsicmp(wcTestCode, wcProductCode) == 0))){
  253. //Open our database
  254. try
  255. {
  256. if ( GetView ( &hView, wcProductCode, wcQuery, L"Directory", TRUE, FALSE ) )
  257. {
  258. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  259. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  260. CheckMSI(uiStatus);
  261. bDoneFirst = false;
  262. dwBufSize = BUFF_SIZE;
  263. GetBufferToPut ( hRecord, 1, dwBufSize, wcBuf, dwDynBuffer1, dynBuffer1, Buffer1 );
  264. // make query on fly
  265. wcQuery1.Append ( 2, Buffer1, L"\'" );
  266. if(((uiStatus = g_fpMsiDatabaseOpenViewW(msidata.GetDatabase (), wcQuery1, &hDView)) == ERROR_SUCCESS)
  267. || !bDoneFirst){
  268. if((g_fpMsiViewExecute(hDView, 0) == ERROR_SUCCESS) || !bDoneFirst){
  269. try{
  270. uiStatus = g_fpMsiViewFetch(hDView, &hDRecord);
  271. while(!bMatch && (!bDoneFirst || (uiStatus == ERROR_SUCCESS)) && (hr != WBEM_E_CALL_CANCELLED)){
  272. bValidated = false;
  273. bDir = false;
  274. if(uiStatus == ERROR_SUCCESS){
  275. dwBufSize = 39;
  276. CheckMSI(g_fpMsiRecordGetStringW(hDRecord, 1, wcCompID, &dwBufSize));
  277. bValidated = ValidateComponentID(wcCompID, wcProductCode);
  278. bDir = true;
  279. }
  280. if(((uiStatus != ERROR_SUCCESS) && !bDoneFirst) || (bValidated && (uiStatus != ERROR_NO_MORE_ITEMS))){
  281. dwBufSize = BUFF_SIZE;
  282. GetBufferToPut ( hRecord, 2, dwBufSize, wcParent, dwDynBuffer, dynBuffer, Buffer );
  283. // make query on fly
  284. wcQuery2.Append ( 2, Buffer, L"\'" );
  285. if(((uiStatus = g_fpMsiDatabaseOpenViewW(msidata.GetDatabase (), wcQuery2, &hPView)) == ERROR_SUCCESS)
  286. || !bDoneFirst){
  287. if((g_fpMsiViewExecute(hPView, 0) == ERROR_SUCCESS) || !bDoneFirst){
  288. try{
  289. uiStatus = g_fpMsiViewFetch(hPView, &hPRecord);
  290. while(!bMatch && (!bDoneFirst || (uiStatus == ERROR_SUCCESS)) && (hr != WBEM_E_CALL_CANCELLED)){
  291. bValidated = false;
  292. bParent = false;
  293. if(uiStatus == ERROR_SUCCESS){
  294. dwBufSize = 39;
  295. CheckMSI(g_fpMsiRecordGetStringW(hPRecord, 1, wcParentCompID, &dwBufSize));
  296. bValidated = ValidateComponentID(wcParentCompID, wcProductCode);
  297. bParent = true;
  298. }
  299. if(((uiStatus != ERROR_SUCCESS) && !bDoneFirst) || (bValidated && (uiStatus != ERROR_NO_MORE_ITEMS))){
  300. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  301. //----------------------------------------------------
  302. if ( Buffer1 && Buffer1 [ 0 ] != 0 )
  303. {
  304. // safe operation
  305. wcProp.Copy ( L"Win32_DirectorySpecification.CheckID=\"" );
  306. if(bDir)
  307. {
  308. wcProp.Append ( 4, Buffer1, wcCompID, wcProductCode, L"\"" );
  309. }
  310. else
  311. {
  312. wcProp.Append ( 3, Buffer1, wcProductCode, L"\"" );
  313. }
  314. PutKeyProperty(m_pObj, pCheck, wcProp, &bDriver, m_pRequest);
  315. if ( Buffer && Buffer [ 0 ] != 0 )
  316. {
  317. // safe operation
  318. wcProp.Copy ( L"Win32_DirectorySpecification.CheckID=\"" );
  319. if(bParent)
  320. {
  321. wcProp.Append ( 4, Buffer, wcParentCompID, wcProductCode, L"\"" );
  322. }
  323. else
  324. {
  325. wcProp.Append ( 3, Buffer, wcProductCode, L"\"" );
  326. }
  327. PutKeyProperty(m_pObj, pLocation, wcProp, &bAttribute, m_pRequest);
  328. //----------------------------------------------------
  329. if(bDriver && bAttribute) bMatch = true;
  330. if((atAction != ACTIONTYPE_GET) || bMatch){
  331. hr = pHandler->Indicate(1, &m_pObj);
  332. }
  333. }
  334. }
  335. m_pObj->Release();
  336. m_pObj = NULL;
  337. if(!bDoneFirst) bDoneFirst = true;
  338. }
  339. g_fpMsiCloseHandle(hPRecord);
  340. uiStatus = g_fpMsiViewFetch(hPView, &hPRecord);
  341. }
  342. }catch(...){
  343. g_fpMsiCloseHandle(hPRecord);
  344. g_fpMsiViewClose(hPView);
  345. g_fpMsiCloseHandle(hPView);
  346. throw;
  347. }
  348. g_fpMsiCloseHandle(hPRecord);
  349. g_fpMsiViewClose(hPView);
  350. g_fpMsiCloseHandle(hPView);
  351. }
  352. }
  353. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  354. {
  355. dynBuffer [ 0 ] = 0;
  356. }
  357. }
  358. g_fpMsiCloseHandle(hDRecord);
  359. uiStatus = g_fpMsiViewFetch(hDView, &hDRecord);
  360. }
  361. }catch(...){
  362. g_fpMsiCloseHandle(hDRecord);
  363. g_fpMsiViewClose(hDView);
  364. g_fpMsiCloseHandle(hDView);
  365. throw;
  366. }
  367. g_fpMsiCloseHandle(hDRecord);
  368. g_fpMsiViewClose(hDView);
  369. g_fpMsiCloseHandle(hDView);
  370. }
  371. }
  372. g_fpMsiCloseHandle(hRecord);
  373. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  374. if ( Buffer1 && Buffer1 [ 0 ] != 0 )
  375. {
  376. Buffer1 [ 0 ] = 0 ;
  377. }
  378. }
  379. }
  380. }
  381. catch(...)
  382. {
  383. if ( dynBuffer )
  384. {
  385. delete [] dynBuffer;
  386. dynBuffer = NULL;
  387. }
  388. if ( dynBuffer1 )
  389. {
  390. delete [] dynBuffer1;
  391. dynBuffer1 = NULL;
  392. }
  393. g_fpMsiCloseHandle(hRecord);
  394. g_fpMsiViewClose(hView);
  395. g_fpMsiCloseHandle(hView);
  396. msidata.CloseDatabase ();
  397. if(m_pObj)
  398. {
  399. m_pObj->Release();
  400. m_pObj = NULL;
  401. }
  402. throw;
  403. }
  404. g_fpMsiCloseHandle(hRecord);
  405. g_fpMsiViewClose(hView);
  406. g_fpMsiCloseHandle(hView);
  407. msidata.CloseDatabase ();
  408. }
  409. }
  410. if ( dynBuffer )
  411. {
  412. delete [] dynBuffer;
  413. dynBuffer = NULL;
  414. }
  415. if ( dynBuffer1 )
  416. {
  417. delete [] dynBuffer1;
  418. dynBuffer1 = NULL;
  419. }
  420. return hr;
  421. }
  422. HRESULT CCheckCheck::IniFileDirectory(IWbemObjectSink *pHandler, ACTIONTYPE atAction,
  423. CRequestObject *pCheckRObj, CRequestObject *pLocationRObj)
  424. {
  425. HRESULT hr = WBEM_S_NO_ERROR;
  426. MSIHANDLE hView = NULL;
  427. MSIHANDLE hRecord = NULL;
  428. MSIHANDLE hDView = NULL;
  429. MSIHANDLE hDRecord = NULL;
  430. int i = -1;
  431. WCHAR wcBuf[BUFF_SIZE];
  432. WCHAR wcDir[BUFF_SIZE];
  433. WCHAR wcProductCode[39];
  434. WCHAR wcCompID[39];
  435. WCHAR wcTestCode[39];
  436. WCHAR wcIniFile[BUFF_SIZE];
  437. DWORD dwBufSize;
  438. bool bMatch = false;
  439. bool bTestCode = false;
  440. UINT uiStatus;
  441. WCHAR wcLocation[BUFF_SIZE];
  442. bool bCheck = false;
  443. bool bLocation = false;
  444. if(atAction != ACTIONTYPE_ENUM)
  445. {
  446. // we are doing GetObject so we need to be reinitialized
  447. hr = WBEM_E_NOT_FOUND;
  448. CHeap_Exception he(CHeap_Exception::E_ALLOCATION_ERROR);
  449. if(pCheckRObj){
  450. for(int i = 0; i < pCheckRObj->m_iPropCount; i++){
  451. if(_wcsicmp(pCheckRObj->m_Property[i], L"CheckID") == 0)
  452. {
  453. if ( ::SysStringLen ( pCheckRObj->m_Value[i] ) < BUFF_SIZE )
  454. {
  455. //Get the action we're looking for
  456. wcscpy(wcBuf, pCheckRObj->m_Value[i]);
  457. // safe operation if wcslen ( wcBuf ) > 38
  458. if ( wcslen ( wcBuf ) > 38 )
  459. {
  460. wcscpy(wcTestCode, &(wcBuf[(wcslen(wcBuf) - 38)]));
  461. }
  462. else
  463. {
  464. // we are not good to go, they have sent us longer string
  465. throw hr;
  466. }
  467. // safe because lenght has been tested already in condition
  468. RemoveFinalGUID(pCheckRObj->m_Value[i], wcIniFile);
  469. bCheck = true;
  470. bTestCode = true;
  471. break;
  472. }
  473. else
  474. {
  475. // we are not good to go, they have sent us longer string
  476. throw hr;
  477. }
  478. }
  479. }
  480. }
  481. if(pLocationRObj){
  482. for(int i = 0; i < pLocationRObj->m_iPropCount; i++){
  483. if(_wcsicmp(pLocationRObj->m_Property[i], L"CheckID") == 0)
  484. {
  485. if ( ::SysStringLen ( pLocationRObj->m_Value[i] ) < BUFF_SIZE )
  486. {
  487. //Get the action we're looking for
  488. wcscpy(wcBuf, pLocationRObj->m_Value[i]);
  489. // safe operation if wcslen ( wcBuf ) > 38
  490. if ( wcslen ( wcBuf ) > 38 )
  491. {
  492. wcscpy(wcTestCode, &(wcBuf[(wcslen(wcBuf) - 38)]));
  493. }
  494. else
  495. {
  496. // we are not good to go, they have sent us longer string
  497. throw hr;
  498. }
  499. // safe because lenght has been tested already in condition
  500. RemoveFinalGUID(pLocationRObj->m_Value[i], wcLocation);
  501. //we have a componentized directory... do a little more work
  502. if ((wcLocation[wcslen(wcLocation) - 1] == L'}') &&
  503. (wcLocation[wcslen(wcLocation) - 38] == L'{')
  504. )
  505. {
  506. RemoveFinalGUID(wcLocation, wcLocation);
  507. }
  508. bTestCode = true;
  509. bLocation = true;
  510. break;
  511. }
  512. else
  513. {
  514. // we are not good to go, they have sent us longer string
  515. throw hr;
  516. }
  517. }
  518. }
  519. }
  520. }
  521. //These will change from class to class
  522. bool bDriver, bAttribute, bDoneFirst, bValidated;
  523. CStringExt wcProp;
  524. Query wcQuery;
  525. wcQuery.Append ( 1, L"select distinct `IniFile`, `Component_`, `DirProperty` from IniFile" );
  526. if(atAction != ACTIONTYPE_ENUM){
  527. //optimize for GetObject
  528. if ( bCheck || bLocation )
  529. {
  530. if ( bCheck )
  531. {
  532. wcQuery.Append ( 3, L" where `IniFile`=\'", wcIniFile, L"\'" );
  533. }
  534. if ( bLocation )
  535. {
  536. if ( bCheck )
  537. {
  538. wcQuery.Append ( 3, L" or `DirProperty`=\'", wcLocation, L"\'" );
  539. }
  540. else
  541. {
  542. wcQuery.Append ( 3, L" where `DirProperty`=\'", wcLocation, L"\'" );
  543. }
  544. }
  545. }
  546. }
  547. QueryExt wcQuery1 ( L"select distinct `ComponentId` from Component where `Directory_`=\'" );
  548. LPWSTR Buffer = NULL;
  549. LPWSTR dynBuffer = NULL;
  550. DWORD dwDynBuffer = 0L;
  551. LPWSTR Buffer1 = NULL;
  552. LPWSTR dynBuffer1 = NULL;
  553. DWORD dwDynBuffer1 = 0L;
  554. while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
  555. {
  556. // safe operation:
  557. // Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
  558. wcscpy(wcProductCode, m_pRequest->Package(i));
  559. if((atAction == ACTIONTYPE_ENUM) ||
  560. (bTestCode && (_wcsicmp(wcTestCode, wcProductCode) == 0))){
  561. //Open our database
  562. try
  563. {
  564. if ( GetView ( &hView, wcProductCode, wcQuery, L"IniFile", TRUE, FALSE ) )
  565. {
  566. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  567. while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
  568. CheckMSI(uiStatus);
  569. bDoneFirst = false;
  570. dwBufSize = BUFF_SIZE;
  571. GetBufferToPut ( hRecord, 3, dwBufSize, wcDir, dwDynBuffer1, dynBuffer1, Buffer1 );
  572. // make query on fly
  573. wcQuery1.Append ( 2, Buffer1, L"\'" );
  574. if(((uiStatus = g_fpMsiDatabaseOpenViewW(msidata.GetDatabase (), wcQuery1, &hDView)) == ERROR_SUCCESS)
  575. || !bDoneFirst){
  576. if((g_fpMsiViewExecute(hDView, 0) == ERROR_SUCCESS) || !bDoneFirst){
  577. try{
  578. uiStatus = g_fpMsiViewFetch(hDView, &hDRecord);
  579. while(!bMatch && (!bDoneFirst || (uiStatus == ERROR_SUCCESS)) && (hr != WBEM_E_CALL_CANCELLED)){
  580. bValidated = false;
  581. if(uiStatus == ERROR_SUCCESS){
  582. dwBufSize = 39;
  583. CheckMSI(g_fpMsiRecordGetStringW(hDRecord, 1, wcCompID, &dwBufSize));
  584. bValidated = ValidateComponentID(wcCompID, wcProductCode);
  585. }
  586. if(((uiStatus != ERROR_SUCCESS) && !bDoneFirst) || (bValidated && (uiStatus != ERROR_NO_MORE_ITEMS))){
  587. if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
  588. //----------------------------------------------------
  589. dwBufSize = BUFF_SIZE;
  590. GetBufferToPut ( hRecord, 1, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  591. if ( Buffer && Buffer [ 0 ] != 0 )
  592. {
  593. // safe operation
  594. wcProp.Copy ( L"Win32_IniFileSpecification.CheckID=\"" );
  595. wcProp.Append ( 3, Buffer, wcProductCode, L"\"" );
  596. PutKeyProperty(m_pObj, pCheck, wcProp, &bDriver, m_pRequest);
  597. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  598. {
  599. dynBuffer [ 0 ] = 0;
  600. }
  601. dwBufSize = BUFF_SIZE;
  602. GetBufferToPut ( hRecord, 2, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, Buffer );
  603. if ( ValidateComponentName ( msidata.GetDatabase (),
  604. wcProductCode,
  605. Buffer
  606. )
  607. )
  608. {
  609. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  610. {
  611. dynBuffer [ 0 ] = 0;
  612. }
  613. if ( Buffer1 && Buffer1 [ 0 ] != 0 )
  614. {
  615. // safe operation
  616. wcProp.Copy ( L"Win32_DirectorySpecification.CheckID=\"" );
  617. if(uiStatus == ERROR_SUCCESS)
  618. {
  619. wcProp.Append ( 4, Buffer1, wcCompID, wcProductCode, L"\"" );
  620. }
  621. else
  622. {
  623. wcProp.Append ( 3, Buffer1, wcProductCode, L"\"" );
  624. }
  625. PutKeyProperty(m_pObj, pLocation, wcProp, &bAttribute, m_pRequest);
  626. //=====================================================
  627. //----------------------------------------------------
  628. if(bDriver && bAttribute) bMatch = true;
  629. if((atAction != ACTIONTYPE_GET) || bMatch){
  630. hr = pHandler->Indicate(1, &m_pObj);
  631. }
  632. }
  633. }
  634. else
  635. {
  636. if ( dynBuffer && dynBuffer [ 0 ] != 0 )
  637. {
  638. dynBuffer [ 0 ] = 0;
  639. }
  640. }
  641. }
  642. if(!bDoneFirst) bDoneFirst = true;
  643. m_pObj->Release();
  644. m_pObj = NULL;
  645. }
  646. g_fpMsiCloseHandle(hDRecord);
  647. uiStatus = g_fpMsiViewFetch(hDView, &hDRecord);
  648. }
  649. }catch(...){
  650. g_fpMsiCloseHandle(hDRecord);
  651. g_fpMsiViewClose(hDView);
  652. g_fpMsiCloseHandle(hDView);
  653. throw;
  654. }
  655. g_fpMsiCloseHandle(hDRecord);
  656. g_fpMsiViewClose(hDView);
  657. g_fpMsiCloseHandle(hDView);
  658. }
  659. }
  660. g_fpMsiCloseHandle(hRecord);
  661. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  662. if ( dynBuffer1 && dynBuffer1 [ 0 ] != 0 )
  663. {
  664. dynBuffer1 [ 0 ] = 0;
  665. }
  666. }
  667. }
  668. }
  669. catch(...)
  670. {
  671. if ( dynBuffer )
  672. {
  673. delete [] dynBuffer;
  674. dynBuffer = NULL;
  675. }
  676. if ( dynBuffer1 )
  677. {
  678. delete [] dynBuffer1;
  679. dynBuffer1 = NULL;
  680. }
  681. g_fpMsiCloseHandle(hRecord);
  682. g_fpMsiViewClose(hView);
  683. g_fpMsiCloseHandle(hView);
  684. msidata.CloseDatabase ();
  685. if(m_pObj)
  686. {
  687. m_pObj->Release();
  688. m_pObj = NULL;
  689. }
  690. throw;
  691. }
  692. g_fpMsiCloseHandle(hRecord);
  693. g_fpMsiViewClose(hView);
  694. g_fpMsiCloseHandle(hView);
  695. msidata.CloseDatabase ();
  696. }
  697. }
  698. if ( dynBuffer )
  699. {
  700. delete [] dynBuffer;
  701. dynBuffer = NULL;
  702. }
  703. if ( dynBuffer1 )
  704. {
  705. delete [] dynBuffer1;
  706. dynBuffer1 = NULL;
  707. }
  708. return hr;
  709. }