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.

298 lines
8.9 KiB

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