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.

426 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 <schannel.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. CString csTempPassword;
  197. csTempPassword = m_pRule->GetRulePassword();
  198. m_sz_password = csTempPassword;
  199. // exchange the data
  200. UpdateData( FALSE );
  201. // return the answer
  202. return f;
  203. }
  204. //---------------------------------------------------------------------------
  205. // this is the part where we fill in most of the items
  206. void CEditWildcardRule::OnOK()
  207. {
  208. CERT_FIELD_ID id;
  209. CString szSub, sz;
  210. LPBYTE pbBin;
  211. DWORD cbBin;
  212. UINT cItems;
  213. UINT iItem;
  214. // update the data
  215. UpdateData( TRUE );
  216. //======== store the rule elements
  217. // start by resetting the entire rule - that way we don't have to
  218. // mess with individual elements in the list, allowing us to cancel.
  219. // But that is ok, because we can just spin through
  220. // the ones in the list very quickly and re-add them
  221. // remove the existing elements from the list.
  222. cItems = m_pRule->GetRuleElemCount();
  223. for ( iItem = 0; iItem < cItems; iItem++ )
  224. m_pRule->DeleteRuleElem( 0 );
  225. // add all the items in the list
  226. cItems = m_clistctrl_list.GetItemCount();
  227. for ( iItem = 0; iItem < cItems; iItem++ )
  228. {
  229. // prepare the field id
  230. id = (CERT_FIELD_ID)m_clistctrl_list.GetItemData( iItem );
  231. // prepare the subfield
  232. sz = m_clistctrl_list.GetItemText(iItem, COL_SUB_FIELD);
  233. szSub = MapSubFieldToAsn1( (PCHAR)(LPCSTR)sz );
  234. // prepare the data
  235. sz = m_clistctrl_list.GetItemText(iItem, COL_MATCH_CRITERIA);
  236. if ( !MatchRequestToBinary((PCHAR)(LPCSTR)sz, &pbBin, &cbBin) )
  237. continue;
  238. // add the element to the rule
  239. m_pRule->AddRuleElem( 0xffffffff, id, (PCHAR)(LPCSTR)szSub, pbBin, cbBin );
  240. // free the binary match data
  241. FreeMatchConversion( pbBin );
  242. }
  243. // set the easy data
  244. m_pRule->SetRuleName( (PCHAR)(LPCSTR)m_sz_description );
  245. m_pRule->SetRuleEnabled( m_bool_enable );
  246. // store the deny access radio buttons
  247. m_pRule->SetRuleDenyAccess( m_int_DenyAccess == ACCESS_DENY );
  248. // store the match issuer buttons
  249. m_pRule->SetMatchAllIssuer( m_int_MatchAllIssuers == MATCH_ISSUER_ALL );
  250. // we have to set the account name into place here
  251. m_pRule->SetRuleAccount( (PCHAR)(LPCSTR)m_sz_accountname );
  252. // store the password
  253. CString csTempPassword;
  254. m_sz_password.CopyTo(csTempPassword);
  255. m_pRule->SetRulePassword( (PCHAR)(LPCSTR)csTempPassword );
  256. // it is valid
  257. CNTBrowsingDialog::OnOK();
  258. }
  259. //---------------------------------------------------------------------------
  260. void CEditWildcardRule::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
  261. {
  262. *pResult = 0;
  263. // if something in the list was double clicked, edit it
  264. if ( m_clistctrl_list.GetSelectedCount() > 0 )
  265. OnEdit();
  266. }
  267. //---------------------------------------------------------------------------
  268. void CEditWildcardRule::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
  269. {
  270. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  271. *pResult = 0;
  272. // enable the correct items
  273. EnableDependantButtons();
  274. }
  275. //---------------------------------------------------------------------------
  276. void CEditWildcardRule::OnEdit()
  277. {
  278. ASSERT( m_clistctrl_list.GetSelectedCount() == 1 );
  279. DWORD iList;
  280. // get index of the selected list item
  281. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  282. ASSERT( iList >= 0 );
  283. // edit the item
  284. EditRule( iList );
  285. }
  286. //---------------------------------------------------------------------------
  287. // actually very similar to editing an existing element
  288. void CEditWildcardRule::OnNew()
  289. {
  290. // declare the editing dialog
  291. CEditRuleElement editDlg;
  292. // fill in its data
  293. editDlg.m_int_field = CERT_FIELD_SUBJECT;
  294. // editDlg.m_sz_subfield = MapAsn1ToSubField( "O" );
  295. editDlg.m_sz_subfield = "O";
  296. editDlg.m_sz_criteria.LoadString( IDS_WILDSTRING );
  297. // run the dialog
  298. if ( editDlg.DoModal() == IDOK )
  299. {
  300. // get the index for adding to the end of the list
  301. int iEnd = m_clistctrl_list.GetItemCount();
  302. // Start with the cert field
  303. CERT_FIELD_ID id = (CERT_FIELD_ID)editDlg.m_int_field;
  304. CString sz = MapIdToField( id );
  305. int i = m_clistctrl_list.InsertItem( iEnd, sz );
  306. m_clistctrl_list.SetItemData( i, id );
  307. m_clistctrl_list.SetItemText( i, COL_SUB_FIELD, editDlg.m_sz_subfield );
  308. m_clistctrl_list.SetItemText( i, COL_MATCH_CRITERIA, editDlg.m_sz_criteria );
  309. }
  310. }
  311. //---------------------------------------------------------------------------
  312. void CEditWildcardRule::OnDelete()
  313. {
  314. ASSERT( m_clistctrl_list.GetSelectedCount() == 1 );
  315. DWORD iList;
  316. // get index of the selected list item
  317. iList = m_clistctrl_list.GetNextItem( -1, LVNI_SELECTED );
  318. ASSERT( iList >= 0 );
  319. // delete the item from the display list
  320. m_clistctrl_list.DeleteItem ( iList );
  321. }
  322. //---------------------------------------------------------------------------
  323. // simple - just run the issuer dialog
  324. void CEditWildcardRule::OnSelectIssuer()
  325. {
  326. CSelectIssuersDlg dlg(m_pMB);
  327. // prep the dialog
  328. dlg.m_pRule = m_pRule;
  329. dlg.m_szMBPath = m_szMBPath;
  330. dlg.m_sz_caption.LoadString( IDS_MATCH_ON_ISSUERS );
  331. // run it
  332. if ( dlg.DoModal() == IDOK )
  333. {
  334. UpdateData( TRUE );
  335. m_int_MatchAllIssuers = MATCH_ISSUER_SOME;
  336. UpdateData( FALSE );
  337. }
  338. }