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.

423 lines
13 KiB

  1. // EdWldRul.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <iadmw.h>
  5. #include "ListRow.h"
  6. #include "ChkLstCt.h"
  7. extern "C"
  8. {
  9. #include <wincrypt.h>
  10. #include <sslsp.h>
  11. }
  12. #include "Iismap.hxx"
  13. #include "Iiscmr.hxx"
  14. #include "brwsdlg.h"
  15. #include "certmap.h"
  16. #include "EdWldRul.h"
  17. #include "EdtRulEl.h"
  18. #include "IssueDlg.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. #define ACCESS_DENY 0
  25. #define ACCESS_ACCEPT 1
  26. #define MATCH_ISSUER_ALL 0
  27. #define MATCH_ISSUER_SOME 1
  28. #define COL_CERT_FIELD 0
  29. #define COL_SUB_FIELD 1
  30. #define COL_MATCH_CRITERIA 2
  31. // notes on the list:
  32. // the list is the only source of current data for the rule elements. The actual
  33. // rule object is not updated with changes in the list until the user hits IDOK.
  34. // that way we can cancel without changing the object. All mapping between the
  35. // text in the list and the binary formats used by the server are done at the
  36. // beginning and end of the dialog
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CEditWildcardRule dialog
  39. //---------------------------------------------------------------------------
  40. CEditWildcardRule::CEditWildcardRule(IMSAdminBase* pMB, CWnd* pParent /*=NULL*/)
  41. : CNTBrowsingDialog(CEditWildcardRule::IDD, pParent),
  42. m_pMB(pMB)
  43. {
  44. //{{AFX_DATA_INIT(CEditWildcardRule)
  45. m_sz_description = _T("");
  46. m_bool_enable = FALSE;
  47. m_int_MatchAllIssuers = -1;
  48. m_int_DenyAccess = -1;
  49. //}}AFX_DATA_INIT
  50. }
  51. //---------------------------------------------------------------------------
  52. void CEditWildcardRule::DoDataExchange(CDataExchange* pDX)
  53. {
  54. CNTBrowsingDialog::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(CEditWildcardRule)
  56. DDX_Control(pDX, IDC_EDIT, m_cbutton_edit);
  57. DDX_Control(pDX, IDC_DELETE, m_cbutton_delete);
  58. DDX_Control(pDX, IDC_NEW, m_cbutton_new);
  59. DDX_Control(pDX, IDC_LIST, m_clistctrl_list);
  60. DDX_Text(pDX, IDC_DESCRIPTION, m_sz_description);
  61. DDX_Check(pDX, IDC_ENABLE_RULE, m_bool_enable);
  62. DDX_Radio(pDX, IDC_ALL_ISSUERS, m_int_MatchAllIssuers);
  63. DDX_Radio(pDX, IDC_REFUSE_LOGON, m_int_DenyAccess);
  64. //}}AFX_DATA_MAP
  65. }
  66. //---------------------------------------------------------------------------
  67. BEGIN_MESSAGE_MAP(CEditWildcardRule, CNTBrowsingDialog)
  68. //{{AFX_MSG_MAP(CEditWildcardRule)
  69. ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
  70. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnItemchangedList)
  71. ON_BN_CLICKED(IDC_EDIT, OnEdit)
  72. ON_BN_CLICKED(IDC_NEW, OnNew)
  73. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  74. ON_BN_CLICKED(IDC_SELECT_ISSUER, OnSelectIssuer)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. //---------------------------------------------------------------------------
  78. BOOL CEditWildcardRule::FInitRulesList()
  79. {
  80. CString sz;
  81. int i;
  82. // setup the main field
  83. sz.LoadString( IDS_CERT_FIELD );
  84. i = m_clistctrl_list.InsertColumn( COL_CERT_FIELD, sz, LVCFMT_LEFT, 100 );
  85. // setup the sub field
  86. sz.LoadString( IDS_SUB_FIELD );
  87. i = m_clistctrl_list.InsertColumn( COL_SUB_FIELD, sz, LVCFMT_LEFT, 70 );
  88. // setup the match criteria column
  89. sz.LoadString( IDS_MATCH_CRITERIA );
  90. i = m_clistctrl_list.InsertColumn( COL_MATCH_CRITERIA, sz, LVCFMT_LEFT, 255 );
  91. return TRUE;
  92. }
  93. //---------------------------------------------------------------------------
  94. BOOL CEditWildcardRule::FillRulesList()
  95. {
  96. CERT_FIELD_ID idCertField;
  97. LPBYTE pContent;
  98. DWORD cbContent;
  99. LPSTR psz;
  100. CString sz;
  101. int i;
  102. // get the number of subfield rules
  103. DWORD cbRules = m_pRule->GetRuleElemCount();
  104. // loop the elements, adding each to the list
  105. for ( DWORD j = 0; j < cbRules; j++ )
  106. {
  107. // get the raw data for the rule element
  108. if ( !m_pRule->GetRuleElem( j, &idCertField, (PCHAR*)&pContent, &cbContent, &psz ) )
  109. continue; // the call failed - try the next
  110. // start converting the data into readable form and adding it to the list
  111. sz = MapIdToField( idCertField );
  112. // create the new entry in the list box.
  113. i = m_clistctrl_list.InsertItem( j, sz );
  114. // add the subfield data
  115. sz = MapAsn1ToSubField( psz );
  116. m_clistctrl_list.SetItemText( i, COL_SUB_FIELD, sz );
  117. // add the content data - reuse the psz pointer
  118. if ( BinaryToMatchRequest( pContent, cbContent, &psz ) )
  119. m_clistctrl_list.SetItemText( i, COL_MATCH_CRITERIA, psz );
  120. // finally, attach the id cert field as user data to the item
  121. m_clistctrl_list.SetItemData( i, idCertField );
  122. }
  123. return TRUE;
  124. }
  125. // editing and updating
  126. //---------------------------------------------------------------------------
  127. void CEditWildcardRule::EnableDependantButtons()
  128. {
  129. // the whole purpose of this routine is to gray or activate
  130. // the edit and delete buttons depending on whether or not anything
  131. // is selected. So start by getting the selection count
  132. UINT cItemsSel = m_clistctrl_list.GetSelectedCount();
  133. if ( cItemsSel > 0 )
  134. {
  135. // there are items selected
  136. m_cbutton_edit.EnableWindow( TRUE );
  137. m_cbutton_delete.EnableWindow( TRUE );
  138. }
  139. else
  140. {
  141. // nope. Nothing selected
  142. m_cbutton_edit.EnableWindow( FALSE );
  143. m_cbutton_delete.EnableWindow( FALSE );
  144. }
  145. // always enable the new button
  146. m_cbutton_new.EnableWindow( TRUE );
  147. }
  148. //---------------------------------------------------------------------------
  149. BOOL CEditWildcardRule::EditRule( DWORD iList )
  150. {
  151. // declare the editing dialog
  152. CEditRuleElement editDlg;
  153. // fill in its data
  154. editDlg.m_int_field = m_clistctrl_list.GetItemData( iList );
  155. editDlg.m_sz_subfield = m_clistctrl_list.GetItemText( iList, COL_SUB_FIELD );
  156. editDlg.m_sz_criteria = m_clistctrl_list.GetItemText( iList, COL_MATCH_CRITERIA );
  157. // run the dialog
  158. if ( editDlg.DoModal() == IDOK )
  159. {
  160. // must convert the field into a string too
  161. CERT_FIELD_ID id = (CERT_FIELD_ID)editDlg.m_int_field;
  162. CString sz = MapIdToField( id );
  163. m_clistctrl_list.SetItemText( iList, COL_CERT_FIELD, sz );
  164. m_clistctrl_list.SetItemData( iList, id );
  165. m_clistctrl_list.SetItemText( iList, COL_SUB_FIELD, editDlg.m_sz_subfield );
  166. m_clistctrl_list.SetItemText( iList, COL_MATCH_CRITERIA, editDlg.m_sz_criteria );
  167. }
  168. return TRUE;
  169. }
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CEditWildcardRule message handlers
  172. //---------------------------------------------------------------------------
  173. BOOL CEditWildcardRule::OnInitDialog()
  174. {
  175. // call the parental oninitdialog
  176. BOOL f = CNTBrowsingDialog::OnInitDialog();
  177. // set the easy default strings
  178. m_sz_accountname = m_pRule->GetRuleAccount(); // managed by CNTBrowsingDialog from here on
  179. m_sz_description = m_pRule->GetRuleName();
  180. m_bool_enable = m_pRule->GetRuleEnabled();
  181. // set up the deny access radio buttons
  182. if ( m_pRule->GetRuleDenyAccess() )
  183. m_int_DenyAccess = ACCESS_DENY;
  184. else
  185. m_int_DenyAccess = ACCESS_ACCEPT;
  186. // set up the match issuer buttons
  187. if ( m_pRule->GetMatchAllIssuer() )
  188. m_int_MatchAllIssuers = MATCH_ISSUER_ALL;
  189. else
  190. m_int_MatchAllIssuers = MATCH_ISSUER_SOME;
  191. // initialize the list
  192. FInitRulesList();
  193. FillRulesList();
  194. EnableDependantButtons();
  195. // initialize the password
  196. m_sz_password = m_pRule->GetRulePassword();
  197. // exchange the data
  198. UpdateData( FALSE );
  199. // return the answer
  200. return f;
  201. }
  202. //---------------------------------------------------------------------------
  203. // this is the part where we fill in most of the items
  204. void CEditWildcardRule::OnOK()
  205. {
  206. CERT_FIELD_ID id;
  207. CString szSub, sz;
  208. LPBYTE pbBin;
  209. DWORD cbBin;
  210. UINT cItems;
  211. UINT iItem;
  212. // update the data
  213. UpdateData( TRUE );
  214. //======== store the rule elements
  215. // start by resetting the entire rule - that way we don't have to
  216. // mess with individual elements in the list, allowing us to cancel.
  217. // But that is ok, because we can just spin through
  218. // the ones in the list very quickly and re-add them
  219. // remove the existing elements from the list.
  220. cItems = m_pRule->GetRuleElemCount();
  221. for ( iItem = 0; iItem < cItems; iItem++ )
  222. m_pRule->DeleteRuleElem( 0 );
  223. // add all the items in the list
  224. cItems = m_clistctrl_list.GetItemCount();
  225. for ( iItem = 0; iItem < cItems; iItem++ )
  226. {
  227. // prepare the field id
  228. id = (CERT_FIELD_ID)m_clistctrl_list.GetItemData( iItem );
  229. // prepare the subfield
  230. sz = m_clistctrl_list.GetItemText(iItem, COL_SUB_FIELD);
  231. szSub = MapSubFieldToAsn1( (PCHAR)(LPCSTR)sz );
  232. // prepare the data
  233. sz = m_clistctrl_list.GetItemText(iItem, COL_MATCH_CRITERIA);
  234. if ( !MatchRequestToBinary((PCHAR)(LPCSTR)sz, &pbBin, &cbBin) )
  235. continue;
  236. // add the element to the rule
  237. m_pRule->AddRuleElem( 0xffffffff, id, (PCHAR)(LPCSTR)szSub, pbBin, cbBin );
  238. // free the binary match data
  239. FreeMatchConversion( pbBin );
  240. }
  241. // set the easy data
  242. m_pRule->SetRuleName( (PCHAR)(LPCSTR)m_sz_description );
  243. m_pRule->SetRuleEnabled( m_bool_enable );
  244. // store the deny access radio buttons
  245. m_pRule->SetRuleDenyAccess( m_int_DenyAccess == ACCESS_DENY );
  246. // store the match issuer buttons
  247. m_pRule->SetMatchAllIssuer( m_int_MatchAllIssuers == MATCH_ISSUER_ALL );
  248. // we have to set the account name into place here
  249. m_pRule->SetRuleAccount( (PCHAR)(LPCSTR)m_sz_accountname );
  250. // store the password
  251. m_pRule->SetRulePassword( (PCHAR)(LPCSTR)m_sz_password );
  252. // it is valid
  253. CNTBrowsingDialog::OnOK();
  254. }
  255. //---------------------------------------------------------------------------
  256. void CEditWildcardRule::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
  257. {
  258. *pResult = 0;
  259. // if something in the list was double clicked, edit it
  260. if ( m_clistctrl_list.GetSelectedCount() > 0 )
  261. OnEdit();
  262. }
  263. //---------------------------------------------------------------------------
  264. void CEditWildcardRule::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
  265. {
  266. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  267. *pResult = 0;
  268. // enable the correct items
  269. EnableDependantButtons();
  270. }
  271. //---------------------------------------------------------------------------
  272. void CEditWildcardRule::OnEdit()
  273. {
  274. ASSERT( m_clistctrl_list.GetSelectedCount() == 1 );
  275. DWORD iList;
  276. // get index of the selected list item
  277. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  278. ASSERT( iList >= 0 );
  279. // edit the item
  280. EditRule( iList );
  281. }
  282. //---------------------------------------------------------------------------
  283. // actually very similar to editing an existing element
  284. void CEditWildcardRule::OnNew()
  285. {
  286. // declare the editing dialog
  287. CEditRuleElement editDlg;
  288. // fill in its data
  289. editDlg.m_int_field = CERT_FIELD_SUBJECT;
  290. // editDlg.m_sz_subfield = MapAsn1ToSubField( "O" );
  291. editDlg.m_sz_subfield = "O";
  292. editDlg.m_sz_criteria.LoadString( IDS_WILDSTRING );
  293. // run the dialog
  294. if ( editDlg.DoModal() == IDOK )
  295. {
  296. // get the index for adding to the end of the list
  297. int iEnd = m_clistctrl_list.GetItemCount();
  298. // Start with the cert field
  299. CERT_FIELD_ID id = (CERT_FIELD_ID)editDlg.m_int_field;
  300. CString sz = MapIdToField( id );
  301. int i = m_clistctrl_list.InsertItem( iEnd, sz );
  302. m_clistctrl_list.SetItemData( i, id );
  303. m_clistctrl_list.SetItemText( i, COL_SUB_FIELD, editDlg.m_sz_subfield );
  304. m_clistctrl_list.SetItemText( i, COL_MATCH_CRITERIA, editDlg.m_sz_criteria );
  305. }
  306. }
  307. //---------------------------------------------------------------------------
  308. void CEditWildcardRule::OnDelete()
  309. {
  310. ASSERT( m_clistctrl_list.GetSelectedCount() == 1 );
  311. DWORD iList;
  312. // get index of the selected list item
  313. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  314. ASSERT( iList >= 0 );
  315. // delete the item from the display list
  316. m_clistctrl_list.DeleteItem ( iList );
  317. }
  318. //---------------------------------------------------------------------------
  319. // simple - just run the issuer dialog
  320. void CEditWildcardRule::OnSelectIssuer()
  321. {
  322. CSelectIssuersDlg dlg(m_pMB);
  323. // prep the dialog
  324. dlg.m_pRule = m_pRule;
  325. dlg.m_szMBPath = m_szMBPath;
  326. dlg.m_sz_caption.LoadString( IDS_MATCH_ON_ISSUERS );
  327. // run it
  328. if ( dlg.DoModal() == IDOK )
  329. {
  330. UpdateData( TRUE );
  331. m_int_MatchAllIssuers = MATCH_ISSUER_SOME;
  332. UpdateData( FALSE );
  333. }
  334. }