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.

285 lines
7.8 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001
  5. //
  6. // File: NewApplicationOIDDlg.cpp
  7. //
  8. // Contents: Implementation of CNewApplicationOIDDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. // NewApplicationOIDDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "NewApplicationOIDDlg.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. // CNewApplicationOIDDlg dialog
  24. CNewApplicationOIDDlg::CNewApplicationOIDDlg(CWnd* pParent)
  25. : CHelpDialog(CNewApplicationOIDDlg::IDD, pParent),
  26. m_bEdit (false),
  27. m_bDirty (false)
  28. {
  29. //{{AFX_DATA_INIT(CNewApplicationOIDDlg)
  30. m_oidFriendlyName = _T("");
  31. m_oidValue = _T("");
  32. //}}AFX_DATA_INIT
  33. }
  34. CNewApplicationOIDDlg::CNewApplicationOIDDlg(CWnd* pParent,
  35. const CString& szDisplayName,
  36. const CString& szOID)
  37. : CHelpDialog(CNewApplicationOIDDlg::IDD, pParent),
  38. m_bEdit (true),
  39. m_bDirty (false),
  40. m_originalOidFriendlyName (szDisplayName),
  41. m_oidFriendlyName (szDisplayName),
  42. m_oidValue (szOID)
  43. {
  44. }
  45. void CNewApplicationOIDDlg::DoDataExchange(CDataExchange* pDX)
  46. {
  47. CHelpDialog::DoDataExchange(pDX);
  48. //{{AFX_DATA_MAP(CNewApplicationOIDDlg)
  49. DDX_Control(pDX, IDC_NEW_APPLICATION_OID_VALUE, m_oidValueEdit);
  50. DDX_Text(pDX, IDC_NEW_APPLICATION_OID_NAME, m_oidFriendlyName);
  51. DDX_Text(pDX, IDC_NEW_APPLICATION_OID_VALUE, m_oidValue);
  52. //}}AFX_DATA_MAP
  53. }
  54. BEGIN_MESSAGE_MAP(CNewApplicationOIDDlg, CHelpDialog)
  55. //{{AFX_MSG_MAP(CNewApplicationOIDDlg)
  56. ON_EN_CHANGE(IDC_NEW_APPLICATION_OID_NAME, OnChangeNewOidName)
  57. ON_EN_CHANGE(IDC_NEW_APPLICATION_OID_VALUE, OnChangeNewOidValue)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CNewApplicationOIDDlg message handlers
  62. BOOL CNewApplicationOIDDlg::OnInitDialog()
  63. {
  64. _TRACE (1, L"Entering CNewApplicationOIDDlg::OnInitDialog\n");
  65. CHelpDialog::OnInitDialog();
  66. PWSTR pwszOID = 0;
  67. if ( m_bEdit )
  68. {
  69. CString text;
  70. VERIFY (text.LoadString (IDS_EDIT_APPLICATION_POLICY));
  71. SetWindowText (text);
  72. m_oidValueEdit.SetReadOnly ();
  73. VERIFY (text.LoadString (IDS_EDIT_APPLICATION_POLICY_HINT));
  74. SetDlgItemText (IDC_NEW_APPLICATION_OID_HINT, text);
  75. }
  76. else
  77. {
  78. HRESULT hr = CAOIDCreateNew
  79. (CERT_OID_TYPE_APPLICATION_POLICY,
  80. 0,
  81. &pwszOID);
  82. _ASSERT (SUCCEEDED(hr));
  83. if ( SUCCEEDED (hr) )
  84. {
  85. m_szOriginalOID = pwszOID;
  86. m_oidValue = pwszOID;
  87. LocalFree (pwszOID);
  88. }
  89. else
  90. {
  91. _TRACE (0, L"CAOIDCreateNew (CERT_OID_TYPE_APPLICATION_POLICY) failed: 0x%x\n",
  92. hr);
  93. }
  94. }
  95. UpdateData (FALSE);
  96. // Don't allow rename for OIDS returned by CryptoAPI
  97. if ( m_bEdit )
  98. {
  99. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  100. {
  101. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  102. if ( pPolicyOID )
  103. {
  104. if ( pPolicyOID->GetOIDW () == m_oidValue )
  105. {
  106. if ( !pPolicyOID->CanRename () )
  107. {
  108. GetDlgItem (IDC_NEW_APPLICATION_OID_NAME)->EnableWindow (FALSE);
  109. }
  110. break;
  111. }
  112. }
  113. }
  114. }
  115. EnableControls ();
  116. _TRACE (-1, L"Leaving CNewApplicationOIDDlg::OnInitDialog\n");
  117. return TRUE; // return TRUE unless you set the focus to a control
  118. // EXCEPTION: OCX Property Pages should return FALSE
  119. }
  120. void CNewApplicationOIDDlg::EnableControls()
  121. {
  122. UpdateData (TRUE);
  123. if ( m_oidFriendlyName.IsEmpty () || m_oidValue.IsEmpty () || !m_bDirty )
  124. GetDlgItem (IDOK)->EnableWindow (FALSE);
  125. else
  126. GetDlgItem (IDOK)->EnableWindow (TRUE);
  127. }
  128. void CNewApplicationOIDDlg::OnChangeNewOidName()
  129. {
  130. m_bDirty = true;
  131. EnableControls ();
  132. }
  133. void CNewApplicationOIDDlg::OnChangeNewOidValue()
  134. {
  135. m_bDirty = true;
  136. EnableControls ();
  137. }
  138. void CNewApplicationOIDDlg::OnCancel()
  139. {
  140. if ( !m_bEdit )
  141. {
  142. HRESULT hr = CAOIDDelete (m_szOriginalOID);
  143. _ASSERT (SUCCEEDED(hr));
  144. if ( FAILED (hr) )
  145. {
  146. _TRACE (0, L"CAOIDDelete (%s) failed: 0x%x\n",
  147. (PCWSTR) m_szOriginalOID, hr);
  148. }
  149. }
  150. CHelpDialog::OnCancel();
  151. }
  152. void CNewApplicationOIDDlg::OnOK()
  153. {
  154. UpdateData (TRUE);
  155. int errorTypeStrID = 0;
  156. if ( !OIDHasValidFormat (m_oidValue, errorTypeStrID) )
  157. {
  158. CString text;
  159. CString caption;
  160. CString errorType;
  161. CThemeContextActivator activator;
  162. VERIFY (caption.LoadString (IDS_CERTTMPL));
  163. VERIFY (errorType.LoadString (errorTypeStrID));
  164. text.FormatMessage (IDS_OID_FORMAT_INVALID, m_oidValue, errorType);
  165. MessageBox (text, caption, MB_OK);
  166. GetDlgItem (IDOK)->EnableWindow (FALSE);
  167. m_oidValueEdit.SetFocus ();
  168. return;
  169. }
  170. if ( !m_bEdit && m_szOriginalOID != m_oidValue )
  171. {
  172. HRESULT hr = CAOIDDelete (m_szOriginalOID);
  173. _ASSERT (SUCCEEDED(hr));
  174. if ( SUCCEEDED (hr) )
  175. {
  176. hr = CAOIDAdd (CERT_OID_TYPE_APPLICATION_POLICY,
  177. 0,
  178. m_oidValue);
  179. if ( FAILED (hr) )
  180. {
  181. CString text;
  182. CString caption;
  183. CThemeContextActivator activator;
  184. VERIFY (caption.LoadString (IDS_CERTTMPL));
  185. text.FormatMessage (IDS_OID_ALREADY_EXISTS, m_oidValue);
  186. MessageBox (text, caption, MB_OK);
  187. GetDlgItem (IDOK)->EnableWindow (FALSE);
  188. m_oidValueEdit.SetFocus ();
  189. _TRACE (0, L"CAOIDAdd (%s) failed: 0x%x\n",
  190. (PCWSTR) m_oidValue, hr);
  191. return;
  192. }
  193. }
  194. else
  195. {
  196. _TRACE (0, L"CAOIDDelete (%s) failed: 0x%x\n",
  197. (PCWSTR) m_szOriginalOID, hr);
  198. return;
  199. }
  200. }
  201. HRESULT hr = S_OK;
  202. // If we're editing, don't save the value if it hasn't changed
  203. if ( (m_bEdit && m_originalOidFriendlyName != m_oidFriendlyName) || !m_bEdit )
  204. {
  205. hr = CAOIDSetProperty (m_oidValue, CERT_OID_PROPERTY_DISPLAY_NAME,
  206. m_oidFriendlyName.IsEmpty () ? 0 : ((LPVOID) (LPCWSTR) m_oidFriendlyName));
  207. if ( SUCCEEDED (hr) )
  208. {
  209. // Update the OID list
  210. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  211. {
  212. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  213. if ( pPolicyOID &&
  214. pPolicyOID->IsApplicationOID () &&
  215. m_oidValue == pPolicyOID->GetOIDW ())
  216. {
  217. pPolicyOID->SetDisplayName (m_oidFriendlyName);
  218. }
  219. }
  220. }
  221. }
  222. _ASSERT (SUCCEEDED(hr));
  223. if ( FAILED (hr) )
  224. {
  225. _TRACE (0, L"CAOIDSetProperty (%s, CERT_OID_PROPERTY_DISPLAY_NAME, %s) failed: 0x%x\n",
  226. (PCWSTR) m_oidValue, (PCWSTR) m_oidFriendlyName, hr);
  227. return;
  228. }
  229. CHelpDialog::OnOK();
  230. }
  231. void CNewApplicationOIDDlg::DoContextHelp (HWND hWndControl)
  232. {
  233. _TRACE(1, L"Entering CNewApplicationOIDDlg::DoContextHelp\n");
  234. // Display context help for a control
  235. if ( !::WinHelp (
  236. hWndControl,
  237. GetContextHelpFile (),
  238. HELP_WM_HELP,
  239. (DWORD_PTR) g_aHelpIDs_IDD_NEW_APPLICATION_OID) )
  240. {
  241. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  242. }
  243. _TRACE(-1, L"Leaving CNewApplicationOIDDlg::DoContextHelp\n");
  244. }