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.

638 lines
16 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1998 - 1999
  4. Module Name: AddPolicyWizardPage3.cpp
  5. Abstract:
  6. Implementation file for the CNewRAPWiz_AllowDeny class.
  7. We implement the class needed to handle the first property page for a Policy node.
  8. Revision History:
  9. mmaguire 12/15/97 - created
  10. byao 1/22/98 Modified for Network Access Policy
  11. --*/
  12. //////////////////////////////////////////////////////////////////////////////
  13. #include "Precompiled.h"
  14. #include "rapwz_allow.h"
  15. #include "NapUtil.h"
  16. #include "PolicyNode.h"
  17. #include "PoliciesNode.h"
  18. #include "ChangeNotification.h"
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Function: CNewRAPWiz_AllowDeny
  22. //
  23. // Class: CNewRAPWiz_AllowDeny
  24. //
  25. // Synopsis: class constructor
  26. //
  27. // Arguments: CPolicyNode *pPolicyNode - policy node for this property page
  28. // CIASAttrList *pAttrList -- attribute list
  29. // TCHAR* pTitle = NULL -
  30. //
  31. // Returns: Nothing
  32. //
  33. // History: Created Header byao 2/16/98 4:31:52 PM
  34. //
  35. //+---------------------------------------------------------------------------
  36. CNewRAPWiz_AllowDeny::CNewRAPWiz_AllowDeny(
  37. CRapWizardData* pWizData,
  38. LONG_PTR hNotificationHandle,
  39. TCHAR* pTitle, BOOL bOwnsNotificationHandle
  40. )
  41. : CIASWizard97Page<CNewRAPWiz_AllowDeny, IDS_NEWRAPWIZ_ALLOWDENY_TITLE, IDS_NEWRAPWIZ_ALLOWDENY_SUBTITLE> ( hNotificationHandle, pTitle, bOwnsNotificationHandle ),
  42. m_spWizData(pWizData)
  43. {
  44. TRACE_FUNCTION("CNewRAPWiz_AllowDeny::CNewRAPWiz_AllowDeny");
  45. m_fDialinAllowed = TRUE;
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // Function: CNewRAPWiz_AllowDeny
  50. //
  51. // Class: CNewRAPWiz_AllowDeny
  52. //
  53. // Synopsis: class destructor
  54. //
  55. // Returns: Nothing
  56. //
  57. // History: Created Header byao 2/16/98 4:31:52 PM
  58. //
  59. //+---------------------------------------------------------------------------
  60. CNewRAPWiz_AllowDeny::~CNewRAPWiz_AllowDeny()
  61. {
  62. TRACE_FUNCTION("CNewRAPWiz_AllowDeny::~CNewRAPWiz_AllowDeny");
  63. }
  64. //////////////////////////////////////////////////////////////////////////////
  65. /*++
  66. CNewRAPWiz_AllowDeny::OnInitDialog
  67. --*/
  68. //////////////////////////////////////////////////////////////////////////////
  69. LRESULT CNewRAPWiz_AllowDeny::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  70. {
  71. TRACE_FUNCTION("CNewRAPWiz_AllowDeny::OnInitDialog");
  72. HRESULT hr = S_OK;
  73. BOOL fRet;
  74. CComPtr<IUnknown> spUnknown;
  75. CComPtr<IEnumVARIANT> spEnumVariant;
  76. long ulCount;
  77. ULONG ulCountReceived;
  78. hr = GetDialinSetting(m_fDialinAllowed);
  79. if ( FAILED(hr) )
  80. {
  81. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "GetDialinSetting() returns %x", hr);
  82. return FALSE;
  83. }
  84. if ( m_fDialinAllowed )
  85. {
  86. CheckDlgButton(IDC_RADIO_DENY_DIALIN, BST_UNCHECKED);
  87. CheckDlgButton(IDC_RADIO_GRANT_DIALIN, BST_CHECKED);
  88. }
  89. else
  90. {
  91. CheckDlgButton(IDC_RADIO_GRANT_DIALIN, BST_UNCHECKED);
  92. CheckDlgButton(IDC_RADIO_DENY_DIALIN, BST_CHECKED);
  93. }
  94. // Set the IDC_STATIC_GRANT_OR_DENY_TEXT static text box to be the appropriate text.
  95. /// TCHAR szText[NAP_MAX_STRING];
  96. /// int iLoadStringResult;
  97. ///
  98. /// UINT uTextID = m_fDialinAllowed ? IDS_POLICY_GRANT_ACCESS_INFO : IDS_POLICY_DENY_ACCESS_INFO;
  99. ///
  100. /// iLoadStringResult = LoadString( _Module.GetResourceInstance(), uTextID, szText, NAP_MAX_STRING );
  101. /// _ASSERT( iLoadStringResult > 0 );
  102. ///
  103. /// SetDlgItemText(IDC_STATIC_GRANT_OR_DENY_TEXT, szText );
  104. SetModified(FALSE);
  105. return TRUE; // ISSUE: what do we need to be returning here?
  106. }
  107. //////////////////////////////////////////////////////////////////////////////
  108. /*++
  109. CNewRAPWiz_AllowDeny::OnDialinCheck
  110. --*/
  111. //////////////////////////////////////////////////////////////////////////////
  112. LRESULT CNewRAPWiz_AllowDeny::OnDialinCheck(UINT uMsg, WPARAM wParam, HWND hWnd, BOOL& bHandled)
  113. {
  114. TRACE_FUNCTION("CNewRAPWiz_AllowDeny::OnDialinCheck");
  115. m_fDialinAllowed = IsDlgButtonChecked(IDC_RADIO_GRANT_DIALIN);
  116. SetModified(TRUE);
  117. // Set the IDC_STATIC_GRANT_OR_DENY_TEXT static text box to be the appropriate text.
  118. TCHAR szText[NAP_MAX_STRING];
  119. int iLoadStringResult;
  120. UINT uTextID = m_fDialinAllowed ? IDS_POLICY_GRANT_ACCESS_INFO : IDS_POLICY_DENY_ACCESS_INFO;
  121. iLoadStringResult = LoadString( _Module.GetResourceInstance(), uTextID, szText, NAP_MAX_STRING );
  122. _ASSERT( iLoadStringResult > 0 );
  123. SetDlgItemText(IDC_STATIC_GRANT_OR_DENY_TEXT, szText );
  124. return 0;
  125. }
  126. //////////////////////////////////////////////////////////////////////////////
  127. /*++
  128. CNewRAPWiz_AllowDeny::OnWizardNext
  129. --*/
  130. //////////////////////////////////////////////////////////////////////////////
  131. BOOL CNewRAPWiz_AllowDeny::OnWizardNext()
  132. {
  133. TRACE_FUNCTION("CNewRAPWiz_AllowDeny::OnWizardNext");
  134. WCHAR wzName[256];
  135. HRESULT hr = S_OK;
  136. int iIndex;
  137. // Set dialin-bit in profile.
  138. hr = SetDialinSetting(m_fDialinAllowed);
  139. if ( FAILED(hr) )
  140. {
  141. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "SetDialinSettings() failed, err = %x", hr);
  142. ShowErrorDialog( m_hWnd, IDS_ERROR_SDO_ERROR_SETDIALIN, NULL, hr);
  143. goto failure;
  144. }
  145. // reset the dirty bit
  146. SetModified(FALSE);
  147. return m_spWizData->GetNextPageId(((PROPSHEETPAGE*)(*this))->pszTemplate);
  148. failure:
  149. //
  150. // we can't do anything more than just close the property page
  151. //
  152. return FALSE;
  153. }
  154. //////////////////////////////////////////////////////////////////////////////
  155. /*++
  156. CNewRAPWiz_AllowDeny::OnQueryCancel
  157. --*/
  158. //////////////////////////////////////////////////////////////////////////////
  159. BOOL CNewRAPWiz_AllowDeny::OnQueryCancel()
  160. {
  161. TRACE_FUNCTION("CNewRAPWiz_AllowDeny::OnQueryCancel");
  162. return TRUE;
  163. }
  164. //+---------------------------------------------------------------------------
  165. //
  166. // Function: CNewRAPWiz_AllowDeny::GetDialinSetting
  167. //
  168. // Synopsis: Check whether the user is allowed to dial in. This function will
  169. // set the dialin bit
  170. //
  171. // Argument: BOOL& fDialinAllowed;
  172. //
  173. // Returns: succeed or not
  174. //
  175. // History: Created Header byao 2/27/98 3:59:38 PM
  176. //
  177. //+---------------------------------------------------------------------------
  178. HRESULT CNewRAPWiz_AllowDeny::GetDialinSetting(BOOL& fDialinAllowed)
  179. {
  180. TRACE_FUNCTION("CNewRAPWiz_AllowDeny::GetDialinSetting");
  181. long ulCount;
  182. ULONG ulCountReceived;
  183. HRESULT hr = S_OK;
  184. CComBSTR bstr;
  185. CComPtr<IUnknown> spUnknown;
  186. CComPtr<IEnumVARIANT> spEnumVariant;
  187. CComVariant var;
  188. // by default, dialin is allowed
  189. fDialinAllowed = FALSE;
  190. //
  191. // get the attribute collection of this profile
  192. //
  193. CComPtr<ISdoCollection> spProfAttrCollectionSdo;
  194. hr = ::GetSdoInterfaceProperty(m_spWizData->m_spProfileSdo,
  195. (LONG)PROPERTY_PROFILE_ATTRIBUTES_COLLECTION,
  196. IID_ISdoCollection,
  197. (void **) &spProfAttrCollectionSdo
  198. );
  199. if ( FAILED(hr) )
  200. {
  201. return hr;
  202. }
  203. _ASSERTE(spProfAttrCollectionSdo);
  204. // We check the count of items in our collection and don't bother getting the
  205. // enumerator if the count is zero.
  206. // This saves time and also helps us to a void a bug in the the enumerator which
  207. // causes it to fail if we call next when it is empty.
  208. hr = spProfAttrCollectionSdo->get_Count( & ulCount );
  209. DebugTrace(DEBUG_NAPMMC_POLICYPAGE1, "Number of prof attributes: %d", ulCount);
  210. if ( FAILED(hr) )
  211. {
  212. ShowErrorDialog(m_hWnd,
  213. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  214. NULL,
  215. hr);
  216. return hr;
  217. }
  218. if ( ulCount > 0)
  219. {
  220. // Get the enumerator for the attribute collection.
  221. hr = spProfAttrCollectionSdo->get__NewEnum( (IUnknown **) & spUnknown );
  222. if ( FAILED(hr) )
  223. {
  224. ShowErrorDialog(m_hWnd,
  225. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  226. NULL,
  227. hr);
  228. return hr;
  229. }
  230. hr = spUnknown->QueryInterface( IID_IEnumVARIANT, (void **) &spEnumVariant );
  231. spUnknown.Release();
  232. if ( FAILED(hr) )
  233. {
  234. ShowErrorDialog(m_hWnd,
  235. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  236. NULL,
  237. hr);
  238. return hr;
  239. }
  240. _ASSERTE( spEnumVariant != NULL );
  241. // Get the first item.
  242. hr = spEnumVariant->Next( 1, &var, &ulCountReceived );
  243. while( SUCCEEDED( hr ) && ulCountReceived == 1 )
  244. {
  245. // Get an sdo pointer from the variant we received.
  246. _ASSERTE( V_VT(&var) == VT_DISPATCH );
  247. _ASSERTE( V_DISPATCH(&var) != NULL );
  248. CComPtr<ISdo> spSdo;
  249. hr = V_DISPATCH(&var)->QueryInterface( IID_ISdo, (void **) &spSdo );
  250. if ( !SUCCEEDED(hr))
  251. {
  252. ShowErrorDialog(m_hWnd,
  253. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  254. NULL
  255. );
  256. return hr;
  257. }
  258. //
  259. // get attribute ID
  260. //
  261. var.Clear();
  262. hr = spSdo->GetProperty(PROPERTY_ATTRIBUTE_ID, &var);
  263. if ( !SUCCEEDED(hr) )
  264. {
  265. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_GETATTRINFO, NULL, hr);
  266. return hr;
  267. }
  268. _ASSERTE( V_VT(&var) == VT_I4 );
  269. DWORD dwAttrId = V_I4(&var);
  270. if ( dwAttrId == (DWORD)IAS_ATTRIBUTE_ALLOW_DIALIN)
  271. {
  272. // found this one in the profile, check for its value
  273. var.Clear();
  274. hr = spSdo->GetProperty(PROPERTY_ATTRIBUTE_VALUE, &var);
  275. if ( !SUCCEEDED(hr) )
  276. {
  277. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_GETATTRINFO, NULL, hr);
  278. return hr;
  279. }
  280. _ASSERTE( V_VT(&var)== VT_BOOL);
  281. fDialinAllowed = ( V_BOOL(&var)==VARIANT_TRUE);
  282. return S_OK;
  283. }
  284. // Clear the variant of whatever it had --
  285. // this will release any data associated with it.
  286. var.Clear();
  287. // Get the next item.
  288. hr = spEnumVariant->Next( 1, &var, &ulCountReceived );
  289. if ( !SUCCEEDED(hr))
  290. {
  291. ShowErrorDialog(m_hWnd,
  292. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  293. NULL,
  294. hr
  295. );
  296. return hr;
  297. }
  298. } // while
  299. } // if
  300. return hr;
  301. }
  302. //+---------------------------------------------------------------------------
  303. //
  304. // Function: CNewRAPWiz_AllowDeny::SetDialinSetting
  305. //
  306. // Synopsis: set the dialin bit into the profile
  307. //
  308. // Argument: BOOL& fDialinAllowed;
  309. //
  310. // Returns: succeed or not
  311. //
  312. // History: Created Header byao 2/27/98 3:59:38 PM
  313. //
  314. //+---------------------------------------------------------------------------
  315. HRESULT CNewRAPWiz_AllowDeny::SetDialinSetting(BOOL fDialinAllowed)
  316. {
  317. TRACE_FUNCTION("CNewRAPWiz_AllowDeny::SetDialinSetting");
  318. long ulCount;
  319. ULONG ulCountReceived;
  320. HRESULT hr = S_OK;
  321. CComBSTR bstr;
  322. CComPtr<IUnknown> spUnknown;
  323. CComPtr<IEnumVARIANT> spEnumVariant;
  324. CComVariant var;
  325. //
  326. // get the attribute collection of this profile
  327. //
  328. CComPtr<ISdoCollection> spProfAttrCollectionSdo;
  329. hr = ::GetSdoInterfaceProperty(m_spWizData->m_spProfileSdo,
  330. (LONG)PROPERTY_PROFILE_ATTRIBUTES_COLLECTION,
  331. IID_ISdoCollection,
  332. (void **) &spProfAttrCollectionSdo
  333. );
  334. if ( FAILED(hr) )
  335. {
  336. return hr;
  337. }
  338. _ASSERTE(spProfAttrCollectionSdo);
  339. // We check the count of items in our collection and don't bother getting the
  340. // enumerator if the count is zero.
  341. // This saves time and also helps us to a void a bug in the the enumerator which
  342. // causes it to fail if we call next when it is empty.
  343. hr = spProfAttrCollectionSdo->get_Count( & ulCount );
  344. if ( FAILED(hr) )
  345. {
  346. ShowErrorDialog(m_hWnd,
  347. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  348. NULL,
  349. hr);
  350. return hr;
  351. }
  352. if ( ulCount > 0)
  353. {
  354. // Get the enumerator for the attribute collection.
  355. hr = spProfAttrCollectionSdo->get__NewEnum( (IUnknown **) & spUnknown );
  356. if ( FAILED(hr) )
  357. {
  358. ShowErrorDialog(m_hWnd,
  359. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  360. NULL,
  361. hr);
  362. return hr;
  363. }
  364. hr = spUnknown->QueryInterface( IID_IEnumVARIANT, (void **) &spEnumVariant );
  365. spUnknown.Release();
  366. if ( FAILED(hr) )
  367. {
  368. ShowErrorDialog(m_hWnd,
  369. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  370. NULL,
  371. hr
  372. );
  373. return hr;
  374. }
  375. _ASSERTE( spEnumVariant != NULL );
  376. // Get the first item.
  377. hr = spEnumVariant->Next( 1, &var, &ulCountReceived );
  378. while( SUCCEEDED( hr ) && ulCountReceived == 1 )
  379. {
  380. // Get an sdo pointer from the variant we received.
  381. _ASSERTE( V_VT(&var) == VT_DISPATCH );
  382. _ASSERTE( V_DISPATCH(&var) != NULL );
  383. CComPtr<ISdo> spSdo;
  384. hr = V_DISPATCH(&var)->QueryInterface( IID_ISdo, (void **) &spSdo );
  385. if ( !SUCCEEDED(hr))
  386. {
  387. ShowErrorDialog(m_hWnd,
  388. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  389. NULL
  390. );
  391. return hr;
  392. }
  393. //
  394. // get attribute ID
  395. //
  396. var.Clear();
  397. hr = spSdo->GetProperty(PROPERTY_ATTRIBUTE_ID, &var);
  398. if ( !SUCCEEDED(hr) )
  399. {
  400. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_GETATTRINFO, NULL, hr);
  401. return hr;
  402. }
  403. _ASSERTE( V_VT(&var) == VT_I4 );
  404. DWORD dwAttrId = V_I4(&var);
  405. if ( dwAttrId == (DWORD)IAS_ATTRIBUTE_ALLOW_DIALIN )
  406. {
  407. // found this one in the profile, check for its value
  408. var.Clear();
  409. V_VT(&var) = VT_BOOL;
  410. V_BOOL(&var) = fDialinAllowed ? VARIANT_TRUE: VARIANT_FALSE ;
  411. hr = spSdo->PutProperty(PROPERTY_ATTRIBUTE_VALUE, &var);
  412. if ( !SUCCEEDED(hr) )
  413. {
  414. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_SETDIALIN, NULL, hr);
  415. return hr;
  416. }
  417. return S_OK;
  418. }
  419. // Clear the variant of whatever it had --
  420. // this will release any data associated with it.
  421. var.Clear();
  422. // Get the next item.
  423. hr = spEnumVariant->Next( 1, &var, &ulCountReceived );
  424. if ( !SUCCEEDED(hr))
  425. {
  426. ShowErrorDialog(m_hWnd,
  427. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  428. NULL,
  429. hr);
  430. return hr;
  431. }
  432. } // while
  433. } // if
  434. // if we reach here, it means we either haven't found the attribute,
  435. // or the profile doesn't have anything in its attribute collection.
  436. if ( !fDialinAllowed )
  437. {
  438. // we don't need to do anything if dialin is allowed, becuase if this
  439. // attribute is not in the profile, then dialin is by default allowed
  440. // but we need to add this attribute to the profile if it's DENIED
  441. // create the SDO for this attribute
  442. CComPtr<IDispatch> spDispatch;
  443. hr = m_spWizData->m_spDictionarySdo->CreateAttribute( (ATTRIBUTEID)IAS_ATTRIBUTE_ALLOW_DIALIN,
  444. (IDispatch**)&spDispatch.p);
  445. if ( !SUCCEEDED(hr) )
  446. {
  447. ShowErrorDialog(m_hWnd,
  448. IDS_ERROR_SDO_ERROR_SETDIALIN,
  449. NULL,
  450. hr
  451. );
  452. return hr;
  453. }
  454. _ASSERTE( spDispatch.p != NULL );
  455. // add this node to profile attribute collection
  456. hr = spProfAttrCollectionSdo->Add(NULL, (IDispatch**)&spDispatch.p);
  457. if ( !SUCCEEDED(hr) )
  458. {
  459. ShowErrorDialog(m_hWnd,
  460. IDS_ERROR_SDO_ERROR_SETDIALIN,
  461. NULL,
  462. hr
  463. );
  464. return hr;
  465. }
  466. //
  467. // get the ISdo pointer
  468. //
  469. CComPtr<ISdo> spAttrSdo;
  470. hr = spDispatch->QueryInterface( IID_ISdo, (void **) &spAttrSdo);
  471. if ( !SUCCEEDED(hr) )
  472. {
  473. ShowErrorDialog(m_hWnd,
  474. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  475. NULL,
  476. hr
  477. );
  478. return hr;
  479. }
  480. _ASSERTE( spAttrSdo != NULL );
  481. // set sdo property for this attribute
  482. CComVariant var;
  483. // set value
  484. V_VT(&var) = VT_BOOL;
  485. V_BOOL(&var) = VARIANT_FALSE;
  486. hr = spAttrSdo->PutProperty(PROPERTY_ATTRIBUTE_VALUE, &var);
  487. if ( !SUCCEEDED(hr) )
  488. {
  489. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_SETDIALIN, NULL, hr );
  490. return hr;
  491. }
  492. var.Clear();
  493. } // if (!dialinallowed)
  494. return hr;
  495. }
  496. //////////////////////////////////////////////////////////////////////////////
  497. /*++
  498. CNewRAPWiz_AllowDeny::OnSetActive
  499. Return values:
  500. TRUE if the page can be made active
  501. FALSE if the page should be be skipped and the next page should be looked at.
  502. Remarks:
  503. If you want to change which pages are visited based on a user's
  504. choices in a previous page, return FALSE here as appropriate.
  505. --*/
  506. //////////////////////////////////////////////////////////////////////////////
  507. BOOL CNewRAPWiz_AllowDeny::OnSetActive()
  508. {
  509. ATLTRACE(_T("# CNewRAPWiz_AllowDeny::OnSetActive\n"));
  510. // MSDN docs say you need to use PostMessage here rather than SendMessage.
  511. ::PropSheet_SetWizButtons(GetParent(), PSWIZB_BACK | PSWIZB_NEXT );
  512. return TRUE;
  513. }