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.

485 lines
13 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : WzConnectToServer.cpp //
  3. // //
  4. // DESCRIPTION : This file implements the dialog for retargeting to //
  5. // another running Microsoft Fax Server. //
  6. // //
  7. // AUTHOR : yossg //
  8. // //
  9. // HISTORY : //
  10. // Jun 26 2000 yossg Create //
  11. // //
  12. // Copyright (C) 2000 Microsoft Corporation All Rights Reserved //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #include "StdAfx.h"
  15. #include "WzConnectToServer.h"
  16. #include "Snapin.h"
  17. #include "FxsValid.h"
  18. #include "dlgutils.h"
  19. #include <Objsel.h> //DSOP_SCOPE_INIT_INFO for DsObjectPicker
  20. #include <windns.h> //DNS_MAX_NAME_BUFFER_LENGTH
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CWzConnectToServer
  23. CWzConnectToServer::CWzConnectToServer(CSnapInItem *pNode)
  24. : CSnapInPropertyPageImpl<CWzConnectToServer>(NULL)
  25. {
  26. m_pRoot = static_cast<CFaxServerNode *>(pNode);
  27. }
  28. CWzConnectToServer::~CWzConnectToServer()
  29. {
  30. }
  31. /*
  32. + CWzConnectToServer::OnInitDialog
  33. +
  34. * Purpose:
  35. * Initiate all dialog controls.
  36. *
  37. * Arguments:
  38. * [in] uMsg : Value identifying the event.
  39. * [in] lParam : Message-specific value.
  40. * [in] wParam : Message-specific value.
  41. * [in] bHandled : bool value.
  42. *
  43. - Return:
  44. - 0 or 1
  45. */
  46. LRESULT
  47. CWzConnectToServer::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  48. {
  49. DEBUG_FUNCTION_NAME( _T("CWzConnectToServer::OnInitDialog"));
  50. HRESULT hRc = S_OK;
  51. //
  52. // Attach controls
  53. //
  54. m_ServerNameEdit.Attach(GetDlgItem(IDC_CONNECT_COMPUTER_NAME_EDIT));
  55. //
  56. // Set length limit
  57. //
  58. m_ServerNameEdit.SetLimitText(DNS_MAX_NAME_BUFFER_LENGTH);
  59. //
  60. // Init the other controls
  61. //
  62. CheckDlgButton(IDC_CONNECT_LOCAL_RADIO1, BST_CHECKED);
  63. CheckDlgButton(IDC_CONNECT_ANOTHER_RADIO2, BST_UNCHECKED);
  64. CheckDlgButton(IDC_CONNECT_OVERRIDE_CHECK, BST_UNCHECKED);
  65. //
  66. // Disable remote computer controls
  67. //
  68. EnableSpecifiedServerControls(FALSE);
  69. return 1;
  70. }
  71. /*
  72. + CWzConnectToServer::OnSetActive
  73. +
  74. * Purpose:
  75. *
  76. *
  77. * Arguments:
  78. *
  79. - Return:
  80. - TRUE or FALSE
  81. */
  82. BOOL CWzConnectToServer::OnSetActive()
  83. {
  84. DEBUG_FUNCTION_NAME( _T("CWzConnectToServer::OnSetActive"));
  85. //
  86. // Must use post message during the setactive message.
  87. //
  88. CWindow( GetParent() ).PostMessage( PSM_SETWIZBUTTONS, 0, PSWIZB_FINISH );
  89. return TRUE;
  90. }
  91. /*
  92. + CWzConnectToServer::OnWizardFinish
  93. +
  94. * Purpose:
  95. * To apply data when wizard finish .
  96. *
  97. * Arguments:
  98. * [in] uMsg : Value identifying the event.
  99. * [in] lParam : Message-specific value.
  100. * [in] wParam : Message-specific value.
  101. * [in] bHandled : bool value.
  102. *
  103. - Return:
  104. - 0 or 1
  105. */
  106. BOOL CWzConnectToServer::OnWizardFinish()
  107. {
  108. DEBUG_FUNCTION_NAME( _T("CWzConnectToServer::OnWizardFinish"));
  109. ATLASSERT (m_pRoot);
  110. HRESULT hRc = S_OK;
  111. DWORD ec = ERROR_SUCCESS;
  112. BOOL fIsLocalServer = TRUE;
  113. CComBSTR bstrServerName = L"";
  114. BOOL fAllowOverrideServerName = FALSE;
  115. //
  116. // Step 1: get data
  117. //
  118. fIsLocalServer = ( IsDlgButtonChecked(IDC_CONNECT_LOCAL_RADIO1) == BST_CHECKED );
  119. if(fIsLocalServer)
  120. {
  121. bstrServerName = L"";
  122. if (!bstrServerName)
  123. {
  124. hRc = E_OUTOFMEMORY;
  125. goto Exit;
  126. }
  127. }
  128. else //!fIsLocalServer => the other server radio button was clicked.
  129. {
  130. //
  131. // 1.a: PreApply Checks
  132. //
  133. if ( !m_ServerNameEdit.GetWindowText(&bstrServerName))
  134. {
  135. DebugPrintEx(
  136. DEBUG_ERR,
  137. TEXT("Failed to GetWindowText(&m_bstrGroupName)"));
  138. DlgMsgBox(this, IDS_FAIL2READ_GROUPNAME);
  139. ::SetFocus(GetDlgItem(IDC_CONNECT_COMPUTER_NAME_EDIT));
  140. hRc = S_FALSE;
  141. goto Exit;
  142. }
  143. //
  144. // Server Name initial \\ trancation (if they are there)
  145. //
  146. if ( ( _tcslen(bstrServerName.m_str) > 2 ) && ( 0 == wcsncmp( bstrServerName.m_str , _T("\\\\") , 2 )) )
  147. {
  148. CComBSTR bstrTmp = _tcsninc(bstrServerName.m_str, 2);
  149. if (!bstrTmp)
  150. {
  151. DebugPrintEx(DEBUG_ERR,
  152. _T("Out of memory -bstr allocation error."));
  153. DlgMsgBox(this, IDS_MEMORY);
  154. ::SetFocus(GetDlgItem(IDC_CONNECT_COMPUTER_NAME_EDIT));
  155. hRc = S_FALSE;
  156. goto Exit;
  157. }
  158. bstrServerName.Empty();
  159. bstrServerName = bstrTmp; // operator = is actually copy() here.
  160. }
  161. //
  162. // Server Name validity checks
  163. //
  164. UINT uRetIDS = 0;
  165. if (!IsValidServerNameString(bstrServerName, &uRetIDS, TRUE /*DNS Name Length*/))
  166. {
  167. ATLASSERT ( 0 == uRetIDS);
  168. DebugPrintEx(DEBUG_ERR,
  169. _T("Non valid server name."));
  170. DlgMsgBox(this, uRetIDS);
  171. ::SetFocus(GetDlgItem(IDC_CONNECT_COMPUTER_NAME_EDIT));
  172. hRc = S_FALSE;
  173. goto Exit;
  174. }
  175. if ( IsLocalServerName(bstrServerName.m_str) )
  176. {
  177. DebugPrintEx( DEBUG_MSG,
  178. _T("The computer name %ws is the same as the name of the current managed server."),
  179. bstrServerName.m_str);
  180. bstrServerName = L"";
  181. }
  182. }
  183. //
  184. // Allow override
  185. //
  186. if (IsDlgButtonChecked(IDC_CONNECT_OVERRIDE_CHECK) == BST_CHECKED)
  187. {
  188. fAllowOverrideServerName = TRUE;
  189. }
  190. //else: fAllowOverrideServerName = FALSE is the default;
  191. //
  192. // Step 2: passed the machine name and the permission to override
  193. //
  194. //
  195. // Redraw main node display name
  196. //
  197. hRc = m_pRoot->SetServerNameOnSnapinAddition(bstrServerName, fAllowOverrideServerName);
  198. if (S_OK != hRc )
  199. {
  200. //error message given by the called function
  201. DebugPrintEx( DEBUG_ERR,
  202. _T("Failed to SetServerNameOnSnapinAddition(bstrServerName)"));
  203. goto Exit;
  204. }
  205. //
  206. // Step 3: Close the dialog
  207. //
  208. ATLASSERT(S_OK == hRc && ERROR_SUCCESS == ec);
  209. DebugPrintEx( DEBUG_MSG,
  210. _T("The connection to the new server was done successfully."));
  211. goto Exit;
  212. Exit:
  213. return (S_OK != hRc) ? FALSE : TRUE;
  214. }
  215. /*
  216. - CWzConnectToServer::OnComputerRadioButtonClicked
  217. -
  218. * Purpose:
  219. * Check status OnComputerRadioButtonClicked
  220. *
  221. * Arguments:
  222. *
  223. * Return:
  224. * 1
  225. */
  226. LRESULT
  227. CWzConnectToServer::OnComputerRadioButtonClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  228. {
  229. UNREFERENCED_PARAMETER (wNotifyCode);
  230. UNREFERENCED_PARAMETER (wID);
  231. UNREFERENCED_PARAMETER (hWndCtl);
  232. UNREFERENCED_PARAMETER (bHandled);
  233. DEBUG_FUNCTION_NAME( _T("CWzConnectToServer::OnComputerRadioButtonClicked"));
  234. if ( IsDlgButtonChecked(IDC_CONNECT_ANOTHER_RADIO2) == BST_CHECKED )
  235. {
  236. EnableSpecifiedServerControls(TRUE);
  237. ::SetFocus(GetDlgItem(IDC_CONNECT_COMPUTER_NAME_EDIT));
  238. }
  239. else //connect to local server
  240. {
  241. EnableSpecifiedServerControls(FALSE);
  242. }
  243. return 1;
  244. }
  245. /*
  246. - CWzConnectToServer::OnTextChanged
  247. -
  248. * Purpose:
  249. * Check the validity of text in side the text box.
  250. *
  251. * Arguments:
  252. *
  253. * Return:
  254. * 1
  255. */
  256. LRESULT
  257. CWzConnectToServer::OnTextChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  258. {
  259. UNREFERENCED_PARAMETER (wNotifyCode);
  260. UNREFERENCED_PARAMETER (wID);
  261. UNREFERENCED_PARAMETER (hWndCtl);
  262. UNREFERENCED_PARAMETER (bHandled);
  263. DEBUG_FUNCTION_NAME( _T("CWzConnectToServer::OnTextChanged"));
  264. //actually in the current design, do nothing
  265. return 1;
  266. }
  267. /*
  268. - CWzConnectToServer::EnableSpecifiedServerControls
  269. -
  270. * Purpose:
  271. * Enable/disable the specified server controls.
  272. *
  273. * Arguments:
  274. * [in] state - boolean value to enable TRUE or FALSE to disable
  275. *
  276. * Return:
  277. * void
  278. */
  279. void CWzConnectToServer::EnableSpecifiedServerControls(BOOL fState)
  280. {
  281. //
  282. // enable/disable controls
  283. //
  284. ::EnableWindow(GetDlgItem(IDC_CONNECT_COMPUTER_NAME_EDIT), fState);
  285. ::EnableWindow(GetDlgItem(IDC_CONNECT_BROWSE4SERVER_BUTTON), fState);
  286. }
  287. /*
  288. - CWzConnectToServer::OnBrowseForMachine
  289. -
  290. * Purpose:
  291. * Enable/disable the specified server controls.
  292. *
  293. * Arguments:
  294. *
  295. * Return:
  296. * OLE error code
  297. */
  298. static UINT g_cfDsObjectPicker =
  299. RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
  300. LRESULT CWzConnectToServer::OnBrowseForMachine(UINT /*uMsg*/, WPARAM /*wParam*/, HWND /*hwnd*/, BOOL& /*bHandled*/)
  301. {
  302. HRESULT hr = S_OK;
  303. static const int SCOPE_INIT_COUNT = 1;
  304. DSOP_SCOPE_INIT_INFO aScopeInit[SCOPE_INIT_COUNT];
  305. DEBUG_FUNCTION_NAME( _T("CWzConnectToServer::OnBrowseForMachine"));
  306. ZeroMemory(aScopeInit, sizeof(DSOP_SCOPE_INIT_INFO) * SCOPE_INIT_COUNT);
  307. //
  308. // Since we just want computer objects from every scope, combine them
  309. // all in a single scope initializer.
  310. //
  311. aScopeInit[0].cbSize = sizeof(DSOP_SCOPE_INIT_INFO);
  312. aScopeInit[0].flType = DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN
  313. | DSOP_SCOPE_TYPE_GLOBAL_CATALOG
  314. | DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN
  315. | DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN
  316. | DSOP_SCOPE_TYPE_WORKGROUP
  317. | DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE
  318. | DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE;
  319. aScopeInit[0].FilterFlags.Uplevel.flBothModes =
  320. DSOP_FILTER_COMPUTERS;
  321. aScopeInit[0].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  322. //
  323. // Put the scope init array into the object picker init array
  324. //
  325. DSOP_INIT_INFO InitInfo;
  326. ZeroMemory(&InitInfo, sizeof(InitInfo));
  327. InitInfo.cbSize = sizeof(InitInfo);
  328. InitInfo.pwzTargetComputer = NULL; // NULL == local machine
  329. InitInfo.cDsScopeInfos = SCOPE_INIT_COUNT;
  330. InitInfo.aDsScopeInfos = aScopeInit;
  331. //
  332. // Note object picker makes its own copy of InitInfo. Also note
  333. // that Initialize may be called multiple times, last call wins.
  334. //
  335. IDsObjectPicker *pDsObjectPicker = NULL;
  336. IDataObject *pdo = NULL;
  337. bool fGotStgMedium = false;
  338. STGMEDIUM stgmedium =
  339. {
  340. TYMED_HGLOBAL,
  341. NULL,
  342. NULL
  343. };
  344. do
  345. {
  346. hr = CoCreateInstance(CLSID_DsObjectPicker,
  347. NULL,
  348. CLSCTX_INPROC_SERVER,
  349. IID_IDsObjectPicker,
  350. (void **) &pDsObjectPicker);
  351. if(FAILED(hr))
  352. break;
  353. hr = pDsObjectPicker->Initialize(&InitInfo);
  354. if(FAILED(hr))
  355. break;
  356. hr = pDsObjectPicker->InvokeDialog(m_hWnd, &pdo);
  357. if(FAILED(hr))
  358. break;
  359. // Quit if user hit Cancel
  360. if (hr == S_FALSE)
  361. {
  362. break;
  363. }
  364. FORMATETC formatetc =
  365. {
  366. (CLIPFORMAT)g_cfDsObjectPicker,
  367. NULL,
  368. DVASPECT_CONTENT,
  369. -1,
  370. TYMED_HGLOBAL
  371. };
  372. hr = pdo->GetData(&formatetc, &stgmedium);
  373. if(FAILED(hr))
  374. break;
  375. fGotStgMedium = true;
  376. PDS_SELECTION_LIST pDsSelList =
  377. (PDS_SELECTION_LIST) GlobalLock(stgmedium.hGlobal);
  378. if (!pDsSelList)
  379. {
  380. break;
  381. }
  382. ATLASSERT(pDsSelList->cItems == 1);
  383. //
  384. // Put the machine name in the edit control
  385. //
  386. SetDlgItemText(IDC_CONNECT_COMPUTER_NAME_EDIT, pDsSelList->aDsSelection[0].pwzName);
  387. GlobalUnlock(stgmedium.hGlobal);
  388. } while (0);
  389. if (fGotStgMedium)
  390. {
  391. ReleaseStgMedium(&stgmedium);
  392. }
  393. if (pDsObjectPicker)
  394. {
  395. pDsObjectPicker->Release();
  396. }
  397. return hr;
  398. }
  399. /////////////////////////////////////////////////////////////////////////////