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.

800 lines
18 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1998 - 1999
  4. Module Name:
  5. IASVendorSpecificAttributeEditor.cpp
  6. Abstract:
  7. Implementation file for the CIASVendorSpecificAttributeEditor class.
  8. Revision History:
  9. mmaguire 06/25/98 - created
  10. --*/
  11. //////////////////////////////////////////////////////////////////////////////
  12. //////////////////////////////////////////////////////////////////////////////
  13. // BEGIN INCLUDES
  14. //
  15. // standard includes:
  16. //
  17. #include "Precompiled.h"
  18. //
  19. // where we can find declaration for main class in this file:
  20. //
  21. #include "IASVendorSpecificAttributeEditor.h"
  22. //
  23. // where we can find declarations needed in this file:
  24. //
  25. #include "IASVendorSpecificEditorPage.h"
  26. #include "iashelper.h"
  27. #include "vendors.h"
  28. //
  29. // END INCLUDES
  30. //////////////////////////////////////////////////////////////////////////////
  31. //////////////////////////////////////////////////////////////////////////////
  32. /*++
  33. CIASVendorSpecificAttributeEditor::get_RFCCompliant
  34. IIASVendorSpecificAttributeEditor interface implementation
  35. --*/
  36. //////////////////////////////////////////////////////////////////////////////
  37. STDMETHODIMP CIASVendorSpecificAttributeEditor::get_RFCCompliant(BOOL * pVal)
  38. {
  39. TRACE(_T("CIASVendorSpecificAttributeEditor::get_RFCCompliant\n"));
  40. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  41. HRESULT hr = S_OK;
  42. // Check for preconditions.
  43. if( ! pVal )
  44. {
  45. return E_INVALIDARG;
  46. }
  47. if( ! m_pvarValue )
  48. {
  49. // We are not initialized properly.
  50. return OLE_E_BLANK;
  51. }
  52. *pVal = ( m_fNonRFC ? FALSE : TRUE );
  53. return hr;
  54. }
  55. //////////////////////////////////////////////////////////////////////////////
  56. /*++
  57. CIASVendorSpecificAttributeEditor::put_RFCCompliant
  58. IIASVendorSpecificAttributeEditor interface implementation
  59. --*/
  60. //////////////////////////////////////////////////////////////////////////////
  61. STDMETHODIMP CIASVendorSpecificAttributeEditor::put_RFCCompliant(BOOL newVal)
  62. {
  63. TRACE(_T("CIASVendorSpecificAttributeEditor::put_RFCCompliant\n"));
  64. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  65. // Check for preconditions.
  66. if( ! m_pvarValue )
  67. {
  68. // We are not initialized properly.
  69. return OLE_E_BLANK;
  70. }
  71. HRESULT hr;
  72. m_fNonRFC = ( newVal ? FALSE : TRUE );
  73. // Call this to take our member variables and pack
  74. // them into the variant we were passed.
  75. hr = RepackVSA();
  76. return hr;
  77. }
  78. //////////////////////////////////////////////////////////////////////////////
  79. /*++
  80. CIASVendorSpecificAttributeEditor::get_VendorID
  81. IIASVendorSpecificAttributeEditor interface implementation
  82. --*/
  83. //////////////////////////////////////////////////////////////////////////////
  84. STDMETHODIMP CIASVendorSpecificAttributeEditor::get_VendorID(long * pVal)
  85. {
  86. TRACE(_T("CIASVendorSpecificAttributeEditor::get_VendorID\n"));
  87. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  88. // Check for preconditions.
  89. if( ! pVal )
  90. {
  91. return E_INVALIDARG;
  92. }
  93. if( ! m_pvarValue )
  94. {
  95. // We are not initialized properly.
  96. return OLE_E_BLANK;
  97. }
  98. *pVal = m_dwVendorId;
  99. return S_OK;
  100. }
  101. //////////////////////////////////////////////////////////////////////////////
  102. /*++
  103. CIASVendorSpecificAttributeEditor::put_VendorID
  104. IIASVendorSpecificAttributeEditor interface implementation
  105. --*/
  106. //////////////////////////////////////////////////////////////////////////////
  107. STDMETHODIMP CIASVendorSpecificAttributeEditor::put_VendorID(long newVal)
  108. {
  109. TRACE(_T("CIASVendorSpecificAttributeEditor::put_VendorID\n"));
  110. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  111. HRESULT hr;
  112. // Check for preconditions.
  113. if( ! m_pvarValue )
  114. {
  115. // We are not initialized properly.
  116. return OLE_E_BLANK;
  117. }
  118. m_dwVendorId = newVal;
  119. // Call this to take our member variables and pack
  120. // them into the variant we were passed.
  121. hr = RepackVSA();
  122. return hr;
  123. }
  124. //////////////////////////////////////////////////////////////////////////////
  125. /*++
  126. CIASVendorSpecificAttributeEditor::get_VSAType
  127. IIASVendorSpecificAttributeEditor interface implementation
  128. --*/
  129. //////////////////////////////////////////////////////////////////////////////
  130. STDMETHODIMP CIASVendorSpecificAttributeEditor::get_VSAType(long * pVal)
  131. {
  132. TRACE(_T("CIASVendorSpecificAttributeEditor::get_VSAType\n"));
  133. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  134. // Check for preconditions.
  135. if( ! pVal )
  136. {
  137. return E_INVALIDARG;
  138. }
  139. if( ! m_pvarValue )
  140. {
  141. // We are not initialized properly.
  142. return OLE_E_BLANK;
  143. }
  144. *pVal = m_dwVSAType;
  145. return S_OK;
  146. }
  147. //////////////////////////////////////////////////////////////////////////////
  148. /*++
  149. CIASVendorSpecificAttributeEditor::put_VSAType
  150. IIASVendorSpecificAttributeEditor interface implementation
  151. --*/
  152. //////////////////////////////////////////////////////////////////////////////
  153. STDMETHODIMP CIASVendorSpecificAttributeEditor::put_VSAType(long newVal)
  154. {
  155. TRACE(_T("CIASVendorSpecificAttributeEditor::put_VSAType\n"));
  156. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  157. HRESULT hr;
  158. // Check for preconditions.
  159. if( ! m_pvarValue )
  160. {
  161. // We are not initialized properly.
  162. return OLE_E_BLANK;
  163. }
  164. m_dwVSAType = newVal;
  165. // Call this to take our member variables and pack
  166. // them into the variant we were passed.
  167. hr = RepackVSA();
  168. return hr;
  169. }
  170. //////////////////////////////////////////////////////////////////////////////
  171. /*++
  172. CIASVendorSpecificAttributeEditor::get_VSAFormat
  173. IIASVendorSpecificAttributeEditor interface implementation
  174. --*/
  175. //////////////////////////////////////////////////////////////////////////////
  176. STDMETHODIMP CIASVendorSpecificAttributeEditor::get_VSAFormat(long * pVal)
  177. {
  178. TRACE(_T("CIASVendorSpecificAttributeEditor::get_VSAFormat\n"));
  179. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  180. // Check for preconditions.
  181. if( ! pVal )
  182. {
  183. return E_INVALIDARG;
  184. }
  185. if( ! m_pvarValue )
  186. {
  187. // We are not initialized properly.
  188. return OLE_E_BLANK;
  189. }
  190. *pVal = m_dwVSAFormat;
  191. return S_OK;
  192. }
  193. //////////////////////////////////////////////////////////////////////////////
  194. /*++
  195. CIASVendorSpecificAttributeEditor::put_VSAFormat
  196. IIASVendorSpecificAttributeEditor interface implementation
  197. --*/
  198. //////////////////////////////////////////////////////////////////////////////
  199. STDMETHODIMP CIASVendorSpecificAttributeEditor::put_VSAFormat(long newVal)
  200. {
  201. TRACE(_T("CIASVendorSpecificAttributeEditor::get_VSAFormat\n"));
  202. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  203. HRESULT hr;
  204. // Check for preconditions.
  205. if( ! m_pvarValue )
  206. {
  207. // We are not initialized properly.
  208. return OLE_E_BLANK;
  209. }
  210. m_dwVSAFormat = newVal;
  211. // Call this to take our member variables and pack
  212. // them into the variant we were passed.
  213. hr = RepackVSA();
  214. return hr;
  215. }
  216. //////////////////////////////////////////////////////////////////////////////
  217. /*++
  218. CIASVendorSpecificAttributeEditor::SetAttributeValue
  219. IIASAttributeEditor interface implementation
  220. --*/
  221. //////////////////////////////////////////////////////////////////////////////
  222. STDMETHODIMP CIASVendorSpecificAttributeEditor::SetAttributeValue(VARIANT * pValue)
  223. {
  224. TRACE(_T("CIASVendorSpecificAttributeEditor::SetAttributeValue\n"));
  225. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  226. // Check for preconditions.
  227. if( ! pValue )
  228. {
  229. return E_INVALIDARG;
  230. }
  231. if( V_VT( pValue ) != VT_EMPTY && V_VT( pValue ) != VT_BSTR )
  232. {
  233. return E_INVALIDARG;
  234. }
  235. m_pvarValue = pValue;
  236. HRESULT hr = S_OK;
  237. // Reset our member variables.
  238. m_dwVendorId = 0;
  239. m_fNonRFC = TRUE;
  240. m_dwVSAFormat = 0;
  241. m_dwVSAType = 0;
  242. m_bstrDisplayValue.Empty();
  243. m_bstrVendorName.Empty();
  244. if( V_VT( m_pvarValue ) == VT_BSTR )
  245. {
  246. hr = UnpackVSA();
  247. }
  248. return hr;
  249. }
  250. //////////////////////////////////////////////////////////////////////////////
  251. /*++
  252. CIASVendorSpecificAttributeEditor::get_ValueAsString
  253. IIASAttributeEditor interface implementation
  254. --*/
  255. //////////////////////////////////////////////////////////////////////////////
  256. STDMETHODIMP CIASVendorSpecificAttributeEditor::get_ValueAsString(BSTR * pbstrDisplayText )
  257. {
  258. TRACE(_T("CIASVendorSpecificAttributeEditor::get_ValueAsString\n"));
  259. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  260. // Check for preconditions.
  261. if( ! pbstrDisplayText )
  262. {
  263. return E_INVALIDARG;
  264. }
  265. if( ! m_pvarValue )
  266. {
  267. // We are not initialized properly.
  268. return OLE_E_BLANK;
  269. }
  270. *pbstrDisplayText = m_bstrDisplayValue.Copy();
  271. return S_OK;
  272. }
  273. //////////////////////////////////////////////////////////////////////////////
  274. /*++
  275. CIASVendorSpecificAttributeEditor::ShowEditor
  276. IIASAttributeEditor interface implementation
  277. --*/
  278. //////////////////////////////////////////////////////////////////////////////
  279. STDMETHODIMP CIASVendorSpecificAttributeEditor::ShowEditor( /*[in, out]*/ BSTR *pReserved )
  280. {
  281. TRACE(_T("CIASVendorSpecificAttributeEditor::ShowEditor\n"));
  282. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  283. if( ! m_spIASAttributeInfo )
  284. {
  285. // We are not initialized properly.
  286. return OLE_E_BLANK;
  287. }
  288. if( ! m_pvarValue )
  289. {
  290. // We are not initialized properly.
  291. return OLE_E_BLANK;
  292. }
  293. HRESULT hr = S_OK;
  294. try
  295. {
  296. // Load page title.
  297. // ::CString strPageTitle;
  298. // strPageTitle.LoadString(IDS_IAS_IP_EDITOR_TITLE);
  299. // CPropertySheet propSheet( (LPCTSTR)strPageTitle );
  300. //
  301. // IP Address Editor
  302. //
  303. CIASPgVendorSpecAttr cppPage;
  304. // Initialize the page's data exchange fields with info from IAttributeInfo
  305. CComBSTR bstrName;
  306. hr = m_spIASAttributeInfo->get_AttributeName( &bstrName );
  307. if( FAILED(hr) ) throw hr;
  308. cppPage.m_strName = bstrName;
  309. LONG lVendorIndex = 0;
  310. CComPtr<IIASNASVendors> spIASNASVendors;
  311. HRESULT hrTemp = CoCreateInstance( CLSID_IASNASVendors, NULL, CLSCTX_INPROC_SERVER, IID_IIASNASVendors, (LPVOID *) &spIASNASVendors );
  312. if( SUCCEEDED(hrTemp) )
  313. {
  314. hrTemp = spIASNASVendors->get_VendorIDToOrdinal(m_dwVendorId, &lVendorIndex);
  315. }
  316. // Note: If vendor information fails, we'll just use 0.
  317. if(hrTemp == S_OK) // converted to index
  318. {
  319. cppPage.m_dVendorIndex = lVendorIndex;
  320. cppPage.m_bVendorIndexAsID = FALSE;
  321. }
  322. else
  323. {
  324. cppPage.m_dVendorIndex = m_dwVendorId;
  325. cppPage.m_bVendorIndexAsID = TRUE;
  326. }
  327. cppPage.m_fNonRFC = m_fNonRFC;
  328. cppPage.m_dType = m_dwVSAType;
  329. cppPage.m_dFormat = m_dwVSAFormat;
  330. cppPage.m_strDispValue = m_bstrDisplayValue;
  331. // Initialize the page's data exchange fields with info from VARIANT value passed in.
  332. if ( V_VT(m_pvarValue) != VT_EMPTY )
  333. {
  334. // _ASSERTE( V_VT(m_pvarValue) == VT_I4 );
  335. // cppPage.m_dwIpAddr = V_I4(m_pvarValue);
  336. // cppPage.m_fIpAddrPreSet = TRUE;
  337. }
  338. // propSheet.AddPage(&cppPage);
  339. // int iResult = propSheet.DoModal();
  340. int iResult = cppPage.DoModal();
  341. if (IDOK == iResult)
  342. {
  343. // Load values from property page into our member variables.
  344. LONG lVendorID = 0;
  345. if(cppPage.m_bVendorIndexAsID == TRUE)
  346. lVendorID = cppPage.m_dVendorIndex;
  347. else
  348. HRESULT hrTemp = spIASNASVendors->get_VendorID(cppPage.m_dVendorIndex, &lVendorID);
  349. // Note: If vendor information fails, we'll just use 0.
  350. m_dwVendorId = lVendorID;
  351. m_fNonRFC = cppPage.m_fNonRFC;
  352. m_dwVSAType = cppPage.m_dType;
  353. m_dwVSAFormat = cppPage.m_dFormat;
  354. m_bstrDisplayValue = cppPage.m_strDispValue;
  355. // Call this to take our member variables and pack
  356. // them into the variant we were passed.
  357. hr = RepackVSA();
  358. }
  359. else
  360. {
  361. hr = S_FALSE;
  362. }
  363. //
  364. // delete the property page pointer
  365. //
  366. // propSheet.RemovePage(&cppPage);
  367. }
  368. catch( HRESULT & hr )
  369. {
  370. return hr;
  371. }
  372. catch(...)
  373. {
  374. return hr = E_FAIL;
  375. }
  376. return hr;
  377. }
  378. //////////////////////////////////////////////////////////////////////////////
  379. /*++
  380. CIASVendorSpecificAttributeEditor::put_ValueAsString
  381. IIASAttributeEditor interface implementation
  382. --*/
  383. //////////////////////////////////////////////////////////////////////////////
  384. STDMETHODIMP CIASVendorSpecificAttributeEditor::put_ValueAsString(BSTR newVal)
  385. {
  386. TRACE(_T("CIASEnumerableAttributeEditor::put_ValueAsString\n"));
  387. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  388. // Check for preconditions.
  389. if( ! m_pvarValue )
  390. {
  391. // We are not initialized properly.
  392. return OLE_E_BLANK;
  393. }
  394. HRESULT hr;
  395. m_bstrDisplayValue = newVal;
  396. // Call this to take our member variables and pack
  397. // them into the variant we were passed.
  398. hr = RepackVSA();
  399. return hr;
  400. }
  401. //////////////////////////////////////////////////////////////////////////////
  402. /*++
  403. CIASVendorSpecificAttributeEditor::UnpackVSA
  404. Parses a vendor specific attribute string into its consituent data.
  405. Stores this data in several member variables of this class.
  406. --*/
  407. //////////////////////////////////////////////////////////////////////////////
  408. STDMETHODIMP CIASVendorSpecificAttributeEditor::UnpackVSA()
  409. {
  410. TRACE(_T("CIASVendorSpecificAttributeEditor::UnpackVSA\n"));
  411. // Attempt to unpack the fields in the Vendor Specific Attribute
  412. // And store them in our member variables.
  413. HRESULT hr;
  414. if( V_VT(m_pvarValue) != VT_BSTR )
  415. {
  416. return E_FAIL;
  417. }
  418. ::CString cstrValue = V_BSTR(m_pvarValue);
  419. ::CString cstrDispValue;
  420. // We will use Baogang's helper functions to extract the required info
  421. // from the vendor specific attribute's value.
  422. hr = ::GetVendorSpecificInfo( cstrValue
  423. , m_dwVendorId
  424. , m_fNonRFC
  425. , m_dwVSAFormat
  426. , m_dwVSAType
  427. , cstrDispValue
  428. );
  429. if( FAILED(hr) )
  430. {
  431. return hr;
  432. }
  433. // Save away the display string.
  434. m_bstrDisplayValue = (LPCTSTR) cstrDispValue;
  435. // Save away the vendor name in our member variable.
  436. CComPtr<IIASNASVendors> spIASNASVendors;
  437. HRESULT hrTemp = CoCreateInstance( CLSID_IASNASVendors, NULL, CLSCTX_INPROC_SERVER, IID_IIASNASVendors, (LPVOID *) &spIASNASVendors );
  438. if( SUCCEEDED(hrTemp) )
  439. {
  440. LONG lVendorIndex;
  441. hrTemp = spIASNASVendors->get_VendorIDToOrdinal(m_dwVendorId, &lVendorIndex);
  442. if( S_OK == hrTemp )
  443. {
  444. CComBSTR bstrVendorName;
  445. hrTemp = spIASNASVendors->get_VendorName( lVendorIndex, &m_bstrVendorName );
  446. }
  447. else
  448. {
  449. hr = ::MakeVendorNameFromVendorID(m_dwVendorId, &m_bstrVendorName );
  450. }
  451. }
  452. // Ignore any HRESULT from above.
  453. return S_OK;
  454. }
  455. //////////////////////////////////////////////////////////////////////////////
  456. /*++
  457. CIASVendorSpecificAttributeEditor::RepackVSA
  458. Takes several member variables of this class and packs them
  459. into a vendor specific attribute string.
  460. --*/
  461. //////////////////////////////////////////////////////////////////////////////
  462. STDMETHODIMP CIASVendorSpecificAttributeEditor::RepackVSA()
  463. {
  464. TRACE(_T("CIASVendorSpecificAttributeEditor::RepackVSA\n"));
  465. HRESULT hr;
  466. ::CString cstrValue;
  467. ::CString cstrDisplayValue = m_bstrDisplayValue;
  468. // We will use Baogang's helper function to pack the required info
  469. // into the vendor specific attribute's value.
  470. hr = ::SetVendorSpecificInfo( cstrValue,
  471. m_dwVendorId,
  472. m_fNonRFC,
  473. m_dwVSAFormat,
  474. m_dwVSAType,
  475. cstrDisplayValue
  476. );
  477. if( FAILED( hr ) )
  478. {
  479. return hr;
  480. }
  481. VariantClear(m_pvarValue);
  482. V_VT(m_pvarValue) = VT_BSTR;
  483. V_BSTR(m_pvarValue) = SysAllocString(cstrValue);
  484. return hr;
  485. }
  486. //////////////////////////////////////////////////////////////////////////////
  487. /*++
  488. CIASVendorSpecificAttributeEditor::get_VendorName
  489. The default implementation of get_VendorName queries the AttributeInfo for this information.
  490. In the case of the RADIUS Vendor Specific Attribute (ID ==26), the AttributeInfo
  491. itself will not have the information about vendor ID, rather this
  492. information will be encapsulated in the attribute value itself.
  493. For this reason, UI clients should always query an attribute editor for vendor
  494. information rather than the attribute itself.
  495. e.g., in the case of VSA's, the AttributeInfo will always return
  496. RADIUS Standard for vendor type.
  497. --*/
  498. //////////////////////////////////////////////////////////////////////////////
  499. STDMETHODIMP CIASVendorSpecificAttributeEditor::get_VendorName(BSTR * pVal)
  500. {
  501. TRACE(_T("CIASVendorSpecificAttributeEditor::get_VendorName\n"));
  502. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  503. // Check for preconditions.
  504. if( ! pVal )
  505. {
  506. return E_INVALIDARG;
  507. }
  508. if( ! m_spIASAttributeInfo )
  509. {
  510. // We are not initialized properly.
  511. return OLE_E_BLANK;
  512. }
  513. HRESULT hr = S_OK;
  514. try
  515. {
  516. if( ! m_pvarValue )
  517. {
  518. // We have not been set with a value, so we can't read vendor ID
  519. // out of that string.
  520. // Just give back the default implementations' answer,
  521. // which in this case will be "RADIUS standard".
  522. hr = CIASAttributeEditor::get_VendorName( pVal );
  523. }
  524. else
  525. {
  526. // We have a value, so pass back the vendor name which we
  527. // extracted out of that value.
  528. *pVal = m_bstrVendorName.Copy();
  529. }
  530. }
  531. catch(HRESULT &hr)
  532. {
  533. return hr;
  534. }
  535. catch(...)
  536. {
  537. return E_FAIL;
  538. }
  539. return hr;
  540. }
  541. //////////////////////////////////////////////////////////////////////////////
  542. /*++
  543. CIASVendorSpecificAttributeEditor::put_VendorName
  544. --*/
  545. //////////////////////////////////////////////////////////////////////////////
  546. STDMETHODIMP CIASVendorSpecificAttributeEditor::put_VendorName(BSTR newVal)
  547. {
  548. TRACE(_T("CIASVendorSpecificAttributeEditor::put_VendorName\n"));
  549. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  550. return E_NOTIMPL;
  551. // Check for preconditions.
  552. // if( ! m_spIASAttributeInfo )
  553. // {
  554. // // We are not initialized properly.
  555. // return OLE_E_BLANK;
  556. // }
  557. }