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.

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