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.

1325 lines
38 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation
  4. Module Name: PolicyPage1.cpp
  5. Abstract:
  6. Implementation file for the CPolicyPage1 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 "PolicyPage1.h"
  15. #include "NapUtil.h"
  16. #include "PolicyNode.h"
  17. #include "PoliciesNode.h"
  18. #include "Condition.h"
  19. #include "EnumCondition.h"
  20. #include "MatchCondition.h"
  21. #include "TodCondition.h"
  22. #include "NtGCond.h"
  23. #include "rasprof.h"
  24. #include "ChangeNotification.h"
  25. #include "policiesnode.h"
  26. #include "tregkey.h"
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Function: CPolicyPage1
  30. //
  31. // Class: CPolicyPage1
  32. //
  33. // Synopsis: class constructor
  34. //
  35. // Arguments: CPolicyNode *pPolicyNode - policy node for this property page
  36. // CIASAttrList *pAttrList -- attribute list
  37. // TCHAR* pTitle = NULL -
  38. //
  39. // Returns: Nothing
  40. //
  41. // History: Created Header byao 2/16/98 4:31:52 PM
  42. //
  43. //+---------------------------------------------------------------------------
  44. CPolicyPage1::CPolicyPage1(
  45. LONG_PTR hNotificationHandle,
  46. CPolicyNode *pPolicyNode,
  47. CIASAttrList *pIASAttrList,
  48. TCHAR* pTitle,
  49. BOOL bOwnsNotificationHandle,
  50. bool isWin2k
  51. )
  52. :CIASPropertyPage<CPolicyPage1>(hNotificationHandle,
  53. pTitle,
  54. bOwnsNotificationHandle),
  55. m_isWin2k(isWin2k)
  56. {
  57. TRACE_FUNCTION("CPolicyPage1::CPolicyPage1");
  58. m_pPolicyNode = pPolicyNode;
  59. m_pIASAttrList = pIASAttrList;
  60. // Add the help button to the page
  61. // m_psp.dwFlags |= PSP_HASHELP;
  62. m_fDialinAllowed = TRUE;
  63. }
  64. //+---------------------------------------------------------------------------
  65. //
  66. // Function: CPolicyPage1
  67. //
  68. // Class: CPolicyPage1
  69. //
  70. // Synopsis: class destructor
  71. //
  72. // Returns: Nothing
  73. //
  74. // History: Created Header byao 2/16/98 4:31:52 PM
  75. //
  76. //+---------------------------------------------------------------------------
  77. CPolicyPage1::~CPolicyPage1()
  78. {
  79. TRACE_FUNCTION("CPolicyPage1::~CPolicyPage1");
  80. // release all the marshalled sdo pointers
  81. if ( m_pStreamDictionarySdoMarshall )
  82. {
  83. m_pStreamDictionarySdoMarshall->Release();
  84. m_pStreamDictionarySdoMarshall = NULL;
  85. }
  86. if ( m_pStreamPoliciesCollectionSdoMarshall)
  87. {
  88. m_pStreamPoliciesCollectionSdoMarshall ->Release();
  89. m_pStreamPoliciesCollectionSdoMarshall = NULL;
  90. }
  91. if ( m_pStreamProfilesCollectionSdoMarshall )
  92. {
  93. m_pStreamProfilesCollectionSdoMarshall ->Release();
  94. m_pStreamProfilesCollectionSdoMarshall = NULL;
  95. }
  96. if ( m_pStreamProfileSdoMarshall )
  97. {
  98. m_pStreamProfileSdoMarshall ->Release();
  99. m_pStreamProfileSdoMarshall = NULL;
  100. }
  101. if ( m_pStreamPolicySdoMarshall )
  102. {
  103. m_pStreamPolicySdoMarshall->Release();
  104. m_pStreamPolicySdoMarshall = NULL;
  105. }
  106. if ( m_pStreamSdoServiceControlMarshall )
  107. {
  108. m_pStreamSdoServiceControlMarshall ->Release();
  109. m_pStreamSdoServiceControlMarshall = NULL;
  110. }
  111. // clear the property page pointer in the policy node
  112. m_pPolicyNode->m_pPolicyPage1 = NULL;
  113. }
  114. //////////////////////////////////////////////////////////////////////////////
  115. /*++
  116. CPolicyPage1::OnInitDialog
  117. --*/
  118. //////////////////////////////////////////////////////////////////////////////
  119. LRESULT CPolicyPage1::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  120. {
  121. TRACE_FUNCTION("CPolicyPage1::OnInitDialog");
  122. HRESULT hr = S_OK;
  123. BOOL fRet;
  124. CComPtr<IUnknown> spUnknown;
  125. CComPtr<IEnumVARIANT> spEnumVariant;
  126. long ulCount;
  127. ULONG ulCountReceived;
  128. fRet = GetSdoPointers();
  129. if (!fRet)
  130. {
  131. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "GetSdoPointers() failed, err = %x", GetLastError());
  132. return fRet;
  133. }
  134. //get the condition collection for this SDO
  135. m_spConditionCollectionSdo = NULL;
  136. hr = ::GetSdoInterfaceProperty(
  137. m_spPolicySdo,
  138. PROPERTY_POLICY_CONDITIONS_COLLECTION,
  139. IID_ISdoCollection,
  140. (void **)&m_spConditionCollectionSdo);
  141. if ( FAILED(hr) )
  142. {
  143. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "Can't get condition collection Sdo, err = %x", hr);
  144. return FALSE;
  145. }
  146. condList.finalConstruct(
  147. m_hWnd,
  148. m_pIASAttrList,
  149. ALLOWEDINCONDITION,
  150. m_spDictionarySdo,
  151. m_spConditionCollectionSdo,
  152. m_pPolicyNode->m_pszServerAddress,
  153. m_pPolicyNode->m_bstrDisplayName
  154. );
  155. if (!condList.onInitDialog()) { return FALSE; }
  156. hr = GetDialinSetting(m_fDialinAllowed);
  157. if ( FAILED(hr) )
  158. {
  159. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "GetDialinSetting() returns %x", hr);
  160. return FALSE;
  161. }
  162. if ( m_fDialinAllowed )
  163. {
  164. CheckDlgButton(IDC_RADIO_DENY_DIALIN, BST_UNCHECKED);
  165. CheckDlgButton(IDC_RADIO_GRANT_DIALIN, BST_CHECKED);
  166. }
  167. else
  168. {
  169. CheckDlgButton(IDC_RADIO_GRANT_DIALIN, BST_UNCHECKED);
  170. CheckDlgButton(IDC_RADIO_DENY_DIALIN, BST_CHECKED);
  171. }
  172. // Set the IDC_STATIC_GRANT_OR_DENY_TEXT static text box to be the appropriate text.
  173. TCHAR szText[NAP_MAX_STRING];
  174. int iLoadStringResult;
  175. UINT uTextID = m_fDialinAllowed ? IDS_POLICY_GRANT_ACCESS_INFO : IDS_POLICY_DENY_ACCESS_INFO;
  176. iLoadStringResult = LoadString( _Module.GetResourceInstance(), uTextID, szText, NAP_MAX_STRING );
  177. _ASSERT( iLoadStringResult > 0 );
  178. SetDlgItemText(IDC_STATIC_GRANT_OR_DENY_TEXT, szText );
  179. SetModified(FALSE);
  180. return TRUE; // ISSUE: what do we need to be returning here?
  181. }
  182. //////////////////////////////////////////////////////////////////////////////
  183. /*++
  184. CPolicyPage1::OnConditionAdd
  185. --*/
  186. //////////////////////////////////////////////////////////////////////////////
  187. LRESULT CPolicyPage1::OnConditionAdd(UINT uMsg, WPARAM wParam, HWND hWnd, BOOL& bHandled)
  188. {
  189. BOOL modified = FALSE;
  190. HRESULT hr = condList.onAdd(modified);
  191. if (modified) { SetModified(TRUE); }
  192. return hr;
  193. }
  194. //////////////////////////////////////////////////////////////////////////////
  195. /*++
  196. CPolicyPage1::OnDialinCheck
  197. --*/
  198. //////////////////////////////////////////////////////////////////////////////
  199. LRESULT CPolicyPage1::OnDialinCheck(UINT uMsg, WPARAM wParam, HWND hWnd, BOOL& bHandled)
  200. {
  201. TRACE_FUNCTION("CPolicyPage1::OnDialinCheck");
  202. m_fDialinAllowed = IsDlgButtonChecked(IDC_RADIO_GRANT_DIALIN);
  203. SetModified(TRUE);
  204. // Set the IDC_STATIC_GRANT_OR_DENY_TEXT static text box to be the appropriate text.
  205. TCHAR szText[NAP_MAX_STRING];
  206. int iLoadStringResult;
  207. UINT uTextID = m_fDialinAllowed ? IDS_POLICY_GRANT_ACCESS_INFO : IDS_POLICY_DENY_ACCESS_INFO;
  208. iLoadStringResult = LoadString( _Module.GetResourceInstance(), uTextID, szText, NAP_MAX_STRING );
  209. _ASSERT( iLoadStringResult > 0 );
  210. SetDlgItemText(IDC_STATIC_GRANT_OR_DENY_TEXT, szText );
  211. return 0;
  212. }
  213. //////////////////////////////////////////////////////////////////////////////
  214. // SetRegistryFootPrint
  215. //////////////////////////////////////////////////////////////////////////////
  216. HRESULT SetRegistryFootPrint(LPCTSTR servername)
  217. {
  218. {
  219. RegKey RemoteAccessParames;
  220. LONG lRes = RemoteAccessParames.Create(
  221. RAS_REG_ROOT,
  222. REGKEY_REMOTEACCESS_PARAMS,
  223. REG_OPTION_NON_VOLATILE,
  224. KEY_WRITE,
  225. NULL,
  226. servername);
  227. if (lRes != ERROR_SUCCESS)
  228. return HRESULT_FROM_WIN32(lRes);
  229. //================================================
  230. // save the values to the key
  231. DWORD regValue = REGVAL_VAL_USERSCONFIGUREDWITHMMC;
  232. lRes = RemoteAccessParames.SetValue(REGVAL_NAME_USERSCONFIGUREDWITHMMC, regValue);
  233. }
  234. return S_OK;
  235. }
  236. //////////////////////////////////////////////////////////////////////////////
  237. /*++
  238. CPolicyPage1::OnApply
  239. --*/
  240. //////////////////////////////////////////////////////////////////////////////
  241. BOOL CPolicyPage1::OnApply()
  242. {
  243. TRACE_FUNCTION("CPolicyPage1::OnApply");
  244. WCHAR wzName[IAS_MAX_STRING];
  245. HRESULT hr = S_OK;
  246. int iIndex;
  247. CPoliciesNode* pPoliciesNode = (CPoliciesNode*)m_pPolicyNode->m_pParentNode;
  248. GetSdoPointers();
  249. if (!condList.onApply()) { return FALSE; }
  250. try
  251. {
  252. //
  253. // now we save the policy properties
  254. //
  255. CComVariant var;
  256. // policy merit value
  257. V_VT(&var) = VT_I4;
  258. V_I4(&var) = m_pPolicyNode->GetMerit();
  259. hr = m_spPolicySdo->PutProperty(PROPERTY_POLICY_MERIT, &var);
  260. if( FAILED(hr) )
  261. {
  262. ErrorTrace(DEBUG_NAPMMC_POLICYPAGE1, "Failed to save Merit Value to the policy, err = %x", hr);
  263. ShowErrorDialog( m_hWnd
  264. , IDS_ERROR_SDO_ERROR_PUTPROP_POLICYMERIT
  265. , NULL
  266. , hr
  267. );
  268. throw hr;
  269. }
  270. var.Clear();
  271. // Commit the changes to the policy.
  272. hr = m_spPolicySdo->Apply();
  273. if( FAILED( hr ) )
  274. {
  275. // can't commit on Policy
  276. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "PolicySdo->Apply() failed, err = %x", hr);
  277. if(hr == DB_E_NOTABLE) // assume, the RPC connection has problem
  278. {
  279. ShowErrorDialog( m_hWnd, IDS_ERROR__NOTABLE_TO_WRITE_SDO );
  280. }
  281. else
  282. {
  283. ShowErrorDialog( m_hWnd, IDS_ERROR_SDO_ERROR_POLICY_APPLY, NULL, hr );
  284. }
  285. throw hr;
  286. }
  287. V_VT(&var) = VT_BSTR;
  288. V_BSTR(&var) = SysAllocString(wzName);
  289. // Set dialin-bit in profile
  290. hr = SetDialinSetting(m_fDialinAllowed);
  291. if ( FAILED(hr) )
  292. {
  293. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "SetDialinSettings() failed, err = %x", hr);
  294. ShowErrorDialog( m_hWnd, IDS_ERROR_SDO_ERROR_SETDIALIN, NULL, hr);
  295. throw hr;
  296. }
  297. // Commit changes to the profile.
  298. hr = m_spProfileSdo->Apply();
  299. if( FAILED( hr ) )
  300. {
  301. // can't commit on Profiles
  302. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "ProfileSdo->Apply() failed, err = %x", hr);
  303. if(hr == DB_E_NOTABLE) // assume, the RPC connection has problem
  304. ShowErrorDialog( m_hWnd, IDS_ERROR__NOTABLE_TO_WRITE_SDO );
  305. else
  306. ShowErrorDialog( m_hWnd, IDS_ERROR_SDO_ERROR_PROFILE_APPLY, NULL, hr );
  307. throw hr;
  308. }
  309. // Tell the service to reload data.
  310. HRESULT hrTemp = m_spSdoServiceControl->ResetService();
  311. if( FAILED( hrTemp ) )
  312. {
  313. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "ISdoServiceControl::ResetService() failed, err = %x", hrTemp);
  314. }
  315. SetRegistryFootPrint((LPCTSTR)m_pPolicyNode->m_pszServerAddress);
  316. // reset the dirty bit
  317. SetModified(FALSE);
  318. //
  319. // notify the main component
  320. // it seems we don't need to do this when the node is brand new!
  321. //
  322. // The data was accepted, so notify the main context of our snapin
  323. // that it may need to update its views.
  324. CChangeNotification * pChangeNotification = new CChangeNotification();
  325. pChangeNotification->m_dwFlags = CHANGE_UPDATE_RESULT_NODE;
  326. pChangeNotification->m_pNode = m_pPolicyNode;
  327. hr = PropertyChangeNotify( (LPARAM) pChangeNotification );
  328. _ASSERTE( SUCCEEDED( hr ) );
  329. }
  330. catch(...)
  331. {
  332. // Can't save policy or profile.
  333. return FALSE;
  334. }
  335. return TRUE;
  336. }
  337. //////////////////////////////////////////////////////////////////////////////
  338. /*++
  339. CPolicyPage1::OnQueryCancel
  340. --*/
  341. //////////////////////////////////////////////////////////////////////////////
  342. BOOL CPolicyPage1::OnQueryCancel()
  343. {
  344. return CIASPropertyPage<CPolicyPage1>::OnQueryCancel();
  345. }
  346. // move code from OnQueryCancel to OnCancel to avoid error 0x8001010d when user is being log off
  347. BOOL CPolicyPage1::OnCancel()
  348. {
  349. TRACE_FUNCTION("CPolicyPage1::OnQueryCancel");
  350. HRESULT hr = S_OK;
  351. hr = m_spPolicySdo->Restore();
  352. if ( FAILED(hr) )
  353. {
  354. if(hr != 0x8001010d)
  355. ShowErrorDialog(m_hWnd, IDS_ERROR_CANT_RESTORE_POLICY, NULL, hr);
  356. else
  357. ShowErrorDialog(m_hWnd, IDS_ERROR_CANT_RESTORE_POLICY, NULL);
  358. }
  359. hr = m_spProfileSdo->Restore();
  360. if ( FAILED(hr) )
  361. {
  362. if(hr != 0x8001010d)
  363. ShowErrorDialog(m_hWnd, IDS_ERROR_CANT_RESTORE_PROFILE, NULL, hr);
  364. else
  365. ShowErrorDialog(m_hWnd, IDS_ERROR_CANT_RESTORE_PROFILE, NULL);
  366. }
  367. return TRUE;
  368. }
  369. //+---------------------------------------------------------------------------
  370. //
  371. // Function: OnConditionList
  372. //
  373. // Class: CConditionPage1
  374. //
  375. // Synopsis: message handler for the condition list box
  376. //
  377. // Arguments: UINT uNotifyCode - notification code
  378. // UINT uID - ID of the control
  379. // HWND hWnd - HANDLE of the window
  380. // BOOL &bHandled - whether the handler has processed the msg
  381. //
  382. // Returns: LRESULT - S_OK: succeeded
  383. // S_FALSE: otherwise
  384. //
  385. // History: Created byao 2/2/98 4:51:35 PM
  386. //
  387. //+---------------------------------------------------------------------------
  388. LRESULT CPolicyPage1::OnConditionList(UINT uNotifyCode, UINT uID, HWND hWnd, BOOL &bHandled)
  389. {
  390. TRACE_FUNCTION("CPolicyPage1::OnConditionList");
  391. if (uNotifyCode == LBN_DBLCLK)
  392. {
  393. // edit the condition
  394. OnConditionEdit(uNotifyCode, uID, hWnd, bHandled);
  395. }
  396. return S_OK;
  397. }
  398. //+---------------------------------------------------------------------------
  399. //
  400. // Function: OnConditionEdit
  401. //
  402. // Class: CConditionPage1
  403. //
  404. // Synopsis: message handler for the condition list box -- user pressed the Edit button
  405. // we need to edit a particular condition
  406. //
  407. // Arguments: UINT uNotifyCode - notification code
  408. // UINT uID - ID of the control
  409. // HWND hWnd - HANDLE of the window
  410. // BOOL &bHandled - whether the handler has processed the msg
  411. //
  412. // Returns: LRESULT - S_OK: succeeded
  413. // S_FALSE: otherwise
  414. //
  415. // History: Created byao 2/21/98 4:51:35 PM
  416. //
  417. //+---------------------------------------------------------------------------
  418. LRESULT CPolicyPage1::OnConditionEdit(UINT uNotifyCode, UINT uID, HWND hWnd, BOOL &bHandled)
  419. {
  420. TRACE_FUNCTION("CPolicyPage1::OnConditionEdit");
  421. BOOL modified = FALSE;
  422. HRESULT hr = condList.onEdit(modified, bHandled);
  423. if (modified) { SetModified(TRUE); }
  424. return hr;
  425. }
  426. //+---------------------------------------------------------------------------
  427. //
  428. // Function: OnConditionRemove
  429. //
  430. // Class: CConditionPage1
  431. //
  432. // Synopsis: message handler for the condition list box -- user pressed "Remove"
  433. // we need to remove this condition
  434. //
  435. // Arguments: UINT uNotifyCode - notification code
  436. // UINT uID - ID of the control
  437. // HWND hWnd - HANDLE of the window
  438. // BOOL &bHandled - whether the handler has processed the msg
  439. //
  440. // Returns: LRESULT - S_OK: succeeded
  441. // S_FALSE: otherwise
  442. //
  443. // History: Created byao 2/22/98 4:51:35 PM
  444. //
  445. //+---------------------------------------------------------------------------
  446. LRESULT CPolicyPage1::OnConditionRemove(UINT uMsg, WPARAM wParam, HWND hWnd, BOOL& bHandled)
  447. {
  448. TRACE_FUNCTION("CPolicyPage1::OnConditionRemove");
  449. BOOL modified = FALSE;
  450. HRESULT hr = condList.onRemove(modified, bHandled);
  451. if (modified) { SetModified(TRUE); }
  452. return hr;
  453. }
  454. //+---------------------------------------------------------------------------
  455. //
  456. // Function: CPolicyPage1::GetSdoPointers
  457. //
  458. // Synopsis: UnMarshall all passed in sdo pointers. These interface pointers
  459. // have to be unmarshalled first, because MMC PropertyPages run in a
  460. // separated thread
  461. //
  462. // Also get the condition collection sdo from the policy sdo
  463. //
  464. // Arguments: None
  465. //
  466. // Returns: TRUE; succeeded
  467. // FALSE: otherwise
  468. //
  469. // History: Created Header byao 2/22/98 1:35:39 AM
  470. //
  471. //+---------------------------------------------------------------------------
  472. BOOL CPolicyPage1::GetSdoPointers()
  473. {
  474. TRACE_FUNCTION("CPolicyPage1::GetSdoPointers");
  475. HRESULT hr;
  476. // Unmarshall the dictionary SDO pointer.
  477. if ( m_pStreamDictionarySdoMarshall)
  478. {
  479. if ( m_spDictionarySdo )
  480. {
  481. m_spDictionarySdo.Release();
  482. m_spDictionarySdo = NULL;
  483. }
  484. hr = CoGetInterfaceAndReleaseStream(
  485. m_pStreamDictionarySdoMarshall
  486. , IID_ISdoDictionaryOld
  487. , (LPVOID *) &m_spDictionarySdo
  488. );
  489. // CoGetInterfaceAndReleaseStream releases this pointer even if it fails.
  490. // We set it to NULL so that our destructor doesn't try to release this again.
  491. m_pStreamDictionarySdoMarshall = NULL;
  492. if( FAILED(hr) || m_spDictionarySdo == NULL )
  493. {
  494. ShowErrorDialog(m_hWnd,
  495. IDS_ERROR_UNMARSHALL,
  496. NULL,
  497. hr
  498. );
  499. return FALSE;
  500. }
  501. }
  502. // Unmarshall the profile SDO interface pointers.
  503. if ( m_pStreamProfileSdoMarshall)
  504. {
  505. if ( m_spProfileSdo )
  506. {
  507. m_spProfileSdo.Release();
  508. m_spProfileSdo = NULL;
  509. }
  510. hr = CoGetInterfaceAndReleaseStream(
  511. m_pStreamProfileSdoMarshall
  512. , IID_ISdo
  513. , (LPVOID *) &m_spProfileSdo
  514. );
  515. // CoGetInterfaceAndReleaseStream releases this pointer even if it fails.
  516. // We set it to NULL so that our destructor doesn't try to release this again.
  517. m_pStreamProfileSdoMarshall = NULL;
  518. if( FAILED( hr) || m_spProfileSdo == NULL )
  519. {
  520. ShowErrorDialog(m_hWnd,
  521. IDS_ERROR_UNMARSHALL,
  522. NULL,
  523. hr
  524. );
  525. return FALSE;
  526. }
  527. }
  528. // Unmarshall the policy SDO interface pointers.
  529. if ( m_pStreamPolicySdoMarshall)
  530. {
  531. m_spPolicySdo.Release();
  532. m_spPolicySdo = NULL;
  533. hr = CoGetInterfaceAndReleaseStream(
  534. m_pStreamPolicySdoMarshall
  535. , IID_ISdo
  536. , (LPVOID *) &m_spPolicySdo
  537. );
  538. // CoGetInterfaceAndReleaseStream releases this pointer even if it fails.
  539. // We set it to NULL so that our destructor doesn't try to release this again.
  540. m_pStreamPolicySdoMarshall = NULL;
  541. if( FAILED( hr) || m_spPolicySdo == NULL )
  542. {
  543. ShowErrorDialog(m_hWnd,
  544. IDS_ERROR_UNMARSHALL,
  545. NULL,
  546. hr
  547. );
  548. return FALSE;
  549. }
  550. }
  551. // Unmarshall the profile collection SDO interface pointers.
  552. if ( m_pStreamProfilesCollectionSdoMarshall )
  553. {
  554. if ( m_spProfilesCollectionSdo )
  555. {
  556. m_spProfilesCollectionSdo.Release();
  557. m_spProfilesCollectionSdo = NULL;
  558. }
  559. hr = CoGetInterfaceAndReleaseStream(
  560. m_pStreamProfilesCollectionSdoMarshall
  561. , IID_ISdoCollection
  562. , (LPVOID *) &m_spProfilesCollectionSdo
  563. );
  564. // CoGetInterfaceAndReleaseStream releases this pointer even if it fails.
  565. // We set it to NULL so that our destructor doesn't try to release this again.
  566. m_pStreamProfilesCollectionSdoMarshall = NULL;
  567. if( FAILED( hr) || m_spProfilesCollectionSdo == NULL )
  568. {
  569. ShowErrorDialog(m_hWnd,
  570. IDS_ERROR_UNMARSHALL,
  571. NULL,
  572. hr
  573. );
  574. return FALSE;
  575. }
  576. }
  577. // Unmarshall the policy collection SDO interface pointers.
  578. if ( m_pStreamPoliciesCollectionSdoMarshall )
  579. {
  580. if ( m_spPoliciesCollectionSdo )
  581. {
  582. m_spPoliciesCollectionSdo.Release();
  583. m_spPoliciesCollectionSdo = NULL;
  584. }
  585. hr = CoGetInterfaceAndReleaseStream(
  586. m_pStreamPoliciesCollectionSdoMarshall
  587. , IID_ISdoCollection
  588. , (LPVOID *) &m_spPoliciesCollectionSdo
  589. );
  590. // CoGetInterfaceAndReleaseStream releases this pointer even if it fails.
  591. // We set it to NULL so that our destructor doesn't try to release this again.
  592. m_pStreamPoliciesCollectionSdoMarshall = NULL;
  593. if( FAILED( hr) || m_spPoliciesCollectionSdo == NULL )
  594. {
  595. ShowErrorDialog(m_hWnd,
  596. IDS_ERROR_UNMARSHALL,
  597. NULL,
  598. hr
  599. );
  600. return FALSE;
  601. }
  602. }
  603. // Unmarshall the policy collection SDO interface pointers.
  604. if ( m_pStreamSdoServiceControlMarshall )
  605. {
  606. if ( m_spSdoServiceControl )
  607. {
  608. m_spSdoServiceControl.Release();
  609. m_spSdoServiceControl = NULL;
  610. }
  611. hr = CoGetInterfaceAndReleaseStream(
  612. m_pStreamSdoServiceControlMarshall
  613. , IID_ISdoServiceControl
  614. , (LPVOID *) &m_spSdoServiceControl
  615. );
  616. // CoGetInterfaceAndReleaseStream releases this pointer even if it fails.
  617. // We set it to NULL so that our destructor doesn't try to release this again.
  618. m_pStreamSdoServiceControlMarshall = NULL;
  619. if( FAILED( hr) || ! m_spSdoServiceControl )
  620. {
  621. ShowErrorDialog(m_hWnd,
  622. IDS_ERROR_UNMARSHALL,
  623. NULL,
  624. hr
  625. );
  626. return FALSE;
  627. }
  628. }
  629. //
  630. // get the condition collection of this sdo
  631. //
  632. if ( m_spPolicySdo )
  633. {
  634. if ( m_spConditionCollectionSdo )
  635. {
  636. m_spConditionCollectionSdo.Release();
  637. m_spConditionCollectionSdo = NULL;
  638. }
  639. hr = ::GetSdoInterfaceProperty(
  640. m_spPolicySdo,
  641. PROPERTY_POLICY_CONDITIONS_COLLECTION,
  642. IID_ISdoCollection,
  643. (void **) &m_spConditionCollectionSdo);
  644. if( FAILED( hr) || m_spConditionCollectionSdo == NULL )
  645. {
  646. ShowErrorDialog(m_hWnd,
  647. IDS_ERROR_UNMARSHALL,
  648. NULL,
  649. hr
  650. );
  651. return FALSE;
  652. }
  653. }
  654. return TRUE;
  655. }
  656. //////////////////////////////////////////////////////////////////////////////
  657. /*++
  658. CPolicyPage1::OnEditProfile
  659. --*/
  660. //////////////////////////////////////////////////////////////////////////////
  661. //////////
  662. // Signature of the entry point to the profile editing DLL.
  663. //////////
  664. typedef HRESULT (APIENTRY *OPENRAS_IASPROFILEDLG)(
  665. LPCWSTR pszMachineName,
  666. ISdo* pProfile, // profile SDO pointer
  667. ISdoDictionaryOld* pDictionary, // dictionary SDO pointer
  668. BOOL bReadOnly, // if the dlg is for readonly
  669. DWORD dwTabFlags, // what to show
  670. void *pvData // additional data
  671. );
  672. LRESULT CPolicyPage1::OnEditProfile(UINT uMsg, WPARAM wParam, HWND hwnd, BOOL& bHandled)
  673. {
  674. TRACE_FUNCTION("CPolicyPage1::OnEditProfile");
  675. OPENRAS_IASPROFILEDLG pfnProfileEditor = NULL;
  676. HRESULT hr = S_OK;
  677. HMODULE hProfileDll = NULL;
  678. hProfileDll = LoadLibrary(_T("rasuser.dll"));
  679. if ( NULL == hProfileDll )
  680. {
  681. hr = HRESULT_FROM_WIN32(GetLastError());
  682. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "LoadLibrary() failed, err = %x", hr);
  683. ShowErrorDialog(m_hWnd, IDS_ERROR_CANT_FIND_PROFILEDLL, NULL, hr);
  684. return 0;
  685. }
  686. pfnProfileEditor = (OPENRAS_IASPROFILEDLG) GetProcAddress(hProfileDll, "OpenRAS_IASProfileDlg");
  687. if ( NULL == pfnProfileEditor )
  688. {
  689. hr = HRESULT_FROM_WIN32(GetLastError());
  690. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "GetProcAddress() failed, err = %x", hr);
  691. ShowErrorDialog(m_hWnd, IDS_ERROR_CANT_FIND_PROFILEAPI, NULL, hr);
  692. FreeLibrary(hProfileDll);
  693. return 0;
  694. }
  695. // findout if this is extending RRAS or IAS
  696. CPoliciesNode* pPoliciesNode = dynamic_cast<CPoliciesNode*>(m_pPolicyNode->m_pParentNode);
  697. DWORD dwFlags = RAS_IAS_PROFILEDLG_SHOW_IASTABS;
  698. if(pPoliciesNode != NULL)
  699. {
  700. if(!pPoliciesNode->m_fExtendingIAS)
  701. dwFlags = RAS_IAS_PROFILEDLG_SHOW_RASTABS;
  702. }
  703. if(m_isWin2k)
  704. {
  705. dwFlags |= RAS_IAS_PROFILEDLG_SHOW_WIN2K;
  706. }
  707. //
  708. // now we do have this profile sdo, call the API
  709. //
  710. hr = pfnProfileEditor(
  711. m_pPolicyNode->m_pszServerAddress,
  712. m_spProfileSdo,
  713. m_spDictionarySdo,
  714. FALSE,
  715. dwFlags,
  716. (void *)&(m_pIASAttrList->m_AttrList)
  717. );
  718. FreeLibrary(hProfileDll);
  719. DebugTrace(DEBUG_NAPMMC_POLICYPAGE1, "OpenRAS_IASProfileDlg() returned %x", hr);
  720. if ( FAILED(hr) )
  721. {
  722. return hr;
  723. }
  724. return hr;
  725. }
  726. //+---------------------------------------------------------------------------
  727. //
  728. // Function: CPolicyPage1::GetDialinSetting
  729. //
  730. // Synopsis: Check whether the user is allowed to dial in. This function will
  731. // set the dialin bit
  732. //
  733. // Argument: BOOL& fDialinAllowed;
  734. //
  735. // Returns: succeed or not
  736. //
  737. // History: Created Header byao 2/27/98 3:59:38 PM
  738. //
  739. //+---------------------------------------------------------------------------
  740. HRESULT CPolicyPage1::GetDialinSetting(BOOL& fDialinAllowed)
  741. {
  742. TRACE_FUNCTION("CPolicyPage1::GetDialinSetting");
  743. long ulCount;
  744. ULONG ulCountReceived;
  745. HRESULT hr = S_OK;
  746. CComBSTR bstr;
  747. CComPtr<IUnknown> spUnknown;
  748. CComPtr<IEnumVARIANT> spEnumVariant;
  749. CComVariant var;
  750. // by default, dialin is allowed
  751. fDialinAllowed = TRUE;
  752. //
  753. // get the attribute collection of this profile
  754. //
  755. CComPtr<ISdoCollection> spProfAttrCollectionSdo;
  756. hr = ::GetSdoInterfaceProperty(m_spProfileSdo,
  757. (LONG)PROPERTY_PROFILE_ATTRIBUTES_COLLECTION,
  758. IID_ISdoCollection,
  759. (void **) &spProfAttrCollectionSdo
  760. );
  761. if ( FAILED(hr) )
  762. {
  763. return hr;
  764. }
  765. _ASSERTE(spProfAttrCollectionSdo);
  766. // We check the count of items in our collection and don't bother getting the
  767. // enumerator if the count is zero.
  768. // This saves time and also helps us to a void a bug in the the enumerator which
  769. // causes it to fail if we call next when it is empty.
  770. hr = spProfAttrCollectionSdo->get_Count( & ulCount );
  771. DebugTrace(DEBUG_NAPMMC_POLICYPAGE1, "Number of prof attributes: %d", ulCount);
  772. if ( FAILED(hr) )
  773. {
  774. ShowErrorDialog(m_hWnd,
  775. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  776. NULL,
  777. hr);
  778. return hr;
  779. }
  780. if ( ulCount > 0)
  781. {
  782. // Get the enumerator for the attribute collection.
  783. hr = spProfAttrCollectionSdo->get__NewEnum( (IUnknown **) & spUnknown );
  784. if ( FAILED(hr) )
  785. {
  786. ShowErrorDialog(m_hWnd,
  787. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  788. NULL,
  789. hr);
  790. return hr;
  791. }
  792. hr = spUnknown->QueryInterface( IID_IEnumVARIANT, (void **) &spEnumVariant );
  793. spUnknown.Release();
  794. if ( FAILED(hr) )
  795. {
  796. ShowErrorDialog(m_hWnd,
  797. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  798. NULL,
  799. hr);
  800. return hr;
  801. }
  802. _ASSERTE( spEnumVariant != NULL );
  803. // Get the first item.
  804. hr = spEnumVariant->Next( 1, &var, &ulCountReceived );
  805. while( SUCCEEDED( hr ) && ulCountReceived == 1 )
  806. {
  807. // Get an sdo pointer from the variant we received.
  808. _ASSERTE( V_VT(&var) == VT_DISPATCH );
  809. _ASSERTE( V_DISPATCH(&var) != NULL );
  810. CComPtr<ISdo> spSdo;
  811. hr = V_DISPATCH(&var)->QueryInterface( IID_ISdo, (void **) &spSdo );
  812. if ( !SUCCEEDED(hr))
  813. {
  814. ShowErrorDialog(m_hWnd,
  815. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  816. NULL
  817. );
  818. return hr;
  819. }
  820. //
  821. // get attribute ID
  822. //
  823. var.Clear();
  824. hr = spSdo->GetProperty(PROPERTY_ATTRIBUTE_ID, &var);
  825. if ( !SUCCEEDED(hr) )
  826. {
  827. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_GETATTRINFO, NULL, hr);
  828. return hr;
  829. }
  830. _ASSERTE( V_VT(&var) == VT_I4 );
  831. DWORD dwAttrId = V_I4(&var);
  832. if ( dwAttrId == (DWORD)IAS_ATTRIBUTE_ALLOW_DIALIN)
  833. {
  834. // found this one in the profile, check for its value
  835. var.Clear();
  836. hr = spSdo->GetProperty(PROPERTY_ATTRIBUTE_VALUE, &var);
  837. if ( !SUCCEEDED(hr) )
  838. {
  839. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_GETATTRINFO, NULL, hr);
  840. return hr;
  841. }
  842. _ASSERTE( V_VT(&var)== VT_BOOL);
  843. fDialinAllowed = ( V_BOOL(&var)==VARIANT_TRUE);
  844. return S_OK;
  845. }
  846. // Clear the variant of whatever it had --
  847. // this will release any data associated with it.
  848. var.Clear();
  849. // Get the next item.
  850. hr = spEnumVariant->Next( 1, &var, &ulCountReceived );
  851. if ( !SUCCEEDED(hr))
  852. {
  853. ShowErrorDialog(m_hWnd,
  854. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  855. NULL,
  856. hr
  857. );
  858. return hr;
  859. }
  860. } // while
  861. } // if
  862. return hr;
  863. }
  864. //+---------------------------------------------------------------------------
  865. //
  866. // Function: CPolicyPage1::SetDialinSetting
  867. //
  868. // Synopsis: set the dialin bit into the profile
  869. //
  870. // Argument: BOOL& fDialinAllowed;
  871. //
  872. // Returns: succeed or not
  873. //
  874. // History: Created Header byao 2/27/98 3:59:38 PM
  875. //
  876. //+---------------------------------------------------------------------------
  877. HRESULT CPolicyPage1::SetDialinSetting(BOOL fDialinAllowed)
  878. {
  879. TRACE_FUNCTION("CPolicyPage1::SetDialinSetting");
  880. long ulCount;
  881. ULONG ulCountReceived;
  882. HRESULT hr = S_OK;
  883. CComBSTR bstr;
  884. CComPtr<IUnknown> spUnknown;
  885. CComPtr<IEnumVARIANT> spEnumVariant;
  886. CComVariant var;
  887. //
  888. // get the attribute collection of this profile
  889. //
  890. CComPtr<ISdoCollection> spProfAttrCollectionSdo;
  891. hr = ::GetSdoInterfaceProperty(m_spProfileSdo,
  892. (LONG)PROPERTY_PROFILE_ATTRIBUTES_COLLECTION,
  893. IID_ISdoCollection,
  894. (void **) &spProfAttrCollectionSdo
  895. );
  896. if ( FAILED(hr) )
  897. {
  898. return hr;
  899. }
  900. _ASSERTE(spProfAttrCollectionSdo);
  901. // We check the count of items in our collection and don't bother getting the
  902. // enumerator if the count is zero.
  903. // This saves time and also helps us to a void a bug in the the enumerator which
  904. // causes it to fail if we call next when it is empty.
  905. hr = spProfAttrCollectionSdo->get_Count( & ulCount );
  906. if ( FAILED(hr) )
  907. {
  908. ShowErrorDialog(m_hWnd,
  909. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  910. NULL,
  911. hr);
  912. return hr;
  913. }
  914. if ( ulCount > 0)
  915. {
  916. // Get the enumerator for the attribute collection.
  917. hr = spProfAttrCollectionSdo->get__NewEnum( (IUnknown **) & spUnknown );
  918. if ( FAILED(hr) )
  919. {
  920. ShowErrorDialog(m_hWnd,
  921. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  922. NULL,
  923. hr);
  924. return hr;
  925. }
  926. hr = spUnknown->QueryInterface( IID_IEnumVARIANT, (void **) &spEnumVariant );
  927. spUnknown.Release();
  928. if ( FAILED(hr) )
  929. {
  930. ShowErrorDialog(m_hWnd,
  931. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  932. NULL,
  933. hr
  934. );
  935. return hr;
  936. }
  937. _ASSERTE( spEnumVariant != NULL );
  938. // Get the first item.
  939. hr = spEnumVariant->Next( 1, &var, &ulCountReceived );
  940. while( SUCCEEDED( hr ) && ulCountReceived == 1 )
  941. {
  942. // Get an sdo pointer from the variant we received.
  943. _ASSERTE( V_VT(&var) == VT_DISPATCH );
  944. _ASSERTE( V_DISPATCH(&var) != NULL );
  945. CComPtr<ISdo> spSdo;
  946. hr = V_DISPATCH(&var)->QueryInterface( IID_ISdo, (void **) &spSdo );
  947. if ( !SUCCEEDED(hr))
  948. {
  949. ShowErrorDialog(m_hWnd,
  950. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  951. NULL
  952. );
  953. return hr;
  954. }
  955. //
  956. // get attribute ID
  957. //
  958. var.Clear();
  959. hr = spSdo->GetProperty(PROPERTY_ATTRIBUTE_ID, &var);
  960. if ( !SUCCEEDED(hr) )
  961. {
  962. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_GETATTRINFO, NULL, hr);
  963. return hr;
  964. }
  965. _ASSERTE( V_VT(&var) == VT_I4 );
  966. DWORD dwAttrId = V_I4(&var);
  967. if ( dwAttrId == (DWORD)IAS_ATTRIBUTE_ALLOW_DIALIN )
  968. {
  969. // found this one in the profile, check for its value
  970. var.Clear();
  971. V_VT(&var) = VT_BOOL;
  972. V_BOOL(&var) = fDialinAllowed ? VARIANT_TRUE: VARIANT_FALSE ;
  973. hr = spSdo->PutProperty(PROPERTY_ATTRIBUTE_VALUE, &var);
  974. if ( !SUCCEEDED(hr) )
  975. {
  976. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_SETDIALIN, NULL, hr);
  977. return hr;
  978. }
  979. return S_OK;
  980. }
  981. // Clear the variant of whatever it had --
  982. // this will release any data associated with it.
  983. var.Clear();
  984. // Get the next item.
  985. hr = spEnumVariant->Next( 1, &var, &ulCountReceived );
  986. if ( !SUCCEEDED(hr))
  987. {
  988. ShowErrorDialog(m_hWnd,
  989. IDS_ERROR_SDO_ERROR_PROFATTRCOLLECTION,
  990. NULL,
  991. hr);
  992. return hr;
  993. }
  994. } // while
  995. } // if
  996. // if we reach here, it means we either haven't found the attribute,
  997. // or the profile doesn't have anything in its attribute collection.
  998. if ( !fDialinAllowed )
  999. {
  1000. // we don't need to do anything if dialin is allowed, becuase if this
  1001. // attribute is not in the profile, then dialin is by default allowed
  1002. // but we need to add this attribute to the profile if it's DENIED
  1003. // create the SDO for this attribute
  1004. CComPtr<IDispatch> spDispatch;
  1005. hr = m_spDictionarySdo->CreateAttribute( (ATTRIBUTEID)IAS_ATTRIBUTE_ALLOW_DIALIN,
  1006. (IDispatch**)&spDispatch.p);
  1007. if ( !SUCCEEDED(hr) )
  1008. {
  1009. ShowErrorDialog(m_hWnd,
  1010. IDS_ERROR_SDO_ERROR_SETDIALIN,
  1011. NULL,
  1012. hr
  1013. );
  1014. return hr;
  1015. }
  1016. _ASSERTE( spDispatch.p != NULL );
  1017. // add this node to profile attribute collection
  1018. hr = spProfAttrCollectionSdo->Add(NULL, (IDispatch**)&spDispatch.p);
  1019. if ( !SUCCEEDED(hr) )
  1020. {
  1021. ShowErrorDialog(m_hWnd,
  1022. IDS_ERROR_SDO_ERROR_SETDIALIN,
  1023. NULL,
  1024. hr
  1025. );
  1026. return hr;
  1027. }
  1028. //
  1029. // get the ISdo pointer
  1030. //
  1031. CComPtr<ISdo> spAttrSdo;
  1032. hr = spDispatch->QueryInterface( IID_ISdo, (void **) &spAttrSdo);
  1033. if ( !SUCCEEDED(hr) )
  1034. {
  1035. ShowErrorDialog(m_hWnd,
  1036. IDS_ERROR_SDO_ERROR_QUERYINTERFACE,
  1037. NULL,
  1038. hr
  1039. );
  1040. return hr;
  1041. }
  1042. _ASSERTE( spAttrSdo != NULL );
  1043. // set sdo property for this attribute
  1044. CComVariant var;
  1045. // set value
  1046. V_VT(&var) = VT_BOOL;
  1047. V_BOOL(&var) = VARIANT_FALSE;
  1048. hr = spAttrSdo->PutProperty(PROPERTY_ATTRIBUTE_VALUE, &var);
  1049. if ( !SUCCEEDED(hr) )
  1050. {
  1051. ShowErrorDialog(m_hWnd, IDS_ERROR_SDO_ERROR_SETDIALIN, NULL, hr );
  1052. return hr;
  1053. }
  1054. var.Clear();
  1055. } // if (!dialinallowed)
  1056. return hr;
  1057. }
  1058. //+---------------------------------------------------------------------------
  1059. //
  1060. // Function: CPolicyPage1::ValidPolicyName
  1061. //
  1062. // Synopsis: Check whether this is a valid policy name
  1063. //
  1064. // Arguments: LPCTSTR pszName - policy name
  1065. //
  1066. // Returns: BOOL - TRUE: valid name
  1067. //
  1068. // History: Created Header byao 3/14/98 1:47:05 AM
  1069. //
  1070. //+---------------------------------------------------------------------------
  1071. BOOL CPolicyPage1::ValidPolicyName(LPCTSTR pszName)
  1072. {
  1073. TRACE_FUNCTION("CPolicyPage1::ValidPolicyName");
  1074. int iIndex;
  1075. int iLen;
  1076. // is this an empty string?
  1077. iLen = wcslen(pszName);
  1078. if ( !iLen )
  1079. {
  1080. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "Empty policy name");
  1081. return FALSE;
  1082. }
  1083. // is this a string that only has white spaces?
  1084. for (iIndex=0; iIndex < iLen; iIndex++)
  1085. {
  1086. if (pszName[iIndex] != _T(' ') ||
  1087. pszName[iIndex] != _T('\t') ||
  1088. pszName[iIndex] != _T('\n')
  1089. )
  1090. {
  1091. break;
  1092. }
  1093. }
  1094. if ( iIndex == iLen )
  1095. {
  1096. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "This policy name has only white spaces");
  1097. return FALSE;
  1098. }
  1099. //
  1100. // does this name already exist?
  1101. //
  1102. if ( ((CPoliciesNode*)(m_pPolicyNode->m_pParentNode))->FindChildWithName(pszName) )
  1103. {
  1104. ErrorTrace(ERROR_NAPMMC_POLICYPAGE1, "This policy name already exists");
  1105. return FALSE;
  1106. }
  1107. return TRUE;
  1108. }