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.

2908 lines
88 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: csocm.cpp
  8. //
  9. // Contents: OCM component DLL for running the Certificate
  10. // Server setup.
  11. //
  12. // Functions:
  13. //
  14. // History: 12/13/96 TedM Created Original Version
  15. // 04/07/97 JerryK Rewrite for Cert Server
  16. // 04/??/97 JerryK Stopped updating these comments since
  17. // every other line changes every day.
  18. // 08/98 XTan Major structure change
  19. //
  20. // Notes:
  21. //
  22. // This sample OCM component DLL can be the component DLL
  23. // for multiple components. It assumes that a companion sample INF
  24. // is being used as the per-component INF, with private data in the
  25. // following form.
  26. //
  27. // [<pwszComponent>,<pwszSubComponent>]
  28. // Bitmap = <bitmapresourcename>
  29. // VerifySelect = 0/1
  30. // VerifyDeselect = 0/1
  31. // ;
  32. // ; follow this with install stuff such as CopyFiles= sections, etc.
  33. //
  34. //------------------------------------------------------------------------------
  35. #include "pch.cpp"
  36. #pragma hdrstop
  37. #include <common.ver>
  38. #include "msg.h"
  39. #include "certmsg.h"
  40. #include "setuput.h"
  41. #include "setupids.h"
  42. #include "clibres.h"
  43. #include "csresstr.h"
  44. // defines
  45. #define cwcMESSAGETEXT 250
  46. #define cwcINFVALUE 250
  47. #define wszSMALLICON L"_SmallIcon"
  48. #define wszUNINSTALL L"_Uninstall"
  49. #define wszUPGRADE L"_Upgrade"
  50. #define wszINSTALL L"_Install"
  51. #define wszVERIFYSELECT L"_VerifySelect"
  52. #define wszVERIFYDESELECT L"_VerifyDeselect"
  53. #define wszCONFIGTITLE L"Title"
  54. #define wszCONFIGCOMMAND L"ConfigCommand"
  55. #define wszCONFIGARGS L"ConfigArgs"
  56. #define wszCONFIGTITLEVAL L"Certificate Services"
  57. #define wszCONFIGCOMMANDVAL L"sysocmgr.exe"
  58. #define wszCONFIGARGSVAL L"/i:certmast.inf /x"
  59. #define __dwFILE__ __dwFILE_OCMSETUP_CSOCM_CPP__
  60. // globals
  61. PER_COMPONENT_DATA g_Comp; // Top Level component
  62. HINSTANCE g_hInstance; // get rid of it????
  63. // find out if certsrv post setup is finished by checking
  64. // registry entries. ie. finish CYS?
  65. HRESULT
  66. CheckPostBaseInstallStatus(
  67. OUT BOOL *pfFinished)
  68. {
  69. HRESULT hr;
  70. HKEY hKey = NULL;
  71. DWORD dwSize = 0;
  72. DWORD dwType = REG_NONE;
  73. //init
  74. *pfFinished = TRUE;
  75. if (ERROR_SUCCESS == RegOpenKeyEx(
  76. HKEY_LOCAL_MACHINE,
  77. wszREGKEYCERTSRVTODOLIST,
  78. 0,
  79. KEY_READ,
  80. &hKey))
  81. {
  82. if (ERROR_SUCCESS == RegQueryValueEx(
  83. hKey,
  84. wszCONFIGCOMMAND,
  85. NULL,
  86. &dwType,
  87. NULL, // only query size
  88. &dwSize) &&
  89. REG_SZ == dwType)
  90. {
  91. dwType = REG_NONE;
  92. if (ERROR_SUCCESS == RegQueryValueEx(
  93. hKey,
  94. wszCONFIGARGS,
  95. NULL,
  96. &dwType,
  97. NULL, // only query size
  98. &dwSize) &&
  99. REG_SZ == dwType)
  100. {
  101. dwType = REG_NONE;
  102. if (ERROR_SUCCESS == RegQueryValueEx(
  103. hKey,
  104. wszCONFIGTITLE,
  105. NULL,
  106. &dwType,
  107. NULL, // only query size
  108. &dwSize) &&
  109. REG_SZ == dwType)
  110. {
  111. //all entries exist
  112. *pfFinished = FALSE;
  113. }
  114. }
  115. }
  116. }
  117. hr = S_OK;
  118. //error:
  119. if (NULL != hKey)
  120. {
  121. RegCloseKey(hKey);
  122. }
  123. return hr;
  124. }
  125. HRESULT
  126. InitComponentAttributes(
  127. IN OUT PER_COMPONENT_DATA *pComp,
  128. IN HINSTANCE hDllHandle)
  129. {
  130. HRESULT hr;
  131. ZeroMemory(pComp, sizeof(PER_COMPONENT_DATA));
  132. pComp->hInstance = hDllHandle;
  133. g_hInstance = hDllHandle; //get rid of it????
  134. pComp->hrContinue = S_OK;
  135. pComp->pwszCustomMessage = NULL;
  136. pComp->fUnattended = FALSE;
  137. pComp->pwszUnattendedFile = NULL;
  138. pComp->pwszServerName = NULL;
  139. pComp->pwszServerNameOld = NULL;
  140. pComp->dwInstallStatus = 0x0;
  141. pComp->fPostBase = FALSE;
  142. (pComp->CA).pServer = NULL;
  143. (pComp->CA).pClient = NULL;
  144. pComp->hinfCAPolicy = INVALID_HANDLE_VALUE;
  145. hr = S_OK;
  146. //error:
  147. return hr;
  148. }
  149. //+------------------------------------------------------------------------
  150. //
  151. // Function: DllMain( . . . . )
  152. //
  153. // Synopsis: DLL Entry Point.
  154. //
  155. // Arguments: [DllHandle] DLL module handle.
  156. // [Reason] Reasons for entry into DLL.
  157. // [Reserved] Reserved.
  158. //
  159. // Returns: BOOL
  160. //
  161. // History: 04/07/97 JerryK Created (again)
  162. //
  163. //-------------------------------------------------------------------------
  164. BOOL WINAPI
  165. DllMain(
  166. IN HMODULE DllHandle,
  167. IN DWORD Reason,
  168. IN LPVOID Reserved)
  169. {
  170. BOOL b;
  171. UNREFERENCED_PARAMETER(Reserved);
  172. b = TRUE;
  173. switch(Reason)
  174. {
  175. case DLL_PROCESS_ATTACH:
  176. DBGPRINT((DBG_SS_CERTOCMI, "Process Attach\n"));
  177. // component initialization
  178. InitComponentAttributes(&g_Comp, DllHandle);
  179. // Fall through to process first thread
  180. case DLL_THREAD_ATTACH:
  181. b = TRUE;
  182. break;
  183. case DLL_PROCESS_DETACH:
  184. DBGPRINT((DBG_SS_CERTOCMI, "Process Detach\n"));
  185. if(INVALID_HANDLE_VALUE != g_Comp.hinfCAPolicy)
  186. myInfCloseFile(g_Comp.hinfCAPolicy);
  187. myInfClearError();
  188. myFreeResourceStrings("certocm.dll");
  189. myFreeColumnDisplayNames();
  190. myRegisterMemDump();
  191. csiLogClose();
  192. break;
  193. case DLL_THREAD_DETACH:
  194. break;
  195. }
  196. return b;
  197. }
  198. extern UNATTENDPARM aUnattendParmClient[];
  199. extern UNATTENDPARM aUnattendParmServer[];
  200. SUBCOMP g_aSubComp[] =
  201. {
  202. {
  203. L"certsrv", // pwszSubComponent
  204. cscTopLevel, // cscSubComponent
  205. 0, // InstallFlags
  206. 0, // UninstallFlags
  207. 0, // ChangeFlags
  208. 0, // UpgradeFlags
  209. 0, // EnabledFlags
  210. 0, // SetupStatusFlags
  211. FALSE, // fDefaultInstallUnattend
  212. FALSE, // fInstallUnattend
  213. NULL // aUnattendParm
  214. },
  215. {
  216. wszSERVERSECTION, // pwszSubComponent
  217. cscServer, // cscSubComponent
  218. IS_SERVER_INSTALL, // InstallFlags
  219. IS_SERVER_REMOVE, // UninstallFlags
  220. IS_SERVER_CHANGE, // ChangeFlags
  221. IS_SERVER_UPGRADE, // UpgradeFlags
  222. IS_SERVER_ENABLED, // EnabledFlags
  223. SETUP_SERVER_FLAG, // SetupStatusFlags
  224. TRUE, // fDefaultInstallUnattend
  225. FALSE, // fInstallUnattend
  226. aUnattendParmServer // aUnattendParm
  227. },
  228. {
  229. wszCLIENTSECTION, // pwszSubComponent
  230. cscClient, // cscSubComponent
  231. IS_CLIENT_INSTALL, // InstallFlags
  232. IS_CLIENT_REMOVE, // UninstallFlags
  233. IS_CLIENT_CHANGE, // ChangeFlags
  234. IS_CLIENT_UPGRADE, // UpgradeFlags
  235. IS_CLIENT_ENABLED, // EnabledFlags
  236. SETUP_CLIENT_FLAG, // SetupStatusFlags
  237. TRUE, // fDefaultInstallUnattend
  238. FALSE, // fInstallUnattend
  239. aUnattendParmClient // aUnattendParm
  240. },
  241. {
  242. NULL, // pwszSubComponent
  243. }
  244. };
  245. SUBCOMP *
  246. TranslateSubComponent(
  247. IN WCHAR const *pwszComponent,
  248. OPTIONAL IN WCHAR const *pwszSubComponent)
  249. {
  250. SUBCOMP *psc;
  251. if (NULL == pwszSubComponent)
  252. {
  253. pwszSubComponent = pwszComponent;
  254. }
  255. for (psc = g_aSubComp; NULL != psc->pwszSubComponent; psc++)
  256. {
  257. if (0 == mylstrcmpiL(psc->pwszSubComponent, pwszSubComponent))
  258. {
  259. break;
  260. }
  261. }
  262. if (NULL == psc->pwszSubComponent)
  263. {
  264. psc = NULL;
  265. }
  266. return(psc);
  267. }
  268. SUBCOMP const *
  269. LookupSubComponent(
  270. IN CertSubComponent SubComp)
  271. {
  272. SUBCOMP const *psc;
  273. for (psc = g_aSubComp; NULL != psc->pwszSubComponent; psc++)
  274. {
  275. if (psc->cscSubComponent == SubComp)
  276. {
  277. break;
  278. }
  279. }
  280. CSASSERT(NULL != psc);
  281. return(psc);
  282. }
  283. BOOL fDebugSupress = TRUE;
  284. HRESULT
  285. UpdateSubComponentInstallStatus(
  286. IN WCHAR const *pwszComponent,
  287. IN WCHAR const *pwszSubComponent,
  288. IN OUT PER_COMPONENT_DATA *pComp)
  289. {
  290. HRESULT hr;
  291. BOOL fWasEnabled;
  292. BOOL fIsEnabled;
  293. DWORD InstallFlags;
  294. SUBCOMP const *psc;
  295. psc = TranslateSubComponent(pwszComponent, pwszSubComponent);
  296. if (NULL == psc)
  297. {
  298. hr = E_INVALIDARG;
  299. _JumpError(hr, error, "Internal error: unsupported component");
  300. }
  301. fWasEnabled = certocmWasEnabled(pComp, psc->cscSubComponent);
  302. fIsEnabled = certocmIsEnabled(pComp, psc->cscSubComponent);
  303. CSILOGDWORD(IDS_LOG_WAS_ENABLED, fWasEnabled);
  304. CSILOGDWORD(IDS_LOG_IS_ENABLED, fIsEnabled);
  305. InstallFlags = psc->InstallFlags | psc->ChangeFlags | psc->EnabledFlags;
  306. if (!fWasEnabled)
  307. {
  308. if (fIsEnabled)
  309. {
  310. // install case
  311. pComp->dwInstallStatus |= InstallFlags;
  312. }
  313. else // !fIsEnabled
  314. {
  315. // this is from check then uncheck, should remove the bit
  316. // turn off both bits
  317. pComp->dwInstallStatus &= ~InstallFlags;
  318. }
  319. }
  320. else // fWasEnabled
  321. {
  322. if (pComp->fPostBase &&
  323. (pComp->Flags & SETUPOP_STANDALONE) )
  324. {
  325. // was installed, invoke from post setup
  326. // this is install case
  327. pComp->dwInstallStatus |= InstallFlags;
  328. }
  329. else if (pComp->Flags & SETUPOP_NTUPGRADE)
  330. {
  331. // if was installed and now in upgrade mode, upgrade case
  332. pComp->dwInstallStatus |= psc->UpgradeFlags | psc->EnabledFlags;
  333. }
  334. else if (!fIsEnabled)
  335. {
  336. // uninstall case
  337. pComp->dwInstallStatus &= ~psc->EnabledFlags;
  338. pComp->dwInstallStatus |= psc->UninstallFlags | psc->ChangeFlags;
  339. }
  340. else // fIsEnabled
  341. {
  342. pComp->dwInstallStatus |= psc->EnabledFlags;
  343. #if DBG_CERTSRV
  344. BOOL fUpgrade = FALSE;
  345. hr = myGetCertRegDWValue(
  346. NULL,
  347. NULL,
  348. NULL,
  349. L"EnforceUpgrade",
  350. (DWORD *) &fUpgrade);
  351. if (S_OK == hr && fUpgrade)
  352. {
  353. pComp->dwInstallStatus |= psc->UpgradeFlags;
  354. }
  355. #endif //DBG_CERTSRV
  356. } // end fIsEnabled else
  357. } // end fWasEnabled else
  358. // after all of this, change upgrade->uninstall if not supported
  359. // detect illegal upgrade
  360. if (pComp->dwInstallStatus & IS_SERVER_UPGRADE)
  361. {
  362. hr = DetermineServerUpgradePath(pComp);
  363. _JumpIfError(hr, error, "DetermineServerUpgradePath");
  364. }
  365. else if (pComp->dwInstallStatus & IS_CLIENT_UPGRADE)
  366. {
  367. hr = DetermineClientUpgradePath(pComp);
  368. _JumpIfError(hr, error, "LoadAndDetermineClientUpgradeInfo");
  369. }
  370. if ((pComp->dwInstallStatus & IS_SERVER_UPGRADE) ||
  371. (pComp->dwInstallStatus & IS_CLIENT_UPGRADE))
  372. {
  373. CSASSERT(pComp->UpgradeFlag != CS_UPGRADE_UNKNOWN);
  374. if (CS_UPGRADE_UNSUPPORTED == pComp->UpgradeFlag)
  375. {
  376. pComp->dwInstallStatus &= ~InstallFlags;
  377. pComp->dwInstallStatus |= psc->UninstallFlags | psc->ChangeFlags;
  378. }
  379. }
  380. CSILOG(
  381. S_OK,
  382. IDS_LOG_INSTALL_STATE,
  383. pwszSubComponent,
  384. NULL,
  385. &pComp->dwInstallStatus);
  386. hr = S_OK;
  387. error:
  388. return hr;
  389. }
  390. HRESULT
  391. certocmOcPreInitialize(
  392. IN WCHAR const *DBGPARMREFERENCED(pwszComponent),
  393. IN UINT Flags,
  394. OUT ULONG_PTR *pulpRet)
  395. {
  396. HRESULT hr;
  397. *pulpRet = 0;
  398. DBGPRINT((DBG_SS_CERTOCMI, "OC_PREINITIALIZE(%ws, %x)\n", pwszComponent, Flags));
  399. myVerifyResourceStrings(g_hInstance);
  400. // Return value is flag telling OCM which char width we want to run in.
  401. #ifdef UNICODE
  402. *pulpRet = OCFLAG_UNICODE & Flags;
  403. #else
  404. *pulpRet = OCFLAG_ANSI & Flags;
  405. #endif
  406. hr = S_OK;
  407. //error:
  408. return hr;
  409. }
  410. // Allocate and initialize a new component.
  411. //
  412. // Return code is Win32 error indicating outcome. ERROR_CANCELLED tells OCM to
  413. // cancel the installation.
  414. HRESULT
  415. certocmOcInitComponent(
  416. IN HWND hwnd,
  417. IN WCHAR const *pwszComponent,
  418. IN OUT SETUP_INIT_COMPONENT *pInitComponent,
  419. IN OUT PER_COMPONENT_DATA *pComp,
  420. OUT ULONG_PTR *pulpRet)
  421. {
  422. HRESULT hr;
  423. BOOL fCoInit = FALSE;
  424. HKEY hkey = NULL;
  425. WCHAR awc[30];
  426. WCHAR *pwc;
  427. DBGPRINT((
  428. DBG_SS_CERTOCMI,
  429. "OC_INIT_COMPONENT(%ws, %p)\n",
  430. pwszComponent,
  431. pInitComponent));
  432. hr = CoInitialize(NULL);
  433. if (S_OK != hr && S_FALSE != hr)
  434. {
  435. _JumpError(hr, error, "CoInitialize");
  436. }
  437. fCoInit = TRUE;
  438. *pulpRet = ERROR_CANCELLED;
  439. if (OCMANAGER_VERSION <= pInitComponent->OCManagerVersion)
  440. {
  441. pInitComponent->OCManagerVersion = OCMANAGER_VERSION;
  442. }
  443. // Allocate a new component string.
  444. pComp->pwszComponent = (WCHAR *) LocalAlloc(LPTR,
  445. (wcslen(pwszComponent) + 1) * sizeof(WCHAR));
  446. _JumpIfOutOfMemory(hr, error, pComp->pwszComponent);
  447. wcscpy(pComp->pwszComponent, pwszComponent);
  448. // OCM passes in some information that we want to save, like the open
  449. // handle to our per-component INF. As long as we have a per-component INF,
  450. // append-open any layout file that is associated with it, in preparation
  451. // for later inf-based file queueing operations.
  452. //
  453. // We save away certain other stuff that gets passed to us now, since OCM
  454. // doesn't guarantee that the SETUP_INIT_COMPONENT will persist beyond the
  455. // processing of this one interface routine.
  456. if (INVALID_HANDLE_VALUE != pInitComponent->ComponentInfHandle &&
  457. NULL != pInitComponent->ComponentInfHandle)
  458. {
  459. pComp->MyInfHandle = pInitComponent->ComponentInfHandle;
  460. }
  461. else
  462. {
  463. hr = E_INVALIDARG;
  464. _JumpError(hr, error, "invalid inf handle");
  465. }
  466. if (NULL != pComp->MyInfHandle)
  467. {
  468. if (!SetupOpenAppendInfFile(NULL, pComp->MyInfHandle, NULL))
  469. {
  470. // SetupOpenAppendInfFile:
  471. // If Filename (Param1) is NULL, the INF filename is
  472. // retrieved from the LayoutFile value of the Version
  473. // section in the existing INF file.
  474. //
  475. // If FileName was not specified and there was no
  476. // LayoutFile value in the Version section of the
  477. // existing INF File, GetLastError returns ERROR_INVALID_DATA.
  478. hr = myHLastError();
  479. _PrintErrorStr(hr, "SetupOpenAppendInfFile", pwszComponent);
  480. }
  481. }
  482. pComp->HelperRoutines = pInitComponent->HelperRoutines;
  483. pComp->Flags = pInitComponent->SetupData.OperationFlags;
  484. pwc = awc;
  485. pwc += wsprintf(pwc, L"0x");
  486. if (0 != (DWORD) (pComp->Flags >> 32))
  487. {
  488. pwc += wsprintf(pwc, L"%x:", (DWORD) (pComp->Flags >> 32));
  489. }
  490. wsprintf(pwc, L"%08x", (DWORD) pComp->Flags);
  491. CSILOG(S_OK, IDS_LOG_OPERATIONFLAGS, awc, NULL, NULL);
  492. CSILOGDWORD(IDS_LOG_POSTBASE, pComp->fPostBase);
  493. hr = RegOpenKey(HKEY_LOCAL_MACHINE, wszREGKEYOCMSUBCOMPONENTS, &hkey);
  494. if (S_OK == hr)
  495. {
  496. DWORD dwType;
  497. DWORD dwValue;
  498. DWORD cb;
  499. DWORD const *pdw;
  500. cb = sizeof(dwValue);
  501. hr = RegQueryValueEx(
  502. hkey,
  503. wszSERVERSECTION,
  504. 0,
  505. &dwType,
  506. (BYTE *) &dwValue,
  507. &cb);
  508. pdw = NULL;
  509. if (S_OK == hr && REG_DWORD == dwType && sizeof(dwValue) == cb)
  510. {
  511. pdw = &dwValue;
  512. }
  513. CSILOG(hr, IDS_LOG_REGSTATE, wszSERVERSECTION, NULL, pdw);
  514. cb = sizeof(dwValue);
  515. hr = RegQueryValueEx(
  516. hkey,
  517. wszCLIENTSECTION,
  518. 0,
  519. &dwType,
  520. (BYTE *) &dwValue,
  521. &cb);
  522. pdw = NULL;
  523. if (S_OK == hr && REG_DWORD == dwType && sizeof(dwValue) == cb)
  524. {
  525. pdw = &dwValue;
  526. }
  527. CSILOG(hr, IDS_LOG_REGSTATE, wszCLIENTSECTION, NULL, pdw);
  528. cb = sizeof(dwValue);
  529. hr = RegQueryValueEx(
  530. hkey,
  531. wszOLDDOCCOMPONENT,
  532. 0,
  533. &dwType,
  534. (BYTE *) &dwValue,
  535. &cb);
  536. pdw = NULL;
  537. if (S_OK == hr && REG_DWORD == dwType && sizeof(dwValue) == cb)
  538. {
  539. CSILOG(hr, IDS_LOG_REGSTATE, wszOLDDOCCOMPONENT, NULL, &dwValue);
  540. }
  541. }
  542. pComp->fUnattended = (pComp->Flags & SETUPOP_BATCH)? TRUE : FALSE;
  543. CSILOG(
  544. S_OK,
  545. IDS_LOG_UNATTENDED,
  546. pComp->fUnattended? pInitComponent->SetupData.UnattendFile : NULL,
  547. NULL,
  548. (DWORD const *) &pComp->fUnattended);
  549. if (pComp->fUnattended)
  550. {
  551. pComp->pwszUnattendedFile = (WCHAR *) LocalAlloc(
  552. LMEM_FIXED,
  553. (wcslen(pInitComponent->SetupData.UnattendFile) + 1) *
  554. sizeof(WCHAR));
  555. _JumpIfOutOfMemory(hr, error, pComp->pwszUnattendedFile);
  556. wcscpy(
  557. pComp->pwszUnattendedFile,
  558. pInitComponent->SetupData.UnattendFile);
  559. }
  560. // initialize ca setup data
  561. hr = InitCASetup(hwnd, pComp);
  562. _JumpIfError(hr, error, "InitCASetup");
  563. hr = S_OK;
  564. *pulpRet = NO_ERROR;
  565. error:
  566. if (NULL != hkey)
  567. {
  568. RegCloseKey(hkey);
  569. }
  570. if (fCoInit)
  571. {
  572. CoUninitialize();
  573. }
  574. return(hr);
  575. }
  576. HRESULT
  577. certocmReadInfString(
  578. IN HINF hInf,
  579. IN WCHAR const *pwszSection,
  580. IN WCHAR const *pwszName,
  581. IN OUT WCHAR **ppwszValue)
  582. {
  583. INFCONTEXT InfContext;
  584. HRESULT hr;
  585. WCHAR wszBuffer[cwcINFVALUE];
  586. WCHAR *pwsz;
  587. if (NULL != *ppwszValue)
  588. {
  589. // free old
  590. LocalFree(*ppwszValue);
  591. *ppwszValue = NULL;
  592. }
  593. if (!SetupFindFirstLine(hInf, pwszSection, pwszName, &InfContext))
  594. {
  595. hr = myHLastError();
  596. _JumpErrorStr(hr, error, "SetupFindFirstLine", pwszSection);
  597. }
  598. if (!SetupGetStringField(
  599. &InfContext,
  600. 1,
  601. wszBuffer,
  602. sizeof(wszBuffer)/sizeof(wszBuffer[0]),
  603. NULL))
  604. {
  605. hr = myHLastError();
  606. _JumpErrorStr(hr, error, "SetupGetStringField", pwszName);
  607. }
  608. pwsz = (WCHAR *) LocalAlloc(
  609. LMEM_FIXED,
  610. (wcslen(wszBuffer) + 1) * sizeof(WCHAR));
  611. _JumpIfOutOfMemory(hr, error, pwsz);
  612. wcscpy(pwsz, wszBuffer);
  613. *ppwszValue = pwsz;
  614. hr = S_OK;
  615. error:
  616. return(hr);
  617. }
  618. HRESULT
  619. certocmReadInfInteger(
  620. IN HINF hInf,
  621. OPTIONAL IN WCHAR const *DBGPARMREFERENCED(pwszFile),
  622. IN WCHAR const *pwszSection,
  623. IN WCHAR const *pwszName,
  624. OUT INT *pValue)
  625. {
  626. INFCONTEXT InfContext;
  627. HRESULT hr = S_OK;
  628. *pValue = 0;
  629. if (!SetupFindFirstLine(hInf, pwszSection, pwszName, &InfContext))
  630. {
  631. hr = myHLastError();
  632. DBGPRINT((
  633. DBG_SS_CERTOCMI,
  634. __FILE__ "(%u): %ws%wsSetupFindFirstLine([%ws] %ws) failed! -> %x\n",
  635. __LINE__,
  636. NULL != pwszFile? pwszFile : L"",
  637. NULL != pwszFile? L": " : L"",
  638. pwszSection,
  639. pwszName,
  640. hr));
  641. goto error;
  642. }
  643. if (!SetupGetIntField(&InfContext, 1, pValue))
  644. {
  645. hr = myHLastError();
  646. DBGPRINT((
  647. DBG_SS_CERTOCM,
  648. __FILE__ "(%u): %ws%wsSetupGetIntField([%ws] %ws) failed! -> %x\n",
  649. __LINE__,
  650. NULL != pwszFile? pwszFile : L"",
  651. NULL != pwszFile? L": " : L"",
  652. pwszSection,
  653. pwszName,
  654. hr));
  655. goto error;
  656. }
  657. DBGPRINT((
  658. DBG_SS_CERTOCMI,
  659. "%ws%ws[%ws] %ws = %u\n",
  660. NULL != pwszFile? pwszFile : L"",
  661. NULL != pwszFile? L": " : L"",
  662. pwszSection,
  663. pwszName,
  664. *pValue));
  665. error:
  666. return(hr);
  667. }
  668. // Return the GDI handle of a small bitmap to be used. NULL means an error
  669. // occurred -- OCM will use a default bitmap.
  670. //
  671. // Demonstrates use of private data in a per-component inf. We will look in
  672. // our per-component inf to determine the resource name for the bitmap for this
  673. // component, and then go fetch it from the resources.
  674. //
  675. // Other possibilities would be to simply return the same hbitmap for all
  676. // cases, or to return NULL, in which case OCM uses a default. Note that we
  677. // ignore the requested width and height and our bitmaps are not language
  678. // dependent.
  679. HRESULT
  680. certocmOcQueryImage(
  681. IN WCHAR const *DBGPARMREFERENCED(pwszComponent),
  682. OPTIONAL IN WCHAR const *DBGPARMREFERENCED(pwszSubComponent),
  683. IN SubComponentInfo wSubComp,
  684. IN UINT DBGPARMREFERENCED(wWidth),
  685. IN UINT DBGPARMREFERENCED(wHeight),
  686. IN OUT PER_COMPONENT_DATA *pComp,
  687. OUT HBITMAP *pulpRet)
  688. {
  689. HBITMAP hRet = NULL;
  690. HRESULT hr;
  691. DBGPRINT((
  692. DBG_SS_CERTOCMI,
  693. "OC_QUERY_IMAGE(%ws, %ws, %hx, %x, %x)\n",
  694. pwszComponent,
  695. pwszSubComponent,
  696. wSubComp,
  697. wWidth,
  698. wHeight));
  699. if (SubCompInfoSmallIcon != wSubComp)
  700. {
  701. goto done;
  702. }
  703. hRet = LoadBitmap(pComp->hInstance, MAKEINTRESOURCE(IDB_APP));
  704. if (NULL == hRet)
  705. {
  706. hr = myHLastError();
  707. _JumpError(hr, error, "LoadBitmap");
  708. }
  709. done:
  710. hr = S_OK;
  711. error:
  712. *pulpRet = hRet;
  713. return hr;
  714. }
  715. // Return the number of wizard pages the current component places in the
  716. // SETUP_REQUEST_PAGES structure.
  717. HRESULT
  718. certocmOcRequestPages(
  719. IN WCHAR const *DBGPARMREFERENCED(pwszComponent),
  720. IN WizardPagesType WizPagesType,
  721. IN OUT SETUP_REQUEST_PAGES *pRequestPages,
  722. IN PER_COMPONENT_DATA *pComp,
  723. OUT ULONG_PTR *pulpRet)
  724. {
  725. HRESULT hr;
  726. *pulpRet = 0;
  727. DBGPRINT((
  728. DBG_SS_CERTOCMI,
  729. "OC_REQUEST_PAGES(%ws, %x, %p)\n",
  730. pwszComponent,
  731. WizPagesType,
  732. pRequestPages));
  733. // don't invoke wiz apge if unattended
  734. // or if running from base setup/upgrade setup
  735. if ((!pComp->fUnattended) && (SETUPOP_STANDALONE & pComp->Flags))
  736. {
  737. *pulpRet = myDoPageRequest(pComp,
  738. WizPagesType, pRequestPages);
  739. }
  740. else
  741. {
  742. DBGPRINT((
  743. DBG_SS_CERTOCMI,
  744. "Not adding wizard pages, %ws\n",
  745. pComp->fUnattended? L"Unattended" : L"GUI Setup"));
  746. }
  747. hr = S_OK;
  748. //error:
  749. return hr;
  750. }
  751. HRESULT
  752. IsIA5DnsMachineName()
  753. {
  754. WCHAR *pwszDnsName = NULL;
  755. CRL_DIST_POINTS_INFO CRLDistInfo;
  756. CRL_DIST_POINT DistPoint;
  757. CERT_ALT_NAME_ENTRY AltNameEntry;
  758. BYTE *pbEncoded = NULL;
  759. DWORD cbEncoded;
  760. static HRESULT s_hr = S_FALSE;
  761. if (S_FALSE != s_hr)
  762. {
  763. goto error;
  764. }
  765. s_hr = myGetMachineDnsName(&pwszDnsName);
  766. _JumpIfError(s_hr, error, "myGetMachineDnsName");
  767. CRLDistInfo.cDistPoint = 1;
  768. CRLDistInfo.rgDistPoint = &DistPoint;
  769. ZeroMemory(&DistPoint, sizeof(DistPoint));
  770. DistPoint.DistPointName.dwDistPointNameChoice = CRL_DIST_POINT_FULL_NAME;
  771. DistPoint.DistPointName.FullName.cAltEntry = 1;
  772. DistPoint.DistPointName.FullName.rgAltEntry = &AltNameEntry;
  773. ZeroMemory(&AltNameEntry, sizeof(AltNameEntry));
  774. AltNameEntry.dwAltNameChoice = CERT_ALT_NAME_URL;
  775. AltNameEntry.pwszURL = pwszDnsName;
  776. if (!myEncodeObject(
  777. X509_ASN_ENCODING,
  778. X509_CRL_DIST_POINTS,
  779. &CRLDistInfo,
  780. 0,
  781. CERTLIB_USE_LOCALALLOC,
  782. &pbEncoded,
  783. &cbEncoded))
  784. {
  785. s_hr = myHLastError();
  786. _JumpIfError(s_hr, error, "myEncodeObject");
  787. }
  788. CSASSERT(S_OK == s_hr);
  789. error:
  790. if (NULL != pwszDnsName)
  791. {
  792. LocalFree(pwszDnsName);
  793. }
  794. if (NULL != pbEncoded)
  795. {
  796. LocalFree(pbEncoded);
  797. }
  798. return(s_hr);
  799. }
  800. // Return boolean to indicate whether to allow selection state change. As
  801. // demonstrated, again we'll go out to our per-component inf to see whether it
  802. // wants us to validate. Note that unattended mode must be respected.
  803. HRESULT
  804. certocmOcQueryChangeSelState(
  805. HWND hwnd,
  806. IN WCHAR const *pwszComponent,
  807. OPTIONAL IN WCHAR const *pwszSubComponent,
  808. IN BOOL fSelectedNew,
  809. IN DWORD Flags,
  810. IN OUT PER_COMPONENT_DATA *pComp,
  811. OUT ULONG_PTR *pulpRet)
  812. {
  813. INT fVerify;
  814. TCHAR wszText[cwcMESSAGETEXT];
  815. const WCHAR* Args[2];
  816. SUBCOMP const *psc;
  817. HRESULT hr;
  818. WCHAR awc[cwcDWORDSPRINTF];
  819. WCHAR awc2[cwcDWORDSPRINTF];
  820. DWORD fRet;
  821. BOOL fServerWasInstalled;
  822. BOOL fWebClientWasInstalled;
  823. int iMsg = 0;
  824. static BOOL s_fWarned = FALSE;
  825. *pulpRet = FALSE;
  826. DBGPRINT((
  827. DBG_SS_CERTOCMI,
  828. "OC_QUERY_CHANGE_SEL_STATE(%ws, %ws, %x, %x)\n",
  829. pwszComponent,
  830. pwszSubComponent,
  831. fSelectedNew,
  832. Flags));
  833. // disallow some selection changes
  834. fServerWasInstalled = certocmWasEnabled(pComp, cscServer);
  835. fWebClientWasInstalled = certocmWasEnabled(pComp, cscClient);
  836. if (fWebClientWasInstalled &&
  837. (OCQ_ACTUAL_SELECTION & Flags))
  838. {
  839. if (fSelectedNew)
  840. {
  841. // check
  842. if (!fServerWasInstalled &&
  843. (0 == LSTRCMPIS(pwszSubComponent, wszSERVERSECTION) ||
  844. 0 == LSTRCMPIS(pwszSubComponent, wszCERTSRVSECTION)) )
  845. {
  846. // case: web client installed and try install server
  847. iMsg = IDS_WRN_UNINSTALL_CLIENT;
  848. }
  849. if (fServerWasInstalled &&
  850. 0 == LSTRCMPIS(pwszSubComponent, wszCLIENTSECTION))
  851. {
  852. // case: uncheck both then check web client
  853. iMsg = IDS_WRN_UNINSTALL_BOTH;
  854. }
  855. }
  856. else
  857. {
  858. // uncheck
  859. if (fServerWasInstalled &&
  860. 0 == LSTRCMPIS(pwszSubComponent, wszSERVERSECTION))
  861. {
  862. // case: full certsrv installed and try leave only web client
  863. iMsg = IDS_WRN_UNINSTALL_BOTH;
  864. }
  865. }
  866. }
  867. // not a server sku
  868. if (!FIsServer())
  869. {
  870. iMsg = IDS_WRN_SERVER_ONLY;
  871. }
  872. if (0 != iMsg)
  873. {
  874. CertWarningMessageBox(
  875. pComp->hInstance,
  876. pComp->fUnattended,
  877. hwnd,
  878. iMsg,
  879. 0,
  880. NULL);
  881. goto done;
  882. }
  883. if (fSelectedNew)
  884. {
  885. hr = IsIA5DnsMachineName();
  886. if (S_OK != hr)
  887. {
  888. CertMessageBox(
  889. pComp->hInstance,
  890. pComp->fUnattended,
  891. hwnd,
  892. IDS_ERR_NONIA5DNSNAME,
  893. hr,
  894. MB_OK | MB_ICONERROR,
  895. NULL);
  896. goto done;
  897. }
  898. if ((OCQ_ACTUAL_SELECTION & Flags) &&
  899. 0 != LSTRCMPIS(pwszSubComponent, wszCLIENTSECTION))
  900. {
  901. if (!s_fWarned)
  902. {
  903. DWORD dwSetupStatus;
  904. hr = GetSetupStatus(NULL, &dwSetupStatus);
  905. if (S_OK == hr)
  906. {
  907. if ((SETUP_CLIENT_FLAG | SETUP_SERVER_FLAG) & dwSetupStatus)
  908. {
  909. s_fWarned = TRUE;
  910. }
  911. CSILOG(
  912. hr,
  913. IDS_LOG_QUERYCHANGESELSTATE,
  914. NULL,
  915. NULL,
  916. &dwSetupStatus);
  917. }
  918. }
  919. if (!s_fWarned)
  920. {
  921. if (IDYES != CertMessageBox(
  922. pComp->hInstance,
  923. pComp->fUnattended,
  924. hwnd,
  925. IDS_WRN_NONAMECHANGE,
  926. S_OK,
  927. MB_YESNO | MB_ICONWARNING | CMB_NOERRFROMSYS,
  928. NULL))
  929. {
  930. goto done;
  931. }
  932. s_fWarned = TRUE;
  933. }
  934. }
  935. }
  936. *pulpRet = TRUE;
  937. if (pComp->fUnattended)
  938. {
  939. goto done;
  940. }
  941. psc = TranslateSubComponent(pwszComponent, pwszSubComponent);
  942. if (NULL == psc)
  943. {
  944. hr = E_INVALIDARG;
  945. _JumpError(hr, error, "Internal error: unsupported component");
  946. }
  947. hr = certocmReadInfInteger(
  948. pComp->MyInfHandle,
  949. NULL,
  950. psc->pwszSubComponent,
  951. fSelectedNew? wszVERIFYSELECT : wszVERIFYDESELECT,
  952. &fVerify);
  953. if (S_OK != hr || !fVerify)
  954. {
  955. goto done;
  956. }
  957. // Don't pass specific lang id to FormatMessage, as it fails if there's no
  958. // msg in that language. Instead, set the thread locale, which will get
  959. // FormatMessage to use a search algorithm to find a message of the
  960. // appropriate language, or use a reasonable fallback msg if there's none.
  961. Args[0] = pwszComponent;
  962. Args[1] = pwszSubComponent;
  963. FormatMessage(
  964. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  965. pComp->hInstance,
  966. fSelectedNew? MSG_SURE_SELECT : MSG_SURE_DESELECT,
  967. 0,
  968. wszText,
  969. sizeof(wszText)/sizeof(wszText[0]),
  970. (va_list *) Args);
  971. *pulpRet = (IDYES == CertMessageBox(
  972. pComp->hInstance,
  973. pComp->fUnattended,
  974. hwnd,
  975. 0,
  976. S_OK,
  977. MB_YESNO |
  978. MB_ICONWARNING |
  979. MB_TASKMODAL |
  980. CMB_NOERRFROMSYS,
  981. wszText));
  982. done:
  983. hr = S_OK;
  984. error:
  985. wsprintf(awc, L"%u", fSelectedNew);
  986. wsprintf(awc2, L"0x%08x", Flags);
  987. fRet = (DWORD) *pulpRet;
  988. CSILOG(hr, IDS_LOG_QUERYCHANGESELSTATE, awc, awc2, &fRet);
  989. return hr;
  990. }
  991. // Calculate disk space for the component being added or removed. Return a
  992. // Win32 error code indicating outcome. In our case the private section for
  993. // this component/subcomponent pair is a simple standard inf install section,
  994. // so we can use high-level disk space list API to do what we want.
  995. HRESULT
  996. certocmOcCalcDiskSpace(
  997. IN WCHAR const *pwszComponent,
  998. OPTIONAL IN WCHAR const *pwszSubComponent,
  999. IN BOOL fAddComponent,
  1000. IN HDSKSPC hDiskSpace,
  1001. IN OUT PER_COMPONENT_DATA *pComp,
  1002. OUT ULONG_PTR *pulpRet)
  1003. {
  1004. HRESULT hr;
  1005. WCHAR *pwsz = NULL;
  1006. SUBCOMP const *psc;
  1007. static fServerFirstCall = TRUE;
  1008. static fClientFirstCall = TRUE;
  1009. DBGPRINT((
  1010. DBG_SS_CERTOCMI,
  1011. "OC_CALC_DISK_SPACE(%ws, %ws, %x, %p)\n",
  1012. pwszComponent,
  1013. pwszSubComponent,
  1014. fAddComponent,
  1015. hDiskSpace));
  1016. psc = TranslateSubComponent(pwszComponent, pwszSubComponent);
  1017. if (NULL == psc)
  1018. {
  1019. hr = E_INVALIDARG;
  1020. _JumpError(hr, error, "Internal error: unsupported component");
  1021. }
  1022. // Being installed or uninstalled. Fetch INSTALL section name,
  1023. // so we can add or remove the files being INSTALLed from the disk
  1024. // space list.
  1025. hr = certocmReadInfString(
  1026. pComp->MyInfHandle,
  1027. psc->pwszSubComponent,
  1028. wszINSTALL,
  1029. &pwsz);
  1030. _JumpIfError(hr, error, "certocmReadInfString");
  1031. if (fAddComponent) // Adding
  1032. {
  1033. if (!SetupAddInstallSectionToDiskSpaceList(
  1034. hDiskSpace,
  1035. pComp->MyInfHandle,
  1036. NULL,
  1037. pwsz,
  1038. 0,
  1039. 0))
  1040. {
  1041. hr = myHLastError();
  1042. _JumpErrorStr(hr, error, "SetupAddInstallSectionToDiskSpaceList", pwsz);
  1043. }
  1044. }
  1045. else // Removing
  1046. {
  1047. if (!SetupRemoveInstallSectionFromDiskSpaceList(
  1048. hDiskSpace,
  1049. pComp->MyInfHandle,
  1050. NULL,
  1051. pwsz,
  1052. 0,
  1053. 0))
  1054. {
  1055. hr = myHLastError();
  1056. _JumpErrorStr(hr, error, "SetupRemoveInstallSectionFromDiskSpaceList", pwsz);
  1057. }
  1058. }
  1059. hr = S_OK;
  1060. error:
  1061. if (NULL != pwsz)
  1062. {
  1063. LocalFree(pwsz);
  1064. }
  1065. *pulpRet = hr;
  1066. return(hr);
  1067. }
  1068. // OCM calls this routine when ready for files to be copied to effect the
  1069. // changes the user requested. The component DLL must figure out whether it is
  1070. // being installed or uninstalled and take appropriate action. For this
  1071. // sample, we look in the private data section for this component/subcomponent
  1072. // pair, and get the name of an uninstall section for the uninstall case.
  1073. //
  1074. // Note that OCM calls us once for the *entire* component and then once per
  1075. // subcomponent. We ignore the first call.
  1076. //
  1077. // Return value is Win32 error code indicating outcome.
  1078. HRESULT
  1079. certocmOcQueueFileOps(
  1080. IN HWND hwnd,
  1081. IN WCHAR const *pwszComponent,
  1082. OPTIONAL IN WCHAR const *pwszSubComponent,
  1083. IN HSPFILEQ hFileQueue,
  1084. IN OUT PER_COMPONENT_DATA *pComp,
  1085. OUT ULONG_PTR *pulpRet)
  1086. {
  1087. HRESULT hr;
  1088. SUBCOMP const *psc;
  1089. BOOL fRemoveFile = FALSE; // TRUE for uninstall; FALSE for install/upgrade
  1090. WCHAR *pwszAction;
  1091. WCHAR *pwsz = NULL;
  1092. static BOOL s_fPreUninstall = FALSE; // preuninstall once
  1093. DBGPRINT((
  1094. DBG_SS_CERTOCMI,
  1095. "OC_QUEUE_FILE_OPS(%ws, %ws, %p)\n",
  1096. pwszComponent,
  1097. pwszSubComponent,
  1098. hFileQueue));
  1099. if (NULL == pwszSubComponent)
  1100. {
  1101. // Do no work for top level component
  1102. goto done;
  1103. }
  1104. psc = TranslateSubComponent(pwszComponent, pwszSubComponent);
  1105. if (NULL == psc)
  1106. {
  1107. hr = E_INVALIDARG;
  1108. _JumpError(hr, error, "Internal error: unsupported component");
  1109. }
  1110. // if unattended, not upgrade, & not uninstall, load
  1111. if (pComp->fUnattended && !(pComp->Flags & SETUPOP_NTUPGRADE) )
  1112. {
  1113. // retrieve unattended attributes
  1114. hr = certocmRetrieveUnattendedText(
  1115. pwszComponent,
  1116. pwszSubComponent,
  1117. pComp);
  1118. if (S_OK != hr && 0x0 != (pComp->Flags & SETUPOP_STANDALONE))
  1119. {
  1120. // only error out if it is from add/remove or post because
  1121. // it could fail regular ntbase in unattended mode without certsrv
  1122. _JumpError(hr, error, "certocmRetrieveUnattendedText");
  1123. }
  1124. // Init install status (must be done after retrieving unattended text)
  1125. hr = UpdateSubComponentInstallStatus(pwszComponent,
  1126. pwszSubComponent,
  1127. pComp);
  1128. _JumpIfError(hr, error, "UpdateSubComponentInstallStatus");
  1129. if (psc->fInstallUnattend) // make sure ON
  1130. {
  1131. if (certocmWasEnabled(pComp, psc->cscSubComponent) &&
  1132. !pComp->fPostBase)
  1133. {
  1134. // the case to run install with component ON twice or more
  1135. hr = HRESULT_FROM_WIN32(ERROR_INVALID_STATE);
  1136. _JumpError(hr, error, "You must uninstall before install");
  1137. }
  1138. if (SETUPOP_STANDALONE & pComp->Flags)
  1139. {
  1140. // only prepare and validate unattende attr in standalone mode
  1141. // in other word, don't call following if NT base
  1142. hr = PrepareUnattendedAttributes(
  1143. hwnd,
  1144. pwszComponent,
  1145. pwszSubComponent,
  1146. pComp);
  1147. _JumpIfError(hr, error, "PrepareUnattendedAttributes");
  1148. }
  1149. }
  1150. }
  1151. else
  1152. {
  1153. // Initialize the install status
  1154. hr = UpdateSubComponentInstallStatus(pwszComponent,
  1155. pwszSubComponent,
  1156. pComp);
  1157. _JumpIfError(hr, error, "UpdateSubComponentInstallStatus");
  1158. }
  1159. // If we're not doing base setup or an upgrade, check to see if we already
  1160. // copied files during base setup, by checking to see if base setup
  1161. // left an entry in the ToDo List.
  1162. if(pComp->fPostBase)
  1163. {
  1164. DBGPRINT((
  1165. DBG_SS_CERTOCMI,
  1166. "File Queueing Skipped, files already installed by GUI setup"));
  1167. goto done;
  1168. }
  1169. /*
  1170. //--- Talk with OCM guys and put this functionality into a notification routine
  1171. //--- This will allow us to pop compatibility error to user before unattended upgrade begins
  1172. // detect illegal upgrade
  1173. if (pComp->dwInstallStatus & IS_SERVER_UPGRADE)
  1174. {
  1175. hr = DetermineServerUpgradePath(pComp);
  1176. _JumpIfError(hr, error, "DetermineServerUpgradePath");
  1177. }
  1178. else if (pComp->dwInstallStatus & IS_CLIENT_UPGRADE)
  1179. {
  1180. hr = DetermineClientUpgradePath(pComp);
  1181. _JumpIfError(hr, error, "LoadAndDetermineClientUpgradeInfo");
  1182. }
  1183. if ((pComp->dwInstallStatus & IS_SERVER_UPGRADE) ||
  1184. (pComp->dwInstallStatus & IS_CLIENT_UPGRADE))
  1185. {
  1186. // block if attempting upgrade that is not Win2K or Whistler
  1187. // lodge a complaint in the log; upgrade all bits and
  1188. if ((CS_UPGRADE_NO != pComp->UpgradeFlag) &&
  1189. (CS_UPGRADE_WHISTLER != pComp->UpgradeFlag) &&
  1190. (CS_UPGRADE_WIN2000 != pComp->UpgradeFlag))
  1191. {
  1192. hr = HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION);
  1193. CertErrorMessageBox(
  1194. pComp->hInstance,
  1195. pComp->fUnattended,
  1196. hwnd,
  1197. IDS_ERR_UPGRADE_NOT_SUPPORTED,
  1198. hr,
  1199. NULL);
  1200. // _JumpError(hr, error, "Unsupported upgrade");
  1201. // continue uninstall/reinstall
  1202. }
  1203. }
  1204. */
  1205. if ((pComp->dwInstallStatus & psc->ChangeFlags) ||
  1206. (pComp->dwInstallStatus & psc->UpgradeFlags) )
  1207. {
  1208. // for ChangeFlags, either install or uninstall
  1209. // all cases, copy file or remove file
  1210. if (pComp->dwInstallStatus & psc->UninstallFlags)
  1211. {
  1212. fRemoveFile = TRUE;
  1213. }
  1214. // Uninstall the core if:
  1215. // this subcomponent is being uninstalled, and
  1216. // this is a core subcomponent (client or server), and
  1217. // this is the server subcomponent, or the server isn't being removed or
  1218. // upgrade
  1219. if (((pComp->dwInstallStatus & psc->UninstallFlags) ||
  1220. (pComp->dwInstallStatus & psc->UpgradeFlags) ) &&
  1221. (cscServer == psc->cscSubComponent ||
  1222. !(IS_SERVER_REMOVE & pComp->dwInstallStatus) ) )
  1223. {
  1224. // if fall into here, either need to overwrite or
  1225. // delete certsrv files so unreg all related dlls
  1226. if (cscServer == psc->cscSubComponent &&
  1227. (pComp->dwInstallStatus & psc->UpgradeFlags) )
  1228. {
  1229. // if this is server upgrade, determine upgrade path
  1230. hr = DetermineServerUpgradePath(pComp);
  1231. _JumpIfError(hr, error, "DetermineServerUpgradePath");
  1232. // determine custom policy module
  1233. hr = DetermineServerCustomModule(
  1234. pComp,
  1235. TRUE); // policy
  1236. _JumpIfError(hr, error, "DetermineServerCustomModule");
  1237. // determine custom exit module
  1238. hr = DetermineServerCustomModule(
  1239. pComp,
  1240. FALSE); // exit
  1241. _JumpIfError(hr, error, "DetermineServerCustomModule");
  1242. }
  1243. if (!s_fPreUninstall)
  1244. {
  1245. hr = PreUninstallCore(hwnd, pComp);
  1246. _JumpIfError(hr, error, "PreUninstallCore");
  1247. s_fPreUninstall = TRUE;
  1248. }
  1249. }
  1250. if ((pComp->dwInstallStatus & psc->ChangeFlags) ||
  1251. (pComp->dwInstallStatus & psc->UpgradeFlags) )
  1252. {
  1253. // Being installed or uninstalled.
  1254. // Fetch [un]install/upgrade section name.
  1255. if (pComp->dwInstallStatus & psc->InstallFlags)
  1256. {
  1257. pwszAction = wszINSTALL;
  1258. }
  1259. else if (pComp->dwInstallStatus & psc->UninstallFlags)
  1260. {
  1261. pwszAction = wszUNINSTALL;
  1262. }
  1263. else if (pComp->dwInstallStatus & psc->UpgradeFlags)
  1264. {
  1265. pwszAction = wszUPGRADE;
  1266. }
  1267. else
  1268. {
  1269. hr = E_INVALIDARG;
  1270. _JumpError(hr, error, "Internal error");
  1271. }
  1272. hr = certocmReadInfString(
  1273. pComp->MyInfHandle,
  1274. psc->pwszSubComponent,
  1275. pwszAction,
  1276. &pwsz);
  1277. _JumpIfError(hr, error, "certocmReadInfString");
  1278. // If uninstalling, copy files without version checks.
  1279. if (!SetupInstallFilesFromInfSection(
  1280. pComp->MyInfHandle,
  1281. NULL,
  1282. hFileQueue,
  1283. pwsz,
  1284. NULL,
  1285. fRemoveFile? 0 : SP_COPY_NEWER))
  1286. {
  1287. hr = myHLastError();
  1288. _JumpIfError(hr, error, "SetupInstallFilesFromInfSection");
  1289. }
  1290. }
  1291. }
  1292. done:
  1293. hr = S_OK;
  1294. error:
  1295. if (NULL != pwsz)
  1296. {
  1297. LocalFree(pwsz);
  1298. }
  1299. if (S_OK != hr)
  1300. {
  1301. SetLastError(hr);
  1302. }
  1303. *pulpRet = hr;
  1304. return(hr);
  1305. }
  1306. // OCM calls this routine when it wants to find out how much work the component
  1307. // wants to perform for nonfile operations to install/uninstall a component or
  1308. // subcomponent. It is called once for the *entire* component and then once
  1309. // for each subcomponent in the component. One could get arbitrarily fancy
  1310. // here but we simply return 1 step per subcomponent. We ignore the "entire
  1311. // component" case.
  1312. //
  1313. // Return value is an arbitrary 'step' count or -1 if error.
  1314. HRESULT
  1315. certocmOcQueryStepCount(
  1316. IN WCHAR const *DBGPARMREFERENCED(pwszComponent),
  1317. OPTIONAL IN WCHAR const *pwszSubComponent,
  1318. OUT ULONG_PTR *pulpRet)
  1319. {
  1320. HRESULT hr;
  1321. *pulpRet = 0;
  1322. DBGPRINT((
  1323. DBG_SS_CERTOCMI,
  1324. "OC_QUERY_STEP_COUNT(%ws, %ws)\n",
  1325. pwszComponent,
  1326. pwszSubComponent));
  1327. // Ignore all but "entire component" case.
  1328. if (NULL != pwszSubComponent)
  1329. {
  1330. goto done;
  1331. }
  1332. *pulpRet = SERVERINSTALLTICKS;
  1333. done:
  1334. hr = S_OK;
  1335. //error:
  1336. return hr;
  1337. }
  1338. // OCM calls this routine when it wants the component dll to perform nonfile
  1339. // ops to install/uninstall a component/subcomponent. It is called once for
  1340. // the *entire* component and then once for each subcomponent in the component.
  1341. // Our install and uninstall actions are based on simple standard inf install
  1342. // sections. We ignore the "entire component" case. Note how similar this
  1343. // code is to the OC_QUEUE_FILE_OPS case.
  1344. HRESULT
  1345. certocmOcCompleteInstallation(
  1346. IN HWND hwnd,
  1347. IN WCHAR const *pwszComponent,
  1348. OPTIONAL IN WCHAR const *pwszSubComponent,
  1349. IN OUT PER_COMPONENT_DATA *pComp,
  1350. OUT ULONG_PTR *pulpRet)
  1351. {
  1352. HRESULT hr;
  1353. TCHAR wszBuffer[cwcINFVALUE];
  1354. SUBCOMP const *psc;
  1355. DWORD dwSetupStatusFlags;
  1356. CASERVERSETUPINFO *pServer = pComp->CA.pServer;
  1357. WCHAR *pwszActiveCA = NULL;
  1358. static BOOL fStoppedW3SVC = FALSE;
  1359. *pulpRet = 0;
  1360. DBGPRINT((
  1361. DBG_SS_CERTOCMI,
  1362. "OC_COMPLETE_INSTALLATION(%ws, %ws)\n",
  1363. pwszComponent,
  1364. pwszSubComponent));
  1365. // Do no work for top level component
  1366. if (NULL == pwszSubComponent)
  1367. {
  1368. goto done;
  1369. }
  1370. psc = TranslateSubComponent(pwszComponent, pwszSubComponent);
  1371. if (NULL == psc)
  1372. {
  1373. hr = E_INVALIDARG;
  1374. _JumpError(hr, error, "Internal error: unsupported component");
  1375. }
  1376. if (pComp->dwInstallStatus & IS_SERVER_REMOVE)
  1377. {
  1378. // for uninstall, check if active ca use DS
  1379. hr = myGetCertRegStrValue(NULL, NULL, NULL,
  1380. wszREGACTIVE, &pwszActiveCA);
  1381. if (S_OK == hr && NULL != pwszActiveCA)
  1382. {
  1383. hr = myGetCertRegDWValue(pwszActiveCA, NULL, NULL,
  1384. wszREGCAUSEDS, (DWORD*)&pServer->fUseDS);
  1385. _PrintIfError(hr, "myGetCertRegDWValue");
  1386. }
  1387. }
  1388. DBGPRINT((
  1389. DBG_SS_CERTOCMI,
  1390. "certocmOcCompleteInstallation: pComp->dwInstallStatus: %lx, pComp->Flags: %lx\n",
  1391. pComp->dwInstallStatus,
  1392. pComp->Flags));
  1393. if ((pComp->dwInstallStatus & psc->ChangeFlags) ||
  1394. (pComp->dwInstallStatus & psc->UpgradeFlags) )
  1395. {
  1396. // for unattended, make sure w3svc is stopped before file copy
  1397. if (!fStoppedW3SVC &&
  1398. pComp->fUnattended &&
  1399. !(pComp->Flags & SETUPOP_NTUPGRADE) &&
  1400. !(pComp->dwInstallStatus & psc->UninstallFlags) )
  1401. {
  1402. //fStoppedW3SVC makes stop only once
  1403. //don't do this in upgrade
  1404. // this happens for unattended
  1405. // also not during uninstall
  1406. hr = StartAndStopService(pComp->hInstance,
  1407. pComp->fUnattended,
  1408. hwnd,
  1409. wszW3SVCNAME,
  1410. TRUE,
  1411. FALSE,
  1412. 0, // doesn't matter since no confirmation
  1413. &g_fW3SvcRunning);
  1414. _PrintIfError(hr, "StartAndStopService");
  1415. fStoppedW3SVC = TRUE;
  1416. }
  1417. // certsrv file copy
  1418. if (!SetupInstallFromInfSection(
  1419. NULL,
  1420. pComp->MyInfHandle,
  1421. wszBuffer,
  1422. SPINST_INIFILES | SPINST_REGISTRY,
  1423. NULL,
  1424. NULL,
  1425. 0,
  1426. NULL,
  1427. NULL,
  1428. NULL,
  1429. NULL))
  1430. {
  1431. hr = myHLastError();
  1432. _JumpError(hr, error, "SetupInstallFromInfSection");
  1433. }
  1434. // Finish uninstalling the core if:
  1435. // this subcomponent is being uninstalled, and
  1436. // this is a core subcomponent (client or server), and
  1437. // this is the server subcomponent, or the server isn't being removed.
  1438. if ( (pComp->dwInstallStatus & psc->UninstallFlags) &&
  1439. (cscServer == psc->cscSubComponent ||
  1440. !(IS_SERVER_REMOVE & pComp->dwInstallStatus) ) )
  1441. {
  1442. // Do uninstall work
  1443. hr = UninstallCore(
  1444. hwnd,
  1445. pComp,
  1446. 0,
  1447. 100,
  1448. certocmPreserving(pComp, cscClient),
  1449. TRUE,
  1450. FALSE);
  1451. _JumpIfError(hr, error, "UninstallCore");
  1452. if (certocmPreserving(pComp, cscClient))
  1453. {
  1454. hr = SetSetupStatus(NULL, SETUP_CLIENT_FLAG, TRUE);
  1455. _JumpIfError(hr, error, "SetSetupStatus");
  1456. }
  1457. else
  1458. {
  1459. // unmark all
  1460. hr = SetSetupStatus(NULL, 0xFFFFFFFF, FALSE);
  1461. _JumpIfError(hr, error, "SetSetupStatus");
  1462. }
  1463. }
  1464. // Finish installing the core if:
  1465. // this subcomponent is being installed, and
  1466. // this is a core subcomponent (client or server), and
  1467. // this is the server subcomponent, or the server isn't being installed.
  1468. // and this is not base setup (we'll do it later if it is)
  1469. else
  1470. if ((pComp->dwInstallStatus & psc->InstallFlags) &&
  1471. (cscServer == psc->cscSubComponent ||
  1472. !(IS_SERVER_INSTALL & pComp->dwInstallStatus)) &&
  1473. (0 != (pComp->Flags & SETUPOP_STANDALONE)))
  1474. {
  1475. DBGPRINT((
  1476. DBG_SS_CERTOCMI,
  1477. "Performing standalone server installation\n"));
  1478. hr = InstallCore(hwnd, pComp, cscServer == psc->cscSubComponent);
  1479. _JumpIfError(hr, error, "InstallCore");
  1480. // last enough to mark complete
  1481. if (pComp->dwInstallStatus & IS_SERVER_INSTALL)
  1482. {
  1483. // machine
  1484. hr = SetSetupStatus(NULL, SETUP_SERVER_FLAG, TRUE);
  1485. _JumpIfError(hr, error, "SetSetupStatus");
  1486. // ca
  1487. hr = SetSetupStatus(
  1488. pServer->pwszSanitizedName,
  1489. SETUP_SERVER_FLAG,
  1490. TRUE);
  1491. _JumpIfError(hr, error, "SetSetupStatus");
  1492. if(IsEnterpriseCA(pServer->CAType))
  1493. {
  1494. hr = SetSetupStatus(
  1495. pServer->pwszSanitizedName,
  1496. SETUP_UPDATE_CAOBJECT_SVRTYPE,
  1497. TRUE);
  1498. _JumpIfError(hr, error, "SetSetupStatus SETUP_UPDATE_CAOBJECT_SVRTYPE");
  1499. }
  1500. hr = GetSetupStatus(pServer->pwszSanitizedName, &dwSetupStatusFlags);
  1501. _JumpIfError(hr, error, "SetSetupStatus");
  1502. // Only start the server if:
  1503. // 1: we're not waiting for the CA cert to be issued, and
  1504. // 2: this is not base setup -- SETUP_STANDALONE means we're
  1505. // running from the Control Panel or were manually invoked.
  1506. // The server will not start during base setup due to an
  1507. // access denied error from JetInit during base setup.
  1508. if (0 == (SETUP_SUSPEND_FLAG & dwSetupStatusFlags) &&
  1509. (0 != (SETUPOP_STANDALONE & pComp->Flags)))
  1510. {
  1511. hr = StartCertsrvService(FALSE);
  1512. _PrintIfError(hr, "failed in starting cert server service");
  1513. }
  1514. // during base setup: f=0 sus=8
  1515. DBGPRINT((
  1516. DBG_SS_CERTOCMI,
  1517. "InstallCore: f=%x sus=%x\n",
  1518. pComp->Flags,
  1519. dwSetupStatusFlags));
  1520. hr = EnableVRootsAndShares(FALSE, FALSE, TRUE, pComp, hwnd);
  1521. if(REGDB_E_CLASSNOTREG == hr ||
  1522. HRESULT_FROM_WIN32(ERROR_SERVICE_DOES_NOT_EXIST) == hr ||
  1523. HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr)
  1524. {
  1525. CertWarningMessageBox(
  1526. pComp->hInstance,
  1527. pComp->fUnattended,
  1528. hwnd,
  1529. IDS_WRN_IIS_NOT_INSTALLED,
  1530. 0,
  1531. NULL);
  1532. hr = S_OK;
  1533. }
  1534. _JumpIfError(hr, error, "failed creating VRoots/shares");
  1535. }
  1536. if (pComp->dwInstallStatus & IS_CLIENT_INSTALL)
  1537. {
  1538. hr = SetSetupStatus(NULL, SETUP_CLIENT_FLAG, TRUE);
  1539. _JumpIfError(hr, error, "SetSetupStatus");
  1540. }
  1541. if ((pComp->dwInstallStatus & IS_SERVER_INSTALL) &&
  1542. (pComp->dwInstallStatus & IS_CLIENT_INSTALL))
  1543. {
  1544. hr = SetSetupStatus(
  1545. pServer->pwszSanitizedName,
  1546. SETUP_CLIENT_FLAG,
  1547. TRUE);
  1548. _JumpIfError(hr, error, "SetSetupStatus");
  1549. }
  1550. // in case we're doing a post-base setup,
  1551. // we always clear the post-base to-do list
  1552. RegDeleteKey(HKEY_LOCAL_MACHINE, wszREGKEYCERTSRVTODOLIST);
  1553. }
  1554. else
  1555. if ((pComp->dwInstallStatus & psc->InstallFlags) &&
  1556. (cscServer == psc->cscSubComponent ||
  1557. !(IS_SERVER_INSTALL & pComp->dwInstallStatus)) &&
  1558. (0 == (pComp->Flags & (SETUPOP_STANDALONE |
  1559. SETUPOP_WIN31UPGRADE |
  1560. SETUPOP_WIN95UPGRADE |
  1561. SETUPOP_NTUPGRADE) )))
  1562. {
  1563. HKEY hkToDoList = NULL;
  1564. WCHAR *pwszConfigTitleVal = NULL;
  1565. WCHAR *pwszArgsValTemp = NULL;
  1566. WCHAR *pwszArgsVal = wszCONFIGARGSVAL;
  1567. BOOL fFreeTitle = FALSE;
  1568. DWORD disp;
  1569. DWORD err;
  1570. DBGPRINT((
  1571. DBG_SS_CERTOCMI,
  1572. "Adding Certificate Services to ToDoList\n"));
  1573. // We're installing base, so create
  1574. // the ToDoList entry stating that we copied files.
  1575. err = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  1576. wszREGKEYCERTSRVTODOLIST,
  1577. 0,
  1578. NULL,
  1579. 0,
  1580. KEY_ALL_ACCESS,
  1581. NULL,
  1582. &hkToDoList,
  1583. &disp);
  1584. hr = HRESULT_FROM_WIN32(err);
  1585. _JumpIfError(hr, error, "RegCreateKeyEx");
  1586. hr = myLoadRCString(
  1587. g_hInstance,
  1588. IDS_TODO_TITLE,
  1589. &pwszConfigTitleVal);
  1590. if (S_OK == hr)
  1591. {
  1592. fFreeTitle = TRUE;
  1593. }
  1594. else
  1595. {
  1596. // If there was no resource, get something...
  1597. pwszConfigTitleVal = wszCONFIGTITLEVAL;
  1598. }
  1599. // config title
  1600. err = RegSetValueEx(hkToDoList,
  1601. wszCONFIGTITLE,
  1602. 0,
  1603. REG_SZ,
  1604. (PBYTE)pwszConfigTitleVal,
  1605. sizeof(WCHAR)*(wcslen(pwszConfigTitleVal)+1));
  1606. hr = HRESULT_FROM_WIN32(err);
  1607. _PrintIfErrorStr(hr, "RegSetValueEx", wszCONFIGTITLE);
  1608. CSILOG(hr, IDS_LOG_TODOLIST, wszCONFIGTITLE, pwszConfigTitleVal, NULL);
  1609. // config command
  1610. err = RegSetValueEx(hkToDoList,
  1611. wszCONFIGCOMMAND,
  1612. 0,
  1613. REG_SZ,
  1614. (PBYTE)wszCONFIGCOMMANDVAL,
  1615. sizeof(WCHAR)*(wcslen(wszCONFIGCOMMANDVAL)+1));
  1616. hr = HRESULT_FROM_WIN32(err);
  1617. _PrintIfErrorStr(hr, "RegSetValueEx", wszCONFIGCOMMAND);
  1618. CSILOG(hr, IDS_LOG_TODOLIST, wszCONFIGCOMMAND, wszCONFIGCOMMANDVAL, NULL);
  1619. // config args
  1620. if (pComp->fUnattended && NULL != pComp->pwszUnattendedFile)
  1621. {
  1622. // if nt base is in unattended mode, expand args with
  1623. // unattended answer file name
  1624. pwszArgsValTemp = (WCHAR*)LocalAlloc(LMEM_FIXED,
  1625. (wcslen(pwszArgsVal) +
  1626. wcslen(pComp->pwszUnattendedFile) + 5) * sizeof(WCHAR));
  1627. _JumpIfOutOfMemory(hr, error, pwszArgsValTemp);
  1628. wcscpy(pwszArgsValTemp, pwszArgsVal);
  1629. wcscat(pwszArgsValTemp, L" /u:");
  1630. wcscat(pwszArgsValTemp, pComp->pwszUnattendedFile);
  1631. pwszArgsVal = pwszArgsValTemp;
  1632. }
  1633. err = RegSetValueEx(hkToDoList,
  1634. wszCONFIGARGS,
  1635. 0,
  1636. REG_SZ,
  1637. (PBYTE)pwszArgsVal,
  1638. sizeof(WCHAR)*(wcslen(pwszArgsVal)+1));
  1639. hr = HRESULT_FROM_WIN32(err);
  1640. _PrintIfErrorStr(hr, "RegSetValueEx", wszCONFIGARGS);
  1641. CSILOG(hr, IDS_LOG_TODOLIST, wszCONFIGARGS, pwszArgsVal, NULL);
  1642. // free stuff
  1643. if (NULL != pwszConfigTitleVal && fFreeTitle)
  1644. {
  1645. LocalFree(pwszConfigTitleVal);
  1646. }
  1647. if (NULL != pwszArgsValTemp)
  1648. {
  1649. LocalFree(pwszArgsValTemp);
  1650. }
  1651. if (NULL != hkToDoList)
  1652. {
  1653. RegCloseKey(hkToDoList);
  1654. }
  1655. }
  1656. else if (pComp->dwInstallStatus & psc->UpgradeFlags)
  1657. {
  1658. BOOL fFinishCYS;
  1659. hr = CheckPostBaseInstallStatus(&fFinishCYS);
  1660. _JumpIfError(hr, error, "CheckPostBaseInstallStatus");
  1661. // if post mode is true, don't execute setup upgrade path
  1662. if (fFinishCYS)
  1663. {
  1664. BOOL fServer = FALSE;
  1665. // upgrade
  1666. if (cscServer == psc->cscSubComponent)
  1667. {
  1668. hr = UpgradeServer(hwnd, pComp);
  1669. _JumpIfError(hr, error, "UpgradeServer");
  1670. fServer = TRUE;
  1671. }
  1672. else if (cscClient == psc->cscSubComponent)
  1673. {
  1674. hr = UpgradeClient(hwnd, pComp);
  1675. _JumpIfError(hr, error, "UpgradeClient");
  1676. }
  1677. // mark setup status
  1678. hr = SetSetupStatus(NULL, psc->SetupStatusFlags, TRUE);
  1679. _PrintIfError(hr, "SetSetupStatus");
  1680. if (fServer)
  1681. {
  1682. // ca level
  1683. hr = SetSetupStatus(
  1684. pServer->pwszSanitizedName,
  1685. psc->SetupStatusFlags, TRUE);
  1686. _PrintIfError(hr, "SetSetupStatus");
  1687. if(IsEnterpriseCA(pServer->CAType))
  1688. {
  1689. hr = SetSetupStatus(
  1690. pServer->pwszSanitizedName,
  1691. SETUP_UPDATE_CAOBJECT_SVRTYPE,
  1692. TRUE);
  1693. _JumpIfError(hr, error,
  1694. "SetSetupStatus SETUP_UPDATE_CAOBJECT_SVRTYPE");
  1695. }
  1696. }
  1697. if (fServer && pServer->fCertSrvWasRunning)
  1698. {
  1699. hr = StartCertsrvService(TRUE);
  1700. _PrintIfError(hr, "failed in starting cert server service");
  1701. }
  1702. }
  1703. }
  1704. }
  1705. done:
  1706. hr = S_OK;
  1707. error:
  1708. if (NULL != pwszActiveCA)
  1709. {
  1710. LocalFree(pwszActiveCA);
  1711. }
  1712. *pulpRet = hr;
  1713. return(hr);
  1714. }
  1715. HRESULT
  1716. certocmOcCommitQueue(
  1717. IN HWND hwnd,
  1718. IN WCHAR const *pwszComponent,
  1719. IN WCHAR const *pwszSubComponent,
  1720. IN PER_COMPONENT_DATA *pComp)
  1721. {
  1722. HRESULT hr;
  1723. SUBCOMP *pSub;
  1724. CASERVERSETUPINFO *pServer = pComp->CA.pServer;
  1725. DBGPRINT((
  1726. DBG_SS_CERTOCMI,
  1727. "OC_ABOUT_TO_COMMIT_QUEUE(%ws, %ws)\n",
  1728. pwszComponent,
  1729. pwszSubComponent));
  1730. pSub = TranslateSubComponent(pwszComponent, pwszSubComponent);
  1731. if (NULL == pSub)
  1732. {
  1733. goto done;
  1734. }
  1735. // setup will satrt soon, mark it incomplete
  1736. if ((pSub->InstallFlags & pComp->dwInstallStatus) &&
  1737. cscServer == pSub->cscSubComponent)
  1738. {
  1739. hr = SetSetupStatus(NULL, pSub->SetupStatusFlags, FALSE);
  1740. _PrintIfError(hr, "SetSetupStatus");
  1741. hr = SetSetupStatus(
  1742. pServer->pwszSanitizedName,
  1743. pSub->SetupStatusFlags,
  1744. FALSE);
  1745. _PrintIfError(hr, "SetSetupStatus");
  1746. }
  1747. if ((cscServer == pSub->cscSubComponent) &&
  1748. (pSub->UpgradeFlags & pComp->dwInstallStatus) )
  1749. {
  1750. // upgrade case, no UI, stop existing certsrv
  1751. hr = StartAndStopService(pComp->hInstance,
  1752. pComp->fUnattended,
  1753. hwnd,
  1754. wszSERVICE_NAME,
  1755. TRUE, // stop the service
  1756. FALSE, // no confirm
  1757. 0, //doesn't matter since no confirm
  1758. &pServer->fCertSrvWasRunning);
  1759. _PrintIfError(hr, "ServiceExists");
  1760. }
  1761. done:
  1762. hr = S_OK;
  1763. //error:
  1764. return hr;
  1765. }
  1766. // Component dll is being unloaded.
  1767. VOID
  1768. certocmOcCleanup(
  1769. IN WCHAR const *pwszComponent,
  1770. IN PER_COMPONENT_DATA *pComp)
  1771. {
  1772. DBGPRINT((DBG_SS_CERTOCMI, "OC_CLEANUP(%ws)\n", pwszComponent));
  1773. if (NULL != pComp->pwszComponent)
  1774. {
  1775. if (0 == mylstrcmpiL(pComp->pwszComponent, pwszComponent))
  1776. {
  1777. FreeCAComponentInfo(pComp);
  1778. }
  1779. }
  1780. // also free some globals
  1781. FreeCAGlobals();
  1782. }
  1783. /////////////////////////////////////////////////////////////////////////////
  1784. //++
  1785. //
  1786. // certocmOcQueryState
  1787. //
  1788. // Routine Description:
  1789. // This funcion sets the original, current, and final selection states of the
  1790. // CertSrv service optional component.
  1791. //
  1792. // Return Value:
  1793. // SubcompOn - indicates that the checkbox should be set
  1794. // SubcompOff - indicates that the checkbox should be clear
  1795. // SubcompUseOCManagerDefault - OC Manager should set the state of the checkbox
  1796. // according to state information that is maintained
  1797. // internally by OC Manager itself.
  1798. //
  1799. // Note:
  1800. // By the time this function gets called OnOcInitComponent has already determined
  1801. // that Terminal Services is not installed. It is only necessary to determine
  1802. // whether Terminal Services is selected for installation.
  1803. //--
  1804. /////////////////////////////////////////////////////////////////////////////
  1805. HRESULT
  1806. certocmOcQueryState(
  1807. IN WCHAR const *pwszComponent,
  1808. OPTIONAL IN WCHAR const *pwszSubComponent,
  1809. IN DWORD SelectionState,
  1810. IN PER_COMPONENT_DATA *pComp,
  1811. OUT ULONG_PTR *pulpRet)
  1812. {
  1813. HRESULT hr;
  1814. SubComponentState stateRet = SubcompUseOcManagerDefault;
  1815. DWORD status;
  1816. WCHAR awc[cwcDWORDSPRINTF];
  1817. BOOL fFinished;
  1818. DBGPRINT((
  1819. DBG_SS_CERTOCMI,
  1820. "OC_QUERY_STATE(%ws, %ws, %x)\n",
  1821. pwszComponent,
  1822. pwszSubComponent,
  1823. SelectionState));
  1824. if (NULL == pwszSubComponent)
  1825. {
  1826. goto done;
  1827. }
  1828. switch(SelectionState)
  1829. {
  1830. case OCSELSTATETYPE_ORIGINAL:
  1831. {
  1832. // check to see if the post link exist
  1833. hr = CheckPostBaseInstallStatus(&fFinished);
  1834. _JumpIfError(hr, error, "CheckPostBaseInstallStatus");
  1835. if (!pComp->fPostBase &&
  1836. (SETUPOP_STANDALONE & pComp->Flags) )
  1837. {
  1838. // install through Components button
  1839. if (!fFinished)
  1840. {
  1841. // don't honor local reg SetupStatus
  1842. break;
  1843. }
  1844. }
  1845. // Return the initial installation state of the subcomponent
  1846. if (!pComp->fPostBase &&
  1847. ((SETUPOP_STANDALONE & pComp->Flags) ||
  1848. (SETUPOP_NTUPGRADE & pComp->Flags)) )
  1849. {
  1850. //there is chance for user installed certsrv during base setup
  1851. //and then upgrade without finishing CYS
  1852. if (fFinished)
  1853. {
  1854. // If this is an upgrade or a standalone, query the registry to
  1855. // get the current installation status
  1856. // XTAN, 7/99
  1857. // currently certsrv_server has Needs relationship with
  1858. // certsrv_client. OCM gathers success for certsrv_client before
  1859. // certsrv_server is complete so we don't trust OCM state info
  1860. // about certsrv_client and we check our reg SetupStatus here.
  1861. // our certsrv_server Needs define is incorrect. If we take it
  1862. // out, we probably don't need to reg SetupStatus at
  1863. // Configuration level at all and we can trust OCM state info
  1864. hr = GetSetupStatus(NULL, &status);
  1865. if (S_OK == hr)
  1866. {
  1867. if (
  1868. (0 == LSTRCMPIS(pwszSubComponent, wszSERVERSECTION) &&
  1869. !(SETUP_SERVER_FLAG & status)) ||
  1870. (0 == LSTRCMPIS(pwszSubComponent, wszCLIENTSECTION) &&
  1871. !(SETUP_CLIENT_FLAG & status))
  1872. )
  1873. {
  1874. // overwrite OCM default
  1875. stateRet = SubcompOff;
  1876. }
  1877. }
  1878. }
  1879. }
  1880. break;
  1881. }
  1882. case OCSELSTATETYPE_CURRENT:
  1883. {
  1884. break;
  1885. }
  1886. case OCSELSTATETYPE_FINAL:
  1887. {
  1888. SUBCOMP const *psc;
  1889. BOOL fWasEnabled;
  1890. if (S_OK != pComp->hrContinue && !pComp->fUnattended)
  1891. {
  1892. stateRet = SubcompOff;
  1893. }
  1894. //get component install info
  1895. psc = TranslateSubComponent(pwszComponent, pwszSubComponent);
  1896. if (NULL == psc)
  1897. {
  1898. hr = E_INVALIDARG;
  1899. _JumpError(hr, error, "Internal error: unsupported component");
  1900. }
  1901. fWasEnabled = certocmWasEnabled(pComp, psc->cscSubComponent);
  1902. // after all of this, change upgrade->uninstall if not supported
  1903. if ((SETUPOP_NTUPGRADE & pComp->Flags) && fWasEnabled)
  1904. {
  1905. CSASSERT(pComp->UpgradeFlag != CS_UPGRADE_UNKNOWN);
  1906. if (CS_UPGRADE_UNSUPPORTED == pComp->UpgradeFlag)
  1907. stateRet = SubcompOff;
  1908. }
  1909. break;
  1910. }
  1911. }
  1912. done:
  1913. hr = S_OK;
  1914. error:
  1915. wsprintf(awc, L"%u", SelectionState);
  1916. CSILOG(S_OK, IDS_LOG_SELECTIONSTATE, awc, NULL, (DWORD const *) &stateRet);
  1917. *pulpRet = stateRet;
  1918. return(hr);
  1919. }
  1920. //+------------------------------------------------------------------------
  1921. //
  1922. // Function: CertSrvOCProc( . . . . )
  1923. //
  1924. // Synopsis: Service procedure for Cert Server OCM Setup.
  1925. //
  1926. // Arguments: [pwszComponent]
  1927. // [pwszSubComponent]
  1928. // [Function]
  1929. // [Param1]
  1930. // [Param2]
  1931. //
  1932. // Returns: DWORD
  1933. //
  1934. // History: 04/07/97 JerryK Created
  1935. //
  1936. //-------------------------------------------------------------------------
  1937. ULONG_PTR
  1938. CertSrvOCProc(
  1939. IN WCHAR const *pwszComponent,
  1940. IN WCHAR const *pwszSubComponent,
  1941. IN UINT Function,
  1942. IN UINT_PTR Param1,
  1943. IN OUT VOID *Param2)
  1944. {
  1945. ULONG_PTR ulpRet = 0;
  1946. WCHAR const *pwszFunction = NULL;
  1947. BOOL fReturnErrCode = TRUE;
  1948. DWORD ErrorLine;
  1949. __try
  1950. {
  1951. switch (Function)
  1952. {
  1953. // OC_PREINITIALIZE:
  1954. // pwszComponent = WCHAR top level component string
  1955. // pwszSubComponent = CHAR top level component string
  1956. // Param1 = char width flags
  1957. // Param2 = unused
  1958. //
  1959. // Return code is char width allowed flags
  1960. case OC_PREINITIALIZE:
  1961. csiLogOpen("+certocm.log");
  1962. CSILOGFILEVERSION(0, L"certocm.dll", szCSVER_STR);
  1963. pwszFunction = L"OC_PREINITIALIZE";
  1964. fReturnErrCode = FALSE;
  1965. // Make sure IDS_LOG_BEGIN & IDS_LOG_END see a Unicode string:
  1966. pwszSubComponent = pwszComponent;
  1967. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  1968. _LeaveIfError(g_Comp.hrContinue, "OC_PREINITIALIZE");
  1969. g_Comp.hrContinue = myInfOpenFile(NULL, &g_Comp.hinfCAPolicy, &ErrorLine);
  1970. if(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == g_Comp.hrContinue)
  1971. {
  1972. g_Comp.hrContinue = S_OK;
  1973. }
  1974. _LeaveIfError(g_Comp.hrContinue, "myInfOpenFile");
  1975. g_Comp.hrContinue = certocmOcPreInitialize(
  1976. pwszComponent,
  1977. (UINT)Param1, //cast to UINT, use as flags
  1978. &ulpRet);
  1979. _PrintIfError(g_Comp.hrContinue, "certocmOcPreInitialize");
  1980. break;
  1981. // OC_INIT_COMPONENT:
  1982. // pwszComponent = WCHAR top level component string
  1983. // pwszSubComponent = unused
  1984. // Param1 = unused
  1985. // Param2 = points to IN OUT SETUP_INIT_COMPONENT structure
  1986. //
  1987. // Return code is Win32 error indicating outcome.
  1988. case OC_INIT_COMPONENT:
  1989. pwszFunction = L"OC_INIT_COMPONENT";
  1990. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  1991. _LeaveIfError(g_Comp.hrContinue, "OC_INIT_COMPONENT");
  1992. g_Comp.hrContinue = certocmOcInitComponent(
  1993. NULL, // probably have to pass null hwnd
  1994. pwszComponent,
  1995. (SETUP_INIT_COMPONENT *) Param2,
  1996. &g_Comp,
  1997. &ulpRet);
  1998. _PrintIfError(g_Comp.hrContinue, "certocmOcInitComponent");
  1999. break;
  2000. case OC_SET_LANGUAGE:
  2001. pwszFunction = L"OC_SET_LANGUAGE";
  2002. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2003. _LeaveIfError(g_Comp.hrContinue, "OC_SET_LANGUAGE");
  2004. DBGPRINT((
  2005. DBG_SS_CERTOCMI,
  2006. "OC_SET_LANGUAGE(%ws, %ws, %x, %x)\n",
  2007. pwszComponent,
  2008. pwszSubComponent,
  2009. Param1,
  2010. Param2));
  2011. break;
  2012. // OC_QUERY_IMAGE:
  2013. //
  2014. // obsolete (only called on x86 if IMAGE_EX fails)
  2015. // use OC_QUERY_IMAGE_EX instead
  2016. //
  2017. // pwszComponent = WCHAR top level component string
  2018. // pwszSubComponent = WCHAR sub-component string
  2019. // Param1 = low 16 bits specify image; only small icon supported
  2020. // Param2 = low 16 bits = desired width, high 16 bits = desired height
  2021. //
  2022. // Return value is the GDI handle of a small bitmap to be used.
  2023. case OC_QUERY_IMAGE:
  2024. pwszFunction = L"OC_QUERY_IMAGE";
  2025. fReturnErrCode = FALSE;
  2026. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2027. _LeaveIfError(g_Comp.hrContinue, "OC_QUERY_IMAGE");
  2028. g_Comp.hrContinue = certocmOcQueryImage(
  2029. pwszComponent,
  2030. pwszSubComponent,
  2031. (SubComponentInfo) LOWORD(Param1),
  2032. LOWORD((ULONG_PTR) Param2),
  2033. HIWORD((ULONG_PTR) Param2),
  2034. &g_Comp,
  2035. (HBITMAP*)&ulpRet);
  2036. _PrintIfError(g_Comp.hrContinue, "certocmOcQueryImage");
  2037. break;
  2038. // OC_QUERY_IMAGE_EX:
  2039. //
  2040. // pwszComponent = WCHAR top level component string
  2041. // pwszSubComponent = WCHAR sub-component string
  2042. // Param1 = [in] OC_QUERY_IMAGE_INFO*
  2043. // Param2 = [in,out] HBITMAP*
  2044. //
  2045. // Return value is S_OK or ERROR_CALL_COMPONENT
  2046. case OC_QUERY_IMAGE_EX:
  2047. pwszFunction = L"OC_QUERY_IMAGE_EX";
  2048. fReturnErrCode = FALSE;
  2049. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2050. {
  2051. OC_QUERY_IMAGE_INFO *pocQueryImageInfo = (OC_QUERY_IMAGE_INFO *) Param1;
  2052. g_Comp.hrContinue = certocmOcQueryImage(
  2053. pwszComponent,
  2054. pwszSubComponent,
  2055. pocQueryImageInfo->ComponentInfo,
  2056. pocQueryImageInfo->DesiredWidth,
  2057. pocQueryImageInfo->DesiredHeight,
  2058. &g_Comp,
  2059. (HBITMAP *) Param2);
  2060. _PrintIfError(g_Comp.hrContinue, "certocmOcQueryImage");
  2061. ulpRet = (S_OK == g_Comp.hrContinue)? TRUE:FALSE;
  2062. }
  2063. break;
  2064. // OC_REQUEST_PAGES:
  2065. // pwszComponent = WCHAR top level component string
  2066. // pwszSubComponent = unused
  2067. // Param1 = Type of wiz pages being requested (WizardPagesType enum)
  2068. // Param2 = points to IN OUT SETUP_REQUEST_PAGES structure
  2069. //
  2070. // Return value is number of pages the component places in the
  2071. // SETUP_REQUEST_PAGES structure.
  2072. case OC_REQUEST_PAGES:
  2073. pwszFunction = L"OC_REQUEST_PAGES";
  2074. fReturnErrCode = FALSE;
  2075. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2076. _LeaveIfError(g_Comp.hrContinue, "OC_REQUEST_PAGES");
  2077. g_Comp.hrContinue = certocmOcRequestPages(
  2078. pwszComponent,
  2079. (WizardPagesType) Param1,
  2080. (SETUP_REQUEST_PAGES *) Param2,
  2081. &g_Comp,
  2082. &ulpRet);
  2083. _PrintIfError(g_Comp.hrContinue, "certocmOcRequestPages");
  2084. break;
  2085. // OC_QUERY_CHANGE_SEL_STATE:
  2086. // pwszComponent = WCHAR top level component string
  2087. // pwszSubComponent = WCHAR sub-component string
  2088. // Param1 = proposed new sel state; 0 = unselected, non 0 = selected
  2089. // Param2 = flags -- OCQ_ACTUAL_SELECTION
  2090. //
  2091. // Return boolean to indicate whether to allow selection state change
  2092. case OC_QUERY_CHANGE_SEL_STATE:
  2093. pwszFunction = L"OC_QUERY_CHANGE_SEL_STATE";
  2094. fReturnErrCode = FALSE;
  2095. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2096. _LeaveIfError(g_Comp.hrContinue, "OC_QUERY_CHANGE_SEL_STATE");
  2097. g_Comp.hrContinue = certocmOcQueryChangeSelState(
  2098. g_Comp.HelperRoutines.QueryWizardDialogHandle(g_Comp.HelperRoutines.OcManagerContext),
  2099. pwszComponent,
  2100. pwszSubComponent,
  2101. (BOOL) Param1,
  2102. (DWORD) (ULONG_PTR) Param2,
  2103. &g_Comp,
  2104. &ulpRet);
  2105. _PrintIfError(g_Comp.hrContinue, "certocmOcQueryChangeSelState");
  2106. break;
  2107. // OC_CALC_DISK_SPACE:
  2108. // pwszComponent = WCHAR top level component string
  2109. // pwszSubComponent = WCHAR sub-component string
  2110. // Param1 = 0 for removing component or non 0 for adding component
  2111. // Param2 = HDSKSPC to operate on
  2112. //
  2113. // Return value is Win32 error code indicating outcome.
  2114. case OC_CALC_DISK_SPACE:
  2115. pwszFunction = L"OC_CALC_DISK_SPACE";
  2116. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2117. _LeaveIfError(g_Comp.hrContinue, "OC_CALC_DISK_SPACE");
  2118. g_Comp.hrContinue = certocmOcCalcDiskSpace(
  2119. pwszComponent,
  2120. pwszSubComponent,
  2121. (BOOL) Param1,
  2122. (HDSKSPC) Param2,
  2123. &g_Comp,
  2124. &ulpRet);
  2125. _PrintIfError(g_Comp.hrContinue, "certocmOcCalcDiskSpace");
  2126. break;
  2127. // OC_QUEUE_FILE_OPS:
  2128. // pwszComponent = WCHAR top level component string
  2129. // pwszSubComponent = WCHAR sub-component string
  2130. // Param1 = unused
  2131. // Param2 = HSPFILEQ to operate on
  2132. //
  2133. // Return value is Win32 error code indicating outcome.
  2134. case OC_QUEUE_FILE_OPS:
  2135. pwszFunction = L"OC_QUEUE_FILE_OPS";
  2136. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2137. _LeaveIfError(g_Comp.hrContinue, "OC_QUEUE_FILE_OPS");
  2138. g_Comp.hrContinue = certocmOcQueueFileOps(
  2139. g_Comp.HelperRoutines.QueryWizardDialogHandle(g_Comp.HelperRoutines.OcManagerContext),
  2140. pwszComponent,
  2141. pwszSubComponent,
  2142. (HSPFILEQ) Param2,
  2143. &g_Comp,
  2144. &ulpRet);
  2145. _PrintIfError(g_Comp.hrContinue, "certocmOcQueueFileOps");
  2146. break;
  2147. // Params? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  2148. // OC_NOTIFICATION_FROM_QUEUE:
  2149. // pwszComponent = WCHAR top level component string
  2150. // pwszSubComponent = unused
  2151. // Param1 = unused
  2152. // Param2 = unused
  2153. //
  2154. // Return value is ???
  2155. case OC_NOTIFICATION_FROM_QUEUE:
  2156. pwszFunction = L"OC_NOTIFICATION_FROM_QUEUE";
  2157. fReturnErrCode = FALSE;
  2158. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2159. DBGPRINT((
  2160. DBG_SS_CERTOCMI,
  2161. "OC_NOTIFICATION_FROM_QUEUE(%ws, %ws, %x, %x)\n",
  2162. pwszComponent,
  2163. pwszSubComponent,
  2164. Param1,
  2165. Param2));
  2166. break;
  2167. // OC_QUERY_STEP_COUNT:
  2168. // pwszComponent = WCHAR top level component string
  2169. // pwszSubComponent = WCHAR sub-component string
  2170. // Param1 = unused
  2171. // Param2 = unused
  2172. //
  2173. // Return value is an arbitrary 'step' count or -1 if error.
  2174. case OC_QUERY_STEP_COUNT:
  2175. pwszFunction = L"OC_QUERY_STEP_COUNT";
  2176. fReturnErrCode = FALSE;
  2177. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2178. _LeaveIfError(g_Comp.hrContinue, "OC_QUERY_STEP_COUNT");
  2179. g_Comp.hrContinue = (DWORD) certocmOcQueryStepCount(
  2180. pwszComponent,
  2181. pwszSubComponent,
  2182. &ulpRet);
  2183. _PrintIfError(g_Comp.hrContinue, "certocmOcQueryStepCount");
  2184. break;
  2185. // OC_COMPLETE_INSTALLATION:
  2186. // pwszComponent = WCHAR top level component string
  2187. // pwszSubComponent = WCHAR sub-component string
  2188. // Param1 = reserved for future expansion
  2189. // Param2 = unused
  2190. //
  2191. // Return value is Win32 error code indicating outcome.
  2192. case OC_COMPLETE_INSTALLATION:
  2193. pwszFunction = L"OC_COMPLETE_INSTALLATION";
  2194. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2195. _LeaveIfError(g_Comp.hrContinue, "OC_COMPLETE_INSTALLATION");
  2196. g_Comp.hrContinue = certocmOcCompleteInstallation(
  2197. g_Comp.HelperRoutines.QueryWizardDialogHandle(g_Comp.HelperRoutines.OcManagerContext),
  2198. pwszComponent,
  2199. pwszSubComponent,
  2200. &g_Comp,
  2201. &ulpRet);
  2202. _PrintIfError(g_Comp.hrContinue, "certocmOcCompleteInstallation");
  2203. break;
  2204. // OC_CLEANUP:
  2205. // pwszComponent = WCHAR top level component string
  2206. // pwszSubComponent = unused
  2207. // Param1 = unused
  2208. // Param2 = unused
  2209. //
  2210. // Return value is ignored
  2211. case OC_CLEANUP:
  2212. // don't _LeaveIfError(g_Comp.hrContinue, "OC_CLEANUP");
  2213. // avoid memory leaks
  2214. pwszFunction = L"OC_CLEANUP";
  2215. fReturnErrCode = FALSE;
  2216. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2217. certocmOcCleanup(pwszComponent, &g_Comp);
  2218. break;
  2219. // Params? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  2220. // OC_QUERY_STATE:
  2221. // pwszComponent = WCHAR top level component string
  2222. // pwszSubComponent = WCHAR sub-component string
  2223. // Param1 = unused? (but Index Server uses it for current state)!
  2224. // Param2 = unused
  2225. //
  2226. // Return value is from the SubComponentState enumerated type
  2227. case OC_QUERY_STATE:
  2228. pwszFunction = L"OC_QUERY_STATE";
  2229. fReturnErrCode = FALSE;
  2230. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2231. //don't _LeaveIfError(g_Comp.hrContinue, "OC_QUERY_STATE");
  2232. certocmOcQueryState(
  2233. pwszComponent,
  2234. pwszSubComponent,
  2235. (DWORD)Param1, //cast to DWORD, use as flags
  2236. &g_Comp,
  2237. &ulpRet);
  2238. break;
  2239. // Params? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  2240. // OC_NEED_MEDIA:
  2241. // pwszComponent = WCHAR top level component string
  2242. // pwszSubComponent = WCHAR sub-component string
  2243. // Param1 = unused
  2244. // Param2 = unused
  2245. //
  2246. // Return value is ???
  2247. case OC_NEED_MEDIA:
  2248. pwszFunction = L"OC_NEED_MEDIA";
  2249. fReturnErrCode = FALSE;
  2250. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2251. DBGPRINT((
  2252. DBG_SS_CERTOCMI,
  2253. "OC_NEED_MEDIA(%ws, %ws, %x, %x)\n",
  2254. pwszComponent,
  2255. pwszSubComponent,
  2256. Param1,
  2257. Param2));
  2258. break;
  2259. // OC_ABOUT_TO_COMMIT_QUEUE:
  2260. // pwszComponent = WCHAR top level component string
  2261. // pwszSubComponent = WCHAR sub-component string
  2262. // Param1 = reserved for future expansion
  2263. // Param2 = unused
  2264. //
  2265. // Return value is Win32 error code indicating outcome.
  2266. case OC_ABOUT_TO_COMMIT_QUEUE:
  2267. pwszFunction = L"OC_ABOUT_TO_COMMIT_QUEUE";
  2268. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2269. _LeaveIfError(g_Comp.hrContinue, "OC_ABOUT_TO_COMMIT_QUEUE");
  2270. g_Comp.hrContinue = certocmOcCommitQueue(
  2271. g_Comp.HelperRoutines.QueryWizardDialogHandle(g_Comp.HelperRoutines.OcManagerContext),
  2272. pwszComponent,
  2273. pwszSubComponent,
  2274. &g_Comp);
  2275. _PrintIfError(g_Comp.hrContinue, "certocmOcCommitQueue");
  2276. break;
  2277. // OC_QUERY_SKIP_PAGE:
  2278. // pwszComponent = WCHAR top level component string
  2279. // pwszSubComponent = unused
  2280. // Param1 = OcManagerPage page indicator
  2281. // Param2 = unused
  2282. //
  2283. // Return value is a boolean -- 0 for display or non 0 for skip
  2284. case OC_QUERY_SKIP_PAGE:
  2285. pwszFunction = L"OC_QUERY_SKIP_PAGE";
  2286. fReturnErrCode = FALSE;
  2287. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2288. DBGPRINT((
  2289. DBG_SS_CERTOCMI,
  2290. "OC_QUERY_SKIP_PAGE(%ws, %x)\n",
  2291. pwszComponent,
  2292. (OcManagerPage) Param1));
  2293. _LeaveIfError(g_Comp.hrContinue, "OC_QUERY_SKIP_PAGE");
  2294. if (g_Comp.fPostBase &&
  2295. (WizardPagesType) Param1 == WizPagesWelcome)
  2296. {
  2297. ulpRet = 1; // non 0 to skip wiz page
  2298. }
  2299. break;
  2300. // OC_WIZARD_CREATED:
  2301. // pwszComponent = WCHAR top level component string
  2302. // pwszSubComponent = ???
  2303. // Param1 = ???
  2304. // Param2 = ???
  2305. //
  2306. // Return value is ???
  2307. case OC_WIZARD_CREATED:
  2308. pwszFunction = L"OC_WIZARD_CREATED";
  2309. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2310. _LeaveIfError(g_Comp.hrContinue, "OC_WIZARD_CREATED");
  2311. break;
  2312. // OC_EXTRA_ROUTINES:
  2313. // pwszComponent = WCHAR top level component string
  2314. // pwszSubComponent = ???
  2315. // Param1 = ???
  2316. // Param2 = ???
  2317. //
  2318. // Return value is ???
  2319. case OC_EXTRA_ROUTINES:
  2320. pwszFunction = L"OC_EXTRA_ROUTINES";
  2321. CSILOG(g_Comp.hrContinue, IDS_LOG_BEGIN, pwszFunction, pwszSubComponent, NULL);
  2322. _LeaveIfError(g_Comp.hrContinue, "OC_EXTRA_ROUTINES");
  2323. break;
  2324. // Some other notification:
  2325. default:
  2326. fReturnErrCode = FALSE;
  2327. CSILOG(
  2328. g_Comp.hrContinue,
  2329. IDS_LOG_BEGIN,
  2330. pwszFunction,
  2331. pwszSubComponent,
  2332. (DWORD const *) &Function);
  2333. DBGPRINT((
  2334. DBG_SS_CERTOCMI,
  2335. "DEFAULT(0x%x: %ws, %ws, %x, %x)\n",
  2336. Function,
  2337. pwszComponent,
  2338. pwszSubComponent,
  2339. Param1,
  2340. Param2));
  2341. break;
  2342. }
  2343. }
  2344. __except(ulpRet = myHEXCEPTIONCODE(), EXCEPTION_EXECUTE_HANDLER)
  2345. {
  2346. if (S_OK == g_Comp.hrContinue)
  2347. {
  2348. g_Comp.hrContinue = (HRESULT)ulpRet;
  2349. }
  2350. _PrintError((HRESULT)ulpRet, "Exception");
  2351. }
  2352. DBGPRINT((DBG_SS_CERTOCMI, "return %p\n", ulpRet));
  2353. // make sure to get a pop up in case of fatal error
  2354. if (S_OK != g_Comp.hrContinue)
  2355. {
  2356. if (!g_Comp.fShownErr)
  2357. {
  2358. int iMsgId = g_Comp.iErrMsg;
  2359. if (0 == iMsgId)
  2360. {
  2361. // use generic one
  2362. iMsgId = IDS_ERR_CERTSRV_SETUP_FAIL;
  2363. }
  2364. CertErrorMessageBox(
  2365. g_Comp.hInstance,
  2366. g_Comp.fUnattended,
  2367. NULL, // null hwnd
  2368. iMsgId,
  2369. g_Comp.hrContinue,
  2370. g_Comp.pwszCustomMessage);
  2371. g_Comp.fShownErr = TRUE;
  2372. }
  2373. // anything fails, cancel install
  2374. HRESULT hr2 = CancelCertsrvInstallation(NULL, &g_Comp);
  2375. _PrintIfError(hr2, "CancelCertsrvInstallation");
  2376. }
  2377. CSILOG(
  2378. fReturnErrCode? (HRESULT) ulpRet : S_OK,
  2379. IDS_LOG_END,
  2380. pwszFunction,
  2381. pwszSubComponent,
  2382. fReturnErrCode? NULL : (DWORD const *) &ulpRet);
  2383. return(ulpRet);
  2384. }
  2385. ULONG_PTR
  2386. CertSrvOCPostProc(
  2387. IN WCHAR const *pwszComponent,
  2388. IN WCHAR const *pwszSubComponent,
  2389. IN UINT Function,
  2390. IN UINT Param1,
  2391. IN OUT VOID *Param2)
  2392. {
  2393. // post setup entry point
  2394. // by going through this path, we know it is invoked in post setup
  2395. g_Comp.fPostBase = TRUE;
  2396. return CertSrvOCProc(
  2397. pwszComponent,
  2398. pwszSubComponent,
  2399. Function,
  2400. Param1,
  2401. Param2);
  2402. }
  2403. VOID
  2404. certocmBumpGasGauge(
  2405. OPTIONAL IN PER_COMPONENT_DATA *pComp,
  2406. IN DWORD PerCentComplete
  2407. DBGPARM(IN WCHAR const *pwszSource))
  2408. {
  2409. static DWORD dwTickCount = 0;
  2410. if (NULL != pComp)
  2411. {
  2412. DWORD NewCount;
  2413. NewCount = (PerCentComplete * SERVERINSTALLTICKS)/100;
  2414. DBGPRINT((
  2415. DBG_SS_CERTOCMI,
  2416. "certocmBumpGasGauge(%ws, %u%%) %d ticks: %d --> %d\n",
  2417. pwszSource,
  2418. PerCentComplete,
  2419. NewCount - dwTickCount,
  2420. dwTickCount,
  2421. NewCount));
  2422. if (SERVERINSTALLTICKS < NewCount)
  2423. {
  2424. NewCount = SERVERINSTALLTICKS;
  2425. }
  2426. while (dwTickCount < NewCount)
  2427. {
  2428. (*pComp->HelperRoutines.TickGauge)(
  2429. pComp->HelperRoutines.OcManagerContext);
  2430. dwTickCount++;
  2431. }
  2432. }
  2433. }
  2434. BOOL
  2435. certocmEnabledSub(
  2436. PER_COMPONENT_DATA *pComp,
  2437. CertSubComponent SubComp,
  2438. DWORD SelectionStateType)
  2439. {
  2440. SUBCOMP const *psc;
  2441. BOOL bRet = FALSE;
  2442. psc = LookupSubComponent(SubComp);
  2443. if (NULL != psc->pwszSubComponent)
  2444. {
  2445. if (pComp->fUnattended &&
  2446. OCSELSTATETYPE_CURRENT == SelectionStateType &&
  2447. 0 == (pComp->Flags & SETUPOP_NTUPGRADE) )
  2448. {
  2449. // unattended case, flags from unattended file
  2450. // upgrade is automatically in unattended mode and make sure
  2451. // to exclude it
  2452. bRet = psc->fInstallUnattend;
  2453. }
  2454. else
  2455. {
  2456. bRet = (*pComp->HelperRoutines.QuerySelectionState)(
  2457. pComp->HelperRoutines.OcManagerContext,
  2458. psc->pwszSubComponent,
  2459. SelectionStateType);
  2460. }
  2461. }
  2462. return(bRet);
  2463. }
  2464. BOOL
  2465. certocmIsEnabled(
  2466. PER_COMPONENT_DATA *pComp,
  2467. CertSubComponent SubComp)
  2468. {
  2469. BOOL bRet;
  2470. bRet = certocmEnabledSub(pComp, SubComp, OCSELSTATETYPE_CURRENT);
  2471. if (!fDebugSupress)
  2472. {
  2473. DBGPRINT((
  2474. DBG_SS_CERTOCMI,
  2475. "certocmIsEnabled(%ws) Is %ws\n",
  2476. LookupSubComponent(SubComp)->pwszSubComponent,
  2477. bRet? L"Enabled" : L"Disabled"));
  2478. }
  2479. return(bRet);
  2480. }
  2481. BOOL
  2482. certocmWasEnabled(
  2483. PER_COMPONENT_DATA *pComp,
  2484. CertSubComponent SubComp)
  2485. {
  2486. BOOL bRet;
  2487. bRet = certocmEnabledSub(pComp, SubComp, OCSELSTATETYPE_ORIGINAL);
  2488. if (!fDebugSupress)
  2489. {
  2490. DBGPRINT((
  2491. DBG_SS_CERTOCMI,
  2492. "certocmWasEnabled(%ws) Was %ws\n",
  2493. LookupSubComponent(SubComp)->pwszSubComponent,
  2494. bRet? L"Enabled" : L"Disabled"));
  2495. }
  2496. return(bRet);
  2497. }
  2498. BOOL
  2499. certocmUninstalling(
  2500. PER_COMPONENT_DATA *pComp,
  2501. CertSubComponent SubComp)
  2502. {
  2503. BOOL bRet;
  2504. fDebugSupress++;
  2505. bRet = certocmWasEnabled(pComp, SubComp) && !certocmIsEnabled(pComp, SubComp);
  2506. fDebugSupress--;
  2507. if (!fDebugSupress)
  2508. {
  2509. DBGPRINT((
  2510. DBG_SS_CERTOCMI,
  2511. "certocmUninstalling(%ws) %ws\n",
  2512. LookupSubComponent(SubComp)->pwszSubComponent,
  2513. bRet? L"TRUE" : L"False"));
  2514. }
  2515. return(bRet);
  2516. }
  2517. BOOL
  2518. certocmInstalling(
  2519. PER_COMPONENT_DATA *pComp,
  2520. CertSubComponent SubComp)
  2521. {
  2522. BOOL bRet;
  2523. fDebugSupress++;
  2524. bRet = !certocmWasEnabled(pComp, SubComp) && certocmIsEnabled(pComp, SubComp);
  2525. fDebugSupress--;
  2526. if (!fDebugSupress)
  2527. {
  2528. DBGPRINT((
  2529. DBG_SS_CERTOCMI,
  2530. "certocmInstalling(%ws) %ws\n",
  2531. LookupSubComponent(SubComp)->pwszSubComponent,
  2532. bRet? L"TRUE" : L"False"));
  2533. }
  2534. return(bRet);
  2535. }
  2536. BOOL
  2537. certocmPreserving(
  2538. PER_COMPONENT_DATA *pComp,
  2539. CertSubComponent SubComp)
  2540. {
  2541. BOOL bRet;
  2542. fDebugSupress++;
  2543. bRet = certocmWasEnabled(pComp, SubComp) && certocmIsEnabled(pComp, SubComp);
  2544. fDebugSupress--;
  2545. if (!fDebugSupress)
  2546. {
  2547. DBGPRINT((
  2548. DBG_SS_CERTOCMI,
  2549. "certocmPreserving(%ws) %ws\n",
  2550. LookupSubComponent(SubComp)->pwszSubComponent,
  2551. bRet? L"TRUE" : L"False"));
  2552. }
  2553. return(bRet);
  2554. }