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.

758 lines
19 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //This file has the implementation for the WMI Provider for WHQL.
  3. //Uses MFC
  4. ///////////////////////////////////////////////////////////////////////////////
  5. // WhqlObj.cpp : Implementation of CWhqlObj
  6. #include "stdafx.h"
  7. #include "WhqlProv.h"
  8. #include "WhqlObj.h"
  9. #include "setupapi.h"
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CWhqlObj
  12. //Fn which actually checks the signature when passed an Inf File.
  13. extern BOOL IsInfSigned(LPTSTR FullInfPath , IWbemClassObject *pInstance = NULL);
  14. inline VOID AddSlashes(LPTSTR str);
  15. inline SCODE PutPropertyValue( IWbemClassObject* pInstance , LPCTSTR lpszProperty , LPCTSTR lpszValue );
  16. STDMETHODIMP CWhqlObj::Initialize(LPWSTR pszUser, LONG lFlags,
  17. LPWSTR pszNamespace, LPWSTR pszLocale,
  18. IWbemServices *pNamespace,
  19. IWbemContext *pCtx,
  20. IWbemProviderInitSink *pInitSink)
  21. {
  22. if (pNamespace)
  23. pNamespace->AddRef();
  24. //Standard Var Inits.
  25. m_pNamespace = pNamespace;
  26. m_csPathStr.Empty();
  27. m_csAntecedent.Empty();
  28. //Let CIMOM know you are initialized
  29. pInitSink->SetStatus(WBEM_S_INITIALIZED, 0);
  30. DEBUGTRACE(L"Provider Initialized\n");
  31. return WBEM_S_NO_ERROR;
  32. }
  33. SCODE CWhqlObj::CreateInstanceEnumAsync(BSTR RefStr, long lFlags, IWbemContext *pCtx,
  34. IWbemObjectSink *pHandler)
  35. {
  36. DEBUGTRACE(L"Provider called for class = %s\n",RefStr);
  37. HRESULT hr = S_OK;
  38. IWbemClassObject *pClass = NULL;
  39. IWbemClassObject **ppInstances = NULL;
  40. VOID **ppData = NULL;
  41. LONG cInstances, lIndex;
  42. cInstances = lIndex = 0L;
  43. m_ptrArr.RemoveAll();
  44. m_csPathStr.Empty();
  45. m_csAntecedent.Empty();
  46. // Do a check of arguments and make sure we have pointer to Namespace
  47. if(pHandler == NULL || m_pNamespace == NULL)
  48. return WBEM_E_INVALID_PARAMETER;
  49. // Get a class object from CIMOM
  50. hr = m_pNamespace->GetObject(RefStr, 0, pCtx, &pClass, NULL);
  51. if ( FAILED(hr) )
  52. return WBEM_E_FAILED;
  53. m_pClass = pClass;
  54. VARIANT var;
  55. VariantInit(&var);
  56. Classes_Provided eClasses;
  57. if(lstrcmpi(RefStr , L"Win32_PnPSignedDriver") == 0)
  58. {
  59. eClasses = Class_Win32_PnPSignedDriver;
  60. }
  61. else if(lstrcmpi(RefStr , L"Win32_PnPSignedDriverCIMDataFile") == 0)
  62. {
  63. eClasses = Class_Win32_PnPSignedDriverCIMDataFile;
  64. }
  65. else if(lstrcmpi(RefStr , L"Win32_PnPSignedDriverWin32PnPEntity") == 0)
  66. {
  67. eClasses = Class_Win32_PnPSignedDriverWin32PnPEntity;
  68. }
  69. hr = PutData( pCtx , eClasses);
  70. if ( FAILED(hr) )
  71. return WBEM_E_FAILED;
  72. VariantClear(&var);
  73. hr = pClass->Release();
  74. cInstances = (LONG)m_ptrArr.GetSize();
  75. ppInstances = (IWbemClassObject**)new LPVOID[cInstances];
  76. for(int nIndex = 0 ;nIndex<cInstances ;nIndex++)
  77. ppInstances[nIndex] = (IWbemClassObject*)m_ptrArr[nIndex];
  78. if (SUCCEEDED(hr))
  79. {
  80. // Send the instances to the caller
  81. hr = pHandler->Indicate(cInstances, ppInstances);
  82. for (lIndex = 0; lIndex < cInstances; lIndex++)
  83. ppInstances[lIndex]->Release();
  84. }
  85. // Cleanup
  86. if (ppInstances)
  87. {
  88. delete []ppInstances;
  89. ppInstances = NULL;
  90. }
  91. m_ptrArr.RemoveAll();
  92. m_csPathStr.Empty();
  93. m_csAntecedent.Empty();
  94. m_csCurPnPID.Empty();
  95. m_pClass = NULL;
  96. // End Cleanup
  97. // Set status
  98. hr = pHandler->SetStatus(0, hr, NULL, NULL);
  99. return hr;
  100. }
  101. /////////////////////////////////////
  102. //Obsolete! For testing purposes only
  103. //
  104. int CWhqlObj::GetInfFileCount()
  105. {
  106. TCHAR lpszInfPath[MAX_PATH];
  107. int iInstances = 0;
  108. GetWindowsDirectory(lpszInfPath , sizeof(lpszInfPath));
  109. lstrcat(lpszInfPath , L"\\inf\\*.inf");
  110. WIN32_FIND_DATA findData;
  111. HANDLE hFile = FindFirstFile(lpszInfPath , &findData);
  112. BOOL bRet = TRUE;
  113. while(hFile != INVALID_HANDLE_VALUE && bRet)
  114. {
  115. iInstances++;
  116. bRet = FindNextFile(hFile , &findData);
  117. }
  118. return iInstances;
  119. }
  120. ////////////////////////////////////////////////////
  121. //Fills up pInstance fields passed an Inf file.
  122. //
  123. SCODE CWhqlObj::GetInfData(LPTSTR lpszInfFile , LPTSTR lpszInfSection , LPTSTR szDeviceID , IWbemContext *pCtx ,
  124. IWbemClassObject *pInstance)
  125. {
  126. TCHAR lpReturnedString[2048];
  127. TCHAR lpSectionList[2048];
  128. CStringArray csarrCopyFileSection;
  129. CStringArray csarrCopyFileBinaries;
  130. HRESULT hr = S_FALSE;
  131. HINF InfHandle = SetupOpenInfFile(lpszInfFile, NULL,INF_STYLE_WIN4,NULL);
  132. INFCONTEXT Context;
  133. BOOL bRet ;
  134. if(INVALID_HANDLE_VALUE == InfHandle)
  135. return S_FALSE;
  136. VARIANT v;
  137. VariantInit(&v);
  138. //Find CopyFiles section.
  139. LPTSTR lpSection = NULL;
  140. bRet = SetupFindFirstLine(InfHandle,lpszInfSection,L"CopyFiles",&Context);
  141. if(!bRet)
  142. {
  143. SetupCloseInfFile( InfHandle );
  144. return S_FALSE;
  145. }
  146. bRet = SetupGetLineText(&Context,InfHandle,NULL,NULL,lpReturnedString,
  147. sizeof(lpReturnedString),NULL);
  148. if(!bRet)
  149. {
  150. SetupCloseInfFile( InfHandle );
  151. return S_FALSE;
  152. }
  153. DEBUGTRACE(L"CopyFiles string for file %s is %s\n",lpszInfFile,lpReturnedString);
  154. LPTSTR seps = L",";
  155. LPTSTR token ;
  156. token = wcstok( lpReturnedString, seps );
  157. csarrCopyFileSection.Add(token);//Add token to csarrCopyFileSection
  158. while (token)
  159. {
  160. lpSection = token;
  161. token = wcstok( NULL, seps );
  162. if(token)
  163. csarrCopyFileSection.Add(token);//Add token to csarrCopyFileSection
  164. }
  165. for(int nIndex = 0;nIndex < csarrCopyFileSection.GetSize() ; nIndex++)
  166. {
  167. //Sometimes CopyFile Might have an entry like @mydriver.sys. Take care of that.
  168. if((csarrCopyFileSection[nIndex])[0] == '@')
  169. {
  170. csarrCopyFileBinaries.Add(LPCTSTR(csarrCopyFileSection[nIndex]) + 1);
  171. DEBUGTRACE(L"Adding binary file %s\n" , LPCTSTR(csarrCopyFileSection[nIndex]) + 1);
  172. continue;
  173. }
  174. bRet = SetupFindFirstLine(InfHandle,csarrCopyFileSection[nIndex],NULL,&Context);
  175. //Put all the files mentioned in the CopyFiles section in an array.
  176. LPTSTR token = NULL;
  177. while(bRet)
  178. {
  179. bRet = SetupGetLineText(&Context,InfHandle,NULL,NULL,lpSectionList,
  180. sizeof(lpSectionList),NULL);
  181. token = wcstok(lpSectionList , L",");
  182. if(token != NULL)
  183. lstrcpy(lpSectionList ,token);
  184. DEBUGTRACE(L"Adding binary file %s\n" , lpSectionList);
  185. csarrCopyFileBinaries.Add(lpSectionList);
  186. bRet = SetupFindNextLine(&Context,&Context);
  187. }
  188. }
  189. CString csTemp;
  190. TCHAR str[MAX_PATH] ;
  191. for(nIndex = 0 ; nIndex < csarrCopyFileBinaries.GetSize() ; nIndex++)
  192. {
  193. hr = m_pClass->SpawnInstance(0, &pInstance);
  194. m_ptrArr.Add(pInstance);
  195. if(GetSystemDirectory(str , sizeof(str)) == 0)
  196. return S_FALSE;
  197. lstrcat(str , L"\\Drivers\\");
  198. AddSlashes(str);
  199. csarrCopyFileBinaries[nIndex] = str + csarrCopyFileBinaries[nIndex];
  200. csTemp = m_csPathStr ;
  201. csTemp += L":CIM_DataFile.Name=\"";
  202. csTemp += csarrCopyFileBinaries[nIndex] + L"\"";
  203. PutPropertyValue( pInstance , L"Antecedent" , m_csAntecedent );
  204. PutPropertyValue( pInstance , L"Dependent" , csTemp );
  205. //////////////////BugBug !
  206. PutPropertyValue( pInstance , L"PnPID" , m_csCurPnPID );
  207. }
  208. if( InfHandle != INVALID_HANDLE_VALUE )
  209. SetupCloseInfFile( InfHandle );
  210. return hr;
  211. }
  212. ///////////////////////////////////////////////////////////////////////
  213. //Creates Instances & populates data given the class type asked for
  214. //Classes_Provided eClasses
  215. //
  216. SCODE CWhqlObj::PutData(IWbemContext *pCtx , Classes_Provided eClasses)
  217. {
  218. if(pCtx == NULL)
  219. return S_FALSE;
  220. if( eClasses == Class_Win32_PnPSignedDriverWin32PnPEntity)
  221. {
  222. return CreateAssoc( pCtx );
  223. }
  224. LPCTSTR szRegKey = L"SYSTEM\\CurrentControlSet\\Control\\Class";
  225. HKEY hKey , hSubKey ;
  226. TCHAR szName[MAX_PATH] ;
  227. TCHAR szDeviceID[MAX_PATH] , szClassGuid[MAX_PATH] , szDeviceDesc[MAX_PATH];
  228. LONG nInstanceIndex;
  229. LONG len = sizeof(szName);
  230. HRESULT hr = S_FALSE;
  231. ULONG lRet = 0L;
  232. LONG lIndex = 0L;
  233. IEnumWbemClassObject *pEnum = NULL;
  234. IWbemClassObject *pInstance = NULL;
  235. IWbemClassObject *pObject = NULL;
  236. if(ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE , szRegKey , &hKey))
  237. return S_FALSE;//goto cleanup;
  238. //Get DeviceID , ClassGuid , Description , __NameSpace , __Server from Win32_PnpEntity class
  239. //We need all these fields for further Proc.This call will create an Enum.
  240. BSTR language = SysAllocString(L"WQL");
  241. BSTR query = SysAllocString(L"select DeviceID , ClassGuid , Description , __NameSpace , __Server from Win32_PnpEntity");
  242. hr = m_pNamespace->ExecQuery(language , query ,
  243. WBEM_FLAG_RETURN_IMMEDIATELY|WBEM_FLAG_FORWARD_ONLY, pCtx , &pEnum);
  244. SysFreeString(language);
  245. SysFreeString(query);
  246. if(pEnum == NULL)
  247. return S_FALSE;
  248. VARIANT v;
  249. VariantInit(&v);
  250. m_csAntecedent.Empty();
  251. m_csCurPnPID.Empty();
  252. //Iterate thro' the Enum for each DeviceID.
  253. for(lIndex = 0L ; (WBEM_S_NO_ERROR == pEnum->Next(WBEM_INFINITE , 1 , &pObject , &lRet )) ; )
  254. {
  255. //Fill m_csPathStr.Its value will be used in Antecedent & Dependent in assoc. class.
  256. //At the end of the condition we should have something like
  257. //m_csPathStr = "\\\\A-KJAW-RI1\\root\\CIMV2"
  258. if(m_csPathStr.IsEmpty())
  259. {
  260. hr = pObject->Get(L"__Server", 0, &v, NULL , NULL);
  261. if( SUCCEEDED(hr) )
  262. {
  263. m_csPathStr += L"\\\\";
  264. m_csPathStr += V_BSTR(&v);
  265. hr = pObject->Get(L"__NameSpace", 0, &v, NULL , NULL);
  266. if( SUCCEEDED(hr) )
  267. {
  268. m_csPathStr += L"\\";
  269. m_csPathStr += V_BSTR(&v);
  270. }
  271. DEBUGTRACE(L"Server & Namespace Path = %s\n" , m_csPathStr);
  272. VariantClear(&v);
  273. }
  274. }
  275. //Get DeviceID from the pObject in the Enum.
  276. hr = pObject->Get(L"DeviceID", 0, &v, NULL , NULL);
  277. if( SUCCEEDED(hr) )
  278. {
  279. if(eClasses == Class_Win32_PnPSignedDriverCIMDataFile)
  280. {
  281. lstrcpy(szDeviceID , V_BSTR(&v));
  282. m_csCurPnPID = szDeviceID;
  283. AddSlashes(szDeviceID);
  284. CString csTemp = m_csPathStr ;
  285. csTemp += L":Win32_PnPSignedDriver.PnPId=\"";
  286. csTemp += szDeviceID;
  287. csTemp += L"\"";
  288. m_csAntecedent = csTemp;//This will be used in assoc. class.
  289. }
  290. lstrcpy(szDeviceID , V_BSTR(&v));
  291. DEBUGTRACE(L"PnPID = %s\n" , szDeviceID);
  292. VariantClear(&v);
  293. }
  294. //Get ClassGuid from the pObject in the Enum.
  295. hr = pObject->Get(L"ClassGuid", 0, &v, NULL , NULL);
  296. if( SUCCEEDED(hr) )
  297. {
  298. lstrcpy(szClassGuid , V_BSTR(&v));
  299. DEBUGTRACE(L"ClassGuid = %s\n" , szClassGuid);
  300. TRACE(V_BSTR(&v));
  301. }
  302. //Get Description from the pObject in the Enum.
  303. hr = pObject->Get(L"Description", 0, &v, NULL , NULL);
  304. if( SUCCEEDED(hr) )
  305. {
  306. lstrcpy(szDeviceDesc , V_BSTR(&v));
  307. DEBUGTRACE(L"DriverDesc = %s\n" , szDeviceDesc);
  308. TRACE(V_BSTR(&v));
  309. }
  310. if(ERROR_SUCCESS == RegOpenKey(hKey, szClassGuid, &hSubKey) )
  311. {
  312. //BugBug:
  313. //Get no. of subKeys for the GUID.
  314. //If there are no subKeys (i presume) this means no Instances of the device
  315. //represented by the GUID are present so we need not Instantiate an Instance Of win32_PnPSignedDriver.
  316. RegQueryInfoKey(hSubKey , NULL , NULL , NULL , &lRet , NULL , NULL , NULL , NULL
  317. , NULL , NULL , NULL);
  318. if(eClasses == Class_Win32_PnPSignedDriver && lRet > 0)
  319. {
  320. hr = m_pClass->SpawnInstance(0, &pInstance);
  321. if(FAILED(hr))
  322. continue;
  323. m_ptrArr.Add(pInstance);
  324. PutPropertyValue( pInstance , L"PnPID" , szDeviceID );
  325. PutPropertyValue( pInstance , L"ClassGuid" , szClassGuid );
  326. //PutPropertyValue( pInstance , L"DriverDesc" , szDeviceDesc );
  327. PutPropertyValue( pInstance , L"Description" , szDeviceDesc );
  328. szName[0] = '\0';
  329. hr = GetService(szDeviceID , szName , (ULONG*)&len);
  330. CStringArray hwidArr;
  331. LPTSTR szHwid = szName;
  332. hwidArr.RemoveAll();
  333. while(len > 0 && *szHwid != '\0')
  334. {
  335. hwidArr.Add(szHwid);
  336. szHwid += lstrlen(szHwid) + 1;
  337. }
  338. if( hwidArr.GetSize() )
  339. {
  340. LPSAFEARRAY psa;
  341. LONG lArrSize = (LONG)hwidArr.GetSize();
  342. SAFEARRAYBOUND rgsabound[] = { lArrSize , 0 };
  343. psa = SafeArrayCreate(VT_BSTR, 1, rgsabound);
  344. if (!psa)
  345. {
  346. return E_OUTOFMEMORY;
  347. }
  348. long dim[1];
  349. BSTR bstr = NULL;
  350. for(int nIdx = 0 ; nIdx < lArrSize ; nIdx++)
  351. {
  352. bstr = hwidArr[nIdx].AllocSysString();
  353. dim[0] = nIdx;
  354. hr = SafeArrayPutElement(psa, dim , bstr);
  355. }
  356. v.vt = VT_ARRAY|VT_BSTR;
  357. v.parray = psa;
  358. hr = pInstance->Put(L"HardwareID", 0, &v, 0 );
  359. VariantClear(&v);
  360. hr = SafeArrayDestroyData(psa);
  361. }
  362. }
  363. nInstanceIndex = 0;
  364. EnumRegKeys(hSubKey , pInstance , szDeviceDesc , szDeviceID , pCtx , eClasses);
  365. RegCloseKey(hSubKey);
  366. if(eClasses == Class_Win32_PnPSignedDriver)
  367. {
  368. PutPropertyValue( pInstance , L"Service" , szName );
  369. }
  370. }
  371. else
  372. {
  373. continue;
  374. }
  375. hr = pObject->Release();
  376. }
  377. //cleanup:
  378. RegCloseKey(hKey);
  379. if(pEnum)
  380. pEnum->Release();
  381. return S_OK;
  382. }
  383. //////////////////////////////////////////////////
  384. //Will return the Service the device supports.
  385. //
  386. SCODE CWhqlObj::GetService(IN LPTSTR szDeviceID , OUT LPTSTR szName , IN ULONG* plen )
  387. {
  388. HKEY hSubKey , hInstanceKey;
  389. DWORD dwType = REG_SZ ;
  390. if(ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE , L"SYSTEM\\CurrentControlSet\\Enum", &hSubKey))
  391. return S_FALSE;
  392. if(ERROR_SUCCESS != RegOpenKey(hSubKey , szDeviceID, &hInstanceKey))
  393. {
  394. RegCloseKey(hSubKey);
  395. return S_FALSE;
  396. }
  397. //RegQueryValueEx(hInstanceKey , L"Service", NULL , &dwType
  398. // , (UCHAR*)szName , (ULONG*)&len );
  399. //Return HardwareID from this func. not service.
  400. dwType = REG_MULTI_SZ;
  401. LONG lRet = RegQueryValueEx(hInstanceKey , L"HardwareID", NULL , &dwType
  402. , (UCHAR*)szName , (ULONG*)plen);
  403. RegCloseKey(hSubKey);
  404. RegCloseKey(hInstanceKey);
  405. return S_OK;
  406. }
  407. ///////////////////////////////////////////////////////
  408. //Enumerates reg key & fills up pInstance fields.
  409. //
  410. SCODE CWhqlObj::EnumRegKeys(HKEY hSubKey , IWbemClassObject* pInstance , LPTSTR szDeviceDesc , LPTSTR szDeviceID ,
  411. IWbemContext *pCtx , Classes_Provided eClasses)
  412. {
  413. LONG nInstanceIndex = 0;
  414. HKEY hInstanceKey;
  415. TCHAR szTempStr[MAX_PATH];
  416. ULONG len = sizeof(szTempStr);
  417. LONG lRet = -1;
  418. DWORD dwType = REG_SZ ;
  419. HRESULT hr = S_FALSE;
  420. BOOL bIsSigned = FALSE;
  421. TCHAR szInfPath[MAX_PATH] , szInfSection[MAX_PATH] , str[MAX_PATH] ;
  422. VARIANT v;
  423. VariantInit(&v);
  424. while(ERROR_SUCCESS == RegEnumKey(hSubKey , nInstanceIndex++, szTempStr , sizeof(szTempStr)) )
  425. {
  426. lRet = RegOpenKey(hSubKey, szTempStr, &hInstanceKey);
  427. if(lRet != ERROR_SUCCESS)
  428. continue;
  429. //Get DriverDesc
  430. len = MAX_PATH;
  431. lRet = RegQueryValueEx(hInstanceKey , L"DriverDesc", NULL , &dwType
  432. , (UCHAR*)szTempStr, &len );
  433. if(lRet != ERROR_SUCCESS)
  434. continue;
  435. if(lstrcmpi(szTempStr , szDeviceDesc) != 0)
  436. {
  437. RegCloseKey(hInstanceKey);
  438. continue;
  439. }
  440. if(eClasses == Class_Win32_PnPSignedDriver)
  441. {
  442. DEBUGTRACE(L"DriverDesc= %s\n" , szTempStr);
  443. //Put DriverDesc
  444. PutPropertyValue( pInstance , L"DriverDesc" , szTempStr );
  445. //Get DriverDate
  446. len = MAX_PATH;
  447. lRet = RegQueryValueEx(hInstanceKey,L"DriverDate", NULL , &dwType , (UCHAR*)szTempStr,(ULONG*)&len );
  448. //if(lRet != ERROR_SUCCESS)
  449. // continue;
  450. DEBUGTRACE(L"DriverDate = %s\n" , szTempStr);
  451. //Put DriverDesc
  452. PutPropertyValue( pInstance , L"DriverDate" , szTempStr );
  453. //Get DriverVersion
  454. len = MAX_PATH;
  455. lRet = RegQueryValueEx(hInstanceKey,L"DriverVersion", NULL , &dwType ,
  456. (UCHAR*)szTempStr,(ULONG*)&len );
  457. //if(lRet != ERROR_SUCCESS)
  458. // continue;
  459. DEBUGTRACE(L"DriverVersion= %s\n" , szTempStr);
  460. //Put DriverVersion
  461. PutPropertyValue( pInstance , L"DriverVersion" , szTempStr );
  462. //Get ProviderName
  463. len = MAX_PATH;
  464. lRet = RegQueryValueEx(hInstanceKey,L"ProviderName", NULL , &dwType ,
  465. (UCHAR*)szTempStr,(ULONG*)&len );
  466. //if(lRet != ERROR_SUCCESS)
  467. // continue;
  468. DEBUGTRACE(L"ProviderName= %s\n" , szTempStr);
  469. //Put ProviderName
  470. PutPropertyValue( pInstance , L"ProviderName" , szTempStr );
  471. }
  472. //Get InfPath
  473. szInfPath[0] = '\0';
  474. len = MAX_PATH;
  475. lRet = RegQueryValueEx(hInstanceKey,L"InfPath", NULL , &dwType , (UCHAR*)szInfPath,(ULONG*)&len );
  476. //if(lRet != ERROR_SUCCESS)
  477. // continue;
  478. DEBUGTRACE(L"InfPath = %s\n" , szInfPath);
  479. //Put InfPath
  480. if(eClasses == Class_Win32_PnPSignedDriver)
  481. {
  482. PutPropertyValue( pInstance , L"InfPath" , szInfPath );
  483. }
  484. //Get Infsection
  485. szInfSection[0] = '\0';
  486. len = MAX_PATH;
  487. lRet = RegQueryValueEx(hInstanceKey,L"InfSection", NULL , &dwType , (UCHAR*)szInfSection,(ULONG*)&len );
  488. //if(lRet != ERROR_SUCCESS)
  489. // continue;
  490. DEBUGTRACE(L"InfSection = %s\n" , szInfSection);
  491. //Get InfsectionExt
  492. szTempStr[0] = '\0';
  493. len = MAX_PATH;
  494. lRet = RegQueryValueEx(hInstanceKey,L"InfSectionExt", NULL , &dwType , (UCHAR*)szTempStr,(ULONG*)&len );
  495. //if(lRet != ERROR_SUCCESS)
  496. // continue;
  497. DEBUGTRACE(L"InfSectionExt = %s\n" , szTempStr);
  498. lstrcat(szInfSection , szTempStr);
  499. //Only if Class_Win32_PnPSignedDriverCIMDataFile call GetInfData to fill up all the
  500. //Win32_PnPSignedDriverCIMDataFile class data.
  501. if(eClasses == Class_Win32_PnPSignedDriverCIMDataFile)
  502. {
  503. GetInfData(szInfPath , szInfSection , szDeviceID , pCtx , pInstance);
  504. }
  505. RegCloseKey(hInstanceKey);
  506. if(eClasses == Class_Win32_PnPSignedDriver)
  507. {
  508. if(GetWindowsDirectory(str , sizeof(str)) == 0)
  509. return S_FALSE;
  510. lstrcat(str , L"\\inf\\" );
  511. lstrcat(str , szInfPath);
  512. IsInfSigned( str , pInstance);
  513. }
  514. break;
  515. }
  516. return hr;
  517. }
  518. SCODE CWhqlObj::CreateAssoc( IWbemContext *pCtx )
  519. {
  520. IEnumWbemClassObject *pEnum = NULL;
  521. IWbemClassObject *pInstance = NULL;
  522. IWbemClassObject *pObject = NULL;
  523. CComBSTR language = L"WQL";
  524. CComBSTR query = L"select DeviceID , ClassGuid , __NameSpace , __Server from Win32_PnpEntity";
  525. CComBSTR tmpBstr = NULL;
  526. CComVariant v;
  527. ULONG ulRet = 0;
  528. HRESULT hr = m_pNamespace->ExecQuery(language , query ,
  529. WBEM_FLAG_RETURN_IMMEDIATELY|WBEM_FLAG_FORWARD_ONLY, pCtx , &pEnum);
  530. if(pEnum == NULL)
  531. return hr;
  532. for( ; (WBEM_S_NO_ERROR == pEnum->Next(WBEM_INFINITE , 1 , &pObject , &ulRet )) ; )
  533. {
  534. //Fill m_csPathStr.Its value will be used in Antecedent & Dependent in assoc. class.
  535. //At the end of the condition we should have something like
  536. //m_csPathStr = "\\\\A-KJAW-RI1\\root\\CIMV2"
  537. if(m_csPathStr.IsEmpty())
  538. {
  539. hr = pObject->Get(L"__Server", 0, &v, NULL , NULL);
  540. if( SUCCEEDED(hr) )
  541. {
  542. m_csPathStr += L"\\\\";
  543. m_csPathStr += V_BSTR(&v);
  544. hr = pObject->Get(L"__NameSpace", 0, &v, NULL , NULL);
  545. if( SUCCEEDED(hr) )
  546. {
  547. m_csPathStr += L"\\";
  548. m_csPathStr += V_BSTR(&v);
  549. }
  550. DEBUGTRACE(L"Server & Namespace Path = %s\n" , m_csPathStr);
  551. VariantClear(&v);
  552. }
  553. }
  554. hr = m_pClass->SpawnInstance(0, &pInstance);
  555. hr = pObject->Get(L"__PATH", 0, &v, NULL , NULL);
  556. hr = pInstance->Put(L"Dependent", 0, &v, 0 );
  557. v.Clear();
  558. hr = pObject->Get(L"DeviceID", 0, &v, NULL , NULL);
  559. tmpBstr = m_csPathStr + "\\Win32_PnPSignedDriver.PnPID=\"";
  560. tmpBstr += v.bstrVal;
  561. tmpBstr += "\"";
  562. PutPropertyValue( pInstance , L"Antecedent" , tmpBstr );
  563. m_ptrArr.Add(pInstance);
  564. }
  565. return hr;
  566. }
  567. VOID AddSlashes(LPTSTR str)
  568. {
  569. LONG len = lstrlen(str);
  570. TCHAR szTmp[MAX_PATH];
  571. int nIndex1,nIndex2;
  572. for(nIndex1 = nIndex2= 0 ; nIndex1 < len ; nIndex1++ , nIndex2++)
  573. {
  574. if(str[nIndex1] == '\\')
  575. szTmp[nIndex2++] = '\\';
  576. szTmp[nIndex2] = str[nIndex1];
  577. }
  578. szTmp[nIndex2] = '\0';
  579. lstrcpy(str , szTmp);
  580. }
  581. VOID DEBUGTRACE(LPTSTR pszText , ... )
  582. {
  583. #ifdef _DEBUG
  584. TCHAR szDebugStr[256];
  585. va_list argList;
  586. va_start(argList, pszText);
  587. vswprintf(szDebugStr , pszText, argList);
  588. va_end(argList);
  589. OutputDebugString(szDebugStr);
  590. #endif
  591. }
  592. SCODE PutPropertyValue( IWbemClassObject* pInstance , LPCTSTR lpszProperty , LPCTSTR lpszValue )
  593. {
  594. HRESULT hr = S_FALSE;
  595. if(pInstance == NULL)
  596. return hr;
  597. CComVariant var;
  598. var = lpszValue;
  599. hr = pInstance->Put(lpszProperty , 0, &var, 0 );
  600. return hr;
  601. }