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.

152 lines
3.6 KiB

  1. // TrusterDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "TrstDlg.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CTrusterDlg dialog
  12. CTrusterDlg::CTrusterDlg(CWnd* pParent /*=NULL*/)
  13. : CDialog(CTrusterDlg::IDD, pParent)
  14. {
  15. //{{AFX_DATA_INIT(CTrusterDlg)
  16. // NOTE: the ClassWizard will add member initialization here
  17. //}}AFX_DATA_INIT
  18. }
  19. void CTrusterDlg::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. DDX_Text(pDX, IDC_USERNAME, m_strUser);
  23. DDX_Text(pDX, IDC_PASSWORD, m_strPassword);
  24. DDX_Text(pDX, IDC_DOMAINNAME, m_strDomain);
  25. //{{AFX_DATA_MAP(CTrusterDlg)
  26. // NOTE: the ClassWizard will add DDX and DDV calls here
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(CTrusterDlg, CDialog)
  30. //{{AFX_MSG_MAP(CTrusterDlg)
  31. ON_BN_CLICKED(IDC_OK, OnOK)
  32. ON_BN_CLICKED(IDC_CANCEL, OnCancel)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CTrusterDlg message handlers
  37. DWORD CTrusterDlg::VerifyPassword(WCHAR * sUserName, WCHAR * sPassword, WCHAR * sDomain)
  38. {
  39. CWaitCursor wait;
  40. DWORD retVal = 0;
  41. CString strDomainUserName;
  42. CString localIPC;
  43. WCHAR localMachine[MAX_PATH];
  44. NETRESOURCE nr;
  45. memset(&nr,0,(sizeof nr));
  46. strDomainUserName.Format(L"%s\\%s",sDomain,sUserName);
  47. // get the name of the local machine
  48. if ( GetComputerName(localMachine,&len) )
  49. {
  50. localIPC.Format(L"\\\\%s",localMachine);
  51. nr.dwType = RESOURCETYPE_ANY;
  52. nr.lpRemoteName = localIPC.GetBuffer(0);
  53. retVal = WNetAddConnection2(&nr,sPassword,strDomainUserName,0);
  54. if ( ! retVal )
  55. {
  56. retVal = WNetCancelConnection2(localIPC.GetBuffer(0),0,TRUE);
  57. if ( retVal )
  58. retVal = 0;
  59. }
  60. else if ( retVal == ERROR_SESSION_CREDENTIAL_CONFLICT )
  61. {
  62. // skip the password check in this case
  63. retVal = 0;
  64. }
  65. }
  66. else
  67. {
  68. retVal = GetLastError();
  69. }
  70. return 0;
  71. }
  72. void CTrusterDlg::OnOK()
  73. {
  74. toreturn =false;
  75. UpdateData(TRUE);
  76. m_strUser.TrimLeft();m_strUser.TrimRight();
  77. m_strDomain.TrimLeft();m_strDomain.TrimRight();
  78. m_strPassword.TrimLeft();m_strPassword.TrimRight();
  79. if (m_strUser.IsEmpty() || m_strDomain.IsEmpty())
  80. {
  81. CString c;
  82. c.LoadString(IDS_MSG_DOMAIN);
  83. CString d;
  84. d.LoadString(IDS_MSG_INPUT);
  85. MessageBox(c,d,MB_OK);
  86. toreturn =false;
  87. }
  88. else
  89. {
  90. DWORD returncode = VerifyPassword(m_strUser.GetBuffer(1000),m_strPassword.GetBuffer(1000),m_strDomain.GetBuffer(1000));
  91. m_strDomain.ReleaseBuffer(); m_strUser.ReleaseBuffer(); m_strPassword.ReleaseBuffer();
  92. if (returncode==ERROR_LOGON_FAILURE || m_strUser.IsEmpty())
  93. {
  94. CString e;
  95. err.ErrorCodeToText(returncode,1000,e.GetBuffer(1000));
  96. e.ReleaseBuffer();
  97. CString txt;
  98. swprintf(txt.GetBuffer(1000),L"%u",returncode);
  99. txt.ReleaseBuffer();
  100. CString text;
  101. text.LoadString(IDS_MSG_ERRORBUF);
  102. e += text;
  103. e+=txt;
  104. e+=L")";
  105. CString title;
  106. title.LoadString(IDS_MSG_ERROR);
  107. MessageBox(e,title,MB_OK);
  108. toreturn =false;
  109. }
  110. else
  111. {
  112. toreturn =true;
  113. }
  114. }
  115. CDialog::OnOK();
  116. }
  117. void CTrusterDlg::OnCancel()
  118. {
  119. toreturn=false;
  120. // TODO: Add your control notification handler code here
  121. CDialog::OnCancel();
  122. }
  123. BOOL CTrusterDlg::OnInitDialog()
  124. {
  125. CDialog::OnInitDialog();
  126. toreturn =false;
  127. if ( m_strDomain.IsEmpty() )
  128. return TRUE;
  129. else
  130. UpdateData(FALSE);
  131. // TODO: Add extra initialization here
  132. return TRUE; // return TRUE unless you set the focus to a control
  133. // EXCEPTION: OCX Property Pages should return FALSE
  134. }