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.

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