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.

2430 lines
62 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. server.cpp
  7. WINS server node information.
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "winssnap.h"
  12. #include "root.h"
  13. #include "Srvlatpp.h"
  14. #include "actreg.h"
  15. #include "reppart.h"
  16. #include "server.h"
  17. #include "svrstats.h"
  18. #include "shlobj.h"
  19. #include "cprogdlg.h"
  20. #include "status.h"
  21. #include "tregkey.h"
  22. #include "verify.h"
  23. #include "pushtrig.h"
  24. #include "ipadddlg.h"
  25. #include <service.h>
  26. #define NB_NAME_MAX_LENGTH 16 // Max length for NetBIOS names
  27. #define LM_NAME_MAX_LENGTH 15 // Maximum length for Lanman-compatible
  28. // NetBIOS Name.
  29. #define DOMAINNAME_LENGTH 255
  30. #define HOSTNAME_LENGTH 16
  31. CNameCache g_NameCache;
  32. int BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  33. {
  34. int i;
  35. switch (uMsg)
  36. {
  37. case BFFM_INITIALIZED:
  38. SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
  39. break;
  40. }
  41. return 0;
  42. }
  43. /*---------------------------------------------------------------------------
  44. CNameThread
  45. Background thread that resolves names
  46. Author: EricDav
  47. ---------------------------------------------------------------------------*/
  48. CNameThread::CNameThread()
  49. {
  50. m_bAutoDelete = FALSE;
  51. m_hEventHandle = NULL;
  52. m_pServerInfoArray = NULL;
  53. }
  54. CNameThread::~CNameThread()
  55. {
  56. if (m_hEventHandle != NULL)
  57. {
  58. VERIFY(::CloseHandle(m_hEventHandle));
  59. m_hEventHandle = NULL;
  60. }
  61. }
  62. void CNameThread::Init(CServerInfoArray * pServerInfoArray)
  63. {
  64. m_pServerInfoArray = pServerInfoArray;
  65. }
  66. BOOL CNameThread::Start()
  67. {
  68. ASSERT(m_hEventHandle == NULL); // cannot call start twice or reuse the same C++ object
  69. m_hEventHandle = ::CreateEvent(NULL,TRUE /*bManualReset*/,FALSE /*signalled*/, NULL);
  70. if (m_hEventHandle == NULL)
  71. return FALSE;
  72. return CreateThread();
  73. }
  74. void CNameThread::Abort(BOOL fAutoDelete)
  75. {
  76. if (!IsRunning() && fAutoDelete)
  77. {
  78. delete this;
  79. }
  80. else
  81. {
  82. m_bAutoDelete = fAutoDelete;
  83. SetEvent(m_hEventHandle);
  84. }
  85. }
  86. void CNameThread::AbortAndWait()
  87. {
  88. Abort(FALSE);
  89. WaitForSingleObject(m_hThread, INFINITE);
  90. }
  91. BOOL CNameThread::IsRunning()
  92. {
  93. if (WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  94. {
  95. return FALSE;
  96. }
  97. else
  98. {
  99. return TRUE;
  100. }
  101. }
  102. int CNameThread::Run()
  103. {
  104. Assert(m_pServerInfoArray);
  105. //
  106. // fill in the host names for each owner in the list
  107. //
  108. UpdateNameCache();
  109. if (FCheckForAbort())
  110. return 29;
  111. for (int i = 0; i < m_pServerInfoArray->GetSize(); i++)
  112. {
  113. if (FCheckForAbort())
  114. break;
  115. DWORD dwIp = m_pServerInfoArray->GetAt(i).m_dwIp;
  116. if (dwIp != 0)
  117. {
  118. CString strName;
  119. if (!GetNameFromCache(dwIp, strName))
  120. {
  121. GetHostName(dwIp, strName);
  122. CNameCacheEntry cacheEntry;
  123. cacheEntry.m_dwIp = dwIp;
  124. cacheEntry.m_strName = strName;
  125. cacheEntry.m_timeLastUpdate.GetCurrentTime();
  126. g_NameCache.Add(cacheEntry);
  127. Trace2("CNameThread::Run - GetHostName for %lx returned %s\n", dwIp, strName);
  128. }
  129. if (FCheckForAbort())
  130. break;
  131. (*m_pServerInfoArray)[i].m_strName = strName;
  132. }
  133. }
  134. return 29; // exit code so I can tell when the thread goes away
  135. }
  136. BOOL CNameThread::FCheckForAbort()
  137. {
  138. if (WaitForSingleObject(m_hEventHandle, 0) == WAIT_OBJECT_0)
  139. {
  140. Trace0("CNameThread::Run - abort detected, exiting...\n");
  141. return TRUE;
  142. }
  143. else
  144. {
  145. return FALSE;
  146. }
  147. }
  148. void CNameThread::UpdateNameCache()
  149. {
  150. CTime time;
  151. time = CTime::GetCurrentTime();
  152. CTimeSpan timespan(0, 1, 0, 0); // 1 hour
  153. for (int i = 0; i < g_NameCache.GetSize(); i++)
  154. {
  155. if (g_NameCache[i].m_timeLastUpdate < (time - timespan))
  156. {
  157. CString strName;
  158. GetHostName(g_NameCache[i].m_dwIp, strName);
  159. g_NameCache[i].m_strName = strName;
  160. if (FCheckForAbort())
  161. break;
  162. }
  163. }
  164. }
  165. BOOL CNameThread::GetNameFromCache(DWORD dwIp, CString & strName)
  166. {
  167. BOOL fFound = FALSE;
  168. for (int i = 0; i < g_NameCache.GetSize(); i++)
  169. {
  170. if (g_NameCache[i].m_dwIp == dwIp)
  171. {
  172. strName = g_NameCache[i].m_strName;
  173. fFound = TRUE;
  174. break;
  175. }
  176. }
  177. return fFound;
  178. }
  179. /*---------------------------------------------------------------------------
  180. Constructor and destructor
  181. Description
  182. Author: EricDav
  183. ---------------------------------------------------------------------------*/
  184. CWinsServerHandler::CWinsServerHandler
  185. (
  186. ITFSComponentData * pComponentData,
  187. LPCWSTR pServerName,
  188. BOOL fConnected,
  189. DWORD dwIp,
  190. DWORD dwFlags,
  191. DWORD dwRefreshInterval
  192. ) : CMTWinsHandler(pComponentData),
  193. m_dwFlags(dwFlags),
  194. m_dwRefreshInterval(dwRefreshInterval),
  195. m_hBinding(NULL)
  196. {
  197. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  198. m_strServerAddress = pServerName;
  199. m_fConnected = fConnected;
  200. m_dwIPAdd = dwIp;
  201. m_hBinding = NULL;
  202. m_bExtension = FALSE;
  203. m_pNameThread = NULL;
  204. strcpy(szIPMon, "");
  205. }
  206. /*---------------------------------------------------------------------------
  207. Constructor and destructor
  208. Description
  209. Author: EricDav
  210. ---------------------------------------------------------------------------*/
  211. CWinsServerHandler::~CWinsServerHandler()
  212. {
  213. HWND hStatsWnd;
  214. // Check to see if this node has a stats sheet up.
  215. hStatsWnd = m_dlgStats.GetSafeHwnd();
  216. if (hStatsWnd != NULL)
  217. {
  218. m_dlgStats.KillRefresherThread();
  219. WaitForStatisticsWindow(&m_dlgStats);
  220. }
  221. // diconnect from server and make the handle invalid
  222. DisConnectFromWinsServer();
  223. // kill the name query thread if exists
  224. if (m_pNameThread)
  225. {
  226. m_pNameThread->AbortAndWait();
  227. delete m_pNameThread;
  228. }
  229. }
  230. /*!--------------------------------------------------------------------------
  231. CWinsServerHandler::InitializeNode
  232. Initializes node specific data
  233. Author: EricDav
  234. ---------------------------------------------------------------------------*/
  235. HRESULT
  236. CWinsServerHandler::InitializeNode
  237. (
  238. ITFSNode * pNode
  239. )
  240. {
  241. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  242. CString IPAdd;
  243. CString strDisp;
  244. if (m_dwIPAdd != 0)
  245. {
  246. MakeIPAddress(m_dwIPAdd, IPAdd);
  247. strDisp.Format(IDS_SERVER_NAME_FORMAT, m_strServerAddress, IPAdd);
  248. }
  249. else
  250. {
  251. strDisp = m_strServerAddress;
  252. }
  253. SetDisplayName(strDisp);
  254. if (m_fConnected)
  255. {
  256. m_nState = loaded;
  257. }
  258. else
  259. {
  260. m_nState = notLoaded;
  261. }
  262. pNode->SetData(TFS_DATA_IMAGEINDEX, GetImageIndex(FALSE));
  263. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, GetImageIndex(TRUE));
  264. // Make the node immediately visible
  265. pNode->SetVisibilityState(TFS_VIS_SHOW);
  266. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  267. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  268. pNode->SetData(TFS_DATA_TYPE, WINSSNAP_SERVER);
  269. SetColumnStringIDs(&aColumns[WINSSNAP_SERVER][0]);
  270. SetColumnWidths(&aColumnWidths[WINSSNAP_SERVER][0]);
  271. return hrOK;
  272. }
  273. /*---------------------------------------------------------------------------
  274. CWinsServerHandler::OnCreateNodeId2
  275. Returns a unique string for this node
  276. Author: EricDav
  277. ---------------------------------------------------------------------------*/
  278. HRESULT CWinsServerHandler::OnCreateNodeId2(ITFSNode * pNode, CString & strId, DWORD * dwFlags)
  279. {
  280. const GUID * pGuid = pNode->GetNodeType();
  281. CString strGuid;
  282. StringFromGUID2(*pGuid, strGuid.GetBuffer(256), 256);
  283. strGuid.ReleaseBuffer();
  284. strId = m_strServerAddress + strGuid;
  285. return hrOK;
  286. }
  287. /*---------------------------------------------------------------------------
  288. CWinsServerHandler::GetImageIndex
  289. Description
  290. Author: EricDav
  291. ---------------------------------------------------------------------------*/
  292. int
  293. CWinsServerHandler::GetImageIndex(BOOL bOpenImage)
  294. {
  295. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  296. int nIndex = 0;
  297. switch (m_nState)
  298. {
  299. case notLoaded:
  300. nIndex = ICON_IDX_SERVER;
  301. break;
  302. case loaded:
  303. nIndex = ICON_IDX_SERVER_CONNECTED;
  304. m_strConnected.LoadString(IDS_SERVER_CONNECTED);
  305. break;
  306. case unableToLoad:
  307. if (m_dwErr == ERROR_ACCESS_DENIED)
  308. {
  309. nIndex = ICON_IDX_SERVER_NO_ACCESS;
  310. }
  311. else
  312. {
  313. nIndex = ICON_IDX_SERVER_LOST_CONNECTION;
  314. }
  315. m_strConnected.LoadString(IDS_SERVER_NOTCONNECTED);
  316. break;
  317. case loading:
  318. nIndex = ICON_IDX_SERVER_BUSY;
  319. break;
  320. default:
  321. ASSERT(FALSE);
  322. }
  323. return nIndex;
  324. }
  325. /*---------------------------------------------------------------------------
  326. CWinsServerHandler::OnHaveData
  327. Description
  328. Author: EricDav
  329. ---------------------------------------------------------------------------*/
  330. void
  331. CWinsServerHandler::OnHaveData
  332. (
  333. ITFSNode * pParentNode,
  334. ITFSNode * pNewNode
  335. )
  336. {
  337. // expand the node so that child nodes appear correctly
  338. LONG_PTR dwType = pNewNode->GetData(TFS_DATA_TYPE);
  339. switch (dwType)
  340. {
  341. case WINSSNAP_ACTIVE_REGISTRATIONS:
  342. {
  343. CActiveRegistrationsHandler * pActReg = GETHANDLER(CActiveRegistrationsHandler, pNewNode);
  344. pActReg->SetServer(pParentNode);
  345. m_spActiveReg.Set(pNewNode);
  346. }
  347. break;
  348. case WINSSNAP_REPLICATION_PARTNERS:
  349. m_spReplicationPartner.Set(pNewNode);
  350. break;
  351. default:
  352. Assert("Invalid node types passed back to server handler!");
  353. break;
  354. }
  355. pParentNode->AddChild(pNewNode);
  356. // now tell the view to update themselves
  357. ExpandNode(pParentNode, TRUE);
  358. }
  359. /*---------------------------------------------------------------------------
  360. CWinsServerHandler::OnHaveData
  361. Description
  362. Author: EricDav
  363. ---------------------------------------------------------------------------*/
  364. void
  365. CWinsServerHandler::OnHaveData
  366. (
  367. ITFSNode * pParentNode,
  368. LPARAM Data,
  369. LPARAM Type
  370. )
  371. {
  372. // This is how we get non-node data back from the background thread.
  373. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  374. switch (Type)
  375. {
  376. case WINS_QDATA_SERVER_INFO:
  377. {
  378. CServerData * pServerInfo = (CServerData *) Data;
  379. DisConnectFromWinsServer();
  380. m_hBinding = pServerInfo->m_hBinding;
  381. m_dwIPAdd = pServerInfo->m_dwServerIp;
  382. m_strServerAddress = pServerInfo->m_strServerName;
  383. m_cConfig = pServerInfo->m_config;
  384. // update the name string
  385. if (!m_bExtension)
  386. {
  387. SPITFSNode spRoot;
  388. CWinsRootHandler * pRoot;
  389. m_spNodeMgr->GetRootNode(&spRoot);
  390. pRoot = GETHANDLER(CWinsRootHandler, spRoot);
  391. SetDisplay(pParentNode, pRoot->GetShowLongName());
  392. }
  393. delete pServerInfo;
  394. }
  395. break;
  396. }
  397. }
  398. /*---------------------------------------------------------------------------
  399. Overridden base handler functions
  400. ---------------------------------------------------------------------------*/
  401. /*---------------------------------------------------------------------------
  402. CWinsServerHandler::OnAddMenuItems
  403. Description
  404. Author: EricDav
  405. ---------------------------------------------------------------------------*/
  406. STDMETHODIMP
  407. CWinsServerHandler::OnAddMenuItems
  408. (
  409. ITFSNode * pNode,
  410. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  411. LPDATAOBJECT lpDataObject,
  412. DATA_OBJECT_TYPES type,
  413. DWORD dwType,
  414. long * pInsertionAllowed
  415. )
  416. {
  417. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  418. LONG fFlags = 0, fLoadingFlags = 0, f351Flags = 0, fAdminFlags = 0;
  419. HRESULT hr = S_OK;
  420. CString strMenuItem;
  421. BOOL b351 = FALSE;
  422. if ( m_nState != loaded )
  423. {
  424. fFlags |= MF_GRAYED;
  425. }
  426. if ( m_nState == loading)
  427. {
  428. fLoadingFlags = MF_GRAYED;
  429. }
  430. if (!m_cConfig.IsAdmin())
  431. {
  432. fAdminFlags = MF_GRAYED;
  433. }
  434. if (type == CCT_SCOPE)
  435. {
  436. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  437. {
  438. strMenuItem.LoadString(IDS_SHOW_SERVER_STATS);
  439. hr = LoadAndAddMenuItem( pContextMenuCallback,
  440. strMenuItem,
  441. IDS_SHOW_SERVER_STATS,
  442. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  443. fFlags );
  444. ASSERT( SUCCEEDED(hr) );
  445. // separator
  446. hr = LoadAndAddMenuItem( pContextMenuCallback,
  447. strMenuItem,
  448. 0,
  449. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  450. MF_SEPARATOR);
  451. ASSERT( SUCCEEDED(hr) );
  452. // scavenge
  453. strMenuItem.LoadString(IDS_SERVER_SCAVENGE);
  454. hr = LoadAndAddMenuItem( pContextMenuCallback,
  455. strMenuItem,
  456. IDS_SERVER_SCAVENGE,
  457. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  458. fFlags );
  459. ASSERT( SUCCEEDED(hr) );
  460. // check if 351 server is being managed
  461. if ( m_nState == loaded )
  462. b351 = CheckIfNT351Server();
  463. // yes? grey out the consistency check items
  464. if(b351)
  465. f351Flags |= MF_GRAYED;
  466. else
  467. f351Flags &= ~MF_GRAYED;
  468. // only available to admins
  469. strMenuItem.LoadString(IDS_DO_CONSISTENCY_CHECK);
  470. hr = LoadAndAddMenuItem( pContextMenuCallback,
  471. strMenuItem,
  472. IDS_DO_CONSISTENCY_CHECK,
  473. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  474. f351Flags | fFlags | fAdminFlags);
  475. ASSERT( SUCCEEDED(hr) );
  476. // only available to admins
  477. strMenuItem.LoadString(IDS_CHECK_VERSION_CONSISTENCY);
  478. hr = LoadAndAddMenuItem( pContextMenuCallback,
  479. strMenuItem,
  480. IDS_CHECK_VERSION_CONSISTENCY,
  481. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  482. f351Flags | fFlags | fAdminFlags);
  483. ASSERT( SUCCEEDED(hr) );
  484. // separator
  485. hr = LoadAndAddMenuItem( pContextMenuCallback,
  486. strMenuItem,
  487. 0,
  488. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  489. MF_SEPARATOR);
  490. ASSERT( SUCCEEDED(hr) );
  491. // replication triggers
  492. strMenuItem.LoadString(IDS_REP_SEND_PUSH_TRIGGER);
  493. hr = LoadAndAddMenuItem( pContextMenuCallback,
  494. strMenuItem,
  495. IDS_REP_SEND_PUSH_TRIGGER,
  496. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  497. fFlags );
  498. ASSERT( SUCCEEDED(hr) );
  499. strMenuItem.LoadString(IDS_REP_SEND_PULL_TRIGGER);
  500. hr = LoadAndAddMenuItem( pContextMenuCallback,
  501. strMenuItem,
  502. IDS_REP_SEND_PULL_TRIGGER,
  503. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  504. fFlags );
  505. ASSERT( SUCCEEDED(hr) );
  506. // separator
  507. hr = LoadAndAddMenuItem( pContextMenuCallback,
  508. strMenuItem,
  509. 0,
  510. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  511. MF_SEPARATOR);
  512. ASSERT( SUCCEEDED(hr) );
  513. // enable backp and restore database only for local servers
  514. if(IsLocalConnection() && m_nState == loaded)
  515. fFlags &= ~MF_GRAYED;
  516. else
  517. fFlags |= MF_GRAYED;
  518. strMenuItem.LoadString(IDS_SERVER_BACKUP);
  519. hr = LoadAndAddMenuItem( pContextMenuCallback,
  520. strMenuItem,
  521. IDS_SERVER_BACKUP,
  522. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  523. fFlags );
  524. ASSERT( SUCCEEDED(hr) );
  525. // default is to not show this item
  526. fFlags |= MF_GRAYED;
  527. BOOL fServiceRunning = TRUE;
  528. ::TFSIsServiceRunning(m_strServerAddress, _T("WINS"), &fServiceRunning);
  529. if (IsLocalConnection() && m_cConfig.IsAdmin())
  530. {
  531. // the service call can be costly if doing it remotely, so only do it
  532. // when we really need to.
  533. if (!fServiceRunning)
  534. fFlags &= ~MF_GRAYED;
  535. }
  536. strMenuItem.LoadString(IDS_SERVER_RESTORE);
  537. hr = LoadAndAddMenuItem( pContextMenuCallback,
  538. strMenuItem,
  539. IDS_SERVER_RESTORE,
  540. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  541. fFlags );
  542. ASSERT( SUCCEEDED(hr) );
  543. }
  544. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TASK)
  545. {
  546. // start/stop service menu items
  547. if ( m_nState == notLoaded ||
  548. m_nState == loading)
  549. {
  550. fFlags = MF_GRAYED;
  551. }
  552. else
  553. {
  554. fFlags = 0;
  555. }
  556. DWORD dwServiceStatus, dwErrorCode, dwErr;
  557. dwErr = ::TFSGetServiceStatus(m_strServerAddress, _T("wins"), &dwServiceStatus, &dwErrorCode);
  558. if (dwErr != ERROR_SUCCESS)
  559. fFlags |= MF_GRAYED;
  560. // determining the restart state is the same as the stop flag
  561. LONG lStartFlag = (dwServiceStatus == SERVICE_STOPPED) ? 0 : MF_GRAYED;
  562. LONG lStopFlag = ( (dwServiceStatus == SERVICE_RUNNING) ||
  563. (dwServiceStatus == SERVICE_PAUSED) ) ? 0 : MF_GRAYED;
  564. LONG lPauseFlag = ( (dwServiceStatus == SERVICE_RUNNING) ||
  565. ( (dwServiceStatus != SERVICE_PAUSED) &&
  566. (dwServiceStatus != SERVICE_STOPPED) ) ) ? 0 : MF_GRAYED;
  567. LONG lResumeFlag = (dwServiceStatus == SERVICE_PAUSED) ? 0 : MF_GRAYED;
  568. strMenuItem.LoadString(IDS_SERVER_START_SERVICE);
  569. hr = LoadAndAddMenuItem( pContextMenuCallback,
  570. strMenuItem,
  571. IDS_SERVER_START_SERVICE,
  572. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  573. fFlags | lStartFlag);
  574. strMenuItem.LoadString(IDS_SERVER_STOP_SERVICE);
  575. hr = LoadAndAddMenuItem( pContextMenuCallback,
  576. strMenuItem,
  577. IDS_SERVER_STOP_SERVICE,
  578. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  579. fFlags | lStopFlag);
  580. strMenuItem.LoadString(IDS_SERVER_PAUSE_SERVICE);
  581. hr = LoadAndAddMenuItem( pContextMenuCallback,
  582. strMenuItem,
  583. IDS_SERVER_PAUSE_SERVICE,
  584. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  585. fFlags | lPauseFlag);
  586. strMenuItem.LoadString(IDS_SERVER_RESUME_SERVICE);
  587. hr = LoadAndAddMenuItem( pContextMenuCallback,
  588. strMenuItem,
  589. IDS_SERVER_RESUME_SERVICE,
  590. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  591. fFlags | lResumeFlag);
  592. strMenuItem.LoadString(IDS_SERVER_RESTART_SERVICE);
  593. hr = LoadAndAddMenuItem( pContextMenuCallback,
  594. strMenuItem,
  595. IDS_SERVER_RESTART_SERVICE,
  596. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  597. fFlags | lStopFlag);
  598. /* Don't do this in the snapin, go back to the old command prompt way
  599. strMenuItem.LoadString(IDS_SERVER_COMPACT);
  600. hr = LoadAndAddMenuItem( pContextMenuCallback,
  601. strMenuItem,
  602. IDS_SERVER_COMPACT,
  603. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  604. fFlags );
  605. ASSERT( SUCCEEDED(hr) );
  606. */
  607. }
  608. }
  609. return hr;
  610. }
  611. /*---------------------------------------------------------------------------
  612. CWinsServerHandler::OnCommand
  613. Description
  614. Author: EricDav
  615. ---------------------------------------------------------------------------*/
  616. STDMETHODIMP
  617. CWinsServerHandler::OnCommand
  618. (
  619. ITFSNode * pNode,
  620. long nCommandId,
  621. DATA_OBJECT_TYPES type,
  622. LPDATAOBJECT pDataObject,
  623. DWORD dwType
  624. )
  625. {
  626. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  627. HRESULT hr = S_OK;
  628. switch (nCommandId)
  629. {
  630. case IDS_SHOW_SERVER_STATS:
  631. ShowServerStatDialog(pNode);
  632. break;
  633. case IDS_SERVER_BACKUP:
  634. DoDBBackup(pNode);
  635. break;
  636. case IDS_SERVER_SCAVENGE:
  637. DoDBScavenge(pNode);
  638. break;
  639. case IDS_SERVER_COMPACT:
  640. DoDBCompact(pNode);
  641. break;
  642. case IDS_SERVER_RESTORE:
  643. DoDBRestore(pNode);
  644. break;
  645. case IDS_DO_CONSISTENCY_CHECK:
  646. OnDoConsistencyCheck(pNode);
  647. break;
  648. case IDS_CHECK_VERSION_CONSISTENCY:
  649. OnDoVersionConsistencyCheck(pNode);
  650. break;
  651. case IDS_REP_SEND_PUSH_TRIGGER:
  652. hr = OnSendPushTrigger(pNode);
  653. break;
  654. case IDS_REP_SEND_PULL_TRIGGER:
  655. hr = OnSendPullTrigger(pNode);
  656. break;
  657. case IDS_SERVER_STOP_SERVICE:
  658. hr = OnControlService(pNode, FALSE);
  659. break;
  660. case IDS_SERVER_START_SERVICE:
  661. hr = OnControlService(pNode, TRUE);
  662. break;
  663. case IDS_SERVER_PAUSE_SERVICE:
  664. hr = OnPauseResumeService(pNode, TRUE);
  665. break;
  666. case IDS_SERVER_RESUME_SERVICE:
  667. hr = OnPauseResumeService(pNode, FALSE);
  668. break;
  669. case IDS_SERVER_RESTART_SERVICE:
  670. hr = OnRestartService(pNode);
  671. break;
  672. default:
  673. break;
  674. }
  675. return hr;
  676. }
  677. /*!--------------------------------------------------------------------------
  678. CWinsServerHandler::HasPropertyPages
  679. Implementation of ITFSNodeHandler::HasPropertyPages
  680. NOTE: the root node handler has to over-ride this function to
  681. handle the snapin manager property page (wizard) case!!!
  682. Author: KennT
  683. ---------------------------------------------------------------------------*/
  684. STDMETHODIMP
  685. CWinsServerHandler::HasPropertyPages
  686. (
  687. ITFSNode * pNode,
  688. LPDATAOBJECT pDataObject,
  689. DATA_OBJECT_TYPES type,
  690. DWORD dwType
  691. )
  692. {
  693. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  694. HRESULT hr = hrOK;
  695. if (dwType & TFS_COMPDATA_CREATE)
  696. {
  697. // This is the case where we are asked to bring up property
  698. // pages when the user is adding a new snapin. These calls
  699. // are forwarded to the root node to handle.
  700. hr = hrOK;
  701. Assert(FALSE); // should never get here
  702. }
  703. else
  704. {
  705. // we have property pages in the normal case, but don't put the
  706. // menu up if we are not loaded yet
  707. if ( m_nState != loaded )
  708. {
  709. hr = hrFalse;
  710. }
  711. else
  712. {
  713. hr = hrOK;
  714. }
  715. }
  716. return hr;
  717. }
  718. /*---------------------------------------------------------------------------
  719. CWinsServerHandler::CreatePropertyPages
  720. Description
  721. Author: EricDav
  722. ---------------------------------------------------------------------------*/
  723. STDMETHODIMP
  724. CWinsServerHandler::CreatePropertyPages
  725. (
  726. ITFSNode * pNode,
  727. LPPROPERTYSHEETCALLBACK lpProvider,
  728. LPDATAOBJECT pDataObject,
  729. LONG_PTR handle,
  730. DWORD dwType
  731. )
  732. {
  733. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  734. HRESULT hr = hrOK;
  735. HPROPSHEETPAGE hPage;
  736. SPIComponentData spComponentData;
  737. Assert(pNode->GetData(TFS_DATA_COOKIE) != 0);
  738. //
  739. // Object gets deleted when the page is destroyed
  740. //
  741. m_spNodeMgr->GetComponentData(&spComponentData);
  742. ConnectToWinsServer(pNode);
  743. // to read the values from the registry
  744. DWORD err = m_cConfig.Load(GetBinding());
  745. // unable to read the registry
  746. if (err != ERROR_SUCCESS)
  747. {
  748. ::WinsMessageBox(WIN32_FROM_HRESULT(err));
  749. return hrOK;
  750. }
  751. CServerProperties * pServerProp =
  752. new CServerProperties(pNode, spComponentData, m_spTFSCompData, NULL);
  753. pServerProp->m_pageGeneral.m_uImage = GetImageIndex(FALSE);
  754. pServerProp->SetConfig(&m_cConfig);
  755. Assert(lpProvider != NULL);
  756. return pServerProp->CreateModelessSheet(lpProvider, handle);
  757. }
  758. /*---------------------------------------------------------------------------
  759. CWinsServerHandler::OnPropertyChange
  760. Description
  761. Author: EricDav
  762. ---------------------------------------------------------------------------*/
  763. HRESULT
  764. CWinsServerHandler::OnPropertyChange
  765. (
  766. ITFSNode * pNode,
  767. LPDATAOBJECT pDataobject,
  768. DWORD dwType,
  769. LPARAM arg,
  770. LPARAM lParam
  771. )
  772. {
  773. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  774. CServerProperties * pServerProp
  775. = reinterpret_cast<CServerProperties *>(lParam);
  776. LONG_PTR changeMask = 0;
  777. // tell the property page to do whatever now that we are back on the
  778. // main thread
  779. pServerProp->OnPropertyChange(TRUE, &changeMask);
  780. pServerProp->AcknowledgeNotify();
  781. if (changeMask)
  782. pNode->ChangeNode(changeMask);
  783. return hrOK;
  784. }
  785. /*!--------------------------------------------------------------------------
  786. CWinsServer::Command
  787. Handles commands for the current view
  788. Author: EricDav
  789. ---------------------------------------------------------------------------*/
  790. STDMETHODIMP
  791. CWinsServerHandler::Command
  792. (
  793. ITFSComponent * pComponent,
  794. MMC_COOKIE cookie,
  795. int nCommandID,
  796. LPDATAOBJECT pDataObject
  797. )
  798. {
  799. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  800. HRESULT hr = S_OK;
  801. switch (nCommandID)
  802. {
  803. case MMCC_STANDARD_VIEW_SELECT:
  804. break;
  805. // this may have come from the scope pane handler, so pass it up
  806. default:
  807. hr = HandleScopeCommand(cookie, nCommandID, pDataObject);
  808. break;
  809. }
  810. return hr;
  811. }
  812. /*!--------------------------------------------------------------------------
  813. CWinsServer::AddMenuItems
  814. Over-ride this to add our view menu item
  815. Author: EricDav
  816. ---------------------------------------------------------------------------*/
  817. STDMETHODIMP
  818. CWinsServerHandler::AddMenuItems
  819. (
  820. ITFSComponent * pComponent,
  821. MMC_COOKIE cookie,
  822. LPDATAOBJECT pDataObject,
  823. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  824. long * pInsertionAllowed
  825. )
  826. {
  827. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  828. HRESULT hr = S_OK;
  829. // figure out if we need to pass this to the scope pane menu handler
  830. hr = HandleScopeMenus(cookie, pDataObject, pContextMenuCallback, pInsertionAllowed);
  831. return hr;
  832. }
  833. /*---------------------------------------------------------------------------
  834. Command handlers
  835. ---------------------------------------------------------------------------*/
  836. /*---------------------------------------------------------------------------
  837. CWinsServerHandler::ShowServerStatDialog(ITFSNode* pNode)
  838. Displays the ServerStatistics Window
  839. Author: v-shubk
  840. ---------------------------------------------------------------------------*/
  841. HRESULT
  842. CWinsServerHandler::ShowServerStatDialog(ITFSNode* pNode)
  843. {
  844. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  845. CThemeContextActivator themeActivator;
  846. m_dlgStats.SetNode(pNode);
  847. m_dlgStats.SetServer(m_strServerAddress);
  848. CreateNewStatisticsWindow(&m_dlgStats,
  849. ::FindMMCMainWindow(),
  850. IDD_STATS_NARROW);
  851. HRESULT hr = hrOK;
  852. return hr;
  853. }
  854. /*!--------------------------------------------------------------------------
  855. CWinsServerHandler::OnDelete
  856. The base handler calls this when MMC sends a MMCN_DELETE for a
  857. scope pane item. We just call our delete command handler.
  858. Author: EricDav
  859. ---------------------------------------------------------------------------*/
  860. HRESULT
  861. CWinsServerHandler::OnDelete
  862. (
  863. ITFSNode * pNode,
  864. LPARAM arg,
  865. LPARAM lParam
  866. )
  867. {
  868. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  869. HRESULT hr = S_OK;
  870. LONG err = 0 ;
  871. CString strMessage, strTemp;
  872. SPITFSNode spParent;
  873. CWinsStatusHandler *pStat = NULL;
  874. CWinsRootHandler *pRoot = NULL;
  875. CThemeContextActivator themeActivator;
  876. strTemp = m_strServerAddress;
  877. AfxFormatString1(strMessage,
  878. IDS_DELETE_SERVER,
  879. m_strServerAddress);
  880. if (AfxMessageBox(strMessage, MB_YESNO) != IDYES)
  881. return NOERROR;
  882. pNode->GetParent(&spParent);
  883. pRoot = GETHANDLER(CWinsRootHandler, spParent);
  884. // remove the node from the status node as well
  885. pStat = GETHANDLER(CWinsStatusHandler, pRoot->m_spStatusNode);
  886. pStat->DeleteNode(pRoot->m_spStatusNode, this);
  887. // remove this node from the list, there's nothing we need to tell
  888. // the server, it's just our local list of servers
  889. spParent->RemoveChild(pNode);
  890. return hr;
  891. }
  892. /*---------------------------------------------------------------------------
  893. CWinsServerHandler::LoadColumns()
  894. Description
  895. Author: v-shubk
  896. ---------------------------------------------------------------------------*/
  897. HRESULT
  898. CWinsServerHandler::LoadColumns(ITFSComponent * pComponent,
  899. MMC_COOKIE cookie,
  900. LPARAM arg,
  901. LPARAM lParam)
  902. {
  903. HRESULT hr = hrOK;
  904. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  905. SPIHeaderCtrl spHeaderCtrl;
  906. pComponent->GetHeaderCtrl(&spHeaderCtrl);
  907. CString str;
  908. int i = 0;
  909. CString strTemp;
  910. strTemp = m_strServerAddress;
  911. while( i< ARRAYLEN(aColumnWidths[1]))
  912. {
  913. if (i == 0)
  914. {
  915. AfxFormatString1(str, IDS_WINSSERVER_NAME, strTemp);
  916. int nTest = spHeaderCtrl->InsertColumn(i,
  917. const_cast<LPTSTR>((LPCWSTR)str),
  918. LVCFMT_LEFT,
  919. aColumnWidths[1][0]);
  920. i++;
  921. }
  922. else
  923. {
  924. str.LoadString(IDS_DESCRIPTION);
  925. int nTest = spHeaderCtrl->InsertColumn(1,
  926. const_cast<LPTSTR>((LPCWSTR)str),
  927. LVCFMT_LEFT,
  928. aColumnWidths[1][1]);
  929. i++;
  930. }
  931. if(aColumns[0][i] == 0)
  932. break;
  933. }
  934. return hrOK;
  935. }
  936. /*!--------------------------------------------------------------------------
  937. CWinsServerHandler::GetStatistics()
  938. Gets the statistics from the server
  939. Author: v-shubk
  940. ---------------------------------------------------------------------------*/
  941. DWORD
  942. CWinsServerHandler::GetStatistics(ITFSNode * pNode, PWINSINTF_RESULTS_T * ppStats)
  943. {
  944. DWORD dwStatus = ERROR_SUCCESS;
  945. CString strName, strIP;
  946. if (ppStats)
  947. *ppStats = NULL;
  948. if (m_dwStatus != ERROR_SUCCESS)
  949. m_dwStatus = ConnectToWinsServer(pNode);
  950. if (m_dwStatus == ERROR_SUCCESS)
  951. {
  952. m_wrResults.WinsStat.NoOfPnrs = 0;
  953. m_wrResults.WinsStat.pRplPnrs = 0;
  954. m_wrResults.NoOfWorkerThds = 1;
  955. #ifdef WINS_CLIENT_APIS
  956. dwStatus = ::WinsStatus(m_hBinding, WINSINTF_E_STAT, &m_wrResults);
  957. #else
  958. dwStatus = ::WinsStatus(WINSINTF_E_STAT, &m_wrResults);
  959. #endif WINS_CLIENT_APIS
  960. if (dwStatus == ERROR_SUCCESS)
  961. {
  962. if (ppStats)
  963. *ppStats = &m_wrResults;
  964. }
  965. }
  966. else
  967. {
  968. dwStatus = m_dwStatus;
  969. }
  970. return dwStatus;
  971. }
  972. /*!--------------------------------------------------------------------------
  973. CWinsServerHandler::ClearStatistics()
  974. Clears the statistics from the server
  975. Author: v-shubk
  976. ---------------------------------------------------------------------------*/
  977. DWORD
  978. CWinsServerHandler::ClearStatistics(ITFSNode *pNode)
  979. {
  980. DWORD dwStatus = ERROR_SUCCESS;
  981. CString strName, strIP;
  982. if (m_dwStatus != ERROR_SUCCESS)
  983. m_dwStatus = ConnectToWinsServer(pNode);
  984. if (m_dwStatus == ERROR_SUCCESS)
  985. {
  986. #ifdef WINS_CLIENT_APIS
  987. dwStatus = ::WinsResetCounters(m_hBinding);
  988. #else
  989. dwStatus = ::WinsResetCounters();
  990. #endif WINS_CLIENT_APIS
  991. }
  992. else
  993. {
  994. dwStatus = m_dwStatus;
  995. }
  996. return dwStatus;
  997. }
  998. /*---------------------------------------------------------------------------
  999. CWinsServerHandler::ConnectToWinsServer()
  1000. Connects to the wins server
  1001. Author: v-shubk
  1002. ---------------------------------------------------------------------------*/
  1003. DWORD
  1004. CWinsServerHandler::ConnectToWinsServer(ITFSNode *pNode)
  1005. {
  1006. HRESULT hr = hrOK;
  1007. CString strServerName, strIP;
  1008. DWORD dwStatus = ERROR_SUCCESS;
  1009. WINSINTF_ADD_T waWinsAddress;
  1010. WINSINTF_BIND_DATA_T wbdBindData;
  1011. // build some information about the server
  1012. strServerName = GetServerAddress();
  1013. DWORD dwIP = GetServerIP();
  1014. MakeIPAddress(dwIP, strIP);
  1015. DisConnectFromWinsServer();
  1016. // now that the server name and ip are valid, call
  1017. // WINSBind function directly.
  1018. do
  1019. {
  1020. char szNetBIOSName[128] = {0};
  1021. // call WinsBind function with the IP address
  1022. wbdBindData.fTcpIp = 1;
  1023. wbdBindData.pPipeName = NULL;
  1024. wbdBindData.pServerAdd = (LPSTR) (LPCTSTR) strIP;
  1025. BEGIN_WAIT_CURSOR
  1026. if ((m_hBinding = ::WinsBind(&wbdBindData)) == NULL)
  1027. {
  1028. m_dwStatus = ::GetLastError();
  1029. break;
  1030. }
  1031. #ifdef WINS_CLIENT_APIS
  1032. m_dwStatus = ::WinsGetNameAndAdd(m_hBinding, &waWinsAddress, (LPBYTE) szNetBIOSName);
  1033. #else
  1034. m_dwStatus = ::WinsGetNameAndAdd(&waWinsAddress, (LPBYTE) szNetBIOSName);
  1035. #endif WINS_CLIENT_APIS
  1036. END_WAIT_CURSOR
  1037. } while (FALSE);
  1038. return m_dwStatus;
  1039. }
  1040. /*---------------------------------------------------------------------------
  1041. CWinsServerHandler::DoDBBackup()
  1042. backs up the database
  1043. Author: v-shubk
  1044. ---------------------------------------------------------------------------*/
  1045. HRESULT
  1046. CWinsServerHandler::DoDBBackup(ITFSNode *pNode)
  1047. {
  1048. HRESULT hr = hrOK;
  1049. DWORD dwStatus = ConnectToWinsServer(pNode);
  1050. CString strBackupPath;
  1051. CString strHelpText;
  1052. strHelpText.LoadString(IDS_SELECT_BACKUP_FOLDER);
  1053. if (GetFolderName(strBackupPath, strHelpText))
  1054. {
  1055. dwStatus = BackupDatabase(strBackupPath);
  1056. if (dwStatus == ERROR_SUCCESS)
  1057. {
  1058. CThemeContextActivator themeActivator;
  1059. AfxMessageBox(IDS_DB_BACKUP_SUCCESS, MB_ICONINFORMATION | MB_OK);
  1060. // don't update the default path just because they selected a path here
  1061. //if (m_cConfig.m_strBackupPath.CompareNoCase(strBackupPath) != 0)
  1062. //{
  1063. // m_cConfig.m_strBackupPath = strBackupPath;
  1064. // m_cConfig.Store();
  1065. //}
  1066. }
  1067. else
  1068. {
  1069. ::WinsMessageBox(dwStatus, MB_OK);
  1070. }
  1071. }
  1072. return HRESULT_FROM_WIN32(dwStatus);
  1073. }
  1074. /*---------------------------------------------------------------------------
  1075. CWinsServerHandler::BackupDatabase(CString strBackupPath)
  1076. Calls WINS API for backing the database
  1077. Author: v-shubk
  1078. ---------------------------------------------------------------------------*/
  1079. DWORD
  1080. CWinsServerHandler::BackupDatabase(CString strBackupPath)
  1081. {
  1082. BOOL fIncremental = FALSE;
  1083. BOOL fDefaultCharUsed = FALSE;
  1084. DWORD dwStatus = ERROR_SUCCESS;
  1085. char szTemp[MAX_PATH] = {0};
  1086. // INTL$ Should this be ACP or OEMCP?
  1087. WideToMBCS(strBackupPath, szTemp, CP_ACP, 0, &fDefaultCharUsed);
  1088. if (fDefaultCharUsed)
  1089. {
  1090. // could not convert this string... error out
  1091. dwStatus = IDS_ERR_CANT_CONVERT_STRING;
  1092. }
  1093. else
  1094. {
  1095. BEGIN_WAIT_CURSOR
  1096. #ifdef WINS_CLIENT_APIS
  1097. dwStatus = ::WinsBackup(m_hBinding, (unsigned char *)szTemp, (short)fIncremental);
  1098. #else
  1099. dwStatus = ::WinsBackup((unsigned char *)szTemp, (short)fIncremental);
  1100. #endif WINS_CLIENT_APIS
  1101. END_WAIT_CURSOR
  1102. }
  1103. return dwStatus;
  1104. }
  1105. /*---------------------------------------------------------------------------
  1106. CWinsServerHandler::DoDBCompact()
  1107. backs up the database
  1108. Author: v-shubk
  1109. ---------------------------------------------------------------------------*/
  1110. HRESULT
  1111. CWinsServerHandler::DoDBCompact(ITFSNode *pNode)
  1112. {
  1113. HRESULT hr = hrOK;
  1114. CThemeContextActivator themeActivator;
  1115. // tell the user that we need to stop WINS in order to do this
  1116. if (AfxMessageBox(IDS_WARN_SERVICE_STOP, MB_YESNO) == IDNO)
  1117. return hr;
  1118. CDBCompactProgress dlgCompactProgress;
  1119. dlgCompactProgress.m_dwIpAddress = m_dwIPAdd;
  1120. dlgCompactProgress.m_strServerName = m_strServerAddress;
  1121. dlgCompactProgress.m_hBinding = GetBinding();
  1122. dlgCompactProgress.m_pConfig = &m_cConfig;
  1123. dlgCompactProgress.DoModal();
  1124. // since the service gets restarted, the new binding handle is in the object
  1125. m_hBinding = dlgCompactProgress.m_hBinding;
  1126. return hr;
  1127. }
  1128. /*---------------------------------------------------------------------------
  1129. CWinsServerHandler::DoDBRestore()
  1130. Restores the database
  1131. Author:v-shubk
  1132. ---------------------------------------------------------------------------*/
  1133. HRESULT
  1134. CWinsServerHandler::DoDBRestore(ITFSNode *pNode)
  1135. {
  1136. DWORD dwStatus = 0;
  1137. DWORD err = ERROR_SUCCESS;
  1138. HRESULT hr = hrOK;
  1139. CString strRestorePath;
  1140. CString strHelpText;
  1141. strHelpText.LoadString(IDS_SELECT_RESTORE_FOLDER);
  1142. if (GetFolderName(strRestorePath, strHelpText))
  1143. {
  1144. BOOL fOldBackup = m_cConfig.m_fBackupOnTermination;
  1145. if (!strRestorePath.IsEmpty())
  1146. {
  1147. BEGIN_WAIT_CURSOR
  1148. // need to disable backup on shutdown since we need to shutdown
  1149. // the server to do this and we don't want it to backup and stomp
  1150. // over what we may want to restore.
  1151. if (fOldBackup)
  1152. {
  1153. m_cConfig.m_fBackupOnTermination = FALSE;
  1154. m_cConfig.Store();
  1155. }
  1156. DisConnectFromWinsServer();
  1157. // convert the string from unicode to DBCS for the WINS API
  1158. char szTemp[MAX_PATH * 2] = {0};
  1159. BOOL fDefaultCharUsed = FALSE;
  1160. // INTL$ should this be ACP or OEMCP?
  1161. WideToMBCS(strRestorePath, szTemp, CP_ACP, 0, &fDefaultCharUsed);
  1162. // if there is no code page available for conversion, error out
  1163. if (fDefaultCharUsed)
  1164. {
  1165. dwStatus = IDS_ERR_CANT_CONVERT_STRING;
  1166. }
  1167. else
  1168. {
  1169. dwStatus = ::WinsRestore((LPBYTE) szTemp);
  1170. }
  1171. END_WAIT_CURSOR
  1172. if (dwStatus == ERROR_SUCCESS)
  1173. {
  1174. // re-start the WINS service that was stopped
  1175. CString strServiceDesc;
  1176. strServiceDesc.LoadString(IDS_SERVICE_NAME);
  1177. err = TFSStartServiceEx(m_strServerAddress, _T("wins"), _T("WINS Service"), strServiceDesc);
  1178. // connect to the server again
  1179. ConnectToWinsServer(pNode);
  1180. CThemeContextActivator themeActivator;
  1181. // let the user know everything went OK.
  1182. AfxMessageBox(IDS_DB_RESTORE_SUCCESS, MB_ICONINFORMATION | MB_OK);
  1183. }
  1184. else
  1185. {
  1186. ::WinsMessageBox(dwStatus, MB_OK);
  1187. }
  1188. hr = HRESULT_FROM_WIN32(dwStatus);
  1189. // restore the backup on shutdown flag if necessary
  1190. if (fOldBackup)
  1191. {
  1192. m_cConfig.m_fBackupOnTermination = TRUE;
  1193. m_cConfig.Store();
  1194. }
  1195. if (SUCCEEDED(hr))
  1196. {
  1197. // need to refresh the server node because this can only be triggered
  1198. // if the service wasn't running
  1199. if (m_pNameThread)
  1200. {
  1201. m_pNameThread->Abort();
  1202. m_pNameThread = NULL;
  1203. }
  1204. OnRefresh(pNode, NULL, 0, 0, 0);
  1205. }
  1206. }
  1207. }
  1208. return hr;
  1209. }
  1210. /*---------------------------------------------------------------------------
  1211. CWinsServerHandler::OnControlService
  1212. -
  1213. Author: EricDav
  1214. ---------------------------------------------------------------------------*/
  1215. HRESULT
  1216. CWinsServerHandler::OnControlService
  1217. (
  1218. ITFSNode * pNode,
  1219. BOOL fStart
  1220. )
  1221. {
  1222. HRESULT hr = hrOK;
  1223. DWORD err = ERROR_SUCCESS;
  1224. CString strServiceDesc;
  1225. strServiceDesc.LoadString(IDS_SERVICE_NAME);
  1226. if (fStart)
  1227. {
  1228. err = TFSStartServiceEx(m_strServerAddress, _T("wins"), _T("WINS Service"), strServiceDesc);
  1229. }
  1230. else
  1231. {
  1232. err = TFSStopServiceEx(m_strServerAddress, _T("wins"), _T("WINS Service"), strServiceDesc);
  1233. }
  1234. if (err == ERROR_SUCCESS)
  1235. {
  1236. // need to refresh the server node because this can only be triggered
  1237. // if the service wasn't running
  1238. if (m_pNameThread)
  1239. {
  1240. m_pNameThread->Abort();
  1241. m_pNameThread = NULL;
  1242. }
  1243. if (!fStart)
  1244. m_fSilent = TRUE;
  1245. OnRefresh(pNode, NULL, 0, 0, 0);
  1246. }
  1247. else
  1248. {
  1249. WinsMessageBox(err);
  1250. hr = HRESULT_FROM_WIN32(err);
  1251. }
  1252. return hr;
  1253. }
  1254. /*---------------------------------------------------------------------------
  1255. CWinsServerHandler::OnPauseResumeService
  1256. -
  1257. Author: EricDav
  1258. ---------------------------------------------------------------------------*/
  1259. HRESULT
  1260. CWinsServerHandler::OnPauseResumeService
  1261. (
  1262. ITFSNode * pNode,
  1263. BOOL fPause
  1264. )
  1265. {
  1266. HRESULT hr = hrOK;
  1267. DWORD err = ERROR_SUCCESS;
  1268. CString strServiceDesc;
  1269. strServiceDesc.LoadString(IDS_SERVICE_NAME);
  1270. if (fPause)
  1271. {
  1272. err = TFSPauseService(m_strServerAddress, _T("wins"), strServiceDesc);
  1273. }
  1274. else
  1275. {
  1276. err = TFSResumeService(m_strServerAddress, _T("wins"), strServiceDesc);
  1277. }
  1278. if (err != ERROR_SUCCESS)
  1279. {
  1280. WinsMessageBox(err);
  1281. hr = HRESULT_FROM_WIN32(err);
  1282. }
  1283. return hr;
  1284. }
  1285. /*---------------------------------------------------------------------------
  1286. CWinsServerHandler::OnRestartService
  1287. -
  1288. Author: EricDav
  1289. ---------------------------------------------------------------------------*/
  1290. HRESULT
  1291. CWinsServerHandler::OnRestartService
  1292. (
  1293. ITFSNode * pNode
  1294. )
  1295. {
  1296. HRESULT hr = hrOK;
  1297. DWORD err = ERROR_SUCCESS;
  1298. CString strServiceDesc;
  1299. strServiceDesc.LoadString(IDS_SERVICE_NAME);
  1300. err = TFSStopServiceEx(m_strServerAddress, _T("wins"), _T("WINS Service"), strServiceDesc);
  1301. if (err != ERROR_SUCCESS)
  1302. {
  1303. WinsMessageBox(err);
  1304. hr = HRESULT_FROM_WIN32(err);
  1305. }
  1306. if (SUCCEEDED(hr))
  1307. {
  1308. err = TFSStartServiceEx(m_strServerAddress, _T("wins"), _T("WINS Service"), strServiceDesc);
  1309. if (err != ERROR_SUCCESS)
  1310. {
  1311. WinsMessageBox(err);
  1312. hr = HRESULT_FROM_WIN32(err);
  1313. }
  1314. }
  1315. // refresh
  1316. OnRefresh(pNode, NULL, 0, 0, 0);
  1317. return hr;
  1318. }
  1319. /*---------------------------------------------------------------------------
  1320. CWinsServerHandler::UpdateStatistics
  1321. Notification that stats are now available. Update stats for the
  1322. server node and give all subnodes a chance to update.
  1323. Author: EricDav
  1324. ---------------------------------------------------------------------------*/
  1325. DWORD
  1326. CWinsServerHandler::UpdateStatistics
  1327. (
  1328. ITFSNode * pNode
  1329. )
  1330. {
  1331. HRESULT hr = hrOK;
  1332. SPITFSNodeEnum spNodeEnum;
  1333. SPITFSNode spCurrentNode;
  1334. ULONG nNumReturned;
  1335. HWND hStatsWnd;
  1336. BOOL bChangeIcon = FALSE;
  1337. // Check to see if this node has a stats sheet up.
  1338. hStatsWnd = m_dlgStats.GetSafeHwnd();
  1339. if (hStatsWnd != NULL)
  1340. {
  1341. PostMessage(hStatsWnd, WM_NEW_STATS_AVAILABLE, 0, 0);
  1342. }
  1343. return hr;
  1344. }
  1345. /*---------------------------------------------------------------------------
  1346. CWinsServerHandler::DoDBScavenge()
  1347. Scavenges the database
  1348. Author: v-shubk
  1349. ---------------------------------------------------------------------------*/
  1350. HRESULT
  1351. CWinsServerHandler::DoDBScavenge(ITFSNode *pNode)
  1352. {
  1353. HRESULT hr = hrOK;
  1354. DWORD dwStatus;
  1355. if (m_dwStatus != ERROR_SUCCESS)
  1356. {
  1357. dwStatus = ConnectToWinsServer(pNode);
  1358. }
  1359. #ifdef WINS_CLIENT_APIS
  1360. dwStatus = ::WinsDoScavenging(m_hBinding);
  1361. #else
  1362. dwStatus = ::WinsDoScavenging();
  1363. #endif WINS_CLIENT_APIS
  1364. if (dwStatus == ERROR_SUCCESS)
  1365. {
  1366. CString strDisp;
  1367. CString strTemp;
  1368. CThemeContextActivator themeActivator;
  1369. strTemp.LoadString(IDS_SCAVENGE_COMMAND);
  1370. AfxFormatString1(strDisp, IDS_QUEUED_MESSAGE, strTemp);
  1371. AfxMessageBox(strDisp, MB_ICONINFORMATION|MB_OK);
  1372. BEGIN_WAIT_CURSOR
  1373. // refresh the stats
  1374. m_wrResults.WinsStat.NoOfPnrs = 0;
  1375. m_wrResults.WinsStat.pRplPnrs = 0;
  1376. m_wrResults.NoOfWorkerThds = 1;
  1377. #ifdef WINS_CLIENT_APIS
  1378. dwStatus = ::WinsStatus(m_hBinding, WINSINTF_E_CONFIG, &m_wrResults);
  1379. #else
  1380. dwStatus = ::WinsStatus(WINSINTF_E_CONFIG, &m_wrResults);
  1381. #endif WINS_CLIENT_APIS
  1382. UpdateStatistics(pNode);
  1383. END_WAIT_CURSOR
  1384. }
  1385. else
  1386. {
  1387. ::WinsMessageBox(dwStatus, MB_OK);
  1388. }
  1389. return HRESULT_FROM_WIN32(dwStatus);
  1390. }
  1391. /*---------------------------------------------------------------------------
  1392. CWinsServerHandler::IsValidNetBIOSName
  1393. Determine if the given netbios is valid, and pre-pend
  1394. a double backslash if not already present (and the address
  1395. is otherwise valid).
  1396. ---------------------------------------------------------------------------*/
  1397. BOOL
  1398. CWinsServerHandler::IsValidNetBIOSName
  1399. (
  1400. CString & strAddress,
  1401. BOOL fLanmanCompatible,
  1402. BOOL fWackwack // expand slashes if not present
  1403. )
  1404. {
  1405. TCHAR szWacks[] = _T("\\\\");
  1406. if (strAddress.IsEmpty())
  1407. {
  1408. return FALSE;
  1409. }
  1410. if (strAddress[0] == _T('\\'))
  1411. {
  1412. if (strAddress.GetLength() < 3)
  1413. {
  1414. return FALSE;
  1415. }
  1416. if (strAddress[1] != _T('\\'))
  1417. {
  1418. // One slash only? Not valid
  1419. return FALSE;
  1420. }
  1421. }
  1422. else
  1423. {
  1424. if (fWackwack)
  1425. {
  1426. // Add the backslashes
  1427. strAddress = szWacks + strAddress;
  1428. }
  1429. }
  1430. int nMaxAllowedLength = fLanmanCompatible
  1431. ? LM_NAME_MAX_LENGTH
  1432. : NB_NAME_MAX_LENGTH;
  1433. if (fLanmanCompatible)
  1434. {
  1435. strAddress.MakeUpper();
  1436. }
  1437. return strAddress.GetLength() <= nMaxAllowedLength + 2;
  1438. }
  1439. /*---------------------------------------------------------------------------
  1440. CWinsServerHandler::OnResultRefresh
  1441. Refreshes the data relating to the server
  1442. Author: v-shubk
  1443. ---------------------------------------------------------------------------*/
  1444. HRESULT
  1445. CWinsServerHandler::OnResultRefresh
  1446. (
  1447. ITFSComponent * pComponent,
  1448. LPDATAOBJECT pDataObject,
  1449. MMC_COOKIE cookie,
  1450. LPARAM arg,
  1451. LPARAM lParam
  1452. )
  1453. {
  1454. HRESULT hr = hrOK;
  1455. SPITFSNode spNode;
  1456. CORg (m_spNodeMgr->FindNode(cookie, &spNode));
  1457. if (m_pNameThread)
  1458. {
  1459. m_pNameThread->Abort();
  1460. m_pNameThread = NULL;
  1461. }
  1462. OnRefresh(spNode, pDataObject, 0, arg, lParam);
  1463. Error:
  1464. return hr;
  1465. }
  1466. /*---------------------------------------------------------------------------
  1467. CWinsServerHandler::OnDoConsistencyCheck(ITFSNode *pNode)
  1468. Consisntency Check for WINS
  1469. Author - v-shubk
  1470. ---------------------------------------------------------------------------*/
  1471. HRESULT
  1472. CWinsServerHandler::OnDoConsistencyCheck(ITFSNode *pNode)
  1473. {
  1474. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1475. CThemeContextActivator themeActivator;
  1476. HRESULT hr = hrOK;
  1477. if(IDYES != AfxMessageBox(IDS_CONSISTENCY_CONFIRM, MB_YESNO))
  1478. return hrFalse;
  1479. WINSINTF_SCV_REQ_T ScvReq;
  1480. ScvReq.Age = 0; // check all the replicas
  1481. ScvReq.fForce = FALSE;
  1482. ScvReq.Opcode_e = WINSINTF_E_SCV_VERIFY;
  1483. #ifdef WINS_CLIENT_APIS
  1484. DWORD dwStatus = ::WinsDoScavengingNew(m_hBinding, &ScvReq);
  1485. #else
  1486. DWORD dwStatus = ::WinsDoScavengingNew(&ScvReq);
  1487. #endif WINS_CLIENT_APIS
  1488. if(dwStatus == ERROR_SUCCESS)
  1489. {
  1490. CString strDisp, strJob;
  1491. strJob.Format(IDS_DO_CONSISTENCY_CHECK_STR);
  1492. AfxFormatString1(strDisp,IDS_QUEUED_MESSAGE, strJob);
  1493. AfxMessageBox(strDisp, MB_OK);
  1494. }
  1495. else
  1496. {
  1497. ::WinsMessageBox(dwStatus, MB_OK);
  1498. }
  1499. return hr;
  1500. }
  1501. /*---------------------------------------------------------------------------
  1502. CWInsServerHandler::OnDoVersionConsistencyCheck(ITFSNode *pNode)
  1503. Performs the version number consistency check
  1504. Author: v-shubk
  1505. ---------------------------------------------------------------------------*/
  1506. HRESULT
  1507. CWinsServerHandler::OnDoVersionConsistencyCheck(ITFSNode *pNode)
  1508. {
  1509. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  1510. CThemeContextActivator themeActivator;
  1511. HRESULT hr = hrOK;
  1512. if (IDYES != AfxMessageBox(IDS_VERSION_CONSIS_CHECK_WARNING, MB_YESNO))
  1513. return hrOK;
  1514. CCheckVersionProgress dlgCheckVersions;
  1515. dlgCheckVersions.m_dwIpAddress = m_dwIPAdd;
  1516. dlgCheckVersions.m_hBinding = GetBinding();
  1517. dlgCheckVersions.DoModal();
  1518. return hr;
  1519. }
  1520. /*---------------------------------------------------------------------------
  1521. CWinsServerHandler::OnSendPushTrigger()
  1522. Sends Push replication trigger
  1523. ---------------------------------------------------------------------------*/
  1524. HRESULT
  1525. CWinsServerHandler::OnSendPushTrigger(ITFSNode * pNode)
  1526. {
  1527. HRESULT hr = hrOK;
  1528. DWORD err = ERROR_SUCCESS;
  1529. CPushTrig dlgPushTrig;
  1530. CGetTriggerPartner dlgTrigPartner;
  1531. CThemeContextActivator themeActivator;
  1532. if (dlgTrigPartner.DoModal() != IDOK)
  1533. return hr;
  1534. if (dlgPushTrig.DoModal() != IDOK)
  1535. return hr;
  1536. err = ::SendTrigger(GetBinding(),
  1537. (LONG) dlgTrigPartner.m_dwServerIp,
  1538. TRUE,
  1539. dlgPushTrig.GetPropagate());
  1540. if (err == ERROR_SUCCESS)
  1541. {
  1542. AfxMessageBox(IDS_REPL_QUEUED, MB_ICONINFORMATION);
  1543. }
  1544. else
  1545. {
  1546. WinsMessageBox(err);
  1547. }
  1548. return HRESULT_FROM_WIN32(err);
  1549. }
  1550. /*---------------------------------------------------------------------------
  1551. CWinsServerHandler::OnSendPullTrigger()
  1552. Sends Pull replication trigger
  1553. ---------------------------------------------------------------------------*/
  1554. HRESULT
  1555. CWinsServerHandler::OnSendPullTrigger(ITFSNode * pNode)
  1556. {
  1557. HRESULT hr = hrOK;
  1558. DWORD err = ERROR_SUCCESS;
  1559. CPullTrig dlgPullTrig;
  1560. CGetTriggerPartner dlgTrigPartner;
  1561. CThemeContextActivator themeActivator;
  1562. if (dlgTrigPartner.DoModal() != IDOK)
  1563. return hr;
  1564. if (dlgPullTrig.DoModal() != IDOK)
  1565. return hr;
  1566. err = ::SendTrigger(GetBinding(),
  1567. (LONG) dlgTrigPartner.m_dwServerIp,
  1568. FALSE,
  1569. FALSE);
  1570. if (err == ERROR_SUCCESS)
  1571. {
  1572. AfxMessageBox(IDS_REPL_QUEUED, MB_ICONINFORMATION);
  1573. }
  1574. else
  1575. {
  1576. ::WinsMessageBox(err);
  1577. }
  1578. return HRESULT_FROM_WIN32(err);
  1579. }
  1580. /*---------------------------------------------------------------------------
  1581. CWinsServerHandler::GetFolderName(CString& strPath)
  1582. Returns the folder name after displaying the
  1583. File Dialog
  1584. ---------------------------------------------------------------------------*/
  1585. BOOL
  1586. CWinsServerHandler::GetFolderName(CString& strPath, CString& strHelpText)
  1587. {
  1588. BOOL fOk = FALSE;
  1589. TCHAR szBuffer[MAX_PATH];
  1590. TCHAR szExpandedPath[MAX_PATH * 2];
  1591. CString strStartingPath = m_cConfig.m_strBackupPath;
  1592. if (strStartingPath.IsEmpty())
  1593. {
  1594. strStartingPath = _T("%SystemDrive%\\");
  1595. }
  1596. ExpandEnvironmentStrings(strStartingPath, szExpandedPath, sizeof(szExpandedPath) / sizeof(TCHAR));
  1597. LPITEMIDLIST pidlPrograms = NULL;
  1598. SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidlPrograms);
  1599. BROWSEINFO browseInfo;
  1600. browseInfo.hwndOwner = ::FindMMCMainWindow();
  1601. browseInfo.pidlRoot = pidlPrograms;
  1602. browseInfo.pszDisplayName = szBuffer;
  1603. browseInfo.lpszTitle = strHelpText;
  1604. browseInfo.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS ;
  1605. browseInfo.lpfn = BrowseCallbackProc;
  1606. browseInfo.lParam = (LPARAM) szExpandedPath;
  1607. LPITEMIDLIST pidlBrowse = SHBrowseForFolder(&browseInfo);
  1608. fOk = SHGetPathFromIDList(pidlBrowse, szBuffer);
  1609. CString strBackupPath(szBuffer);
  1610. strPath = strBackupPath;
  1611. LPMALLOC pMalloc = NULL;
  1612. if (pidlPrograms && SUCCEEDED(SHGetMalloc(&pMalloc)))
  1613. {
  1614. if (pMalloc)
  1615. pMalloc->Free(pidlPrograms);
  1616. }
  1617. return fOk;
  1618. }
  1619. /*---------------------------------------------------------------------------
  1620. CWinsServerHandler::SetExtensionName()
  1621. -
  1622. Author: EricDav
  1623. ---------------------------------------------------------------------------*/
  1624. void
  1625. CWinsServerHandler::SetExtensionName()
  1626. {
  1627. SetDisplayName(_T("WINS"));
  1628. m_bExtension = TRUE;
  1629. }
  1630. /*---------------------------------------------------------------------------
  1631. CWinsServerHandler::IsLocalConnection()
  1632. Checks if the local server is being managed
  1633. Author: v-shubk
  1634. ---------------------------------------------------------------------------*/
  1635. BOOL
  1636. CWinsServerHandler::IsLocalConnection()
  1637. {
  1638. // get the server netbios name
  1639. CString strServerName = m_strServerAddress;
  1640. TCHAR lpBuffer[MAX_COMPUTERNAME_LENGTH + 1]; // address of name buffer
  1641. DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
  1642. ::GetComputerName(lpBuffer,&nSize);
  1643. CString strCompName(lpBuffer);
  1644. if(strCompName.CompareNoCase(strServerName) == 0)
  1645. return TRUE;
  1646. return FALSE;
  1647. }
  1648. /*---------------------------------------------------------------------------
  1649. CWinsServerHandler:: DeleteWinsServer(CWinsServerObj* pws)
  1650. Calls WinsAPI to delete the server
  1651. Author: v-shubk
  1652. ---------------------------------------------------------------------------*/
  1653. DWORD
  1654. CWinsServerHandler:: DeleteWinsServer
  1655. (
  1656. DWORD dwIpAddress
  1657. )
  1658. {
  1659. DWORD err = ERROR_SUCCESS;
  1660. WINSINTF_ADD_T WinsAdd;
  1661. WinsAdd.Len = 4;
  1662. WinsAdd.Type = 0;
  1663. WinsAdd.IPAdd = dwIpAddress;
  1664. #ifdef WINS_CLIENT_APIS
  1665. err = ::WinsDeleteWins(GetBinding(), &WinsAdd);
  1666. #else
  1667. err = ::WinsDeleteWins(&WinsAdd);
  1668. #endif WINS_CLIENT_APIS
  1669. return err;
  1670. }
  1671. /*---------------------------------------------------------------------------
  1672. CWinsServerHandler::DisConnectFromWinsServer()
  1673. Calls WinsUnbind and makes the binding handle invalid
  1674. ---------------------------------------------------------------------------*/
  1675. void
  1676. CWinsServerHandler::DisConnectFromWinsServer()
  1677. {
  1678. if (m_hBinding)
  1679. {
  1680. CString strIP;
  1681. WINSINTF_BIND_DATA_T wbdBindData;
  1682. DWORD dwIP = GetServerIP();
  1683. MakeIPAddress(dwIP, strIP);
  1684. wbdBindData.fTcpIp = 1;
  1685. wbdBindData.pPipeName = NULL;
  1686. wbdBindData.pServerAdd = (LPSTR) (LPCTSTR) strIP;
  1687. ::WinsUnbind(&wbdBindData, m_hBinding);
  1688. m_hBinding = NULL;
  1689. }
  1690. }
  1691. /*---------------------------------------------------------------------------
  1692. CWinsServerHandler::CheckIfNT351Server()
  1693. Checks if a 351 server is being managed
  1694. ---------------------------------------------------------------------------*/
  1695. BOOL
  1696. CWinsServerHandler::CheckIfNT351Server()
  1697. {
  1698. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1699. DWORD err = ERROR_SUCCESS;
  1700. CString lpstrRoot;
  1701. CString lpstrVersion;
  1702. CString strVersion;
  1703. BOOL f351 = FALSE;
  1704. // don't go to the registry each time -- we have the info in our config object
  1705. // 7/8/98 - EricDav
  1706. /*
  1707. // connect to the registry of the server to find if
  1708. // it's a 351 server
  1709. lpstrRoot = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
  1710. lpstrVersion = _T("CurrentVersion");
  1711. RegKey rk;
  1712. err = rk.Open(HKEY_LOCAL_MACHINE, lpstrRoot, KEY_READ, m_strServerAddress);
  1713. // Get the count of items
  1714. if (!err)
  1715. err = rk.QueryValue(lpstrVersion,strVersion) ;
  1716. if(strVersion.CompareNoCase(_T("3.51")) == 0 )
  1717. return TRUE;
  1718. return FALSE;
  1719. */
  1720. if (m_cConfig.m_dwMajorVersion < 4)
  1721. {
  1722. f351 = TRUE;
  1723. }
  1724. return f351;
  1725. }
  1726. /*---------------------------------------------------------------------------
  1727. CWinsServerHandler::SetDisplay()
  1728. Sets the node name to either the host name or FQDN
  1729. ---------------------------------------------------------------------------*/
  1730. void
  1731. CWinsServerHandler::SetDisplay(ITFSNode * pNode, BOOL fFQDN)
  1732. {
  1733. CHAR szHostName[MAX_PATH] = {0};
  1734. CString strIPAdd, strDisplay;
  1735. ::MakeIPAddress(m_dwIPAdd, strIPAdd);
  1736. if (fFQDN)
  1737. {
  1738. // check if the server name was resolved and added
  1739. if (m_dwIPAdd != 0)
  1740. {
  1741. // default is ACP. This should use ACP because winsock uses ACP
  1742. WideToMBCS(m_strServerAddress, szHostName);
  1743. HOSTENT * pHostent = ::gethostbyname((CHAR *) szHostName);
  1744. if (pHostent)
  1745. {
  1746. CString strFQDN;
  1747. MBCSToWide(pHostent->h_name, strFQDN);
  1748. strFQDN.MakeLower();
  1749. strDisplay.Format(IDS_SERVER_NAME_FORMAT, strFQDN, strIPAdd);
  1750. SetDisplayName(strDisplay);
  1751. if (pNode)
  1752. pNode->ChangeNode(SCOPE_PANE_CHANGE_ITEM_DATA);
  1753. }
  1754. }
  1755. }
  1756. // if not FQDN
  1757. else
  1758. {
  1759. if (m_dwIPAdd != 0)
  1760. {
  1761. strDisplay.Format(IDS_SERVER_NAME_FORMAT, m_strServerAddress, strIPAdd);
  1762. }
  1763. else
  1764. {
  1765. strDisplay = m_strServerAddress;
  1766. }
  1767. SetDisplayName(strDisplay);
  1768. if (pNode)
  1769. pNode->ChangeNode(SCOPE_PANE_CHANGE_ITEM_DATA);
  1770. }
  1771. }
  1772. void
  1773. CWinsServerHandler::GetErrorInfo(CString & strTitle, CString & strBody, IconIdentifier * pIcon)
  1774. {
  1775. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1776. TCHAR szBuffer[MAX_PATH * 2];
  1777. // build the body text
  1778. LoadMessage(m_dwErr, szBuffer, sizeof(szBuffer) / sizeof(TCHAR));
  1779. AfxFormatString1(strBody, IDS_SERVER_MESSAGE_BODY, szBuffer);
  1780. CString strTemp;
  1781. strTemp.LoadString(IDS_SERVER_MESSAGE_BODY_REFRESH);
  1782. strBody += strTemp;
  1783. // get the title
  1784. strTitle.LoadString(IDS_SERVER_MESSAGE_TITLE);
  1785. // and the icon
  1786. if (pIcon)
  1787. {
  1788. *pIcon = Icon_Error;
  1789. }
  1790. }
  1791. /*---------------------------------------------------------------------------
  1792. Background thread functionality
  1793. ---------------------------------------------------------------------------*/
  1794. /*---------------------------------------------------------------------------
  1795. CWinsServerHandler::OnCreateQuery
  1796. Description
  1797. Author: EricDav
  1798. ---------------------------------------------------------------------------*/
  1799. ITFSQueryObject*
  1800. CWinsServerHandler::OnCreateQuery(ITFSNode * pNode)
  1801. {
  1802. CWinsServerQueryObj* pQuery = NULL;
  1803. HRESULT hr = hrOK;
  1804. COM_PROTECT_TRY
  1805. {
  1806. m_pNameThread = new CNameThread();
  1807. pQuery = new CWinsServerQueryObj(m_spTFSCompData, m_spNodeMgr);
  1808. pQuery->m_strServer = GetServerAddress();
  1809. pQuery->m_dwIPAdd = m_dwIPAdd;
  1810. pQuery->m_pNameThread = m_pNameThread;
  1811. pQuery->m_pServerInfoArray = &m_ServerInfoArray;
  1812. }
  1813. COM_PROTECT_CATCH
  1814. return pQuery;
  1815. }
  1816. /*---------------------------------------------------------------------------
  1817. CWinsServerHandler::OnEventAbort
  1818. Description
  1819. Author: EricDav
  1820. ---------------------------------------------------------------------------*/
  1821. void
  1822. CWinsServerQueryObj::OnEventAbort
  1823. (
  1824. DWORD dwData,
  1825. DWORD dwType
  1826. )
  1827. {
  1828. if (dwType == WINS_QDATA_SERVER_INFO)
  1829. {
  1830. Trace0("CWinsServerHandler::OnEventAbort - deleting version");
  1831. delete ULongToPtr(dwData);
  1832. }
  1833. }
  1834. /*---------------------------------------------------------------------------
  1835. CWinsServerQueryObj::Execute()
  1836. Enumerates everything about a server
  1837. Author: EricDav
  1838. ---------------------------------------------------------------------------*/
  1839. STDMETHODIMP
  1840. CWinsServerQueryObj::Execute()
  1841. {
  1842. HRESULT hr = hrOK;
  1843. WINSINTF_BIND_DATA_T wbdBindData;
  1844. CString strName, strIp;
  1845. DWORD dwStatus = ERROR_SUCCESS;
  1846. DWORD dwIp;
  1847. CServerData * pServerInfo;
  1848. // need to get the server name and IP address if the server is added
  1849. // with Do not connect option
  1850. dwStatus = ::VerifyWinsServer(m_strServer, strName, dwIp);
  1851. if (dwStatus != ERROR_SUCCESS)
  1852. {
  1853. Trace1("CWinsServerQueryObj::Execute() - VerifyWinsServer failed! %d\n", dwStatus);
  1854. // Use the existing information we have to try and connect
  1855. if (m_dwIPAdd)
  1856. {
  1857. // we couldn't resolve the name so just use what we have and try to connect
  1858. strName = m_strServer;
  1859. dwIp = m_dwIPAdd;
  1860. }
  1861. else
  1862. {
  1863. // we don't have an IP for this and we can't resolve the name, so error out
  1864. PostError(dwStatus);
  1865. return hrFalse;
  1866. }
  1867. }
  1868. pServerInfo = new CServerData;
  1869. ::MakeIPAddress(dwIp, strIp);
  1870. pServerInfo->m_strServerName = strName;
  1871. pServerInfo->m_dwServerIp = dwIp;
  1872. pServerInfo->m_hBinding = NULL;
  1873. // get a binding for this server
  1874. wbdBindData.fTcpIp = 1;
  1875. wbdBindData.pPipeName = NULL;
  1876. wbdBindData.pServerAdd = (LPSTR) (LPCTSTR) strIp;
  1877. if ((pServerInfo->m_hBinding = ::WinsBind(&wbdBindData)) == NULL)
  1878. {
  1879. dwStatus = ::GetLastError();
  1880. // send what info we have back to the main thread
  1881. AddToQueue((LPARAM) pServerInfo, WINS_QDATA_SERVER_INFO);
  1882. Trace1("CWinsServerQueryObj::Execute() - WinsBind failed! %d\n", dwStatus);
  1883. PostError(dwStatus);
  1884. return hrFalse;
  1885. }
  1886. // load the configuration object
  1887. //pServerInfo->m_config.SetOwner(strName);
  1888. pServerInfo->m_config.SetOwner(strIp);
  1889. dwStatus = pServerInfo->m_config.Load(pServerInfo->m_hBinding);
  1890. if (dwStatus != ERROR_SUCCESS)
  1891. {
  1892. // send what info we have back to the main thread
  1893. AddToQueue((LPARAM) pServerInfo, WINS_QDATA_SERVER_INFO);
  1894. Trace1("CWinsServerQueryObj::Execute() - Load configuration failed! %d\n", dwStatus);
  1895. PostError(dwStatus);
  1896. return hrFalse;
  1897. }
  1898. // send all of the information back to the main thread here
  1899. handle_t hBinding = pServerInfo->m_hBinding;
  1900. AddToQueue((LPARAM) pServerInfo, WINS_QDATA_SERVER_INFO);
  1901. // build the child nodes
  1902. AddNodes(hBinding);
  1903. return hrFalse;
  1904. }
  1905. /*---------------------------------------------------------------------------
  1906. CWinsServerQueryObj::AddNodes
  1907. Creates the active registrations and replication partners nodes
  1908. Author: EricDav
  1909. ---------------------------------------------------------------------------*/
  1910. void
  1911. CWinsServerQueryObj::AddNodes(handle_t hBinding)
  1912. {
  1913. HRESULT hr = hrOK;
  1914. SPITFSNode spActReg, spRepPart;
  1915. CServerInfoArray * pServerInfoArray;
  1916. //
  1917. // active registrations node
  1918. //
  1919. CActiveRegistrationsHandler *pActRegHand = NULL;
  1920. try
  1921. {
  1922. pActRegHand = new CActiveRegistrationsHandler(m_spTFSCompData);
  1923. }
  1924. catch(...)
  1925. {
  1926. hr = E_OUTOFMEMORY;
  1927. }
  1928. //
  1929. // Create the actreg container information
  1930. //
  1931. CreateContainerTFSNode(&spActReg,
  1932. &GUID_WinsActiveRegNodeType,
  1933. pActRegHand,
  1934. pActRegHand,
  1935. m_spNodeMgr);
  1936. // Tell the handler to initialize any specific data
  1937. pActRegHand->InitializeNode((ITFSNode *) spActReg);
  1938. // load the name type mapping from the registry
  1939. pActRegHand->m_NameTypeMap.SetMachineName(m_strServer);
  1940. pActRegHand->m_NameTypeMap.Load();
  1941. // build the owner mapping
  1942. pActRegHand->m_pServerInfoArray = m_pServerInfoArray;
  1943. pActRegHand->BuildOwnerArray(hBinding);
  1944. // Post this node back to the main thread
  1945. AddToQueue(spActReg);
  1946. pActRegHand->Release();
  1947. //
  1948. // replication partners node
  1949. //
  1950. CReplicationPartnersHandler *pReplicationHand = NULL;
  1951. try
  1952. {
  1953. pReplicationHand = new CReplicationPartnersHandler (m_spTFSCompData);
  1954. }
  1955. catch(...)
  1956. {
  1957. hr = E_OUTOFMEMORY;
  1958. }
  1959. // Create the actreg container information
  1960. CreateContainerTFSNode(&spRepPart,
  1961. &GUID_WinsReplicationNodeType,
  1962. pReplicationHand,
  1963. pReplicationHand,
  1964. m_spNodeMgr);
  1965. // Tell the handler to initialize any specific data
  1966. pReplicationHand->InitializeNode((ITFSNode *) spRepPart);
  1967. // Post this node back to the main thread
  1968. AddToQueue(spRepPart);
  1969. pReplicationHand->Release();
  1970. // kick off the name query thread
  1971. m_pNameThread->Init(m_pServerInfoArray);
  1972. m_pNameThread->Start();
  1973. }