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.

1096 lines
35 KiB

  1. // Map11Pge.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <iadmw.h>
  5. #include "certmap.h"
  6. // persistence and mapping includes
  7. #include "WrapMaps.h"
  8. //#include "wrpprsis.h"
  9. //#include "admutil.h"
  10. #include "ListRow.h"
  11. #include "ChkLstCt.h"
  12. #include "wrapmb.h"
  13. // mapping page includes
  14. #include "brwsdlg.h"
  15. #include "EdtOne11.h"
  16. #include "Ed11Maps.h"
  17. #include "Map11Pge.h"
  18. #include "CrackCrt.h"
  19. #include <iiscnfgp.h>
  20. //#include "WrpMBWrp.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. #define COL_NUM_ENABLED 0
  27. #define COL_NUM_NAME 1
  28. #define COL_NUM_NTACCOUNT 2
  29. #define MB_EXTEND_KEY _T("Cert11")
  30. #define MB_EXTEND_KEY_MAPS _T("Cert11/Mappings")
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMap11Page property page
  33. IMPLEMENT_DYNCREATE(CMap11Page, CPropertyPage)
  34. CMap11Page::CMap11Page() : CPropertyPage(CMap11Page::IDD),
  35. m_MapsInMetabase( 0 )
  36. {
  37. //{{AFX_DATA_INIT(CMap11Page)
  38. m_csz_i_c = _T("");
  39. m_csz_i_o = _T("");
  40. m_csz_i_ou = _T("");
  41. m_csz_s_c = _T("");
  42. m_csz_s_cn = _T("");
  43. m_csz_s_l = _T("");
  44. m_csz_s_o = _T("");
  45. m_csz_s_ou = _T("");
  46. m_csz_s_s = _T("");
  47. //}}AFX_DATA_INIT
  48. }
  49. CMap11Page::~CMap11Page()
  50. {
  51. ResetMappingList();
  52. }
  53. void CMap11Page::DoDataExchange(CDataExchange* pDX)
  54. {
  55. CPropertyPage::DoDataExchange(pDX);
  56. //{{AFX_DATA_MAP(CMap11Page)
  57. DDX_Control(pDX, IDC_ADD, m_cbutton_add);
  58. DDX_Control(pDX, IDC_ISSUER, m_cbutton_grp_issuer);
  59. DDX_Control(pDX, IDC_ISSUED_TO, m_cbutton_grp_issuedto);
  60. DDX_Control(pDX, IDC_LIST, m_clistctrl_list);
  61. DDX_Control(pDX, IDC_EDIT_11MAP, m_cbutton_editmap);
  62. DDX_Control(pDX, IDC_DELETE, m_cbutton_delete);
  63. DDX_Text(pDX, IDC_I_C, m_csz_i_c);
  64. DDX_Text(pDX, IDC_I_O, m_csz_i_o);
  65. DDX_Text(pDX, IDC_I_OU, m_csz_i_ou);
  66. DDX_Text(pDX, IDC_S_C, m_csz_s_c);
  67. DDX_Text(pDX, IDC_S_CN, m_csz_s_cn);
  68. DDX_Text(pDX, IDC_S_L, m_csz_s_l);
  69. DDX_Text(pDX, IDC_S_O, m_csz_s_o);
  70. DDX_Text(pDX, IDC_S_OU, m_csz_s_ou);
  71. DDX_Text(pDX, IDC_S_S, m_csz_s_s);
  72. //}}AFX_DATA_MAP
  73. }
  74. BEGIN_MESSAGE_MAP(CMap11Page, CPropertyPage)
  75. //{{AFX_MSG_MAP(CMap11Page)
  76. ON_BN_CLICKED(IDC_ADD, OnAdd)
  77. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  78. ON_BN_CLICKED(IDC_EDIT_11MAP, OnEdit11map)
  79. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnItemchangedList)
  80. ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
  81. //}}AFX_MSG_MAP
  82. ON_COMMAND(ID_HELP_FINDER, DoHelp)
  83. ON_COMMAND(ID_HELP, DoHelp)
  84. ON_COMMAND(ID_CONTEXT_HELP, DoHelp)
  85. ON_COMMAND(ID_DEFAULT_HELP, DoHelp)
  86. END_MESSAGE_MAP()
  87. //---------------------------------------------------------------------------
  88. void CMap11Page::DoHelp()
  89. {
  90. WinHelp( HIDD_CERTMAP_MAIN_BASIC );
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. // initialization routines
  94. //---------------------------------------------------------------------------
  95. // FInitMapper is called by the routine instantiating this page. After the object
  96. // is first created is when it is called. It allows us to fail gracefully.
  97. BOOL CMap11Page::FInit(IMSAdminBase* pMB)
  98. {
  99. m_pMB = pMB;
  100. // this has become a simple place
  101. return TRUE;
  102. }
  103. //---------------------------------------------------------------------------
  104. BOOL CMap11Page::OnInitDialog()
  105. {
  106. //call the parental oninitdialog
  107. BOOL f = CPropertyPage::OnInitDialog();
  108. // if the initinalization (sp?) succeeded, init the list and other items
  109. if ( f )
  110. {
  111. // init the contents of the list
  112. FInitMappingList();
  113. // Fill the mapping list with the stored items
  114. FillMappingList();
  115. // set the initial button states
  116. EnableDependantButtons();
  117. }
  118. // set any changes in the info into place
  119. UpdateData(FALSE);
  120. // return the answer
  121. return f;
  122. }
  123. //---------------------------------------------------------------------------
  124. BOOL CMap11Page::FInitMappingList()
  125. {
  126. CString sz;
  127. int i;
  128. // setup the friendly name column
  129. sz.Empty();
  130. i = m_clistctrl_list.InsertColumn( COL_NUM_ENABLED, sz, LVCFMT_LEFT, 20 );
  131. // setup the friendly name column
  132. sz.LoadString( IDS_LIST11_NAME );
  133. i = m_clistctrl_list.InsertColumn( COL_NUM_NAME, sz, LVCFMT_LEFT, 105 );
  134. // setup the account column
  135. sz.LoadString( IDS_LIST11_ACCOUNT );
  136. i = m_clistctrl_list.InsertColumn( COL_NUM_NTACCOUNT, sz, LVCFMT_LEFT, 195 );
  137. return TRUE;
  138. }
  139. //---------------------------------------------------------------------------
  140. BOOL CMap11Page::FillMappingList()
  141. {
  142. // reset the mapping list - get rid of anything in there now
  143. ResetMappingList();
  144. // read in the mappings - it adds them to the list
  145. FReadMappings();
  146. return TRUE;
  147. }
  148. //---------------------------------------------------------------------------
  149. //BOOL CMap11Page::FAddMappingToList( C11Mapping* pMap, DWORD iList )
  150. BOOL CMap11Page::FAddMappingToList( C11Mapping* pMap )
  151. {
  152. CString sz;
  153. int i;
  154. DWORD iList;
  155. // if requested, make sure the mapping is added to the end of the list
  156. iList = m_clistctrl_list.GetItemCount();
  157. // get the appropriate "enabled" string
  158. BOOL fEnabled;
  159. pMap->GetMapEnabled( &fEnabled );
  160. if ( fEnabled )
  161. sz.LoadString( IDS_ENABLED );
  162. else
  163. sz.Empty();
  164. // add the friendly name of the mapping
  165. // create the new entry in the list box. Do not sort on this entry - yet
  166. i = m_clistctrl_list.InsertItem( iList, sz );
  167. // add the friendly name of the mapping
  168. pMap->GetMapName( sz );
  169. // create the new entry in the list box. Do not sort on this entry - yet
  170. m_clistctrl_list.SetItemText( i, COL_NUM_NAME, sz );
  171. // add the account name of the mapping
  172. pMap->GetNTAccount( sz );
  173. m_clistctrl_list.SetItemText( i, COL_NUM_NTACCOUNT, sz );
  174. // attach the pointer to the mapping as the private data in the list.
  175. m_clistctrl_list.SetItemData( i, (UINT_PTR)pMap );
  176. // return whether or not the insertion succeeded
  177. return TRUE;
  178. }
  179. //---------------------------------------------------------------------------
  180. void CMap11Page::EnableDependantButtons()
  181. {
  182. // the whole purpose of this routine is to gray or activate
  183. // the edit and delete buttons depending on whether or not anything
  184. // is selected. So start by getting the selection count
  185. if ( m_clistctrl_list.GetSelectedCount() > 0 )
  186. {
  187. // there are items selected
  188. m_cbutton_editmap.EnableWindow( TRUE );
  189. m_cbutton_delete.EnableWindow( TRUE );
  190. EnableCrackDisplay( TRUE );
  191. }
  192. else
  193. {
  194. // nope. Nothing selected
  195. m_cbutton_editmap.EnableWindow( FALSE );
  196. m_cbutton_delete.EnableWindow( FALSE );
  197. }
  198. // always enable the add button
  199. m_cbutton_add.EnableWindow( TRUE );
  200. }
  201. //---------------------------------------------------------------------------
  202. BOOL CMap11Page::EditOneMapping( C11Mapping* pUpdateMap )
  203. {
  204. CEditOne11MapDlg mapdlg;
  205. // prepare the mapping dialog
  206. pUpdateMap->GetMapName( mapdlg.m_sz_mapname );
  207. pUpdateMap->GetMapEnabled( &mapdlg.m_bool_enable );
  208. pUpdateMap->GetNTAccount( mapdlg.m_sz_accountname );
  209. pUpdateMap->GetNTPassword( mapdlg.m_sz_password );
  210. // run the mapping dialog
  211. if ( mapdlg.DoModal() == IDOK )
  212. {
  213. // update its friendly name
  214. pUpdateMap->SetMapName( mapdlg.m_sz_mapname );
  215. // set the NT account field of the mapping object
  216. pUpdateMap->SetNTAccount( mapdlg.m_sz_accountname );
  217. // set the NT account password field of the mapping object
  218. pUpdateMap->SetNTPassword( mapdlg.m_sz_password );
  219. // set whether or not the mapping is enabled
  220. pUpdateMap->SetMapEnabled( mapdlg.m_bool_enable );
  221. // NOTE: the caller is resposible for calling UpdateMappingInDispList
  222. // as the mapping in question may not yet be in the display list
  223. // this mapping has changed. Mark it to be saved
  224. MarkToSave( pUpdateMap );
  225. // return true because the user said "OK"
  226. return TRUE;
  227. }
  228. // return FALSE because the user did not say "OK"
  229. return FALSE;
  230. }
  231. //---------------------------------------------------------------------------
  232. BOOL CMap11Page::EditMultipleMappings()
  233. {
  234. CEdit11Mappings mapdlg;
  235. C11Mapping* pUpdate11Map;
  236. BOOL fSetInitialState = FALSE;
  237. BOOL fEnable;
  238. // scan the list of seleted items for the proper initial enable button state
  239. // loop through the selected items, setting each one's mapping
  240. int iList = -1;
  241. while( (iList = m_clistctrl_list.GetNextItem( iList, LVNI_SELECTED )) >= 0 )
  242. {
  243. // get the mapping item for updating purposes
  244. pUpdate11Map = GetMappingInDisplay( iList );
  245. ASSERT( pUpdate11Map );
  246. if ( !pUpdate11Map )
  247. {
  248. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  249. break;
  250. }
  251. // get the enable state of the mapping
  252. pUpdate11Map->GetMapEnabled( &fEnable );
  253. // if this is the first time, just set the initial state
  254. if ( !fSetInitialState )
  255. {
  256. mapdlg.m_int_enable = fEnable;
  257. fSetInitialState = TRUE;
  258. }
  259. else
  260. {
  261. // if it is different, then go indeterminate and break
  262. if ( fEnable != mapdlg.m_int_enable )
  263. {
  264. mapdlg.m_int_enable = 2;
  265. break;
  266. }
  267. }
  268. }
  269. // run the mapping dialog
  270. if ( mapdlg.DoModal() == IDOK )
  271. {
  272. // loop through the selected items, setting each one's mapping
  273. int iList = -1;
  274. while( (iList = m_clistctrl_list.GetNextItem( iList, LVNI_SELECTED )) >= 0 )
  275. {
  276. // get the mapping item for updating purposes
  277. pUpdate11Map = GetMappingInDisplay( iList );
  278. if ( !pUpdate11Map )
  279. {
  280. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  281. break;
  282. }
  283. // set the enable flag if requested
  284. switch ( mapdlg.m_int_enable )
  285. {
  286. case 0: // disable
  287. pUpdate11Map->SetMapEnabled( FALSE );
  288. break;
  289. case 1: // enable
  290. pUpdate11Map->SetMapEnabled( TRUE );
  291. break;
  292. }
  293. // set the NT account field of the mapping object
  294. pUpdate11Map->SetNTAccount( mapdlg.m_sz_accountname );
  295. // set the NT account password field of the mapping object
  296. pUpdate11Map->SetNTPassword( mapdlg.m_sz_password );
  297. // update it in the list control too
  298. UpdateMappingInDispList( iList, pUpdate11Map );
  299. // this mapping has changed. Mark it to be saved
  300. MarkToSave( pUpdate11Map );
  301. }
  302. // activate the apply button
  303. SetModified();
  304. // return true because the user said "OK"
  305. return TRUE;
  306. }
  307. // return FALSE because the user did not say "OK"
  308. return FALSE;
  309. }
  310. //---------------------------------------------------------------------------
  311. void CMap11Page::UpdateMappingInDispList( DWORD iList, C11Mapping* pMap )
  312. {
  313. CString sz;
  314. // verify the index and the pointer!
  315. ASSERT( pMap == GetMappingInDisplay(iList) );
  316. // get the appropriate "enabled" string
  317. BOOL fEnabled;
  318. pMap->GetMapEnabled( &fEnabled );
  319. if ( fEnabled )
  320. sz.LoadString( IDS_ENABLED );
  321. else
  322. sz.Empty();
  323. // update the "Enabled" indicator
  324. m_clistctrl_list.SetItemText( iList, COL_NUM_ENABLED, sz );
  325. // update the mapping name
  326. pMap->GetMapName( sz );
  327. m_clistctrl_list.SetItemText( iList, COL_NUM_NAME, sz );
  328. // update the account name
  329. pMap->GetNTAccount( sz );
  330. m_clistctrl_list.SetItemText( iList, COL_NUM_NTACCOUNT, sz );
  331. }
  332. //---------------------------------------------------------------------------
  333. void CMap11Page::ResetMappingList()
  334. {
  335. // first, delete all the mapping objects in the list
  336. DWORD cbList = m_clistctrl_list.GetItemCount();
  337. for ( DWORD iList = 0; iList < cbList; iList++ )
  338. DeleteMapping( GetMappingInDisplay(iList) );
  339. // reset the mapping list - get rid of anything in there now
  340. m_clistctrl_list.DeleteAllItems();
  341. }
  342. //---------------------------------------------------------------------------
  343. void CMap11Page::MarkToSave( C11Mapping* pSaveMap, BOOL fSave )
  344. {
  345. // first, we see if it is already in the list. If it is, we have nothing to do
  346. // unless fSave is set to false, then we remove it from the list
  347. DWORD cbItemsInList = (DWORD)m_rgbSave.GetSize();
  348. for ( DWORD i = 0; i < cbItemsInList; i++ )
  349. {
  350. if ( pSaveMap == (C11Mapping*)m_rgbSave[i] )
  351. {
  352. // go away if fSave, otherwise, double check it isn't
  353. // anywhere else in the list
  354. if ( fSave )
  355. {
  356. return;
  357. }
  358. else
  359. {
  360. // remove the item from the list
  361. m_rgbSave.RemoveAt(i);
  362. // don't skip now as the list slid down
  363. cbItemsInList--;
  364. i--;
  365. }
  366. }
  367. }
  368. // since it is not there, we should add it, if fSave is true
  369. if ( fSave )
  370. m_rgbSave.Add( (CObject*)pSaveMap );
  371. }
  372. /////////////////////////////////////////////////////////////////////////////
  373. // CMap11Page message handlers
  374. //---------------------------------------------------------------------------
  375. void CMap11Page::OnOK()
  376. {
  377. // this has gotten much simpler
  378. FWriteMappings();
  379. CPropertyPage::OnOK();
  380. }
  381. //---------------------------------------------------------------------------
  382. BOOL CMap11Page::OnApply()
  383. {
  384. // this has gotten much simpler
  385. BOOL f = FWriteMappings();
  386. // rebuild the display
  387. FillMappingList();
  388. return f;
  389. }
  390. //#define MB_EXTEND_KEY "nsepm/Cert11/"
  391. //#define MB_EXTEND_KEY_MAPS "nsepm/Cert11/Mappings/"
  392. //---------------------------------------------------------------------------
  393. // when the user pushes the add button, ask them to load a certificate, then
  394. // add it to the list as a mapping
  395. void CMap11Page::OnAdd()
  396. {
  397. // put this in a try/catch to make errors easier to deal with
  398. try {
  399. CString szFilter;
  400. szFilter.LoadString( IDS_KEY_OR_CERT_FILE_FILTER );
  401. // prepare the file dialog variables
  402. CFileDialog cfdlg(TRUE, NULL, NULL,
  403. OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
  404. (LPCTSTR)szFilter);
  405. // Disable hook to get Windows 2000 style dialog
  406. cfdlg.m_ofn.Flags &= ~(OFN_ENABLEHOOK);
  407. // run the dialog
  408. if ( cfdlg.DoModal() == IDOK )
  409. {
  410. // add the certificate to the mapping list
  411. if ( FAddCertificateFile( cfdlg.GetPathName() ) )
  412. {
  413. // activate the apply button
  414. SetModified();
  415. }
  416. }
  417. }
  418. catch ( CException e )
  419. {
  420. }
  421. }
  422. //---------------------------------------------------------------------------
  423. void CMap11Page::OnDelete()
  424. {
  425. C11Mapping* pKillMap;
  426. // ask the user to confirm this decision
  427. if ( AfxMessageBox(IDS_CONFIRM_DELETE, MB_OKCANCEL) != IDOK )
  428. return;
  429. // loop through the selected items. Remove each from the list,
  430. // then mark it to be deleted.
  431. int iList = -1;
  432. while( (iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED )) >= 0 )
  433. {
  434. // get the mapping
  435. pKillMap = GetMappingInDisplay( iList );
  436. // remove it from the list
  437. m_clistctrl_list.DeleteItem( iList );
  438. // if it has not yet been applied to the metabase, continue
  439. if ( pKillMap->iMD == NEW_OBJECT )
  440. {
  441. // since this mapping never existed, we can just remove it from the add/edit lists
  442. MarkToSave( pKillMap, FALSE );
  443. // go to the next selected object
  444. continue;
  445. }
  446. // mark the item to be deleted from the metabase
  447. m_rgbDelete.Add( (CObject*)pKillMap );
  448. }
  449. // activate the apply button
  450. SetModified();
  451. }
  452. //---------------------------------------------------------------------------
  453. void CMap11Page::OnEdit11map()
  454. {
  455. int iList;
  456. C11Mapping* pUpdateMap;
  457. // what happens here depends on if just one mapping is selected, or many
  458. switch( m_clistctrl_list.GetSelectedCount() )
  459. {
  460. case 0: // do nothing - should not get here because button grays out
  461. ASSERT( FALSE );
  462. break;
  463. case 1: // get the mapping for update and run single edit dialog
  464. // get index of the selected list item
  465. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  466. ASSERT( iList >= 0 );
  467. // get the mapping item for updating purposes
  468. pUpdateMap = GetMappingInDisplay( iList );
  469. if ( !pUpdateMap )
  470. {
  471. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  472. break;
  473. }
  474. // edit the mapping, update it if successful, delete if not
  475. if ( EditOneMapping(pUpdateMap) )
  476. {
  477. UpdateMappingInDispList( iList, pUpdateMap );
  478. // activate the apply button
  479. SetModified();
  480. }
  481. break;
  482. default: // run the multi edit dialog
  483. EditMultipleMappings();
  484. break;
  485. }
  486. }
  487. //---------------------------------------------------------------------------
  488. void CMap11Page::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
  489. {
  490. *pResult = 0;
  491. // if something in the list was double clicked, edit it
  492. if ( m_clistctrl_list.GetSelectedCount() > 0 )
  493. OnEdit11map();
  494. }
  495. //---------------------------------------------------------------------------
  496. void CMap11Page::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
  497. {
  498. C11Mapping* pSelMap;
  499. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  500. *pResult = 0;
  501. // enable the correct items
  502. EnableDependantButtons();
  503. // fill in the cracked information for the selected mapping - if there is only one
  504. if ( m_clistctrl_list.GetSelectedCount() == 1 )
  505. {
  506. // get index of the selected list item
  507. int i = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  508. ASSERT( i >= 0 );
  509. // get the mapper index for the item
  510. pSelMap = GetMappingInDisplay( i );
  511. if ( pSelMap )
  512. {
  513. DisplayCrackedMap( pSelMap );
  514. }
  515. }
  516. else
  517. {
  518. // either multiple, or no mappings selected
  519. EnableCrackDisplay( FALSE );
  520. }
  521. }
  522. //================================================================================
  523. // special display
  524. //---------------------------------------------------------------------------
  525. BOOL CMap11Page::DisplayCrackedMap( C11Mapping* pMap )
  526. {
  527. PUCHAR pCert;
  528. DWORD cbCert;
  529. CString sz;
  530. // obtain a reference to the certificate
  531. if ( !pMap->GetCertificate( &pCert, &cbCert ) )
  532. return FALSE;
  533. // crack the certificate
  534. CCrackedCert cracker;
  535. if ( !cracker.CrackCert( pCert, cbCert ) )
  536. return FALSE;
  537. // fill in all the fields
  538. cracker.GetIssuerCountry( sz );
  539. m_csz_i_c = sz;
  540. cracker.GetIssuerOrganization( sz );
  541. m_csz_i_o = sz;
  542. cracker.GetIssuerUnit( sz );
  543. m_csz_i_ou = sz;
  544. cracker.GetSubjectCountry( sz );
  545. m_csz_s_c = sz;
  546. cracker.GetSubjectCommonName( sz );
  547. m_csz_s_cn = sz;
  548. cracker.GetSubjectLocality( sz );
  549. m_csz_s_l = sz;
  550. cracker.GetSubjectOrganization( sz );
  551. m_csz_s_o = sz;
  552. cracker.GetSubjectUnit( sz );
  553. m_csz_s_ou = sz;
  554. cracker.GetSubjectState( sz );
  555. m_csz_s_s = sz;
  556. UpdateData( FALSE );
  557. // return success
  558. return TRUE;
  559. }
  560. //---------------------------------------------------------------------------
  561. void CMap11Page::ClearCrackDisplay()
  562. {
  563. m_csz_i_c.Empty();
  564. m_csz_i_o.Empty();
  565. m_csz_i_ou.Empty();
  566. m_csz_s_c.Empty();
  567. m_csz_s_cn.Empty();
  568. m_csz_s_l.Empty();
  569. m_csz_s_o.Empty();
  570. m_csz_s_ou.Empty();
  571. m_csz_s_s.Empty();
  572. UpdateData( FALSE );
  573. }
  574. //---------------------------------------------------------------------------
  575. void CMap11Page::EnableCrackDisplay( BOOL fEnable )
  576. {
  577. if ( !fEnable )
  578. ClearCrackDisplay();
  579. m_cbutton_grp_issuer.EnableWindow( fEnable );
  580. m_cbutton_grp_issuedto.EnableWindow( fEnable );
  581. }
  582. //---------------------------------------------------------------------------
  583. BOOL CMap11Page::FReadMappings()
  584. {
  585. BOOL f;
  586. C11Mapping* pMap;
  587. DWORD cbData;
  588. PVOID pData;
  589. DWORD fEnabled;
  590. CString sz;
  591. BOOL fRet = TRUE;
  592. // before messing with the metabase, prepare the strings we will need
  593. CString szBasePath = m_szMBPath + _T('/');
  594. CString szRelativePath = MB_EXTEND_KEY_MAPS;
  595. CString szObjectPath = m_szMBPath + _T('/') + szRelativePath;
  596. CString szMapPath;
  597. // prepare the metabase wrappers
  598. CWrapMetaBase mbWrap;
  599. f = mbWrap.FInit(m_pMB);
  600. // open the base object
  601. f = mbWrap.Open( szObjectPath, METADATA_PERMISSION_READ );
  602. ASSERT( f );
  603. if ( !f )
  604. {
  605. return FALSE;
  606. }
  607. // for now, at least, we are reading in all the mappings. reset the m_nNamer counter
  608. // so that we end up with a somewhat accurate reading of the last number-name in the list.
  609. m_MapsInMetabase = 0;
  610. // Loop the items in the metabase, adding each to the napper.
  611. DWORD index = 0;
  612. CString szEnum;
  613. while ( mbWrap.EnumObjects(_T(""), szEnum.GetBuffer(MAX_PATH*sizeof(WCHAR)),
  614. MAX_PATH*sizeof(WCHAR), index) )
  615. {
  616. szEnum.ReleaseBuffer();
  617. // keep track of the number of mappings we encounter
  618. m_MapsInMetabase++;
  619. // build the final mapping object path
  620. szMapPath.Format( _T("/%s"), szEnum );
  621. // make a new mapping object
  622. pMap = PNewMapping();
  623. if (pMap == NULL) {
  624. SetLastError(E_OUTOFMEMORY);
  625. fRet = FALSE;
  626. break;
  627. }
  628. // install the object name into the mapping
  629. pMap->iMD = m_MapsInMetabase;
  630. // get the certificate
  631. pData = mbWrap.GetData( szMapPath, MD_MAPCERT, IIS_MD_UT_SERVER, BINARY_METADATA, &cbData );
  632. if ( pData )
  633. {
  634. // set the data into place
  635. pMap->SetCertificate( (PUCHAR)pData, cbData );
  636. // free the buffer
  637. mbWrap.FreeWrapData( pData );
  638. }
  639. // get the NT Account - a string
  640. cbData = METADATA_MAX_NAME_LEN;
  641. if ( Get11String( &mbWrap, szMapPath, MD_MAPNTACCT, sz) )
  642. {
  643. pMap->SetNTAccount( sz );
  644. }
  645. // get the NT Password
  646. cbData = METADATA_MAX_NAME_LEN;
  647. if ( Get11String( &mbWrap, szMapPath, MD_MAPNTPWD, sz) )
  648. {
  649. pMap->SetNTPassword( sz );
  650. }
  651. // get the Enabled flag
  652. if ( mbWrap.GetDword( szMapPath, MD_MAPENABLED, IIS_MD_UT_SERVER, &fEnabled) )
  653. pMap->SetMapEnabled( (fEnabled > 0) );
  654. // get the mapping name
  655. cbData = METADATA_MAX_NAME_LEN;
  656. if ( Get11String( &mbWrap, szMapPath, MD_MAPNAME, sz) )
  657. {
  658. pMap->SetMapName( sz );
  659. }
  660. // add the mapping to the list
  661. FAddMappingToList( pMap );
  662. // increment the index
  663. index++;
  664. }
  665. szEnum.ReleaseBuffer();
  666. // close the mapping object
  667. mbWrap.Close();
  668. // return success
  669. return fRet;
  670. }
  671. //---------------------------------------------------------------------------
  672. // IMPORTANT: There is a bug in the mapping namespace extension where, even
  673. // though we are using the unicode metabase interface, all the strings are
  674. // expected to be ansi. This means that we cannont use the wrapmb getstring
  675. // and setstring calls with regards to the nsmp extetention. That is why
  676. // there are these two string wrapper classes that
  677. // also, all the strings used here are IIS_MD_UT_SERVER, so we can elimiate that parameter.
  678. BOOL CMap11Page::Get11String(CWrapMetaBase* pmb, LPCTSTR pszPath, DWORD dwPropID, CString& sz)
  679. {
  680. DWORD dwcb;
  681. BOOL fAnswer = FALSE;
  682. // get the string using the self-allocating get data process
  683. // that that it is cast as ANSI so the sz gets it right.
  684. // NOTE: This must be gotten as an ANSI string!
  685. PCHAR pchar = (PCHAR)pmb->GetData( pszPath, dwPropID, IIS_MD_UT_SERVER, STRING_METADATA, &dwcb );
  686. if ( pchar )
  687. {
  688. // set the answer
  689. sz = pchar;
  690. fAnswer = TRUE;
  691. // clean up
  692. pmb->FreeWrapData( pchar );
  693. }
  694. // return the answer
  695. return fAnswer;
  696. }
  697. //---------------------------------------------------------------------------
  698. /* INTRINSA suppress=null_pointers, uninitialized */
  699. BOOL CMap11Page::Set11String(CWrapMetaBase* pmb, LPCTSTR pszPath, DWORD dwPropID, CString& sz, DWORD dwFlags )
  700. {
  701. USES_CONVERSION;
  702. // Easy. Just set it as data
  703. // Make sure it is set back as an ANSI string though
  704. LPSTR pA = T2A((LPTSTR)(LPCTSTR)sz);
  705. return pmb->SetData( pszPath, dwPropID, IIS_MD_UT_SERVER, STRING_METADATA,
  706. (PVOID)pA, strlen(pA)+1, dwFlags );
  707. }
  708. //---------------------------------------------------------------------------
  709. // we only need to write out the mappings that have been either changed or added.
  710. // Thoughts on further optimizations: The bare minimum info about where to find
  711. // a mapping in the metabase could be stored in the metabase. Then, the mappings
  712. // would only be loaded when they were added to be edited or displayed in the
  713. // cracked list. The private data for each item in the list would have to have
  714. // some sort of reference to a position in the metabase.
  715. BOOL CMap11Page::FWriteMappings()
  716. {
  717. BOOL f;
  718. DWORD i,j;
  719. DWORD cMappings;
  720. C11Mapping* pMap;
  721. C11Mapping* pMapTemp;
  722. CString sz;
  723. DWORD dwEnabled;
  724. PUCHAR pCert;
  725. DWORD cbCert;
  726. DWORD iList;
  727. // before messing with the metabase, prepare the strings we will need
  728. CString szTempPath;
  729. CString szBasePath = m_szMBPath + _T("/Cert11");
  730. CString szRelativePath = _T("/Mappings");
  731. CString szObjectPath = szRelativePath + _T('/');
  732. // prepare the base metabase wrapper
  733. CWrapMetaBase mbBase;
  734. f = mbBase.FInit(m_pMB);
  735. if ( !f )
  736. {
  737. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  738. return FALSE;
  739. }
  740. // first, we have to open the Cert11 object. If it doesn't exist
  741. // then we have to add it tothe metabase
  742. if ( !mbBase.Open( szBasePath, METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE ) )
  743. {
  744. // Cert11 does not exist - open the namespace base and add it
  745. szTempPath = m_szMBPath + _T('/');
  746. if ( !mbBase.Open( szTempPath, METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE ) )
  747. {
  748. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  749. return FALSE; // serious problems if we can't open the base
  750. }
  751. // add the Cert11 object
  752. szTempPath = _T("Cert11");
  753. f = mbBase.AddObject( szTempPath );
  754. mbBase.Close();
  755. if ( !f )
  756. {
  757. AfxMessageBox( IDS_ERR_CANTADD );
  758. return FALSE;
  759. }
  760. // try again to open the Cert11. Fail if it doesn't work
  761. if ( !mbBase.Open( szBasePath, METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE ) )
  762. {
  763. AfxMessageBox( IDS_ERR_ACCESS_MAPPING );
  764. return FALSE;
  765. }
  766. }
  767. //==========
  768. // start by deleting all the mappings in the to-be-deleted list
  769. cMappings = (DWORD)m_rgbDelete.GetSize();
  770. // only bother if there are items waiting to be deleted
  771. if ( cMappings > 0 )
  772. {
  773. // get the count of mappings in the display list
  774. DWORD cList = m_clistctrl_list.GetItemCount();
  775. // sort the mappings, in decending order
  776. for ( i = 0; i < cMappings-1; i++ )
  777. {
  778. pMap = (C11Mapping*)m_rgbDelete[i];
  779. for ( j = i; j < cMappings; j++ )
  780. {
  781. pMapTemp = (C11Mapping*)m_rgbDelete[j];
  782. if ( pMap->iMD < pMapTemp->iMD )
  783. {
  784. m_rgbDelete.SetAt( i, (CObject*)pMapTemp );
  785. m_rgbDelete.SetAt( j, (CObject*)pMap );
  786. pMap = pMapTemp;
  787. }
  788. }
  789. }
  790. // loop the mappings, deleting each from the metabase
  791. for ( i = 0; i < cMappings; i++ )
  792. {
  793. // get the mapping object
  794. pMap = (C11Mapping*)m_rgbDelete[i];
  795. if ( !pMap || (pMap->iMD == NEW_OBJECT) )
  796. continue;
  797. // build the relative path to the object in question.
  798. szObjectPath.Format( _T("%s/%d"), szRelativePath, pMap->iMD );
  799. // delete that mapping's object from the metabase
  800. f = mbBase.DeleteObject( szObjectPath );
  801. // decrement the number of maps in the metabase
  802. m_MapsInMetabase--;
  803. // loop the items in the list, decrementing the index of those
  804. // that are above it. Yes - this is non-optimal, but its what
  805. // has to be done for now
  806. for ( iList = 0; iList < cList; iList++ )
  807. {
  808. pMapTemp = GetMappingInDisplay(iList);
  809. if ( (pMapTemp->iMD > pMap->iMD) && (pMapTemp->iMD != NEW_OBJECT) )
  810. pMapTemp->iMD--;
  811. }
  812. // since we will no longer be needing this mapping, delete it
  813. DeleteMapping( pMap );
  814. }
  815. // reset the to-be-deleted list
  816. m_rgbDelete.RemoveAll();
  817. }
  818. //==========
  819. // get the number mappings in the to-be-saved list
  820. cMappings = (DWORD)m_rgbSave.GetSize();
  821. // loop the mappings, adding each to the metabase
  822. for ( i = 0; i < cMappings; i++ )
  823. {
  824. // get the mapping object
  825. pMap = (C11Mapping*)m_rgbSave[i];
  826. ASSERT( pMap );
  827. // if the object is already in the metabase, just open it.
  828. if ( pMap->iMD != NEW_OBJECT )
  829. {
  830. // build the relative path to the object
  831. szObjectPath.Format( _T("%s/%d"), szRelativePath, pMap->iMD );
  832. }
  833. else
  834. {
  835. // set up the name of the new mapping as one higher
  836. // than the number of mappings in the metabase
  837. pMap->iMD = m_MapsInMetabase + 1;
  838. // build the relative path to the object
  839. szObjectPath.Format( _T("%s/%d"), szRelativePath, pMap->iMD );
  840. // add the mapping object to the base
  841. f = mbBase.AddObject( szObjectPath );
  842. if ( f )
  843. {
  844. // increment the number of maps in the metabase
  845. m_MapsInMetabase++;
  846. }
  847. }
  848. // write the object's parameters
  849. if ( f )
  850. {
  851. // save the certificate
  852. if ( pMap->GetCertificate(&pCert, &cbCert) )
  853. {
  854. // set the data into place in the object
  855. f = mbBase.SetData( szObjectPath, MD_MAPCERT, IIS_MD_UT_SERVER, BINARY_METADATA,
  856. pCert, cbCert, METADATA_SECURE | METADATA_INHERIT );
  857. }
  858. // save the NTAccount
  859. if ( pMap->GetNTAccount(sz) )
  860. {
  861. // set the data into place in the object
  862. f = Set11String(&mbBase, szObjectPath, MD_MAPNTACCT, sz, METADATA_SECURE);
  863. }
  864. // save the password - secure
  865. if ( pMap->GetNTPassword(sz) )
  866. {
  867. // set the data into place in the object
  868. f = Set11String(&mbBase, szObjectPath, MD_MAPNTPWD, sz, METADATA_SECURE);
  869. }
  870. // save the map's name
  871. if ( pMap->GetMapName(sz) )
  872. {
  873. // set the data into place in the object
  874. f = Set11String(&mbBase, szObjectPath, MD_MAPNAME, sz);
  875. }
  876. // save the Enabled flag
  877. // server reads the flag as the value of the dword
  878. if ( pMap->GetMapEnabled(&f) )
  879. {
  880. dwEnabled = (DWORD)f;
  881. f = mbBase.SetDword( szObjectPath, MD_MAPENABLED, IIS_MD_UT_SERVER, dwEnabled );
  882. }
  883. }
  884. }
  885. // close the base object
  886. mbBase.Close();
  887. // save the metabase
  888. mbBase.Save();
  889. // reset the to-be-saved list
  890. m_rgbSave.RemoveAll();
  891. // return success
  892. return TRUE;
  893. }
  894. //---------------------------------------------------------------------------
  895. C11Mapping* CMap11Page::PNewMapping()
  896. {
  897. // the way it should be
  898. return new C11Mapping();
  899. }
  900. //---------------------------------------------------------------------------
  901. void CMap11Page::DeleteMapping( C11Mapping* pMap )
  902. {
  903. // the way it should be
  904. delete pMap;
  905. }