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

1939 lines
53 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2001.
  5. //
  6. // File: cookie.cpp
  7. //
  8. // Contents: Functions for handling SCE cookies for the scope and
  9. // result panes
  10. //
  11. // History:
  12. //
  13. //---------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "cookie.h"
  16. #include "snapmgr.h"
  17. #include "wrapper.h"
  18. #include <sceattch.h>
  19. #include "precdisp.h"
  20. #include "util.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. CFolder::~CFolder()
  27. {
  28. if (m_pScopeItem)
  29. {
  30. delete m_pScopeItem;
  31. m_pScopeItem = NULL;
  32. }
  33. CoTaskMemFree(m_pszName);
  34. CoTaskMemFree(m_pszDesc);
  35. while (!m_resultItemList.IsEmpty () )
  36. {
  37. CResult* pResult = m_resultItemList.RemoveHead ();
  38. if ( pResult )
  39. pResult->Release ();
  40. }
  41. }
  42. //+--------------------------------------------------------------------------
  43. //
  44. // Method: SetDesc
  45. //
  46. // Synopsis: Sets the description of the folder
  47. //
  48. // Arguments: [szDesc] - [in] the new description of the folder
  49. //
  50. // Returns: TRUE if successfull, FALSE otherwise
  51. //
  52. // Modifies: m_pszDesc
  53. //
  54. // History:
  55. //
  56. //---------------------------------------------------------------------------
  57. BOOL CFolder::SetDesc(LPCTSTR szDesc)
  58. {
  59. UINT uiByteLen = 0;
  60. LPOLESTR psz = 0;
  61. if (szDesc != NULL)
  62. {
  63. uiByteLen = (lstrlen(szDesc) + 1) * sizeof(OLECHAR);
  64. psz = (LPOLESTR)::CoTaskMemAlloc(uiByteLen);
  65. if (psz != NULL)
  66. {
  67. lstrcpy(psz, szDesc);
  68. CoTaskMemFree(m_pszDesc);
  69. m_pszDesc = psz;
  70. }
  71. else
  72. return FALSE;
  73. }
  74. else
  75. return FALSE;
  76. return TRUE;
  77. }
  78. // --------------------------------------------------------------------------
  79. // Method: SetViewUpdate
  80. //
  81. // Synopsis: Sets and gets update flag of this folder
  82. //
  83. // History: Raid #258237, 4/12/2001
  84. //
  85. //---------------------------------------------------------------------------
  86. void CFolder::SetViewUpdate(BOOL fUpdate)
  87. {
  88. m_ViewUpdate = fUpdate;
  89. }
  90. BOOL CFolder::GetViewUpdate() const
  91. {
  92. return m_ViewUpdate;
  93. }
  94. //+--------------------------------------------------------------------------
  95. //
  96. // Method: SetMode
  97. //
  98. // Synopsis: Sets the SCE Mode that this folder is operating under and
  99. // calculates the "Mode Bits" appropriate for that mode
  100. //
  101. // Arguments: [dwMode] - The mode to set
  102. //
  103. // Returns: TRUE if the mode is valid, FALSE otherwise
  104. //
  105. // Modifies: m_dwMode
  106. // m_ModeBits
  107. //
  108. // History: 20-Jan-1998 Robcap created
  109. //
  110. //---------------------------------------------------------------------------
  111. BOOL CFolder::SetMode(DWORD dwMode)
  112. {
  113. //
  114. // Make sure this is a legitimate mode
  115. //
  116. switch (dwMode)
  117. {
  118. case SCE_MODE_RSOP_COMPUTER:
  119. case SCE_MODE_RSOP_USER:
  120. case SCE_MODE_LOCALSEC:
  121. case SCE_MODE_COMPUTER_MANAGEMENT:
  122. case SCE_MODE_DC_MANAGEMENT:
  123. case SCE_MODE_LOCAL_USER:
  124. case SCE_MODE_LOCAL_COMPUTER:
  125. case SCE_MODE_REMOTE_USER:
  126. case SCE_MODE_REMOTE_COMPUTER:
  127. case SCE_MODE_DOMAIN_USER:
  128. case SCE_MODE_DOMAIN_COMPUTER:
  129. case SCE_MODE_OU_USER:
  130. case SCE_MODE_OU_COMPUTER:
  131. case SCE_MODE_EDITOR:
  132. case SCE_MODE_VIEWER:
  133. case SCE_MODE_DOMAIN_COMPUTER_ERROR:
  134. m_dwMode = dwMode;
  135. break;
  136. default:
  137. return FALSE;
  138. break;
  139. }
  140. //
  141. // Calculate the mode bits for this mode
  142. //
  143. m_ModeBits = 0;
  144. //
  145. // Directory Services not avalible in NT4
  146. //
  147. if ((dwMode == SCE_MODE_DOMAIN_COMPUTER) ||
  148. (dwMode == SCE_MODE_DC_MANAGEMENT))
  149. {
  150. m_ModeBits |= MB_DS_OBJECTS_SECTION;
  151. }
  152. if ((dwMode == SCE_MODE_OU_USER) ||
  153. (dwMode == SCE_MODE_DOMAIN_USER) ||
  154. (dwMode == SCE_MODE_REMOTE_COMPUTER) ||
  155. (dwMode == SCE_MODE_REMOTE_USER) ||
  156. (dwMode == SCE_MODE_RSOP_USER) ||
  157. (dwMode == SCE_MODE_DOMAIN_COMPUTER_ERROR) ||
  158. (dwMode == SCE_MODE_LOCAL_USER))
  159. {
  160. m_ModeBits |= MB_NO_NATIVE_NODES |
  161. MB_NO_TEMPLATE_VERBS |
  162. MB_WRITE_THROUGH;
  163. }
  164. if ((dwMode == SCE_MODE_OU_COMPUTER) ||
  165. (dwMode == SCE_MODE_DOMAIN_COMPUTER) )
  166. {
  167. m_ModeBits |= MB_SINGLE_TEMPLATE_ONLY |
  168. MB_NO_TEMPLATE_VERBS |
  169. MB_GROUP_POLICY |
  170. MB_WRITE_THROUGH;
  171. }
  172. if (dwMode == SCE_MODE_RSOP_COMPUTER)
  173. {
  174. m_ModeBits |= MB_SINGLE_TEMPLATE_ONLY |
  175. MB_NO_TEMPLATE_VERBS |
  176. MB_WRITE_THROUGH;
  177. }
  178. if (dwMode == SCE_MODE_RSOP_COMPUTER ||
  179. dwMode == SCE_MODE_RSOP_USER)
  180. {
  181. m_ModeBits |= MB_READ_ONLY |
  182. MB_RSOP;
  183. }
  184. if (SCE_MODE_LOCAL_COMPUTER == dwMode)
  185. {
  186. m_ModeBits |= MB_LOCAL_POLICY |
  187. MB_LOCALSEC |
  188. MB_NO_TEMPLATE_VERBS |
  189. MB_SINGLE_TEMPLATE_ONLY |
  190. MB_WRITE_THROUGH;
  191. if (!IsAdmin()) {
  192. m_ModeBits |= MB_READ_ONLY;
  193. }
  194. if (IsDomainController())
  195. {
  196. m_ModeBits |= MB_DS_OBJECTS_SECTION;
  197. }
  198. }
  199. if ( dwMode == SCE_MODE_EDITOR )
  200. {
  201. m_ModeBits |= MB_TEMPLATE_EDITOR;
  202. m_ModeBits |= MB_DS_OBJECTS_SECTION;
  203. }
  204. else if ( dwMode == SCE_MODE_VIEWER )
  205. {
  206. m_ModeBits |= MB_ANALYSIS_VIEWER;
  207. if (IsDomainController())
  208. {
  209. m_ModeBits |= MB_DS_OBJECTS_SECTION;
  210. }
  211. }
  212. else if (dwMode == SCE_MODE_LOCALSEC)
  213. {
  214. m_ModeBits |= MB_LOCALSEC;
  215. if (!IsAdmin())
  216. {
  217. m_ModeBits |= MB_READ_ONLY;
  218. }
  219. if (IsDomainController())
  220. {
  221. m_ModeBits |= MB_DS_OBJECTS_SECTION;
  222. }
  223. }
  224. return TRUE;
  225. }
  226. //+--------------------------------------------------------------------------
  227. //
  228. // Method: Create
  229. //
  230. // Synopsis: Initialize a CFolder Object
  231. //
  232. //
  233. // Arguments: [szName] - The folder's display name
  234. // [szDesc] - The folder's discription
  235. // [infName] - The inf file associated with the folder (optional)
  236. // [nImage] - The folder's closed icon index
  237. // [nOpenImage] - the folder's open icon index
  238. // [type] - The folder' type
  239. // [bHasChildren] - True if the folder has children folders
  240. // [dwMode] - The Mode the folder operates under
  241. // [pData] - Extra data to associate with the folder
  242. //
  243. //
  244. // History:
  245. //
  246. //---------------------------------------------------------------------------
  247. HRESULT CFolder::Create(LPCTSTR szName, // Name
  248. LPCTSTR szDesc, // Description
  249. LPCTSTR infName, // inf file name
  250. int nImage, // closed icon index
  251. int nOpenImage, // open icon index
  252. FOLDER_TYPES type, // folder type
  253. BOOL bHasChildren, // has children
  254. DWORD dwMode, // mode
  255. PVOID pData) // data
  256. {
  257. UINT uiByteLen = 0;
  258. LPOLESTR psz = 0;
  259. HRESULT hr = S_OK;
  260. ASSERT(m_pScopeItem == NULL); // Calling create twice on this item?
  261. CString str;
  262. //
  263. // Two-stage construction
  264. //
  265. m_pScopeItem = new SCOPEDATAITEM;
  266. if (!m_pScopeItem)
  267. return E_OUTOFMEMORY;
  268. ZeroMemory(m_pScopeItem,sizeof(m_pScopeItem));
  269. //
  270. // Set folder type
  271. //
  272. m_type = type;
  273. //
  274. // Add node name
  275. //
  276. if (szName != NULL || szDesc != NULL )
  277. {
  278. m_pScopeItem->mask = SDI_STR;
  279. //
  280. // Displayname is a callback (unsigned short*)(-1)
  281. m_pScopeItem->displayname = MMC_CALLBACK;
  282. }
  283. if ( szName != NULL )
  284. {
  285. uiByteLen = (lstrlen(szName) + 1) * sizeof(OLECHAR);
  286. psz = (LPOLESTR)::CoTaskMemAlloc(uiByteLen);
  287. if (psz != NULL)
  288. lstrcpy(psz, szName);
  289. else
  290. hr = E_OUTOFMEMORY;
  291. CoTaskMemFree(m_pszName);
  292. m_pszName = psz;
  293. }
  294. if (szDesc != NULL)
  295. {
  296. uiByteLen = (lstrlen(szDesc) + 1) * sizeof(OLECHAR);
  297. psz = (LPOLESTR)::CoTaskMemAlloc(uiByteLen);
  298. if (psz != NULL)
  299. lstrcpy(psz, szDesc);
  300. else
  301. hr = E_OUTOFMEMORY;
  302. CoTaskMemFree(m_pszDesc);
  303. m_pszDesc = psz;
  304. }
  305. if (infName != NULL)
  306. {
  307. uiByteLen = (lstrlen(infName) + 1) * sizeof(OLECHAR);
  308. psz = (LPOLESTR)::CoTaskMemAlloc(uiByteLen);
  309. if (psz != NULL)
  310. lstrcpy(psz, infName);
  311. else
  312. hr = E_OUTOFMEMORY;
  313. CoTaskMemFree(m_infName);
  314. m_infName = psz;
  315. }
  316. //
  317. // Add close image
  318. //
  319. m_pScopeItem->mask |= SDI_IMAGE; // no close image for now
  320. // m_pScopeItem->nImage = (int)MMC_CALLBACK;
  321. m_pScopeItem->nImage = nImage;
  322. //
  323. // Add open image
  324. //
  325. if (nOpenImage != -1)
  326. {
  327. m_pScopeItem->mask |= SDI_OPENIMAGE;
  328. m_pScopeItem->nOpenImage = nOpenImage;
  329. }
  330. //
  331. // Add button to node if the folder has children
  332. //
  333. if (bHasChildren == TRUE)
  334. {
  335. m_pScopeItem->mask |= SDI_CHILDREN;
  336. //
  337. // The number of children doesn't make any difference now,
  338. // so pick 1 until the node is expanded and the true value
  339. // is known
  340. //
  341. m_pScopeItem->cChildren = 1;
  342. }
  343. //
  344. // Set the SCE Mode and calculate the mode bits
  345. //
  346. if (dwMode)
  347. SetMode(dwMode);
  348. m_pData = pData;
  349. return hr;
  350. }
  351. //+------------------------------------------------------------------------------------------------
  352. // CFolder::SetDesc
  353. //
  354. // Translate dwStatus and dwNumChildren to a string and sets m_szDesc
  355. //
  356. // Argumens: [dwStats] - Object status.
  357. // [dwNumChildren] - Number of children for the object.
  358. //
  359. // Returns: TRUE - If successful
  360. // FALSE - If no more memory is available (or dwStatus is greater then 999)
  361. //-------------------------------------------------------------------------------------------------
  362. BOOL CFolder::SetDesc( DWORD dwStatus, DWORD dwNumChildren )
  363. {
  364. if(dwStatus > 999)
  365. return FALSE;
  366. TCHAR szText[256];
  367. swprintf(szText, L"%03d%d", dwStatus, dwNumChildren);
  368. SetDesc(szText);
  369. return TRUE;
  370. }
  371. //+------------------------------------------------------------------------------------------------
  372. // CFolder::GetObjectInfo
  373. //
  374. // Translate m_szDesc into dwStatus and dwNumChildren
  375. //
  376. // Argumens: [pdwStats] - Object status.
  377. // [pdwNumChildren] - Number of children for the object.
  378. //
  379. // Returns: TRUE - If successful
  380. // FALSE - m_szDesc is NULL
  381. //-------------------------------------------------------------------------------------------------
  382. BOOL CFolder::GetObjectInfo( DWORD *pdwStatus, DWORD *pdwNumChildren )
  383. {
  384. if(!m_pszDesc)
  385. return FALSE;
  386. if( lstrlen(m_pszDesc) < 4)
  387. return FALSE;
  388. if(pdwStatus )
  389. *pdwStatus = (m_pszDesc[0]-L'0')*100 + (m_pszDesc[1]-L'0')*10+ (m_pszDesc[2]-L'0');
  390. if(pdwNumChildren)
  391. *pdwNumChildren = _wtol( m_pszDesc + 3 );
  392. return TRUE;
  393. }
  394. /*--------------------------------------------------------------------------------------------------
  395. Method: GetResultItemHandle()
  396. Synopisi: This function must be called to retreive a valid handle to this folders result items.
  397. The handle must be freed by a call to ReleaseResultItemHandle(). If these two functions
  398. are not called in conjunction. The behavior fo the result items will be strange.
  399. Arguments: [handle] - [out] The handle value to use for any other functions that require a
  400. handle.
  401. Returns: ERROR_SUCCESS - A valid result item was returned
  402. ERROR_INVALID_PARAMETER - [handle] is NULL
  403. --------------------------------------------------------------------------------------------------*/
  404. DWORD CFolder::GetResultItemHandle(
  405. HANDLE *handle)
  406. {
  407. if(!handle)
  408. return ERROR_INVALID_PARAMETER;
  409. m_iRefCount++;
  410. *handle = (HANDLE)&m_resultItemList;
  411. return ERROR_SUCCESS;
  412. }
  413. /*--------------------------------------------------------------------------------------------------
  414. Method: GetResultItem()
  415. Synopisi: Returns the result item pointed to by position and sets [pos] to the next item.
  416. Arguments: [handle] - [in] A valid handle returns by GetResultItemHandle()
  417. [pos] - [in|out] The position of the result. If this value is NULL, the first result
  418. item in the list is returned.
  419. [pResult] - [out] A pointer to a result item pointer
  420. Returns: ERROR_SUCCESS - A result item was found for the position.
  421. ERROR_INVALID_PARAMETER - [handle] is invalid, or [pResult] is NULL
  422. --------------------------------------------------------------------------------------------------*/
  423. DWORD CFolder::GetResultItem(
  424. HANDLE handle,
  425. POSITION &pos,
  426. CResult **pResult)
  427. {
  428. if(!handle || handle != (HANDLE)&m_resultItemList || !pResult)
  429. return ERROR_INVALID_PARAMETER;
  430. if(!pos)
  431. {
  432. pos = m_resultItemList.GetHeadPosition();
  433. if(!pos)
  434. {
  435. *pResult = NULL;
  436. return ERROR_SUCCESS;
  437. }
  438. }
  439. *pResult = m_resultItemList.GetNext(pos);
  440. return ERROR_SUCCESS;
  441. }
  442. /*--------------------------------------------------------------------------------------------------
  443. Method: GetResultItemPosition()
  444. Synopisi: Returns the position of the result item in the result item list for this folder item.
  445. Arguments: [handle] - A valid handle returns by GetResultItemHandle()
  446. [pResult] - The retult item position to return.
  447. Returns: NULL - Invalid handle or the result item is not part of this folder.
  448. POSITION - A valid position value that can be used in other calls that require the
  449. position of the result item.
  450. --------------------------------------------------------------------------------------------------*/
  451. POSITION CFolder::GetResultItemPosition(
  452. HANDLE handle,
  453. CResult *pResult)
  454. {
  455. if(handle != (HANDLE)&m_resultItemList)
  456. return NULL;
  457. POSITION pos = m_resultItemList.GetHeadPosition();
  458. while(pos)
  459. {
  460. if(pResult == m_resultItemList.GetNext(pos))
  461. break;
  462. }
  463. return pos;
  464. }
  465. /*--------------------------------------------------------------------------------------------------
  466. Method: RemoveAllResultItems()
  467. Synopisi: Removes all result items from the list. This call sets the ref count to 0 so it could
  468. be a very damaging call.
  469. --------------------------------------------------------------------------------------------------*/
  470. void CFolder::RemoveAllResultItems()
  471. {
  472. //
  473. // Very Very dangerous call.
  474. //
  475. m_iRefCount = 1;
  476. HANDLE handle = (HANDLE)&m_resultItemList;
  477. ReleaseResultItemHandle (handle);
  478. }
  479. DWORD CFolder::GetDisplayName( CString &str, int iCol )
  480. {
  481. int npos;
  482. DWORD dwRet = ERROR_INVALID_PARAMETER;
  483. if(!iCol)
  484. {
  485. str = GetName();
  486. dwRet = ERROR_SUCCESS;
  487. }
  488. switch(m_type)
  489. {
  490. case PROFILE:
  491. case REG_OBJECTS:
  492. if(!iCol)
  493. {
  494. npos = str.ReverseFind(L'\\');
  495. str = GetName() + npos + 1;
  496. dwRet = ERROR_SUCCESS;
  497. }
  498. break;
  499. case FILE_OBJECTS:
  500. if (0 == iCol)
  501. {
  502. npos = str.ReverseFind(L'\\');
  503. if (str.GetLength() > npos + 1)
  504. {
  505. str=GetName() + npos + 1;
  506. }
  507. dwRet = ERROR_SUCCESS;
  508. }
  509. break;
  510. case STATIC:
  511. if(iCol == 2)
  512. {
  513. str = GetDesc();
  514. dwRet = ERROR_SUCCESS;
  515. }
  516. break;
  517. }
  518. if(dwRet != ERROR_SUCCESS)
  519. {
  520. if( ((m_type >= ANALYSIS && m_type <=AREA_FILESTORE_ANALYSIS) ||
  521. (m_type >= LOCALPOL_ACCOUNT && m_type <= LOCALPOL_LAST))
  522. && iCol == 1)
  523. {
  524. str = GetDesc();
  525. dwRet = ERROR_SUCCESS;
  526. }
  527. else if(iCol <= 3 && GetDesc() != NULL)
  528. {
  529. LPTSTR szDesc = GetDesc();
  530. switch(iCol)
  531. {
  532. case 1:
  533. // first 3 digits of m_pszDesc
  534. dwRet = 0;
  535. GetObjectInfo( &dwRet, NULL );
  536. ObjectStatusToString(dwRet, &str);
  537. dwRet = ERROR_SUCCESS;
  538. break;
  539. case 2:
  540. // first 2 digits of m_pszDesc
  541. dwRet = 0;
  542. GetObjectInfo( &dwRet, NULL );
  543. dwRet &= (~SCE_STATUS_PERMISSION_MISMATCH | 0x0F);
  544. ObjectStatusToString(dwRet, &str);
  545. dwRet = ERROR_SUCCESS;
  546. break;
  547. case 3:
  548. str = szDesc+3;
  549. dwRet = ERROR_SUCCESS;
  550. break;
  551. default:
  552. break;
  553. }
  554. }
  555. }
  556. return dwRet;
  557. }
  558. /*--------------------------------------------------------------------------------------------------
  559. Method: AddResultItem()
  560. Synopisi: Adds a result item to the list.
  561. Arguments: [handle] - [in] A handle returned by GetResultItemHandle().
  562. [pResult] - [in] The result item to add.
  563. Returns: ERROR_SUCCESS - The result item was added.
  564. ERROR_INVALID_PARAMETER - [handle] is invalid, or pResult is NULL.
  565. --------------------------------------------------------------------------------------------------*/
  566. DWORD CFolder::AddResultItem(
  567. HANDLE handle,
  568. CResult *pResult)
  569. {
  570. if(!pResult || handle != (HANDLE)&m_resultItemList)
  571. return ERROR_INVALID_PARAMETER;
  572. m_resultItemList.AddHead(pResult);
  573. return ERROR_SUCCESS;
  574. }
  575. /*--------------------------------------------------------------------------------------------------
  576. Method: RemoveResultItem()
  577. Synopisi: Removes a result item from the list..
  578. Arguments: [handle] - [in] A handle returned by GetResultItemHandle().
  579. [pResult] - [in] The result item to remove.
  580. Returns: ERROR_SUCCESS - The item was removed
  581. ERROR_INVALID_PARAMETER - [handle] is invalid, or pResult is NULL.
  582. ERROR_RESOURCE_NOT_FOUND - The result item does not exist withen this folder.
  583. --------------------------------------------------------------------------------------------------*/
  584. DWORD CFolder::RemoveResultItem (
  585. HANDLE handle,
  586. CResult *pItem)
  587. {
  588. if(!pItem || handle != (HANDLE)&m_resultItemList)
  589. return ERROR_INVALID_PARAMETER;
  590. POSITION posCur;
  591. POSITION pos = m_resultItemList.GetHeadPosition();
  592. while(pos)
  593. {
  594. posCur = pos;
  595. if ( m_resultItemList.GetNext(pos) == pItem )
  596. {
  597. m_resultItemList.RemoveAt(posCur);
  598. return ERROR_SUCCESS;
  599. }
  600. }
  601. return ERROR_RESOURCE_NOT_FOUND;
  602. }
  603. /*--------------------------------------------------------------------------------------------------
  604. Method: ReleaseResultItemHandle()
  605. Synopisi: Release associated data with the handle. If the ref count goes to zero then
  606. all result items are removed from the list.
  607. Arguments: [handle] - [in] A handle returned by GetResultItemHandle().
  608. Returns: ERROR_SUCCESS - The function succeded
  609. ERROR_INVALID_PARAMETER - [handle] is invalid.
  610. --------------------------------------------------------------------------------------------------*/
  611. DWORD CFolder::ReleaseResultItemHandle(
  612. HANDLE &handle)
  613. {
  614. if(handle != (HANDLE)&m_resultItemList)
  615. return ERROR_INVALID_PARAMETER;
  616. if( !m_iRefCount )
  617. return ERROR_SUCCESS;
  618. m_iRefCount--;
  619. if(!m_iRefCount)
  620. {
  621. while (!m_resultItemList.IsEmpty () )
  622. {
  623. CResult* pResult = m_resultItemList.RemoveHead ();
  624. if ( pResult )
  625. pResult->Release ();
  626. }
  627. }
  628. handle = NULL;
  629. return ERROR_SUCCESS;
  630. }
  631. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  632. // CResult
  633. //
  634. //+--------------------------------------------------------------------------
  635. //
  636. // Method: Create
  637. //
  638. // Synopsis: Initialize a CResult Object
  639. //
  640. //
  641. // Arguments: [szAttr] - The result item's display name
  642. // [dwBase] - The item's template setting
  643. // [dwSetting] - The item's last inspected setting
  644. // [type] - The type of the item's setting
  645. // [status] - The matched status of the item
  646. // [cookie] - The MMC cookie for this item
  647. // [szUnits] - The units this item's setting is measured in
  648. // [nID] - An identifier for the item, dependant on the type
  649. // [pBaseInfo] - The template object this item belongs to
  650. // [pDataObj] - The data object of the scope pane this item belongs to
  651. // [pNotify] - Object to pass notifications through
  652. // History:
  653. //
  654. //---------------------------------------------------------------------------
  655. HRESULT CResult::Create(LPCTSTR szAttr, // attribute's display name
  656. LONG_PTR dwBase, // template setting
  657. LONG_PTR dwSetting, // last inspected setting
  658. RESULT_TYPES type, // type of the item's setting
  659. int status, // matched status of the item
  660. MMC_COOKIE cookie, // the MMC cookie for this item
  661. LPCTSTR szUnits, // units the setting is measured in
  662. LONG_PTR nID, // An identifier for the item, dependant on the type
  663. PEDITTEMPLATE pBaseInfo, // The template object this item belongs to
  664. LPDATAOBJECT pDataObj, // The data object of the scope pane this item belongs to
  665. LPNOTIFY pNotify, // Notification object
  666. CSnapin *pSnapin) // Snapin window which owns this object
  667. {
  668. HRESULT hr = S_OK;
  669. m_type = type;
  670. m_status = status;
  671. m_cookie = cookie;
  672. m_dwBase = dwBase;
  673. m_dwSetting = dwSetting;
  674. m_nID = nID;
  675. m_profBase = pBaseInfo;
  676. //m_pDataObj = pDataObj;
  677. m_pNotify = pNotify;
  678. m_pSnapin = pSnapin;
  679. UINT uiByteLen = 0;
  680. LPTSTR psz = 0;
  681. if ( szAttr != NULL )
  682. {
  683. uiByteLen = (lstrlen(szAttr) + 1);
  684. psz = new TCHAR[uiByteLen];
  685. if (psz != NULL)
  686. {
  687. lstrcpy(psz, szAttr);
  688. }
  689. else
  690. {
  691. hr = E_OUTOFMEMORY;
  692. }
  693. if (m_szAttr)
  694. {
  695. delete [] m_szAttr;
  696. }
  697. m_szAttr = psz;
  698. }
  699. if ( szUnits != NULL )
  700. {
  701. SetUnits( szUnits );
  702. if(!m_szUnits){
  703. hr = E_OUTOFMEMORY;
  704. }
  705. }
  706. return hr;
  707. }
  708. void CResult::SetUnits(
  709. LPCTSTR sz)
  710. {
  711. if (ITEM_GROUP == GetType())
  712. {
  713. //
  714. // we shouldn't be storing this in a string storage
  715. // This isn't actually a string and shouldn't be copied. Yuck.
  716. //
  717. m_szUnits = (LPTSTR)sz;
  718. }
  719. else
  720. {
  721. if(m_szUnits)
  722. {
  723. LocalFree(m_szUnits);
  724. }
  725. m_szUnits = NULL;
  726. if(sz)
  727. {
  728. int iLen = lstrlen(sz);
  729. m_szUnits = (LPTSTR) LocalAlloc(0, (iLen + 1) * sizeof(TCHAR));
  730. if(!m_szUnits)
  731. return;
  732. lstrcpy(m_szUnits, sz);
  733. }
  734. }
  735. }
  736. //+--------------------------------------------------------------------------
  737. //
  738. // Method: Update
  739. //
  740. // Synopsis: Updates a changed result item and broadcasts
  741. // that change appropriately
  742. //
  743. // History:
  744. //
  745. //---------------------------------------------------------------------------
  746. void CResult::Update(CSnapin *pSnapin, BOOL bEntirePane)
  747. {
  748. LPARAM hint = 0;
  749. //
  750. // Set the appropriate template section as needing to be saved
  751. //
  752. if (m_profBase)
  753. {
  754. //
  755. // m_profBase will only be set for Configuation templates.
  756. // It will not be set for Analysis items
  757. //
  758. if (m_cookie && ((CFolder *)m_cookie)->GetType() < AREA_POLICY_ANALYSIS )
  759. {
  760. switch ( ((CFolder *)m_cookie)->GetType())
  761. {
  762. case POLICY_ACCOUNT:
  763. case POLICY_LOCAL:
  764. case POLICY_EVENTLOG:
  765. case POLICY_PASSWORD:
  766. case POLICY_KERBEROS:
  767. case POLICY_LOCKOUT:
  768. case POLICY_AUDIT:
  769. case POLICY_OTHER:
  770. case POLICY_LOG:
  771. m_profBase->SetDirty(AREA_SECURITY_POLICY);
  772. break;
  773. case AREA_PRIVILEGE:
  774. m_profBase->SetDirty(AREA_PRIVILEGES);
  775. break;
  776. case AREA_GROUPS:
  777. m_profBase->SetDirty(AREA_GROUP_MEMBERSHIP);
  778. break;
  779. case AREA_SERVICE:
  780. m_profBase->SetDirty(AREA_SYSTEM_SERVICE);
  781. break;
  782. case AREA_REGISTRY:
  783. m_profBase->SetDirty(AREA_REGISTRY_SECURITY);
  784. break;
  785. case AREA_FILESTORE:
  786. m_profBase->SetDirty(AREA_FILE_SECURITY);
  787. break;
  788. }
  789. }
  790. }
  791. //
  792. // Query the snap in data.
  793. //
  794. LPDATAOBJECT pDataObj;
  795. if( pSnapin->QueryDataObject( m_cookie, CCT_RESULT, &pDataObj ) != S_OK){
  796. return;
  797. }
  798. if(!m_pNotify){
  799. return;
  800. }
  801. //
  802. // Update all views.
  803. //
  804. if(bEntirePane)
  805. {
  806. if(!pSnapin->GetSelectedFolder())
  807. {
  808. return;
  809. }
  810. if( pDataObj && m_pNotify ) //Raid #357968, #354861, 4/25/2001
  811. {
  812. LPNOTIFY pNotify = m_pNotify;
  813. pSnapin->GetSelectedFolder()->RemoveAllResultItems();
  814. pNotify->UpdateAllViews(
  815. pDataObj,
  816. (LPARAM)pSnapin->GetSelectedFolder(),
  817. UAV_RESULTITEM_UPDATEALL
  818. );
  819. }
  820. }
  821. else
  822. {
  823. if (pDataObj && m_pNotify)
  824. {
  825. m_pNotify->UpdateAllViews(
  826. pDataObj,
  827. NULL,
  828. pSnapin->GetSelectedFolder(),
  829. this,
  830. UAV_RESULTITEM_UPDATE
  831. );
  832. pDataObj->Release();
  833. }
  834. }
  835. }
  836. //+--------------------------------------------------------------------------
  837. //
  838. // Method: GetAttrPretty
  839. //
  840. // Synopsis: Get the Attribute's display name as it should be displayed
  841. // in the result pane
  842. //
  843. // History:
  844. //
  845. //---------------------------------------------------------------------------
  846. LPCTSTR CResult::GetAttrPretty()
  847. {
  848. return GetAttr();
  849. }
  850. //+--------------------------------------------------------------------------
  851. //
  852. // Method: CResult::GetStatusErrorString
  853. //
  854. // Synopsis: This function caclulates the error status string to display
  855. // for the CResult item. In LPO mode it always returns
  856. // IDS_NOT_DEFINED, and for MB_TEMPLATE_EDITOR mode it always
  857. // Loads IDS_NOT_CONFIGURED
  858. //
  859. // Arguments: [pStr] - [Optional] CString object to load resource with.
  860. //
  861. // Returns: The resource ID to load. else zero if the error is not
  862. // defined.
  863. //
  864. // History: a-mthoge 11/17/1998
  865. //
  866. //---------------------------------------------------------------------------
  867. DWORD CResult::GetStatusErrorString( CString *pStr )
  868. {
  869. DWORD nRes = 0;
  870. if( m_cookie )
  871. {
  872. if( ((CFolder *)m_cookie)->GetModeBits() & MB_LOCALSEC )
  873. {
  874. if (GetType() ==ITEM_LOCALPOL_REGVALUE)
  875. {
  876. nRes = IDS_NOT_DEFINED;
  877. }
  878. else
  879. {
  880. nRes = IDS_NOT_APPLICABLE;
  881. }
  882. }
  883. else if ( ((CFolder *)m_cookie)->GetModeBits() & MB_RSOP )
  884. {
  885. nRes = IDS_NO_POLICY;
  886. }
  887. else if (((CFolder *)m_cookie)->GetModeBits() & MB_ANALYSIS_VIEWER)
  888. {
  889. nRes = IDS_NOT_ANALYZED;
  890. }
  891. else if( ((CFolder *)m_cookie)->GetModeBits() & (MB_TEMPLATE_EDITOR | MB_SINGLE_TEMPLATE_ONLY) )
  892. {
  893. nRes = IDS_NOT_CONFIGURED;
  894. }
  895. }
  896. if(!nRes)
  897. {
  898. nRes = GetStatus();
  899. if(!nRes)
  900. {
  901. nRes = GetStatus();
  902. }
  903. nRes = ObjectStatusToString( nRes, pStr );
  904. }
  905. else if(pStr)
  906. {
  907. pStr->LoadString( nRes );
  908. }
  909. return nRes;
  910. }
  911. LPCTSTR CResult::GetSourceGPOString()
  912. {
  913. // ASSERT(pFolder->GetModeBits() & RSOP);
  914. vector<PPRECEDENCEDISPLAY>* vppd = GetPrecedenceDisplays();
  915. if (vppd && !vppd->empty())
  916. {
  917. PPRECEDENCEDISPLAY ppd = vppd->front();
  918. return ppd->m_szGPO;
  919. }
  920. return NULL;
  921. }
  922. //+--------------------------------------------------------------------------
  923. //
  924. // Method: CResult::GetDisplayName
  925. //
  926. // Synopsis: Gets the display name for the result item.
  927. //
  928. // Arguments: [pFolder] - [Optional] If this parameter is NULL, m_Cookie
  929. // is used as the CFolder object.
  930. // [str] - [out] On exit this function will contain the
  931. // string to display.
  932. // [iCol] - [in] The column you want to retrieve the string
  933. // for.
  934. //
  935. // Returns: ERROR_SUCCESS - [str] is a valid string for the column.
  936. //
  937. // History: a-mthoge 11/17/1998
  938. //
  939. //---------------------------------------------------------------------------
  940. DWORD
  941. CResult::GetDisplayName(
  942. CFolder *pFolder,
  943. CString &str,
  944. int iCol
  945. )
  946. {
  947. DWORD dwRet = ERROR_INVALID_PARAMETER;
  948. //
  949. // If pFolder is not passed in then use the cookie as the CFolder
  950. // object.
  951. //
  952. if ( pFolder )
  953. {
  954. // bogus assertion?
  955. // ASSERT(pFolder != (CFolder *)GetCookie());
  956. } else {
  957. pFolder = (CFolder *)GetCookie();
  958. }
  959. LPTSTR pszAlloc = NULL;
  960. int npos = 0;
  961. if (iCol == 0) {
  962. //
  963. // First column strings.
  964. //
  965. str = GetAttr();
  966. if (pFolder &&
  967. (pFolder->GetType() < AREA_POLICY || pFolder->GetType() > REG_OBJECTS) ) {
  968. //
  969. // SCE Object strings
  970. //
  971. npos = str.ReverseFind(L'\\');
  972. } else {
  973. npos = 0;
  974. }
  975. //
  976. // All other strings.
  977. //
  978. if ( npos > 0 ) {
  979. str = GetAttr() + npos + 1;
  980. }
  981. return ERROR_SUCCESS;
  982. }
  983. if ( pFolder ) {
  984. //
  985. // Items that are defined by the folder type.
  986. //
  987. if ((pFolder->GetType() == AREA_REGISTRY ||
  988. pFolder->GetType() == AREA_FILESTORE) &&
  989. ((pFolder->GetModeBits() & MB_RSOP) == MB_RSOP) &&
  990. iCol == 1) {
  991. str = GetSourceGPOString();
  992. }
  993. switch (pFolder->GetType()) {
  994. case AREA_REGISTRY:
  995. case AREA_FILESTORE:
  996. //
  997. // profile objects area
  998. //
  999. switch (GetStatus()) {
  1000. case SCE_STATUS_IGNORE:
  1001. str.LoadString(IDS_OBJECT_IGNORE);
  1002. break;
  1003. case SCE_STATUS_OVERWRITE:
  1004. str.LoadString(IDS_OBJECT_OVERWRITE);
  1005. break;
  1006. }
  1007. dwRet = ERROR_SUCCESS;
  1008. break;
  1009. }
  1010. if ( pFolder->GetType() >= AREA_REGISTRY_ANALYSIS && pFolder->GetType() < AREA_LOCALPOL ) {
  1011. switch ( iCol ) {
  1012. case 1:
  1013. // permission status
  1014. dwRet = GetStatus() & (~SCE_STATUS_AUDIT_MISMATCH | 0x0F);
  1015. ObjectStatusToString(dwRet, &str);
  1016. break;
  1017. case 2:
  1018. // auditing status
  1019. dwRet = GetStatus() & (~SCE_STATUS_PERMISSION_MISMATCH | 0x0F);
  1020. ObjectStatusToString(dwRet, &str);
  1021. break;
  1022. default:
  1023. str = TEXT("0");
  1024. break;
  1025. }
  1026. dwRet = ERROR_SUCCESS;
  1027. }
  1028. if (dwRet == ERROR_SUCCESS) {
  1029. return dwRet;
  1030. }
  1031. }
  1032. //
  1033. // Items determined by result type.
  1034. //
  1035. switch ( GetType () ) {
  1036. case ITEM_PROF_GROUP:
  1037. if ( GetID() ) {
  1038. //
  1039. // Group member ship strings.
  1040. //
  1041. PSCE_GROUP_MEMBERSHIP pgm;
  1042. pgm = (PSCE_GROUP_MEMBERSHIP)( GetID() );
  1043. if ( iCol == 1) {
  1044. //
  1045. // Members string.
  1046. //
  1047. ConvertNameListToString(pgm->pMembers, &pszAlloc);
  1048. } else if (iCol == 2){
  1049. //
  1050. // Members of string.
  1051. //
  1052. ConvertNameListToString(pgm->pMemberOf, &pszAlloc);
  1053. } else if (iCol == 3) {
  1054. ASSERT(m_pSnapin->GetModeBits() & MB_RSOP);
  1055. str = GetSourceGPOString();
  1056. } else {
  1057. ASSERT(0 && "Illegal column");
  1058. }
  1059. if (pszAlloc) {
  1060. str = pszAlloc;
  1061. delete [] pszAlloc;
  1062. }
  1063. }
  1064. dwRet = ERROR_SUCCESS;
  1065. break;
  1066. case ITEM_GROUP:
  1067. if ( GetID() ) {
  1068. PSCE_GROUP_MEMBERSHIP pgm;
  1069. pgm = (PSCE_GROUP_MEMBERSHIP)(GetID());
  1070. if (iCol == 1) {
  1071. TranslateSettingToString(
  1072. GetGroupStatus( pgm->Status, STATUS_GROUP_MEMBERS ),
  1073. NULL,
  1074. GetType(),
  1075. &pszAlloc
  1076. );
  1077. } else if (iCol == 2) {
  1078. TranslateSettingToString(
  1079. GetGroupStatus(pgm->Status, STATUS_GROUP_MEMBEROF),
  1080. NULL,
  1081. GetType(),
  1082. &pszAlloc
  1083. );
  1084. } else {
  1085. ASSERT(0 && "Illegal column");
  1086. }
  1087. //
  1088. // Test to see if the result item already has a string, if it does then
  1089. // we will delete the old string.
  1090. //
  1091. if (pszAlloc) {
  1092. str = pszAlloc;
  1093. delete [] pszAlloc;
  1094. }
  1095. }
  1096. dwRet = ERROR_SUCCESS;
  1097. break;
  1098. case ITEM_PROF_REGVALUE:
  1099. if (iCol == 2 && (m_pSnapin->GetModeBits() & MB_RSOP) == MB_RSOP) {
  1100. str = GetSourceGPOString();
  1101. break;
  1102. }
  1103. case ITEM_REGVALUE:
  1104. case ITEM_LOCALPOL_REGVALUE:
  1105. {
  1106. PSCE_REGISTRY_VALUE_INFO prv = NULL;
  1107. if (iCol == 1) {
  1108. prv = (PSCE_REGISTRY_VALUE_INFO)(GetBase());
  1109. } else if (iCol == 2) {
  1110. prv = (PSCE_REGISTRY_VALUE_INFO)(GetSetting());
  1111. } else {
  1112. ASSERT(0 && "Illegal column");
  1113. }
  1114. if ( prv ) {
  1115. if ( iCol > 1 && !(prv->Value)) {
  1116. //
  1117. // Determine status fron analysis.
  1118. //
  1119. GetStatusErrorString( &str );
  1120. dwRet = ERROR_SUCCESS;
  1121. break;
  1122. }
  1123. //
  1124. // Determine string by the item value.
  1125. //
  1126. if ( dwRet != ERROR_SUCCESS ) {
  1127. pszAlloc = NULL;
  1128. switch ( GetID() ) {
  1129. case SCE_REG_DISPLAY_NUMBER:
  1130. if ( prv->Value ) {
  1131. TranslateSettingToString(
  1132. _wtol(prv->Value),
  1133. GetUnits(),
  1134. ITEM_DW,
  1135. &pszAlloc
  1136. );
  1137. }
  1138. break;
  1139. case SCE_REG_DISPLAY_CHOICE:
  1140. if ( prv->Value ) {
  1141. TranslateSettingToString(_wtol(prv->Value),
  1142. NULL,
  1143. ITEM_REGCHOICE,
  1144. &pszAlloc);
  1145. }
  1146. break;
  1147. case SCE_REG_DISPLAY_FLAGS:
  1148. if ( prv->Value ) {
  1149. TranslateSettingToString(_wtol(prv->Value),
  1150. NULL,
  1151. ITEM_REGFLAGS,
  1152. &pszAlloc);
  1153. if( pszAlloc == NULL ) //Raid #286697, 4/4/2001
  1154. {
  1155. str.LoadString(IDS_NO_MIN);
  1156. dwRet = ERROR_SUCCESS;
  1157. }
  1158. }
  1159. break;
  1160. case SCE_REG_DISPLAY_MULTISZ:
  1161. case SCE_REG_DISPLAY_STRING:
  1162. if (prv && prv->Value) {
  1163. str = prv->Value;
  1164. dwRet = ERROR_SUCCESS;
  1165. }
  1166. break;
  1167. default: // boolean
  1168. if ( prv->Value ) {
  1169. long val;
  1170. val = _wtol(prv->Value);
  1171. TranslateSettingToString( val,
  1172. NULL,
  1173. ITEM_BOOL,
  1174. &pszAlloc
  1175. );
  1176. }
  1177. break;
  1178. }
  1179. }
  1180. if (dwRet != ERROR_SUCCESS) {
  1181. if ( pszAlloc ) {
  1182. str = pszAlloc;
  1183. delete [] pszAlloc;
  1184. } else {
  1185. GetStatusErrorString(&str);
  1186. }
  1187. }
  1188. }
  1189. dwRet = ERROR_SUCCESS;
  1190. }
  1191. break;
  1192. }
  1193. if (dwRet != ERROR_SUCCESS) {
  1194. //
  1195. // Other areas.
  1196. //
  1197. if (iCol == 1) {
  1198. if( GetBase() == (LONG_PTR)ULongToPtr(SCE_NO_VALUE)){
  1199. if( m_pSnapin->GetModeBits() & MB_LOCALSEC){
  1200. str.LoadString(IDS_NOT_APPLICABLE);
  1201. } else {
  1202. str.LoadString(IDS_NOT_CONFIGURED);
  1203. }
  1204. } else {
  1205. //
  1206. // Edit template
  1207. //
  1208. GetBase(pszAlloc);
  1209. }
  1210. } else if (iCol == 2) {
  1211. if ((m_pSnapin->GetModeBits() & MB_RSOP) == MB_RSOP) {
  1212. //
  1213. // RSOP Mode
  1214. //
  1215. str = GetSourceGPOString();
  1216. } else {
  1217. //
  1218. // Analysis Template.
  1219. //
  1220. GetSetting(pszAlloc);
  1221. }
  1222. } else {
  1223. ASSERT(0 && "Illegal column");
  1224. }
  1225. if (pszAlloc) {
  1226. str = pszAlloc;
  1227. delete [] pszAlloc;
  1228. }
  1229. dwRet = ERROR_SUCCESS;
  1230. }
  1231. return dwRet;
  1232. }
  1233. //+--------------------------------------------------------------------------
  1234. //
  1235. // Function: TranslateSettingToString
  1236. //
  1237. // Synopsis: Convert a result pane setting into a string
  1238. //
  1239. // Arguments: [setting] - [in] The value to be converted
  1240. // [unit] - [in, optiona] The string for the units to use
  1241. // [type] - [in] The type of the setting to be converted
  1242. // [LPTSTR] - [in|out] the address to store the string at
  1243. //
  1244. // Returns: *[LPTSTR] - the translated string
  1245. //
  1246. //---------------------------------------------------------------------------
  1247. void CResult::TranslateSettingToString(LONG_PTR setting,
  1248. LPCTSTR unit,
  1249. RESULT_TYPES type,
  1250. LPTSTR* pTmpstr)
  1251. {
  1252. DWORD nRes = 0;
  1253. if (!pTmpstr)
  1254. {
  1255. ASSERT(pTmpstr);
  1256. return;
  1257. }
  1258. *pTmpstr = NULL;
  1259. switch ( setting )
  1260. {
  1261. case SCE_KERBEROS_OFF_VALUE:
  1262. nRes = IDS_OFF;
  1263. break;
  1264. case SCE_FOREVER_VALUE:
  1265. nRes = IDS_FOREVER;
  1266. break;
  1267. case SCE_ERROR_VALUE:
  1268. nRes = IDS_ERROR_VALUE;
  1269. break;
  1270. case SCE_NO_VALUE:
  1271. nRes = GetStatusErrorString( NULL );
  1272. break;
  1273. case SCE_NOT_ANALYZED_VALUE:
  1274. nRes = GetStatusErrorString( NULL );
  1275. break;
  1276. default:
  1277. switch ( type )
  1278. {
  1279. case ITEM_SZ:
  1280. case ITEM_PROF_SZ:
  1281. case ITEM_LOCALPOL_SZ:
  1282. if (setting && setting != (LONG_PTR)ULongToPtr(SCE_NO_VALUE))
  1283. {
  1284. *pTmpstr = new TCHAR[lstrlen((LPTSTR)setting)+1];
  1285. if (*pTmpstr)
  1286. wcscpy(*pTmpstr,(LPTSTR)setting);
  1287. }
  1288. else
  1289. nRes = GetStatusErrorString(NULL);
  1290. break;
  1291. case ITEM_PROF_BOOL:
  1292. case ITEM_LOCALPOL_BOOL:
  1293. case ITEM_BOOL:
  1294. if ( setting )
  1295. nRes = IDS_ENABLED;
  1296. else
  1297. nRes = IDS_DISABLED;
  1298. break;
  1299. case ITEM_PROF_BON:
  1300. case ITEM_LOCALPOL_BON:
  1301. case ITEM_BON:
  1302. if ( setting )
  1303. nRes = IDS_ON;
  1304. else
  1305. nRes = IDS_OFF;
  1306. break;
  1307. case ITEM_PROF_B2ON:
  1308. case ITEM_LOCALPOL_B2ON:
  1309. case ITEM_B2ON:
  1310. {
  1311. CString strAudit;
  1312. CString strFailure;
  1313. if ( setting & AUDIT_SUCCESS )
  1314. strAudit.LoadString(IDS_SUCCESS);
  1315. if ( setting & AUDIT_FAILURE )
  1316. {
  1317. if (setting & AUDIT_SUCCESS)
  1318. strAudit += TEXT(", ");
  1319. strFailure.LoadString(IDS_FAILURE);
  1320. strAudit += strFailure;
  1321. }
  1322. if (strAudit.IsEmpty())
  1323. strAudit.LoadString(IDS_DO_NOT_AUDIT);
  1324. *pTmpstr = new TCHAR [ strAudit.GetLength()+1 ];
  1325. if (*pTmpstr)
  1326. wcscpy(*pTmpstr, (LPCTSTR) strAudit);
  1327. }
  1328. break;
  1329. case ITEM_PROF_RET:
  1330. case ITEM_LOCALPOL_RET:
  1331. case ITEM_RET:
  1332. switch(setting)
  1333. {
  1334. case SCE_RETAIN_BY_DAYS:
  1335. nRes = IDS_BY_DAYS;
  1336. break;
  1337. case SCE_RETAIN_AS_NEEDED:
  1338. nRes = IDS_AS_NEEDED;
  1339. break;
  1340. case SCE_RETAIN_MANUALLY:
  1341. nRes = IDS_MANUALLY;
  1342. break;
  1343. default:
  1344. break;
  1345. }
  1346. break;
  1347. case ITEM_PROF_REGCHOICE:
  1348. case ITEM_REGCHOICE:
  1349. {
  1350. PREGCHOICE pRegChoice = m_pRegChoices;
  1351. while(pRegChoice)
  1352. {
  1353. if (pRegChoice->dwValue == (DWORD)setting)
  1354. {
  1355. *pTmpstr = new TCHAR[lstrlen(pRegChoice->szName)+1];
  1356. if (*pTmpstr)
  1357. wcscpy(*pTmpstr, (LPCTSTR) pRegChoice->szName);
  1358. break;
  1359. }
  1360. pRegChoice = pRegChoice->pNext;
  1361. }
  1362. break;
  1363. }
  1364. case ITEM_REGFLAGS:
  1365. {
  1366. TCHAR *pStr = NULL;
  1367. PREGFLAGS pRegFlags = m_pRegFlags;
  1368. while(pRegFlags)
  1369. {
  1370. if ((pRegFlags->dwValue & (DWORD) setting) == pRegFlags->dwValue)
  1371. {
  1372. pStr = *pTmpstr;
  1373. *pTmpstr = new TCHAR[(pStr?lstrlen(pStr):0)+lstrlen(pRegFlags->szName)+2];
  1374. if (*pTmpstr)
  1375. {
  1376. if (pStr)
  1377. {
  1378. lstrcpy(*pTmpstr, (LPCTSTR) pStr);
  1379. lstrcat(*pTmpstr,L",");
  1380. lstrcat(*pTmpstr, pRegFlags->szName);
  1381. }
  1382. else
  1383. lstrcpy(*pTmpstr, pRegFlags->szName);
  1384. }
  1385. if (pStr)
  1386. delete [] pStr;
  1387. }
  1388. pRegFlags = pRegFlags->pNext;
  1389. }
  1390. break;
  1391. }
  1392. case ITEM_PROF_GROUP:
  1393. case ITEM_PROF_PRIVS:
  1394. if (NULL != setting && (LONG_PTR)ULongToPtr(SCE_NO_VALUE) != setting )
  1395. ConvertNameListToString((PSCE_NAME_LIST) setting,pTmpstr);
  1396. break;
  1397. case ITEM_LOCALPOL_PRIVS:
  1398. if (NULL != setting && (LONG_PTR)ULongToPtr(SCE_NO_VALUE) != setting )
  1399. ConvertNameListToString(((PSCE_PRIVILEGE_ASSIGNMENT) setting)->AssignedTo,pTmpstr);
  1400. break;
  1401. case ITEM_PRIVS:
  1402. if (NULL != setting && (LONG_PTR)ULongToPtr(SCE_NO_VALUE) != setting )
  1403. ConvertNameListToString(((PSCE_PRIVILEGE_ASSIGNMENT) setting)->AssignedTo,pTmpstr);
  1404. else
  1405. nRes = GetStatusErrorString(NULL);
  1406. break;
  1407. case ITEM_GROUP:
  1408. //nRes = GetStatusErrorString(NULL);
  1409. nRes = ObjectStatusToString((DWORD) setting, NULL);
  1410. if ( setting == MY__SCE_MEMBEROF_NOT_APPLICABLE )
  1411. nRes = IDS_NOT_APPLICABLE;
  1412. break;
  1413. case ITEM_PROF_DW:
  1414. case ITEM_LOCALPOL_DW:
  1415. case ITEM_DW:
  1416. nRes = 0;
  1417. if ( unit )
  1418. {
  1419. *pTmpstr = new TCHAR[wcslen(unit)+20];
  1420. if (*pTmpstr)
  1421. swprintf(*pTmpstr, L"%d %s", setting, unit);
  1422. }
  1423. else
  1424. {
  1425. *pTmpstr = new TCHAR[20];
  1426. if (*pTmpstr)
  1427. swprintf(*pTmpstr, L"%d", setting);
  1428. }
  1429. break;
  1430. default:
  1431. *pTmpstr = NULL;
  1432. break;
  1433. }
  1434. break;
  1435. }
  1436. if (nRes)
  1437. {
  1438. CString strRes;
  1439. if (strRes.LoadString(nRes))
  1440. {
  1441. *pTmpstr = new TCHAR[strRes.GetLength()+1];
  1442. if (*pTmpstr)
  1443. wcscpy(*pTmpstr, (LPCTSTR) strRes);
  1444. else
  1445. {
  1446. //
  1447. // Couldn't allocate string so display will be blank.
  1448. //
  1449. }
  1450. }
  1451. else
  1452. {
  1453. //
  1454. // Couldn't load string so display will be blank.
  1455. //
  1456. }
  1457. }
  1458. }
  1459. //+--------------------------------------------------------------------------
  1460. //
  1461. // Function: GetProfileDefault()
  1462. //
  1463. // Synopsis: Find the default values for undefined policies
  1464. //
  1465. // Returns: The value to assign as the default value for the policy.
  1466. //
  1467. // SCE_NO_VALUE is returned on error.
  1468. //
  1469. //+--------------------------------------------------------------------------
  1470. DWORD_PTR
  1471. CResult::GetProfileDefault() {
  1472. PEDITTEMPLATE pet = NULL;
  1473. SCE_PROFILE_INFO *pspi = NULL;
  1474. if (!m_pSnapin) {
  1475. return (DWORD_PTR)ULongToPtr(SCE_NO_VALUE);
  1476. }
  1477. pet = m_pSnapin->GetTemplate(GT_DEFAULT_TEMPLATE);
  1478. if (pet && pet->pTemplate) {
  1479. pspi = pet->pTemplate;
  1480. }
  1481. #define PROFILE_DEFAULT(X,Y) ((pspi && (pspi->X != SCE_NO_VALUE)) ? pspi->X : Y)
  1482. #define PROFILE_KERB_DEFAULT(X,Y) ((pspi && pspi->pKerberosInfo && (pspi->pKerberosInfo->X != SCE_NO_VALUE)) ? pspi->pKerberosInfo->X : Y)
  1483. switch (m_nID) {
  1484. // L"Maximum passage age", L"Days"
  1485. case IDS_MAX_PAS_AGE:
  1486. return PROFILE_DEFAULT(MaximumPasswordAge,42);
  1487. // L"Minimum passage age", L"Days"
  1488. case IDS_MIN_PAS_AGE:
  1489. return PROFILE_DEFAULT(MinimumPasswordAge,0);
  1490. // L"Minimum passage length", L"Characters"
  1491. case IDS_MIN_PAS_LEN:
  1492. return PROFILE_DEFAULT(MinimumPasswordLength,0);
  1493. // L"Password history size", L"Passwords"
  1494. case IDS_PAS_UNIQUENESS:
  1495. return PROFILE_DEFAULT(PasswordHistorySize,0);
  1496. // L"Password complexity", L""
  1497. case IDS_PAS_COMPLEX:
  1498. return PROFILE_DEFAULT(PasswordComplexity,0);
  1499. // L"Clear Text Password", L""
  1500. case IDS_CLEAR_PASSWORD:
  1501. return PROFILE_DEFAULT(ClearTextPassword,0);
  1502. // L"Require logon to change password", L""
  1503. case IDS_REQ_LOGON:
  1504. return PROFILE_DEFAULT(RequireLogonToChangePassword,0);
  1505. case IDS_KERBEROS_MAX_SERVICE:
  1506. return PROFILE_KERB_DEFAULT(MaxServiceAge,600);
  1507. case IDS_KERBEROS_MAX_CLOCK:
  1508. return PROFILE_KERB_DEFAULT(MaxClockSkew,5);
  1509. case IDS_KERBEROS_RENEWAL:
  1510. return PROFILE_KERB_DEFAULT(MaxRenewAge,10);
  1511. case IDS_KERBEROS_MAX_AGE:
  1512. return PROFILE_KERB_DEFAULT(MaxTicketAge,7);
  1513. case IDS_KERBEROS_VALIDATE_CLIENT:
  1514. return PROFILE_KERB_DEFAULT(TicketValidateClient,1);
  1515. // L"Account lockout count", L"Attempts"
  1516. case IDS_LOCK_COUNT:
  1517. return PROFILE_DEFAULT(LockoutBadCount,0);
  1518. // L"Reset lockout count after", L"Minutes"
  1519. case IDS_LOCK_RESET_COUNT:
  1520. return PROFILE_DEFAULT(ResetLockoutCount,30);
  1521. // L"Lockout duration", L"Minutes"
  1522. case IDS_LOCK_DURATION:
  1523. return PROFILE_DEFAULT(LockoutDuration,30);
  1524. // L"Event Auditing Mode",
  1525. case IDS_EVENT_ON:
  1526. return 0;
  1527. // L"Audit system events"
  1528. case IDS_SYSTEM_EVENT:
  1529. return PROFILE_DEFAULT(AuditSystemEvents,0);
  1530. // L"Audit logon events"
  1531. case IDS_LOGON_EVENT:
  1532. return PROFILE_DEFAULT(AuditLogonEvents,0);
  1533. // L"Audit Object Access"
  1534. case IDS_OBJECT_ACCESS:
  1535. return PROFILE_DEFAULT(AuditObjectAccess,0);
  1536. // L"Audit Privilege Use"
  1537. case IDS_PRIVILEGE_USE:
  1538. return PROFILE_DEFAULT(AuditPrivilegeUse,0);
  1539. // L"Audit policy change"
  1540. case IDS_POLICY_CHANGE:
  1541. return PROFILE_DEFAULT(AuditPolicyChange,0);
  1542. // L"Audit Account Manage"
  1543. case IDS_ACCOUNT_MANAGE:
  1544. return PROFILE_DEFAULT(AuditAccountManage,0);
  1545. // L"Audit process tracking"
  1546. case IDS_PROCESS_TRACK:
  1547. return PROFILE_DEFAULT(AuditProcessTracking,0);
  1548. // L"Audit directory service access"
  1549. case IDS_DIRECTORY_ACCESS:
  1550. return PROFILE_DEFAULT(AuditDSAccess,0);
  1551. // L"Audit Account Logon"
  1552. case IDS_ACCOUNT_LOGON:
  1553. return PROFILE_DEFAULT(AuditAccountLogon,0);
  1554. // L"Network access: Allow anonymous SID/Name translation"
  1555. case IDS_LSA_ANON_LOOKUP:
  1556. return PROFILE_DEFAULT(LSAAnonymousNameLookup,0);
  1557. // L"Force logoff when logon hour expire", L""
  1558. case IDS_FORCE_LOGOFF:
  1559. return PROFILE_DEFAULT(ForceLogoffWhenHourExpire,0);
  1560. // L"Accounts: Administrator account status"
  1561. case IDS_ENABLE_ADMIN:
  1562. return PROFILE_DEFAULT(EnableAdminAccount,1);
  1563. // L"Accounts: Guest account status"
  1564. case IDS_ENABLE_GUEST:
  1565. return PROFILE_DEFAULT(EnableGuestAccount,0);
  1566. // L"... Log Maximum Size", L"KBytes"
  1567. case IDS_SYS_LOG_MAX:
  1568. return PROFILE_DEFAULT(MaximumLogSize[0],512);
  1569. case IDS_SEC_LOG_MAX:
  1570. return PROFILE_DEFAULT(MaximumLogSize[0],512);
  1571. case IDS_APP_LOG_MAX:
  1572. return PROFILE_DEFAULT(MaximumLogSize[0],512);
  1573. return 512;
  1574. // L"... Log Retention Method",
  1575. case IDS_SYS_LOG_RET:
  1576. return PROFILE_DEFAULT(AuditLogRetentionPeriod[0],1);
  1577. case IDS_SEC_LOG_RET:
  1578. return PROFILE_DEFAULT(AuditLogRetentionPeriod[0],1);
  1579. case IDS_APP_LOG_RET:
  1580. return PROFILE_DEFAULT(AuditLogRetentionPeriod[0],1);
  1581. return 1;
  1582. // L"... Log Retention days", "days"
  1583. case IDS_SYS_LOG_DAYS:
  1584. return PROFILE_DEFAULT(RetentionDays[0],7);
  1585. case IDS_SEC_LOG_DAYS:
  1586. return PROFILE_DEFAULT(RetentionDays[0],7);
  1587. case IDS_APP_LOG_DAYS:
  1588. return PROFILE_DEFAULT(RetentionDays[0],7);
  1589. // L"RestrictGuestAccess", L""
  1590. case IDS_SYS_LOG_GUEST:
  1591. return PROFILE_DEFAULT(RestrictGuestAccess[0],1);
  1592. case IDS_SEC_LOG_GUEST:
  1593. return PROFILE_DEFAULT(RestrictGuestAccess[0],1);
  1594. case IDS_APP_LOG_GUEST:
  1595. return PROFILE_DEFAULT(RestrictGuestAccess[0],1);
  1596. }
  1597. return (DWORD_PTR)ULongToPtr(SCE_NO_VALUE);
  1598. }
  1599. //+--------------------------------------------------------------------------
  1600. //
  1601. // Function: GetRegDefault()
  1602. //
  1603. // Synopsis: Find the default values for undefined policies
  1604. //
  1605. // Returns: The value to assign as the default value for the policy.
  1606. //
  1607. // SCE_NO_VALUE is returned on error.
  1608. //
  1609. //+--------------------------------------------------------------------------
  1610. DWORD_PTR
  1611. CResult::GetRegDefault() {
  1612. SCE_PROFILE_INFO *pspi = NULL;
  1613. LPTSTR szValue = NULL;
  1614. DWORD_PTR dwValue = SCE_NO_VALUE;
  1615. if (!m_pSnapin) {
  1616. return (DWORD_PTR)ULongToPtr(SCE_NO_VALUE);
  1617. }
  1618. PEDITTEMPLATE pet = m_pSnapin->GetTemplate(GT_DEFAULT_TEMPLATE);
  1619. if (!pet || !pet->pTemplate) {
  1620. return (DWORD_PTR)ULongToPtr(SCE_NO_VALUE);
  1621. }
  1622. if (pet && pet->pTemplate) {
  1623. pspi = pet->pTemplate;
  1624. }
  1625. PSCE_REGISTRY_VALUE_INFO regArrayThis = (PSCE_REGISTRY_VALUE_INFO)m_dwBase;
  1626. if (pspi != NULL)
  1627. {
  1628. PSCE_REGISTRY_VALUE_INFO regArray = pspi->aRegValues;
  1629. DWORD nCount = pspi->RegValueCount;
  1630. for(DWORD i=0;i<nCount;i++)
  1631. {
  1632. if (0 == lstrcmpi(regArray[i].FullValueName,
  1633. regArrayThis->FullValueName))
  1634. {
  1635. szValue = regArray[i].Value;
  1636. break;
  1637. }
  1638. }
  1639. }
  1640. switch (regArrayThis->ValueType)
  1641. {
  1642. case SCE_REG_DISPLAY_ENABLE:
  1643. if (szValue)
  1644. {
  1645. dwValue = (DWORD)StrToLong(szValue); //Raid #413311, 6/11/2001, Yanggao
  1646. }
  1647. if (dwValue == SCE_NO_VALUE)
  1648. {
  1649. // default: enable
  1650. dwValue = 1;
  1651. }
  1652. break;
  1653. case SCE_REG_DISPLAY_NUMBER:
  1654. if (szValue) {
  1655. dwValue = (DWORD)StrToLong(szValue); //Raid #413311, 6/11/2001, Yanggao
  1656. }
  1657. if (dwValue == SCE_NO_VALUE) {
  1658. dwValue = 1;
  1659. }
  1660. break;
  1661. case SCE_REG_DISPLAY_STRING:
  1662. if( szValue )
  1663. {
  1664. dwValue = (DWORD_PTR)szValue;
  1665. }
  1666. break;
  1667. case SCE_REG_DISPLAY_CHOICE:
  1668. if (szValue)
  1669. {
  1670. dwValue = (DWORD)StrToLong(szValue); //Raid #413311, 6/11/2001, Yanggao
  1671. }
  1672. if (dwValue == SCE_NO_VALUE)
  1673. {
  1674. dwValue = 0;
  1675. }
  1676. break;
  1677. case REG_MULTI_SZ: //Raid #413311, 6/11/2001, Yanggao
  1678. if (szValue)
  1679. {
  1680. dwValue = (DWORD_PTR)szValue; //Raid #367756, 4/13/2001
  1681. }
  1682. break;
  1683. default:
  1684. if (szValue)
  1685. {
  1686. dwValue = (DWORD)StrToLong(szValue); //Raid #413311, 6/11/2001, Yanggao
  1687. }
  1688. //Some security option in group policy is not defined. Their property pages should not display
  1689. //any item checked. It confuses user and creates inconsistence.
  1690. break;
  1691. }
  1692. return dwValue;
  1693. }
  1694. //+--------------------------------------------------------------------------
  1695. //
  1696. // Function: GetSnapin()
  1697. //
  1698. // Synopsis: Find current snapin of result item.
  1699. //
  1700. // Returns: Pointer of snapin
  1701. //
  1702. //+--------------------------------------------------------------------------
  1703. CSnapin* CResult::GetSnapin()
  1704. {
  1705. return m_pSnapin;
  1706. }