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.

9524 lines
281 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1997.
  5. //
  6. // File: rsoproot.cpp
  7. //
  8. // Contents: implementation of root RSOP snap-in node
  9. //
  10. // Classes: CRSOPComponentDataCF
  11. // CRSOPComponentData
  12. //
  13. // Functions:
  14. //
  15. // History: 09-13-1999 stevebl Created
  16. //
  17. //---------------------------------------------------------------------------
  18. #include "main.h"
  19. #include "objsel.h" // for the object picker
  20. #include "rsoputil.h"
  21. #include "rsopwizard.h"
  22. #include <ntdsapi.h> // for the Ds*DomainController* API
  23. #include "sddl.h" // for sid to string functions
  24. //---------------------------------------------------------------------------
  25. // Help ids
  26. //
  27. DWORD aGPOListHelpIds[] =
  28. {
  29. IDC_LIST1, IDH_RSOP_GPOLIST,
  30. IDC_CHECK1, IDH_RSOP_GPOSOM,
  31. IDC_CHECK2, IDH_RSOP_APPLIEDGPOS,
  32. IDC_CHECK3, IDH_RSOP_REVISION,
  33. IDC_BUTTON1, IDH_RSOP_SECURITY,
  34. IDC_BUTTON2, IDH_RSOP_EDIT,
  35. 0, 0
  36. };
  37. DWORD aErrorsHelpIds[] =
  38. {
  39. IDC_LIST1, IDH_RSOP_COMPONENTLIST,
  40. IDC_EDIT1, IDH_RSOP_COMPONENTDETAILS,
  41. IDC_BUTTON1, IDH_RSOP_SAVEAS,
  42. 0, 0
  43. };
  44. DWORD aQueryHelpIds[] =
  45. {
  46. IDC_LIST1, IDH_RSOP_QUERYLIST,
  47. 0, 0
  48. };
  49. //---------------------------------------------------------------------------
  50. // Private functions
  51. //
  52. HRESULT RunRSOPQueryInternal( HWND hParent, CRSOPExtendedProcessing* pExtendedProcessing,
  53. LPRSOP_QUERY pQuery, LPRSOP_QUERY_RESULTS* ppResults ); // In RSOPQuery.cpp
  54. WCHAR * NameWithoutDomain(WCHAR * szName); // In RSOPWizard.cpp
  55. //************************************************************************
  56. // ParseDN
  57. //
  58. // Purpose: Parses the given name to get the pieces.
  59. //
  60. // Parameters:
  61. // lpDSObject - Path to the DS Obkect in the format LDAP://<DC-Name>/DN
  62. // pwszDomain - Returns the <DC-Name>. This is allocated in the fn.
  63. // pszDN - The DN part of lpDSObject
  64. // szSOM - THe actual SOM (the node on which we have the rsop rights on
  65. //
  66. // No return value. If memory couldn't be allocated for the pwszDomain it is returned as NULL
  67. //
  68. //************************************************************************
  69. void ParseDN(LPWSTR lpDSObject, LPWSTR *pwszDomain, LPWSTR *pszDN, LPWSTR *szSOM)
  70. {
  71. LPWSTR szContainer = lpDSObject;
  72. LPWSTR lpEnd = NULL;
  73. *pszDN = szContainer;
  74. if (CompareString (LOCALE_USER_DEFAULT, NORM_STOP_ON_NULL, TEXT("LDAP://"),
  75. 7, szContainer, 7) != CSTR_EQUAL)
  76. {
  77. DebugMsg((DM_WARNING, TEXT("GetSOMFromDN: Object does not start with LDAP://")));
  78. return;
  79. }
  80. szContainer += 7;
  81. lpEnd = szContainer;
  82. //
  83. // Move till the end of the domain name
  84. //
  85. *pwszDomain = NULL;
  86. while (*lpEnd && (*lpEnd != TEXT('/'))) {
  87. lpEnd++;
  88. }
  89. if (*lpEnd == TEXT('/')) {
  90. *pwszDomain = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*( (lpEnd - szContainer) + 1));
  91. if (*pwszDomain) {
  92. wcsncpy(*pwszDomain, szContainer, (lpEnd - szContainer));
  93. }
  94. szContainer = lpEnd + 1;
  95. }
  96. *pszDN = szContainer;
  97. while (*szContainer) {
  98. //
  99. // See if the DN name starts with OU=
  100. //
  101. if (CompareString (LOCALE_INVARIANT, NORM_IGNORECASE,
  102. szContainer, 3, TEXT("OU="), 3) == CSTR_EQUAL) {
  103. break;
  104. }
  105. //
  106. // See if the DN name starts with DC=
  107. //
  108. else if (CompareString (LOCALE_INVARIANT, NORM_IGNORECASE,
  109. szContainer, 3, TEXT("DC="), 3) == CSTR_EQUAL) {
  110. break;
  111. }
  112. //
  113. // Move to the next chunk of the DN name
  114. //
  115. while (*szContainer && (*szContainer != TEXT(','))) {
  116. szContainer++;
  117. }
  118. if (*szContainer == TEXT(',')) {
  119. szContainer++;
  120. }
  121. }
  122. *szSOM = szContainer;
  123. return;
  124. }
  125. //************************************************************************
  126. // ParseCommandLine
  127. //
  128. // Purpose: Parse the command line to return the value associated with options
  129. //
  130. // Parameters:
  131. // szCommandLine - Part remaining in the unparsed command lines
  132. // szArgPrefix - Argument prefix
  133. // szArgVal - Argument value. expected in unescaped quotes
  134. // pbFoundArg - Whether the argument was found or not
  135. //
  136. //
  137. // Return
  138. // The remaining cmd line
  139. //
  140. //************************************************************************
  141. LPTSTR ParseCommandLine(LPTSTR szCommandLine, LPTSTR szArgPrefix, LPTSTR *szArgVal, BOOL *pbFoundArg)
  142. {
  143. LPTSTR lpEnd = NULL;
  144. int iTemp;
  145. iTemp = lstrlen (szArgPrefix);
  146. if (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE | NORM_STOP_ON_NULL,
  147. szArgPrefix, iTemp,
  148. szCommandLine, iTemp) == CSTR_EQUAL)
  149. {
  150. *pbFoundArg = TRUE;
  151. //
  152. // Found the switch
  153. //
  154. szCommandLine += iTemp + 1;
  155. lpEnd = szCommandLine;
  156. while (*lpEnd &&
  157. (!( ( (*(lpEnd-1)) != TEXT('\\') ) && ( (*lpEnd) == TEXT('\"') ) ) ) ) /* look for an unesced quote */
  158. lpEnd++;
  159. // lpEnd is at the end or at the last quote
  160. *szArgVal = (LPTSTR) LocalAlloc (LPTR, ((lpEnd - szCommandLine) + 1) * sizeof(TCHAR));
  161. if (*szArgVal)
  162. {
  163. lstrcpyn (*szArgVal, szCommandLine, (int)((lpEnd - szCommandLine) + 1));
  164. DebugMsg((DM_VERBOSE, TEXT("ParseCOmmandLine: Argument %s = <%s>"), szArgPrefix, *szArgVal));
  165. }
  166. if ((*lpEnd) == TEXT('\"'))
  167. szCommandLine = lpEnd+1;
  168. }
  169. else
  170. *pbFoundArg = FALSE;
  171. return szCommandLine;
  172. }
  173. //-------------------------------------------------------
  174. WCHAR* NormalizedComputerName(WCHAR * szComputerName )
  175. {
  176. TCHAR* szNormalizedComputerName;
  177. // Computer names may start with '\\', so we will return
  178. // the computer name without that prefix if it exists
  179. szNormalizedComputerName = szComputerName;
  180. if ( szNormalizedComputerName )
  181. {
  182. // Make sure that the computer name string is at least 2 characters in length --
  183. // if the first character is non-zero, we know the second character must exist
  184. // since this is a zero terminated string -- in this case, it is safe to compare
  185. // the first 2 characters
  186. if ( *szNormalizedComputerName )
  187. {
  188. if ( ( TEXT('\\') == szNormalizedComputerName[0] ) &&
  189. ( TEXT('\\') == szNormalizedComputerName[1] ) )
  190. {
  191. szNormalizedComputerName += 2;
  192. }
  193. }
  194. }
  195. return szNormalizedComputerName;
  196. }
  197. //************************************************************************
  198. // CopyUnescapedSOM
  199. //
  200. // Purpose: to remove all escape sequence literals
  201. // of the form \" from a SOM stored in WMI -- WMI
  202. // cannot store the " character in a key field, so the
  203. // only way to store the " is to escape it -- this is done
  204. // so by preceding it with the \ char. To give back
  205. // a friendly display to the user, we undo the escape process
  206. //************************************************************************
  207. void CopyUnescapedSOM( LPTSTR lpUnescapedSOM, LPTSTR lpSOM )
  208. {
  209. while ( *lpSOM )
  210. {
  211. //
  212. // If we have the escape character
  213. //
  214. if ( TEXT('\\') == *lpSOM )
  215. {
  216. //
  217. // Check for the " character
  218. //
  219. if ( (TEXT('"') == *(lpSOM + 1)) || (TEXT('\\') == *(lpSOM + 1)) )
  220. {
  221. //
  222. // Skip the escape character if this is the " char
  223. //
  224. lpSOM++;
  225. }
  226. }
  227. *lpUnescapedSOM++ = *lpSOM++;
  228. }
  229. *lpUnescapedSOM = TEXT('\0');
  230. }
  231. //*************************************************************
  232. //
  233. // MyTranslateName()
  234. //
  235. // Purpose: Gets the user name in the requested format
  236. //
  237. // Return: lpUserName if successful
  238. // NULL if an error occurs
  239. //
  240. // Allocates and retries with the appropriate buffer size
  241. //
  242. //*************************************************************
  243. LPTSTR MyTranslateName (LPTSTR lpAccName, EXTENDED_NAME_FORMAT NameFormat, EXTENDED_NAME_FORMAT desiredNameFormat)
  244. {
  245. DWORD dwError = ERROR_SUCCESS;
  246. LPTSTR lpUserName = NULL, lpTemp;
  247. ULONG ulUserNameSize;
  248. //
  249. // Allocate a buffer for the user name
  250. //
  251. ulUserNameSize = 75;
  252. if (desiredNameFormat == NameFullyQualifiedDN) {
  253. ulUserNameSize = 200;
  254. }
  255. lpUserName = (LPTSTR) LocalAlloc (LPTR, ulUserNameSize * sizeof(TCHAR));
  256. if (!lpUserName) {
  257. dwError = GetLastError();
  258. DebugMsg((DM_WARNING, TEXT("MyGetUserName: Failed to allocate memory with %d"),
  259. dwError));
  260. goto Exit;
  261. }
  262. //
  263. // Get the username in the requested format
  264. //
  265. if (!TranslateName (lpAccName, NameFormat, desiredNameFormat, lpUserName, &ulUserNameSize)) {
  266. //
  267. // If the call failed due to insufficient memory, realloc
  268. // the buffer and try again. Otherwise, exit now.
  269. //
  270. dwError = GetLastError();
  271. if (dwError != ERROR_INSUFFICIENT_BUFFER) {
  272. DebugMsg((DM_WARNING, TEXT("MyGetTranslateName: TranslateName failed with %d"),
  273. dwError));
  274. LocalFree (lpUserName);
  275. lpUserName = NULL;
  276. goto Exit;
  277. }
  278. lpTemp = (LPTSTR) LocalReAlloc (lpUserName, (ulUserNameSize * sizeof(TCHAR)),
  279. LMEM_MOVEABLE);
  280. if (!lpTemp) {
  281. dwError = GetLastError();
  282. DebugMsg((DM_WARNING, TEXT("MyGetTranslateName: Failed to realloc memory with %d"),
  283. dwError));
  284. LocalFree (lpUserName);
  285. lpUserName = NULL;
  286. goto Exit;
  287. }
  288. lpUserName = lpTemp;
  289. if (!TranslateName (lpAccName, NameFormat, desiredNameFormat, lpUserName, &ulUserNameSize)) {
  290. dwError = GetLastError();
  291. DebugMsg((DM_WARNING, TEXT("MyGetTranslateName: TranslateName failed with %d"),
  292. dwError));
  293. LocalFree (lpUserName);
  294. lpUserName = NULL;
  295. goto Exit;
  296. }
  297. dwError = ERROR_SUCCESS;
  298. }
  299. Exit:
  300. SetLastError(dwError);
  301. return lpUserName;
  302. }
  303. //---------------------------------------------------------------------------
  304. // _CExtendedProcessing class
  305. class _CExtendedProcessing : public CRSOPExtendedProcessing
  306. {
  307. public:
  308. _CExtendedProcessing( BOOL bGetExtendedErrorInfo, CRSOPGPOLists& gpoLists, CRSOPCSELists& cseLists )
  309. : m_GPOLists( gpoLists )
  310. , m_CSELists( cseLists )
  311. , m_bGetExtendedErrorInfo( bGetExtendedErrorInfo )
  312. { ; }
  313. ~_CExtendedProcessing()
  314. { ; }
  315. virtual HRESULT DoProcessing( LPRSOP_QUERY pQuery, LPRSOP_QUERY_RESULTS pResults, BOOL bGetExtendedErrorInfo );
  316. virtual BOOL GetExtendedErrorInfo() const
  317. {
  318. return m_bGetExtendedErrorInfo;
  319. }
  320. private:
  321. CRSOPGPOLists& m_GPOLists;
  322. CRSOPCSELists& m_CSELists;
  323. BOOL m_bGetExtendedErrorInfo;
  324. };
  325. HRESULT _CExtendedProcessing::DoProcessing( LPRSOP_QUERY pQuery, LPRSOP_QUERY_RESULTS pResults, BOOL bGetExtendedErrorInfo )
  326. {
  327. m_bGetExtendedErrorInfo = bGetExtendedErrorInfo;
  328. m_GPOLists.Build( pResults->szWMINameSpace );
  329. m_CSELists.Build( pQuery, pResults->szWMINameSpace, GetExtendedErrorInfo() );
  330. if ( m_CSELists.GetEvents() != NULL )
  331. {
  332. m_CSELists.GetEvents()->DumpDebugInfo();
  333. }
  334. return S_OK;
  335. }
  336. //---------------------------------------------------------------------------
  337. // CRSOPGPOLists class
  338. void CRSOPGPOLists::Build( LPTSTR szWMINameSpace )
  339. {
  340. LPTSTR lpNamespace, lpEnd;
  341. ULONG ulNoChars;
  342. HRESULT hr;
  343. ulNoChars = lstrlen(szWMINameSpace) + 20;
  344. lpNamespace = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  345. if (lpNamespace)
  346. {
  347. hr = StringCchCopy( lpNamespace, ulNoChars, szWMINameSpace );
  348. ASSERT(SUCCEEDED(hr));
  349. ULONG ulNoRemChars;
  350. lpEnd = CheckSlash(lpNamespace);
  351. ulNoRemChars = ulNoChars - lstrlen(lpNamespace);
  352. hr = StringCchCat (lpNamespace, ulNoChars, TEXT("User"));
  353. if (SUCCEEDED(hr))
  354. {
  355. if (m_pUserGPOList)
  356. {
  357. FreeGPOListData(m_pUserGPOList);
  358. m_pUserGPOList = NULL;
  359. }
  360. BuildGPOList (&m_pUserGPOList, lpNamespace);
  361. }
  362. else
  363. {
  364. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOLists: Could not copy the nmae space with %d"),hr));
  365. }
  366. hr = StringCchCopy (lpEnd, ulNoRemChars, TEXT("Computer"));
  367. if (SUCCEEDED(hr))
  368. {
  369. if (m_pComputerGPOList)
  370. {
  371. FreeGPOListData(m_pComputerGPOList);
  372. m_pComputerGPOList = NULL;
  373. }
  374. BuildGPOList (&m_pComputerGPOList, lpNamespace);
  375. }
  376. else
  377. {
  378. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOLists: Cou;d not copy the nmae space with %d"),hr));
  379. }
  380. LocalFree (lpNamespace);
  381. }
  382. else
  383. {
  384. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOLists: Failed to allocate memory for namespace with %d"),
  385. GetLastError()));
  386. }
  387. }
  388. //-------------------------------------------------------
  389. void CRSOPGPOLists::BuildGPOList (LPGPOLISTITEM * lpList, LPTSTR lpNamespace)
  390. {
  391. HRESULT hr;
  392. ULONG n, ulIndex = 0, ulOrder, ulAppliedOrder;
  393. IWbemClassObject * pObjGPLink = NULL;
  394. IWbemClassObject * pObjGPO = NULL;
  395. IWbemClassObject * pObjSOM = NULL;
  396. IEnumWbemClassObject * pAppliedEnum = NULL;
  397. IEnumWbemClassObject * pNotAppliedEnum = NULL;
  398. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  399. BSTR strAppliedQuery = SysAllocString(TEXT("SELECT * FROM RSOP_GPLink where AppliedOrder > 0"));
  400. BSTR strNotAppliedQuery = SysAllocString(TEXT("SELECT * FROM RSOP_GPLink where AppliedOrder = 0"));
  401. BSTR strNamespace = SysAllocString(lpNamespace);
  402. BSTR strTemp = NULL;
  403. WCHAR * szGPOName = NULL;
  404. WCHAR * szSOM = NULL;
  405. WCHAR * szGPOPath = NULL;
  406. WCHAR szFiltering[80] = {0};
  407. BSTR bstrTemp = NULL;
  408. ULONG ul = 0, ulVersion = 0;
  409. BOOL bLinkEnabled, bGPOEnabled, bAccessDenied, bFilterAllowed, bSOMBlocked;
  410. BOOL bProcessAppliedList = TRUE;
  411. IWbemLocator * pLocator = NULL;
  412. IWbemServices * pNamespace = NULL;
  413. LV_COLUMN lvcol;
  414. BOOL bValidGPOData;
  415. LPBYTE pSD = NULL;
  416. DWORD dwDataSize = 0;
  417. // Get a locator instance
  418. hr = CoCreateInstance(CLSID_WbemLocator,
  419. 0,
  420. CLSCTX_INPROC_SERVER,
  421. IID_IWbemLocator,
  422. (LPVOID *)&pLocator);
  423. if (FAILED(hr))
  424. {
  425. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: CoCreateInstance failed with 0x%x"), hr));
  426. goto cleanup;
  427. }
  428. // Connect to the namespace
  429. BSTR bstrNamespace = SysAllocString( lpNamespace );
  430. if ( bstrNamespace == NULL )
  431. {
  432. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to allocate BSTR memory.")));
  433. hr = E_OUTOFMEMORY;
  434. goto cleanup;
  435. }
  436. hr = pLocator->ConnectServer(bstrNamespace,
  437. NULL,
  438. NULL,
  439. NULL,
  440. 0,
  441. NULL,
  442. NULL,
  443. &pNamespace);
  444. SysFreeString( bstrNamespace );
  445. if (FAILED(hr))
  446. {
  447. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: ConnectServer failed with 0x%x"), hr));
  448. goto cleanup;
  449. }
  450. // Set the proper security to encrypt the data
  451. hr = CoSetProxyBlanket(pNamespace,
  452. RPC_C_AUTHN_DEFAULT,
  453. RPC_C_AUTHZ_DEFAULT,
  454. COLE_DEFAULT_PRINCIPAL,
  455. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  456. RPC_C_IMP_LEVEL_IMPERSONATE,
  457. NULL,
  458. 0);
  459. if (FAILED(hr))
  460. {
  461. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: CoSetProxyBlanket failed with 0x%x"), hr));
  462. goto cleanup;
  463. }
  464. // Query for the RSOP_GPLink (applied) instances
  465. hr = pNamespace->ExecQuery(strQueryLanguage,
  466. strAppliedQuery,
  467. WBEM_FLAG_RETURN_IMMEDIATELY,
  468. NULL,
  469. &pAppliedEnum);
  470. if (FAILED(hr))
  471. {
  472. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: ExecQuery failed with 0x%x"), hr));
  473. goto cleanup;
  474. }
  475. // Query for the RSOP_GPLink (notapplied) instances
  476. hr = pNamespace->ExecQuery(strQueryLanguage,
  477. strNotAppliedQuery,
  478. WBEM_FLAG_RETURN_IMMEDIATELY,
  479. NULL,
  480. &pNotAppliedEnum);
  481. if (FAILED(hr))
  482. {
  483. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: ExecQuery (notapplied) failed with 0x%x"), hr));
  484. goto cleanup;
  485. }
  486. bProcessAppliedList = FALSE;
  487. // Loop through the results
  488. while (TRUE)
  489. {
  490. if (!bProcessAppliedList) {
  491. // No need to sort the not applied list
  492. hr = pNotAppliedEnum->Next(WBEM_INFINITE, 1, &pObjGPLink, &n);
  493. if (FAILED(hr) || (n == 0))
  494. {
  495. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::BuildGPOList: Getting applied links")));
  496. bProcessAppliedList = TRUE;
  497. }
  498. else {
  499. hr = GetParameter(pObjGPLink, TEXT("AppliedOrder"), ulOrder);
  500. if (FAILED(hr))
  501. {
  502. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get link order with 0x%x"), hr));
  503. goto cleanup;
  504. }
  505. }
  506. }
  507. // Reset the enumerator so we can look through the results to find the correct index
  508. if (bProcessAppliedList) {
  509. pAppliedEnum->Reset();
  510. // Find the correct index in the result set
  511. ulIndex++;
  512. ulOrder = 0;
  513. do {
  514. hr = pAppliedEnum->Next(WBEM_INFINITE, 1, &pObjGPLink, &n);
  515. if (FAILED(hr) || (n == 0))
  516. {
  517. goto cleanup;
  518. }
  519. hr = GetParameter(pObjGPLink, TEXT("AppliedOrder"), ulOrder);
  520. if (FAILED(hr))
  521. {
  522. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get link order with 0x%x"), hr));
  523. goto cleanup;
  524. }
  525. if (ulOrder != ulIndex)
  526. {
  527. pObjGPLink->Release();
  528. pObjGPLink = NULL;
  529. }
  530. } while (ulOrder != ulIndex);
  531. if (FAILED(hr)) {
  532. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Next failed with error 0x%x"), hr));
  533. goto cleanup;
  534. }
  535. }
  536. // Get the applied order of this link
  537. hr = GetParameter(pObjGPLink, TEXT("AppliedOrder"), ulAppliedOrder);
  538. if (FAILED(hr))
  539. {
  540. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get applied order with 0x%x"), hr));
  541. goto cleanup;
  542. }
  543. // Get the enabled state of the link
  544. hr = GetParameter(pObjGPLink, TEXT("enabled"), bLinkEnabled);
  545. if (FAILED(hr))
  546. {
  547. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get enabled with 0x%x"), hr));
  548. goto cleanup;
  549. }
  550. // Get the GPO path
  551. hr = GetParameterBSTR(pObjGPLink, TEXT("GPO"), bstrTemp);
  552. if (FAILED(hr))
  553. {
  554. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get GPO with 0x%x"), hr));
  555. goto cleanup;
  556. }
  557. // Set the default GPO name to be the gpo path. Don't worry about
  558. // freeing this string because the GetParameter call will free the buffer
  559. // when the real name is successfully queried. Sometimes the rsop_gpo instance
  560. // won't exist if this gpo is new.
  561. ULONG ulNoChars;
  562. ulNoChars = _tcslen(bstrTemp) + 1;
  563. szGPOName = new TCHAR[ulNoChars];
  564. if (!szGPOName)
  565. {
  566. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to allocate memory for temp gpo name.")));
  567. goto cleanup;
  568. }
  569. if (CompareString (LOCALE_INVARIANT, NORM_IGNORECASE | NORM_STOP_ON_NULL,
  570. TEXT("RSOP_GPO.id="), 12, bstrTemp, 12) == CSTR_EQUAL)
  571. {
  572. // removing the first and last quote
  573. hr = StringCchCopy (szGPOName, ulNoChars, bstrTemp+13);
  574. if (SUCCEEDED(hr))
  575. {
  576. szGPOName[lstrlen(szGPOName)-1] = TEXT('\0');
  577. }
  578. }
  579. else
  580. {
  581. hr = StringCchCopy (szGPOName, ulNoChars, bstrTemp);
  582. }
  583. if (FAILED(hr))
  584. {
  585. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Could not copy GPO name")));
  586. goto cleanup;
  587. }
  588. // Add ldap to the path if appropriate
  589. if (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, szGPOName, -1, TEXT("LocalGPO"), -1) != CSTR_EQUAL)
  590. {
  591. ulNoChars = lstrlen(szGPOName) + 10;
  592. szGPOPath = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(WCHAR));
  593. if (!szGPOPath)
  594. {
  595. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to allocate memory for full path with %d"),
  596. GetLastError()));
  597. goto cleanup;
  598. }
  599. hr = StringCchCopy (szGPOPath, ulNoChars, TEXT("LDAP://"));
  600. if (SUCCEEDED(hr))
  601. {
  602. hr = StringCchCat (szGPOPath, ulNoChars, szGPOName);
  603. }
  604. if (FAILED(hr))
  605. {
  606. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Could not copy GPO path")));
  607. goto cleanup;
  608. }
  609. }
  610. else
  611. {
  612. szGPOPath = NULL;
  613. }
  614. bValidGPOData = FALSE;
  615. // Bind to the GPO
  616. hr = pNamespace->GetObject(
  617. bstrTemp,
  618. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  619. NULL,
  620. &pObjGPO,
  621. NULL);
  622. if (FAILED(hr))
  623. {
  624. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: GetObject for GPO %s failed with 0x%x"),
  625. bstrTemp, hr));
  626. SysFreeString (bstrTemp);
  627. bstrTemp = NULL;
  628. goto GetSOMData;
  629. }
  630. SysFreeString (bstrTemp);
  631. bstrTemp = NULL;
  632. // Get the GPO name
  633. hr = GetParameter(pObjGPO, TEXT("name"), szGPOName);
  634. if (FAILED(hr))
  635. {
  636. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get name with 0x%x"), hr));
  637. goto GetSOMData;
  638. }
  639. // Get the version number
  640. hr = GetParameter(pObjGPO, TEXT("version"), ulVersion);
  641. if (FAILED(hr))
  642. {
  643. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get version with 0x%x"), hr));
  644. goto GetSOMData;
  645. }
  646. // Get the enabled state of the GPO
  647. hr = GetParameter(pObjGPO, TEXT("enabled"), bGPOEnabled);
  648. if (FAILED(hr))
  649. {
  650. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get gpo enabled state with 0x%x"), hr));
  651. goto GetSOMData;
  652. }
  653. // Get the WMI filter state of the GPO
  654. hr = GetParameter(pObjGPO, TEXT("filterAllowed"), bFilterAllowed);
  655. if (FAILED(hr))
  656. {
  657. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get gpo enabled state with 0x%x"), hr));
  658. goto GetSOMData;
  659. }
  660. // Check for access denied
  661. hr = GetParameter(pObjGPO, TEXT("accessDenied"), bAccessDenied);
  662. if (FAILED(hr))
  663. {
  664. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get accessdenied with 0x%x"), hr));
  665. goto GetSOMData;
  666. }
  667. // Get the security descriptor
  668. if (szGPOPath)
  669. {
  670. hr = GetParameterBytes(pObjGPO, TEXT("securityDescriptor"), &pSD, &dwDataSize);
  671. if (FAILED(hr))
  672. {
  673. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get security descriptor with 0x%x"), hr));
  674. goto GetSOMData;
  675. }
  676. }
  677. bValidGPOData = TRUE;
  678. GetSOMData:
  679. // Get the SOM for this link (the S,D,OU that this GPO is linked to)
  680. hr = GetParameterBSTR(pObjGPLink, TEXT("SOM"), bstrTemp);
  681. if (FAILED(hr))
  682. {
  683. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get SOM with 0x%x"), hr));
  684. goto AddNode;
  685. }
  686. // Bind to the SOM instance
  687. hr = pNamespace->GetObject(
  688. bstrTemp,
  689. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  690. NULL,
  691. &pObjSOM,
  692. NULL);
  693. if (FAILED(hr))
  694. {
  695. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: GetObject for SOM of %s failed with 0x%x"),
  696. bstrTemp, hr));
  697. SysFreeString (bstrTemp);
  698. bstrTemp = NULL;
  699. goto AddNode;
  700. }
  701. SysFreeString (bstrTemp);
  702. bstrTemp = NULL;
  703. // Get SOM name
  704. hr = GetParameter(pObjSOM, TEXT("id"), szSOM);
  705. if (FAILED(hr))
  706. {
  707. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get som id with 0x%x"), hr));
  708. goto AddNode;
  709. }
  710. // Get blocked from above
  711. hr = GetParameter(pObjSOM, TEXT("blocked"), bSOMBlocked);
  712. if (FAILED(hr))
  713. {
  714. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to get som id with 0x%x"), hr));
  715. goto AddNode;
  716. }
  717. AddNode:
  718. // Decide on the filtering name
  719. if (ulAppliedOrder > 0)
  720. {
  721. LoadString(g_hInstance, IDS_APPLIED, szFiltering, ARRAYSIZE(szFiltering));
  722. }
  723. else if (!bLinkEnabled)
  724. {
  725. LoadString(g_hInstance, IDS_DISABLEDLINK, szFiltering, ARRAYSIZE(szFiltering));
  726. }
  727. else if (bSOMBlocked) {
  728. LoadString(g_hInstance, IDS_BLOCKEDSOM, szFiltering, ARRAYSIZE(szFiltering));
  729. }
  730. else if ((bValidGPOData) && (!bGPOEnabled))
  731. {
  732. LoadString(g_hInstance, IDS_DISABLEDGPO, szFiltering, ARRAYSIZE(szFiltering));
  733. }
  734. else if ((bValidGPOData) && (bAccessDenied))
  735. {
  736. LoadString(g_hInstance, IDS_SECURITYDENIED, szFiltering, ARRAYSIZE(szFiltering));
  737. }
  738. else if ((bValidGPOData) && (!bFilterAllowed))
  739. {
  740. LoadString(g_hInstance, IDS_WMIFILTERFAILED, szFiltering, ARRAYSIZE(szFiltering));
  741. }
  742. else if ((bValidGPOData) && (ulVersion == 0))
  743. {
  744. LoadString(g_hInstance, IDS_NODATA, szFiltering, ARRAYSIZE(szFiltering));
  745. }
  746. else
  747. {
  748. LoadString(g_hInstance, IDS_UNKNOWNREASON, szFiltering, ARRAYSIZE(szFiltering));
  749. }
  750. if (!szSOM)
  751. {
  752. szSOM = new TCHAR[2];
  753. if (!szSOM)
  754. {
  755. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to allocate memory for temp som name.")));
  756. goto cleanup;
  757. }
  758. szSOM[0] = TEXT(' ');
  759. }
  760. // Add this node to the list
  761. if (!AddGPOListNode(szGPOName, szGPOPath, szSOM, szFiltering, ulVersion,
  762. ((ulAppliedOrder > 0) ? TRUE : FALSE), pSD, dwDataSize, lpList))
  763. {
  764. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: AddGPOListNode failed.")));
  765. }
  766. // Prepare for next iteration
  767. if (pObjSOM)
  768. {
  769. pObjSOM->Release();
  770. pObjSOM = NULL;
  771. }
  772. if (pObjGPO)
  773. {
  774. pObjGPO->Release();
  775. pObjGPO = NULL;
  776. }
  777. if (pObjGPLink)
  778. {
  779. pObjGPLink->Release();
  780. pObjGPLink = NULL;
  781. }
  782. if (szGPOName)
  783. {
  784. delete [] szGPOName;
  785. szGPOName = NULL;
  786. }
  787. if (szSOM)
  788. {
  789. delete [] szSOM;
  790. szSOM = NULL;
  791. }
  792. if (szGPOPath)
  793. {
  794. LocalFree (szGPOPath);
  795. szGPOPath = NULL;
  796. }
  797. if (pSD)
  798. {
  799. LocalFree (pSD);
  800. pSD = NULL;
  801. dwDataSize = 0;
  802. }
  803. ulVersion = 0;
  804. }
  805. cleanup:
  806. if (szGPOPath)
  807. {
  808. LocalFree (szGPOPath);
  809. }
  810. if (pSD)
  811. {
  812. LocalFree (pSD);
  813. }
  814. if (szGPOName)
  815. {
  816. delete [] szGPOName;
  817. }
  818. if (szSOM)
  819. {
  820. delete [] szSOM;
  821. }
  822. if (pObjSOM)
  823. {
  824. pObjSOM->Release();
  825. }
  826. if (pObjGPO)
  827. {
  828. pObjGPO->Release();
  829. }
  830. if (pObjGPLink)
  831. {
  832. pObjGPLink->Release();
  833. }
  834. if (pAppliedEnum)
  835. {
  836. pAppliedEnum->Release();
  837. }
  838. if (pNotAppliedEnum)
  839. {
  840. pNotAppliedEnum->Release();
  841. }
  842. if (pNamespace)
  843. {
  844. pNamespace->Release();
  845. }
  846. if (pLocator)
  847. {
  848. pLocator->Release();
  849. }
  850. SysFreeString(strQueryLanguage);
  851. SysFreeString(strAppliedQuery);
  852. SysFreeString(strNotAppliedQuery);
  853. SysFreeString(strNamespace);
  854. }
  855. //-------------------------------------------------------
  856. VOID CRSOPGPOLists::FreeGPOListData(LPGPOLISTITEM lpList)
  857. {
  858. LPGPOLISTITEM lpTemp;
  859. do {
  860. lpTemp = lpList->pNext;
  861. LocalFree (lpList);
  862. lpList = lpTemp;
  863. } while (lpTemp);
  864. }
  865. //-------------------------------------------------------
  866. BOOL CRSOPGPOLists::AddGPOListNode(LPTSTR lpGPOName, LPTSTR lpDSPath, LPTSTR lpSOM,
  867. LPTSTR lpFiltering, DWORD dwVersion, BOOL bApplied,
  868. LPBYTE pSD, DWORD dwSDSize, LPGPOLISTITEM *lpList)
  869. {
  870. DWORD dwSize;
  871. LPGPOLISTITEM lpItem, lpTemp;
  872. ULONG ulNoChars;
  873. HRESULT hr;
  874. //
  875. // Calculate the size of the new item
  876. //
  877. dwSize = sizeof (GPOLISTITEM);
  878. dwSize += ((lstrlen(lpGPOName) + 1) * sizeof(TCHAR));
  879. if (lpDSPath)
  880. {
  881. dwSize += ((lstrlen(lpDSPath) + 1) * sizeof(TCHAR));
  882. }
  883. dwSize += ((lstrlen(lpSOM) + 1) * sizeof(TCHAR));
  884. dwSize += ((lstrlen(lpSOM) + 1) * sizeof(TCHAR)); // The unescaped SOM length -- it is always smaller than the actual SOM
  885. dwSize += ((lstrlen(lpFiltering) + 1) * sizeof(TCHAR));
  886. dwSize += dwSDSize + MAX_ALIGNMENT_SIZE;
  887. //
  888. // Allocate space for it
  889. //
  890. lpItem = (LPGPOLISTITEM) LocalAlloc (LPTR, dwSize);
  891. if (!lpItem) {
  892. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::AddGPOListNode: Failed to allocate memory with %d"),
  893. GetLastError()));
  894. return FALSE;
  895. }
  896. //
  897. // Fill in item
  898. //
  899. ulNoChars = (dwSize - sizeof(GPOLISTITEM))/sizeof(WCHAR);
  900. lpItem->lpGPOName = (LPTSTR)(((LPBYTE)lpItem) + sizeof(GPOLISTITEM));
  901. hr = StringCchCopy (lpItem->lpGPOName, ulNoChars, lpGPOName);
  902. if (SUCCEEDED(hr))
  903. {
  904. if (lpDSPath)
  905. {
  906. lpItem->lpDSPath = lpItem->lpGPOName + lstrlen (lpItem->lpGPOName) + 1;
  907. ulNoChars = ulNoChars -(lstrlen (lpItem->lpGPOName) + 1);
  908. hr = StringCchCopy (lpItem->lpDSPath, ulNoChars, lpDSPath);
  909. if (SUCCEEDED(hr))
  910. {
  911. lpItem->lpSOM = lpItem->lpDSPath + lstrlen (lpItem->lpDSPath) + 1;
  912. ulNoChars = ulNoChars - (lstrlen (lpItem->lpDSPath) + 1);
  913. hr = StringCchCopy (lpItem->lpSOM, ulNoChars, lpSOM);
  914. }
  915. }
  916. else
  917. {
  918. lpItem->lpSOM = lpItem->lpGPOName + lstrlen (lpItem->lpGPOName) + 1;
  919. ulNoChars = ulNoChars - (lstrlen (lpItem->lpGPOName) + 1);
  920. hr = StringCchCopy (lpItem->lpSOM, ulNoChars, lpSOM);
  921. }
  922. }
  923. if (FAILED(hr))
  924. {
  925. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::AddGPOListNode: Could not copy GPO list item with %d"), hr));
  926. LocalFree(lpItem);
  927. return FALSE;
  928. }
  929. //
  930. // Note that the DS SOM's may contain characters such as '"' that
  931. // must be escaped with a "\" in WMI -- thus the SOM name will contain
  932. // '\' escape chars that are not actually present in the real SOM name,
  933. // so we call a function that removes them
  934. //
  935. lpItem->lpUnescapedSOM = lpItem->lpSOM + lstrlen (lpItem->lpSOM) + 1;
  936. CopyUnescapedSOM( lpItem->lpUnescapedSOM, lpItem->lpSOM );
  937. lpItem->lpFiltering = lpItem->lpUnescapedSOM + lstrlen (lpItem->lpUnescapedSOM) + 1;
  938. ulNoChars = ulNoChars - (lstrlen (lpItem->lpUnescapedSOM) + 1);
  939. hr = StringCchCopy (lpItem->lpFiltering, ulNoChars, lpFiltering);
  940. if (FAILED(hr))
  941. {
  942. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::AddGPOListNode: Could not copy GPO list item with %d"), hr));
  943. LocalFree(lpItem);
  944. return FALSE;
  945. }
  946. if (pSD)
  947. {
  948. // sd has to be pointer aligned. This is currently aligning it to
  949. // 8 byte boundary
  950. DWORD dwOffset;
  951. dwOffset = (DWORD) ((LPBYTE)(lpItem->lpFiltering + lstrlen (lpItem->lpFiltering) + 1) - (LPBYTE)lpItem);
  952. lpItem->pSD = (LPBYTE)lpItem + ALIGN_SIZE_TO_NEXTPTR(dwOffset);
  953. CopyMemory (lpItem->pSD, pSD, dwSDSize);
  954. }
  955. lpItem->dwVersion = dwVersion;
  956. lpItem->bApplied = bApplied;
  957. //
  958. // Add item to the link list
  959. //
  960. if (*lpList)
  961. {
  962. lpTemp = *lpList;
  963. while (lpTemp)
  964. {
  965. if (!lpTemp->pNext)
  966. {
  967. lpTemp->pNext = lpItem;
  968. break;
  969. }
  970. lpTemp = lpTemp->pNext;
  971. }
  972. }
  973. else
  974. {
  975. *lpList = lpItem;
  976. }
  977. return TRUE;
  978. }
  979. //---------------------------------------------------------------------------
  980. // CRSOPCSELists class
  981. VOID CRSOPCSELists::Build( LPRSOP_QUERY pQuery, LPTSTR szWMINameSpace, BOOL bGetEventLogErrors )
  982. {
  983. LPTSTR lpNamespace, lpEnd;
  984. HRESULT hr;
  985. ULONG ulNoChars;
  986. ULONG ulNoRemChars;
  987. ulNoChars = lstrlen(szWMINameSpace) + 20;
  988. lpNamespace = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  989. if (lpNamespace)
  990. {
  991. hr = StringCchCopy( lpNamespace, ulNoChars, szWMINameSpace );
  992. ASSERT(SUCCEEDED(hr));
  993. lpEnd = CheckSlash(lpNamespace);
  994. ulNoRemChars = ulNoChars - lstrlen(lpNamespace);
  995. m_bNoQuery = !bGetEventLogErrors;
  996. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  997. {
  998. m_szTargetMachine = pQuery->szDomainController;
  999. }
  1000. else
  1001. {
  1002. m_szTargetMachine = pQuery->szComputerName;
  1003. }
  1004. hr = StringCchCat (lpNamespace, ulNoChars, TEXT("User"));
  1005. if (SUCCEEDED(hr))
  1006. {
  1007. if (m_pUserCSEList)
  1008. {
  1009. FreeCSEData(m_pUserCSEList);
  1010. m_pUserCSEList = NULL;
  1011. m_bUserCSEError = FALSE;
  1012. m_bUserGPCoreError = FALSE;
  1013. m_bUserGPCoreWarning = FALSE;
  1014. }
  1015. BuildCSEList( pQuery, &m_pUserCSEList, lpNamespace, TRUE, &m_bUserCSEError, &m_bUserGPCoreError );
  1016. if (!m_bViewIsArchivedData)
  1017. {
  1018. QueryRSoPPolicySettingStatusInstances (lpNamespace);
  1019. }
  1020. //
  1021. // by this time m_pEvents is populated with eventlog entries
  1022. // in archived and non archived cases
  1023. //
  1024. // go through the list and figure out which one belongs to gp core
  1025. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  1026. {
  1027. for (LPCSEITEM lpTemp=m_pUserCSEList; lpTemp != NULL; lpTemp = lpTemp->pNext)
  1028. {
  1029. GUID guid;
  1030. StringToGuid( lpTemp->lpGUID, &guid);
  1031. if (IsNullGUID(&guid))
  1032. {
  1033. if (m_pEvents)
  1034. {
  1035. LPWSTR szEvents=NULL;
  1036. m_pEvents->GetCSEEntries(&(lpTemp->BeginTime), &(lpTemp->EndTime),
  1037. lpTemp->lpEventSources,
  1038. &szEvents,
  1039. TRUE);
  1040. if (szEvents)
  1041. {
  1042. m_bUserGPCoreWarning = TRUE;
  1043. CoTaskMemFree(szEvents);
  1044. }
  1045. }
  1046. break;
  1047. }
  1048. }
  1049. }
  1050. }
  1051. hr = StringCchCopy (lpEnd, ulNoRemChars, TEXT("Computer"));
  1052. if (SUCCEEDED(hr))
  1053. {
  1054. if (m_pComputerCSEList)
  1055. {
  1056. FreeCSEData(m_pComputerCSEList);
  1057. m_pComputerCSEList = NULL;
  1058. m_bComputerCSEError = FALSE;
  1059. m_bComputerGPCoreError = FALSE;
  1060. m_bComputerGPCoreWarning = FALSE;
  1061. }
  1062. BuildCSEList( pQuery, &m_pComputerCSEList, lpNamespace, FALSE, &m_bComputerCSEError, &m_bComputerGPCoreError );
  1063. if (!m_bViewIsArchivedData)
  1064. {
  1065. QueryRSoPPolicySettingStatusInstances (lpNamespace);
  1066. }
  1067. //
  1068. // by this time m_pEvents is populated with eventlog entries
  1069. // in archived and non archived cases
  1070. //
  1071. // go through the list and figure out which one belongs to gp core
  1072. if ( pQuery->QueryType == RSOP_PLANNING_MODE )
  1073. {
  1074. for (LPCSEITEM lpTemp=m_pComputerCSEList; lpTemp != NULL; lpTemp = lpTemp->pNext)
  1075. {
  1076. GUID guid;
  1077. StringToGuid( lpTemp->lpGUID, &guid);
  1078. if (IsNullGUID(&guid))
  1079. {
  1080. if (m_pEvents)
  1081. {
  1082. LPWSTR szEvents=NULL;
  1083. m_pEvents->GetCSEEntries(&(lpTemp->BeginTime), &(lpTemp->EndTime),
  1084. lpTemp->lpEventSources,
  1085. &szEvents,
  1086. TRUE);
  1087. if (szEvents)
  1088. {
  1089. m_bComputerGPCoreWarning = TRUE;
  1090. CoTaskMemFree(szEvents);
  1091. }
  1092. }
  1093. break;
  1094. }
  1095. }
  1096. }
  1097. }
  1098. LocalFree (lpNamespace);
  1099. }
  1100. else
  1101. {
  1102. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSELists: Failed to allocate memory for namespace with %d"),
  1103. GetLastError()));
  1104. }
  1105. m_szTargetMachine = NULL;
  1106. }
  1107. //-------------------------------------------------------
  1108. void CRSOPCSELists::BuildCSEList( LPRSOP_QUERY pQuery, LPCSEITEM * lpList, LPTSTR lpNamespace, BOOL bUser, BOOL *bCSEError, BOOL *bGPCoreError )
  1109. {
  1110. HRESULT hr;
  1111. ULONG n;
  1112. IWbemClassObject * pExtension = NULL;
  1113. IEnumWbemClassObject * pEnum = NULL;
  1114. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  1115. BSTR strQuery = SysAllocString(TEXT("SELECT * FROM RSOP_ExtensionStatus"));
  1116. BSTR strNamespace = SysAllocString(lpNamespace);
  1117. BSTR bstrName = NULL;
  1118. BSTR bstrGUID = NULL;
  1119. BSTR bstrBeginTime = NULL;
  1120. BSTR bstrEndTime = NULL;
  1121. ULONG ulLoggingStatus;
  1122. ULONG ulStatus;
  1123. IWbemLocator * pLocator = NULL;
  1124. IWbemServices * pNamespace = NULL;
  1125. SYSTEMTIME BeginTime, EndTime;
  1126. LPTSTR lpSourceNames = NULL;
  1127. XBStr xbstrWbemTime;
  1128. LPSOURCEENTRY lpSources;
  1129. // Get a locator instance
  1130. hr = CoCreateInstance(CLSID_WbemLocator,
  1131. 0,
  1132. CLSCTX_INPROC_SERVER,
  1133. IID_IWbemLocator,
  1134. (LPVOID *)&pLocator);
  1135. if (FAILED(hr))
  1136. {
  1137. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: CoCreateInstance failed with 0x%x"), hr));
  1138. goto cleanup;
  1139. }
  1140. // Connect to the namespace
  1141. BSTR bstrNamespace = SysAllocString( lpNamespace );
  1142. if ( bstrNamespace == NULL )
  1143. {
  1144. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: Failed to allocate BSTR memory.")));
  1145. hr = E_OUTOFMEMORY;
  1146. goto cleanup;
  1147. }
  1148. hr = pLocator->ConnectServer(bstrNamespace,
  1149. NULL,
  1150. NULL,
  1151. NULL,
  1152. 0,
  1153. NULL,
  1154. NULL,
  1155. &pNamespace);
  1156. SysFreeString( bstrNamespace );
  1157. if (FAILED(hr))
  1158. {
  1159. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: ConnectServer failed with 0x%x"), hr));
  1160. goto cleanup;
  1161. }
  1162. // Set the proper security to encrypt the data
  1163. hr = CoSetProxyBlanket(pNamespace,
  1164. RPC_C_AUTHN_DEFAULT,
  1165. RPC_C_AUTHZ_DEFAULT,
  1166. COLE_DEFAULT_PRINCIPAL,
  1167. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  1168. RPC_C_IMP_LEVEL_IMPERSONATE,
  1169. NULL,
  1170. 0);
  1171. if (FAILED(hr))
  1172. {
  1173. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: CoSetProxyBlanket failed with 0x%x"), hr));
  1174. goto cleanup;
  1175. }
  1176. // Query for the RSOP_ExtensionStatus instances
  1177. hr = pNamespace->ExecQuery(strQueryLanguage,
  1178. strQuery,
  1179. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  1180. NULL,
  1181. &pEnum);
  1182. if (FAILED(hr))
  1183. {
  1184. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: ExecQuery failed with 0x%x"), hr));
  1185. goto cleanup;
  1186. }
  1187. // Loop through the results
  1188. while (TRUE)
  1189. {
  1190. // Get 1 instance
  1191. hr = pEnum->Next(WBEM_INFINITE, 1, &pExtension, &n);
  1192. if (FAILED(hr) || (n == 0))
  1193. {
  1194. goto cleanup;
  1195. }
  1196. // Get the name
  1197. hr = GetParameterBSTR(pExtension, TEXT("displayName"), bstrName);
  1198. if (FAILED(hr))
  1199. {
  1200. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: Failed to get display name with 0x%x"), hr));
  1201. goto cleanup;
  1202. }
  1203. // Get the GUID
  1204. hr = GetParameterBSTR(pExtension, TEXT("extensionGuid"), bstrGUID);
  1205. if (FAILED(hr))
  1206. {
  1207. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: Failed to get display name with 0x%x"), hr));
  1208. goto cleanup;
  1209. }
  1210. // Get the status
  1211. hr = GetParameter(pExtension, TEXT("error"), ulStatus);
  1212. if (FAILED(hr))
  1213. {
  1214. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: Failed to get status with 0x%x"), hr));
  1215. goto cleanup;
  1216. }
  1217. // Get the rsop logging status
  1218. hr = GetParameter(pExtension, TEXT("loggingStatus"), ulLoggingStatus);
  1219. if (FAILED(hr))
  1220. {
  1221. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: Failed to get logging status with 0x%x"), hr));
  1222. goto cleanup;
  1223. }
  1224. // Get the BeginTime in bstr format
  1225. hr = GetParameterBSTR(pExtension, TEXT("beginTime"), bstrBeginTime);
  1226. if (FAILED(hr))
  1227. {
  1228. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: Failed to get begin time with 0x%x"), hr));
  1229. goto cleanup;
  1230. }
  1231. // Convert it to system time format
  1232. xbstrWbemTime = bstrBeginTime;
  1233. hr = WbemTimeToSystemTime(xbstrWbemTime, BeginTime);
  1234. if (FAILED(hr))
  1235. {
  1236. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: WbemTimeToSystemTime failed with 0x%x"), hr));
  1237. goto cleanup;
  1238. }
  1239. // Get the EndTime in bstr format
  1240. hr = GetParameterBSTR(pExtension, TEXT("endTime"), bstrEndTime);
  1241. if (SUCCEEDED(hr))
  1242. {
  1243. // Convert it to system time format
  1244. xbstrWbemTime = bstrEndTime;
  1245. hr = WbemTimeToSystemTime(xbstrWbemTime, EndTime);
  1246. if (FAILED(hr))
  1247. {
  1248. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: WbemTimeToSystemTime failed with 0x%x"), hr));
  1249. goto cleanup;
  1250. }
  1251. }
  1252. else
  1253. {
  1254. FILETIME ft;
  1255. ULARGE_INTEGER ulTime;
  1256. // Add 2 minutes to BeginTime to get a close approx of the EndTime
  1257. if (!SystemTimeToFileTime (&BeginTime, &ft))
  1258. {
  1259. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: SystemTimeToFileTime failed with %d"), GetLastError()));
  1260. goto cleanup;
  1261. }
  1262. ulTime.LowPart = ft.dwLowDateTime;
  1263. ulTime.HighPart = ft.dwHighDateTime;
  1264. ulTime.QuadPart = ulTime.QuadPart + (10000000 * 120); // 120 seconds
  1265. ft.dwLowDateTime = ulTime.LowPart;
  1266. ft.dwHighDateTime = ulTime.HighPart;
  1267. if (!FileTimeToSystemTime (&ft, &EndTime))
  1268. {
  1269. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: FileTimeToSystemTime failed with %d"), GetLastError()));
  1270. goto cleanup;
  1271. }
  1272. }
  1273. // Get the event log source information
  1274. lpSources = NULL;
  1275. GetEventLogSources (pNamespace, bstrGUID, m_szTargetMachine,
  1276. &BeginTime, &EndTime, &lpSources);
  1277. // Add this node to the list
  1278. if (!AddCSENode(bstrName, bstrGUID, ulStatus, ulLoggingStatus, &BeginTime, &EndTime, bUser,
  1279. lpList, bCSEError, bGPCoreError, lpSources))
  1280. {
  1281. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildCSEList: AddGPOListNode failed.")));
  1282. if (m_pEvents)
  1283. {
  1284. m_pEvents->FreeSourceData (lpSources);
  1285. }
  1286. goto cleanup;
  1287. }
  1288. // Prepare for next iteration
  1289. SysFreeString (bstrName);
  1290. bstrName = NULL;
  1291. SysFreeString (bstrGUID);
  1292. bstrGUID = NULL;
  1293. SysFreeString (bstrBeginTime);
  1294. bstrBeginTime = NULL;
  1295. if (bstrEndTime)
  1296. {
  1297. SysFreeString (bstrEndTime);
  1298. bstrEndTime = NULL;
  1299. }
  1300. LocalFree (lpSourceNames);
  1301. lpSourceNames = NULL;
  1302. pExtension->Release();
  1303. pExtension = NULL;
  1304. }
  1305. cleanup:
  1306. if (bstrName)
  1307. {
  1308. SysFreeString (bstrName);
  1309. }
  1310. if (bstrGUID)
  1311. {
  1312. SysFreeString (bstrGUID);
  1313. }
  1314. if (bstrBeginTime)
  1315. {
  1316. SysFreeString (bstrBeginTime);
  1317. }
  1318. if (bstrEndTime)
  1319. {
  1320. SysFreeString (bstrEndTime);
  1321. }
  1322. if (lpSourceNames)
  1323. {
  1324. LocalFree (lpSourceNames);
  1325. }
  1326. if (pEnum)
  1327. {
  1328. pEnum->Release();
  1329. }
  1330. if (pNamespace)
  1331. {
  1332. pNamespace->Release();
  1333. }
  1334. if (pLocator)
  1335. {
  1336. pLocator->Release();
  1337. }
  1338. SysFreeString(strQueryLanguage);
  1339. SysFreeString(strQuery);
  1340. SysFreeString(strNamespace);
  1341. }
  1342. //-------------------------------------------------------
  1343. VOID CRSOPCSELists::FreeCSEData(LPCSEITEM lpList)
  1344. {
  1345. LPCSEITEM lpTemp;
  1346. do {
  1347. lpTemp = lpList->pNext;
  1348. if (m_pEvents)
  1349. {
  1350. m_pEvents->FreeData();
  1351. m_pEvents->FreeSourceData (lpList->lpEventSources);
  1352. }
  1353. LocalFree (lpList);
  1354. lpList = lpTemp;
  1355. } while (lpTemp);
  1356. }
  1357. //-------------------------------------------------------
  1358. BOOL CRSOPCSELists::AddCSENode(LPTSTR lpName, LPTSTR lpGUID, DWORD dwStatus,
  1359. ULONG ulLoggingStatus, SYSTEMTIME *pBeginTime, SYSTEMTIME *pEndTime, BOOL bUser,
  1360. LPCSEITEM *lpList, BOOL *bCSEError, BOOL *bGPCoreError,
  1361. LPSOURCEENTRY lpSources)
  1362. {
  1363. DWORD dwSize;
  1364. LPCSEITEM lpItem, lpTemp;
  1365. GUID guid;
  1366. ULONG ulNoChars;
  1367. HRESULT hr;
  1368. //
  1369. // Calculate the size of the new item
  1370. //
  1371. dwSize = sizeof (CSEITEM);
  1372. dwSize += ((lstrlen(lpName) + 1) * sizeof(TCHAR));
  1373. dwSize += ((lstrlen(lpGUID) + 1) * sizeof(TCHAR));
  1374. //
  1375. // Allocate space for it
  1376. //
  1377. lpItem = (LPCSEITEM) LocalAlloc (LPTR, dwSize);
  1378. if (!lpItem) {
  1379. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::AddCSENode: Failed to allocate memory with %d"),
  1380. GetLastError()));
  1381. return FALSE;
  1382. }
  1383. //
  1384. // Fill in item
  1385. //
  1386. lpItem->lpName = (LPTSTR)(((LPBYTE)lpItem) + sizeof(CSEITEM));
  1387. ulNoChars = (dwSize - sizeof(CSEITEM))/sizeof(WCHAR);
  1388. hr = StringCchCopy (lpItem->lpName, ulNoChars, lpName);
  1389. if (SUCCEEDED(hr))
  1390. {
  1391. lpItem->lpGUID = lpItem->lpName + lstrlen (lpItem->lpName) + 1;
  1392. ulNoChars = ulNoChars - (lstrlen (lpItem->lpName) + 1);
  1393. hr = StringCchCopy (lpItem->lpGUID, ulNoChars, lpGUID);
  1394. }
  1395. if (FAILED(hr))
  1396. {
  1397. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::AddCSENode: Could not copy GPO name with %d"),hr));
  1398. LocalFree(lpItem);
  1399. return FALSE;
  1400. }
  1401. lpItem->dwStatus = dwStatus;
  1402. lpItem->ulLoggingStatus = ulLoggingStatus;
  1403. lpItem->lpEventSources = lpSources;
  1404. lpItem->bUser = bUser;
  1405. CopyMemory ((LPBYTE)&lpItem->BeginTime, pBeginTime, sizeof(SYSTEMTIME));
  1406. CopyMemory ((LPBYTE)&lpItem->EndTime, pEndTime, sizeof(SYSTEMTIME));
  1407. //
  1408. // Add item to the link list
  1409. //
  1410. if (*lpList)
  1411. {
  1412. StringToGuid( lpGUID, &guid);
  1413. if (IsNullGUID (&guid))
  1414. {
  1415. lpItem->pNext = *lpList;
  1416. *lpList = lpItem;
  1417. }
  1418. else
  1419. {
  1420. lpTemp = *lpList;
  1421. while (lpTemp)
  1422. {
  1423. if (!lpTemp->pNext)
  1424. {
  1425. lpTemp->pNext = lpItem;
  1426. break;
  1427. }
  1428. lpTemp = lpTemp->pNext;
  1429. }
  1430. }
  1431. }
  1432. else
  1433. {
  1434. *lpList = lpItem;
  1435. }
  1436. //
  1437. // Set the error flag if appropriate
  1438. //
  1439. if ((dwStatus != ERROR_SUCCESS) || (ulLoggingStatus == 2))
  1440. {
  1441. StringToGuid( lpGUID, &guid);
  1442. if (IsNullGUID (&guid))
  1443. {
  1444. *bGPCoreError = TRUE;
  1445. }
  1446. else
  1447. {
  1448. *bCSEError = TRUE;
  1449. }
  1450. }
  1451. return TRUE;
  1452. }
  1453. //-------------------------------------------------------
  1454. void CRSOPCSELists::GetEventLogSources (IWbemServices * pNamespace,
  1455. LPTSTR lpCSEGUID, LPTSTR lpComputerName,
  1456. SYSTEMTIME *BeginTime, SYSTEMTIME *EndTime,
  1457. LPSOURCEENTRY *lpSources)
  1458. {
  1459. HRESULT hr;
  1460. ULONG n;
  1461. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  1462. BSTR strQuery = NULL;
  1463. LPTSTR lpQuery;
  1464. const TCHAR szBaseQuery [] = TEXT("SELECT * FROM RSOP_ExtensionEventSourceLink WHERE extensionStatus=\"RSOP_ExtensionStatus.extensionGuid=\\\"%s\\\"\"");
  1465. IEnumWbemClassObject * pEnum = NULL;
  1466. IWbemClassObject * pLink = NULL;
  1467. IWbemClassObject * pEventSource = NULL;
  1468. BSTR bstrEventSource = NULL;
  1469. BSTR bstrEventLogName = NULL;
  1470. BSTR bstrEventSourceName = NULL;
  1471. ULONG ulNoChars;
  1472. //
  1473. // Build the query first
  1474. //
  1475. ulNoChars = lstrlen(szBaseQuery) + 50;
  1476. lpQuery = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  1477. if (!lpQuery)
  1478. {
  1479. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetEventLogSources: Failed to allocate memory for query")));
  1480. goto cleanup;
  1481. }
  1482. hr = StringCchPrintf (lpQuery, ulNoChars, szBaseQuery, lpCSEGUID);
  1483. if (FAILED(hr))
  1484. {
  1485. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetEventLogSources: Failed to copy rsop query")));
  1486. LocalFree (lpQuery);
  1487. goto cleanup;
  1488. }
  1489. strQuery = SysAllocString(lpQuery);
  1490. LocalFree (lpQuery);
  1491. if (!strQuery)
  1492. {
  1493. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetEventLogSources: Failed to allocate memory for query (2)")));
  1494. goto cleanup;
  1495. }
  1496. //
  1497. // Query for the RSOP_ExtensionEventSourceLink instances that match this CSE
  1498. //
  1499. hr = pNamespace->ExecQuery(strQueryLanguage,
  1500. strQuery,
  1501. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  1502. NULL,
  1503. &pEnum);
  1504. if (FAILED(hr))
  1505. {
  1506. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetEventLogSources: ExecQuery failed with 0x%x"), hr));
  1507. goto cleanup;
  1508. }
  1509. //
  1510. // Loop through the results
  1511. //
  1512. while (TRUE)
  1513. {
  1514. //
  1515. // Get 1 instance
  1516. //
  1517. hr = pEnum->Next(WBEM_INFINITE, 1, &pLink, &n);
  1518. if (FAILED(hr) || (n == 0))
  1519. {
  1520. goto cleanup;
  1521. }
  1522. //
  1523. // Get the eventSource reference
  1524. //
  1525. hr = GetParameterBSTR(pLink, TEXT("eventSource"), bstrEventSource);
  1526. if (FAILED(hr))
  1527. {
  1528. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetEventLogSources: Failed to get event source reference with 0x%x"), hr));
  1529. goto cleanup;
  1530. }
  1531. //
  1532. // Get the eventSource instance
  1533. //
  1534. hr = pNamespace->GetObject(
  1535. bstrEventSource,
  1536. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  1537. NULL,
  1538. &pEventSource,
  1539. NULL);
  1540. if (FAILED(hr))
  1541. {
  1542. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetEventLogSources: GetObject for event source of %s failed with 0x%x"),
  1543. bstrEventSource, hr));
  1544. goto loopagain;
  1545. }
  1546. //
  1547. // Get the eventLogSource property
  1548. //
  1549. hr = GetParameterBSTR(pEventSource, TEXT("eventLogSource"), bstrEventSourceName);
  1550. if (FAILED(hr))
  1551. {
  1552. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetEventLogSources: Failed to get event source name with 0x%x"), hr));
  1553. goto cleanup;
  1554. }
  1555. //
  1556. // Get the eventLogName property
  1557. //
  1558. hr = GetParameterBSTR(pEventSource, TEXT("eventLogName"), bstrEventLogName);
  1559. if (FAILED(hr))
  1560. {
  1561. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetEventLogSources: Failed to get event log name with 0x%x"), hr));
  1562. goto cleanup;
  1563. }
  1564. if (m_pEvents)
  1565. {
  1566. //
  1567. // Add it to the list of sources
  1568. //
  1569. m_pEvents->AddSourceEntry (bstrEventLogName, bstrEventSourceName, lpSources);
  1570. //
  1571. // Initialize the event log database for this source if we are working
  1572. // with a live query. If this is archived data, the event log entries
  1573. // will be reloaded from the saved console file.
  1574. //
  1575. if (!m_bViewIsArchivedData && !m_bNoQuery)
  1576. {
  1577. m_pEvents->QueryForEventLogEntries (lpComputerName,
  1578. bstrEventLogName, bstrEventSourceName,
  1579. 0, BeginTime, EndTime);
  1580. }
  1581. }
  1582. //
  1583. // Clean up for next item
  1584. //
  1585. SysFreeString (bstrEventLogName);
  1586. bstrEventLogName = NULL;
  1587. SysFreeString (bstrEventSourceName);
  1588. bstrEventSourceName = NULL;
  1589. pEventSource->Release();
  1590. pEventSource = NULL;
  1591. loopagain:
  1592. SysFreeString (bstrEventSource);
  1593. bstrEventSource = NULL;
  1594. pLink->Release();
  1595. pLink = NULL;
  1596. }
  1597. cleanup:
  1598. if (bstrEventSourceName)
  1599. {
  1600. SysFreeString (bstrEventSourceName);
  1601. }
  1602. if (bstrEventLogName)
  1603. {
  1604. SysFreeString (bstrEventLogName);
  1605. }
  1606. if (bstrEventSource)
  1607. {
  1608. SysFreeString (bstrEventSource);
  1609. }
  1610. if (pEventSource)
  1611. {
  1612. pEventSource->Release();
  1613. }
  1614. if (pLink)
  1615. {
  1616. pLink->Release();
  1617. }
  1618. if (pEnum)
  1619. {
  1620. pEnum->Release();
  1621. }
  1622. if (strQueryLanguage)
  1623. {
  1624. SysFreeString(strQueryLanguage);
  1625. }
  1626. if (strQuery)
  1627. {
  1628. SysFreeString(strQuery);
  1629. }
  1630. }
  1631. //-------------------------------------------------------
  1632. void CRSOPCSELists::QueryRSoPPolicySettingStatusInstances (LPTSTR lpNamespace)
  1633. {
  1634. HRESULT hr;
  1635. ULONG n;
  1636. IWbemClassObject * pStatus = NULL;
  1637. IEnumWbemClassObject * pEnum = NULL;
  1638. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  1639. BSTR strQuery = SysAllocString(TEXT("SELECT * FROM RSoP_PolicySettingStatus"));
  1640. BSTR strNamespace = SysAllocString(lpNamespace);
  1641. BSTR bstrEventSource = NULL;
  1642. BSTR bstrEventLogName = NULL;
  1643. DWORD dwEventID;
  1644. BSTR bstrEventTime = NULL;
  1645. IWbemLocator * pLocator = NULL;
  1646. IWbemServices * pNamespace = NULL;
  1647. SYSTEMTIME EventTime, BeginTime, EndTime;
  1648. XBStr xbstrWbemTime;
  1649. FILETIME ft;
  1650. ULARGE_INTEGER ulTime;
  1651. //
  1652. // Get a locator instance
  1653. //
  1654. hr = CoCreateInstance(CLSID_WbemLocator,
  1655. 0,
  1656. CLSCTX_INPROC_SERVER,
  1657. IID_IWbemLocator,
  1658. (LPVOID *)&pLocator);
  1659. if (FAILED(hr))
  1660. {
  1661. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: CoCreateInstance failed with 0x%x"), hr));
  1662. goto cleanup;
  1663. }
  1664. //
  1665. // Connect to the namespace
  1666. //
  1667. BSTR bstrNamespace = SysAllocString( lpNamespace );
  1668. if ( bstrNamespace == NULL )
  1669. {
  1670. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: Failed to allocate BSTR memory.")));
  1671. hr = E_OUTOFMEMORY;
  1672. goto cleanup;
  1673. }
  1674. hr = pLocator->ConnectServer(bstrNamespace,
  1675. NULL,
  1676. NULL,
  1677. NULL,
  1678. 0,
  1679. NULL,
  1680. NULL,
  1681. &pNamespace);
  1682. SysFreeString( bstrNamespace );
  1683. if (FAILED(hr))
  1684. {
  1685. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: ConnectServer failed with 0x%x"), hr));
  1686. goto cleanup;
  1687. }
  1688. // Set the proper security to encrypt the data
  1689. hr = CoSetProxyBlanket(pNamespace,
  1690. RPC_C_AUTHN_DEFAULT,
  1691. RPC_C_AUTHZ_DEFAULT,
  1692. COLE_DEFAULT_PRINCIPAL,
  1693. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  1694. RPC_C_IMP_LEVEL_IMPERSONATE,
  1695. NULL,
  1696. 0);
  1697. if (FAILED(hr))
  1698. {
  1699. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: CoSetProxyBlanket failed with 0x%x"), hr));
  1700. goto cleanup;
  1701. }
  1702. //
  1703. // Query for the RSoP_PolicySettingStatus instances
  1704. //
  1705. hr = pNamespace->ExecQuery(strQueryLanguage,
  1706. strQuery,
  1707. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  1708. NULL,
  1709. &pEnum);
  1710. if (FAILED(hr))
  1711. {
  1712. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: ExecQuery failed with 0x%x"), hr));
  1713. goto cleanup;
  1714. }
  1715. //
  1716. // Loop through the results
  1717. //
  1718. while (TRUE)
  1719. {
  1720. //
  1721. // Get 1 instance
  1722. //
  1723. hr = pEnum->Next(WBEM_INFINITE, 1, &pStatus, &n);
  1724. if (FAILED(hr) || (n == 0))
  1725. {
  1726. goto cleanup;
  1727. }
  1728. //
  1729. // Get the event source name
  1730. //
  1731. hr = GetParameterBSTR(pStatus, TEXT("eventSource"), bstrEventSource);
  1732. if (FAILED(hr))
  1733. {
  1734. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: Failed to get display name with 0x%x"), hr));
  1735. goto cleanup;
  1736. }
  1737. //
  1738. // Get the event log name
  1739. //
  1740. hr = GetParameterBSTR(pStatus, TEXT("eventLogName"), bstrEventLogName);
  1741. if (FAILED(hr))
  1742. {
  1743. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: Failed to get display name with 0x%x"), hr));
  1744. goto cleanup;
  1745. }
  1746. //
  1747. // Get the event ID
  1748. //
  1749. hr = GetParameter(pStatus, TEXT("eventID"), (ULONG)dwEventID);
  1750. if (FAILED(hr))
  1751. {
  1752. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: Failed to get display name with 0x%x"), hr));
  1753. goto cleanup;
  1754. }
  1755. //
  1756. // Get the EventTime in bstr format
  1757. //
  1758. hr = GetParameterBSTR(pStatus, TEXT("eventTime"), bstrEventTime);
  1759. if (FAILED(hr))
  1760. {
  1761. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: Failed to get event time with 0x%x"), hr));
  1762. goto cleanup;
  1763. }
  1764. //
  1765. // Convert it to system time format
  1766. //
  1767. xbstrWbemTime = bstrEventTime;
  1768. hr = WbemTimeToSystemTime(xbstrWbemTime, EventTime);
  1769. if (FAILED(hr))
  1770. {
  1771. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: WbemTimeToSystemTime failed with 0x%x"), hr));
  1772. goto cleanup;
  1773. }
  1774. //
  1775. // Take the event time minus 1 second to get the begin time
  1776. //
  1777. if (!SystemTimeToFileTime (&EventTime, &ft))
  1778. {
  1779. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: SystemTimeToFileTime failed with %d"), GetLastError()));
  1780. goto cleanup;
  1781. }
  1782. ulTime.LowPart = ft.dwLowDateTime;
  1783. ulTime.HighPart = ft.dwHighDateTime;
  1784. ulTime.QuadPart = ulTime.QuadPart - 10000000; // 1 second
  1785. ft.dwLowDateTime = ulTime.LowPart;
  1786. ft.dwHighDateTime = ulTime.HighPart;
  1787. if (!FileTimeToSystemTime (&ft, &BeginTime))
  1788. {
  1789. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: FileTimeToSystemTime failed with %d"), GetLastError()));
  1790. goto cleanup;
  1791. }
  1792. //
  1793. // Take the event time plus 1 second to get the end time
  1794. //
  1795. if (!SystemTimeToFileTime (&EventTime, &ft))
  1796. {
  1797. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: SystemTimeToFileTime failed with %d"), GetLastError()));
  1798. goto cleanup;
  1799. }
  1800. ulTime.LowPart = ft.dwLowDateTime;
  1801. ulTime.HighPart = ft.dwHighDateTime;
  1802. ulTime.QuadPart = ulTime.QuadPart + 10000000; // 1 second
  1803. ft.dwLowDateTime = ulTime.LowPart;
  1804. ft.dwHighDateTime = ulTime.HighPart;
  1805. if (!FileTimeToSystemTime (&ft, &EndTime))
  1806. {
  1807. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::QueryRSoPPolicySettingStatusInstances: FileTimeToSystemTime failed with %d"), GetLastError()));
  1808. goto cleanup;
  1809. }
  1810. //
  1811. // Get the event log source information
  1812. //
  1813. if (m_pEvents && !m_bNoQuery)
  1814. {
  1815. m_pEvents->QueryForEventLogEntries( m_szTargetMachine,
  1816. bstrEventLogName, bstrEventSource, dwEventID,
  1817. &BeginTime, &EndTime);
  1818. }
  1819. //
  1820. // Prepare for next iteration
  1821. //
  1822. SysFreeString (bstrEventSource);
  1823. bstrEventSource = NULL;
  1824. SysFreeString (bstrEventLogName);
  1825. bstrEventLogName = NULL;
  1826. SysFreeString (bstrEventTime);
  1827. bstrEventTime = NULL;
  1828. pStatus->Release();
  1829. pStatus = NULL;
  1830. }
  1831. cleanup:
  1832. if (bstrEventSource)
  1833. {
  1834. SysFreeString (bstrEventSource);
  1835. }
  1836. if (bstrEventLogName)
  1837. {
  1838. SysFreeString (bstrEventLogName);
  1839. }
  1840. if (bstrEventTime)
  1841. {
  1842. SysFreeString (bstrEventTime);
  1843. }
  1844. if (pEnum)
  1845. {
  1846. pEnum->Release();
  1847. }
  1848. if (pNamespace)
  1849. {
  1850. pNamespace->Release();
  1851. }
  1852. if (pLocator)
  1853. {
  1854. pLocator->Release();
  1855. }
  1856. SysFreeString(strQueryLanguage);
  1857. SysFreeString(strQuery);
  1858. SysFreeString(strNamespace);
  1859. }
  1860. //---------------------------------------------------------------------------
  1861. // CRSOPComponentData class
  1862. //
  1863. //-------------------------------------------------------
  1864. // Static member variable declarations
  1865. //
  1866. unsigned int CRSOPCMenu::m_cfDSObjectName = RegisterClipboardFormat(CFSTR_DSOBJECTNAMES);
  1867. //-------------------------------------------------------
  1868. // Constructors/destructor
  1869. //
  1870. CRSOPComponentData::CRSOPComponentData()
  1871. : m_CSELists( m_bViewIsArchivedData )
  1872. {
  1873. InterlockedIncrement(&g_cRefThisDll);
  1874. m_bPostXPBuild = FALSE; // Assume this is not post XP until verified as otherwise
  1875. OSVERSIONINFOEX osvi;
  1876. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
  1877. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  1878. if ( GetVersionEx ((OSVERSIONINFO*) &osvi) )
  1879. {
  1880. // Windows XP was version 5.1, while .Net Server is version 5.2. So, we enable the
  1881. // additional features for any version past XP, i.e. >= 5.2
  1882. m_bPostXPBuild = (osvi.dwMajorVersion >= 5) && (osvi.dwMinorVersion >= 2) && (VER_NT_WORKSTATION != osvi.wProductType);
  1883. }
  1884. m_cRef = 1;
  1885. m_hwndFrame = NULL;
  1886. m_bOverride = FALSE;
  1887. m_bDirty = FALSE;
  1888. m_bRefocusInit = FALSE;
  1889. m_bArchiveData = FALSE;
  1890. m_bViewIsArchivedData = FALSE;
  1891. m_pScope = NULL;
  1892. m_pConsole = NULL;
  1893. m_hRoot = NULL;
  1894. m_hMachine = NULL;
  1895. m_hUser = NULL;
  1896. m_bRootExpanded = FALSE;
  1897. m_szDisplayName = NULL;
  1898. m_bInitialized = FALSE;
  1899. m_pRSOPQuery = NULL;
  1900. m_pRSOPQueryResults = NULL;
  1901. m_dwLoadFlags = RSOP_NOMSC;
  1902. m_bNamespaceSpecified = FALSE;
  1903. m_dwLoadFlags = RSOP_NOMSC;
  1904. m_bGetExtendedErrorInfo = TRUE;
  1905. m_hRichEdit = LoadLibrary (TEXT("riched20.dll"));
  1906. m_BigBoldFont = NULL;
  1907. m_BoldFont = NULL;
  1908. }
  1909. //-------------------------------------------------------
  1910. CRSOPComponentData::~CRSOPComponentData()
  1911. {
  1912. if (m_szDisplayName)
  1913. {
  1914. delete [] m_szDisplayName;
  1915. }
  1916. if (m_pScope)
  1917. {
  1918. m_pScope->Release();
  1919. }
  1920. if (m_pConsole)
  1921. {
  1922. m_pConsole->Release();
  1923. }
  1924. if (m_hRichEdit)
  1925. {
  1926. FreeLibrary (m_hRichEdit);
  1927. }
  1928. if ( m_BoldFont )
  1929. {
  1930. DeleteObject(m_BoldFont); m_BoldFont = NULL;
  1931. }
  1932. if ( m_BoldFont )
  1933. {
  1934. DeleteObject(m_BigBoldFont); m_BigBoldFont = NULL;
  1935. }
  1936. InterlockedDecrement(&g_cRefThisDll);
  1937. }
  1938. //-------------------------------------------------------
  1939. // CRSOPComponentData object implementation (IUnknown)
  1940. HRESULT CRSOPComponentData::QueryInterface (REFIID riid, void **ppv)
  1941. {
  1942. if (IsEqualIID(riid, IID_IComponentData) || IsEqualIID(riid, IID_IUnknown))
  1943. {
  1944. *ppv = (LPCOMPONENT)this;
  1945. m_cRef++;
  1946. return S_OK;
  1947. }
  1948. else if (IsEqualIID(riid, IID_IExtendPropertySheet2))
  1949. {
  1950. *ppv = (LPEXTENDPROPERTYSHEET)this;
  1951. m_cRef++;
  1952. return S_OK;
  1953. }
  1954. else if (IsEqualIID(riid, IID_IExtendContextMenu))
  1955. {
  1956. *ppv = (LPEXTENDCONTEXTMENU)this;
  1957. m_cRef++;
  1958. return S_OK;
  1959. }
  1960. else if (IsEqualIID(riid, IID_IPersistStreamInit))
  1961. {
  1962. *ppv = (LPPERSISTSTREAMINIT)this;
  1963. m_cRef++;
  1964. return S_OK;
  1965. }
  1966. else if (IsEqualIID(riid, IID_ISnapinHelp))
  1967. {
  1968. *ppv = (LPSNAPINHELP)this;
  1969. m_cRef++;
  1970. return S_OK;
  1971. }
  1972. else
  1973. {
  1974. *ppv = NULL;
  1975. return E_NOINTERFACE;
  1976. }
  1977. }
  1978. //-------------------------------------------------------
  1979. ULONG CRSOPComponentData::AddRef (void)
  1980. {
  1981. return ++m_cRef;
  1982. }
  1983. //-------------------------------------------------------
  1984. ULONG CRSOPComponentData::Release (void)
  1985. {
  1986. if (--m_cRef == 0)
  1987. {
  1988. delete this;
  1989. return 0;
  1990. }
  1991. return m_cRef;
  1992. }
  1993. //-------------------------------------------------------
  1994. // CRSOPComponentData object implementation (IComponentData)
  1995. STDMETHODIMP CRSOPComponentData::Initialize(LPUNKNOWN pUnknown)
  1996. {
  1997. HRESULT hr;
  1998. HBITMAP bmp16x16;
  1999. HBITMAP hbmp32x32;
  2000. LPIMAGELIST lpScopeImage;
  2001. // QI for IConsoleNameSpace
  2002. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace2, (LPVOID *)&m_pScope);
  2003. if (FAILED(hr))
  2004. {
  2005. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Initialize: Failed to QI for IConsoleNameSpace2.")));
  2006. return hr;
  2007. }
  2008. // QI for IConsole
  2009. hr = pUnknown->QueryInterface(IID_IConsole, (LPVOID *)&m_pConsole);
  2010. if (FAILED(hr))
  2011. {
  2012. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Initialize: Failed to QI for IConsole.")));
  2013. m_pScope->Release();
  2014. m_pScope = NULL;
  2015. return hr;
  2016. }
  2017. m_pConsole->GetMainWindow (&m_hwndFrame);
  2018. // Query for the scope imagelist interface
  2019. hr = m_pConsole->QueryScopeImageList(&lpScopeImage);
  2020. if (FAILED(hr))
  2021. {
  2022. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Initialize: Failed to QI for scope imagelist.")));
  2023. m_pScope->Release();
  2024. m_pScope = NULL;
  2025. m_pConsole->Release();
  2026. m_pConsole=NULL;
  2027. return hr;
  2028. }
  2029. // Load the bitmaps from the dll
  2030. bmp16x16=LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_16x16));
  2031. hbmp32x32 = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_32x32));
  2032. // Set the images
  2033. lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR *>(bmp16x16),
  2034. reinterpret_cast<LONG_PTR *>(hbmp32x32),
  2035. 0, RGB(255, 0, 255));
  2036. lpScopeImage->Release();
  2037. return S_OK;
  2038. }
  2039. //-------------------------------------------------------
  2040. STDMETHODIMP CRSOPComponentData::CreateComponent(LPCOMPONENT *ppComponent)
  2041. {
  2042. HRESULT hr;
  2043. CRSOPSnapIn *pSnapIn;
  2044. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::CreateComponent: Entering.")));
  2045. // Initialize
  2046. *ppComponent = NULL;
  2047. // Create the snapin view
  2048. pSnapIn = new CRSOPSnapIn(this);
  2049. if (!pSnapIn)
  2050. {
  2051. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateComponent: Failed to create CRSOPSnapIn.")));
  2052. return E_OUTOFMEMORY;
  2053. }
  2054. // QI for IComponent
  2055. hr = pSnapIn->QueryInterface(IID_IComponent, (LPVOID *)ppComponent);
  2056. pSnapIn->Release(); // release QI
  2057. return hr;
  2058. }
  2059. //-------------------------------------------------------
  2060. STDMETHODIMP CRSOPComponentData::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  2061. LPDATAOBJECT* ppDataObject)
  2062. {
  2063. HRESULT hr = E_NOINTERFACE;
  2064. CRSOPDataObject *pDataObject;
  2065. LPRSOPDATAOBJECT pRSOPDataObject;
  2066. // Create a new DataObject
  2067. pDataObject = new CRSOPDataObject(this); // ref == 1
  2068. if (!pDataObject)
  2069. return E_OUTOFMEMORY;
  2070. // QI for the private RSOPDataObject interface so we can set the cookie
  2071. // and type information.
  2072. hr = pDataObject->QueryInterface(IID_IRSOPDataObject, (LPVOID *)&pRSOPDataObject);
  2073. if (FAILED(hr))
  2074. {
  2075. pDataObject->Release();
  2076. return(hr);
  2077. }
  2078. pRSOPDataObject->SetType(type);
  2079. pRSOPDataObject->SetCookie(cookie);
  2080. pRSOPDataObject->Release();
  2081. // QI for a normal IDataObject to return.
  2082. hr = pDataObject->QueryInterface(IID_IDataObject, (LPVOID *)ppDataObject);
  2083. pDataObject->Release(); // release initial ref
  2084. return hr;
  2085. }
  2086. //-------------------------------------------------------
  2087. STDMETHODIMP CRSOPComponentData::Destroy(VOID)
  2088. {
  2089. HRESULT hr = S_OK;
  2090. if (m_bInitialized)
  2091. {
  2092. if (m_bViewIsArchivedData)
  2093. {
  2094. hr = DeleteArchivedRSOPNamespace();
  2095. }
  2096. else
  2097. {
  2098. if (!m_bNamespaceSpecified) {
  2099. FreeRSOPQueryResults( m_pRSOPQuery, m_pRSOPQueryResults );
  2100. }
  2101. else {
  2102. // freeing results without deleting the namespace
  2103. if (m_pRSOPQueryResults) {
  2104. if (m_pRSOPQueryResults->szWMINameSpace) {
  2105. LocalFree( m_pRSOPQueryResults->szWMINameSpace );
  2106. m_pRSOPQueryResults->szWMINameSpace = NULL;
  2107. }
  2108. LocalFree( m_pRSOPQueryResults );
  2109. m_pRSOPQueryResults = NULL;
  2110. }
  2111. m_bNamespaceSpecified = FALSE;
  2112. }
  2113. FreeRSOPQuery(m_pRSOPQuery);
  2114. m_pRSOPQuery = NULL;
  2115. }
  2116. if (SUCCEEDED(hr))
  2117. {
  2118. m_bInitialized = FALSE;
  2119. }
  2120. }
  2121. if (FAILED(hr))
  2122. {
  2123. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Destroy: Failed to delete namespace with 0x%x"), hr ));
  2124. }
  2125. return hr;
  2126. }
  2127. //-------------------------------------------------------
  2128. STDMETHODIMP CRSOPComponentData::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  2129. {
  2130. HRESULT hr = S_OK;
  2131. switch (event)
  2132. {
  2133. case MMCN_EXPAND:
  2134. if (arg == TRUE)
  2135. {
  2136. HSCOPEITEM hExpandingItem = (HSCOPEITEM)param;
  2137. hr = EnumerateScopePane( hExpandingItem );
  2138. if ( hExpandingItem == m_hRoot )
  2139. {
  2140. m_bRootExpanded = TRUE;
  2141. }
  2142. }
  2143. break;
  2144. case MMCN_PRELOAD:
  2145. if (!m_bRefocusInit)
  2146. {
  2147. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::Notify: Received MMCN_PRELOAD event.")));
  2148. m_bRefocusInit = TRUE;
  2149. m_hRoot = (HSCOPEITEM)arg;
  2150. hr = SetRootNode();
  2151. if ( hr != S_OK )
  2152. {
  2153. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Notify: Setting the root scope item failed with 0x%x"), hr));
  2154. }
  2155. }
  2156. break;
  2157. default:
  2158. break;
  2159. }
  2160. return hr;
  2161. }
  2162. //-------------------------------------------------------
  2163. STDMETHODIMP CRSOPComponentData::GetDisplayInfo(LPSCOPEDATAITEM pItem)
  2164. {
  2165. DWORD dwIndex;
  2166. if (pItem == NULL)
  2167. {
  2168. return E_POINTER;
  2169. }
  2170. if ( ((DWORD) pItem->lParam == 0) && (m_szDisplayName != NULL) )
  2171. {
  2172. pItem->displayname = m_szDisplayName;
  2173. return S_OK;
  2174. }
  2175. // Find item
  2176. for (dwIndex = 0; dwIndex < g_dwNameSpaceItems; dwIndex++)
  2177. {
  2178. if ( g_RsopNameSpace[dwIndex].dwID == (DWORD) pItem->lParam )
  2179. {
  2180. break;
  2181. }
  2182. }
  2183. if (dwIndex == g_dwNameSpaceItems)
  2184. {
  2185. pItem->displayname = NULL;
  2186. }
  2187. else
  2188. {
  2189. pItem->displayname = g_RsopNameSpace[dwIndex].szDisplayName;
  2190. }
  2191. return S_OK;
  2192. }
  2193. //-------------------------------------------------------
  2194. STDMETHODIMP CRSOPComponentData::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  2195. {
  2196. HRESULT hr = S_FALSE;
  2197. LPRSOPDATAOBJECT pRSOPDataObjectA, pRSOPDataObjectB;
  2198. MMC_COOKIE cookie1, cookie2;
  2199. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  2200. return E_POINTER;
  2201. //
  2202. // QI for the private RSOPDataObject interface
  2203. //
  2204. if (FAILED(lpDataObjectA->QueryInterface(IID_IRSOPDataObject,
  2205. (LPVOID *)&pRSOPDataObjectA)))
  2206. {
  2207. return S_FALSE;
  2208. }
  2209. if (FAILED(lpDataObjectB->QueryInterface(IID_IRSOPDataObject,
  2210. (LPVOID *)&pRSOPDataObjectB)))
  2211. {
  2212. pRSOPDataObjectA->Release();
  2213. return S_FALSE;
  2214. }
  2215. pRSOPDataObjectA->GetCookie(&cookie1);
  2216. pRSOPDataObjectB->GetCookie(&cookie2);
  2217. if (cookie1 == cookie2)
  2218. {
  2219. hr = S_OK;
  2220. }
  2221. pRSOPDataObjectA->Release();
  2222. pRSOPDataObjectB->Release();
  2223. return hr;
  2224. }
  2225. //-------------------------------------------------------
  2226. // IComponentData helper methods
  2227. HRESULT CRSOPComponentData::SetRootNode()
  2228. {
  2229. SCOPEDATAITEM item;
  2230. ZeroMemory (&item, sizeof(SCOPEDATAITEM));
  2231. item.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE | SDI_CHILDREN;
  2232. item.displayname = MMC_CALLBACK;
  2233. if (m_bInitialized)
  2234. {
  2235. item.cChildren = 1;
  2236. if (m_CSELists.GetUserGPCoreError() || m_CSELists.GetComputerGPCoreError())
  2237. {
  2238. item.nImage = 3;
  2239. item.nOpenImage = 3;
  2240. }
  2241. else if (m_CSELists.GetUserCSEError() || m_CSELists.GetComputerCSEError()
  2242. || m_pRSOPQueryResults->bUserDeniedAccess
  2243. || m_pRSOPQueryResults->bComputerDeniedAccess )
  2244. {
  2245. item.nImage = 11;
  2246. item.nOpenImage = 11;
  2247. }
  2248. else
  2249. {
  2250. item.nImage = 2;
  2251. item.nOpenImage = 2;
  2252. }
  2253. }
  2254. else
  2255. {
  2256. item.cChildren = 0;
  2257. item.nImage = 2;
  2258. item.nOpenImage = 2;
  2259. }
  2260. item.ID = m_hRoot;
  2261. return m_pScope->SetItem (&item);
  2262. }
  2263. //-------------------------------------------------------
  2264. HRESULT CRSOPComponentData::EnumerateScopePane ( HSCOPEITEM hParent )
  2265. {
  2266. SCOPEDATAITEM item;
  2267. HRESULT hr;
  2268. DWORD dwIndex, i;
  2269. if ( m_hRoot == NULL )
  2270. {
  2271. m_hRoot = hParent;
  2272. if (!m_bRefocusInit)
  2273. {
  2274. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::EnumerateScopePane: Resetting the root node")));
  2275. m_bRefocusInit = TRUE;
  2276. hr = SetRootNode();
  2277. if ( hr != S_OK )
  2278. {
  2279. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EnumerateScopePane: Setting the root scope item failed with 0x%x"), hr));
  2280. return E_FAIL;
  2281. }
  2282. }
  2283. }
  2284. if (!m_bInitialized)
  2285. {
  2286. return S_OK;
  2287. }
  2288. if (m_hRoot == hParent)
  2289. {
  2290. dwIndex = 0;
  2291. }
  2292. else
  2293. {
  2294. item.mask = SDI_PARAM;
  2295. item.ID = hParent;
  2296. hr = m_pScope->GetItem (&item);
  2297. if (FAILED(hr))
  2298. return hr;
  2299. dwIndex = (DWORD)item.lParam;
  2300. }
  2301. // RM: Make sure that parent item is expanded before inserting any new scope items
  2302. m_pScope->Expand( hParent );
  2303. for (i = 0; i < g_dwNameSpaceItems; i++)
  2304. {
  2305. if (g_RsopNameSpace[i].dwParent == dwIndex)
  2306. {
  2307. BOOL bAdd = TRUE;
  2308. if (g_RsopNameSpace[i].dwID == 1)
  2309. {
  2310. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  2311. {
  2312. if ( (m_pRSOPQuery->pComputer->szName == NULL) && (m_pRSOPQuery->pComputer->szSOM == NULL) )
  2313. {
  2314. bAdd = FALSE;
  2315. }
  2316. }
  2317. else
  2318. {
  2319. if ( m_pRSOPQuery->szComputerName == NULL )
  2320. {
  2321. bAdd = FALSE;
  2322. }
  2323. }
  2324. if ( (m_pRSOPQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY )
  2325. {
  2326. bAdd = FALSE;
  2327. }
  2328. if ( m_pRSOPQueryResults->bNoComputerPolicyData )
  2329. {
  2330. bAdd = FALSE;
  2331. }
  2332. if ( m_pRSOPQueryResults->bComputerDeniedAccess )
  2333. {
  2334. bAdd = FALSE;
  2335. }
  2336. }
  2337. if (g_RsopNameSpace[i].dwID == 2)
  2338. {
  2339. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  2340. {
  2341. if ( m_pRSOPQuery->LoopbackMode == RSOP_LOOPBACK_NONE )
  2342. {
  2343. if ( (m_pRSOPQuery->pUser->szName == NULL) && (m_pRSOPQuery->pUser->szSOM == NULL) )
  2344. {
  2345. bAdd = FALSE;
  2346. }
  2347. else if ( (m_pRSOPQuery->dwFlags & RSOP_NO_USER_POLICY) == RSOP_NO_USER_POLICY )
  2348. {
  2349. bAdd = FALSE;
  2350. }
  2351. }
  2352. }
  2353. else // RSOP_LOGGING_MODE
  2354. {
  2355. if ( (m_pRSOPQuery->szUserSid == NULL) && (m_pRSOPQuery->szUserName == NULL) )
  2356. {
  2357. bAdd = FALSE;
  2358. }
  2359. else if ( (m_pRSOPQuery->dwFlags & RSOP_NO_USER_POLICY) == RSOP_NO_USER_POLICY )
  2360. {
  2361. bAdd = FALSE;
  2362. }
  2363. }
  2364. if ( m_pRSOPQueryResults->bNoUserPolicyData)
  2365. {
  2366. bAdd = FALSE;
  2367. }
  2368. if ( m_pRSOPQueryResults->bUserDeniedAccess )
  2369. {
  2370. bAdd = FALSE;
  2371. }
  2372. }
  2373. if (bAdd)
  2374. {
  2375. INT iIcon, iOpenIcon;
  2376. iIcon = g_RsopNameSpace[i].iIcon;
  2377. iOpenIcon = g_RsopNameSpace[i].iOpenIcon;
  2378. if ((i == 1) && m_CSELists.GetComputerGPCoreError())
  2379. {
  2380. iIcon = 12;
  2381. iOpenIcon = 12;
  2382. }
  2383. else if ((i == 1) && (ComputerCSEErrorExists() || ComputerGPCoreWarningExists()))
  2384. {
  2385. iIcon = 14;
  2386. iOpenIcon = 14;
  2387. }
  2388. else if ((i == 2) && UserGPCoreErrorExists())
  2389. {
  2390. iIcon = 13;
  2391. iOpenIcon = 13;
  2392. }
  2393. else if ((i == 2) && (UserCSEErrorExists() || UserGPCoreWarningExists()))
  2394. {
  2395. iIcon = 15;
  2396. iOpenIcon = 15;
  2397. }
  2398. item.mask = SDI_STR | SDI_STATE | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM | SDI_CHILDREN;
  2399. item.displayname = MMC_CALLBACK;
  2400. item.nImage = iIcon;
  2401. item.nOpenImage = iOpenIcon;
  2402. item.nState = 0;
  2403. item.cChildren = g_RsopNameSpace[i].cChildren;
  2404. item.lParam = g_RsopNameSpace[i].dwID;
  2405. item.relativeID = hParent;
  2406. if (SUCCEEDED(m_pScope->InsertItem (&item)))
  2407. {
  2408. if (i == 1)
  2409. {
  2410. m_hMachine = item.ID;
  2411. }
  2412. else if (i == 2)
  2413. {
  2414. m_hUser = item.ID;
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. return S_OK;
  2421. }
  2422. //-------------------------------------------------------
  2423. // CRSOPComponentData object implementation (IExtendPropertySheet2)
  2424. STDMETHODIMP CRSOPComponentData::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  2425. LONG_PTR handle, LPDATAOBJECT lpDataObject)
  2426. {
  2427. HRESULT hr = E_FAIL;
  2428. PROPSHEETPAGE psp;
  2429. HPROPSHEETPAGE hPage;
  2430. // Set up fonts
  2431. hr = SetupFonts();
  2432. if (FAILED(hr))
  2433. {
  2434. return hr;
  2435. }
  2436. // Now check which property page to show
  2437. BOOL fRoot, fMachine, fUser;
  2438. hr = IsNode(lpDataObject, 0); // check for root node
  2439. fRoot = (S_OK == hr);
  2440. hr = IsNode(lpDataObject, 1); // check for machine node
  2441. fMachine = (S_OK == hr);
  2442. hr = IsNode(lpDataObject, 2); // check for user
  2443. fUser = (S_OK == hr);
  2444. hr = S_OK;
  2445. if (fMachine || fUser)
  2446. {
  2447. // Create the GPO property sheet
  2448. psp.dwSize = sizeof(PROPSHEETPAGE);
  2449. psp.dwFlags = 0;
  2450. psp.hInstance = g_hInstance;
  2451. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_GPOLIST);
  2452. psp.pfnDlgProc = fMachine ? RSOPGPOListMachineProc : RSOPGPOListUserProc;
  2453. psp.lParam = (LPARAM) this;
  2454. hPage = CreatePropertySheetPage(&psp);
  2455. if (!hPage)
  2456. {
  2457. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreatePropertyPages: Failed to create property sheet page with %d."),
  2458. GetLastError()));
  2459. return E_FAIL;
  2460. }
  2461. hr = lpProvider->AddPage(hPage);
  2462. // Create the Error information property sheet
  2463. psp.dwSize = sizeof(PROPSHEETPAGE);
  2464. psp.dwFlags = 0;
  2465. psp.hInstance = g_hInstance;
  2466. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_ERRORS);
  2467. psp.pfnDlgProc = fMachine ? RSOPErrorsMachineProc : RSOPErrorsUserProc;
  2468. psp.lParam = (LPARAM) this;
  2469. hPage = CreatePropertySheetPage(&psp);
  2470. if (!hPage)
  2471. {
  2472. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreatePropertyPages: Failed to create property sheet page with %d."),
  2473. GetLastError()));
  2474. return E_FAIL;
  2475. }
  2476. hr = lpProvider->AddPage(hPage);
  2477. }
  2478. if (fRoot)
  2479. {
  2480. // Create the GPO property sheet
  2481. psp.dwSize = sizeof(PROPSHEETPAGE);
  2482. psp.dwFlags = 0;
  2483. psp.hInstance = g_hInstance;
  2484. psp.pszTemplate = MAKEINTRESOURCE(IDD_RSOP_QUERY);
  2485. psp.pfnDlgProc = QueryDlgProc;
  2486. psp.lParam = (LPARAM) this;
  2487. hPage = CreatePropertySheetPage(&psp);
  2488. if (!hPage)
  2489. {
  2490. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreatePropertyPages: Failed to create property sheet page with %d."),
  2491. GetLastError()));
  2492. return E_FAIL;
  2493. }
  2494. hr = lpProvider->AddPage(hPage);
  2495. }
  2496. return hr;
  2497. // RM: Removed! return SetupPropertyPages(RSOP_NOMSC, lpProvider, handle, lpDataObject);
  2498. }
  2499. //-------------------------------------------------------
  2500. STDMETHODIMP CRSOPComponentData::QueryPagesFor(LPDATAOBJECT lpDataObject)
  2501. {
  2502. HRESULT hr;
  2503. if ( !m_bInitialized )
  2504. {
  2505. hr = S_FALSE;
  2506. }
  2507. else
  2508. {
  2509. hr = IsSnapInManager(lpDataObject);
  2510. if (hr != S_OK)
  2511. {
  2512. hr = IsNode(lpDataObject, 0); // check for root
  2513. if (S_OK == hr)
  2514. {
  2515. return hr;
  2516. }
  2517. hr = IsNode(lpDataObject, 1); // check for machine
  2518. if (S_OK == hr)
  2519. {
  2520. return hr;
  2521. }
  2522. hr = IsNode(lpDataObject, 2); // check for user
  2523. if (S_OK == hr)
  2524. {
  2525. return hr;
  2526. }
  2527. hr = E_FAIL;
  2528. }
  2529. }
  2530. return hr;
  2531. }
  2532. //-------------------------------------------------------
  2533. STDMETHODIMP CRSOPComponentData::GetWatermarks(LPDATAOBJECT lpIDataObject,
  2534. HBITMAP* lphWatermark,
  2535. HBITMAP* lphHeader,
  2536. HPALETTE* lphPalette,
  2537. BOOL* pbStretch)
  2538. {
  2539. *lphPalette = NULL;
  2540. *lphHeader = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_HEADER));
  2541. *lphWatermark = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_WIZARD));;
  2542. *pbStretch = TRUE;
  2543. return S_OK;
  2544. }
  2545. //-------------------------------------------------------
  2546. // IExtendPropertySheet2 helper methods
  2547. HRESULT CRSOPComponentData::IsSnapInManager (LPDATAOBJECT lpDataObject)
  2548. {
  2549. HRESULT hr = S_FALSE;
  2550. LPRSOPDATAOBJECT pRSOPDataObject;
  2551. DATA_OBJECT_TYPES type;
  2552. // We can determine if this is a RSOP DataObject by trying to
  2553. // QI for the private IRSOPDataObject interface. If found,
  2554. // it belongs to us.
  2555. if (SUCCEEDED(lpDataObject->QueryInterface(IID_IRSOPDataObject,
  2556. (LPVOID *)&pRSOPDataObject)))
  2557. {
  2558. // This is a GPO object. Now see if is a scope pane
  2559. // data object. We only want to display the property
  2560. // sheet for the scope pane.
  2561. if (SUCCEEDED(pRSOPDataObject->GetType(&type)))
  2562. {
  2563. if (type == CCT_SNAPIN_MANAGER)
  2564. {
  2565. hr = S_OK;
  2566. }
  2567. }
  2568. pRSOPDataObject->Release();
  2569. }
  2570. return(hr);
  2571. }
  2572. //-------------------------------------------------------
  2573. HRESULT CRSOPComponentData::IsNode (LPDATAOBJECT lpDataObject, MMC_COOKIE cookie)
  2574. {
  2575. HRESULT hr = S_FALSE;
  2576. LPRSOPDATAOBJECT pRSOPDataObject;
  2577. DATA_OBJECT_TYPES type;
  2578. MMC_COOKIE testcookie;
  2579. // This is a check for the special case where the Message OCX result pane
  2580. // is active and the snapin is not yet initialized. So, if the query is
  2581. // to check whether this is the root node, we can return TRUE, else return
  2582. // FALSE.
  2583. if ( IS_SPECIAL_DATAOBJECT(lpDataObject) )
  2584. {
  2585. ASSERT( !m_bInitialized );
  2586. if ( cookie == 0 )
  2587. {
  2588. hr = S_OK;
  2589. }
  2590. }
  2591. // We can determine if this is a GPO DataObject by trying to
  2592. // QI for the private IGPEDataObject interface. If found,
  2593. // it belongs to us.
  2594. else if (SUCCEEDED(lpDataObject->QueryInterface(IID_IRSOPDataObject,
  2595. (LPVOID *)&pRSOPDataObject)))
  2596. {
  2597. pRSOPDataObject->GetType(&type);
  2598. pRSOPDataObject->GetCookie(&testcookie);
  2599. if ((type == CCT_SCOPE) && (cookie == testcookie))
  2600. {
  2601. hr = S_OK;
  2602. }
  2603. pRSOPDataObject->Release();
  2604. }
  2605. return (hr);
  2606. }
  2607. //-------------------------------------------------------
  2608. // CRSOPComponentData object implementation (IExtendContextMenu)
  2609. STDMETHODIMP CRSOPComponentData::AddMenuItems(LPDATAOBJECT piDataObject,
  2610. LPCONTEXTMENUCALLBACK pCallback,
  2611. LONG *pInsertionAllowed)
  2612. {
  2613. HRESULT hr = S_OK;
  2614. TCHAR szMenuItem[100];
  2615. TCHAR szDescription[250];
  2616. CONTEXTMENUITEM item;
  2617. if (IsNode(piDataObject, 0) == S_OK)
  2618. {
  2619. if ( (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP) == CCM_INSERTIONALLOWED_TOP)
  2620. {
  2621. // Add "Rerun query..." menu option
  2622. if ( m_bInitialized )
  2623. {
  2624. // Changing the query is only supported in post XP builds
  2625. if ( !m_bNamespaceSpecified && m_bPostXPBuild )
  2626. {
  2627. LoadString (g_hInstance, IDS_RSOP_CHANGEQUERY, szMenuItem, 100);
  2628. LoadString (g_hInstance, IDS_RSOP_CHANGEQUERYDESC, szDescription, 250);
  2629. item.strName = szMenuItem;
  2630. item.strStatusBarText = szDescription;
  2631. item.lCommandID = IDM_GENERATE_RSOP;
  2632. item.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  2633. item.fFlags = 0;
  2634. item.fSpecialFlags = 0;
  2635. hr = pCallback->AddItem(&item);
  2636. }
  2637. }
  2638. else
  2639. {
  2640. LoadString (g_hInstance, IDS_RSOP_RUNQUERY, szMenuItem, 100);
  2641. LoadString (g_hInstance, IDS_RSOP_RUNQUERYDESC, szDescription, 250);
  2642. item.strName = szMenuItem;
  2643. item.strStatusBarText = szDescription;
  2644. item.lCommandID = IDM_GENERATE_RSOP;
  2645. item.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  2646. item.fFlags = 0;
  2647. item.fSpecialFlags = 0;
  2648. hr = pCallback->AddItem(&item);
  2649. }
  2650. // Refreshing the query is only supported in post XP builds
  2651. if ( m_bInitialized && (!m_bNamespaceSpecified) && m_bPostXPBuild )
  2652. {
  2653. LoadString (g_hInstance, IDS_RSOP_REFRESHQUERY, szMenuItem, 100);
  2654. LoadString (g_hInstance, IDS_RSOP_REFRESHQUERYDESC, szDescription, 250);
  2655. item.strName = szMenuItem;
  2656. item.strStatusBarText = szDescription;
  2657. item.lCommandID = IDM_REFRESH_RSOP;
  2658. item.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  2659. item.fFlags = 0;
  2660. item.fSpecialFlags = 0;
  2661. hr = pCallback->AddItem(&item);
  2662. }
  2663. }
  2664. if ( (*pInsertionAllowed & CCM_INSERTIONALLOWED_VIEW) == CCM_INSERTIONALLOWED_VIEW)
  2665. {
  2666. // Add "Archive data" menu option
  2667. LoadString (g_hInstance, IDS_ARCHIVEDATA, szMenuItem, 100);
  2668. LoadString (g_hInstance, IDS_ARCHIVEDATADESC, szDescription, 250);
  2669. item.strName = szMenuItem;
  2670. item.strStatusBarText = szDescription;
  2671. item.lCommandID = IDM_ARCHIVEDATA;
  2672. item.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_VIEW;
  2673. item.fFlags = m_bArchiveData ? MFS_CHECKED : 0;
  2674. item.fSpecialFlags = 0;
  2675. hr = pCallback->AddItem(&item);
  2676. }
  2677. }
  2678. return(hr);
  2679. }
  2680. //-------------------------------------------------------
  2681. STDMETHODIMP CRSOPComponentData::Command(LONG lCommandID, LPDATAOBJECT piDataObject)
  2682. {
  2683. TCHAR szCaption[100];
  2684. TCHAR szMessage[300];
  2685. INT iRet;
  2686. switch (lCommandID)
  2687. {
  2688. case IDM_ARCHIVEDATA:
  2689. {
  2690. m_bArchiveData = !m_bArchiveData;
  2691. SetDirty();
  2692. }
  2693. break;
  2694. case IDM_GENERATE_RSOP:
  2695. {
  2696. HRESULT hr = InitializeRSOP( TRUE );
  2697. if ( FAILED(hr) )
  2698. {
  2699. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Command: Failed to run RSOP query with 0x%x"), hr ));
  2700. }
  2701. }
  2702. break;
  2703. case IDM_REFRESH_RSOP:
  2704. {
  2705. if ( m_bInitialized )
  2706. {
  2707. HRESULT hr = InitializeRSOP( FALSE );
  2708. if ( FAILED(hr) )
  2709. {
  2710. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Command: Failed to run RSOP query with 0x%x"), hr ));
  2711. }
  2712. }
  2713. }
  2714. break;
  2715. }
  2716. return S_OK;
  2717. }
  2718. //-------------------------------------------------------
  2719. // CRSOPComponentData object implementation (IPersistStreamInit)
  2720. STDMETHODIMP CRSOPComponentData::GetClassID(CLSID *pClassID)
  2721. {
  2722. if (!pClassID)
  2723. {
  2724. return E_FAIL;
  2725. }
  2726. *pClassID = CLSID_RSOPSnapIn;
  2727. return S_OK;
  2728. }
  2729. //-------------------------------------------------------
  2730. STDMETHODIMP CRSOPComponentData::IsDirty(VOID)
  2731. {
  2732. return ThisIsDirty() ? S_OK : S_FALSE;
  2733. }
  2734. //-------------------------------------------------------
  2735. //-------------------------------------------------------
  2736. HRESULT
  2737. ExtractSecurityGroups(
  2738. IN IWbemClassObject *pSessionInst,
  2739. IN LPRSOP_QUERY_TARGET pRsopQueryTarget)
  2740. {
  2741. LPWSTR *szSecGroupSids;
  2742. HRESULT hr = S_OK;
  2743. // get the secgrps of the Comp, if available
  2744. GetParameter(pSessionInst,
  2745. L"SecurityGroups",
  2746. szSecGroupSids,
  2747. (pRsopQueryTarget->dwSecurityGroupCount));
  2748. pRsopQueryTarget->adwSecurityGroupsAttr = (DWORD *)LocalAlloc(LPTR,
  2749. sizeof(DWORD)*((pRsopQueryTarget->dwSecurityGroupCount)));
  2750. if (!pRsopQueryTarget->adwSecurityGroupsAttr)
  2751. {
  2752. hr = E_OUTOFMEMORY;
  2753. goto Cleanup;
  2754. }
  2755. pRsopQueryTarget->aszSecurityGroups = (LPWSTR *)LocalAlloc(LPTR,
  2756. sizeof(LPWSTR)*((pRsopQueryTarget->dwSecurityGroupCount)));
  2757. if (!pRsopQueryTarget->aszSecurityGroups)
  2758. {
  2759. hr = E_OUTOFMEMORY;
  2760. goto Cleanup;
  2761. }
  2762. for (DWORD i = 0; i < (pRsopQueryTarget->dwSecurityGroupCount); i++)
  2763. {
  2764. (pRsopQueryTarget->adwSecurityGroupsAttr)[i] = 0;
  2765. if (!GetUserNameFromStringSid(szSecGroupSids[i], &((pRsopQueryTarget->aszSecurityGroups)[i])))
  2766. {
  2767. ULONG ulNoChars = lstrlen(szSecGroupSids[i])+1;
  2768. (pRsopQueryTarget->aszSecurityGroups)[i] = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*ulNoChars);
  2769. if (!((pRsopQueryTarget->aszSecurityGroups)[i]))
  2770. {
  2771. hr = E_OUTOFMEMORY;
  2772. goto Cleanup;
  2773. }
  2774. hr = StringCchCopy((pRsopQueryTarget->aszSecurityGroups)[i], ulNoChars, szSecGroupSids[i]);
  2775. ASSERT(SUCCEEDED(hr));
  2776. }
  2777. }
  2778. hr = S_OK;
  2779. Cleanup:
  2780. if (szSecGroupSids)
  2781. {
  2782. for (DWORD i = 0; i < (pRsopQueryTarget->dwSecurityGroupCount); i++)
  2783. {
  2784. if (szSecGroupSids[i])
  2785. {
  2786. LocalFree(szSecGroupSids[i]);
  2787. }
  2788. }
  2789. LocalFree(szSecGroupSids);
  2790. }
  2791. if (FAILED(hr))
  2792. {
  2793. if (pRsopQueryTarget->adwSecurityGroupsAttr)
  2794. {
  2795. LocalFree(pRsopQueryTarget->adwSecurityGroupsAttr);
  2796. pRsopQueryTarget->adwSecurityGroupsAttr = NULL;
  2797. }
  2798. if (pRsopQueryTarget->aszSecurityGroups)
  2799. {
  2800. for (DWORD i = 0; i < (pRsopQueryTarget->dwSecurityGroupCount); i++)
  2801. {
  2802. if ((pRsopQueryTarget->aszSecurityGroups)[i])
  2803. {
  2804. LocalFree((pRsopQueryTarget->aszSecurityGroups)[i]);
  2805. }
  2806. }
  2807. LocalFree(pRsopQueryTarget->aszSecurityGroups);
  2808. pRsopQueryTarget->aszSecurityGroups = NULL;
  2809. pRsopQueryTarget->dwSecurityGroupCount = 0;
  2810. }
  2811. }
  2812. return hr;
  2813. }
  2814. //-------------------------------------------------------
  2815. //-------------------------------------------------------
  2816. #define USER_SUBNAMESPACE L"User"
  2817. #define COMP_SUBNAMESPACE L"Computer"
  2818. #define RSOP_SESSION_PATH L"RSOP_Session.id=\"Session1\""
  2819. HRESULT
  2820. CRSOPComponentData::EvaluateParameters(
  2821. IN LPWSTR szNamespace,
  2822. IN LPWSTR szTarget)
  2823. /*++
  2824. Routine Description:
  2825. Given the namespace name and the DC that is passed in as a commandline
  2826. argument, this function will compute the effective parameters that were
  2827. used to get the result.
  2828. Arguments:
  2829. [in] szNamespace - Namespace which needs to be read to get the parameters
  2830. [in] szTarget - This can be DC. (in case of planning mode there is currently no way to
  2831. to determine which dc was used to generate the planning mode
  2832. data from the namespace. So we need a separate parameter)
  2833. - or logging mode target computer. (in case of logging mode there is
  2834. currently no way to to determine which machine was used to generate
  2835. the logging mode data. So we need a separate parameter)
  2836. [out] m_pRsopQuery - Returns an allocated RsopQuery that corresponds to the parameters
  2837. for this rsop namespace
  2838. [out] m_pRsopQueryResults - Returns the query result that corresponds to the result elements
  2839. Return Value:
  2840. S_OK on success.
  2841. On failure the corresponding error code will be returned.
  2842. Any API calls that are made in this function might fail and these error
  2843. codes will be returned directly.
  2844. Note:
  2845. This will just return parameters to the closest approximation.
  2846. ie. this will return the minimal sets of parameters that would get this result.
  2847. for example: if wmi filters A, B & C were specified in a planning mode query and
  2848. there were gpos with filters A & B, these will return just A & B (and not C)
  2849. We will always return security groups whether or not the user had specified these in
  2850. the original query.
  2851. We will return the parent som for the user/computer in all cases
  2852. --*/
  2853. {
  2854. HRESULT hr = S_OK;
  2855. IWbemLocator *pLocator = NULL;
  2856. IWbemServices *pUserNamespace = NULL;
  2857. IWbemServices *pCompNamespace = NULL;
  2858. LPWSTR szUserNamespace = NULL;
  2859. LPWSTR szCompNamespace = NULL;
  2860. LPWSTR lpEnd = NULL;
  2861. BSTR bstrNamespace = NULL;
  2862. BSTR bstrSessionInstPath = NULL;
  2863. IWbemClassObject *pUserSessionInst = NULL;
  2864. IWbemClassObject *pCompSessionInst = NULL;
  2865. BOOL bPlanning = TRUE;
  2866. if (!szTarget)
  2867. {
  2868. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Target name was not specified") ) );
  2869. return E_INVALIDARG;
  2870. }
  2871. DebugMsg( (DM_VERBOSE, TEXT("CRSOPComponentData::EvaluateParameters namespace=<%s>, target=<%s>"), szNamespace, szTarget) );
  2872. hr = CoCreateInstance(CLSID_WbemLocator,
  2873. 0,
  2874. CLSCTX_INPROC_SERVER,
  2875. IID_IWbemLocator,
  2876. (LPVOID *) &pLocator);
  2877. if (FAILED(hr))
  2878. {
  2879. goto Cleanup;
  2880. }
  2881. bstrSessionInstPath = SysAllocString(RSOP_SESSION_PATH);
  2882. if (!bstrSessionInstPath)
  2883. {
  2884. goto Cleanup;
  2885. }
  2886. // allocate memory for the original namespace followed by "\" and computer or user
  2887. ULONG ulNoChars = lstrlen(szNamespace) + lstrlen(USER_SUBNAMESPACE) + 5;
  2888. szUserNamespace = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*ulNoChars);
  2889. if (!szUserNamespace)
  2890. {
  2891. hr = E_OUTOFMEMORY;
  2892. goto Cleanup;
  2893. }
  2894. hr = StringCchCopy (szUserNamespace, ulNoChars, szNamespace);
  2895. ASSERT(SUCCEEDED(hr));
  2896. lpEnd = CheckSlash(szUserNamespace);
  2897. //
  2898. // first the user namespace
  2899. //
  2900. hr = StringCchCat(szUserNamespace, ulNoChars, USER_SUBNAMESPACE);
  2901. if (FAILED(hr))
  2902. {
  2903. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Could not copy user namespace with 0x%x"), hr));
  2904. goto Cleanup;
  2905. }
  2906. bstrNamespace = SysAllocString(szUserNamespace);
  2907. if (!bstrNamespace)
  2908. {
  2909. hr = E_OUTOFMEMORY;
  2910. goto Cleanup;
  2911. }
  2912. hr = pLocator->ConnectServer(bstrNamespace,
  2913. NULL,
  2914. NULL,
  2915. NULL,
  2916. 0,
  2917. NULL,
  2918. NULL,
  2919. &pUserNamespace);
  2920. if (FAILED(hr))
  2921. {
  2922. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to connect to user namespace with 0x%x"), hr));
  2923. goto Cleanup;
  2924. }
  2925. hr = pUserNamespace->GetObject(bstrSessionInstPath,
  2926. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  2927. NULL,
  2928. &pUserSessionInst,
  2929. NULL);
  2930. if (FAILED(hr))
  2931. {
  2932. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get session obj for user namespace with 0x%x"), hr));
  2933. goto Cleanup;
  2934. }
  2935. //
  2936. // Now computer
  2937. //
  2938. if (bstrNamespace)
  2939. {
  2940. SysFreeString(bstrNamespace);
  2941. bstrNamespace = NULL;
  2942. }
  2943. // allocate memory for the original namespace followed by "\" and computer or user
  2944. ulNoChars = lstrlen(szNamespace) + lstrlen(COMP_SUBNAMESPACE) + 5;
  2945. szCompNamespace = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*ulNoChars);
  2946. if (!szCompNamespace)
  2947. {
  2948. hr = E_OUTOFMEMORY;
  2949. goto Cleanup;
  2950. }
  2951. hr = StringCchCopy (szCompNamespace, ulNoChars, szNamespace);
  2952. ASSERT(SUCCEEDED(hr));
  2953. lpEnd = CheckSlash(szCompNamespace);
  2954. //
  2955. // now the Comp namespace
  2956. //
  2957. hr = StringCchCat(szCompNamespace, ulNoChars, COMP_SUBNAMESPACE);
  2958. ASSERT(SUCCEEDED(hr));
  2959. bstrNamespace = SysAllocString(szCompNamespace);
  2960. if (!bstrNamespace)
  2961. {
  2962. hr = E_OUTOFMEMORY;
  2963. goto Cleanup;
  2964. }
  2965. hr = pLocator->ConnectServer(bstrNamespace,
  2966. NULL,
  2967. NULL,
  2968. NULL,
  2969. 0,
  2970. NULL,
  2971. NULL,
  2972. &pCompNamespace);
  2973. if (FAILED(hr))
  2974. {
  2975. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to connect to computer namespace with 0x%x"), hr));
  2976. goto Cleanup;
  2977. }
  2978. hr = pCompNamespace->GetObject(bstrSessionInstPath,
  2979. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  2980. NULL,
  2981. &pCompSessionInst,
  2982. NULL);
  2983. if (FAILED(hr))
  2984. {
  2985. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get session obj for computer namespace with 0x%x"), hr));
  2986. goto Cleanup;
  2987. }
  2988. //
  2989. // now check whether we have planning mode flag in either user/computer
  2990. // if it is not in either then we can assume it to be in logging mode
  2991. // otherwise we will assume it to be in planning mode
  2992. //
  2993. ULONG ulUserFlags;
  2994. ULONG ulCompFlags;
  2995. // Get the flags parameter for user
  2996. hr = GetParameter(pUserSessionInst, TEXT("flags"), ulUserFlags);
  2997. if (FAILED(hr))
  2998. {
  2999. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get flags param with 0x%x"), hr));
  3000. goto Cleanup;
  3001. }
  3002. // Get the flags parameter for computer
  3003. hr = GetParameter(pCompSessionInst, TEXT("flags"), ulCompFlags);
  3004. if (FAILED(hr))
  3005. {
  3006. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get flags param with 0x%x"), hr));
  3007. goto Cleanup;
  3008. }
  3009. if ((ulUserFlags & FLAG_PLANNING_MODE) || (ulCompFlags & FLAG_PLANNING_MODE))
  3010. {
  3011. bPlanning = TRUE;
  3012. if ( !ChangeRSOPQueryType( m_pRSOPQuery, RSOP_PLANNING_MODE ) )
  3013. {
  3014. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to change query type") ) );
  3015. hr = E_FAIL;
  3016. goto Cleanup;
  3017. }
  3018. }
  3019. else
  3020. {
  3021. bPlanning = FALSE;
  3022. if ( !ChangeRSOPQueryType( m_pRSOPQuery, RSOP_LOGGING_MODE ) )
  3023. {
  3024. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to change query type") ) );
  3025. hr = E_FAIL;
  3026. goto Cleanup;
  3027. }
  3028. }
  3029. // rsop query results
  3030. m_pRSOPQueryResults = (LPRSOP_QUERY_RESULTS)LocalAlloc( LPTR, sizeof(RSOP_QUERY_RESULTS) );
  3031. if ( m_pRSOPQueryResults == NULL )
  3032. {
  3033. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to create RSOP_QUERY_RESULTS.")) );
  3034. hr = E_OUTOFMEMORY;
  3035. goto Cleanup;
  3036. }
  3037. ulNoChars = 1+lstrlen(szNamespace);
  3038. m_pRSOPQueryResults->szWMINameSpace = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*ulNoChars);
  3039. if (!(m_pRSOPQueryResults->szWMINameSpace))
  3040. {
  3041. hr = E_OUTOFMEMORY;
  3042. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to allocate memory for namespace with 0x%x"), hr));
  3043. goto Cleanup;
  3044. }
  3045. hr = StringCchCopy(m_pRSOPQueryResults->szWMINameSpace, ulNoChars, szNamespace);
  3046. ASSERT(SUCCEEDED(hr));
  3047. m_pRSOPQuery->dwFlags = RSOP_NO_WELCOME;
  3048. m_pRSOPQuery->UIMode = RSOP_UI_NONE;
  3049. if (bPlanning)
  3050. {
  3051. ULONG ulFlags = 0;
  3052. IWbemClassObject *pSessionInst = NULL;
  3053. BOOL bUserSpecified = FALSE;
  3054. BOOL bCompSpecified = FALSE;
  3055. if (ulUserFlags & FLAG_PLANNING_MODE)
  3056. {
  3057. if (ulUserFlags & FLAG_LOOPBACK_MERGE)
  3058. {
  3059. m_pRSOPQuery->LoopbackMode = RSOP_LOOPBACK_MERGE;
  3060. }
  3061. else if (ulUserFlags & FLAG_LOOPBACK_REPLACE)
  3062. {
  3063. m_pRSOPQuery->LoopbackMode = RSOP_LOOPBACK_REPLACE;
  3064. }
  3065. else
  3066. {
  3067. m_pRSOPQuery->LoopbackMode = RSOP_LOOPBACK_NONE;
  3068. }
  3069. //
  3070. // User has data specified. so we will use user to update information
  3071. //
  3072. ulFlags = ulUserFlags;
  3073. pSessionInst = pUserSessionInst;
  3074. bUserSpecified = TRUE;
  3075. }
  3076. else
  3077. {
  3078. m_pRSOPQuery->dwFlags |= RSOP_NO_USER_POLICY;
  3079. m_pRSOPQueryResults->bNoUserPolicyData = TRUE;
  3080. }
  3081. if (ulCompFlags & FLAG_PLANNING_MODE)
  3082. {
  3083. //
  3084. // Comp has data specified. so we will use comp to update all global information
  3085. //
  3086. ulFlags = ulCompFlags;
  3087. pSessionInst = pCompSessionInst;
  3088. bCompSpecified = TRUE;
  3089. }
  3090. else
  3091. {
  3092. m_pRSOPQuery->dwFlags |= RSOP_NO_COMPUTER_POLICY;
  3093. m_pRSOPQueryResults->bNoComputerPolicyData = TRUE;
  3094. }
  3095. // slowlink value
  3096. hr = GetParameter(pSessionInst, TEXT("slowLink"), m_pRSOPQuery->bSlowNetworkConnection);
  3097. if (FAILED(hr))
  3098. {
  3099. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get slowlink param with 0x%x"), hr));
  3100. goto Cleanup;
  3101. }
  3102. // site value. we should ignore the error
  3103. GetParameter(pSessionInst, TEXT("Site"), m_pRSOPQuery->szSite, TRUE);
  3104. // set the dc as appropriate
  3105. if (szTarget)
  3106. {
  3107. ulNoChars = 1+lstrlen(szTarget);
  3108. m_pRSOPQuery->szDomainController = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*ulNoChars);
  3109. if (!(m_pRSOPQuery->szDomainController))
  3110. {
  3111. hr = E_OUTOFMEMORY;
  3112. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to allocate memory for dc with 0x%x"), hr));
  3113. goto Cleanup;
  3114. }
  3115. hr = StringCchCopy (m_pRSOPQuery->szDomainController, ulNoChars, szTarget);
  3116. ASSERT(SUCCEEDED(hr));
  3117. }
  3118. if (bUserSpecified)
  3119. {
  3120. // get the name of the user, if available
  3121. hr = GetParameter(pUserSessionInst, L"targetName", (m_pRSOPQuery->pUser->szName), TRUE);
  3122. if ( SUCCEEDED(hr) )
  3123. {
  3124. // check for an empty string, since this will mean that only a SOM was specified and the
  3125. // name has to be NULL.
  3126. if ( (m_pRSOPQuery->pUser->szName != NULL) && (m_pRSOPQuery->pUser->szName[0] == TEXT('\0')) )
  3127. {
  3128. LocalFree( m_pRSOPQuery->pUser->szName );
  3129. m_pRSOPQuery->pUser->szName = NULL;
  3130. }
  3131. }
  3132. // get the som
  3133. hr = GetParameter(pUserSessionInst, L"SOM", (m_pRSOPQuery->pUser->szSOM), TRUE);
  3134. if (FAILED(hr))
  3135. {
  3136. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get som param with 0x%x"), hr));
  3137. goto Cleanup;
  3138. }
  3139. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::EvaluateParameters: SOM = %s"), m_pRSOPQuery->pUser->szSOM ? m_pRSOPQuery->pUser->szSOM : TEXT("<NULL>")));
  3140. if (ulUserFlags & FLAG_ASSUME_USER_WQLFILTER_TRUE)
  3141. {
  3142. (m_pRSOPQuery->pUser->bAssumeWQLFiltersTrue) = TRUE;
  3143. }
  3144. else
  3145. {
  3146. (m_pRSOPQuery->pUser->bAssumeWQLFiltersTrue) = FALSE;
  3147. }
  3148. // get the secgrps of the user, if available
  3149. hr = ExtractSecurityGroups(pUserSessionInst, m_pRSOPQuery->pUser);
  3150. if (FAILED(hr))
  3151. {
  3152. goto Cleanup;
  3153. }
  3154. // get applicable wmi filters
  3155. if (!(m_pRSOPQuery->pUser->bAssumeWQLFiltersTrue))
  3156. {
  3157. hr = ExtractWQLFilters(szUserNamespace,
  3158. &(m_pRSOPQuery->pUser->dwWQLFilterCount),
  3159. &(m_pRSOPQuery->pUser->aszWQLFilterNames),
  3160. &(m_pRSOPQuery->pUser->aszWQLFilters),
  3161. TRUE);
  3162. if (FAILED(hr))
  3163. {
  3164. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get Extract WMI filter param with 0x%x"), hr));
  3165. goto Cleanup;
  3166. }
  3167. }
  3168. }
  3169. if (bCompSpecified)
  3170. {
  3171. // get the name of the Comp, if available
  3172. hr = GetParameter(pCompSessionInst, L"targetName", (m_pRSOPQuery->pComputer->szName), TRUE);
  3173. if ( SUCCEEDED(hr) )
  3174. {
  3175. // check for an empty string, since this will mean that only a SOM was specified and the
  3176. // name has to be NULL.
  3177. if ( (m_pRSOPQuery->pComputer->szName != NULL) && (m_pRSOPQuery->pComputer->szName[0] == TEXT('\0')) )
  3178. {
  3179. LocalFree( m_pRSOPQuery->pComputer->szName );
  3180. m_pRSOPQuery->pComputer->szName = NULL;
  3181. }
  3182. }
  3183. // get the som
  3184. hr = GetParameter(pCompSessionInst, L"SOM", (m_pRSOPQuery->pComputer->szSOM), TRUE);
  3185. if (FAILED(hr))
  3186. {
  3187. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get som param with 0x%x"), hr));
  3188. goto Cleanup;
  3189. }
  3190. if (ulCompFlags & FLAG_ASSUME_COMP_WQLFILTER_TRUE)
  3191. {
  3192. (m_pRSOPQuery->pComputer->bAssumeWQLFiltersTrue) = TRUE;
  3193. }
  3194. else
  3195. {
  3196. (m_pRSOPQuery->pComputer->bAssumeWQLFiltersTrue) = FALSE;
  3197. }
  3198. hr = ExtractSecurityGroups(pCompSessionInst, m_pRSOPQuery->pComputer);
  3199. if (FAILED(hr))
  3200. {
  3201. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to extract security group param for comp with 0x%x"), hr));
  3202. }
  3203. // get applicable wmi filters
  3204. if (!(m_pRSOPQuery->pComputer->bAssumeWQLFiltersTrue))
  3205. {
  3206. hr = ExtractWQLFilters(szCompNamespace,
  3207. &(m_pRSOPQuery->pComputer->dwWQLFilterCount),
  3208. &(m_pRSOPQuery->pComputer->aszWQLFilterNames),
  3209. &(m_pRSOPQuery->pComputer->aszWQLFilters),
  3210. TRUE);
  3211. if (FAILED(hr))
  3212. {
  3213. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to get Extract WMI filter param with 0x%x"), hr));
  3214. goto Cleanup;
  3215. }
  3216. }
  3217. }
  3218. }
  3219. else
  3220. {
  3221. LPTSTR szComputerName; // SAM style computer object name
  3222. hr = GetParameter(pUserSessionInst, L"targetName", (m_pRSOPQuery->szUserName), TRUE);
  3223. if (SUCCEEDED(hr) && (m_pRSOPQuery->szUserName) && (*(m_pRSOPQuery->szUserName)))
  3224. {
  3225. GetStringSid((m_pRSOPQuery->szUserName), &(m_pRSOPQuery->szUserSid));
  3226. }
  3227. else
  3228. {
  3229. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::EvaluateParameters: No user data specified")));
  3230. if (m_pRSOPQuery->szUserName)
  3231. {
  3232. LocalFree(m_pRSOPQuery->szUserName);
  3233. m_pRSOPQuery->szUserName = NULL;
  3234. }
  3235. // assume that the user results are not present
  3236. m_pRSOPQuery->szUserName = NULL;
  3237. m_pRSOPQuery->szUserSid = NULL;
  3238. m_pRSOPQuery->dwFlags |= RSOP_NO_USER_POLICY;
  3239. m_pRSOPQueryResults->bNoUserPolicyData = TRUE;
  3240. }
  3241. hr = GetParameter(pCompSessionInst, L"targetName", szComputerName, TRUE);
  3242. if (FAILED(hr) || (!szComputerName) || (!(*szComputerName)))
  3243. {
  3244. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::EvaluateParameters: No Computer data specified")));
  3245. // assume that the computer results are not present
  3246. m_pRSOPQuery->dwFlags |= RSOP_NO_COMPUTER_POLICY;
  3247. m_pRSOPQueryResults->bNoComputerPolicyData = TRUE;
  3248. }
  3249. if (szComputerName)
  3250. {
  3251. LocalFree(szComputerName);
  3252. }
  3253. if (szTarget)
  3254. {
  3255. ulNoChars = 1+lstrlen(szTarget);
  3256. m_pRSOPQuery->szComputerName = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*ulNoChars);
  3257. if (!(m_pRSOPQuery->szComputerName))
  3258. {
  3259. hr = E_OUTOFMEMORY;
  3260. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::EvaluateParameters: Failed to allocate memory for target comp with 0x%x"), hr));
  3261. goto Cleanup;
  3262. }
  3263. hr = StringCchCopy(m_pRSOPQuery->szComputerName, ulNoChars, szTarget);
  3264. ASSERT(SUCCEEDED(hr));
  3265. }
  3266. }
  3267. DebugMsg( (DM_VERBOSE, TEXT("CRSOPComponentData::EvaluateParameters successful for namespace=<%s>, target=<%s>"), szNamespace, szTarget) );
  3268. Cleanup:
  3269. if (pUserSessionInst)
  3270. {
  3271. pUserSessionInst->Release();
  3272. }
  3273. if (pCompSessionInst)
  3274. {
  3275. pCompSessionInst->Release();
  3276. }
  3277. if (pUserNamespace)
  3278. {
  3279. pUserNamespace->Release();
  3280. }
  3281. if (pCompNamespace)
  3282. {
  3283. pCompNamespace->Release();
  3284. }
  3285. if (bstrNamespace)
  3286. {
  3287. SysFreeString(bstrNamespace);
  3288. bstrNamespace = NULL;
  3289. }
  3290. if (szUserNamespace)
  3291. {
  3292. LocalFree(szUserNamespace);
  3293. }
  3294. if (szCompNamespace)
  3295. {
  3296. LocalFree(szCompNamespace);
  3297. }
  3298. if (bstrSessionInstPath)
  3299. {
  3300. SysFreeString(bstrSessionInstPath);
  3301. }
  3302. if (pLocator)
  3303. {
  3304. pLocator->Release();
  3305. }
  3306. return hr;
  3307. }
  3308. //-------------------------------------------------------
  3309. STDMETHODIMP CRSOPComponentData::Load(IStream *pStm)
  3310. {
  3311. HRESULT hr = E_FAIL;
  3312. DWORD dwVersion, dwFlags;
  3313. ULONG nBytesRead;
  3314. LONG lIndex, lMax;
  3315. LPTSTR lpText = NULL;
  3316. BSTR bstrText;
  3317. LPTSTR lpCommandLine = NULL;
  3318. LPTSTR lpTemp, lpMode;
  3319. BOOL bFoundArg;
  3320. int iStrLen;
  3321. // Parameter / initialization check
  3322. if (!pStm)
  3323. return E_FAIL;
  3324. if ( m_pRSOPQuery == NULL )
  3325. {
  3326. if ( !CreateRSOPQuery( &m_pRSOPQuery, RSOP_UNKNOWN_MODE ) )
  3327. {
  3328. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to create RSOP_QUERY_CONTEXT with 0x%x."),
  3329. HRESULT_FROM_WIN32(GetLastError())));
  3330. hr = E_FAIL;
  3331. goto Exit;
  3332. }
  3333. }
  3334. // Get the command line
  3335. lpCommandLine = GetCommandLine();
  3336. // Read in the saved data version number
  3337. hr = pStm->Read(&dwVersion, sizeof(dwVersion), &nBytesRead);
  3338. if ((hr != S_OK) || (nBytesRead != sizeof(dwVersion)))
  3339. {
  3340. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read version number with 0x%x."), hr));
  3341. hr = E_FAIL;
  3342. goto Exit;
  3343. }
  3344. // Confirm that we are working with the correct version
  3345. if (dwVersion != RSOP_PERSIST_DATA_VERSION)
  3346. {
  3347. ReportError(m_hwndFrame, 0, IDS_INVALIDMSC);
  3348. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Wrong version number (%d)."), dwVersion));
  3349. hr = E_FAIL;
  3350. goto Exit;
  3351. }
  3352. // Read the flags
  3353. hr = pStm->Read(&dwFlags, sizeof(dwFlags), &nBytesRead);
  3354. if ((hr != S_OK) || (nBytesRead != sizeof(dwFlags)))
  3355. {
  3356. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read flags with 0x%x."), hr));
  3357. hr = E_FAIL;
  3358. goto Exit;
  3359. }
  3360. // Parse the command line
  3361. DebugMsg((DM_VERBOSE, TEXT("CComponentData::Load: Command line switch override enabled. Command line = %s"), lpCommandLine));
  3362. lpTemp = lpCommandLine;
  3363. iStrLen = lstrlen (RSOP_CMD_LINE_START);
  3364. LPTSTR szUserSOMPref = NULL;
  3365. LPTSTR szComputerSOMPref = NULL;
  3366. LPTSTR szUserNamePref = NULL;
  3367. LPTSTR szComputerNamePref = NULL;
  3368. LPTSTR szSitePref = NULL;
  3369. LPTSTR szDCPref = NULL;
  3370. LPTSTR szNamespacePref = NULL;
  3371. LPTSTR szTargetPref = NULL;
  3372. do
  3373. {
  3374. if (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE | NORM_STOP_ON_NULL,
  3375. RSOP_CMD_LINE_START, iStrLen,
  3376. lpTemp, iStrLen) == CSTR_EQUAL)
  3377. {
  3378. m_bOverride = TRUE;
  3379. m_dwLoadFlags = RSOPMSC_OVERRIDE;
  3380. lpTemp = ParseCommandLine(lpTemp, RSOP_MODE, &lpMode, &bFoundArg);
  3381. if (bFoundArg) {
  3382. if (lpMode && lpMode[0]) {
  3383. if ( _ttoi(lpMode) == 0 )
  3384. {
  3385. if ( !ChangeRSOPQueryType( m_pRSOPQuery, RSOP_LOGGING_MODE ) )
  3386. {
  3387. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to change query type") ) );
  3388. hr = E_FAIL;
  3389. goto Exit;
  3390. }
  3391. }
  3392. else
  3393. {
  3394. if ( !ChangeRSOPQueryType( m_pRSOPQuery, RSOP_PLANNING_MODE ) )
  3395. {
  3396. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to change query type") ) );
  3397. hr = E_FAIL;
  3398. goto Exit;
  3399. }
  3400. }
  3401. }
  3402. else
  3403. {
  3404. if ( !ChangeRSOPQueryType( m_pRSOPQuery, RSOP_PLANNING_MODE ) )
  3405. {
  3406. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to change query type") ) );
  3407. hr = E_FAIL;
  3408. goto Exit;
  3409. }
  3410. }
  3411. if (lpMode) {
  3412. LocalFree(lpMode);
  3413. lpMode = NULL;
  3414. }
  3415. continue;
  3416. }
  3417. if (NULL == szUserSOMPref)
  3418. {
  3419. lpTemp = ParseCommandLine(lpTemp, RSOP_USER_OU_PREF, &szUserSOMPref, &bFoundArg);
  3420. if (bFoundArg)
  3421. {
  3422. continue;
  3423. }
  3424. }
  3425. if (NULL == szComputerSOMPref)
  3426. {
  3427. lpTemp = ParseCommandLine(lpTemp, RSOP_COMP_OU_PREF, &szComputerSOMPref, &bFoundArg);
  3428. if (bFoundArg)
  3429. {
  3430. continue;
  3431. }
  3432. }
  3433. if (NULL == szUserNamePref)
  3434. {
  3435. lpTemp = ParseCommandLine(lpTemp, RSOP_USER_NAME, &szUserNamePref, &bFoundArg);
  3436. if (bFoundArg)
  3437. {
  3438. continue;
  3439. }
  3440. }
  3441. if (NULL==szComputerNamePref)
  3442. {
  3443. lpTemp = ParseCommandLine(lpTemp, RSOP_COMP_NAME, &szComputerNamePref, &bFoundArg);
  3444. if (bFoundArg)
  3445. {
  3446. // RM: This code has been copied in from RSOPGetCompDlgProc and RSOPGetTargetDlgProc as I believe it belongs here.
  3447. ULONG ulNoChars = wcslen(szComputerNamePref)+1;
  3448. LPTSTR szTemp = (LPTSTR)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  3449. if ( szTemp == NULL )
  3450. {
  3451. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to allocate memory with 0x%x."),
  3452. HRESULT_FROM_WIN32(GetLastError())) );
  3453. hr = E_FAIL;
  3454. goto Exit;
  3455. }
  3456. hr = StringCchCopy( szTemp, ulNoChars, NormalizedComputerName( szComputerNamePref) );
  3457. if (FAILED(hr))
  3458. {
  3459. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to copy computer name with 0x%x."), hr) );
  3460. LocalFree( szComputerNamePref );
  3461. LocalFree(szTemp);
  3462. goto Exit;
  3463. }
  3464. if ( wcslen( szTemp ) >= 1 )
  3465. {
  3466. // this is being called from dsa. A terminating '$' will be passed in
  3467. szTemp[ wcslen(szTemp)-1] = L'\0';
  3468. }
  3469. LocalFree( szComputerNamePref );
  3470. szComputerNamePref = szTemp;
  3471. continue;
  3472. }
  3473. }
  3474. if (NULL == szSitePref)
  3475. {
  3476. lpTemp = ParseCommandLine(lpTemp, RSOP_SITENAME, &szSitePref, &bFoundArg);
  3477. if (bFoundArg)
  3478. {
  3479. continue;
  3480. }
  3481. }
  3482. if (NULL == szDCPref)
  3483. {
  3484. lpTemp = ParseCommandLine(lpTemp, RSOP_DCNAME_PREF, &szDCPref, &bFoundArg);
  3485. if (bFoundArg)
  3486. {
  3487. continue;
  3488. }
  3489. }
  3490. if (NULL == szNamespacePref)
  3491. {
  3492. lpTemp = ParseCommandLine(lpTemp, RSOP_NAMESPACE, &szNamespacePref, &bFoundArg);
  3493. if (bFoundArg)
  3494. {
  3495. m_bNamespaceSpecified = TRUE;
  3496. continue;
  3497. }
  3498. }
  3499. if (NULL == szTargetPref)
  3500. {
  3501. lpTemp = ParseCommandLine(lpTemp, RSOP_TARGETCOMP, &szTargetPref, &bFoundArg);
  3502. if (bFoundArg)
  3503. {
  3504. continue;
  3505. }
  3506. }
  3507. lpTemp += iStrLen;
  3508. continue;
  3509. }
  3510. lpTemp++;
  3511. } while (*lpTemp);
  3512. if ( m_bOverride )
  3513. {
  3514. if (m_bNamespaceSpecified)
  3515. {
  3516. hr = EvaluateParameters(szNamespacePref, szTargetPref);
  3517. if (szNamespacePref)
  3518. {
  3519. LocalFree(szNamespacePref);
  3520. szNamespacePref = NULL;
  3521. }
  3522. if (szTargetPref)
  3523. {
  3524. LocalFree(szTargetPref);
  3525. szTargetPref = NULL;
  3526. }
  3527. if (FAILED(hr))
  3528. {
  3529. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Load: EvaluateParameters failed with error 0x%x"), hr) );
  3530. goto Exit;
  3531. }
  3532. }
  3533. else {
  3534. m_pRSOPQuery->UIMode = RSOP_UI_WIZARD;
  3535. m_pRSOPQuery->dwFlags |= RSOP_NO_WELCOME;
  3536. // Store parameters found
  3537. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3538. {
  3539. m_pRSOPQuery->pUser->szName = szUserNamePref;
  3540. m_pRSOPQuery->pUser->szSOM = szUserSOMPref;
  3541. m_pRSOPQuery->pComputer->szName = szComputerNamePref;
  3542. m_pRSOPQuery->pComputer->szSOM = szComputerSOMPref;
  3543. m_pRSOPQuery->szSite = szSitePref;
  3544. m_pRSOPQuery->szDomainController = szDCPref;
  3545. if ( (m_pRSOPQuery->pUser->szName != NULL)
  3546. || (m_pRSOPQuery->pUser->szSOM != NULL) )
  3547. {
  3548. m_pRSOPQuery->dwFlags |= RSOP_FIX_USER;
  3549. }
  3550. if ( (m_pRSOPQuery->pComputer->szName != NULL)
  3551. || (m_pRSOPQuery->pComputer->szSOM != NULL) )
  3552. {
  3553. m_pRSOPQuery->dwFlags |= RSOP_FIX_COMPUTER;
  3554. }
  3555. // If both the user and computer are fixed, we are unfixing both
  3556. // since we don't know what the "user" intended to fix
  3557. if ( (m_pRSOPQuery->dwFlags & RSOP_FIX_COMPUTER)
  3558. && (m_pRSOPQuery->dwFlags & RSOP_FIX_USER) )
  3559. {
  3560. m_pRSOPQuery->dwFlags = m_pRSOPQuery->dwFlags & (RSOP_FIX_COMPUTER ^ 0xffffffff);
  3561. m_pRSOPQuery->dwFlags = m_pRSOPQuery->dwFlags & (RSOP_FIX_USER ^ 0xffffffff);
  3562. }
  3563. if ( m_pRSOPQuery->szSite != NULL )
  3564. {
  3565. m_pRSOPQuery->dwFlags |= RSOP_FIX_SITENAME;
  3566. }
  3567. if ( m_pRSOPQuery->szDomainController != NULL )
  3568. {
  3569. m_pRSOPQuery->dwFlags |= RSOP_FIX_DC;
  3570. }
  3571. }
  3572. else
  3573. {
  3574. m_pRSOPQuery->szUserName = szUserNamePref;
  3575. m_pRSOPQuery->szComputerName = szComputerNamePref;
  3576. if ( m_pRSOPQuery->szUserName != NULL )
  3577. {
  3578. m_pRSOPQuery->dwFlags |= RSOP_FIX_USER;
  3579. }
  3580. if ( m_pRSOPQuery->szComputerName != NULL )
  3581. {
  3582. m_pRSOPQuery->dwFlags |= RSOP_FIX_COMPUTER;
  3583. }
  3584. if ( szUserSOMPref != NULL )
  3585. {
  3586. LocalFree( szUserSOMPref );
  3587. }
  3588. if ( szComputerSOMPref != NULL )
  3589. {
  3590. LocalFree( szComputerSOMPref );
  3591. }
  3592. if ( szSitePref != NULL )
  3593. {
  3594. LocalFree( szSitePref );
  3595. }
  3596. if ( szDCPref != NULL )
  3597. {
  3598. LocalFree( szDCPref );
  3599. }
  3600. }
  3601. }
  3602. }
  3603. else
  3604. {
  3605. if ( dwFlags & MSC_RSOP_FLAG_NO_DATA )
  3606. {
  3607. // There is no data in this file, so we simply quit here.
  3608. m_pRSOPQuery->UIMode = RSOP_UI_WIZARD;
  3609. hr = S_OK;
  3610. goto Exit;
  3611. }
  3612. m_bGetExtendedErrorInfo = !((dwFlags & MSC_RSOP_FLAG_NOGETEXTENDEDERRORINFO) != 0);
  3613. // Decode the loaded flags
  3614. m_dwLoadFlags = RSOPMSC_NOOVERRIDE;
  3615. m_bOverride = FALSE;
  3616. m_pRSOPQuery->UIMode = RSOP_UI_REFRESH;
  3617. if (dwFlags & MSC_RSOP_FLAG_DIAGNOSTIC)
  3618. {
  3619. if ( !ChangeRSOPQueryType( m_pRSOPQuery, RSOP_LOGGING_MODE ) )
  3620. {
  3621. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to change query type") ) );
  3622. hr = E_FAIL;
  3623. goto Exit;
  3624. }
  3625. }
  3626. else
  3627. {
  3628. if ( !ChangeRSOPQueryType( m_pRSOPQuery, RSOP_PLANNING_MODE ) )
  3629. {
  3630. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to change query type") ) );
  3631. hr = E_FAIL;
  3632. goto Exit;
  3633. }
  3634. }
  3635. if (dwFlags & MSC_RSOP_FLAG_ARCHIVEDATA)
  3636. {
  3637. m_bArchiveData = TRUE;
  3638. m_bViewIsArchivedData = TRUE;
  3639. }
  3640. if ( (dwFlags & MSC_RSOP_FLAG_SLOWLINK) && (m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE) )
  3641. {
  3642. m_pRSOPQuery->bSlowNetworkConnection = TRUE;
  3643. }
  3644. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3645. {
  3646. if (dwFlags & MSC_RSOP_FLAG_LOOPBACK_REPLACE)
  3647. {
  3648. m_pRSOPQuery->LoopbackMode = RSOP_LOOPBACK_REPLACE;
  3649. }
  3650. else if (dwFlags & MSC_RSOP_FLAG_LOOPBACK_MERGE)
  3651. {
  3652. m_pRSOPQuery->LoopbackMode = RSOP_LOOPBACK_MERGE;
  3653. }
  3654. else
  3655. {
  3656. m_pRSOPQuery->LoopbackMode = RSOP_LOOPBACK_NONE;
  3657. }
  3658. m_pRSOPQuery->pComputer->bAssumeWQLFiltersTrue =
  3659. (dwFlags & MSC_RSOP_FLAG_COMPUTERWQLFILTERSTRUE) == MSC_RSOP_FLAG_COMPUTERWQLFILTERSTRUE;
  3660. m_pRSOPQuery->pUser->bAssumeWQLFiltersTrue =
  3661. (dwFlags & MSC_RSOP_FLAG_USERWQLFILTERSTRUE) == MSC_RSOP_FLAG_USERWQLFILTERSTRUE;
  3662. }
  3663. if (dwFlags & MSC_RSOP_FLAG_NOUSER)
  3664. {
  3665. m_pRSOPQuery->dwFlags |= RSOP_NO_USER_POLICY;
  3666. }
  3667. if (dwFlags & MSC_RSOP_FLAG_NOCOMPUTER)
  3668. {
  3669. m_pRSOPQuery->dwFlags |= RSOP_NO_COMPUTER_POLICY;
  3670. }
  3671. if ( m_bViewIsArchivedData )
  3672. {
  3673. // We must create a dummy RSOP query results structure for the loaded information
  3674. m_pRSOPQueryResults = (LPRSOP_QUERY_RESULTS)LocalAlloc( LPTR, sizeof(RSOP_QUERY_RESULTS) );
  3675. if ( m_pRSOPQueryResults == NULL )
  3676. {
  3677. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to create RSOP_QUERY_CONTEXT.")) );
  3678. hr = E_FAIL;
  3679. goto Exit;
  3680. }
  3681. m_pRSOPQueryResults->bComputerDeniedAccess = FALSE;
  3682. m_pRSOPQueryResults->bNoComputerPolicyData = FALSE;
  3683. m_pRSOPQueryResults->bNoUserPolicyData = FALSE;
  3684. m_pRSOPQueryResults->bUserDeniedAccess = FALSE;
  3685. m_pRSOPQueryResults->szWMINameSpace = NULL;
  3686. }
  3687. if (dwFlags & MSC_RSOP_FLAG_USERDENIED)
  3688. {
  3689. // RM: Must still decide what to do here. Removing the persistence of this
  3690. // item might cause a regression, but it is not sure if anybody uses this "feature".
  3691. // m_bUserDeniedAccess = TRUE;
  3692. if ( m_bViewIsArchivedData )
  3693. {
  3694. m_pRSOPQueryResults->bUserDeniedAccess = TRUE;
  3695. }
  3696. }
  3697. if (dwFlags & MSC_RSOP_FLAG_COMPUTERDENIED)
  3698. {
  3699. // RM: Must still decide what to do here. Removing the persistence of this
  3700. // item might cause a regression, but it is not sure if anybody uses this "feature".
  3701. // m_bComputerDeniedAccess = TRUE;
  3702. if ( m_bViewIsArchivedData )
  3703. {
  3704. m_pRSOPQueryResults->bComputerDeniedAccess = TRUE;
  3705. }
  3706. }
  3707. // Read the computer name
  3708. LPTSTR szComputerName = NULL;
  3709. hr = ReadString( pStm, &szComputerName, TRUE );
  3710. if (hr != S_OK)
  3711. {
  3712. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read the computer name with 0x%x."), hr));
  3713. hr = E_FAIL;
  3714. goto Exit;
  3715. }
  3716. // Read the computer SOM
  3717. LPTSTR szComputerSOM = NULL;
  3718. hr = ReadString( pStm, &szComputerSOM, TRUE );
  3719. if (hr != S_OK)
  3720. {
  3721. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read the computer SOM with 0x%x."), hr));
  3722. hr = E_FAIL;
  3723. LocalFree( szComputerName );
  3724. goto Exit;
  3725. }
  3726. // RM: based on the query type, set the right variables
  3727. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3728. {
  3729. m_pRSOPQuery->pComputer->szName = szComputerName;
  3730. m_pRSOPQuery->pComputer->szSOM = szComputerSOM;
  3731. }
  3732. else
  3733. {
  3734. if ( szComputerName != NULL )
  3735. {
  3736. m_pRSOPQuery->szComputerName = szComputerName;
  3737. }
  3738. LocalFree( szComputerSOM );
  3739. // RM: From investigating the code, I have concluded that in logging mode, only a computer name can be specified, not a SOM.
  3740. }
  3741. DWORD listCount = 0;
  3742. LPTSTR* aszStringList = NULL;
  3743. // Read in the computer security groups
  3744. hr = LoadStringList( pStm, &listCount, &aszStringList );
  3745. if ( FAILED(hr) )
  3746. {
  3747. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read computer security groups with 0x%x."), hr));
  3748. hr = E_FAIL;
  3749. goto Exit;
  3750. }
  3751. // RM: Once again, there should be no security groups to read in if this is logging mode, but for backwards compatability I must
  3752. // try to read in whatever there is.
  3753. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3754. {
  3755. m_pRSOPQuery->pComputer->dwSecurityGroupCount = listCount;
  3756. m_pRSOPQuery->pComputer->aszSecurityGroups = aszStringList;
  3757. }
  3758. else if ( listCount != 0 )
  3759. {
  3760. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Loaded computer security groups in logging mode!")) );
  3761. hr = E_FAIL;
  3762. goto Exit;
  3763. }
  3764. // Read in the computer WQL filters
  3765. listCount = 0;
  3766. aszStringList = NULL;
  3767. hr = LoadStringList( pStm, &listCount, &aszStringList );
  3768. if ( FAILED(hr) )
  3769. {
  3770. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read computer WQL filters with 0x%x."), hr));
  3771. hr = E_FAIL;
  3772. goto Exit;
  3773. }
  3774. // RM: See notes for security groups - same applies here
  3775. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3776. {
  3777. m_pRSOPQuery->pComputer->dwWQLFilterCount = listCount;
  3778. m_pRSOPQuery->pComputer->aszWQLFilters = aszStringList;
  3779. }
  3780. else if ( listCount != 0 )
  3781. {
  3782. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Loaded computer WQL filters in logging mode!")) );
  3783. hr = E_FAIL;
  3784. goto Exit;
  3785. }
  3786. // Read in the computer WQL filter names
  3787. listCount = 0;
  3788. aszStringList = NULL;
  3789. hr = LoadStringList( pStm, &listCount, &aszStringList );
  3790. if ( FAILED(hr) )
  3791. {
  3792. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read computer WQL filter names with 0x%x."), hr));
  3793. hr = E_FAIL;
  3794. goto Exit;
  3795. }
  3796. // RM: See notes for security groups - same applies here
  3797. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3798. {
  3799. //m_pRSOPQuery->pComputer->dwWQLFilterNameCount= listCount;
  3800. // The number of filter names must match the number of filters
  3801. m_pRSOPQuery->pComputer->aszWQLFilterNames= aszStringList;
  3802. }
  3803. else if ( listCount != 0 )
  3804. {
  3805. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Loaded computer WQL filter names in logging mode!")) );
  3806. hr = E_FAIL;
  3807. goto Exit;
  3808. }
  3809. // Read the user name
  3810. LPTSTR szUserNameOrSid = NULL;
  3811. hr = ReadString( pStm, &szUserNameOrSid, TRUE );
  3812. if (hr != S_OK)
  3813. {
  3814. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read the user name with 0x%x."), hr));
  3815. hr = E_FAIL;
  3816. goto Exit;
  3817. }
  3818. // Read the user display name (only used in logging mode)
  3819. LPTSTR szUserDisplayName = NULL;
  3820. hr = ReadString( pStm, &szUserDisplayName, TRUE );
  3821. if (hr != S_OK)
  3822. {
  3823. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read the user display name with 0x%x."), hr));
  3824. hr = E_FAIL;
  3825. LocalFree( szUserNameOrSid );
  3826. goto Exit;
  3827. }
  3828. // Read the user SOM
  3829. LPTSTR szUserSOM = NULL;
  3830. hr = ReadString( pStm, &szUserSOM, TRUE );
  3831. if (hr != S_OK)
  3832. {
  3833. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read the user SOM with 0x%x."), hr));
  3834. hr = E_FAIL;
  3835. LocalFree( szUserNameOrSid );
  3836. LocalFree( szUserDisplayName );
  3837. goto Exit;
  3838. }
  3839. if (m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE)
  3840. {
  3841. m_pRSOPQuery->pUser->szName = szUserNameOrSid;
  3842. m_pRSOPQuery->pUser->szSOM = szUserSOM;
  3843. }
  3844. else
  3845. {
  3846. // First check if the user sid is a special character and we are going to do logging mode. If this is the case,
  3847. // the current user is found and used (SPECIAL: used primarily by RSOP.MSC)
  3848. if ( (m_pRSOPQuery->QueryType == RSOP_LOGGING_MODE)
  3849. && !lstrcmpi( szUserNameOrSid, TEXT(".") ) && !m_bViewIsArchivedData )
  3850. {
  3851. LPTSTR szThisUserName = NULL;
  3852. szThisUserName = MyGetUserName (NameSamCompatible);
  3853. if ( szThisUserName != NULL )
  3854. {
  3855. if ( szUserDisplayName != NULL )
  3856. {
  3857. LocalFree( szUserDisplayName );
  3858. }
  3859. szUserDisplayName = szThisUserName;
  3860. }
  3861. }
  3862. // RM: From investigating the code, I have concluded that the assignment below is what originally happened
  3863. // in the wizard. Also, the UserSOM is not used and should actually be NULL.
  3864. m_pRSOPQuery->szUserName = szUserDisplayName;
  3865. m_pRSOPQuery->szUserSid = szUserNameOrSid;
  3866. }
  3867. // Read in the user security groups
  3868. listCount = 0;
  3869. aszStringList = NULL;
  3870. hr = LoadStringList( pStm, &listCount, &aszStringList );
  3871. if ( FAILED(hr) )
  3872. {
  3873. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read user security groups with 0x%x."), hr));
  3874. hr = E_FAIL;
  3875. goto Exit;
  3876. }
  3877. // RM: Once again, there should be no security groups to read in if this is logging mode, but for backwards compatability I must
  3878. // try to read in whatever there is.
  3879. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3880. {
  3881. m_pRSOPQuery->pUser->dwSecurityGroupCount = listCount;
  3882. m_pRSOPQuery->pUser->aszSecurityGroups = aszStringList;
  3883. }
  3884. else if ( listCount != 0 )
  3885. {
  3886. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Loaded user security groups in logging mode!")) );
  3887. hr = E_FAIL;
  3888. goto Exit;
  3889. }
  3890. // Read in the WQL filters
  3891. listCount = 0;
  3892. aszStringList = NULL;
  3893. hr = LoadStringList( pStm, &listCount, &aszStringList );
  3894. if ( FAILED(hr) )
  3895. {
  3896. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read user WQL filters with 0x%x."), hr));
  3897. hr = E_FAIL;
  3898. goto Exit;
  3899. }
  3900. // RM: See notes for security groups - same applies here
  3901. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3902. {
  3903. m_pRSOPQuery->pUser->dwWQLFilterCount = listCount;
  3904. m_pRSOPQuery->pUser->aszWQLFilters = aszStringList;
  3905. }
  3906. else if ( listCount != 0 )
  3907. {
  3908. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Loaded user WQL filters in logging mode!")) );
  3909. hr = E_FAIL;
  3910. goto Exit;
  3911. }
  3912. // Read in the WQL filter names
  3913. listCount = 0;
  3914. aszStringList = NULL;
  3915. hr = LoadStringList( pStm, &listCount, &aszStringList );
  3916. if ( FAILED(hr) )
  3917. {
  3918. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read user WQL filter names with 0x%x."), hr));
  3919. hr = E_FAIL;
  3920. goto Exit;
  3921. }
  3922. // RM: See notes for security groups - same applies here
  3923. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3924. {
  3925. //m_pRSOPQuery->pUser->dwWQLFilterNameCount= listCount;
  3926. // The number of filter names must match the number of filters
  3927. m_pRSOPQuery->pUser->aszWQLFilterNames= aszStringList;
  3928. }
  3929. else if ( listCount != 0 )
  3930. {
  3931. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Loaded user WQL filter names in logging mode!")) );
  3932. hr = E_FAIL;
  3933. goto Exit;
  3934. }
  3935. // Read the site
  3936. LPTSTR szSite = NULL;
  3937. hr = ReadString( pStm, &szSite, TRUE );
  3938. if (hr != S_OK)
  3939. {
  3940. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read the site with 0x%x."), hr));
  3941. hr = E_FAIL;
  3942. goto Exit;
  3943. }
  3944. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3945. {
  3946. m_pRSOPQuery->szSite = szSite;
  3947. }
  3948. else
  3949. {
  3950. LocalFree( szSite );
  3951. }
  3952. // Read the DC
  3953. LPTSTR szDomainController = NULL;
  3954. hr = ReadString( pStm, &szDomainController, TRUE );
  3955. if (hr != S_OK)
  3956. {
  3957. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read the dc with 0x%x."), hr));
  3958. hr = E_FAIL;
  3959. goto Exit;
  3960. }
  3961. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  3962. {
  3963. m_pRSOPQuery->szDomainController = szDomainController;
  3964. }
  3965. else
  3966. {
  3967. LocalFree( szDomainController );
  3968. }
  3969. }
  3970. // Read in the WMI data if appropriate
  3971. if (m_bNamespaceSpecified)
  3972. {
  3973. // Initialize the snapin
  3974. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::Load: Launching RSOP to collect data from the namespace.")));
  3975. hr = InitializeRSOP( FALSE );
  3976. if ( FAILED(hr) )
  3977. {
  3978. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: InitializeRSOP failed with 0x%x."), hr));
  3979. goto Exit;
  3980. }
  3981. }
  3982. else if (m_bViewIsArchivedData)
  3983. {
  3984. m_pStm = pStm;
  3985. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::Load: Launching RSOP status dialog box.")));
  3986. if (DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_RSOP_STATUSMSC),
  3987. NULL, InitArchivedRsopDlgProc, (LPARAM) this ) == -1) {
  3988. m_pStm = NULL;
  3989. hr = HRESULT_FROM_WIN32(GetLastError());
  3990. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Falied to create dialog box. 0x%x"), hr));
  3991. goto Exit;
  3992. }
  3993. m_pStm = NULL;
  3994. }
  3995. else
  3996. {
  3997. // Initialize the snapin
  3998. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::Load: Launching RSOP status dialog box.")));
  3999. hr = InitializeRSOP( FALSE );
  4000. if ( (hr == S_FALSE) && (m_dwLoadFlags == RSOPMSC_OVERRIDE) )
  4001. {
  4002. // this is a hack to get mmc to not launch itself when user cancelled the wizard
  4003. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::Load: User cancelled the wizard. Exitting the process")));
  4004. TerminateProcess (GetCurrentProcess(), ERROR_CANCELLED);
  4005. }
  4006. if ( FAILED(hr) )
  4007. {
  4008. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: InitializeRSOP failed with 0x%x."), hr));
  4009. goto Exit;
  4010. }
  4011. }
  4012. Exit:
  4013. return hr;
  4014. }
  4015. //-------------------------------------------------------
  4016. STDMETHODIMP CRSOPComponentData::Save(IStream *pStm, BOOL fClearDirty)
  4017. {
  4018. HRESULT hr = STG_E_CANTSAVE;
  4019. ULONG nBytesWritten;
  4020. DWORD dwTemp;
  4021. DWORD dwFlags;
  4022. GROUP_POLICY_OBJECT_TYPE gpoType;
  4023. LPTSTR lpPath = NULL;
  4024. LPTSTR lpTemp;
  4025. DWORD dwPathSize = 1024;
  4026. LONG lIndex, lMax;
  4027. LPTSTR lpText;
  4028. LPTSTR lpUserData = NULL, lpComputerData = NULL;
  4029. TCHAR szPath[2*MAX_PATH];
  4030. // Save the version number
  4031. dwTemp = RSOP_PERSIST_DATA_VERSION;
  4032. hr = pStm->Write(&dwTemp, sizeof(dwTemp), &nBytesWritten);
  4033. if ((hr != S_OK) || (nBytesWritten != sizeof(dwTemp)))
  4034. {
  4035. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to write version number with 0x%x."), hr));
  4036. goto Exit;
  4037. }
  4038. // Save the flags
  4039. dwTemp = 0;
  4040. if ( !m_bInitialized )
  4041. {
  4042. dwTemp |= MSC_RSOP_FLAG_NO_DATA;
  4043. }
  4044. else
  4045. {
  4046. if ( !m_bGetExtendedErrorInfo )
  4047. {
  4048. dwTemp |= MSC_RSOP_FLAG_NOGETEXTENDEDERRORINFO;
  4049. }
  4050. if ( (m_pRSOPQuery == NULL) || (m_pRSOPQueryResults == NULL) )
  4051. {
  4052. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Save: Cannot save snapin with no initialized RSOP query or results.")) );
  4053. return E_FAIL;
  4054. }
  4055. if ( m_pRSOPQuery->QueryType == RSOP_UNKNOWN_MODE )
  4056. {
  4057. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Save: Cannot save snapin with no initialized RSOP query.")) );
  4058. return E_FAIL;
  4059. }
  4060. if ( m_pRSOPQuery->QueryType == RSOP_LOGGING_MODE )
  4061. {
  4062. dwTemp |= MSC_RSOP_FLAG_DIAGNOSTIC;
  4063. }
  4064. if (m_bArchiveData)
  4065. {
  4066. dwTemp |= MSC_RSOP_FLAG_ARCHIVEDATA;
  4067. }
  4068. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4069. {
  4070. if ( m_pRSOPQuery->bSlowNetworkConnection )
  4071. {
  4072. dwTemp |= MSC_RSOP_FLAG_SLOWLINK;
  4073. }
  4074. switch ( m_pRSOPQuery->LoopbackMode )
  4075. {
  4076. case RSOP_LOOPBACK_REPLACE:
  4077. dwTemp |= MSC_RSOP_FLAG_LOOPBACK_REPLACE;
  4078. break;
  4079. case RSOP_LOOPBACK_MERGE:
  4080. dwTemp |= MSC_RSOP_FLAG_LOOPBACK_MERGE;
  4081. break;
  4082. default:
  4083. break;
  4084. }
  4085. if ( m_pRSOPQuery->pComputer->bAssumeWQLFiltersTrue )
  4086. {
  4087. dwTemp |= MSC_RSOP_FLAG_COMPUTERWQLFILTERSTRUE;
  4088. }
  4089. if ( m_pRSOPQuery->pUser->bAssumeWQLFiltersTrue )
  4090. {
  4091. dwTemp |= MSC_RSOP_FLAG_USERWQLFILTERSTRUE;
  4092. }
  4093. }
  4094. if ( (m_pRSOPQuery->dwFlags & RSOP_NO_USER_POLICY) == RSOP_NO_USER_POLICY )
  4095. {
  4096. dwTemp |= MSC_RSOP_FLAG_NOUSER;
  4097. }
  4098. if ( (m_pRSOPQuery->dwFlags & RSOP_NO_COMPUTER_POLICY) == RSOP_NO_COMPUTER_POLICY )
  4099. {
  4100. dwTemp |= MSC_RSOP_FLAG_NOCOMPUTER;
  4101. }
  4102. // RM: must still decide what to do here, but from all accounts it looks like this is completele redundant
  4103. // unless the RSOP data was also archived.
  4104. /*
  4105. if (m_bUserDeniedAccess)
  4106. {
  4107. dwTemp |= MSC_RSOP_FLAG_USERDENIED;
  4108. }
  4109. if (m_bComputerDeniedAccess)
  4110. {
  4111. dwTemp |= MSC_RSOP_FLAG_COMPUTERDENIED;
  4112. }
  4113. */
  4114. }
  4115. hr = pStm->Write(&dwTemp, sizeof(dwTemp), &nBytesWritten);
  4116. if ((hr != S_OK) || (nBytesWritten != sizeof(dwTemp)))
  4117. {
  4118. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to write flags with 0x%x."), hr));
  4119. goto Exit;
  4120. }
  4121. // If there is no data, we quit here
  4122. if ( !m_bInitialized )
  4123. {
  4124. return S_OK;
  4125. }
  4126. // Save the computer name
  4127. LPTSTR szComputerName = NULL;
  4128. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4129. {
  4130. szComputerName = m_pRSOPQuery->pComputer->szName;
  4131. }
  4132. else
  4133. {
  4134. szComputerName = m_pRSOPQuery->szComputerName;
  4135. }
  4136. if ( szComputerName == NULL )
  4137. {
  4138. // SaveString knows how to handle NULL strings. We must save this so that a NULL string can be loaded!
  4139. hr = SaveString( pStm, szComputerName );
  4140. }
  4141. else
  4142. {
  4143. if ( (m_bArchiveData) && (!lstrcmpi(szComputerName, TEXT("."))) )
  4144. {
  4145. ULONG ulSize = MAX_PATH;
  4146. LPTSTR szLocalComputerName = new TCHAR[MAX_PATH];
  4147. if ( szLocalComputerName == NULL )
  4148. {
  4149. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save computer name (could not allocate memory)")) );
  4150. hr = E_FAIL;
  4151. goto Exit;
  4152. }
  4153. if (!GetComputerObjectName (NameSamCompatible, szLocalComputerName, &ulSize))
  4154. {
  4155. DWORD dwLastError = GetLastError();
  4156. if ( dwLastError == ERROR_MORE_DATA )
  4157. {
  4158. delete [] szLocalComputerName;
  4159. szLocalComputerName = new TCHAR[ulSize];
  4160. if ( szLocalComputerName == NULL )
  4161. {
  4162. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save computer name (could not allocate memory)")) );
  4163. hr = E_FAIL;
  4164. goto Exit;
  4165. }
  4166. if (!GetComputerObjectName (NameSamCompatible, szLocalComputerName, &ulSize))
  4167. {
  4168. dwLastError = GetLastError();
  4169. }
  4170. else
  4171. {
  4172. dwLastError = ERROR_SUCCESS;
  4173. }
  4174. }
  4175. if ( dwLastError != ERROR_SUCCESS )
  4176. {
  4177. if ( !GetComputerNameEx (ComputerNameNetBIOS, szLocalComputerName, &ulSize) )
  4178. {
  4179. dwLastError = GetLastError();
  4180. if ( dwLastError == ERROR_MORE_DATA )
  4181. {
  4182. delete [] szLocalComputerName;
  4183. szLocalComputerName = new TCHAR[ulSize];
  4184. if ( szLocalComputerName == NULL )
  4185. {
  4186. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save computer name (could not allocate memory)")) );
  4187. hr = E_FAIL;
  4188. goto Exit;
  4189. }
  4190. if (!GetComputerNameEx (ComputerNameNetBIOS, szLocalComputerName, &ulSize))
  4191. {
  4192. dwLastError = GetLastError();
  4193. }
  4194. }
  4195. }
  4196. }
  4197. if ( dwLastError != ERROR_SUCCESS )
  4198. {
  4199. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Save: Could not obtain computer name with 0x%x"),
  4200. HRESULT_FROM_WIN32(dwLastError) ) );
  4201. hr = E_FAIL;
  4202. delete [] szLocalComputerName;
  4203. goto Exit;
  4204. }
  4205. }
  4206. if ( (szLocalComputerName != NULL) && (wcslen(szLocalComputerName) >= 1)
  4207. && (szLocalComputerName[wcslen(szLocalComputerName)-1] == L'$'))
  4208. {
  4209. // Remove the terminating '$' to be consistent with saving a specific computer name in logging mode.
  4210. szLocalComputerName[ wcslen(szLocalComputerName)-1] = L'\0';
  4211. }
  4212. hr = SaveString (pStm, szLocalComputerName);
  4213. delete [] szLocalComputerName;
  4214. }
  4215. else
  4216. {
  4217. hr = SaveString (pStm, szComputerName);
  4218. }
  4219. }
  4220. if (hr != S_OK)
  4221. {
  4222. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save computer name with %d."), hr));
  4223. goto Exit;
  4224. }
  4225. // Save the computer SOM
  4226. LPTSTR szComputerSOM = NULL;
  4227. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4228. {
  4229. szComputerSOM = m_pRSOPQuery->pComputer->szSOM;
  4230. }
  4231. hr = SaveString( pStm, szComputerSOM );
  4232. if (hr != S_OK)
  4233. {
  4234. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save computer SOM with %d."), hr));
  4235. goto Exit;
  4236. }
  4237. // Save the computer security groups
  4238. DWORD dwStringCount = 0;
  4239. LPTSTR* aszStringList = NULL;
  4240. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4241. {
  4242. dwStringCount = m_pRSOPQuery->pComputer->dwSecurityGroupCount;
  4243. aszStringList = m_pRSOPQuery->pComputer->aszSecurityGroups;
  4244. }
  4245. hr = SaveStringList( pStm, dwStringCount, aszStringList );
  4246. if ( hr != S_OK )
  4247. {
  4248. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to write computer security groups.")) );
  4249. goto Exit;
  4250. }
  4251. // Save the computer WQL filters
  4252. dwStringCount = 0;
  4253. aszStringList = NULL;
  4254. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4255. {
  4256. dwStringCount = m_pRSOPQuery->pComputer->dwWQLFilterCount;
  4257. aszStringList = m_pRSOPQuery->pComputer->aszWQLFilters;
  4258. }
  4259. hr = SaveStringList( pStm, dwStringCount, aszStringList );
  4260. if ( hr != S_OK )
  4261. {
  4262. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to write computer WQL filters.")) );
  4263. goto Exit;
  4264. }
  4265. // Save the computer WQL filter names
  4266. dwStringCount = 0;
  4267. aszStringList = NULL;
  4268. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4269. {
  4270. dwStringCount = m_pRSOPQuery->pComputer->dwWQLFilterCount;
  4271. aszStringList = m_pRSOPQuery->pComputer->aszWQLFilterNames;
  4272. }
  4273. hr = SaveStringList( pStm, dwStringCount, aszStringList );
  4274. if ( hr != S_OK )
  4275. {
  4276. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to write computer WQL filter names.")) );
  4277. goto Exit;
  4278. }
  4279. // Save the user name/
  4280. // fyi, This is not used in diagnostic mode archive data
  4281. LPTSTR szUserNameOrSid = NULL;
  4282. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4283. {
  4284. szUserNameOrSid = m_pRSOPQuery->pUser->szName;
  4285. }
  4286. else
  4287. {
  4288. // RM: (See Load method)
  4289. szUserNameOrSid = m_pRSOPQuery->szUserSid;
  4290. }
  4291. hr = SaveString( pStm, szUserNameOrSid );
  4292. if (hr != S_OK)
  4293. {
  4294. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save user name with %d."), hr));
  4295. goto Exit;
  4296. }
  4297. // Save the user display name (only used in logging mode)
  4298. LPTSTR szUserDisplayName = NULL;
  4299. if ( m_pRSOPQuery->QueryType == RSOP_LOGGING_MODE )
  4300. {
  4301. if ( 0 == lstrcmpi( m_pRSOPQuery->szUserSid, TEXT(".") ) )
  4302. {
  4303. szUserDisplayName = m_pRSOPQuery->szUserSid;
  4304. }
  4305. else
  4306. {
  4307. szUserDisplayName = m_pRSOPQuery->szUserName;
  4308. }
  4309. if ( m_bArchiveData && !lstrcmpi( m_pRSOPQuery->szUserSid, TEXT(".") ) )
  4310. {
  4311. LPTSTR lpSaveTemp;
  4312. lpSaveTemp = MyGetUserName (NameSamCompatible);
  4313. if ( lpSaveTemp == NULL )
  4314. {
  4315. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to get user name for archived data.")) );
  4316. hr = E_FAIL;
  4317. goto Exit;
  4318. }
  4319. hr = SaveString (pStm, lpSaveTemp);
  4320. LocalFree (lpSaveTemp);
  4321. }
  4322. else
  4323. {
  4324. hr = SaveString (pStm, szUserDisplayName );
  4325. }
  4326. }
  4327. else
  4328. {
  4329. hr = SaveString( pStm, szUserDisplayName );
  4330. }
  4331. if (hr != S_OK)
  4332. {
  4333. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save user display name with %d."), hr));
  4334. goto Exit;
  4335. }
  4336. // Save the user SOM
  4337. LPTSTR szUserSOM = NULL;
  4338. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4339. {
  4340. szUserSOM = m_pRSOPQuery->pUser->szSOM;
  4341. }
  4342. hr = SaveString (pStm, szUserSOM);
  4343. if (hr != S_OK)
  4344. {
  4345. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save user SOM with %d."), hr));
  4346. goto Exit;
  4347. }
  4348. // Save the user security groups
  4349. dwStringCount = 0;
  4350. aszStringList = NULL;
  4351. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4352. {
  4353. dwStringCount = m_pRSOPQuery->pUser->dwSecurityGroupCount;
  4354. aszStringList = m_pRSOPQuery->pUser->aszSecurityGroups;
  4355. }
  4356. hr = SaveStringList( pStm, dwStringCount, aszStringList );
  4357. if ( hr != S_OK )
  4358. {
  4359. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to write user security groups.")) );
  4360. goto Exit;
  4361. }
  4362. // Save the user WQL filters
  4363. dwStringCount = 0;
  4364. aszStringList = NULL;
  4365. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4366. {
  4367. dwStringCount = m_pRSOPQuery->pUser->dwWQLFilterCount;
  4368. aszStringList = m_pRSOPQuery->pUser->aszWQLFilters;
  4369. }
  4370. hr = SaveStringList( pStm, dwStringCount, aszStringList );
  4371. if ( hr != S_OK )
  4372. {
  4373. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to write user WQL filters.")) );
  4374. goto Exit;
  4375. }
  4376. // Save the user WQL filter names
  4377. dwStringCount = 0;
  4378. aszStringList = NULL;
  4379. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4380. {
  4381. dwStringCount = m_pRSOPQuery->pUser->dwWQLFilterCount;
  4382. aszStringList = m_pRSOPQuery->pUser->aszWQLFilterNames;
  4383. }
  4384. hr = SaveStringList( pStm, dwStringCount, aszStringList );
  4385. if ( hr != S_OK )
  4386. {
  4387. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to write user WQL filter names.")) );
  4388. goto Exit;
  4389. }
  4390. // Save the site
  4391. LPTSTR szSite = NULL;
  4392. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4393. {
  4394. szSite = m_pRSOPQuery->szSite;
  4395. }
  4396. hr = SaveString( pStm, szSite );
  4397. if (hr != S_OK)
  4398. {
  4399. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save site with %d."), hr));
  4400. goto Exit;
  4401. }
  4402. // Save the DC
  4403. LPTSTR szDomainController = NULL;
  4404. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4405. {
  4406. szDomainController = m_pRSOPQuery->szDomainController;
  4407. }
  4408. hr = SaveString( pStm, szDomainController );
  4409. if (hr != S_OK)
  4410. {
  4411. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Failed to save DC with %d."), hr));
  4412. goto Exit;
  4413. }
  4414. // Save the WMI and event log data if appropriate
  4415. if (m_bArchiveData)
  4416. {
  4417. lpComputerData = CreateTempFile();
  4418. if (!lpComputerData)
  4419. {
  4420. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: CreateTempFile failed with %d."), GetLastError()));
  4421. hr = HRESULT_FROM_WIN32(GetLastError());
  4422. goto Exit;
  4423. }
  4424. ULONG ulNoRemChars = 0;
  4425. hr = StringCchCopy (szPath, ARRAYSIZE(szPath),m_pRSOPQueryResults->szWMINameSpace );
  4426. if (SUCCEEDED(hr))
  4427. {
  4428. lpTemp = CheckSlash (szPath);
  4429. ulNoRemChars = ARRAYSIZE(szPath) - lstrlen(szPath);
  4430. hr = StringCchCat (szPath, ARRAYSIZE(szPath), COMPUTER_SECTION);
  4431. }
  4432. if (FAILED(hr))
  4433. {
  4434. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Could not copy WMI name space with %d."), hr));
  4435. goto Exit;
  4436. }
  4437. hr = ExportRSoPData (szPath, lpComputerData);
  4438. if (hr != S_OK)
  4439. {
  4440. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: ExportRSoPData failed with 0x%x."), hr));
  4441. goto Exit;
  4442. }
  4443. hr = CopyFileToMSC (lpComputerData, pStm);
  4444. if (hr != S_OK)
  4445. {
  4446. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: CopyFileToMSC failed with 0x%x."), hr));
  4447. goto Exit;
  4448. }
  4449. lpUserData = CreateTempFile();
  4450. if (!lpUserData)
  4451. {
  4452. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: CreateTempFile failed with %d."), GetLastError()));
  4453. hr = HRESULT_FROM_WIN32(GetLastError());
  4454. goto Exit;
  4455. }
  4456. hr = StringCchCopy (lpTemp, ulNoRemChars, USER_SECTION);
  4457. if (FAILED(hr))
  4458. {
  4459. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: Could not copy WMI name space with %d."), hr));
  4460. goto Exit;
  4461. }
  4462. hr = ExportRSoPData (szPath, lpUserData);
  4463. if (hr != S_OK)
  4464. {
  4465. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: ExportRSoPData failed with 0x%x."), hr));
  4466. goto Exit;
  4467. }
  4468. hr = CopyFileToMSC (lpUserData, pStm);
  4469. if (hr != S_OK)
  4470. {
  4471. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: CopyFileToMSC failed with 0x%x."), hr));
  4472. goto Exit;
  4473. }
  4474. // Save the event log entries
  4475. hr = m_CSELists.GetEvents()->SaveEntriesToStream(pStm);
  4476. if (hr != S_OK)
  4477. {
  4478. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Save: SaveEntriesToStream failed with 0x%x."), hr));
  4479. goto Exit;
  4480. }
  4481. }
  4482. if (fClearDirty)
  4483. {
  4484. ClearDirty();
  4485. }
  4486. Exit:
  4487. if (lpUserData)
  4488. {
  4489. DeleteFile (lpUserData);
  4490. delete [] lpUserData;
  4491. }
  4492. if (lpComputerData)
  4493. {
  4494. DeleteFile (lpComputerData);
  4495. delete [] lpComputerData;
  4496. }
  4497. return hr;
  4498. }
  4499. //-------------------------------------------------------
  4500. STDMETHODIMP CRSOPComponentData::GetSizeMax(ULARGE_INTEGER *pcbSize)
  4501. {
  4502. return E_NOTIMPL;
  4503. }
  4504. //-------------------------------------------------------
  4505. STDMETHODIMP CRSOPComponentData::InitNew(void)
  4506. {
  4507. return S_OK;
  4508. }
  4509. //-------------------------------------------------------
  4510. // IPersistStreamInit helper methods
  4511. STDMETHODIMP CRSOPComponentData::CopyFileToMSC (LPTSTR lpFileName, IStream *pStm)
  4512. {
  4513. ULONG nBytesWritten;
  4514. WIN32_FILE_ATTRIBUTE_DATA info;
  4515. ULARGE_INTEGER FileSize, SubtractAmount;
  4516. HANDLE hFile;
  4517. DWORD dwError, dwReadAmount, dwRead;
  4518. LPBYTE lpData;
  4519. HRESULT hr;
  4520. // Get the file size
  4521. if (!GetFileAttributesEx (lpFileName, GetFileExInfoStandard, &info))
  4522. {
  4523. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: Failed to get file attributes with %d."), GetLastError()));
  4524. return HRESULT_FROM_WIN32(GetLastError());
  4525. }
  4526. FileSize.LowPart = info.nFileSizeLow;
  4527. FileSize.HighPart = info.nFileSizeHigh;
  4528. // Save the file size
  4529. hr = pStm->Write(&FileSize, sizeof(FileSize), &nBytesWritten);
  4530. if (hr != S_OK)
  4531. {
  4532. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: Failed to write string length with %d."), hr));
  4533. return hr;
  4534. }
  4535. if (nBytesWritten != sizeof(FileSize))
  4536. {
  4537. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: Failed to write the correct amount of data.")));
  4538. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  4539. }
  4540. // Allocate a buffer to use for the transfer
  4541. lpData = (LPBYTE) LocalAlloc (LPTR, 4096);
  4542. if (!lpData)
  4543. {
  4544. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: Failed to allocate memory with %d."), GetLastError()));
  4545. return HRESULT_FROM_WIN32(GetLastError());
  4546. }
  4547. // Open the temp file
  4548. hFile = CreateFile (lpFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING,
  4549. FILE_ATTRIBUTE_NORMAL, NULL);
  4550. if (hFile == INVALID_HANDLE_VALUE)
  4551. {
  4552. dwError = GetLastError();
  4553. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: CreateFile for %s failed with %d"), lpFileName, dwError));
  4554. LocalFree (lpData);
  4555. return HRESULT_FROM_WIN32(dwError);
  4556. }
  4557. while (FileSize.QuadPart)
  4558. {
  4559. // Determine how much to read
  4560. dwReadAmount = (FileSize.QuadPart > 4096) ? 4096 : FileSize.LowPart;
  4561. // Read from the temp file
  4562. if (!ReadFile (hFile, lpData, dwReadAmount, &dwRead, NULL))
  4563. {
  4564. dwError = GetLastError();
  4565. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: ReadFile failed with %d"), dwError));
  4566. LocalFree (lpData);
  4567. CloseHandle (hFile);
  4568. return HRESULT_FROM_WIN32(dwError);
  4569. }
  4570. // Make sure we read enough
  4571. if (dwReadAmount != dwRead)
  4572. {
  4573. dwError = ERROR_INVALID_DATA;
  4574. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: Failed to read enough data")));
  4575. LocalFree (lpData);
  4576. CloseHandle (hFile);
  4577. return HRESULT_FROM_WIN32(dwError);
  4578. }
  4579. // Write to the stream
  4580. hr = pStm->Write(lpData, dwReadAmount, &nBytesWritten);
  4581. if (hr != S_OK)
  4582. {
  4583. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: Failed to write data with %d."), hr));
  4584. LocalFree (lpData);
  4585. CloseHandle (hFile);
  4586. return hr;
  4587. }
  4588. if (nBytesWritten != dwReadAmount)
  4589. {
  4590. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyFileToMSC: Failed to write the correct amount of data.")));
  4591. LocalFree (lpData);
  4592. CloseHandle (hFile);
  4593. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  4594. }
  4595. SubtractAmount.LowPart = dwReadAmount;
  4596. SubtractAmount.HighPart = 0;
  4597. FileSize.QuadPart = FileSize.QuadPart - SubtractAmount.QuadPart;
  4598. }
  4599. CloseHandle (hFile);
  4600. LocalFree (lpData);
  4601. return S_OK;
  4602. }
  4603. //-------------------------------------------------------
  4604. STDMETHODIMP CRSOPComponentData::CreateNameSpace (LPTSTR lpNameSpace, LPTSTR lpParentNameSpace)
  4605. {
  4606. IWbemLocator *pIWbemLocator;
  4607. IWbemServices *pIWbemServices;
  4608. IWbemClassObject *pIWbemClassObject = NULL, *pObject = NULL;
  4609. VARIANT var;
  4610. BSTR bstrName, bstrNameProp;
  4611. HRESULT hr;
  4612. // Create a locater instance
  4613. hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER,
  4614. IID_IWbemLocator, (LPVOID *) &pIWbemLocator);
  4615. if (FAILED(hr))
  4616. {
  4617. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: CoCreateInstance failed with 0x%x"), hr));
  4618. return hr;
  4619. }
  4620. // Connect to the server
  4621. BSTR bstrParentNamespace = SysAllocString( lpParentNameSpace );
  4622. if ( bstrParentNamespace == NULL )
  4623. {
  4624. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::BuildGPOList: Failed to allocate BSTR memory.")));
  4625. pIWbemLocator->Release();
  4626. return E_OUTOFMEMORY;
  4627. }
  4628. hr = pIWbemLocator->ConnectServer(bstrParentNamespace, NULL, NULL, 0, 0, NULL, NULL, &pIWbemServices);
  4629. SysFreeString( bstrParentNamespace );
  4630. if (FAILED(hr))
  4631. {
  4632. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: ConnectServer to %s failed with 0x%x"), lpNameSpace, hr));
  4633. pIWbemLocator->Release();
  4634. return hr;
  4635. }
  4636. // Get the namespace class
  4637. bstrName = SysAllocString (TEXT("__Namespace"));
  4638. if (!bstrName)
  4639. {
  4640. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: SysAllocString failed with %d"), GetLastError()));
  4641. pIWbemServices->Release();
  4642. pIWbemLocator->Release();
  4643. return hr;
  4644. }
  4645. hr = pIWbemServices->GetObject( bstrName, 0, NULL, &pIWbemClassObject, NULL);
  4646. SysFreeString (bstrName);
  4647. if (FAILED(hr)) {
  4648. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: GetObject failed with 0x%x"), hr));
  4649. pIWbemServices->Release();
  4650. pIWbemLocator->Release();
  4651. return hr;
  4652. }
  4653. // Spawn Instance
  4654. hr = pIWbemClassObject->SpawnInstance(0, &pObject);
  4655. if (FAILED(hr)) {
  4656. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: SpawnInstance failed with 0x%x"), hr));
  4657. pIWbemServices->Release();
  4658. pIWbemLocator->Release();
  4659. return hr;
  4660. }
  4661. // Convert new namespace to a bstr
  4662. bstrName = SysAllocString (lpNameSpace);
  4663. if (!bstrName)
  4664. {
  4665. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: SysAllocString failed with %d"), GetLastError()));
  4666. pObject->Release();
  4667. pIWbemServices->Release();
  4668. pIWbemLocator->Release();
  4669. return hr;
  4670. }
  4671. // Set the display name
  4672. var.vt = VT_BSTR;
  4673. var.bstrVal = bstrName;
  4674. bstrNameProp = SysAllocString (TEXT("Name"));
  4675. if (!bstrNameProp)
  4676. {
  4677. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: SysAllocString failed with %d"), GetLastError()));
  4678. pObject->Release();
  4679. pIWbemServices->Release();
  4680. pIWbemLocator->Release();
  4681. return hr;
  4682. }
  4683. hr = pObject->Put( bstrNameProp, 0, &var, 0 );
  4684. SysFreeString (bstrNameProp);
  4685. if (FAILED(hr)) {
  4686. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: Put failed with 0x%x"), hr));
  4687. SysFreeString (bstrName);
  4688. pObject->Release();
  4689. pIWbemServices->Release();
  4690. pIWbemLocator->Release();
  4691. return hr;
  4692. }
  4693. // Commit the instance
  4694. hr = pIWbemServices->PutInstance( pObject, WBEM_FLAG_CREATE_OR_UPDATE, NULL, NULL );
  4695. if (FAILED(hr)) {
  4696. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CreateNameSpace: PutInstance failed with 0x%x"), hr));
  4697. }
  4698. SysFreeString (bstrName);
  4699. pObject->Release();
  4700. pIWbemServices->Release();
  4701. pIWbemLocator->Release();
  4702. return hr;
  4703. }
  4704. //-------------------------------------------------------
  4705. STDMETHODIMP CRSOPComponentData::CopyMSCToFile (IStream *pStm, LPTSTR *lpMofFileName)
  4706. {
  4707. HRESULT hr;
  4708. LPTSTR lpFileName;
  4709. ULARGE_INTEGER FileSize, SubtractAmount;
  4710. ULONG nBytesRead;
  4711. LPBYTE lpData;
  4712. DWORD dwError, dwReadAmount, dwRead, dwBytesWritten;
  4713. HANDLE hFile;
  4714. // Get the filename to work with
  4715. lpFileName = CreateTempFile();
  4716. if (!lpFileName)
  4717. {
  4718. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyMSCToFile: Failed to create temp filename with %d"), GetLastError()));
  4719. return HRESULT_FROM_WIN32(GetLastError());
  4720. }
  4721. // Read in the data length
  4722. hr = pStm->Read(&FileSize, sizeof(FileSize), &nBytesRead);
  4723. if ((hr != S_OK) || (nBytesRead != sizeof(FileSize)))
  4724. {
  4725. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyMSCToFile: Failed to read data size with 0x%x."), hr));
  4726. return E_FAIL;
  4727. }
  4728. // Allocate a buffer to use for the transfer
  4729. lpData = (LPBYTE) LocalAlloc (LPTR, 4096);
  4730. if (!lpData)
  4731. {
  4732. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyMSCToFile: Failed to allocate memory with %d."), GetLastError()));
  4733. return HRESULT_FROM_WIN32(GetLastError());
  4734. }
  4735. // Open the temp file
  4736. hFile = CreateFile (lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
  4737. FILE_ATTRIBUTE_NORMAL, NULL);
  4738. if (hFile == INVALID_HANDLE_VALUE)
  4739. {
  4740. dwError = GetLastError();
  4741. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyMSCToFile: CreateFile for %s failed with %d"), lpFileName, dwError));
  4742. LocalFree (lpData);
  4743. return HRESULT_FROM_WIN32(dwError);
  4744. }
  4745. while (FileSize.QuadPart)
  4746. {
  4747. // Determine how much to read
  4748. dwReadAmount = (FileSize.QuadPart > 4096) ? 4096 : FileSize.LowPart;
  4749. // Read from the msc file
  4750. hr = pStm->Read(lpData, dwReadAmount, &nBytesRead);
  4751. if ((hr != S_OK) || (nBytesRead != dwReadAmount))
  4752. {
  4753. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyMSCToFile: Read failed with 0x%x"), hr));
  4754. LocalFree (lpData);
  4755. CloseHandle (hFile);
  4756. return hr;
  4757. }
  4758. // Write to the temp file
  4759. if (!WriteFile(hFile, lpData, dwReadAmount, &dwBytesWritten, NULL))
  4760. {
  4761. dwError = GetLastError();
  4762. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyMSCToFile: Failed to write data with %d."), dwError));
  4763. LocalFree (lpData);
  4764. CloseHandle (hFile);
  4765. return HRESULT_FROM_WIN32(dwError);
  4766. }
  4767. if (dwBytesWritten != dwReadAmount)
  4768. {
  4769. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::CopyMSCToFile: Failed to write the correct amount of data.")));
  4770. LocalFree (lpData);
  4771. CloseHandle (hFile);
  4772. return HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
  4773. }
  4774. SubtractAmount.LowPart = dwReadAmount;
  4775. SubtractAmount.HighPart = 0;
  4776. FileSize.QuadPart = FileSize.QuadPart - SubtractAmount.QuadPart;
  4777. }
  4778. CloseHandle (hFile);
  4779. LocalFree (lpData);
  4780. *lpMofFileName = lpFileName;
  4781. return S_OK;
  4782. }
  4783. //-------------------------------------------------------
  4784. STDMETHODIMP CRSOPComponentData::BuildDisplayName (void)
  4785. {
  4786. TCHAR szArchiveData[100];
  4787. TCHAR szBuffer[MAX_PATH];
  4788. TCHAR szComputerNameBuffer[100];
  4789. LPTSTR szUserName, szComputerName, lpEnd;
  4790. LPTSTR szUserOU, szComputerOU;
  4791. DWORD dwSize;
  4792. int n;
  4793. // Make the display name (needs to handle empty names)
  4794. if (m_bViewIsArchivedData)
  4795. {
  4796. LoadString(g_hInstance, IDS_ARCHIVEDATATAG, szArchiveData, ARRAYSIZE(szArchiveData));
  4797. }
  4798. else
  4799. {
  4800. szArchiveData[0] = TEXT('\0');
  4801. }
  4802. szUserName = NULL;
  4803. szUserOU = NULL;
  4804. if ( !m_pRSOPQueryResults->bNoUserPolicyData )
  4805. {
  4806. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4807. {
  4808. if ( m_pRSOPQuery->pUser->szName != NULL )
  4809. {
  4810. szUserName = NameWithoutDomain( m_pRSOPQuery->pUser->szName );
  4811. }
  4812. else if ( m_pRSOPQuery->pUser->szSOM )
  4813. {
  4814. szUserOU = GetContainerFromLDAPPath( m_pRSOPQuery->pUser->szSOM );
  4815. szUserName = szUserOU;
  4816. }
  4817. }
  4818. else if ( m_pRSOPQuery->szUserName != NULL )
  4819. {
  4820. szUserName = NameWithoutDomain( m_pRSOPQuery->szUserName );
  4821. }
  4822. }
  4823. szComputerName = NULL;
  4824. szComputerOU = NULL;
  4825. if ( !m_pRSOPQueryResults->bNoComputerPolicyData )
  4826. {
  4827. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  4828. {
  4829. if ( m_pRSOPQuery->pComputer->szName != NULL )
  4830. {
  4831. szComputerName = m_pRSOPQuery->pComputer->szName;
  4832. }
  4833. else if ( m_pRSOPQuery->pComputer->szSOM != NULL )
  4834. {
  4835. szComputerOU = GetContainerFromLDAPPath( m_pRSOPQuery->pComputer->szSOM );
  4836. }
  4837. }
  4838. else if ( m_pRSOPQuery->szComputerName != NULL )
  4839. {
  4840. szComputerName = m_pRSOPQuery->szComputerName;
  4841. }
  4842. // Format computer name if necessary
  4843. if ( szComputerName != NULL )
  4844. {
  4845. if ( !lstrcmpi(szComputerName, TEXT(".")) )
  4846. {
  4847. szComputerNameBuffer[0] = TEXT('\0');
  4848. dwSize = ARRAYSIZE(szComputerNameBuffer);
  4849. GetComputerNameEx (ComputerNameNetBIOS, szComputerNameBuffer, &dwSize);
  4850. szComputerName = szComputerNameBuffer;
  4851. }
  4852. else
  4853. {
  4854. lstrcpyn (szComputerNameBuffer, NameWithoutDomain(szComputerName),
  4855. ARRAYSIZE(szComputerNameBuffer));
  4856. szComputerName = szComputerNameBuffer;
  4857. lpEnd = szComputerName + lstrlen(szComputerName) - 1;
  4858. if (*lpEnd == TEXT('$'))
  4859. {
  4860. *lpEnd = TEXT('\0');
  4861. }
  4862. }
  4863. }
  4864. else if ( szComputerOU != NULL )
  4865. {
  4866. szComputerName = szComputerOU;
  4867. }
  4868. }
  4869. if ( (szUserName != NULL) && (szComputerName != NULL) )
  4870. {
  4871. LoadString(g_hInstance, IDS_RSOP_DISPLAYNAME1, szBuffer, ARRAYSIZE(szBuffer));
  4872. n = wcslen(szBuffer) + wcslen (szArchiveData) +
  4873. wcslen(szUserName) + wcslen(szComputerName) + 1;
  4874. m_szDisplayName = new WCHAR[n];
  4875. if (m_szDisplayName)
  4876. {
  4877. (void) StringCchPrintf(m_szDisplayName, n, szBuffer, szUserName, szComputerName);
  4878. }
  4879. }
  4880. else if ( (szUserName != NULL) && (szComputerName == NULL) )
  4881. {
  4882. LoadString(g_hInstance, IDS_RSOP_DISPLAYNAME2, szBuffer, ARRAYSIZE(szBuffer));
  4883. n = wcslen(szBuffer) + wcslen (szArchiveData) +
  4884. wcslen(szUserName) + 1;
  4885. m_szDisplayName = new WCHAR[n];
  4886. if (m_szDisplayName)
  4887. {
  4888. (void) StringCchPrintf (m_szDisplayName, n, szBuffer, szUserName);
  4889. }
  4890. }
  4891. else
  4892. {
  4893. LoadString(g_hInstance, IDS_RSOP_DISPLAYNAME2, szBuffer, ARRAYSIZE(szBuffer));
  4894. n = wcslen(szBuffer) + wcslen (szArchiveData) +
  4895. (szComputerName ? wcslen(szComputerName) : 0) + 1;
  4896. m_szDisplayName = new WCHAR[n];
  4897. if (m_szDisplayName)
  4898. {
  4899. (void) StringCchPrintf (m_szDisplayName, n, szBuffer, (szComputerName ? szComputerName : L""));
  4900. }
  4901. }
  4902. if ( (m_szDisplayName != NULL) && m_bViewIsArchivedData)
  4903. {
  4904. (void) StringCchCat (m_szDisplayName, n, szArchiveData);
  4905. }
  4906. if ( szUserOU != NULL )
  4907. {
  4908. delete [] szUserOU;
  4909. }
  4910. if ( szComputerOU != NULL )
  4911. {
  4912. delete [] szComputerOU;
  4913. }
  4914. return S_OK;
  4915. }
  4916. //-------------------------------------------------------
  4917. HRESULT CRSOPComponentData::LoadStringList( IStream* pStm, DWORD* pCount, LPTSTR** paszStringList )
  4918. {
  4919. HRESULT hr = S_OK;
  4920. DWORD dwStringCount = 0;
  4921. DWORD dwIndex = 0;
  4922. ULONG nBytesRead;
  4923. // Read in the list count
  4924. hr = pStm->Read( &dwStringCount, sizeof(dwStringCount), &nBytesRead );
  4925. if ( (hr != S_OK) || (nBytesRead != sizeof(dwStringCount)) )
  4926. {
  4927. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::LoadStringList: Failed to read string list count with 0x%x."), hr));
  4928. hr = E_FAIL;
  4929. }
  4930. // Read in the security groups
  4931. else if ( dwStringCount != 0 )
  4932. {
  4933. (*paszStringList) = (LPTSTR*)LocalAlloc( LPTR, sizeof(LPTSTR)*dwStringCount );
  4934. if ( (*paszStringList) == NULL )
  4935. {
  4936. DebugMsg( (DM_WARNING, TEXT("CRSOPComponentData::LoadBSTRList: Failed to allocate memory for string list with 0x%x."),
  4937. HRESULT_FROM_WIN32(GetLastError()) ) );
  4938. hr = E_FAIL;
  4939. }
  4940. else
  4941. {
  4942. LPTSTR szString = NULL;
  4943. for ( dwIndex = 0; dwIndex < dwStringCount; dwIndex++ )
  4944. {
  4945. hr = ReadString( pStm, &szString, TRUE );
  4946. if (hr != S_OK)
  4947. {
  4948. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::Load: Failed to read string with 0x%x."), hr));
  4949. hr = E_FAIL;
  4950. goto ErrorExit;
  4951. }
  4952. (*paszStringList)[dwIndex] = szString;
  4953. }
  4954. *pCount = dwStringCount;
  4955. }
  4956. }
  4957. return hr;
  4958. ErrorExit:
  4959. // Free allocated memory
  4960. for ( DWORD dwClearIndex = 0; dwClearIndex < dwIndex; dwClearIndex++ )
  4961. {
  4962. LocalFree( (*paszStringList)[dwClearIndex] );
  4963. paszStringList[dwClearIndex] = 0;
  4964. }
  4965. LocalFree( *paszStringList );
  4966. *paszStringList = NULL;
  4967. return hr;
  4968. }
  4969. //-------------------------------------------------------
  4970. HRESULT CRSOPComponentData::SaveStringList( IStream* pStm, DWORD dwCount, LPTSTR* aszStringList )
  4971. {
  4972. HRESULT hr = S_OK;
  4973. ULONG nBytesWritten;
  4974. // Write the count
  4975. hr = pStm->Write( &dwCount, sizeof(dwCount), &nBytesWritten );
  4976. if ( (hr != S_OK) || (nBytesWritten != sizeof(dwCount)) )
  4977. {
  4978. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::SaveStringList: Failed to write string list count with %d."), hr));
  4979. return E_FAIL;
  4980. }
  4981. // If there are strings to write, do so
  4982. if ( dwCount != 0 )
  4983. {
  4984. DWORD dwIndex;
  4985. for ( dwIndex = 0; dwIndex < dwCount; dwIndex++ )
  4986. {
  4987. hr = SaveString( pStm, aszStringList[dwIndex] );
  4988. if (hr != S_OK)
  4989. {
  4990. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::SaveStringList: Failed to save string list with %d."), hr));
  4991. return E_FAIL;
  4992. }
  4993. }
  4994. }
  4995. return S_OK;
  4996. }
  4997. //-------------------------------------------------------
  4998. // Helpers for IRSOPInformation
  4999. STDMETHODIMP CRSOPComponentData::GetNamespace (DWORD dwSection, LPOLESTR pszName, int cchMaxLength)
  5000. {
  5001. TCHAR szPath[2*MAX_PATH];
  5002. LPTSTR lpEnd;
  5003. //
  5004. // Check parameters
  5005. //
  5006. if (!pszName || (cchMaxLength <= 0))
  5007. return E_INVALIDARG;
  5008. if (!m_bInitialized)
  5009. {
  5010. return OLE_E_BLANK;
  5011. }
  5012. if ((dwSection != GPO_SECTION_ROOT) &&
  5013. (dwSection != GPO_SECTION_USER) &&
  5014. (dwSection != GPO_SECTION_MACHINE))
  5015. return E_INVALIDARG;
  5016. //
  5017. // Build the path
  5018. //
  5019. HRESULT hr = StringCchCopy ( szPath, ARRAYSIZE(szPath), m_pRSOPQueryResults->szWMINameSpace );
  5020. if (FAILED(hr))
  5021. {
  5022. return hr;
  5023. }
  5024. if (dwSection != GPO_SECTION_ROOT)
  5025. {
  5026. if (dwSection == GPO_SECTION_USER)
  5027. {
  5028. lpEnd = CheckSlash (szPath);
  5029. hr = StringCchCat (szPath, ARRAYSIZE(szPath), USER_SECTION);
  5030. }
  5031. else if (dwSection == GPO_SECTION_MACHINE)
  5032. {
  5033. lpEnd = CheckSlash (szPath);
  5034. hr = StringCchCat (szPath, ARRAYSIZE(szPath), COMPUTER_SECTION);
  5035. }
  5036. else
  5037. {
  5038. return E_INVALIDARG;
  5039. }
  5040. if (FAILED(hr))
  5041. {
  5042. return hr;
  5043. }
  5044. }
  5045. //
  5046. // Save the name
  5047. //
  5048. if ((lstrlen (szPath) + 1) <= cchMaxLength)
  5049. {
  5050. hr = StringCchCopy (pszName, cchMaxLength, szPath);
  5051. return hr;
  5052. }
  5053. return E_OUTOFMEMORY;
  5054. }
  5055. //-------------------------------------------------------
  5056. STDMETHODIMP CRSOPComponentData::GetFlags (DWORD * pdwFlags)
  5057. {
  5058. if (!pdwFlags)
  5059. {
  5060. return E_INVALIDARG;
  5061. }
  5062. *pdwFlags = 0;
  5063. if ( (m_pRSOPQuery != NULL) && (m_pRSOPQuery->QueryType == RSOP_LOGGING_MODE) )
  5064. {
  5065. *pdwFlags = RSOP_INFO_FLAG_DIAGNOSTIC_MODE;
  5066. }
  5067. return S_OK;
  5068. }
  5069. //-------------------------------------------------------
  5070. STDMETHODIMP CRSOPComponentData::GetEventLogEntryText (LPOLESTR pszEventSource,
  5071. LPOLESTR pszEventLogName,
  5072. LPOLESTR pszEventTime,
  5073. DWORD dwEventID,
  5074. LPOLESTR *ppszText)
  5075. {
  5076. return ( m_CSELists.GetEvents() ? m_CSELists.GetEvents()->GetEventLogEntryText(pszEventSource, pszEventLogName, pszEventTime,
  5077. dwEventID, ppszText) : E_NOINTERFACE);
  5078. }
  5079. //-------------------------------------------------------
  5080. // CRSOPComponentData object implementation (ISnapinHelp)
  5081. STDMETHODIMP CRSOPComponentData::GetHelpTopic(LPOLESTR *lpCompiledHelpFile)
  5082. {
  5083. LPOLESTR lpHelpFile;
  5084. lpHelpFile = (LPOLESTR) CoTaskMemAlloc (MAX_PATH * sizeof(WCHAR));
  5085. if (!lpHelpFile)
  5086. {
  5087. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::GetHelpTopic: Failed to allocate memory.")));
  5088. return E_OUTOFMEMORY;
  5089. }
  5090. ExpandEnvironmentStringsW (L"%SystemRoot%\\Help\\rsopsnp.chm",
  5091. lpHelpFile, MAX_PATH);
  5092. *lpCompiledHelpFile = lpHelpFile;
  5093. return S_OK;
  5094. }
  5095. //-------------------------------------------------------
  5096. HRESULT CRSOPComponentData::SetupFonts()
  5097. {
  5098. HRESULT hr;
  5099. LOGFONT BigBoldLogFont;
  5100. LOGFONT BoldLogFont;
  5101. HDC pdc = NULL;
  5102. WCHAR largeFontSizeString[128];
  5103. INT largeFontSize;
  5104. WCHAR smallFontSizeString[128];
  5105. INT smallFontSize;
  5106. // Create the fonts we need based on the dialog font
  5107. NONCLIENTMETRICS ncm = {0};
  5108. ncm.cbSize = sizeof (ncm);
  5109. if (SystemParametersInfo (SPI_GETNONCLIENTMETRICS, 0, &ncm, 0) == FALSE) {
  5110. hr = HRESULT_FROM_WIN32(GetLastError());
  5111. goto end;
  5112. }
  5113. BigBoldLogFont = ncm.lfMessageFont;
  5114. BoldLogFont = ncm.lfMessageFont;
  5115. // Create Big Bold Font and Bold Font
  5116. BigBoldLogFont.lfWeight = FW_BOLD;
  5117. BoldLogFont.lfWeight = FW_BOLD;
  5118. // Load size and name from resources, since these may change
  5119. // from locale to locale based on the size of the system font, etc.
  5120. if ( !LoadString (g_hInstance, IDS_LARGEFONTNAME, BigBoldLogFont.lfFaceName, LF_FACESIZE) )
  5121. {
  5122. ASSERT (0);
  5123. hr = StringCchCopy (BigBoldLogFont.lfFaceName, LF_FACESIZE, L"Verdana");
  5124. if (FAILED(hr))
  5125. {
  5126. goto end;
  5127. }
  5128. }
  5129. if ( LoadString (g_hInstance, IDS_LARGEFONTSIZE, largeFontSizeString, ARRAYSIZE(largeFontSizeString)) )
  5130. {
  5131. largeFontSize = wcstoul ((LPCWSTR) largeFontSizeString, NULL, 10);
  5132. }
  5133. else
  5134. {
  5135. ASSERT (0);
  5136. largeFontSize = 12;
  5137. }
  5138. if ( !LoadString (g_hInstance, IDS_SMALLFONTNAME, BoldLogFont.lfFaceName, LF_FACESIZE) )
  5139. {
  5140. ASSERT (0);
  5141. hr = StringCchCopy (BoldLogFont.lfFaceName, LF_FACESIZE, L"Verdana");
  5142. if (FAILED(hr))
  5143. {
  5144. goto end;
  5145. }
  5146. }
  5147. if ( LoadString (g_hInstance, IDS_SMALLFONTSIZE, smallFontSizeString, ARRAYSIZE(smallFontSizeString)) )
  5148. {
  5149. smallFontSize = wcstoul ((LPCWSTR) smallFontSizeString, NULL, 10);
  5150. }
  5151. else
  5152. {
  5153. ASSERT (0);
  5154. smallFontSize = 8;
  5155. }
  5156. pdc = GetDC (NULL);
  5157. if (pdc == NULL) {
  5158. hr = HRESULT_FROM_WIN32(GetLastError());
  5159. goto end;
  5160. }
  5161. BigBoldLogFont.lfHeight = 0 - (GetDeviceCaps (pdc, LOGPIXELSY) * largeFontSize / 72);
  5162. BoldLogFont.lfHeight = 0 - (GetDeviceCaps (pdc, LOGPIXELSY) * smallFontSize / 72);
  5163. m_BigBoldFont = CreateFontIndirect (&BigBoldLogFont);
  5164. if (m_BigBoldFont == NULL) {
  5165. hr = HRESULT_FROM_WIN32(GetLastError());
  5166. goto end;
  5167. }
  5168. m_BoldFont = CreateFontIndirect (&BoldLogFont);
  5169. if (m_BoldFont == NULL) {
  5170. hr = HRESULT_FROM_WIN32(GetLastError());
  5171. goto end;
  5172. }
  5173. hr = S_OK;
  5174. end:
  5175. if (pdc != NULL) {
  5176. ReleaseDC (NULL, pdc);
  5177. pdc = NULL;
  5178. }
  5179. return hr;
  5180. }
  5181. //-------------------------------------------------------
  5182. INT_PTR CALLBACK CRSOPComponentData::RSOPGPOListMachineProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  5183. {
  5184. WCHAR szBuffer[MAX_PATH];
  5185. CRSOPComponentData* pCD;
  5186. switch (message)
  5187. {
  5188. case WM_INITDIALOG:
  5189. pCD = (CRSOPComponentData*) (((LPPROPSHEETPAGE)lParam)->lParam);
  5190. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pCD);
  5191. LoadString(g_hInstance, IDS_RSOP_GPOLIST_MACHINE, szBuffer, ARRAYSIZE(szBuffer));
  5192. SetDlgItemText(hDlg, IDC_STATIC1, szBuffer);
  5193. if (pCD)
  5194. {
  5195. pCD->FillGPOList(hDlg, IDC_LIST1, pCD->m_GPOLists.GetComputerList(), FALSE, FALSE, FALSE, TRUE);
  5196. }
  5197. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5198. break;
  5199. case WM_COMMAND:
  5200. {
  5201. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5202. if (pCD)
  5203. {
  5204. switch (LOWORD(wParam))
  5205. {
  5206. case IDC_CHECK1:
  5207. case IDC_CHECK2:
  5208. case IDC_CHECK3:
  5209. {
  5210. pCD->FillGPOList(hDlg,
  5211. IDC_LIST1,
  5212. pCD->m_GPOLists.GetComputerList(),
  5213. (BOOL) SendMessage(GetDlgItem(hDlg, IDC_CHECK1), BM_GETCHECK, 0, 0),
  5214. (BOOL) SendMessage(GetDlgItem(hDlg, IDC_CHECK2), BM_GETCHECK, 0, 0),
  5215. (BOOL) SendMessage(GetDlgItem(hDlg, IDC_CHECK3), BM_GETCHECK, 0, 0),
  5216. FALSE);
  5217. }
  5218. break;
  5219. case IDC_BUTTON2:
  5220. case IDM_GPOLIST_EDIT:
  5221. pCD->OnEdit(hDlg);
  5222. break;
  5223. case IDC_BUTTON1:
  5224. case IDM_GPOLIST_SECURITY:
  5225. pCD->OnSecurity(hDlg);
  5226. break;
  5227. }
  5228. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5229. }
  5230. }
  5231. break;
  5232. case WM_NOTIFY:
  5233. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5234. break;
  5235. case WM_REFRESHDISPLAY:
  5236. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5237. if (pCD)
  5238. {
  5239. pCD->OnRefreshDisplay(hDlg);
  5240. }
  5241. break;
  5242. case WM_HELP: // F1
  5243. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  5244. (ULONG_PTR) (LPSTR) aGPOListHelpIds);
  5245. break;
  5246. case WM_CONTEXTMENU:
  5247. if (GetDlgItem(hDlg, IDC_LIST1) == (HWND)wParam)
  5248. {
  5249. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5250. if (pCD)
  5251. {
  5252. pCD->OnContextMenu(hDlg, lParam);
  5253. }
  5254. }
  5255. else
  5256. {
  5257. // right mouse click
  5258. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  5259. (ULONG_PTR) (LPSTR) aGPOListHelpIds);
  5260. }
  5261. return TRUE;
  5262. }
  5263. return FALSE;
  5264. }
  5265. //-------------------------------------------------------
  5266. INT_PTR CALLBACK CRSOPComponentData::RSOPGPOListUserProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  5267. {
  5268. WCHAR szBuffer[MAX_PATH];
  5269. CRSOPComponentData* pCD;
  5270. switch (message)
  5271. {
  5272. case WM_INITDIALOG:
  5273. pCD = (CRSOPComponentData*) (((LPPROPSHEETPAGE)lParam)->lParam);
  5274. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pCD);
  5275. LoadString(g_hInstance, IDS_RSOP_GPOLIST_USER, szBuffer, ARRAYSIZE(szBuffer));
  5276. SetDlgItemText(hDlg, IDC_STATIC1, szBuffer);
  5277. if (pCD)
  5278. {
  5279. pCD->FillGPOList(hDlg, IDC_LIST1, pCD->m_GPOLists.GetUserList(), FALSE, FALSE, FALSE, TRUE);
  5280. }
  5281. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5282. break;
  5283. case WM_COMMAND:
  5284. {
  5285. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5286. if (pCD)
  5287. {
  5288. switch (LOWORD(wParam))
  5289. {
  5290. case IDC_CHECK1:
  5291. case IDC_CHECK2:
  5292. case IDC_CHECK3:
  5293. {
  5294. pCD->FillGPOList(hDlg,
  5295. IDC_LIST1,
  5296. pCD->m_GPOLists.GetUserList(),
  5297. (BOOL) SendMessage(GetDlgItem(hDlg, IDC_CHECK1), BM_GETCHECK, 0, 0),
  5298. (BOOL) SendMessage(GetDlgItem(hDlg, IDC_CHECK2), BM_GETCHECK, 0, 0),
  5299. (BOOL) SendMessage(GetDlgItem(hDlg, IDC_CHECK3), BM_GETCHECK, 0, 0),
  5300. FALSE);
  5301. }
  5302. break;
  5303. case IDC_BUTTON2:
  5304. case IDM_GPOLIST_EDIT:
  5305. pCD->OnEdit(hDlg);
  5306. break;
  5307. case IDC_BUTTON1:
  5308. case IDM_GPOLIST_SECURITY:
  5309. pCD->OnSecurity(hDlg);
  5310. break;
  5311. }
  5312. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5313. }
  5314. }
  5315. break;
  5316. case WM_NOTIFY:
  5317. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5318. break;
  5319. case WM_REFRESHDISPLAY:
  5320. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5321. if (pCD)
  5322. {
  5323. pCD->OnRefreshDisplay(hDlg);
  5324. }
  5325. break;
  5326. case WM_HELP: // F1
  5327. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  5328. (ULONG_PTR) (LPSTR) aGPOListHelpIds);
  5329. break;
  5330. case WM_CONTEXTMENU:
  5331. if (GetDlgItem(hDlg, IDC_LIST1) == (HWND)wParam)
  5332. {
  5333. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5334. if (pCD)
  5335. {
  5336. pCD->OnContextMenu(hDlg, lParam);
  5337. }
  5338. }
  5339. else
  5340. {
  5341. // right mouse click
  5342. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  5343. (ULONG_PTR) (LPSTR) aGPOListHelpIds);
  5344. }
  5345. return TRUE;
  5346. }
  5347. return FALSE;
  5348. }
  5349. //-------------------------------------------------------
  5350. INT_PTR CALLBACK CRSOPComponentData::RSOPErrorsMachineProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  5351. {
  5352. CRSOPComponentData* pCD;
  5353. switch (message)
  5354. {
  5355. case WM_INITDIALOG:
  5356. pCD = (CRSOPComponentData*) (((LPPROPSHEETPAGE)lParam)->lParam);
  5357. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pCD);
  5358. if (pCD)
  5359. {
  5360. pCD->InitializeErrorsDialog(hDlg, pCD->m_CSELists.GetComputerList());
  5361. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5362. }
  5363. break;
  5364. case WM_COMMAND:
  5365. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5366. if (pCD)
  5367. {
  5368. if (LOWORD(wParam) == IDC_BUTTON1)
  5369. {
  5370. pCD->OnSaveAs(hDlg);
  5371. }
  5372. if (LOWORD(wParam) == IDCANCEL)
  5373. {
  5374. SendMessage(GetParent(hDlg), message, wParam, lParam);
  5375. }
  5376. }
  5377. break;
  5378. case WM_NOTIFY:
  5379. {
  5380. LPNMHDR lpHdr = (LPNMHDR)lParam;
  5381. if (lpHdr->code == LVN_ITEMCHANGED)
  5382. {
  5383. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5384. }
  5385. }
  5386. break;
  5387. case WM_REFRESHDISPLAY:
  5388. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5389. if (pCD)
  5390. {
  5391. pCD->RefreshErrorInfo (hDlg);
  5392. }
  5393. break;
  5394. case WM_HELP: // F1
  5395. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  5396. (ULONG_PTR) (LPSTR) aErrorsHelpIds);
  5397. break;
  5398. case WM_CONTEXTMENU:
  5399. // right mouse click
  5400. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  5401. (ULONG_PTR) (LPSTR) aErrorsHelpIds);
  5402. return TRUE;
  5403. }
  5404. return FALSE;
  5405. }
  5406. //-------------------------------------------------------
  5407. INT_PTR CALLBACK CRSOPComponentData::RSOPErrorsUserProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  5408. {
  5409. CRSOPComponentData* pCD;
  5410. switch (message)
  5411. {
  5412. case WM_INITDIALOG:
  5413. pCD = (CRSOPComponentData*) (((LPPROPSHEETPAGE)lParam)->lParam);
  5414. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pCD);
  5415. if (pCD)
  5416. {
  5417. pCD->InitializeErrorsDialog(hDlg, pCD->m_CSELists.GetUserList());
  5418. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5419. }
  5420. break;
  5421. case WM_COMMAND:
  5422. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5423. if (pCD)
  5424. {
  5425. if (LOWORD(wParam) == IDC_BUTTON1)
  5426. {
  5427. pCD->OnSaveAs(hDlg);
  5428. }
  5429. if (LOWORD(wParam) == IDCANCEL)
  5430. {
  5431. SendMessage(GetParent(hDlg), message, wParam, lParam);
  5432. }
  5433. }
  5434. break;
  5435. case WM_NOTIFY:
  5436. {
  5437. LPNMHDR lpHdr = (LPNMHDR)lParam;
  5438. if (lpHdr->code == LVN_ITEMCHANGED)
  5439. {
  5440. PostMessage (hDlg, WM_REFRESHDISPLAY, 0, 0);
  5441. }
  5442. }
  5443. break;
  5444. break;
  5445. case WM_REFRESHDISPLAY:
  5446. pCD = (CRSOPComponentData*) GetWindowLongPtr (hDlg, DWLP_USER);
  5447. if (pCD)
  5448. {
  5449. pCD->RefreshErrorInfo (hDlg);
  5450. }
  5451. break;
  5452. case WM_HELP: // F1
  5453. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  5454. (ULONG_PTR) (LPSTR) aErrorsHelpIds);
  5455. break;
  5456. case WM_CONTEXTMENU:
  5457. // right mouse click
  5458. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  5459. (ULONG_PTR) (LPSTR) aErrorsHelpIds);
  5460. return TRUE;
  5461. }
  5462. return FALSE;
  5463. }
  5464. //-------------------------------------------------------
  5465. INT_PTR CALLBACK CRSOPComponentData::QueryDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  5466. {
  5467. WCHAR szBuffer[MAX_PATH];
  5468. CRSOPComponentData * pCD;
  5469. switch (message)
  5470. {
  5471. case WM_INITDIALOG:
  5472. pCD = (CRSOPComponentData *) (((LPPROPSHEETPAGE)lParam)->lParam);
  5473. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pCD);
  5474. if (pCD)
  5475. {
  5476. CRSOPWizard::InitializeResultsList (GetDlgItem(hDlg, IDC_LIST1));
  5477. CRSOPWizard::FillResultsList (GetDlgItem(hDlg, IDC_LIST1), pCD->m_pRSOPQuery, pCD->m_pRSOPQueryResults);
  5478. }
  5479. break;
  5480. case WM_HELP: // F1
  5481. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  5482. (ULONG_PTR) (LPSTR) aQueryHelpIds);
  5483. break;
  5484. case WM_CONTEXTMENU: // right mouse click
  5485. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  5486. (ULONG_PTR) (LPSTR) aQueryHelpIds);
  5487. return (TRUE);
  5488. }
  5489. return FALSE;
  5490. }
  5491. //-------------------------------------------------------
  5492. // Dialog event handlers
  5493. void CRSOPComponentData::OnEdit(HWND hDlg)
  5494. {
  5495. HWND hLV;
  5496. LVITEM item;
  5497. LPGPOLISTITEM lpItem;
  5498. INT i;
  5499. SHELLEXECUTEINFO ExecInfo;
  5500. TCHAR szArgs[MAX_PATH + 30];
  5501. //
  5502. // Get the selected item (if any)
  5503. //
  5504. hLV = GetDlgItem (hDlg, IDC_LIST1);
  5505. i = ListView_GetNextItem(hLV, -1, LVNI_SELECTED);
  5506. if (i < 0)
  5507. {
  5508. return;
  5509. }
  5510. ZeroMemory (&item, sizeof(item));
  5511. item.mask = LVIF_PARAM;
  5512. item.iItem = i;
  5513. if (!ListView_GetItem (hLV, &item))
  5514. {
  5515. return;
  5516. }
  5517. lpItem = (LPGPOLISTITEM) item.lParam;
  5518. if (lpItem->lpDSPath)
  5519. {
  5520. if (!SpawnGPE(lpItem->lpDSPath, GPHintUnknown, NULL, hDlg))
  5521. {
  5522. ReportError (hDlg, GetLastError(), IDS_SPAWNGPEFAILED);
  5523. }
  5524. }
  5525. else
  5526. {
  5527. ZeroMemory (&ExecInfo, sizeof(ExecInfo));
  5528. ExecInfo.cbSize = sizeof(ExecInfo);
  5529. ExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  5530. ExecInfo.lpVerb = TEXT("open");
  5531. ExecInfo.lpFile = TEXT("gpedit.msc");
  5532. ExecInfo.nShow = SW_SHOWNORMAL;
  5533. LPTSTR szComputerName = NULL;
  5534. if ( m_pRSOPQuery->QueryType == RSOP_PLANNING_MODE )
  5535. {
  5536. szComputerName = m_pRSOPQuery->pComputer->szName;
  5537. }
  5538. else
  5539. {
  5540. szComputerName = m_pRSOPQuery->szComputerName;
  5541. }
  5542. if ( lstrcmpi(szComputerName, TEXT(".")))
  5543. {
  5544. HRESULT hr = StringCchPrintf (szArgs,
  5545. ARRAYSIZE(szArgs),
  5546. TEXT("/gpcomputer:\"%s\" /gphint:1"),
  5547. szComputerName);
  5548. if (FAILED(hr))
  5549. {
  5550. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::OnEdit: Could not copy computer name with %d"), hr));
  5551. ReportError(NULL, GetLastError(), IDS_SPAWNGPEFAILED);
  5552. return;
  5553. }
  5554. ExecInfo.lpParameters = szArgs;
  5555. }
  5556. if (ShellExecuteEx (&ExecInfo))
  5557. {
  5558. SetWaitCursor();
  5559. WaitForInputIdle (ExecInfo.hProcess, 10000);
  5560. ClearWaitCursor();
  5561. CloseHandle (ExecInfo.hProcess);
  5562. }
  5563. else
  5564. {
  5565. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::OnEdit: ShellExecuteEx failed with %d"),
  5566. GetLastError()));
  5567. ReportError(NULL, GetLastError(), IDS_SPAWNGPEFAILED);
  5568. }
  5569. }
  5570. }
  5571. //-------------------------------------------------------
  5572. void CRSOPComponentData::OnSecurity(HWND hDlg)
  5573. {
  5574. HWND hLV;
  5575. INT i;
  5576. HRESULT hr;
  5577. LVITEM item;
  5578. LPGPOLISTITEM lpItem;
  5579. TCHAR szGPOName[MAX_FRIENDLYNAME];
  5580. PROPSHEETHEADER psh;
  5581. HPROPSHEETPAGE hPages[2];
  5582. //
  5583. // Get the selected item (if any)
  5584. //
  5585. hLV = GetDlgItem (hDlg, IDC_LIST1);
  5586. i = ListView_GetNextItem(hLV, -1, LVNI_SELECTED);
  5587. if (i < 0)
  5588. {
  5589. return;
  5590. }
  5591. ZeroMemory (&item, sizeof(item));
  5592. item.mask = LVIF_TEXT | LVIF_PARAM;
  5593. item.iItem = i;
  5594. item.pszText = szGPOName;
  5595. item.cchTextMax = ARRAYSIZE(szGPOName);
  5596. if (!ListView_GetItem (hLV, &item))
  5597. {
  5598. return;
  5599. }
  5600. lpItem = (LPGPOLISTITEM) item.lParam;
  5601. //
  5602. // Create the security page
  5603. //
  5604. hr = DSCreateSecurityPage (lpItem->lpDSPath, L"groupPolicyContainer",
  5605. DSSI_IS_ROOT | DSSI_READ_ONLY,
  5606. &hPages[0], ReadSecurityDescriptor,
  5607. WriteSecurityDescriptor, (LPARAM)lpItem);
  5608. if (FAILED(hr))
  5609. {
  5610. return;
  5611. }
  5612. //
  5613. // Display the property sheet
  5614. //
  5615. ZeroMemory (&psh, sizeof(psh));
  5616. psh.dwSize = sizeof(psh);
  5617. psh.dwFlags = PSH_PROPTITLE;
  5618. psh.hwndParent = hDlg;
  5619. psh.hInstance = g_hInstance;
  5620. psh.pszCaption = szGPOName;
  5621. psh.nPages = 1;
  5622. psh.phpage = hPages;
  5623. PropertySheet (&psh);
  5624. }
  5625. //-------------------------------------------------------
  5626. void CRSOPComponentData::OnRefreshDisplay(HWND hDlg)
  5627. {
  5628. INT iIndex;
  5629. LVITEM item;
  5630. LPGPOLISTITEM lpItem;
  5631. iIndex = ListView_GetNextItem (GetDlgItem(hDlg, IDC_LIST1), -1,
  5632. LVNI_ALL | LVNI_SELECTED);
  5633. if (iIndex != -1)
  5634. {
  5635. item.mask = LVIF_PARAM;
  5636. item.iItem = iIndex;
  5637. item.iSubItem = 0;
  5638. if (!ListView_GetItem (GetDlgItem(hDlg, IDC_LIST1), &item))
  5639. {
  5640. return;
  5641. }
  5642. lpItem = (LPGPOLISTITEM) item.lParam;
  5643. if (lpItem->pSD)
  5644. {
  5645. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), TRUE);
  5646. }
  5647. else
  5648. {
  5649. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  5650. }
  5651. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), TRUE);
  5652. }
  5653. else
  5654. {
  5655. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON1), FALSE);
  5656. EnableWindow (GetDlgItem(hDlg, IDC_BUTTON2), FALSE);
  5657. }
  5658. }
  5659. //-------------------------------------------------------
  5660. void CRSOPComponentData::OnContextMenu(HWND hDlg, LPARAM lParam)
  5661. {
  5662. LPGPOLISTITEM lpItem;
  5663. LVITEM item;
  5664. HMENU hPopup;
  5665. HWND hLV;
  5666. int i;
  5667. RECT rc;
  5668. POINT pt;
  5669. //
  5670. // Get the selected item (if any)
  5671. //
  5672. hLV = GetDlgItem (hDlg, IDC_LIST1);
  5673. i = ListView_GetNextItem(hLV, -1, LVNI_SELECTED);
  5674. if (i < 0)
  5675. {
  5676. return;
  5677. }
  5678. item.mask = LVIF_PARAM;
  5679. item.iItem = i;
  5680. item.iSubItem = 0;
  5681. if (!ListView_GetItem (GetDlgItem(hDlg, IDC_LIST1), &item))
  5682. {
  5683. return;
  5684. }
  5685. lpItem = (LPGPOLISTITEM) item.lParam;
  5686. //
  5687. // Figure out where to place the context menu
  5688. //
  5689. pt.x = ((int)(short)LOWORD(lParam));
  5690. pt.y = ((int)(short)HIWORD(lParam));
  5691. GetWindowRect (hLV, &rc);
  5692. if (!PtInRect (&rc, pt))
  5693. {
  5694. if ((lParam == (LPARAM) -1) && (i >= 0))
  5695. {
  5696. rc.left = LVIR_SELECTBOUNDS;
  5697. SendMessage (hLV, LVM_GETITEMRECT, i, (LPARAM) &rc);
  5698. pt.x = rc.left + 8;
  5699. pt.y = rc.top + ((rc.bottom - rc.top) / 2);
  5700. ClientToScreen (hLV, &pt);
  5701. }
  5702. else
  5703. {
  5704. pt.x = rc.left + ((rc.right - rc.left) / 2);
  5705. pt.y = rc.top + ((rc.bottom - rc.top) / 2);
  5706. }
  5707. }
  5708. //
  5709. // Load the context menu
  5710. //
  5711. hPopup = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDM_GPOLIST_CONTEXTMENU));
  5712. if (!hPopup) {
  5713. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::OnContextMenu: LoadMenu failed with %d"),
  5714. GetLastError()));
  5715. return;
  5716. }
  5717. if (!(lpItem->pSD)) {
  5718. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::OnContextMenu: Disabling Security menu item")));
  5719. EnableMenuItem(GetSubMenu(hPopup, 0), IDM_GPOLIST_SECURITY, MF_GRAYED);
  5720. DrawMenuBar(hDlg);
  5721. }
  5722. //
  5723. // Display the menu
  5724. //
  5725. TrackPopupMenu(GetSubMenu(hPopup, 0), TPM_LEFTALIGN, pt.x, pt.y, 0, hDlg, NULL);
  5726. DestroyMenu(hPopup);
  5727. }
  5728. //-------------------------------------------------------
  5729. void CRSOPComponentData::OnSaveAs (HWND hDlg)
  5730. {
  5731. OPENFILENAME ofn;
  5732. TCHAR szFilter[100];
  5733. LPTSTR lpTemp;
  5734. TCHAR szFile[2*MAX_PATH];
  5735. HANDLE hFile;
  5736. DWORD dwSize, dwBytesWritten;
  5737. //
  5738. // Load the filter string and replace the # signs with nulls
  5739. //
  5740. LoadString (g_hInstance, IDS_ERRORFILTER, szFilter, ARRAYSIZE(szFilter));
  5741. lpTemp = szFilter;
  5742. while (*lpTemp)
  5743. {
  5744. if (*lpTemp == TEXT('#'))
  5745. *lpTemp = TEXT('\0');
  5746. lpTemp++;
  5747. }
  5748. //
  5749. // Call the Save common dialog
  5750. //
  5751. szFile[0] = TEXT('\0');
  5752. ZeroMemory (&ofn, sizeof(ofn));
  5753. ofn.lStructSize = sizeof(ofn);
  5754. ofn.hwndOwner = hDlg;
  5755. ofn.lpstrFilter = szFilter;
  5756. ofn.nFilterIndex = 1;
  5757. ofn.lpstrFile = szFile;
  5758. ofn.nMaxFile = 2*MAX_PATH;
  5759. ofn.lpstrDefExt = TEXT("txt");
  5760. ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
  5761. if (!GetSaveFileName (&ofn))
  5762. {
  5763. return;
  5764. }
  5765. SetWaitCursor ();
  5766. //
  5767. // Create the text file
  5768. //
  5769. hFile = CreateFile (szFile, GENERIC_WRITE, 0, NULL,
  5770. CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
  5771. NULL);
  5772. if (hFile == INVALID_HANDLE_VALUE)
  5773. {
  5774. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::OnSaveAs: CreateFile failed with %d"), GetLastError()));
  5775. ClearWaitCursor ();
  5776. return;
  5777. }
  5778. //
  5779. // Get the text out of the edit control
  5780. //
  5781. dwSize = (DWORD) SendDlgItemMessage (hDlg, IDC_EDIT1, WM_GETTEXTLENGTH, 0, 0);
  5782. lpTemp = (LPTSTR) LocalAlloc (LPTR, (dwSize+2) * sizeof(TCHAR));
  5783. if (!lpTemp)
  5784. {
  5785. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::OnSaveAs: LocalAlloc failed with %d"), GetLastError()));
  5786. CloseHandle (hFile);
  5787. ClearWaitCursor ();
  5788. return;
  5789. }
  5790. SendDlgItemMessage (hDlg, IDC_EDIT1, WM_GETTEXT, (dwSize+1), (LPARAM) lpTemp);
  5791. //
  5792. // Save it to the new file
  5793. //
  5794. WriteFile(hFile, L"\xfeff\r\n", 3 * sizeof(WCHAR), &dwBytesWritten, NULL);
  5795. if (!WriteFile (hFile, lpTemp, (dwSize * sizeof(TCHAR)), &dwBytesWritten, NULL) ||
  5796. (dwBytesWritten != (dwSize * sizeof(TCHAR))))
  5797. {
  5798. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::OnSaveAs: Failed to text with %d"),
  5799. GetLastError()));
  5800. }
  5801. LocalFree (lpTemp);
  5802. CloseHandle (hFile);
  5803. ClearWaitCursor ();
  5804. }
  5805. //-------------------------------------------------------
  5806. // Dialog helper methods
  5807. void CRSOPComponentData::InitializeErrorsDialog(HWND hDlg, LPCSEITEM lpList)
  5808. {
  5809. RECT rect;
  5810. WCHAR szBuffer[256];
  5811. LV_COLUMN lvcol;
  5812. LONG lWidth;
  5813. INT cxName = 0, cxStatus = 0, iIndex = 0, iDefault = 0;
  5814. DWORD dwCount = 0;
  5815. HWND hList = GetDlgItem(hDlg, IDC_LIST1);
  5816. LPCSEITEM lpTemp;
  5817. LVITEM item;
  5818. GUID guid;
  5819. BOOL bGPCoreFailed = FALSE;
  5820. //
  5821. // Count the number of components
  5822. //
  5823. lpTemp = lpList;
  5824. while (lpTemp)
  5825. {
  5826. lpTemp = lpTemp->pNext;
  5827. dwCount++;
  5828. }
  5829. //
  5830. // Decide on the column widths
  5831. //
  5832. GetClientRect(hList, &rect);
  5833. if (dwCount > (DWORD)ListView_GetCountPerPage(hList))
  5834. {
  5835. lWidth = (rect.right - rect.left) - GetSystemMetrics(SM_CYHSCROLL);
  5836. }
  5837. else
  5838. {
  5839. lWidth = rect.right - rect.left;
  5840. }
  5841. cxStatus = (lWidth * 35) / 100;
  5842. cxName = lWidth - cxStatus;
  5843. //
  5844. // Insert the component name column and then the status column
  5845. //
  5846. memset(&lvcol, 0, sizeof(lvcol));
  5847. lvcol.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
  5848. lvcol.fmt = LVCFMT_LEFT;
  5849. lvcol.pszText = szBuffer;
  5850. lvcol.cx = cxName;
  5851. LoadString(g_hInstance, IDS_COMPONENT_NAME, szBuffer, ARRAYSIZE(szBuffer));
  5852. ListView_InsertColumn(hList, 0, &lvcol);
  5853. lvcol.cx = cxStatus;
  5854. LoadString(g_hInstance, IDS_STATUS, szBuffer, ARRAYSIZE(szBuffer));
  5855. ListView_InsertColumn(hList, 1, &lvcol);
  5856. //
  5857. // Turn on some listview features
  5858. //
  5859. SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
  5860. LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
  5861. //
  5862. // Insert the CSE's
  5863. //
  5864. lpTemp = lpList;
  5865. while (lpTemp)
  5866. {
  5867. ZeroMemory (&item, sizeof(item));
  5868. item.mask = LVIF_TEXT | LVIF_PARAM;
  5869. item.iItem = iIndex;
  5870. item.pszText = lpTemp->lpName;
  5871. item.lParam = (LPARAM) lpTemp;
  5872. iIndex = ListView_InsertItem (hList, &item);
  5873. if (bGPCoreFailed)
  5874. {
  5875. LoadString(g_hInstance, IDS_CSE_NA, szBuffer, ARRAYSIZE(szBuffer));
  5876. }
  5877. else if ((lpTemp->dwStatus == ERROR_SUCCESS) && (lpTemp->ulLoggingStatus != 2))
  5878. {
  5879. if (lpTemp->ulLoggingStatus == 3)
  5880. {
  5881. LoadString(g_hInstance, IDS_SUCCESS2, szBuffer, ARRAYSIZE(szBuffer));
  5882. }
  5883. else
  5884. {
  5885. LoadString(g_hInstance, IDS_SUCCESS, szBuffer, ARRAYSIZE(szBuffer));
  5886. }
  5887. }
  5888. else if (lpTemp->dwStatus == E_PENDING)
  5889. {
  5890. LoadString(g_hInstance, IDS_PENDING, szBuffer, ARRAYSIZE(szBuffer));
  5891. }
  5892. else if (lpTemp->dwStatus == ERROR_OVERRIDE_NOCHANGES)
  5893. {
  5894. LoadString(g_hInstance, IDS_WARNING, szBuffer, ARRAYSIZE(szBuffer));
  5895. }
  5896. else if (lpTemp->dwStatus == ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED)
  5897. {
  5898. //
  5899. // If policy application was delayed, we don't want to say that it has
  5900. // failed, so we display a special indicator in that case
  5901. //
  5902. if (lpTemp->ulLoggingStatus == 3)
  5903. {
  5904. LoadString(g_hInstance, IDS_POLICY_DELAYED2, szBuffer, ARRAYSIZE(szBuffer));
  5905. }
  5906. else
  5907. {
  5908. LoadString(g_hInstance, IDS_POLICY_DELAYED, szBuffer, ARRAYSIZE(szBuffer));
  5909. }
  5910. }
  5911. else
  5912. {
  5913. if (lpTemp->ulLoggingStatus == 3)
  5914. {
  5915. LoadString(g_hInstance, IDS_FAILED2, szBuffer, ARRAYSIZE(szBuffer));
  5916. }
  5917. else
  5918. {
  5919. LoadString(g_hInstance, IDS_FAILED, szBuffer, ARRAYSIZE(szBuffer));
  5920. }
  5921. }
  5922. item.mask = LVIF_TEXT;
  5923. item.pszText = szBuffer;
  5924. item.iItem = iIndex;
  5925. item.iSubItem = 1;
  5926. ListView_SetItem(hList, &item);
  5927. //
  5928. // Check if GPCore failed
  5929. //
  5930. StringToGuid( lpTemp->lpGUID, &guid);
  5931. if (IsNullGUID (&guid))
  5932. {
  5933. if (lpTemp->dwStatus != ERROR_SUCCESS)
  5934. {
  5935. bGPCoreFailed = TRUE;
  5936. }
  5937. }
  5938. lpTemp = lpTemp->pNext;
  5939. iIndex++;
  5940. }
  5941. //
  5942. // Select the first non-successful item
  5943. //
  5944. iIndex = 0;
  5945. while (iIndex < ListView_GetItemCount(hList))
  5946. {
  5947. ZeroMemory (&item, sizeof(item));
  5948. item.mask = LVIF_PARAM;
  5949. item.iItem = iIndex;
  5950. if (!ListView_GetItem (hList, &item))
  5951. {
  5952. break;
  5953. }
  5954. if (item.lParam)
  5955. {
  5956. lpTemp = (LPCSEITEM) item.lParam;
  5957. if ((lpTemp->dwStatus != ERROR_SUCCESS) || (lpTemp->ulLoggingStatus == 2))
  5958. {
  5959. iDefault = iIndex;
  5960. break;
  5961. }
  5962. }
  5963. iIndex++;
  5964. }
  5965. item.mask = LVIF_STATE;
  5966. item.iItem = iDefault;
  5967. item.iSubItem = 0;
  5968. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  5969. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  5970. SendMessage (hList, LVM_SETITEMSTATE, iDefault, (LPARAM) &item);
  5971. SendMessage (hList, LVM_ENSUREVISIBLE, iDefault, FALSE);
  5972. }
  5973. //-------------------------------------------------------
  5974. void CRSOPComponentData::RefreshErrorInfo (HWND hDlg)
  5975. {
  5976. HWND hList = GetDlgItem(hDlg, IDC_LIST1);
  5977. HWND hEdit = GetDlgItem(hDlg, IDC_EDIT1);
  5978. LPCSEITEM lpItem;
  5979. LVITEM item;
  5980. INT iIndex;
  5981. TCHAR szBuffer[300];
  5982. LPTSTR lpMsg;
  5983. TCHAR szDate[100];
  5984. TCHAR szTime[100];
  5985. TCHAR szFormat[80];
  5986. FILETIME ft, ftLocal;
  5987. SYSTEMTIME systime;
  5988. LPOLESTR lpEventLogText = NULL;
  5989. CHARFORMAT2 chFormat;
  5990. BOOL bBold = FALSE;
  5991. GUID guid;
  5992. HRESULT hr;
  5993. iIndex = ListView_GetNextItem (hList, -1, LVNI_ALL | LVNI_SELECTED);
  5994. if (iIndex != -1)
  5995. {
  5996. //
  5997. // Get the CSEITEM pointer
  5998. //
  5999. item.mask = LVIF_PARAM;
  6000. item.iItem = iIndex;
  6001. item.iSubItem = 0;
  6002. if (!ListView_GetItem (hList, &item))
  6003. {
  6004. return;
  6005. }
  6006. lpItem = (LPCSEITEM) item.lParam;
  6007. if (!lpItem)
  6008. {
  6009. return;
  6010. }
  6011. SendMessage (hEdit, WM_SETREDRAW, FALSE, 0);
  6012. //
  6013. // Set the time information
  6014. //
  6015. SendMessage (hEdit, EM_SETSEL, 0, (LPARAM) -1);
  6016. SystemTimeToFileTime (&lpItem->EndTime, &ft);
  6017. FileTimeToLocalFileTime (&ft, &ftLocal);
  6018. FileTimeToSystemTime (&ftLocal, &systime);
  6019. GetDateFormat (LOCALE_USER_DEFAULT, DATE_LONGDATE, &systime,
  6020. NULL, szDate, ARRAYSIZE (szDate));
  6021. GetTimeFormat (LOCALE_USER_DEFAULT, 0, &systime,
  6022. NULL, szTime, ARRAYSIZE (szTime));
  6023. LoadString (g_hInstance, IDS_DATETIMEFORMAT, szFormat, ARRAYSIZE(szFormat));
  6024. (void) StringCchPrintf (szBuffer, ARRAYSIZE(szBuffer), szFormat, szDate, szTime);
  6025. //
  6026. // Turn italic on
  6027. //
  6028. ZeroMemory (&chFormat, sizeof(chFormat));
  6029. chFormat.cbSize = sizeof(chFormat);
  6030. chFormat.dwMask = CFM_ITALIC;
  6031. chFormat.dwEffects = CFE_ITALIC;
  6032. SendMessage (hEdit, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD,
  6033. (LPARAM) &chFormat);
  6034. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) szBuffer);
  6035. if (lpItem->ulLoggingStatus == 3)
  6036. {
  6037. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6038. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) TEXT("\r\n\r\n"));
  6039. LoadString(g_hInstance, IDS_LEGACYCSE, szBuffer, ARRAYSIZE(szBuffer));
  6040. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6041. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) szBuffer);
  6042. LoadString(g_hInstance, IDS_LEGACYCSE1, szBuffer, ARRAYSIZE(szBuffer));
  6043. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6044. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) szBuffer);
  6045. }
  6046. //
  6047. // Turn italic off
  6048. //
  6049. ZeroMemory (&chFormat, sizeof(chFormat));
  6050. chFormat.cbSize = sizeof(chFormat);
  6051. chFormat.dwMask = CFM_ITALIC;
  6052. SendMessage (hEdit, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD,
  6053. (LPARAM) &chFormat);
  6054. //
  6055. // Put a blank line in between the time and the main message
  6056. //
  6057. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6058. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) TEXT("\r\n\r\n"));
  6059. //
  6060. // Set the main message
  6061. //
  6062. if (lpItem->ulLoggingStatus == 2)
  6063. {
  6064. if ( lpItem->dwStatus == ERROR_SUCCESS )
  6065. LoadString(g_hInstance, IDS_LOGGINGFAILED, szBuffer, ARRAYSIZE(szBuffer));
  6066. else
  6067. LoadString(g_hInstance, IDS_FAILEDMSG2, szBuffer, ARRAYSIZE(szBuffer));
  6068. bBold = TRUE;
  6069. }
  6070. else if (lpItem->dwStatus == ERROR_SUCCESS)
  6071. {
  6072. LoadString(g_hInstance, IDS_SUCCESSMSG, szBuffer, ARRAYSIZE(szBuffer));
  6073. }
  6074. else if (lpItem->dwStatus == E_PENDING)
  6075. {
  6076. LoadString(g_hInstance, IDS_PENDINGMSG, szBuffer, ARRAYSIZE(szBuffer));
  6077. }
  6078. else if (lpItem->dwStatus == ERROR_OVERRIDE_NOCHANGES)
  6079. {
  6080. LoadString(g_hInstance, IDS_OVERRIDE, szBuffer, ARRAYSIZE(szBuffer));
  6081. bBold = TRUE;
  6082. }
  6083. else if (lpItem->dwStatus == ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED)
  6084. {
  6085. if (lpItem->bUser)
  6086. {
  6087. LoadString(g_hInstance, IDS_SYNC_REQUIRED_USER, szBuffer, ARRAYSIZE(szBuffer));
  6088. }
  6089. else
  6090. {
  6091. LoadString(g_hInstance, IDS_SYNC_REQUIRED_MACH, szBuffer, ARRAYSIZE(szBuffer));
  6092. }
  6093. bBold = TRUE;
  6094. }
  6095. else
  6096. {
  6097. LoadString(g_hInstance, IDS_FAILEDMSG1, szBuffer, ARRAYSIZE(szBuffer));
  6098. bBold = TRUE;
  6099. }
  6100. if (bBold)
  6101. {
  6102. //
  6103. // Turn bold on
  6104. //
  6105. ZeroMemory (&chFormat, sizeof(chFormat));
  6106. chFormat.cbSize = sizeof(chFormat);
  6107. chFormat.dwMask = CFM_BOLD;
  6108. chFormat.dwEffects = CFE_BOLD;
  6109. SendMessage (hEdit, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD,
  6110. (LPARAM) &chFormat);
  6111. }
  6112. ULONG ulNoChars = lstrlen(lpItem->lpName) + lstrlen(szBuffer) + 1;
  6113. lpMsg = (LPTSTR) LocalAlloc(LPTR, ulNoChars * sizeof(TCHAR));
  6114. if (lpMsg)
  6115. {
  6116. hr = StringCchPrintf (lpMsg, ulNoChars, szBuffer, lpItem->lpName);
  6117. if (FAILED(hr))
  6118. {
  6119. LocalFree(lpMsg);
  6120. lpMsg = NULL;
  6121. }
  6122. }
  6123. if (!lpMsg)
  6124. {
  6125. SendMessage (hEdit, WM_SETREDRAW, TRUE, 0);
  6126. InvalidateRect (hEdit, NULL, TRUE);
  6127. UpdateWindow (hEdit);
  6128. return;
  6129. }
  6130. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6131. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) lpMsg);
  6132. LocalFree (lpMsg);
  6133. //
  6134. // Even if the CSE was successful or if it returned E_PENDING, continue on to get the
  6135. // eventlog msgs
  6136. //
  6137. StringToGuid( lpItem->lpGUID, &guid);
  6138. if (!((lpItem->dwStatus == ERROR_SUCCESS) || (lpItem->dwStatus == E_PENDING)))
  6139. {
  6140. //
  6141. // Print the error code if appropriate
  6142. //
  6143. if (lpItem->dwStatus != ERROR_OVERRIDE_NOCHANGES && lpItem->dwStatus != ERROR_SYNC_FOREGROUND_REFRESH_REQUIRED )
  6144. {
  6145. lpMsg = (LPTSTR) LocalAlloc(LPTR, 300 * sizeof(TCHAR));
  6146. if (lpMsg)
  6147. {
  6148. LoadMessage (lpItem->dwStatus, lpMsg, 300);
  6149. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6150. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) lpMsg);
  6151. LocalFree (lpMsg);
  6152. }
  6153. }
  6154. //
  6155. // Special case GPCore to have an additional message
  6156. //
  6157. if (IsNullGUID (&guid))
  6158. {
  6159. LoadString(g_hInstance, IDS_GPCOREFAIL, szBuffer, ARRAYSIZE(szBuffer));
  6160. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6161. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) szBuffer);
  6162. }
  6163. }
  6164. else {
  6165. if (lpItem->ulLoggingStatus == 2) {
  6166. //
  6167. // Special case GPCore to have an additional message if logging failed
  6168. //
  6169. if (IsNullGUID (&guid))
  6170. {
  6171. LoadString(g_hInstance, IDS_GPCORE_LOGGINGFAIL, szBuffer, ARRAYSIZE(szBuffer));
  6172. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6173. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) szBuffer);
  6174. }
  6175. }
  6176. }
  6177. if (bBold)
  6178. {
  6179. //
  6180. // Turn bold off
  6181. //
  6182. ZeroMemory (&chFormat, sizeof(chFormat));
  6183. chFormat.cbSize = sizeof(chFormat);
  6184. chFormat.dwMask = CFM_BOLD;
  6185. SendMessage (hEdit, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD,
  6186. (LPARAM) &chFormat);
  6187. }
  6188. //
  6189. // Get any event log text for this CSE
  6190. //
  6191. if (m_CSELists.GetEvents() && SUCCEEDED(m_CSELists.GetEvents()->GetCSEEntries(&lpItem->BeginTime, &lpItem->EndTime,
  6192. lpItem->lpEventSources, &lpEventLogText,
  6193. (IsNullGUID (&guid)))))
  6194. {
  6195. //
  6196. // Put a blank line between the main message and the Additional information header
  6197. //
  6198. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6199. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) TEXT("\r\n"));
  6200. //
  6201. // Turn underline on
  6202. //
  6203. ZeroMemory (&chFormat, sizeof(chFormat));
  6204. chFormat.cbSize = sizeof(chFormat);
  6205. chFormat.dwMask = CFM_UNDERLINETYPE | CFM_UNDERLINE;
  6206. chFormat.dwEffects = CFE_UNDERLINE;
  6207. chFormat.bUnderlineType = CFU_UNDERLINE;
  6208. SendMessage (hEdit, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD,
  6209. (LPARAM) &chFormat);
  6210. LoadString(g_hInstance, IDS_ADDITIONALINFO, szBuffer, ARRAYSIZE(szBuffer));
  6211. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6212. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) szBuffer);
  6213. //
  6214. // Turn underline off
  6215. //
  6216. ZeroMemory (&chFormat, sizeof(chFormat));
  6217. chFormat.cbSize = sizeof(chFormat);
  6218. chFormat.dwMask = CFM_UNDERLINETYPE | CFM_UNDERLINE;
  6219. chFormat.dwEffects = CFE_UNDERLINE;
  6220. chFormat.bUnderlineType = CFU_UNDERLINENONE;
  6221. SendMessage (hEdit, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD,
  6222. (LPARAM) &chFormat);
  6223. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6224. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) TEXT("\r\n"));
  6225. //
  6226. // Add the event log info to the edit control
  6227. //
  6228. SendMessage (hEdit, EM_SETSEL, (WPARAM)-1, (LPARAM) -1);
  6229. SendMessage (hEdit, EM_REPLACESEL, 0, (LPARAM) lpEventLogText);
  6230. CoTaskMemFree (lpEventLogText);
  6231. }
  6232. SendMessage (hEdit, EM_SETSEL, 0, 0);
  6233. SendMessage (hEdit, EM_SCROLLCARET, 0, 0);
  6234. SendMessage (hEdit, WM_SETREDRAW, TRUE, 0);
  6235. InvalidateRect (hEdit, NULL, TRUE);
  6236. UpdateWindow (hEdit);
  6237. }
  6238. }
  6239. //-------------------------------------------------------
  6240. HRESULT WINAPI CRSOPComponentData::ReadSecurityDescriptor (LPCWSTR lpGPOPath,
  6241. SECURITY_INFORMATION si,
  6242. PSECURITY_DESCRIPTOR *pSD,
  6243. LPARAM lpContext)
  6244. {
  6245. LPGPOLISTITEM lpItem;
  6246. HRESULT hr;
  6247. lpItem = (LPGPOLISTITEM) lpContext;
  6248. if (!lpItem)
  6249. {
  6250. return E_FAIL;
  6251. }
  6252. if (si & DACL_SECURITY_INFORMATION)
  6253. {
  6254. *pSD = lpItem->pSD;
  6255. }
  6256. else
  6257. {
  6258. *pSD = NULL;
  6259. }
  6260. return S_OK;
  6261. }
  6262. //-------------------------------------------------------
  6263. HRESULT WINAPI CRSOPComponentData::WriteSecurityDescriptor (LPCWSTR lpGPOPath,
  6264. SECURITY_INFORMATION si,
  6265. PSECURITY_DESCRIPTOR pSD,
  6266. LPARAM lpContext)
  6267. {
  6268. return S_OK;
  6269. }
  6270. //-------------------------------------------------------
  6271. void CRSOPComponentData::FillGPOList(HWND hDlg, DWORD dwListID, LPGPOLISTITEM lpList,
  6272. BOOL bSOM, BOOL bFiltering, BOOL bVersion, BOOL bInitial)
  6273. {
  6274. LV_COLUMN lvcol;
  6275. HWND hList;
  6276. LV_ITEM item;
  6277. int iItem;
  6278. TCHAR szVersion[80];
  6279. TCHAR szVersionFormat[50];
  6280. INT iColIndex, iDefault = 0;
  6281. LPGPOLISTITEM lpItem, lpDefault = NULL;
  6282. DWORD dwCount = 0;
  6283. LVFINDINFO FindInfo;
  6284. HRESULT hr;
  6285. ULONG ulNoChars;
  6286. LoadString(g_hInstance, IDS_VERSIONFORMAT, szVersionFormat, ARRAYSIZE(szVersionFormat));
  6287. hList = GetDlgItem(hDlg, dwListID);
  6288. ListView_DeleteAllItems(hList);
  6289. lpItem = lpList;
  6290. while (lpItem)
  6291. {
  6292. if (bInitial)
  6293. {
  6294. if (LOWORD(lpItem->dwVersion) != HIWORD(lpItem->dwVersion))
  6295. {
  6296. bVersion = TRUE;
  6297. CheckDlgButton (hDlg, IDC_CHECK3, BST_CHECKED);
  6298. }
  6299. }
  6300. lpItem = lpItem->pNext;
  6301. dwCount++;
  6302. }
  6303. PrepGPOList(hList, bSOM, bFiltering, bVersion, dwCount);
  6304. lpItem = lpList;
  6305. while (lpItem)
  6306. {
  6307. if (lpItem->bApplied || bFiltering)
  6308. {
  6309. hr = StringCchPrintf (szVersion,
  6310. ARRAYSIZE(szVersion),
  6311. szVersionFormat,
  6312. LOWORD(lpItem->dwVersion),
  6313. HIWORD(lpItem->dwVersion));
  6314. if (FAILED(hr))
  6315. {
  6316. lpItem = lpItem->pNext;
  6317. continue;
  6318. }
  6319. iColIndex = 0;
  6320. memset(&item, 0, sizeof(item));
  6321. item.mask = LVIF_TEXT | LVIF_PARAM;
  6322. item.pszText = lpItem->lpGPOName;
  6323. item.iItem = 0;
  6324. item.lParam = (LPARAM) lpItem;
  6325. iItem = ListView_InsertItem(hList, &item);
  6326. iColIndex++;
  6327. if (bInitial)
  6328. {
  6329. if (LOWORD(lpItem->dwVersion) != HIWORD(lpItem->dwVersion))
  6330. {
  6331. lpDefault = lpItem;
  6332. }
  6333. }
  6334. if (bFiltering)
  6335. {
  6336. item.mask = LVIF_TEXT;
  6337. item.pszText = lpItem->lpFiltering;
  6338. item.iItem = iItem;
  6339. item.iSubItem = iColIndex;
  6340. ListView_SetItem(hList, &item);
  6341. iColIndex++;
  6342. }
  6343. if (bSOM)
  6344. {
  6345. item.mask = LVIF_TEXT;
  6346. item.pszText = lpItem->lpUnescapedSOM;
  6347. item.iItem = iItem;
  6348. item.iSubItem = iColIndex;
  6349. ListView_SetItem(hList, &item);
  6350. iColIndex++;
  6351. }
  6352. if (bVersion)
  6353. {
  6354. item.mask = LVIF_TEXT;
  6355. item.pszText = szVersion;
  6356. item.iItem = iItem;
  6357. item.iSubItem = iColIndex;
  6358. ListView_SetItem(hList, &item);
  6359. }
  6360. }
  6361. lpItem = lpItem->pNext;
  6362. }
  6363. if (lpDefault)
  6364. {
  6365. ZeroMemory (&FindInfo, sizeof(FindInfo));
  6366. FindInfo.flags = LVFI_PARAM;
  6367. FindInfo.lParam = (LPARAM) lpDefault;
  6368. iDefault = ListView_FindItem(hList, -1, &FindInfo);
  6369. if (iDefault == -1)
  6370. {
  6371. iDefault = 0;
  6372. }
  6373. }
  6374. // Select a item
  6375. item.mask = LVIF_STATE;
  6376. item.iItem = iDefault;
  6377. item.iSubItem = 0;
  6378. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  6379. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  6380. SendMessage (hList, LVM_SETITEMSTATE, (WPARAM)iDefault, (LPARAM) &item);
  6381. SendMessage (hList, LVM_ENSUREVISIBLE, iDefault, FALSE);
  6382. }
  6383. //-------------------------------------------------------
  6384. void CRSOPComponentData::PrepGPOList(HWND hList, BOOL bSOM, BOOL bFiltering,
  6385. BOOL bVersion, DWORD dwCount)
  6386. {
  6387. RECT rect;
  6388. WCHAR szHeading[256];
  6389. LV_COLUMN lvcol;
  6390. LONG lWidth;
  6391. INT cxName = 0, cxSOM = 0, cxFiltering = 0, cxVersion = 0, iTotal = 0;
  6392. INT iColIndex = 0;
  6393. //
  6394. // Delete any previous columns
  6395. //
  6396. SendMessage (hList, LVM_DELETECOLUMN, 3, 0);
  6397. SendMessage (hList, LVM_DELETECOLUMN, 2, 0);
  6398. SendMessage (hList, LVM_DELETECOLUMN, 1, 0);
  6399. SendMessage (hList, LVM_DELETECOLUMN, 0, 0);
  6400. //
  6401. // Decide on the column widths
  6402. //
  6403. GetClientRect(hList, &rect);
  6404. if (dwCount > (DWORD)ListView_GetCountPerPage(hList))
  6405. {
  6406. lWidth = (rect.right - rect.left) - GetSystemMetrics(SM_CYHSCROLL);
  6407. }
  6408. else
  6409. {
  6410. lWidth = rect.right - rect.left;
  6411. }
  6412. if (bFiltering)
  6413. {
  6414. cxFiltering = (lWidth * 30) / 100;
  6415. iTotal += cxFiltering;
  6416. }
  6417. if (bVersion)
  6418. {
  6419. cxVersion = (lWidth * 30) / 100;
  6420. iTotal += cxVersion;
  6421. }
  6422. if (bSOM)
  6423. {
  6424. cxSOM = (lWidth - iTotal) / 2;
  6425. iTotal += cxSOM;
  6426. cxName = lWidth - iTotal;
  6427. }
  6428. else
  6429. {
  6430. cxName = lWidth - iTotal;
  6431. }
  6432. //
  6433. // Insert the GPO Name column and then any appropriate columns
  6434. //
  6435. memset(&lvcol, 0, sizeof(lvcol));
  6436. lvcol.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
  6437. lvcol.fmt = LVCFMT_LEFT;
  6438. lvcol.pszText = szHeading;
  6439. lvcol.cx = cxName;
  6440. LoadString(g_hInstance, IDS_GPO_NAME, szHeading, ARRAYSIZE(szHeading));
  6441. ListView_InsertColumn(hList, iColIndex, &lvcol);
  6442. iColIndex++;
  6443. if (bFiltering)
  6444. {
  6445. lvcol.cx = cxFiltering;
  6446. LoadString(g_hInstance, IDS_FILTERING, szHeading, ARRAYSIZE(szHeading));
  6447. ListView_InsertColumn(hList, iColIndex, &lvcol);
  6448. iColIndex++;
  6449. }
  6450. if (bSOM)
  6451. {
  6452. lvcol.cx = cxSOM;
  6453. LoadString(g_hInstance, IDS_SOM, szHeading, ARRAYSIZE(szHeading));
  6454. ListView_InsertColumn(hList, iColIndex, &lvcol);
  6455. iColIndex++;
  6456. }
  6457. if (bVersion)
  6458. {
  6459. lvcol.cx = cxVersion;
  6460. LoadString(g_hInstance, IDS_VERSION, szHeading, ARRAYSIZE(szHeading));
  6461. ListView_InsertColumn(hList, iColIndex, &lvcol);
  6462. }
  6463. //
  6464. // Turn on some listview features
  6465. //
  6466. SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
  6467. LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
  6468. }
  6469. //-------------------------------------------------------
  6470. // Dialog methods for loading RSOP data from archive
  6471. INT_PTR CALLBACK CRSOPComponentData::InitArchivedRsopDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  6472. {
  6473. CRSOPComponentData * pCD;
  6474. HRESULT hr = S_OK;
  6475. TCHAR szMessage[200];
  6476. switch (message)
  6477. {
  6478. case WM_INITDIALOG:
  6479. {
  6480. pCD = (CRSOPComponentData *) lParam;
  6481. SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR) pCD);
  6482. if (pCD)
  6483. {
  6484. CRSOPWizard::InitializeResultsList (GetDlgItem (hDlg, IDC_LIST1));
  6485. CRSOPWizard::FillResultsList (GetDlgItem (hDlg, IDC_LIST1), pCD->m_pRSOPQuery, pCD->m_pRSOPQueryResults);
  6486. LoadString(g_hInstance, IDS_PLEASEWAIT1, szMessage, ARRAYSIZE(szMessage));
  6487. SetWindowText(GetDlgItem(hDlg, IDC_STATIC1), szMessage);
  6488. ShowWindow(GetDlgItem(hDlg, IDC_PROGRESS1), SW_HIDE);
  6489. }
  6490. PostMessage(hDlg, WM_INITRSOP, 0, 0);
  6491. return TRUE;
  6492. }
  6493. case WM_INITRSOP:
  6494. pCD = (CRSOPComponentData *) GetWindowLongPtr (hDlg, DWLP_USER);
  6495. hr = pCD->InitializeRSOPFromArchivedData(pCD->m_pStm);
  6496. if (hr != S_OK)
  6497. {
  6498. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitArchivedRsopDlgProc: InitializeRSOPFromArchivedData failed with 0x%x."), hr));
  6499. EndDialog(hDlg, 0);
  6500. return TRUE;
  6501. }
  6502. EndDialog(hDlg, 1);
  6503. return TRUE;
  6504. }
  6505. return FALSE;
  6506. }
  6507. //-------------------------------------------------------
  6508. HRESULT CRSOPComponentData::DeleteArchivedRSOPNamespace()
  6509. {
  6510. IWbemLocator * pLocator = NULL;
  6511. IWbemServices * pNamespace = NULL;
  6512. BSTR bstrParam = NULL;
  6513. LPTSTR lpTemp = NULL;
  6514. BSTR bstrTemp = NULL;
  6515. HRESULT hr = S_OK;
  6516. if ( m_pRSOPQueryResults->szWMINameSpace != NULL )
  6517. {
  6518. LocalFree( m_pRSOPQueryResults->szWMINameSpace );
  6519. m_pRSOPQueryResults->szWMINameSpace = NULL;
  6520. }
  6521. LocalFree( m_pRSOPQueryResults );
  6522. m_pRSOPQueryResults = NULL;
  6523. // Delete the namespace
  6524. hr = CoCreateInstance(CLSID_WbemLocator,
  6525. 0,
  6526. CLSCTX_INPROC_SERVER,
  6527. IID_IWbemLocator,
  6528. (LPVOID *) &pLocator);
  6529. if (FAILED(hr))
  6530. {
  6531. goto Cleanup;
  6532. }
  6533. // Delete the namespace we created when loading the data
  6534. bstrParam = SysAllocString(TEXT("\\\\.\\root\\rsop"));
  6535. if (!bstrParam)
  6536. {
  6537. hr = E_FAIL;
  6538. goto Cleanup;
  6539. }
  6540. hr = pLocator->ConnectServer(bstrParam,
  6541. NULL,
  6542. NULL,
  6543. NULL,
  6544. 0,
  6545. NULL,
  6546. NULL,
  6547. &pNamespace);
  6548. if (FAILED(hr))
  6549. {
  6550. goto Cleanup;
  6551. }
  6552. // Set the proper security to encrypt the data
  6553. hr = CoSetProxyBlanket(pNamespace,
  6554. RPC_C_AUTHN_DEFAULT,
  6555. RPC_C_AUTHZ_DEFAULT,
  6556. COLE_DEFAULT_PRINCIPAL,
  6557. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  6558. RPC_C_IMP_LEVEL_IMPERSONATE,
  6559. NULL,
  6560. 0);
  6561. if (FAILED(hr))
  6562. {
  6563. goto Cleanup;
  6564. }
  6565. // Allocate a temp buffer to store the fully qualified path in
  6566. ULONG ulNoChars = lstrlen(m_szArchivedDataGuid) + 30;
  6567. lpTemp = new TCHAR [ulNoChars];
  6568. if (!lpTemp)
  6569. {
  6570. hr = HRESULT_FROM_WIN32(GetLastError());
  6571. goto Cleanup;
  6572. }
  6573. hr = StringCchPrintf (lpTemp, ulNoChars, TEXT("__Namespace.name=\"%ws\""), m_szArchivedDataGuid);
  6574. if ( FAILED(hr))
  6575. {
  6576. goto Cleanup;
  6577. }
  6578. // Delete the namespace
  6579. bstrTemp = SysAllocString (lpTemp);
  6580. if (!bstrTemp)
  6581. {
  6582. hr = E_FAIL;
  6583. goto Cleanup;
  6584. }
  6585. hr = pNamespace->DeleteInstance( bstrTemp, 0, NULL, NULL);
  6586. Cleanup:
  6587. if (lpTemp)
  6588. {
  6589. delete [] lpTemp;
  6590. }
  6591. if (bstrTemp)
  6592. {
  6593. SysFreeString(bstrTemp);
  6594. }
  6595. if (bstrParam)
  6596. {
  6597. SysFreeString(bstrParam);
  6598. }
  6599. if (pNamespace)
  6600. {
  6601. pNamespace->Release();
  6602. }
  6603. if (pLocator)
  6604. {
  6605. pLocator->Release();
  6606. }
  6607. return hr;
  6608. }
  6609. STDMETHODIMP CRSOPComponentData::InitializeRSOPFromArchivedData(IStream *pStm)
  6610. {
  6611. HRESULT hr;
  6612. TCHAR szNameSpace[100];
  6613. GUID guid;
  6614. LPTSTR lpEnd, lpFileName, lpTemp;
  6615. // Create a guid to work with
  6616. hr = CoCreateGuid( &guid );
  6617. if (FAILED(hr)) {
  6618. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: CoCreateGuid failed with 0x%x"), hr));
  6619. return hr;
  6620. }
  6621. hr = StringCchPrintf ( m_szArchivedDataGuid,
  6622. ARRAYSIZE(m_szArchivedDataGuid),
  6623. L"NS%08lX_%04X_%04X_%02X%02X_%02X%02X%02X%02X%02X%02X",
  6624. guid.Data1,
  6625. guid.Data2,
  6626. guid.Data3,
  6627. guid.Data4[0], guid.Data4[1],
  6628. guid.Data4[2], guid.Data4[3],
  6629. guid.Data4[4], guid.Data4[5],
  6630. guid.Data4[6], guid.Data4[7] );
  6631. if (FAILED(hr))
  6632. {
  6633. DebugMsg((DM_WARNING,
  6634. TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: Coudl not copy Archived data guid with 0x%x"),
  6635. hr));
  6636. return hr;
  6637. }
  6638. hr = StringCchCopy (szNameSpace, ARRAYSIZE(szNameSpace), TEXT("\\\\.\\root\\rsop"));
  6639. if (FAILED(hr))
  6640. {
  6641. DebugMsg((DM_WARNING,
  6642. TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: Coudl not copy data with 0x%x"),
  6643. hr));
  6644. return hr;
  6645. }
  6646. // Build the parent namespace
  6647. hr = CreateNameSpace (m_szArchivedDataGuid, szNameSpace);
  6648. if (FAILED(hr)) {
  6649. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: CreateNameSpace failed with 0x%x"), hr));
  6650. return hr;
  6651. }
  6652. lpEnd = CheckSlash (szNameSpace);
  6653. hr = StringCchCat (szNameSpace, ARRAYSIZE(szNameSpace),m_szArchivedDataGuid );
  6654. if (FAILED(hr))
  6655. {
  6656. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: CreateNameSpace failed with 0x%x"), hr));
  6657. return hr;
  6658. }
  6659. // Build the user subnamespace
  6660. hr = CreateNameSpace (TEXT("User"), szNameSpace);
  6661. if (FAILED(hr)) {
  6662. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: CreateNameSpace failed with 0x%x"), hr));
  6663. return hr;
  6664. }
  6665. // Build the computer subnamespace
  6666. hr = CreateNameSpace (TEXT("Computer"), szNameSpace);
  6667. if (FAILED(hr)) {
  6668. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: CreateNameSpace failed with 0x%x"), hr));
  6669. return hr;
  6670. }
  6671. // Save the namespace for future use
  6672. ULONG ulNoChars = lstrlen(szNameSpace) + 1;
  6673. m_pRSOPQueryResults->szWMINameSpace = (LPTSTR)LocalAlloc( LPTR, ulNoChars * sizeof(TCHAR) );
  6674. if ( m_pRSOPQueryResults->szWMINameSpace == NULL ) {
  6675. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: Failed to allocate memory with %d"), GetLastError()));
  6676. return HRESULT_FROM_WIN32(GetLastError());
  6677. }
  6678. hr = StringCchCopy ( m_pRSOPQueryResults->szWMINameSpace, ulNoChars, szNameSpace );
  6679. ASSERT(SUCCEEDED(hr));
  6680. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: Namespace name is: %s"), szNameSpace));
  6681. // Make a copy of the namespace that we can manipulate (to load the data with)
  6682. ulNoChars = lstrlen(szNameSpace) + 10;
  6683. lpTemp = new TCHAR[ulNoChars];
  6684. if (!lpTemp) {
  6685. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: Failed to allocate memory with %d"), GetLastError()));
  6686. return HRESULT_FROM_WIN32(GetLastError());
  6687. }
  6688. hr = StringCchCopy( lpTemp, ulNoChars, m_pRSOPQueryResults->szWMINameSpace );
  6689. ASSERT(SUCCEEDED(hr));
  6690. ULONG ulNoRemChars;
  6691. lpEnd = CheckSlash (lpTemp);
  6692. ulNoRemChars = ulNoChars - lstrlen(lpTemp);
  6693. hr = StringCchCat (lpTemp, ulNoChars, TEXT("Computer"));
  6694. if (FAILED(hr))
  6695. {
  6696. DebugMsg((DM_WARNING,
  6697. TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: Could not copy WMI name space with 0x%x"),
  6698. hr));
  6699. delete [] lpTemp;
  6700. return hr;
  6701. }
  6702. // Extract the computer data to a temp file
  6703. hr = CopyMSCToFile (pStm, &lpFileName);
  6704. if (FAILED(hr)) {
  6705. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: CopyMSCToFile failed with 0x%x"), hr));
  6706. delete [] lpTemp;
  6707. return hr;
  6708. }
  6709. // Use the mof compiler to pull the data from the file and put it in the new namespace
  6710. hr = ImportRSoPData (lpTemp, lpFileName);
  6711. DeleteFile (lpFileName);
  6712. delete [] lpFileName;
  6713. if (FAILED(hr)) {
  6714. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: ImportRSoPData failed with 0x%x"), hr));
  6715. delete [] lpTemp;
  6716. return hr;
  6717. }
  6718. // Now extract the user data to a temp file
  6719. hr = StringCchCopy (lpEnd, ulNoRemChars, TEXT("User"));
  6720. if (FAILED(hr))
  6721. {
  6722. DebugMsg((DM_WARNING,
  6723. TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: Could not copy WMI name space with 0x%x"),
  6724. hr));
  6725. delete [] lpTemp;
  6726. return hr;
  6727. }
  6728. hr = CopyMSCToFile (pStm, &lpFileName);
  6729. if (FAILED(hr)) {
  6730. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: CopyMSCToFile failed with 0x%x"), hr));
  6731. delete [] lpTemp;
  6732. return hr;
  6733. }
  6734. // Use the mof compiler to pull the data from the file and put it in the new namespace
  6735. hr = ImportRSoPData (lpTemp, lpFileName);
  6736. DeleteFile (lpFileName);
  6737. delete [] lpFileName;
  6738. if (FAILED(hr)) {
  6739. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: ImportRSoPData failed with 0x%x"), hr));
  6740. delete [] lpTemp;
  6741. return hr;
  6742. }
  6743. delete [] lpTemp;
  6744. // Pull the event log information and initialize the database
  6745. hr = m_CSELists.GetEvents()->LoadEntriesFromStream(pStm);
  6746. if (FAILED(hr))
  6747. {
  6748. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOPFromArchivedData: LoadEntriesFromStream failed with 0x%x."), hr));
  6749. return hr;
  6750. }
  6751. // Build the common data structures used by various property sheets
  6752. m_GPOLists.Build( m_pRSOPQueryResults->szWMINameSpace );
  6753. m_CSELists.Build( m_pRSOPQuery, m_pRSOPQueryResults->szWMINameSpace, m_bGetExtendedErrorInfo );
  6754. if ( m_CSELists.GetEvents() )
  6755. {
  6756. m_CSELists.GetEvents()->DumpDebugInfo();
  6757. }
  6758. // Build the display name
  6759. BuildDisplayName();
  6760. m_bInitialized = TRUE;
  6761. return S_OK;
  6762. }
  6763. //-------------------------------------------------------
  6764. HRESULT CRSOPComponentData::InitializeRSOP( BOOL bShowWizard )
  6765. {
  6766. HRESULT hr;
  6767. _CExtendedProcessing extendedProcessing( m_bGetExtendedErrorInfo, m_GPOLists, m_CSELists );
  6768. // if the UI is launched with namespace specification, there is nothing more to be done here
  6769. // no query needs to be run etc.
  6770. if (!m_bNamespaceSpecified)
  6771. {
  6772. if ( !m_bInitialized )
  6773. {
  6774. if ( m_pRSOPQuery == NULL )
  6775. {
  6776. if ( !CreateRSOPQuery( &m_pRSOPQuery, RSOP_UNKNOWN_MODE ) )
  6777. {
  6778. return HRESULT_FROM_WIN32( GetLastError() );
  6779. }
  6780. }
  6781. m_pRSOPQuery->dwFlags |= RSOP_NEW_QUERY;
  6782. hr = RunRSOPQueryInternal( m_hwndFrame, &extendedProcessing, m_pRSOPQuery, &m_pRSOPQueryResults );
  6783. }
  6784. else
  6785. {
  6786. LPRSOP_QUERY_RESULTS pNewResults = NULL;
  6787. // We want the following to be set
  6788. m_pRSOPQuery->dwFlags = m_pRSOPQuery->dwFlags & (RSOP_NEW_QUERY ^ 0xffffffff);
  6789. m_pRSOPQuery->dwFlags |= RSOP_NO_WELCOME;
  6790. if ( bShowWizard )
  6791. {
  6792. m_pRSOPQuery->UIMode = RSOP_UI_WIZARD;
  6793. }
  6794. else
  6795. {
  6796. m_pRSOPQuery->UIMode = RSOP_UI_REFRESH;
  6797. }
  6798. // Run the query
  6799. hr = RunRSOPQueryInternal( m_hwndFrame, &extendedProcessing, m_pRSOPQuery, &pNewResults );
  6800. if ( hr == S_OK )
  6801. {
  6802. if ( m_bViewIsArchivedData )
  6803. {
  6804. DeleteArchivedRSOPNamespace();
  6805. m_bViewIsArchivedData = FALSE;
  6806. }
  6807. else
  6808. {
  6809. // If the old and new namespaces are the same, it translates to the case where a non-admin user
  6810. // reran the query and chose to discard the previous query results in favour of the new one's.
  6811. // In this case we do not delete the namespace as it is the one that should be used.
  6812. if ( CompareString( LOCALE_INVARIANT, 0, m_pRSOPQueryResults->szWMINameSpace, -1, pNewResults->szWMINameSpace, -1 ) == CSTR_EQUAL )
  6813. {
  6814. LocalFree( m_pRSOPQueryResults->szWMINameSpace );
  6815. LocalFree( m_pRSOPQueryResults );
  6816. }
  6817. else
  6818. {
  6819. FreeRSOPQueryResults( m_pRSOPQuery, m_pRSOPQueryResults );
  6820. }
  6821. }
  6822. m_pRSOPQueryResults = pNewResults;
  6823. }
  6824. else
  6825. {
  6826. FreeRSOPQueryResults( m_pRSOPQuery, pNewResults );
  6827. }
  6828. }
  6829. if ( FAILED(hr) )
  6830. {
  6831. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOP: SetupPropertyPages failed with 0x%x"), hr));
  6832. }
  6833. if (hr == S_FALSE)
  6834. {
  6835. DebugMsg((DM_VERBOSE, TEXT("CRSOPComponentData::InitializeRSOP: User cancelled in the init wizard")));
  6836. }
  6837. }
  6838. else
  6839. {
  6840. hr = extendedProcessing.DoProcessing(m_pRSOPQuery, m_pRSOPQueryResults, TRUE);
  6841. }
  6842. if ( hr == S_OK )
  6843. {
  6844. m_bGetExtendedErrorInfo = extendedProcessing.GetExtendedErrorInfo();
  6845. if ( m_bInitialized && (m_hRoot != NULL) )
  6846. {
  6847. if ( m_hMachine != NULL) hr = m_pScope->DeleteItem( m_hMachine, FALSE );
  6848. if ( m_hUser != NULL) hr = m_pScope->DeleteItem( m_hUser, FALSE );
  6849. hr = m_pScope->DeleteItem( m_hRoot, FALSE );
  6850. if ( hr != S_OK )
  6851. {
  6852. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOP: Deleting scope items failed with 0x%x"), hr));
  6853. return E_FAIL;
  6854. }
  6855. m_hMachine = NULL;
  6856. m_hUser = NULL;
  6857. }
  6858. else
  6859. {
  6860. m_bInitialized = TRUE;
  6861. }
  6862. if ( !m_bNamespaceSpecified )
  6863. {
  6864. SetDirty();
  6865. }
  6866. BuildDisplayName();
  6867. if ( m_hRoot != NULL )
  6868. {
  6869. hr = SetRootNode();
  6870. if ( hr != S_OK )
  6871. {
  6872. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOP: Setting the root scope item failed with 0x%x"), hr));
  6873. return E_FAIL;
  6874. }
  6875. if ( m_bRootExpanded )
  6876. {
  6877. // Must recreate root subitems since MMC does not seem to notice that it must re-expand the node if all its subitems
  6878. // where deleted.
  6879. hr = EnumerateScopePane( m_hRoot );
  6880. if ( FAILED(hr) )
  6881. {
  6882. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOP: Enumerating the scope items failed with 0x%x"), hr));
  6883. return E_FAIL;
  6884. }
  6885. }
  6886. else
  6887. {
  6888. hr = m_pScope->Expand( m_hRoot );
  6889. if ( FAILED(hr) )
  6890. {
  6891. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOP: Expanding the scope items failed with 0x%x"), hr));
  6892. return E_FAIL;
  6893. }
  6894. if ( hr == S_FALSE )
  6895. {
  6896. DebugMsg((DM_WARNING, TEXT("CRSOPComponentData::InitializeRSOP: Expanding the scope items seemingly already done.")));
  6897. hr = S_OK;
  6898. }
  6899. }
  6900. // For refresh and consistency purposes, reselect the root node
  6901. m_pConsole->SelectScopeItem( m_hRoot );
  6902. }
  6903. }
  6904. return hr;
  6905. }
  6906. ///////////////////////////////////////////////////////////////////////////////
  6907. // //
  6908. // Class factory object implementation //
  6909. // //
  6910. ///////////////////////////////////////////////////////////////////////////////
  6911. CRSOPComponentDataCF::CRSOPComponentDataCF()
  6912. {
  6913. m_cRef = 1;
  6914. InterlockedIncrement(&g_cRefThisDll);
  6915. }
  6916. CRSOPComponentDataCF::~CRSOPComponentDataCF()
  6917. {
  6918. InterlockedDecrement(&g_cRefThisDll);
  6919. }
  6920. ///////////////////////////////////////////////////////////////////////////////
  6921. // //
  6922. // Class factory object implementation (IUnknown) //
  6923. // //
  6924. ///////////////////////////////////////////////////////////////////////////////
  6925. STDMETHODIMP_(ULONG)
  6926. CRSOPComponentDataCF::AddRef()
  6927. {
  6928. return ++m_cRef;
  6929. }
  6930. STDMETHODIMP_(ULONG)
  6931. CRSOPComponentDataCF::Release()
  6932. {
  6933. if (--m_cRef == 0)
  6934. {
  6935. delete this;
  6936. return 0;
  6937. }
  6938. return m_cRef;
  6939. }
  6940. STDMETHODIMP
  6941. CRSOPComponentDataCF::QueryInterface(REFIID riid, LPVOID FAR* ppv)
  6942. {
  6943. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  6944. {
  6945. *ppv = (LPCLASSFACTORY)this;
  6946. m_cRef++;
  6947. return S_OK;
  6948. }
  6949. else
  6950. {
  6951. *ppv = NULL;
  6952. return E_NOINTERFACE;
  6953. }
  6954. }
  6955. ///////////////////////////////////////////////////////////////////////////////
  6956. // //
  6957. // Class factory object implementation (IClassFactory) //
  6958. // //
  6959. ///////////////////////////////////////////////////////////////////////////////
  6960. STDMETHODIMP
  6961. CRSOPComponentDataCF::CreateInstance(LPUNKNOWN pUnkOuter,
  6962. REFIID riid,
  6963. LPVOID FAR* ppvObj)
  6964. {
  6965. *ppvObj = NULL;
  6966. if (pUnkOuter)
  6967. return CLASS_E_NOAGGREGATION;
  6968. CRSOPComponentData *pComponentData = new CRSOPComponentData(); // ref count == 1
  6969. if (!pComponentData)
  6970. return E_OUTOFMEMORY;
  6971. HRESULT hr = pComponentData->QueryInterface(riid, ppvObj);
  6972. pComponentData->Release(); // release initial ref
  6973. return hr;
  6974. }
  6975. STDMETHODIMP
  6976. CRSOPComponentDataCF::LockServer(BOOL fLock)
  6977. {
  6978. return E_NOTIMPL;
  6979. }
  6980. ///////////////////////////////////////////////////////////////////////////////
  6981. // //
  6982. // Class factory implementation for rsop context menu //
  6983. // //
  6984. ///////////////////////////////////////////////////////////////////////////////
  6985. CRSOPCMenuCF::CRSOPCMenuCF()
  6986. {
  6987. m_cRef = 1;
  6988. InterlockedIncrement(&g_cRefThisDll);
  6989. }
  6990. CRSOPCMenuCF::~CRSOPCMenuCF()
  6991. {
  6992. InterlockedDecrement(&g_cRefThisDll);
  6993. }
  6994. ///////////////////////////////////////////////////////////////////////////////
  6995. // //
  6996. // Class factory object implementation (IUnknown) //
  6997. // //
  6998. ///////////////////////////////////////////////////////////////////////////////
  6999. STDMETHODIMP_(ULONG)
  7000. CRSOPCMenuCF::AddRef()
  7001. {
  7002. return InterlockedIncrement(&m_cRef);
  7003. }
  7004. STDMETHODIMP_(ULONG)
  7005. CRSOPCMenuCF::Release()
  7006. {
  7007. m_cRef = InterlockedDecrement(&m_cRef);
  7008. if (m_cRef == 0)
  7009. {
  7010. delete this;
  7011. return 0;
  7012. }
  7013. return m_cRef;
  7014. }
  7015. STDMETHODIMP
  7016. CRSOPCMenuCF::QueryInterface(REFIID riid, LPVOID FAR* ppv)
  7017. {
  7018. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  7019. {
  7020. *ppv = (LPCLASSFACTORY)this;
  7021. AddRef();
  7022. return S_OK;
  7023. }
  7024. else
  7025. {
  7026. *ppv = NULL;
  7027. return E_NOINTERFACE;
  7028. }
  7029. }
  7030. ///////////////////////////////////////////////////////////////////////////////
  7031. // //
  7032. // Class factory object implementation (IClassFactory) //
  7033. // //
  7034. ///////////////////////////////////////////////////////////////////////////////
  7035. STDMETHODIMP
  7036. CRSOPCMenuCF::CreateInstance(LPUNKNOWN pUnkOuter,
  7037. REFIID riid,
  7038. LPVOID FAR* ppvObj)
  7039. {
  7040. *ppvObj = NULL;
  7041. if (pUnkOuter)
  7042. return CLASS_E_NOAGGREGATION;
  7043. CRSOPCMenu *pRsopCMenu = new CRSOPCMenu(); // ref count == 1
  7044. if (!pRsopCMenu)
  7045. return E_OUTOFMEMORY;
  7046. HRESULT hr = pRsopCMenu->QueryInterface(riid, ppvObj);
  7047. pRsopCMenu->Release(); // release initial ref
  7048. return hr;
  7049. }
  7050. STDMETHODIMP
  7051. CRSOPCMenuCF::LockServer(BOOL fLock)
  7052. {
  7053. return E_NOTIMPL;
  7054. }
  7055. ///////////////////////////////////////////////////////////////////////////////
  7056. // //
  7057. // CRSOPCMenu implementation for rsop context menu //
  7058. // //
  7059. ///////////////////////////////////////////////////////////////////////////////
  7060. CRSOPCMenu::CRSOPCMenu()
  7061. {
  7062. m_cRef = 1;
  7063. m_lpDSObject = NULL;
  7064. m_szDN = NULL;
  7065. m_szDomain = NULL;
  7066. InterlockedIncrement(&g_cRefThisDll);
  7067. }
  7068. CRSOPCMenu::~CRSOPCMenu()
  7069. {
  7070. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu:: Context menu destroyed")));
  7071. InterlockedDecrement(&g_cRefThisDll);
  7072. if (m_lpDSObject)
  7073. LocalFree(m_lpDSObject);
  7074. if (m_szDN)
  7075. {
  7076. LocalFree(m_szDN);
  7077. }
  7078. }
  7079. ///////////////////////////////////////////////////////////////////////////////
  7080. // //
  7081. // CRSOPCMenu implementation (IUnknown) //
  7082. // //
  7083. ///////////////////////////////////////////////////////////////////////////////
  7084. STDMETHODIMP_(ULONG)
  7085. CRSOPCMenu::AddRef()
  7086. {
  7087. return InterlockedIncrement(&m_cRef);
  7088. }
  7089. STDMETHODIMP_(ULONG)
  7090. CRSOPCMenu::Release()
  7091. {
  7092. m_cRef = InterlockedDecrement(&m_cRef);
  7093. if (m_cRef == 0)
  7094. {
  7095. delete this;
  7096. return 0;
  7097. }
  7098. return m_cRef;
  7099. }
  7100. STDMETHODIMP
  7101. CRSOPCMenu::QueryInterface(REFIID riid, LPVOID FAR* ppv)
  7102. {
  7103. if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IExtendContextMenu))
  7104. {
  7105. *ppv = (LPCLASSFACTORY)this;
  7106. AddRef();
  7107. return S_OK;
  7108. }
  7109. else
  7110. {
  7111. *ppv = NULL;
  7112. return E_NOINTERFACE;
  7113. }
  7114. }
  7115. ///////////////////////////////////////////////////////////////////////////////
  7116. // //
  7117. // CRSOPCMenu implementation (IExtendContextMenu) //
  7118. // //
  7119. ///////////////////////////////////////////////////////////////////////////////
  7120. STDMETHODIMP
  7121. CRSOPCMenu::AddMenuItems(LPDATAOBJECT piDataObject,
  7122. LPCONTEXTMENUCALLBACK piCallback,
  7123. long * pInsertionAllowed)
  7124. {
  7125. FORMATETC fm;
  7126. STGMEDIUM medium;
  7127. LPDSOBJECTNAMES lpNames;
  7128. CONTEXTMENUITEM ctxMenu;
  7129. HRESULT hr=S_OK;
  7130. LPTSTR lpTemp;
  7131. HANDLE hTokenUser = 0;
  7132. BOOL bPlAccessGranted = FALSE, bLoAccessGranted = FALSE;
  7133. BOOL bLoNeeded = TRUE;
  7134. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::AddMenuItems: Entering")));
  7135. // if we are not allowed in the tasks menu quit
  7136. if (!((*pInsertionAllowed) & CCM_INSERTIONALLOWED_TASK )) {
  7137. return S_OK;
  7138. }
  7139. //
  7140. // Ask DS admin for the ldap path to the selected object
  7141. //
  7142. ZeroMemory (&fm, sizeof(fm));
  7143. fm.cfFormat = (WORD)m_cfDSObjectName;
  7144. fm.tymed = TYMED_HGLOBAL;
  7145. ZeroMemory (&medium, sizeof(medium));
  7146. medium.tymed = TYMED_HGLOBAL;
  7147. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_NODISCARD, 512);
  7148. if (medium.hGlobal)
  7149. {
  7150. hr = piDataObject->GetData(&fm, &medium);
  7151. if (SUCCEEDED(hr))
  7152. {
  7153. lpNames = (LPDSOBJECTNAMES) GlobalLock (medium.hGlobal);
  7154. if (lpNames) {
  7155. lpTemp = (LPWSTR) (((LPBYTE)lpNames) + lpNames->aObjects[0].offsetName);
  7156. if (m_lpDSObject)
  7157. {
  7158. LocalFree (m_lpDSObject);
  7159. }
  7160. ULONG ulNoChars;
  7161. ulNoChars = lstrlen (lpTemp) + 1;
  7162. m_lpDSObject = (LPTSTR) LocalAlloc (LPTR, ulNoChars * sizeof(TCHAR));
  7163. if (m_lpDSObject)
  7164. {
  7165. hr = StringCchCopy (m_lpDSObject, ulNoChars, lpTemp);
  7166. ASSERT(SUCCEEDED(hr));
  7167. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::AddMenuItems: LDAP path from DS Admin %s"), m_lpDSObject));
  7168. }
  7169. else {
  7170. hr = HRESULT_FROM_WIN32(GetLastError());
  7171. }
  7172. m_rsopHint = RSOPHintUnknown;
  7173. if (lpNames->aObjects[0].offsetClass) {
  7174. lpTemp = (LPWSTR) (((LPBYTE)lpNames) + lpNames->aObjects[0].offsetClass);
  7175. if (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, lpTemp, -1, TEXT("domainDNS"), -1) == CSTR_EQUAL)
  7176. {
  7177. m_rsopHint = RSOPHintDomain;
  7178. }
  7179. else if (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, lpTemp, -1, TEXT("organizationalUnit"), -1) == CSTR_EQUAL)
  7180. {
  7181. m_rsopHint = RSOPHintOrganizationalUnit;
  7182. }
  7183. else if (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, lpTemp, -1, TEXT("site"), -1) == CSTR_EQUAL)
  7184. {
  7185. m_rsopHint = RSOPHintSite;
  7186. }
  7187. else if (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, lpTemp, -1, TEXT("user"), -1) == CSTR_EQUAL)
  7188. {
  7189. m_rsopHint = RSOPHintUser;
  7190. }
  7191. else if (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, lpTemp, -1, TEXT("computer"), -1) == CSTR_EQUAL)
  7192. {
  7193. m_rsopHint = RSOPHintMachine;
  7194. }
  7195. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::AddMenuItems: m_rsopHint = %d"), m_rsopHint));
  7196. } else {
  7197. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::AddMenuItems: No objectclass defined.")));
  7198. }
  7199. GlobalUnlock (medium.hGlobal);
  7200. }
  7201. else {
  7202. hr = HRESULT_FROM_WIN32(GetLastError());
  7203. }
  7204. }
  7205. GlobalFree(medium.hGlobal);
  7206. }
  7207. else {
  7208. hr = HRESULT_FROM_WIN32(GetLastError());
  7209. }
  7210. //
  7211. // if we got our data as expected add the menu
  7212. //
  7213. if (SUCCEEDED(hr)) {
  7214. LPWSTR szContainer = NULL;
  7215. LPWSTR szTempDN = NULL;
  7216. //
  7217. // Now check whether the user has right to do rsop generation
  7218. // if the container is anything other than the Site
  7219. //
  7220. if (m_szDomain) {
  7221. LocalFree(m_szDomain);
  7222. m_szDomain = NULL;
  7223. }
  7224. ParseDN(m_lpDSObject, &m_szDomain, &szTempDN, &szContainer);
  7225. if (m_szDN)
  7226. {
  7227. LocalFree(m_szDN);
  7228. m_szDN = NULL;
  7229. }
  7230. if (szTempDN)
  7231. {
  7232. hr = UnEscapeLdapPath(szTempDN, &m_szDN);
  7233. }
  7234. if (FAILED(hr))
  7235. {
  7236. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::AddMenuItems: UnEscapeLdapPath failed. Error 0x%x"), hr));
  7237. bLoAccessGranted = bPlAccessGranted = FALSE;
  7238. }
  7239. else {
  7240. if ((m_rsopHint == RSOPHintMachine) || (m_rsopHint == RSOPHintUser))
  7241. bLoNeeded = TRUE;
  7242. else
  7243. bLoNeeded = FALSE;
  7244. if (m_rsopHint != RSOPHintSite) {
  7245. if (!OpenThreadToken (GetCurrentThread(), TOKEN_IMPERSONATE | TOKEN_DUPLICATE | TOKEN_QUERY, TRUE, &hTokenUser)) {
  7246. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_IMPERSONATE | TOKEN_DUPLICATE | TOKEN_QUERY, &hTokenUser)) {
  7247. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::AddMenuItems: Couldn't get process token. Error %d"), GetLastError()));
  7248. bLoAccessGranted = bPlAccessGranted = FALSE;
  7249. }
  7250. }
  7251. if (hTokenUser) {
  7252. DWORD dwErr;
  7253. dwErr = CheckAccessForPolicyGeneration( hTokenUser, szContainer, m_szDomain, FALSE, &bPlAccessGranted);
  7254. if (dwErr != ERROR_SUCCESS) {
  7255. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::AddMenuItems: CheckAccessForPolicyGeneration. Error %d"), dwErr));
  7256. bPlAccessGranted = FALSE;
  7257. }
  7258. if (bLoNeeded) {
  7259. dwErr = CheckAccessForPolicyGeneration( hTokenUser, szContainer, m_szDomain, TRUE, &bLoAccessGranted);
  7260. if (dwErr != ERROR_SUCCESS) {
  7261. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::AddMenuItems: CheckAccessForPolicyGeneration. Error %d"), dwErr));
  7262. bLoAccessGranted = FALSE;
  7263. }
  7264. }
  7265. CloseHandle(hTokenUser);
  7266. }
  7267. }
  7268. else {
  7269. bPlAccessGranted = TRUE;
  7270. }
  7271. }
  7272. if (bPlAccessGranted) {
  7273. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::AddMenuItems: User has right to do Planning RSOP")));
  7274. }
  7275. if (bLoAccessGranted) {
  7276. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::AddMenuItems: User has right to do Logging RSOP")));
  7277. }
  7278. //
  7279. // Add the Context menu appropriately
  7280. //
  7281. WCHAR szMenuName[150];
  7282. memset(&ctxMenu, 0, sizeof(ctxMenu));
  7283. LoadString (g_hInstance, IDS_RSOP_PLANNING, szMenuName, ARRAYSIZE(szMenuName));
  7284. ctxMenu.strName = szMenuName;
  7285. ctxMenu.strStatusBarText = NULL;
  7286. ctxMenu.lCommandID = RSOP_LAUNCH_PLANNING; // no sp. flags
  7287. ctxMenu.lInsertionPointID = CCM_INSERTIONPOINTID_3RDPARTY_TASK;
  7288. if (bPlAccessGranted)
  7289. ctxMenu.fFlags = MF_ENABLED;
  7290. else
  7291. ctxMenu.fFlags = MF_GRAYED | MF_DISABLED;
  7292. hr = piCallback->AddItem(&ctxMenu);
  7293. if (bLoNeeded) {
  7294. LoadString (g_hInstance, IDS_RSOP_LOGGING, szMenuName, ARRAYSIZE(szMenuName));
  7295. ctxMenu.strName = szMenuName;
  7296. ctxMenu.strStatusBarText = NULL;
  7297. ctxMenu.lCommandID = RSOP_LAUNCH_LOGGING; // no sp. flags
  7298. ctxMenu.lInsertionPointID = CCM_INSERTIONPOINTID_3RDPARTY_TASK;
  7299. if (bLoAccessGranted)
  7300. ctxMenu.fFlags = MF_ENABLED;
  7301. else
  7302. ctxMenu.fFlags = MF_GRAYED | MF_DISABLED;
  7303. hr = piCallback->AddItem(&ctxMenu);
  7304. }
  7305. }
  7306. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::AddMenuItems: Leaving hr = 0x%x"), hr));
  7307. return hr;
  7308. }
  7309. STDMETHODIMP
  7310. CRSOPCMenu::Command(long lCommandID, LPDATAOBJECT piDataObject)
  7311. {
  7312. DWORD dwSize = 0;
  7313. LPTSTR szArguments=NULL, lpEnd=NULL;
  7314. SHELLEXECUTEINFO ExecInfo;
  7315. LPTSTR szUserName=NULL, szMachName=NULL;
  7316. LPTSTR szFile = NULL;
  7317. HRESULT hr;
  7318. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::Command: lCommandID = %d"), lCommandID));
  7319. //
  7320. // Launch rsop.msc with the appropriate cmd line arguments
  7321. //
  7322. dwSize += lstrlen(RSOP_MODE) + 10;
  7323. if (m_rsopHint == RSOPHintSite) {
  7324. dwSize += lstrlen(RSOP_SITENAME) + lstrlen(m_szDN)+10;
  7325. }
  7326. if (m_rsopHint == RSOPHintDomain) {
  7327. dwSize += lstrlen(RSOP_COMP_OU_PREF) + lstrlen(m_szDN)+10;
  7328. dwSize += lstrlen(RSOP_USER_OU_PREF) + lstrlen(m_szDN)+10;
  7329. }
  7330. if (m_rsopHint == RSOPHintOrganizationalUnit) {
  7331. dwSize += lstrlen(RSOP_COMP_OU_PREF) + lstrlen(m_szDN)+10;
  7332. dwSize += lstrlen(RSOP_USER_OU_PREF) + lstrlen(m_szDN)+10;
  7333. }
  7334. if (m_rsopHint == RSOPHintMachine) {
  7335. szMachName = MyTranslateName(m_szDN, NameFullyQualifiedDN, NameSamCompatible);
  7336. if (!szMachName) {
  7337. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: MyTranslateName failed with error %d"), GetLastError()));
  7338. goto Exit;
  7339. }
  7340. dwSize += lstrlen(RSOP_COMP_NAME) + lstrlen(szMachName)+10;
  7341. }
  7342. if (m_rsopHint == RSOPHintUser) {
  7343. szUserName = MyTranslateName(m_szDN, NameFullyQualifiedDN, NameSamCompatible);
  7344. if (!szUserName) {
  7345. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: MyTranslateName failed with error %d"), GetLastError()));
  7346. goto Exit;
  7347. }
  7348. dwSize += lstrlen(RSOP_USER_NAME) + lstrlen(szUserName)+10;
  7349. }
  7350. if (m_szDomain) {
  7351. dwSize += lstrlen(RSOP_DCNAME_PREF) + lstrlen(m_szDomain)+10;
  7352. }
  7353. szArguments = (LPTSTR) LocalAlloc (LPTR, dwSize * sizeof(TCHAR));
  7354. if (!szArguments)
  7355. {
  7356. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Failed to allocate memory with %d"),
  7357. GetLastError()));
  7358. goto Exit;
  7359. }
  7360. ULONG ulNoChars;
  7361. hr = StringCchPrintf (szArguments, dwSize, TEXT("/s "));
  7362. if (FAILED(hr))
  7363. {
  7364. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7365. goto Exit;
  7366. }
  7367. lpEnd = szArguments + lstrlen(szArguments);
  7368. ulNoChars = dwSize - lstrlen(szArguments);
  7369. //
  7370. // Build the command line arguments
  7371. //
  7372. hr = StringCchPrintf(lpEnd, ulNoChars, L"%s\"%d\" ", RSOP_MODE, (lCommandID == RSOP_LAUNCH_PLANNING) ? 1 : 0);
  7373. if (FAILED(hr))
  7374. {
  7375. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7376. goto Exit;
  7377. }
  7378. lpEnd = szArguments + lstrlen(szArguments);
  7379. ulNoChars = dwSize - lstrlen(szArguments);
  7380. if (m_rsopHint == RSOPHintSite)
  7381. {
  7382. hr = StringCchPrintf(lpEnd, ulNoChars, L"%s\"%s\" ", RSOP_SITENAME, m_szDN);
  7383. if (FAILED(hr))
  7384. {
  7385. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7386. goto Exit;
  7387. }
  7388. lpEnd = szArguments + lstrlen(szArguments);
  7389. ulNoChars = dwSize - lstrlen(szArguments);
  7390. }
  7391. if (m_rsopHint == RSOPHintDomain) {
  7392. hr = StringCchPrintf (lpEnd, ulNoChars, L"%s\"%s\" ", RSOP_COMP_OU_PREF, m_szDN);
  7393. if (FAILED(hr))
  7394. {
  7395. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7396. goto Exit;
  7397. }
  7398. lpEnd = szArguments + lstrlen(szArguments);
  7399. ulNoChars = dwSize - lstrlen(szArguments);
  7400. hr = StringCchPrintf (lpEnd, ulNoChars, L"%s\"%s\" ", RSOP_USER_OU_PREF, m_szDN);
  7401. if (FAILED(hr))
  7402. {
  7403. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7404. goto Exit;
  7405. }
  7406. lpEnd = szArguments + lstrlen(szArguments);
  7407. ulNoChars = dwSize - lstrlen(szArguments);
  7408. }
  7409. if (m_rsopHint == RSOPHintOrganizationalUnit) {
  7410. hr = StringCchPrintf (lpEnd, ulNoChars, L"%s\"%s\" ", RSOP_COMP_OU_PREF, m_szDN);
  7411. if (FAILED(hr))
  7412. {
  7413. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7414. goto Exit;
  7415. }
  7416. lpEnd = szArguments + lstrlen(szArguments);
  7417. ulNoChars = dwSize - lstrlen(szArguments);
  7418. hr = StringCchPrintf (lpEnd, ulNoChars, L"%s\"%s\" ", RSOP_USER_OU_PREF, m_szDN);
  7419. if (FAILED(hr))
  7420. {
  7421. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7422. goto Exit;
  7423. }
  7424. lpEnd = szArguments + lstrlen(szArguments);
  7425. ulNoChars = dwSize - lstrlen(szArguments);
  7426. }
  7427. if (m_rsopHint == RSOPHintMachine) {
  7428. hr = StringCchPrintf (lpEnd, ulNoChars, L"%s\"%s\" ", RSOP_COMP_NAME, szMachName);
  7429. if (FAILED(hr))
  7430. {
  7431. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7432. goto Exit;
  7433. }
  7434. lpEnd = szArguments + lstrlen(szArguments);
  7435. ulNoChars = dwSize - lstrlen(szArguments);
  7436. }
  7437. if (m_rsopHint == RSOPHintUser) {
  7438. hr = StringCchPrintf (lpEnd, ulNoChars, L"%s\"%s\" ", RSOP_USER_NAME, szUserName);
  7439. if (FAILED(hr))
  7440. {
  7441. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7442. goto Exit;
  7443. }
  7444. lpEnd = szArguments + lstrlen(szArguments);
  7445. ulNoChars = dwSize - lstrlen(szArguments);
  7446. }
  7447. if (m_szDomain) {
  7448. hr = StringCchPrintf (lpEnd, ulNoChars, L"%s\"%s\" ", RSOP_DCNAME_PREF, m_szDomain);
  7449. if (FAILED(hr))
  7450. {
  7451. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7452. goto Exit;
  7453. }
  7454. lpEnd = szArguments + lstrlen(szArguments);
  7455. ulNoChars = dwSize - lstrlen(szArguments);
  7456. }
  7457. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::Command: Starting GPE with %s"), szArguments));
  7458. // Get the file to execute with the right path
  7459. TCHAR szRSOPMSC[] = TEXT("rsop.msc");
  7460. ulNoChars = MAX_PATH + _tcslen(szRSOPMSC) + 2;
  7461. szFile = new TCHAR[ulNoChars];
  7462. if ( szFile == NULL )
  7463. {
  7464. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Failed to allocate memory.")));
  7465. goto Exit;
  7466. }
  7467. UINT uPathSize = GetSystemDirectory( szFile, MAX_PATH);
  7468. if ( uPathSize == 0 )
  7469. {
  7470. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Failed to get the system directory with %d"),
  7471. GetLastError()));
  7472. goto Exit;
  7473. }
  7474. else if ( uPathSize > MAX_PATH )
  7475. {
  7476. delete [] szFile;
  7477. ulNoChars = uPathSize + _tcslen(szRSOPMSC) + 2;
  7478. szFile = new TCHAR[ulNoChars];
  7479. if ( szFile == NULL )
  7480. {
  7481. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Failed to allocate memory.")));
  7482. goto Exit;
  7483. }
  7484. UINT uPathSize2 = GetSystemDirectory( szFile, uPathSize );
  7485. if ( uPathSize2 == 0 )
  7486. {
  7487. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Failed to get the system directory with %d"),
  7488. GetLastError()));
  7489. goto Exit;
  7490. }
  7491. }
  7492. if ( szFile[_tcslen(szFile)-1] != _T('\\') )
  7493. {
  7494. szFile[_tcslen(szFile)+1] = _T('\0');
  7495. szFile[_tcslen(szFile)] = _T('\\');
  7496. }
  7497. hr = StringCchCat ( szFile, ulNoChars, szRSOPMSC );
  7498. if (FAILED(hr))
  7499. {
  7500. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: Could not copy arguments with 0x%x"), hr));
  7501. goto Exit;
  7502. }
  7503. // Set up the execution info
  7504. ZeroMemory (&ExecInfo, sizeof(ExecInfo));
  7505. ExecInfo.cbSize = sizeof(ExecInfo);
  7506. ExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  7507. ExecInfo.lpVerb = TEXT("open");
  7508. ExecInfo.lpFile = szFile;
  7509. ExecInfo.lpParameters = szArguments;
  7510. ExecInfo.nShow = SW_SHOWNORMAL;
  7511. if (ShellExecuteEx (&ExecInfo))
  7512. {
  7513. DebugMsg((DM_VERBOSE, TEXT("CRSOPCMenu::Command: Launched rsop tool")));
  7514. SetWaitCursor();
  7515. WaitForInputIdle (ExecInfo.hProcess, 10000);
  7516. ClearWaitCursor();
  7517. CloseHandle (ExecInfo.hProcess);
  7518. }
  7519. else
  7520. {
  7521. DebugMsg((DM_WARNING, TEXT("CRSOPCMenu::Command: ShellExecuteEx failed with %d"),
  7522. GetLastError()));
  7523. // ReportError(NULL, GetLastError(), IDS_SPAWNRSOPFAILED);
  7524. goto Exit;
  7525. }
  7526. Exit:
  7527. if (szUserName) {
  7528. LocalFree(szUserName);
  7529. }
  7530. if (szMachName) {
  7531. LocalFree(szMachName);
  7532. }
  7533. if (szArguments) {
  7534. LocalFree (szArguments);
  7535. }
  7536. if (szFile != NULL)
  7537. {
  7538. delete [] szFile;
  7539. }
  7540. return S_OK;
  7541. }
  7542. BOOL
  7543. EnableWMIFilters( LPWSTR szGPOPath )
  7544. {
  7545. BOOL bReturn = FALSE;
  7546. LPWSTR szDomain = szGPOPath;
  7547. IWbemLocator* pLocator = 0;
  7548. IWbemServices* pServices = 0;
  7549. HRESULT hr;
  7550. while ( szDomain )
  7551. {
  7552. if ( CompareString( LOCALE_INVARIANT,
  7553. NORM_IGNORECASE,
  7554. szDomain,
  7555. 3,
  7556. L"DC=",
  7557. 3 ) == CSTR_EQUAL )
  7558. {
  7559. break;
  7560. }
  7561. szDomain++;
  7562. }
  7563. if ( !szDomain )
  7564. {
  7565. goto Exit;
  7566. }
  7567. hr = CoCreateInstance( CLSID_WbemLocator,
  7568. 0,
  7569. CLSCTX_INPROC_SERVER,
  7570. IID_IWbemLocator,
  7571. (void**) &pLocator );
  7572. if ( FAILED( hr ) )
  7573. {
  7574. goto Exit;
  7575. }
  7576. BSTR xbstrNamespace = SysAllocString( L"\\\\.\\root\\Policy" );
  7577. if ( !xbstrNamespace )
  7578. {
  7579. goto Exit;
  7580. }
  7581. hr = pLocator->ConnectServer( xbstrNamespace, // namespace
  7582. 0, // user
  7583. 0, // password
  7584. 0, // locale
  7585. 0, // security flags
  7586. 0, // authority
  7587. 0, // Wbem context
  7588. &pServices ); // IWbemServices
  7589. SysFreeString( xbstrNamespace );
  7590. if ( FAILED( hr ) )
  7591. {
  7592. goto Exit;
  7593. }
  7594. WCHAR szDomainCanonical[512];
  7595. DWORD dwSize = 512;
  7596. if ( !TranslateName(szDomain,
  7597. NameUnknown,
  7598. NameCanonical,
  7599. szDomainCanonical,
  7600. &dwSize ) )
  7601. {
  7602. goto Exit;
  7603. }
  7604. LPWSTR szTemp = wcsrchr( szDomainCanonical, L'/' );
  7605. if ( szTemp )
  7606. {
  7607. *szTemp = 0;
  7608. }
  7609. WCHAR szBuffer[512];
  7610. hr = StringCchPrintf ( szBuffer, ARRAYSIZE(szBuffer), L"MSFT_SomFilterStatus.domain=\"%s\"", szDomainCanonical );
  7611. if (FAILED(hr))
  7612. {
  7613. goto Exit;
  7614. }
  7615. BSTR bstrObjectPath = SysAllocString( szBuffer );
  7616. if ( !bstrObjectPath )
  7617. {
  7618. goto Exit;
  7619. }
  7620. // Set the proper security to encrypt the data
  7621. hr = CoSetProxyBlanket(pServices,
  7622. RPC_C_AUTHN_WINNT,
  7623. RPC_C_AUTHZ_DEFAULT,
  7624. 0,
  7625. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  7626. RPC_C_IMP_LEVEL_IMPERSONATE,
  7627. 0,
  7628. 0);
  7629. if ( FAILED( hr ) )
  7630. {
  7631. SysFreeString( bstrObjectPath );
  7632. goto Exit;
  7633. }
  7634. IWbemClassObject* xObject = 0;
  7635. hr = pServices->GetObject( bstrObjectPath,
  7636. WBEM_FLAG_RETURN_WBEM_COMPLETE,
  7637. 0,
  7638. &xObject,
  7639. 0 );
  7640. SysFreeString( bstrObjectPath );
  7641. if ( FAILED( hr ) )
  7642. {
  7643. goto Exit;
  7644. }
  7645. VARIANT var;
  7646. VariantInit(&var);
  7647. hr = xObject->Get(L"SchemaAvailable", 0, &var, NULL, NULL);
  7648. if((FAILED(hr)) || ( var.vt == VT_NULL ))
  7649. {
  7650. DebugMsg((DM_WARNING, TEXT("EnableWMIFilters: Get failed for SchemaAvailable with error 0x%x"), hr));
  7651. goto Exit;
  7652. }
  7653. if (var.boolVal == VARIANT_FALSE )
  7654. {
  7655. VariantClear(&var);
  7656. goto Exit;
  7657. }
  7658. VariantClear(&var);
  7659. DebugMsg((DM_VERBOSE, TEXT("Schema is available for wmi filters")));
  7660. bReturn = TRUE;
  7661. Exit:
  7662. if ( pLocator )
  7663. {
  7664. pLocator->Release();
  7665. }
  7666. if ( pServices )
  7667. {
  7668. pServices->Release();
  7669. }
  7670. return bReturn;
  7671. }