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.

1770 lines
47 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*++
  3. Module Name:
  4. MainFrm.cpp
  5. Abstract:
  6. This Module contains the implementation of CMainFrame class
  7. (The Frame Window of the application)
  8. Author:
  9. Arathi Kundapur (v-akunda) 11-Feb-1998
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include <lm.h>
  14. #include "LicMgr.h"
  15. #include "defines.h"
  16. #include "LSServer.h"
  17. #include "MainFrm.h"
  18. #include "RtList.h"
  19. #include "lSmgrdoc.h"
  20. #include "LtView.h"
  21. #include "cntdlg.h"
  22. #include "treenode.h"
  23. #include "ntsecapi.h"
  24. #include "TlsHunt.h"
  25. #include "htmlhelp.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. #define TRUSTED_ACTIVATION_SITE_REGPATH L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\escDomains\\microsoft.com\\*.activate"
  32. #define TRUSTED_ACTIVATION_REG_VALUE_NAME L"https"
  33. #define TRUSTED_ACTIVATION_REG_VALUE 2
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMainFrame
  36. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  37. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  38. //{{AFX_MSG_MAP(CMainFrame)
  39. ON_WM_CREATE()
  40. ON_MESSAGE(WM_ENUMERATESERVER, OnEnumerateServer)
  41. ON_MESSAGE(WM_SEL_CHANGE, OnSelChange)
  42. ON_MESSAGE(WM_ADD_ALL_SERVERS, OnAddAllServers)
  43. ON_MESSAGE(WM_ADD_SERVER, OnAddServer)
  44. ON_COMMAND(ID_LARGE_ICONS, OnLargeIcons)
  45. ON_COMMAND(ID_SMALL_ICONS, OnSmallIcons)
  46. ON_COMMAND(ID_LIST, OnList)
  47. ON_COMMAND(ID_DETAILS, OnDetails)
  48. ON_COMMAND(ID_EXIT, OnExit)
  49. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  50. ON_COMMAND(ID_HELP_FINDER, OnHelp)
  51. ON_COMMAND(ID_CONNECT_SERVER, OnConnectServer)
  52. ON_COMMAND(ID_REGISTRATION, OnRegistration)
  53. ON_COMMAND(ID_KEY_HELP , OnHelp )
  54. ON_UPDATE_COMMAND_UI( ID_ACTION_DOWNLOADLICENSES, OnUpdateDownloadlicenses )
  55. ON_UPDATE_COMMAND_UI( ID_ACTION_ADVANCED_REPEATLASTDOWNLOAD , OnUpdateRepeatLastDownload )
  56. ON_UPDATE_COMMAND_UI( ID_ACTION_ADVANCED_REREGISTERSERVER , OnUpdateReregisterserver )
  57. ON_UPDATE_COMMAND_UI( ID_ACTION_ADVANCED_UNREGISTERSERVER , OnUpdateUnregisterserver )
  58. ON_UPDATE_COMMAND_UI( ID_VIEW_PROPERTIES , OnUpdateProperties )
  59. ON_COMMAND( ID_REFRESH, OnRefreshServer )
  60. ON_COMMAND( ID_VIEW_REFRESHALL , OnRefresh )
  61. ON_UPDATE_COMMAND_UI( ID_REFRESH , OnUpdateRefresh )
  62. ON_COMMAND( ID_ACTION_DOWNLOADLICENSES , OnDownLoadLicenses )
  63. ON_COMMAND( ID_ACTION_ADVANCED_REPEATLASTDOWNLOAD , OnRepeatLastDownLoad )
  64. ON_COMMAND( ID_ACTION_ADVANCED_REREGISTERSERVER , OnReRegisterServer )
  65. ON_COMMAND( ID_ACTION_ADVANCED_UNREGISTERSERVER , OnUnRegisterServer )
  66. ON_COMMAND( ID_VIEW_PROPERTIES , OnProperties )
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. static UINT indicators[] =
  70. {
  71. ID_SEPARATOR, // status line indicator
  72. ID_INDICATOR_CAPS,
  73. ID_INDICATOR_NUM,
  74. ID_INDICATOR_SCRL,
  75. };
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CMainFrame construction/destruction
  78. CMainFrame::CMainFrame()
  79. {
  80. m_pRightView= NULL;
  81. m_pLeftView = NULL;
  82. m_pServer = NULL;
  83. }
  84. CMainFrame::~CMainFrame()
  85. {
  86. }
  87. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  88. {
  89. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  90. return -1;
  91. if (!m_wndToolBar.Create(this) ||
  92. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  93. {
  94. TRACE0("Failed to create toolbar\n");
  95. return -1; // fail to create
  96. }
  97. #if 0
  98. if (!m_wndStatusBar.Create(this) ||
  99. !m_wndStatusBar.SetIndicators(indicators,
  100. sizeof(indicators)/sizeof(UINT)))
  101. {
  102. TRACE0("Failed to create status bar\n");
  103. return -1; // fail to create
  104. }
  105. #endif
  106. // Remove this if you don't want tool tips or a resizeable toolbar
  107. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  108. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  109. // Delete these three lines if you don't want the toolbar to be dockable
  110. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  111. EnableDocking(CBRS_ALIGN_ANY);
  112. DockControlBar(&m_wndToolBar);
  113. return 0;
  114. }
  115. void CMainFrame::OnHelp()
  116. {
  117. TCHAR * pHtml = L"ts_lice_topnode.htm";
  118. HtmlHelp(AfxGetMainWnd()->m_hWnd, L"tslic.chm", HH_DISPLAY_TOPIC,(DWORD_PTR)pHtml);
  119. }
  120. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  121. {
  122. cs.style &= ~FWS_ADDTOTITLE;
  123. return CFrameWnd::PreCreateWindow(cs);
  124. }
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CMainFrame diagnostics
  127. #ifdef _DEBUG
  128. void CMainFrame::AssertValid() const
  129. {
  130. CFrameWnd::AssertValid();
  131. }
  132. void CMainFrame::Dump(CDumpContext& dc) const
  133. {
  134. CFrameWnd::Dump(dc);
  135. }
  136. #endif //_DEBUG
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CMainFrame message handlers
  139. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
  140. {
  141. m_SplitterWnd.CreateStatic(this,1,2); //1 row, 2 columns
  142. m_SplitterWnd.CreateView(0,0,(CRuntimeClass *)pContext->m_pNewViewClass,CSize(150,150),pContext);
  143. m_SplitterWnd.CreateView(0,1,RUNTIME_CLASS(CRightList),CSize(0,0),pContext);
  144. m_pRightView = (CView *)m_SplitterWnd.GetPane(0, 1);
  145. m_pLeftView = (CLicMgrLeftView *)m_SplitterWnd.GetPane(0, 0);
  146. return TRUE;
  147. }
  148. LRESULT CMainFrame::OnSelChange(WPARAM wParam, LPARAM lParam)
  149. {
  150. LRESULT lResult = 0;
  151. m_pRightView->SendMessage(WM_SEL_CHANGE,wParam,lParam);
  152. return lResult;
  153. }
  154. void CMainFrame::OnLargeIcons()
  155. {
  156. PressButton(ID_LARGE_ICONS,TRUE);
  157. PressButton(ID_SMALL_ICONS,FALSE);
  158. PressButton(ID_LIST,FALSE);
  159. PressButton(ID_DETAILS,FALSE);
  160. m_pRightView->SendMessage(WM_COMMAND,ID_LARGE_ICONS,0);
  161. }
  162. void CMainFrame::OnSmallIcons()
  163. {
  164. PressButton(ID_LARGE_ICONS,FALSE);
  165. PressButton(ID_SMALL_ICONS,TRUE);
  166. PressButton(ID_LIST,FALSE);
  167. PressButton(ID_DETAILS,FALSE);
  168. m_pRightView->SendMessage(WM_COMMAND,ID_SMALL_ICONS,0);
  169. }
  170. void CMainFrame::OnList()
  171. {
  172. PressButton(ID_LARGE_ICONS,FALSE);
  173. PressButton(ID_SMALL_ICONS,FALSE);
  174. PressButton(ID_LIST,TRUE);
  175. PressButton(ID_DETAILS,FALSE);
  176. m_pRightView->SendMessage(WM_COMMAND,ID_LIST,0);
  177. }
  178. void CMainFrame::OnDetails()
  179. {
  180. PressButton(ID_LARGE_ICONS,FALSE);
  181. PressButton(ID_SMALL_ICONS,FALSE);
  182. PressButton(ID_LIST,FALSE);
  183. PressButton(ID_DETAILS,TRUE);
  184. m_pRightView->SendMessage(WM_COMMAND,ID_DETAILS,0);
  185. }
  186. void CMainFrame::OnExit()
  187. {
  188. SendMessage(WM_CLOSE,0,0);
  189. }
  190. LRESULT CMainFrame::OnAddAllServers(WPARAM wParam, LPARAM lParam)
  191. {
  192. LRESULT lResult = 0;
  193. m_pLeftView->SendMessage(WM_ADD_ALL_SERVERS,wParam,lParam);
  194. return lResult;
  195. }
  196. LRESULT CMainFrame::OnAddServer(WPARAM wParam, LPARAM lParam)
  197. {
  198. LRESULT lResult = 0;
  199. m_pLeftView->SendMessage(WM_ADD_SERVER,wParam,lParam);
  200. m_pRightView->SendMessage(WM_ADD_SERVER,wParam,lParam);
  201. return lResult;
  202. }
  203. void CMainFrame::OnAppAbout()
  204. {
  205. CString AppName;
  206. AppName.LoadString(IDS_APP_NAME);
  207. ::ShellAbout((HWND)m_hWnd,(LPCTSTR)AppName,
  208. NULL,NULL);
  209. }
  210. void CMainFrame::OnRegistration()
  211. {
  212. CWnd* cWnd = AfxGetMainWnd();
  213. HWND hWnd=cWnd->GetSafeHwnd();
  214. DWORD status;
  215. CString TempString;
  216. CString Server;
  217. CLicServer* pServer = NULL;
  218. WCHAR szServer[MAX_COMPUTERNAME_LENGTH + 1];
  219. BOOL bRefresh;
  220. try
  221. {
  222. if(ERROR_SUCCESS != GetActiveServer(&pServer))
  223. {
  224. DBGMSG( L"LICMGR : OnRegistration no active servers\n",0 );
  225. return;
  226. }
  227. if(SERVER_TS5_ENFORCED == pServer->GetServerType())
  228. {
  229. DBGMSG( L"LICMGR : OnRegistration on enforced server\n",0 );
  230. if( !pServer->IsUserAdmin( ) )
  231. {
  232. AfxMessageBox( IDS_E_ACCESSDENIED );
  233. // ::MessageBox( GetSafeHwnd( ) , L"Unable to perform operation: Access denied" , L"Terminal Services Licensing" , MB_OK|MB_ICONINFORMATION );
  234. return;
  235. }
  236. if(pServer->UseIpAddress())
  237. {
  238. Server = pServer->GetIpAddress();
  239. }
  240. else
  241. {
  242. Server = pServer->GetName();
  243. }
  244. lstrcpy(szServer, (LPCTSTR)Server);
  245. DWORD dwStatus = pServer->GetServerRegistrationStatus( );
  246. DBGMSG( L"LICMGR:CMainFrame::OnRegistration calling StartWizard\n", 0 );
  247. StartWizardEx( hWnd , WIZACTION_REGISTERLS , szServer , &bRefresh );
  248. //DBGMSG( L"LICMGR:CMainFrame::OnRegistration - StartWizard returned 0x%x\n" , status );
  249. if( IsLicenseServerRegistered( hWnd , szServer , &status ) == ERROR_SUCCESS )
  250. {
  251. pServer->SetServerRegistrationStatus( status );
  252. }
  253. if( dwStatus != status )
  254. {
  255. RefreshServer(pServer);
  256. }
  257. UpdateWindow();
  258. }
  259. else
  260. {
  261. DBGMSG( L"LICMGR : OnRegistration on non-enforced server\n",0 );
  262. }
  263. }
  264. catch (...)
  265. {
  266. // validation failed - user already alerted, fall through
  267. // Note: DELETE_EXCEPTION_(e) not required
  268. }
  269. }
  270. //////////////////////////////////////////////////////////////////////////////
  271. BOOL
  272. CMainFrame::ConnectServer(
  273. LPCTSTR pszServer
  274. )
  275. /*++
  276. ++*/
  277. {
  278. CConnectDialog ConnectDialog;
  279. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  280. ASSERT(pDoc);
  281. if(NULL == pDoc)
  282. return FALSE;
  283. HRESULT hResult = ERROR_SUCCESS;
  284. SERVER_TYPE ServerType;
  285. CString Scope;
  286. if(pszServer == NULL)
  287. {
  288. if(ConnectDialog.DoModal() != IDOK)
  289. {
  290. return FALSE;
  291. }
  292. //
  293. // Empty string - local machine
  294. //
  295. if(ConnectDialog.m_Server.IsEmpty())
  296. {
  297. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  298. DWORD dwBufSize = MAX_COMPUTERNAME_LENGTH + 1;
  299. memset(szComputerName, 0, sizeof(szComputerName));
  300. GetComputerName(szComputerName, &dwBufSize);
  301. ConnectDialog.m_Server = szComputerName;
  302. }
  303. }
  304. else
  305. {
  306. //
  307. // Minimize code change
  308. //
  309. ConnectDialog.m_Server = pszServer;
  310. }
  311. SetCursor(LoadCursor(NULL,IDC_WAIT));
  312. if(TRUE == pDoc->IsServerInList(ConnectDialog.m_Server))
  313. {
  314. //AfxMessageBox(IDS_DUPLICATE_SERVER);
  315. return FALSE;
  316. }
  317. //HUEIHUEI - Check if server is registered
  318. //
  319. // Do a NT4 RPC connect to make sure the license server
  320. // can accept our calls.
  321. //
  322. CString IpAddress(ConnectDialog.m_Server);
  323. hResult = pDoc->ConnectToServer(
  324. ConnectDialog.m_Server,
  325. Scope,
  326. ServerType
  327. );
  328. if(ERROR_SUCCESS != hResult)
  329. {
  330. CDialog ErrorDialog(IDD_CONNECT_ERROR,this);
  331. ErrorDialog.DoModal();
  332. }
  333. else
  334. {
  335. CAllServers * pAllServers = pDoc->GetAllServers();
  336. CLicServer *pServer1 = NULL;
  337. if(IpAddress != ConnectDialog.m_Server)
  338. {
  339. if(TRUE == pDoc->IsServerInList(ConnectDialog.m_Server))
  340. {
  341. return TRUE;
  342. }
  343. pServer1 = new CLicServer(
  344. ConnectDialog.
  345. m_Server,
  346. ServerType,
  347. Scope,
  348. IpAddress
  349. );
  350. }
  351. else
  352. {
  353. pServer1= new CLicServer(
  354. ConnectDialog.
  355. m_Server,
  356. ServerType,
  357. Scope
  358. );
  359. }
  360. if(pServer1)
  361. {
  362. DWORD dwStatus;
  363. // check for admin
  364. pServer1->SetAdmin( IsUserAdmin( pServer1->GetName() ) );
  365. if( pServer1->IsUserAdmin( ) )
  366. {
  367. if( IsLicenseServerRegistered( GetSafeHwnd() , ( LPCTSTR )pServer1->GetName() , &dwStatus ) == ERROR_SUCCESS )
  368. {
  369. pServer1->SetServerRegistrationStatus( dwStatus );
  370. }
  371. }
  372. CLicMgrDoc * pDoc = (CLicMgrDoc *)(GetActiveView()->GetDocument());
  373. pDoc->EnumerateKeyPacks( pServer1 , LSKEYPACK_SEARCH_LANGID , TRUE );
  374. WIZCONNECTION WizConType;
  375. if( GetConnectionType( GetSafeHwnd() , pServer1->GetName() , &WizConType ) == ERROR_SUCCESS )
  376. {
  377. DBGMSG( L"ConnectServer - GetConnectionType obtained %d" , WizConType );
  378. pServer1->SetConType( WizConType );
  379. }
  380. pAllServers->AddLicServer(pServer1);
  381. SendMessage(WM_ADD_SERVER,0,(LPARAM)pServer1);
  382. // after the send message is called all servers will have their keypacks cached.
  383. pServer1->SetDownLoadLics( IsDownLoadedPacks( pServer1 ) );
  384. }
  385. else
  386. {
  387. return FALSE;
  388. }
  389. }
  390. return TRUE;
  391. }
  392. ////////////////////////////////////////////////////////////////////////////
  393. void
  394. CMainFrame::OnConnectServer()
  395. {
  396. ConnectServer();
  397. }
  398. HRESULT
  399. CMainFrame::AddLicensestoList(
  400. CKeyPack * pKeyPack,
  401. CListCtrl * pListCtrl,
  402. BOOL bRefresh
  403. )
  404. /*++
  405. --*/
  406. {
  407. CLicServer *pServer = NULL;
  408. CString Error;
  409. HRESULT hr;
  410. ASSERT(pKeyPack);
  411. ASSERT(pListCtrl);
  412. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  413. ASSERT(pDoc);
  414. if(NULL == pKeyPack || NULL == pListCtrl || NULL == pDoc)
  415. {
  416. return E_FAIL;
  417. }
  418. if(TRUE == bRefresh)
  419. {
  420. if((hr = pKeyPack->RefreshIssuedLicenses()) != S_OK)
  421. {
  422. EnumFailed(hr,pKeyPack->GetServer());
  423. return E_FAIL;
  424. }
  425. }
  426. IssuedLicenseList * pIssuedLicenseList = pKeyPack->GetIssuedLicenseList();
  427. ASSERT(pIssuedLicenseList);
  428. if(NULL == pIssuedLicenseList)
  429. {
  430. return E_FAIL;
  431. }
  432. LSKeyPack sKeyPack = pKeyPack->GetKeyPackStruct();
  433. int nIndex = 0;
  434. int nSubitemIndex = 1;
  435. CString TempString;
  436. POSITION pos;
  437. LV_ITEM lvI;
  438. lvI.mask = LVIF_TEXT |LVIF_IMAGE |LVIF_STATE | LVIF_PARAM;
  439. lvI.state = 0;
  440. lvI.stateMask =0;
  441. lvI.iSubItem = 0;
  442. lvI.iImage = 2;
  443. pos = pIssuedLicenseList->GetHeadPosition();
  444. while(pos)
  445. {
  446. lvI.iItem = nIndex;
  447. nSubitemIndex = 1;
  448. CLicense * pLicense = pIssuedLicenseList->GetNext(pos);
  449. ASSERT(pLicense);
  450. if(NULL == pLicense)
  451. {
  452. continue;
  453. }
  454. LSLicenseEx sLicense = pLicense->GetLicenseStruct();
  455. lvI.lParam = (LPARAM)pLicense;
  456. TempString = sLicense.szMachineName;
  457. lvI.pszText = TempString.GetBuffer(TempString.GetLength());
  458. lvI.cchTextMax =lstrlen(lvI.pszText + 1);
  459. nIndex = pListCtrl->InsertItem(&lvI);
  460. //Set the Issue date.
  461. pDoc->TimeToString(&sLicense.ftIssueDate, TempString);
  462. if(TempString.IsEmpty())
  463. {
  464. TempString.LoadString(IDS_UNKNOWN);
  465. }
  466. pListCtrl->SetItemText(nIndex,nSubitemIndex,(LPCTSTR)TempString);
  467. nSubitemIndex++;
  468. //Set the expiry date.
  469. if(0x7FFFFFFF != sLicense.ftExpireDate)
  470. {
  471. TempString.LoadString(IDS_DASH);
  472. pDoc->TimeToString(&sLicense.ftExpireDate, TempString);
  473. if(TempString.IsEmpty())
  474. {
  475. TempString.LoadString(IDS_UNKNOWN);
  476. }
  477. }
  478. else
  479. {
  480. TempString.LoadString(IDS_DASH);
  481. }
  482. pListCtrl->SetItemText(nIndex,nSubitemIndex,(LPCTSTR)TempString);
  483. nSubitemIndex++;
  484. // adding status text to license's status column
  485. /*switch( sLicense.ucLicenseStatus )
  486. {
  487. case LSLICENSE_STATUS_UNKNOWN:
  488. TempString.LoadString( IDS_LICENSESTATUS_UNKNOWN );
  489. break;
  490. case LSLICENSE_STATUS_TEMPORARY:
  491. TempString.LoadString( IDS_LICENSESTATUS_TEMPORARY );
  492. break;
  493. case LSLICENSE_STATUS_ACTIVE:
  494. //case LSLICENSE_STATUS_PENDING_ACTIVE:
  495. case LSLICENSE_STATUS_CONCURRENT:
  496. TempString.LoadString( IDS_LICENSESTATUS_ACTIVE );
  497. break;
  498. case LSLICENSE_STATUS_UPGRADED:
  499. TempString.LoadString( IDS_LICENSESTATUS_UPGRADED );
  500. break;
  501. //case LSLICENSE_STATUS_REVOKE:
  502. //case LSLICENSE_STATUS_REVOKE_PENDING:
  503. // TempString.LoadString( IDS_LICENSESTATUS_REVOKE );
  504. }
  505. if( TempString.IsEmpty() )
  506. {
  507. TempString.LoadString(IDS_UNKNOWN);
  508. }
  509. pListCtrl->SetItemText(nIndex,nSubitemIndex,(LPCTSTR)TempString);*/
  510. // adding quantity
  511. TCHAR sQuantity[12]; //long enough to handle any DWORD
  512. _ltow(sLicense.dwQuantity, sQuantity, 10);
  513. pListCtrl->SetItemText(nIndex, nSubitemIndex, sQuantity);
  514. nIndex ++;
  515. }
  516. return S_OK;
  517. }
  518. void CMainFrame :: PressButton(UINT uId, BOOL bPress)
  519. {
  520. CToolBarCtrl& ToolBarCtrl = m_wndToolBar.GetToolBarCtrl();
  521. ToolBarCtrl.PressButton(uId,bPress);
  522. }
  523. /////////////////////////////////////////////////////////////////////
  524. LRESULT
  525. CMainFrame::OnEnumerateServer(WPARAM wParam, LPARAM lParam)
  526. {
  527. CTlsHunt huntDlg;
  528. huntDlg.DoModal();
  529. if( wParam == 0 &&
  530. huntDlg.IsUserCancel() == FALSE &&
  531. huntDlg.GetNumServerFound() == 0 )
  532. {
  533. AfxMessageBox(IDS_NOSERVERINDOMAIN);
  534. }
  535. return 0;
  536. }
  537. /////////////////////////////////////////////////////////////////////
  538. void
  539. CMainFrame :: ConnectAndDisplay()
  540. {
  541. CLicMgrApp *pApp = (CLicMgrApp*)AfxGetApp();
  542. ASSERT(pApp);
  543. CLicMgrDoc *pDoc = (CLicMgrDoc *)(GetActiveView()->GetDocument());
  544. ASSERT(pDoc);
  545. if(NULL == pApp || NULL == pDoc)
  546. return;
  547. HRESULT hResult = ERROR_SUCCESS;
  548. CString LicServer;
  549. CString Server = pApp->m_Server;
  550. if(!Server.IsEmpty())
  551. {
  552. //Server Specified in the command line. Connect to it.
  553. hResult = pDoc->ConnectWithCurrentParams();
  554. }
  555. else
  556. {
  557. ActivateFrame();
  558. //
  559. // Save a copy of what we have.
  560. //
  561. LicServer = pApp->m_Server;
  562. pApp->m_Server = _TEXT("");
  563. hResult = pDoc->ConnectWithCurrentParams();
  564. pApp->m_Server = LicServer;
  565. hResult = ERROR_SUCCESS;
  566. }
  567. switch(hResult)
  568. {
  569. case E_FAIL:
  570. AfxMessageBox(IDS_CONNECT_SERVER_FAILED);
  571. break;
  572. case E_OUTOFMEMORY:
  573. AfxMessageBox(IDS_NO_MEMORY);
  574. SendMessage(WM_CLOSE,0,0);
  575. break;
  576. case E_DUPLICATE:
  577. AfxMessageBox(IDS_DUPLICATE_SERVER);
  578. break;
  579. }
  580. return;
  581. }
  582. void CMainFrame::OnRefresh()
  583. {
  584. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  585. ASSERT(pDoc);
  586. if(NULL == pDoc)
  587. {
  588. AfxMessageBox(IDS_INTERNAL_ERROR);
  589. return;
  590. }
  591. HRESULT hResult = ERROR_SUCCESS;
  592. CWaitCursor Wait;
  593. CAllServers *pAllServers = pDoc->GetAllServers();
  594. ASSERT(pAllServers);
  595. if(NULL == pAllServers)
  596. {
  597. AfxMessageBox(IDS_INTERNAL_ERROR);
  598. return;
  599. }
  600. LicServerList * pLicServerList = pAllServers->GetLicServerList();
  601. ASSERT(pLicServerList);
  602. if(NULL == pLicServerList)
  603. {
  604. AfxMessageBox(IDS_INTERNAL_ERROR);
  605. return;
  606. }
  607. POSITION pos = pLicServerList->GetHeadPosition();
  608. OnEnumerateServer((pos == NULL) ? 0 : 1, 0); // show error dialog if nothing in the list
  609. Wait.Restore();
  610. while(pos)
  611. {
  612. // Connect to each server and check if the information in the cache is current. If not update the information.
  613. // If the connection to the server cannot be establised,add them to the list to display to the user.
  614. POSITION TempPos = pos;
  615. CLicServer * pLicServer = pLicServerList->GetNext(pos);
  616. ASSERT(pLicServer);
  617. if(NULL == pLicServer)
  618. continue;
  619. //Call Refresh Server
  620. hResult = RefreshServer(pLicServer);
  621. }
  622. return;
  623. }
  624. void CMainFrame::DeleteServer(LicServerList * pLicServerList, POSITION TempPos, CLicServer * pLicServer)
  625. {
  626. if(NULL == pLicServerList || NULL == pLicServer)
  627. return;
  628. m_pLeftView->SendMessage(WM_DELETE_SERVER,0,(LPARAM)pLicServer);
  629. m_pRightView->SendMessage(WM_DELETE_SERVER,0,(LPARAM)pLicServer);
  630. pLicServerList->RemoveAt(TempPos);
  631. delete pLicServer;
  632. pLicServer = NULL;
  633. }
  634. void CMainFrame::SetTreeViewSel(LPARAM lParam, NODETYPE NodeType)
  635. {
  636. if(NULL == lParam || NULL == m_pLeftView)
  637. return;
  638. ((CLicMgrLeftView *)m_pLeftView)->SetSelection(lParam, NodeType);
  639. SetActiveView(m_pLeftView);
  640. return;
  641. }
  642. void InitLsaString(PLSA_UNICODE_STRING LsaString, LPWSTR String )
  643. {
  644. DWORD StringLength;
  645. if (String == NULL)
  646. {
  647. LsaString->Buffer = NULL;
  648. LsaString->Length = 0;
  649. LsaString->MaximumLength = 0;
  650. return;
  651. }
  652. StringLength = lstrlen(String);
  653. LsaString->Buffer = String;
  654. LsaString->Length = (USHORT) StringLength * sizeof(WCHAR);
  655. LsaString->MaximumLength=(USHORT)(StringLength+1) * sizeof(WCHAR);
  656. }
  657. NTSTATUS
  658. OpenPolicy(
  659. LPWSTR ServerName,
  660. DWORD DesiredAccess,
  661. PLSA_HANDLE PolicyHandle
  662. )
  663. /*++
  664. --*/
  665. {
  666. LSA_OBJECT_ATTRIBUTES ObjectAttributes;
  667. LSA_UNICODE_STRING ServerString;
  668. PLSA_UNICODE_STRING Server = NULL;
  669. // Always initialize the object attributes to all zeroes.
  670. ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
  671. if (ServerName != NULL)
  672. {
  673. // Make a LSA_UNICODE_STRING out of the LPWSTR passed in
  674. InitLsaString(&ServerString, ServerName);
  675. Server = &ServerString;
  676. }
  677. // Attempt to open the policy.
  678. return LsaOpenPolicy(Server, &ObjectAttributes, DesiredAccess, PolicyHandle );
  679. }
  680. BOOL CMainFrame::IsUserAdmin(CString& Server)
  681. {
  682. BOOL IsUserAdmin = FALSE;
  683. LSA_HANDLE PolicyHandle = NULL;
  684. NTSTATUS Status;
  685. Status = OpenPolicy(Server.GetBuffer(Server.GetLength()),POLICY_SERVER_ADMIN,&PolicyHandle);
  686. DBGMSG( L"LICMGR@CMainFrame::IsUserAdmin OpenPolicy returned 0x%x\n" , Status );
  687. if(Status == 0)
  688. IsUserAdmin = TRUE;
  689. if(PolicyHandle)
  690. LsaClose(PolicyHandle);
  691. return IsUserAdmin;
  692. }
  693. void CMainFrame::EnumFailed(HRESULT reason, CLicServer * pLicServer)
  694. {
  695. DBGMSG( L"CMainFrame_EnumFailed\n" , 0 );
  696. ASSERT(pLicServer);
  697. if(NULL == pLicServer)
  698. return;
  699. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  700. ASSERT(pDoc);
  701. if(NULL == pDoc)
  702. return;
  703. CString Error;
  704. CString Server;
  705. POSITION pos;
  706. BOOL bFoundServer = FALSE;
  707. LicServerList * pLicServerList = NULL;
  708. POSITION temppos = NULL;
  709. switch(reason)
  710. {
  711. case CONNECTION_FAILED:
  712. DBGMSG( L"\tCONNECTION_FAILED\n" , 0 );
  713. Server = pLicServer->GetName();
  714. Error.Format(IDS_CONNECT_ERROR,Server);
  715. AfxMessageBox(Error);
  716. pLicServerList = (pDoc->GetAllServers())->GetLicServerList();
  717. if(NULL == pLicServerList)
  718. break;
  719. //Find the position of the server in the List;
  720. pos = pLicServerList->GetHeadPosition();
  721. while(pos)
  722. {
  723. temppos = pos;
  724. CLicServer *pServer = (CLicServer *)pLicServerList->GetNext(pos);
  725. ASSERT(pServer);
  726. if(NULL == pServer)
  727. continue;
  728. if((0 == Server.CompareNoCase(pServer->GetName())) || (0 == Server.CompareNoCase(pServer->GetIpAddress())))
  729. {
  730. bFoundServer = TRUE;
  731. break;
  732. }
  733. }
  734. if(bFoundServer)
  735. DeleteServer(pLicServerList,temppos,pLicServer);
  736. break;
  737. case LSERVER_E_SERVER_BUSY:
  738. DBGMSG( L"\tLSERVER_E_SERVER_BUSY\n" , 0 );
  739. AfxMessageBox(IDS_SERVER_BUSY);
  740. break;
  741. case LSERVER_E_OUTOFMEMORY:
  742. DBGMSG( L"\tLSERVER_E_OUTOFMEMORY\n" , 0 );
  743. AfxMessageBox(IDS_SERVER_OUTOFMEMORY);
  744. break;
  745. case LSERVER_E_INTERNAL_ERROR:
  746. DBGMSG( L"\tLSERVER_E_INTERNAL_ERROR\n" , 0 );
  747. AfxMessageBox(IDS_SERVER_INTERNAL_ERROR);
  748. pLicServerList = (pDoc->GetAllServers())->GetLicServerList();
  749. if(NULL == pLicServerList)
  750. break;
  751. //Find the position of the server in the List;
  752. pos = pLicServerList->GetHeadPosition();
  753. while(pos)
  754. {
  755. temppos = pos;
  756. CLicServer *pServer = (CLicServer *)pLicServerList->GetNext(pos);
  757. ASSERT(pServer);
  758. if(NULL == pServer)
  759. continue;
  760. if((0 == Server.CompareNoCase(pServer->GetName())) || (0 == Server.CompareNoCase(pServer->GetIpAddress())))
  761. {
  762. bFoundServer = TRUE;
  763. break;
  764. }
  765. }
  766. if(bFoundServer)
  767. DeleteServer(pLicServerList,temppos,pLicServer);
  768. break;
  769. case E_OUTOFMEMORY:
  770. DBGMSG( L"\tE_OUTOFMEMORY\n" , 0 );
  771. AfxMessageBox(IDS_NO_MEMORY);
  772. break;
  773. default:
  774. break;
  775. }
  776. }
  777. void CMainFrame::SelectView(VIEW view)
  778. {
  779. if(view == TREEVIEW)
  780. {
  781. SetActiveView(m_pLeftView);
  782. }
  783. else
  784. {
  785. SetActiveView(m_pRightView);
  786. }
  787. }
  788. HRESULT CMainFrame::RefreshServer(CLicServer * pLicServer)
  789. {
  790. DWORD dwStatus = 0;
  791. HRESULT hResult = E_FAIL;
  792. CWaitCursor Wait;
  793. if(NULL == pLicServer)
  794. return E_INVALIDARG;
  795. DBGMSG( L"LICMGR : CMainFrame::RefreshServer %s\n" , (LPCTSTR) pLicServer->GetName( ) );
  796. CLicMgrDoc * pDoc =(CLicMgrDoc *)(GetActiveView()->GetDocument());
  797. ASSERT(pDoc);
  798. if(NULL == pDoc)
  799. return ERROR_INTERNAL_ERROR;
  800. CString Server;
  801. if(pLicServer->UseIpAddress())
  802. Server = pLicServer->GetIpAddress();
  803. else
  804. Server = pLicServer->GetName();
  805. WIZCONNECTION WizConType;
  806. DBGMSG( L"LICMGR:CMainFrame::RefreshServer setting ConnectionType\n" , 0 );
  807. hResult = GetConnectionType(GetSafeHwnd(), Server, &WizConType);
  808. //This will be returned if we couldn't connect to the remote registry
  809. if (hResult == ERROR_BAD_NETPATH)
  810. {
  811. EnumFailed(CONNECTION_FAILED, pLicServer);
  812. return hResult;
  813. }
  814. pLicServer->SetConType( WizConType );
  815. // check for admin
  816. DBGMSG( L"LICMGR:CMainFrame::RefreshServer setting admin priv\n" , 0 );
  817. pLicServer->SetAdmin( IsUserAdmin( Server ) );
  818. if( pLicServer->IsUserAdmin( ) )
  819. {
  820. DBGMSG( L"LICMGR:CMainFrame::RefreshServer updating server status\n" , 0 );
  821. if( IsLicenseServerRegistered( GetSafeHwnd( ) , Server , &dwStatus ) == ERROR_SUCCESS )
  822. pLicServer->SetServerRegistrationStatus( dwStatus );
  823. else
  824. pLicServer->SetServerRegistrationStatus( ( DWORD )-1 );
  825. }
  826. KeyPackList * pkeypackList = pLicServer->GetKeyPackList();
  827. if(NULL == pkeypackList)
  828. {
  829. DBGMSG( L"LICMGR:RefreshServer no keypacklist\n",0 );
  830. return E_FAIL;
  831. }
  832. POSITION pos1 = pkeypackList->GetHeadPosition();
  833. CKeyPack *pKeyPack = NULL;
  834. DBGMSG( L"LICMGR:CMainFrame::RefreshServer removing keypacks\n" , 0 );
  835. while(pos1)
  836. {
  837. pKeyPack = (CKeyPack *)pkeypackList->GetNext(pos1);
  838. ASSERT(pKeyPack);
  839. if(pKeyPack)
  840. {
  841. delete pKeyPack;
  842. pKeyPack = NULL;
  843. }
  844. }
  845. pkeypackList->RemoveAll();
  846. pLicServer->Expand(FALSE);
  847. DBGMSG( L"LICMGR:CMainFrame::RefreshServer enumerating keypacks\n" , 0 );
  848. hResult = pDoc->EnumerateKeyPacks(pLicServer, LSKEYPACK_SEARCH_LANGID, TRUE);
  849. if(hResult != S_OK)
  850. {
  851. EnumFailed( hResult , pLicServer );
  852. return hResult;
  853. }
  854. DBGMSG( L"LICMGR:CMainFrame::RefreshServer checking for keypacks\n" , 0 );
  855. pLicServer->SetDownLoadLics( IsDownLoadedPacks( pLicServer ) );
  856. m_pLeftView->SendMessage(WM_UPDATE_SERVER,0,(LPARAM)pLicServer);
  857. m_pRightView->SendMessage(WM_UPDATE_SERVER,0,(LPARAM)pLicServer);
  858. return hResult;
  859. }
  860. //--------------------------------------------------------------------
  861. void CMainFrame::OnUpdateDownloadlicenses( CCmdUI * pCmdUI )
  862. {
  863. DBGMSG( L"LICMGR@CMainFrame::OnUpdateDownloadlicenses\n" , 0 );
  864. CLicServer *pServer = NULL;
  865. HRESULT hr;
  866. GetActiveServer( &pServer );
  867. pCmdUI->Enable( FALSE );
  868. if( pServer != NULL )
  869. {
  870. if( pServer->GetServerType( ) == SERVER_TS5_ENFORCED )
  871. {
  872. pCmdUI->Enable( IsServerRegistered( &hr ) );
  873. }
  874. else
  875. {
  876. pCmdUI->Enable( TRUE );
  877. }
  878. }
  879. else
  880. {
  881. pCmdUI->Enable( FALSE );
  882. }
  883. }
  884. //--------------------------------------------------------------------
  885. void CMainFrame::OnUpdateRepeatLastDownload( CCmdUI * pCmdUI )
  886. {
  887. DBGMSG( L"LICMGR@CMainFrame::OnUpdateRepeatLastDownload\n" , 0 );
  888. HRESULT hr;
  889. CLicServer * pLicServer = NULL;
  890. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  891. {
  892. if( pLicServer->GetConType( ) != CONNECTION_WWW )
  893. {
  894. if( IsServerRegistered( &hr ) )
  895. {
  896. pCmdUI->Enable( IsLicensesDownLoaded() );
  897. return;
  898. }
  899. }
  900. }
  901. pCmdUI->Enable( FALSE );
  902. }
  903. //--------------------------------------------------------------------
  904. void CMainFrame::OnUpdateReregisterserver( CCmdUI * pCmdUI )
  905. {
  906. DBGMSG( L"LICMGR@CMainFrame::OnUpdateReregisterserver\n" , 0 );
  907. HRESULT hr;
  908. CLicServer * pLicServer = NULL;
  909. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  910. {
  911. if( pLicServer->GetConType( ) != CONNECTION_WWW )
  912. {
  913. pCmdUI->Enable( IsServerRegistered( &hr ) );
  914. return;
  915. }
  916. }
  917. pCmdUI->Enable( FALSE );
  918. }
  919. //--------------------------------------------------------------------
  920. void CMainFrame::OnUpdateUnregisterserver( CCmdUI * pCmdUI )
  921. {
  922. DBGMSG( L"LICMGR@CMainFrame::OnUpdateUnregisterserver\n" , 0 );
  923. HRESULT hr;
  924. CLicServer * pLicServer = NULL;
  925. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  926. {
  927. if( pLicServer->GetConType( ) != CONNECTION_WWW )
  928. {
  929. pCmdUI->Enable( IsServerRegistered( &hr ) );
  930. return;
  931. }
  932. }
  933. pCmdUI->Enable( FALSE );
  934. }
  935. //--------------------------------------------------------------------
  936. void CMainFrame::OnUpdateRefresh( CCmdUI *pCmdUI )
  937. {
  938. CLicServer * pLicServer = NULL;
  939. if( FAILED( GetActiveServer( &pLicServer ) ) )
  940. {
  941. pCmdUI->Enable( FALSE );
  942. }
  943. else
  944. {
  945. pCmdUI->Enable( TRUE );
  946. }
  947. }
  948. //--------------------------------------------------------------------
  949. void CMainFrame::OnUpdateProperties( CCmdUI *pCmdUI )
  950. {
  951. CLicServer * pLicServer = NULL;
  952. GetActiveServer( &pLicServer );
  953. pCmdUI->Enable( FALSE );
  954. if( pLicServer != NULL && pLicServer->GetServerType( ) == SERVER_TS5_ENFORCED )
  955. {
  956. pCmdUI->Enable( TRUE );
  957. }
  958. }
  959. //--------------------------------------------------------------------
  960. void CMainFrame::OnRefreshServer( )
  961. {
  962. CLicServer * pLicServer = NULL;
  963. if( FAILED( GetActiveServer( &pLicServer ) ) )
  964. {
  965. // nothing to refresh
  966. return;
  967. }
  968. RefreshServer( pLicServer );
  969. }
  970. //--------------------------------------------------------------------
  971. BOOL CMainFrame::IsServerRegistered( HRESULT *phrStatus )
  972. {
  973. BOOL bEnable = FALSE;
  974. ASSERT( phrStatus != NULL );
  975. DWORD dwServerStatus = ERROR_SUCCESS;
  976. CLicServer * pLicServer = NULL;
  977. *phrStatus = GetActiveServer( &pLicServer );
  978. if( pLicServer != NULL )
  979. {
  980. if( pLicServer->GetServerType() == SERVER_TS5_ENFORCED )
  981. {
  982. dwServerStatus = pLicServer->GetServerRegistrationStatus( );
  983. }
  984. else
  985. {
  986. *phrStatus = E_FAIL; // fail all non enforced server
  987. }
  988. }
  989. if( dwServerStatus == LSERVERSTATUS_REGISTER_INTERNET ||
  990. dwServerStatus == LSERVERSTATUS_REGISTER_OTHER )
  991. {
  992. bEnable = TRUE;
  993. }
  994. else
  995. {
  996. bEnable = FALSE;
  997. }
  998. DBGMSG( L"LICMGR@CMainFrame::IsServerRegistered -- status returned 0x%x\n" , dwServerStatus );
  999. return bEnable;
  1000. }
  1001. //--------------------------------------------------------------------
  1002. // used by views
  1003. //--------------------------------------------------------------------
  1004. void CMainFrame::UI_initmenu( CMenu *pMenu , NODETYPE nt )
  1005. {
  1006. HRESULT hr;
  1007. CLicServer *pServer;
  1008. GetActiveServer( &pServer );
  1009. if( pMenu == NULL )
  1010. {
  1011. return;
  1012. }
  1013. UINT uMF = MF_GRAYED | MF_DISABLED;
  1014. if( pServer != NULL )
  1015. {
  1016. if( pServer->GetConType() != CONNECTION_WWW )
  1017. {
  1018. DBGMSG( L"LICMGR:UI_initmenu server contype is not www\n" , 0 );
  1019. uMF = MF_ENABLED;
  1020. }
  1021. }
  1022. BOOL bEnable = IsServerRegistered( &hr );
  1023. if( nt == NODE_SERVER )
  1024. {
  1025. if( bEnable )
  1026. {
  1027. if( FAILED( hr ) )
  1028. {
  1029. pMenu->EnableMenuItem( ID_SVR_ACTIVATESERVER , MF_ENABLED );
  1030. }
  1031. else
  1032. {
  1033. pMenu->EnableMenuItem( ID_SVR_ACTIVATESERVER , MF_GRAYED | MF_DISABLED );
  1034. }
  1035. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REACTIVATESERVER , MF_ENABLED );
  1036. pMenu->EnableMenuItem( ID_LPK_ADVANCED_DEACTIVATESERVER , uMF );
  1037. pMenu->EnableMenuItem( ID_LPK_PROPERTIES , MF_ENABLED );
  1038. if( IsLicensesDownLoaded() )
  1039. {
  1040. pMenu->EnableMenuItem( ID_LPK_DOWNLOADLICENSES , MF_ENABLED );
  1041. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REPEATLASTDOWNLOAD , uMF );
  1042. }
  1043. else
  1044. {
  1045. pMenu->EnableMenuItem( ID_LPK_DOWNLOADLICENSES , MF_ENABLED );
  1046. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REPEATLASTDOWNLOAD , MF_GRAYED | MF_DISABLED );
  1047. }
  1048. }
  1049. else
  1050. {
  1051. if( SUCCEEDED( hr ) )
  1052. {
  1053. pMenu->EnableMenuItem( ID_SVR_ACTIVATESERVER , MF_ENABLED );
  1054. }
  1055. else
  1056. {
  1057. pMenu->EnableMenuItem( ID_SVR_ACTIVATESERVER , MF_DISABLED | MF_GRAYED );
  1058. }
  1059. if( pServer != NULL )
  1060. {
  1061. if( pServer->GetServerType( ) == SERVER_TS5_ENFORCED )
  1062. {
  1063. pMenu->EnableMenuItem( ID_LPK_DOWNLOADLICENSES , MF_GRAYED | MF_DISABLED );
  1064. pMenu->EnableMenuItem( ID_LPK_PROPERTIES , MF_ENABLED );
  1065. }
  1066. else
  1067. {
  1068. pMenu->EnableMenuItem( ID_LPK_DOWNLOADLICENSES , MF_ENABLED );
  1069. pMenu->EnableMenuItem( ID_LPK_PROPERTIES , MF_GRAYED | MF_DISABLED );
  1070. }
  1071. }
  1072. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REPEATLASTDOWNLOAD , MF_GRAYED | MF_DISABLED );
  1073. pMenu->EnableMenuItem( ID_LPK_ADVANCED_REACTIVATESERVER , MF_GRAYED | MF_DISABLED );
  1074. pMenu->EnableMenuItem( ID_LPK_ADVANCED_DEACTIVATESERVER , MF_GRAYED | MF_DISABLED );
  1075. }
  1076. }
  1077. else if( nt == NODE_KEYPACK )
  1078. {
  1079. if( bEnable )
  1080. {
  1081. if( IsLicensesDownLoaded() )
  1082. {
  1083. pMenu->EnableMenuItem( ID_LICPAK_DOWNLOADLICENSES , MF_ENABLED );
  1084. pMenu->EnableMenuItem( ID_LICPAK_REPEATDOWNLOAD , uMF );
  1085. }
  1086. else
  1087. {
  1088. pMenu->EnableMenuItem( ID_LICPAK_DOWNLOADLICENSES , MF_ENABLED );
  1089. pMenu->EnableMenuItem( ID_LICPAK_REPEATDOWNLOAD , MF_GRAYED | MF_DISABLED );
  1090. }
  1091. }
  1092. else
  1093. {
  1094. if( pServer != NULL && pServer->GetServerType() == SERVER_TS5_ENFORCED )
  1095. {
  1096. pMenu->EnableMenuItem( ID_LICPAK_DOWNLOADLICENSES , MF_GRAYED | MF_DISABLED );
  1097. }
  1098. else
  1099. {
  1100. pMenu->EnableMenuItem( ID_LICPAK_DOWNLOADLICENSES , MF_ENABLED );
  1101. }
  1102. pMenu->EnableMenuItem( ID_LICPAK_REPEATDOWNLOAD , MF_GRAYED | MF_DISABLED );
  1103. }
  1104. }
  1105. else if( nt == NODE_ALL_SERVERS )
  1106. {
  1107. pMenu->EnableMenuItem( ID_ALLSVR_REFRESHALL , MF_ENABLED );
  1108. }
  1109. /*
  1110. else if( nt == NODE_NONE )
  1111. {
  1112. // this can only mean licenses
  1113. if( !IsLicensesDownLoaded( ) )
  1114. {
  1115. pMenu->EnableMenuItem( ID_LIC_DOWNLOADLICENSES , MF_GRAYED | MF_DISABLED );
  1116. }
  1117. }
  1118. */
  1119. }
  1120. //------------------------------------------------------------------------------------
  1121. void CMainFrame::OnDownLoadLicenses( )
  1122. {
  1123. BOOL bF;
  1124. CLicServer *pLicServer = NULL;
  1125. GetActiveServer( &pLicServer );
  1126. if( pLicServer != NULL )
  1127. {
  1128. if( pLicServer->GetServerType() == SERVER_TS5_ENFORCED )
  1129. {
  1130. DWORD dw = WizardActionOnServer( WIZACTION_DOWNLOADLKP , &bF , NOVIEW );
  1131. DBGMSG( L"LICMGR : OnDownLoadLicenses returned 0x%x\n " , dw );
  1132. }
  1133. }
  1134. }
  1135. //------------------------------------------------------------------------------------
  1136. void CMainFrame::OnRepeatLastDownLoad( )
  1137. {
  1138. BOOL bF;
  1139. DWORD dw = WizardActionOnServer( WIZACTION_DOWNLOADLASTLKP , &bF , NOVIEW );
  1140. DBGMSG( L"LICMGR : OnRepeatLastDownLoad returned 0x%x\n " , dw );
  1141. }
  1142. //------------------------------------------------------------------------------------
  1143. void CMainFrame::OnReRegisterServer( )
  1144. {
  1145. BOOL bF;
  1146. DWORD dw = WizardActionOnServer( WIZACTION_REREGISTERLS , &bF , NOVIEW );
  1147. DBGMSG( L"LICMGR : OnReRegisterServer returned 0x%x\n " , dw );
  1148. }
  1149. //------------------------------------------------------------------------------------
  1150. void CMainFrame::OnUnRegisterServer( )
  1151. {
  1152. BOOL bF;
  1153. DWORD dw = WizardActionOnServer( WIZACTION_UNREGISTERLS , &bF , NOVIEW );
  1154. DBGMSG( L"LICMGR : OnUnRegisterServer returned 0x%x\n " , dw );
  1155. }
  1156. //------------------------------------------------------------------------------------
  1157. void CMainFrame::OnProperties( )
  1158. {
  1159. BOOL bF;
  1160. DWORD dw = WizardActionOnServer( WIZACTION_SHOWPROPERTIES , &bF , NOVIEW );
  1161. DBGMSG( L"LICMGR : CMainFrame -- OnProperties returned 0x%x\n", dw );
  1162. }
  1163. //------------------------------------------------------------------------------------
  1164. BOOL CMainFrame::IsLicensesDownLoaded( )
  1165. {
  1166. CLicServer * pLicServer = NULL;
  1167. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  1168. {
  1169. if( pLicServer != NULL )
  1170. {
  1171. if( pLicServer->GetConType( ) != CONNECTION_PHONE )
  1172. {
  1173. DBGMSG( L"Licmgr CMainFrame::IsLicensesDownLoaded GetConnectionType internet - www base\n" , 0 );
  1174. return pLicServer->IsLicsDownloaded( );
  1175. }
  1176. else
  1177. {
  1178. return FALSE;
  1179. }
  1180. }
  1181. }
  1182. return FALSE;
  1183. }
  1184. //------------------------------------------------------------------------------------
  1185. DWORD CMainFrame::WizardActionOnServer( WIZACTION wa , PBOOL pbRefresh , VIEW vt )
  1186. {
  1187. CLicMgrLeftView * pLeftView = (CLicMgrLeftView *)m_pLeftView;
  1188. CTreeCtrl& TreeCtrl = pLeftView->GetTreeCtrl();
  1189. CRightList * pRightView = (CRightList *)m_pRightView;
  1190. CLicServer *pServer = NULL;
  1191. if( vt == TREEVIEW )
  1192. {
  1193. CTreeNode *pNode = (CTreeNode *)TreeCtrl.GetItemData( pLeftView->GetRightClickedItem() );
  1194. if( pNode->GetNodeType() == NODE_SERVER )
  1195. {
  1196. pServer = static_cast< CLicServer * >( pNode->GetTreeObject() );
  1197. }
  1198. else if( pNode->GetNodeType( ) == NODE_KEYPACK )
  1199. {
  1200. CKeyPack *pKeyPack = static_cast< CKeyPack *>( pNode->GetTreeObject() );
  1201. if( pKeyPack != NULL )
  1202. {
  1203. pServer = pKeyPack->GetServer( );
  1204. }
  1205. }
  1206. }
  1207. else if( vt == LISTVIEW )
  1208. {
  1209. CListCtrl& listctrl = pRightView->GetListCtrl();
  1210. CLicMgrDoc * pDoc = ( CLicMgrDoc * )( GetActiveView()->GetDocument( ) );
  1211. ASSERT(pDoc);
  1212. if(NULL == pDoc)
  1213. {
  1214. return ERROR_INVALID_PARAMETER;
  1215. }
  1216. int nSelected = listctrl.GetNextItem(-1, LVNI_SELECTED);
  1217. if( -1 != nSelected)
  1218. {
  1219. DWORD_PTR dCurrSel = listctrl.GetItemData( nSelected );
  1220. if( NODE_ALL_SERVERS == pDoc->GetNodeType() )
  1221. {
  1222. pServer = reinterpret_cast< CLicServer * >( dCurrSel );
  1223. }
  1224. else if( pDoc->GetNodeType() == NODE_SERVER )
  1225. {
  1226. CKeyPack *pKeyPack = reinterpret_cast< CKeyPack *>( dCurrSel );
  1227. if( pKeyPack != NULL )
  1228. {
  1229. pServer = pKeyPack->GetServer( );
  1230. }
  1231. }
  1232. else if( pDoc->GetNodeType( ) == NODE_KEYPACK )
  1233. {
  1234. CLicense * pLicense = reinterpret_cast< CLicense * >( dCurrSel );
  1235. pServer = ( pLicense->GetKeyPack() )->GetServer( );
  1236. }
  1237. }
  1238. }
  1239. else if( vt == NOVIEW )
  1240. {
  1241. CLicServer * pLicServer = NULL;
  1242. if( SUCCEEDED( GetActiveServer( &pLicServer ) ) )
  1243. {
  1244. pServer = pLicServer;
  1245. }
  1246. }
  1247. if( pServer != NULL )
  1248. {
  1249. DWORD dw = ERROR_SUCCESS;
  1250. // check for admin
  1251. if( !pServer->IsUserAdmin( ) )
  1252. {
  1253. AfxMessageBox( IDS_E_ACCESSDENIED );
  1254. //::MessageBox( GetSafeHwnd( ) , L"Unable to perform operation: Access denied" , L"Terminal Services Licensing" , MB_OK|MB_ICONINFORMATION );
  1255. return ERROR_ACCESS_DENIED;
  1256. }
  1257. if( wa != WIZACTION_REGISTERLS )
  1258. {
  1259. if( pServer->GetServerType() == SERVER_TS5_ENFORCED )
  1260. {
  1261. DBGMSG( L"LICMGR:CMainFrame::WizardActionOnServer calling StartWizard\n", 0 );
  1262. dw = StartWizardEx( GetSafeHwnd( ) , wa , (LPCTSTR)pServer->GetName( ) , pbRefresh );
  1263. DBGMSG( L"StartWizard ( central call ) returned 0x%x\n", dw );
  1264. DBGMSG( L"StartWizard ( central call ) refresh = %s\n", *pbRefresh ? L"true" : L"false" );
  1265. if( *pbRefresh )
  1266. {
  1267. RefreshServer( pServer );
  1268. }
  1269. }
  1270. }
  1271. switch( wa )
  1272. {
  1273. case WIZACTION_REGISTERLS:
  1274. // this handles non-enforced as well.
  1275. OnRegistration( );
  1276. break;
  1277. case WIZACTION_UNREGISTERLS :
  1278. if( dw == ERROR_SUCCESS )
  1279. {
  1280. pServer->SetDownLoadLics( FALSE );
  1281. }
  1282. // FALL THROUGH
  1283. case WIZACTION_REREGISTERLS :
  1284. {
  1285. DWORD dwStatus;
  1286. if( IsLicenseServerRegistered( GetSafeHwnd( ) , (LPCTSTR)pServer->GetName( ) , &dwStatus ) == ERROR_SUCCESS )
  1287. {
  1288. pServer->SetServerRegistrationStatus( dwStatus );
  1289. }
  1290. }
  1291. break;
  1292. }
  1293. return dw;
  1294. }
  1295. return ERROR_INVALID_PARAMETER;
  1296. }
  1297. // IE hardening bug, we need to add the activation site to the IE
  1298. // trusted sites list, after wizard is done, we'll remove
  1299. // So we'll wrap startwizard call
  1300. DWORD CMainFrame::StartWizardEx(HWND hWndParent,
  1301. WIZACTION WizAction,
  1302. LPCTSTR pszLSName,
  1303. PBOOL pbRefresh)
  1304. {
  1305. HKEY hKey = NULL;
  1306. if (RegCreateKeyEx(HKEY_CURRENT_USER,
  1307. TRUSTED_ACTIVATION_SITE_REGPATH,
  1308. 0,
  1309. NULL,
  1310. REG_OPTION_NON_VOLATILE,
  1311. KEY_ALL_ACCESS,
  1312. NULL,
  1313. &hKey,
  1314. NULL) == ERROR_SUCCESS)
  1315. {
  1316. DWORD dwValue = TRUSTED_ACTIVATION_REG_VALUE;
  1317. // Create the key value
  1318. LONG lResult = RegSetValueEx(hKey,
  1319. TRUSTED_ACTIVATION_REG_VALUE_NAME,
  1320. 0,
  1321. REG_DWORD,
  1322. (LPBYTE)&dwValue,
  1323. sizeof(DWORD));
  1324. }
  1325. DWORD dw = StartWizard(hWndParent ,WizAction ,pszLSName ,pbRefresh);
  1326. // Delete key we created above
  1327. RegDeleteKey(HKEY_CURRENT_USER, TRUSTED_ACTIVATION_SITE_REGPATH);
  1328. if (hKey != NULL)
  1329. {
  1330. RegCloseKey(hKey);
  1331. }
  1332. return dw;
  1333. }
  1334. //------------------------------------------------------------------------------------
  1335. BOOL CMainFrame::IsDownLoadedPacks( CLicServer *pServer )
  1336. {
  1337. UINT counter = 0;
  1338. if( pServer != NULL )
  1339. {
  1340. KeyPackList *pKeyPackList = pServer->GetKeyPackList( );
  1341. if( pKeyPackList != NULL )
  1342. {
  1343. POSITION pos = pKeyPackList->GetHeadPosition();
  1344. while(pos)
  1345. {
  1346. CKeyPack *pKeyPack = (CKeyPack *)pKeyPackList->GetNext(pos);
  1347. if( pKeyPack != NULL )
  1348. {
  1349. if( pKeyPack->GetKeyPackStruct().ucKeyPackType != LSKEYPACKTYPE_TEMPORARY &&
  1350. pKeyPack->GetKeyPackStruct().ucKeyPackType != LSKEYPACKTYPE_FREE )
  1351. {
  1352. counter++;
  1353. DBGMSG( L"LICMGR:CMainFrame found %d keypack(s)\n" , counter );
  1354. }
  1355. }
  1356. }
  1357. if( counter >= 1 )
  1358. {
  1359. DBGMSG( L"LICMGR : CMainFrame IsDownLoadedPacks returns true\n" ,0 );
  1360. return TRUE;
  1361. }
  1362. }
  1363. }
  1364. DBGMSG( L"LICMGR : CMainFrame IsDownLoadedPacks returns false \n" ,0 );
  1365. return FALSE;
  1366. }