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.

1402 lines
41 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: sprpage.cpp
  7. //
  8. // Contents: WiF Policy Snapin: Policy Description/ Manager Page.
  9. //
  10. //
  11. // History: TaroonM
  12. // 10/30/01
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #include "sprpage.h"
  17. #include "nfaa.h"
  18. #include "ssidpage.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. typedef CTypedPtrList<CPtrList, PWIRELESS_PS_DATA> CSNPPSList;
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CSecPolRulesPage property page
  27. const TCHAR CSecPolRulesPage::STICKY_SETTING_USE_SEC_POLICY_WIZARD[] = _T("UseSecPolicyWizard");
  28. IMPLEMENT_DYNCREATE(CSecPolRulesPage, CSnapinPropPage)
  29. //Taroon:: Big change here.. check if it is correct
  30. CSecPolRulesPage::CSecPolRulesPage() : CSnapinPropPage(CSecPolRulesPage::IDD,FALSE)
  31. {
  32. //{{AFX_DATA_INIT(CSecPolRulesPage)
  33. // NOTE: the ClassWizard will add member initialization here
  34. //}}AFX_DATA_INIT
  35. m_iSortSubItem = 0;
  36. m_bSortOrder = TRUE;
  37. m_MMCthreadID = ::GetCurrentThreadId();
  38. m_pPrpSh = NULL;
  39. m_bHasWarnedPSCorruption = FALSE;
  40. m_currentWirelessPolicyData = NULL;
  41. m_bReadOnly = FALSE;
  42. }
  43. CSecPolRulesPage::~CSecPolRulesPage()
  44. {
  45. }
  46. void CSecPolRulesPage::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CSnapinPropPage::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CSecPolRulesPage)
  50. DDX_Control(pDX, IDC_PS_LIST, m_lstActions);
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CSecPolRulesPage, CSnapinPropPage)
  54. //{{AFX_MSG_MAP(CSecPolRulesPage)
  55. ON_BN_CLICKED(IDC_ACTION_PS_ADD, OnActionAdd)
  56. ON_BN_CLICKED(IDC_ACTION_PS_EDIT, OnActionEdit)
  57. ON_BN_CLICKED(IDC_ACTION_PS_REMOVE, OnActionRemove)
  58. ON_BN_CLICKED(IDC_PS_UP, OnActionUp)
  59. ON_BN_CLICKED(IDC_PS_DOWN,OnActionDown)
  60. ON_NOTIFY(NM_DBLCLK, IDC_PS_LIST, OnDblclkActionslist)
  61. //ON_NOTIFY(LVN_COLUMNCLICK, IDC_ACTIONSLIST, OnColumnclickActionslist)
  62. //ON_NOTIFY(NM_CLICK, IDC_ACTIONSLIST, OnClickActionslist)
  63. ON_WM_HELPINFO()
  64. ON_NOTIFY(LVN_ITEMCHANGED, IDC_PS_LIST, OnItemchangedActionslist)
  65. ON_NOTIFY(LVN_KEYDOWN, IDC_PS_LIST, OnKeydownActionslist)
  66. ON_WM_DESTROY()
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CSecPolRulesPage message handlers
  71. BOOL CSecPolRulesPage::OnApply()
  72. {
  73. //if there is any sub dialog active, we cannot apply
  74. if (m_pPrpSh)
  75. {
  76. return FALSE;
  77. }
  78. // the rules page doesn't actually have any data on it that
  79. // the user might modify and then apply. in fact all changes
  80. // from this page actually happen directly on the dsObjects
  81. if( ERROR_SUCCESS != UpdateWlstore()) {
  82. PopulateListControl();
  83. return FALSE;
  84. }
  85. if (!m_bReadOnly) {
  86. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  87. pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  88. UpdateWirelessPolicyDataWithPreferredSettings(
  89. pWirelessPolicyData,
  90. m_currentWirelessPolicyData
  91. );
  92. }
  93. return CSnapinPropPage::OnApply();
  94. }
  95. HRESULT CSecPolRulesPage::UpdateWlstore()
  96. {
  97. HRESULT hr = S_OK;
  98. HANDLE hPolicyStore = NULL;
  99. SNP_PS_LIST::iterator theIterator;
  100. BOOL dwModified = FALSE;
  101. CComObject<CSecPolItem>* pResultItem = NULL;
  102. PWIRELESS_POLICY_DATA pWirelessPolicyData;
  103. pResultItem = GetResultObject();
  104. hPolicyStore = pResultItem->m_pComponentDataImpl->GetPolicyStoreHandle();
  105. ASSERT(hPolicyStore);
  106. pWirelessPolicyData = pResultItem->GetWirelessPolicy();
  107. for(theIterator = m_NfaList.begin(); theIterator != m_NfaList.end(); theIterator++)
  108. {
  109. PSNP_PS_DATA pNfaData = (PSNP_PS_DATA) (*theIterator);
  110. PWIRELESS_PS_DATA pBWirelessPSData = pNfaData->pWirelessPSData;
  111. switch(pNfaData->status)
  112. {
  113. case NEW:
  114. {
  115. break;
  116. }
  117. case MODIFIED:
  118. {
  119. break;
  120. }
  121. case BEREMOVED:
  122. {
  123. break;
  124. }
  125. }//switch
  126. }//for
  127. return hr;
  128. }
  129. void CSecPolRulesPage::OnCancel()
  130. {
  131. //WirelessFreePolicyData(m_currentWirelessPolicyData);
  132. CSnapinPropPage::OnCancel();
  133. }
  134. BOOL CSecPolRulesPage::OnInitDialog()
  135. {
  136. CSnapinPropPage::OnInitDialog();
  137. DWORD dwError = 0;
  138. m_pPrpSh = NULL;
  139. // set headers on the list control
  140. m_lstActions.InsertColumn(0,ResourcedString(IDS_COLUMN_SSIDNAME), LVCFMT_CENTER, 120, 0);
  141. m_lstActions.InsertColumn(1,ResourcedString(IDS_COLUMN_AUTHMETHOD), LVCFMT_CENTER, 80, 1);
  142. m_lstActions.InsertColumn(2,ResourcedString(IDS_COLUMN_PRIVACY), LVCFMT_CENTER, 80, 2);
  143. //m_lstActions.InsertColumn(3,ResourcedString(IDS_COLUMN_ADAPTERTYPE), LVCFMT_LEFT, 90, 3);
  144. // set the image list
  145. CThemeContextActivator activator;
  146. m_imagelistChecks.Create(IDB_PSTYPE, 16, 1, RGB(0,255,0));
  147. // m_lstActions.SetImageList (&m_imagelistChecks, LVSIL_STATE);
  148. m_lstActions.SetImageList (CImageList::FromHandle(m_imagelistChecks), LVSIL_SMALL);
  149. // turn on entire row selection
  150. ListView_SetExtendedListViewStyle (m_lstActions.GetSafeHwnd(), LVS_EX_FULLROWSELECT);
  151. // Copy the Policy Data to the m_currentWirelessPolicyData
  152. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  153. pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  154. dwError = CopyWirelessPolicyData(
  155. pWirelessPolicyData,
  156. &m_currentWirelessPolicyData
  157. );
  158. if(dwError) {
  159. ReportError(IDS_DISPLAY_ERROR, 0);
  160. BAIL_ON_WIN32_ERROR(dwError);
  161. }
  162. if (pWirelessPolicyData->dwFlags & WLSTORE_READONLY) {
  163. m_bReadOnly = TRUE;
  164. }
  165. if (m_bReadOnly) {
  166. DisableControls();
  167. }
  168. //store the rules data in m_NfaList linked list
  169. InitialzeNfaList(); //taroonm
  170. // fill the list control with the current PSs
  171. PopulateListControl(); //taroonm
  172. // Select the first list item
  173. if (m_lstActions.GetItemCount())
  174. {
  175. m_lstActions.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  176. EnableDisableButtons ();
  177. }
  178. // OK, we can start paying attention to modifications made via dlg controls now.
  179. // This should be the last call before returning from OnInitDialog.
  180. OnFinishInitDialog();
  181. return TRUE; // return TRUE unless you set the focus to a control
  182. // EXCEPTION: OCX Property Pages should return FALSE
  183. error:
  184. return(FALSE);
  185. }
  186. void CSecPolRulesPage::InitialzeNfaList()
  187. {
  188. HRESULT hr;
  189. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  190. PWIRELESS_PS_DATA * ppWirelessPSData = NULL;
  191. PWIRELESS_PS_DATA pAWirelessPSData = NULL;
  192. DWORD i = 0;
  193. HANDLE hPolicyStore = NULL;
  194. DWORD dwNumPSObjects = 0;
  195. CComObject<CSecPolItem>* pResultItem = NULL;
  196. DWORD dwError = 0;
  197. SNP_PS_LIST::iterator theIterator;
  198. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  199. PSNP_PS_DATA pNfaData = NULL;
  200. // Unselect Everything First
  201. SELECT_NO_LISTITEM( m_lstActions );
  202. //empty the previous List
  203. if (!m_NfaList.empty()) {
  204. for(theIterator = m_NfaList.begin();theIterator != m_NfaList.end(); ++theIterator) {
  205. pNfaData = (PSNP_PS_DATA)(*theIterator);
  206. pWirelessPSData = pNfaData->pWirelessPSData;
  207. FreeWirelessPSData(pWirelessPSData);
  208. LocalFree(pNfaData);
  209. }
  210. }
  211. m_NfaList.clear();
  212. pWirelessPolicyData = m_currentWirelessPolicyData;
  213. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  214. dwNumPSObjects = pWirelessPolicyData->dwNumPreferredSettings;
  215. for (i = 0; i < dwNumPSObjects; i++) {
  216. DWORD dwErrorTmp = ERROR_SUCCESS;
  217. pAWirelessPSData = *(ppWirelessPSData + i);
  218. PSNP_PS_DATA pNfaData = NULL;
  219. pNfaData = (PSNP_PS_DATA) LocalAlloc(LMEM_ZEROINIT, sizeof(SNP_PS_DATA));
  220. if(pNfaData == NULL) {
  221. goto error;
  222. }
  223. pNfaData->status = NOTMODIFIED; //taroonm
  224. dwError = CopyWirelessPSData(pAWirelessPSData,&pNfaData->pWirelessPSData);
  225. BAIL_ON_WIN32_ERROR(dwError);
  226. m_NfaList.push_back(pNfaData);
  227. }//for
  228. return;
  229. error:
  230. //
  231. // BugBug KrishnaG cleanup
  232. //
  233. // Taroon:: TODO Deallocate the m_nfa list here and report Error
  234. ReportError(IDS_DISPLAY_ERROR, HRESULT_FROM_WIN32(dwError));
  235. return;
  236. }
  237. void CSecPolRulesPage::UnPopulateListControl ()
  238. {
  239. int nIndex=0;
  240. // Make sure no items are selected so EnableDisableButtons doesn't do
  241. // so much work when its called by the LVN_ITEMCHANGED handler. (_DEBUG only)
  242. SELECT_NO_LISTITEM( m_lstActions );
  243. m_lstActions.DeleteAllItems();
  244. }
  245. CString CSecPolRulesPage::GetColumnStrBuffer (PWIRELESS_PS_DATA pWirelessPSData, int iColumn)
  246. {
  247. CString strBuffer;
  248. HANDLE hPolicyStore = NULL;
  249. GUID ZeroGuid;
  250. DWORD dwError = 0;
  251. BOOL bInitial = TRUE;
  252. CComObject<CSecPolItem>* pResultItem = NULL;
  253. pResultItem = GetResultObject();
  254. hPolicyStore = pResultItem->m_pComponentDataImpl->GetPolicyStoreHandle();
  255. switch (iColumn)
  256. {
  257. case 0:
  258. strBuffer = pWirelessPSData->pszWirelessSSID;
  259. break;
  260. case 1:
  261. if (pWirelessPSData->dwEnable8021x) {
  262. strBuffer.LoadString (IDS_8021X_ENABLED);
  263. } else {
  264. strBuffer.LoadString (IDS_8021X_DISABLED);
  265. }
  266. break;
  267. case 2:
  268. if (pWirelessPSData->dwWepEnabled) {
  269. strBuffer.LoadString (IDS_WEP_ENABLED);
  270. } else {
  271. strBuffer.LoadString (IDS_WEP_DISABLED);
  272. }
  273. break;
  274. default:
  275. ASSERT (0);
  276. strBuffer.LoadString (IDS_DATAERROR);
  277. break;
  278. }
  279. return strBuffer;
  280. }
  281. void CSecPolRulesPage::PopulateListControl()
  282. {
  283. HRESULT hr = S_OK;
  284. PSNP_PS_DATA pNfaData;
  285. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  286. LV_ITEM item;
  287. CString strBuffer;
  288. int nItem = 0;
  289. int nSubItem = 0;
  290. SNP_PS_LIST::reverse_iterator theIterator;
  291. // clear out the list control
  292. UnPopulateListControl();
  293. for (theIterator = m_NfaList.rbegin(); theIterator != m_NfaList.rend();
  294. theIterator++)
  295. {
  296. pNfaData = (PSNP_PS_DATA)(*theIterator);
  297. pWirelessPSData = pNfaData->pWirelessPSData;
  298. if( pNfaData->status == BEREMOVED || pNfaData->status == REMOVED || pNfaData->status == NEWREMOVED ) {
  299. continue;
  300. }
  301. item.mask = LVIF_TEXT | LVIF_IMAGE;
  302. // item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
  303. item.iItem = nItem;
  304. nSubItem = 0;
  305. // Set the Network type
  306. if (pWirelessPSData->dwNetworkType == WIRELESS_NETWORK_TYPE_ADHOC) {
  307. item.iImage = 5;
  308. }
  309. if (pWirelessPSData->dwNetworkType == WIRELESS_NETWORK_TYPE_AP) {
  310. item.iImage = 3;
  311. }
  312. // "Wireless SSID"
  313. item.iSubItem = nSubItem++;
  314. strBuffer = GetColumnStrBuffer (pWirelessPSData, 0);
  315. item.pszText = strBuffer.GetBuffer(32);
  316. item.iItem = m_lstActions.InsertItem (&item);
  317. // "Negotiation Policy
  318. item.iSubItem = nSubItem++;
  319. strBuffer = GetColumnStrBuffer (pWirelessPSData, 1);
  320. item.pszText = strBuffer.GetBuffer(20);
  321. m_lstActions.SetItem (&item);
  322. // "Authentication Method"
  323. item.iSubItem = nSubItem++;
  324. strBuffer = GetColumnStrBuffer (pWirelessPSData, 2);
  325. item.pszText = strBuffer.GetBuffer(20);
  326. m_lstActions.SetItem (&item);
  327. // store the pWirelessPSData
  328. ASSERT (pWirelessPSData);
  329. VERIFY( m_lstActions.SetItemData(item.iItem, (DWORD_PTR)pNfaData) );
  330. }
  331. EnableDisableButtons ();
  332. }
  333. void CSecPolRulesPage::HandleSideEffectApply()
  334. {
  335. // make sure we are marked as modified
  336. SetModified();
  337. // The Add has been committed, canceling it is no longer possible.
  338. // Disable the cancel button
  339. CancelToClose();
  340. }
  341. int CSecPolRulesPage::DisplayPSProperties (
  342. //PWIRELESS_PS_DATA pBWirelessPSData,
  343. PSNP_PS_DATA pNfaData,
  344. CString strTitle,
  345. BOOL bDoingAdd,
  346. BOOL* pbAfterWizardHook
  347. )
  348. {
  349. HANDLE hPolicyStore = NULL;
  350. DWORD dwError = 0;
  351. GUID PolicyIdentifier;
  352. PWIRELESS_PS_DATA pBWirelessPSData = pNfaData->pWirelessPSData;
  353. CComObject<CSecPolItem>* pResultItem = NULL;
  354. PWIRELESS_POLICY_DATA pWirelessPolicy = NULL;
  355. int nReturn = 0;
  356. pResultItem = GetResultObject();
  357. hPolicyStore = pResultItem->m_pComponentDataImpl->GetPolicyStoreHandle();
  358. pWirelessPolicy = m_currentWirelessPolicyData;
  359. PolicyIdentifier = pWirelessPolicy->PolicyIdentifier;
  360. CSingleLock cLock(&m_csDlg);
  361. CComPtr<CPSPropSheetManager> spPropshtManager =
  362. new CComObject<CPSPropSheetManager>;
  363. if (NULL == spPropshtManager.p) {
  364. ReportError(IDS_OPERATION_FAIL, E_OUTOFMEMORY);
  365. return nReturn;
  366. }
  367. // load in the property pages
  368. CPS8021XPropPage pageAdapter;
  369. CSSIDPage pageSSID;
  370. //
  371. spPropshtManager->SetData(
  372. GetResultObject(),
  373. pBWirelessPSData,
  374. bDoingAdd
  375. );
  376. // theory is that if one fails, they all fail
  377. pageAdapter.Initialize(pBWirelessPSData, GetResultObject()->m_pComponentDataImpl, pWirelessPolicy->dwFlags);
  378. pageSSID.Initialize(pBWirelessPSData, GetResultObject()->m_pComponentDataImpl, pWirelessPolicy);
  379. spPropshtManager->AddPage (&pageSSID);
  380. spPropshtManager->AddPage (&pageAdapter);
  381. spPropshtManager->GetSheet()->SetTitle (strTitle, PSH_PROPTITLE);
  382. m_pPrpSh = spPropshtManager->GetSheet();
  383. m_pPrpSh->m_psh.dwFlags |= PSH_NOAPPLYNOW;
  384. // display the dialog
  385. nReturn = spPropshtManager->GetSheet()->DoModal();
  386. //nReturn = spPropshtManager->GetSheet()->Create();
  387. cLock.Lock();
  388. m_pPrpSh = NULL;
  389. cLock.Unlock();
  390. if (m_bReadOnly) {
  391. return nReturn;
  392. }
  393. if (spPropshtManager->HasEverApplied())
  394. {
  395. nReturn = IDOK;
  396. }
  397. return nReturn;
  398. }
  399. void CSecPolRulesPage::OnActionAdd()
  400. {
  401. // handle the add on a different thread and then continue
  402. // this is to fix NT bug #203059 per MFC KB article ID Q177101
  403. GetParent()->EnableWindow (FALSE);
  404. AfxBeginThread((AFX_THREADPROC)DoThreadActionAdd, this);
  405. }
  406. void CSecPolRulesPage::OnActionUp()
  407. {
  408. //Taroon: Todo Check this is needed or not and then remvoe
  409. //GetParent()->EnableWindow (FALSE);
  410. CComObject<CSecPolItem>* pResultItem = NULL;
  411. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  412. //lower means lower indexed
  413. PWIRELESS_PS_DATA pLowerWirelessPSData = NULL;
  414. PWIRELESS_PS_DATA pUpperWirelessPSData = NULL;
  415. // Only 1 item can be selected for move to be enabled
  416. ASSERT( m_lstActions.GetSelectedCount() == 1 );
  417. // ok, one of the PSs must be selected
  418. int nIndex = m_lstActions.GetNextItem(-1,LVNI_SELECTED);
  419. if (-1 == nIndex)
  420. return;
  421. PSNP_PS_DATA pUpperNfaData;
  422. pUpperNfaData = (PSNP_PS_DATA) m_lstActions.GetItemData(nIndex);
  423. pUpperWirelessPSData = pUpperNfaData->pWirelessPSData;
  424. pWirelessPolicyData = m_currentWirelessPolicyData;
  425. if (pWirelessPolicyData && pUpperWirelessPSData)
  426. {
  427. DWORD dwCurrentId;
  428. dwCurrentId = pUpperWirelessPSData->dwId;
  429. if (dwCurrentId != 0) {
  430. WirelessPSMoveUp(pWirelessPolicyData,dwCurrentId);
  431. // update the m_nfaList as well.
  432. PSNP_PS_DATA pLowerNfaData = NULL;
  433. pLowerNfaData = m_NfaList[dwCurrentId-1];
  434. pLowerWirelessPSData = pLowerNfaData->pWirelessPSData;
  435. pLowerWirelessPSData->dwId = dwCurrentId;
  436. pUpperWirelessPSData->dwId = dwCurrentId-1;
  437. m_NfaList[dwCurrentId-1] = pUpperNfaData;
  438. m_NfaList[dwCurrentId] = pLowerNfaData;
  439. PopulateListControl ();
  440. SetModified();
  441. m_lstActions.SetItemState( dwCurrentId-1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  442. }
  443. }
  444. }
  445. void CSecPolRulesPage::OnActionDown()
  446. {
  447. //Taroon: Todo Check this is needed or not and then remvoe
  448. //GetParent()->EnableWindow (FALSE);
  449. CComObject<CSecPolItem>* pResultItem = NULL;
  450. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  451. //lower means lower indexed
  452. PWIRELESS_PS_DATA pLowerWirelessPSData = NULL;
  453. PWIRELESS_PS_DATA pUpperWirelessPSData = NULL;
  454. DWORD dwTotalItems = 0;
  455. // Only 1 item can be selected for move to be enabled
  456. ASSERT( m_lstActions.GetSelectedCount() == 1 );
  457. // ok, one of the PSs must be selected
  458. int nIndex = m_lstActions.GetNextItem(-1,LVNI_SELECTED);
  459. if (-1 == nIndex)
  460. return;
  461. PSNP_PS_DATA pLowerNfaData;
  462. pLowerNfaData = (PSNP_PS_DATA) m_lstActions.GetItemData(nIndex);
  463. pLowerWirelessPSData = pLowerNfaData->pWirelessPSData;
  464. pWirelessPolicyData = m_currentWirelessPolicyData;
  465. dwTotalItems = pWirelessPolicyData->dwNumPreferredSettings;
  466. if (pWirelessPolicyData && pLowerWirelessPSData)
  467. {
  468. DWORD dwCurrentId;
  469. dwCurrentId = pLowerWirelessPSData->dwId;
  470. if (dwCurrentId < dwTotalItems -1) {
  471. WirelessPSMoveDown(pWirelessPolicyData,dwCurrentId);
  472. // update the m_nfaList as well.
  473. PSNP_PS_DATA pUpperNfaData = NULL;
  474. pUpperNfaData = m_NfaList[dwCurrentId + 1];
  475. pUpperWirelessPSData = pUpperNfaData->pWirelessPSData;
  476. pLowerWirelessPSData->dwId = dwCurrentId +1;
  477. pUpperWirelessPSData->dwId = dwCurrentId;
  478. m_NfaList[dwCurrentId+1] = pLowerNfaData;
  479. m_NfaList[dwCurrentId] = pUpperNfaData;
  480. PopulateListControl ();
  481. SetModified();
  482. m_lstActions.SetItemState( dwCurrentId+1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  483. }
  484. }
  485. }
  486. UINT AFX_CDECL CSecPolRulesPage::DoThreadActionAdd(LPVOID pParam)
  487. {
  488. CSecPolRulesPage* pObject = (CSecPolRulesPage*)pParam;
  489. if (pObject == NULL ||
  490. !pObject->IsKindOf(RUNTIME_CLASS(CSecPolRulesPage)))
  491. return -1; // illegal parameter
  492. DWORD dwDlgRuleThreadId = GetCurrentThreadId();
  493. AttachThreadInput(dwDlgRuleThreadId, pObject->m_MMCthreadID, TRUE);
  494. HRESULT hr = CoInitialize(NULL);
  495. if (FAILED(hr))
  496. return hr;
  497. // call back to the objects ActionAdd handler
  498. pObject->OnThreadSafeActionAdd();
  499. pObject->GetParent()->EnableWindow (TRUE);
  500. pObject->GetParent()->SetFocus ();
  501. CoUninitialize();
  502. AttachThreadInput(dwDlgRuleThreadId, pObject->m_MMCthreadID, FALSE);
  503. return 0;
  504. }
  505. void CSecPolRulesPage::OnThreadSafeActionAdd()
  506. {
  507. DWORD dwError = 0;
  508. BOOL bDisplayProperties = FALSE;
  509. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  510. PSNP_PS_DATA pNfaData = NULL;
  511. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  512. PWIRELESS_PS_DATA pNewWirelessPSData = NULL;
  513. pNfaData = (PSNP_PS_DATA) LocalAlloc(LMEM_ZEROINIT, sizeof(SNP_PS_DATA));
  514. if(pNfaData == NULL) {
  515. ReportError(IDS_OPERATION_FAIL, E_OUTOFMEMORY);
  516. return;
  517. }
  518. //
  519. // Create the WIRELESS_PS Object
  520. //
  521. //
  522. //
  523. pWirelessPSData = (PWIRELESS_PS_DATA) AllocPolMem(sizeof(WIRELESS_PS_DATA));
  524. if(pWirelessPSData == NULL) {
  525. ReportError(IDS_OPERATION_FAIL, E_OUTOFMEMORY);
  526. return;
  527. }
  528. pNfaData->status = NEW;
  529. pNfaData->pWirelessPSData = pWirelessPSData;
  530. CString pszNewSSID;
  531. CString pszSampleDescription;
  532. pszSampleDescription.LoadString(IDS_SAMPLE_DESCRIPTION);
  533. // Initialize the PWIRELESS_PS_DATA
  534. //
  535. //
  536. GenerateUniquePSName(IDS_NEW_PS_NAME,pszNewSSID);
  537. SSIDDupString(pWirelessPSData->pszWirelessSSID, pszNewSSID);
  538. pWirelessPSData->dwWirelessSSIDLen =
  539. lstrlenW(pWirelessPSData->pszWirelessSSID);
  540. pWirelessPSData->dwWepEnabled = 1;
  541. pWirelessPSData->dwNetworkAuthentication = 0;
  542. pWirelessPSData->dwAutomaticKeyProvision = 1;
  543. pWirelessPSData->dwNetworkType = WIRELESS_NETWORK_TYPE_AP;
  544. pWirelessPSData->dwEnable8021x = 1;
  545. pWirelessPSData->dw8021xMode =
  546. WIRELESS_8021X_MODE_NAS_TRANSMIT_EAPOLSTART_WIRED;
  547. pWirelessPSData->dwEapType = WIRELESS_EAP_TYPE_TLS;
  548. pWirelessPSData->dwEAPDataLen = 0;
  549. pWirelessPSData->pbEAPData = NULL;
  550. pWirelessPSData->dwMachineAuthentication = 1;
  551. pWirelessPSData->dwMachineAuthenticationType = WIRELESS_MC_AUTH_TYPE_USER_DONTCARE_MC;
  552. pWirelessPSData->dwGuestAuthentication = 0;
  553. pWirelessPSData->dwIEEE8021xMaxStart = 3;
  554. pWirelessPSData->dwIEEE8021xStartPeriod = 60;
  555. pWirelessPSData->dwIEEE8021xAuthPeriod = 30;
  556. pWirelessPSData->dwIEEE8021xHeldPeriod = 60;
  557. pWirelessPSData->dwId = -1;
  558. pWirelessPSData->pszDescription = AllocPolStr(pszSampleDescription);
  559. pWirelessPSData->dwDescriptionLen = 2*lstrlenW(pWirelessPSData->pszDescription);
  560. UpdateWirelessPSData(pWirelessPSData);
  561. CString szNewPreferredSetting;
  562. szNewPreferredSetting.LoadString(IDS_NEW_PREFERRED_SETTING);
  563. // display the dialog
  564. int dlgRetVal = DisplayPSProperties (
  565. pNfaData,
  566. szNewPreferredSetting,
  567. TRUE,
  568. &bDisplayProperties
  569. );
  570. // IDOK in case we didn't use the wizard for some reason
  571. if ((dlgRetVal == ID_WIZFINISH) || (dlgRetVal == IDOK))
  572. {
  573. // turn on the wait cursor
  574. CWaitCursor waitCursor;
  575. //user added new nfa rule, update the m_NfaList
  576. UpdateWirelessPSData(pWirelessPSData);
  577. pWirelessPolicyData = m_currentWirelessPolicyData;
  578. dwError = CopyWirelessPSData(pWirelessPSData,&pNewWirelessPSData);
  579. BAIL_ON_WIN32_ERROR(dwError);
  580. dwError = WirelessAddPSToPolicy(pWirelessPolicyData, pNewWirelessPSData);
  581. BAIL_ON_WIN32_ERROR(dwError);
  582. pWirelessPSData->dwId = pNewWirelessPSData->dwId;
  583. m_NfaList.push_back(pNfaData);
  584. DWORD dwSelection = -1;
  585. dwSelection = pWirelessPSData->dwId;
  586. InitialzeNfaList();
  587. PopulateListControl ();
  588. // Select the new item only
  589. SELECT_NO_LISTITEM( m_lstActions );
  590. m_lstActions.SetItemState( dwSelection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  591. //HandleSideEffectApply();
  592. SetModified();
  593. }
  594. else
  595. {
  596. if (pWirelessPSData) {
  597. FreeWirelessPSData(pWirelessPSData);
  598. }
  599. if (pNfaData) {
  600. LocalFree(pNfaData);
  601. }
  602. }
  603. return;
  604. error:
  605. ReportError(IDS_ADD_ERROR, HRESULT_FROM_WIN32(dwError));
  606. return;
  607. }
  608. void CSecPolRulesPage::OnActionEdit()
  609. {
  610. // handle the add on a different thread and then continue
  611. // this is to fix NT bug #203059 per MFC KB article ID Q177101
  612. GetParent()->EnableWindow (FALSE);
  613. AfxBeginThread((AFX_THREADPROC)DoThreadActionEdit, this);
  614. }
  615. UINT AFX_CDECL CSecPolRulesPage::DoThreadActionEdit(LPVOID pParam)
  616. {
  617. CSecPolRulesPage* pObject = (CSecPolRulesPage*)pParam;
  618. if (pObject == NULL ||
  619. !pObject->IsKindOf(RUNTIME_CLASS(CSecPolRulesPage)))
  620. return -1; // illegal parameter
  621. DWORD dwDlgRuleThreadId = GetCurrentThreadId();
  622. AttachThreadInput(dwDlgRuleThreadId, pObject->m_MMCthreadID, TRUE);
  623. HRESULT hr = CoInitialize(NULL);
  624. if (FAILED(hr))
  625. return hr;
  626. // call back to the objects ActionAdd handler
  627. pObject->OnThreadSafeActionEdit();
  628. pObject->GetParent()->EnableWindow (TRUE);
  629. pObject->GetParent()->SetFocus ();
  630. CoUninitialize();
  631. AttachThreadInput(dwDlgRuleThreadId, pObject->m_MMCthreadID, FALSE);
  632. return 0;
  633. }
  634. void CSecPolRulesPage::OnThreadSafeActionEdit()
  635. {
  636. // Only 1 item can be selected for Edit to be enabled
  637. ASSERT( m_lstActions.GetSelectedCount() == 1 );
  638. DWORD dwError = 0;
  639. // ok, one of the PSs must be selected
  640. int nIndex = m_lstActions.GetNextItem(-1,LVNI_SELECTED);
  641. if (-1 == nIndex)
  642. return;
  643. PSNP_PS_DATA pNfaData;
  644. PWIRELESS_PS_DATA pBWirelessPSData = NULL;
  645. pNfaData = (PSNP_PS_DATA) m_lstActions.GetItemData(nIndex);
  646. pBWirelessPSData = pNfaData->pWirelessPSData;
  647. // display the dialog
  648. if (pBWirelessPSData)
  649. {
  650. BOOL bHook = FALSE;
  651. DWORD dwError = 0;
  652. CString strTitle;
  653. strTitle.FormatMessage(IDS_EDIT_TITLE,pBWirelessPSData->pszWirelessSSID);
  654. if (DisplayPSProperties (pNfaData,strTitle, FALSE, &bHook) == IDOK)
  655. {
  656. if (!m_bReadOnly) {
  657. if( pNfaData->status != NEW )
  658. pNfaData->status = MODIFIED;
  659. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  660. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  661. DWORD dwCurrentId = 0;
  662. pWirelessPSData = pNfaData->pWirelessPSData;
  663. /* Taroon:RemoveRight
  664. pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  665. */
  666. pWirelessPolicyData = m_currentWirelessPolicyData;
  667. UpdateWirelessPSData(pWirelessPSData);
  668. dwError = WirelessSetPSDataInPolicyId(pWirelessPolicyData, pWirelessPSData);
  669. BAIL_ON_WIN32_ERROR(dwError);
  670. nIndex = pWirelessPSData->dwId;
  671. SetModified();
  672. InitialzeNfaList();
  673. }
  674. }
  675. // PopulateListControl can disable the edit button, save its handle so we
  676. // can reset the focus if this happens.
  677. HWND hWndCtrl = ::GetFocus();
  678. // always redraw the listbox, they might have managed filters or negpols even in a
  679. // 'cancel' situation and thus we need to accurately reflect the current state
  680. PopulateListControl ();
  681. // Select the edited item
  682. m_lstActions.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  683. if (::GetFocus() == NULL)
  684. ::SetFocus( hWndCtrl );
  685. }
  686. return;
  687. error:
  688. ReportError(IDS_SAVE_ERROR, HRESULT_FROM_WIN32(dwError));
  689. return;
  690. }
  691. void CSecPolRulesPage::OnActionRemove()
  692. {
  693. // Something must be selected to do a remove
  694. if (-1 == m_lstActions.GetNextItem(-1,LVNI_SELECTED))
  695. return;
  696. // verify that they really want to do this
  697. if (AfxMessageBox (IDS_SUREYESNO, MB_YESNO | MB_DEFBUTTON2) != IDYES)
  698. return;
  699. HANDLE hPolicyStore = NULL;
  700. DWORD dwError = 0;
  701. hPolicyStore = GetResultObject()->m_pComponentDataImpl->GetPolicyStoreHandle();
  702. ASSERT(hPolicyStore);
  703. // need to make sure that none of the selected items are the non-deleteable
  704. int nIndex = -1;
  705. DWORD nDeleteIndex = -1;
  706. DWORD dwNumRemoved = 0;
  707. while (-1 != (nIndex = m_lstActions.GetNextItem( nIndex, LVNI_SELECTED )))
  708. {
  709. PSNP_PS_DATA pNfaData;
  710. pNfaData = (PSNP_PS_DATA) m_lstActions.GetItemData(nIndex);
  711. PWIRELESS_PS_DATA pBWirelessPSData = pNfaData->pWirelessPSData;
  712. if (pBWirelessPSData)
  713. {
  714. if( pNfaData->status != NEW )
  715. pNfaData->status = BEREMOVED;
  716. else
  717. pNfaData->status = NEWREMOVED;
  718. nDeleteIndex = nIndex;
  719. }
  720. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  721. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  722. DWORD dwCurrentId = 0;
  723. //Remove the items right here from m_nfaList and Policy Object as well
  724. /* Taroon:RemoveRight
  725. pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  726. */
  727. pWirelessPolicyData = m_currentWirelessPolicyData;
  728. pWirelessPSData = pNfaData->pWirelessPSData;
  729. dwCurrentId = pWirelessPSData->dwId - dwNumRemoved;
  730. dwError = WirelessRemovePSFromPolicyId(pWirelessPolicyData,dwCurrentId);
  731. BAIL_ON_WIN32_ERROR(dwError);
  732. dwNumRemoved++;
  733. }
  734. SELECT_NO_LISTITEM( m_lstActions );
  735. InitialzeNfaList();
  736. // Save the currently focused control, PopulateListControl disables some
  737. // controls so we may have to reset the focus if this happens.
  738. CWnd *pwndFocus = GetFocus();
  739. PopulateListControl ();
  740. // Select previous item in list only
  741. SELECT_NO_LISTITEM( m_lstActions );
  742. int nPrevSel = SELECT_PREV_LISTITEM( m_lstActions, nDeleteIndex );
  743. // Fix up button focus
  744. EnableDisableButtons();
  745. SetPostRemoveFocus( nPrevSel, IDC_ACTION_PS_ADD, IDC_ACTION_PS_REMOVE, pwndFocus );
  746. // If the currently selected item is non-deleteable, the Remove button is
  747. // now disabled. Move the focus to the Add button for this case.
  748. if (!GetDlgItem( IDC_ACTION_PS_REMOVE)->IsWindowEnabled())
  749. {
  750. GotoDlgCtrl( GetDlgItem( IDC_ACTION_PS_ADD) );
  751. }
  752. SetModified();
  753. return;
  754. error:
  755. ReportError(IDS_REMOVINGERROR, HRESULT_FROM_WIN32(dwError));
  756. return;
  757. }
  758. void CSecPolRulesPage::OnDblclkActionslist(NMHDR* pNMHDR, LRESULT* pResult)
  759. {
  760. // ok, sounds like maybe they have clicked something in which case
  761. // we want to do an add
  762. switch (pNMHDR->code)
  763. {
  764. case NM_DBLCLK:
  765. {
  766. // we only want to do the edit if ONE item is selected
  767. if (m_lstActions.GetSelectedCount() == 1 )
  768. {
  769. OnActionEdit();
  770. }
  771. break;
  772. }
  773. default:
  774. break;
  775. }
  776. *pResult = 0;
  777. }
  778. void CSecPolRulesPage::EnableDisableButtons ()
  779. {
  780. if (m_bReadOnly)
  781. {
  782. DisableControls();
  783. return;
  784. }
  785. // ok, one of the rules must be selected for the E/R buttons to be enabled
  786. if (-1 != m_lstActions.GetNextItem(-1,LVNI_SELECTED))
  787. {
  788. // Disable Edit button if multiple selection
  789. int nSelectionCount = m_lstActions.GetSelectedCount();
  790. // Edit is easy
  791. SAFE_ENABLEWINDOW (IDC_ACTION_PS_EDIT, (1 == nSelectionCount));
  792. // Enable Remove only if it all selected pols are removable type
  793. SAFE_ENABLEWINDOW (IDC_ACTION_PS_REMOVE, PSsRemovable());
  794. if(nSelectionCount == 1 ) {
  795. SAFE_ENABLEWINDOW(IDC_PS_UP, TRUE);
  796. SAFE_ENABLEWINDOW(IDC_PS_DOWN, TRUE);
  797. // ok, one of the PSs must be selected
  798. int nIndex = m_lstActions.GetNextItem(-1,LVNI_SELECTED);
  799. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  800. DWORD dwAdhocStart = 0;
  801. DWORD dwNumPreferredSettings = 0;
  802. /* Taroon:RemoveRight
  803. pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  804. */
  805. pWirelessPolicyData = m_currentWirelessPolicyData;
  806. dwAdhocStart = pWirelessPolicyData->dwNumAPNetworks;
  807. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  808. if ((dwAdhocStart == nIndex) || (nIndex == 0)) {
  809. SAFE_ENABLEWINDOW(IDC_PS_UP, FALSE);
  810. }
  811. if ((dwAdhocStart == (nIndex + 1))||
  812. (nIndex == (dwNumPreferredSettings - 1)))
  813. {
  814. SAFE_ENABLEWINDOW(IDC_PS_DOWN, FALSE);
  815. }
  816. } else {
  817. SAFE_ENABLEWINDOW(IDC_PS_UP, FALSE);
  818. SAFE_ENABLEWINDOW(IDC_PS_DOWN, FALSE);
  819. }
  820. }
  821. else
  822. {
  823. // if nothing was selected this takes care of it
  824. SAFE_ENABLEWINDOW (IDC_ACTION_PS_EDIT, FALSE);
  825. SAFE_ENABLEWINDOW (IDC_ACTION_PS_REMOVE, FALSE);
  826. SAFE_ENABLEWINDOW(IDC_PS_UP, FALSE);
  827. SAFE_ENABLEWINDOW(IDC_PS_DOWN, FALSE);
  828. }
  829. }
  830. void CSecPolRulesPage::DisableControls ()
  831. {
  832. SAFE_ENABLEWINDOW (IDC_ACTION_PS_EDIT, FALSE);
  833. SAFE_ENABLEWINDOW (IDC_ACTION_PS_ADD, FALSE);
  834. SAFE_ENABLEWINDOW (IDC_ACTION_PS_REMOVE, FALSE);
  835. SAFE_ENABLEWINDOW(IDC_PS_UP, FALSE);
  836. SAFE_ENABLEWINDOW(IDC_PS_DOWN, FALSE);
  837. return;
  838. }
  839. BOOL CSecPolRulesPage::OnHelpInfo(HELPINFO* pHelpInfo)
  840. {
  841. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  842. {
  843. DWORD* pdwHelp = (DWORD*) &g_aHelpIDs_IDD_PS_LIST[0];
  844. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  845. c_szWlsnpHelpFile,
  846. HELP_WM_HELP,
  847. (DWORD_PTR)(LPVOID)pdwHelp);
  848. }
  849. return CSnapinPropPage::OnHelpInfo(pHelpInfo);
  850. }
  851. void CSecPolRulesPage::OnItemchangedActionslist(NMHDR* pNMHDR, LRESULT* pResult)
  852. {
  853. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  854. EnableDisableButtons ();
  855. *pResult = 0;
  856. }
  857. void CSecPolRulesPage::OnKeydownActionslist(NMHDR* pNMHDR, LRESULT* pResult)
  858. {
  859. // Something must be selected to do process the key opration
  860. if (-1 == m_lstActions.GetNextItem(-1,LVNI_SELECTED))
  861. return;
  862. LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
  863. if (VK_SPACE == pLVKeyDown->wVKey)
  864. {
  865. if (m_lstActions.GetSelectedCount() == 1)
  866. {
  867. int nItem;
  868. if (-1 != (nItem = m_lstActions.GetNextItem(-1, LVNI_SELECTED)))
  869. {
  870. PWIRELESS_PS_DATA pBWirelessPSData = NULL;
  871. PSNP_PS_DATA pNfaData;
  872. pNfaData = (PSNP_PS_DATA) m_lstActions.GetItemData(nItem);
  873. pBWirelessPSData = pNfaData->pWirelessPSData;
  874. ASSERT(pBWirelessPSData);
  875. // Redraw the list
  876. PopulateListControl ();
  877. // Reselect the toggled item
  878. DWORD dwSelection = -1;
  879. dwSelection = pBWirelessPSData->dwId;
  880. m_lstActions.SetItemState( dwSelection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  881. }
  882. }
  883. }
  884. else if (VK_DELETE == pLVKeyDown->wVKey)
  885. {
  886. if (!PSsRemovable())
  887. return;
  888. OnActionRemove();
  889. }
  890. *pResult = 0;
  891. }
  892. // Function: ToggleRuleActivation
  893. // Desc: Toggle the activation of the Security Policy Rule in the dlg's
  894. // list control.
  895. // Args:
  896. // nItemIndex: the 0-based index of the list item to be toggled
  897. HRESULT CSecPolRulesPage::ToggleRuleActivation( int nItemIndex )
  898. {
  899. HRESULT hr = S_OK;
  900. PSNP_PS_DATA pNfaData;
  901. pNfaData = (PSNP_PS_DATA) m_lstActions.GetItemData(nItemIndex);
  902. PWIRELESS_PS_DATA pBWirelessPSData = pNfaData->pWirelessPSData;
  903. SetModified();
  904. return hr;
  905. }
  906. void CSecPolRulesPage::OnDestroy()
  907. {
  908. // Note: We never receive a WM_CLOSE, so clean up here.
  909. SNP_PS_LIST::iterator theIterator;
  910. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  911. PSNP_PS_DATA pNfaData = NULL;
  912. FreeWirelessPolicyData(m_currentWirelessPolicyData);
  913. // Free objects associated with list.
  914. UnPopulateListControl();
  915. /* Taroon * found this leak from dh.. clearing Nfa List */
  916. //empty the previous List
  917. if (!m_NfaList.empty()) {
  918. for(theIterator = m_NfaList.begin();theIterator != m_NfaList.end(); ++theIterator) {
  919. pNfaData = (PSNP_PS_DATA)(*theIterator);
  920. pWirelessPSData = pNfaData->pWirelessPSData;
  921. FreeWirelessPSData(pWirelessPSData);
  922. LocalFree(pNfaData);
  923. }
  924. }
  925. m_NfaList.clear();
  926. CSnapinPropPage::OnDestroy();
  927. }
  928. BOOL CSecPolRulesPage::PSsRemovable()
  929. {
  930. if (m_lstActions.GetSelectedCount() == 0)
  931. return FALSE;
  932. BOOL bRemoveable = TRUE;
  933. int nIndex = -1;
  934. while (-1 != (nIndex = m_lstActions.GetNextItem( nIndex, LVNI_SELECTED )))
  935. {
  936. PSNP_PS_DATA pNfaData;
  937. pNfaData = (PSNP_PS_DATA) m_lstActions.GetItemData(nIndex);
  938. PWIRELESS_PS_DATA pBWirelessPSData = pNfaData->pWirelessPSData;
  939. if (NULL == pBWirelessPSData)
  940. continue;
  941. }
  942. return bRemoveable;
  943. }
  944. void CSecPolRulesPage::GenerateUniquePSName (UINT nID, CString& strName)
  945. {
  946. BOOL bUnique = TRUE;
  947. int iUTag = 0;
  948. CString strUName;
  949. DWORD dwError = 0;
  950. DWORD i = 0;
  951. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  952. PWIRELESS_PS_DATA *ppWirelessPSData = NULL;
  953. PWIRELESS_PS_DATA pWirelessPSData = NULL;
  954. DWORD dwNumPreferredSettings = 0;
  955. // if an nID was passed in then start with that
  956. if (nID != 0)
  957. {
  958. strName.LoadString (nID);
  959. }
  960. /* Taroon:RemoveRight
  961. pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  962. */
  963. pWirelessPolicyData = m_currentWirelessPolicyData;
  964. // zip through the ps and verify name is unique
  965. do
  966. {
  967. // only start tacking numbers on after the first pass
  968. if (iUTag > 0)
  969. {
  970. TCHAR buff[32];
  971. wsprintf (buff, _T(" (%d)"), iUTag);
  972. strUName = strName + buff;
  973. bUnique = TRUE;
  974. } else
  975. {
  976. strUName = strName;
  977. bUnique = TRUE;
  978. }
  979. ppWirelessPSData = pWirelessPolicyData->ppWirelessPSData;
  980. dwNumPreferredSettings = pWirelessPolicyData->dwNumPreferredSettings;
  981. for (i = 0; i < dwNumPreferredSettings ; i++) {
  982. pWirelessPSData = *(ppWirelessPSData + i);
  983. if (0 == strUName.CompareNoCase(pWirelessPSData->pszWirelessSSID)) {
  984. // set bUnique to FALSE
  985. bUnique = FALSE;
  986. iUTag++;
  987. }
  988. }
  989. }
  990. while (bUnique == FALSE);
  991. // done
  992. strName = strUName;
  993. }
  994. ////////////////////////////////////////////////////////////////////////////////////
  995. // CSecPolPropSheetManager
  996. BOOL CSecPolPropSheetManager::OnApply()
  997. {
  998. BOOL bRet = TRUE;
  999. //Query each page to apply
  1000. bRet = CMMCPropSheetManager::OnApply();
  1001. //if some page refuse to apply, dont do anything
  1002. if (!bRet)
  1003. return bRet;
  1004. ASSERT(m_pSecPolItem);
  1005. if (NULL == m_pSecPolItem)
  1006. return bRet;
  1007. DWORD dwError = 0;
  1008. dwError = WirelessSetPolicyData(
  1009. m_pSecPolItem->m_pComponentDataImpl->GetPolicyStoreHandle(),
  1010. m_pSecPolItem->GetWirelessPolicy()
  1011. );
  1012. if (ERROR_SUCCESS != dwError)
  1013. {
  1014. ReportError(IDS_SAVE_ERROR, HRESULT_FROM_WIN32(dwError));
  1015. }
  1016. GUID guidClientExt = CLSID_WIRELESSClientEx;
  1017. GUID guidSnapin = CLSID_Snapin;
  1018. m_pSecPolItem->m_pComponentDataImpl->UseGPEInformationInterface()->PolicyChanged (
  1019. TRUE,
  1020. TRUE,
  1021. &guidClientExt,
  1022. &guidSnapin
  1023. );
  1024. NotifyManagerApplied();
  1025. NotifyConsole();
  1026. return bRet;
  1027. }