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.

235 lines
8.2 KiB

  1. #include "stdafx.h"
  2. #include "newcondlg.h"
  3. #include "browsedlg.h"
  4. #include "resource.h"
  5. #include "validate.h"
  6. CNewConDlg* CNewConDlg::m_pThis = NULL;
  7. CNewConDlg::CNewConDlg(HWND hWndOwner, HINSTANCE hInst) : m_hWnd(hWndOwner), m_hInst(hInst)
  8. {
  9. m_pThis = this;
  10. //
  11. // Password saving is disabled by default
  12. //
  13. m_bSavePassword = FALSE;
  14. //
  15. // Connect to console is enabled by default
  16. //
  17. m_bConnectToConsole = TRUE;
  18. ZeroMemory(m_szServer, sizeof(m_szServer));
  19. ZeroMemory(m_szDescription, sizeof(m_szDescription));
  20. ZeroMemory(m_szUserName, sizeof(m_szUserName));
  21. ZeroMemory(m_szPassword, sizeof(m_szPassword));
  22. ZeroMemory(m_szDomain, sizeof(m_szDomain));
  23. }
  24. CNewConDlg::~CNewConDlg()
  25. {
  26. ZeroPasswordMemory();
  27. }
  28. INT_PTR
  29. CNewConDlg::DoModal()
  30. {
  31. INT_PTR retVal;
  32. retVal = DialogBox( m_hInst,MAKEINTRESOURCE(IDD_NEWCON), m_hWnd, StaticDlgProc);
  33. return retVal;
  34. }
  35. INT_PTR CALLBACK CNewConDlg::StaticDlgProc(HWND hDlg,UINT uMsg, WPARAM wParam, LPARAM lParam)
  36. {
  37. //
  38. // need access to class variables so redirect to non-static version of callback
  39. //
  40. return m_pThis->DlgProc(hDlg,uMsg,wParam,lParam);
  41. }
  42. INT_PTR
  43. CNewConDlg::DlgProc(HWND hDlg,UINT uMsg, WPARAM wParam, LPARAM)
  44. {
  45. switch (uMsg)
  46. {
  47. case WM_INITDIALOG:
  48. {
  49. //Limit length of these edit boxes
  50. SendMessage(GetDlgItem(hDlg, IDC_DESCRIPTION), EM_LIMITTEXT, CL_MAX_DESC_LENGTH, 0);
  51. SendMessage(GetDlgItem(hDlg, IDC_SERVER), EM_LIMITTEXT, CL_MAX_DOMAIN_LENGTH, 0);
  52. SendMessage(GetDlgItem(hDlg, IDC_USERNAME), EM_LIMITTEXT, CL_MAX_USERNAME_LENGTH, 0);
  53. SendMessage(GetDlgItem(hDlg, IDC_PASSWORD), EM_LIMITTEXT, CL_MAX_PASSWORD_EDIT, 0);
  54. SendMessage(GetDlgItem(hDlg, IDC_DOMAIN), EM_LIMITTEXT, CL_MAX_DOMAIN_LENGTH, 0);
  55. //Save password settings
  56. SendMessage(GetDlgItem(hDlg, IDC_SAVE_PASSWORD), BM_SETCHECK,
  57. m_bSavePassword ? (WPARAM)BST_CHECKED : (WPARAM)BST_UNCHECKED, 0);
  58. //Connect to console settings
  59. SendMessage(GetDlgItem(hDlg, IDC_CONNECT_TO_CONSOLE), BM_SETCHECK,
  60. m_bConnectToConsole ? (WPARAM)BST_CHECKED : (WPARAM)BST_UNCHECKED, 0);
  61. EnableWindow(GetDlgItem(hDlg, IDC_USERNAME), TRUE);
  62. EnableWindow(GetDlgItem(hDlg, IDC_PASSWORD), TRUE);
  63. EnableWindow(GetDlgItem(hDlg, IDC_DOMAIN), TRUE);
  64. EnableWindow(GetDlgItem(hDlg, IDC_USERNAME_STATIC), TRUE);
  65. EnableWindow(GetDlgItem(hDlg, IDC_PASSWORD_STATIC), TRUE);
  66. EnableWindow(GetDlgItem(hDlg, IDC_DOMAIN_STATIC), TRUE);
  67. SetFocus(GetDlgItem(hDlg, IDC_SERVER));
  68. break; // WM_INITDIALOG
  69. }
  70. case WM_COMMAND:
  71. {
  72. if (BN_CLICKED == HIWORD(wParam))
  73. {
  74. if (IDCANCEL == (int) LOWORD(wParam))
  75. {
  76. //
  77. // Cancel out of the dialog
  78. //
  79. EndDialog( hDlg, IDCANCEL);
  80. }
  81. else if (IDOK == (int) LOWORD(wParam))
  82. {
  83. //
  84. // Ok button pressed
  85. // validate and store dialog settings
  86. //
  87. // todo: validate here.
  88. if (!CValidate::Validate(hDlg, m_hInst))
  89. {
  90. return FALSE;
  91. }
  92. //Retrieve the data to be stored.
  93. GetDlgItemText(hDlg, IDC_DESCRIPTION, m_szDescription, MAX_PATH);
  94. GetDlgItemText(hDlg, IDC_SERVER, m_szServer, MAX_PATH);
  95. if (!lstrcmp( m_szDescription, L""))
  96. {
  97. //if no description is specified. Default to the server name
  98. //todo: check for existing server
  99. lstrcpy(m_szDescription, m_szServer);
  100. }
  101. //
  102. // Get user/pass/domain
  103. //
  104. GetDlgItemText(hDlg, IDC_USERNAME, m_szUserName,
  105. CL_MAX_USERNAME_LENGTH - 1);
  106. GetDlgItemText(hDlg, IDC_PASSWORD, m_szPassword,
  107. CL_MAX_PASSWORD_LENGTH_BYTES / sizeof(TCHAR) - 1);
  108. GetDlgItemText(hDlg, IDC_DOMAIN, m_szDomain,
  109. CL_MAX_DOMAIN_LENGTH -1);
  110. if (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_SAVE_PASSWORD))
  111. {
  112. m_bSavePassword = TRUE;
  113. }
  114. else
  115. {
  116. m_bSavePassword = FALSE;
  117. }
  118. if(BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_CONNECT_TO_CONSOLE))
  119. {
  120. m_bConnectToConsole = TRUE;
  121. }
  122. else
  123. {
  124. m_bConnectToConsole = FALSE;
  125. }
  126. EndDialog( hDlg, IDOK);
  127. }
  128. if (IDC_BROWSE_SERVERS == LOWORD(wParam))
  129. {
  130. INT_PTR nResult = IDCANCEL;
  131. CBrowseDlg dlg( hDlg, m_hInst);
  132. nResult = dlg.DoModal();
  133. if (-1 == nResult)
  134. {
  135. ODS(L"DialogBox failed newcondlg.cpp\n");
  136. }
  137. if (IDOK == nResult)
  138. {
  139. SetDlgItemText(hDlg, IDC_SERVER, dlg.GetServer());
  140. //
  141. // set connection name as well if necessary
  142. //
  143. TCHAR szDesc[CL_MAX_DESC_LENGTH];
  144. GetDlgItemText(hDlg, IDC_DESCRIPTION, szDesc, CL_MAX_DESC_LENGTH);
  145. if(!lstrcmp(szDesc, L""))
  146. {
  147. SetDlgItemText(hDlg, IDC_DESCRIPTION, dlg.GetServer());
  148. }
  149. }
  150. SetFocus(hDlg);
  151. }
  152. }
  153. else if (EN_KILLFOCUS == HIWORD(wParam))
  154. {
  155. if(IDC_SERVER == LOWORD(wParam))
  156. {
  157. //
  158. // set connection name to server name if conn name is blank
  159. //
  160. TCHAR szDesc[CL_MAX_DESC_LENGTH];
  161. TCHAR szServer[CL_MAX_DESC_LENGTH];
  162. GetDlgItemText(hDlg, IDC_DESCRIPTION, szDesc, CL_MAX_DESC_LENGTH);
  163. if(!lstrcmp(szDesc, L""))
  164. {
  165. GetDlgItemText(hDlg, IDC_SERVER, szServer, CL_MAX_DOMAIN_LENGTH);
  166. SetDlgItemText(hDlg, IDC_DESCRIPTION, szServer);
  167. }
  168. }
  169. }
  170. else if (EN_CHANGE == HIWORD(wParam))
  171. {
  172. if ((LOWORD(wParam) == IDC_USERNAME))
  173. {
  174. //Handle UPN style user names
  175. //by disabling the domain field if there
  176. //is an @ in the username
  177. TCHAR szUserName[CL_MAX_USERNAME_LENGTH];
  178. BOOL fDisableDomain = FALSE;
  179. GetDlgItemText( hDlg, IDC_USERNAME,
  180. szUserName, SIZEOF_TCHARBUFFER(szUserName));
  181. if(!_tcsstr(szUserName, TEXT("@")))
  182. {
  183. fDisableDomain = TRUE;
  184. }
  185. EnableWindow(GetDlgItem(hDlg, IDC_DOMAIN),
  186. fDisableDomain);
  187. }
  188. }
  189. break; // WM_COMMAND
  190. }
  191. }
  192. return FALSE;
  193. }
  194. BOOL CNewConDlg::GetPasswordSpecified()
  195. {
  196. BOOL fPasswordSpecified = FALSE;
  197. if (_tcslen(m_szPassword) != 0)
  198. {
  199. fPasswordSpecified = TRUE;
  200. }
  201. return fPasswordSpecified;
  202. }