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.

593 lines
15 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1997 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Iis.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CNNTPVirtualRootParamsPage class.
  10. //
  11. // Author:
  12. // Pete Benoit (v-pbenoi) October 16, 1996
  13. // David Potter (davidp) October 17, 1996
  14. //
  15. // Revision History:
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include <inetinfo.h>
  22. #include "IISClEx4.h"
  23. #include "nntpprop.h"
  24. #include "ExtObj.h"
  25. #include "DDxDDv.h"
  26. #include "HelpData.h" // for g_rghelpmap*
  27. #include <iadm.h>
  28. #include <iiscnfgp.h>
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CNNTPVirtualRootParamsPage property page
  36. /////////////////////////////////////////////////////////////////////////////
  37. IMPLEMENT_DYNCREATE(CNNTPVirtualRootParamsPage, CBasePropertyPage)
  38. /////////////////////////////////////////////////////////////////////////////
  39. // Message Maps
  40. BEGIN_MESSAGE_MAP(CNNTPVirtualRootParamsPage, CBasePropertyPage)
  41. //{{AFX_MSG_MAP(CNNTPVirtualRootParamsPage)
  42. ON_CBN_SELCHANGE(IDC_PP_NNTP_INSTANCEID, OnChangeRequiredField)
  43. ON_BN_CLICKED(IDC_PP_NNTP_REFRESH, OnRefresh)
  44. //}}AFX_MSG_MAP
  45. // TODO: Modify the following lines to represent the data displayed on this page.
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. //++
  49. //
  50. // CNNTPVirtualRootParamsPage::CNNTPVirtualRootParamsPage
  51. //
  52. // Routine Description:
  53. // Default constructor.
  54. //
  55. // Arguments:
  56. // None.
  57. //
  58. // Return Value:
  59. // None.
  60. //
  61. //--
  62. /////////////////////////////////////////////////////////////////////////////
  63. CNNTPVirtualRootParamsPage::CNNTPVirtualRootParamsPage(void)
  64. : CBasePropertyPage(g_rghelpmapIISParameters)
  65. {
  66. // TODO: Modify the following lines to represent the data displayed on this page.
  67. //{{AFX_DATA_INIT(CNNTPVirtualRootParamsPage)
  68. m_strInstanceId = _T("");
  69. //}}AFX_DATA_INIT
  70. m_fReadList = FALSE;
  71. try
  72. {
  73. m_strServiceName = IIS_SVC_NAME_NNTP;
  74. } // try
  75. catch (CMemoryException * pme)
  76. {
  77. pme->ReportError();
  78. pme->Delete();
  79. } // catch: CMemoryException
  80. // Setup the property array.
  81. {
  82. m_rgProps[epropServiceName].Set(REGPARAM_IIS_SERVICE_NAME, m_strServiceName, m_strPrevServiceName);
  83. m_rgProps[epropInstanceId].Set(REGPARAM_IIS_INSTANCEID, m_strInstanceId, m_strPrevInstanceId);
  84. } // Setup the property array
  85. m_iddPropertyPage = IDD_PP_NNTP_PARAMETERS;
  86. m_iddWizardPage = IDD_WIZ_NNTP_PARAMETERS;
  87. m_idcPPTitle = IDC_PP_NNTP_TITLE;
  88. } //*** CNNTPVirtualRootParamsPage::CNNTPVirtualRootParamsPage()
  89. /////////////////////////////////////////////////////////////////////////////
  90. //++
  91. //
  92. // CNNTPVirtualRootParamsPage::DoDataExchange
  93. //
  94. // Routine Description:
  95. // Do data exchange between the dialog and the class.
  96. //
  97. // Arguments:
  98. // pDX [IN OUT] Data exchange object
  99. //
  100. // Return Value:
  101. // None.
  102. //
  103. //--
  104. /////////////////////////////////////////////////////////////////////////////
  105. void CNNTPVirtualRootParamsPage::DoDataExchange(CDataExchange * pDX)
  106. {
  107. CString strInstanceId;
  108. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  109. CBasePropertyPage::DoDataExchange(pDX);
  110. // TODO: Modify the following lines to represent the data displayed on this page.
  111. //{{AFX_DATA_MAP(CNNTPVirtualRootParamsPage)
  112. DDX_Control(pDX, IDC_PP_NNTP_INSTANCEID, m_cInstanceId);
  113. DDX_Text(pDX, IDC_PP_NNTP_INSTANCEID, m_strInstanceName);
  114. //}}AFX_DATA_MAP
  115. if (pDX->m_bSaveAndValidate)
  116. {
  117. if (!BBackPressed())
  118. {
  119. DDV_RequiredText(pDX, IDC_PP_NNTP_INSTANCEID, IDC_PP_NNTP_INSTANCEID_LABEL, m_strInstanceName);
  120. } // if: Back button not pressed
  121. m_strInstanceId = NameToMetabaseId( m_strInstanceName );
  122. m_strServiceName = IIS_SVC_NAME_NNTP;
  123. } // if: saving data from dialog
  124. } //*** CNNTPVirtualRootParamsPage::DoDataExchange()
  125. /////////////////////////////////////////////////////////////////////////////
  126. //++
  127. //
  128. // CNNTPVirtualRootParamsPage::OnInitDialog
  129. //
  130. // Routine Description:
  131. // Handler for the WM_INITDIALOG message.
  132. //
  133. // Arguments:
  134. // None.
  135. //
  136. // Return Value:
  137. // TRUE We need the focus to be set for us.
  138. // FALSE We already set the focus to the proper control.
  139. //
  140. //--
  141. /////////////////////////////////////////////////////////////////////////////
  142. BOOL CNNTPVirtualRootParamsPage::OnInitDialog(void)
  143. {
  144. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  145. CBasePropertyPage::OnInitDialog();
  146. m_cInstanceId.EnableWindow( TRUE );
  147. OnChangeCtrl();
  148. if (!BWizard())
  149. {
  150. FillServerList();
  151. }
  152. return TRUE; // return TRUE unless you set the focus to a control
  153. // EXCEPTION: OCX Property Pages should return FALSE
  154. } //*** CNNTPVirtualRootParamsPage::OnInitDialog()
  155. /////////////////////////////////////////////////////////////////////////////
  156. //++
  157. //
  158. // CNNTPVirtualRootParamsPage::OnSetActive
  159. //
  160. // Routine Description:
  161. // Handler for the PSN_SETACTIVE message.
  162. //
  163. // Arguments:
  164. // None.
  165. //
  166. // Return Value:
  167. // TRUE Page successfully initialized.
  168. // FALSE Page not initialized.
  169. //
  170. //--
  171. /////////////////////////////////////////////////////////////////////////////
  172. BOOL CNNTPVirtualRootParamsPage::OnSetActive(void)
  173. {
  174. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  175. // Enable/disable the Next/Finish button.
  176. if (BWizard())
  177. {
  178. FillServerList();
  179. } // if: in the wizard
  180. return CBasePropertyPage::OnSetActive();
  181. } //*** CNNTPVirtualRootParamsPage::OnSetActive()
  182. /////////////////////////////////////////////////////////////////////////////
  183. //++
  184. //
  185. // CNNTPVirtualRootParamsPage::OnChangeRequiredField
  186. //
  187. // Routine Description:
  188. // Handler for the EN_CHANGE message on the Share name or Path edit
  189. // controls.
  190. //
  191. // Arguments:
  192. // None.
  193. //
  194. // Return Value:
  195. // None.
  196. //
  197. //--
  198. /////////////////////////////////////////////////////////////////////////////
  199. void CNNTPVirtualRootParamsPage::OnChangeRequiredField(void)
  200. {
  201. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  202. OnChangeCtrl();
  203. if (BWizard())
  204. {
  205. SetEnableNext();
  206. } // if: in a wizard
  207. } //*** CNNTPVirtualRootParamsPage::OnChangeRequiredField()
  208. ////
  209. void
  210. CNNTPVirtualRootParamsPage::FillServerList(
  211. )
  212. /*++
  213. Routine Description:
  214. Populate server combo box with server list relevant to current service type,
  215. set current selection based on server instance ID
  216. enable Finish button if list non empty
  217. Arguments:
  218. None
  219. Returns:
  220. Nothing
  221. --*/
  222. {
  223. int nIndex;
  224. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  225. //
  226. // build array if not already done
  227. //
  228. if ( !m_fReadList )
  229. {
  230. HRESULT hr;
  231. hr = ReadList( &m_ServiceArray, MD_SERVICE_ROOT_NNTP, LPCTSTR(Peo()->StrNodeName()) );
  232. if (FAILED(hr))
  233. {
  234. CString err;
  235. if ( REGDB_E_IIDNOTREG == hr)
  236. {
  237. err.Format(IDS_IIS_PROXY_MISCONFIGURED, Peo()->StrNodeName());
  238. AfxMessageBox(err);
  239. }
  240. else
  241. {
  242. CString fmtError;
  243. DWORD dwError;
  244. if ( (HRESULT_FACILITY(hr) == FACILITY_WIN32) ||
  245. (HRESULT_FACILITY(hr) == FACILITY_NT_BIT))
  246. {
  247. dwError = (DWORD) HRESULT_CODE(hr);
  248. }
  249. else
  250. {
  251. dwError = (DWORD) hr;
  252. }
  253. FormatError(fmtError, dwError);
  254. err.Format(IDS_ENUMERATE_FAILED, Peo()->StrNodeName(), fmtError);
  255. AfxMessageBox(err);
  256. }
  257. m_cInstanceId.EnableWindow(FALSE);
  258. }
  259. else
  260. {
  261. m_cInstanceId.EnableWindow(TRUE);
  262. }
  263. m_fReadList = TRUE;
  264. }
  265. m_strInstanceName = MetabaseIdToName( m_strInstanceId );
  266. // add to combo from array
  267. DWORD nAddCount = 0;
  268. m_cInstanceId.ResetContent();
  269. for ( nIndex = 0 ; nIndex < m_ServiceArray.GetSize() ; ++nIndex )
  270. {
  271. //
  272. // Only add sites that are not cluster enabled or have the same ID as the resource
  273. //
  274. if ( (!m_ServiceArray.ElementAt(nIndex).IsClusterEnabled()) ||
  275. (!lstrcmp( m_ServiceArray.ElementAt( nIndex ).GetId(), m_strInstanceId))
  276. )
  277. {
  278. if ( m_cInstanceId.AddString( m_ServiceArray.ElementAt( nIndex ).GetName() ) < 0 )
  279. {
  280. OutputDebugStringW( L"Error add\n" );
  281. }
  282. else
  283. {
  284. nAddCount++;
  285. }
  286. }
  287. }
  288. if (0 == nAddCount)
  289. {
  290. m_cInstanceId.EnableWindow(FALSE);
  291. if (BWizard())
  292. {
  293. CString err;
  294. EnableNext(FALSE);
  295. err.Format(IDS_ALL_INSTANCES_CLUSTER_ENABLED, Peo()->StrNodeName());
  296. AfxMessageBox(err);
  297. }
  298. }
  299. else
  300. {
  301. if (BWizard())
  302. {
  303. SetEnableNext();
  304. m_cInstanceId.SetCurSel(0);
  305. }
  306. else
  307. {
  308. nIndex = m_cInstanceId.FindStringExact(-1, m_strInstanceName);
  309. if ( nIndex != CB_ERR )
  310. {
  311. m_cInstanceId.SetCurSel(nIndex);
  312. }
  313. }
  314. }
  315. }
  316. HRESULT
  317. CNNTPVirtualRootParamsPage::ReadList(
  318. CArray <IISMapper, IISMapper>* pMapperArray,
  319. LPWSTR pszPath,
  320. LPCWSTR wcsMachineName
  321. )
  322. /*++
  323. Routine Description:
  324. Read a server list from metabase based on metabase path
  325. Arguments:
  326. pMapperArray - array where to add list of ( ServerComment, InstanceId ) pairs
  327. pszPath - metabase path, e.g. LM/NNTPSVC
  328. Returns:
  329. Error code, S_OK if success
  330. --*/
  331. {
  332. IMSAdminBaseW * pcAdmCom = NULL;
  333. METADATA_HANDLE hmd;
  334. DWORD i;
  335. WCHAR aId[METADATA_MAX_NAME_LEN];
  336. WCHAR aName[512];
  337. HRESULT hRes = S_OK;
  338. COSERVERINFO csiMachine;
  339. MULTI_QI QI = {&IID_IMSAdminBase, NULL, 0};
  340. ZeroMemory( &csiMachine, sizeof(COSERVERINFO) );
  341. csiMachine.pwszName = (LPWSTR)wcsMachineName;
  342. hRes = CoCreateInstanceEx( GETAdminBaseCLSID(TRUE),
  343. NULL,
  344. CLSCTX_SERVER,
  345. &csiMachine,
  346. 1,
  347. &QI
  348. );
  349. if ( SUCCEEDED(hRes) && SUCCEEDED(QI.hr))
  350. {
  351. pcAdmCom = (IMSAdminBaseW *)QI.pItf;
  352. if( SUCCEEDED( hRes = pcAdmCom->OpenKey( METADATA_MASTER_ROOT_HANDLE,
  353. pszPath,
  354. METADATA_PERMISSION_READ,
  355. 5000,
  356. &hmd)) )
  357. {
  358. for ( i = 0 ;
  359. SUCCEEDED(pcAdmCom->EnumKeys( hmd, L"", aId, i )) ;
  360. ++i )
  361. {
  362. METADATA_RECORD md;
  363. DWORD dwReq = sizeof(aName);
  364. memset( &md, 0, sizeof(md) );
  365. md.dwMDDataType = STRING_METADATA;
  366. md.dwMDUserType = IIS_MD_UT_SERVER;
  367. md.dwMDIdentifier = MD_SERVER_COMMENT;
  368. md.dwMDDataLen = sizeof(aName);
  369. md.pbMDData = (LPBYTE)aName;
  370. if ( SUCCEEDED( pcAdmCom->GetData( hmd, aId, &md, &dwReq) ) )
  371. {
  372. DWORD dwClusterEnabled = 0;
  373. memset( &md, 0, sizeof(md) );
  374. md.dwMDDataType = DWORD_METADATA;
  375. md.dwMDUserType = IIS_MD_UT_SERVER;
  376. md.dwMDIdentifier = MD_CLUSTER_ENABLED;
  377. md.dwMDDataLen = sizeof(dwClusterEnabled);
  378. md.pbMDData = (LPBYTE)&dwClusterEnabled;
  379. pcAdmCom->GetData( hmd, aId, &md, &dwReq);
  380. IISMapper* pMap = new IISMapper( aName, aId, dwClusterEnabled );
  381. if ( pMap )
  382. {
  383. pMapperArray->Add( *pMap );
  384. }
  385. else
  386. {
  387. hRes = E_OUTOFMEMORY;
  388. break;
  389. }
  390. }
  391. }
  392. pcAdmCom->CloseKey( hmd );
  393. }
  394. pcAdmCom->Release();
  395. }
  396. return hRes;
  397. }
  398. LPWSTR
  399. CNNTPVirtualRootParamsPage::NameToMetabaseId(
  400. CString& strName
  401. )
  402. /*++
  403. Routine Description:
  404. Convert ServerComment to InstanceId
  405. Arguments:
  406. strName - ServerComment
  407. Returns:
  408. InstanceId if strName found in array, otherwise NULL
  409. --*/
  410. {
  411. DWORD i;
  412. for ( i = 0 ; i < (DWORD)m_ServiceArray.GetSize() ; ++i )
  413. {
  414. if ( !m_ServiceArray.ElementAt( i ).GetName().Compare( strName ) )
  415. {
  416. return (LPWSTR)(LPCTSTR)(m_ServiceArray.ElementAt( i ).GetId());
  417. }
  418. }
  419. return NULL;
  420. }
  421. LPWSTR
  422. CNNTPVirtualRootParamsPage::MetabaseIdToName(
  423. CString& strId
  424. )
  425. /*++
  426. Routine Description:
  427. Convert InstanceId to ServerComment
  428. Arguments:
  429. strId - InstanceID
  430. Returns:
  431. InstanceId if strName found in array.
  432. If not found return 1st array element if array not empty, otherwise NULL
  433. --*/
  434. {
  435. DWORD i;
  436. for ( i = 0 ; i < (DWORD)m_ServiceArray.GetSize() ; ++i )
  437. {
  438. if ( !m_ServiceArray.ElementAt( i ).GetId().Compare( strId ) )
  439. {
  440. return (LPWSTR)(LPCTSTR)(m_ServiceArray.ElementAt( i ).GetName());
  441. }
  442. }
  443. return m_ServiceArray.GetSize() == 0 ? NULL : (LPWSTR)(LPCTSTR)(m_ServiceArray.ElementAt( 0 ).GetName());
  444. }
  445. VOID
  446. CNNTPVirtualRootParamsPage::SetEnableNext(
  447. VOID
  448. )
  449. /*++
  450. Routine Description:
  451. Set enable state of Finish button
  452. Arguments:
  453. None
  454. Returns:
  455. Nothing
  456. --*/
  457. {
  458. EnableNext( m_ServiceArray.GetSize() ? TRUE : FALSE );
  459. }
  460. void CNNTPVirtualRootParamsPage::OnRefresh()
  461. {
  462. m_fReadList = FALSE;
  463. m_ServiceArray.RemoveAll();
  464. FillServerList();
  465. }