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.

1457 lines
48 KiB

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