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.

1225 lines
30 KiB

  1. /*
  2. * Copyright (c) 1998 Microsoft Corporation
  3. *
  4. * Module Name:
  5. *
  6. * licenoc.cpp
  7. *
  8. * Abstract:
  9. *
  10. * This file contains the main OC code.
  11. *
  12. * Author:
  13. *
  14. * Breen Hagan (BreenH) Oct-02-98
  15. *
  16. * Environment:
  17. *
  18. * User Mode
  19. */
  20. #include "stdafx.h"
  21. #include "pages.h"
  22. #include "..\common\svcrole.h"
  23. #include "upgdef.h"
  24. #include "logfile.h"
  25. /*
  26. * Constants.
  27. */
  28. const TCHAR gszLogFile[] = _T("%SystemRoot%\\LicenOc.log");
  29. const TCHAR *gInstallSectionNames[] = {
  30. _T("LicenseServer.Install"),
  31. _T("LicenseServer.Uninstall"),
  32. _T("LicenseServer.StandaloneInstall"),
  33. _T("LicenseServer.StandaloneUninstall"),
  34. _T("LicenseServer.DoNothing")
  35. };
  36. /*
  37. * Global variables.
  38. */
  39. BOOL gNt4Upgrade = FALSE;
  40. BOOL gNtUpgrade;
  41. BOOL gStandAlone;
  42. BOOL gUnAttended;
  43. EnablePage *gEnableDlg = NULL;
  44. EServerType gServerRole = eEnterpriseServer;
  45. HINSTANCE ghInstance = NULL;
  46. PSETUP_INIT_COMPONENT gpInitComponentData = NULL;
  47. /*
  48. * Function prototypes.
  49. */
  50. HINF GetComponentInfHandle(VOID);
  51. DWORD GetComponentVersion(VOID);
  52. HINSTANCE GetInstance(VOID);
  53. EInstall GetInstallSection(VOID);
  54. LPCTSTR GetInstallSectionName(VOID);
  55. BOOL GetSelectionState(UINT);
  56. EServerType GetServerRole(VOID);
  57. DWORD OnPreinitialize(UINT_PTR);
  58. DWORD OnInitComponent(PSETUP_INIT_COMPONENT);
  59. DWORD OnSetLanguage(UINT_PTR);
  60. DWORD OnQueryImage(UINT_PTR, PDWORD);
  61. DWORD OnRequestPages(WizardPagesType, PSETUP_REQUEST_PAGES);
  62. DWORD OnWizardCreated(VOID);
  63. DWORD OnQueryState(UINT_PTR);
  64. DWORD OnQueryChangeSelState(UINT_PTR, UINT);
  65. DWORD OnCalcDiskSpace(LPCTSTR, UINT_PTR, HDSKSPC);
  66. DWORD OnQueueFileOps(LPCTSTR, HSPFILEQ);
  67. DWORD OnQueryStepCount(VOID);
  68. DWORD OnAboutToCommitQueue(VOID);
  69. DWORD OnCompleteInstallation(LPCTSTR);
  70. DWORD OnCleanup(VOID);
  71. VOID SetDatabaseDirectory(LPCTSTR);
  72. DWORD SetServerRole(UINT);
  73. #define GetCurrentSelectionState() GetSelectionState(OCSELSTATETYPE_CURRENT)
  74. #define GetOriginalSelectionState() GetSelectionState(OCSELSTATETYPE_ORIGINAL)
  75. /*
  76. * Helper Functions.
  77. */
  78. HINF
  79. GetComponentInfHandle(
  80. VOID
  81. )
  82. {
  83. return(gpInitComponentData->ComponentInfHandle);
  84. }
  85. DWORD
  86. GetComponentVersion(
  87. VOID
  88. )
  89. {
  90. return(OCMANAGER_VERSION);
  91. }
  92. HINSTANCE
  93. GetInstance(
  94. VOID
  95. )
  96. {
  97. return(ghInstance);
  98. }
  99. EInstall
  100. GetInstallSection(
  101. VOID
  102. )
  103. {
  104. BOOL fCurrentState = GetCurrentSelectionState();
  105. BOOL fOriginalState = GetOriginalSelectionState();
  106. //
  107. // StandAlone Setup Matrix
  108. //
  109. // Originally Selected, Currently Selected -> DoNothing
  110. // Originally Selected, Currently Unselected -> Uninstall
  111. // Originally Unselected, Currently Selected -> Install
  112. // Originally Unselected, Currently Unselected -> DoNothing
  113. //
  114. // Gui Mode / Upgrade Matrix
  115. //
  116. // Nt 4.0 any setup, Nt 5.0 w LS -> Install
  117. // Nt 4.0 any setup, Nt 5.0 w/o LS -> Uninstall
  118. // Nt 5.0 w/ LS, Nt 5.0 w/ LS -> Install
  119. // Nt 5.0 w/ LS, Nt 5.0 w/o LS -> Uninstall
  120. // Nt 5.0 w/o LS, Nt 5.0 w/ LS -> Install
  121. // Nt 5.0 w/o LS, Nt 5.0 w/o LS -> Uninstall
  122. // Win9x, Nt5.0 w/ LS -> Install
  123. // Win9x, Nt5.0 w/o LS -> Uninstall
  124. //
  125. //
  126. // If this is a TS 4 installation, fOriginalState will be false,
  127. // even though LS is installed. Handle this case first.
  128. //
  129. if (gNt4Upgrade)
  130. {
  131. return(kInstall);
  132. }
  133. if (gStandAlone)
  134. {
  135. if (fCurrentState == fOriginalState)
  136. {
  137. return(kDoNothing);
  138. }
  139. else
  140. {
  141. if (fCurrentState)
  142. {
  143. return (kStandaloneInstall);
  144. }
  145. else
  146. {
  147. return (kStandaloneUninstall);
  148. }
  149. }
  150. }
  151. else
  152. {
  153. if (fCurrentState)
  154. {
  155. return (kInstall);
  156. }
  157. else
  158. {
  159. return (kUninstall);
  160. }
  161. }
  162. }
  163. LPCTSTR
  164. GetInstallSectionName(
  165. VOID
  166. )
  167. {
  168. LOGMESSAGE(
  169. _T("GetInstallSectionName: Returned %s"),
  170. gInstallSectionNames[(INT)GetInstallSection()]
  171. );
  172. return(gInstallSectionNames[(INT)GetInstallSection()]);
  173. }
  174. BOOL
  175. GetSelectionState(
  176. UINT StateType
  177. )
  178. {
  179. return(gpInitComponentData->HelperRoutines.QuerySelectionState(
  180. gpInitComponentData->HelperRoutines.OcManagerContext,
  181. COMPONENT_NAME,
  182. StateType
  183. ));
  184. }
  185. EServerType
  186. GetServerRole(
  187. VOID
  188. )
  189. {
  190. return(gServerRole);
  191. }
  192. BOOL
  193. InWin2000Domain(
  194. VOID
  195. )
  196. {
  197. NET_API_STATUS dwErr;
  198. DSROLE_PRIMARY_DOMAIN_INFO_BASIC *pDomainInfo = NULL;
  199. PDOMAIN_CONTROLLER_INFO pdcInfo = NULL;
  200. BOOL fRet = FALSE;
  201. //
  202. // Check if we're in a workgroup
  203. //
  204. dwErr = DsRoleGetPrimaryDomainInformation(NULL,
  205. DsRolePrimaryDomainInfoBasic,
  206. (PBYTE *) &pDomainInfo);
  207. if ((dwErr != NO_ERROR) || (pDomainInfo == NULL))
  208. {
  209. return FALSE;
  210. }
  211. switch (pDomainInfo->MachineRole)
  212. {
  213. case DsRole_RoleStandaloneWorkstation:
  214. case DsRole_RoleStandaloneServer:
  215. DsRoleFreeMemory(pDomainInfo);
  216. return FALSE;
  217. break; // just in case
  218. }
  219. DsRoleFreeMemory(pDomainInfo);
  220. dwErr = DsGetDcName(NULL, // Computer Name
  221. NULL, // Domain Name
  222. NULL, // Domain GUID
  223. NULL, // Site Name
  224. DS_DIRECTORY_SERVICE_PREFERRED,
  225. &pdcInfo);
  226. if ((dwErr != NO_ERROR) || (pdcInfo == NULL))
  227. {
  228. return FALSE;
  229. }
  230. if (pdcInfo->Flags & DS_DS_FLAG)
  231. {
  232. fRet = TRUE;
  233. }
  234. NetApiBufferFree(pdcInfo);
  235. return fRet;
  236. }
  237. DWORD
  238. SetServerRole(
  239. IN UINT newType
  240. )
  241. {
  242. switch(newType) {
  243. case ePlainServer:
  244. case eEnterpriseServer:
  245. gServerRole = (EServerType)newType;
  246. break;
  247. default:
  248. // Set the appropriate default
  249. gServerRole = InWin2000Domain() ? eEnterpriseServer : ePlainServer;
  250. return(ERROR_INVALID_PARAMETER);
  251. }
  252. return(NO_ERROR);
  253. }
  254. /*
  255. * DllMain
  256. *
  257. * Initial entry point into the License Server OC dll.
  258. */
  259. DWORD WINAPI
  260. DllMain(
  261. IN HINSTANCE hInstance,
  262. IN DWORD dwReason,
  263. IN LPVOID lpReserved
  264. )
  265. {
  266. TCHAR pszLogFile[MAX_PATH + 1];
  267. switch(dwReason) {
  268. case DLL_PROCESS_ATTACH:
  269. if (hInstance != NULL) {
  270. ghInstance = hInstance;
  271. } else {
  272. return(FALSE);
  273. }
  274. ExpandEnvironmentStrings(gszLogFile, pszLogFile, MAX_PATH);
  275. LOGINIT(pszLogFile, COMPONENT_NAME);
  276. break;
  277. case DLL_THREAD_ATTACH:
  278. break;
  279. case DLL_PROCESS_DETACH:
  280. break;
  281. case DLL_THREAD_DETACH:
  282. break;
  283. }
  284. UNREFERENCED_PARAMETER(lpReserved);
  285. return(TRUE);
  286. }
  287. /*
  288. * EntryProc()
  289. *
  290. * Entry point into OCBase class for OCManager.
  291. */
  292. DWORD
  293. EntryProc(
  294. IN LPCVOID ComponentId,
  295. IN LPCVOID SubcomponentId,
  296. IN UINT Function,
  297. IN UINT_PTR Param1,
  298. IN OUT PVOID Param2
  299. )
  300. {
  301. DWORD dwRet;
  302. switch(Function) {
  303. case OC_PREINITIALIZE:
  304. LOGMESSAGE(_T("\r\nOnPreinitialize: Entered"));
  305. dwRet = OnPreinitialize(
  306. Param1
  307. );
  308. LOGMESSAGE(_T("OnPreinitialize: Returned"));
  309. break;
  310. case OC_INIT_COMPONENT:
  311. LOGMESSAGE(_T("\r\nOnInitComponent: Entered"));
  312. dwRet = OnInitComponent(
  313. (PSETUP_INIT_COMPONENT)Param2
  314. );
  315. LOGMESSAGE(_T("OnInitComponent: Returned"));
  316. break;
  317. case OC_SET_LANGUAGE:
  318. LOGMESSAGE(_T("\r\nOnSetLanguage: Entered"));
  319. dwRet = OnSetLanguage(
  320. Param1
  321. );
  322. LOGMESSAGE(_T("OnSetLanguage: Returned"));
  323. break;
  324. case OC_QUERY_IMAGE:
  325. LOGMESSAGE(_T("\r\nOnQueryImage: Entered"));
  326. dwRet = OnQueryImage(
  327. Param1,
  328. (PDWORD)Param2
  329. );
  330. LOGMESSAGE(_T("OnQueryImage: Returned"));
  331. break;
  332. case OC_REQUEST_PAGES:
  333. LOGMESSAGE(_T("\r\nOnRequestPages: Entered"));
  334. dwRet = OnRequestPages(
  335. (WizardPagesType)Param1,
  336. (PSETUP_REQUEST_PAGES)Param2
  337. );
  338. LOGMESSAGE(_T("OnRequestPages: Returned"));
  339. break;
  340. case OC_WIZARD_CREATED:
  341. LOGMESSAGE(_T("\r\nOnWizardCreated: Entered"));
  342. dwRet = OnWizardCreated();
  343. LOGMESSAGE(_T("OnWizardCreated: Returned"));
  344. break;
  345. case OC_QUERY_STATE:
  346. LOGMESSAGE(_T("\r\nOnQueryState: Entered"));
  347. dwRet = OnQueryState(
  348. Param1
  349. );
  350. LOGMESSAGE(_T("OnQueryState: Returned"));
  351. break;
  352. case OC_QUERY_CHANGE_SEL_STATE:
  353. LOGMESSAGE(_T("\r\nOnQueryChangeSelState: Entered"));
  354. dwRet = OnQueryChangeSelState(
  355. Param1,
  356. (UINT)((UINT_PTR)Param2)
  357. );
  358. LOGMESSAGE(_T("OnQueryChangeSelState: Returned"));
  359. break;
  360. case OC_CALC_DISK_SPACE:
  361. LOGMESSAGE(_T("\r\nOnCalcDiskSpace: Entered"));
  362. dwRet = OnCalcDiskSpace(
  363. (LPCTSTR)SubcomponentId,
  364. Param1,
  365. (HDSKSPC)Param2
  366. );
  367. LOGMESSAGE(_T("OnCalcDiskSpace: Returned"));
  368. break;
  369. case OC_QUEUE_FILE_OPS:
  370. LOGMESSAGE(_T("\r\nOnQueueFileOps: Entered"));
  371. dwRet = OnQueueFileOps(
  372. (LPCTSTR)SubcomponentId,
  373. (HSPFILEQ)Param2
  374. );
  375. LOGMESSAGE(_T("OnQueueFileOps: Returned"));
  376. break;
  377. case OC_QUERY_STEP_COUNT:
  378. LOGMESSAGE(_T("\r\nOnQueryStepCount: Entered"));
  379. dwRet = OnQueryStepCount();
  380. LOGMESSAGE(_T("OnQueryStepCount: Returned"));
  381. break;
  382. case OC_ABOUT_TO_COMMIT_QUEUE:
  383. LOGMESSAGE(_T("\r\nOnAboutToCommitQueue: Entered"));
  384. dwRet = OnAboutToCommitQueue();
  385. LOGMESSAGE(_T("OnAboutToCommitQueue: Returned"));
  386. break;
  387. case OC_COMPLETE_INSTALLATION:
  388. LOGMESSAGE(_T("\r\nOnCompleteInstallation: Entered"));
  389. dwRet = OnCompleteInstallation(
  390. (LPCTSTR)SubcomponentId
  391. );
  392. LOGMESSAGE(_T("OnCompleteInstallation: Returned"));
  393. break;
  394. case OC_CLEANUP:
  395. LOGMESSAGE(_T("\r\nOnCleanup: Entered"));
  396. dwRet = OnCleanup();
  397. break;
  398. default:
  399. LOGMESSAGE(_T("\r\nOC Manager calling for unknown function %ld\r\n"),
  400. Function);
  401. dwRet = 0;
  402. }
  403. UNREFERENCED_PARAMETER(ComponentId);
  404. return(dwRet);
  405. }
  406. /*
  407. * OnPreinitialize()
  408. *
  409. *
  410. */
  411. DWORD
  412. OnPreinitialize(
  413. IN UINT_PTR Flags
  414. )
  415. {
  416. UNREFERENCED_PARAMETER(Flags);
  417. #ifdef UNICODE
  418. return(OCFLAG_UNICODE);
  419. #else
  420. return(OCFLAG_ANSI);
  421. #endif
  422. }
  423. /*
  424. * OnInitComponent()
  425. *
  426. *
  427. */
  428. DWORD
  429. OnInitComponent(
  430. IN PSETUP_INIT_COMPONENT pSetupInitComponent
  431. )
  432. {
  433. BOOL fErr;
  434. DWORDLONG OperationFlags;
  435. if (pSetupInitComponent == NULL) {
  436. LOGMESSAGE(_T("OnInitComponent: Passed NULL PSETUP_INIT_COMPONENT"));
  437. return(ERROR_CANCELLED);
  438. }
  439. //
  440. // Verify that the OC Manager and OC versions are compatible.
  441. //
  442. pSetupInitComponent->ComponentVersion = GetComponentVersion();
  443. if (pSetupInitComponent->ComponentVersion >
  444. pSetupInitComponent->OCManagerVersion) {
  445. LOGMESSAGE(_T("OnInitComponent: Version mismatch."));
  446. return(ERROR_CALL_NOT_IMPLEMENTED);
  447. }
  448. //
  449. // Copy setup data.
  450. //
  451. gpInitComponentData = (PSETUP_INIT_COMPONENT)LocalAlloc(
  452. LPTR,
  453. sizeof(SETUP_INIT_COMPONENT)
  454. );
  455. if (gpInitComponentData == NULL) {
  456. LOGMESSAGE(_T("OnInitComponent: Can't allocate gpInitComponentData."));
  457. return(ERROR_CANCELLED);
  458. }
  459. CopyMemory(
  460. gpInitComponentData,
  461. pSetupInitComponent,
  462. sizeof(SETUP_INIT_COMPONENT)
  463. );
  464. //
  465. // Open Inf file.
  466. //
  467. if (GetComponentInfHandle() == NULL) {
  468. return(ERROR_CANCELLED);
  469. }
  470. fErr = SetupOpenAppendInfFile(
  471. NULL,
  472. GetComponentInfHandle(),
  473. NULL
  474. );
  475. if (!fErr) {
  476. LOGMESSAGE(_T("OnInitComponent: SetupOpenAppendInfFile failed: %ld"),
  477. GetLastError());
  478. return(GetLastError());
  479. }
  480. //
  481. // Set state variables.
  482. //
  483. OperationFlags = gpInitComponentData->SetupData.OperationFlags;
  484. gStandAlone = OperationFlags & SETUPOP_STANDALONE ? TRUE : FALSE;
  485. gUnAttended = OperationFlags & SETUPOP_BATCH ? TRUE : FALSE;
  486. gNtUpgrade = OperationFlags & SETUPOP_NTUPGRADE ? TRUE : FALSE;
  487. LOGMESSAGE(_T("OnInitComponent: gStandAlone = %s"),
  488. gStandAlone ? _T("TRUE") : _T("FALSE"));
  489. LOGMESSAGE(_T("OnInitComponent: gUnAttended = %s"),
  490. gUnAttended ? _T("TRUE") : _T("FALSE"));
  491. LOGMESSAGE(_T("OnInitComponent: gNtUpgrade = %s"),
  492. gNtUpgrade ? _T("TRUE") : _T("FALSE"));
  493. //
  494. // Gather previous version's information from registry. If the role
  495. // does not exist in the registry, SetServerRole will stay with the
  496. // default.
  497. //
  498. SetServerRole(GetServerRoleFromRegistry());
  499. //
  500. // Check for Nt4 Upgrade.
  501. //
  502. if (GetNT4DbConfig(NULL, NULL, NULL, NULL) == NO_ERROR) {
  503. LOGMESSAGE(_T("OnInitComponent: Nt4Upgrade"));
  504. gNt4Upgrade = TRUE;
  505. DeleteNT4ODBCDataSource();
  506. }
  507. //
  508. // License Server will only use the directory in the registry during
  509. // an Nt5 to Nt5 upgrade or stand alone setup from Add/Remove Programs.
  510. //
  511. if (gStandAlone || (gNtUpgrade && !gNt4Upgrade)) {
  512. LPCTSTR pszDbDirFromReg = GetDatabaseDirectoryFromRegistry();
  513. if (pszDbDirFromReg != NULL) {
  514. SetDatabaseDirectory(pszDbDirFromReg);
  515. }
  516. }
  517. return(NO_ERROR);
  518. }
  519. /*
  520. * OnSetLanguage()
  521. *
  522. *
  523. */
  524. DWORD
  525. OnSetLanguage(
  526. IN UINT_PTR LanguageId
  527. )
  528. {
  529. UNREFERENCED_PARAMETER(LanguageId);
  530. return((DWORD)FALSE);
  531. }
  532. /*
  533. * OnQueryImage()
  534. *
  535. *
  536. */
  537. DWORD
  538. OnQueryImage(
  539. IN UINT_PTR SubCompEnum,
  540. IN OUT PDWORD Size
  541. )
  542. {
  543. UNREFERENCED_PARAMETER(SubCompEnum);
  544. UNREFERENCED_PARAMETER(Size);
  545. return((DWORD)NULL);
  546. }
  547. /*
  548. * OnRequestPages()
  549. *
  550. *
  551. */
  552. DWORD
  553. OnRequestPages(
  554. IN WizardPagesType PageTypeEnum,
  555. IN OUT PSETUP_REQUEST_PAGES pRequestPages
  556. )
  557. {
  558. const DWORD cUiPages = 1;
  559. BOOL fErr;
  560. LOGMESSAGE(_T("OnRequestPages: Page Type %d"), PageTypeEnum);
  561. if (pRequestPages == NULL) {
  562. LOGMESSAGE(_T("OnRequestPages: pRequestPages == NULL"));
  563. return(0);
  564. }
  565. if ((!gStandAlone) || (PageTypeEnum != WizPagesEarly)) {
  566. return(0);
  567. }
  568. if (pRequestPages->MaxPages >= cUiPages) {
  569. gEnableDlg = new EnablePage;
  570. if (gEnableDlg == NULL) {
  571. goto CleanUp1;
  572. }
  573. fErr = gEnableDlg->Initialize();
  574. if (!fErr) {
  575. goto CleanUp1;
  576. }
  577. pRequestPages->Pages[0] = CreatePropertySheetPage(
  578. (LPPROPSHEETPAGE)gEnableDlg
  579. );
  580. if (pRequestPages->Pages[0] == NULL) {
  581. LOGMESSAGE(_T("OnRequestPages: Failed CreatePropertySheetPage!"));
  582. goto CleanUp0;
  583. }
  584. }
  585. return(cUiPages);
  586. CleanUp0:
  587. delete gEnableDlg;
  588. CleanUp1:
  589. SetLastError(ERROR_OUTOFMEMORY);
  590. LOGMESSAGE(_T("OnRequestPages: Out of Memory!"));
  591. return((DWORD)-1);
  592. }
  593. /*
  594. * OnWizardCreated()
  595. *
  596. *
  597. */
  598. DWORD
  599. OnWizardCreated(
  600. VOID
  601. )
  602. {
  603. return(NO_ERROR);
  604. }
  605. /*
  606. * OnQueryState()
  607. *
  608. *
  609. */
  610. DWORD
  611. OnQueryState(
  612. IN UINT_PTR uState
  613. )
  614. {
  615. UNREFERENCED_PARAMETER(uState);
  616. return(SubcompUseOcManagerDefault);
  617. }
  618. /*
  619. * OnQueryChangeSelState()
  620. *
  621. *
  622. */
  623. DWORD
  624. OnQueryChangeSelState(
  625. IN UINT_PTR SelectionState,
  626. IN UINT Flags
  627. )
  628. {
  629. BOOL fDirectSelection;
  630. BOOL fRet;
  631. BOOL fSelect;
  632. UNREFERENCED_PARAMETER(Flags);
  633. if (Flags & OCQ_ACTUAL_SELECTION)
  634. {
  635. fDirectSelection = TRUE;
  636. }
  637. else
  638. {
  639. fDirectSelection = FALSE;
  640. }
  641. fRet = TRUE;
  642. fSelect = (SelectionState != 0);
  643. if (!fSelect && fDirectSelection && GetOriginalSelectionState())
  644. {
  645. DWORD dwStatus;
  646. HWND hWnd;
  647. int iRet;
  648. hWnd = gpInitComponentData->HelperRoutines.QueryWizardDialogHandle(gpInitComponentData->HelperRoutines.OcManagerContext);
  649. dwStatus = DisplayMessageBox(
  650. hWnd,
  651. IDS_STRING_LICENSES_GO_BYE_BYE,
  652. IDS_MAIN_TITLE,
  653. MB_YESNO,
  654. &iRet
  655. );
  656. if (dwStatus == ERROR_SUCCESS)
  657. {
  658. fRet = (iRet == IDYES);
  659. }
  660. }
  661. return((DWORD)fRet);
  662. }
  663. /*
  664. * OnCalcDiskSpace()
  665. *
  666. *
  667. */
  668. DWORD
  669. OnCalcDiskSpace(
  670. IN LPCTSTR SubcomponentId,
  671. IN UINT_PTR AddComponent,
  672. IN OUT HDSKSPC DiskSpaceHdr
  673. )
  674. {
  675. BOOL fErr;
  676. LPCTSTR pSection;
  677. if ((SubcomponentId == NULL) ||
  678. (SubcomponentId[0] == NULL)) {
  679. return(0);
  680. }
  681. LOGMESSAGE(_T("OnCalcDiskSpace: %s"),
  682. AddComponent ? _T("Installing") : _T("Removing"));
  683. //
  684. // There is no clear documentation on how this should work. If the
  685. // size of the installation should be visible no matter what, then
  686. // the section to install should be hardcoded, not determined by
  687. // the current state.
  688. //
  689. pSection = gInstallSectionNames[kInstall];
  690. LOGMESSAGE(_T("OnCalcDiskSpace: Calculating for %s"), pSection);
  691. if (AddComponent != 0) {
  692. fErr = SetupAddInstallSectionToDiskSpaceList(
  693. DiskSpaceHdr,
  694. GetComponentInfHandle(),
  695. NULL,
  696. pSection,
  697. NULL,
  698. 0
  699. );
  700. } else {
  701. fErr = SetupRemoveInstallSectionFromDiskSpaceList(
  702. DiskSpaceHdr,
  703. GetComponentInfHandle(),
  704. NULL,
  705. pSection,
  706. NULL,
  707. 0
  708. );
  709. }
  710. if (fErr) {
  711. return(NO_ERROR);
  712. } else {
  713. LOGMESSAGE(_T("OnCalcDiskSpace: Error %ld"), GetLastError());
  714. return(GetLastError());
  715. }
  716. }
  717. /*
  718. * OnQueueFileOps()
  719. *
  720. *
  721. */
  722. DWORD
  723. OnQueueFileOps(
  724. IN LPCTSTR SubcomponentId,
  725. IN OUT HSPFILEQ FileQueueHdr
  726. )
  727. {
  728. BOOL fErr;
  729. DWORD dwErr;
  730. EInstall eInstallSection;
  731. LPCTSTR pSection;
  732. if ((SubcomponentId == NULL) ||
  733. (SubcomponentId[0] == NULL)) {
  734. return(0);
  735. }
  736. pSection = GetInstallSectionName();
  737. LOGMESSAGE(_T("OnQueueFileOps: Queueing %s"), pSection);
  738. //
  739. // Stop and remove the license server service, if needed. This must
  740. // be done before queueing files for deletion.
  741. //
  742. eInstallSection = GetInstallSection();
  743. if (eInstallSection == kUninstall || eInstallSection == kStandaloneUninstall) {
  744. if (gServerRole == eEnterpriseServer) {
  745. if (UnpublishEnterpriseServer() != S_OK) {
  746. LOGMESSAGE(
  747. _T("OnQueueFileOps: UnpublishEnterpriseServer() failed")
  748. );
  749. }
  750. }
  751. dwErr = ServiceDeleteFromInfSection(
  752. GetComponentInfHandle(),
  753. pSection
  754. );
  755. if (dwErr != ERROR_SUCCESS) {
  756. LOGMESSAGE(
  757. _T("OnQueueFileOps: Error deleting service: %ld"),
  758. dwErr
  759. );
  760. }
  761. }
  762. fErr = SetupInstallFilesFromInfSection(
  763. GetComponentInfHandle(),
  764. NULL,
  765. FileQueueHdr,
  766. pSection,
  767. NULL,
  768. eInstallSection == kUninstall ? 0 : SP_COPY_NEWER
  769. );
  770. if (fErr) {
  771. return(NO_ERROR);
  772. } else {
  773. LOGMESSAGE(_T("OnQueueFileOps: Error %ld"), GetLastError());
  774. return(GetLastError());
  775. }
  776. }
  777. /*
  778. * OnQueryStepCount()
  779. *
  780. * TODO: how many steps, when should we tick?
  781. */
  782. DWORD
  783. OnQueryStepCount(
  784. VOID
  785. )
  786. {
  787. return(0);
  788. }
  789. /*
  790. * OnAboutToCommitQueue()
  791. *
  792. *
  793. */
  794. DWORD
  795. OnAboutToCommitQueue(
  796. VOID
  797. )
  798. {
  799. return(NO_ERROR);
  800. }
  801. /*
  802. * OnCompleteInstallation()
  803. *
  804. *
  805. */
  806. DWORD
  807. OnCompleteInstallation(
  808. IN LPCTSTR SubcomponentId
  809. )
  810. {
  811. BOOL fErr;
  812. DWORD dwErr;
  813. EInstall eInstallSection = GetInstallSection();
  814. LPCTSTR pSection;
  815. TCHAR tchBuf[MESSAGE_SIZE] ={0};
  816. TCHAR tchTitle[TITLE_SIZE] = {0};
  817. if ((SubcomponentId == NULL) ||
  818. (SubcomponentId[0] == NULL)) {
  819. return(NO_ERROR);
  820. }
  821. //
  822. // This has to run even for "kDoNothing" - if the LS was previously
  823. // installed and is still installed
  824. //
  825. dwErr = MigrateLsaSecrets();
  826. if (dwErr != NO_ERROR) {
  827. LOGMESSAGE(
  828. _T("OnCompleteInstallation: MigrateLsaSecrets: Error %ld"),
  829. dwErr
  830. );
  831. return(dwErr);
  832. }
  833. if(eInstallSection == kDoNothing)
  834. {
  835. LOGMESSAGE(_T("OnCompleteInstallation: Nothing to do"));
  836. return (NO_ERROR);
  837. }
  838. pSection = GetInstallSectionName();
  839. //
  840. // In GUI mode setup and in unattended StandAlone setup, the wizard
  841. // page does not display, and therefore the directory is not created.
  842. // Create the default directory here.
  843. //
  844. if (eInstallSection == kInstall || eInstallSection == kStandaloneInstall) {
  845. if ((!gStandAlone) || (gUnAttended)) {
  846. CreateDatabaseDirectory();
  847. }
  848. }
  849. //
  850. // SetupAPI correctly handles installing and removing files, and
  851. // creating start menu links.
  852. fErr = SetupInstallFromInfSection(
  853. NULL,
  854. GetComponentInfHandle(),
  855. pSection,
  856. SPINST_INIFILES | SPINST_REGISTRY | SPINST_PROFILEITEMS,
  857. NULL,
  858. NULL,
  859. 0,
  860. NULL,
  861. NULL,
  862. NULL,
  863. NULL
  864. );
  865. if (!fErr) {
  866. LOGMESSAGE(_T("OnCompleteInstallation: InstallFromInf failed %ld"),
  867. GetLastError());
  868. return(GetLastError());
  869. }
  870. if (eInstallSection == kStandaloneInstall)
  871. {
  872. CreateDatabaseDirectory();
  873. //
  874. // Set service settings first and install the service.
  875. //
  876. dwErr = CreateRegistrySettings(GetDatabaseDirectory(), gServerRole);
  877. if (dwErr != NO_ERROR) {
  878. LOGMESSAGE(
  879. _T("OnCompleteInstallation: kStandaloneInstall: CreateRegistrySettings: Error %ld"),
  880. dwErr
  881. );
  882. return(dwErr);
  883. }
  884. fErr = SetupInstallServicesFromInfSection(
  885. GetComponentInfHandle(),
  886. pSection,
  887. 0
  888. );
  889. if (!fErr) {
  890. LOGMESSAGE(
  891. _T("OnCompleteInstallation: kStandaloneInstall: InstallServices: Error %ld"),
  892. GetLastError()
  893. );
  894. return(GetLastError());
  895. }
  896. if (gServerRole == eEnterpriseServer) {
  897. if (PublishEnterpriseServer() != S_OK) {
  898. LOGMESSAGE(_T("OnCompleteInstallation: kStandaloneInstall: PublishEnterpriseServer() failed. Setup will still complete."));
  899. LOGMESSAGE(_T("PublishEnterpriseServer: kStandaloneInstall: Uninstall, try logging on as a member of the Enterprise Admins or Domain Admins group and then run setup again."));
  900. if (!gUnAttended)
  901. {
  902. LoadString( GetInstance(), IDS_INSUFFICIENT_PERMISSION, tchBuf, sizeof(tchBuf)/sizeof(TCHAR));
  903. LoadString( GetInstance(), IDS_MAIN_TITLE, tchTitle, sizeof(tchTitle)/sizeof(TCHAR));
  904. MessageBox( NULL, tchBuf, tchTitle, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
  905. }
  906. }
  907. }
  908. dwErr = ServiceStartFromInfSection(
  909. GetComponentInfHandle(),
  910. pSection
  911. );
  912. if (dwErr != ERROR_SUCCESS) {
  913. LOGMESSAGE(
  914. _T("OnCompleteInstallation: kStandaloneInstall: Error starting service: %ld"),
  915. dwErr
  916. );
  917. return(dwErr);
  918. }
  919. }
  920. //
  921. // Perform installation and upgrade-specific tasks.
  922. //
  923. else if (eInstallSection == kInstall)
  924. {
  925. LOGMESSAGE(_T("OnCompleteInstallation: kInstall: Installing"));
  926. //
  927. // Set service settings first and install the service.
  928. //
  929. dwErr = CreateRegistrySettings(GetDatabaseDirectory(), gServerRole);
  930. if (dwErr != NO_ERROR)
  931. {
  932. LOGMESSAGE(
  933. _T("OnCompleteInstallation: kInstall: CreateRegistrySettings: Error %ld"),
  934. dwErr
  935. );
  936. return(dwErr);
  937. }
  938. fErr = SetupInstallServicesFromInfSection(
  939. GetComponentInfHandle(),
  940. pSection,
  941. 0
  942. );
  943. if (!fErr)
  944. {
  945. LOGMESSAGE(
  946. _T("OnCompleteInstallation: kInstall: InstallServices: Error %ld"),
  947. GetLastError()
  948. );
  949. return(GetLastError());
  950. }
  951. if (gServerRole == eEnterpriseServer)
  952. {
  953. if (PublishEnterpriseServer() != S_OK)
  954. {
  955. LOGMESSAGE(_T("OnCompleteInstallation: kInstall: PublishEnterpriseServer() failed. Setup will still complete."));
  956. LOGMESSAGE(_T("PublishEnterpriseServer: kInstall: Uninstall, try logging on as a member of the Enterprise Admins or Domain Admins group and then run setup again."));
  957. if (!gUnAttended)
  958. {
  959. LoadString( GetInstance(), IDS_INSUFFICIENT_PERMISSION, tchBuf, sizeof(tchBuf)/sizeof(TCHAR));
  960. LoadString( GetInstance(), IDS_MAIN_TITLE, tchTitle, sizeof(tchTitle)/sizeof(TCHAR));
  961. MessageBox( NULL, tchBuf, tchTitle, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
  962. }
  963. }
  964. }
  965. }
  966. else if (eInstallSection == kUninstall)
  967. {
  968. CleanLicenseServerSecret();
  969. RemoveDatabaseDirectory();
  970. RemoveRegistrySettings();
  971. fErr = SetupInstallFromInfSection(
  972. NULL,
  973. GetComponentInfHandle(),
  974. pSection,
  975. SPINST_INIFILES | SPINST_REGISTRY | SPINST_PROFILEITEMS,
  976. NULL,
  977. NULL,
  978. 0,
  979. NULL,
  980. NULL,
  981. NULL,
  982. NULL
  983. );
  984. if (!fErr)
  985. {
  986. LOGMESSAGE(_T("OnCompleteInstallation: kUninstall: InstallFromInf failed %ld"),
  987. GetLastError());
  988. return(GetLastError());
  989. }
  990. }
  991. else if (eInstallSection == kStandaloneUninstall)
  992. {
  993. CleanLicenseServerSecret();
  994. RemoveDatabaseDirectory();
  995. RemoveRegistrySettings();
  996. fErr = SetupInstallFromInfSection(
  997. NULL,
  998. GetComponentInfHandle(),
  999. pSection,
  1000. SPINST_INIFILES | SPINST_REGISTRY | SPINST_PROFILEITEMS,
  1001. NULL,
  1002. NULL,
  1003. 0,
  1004. NULL,
  1005. NULL,
  1006. NULL,
  1007. NULL
  1008. );
  1009. if (!fErr)
  1010. {
  1011. LOGMESSAGE(_T("OnCompleteInstallation: kStandaloneUninstall: InstallFromInf failed %ld"),
  1012. GetLastError());
  1013. return(GetLastError());
  1014. }
  1015. }
  1016. return(NO_ERROR);
  1017. }
  1018. /*
  1019. * OnCleanup()
  1020. *
  1021. *
  1022. */
  1023. DWORD
  1024. OnCleanup(
  1025. VOID
  1026. )
  1027. {
  1028. if (gpInitComponentData != NULL) {
  1029. LocalFree(gpInitComponentData);
  1030. }
  1031. if (gEnableDlg != NULL) {
  1032. delete gEnableDlg;
  1033. }
  1034. LOGMESSAGE(_T("OnCleanup: Returned"));
  1035. LOGCLOSE();
  1036. return(NO_ERROR);
  1037. }