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.

363 lines
16 KiB

  1. #include "precomp.h"
  2. extern TCHAR g_szCustIns[];
  3. extern TCHAR g_szBuildTemp[];
  4. extern TCHAR g_szTempSign[];
  5. extern TCHAR g_szWizRoot[];
  6. extern TCHAR g_szDestCif[];
  7. extern TCHAR g_szDefInf[];
  8. extern TCHAR g_szCustInf[];
  9. extern TCHAR g_szAllModes[];
  10. extern TCHAR g_szLanguage[];
  11. extern BOOL g_fIntranet;
  12. extern BOOL g_fServerICW, g_fServerKiosk, g_fServerless;
  13. extern PROPSHEETPAGE g_psp[];
  14. extern int g_iCurPage;
  15. extern void SetCompSize(LPTSTR szCab, LPTSTR szSect, DWORD dwInstallSize);
  16. extern void WriteModesToCif(CCifRWComponent_t * pCifRWComponent_t, LPCTSTR pcszModes);
  17. // global variables
  18. TCHAR g_szJobVersion[32];
  19. TCHAR g_szDeskTemp[MAX_PATH] = TEXT("");
  20. TCHAR g_szUnsignedFiles[MAX_BUF] = TEXT("");
  21. // static variables
  22. static DWORD s_dwDDF = 0;
  23. static TCHAR s_szInfAdd1[] = TEXT("\r\n[ProgramFilesDir]\r\nHKLM,Software\\Microsoft\\Windows\\CurrentVersion,ProgramFilesDir,,%24%\r\n");
  24. static TCHAR s_szInfAdd2[] = TEXT("\r\n[IeFilesDir]\r\nHKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE\"")
  25. TEXT(",\"Path\",,\"%24%\\Program Files\\%IEDIR%\"\r\n");
  26. static TCHAR s_szDDFTpl[] = TEXT(".Set SourceDir=%s\r\nsetup.inf /INF=NO\r\ninstall.inf /INF=NO");
  27. void CreatePostCmdSection(LPCTSTR szDestDir, LPCTSTR szInf)
  28. {
  29. TCHAR szLDID[MAX_PATH],
  30. szDir[MAX_PATH],
  31. szBuildDir[MAX_PATH];
  32. LPTSTR pPtr,
  33. pPostCmdSect;
  34. int nSizeSectBuffer = 0;
  35. if (szDestDir == NULL || *szDestDir == TEXT('\0') || szInf == NULL || *szInf == TEXT('\0'))
  36. return;
  37. *szLDID = TEXT('\0');
  38. *szDir = TEXT('\0');
  39. pPtr = StrChr(szDestDir, TEXT(','));
  40. if (pPtr != NULL)
  41. {
  42. StrCpyN(szLDID, szDestDir, (int) ((pPtr - szDestDir) + 1));
  43. StrCpy(szDir, pPtr + 1);
  44. }
  45. if (*szLDID == TEXT('\0') || *szDir == TEXT('\0'))
  46. return;
  47. wnsprintf(szBuildDir, countof(szBuildDir), TEXT("%%%s%%\\%s"), szLDID, szDir);
  48. nSizeSectBuffer = MAX_PATH * 5;
  49. pPostCmdSect = (LPTSTR)LocalAlloc(LPTR, nSizeSectBuffer * sizeof(TCHAR));
  50. if (pPostCmdSect)
  51. {
  52. TCHAR szFile[MAX_PATH],
  53. szSectLine[MAX_PATH];
  54. int nCopyIndex = 0;
  55. WIN32_FIND_DATA findFileData;
  56. // add .adm inf line (if any) to the section string
  57. PathCombine(szFile, g_szTempSign, TEXT("*.inf"));
  58. HANDLE hFind = FindFirstFile(szFile, &findFileData);
  59. if(hFind != INVALID_HANDLE_VALUE)
  60. {
  61. TCHAR szADMFile[MAX_PATH],
  62. szADMPath[MAX_PATH];
  63. LPTSTR pTemp;
  64. PathCombine(szADMPath, g_szWizRoot, TEXT("Policies"));
  65. PathAppend(szADMPath, g_szLanguage);
  66. do
  67. {
  68. StrCpy(szFile, findFileData.cFileName);
  69. PathRenameExtension(szFile, TEXT(".adm"));
  70. PathCombine(szADMFile, szADMPath, szFile);
  71. if (PathFileExists(szADMFile))
  72. {
  73. wnsprintf(szSectLine, countof(szSectLine), TEXT("rundll32.exe advpack.dll,LaunchINFSection %s\\%s,DefaultInstall.HKLM, 1"), szBuildDir, findFileData.cFileName);
  74. if (nCopyIndex + StrLen(szSectLine) + 1 > (nSizeSectBuffer - 1))
  75. {
  76. nSizeSectBuffer += MAX_PATH;
  77. pTemp = (LPTSTR)LocalReAlloc(pPostCmdSect, nSizeSectBuffer, LMEM_ZEROINIT);
  78. if (pTemp != NULL)
  79. pPostCmdSect = pTemp;
  80. else
  81. break;
  82. }
  83. StrCpy(pPostCmdSect + nCopyIndex, szSectLine);
  84. nCopyIndex += StrLen(szSectLine);
  85. nCopyIndex++; // section lines must be spaced with a NULL character
  86. }
  87. }while(FindNextFile(hFind, &findFileData));
  88. FindClose(hFind);
  89. }
  90. }
  91. if (pPostCmdSect != NULL)
  92. {
  93. if (*pPostCmdSect != TEXT('\0'))
  94. {
  95. WritePrivateProfileSection(TEXT("PostCmdSect"), pPostCmdSect, szInf);
  96. WritePrivateProfileString(NULL, NULL, NULL, szInf);
  97. }
  98. LocalFree(pPostCmdSect);
  99. }
  100. }
  101. HRESULT CabUpFolder(HWND hWnd, LPTSTR szFolderPath, LPTSTR szDestDir, LPTSTR szCabname,
  102. LPTSTR szDisplayName, LPTSTR szGuid, LPTSTR szAddReg)
  103. {
  104. WIN32_FIND_DATA fd;
  105. HANDLE hFind;
  106. TCHAR szFrom[MAX_PATH];
  107. TCHAR szCabPath[MAX_PATH];
  108. TCHAR szDDF[MAX_PATH];
  109. TCHAR szDiamondParams[MAX_PATH];
  110. TCHAR szInf[MAX_PATH];
  111. TCHAR szSetInf[MAX_PATH];
  112. TCHAR szTempDir[MAX_PATH];
  113. TCHAR szIEDir[MAX_PATH];
  114. TCHAR szMakeCabLoc[MAX_PATH];
  115. TCHAR szDefaultInstallSect[64];
  116. DWORD dwsHi, nWritten;
  117. HANDLE hDDF, hInf, hRegInf, hMakeCab;
  118. SHELLEXECUTEINFO shInfo;
  119. TCHAR szDDFAdd[3 * MAX_PATH];
  120. DWORD dwInstallSize;
  121. TCHAR szSourceDisk[80];
  122. PathCombine(szFrom, szFolderPath, TEXT("*.*"));
  123. PathCombine(szCabPath, g_szBuildTemp, szCabname);
  124. PathCombine(szDDF, g_szBuildTemp, TEXT("Folder.ddf"));
  125. wnsprintf(szDiamondParams, countof(szDiamondParams), TEXT("/D CabinetName1=..\\%s /D SourceDir=\"%s\" /F %s"),
  126. szCabname, szFolderPath, szDDF);
  127. StrCpy(szInf, szCabPath);
  128. PathRemoveFileSpec(szInf);
  129. PathAppend(szInf, TEXT("install.inf"));
  130. if (ISNULL(szGuid))
  131. {
  132. GUID guid;
  133. if (CoCreateGuid(&guid) == NOERROR)
  134. CoStringFromGUID(guid, szGuid, 64);
  135. }
  136. DeleteFile(szInf);
  137. WritePrivateProfileString(VERSION, TEXT("Signature"), TEXT("$Chicago$"), szInf);
  138. WritePrivateProfileString(VERSION, TEXT("AdvancedInf"), TEXT("2.5"), szInf);
  139. WritePrivateProfileString(VERSION, TEXT("LayoutFile"), TEXT("Setup.inf"), szInf);
  140. WritePrivateProfileString( TEXT("CustInstDestSection"), TEXT("49000,49001,49002,49003"),
  141. TEXT("ProgramFilesDir,5"), szInf );
  142. WritePrivateProfileString( TEXT("CustInstDestSection"), TEXT("49100,49101,49102,49103"),
  143. TEXT("IEFilesDir,5"), szInf );
  144. LoadString( g_rvInfo.hInst, IDS_IE, szIEDir, MAX_PATH );
  145. WritePrivateProfileString( IS_STRINGS, TEXT("IEDIR"), szIEDir, szInf);
  146. StrCpy(szDefaultInstallSect, DEFAULT_INSTALL);
  147. WritePrivateProfileString(szDefaultInstallSect, TEXT("CopyFiles"), TEXT("CopyFileSect"), szInf);
  148. WritePrivateProfileString(szDefaultInstallSect, TEXT("CustomDestination"),
  149. TEXT("CustInstDestSection"), szInf);
  150. WritePrivateProfileString(szDefaultInstallSect, REQUIRED_ENGINE, SETUPAPI_FATAL, szInf);
  151. WritePrivateProfileString(TEXT("DestinationDirs"), TEXT("CopyFileSect"), szDestDir, szInf);
  152. WritePrivateProfileString(NULL, NULL, NULL, szInf);
  153. hInf = CreateFile(szInf, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
  154. FILE_ATTRIBUTE_NORMAL, NULL);
  155. SetFilePointer(hInf, 0, NULL, FILE_END);
  156. WriteStringToFile( hInf, s_szInfAdd1, StrLen(s_szInfAdd1));
  157. WriteStringToFile( hInf, s_szInfAdd2, StrLen(s_szInfAdd2) );
  158. WriteStringToFile( hInf, TEXT("\r\n[CopyFileSect]\r\n"), 18);
  159. hDDF = CreateFile(szDDF, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
  160. FILE_ATTRIBUTE_NORMAL, NULL);
  161. if (hDDF == INVALID_HANDLE_VALUE)
  162. {
  163. CloseHandle(hInf);
  164. return E_FAIL;
  165. }
  166. if (s_dwDDF == 0) s_dwDDF = GetFileSize( hDDF, &dwsHi );
  167. SetFilePointer(hDDF, s_dwDDF, NULL, FILE_BEGIN);
  168. SetEndOfFile( hDDF );
  169. if ((hFind = FindFirstFile( szFrom, &fd)) != INVALID_HANDLE_VALUE)
  170. while (1)
  171. {
  172. LPTSTR pFn = fd.cFileName;
  173. if ((ISNONNULL(pFn)) && StrCmp(pFn, TEXT(".")) && StrCmp(pFn, TEXT(".."))
  174. && ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0))
  175. {
  176. WriteStringToFile( hDDF, TEXT("\""), 1);
  177. WriteStringToFile( hDDF, pFn, StrLen(pFn) );
  178. WriteStringToFile( hDDF, TEXT("\"\r\n"), 3 );
  179. WriteStringToFile( hInf, TEXT("\""), 1 );
  180. WriteStringToFile( hInf, pFn, StrLen(pFn) );
  181. WriteStringToFile( hInf, TEXT("\"\r\n"), 3 );
  182. }
  183. if (!FindNextFile( hFind, &fd ))
  184. if (GetLastError() == ERROR_NO_MORE_FILES)
  185. {
  186. FindClose( hFind );
  187. break;
  188. }
  189. }
  190. if (szAddReg)
  191. {
  192. if (ISNONNULL(szAddReg))
  193. {
  194. TCHAR szRegInf[MAX_PATH];
  195. CHAR szRegInfBuf[2048];
  196. TCHAR szQuotedVer[80];
  197. TCHAR szClearStubCmd[MAX_PATH];
  198. DWORD nRead;
  199. PathCombine(szRegInf, g_szBuildTemp, TEXT("ADDREG.INF"));
  200. ZeroMemory(szRegInfBuf, sizeof(szRegInfBuf));
  201. hRegInf = CreateFile(szRegInf, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
  202. FILE_ATTRIBUTE_NORMAL, NULL);
  203. ReadFile( hRegInf, szRegInfBuf, sizeof(szRegInfBuf), &nRead, NULL );
  204. WriteFile( hInf, szRegInfBuf, nRead, &nWritten, NULL );
  205. CloseHandle(hInf);
  206. CloseHandle(hRegInf);
  207. if ((szGuid[0] == TEXT('>')) || (szGuid[0] == TEXT('<')))
  208. {
  209. WritePrivateProfileString(szDefaultInstallSect, TEXT("DelReg"),
  210. TEXT("DelRegSect"), szInf);
  211. WritePrivateProfileString( IS_STRINGS, TEXT("OLDGUID"), &szGuid[1], szInf);
  212. }
  213. else
  214. WritePrivateProfileString(TEXT("DelRegSect"), NULL, NULL, szInf);
  215. wnsprintf(szQuotedVer, countof(szQuotedVer), TEXT("\"%s\""), g_szJobVersion);
  216. wnsprintf(szClearStubCmd, countof(szClearStubCmd), TEXT("\"RUNDLL32 IEDKCS32.DLL,BrandCleanInstallStubs %s\""), szGuid);
  217. WritePrivateProfileString( IS_STRINGS, TEXT("Description"), szDisplayName, szInf);
  218. WritePrivateProfileString( IS_STRINGS, TEXT("StubPath"), szAddReg, szInf);
  219. WritePrivateProfileString( IS_STRINGS, TEXT("Revision"), szQuotedVer, szInf);
  220. WritePrivateProfileString( IS_STRINGS, TEXT("GUID"), szGuid, szInf);
  221. WritePrivateProfileString( IS_STRINGS, TEXT("ClearStubsCmd"), szClearStubCmd, szInf);
  222. WritePrivateProfileString( szDefaultInstallSect, TEXT("AddReg"), TEXT("AddRegSect"), szInf);
  223. // create a postcmdsect to dump the HKLM data of the rating.inf and the
  224. // .adm inf's.
  225. WritePrivateProfileString(szDefaultInstallSect, TEXT("RunPostSetupCommands"), TEXT("PostCmdSect"), szInf);
  226. CreatePostCmdSection(szDestDir, szInf);
  227. }
  228. else CloseHandle(hInf);
  229. }
  230. else CloseHandle(hInf);
  231. wnsprintf(szDDFAdd, countof(szDDFAdd), s_szDDFTpl, g_szBuildTemp);
  232. WriteStringToFile( hDDF, szDDFAdd, StrLen(szDDFAdd));
  233. CloseHandle(hDDF);
  234. WritePrivateProfileString(NULL, NULL, NULL, szInf);
  235. wnsprintf(szSourceDisk, countof(szSourceDisk), TEXT("\"Custom Folder\",%s,0"), szCabname);
  236. PathCombine(szSetInf, g_szBuildTemp, TEXT("SETUP.INF") );
  237. DeleteFile(szSetInf);
  238. WritePrivateProfileString( TEXT("SourceDisksNames"), TEXT("1"), szSourceDisk, szSetInf );
  239. WritePrivateProfileString(NULL, NULL, NULL, szSetInf);
  240. dwInstallSize = FolderSize(szFolderPath) >> 10;
  241. memset(&shInfo, 0, sizeof(shInfo));
  242. shInfo.cbSize = sizeof(shInfo);
  243. shInfo.hwnd = hWnd;
  244. shInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  245. shInfo.lpVerb = TEXT("open");
  246. // If MAKECAB.EXE is in the current directory, use the full path.
  247. // otherwise when we build in the scratch dir we won't find it.
  248. PathCombine(szMakeCabLoc, g_szBuildTemp, TEXT("MAKECAB.EXE"));
  249. hMakeCab = CreateFile(szMakeCabLoc, GENERIC_READ, 0, NULL, OPEN_EXISTING,
  250. FILE_ATTRIBUTE_NORMAL, NULL);
  251. if(hMakeCab == INVALID_HANDLE_VALUE)
  252. shInfo.lpFile = TEXT("MAKECAB.EXE");
  253. else
  254. {
  255. CloseHandle(hMakeCab);
  256. shInfo.lpFile = szMakeCabLoc;
  257. }
  258. shInfo.lpParameters = szDiamondParams;
  259. PathCombine(szTempDir, g_szBuildTemp, TEXT("SCRATCH") ); // SETUP.INF is destroyed by ShellExecAndWait!! Use scratch dir
  260. CreateDirectory(szTempDir, NULL);
  261. shInfo.lpDirectory = szTempDir;
  262. shInfo.nShow = SW_MINIMIZE;
  263. SetCurrentDirectory(szTempDir);
  264. ShellExecAndWait(shInfo);
  265. SetCurrentDirectory(g_szBuildTemp);
  266. {
  267. ICifRWComponent * pCifRWComponent;
  268. CCifRWComponent_t * pCifRWComponent_t;
  269. ICifComponent * pCifBaseComp;
  270. g_lpCifRWFileDest->DeleteComponent(szCabname);
  271. g_lpCifRWFileDest->CreateComponent(szCabname, &pCifRWComponent);
  272. pCifRWComponent_t = new CCifRWComponent_t(pCifRWComponent);
  273. pCifRWComponent_t->SetGUID(szGuid);
  274. pCifRWComponent_t->SetDescription(szDisplayName);
  275. pCifRWComponent_t->SetUrl(0, szCabname, 3);
  276. pCifRWComponent_t->SetVersion(g_szJobVersion);
  277. pCifRWComponent_t->SetCommand(0, TEXT("INSTALL.INF"), TEXT(""), 0);
  278. pCifRWComponent_t->SetReboot(TRUE);
  279. WriteModesToCif(pCifRWComponent_t, g_szAllModes);
  280. pCifRWComponent_t->SetGroup(TEXT("BASEIE4"));
  281. pCifRWComponent_t->SetPriority(835);
  282. pCifRWComponent_t->SetUIVisible(FALSE);
  283. if (SUCCEEDED(g_lpCifRWFileDest->FindComponent(TEXT("BASEIE40_Win"), &pCifBaseComp)))
  284. {
  285. // passing in the slash because we can't change inseng interface signature
  286. // this translates to writing a line of BASEIE40:N:5.0.0.0"
  287. pCifRWComponent_t->AddDependency(TEXT("BASEIE40_Win"), TEXT('\\'));
  288. delete pCifRWComponent_t;
  289. g_lpCifRWFileDest->CreateComponent(TEXT("BASEIE40_Win"), &pCifRWComponent);
  290. pCifRWComponent_t = new CCifRWComponent_t(pCifRWComponent);
  291. pCifRWComponent_t->AddToTreatAsOne(szCabname);
  292. delete pCifRWComponent_t;
  293. g_lpCifRWFileDest->CreateComponent(TEXT("BASEIE40_NTx86"), &pCifRWComponent);
  294. pCifRWComponent_t = new CCifRWComponent_t(pCifRWComponent);
  295. pCifRWComponent_t->AddToTreatAsOne(szCabname);
  296. delete pCifRWComponent_t;
  297. }
  298. else
  299. {
  300. // passing in the slash because we can't change inseng interface signature
  301. // this translates to writing a line of BASEIE40:N:5.0.0.0"
  302. pCifRWComponent_t->AddDependency(TEXT("BASEIE40_NTAlpha"), TEXT('\\'));
  303. delete pCifRWComponent_t;
  304. g_lpCifRWFileDest->CreateComponent(TEXT("BASEIE40_NTAlpha"), &pCifRWComponent);
  305. pCifRWComponent_t = new CCifRWComponent_t(pCifRWComponent);
  306. pCifRWComponent_t->AddToTreatAsOne(szCabname);
  307. delete pCifRWComponent_t;
  308. }
  309. }
  310. SetCompSize(szCabPath, szCabname, dwInstallSize);
  311. return(S_OK);
  312. }
  313. void BuildIE4Folders(HWND hWnd)
  314. {
  315. // build desktop.cab if g_szDeskTemp exists and is non-empty
  316. if (PathIsDirectory(g_szDeskTemp) && !RemoveDirectory(g_szDeskTemp))
  317. {
  318. TCHAR szGuid[128];
  319. TCHAR szCustDesk[128];
  320. GetPrivateProfileString(IS_STRINGS, TEXT("DesktopName"), TEXT(""), szCustDesk, countof(szCustDesk), g_szDefInf);
  321. if (ISNULL(szCustDesk))
  322. LoadString(g_rvInfo.hInst, IDS_CUSTDESK, szCustDesk, countof(szCustDesk));
  323. GetPrivateProfileString(IS_BRANDING, TEXT("DesktopGuid"), TEXT(""), szGuid, countof(szGuid), g_szCustIns);
  324. CabUpFolder(hWnd, g_szDeskTemp, TEXT("25,WEB"), TEXT("DESKTOP.CAB"), szCustDesk, szGuid, NULL);
  325. SignFile(TEXT("DESKTOP.CAB"), g_szBuildTemp, g_szCustIns, g_szUnsignedFiles, g_szCustInf);
  326. PathRemovePath(g_szDeskTemp);
  327. }
  328. }