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.

181 lines
4.6 KiB

  1. // NKDNcpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "keyring.h"
  5. #include "NKChseCA.h"
  6. #include "NKDN.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CNKDistinguishedName dialog
  14. CNKDistinguishedName::CNKDistinguishedName(CWnd* pParent /*=NULL*/)
  15. : CNKPages(CNKDistinguishedName::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CNKDistinguishedName)
  18. m_nkdn_sz_CN = _T("");
  19. m_nkdn_sz_O = _T("");
  20. m_nkdn_sz_OU = _T("");
  21. //}}AFX_DATA_INIT
  22. }
  23. void CNKDistinguishedName::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CNKDistinguishedName)
  27. DDX_Control(pDX, IDC_NEWKEY_COMMONNAME, m_control_CN);
  28. DDX_Control(pDX, IDC_NEWKEY_ORGUNIT, m_control_OU);
  29. DDX_Control(pDX, IDC_NEWKEY_ORG, m_control_O);
  30. DDX_Text(pDX, IDC_NEWKEY_COMMONNAME, m_nkdn_sz_CN);
  31. DDV_MaxChars(pDX, m_nkdn_sz_CN, 64);
  32. DDX_Text(pDX, IDC_NEWKEY_ORG, m_nkdn_sz_O);
  33. DDV_MaxChars(pDX, m_nkdn_sz_O, 64);
  34. DDX_Text(pDX, IDC_NEWKEY_ORGUNIT, m_nkdn_sz_OU);
  35. DDV_MaxChars(pDX, m_nkdn_sz_OU, 64);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CNKDistinguishedName, CDialog)
  39. //{{AFX_MSG_MAP(CNKDistinguishedName)
  40. ON_EN_CHANGE(IDC_NEWKEY_COMMONNAME, OnChangeNewkeyCommonname)
  41. ON_EN_CHANGE(IDC_NEWKEY_ORG, OnChangeNewkeyOrg)
  42. ON_EN_CHANGE(IDC_NEWKEY_ORGUNIT, OnChangeNewkeyOrgunit)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. #define SZ_DN_CN "DN_COMMON_NAME"
  46. #define SZ_DN_O "DN_ORGANIZATION"
  47. #define SZ_DN_OU "DN_ORG_UNIT"
  48. //----------------------------------------------------------------
  49. void CNKDistinguishedName::OnFinish()
  50. {
  51. // store the user entries
  52. SetStoredString( m_nkdn_sz_CN, SZ_DN_CN );
  53. SetStoredString( m_nkdn_sz_O, SZ_DN_O );
  54. SetStoredString( m_nkdn_sz_OU, SZ_DN_OU );
  55. }
  56. //----------------------------------------------------------------
  57. BOOL CNKDistinguishedName::OnInitDialog( )
  58. {
  59. // if the entries from last time are available, use them
  60. try
  61. {
  62. FGetStoredString( m_nkdn_sz_CN, SZ_DN_CN );
  63. FGetStoredString( m_nkdn_sz_O, SZ_DN_O );
  64. FGetStoredString( m_nkdn_sz_OU, SZ_DN_OU );
  65. }
  66. catch( CException e )
  67. {
  68. }
  69. // call superclass
  70. CPropertyPage::OnInitDialog();
  71. // return 0 to say we set the default item
  72. // return 1 to just select the default default item
  73. return 1;
  74. }
  75. //----------------------------------------------------------------
  76. BOOL CNKDistinguishedName::OnSetActive()
  77. {
  78. ActivateButtons();
  79. return CPropertyPage::OnSetActive();
  80. }
  81. //----------------------------------------------------------------
  82. void CNKDistinguishedName::ActivateButtons()
  83. {
  84. DWORD flags = PSWIZB_BACK;
  85. BOOL fCanGoOn = TRUE;
  86. UpdateData(TRUE);
  87. //now make sure there is something in each of the required fields
  88. fCanGoOn &= !m_nkdn_sz_CN.IsEmpty();
  89. fCanGoOn &= !m_nkdn_sz_O.IsEmpty();
  90. fCanGoOn &= !m_nkdn_sz_OU.IsEmpty();
  91. // if we can go on, hilite the button
  92. if ( fCanGoOn )
  93. {
  94. flags |= PSWIZB_NEXT;
  95. }
  96. // update the property sheet buttons
  97. m_pPropSheet->SetWizardButtons( flags );
  98. }
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CNKDistinguishedName message handlers
  101. //----------------------------------------------------------------
  102. void CNKDistinguishedName::OnChangeNewkeyCommonname()
  103. {
  104. ActivateButtons();
  105. }
  106. //----------------------------------------------------------------
  107. void CNKDistinguishedName::OnChangeNewkeyOrg()
  108. {
  109. ActivateButtons();
  110. }
  111. //----------------------------------------------------------------
  112. void CNKDistinguishedName::OnChangeNewkeyOrgunit()
  113. {
  114. ActivateButtons();
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. //----------------------------------------------------------------
  118. CDNEdit::CDNEdit()
  119. {
  120. szExclude.LoadString( IDS_ILLEGAL_DN_CHARS );
  121. szTotallyExclude.LoadString( IDS_TOTALLY_ILLEGAL_CHARS );
  122. }
  123. //----------------------------------------------------------------
  124. BOOL CDNEdit::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  125. {
  126. // if it is a character
  127. if ( message == WM_CHAR )
  128. {
  129. TCHAR chCharCode = (TCHAR)wParam;
  130. // first test the totally bad characters
  131. if ( strchr(szTotallyExclude, chCharCode) )
  132. {
  133. MessageBeep(0);
  134. return 1;
  135. }
  136. // now test the potentially bad characters
  137. if ( strchr(szExclude, chCharCode) )
  138. switch( AfxMessageBox(IDS_BADCHARMSG, MB_YESNO|MB_ICONQUESTION) )
  139. {
  140. case IDYES:
  141. break;
  142. case IDNO:
  143. // reject the character
  144. MessageBeep(0);
  145. return 1;
  146. }
  147. }
  148. // return the default answer
  149. return CEdit::OnWndMsg( message, wParam, lParam, pResult);
  150. }