Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1934 lines
63 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) 1995-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #include "stdafx.h"
  9. #include "afxdlgs.h"
  10. #include "cookie.h"
  11. #include "snapmgr.h"
  12. #include "util.h"
  13. #include "AString.h"
  14. #include "ANumber.h"
  15. #include "AEnable.h"
  16. #include "AAudit.h"
  17. #include "ARet.h"
  18. #include "ARight.h"
  19. #include "CAudit.h"
  20. #include "CNumber.h"
  21. #include "CEnable.h"
  22. #include "CName.h"
  23. #include "CPrivs.h"
  24. #include "CGroup.h"
  25. #include "Cret.h"
  26. #include "chklist.h"
  27. #include "servperm.h"
  28. #include "aobject.h"
  29. #include "cobject.h"
  30. #include "UIThread.h"
  31. #ifdef _DEBUG
  32. #define new DEBUG_NEW
  33. #undef THIS_FILE
  34. static char THIS_FILE[] = __FILE__;
  35. #endif
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Event handlers for IFrame::Notify
  38. /////////////////////////////////////////////////////////////////////////////
  39. HRESULT CSnapin::OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  40. {
  41. ASSERT(FALSE);
  42. return S_OK;
  43. }
  44. HRESULT CSnapin::OnShow(LPDATAOBJECT pDataObj, MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  45. {
  46. // Note - arg is TRUE when it is time to enumerate
  47. if (arg == TRUE)
  48. {
  49. m_ShowCookie = cookie;
  50. // Show the headers for this nodetype
  51. InitializeHeaders(cookie);
  52. // Show data
  53. EnumerateResultPane(cookie, param, pDataObj);
  54. // BUBBUG - Demonstration to should how you can attach
  55. // and a toolbar when a particular nodes gets focus.
  56. // warning this needs to be here as the toolbars are
  57. // currently hidden when the previous node looses focus.
  58. // This should be update to show the user how to hide
  59. // and show toolbars. (Detach and Attach).
  60. //m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar1);
  61. //m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar2);
  62. }
  63. else
  64. {
  65. // Free data associated with the result pane items, because
  66. // your node is no longer being displayed.
  67. // Note: The console will remove the items from the result pane
  68. m_ShowCookie = 0;
  69. DeleteServiceResultList(cookie);
  70. DeleteList(FALSE);
  71. }
  72. return S_OK;
  73. }
  74. HRESULT CSnapin::OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  75. {
  76. return S_OK;
  77. }
  78. BOOL CALLBACK MyPropSheetDlgProc(HWND hwnd, UINT uMsg, WPARAM wp, LPARAM lp)
  79. {
  80. return FALSE;
  81. }
  82. HRESULT CSnapin::OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  83. {
  84. return S_OK;
  85. }
  86. HRESULT CSnapin::OnPropertyChange(LPDATAOBJECT lpDataObject)
  87. {
  88. return S_OK;
  89. }
  90. //+--------------------------------------------------------------------------
  91. //
  92. // Method: InitializeHeaders
  93. //
  94. // Synopsis: Set the result item headers appropriate for the area
  95. //
  96. // Arguments: [cookie] - [in] the folder whose result item to setting headers for
  97. //
  98. // Returns:
  99. //
  100. // History:
  101. //
  102. //---------------------------------------------------------------------------
  103. SCE_COLUMNINFO g_columnInfo[] = {
  104. { AREA_REGISTRY_ANALYSIS, 5, 0 },
  105. { IDS_COL_OBJECT, LVCFMT_LEFT, 220 },
  106. { IDS_PERMISSION, LVCFMT_LEFT, 80 },
  107. { IDS_AUDITING, LVCFMT_LEFT, 70 },
  108. { IDS_COL_BAD_COUNT, LVCFMT_LEFT, 60 },
  109. { IDS_RSOP_GPO, LVCFMT_LEFT, 100 },
  110. { AREA_REGISTRY, 2, 0 },
  111. { IDS_COL_OBJECT, LVCFMT_LEFT, 220 },
  112. { IDS_RSOP_GPO, LVCFMT_LEFT, 100 },
  113. { AREA_GROUPS, 4, 0 },
  114. { IDS_GROUP_NAME, LVCFMT_LEFT, 200 },
  115. { IDS_COL_MEMBERSHIP, LVCFMT_LEFT, 120 },
  116. { IDS_COL_MEMBEROF, LVCFMT_LEFT, 120 },
  117. { IDS_RSOP_GPO, LVCFMT_LEFT, 100 },
  118. { AREA_SERVICE, 4, 0 },
  119. { IDS_COL_SERVICE, LVCFMT_LEFT, 170 },
  120. { IDS_STARTUP, LVCFMT_LEFT, 80 },
  121. { IDS_PERMISSION, LVCFMT_LEFT, 80 },
  122. { IDS_RSOP_GPO, LVCFMT_LEFT, 100 },
  123. { POLICY_PASSWORD, 3, 0 },
  124. { IDS_ATTR, LVCFMT_LEFT, 250 },
  125. { IDS_BASE_TEMPLATE, LVCFMT_LEFT, 190 },
  126. { IDS_RSOP_GPO, LVCFMT_LEFT, 100 },
  127. { POLICY_PASSWORD_ANALYSIS, 4, 0 },
  128. { IDS_ATTR, LVCFMT_LEFT, 200 },
  129. { IDS_BASE_ANALYSIS, LVCFMT_LEFT, 120 },
  130. { IDS_SETTING, LVCFMT_LEFT, 120 },
  131. { IDS_RSOP_GPO, LVCFMT_LEFT, 100 },
  132. { LOCALPOL_PASSWORD, 3, 0 },
  133. { IDS_ATTR, LVCFMT_LEFT, 200 },
  134. { IDS_LOCAL_POLICY_COLUMN, LVCFMT_LEFT, 120 },
  135. { IDS_RSOP_GPO, LVCFMT_LEFT, 100 },
  136. { NONE, 2, 0 },
  137. { IDS_NAME, LVCFMT_LEFT, 180 },
  138. { IDS_DESC, LVCFMT_LEFT, 270 },
  139. };
  140. HRESULT CSnapin::InitializeHeaders(MMC_COOKIE cookie)
  141. {
  142. HRESULT hr = S_OK;
  143. ASSERT(m_pHeader);
  144. // Create a new array of column sizes. We just need to copy the static buffer
  145. // g_columnInfo.
  146. FOLDER_TYPES type;
  147. CFolder* pFolder = (CFolder *)cookie;
  148. if ( NULL == cookie)
  149. {
  150. // the root
  151. type = NONE;
  152. }
  153. else
  154. type = pFolder->GetType();
  155. PSCE_COLUMNINFO pCur = NULL;
  156. CString str;
  157. int i = 0;
  158. int iDesc = 0;
  159. int iInsert = 0;
  160. PSCE_COLINFOARRAY pHeader = NULL;
  161. if(m_pComponentData){
  162. pHeader = reinterpret_cast<CComponentDataImpl *>(m_pComponentData)->GetColumnInfo( type );
  163. }
  164. if( !pHeader )
  165. {
  166. // Create new header look up.
  167. switch(type){
  168. case AREA_REGISTRY:
  169. case AREA_FILESTORE:
  170. type = AREA_REGISTRY;
  171. break;
  172. case AREA_REGISTRY_ANALYSIS:
  173. case AREA_FILESTORE_ANALYSIS:
  174. case REG_OBJECTS:
  175. case FILE_OBJECTS:
  176. type = AREA_REGISTRY_ANALYSIS;
  177. break;
  178. case AREA_GROUPS:
  179. case AREA_GROUPS_ANALYSIS:
  180. type = AREA_GROUPS;
  181. break;
  182. case AREA_SERVICE:
  183. case AREA_SERVICE_ANALYSIS:
  184. type = AREA_SERVICE;
  185. break;
  186. default:
  187. if ( type >= POLICY_PASSWORD &&
  188. type <= AREA_FILESTORE )
  189. {
  190. type = POLICY_PASSWORD;
  191. }
  192. else if ( type >= POLICY_PASSWORD_ANALYSIS &&
  193. type <= REG_OBJECTS )
  194. {
  195. type = POLICY_PASSWORD_ANALYSIS;
  196. }
  197. else if (type >= LOCALPOL_PASSWORD &&
  198. type <= LOCALPOL_LAST)
  199. {
  200. type = LOCALPOL_PASSWORD;
  201. }
  202. else
  203. {
  204. type = NONE;
  205. }
  206. break;
  207. }
  208. pCur = g_columnInfo;
  209. for( i = 0; i < sizeof(g_columnInfo)/sizeof(SCE_COLUMNINFO);i++)
  210. {
  211. if(pCur[i].colID == type)
  212. {
  213. iInsert = pCur[i].nCols;
  214. i++;
  215. break;
  216. }
  217. i += pCur[i].nCols;
  218. }
  219. //
  220. // RSOP Mode has an extra column for the GPO source
  221. // If we're not in RSOP mode then ignore that column
  222. //
  223. if (((GetModeBits() & MB_RSOP) != MB_RSOP) && (NONE != type))
  224. {
  225. iInsert--;
  226. }
  227. if(pFolder)
  228. {
  229. type = pFolder->GetType();
  230. }
  231. iDesc = i;
  232. pCur += iDesc;
  233. pHeader = (PSCE_COLINFOARRAY)LocalAlloc(0, sizeof(SCE_COLINFOARRAY) + (sizeof(int) * iInsert) );
  234. if(pHeader)
  235. {
  236. pHeader->iIndex = i;
  237. pHeader->nCols = iInsert;
  238. for(i = 0; i < iInsert; i++)
  239. {
  240. pHeader->nWidth[i] = pCur[i].nWidth;
  241. }
  242. reinterpret_cast<CComponentDataImpl *>(m_pComponentData)->SetColumnInfo( type, pHeader );
  243. }
  244. }
  245. else
  246. {
  247. iDesc = pHeader->iIndex;
  248. iInsert = pHeader->nCols;
  249. }
  250. // Insert the columns.
  251. m_nColumns = iInsert;
  252. BOOL bGroupPolicy = FALSE;
  253. //
  254. // special case Group Policy mode since "Policy Setting" has
  255. // to be displayed instead of "Computer Setting"
  256. //
  257. if (GetModeBits() & MB_GROUP_POLICY)
  258. {
  259. bGroupPolicy = TRUE;
  260. }
  261. pCur = g_columnInfo + iDesc;
  262. for(i = 0; i < iInsert; i++)
  263. {
  264. if (bGroupPolicy && pCur->colID == IDS_BASE_TEMPLATE)
  265. {
  266. str.LoadString( IDS_POLICY_SETTING );
  267. }
  268. else
  269. {
  270. str.LoadString( pCur->colID );
  271. }
  272. if(pHeader)
  273. {
  274. m_pHeader->InsertColumn( i, str, pCur->nCols, pHeader->nWidth[i] );
  275. }
  276. else
  277. {
  278. m_pHeader->InsertColumn( i, str, pCur->nCols, pCur->nWidth );
  279. }
  280. pCur++;
  281. }
  282. switch(type) {
  283. case STATIC:
  284. case ROOT:
  285. case ANALYSIS:
  286. case CONFIGURATION:
  287. case LOCATIONS:
  288. case PROFILE:
  289. case LOCALPOL:
  290. case POLICY_LOCAL:
  291. case POLICY_ACCOUNT:
  292. case POLICY_LOCAL_ANALYSIS:
  293. case POLICY_ACCOUNT_ANALYSIS:
  294. case LOCALPOL_ACCOUNT:
  295. case LOCALPOL_LOCAL:
  296. m_pResult->ModifyViewStyle(MMC_NOSORTHEADER,(MMC_RESULT_VIEW_STYLE)0);
  297. break;
  298. default:
  299. m_pResult->ModifyViewStyle((MMC_RESULT_VIEW_STYLE)0,MMC_NOSORTHEADER);
  300. break;
  301. }
  302. return hr;
  303. }
  304. HRESULT CSnapin::InitializeBitmaps(MMC_COOKIE cookie)
  305. {
  306. ASSERT(m_pImageResult != NULL);
  307. CBitmap bmp16x16;
  308. CBitmap bmp32x32;
  309. // Load the bitmaps from the dll
  310. bmp16x16.LoadBitmap(IDB_ICON16 /*IDB_16x16 */);
  311. bmp32x32.LoadBitmap(IDB_ICON32 /*IDB_32x32 */);
  312. // Set the images
  313. m_pImageResult->ImageListSetStrip(reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  314. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp32x32)),
  315. 0, RGB(255, 0, 255));
  316. return S_OK;
  317. }
  318. //+--------------------------------------------------------------------------
  319. //
  320. // Function: CComponentDataImpl::SerializeColumnInfo
  321. //
  322. // Synopsis: Saves or loads column information contained in m_mapColumns.
  323. // The function saves out the information in char format.
  324. // SCECOLUMNS:%d - number of column information structures.
  325. // T:%d, - type of column (key)
  326. // I:%d, - Index into [g_columnInfo]
  327. // C:%d, - Number of columns
  328. // W:%d, - Width of a column.
  329. //
  330. // Arguments: [pStm] - Stream to read or write to.
  331. // [pTotalWrite] - [Optional] Total number of bytes written.
  332. // [bRead] - If True then we should read from the stream.
  333. //
  334. // Returns: ERROR_SUCCESS - Everything was successful.
  335. // E_OUTOFMEMORY - Out of memory.
  336. //
  337. // History:
  338. //
  339. //---------------------------------------------------------------------------
  340. DWORD CComponentDataImpl::SerializeColumnInfo(
  341. IStream *pStm,
  342. ULONG *pTotalWrite,
  343. BOOL bRead)
  344. {
  345. ULONG nBytesWritten = 0;
  346. POSITION pos = NULL;
  347. FOLDER_TYPES fType;
  348. PSCE_COLINFOARRAY pData = 0;
  349. ULONG totalWrite = 0;
  350. int i = 0;
  351. LPCTSTR pszHeader = TEXT("SCECOLUMNS:%d{");
  352. LPCTSTR pszColHead = TEXT("{T:%d,I:%d,C:%d,");
  353. if(!bRead)
  354. {
  355. // Write columns. Save the information in text format so that we will be
  356. // independent of sizeof stuff.
  357. pos = m_mapColumns.GetStartPosition();
  358. totalWrite = 0;
  359. if(pos)
  360. {
  361. char szWrite[256];
  362. // Write header.
  363. totalWrite += WriteSprintf(pStm, pszHeader, m_mapColumns.GetCount());
  364. while(pos)
  365. {
  366. m_mapColumns.GetNextAssoc(pos, fType, pData);
  367. if(pData)
  368. {
  369. // write out the type.
  370. totalWrite += WriteSprintf(pStm, pszColHead, fType, g_columnInfo[pData->iIndex - 1].colID, pData->nCols);
  371. // write out each column width.
  372. for(i = 0; i < pData->nCols; i++)
  373. {
  374. if( i + 1 < pData->nCols)
  375. {
  376. totalWrite += WriteSprintf(pStm, TEXT("W:%d,"), pData->nWidth[i]);
  377. }
  378. else
  379. {
  380. totalWrite += WriteSprintf(pStm, TEXT("W:%d}"), pData->nWidth[i]);
  381. }
  382. }
  383. }
  384. }
  385. totalWrite += WriteSprintf(pStm, TEXT("}"));
  386. }
  387. if(pTotalWrite)
  388. {
  389. *pTotalWrite = totalWrite;
  390. }
  391. }
  392. else
  393. {
  394. int iTotalTypes = 0;
  395. int iIndex = 0;
  396. int nCols = 0;
  397. if( ReadSprintf( pStm, pszHeader, &iTotalTypes) != -1)
  398. {
  399. for( i = 0; i < iTotalTypes; i++)
  400. {
  401. if( ReadSprintf(pStm, pszColHead, &fType, &iIndex, &nCols) == - 1)
  402. {
  403. break;
  404. }
  405. // find index of column information.
  406. for(int k = 0; k < sizeof(g_columnInfo)/sizeof(SCE_COLUMNINFO); k++)
  407. {
  408. if( g_columnInfo[k].colID == iIndex )
  409. {
  410. iIndex = k + 1;
  411. break;
  412. }
  413. }
  414. pData = (PSCE_COLINFOARRAY)LocalAlloc(0, sizeof(SCE_COLINFOARRAY) + (sizeof(int) * nCols) );
  415. if(pData)
  416. {
  417. pData->iIndex = iIndex;
  418. pData->nCols = nCols;
  419. for( iIndex = 0; iIndex < nCols; iIndex++)
  420. {
  421. if( iIndex + 1 < nCols)
  422. ReadSprintf(pStm, TEXT("W:%d,"), &(pData->nWidth[ iIndex ]) );
  423. else
  424. ReadSprintf(pStm, TEXT("W:%d}"), &(pData->nWidth[ iIndex ]) );
  425. }
  426. SetColumnInfo( fType, pData );
  427. }
  428. else
  429. return (DWORD)E_OUTOFMEMORY;
  430. }
  431. ReadSprintf(pStm, TEXT("}"));
  432. }
  433. }
  434. return ERROR_SUCCESS;
  435. }
  436. //+--------------------------------------------------------------------------
  437. //
  438. // Method: EnumerateResultPane
  439. //
  440. // Synopsis: Create the result pane items for the result pane that MMC
  441. // is displaying
  442. //
  443. // Arguments: [cookie] - The cookie representing the node's who we
  444. // are enumerating
  445. // [pParent] - The scope node whose result pane we are showing
  446. // [pDataObj] - The data object for the scope node we are showing
  447. //
  448. // Returns: none
  449. //
  450. // Modifies: m_resultItemList
  451. //
  452. // History: 12-15-1997 Robcap
  453. //
  454. //---------------------------------------------------------------------------
  455. void CSnapin::EnumerateResultPane(MMC_COOKIE cookie, HSCOPEITEM pParent, LPDATAOBJECT pDataObj)
  456. {
  457. PEDITTEMPLATE pTemplateInfo = 0;
  458. PEDITTEMPLATE pProfileTemplate = 0;
  459. PEDITTEMPLATE pBaseTemplate = 0;
  460. PSCE_PROFILE_INFO pProfileInfo = 0;
  461. PSCE_PROFILE_INFO pBaseInfo = 0;
  462. DWORD idErr = 0;
  463. CComponentDataImpl *pccDataImpl = 0;
  464. ASSERT(m_pResult != NULL); // make sure we QI'ed for the interface
  465. ASSERT(m_pComponentData != NULL);
  466. pccDataImpl = (CComponentDataImpl *)m_pComponentData;
  467. //
  468. // This may take a while; let the user have some warning rather than
  469. // just going blank on them
  470. //
  471. CWaitCursor wc;
  472. //
  473. // cookie is the scope pane item for which to enumerate.
  474. // for safety, we should find the object in m_pComponentData
  475. // CFolder* pFolder = dynamic_cast<CComponentDataImpl*>(m_pComponentData)->FindObject(cookie, NULL);
  476. // but for performance (and hopes nothing mess up), we could
  477. // cast the cookie to scope item type (CFolder)
  478. //
  479. CFolder* pFolder = 0;
  480. CString sErr;
  481. SCESTATUS rc = 0;
  482. PSCE_ERROR_LOG_INFO ErrBuf=NULL;
  483. AREA_INFORMATION area=0;
  484. CString StrErr;
  485. PVOID pHandle=NULL;
  486. if ( cookie )
  487. pFolder = (CFolder *)cookie;
  488. else
  489. pFolder = ((CComponentDataImpl *)m_pComponentData)->FindObject(cookie, NULL);
  490. //
  491. // pFolder could be NULL for the root.
  492. //
  493. if ( pFolder == NULL )
  494. return;
  495. FOLDER_TYPES type = pFolder->GetType();
  496. if( pFolder == m_pSelectedFolder &&
  497. m_pSelectedFolder &&
  498. m_pSelectedFolder->GetResultListCount() )
  499. {
  500. //
  501. // Do nothing.
  502. return;
  503. }
  504. else
  505. {
  506. if( m_pSelectedFolder && m_resultItemHandle )
  507. {
  508. m_pSelectedFolder->ReleaseResultItemHandle( m_resultItemHandle );
  509. }
  510. pFolder->GetResultItemHandle( &m_resultItemHandle );
  511. m_pSelectedFolder = pFolder;
  512. if( pFolder->GetResultListCount() )
  513. {
  514. goto AddToResultPane;
  515. }
  516. }
  517. //
  518. // If this is the top Analysis folder and it hasn't been enumerated yet then
  519. // Make sure we do so and put back any folders that we've removed from there,
  520. // Since MMC won't give us a second expand event to do it on
  521. //
  522. //
  523. // The Analysis Pane isn't available now; let the user know why
  524. //
  525. if (type == ANALYSIS)
  526. {
  527. if (((CComponentDataImpl *) m_pComponentData)->m_bIsLocked)
  528. {
  529. //
  530. // should print more informative messages as to why the info isn't available
  531. //
  532. AddResultItem(IDS_ERROR_ANALYSIS_LOCKED, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  533. goto AddToResultPane;
  534. }
  535. if (!(((CComponentDataImpl *) m_pComponentData)->SadHandle))
  536. {
  537. //
  538. // should print more informative messages as to why the info isn't available
  539. //
  540. FormatDBErrorMessage(
  541. ((CComponentDataImpl *)m_pComponentData)->SadErrored,
  542. ((CComponentDataImpl *)m_pComponentData)->SadName,
  543. sErr);
  544. sErr.TrimLeft();
  545. sErr.TrimRight();
  546. AddResultItem(sErr, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  547. goto AddToResultPane;
  548. }
  549. }
  550. if (type == ANALYSIS ||
  551. (type >= AREA_POLICY_ANALYSIS && type <= REG_OBJECTS))
  552. {
  553. CString strDBName;
  554. CString strDBFmt;
  555. CString strDB;
  556. LPTSTR szDBName;
  557. strDB = ((CComponentDataImpl *)m_pComponentData)->SadName;
  558. if (strDB.IsEmpty() || IsSystemDatabase(strDB))
  559. strDBFmt.LoadString(IDS_SYSTEM_DB_NAME_FMT);
  560. else
  561. strDBFmt.LoadString(IDS_PRIVATE_DB_NAME_FMT);
  562. strDBName.Format(strDBFmt,strDB);
  563. szDBName = strDBName.GetBuffer(1);
  564. m_pResult->SetDescBarText(szDBName);
  565. //AddResultItem(strDBFmt,NULL,NULL,ITEM_OTHER,SCE_STATUS_GOOD,cookie);
  566. }
  567. if (type >= CONFIGURATION && type <= AREA_FILESTORE)
  568. {
  569. //
  570. // We're in the Profile area, so we don't need to keep the Analysis area
  571. // open. Close it to save memory:
  572. //
  573. ((CComponentDataImpl *)m_pComponentData)->CloseAnalysisPane();
  574. }
  575. if ( type == PROFILE )
  576. {
  577. //
  578. // Do not display the error message if we do not implement native modes.
  579. //
  580. if( pFolder->GetState() & CFolder::state_InvalidTemplate &&
  581. !(pFolder->GetMode() & MB_NO_NATIVE_NODES ))
  582. {
  583. StrErr.LoadString( IDS_ERROR_CANT_OPEN_PROFILE );
  584. AddResultItem(StrErr, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  585. goto AddToResultPane;
  586. }
  587. else if (pFolder->GetMode() == SCE_MODE_DOMAIN_COMPUTER_ERROR)
  588. {
  589. StrErr.LoadString( IDS_ERROR_NOT_ON_PDC );
  590. AddResultItem(StrErr, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  591. goto AddToResultPane;
  592. }
  593. }
  594. if ( (type < AREA_POLICY) ||
  595. (type > AREA_LAST))
  596. {
  597. return;
  598. }
  599. switch (type)
  600. {
  601. case AREA_PRIVILEGE:
  602. case AREA_PRIVILEGE_ANALYSIS:
  603. case LOCALPOL_PRIVILEGE:
  604. area = AREA_PRIVILEGES;
  605. break;
  606. case AREA_GROUPS:
  607. case AREA_GROUPS_ANALYSIS:
  608. area = AREA_GROUP_MEMBERSHIP;
  609. break;
  610. case AREA_SERVICE:
  611. case AREA_SERVICE_ANALYSIS:
  612. area = AREA_SYSTEM_SERVICE;
  613. break;
  614. case AREA_REGISTRY:
  615. case AREA_REGISTRY_ANALYSIS:
  616. case REG_OBJECTS:
  617. area = AREA_REGISTRY_SECURITY;
  618. break;
  619. case AREA_FILESTORE:
  620. case AREA_FILESTORE_ANALYSIS:
  621. case FILE_OBJECTS:
  622. area = AREA_FILE_SECURITY;
  623. break;
  624. default:
  625. // case AREA_POLICY:
  626. // case AREA_POLICY_ANALYSIS:
  627. // case AREA_LOCALPOL_POLICY:
  628. area = AREA_SECURITY_POLICY;
  629. break;
  630. }
  631. if ( type >= AREA_POLICY &&
  632. type <= AREA_FILESTORE )
  633. {
  634. //
  635. // inf profiles
  636. //
  637. ASSERT(pFolder->GetInfFile());
  638. if ( pFolder->GetInfFile() == NULL )
  639. return;
  640. //
  641. // Get the Profile info from the cache
  642. //
  643. pTemplateInfo = GetTemplate(pFolder->GetInfFile(),AREA_ALL,&idErr);
  644. if (!pTemplateInfo)
  645. {
  646. AddResultItem(idErr,NULL,NULL,ITEM_OTHER,SCE_STATUS_ERROR_NOT_AVAILABLE,cookie);
  647. }
  648. else
  649. {
  650. CreateProfileResultList(cookie,
  651. type,
  652. pTemplateInfo,
  653. pDataObj);
  654. }
  655. }
  656. else if ((type >= LOCALPOL_ACCOUNT) &&
  657. (type <= LOCALPOL_LAST))
  658. {
  659. if (!((CComponentDataImpl*)m_pComponentData)->SadHandle &&
  660. (ERROR_SUCCESS != ((CComponentDataImpl*)m_pComponentData)->SadErrored))
  661. {
  662. ((CComponentDataImpl*)m_pComponentData)->LoadSadInfo(FALSE);
  663. }
  664. pHandle = ((CComponentDataImpl*)m_pComponentData)->SadHandle;
  665. //
  666. // Get the Computer and Last Inspection Templates
  667. //
  668. pTemplateInfo = GetTemplate(GT_EFFECTIVE_POLICY,area,&idErr);
  669. if (!pTemplateInfo)
  670. {
  671. AddResultItem(idErr, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  672. goto AddToResultPane;
  673. }
  674. pBaseTemplate = pTemplateInfo;
  675. pTemplateInfo = GetTemplate(GT_LOCAL_POLICY,area,&idErr);
  676. if (!pTemplateInfo)
  677. {
  678. AddResultItem(idErr, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  679. goto AddToResultPane;
  680. }
  681. pProfileTemplate = pTemplateInfo;
  682. CreateLocalPolicyResultList(cookie, type, pProfileTemplate, pBaseTemplate, pDataObj);
  683. }
  684. else if ( area != AREA_REGISTRY_SECURITY &&
  685. area != AREA_FILE_SECURITY &&
  686. area != AREA_DS_OBJECTS )
  687. {
  688. //
  689. // SadName and SadHandle should already been populated
  690. //
  691. if (!((CComponentDataImpl*)m_pComponentData)->SadHandle &&
  692. ((CComponentDataImpl*)m_pComponentData)->SadErrored != SCESTATUS_SUCCESS)
  693. {
  694. ((CComponentDataImpl*)m_pComponentData)->LoadSadInfo(TRUE);
  695. }
  696. pHandle = ((CComponentDataImpl*)m_pComponentData)->SadHandle;
  697. if ( NULL == pHandle )
  698. {
  699. AddResultItem(IDS_ERROR_NO_ANALYSIS_INFO, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  700. goto AddToResultPane;
  701. }
  702. //
  703. // Get the Computer and Last Inspection Templates
  704. //
  705. pTemplateInfo = GetTemplate(GT_COMPUTER_TEMPLATE,area,&idErr);
  706. if (!pTemplateInfo)
  707. {
  708. AddResultItem(idErr, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  709. goto AddToResultPane;
  710. }
  711. pBaseTemplate = pTemplateInfo;
  712. pTemplateInfo = GetTemplate(GT_LAST_INSPECTION,area,&idErr);
  713. if (!pTemplateInfo)
  714. {
  715. AddResultItem(idErr, NULL, NULL, ITEM_OTHER, SCE_STATUS_ERROR_NOT_AVAILABLE, cookie);
  716. goto AddToResultPane;
  717. }
  718. pProfileTemplate = pTemplateInfo;
  719. CreateAnalysisResultList(cookie, type, pProfileTemplate, pBaseTemplate,pDataObj);
  720. }
  721. else if (AREA_FILE_SECURITY == area)
  722. {
  723. // registry and file objects
  724. // SadName and SadHandle should already been populated
  725. pHandle = ((CComponentDataImpl*)m_pComponentData)->SadHandle;
  726. if ( NULL == pHandle )
  727. {
  728. return;
  729. }
  730. PSCE_OBJECT_CHILDREN ObjectList=NULL;
  731. if ( type == FILE_OBJECTS )
  732. {
  733. // get next level objects
  734. rc = SceGetObjectChildren(pHandle,
  735. SCE_ENGINE_SAP,
  736. area,
  737. pFolder->GetName(),
  738. &ObjectList,
  739. &ErrBuf);
  740. }
  741. CreateObjectResultList(cookie, type, area, ObjectList, pHandle, pDataObj);
  742. if ( (type == REG_OBJECTS || type == FILE_OBJECTS) && ObjectList )
  743. {
  744. SceFreeMemory((PVOID)ObjectList, SCE_STRUCT_OBJECT_CHILDREN);
  745. }
  746. }
  747. // free memory buffers
  748. if ( ErrBuf )
  749. SceFreeMemory((PVOID)ErrBuf, SCE_STRUCT_ERROR_LOG_INFO);
  750. AddToResultPane:
  751. if (m_pResult)
  752. {
  753. //
  754. // Prepare the result window.
  755. //
  756. m_pResult->SetItemCount(
  757. m_pSelectedFolder->GetResultListCount( ),
  758. MMCLV_UPDATE_NOINVALIDATEALL);
  759. RESULTDATAITEM resultItem;
  760. ZeroMemory(&resultItem,sizeof(resultItem));
  761. resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  762. resultItem.str = MMC_CALLBACK;
  763. resultItem.nImage = -1; // equivalent to: MMC_CALLBACK;
  764. // Set the result as the cookie
  765. POSITION pos = NULL;
  766. do {
  767. if( m_pSelectedFolder->GetResultItem(
  768. m_resultItemHandle,
  769. pos,
  770. (CResult **)&(resultItem.lParam)
  771. ) == ERROR_SUCCESS)
  772. {
  773. if(resultItem.lParam)
  774. {
  775. m_pResult->InsertItem(&resultItem);
  776. }
  777. }
  778. else
  779. break;
  780. } while(pos);
  781. m_pResult->Sort(0, 0, 0);
  782. }
  783. }
  784. void ConvertNameListToString(PSCE_NAME_LIST pList, LPTSTR *sz)
  785. {
  786. LPTSTR pszNew;
  787. if (NULL == sz)
  788. return;
  789. if (NULL == pList)
  790. return;
  791. //
  792. // Get Total size for buffer.
  793. //
  794. int iSize = 0;
  795. PSCE_NAME_LIST pTemp = 0;
  796. for( pTemp=pList;pTemp != NULL; pTemp=pTemp->Next)
  797. {
  798. if ( !(pTemp->Name) )
  799. continue;
  800. iSize += lstrlen(pTemp->Name) + 1;
  801. }
  802. //
  803. // Allocate buffer.
  804. //
  805. pszNew = new TCHAR[iSize + 1];
  806. if (!pszNew)
  807. return;
  808. *sz = pszNew;
  809. //
  810. // Copy the strings.
  811. //
  812. for (pTemp=pList; pTemp != NULL; pTemp=pTemp->Next)
  813. {
  814. if (!(pTemp->Name))
  815. continue;
  816. iSize = lstrlen(pTemp->Name);
  817. memcpy(pszNew, pTemp->Name, iSize * sizeof(TCHAR));
  818. pszNew += iSize;
  819. *pszNew = L',';
  820. pszNew++;
  821. }
  822. *(pszNew - 1) = 0;
  823. }
  824. //+--------------------------------------------------------------------------
  825. //
  826. // Method: CreateProfileResultList
  827. //
  828. // Synopsis: Create the result pane items for profile section
  829. //
  830. // Arguments: [cookie] - The cookie representing the folder which we
  831. // are enumerating
  832. // [type] - The type of the folder we are enumerating
  833. // [pSceInfo] - The overall template that we are enumerating
  834. // [pDataObj] - The data object for this folder
  835. //
  836. // Returns: none
  837. //
  838. //---------------------------------------------------------------------------
  839. void
  840. CSnapin::CreateProfileResultList(MMC_COOKIE cookie,
  841. FOLDER_TYPES type,
  842. PEDITTEMPLATE pSceInfo,
  843. LPDATAOBJECT pDataObj)
  844. {
  845. bool bVerify=false;
  846. CString listStr;
  847. PSCE_PRIVILEGE_ASSIGNMENT pPriv=NULL;
  848. PSCE_GROUP_MEMBERSHIP pGroup=NULL;
  849. PSCE_OBJECT_ARRAY pObject = 0;
  850. UINT i = 0;
  851. switch (type)
  852. {
  853. case POLICY_KERBEROS:
  854. case POLICY_PASSWORD:
  855. case POLICY_LOCKOUT:
  856. case POLICY_AUDIT:
  857. case POLICY_OTHER:
  858. case POLICY_LOG:
  859. CreateProfilePolicyResultList(cookie,
  860. type,
  861. pSceInfo,
  862. pDataObj);
  863. break;
  864. case AREA_POLICY:
  865. //
  866. // Policy folder only contains other folders, no actual result items
  867. //
  868. break;
  869. case AREA_PRIVILEGE:
  870. {
  871. CString strDisp;
  872. LPTSTR szDisp;
  873. DWORD cbDisp;
  874. szDisp = new TCHAR [255];
  875. if (!szDisp)
  876. break;
  877. LPTSTR szPriv = new TCHAR [255];
  878. if ( !szPriv )
  879. {
  880. delete[] szDisp;
  881. break;
  882. }
  883. for ( int i2=0; i2<cPrivCnt; i2++ )
  884. {
  885. cbDisp = 255;
  886. if ( SCESTATUS_SUCCESS == SceLookupPrivRightName(i2,szPriv, (PINT)&cbDisp) )
  887. {
  888. for (pPriv=pSceInfo->pTemplate->OtherInfo.smp.pPrivilegeAssignedTo;
  889. pPriv!=NULL;
  890. pPriv=pPriv->Next)
  891. {
  892. if ( _wcsicmp(szPriv, pPriv->Name) == 0 )
  893. break;
  894. }
  895. cbDisp = 255;
  896. if ( pPriv )
  897. {
  898. //
  899. // find it in the template
  900. //
  901. GetRightDisplayName(NULL,(LPCTSTR)pPriv->Name,szDisp,&cbDisp);
  902. AddResultItem(szDisp, // The name of the attribute being added
  903. (LONG_PTR)(i2>=cPrivW2k), // Raid #382263, The last inspected setting of the attribute
  904. (LONG_PTR)pPriv->AssignedTo, // The template setting of the attribute
  905. ITEM_PROF_PRIVS, // The type of of the attribute's data
  906. -1, // The mismatch status of the attribute
  907. cookie, // The cookie for the result item pane
  908. FALSE, // Copy last inspected from template
  909. NULL, // The units the attribute is set in
  910. (LONG_PTR) pPriv, // An id to let us know where to save this attribute
  911. pSceInfo, // The template to save this attribute in
  912. pDataObj // The data object for the scope note who owns the result pane
  913. );
  914. }
  915. else
  916. {
  917. //
  918. // a not configured privilege
  919. //
  920. GetRightDisplayName(NULL,(LPCTSTR)szPriv,szDisp,&cbDisp);
  921. AddResultItem(szDisp, // The name of the attribute being added
  922. (LONG_PTR)(i2>=cPrivW2k), // Raid #382263, The last inspected setting of the attribute
  923. (LONG_PTR)ULongToPtr(SCE_NO_VALUE), // The template setting of the attribute
  924. ITEM_PROF_PRIVS, // The type of of the attribute's data
  925. -1, // The mismatch status of the attribute
  926. cookie, // The cookie for the result item pane
  927. FALSE, // Copy last inspected from template
  928. szPriv, // Save the privilege name in this buffer
  929. 0, // An id to let us know where to save this attribute
  930. pSceInfo, // The template to save this attribute in
  931. pDataObj // The data object for the scope note who owns the result pane
  932. );
  933. }
  934. }
  935. else
  936. {
  937. // impossible, just continue
  938. }
  939. }
  940. delete[] szDisp;
  941. delete[] szPriv;
  942. }
  943. break;
  944. case AREA_GROUPS:
  945. for (pGroup=pSceInfo->pTemplate->pGroupMembership;
  946. pGroup!=NULL;
  947. pGroup=pGroup->Next)
  948. {
  949. AddResultItem((LPCTSTR)pGroup->GroupName, // The name of the attribute being added
  950. 0, // The last inspection
  951. (LONG_PTR)pGroup, // The template info
  952. ITEM_PROF_GROUP, // The type of of the attribute's data
  953. -1, // The mismatch status of the attribute
  954. cookie, // The cookie for the result item pane
  955. FALSE, // Copy last inspected from template
  956. NULL, // The units the attribute is set in
  957. (LONG_PTR)pGroup, // An id to let us know where to save this attribute
  958. pSceInfo, // The template to save this attribute in
  959. pDataObj); // The data object for the scope note who owns the result pane
  960. }
  961. break;
  962. case AREA_SERVICE:
  963. CreateProfServiceResultList(cookie,
  964. type,
  965. pSceInfo,
  966. pDataObj);
  967. break;
  968. case AREA_REGISTRY:
  969. pObject = pSceInfo->pTemplate->pRegistryKeys.pAllNodes;
  970. if ( pObject!=NULL )
  971. {
  972. for (i=0; i<pObject->Count; i++)
  973. {
  974. AddResultItem(pObject->pObjectArray[i]->Name, // The name of the attribute being added
  975. NULL, // The last inspected setting of the attribute
  976. (LONG_PTR)pObject->pObjectArray[i]->pSecurityDescriptor, // The template setting of the attribute
  977. ITEM_PROF_REGSD, // The type of of the attribute's data
  978. pObject->pObjectArray[i]->Status, // The mismatch status of the attribute
  979. cookie, // The cookie for the result item pane
  980. FALSE, // Copy last inspected from template
  981. NULL, // The units the attribute is set in
  982. (LONG_PTR)pObject->pObjectArray[i], // An id to let us know where to save this attribute
  983. pSceInfo, // The template to save this attribute in
  984. pDataObj); // The data object for the scope note who owns the result pane
  985. }
  986. }
  987. break;
  988. case AREA_FILESTORE:
  989. pObject = pSceInfo->pTemplate->pFiles.pAllNodes;
  990. if ( pObject!=NULL )
  991. {
  992. for (i=0; i<pObject->Count; i++)
  993. {
  994. AddResultItem(pObject->pObjectArray[i]->Name, // The name of the attribute being added
  995. NULL, // The last inspected setting of the attribute
  996. (LONG_PTR)pObject->pObjectArray[i]->pSecurityDescriptor, // The template setting of the attribute
  997. ITEM_PROF_FILESD, // The type of of the attribute's data
  998. pObject->pObjectArray[i]->Status, // The mismatch status of the attribute
  999. cookie, // The cookie for the result item pane
  1000. FALSE, // Copy last inspected from template
  1001. NULL, // The units the attribute is set in
  1002. (LONG_PTR)pObject->pObjectArray[i], // An id to let us know where to save this attribute
  1003. pSceInfo, // The template to save this attribute in
  1004. pDataObj // The data object for the scope note who owns the result pane
  1005. );
  1006. }
  1007. }
  1008. break;
  1009. default:
  1010. break;
  1011. }
  1012. }
  1013. //+--------------------------------------------------------------------------
  1014. //
  1015. // Method: CreateAnalysisResultList
  1016. //
  1017. // Synopsis: Create the result pane items for the analysis section
  1018. //
  1019. // Arguments: [cookie] - The cookie representing the folder which we
  1020. // are enumerating
  1021. // [type] - The type of the folder we are enumerating
  1022. // [pSceInfo] - The last inspection template that we are enumerating
  1023. // [pSceBase] - The computer template that we are enumerating
  1024. // [pDataObj] - The data object for this folder
  1025. //
  1026. // Returns: none
  1027. //
  1028. //---------------------------------------------------------------------------
  1029. void CSnapin::CreateAnalysisResultList(MMC_COOKIE cookie,
  1030. FOLDER_TYPES type,
  1031. PEDITTEMPLATE pSceInfo,
  1032. PEDITTEMPLATE pBase,
  1033. LPDATAOBJECT pDataObj )
  1034. {
  1035. bool bVerify=true;
  1036. CString listStr;
  1037. CString listBase;
  1038. PSCE_PRIVILEGE_ASSIGNMENT pPriv = 0;
  1039. PSCE_PRIVILEGE_ASSIGNMENT pPrivBase = 0;
  1040. UINT i = 0;
  1041. switch (type)
  1042. {
  1043. case POLICY_KERBEROS_ANALYSIS:
  1044. case POLICY_PASSWORD_ANALYSIS:
  1045. case POLICY_LOCKOUT_ANALYSIS:
  1046. case POLICY_AUDIT_ANALYSIS:
  1047. case POLICY_OTHER_ANALYSIS:
  1048. case POLICY_LOG_ANALYSIS:
  1049. CreateAnalysisPolicyResultList(cookie,
  1050. type,
  1051. pSceInfo,
  1052. pBase,
  1053. pDataObj);
  1054. break;
  1055. case AREA_POLICY_ANALYSIS:
  1056. break;
  1057. case AREA_PRIVILEGE_ANALYSIS:
  1058. {
  1059. // find in the current setting list
  1060. TCHAR szDisp[255];
  1061. DWORD cbDisp = 0;
  1062. for (pPriv=pSceInfo->pTemplate->OtherInfo.sap.pPrivilegeAssignedTo;
  1063. pPriv!=NULL;
  1064. pPriv=pPriv->Next)
  1065. {
  1066. // find in the base setting list
  1067. for (pPrivBase=pBase->pTemplate->OtherInfo.smp.pPrivilegeAssignedTo;
  1068. pPrivBase!=NULL;
  1069. pPrivBase=pPrivBase->Next)
  1070. {
  1071. if ( pPrivBase->Value == pPriv->Value )
  1072. break;
  1073. }
  1074. cbDisp = 255;
  1075. GetRightDisplayName(NULL,(LPCTSTR)pPriv->Name,szDisp,&cbDisp);
  1076. if (pPrivBase == NULL)
  1077. {
  1078. pPrivBase = (PSCE_PRIVILEGE_ASSIGNMENT)ULongToPtr(SCE_NO_VALUE);
  1079. }
  1080. AddResultItem(szDisp, // The name of the attribute being added
  1081. (LONG_PTR)pPriv, // The last inspected setting of the attribute
  1082. (LONG_PTR)pPrivBase, // The template setting of the attribute
  1083. ITEM_PRIVS, // The type of of the attribute's data
  1084. pPriv->Status, // The mismatch status of the attribute
  1085. cookie, // The cookie for the result item pane
  1086. FALSE, // True if the setting is set only if it differs from base (so copy the data)
  1087. NULL, // The units the attribute is set in
  1088. 0, // An id to let us know where to save this attribute
  1089. pBase, // The template to save this attribute in
  1090. pDataObj); // The data object for the scope note who owns the result pane
  1091. }
  1092. }
  1093. break;
  1094. case AREA_GROUPS_ANALYSIS:
  1095. {
  1096. PSCE_GROUP_MEMBERSHIP pGroup = 0;
  1097. PSCE_GROUP_MEMBERSHIP grpBase = 0;
  1098. //
  1099. // it is OK to start with pSceInfo because each group at least has
  1100. // PrivilegesHeld field not null.
  1101. //
  1102. bVerify = FALSE;
  1103. for (pGroup=pSceInfo->pTemplate->pGroupMembership; pGroup!=NULL; pGroup=pGroup->Next)
  1104. {
  1105. //
  1106. // find the base to compare with
  1107. //
  1108. if ( NULL == pGroup->GroupName )
  1109. continue;
  1110. for (grpBase=pBase->pTemplate->pGroupMembership; grpBase!=NULL;
  1111. grpBase=grpBase->Next)
  1112. {
  1113. if ( grpBase->GroupName &&
  1114. _wcsicmp(pGroup->GroupName, grpBase->GroupName) == 0 )
  1115. {
  1116. break;
  1117. }
  1118. }
  1119. AddResultItem((LPCTSTR)pGroup->GroupName, // The name of the attribute being added
  1120. GetGroupStatus(pGroup->Status, STATUS_GROUP_MEMBEROF), // The last inspected setting of the attribute
  1121. GetGroupStatus(pGroup->Status, STATUS_GROUP_MEMBERS), // The template setting of the attribute
  1122. ITEM_GROUP, // The type of of the attribute's data
  1123. GetGroupStatus(pGroup->Status, STATUS_GROUP_RECORD), // status // The mismatch status of the attribute
  1124. cookie, // The cookie for the result item pane
  1125. FALSE, // Copy last inspected from template
  1126. (LPTSTR)grpBase, //NULL, // The units the attribute is set in
  1127. (LONG_PTR)pGroup, // An id to let us know where to save this attribute
  1128. pBase, //pSceInfo, // The template to save this attribute in
  1129. pDataObj); // The data object for the scope note who owns the result pane
  1130. }
  1131. }
  1132. break;
  1133. case AREA_SERVICE_ANALYSIS:
  1134. // AddResultItem(L"Not Implemented", NULL, NULL, ITEM_OTHER, -1, cookie);
  1135. CreateAnalysisServiceResultList(cookie,
  1136. type,
  1137. pSceInfo,
  1138. pBase,
  1139. pDataObj);
  1140. break;
  1141. default:
  1142. break;
  1143. }
  1144. }
  1145. //+--------------------------------------------------------------------------
  1146. //
  1147. // Method: CreateObjectResultList
  1148. //
  1149. // Synopsis: Create the result pane items for an Object section
  1150. //
  1151. // Arguments: [cookie] - The cookie representing the folder which we
  1152. // are enumerating
  1153. // [type] - The type of the folder we are enumerating
  1154. // [Area] - The SCE Area we're enumerating
  1155. // [pObjList] - The array of object to enumerate
  1156. // [pHandle] -
  1157. // [pDataObj] - The data object for the folder we're enumerating
  1158. //
  1159. // Returns: none
  1160. //
  1161. //---------------------------------------------------------------------------
  1162. void CSnapin::CreateObjectResultList(MMC_COOKIE cookie,
  1163. FOLDER_TYPES type,
  1164. AREA_INFORMATION Area,
  1165. PSCE_OBJECT_CHILDREN pObjList,
  1166. PVOID pHandle,
  1167. LPDATAOBJECT pDataObj )
  1168. {
  1169. if ( pObjList == NULL )
  1170. {
  1171. //
  1172. // no object to add
  1173. //
  1174. return;
  1175. }
  1176. PWSTR ObjSetting=NULL;
  1177. PWSTR ObjBase=NULL;
  1178. CString tmpstr;
  1179. LPTSTR szPath = NULL;
  1180. RESULT_TYPES rsltType;
  1181. if ( Area == AREA_REGISTRY_SECURITY)
  1182. rsltType = ITEM_REGSD;
  1183. else if ( Area == AREA_FILE_SECURITY )
  1184. rsltType = ITEM_FILESD;
  1185. else
  1186. {
  1187. ASSERT(FALSE);
  1188. return;
  1189. }
  1190. PSCE_OBJECT_CHILDREN_NODE *pObjNode=&(pObjList->arrObject);
  1191. for (DWORD i=0; i<pObjList->nCount; i++)
  1192. {
  1193. BOOL bContainer = FALSE;
  1194. CString strName;
  1195. if ( pObjNode[i] == NULL ||
  1196. pObjNode[i]->Name == NULL )
  1197. {
  1198. continue;
  1199. }
  1200. if (AREA_FILE_SECURITY == Area)
  1201. {
  1202. DWORD dw = (DWORD)-1;
  1203. strName = ((CFolder *)cookie)->GetName();
  1204. if (strName.Right(1) != L"\\")
  1205. {
  1206. strName += L"\\";
  1207. }
  1208. strName += pObjNode[i]->Name;
  1209. dw = GetFileAttributes(strName);
  1210. if ((DWORD)-1 == dw)
  1211. {
  1212. //
  1213. // GetFileAttributes should never fail, but in case it does assume
  1214. // that this isn't a container (this matches CreateFolderList)
  1215. //
  1216. bContainer = FALSE;
  1217. }
  1218. else
  1219. {
  1220. bContainer = dw & FILE_ATTRIBUTE_DIRECTORY;
  1221. }
  1222. }
  1223. else
  1224. {
  1225. bContainer = FALSE;
  1226. }
  1227. if ( !bContainer )
  1228. {
  1229. //
  1230. // only add the leaf objects in result pane.
  1231. // non-leaf objects are added to the scope pane already
  1232. //
  1233. PEDITTEMPLATE pBaseObject=NULL;
  1234. if ( type == REG_OBJECTS ||
  1235. type == FILE_OBJECTS )
  1236. {
  1237. tmpstr = ((CFolder*)cookie)->GetName();
  1238. if (tmpstr.Right(1) != L"\\")
  1239. {
  1240. tmpstr += L"\\";
  1241. }
  1242. tmpstr += pObjNode[i]->Name;
  1243. }
  1244. else
  1245. {
  1246. //
  1247. // shouldn't get here
  1248. //
  1249. tmpstr = TEXT("");
  1250. }
  1251. szPath = (LPTSTR) malloc((tmpstr.GetLength()+1) * sizeof(TCHAR));
  1252. if (szPath)
  1253. {
  1254. lstrcpy(szPath,tmpstr.GetBuffer(2));
  1255. AddResultItem(pObjNode[i]->Name, // The name of the attribute being added
  1256. NULL, // The last inspected setting of the attribute
  1257. NULL, // The template setting of the attribute
  1258. rsltType, // The type of of the attribute's data
  1259. pObjNode[i]->Status,// The mismatch status of the attribute
  1260. cookie, // The cookie for the result item pane
  1261. FALSE, // True if the setting is set only if it differs from base (so copy the data)
  1262. szPath, // The units the attribute is set in
  1263. (LONG_PTR)pHandle, // An id to let us know where to save this attribute
  1264. pBaseObject, // The template to save this attribute in
  1265. pDataObj); // The data object for the scope note who owns the result pane
  1266. }
  1267. else
  1268. {
  1269. // Out of memory
  1270. }
  1271. }
  1272. }
  1273. }
  1274. //+--------------------------------------------------------------------------
  1275. //
  1276. // Method: AddResultItem
  1277. //
  1278. // Synopsis: Add an item to the result pane from a string resource
  1279. //
  1280. // Arguments: [rID] - The resource id of name of the attribute being added
  1281. // [setting] - The last inspected setting of the attribute
  1282. // [base] - The template setting of the attribute
  1283. // [type] - The type of of the attribute's data
  1284. // [status] - The mismatch status of the attribute
  1285. // [cookie] - The cookie for the result item pane
  1286. // [bVerify] - True if the setting is set only if it differs
  1287. // from base (so copy the data)
  1288. // [pBaseInfo] - The template to save this attribute in
  1289. // [pDataObj] - The data object for the scope note who owns the result pane
  1290. //
  1291. // Returns: a pointer to the CResult created to hold the item
  1292. //
  1293. // History:
  1294. //
  1295. //---------------------------------------------------------------------------
  1296. CResult* CSnapin::AddResultItem(UINT rID,
  1297. LONG_PTR setting,
  1298. LONG_PTR base,
  1299. RESULT_TYPES type,
  1300. int status,
  1301. MMC_COOKIE cookie,
  1302. BOOL bVerify,
  1303. PEDITTEMPLATE pBaseInfo,
  1304. LPDATAOBJECT pDataObj)
  1305. {
  1306. CString strRes;
  1307. strRes.LoadString(rID);
  1308. if (!strRes)
  1309. return NULL;
  1310. LPCTSTR Attrib = 0;
  1311. LPCTSTR unit=NULL;
  1312. //
  1313. // The unit for the attribute is stored in the resource after a \n
  1314. //
  1315. int npos = strRes.ReverseFind(L'\n');
  1316. if ( npos > 0 )
  1317. {
  1318. Attrib = strRes.GetBufferSetLength(npos);
  1319. unit = (LPCTSTR)strRes+npos+1;
  1320. }
  1321. else
  1322. {
  1323. Attrib = (LPCTSTR)strRes;
  1324. }
  1325. return AddResultItem(Attrib,setting,base,type,status,cookie,bVerify,unit,rID,pBaseInfo,pDataObj);
  1326. }
  1327. //+--------------------------------------------------------------------------
  1328. //
  1329. // Method: AddResultItem
  1330. //
  1331. // Synopsis: Add an item to the result pane
  1332. //
  1333. // Arguments: [Attrib] - The name of the attribute being added
  1334. // [setting] - The last inspected setting of the attribute
  1335. // [base] - The template setting of the attribute
  1336. // [type] - The type of of the attribute's data
  1337. // [status] - The mismatch status of the attribute
  1338. // [cookie] - The cookie for the result item pane
  1339. // [bVerify] - True if the setting is set only if it differs
  1340. // from base (so copy the data)
  1341. // [unit] - The units the attribute is set in
  1342. // [nID] - An id to let us know where to save this attribute
  1343. // [pBaseInfo] - The template to save this attribute in
  1344. // [pDataObj] - The data object for the scope note who owns the result pane
  1345. //
  1346. // Returns: a pointer to the CResult created to hold the item
  1347. //
  1348. // History:
  1349. //
  1350. //---------------------------------------------------------------------------
  1351. CResult* CSnapin::AddResultItem(LPCTSTR Attrib,
  1352. LONG_PTR setting,
  1353. LONG_PTR base,
  1354. RESULT_TYPES type,
  1355. int status,
  1356. MMC_COOKIE cookie,
  1357. BOOL bVerify,
  1358. LPCTSTR unit,
  1359. LONG_PTR nID,
  1360. PEDITTEMPLATE pBaseInfo,
  1361. LPDATAOBJECT pDataObj,
  1362. CResult *pResult)
  1363. {
  1364. if ( bVerify )
  1365. {
  1366. if ( (LONG_PTR)SCE_NOT_ANALYZED_VALUE == setting )
  1367. {
  1368. //
  1369. // The setting was changed but has not been analyzed.
  1370. //
  1371. status = SCE_STATUS_NOT_ANALYZED;
  1372. }
  1373. else if ( base == (LONG_PTR)ULongToPtr(SCE_NO_VALUE) ||
  1374. (BYTE)base == (BYTE)SCE_NO_VALUE )
  1375. {
  1376. //
  1377. // The setting is no longer configured.
  1378. //
  1379. status = SCE_STATUS_NOT_CONFIGURED;
  1380. }
  1381. else if ( !(m_pSelectedFolder->GetModeBits() & MB_LOCAL_POLICY) &&
  1382. (setting == (LONG_PTR)ULongToPtr(SCE_NO_VALUE) ||
  1383. (BYTE)setting == (BYTE)SCE_NO_VALUE ))
  1384. {
  1385. // add the base for current setting
  1386. setting = base;
  1387. status = SCE_STATUS_GOOD; // a good item
  1388. }
  1389. else if ( setting != base )
  1390. status = SCE_STATUS_MISMATCH;
  1391. else
  1392. status = SCE_STATUS_GOOD;
  1393. }
  1394. CResult* pNewResult = pResult;
  1395. if (!pNewResult)
  1396. {
  1397. pNewResult = new CResult();
  1398. // refCount is already 1 // result->AddRef();
  1399. }
  1400. ASSERT(pNewResult);
  1401. if ( pNewResult )
  1402. {
  1403. pNewResult->Create(Attrib,
  1404. base,
  1405. setting,
  1406. type,
  1407. status,
  1408. cookie,
  1409. unit,
  1410. nID,
  1411. pBaseInfo,
  1412. pDataObj,
  1413. m_pNotifier,
  1414. this);
  1415. if (!pResult)
  1416. {
  1417. m_pSelectedFolder->AddResultItem (
  1418. m_resultItemHandle,
  1419. pNewResult);
  1420. }
  1421. }
  1422. return pNewResult;
  1423. }
  1424. //+--------------------------------------------------------------------------
  1425. //
  1426. // Method: AddResultItem
  1427. //
  1428. // Synopsis: Add a group item to the analysis section result pane.
  1429. // This adds three actual result pane items:
  1430. // 1) The actual name of the group
  1431. // 2) The members of the group
  1432. // 3) The groups this group is a member of
  1433. //
  1434. // Arguments: [szName] - The name of the group being added
  1435. // [grpTemplate] - The last inspected setting of the attribute
  1436. // [grpInspecte] - The template setting of the attribute
  1437. // [cookie] - The cookie IDing the result pane item
  1438. // [pDataObj] - The data object for the scope pane item
  1439. //
  1440. // History:
  1441. //
  1442. //---------------------------------------------------------------------------
  1443. void CSnapin::AddResultItem(LPCTSTR szName,
  1444. PSCE_GROUP_MEMBERSHIP grpTemplate,
  1445. PSCE_GROUP_MEMBERSHIP grpInspect,
  1446. MMC_COOKIE cookie,
  1447. LPDATAOBJECT pDataObj)
  1448. {
  1449. //
  1450. // This area contains MAX_ITEM_ID_INDEX(3) linked result lines:
  1451. // Group Name
  1452. // Members: Template Last Inspected
  1453. // Membership: Template Last Inspected
  1454. //comment out Privileges: Template Last Inspected
  1455. //
  1456. if ( !grpInspect || !szName || !cookie )
  1457. {
  1458. ASSERT(FALSE);
  1459. return;
  1460. }
  1461. //
  1462. // pResults & hResultItems are needed to link the lines together
  1463. //
  1464. typedef CResult *PRESULT;
  1465. PRESULT pResults[3];
  1466. HRESULTITEM hResultItems[3];
  1467. int status = 0;
  1468. //
  1469. // add one entry for the group name
  1470. //
  1471. if ( grpInspect->Status & SCE_GROUP_STATUS_NOT_ANALYZED )
  1472. status = SCE_STATUS_NOT_CONFIGURED;
  1473. else
  1474. status = -1;
  1475. pResults[0]= AddResultItem(szName, // The name of the attribute being added
  1476. (LONG_PTR)grpInspect, // The last inspected setting of the attribute
  1477. (LONG_PTR)grpTemplate, // The template setting of the attribute
  1478. ITEM_GROUP, // The type of of the attribute's data
  1479. status, // The mismatch status of the attribute
  1480. cookie, // The cookie for the result item pane
  1481. FALSE, // True if the setting is set only if it differs from base (so copy the data)
  1482. NULL, // The units the attribute is set in
  1483. NULL, // An id to let us know where to save this attribute
  1484. (CEditTemplate *)szName, // The template to save this attribute in
  1485. pDataObj); // The data object for the scope note who owns the result pane
  1486. //
  1487. // L" -- Members"
  1488. //
  1489. status = grpInspect->Status;
  1490. if ( status & SCE_GROUP_STATUS_NOT_ANALYZED ||
  1491. status & SCE_GROUP_STATUS_NC_MEMBERS )
  1492. {
  1493. status = SCE_STATUS_NOT_CONFIGURED;
  1494. }
  1495. else if ( status & SCE_GROUP_STATUS_MEMBERS_MISMATCH )
  1496. {
  1497. status = SCE_STATUS_MISMATCH;
  1498. }
  1499. else
  1500. status = SCE_STATUS_GOOD;
  1501. pResults[1] = AddResultItem(IDS_GRP_MEMBERS,
  1502. (LONG_PTR)grpInspect,
  1503. (LONG_PTR)grpTemplate,
  1504. ITEM_GROUP_MEMBERS,
  1505. status,
  1506. cookie,
  1507. false,
  1508. (PEDITTEMPLATE)szName,
  1509. pDataObj);
  1510. //
  1511. // L" -- Membership"
  1512. //
  1513. status = grpInspect->Status;
  1514. if ( status & SCE_GROUP_STATUS_NOT_ANALYZED ||
  1515. status & SCE_GROUP_STATUS_NC_MEMBEROF )
  1516. {
  1517. status = SCE_STATUS_NOT_CONFIGURED;
  1518. }
  1519. else if ( status & SCE_GROUP_STATUS_MEMBEROF_MISMATCH )
  1520. {
  1521. status = SCE_STATUS_MISMATCH;
  1522. }
  1523. else
  1524. status = SCE_STATUS_GOOD;
  1525. pResults[2] = AddResultItem(IDS_GRP_MEMBEROF,
  1526. (LONG_PTR)grpInspect,
  1527. (LONG_PTR)grpTemplate,
  1528. ITEM_GROUP_MEMBEROF,
  1529. status,
  1530. cookie,
  1531. false,
  1532. (PEDITTEMPLATE)szName,
  1533. pDataObj);
  1534. //
  1535. // save the relative cookies
  1536. //
  1537. if ( pResults[0] )
  1538. pResults[0]->SetRelativeCookies((MMC_COOKIE)pResults[1], (MMC_COOKIE)pResults[2]);
  1539. if ( pResults[1] )
  1540. pResults[1]->SetRelativeCookies((MMC_COOKIE)pResults[0], (MMC_COOKIE)pResults[2]);
  1541. if ( pResults[2] )
  1542. pResults[2]->SetRelativeCookies((MMC_COOKIE)pResults[0], (MMC_COOKIE)pResults[1]);
  1543. }
  1544. void CSnapin::DeleteList (BOOL bDeleteResultItem)
  1545. {
  1546. POSITION pos = NULL;
  1547. if (m_pSelectedFolder && m_resultItemHandle)
  1548. {
  1549. CResult *pResult = 0;
  1550. do {
  1551. if( m_pSelectedFolder->GetResultItem(
  1552. m_resultItemHandle,
  1553. pos,
  1554. &pResult) != ERROR_SUCCESS)
  1555. {
  1556. break;
  1557. }
  1558. if ( pResult )
  1559. {
  1560. if ( bDeleteResultItem )
  1561. {
  1562. HRESULTITEM hItem = NULL;
  1563. if( S_OK == m_pResult->FindItemByLParam((LPARAM)m_pResult, &hItem ))
  1564. {
  1565. if(hItem)
  1566. {
  1567. m_pResult->DeleteItem(hItem, 0);
  1568. }
  1569. }
  1570. }
  1571. }
  1572. else
  1573. break;
  1574. } while( pos );
  1575. //
  1576. // Release the hold on this object.
  1577. //
  1578. m_pSelectedFolder->ReleaseResultItemHandle( m_resultItemHandle );
  1579. m_resultItemHandle = NULL;
  1580. m_pSelectedFolder = NULL;
  1581. }
  1582. }
  1583. //+--------------------------------------------------------------------------
  1584. //
  1585. // Function: OnUpdateView
  1586. //
  1587. // Synopsis: If the updated view is being shown by this CSnapin then
  1588. // clear out the old view and redisplay it with the new info
  1589. //
  1590. // Arguments: [lpDataObject] - unused
  1591. // [data] - the cookie for the folder being updated
  1592. // [hint] - unused
  1593. //
  1594. //
  1595. //---------------------------------------------------------------------------
  1596. HRESULT
  1597. CSnapin::OnUpdateView(LPDATAOBJECT lpDataObject,LPARAM data, LPARAM hint )
  1598. {
  1599. if (lpDataObject == (LPDATAOBJECT)this)
  1600. return S_OK;
  1601. CResult *pResult = (CResult *)data;
  1602. HRESULTITEM hRItem = NULL;
  1603. RESULTDATAITEM resultItem;
  1604. HRESULT hr = m_pResult->FindItemByLParam( (LPARAM)pResult, &hRItem );
  1605. POSITION pos = NULL;
  1606. switch(hint)
  1607. {
  1608. case UAV_RESULTITEM_UPDATEALL:
  1609. //
  1610. // The caller is responsible for clearing the result items from this
  1611. // this will invalidate all references to the folder object. Because of
  1612. // this we have to make sure the reference counter is updated correctly,
  1613. // so for every CSnapin object GetResultITemHandle is called so that we
  1614. // don't delete the list when it is still needed.
  1615. //
  1616. if(data != (LPARAM)m_pSelectedFolder && (CFolder*)data != NULL)
  1617. {
  1618. //Raid #258237, 4/12/2001
  1619. CFolder* pCurFolder = (CFolder*)data;
  1620. if( !pCurFolder->GetViewUpdate() )
  1621. return S_OK;
  1622. CFolder* pOldFolder = m_pSelectedFolder;
  1623. pCurFolder->SetViewUpdate(FALSE);
  1624. if( !pCurFolder->GetResultListCount() )
  1625. {
  1626. EnumerateResultPane(
  1627. (MMC_COOKIE)pCurFolder,
  1628. pCurFolder->GetScopeItem()->ID,
  1629. NULL
  1630. );
  1631. m_pSelectedFolder = pOldFolder;
  1632. }
  1633. }
  1634. if( m_pSelectedFolder->GetViewUpdate() )
  1635. m_pSelectedFolder->SetViewUpdate(FALSE);
  1636. m_pResult->DeleteAllRsltItems();
  1637. if( !m_pSelectedFolder->GetResultListCount() )
  1638. {
  1639. //
  1640. // This should only be called by the first CSnapin who recieves this message.
  1641. //
  1642. EnumerateResultPane(
  1643. (MMC_COOKIE)m_pSelectedFolder,
  1644. m_pSelectedFolder->GetScopeItem()->ID,
  1645. NULL
  1646. );
  1647. break;
  1648. }
  1649. else
  1650. {
  1651. m_pSelectedFolder->GetResultItemHandle(
  1652. &m_resultItemHandle);
  1653. }
  1654. break;
  1655. case UAV_RESULTITEM_REDRAWALL:
  1656. if( data != (LPARAM)m_pSelectedFolder )
  1657. {
  1658. return S_OK;
  1659. }
  1660. m_pResult->DeleteAllRsltItems();
  1661. ZeroMemory(&resultItem,sizeof(resultItem));
  1662. resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  1663. resultItem.str = MMC_CALLBACK;
  1664. resultItem.nImage = -1; // equivalent to: MMC_CALLBACK;
  1665. pos = NULL;
  1666. m_pResult->SetItemCount(
  1667. m_pSelectedFolder->GetResultListCount( ),
  1668. MMCLV_UPDATE_NOINVALIDATEALL);
  1669. do {
  1670. m_pSelectedFolder->GetResultItem(
  1671. m_resultItemHandle,
  1672. pos,
  1673. (CResult **)&(resultItem.lParam));
  1674. if(resultItem.lParam)
  1675. {
  1676. m_pResult->InsertItem( &resultItem );
  1677. }
  1678. } while(pos);
  1679. m_pResult->Sort(0, 0, 0);
  1680. break;
  1681. case UAV_RESULTITEM_ADD:
  1682. //
  1683. // This adds a CResult item to the result pane, if and only if the item
  1684. // does not already exist withen the pane.
  1685. //
  1686. if(!m_pSelectedFolder ||
  1687. !m_pSelectedFolder->GetResultItemPosition(
  1688. m_resultItemHandle,
  1689. pResult) ||
  1690. hRItem )
  1691. {
  1692. return S_OK;
  1693. }
  1694. ZeroMemory(&resultItem,sizeof(resultItem));
  1695. resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  1696. resultItem.str = MMC_CALLBACK;
  1697. resultItem.nImage = -1; // equivalent to: MMC_CALLBACK;
  1698. resultItem.lParam = (LPARAM)pResult;
  1699. m_pResult->InsertItem( &resultItem );
  1700. m_pResult->Sort(0, 0, 0);
  1701. break;
  1702. case UAV_RESULTITEM_REMOVE:
  1703. //
  1704. // This removes the HRESULTITEM associated with the CResult item passed in
  1705. // through the data member.
  1706. //
  1707. if(hRItem)
  1708. m_pResult->DeleteItem( hRItem, 0 );
  1709. break;
  1710. default:
  1711. //
  1712. // By default we just repaint the item.
  1713. //
  1714. m_pResult->UpdateItem( hRItem );
  1715. break;
  1716. }
  1717. return hr;
  1718. }