Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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