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.

643 lines
13 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. DDX_Text_SecuredString(pDX, IDC_EDIT_PASSWORD2, m_strPassword);
  83. //DDV_MaxCharsBalloon(pDX, m_strPassword, PWLEN);
  84. DDV_MaxCharsBalloon_SecuredString(pDX, m_strPassword, PWLEN);
  85. DDX_Control(pDX, IDC_EDIT_USER_NAME, m_edit_UserName);
  86. DDX_Control(pDX, IDC_EDIT_PASSWORD2, m_edit_Password);
  87. DDX_Control(pDX, IDC_STATIC_PROMPT2, m_static_Prompt);
  88. DDX_Control(pDX, IDOK, m_button_Ok);
  89. //}}AFX_DATA_MAP
  90. }
  91. //
  92. // Message Map
  93. //
  94. BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
  95. //{{AFX_MSG_MAP(CLoginDlg)
  96. //}}AFX_MSG_MAP
  97. ON_EN_CHANGE(IDC_EDIT_USER_NAME, SetControlStates)
  98. END_MESSAGE_MAP()
  99. //
  100. // Message Handlers
  101. //
  102. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  103. void
  104. CLoginDlg::SetControlStates()
  105. /*++
  106. Routine Description:
  107. Set UI control enabled/disabled states
  108. Arguments:
  109. None
  110. Return Value:
  111. None
  112. --*/
  113. {
  114. m_button_Ok.EnableWindow(m_edit_UserName.GetWindowTextLength() > 0);
  115. }
  116. BOOL
  117. CLoginDlg::OnInitDialog()
  118. /*++
  119. Routine Description:
  120. WM_INITDIALOG handler. Initialize the dialog.
  121. Arguments:
  122. None.
  123. Return Value:
  124. TRUE if no focus is to be set automatically, FALSE if the focus
  125. is already set.
  126. --*/
  127. {
  128. CDialog::OnInitDialog();
  129. CString str;
  130. switch(m_nType)
  131. {
  132. case LDLG_ENTER_PASS:
  133. //
  134. // Change text for the "Enter Password" dialog
  135. //
  136. VERIFY(str.LoadString(IDS_ENTER_PASSWORD));
  137. SetWindowText(str);
  138. str.Format(IDS_RESOLVE_PASSWORD, m_pMachine->QueryServerName());
  139. m_static_Prompt.SetWindowText(str);
  140. //
  141. // Fall through
  142. //
  143. case LDLG_ACCESS_DENIED:
  144. //
  145. // This is the default text on the dialog
  146. //
  147. m_strUserName = m_strOriginalUserName = m_pMachine->QueryUserName();
  148. if (!m_strUserName.IsEmpty())
  149. {
  150. m_edit_UserName.SetWindowText(m_strUserName);
  151. m_edit_Password.SetFocus();
  152. }
  153. else
  154. {
  155. m_edit_UserName.SetFocus();
  156. }
  157. break;
  158. case LDLG_IMPERSONATION:
  159. VERIFY(str.LoadString(IDS_IMPERSONATION));
  160. SetWindowText(str);
  161. str.Format(IDS_IMPERSONATION_PROMPT, m_pMachine->QueryServerName());
  162. m_static_Prompt.SetWindowText(str);
  163. m_edit_UserName.SetFocus();
  164. break;
  165. default:
  166. ASSERT_MSG("Invalid dialog type");
  167. }
  168. SetControlStates();
  169. return FALSE;
  170. }
  171. void
  172. CLoginDlg::OnOK()
  173. /*++
  174. Routine Description:
  175. OK button handler. Attempt to connect to the machine specified. If
  176. machiname is ok, dismiss the dialog. Otherwise put up an error message
  177. and stay active.
  178. Arguments:
  179. None
  180. Return Value:
  181. None
  182. --*/
  183. {
  184. ASSERT_PTR(m_pMachine);
  185. if (UpdateData(TRUE))
  186. {
  187. CString csTempPassword;
  188. m_strPassword.CopyTo(csTempPassword);
  189. CError err(m_pMachine->Impersonate(m_strUserName, csTempPassword));
  190. if (err.Failed())
  191. {
  192. //
  193. // Not a proper impersonation created. Keep the dialog
  194. // open to make corrections.
  195. //
  196. m_pMachine->DisplayError(err, m_hWnd);
  197. m_edit_Password.SetSel(0, -1);
  198. m_edit_Password.SetFocus();
  199. return;
  200. }
  201. }
  202. EndDialog(IDOK);
  203. }
  204. //
  205. // Connect to server dialog
  206. //
  207. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  208. ConnectServerDlg::ConnectServerDlg(
  209. IN IConsoleNameSpace * pConsoleNameSpace,
  210. IN IConsole * pConsole,
  211. IN CWnd * pParent OPTIONAL
  212. )
  213. /*++
  214. Routine Description:
  215. Constructor.
  216. Arguments:
  217. CWnd * pParent : Optional pointer to parent window
  218. Return Value:
  219. N/A
  220. --*/
  221. : CDialog(ConnectServerDlg::IDD, pParent),
  222. m_fImpersonate(FALSE),
  223. m_strServerName(),
  224. m_strPassword(),
  225. m_strUserName(),
  226. m_pMachine(NULL),
  227. m_pConsoleNameSpace(pConsoleNameSpace),
  228. m_pConsole(pConsole)
  229. {
  230. #if 0 // Keep Classwizard happy
  231. //{{AFX_DATA_INIT(ConnectServerDlg)
  232. m_fImpersonate = FALSE;
  233. m_strServerName = _T("");
  234. m_strUserName = _T("");
  235. m_strPassword = _T("");
  236. //}}AFX_DATA_INIT
  237. #endif // 0
  238. }
  239. void
  240. ConnectServerDlg::DoDataExchange(
  241. IN CDataExchange * pDX
  242. )
  243. /*++
  244. Routine Description:
  245. Initialise/Store control data
  246. Arguments:
  247. CDataExchange * pDX - DDX/DDV control structure
  248. Return Value:
  249. None
  250. --*/
  251. {
  252. CDialog::DoDataExchange(pDX);
  253. //{{AFX_DATA_MAP(ConnectServerDlg)
  254. DDX_Check(pDX, IDC_CHECK_CONNECT_AS, m_fImpersonate);
  255. DDX_Text(pDX, IDC_SERVERNAME, m_strServerName);
  256. DDV_MaxCharsBalloon(pDX, m_strServerName, MAX_SERVERNAME_LEN);
  257. DDX_Text(pDX, IDC_EDIT_USER_NAME, m_strUserName);
  258. //DDX_Text(pDX, IDC_EDIT_PASSWORD2, m_strPassword);
  259. DDX_Text_SecuredString(pDX, IDC_EDIT_PASSWORD2, m_strPassword);
  260. //DDV_MaxCharsBalloon(pDX, m_strPassword, PWLEN);
  261. DDV_MaxCharsBalloon_SecuredString(pDX, m_strPassword, PWLEN);
  262. DDX_Control(pDX, IDC_EDIT_USER_NAME, m_edit_UserName);
  263. DDX_Control(pDX, IDC_EDIT_PASSWORD2, m_edit_Password);
  264. DDX_Control(pDX, IDC_SERVERNAME, m_edit_ServerName);
  265. DDX_Control(pDX, IDC_STATIC_USER_NAME, m_static_UserName);
  266. DDX_Control(pDX, IDC_STATIC_PASSWORD2, m_static_Password);
  267. DDX_Control(pDX, IDOK, m_button_Ok);
  268. //}}AFX_DATA_MAP
  269. }
  270. //
  271. // Message Map
  272. //
  273. BEGIN_MESSAGE_MAP(ConnectServerDlg, CDialog)
  274. //{{AFX_MSG_MAP(ConnectServerDlg)
  275. ON_BN_CLICKED(IDC_CHECK_CONNECT_AS, OnCheckConnectAs)
  276. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  277. ON_BN_CLICKED(ID_HELP, OnButtonHelp)
  278. //}}AFX_MSG_MAP
  279. ON_EN_CHANGE(IDC_SERVERNAME, SetControlStates)
  280. ON_EN_CHANGE(IDC_EDIT_USER_NAME, SetControlStates)
  281. END_MESSAGE_MAP()
  282. void
  283. ConnectServerDlg::SetControlStates()
  284. /*++
  285. Routine Description:
  286. Set UI control enabled/disabled states.
  287. Arguments:
  288. None
  289. Return Value:
  290. None
  291. --*/
  292. {
  293. m_static_UserName.EnableWindow(m_fImpersonate);
  294. m_static_Password.EnableWindow(m_fImpersonate);
  295. m_edit_UserName.EnableWindow(m_fImpersonate);
  296. m_edit_Password.EnableWindow(m_fImpersonate);
  297. m_button_Ok.EnableWindow(
  298. m_edit_ServerName.GetWindowTextLength() > 0 &&
  299. (m_edit_UserName.GetWindowTextLength() > 0 || !m_fImpersonate)
  300. );
  301. }
  302. //
  303. // Message Handlers
  304. //
  305. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  306. BOOL
  307. ConnectServerDlg::OnInitDialog()
  308. /*++
  309. Routine Description:
  310. WM_INITDIALOG handler. Initialize the dialog.
  311. Arguments:
  312. None.
  313. Return Value:
  314. TRUE if no focus is to be set automatically, FALSE if the focus
  315. is already set.
  316. --*/
  317. {
  318. CDialog::OnInitDialog();
  319. SetControlStates();
  320. return TRUE;
  321. }
  322. void
  323. ConnectServerDlg::OnButtonBrowse()
  324. /*++
  325. Routine Description:
  326. 'Browse' button handler. Browse for a computer name
  327. Arguments:
  328. None
  329. Return Value:
  330. None
  331. --*/
  332. {
  333. CGetComputer picker;
  334. if (picker.GetComputer(m_hWnd))
  335. {
  336. m_edit_ServerName.SetWindowText(picker.m_strComputerName);
  337. SetControlStates();
  338. m_button_Ok.SetFocus();
  339. }
  340. #ifdef _DEBUG
  341. else
  342. {
  343. TRACE(_T("ConnectServerDlg::OnButtonBrowse() -> Cannot get computer name from browser\n"));
  344. }
  345. #endif
  346. }
  347. void
  348. ConnectServerDlg::OnCheckConnectAs()
  349. /*++
  350. Routine Description:
  351. "Connect As" checbox event handler. Enable/Disable username/password
  352. controls.
  353. Arguments:
  354. None
  355. Return Value:
  356. None
  357. --*/
  358. {
  359. m_fImpersonate = !m_fImpersonate;
  360. SetControlStates();
  361. if (m_fImpersonate)
  362. {
  363. m_edit_UserName.SetFocus();
  364. m_edit_UserName.SetSel(0, -1);
  365. }
  366. }
  367. void
  368. ConnectServerDlg::OnOK()
  369. /*++
  370. Routine Description:
  371. OK button handler. Attempt to connect to the machine specified. If
  372. machiname is ok, dismiss the dialog. Otherwise put up an error message
  373. and stay active.
  374. Arguments:
  375. None
  376. Return Value:
  377. None
  378. --*/
  379. {
  380. ASSERT(m_pMachine == NULL);
  381. CError err;
  382. if (UpdateData(TRUE))
  383. {
  384. do
  385. {
  386. CString csTempPassword;
  387. m_strPassword.CopyTo(csTempPassword);
  388. LPCTSTR lpszUserName = m_fImpersonate ? (LPCTSTR)m_strUserName : NULL;
  389. LPCTSTR lpszPassword = m_fImpersonate ? (LPCTSTR)csTempPassword : NULL;
  390. CString server = m_strServerName;
  391. if (PathIsUNCServer(m_strServerName))
  392. {
  393. server = m_strServerName.Mid(2);
  394. }
  395. else
  396. {
  397. server = m_strServerName;
  398. }
  399. m_pMachine = new CIISMachine(m_pConsoleNameSpace,m_pConsole,CComAuthInfo(server,lpszUserName,lpszPassword));
  400. if (m_pMachine)
  401. {
  402. //
  403. // Verify the machine object is created.
  404. //
  405. err = CIISMachine::VerifyMachine(m_pMachine);
  406. if (err.Failed())
  407. {
  408. //
  409. // Not a proper machine object created. Keep the dialog
  410. // open to make corrections.
  411. //
  412. m_pMachine->DisplayError(err, m_hWnd);
  413. m_edit_ServerName.SetSel(0, -1);
  414. m_edit_ServerName.SetFocus();
  415. m_pMachine->Release();
  416. m_pMachine = NULL;
  417. }
  418. else
  419. {
  420. // IIS5.1 block for iis6 remote administration
  421. CRegKey rk;
  422. rk.Create(HKEY_LOCAL_MACHINE, g_cszInetSTPBasePath_);
  423. DWORD major;
  424. if (ERROR_SUCCESS == rk.QueryValue(major, g_cszMajorVersion_))
  425. {
  426. if (m_pMachine->QueryMajorVersion() == 6 && major == 5)
  427. {
  428. DoHelpMessageBox(m_hWnd,IDS_UPGRADE_TO_IIS6, MB_APPLMODAL | MB_OK | MB_ICONINFORMATION, 0);
  429. m_pMachine->Release();
  430. m_pMachine = NULL;
  431. }
  432. }
  433. }
  434. }
  435. else
  436. {
  437. err = ERROR_NOT_ENOUGH_MEMORY;
  438. err.MessageBox(m_hWnd);
  439. }
  440. }
  441. while(FALSE);
  442. }
  443. if (m_pMachine != NULL)
  444. {
  445. EndDialog(IDOK);
  446. }
  447. }
  448. #define HIDD_CONNECT_SERVER 0x29cd9
  449. void
  450. ConnectServerDlg::OnButtonHelp()
  451. {
  452. WinHelpDebug(HIDD_CONNECT_SERVER);
  453. ::WinHelp(m_hWnd, theApp.m_pszHelpFilePath, HELP_CONTEXT, HIDD_CONNECT_SERVER);
  454. }