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.

2318 lines
74 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2001.
  5. //
  6. // File: RSOPWizard.cpp
  7. //
  8. // Contents: implementation of RSOP wizard
  9. //
  10. // Classes: CRSOPWizard
  11. //
  12. // Functions:
  13. //
  14. // History: 08-02-2001 rhynierm Created
  15. //
  16. //---------------------------------------------------------------------------
  17. #include "main.h"
  18. #include "RSOPWizard.h"
  19. #include "sddl.h" // for sid to string functions
  20. #include "RSOPUtil.h"
  21. //---------------------------------------------------------------------------
  22. // Utility methods
  23. //
  24. WCHAR * NameWithoutDomain(WCHAR * szName)
  25. {
  26. // The name passed in could be of the form
  27. // "domain/name"
  28. // or it could be just
  29. // "name"
  30. int cch = 0;
  31. if (NULL != szName)
  32. {
  33. while (szName[cch])
  34. {
  35. if (szName[cch] == L'/' || szName[cch] == L'\\')
  36. {
  37. return &szName[cch + 1];
  38. }
  39. cch++;
  40. }
  41. }
  42. return szName;
  43. }
  44. //---------------------------------------------------------------------------
  45. // CRSOPWizard class implementation
  46. //
  47. //-------------------------------------------------------
  48. // RSOP data generation/manipulation
  49. HRESULT CRSOPWizard::DeleteRSOPData( LPTSTR szNameSpace, LPRSOP_QUERY pQuery )
  50. {
  51. IWbemLocator * pLocator = NULL;
  52. IWbemServices * pNamespace = NULL;
  53. IWbemClassObject * pClass = NULL;
  54. IWbemClassObject * pOutInst = NULL;
  55. IWbemClassObject * pInClass = NULL;
  56. IWbemClassObject * pInInst = NULL;
  57. BSTR bstrParam = NULL;
  58. BSTR bstrClassPath = NULL;
  59. BSTR bstrMethodName = NULL;
  60. VARIANT var;
  61. TCHAR szBuffer[MAX_PATH];
  62. LPTSTR szLocalNameSpace = NULL;
  63. HRESULT hr;
  64. HRESULT hrSuccess;
  65. ULONG ulNoChars;
  66. ulNoChars = 2+lstrlen(szNameSpace);
  67. szLocalNameSpace = (LPTSTR)LocalAlloc(LPTR, ulNoChars*sizeof(TCHAR));
  68. if (!szLocalNameSpace) {
  69. hr = HRESULT_FROM_WIN32(GetLastError());
  70. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::DeleteRSOPData: LocalAlloc failed with 0x%x"), hr));
  71. goto Cleanup;
  72. }
  73. if (CompareString (LOCALE_USER_DEFAULT, NORM_STOP_ON_NULL,
  74. TEXT("\\\\"), 2, szNameSpace, 2) == CSTR_EQUAL) {
  75. if (CompareString (LOCALE_USER_DEFAULT, NORM_STOP_ON_NULL,
  76. TEXT("\\\\."), 3, szNameSpace, 3) != CSTR_EQUAL) {
  77. LPTSTR lpEnd;
  78. lpEnd = wcschr(szNameSpace+2, L'\\');
  79. if (!lpEnd) {
  80. hr = E_FAIL;
  81. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::DeleteRSOPData: Invalid format for name space")));
  82. goto Cleanup;
  83. }
  84. else {
  85. hr = StringCchCopy(szLocalNameSpace, ulNoChars, TEXT("\\\\."));
  86. if (SUCCEEDED(hr))
  87. {
  88. hr = StringCchCat(szLocalNameSpace, ulNoChars, lpEnd);
  89. }
  90. if (FAILED(hr))
  91. {
  92. goto Cleanup;
  93. }
  94. }
  95. }
  96. else {
  97. hr = StringCchCopy(szLocalNameSpace, ulNoChars, szNameSpace);
  98. if (FAILED(hr))
  99. {
  100. goto Cleanup;
  101. }
  102. }
  103. }
  104. else {
  105. hr = StringCchCopy(szLocalNameSpace, ulNoChars, szNameSpace);
  106. if (FAILED(hr))
  107. {
  108. goto Cleanup;
  109. }
  110. }
  111. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::DeleteRSOPData: Namespace passed to the provider = %s"), szLocalNameSpace));
  112. hr = CoCreateInstance(CLSID_WbemLocator,
  113. 0,
  114. CLSCTX_INPROC_SERVER,
  115. IID_IWbemLocator,
  116. (LPVOID *) &pLocator);
  117. if (FAILED(hr))
  118. {
  119. goto Cleanup;
  120. }
  121. if ( pQuery->QueryType == RSOP_LOGGING_MODE )
  122. {
  123. // set up diagnostic mode
  124. // build a path to the target: "\\\\computer\\root\\rsop"
  125. hr = StringCchPrintf(szBuffer,
  126. ARRAYSIZE(szBuffer),
  127. TEXT("\\\\%s\\root\\rsop"),
  128. NameWithoutDomain( pQuery->szComputerName ));
  129. if (FAILED(hr))
  130. {
  131. goto Cleanup;
  132. }
  133. bstrParam = SysAllocString(szBuffer);
  134. if (!bstrParam)
  135. {
  136. hr = E_FAIL;
  137. goto Cleanup;
  138. }
  139. hr = pLocator->ConnectServer(bstrParam,
  140. NULL,
  141. NULL,
  142. NULL,
  143. 0,
  144. NULL,
  145. NULL,
  146. &pNamespace);
  147. if (FAILED(hr))
  148. {
  149. goto Cleanup;
  150. }
  151. bstrClassPath = SysAllocString(TEXT("RsopLoggingModeProvider"));
  152. hr = pNamespace->GetObject(bstrClassPath,
  153. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  154. NULL,
  155. &pClass,
  156. NULL);
  157. if (FAILED(hr))
  158. {
  159. goto Cleanup;
  160. }
  161. }
  162. else
  163. {
  164. // set up planning mode
  165. // build a path to the DC: "\\\\dc\\root\\rsop"
  166. hr = StringCchPrintf( szBuffer,
  167. ARRAYSIZE(szBuffer),
  168. TEXT("\\\\%s\\root\\rsop"),
  169. pQuery->szDomainController );
  170. if (FAILED(hr))
  171. {
  172. goto Cleanup;
  173. }
  174. bstrParam = SysAllocString(szBuffer);
  175. if (!bstrParam)
  176. {
  177. hr = E_FAIL;
  178. goto Cleanup;
  179. }
  180. hr = pLocator->ConnectServer(bstrParam,
  181. NULL,
  182. NULL,
  183. NULL,
  184. 0,
  185. NULL,
  186. NULL,
  187. &pNamespace);
  188. if (FAILED(hr))
  189. {
  190. goto Cleanup;
  191. }
  192. bstrClassPath = SysAllocString(TEXT("RsopPlanningModeProvider"));
  193. hr = pNamespace->GetObject(bstrClassPath,
  194. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  195. NULL,
  196. &pClass,
  197. NULL);
  198. if (FAILED(hr))
  199. {
  200. goto Cleanup;
  201. }
  202. }
  203. bstrMethodName = SysAllocString(TEXT("RsopDeleteSession"));
  204. if (!bstrMethodName)
  205. {
  206. hr = E_FAIL;
  207. goto Cleanup;
  208. }
  209. hr = pClass->GetMethod(bstrMethodName,
  210. 0,
  211. &pInClass,
  212. NULL);
  213. if (FAILED(hr))
  214. {
  215. goto Cleanup;
  216. }
  217. hr = pInClass->SpawnInstance(0, &pInInst);
  218. if (FAILED(hr))
  219. {
  220. goto Cleanup;
  221. }
  222. hr = SetParameter(pInInst, TEXT("nameSpace"), szLocalNameSpace);
  223. if (FAILED(hr))
  224. {
  225. goto Cleanup;
  226. }
  227. // Set the proper security to prevent the ExecMethod call from failing and to enable encryption
  228. hr = CoSetProxyBlanket(pNamespace,
  229. RPC_C_AUTHN_DEFAULT,
  230. RPC_C_AUTHZ_DEFAULT,
  231. COLE_DEFAULT_PRINCIPAL,
  232. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  233. RPC_C_IMP_LEVEL_IMPERSONATE,
  234. NULL,
  235. 0);
  236. if (FAILED(hr))
  237. {
  238. goto Cleanup;
  239. }
  240. hr = pNamespace->ExecMethod(bstrClassPath,
  241. bstrMethodName,
  242. 0,
  243. NULL,
  244. pInInst,
  245. &pOutInst,
  246. NULL);
  247. if (FAILED(hr))
  248. {
  249. goto Cleanup;
  250. }
  251. hr = GetParameter(pOutInst, TEXT("hResult"), hrSuccess);
  252. if (SUCCEEDED(hr))
  253. {
  254. if (FAILED(hrSuccess))
  255. {
  256. hr = hrSuccess;
  257. }
  258. }
  259. Cleanup:
  260. if (szLocalNameSpace) {
  261. LocalFree(szLocalNameSpace);
  262. szLocalNameSpace = NULL;
  263. }
  264. SysFreeString(bstrParam);
  265. SysFreeString(bstrClassPath);
  266. SysFreeString(bstrMethodName);
  267. if (pInInst)
  268. {
  269. pInInst->Release();
  270. }
  271. if (pOutInst)
  272. {
  273. pOutInst->Release();
  274. }
  275. if (pInClass)
  276. {
  277. pInClass->Release();
  278. }
  279. if (pClass)
  280. {
  281. pClass->Release();
  282. }
  283. if (pNamespace)
  284. {
  285. pNamespace->Release();
  286. }
  287. if (pLocator)
  288. {
  289. pLocator->Release();
  290. }
  291. return hr;
  292. }
  293. //-------------------------------------------------------
  294. // Synopsis: Wrapper around GenerateRSOPData. This version adds retry
  295. // support. If the user doesn't have access to half of the data
  296. // this method will re-issue the query for only the part of the data
  297. // the user has access to.
  298. HRESULT CRSOPWizard::GenerateRSOPDataEx( HWND hDlg, LPRSOP_QUERY pQuery, LPRSOP_QUERY_RESULTS* ppResults )
  299. {
  300. // Check preconditions
  301. if ( pQuery == NULL )
  302. {
  303. return E_FAIL;
  304. }
  305. *ppResults = (LPRSOP_QUERY_RESULTS)LocalAlloc( LPTR, sizeof(RSOP_QUERY_RESULTS) );
  306. if ( *ppResults == NULL )
  307. {
  308. DebugMsg( (DM_WARNING, TEXT("CreateRSOPQuery: Failed to allocate memory with 0x%x."), HRESULT_FROM_WIN32(GetLastError())) );
  309. return E_FAIL;
  310. }
  311. (*ppResults)->szWMINameSpace = 0;
  312. (*ppResults)->bUserDeniedAccess = FALSE;
  313. (*ppResults)->bNoUserPolicyData = FALSE;
  314. (*ppResults)->bComputerDeniedAccess = FALSE;
  315. (*ppResults)->bNoComputerPolicyData = FALSE;
  316. (*ppResults)->ulErrorInfo = 0;
  317. HRESULT hr;
  318. BOOL bSkipCSEs, bLimitData, bUser, bForceCreate;
  319. bSkipCSEs = bLimitData = bUser = bForceCreate = FALSE;
  320. // Perform basic RSOP query
  321. hr = GenerateRSOPData( hDlg, pQuery, &((*ppResults)->szWMINameSpace),
  322. bSkipCSEs, bLimitData, bUser, bForceCreate,
  323. &((*ppResults)->ulErrorInfo) );
  324. if (FAILED(hr))
  325. {
  326. BOOL bNoUserData = FALSE;
  327. BOOL bNoComputerData = FALSE;
  328. if ( ((*ppResults)->ulErrorInfo) == RSOP_USER_ACCESS_DENIED )
  329. {
  330. if ( (pQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY )
  331. {
  332. // Do not try to do the query without the user's RSOP data since
  333. // we are not supposed to get the computer's RSOP data in any case.
  334. // NOTE: Since we already have UI lockdown another string cannot be added
  335. // at this stage to describe this specific failure. The message for access
  336. // denied for both user and computer must therefor suffice and will not
  337. // create any real confusion.
  338. (*ppResults)->ulErrorInfo = RSOP_USER_ACCESS_DENIED | RSOP_COMPUTER_ACCESS_DENIED;
  339. }
  340. else
  341. {
  342. ReportError (hDlg, hr, IDS_EXECFAILED_USER);
  343. (*ppResults)->bUserDeniedAccess = TRUE;
  344. FillResultsList( GetDlgItem (hDlg, IDC_LIST1), pQuery, *ppResults );
  345. bSkipCSEs = bUser = bForceCreate = FALSE;
  346. bLimitData = TRUE;
  347. bNoUserData = TRUE;
  348. hr = GenerateRSOPData( hDlg, pQuery, &((*ppResults)->szWMINameSpace),
  349. bSkipCSEs, bLimitData, bUser, bForceCreate,
  350. &((*ppResults)->ulErrorInfo),
  351. bNoUserData, bNoComputerData );
  352. }
  353. }
  354. else if ( ((*ppResults)->ulErrorInfo) == RSOP_COMPUTER_ACCESS_DENIED )
  355. {
  356. if ( (pQuery->dwFlags & RSOP_NO_USER_POLICY) == RSOP_NO_USER_POLICY )
  357. {
  358. // Do not try to do the query without the computer's RSOP data since
  359. // we are not supposed to get the user's RSOP data in any case.
  360. // NOTE: Since we already have UI lockdown another string cannot be added
  361. // at this stage to describe this specific failure. The message for access
  362. // denied for both user and computer must therefor suffice and will not
  363. // create any real confusion.
  364. (*ppResults)->ulErrorInfo = RSOP_USER_ACCESS_DENIED | RSOP_COMPUTER_ACCESS_DENIED;
  365. }
  366. else
  367. {
  368. ReportError (hDlg, hr, IDS_EXECFAILED_COMPUTER);
  369. (*ppResults)->bComputerDeniedAccess = TRUE;
  370. FillResultsList( GetDlgItem (hDlg, IDC_LIST1), pQuery, *ppResults );
  371. bSkipCSEs = bForceCreate = FALSE;
  372. bLimitData = bUser = TRUE;
  373. bNoComputerData = TRUE;
  374. hr = GenerateRSOPData (hDlg, pQuery, &((*ppResults)->szWMINameSpace),
  375. bSkipCSEs, bLimitData, bUser, bForceCreate,
  376. &((*ppResults)->ulErrorInfo),
  377. bNoUserData, bNoComputerData );
  378. }
  379. }
  380. if (FAILED(hr))
  381. {
  382. if ( (((*ppResults)->ulErrorInfo) & RSOP_COMPUTER_ACCESS_DENIED) &&
  383. (((*ppResults)->ulErrorInfo) & RSOP_USER_ACCESS_DENIED) )
  384. {
  385. // both are denied access
  386. ReportError (hDlg, hr, IDS_EXECFAILED_BOTH);
  387. }
  388. else if (hr == HRESULT_FROM_WIN32(WAIT_TIMEOUT))
  389. {
  390. ReportError (hDlg, hr, IDS_EXECFAILED_TIMEDOUT);
  391. }
  392. else if ( ((*ppResults)->ulErrorInfo) & RSOP_TEMPNAMESPACE_EXISTS )
  393. {
  394. TCHAR szConfirm[MAX_PATH], szTitle[MAX_PATH];
  395. szConfirm[0] = szTitle[0] = TEXT('\0');
  396. // If this is a new query being performed and this error condition occurs, we can savely say
  397. // that someone else is hogging the namespace, otherwise, it is probably us doing the hogging :)
  398. if ( (pQuery->dwFlags & RSOP_NEW_QUERY) == RSOP_NEW_QUERY )
  399. {
  400. LoadString(g_hInstance, IDS_RSOPDELNAMESPACE, szConfirm, ARRAYSIZE(szConfirm));
  401. }
  402. else
  403. {
  404. LoadString(g_hInstance, IDS_RSOPDELNAMESPACE2, szConfirm, ARRAYSIZE(szConfirm));
  405. }
  406. LoadString(g_hInstance, IDS_RSOPDELNS_TITLE, szTitle, ARRAYSIZE(szTitle));
  407. if (MessageBox(hDlg, szConfirm, szTitle, MB_OKCANCEL | MB_ICONQUESTION | MB_DEFBUTTON2) == IDOK) {
  408. // use the same options as before
  409. bForceCreate = TRUE;
  410. hr = GenerateRSOPData( hDlg, pQuery, &((*ppResults)->szWMINameSpace),
  411. bSkipCSEs, bLimitData, bUser, bForceCreate,
  412. &((*ppResults)->ulErrorInfo),
  413. bNoUserData, bNoComputerData );
  414. if ( FAILED(hr) )
  415. {
  416. if ( hr == HRESULT_FROM_WIN32(WAIT_TIMEOUT) )
  417. {
  418. ReportError( hDlg, hr, IDS_EXECFAILED_TIMEDOUT );
  419. }
  420. else
  421. {
  422. ReportError( hDlg, hr, IDS_EXECFAILED );
  423. }
  424. }
  425. }
  426. }
  427. else
  428. {
  429. ReportError (hDlg, hr, IDS_EXECFAILED);
  430. }
  431. }
  432. }
  433. return hr;
  434. }
  435. //-------------------------------------------------------
  436. // Synopsis: Calls the rsop provider based on the settings made in the
  437. // initialization wizard
  438. //
  439. // Arguments:
  440. //
  441. // Returns:
  442. //
  443. // Modifies:
  444. //
  445. // History: 10-04-1999 stevebl Created
  446. //
  447. // Notes:
  448. //
  449. HRESULT CRSOPWizard::GenerateRSOPData( HWND hDlg,
  450. LPRSOP_QUERY pQuery,
  451. LPTSTR* pszNameSpace,
  452. BOOL bSkipCSEs,
  453. BOOL bLimitData,
  454. BOOL bUser,
  455. BOOL bForceCreate,
  456. ULONG *pulErrorInfo,
  457. BOOL bNoUserData /* = FALSE */,
  458. BOOL bNoComputerData /* = FALSE */)
  459. {
  460. // Check preconditions
  461. if ( pQuery == NULL )
  462. {
  463. return E_FAIL;
  464. }
  465. IWbemLocator * pLocator = NULL;
  466. IWbemServices * pNamespace = NULL;
  467. IWbemClassObject * pClass = NULL;
  468. IWbemClassObject * pOutInst = NULL;
  469. IWbemClassObject * pInClass = NULL;
  470. IWbemClassObject * pInInst = NULL;
  471. IUnsecuredApartment *pSpawner = NULL;
  472. IUnknown *pSubstitute = NULL;
  473. IWbemObjectSink *pSubstituteSink = NULL;
  474. BSTR bstrParam = NULL;
  475. BSTR bstrClassPath = NULL;
  476. BSTR bstrMethodName = NULL;
  477. VARIANT var;
  478. TCHAR szBuffer[MAX_PATH];
  479. HRESULT hr;
  480. HRESULT hrSuccess;
  481. CCreateSessionSink *pCSS = NULL;
  482. MSG msg;
  483. UINT uiFlags = 0;
  484. BOOL bSetData;
  485. HANDLE hEvent = NULL;
  486. hr = CoCreateInstance(CLSID_WbemLocator,
  487. 0,
  488. CLSCTX_INPROC_SERVER,
  489. IID_IWbemLocator,
  490. (LPVOID *) &pLocator);
  491. if (FAILED(hr))
  492. {
  493. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: CoCreateInstance failed with 0x%x"), hr));
  494. goto Cleanup;
  495. }
  496. if ( pQuery->QueryType == RSOP_LOGGING_MODE )
  497. {
  498. // set up diagnostic mode
  499. // build a path to the target: "\\\\computer\\root\\rsop"
  500. hr = StringCchPrintf(szBuffer,
  501. ARRAYSIZE(szBuffer),
  502. TEXT("\\\\%s\\root\\rsop"),
  503. NameWithoutDomain(pQuery->szComputerName));
  504. if (FAILED(hr))
  505. {
  506. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: failed to copy computer name with 0x%x"), hr));
  507. goto Cleanup;
  508. }
  509. bstrParam = SysAllocString(szBuffer);
  510. hr = pLocator->ConnectServer(bstrParam,
  511. NULL,
  512. NULL,
  513. NULL,
  514. 0,
  515. NULL,
  516. NULL,
  517. &pNamespace);
  518. if (FAILED(hr))
  519. {
  520. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: ConnectServer failed with 0x%x"), hr));
  521. if ( hDlg != NULL )
  522. {
  523. WCHAR szTitle[MAX_PATH];
  524. ULONG ulSize;
  525. ulSize = ARRAYSIZE(szTitle);
  526. if ( !lstrcmpi(pQuery->szComputerName, L".") )
  527. {
  528. if (!GetComputerObjectName (NameDisplay, szTitle, &ulSize))
  529. {
  530. ulSize = ARRAYSIZE(szTitle);
  531. if ( !GetComputerNameEx (ComputerNamePhysicalNetBIOS, szTitle, &ulSize))
  532. {
  533. hr = StringCchCopy(szTitle, ulSize, L".");
  534. if (FAILED(hr))
  535. {
  536. goto Cleanup;
  537. }
  538. }
  539. }
  540. ReportError (hDlg, hr, IDS_CONNECTSERVERFAILED, szTitle);
  541. }
  542. else
  543. {
  544. ReportError (hDlg, hr, IDS_CONNECTSERVERFAILED, pQuery->szComputerName);
  545. }
  546. }
  547. goto Cleanup;
  548. }
  549. bstrClassPath = SysAllocString(TEXT("RsopLoggingModeProvider"));
  550. hr = pNamespace->GetObject(bstrClassPath,
  551. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  552. NULL,
  553. &pClass,
  554. NULL);
  555. if (FAILED(hr))
  556. {
  557. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: GetObject failed with 0x%x"), hr));
  558. goto Cleanup;
  559. }
  560. bstrMethodName = SysAllocString(TEXT("RsopCreateSession"));
  561. hr = pClass->GetMethod(bstrMethodName,
  562. 0,
  563. &pInClass,
  564. NULL);
  565. if (FAILED(hr))
  566. {
  567. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: GetMethod failed with 0x%x"), hr));
  568. goto Cleanup;
  569. }
  570. hr = pInClass->SpawnInstance(0, &pInInst);
  571. if (FAILED(hr))
  572. {
  573. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SpawnInstance failed with 0x%x"), hr));
  574. goto Cleanup;
  575. }
  576. // RM: It is quite difficult to figure out what is going on here. Since this method is called multiple times from GenerateRSOPDataEx,
  577. // where one of there variables gets set, it might be that it was intended that way. Otherwise it serves no purpose to check
  578. // the "results" of a query (bUserDeniedAccess) before generating the results ...
  579. if ( ((pQuery->dwFlags & RSOP_NO_USER_POLICY) == RSOP_NO_USER_POLICY) || bNoUserData)
  580. {
  581. uiFlags |= FLAG_NO_USER;
  582. }
  583. if ( ((pQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY) || bNoComputerData )
  584. {
  585. uiFlags |= FLAG_NO_COMPUTER;
  586. }
  587. if ( bForceCreate )
  588. {
  589. uiFlags |= FLAG_FORCE_CREATENAMESPACE;
  590. }
  591. hr = SetParameter(pInInst, TEXT("flags"), uiFlags);
  592. if (FAILED(hr))
  593. {
  594. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  595. goto Cleanup;
  596. }
  597. // RM: Double check that the the username is set to a "." in the wizard for this case
  598. if ( !lstrcmpi( pQuery->szUserSid, TEXT(".")) )
  599. {
  600. hr = SetParameterToNull( pInInst, TEXT("userSid") );
  601. }
  602. else
  603. {
  604. hr = SetParameter( pInInst, TEXT("userSid"), pQuery->szUserSid );
  605. }
  606. if (FAILED(hr))
  607. {
  608. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  609. goto Cleanup;
  610. }
  611. }
  612. else if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  613. {
  614. // set up planning mode
  615. // build a path to the DC: "\\\\dc\\root\\rsop"
  616. hr = StringCchPrintf(szBuffer,
  617. ARRAYSIZE(szBuffer),
  618. TEXT("\\\\%s\\root\\rsop"),
  619. pQuery->szDomainController );
  620. if (FAILED(hr))
  621. {
  622. goto Cleanup;
  623. }
  624. bstrParam = SysAllocString(szBuffer);
  625. hr = pLocator->ConnectServer(bstrParam,
  626. NULL,
  627. NULL,
  628. NULL,
  629. 0,
  630. NULL,
  631. NULL,
  632. &pNamespace);
  633. if (FAILED(hr))
  634. {
  635. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: ConnectServer failed with 0x%x"), hr));
  636. if ( hDlg != NULL )
  637. {
  638. ReportError (hDlg, hr, IDS_CONNECTSERVERFAILED, pQuery->szDomainController );
  639. }
  640. goto Cleanup;
  641. }
  642. bstrClassPath = SysAllocString(TEXT("RsopPlanningModeProvider"));
  643. hr = pNamespace->GetObject(bstrClassPath,
  644. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  645. NULL,
  646. &pClass,
  647. NULL);
  648. if (FAILED(hr))
  649. {
  650. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: GetObject failed with 0x%x"), hr));
  651. goto Cleanup;
  652. }
  653. bstrMethodName = SysAllocString(TEXT("RsopCreateSession"));
  654. hr = pClass->GetMethod(bstrMethodName,
  655. 0,
  656. &pInClass,
  657. NULL);
  658. if (FAILED(hr))
  659. {
  660. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: GetMethod failed with 0x%x"), hr));
  661. goto Cleanup;
  662. }
  663. hr = pInClass->SpawnInstance(0, &pInInst);
  664. if (FAILED(hr))
  665. {
  666. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SpawnInstance failed with 0x%x"), hr));
  667. goto Cleanup;
  668. }
  669. if ( pQuery->bSlowNetworkConnection )
  670. {
  671. uiFlags |= FLAG_ASSUME_SLOW_LINK;
  672. }
  673. if ( !bSkipCSEs || bUser )
  674. {
  675. switch ( pQuery->LoopbackMode)
  676. {
  677. case RSOP_LOOPBACK_REPLACE:
  678. uiFlags |= FLAG_LOOPBACK_REPLACE;
  679. break;
  680. case RSOP_LOOPBACK_MERGE:
  681. uiFlags |= FLAG_LOOPBACK_MERGE;
  682. break;
  683. default:
  684. break;
  685. }
  686. }
  687. if ( bSkipCSEs )
  688. {
  689. uiFlags |= (FLAG_NO_GPO_FILTER | FLAG_NO_CSE_INVOKE);
  690. }
  691. else
  692. {
  693. if ( pQuery->pComputer->bAssumeWQLFiltersTrue )
  694. {
  695. uiFlags |= FLAG_ASSUME_COMP_WQLFILTER_TRUE;
  696. }
  697. if ( pQuery->pUser->bAssumeWQLFiltersTrue )
  698. {
  699. uiFlags |= FLAG_ASSUME_USER_WQLFILTER_TRUE;
  700. }
  701. }
  702. hr = SetParameter(pInInst, TEXT("flags"), uiFlags);
  703. if (FAILED(hr))
  704. {
  705. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  706. goto Cleanup;
  707. }
  708. //
  709. // If this method is being called to generate temporary rsop data for the
  710. // wmi filter UI, we only want to initialize half of the args (either user
  711. // or computer). Decide if we want to set the computer information here.
  712. //
  713. bSetData = TRUE;
  714. if ( bLimitData )
  715. {
  716. if ( bUser && (RSOP_LOOPBACK_NONE == pQuery->LoopbackMode) )
  717. {
  718. bSetData = FALSE;
  719. }
  720. }
  721. if ( (pQuery->pComputer->szName != NULL) && bSetData )
  722. {
  723. hr = SetParameter(pInInst, TEXT("computerName"), pQuery->pComputer->szName );
  724. }
  725. else
  726. {
  727. hr = SetParameterToNull(pInInst, TEXT("computerName"));
  728. }
  729. if (FAILED(hr))
  730. {
  731. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  732. goto Cleanup;
  733. }
  734. if ( (pQuery->pComputer->szSOM != NULL) && bSetData )
  735. {
  736. hr = SetParameter(pInInst, TEXT("computerSOM"), pQuery->pComputer->szSOM );
  737. }
  738. else
  739. {
  740. hr = SetParameterToNull (pInInst, TEXT("computerSOM"));
  741. }
  742. if (FAILED(hr))
  743. {
  744. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  745. goto Cleanup;
  746. }
  747. if ( bSetData && (pQuery->pComputer->dwSecurityGroupCount != 0) )
  748. {
  749. SAFEARRAY* saComputerSecurityGroups = NULL;
  750. hr = CreateSafeArray( pQuery->pComputer->dwSecurityGroupCount, pQuery->pComputer->aszSecurityGroups, &saComputerSecurityGroups );
  751. if ( FAILED(hr) )
  752. {
  753. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: CreateSafeArray failed with 0x%x"), hr));
  754. goto Cleanup;
  755. }
  756. hr = SetParameter(pInInst, TEXT("computerSecurityGroups"), saComputerSecurityGroups );
  757. SafeArrayDestroy( saComputerSecurityGroups );
  758. }
  759. else
  760. {
  761. hr = SetParameterToNull(pInInst, TEXT("computerSecurityGroups"));
  762. }
  763. if (FAILED(hr))
  764. {
  765. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  766. goto Cleanup;
  767. }
  768. if ( bSetData && (pQuery->pComputer->dwWQLFilterCount != 0) )
  769. {
  770. SAFEARRAY* saComputerWQLFilters = NULL;
  771. hr = CreateSafeArray( pQuery->pComputer->dwWQLFilterCount, pQuery->pComputer->aszWQLFilters, &saComputerWQLFilters );
  772. if ( FAILED(hr) )
  773. {
  774. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: CreateSafeArray failed with 0x%x"), hr));
  775. goto Cleanup;
  776. }
  777. hr = SetParameter(pInInst, TEXT("computerGPOFilters"), saComputerWQLFilters);
  778. SafeArrayDestroy( saComputerWQLFilters );
  779. }
  780. else
  781. {
  782. hr = SetParameterToNull(pInInst, TEXT("computerGPOFilters"));
  783. }
  784. if (FAILED(hr))
  785. {
  786. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  787. goto Cleanup;
  788. }
  789. //
  790. // If this method is being called to generate temporary RSOP data for the
  791. // wmi filter UI, we only want to initialize half of the args (either user
  792. // or computer). Decide if we want to set the user information here.
  793. //
  794. bSetData = TRUE;
  795. if ( bLimitData )
  796. {
  797. if ( !bUser )
  798. {
  799. bSetData = FALSE;
  800. }
  801. }
  802. if ( (pQuery->pUser->szName != NULL) && bSetData)
  803. {
  804. hr = SetParameter(pInInst, TEXT("userName"), pQuery->pUser->szName );
  805. }
  806. else
  807. {
  808. hr = SetParameterToNull(pInInst, TEXT("userName"));
  809. }
  810. if (FAILED(hr))
  811. {
  812. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  813. goto Cleanup;
  814. }
  815. if ( (pQuery->pUser->szSOM != NULL) && bSetData)
  816. {
  817. hr = SetParameter(pInInst, TEXT("userSOM"), pQuery->pUser->szSOM );
  818. }
  819. else
  820. {
  821. hr = SetParameterToNull (pInInst, TEXT("userSOM"));
  822. }
  823. if (FAILED(hr))
  824. {
  825. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  826. goto Cleanup;
  827. }
  828. if ( bSetData && (pQuery->pUser->dwSecurityGroupCount != 0) )
  829. {
  830. SAFEARRAY* saUserSecurityGroups = NULL;
  831. hr = CreateSafeArray( pQuery->pUser->dwSecurityGroupCount, pQuery->pUser->aszSecurityGroups, &saUserSecurityGroups );
  832. if ( FAILED(hr) )
  833. {
  834. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: CreateSafeArray failed with 0x%x"), hr));
  835. goto Cleanup;
  836. }
  837. hr = SetParameter(pInInst, TEXT("userSecurityGroups"), saUserSecurityGroups );
  838. SafeArrayDestroy( saUserSecurityGroups );
  839. }
  840. else
  841. {
  842. hr = SetParameterToNull(pInInst, TEXT("userSecurityGroups"));
  843. }
  844. if (FAILED(hr))
  845. {
  846. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  847. goto Cleanup;
  848. }
  849. if ( bSetData && (pQuery->pUser->dwWQLFilterCount != 0) )
  850. {
  851. SAFEARRAY* saUserWQLFilters = NULL;
  852. hr = CreateSafeArray( pQuery->pUser->dwWQLFilterCount, pQuery->pUser->aszWQLFilters, &saUserWQLFilters );
  853. if ( FAILED(hr) )
  854. {
  855. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: CreateSafeArray failed with 0x%x"), hr));
  856. goto Cleanup;
  857. }
  858. hr = SetParameter(pInInst, TEXT("userGPOFilters"), saUserWQLFilters);
  859. SafeArrayDestroy( saUserWQLFilters );
  860. }
  861. else
  862. {
  863. hr = SetParameterToNull(pInInst, TEXT("userGPOFilters"));
  864. }
  865. if (FAILED(hr))
  866. {
  867. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  868. goto Cleanup;
  869. }
  870. if ( pQuery->szSite != NULL )
  871. {
  872. hr = SetParameter(pInInst, TEXT("site"), pQuery->szSite );
  873. }
  874. else
  875. {
  876. hr = SetParameterToNull(pInInst, TEXT("site"));
  877. }
  878. if (FAILED(hr))
  879. {
  880. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: SetParameter failed with 0x%x"), hr));
  881. goto Cleanup;
  882. }
  883. }
  884. else
  885. {
  886. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: The query type was not specified properly")));
  887. goto Cleanup;
  888. }
  889. hr = CoCreateInstance(CLSID_UnsecuredApartment, NULL, CLSCTX_ALL,
  890. IID_IUnsecuredApartment, (void **)&pSpawner);
  891. if (FAILED(hr))
  892. {
  893. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: CoCreateInstance for unsecure apartment failed with 0x%x"), hr));
  894. goto Cleanup;
  895. }
  896. hEvent = CreateEvent(
  897. NULL,
  898. FALSE,
  899. FALSE,
  900. NULL);
  901. if (NULL == hEvent)
  902. {
  903. DebugMsg((DM_WARNING, L"CRSOPComponentData::GenerateRSOPData: Failed to create event"));
  904. hr = HRESULT_FROM_WIN32(GetLastError());
  905. goto Cleanup;
  906. }
  907. pCSS = new CCreateSessionSink(hDlg != NULL? GetDlgItem(hDlg, IDC_PROGRESS1) : NULL, hEvent, (pQuery->dwFlags & RSOP_90P_ONLY) != 0);
  908. if (!pCSS)
  909. {
  910. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: Failed to create createsessionsink")));
  911. goto Cleanup;
  912. }
  913. hr = pSpawner->CreateObjectStub(pCSS, &pSubstitute);
  914. if (FAILED(hr))
  915. {
  916. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: CreateObjectStub failed with 0x%x"), hr));
  917. goto Cleanup;
  918. }
  919. hr = pSubstitute->QueryInterface(IID_IWbemObjectSink, (LPVOID *)&pSubstituteSink);
  920. if (FAILED(hr))
  921. {
  922. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: QI failed with 0x%x"), hr));
  923. goto Cleanup;
  924. }
  925. // Set the proper security to prevent the ExecMethod call from failing and to enable encryption
  926. hr = CoSetProxyBlanket(pNamespace,
  927. RPC_C_AUTHN_DEFAULT,
  928. RPC_C_AUTHZ_DEFAULT,
  929. COLE_DEFAULT_PRINCIPAL,
  930. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  931. RPC_C_IMP_LEVEL_IMPERSONATE,
  932. NULL,
  933. 0);
  934. if (FAILED(hr))
  935. {
  936. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: CoSetProxyBlanket failed with 0x%x"), hr));
  937. goto Cleanup;
  938. }
  939. pCSS->SendQuitEvent (TRUE);
  940. hr = pNamespace->ExecMethodAsync(bstrClassPath,
  941. bstrMethodName,
  942. WBEM_FLAG_SEND_STATUS,
  943. NULL,
  944. pInInst,
  945. pSubstituteSink);
  946. if (FAILED(hr))
  947. {
  948. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GenerateRSOPData: ExecMethodAsync failed with 0x%x"), hr));
  949. pCSS->SendQuitEvent (FALSE);
  950. goto Cleanup;
  951. }
  952. DWORD dwEventRetVal;
  953. while (TRUE)
  954. {
  955. dwEventRetVal = MsgWaitForMultipleObjectsEx(
  956. 1,
  957. &hEvent,
  958. INFINITE,
  959. QS_VALID, // QS_ALLINPUT | QS_TRANSFER | QS_ALLPOSTMESSAGE, is what COM seem to be using
  960. // CoWaitForMultipleHandles
  961. MWMO_INPUTAVAILABLE);
  962. if ( WAIT_OBJECT_0 == dwEventRetVal)
  963. {
  964. break;
  965. }
  966. if (PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))
  967. {
  968. TranslateMessage(&msg);
  969. DispatchMessage(&msg);
  970. continue;
  971. }
  972. }
  973. pCSS->SendQuitEvent (FALSE);
  974. pCSS->GetResult (&hrSuccess);
  975. pCSS->GetErrorInfo (pulErrorInfo);
  976. if (SUCCEEDED(hrSuccess))
  977. {
  978. LPTSTR lpComputerName;
  979. BSTR bstrNamespace = NULL;
  980. pCSS->GetNamespace (&bstrNamespace);
  981. if (bstrNamespace)
  982. {
  983. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  984. {
  985. lpComputerName = pQuery->szDomainController;
  986. }
  987. else
  988. {
  989. lpComputerName = NameWithoutDomain(pQuery->szComputerName );
  990. }
  991. ULONG ulNoChars = _tcslen(bstrNamespace) + _tcslen(lpComputerName) + 1;
  992. *pszNameSpace = (TCHAR*)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  993. if (*pszNameSpace)
  994. {
  995. hr = StringCchCopy (*pszNameSpace, ulNoChars, TEXT("\\\\"));
  996. if (SUCCEEDED(hr))
  997. {
  998. hr = StringCchCat (*pszNameSpace, ulNoChars, lpComputerName);
  999. }
  1000. if (SUCCEEDED(hr))
  1001. {
  1002. hr = StringCchCat (*pszNameSpace, ulNoChars, (bstrNamespace+3));
  1003. }
  1004. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::GenerateRSOPData: Complete namespace is: %s"), *pszNameSpace));
  1005. }
  1006. else
  1007. {
  1008. hr = E_OUTOFMEMORY;
  1009. }
  1010. }
  1011. }
  1012. else
  1013. {
  1014. hr = hrSuccess;
  1015. if (hDlg)
  1016. {
  1017. SendMessage (GetDlgItem(hDlg, IDC_PROGRESS1), PBM_SETPOS, 0, 0);
  1018. }
  1019. goto Cleanup;
  1020. }
  1021. Cleanup:
  1022. SysFreeString(bstrParam);
  1023. SysFreeString(bstrClassPath);
  1024. SysFreeString(bstrMethodName);
  1025. if(hEvent != NULL)
  1026. {
  1027. CloseHandle(hEvent);
  1028. }
  1029. if (pInInst)
  1030. {
  1031. pInInst->Release();
  1032. }
  1033. if (pOutInst)
  1034. {
  1035. pOutInst->Release();
  1036. }
  1037. if (pInClass)
  1038. {
  1039. pInClass->Release();
  1040. }
  1041. if (pClass)
  1042. {
  1043. pClass->Release();
  1044. }
  1045. if (pNamespace)
  1046. {
  1047. pNamespace->Release();
  1048. }
  1049. if (pLocator)
  1050. {
  1051. pLocator->Release();
  1052. }
  1053. if (pSubstitute)
  1054. {
  1055. pSubstitute->Release();
  1056. }
  1057. if (pSubstituteSink)
  1058. {
  1059. pSubstituteSink->Release();
  1060. }
  1061. if (pSpawner)
  1062. {
  1063. pSpawner->Release();
  1064. }
  1065. if (pCSS)
  1066. {
  1067. pCSS->Release();
  1068. }
  1069. return hr;
  1070. }
  1071. //-------------------------------------------------------
  1072. HRESULT CRSOPWizard::CreateSafeArray( DWORD dwCount, LPTSTR* aszStringList, SAFEARRAY** psaList )
  1073. {
  1074. SAFEARRAYBOUND rgsabound[1];
  1075. rgsabound[0].lLbound = 0;
  1076. rgsabound[0].cElements = dwCount;
  1077. *psaList = SafeArrayCreate (VT_BSTR, 1, rgsabound);
  1078. if ( *psaList == NULL )
  1079. {
  1080. return E_OUTOFMEMORY;
  1081. }
  1082. long lCount = (long)dwCount;
  1083. for ( long l = 0; l < lCount; l++ )
  1084. {
  1085. BSTR bstr = SysAllocString( aszStringList[l] );
  1086. if ( bstr != NULL )
  1087. {
  1088. HRESULT hr = SafeArrayPutElement( *psaList, &l, bstr );
  1089. if (FAILED(hr))
  1090. {
  1091. DebugMsg((DM_WARNING, TEXT("CRSOPWizard::CreateSafeArray: SafeArrayPutElement failed with 0x%x."), hr));
  1092. }
  1093. }
  1094. }
  1095. return S_OK;
  1096. }
  1097. //-------------------------------------------------------
  1098. VOID CRSOPWizard::InitializeResultsList (HWND hLV)
  1099. {
  1100. LV_COLUMN lvcol;
  1101. RECT rect;
  1102. TCHAR szTitle[50];
  1103. SendMessage(hLV, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
  1104. LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
  1105. //
  1106. // Add the columns to the listview
  1107. //
  1108. GetClientRect(hLV, &rect);
  1109. ZeroMemory(&lvcol, sizeof(lvcol));
  1110. LoadString(g_hInstance, IDS_RSOP_DETAILS, szTitle, ARRAYSIZE(szTitle));
  1111. lvcol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
  1112. lvcol.pszText = szTitle;
  1113. lvcol.fmt = LVCFMT_LEFT;
  1114. lvcol.cx = (int)(rect.right * .40);
  1115. ListView_InsertColumn(hLV, 0, &lvcol);
  1116. LoadString(g_hInstance, IDS_RSOP_SETTINGS, szTitle, ARRAYSIZE(szTitle));
  1117. lvcol.cx = ((rect.right - lvcol.cx) - GetSystemMetrics(SM_CYHSCROLL));
  1118. lvcol.pszText = szTitle;
  1119. ListView_InsertColumn(hLV, 1, &lvcol);
  1120. }
  1121. //-------------------------------------------------------
  1122. void CRSOPWizard::FillResultsList (HWND hLV, LPRSOP_QUERY pQuery, LPRSOP_QUERY_RESULTS pQueryResults)
  1123. {
  1124. TCHAR szTitle[200];
  1125. TCHAR szAccessDenied[75];
  1126. LPTSTR lpEnd;
  1127. LVITEM item;
  1128. INT iIndex = 0;
  1129. ULONG ulSize;
  1130. HRESULT hr;
  1131. if ( pQuery == NULL )
  1132. {
  1133. return;
  1134. }
  1135. ListView_DeleteAllItems (hLV);
  1136. // Mode
  1137. ZeroMemory (&item, sizeof(item));
  1138. LoadString(g_hInstance, IDS_RSOP_FINISH_P0, szTitle, ARRAYSIZE(szTitle));
  1139. item.mask = LVIF_TEXT;
  1140. item.iItem = iIndex;
  1141. item.pszText = szTitle;
  1142. iIndex = ListView_InsertItem (hLV, &item);
  1143. if (iIndex != -1)
  1144. {
  1145. if ( pQuery->QueryType == RSOP_LOGGING_MODE )
  1146. {
  1147. LoadString(g_hInstance, IDS_DIAGNOSTIC, szTitle, ARRAYSIZE(szTitle));
  1148. }
  1149. else
  1150. {
  1151. LoadString(g_hInstance, IDS_PLANNING, szTitle, ARRAYSIZE(szTitle));
  1152. }
  1153. item.mask = LVIF_TEXT;
  1154. item.pszText = szTitle;
  1155. item.iItem = iIndex;
  1156. item.iSubItem = 1;
  1157. ListView_SetItem(hLV, &item);
  1158. }
  1159. if ( pQuery->QueryType == RSOP_LOGGING_MODE )
  1160. {
  1161. // User Name
  1162. ZeroMemory (&item, sizeof(item));
  1163. iIndex++;
  1164. LoadString(g_hInstance, IDS_RSOP_FINISH_P1, szTitle, ARRAYSIZE(szTitle));
  1165. item.mask = LVIF_TEXT;
  1166. item.iItem = iIndex;
  1167. item.pszText = szTitle;
  1168. iIndex = ListView_InsertItem (hLV, &item);
  1169. if (iIndex != -1)
  1170. {
  1171. item.mask = LVIF_TEXT;
  1172. if ( pQuery->szUserName != NULL )
  1173. {
  1174. lstrcpyn (szTitle, pQuery->szUserName, ARRAYSIZE(szTitle));
  1175. }
  1176. else
  1177. {
  1178. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1179. }
  1180. if ( (pQueryResults != NULL) && pQueryResults->bUserDeniedAccess )
  1181. {
  1182. LoadString(g_hInstance, IDS_ACCESSDENIED2, szAccessDenied, ARRAYSIZE(szAccessDenied));
  1183. if ((UINT)(ARRAYSIZE(szTitle) - lstrlen(szTitle)) > (UINT) lstrlen(szAccessDenied))
  1184. {
  1185. hr = StringCchCat (szTitle, ARRAYSIZE(szTitle), szAccessDenied);
  1186. ASSERT(SUCCEEDED(hr));
  1187. }
  1188. }
  1189. item.pszText = szTitle;
  1190. item.iItem = iIndex;
  1191. item.iSubItem = 1;
  1192. ListView_SetItem(hLV, &item);
  1193. }
  1194. // Do not display user data
  1195. ZeroMemory (&item, sizeof(item));
  1196. iIndex++;
  1197. LoadString(g_hInstance, IDS_RSOP_FINISH_P15, szTitle, ARRAYSIZE(szTitle));
  1198. item.mask = LVIF_TEXT;
  1199. item.iItem = iIndex;
  1200. item.pszText = szTitle;
  1201. iIndex = ListView_InsertItem (hLV, &item);
  1202. if (iIndex != -1)
  1203. {
  1204. if ( ((pQuery->dwFlags & RSOP_NO_USER_POLICY) == RSOP_NO_USER_POLICY)
  1205. || ((pQueryResults != NULL) && pQueryResults->bNoUserPolicyData) )
  1206. {
  1207. LoadString(g_hInstance, IDS_NO, szTitle, ARRAYSIZE(szTitle));
  1208. }
  1209. else
  1210. {
  1211. LoadString(g_hInstance, IDS_YES, szTitle, ARRAYSIZE(szTitle));
  1212. }
  1213. item.mask = LVIF_TEXT;
  1214. item.pszText = szTitle;
  1215. item.iItem = iIndex;
  1216. item.iSubItem = 1;
  1217. ListView_SetItem(hLV, &item);
  1218. }
  1219. // Computer Name
  1220. ZeroMemory (&item, sizeof(item));
  1221. iIndex++;
  1222. LoadString(g_hInstance, IDS_RSOP_FINISH_P2, szTitle, ARRAYSIZE(szTitle));
  1223. item.mask = LVIF_TEXT;
  1224. item.iItem = iIndex;
  1225. item.pszText = szTitle;
  1226. iIndex = ListView_InsertItem (hLV, &item);
  1227. if (iIndex != -1)
  1228. {
  1229. szTitle[0] = TEXT('\0');
  1230. if (!lstrcmpi( pQuery->szComputerName, TEXT(".")))
  1231. {
  1232. ulSize = ARRAYSIZE(szTitle);
  1233. if (!GetComputerObjectName (NameSamCompatible, szTitle, &ulSize))
  1234. {
  1235. ulSize = ARRAYSIZE(szTitle);
  1236. GetComputerNameEx (ComputerNameNetBIOS, szTitle, &ulSize);
  1237. }
  1238. }
  1239. else
  1240. {
  1241. lstrcpyn (szTitle, pQuery->szComputerName, ARRAYSIZE(szTitle));
  1242. }
  1243. // Remove the trailing $
  1244. lpEnd = szTitle + lstrlen(szTitle) - 1;
  1245. if (*lpEnd == TEXT('$'))
  1246. {
  1247. *lpEnd = TEXT('\0');
  1248. }
  1249. if ( (pQueryResults != NULL) && pQueryResults->bComputerDeniedAccess )
  1250. {
  1251. LoadString(g_hInstance, IDS_ACCESSDENIED2, szAccessDenied, ARRAYSIZE(szAccessDenied));
  1252. if ((UINT)(ARRAYSIZE(szTitle) - lstrlen(szTitle)) > (UINT)lstrlen(szAccessDenied))
  1253. {
  1254. hr = StringCchCat (szTitle, ARRAYSIZE(szTitle), szAccessDenied);
  1255. ASSERT(SUCCEEDED(hr));
  1256. }
  1257. }
  1258. item.mask = LVIF_TEXT;
  1259. item.pszText = szTitle;
  1260. item.iItem = iIndex;
  1261. item.iSubItem = 1;
  1262. ListView_SetItem(hLV, &item);
  1263. }
  1264. // Do not display computer data
  1265. ZeroMemory (&item, sizeof(item));
  1266. iIndex++;
  1267. LoadString(g_hInstance, IDS_RSOP_FINISH_P14, szTitle, ARRAYSIZE(szTitle));
  1268. item.mask = LVIF_TEXT;
  1269. item.iItem = iIndex;
  1270. item.pszText = szTitle;
  1271. iIndex = ListView_InsertItem (hLV, &item);
  1272. if (iIndex != -1)
  1273. {
  1274. if ( ((pQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY)
  1275. || ((pQueryResults != NULL) && pQueryResults->bNoComputerPolicyData) )
  1276. {
  1277. LoadString(g_hInstance, IDS_NO, szTitle, ARRAYSIZE(szTitle));
  1278. }
  1279. else
  1280. {
  1281. LoadString(g_hInstance, IDS_YES, szTitle, ARRAYSIZE(szTitle));
  1282. }
  1283. item.mask = LVIF_TEXT;
  1284. item.pszText = szTitle;
  1285. item.iItem = iIndex;
  1286. item.iSubItem = 1;
  1287. ListView_SetItem(hLV, &item);
  1288. }
  1289. }
  1290. else if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  1291. {
  1292. // User Name
  1293. ZeroMemory (&item, sizeof(item));
  1294. iIndex++;
  1295. if ( (pQuery->pUser->szName == NULL) && (pQuery->pUser->szSOM != NULL) )
  1296. {
  1297. LoadString(g_hInstance, IDS_RSOP_FINISH_P9, szTitle, ARRAYSIZE(szTitle));
  1298. item.mask = LVIF_TEXT;
  1299. item.iItem = iIndex;
  1300. item.pszText = szTitle;
  1301. iIndex = ListView_InsertItem (hLV, &item);
  1302. if (iIndex != -1)
  1303. {
  1304. item.mask = LVIF_TEXT;
  1305. lstrcpyn (szTitle, pQuery->pUser->szSOM, ARRAYSIZE(szTitle));
  1306. if ( (pQueryResults != NULL) && pQueryResults->bUserDeniedAccess )
  1307. {
  1308. LoadString(g_hInstance, IDS_ACCESSDENIED2, szAccessDenied, ARRAYSIZE(szAccessDenied));
  1309. if ((UINT)(ARRAYSIZE(szTitle) - lstrlen(szTitle)) > (UINT)lstrlen(szAccessDenied))
  1310. {
  1311. hr = StringCchCat (szTitle, ARRAYSIZE(szTitle), szAccessDenied);
  1312. ASSERT(SUCCEEDED(hr));
  1313. }
  1314. }
  1315. item.pszText = szTitle;
  1316. item.iItem = iIndex;
  1317. item.iSubItem = 1;
  1318. ListView_SetItem(hLV, &item);
  1319. }
  1320. }
  1321. else
  1322. {
  1323. LoadString(g_hInstance, IDS_RSOP_FINISH_P1, szTitle, ARRAYSIZE(szTitle));
  1324. item.mask = LVIF_TEXT;
  1325. item.iItem = iIndex;
  1326. item.pszText = szTitle;
  1327. iIndex = ListView_InsertItem (hLV, &item);
  1328. if (iIndex != -1)
  1329. {
  1330. item.mask = LVIF_TEXT;
  1331. if ( pQuery->pUser->szName != NULL )
  1332. {
  1333. lstrcpyn (szTitle, pQuery->pUser->szName, ARRAYSIZE(szTitle));
  1334. }
  1335. else
  1336. {
  1337. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1338. }
  1339. if ( (pQueryResults != NULL) && pQueryResults->bUserDeniedAccess)
  1340. {
  1341. LoadString(g_hInstance, IDS_ACCESSDENIED2, szAccessDenied, ARRAYSIZE(szAccessDenied));
  1342. if ((UINT)(ARRAYSIZE(szTitle) - lstrlen(szTitle)) > (UINT)lstrlen(szAccessDenied))
  1343. {
  1344. hr = StringCchCat (szTitle, ARRAYSIZE(szTitle), szAccessDenied);
  1345. ASSERT(SUCCEEDED(hr));
  1346. }
  1347. }
  1348. item.pszText = szTitle;
  1349. item.iItem = iIndex;
  1350. item.iSubItem = 1;
  1351. ListView_SetItem(hLV, &item);
  1352. }
  1353. }
  1354. // Computer Name
  1355. ZeroMemory (&item, sizeof(item));
  1356. iIndex++;
  1357. if ( (pQuery->pComputer->szName == NULL) && (pQuery->pComputer->szSOM != NULL) )
  1358. {
  1359. LoadString(g_hInstance, IDS_RSOP_FINISH_P10, szTitle, ARRAYSIZE(szTitle));
  1360. item.mask = LVIF_TEXT;
  1361. item.iItem = iIndex;
  1362. item.pszText = szTitle;
  1363. iIndex = ListView_InsertItem (hLV, &item);
  1364. if (iIndex != -1)
  1365. {
  1366. item.mask = LVIF_TEXT;
  1367. lstrcpyn (szTitle, pQuery->pComputer->szSOM, ARRAYSIZE(szTitle));
  1368. if ( (pQueryResults != NULL) && pQueryResults->bComputerDeniedAccess )
  1369. {
  1370. LoadString(g_hInstance, IDS_ACCESSDENIED2, szAccessDenied, ARRAYSIZE(szAccessDenied));
  1371. if ((UINT)(ARRAYSIZE(szTitle) - lstrlen(szTitle)) > (UINT)lstrlen(szAccessDenied))
  1372. {
  1373. hr = StringCchCat (szTitle, ARRAYSIZE(szTitle), szAccessDenied);
  1374. ASSERT(SUCCEEDED(hr));
  1375. }
  1376. }
  1377. item.pszText = szTitle;
  1378. item.iItem = iIndex;
  1379. item.iSubItem = 1;
  1380. ListView_SetItem(hLV, &item);
  1381. }
  1382. }
  1383. else
  1384. {
  1385. LoadString(g_hInstance, IDS_RSOP_FINISH_P2, szTitle, ARRAYSIZE(szTitle));
  1386. item.mask = LVIF_TEXT;
  1387. item.iItem = iIndex;
  1388. item.pszText = szTitle;
  1389. iIndex = ListView_InsertItem (hLV, &item);
  1390. if (iIndex != -1)
  1391. {
  1392. item.mask = LVIF_TEXT;
  1393. if ( pQuery->pComputer->szName != NULL )
  1394. {
  1395. lstrcpyn (szTitle, pQuery->pComputer->szName, ARRAYSIZE(szTitle));
  1396. lpEnd = szTitle + lstrlen(szTitle) - 1;
  1397. if (*lpEnd == TEXT('$'))
  1398. {
  1399. *lpEnd = TEXT('\0');
  1400. }
  1401. }
  1402. else
  1403. {
  1404. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1405. }
  1406. if ( (pQueryResults != NULL) && pQueryResults->bComputerDeniedAccess )
  1407. {
  1408. LoadString(g_hInstance, IDS_ACCESSDENIED2, szAccessDenied, ARRAYSIZE(szAccessDenied));
  1409. if ((UINT)(ARRAYSIZE(szTitle) - lstrlen(szTitle)) > (UINT)lstrlen(szAccessDenied))
  1410. {
  1411. hr = StringCchCat (szTitle, ARRAYSIZE(szTitle), szAccessDenied);
  1412. ASSERT(SUCCEEDED(hr));
  1413. }
  1414. }
  1415. item.iItem = iIndex;
  1416. item.iSubItem = 1;
  1417. item.pszText = szTitle;
  1418. ListView_SetItem(hLV, &item);
  1419. }
  1420. }
  1421. // Show all GPOs
  1422. ZeroMemory (&item, sizeof(item));
  1423. iIndex++;
  1424. LoadString(g_hInstance, IDS_RSOP_FINISH_P13, szTitle, ARRAYSIZE(szTitle));
  1425. item.mask = LVIF_TEXT;
  1426. item.iItem = iIndex;
  1427. item.pszText = szTitle;
  1428. iIndex = ListView_InsertItem (hLV, &item);
  1429. if (iIndex != -1)
  1430. {
  1431. if ( pQuery->bSlowNetworkConnection )
  1432. {
  1433. LoadString(g_hInstance, IDS_YES, szTitle, ARRAYSIZE(szTitle));
  1434. }
  1435. else
  1436. {
  1437. LoadString(g_hInstance, IDS_NO, szTitle, ARRAYSIZE(szTitle));
  1438. }
  1439. item.mask = LVIF_TEXT;
  1440. item.pszText = szTitle;
  1441. item.iItem = iIndex;
  1442. item.iSubItem = 1;
  1443. ListView_SetItem(hLV, &item);
  1444. }
  1445. // Indicate the loopback mode
  1446. ZeroMemory (&item, sizeof(item));
  1447. iIndex++;
  1448. LoadString(g_hInstance, IDS_RSOP_FINISH_P16, szTitle, ARRAYSIZE(szTitle));
  1449. item.mask = LVIF_TEXT;
  1450. item.iItem = iIndex;
  1451. item.pszText = szTitle;
  1452. iIndex = ListView_InsertItem (hLV, &item);
  1453. if (iIndex != -1)
  1454. {
  1455. switch ( pQuery->LoopbackMode)
  1456. {
  1457. case RSOP_LOOPBACK_NONE:
  1458. LoadString(g_hInstance, IDS_NONE, szTitle, ARRAYSIZE(szTitle));
  1459. break;
  1460. case RSOP_LOOPBACK_REPLACE:
  1461. LoadString(g_hInstance, IDS_LOOPBACK_REPLACE, szTitle, ARRAYSIZE(szTitle));
  1462. break;
  1463. case RSOP_LOOPBACK_MERGE:
  1464. LoadString(g_hInstance, IDS_LOOPBACK_MERGE, szTitle, ARRAYSIZE(szTitle));
  1465. break;
  1466. }
  1467. item.mask = LVIF_TEXT;
  1468. item.pszText = szTitle;
  1469. item.iItem = iIndex;
  1470. item.iSubItem = 1;
  1471. ListView_SetItem(hLV, &item);
  1472. }
  1473. // Site Name
  1474. ZeroMemory (&item, sizeof(item));
  1475. iIndex++;
  1476. LoadString(g_hInstance, IDS_RSOP_FINISH_P3, szTitle, ARRAYSIZE(szTitle));
  1477. item.mask = LVIF_TEXT;
  1478. item.iItem = iIndex;
  1479. item.pszText = szTitle;
  1480. iIndex = ListView_InsertItem (hLV, &item);
  1481. if (iIndex != -1)
  1482. {
  1483. item.mask = LVIF_TEXT;
  1484. if ( pQuery->szSite != NULL )
  1485. {
  1486. item.pszText = pQuery->szSite;
  1487. }
  1488. else
  1489. {
  1490. LoadString(g_hInstance, IDS_NONE, szTitle, ARRAYSIZE(szTitle));
  1491. item.pszText = szTitle;
  1492. }
  1493. item.iItem = iIndex;
  1494. item.iSubItem = 1;
  1495. ListView_SetItem(hLV, &item);
  1496. }
  1497. /*
  1498. // DC Name
  1499. ZeroMemory (&item, sizeof(item));
  1500. iIndex++;
  1501. LoadString(g_hInstance, IDS_RSOP_FINISH_P4, szTitle, ARRAYSIZE(szTitle));
  1502. item.mask = LVIF_TEXT;
  1503. item.iItem = iIndex;
  1504. item.pszText = szTitle;
  1505. iIndex = ListView_InsertItem (hLV, &item);
  1506. if (iIndex != -1)
  1507. {
  1508. item.mask = LVIF_TEXT;
  1509. item.pszText = m_szDC;
  1510. item.iItem = iIndex;
  1511. item.iSubItem = 1;
  1512. ListView_SetItem(hLV, &item);
  1513. }
  1514. */
  1515. // Alternate User Location
  1516. if ( pQuery->pUser->szName != NULL )
  1517. {
  1518. ZeroMemory (&item, sizeof(item));
  1519. iIndex++;
  1520. LoadString(g_hInstance, IDS_RSOP_FINISH_P5, szTitle, ARRAYSIZE(szTitle));
  1521. item.mask = LVIF_TEXT;
  1522. item.iItem = iIndex;
  1523. item.pszText = szTitle;
  1524. iIndex = ListView_InsertItem (hLV, &item);
  1525. if (iIndex != -1)
  1526. {
  1527. item.mask = LVIF_TEXT;
  1528. if ( pQuery->pUser->szSOM != NULL )
  1529. {
  1530. item.pszText = pQuery->pUser->szSOM;
  1531. }
  1532. else
  1533. {
  1534. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1535. item.pszText = szTitle;
  1536. }
  1537. item.iItem = iIndex;
  1538. item.iSubItem = 1;
  1539. ListView_SetItem(hLV, &item);
  1540. }
  1541. }
  1542. // Alternate Computer Location
  1543. if ( pQuery->pComputer->szName != NULL )
  1544. {
  1545. ZeroMemory (&item, sizeof(item));
  1546. iIndex++;
  1547. LoadString(g_hInstance, IDS_RSOP_FINISH_P6, szTitle, ARRAYSIZE(szTitle));
  1548. item.mask = LVIF_TEXT;
  1549. item.iItem = iIndex;
  1550. item.pszText = szTitle;
  1551. iIndex = ListView_InsertItem (hLV, &item);
  1552. if (iIndex != -1)
  1553. {
  1554. item.mask = LVIF_TEXT;
  1555. if ( pQuery->pComputer->szSOM != NULL )
  1556. {
  1557. item.pszText = pQuery->pComputer->szSOM;
  1558. }
  1559. else
  1560. {
  1561. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1562. item.pszText = szTitle;
  1563. }
  1564. item.iItem = iIndex;
  1565. item.iSubItem = 1;
  1566. ListView_SetItem(hLV, &item);
  1567. }
  1568. }
  1569. // Alternate User security groups
  1570. if ( (pQuery->pUser->szName != NULL)
  1571. || (pQuery->pUser->szSOM != NULL)
  1572. || (RSOP_LOOPBACK_NONE != pQuery->LoopbackMode) )
  1573. {
  1574. if ( pQuery->pUser->dwSecurityGroupCount != 0 )
  1575. {
  1576. DWORD dwIndex;
  1577. for ( dwIndex = 0; dwIndex < pQuery->pUser->dwSecurityGroupCount; dwIndex++ )
  1578. {
  1579. ZeroMemory (&item, sizeof(item));
  1580. iIndex++;
  1581. item.mask = LVIF_TEXT;
  1582. item.iItem = iIndex;
  1583. if ( dwIndex == 0 )
  1584. {
  1585. LoadString(g_hInstance, IDS_RSOP_FINISH_P7, szTitle, ARRAYSIZE(szTitle));
  1586. item.pszText = szTitle;
  1587. }
  1588. else
  1589. {
  1590. item.pszText = TEXT("");
  1591. }
  1592. iIndex = ListView_InsertItem (hLV, &item);
  1593. if (iIndex != -1)
  1594. {
  1595. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1596. item.mask = LVIF_TEXT;
  1597. item.pszText = pQuery->pUser->aszSecurityGroups[dwIndex];
  1598. item.iItem = iIndex;
  1599. item.iSubItem = 1;
  1600. ListView_SetItem(hLV, &item);
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. ZeroMemory (&item, sizeof(item));
  1607. iIndex++;
  1608. LoadString(g_hInstance, IDS_RSOP_FINISH_P7, szTitle, ARRAYSIZE(szTitle));
  1609. item.mask = LVIF_TEXT;
  1610. item.iItem = iIndex;
  1611. item.pszText = szTitle;
  1612. iIndex = ListView_InsertItem (hLV, &item);
  1613. if (iIndex != -1)
  1614. {
  1615. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1616. item.mask = LVIF_TEXT;
  1617. item.pszText = szTitle;
  1618. item.iItem = iIndex;
  1619. item.iSubItem = 1;
  1620. ListView_SetItem(hLV, &item);
  1621. }
  1622. }
  1623. }
  1624. // Alternate Computer security groups
  1625. if ( (pQuery->pComputer->szName != NULL) || (pQuery->pComputer->szSOM != NULL) )
  1626. {
  1627. if ( pQuery->pComputer->dwSecurityGroupCount != 0 )
  1628. {
  1629. DWORD dwIndex;
  1630. for ( dwIndex = 0; dwIndex < pQuery->pComputer->dwSecurityGroupCount; dwIndex++ )
  1631. {
  1632. ZeroMemory (&item, sizeof(item));
  1633. iIndex++;
  1634. item.mask = LVIF_TEXT;
  1635. item.iItem = iIndex;
  1636. if ( dwIndex == 0 )
  1637. {
  1638. LoadString(g_hInstance, IDS_RSOP_FINISH_P8, szTitle, ARRAYSIZE(szTitle));
  1639. item.pszText = szTitle;
  1640. }
  1641. else
  1642. {
  1643. item.pszText = TEXT("");
  1644. }
  1645. iIndex = ListView_InsertItem (hLV, &item);
  1646. if (iIndex != -1)
  1647. {
  1648. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1649. item.mask = LVIF_TEXT;
  1650. LPTSTR szText = pQuery->pComputer->aszSecurityGroups[dwIndex];
  1651. BOOL bDollarRemoved = FALSE;
  1652. if ( szText[wcslen(szText)-1] == L'$' )
  1653. {
  1654. bDollarRemoved = TRUE;
  1655. szText[wcslen(szText)-1] = 0;
  1656. }
  1657. item.pszText = szText;
  1658. item.iItem = iIndex;
  1659. item.iSubItem = 1;
  1660. ListView_SetItem(hLV, &item);
  1661. if (bDollarRemoved) {
  1662. szText[wcslen(szText)] = L'$';
  1663. }
  1664. }
  1665. }
  1666. }
  1667. else
  1668. {
  1669. ZeroMemory (&item, sizeof(item));
  1670. iIndex++;
  1671. LoadString(g_hInstance, IDS_RSOP_FINISH_P8, szTitle, ARRAYSIZE(szTitle));
  1672. item.mask = LVIF_TEXT;
  1673. item.iItem = iIndex;
  1674. item.pszText = szTitle;
  1675. iIndex = ListView_InsertItem (hLV, &item);
  1676. if (iIndex != -1)
  1677. {
  1678. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1679. item.mask = LVIF_TEXT;
  1680. item.pszText = szTitle;
  1681. item.iItem = iIndex;
  1682. item.iSubItem = 1;
  1683. ListView_SetItem(hLV, &item);
  1684. }
  1685. }
  1686. }
  1687. // User WQL filters
  1688. if ( (pQuery->pUser->szName != NULL)
  1689. || (pQuery->pUser->szSOM != NULL)
  1690. || (RSOP_LOOPBACK_NONE != pQuery->LoopbackMode) )
  1691. {
  1692. if ( pQuery->pUser->dwWQLFilterCount != 0 )
  1693. {
  1694. DWORD dwIndex = 0;
  1695. for ( dwIndex = 0; dwIndex < pQuery->pUser->dwWQLFilterCount; dwIndex++ )
  1696. {
  1697. ZeroMemory (&item, sizeof(item));
  1698. iIndex++;
  1699. item.mask = LVIF_TEXT;
  1700. item.iItem = iIndex;
  1701. if ( dwIndex == 0 )
  1702. {
  1703. LoadString(g_hInstance, IDS_RSOP_FINISH_P11, szTitle, ARRAYSIZE(szTitle));
  1704. item.pszText = szTitle;
  1705. }
  1706. else
  1707. {
  1708. item.pszText = TEXT("");
  1709. }
  1710. iIndex = ListView_InsertItem (hLV, &item);
  1711. if (iIndex != -1)
  1712. {
  1713. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1714. item.mask = LVIF_TEXT;
  1715. item.pszText = pQuery->pUser->aszWQLFilterNames[dwIndex];
  1716. item.iItem = iIndex;
  1717. item.iSubItem = 1;
  1718. ListView_SetItem(hLV, &item);
  1719. }
  1720. }
  1721. }
  1722. else
  1723. {
  1724. ZeroMemory (&item, sizeof(item));
  1725. iIndex++;
  1726. LoadString(g_hInstance, IDS_RSOP_FINISH_P11, szTitle, ARRAYSIZE(szTitle));
  1727. item.mask = LVIF_TEXT;
  1728. item.iItem = iIndex;
  1729. item.pszText = szTitle;
  1730. iIndex = ListView_InsertItem (hLV, &item);
  1731. if (iIndex != -1)
  1732. {
  1733. if ( pQuery->pUser->bAssumeWQLFiltersTrue )
  1734. {
  1735. LoadString(g_hInstance, IDS_SKIPWQLFILTER, szTitle, ARRAYSIZE(szTitle));
  1736. }
  1737. else
  1738. {
  1739. LoadString(g_hInstance, IDS_NONESELECTED, szTitle, ARRAYSIZE(szTitle));
  1740. }
  1741. item.mask = LVIF_TEXT;
  1742. item.pszText = szTitle;
  1743. item.iItem = iIndex;
  1744. item.iSubItem = 1;
  1745. ListView_SetItem(hLV, &item);
  1746. }
  1747. }
  1748. }
  1749. // Computer WQL filters
  1750. if ( (pQuery->pComputer->szName != NULL)
  1751. || (pQuery->pComputer->szSOM != NULL) )
  1752. {
  1753. if ( pQuery->pComputer->dwWQLFilterCount != 0 )
  1754. {
  1755. DWORD dwIndex = 0;
  1756. for ( dwIndex = 0; dwIndex < pQuery->pComputer->dwWQLFilterCount; dwIndex++ )
  1757. {
  1758. ZeroMemory (&item, sizeof(item));
  1759. iIndex++;
  1760. item.mask = LVIF_TEXT;
  1761. item.iItem = iIndex;
  1762. if ( dwIndex == 0 )
  1763. {
  1764. LoadString(g_hInstance, IDS_RSOP_FINISH_P12, szTitle, ARRAYSIZE(szTitle));
  1765. item.pszText = szTitle;
  1766. }
  1767. else
  1768. {
  1769. item.pszText = TEXT("");
  1770. }
  1771. iIndex = ListView_InsertItem (hLV, &item);
  1772. if (iIndex != -1)
  1773. {
  1774. LoadString(g_hInstance, IDS_NOTSPECIFIED, szTitle, ARRAYSIZE(szTitle));
  1775. item.mask = LVIF_TEXT;
  1776. item.pszText = pQuery->pComputer->aszWQLFilterNames[dwIndex];
  1777. item.iItem = iIndex;
  1778. item.iSubItem = 1;
  1779. ListView_SetItem(hLV, &item);
  1780. }
  1781. }
  1782. }
  1783. else
  1784. {
  1785. ZeroMemory (&item, sizeof(item));
  1786. iIndex++;
  1787. LoadString(g_hInstance, IDS_RSOP_FINISH_P12, szTitle, ARRAYSIZE(szTitle));
  1788. item.mask = LVIF_TEXT;
  1789. item.iItem = iIndex;
  1790. item.pszText = szTitle;
  1791. iIndex = ListView_InsertItem (hLV, &item);
  1792. if (iIndex != -1)
  1793. {
  1794. if ( pQuery->pComputer->bAssumeWQLFiltersTrue )
  1795. {
  1796. LoadString(g_hInstance, IDS_SKIPWQLFILTER, szTitle, ARRAYSIZE(szTitle));
  1797. }
  1798. else
  1799. {
  1800. LoadString(g_hInstance, IDS_NONESELECTED, szTitle, ARRAYSIZE(szTitle));
  1801. }
  1802. item.mask = LVIF_TEXT;
  1803. item.pszText = szTitle;
  1804. item.iItem = iIndex;
  1805. item.iSubItem = 1;
  1806. ListView_SetItem(hLV, &item);
  1807. }
  1808. }
  1809. }
  1810. }
  1811. }
  1812. ///////////////////////////////////////////////////////////////////////////////
  1813. // //
  1814. // IWbemObjectSink implementation //
  1815. // //
  1816. ///////////////////////////////////////////////////////////////////////////////
  1817. CCreateSessionSink::CCreateSessionSink(HWND hProgress, HANDLE hEvent, BOOL bLimitProgress)
  1818. {
  1819. m_cRef = 1;
  1820. InterlockedIncrement(&g_cRefThisDll);
  1821. m_hProgress = hProgress;
  1822. m_hEvent = hEvent;
  1823. m_bSendEvent = FALSE;
  1824. m_hrSuccess = S_OK;
  1825. m_pNameSpace = NULL;
  1826. m_ulErrorInfo = 0;
  1827. m_bLimitProgress = bLimitProgress;
  1828. SendMessage (hProgress, PBM_SETPOS, 0, 0);
  1829. }
  1830. CCreateSessionSink::~CCreateSessionSink()
  1831. {
  1832. if (m_pNameSpace)
  1833. {
  1834. SysFreeString (m_pNameSpace);
  1835. }
  1836. InterlockedDecrement(&g_cRefThisDll);
  1837. }
  1838. STDMETHODIMP_(ULONG)
  1839. CCreateSessionSink::AddRef()
  1840. {
  1841. return ++m_cRef;
  1842. }
  1843. STDMETHODIMP_(ULONG)
  1844. CCreateSessionSink::Release()
  1845. {
  1846. if (--m_cRef == 0)
  1847. {
  1848. delete this;
  1849. return 0;
  1850. }
  1851. return m_cRef;
  1852. }
  1853. STDMETHODIMP
  1854. CCreateSessionSink::QueryInterface(REFIID riid, LPVOID FAR* ppv)
  1855. {
  1856. if (IsEqualIID(riid, IID_IUnknown))
  1857. {
  1858. *ppv = (IUnknown *)this;
  1859. m_cRef++;
  1860. return S_OK;
  1861. }
  1862. else if (IsEqualIID(riid, IID_IWbemObjectSink))
  1863. {
  1864. *ppv = (IWbemObjectSink *)this;
  1865. m_cRef++;
  1866. return S_OK;
  1867. }
  1868. else
  1869. {
  1870. *ppv = NULL;
  1871. return E_NOINTERFACE;
  1872. }
  1873. }
  1874. STDMETHODIMP CCreateSessionSink::SendQuitEvent (BOOL bSendEvent)
  1875. {
  1876. m_bSendEvent = bSendEvent;
  1877. return S_OK;
  1878. }
  1879. STDMETHODIMP CCreateSessionSink::GetResult (HRESULT *hSuccess)
  1880. {
  1881. *hSuccess = m_hrSuccess;
  1882. return S_OK;
  1883. }
  1884. STDMETHODIMP CCreateSessionSink::GetNamespace (BSTR *pNamespace)
  1885. {
  1886. *pNamespace = m_pNameSpace;
  1887. return S_OK;
  1888. }
  1889. STDMETHODIMP CCreateSessionSink::GetErrorInfo (ULONG *pulErrorInfo)
  1890. {
  1891. *pulErrorInfo = m_ulErrorInfo;
  1892. return S_OK;
  1893. }
  1894. STDMETHODIMP CCreateSessionSink::Indicate(long lObjCount, IWbemClassObject **pArray)
  1895. {
  1896. LONG lIndex;
  1897. HRESULT hr;
  1898. IWbemClassObject *pObject;
  1899. for (lIndex = 0; lIndex < lObjCount; lIndex++)
  1900. {
  1901. pObject = pArray[lIndex];
  1902. hr = GetParameter(pObject, TEXT("hResult"), m_hrSuccess);
  1903. if (SUCCEEDED(hr))
  1904. {
  1905. if (SUCCEEDED(m_hrSuccess))
  1906. {
  1907. GetParameterBSTR(pObject, TEXT("nameSpace"), m_pNameSpace);
  1908. }
  1909. else
  1910. {
  1911. GetParameter(pObject, TEXT("ExtendedInfo"), m_ulErrorInfo);
  1912. }
  1913. }
  1914. DebugMsg((DM_VERBOSE, TEXT("CCreateSessionSink::Indicate: Status: 0x%x"), m_hrSuccess));
  1915. DebugMsg((DM_VERBOSE, TEXT("CCreateSessionSink::Indicate: Namespace: %s"), m_pNameSpace ? m_pNameSpace : TEXT("Null")));
  1916. DebugMsg((DM_VERBOSE, TEXT("CCreateSessionSink::Indicate: ExtendedInfo: %d"), m_ulErrorInfo));
  1917. }
  1918. return WBEM_S_NO_ERROR;
  1919. }
  1920. STDMETHODIMP CCreateSessionSink::SetStatus(LONG lFlags, HRESULT hResult,
  1921. BSTR strParam, IWbemClassObject *pObjParam)
  1922. {
  1923. HRESULT hr;
  1924. if (lFlags == WBEM_STATUS_PROGRESS)
  1925. {
  1926. if (m_hProgress)
  1927. {
  1928. //
  1929. // The hResult arg contains both the denominator
  1930. // and the numerator packed together.
  1931. //
  1932. // Denominator is in the high word
  1933. // Numerator is in the low word
  1934. //
  1935. ULONG uDenominator = MAKELONG(HIWORD(hResult), 0);
  1936. ULONG uNumerator = MAKELONG(LOWORD(hResult), 0);
  1937. if ( m_bLimitProgress )
  1938. {
  1939. // Now to transform progress indicator values to 90% of whole bar
  1940. uDenominator *= 10;
  1941. uNumerator *= 9;
  1942. }
  1943. SendMessage (m_hProgress, PBM_SETRANGE32, 0, (LPARAM) uDenominator);
  1944. SendMessage (m_hProgress, PBM_SETPOS, (WPARAM) uNumerator, 0);
  1945. DebugMsg((DM_VERBOSE, TEXT("CCreateSessionSink::SetStatus: Precentage complete: %d"), uNumerator));
  1946. }
  1947. }
  1948. if (lFlags == WBEM_STATUS_COMPLETE)
  1949. {
  1950. if (m_bSendEvent)
  1951. {
  1952. if (hResult != WBEM_S_NO_ERROR)
  1953. {
  1954. m_hrSuccess = hResult;
  1955. DebugMsg((DM_VERBOSE, TEXT("CCreateSessionSink::SetStatus: Setting error status to: 0x%x"), m_hrSuccess));
  1956. }
  1957. if (SetEvent(m_hEvent) == FALSE)
  1958. {
  1959. hr = HRESULT_FROM_WIN32(GetLastError());
  1960. DebugMsg((DM_WARNING, L"CCreateSessionSink::SetStatus:SetEvent failed with 0x%x", hr));
  1961. }
  1962. }
  1963. }
  1964. return WBEM_S_NO_ERROR;
  1965. }