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.

399 lines
12 KiB

  1. // WWzTwo.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <iadmw.h>
  5. #include "certmap.h"
  6. #include "ListRow.h"
  7. #include "ChkLstCt.h"
  8. extern "C"
  9. {
  10. #include <wincrypt.h>
  11. #include <sslsp.h>
  12. }
  13. #include "Iismap.hxx"
  14. #include "Iiscmr.hxx"
  15. #include "brwsdlg.h"
  16. #include "EdWldRul.h"
  17. #include "EdtRulEl.h"
  18. #include "WWzTwo.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. #define COL_CERT_FIELD 0
  25. #define COL_SUB_FIELD 1
  26. #define COL_MATCH_CRITERIA 2
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CWildWizTwo property page
  29. IMPLEMENT_DYNCREATE(CWildWizTwo, CPropertyPage)
  30. CWildWizTwo::CWildWizTwo() : CPropertyPage(CWildWizTwo::IDD)
  31. {
  32. //{{AFX_DATA_INIT(CWildWizTwo)
  33. //}}AFX_DATA_INIT
  34. }
  35. CWildWizTwo::~CWildWizTwo()
  36. {
  37. }
  38. void CWildWizTwo::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CPropertyPage::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CWildWizTwo)
  42. DDX_Control(pDX, IDC_LIST, m_clistctrl_list);
  43. DDX_Control(pDX, IDC_NEW, m_cbutton_new);
  44. DDX_Control(pDX, IDC_EDIT, m_cbutton_edit);
  45. DDX_Control(pDX, IDC_DELETE, m_cbutton_delete);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CWildWizTwo, CPropertyPage)
  49. //{{AFX_MSG_MAP(CWildWizTwo)
  50. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  51. ON_BN_CLICKED(IDC_EDIT, OnEdit)
  52. ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
  53. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnItemchangedList)
  54. ON_BN_CLICKED(IDC_NEW, OnNew)
  55. //}}AFX_MSG_MAP
  56. ON_COMMAND(ID_HELP_FINDER, DoHelp)
  57. ON_COMMAND(ID_HELP, DoHelp)
  58. ON_COMMAND(ID_CONTEXT_HELP, DoHelp)
  59. ON_COMMAND(ID_DEFAULT_HELP, DoHelp)
  60. END_MESSAGE_MAP()
  61. //---------------------------------------------------------------------------
  62. void CWildWizTwo::DoHelp()
  63. {
  64. WinHelp( HIDD_CERTMAP_ADV_RUL_RULES );
  65. }
  66. //---------------------------------------------------------------------------
  67. BOOL CWildWizTwo::FInitRulesList()
  68. {
  69. CString sz;
  70. int i;
  71. // setup the main field
  72. sz.LoadString( IDS_CERT_FIELD );
  73. i = m_clistctrl_list.InsertColumn( COL_CERT_FIELD, sz, LVCFMT_LEFT, 100 );
  74. // setup the sub field
  75. sz.LoadString( IDS_SUB_FIELD );
  76. i = m_clistctrl_list.InsertColumn( COL_SUB_FIELD, sz, LVCFMT_LEFT, 70 );
  77. // setup the match criteria column
  78. sz.LoadString( IDS_MATCH_CRITERIA );
  79. i = m_clistctrl_list.InsertColumn( COL_MATCH_CRITERIA, sz, LVCFMT_LEFT, 226 );
  80. return TRUE;
  81. }
  82. //---------------------------------------------------------------------------
  83. BOOL CWildWizTwo::FillRulesList()
  84. {
  85. CERT_FIELD_ID idCertField;
  86. LPBYTE pContent;
  87. DWORD cbContent;
  88. LPSTR psz;
  89. DWORD flags;
  90. CString sz;
  91. int i;
  92. //
  93. // UNICODE/ANSI conversion -- RonaldM
  94. //
  95. USES_CONVERSION;
  96. // get the number of subfield rules
  97. DWORD cbRules = m_pRule->GetRuleElemCount();
  98. // loop the elements, adding each to the list
  99. for ( DWORD j = 0; j < cbRules; j++ )
  100. {
  101. // get the raw data for the rule element
  102. if ( !m_pRule->GetRuleElem( j, &idCertField, (PCHAR*)&pContent, &cbContent, &psz, &flags ) )
  103. continue; // the call failed - try the next
  104. // start converting the data into readable form and adding it to the list
  105. sz = MapIdToField( idCertField );
  106. // create the new entry in the list box.
  107. i = m_clistctrl_list.InsertItem( j, sz );
  108. // add the subfield data
  109. sz = MapAsn1ToSubField( psz );
  110. m_clistctrl_list.SetItemText( i, COL_SUB_FIELD, sz );
  111. // add the content data - reuse the psz pointer
  112. if ( BinaryToMatchRequest( pContent, cbContent, &psz ) )
  113. m_clistctrl_list.SetItemText( i, COL_MATCH_CRITERIA, A2T(psz) );
  114. // finally, attach the id cert field as user data to the item
  115. DWORD dw;
  116. BOOL fMatchCapitalization = !(flags & CMR_FLAGS_CASE_INSENSITIVE);
  117. dw = ( (fMatchCapitalization << 16) | idCertField );
  118. m_clistctrl_list.SetItemData( i, dw );
  119. }
  120. return TRUE;
  121. }
  122. //CMR_FLAGS_CASE_INSENSITIVE
  123. // editing and updating
  124. //---------------------------------------------------------------------------
  125. void CWildWizTwo::EnableDependantButtons()
  126. {
  127. // the whole purpose of this routine is to gray or activate
  128. // the edit and delete buttons depending on whether or not anything
  129. // is selected. So start by getting the selection count
  130. UINT cItemsSel = m_clistctrl_list.GetSelectedCount();
  131. if ( cItemsSel > 0 )
  132. {
  133. // there are items selected
  134. m_cbutton_edit.EnableWindow( TRUE );
  135. m_cbutton_delete.EnableWindow( TRUE );
  136. }
  137. else
  138. {
  139. // nope. Nothing selected
  140. m_cbutton_edit.EnableWindow( FALSE );
  141. m_cbutton_delete.EnableWindow( FALSE );
  142. }
  143. // always enable the new button
  144. m_cbutton_new.EnableWindow( TRUE );
  145. }
  146. //---------------------------------------------------------------------------
  147. BOOL CWildWizTwo::EditRule( DWORD iList )
  148. {
  149. // declare the editing dialog
  150. CEditRuleElement editDlg;
  151. DWORD dw;
  152. // fill in its data
  153. // IA64 - OK to cast as the data really is just a DWORD
  154. dw = (DWORD)m_clistctrl_list.GetItemData( iList );
  155. editDlg.m_bool_match_case = HIWORD( dw );
  156. editDlg.m_int_field = LOWORD( dw );
  157. editDlg.m_sz_subfield = m_clistctrl_list.GetItemText( iList, COL_SUB_FIELD );
  158. editDlg.m_sz_criteria = m_clistctrl_list.GetItemText( iList, COL_MATCH_CRITERIA );
  159. // run the dialog
  160. if ( editDlg.DoModal() == IDOK )
  161. {
  162. // must convert the field into a string too
  163. CERT_FIELD_ID id = (CERT_FIELD_ID)editDlg.m_int_field;
  164. CString sz = MapIdToField( id );
  165. m_clistctrl_list.SetItemText( iList, COL_CERT_FIELD, sz );
  166. dw = ( (editDlg.m_bool_match_case << 16) | id);
  167. m_clistctrl_list.SetItemData( iList, dw );
  168. m_clistctrl_list.SetItemText( iList, COL_SUB_FIELD, editDlg.m_sz_subfield );
  169. m_clistctrl_list.SetItemText( iList, COL_MATCH_CRITERIA, editDlg.m_sz_criteria );
  170. // we can now apply
  171. SetModified();
  172. }
  173. return TRUE;
  174. }
  175. /////////////////////////////////////////////////////////////////////////////
  176. // CWildWizTwo message handlers
  177. //---------------------------------------------------------------------------
  178. BOOL CWildWizTwo::OnInitDialog()
  179. {
  180. // call the parental oninitdialog
  181. BOOL f = CPropertyPage::OnInitDialog();
  182. // initialize the list
  183. FInitRulesList();
  184. FillRulesList();
  185. EnableDependantButtons();
  186. // return the answer
  187. return f;
  188. }
  189. //---------------------------------------------------------------------------
  190. BOOL CWildWizTwo::OnWizardFinish()
  191. {
  192. return OnApply();
  193. }
  194. //---------------------------------------------------------------------------
  195. BOOL CWildWizTwo::OnApply()
  196. {
  197. CERT_FIELD_ID id;
  198. CString szSub, sz;
  199. LPBYTE pbBin;
  200. DWORD cbBin;
  201. UINT cItems;
  202. UINT iItem;
  203. USES_CONVERSION;
  204. // update the data
  205. UpdateData( TRUE );
  206. //======== store the rule elements
  207. // start by resetting the entire rule - that way we don't have to
  208. // mess with individual elements in the list, allowing us to cancel.
  209. // But that is ok, because we can just spin through
  210. // the ones in the list very quickly and re-add them
  211. // remove the existing elements from the list.
  212. cItems = m_pRule->GetRuleElemCount();
  213. for ( iItem = 0; iItem < cItems; iItem++ )
  214. m_pRule->DeleteRuleElem( 0 );
  215. // add all the items in the list
  216. cItems = m_clistctrl_list.GetItemCount();
  217. for ( iItem = 0; iItem < cItems; iItem++ )
  218. {
  219. // prepare the field id
  220. id = (CERT_FIELD_ID)LOWORD(m_clistctrl_list.GetItemData( iItem ));
  221. // prepare the caps flag
  222. BOOL fCaps = HIWORD(m_clistctrl_list.GetItemData( iItem ));
  223. DWORD flags = 0;
  224. if ( !fCaps )
  225. flags = CMR_FLAGS_CASE_INSENSITIVE;
  226. // prepare the subfield
  227. sz = m_clistctrl_list.GetItemText(iItem, COL_SUB_FIELD);
  228. LPSTR szA = T2A((LPTSTR)(LPCTSTR)sz);
  229. szSub = MapSubFieldToAsn1( szA );
  230. // prepare the data
  231. sz = m_clistctrl_list.GetItemText(iItem, COL_MATCH_CRITERIA);
  232. szA = T2A((LPTSTR)(LPCTSTR)sz);
  233. if ( !MatchRequestToBinary( szA, &pbBin, &cbBin) )
  234. continue;
  235. // add the element to the rule
  236. m_pRule->AddRuleElem( 0xffffffff, id, T2A((LPTSTR)(LPCTSTR)szSub), pbBin, cbBin, flags );
  237. // free the binary match data
  238. FreeMatchConversion( pbBin );
  239. }
  240. // return success
  241. SetModified( FALSE );
  242. return TRUE;
  243. }
  244. //---------------------------------------------------------------------------
  245. void CWildWizTwo::OnDelete()
  246. {
  247. ASSERT( m_clistctrl_list.GetSelectedCount() == 1 );
  248. DWORD iList;
  249. // get index of the selected list item
  250. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  251. ASSERT( iList >= 0 );
  252. // delete the item from the display list
  253. m_clistctrl_list.DeleteItem ( iList );
  254. // we can now apply
  255. SetModified();
  256. }
  257. //---------------------------------------------------------------------------
  258. void CWildWizTwo::OnEdit()
  259. {
  260. ASSERT( m_clistctrl_list.GetSelectedCount() == 1 );
  261. DWORD iList;
  262. // get index of the selected list item
  263. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  264. ASSERT( iList >= 0 );
  265. // edit the item
  266. EditRule( iList );
  267. }
  268. //---------------------------------------------------------------------------
  269. void CWildWizTwo::OnNew()
  270. {
  271. // declare the editing dialog
  272. CEditRuleElement editDlg;
  273. // fill in its data
  274. editDlg.m_bool_match_case = TRUE;
  275. editDlg.m_int_field = CERT_FIELD_SUBJECT;
  276. editDlg.m_sz_subfield = "O";
  277. editDlg.m_sz_criteria.LoadString( IDS_WILDSTRING );
  278. // run the dialog
  279. if ( editDlg.DoModal() == IDOK )
  280. {
  281. // get the index for adding to the end of the list
  282. int iEnd = m_clistctrl_list.GetItemCount();
  283. // Start with the cert field
  284. CERT_FIELD_ID id = (CERT_FIELD_ID)editDlg.m_int_field;
  285. CString sz = MapIdToField( id );
  286. int i = m_clistctrl_list.InsertItem( iEnd, sz );
  287. DWORD dw = ( (editDlg.m_bool_match_case << 16) | id);
  288. m_clistctrl_list.SetItemData( i, dw );
  289. // m_clistctrl_list.SetItemData( i, id );
  290. m_clistctrl_list.SetItemText( i, COL_SUB_FIELD, editDlg.m_sz_subfield );
  291. m_clistctrl_list.SetItemText( i, COL_MATCH_CRITERIA, editDlg.m_sz_criteria );
  292. // we can now apply
  293. SetModified();
  294. }
  295. }
  296. //---------------------------------------------------------------------------
  297. void CWildWizTwo::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
  298. {
  299. *pResult = 0;
  300. // if something in the list was double clicked, edit it
  301. if ( m_clistctrl_list.GetSelectedCount() > 0 )
  302. OnEdit();
  303. }
  304. //---------------------------------------------------------------------------
  305. void CWildWizTwo::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
  306. {
  307. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  308. *pResult = 0;
  309. // enable the correct items
  310. EnableDependantButtons();
  311. }
  312. //---------------------------------------------------------------------------
  313. BOOL CWildWizTwo::OnSetActive()
  314. {
  315. // if this is a wizard, gray out the back button
  316. if ( m_fIsWizard )
  317. m_pPropSheet->SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );
  318. return CPropertyPage::OnSetActive();
  319. }