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.

1779 lines
56 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2001.
  5. //
  6. // File: scopane.cpp
  7. //
  8. // Contents: Functions for handling the scope pane folder structure
  9. //
  10. // History: 12-12-1997 RobCap Split out from snapmgr.cpp
  11. //
  12. //---------------------------------------------------------------------------
  13. #include "stdafx.h"
  14. #include "cookie.h"
  15. #include "snapmgr.h"
  16. #include "resource.h"
  17. #include "wrapper.h"
  18. #include "util.h"
  19. #include <sceattch.h>
  20. #include <io.h>
  21. #ifdef INITGUID
  22. #undef INITGUID
  23. #include <gpedit.h>
  24. #define INITGUID
  25. #include "userenv.h"
  26. #endif
  27. //
  28. // Array of folders to list in the scope pane
  29. // The order of this array is important:
  30. // All folders which appear at the same level must be adjacent
  31. // to each other and the array and #defines need to be kept in
  32. // sync
  33. //
  34. //
  35. #define USE_KERBEROS 1
  36. //
  37. // Top level folders
  38. //
  39. #define ANALYSIS_FOLDER 0
  40. #define CONFIGURATION_FOLDER (ANALYSIS_FOLDER +1)
  41. //
  42. // Profile level folders
  43. //
  44. #define PROFILE_ACCOUNT_FOLDER (CONFIGURATION_FOLDER +1)
  45. #define PROFILE_LOCAL_FOLDER (PROFILE_ACCOUNT_FOLDER +1)
  46. #define PROFILE_EVENTLOG_FOLDER (PROFILE_LOCAL_FOLDER +1)
  47. #define PROFILE_GROUPS_FOLDER (PROFILE_EVENTLOG_FOLDER +1)
  48. #define PROFILE_SERVICE_FOLDER (PROFILE_GROUPS_FOLDER +1)
  49. #define PROFILE_REGISTRY_FOLDER (PROFILE_SERVICE_FOLDER +1)
  50. #define PROFILE_FILESTORE_FOLDER (PROFILE_REGISTRY_FOLDER +1)
  51. //
  52. // Profile/Account level folders
  53. //
  54. #define ACCOUNT_PASSWORD_FOLDER (PROFILE_FILESTORE_FOLDER +1)
  55. #define ACCOUNT_LOCKOUT_FOLDER (ACCOUNT_PASSWORD_FOLDER +1)
  56. #define ACCOUNT_KERBEROS_FOLDER (ACCOUNT_LOCKOUT_FOLDER +1)
  57. //
  58. // Profile/Local level folders
  59. //
  60. #define LOCAL_AUDIT_FOLDER (ACCOUNT_KERBEROS_FOLDER +1)
  61. #define LOCAL_PRIVILEGE_FOLDER (LOCAL_AUDIT_FOLDER +1)
  62. #define LOCAL_OTHER_FOLDER (LOCAL_PRIVILEGE_FOLDER +1)
  63. //
  64. // Profile/Eventlog level folders
  65. //
  66. #define EVENTLOG_LOG_FOLDER (LOCAL_OTHER_FOLDER +1)
  67. #define NUM_FOLDERS (LOCAL_OTHER_FOLDER +1)
  68. //#define NUM_FOLDERS (EVENTLOG_LOG_FOLDER +1)
  69. //
  70. // #defines to identify which folders belong in which sections
  71. //
  72. #define FIRST_STATIC_FOLDER ANALYSIS_FOLDER
  73. #define LAST_STATIC_FOLDER CONFIGURATION_FOLDER
  74. #define FIRST_PROFILE_FOLDER PROFILE_ACCOUNT_FOLDER
  75. #define LAST_PROFILE_FOLDER PROFILE_DSOBJECT_FOLDER
  76. #define LAST_PROFILE_NODS_FOLDER PROFILE_FILESTORE_FOLDER
  77. #define LAST_LOCALPOL_FOLDER PROFILE_LOCAL_FOLDER
  78. #define FIRST_ACCOUNT_FOLDER ACCOUNT_PASSWORD_FOLDER
  79. #define LAST_ACCOUNT_NODS_FOLDER ACCOUNT_LOCKOUT_FOLDER
  80. //
  81. // remove kerberos section from NT5 for now
  82. //
  83. #if defined(_NT4BACK_PORT) || !defined(USE_KERBEROS)
  84. #define LAST_ACCOUNT_FOLDER ACCOUNT_LOCKOUT_FOLDER
  85. #else
  86. #define LAST_ACCOUNT_FOLDER ACCOUNT_KERBEROS_FOLDER
  87. #endif
  88. #define FIRST_LOCAL_FOLDER LOCAL_AUDIT_FOLDER
  89. #define LAST_LOCAL_FOLDER LOCAL_OTHER_FOLDER
  90. #define FIRST_EVENTLOG_FOLDER EVENTLOG_LOG_FOLDER
  91. #define LAST_EVENTLOG_FOLDER EVENTLOG_LOG_FOLDER
  92. //
  93. // The actual folder data
  94. // This must be kept in sync with the above #defines
  95. // should be initialized based on the #defines rather than
  96. // independantly on them. Let the compiler keep things
  97. // accurate for us
  98. //
  99. FOLDER_DATA SecmgrFolders[NUM_FOLDERS] =
  100. {
  101. { IDS_ANALYZE, IDS_ANALYZE_DESC, ANALYSIS},
  102. { IDS_CONFIGURE, IDS_CONFIGURE_DESC, CONFIGURATION},
  103. { IDS_ACCOUNT_POLICY, IDS_ACCOUNT_DESC, POLICY_ACCOUNT},
  104. { IDS_LOCAL_POLICY, IDS_LOCAL_DESC, POLICY_LOCAL},
  105. { IDS_EVENT_LOG, IDS_EVENT_LOG, POLICY_LOG},
  106. { IDS_GROUPS, IDS_GROUPS_DESC, AREA_GROUPS},
  107. { IDS_SERVICE, IDS_SERVICE_DESC, AREA_SERVICE},
  108. { IDS_REGISTRY, IDS_REGISTRY_DESC, AREA_REGISTRY},
  109. { IDS_FILESTORE, IDS_FILESTORE_DESC, AREA_FILESTORE},
  110. { IDS_PASSWORD_CATEGORY, IDS_PASSWORD_CATEGORY, POLICY_PASSWORD},
  111. { IDS_LOCKOUT_CATEGORY, IDS_LOCKOUT_CATEGORY, POLICY_LOCKOUT},
  112. { IDS_KERBEROS_CATEGORY, IDS_KERBEROS_CATEGORY, POLICY_KERBEROS},
  113. { IDS_EVENT_AUDIT, IDS_EVENT_AUDIT, POLICY_AUDIT},
  114. { IDS_PRIVILEGE, IDS_PRIVILEGE, AREA_PRIVILEGE},
  115. { IDS_OTHER_CATEGORY, IDS_OTHER_CATEGORY, POLICY_OTHER},
  116. };
  117. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  118. //+--------------------------------------------------------------------------
  119. //
  120. // Function: AddLocationsToFolderList
  121. //
  122. // Synopsis: Adds the locations from a given registry key to the
  123. // folder list. Returns the number of locations added.
  124. // Helper function for CreateFolderList
  125. //
  126. // Arguments: [hKey] - the key holding the locations
  127. // [dwMode] - the mode SCAT is running in
  128. // [bCheckForDupes] - TRUE to check for duplicates before adding
  129. // [pPos] - output only
  130. //
  131. // Returns: *[pPos] - the position in m_pScopeItemList of the first
  132. // folder created
  133. // the number of child folders created
  134. //
  135. // Modifies: CComponentDataImpl::m_pScopeItemList
  136. //
  137. // History: 7-26-l999 RobCap broken out from CreateFolderList
  138. //
  139. //---------------------------------------------------------------------------
  140. INT
  141. CComponentDataImpl::AddLocationsToFolderList(HKEY hKey,
  142. DWORD dwMode,
  143. BOOL bCheckForDupes,
  144. POSITION *pPos) {
  145. LPTSTR tmpstr=NULL;
  146. WCHAR pBuf[MAX_PATH+1];
  147. DWORD BufSize = MAX_PATH;
  148. WCHAR pExpanded[MAX_PATH+1];
  149. FILETIME LastWriteTime;
  150. PWSTR Desc=NULL;
  151. CFolder *folder =NULL;
  152. INT nCount = 0;
  153. DWORD status = 0;
  154. HRESULT hr = S_OK;
  155. //
  156. // enumerate all subkeys of the key
  157. //
  158. int iTotal = 0;
  159. do {
  160. memset(pBuf, '\0', (MAX_PATH+1)*sizeof(WCHAR)); //Raid #553113, Yanggao.
  161. BufSize = MAX_PATH;
  162. status = RegEnumKeyEx(hKey,
  163. nCount,
  164. pBuf,
  165. &BufSize,
  166. NULL,
  167. NULL,
  168. NULL,
  169. &LastWriteTime);
  170. if ( ERROR_SUCCESS == status ) { //Raid #553113, yanggao.
  171. //
  172. // get description of this location (subkey)
  173. //
  174. MyRegQueryValue( hKey,
  175. pBuf,
  176. L"Description", // Value name (not localized)
  177. (PVOID*)&Desc,
  178. &BufSize );
  179. //
  180. // replace '/' with '\' because Registry does not
  181. // take '\' in a single key
  182. //
  183. tmpstr = wcschr(pBuf, L'/');
  184. while (tmpstr) {
  185. *tmpstr = L'\\';
  186. tmpstr = wcschr(tmpstr, L'/');
  187. }
  188. //This is not a safe usage. Make sure pBuf and pExpanded is terminated. Raid #553113, Yanggao.
  189. memset(pExpanded, '\0', (MAX_PATH+1)*sizeof(WCHAR));
  190. if (!ExpandEnvironmentStrings(pBuf,pExpanded,MAX_PATH)) {
  191. wcsncpy(pExpanded,pBuf,BufSize);
  192. }
  193. if (bCheckForDupes) {
  194. //
  195. // Make sure we haven't already added this directory
  196. //
  197. POSITION pos;
  198. BOOL bDuplicate = FALSE;
  199. pos = m_scopeItemList.GetHeadPosition();
  200. for (int i=0;i < m_scopeItemList.GetCount(); i++) {
  201. folder = m_scopeItemList.GetAt(pos);
  202. if (folder && (0 == lstrcmp(folder->GetName(),pExpanded))) {
  203. bDuplicate = TRUE;
  204. break;
  205. }
  206. }
  207. if (bDuplicate) {
  208. if ( Desc )
  209. LocalFree(Desc);
  210. Desc = NULL;
  211. continue;
  212. }
  213. }
  214. folder = new CFolder();
  215. if (folder) {
  216. if( _wchdir( pExpanded ) ){
  217. folder->SetState( CFolder::state_InvalidTemplate );
  218. }
  219. //
  220. // Create the folder objects with static data
  221. //
  222. hr = folder->Create(pExpanded, // Name
  223. Desc, // Description
  224. NULL, // inf file name
  225. CONFIG_FOLDER_IDX, // closed icon index
  226. CONFIG_FOLDER_IDX, // open icon index
  227. LOCATIONS, // folder type
  228. TRUE, // has children
  229. dwMode, // SCE mode
  230. NULL); // Extra Data
  231. if (SUCCEEDED(hr)) {
  232. m_scopeItemList.AddTail(folder);
  233. if ( iTotal == 0 && NULL != pPos && !bCheckForDupes) {
  234. *pPos = m_scopeItemList.GetTailPosition();
  235. }
  236. } else { // if can't create, then quit doing it anymore, no more reason to continue
  237. delete folder;
  238. if ( Desc )
  239. LocalFree(Desc);
  240. Desc = NULL;
  241. break;
  242. }
  243. } else {
  244. hr = E_OUTOFMEMORY;
  245. if ( Desc )
  246. LocalFree(Desc);
  247. Desc = NULL;
  248. break;
  249. }
  250. if ( Desc ) {
  251. LocalFree(Desc);
  252. }
  253. Desc = NULL;
  254. nCount++;
  255. iTotal++;
  256. }
  257. } while ( status != ERROR_NO_MORE_ITEMS );
  258. return nCount;
  259. }
  260. //+--------------------------------------------------------------------------
  261. //
  262. // Function: CreateFolderList
  263. //
  264. // Synopsis: Adds the children folders of pFolder to m_pScopeItemList
  265. // and returns the location of the first such folder and the
  266. // number added
  267. //
  268. // Arguments: [pFolder] - the folder whose children we want to find
  269. // [type] - the type of that folder
  270. // [pPos] - output only
  271. // [Count] - output only
  272. //
  273. // Returns: *[pPos] - the position in m_pScopeItemList of the first
  274. // folder created
  275. // *[Count] - the number of child folders created
  276. //
  277. // Modifies: CComponentDataImpl::m_pScopeItemList
  278. //
  279. // History: 12-15-1997 RobCap made dynamic based on mode
  280. //
  281. //---------------------------------------------------------------------------
  282. HRESULT
  283. CComponentDataImpl::CreateFolderList(CFolder *pFolder, // Optional, In
  284. FOLDER_TYPES type, // In
  285. POSITION *pPos, // Optional, Out
  286. INT *Count) // Optional, Out,
  287. {
  288. CFolder* folder = 0;
  289. INT nStart = 0;
  290. INT nCount = 0;
  291. BOOL bHasChildren = FALSE;
  292. struct _wfinddata_t findData;
  293. intptr_t hFile = 0;
  294. WCHAR pBuf[MAX_PATH];
  295. HKEY hKey = 0;
  296. DWORD BufSize = 0;
  297. DWORD status = 0;
  298. PWSTR Desc=NULL;
  299. LPTSTR tmpstr=NULL;
  300. HRESULT hr = S_OK;
  301. DWORD dwErr = 0;
  302. SCESTATUS rc = 0;
  303. PSCE_OBJECT_CHILDREN ObjectList=NULL;
  304. PSCE_OBJECT_LIST pObject = 0;
  305. PSCE_ERROR_LOG_INFO ErrBuf=NULL;
  306. CString StrErr;
  307. PSCE_PROFILE_INFO pProfileInfo=NULL;
  308. FOLDER_TYPES newType;
  309. PEDITTEMPLATE pet = 0;
  310. //
  311. // initialize dwMode and ModeBits
  312. //
  313. DWORD dwMode=0;
  314. DWORD ModeBits=0;
  315. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  316. if (Count)
  317. *Count = 0;
  318. if (pFolder)
  319. {
  320. dwMode = pFolder->GetMode();
  321. ModeBits = pFolder->GetModeBits();
  322. }
  323. //
  324. // This could take some time, so create a wait curser
  325. //
  326. CWaitCursor wc;
  327. switch ( type )
  328. {
  329. case ROOT:
  330. //
  331. // Initial standalone mode root mode
  332. //
  333. folder = new CFolder();
  334. if (!folder)
  335. return E_OUTOFMEMORY;
  336. if ( GetImplType() == SCE_IMPL_TYPE_SAV )
  337. {
  338. dwMode = SCE_MODE_VIEWER;
  339. newType = ANALYSIS;
  340. }
  341. else if ( GetImplType() == SCE_IMPL_TYPE_SCE )
  342. {
  343. dwMode = SCE_MODE_EDITOR;
  344. newType = CONFIGURATION;
  345. }
  346. else if ( GetImplType() == SCE_IMPL_TYPE_LS)
  347. {
  348. dwMode = SCE_MODE_LOCALSEC;
  349. newType = LOCALPOL;
  350. }
  351. else
  352. {
  353. dwMode = 0;
  354. newType = CONFIGURATION;
  355. }
  356. //
  357. // Create the folder objects with static data
  358. // MMC pulls in the name from the data object
  359. //
  360. hr = folder->Create(L"", // Name
  361. L"", // Description
  362. NULL, // inf file name
  363. SCE_IMAGE_IDX, // closed icon index
  364. SCE_IMAGE_IDX, // open icon index
  365. newType, // folder type
  366. TRUE, // has children
  367. dwMode, // SCE Mode
  368. NULL); // Extra Data
  369. if (SUCCEEDED(hr))
  370. {
  371. folder->SetCookie(NULL);
  372. switch (m_Mode)
  373. {
  374. case SCE_MODE_DOMAIN_COMPUTER:
  375. case SCE_MODE_OU_COMPUTER:
  376. case SCE_MODE_LOCAL_COMPUTER:
  377. case SCE_MODE_REMOTE_COMPUTER:
  378. m_computerModeBits = folder->GetModeBits();
  379. break;
  380. case SCE_MODE_REMOTE_USER:
  381. case SCE_MODE_LOCAL_USER:
  382. case SCE_MODE_DOMAIN_USER:
  383. case SCE_MODE_OU_USER:
  384. m_userModeBits = folder->GetModeBits();
  385. break;
  386. default:
  387. m_computerModeBits = folder->GetModeBits();
  388. break;
  389. }
  390. m_scopeItemList.AddTail(folder);
  391. return S_OK;
  392. }
  393. else
  394. {
  395. delete folder;
  396. return hr;
  397. }
  398. case ANALYSIS:
  399. pFolder->SetInfFile(GT_COMPUTER_TEMPLATE);
  400. m_AnalFolder = pFolder;
  401. //
  402. // Very first time initialization of the sad name.
  403. // Ask the user to get a sad name if none exists.
  404. //
  405. if(!m_AnalFolder && SadName.IsEmpty() )
  406. OnOpenDataBase();
  407. //
  408. // enumerate security areas for analysis
  409. //
  410. if ( !SadHandle )
  411. LoadSadInfo(TRUE);
  412. //
  413. // The data under the Analysis node is not valid right now,
  414. // so don't display any folders
  415. //
  416. if (m_bIsLocked)
  417. return S_OK;
  418. //
  419. // We weren't able to load the Analysis data even though we're
  420. // not in the middle of an action that should be blocking it
  421. //
  422. if ( SadErrored != ERROR_SUCCESS || !SadHandle)
  423. return E_FAIL;
  424. nStart = FIRST_PROFILE_FOLDER;
  425. //
  426. // Display all but the DS Objects folder
  427. //
  428. nCount = LAST_PROFILE_NODS_FOLDER - FIRST_PROFILE_FOLDER +1;
  429. bHasChildren = FALSE;
  430. break;
  431. case AREA_REGISTRY_ANALYSIS:
  432. case AREA_FILESTORE_ANALYSIS:
  433. if ( SadHandle == NULL )
  434. {
  435. //
  436. // We shouldn't be able to get this far without a SadHandle
  437. //
  438. ASSERT(FALSE);
  439. return E_FAIL;
  440. }
  441. if (m_bIsLocked)
  442. {
  443. //
  444. // We shouldn't be able to get this far if we're locked
  445. //
  446. ASSERT(FALSE);
  447. return E_FAIL;
  448. }
  449. switch ( type )
  450. {
  451. case AREA_REGISTRY_ANALYSIS:
  452. status = AREA_REGISTRY_SECURITY; // use status temporatorily
  453. newType = REG_OBJECTS;
  454. break;
  455. case AREA_FILESTORE_ANALYSIS:
  456. status = AREA_FILE_SECURITY;
  457. newType = FILE_OBJECTS;
  458. break;
  459. default:
  460. break;
  461. }
  462. //
  463. // get the object roots
  464. //
  465. pet = GetTemplate(GT_LAST_INSPECTION,status,&dwErr);
  466. if (!pet)
  467. {
  468. CString strErr;
  469. strErr.LoadString(dwErr);
  470. AfxMessageBox(strErr);
  471. return E_FAIL;
  472. }
  473. pProfileInfo = pet->pTemplate;
  474. if ( pProfileInfo )
  475. {
  476. //
  477. // add the object roots
  478. //
  479. if ( type == AREA_REGISTRY_ANALYSIS)
  480. pObject = pProfileInfo->pRegistryKeys.pOneLevel;
  481. else if ( type == AREA_FILESTORE_ANALYSIS )
  482. pObject = pProfileInfo->pFiles.pOneLevel;
  483. else
  484. pObject = pProfileInfo->pDsObjects.pOneLevel;
  485. for (; pObject!=NULL; pObject=pObject->Next)
  486. {
  487. CString strRoot;
  488. strRoot = (LPCTSTR)pObject->Name;
  489. if (AREA_FILESTORE_ANALYSIS == type)
  490. {
  491. //
  492. // We want c:\, not c: here.
  493. //
  494. strRoot += L"\\";
  495. }
  496. //
  497. // These are the roots of the objects.
  498. // They are always containers
  499. //
  500. if (SCE_STATUS_NO_ACL_SUPPORT == pObject->Status)
  501. {
  502. folder = CreateAndAddOneNode(pFolder,
  503. // pObject->Name,
  504. strRoot,
  505. pBuf,
  506. newType,
  507. FALSE,
  508. GT_COMPUTER_TEMPLATE,
  509. pObject,
  510. pObject->Status);
  511. }
  512. else
  513. {
  514. folder = CreateAndAddOneNode(
  515. pFolder, // Parent folder
  516. // pObject->Name, // Name
  517. strRoot,
  518. pBuf, // Description
  519. newType, // Folder Type
  520. TRUE, // Has Children?
  521. GT_COMPUTER_TEMPLATE, // INF File
  522. pObject, // Extra Data: the object
  523. pObject->Status); // Status
  524. }
  525. if(folder)
  526. folder->SetDesc( pObject->Status, pObject->Count );
  527. }
  528. }
  529. return S_OK;
  530. case REG_OBJECTS:
  531. case FILE_OBJECTS:
  532. if ( SadHandle == NULL )
  533. {
  534. //
  535. // We shouldn't be able to get this far without a SadHandle
  536. //
  537. ASSERT(FALSE);
  538. return E_FAIL;
  539. }
  540. if ( type == REG_OBJECTS)
  541. status = AREA_REGISTRY_SECURITY;
  542. else if ( type == FILE_OBJECTS )
  543. status = AREA_FILE_SECURITY;
  544. else
  545. {
  546. ASSERT(FALSE);
  547. return E_FAIL;
  548. }
  549. //
  550. // get the next level objects
  551. //
  552. rc = SceGetObjectChildren(SadHandle, // hProfile
  553. SCE_ENGINE_SAP, // Profile type
  554. (AREA_INFORMATION)status, // Area
  555. (LPTSTR)(pFolder->GetName()),// Object prefix
  556. &ObjectList, // Object list [out]
  557. &ErrBuf); // Error list [out]
  558. if ( ErrBuf )
  559. { // rc != SCESTATUS_SUCCESS ) {
  560. MyFormatResMessage(rc, IDS_ERROR_GETTING_LAST_ANALYSIS, ErrBuf, StrErr);
  561. SceFreeMemory((PVOID)ErrBuf, SCE_STRUCT_ERROR_LOG_INFO);
  562. ErrBuf = NULL;
  563. }
  564. if ( rc == SCESTATUS_SUCCESS &&
  565. ObjectList )
  566. {
  567. BOOL bContainer = FALSE;
  568. //
  569. // add the objects
  570. //
  571. PSCE_OBJECT_CHILDREN_NODE *pObjNode = &(ObjectList->arrObject);
  572. for (DWORD i=0; i<ObjectList->nCount;i++)
  573. {
  574. //
  575. // These are the next level objects
  576. //
  577. if ( pObjNode[i] == NULL ||
  578. pObjNode[i]->Name == NULL )
  579. {
  580. continue;
  581. }
  582. if (SCE_STATUS_NO_ACL_SUPPORT == pObjNode[i]->Status)
  583. {
  584. // No ACL support, so don't add sub objects
  585. continue;
  586. }
  587. //
  588. // If there are any mismatched child objects then we know
  589. // that this is a container, otherwise we have to check the
  590. // object on the system to find out if it is a container
  591. //
  592. if ( pObjNode[i]->Count > 0 )
  593. bContainer = TRUE;
  594. else
  595. {
  596. if (FILE_OBJECTS == type)
  597. {
  598. //
  599. // Check if a file object is a container
  600. //
  601. CString strPath;
  602. DWORD dwAttr = 0;
  603. strPath = pFolder->GetName();
  604. if (strPath.Right(1) != L"\\")
  605. {
  606. strPath += L"\\";
  607. }
  608. strPath += pObjNode[i]->Name;
  609. dwAttr = GetFileAttributes(strPath);
  610. if (0xFFFFFFFF == dwAttr)
  611. bContainer = FALSE;
  612. else
  613. bContainer = dwAttr & FILE_ATTRIBUTE_DIRECTORY;
  614. }
  615. else
  616. {
  617. //
  618. // Always treat Registry Keys and DS Objects as containers
  619. //
  620. bContainer = TRUE;
  621. }
  622. }
  623. if (bContainer)
  624. {
  625. StrErr = pFolder->GetName();
  626. if (StrErr.Right(1) != L"\\")
  627. StrErr += L"\\";
  628. StrErr += pObjNode[i]->Name;
  629. folder = CreateAndAddOneNode(
  630. pFolder, // Parent folder
  631. (LPTSTR)((LPCTSTR)StrErr), // Name
  632. pBuf, // Description
  633. type, // Folder Type
  634. TRUE, // Has Children?
  635. GT_COMPUTER_TEMPLATE, // INF File
  636. NULL,
  637. pObjNode[i]->Status); // Object Status
  638. if(folder)
  639. {
  640. folder->SetDesc( pObjNode[i]->Status,
  641. pObjNode[i]->Count );
  642. }
  643. }
  644. }
  645. }
  646. if ( ObjectList )
  647. SceFreeMemory((PVOID)ObjectList, SCE_STRUCT_OBJECT_CHILDREN );
  648. return S_OK;
  649. case CONFIGURATION:
  650. {
  651. //
  652. // enumerate profile locations in registry
  653. //
  654. CString strLocations;
  655. m_ConfigFolder = pFolder;
  656. nCount = 0;
  657. if (strLocations.LoadString(IDS_TEMPLATE_LOCATION_KEY))
  658. {
  659. //
  660. // Bug 375324 - Merge HKCU locations with HKLM locations
  661. //
  662. status = RegOpenKeyEx( HKEY_CURRENT_USER,
  663. strLocations,
  664. 0, KEY_READ, &hKey);
  665. if ( NO_ERROR == status )
  666. {
  667. nCount += AddLocationsToFolderList(hKey,dwMode,FALSE,pPos);
  668. RegCloseKey(hKey);
  669. }
  670. if ( 0 == nCount )
  671. {
  672. //
  673. // Empty location list, so add a default
  674. //
  675. CString strDefLoc;
  676. CString strDefLocEx;
  677. strDefLoc.LoadString(IDS_DEFAULT_LOCATION);
  678. int iLen = strDefLoc.GetLength()+MAX_PATH;
  679. LPWSTR pBuffer = strDefLocEx.GetBuffer(iLen+1); //This is not a safe usage. Make sure pBuffer is terminated. Raid #553113, Yanggao.
  680. if (ExpandEnvironmentStrings(strDefLoc, pBuffer, iLen))
  681. {
  682. //
  683. // must use pBuffer here since strDefLocEx has not been released
  684. //
  685. AddTemplateLocation(pFolder,pBuffer,FALSE,TRUE);
  686. }
  687. else
  688. AddTemplateLocation(pFolder,strDefLoc,FALSE,TRUE);
  689. strDefLocEx.ReleaseBuffer();
  690. }
  691. }
  692. if ( Count != NULL )
  693. *Count = nCount;
  694. return hr;
  695. }
  696. case LOCATIONS:
  697. {
  698. //
  699. // enumerate available profiles under the location (*.inf files)
  700. //
  701. //
  702. // pFolder is required in this case
  703. //
  704. if (!pFolder)
  705. return E_INVALIDARG;
  706. //This is not a sage usage. avoid using swprintf. Raid #555867. Yanggao.
  707. CString strBuf;
  708. strBuf.Format(L"%s\\*.inf", (LPTSTR)(pFolder->GetName()));
  709. bHasChildren = FALSE;
  710. hFile = _wfindfirst(strBuf.GetBuffer(0), &findData);
  711. strBuf.ReleaseBuffer();
  712. if ( hFile != -1)
  713. {
  714. do {
  715. //
  716. // Don't add this item to the node if it is a subdirectory.
  717. //
  718. CString strDisplay;
  719. strDisplay.Format(
  720. TEXT("%s\\%s"),
  721. (LPCTSTR)(pFolder->GetName()),
  722. findData.name);
  723. if( findData.attrib & _A_SUBDIR )
  724. continue;
  725. //
  726. // get template's description
  727. //
  728. strDisplay = findData.name;
  729. //
  730. // GetLength has to be at least 4, since we searched on *.inf
  731. //
  732. strDisplay = strDisplay.Left(strDisplay.GetLength() - 4);
  733. //This is not a safe usage. avoid using swprintf. Raid #555867. Yanggao.
  734. strBuf.Format(
  735. L"%s\\%s",
  736. (LPTSTR)(pFolder->GetName()),
  737. findData.name);
  738. if (! GetProfileDescription(strBuf, &Desc) )
  739. Desc = NULL;
  740. else
  741. {
  742. //
  743. // No problem; we just won't display a description
  744. //
  745. }
  746. nCount++;
  747. folder = new CFolder();
  748. if (folder)
  749. {
  750. //
  751. // Create the folder objects
  752. // save full file name her
  753. //
  754. hr = folder->Create((LPCTSTR)strDisplay, // Name
  755. Desc, // Description
  756. strBuf, // inf file name
  757. TEMPLATES_IDX, // closed icon index
  758. TEMPLATES_IDX, // open icon index
  759. PROFILE, // folder type
  760. bHasChildren, // has children
  761. dwMode, // SCE Mode
  762. NULL); // Extra Data
  763. if (SUCCEEDED(hr))
  764. {
  765. m_scopeItemList.AddTail(folder);
  766. if ( nCount == 1 && NULL != pPos )
  767. {
  768. *pPos = m_scopeItemList.GetTailPosition();
  769. }
  770. }
  771. else
  772. {
  773. delete folder;
  774. folder = NULL;
  775. }
  776. }
  777. else
  778. hr = E_OUTOFMEMORY;
  779. if (Desc)
  780. {
  781. LocalFree(Desc);
  782. Desc = NULL;
  783. }
  784. } while ( _wfindnext(hFile, &findData) == 0 );
  785. }
  786. _findclose(hFile);
  787. if ( Count != NULL )
  788. *Count = nCount;
  789. return hr;
  790. }
  791. case PROFILE:
  792. {
  793. TCHAR pszGPTPath[MAX_PATH*5];
  794. SCESTATUS scestatus = 0;
  795. //
  796. // enumerate security areas for this profile
  797. //
  798. if (ModeBits & MB_NO_NATIVE_NODES)
  799. {
  800. //
  801. //
  802. //
  803. nStart = nCount = 0;
  804. break;
  805. }
  806. //
  807. // Find the path to the SCE template within the GPT template
  808. //
  809. if (ModeBits & MB_GROUP_POLICY)
  810. {
  811. //
  812. // get GPT root path
  813. //
  814. hr = m_pGPTInfo->GetFileSysPath(GPO_SECTION_MACHINE,
  815. pszGPTPath,
  816. ARRAYSIZE(pszGPTPath));
  817. if (SUCCEEDED(hr))
  818. {
  819. if (NULL == m_szSingleTemplateName)
  820. {
  821. //
  822. // Allocate memory for the pszGPTPath + <backslash> + GPTSCE_TEMPLATE + <trailing nul>
  823. //
  824. m_szSingleTemplateName = (LPTSTR) LocalAlloc(LPTR,(lstrlen(pszGPTPath)+lstrlen(GPTSCE_TEMPLATE)+2)*sizeof(TCHAR));
  825. }
  826. if (NULL != m_szSingleTemplateName)
  827. {
  828. //This is a safe usage.
  829. lstrcpy(m_szSingleTemplateName,pszGPTPath);
  830. lstrcat(m_szSingleTemplateName,L"\\" GPTSCE_TEMPLATE);
  831. PSCE_PROFILE_INFO spi = NULL;
  832. //
  833. // Create a new template there if there isn't one already
  834. //
  835. if (!CreateNewProfile(m_szSingleTemplateName,&spi))
  836. {
  837. hr = E_FAIL;
  838. }
  839. else
  840. {
  841. if (!GetTemplate(m_szSingleTemplateName) && spi)
  842. {
  843. //
  844. // bug 265996
  845. //
  846. // The first time a GPO's Security Settings are opened we create
  847. // the file, but if it's on a remote machine it may not have been
  848. // created yet when we try to open it
  849. //
  850. // Since we know what's going to be in it once it's created we
  851. // can skip the open step and just shove our template into the
  852. // cache
  853. //
  854. // Allocate space for key.
  855. //
  856. LPTSTR szKey = new TCHAR[ lstrlen( m_szSingleTemplateName ) + 1];
  857. if(!szKey)
  858. {
  859. return NULL;
  860. }
  861. //This is a safe usage.
  862. lstrcpy(szKey, m_szSingleTemplateName);
  863. _wcslwr( szKey );
  864. //
  865. // Create a new CEditTemplate
  866. //
  867. CEditTemplate *pTemplateInfo = new CEditTemplate;
  868. if (pTemplateInfo)
  869. {
  870. pTemplateInfo->SetInfFile(m_szSingleTemplateName);
  871. pTemplateInfo->SetNotificationWindow(m_pNotifier);
  872. pTemplateInfo->pTemplate = spi;
  873. //
  874. // This is a brand new template; ergo everything's loaded
  875. //
  876. pTemplateInfo->AddArea(AREA_ALL);
  877. //
  878. // Stick it in the cache
  879. //
  880. m_Templates.SetAt(szKey, pTemplateInfo);
  881. //
  882. // expand registry value section based on registry values list on local machine
  883. //
  884. SceRegEnumAllValues(
  885. &(pTemplateInfo->pTemplate->RegValueCount),
  886. &(pTemplateInfo->pTemplate->aRegValues));
  887. }
  888. if (szKey)
  889. delete[] szKey;
  890. }
  891. }
  892. }
  893. else
  894. hr = E_OUTOFMEMORY;
  895. }
  896. }
  897. nStart = FIRST_PROFILE_FOLDER;
  898. //
  899. // Display all but the DS Objects folder
  900. //
  901. nCount = LAST_PROFILE_NODS_FOLDER - FIRST_PROFILE_FOLDER +1;
  902. bHasChildren = FALSE;
  903. tmpstr = pFolder->GetInfFile(); // inf file full path name
  904. //
  905. // If this folder is in a write-through mode then set that
  906. // on the template
  907. //
  908. PEDITTEMPLATE pie;
  909. pie = GetTemplate(tmpstr);
  910. if ( pie )
  911. {
  912. if (ModeBits & MB_WRITE_THROUGH)
  913. {
  914. pie->SetWriteThrough(TRUE);
  915. }
  916. }
  917. else
  918. {
  919. //
  920. // Mark as bad template.
  921. //
  922. pFolder->SetState( CFolder::state_InvalidTemplate );
  923. nCount = 0;
  924. }
  925. break;
  926. }
  927. case LOCALPOL:
  928. {
  929. nStart = FIRST_PROFILE_FOLDER;
  930. nCount = LAST_LOCALPOL_FOLDER - FIRST_PROFILE_FOLDER +1;
  931. bHasChildren = FALSE;
  932. pFolder->SetInfFile(GT_LOCAL_POLICY);
  933. break;
  934. }
  935. case POLICY_ACCOUNT:
  936. if (!pFolder)
  937. {
  938. return E_INVALIDARG;
  939. }
  940. else
  941. {
  942. tmpstr = pFolder->GetInfFile();
  943. }
  944. // fall through;
  945. case LOCALPOL_ACCOUNT:
  946. case POLICY_ACCOUNT_ANALYSIS:
  947. nStart = FIRST_ACCOUNT_FOLDER;
  948. if (ModeBits & MB_DS_OBJECTS_SECTION)
  949. {
  950. //
  951. // Include the DC Specific folders
  952. //
  953. nCount = LAST_ACCOUNT_FOLDER - FIRST_ACCOUNT_FOLDER + 1;
  954. }
  955. else
  956. {
  957. //
  958. // Display all but the DC Specific folders
  959. //
  960. nCount = LAST_ACCOUNT_NODS_FOLDER - FIRST_ACCOUNT_FOLDER +1;
  961. }
  962. bHasChildren = FALSE;
  963. break;
  964. case POLICY_LOCAL:
  965. if (!pFolder)
  966. {
  967. return E_INVALIDARG;
  968. }
  969. else
  970. {
  971. tmpstr = pFolder->GetInfFile();
  972. }
  973. // fall through;
  974. case LOCALPOL_LOCAL:
  975. case POLICY_LOCAL_ANALYSIS:
  976. nStart = FIRST_LOCAL_FOLDER;
  977. nCount = LAST_LOCAL_FOLDER - FIRST_LOCAL_FOLDER +1;
  978. bHasChildren = FALSE;
  979. break;
  980. case POLICY_EVENTLOG:
  981. if (!pFolder)
  982. return E_INVALIDARG;
  983. else
  984. tmpstr = pFolder->GetInfFile();
  985. // fall through;
  986. case LOCALPOL_EVENTLOG:
  987. case POLICY_EVENTLOG_ANALYSIS:
  988. nStart = FIRST_EVENTLOG_FOLDER;
  989. nCount = LAST_EVENTLOG_FOLDER - FIRST_EVENTLOG_FOLDER +1;
  990. bHasChildren = FALSE;
  991. break;
  992. default:
  993. break;
  994. }
  995. if ( Count != NULL )
  996. *Count = nCount;
  997. CString cStrName;
  998. CString cStrDesc;
  999. for (int i=nStart; i < nStart+nCount; i++)
  1000. {
  1001. folder = new CFolder();
  1002. if (!folder)
  1003. {
  1004. //
  1005. // What about other folders that we've created?
  1006. //
  1007. return E_OUTOFMEMORY;
  1008. }
  1009. if (!cStrName.LoadString(SecmgrFolders[i].ResID) ||
  1010. !cStrDesc.LoadString(SecmgrFolders[i].DescID))
  1011. {
  1012. delete folder;
  1013. return E_FAIL;
  1014. }
  1015. //
  1016. // Create the folder objects with static data
  1017. //
  1018. if (type == ANALYSIS ||
  1019. type == AREA_POLICY_ANALYSIS ||
  1020. type == POLICY_ACCOUNT_ANALYSIS ||
  1021. type == POLICY_LOCAL_ANALYSIS ||
  1022. type == POLICY_EVENTLOG_ANALYSIS )
  1023. {
  1024. if (m_bIsLocked)
  1025. {
  1026. nCount = 0;
  1027. delete folder;
  1028. // Should display an "in use" message in result pane
  1029. //
  1030. // We're not adding anything, but we're not actually failing
  1031. //
  1032. return S_OK;
  1033. }
  1034. tmpstr = GT_COMPUTER_TEMPLATE;
  1035. switch (SecmgrFolders[i].type)
  1036. {
  1037. case AREA_POLICY:
  1038. newType = AREA_POLICY_ANALYSIS;
  1039. break;
  1040. case AREA_PRIVILEGE:
  1041. newType = AREA_PRIVILEGE_ANALYSIS;
  1042. break;
  1043. case AREA_GROUPS:
  1044. newType = AREA_GROUPS_ANALYSIS;
  1045. break;
  1046. case AREA_SERVICE:
  1047. newType = AREA_SERVICE_ANALYSIS;
  1048. tmpstr = GT_COMPUTER_TEMPLATE;
  1049. break;
  1050. case AREA_REGISTRY:
  1051. newType = AREA_REGISTRY_ANALYSIS;
  1052. break;
  1053. case AREA_FILESTORE:
  1054. newType = AREA_FILESTORE_ANALYSIS;
  1055. break;
  1056. case POLICY_ACCOUNT:
  1057. newType = POLICY_ACCOUNT_ANALYSIS;
  1058. break;
  1059. case POLICY_LOCAL:
  1060. newType = POLICY_LOCAL_ANALYSIS;
  1061. break;
  1062. case POLICY_EVENTLOG:
  1063. newType = POLICY_EVENTLOG_ANALYSIS;
  1064. break;
  1065. case POLICY_PASSWORD:
  1066. newType = POLICY_PASSWORD_ANALYSIS;
  1067. break;
  1068. case POLICY_KERBEROS:
  1069. newType = POLICY_KERBEROS_ANALYSIS;
  1070. break;
  1071. case POLICY_LOCKOUT:
  1072. newType = POLICY_LOCKOUT_ANALYSIS;
  1073. break;
  1074. case POLICY_AUDIT:
  1075. newType = POLICY_AUDIT_ANALYSIS;
  1076. break;
  1077. case POLICY_OTHER:
  1078. newType = POLICY_OTHER_ANALYSIS;
  1079. break;
  1080. case POLICY_LOG:
  1081. newType = POLICY_LOG_ANALYSIS;
  1082. break;
  1083. default:
  1084. newType = SecmgrFolders[i].type;
  1085. break;
  1086. }
  1087. int nImage = GetScopeImageIndex(newType);
  1088. hr = folder->Create(cStrName.GetBuffer(2), // Name
  1089. cStrDesc.GetBuffer(2), // Description
  1090. tmpstr, // inf file name
  1091. nImage, // closed icon index
  1092. nImage, // open icon index
  1093. newType, // folder type
  1094. bHasChildren, // has children
  1095. dwMode, // SCE Mode
  1096. NULL); // Extra Data
  1097. }
  1098. else if (type == LOCALPOL ||
  1099. type == AREA_LOCALPOL ||
  1100. type == LOCALPOL_ACCOUNT ||
  1101. type == LOCALPOL_LOCAL ||
  1102. type == LOCALPOL_EVENTLOG )
  1103. {
  1104. if (m_bIsLocked)
  1105. {
  1106. nCount = 0;
  1107. delete folder;
  1108. // Should display an "in use" message in result pane
  1109. //
  1110. // We're not adding anything, but we're not actually failing
  1111. //
  1112. return S_OK;
  1113. }
  1114. tmpstr = GT_LOCAL_POLICY;
  1115. switch (SecmgrFolders[i].type)
  1116. {
  1117. case AREA_POLICY:
  1118. newType = AREA_LOCALPOL;
  1119. break;
  1120. case POLICY_ACCOUNT:
  1121. newType = LOCALPOL_ACCOUNT;
  1122. break;
  1123. case POLICY_LOCAL:
  1124. newType = LOCALPOL_LOCAL;
  1125. break;
  1126. case POLICY_EVENTLOG:
  1127. newType = LOCALPOL_EVENTLOG;
  1128. break;
  1129. case POLICY_PASSWORD:
  1130. newType = LOCALPOL_PASSWORD;
  1131. break;
  1132. case POLICY_KERBEROS:
  1133. newType = LOCALPOL_KERBEROS;
  1134. break;
  1135. case POLICY_LOCKOUT:
  1136. newType = LOCALPOL_LOCKOUT;
  1137. break;
  1138. case POLICY_AUDIT:
  1139. newType = LOCALPOL_AUDIT;
  1140. break;
  1141. case POLICY_OTHER:
  1142. newType = LOCALPOL_OTHER;
  1143. break;
  1144. case POLICY_LOG:
  1145. newType = LOCALPOL_LOG;
  1146. break;
  1147. case AREA_PRIVILEGE:
  1148. newType = LOCALPOL_PRIVILEGE;
  1149. break;
  1150. default:
  1151. newType = SecmgrFolders[i].type;
  1152. break;
  1153. }
  1154. int nImage = GetScopeImageIndex(newType);
  1155. hr = folder->Create(cStrName.GetBuffer(2), // Name
  1156. cStrDesc.GetBuffer(2), // Description
  1157. tmpstr, // inf file name
  1158. nImage, // closed icon index
  1159. nImage, // open icon index
  1160. newType, // folder type
  1161. bHasChildren, // has children
  1162. dwMode, // SCE Mode
  1163. NULL); // Extra Data
  1164. }
  1165. else
  1166. {
  1167. int nImage = GetScopeImageIndex(SecmgrFolders[i].type);
  1168. hr = folder->Create(cStrName.GetBuffer(2), // Name
  1169. cStrDesc.GetBuffer(2), // Description
  1170. tmpstr, // inf file name
  1171. nImage, // closed icon index
  1172. nImage, // open icon index
  1173. SecmgrFolders[i].type, // folder type
  1174. bHasChildren, // has children
  1175. dwMode, // SCE Mode
  1176. NULL); // Extra Data
  1177. }
  1178. if (SUCCEEDED(hr))
  1179. {
  1180. m_scopeItemList.AddTail(folder);
  1181. if ( i == nStart && NULL != pPos )
  1182. {
  1183. *pPos = m_scopeItemList.GetTailPosition();
  1184. }
  1185. }
  1186. else
  1187. {
  1188. delete folder;
  1189. return hr;
  1190. }
  1191. }
  1192. return S_OK;
  1193. }
  1194. //+--------------------------------------------------------------------------
  1195. //
  1196. // Method: EnumerateScopePane
  1197. //
  1198. // Synopsis: Add the child folders of cookie/pParent to MMC's scope pane tree
  1199. //
  1200. // Arguments: [cookie] - The cookie representing the node's who we
  1201. // are enumerating
  1202. // [pParent] - The id of the node we are enumerating
  1203. // [dwMode] - The mode SCE is operating under (only allowed for
  1204. // initial enumeration)
  1205. //
  1206. // Returns: none
  1207. //
  1208. // Modifies: m_ScopeItemList (via CreateFolderList)
  1209. //
  1210. // History: 12-15-1997 Robcap
  1211. //
  1212. //---------------------------------------------------------------------------
  1213. void CComponentDataImpl::EnumerateScopePane(MMC_COOKIE cookie, HSCOPEITEM pParent)
  1214. {
  1215. int i = 0;
  1216. ASSERT(m_pScope != NULL); // make sure we QI'ed for the interface
  1217. if (NULL == m_pScope)
  1218. return;
  1219. m_bEnumerateScopePaneCalled = true;
  1220. //
  1221. // Enumerate the scope pane
  1222. //
  1223. // Note - Each cookie in the scope pane represents a folder.
  1224. // A released product may have more then one level of children.
  1225. // This sample assumes the parent node is one level deep.
  1226. ASSERT(pParent != 0);
  1227. if (0 == pParent)
  1228. return;
  1229. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1230. if (m_scopeItemList.GetCount() == 0 )
  1231. {
  1232. CreateFolderList(NULL, ROOT, NULL, NULL);
  1233. }
  1234. //
  1235. // Enumerate the scope pane
  1236. // return the folder object that represents the cookie
  1237. // Note - for large list, use dictionary
  1238. //
  1239. CFolder* pThis = FindObject(cookie, NULL);
  1240. if (NULL == pThis)
  1241. pThis = m_AnalFolder;
  1242. ASSERT(pThis);
  1243. if ( NULL == pThis )
  1244. return;
  1245. //
  1246. // Note - Each cookie in the scope pane represents a folder.
  1247. //
  1248. //
  1249. // If we've already enumerated this folder then don't do it again
  1250. //
  1251. if ( pThis->IsEnumerated() )
  1252. return;
  1253. POSITION pos = NULL;
  1254. int nCount = 0;
  1255. CFolder *pFolder = 0;
  1256. //
  1257. // the pParent is the enumerated node's item ID, not its parent ID
  1258. //
  1259. pThis->GetScopeItem()->ID = pParent;
  1260. if (SUCCEEDED(CreateFolderList( pThis,
  1261. pThis->GetType(),
  1262. &pos,
  1263. &nCount )))
  1264. {
  1265. for (i=0; (i < nCount) && (pos != NULL); i++ )
  1266. {
  1267. pFolder = m_scopeItemList.GetNext(pos);
  1268. ASSERT(NULL != pFolder);
  1269. if ( pFolder == NULL )
  1270. {
  1271. continue;
  1272. }
  1273. LPSCOPEDATAITEM pScope;
  1274. pScope = pFolder->GetScopeItem();
  1275. ASSERT(NULL != pScope); //Validate pScope.
  1276. if( !pScope ) //Raid #550912, yanggao.
  1277. {
  1278. break;
  1279. }
  1280. //
  1281. // Set the parent
  1282. //
  1283. pScope->relativeID = pParent;
  1284. //
  1285. // Set the folder as the cookie
  1286. //
  1287. pScope->mask |= SDI_PARAM;
  1288. pScope->lParam = reinterpret_cast<LPARAM>(pFolder);
  1289. pFolder->SetCookie(reinterpret_cast<MMC_COOKIE>(pFolder));
  1290. m_pScope->InsertItem(pScope);
  1291. //
  1292. // Note - On return, the ID member of 'm_pScopeItem'
  1293. // contains the handle to the newly inserted item!
  1294. //
  1295. ASSERT(pScope->ID != NULL); //Bogus assertion
  1296. }
  1297. // This was commented out, but is needed to fix
  1298. // 249158: SCE UI: Every time analysis is performed, another set of node appears
  1299. // This flag will prevent the nodes from being re-enumerated.
  1300. // If this doesn't work, then all the child nodes should be deleted before
  1301. // reenumeration
  1302. pThis->Set(TRUE); // folder has been enumerated
  1303. }
  1304. else
  1305. {
  1306. //
  1307. // Error creating folder list. Make sure the folder isn't
  1308. // marked as opened so that we can try to expand it again later
  1309. //
  1310. SCOPEDATAITEM item;
  1311. ZeroMemory (&item, sizeof (item));
  1312. item.mask = SDI_STATE;
  1313. item.nState = 0;
  1314. item.ID = pThis->GetScopeItem()->ID;
  1315. //
  1316. // Nothing else we can do if this returns a failure, so
  1317. // don't worry about it
  1318. //
  1319. (void)m_pScope->SetItem (&item);
  1320. }
  1321. }
  1322. /*------------------------------------------------------------------------------------------
  1323. CComponentDataImpl::GetColumnInfo
  1324. Synopsis: Returns the column info for a folder type.
  1325. Arguments: [fType] - The type of the CFolder item.
  1326. Returns: a pointer to an int * where int[0] = the resource descritption into g_columnInfo.
  1327. int[1] = the number of columns this array describes.
  1328. NULL - If there is no matching key.
  1329. ------------------------------------------------------------------------------------------*/
  1330. PSCE_COLINFOARRAY CComponentDataImpl::GetColumnInfo( FOLDER_TYPES fType )
  1331. {
  1332. PSCE_COLINFOARRAY pRet = NULL;
  1333. if( m_mapColumns.Lookup(fType, pRet) )
  1334. {
  1335. return pRet;
  1336. }
  1337. return NULL;
  1338. }
  1339. /*------------------------------------------------------------------------------------------
  1340. CComponentDataImpl::SetColumnInfo
  1341. Synopsis: Sets the column info for a certain type of folder.
  1342. Arguments: [fType] - The type of the CFolder item.
  1343. [pInfo] - The new column info.
  1344. ------------------------------------------------------------------------------------------*/
  1345. void CComponentDataImpl::SetColumnInfo( FOLDER_TYPES fType, PSCE_COLINFOARRAY pInfo)
  1346. {
  1347. PSCE_COLINFOARRAY pCur = GetColumnInfo(fType);
  1348. if(pCur)
  1349. {
  1350. LocalFree(pCur);
  1351. }
  1352. m_mapColumns.SetAt(fType, pInfo);
  1353. }
  1354. /*------------------------------------------------------------------------------------------
  1355. CComponentDataImpl::UpdateObjectStatus
  1356. Synopsis: Updates the status of all objects under the child and parents if bUpdateThis
  1357. is TRUE.
  1358. Arguments: [pParent] - The Object to set status on
  1359. [bUpdateThis] - Weather to update the object or not.
  1360. ------------------------------------------------------------------------------------------*/
  1361. DWORD CComponentDataImpl::UpdateObjectStatus(
  1362. CFolder *pParent,
  1363. BOOL bUpdateThis)
  1364. {
  1365. if(!pParent)
  1366. return ERROR_INVALID_PARAMETER;
  1367. DWORD status = 0;
  1368. TCHAR szBuf[50];
  1369. switch(pParent->GetType())
  1370. {
  1371. case REG_OBJECTS:
  1372. status = AREA_REGISTRY_SECURITY;
  1373. break;
  1374. case FILE_OBJECTS:
  1375. status = AREA_FILE_SECURITY;
  1376. break;
  1377. default:
  1378. return ERROR_INVALID_PARAMETER;
  1379. }
  1380. PSCE_OBJECT_CHILDREN ObjectList = NULL;
  1381. PSCE_ERROR_LOG_INFO ErrBuf = NULL;
  1382. SCESTATUS rc = 0;
  1383. CString StrErr;
  1384. SCOPEDATAITEM sci;
  1385. HSCOPEITEM hItem = NULL;
  1386. LONG_PTR pCookie = NULL;
  1387. ZeroMemory(&sci, sizeof(SCOPEDATAITEM));
  1388. sci.mask = SDI_STR | SDI_PARAM;
  1389. #define UPDATE_STATUS( X, O ) X->SetDesc( O->Status, O->Count );\
  1390. X->GetScopeItem()->nImage = GetScopeImageIndex( X->GetType(), O->Status);\
  1391. X->GetScopeItem()->nOpenImage = X->GetScopeItem()->nImage;
  1392. LPCTSTR pszParent = NULL;
  1393. if (bUpdateThis)
  1394. {
  1395. CFolder *pCurrent = pParent;
  1396. pParent->RemoveAllResultItems();
  1397. m_pConsole->UpdateAllViews(NULL, (MMC_COOKIE)pParent, UAV_RESULTITEM_UPDATEALL);
  1398. hItem = pCurrent->GetScopeItem()->ID;
  1399. do {
  1400. //
  1401. // Walk up the items parent and update the items status.
  1402. //
  1403. if( m_pScope->GetParentItem( hItem, &hItem, &pCookie) == S_OK)
  1404. {
  1405. pszParent = (LPCTSTR)((CFolder *)pCookie)->GetName();
  1406. }
  1407. else
  1408. break;
  1409. if(!pCookie)
  1410. break;
  1411. //
  1412. // We are finished going up the parent.
  1413. //
  1414. switch( ((CFolder *)pCookie)->GetType() )
  1415. {
  1416. case AREA_REGISTRY_ANALYSIS:
  1417. case AREA_FILESTORE_ANALYSIS:
  1418. pszParent = NULL;
  1419. break;
  1420. default:
  1421. break;
  1422. }
  1423. //
  1424. // We have to get object information from the parent to the count parameter.
  1425. //
  1426. rc = SceGetObjectChildren(SadHandle, // hProfile
  1427. SCE_ENGINE_SAP, // Profile type
  1428. (AREA_INFORMATION)status, // Area
  1429. (LPTSTR)pszParent, // Object prefix
  1430. &ObjectList, // Object list [out]
  1431. &ErrBuf);
  1432. if(ErrBuf)
  1433. {
  1434. SceFreeMemory((PVOID)ErrBuf, SCE_STRUCT_ERROR_LOG_INFO);
  1435. ErrBuf = NULL;
  1436. }
  1437. if(SCESTATUS_SUCCESS != rc)
  1438. break;
  1439. //
  1440. // Find object in link list.
  1441. //
  1442. DWORD i=0;
  1443. sci.lParam = (LONG_PTR)pCurrent;
  1444. GetDisplayInfo( &sci );
  1445. PSCE_OBJECT_CHILDREN_NODE *pObjNode = &(ObjectList->arrObject);
  1446. while(ObjectList && i<ObjectList->nCount)
  1447. {
  1448. if( pObjNode[i] &&
  1449. pObjNode[i]->Name &&
  1450. !lstrcmpi(sci.displayname, pObjNode[i]->Name) )
  1451. {
  1452. UPDATE_STATUS(pCurrent, pObjNode[i]);
  1453. //
  1454. // Update scopeItem.
  1455. //
  1456. m_pScope->SetItem(pCurrent->GetScopeItem());
  1457. break;
  1458. }
  1459. i++;
  1460. }
  1461. if ( ObjectList )
  1462. {
  1463. SceFreeMemory((PVOID)ObjectList, SCE_STRUCT_OBJECT_CHILDREN );
  1464. ObjectList = NULL;
  1465. }
  1466. pCurrent = (CFolder *)pCookie;
  1467. } while( pszParent && hItem );
  1468. }
  1469. ObjectList = NULL;
  1470. ErrBuf = NULL;
  1471. //
  1472. // Get Object children.
  1473. //
  1474. pszParent = pParent->GetName();
  1475. rc = SceGetObjectChildren(SadHandle, // hProfile
  1476. SCE_ENGINE_SAP, // Profile type
  1477. (AREA_INFORMATION)status, // Area
  1478. (LPTSTR)pszParent, // Object prefix
  1479. &ObjectList, // Object list [out]
  1480. &ErrBuf);
  1481. //
  1482. // Error list [out]
  1483. //
  1484. if ( ErrBuf )
  1485. {
  1486. MyFormatResMessage(rc, IDS_ERROR_GETTING_LAST_ANALYSIS, ErrBuf, StrErr);
  1487. SceFreeMemory((PVOID)ErrBuf, SCE_STRUCT_ERROR_LOG_INFO);
  1488. ErrBuf = NULL;
  1489. }
  1490. if ( SCESTATUS_SUCCESS == rc)
  1491. {
  1492. //
  1493. // Update all the children.
  1494. //
  1495. if( m_pScope->GetChildItem(pParent->GetScopeItem()->ID, &hItem, &pCookie) == S_OK && pCookie)
  1496. {
  1497. sci.lParam = (LONG_PTR)pCookie;
  1498. GetDisplayInfo(&sci);
  1499. while(hItem)
  1500. {
  1501. pParent = reinterpret_cast<CFolder *>(pCookie);
  1502. //
  1503. // Find object in object list.
  1504. //
  1505. DWORD i=0;
  1506. while( ObjectList && i<ObjectList->nCount )
  1507. {
  1508. if( (&(ObjectList->arrObject))[i] &&
  1509. (&(ObjectList->arrObject))[i]->Name &&
  1510. !lstrcmpi((&(ObjectList->arrObject))[i]->Name, (LPCTSTR)sci.displayname) )
  1511. {
  1512. UPDATE_STATUS(pParent, (&(ObjectList->arrObject))[i]);
  1513. //
  1514. // Update this objects children.
  1515. //
  1516. UpdateObjectStatus( pParent, FALSE );
  1517. //
  1518. // Update the name space
  1519. //
  1520. pParent->RemoveAllResultItems();
  1521. m_pConsole->UpdateAllViews(NULL, (MMC_COOKIE)pParent, UAV_RESULTITEM_UPDATEALL);
  1522. m_pScope->SetItem(pParent->GetScopeItem());
  1523. break;
  1524. }
  1525. i++;
  1526. }
  1527. if(ObjectList == NULL || i >= ObjectList->nCount)
  1528. {
  1529. //
  1530. // Couldn't find the item, so just stop.
  1531. //
  1532. break;
  1533. }
  1534. //
  1535. // Next Scope item
  1536. //
  1537. if( m_pScope->GetNextItem(hItem, &hItem, &pCookie) != S_OK)
  1538. {
  1539. break;
  1540. }
  1541. }
  1542. }
  1543. }
  1544. if ( ObjectList )
  1545. SceFreeMemory((PVOID)ObjectList, SCE_STRUCT_OBJECT_CHILDREN );
  1546. return ERROR_SUCCESS;
  1547. }