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

7401 lines
216 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2001.
  5. //
  6. // File: snapmgr.cpp
  7. //
  8. // Contents: Core CComponentDataImpl and CSnapin routines for
  9. // Security Configuration Modules (Editor, Manager, Extension)
  10. //
  11. // History:
  12. //
  13. //---------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "afxcmn.h"
  16. #include "afxdlgs.h"
  17. #include "cookie.h"
  18. #include "snapmgr.h"
  19. #include "DataObj.h"
  20. #include "resource.h"
  21. #include "wrapper.h"
  22. #include "util.h"
  23. #include "RegDlg.h"
  24. #include "savetemp.h"
  25. #include "getuser.h"
  26. #include "servperm.h"
  27. #include "addobj.h"
  28. #include "perfanal.h"
  29. #include "newprof.h"
  30. #include "AddGrp.h"
  31. #include "dattrs.h"
  32. #define INITGUID
  33. #include "scesetup.h"
  34. #include "userenv.h"
  35. #undef INITGUID
  36. #include <gpedit.h>
  37. // #include <atlimpl.cpp>
  38. #ifdef _DEBUG
  39. #define new DEBUG_NEW
  40. #undef THIS_FILE
  41. static char THIS_FILE[] = __FILE__;
  42. #endif
  43. #define CF_MACHINE_NAME L"MMC_SNAPIN_MACHINE_NAME"
  44. long CSnapin::lDataObjectRefCount = 0;
  45. BOOL RegisterCheckListWndClass(void); // in chklist.cpp
  46. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  47. static MMCBUTTON SnapinButtons[] =
  48. {
  49. { 0, 1, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Folder"), _T("New Folder")},
  50. { 1, 2, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Inbox"), _T("Mail Inbox")},
  51. { 2, 3, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Outbox"), _T("Mail Outbox")},
  52. { 3, 4, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Send"), _T("Send Message")},
  53. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, _T(" "), _T("")},
  54. { 4, 5, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Trash"), _T("Trash")},
  55. { 5, 6, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Open"), _T("Open Folder")},
  56. { 6, 7, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("News"), _T("Today's News")},
  57. { 7, 8, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("INews"), _T("Internet News")},
  58. };
  59. static MMCBUTTON SnapinButtons2[] =
  60. {
  61. { 0, 10, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Compose"), _T("Compose Message")},
  62. { 1, 20, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Print"), _T("Print Message")},
  63. { 2, 30, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Find"), _T("Find Message")},
  64. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, _T(" "), _T("")},
  65. { 3, 40, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Inbox"), _T("Inbox")},
  66. { 4, 50, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Smile"), _T("Smile :-)")},
  67. { 5, 60, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Reply"), _T("Reply")},
  68. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP , _T(" "), _T("")},
  69. { 6, 70, TBSTATE_ENABLED, TBSTYLE_BUTTON, _T("Reply All"), _T("Reply All")},
  70. };
  71. UINT cfSceAccountArea;
  72. UINT cfSceEventLogArea;
  73. UINT cfSceLocalArea;
  74. UINT cfSceGroupsArea;
  75. UINT cfSceRegistryArea;
  76. UINT cfSceFileArea;
  77. UINT cfSceServiceArea;
  78. ///////////////////////////////////////////////////////////////////////////////
  79. // RESOURCES
  80. BEGIN_MENU(CSecmgrNodeMenuHolder)
  81. BEGIN_CTX
  82. END_CTX
  83. BEGIN_RES
  84. END_RES
  85. END_MENU
  86. BEGIN_MENU(CAnalyzeNodeMenuHolder)
  87. BEGIN_CTX
  88. CTX_ENTRY(IDM_OPEN_PRIVATE_DB, 0, 0)
  89. CTX_ENTRY(IDM_ANALYZE, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  90. CTX_ENTRY(IDM_APPLY, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  91. CTX_ENTRY(IDM_SAVE, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  92. CTX_ENTRY(IDM_ASSIGN, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  93. CTX_ENTRY(IDM_GENERATE, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  94. CTX_ENTRY(IDM_VIEW_LOGFILE, 0, CCM_INSERTIONPOINTID_PRIMARY_VIEW)
  95. CTX_ENTRY(IDM_SECURE_WIZARD, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  96. END_CTX
  97. BEGIN_RES
  98. RES_ENTRY(IDS_OPEN_DB)
  99. RES_ENTRY(IDS_ANALYZE_PROFILE)
  100. RES_ENTRY(IDS_APPLY_PROFILE)
  101. RES_ENTRY(IDS_SAVE_PROFILE)
  102. RES_ENTRY(IDS_ASSIGN_CONFIGURATION)
  103. RES_ENTRY(IDS_GENERATE_PROFILE)
  104. RES_ENTRY(IDS_VIEW_LOGFILE)
  105. RES_ENTRY(IDS_SECURE_WIZARD)
  106. END_RES
  107. END_MENU
  108. BEGIN_MENU(CConfigNodeMenuHolder)
  109. BEGIN_CTX
  110. CTX_ENTRY(IDM_ADD_LOC, 0, CCM_INSERTIONPOINTID_PRIMARY_NEW)
  111. END_CTX
  112. BEGIN_RES
  113. RES_ENTRY(IDS_ADD_LOCATION)
  114. END_RES
  115. END_MENU
  116. BEGIN_MENU(CLocationNodeMenuHolder)
  117. BEGIN_CTX
  118. CTX_ENTRY(IDM_NEW, 0, CCM_INSERTIONPOINTID_PRIMARY_NEW)
  119. //CTX_ENTRY(IDM_REMOVE, 0)
  120. CTX_ENTRY(IDM_RELOAD, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  121. CTX_ENTRY(IDM_DESCRIBE_LOCATION, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  122. END_CTX
  123. BEGIN_RES
  124. RES_ENTRY(IDS_NEW_PROFILE)
  125. //RES_ENTRY(IDS_REMOVE_LOCATION)
  126. RES_ENTRY(IDS_RELOAD_LOCATION)
  127. RES_ENTRY(IDS_DESCRIBE)
  128. END_RES
  129. END_MENU
  130. BEGIN_MENU(CSSProfileNodeMenuHolder)
  131. BEGIN_CTX
  132. CTX_ENTRY(IDM_IMPORT_POLICY, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  133. CTX_ENTRY(IDM_EXPORT_POLICY, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  134. CTX_ENTRY(IDM_RELOAD, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  135. END_CTX
  136. BEGIN_RES
  137. RES_ENTRY(IDS_IMPORT_POLICY)
  138. RES_ENTRY(IDS_EXPORT_POLICY)
  139. RES_ENTRY(IDS_REFRESH_TEMPLATE)
  140. END_RES
  141. END_MENU
  142. BEGIN_MENU(CRSOPProfileNodeMenuHolder)
  143. BEGIN_CTX
  144. //CTX_ENTRY(IDM_RELOAD, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  145. END_CTX
  146. BEGIN_RES
  147. //RES_ENTRY(IDS_REFRESH_TEMPLATE)
  148. END_RES
  149. END_MENU
  150. BEGIN_MENU(CLocalPolNodeMenuHolder)
  151. BEGIN_CTX
  152. CTX_ENTRY(IDM_IMPORT_LOCAL_POLICY, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  153. CTX_ENTRY(IDM_RELOAD, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  154. END_CTX
  155. BEGIN_RES
  156. RES_ENTRY(IDS_IMPORT_POLICY)
  157. RES_ENTRY(IDS_REFRESH_LOCALPOL)
  158. END_RES
  159. END_MENU
  160. BEGIN_MENU(CProfileNodeMenuHolder)
  161. BEGIN_CTX
  162. CTX_ENTRY(IDM_DESCRIBE_PROFILE, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  163. CTX_ENTRY(IDM_SAVE, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  164. CTX_ENTRY(IDM_SAVEAS, 0, CCM_INSERTIONPOINTID_PRIMARY_TASK)
  165. END_CTX
  166. BEGIN_RES
  167. RES_ENTRY(IDS_DESCRIBE)
  168. RES_ENTRY(IDS_SAVE_PROFILE)
  169. RES_ENTRY(IDS_SAVEAS_PROFILE)
  170. END_RES
  171. END_MENU
  172. BEGIN_MENU(CProfileAreaMenuHolder)
  173. BEGIN_CTX
  174. CTX_ENTRY(IDM_COPY, 0,0)
  175. CTX_ENTRY(IDM_PASTE, 0,0)
  176. END_CTX
  177. BEGIN_RES
  178. RES_ENTRY(IDS_COPY_PROFILE)
  179. RES_ENTRY(IDS_PASTE_PROFILE)
  180. END_RES
  181. END_MENU
  182. BEGIN_MENU(CProfileSubAreaMenuHolder)
  183. BEGIN_CTX
  184. END_CTX
  185. BEGIN_RES
  186. END_RES
  187. END_MENU
  188. BEGIN_MENU(CProfileSubAreaEventLogMenuHolder) //Raid #253209, Yang Gao, 3/27/2001
  189. BEGIN_CTX
  190. CTX_ENTRY(IDM_COPY, 0,0)
  191. CTX_ENTRY(IDM_PASTE, 0,0)
  192. END_CTX
  193. BEGIN_RES
  194. RES_ENTRY(IDS_COPY_PROFILE)
  195. RES_ENTRY(IDS_PASTE_PROFILE)
  196. END_RES
  197. END_MENU
  198. BEGIN_MENU(CProfileGroupsMenuHolder)
  199. BEGIN_CTX
  200. CTX_ENTRY(IDM_ADD_GROUPS, 0,CCM_INSERTIONPOINTID_PRIMARY_NEW)
  201. CTX_ENTRY(IDM_COPY, 0,0)
  202. CTX_ENTRY(IDM_PASTE, 0,0)
  203. END_CTX
  204. BEGIN_RES
  205. RES_ENTRY(IDS_ADD_GROUP)
  206. RES_ENTRY(IDS_COPY_PROFILE)
  207. RES_ENTRY(IDS_PASTE_PROFILE)
  208. END_RES
  209. END_MENU
  210. BEGIN_MENU(CProfileRegistryMenuHolder)
  211. BEGIN_CTX
  212. CTX_ENTRY(IDM_ADD_REGISTRY, 0,CCM_INSERTIONPOINTID_PRIMARY_NEW)
  213. CTX_ENTRY(IDM_COPY, 0,0)
  214. CTX_ENTRY(IDM_PASTE, 0,0)
  215. END_CTX
  216. BEGIN_RES
  217. RES_ENTRY(IDS_ADD_KEY)
  218. RES_ENTRY(IDS_COPY_PROFILE)
  219. RES_ENTRY(IDS_PASTE_PROFILE)
  220. END_RES
  221. END_MENU
  222. BEGIN_MENU(CProfileFilesMenuHolder)
  223. BEGIN_CTX
  224. CTX_ENTRY(IDM_ADD_FOLDER, 0,CCM_INSERTIONPOINTID_PRIMARY_NEW)
  225. CTX_ENTRY(IDM_COPY, 0,0)
  226. CTX_ENTRY(IDM_PASTE, 0,0)
  227. END_CTX
  228. BEGIN_RES
  229. RES_ENTRY(IDS_ADD_FILES_AND_FOLDERS)
  230. RES_ENTRY(IDS_COPY_PROFILE)
  231. RES_ENTRY(IDS_PASTE_PROFILE)
  232. END_RES
  233. END_MENU
  234. BEGIN_MENU(CAnalyzeAreaMenuHolder)
  235. BEGIN_CTX
  236. END_CTX
  237. BEGIN_RES
  238. END_RES
  239. END_MENU
  240. BEGIN_MENU(CAnalyzeGroupsMenuHolder)
  241. BEGIN_CTX
  242. CTX_ENTRY(IDM_ADD_GROUPS, 0,CCM_INSERTIONPOINTID_PRIMARY_NEW)
  243. END_CTX
  244. BEGIN_RES
  245. RES_ENTRY(IDS_ADD_GROUP)
  246. END_RES
  247. END_MENU
  248. BEGIN_MENU(CAnalyzeFilesMenuHolder)
  249. BEGIN_CTX
  250. CTX_ENTRY(IDM_ADD_ANAL_FOLDER, 0,CCM_INSERTIONPOINTID_PRIMARY_NEW)
  251. END_CTX
  252. BEGIN_RES
  253. RES_ENTRY(IDS_ADD_FILES_AND_FOLDERS)
  254. END_RES
  255. END_MENU
  256. BEGIN_MENU(CAnalyzeRegistryMenuHolder)
  257. BEGIN_CTX
  258. CTX_ENTRY(IDM_ADD_ANAL_KEY, 0,CCM_INSERTIONPOINTID_PRIMARY_NEW)
  259. END_CTX
  260. BEGIN_RES
  261. RES_ENTRY(IDS_ADD_KEY)
  262. END_RES
  263. END_MENU
  264. BEGIN_MENU(CAnalyzeObjectsMenuHolder)
  265. BEGIN_CTX
  266. //CTX_ENTRY(IDM_OBJECT_SECURITY,0,CCM_INSERTIONPOINTID_PRIMARY_TASK)
  267. END_CTX
  268. BEGIN_RES
  269. //RES_ENTRY(IDS_SECURITY_MENU)
  270. END_RES
  271. END_MENU
  272. ////////////////////////////////////////////////////////////
  273. // Implementation
  274. template <class TYPE>
  275. TYPE* Extract(LPDATAOBJECT lpDataObject, CLIPFORMAT cf)
  276. {
  277. ASSERT(lpDataObject != NULL);
  278. //Raid #202964, 4/17/2001
  279. if ( lpDataObject == NULL || (LPDATAOBJECT) MMC_MULTI_SELECT_COOKIE == lpDataObject )
  280. {
  281. return NULL;
  282. }
  283. TYPE* p = NULL;
  284. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL};
  285. FORMATETC formatetc = {
  286. cf,
  287. NULL,
  288. DVASPECT_CONTENT,
  289. -1,
  290. TYMED_HGLOBAL
  291. };
  292. HRESULT hRet = S_OK;
  293. // Allocate memory for the stream
  294. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, sizeof(TYPE));
  295. // Attempt to get data from the object
  296. do {
  297. if (stgmedium.hGlobal == NULL)
  298. break;
  299. hRet = lpDataObject->GetDataHere(&formatetc, &stgmedium);
  300. //
  301. // So far there are only two conditions in which we want to check for a multi select
  302. // 1. If the GetDataHere fails, then we should check to see if this is a mutli
  303. // select case.
  304. // 2. If GetDataHere succeeded but we got a specail cookie instead of a valid
  305. // SCE cookie we again want to call GetData to see if we have mutli select data
  306. // in the CDataObject.
  307. //
  308. if( FAILED(hRet) ||
  309. (formatetc.cfFormat == CDataObject::m_cfInternal &&
  310. IS_SPECIAL_COOKIE( ((INTERNAL *)stgmedium.hGlobal)->m_cookie) ) ) {
  311. GlobalFree(stgmedium.hGlobal);
  312. //
  313. // See if this data object is a mutli select.
  314. //
  315. ZeroMemory(&formatetc, sizeof(FORMATETC));
  316. formatetc.tymed = TYMED_HGLOBAL;
  317. formatetc.cfFormat = (CLIPFORMAT)::RegisterClipboardFormat( CCF_MULTI_SELECT_SNAPINS );
  318. stgmedium.hGlobal = NULL;
  319. if( FAILED(hRet )){
  320. //
  321. // If get data here failed, then try to get the information by calling GetData.
  322. // In multi select mode we get a data object to the snapins that have the data objects.
  323. //
  324. if( SUCCEEDED( lpDataObject->GetData(&formatetc, &stgmedium) ) ){
  325. SMMCDataObjects *pObjects = (SMMCDataObjects *)GlobalLock( stgmedium.hGlobal );
  326. if(pObjects && pObjects->count){
  327. lpDataObject = pObjects->lpDataObject[0];
  328. GlobalUnlock( stgmedium.hGlobal );
  329. if(lpDataObject){
  330. ReleaseStgMedium( &stgmedium );
  331. formatetc.cfFormat = (CLIPFORMAT)CDataObject::m_cfInternal;
  332. stgmedium.hGlobal = NULL;
  333. lpDataObject->GetData(&formatetc, &stgmedium);
  334. }
  335. }
  336. }
  337. } else {
  338. //
  339. // The data object is ours and a special cookie was recieved from GetDataHere.
  340. // this probably means that we have a mutli select, so look for it.
  341. //
  342. formatetc.cfFormat = (CLIPFORMAT)CDataObject::m_cfInternal;
  343. lpDataObject->GetData(&formatetc, &stgmedium);
  344. }
  345. }
  346. p = reinterpret_cast<TYPE*>(stgmedium.hGlobal);
  347. if (p == NULL)
  348. break;
  349. } while (FALSE);
  350. return p;
  351. }
  352. INTERNAL* ExtractInternalFormat(LPDATAOBJECT lpDataObject)
  353. {
  354. return Extract<INTERNAL>(lpDataObject, (CLIPFORMAT) CDataObject::m_cfInternal);
  355. }
  356. GUID* ExtractNodeType(LPDATAOBJECT lpDataObject)
  357. {
  358. return Extract<GUID>(lpDataObject, (CLIPFORMAT)CDataObject::m_cfNodeType);
  359. }
  360. PWSTR ExtractMachineName(LPDATAOBJECT lpDataObject, CLIPFORMAT cf)
  361. {
  362. if ( lpDataObject == NULL ) {
  363. return NULL;
  364. }
  365. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL};
  366. FORMATETC formatetc = { cf, NULL,
  367. DVASPECT_CONTENT, -1, TYMED_HGLOBAL
  368. };
  369. //
  370. // Allocate memory for the stream
  371. //
  372. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, (MAX_PATH+1)*sizeof(WCHAR));
  373. //
  374. // Attempt to get data from the object
  375. //
  376. HRESULT hr = S_FALSE;
  377. PWSTR p=NULL;
  378. do {
  379. if (stgmedium.hGlobal == NULL)
  380. break;
  381. if (FAILED(lpDataObject->GetDataHere(&formatetc, &stgmedium))) {
  382. GlobalFree(stgmedium.hGlobal);
  383. break;
  384. }
  385. p = reinterpret_cast<WCHAR*>(stgmedium.hGlobal);
  386. if (p == NULL)
  387. break;
  388. } while (FALSE);
  389. return p;
  390. }
  391. /////////////////////////////////////////////////////////////////////////////
  392. // CSnapin's IComponent implementation
  393. //+--------------------------------------------------------------------------------------
  394. // CSnapin::GetResultViewType
  395. //
  396. // Since we need to display an HTML file for the error message, we check for errors
  397. // in this function.
  398. //
  399. // If there is some error, this function writes a temporary HTML file, and sets
  400. // the view type to an HTML file.
  401. //
  402. // Arguments: [cookie] - The cookie associated with the scope pane item being
  403. // displyaed.
  404. // [ppViewType] - The type of view we want.
  405. // [pViewOptions] - The options for the view.
  406. //
  407. // Returns: S_OK - We want MMC to display the specifide view type.
  408. //---------------------------------------------------------------------------------------
  409. STDMETHODIMP CSnapin::GetResultViewType(MMC_COOKIE cookie, LPOLESTR* ppViewType,
  410. LONG* pViewOptions)
  411. {
  412. #define pComponentImpl reinterpret_cast<CComponentDataImpl *>(m_pComponentData)
  413. CFolder *pFolder = reinterpret_cast<CFolder *>(cookie);
  414. CString sHtmlFile;
  415. FOLDER_TYPES fType = STATIC;
  416. HRESULT hr=S_OK;
  417. //
  418. // Delete the old temporary file.
  419. //
  420. if( !pComponentImpl->m_strTempFile.IsEmpty() ){
  421. DeleteFile( pComponentImpl->m_strTempFile );
  422. }
  423. //
  424. // What kind of error do we want to display.
  425. //
  426. if( pFolder ){
  427. fType = pFolder->GetType();
  428. } else {
  429. switch( GetImplType() ){
  430. case SCE_IMPL_TYPE_SAV:
  431. fType = ANALYSIS;
  432. break;
  433. }
  434. }
  435. //
  436. // Errors supported. We have to create an html file and set sHtmlFile to a
  437. // valid source if we want an error to be displayed.
  438. //
  439. CWriteHtmlFile ht;
  440. switch(fType){
  441. case LOCATIONS:
  442. //
  443. // Need to check Location areas for permissions, and to see if it exists at all.
  444. //
  445. pFolder->GetDisplayName( sHtmlFile, 0 );
  446. //
  447. // Set the current working directory.
  448. //
  449. if( !SetCurrentDirectory( sHtmlFile ) ){
  450. //
  451. // Get the error message and write the HTML file.
  452. //
  453. LPTSTR pszMsg;
  454. FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  455. NULL,
  456. GetLastError(),
  457. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT ),
  458. (LPTSTR)&pszMsg,
  459. 0,
  460. NULL
  461. );
  462. ht.Create();
  463. ht.Write(IDS_BAD_LOCATION);
  464. if(pszMsg){
  465. ht.Write(pszMsg);
  466. LocalFree(pszMsg);
  467. }
  468. pFolder->SetState( CFolder::state_InvalidTemplate );
  469. } else {
  470. pFolder->SetState( 0, ~CFolder::state_InvalidTemplate );
  471. }
  472. break;
  473. case LOCALPOL_ACCOUNT:
  474. case LOCALPOL_LOCAL:
  475. case LOCALPOL_EVENTLOG:
  476. case LOCALPOL_PASSWORD:
  477. case LOCALPOL_KERBEROS:
  478. case LOCALPOL_LOCKOUT:
  479. case LOCALPOL_AUDIT:
  480. case LOCALPOL_OTHER:
  481. case LOCALPOL_LOG:
  482. case LOCALPOL_PRIVILEGE:
  483. //
  484. // Load the sad info.
  485. //
  486. pComponentImpl->LoadSadInfo(FALSE);
  487. break;
  488. case PROFILE:
  489. //
  490. // Template error messages.
  491. //
  492. if(pFolder->GetModeBits() & MB_NO_NATIVE_NODES ){
  493. break;
  494. }
  495. if( pFolder->GetState() & CFolder::state_Unknown ){
  496. // We must load the template and find out if it is a valid
  497. // configuration template.
  498. if(!GetTemplate( pFolder->GetInfFile(), AREA_USER_SETTINGS)){
  499. pFolder->SetState( CFolder::state_InvalidTemplate, ~CFolder::state_Unknown );
  500. } else {
  501. pFolder->SetState( 0, ~CFolder::state_Unknown );
  502. }
  503. }
  504. if( pFolder->GetState() & CFolder::state_InvalidTemplate ){
  505. ht.Create();
  506. ht.Write( IDS_ERROR_CANT_OPEN_PROFILE );
  507. }
  508. break;
  509. case ANALYSIS:
  510. //
  511. // Analysis Error messages.
  512. //
  513. if( pComponentImpl->m_bIsLocked ){
  514. //
  515. // We are configuring or analyzing the database
  516. //
  517. ht.Create();
  518. ht.Write( IDS_ERROR_ANALYSIS_LOCKED );
  519. } else if( pComponentImpl->SadName.IsEmpty() ){
  520. //
  521. // Display the start screen.
  522. //
  523. ht.Create();
  524. ht.Write( IDS_HTML_OPENDATABASE );
  525. } else if( pComponentImpl->m_dwFlags & CComponentDataImpl::flag_showLogFile &&
  526. pComponentImpl->GetErroredLogFile() ){
  527. //
  528. // Display the error log file.
  529. //
  530. ht.Create();
  531. ht.Write( L"<B>" );
  532. ht.Write( IDS_VIEW_LOGFILE_TITLE );
  533. ht.Write( pComponentImpl->GetErroredLogFile() );
  534. ht.Write( L"</B><BR>" );
  535. ht.CopyTextFile( pComponentImpl->GetErroredLogFile(), pComponentImpl->m_ErroredLogPos );
  536. } else if( SCESTATUS_SUCCESS != pComponentImpl->SadErrored ){
  537. ht.Create();
  538. ht.Write( L"<B>%s</B><BR><BR>", (LPCTSTR)pComponentImpl->SadName );
  539. //
  540. // This block of code will be removed as soon the engine returns us
  541. // a more useful error message if the database does not contain sad info.
  542. //
  543. WIN32_FIND_DATA fd;
  544. HANDLE handle = FindFirstFile( pComponentImpl->SadName, &fd );
  545. if(handle != INVALID_HANDLE_VALUE){
  546. FindClose(handle);
  547. if( pComponentImpl->SadErrored == SCESTATUS_PROFILE_NOT_FOUND ){
  548. ht.Write( IDS_DBERR5_NO_ANALYSIS );
  549. } else {
  550. goto write_normal_error;
  551. }
  552. } else {
  553. write_normal_error:
  554. CString str;
  555. FormatDBErrorMessage( pComponentImpl->SadErrored, NULL, str);
  556. ht.Write( str );
  557. }
  558. }
  559. break;
  560. }
  561. DWORD dwSize = ht.GetFileName(NULL, 0);
  562. if(dwSize){
  563. //
  564. // We want to display an HTML file.
  565. //
  566. *ppViewType = (LPOLESTR)LocalAlloc( 0, sizeof(TCHAR) * (dwSize + 1));
  567. if(!*ppViewType){
  568. ht.Close( TRUE );
  569. goto normal;
  570. }
  571. ht.GetFileName( (LPTSTR)*ppViewType, dwSize + 1);
  572. pComponentImpl->m_strTempFile = *ppViewType;
  573. *pViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  574. } else {
  575. normal:
  576. //
  577. // Normal list view.
  578. //
  579. *ppViewType = NULL;
  580. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  581. //
  582. // S_FALSE means normal list view, S_OK means HTML or OCX
  583. //
  584. hr = S_FALSE;
  585. if(pFolder) {
  586. //
  587. // For mutli select, just add, or remove the case to enable multi select for a folder
  588. //
  589. switch( pFolder->GetType() ){
  590. case AREA_REGISTRY:
  591. case AREA_FILESTORE:
  592. case AREA_GROUPS:
  593. case AREA_GROUPS_ANALYSIS:
  594. *pViewOptions = MMC_VIEW_OPTIONS_MULTISELECT;
  595. break;
  596. }
  597. }
  598. }
  599. return hr;
  600. #undef pComponentImpl
  601. }
  602. STDMETHODIMP CSnapin::Initialize(LPCONSOLE lpConsole)
  603. {
  604. ASSERT(lpConsole != NULL);
  605. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  606. // Save the IConsole pointer
  607. m_pConsole = lpConsole;
  608. m_pConsole->AddRef();
  609. // Load resource strings
  610. LoadResources();
  611. // QI for a IHeaderCtrl
  612. HRESULT hr = m_pConsole->QueryInterface(IID_IHeaderCtrl,
  613. reinterpret_cast<void**>(&m_pHeader));
  614. // Give the console the header control interface pointer
  615. if (SUCCEEDED(hr)) {
  616. m_pConsole->SetHeader(m_pHeader);
  617. }
  618. if (!SUCCEEDED(m_pConsole->GetMainWindow(&m_hwndParent))) {
  619. m_pConsole->Release();
  620. return E_FAIL;
  621. }
  622. m_pConsole->QueryInterface(IID_IResultData,
  623. reinterpret_cast<void**>(&m_pResult));
  624. hr = m_pConsole->QueryResultImageList(&m_pImageResult);
  625. ASSERT(hr == S_OK);
  626. hr = m_pConsole->QueryConsoleVerb(&m_pConsoleVerb);
  627. ASSERT(hr == S_OK);
  628. return S_OK;
  629. }
  630. STDMETHODIMP CSnapin::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  631. {
  632. HRESULT hr = S_FALSE;
  633. MMC_COOKIE cookie;
  634. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  635. if (event == MMCN_PROPERTY_CHANGE) {
  636. hr = OnPropertyChange(lpDataObject);
  637. } else if (event == MMCN_VIEW_CHANGE) {
  638. hr = OnUpdateView(lpDataObject,arg,param);
  639. } else {
  640. INTERNAL* pInternal = NULL;
  641. switch (event) {
  642. case MMCN_COLUMNS_CHANGED:
  643. hr = S_FALSE;
  644. break;
  645. case MMCN_ACTIVATE:
  646. break;
  647. case MMCN_CLICK:
  648. case MMCN_DBLCLICK:
  649. break;
  650. case MMCN_SHOW:
  651. // pass a file name and file handle
  652. pInternal = ExtractInternalFormat(lpDataObject);
  653. if (pInternal == NULL) {
  654. // Actually looking for our extension
  655. return S_OK;
  656. }
  657. hr = OnShow(lpDataObject,pInternal->m_cookie, arg, param);
  658. break;
  659. case MMCN_MINIMIZED:
  660. pInternal = ExtractInternalFormat(lpDataObject);
  661. if (pInternal == NULL) {
  662. // Actually looking for our extension
  663. return S_OK;
  664. }
  665. hr = OnMinimize(pInternal->m_cookie, arg, param);
  666. break;
  667. case MMCN_SELECT:
  668. pInternal = ExtractInternalFormat(lpDataObject);
  669. if (pInternal == NULL) {
  670. // Actually looking for our extension
  671. return S_OK;
  672. }
  673. HandleStandardVerbs(arg, lpDataObject);
  674. break;
  675. case MMCN_BTN_CLICK:
  676. break;
  677. case MMCN_ADD_IMAGES: {
  678. InitializeBitmaps(NULL);
  679. break;
  680. }
  681. case MMCN_SNAPINHELP:
  682. case MMCN_CONTEXTHELP: {
  683. CString strTopic;
  684. CString strPath;
  685. LPTSTR szPath;
  686. LPDISPLAYHELP pDisplayHelp;
  687. pInternal = ExtractInternalFormat(lpDataObject);
  688. if (pInternal == NULL) {
  689. // Actually looking for our extension
  690. return S_OK;
  691. }
  692. hr = m_pConsole->QueryInterface(IID_IDisplayHelp,
  693. reinterpret_cast<void**>(&pDisplayHelp));
  694. ASSERT(hr == S_OK);
  695. if (SUCCEEDED(hr)) {
  696. szPath = strPath.GetBuffer(MAX_PATH);
  697. ::GetWindowsDirectory(szPath,MAX_PATH);
  698. strPath.ReleaseBuffer();
  699. FOLDER_TYPES type = ((CFolder *)pInternal->m_cookie)->GetType(); //Yanggao 1/31/2001 Bug258658
  700. switch (((CComponentDataImpl*)m_pComponentData)->GetImplType()) {
  701. case SCE_IMPL_TYPE_SCE:
  702. strTopic.LoadString(IDS_HTMLHELP_SCE_TOPIC);
  703. break;
  704. case SCE_IMPL_TYPE_SAV:
  705. strTopic.LoadString(IDS_HTMLHELP_SCM_TOPIC);
  706. break;
  707. case SCE_IMPL_TYPE_EXTENSION:
  708. {
  709. // Raid #258658. 4/10/2001, Go to different .chm for security policy.
  710. CFolder* pFolder = (CFolder *) pInternal->m_cookie;
  711. DWORD tempmode = pFolder->GetMode();
  712. if( SCE_MODE_LOCAL_COMPUTER == tempmode ||
  713. SCE_MODE_LOCAL_USER == tempmode )
  714. {
  715. strTopic.LoadString(IDS_HTMLHELP_LPPOLICY_TOPIC);
  716. }
  717. else
  718. {
  719. strTopic.LoadString(IDS_HTMLHELP_POLICY_TOPIC);
  720. }
  721. break;
  722. }
  723. case SCE_IMPL_TYPE_LS:
  724. strTopic.LoadString(IDS_HTMLHELP_LS_TOPIC);
  725. default:
  726. ASSERT(0);
  727. }
  728. strPath += strTopic;
  729. szPath = (LPTSTR)CoTaskMemAlloc(sizeof(LPTSTR) * (strPath.GetLength()+1));
  730. if (szPath) {
  731. lstrcpy(szPath,strPath);
  732. hr = pDisplayHelp->ShowTopic(T2OLE((LPWSTR)(LPCWSTR)szPath));
  733. }
  734. pDisplayHelp->Release();
  735. }
  736. break;
  737. }
  738. case MMCN_DELETE:
  739. // add for delete operations
  740. // AfxMessageBox(_T("CSnapin::MMCN_DELETE"));
  741. pInternal = ExtractInternalFormat(lpDataObject);
  742. if (pInternal == NULL) {
  743. // Actually looking for our extension
  744. return S_OK;
  745. }
  746. OnDeleteObjects(lpDataObject,
  747. CCT_RESULT,
  748. pInternal->m_cookie,
  749. arg,
  750. param);
  751. break;
  752. case MMCN_RENAME:
  753. //AfxMessageBox(_T("CSnapin::MMCN_RENAME\n"));
  754. break;
  755. case MMCN_PASTE:
  756. // OnPasteArea(pFolder->GetInfFile(),pFolder->GetType());
  757. break;
  758. case MMCN_QUERY_PASTE:
  759. break;
  760. // Note - Future expansion of notify types possible
  761. default: {
  762. }
  763. hr = E_UNEXPECTED;
  764. break;
  765. }
  766. if (pInternal) {
  767. FREE_INTERNAL(pInternal);
  768. }
  769. }
  770. // if (m_pResult)
  771. // m_pResult->SetDescBarText(_T("hello world"));
  772. return hr;
  773. }
  774. STDMETHODIMP CSnapin::Destroy(MMC_COOKIE cookie)
  775. {
  776. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  777. DeleteList(FALSE);
  778. // Release the interfaces that we QI'ed
  779. if (m_pConsole != NULL) {
  780. // Tell the console to release the header control interface
  781. m_pConsole->SetHeader(NULL);
  782. SAFE_RELEASE(m_pHeader);
  783. SAFE_RELEASE(m_pResult);
  784. SAFE_RELEASE(m_pImageResult);
  785. // Release the IConsole interface last
  786. SAFE_RELEASE(m_pConsole);
  787. SAFE_RELEASE(m_pComponentData); // QI'ed in IComponentDataImpl::CreateComponent
  788. SAFE_RELEASE(m_pConsoleVerb);
  789. }
  790. if (g_hDsSecDll) {
  791. FreeLibrary(g_hDsSecDll);
  792. g_hDsSecDll = NULL;
  793. }
  794. return S_OK;
  795. }
  796. STDMETHODIMP CSnapin::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type,
  797. LPDATAOBJECT* ppDataObject)
  798. {
  799. HRESULT hr = E_FAIL;
  800. // Delegate it to the IComponentData
  801. int iCnt = 0;
  802. if( cookie == (MMC_COOKIE)MMC_MULTI_SELECT_COOKIE ){
  803. RESULTDATAITEM ri;
  804. ZeroMemory( &ri, sizeof(RESULTDATAITEM));
  805. ri.mask = RDI_INDEX | RDI_STATE;
  806. ri.nIndex = -1;
  807. ri.nState = LVIS_SELECTED;
  808. BOOL bCreate = TRUE;
  809. while( m_pResult->GetNextItem(&ri) == S_OK){
  810. iCnt++;
  811. if( ri.bScopeItem ){
  812. //
  813. // will not allow actions to be performed on scope items.
  814. //
  815. bCreate = FALSE;
  816. break;
  817. }
  818. }
  819. if(bCreate){
  820. ri.nIndex = -1;
  821. if( m_pResult->GetNextItem(&ri) == S_OK){
  822. cookie = (MMC_COOKIE)ri.lParam;
  823. type = CCT_RESULT;
  824. CComObject<CDataObject>* pObject;
  825. hr = CComObject<CDataObject>::CreateInstance(&pObject);
  826. if (!SUCCEEDED(hr)) {
  827. return hr;
  828. }
  829. ASSERT(pObject != NULL);
  830. if (NULL == pObject) {
  831. return E_FAIL;
  832. }
  833. pObject->SetClsid( reinterpret_cast<CComponentDataImpl *>(m_pComponentData)->GetCoClassID() );
  834. if(m_pSelectedFolder){
  835. pObject->SetFolderType( m_pSelectedFolder->GetType() );
  836. }
  837. do {
  838. pObject->AddInternal( (MMC_COOKIE)ri.lParam, CCT_RESULT );
  839. } while( m_pResult->GetNextItem(&ri) == S_OK );
  840. return pObject->QueryInterface(IID_IDataObject,
  841. reinterpret_cast<void**>(ppDataObject));
  842. }
  843. }
  844. }
  845. ASSERT(m_pComponentData != NULL);
  846. return m_pComponentData->QueryDataObject(cookie, type, ppDataObject);
  847. }
  848. /////////////////////////////////////////////////////////////////////////////
  849. // CSnapin's implementation specific members
  850. DEBUG_DECLARE_INSTANCE_COUNTER(CSnapin);
  851. CSnapin::CSnapin()
  852. {
  853. DEBUG_INCREMENT_INSTANCE_COUNTER(CSnapin);
  854. CSnapin::lDataObjectRefCount = 0;
  855. RegisterCheckListWndClass();
  856. Construct();
  857. }
  858. CSnapin::~CSnapin()
  859. {
  860. #if DBG==1
  861. ASSERT(dbg_cRef == 0);
  862. #endif
  863. DEBUG_DECREMENT_INSTANCE_COUNTER(CSnapin);
  864. SAFE_RELEASE(m_pToolbar1);
  865. SAFE_RELEASE(m_pToolbar2);
  866. SAFE_RELEASE(m_pControlbar);
  867. SAFE_RELEASE(m_pConsoleVerb);
  868. SAFE_RELEASE(m_pImageResult);
  869. // Make sure the interfaces have been released
  870. ASSERT(m_pConsole == NULL);
  871. ASSERT(m_pHeader == NULL);
  872. ASSERT(m_pToolbar1 == NULL);
  873. ASSERT(m_pToolbar2 == NULL);
  874. delete m_pbmpToolbar1;
  875. delete m_pbmpToolbar2;
  876. if (m_szAnalTimeStamp) {
  877. LocalFree(m_szAnalTimeStamp);
  878. m_szAnalTimeStamp = NULL;
  879. }
  880. Construct();
  881. //If don't save template, CSnapin::lDataObjectRefCount will be 1 here.
  882. ASSERT(CSnapin::lDataObjectRefCount == 0 || CSnapin::lDataObjectRefCount == 1);
  883. }
  884. void CSnapin::Construct()
  885. {
  886. #if DBG==1
  887. dbg_cRef = 0;
  888. #endif
  889. m_pConsole = NULL;
  890. m_pHeader = NULL;
  891. m_pResult = NULL;
  892. m_pImageResult = NULL;
  893. m_pComponentData = NULL;
  894. m_pToolbar1 = NULL;
  895. m_pToolbar2 = NULL;
  896. m_pControlbar = NULL;
  897. m_pbmpToolbar1 = NULL;
  898. m_pbmpToolbar2 = NULL;
  899. m_pConsoleVerb = NULL;
  900. m_szAnalTimeStamp = NULL;
  901. m_pNotifier = NULL;
  902. m_hwndParent = 0;
  903. m_pSelectedFolder = NULL;
  904. m_nColumns = 0;
  905. }
  906. void CSnapin::LoadResources()
  907. {
  908. // Load strings from resources
  909. m_colName.LoadString(IDS_NAME);
  910. m_colDesc.LoadString(IDS_DESC);
  911. m_colAttr.LoadString(IDS_ATTR);
  912. m_colBaseAnalysis.LoadString(IDS_BASE_ANALYSIS);
  913. m_colBaseTemplate.LoadString(IDS_BASE_TEMPLATE);
  914. m_colLocalPol.LoadString(IDS_LOCAL_POLICY_COLUMN);
  915. m_colSetting.LoadString(IDS_SETTING);
  916. }
  917. //+--------------------------------------------------------------------------
  918. //
  919. // Function: GetDisplayInfo
  920. //
  921. // Synopsis: Get the string or icon to be displayed for a given result item
  922. //
  923. // Arguments: [pResult] - the result item to get display info for and the
  924. // type of information to be retrieved
  925. //
  926. // Returns: The information to be retrieved in the appropriate field of
  927. // pResult (str for strings, nImage for icons)
  928. //
  929. //---------------------------------------------------------------------------
  930. STDMETHODIMP CSnapin::GetDisplayInfo(RESULTDATAITEM *pResult)
  931. {
  932. CString str;
  933. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  934. ASSERT(pResult != NULL);
  935. m_strDisplay.Empty();
  936. LPTSTR szAlloc = NULL;
  937. if (pResult)
  938. {
  939. CString tmpstr;
  940. int npos = 0;
  941. CFolder* pFolder = 0;
  942. CString strIndent;
  943. if (pResult->bScopeItem == TRUE)
  944. {
  945. //
  946. // pResult is a scope item, not a result item
  947. //
  948. pFolder = reinterpret_cast<CFolder*>(pResult->lParam);
  949. if( pResult->mask & RDI_STR)
  950. {
  951. if( pFolder->GetDisplayName( m_strDisplay, pResult->nCol ) == ERROR_SUCCESS)
  952. {
  953. pResult->str = (LPOLESTR)(LPCTSTR)m_strDisplay;
  954. }
  955. }
  956. if ( pResult->mask & RDI_IMAGE )
  957. {
  958. pResult->nImage = pFolder->GetScopeItem()->nImage;
  959. }
  960. }
  961. else
  962. {
  963. CResult* pData = reinterpret_cast<CResult*>(pResult->lParam);
  964. pFolder = m_pSelectedFolder; //(CFolder*)(pData->GetCookie());
  965. if (pResult->mask & RDI_IMAGE)
  966. {
  967. //
  968. // queries the icon index
  969. //
  970. int nImage = GetResultImageIndex(pFolder,
  971. pData);
  972. pResult->nImage = nImage;
  973. }
  974. if( pResult->mask & RDI_STR )
  975. {
  976. if ( pFolder && pResult->nCol &&
  977. ( pFolder->GetType() == AREA_SERVICE ||
  978. pFolder->GetType() == AREA_SERVICE_ANALYSIS) )
  979. {
  980. //
  981. // service node
  982. //
  983. GetDisplayInfoForServiceNode(pResult, pFolder, pData);
  984. }
  985. else if ( pData->GetDisplayName( pFolder, m_strDisplay, pResult->nCol ) == ERROR_SUCCESS )
  986. {
  987. if( pData->GetID() == SCE_REG_DISPLAY_MULTISZ ) //Bug349000, Yang Gao, 2/23/2001
  988. {
  989. MultiSZToDisp(m_strDisplay, m_multistrDisplay);
  990. pResult->str = (LPOLESTR)(LPCTSTR)m_multistrDisplay;
  991. }
  992. else
  993. {
  994. pResult->str = (LPOLESTR)(LPCTSTR)m_strDisplay;
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. return S_OK;
  1001. }
  1002. /////////////////////////////////////////////////////////////////////////////
  1003. // IExtendContextMenu Implementation
  1004. STDMETHODIMP CSnapin::AddMenuItems(LPDATAOBJECT pDataObject,
  1005. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1006. LONG* pInsertionAllowed)
  1007. {
  1008. // if scope item, then call CComponentDataImpl.AddMenuItems
  1009. // else build menu item here for result items.
  1010. INTERNAL* pAllInternal = ExtractInternalFormat(pDataObject);
  1011. INTERNAL* pInternal = NULL;
  1012. CONTEXTMENUITEM cmi;
  1013. HRESULT hr = S_OK;
  1014. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1015. MMC_COOKIE cookie = NULL;
  1016. DATA_OBJECT_TYPES type = CCT_UNINITIALIZED;
  1017. pInternal = pAllInternal;
  1018. if (pAllInternal == NULL) {
  1019. return S_OK;
  1020. } else if(pAllInternal->m_cookie == (MMC_COOKIE)MMC_MULTI_SELECT_COOKIE){
  1021. //
  1022. // Currently we do not support any options except for delete if there is a mutli select.
  1023. // Remove the comment below to allow other menu items for the CCT_RESULT type.
  1024. //pInternal++;
  1025. }
  1026. if (CCT_RESULT == pInternal->m_type) {
  1027. #if defined(USE_SECURITY_VERB)
  1028. CResult *pResult;
  1029. //
  1030. // In the result pane add the Security... menu item
  1031. //
  1032. pResult = (CResult *)pInternal->m_cookie;
  1033. if (pResult && (pResult->GetType() != ITEM_OTHER)) {
  1034. //
  1035. // It's an editable type, so add the menu item
  1036. //
  1037. CString strSecurity;
  1038. CString strSecurityDesc;
  1039. strSecurity.LoadString(IDS_SECURITY_MENU_ITEM);
  1040. strSecurityDesc.LoadString(IDS_SECURITY_MENU_ITEM_DESC);
  1041. ZeroMemory(&cmi,sizeof(cmi));
  1042. cmi.strName = strSecurity.GetBuffer(0);;
  1043. cmi.strStatusBarText = strSecurityDesc.GetBuffer(0);
  1044. cmi.lCommandID = MMC_VERB_OPEN;
  1045. cmi.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  1046. cmi.fFlags = MF_ENABLED|MF_STRING;
  1047. cmi.fSpecialFlags = CCM_SPECIAL_DEFAULT_ITEM;
  1048. hr = pContextMenuCallback->AddItem(&cmi);
  1049. }
  1050. #endif
  1051. } else if(CCT_SCOPE == pInternal->m_type && (*pInsertionAllowed) & CCM_INSERTIONALLOWED_NEW ) {
  1052. //
  1053. // Insert menus for the scope item.
  1054. //
  1055. hr = ((CComponentDataImpl*)m_pComponentData)->AddMenuItems(pDataObject,
  1056. pContextMenuCallback, pInsertionAllowed);
  1057. }
  1058. FREE_INTERNAL(pAllInternal);
  1059. return hr;
  1060. }
  1061. STDMETHODIMP CSnapin::Command(long nCommandID, LPDATAOBJECT pDataObject)
  1062. {
  1063. // if scope item, then call CComponentDataImpl.AddMenuItems
  1064. // else build menu item here for result items.
  1065. INTERNAL* pAllInternal = ExtractInternalFormat(pDataObject);
  1066. INTERNAL* pInternal = NULL;
  1067. HRESULT hr=S_OK;
  1068. int iCnt = 1;
  1069. pInternal = pAllInternal;
  1070. if (pInternal == NULL) {
  1071. // Actually looking for our extension
  1072. return S_OK;
  1073. } else if( pInternal->m_cookie == MMC_MULTI_SELECT_COOKIE ){
  1074. iCnt = (int)pInternal->m_type;
  1075. pInternal++;
  1076. }
  1077. while( iCnt-- ){
  1078. hr = ((CComponentDataImpl*)m_pComponentData)->Command(nCommandID, pDataObject);
  1079. pInternal++;
  1080. }
  1081. if (pAllInternal) {
  1082. FREE_INTERNAL(pAllInternal);
  1083. }
  1084. return hr;
  1085. }
  1086. /////////////////////////////////////////////////////////////////////////////
  1087. // IExtendPropertySheet Implementation
  1088. STDMETHODIMP CSnapin::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  1089. LONG_PTR handle,
  1090. LPDATAOBJECT lpDataObject)
  1091. {
  1092. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1093. if (!lpDataObject || !lpProvider || !handle) {
  1094. return E_INVALIDARG;
  1095. }
  1096. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1097. if (!pInternal)
  1098. {
  1099. return E_UNEXPECTED;
  1100. }
  1101. if(pInternal->m_cookie == (MMC_COOKIE)MMC_MULTI_SELECT_COOKIE)
  1102. {
  1103. return S_FALSE;
  1104. }
  1105. else if (pInternal->m_type == CCT_RESULT)
  1106. {
  1107. return AddAttrPropPages(lpProvider,(CResult*)pInternal->m_cookie,handle);
  1108. }
  1109. return S_FALSE;
  1110. }
  1111. STDMETHODIMP CSnapin::QueryPagesFor(LPDATAOBJECT lpDataObject)
  1112. {
  1113. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1114. if (!lpDataObject) {
  1115. return E_INVALIDARG;
  1116. }
  1117. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1118. if (!pInternal) {
  1119. return E_UNEXPECTED;
  1120. }
  1121. if(pInternal->m_cookie == (MMC_COOKIE)MMC_MULTI_SELECT_COOKIE) {
  1122. //
  1123. // Don't currently support properties for multiselect or anything
  1124. //
  1125. return S_FALSE;
  1126. } else {
  1127. RESULT_TYPES type = ((CResult *)pInternal->m_cookie)->GetType();
  1128. if (ITEM_OTHER != type) {
  1129. return S_OK;
  1130. } else {
  1131. return S_FALSE;
  1132. }
  1133. }
  1134. return S_FALSE;
  1135. }
  1136. DWORD CComponentDataImpl::m_GroupMode = SCE_MODE_UNKNOWN;
  1137. ///////////////////////////////////////////////////////////////////////////////
  1138. // IComponentData implementation
  1139. DEBUG_DECLARE_INSTANCE_COUNTER(CComponentDataImpl);
  1140. CComponentDataImpl::CComponentDataImpl() :
  1141. m_computerModeBits (0),
  1142. m_userModeBits (0),
  1143. m_bEnumerateScopePaneCalled (false)
  1144. {
  1145. DEBUG_INCREMENT_INSTANCE_COUNTER(CComponentDataImpl);
  1146. m_pScope = NULL;
  1147. m_pConsole = NULL;
  1148. m_bIsDirty = FALSE;
  1149. m_bIsLocked = FALSE;
  1150. m_AnalFolder = NULL;
  1151. m_szSingleTemplateName = NULL;
  1152. m_bDeleteSingleTemplate = FALSE;
  1153. m_pUIThread = NULL;
  1154. m_pNotifier = NULL;
  1155. SadName.Empty();
  1156. SadLoaded = FALSE;
  1157. SadHandle = NULL;
  1158. SadErrored = SCESTATUS_PROFILE_NOT_FOUND;
  1159. SadTransStarted = FALSE;
  1160. m_pszErroredLogFile = NULL;
  1161. m_dwFlags = 0;
  1162. m_pGPTInfo = NULL;
  1163. m_pRSOPInfo = NULL;
  1164. m_pWMIRsop = NULL;
  1165. cfSceAccountArea = RegisterClipboardFormat(CF_SCE_ACCOUNT_AREA);
  1166. cfSceEventLogArea = RegisterClipboardFormat(CF_SCE_EVENTLOG_AREA);
  1167. cfSceLocalArea = RegisterClipboardFormat(CF_SCE_LOCAL_AREA);
  1168. cfSceGroupsArea = RegisterClipboardFormat(CF_SCE_GROUPS_AREA);
  1169. cfSceRegistryArea = RegisterClipboardFormat(CF_SCE_REGISTRY_AREA);
  1170. cfSceFileArea = RegisterClipboardFormat(CF_SCE_FILE_AREA);
  1171. cfSceServiceArea = RegisterClipboardFormat(CF_SCE_SERVICE_AREA);
  1172. InitializeCriticalSection(&csAnalysisPane);
  1173. }
  1174. CComponentDataImpl::~CComponentDataImpl()
  1175. {
  1176. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1177. DEBUG_DECREMENT_INSTANCE_COUNTER(CComponentDataImpl);
  1178. ASSERT(m_pScope == NULL);
  1179. //If don't save template, CSnapin::lDataObjectRefCount will be 1 here.
  1180. ASSERT(CSnapin::lDataObjectRefCount == 0 || CSnapin::lDataObjectRefCount == 1);
  1181. if( m_pszErroredLogFile )
  1182. {
  1183. LocalFree( m_pszErroredLogFile );
  1184. }
  1185. //
  1186. // NT5 only
  1187. //
  1188. if (m_szSingleTemplateName)
  1189. {
  1190. if (m_bDeleteSingleTemplate)
  1191. {
  1192. DeleteFile(m_szSingleTemplateName);
  1193. }
  1194. LocalFree(m_szSingleTemplateName);
  1195. }
  1196. // Delete templates.
  1197. POSITION pos = m_Templates.GetStartPosition();
  1198. PEDITTEMPLATE pTemplate;
  1199. CString strKey;
  1200. while (pos)
  1201. {
  1202. m_Templates.GetNextAssoc(pos,strKey,pTemplate);
  1203. if (pTemplate && pTemplate->pTemplate)
  1204. {
  1205. SceFreeProfileMemory(pTemplate->pTemplate);
  1206. pTemplate->pTemplate = NULL;
  1207. }
  1208. if (NULL != pTemplate)
  1209. {
  1210. delete pTemplate;
  1211. }
  1212. }
  1213. if (NULL != m_pUIThread)
  1214. {
  1215. delete m_pUIThread;
  1216. }
  1217. if( m_pNotifier ) //Memory leak, 4/27/2001
  1218. {
  1219. delete m_pNotifier;
  1220. }
  1221. // Delete column information structure.
  1222. pos = m_mapColumns.GetStartPosition();
  1223. FOLDER_TYPES fTypes;
  1224. while(pos)
  1225. {
  1226. PSCE_COLINFOARRAY pCols;
  1227. m_mapColumns.GetNextAssoc(pos, fTypes, pCols);
  1228. if (pCols)
  1229. {
  1230. LocalFree(pCols);
  1231. }
  1232. }
  1233. m_mapColumns.RemoveAll();
  1234. if (m_pWMIRsop)
  1235. {
  1236. delete m_pWMIRsop;
  1237. }
  1238. DeleteCriticalSection(&csAnalysisPane);
  1239. if ( m_pGPTInfo )
  1240. m_pGPTInfo->Release ();
  1241. }
  1242. STDMETHODIMP CComponentDataImpl::Initialize(LPUNKNOWN pUnknown)
  1243. {
  1244. ASSERT(pUnknown != NULL);
  1245. HRESULT hr;
  1246. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1247. AfxInitRichEdit();
  1248. m_pNotifier = new CHiddenWnd;
  1249. if (NULL == m_pNotifier) {
  1250. return E_FAIL;
  1251. }
  1252. // MMC should only call ::Initialize once!
  1253. ASSERT(m_pScope == NULL);
  1254. pUnknown->QueryInterface(IID_IConsoleNameSpace2,
  1255. reinterpret_cast<void**>(&m_pScope));
  1256. // add the images for the scope tree
  1257. CBitmap bmp16x16;
  1258. CBitmap bmp32x32;
  1259. LPIMAGELIST lpScopeImage;
  1260. hr = pUnknown->QueryInterface(IID_IConsole2, reinterpret_cast<void**>(&m_pConsole));
  1261. ASSERT(hr == S_OK);
  1262. hr = m_pConsole->QueryScopeImageList(&lpScopeImage);
  1263. //
  1264. // Create the hidden notifications window. This window is so that our
  1265. // secondary UI thread can post messages to the main thread which can
  1266. // then be forwarded on to the otherwise unmarshalled MMC COM interfaces.
  1267. //
  1268. // if (!m_pNotifier->Create(NULL,L"SCE Notifications Window",WS_OVERLAPPED,CRect(0,0,0,0),NULL,0)) {
  1269. if (!m_pNotifier->CreateEx(0,
  1270. AfxRegisterWndClass(0),
  1271. L"SCE Notifications Window",
  1272. 0,
  1273. 0,0,0,0,
  1274. 0,
  1275. 0,
  1276. 0)) {
  1277. m_pConsole->Release();
  1278. pUnknown->Release();
  1279. delete m_pNotifier;
  1280. m_pNotifier = NULL;
  1281. return E_FAIL;
  1282. }
  1283. m_pNotifier->SetConsole(m_pConsole);
  1284. m_pNotifier->SetComponentDataImpl(this);
  1285. ASSERT(hr == S_OK);
  1286. // Load the bitmaps from the dll
  1287. bmp16x16.LoadBitmap(IDB_ICON16 /*IDB_16x16 */);
  1288. bmp32x32.LoadBitmap(IDB_ICON32 /*IDB_32x32 */);
  1289. // Set the images
  1290. lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  1291. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp32x32)),
  1292. 0, RGB(255, 0, 255));
  1293. lpScopeImage->Release();
  1294. m_pUIThread = AfxBeginThread(RUNTIME_CLASS(CUIThread));
  1295. m_fSvcNotReady = FALSE;
  1296. m_nNewTemplateIndex = 0;
  1297. //
  1298. // Create the root folder list, If the root isn't created, then when the user
  1299. // right clicks to choose a database the menu command is not executed.
  1300. //
  1301. //
  1302. if(GetImplType() == SCE_IMPL_TYPE_SAV)
  1303. CreateFolderList( NULL, ROOT, NULL, NULL);
  1304. return S_OK;
  1305. }
  1306. STDMETHODIMP CComponentDataImpl::CreateComponent(LPCOMPONENT* ppComponent)
  1307. {
  1308. ASSERT(ppComponent != NULL);
  1309. CComObject<CSnapin>* pObject;
  1310. HRESULT hr = CComObject<CSnapin>::CreateInstance(&pObject);
  1311. if (!SUCCEEDED(hr))
  1312. return hr;
  1313. if (!SUCCEEDED(m_pConsole->GetMainWindow(&m_hwndParent)))
  1314. {
  1315. }
  1316. // Store IComponentData
  1317. pObject->SetIComponentData(this);
  1318. pObject->m_pUIThread = m_pUIThread;
  1319. pObject->m_pNotifier = m_pNotifier;
  1320. return pObject->QueryInterface(IID_IComponent,
  1321. reinterpret_cast<void**>(ppComponent));
  1322. }
  1323. STDMETHODIMP CComponentDataImpl::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  1324. {
  1325. ASSERT(m_pScope != NULL);
  1326. HRESULT hr = S_FALSE;
  1327. // CFolder* pFolder = NULL;
  1328. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1329. INTERNAL* pInternal = NULL;
  1330. // Since it's my folder it has an internal format.
  1331. // Design Note: for extension. I can use the fact, that the data object doesn't have
  1332. // my internal format and I should look at the node type and see how to extend it.
  1333. if (event == MMCN_PROPERTY_CHANGE) {
  1334. hr = OnProperties(param);
  1335. } else {
  1336. /*
  1337. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1338. if (pInternal == NULL) {
  1339. // Actually looking for our extension
  1340. return S_OK;
  1341. }
  1342. long cookie = pInternal->m_cookie;
  1343. FREE_INTERNAL(pInternal);
  1344. */
  1345. switch (event) {
  1346. case MMCN_DELETE:
  1347. hr = OnDelete(lpDataObject, arg, param);
  1348. break;
  1349. case MMCN_RENAME:
  1350. hr = OnRename(lpDataObject, arg, param);
  1351. break;
  1352. case MMCN_EXPAND:
  1353. hr = OnExpand(lpDataObject, arg, param);
  1354. break;
  1355. case MMCN_CONTEXTMENU:
  1356. hr = OnContextMenu(lpDataObject, arg, param);
  1357. break;
  1358. case MMCN_BTN_CLICK:
  1359. break;
  1360. case MMCN_SELECT: {
  1361. break;
  1362. }
  1363. case MMCN_PASTE: {
  1364. pInternal = ExtractInternalFormat(lpDataObject);
  1365. if (pInternal) {
  1366. MMC_COOKIE cookie = pInternal->m_cookie;
  1367. if ( cookie ) {
  1368. CFolder *pFolder = (CFolder*)cookie;
  1369. OnPasteArea(pFolder->GetInfFile(),pFolder->GetType());
  1370. }
  1371. }
  1372. break;
  1373. }
  1374. case MMCN_REMOVE_CHILDREN: {
  1375. if (NULL != m_pNotifier) {
  1376. m_pNotifier->DestroyWindow();
  1377. delete m_pNotifier;
  1378. m_pNotifier = NULL;
  1379. }
  1380. POSITION pos;
  1381. pos = m_scopeItemPopups.GetStartPosition();
  1382. LONG_PTR key;
  1383. CDialog *pDlg;
  1384. while (pos) {
  1385. m_scopeItemPopups.GetNextAssoc(pos,key,pDlg);
  1386. if(m_pUIThread){
  1387. m_pUIThread->PostThreadMessage(SCEM_DESTROY_DIALOG, (WPARAM)pDlg, 0);
  1388. }
  1389. m_scopeItemPopups.RemoveKey(key);
  1390. }
  1391. break;
  1392. }
  1393. default:
  1394. break;
  1395. }
  1396. }
  1397. return hr;
  1398. }
  1399. STDMETHODIMP CComponentDataImpl::Destroy()
  1400. {
  1401. // Delete enumerated scope items
  1402. // close profile handle if it is open
  1403. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1404. //
  1405. // Free the account type name list.
  1406. //
  1407. CGetUser::GetAccountType(NULL);
  1408. if(!m_strTempFile.IsEmpty()){
  1409. DeleteFile( m_strTempFile );
  1410. }
  1411. {
  1412. CSaveTemplates pSaveTemplate;
  1413. POSITION pos;
  1414. PEDITTEMPLATE pTemplate;
  1415. CString strKey;
  1416. int nDirty;
  1417. //
  1418. // Bug #197054:
  1419. //
  1420. // Offer to save dirty templates before reporting if the console
  1421. // itself is dirty and giving users a chance to save that. If
  1422. // we only save the templates when we save the console then users
  1423. // can unknowingly decide not to save changes to the console and
  1424. // discard all of their changes to the templates
  1425. //
  1426. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1427. nDirty = 0;
  1428. if (GetModeBits() & MB_TEMPLATE_EDITOR) {
  1429. pos = m_Templates.GetStartPosition();
  1430. while (pos) {
  1431. m_Templates.GetNextAssoc(pos,strKey,pTemplate);
  1432. if (pTemplate->IsDirty() && !pTemplate->QueryNoSave()) {
  1433. pSaveTemplate.AddTemplate(strKey,pTemplate);
  1434. nDirty++;
  1435. }
  1436. }
  1437. if (nDirty)
  1438. {
  1439. CThemeContextActivator activator;
  1440. if (-1 == pSaveTemplate.DoModal())
  1441. {
  1442. CString str;
  1443. str.LoadString(IDS_ERROR_CANT_SAVE);
  1444. AfxMessageBox(str);
  1445. }
  1446. }
  1447. } else if (GetModeBits() & MB_ANALYSIS_VIEWER) {
  1448. pTemplate = GetTemplate(GT_COMPUTER_TEMPLATE);
  1449. if (pTemplate && pTemplate->IsDirty()) {
  1450. if (IDYES == AfxMessageBox(IDS_SAVE_DATABASE,MB_YESNO)) {
  1451. pTemplate->Save();
  1452. }
  1453. }
  1454. }
  1455. }
  1456. DeleteList();
  1457. SAFE_RELEASE(m_pScope);
  1458. SAFE_RELEASE(m_pConsole);
  1459. if ( SadHandle ) {
  1460. if ( SadTransStarted ) {
  1461. EngineRollbackTransaction();
  1462. SadTransStarted = FALSE;
  1463. }
  1464. EngineCloseProfile(&SadHandle);
  1465. SadHandle = NULL;
  1466. }
  1467. if (g_hDsSecDll) {
  1468. FreeLibrary(g_hDsSecDll);
  1469. g_hDsSecDll = NULL;
  1470. }
  1471. return S_OK;
  1472. }
  1473. STDMETHODIMP CComponentDataImpl::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  1474. {
  1475. HRESULT hr;
  1476. ASSERT(ppDataObject != NULL);
  1477. CComObject<CDataObject>* pObject;
  1478. hr = CComObject<CDataObject>::CreateInstance(&pObject);
  1479. if (!SUCCEEDED(hr)) {
  1480. return hr;
  1481. }
  1482. if (NULL == pObject) {
  1483. return E_FAIL;
  1484. }
  1485. // Save cookie and type for delayed rendering
  1486. CFolder *pFolder;
  1487. LPSCESVCATTACHMENTDATA pAttachData;
  1488. pObject->SetType(type);
  1489. pObject->SetCookie(cookie);
  1490. //
  1491. // Store the coclass with the data object
  1492. //
  1493. pObject->SetClsid(GetCoClassID());
  1494. if (cookie && (CCT_SCOPE == type)) {
  1495. pFolder = (CFolder *) cookie;
  1496. pObject->SetFolderType(pFolder->GetType());
  1497. if ((AREA_SERVICE == pFolder->GetType()) ||
  1498. (AREA_SERVICE_ANALYSIS == pFolder->GetType())) {
  1499. InternalAddRef();
  1500. pObject->SetSceSvcAttachmentData(this);
  1501. }
  1502. pObject->SetMode(pFolder->GetMode());
  1503. pObject->SetModeBits(pFolder->GetModeBits());
  1504. pObject->SetGPTInfo(m_pGPTInfo);
  1505. pObject->SetRSOPInfo(m_pRSOPInfo);
  1506. }
  1507. return pObject->QueryInterface(IID_IDataObject,
  1508. reinterpret_cast<void**>(ppDataObject));
  1509. }
  1510. ///////////////////////////////////////////////////////////////////////////////
  1511. //// IPersistStream interface members
  1512. STDMETHODIMP CComponentDataImpl::GetClassID(CLSID *pClassID)
  1513. {
  1514. ASSERT(pClassID != NULL);
  1515. // Copy the CLSID for this snapin
  1516. *pClassID = GetCoClassID(); // CLSID_Snapin;
  1517. return E_NOTIMPL;
  1518. }
  1519. STDMETHODIMP CComponentDataImpl::IsDirty()
  1520. {
  1521. if (ThisIsDirty()) {
  1522. return S_OK;
  1523. }
  1524. return S_FALSE;
  1525. }
  1526. //+--------------------------------------------------------------------------
  1527. // CComponentDataImpl::Load
  1528. //
  1529. // Loads configuration saved information from the MMC stream.
  1530. // SAD:{%s} - The sad same, if any.
  1531. // LOGFILE:{%s}{%d} - The log file last used for the database,
  1532. // and the position the was last written to by this
  1533. // remembered snapin. If the user chooses not to save this
  1534. // information then, What is displayed will be out of date.
  1535. // SerializecolumnInfo() is called to create remembered column information.
  1536. //
  1537. // Arguments: [pStm] - The MMC stream to load from.
  1538. //
  1539. // Returns: S_OK - Always.
  1540. //
  1541. //---------------------------------------------------------------------------
  1542. STDMETHODIMP CComponentDataImpl::Load(IStream *pStm)
  1543. {
  1544. ASSERT(pStm);
  1545. //
  1546. // Read sad name.
  1547. //
  1548. LPTSTR szSadName = NULL;
  1549. if (0 < ReadSprintf(pStm,L"SAD:{%s}",&szSadName)) {
  1550. SadName = szSadName;
  1551. LocalFree(szSadName);
  1552. LoadSadInfo(TRUE);
  1553. }
  1554. //
  1555. // Read log file used and last position it was viewed from.
  1556. //
  1557. DWORD nPos;
  1558. if( 0 < ReadSprintf(pStm, L"LOGFILE:{%s}{%d}", &szSadName, &nPos) ){
  1559. SetErroredLogFile( szSadName, nPos);
  1560. LocalFree( szSadName );
  1561. }
  1562. SerializeColumnInfo( pStm, NULL, TRUE );
  1563. return S_OK;
  1564. }
  1565. //+--------------------------------------------------------------------------
  1566. // CComponentDataImpl::Save
  1567. //
  1568. // Saves configuration file information.
  1569. // SAD:{%s} - The sad same, if any.
  1570. // LOGFILE:{%s}{%d} - The log file last used for the database,
  1571. // and the position the was last written to by this
  1572. // remembered snapin. If the user chooses not to save this
  1573. // information then, What is displayed will be out of date.
  1574. // SerializecolumnInfo() is called to save column information.
  1575. //
  1576. // Arguments: [pStm] - The MMC stream to save to
  1577. //
  1578. // Returns: S_OK - Always.
  1579. //
  1580. //---------------------------------------------------------------------------
  1581. STDMETHODIMP CComponentDataImpl::Save(IStream *pStm, BOOL fClearDirty)
  1582. {
  1583. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1584. ASSERT(pStm);
  1585. if (!SadName.IsEmpty() && !IsSystemDatabase(SadName)) {
  1586. WriteSprintf(pStm,L"SAD:{%s}",(LPCTSTR)SadName);
  1587. }
  1588. if ( GetErroredLogFile() ){
  1589. LONG uPos = 0;
  1590. WriteSprintf(pStm, L"LOGFILE:{%s}{%d}", GetErroredLogFile(&uPos), uPos);
  1591. }
  1592. SerializeColumnInfo( pStm, NULL, FALSE );
  1593. if (fClearDirty) {
  1594. ClearDirty();
  1595. }
  1596. return S_OK;
  1597. }
  1598. //+--------------------------------------------------------------------------
  1599. // CComponentDataImpl::GetSizeMax
  1600. //
  1601. // Don't have a clue what the size will be of the string we want to save.
  1602. //
  1603. // Returns: S_OK - Always.
  1604. //
  1605. //---------------------------------------------------------------------------
  1606. STDMETHODIMP CComponentDataImpl::GetSizeMax(ULARGE_INTEGER *pcbSize)
  1607. {
  1608. return S_OK;
  1609. }
  1610. ///////////////////////////////////////////////////////////////////////////////
  1611. //// Notify handlers for IComponentData
  1612. HRESULT CComponentDataImpl::OnAdd(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param)
  1613. {
  1614. return E_UNEXPECTED;
  1615. }
  1616. HRESULT CComponentDataImpl::OnRename(LPDATAOBJECT lpDataObject,LPARAM arg, LPARAM param)
  1617. {
  1618. return E_UNEXPECTED;
  1619. }
  1620. //+--------------------------------------------------------------------------
  1621. //
  1622. // Method: OnExpand
  1623. //
  1624. // Synopsis: Expand a scope pane node and add its children folders
  1625. //
  1626. // Arguments: [lpDataObject] - The data object for the node we're expanding
  1627. // [arg] - Whether or not initialize has been called
  1628. // [param] - The id of the node we're expanding
  1629. //
  1630. //
  1631. // Modifies:
  1632. //
  1633. // History: 12-15-1997 Robcap
  1634. //
  1635. //---------------------------------------------------------------------------
  1636. HRESULT CComponentDataImpl::OnExpand(LPDATAOBJECT lpDataObject,
  1637. LPARAM arg,
  1638. LPARAM param)
  1639. {
  1640. CString strName;
  1641. CString strDesc;
  1642. DWORD dwMode = 0;
  1643. SCESTATUS scestatus = SCESTATUS_SUCCESS;
  1644. ASSERT(lpDataObject);
  1645. if ( lpDataObject == NULL )
  1646. return E_FAIL;
  1647. HRESULT hr = S_OK;
  1648. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1649. CFolder *pFolder = NULL;
  1650. if (pInternal == NULL)
  1651. {
  1652. //
  1653. // The node doesn't have our internal format, so we must be extending
  1654. // somebody else. Figure out who we are extending and what mode we are in
  1655. //
  1656. GUID* nodeType = ExtractNodeType(lpDataObject);
  1657. GUID guidMyComputer = structuuidNodetypeSystemTools;
  1658. dwMode = SCE_MODE_UNKNOWN;
  1659. if (!nodeType)
  1660. {
  1661. //
  1662. // This should never happen; nodeType should always be set here
  1663. //
  1664. ASSERT(FALSE);
  1665. return E_FAIL;
  1666. }
  1667. //
  1668. // MAX_PATH*5 is magic; GetDSPath and GetGPT path don't provide
  1669. // a direct way to find out how long a path is needed
  1670. //
  1671. TCHAR pszDSPath[MAX_PATH*5];
  1672. TCHAR pszGPTPath[MAX_PATH*5];
  1673. if (::IsEqualGUID(*nodeType,NODEID_Machine) ||
  1674. ::IsEqualGUID(*nodeType,NODEID_User))
  1675. {
  1676. //
  1677. // GPE Extension
  1678. //
  1679. hr = lpDataObject->QueryInterface(IID_IGPEInformation,
  1680. reinterpret_cast<void**>(&m_pGPTInfo));
  1681. if (SUCCEEDED(hr))
  1682. {
  1683. //
  1684. // get ds root path
  1685. //
  1686. DWORD dwSection = 0;
  1687. GROUP_POLICY_HINT_TYPE gpHint;
  1688. GROUP_POLICY_OBJECT_TYPE gpType;
  1689. //
  1690. // Give the GPT Information to the hidden notifications window so
  1691. // it can keep calls to it on this thread
  1692. //
  1693. m_pNotifier->SetGPTInformation(m_pGPTInfo);
  1694. hr = m_pGPTInfo->GetType(&gpType);
  1695. if ( SUCCEEDED(hr) )
  1696. {
  1697. switch ( gpType )
  1698. {
  1699. case GPOTypeLocal:
  1700. //
  1701. // We're editing a this machine's Policy, not Global Policy
  1702. //
  1703. if (::IsEqualGUID(*nodeType,NODEID_Machine))
  1704. {
  1705. //
  1706. // LPE Machine Node type
  1707. //
  1708. dwMode = SCE_MODE_LOCAL_COMPUTER;
  1709. ASSERT(m_pNotifier);
  1710. }
  1711. else
  1712. {
  1713. //
  1714. // LPE User Node type
  1715. //
  1716. dwMode = SCE_MODE_LOCAL_USER;
  1717. }
  1718. break;
  1719. case GPOTypeRemote:
  1720. //
  1721. // We're editing a remote machine's Policy
  1722. //
  1723. if (::IsEqualGUID(*nodeType,NODEID_Machine))
  1724. {
  1725. //
  1726. // LPE Machine Node type
  1727. //
  1728. dwMode = SCE_MODE_REMOTE_COMPUTER;
  1729. }
  1730. else
  1731. {
  1732. //
  1733. // LPE User Node type
  1734. //
  1735. dwMode = SCE_MODE_REMOTE_USER;
  1736. }
  1737. break;
  1738. default:
  1739. hr = m_pGPTInfo->GetHint(&gpHint);
  1740. if (SUCCEEDED(hr))
  1741. {
  1742. switch (gpHint)
  1743. {
  1744. case GPHintMachine:
  1745. case GPHintUnknown:
  1746. case GPHintDomain:
  1747. //
  1748. // We're editing Global Domain Policy
  1749. //
  1750. if (::IsEqualGUID(*nodeType,NODEID_Machine))
  1751. {
  1752. //
  1753. // GPE Machine Node type
  1754. //
  1755. dwMode = SCE_MODE_DOMAIN_COMPUTER;
  1756. }
  1757. else
  1758. {
  1759. //
  1760. // GPE User Node type
  1761. //
  1762. dwMode = SCE_MODE_DOMAIN_USER;
  1763. }
  1764. break;
  1765. case GPHintSite:
  1766. case GPHintOrganizationalUnit:
  1767. //
  1768. // We're editing Global Domain Policy
  1769. //
  1770. if (::IsEqualGUID(*nodeType,NODEID_Machine))
  1771. {
  1772. //
  1773. // GPE Machine Node type
  1774. //
  1775. dwMode = SCE_MODE_OU_COMPUTER;
  1776. }
  1777. else
  1778. {
  1779. //
  1780. // GPE User Node type
  1781. //
  1782. dwMode = SCE_MODE_OU_USER;
  1783. }
  1784. break;
  1785. default:
  1786. //
  1787. // Should never get here
  1788. //
  1789. ASSERT(FALSE);
  1790. break;
  1791. }
  1792. }
  1793. break;
  1794. }
  1795. //
  1796. // remember the root node's mode
  1797. //
  1798. m_Mode = dwMode;
  1799. m_GroupMode = dwMode;
  1800. switch (dwMode)
  1801. {
  1802. case SCE_MODE_DOMAIN_COMPUTER:
  1803. case SCE_MODE_OU_COMPUTER:
  1804. dwSection = GPO_SECTION_MACHINE;
  1805. break;
  1806. case SCE_MODE_LOCAL_COMPUTER:
  1807. //
  1808. // For local use the policy database rather than a template
  1809. //
  1810. break;
  1811. case SCE_MODE_REMOTE_COMPUTER:
  1812. case SCE_MODE_REMOTE_USER:
  1813. case SCE_MODE_LOCAL_USER:
  1814. case SCE_MODE_DOMAIN_USER:
  1815. case SCE_MODE_OU_USER:
  1816. //
  1817. // For now we don't support any native nodes in USER modes, so we
  1818. // don't need a template
  1819. //
  1820. break;
  1821. default:
  1822. break;
  1823. }
  1824. //
  1825. // Find the path to the SCE template within the GPT template
  1826. //
  1827. if (GPO_SECTION_MACHINE == dwSection)
  1828. {
  1829. //
  1830. // 156869 Default Domain and Default DC GPO's should only be modifiable on the FSMO PDC
  1831. //
  1832. TCHAR szGUID[MAX_PATH];
  1833. hr = m_pGPTInfo->GetName(szGUID,MAX_PATH);
  1834. if (SUCCEEDED(hr))
  1835. {
  1836. LPTSTR szDCGUID = TEXT("{") STR_DEFAULT_DOMAIN_CONTROLLER_GPO_GUID TEXT("}");
  1837. LPTSTR szDomGUID = TEXT("{") STR_DEFAULT_DOMAIN_GPO_GUID TEXT("}");
  1838. if ((0 == lstrcmpi(szGUID, szDCGUID)) || (0 == lstrcmpi(szGUID, szDomGUID)))
  1839. {
  1840. LPGROUPPOLICYOBJECT pGPO = NULL;
  1841. //
  1842. // Default Domain or Default DC GPO. Make sure we're talking to the PDC
  1843. //
  1844. TCHAR szDCName[MAX_PATH];
  1845. hr = lpDataObject->QueryInterface(IID_IGroupPolicyObject,(LPVOID*)&pGPO);
  1846. if (SUCCEEDED(hr))
  1847. {
  1848. hr = pGPO->GetMachineName(szDCName,MAX_PATH);
  1849. pGPO->Release();
  1850. }
  1851. if (SUCCEEDED(hr))
  1852. {
  1853. DOMAIN_CONTROLLER_INFO *dci = 0;
  1854. if (NO_ERROR != DsGetDcName(szDCName,NULL,NULL,NULL,DS_PDC_REQUIRED,&dci))
  1855. {
  1856. //
  1857. // We're not connected to the PDC (or we can't get info about who we're
  1858. // connected to, so assume the same
  1859. //
  1860. dwMode = SCE_MODE_DOMAIN_COMPUTER_ERROR;
  1861. }
  1862. if(dci)
  1863. NetApiBufferFree(dci);
  1864. }
  1865. else
  1866. dwMode = SCE_MODE_DOMAIN_COMPUTER_ERROR;
  1867. }
  1868. }
  1869. else
  1870. {
  1871. //
  1872. // Can't get the name of the DC we're talking to, so assume it's not the PDC
  1873. //
  1874. dwMode = SCE_MODE_DOMAIN_COMPUTER_ERROR;
  1875. }
  1876. //
  1877. // get GPT root path
  1878. //
  1879. hr = m_pGPTInfo->GetFileSysPath(dwSection,
  1880. pszGPTPath,
  1881. ARRAYSIZE(pszGPTPath));
  1882. if (SUCCEEDED(hr))
  1883. {
  1884. //
  1885. // Allocate memory for the pszGPTPath + <backslash> + GPTSCE_TEMPLATE + <trailing nul>
  1886. //
  1887. m_szSingleTemplateName = (LPTSTR) LocalAlloc(LPTR,(lstrlen(pszGPTPath)+lstrlen(GPTSCE_TEMPLATE)+2)*sizeof(TCHAR));
  1888. if (NULL != m_szSingleTemplateName)
  1889. {
  1890. lstrcpy(m_szSingleTemplateName,pszGPTPath);
  1891. lstrcat(m_szSingleTemplateName,L"\\" GPTSCE_TEMPLATE);
  1892. }
  1893. else
  1894. hr = E_OUTOFMEMORY;
  1895. }
  1896. }
  1897. else
  1898. {
  1899. //
  1900. // else user section
  1901. //
  1902. }
  1903. }
  1904. else
  1905. {
  1906. //
  1907. // can't get GPT path, error is in hr
  1908. ASSERT(FALSE);
  1909. //
  1910. }
  1911. }
  1912. else
  1913. {
  1914. //
  1915. // else error in hr
  1916. //
  1917. }
  1918. } else if (::IsEqualGUID(*nodeType,NODEID_RSOPMachine) ||
  1919. ::IsEqualGUID(*nodeType,NODEID_RSOPUser))
  1920. {
  1921. //
  1922. // RSOP Extension
  1923. //
  1924. if (::IsEqualGUID(*nodeType,NODEID_RSOPMachine))
  1925. {
  1926. //
  1927. // GPE Machine Node type
  1928. //
  1929. dwMode = SCE_MODE_RSOP_COMPUTER;
  1930. m_szSingleTemplateName = (LPTSTR) LocalAlloc(LPTR,(lstrlen(GT_RSOP_TEMPLATE)+1)*sizeof(TCHAR));
  1931. if (NULL != m_szSingleTemplateName)
  1932. lstrcpy(m_szSingleTemplateName,GT_RSOP_TEMPLATE);
  1933. else
  1934. hr = E_OUTOFMEMORY;
  1935. }
  1936. else
  1937. {
  1938. //
  1939. // GPE User Node type
  1940. //
  1941. dwMode = SCE_MODE_RSOP_USER;
  1942. }
  1943. hr = lpDataObject->QueryInterface(IID_IRSOPInformation,
  1944. reinterpret_cast<void**>(&m_pRSOPInfo));
  1945. }
  1946. else
  1947. {
  1948. //
  1949. // We should never get into this state
  1950. //
  1951. ASSERT(0);
  1952. hr = E_FAIL;
  1953. }
  1954. //
  1955. // free node type buffer
  1956. //
  1957. if (nodeType)
  1958. GlobalFree(nodeType);
  1959. if ( FAILED(hr) )
  1960. {
  1961. //
  1962. // free template buffer if allocated
  1963. //
  1964. if ( m_szSingleTemplateName )
  1965. LocalFree(m_szSingleTemplateName);
  1966. m_szSingleTemplateName = NULL;
  1967. return hr;
  1968. }
  1969. //
  1970. // As an extension snapin, the secedit root node should be added
  1971. //
  1972. pFolder = new CFolder();
  1973. ASSERT(pFolder);
  1974. if ( pFolder )
  1975. {
  1976. if (!pFolder->SetMode(dwMode))
  1977. {
  1978. //
  1979. // This should never happen; we should always have a valid dwMode by now
  1980. //
  1981. ASSERT(FALSE);
  1982. //
  1983. // remember to free the memory
  1984. //
  1985. delete pFolder;
  1986. return E_FAIL;
  1987. }
  1988. FOLDER_TYPES RootType = STATIC;
  1989. LPTSTR szInfFile = NULL;
  1990. DWORD* pdwModeBits = 0;
  1991. switch (m_Mode)
  1992. {
  1993. case SCE_MODE_DOMAIN_COMPUTER:
  1994. case SCE_MODE_OU_COMPUTER:
  1995. case SCE_MODE_LOCAL_COMPUTER:
  1996. case SCE_MODE_REMOTE_COMPUTER:
  1997. pdwModeBits = &m_computerModeBits;
  1998. break;
  1999. case SCE_MODE_REMOTE_USER:
  2000. case SCE_MODE_LOCAL_USER:
  2001. case SCE_MODE_DOMAIN_USER:
  2002. case SCE_MODE_OU_USER:
  2003. pdwModeBits = &m_userModeBits;
  2004. break;
  2005. default:
  2006. pdwModeBits = &m_computerModeBits;
  2007. break;
  2008. }
  2009. *pdwModeBits = pFolder->GetModeBits();
  2010. if (*pdwModeBits & MB_ANALYSIS_VIEWER)
  2011. {
  2012. strName.LoadString(IDS_ANALYSIS_VIEWER_NAME);
  2013. szInfFile = GT_COMPUTER_TEMPLATE;
  2014. RootType = ANALYSIS;
  2015. }
  2016. else if (*pdwModeBits & MB_TEMPLATE_EDITOR)
  2017. {
  2018. strName.LoadString(IDS_TEMPLATE_EDITOR_NAME);
  2019. RootType = CONFIGURATION;
  2020. }
  2021. else if (*pdwModeBits & MB_LOCAL_POLICY)
  2022. {
  2023. strName.LoadString(IDS_EXTENSION_NAME);
  2024. RootType = LOCALPOL;
  2025. }
  2026. else if (*pdwModeBits & MB_STANDALONE_NAME)
  2027. {
  2028. strName.LoadString(IDS_NODENAME);
  2029. RootType = STATIC;
  2030. }
  2031. else if (*pdwModeBits & MB_SINGLE_TEMPLATE_ONLY)
  2032. {
  2033. strName.LoadString(IDS_EXTENSION_NAME);
  2034. RootType = PROFILE;
  2035. szInfFile = m_szSingleTemplateName;
  2036. }
  2037. else if (*pdwModeBits & MB_NO_NATIVE_NODES)
  2038. {
  2039. strName.LoadString(IDS_EXTENSION_NAME);
  2040. RootType = PROFILE;
  2041. }
  2042. else
  2043. {
  2044. strName.LoadString(IDS_EXTENSION_NAME);
  2045. }
  2046. strDesc.LoadString(IDS_SECURITY_SETTING_DESC); // only GPE extensions get here
  2047. hr = pFolder->Create(strName, // Name
  2048. strDesc, // Description
  2049. szInfFile, // inf file name
  2050. SCE_IMAGE_IDX, // closed icon index
  2051. SCE_IMAGE_IDX, // open icon index
  2052. RootType, // folder type
  2053. TRUE, // has children
  2054. dwMode, // SCE Mode
  2055. NULL); // Extra Data
  2056. if (FAILED(hr))
  2057. {
  2058. delete pFolder;
  2059. return hr;
  2060. }
  2061. m_scopeItemList.AddTail(pFolder);
  2062. // Set the parent
  2063. pFolder->GetScopeItem()->mask |= SDI_PARENT;
  2064. pFolder->GetScopeItem()->relativeID = param;
  2065. // Set the folder as the cookie
  2066. pFolder->GetScopeItem()->mask |= SDI_PARAM;
  2067. pFolder->GetScopeItem()->lParam = reinterpret_cast<LPARAM>(pFolder);
  2068. pFolder->SetCookie(reinterpret_cast<MMC_COOKIE>(pFolder));
  2069. m_pScope->InsertItem(pFolder->GetScopeItem());
  2070. //
  2071. // Note - On return, the ID member of 'm_pScopeItem'
  2072. // contains the handle to the newly inserted item!
  2073. //
  2074. ASSERT(pFolder->GetScopeItem()->ID != NULL);
  2075. }
  2076. else
  2077. return E_OUTOFMEMORY;
  2078. return S_OK;
  2079. }
  2080. else
  2081. {
  2082. //
  2083. // Expanding one of our own nodes
  2084. MMC_COOKIE cookie = pInternal->m_cookie;
  2085. FREE_INTERNAL(pInternal);
  2086. if (arg != FALSE)
  2087. {
  2088. //
  2089. // Did Initialize get called?
  2090. //
  2091. ASSERT(m_pScope != NULL);
  2092. EnumerateScopePane(cookie, param);
  2093. }
  2094. }
  2095. return S_OK;
  2096. }
  2097. HRESULT CComponentDataImpl::OnSelect(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param)
  2098. {
  2099. return S_OK;
  2100. }
  2101. HRESULT CComponentDataImpl::OnContextMenu(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param)
  2102. {
  2103. return S_OK;
  2104. }
  2105. HRESULT CComponentDataImpl::OnProperties(LPARAM param)
  2106. {
  2107. if (param == NULL)
  2108. return S_OK;
  2109. ASSERT(param != NULL);
  2110. return S_OK;
  2111. }
  2112. void CComponentDataImpl::DeleteList()
  2113. {
  2114. POSITION pos = m_scopeItemList.GetHeadPosition();
  2115. while (pos)
  2116. delete m_scopeItemList.GetNext(pos);
  2117. }
  2118. CFolder* CComponentDataImpl::FindObject(MMC_COOKIE cookie, POSITION* thePos)
  2119. {
  2120. POSITION pos = m_scopeItemList.GetHeadPosition();
  2121. POSITION curPos;
  2122. CFolder* pFolder = NULL;
  2123. while (pos) {
  2124. curPos = pos;
  2125. // pos is already updated to the next item after this call
  2126. pFolder = m_scopeItemList.GetNext(pos);
  2127. //
  2128. // The first folder in the list belongs to cookie 0
  2129. //
  2130. if (!cookie || (pFolder == (CFolder *)cookie)) {
  2131. if ( thePos ) {
  2132. *thePos = curPos;
  2133. }
  2134. return pFolder;
  2135. }
  2136. }
  2137. if ( thePos ) {
  2138. *thePos = NULL;
  2139. }
  2140. return NULL;
  2141. }
  2142. STDMETHODIMP CComponentDataImpl::GetDisplayInfo(SCOPEDATAITEM* pScopeDataItem)
  2143. {
  2144. ASSERT(pScopeDataItem != NULL);
  2145. if (pScopeDataItem == NULL)
  2146. return E_POINTER;
  2147. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  2148. CFolder* pFolder = reinterpret_cast<CFolder*>(pScopeDataItem->lParam);
  2149. ASSERT(pScopeDataItem->mask & SDI_STR);
  2150. // MMC does not supprot call back on scope node image
  2151. if ( pScopeDataItem->mask & SDI_IMAGE ) {
  2152. //int nImage = GetScopeImageIndex(pFolder->GetType());
  2153. pScopeDataItem->nImage = pFolder->GetScopeItem()->nImage;
  2154. }
  2155. m_strDisplay.Empty();
  2156. if(pFolder){
  2157. pFolder->GetDisplayName(m_strDisplay, 0);
  2158. m_Mode = pFolder->GetMode(); //YangGao #332852 fix.
  2159. }
  2160. pScopeDataItem->displayname = (LPOLESTR)(LPCTSTR)m_strDisplay;
  2161. ASSERT(pScopeDataItem->displayname != NULL);
  2162. return S_OK;
  2163. }
  2164. STDMETHODIMP CComponentDataImpl::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  2165. {
  2166. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  2167. return E_POINTER;
  2168. // Make sure both data object are mine
  2169. HRESULT hr = S_FALSE;
  2170. INTERNAL *pA = ExtractInternalFormat(lpDataObjectA);
  2171. INTERNAL *pB = ExtractInternalFormat(lpDataObjectB);
  2172. if (pA != NULL && pB != NULL)
  2173. hr = (*pA == *pB) ? S_OK : S_FALSE;
  2174. FREE_INTERNAL(pA);
  2175. FREE_INTERNAL(pB);
  2176. return hr;
  2177. }
  2178. /////////////////////////////////////////////////////////////////////////////
  2179. // IExtendPropertySheet Implementation
  2180. STDMETHODIMP CComponentDataImpl::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  2181. LONG_PTR handle,
  2182. LPDATAOBJECT lpDataObject)
  2183. {
  2184. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  2185. if (!lpDataObject || !lpProvider || !handle) {
  2186. return E_INVALIDARG;
  2187. }
  2188. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  2189. if (!pInternal) {
  2190. return E_UNEXPECTED;
  2191. }
  2192. if(pInternal->m_cookie == (MMC_COOKIE)MMC_MULTI_SELECT_COOKIE) {
  2193. return S_FALSE;
  2194. } else if (pInternal->m_type == CCT_SCOPE) {
  2195. return AddAttrPropPages(lpProvider,(CFolder*)(pInternal->m_cookie),handle);
  2196. }
  2197. return S_FALSE;
  2198. }
  2199. STDMETHODIMP CComponentDataImpl::QueryPagesFor(LPDATAOBJECT lpDataObject)
  2200. {
  2201. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  2202. // Look at the data object and see if it an item in the scope pane
  2203. return IsScopePaneNode(lpDataObject) ? S_OK : S_FALSE;
  2204. }
  2205. BOOL CComponentDataImpl::IsScopePaneNode(LPDATAOBJECT lpDataObject)
  2206. {
  2207. BOOL bResult = FALSE;
  2208. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  2209. // taking out m_cookie == NULL, should check foldertype ???
  2210. if (pInternal->m_type == CCT_SCOPE) {
  2211. bResult = TRUE;
  2212. }
  2213. FREE_INTERNAL(pInternal);
  2214. return bResult;
  2215. }
  2216. ///////////////////////////////////////////////////////////////////////////////
  2217. // IExtendContextMenu implementation
  2218. //
  2219. BOOL LoadContextMenuResources(MENUMAP* pMenuMap)
  2220. {
  2221. HINSTANCE hInstance = _Module.GetModuleInstance();
  2222. for (int i = 0; pMenuMap->ctxMenu[i].strName; i++) {
  2223. if (0 == ::LoadString(hInstance, pMenuMap->dataRes[i].uResID, pMenuMap->dataRes[i].szBuffer, MAX_CONTEXT_MENU_STRLEN*2))
  2224. return FALSE;
  2225. pMenuMap->ctxMenu[i].strName = pMenuMap->dataRes[i].szBuffer;
  2226. for (WCHAR* pCh = pMenuMap->dataRes[i].szBuffer; (*pCh) != NULL; pCh++) {
  2227. if ( (*pCh) == L'\n') {
  2228. pMenuMap->ctxMenu[i].strStatusBarText = (pCh+1);
  2229. (*pCh) = NULL;
  2230. break;
  2231. }
  2232. }
  2233. }
  2234. return TRUE;
  2235. }
  2236. BOOL CComponentDataImpl::LoadResources()
  2237. {
  2238. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  2239. return
  2240. LoadContextMenuResources(CSecmgrNodeMenuHolder::GetMenuMap() ) &&
  2241. LoadContextMenuResources(CAnalyzeNodeMenuHolder::GetMenuMap()) &&
  2242. LoadContextMenuResources(CConfigNodeMenuHolder::GetMenuMap()) &&
  2243. LoadContextMenuResources(CLocationNodeMenuHolder::GetMenuMap()) &&
  2244. LoadContextMenuResources(CSSProfileNodeMenuHolder::GetMenuMap()) &&
  2245. LoadContextMenuResources(CRSOPProfileNodeMenuHolder::GetMenuMap()) &&
  2246. LoadContextMenuResources(CLocalPolNodeMenuHolder::GetMenuMap()) &&
  2247. LoadContextMenuResources(CProfileNodeMenuHolder::GetMenuMap()) &&
  2248. LoadContextMenuResources(CProfileAreaMenuHolder::GetMenuMap()) &&
  2249. LoadContextMenuResources(CProfileSubAreaMenuHolder::GetMenuMap()) &&
  2250. LoadContextMenuResources(CProfileSubAreaEventLogMenuHolder::GetMenuMap()) &&
  2251. LoadContextMenuResources(CAnalyzeAreaMenuHolder::GetMenuMap()) &&
  2252. LoadContextMenuResources(CAnalyzeGroupsMenuHolder::GetMenuMap()) &&
  2253. LoadContextMenuResources(CAnalyzeFilesMenuHolder::GetMenuMap()) &&
  2254. LoadContextMenuResources(CAnalyzeRegistryMenuHolder::GetMenuMap()) &&
  2255. LoadContextMenuResources(CProfileGroupsMenuHolder::GetMenuMap()) &&
  2256. LoadContextMenuResources(CProfileFilesMenuHolder::GetMenuMap()) &&
  2257. LoadContextMenuResources(CProfileRegistryMenuHolder::GetMenuMap()) &&
  2258. LoadContextMenuResources(CAnalyzeObjectsMenuHolder::GetMenuMap());
  2259. }
  2260. STDMETHODIMP CComponentDataImpl::AddMenuItems(LPDATAOBJECT pDataObject,
  2261. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  2262. LONG* pInsertionAllowed)
  2263. {
  2264. HRESULT hr = S_OK;
  2265. // Note - snap-ins need to look at the data object and determine
  2266. // in what context, menu items need to be added.
  2267. INTERNAL* pInternal = ExtractInternalFormat(pDataObject);
  2268. if (pInternal == NULL)
  2269. {
  2270. //
  2271. // Actually looking for our extension
  2272. //
  2273. return S_OK;
  2274. }
  2275. MMC_COOKIE cookie = pInternal->m_cookie;
  2276. LPCONTEXTMENUITEM pContextMenuItem=NULL;
  2277. CFolder *pFolder = NULL;
  2278. if ( NULL == cookie )
  2279. {
  2280. //
  2281. // root. IDS_ABOUT_SECMGR
  2282. //
  2283. //
  2284. // either analysis node, or configuration node
  2285. //
  2286. if ( ::IsEqualGUID(pInternal->m_clsid, CLSID_SAVSnapin) )
  2287. {
  2288. if ((NULL == SadHandle) && SadErrored != SCESTATUS_SUCCESS)
  2289. {
  2290. LoadSadInfo(TRUE);
  2291. }
  2292. pContextMenuItem = CAnalyzeNodeMenuHolder::GetContextMenuItem();
  2293. }
  2294. else if ( ::IsEqualGUID(pInternal->m_clsid, CLSID_SCESnapin) )
  2295. pContextMenuItem = CConfigNodeMenuHolder::GetContextMenuItem();
  2296. else if ( ::IsEqualGUID(pInternal->m_clsid, CLSID_LSSnapin) )
  2297. pContextMenuItem = CLocalPolNodeMenuHolder::GetContextMenuItem();
  2298. }
  2299. else
  2300. {
  2301. pFolder = (CFolder *)cookie;
  2302. FOLDER_TYPES type = pFolder->GetType(); //pInternal->m_foldertype;
  2303. switch (type)
  2304. {
  2305. case CONFIGURATION:
  2306. // IDS_ADD_LOCATION
  2307. pContextMenuItem = CConfigNodeMenuHolder::GetContextMenuItem();
  2308. break;
  2309. case LOCATIONS:
  2310. // IDS_NEW_PROFILE,
  2311. pContextMenuItem = CLocationNodeMenuHolder::GetContextMenuItem();
  2312. break;
  2313. case ANALYSIS:
  2314. // IDS_PROFILE_INFO
  2315. if ((NULL == SadHandle) && SadErrored != SCESTATUS_SUCCESS)
  2316. LoadSadInfo(TRUE);
  2317. pContextMenuItem = CAnalyzeNodeMenuHolder::GetContextMenuItem();
  2318. break;
  2319. case LOCALPOL:
  2320. if( !(pFolder->GetState() & CFolder::state_InvalidTemplate))
  2321. pContextMenuItem = CLocalPolNodeMenuHolder::GetContextMenuItem();
  2322. break;
  2323. case PROFILE:
  2324. //
  2325. // If we're in a mode that doesn't want template (aka profile) verbs
  2326. // Then don't add the save, save as & configure verbs here
  2327. //
  2328. if (pFolder->GetState() & CFolder::state_InvalidTemplate)
  2329. break;
  2330. else if (!(pFolder->GetModeBits() & MB_NO_TEMPLATE_VERBS))
  2331. pContextMenuItem = CProfileNodeMenuHolder::GetContextMenuItem();
  2332. else if (GetModeBits() & MB_READ_ONLY)
  2333. pContextMenuItem = CRSOPProfileNodeMenuHolder::GetContextMenuItem();
  2334. else
  2335. pContextMenuItem = CSSProfileNodeMenuHolder::GetContextMenuItem();
  2336. break;
  2337. case AREA_POLICY:
  2338. case AREA_SERVICE:
  2339. case POLICY_ACCOUNT:
  2340. case POLICY_LOCAL:
  2341. case POLICY_EVENTLOG:
  2342. if ((GetModeBits() & MB_READ_ONLY) != MB_READ_ONLY)
  2343. pContextMenuItem = CProfileAreaMenuHolder::GetContextMenuItem();
  2344. break;
  2345. case AREA_PRIVILEGE:
  2346. case POLICY_PASSWORD:
  2347. case POLICY_KERBEROS:
  2348. case POLICY_LOCKOUT:
  2349. case POLICY_AUDIT:
  2350. case POLICY_OTHER:
  2351. if ((GetModeBits() & MB_READ_ONLY) != MB_READ_ONLY)
  2352. pContextMenuItem = CProfileSubAreaMenuHolder::GetContextMenuItem();
  2353. break;
  2354. case POLICY_LOG: //Raid #253209, Yang Gao, 3/27/2001.
  2355. if ((GetModeBits() & MB_READ_ONLY) != MB_READ_ONLY)
  2356. pContextMenuItem = CProfileSubAreaEventLogMenuHolder::GetContextMenuItem();
  2357. break;
  2358. case AREA_GROUPS:
  2359. if ((GetModeBits() & MB_READ_ONLY) != MB_READ_ONLY)
  2360. pContextMenuItem = CProfileGroupsMenuHolder::GetContextMenuItem();
  2361. break;
  2362. case AREA_REGISTRY:
  2363. if ((GetModeBits() & MB_READ_ONLY) != MB_READ_ONLY)
  2364. pContextMenuItem = CProfileRegistryMenuHolder::GetContextMenuItem();
  2365. break;
  2366. case AREA_FILESTORE:
  2367. if ((GetModeBits() & MB_READ_ONLY) != MB_READ_ONLY)
  2368. pContextMenuItem = CProfileFilesMenuHolder::GetContextMenuItem();
  2369. break;
  2370. case AREA_POLICY_ANALYSIS:
  2371. case AREA_PRIVILEGE_ANALYSIS:
  2372. case AREA_SERVICE_ANALYSIS:
  2373. // if under analysis info node, IDS_REFRESH_AREA
  2374. pContextMenuItem = CAnalyzeAreaMenuHolder::GetContextMenuItem();
  2375. break;
  2376. case AREA_GROUPS_ANALYSIS:
  2377. pContextMenuItem = CAnalyzeGroupsMenuHolder::GetContextMenuItem();
  2378. break;
  2379. case AREA_REGISTRY_ANALYSIS:
  2380. pContextMenuItem = CAnalyzeRegistryMenuHolder::GetContextMenuItem();
  2381. break;
  2382. case AREA_FILESTORE_ANALYSIS:
  2383. pContextMenuItem = CAnalyzeFilesMenuHolder::GetContextMenuItem();
  2384. break;
  2385. case REG_OBJECTS:
  2386. case FILE_OBJECTS:
  2387. pContextMenuItem = CAnalyzeObjectsMenuHolder::GetContextMenuItem();
  2388. break;
  2389. default:
  2390. break;
  2391. }
  2392. }
  2393. FREE_INTERNAL(pInternal);
  2394. if ( NULL == pContextMenuItem )
  2395. return hr;
  2396. //
  2397. // Loop through and add each of the menu items
  2398. //
  2399. PWSTR pstrWizardName = NULL;
  2400. PWSTR pstrPathName=NULL;
  2401. for ( LPCONTEXTMENUITEM m = pContextMenuItem; m->strName; m++)
  2402. {
  2403. //
  2404. // make a tempoary copy that can be modified
  2405. //
  2406. CONTEXTMENUITEM tempItem;
  2407. ::memcpy(&tempItem, m, sizeof(CONTEXTMENUITEM));
  2408. //
  2409. // check each command's state ?
  2410. //
  2411. CString strInf;
  2412. PEDITTEMPLATE pTemp = 0;
  2413. switch (tempItem.lCommandID )
  2414. {
  2415. case IDM_RELOAD:
  2416. case IDM_DESCRIBE_LOCATION:
  2417. case IDM_NEW:
  2418. if(pFolder &&
  2419. pFolder->GetType() == LOCATIONS &&
  2420. pFolder->GetState() & CFolder::state_InvalidTemplate )
  2421. {
  2422. tempItem.fFlags = MF_GRAYED;
  2423. }
  2424. break;
  2425. case IDM_EXPORT_POLICY:
  2426. //
  2427. // Grey out export if we can't open a database.
  2428. //
  2429. if(!SadHandle)
  2430. tempItem.fFlags = MF_GRAYED;
  2431. break;
  2432. case IDM_EXPORT_LOCALPOLICY:
  2433. case IDM_EXPORT_EFFECTIVE:
  2434. if(!SadHandle)
  2435. {
  2436. //
  2437. // Don't try to insert these items.
  2438. continue;
  2439. }
  2440. //
  2441. // Sub items of effective policy.
  2442. //
  2443. tempItem.lInsertionPointID = IDM_EXPORT_POLICY;
  2444. break;
  2445. case IDM_SECURE_WIZARD:
  2446. //
  2447. // check if there is a secure wizard registered
  2448. //
  2449. GetSecureWizardName(&pstrPathName, &pstrWizardName);
  2450. if ( pstrPathName )
  2451. {
  2452. //
  2453. // if PathName is returned, the secure wizard is registered
  2454. // but the display name may not be defined in the resource
  2455. // in which case, the default "Secure Wizard" string is used.
  2456. //
  2457. if ( pstrWizardName )
  2458. tempItem.strName = pstrWizardName;
  2459. LocalFree(pstrPathName);
  2460. }
  2461. else
  2462. continue;
  2463. break;
  2464. case IDM_PASTE:
  2465. {
  2466. UINT cf = 0;
  2467. AREA_INFORMATION Area;
  2468. if (cookie && GetFolderCopyPasteInfo(((CFolder*)cookie)->GetType(),&Area,&cf))
  2469. {
  2470. OpenClipboard(NULL);
  2471. if (!::IsClipboardFormatAvailable(cf))
  2472. tempItem.fFlags = MF_GRAYED;
  2473. CloseClipboard();
  2474. }
  2475. }
  2476. break;
  2477. case IDM_SAVE:
  2478. {
  2479. CFolder *pFolder2 = (CFolder *)cookie;
  2480. if ( pFolder2 && ANALYSIS != pFolder2->GetType() )
  2481. strInf = pFolder2->GetInfFile();
  2482. else
  2483. {
  2484. //
  2485. // analysis
  2486. //
  2487. strInf = GT_COMPUTER_TEMPLATE;
  2488. }
  2489. if ( strInf )
  2490. {
  2491. pTemp= GetTemplate(strInf);
  2492. if( pTemp && pFolder2 ) //212287, Yanggao, 3/20/2001
  2493. {
  2494. LPCTSTR des = pFolder2->GetDesc();
  2495. if( des )
  2496. {
  2497. if( pTemp->GetDesc() )
  2498. {
  2499. if( !wcscmp(des, pTemp->GetDesc()) )
  2500. pTemp->SetDescription(des);
  2501. }
  2502. else
  2503. pTemp->SetDescription(des);
  2504. }
  2505. }
  2506. if (!pTemp || !pTemp->IsDirty())
  2507. tempItem.fFlags = MF_GRAYED;
  2508. }
  2509. else
  2510. tempItem.fFlags = MF_GRAYED;
  2511. if (m_bIsLocked)
  2512. tempItem.fFlags = MF_GRAYED;
  2513. }
  2514. break;
  2515. case IDM_ASSIGN:
  2516. //
  2517. // For NT5 this menu item should be grayed if we don't have a sad handle and if analysis is locked.
  2518. //
  2519. if (m_bIsLocked || (!SadHandle && SadName.IsEmpty()) ||
  2520. SadErrored == SCESTATUS_ACCESS_DENIED)
  2521. {
  2522. tempItem.fFlags = MF_GRAYED;
  2523. }
  2524. break;
  2525. case IDM_VIEW_LOGFILE:
  2526. if(!GetErroredLogFile())
  2527. tempItem.fFlags = MF_GRAYED;
  2528. else if (m_dwFlags & flag_showLogFile )
  2529. tempItem.fFlags = MF_CHECKED;
  2530. break;
  2531. case IDM_SET_DB:
  2532. case IDM_OPEN_PRIVATE_DB:
  2533. if ( m_bIsLocked )
  2534. tempItem.fFlags = MF_GRAYED;
  2535. break;
  2536. case IDM_SUMMARY:
  2537. case IDM_APPLY:
  2538. case IDM_GENERATE:
  2539. case IDM_ANALYZE:
  2540. {
  2541. WIN32_FIND_DATA fd;
  2542. HANDLE handle = 0;
  2543. //
  2544. // Bug #156375
  2545. //
  2546. // don't gray out if we have a database file. we can't open the
  2547. // database (and therefore get a SadHandle) unless the database has
  2548. // already been analyzed, which gives a chicken & egg problem with
  2549. // requiring the SadHandle to enable IDM_ANALYZE or IDM_APPLY....
  2550. // (if we have a SadHandle already then everything's fine, of course)
  2551. //
  2552. // If the database is corrupt or invalid then the actual action will
  2553. // fail and we'll display an error then.
  2554. //
  2555. if (m_bIsLocked)
  2556. {
  2557. tempItem.fFlags = MF_GRAYED;
  2558. //
  2559. // If we have a SadHandle then we're ok
  2560. //
  2561. }
  2562. else if (!SadHandle)
  2563. {
  2564. //
  2565. // Bug #387406
  2566. //
  2567. // If we don't have a SadHandle we can't generate a template
  2568. // even if the database file exists
  2569. //
  2570. if (IDM_GENERATE == tempItem.lCommandID )
  2571. tempItem.fFlags = MF_GRAYED;
  2572. else
  2573. {
  2574. //
  2575. // With no database handle & no assigned configuration then let the
  2576. // menu option be selected so long as the database file exists.
  2577. //
  2578. if (SadName.IsEmpty() || SadErrored == SCESTATUS_ACCESS_DENIED)
  2579. tempItem.fFlags = MF_GRAYED;
  2580. else
  2581. {
  2582. handle = FindFirstFile(SadName,&fd);
  2583. if (INVALID_HANDLE_VALUE == handle)
  2584. tempItem.fFlags = MF_GRAYED;
  2585. else
  2586. FindClose(handle);
  2587. }
  2588. }
  2589. }
  2590. }
  2591. break;
  2592. case IDM_ADD_LOC:
  2593. if ( !m_bEnumerateScopePaneCalled )
  2594. tempItem.fFlags = MF_GRAYED;
  2595. break;
  2596. default:
  2597. break;
  2598. }
  2599. hr = pContextMenuCallback->AddItem(&tempItem);
  2600. if (FAILED(hr))
  2601. break;
  2602. }
  2603. if ( pstrWizardName )
  2604. LocalFree(pstrWizardName);
  2605. return hr;
  2606. }
  2607. DWORD DeleteLocationFromReg2(HKEY hKey,LPCTSTR KeyStr)
  2608. {
  2609. DWORD rc = 0;
  2610. // replace the "\" with "/" because registry does not take "\" in a single key
  2611. CString tmpstr = KeyStr;
  2612. int npos = tmpstr.Find(L'\\');
  2613. while (npos > 0) {
  2614. *(tmpstr.GetBuffer(1)+npos) = L'/';
  2615. npos = tmpstr.Find(L'\\');
  2616. }
  2617. rc = RegDeleteKey( hKey, (LPCTSTR)tmpstr);
  2618. RegCloseKey(hKey);
  2619. return rc;
  2620. }
  2621. DWORD DeleteLocationFromReg(LPCTSTR KeyStr)
  2622. {
  2623. // delete the location to registry
  2624. BOOL bSuccess = FALSE;
  2625. HKEY hKey=NULL;
  2626. DWORD rc = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  2627. L"Software\\Microsoft\\Windows NT\\CurrentVersion\\secmgr",
  2628. 0, KEY_READ | KEY_WRITE,
  2629. &hKey);
  2630. if (ERROR_SUCCESS == rc) {
  2631. bSuccess = TRUE;
  2632. DeleteLocationFromReg2(hKey,KeyStr);
  2633. }
  2634. //
  2635. // Bug 375324: Delete from both system & local keys if possible
  2636. //
  2637. rc = RegOpenKeyEx( HKEY_CURRENT_USER,
  2638. L"Software\\Microsoft\\Windows NT\\CurrentVersion\\secmgr",
  2639. 0, KEY_READ | KEY_WRITE,
  2640. &hKey);
  2641. if (ERROR_SUCCESS == rc) {
  2642. DeleteLocationFromReg2(hKey,KeyStr);
  2643. }
  2644. //
  2645. // If we succeeded the first key then we don't care what happened
  2646. // for the second (it'll probably fail since the key didn't exist
  2647. // there anyway)
  2648. //
  2649. if (bSuccess) {
  2650. return ERROR_SUCCESS;
  2651. } else {
  2652. return rc;
  2653. }
  2654. }
  2655. //+--------------------------------------------------------------------------
  2656. //
  2657. // Method: CloseAnalysisPane
  2658. //
  2659. // Synopsis: Close up the Analysis Pane and free any memory for folders that
  2660. // we aren't using any longer.
  2661. //
  2662. // History: a-mthoge 06-09-1998 - _NT4BACK_PORT item to reinsert the scope
  2663. // item back into the tree.
  2664. //
  2665. //---------------------------------------------------------------------------
  2666. void
  2667. CComponentDataImpl::CloseAnalysisPane() {
  2668. SCOPEDATAITEM item;
  2669. if (m_AnalFolder && m_AnalFolder->IsEnumerated()) {
  2670. DeleteChildrenUnderNode(m_AnalFolder);
  2671. m_AnalFolder->Set(FALSE);
  2672. if (m_AnalFolder->GetScopeItem()) {
  2673. //
  2674. // Mark item as unexpanded so we can re expand it later
  2675. //
  2676. ZeroMemory (&item, sizeof (item));
  2677. item.mask = SDI_STATE;
  2678. item.nState = 0;
  2679. item.ID = m_AnalFolder->GetScopeItem()->ID;
  2680. (void)m_pScope->SetItem (&item);
  2681. }
  2682. }
  2683. }
  2684. //+--------------------------------------------------------------------------
  2685. //
  2686. // Method: LockAnalysisPane
  2687. //
  2688. // Synopsis: Lock the Analysis Pane so that it closes and won't reopen
  2689. //
  2690. // Arguments: [bLock] - [in] TRUE to lock the pane, FALSE to unlock it
  2691. //
  2692. // Returns: TRUE if the pane ends up locked, FALSE if it ends up unlocked
  2693. //
  2694. // History: a-mthoge 06-09-1998 - Added _NT4BACKPORT and SelectScopeItem
  2695. // berfore enumeration.
  2696. //
  2697. //
  2698. //---------------------------------------------------------------------------
  2699. BOOL
  2700. CComponentDataImpl::LockAnalysisPane(BOOL bLock, BOOL fRemoveAnalDlg) {
  2701. TryEnterCriticalSection(&csAnalysisPane);
  2702. m_bIsLocked = bLock;
  2703. //
  2704. // Close the Analysis Pane whichever way we're going
  2705. // If we're locking then we want to close it to clear out any
  2706. // now-invalid data.
  2707. //
  2708. // If we're unlocking then we want to make sure that the folder
  2709. // is fresh and that MMC doesn't think it's already been expanded,
  2710. // and refuse to expand it anew.
  2711. //
  2712. if (!bLock) {
  2713. if (!m_AnalFolder) {
  2714. goto ExitLockAnalysisPane;
  2715. }
  2716. if (!m_AnalFolder->GetScopeItem() ) {
  2717. goto ExitLockAnalysisPane;
  2718. }
  2719. //
  2720. // If we're unlocking it then enumerate its subfolders
  2721. //
  2722. RefreshSadInfo(fRemoveAnalDlg);
  2723. }
  2724. ExitLockAnalysisPane:
  2725. LeaveCriticalSection(&csAnalysisPane);
  2726. return m_bIsLocked;
  2727. }
  2728. void CComponentDataImpl::RefreshSadInfo(BOOL fRemoveAnalDlg)
  2729. {
  2730. CPerformAnalysis *pPA = 0;
  2731. UnloadSadInfo();
  2732. LoadSadInfo( TRUE );
  2733. //
  2734. // No need to LoadSadInfo() since EnumerateScopePane will do it when it needs it
  2735. //
  2736. if(m_pConsole && m_AnalFolder)
  2737. {
  2738. EnumerateScopePane( (MMC_COOKIE)m_AnalFolder, m_AnalFolder->GetScopeItem()->ID );
  2739. m_pConsole->SelectScopeItem(m_AnalFolder->GetScopeItem()->ID);
  2740. }
  2741. //
  2742. // remove cached analysis popup since it has cached filenames
  2743. //
  2744. if (fRemoveAnalDlg)
  2745. {
  2746. pPA = (CPerformAnalysis *) this->GetPopupDialog(IDM_ANALYZE);
  2747. if (pPA != NULL)
  2748. {
  2749. this->RemovePopupDialog(IDM_ANALYZE);
  2750. delete(pPA);
  2751. }
  2752. }
  2753. }
  2754. void
  2755. CComponentDataImpl::UnloadSadInfo() {
  2756. if (SadHandle) {
  2757. if ( SadTransStarted ) {
  2758. EngineRollbackTransaction();
  2759. SadTransStarted = FALSE;
  2760. }
  2761. EngineCloseProfile(&SadHandle);
  2762. // SadName.Empty();
  2763. SadDescription.Empty();
  2764. SadAnalyzeStamp.Empty();
  2765. SadConfigStamp.Empty();
  2766. CloseAnalysisPane();
  2767. }
  2768. //
  2769. // Dump our cached templates so they get reloaded with the
  2770. // new Sad information when it is available
  2771. //
  2772. DeleteTemplate(GT_COMPUTER_TEMPLATE);
  2773. DeleteTemplate(GT_LAST_INSPECTION);
  2774. SadLoaded = FALSE;
  2775. SadErrored = SCESTATUS_SUCCESS;
  2776. SadTransStarted = FALSE;
  2777. SadHandle = 0;
  2778. }
  2779. void CComponentDataImpl::LoadSadInfo(BOOL bRequireAnalysis)
  2780. {
  2781. DWORD rc;
  2782. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  2783. CWaitCursor wc;
  2784. if (SadHandle) {
  2785. return;
  2786. }
  2787. if (m_bIsLocked) {
  2788. return;
  2789. }
  2790. //
  2791. // get name again
  2792. //
  2793. LPWSTR FileName=NULL;
  2794. LPWSTR FileDesc=NULL;
  2795. LPWSTR FileStamp1=NULL;
  2796. LPWSTR FileStamp2=NULL;
  2797. DWORD RegType;
  2798. if ( SadName.IsEmpty() && bRequireAnalysis) {
  2799. //
  2800. // SadName is required if Analysis is required, but not otherwise
  2801. // as the engine will find the system database on its own if passed
  2802. // a NULL file name
  2803. //
  2804. return;
  2805. }
  2806. SadErrored = EngineOpenProfile( (SadName.IsEmpty() ? NULL : (LPCTSTR)SadName),
  2807. bRequireAnalysis ? OPEN_PROFILE_ANALYSIS : OPEN_PROFILE_LOCALPOL,
  2808. &SadHandle );
  2809. if (SadErrored == SCESTATUS_SUCCESS ) {
  2810. EngineGetDescription( SadHandle, &FileDesc);
  2811. if ( FileDesc ) {
  2812. SadDescription = FileDesc;
  2813. LocalFree(FileDesc);
  2814. }
  2815. SadLoaded = TRUE;
  2816. SadTransStarted = TRUE;
  2817. return;
  2818. }
  2819. if (FileName) {
  2820. LocalFree(FileName);
  2821. }
  2822. SadTransStarted = FALSE;
  2823. //
  2824. // Bug #197052 - Should automatically analyze if no anal info is available
  2825. //
  2826. return;
  2827. }
  2828. //+--------------------------------------------------------------------------
  2829. //
  2830. // Function: BrowseCallbackProc
  2831. //
  2832. // Synopsis: Callback procedure for File & Folder adding SHBrowseForFolder
  2833. // to set the title bar appropriately
  2834. //
  2835. // Arguments: [hwnd] - the hwnd of the browse dialog
  2836. // [uMsg] - the message from the dialog
  2837. // [lParam] - message dependant
  2838. // [pData] - message dependant
  2839. //
  2840. // Returns: 0
  2841. //
  2842. //---------------------------------------------------------------------------
  2843. int
  2844. BrowseCallbackProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM pData) {
  2845. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  2846. switch(uMsg) {
  2847. case BFFM_INITIALIZED: {
  2848. CString strTitle;
  2849. strTitle.LoadString(IDS_FILEFOLDER_BROWSE_TITLE);
  2850. SetWindowText(hwnd,strTitle);
  2851. break;
  2852. }
  2853. case BFFM_VALIDATEFAILED :{
  2854. if( pData )
  2855. {
  2856. *(CString*)pData = (LPWSTR)(lParam);
  2857. CString ptempstr = (LPWSTR)(lParam); //Raid #374069, 4/23/2001
  2858. if( -1 != ptempstr.Find(L"\\\\") )
  2859. {
  2860. return 1;
  2861. }
  2862. }
  2863. break;
  2864. }
  2865. default:
  2866. break;
  2867. }
  2868. return 0;
  2869. }
  2870. STDMETHODIMP CComponentDataImpl::Command(long nCommandID, LPDATAOBJECT pDataObject)
  2871. {
  2872. // Note - snap-ins need to look at the data object and determine
  2873. // in what context the command is being called.
  2874. // Handle each of the commands.
  2875. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  2876. INTERNAL* pInternal = ExtractInternalFormat(pDataObject);
  2877. if (pInternal == NULL) {
  2878. // Actually looking for our extension
  2879. return S_OK;
  2880. }
  2881. MMC_COOKIE cookie = pInternal->m_cookie;
  2882. CFolder* pFolder;
  2883. if ( cookie) {
  2884. pFolder = (CFolder*)cookie;
  2885. /*
  2886. if( m_pConsole && nCommandID != IDM_OBJECT_SECURITY) {
  2887. m_pConsole->SelectScopeItem(pFolder->GetScopeItem()->ID);
  2888. }
  2889. */
  2890. } else {
  2891. pFolder = FindObject(cookie, NULL);
  2892. if ( pFolder == NULL ) {
  2893. return S_OK;
  2894. }
  2895. }
  2896. FREE_INTERNAL(pInternal);
  2897. LPWSTR Name=NULL, Desc=NULL;
  2898. //
  2899. // initialize SadName, SadDescription, and SadDateTime
  2900. //
  2901. if ( !SadHandle && (nCommandID == IDM_SUMMARY ||
  2902. // if ( !SadLoaded && (nCommandID == IDM_SUMMARY || // HAPPYHAPPY
  2903. nCommandID == IDM_ANALYZE ||
  2904. nCommandID == IDM_APPLY ||
  2905. nCommandID == IDM_ASSIGN ||
  2906. nCommandID == IDM_GENERATE ) ) {
  2907. if (pFolder->GetModeBits() & MB_LOCAL_POLICY) {
  2908. LoadSadInfo(FALSE);
  2909. } else {
  2910. LoadSadInfo(TRUE);
  2911. }
  2912. }
  2913. //
  2914. // more variable definitions used inside case statements
  2915. //
  2916. PVOID pDlg;
  2917. CString ResString, AreaString;
  2918. CPropertySheet sheet;
  2919. CString tmpstr;
  2920. MMC_COOKIE FindCookie;
  2921. struct _wfinddata_t findData;
  2922. LONG hFile;
  2923. WCHAR pBuf[MAX_PATH];
  2924. HRESULT hr;
  2925. HSCOPEITEM pItemChild;
  2926. // AREA_INFORMATION Area;
  2927. switch (nCommandID) {
  2928. case MMC_VERB_OPEN:
  2929. break;
  2930. case MMC_VERB_COPY:
  2931. case MMC_VERB_PASTE:
  2932. break;
  2933. case IDM_VIEW_LOGFILE:
  2934. if (m_dwFlags & flag_showLogFile) {
  2935. m_dwFlags &= ~flag_showLogFile;
  2936. } else {
  2937. m_dwFlags |= flag_showLogFile;
  2938. }
  2939. //
  2940. // Force a repaint.
  2941. //
  2942. m_pConsole->SelectScopeItem( pFolder->GetScopeItem()->ID );
  2943. break;
  2944. case IDM_OPEN_SYSTEM_DB: {
  2945. CString szSysDB;
  2946. hr = GetSystemDatabase(&szSysDB); //Raid bug 261450, Yang Gao, 3/30/2001
  2947. if (SUCCEEDED(hr)) {
  2948. //
  2949. // Don't change anything if nothing changes
  2950. //
  2951. if (SadName != szSysDB) {
  2952. SadName = szSysDB;
  2953. RefreshSadInfo();
  2954. }
  2955. }
  2956. break;
  2957. }
  2958. case IDM_OPEN_PRIVATE_DB:
  2959. hr = OnOpenDataBase();
  2960. break;
  2961. case IDM_NEW_DATABASE:
  2962. hr = OnNewDatabase();
  2963. break;
  2964. case IDM_IMPORT_POLICY:
  2965. hr = OnImportPolicy(pDataObject);
  2966. break;
  2967. case IDM_IMPORT_LOCAL_POLICY:
  2968. hr = OnImportLocalPolicy(pDataObject);
  2969. break;
  2970. case IDM_EXPORT_LOCALPOLICY:
  2971. hr = OnExportPolicy(FALSE);
  2972. break;
  2973. case IDM_EXPORT_EFFECTIVE:
  2974. hr = OnExportPolicy(TRUE);
  2975. break;
  2976. case IDM_ANALYZE: {
  2977. PEDITTEMPLATE pet;
  2978. //
  2979. // If the computer template has been changed then save it before we
  2980. // can apply it so we don't lose any changes
  2981. //
  2982. pet = GetTemplate(GT_COMPUTER_TEMPLATE);
  2983. if (pet && pet->IsDirty()) {
  2984. pet->Save();
  2985. }
  2986. hr = OnAnalyze();
  2987. break;
  2988. }
  2989. case IDM_DESCRIBE_PROFILE:
  2990. m_pUIThread->PostThreadMessage(SCEM_DESCRIBE_PROFILE,(WPARAM)pFolder,(LPARAM) this);
  2991. break;
  2992. case IDM_DESCRIBE_LOCATION:
  2993. m_pUIThread->PostThreadMessage(SCEM_DESCRIBE_LOCATION,(WPARAM)pFolder,(LPARAM) this);
  2994. break;
  2995. case IDM_NEW:
  2996. m_pUIThread->PostThreadMessage(SCEM_NEW_CONFIGURATION,(WPARAM)pFolder,(LPARAM) this);
  2997. break;
  2998. case IDM_ADD_LOC:
  2999. {
  3000. // add a location
  3001. BROWSEINFO bi;
  3002. LPMALLOC pMalloc = NULL;
  3003. LPITEMIDLIST pidlLocation = NULL;
  3004. CString strLocation;
  3005. CString strTitle;
  3006. BOOL bGotLocation = FALSE;
  3007. HKEY hLocKey = NULL;
  3008. HKEY hKey = NULL;
  3009. DWORD dwDisp = 0;
  3010. strTitle.LoadString(IDS_ADDLOCATION_TITLE);
  3011. ZeroMemory(&bi,sizeof(bi));
  3012. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
  3013. bi.lpszTitle = strTitle;
  3014. bi.hwndOwner = m_hwndParent;
  3015. pidlLocation = SHBrowseForFolder(&bi);
  3016. if (pidlLocation)
  3017. {
  3018. bGotLocation = SHGetPathFromIDList(pidlLocation,strLocation.GetBuffer(MAX_PATH));
  3019. strLocation.ReleaseBuffer();
  3020. if (SUCCEEDED(SHGetMalloc(&pMalloc)))
  3021. {
  3022. pMalloc->Free(pidlLocation);
  3023. pMalloc->Release();
  3024. }
  3025. if (bGotLocation)
  3026. {
  3027. //If a drive such as D: is selected, path comes as D:\
  3028. //Remove trailing backslash
  3029. if( strLocation[ strLocation.GetLength() -1 ] == '\\' )
  3030. strLocation.SetAt(strLocation.GetLength() - 1, 0 );
  3031. AddTemplateLocation(pFolder, // the parent folder
  3032. strLocation, // the location name
  3033. FALSE, // strLocationKey is a file name ?
  3034. FALSE // refresh this location if it already exists ?
  3035. );
  3036. }
  3037. else
  3038. AfxMessageBox(IDS_ADD_LOC_FAILED);
  3039. }
  3040. break;
  3041. }
  3042. case IDM_ADD_FOLDER:
  3043. {
  3044. BROWSEINFO bi;
  3045. LPMALLOC pMalloc = NULL;
  3046. LPITEMIDLIST pidlRoot = NULL;
  3047. LPITEMIDLIST pidlLocation = NULL;
  3048. CString strCallBack;
  3049. CString strPath;
  3050. LPTSTR szPath = NULL;
  3051. CString strDescription;
  3052. CString strTitle;
  3053. CString strLocationKey;
  3054. bool fDuplicate = false;
  3055. ULONG strleng = MAX_PATH;
  3056. SHGetSpecialFolderLocation(m_hwndParent,CSIDL_DRIVES,&pidlRoot);
  3057. ZeroMemory(&bi,sizeof(bi));
  3058. strTitle.LoadString(IDS_ADDFILESANDFOLDERS_TITLE);
  3059. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_BROWSEINCLUDEFILES | BIF_USENEWUI
  3060. | BIF_EDITBOX|BIF_VALIDATE |BIF_NEWDIALOGSTYLE;
  3061. bi.lpfn = BrowseCallbackProc;
  3062. bi.hwndOwner = m_hwndParent;
  3063. bi.lpszTitle = strTitle;
  3064. bi.pidlRoot = pidlRoot;
  3065. bi.lParam = (LPARAM)&strCallBack;
  3066. unsigned int i;
  3067. pidlLocation = SHBrowseForFolder(&bi);
  3068. if ( !pidlLocation && strCallBack.IsEmpty() )
  3069. {
  3070. if (SUCCEEDED(SHGetMalloc(&pMalloc)))
  3071. {
  3072. pMalloc->Free(pidlLocation);
  3073. pMalloc->Free(pidlRoot);
  3074. pMalloc->Release();
  3075. }
  3076. break;
  3077. }
  3078. if( pidlLocation )
  3079. {
  3080. //Raid #374069, 6/13/2001, Yanggao
  3081. if( FALSE == SHGetPathFromIDList(pidlLocation,strPath.GetBuffer(MAX_PATH)) )
  3082. {
  3083. strPath.ReleaseBuffer();
  3084. strPath = strCallBack;
  3085. }
  3086. else
  3087. {
  3088. strPath.ReleaseBuffer();
  3089. if(!strCallBack.IsEmpty()) //Raid #374069, 4/23/2001
  3090. {
  3091. if( -1 != strCallBack.Find(L':') )
  3092. {
  3093. strPath = strCallBack;
  3094. }
  3095. else
  3096. {
  3097. if( L'\\' == strPath.GetAt(strPath.GetLength()-1) )
  3098. {
  3099. if( L'\\' == strCallBack.GetAt(0) )
  3100. {
  3101. strCallBack.Delete(0, 1);
  3102. }
  3103. }
  3104. else
  3105. {
  3106. if( L'\\' != strCallBack.GetAt(0) )
  3107. {
  3108. strPath = strPath + L"\\";
  3109. }
  3110. }
  3111. strPath = strPath + strCallBack;
  3112. strCallBack.Empty();
  3113. }
  3114. }
  3115. }
  3116. }
  3117. else
  3118. {
  3119. strPath = strCallBack;
  3120. strCallBack.Empty();
  3121. }
  3122. szPath = UnexpandEnvironmentVariables(strPath);
  3123. if (szPath) {
  3124. strPath = szPath;
  3125. LocalFree(szPath);
  3126. szPath = NULL;
  3127. }
  3128. if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
  3129. pMalloc->Free(pidlLocation);
  3130. pMalloc->Free(pidlRoot);
  3131. pMalloc->Release();
  3132. }
  3133. if (!strPath) {
  3134. break;
  3135. }
  3136. PEDITTEMPLATE pet;
  3137. PSCE_OBJECT_ARRAY poa;
  3138. pet = GetTemplate(pFolder->GetInfFile());
  3139. //
  3140. // Need to grow the template's PSCE_OBJECT_ARRAY and add the new file entry
  3141. //
  3142. if ( !pet || !pet->pTemplate ) {
  3143. break;
  3144. }
  3145. poa = pet->pTemplate->pFiles.pAllNodes;
  3146. if ( !poa ) {
  3147. poa = (PSCE_OBJECT_ARRAY)LocalAlloc(LPTR, sizeof(SCE_OBJECT_ARRAY));
  3148. if ( poa ) {
  3149. poa->Count = 0;
  3150. poa->pObjectArray = NULL;
  3151. } else {
  3152. break;
  3153. }
  3154. pet->pTemplate->pFiles.pAllNodes = poa;
  3155. }
  3156. //
  3157. // Make sure this file isn't already in the list:
  3158. //
  3159. fDuplicate = false;
  3160. for (i=0;i < poa->Count;i++) {
  3161. if (lstrcmpi(poa->pObjectArray[i]->Name,strPath) == 0) {
  3162. fDuplicate = true;
  3163. break;
  3164. }
  3165. }
  3166. if (fDuplicate) {
  3167. break;
  3168. }
  3169. PSECURITY_DESCRIPTOR pSelSD;
  3170. SECURITY_INFORMATION SelSeInfo;
  3171. BYTE ConfigStatus;
  3172. pSelSD=NULL;
  3173. SelSeInfo=0;
  3174. INT_PTR nRet;
  3175. if( GetAddObjectSecurity(
  3176. m_hwndParent,
  3177. strPath,
  3178. TRUE,
  3179. SE_FILE_OBJECT,
  3180. pSelSD,
  3181. SelSeInfo,
  3182. ConfigStatus
  3183. ) != S_OK ){
  3184. break;
  3185. }
  3186. if ( pSelSD && SelSeInfo ) {
  3187. poa->Count++;
  3188. PSCE_OBJECT_SECURITY *pCopy;
  3189. pCopy = (PSCE_OBJECT_SECURITY *)LocalAlloc(LPTR,poa->Count*sizeof(PSCE_OBJECT_SECURITY));
  3190. if (!pCopy) {
  3191. poa->Count--;
  3192. ErrorHandler();
  3193. LocalFree(pSelSD);
  3194. pSelSD = NULL;
  3195. break;
  3196. }
  3197. for (i=0;i<(poa->Count -1);i++) {
  3198. pCopy[i] = poa->pObjectArray[i];
  3199. }
  3200. if ( poa->pObjectArray ) {
  3201. LocalFree(poa->pObjectArray);
  3202. }
  3203. poa->pObjectArray = pCopy;
  3204. poa->pObjectArray[poa->Count-1] = (PSCE_OBJECT_SECURITY) LocalAlloc(LPTR,sizeof(SCE_OBJECT_SECURITY));
  3205. if (poa->pObjectArray[poa->Count-1]) {
  3206. poa->pObjectArray[poa->Count-1]->Name = (PWSTR) LocalAlloc(LPTR,(strPath.GetLength()+1)*sizeof(TCHAR));
  3207. if (poa->pObjectArray[poa->Count-1]->Name) {
  3208. lstrcpy(poa->pObjectArray[poa->Count-1]->Name,strPath);
  3209. poa->pObjectArray[poa->Count-1]->IsContainer = TRUE;
  3210. poa->pObjectArray[poa->Count-1]->Status = ConfigStatus;
  3211. poa->pObjectArray[poa->Count-1]->pSecurityDescriptor = pSelSD;
  3212. pSelSD = NULL;
  3213. poa->pObjectArray[poa->Count-1]->SeInfo = SelSeInfo;
  3214. pet->pTemplate->pFiles.pAllNodes = poa;
  3215. pet->SetDirty(AREA_FILE_SECURITY);
  3216. ((CFolder *)cookie)->RemoveAllResultItems();
  3217. m_pConsole->UpdateAllViews(NULL, cookie, UAV_RESULTITEM_UPDATEALL);
  3218. } else {
  3219. //
  3220. // Couldn't allocate memory for the object's name,
  3221. // so remove the object from the count & array
  3222. //
  3223. LocalFree(poa->pObjectArray[poa->Count-1]);
  3224. poa->pObjectArray[poa->Count-1] = 0;
  3225. poa->Count--;
  3226. }
  3227. } else {
  3228. //
  3229. // Couldn't allocate the new object, so remove it from the count
  3230. //
  3231. poa->Count--;
  3232. }
  3233. }
  3234. if ( pSelSD ) {
  3235. LocalFree(pSelSD);
  3236. pSelSD = NULL;
  3237. }
  3238. if (pet->pTemplate->pFiles.pAllNodes == NULL) {
  3239. LocalFree(poa);
  3240. }
  3241. break;
  3242. }
  3243. case IDM_ADD_GROUPS: {
  3244. PSCE_NAME_LIST pName = NULL;
  3245. CWnd cWnd;
  3246. cWnd.Attach( m_hwndParent );
  3247. CGetUser gu;
  3248. CSCEAddGroup dlg( &cWnd );
  3249. if( (pFolder->GetModeBits() & MB_LOCAL_POLICY) ||
  3250. (pFolder->GetModeBits() & MB_ANALYSIS_VIEWER) ){
  3251. if (gu.Create(m_hwndParent, SCE_SHOW_BUILTIN | SCE_SHOW_ALIASES | SCE_SHOW_LOCALONLY |
  3252. SCE_SHOW_SCOPE_LOCAL )) {
  3253. pName = gu.GetUsers();
  3254. }
  3255. } else {
  3256. dlg.m_dwFlags = SCE_SHOW_BUILTIN | SCE_SHOW_LOCALGROUPS | SCE_SHOW_GLOBAL;
  3257. if (pFolder->GetModeBits() & MB_GROUP_POLICY) {
  3258. //
  3259. // Set the scope flags explicitely because we want to limit the added groups
  3260. // here to ones from our own domain. If we SetModeBits then CSCEADDGroup
  3261. // will allow restricting groups that don't belong to us.
  3262. //
  3263. // Allow free-text groups to be added if the admin knows that a group will
  3264. // exist on machines within the OU.
  3265. //
  3266. dlg.m_dwFlags |= SCE_SHOW_SCOPE_DOMAIN;
  3267. } else {
  3268. ASSERT(pFolder->GetModeBits() & MB_TEMPLATE_EDITOR);
  3269. //
  3270. // Allow people to pick any group to restrict because we have no idea
  3271. // where this template will be used. It could conceivably be for a
  3272. // GPO on another domain, etc.
  3273. //
  3274. dlg.m_dwFlags |= SCE_SHOW_SCOPE_ALL;
  3275. }
  3276. CThemeContextActivator activator;
  3277. if(dlg.DoModal() == IDOK)
  3278. {
  3279. if(dlg.GetUsers()->Name )
  3280. pName = dlg.GetUsers();
  3281. }
  3282. }
  3283. cWnd.Detach();
  3284. if(pName){
  3285. PSCE_GROUP_MEMBERSHIP pgm,pGroup,pgmBase,pgmProfile;
  3286. PEDITTEMPLATE pTemplate;
  3287. BOOL fDuplicate;
  3288. BOOL fAnalysis = FALSE;
  3289. if (pFolder->GetType() == AREA_GROUPS_ANALYSIS) {
  3290. pTemplate = GetTemplate(GT_COMPUTER_TEMPLATE,AREA_GROUP_MEMBERSHIP);
  3291. if (pTemplate) {
  3292. pgmBase = pTemplate->pTemplate->pGroupMembership;
  3293. } else {
  3294. break;
  3295. }
  3296. pTemplate = GetTemplate(GT_LAST_INSPECTION,AREA_GROUP_MEMBERSHIP);
  3297. if (pTemplate) {
  3298. pgmProfile = pTemplate->pTemplate->pGroupMembership;
  3299. } else {
  3300. break;
  3301. }
  3302. fAnalysis = TRUE;
  3303. } else {
  3304. pTemplate = GetTemplate(pFolder->GetInfFile());
  3305. if (!pTemplate) {
  3306. break;
  3307. }
  3308. pgm = pTemplate->pTemplate->pGroupMembership;
  3309. fAnalysis = FALSE;
  3310. }
  3311. while (pName) {
  3312. //
  3313. // Make sure this isn't a duplicate
  3314. //
  3315. if (fAnalysis) {
  3316. pGroup = pgmProfile;
  3317. } else {
  3318. pGroup = pgm;
  3319. }
  3320. fDuplicate = false;
  3321. while (pGroup) {
  3322. if (lstrcmp(pGroup->GroupName,pName->Name) == 0) {
  3323. fDuplicate = true;
  3324. break;
  3325. }
  3326. pGroup = pGroup->Next;
  3327. }
  3328. if (false != fDuplicate) {
  3329. pName = pName->Next;
  3330. continue;
  3331. }
  3332. pGroup = (PSCE_GROUP_MEMBERSHIP) LocalAlloc(LPTR,sizeof(SCE_GROUP_MEMBERSHIP));
  3333. if ( pGroup ) {
  3334. pGroup->GroupName = (PWSTR) LocalAlloc(LPTR,(lstrlen(pName->Name)+1)*sizeof(TCHAR));
  3335. if ( pGroup->GroupName ) {
  3336. lstrcpy(pGroup->GroupName,pName->Name);
  3337. pGroup->pMembers=NULL;
  3338. pGroup->pMemberOf=NULL;
  3339. if (fAnalysis) {
  3340. //
  3341. // First add the group to the LAST_INSPECTION area
  3342. //
  3343. pGroup->Next = pgmProfile;
  3344. pGroup->Status = SCE_GROUP_STATUS_NOT_ANALYZED;
  3345. pgmProfile = pGroup;
  3346. //
  3347. // Also, add this group to the computer template in case a save is done at this point.
  3348. //
  3349. PEDITTEMPLATE pTemp = GetTemplate(GT_COMPUTER_TEMPLATE,AREA_GROUP_MEMBERSHIP);
  3350. pGroup = (PSCE_GROUP_MEMBERSHIP) LocalAlloc(LPTR,sizeof(SCE_GROUP_MEMBERSHIP));
  3351. if ( pTemp && pGroup ) {
  3352. pGroup->GroupName = (PWSTR) LocalAlloc(LPTR,(lstrlen(pName->Name)+1)*sizeof(TCHAR));
  3353. if ( pGroup->GroupName ) {
  3354. lstrcpy(pGroup->GroupName,pName->Name);
  3355. pGroup->pMembers=NULL;
  3356. pGroup->pMemberOf=NULL;
  3357. pGroup->Next = pgmBase;
  3358. pGroup->Status = SCE_GROUP_STATUS_NOT_ANALYZED;
  3359. pTemp->pTemplate->pGroupMembership = pGroup;
  3360. }
  3361. else {
  3362. //
  3363. // no memory
  3364. //
  3365. LocalFree(pGroup);
  3366. break;
  3367. }
  3368. } else {
  3369. //
  3370. // no memory
  3371. //
  3372. if (pGroup)
  3373. LocalFree(pGroup);
  3374. break;
  3375. }
  3376. } else {
  3377. pGroup->Status = 0;
  3378. pGroup->Next = pgm;
  3379. pgm = pGroup;
  3380. }
  3381. } else {
  3382. //
  3383. // no memory
  3384. //
  3385. LocalFree(pGroup);
  3386. break;
  3387. }
  3388. } else {
  3389. break;
  3390. }
  3391. pName = pName->Next;
  3392. }
  3393. if (fAnalysis)
  3394. {
  3395. //
  3396. // add to the last inspection list with status
  3397. // not analyzed
  3398. //
  3399. pTemplate->pTemplate->pGroupMembership = pgmProfile;
  3400. }
  3401. else
  3402. {
  3403. pTemplate->pTemplate->pGroupMembership = pgm;
  3404. }
  3405. //
  3406. // Need to SetDirty AFTER making the changes, not before.
  3407. // Otherwise modes which write the changes out immediately
  3408. // won't have a chance at them. (Bug 396549)
  3409. //
  3410. if (pTemplate)
  3411. {
  3412. pTemplate->SetDirty(AREA_GROUP_MEMBERSHIP);
  3413. }
  3414. CString ObjName = pgm->GroupName;
  3415. pFolder->RemoveAllResultItems();
  3416. pFolder->SetViewUpdate(TRUE);
  3417. m_pConsole->UpdateAllViews(NULL, (LONG_PTR)pFolder,UAV_RESULTITEM_UPDATEALL);
  3418. //Raid #258237, Yang Gao, 3/28/2001
  3419. BOOL bGP = ( (GetModeBits() & MB_SINGLE_TEMPLATE_ONLY) == MB_SINGLE_TEMPLATE_ONLY );
  3420. CAttribute* pAttr = NULL;
  3421. CResult* pResult = NULL;
  3422. HANDLE handle;
  3423. POSITION pos = NULL;
  3424. int tempcount = pFolder->GetResultListCount();
  3425. pFolder->GetResultItemHandle ( &handle );
  3426. if(!handle)
  3427. {
  3428. break;
  3429. }
  3430. pFolder->GetResultItem (handle, pos, &pResult);
  3431. while(pResult)
  3432. {
  3433. if(!pos)
  3434. {
  3435. //Find the last one;
  3436. break;
  3437. }
  3438. pFolder->GetResultItem(handle, pos, &pResult);
  3439. }
  3440. pFolder->ReleaseResultItemHandle (handle);
  3441. if( pResult && (pResult->GetType() == ITEM_PROF_GROUP) )
  3442. {
  3443. if( bGP )
  3444. pAttr = new CDomainGroup;
  3445. else
  3446. pAttr = new CConfigGroup(0);
  3447. if( pAttr )
  3448. {
  3449. pAttr->SetSnapin(pResult->GetSnapin());
  3450. pAttr->Initialize(pResult);
  3451. pAttr->SetReadOnly(FALSE);
  3452. pAttr->SetTitle(pResult->GetAttrPretty());
  3453. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pAttr->m_psp);
  3454. PROPSHEETHEADER psh;
  3455. HPROPSHEETPAGE hpsp[1];
  3456. hpsp[0] = hPage;
  3457. ZeroMemory(&psh,sizeof(psh));
  3458. psh.dwSize = sizeof(psh);
  3459. psh.dwFlags = PSH_DEFAULT;
  3460. psh.nPages = 1;
  3461. psh.phpage = hpsp;
  3462. CString str=_T("");
  3463. str.LoadString(IDS_SECURITY_PROPERTIES);
  3464. ObjName = ObjName + str;
  3465. psh.pszCaption = (LPCTSTR)ObjName;
  3466. psh.hwndParent = pResult->GetSnapin()->GetParentWindow();
  3467. int nRet = (int)PropertySheet(&psh);
  3468. }
  3469. }
  3470. }
  3471. break;
  3472. }
  3473. case IDM_SAVEAS: {
  3474. PEDITTEMPLATE pTemplate;
  3475. CString strDefExt;
  3476. CString strFilters;
  3477. CString strNewfile;
  3478. HWND hwndParent;
  3479. SCESTATUS status;
  3480. PSCE_ERROR_LOG_INFO ErrLog;
  3481. pTemplate = GetTemplate(pFolder->GetInfFile());
  3482. strDefExt.LoadString(IDS_LOGFILE_DEF_EXT);
  3483. strFilters.LoadString(IDS_PROFILE_FILTER);
  3484. m_pConsole->GetMainWindow(&hwndParent);
  3485. // Translate filter into commdlg format (lots of \0)
  3486. LPTSTR szFilter = strFilters.GetBuffer(0); // modify the buffer in place
  3487. LPTSTR pch = szFilter;
  3488. // MFC delimits with '|' not '\0'
  3489. while ((pch = _tcschr(pch, '|')) != NULL)
  3490. *pch++ = '\0';
  3491. // do not call ReleaseBuffer() since the string contains '\0' characters
  3492. strNewfile = pFolder->GetInfFile();
  3493. OPENFILENAME ofn;
  3494. ::ZeroMemory (&ofn, sizeof (OPENFILENAME));
  3495. ofn.lStructSize = sizeof(OPENFILENAME);
  3496. ofn.lpstrFilter = szFilter;
  3497. ofn.lpstrFile = strNewfile.GetBuffer(MAX_PATH),
  3498. ofn.nMaxFile = MAX_PATH;
  3499. ofn.lpstrDefExt = strDefExt,
  3500. ofn.hwndOwner = m_hwndParent;
  3501. ofn.Flags = OFN_HIDEREADONLY |
  3502. OFN_OVERWRITEPROMPT |
  3503. OFN_DONTADDTORECENT|
  3504. OFN_NOREADONLYRETURN |
  3505. OFN_PATHMUSTEXIST |
  3506. OFN_EXPLORER;
  3507. if (GetSaveFileName(&ofn)) {
  3508. strNewfile.ReleaseBuffer();
  3509. //
  3510. // No need to check if this is the same file or not since the
  3511. // CEditTemplate::Save will handle that
  3512. //
  3513. if (!pTemplate->Save(strNewfile)) {
  3514. MyFormatMessage(
  3515. SCESTATUS_ACCESS_DENIED,
  3516. 0,
  3517. NULL,
  3518. strFilters
  3519. );
  3520. strFilters += strNewfile;
  3521. strNewfile.LoadString(IDS_SAVE_FAILED);
  3522. ::MessageBox( hwndParent, strFilters, strNewfile, MB_OK );
  3523. }
  3524. else
  3525. {
  3526. //
  3527. // At this point the new template has succesfully been written, so refresh
  3528. // the template that was "save as'd" back to its original state.
  3529. //
  3530. if (0 != _wcsicmp(strNewfile, pTemplate->GetInfName()))
  3531. {
  3532. DWORD dwErr = pTemplate->RefreshTemplate(0);
  3533. if ( 0 != dwErr )
  3534. {
  3535. CString strErr;
  3536. MyFormatResMessage (SCESTATUS_SUCCESS, dwErr, NULL, strErr);
  3537. AfxMessageBox(strErr);
  3538. break;;
  3539. }
  3540. }
  3541. //
  3542. // find the parent node and refresh locations.
  3543. //
  3544. if ( m_pScope )
  3545. {
  3546. hr = m_pScope->GetParentItem(pFolder->GetScopeItem()->ID,
  3547. &pItemChild,
  3548. &FindCookie
  3549. );
  3550. if ( SUCCEEDED(hr) )
  3551. {
  3552. //
  3553. // do not need to refresh the old location, just refresh the new location (maybe same)
  3554. //
  3555. int npos = strNewfile.ReverseFind(L'\\');
  3556. CString strOldfile = pFolder->GetInfFile();
  3557. int npos2 = strOldfile.ReverseFind(L'\\');
  3558. // TODO: check and see if npos should be compared to -1 here
  3559. if ( npos && (npos != npos2 ||
  3560. _wcsnicmp((LPCTSTR)strNewfile,
  3561. (LPCTSTR)strOldfile, npos) != 0) )
  3562. {
  3563. //
  3564. // a different location is specified
  3565. // find grand parent (in order to add the location)
  3566. //
  3567. HSCOPEITEM GrandParent;
  3568. MMC_COOKIE GrandCookie;
  3569. hr = m_pScope->GetParentItem(pItemChild,
  3570. &GrandParent,
  3571. &GrandCookie
  3572. );
  3573. if ( SUCCEEDED(hr) ) {
  3574. //
  3575. // check if a new location is specified,
  3576. // if it is, add the location to registry and scope pane
  3577. //
  3578. AddTemplateLocation((CFolder *)GrandCookie,
  3579. strNewfile,
  3580. TRUE, // this is a file name
  3581. TRUE // refresh this location if it already exists
  3582. );
  3583. }
  3584. } else {
  3585. //
  3586. // a new template in the same location, refresh it
  3587. //
  3588. ReloadLocation((CFolder *)FindCookie);
  3589. }
  3590. }
  3591. }
  3592. }
  3593. }
  3594. break;
  3595. }
  3596. case IDM_SAVE: {
  3597. PEDITTEMPLATE pTemplate;
  3598. CString strInf;
  3599. if ( ANALYSIS == pFolder->GetType() ) {
  3600. //
  3601. // analysis
  3602. //
  3603. strInf = GT_COMPUTER_TEMPLATE;
  3604. } else {
  3605. strInf = pFolder->GetInfFile();
  3606. }
  3607. pTemplate = GetTemplate(strInf);
  3608. if (pTemplate && pTemplate->IsDirty()) {
  3609. // pTemplate->Save(pFolder->GetInfFile());
  3610. pTemplate->Save(strInf);
  3611. }
  3612. break;
  3613. }
  3614. case IDM_ADD_REGISTRY:
  3615. case IDM_ADD_ANAL_KEY: {
  3616. // add a result entry
  3617. CRegistryDialog rd;
  3618. rd.SetConsole(m_pConsole);
  3619. rd.SetComponentData(this);
  3620. if ( IDM_ADD_REGISTRY == nCommandID ) {
  3621. rd.SetProfileInfo(GetTemplate(pFolder->GetInfFile()),
  3622. pFolder->GetType() );
  3623. } else {
  3624. rd.SetProfileInfo(GetTemplate(GT_COMPUTER_TEMPLATE),
  3625. pFolder->GetType() );
  3626. rd.SetHandle(SadHandle);
  3627. }
  3628. rd.SetCookie(cookie);
  3629. CThemeContextActivator activator;
  3630. rd.DoModal();
  3631. break;
  3632. }
  3633. case IDM_ADD_ANAL_FILES:
  3634. case IDM_ADD_ANAL_FOLDER:
  3635. if ( IDM_ADD_ANAL_FILES == nCommandID ) {
  3636. hr = AddAnalysisFilesToList(pDataObject, cookie,pFolder->GetType());
  3637. } else if ( IDM_ADD_ANAL_FOLDER == nCommandID ) {
  3638. hr = AddAnalysisFolderToList(pDataObject, cookie,pFolder->GetType());
  3639. }
  3640. if ( SUCCEEDED(hr) )
  3641. {
  3642. DeleteChildrenUnderNode(pFolder);
  3643. if ( pFolder->IsEnumerated() )
  3644. {
  3645. pFolder->Set(FALSE);
  3646. EnumerateScopePane(cookie,pFolder->GetScopeItem()->ID);
  3647. }
  3648. }
  3649. break;
  3650. case IDM_GENERATE:
  3651. hr = OnSaveConfiguration();
  3652. break;
  3653. case IDM_ASSIGN:
  3654. SCESTATUS sceStatus;
  3655. hr = OnAssignConfiguration(&sceStatus);
  3656. break;
  3657. case IDM_SECURE_WIZARD:
  3658. hr = OnSecureWizard();
  3659. break;
  3660. case IDM_APPLY:
  3661. {
  3662. //
  3663. // If the computer template has been changed then save it before we
  3664. // can apply it so we don't lose any changes
  3665. //
  3666. PEDITTEMPLATE pet = GetTemplate(GT_COMPUTER_TEMPLATE);
  3667. if (pet && pet->IsDirty()) {
  3668. pet->Save();
  3669. }
  3670. m_pUIThread->PostThreadMessage(SCEM_APPLY_PROFILE,(WPARAM)(LPCTSTR)SadName,(LPARAM)this);
  3671. break;
  3672. }
  3673. case IDM_REMOVE:
  3674. //
  3675. // delete the location from registry
  3676. //
  3677. DeleteLocationFromReg(pFolder->GetName());
  3678. // pFolder is not deleted after DeleteChildrenUnderNode
  3679. DeleteChildrenUnderNode( pFolder );
  3680. // set focus to the parent, then delete this node
  3681. DeleteThisNode(pFolder);
  3682. break;
  3683. case IDM_DELETE: {
  3684. tmpstr.LoadString(IDS_CONFIRM_DELETE_TEMPLATE);
  3685. if ( IDNO == AfxMessageBox(tmpstr,MB_YESNO, 0) ) {
  3686. return FALSE;
  3687. }
  3688. /*
  3689. SHFILEOPSTRUCT sfo;
  3690. TCHAR *szFile;
  3691. // delete the file
  3692. ZeroMemory(&sfo,sizeof(sfo));
  3693. sfo.wFunc = FO_DELETE;
  3694. sfo.fFlags = FOF_ALLOWUNDO;
  3695. // Must be double NUL terminated;
  3696. szFile = new TCHAR [ lstrlen(pFolder->GetName()) + 2 ];
  3697. lstrcpy(szFile,pFolder->GetName());
  3698. sfo.pFrom = szFile;
  3699. */
  3700. DeleteFile(pFolder->GetName());
  3701. // SHFileOperation returns 0 on success
  3702. // if (!SHFileOperation(&sfo)) {
  3703. // pFolder is not deleted after DeleteChildrenUnderNode
  3704. DeleteChildrenUnderNode( pFolder );
  3705. // set focus to the parent, then delete this node
  3706. DeleteThisNode(pFolder);
  3707. // }
  3708. // delete[] szFile;
  3709. break;
  3710. }
  3711. case IDM_RELOAD:
  3712. if(pFolder->GetType() == LOCALPOL){
  3713. //
  3714. // Reload local policy.
  3715. //
  3716. UnloadSadInfo();
  3717. DeleteTemplate( GT_LOCAL_POLICY );
  3718. DeleteTemplate( GT_EFFECTIVE_POLICY );
  3719. LoadSadInfo( FALSE );
  3720. RefreshAllFolders();
  3721. } else if (pFolder->GetType() == PROFILE) {
  3722. //
  3723. // bug 380290 - do the right thing when refreshing profiles
  3724. //
  3725. CEditTemplate *pet;
  3726. int bSave;
  3727. CString strSavep;
  3728. pet = GetTemplate(pFolder->GetInfFile());
  3729. if (pet->IsDirty()) {
  3730. AfxFormatString1( strSavep, IDS_SAVE_P, pet->GetFriendlyName());
  3731. bSave = AfxMessageBox(strSavep,MB_YESNOCANCEL|MB_ICONQUESTION);
  3732. if (IDYES == bSave) {
  3733. pet->Save();
  3734. } else if (IDCANCEL == bSave) {
  3735. break;
  3736. }
  3737. }
  3738. DWORD dwErr = pet->RefreshTemplate(AREA_ALL);
  3739. if ( 0 != dwErr )
  3740. {
  3741. CString strErr;
  3742. MyFormatResMessage (SCESTATUS_SUCCESS, dwErr, NULL, strErr);
  3743. AfxMessageBox(strErr);
  3744. break;
  3745. }
  3746. RefreshAllFolders();
  3747. } else if (pFolder->GetType() == LOCATIONS) {
  3748. //
  3749. // Refresh location.
  3750. //
  3751. hr = ReloadLocation(pFolder);
  3752. } else {
  3753. //
  3754. // Should never get here
  3755. //
  3756. }
  3757. break;
  3758. case IDM_COPY: {
  3759. if (!SUCCEEDED(OnCopyArea(pFolder->GetInfFile(),pFolder->GetType()))) {
  3760. AfxMessageBox(IDS_COPY_FAILED);
  3761. }
  3762. break;
  3763. }
  3764. case IDM_CUT:
  3765. break;
  3766. case IDM_PASTE:
  3767. OnPasteArea(pFolder->GetInfFile(),pFolder->GetType());
  3768. //
  3769. // after information is pasted, update all views related to the cookie
  3770. //
  3771. if ( m_pConsole ) {
  3772. pFolder->RemoveAllResultItems();
  3773. m_pConsole->UpdateAllViews(NULL , (LPARAM)pFolder, UAV_RESULTITEM_UPDATEALL);
  3774. }
  3775. break;
  3776. default:
  3777. ASSERT(FALSE); // Unknown command!
  3778. break;
  3779. }
  3780. return S_OK;
  3781. }
  3782. //+------------------------------------------------------------------------------------------
  3783. // CComponentDataImpl::RefreshAllFolders
  3784. //
  3785. // Updates all folders that are enumerated and have result items.
  3786. //
  3787. // Returns: The number of folders updated, or -1 if there is an error.
  3788. //
  3789. //-------------------------------------------------------------------------------------------
  3790. int
  3791. CComponentDataImpl::RefreshAllFolders()
  3792. {
  3793. if( !m_pScope ){
  3794. return -1;
  3795. }
  3796. int icnt = 0;
  3797. POSITION pos = m_scopeItemList.GetHeadPosition();
  3798. while(pos){
  3799. CFolder *pFolder = m_scopeItemList.GetNext(pos);
  3800. if(pFolder && pFolder->GetResultListCount() ){
  3801. pFolder->RemoveAllResultItems();
  3802. m_pConsole->UpdateAllViews(NULL, (LPARAM)pFolder, UAV_RESULTITEM_UPDATEALL);
  3803. icnt++;
  3804. }
  3805. }
  3806. return icnt;
  3807. }
  3808. ///////////////////////////////////////////////////////////////////////////
  3809. // Method: AddTemplateLocation
  3810. //
  3811. // Synopsis: Add a template location if it does not exist
  3812. // and if requested, refresh the location if it exists.
  3813. //
  3814. // Arguments: [pParent] - The parent node under which to add the new node
  3815. // [NameStr] - The display name of the new node
  3816. // [theCookie] - the folder's cookie if it already exists, or NULL
  3817. //
  3818. // Returns: TRUE = the folder already exists
  3819. // FALSE = the folder does not exist
  3820. //
  3821. ////////////////////////////////////////////////////////////////////
  3822. BOOL
  3823. CComponentDataImpl::AddTemplateLocation(CFolder *pParent,
  3824. CString szName,
  3825. BOOL bIsFileName,
  3826. BOOL bRefresh
  3827. )
  3828. {
  3829. int npos;
  3830. if ( bIsFileName ) {
  3831. npos = szName.ReverseFind(L'\\');
  3832. } else {
  3833. npos = szName.GetLength();
  3834. }
  3835. CString strTmp = szName.Left(npos);
  3836. LPTSTR sz = strTmp.GetBuffer(MAX_PATH);
  3837. //
  3838. // Can't put '\' in the registry, so convert to '/'
  3839. //
  3840. while (sz = wcschr(sz,L'\\')) {
  3841. *sz = L'/';
  3842. }
  3843. strTmp.ReleaseBuffer();
  3844. CString strLocationKey;
  3845. strLocationKey.LoadString(IDS_TEMPLATE_LOCATION_KEY);
  3846. BOOL bRet = FALSE;
  3847. HKEY hLocKey = NULL;
  3848. HKEY hKey = NULL;
  3849. DWORD dwDisp = 0;
  3850. DWORD rc = E_FAIL;
  3851. //
  3852. // Bug 119208: Store in HKCU rather than in HKLM
  3853. //
  3854. rc = RegCreateKeyEx(
  3855. HKEY_CURRENT_USER,
  3856. strLocationKey,
  3857. 0,
  3858. L"",
  3859. 0,
  3860. KEY_READ | KEY_WRITE | KEY_CREATE_SUB_KEY ,
  3861. NULL,
  3862. &hLocKey,
  3863. &dwDisp);
  3864. if (ERROR_SUCCESS == rc) {
  3865. if (ERROR_SUCCESS == RegCreateKeyEx(
  3866. hLocKey,
  3867. strTmp,
  3868. 0,
  3869. L"",
  3870. 0,
  3871. KEY_WRITE | KEY_CREATE_SUB_KEY,
  3872. NULL,
  3873. &hKey,
  3874. &dwDisp)) {
  3875. bRet = TRUE;
  3876. RegCloseKey(hKey);
  3877. }
  3878. RegCloseKey(hLocKey);
  3879. }
  3880. if ( bRet ) {
  3881. //
  3882. // key is added to registry, create the node in scope pane
  3883. //
  3884. MMC_COOKIE FindCookie;
  3885. CFolder *pNewParent;
  3886. if (!pParent) {
  3887. pNewParent = m_ConfigFolder;
  3888. } else {
  3889. pNewParent = pParent;
  3890. }
  3891. if (!IsNameInChildrenScopes(pNewParent, //pParent,
  3892. szName.Left(npos),
  3893. &FindCookie)) {
  3894. CreateAndAddOneNode(pNewParent, //pParent,
  3895. (LPTSTR((LPCTSTR)(szName.Left(npos)))),
  3896. NULL,
  3897. LOCATIONS,
  3898. TRUE);
  3899. }
  3900. if ( FindCookie && bRefresh ) {
  3901. ReloadLocation((CFolder *)FindCookie);
  3902. }
  3903. }
  3904. return bRet;
  3905. }
  3906. ///////////////////////////////////////////////////////////////////////////
  3907. // Method: IsNameInChildrenScopes
  3908. //
  3909. // Synopsis: detects if a node already exists under the subtree of this node.
  3910. // The existence is determined by the folder name string comparison.
  3911. //
  3912. // Arguments: [pParent] - The parent node under which to add the new node
  3913. // [NameStr] - The display name of the new node
  3914. // [theCookie] - the folder's cookie if it already exists, or NULL
  3915. //
  3916. // Returns: TRUE = the folder already exists
  3917. // FALSE = the folder does not exist
  3918. //
  3919. ////////////////////////////////////////////////////////////////////
  3920. BOOL
  3921. CComponentDataImpl::IsNameInChildrenScopes(CFolder* pParent,
  3922. LPCTSTR NameStr,
  3923. MMC_COOKIE *theCookie)
  3924. {
  3925. HSCOPEITEM pItemChild=NULL;
  3926. MMC_COOKIE lCookie=NULL;
  3927. CFolder* pFolder = 0;
  3928. HRESULT hr = S_OK;
  3929. LPSCOPEDATAITEM psdi = 0;
  3930. HSCOPEITEM hid = 0;
  3931. if (pParent)
  3932. {
  3933. psdi = pParent->GetScopeItem();
  3934. if (psdi)
  3935. hid = psdi->ID;
  3936. }
  3937. hr = m_pScope->GetChildItem(hid, &pItemChild, &lCookie);
  3938. // find a child item
  3939. while ( SUCCEEDED(hr) )
  3940. {
  3941. pFolder = (CFolder*)lCookie;
  3942. if ( pFolder )
  3943. {
  3944. if ( _wcsicmp(pFolder->GetName(), NameStr) == 0 )
  3945. {
  3946. if ( theCookie )
  3947. *theCookie = lCookie;
  3948. return TRUE;
  3949. }
  3950. }
  3951. hr = m_pScope->GetNextItem(pItemChild, &pItemChild, &lCookie);
  3952. }
  3953. if ( theCookie )
  3954. *theCookie = NULL;
  3955. return FALSE;
  3956. }
  3957. //+--------------------------------------------------------------------------
  3958. //
  3959. // Method: CreateAndAddOneNode
  3960. //
  3961. // Synopsis: Creates and adds a folder to the scope pane
  3962. //
  3963. //
  3964. // Arguments: [pParent] - The parent node under which to add the new node
  3965. // [Name] - The display name of the new node
  3966. // [Desc] - The description of the new node
  3967. // [type] - The folder type of the new node
  3968. // [bChildren] - True if there are children folders under the new node
  3969. // [szInfFile] - The name of the Inf file associated with the new node
  3970. // [pData] - A pointer to extra data
  3971. //
  3972. // Returns: The CFolder created if successful, NULL otherwise
  3973. //
  3974. // History:
  3975. //
  3976. //---------------------------------------------------------------------------
  3977. CFolder*
  3978. CComponentDataImpl::CreateAndAddOneNode(CFolder* pParent,
  3979. LPCTSTR Name,
  3980. LPCTSTR Desc,
  3981. FOLDER_TYPES type,
  3982. BOOL bChildren,
  3983. LPCTSTR szInfFile,
  3984. LPVOID pData,
  3985. DWORD status)
  3986. {
  3987. DWORD dwMode;
  3988. HRESULT hr;
  3989. //
  3990. // The new node inherits its parent's SCE mode
  3991. //
  3992. if (pParent) {
  3993. dwMode = pParent->GetMode();
  3994. } else {
  3995. return NULL;
  3996. }
  3997. CFolder* folder = new CFolder();
  3998. if (!folder) {
  3999. return NULL;
  4000. }
  4001. //
  4002. // Create the folder objects with static data
  4003. //
  4004. //
  4005. // Find the icon index for the folder type
  4006. //
  4007. int nImage = GetScopeImageIndex(type, status);
  4008. hr = folder->Create( Name,
  4009. Desc,
  4010. szInfFile,
  4011. nImage,
  4012. nImage,
  4013. type,
  4014. bChildren,
  4015. dwMode,
  4016. pData);
  4017. if (FAILED(hr)) {
  4018. delete folder;
  4019. return NULL;
  4020. }
  4021. m_scopeItemList.AddTail(folder);
  4022. HSCOPEITEM hItem = NULL;
  4023. LONG_PTR pCookie;
  4024. CString strThis, strNext;
  4025. switch(type){
  4026. case AREA_REGISTRY_ANALYSIS:
  4027. case AREA_FILESTORE_ANALYSIS:
  4028. case REG_OBJECTS:
  4029. case FILE_OBJECTS:
  4030. //
  4031. // Insert items in alpha order.
  4032. //
  4033. if( m_pScope->GetChildItem(pParent->GetScopeItem()->ID, &hItem, &pCookie) == S_OK && pCookie){
  4034. folder->GetScopeItem()->lParam = (LPARAM)folder;
  4035. folder->GetDisplayName( strThis, 0);
  4036. folder->GetScopeItem()->mask &= ~(SDI_PARENT | SDI_PREVIOUS);
  4037. while(hItem){
  4038. reinterpret_cast<CFolder *>(pCookie)->GetDisplayName(strNext, 0);
  4039. int i = lstrcmpi( strThis, strNext );
  4040. if( i < 0 ){
  4041. folder->GetScopeItem()->relativeID = hItem;
  4042. folder->GetScopeItem()->mask |= SDI_NEXT;
  4043. break;
  4044. }
  4045. if( m_pScope->GetNextItem(hItem, &hItem, &pCookie) != S_OK){
  4046. hItem = NULL;
  4047. }
  4048. }
  4049. }
  4050. break;
  4051. }
  4052. if(hItem == NULL){
  4053. folder->GetScopeItem()->mask &= ~(SDI_PREVIOUS | SDI_NEXT);
  4054. folder->GetScopeItem()->mask |= SDI_PARENT;
  4055. folder->GetScopeItem()->relativeID = pParent->GetScopeItem()->ID;
  4056. }
  4057. //
  4058. // Set the folder as the cookie
  4059. //
  4060. folder->GetScopeItem()->displayname = MMC_CALLBACK;
  4061. folder->GetScopeItem()->mask |= SDI_PARAM;
  4062. folder->GetScopeItem()->lParam = reinterpret_cast<LPARAM>(folder);
  4063. folder->SetCookie(reinterpret_cast<MMC_COOKIE>(folder));
  4064. m_pScope->InsertItem(folder->GetScopeItem());
  4065. folder->GetScopeItem()->relativeID = pParent->GetScopeItem()->ID;
  4066. //
  4067. // Note - On return, the ID member of 'GetScopeItem()'
  4068. // contains the handle to the newly inserted item!
  4069. //
  4070. ASSERT(folder->GetScopeItem()->ID != NULL);
  4071. return folder;
  4072. }
  4073. void CComponentDataImpl::DeleteChildrenUnderNode(CFolder* pParent)
  4074. {
  4075. HSCOPEITEM pItemChild=NULL;
  4076. MMC_COOKIE lCookie=NULL;
  4077. CFolder* pFolder=NULL;
  4078. pItemChild = NULL;
  4079. HRESULT hr = E_FAIL;
  4080. if (pParent && pParent->GetScopeItem()) {
  4081. hr = m_pScope->GetChildItem(pParent->GetScopeItem()->ID, &pItemChild, &lCookie);
  4082. }
  4083. // find a child item
  4084. while ( pItemChild ) {
  4085. pFolder = (CFolder*)lCookie;
  4086. if ( pFolder )
  4087. DeleteChildrenUnderNode(pFolder); // delete children first
  4088. // get next pointer
  4089. hr = m_pScope->GetNextItem(pItemChild, &pItemChild, &lCookie);
  4090. // delete this node
  4091. if ( pFolder)
  4092. DeleteThisNode(pFolder);
  4093. }
  4094. }
  4095. void CComponentDataImpl::DeleteThisNode(CFolder* pNode)
  4096. {
  4097. ASSERT(pNode);
  4098. POSITION pos=NULL;
  4099. // delete from the m_scopeItemList
  4100. if ( FindObject((MMC_COOKIE)pNode, &pos) ) {
  4101. if ( pos ) {
  4102. m_scopeItemList.RemoveAt(pos);
  4103. }
  4104. }
  4105. pos = NULL;
  4106. LONG_PTR fullKey;
  4107. CDialog *pDlg = MatchNextPopupDialog(
  4108. pos,
  4109. (LONG_PTR)pNode,
  4110. &fullKey
  4111. );
  4112. while( pDlg ){
  4113. m_scopeItemPopups.RemoveKey( fullKey );
  4114. pDlg->ShowWindow(SW_HIDE);
  4115. if(m_pUIThread){
  4116. m_pUIThread->PostThreadMessage(
  4117. SCEM_DESTROY_DIALOG,
  4118. (WPARAM)pDlg,
  4119. (LPARAM)this
  4120. );
  4121. }
  4122. pDlg = NULL;
  4123. if(!pos){
  4124. break;
  4125. }
  4126. pDlg = MatchNextPopupDialog(
  4127. pos,
  4128. (LONG_PTR)pNode,
  4129. &fullKey
  4130. );
  4131. }
  4132. if (m_pScope && pNode && pNode->GetScopeItem()) {
  4133. HRESULT hr = m_pScope->DeleteItem(pNode->GetScopeItem()->ID, TRUE);
  4134. }
  4135. // delete the node
  4136. delete pNode;
  4137. }
  4138. ///////////////////////////////////////////////////////////////////////////////
  4139. // IExtendControlbar implementation
  4140. //
  4141. STDMETHODIMP CSnapin::SetControlbar(LPCONTROLBAR pControlbar)
  4142. {
  4143. TRACE(_T("CSnapin::SetControlbar(%ld)\n"),pControlbar);
  4144. return S_FALSE;
  4145. }
  4146. STDMETHODIMP CSnapin::ControlbarNotify(MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  4147. {
  4148. HRESULT hr=S_FALSE;
  4149. switch (event) {
  4150. case MMCN_BTN_CLICK:
  4151. TCHAR szMessage[MAX_PATH];
  4152. wsprintf(szMessage, _T("CommandID %ld"),param);
  4153. AfxMessageBox(szMessage);
  4154. break;
  4155. case MMCN_SELECT:
  4156. // TRACE(_T("CSnapin::ControlbarNotify - MMCN_SEL_CHANGE\n"));
  4157. HandleExtToolbars(arg, param);
  4158. break;
  4159. /* case MMCN_RENAME:
  4160. TRACE(_T("CSnapin::ControlbarNotify - MMCN_RENAME (ignored)\n"));
  4161. break;
  4162. case MMCN_CLICK:
  4163. TRACE(_T("CSnapin::ControlbarNotify - MMCN_CLICK (ignored)\n"));
  4164. break;
  4165. case MMCN_DELETE:
  4166. TRACE(_T("CSnapin::ControlbarNotify - MMCN_DELETE (ignored)\n"));
  4167. break;
  4168. /* TRACEMMCN(MMCN_ACTIVATE)
  4169. TRACEMMCN(MMCN_ADD_IMAGES)
  4170. TRACEMMCN(MMCN_CONTEXTMENU)
  4171. TRACEMMCN(MMCN_DBLCLICK)
  4172. TRACEMMCN(MMCN_EXPAND)
  4173. TRACEMMCN(MMCN_MINIMIZED)
  4174. TRACEMMCN(MMCN_PROPERTY_CHANGE)
  4175. TRACEMMCN(MMCN_REMOVE_CHILDREN)
  4176. TRACEMMCN(MMCN_SHOW)
  4177. TRACEMMCN(MMCN_VIEW_CHANGE)
  4178. */
  4179. default:
  4180. ASSERT(FALSE); // Unhandle event
  4181. }
  4182. return S_OK;
  4183. }
  4184. // This compares two data objects to see if they are the same object.
  4185. // return
  4186. // S_OK if equal otherwise S_FALSE
  4187. //
  4188. // Note: check to make sure both objects belong to the snap-in.
  4189. //
  4190. STDMETHODIMP CSnapin::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  4191. {
  4192. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  4193. return E_POINTER;
  4194. // Make sure both data object are mine
  4195. HRESULT hr = S_FALSE;
  4196. INTERNAL *pA = ExtractInternalFormat(lpDataObjectA);
  4197. INTERNAL *pB = ExtractInternalFormat(lpDataObjectB);
  4198. if (pA != NULL && pB != NULL) {
  4199. hr = (*pA == *pB) ? S_OK : S_FALSE;
  4200. }
  4201. FREE_INTERNAL(pA);
  4202. FREE_INTERNAL(pB);
  4203. return hr;
  4204. }
  4205. // This compare is used to sort the item's in the listview
  4206. //
  4207. // Parameters:
  4208. //
  4209. // lUserParam - user param passed in when IResultData::Sort() was called
  4210. // cookieA - first item to compare
  4211. // cookieB - second item to compare
  4212. // pnResult [in, out]- contains the col on entry,
  4213. // -1, 0, 1 based on comparison for return value.
  4214. //
  4215. // Note: Assum sort is ascending when comparing.
  4216. STDMETHODIMP CSnapin::Compare(LPARAM lUserParam, MMC_COOKIE cookieA, MMC_COOKIE cookieB, int* pnResult)
  4217. {
  4218. if (pnResult == NULL) {
  4219. ASSERT(FALSE);
  4220. return E_POINTER;
  4221. }
  4222. // check col range
  4223. int nCol = *pnResult;
  4224. ASSERT(nCol >=0 && nCol< 3);
  4225. *pnResult = 0;
  4226. if ( nCol < 0 || nCol >= 3)
  4227. return S_OK;
  4228. CString strA;
  4229. CString strB;
  4230. RESULTDATAITEM rid;
  4231. CResult* pDataA = reinterpret_cast<CResult*>(cookieA);
  4232. CResult* pDataB = reinterpret_cast<CResult*>(cookieB);
  4233. ASSERT(pDataA != NULL && pDataB != NULL);
  4234. ZeroMemory(&rid,sizeof(rid));
  4235. rid.mask = RDI_STR;
  4236. rid.bScopeItem = FALSE;
  4237. rid.nCol = nCol;
  4238. rid.lParam = cookieA;
  4239. GetDisplayInfo(&rid);
  4240. strA = rid.str;
  4241. rid.lParam = cookieB;
  4242. GetDisplayInfo(&rid);
  4243. strB = rid.str;
  4244. if (strA.IsEmpty()) {
  4245. *pnResult = strB.IsEmpty() ? 0 : 1;
  4246. } else if (strB.IsEmpty()) {
  4247. *pnResult = -1;
  4248. } else {
  4249. //
  4250. // Compare in a locale dependant manner
  4251. //
  4252. // Subtract 2 from CS to make result equivalent to strcmp
  4253. //
  4254. *pnResult = CompareString(LOCALE_SYSTEM_DEFAULT,
  4255. NORM_IGNORECASE,
  4256. (LPCTSTR)strA,-1, (LPCTSTR)strB,-1) -2;
  4257. }
  4258. return S_OK;
  4259. }
  4260. void CSnapin::HandleStandardVerbs(LPARAM arg, LPDATAOBJECT lpDataObject)
  4261. {
  4262. if (lpDataObject == NULL) {
  4263. return;
  4264. }
  4265. INTERNAL* pAllInternal = ExtractInternalFormat(lpDataObject);
  4266. INTERNAL* pInternal = pAllInternal;
  4267. if(pAllInternal &&
  4268. pAllInternal->m_cookie == (MMC_COOKIE)MMC_MULTI_SELECT_COOKIE ){
  4269. pInternal++;
  4270. }
  4271. BOOL bSelect = HIWORD(arg);
  4272. BOOL bScope = LOWORD(arg);
  4273. if (!bSelect) {
  4274. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES,HIDDEN,TRUE);
  4275. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE,HIDDEN,TRUE);
  4276. m_pConsoleVerb->SetVerbState(MMC_VERB_OPEN,HIDDEN,TRUE);
  4277. return;
  4278. }
  4279. // You should crack the data object and enable/disable/hide standard
  4280. // commands appropriately. The standard commands are reset everytime you get
  4281. // called. So you must reset them back.
  4282. // arg == TRUE -> Selection occured in the Scope view
  4283. // arg == FALSE -> Selection occured in the Result view
  4284. // add for delete operations
  4285. if (m_pConsoleVerb && pInternal) {
  4286. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, FALSE);
  4287. if (pInternal->m_type == CCT_SCOPE) {
  4288. MMC_COOKIE cookie = pInternal->m_cookie;
  4289. if ( cookie ) {
  4290. CFolder *pFolder = (CFolder*)cookie;
  4291. if (pFolder->GetType() == REG_OBJECTS ||
  4292. pFolder->GetType() == FILE_OBJECTS) {
  4293. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES,ENABLED,TRUE);
  4294. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  4295. } else {
  4296. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES,HIDDEN,TRUE);
  4297. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  4298. }
  4299. }
  4300. m_pConsoleVerb->SetVerbState(MMC_VERB_OPEN,ENABLED,TRUE);
  4301. }
  4302. if ( pInternal->m_type == CCT_RESULT ) {
  4303. if ( pInternal->m_cookie != NULL ) {
  4304. RESULT_TYPES type = ((CResult *)pInternal->m_cookie)->GetType();
  4305. if ( type == ITEM_PROF_GROUP ||
  4306. type == ITEM_PROF_REGSD ||
  4307. type == ITEM_PROF_FILESD
  4308. ) {
  4309. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  4310. }
  4311. if (type != ITEM_OTHER) {
  4312. if (pInternal->m_cookie != (MMC_COOKIE)MMC_MULTI_SELECT_COOKIE) {
  4313. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  4314. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_PROPERTIES);
  4315. } else {
  4316. //
  4317. // Multi select properties not supported (yet)
  4318. //
  4319. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, FALSE);
  4320. }
  4321. }
  4322. }
  4323. } else if ( pInternal->m_type == CCT_SCOPE ) {
  4324. CFolder *pFolder = (CFolder *)pInternal->m_cookie;
  4325. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
  4326. m_pConsoleVerb->SetDefaultVerb(MMC_VERB_OPEN);
  4327. if( NONE == pInternal->m_foldertype && bSelect && bScope ) //Raid #257461, 4/19/2001
  4328. {
  4329. m_pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, HIDDEN,TRUE);
  4330. }
  4331. //
  4332. // for scope nodes, only the location and template are allowed to delete
  4333. //
  4334. if ( pFolder != NULL ) {
  4335. FOLDER_TYPES fType = pFolder->GetType();
  4336. //
  4337. // do not expose 'delete' menu option in single template mode
  4338. //
  4339. if ( LOCATIONS == fType || // PROFILE == fType) {
  4340. ( fType == PROFILE &&
  4341. !( pFolder->GetModeBits() & MB_SINGLE_TEMPLATE_ONLY )) ) {
  4342. if(fType == PROFILE && (pFolder->GetState() & CFolder::state_Unknown) ){
  4343. // We must load the template and find out if it is a valid
  4344. // configuration template.
  4345. if(!GetTemplate( pFolder->GetInfFile(), AREA_USER_SETTINGS)){
  4346. pFolder->SetState( CFolder::state_InvalidTemplate, ~CFolder::state_Unknown );
  4347. } else {
  4348. pFolder->SetState( 0, ~CFolder::state_Unknown );
  4349. }
  4350. }
  4351. if( fType != PROFILE || !(pFolder->GetState() & CFolder::state_InvalidTemplate) ) {
  4352. if (CAttribute::m_nDialogs == 0) {
  4353. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, HIDDEN, FALSE);
  4354. m_pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  4355. }
  4356. }
  4357. }
  4358. }
  4359. }
  4360. }
  4361. if (pAllInternal) {
  4362. FREE_INTERNAL(pAllInternal);
  4363. }
  4364. }
  4365. void CSnapin::HandleExtToolbars(LPARAM arg, LPARAM param)
  4366. {
  4367. /*
  4368. static BOOL bSwap=FALSE;
  4369. INTERNAL* pInternal = NULL;
  4370. HRESULT hr;
  4371. if (arg == TRUE) // Scope view selection. [0] Old dataobject in selection
  4372. { // [1] New dataobject in selection
  4373. LPDATAOBJECT rgpDataObject[2] = {NULL, NULL};
  4374. LPDATAOBJECT* ppDataObject = reinterpret_cast<LPDATAOBJECT*>(param);
  4375. rgpDataObject[0] = *ppDataObject;
  4376. ppDataObject++;
  4377. rgpDataObject[1] = *ppDataObject;
  4378. if (rgpDataObject[1] != NULL)
  4379. pInternal = ExtractInternalFormat(rgpDataObject[1]); // The new selection
  4380. // Attach the toolbars to the window
  4381. hr = m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar1);
  4382. ASSERT(SUCCEEDED(hr));
  4383. hr = m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar2);
  4384. ASSERT(SUCCEEDED(hr));
  4385. }
  4386. else // Result view selection
  4387. {
  4388. LPDATAOBJECT lpDataObject = reinterpret_cast<LPDATAOBJECT>(param);
  4389. if (lpDataObject != NULL)
  4390. pInternal = ExtractInternalFormat(lpDataObject);
  4391. // Attach the toolbars to the window
  4392. hr = m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar1);
  4393. ASSERT(SUCCEEDED(hr));
  4394. hr = m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar2);
  4395. ASSERT(SUCCEEDED(hr));
  4396. }
  4397. if (pInternal != NULL)
  4398. {
  4399. long cookie = pInternal->m_cookie;
  4400. if (pInternal->m_type == CCT_SCOPE) // Scope Item
  4401. {
  4402. m_pToolbar1->SetButtonState(1, ENABLED, FALSE); // 1 = CMD ID
  4403. m_pToolbar1->SetButtonState(2, CHECKED, TRUE); // 2 = CMD ID
  4404. m_pToolbar1->SetButtonState(3, HIDDEN, TRUE); // 3 = CMD ID
  4405. m_pToolbar1->SetButtonState(4, INDETERMINATE, TRUE); // 4 = CMD ID
  4406. m_pToolbar1->SetButtonState(5, BUTTONPRESSED, TRUE); // 5 = CMD ID
  4407. }
  4408. else // Result Item
  4409. {
  4410. bSwap = !bSwap;
  4411. // Above is the correct way
  4412. m_pToolbar2->SetButtonState(20, CHECKED, bSwap);
  4413. m_pToolbar2->SetButtonState(30, HIDDEN, bSwap);
  4414. m_pToolbar2->SetButtonState(40, INDETERMINATE, bSwap);
  4415. m_pToolbar2->SetButtonState(50, BUTTONPRESSED, bSwap);
  4416. }
  4417. }
  4418. else
  4419. {
  4420. // We are no longer selected.
  4421. // You could detach your toolbars at this point. If you don't the
  4422. // console will automatically do it for you.
  4423. }
  4424. if (pInternal)
  4425. FREE_INTERNAL(pInternal);
  4426. */
  4427. }
  4428. /*
  4429. template <> void AFXAPI DestructElements <CDialog> ( CDialog* pDlg, int nCount )
  4430. {
  4431. for ( int i = 0; i < nCount; i++, pDlg++ )
  4432. {
  4433. delete pDlg;
  4434. }
  4435. }*/
  4436. //+--------------------------------------------------------------------------
  4437. //
  4438. // Method: GetTemplate
  4439. //
  4440. // Synopsis: Get the CEditTemplate for the given INF file, checking first
  4441. // in the cache of loaded CEditTemplates or creating a new one
  4442. // if the INF file has not yet been loaded.
  4443. //
  4444. // Arguments: [szInfFile] - The path and name of the INF file to retrieve
  4445. // [aiArea] - The SCE area that we're interested for the template
  4446. // *[pErr] - [out] a PDWORD to get error information
  4447. //
  4448. // Returns: A pointer to the CEditTemplate requested, or NULL if it's not
  4449. // available.
  4450. // *[pErr] - the resource id of an error string, if an error occurs
  4451. //
  4452. //
  4453. // History:
  4454. //
  4455. //---------------------------------------------------------------------------
  4456. PEDITTEMPLATE
  4457. CComponentDataImpl::GetTemplate(LPCTSTR szInfFile,AREA_INFORMATION aiArea, DWORD *pErr)
  4458. {
  4459. PEDITTEMPLATE pTemplateInfo = NULL;
  4460. BOOL bNewTemplate = FALSE;
  4461. PVOID pHandle = NULL;
  4462. SCESTATUS rc=0;
  4463. LPTSTR szKey;
  4464. if (pErr) {
  4465. *pErr = 0;
  4466. }
  4467. ASSERT(szInfFile);
  4468. if (!szInfFile) {
  4469. return NULL;
  4470. }
  4471. //
  4472. // Allocate space for key.
  4473. //
  4474. szKey = new TCHAR[ lstrlen( szInfFile ) + 1];
  4475. if(!szKey){
  4476. return NULL;
  4477. }
  4478. lstrcpy(szKey, szInfFile);
  4479. _wcslwr( szKey );
  4480. //
  4481. // Find pTemplateInfo in our cache
  4482. //
  4483. m_Templates.Lookup(szKey, pTemplateInfo);
  4484. //
  4485. // If it's not there then create a new one
  4486. //
  4487. if (!pTemplateInfo) {
  4488. bNewTemplate = TRUE;
  4489. pTemplateInfo = new CEditTemplate;
  4490. if (!pTemplateInfo) {
  4491. if (pErr) {
  4492. *pErr = IDS_ERROR_CANT_OPEN_PROFILE;
  4493. }
  4494. goto done;
  4495. }
  4496. pTemplateInfo->SetInfFile(szInfFile);
  4497. pTemplateInfo->SetNotificationWindow(m_pNotifier);
  4498. pTemplateInfo->pTemplate = NULL;
  4499. }
  4500. if (GetModeBits() & MB_WRITE_THROUGH) {
  4501. pTemplateInfo->SetWriteThrough(TRUE);
  4502. }
  4503. //
  4504. // Check that the pTemplateInfo has the area that we're looking for, otherwise
  4505. // load that area
  4506. //
  4507. if (!pTemplateInfo->CheckArea(aiArea)) {
  4508. //
  4509. // Don't reload the areas we already have since they may be dirty and we'll have a
  4510. // huge memory problem.
  4511. //
  4512. aiArea &= ~(pTemplateInfo->QueryArea());
  4513. if ((lstrcmp(GT_COMPUTER_TEMPLATE,szInfFile) == 0) ||
  4514. (lstrcmp(GT_LAST_INSPECTION,szInfFile) == 0)) {
  4515. //
  4516. // Analysis pane areas from jet database, not INF files
  4517. //
  4518. SCETYPE sceType;
  4519. PSCE_ERROR_LOG_INFO perr = NULL;
  4520. if (lstrcmp(GT_COMPUTER_TEMPLATE,szInfFile) == 0) {
  4521. sceType = SCE_ENGINE_SMP;
  4522. } else {
  4523. sceType = SCE_ENGINE_SAP;
  4524. pTemplateInfo->SetNoSave(TRUE);
  4525. }
  4526. pTemplateInfo->SetFriendlyName( SadName );
  4527. pTemplateInfo->SetProfileHandle(SadHandle);
  4528. pTemplateInfo->SetComponentDataImpl(this);
  4529. rc = SceGetSecurityProfileInfo(SadHandle, // hProfile
  4530. sceType, // Profile type
  4531. aiArea, // Area
  4532. &(pTemplateInfo->pTemplate), // SCE_PROFILE_INFO [out]
  4533. &perr); // Error List [out]
  4534. if (SCESTATUS_SUCCESS != rc) {
  4535. if (bNewTemplate) {
  4536. delete pTemplateInfo;
  4537. }
  4538. if (pErr) {
  4539. *pErr = IDS_ERROR_CANT_GET_PROFILE_INFO;
  4540. }
  4541. pTemplateInfo = NULL;
  4542. goto done;
  4543. }
  4544. } else if ((lstrcmp(GT_LOCAL_POLICY,szInfFile) == 0) ||
  4545. (lstrcmp(GT_EFFECTIVE_POLICY,szInfFile) == 0)) {
  4546. //
  4547. // Local Policy pane areas from jet database, not INF files
  4548. //
  4549. SCETYPE sceType;
  4550. PSCE_ERROR_LOG_INFO perr = NULL;
  4551. PVOID tempSad;
  4552. tempSad = SadHandle;
  4553. if (lstrcmp(GT_LOCAL_POLICY,szInfFile) == 0) {
  4554. sceType = SCE_ENGINE_SYSTEM;
  4555. } else {
  4556. sceType = SCE_ENGINE_GPO;
  4557. }
  4558. pTemplateInfo->SetNoSave(TRUE);
  4559. pTemplateInfo->SetProfileHandle(tempSad);
  4560. pTemplateInfo->SetComponentDataImpl(this);
  4561. rc = SceGetSecurityProfileInfo(tempSad, // hProfile
  4562. sceType, // Profile type
  4563. aiArea, // Area
  4564. &(pTemplateInfo->pTemplate), // SCE_PROFILE_INFO [out]
  4565. &perr); // Error List [out]
  4566. if (SCESTATUS_SUCCESS != rc) {
  4567. //
  4568. // We don't really need the policy template, though it'd be nice
  4569. // We'll be read-only as a non-admin anyway so they can't edit
  4570. //
  4571. // Likewise in a standalone machine the GPO won't be found so we
  4572. // can just ignore that error as expected
  4573. //
  4574. if (sceType == SCE_ENGINE_GPO) {
  4575. if (SCESTATUS_PROFILE_NOT_FOUND == rc) {
  4576. //
  4577. // No GPO, so we're on a standalone. No need to give warnings
  4578. //
  4579. pTemplateInfo->SetTemplateDefaults();
  4580. rc = SCESTATUS_SUCCESS;
  4581. } else if ((SCESTATUS_ACCESS_DENIED == rc) && pTemplateInfo->pTemplate) {
  4582. //
  4583. // We were denied in some sections, but not all. Play on!
  4584. //
  4585. rc = SCESTATUS_SUCCESS;
  4586. } else {
  4587. CString strMessage;
  4588. CString strFormat;
  4589. LPTSTR lpMsgBuf=NULL;
  4590. //
  4591. // Real error of some sort. Display a messagebox
  4592. //
  4593. //
  4594. // translate SCESTATUS into DWORD
  4595. //
  4596. DWORD win32 = SceStatusToDosError(rc);
  4597. //
  4598. // get error description of rc
  4599. //
  4600. FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  4601. NULL,
  4602. win32,
  4603. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  4604. (LPTSTR)(PVOID)&lpMsgBuf,
  4605. 0,
  4606. NULL
  4607. );
  4608. if ( lpMsgBuf != NULL ) {
  4609. if (IsAdmin()) {
  4610. strFormat.LoadString(IDS_ADMIN_NO_GPO);
  4611. } else {
  4612. strFormat.LoadString(IDS_NON_ADMIN_NO_GPO);
  4613. }
  4614. strMessage.Format(strFormat,lpMsgBuf);
  4615. LocalFree(lpMsgBuf);
  4616. lpMsgBuf = NULL;
  4617. AfxMessageBox(strMessage,MB_ICONEXCLAMATION|MB_OK);
  4618. }
  4619. //
  4620. // Ok. We've notified them of the error, but don't otherwise care
  4621. // so pretend we got a valid but empty buffer
  4622. //
  4623. pTemplateInfo->SetTemplateDefaults();
  4624. rc = SCESTATUS_SUCCESS;
  4625. }
  4626. }
  4627. }
  4628. } else if (lstrcmp(GT_LOCAL_POLICY_DELTA,szInfFile) == 0) {
  4629. //
  4630. // Local Policy Changes. Initialize everything to not changed
  4631. //
  4632. SCE_PROFILE_INFO *ppi;
  4633. CString strLocalPol;
  4634. strLocalPol.LoadString(IDS_LOCAL_POLICY_FRIENDLY_NAME);
  4635. pTemplateInfo->SetFriendlyName( strLocalPol );
  4636. pTemplateInfo->SetWriteThrough(TRUE);
  4637. pTemplateInfo->SetProfileHandle(SadHandle);
  4638. pTemplateInfo->SetComponentDataImpl(this);
  4639. if (NULL == pTemplateInfo->pTemplate) {
  4640. pTemplateInfo->pTemplate = (SCE_PROFILE_INFO*)LocalAlloc(LPTR,sizeof(SCE_PROFILE_INFO));
  4641. }
  4642. ppi = pTemplateInfo->pTemplate;
  4643. if (NULL == ppi) {
  4644. if (pErr) {
  4645. *pErr = IDS_ERROR_CANT_GET_PROFILE_INFO;
  4646. }
  4647. return NULL;
  4648. }
  4649. ppi->Type = SCE_ENGINE_SCP;
  4650. VerifyKerberosInfo( ppi );
  4651. if (aiArea & AREA_SECURITY_POLICY) {
  4652. pTemplateInfo->SetTemplateDefaults();
  4653. }
  4654. //
  4655. // Further processing depends on rc == SCESTATUS_SUCCESS,
  4656. // even though we didn't actually call the engine here
  4657. //
  4658. rc = SCESTATUS_SUCCESS;
  4659. } else if (lstrcmp(GT_DEFAULT_TEMPLATE,szInfFile) == 0 ||
  4660. lstrcmp(GT_RSOP_TEMPLATE,szInfFile) == 0) {
  4661. pTemplateInfo->SetComponentDataImpl(this);
  4662. if (pTemplateInfo->RefreshTemplate(AREA_ALL)) {
  4663. if (pErr) {
  4664. *pErr = IDS_ERROR_CANT_GET_PROFILE_INFO;
  4665. }
  4666. return NULL;
  4667. }
  4668. rc = SCESTATUS_SUCCESS;
  4669. } else {
  4670. if (EngineOpenProfile(szInfFile,OPEN_PROFILE_CONFIGURE,&pHandle) != SCESTATUS_SUCCESS) {
  4671. if (pErr) {
  4672. *pErr = IDS_ERROR_CANT_OPEN_PROFILE;
  4673. }
  4674. if (bNewTemplate) {
  4675. delete pTemplateInfo;
  4676. }
  4677. pTemplateInfo = NULL;
  4678. goto done;
  4679. }
  4680. ASSERT(pHandle);
  4681. if ((GetModeBits() & MB_GROUP_POLICY) == MB_GROUP_POLICY) {
  4682. pTemplateInfo->SetPolicy(TRUE);
  4683. }
  4684. //
  4685. // get information from this template
  4686. //
  4687. PSCE_ERROR_LOG_INFO errBuff;
  4688. rc = SceGetSecurityProfileInfo(pHandle,
  4689. SCE_ENGINE_SCP,
  4690. aiArea,
  4691. &(pTemplateInfo->pTemplate),
  4692. &errBuff //NULL // &ErrBuf do not care errors
  4693. );
  4694. SceCloseProfile(&pHandle);
  4695. pHandle = NULL;
  4696. }
  4697. /*
  4698. if do not care errors, no need to use this buffer
  4699. if ( ErrBuf ) {
  4700. SceFreeMemory((PVOID)ErrBuf, SCE_STRUCT_ERROR_LOG_INFO);
  4701. ErrBuf = NULL;
  4702. }
  4703. */
  4704. if (rc != SCESTATUS_SUCCESS) {
  4705. if (pErr) {
  4706. *pErr = IDS_ERROR_CANT_GET_PROFILE_INFO;
  4707. }
  4708. //
  4709. // if we allocated pTemplateInfo then delete it.
  4710. //
  4711. if (bNewTemplate) {
  4712. delete pTemplateInfo;
  4713. }
  4714. pTemplateInfo = NULL;
  4715. goto done;
  4716. }
  4717. //
  4718. // Set the area in the template
  4719. //
  4720. pTemplateInfo->AddArea(aiArea);
  4721. //
  4722. // add this template to the list
  4723. //
  4724. m_Templates.SetAt(szKey, pTemplateInfo);
  4725. if ( aiArea & AREA_SECURITY_POLICY &&
  4726. pTemplateInfo->pTemplate ) {
  4727. //
  4728. // expand registry value section based on registry values list on local machine
  4729. //
  4730. SceRegEnumAllValues(
  4731. &(pTemplateInfo->pTemplate->RegValueCount),
  4732. &(pTemplateInfo->pTemplate->aRegValues)
  4733. );
  4734. }
  4735. }
  4736. done:
  4737. if(szKey){
  4738. delete [] szKey;
  4739. }
  4740. return pTemplateInfo;
  4741. }
  4742. //+--------------------------------------------------------------------------
  4743. //
  4744. // Method: GetTemplate
  4745. //
  4746. // Synopsis: Get the CEditTemplate for the given INF file from the cache
  4747. // maintained in m_pComponentData
  4748. //
  4749. // Arguments: [szInfFile] - The path and name of the INF file to retrieve
  4750. // [aiArea] - The SCE area that we're interested for the template
  4751. // *[pErr] - [out] a PDWORD to get error information
  4752. //
  4753. // Returns: A pointer to the CEditTemplate requested, or NULL if it's not
  4754. // available.
  4755. // *[pErr] - the resource id of an error string, if an error occurs
  4756. //
  4757. //
  4758. // History:
  4759. //
  4760. //---------------------------------------------------------------------------
  4761. PEDITTEMPLATE
  4762. CSnapin::GetTemplate(LPCTSTR szInfFile,AREA_INFORMATION aiArea,DWORD *pErr) {
  4763. return ((CComponentDataImpl *)m_pComponentData)->GetTemplate(szInfFile,aiArea,pErr);
  4764. }
  4765. HRESULT
  4766. CComponentDataImpl::ReloadLocation(CFolder * pFolder)
  4767. {
  4768. PEDITTEMPLATE pTemplate;
  4769. POSITION pos;
  4770. CString strKey;
  4771. HSCOPEITEM pItemChild=NULL;
  4772. MMC_COOKIE lCookie=NULL;
  4773. CFolder *pChild;
  4774. CString strName,strNotSaved;
  4775. LPTSTR szDesc = 0,szLoc = 0;
  4776. DWORD nLoc = 0;
  4777. HRESULT hr = S_OK;
  4778. if (!m_pScope)
  4779. return E_FAIL;
  4780. // Clear out this node
  4781. DeleteChildrenUnderNode(pFolder);
  4782. // Call EnumerateScopePane to reload it
  4783. // Do we need to worry about saving changed templates?
  4784. // No: since they're saved by name when the template is opened up it'll pick up the
  4785. // proper changed template
  4786. // Yes: what about changed templates where the file no longer exists (or never has,
  4787. // for new templates?) These will still show up in the save templates dialog,
  4788. // but won't be accessable for editing until then.
  4789. // Maybe loop through the changed templates and if they fall under this location
  4790. // and don't otherwise have a save file then add a folder for them?
  4791. //
  4792. // Set the folder not to be enumerated
  4793. //
  4794. pFolder->Set(FALSE);
  4795. EnumerateScopePane((MMC_COOKIE)pFolder,pFolder->GetScopeItem()->ID);
  4796. bool bFoundFolder;
  4797. szLoc = pFolder->GetName();
  4798. nLoc = lstrlen(szLoc);
  4799. pos = m_Templates.GetStartPosition();
  4800. while (pos) {
  4801. m_Templates.GetNextAssoc(pos,strKey,pTemplate);
  4802. //
  4803. // If the template hasn't been changed then we don't care about it
  4804. //
  4805. if ( !pTemplate->IsDirty()
  4806. ) {
  4807. continue;
  4808. }
  4809. //
  4810. // We only care about templates in the location we are reloading
  4811. //
  4812. if (_wcsnicmp(strKey,szLoc,nLoc)) {
  4813. bFoundFolder = false;
  4814. hr = m_pScope->GetChildItem(pFolder->GetScopeItem()->ID, &pItemChild, &lCookie);
  4815. //
  4816. // find a child item
  4817. //
  4818. while ( SUCCEEDED(hr) ) {
  4819. pChild = (CFolder*)lCookie;
  4820. if ( pChild ) {
  4821. if ( _wcsicmp(pChild->GetInfFile(), strKey) == 0 ) {
  4822. //
  4823. // The template has a folder here already, so we don't need to do anything
  4824. //
  4825. bFoundFolder = true;
  4826. break;
  4827. }
  4828. }
  4829. hr = m_pScope->GetNextItem(pItemChild, &pItemChild, &lCookie);
  4830. }
  4831. if (!bFoundFolder) {
  4832. //
  4833. // We didn't find a folder for the template, so add one
  4834. //
  4835. //
  4836. // The folder's name is its file part, less ".inf"
  4837. //
  4838. strName = strKey.Right(strName.GetLength() - nLoc);
  4839. strName = strName.Left(strName.GetLength() - 4);
  4840. // Since there's no file for this guy, mark it as not saved
  4841. if (strNotSaved.LoadString(IDS_NOT_SAVED_SUFFIX)) {
  4842. strName += strNotSaved;
  4843. }
  4844. if (! GetProfileDescription((LPCTSTR)strKey, &szDesc) ) {
  4845. szDesc = NULL;
  4846. }
  4847. CreateAndAddOneNode(pFolder, (LPCTSTR)strName, szDesc, PROFILE, TRUE,strKey);
  4848. if (szDesc) {
  4849. LocalFree(szDesc);
  4850. szDesc = NULL;
  4851. }
  4852. }
  4853. }
  4854. }
  4855. return S_OK;
  4856. }
  4857. DWORD
  4858. CSnapin::GetResultItemIDs(
  4859. CResult *pResult,
  4860. HRESULTITEM *pIDArray,
  4861. int nIDArray
  4862. )
  4863. {
  4864. if(!m_pResult){
  4865. return ERROR_NOT_READY;
  4866. }
  4867. if(!pResult || !pIDArray || nIDArray <= 0){
  4868. return ERROR_INVALID_PARAMETER;
  4869. }
  4870. ZeroMemory( pIDArray, sizeof(RESULTDATAITEM) * nIDArray );
  4871. if(S_OK == m_pResult->FindItemByLParam(
  4872. (LPARAM)pResult,
  4873. pIDArray
  4874. ) ){
  4875. RESULTDATAITEM rdi;
  4876. ZeroMemory(&rdi, sizeof(RESULTDATAITEM));
  4877. rdi.mask = RDI_PARAM | RDI_INDEX;
  4878. rdi.lParam = (LPARAM)pResult;
  4879. rdi.itemID = pIDArray[0];
  4880. if( m_pResult->GetItem( &rdi ) == S_OK ){
  4881. for(int i = 1; i < nIDArray; i++) {
  4882. if( m_pResult->GetNextItem(&rdi) == S_OK){
  4883. pIDArray[i] = rdi.itemID;
  4884. } else {
  4885. break;
  4886. }
  4887. }
  4888. }
  4889. }
  4890. return ERROR_SUCCESS;
  4891. }
  4892. //+----------------------------------------------------------------------------------
  4893. //Method: CSnapin::UpdateAnalysisInfo
  4894. //
  4895. //Synopsis: This function updates only priviledge assingedto area.
  4896. //
  4897. //Arguments: [bRemove] - Weither to remove or add an item.
  4898. // [ppaLink] - The link to be removed or added. This paramter is
  4899. // set to NULL if remove is successful or a pointer
  4900. // to a new SCE_PRIVILEGE_ASSIGNMENT item.
  4901. // [pszName] - Only used when adding a new item.
  4902. //
  4903. //Returns: ERROR_INVALID_PARAMETER - [ppaLink] is NULL or if removing
  4904. // [*ppaLink] is NULL.
  4905. // if adding then if [pszName] is NULL
  4906. // ERROR_RESOURCE_NOT_FOUND - If the link could not be found
  4907. // in this template.
  4908. // E_POINTER - If [pszName] is a bad pointer or
  4909. // [ppaLink] is bad.
  4910. // E_OUTOFMEMORY - Not enough resources to complete the
  4911. // operation.
  4912. // ERROR_SUCCESS - The opration was successful.
  4913. //----------------------------------------------------------------------------------+
  4914. DWORD
  4915. CSnapin::UpdateAnalysisInfo(
  4916. CResult *pResult,
  4917. BOOL bDelete,
  4918. PSCE_PRIVILEGE_ASSIGNMENT *pInfo,
  4919. LPCTSTR pszName
  4920. )
  4921. {
  4922. PEDITTEMPLATE pBaseTemplate;
  4923. pBaseTemplate = GetTemplate(GT_COMPUTER_TEMPLATE,AREA_SECURITY_POLICY);
  4924. if (!pBaseTemplate) {
  4925. return ERROR_FILE_NOT_FOUND;
  4926. }
  4927. DWORD dwRet;
  4928. dwRet = pBaseTemplate->UpdatePrivilegeAssignedTo(
  4929. bDelete,
  4930. pInfo,
  4931. pszName
  4932. );
  4933. if(dwRet == ERROR_SUCCESS){
  4934. pBaseTemplate->SetDirty(AREA_PRIVILEGES);
  4935. //
  4936. // Update the result item.
  4937. //
  4938. LONG_PTR dwBase =(LONG_PTR)(*pInfo);
  4939. if(!dwBase){
  4940. dwBase = (LONG_PTR)ULongToPtr(SCE_NO_VALUE);
  4941. }
  4942. if(*pInfo &&
  4943. pResult->GetSetting() &&
  4944. pResult->GetSetting() != (LONG_PTR)ULongToPtr(SCE_NO_VALUE)
  4945. ){
  4946. (*pInfo)->Value = ((PSCE_PRIVILEGE_ASSIGNMENT)pResult->GetSetting())->Value;
  4947. }
  4948. AddResultItem(
  4949. NULL, // The name of the attribute being added
  4950. (LONG_PTR)pResult->GetSetting(),
  4951. // The last inspected setting of the attribute
  4952. (LONG_PTR)dwBase, // The template setting of the attribute
  4953. ITEM_PRIVS, // The type of of the attribute's data
  4954. pResult->GetStatus(), // The mismatch status of the attribute
  4955. pResult->GetCookie(), // The cookie for the result item pane
  4956. FALSE, // True if the setting is set only if it differs from base (so copy the data)
  4957. NULL, // The units the attribute is set in
  4958. pResult->GetID(), // An id to let us know where to save this attribute
  4959. pResult->GetBaseProfile(), // The template to save this attribute in
  4960. NULL, // The data object for the scope note who owns the result pane
  4961. pResult
  4962. );
  4963. }
  4964. return dwRet;
  4965. }
  4966. //+--------------------------------------------------------------------------
  4967. //
  4968. // Function: SetAnalysisInfo
  4969. //
  4970. // Synopsis: Set a single policy entry to a new value in the Analysis
  4971. // template.
  4972. //
  4973. // Arguments: [dwItem] - the id of the item to set
  4974. // [dwNew] - the new setting for that item
  4975. // [pResult]- Pointer to the result item which is being updated.
  4976. //
  4977. // Returns: The new mismatch status of the item:
  4978. // -1 if the item wasn't found
  4979. // SCE_STATUS_GOOD if the items now match
  4980. // SCE_STATUS_MISMATCH if they are now different
  4981. //
  4982. //
  4983. // Modifies:
  4984. //
  4985. // History: 12-12-1997 Robcap
  4986. //
  4987. //---------------------------------------------------------------------------
  4988. int
  4989. CSnapin::SetAnalysisInfo(ULONG_PTR dwItem, ULONG_PTR dwNew, CResult *pResult)
  4990. {
  4991. CString str;
  4992. PSCE_PROFILE_INFO pProfileInfo;
  4993. PSCE_PROFILE_INFO pBaseInfo;
  4994. PEDITTEMPLATE pBaseTemplate;
  4995. PEDITTEMPLATE pProfileTemplate;
  4996. int nRet;
  4997. pBaseTemplate = GetTemplate(GT_COMPUTER_TEMPLATE,AREA_SECURITY_POLICY);
  4998. if (!pBaseTemplate) {
  4999. return -1;
  5000. }
  5001. pBaseInfo = pBaseTemplate->pTemplate;
  5002. pProfileTemplate = GetTemplate(GT_LAST_INSPECTION,AREA_SECURITY_POLICY);
  5003. if (!pProfileTemplate) {
  5004. return -1;
  5005. }
  5006. pProfileInfo = pProfileTemplate->pTemplate;
  5007. // If the Last Inspect (pProfileInfo) setting was SCE_NO_VALUE, then it was a match,
  5008. // so copy the actual value from the Template (pBaseInfo) setting
  5009. // Then copy the new value into the Template setting
  5010. // Compare them; if they are the same then we have a match, so the Last Inspect should
  5011. // be set back to SCE_NO_VALUE (is this last part necessary?), otherwise it's a mismatch
  5012. #ifdef UPDATE_ITEM
  5013. #undef UPDATE_ITEM
  5014. #endif
  5015. #define UPDATE_ITEM(X) pBaseTemplate->SetDirty(AREA_SECURITY_POLICY);\
  5016. if( SCE_NO_VALUE == pProfileInfo->X ){\
  5017. pProfileInfo->X = pBaseInfo->X;\
  5018. }\
  5019. pBaseInfo->X = PtrToUlong((PVOID)dwNew); \
  5020. if (SCE_NOT_ANALYZED_VALUE == pProfileInfo->X ){\
  5021. nRet = SCE_STATUS_NOT_ANALYZED;\
  5022. } else if (SCE_NO_VALUE == PtrToUlong((PVOID)dwNew)) { \
  5023. nRet = SCE_STATUS_NOT_CONFIGURED; \
  5024. } else if (SCE_NO_VALUE == pProfileInfo->X ){\
  5025. pProfileInfo->X = SCE_NOT_ANALYZED_VALUE;\
  5026. nRet = SCE_STATUS_NOT_ANALYZED;\
  5027. } else if (pBaseInfo->X == pProfileInfo->X) { \
  5028. nRet = SCE_STATUS_GOOD; \
  5029. } else { \
  5030. nRet = SCE_STATUS_MISMATCH;\
  5031. }\
  5032. if(pResult){\
  5033. pResult->SetSetting( pProfileInfo->X );\
  5034. }
  5035. nRet = -1;
  5036. switch (dwItem) {
  5037. case IDS_MAX_PAS_AGE:
  5038. UPDATE_ITEM(MaximumPasswordAge);
  5039. break;
  5040. case IDS_MIN_PAS_AGE:
  5041. UPDATE_ITEM(MinimumPasswordAge);
  5042. break;
  5043. case IDS_MIN_PAS_LEN:
  5044. UPDATE_ITEM(MinimumPasswordLength);
  5045. break;
  5046. case IDS_PAS_UNIQUENESS:
  5047. UPDATE_ITEM(PasswordHistorySize);
  5048. break;
  5049. case IDS_PAS_COMPLEX:
  5050. UPDATE_ITEM(PasswordComplexity);
  5051. break;
  5052. case IDS_REQ_LOGON:
  5053. UPDATE_ITEM(RequireLogonToChangePassword);
  5054. break;
  5055. case IDS_LOCK_COUNT:
  5056. UPDATE_ITEM(LockoutBadCount);
  5057. break;
  5058. case IDS_LOCK_RESET_COUNT:
  5059. UPDATE_ITEM(ResetLockoutCount);
  5060. break;
  5061. case IDS_LOCK_DURATION:
  5062. UPDATE_ITEM(LockoutDuration);
  5063. break;
  5064. case IDS_FORCE_LOGOFF:
  5065. UPDATE_ITEM(ForceLogoffWhenHourExpire);
  5066. break;
  5067. case IDS_ENABLE_ADMIN:
  5068. UPDATE_ITEM(EnableAdminAccount);
  5069. break;
  5070. case IDS_ENABLE_GUEST:
  5071. UPDATE_ITEM(EnableGuestAccount);
  5072. break;
  5073. case IDS_NEW_ADMIN:
  5074. //
  5075. // First copy the name if the analysis info used to be a match.
  5076. // Then copy the new name to the configuration buffer.
  5077. // Then get the status of the item.
  5078. //
  5079. #define UPDATE_STRING( X ) if ( (pProfileInfo->X == (LPTSTR)ULongToPtr(SCE_NO_VALUE) ||\
  5080. pProfileInfo->X == NULL) &&\
  5081. (pBaseInfo->X != (LPTSTR)ULongToPtr(SCE_NO_VALUE) &&\
  5082. pBaseInfo->X != NULL) ) {\
  5083. pProfileInfo->X = (LPTSTR)LocalAlloc(0, sizeof(TCHAR) * (lstrlen(pBaseInfo->X) + 1));\
  5084. if(pProfileInfo->X){\
  5085. lstrcpy(pProfileInfo->X, pBaseInfo->X);\
  5086. }\
  5087. }\
  5088. if (pBaseInfo->X) {\
  5089. LocalFree(pBaseInfo->X);\
  5090. }\
  5091. if (dwNew && (dwNew != (LONG_PTR)ULongToPtr(SCE_NO_VALUE))) {\
  5092. pBaseInfo->X =\
  5093. (PWSTR)LocalAlloc(LPTR,sizeof(TCHAR)*(lstrlen((PWSTR)dwNew)+1));\
  5094. if (pBaseInfo->X) {\
  5095. lstrcpy(pBaseInfo->X,(PWSTR)dwNew);\
  5096. } else {\
  5097. return SCE_STATUS_NOT_CONFIGURED;\
  5098. }\
  5099. } else {\
  5100. pBaseInfo->X = NULL;\
  5101. return SCE_STATUS_NOT_CONFIGURED;\
  5102. }\
  5103. if (pProfileInfo->X &&\
  5104. _wcsicmp(pBaseInfo->X,pProfileInfo->X) == 0 ) {\
  5105. return SCE_STATUS_GOOD;\
  5106. } else {\
  5107. return SCE_STATUS_MISMATCH;\
  5108. }
  5109. pBaseTemplate->SetDirty(AREA_SECURITY_POLICY);
  5110. UPDATE_STRING( NewAdministratorName );
  5111. break;
  5112. case IDS_NEW_GUEST:
  5113. pBaseTemplate->SetDirty(AREA_SECURITY_POLICY);
  5114. UPDATE_STRING( NewGuestName );
  5115. break;
  5116. case IDS_SYS_LOG_MAX:
  5117. UPDATE_ITEM(MaximumLogSize[EVENT_TYPE_SYSTEM]);
  5118. break;
  5119. case IDS_SYS_LOG_RET:
  5120. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_SYSTEM]);
  5121. break;
  5122. case IDS_SYS_LOG_DAYS:
  5123. UPDATE_ITEM(RetentionDays[EVENT_TYPE_SYSTEM]);
  5124. break;
  5125. case IDS_SEC_LOG_MAX:
  5126. UPDATE_ITEM(MaximumLogSize[EVENT_TYPE_SECURITY]);
  5127. break;
  5128. case IDS_SEC_LOG_RET:
  5129. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_SECURITY]);
  5130. break;
  5131. case IDS_SEC_LOG_DAYS:
  5132. UPDATE_ITEM(RetentionDays[EVENT_TYPE_SECURITY]);
  5133. break;
  5134. case IDS_APP_LOG_MAX:
  5135. UPDATE_ITEM(MaximumLogSize[EVENT_TYPE_APP]);
  5136. break;
  5137. case IDS_APP_LOG_RET:
  5138. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_APP]);
  5139. break;
  5140. case IDS_APP_LOG_DAYS:
  5141. UPDATE_ITEM(RetentionDays[EVENT_TYPE_APP]);
  5142. break;
  5143. case IDS_SYSTEM_EVENT:
  5144. UPDATE_ITEM(AuditSystemEvents);
  5145. break;
  5146. case IDS_LOGON_EVENT:
  5147. UPDATE_ITEM(AuditLogonEvents);
  5148. break;
  5149. case IDS_OBJECT_ACCESS:
  5150. UPDATE_ITEM(AuditObjectAccess);
  5151. break;
  5152. case IDS_PRIVILEGE_USE:
  5153. UPDATE_ITEM(AuditPrivilegeUse);
  5154. break;
  5155. case IDS_POLICY_CHANGE:
  5156. UPDATE_ITEM(AuditPolicyChange);
  5157. break;
  5158. case IDS_ACCOUNT_MANAGE:
  5159. UPDATE_ITEM(AuditAccountManage);
  5160. break;
  5161. case IDS_PROCESS_TRACK:
  5162. UPDATE_ITEM(AuditProcessTracking);
  5163. break;
  5164. case IDS_DIRECTORY_ACCESS:
  5165. UPDATE_ITEM(AuditDSAccess);
  5166. break;
  5167. case IDS_ACCOUNT_LOGON:
  5168. UPDATE_ITEM(AuditAccountLogon);
  5169. break;
  5170. case IDS_SYS_LOG_GUEST:
  5171. UPDATE_ITEM(RestrictGuestAccess[EVENT_TYPE_SYSTEM]);
  5172. break;
  5173. case IDS_SEC_LOG_GUEST:
  5174. UPDATE_ITEM(RestrictGuestAccess[EVENT_TYPE_SECURITY]);
  5175. break;
  5176. case IDS_APP_LOG_GUEST:
  5177. UPDATE_ITEM(RestrictGuestAccess[EVENT_TYPE_APP]);
  5178. break;
  5179. case IDS_CLEAR_PASSWORD:
  5180. UPDATE_ITEM(ClearTextPassword);
  5181. break;
  5182. case IDS_KERBEROS_MAX_SERVICE:
  5183. UPDATE_ITEM(pKerberosInfo->MaxServiceAge);
  5184. break;
  5185. case IDS_KERBEROS_MAX_CLOCK:
  5186. UPDATE_ITEM(pKerberosInfo->MaxClockSkew);
  5187. break;
  5188. case IDS_KERBEROS_VALIDATE_CLIENT:
  5189. UPDATE_ITEM(pKerberosInfo->TicketValidateClient);
  5190. break;
  5191. case IDS_KERBEROS_MAX_AGE:
  5192. UPDATE_ITEM(pKerberosInfo->MaxTicketAge);
  5193. break;
  5194. case IDS_KERBEROS_RENEWAL:
  5195. UPDATE_ITEM(pKerberosInfo->MaxRenewAge);
  5196. break;
  5197. default:
  5198. break;
  5199. }
  5200. #undef UPDATE_ITEM
  5201. #undef UPDATE_STRING
  5202. return nRet;
  5203. }
  5204. //+----------------------------------------------------------------------------------
  5205. //Method: CSnapin::UpdateLocalPolInfo
  5206. //
  5207. //Synopsis: This function update the priviledge unsigned to area of local
  5208. // Policy.
  5209. // First the local policy is updated to the database,
  5210. // Then the template used for display is updated.
  5211. // Last the CResult item is updated.
  5212. //
  5213. //Arguments: [bRemove] - Weither to remove or add an item.
  5214. // [ppaLink] - The link to be removed or added. This paramter is
  5215. // set to NULL if remove is successful or a pointer
  5216. // to a new SCE_PRIVILEGE_ASSIGNMENT item.
  5217. // [pszName] - Only used when adding a new item.
  5218. //
  5219. //Returns: ERROR_INVALID_PARAMETER - [ppaLink] is NULL or if removing
  5220. // [*ppaLink] is NULL.
  5221. // if adding then if [pszName] is NULL
  5222. // ERROR_RESOURCE_NOT_FOUND - If the link could not be found
  5223. // in this template.
  5224. // E_POINTER - If [pszName] is a bad pointer or
  5225. // [ppaLink] is bad.
  5226. // E_OUTOFMEMORY - Not enough resources to complete the
  5227. // operation.
  5228. // ERROR_SUCCESS - The opration was successful.
  5229. //----------------------------------------------------------------------------------+
  5230. DWORD
  5231. CSnapin::UpdateLocalPolInfo(
  5232. CResult *pResult,
  5233. BOOL bDelete,
  5234. PSCE_PRIVILEGE_ASSIGNMENT *pInfo,
  5235. LPCTSTR pszName
  5236. )
  5237. {
  5238. PEDITTEMPLATE pLocalPol;
  5239. if (!pszName && (NULL != pInfo) && (NULL != *pInfo)){
  5240. pszName = (*pInfo)->Name;
  5241. }
  5242. //
  5243. // Update changes only for the saved local policy section
  5244. //
  5245. pLocalPol = GetTemplate(GT_LOCAL_POLICY_DELTA,AREA_PRIVILEGES);
  5246. if (!pLocalPol) {
  5247. return ERROR_FILE_NOT_FOUND;
  5248. }
  5249. //
  5250. // For local policy delta section mark the node to be deleted by the
  5251. // engine, don't actually delete it from the list.
  5252. //
  5253. // Create new link
  5254. DWORD dwRet;
  5255. if(pInfo && *pInfo){
  5256. //
  5257. // Save values of privilege buffer.
  5258. //
  5259. dwRet = (*pInfo)->Status;
  5260. PSCE_PRIVILEGE_ASSIGNMENT pNext = (*pInfo)->Next;
  5261. (*pInfo)->Next = NULL;
  5262. if(bDelete){
  5263. (*pInfo)->Status = SCE_DELETE_VALUE;
  5264. }
  5265. //
  5266. // Update the engine.
  5267. //
  5268. pLocalPol->pTemplate->OtherInfo.smp.pPrivilegeAssignedTo = *pInfo;
  5269. pLocalPol->SetDirty(AREA_PRIVILEGES);
  5270. (*pInfo)->Status = dwRet;
  5271. (*pInfo)->Next = pNext;
  5272. } else {
  5273. return ERROR_INVALID_PARAMETER;
  5274. }
  5275. //
  5276. // Update for the displayed Local Policy section
  5277. //
  5278. if( pInfo && ((!bDelete && !(*pInfo)) || (bDelete && *pInfo)) ){
  5279. pLocalPol = GetTemplate(GT_LOCAL_POLICY,AREA_PRIVILEGES);
  5280. if (!pLocalPol) {
  5281. return ERROR_FILE_NOT_FOUND;
  5282. }
  5283. //
  5284. // Only make a call to this function if we are updating the priviledge link list.
  5285. //
  5286. dwRet = pLocalPol->UpdatePrivilegeAssignedTo(
  5287. bDelete,
  5288. pInfo,
  5289. pszName
  5290. );
  5291. pLocalPol->SetDirty(AREA_PRIVILEGES);
  5292. }
  5293. if(dwRet == ERROR_SUCCESS){
  5294. //
  5295. // Update the result item.
  5296. //
  5297. LONG_PTR dwBase =(LONG_PTR)(*pInfo);
  5298. if(!dwBase){
  5299. dwBase = (LONG_PTR)ULongToPtr(SCE_NO_VALUE);
  5300. }
  5301. if(*pInfo &&
  5302. pResult->GetSetting() &&
  5303. pResult->GetSetting() != (LONG_PTR)ULongToPtr(SCE_NO_VALUE) ){
  5304. (*pInfo)->Value = ((PSCE_PRIVILEGE_ASSIGNMENT)pResult->GetSetting())->Value;
  5305. }
  5306. AddResultItem(
  5307. NULL, // The name of the attribute being added
  5308. (LONG_PTR)pResult->GetSetting(),
  5309. // The last inspected setting of the attribute
  5310. (LONG_PTR)dwBase, // The template setting of the attribute
  5311. ITEM_LOCALPOL_PRIVS, // The type of of the attribute's data
  5312. pResult->GetStatus(), // The mismatch status of the attribute
  5313. pResult->GetCookie(), // The cookie for the result item pane
  5314. FALSE, // True if the setting is set only if it differs from base (so copy the data)
  5315. NULL, // The units the attribute is set in
  5316. pResult->GetID(), // An id to let us know where to save this attribute
  5317. pResult->GetBaseProfile(), // The template to save this attribute in
  5318. NULL, // The data object for the scope note who owns the result pane
  5319. pResult
  5320. );
  5321. }
  5322. return dwRet;
  5323. }
  5324. //+--------------------------------------------------------------------------
  5325. //
  5326. // Function: SetLocalPolInfo
  5327. //
  5328. // Synopsis: Set a single policy entry to a new value in the local policy
  5329. // template. Update both the displayed local policy buffer and
  5330. // the changes-only local policy buffer
  5331. //
  5332. // Arguments: [dwItem] - the id of the item to set
  5333. // [dwNew] - the new setting for that item
  5334. //
  5335. // Returns: The new mismatch status of the item:
  5336. // SCE_STATUS_GOOD if the items now match
  5337. // SCE_STATUS_MISMATCH if they are now different
  5338. // SCE_STATUS_NOT_CONFIGURED if the item is now non-configured
  5339. // SCE_ERROR_VALUE if there was an error saving
  5340. //
  5341. //
  5342. // Modifies:
  5343. //
  5344. // History: 12-12-1997 Robcap
  5345. //
  5346. //---------------------------------------------------------------------------
  5347. int
  5348. CSnapin::SetLocalPolInfo(ULONG_PTR dwItem, ULONG_PTR dwNew)
  5349. {
  5350. CString str;
  5351. PSCE_PROFILE_INFO pLocalInfo;
  5352. PSCE_PROFILE_INFO pLocalDeltaInfo;
  5353. PSCE_PROFILE_INFO pEffectiveInfo;
  5354. PEDITTEMPLATE pLocalTemplate;
  5355. PEDITTEMPLATE pLocalDeltaTemplate;
  5356. PEDITTEMPLATE pEffectiveTemplate;
  5357. int nRet;
  5358. ULONG_PTR dwSave;
  5359. ULONG_PTR dwSaveDelta;
  5360. pEffectiveTemplate = GetTemplate(GT_EFFECTIVE_POLICY,AREA_SECURITY_POLICY);
  5361. if (!pEffectiveTemplate) {
  5362. return SCE_ERROR_VALUE;
  5363. }
  5364. pEffectiveInfo = pEffectiveTemplate->pTemplate;
  5365. pLocalTemplate = GetTemplate(GT_LOCAL_POLICY,AREA_SECURITY_POLICY);
  5366. if (!pLocalTemplate) {
  5367. return SCE_ERROR_VALUE;
  5368. }
  5369. pLocalInfo = pLocalTemplate->pTemplate;
  5370. if (!pLocalInfo) {
  5371. return SCE_ERROR_VALUE;
  5372. }
  5373. pLocalDeltaTemplate = GetTemplate(GT_LOCAL_POLICY_DELTA,AREA_SECURITY_POLICY);
  5374. if (!pLocalDeltaTemplate) {
  5375. return SCE_ERROR_VALUE;
  5376. }
  5377. if ( !pLocalDeltaTemplate->IsLockedWriteThrough() )
  5378. pLocalDeltaTemplate->SetTemplateDefaults();
  5379. pLocalDeltaInfo = pLocalDeltaTemplate->pTemplate;
  5380. if (!pLocalDeltaInfo) {
  5381. return SCE_ERROR_VALUE;
  5382. }
  5383. // Compare them; if they are the same then we have a match, so the Last Inspect should
  5384. // be set back to SCE_NO_VALUE (is this last part necessary?), otherwise it's a mismatch
  5385. //
  5386. // If the new value is different from the old value then call SetDirty after the changes
  5387. // have been made, otherwise we may save things before that
  5388. // Once the dirty bit has been set (causing the delta template to be immediately saved)
  5389. // reset the changed item back to SCE_STATUS_NOT_CONFIGURED in that template
  5390. //
  5391. // If the SetDirty fails then undo the changes and return SCE_ERROR_VALUE
  5392. //
  5393. #ifdef UPDATE_ITEM
  5394. #undef UPDATE_ITEM
  5395. #endif
  5396. #define UPDATE_ITEM(X) dwSave = pLocalInfo->X; \
  5397. dwSaveDelta = pLocalDeltaInfo->X; \
  5398. pLocalInfo->X = (DWORD)PtrToUlong((PVOID)dwNew); \
  5399. pLocalDeltaInfo->X = (DWORD)PtrToUlong((PVOID)dwNew); \
  5400. if (SCE_NO_VALUE == (DWORD)PtrToUlong((PVOID)dwNew)) { \
  5401. pLocalDeltaInfo->X = SCE_DELETE_VALUE; \
  5402. nRet = SCE_STATUS_NOT_CONFIGURED; \
  5403. } else if (pEffectiveInfo->X == pLocalInfo->X) { \
  5404. nRet = SCE_STATUS_GOOD; \
  5405. } else { \
  5406. nRet = SCE_STATUS_MISMATCH; \
  5407. } \
  5408. if (dwSave != (DWORD)PtrToUlong((PVOID)dwNew) && \
  5409. !pLocalDeltaTemplate->SetDirty(AREA_SECURITY_POLICY)) { \
  5410. pLocalInfo->X = (DWORD)PtrToUlong((PVOID)dwSave); \
  5411. nRet = SCE_ERROR_VALUE; \
  5412. } \
  5413. if ( !pLocalDeltaTemplate->IsLockedWriteThrough() ) \
  5414. pLocalDeltaInfo->X = SCE_NO_VALUE;
  5415. // In order to batch dependent settings together (for write through mode), the delta info
  5416. // buffer should not be reset to "no value" since it may not be set in the SetDirty call
  5417. CString oldstrName; //Yanggao 1/31/2001 Bug211219. For keeping original name.
  5418. nRet = SCE_ERROR_VALUE;
  5419. switch (dwItem) {
  5420. case IDS_MAX_PAS_AGE:
  5421. UPDATE_ITEM(MaximumPasswordAge);
  5422. break;
  5423. case IDS_MIN_PAS_AGE:
  5424. UPDATE_ITEM(MinimumPasswordAge);
  5425. break;
  5426. case IDS_MIN_PAS_LEN:
  5427. UPDATE_ITEM(MinimumPasswordLength);
  5428. break;
  5429. case IDS_PAS_UNIQUENESS:
  5430. UPDATE_ITEM(PasswordHistorySize);
  5431. break;
  5432. case IDS_PAS_COMPLEX:
  5433. UPDATE_ITEM(PasswordComplexity);
  5434. break;
  5435. case IDS_REQ_LOGON:
  5436. UPDATE_ITEM(RequireLogonToChangePassword);
  5437. break;
  5438. case IDS_LOCK_COUNT:
  5439. UPDATE_ITEM(LockoutBadCount);
  5440. break;
  5441. case IDS_LOCK_RESET_COUNT:
  5442. UPDATE_ITEM(ResetLockoutCount);
  5443. break;
  5444. case IDS_LOCK_DURATION:
  5445. UPDATE_ITEM(LockoutDuration);
  5446. break;
  5447. case IDS_FORCE_LOGOFF:
  5448. UPDATE_ITEM(ForceLogoffWhenHourExpire);
  5449. break;
  5450. case IDS_ENABLE_ADMIN:
  5451. UPDATE_ITEM(EnableAdminAccount);
  5452. break;
  5453. case IDS_ENABLE_GUEST:
  5454. UPDATE_ITEM(EnableGuestAccount);
  5455. break;
  5456. case IDS_NEW_ADMIN:
  5457. pLocalTemplate->SetDirty(AREA_SECURITY_POLICY);
  5458. if (pLocalInfo->NewAdministratorName)
  5459. {
  5460. // Yanggao 1/31/2001. Bug211219.
  5461. oldstrName = (LPCTSTR)(pLocalInfo->NewAdministratorName);
  5462. LocalFree(pLocalInfo->NewAdministratorName);
  5463. pLocalInfo->NewAdministratorName = NULL;
  5464. }
  5465. pLocalDeltaInfo->NewAdministratorName = (LPTSTR)IntToPtr(SCE_DELETE_VALUE);
  5466. if (dwNew && (dwNew != (LONG_PTR)ULongToPtr(SCE_NO_VALUE)))
  5467. {
  5468. pLocalInfo->NewAdministratorName =
  5469. (PWSTR)LocalAlloc(LPTR,sizeof(TCHAR)*(lstrlen((PWSTR)dwNew)+1));
  5470. if (pLocalInfo->NewAdministratorName)
  5471. {
  5472. lstrcpy(pLocalInfo->NewAdministratorName,(PWSTR)dwNew);
  5473. pLocalDeltaInfo->NewAdministratorName = pLocalInfo->NewAdministratorName;
  5474. }
  5475. }
  5476. if( !pLocalInfo->NewAdministratorName )
  5477. {
  5478. nRet = SCE_STATUS_NOT_CONFIGURED;
  5479. }
  5480. else
  5481. {
  5482. if (pEffectiveInfo->NewAdministratorName &&
  5483. _wcsicmp(pLocalInfo->NewAdministratorName,
  5484. pEffectiveInfo->NewAdministratorName) == 0 )
  5485. {
  5486. nRet = SCE_STATUS_GOOD;
  5487. }
  5488. else
  5489. {
  5490. nRet = SCE_STATUS_MISMATCH;
  5491. }
  5492. }
  5493. //Yanggao 1/31/2001 Bug211219. Recover original name if save failed.
  5494. if( !pLocalDeltaTemplate->SetDirty(AREA_SECURITY_POLICY) &&
  5495. SCE_STATUS_MISMATCH == nRet )
  5496. {
  5497. pLocalTemplate->SetDirty(AREA_SECURITY_POLICY);
  5498. if (pLocalInfo->NewAdministratorName)
  5499. {
  5500. LocalFree(pLocalInfo->NewAdministratorName);
  5501. pLocalInfo->NewAdministratorName = NULL;
  5502. }
  5503. pLocalDeltaInfo->NewAdministratorName = (LPTSTR)IntToPtr(SCE_DELETE_VALUE);
  5504. LONG_PTR dwOld = (LONG_PTR)(LPCTSTR)oldstrName;
  5505. if (dwOld && (dwOld != (LONG_PTR)ULongToPtr(SCE_NO_VALUE)))
  5506. {
  5507. pLocalInfo->NewAdministratorName =
  5508. (PWSTR)LocalAlloc(LPTR,sizeof(TCHAR)*(lstrlen((PWSTR)dwOld)+1));
  5509. if (pLocalInfo->NewAdministratorName)
  5510. {
  5511. lstrcpy(pLocalInfo->NewAdministratorName,(PWSTR)dwOld);
  5512. pLocalDeltaInfo->NewAdministratorName = pLocalInfo->NewAdministratorName;
  5513. }
  5514. }
  5515. pLocalDeltaTemplate->SetDirty(AREA_SECURITY_POLICY);
  5516. }
  5517. break;
  5518. case IDS_NEW_GUEST:
  5519. pLocalTemplate->SetDirty(AREA_SECURITY_POLICY);
  5520. if (pLocalInfo->NewGuestName)
  5521. {
  5522. //Yanggao 3/15/2001 Bug211219. Recover original name if save failed.
  5523. oldstrName = (LPCTSTR)(pLocalInfo->NewGuestName);
  5524. LocalFree(pLocalInfo->NewGuestName);
  5525. pLocalInfo->NewGuestName = NULL;
  5526. }
  5527. pLocalDeltaInfo->NewGuestName = (LPTSTR)IntToPtr(SCE_DELETE_VALUE);
  5528. if (dwNew && (dwNew != (LONG_PTR)ULongToPtr(SCE_NO_VALUE)))
  5529. {
  5530. pLocalInfo->NewGuestName =
  5531. (PWSTR)LocalAlloc(LPTR,sizeof(TCHAR)*(lstrlen((PWSTR)dwNew)+1));
  5532. if (pLocalInfo->NewGuestName)
  5533. {
  5534. lstrcpy(pLocalInfo->NewGuestName,(PWSTR)dwNew);
  5535. pLocalDeltaInfo->NewGuestName = pLocalInfo->NewGuestName;
  5536. }
  5537. }
  5538. if( !pLocalInfo->NewGuestName )
  5539. {
  5540. nRet = SCE_STATUS_NOT_CONFIGURED;
  5541. }
  5542. else
  5543. {
  5544. if (pEffectiveInfo->NewGuestName &&
  5545. _wcsicmp(pLocalInfo->NewGuestName,pEffectiveInfo->NewGuestName) == 0 )
  5546. {
  5547. nRet = SCE_STATUS_GOOD;
  5548. }
  5549. else
  5550. {
  5551. nRet = SCE_STATUS_MISMATCH;
  5552. }
  5553. }
  5554. //Yanggao 3/15/2001 Bug211219. Recover original name if save failed.
  5555. if( !pLocalDeltaTemplate->SetDirty(AREA_SECURITY_POLICY) &&
  5556. SCE_STATUS_MISMATCH == nRet )
  5557. {
  5558. pLocalTemplate->SetDirty(AREA_SECURITY_POLICY);
  5559. if (pLocalInfo->NewGuestName)
  5560. {
  5561. LocalFree(pLocalInfo->NewGuestName);
  5562. pLocalInfo->NewGuestName = NULL;
  5563. }
  5564. pLocalDeltaInfo->NewGuestName = (LPTSTR)IntToPtr(SCE_DELETE_VALUE);
  5565. LONG_PTR dwOld = (LONG_PTR)(LPCTSTR)oldstrName;
  5566. if (dwOld && (dwOld != (LONG_PTR)ULongToPtr(SCE_NO_VALUE)))
  5567. {
  5568. pLocalInfo->NewGuestName =
  5569. (PWSTR)LocalAlloc(LPTR,sizeof(TCHAR)*(lstrlen((PWSTR)dwOld)+1));
  5570. if (pLocalInfo->NewGuestName)
  5571. {
  5572. lstrcpy(pLocalInfo->NewGuestName,(PWSTR)dwOld);
  5573. pLocalDeltaInfo->NewGuestName = pLocalInfo->NewGuestName;
  5574. }
  5575. }
  5576. pLocalDeltaTemplate->SetDirty(AREA_SECURITY_POLICY);
  5577. }
  5578. break;
  5579. case IDS_SYS_LOG_MAX:
  5580. UPDATE_ITEM(MaximumLogSize[EVENT_TYPE_SYSTEM]);
  5581. break;
  5582. case IDS_SYS_LOG_RET:
  5583. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_SYSTEM]);
  5584. if (SCE_RETAIN_BY_DAYS != dwNew) {
  5585. dwNew = SCE_NO_VALUE;
  5586. UPDATE_ITEM(RetentionDays[EVENT_TYPE_SYSTEM]);
  5587. }
  5588. break;
  5589. case IDS_SYS_LOG_DAYS:
  5590. UPDATE_ITEM(RetentionDays[EVENT_TYPE_SYSTEM]);
  5591. dwNew = SCE_RETAIN_BY_DAYS;
  5592. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_SYSTEM]);
  5593. break;
  5594. case IDS_SEC_LOG_MAX:
  5595. UPDATE_ITEM(MaximumLogSize[EVENT_TYPE_SECURITY]);
  5596. break;
  5597. case IDS_SEC_LOG_RET:
  5598. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_SECURITY]);
  5599. if (SCE_RETAIN_BY_DAYS != dwNew) {
  5600. dwNew = SCE_NO_VALUE;
  5601. UPDATE_ITEM(RetentionDays[EVENT_TYPE_SECURITY]);
  5602. }
  5603. break;
  5604. case IDS_SEC_LOG_DAYS:
  5605. UPDATE_ITEM(RetentionDays[EVENT_TYPE_SECURITY]);
  5606. dwNew = SCE_RETAIN_BY_DAYS;
  5607. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_SECURITY]);
  5608. break;
  5609. case IDS_APP_LOG_MAX:
  5610. UPDATE_ITEM(MaximumLogSize[EVENT_TYPE_APP]);
  5611. break;
  5612. case IDS_APP_LOG_RET:
  5613. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_APP]);
  5614. if (SCE_RETAIN_BY_DAYS != dwNew) {
  5615. dwNew = SCE_NO_VALUE;
  5616. UPDATE_ITEM(RetentionDays[EVENT_TYPE_APP]);
  5617. }
  5618. break;
  5619. case IDS_APP_LOG_DAYS:
  5620. UPDATE_ITEM(RetentionDays[EVENT_TYPE_APP]);
  5621. dwNew = SCE_RETAIN_BY_DAYS;
  5622. UPDATE_ITEM(AuditLogRetentionPeriod[EVENT_TYPE_APP]);
  5623. break;
  5624. case IDS_SYSTEM_EVENT:
  5625. UPDATE_ITEM(AuditSystemEvents);
  5626. break;
  5627. case IDS_LOGON_EVENT:
  5628. UPDATE_ITEM(AuditLogonEvents);
  5629. break;
  5630. case IDS_OBJECT_ACCESS:
  5631. UPDATE_ITEM(AuditObjectAccess);
  5632. break;
  5633. case IDS_PRIVILEGE_USE:
  5634. UPDATE_ITEM(AuditPrivilegeUse);
  5635. break;
  5636. case IDS_POLICY_CHANGE:
  5637. UPDATE_ITEM(AuditPolicyChange);
  5638. break;
  5639. case IDS_ACCOUNT_MANAGE:
  5640. UPDATE_ITEM(AuditAccountManage);
  5641. break;
  5642. case IDS_PROCESS_TRACK:
  5643. UPDATE_ITEM(AuditProcessTracking);
  5644. break;
  5645. case IDS_DIRECTORY_ACCESS:
  5646. UPDATE_ITEM(AuditDSAccess);
  5647. break;
  5648. case IDS_ACCOUNT_LOGON:
  5649. UPDATE_ITEM(AuditAccountLogon);
  5650. break;
  5651. case IDS_SYS_LOG_GUEST:
  5652. UPDATE_ITEM(RestrictGuestAccess[EVENT_TYPE_SYSTEM]);
  5653. break;
  5654. case IDS_SEC_LOG_GUEST:
  5655. UPDATE_ITEM(RestrictGuestAccess[EVENT_TYPE_SECURITY]);
  5656. break;
  5657. case IDS_APP_LOG_GUEST:
  5658. UPDATE_ITEM(RestrictGuestAccess[EVENT_TYPE_APP]);
  5659. break;
  5660. case IDS_CLEAR_PASSWORD:
  5661. UPDATE_ITEM(ClearTextPassword);
  5662. break;
  5663. case IDS_KERBEROS_MAX_AGE:
  5664. #define CHECK_KERBEROS if( !pLocalInfo->pKerberosInfo ||\
  5665. !pLocalDeltaInfo->pKerberosInfo ||\
  5666. !pEffectiveInfo->pKerberosInfo ){\
  5667. break;\
  5668. }
  5669. CHECK_KERBEROS
  5670. UPDATE_ITEM(pKerberosInfo->MaxTicketAge);
  5671. break;
  5672. case IDS_KERBEROS_RENEWAL:
  5673. CHECK_KERBEROS
  5674. UPDATE_ITEM(pKerberosInfo->MaxRenewAge);
  5675. break;
  5676. case IDS_KERBEROS_MAX_SERVICE:
  5677. CHECK_KERBEROS
  5678. UPDATE_ITEM(pKerberosInfo->MaxServiceAge);
  5679. break;
  5680. case IDS_KERBEROS_MAX_CLOCK:
  5681. CHECK_KERBEROS
  5682. UPDATE_ITEM(pKerberosInfo->MaxClockSkew);
  5683. break;
  5684. case IDS_KERBEROS_VALIDATE_CLIENT:
  5685. CHECK_KERBEROS
  5686. UPDATE_ITEM(pKerberosInfo->TicketValidateClient);
  5687. break;
  5688. case IDS_LSA_ANON_LOOKUP: //Raid #324250, 4/5/2001
  5689. UPDATE_ITEM(LSAAnonymousNameLookup);
  5690. break;
  5691. #undef CHECK_KERBEROS
  5692. default:
  5693. break;
  5694. }
  5695. return nRet;
  5696. }
  5697. //+------------------------------------------------------------------------------
  5698. // GetImageOffset
  5699. //
  5700. // Returns the offset in the image index depending on the status of the item.
  5701. //
  5702. // Returns
  5703. // Image offset, there is no error.
  5704. //-------------------------------------------------------------------------------
  5705. int
  5706. GetImageOffset(
  5707. DWORD status
  5708. )
  5709. {
  5710. int nImage = 0;
  5711. switch (status) {
  5712. case SCE_STATUS_GOOD:
  5713. nImage = IMOFFSET_GOOD;
  5714. break;
  5715. case SCE_STATUS_MISMATCH:
  5716. nImage = IMOFFSET_MISMATCH;
  5717. break;
  5718. case SCE_STATUS_NOT_ANALYZED:
  5719. nImage = IMOFFSET_NOT_ANALYZED;
  5720. break;
  5721. case SCE_STATUS_ERROR_NOT_AVAILABLE:
  5722. nImage = IMOFFSET_ERROR;
  5723. break;
  5724. }
  5725. return nImage;
  5726. }
  5727. int
  5728. GetScopeImageIndex(
  5729. FOLDER_TYPES type,
  5730. DWORD status
  5731. )
  5732. /*
  5733. Get the right image icon for scope items based on the folder type
  5734. */
  5735. {
  5736. int nImage;
  5737. switch ( type ) {
  5738. case ROOT:
  5739. case STATIC:
  5740. nImage = SCE_IMAGE_IDX;
  5741. break;
  5742. case ANALYSIS:
  5743. nImage = LAST_IC_IMAGE_IDX;
  5744. break;
  5745. case PROFILE:
  5746. nImage = TEMPLATES_IDX;
  5747. break;
  5748. case CONFIGURATION:
  5749. case LOCATIONS:
  5750. nImage = CONFIG_FOLDER_IDX;
  5751. break;
  5752. case POLICY_ACCOUNT:
  5753. case POLICY_PASSWORD:
  5754. case POLICY_KERBEROS:
  5755. case POLICY_LOCKOUT:
  5756. nImage = CONFIG_ACCOUNT_IDX;
  5757. break;
  5758. case POLICY_ACCOUNT_ANALYSIS:
  5759. case POLICY_PASSWORD_ANALYSIS:
  5760. case POLICY_KERBEROS_ANALYSIS:
  5761. case POLICY_LOCKOUT_ANALYSIS:
  5762. nImage = CONFIG_ACCOUNT_IDX;
  5763. break;
  5764. case POLICY_LOCAL:
  5765. case POLICY_EVENTLOG:
  5766. case POLICY_AUDIT:
  5767. case POLICY_OTHER:
  5768. case POLICY_LOG:
  5769. case AREA_PRIVILEGE:
  5770. nImage = CONFIG_LOCAL_IDX;
  5771. break;
  5772. case POLICY_LOCAL_ANALYSIS:
  5773. case POLICY_EVENTLOG_ANALYSIS:
  5774. case POLICY_AUDIT_ANALYSIS:
  5775. case POLICY_OTHER_ANALYSIS:
  5776. case POLICY_LOG_ANALYSIS:
  5777. case AREA_PRIVILEGE_ANALYSIS:
  5778. nImage = CONFIG_LOCAL_IDX;
  5779. break;
  5780. case REG_OBJECTS:
  5781. nImage = CONFIG_REG_IDX + GetImageOffset( status & 0xF );
  5782. break;
  5783. case FILE_OBJECTS:
  5784. nImage = FOLDER_IMAGE_IDX + GetImageOffset( status & 0xF );
  5785. break;
  5786. default:
  5787. nImage = CONFIG_FOLDER_IDX;
  5788. break;
  5789. }
  5790. return nImage;
  5791. }
  5792. int
  5793. GetResultImageIndex(
  5794. CFolder* pFolder,
  5795. CResult* pResult
  5796. )
  5797. /*
  5798. Get the image icon for the result item, based on where the
  5799. result item belongs to (which folder), the type of the result item,
  5800. and the status of the result item
  5801. */
  5802. {
  5803. RESULT_TYPES rsltType;
  5804. int nImage;
  5805. BOOL bCheck = TRUE;
  5806. if (!pFolder || !pResult ) {
  5807. // don't know which scope it belongs to ?
  5808. // should not occur
  5809. nImage = BLANK_IMAGE_IDX;
  5810. } else {
  5811. rsltType = pResult->GetType();
  5812. PSCE_GROUP_MEMBERSHIP pGroup;
  5813. int ista;
  5814. if ( pResult->GetStatus() == -1 ) {
  5815. ista = -1;
  5816. } else {
  5817. ista = pResult->GetStatus() & 0x0F;
  5818. }
  5819. //
  5820. // Get base image index.
  5821. //
  5822. switch ( pFolder->GetType() ) {
  5823. case POLICY_KERBEROS:
  5824. case POLICY_PASSWORD:
  5825. case POLICY_LOCKOUT:
  5826. case POLICY_PASSWORD_ANALYSIS:
  5827. case POLICY_KERBEROS_ANALYSIS:
  5828. case POLICY_LOCKOUT_ANALYSIS:
  5829. case LOCALPOL_KERBEROS:
  5830. case LOCALPOL_PASSWORD:
  5831. case LOCALPOL_LOCKOUT:
  5832. nImage = CONFIG_POLICY_IDX;
  5833. break;
  5834. case POLICY_AUDIT:
  5835. case POLICY_LOG:
  5836. case POLICY_OTHER:
  5837. case AREA_PRIVILEGE:
  5838. case POLICY_AUDIT_ANALYSIS:
  5839. case POLICY_LOG_ANALYSIS:
  5840. case POLICY_OTHER_ANALYSIS:
  5841. case AREA_PRIVILEGE_ANALYSIS:
  5842. case LOCALPOL_AUDIT:
  5843. case LOCALPOL_LOG:
  5844. case LOCALPOL_OTHER:
  5845. case LOCALPOL_PRIVILEGE:
  5846. nImage = CONFIG_POLICY_IDX;
  5847. break;
  5848. case AREA_GROUPS:
  5849. nImage = CONFIG_GROUP_IDX;
  5850. break;
  5851. case AREA_SERVICE:
  5852. case AREA_SERVICE_ANALYSIS:
  5853. nImage = CONFIG_SERVICE_IDX;
  5854. break;
  5855. case AREA_FILESTORE:
  5856. case AREA_FILESTORE_ANALYSIS:
  5857. // container or file ???
  5858. nImage = FOLDER_IMAGE_IDX;
  5859. break;
  5860. case AREA_REGISTRY:
  5861. case AREA_REGISTRY_ANALYSIS:
  5862. nImage = CONFIG_REG_IDX;
  5863. break;
  5864. case REG_OBJECTS:
  5865. nImage = CONFIG_REG_IDX;
  5866. break;
  5867. case FILE_OBJECTS:
  5868. nImage = CONFIG_FILE_IDX;
  5869. break;
  5870. case AREA_GROUPS_ANALYSIS:
  5871. if ( rsltType == ITEM_GROUP ) {
  5872. nImage = CONFIG_GROUP_IDX;
  5873. } else {
  5874. //
  5875. // the members or memberof record
  5876. //
  5877. bCheck = FALSE;
  5878. if ( SCE_STATUS_GOOD == ista ) {
  5879. nImage = SCE_OK_IDX;
  5880. } else if ( SCE_STATUS_MISMATCH == ista ) {
  5881. nImage = SCE_CRITICAL_IDX;
  5882. } else {
  5883. nImage = BLANK_IMAGE_IDX;
  5884. }
  5885. }
  5886. break;
  5887. default:
  5888. bCheck = FALSE;
  5889. nImage = BLANK_IMAGE_IDX;
  5890. break;
  5891. }
  5892. //
  5893. // Find the status icon. The image map garentees the order of these images.
  5894. // We don't need to check the status if we are in MB_TEMPLATE_EDITOR.
  5895. //
  5896. if( bCheck ){
  5897. if( pFolder->GetModeBits() & (MB_ANALYSIS_VIEWER) ){
  5898. nImage += GetImageOffset( ista );
  5899. } else if( SCE_STATUS_ERROR_NOT_AVAILABLE == ista ){
  5900. nImage = SCE_CRITICAL_IDX;
  5901. }
  5902. }
  5903. if ((pFolder->GetModeBits() & MB_LOCALSEC) == MB_LOCALSEC) {
  5904. if (pResult->GetType() == ITEM_LOCALPOL_REGVALUE) {
  5905. SCE_REGISTRY_VALUE_INFO *pRegValue;
  5906. pRegValue = (PSCE_REGISTRY_VALUE_INFO)pResult->GetSetting();
  5907. if (!pRegValue || pRegValue->Status != SCE_STATUS_NOT_CONFIGURED) {
  5908. nImage = LOCALSEC_POLICY_IDX;
  5909. }
  5910. } else if (pResult->GetType() == ITEM_LOCALPOL_SZ) {
  5911. if (pResult->GetSetting()) {
  5912. nImage = LOCALSEC_POLICY_IDX;
  5913. }
  5914. } else if (pResult->GetType() == ITEM_LOCALPOL_PRIVS) {
  5915. //
  5916. // If there is a setting it's a pointer; if not, it is NULL
  5917. //
  5918. if (pResult->GetSetting()) {
  5919. nImage = LOCALSEC_POLICY_IDX;
  5920. }
  5921. } else if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) != pResult->GetSetting()) {
  5922. nImage = LOCALSEC_POLICY_IDX;
  5923. }
  5924. }
  5925. }
  5926. if ( nImage < 0 ) {
  5927. nImage = BLANK_IMAGE_IDX;
  5928. }
  5929. return nImage;
  5930. }
  5931. //+--------------------------------------------------------------------------
  5932. //
  5933. // Method: GetPopupDialog
  5934. //
  5935. // Synopsis: Retrieve a popup dialog from the cache
  5936. //
  5937. // Arguments: [nID] - An identifier for the dialog
  5938. //
  5939. // Returns: The dialog if it exists, NULL otherwise
  5940. //
  5941. // History:
  5942. //
  5943. //---------------------------------------------------------------------------
  5944. CDialog *
  5945. CComponentDataImpl::GetPopupDialog(LONG_PTR nID) {
  5946. CDialog *pDlg = NULL;
  5947. if (m_scopeItemPopups.Lookup(nID,pDlg)) {
  5948. return pDlg;
  5949. } else {
  5950. return NULL;
  5951. }
  5952. }
  5953. //+--------------------------------------------------------------------------
  5954. //
  5955. // Method: AddPopupDialog
  5956. //
  5957. // Synopsis: Set a popup dialog into the cache
  5958. //
  5959. // Arguments: [nID] - An identifier for the dialog
  5960. // [pDlg] - The dialog
  5961. //
  5962. // History:
  5963. //
  5964. //---------------------------------------------------------------------------
  5965. void
  5966. CComponentDataImpl::AddPopupDialog(LONG_PTR nID,CDialog *pDlg) {
  5967. if (pDlg) {
  5968. m_scopeItemPopups.SetAt(nID,pDlg);
  5969. }
  5970. }
  5971. //+--------------------------------------------------------------------------
  5972. //
  5973. // Method: RemovePopupDialog
  5974. //
  5975. // Synopsis: Removes a popup dialog from the cache
  5976. //
  5977. // Arguments: [nID] - An identifier for the dialog
  5978. //
  5979. // History:
  5980. //
  5981. //---------------------------------------------------------------------------
  5982. void
  5983. CComponentDataImpl::RemovePopupDialog(LONG_PTR nID) {
  5984. CDialog *pDlg = NULL;
  5985. if (m_scopeItemPopups.Lookup(nID,pDlg)) {
  5986. m_scopeItemPopups.RemoveKey(nID);
  5987. }
  5988. }
  5989. //+--------------------------------------------------------------------------
  5990. //
  5991. // Method: EngineTransactionStarted
  5992. //
  5993. // Synopsis: Start transaction in the jet engine if one is not started
  5994. //
  5995. // Arguments: None
  5996. //
  5997. // History:
  5998. //
  5999. //---------------------------------------------------------------------------
  6000. BOOL
  6001. CComponentDataImpl::EngineTransactionStarted()
  6002. {
  6003. if ( !SadTransStarted && SadHandle ) {
  6004. //
  6005. // start the transaction
  6006. //
  6007. if ( SCESTATUS_SUCCESS == SceStartTransaction(SadHandle) ) {
  6008. SadTransStarted = TRUE;
  6009. }
  6010. }
  6011. return SadTransStarted;
  6012. }
  6013. //+--------------------------------------------------------------------------
  6014. //
  6015. // Method: EngineCommitTransaction
  6016. //
  6017. // Synopsis: Commit transaction in the jet engine if one is started
  6018. //
  6019. // Arguments: None
  6020. //
  6021. // History:
  6022. //
  6023. //---------------------------------------------------------------------------
  6024. BOOL
  6025. CComponentDataImpl::EngineCommitTransaction()
  6026. {
  6027. if ( SadTransStarted && SadHandle ) {
  6028. //
  6029. // start the transaction
  6030. //
  6031. if ( SCESTATUS_SUCCESS == SceCommitTransaction(SadHandle) ) {
  6032. SadTransStarted = FALSE;
  6033. return TRUE;
  6034. }
  6035. }
  6036. return FALSE;
  6037. }
  6038. //+--------------------------------------------------------------------------
  6039. //
  6040. // Method: GetLinkedTopics
  6041. //
  6042. // Synopsis: Return full path of help file.
  6043. //
  6044. // History: Raid #258658, 4/10/2001
  6045. //
  6046. //---------------------------------------------------------------------------
  6047. STDMETHODIMP CComponentDataImpl::GetLinkedTopics(LPOLESTR *lpCompiledHelpFiles)
  6048. {
  6049. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  6050. HRESULT hr = S_OK;
  6051. if ( lpCompiledHelpFiles )
  6052. {
  6053. CString strLinkedTopic;
  6054. UINT nLen = ::GetSystemWindowsDirectory (strLinkedTopic.GetBufferSetLength(2 * MAX_PATH), 2 * MAX_PATH);
  6055. strLinkedTopic.ReleaseBuffer();
  6056. if ( nLen )
  6057. {
  6058. CString strFile;
  6059. if( SCE_MODE_LOCAL_COMPUTER == m_GroupMode || SCE_MODE_LOCAL_USER == m_GroupMode )
  6060. {
  6061. strFile.LoadString(IDS_HTMLHELP_LPPOLICY_TOPIC);
  6062. strFile.Replace(L':', L'\0');
  6063. }
  6064. else
  6065. {
  6066. strFile.LoadString(IDS_HTMLHELP_POLICY_TOPIC);
  6067. strFile.Replace(L':', L'\0');
  6068. }
  6069. strLinkedTopic = strLinkedTopic + strFile;
  6070. *lpCompiledHelpFiles = reinterpret_cast<LPOLESTR>
  6071. (CoTaskMemAlloc((strLinkedTopic.GetLength() + 1)* sizeof(wchar_t)));
  6072. if ( *lpCompiledHelpFiles )
  6073. {
  6074. wcscpy(*lpCompiledHelpFiles, (PWSTR)(PCWSTR)strLinkedTopic);
  6075. }
  6076. else
  6077. hr = E_OUTOFMEMORY;
  6078. }
  6079. else
  6080. hr = E_FAIL;
  6081. }
  6082. else
  6083. return E_POINTER;
  6084. return hr;
  6085. }
  6086. //+--------------------------------------------------------------------------
  6087. //
  6088. // Method: EngineRollbackTransaction
  6089. //
  6090. // Synopsis: Rollback transaction in the jet engine if one is started
  6091. //
  6092. // Arguments: None
  6093. //
  6094. // History:
  6095. //
  6096. //---------------------------------------------------------------------------
  6097. BOOL
  6098. CComponentDataImpl::EngineRollbackTransaction()
  6099. {
  6100. if ( SadTransStarted && SadHandle ) {
  6101. //
  6102. // start the transaction
  6103. //
  6104. SceRollbackTransaction(SadHandle);
  6105. SadTransStarted = FALSE;
  6106. return TRUE;
  6107. }
  6108. return FALSE;
  6109. }
  6110. CDialog *
  6111. CComponentDataImpl::MatchNextPopupDialog(
  6112. POSITION &pos,
  6113. LONG_PTR priKey,
  6114. LONG_PTR *fullPos
  6115. )
  6116. {
  6117. if(pos == NULL){
  6118. pos = m_scopeItemPopups.GetStartPosition();
  6119. }
  6120. LONG_PTR key;
  6121. CDialog *pDlg = NULL;
  6122. while(pos){
  6123. m_scopeItemPopups.GetNextAssoc(pos, key, pDlg);
  6124. if( DLG_KEY_PRIMARY(priKey) == DLG_KEY_PRIMARY(key) ){
  6125. if(fullPos){
  6126. *fullPos = key;
  6127. }
  6128. return pDlg;
  6129. }
  6130. pDlg = NULL;
  6131. }
  6132. return pDlg;
  6133. }
  6134. //+--------------------------------------------------------------------------
  6135. //
  6136. // Method: CheckEngineTransaction
  6137. //
  6138. // Synopsis: From CSnapin to check/start transaction in the jet engine
  6139. //
  6140. // Arguments: None
  6141. //
  6142. // History:
  6143. //
  6144. //---------------------------------------------------------------------------
  6145. BOOL
  6146. CSnapin::CheckEngineTransaction()
  6147. {
  6148. return ((CComponentDataImpl*)m_pComponentData)->EngineTransactionStarted();
  6149. }
  6150. //+--------------------------------------------------------------------------
  6151. //
  6152. // Method: GetHelpTopic
  6153. //
  6154. // Synopsis: Return the path to the help file for this snapin
  6155. //
  6156. // Arguments: *lpCompiledHelpFile - [out] pointer to fill with the path to the help file
  6157. // szFile - [in] the file name of the help file for this snapin
  6158. // History:
  6159. //
  6160. //---------------------------------------------------------------------------
  6161. HRESULT
  6162. CComponentDataImpl::GetHelpTopic(LPOLESTR* lpCompiledHelpFile, LPCTSTR szFile)
  6163. {
  6164. CString sPath;
  6165. LPTSTR szPath;
  6166. if (lpCompiledHelpFile == NULL) {
  6167. return E_POINTER;
  6168. }
  6169. szPath = sPath.GetBuffer(MAX_PATH);
  6170. if (!szPath) {
  6171. return E_OUTOFMEMORY;
  6172. }
  6173. if (!GetWindowsDirectory(szPath,MAX_PATH)) {
  6174. return E_FAIL;
  6175. }
  6176. sPath.ReleaseBuffer();
  6177. sPath += szFile;
  6178. *lpCompiledHelpFile = reinterpret_cast<LPOLESTR>
  6179. (CoTaskMemAlloc((sPath.GetLength() + 1)* sizeof(wchar_t)));
  6180. if (*lpCompiledHelpFile == NULL) {
  6181. return E_OUTOFMEMORY;
  6182. }
  6183. USES_CONVERSION;
  6184. wcscpy(*lpCompiledHelpFile, T2OLE((LPTSTR)(LPCTSTR)sPath));
  6185. return S_OK;
  6186. }
  6187. //+--------------------------------------------------------------------------
  6188. //
  6189. // Method: CComponentDataImpl::SetErroredLogFile
  6190. //
  6191. // Synopsis: Sets the log file created by the engine. We can then display
  6192. // this log file later on, if there was an error performing the
  6193. // analysis or configuration.
  6194. //
  6195. // Arguments: [pszFileName] - The file name to set. This can be NULL.
  6196. // [dwPosLow] - The starting pos of the file. only supports files less then a
  6197. // gigabyte.
  6198. //
  6199. //
  6200. //---------------------------------------------------------------------------
  6201. void
  6202. CComponentDataImpl::SetErroredLogFile( LPCTSTR pszFileName, LONG dwPosLow)
  6203. {
  6204. if(m_pszErroredLogFile){
  6205. LocalFree( m_pszErroredLogFile );
  6206. }
  6207. m_ErroredLogPos = dwPosLow;
  6208. m_pszErroredLogFile = NULL;
  6209. if(pszFileName ){
  6210. DWORD dwRet = 0;
  6211. __try {
  6212. dwRet = lstrlen(pszFileName);
  6213. } __except( EXCEPTION_CONTINUE_EXECUTION ){
  6214. return;
  6215. }
  6216. m_pszErroredLogFile = (LPTSTR)LocalAlloc(0, sizeof(TCHAR) * (dwRet + 1) );
  6217. if( !m_pszErroredLogFile ){
  6218. return;
  6219. }
  6220. lstrcpy( m_pszErroredLogFile, pszFileName );
  6221. }
  6222. }
  6223. //+--------------------------------------------------------------------------
  6224. //
  6225. // Method: GetHelpTopic
  6226. //
  6227. // Synopsis: Return the path to the help file for this snapin
  6228. //
  6229. // Arguments: *lpCompiledHelpFile - [out] pointer to fill with the path to the help file
  6230. //
  6231. // History:
  6232. //
  6233. //---------------------------------------------------------------------------
  6234. HRESULT
  6235. CComponentDataSCEImpl::GetHelpTopic(LPOLESTR* lpCompiledHelpFile) {
  6236. CString sFile;
  6237. //
  6238. // Needed for Loadstring
  6239. //
  6240. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  6241. sFile.LoadString(IDS_HELPFILE_SCE);
  6242. return CComponentDataImpl::GetHelpTopic(lpCompiledHelpFile,(LPCTSTR)sFile);
  6243. }
  6244. //+--------------------------------------------------------------------------
  6245. //
  6246. // Method: GetHelpTopic
  6247. //
  6248. // Synopsis: Return the path to the help file for this snapin
  6249. //
  6250. // Arguments: *lpCompiledHelpFile - [out] pointer to fill with the path to the help file
  6251. //
  6252. // History:
  6253. //
  6254. //---------------------------------------------------------------------------
  6255. HRESULT
  6256. CComponentDataSAVImpl::GetHelpTopic(LPOLESTR* lpCompiledHelpFile) {
  6257. CString sFile;
  6258. //
  6259. // Needed for Loadstring
  6260. //
  6261. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  6262. sFile.LoadString(IDS_HELPFILE_SAV);
  6263. return CComponentDataImpl::GetHelpTopic(lpCompiledHelpFile,(LPCTSTR)sFile);
  6264. }
  6265. //+--------------------------------------------------------------------------
  6266. //
  6267. // Method: GetHelpTopic
  6268. //
  6269. // Synopsis: Return the path to the help file for this snapin
  6270. //
  6271. // Arguments: *lpCompiledHelpFile - [out] pointer to fill with the path to the help file
  6272. //
  6273. // History:
  6274. //
  6275. //---------------------------------------------------------------------------
  6276. HRESULT
  6277. CComponentDataLSImpl::GetHelpTopic(LPOLESTR* lpCompiledHelpFile) {
  6278. CString sFile;
  6279. //
  6280. // Needed for Loadstring
  6281. //
  6282. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  6283. sFile.LoadString(IDS_HELPFILE_LS);
  6284. return CComponentDataImpl::GetHelpTopic(lpCompiledHelpFile,(LPCTSTR)sFile);
  6285. }
  6286. //+--------------------------------------------------------------------------
  6287. //
  6288. // Method: GetHelpTopic
  6289. //
  6290. // Synopsis: Return the path to the help file for this snapin
  6291. //
  6292. // Arguments: *lpCompiledHelpFile - [out] pointer to fill with the path to the help file
  6293. //
  6294. // History:
  6295. //
  6296. //---------------------------------------------------------------------------
  6297. HRESULT
  6298. CComponentDataRSOPImpl::GetHelpTopic(LPOLESTR* lpCompiledHelpFile) {
  6299. CString sFile;
  6300. //
  6301. // Needed for Loadstring
  6302. //
  6303. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  6304. sFile.LoadString(IDS_HELPFILE_RSOP);
  6305. return CComponentDataImpl::GetHelpTopic(lpCompiledHelpFile,(LPCTSTR)sFile);
  6306. }
  6307. //+--------------------------------------------------------------------------
  6308. //
  6309. // Method: GetHelpTopic
  6310. //
  6311. // Synopsis: Return the path to the help file for this snapin
  6312. //
  6313. // Arguments: *lpCompiledHelpFile - [out] pointer to fill with the path to the help file
  6314. //
  6315. // History:
  6316. //
  6317. //---------------------------------------------------------------------------
  6318. HRESULT
  6319. CComponentDataExtensionImpl::GetHelpTopic(LPOLESTR* lpCompiledHelpFile) {
  6320. CString sFile;
  6321. //
  6322. // Needed for Loadstring
  6323. //
  6324. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  6325. //Raid #258658, 4/10/2001. If currently security setting node is not expanded, we
  6326. //won't give them any helptopic. So after it is expanded, this function will be called
  6327. //because it is only allowed calling one time.
  6328. DWORD tempmode = CComponentDataImpl::GetGroupMode();
  6329. if( SCE_MODE_UNKNOWN != tempmode )
  6330. {
  6331. if( SCE_MODE_LOCAL_COMPUTER == tempmode ||
  6332. SCE_MODE_LOCAL_USER == tempmode )
  6333. sFile.LoadString(IDS_HELPFILE_LOCAL_EXTENSION);
  6334. else
  6335. sFile.LoadString(IDS_HELPFILE_EXTENSION);
  6336. }
  6337. return CComponentDataImpl::GetHelpTopic(lpCompiledHelpFile,(LPCTSTR)sFile);
  6338. }
  6339. //+--------------------------------------------------------------------------
  6340. //
  6341. // Method: GetAnalTimeStamp
  6342. //
  6343. // Synopsis: Return the time of the last analysis
  6344. //
  6345. // History:
  6346. //
  6347. //---------------------------------------------------------------------------
  6348. LPTSTR
  6349. CSnapin::GetAnalTimeStamp() {
  6350. PVOID SadHandle;
  6351. CString strFormat;
  6352. CString strTimeStamp;
  6353. LPTSTR szAnalTimeStamp = NULL;
  6354. //
  6355. // Should cache this, but then we can't refresh it easily
  6356. // when the system is re-analyzed.
  6357. //
  6358. if (m_szAnalTimeStamp) {
  6359. LocalFree(m_szAnalTimeStamp);
  6360. m_szAnalTimeStamp = NULL;
  6361. // return m_szAnalTimeStamp;
  6362. }
  6363. SadHandle = ((CComponentDataImpl*)m_pComponentData)->SadHandle;
  6364. if (!SadHandle) {
  6365. return 0;
  6366. }
  6367. if (SCESTATUS_SUCCESS == SceGetTimeStamp(SadHandle,NULL,&szAnalTimeStamp)) {
  6368. if (szAnalTimeStamp) {
  6369. strFormat.LoadString(IDS_ANALTIMESTAMP);
  6370. strTimeStamp.Format(strFormat,szAnalTimeStamp);
  6371. m_szAnalTimeStamp = (LPTSTR) LocalAlloc(LPTR,(1+strTimeStamp.GetLength())*sizeof(TCHAR));
  6372. if (m_szAnalTimeStamp) {
  6373. lstrcpy(m_szAnalTimeStamp,strTimeStamp);
  6374. }
  6375. LocalFree(szAnalTimeStamp);
  6376. }
  6377. }
  6378. return m_szAnalTimeStamp;
  6379. }
  6380. DWORD CComponentDataImpl::GetGroupMode()
  6381. {
  6382. return m_GroupMode;
  6383. }