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.

266 lines
8.6 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2002.
  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. ASSERT (pCompData);
  41. if ( !pCompData )
  42. return;
  43. ASSERT (pszValueName);
  44. if ( !pszValueName )
  45. return;
  46. const CRSOPObjectArray* pObjectArray = bIsComputer ?
  47. pCompData->GetRSOPObjectArrayComputer () : pCompData->GetRSOPObjectArrayUser ();
  48. int nIndex = 0;
  49. // NOTE: rsop object array is sorted first by registry key, then by precedence
  50. INT_PTR nUpperBound = pObjectArray->GetUpperBound ();
  51. bool bFound = false;
  52. // security review 2/22/2002 BryanWal ok
  53. size_t nLenRegPath = wcslen (szRegPath);
  54. UINT nLastPrecedenceFound = 0;
  55. while ( nUpperBound >= nIndex )
  56. {
  57. CRSOPObject* pObject = pObjectArray->GetAt (nIndex);
  58. if ( pObject )
  59. {
  60. // Consider only entries from this store
  61. // security review 2/22/2002 BryanWal ok
  62. if ( !_wcsnicmp (szRegPath, pObject->GetRegistryKey (), nLenRegPath) )
  63. {
  64. // If the value is present, check for that, too
  65. if ( pszValueName )
  66. {
  67. if ( !wcscmp (STR_BLOB, pszValueName) )
  68. {
  69. // If not equal to "Blob" or "Blob0", then continue
  70. // security review 2/22/2002 BryanWal ok
  71. if ( wcscmp (STR_BLOB, pObject->GetValueName ()) &&
  72. wcscmp (STR_BLOB0, pObject->GetValueName ()) )
  73. {
  74. nIndex++;
  75. continue;
  76. }
  77. }
  78. // security review 2/22/2002 BryanWal ok
  79. else if ( wcscmp (pszValueName, pObject->GetValueName ()) ) // not equal
  80. {
  81. nIndex++;
  82. continue;
  83. }
  84. }
  85. bFound = true;
  86. // While we are only interested, for example, in the Root store,
  87. // there is no object ending in "Root", so we just want to get
  88. // any object from the root store and to find, essentially, how
  89. // many policies we're dealing with. So get one object from
  90. // each precedence level.
  91. if ( pObject->GetPrecedence () > nLastPrecedenceFound )
  92. {
  93. nLastPrecedenceFound = pObject->GetPrecedence ();
  94. // If there is a value, we want that, otherwise we only want the key
  95. if ( pszValueName || pObject->GetValueName ().IsEmpty () )
  96. {
  97. CRSOPObject* pNewObject = new CRSOPObject (*pObject);
  98. if ( pNewObject )
  99. m_rsopObjectArray.Add (pNewObject);
  100. }
  101. }
  102. }
  103. else if ( bFound )
  104. {
  105. // Since the list is sorted, and we've already found the
  106. // desired RSOP objects and no longer are finding them,
  107. // there aren't any more. We can optimize and break here.
  108. break;
  109. }
  110. }
  111. else
  112. break;
  113. nIndex++;
  114. }
  115. }
  116. CPolicyPrecedencePropertyPage::~CPolicyPrecedencePropertyPage()
  117. {
  118. int nIndex = 0;
  119. INT_PTR nUpperBound = m_rsopObjectArray.GetUpperBound ();
  120. while ( nUpperBound >= nIndex )
  121. {
  122. CRSOPObject* pCurrObject = m_rsopObjectArray.GetAt (nIndex);
  123. if ( pCurrObject )
  124. {
  125. delete pCurrObject;
  126. }
  127. nIndex++;
  128. }
  129. m_rsopObjectArray.RemoveAll ();
  130. }
  131. void CPolicyPrecedencePropertyPage::DoDataExchange(CDataExchange* pDX)
  132. {
  133. CHelpPropertyPage::DoDataExchange(pDX);
  134. //{{AFX_DATA_MAP(CPolicyPrecedencePropertyPage)
  135. DDX_Control(pDX, IDC_POLICY_PRECEDENCE, m_precedenceTable);
  136. //}}AFX_DATA_MAP
  137. }
  138. BEGIN_MESSAGE_MAP(CPolicyPrecedencePropertyPage, CHelpPropertyPage)
  139. //{{AFX_MSG_MAP(CPolicyPrecedencePropertyPage)
  140. //}}AFX_MSG_MAP
  141. END_MESSAGE_MAP()
  142. /////////////////////////////////////////////////////////////////////////////
  143. // CPolicyPrecedencePropertyPage message handlers
  144. BOOL CPolicyPrecedencePropertyPage::OnInitDialog()
  145. {
  146. CHelpPropertyPage::OnInitDialog();
  147. int colWidths[NUM_COLS] = {200, 100};
  148. // Add "Policy Name" column
  149. CString szText;
  150. VERIFY (szText.LoadString (IDS_PRECEDENCE_TABLE_GPO_NAME));
  151. VERIFY (m_precedenceTable.InsertColumn (COL_GPO_NAME, (LPCWSTR) szText,
  152. LVCFMT_LEFT, colWidths[COL_GPO_NAME], COL_GPO_NAME) != -1);
  153. // Add "Setting" column
  154. VERIFY (szText.LoadString (IDS_PRECEDENCE_TABLE_SETTING));
  155. VERIFY (m_precedenceTable.InsertColumn (COL_SETTING, (LPCWSTR) szText,
  156. LVCFMT_LEFT, colWidths[COL_SETTING], COL_SETTING) != -1);
  157. // Set to full-row select
  158. DWORD dwExstyle = m_precedenceTable.GetExtendedStyle ();
  159. m_precedenceTable.SetExtendedStyle (dwExstyle | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
  160. int nIndex = 0;
  161. INT_PTR nUpperBound = m_rsopObjectArray.GetUpperBound ();
  162. while ( nUpperBound >= nIndex )
  163. {
  164. CRSOPObject* pObject = m_rsopObjectArray.GetAt (nIndex);
  165. if ( pObject )
  166. {
  167. InsertItemInList (pObject);
  168. }
  169. else
  170. break;
  171. nIndex++;
  172. }
  173. return TRUE; // return TRUE unless you set the focus to a control
  174. // EXCEPTION: OCX Property Pages should return FALSE
  175. }
  176. void CPolicyPrecedencePropertyPage::InsertItemInList(const CRSOPObject * pObject)
  177. {
  178. _TRACE (1, L"CPolicyPrecedencePropertyPage::InsertItemInList\n");
  179. LV_ITEM lvItem;
  180. int iItem = m_precedenceTable.GetItemCount ();
  181. int iResult = 0;
  182. // security review 2/22/2002 BryanWal ok
  183. ::ZeroMemory (&lvItem, sizeof (lvItem));
  184. lvItem.mask = LVIF_TEXT;
  185. lvItem.iItem = iItem;
  186. lvItem.iSubItem = COL_GPO_NAME;
  187. lvItem.pszText = (LPWSTR)(LPCWSTR) pObject->GetPolicyName ();
  188. lvItem.iImage = 0;
  189. lvItem.lParam = 0;
  190. iItem = m_precedenceTable.InsertItem (&lvItem);
  191. ASSERT (-1 != iItem);
  192. if ( -1 == iItem )
  193. return;
  194. CString szEnabled;
  195. CString szDisabled;
  196. VERIFY (szEnabled.LoadString (IDS_ENABLED));
  197. VERIFY (szDisabled.LoadString (IDS_DISABLED));
  198. // security review 2/22/2002 BryanWal ok
  199. ::ZeroMemory (&lvItem, sizeof (lvItem));
  200. lvItem.mask = LVIF_TEXT;
  201. lvItem.iItem = iItem;
  202. lvItem.iSubItem = COL_SETTING;
  203. lvItem.pszText = (LPWSTR)(LPCWSTR) ((1 == pObject->GetPrecedence ()) ? szEnabled : szDisabled);
  204. iResult = m_precedenceTable.SetItem (&lvItem);
  205. ASSERT (-1 != iResult);
  206. _TRACE (-1, L"Leaving CPolicyPrecedencePropertyPage::InsertItemInList\n");
  207. }
  208. void CPolicyPrecedencePropertyPage::DoContextHelp (HWND hWndControl)
  209. {
  210. _TRACE (1, L"Entering CPolicyPrecedencePropertyPage::DoContextHelp\n");
  211. static const DWORD help_map[] =
  212. {
  213. IDC_POLICY_PRECEDENCE, IDH_POLICY_PRECEDENCE,
  214. 0, 0
  215. };
  216. switch (::GetDlgCtrlID (hWndControl))
  217. {
  218. case IDC_POLICY_PRECEDENCE:
  219. if ( !::WinHelp (
  220. hWndControl,
  221. GetF1HelpFilename(),
  222. HELP_WM_HELP,
  223. (DWORD_PTR) help_map) )
  224. {
  225. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  226. }
  227. break;
  228. default:
  229. break;
  230. }
  231. _TRACE (-1, L"Leaving CPolicyPrecedencePropertyPage::DoContextHelp\n");
  232. }