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.

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