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.

578 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. llsmgr.cpp
  5. Abstract:
  6. Application object implementation.
  7. Author:
  8. Don Ryan (donryan) 12-Feb-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. Jeff Parham (jeffparh) 16-Jan-1996
  13. Added SetLastTargetServer() to OpenDocumentFile() to help isolate
  14. server connection problems. (Bug #2993.)
  15. --*/
  16. #include "stdafx.h"
  17. #include "llsmgr.h"
  18. #include "mainfrm.h"
  19. #include "llsdoc.h"
  20. #include "llsview.h"
  21. #include "sdomdlg.h"
  22. #include "shellapi.h"
  23. #include <afxpriv.h>
  24. #include <htmlhelp.h>
  25. #include <sbs_res.h>
  26. BOOL IsRestrictedSmallBusSrv( void );
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31. CLlsmgrApp theApp; // The one and only CLlsmgrApp object
  32. BEGIN_MESSAGE_MAP(CLlsmgrApp, CWinApp)
  33. //{{AFX_MSG_MAP(CLlsmgrApp)
  34. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. CLlsmgrApp::CLlsmgrApp()
  38. /*++
  39. Routine Description:
  40. Constructor for application object.
  41. Arguments:
  42. None.
  43. Return Values:
  44. None.
  45. --*/
  46. {
  47. m_pApplication = NULL;
  48. m_bIsAutomated = FALSE;
  49. #ifdef _DEBUG_VERBOSE
  50. afxMemDF |= checkAlwaysMemDF;
  51. #endif
  52. }
  53. int CLlsmgrApp::ExitInstance()
  54. /*++
  55. Routine Description:
  56. Called by framework to exit this instance of an application.
  57. Arguments:
  58. None.
  59. Return Values:
  60. Application's exit code.
  61. --*/
  62. {
  63. if (m_pApplication && !m_bIsAutomated)
  64. m_pApplication->InternalRelease();
  65. #ifdef _DEBUG
  66. CMemoryState exitMem;
  67. CMemoryState diffMem;
  68. exitMem.Checkpoint();
  69. if (!diffMem.Difference(m_initMem, exitMem))
  70. {
  71. diffMem.DumpStatistics();
  72. m_initMem.DumpAllObjectsSince();
  73. }
  74. #endif
  75. return CWinApp::ExitInstance();
  76. }
  77. BOOL CLlsmgrApp::InitInstance()
  78. /*++
  79. Routine Description:
  80. Called by framework to initialize a new instance of an application.
  81. Arguments:
  82. None.
  83. Return Values:
  84. TRUE if initialization succeeds.
  85. --*/
  86. {
  87. #ifdef _DEBUG
  88. m_initMem.Checkpoint();
  89. #endif
  90. //
  91. // Check if this server is a restricted small business server.
  92. // If so, disallow further use of the license manager.
  93. //
  94. if (IsRestrictedSmallBusSrv())
  95. {
  96. //
  97. // Let the user know of the restriction.
  98. //
  99. HINSTANCE hSbsLib = NULL;
  100. hSbsLib = LoadLibrary( SBS_RESOURCE_DLL ) ;
  101. if (NULL != hSbsLib)
  102. {
  103. TCHAR pszText[512+1];
  104. LoadString ( hSbsLib, SBS_License_Error, pszText, 512 );
  105. AfxMessageBox( pszText );
  106. }
  107. else
  108. {
  109. AfxMessageBox(IDP_SBS_RESTRICTED);
  110. }
  111. return FALSE;
  112. }
  113. //
  114. // Initialize OLE libraries
  115. //
  116. if (!AfxOleInit())
  117. {
  118. AfxMessageBox(IDP_OLE_INIT_FAILED);
  119. return FALSE;
  120. }
  121. //
  122. // If the application was launched as an OLE server (run with
  123. // /Embedding or /Automation) then register all OLE server factories
  124. // as running and don't show main window.
  125. //
  126. if (RunEmbedded() || RunAutomated())
  127. {
  128. COleTemplateServer::RegisterAll();
  129. return m_bIsAutomated = TRUE;
  130. }
  131. //
  132. // Create image list for common controls
  133. //
  134. m_smallImages.Create(IDB_SMALL_CTRLS, BMPI_SMALL_SIZE, 0, BMPI_RGB_BKGND);
  135. m_largeImages.Create(IDB_LARGE_CTRLS, BMPI_LARGE_SIZE, 0, BMPI_RGB_BKGND);
  136. //
  137. // Create document template
  138. //
  139. m_pDocTemplate = new CSingleDocTemplate(
  140. IDR_MAINFRAME,
  141. RUNTIME_CLASS(CLlsmgrDoc),
  142. RUNTIME_CLASS(CMainFrame),
  143. RUNTIME_CLASS(CLlsmgrView)
  144. );
  145. AddDocTemplate(m_pDocTemplate);
  146. //
  147. // Create OLE-createable application object. This object
  148. // will save itself in m_pApplication so there should only
  149. // be one and only one. If the application was launched as
  150. // an OLE server then this object is created automatically
  151. // via CreateObject() or GetObject().
  152. //
  153. CApplication* pApplication = new CApplication;
  154. if (pApplication && !pApplication->GetLastStatus())
  155. {
  156. OnFileNew(); // display empty frame ...
  157. m_pMainWnd->PostMessage(WM_COMMAND, ID_APP_STARTUP);
  158. }
  159. else
  160. {
  161. AfxMessageBox(IDP_APP_INIT_FAILED);
  162. return FALSE;
  163. }
  164. return TRUE;
  165. }
  166. void CLlsmgrApp::DisplayStatus(long Status)
  167. /*++
  168. Routine Description:
  169. Retrieves status string and displays.
  170. Arguments:
  171. Status - status code.
  172. Return Values:
  173. None.
  174. --*/
  175. {
  176. m_pApplication->SetLastStatus(Status);
  177. DisplayLastStatus();
  178. }
  179. void CLlsmgrApp::DisplayLastStatus()
  180. /*++
  181. Routine Description:
  182. Retrieves status string and displays.
  183. Arguments:
  184. None.
  185. Return Values:
  186. None.
  187. --*/
  188. {
  189. BSTR LastErrorString = m_pApplication->GetLastErrorString();
  190. AfxMessageBox(LastErrorString);
  191. SysFreeString(LastErrorString);
  192. }
  193. void CLlsmgrApp::OnAppAbout()
  194. /*++
  195. Routine Description:
  196. Message handler for ID_APP_ABOUT.
  197. Arguments:
  198. None.
  199. Return Values:
  200. None.
  201. --*/
  202. {
  203. BSTR AppName = LlsGetApp()->GetName();
  204. ::ShellAbout(m_pMainWnd->GetSafeHwnd(), AppName, AppName, LoadIcon(IDR_MAINFRAME));
  205. SysFreeString(AppName);
  206. }
  207. CDocument* CLlsmgrApp::OpenDocumentFile(LPCTSTR lpszFileName)
  208. /*++
  209. Routine Description:
  210. Message handler for ID_FILE_OPEN.
  211. Arguments:
  212. lpszFileName - file name (actually domain name).
  213. Return Values:
  214. Pointer to object is successful.
  215. --*/
  216. {
  217. BOOL bFocusChanged = FALSE;
  218. VARIANT va;
  219. VariantInit(&va);
  220. BeginWaitCursor();
  221. if (lpszFileName)
  222. {
  223. va.vt = VT_BSTR;
  224. va.bstrVal = SysAllocStringLen(lpszFileName, lstrlen(lpszFileName));
  225. bFocusChanged = LlsGetApp()->SelectDomain(va);
  226. }
  227. else
  228. {
  229. bFocusChanged = LlsGetApp()->SelectEnterprise();
  230. CString eTitle;
  231. eTitle.LoadString(IDS_ENTERPRISE);
  232. lpszFileName = MKSTR(eTitle);
  233. }
  234. EndWaitCursor();
  235. VariantClear(&va); // free system string if necessary...
  236. if (!bFocusChanged)
  237. {
  238. LPTSTR pszLastTargetServer;
  239. if (LlsGetLastStatus() == STATUS_ACCESS_DENIED)
  240. {
  241. AfxMessageBox(IDP_ERROR_NO_PRIVILEGES);
  242. }
  243. else if ( ( ( LlsGetLastStatus() == RPC_S_SERVER_UNAVAILABLE )
  244. || ( LlsGetLastStatus() == RPC_NT_SERVER_UNAVAILABLE ) )
  245. && ( NULL != ( pszLastTargetServer = LlsGetLastTargetServer() ) ) )
  246. {
  247. CString strMessage;
  248. AfxFormatString1( strMessage, IDP_ERROR_NO_RPC_SERVER_FORMAT, pszLastTargetServer );
  249. SysFreeString( pszLastTargetServer );
  250. AfxMessageBox( strMessage );
  251. }
  252. else
  253. {
  254. DisplayLastStatus();
  255. }
  256. return FALSE;
  257. }
  258. //
  259. // Notify framework that focus changed....
  260. //
  261. return m_pDocTemplate->OpenDocumentFile(lpszFileName);
  262. }
  263. BOOL CLlsmgrApp::OnAppStartup()
  264. /*++
  265. Routine Description:
  266. Message handler for ID_APP_STARTUP.
  267. Arguments:
  268. None.
  269. Return Values:
  270. Returns true if successful.
  271. --*/
  272. {
  273. CString strStartingPoint;
  274. //
  275. // Update registry in case it has been damaged
  276. //
  277. COleObjectFactory::UpdateRegistryAll();
  278. //
  279. // Select domain using command line or machine name
  280. //
  281. if (m_lpCmdLine && *m_lpCmdLine)
  282. {
  283. LPCTSTR pszStartingPoint;
  284. pszStartingPoint = m_lpCmdLine;
  285. while (_istspace(*pszStartingPoint))
  286. pszStartingPoint = _tcsinc(pszStartingPoint);
  287. strStartingPoint = pszStartingPoint;
  288. strStartingPoint.TrimRight();
  289. }
  290. else
  291. {
  292. TCHAR szComputerName[MAX_PATH+1];
  293. DWORD cchComputerName = sizeof(szComputerName) / sizeof(TCHAR);
  294. if (::GetComputerName(szComputerName, &cchComputerName))
  295. {
  296. strStartingPoint = _T("\\\\");
  297. strStartingPoint += szComputerName;
  298. }
  299. else
  300. {
  301. DisplayStatus(::GetLastError());
  302. m_pMainWnd->PostMessage(WM_CLOSE);
  303. return FALSE;
  304. }
  305. }
  306. if (!OpenDocumentFile(strStartingPoint))
  307. {
  308. CSelectDomainDialog sdomDlg;
  309. if (sdomDlg.DoModal() != IDOK)
  310. {
  311. m_pMainWnd->PostMessage(WM_CLOSE);
  312. return FALSE;
  313. }
  314. }
  315. return TRUE;
  316. }
  317. void CLlsmgrApp::WinHelp( DWORD_PTR dwData, UINT nCmd )
  318. /*++
  319. Routine Description:
  320. Same as CWinApp::WinHelp with the exception that we trap HELP_CONTEXT on
  321. IDR_MAINFRAME and translate it to a HELP_FINDER call.
  322. Arguments:
  323. None.
  324. Return Values:
  325. None.
  326. --*/
  327. {
  328. UNREFERENCED_PARAMETER( dwData );
  329. UNREFERENCED_PARAMETER( nCmd );
  330. CWnd* pMainWnd = AfxGetMainWnd();
  331. ASSERT_VALID( pMainWnd );
  332. ::HtmlHelp(pMainWnd->m_hWnd, L"liceconcepts.chm", HH_DISPLAY_TOPIC,0);
  333. }
  334. const WCHAR wszProductOptions[] =
  335. L"System\\CurrentControlSet\\Control\\ProductOptions";
  336. const WCHAR wszProductSuite[] =
  337. L"ProductSuite";
  338. const WCHAR wszSBSRestricted[] =
  339. L"Small Business(Restricted)";
  340. BOOL IsRestrictedSmallBusSrv( void )
  341. /*++
  342. Routine Description:
  343. Check if this server is a Microsoft small business restricted server.
  344. Arguments:
  345. None.
  346. Return Values:
  347. TRUE -- This server is a restricted small business server.
  348. FALSE -- No such restriction.
  349. --*/
  350. {
  351. WCHAR wszBuffer[1024] = L"";
  352. DWORD cbBuffer = sizeof(wszBuffer);
  353. DWORD dwType;
  354. LPWSTR pwszSuite;
  355. HKEY hKey;
  356. BOOL bRet = FALSE;
  357. //
  358. // Check if this server is a Microsoft small business restricted server.
  359. // Do so by checking for the existence of the string
  360. // "Small Business(Restricted)"
  361. // in the MULTI_SZ "ProductSuite" value under
  362. // HKLM\CurrentCcntrolSet\Control\ProductOptions.
  363. //
  364. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  365. wszProductOptions,
  366. 0,
  367. KEY_READ,
  368. &hKey) == ERROR_SUCCESS)
  369. {
  370. if (RegQueryValueEx(hKey,
  371. wszProductSuite,
  372. NULL,
  373. &dwType,
  374. (LPBYTE)wszBuffer,
  375. &cbBuffer) == ERROR_SUCCESS)
  376. {
  377. if (dwType == REG_MULTI_SZ && *wszBuffer)
  378. {
  379. pwszSuite = wszBuffer;
  380. while (*pwszSuite)
  381. {
  382. if (lstrcmpi(pwszSuite, wszSBSRestricted) == 0)
  383. {
  384. bRet = TRUE;
  385. break;
  386. }
  387. pwszSuite += wcslen(pwszSuite) + 1;
  388. }
  389. }
  390. }
  391. RegCloseKey(hKey);
  392. }
  393. return bRet;
  394. }