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.

349 lines
9.8 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001.
  5. //
  6. // File: NewIssuanceOIDDlg.cpp
  7. //
  8. // Contents: Implementation of CNewIssuanceOIDDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. // NewIssuanceOIDDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "NewIssuanceOIDDlg.h"
  15. #include "PolicyOID.h"
  16. extern POLICY_OID_LIST g_policyOIDList;
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CNewIssuanceOIDDlg dialog
  24. CNewIssuanceOIDDlg::CNewIssuanceOIDDlg(CWnd* pParent)
  25. : CHelpDialog(CNewIssuanceOIDDlg::IDD, pParent),
  26. m_bEdit (false),
  27. m_bDirty (false)
  28. {
  29. //{{AFX_DATA_INIT(CNewIssuanceOIDDlg)
  30. m_oidFriendlyName = _T("");
  31. m_oidValue = _T("");
  32. m_CPSValue = _T("");
  33. //}}AFX_DATA_INIT
  34. }
  35. CNewIssuanceOIDDlg::CNewIssuanceOIDDlg(CWnd* pParent,
  36. const CString& szDisplayName,
  37. const CString& szOID,
  38. const CString& szCPS)
  39. : CHelpDialog(CNewIssuanceOIDDlg::IDD, pParent),
  40. m_bEdit (true),
  41. m_bDirty (false),
  42. m_originalOidFriendlyName (szDisplayName),
  43. m_oidFriendlyName (szDisplayName),
  44. m_oidValue (szOID),
  45. m_CPSValue (szCPS),
  46. m_originalCPSValue (szCPS)
  47. {
  48. }
  49. void CNewIssuanceOIDDlg::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CHelpDialog::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(CNewIssuanceOIDDlg)
  53. DDX_Control(pDX, IDC_NEW_ISSUANCE_OID_VALUE, m_oidValueEdit);
  54. DDX_Control(pDX, IDC_CPS_EDIT, m_CPSEdit);
  55. DDX_Text(pDX, IDC_NEW_ISSUANCE_OID_NAME, m_oidFriendlyName);
  56. DDX_Text(pDX, IDC_NEW_ISSUANCE_OID_VALUE, m_oidValue);
  57. DDX_Text(pDX, IDC_CPS_EDIT, m_CPSValue);
  58. //}}AFX_DATA_MAP
  59. }
  60. BEGIN_MESSAGE_MAP(CNewIssuanceOIDDlg, CHelpDialog)
  61. //{{AFX_MSG_MAP(CNewIssuanceOIDDlg)
  62. ON_EN_CHANGE(IDC_NEW_ISSUANCE_OID_NAME, OnChangeNewOidName)
  63. ON_EN_CHANGE(IDC_NEW_ISSUANCE_OID_VALUE, OnChangeNewOidValue)
  64. ON_NOTIFY(EN_LINK, IDC_CPS_EDIT, OnClickedURL )
  65. ON_EN_CHANGE(IDC_CPS_EDIT, OnChangeCpsEdit)
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CNewIssuanceOIDDlg message handlers
  70. BOOL CNewIssuanceOIDDlg::OnInitDialog()
  71. {
  72. _TRACE (1, L"Entering CNewIssuanceOIDDlg::OnInitDialog\n");
  73. CHelpDialog::OnInitDialog();
  74. m_CPSEdit.SendMessage (EM_AUTOURLDETECT, TRUE);
  75. m_CPSEdit.SetEventMask (ENM_CHANGE | ENM_LINK);
  76. PWSTR pwszOID = 0;
  77. if ( m_bEdit )
  78. {
  79. CString text;
  80. VERIFY (text.LoadString (IDS_EDIT_ISSUANCE_POLICY));
  81. SetWindowText (text);
  82. m_oidValueEdit.SetReadOnly ();
  83. VERIFY (text.LoadString (IDS_NEW_ISSUANCE_POLICY_HINT));
  84. SetDlgItemText (IDC_NEW_ISSUANCE_POLICY_HINT, text);
  85. }
  86. else
  87. {
  88. HRESULT hr = CAOIDCreateNew
  89. (CERT_OID_TYPE_ISSUER_POLICY,
  90. 0,
  91. &pwszOID);
  92. _ASSERT (SUCCEEDED(hr));
  93. if ( SUCCEEDED (hr) )
  94. {
  95. m_szOriginalOID = pwszOID;
  96. m_oidValue = pwszOID;
  97. LocalFree (pwszOID);
  98. }
  99. else
  100. {
  101. _TRACE (0, L"CAOIDCreateNew (CERT_OID_TYPE_ISSUER_POLICY) failed: 0x%x\n",
  102. hr);
  103. }
  104. }
  105. UpdateData (FALSE);
  106. // Don't allow rename for OIDS returned by CryptoAPI
  107. if ( m_bEdit )
  108. {
  109. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  110. {
  111. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  112. if ( pPolicyOID )
  113. {
  114. if ( pPolicyOID->GetOIDW () == m_oidValue )
  115. {
  116. if ( !pPolicyOID->CanRename () )
  117. {
  118. GetDlgItem (IDC_NEW_ISSUANCE_OID_NAME)->EnableWindow (FALSE);
  119. }
  120. break;
  121. }
  122. }
  123. }
  124. }
  125. EnableControls ();
  126. _TRACE (-1, L"Leaving CNewIssuanceOIDDlg::OnInitDialog\n");
  127. return TRUE; // return TRUE unless you set the focus to a control
  128. // EXCEPTION: OCX Property Pages should return FALSE
  129. }
  130. void CNewIssuanceOIDDlg::EnableControls()
  131. {
  132. UpdateData (TRUE);
  133. if ( m_oidFriendlyName.IsEmpty () || m_oidValue.IsEmpty () || !m_bDirty )
  134. GetDlgItem (IDOK)->EnableWindow (FALSE);
  135. else
  136. GetDlgItem (IDOK)->EnableWindow (TRUE);
  137. }
  138. void CNewIssuanceOIDDlg::OnChangeNewOidName()
  139. {
  140. m_bDirty = true;
  141. EnableControls ();
  142. }
  143. void CNewIssuanceOIDDlg::OnChangeNewOidValue()
  144. {
  145. m_bDirty = true;
  146. EnableControls ();
  147. }
  148. void CNewIssuanceOIDDlg::OnCancel()
  149. {
  150. if ( !m_bEdit )
  151. {
  152. HRESULT hr = CAOIDDelete (m_szOriginalOID);
  153. _ASSERT (SUCCEEDED(hr));
  154. if ( FAILED (hr) )
  155. {
  156. _TRACE (0, L"CAOIDDelete (%s) failed: 0x%x\n",
  157. (PCWSTR) m_szOriginalOID, hr);
  158. }
  159. }
  160. CHelpDialog::OnCancel();
  161. }
  162. void CNewIssuanceOIDDlg::OnOK()
  163. {
  164. CThemeContextActivator activator;
  165. UpdateData (TRUE);
  166. int errorTypeStrID = 0;
  167. if ( !OIDHasValidFormat (m_oidValue, errorTypeStrID) )
  168. {
  169. CString text;
  170. CString caption;
  171. CString errorType;
  172. VERIFY (caption.LoadString (IDS_CERTTMPL));
  173. if ( errorTypeStrID )
  174. VERIFY (errorType.LoadString (errorTypeStrID));
  175. text.FormatMessage (IDS_OID_FORMAT_INVALID, m_oidValue, errorType);
  176. MessageBox (text, caption, MB_OK);
  177. GetDlgItem (IDOK)->EnableWindow (FALSE);
  178. m_oidValueEdit.SetFocus ();
  179. return;
  180. }
  181. if ( !m_bEdit && m_szOriginalOID != m_oidValue )
  182. {
  183. HRESULT hr = CAOIDDelete (m_szOriginalOID);
  184. _ASSERT (SUCCEEDED(hr));
  185. if ( SUCCEEDED (hr) )
  186. {
  187. hr = CAOIDAdd (CERT_OID_TYPE_ISSUER_POLICY,
  188. 0,
  189. m_oidValue);
  190. if ( FAILED (hr) )
  191. {
  192. CString text;
  193. CString caption;
  194. VERIFY (caption.LoadString (IDS_CERTTMPL));
  195. text.FormatMessage (IDS_CANNOT_ADD_ISSUANCE_OID, GetSystemMessage (hr));
  196. MessageBox (text, caption, MB_OK | MB_ICONWARNING);
  197. _TRACE (0, L"CAOIDAdd (%s) failed: 0x%x\n",
  198. (PCWSTR) m_oidValue, hr);
  199. return;
  200. }
  201. }
  202. else
  203. {
  204. _TRACE (0, L"CAOIDDelete (%s) failed: 0x%x\n",
  205. (PCWSTR) m_szOriginalOID, hr);
  206. return;
  207. }
  208. }
  209. HRESULT hr = S_OK;
  210. // If we're editing, don't save the value if it hasn't changed
  211. if ( (m_bEdit && m_originalOidFriendlyName != m_oidFriendlyName) || !m_bEdit )
  212. hr = CAOIDSetProperty (m_oidValue, CERT_OID_PROPERTY_DISPLAY_NAME,
  213. m_oidFriendlyName.IsEmpty () ? 0 : ((LPVOID) (LPCWSTR) m_oidFriendlyName));
  214. if ( SUCCEEDED (hr) )
  215. {
  216. if ( SUCCEEDED (hr) )
  217. {
  218. // Update the OID list
  219. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  220. {
  221. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  222. if ( pPolicyOID &&
  223. pPolicyOID->IsIssuanceOID () &&
  224. m_oidValue == pPolicyOID->GetOIDW ())
  225. {
  226. pPolicyOID->SetDisplayName (m_oidFriendlyName);
  227. }
  228. }
  229. }
  230. if ( (m_bEdit && m_originalCPSValue != m_CPSValue) || !m_bEdit )
  231. hr = CAOIDSetProperty (m_oidValue, CERT_OID_PROPERTY_CPS,
  232. m_CPSValue.IsEmpty () ? 0 : ((LPVOID) (LPCWSTR) m_CPSValue));
  233. if ( FAILED (hr) )
  234. {
  235. CString text;
  236. CString caption;
  237. VERIFY (caption.LoadString (IDS_CERTTMPL));
  238. text.FormatMessage (IDS_CANNOT_WRITE_CPS, GetSystemMessage (hr));
  239. MessageBox (text, caption, MB_OK | MB_ICONWARNING);
  240. _TRACE (0, L"CAOIDSetProperty (%s, CERT_OID_PROPERTY_CPS, %s) failed: 0x%x\n",
  241. (PCWSTR) m_oidValue, (PCWSTR) m_CPSValue, hr);
  242. return;
  243. }
  244. }
  245. else
  246. {
  247. CString text;
  248. CString caption;
  249. VERIFY (caption.LoadString (IDS_CERTTMPL));
  250. text.FormatMessage (IDS_CANNOT_WRITE_DISPLAY_NAME, GetSystemMessage (hr));
  251. MessageBox (text, caption, MB_OK | MB_ICONWARNING);
  252. _TRACE (0, L"CAOIDSetProperty (%s, CERT_OID_PROPERTY_DISPLAY_NAME, %s) failed: 0x%x\n",
  253. (PCWSTR) m_oidValue, (PCWSTR) m_oidFriendlyName, hr);
  254. return;
  255. }
  256. CHelpDialog::OnOK();
  257. }
  258. void CNewIssuanceOIDDlg::DoContextHelp (HWND hWndControl)
  259. {
  260. _TRACE(-1, L"Entering CNewIssuanceOIDDlg::DoContextHelp\n");
  261. // Display context help for a control
  262. if ( !::WinHelp (
  263. hWndControl,
  264. GetContextHelpFile (),
  265. HELP_WM_HELP,
  266. (DWORD_PTR) g_aHelpIDs_IDD_NEW_ISSUANCE_OID) )
  267. {
  268. _TRACE(-1, L"WinHelp () failed: 0x%x\n", GetLastError ());
  269. }
  270. _TRACE(-1, L"Leaving CNewIssuanceOIDDlg::DoContextHelp\n");
  271. }
  272. void CNewIssuanceOIDDlg::OnClickedURL( NMHDR * pNMHDR, LRESULT * pResult )
  273. {
  274. ENLINK *pEnlink = reinterpret_cast< ENLINK * >( pNMHDR );
  275. if ( pEnlink->msg == WM_LBUTTONUP )
  276. {
  277. UpdateData (TRUE);
  278. CString strCPSText;
  279. CString strURL;
  280. // pEnlink->chrg.cpMin and pEnlink->chrg.cpMax delimit the URL string.
  281. strURL = m_CPSValue.Mid (pEnlink->chrg.cpMin, pEnlink->chrg.cpMax - pEnlink->chrg.cpMin);
  282. // Displaying the URL may take time, so show the hourglass cursor.
  283. CWaitCursor waitCursor;
  284. if ( ShellExecute( this->m_hWnd, _T("open"), strURL, NULL, NULL, SW_SHOWDEFAULT ) <= (HINSTANCE) 32 )
  285. {
  286. CThemeContextActivator activator;
  287. AfxMessageBox( IDS_BROWSER_ERROR );
  288. }
  289. }
  290. *pResult = 0;
  291. }
  292. void CNewIssuanceOIDDlg::OnChangeCpsEdit()
  293. {
  294. m_bDirty = true;
  295. EnableControls ();
  296. }