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.

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