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.

180 lines
5.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2000 **/
  4. /**********************************************************************/
  5. /*
  6. cred.cpp
  7. This file contains all of the prototypes for the
  8. credentials dialog used for DDNS.
  9. FILE HISTORY:
  10. */
  11. #include "stdafx.h"
  12. #include "cred.h"
  13. #include "lsa.h" // RtlEncodeW/RtlDecodeW
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CCredentials dialog
  21. CCredentials::CCredentials(CWnd* pParent /*=NULL*/)
  22. : CBaseDialog(CCredentials::IDD, pParent)
  23. {
  24. //{{AFX_DATA_INIT(CCredentials)
  25. // NOTE: the ClassWizard will add member initialization here
  26. //}}AFX_DATA_INIT
  27. }
  28. void CCredentials::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CBaseDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CCredentials)
  32. DDX_Control(pDX, IDOK, m_buttonOk);
  33. DDX_Control(pDX, IDC_EDIT_CRED_USERNAME, m_editUsername);
  34. DDX_Control(pDX, IDC_EDIT_CRED_PASSWORD2, m_editPassword2);
  35. DDX_Control(pDX, IDC_EDIT_CRED_PASSWORD, m_editPassword);
  36. DDX_Control(pDX, IDC_EDIT_CRED_DOMAIN, m_editDomain);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CCredentials, CBaseDialog)
  40. //{{AFX_MSG_MAP(CCredentials)
  41. ON_EN_CHANGE(IDC_EDIT_CRED_USERNAME, OnChangeEditCredUsername)
  42. ON_EN_CHANGE(IDC_EDIT_CRED_DOMAIN, OnChangeEditCredDomain)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CCredentials message handlers
  47. BOOL CCredentials::OnInitDialog()
  48. {
  49. CBaseDialog::OnInitDialog();
  50. CString strUsername, strDomain, dummyPasswd;
  51. LPTSTR pszUsername, pszDomain;
  52. pszUsername = strUsername.GetBuffer(MAX_PATH);
  53. pszDomain = strDomain.GetBuffer(MAX_PATH);
  54. // call the DHCP api to get the current username and domain
  55. DWORD err = DhcpServerQueryDnsRegCredentials((LPWSTR) ((LPCTSTR) m_strServerIp),
  56. MAX_PATH,
  57. pszUsername,
  58. MAX_PATH,
  59. pszDomain);
  60. strUsername.ReleaseBuffer();
  61. strDomain.ReleaseBuffer();
  62. if (err == ERROR_SUCCESS)
  63. {
  64. m_editUsername.SetWindowText(strUsername);
  65. m_editDomain.SetWindowText(strDomain);
  66. // set the password fields to something
  67. dummyPasswd = _T("xxxxxxxxxx");
  68. m_editPassword.SetWindowText( dummyPasswd );
  69. m_editPassword2.SetWindowText( dummyPasswd );
  70. }
  71. else
  72. {
  73. ::DhcpMessageBox(err);
  74. }
  75. m_fNewUsernameOrDomain = FALSE;
  76. return TRUE; // return TRUE unless you set the focus to a control
  77. // EXCEPTION: OCX Property Pages should return FALSE
  78. }
  79. void CCredentials::OnOK()
  80. {
  81. CString strUsername, strDomain, strPassword1, strPassword2, dummyPasswd;
  82. dummyPasswd = _T("xxxxxxxxxx");
  83. // grab the username and domain
  84. m_editUsername.GetWindowText(strUsername);
  85. m_editDomain.GetWindowText(strDomain);
  86. // grab the passwords and make sure they match
  87. m_editPassword.GetWindowText(strPassword1);
  88. m_editPassword2.GetWindowText(strPassword2);
  89. if (strPassword1.Compare(strPassword2) != 0)
  90. {
  91. // passwords don't match
  92. AfxMessageBox(IDS_PASSWORDS_DONT_MATCH);
  93. m_editPassword.SetFocus();
  94. return;
  95. }
  96. //
  97. // run through the following code if user changed passwd.
  98. //
  99. if ( strPassword2 != dummyPasswd )
  100. {
  101. // encode the password
  102. unsigned char ucSeed = DHCP_ENCODE_SEED;
  103. LPTSTR pszPassword = strPassword1.GetBuffer((strPassword1.GetLength() + 1) * sizeof(TCHAR));
  104. RtlEncodeW(&ucSeed, pszPassword);
  105. // send to the DHCP api.
  106. DWORD err = ERROR_SUCCESS;
  107. err = DhcpServerSetDnsRegCredentials((LPWSTR) ((LPCTSTR) m_strServerIp),
  108. (LPWSTR) ((LPCTSTR) strUsername),
  109. (LPWSTR) ((LPCTSTR) strDomain),
  110. (LPWSTR) ((LPCTSTR) pszPassword));
  111. if (err != ERROR_SUCCESS)
  112. {
  113. // something failed, notify the user
  114. ::DhcpMessageBox(err);
  115. return;
  116. }
  117. }
  118. CBaseDialog::OnOK();
  119. }
  120. void CCredentials::OnChangeEditCredUsername()
  121. {
  122. if (!m_fNewUsernameOrDomain)
  123. {
  124. m_fNewUsernameOrDomain = TRUE;
  125. m_editPassword.SetWindowText(_T(""));
  126. m_editPassword2.SetWindowText(_T(""));
  127. }
  128. }
  129. void CCredentials::OnChangeEditCredDomain()
  130. {
  131. if (!m_fNewUsernameOrDomain)
  132. {
  133. m_fNewUsernameOrDomain = TRUE;
  134. m_editPassword.SetWindowText(_T(""));
  135. m_editPassword2.SetWindowText(_T(""));
  136. }
  137. }
  138. void CCredentials::SetServerIp(LPCTSTR pszServerIp)
  139. {
  140. m_strServerIp = pszServerIp;
  141. }