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.

637 lines
12 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name :
  4. connects.cpp
  5. Abstract:
  6. "Connect to a single server" dialog
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Sergei Antonoc (sergeia)
  10. Project:
  11. Internet Services Manager
  12. Revision History:
  13. --*/
  14. #include "stdafx.h"
  15. #include "common.h"
  16. #include "inetprop.h"
  17. #include "InetMgrApp.h"
  18. #include "iisobj.h"
  19. #include "connects.h"
  20. #include "objpick.h"
  21. #define MAX_SERVERNAME_LEN (255)
  22. const LPCTSTR g_cszInetSTPBasePath_ = _T("Software\\Microsoft\\InetStp");
  23. const LPCTSTR g_cszMajorVersion_ = _T("MajorVersion");
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char BASED_CODE THIS_FILE[] = __FILE__;
  27. #endif
  28. extern CInetmgrApp theApp;
  29. //
  30. // CLoginDlg Dialog
  31. //
  32. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  33. CLoginDlg::CLoginDlg(
  34. IN int nType,
  35. IN CIISMachine * pMachine,
  36. IN CWnd * pParent OPTIONAL
  37. )
  38. /*++
  39. Routine Description:
  40. Constructor
  41. Arguments:
  42. int nType : Type of dialog to bring up:
  43. LDLG_ACCESS_DENIED - Access Denied dlg
  44. LDLG_ENTER_PASS - Enter password dlg
  45. LDLG_IMPERSONATION - Impersonation dlg
  46. CIISMachine * pMachine : Machine object
  47. CWnd * pParent : Parent window
  48. Return Value:
  49. --*/
  50. : CDialog(CLoginDlg::IDD, pParent),
  51. m_nType(nType),
  52. m_strOriginalUserName(),
  53. m_strUserName(),
  54. m_strPassword(),
  55. m_pMachine(pMachine)
  56. {
  57. #if 0 // Keep Classwizard happy
  58. //{{AFX_DATA_INIT(CLoginDlg)
  59. m_strPassword = _T("");
  60. m_strUserName = _T("");
  61. //}}AFX_DATA_INIT
  62. #endif // 0
  63. ASSERT_PTR(m_pMachine);
  64. }
  65. void
  66. CLoginDlg::DoDataExchange(
  67. IN OUT CDataExchange * pDX
  68. )
  69. /*++
  70. Routine Description:
  71. Initialise/Store control data
  72. Arguments:
  73. CDataExchange * pDX - DDX/DDV control structure
  74. Return Value:
  75. None
  76. --*/
  77. {
  78. CDialog::DoDataExchange(pDX);
  79. //{{AFX_DATA_MAP(CLoginDlg)
  80. DDX_Text(pDX, IDC_EDIT_USER_NAME, m_strUserName);
  81. DDX_Text(pDX, IDC_EDIT_PASSWORD2, m_strPassword);
  82. DDV_MaxChars(pDX, m_strPassword, PWLEN);
  83. DDX_Control(pDX, IDC_EDIT_USER_NAME, m_edit_UserName);
  84. DDX_Control(pDX, IDC_EDIT_PASSWORD2, m_edit_Password);
  85. DDX_Control(pDX, IDC_STATIC_PROMPT2, m_static_Prompt);
  86. DDX_Control(pDX, IDOK, m_button_Ok);
  87. //}}AFX_DATA_MAP
  88. }
  89. //
  90. // Message Map
  91. //
  92. BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
  93. //{{AFX_MSG_MAP(CLoginDlg)
  94. //}}AFX_MSG_MAP
  95. ON_EN_CHANGE(IDC_EDIT_USER_NAME, SetControlStates)
  96. END_MESSAGE_MAP()
  97. //
  98. // Message Handlers
  99. //
  100. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  101. void
  102. CLoginDlg::SetControlStates()
  103. /*++
  104. Routine Description:
  105. Set UI control enabled/disabled states
  106. Arguments:
  107. None
  108. Return Value:
  109. None
  110. --*/
  111. {
  112. m_button_Ok.EnableWindow(m_edit_UserName.GetWindowTextLength() > 0);
  113. }
  114. BOOL
  115. CLoginDlg::OnInitDialog()
  116. /*++
  117. Routine Description:
  118. WM_INITDIALOG handler. Initialize the dialog.
  119. Arguments:
  120. None.
  121. Return Value:
  122. TRUE if no focus is to be set automatically, FALSE if the focus
  123. is already set.
  124. --*/
  125. {
  126. CDialog::OnInitDialog();
  127. CString str;
  128. switch(m_nType)
  129. {
  130. case LDLG_ENTER_PASS:
  131. //
  132. // Change text for the "Enter Password" dialog
  133. //
  134. VERIFY(str.LoadString(IDS_ENTER_PASSWORD));
  135. SetWindowText(str);
  136. str.Format(IDS_RESOLVE_PASSWORD, m_pMachine->QueryServerName());
  137. m_static_Prompt.SetWindowText(str);
  138. //
  139. // Fall through
  140. //
  141. case LDLG_ACCESS_DENIED:
  142. //
  143. // This is the default text on the dialog
  144. //
  145. m_strUserName = m_strOriginalUserName = m_pMachine->QueryUserName();
  146. if (!m_strUserName.IsEmpty())
  147. {
  148. m_edit_UserName.SetWindowText(m_strUserName);
  149. m_edit_Password.SetFocus();
  150. }
  151. else
  152. {
  153. m_edit_UserName.SetFocus();
  154. }
  155. break;
  156. case LDLG_IMPERSONATION:
  157. VERIFY(str.LoadString(IDS_IMPERSONATION));
  158. SetWindowText(str);
  159. str.Format(IDS_IMPERSONATION_PROMPT, m_pMachine->QueryServerName());
  160. m_static_Prompt.SetWindowText(str);
  161. m_edit_UserName.SetFocus();
  162. break;
  163. default:
  164. ASSERT_MSG("Invalid dialog type");
  165. }
  166. SetControlStates();
  167. return FALSE;
  168. }
  169. void
  170. CLoginDlg::OnOK()
  171. /*++
  172. Routine Description:
  173. OK button handler. Attempt to connect to the machine specified. If
  174. machiname is ok, dismiss the dialog. Otherwise put up an error message
  175. and stay active.
  176. Arguments:
  177. None
  178. Return Value:
  179. None
  180. --*/
  181. {
  182. ASSERT_PTR(m_pMachine);
  183. if (UpdateData(TRUE))
  184. {
  185. CError err(m_pMachine->Impersonate(m_strUserName, m_strPassword));
  186. if (err.Failed())
  187. {
  188. //
  189. // Not a proper impersonation created. Keep the dialog
  190. // open to make corrections.
  191. //
  192. m_pMachine->DisplayError(err);
  193. m_edit_Password.SetSel(0, -1);
  194. m_edit_Password.SetFocus();
  195. return;
  196. }
  197. }
  198. EndDialog(IDOK);
  199. }
  200. //
  201. // Connect to server dialog
  202. //
  203. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  204. ConnectServerDlg::ConnectServerDlg(
  205. IN CWnd * pParent OPTIONAL
  206. )
  207. /*++
  208. Routine Description:
  209. Constructor.
  210. Arguments:
  211. CWnd * pParent : Optional pointer to parent window
  212. Return Value:
  213. N/A
  214. --*/
  215. : CDialog(ConnectServerDlg::IDD, pParent),
  216. m_fImpersonate(FALSE),
  217. m_strServerName(),
  218. m_strPassword(),
  219. m_strUserName(),
  220. m_pMachine(NULL)
  221. {
  222. #if 0 // Keep Classwizard happy
  223. //{{AFX_DATA_INIT(ConnectServerDlg)
  224. m_fImpersonate = FALSE;
  225. m_strServerName = _T("");
  226. m_strUserName = _T("");
  227. m_strPassword = _T("");
  228. //}}AFX_DATA_INIT
  229. #endif // 0
  230. }
  231. void
  232. ConnectServerDlg::DoDataExchange(
  233. IN CDataExchange * pDX
  234. )
  235. /*++
  236. Routine Description:
  237. Initialise/Store control data
  238. Arguments:
  239. CDataExchange * pDX - DDX/DDV control structure
  240. Return Value:
  241. None
  242. --*/
  243. {
  244. CDialog::DoDataExchange(pDX);
  245. //{{AFX_DATA_MAP(ConnectServerDlg)
  246. DDX_Check(pDX, IDC_CHECK_CONNECT_AS, m_fImpersonate);
  247. DDX_Text(pDX, IDC_SERVERNAME, m_strServerName);
  248. DDV_MaxChars(pDX, m_strServerName, MAX_SERVERNAME_LEN);
  249. DDX_Text(pDX, IDC_EDIT_USER_NAME, m_strUserName);
  250. DDX_Text(pDX, IDC_EDIT_PASSWORD2, m_strPassword);
  251. DDV_MaxChars(pDX, m_strPassword, PWLEN);
  252. DDX_Control(pDX, IDC_EDIT_USER_NAME, m_edit_UserName);
  253. DDX_Control(pDX, IDC_EDIT_PASSWORD2, m_edit_Password);
  254. DDX_Control(pDX, IDC_SERVERNAME, m_edit_ServerName);
  255. DDX_Control(pDX, IDC_STATIC_USER_NAME, m_static_UserName);
  256. DDX_Control(pDX, IDC_STATIC_PASSWORD2, m_static_Password);
  257. DDX_Control(pDX, IDOK, m_button_Ok);
  258. //}}AFX_DATA_MAP
  259. }
  260. //
  261. // Message Map
  262. //
  263. BEGIN_MESSAGE_MAP(ConnectServerDlg, CDialog)
  264. //{{AFX_MSG_MAP(ConnectServerDlg)
  265. ON_BN_CLICKED(IDC_CHECK_CONNECT_AS, OnCheckConnectAs)
  266. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  267. ON_BN_CLICKED(ID_HELP, OnButtonHelp)
  268. //}}AFX_MSG_MAP
  269. ON_EN_CHANGE(IDC_SERVERNAME, SetControlStates)
  270. ON_EN_CHANGE(IDC_EDIT_USER_NAME, SetControlStates)
  271. END_MESSAGE_MAP()
  272. void
  273. ConnectServerDlg::SetControlStates()
  274. /*++
  275. Routine Description:
  276. Set UI control enabled/disabled states.
  277. Arguments:
  278. None
  279. Return Value:
  280. None
  281. --*/
  282. {
  283. m_static_UserName.EnableWindow(m_fImpersonate);
  284. m_static_Password.EnableWindow(m_fImpersonate);
  285. m_edit_UserName.EnableWindow(m_fImpersonate);
  286. m_edit_Password.EnableWindow(m_fImpersonate);
  287. m_button_Ok.EnableWindow(
  288. m_edit_ServerName.GetWindowTextLength() > 0 &&
  289. (m_edit_UserName.GetWindowTextLength() > 0 || !m_fImpersonate)
  290. );
  291. }
  292. //
  293. // Message Handlers
  294. //
  295. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  296. BOOL
  297. ConnectServerDlg::OnInitDialog()
  298. /*++
  299. Routine Description:
  300. WM_INITDIALOG handler. Initialize the dialog.
  301. Arguments:
  302. None.
  303. Return Value:
  304. TRUE if no focus is to be set automatically, FALSE if the focus
  305. is already set.
  306. --*/
  307. {
  308. CDialog::OnInitDialog();
  309. SetControlStates();
  310. return TRUE;
  311. }
  312. void
  313. ConnectServerDlg::OnButtonBrowse()
  314. /*++
  315. Routine Description:
  316. 'Browse' button handler. Browse for a computer name
  317. Arguments:
  318. None
  319. Return Value:
  320. None
  321. --*/
  322. {
  323. CGetComputer picker;
  324. if (picker.GetComputer(m_hWnd))
  325. {
  326. m_edit_ServerName.SetWindowText(picker.m_strComputerName);
  327. SetControlStates();
  328. m_button_Ok.SetFocus();
  329. }
  330. #ifdef _DEBUG
  331. else
  332. {
  333. TRACE(_T("ConnectServerDlg::OnButtonBrowse() -> Cannot get computer name from browser\n"));
  334. }
  335. #endif
  336. }
  337. void
  338. ConnectServerDlg::OnCheckConnectAs()
  339. /*++
  340. Routine Description:
  341. "Connect As" checbox event handler. Enable/Disable username/password
  342. controls.
  343. Arguments:
  344. None
  345. Return Value:
  346. None
  347. --*/
  348. {
  349. m_fImpersonate = !m_fImpersonate;
  350. SetControlStates();
  351. if (m_fImpersonate)
  352. {
  353. m_edit_UserName.SetFocus();
  354. m_edit_UserName.SetSel(0, -1);
  355. }
  356. }
  357. void
  358. ConnectServerDlg::OnOK()
  359. /*++
  360. Routine Description:
  361. OK button handler. Attempt to connect to the machine specified. If
  362. machiname is ok, dismiss the dialog. Otherwise put up an error message
  363. and stay active.
  364. Arguments:
  365. None
  366. Return Value:
  367. None
  368. --*/
  369. {
  370. ASSERT(m_pMachine == NULL);
  371. CError err;
  372. if (UpdateData(TRUE))
  373. {
  374. do
  375. {
  376. LPCTSTR lpszUserName = m_fImpersonate ? (LPCTSTR)m_strUserName : NULL;
  377. LPCTSTR lpszPassword = m_fImpersonate ? (LPCTSTR)m_strPassword : NULL;
  378. CString server = m_strServerName;
  379. if (PathIsUNCServer(m_strServerName))
  380. {
  381. server = m_strServerName.Mid(2);
  382. }
  383. else
  384. {
  385. server = m_strServerName;
  386. }
  387. m_pMachine = new CIISMachine(CComAuthInfo(
  388. server,
  389. lpszUserName,
  390. lpszPassword
  391. ));
  392. if (m_pMachine)
  393. {
  394. //
  395. // Verify the machine object is created.
  396. //
  397. err = CIISMachine::VerifyMachine(m_pMachine);
  398. if (err.Failed())
  399. {
  400. //
  401. // Not a proper machine object created. Keep the dialog
  402. // open to make corrections.
  403. //
  404. m_pMachine->DisplayError(err);
  405. m_edit_ServerName.SetSel(0, -1);
  406. m_edit_ServerName.SetFocus();
  407. SAFE_DELETE(m_pMachine);
  408. }
  409. else
  410. {
  411. // IIS5.1 block for iis6 remote administration
  412. CRegKey rk;
  413. rk.Create(HKEY_LOCAL_MACHINE, g_cszInetSTPBasePath_);
  414. DWORD major;
  415. if (ERROR_SUCCESS == rk.QueryValue(major, g_cszMajorVersion_))
  416. {
  417. if (m_pMachine->QueryMajorVersion() == 6 && major == 5)
  418. {
  419. AfxMessageBox(IDS_UPGRADE_TO_IIS6);
  420. SAFE_DELETE(m_pMachine);
  421. }
  422. }
  423. }
  424. }
  425. else
  426. {
  427. err = ERROR_NOT_ENOUGH_MEMORY;
  428. err.MessageBox();
  429. }
  430. }
  431. while(FALSE);
  432. }
  433. //
  434. // Dismiss the dialog only if a proper machine object was created
  435. //
  436. if (m_pMachine)
  437. {
  438. EndDialog(IDOK);
  439. }
  440. }
  441. #define HIDD_CONNECT_SERVER 0x29cd9
  442. void
  443. ConnectServerDlg::OnButtonHelp()
  444. {
  445. ::WinHelp(m_hWnd, theApp.m_pszHelpFilePath, HELP_CONTEXT, HIDD_CONNECT_SERVER);
  446. }