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.

233 lines
7.4 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2001.
  6. //
  7. // File: PolicyPrecedencePropertyPage.cpp
  8. //
  9. // Contents: Implementation of PolicyPrecedencePropertyPage
  10. //
  11. //----------------------------------------------------------------------------
  12. // PolicyPrecedencePropertyPage.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include <gpedit.h>
  16. #include "compdata.h"
  17. #include "PolicyPrecedencePropertyPage.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. enum {
  24. COL_GPO_NAME = 0,
  25. COL_SETTING,
  26. NUM_COLS
  27. };
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CPolicyPrecedencePropertyPage property page
  30. CPolicyPrecedencePropertyPage::CPolicyPrecedencePropertyPage(
  31. const CCertMgrComponentData* pCompData,
  32. const CString& szRegPath,
  33. PCWSTR pszValueName,
  34. bool bIsComputer)
  35. : CHelpPropertyPage(CPolicyPrecedencePropertyPage::IDD)
  36. {
  37. //{{AFX_DATA_INIT(CPolicyPrecedencePropertyPage)
  38. // NOTE: the ClassWizard will add member initialization here
  39. //}}AFX_DATA_INIT
  40. const CRSOPObjectArray* pObjectArray = bIsComputer ?
  41. pCompData->GetRSOPObjectArrayComputer () : pCompData->GetRSOPObjectArrayUser ();
  42. int nIndex = 0;
  43. // NOTE: rsop object array is sorted first by registry key, then by precedence
  44. INT_PTR nUpperBound = pObjectArray->GetUpperBound ();
  45. bool bFound = false;
  46. size_t nLenRegPath = wcslen (szRegPath);
  47. UINT nLastPrecedenceFound = 0;
  48. while ( nUpperBound >= nIndex )
  49. {
  50. CRSOPObject* pObject = pObjectArray->GetAt (nIndex);
  51. if ( pObject )
  52. {
  53. // Consider only entries from this store
  54. if ( !_wcsnicmp (szRegPath, pObject->GetRegistryKey (), nLenRegPath) )
  55. {
  56. // If the value is present, check for that, too
  57. if ( pszValueName )
  58. {
  59. if ( !wcscmp (STR_BLOB, pszValueName) )
  60. {
  61. // If not equal to "Blob" or "Blob0", then continue
  62. if ( wcscmp (STR_BLOB, pObject->GetValueName ()) &&
  63. wcscmp (STR_BLOB0, pObject->GetValueName ()) )
  64. {
  65. nIndex++;
  66. continue;
  67. }
  68. }
  69. else if ( wcscmp (pszValueName, pObject->GetValueName ()) ) // not equal
  70. {
  71. nIndex++;
  72. continue;
  73. }
  74. }
  75. bFound = true;
  76. // While we are only interested, for example, in the Root store,
  77. // there is no object ending in "Root", so we just want to get
  78. // any object from the root store and to find, essentially, how
  79. // many policies we're dealing with. So get one object from
  80. // each precedence level.
  81. if ( pObject->GetPrecedence () > nLastPrecedenceFound )
  82. {
  83. nLastPrecedenceFound = pObject->GetPrecedence ();
  84. // If there is a value, we want that, otherwise we only want the key
  85. if ( pszValueName || pObject->GetValueName ().IsEmpty () )
  86. {
  87. CRSOPObject* pNewObject = new CRSOPObject (*pObject);
  88. if ( pNewObject )
  89. m_rsopObjectArray.Add (pNewObject);
  90. }
  91. }
  92. }
  93. else if ( bFound )
  94. {
  95. // Since the list is sorted, and we've already found the
  96. // desired RSOP objects and no longer are finding them,
  97. // there aren't any more. We can optimize and break here.
  98. break;
  99. }
  100. }
  101. else
  102. break;
  103. nIndex++;
  104. }
  105. }
  106. CPolicyPrecedencePropertyPage::~CPolicyPrecedencePropertyPage()
  107. {
  108. m_rsopObjectArray.RemoveAll ();
  109. }
  110. void CPolicyPrecedencePropertyPage::DoDataExchange(CDataExchange* pDX)
  111. {
  112. CHelpPropertyPage::DoDataExchange(pDX);
  113. //{{AFX_DATA_MAP(CPolicyPrecedencePropertyPage)
  114. DDX_Control(pDX, IDC_POLICY_PRECEDENCE, m_precedenceTable);
  115. //}}AFX_DATA_MAP
  116. }
  117. BEGIN_MESSAGE_MAP(CPolicyPrecedencePropertyPage, CHelpPropertyPage)
  118. //{{AFX_MSG_MAP(CPolicyPrecedencePropertyPage)
  119. //}}AFX_MSG_MAP
  120. END_MESSAGE_MAP()
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CPolicyPrecedencePropertyPage message handlers
  123. BOOL CPolicyPrecedencePropertyPage::OnInitDialog()
  124. {
  125. CHelpPropertyPage::OnInitDialog();
  126. int colWidths[NUM_COLS] = {200, 100};
  127. // Add "Policy Name" column
  128. CString szText;
  129. VERIFY (szText.LoadString (IDS_PRECEDENCE_TABLE_GPO_NAME));
  130. VERIFY (m_precedenceTable.InsertColumn (COL_GPO_NAME, (LPCWSTR) szText,
  131. LVCFMT_LEFT, colWidths[COL_GPO_NAME], COL_GPO_NAME) != -1);
  132. // Add "Setting" column
  133. VERIFY (szText.LoadString (IDS_PRECEDENCE_TABLE_SETTING));
  134. VERIFY (m_precedenceTable.InsertColumn (COL_SETTING, (LPCWSTR) szText,
  135. LVCFMT_LEFT, colWidths[COL_SETTING], COL_SETTING) != -1);
  136. // Set to full-row select
  137. DWORD dwExstyle = m_precedenceTable.GetExtendedStyle ();
  138. m_precedenceTable.SetExtendedStyle (dwExstyle | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
  139. int nIndex = 0;
  140. INT_PTR nUpperBound = m_rsopObjectArray.GetUpperBound ();
  141. while ( nUpperBound >= nIndex )
  142. {
  143. CRSOPObject* pObject = m_rsopObjectArray.GetAt (nIndex);
  144. if ( pObject )
  145. {
  146. InsertItemInList (pObject);
  147. }
  148. else
  149. break;
  150. nIndex++;
  151. }
  152. return TRUE; // return TRUE unless you set the focus to a control
  153. // EXCEPTION: OCX Property Pages should return FALSE
  154. }
  155. void CPolicyPrecedencePropertyPage::InsertItemInList(const CRSOPObject * pObject)
  156. {
  157. _TRACE (1, L"CPolicyPrecedencePropertyPage::InsertItemInList\n");
  158. LV_ITEM lvItem;
  159. int iItem = m_precedenceTable.GetItemCount ();
  160. int iResult = 0;
  161. ::ZeroMemory (&lvItem, sizeof (lvItem));
  162. lvItem.mask = LVIF_TEXT;
  163. lvItem.iItem = iItem;
  164. lvItem.iSubItem = COL_GPO_NAME;
  165. lvItem.pszText = (LPWSTR)(LPCWSTR) pObject->GetPolicyName ();
  166. lvItem.iImage = 0;
  167. lvItem.lParam = 0;
  168. iItem = m_precedenceTable.InsertItem (&lvItem);
  169. ASSERT (-1 != iItem);
  170. if ( -1 == iItem )
  171. return;
  172. CString szEnabled;
  173. CString szDisabled;
  174. VERIFY (szEnabled.LoadString (IDS_ENABLED));
  175. VERIFY (szDisabled.LoadString (IDS_DISABLED));
  176. ::ZeroMemory (&lvItem, sizeof (lvItem));
  177. lvItem.mask = LVIF_TEXT;
  178. lvItem.iItem = iItem;
  179. lvItem.iSubItem = COL_SETTING;
  180. lvItem.pszText = (LPWSTR)(LPCWSTR) ((1 == pObject->GetPrecedence ()) ? szEnabled : szDisabled);
  181. iResult = m_precedenceTable.SetItem (&lvItem);
  182. ASSERT (-1 != iResult);
  183. _TRACE (-1, L"Leaving CPolicyPrecedencePropertyPage::InsertItemInList\n");
  184. }
  185. void CPolicyPrecedencePropertyPage::DoContextHelp (HWND hWndControl)
  186. {
  187. _TRACE (1, L"Entering CPolicyPrecedencePropertyPage::DoContextHelp\n");
  188. static const DWORD help_map[] =
  189. {
  190. IDC_POLICY_PRECEDENCE, IDH_POLICY_PRECEDENCE,
  191. 0, 0
  192. };
  193. if ( !::WinHelp (
  194. hWndControl,
  195. GetF1HelpFilename(),
  196. HELP_WM_HELP,
  197. (DWORD_PTR) help_map) )
  198. {
  199. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  200. }
  201. _TRACE (-1, L"Leaving CPolicyPrecedencePropertyPage::DoContextHelp\n");
  202. }