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.

269 lines
8.3 KiB

  1. /****************************************************************************\
  2. SLPFILES.C / Factory Mode (FACTORY.EXE)
  3. Microsoft Confidential
  4. Copyright (c) Microsoft Corporation 2001
  5. All rights reserved
  6. Source file for Factory that contains the update SLP files state
  7. functions.
  8. 07/2001 - Jason Cohen (JCOHEN)
  9. Added this new source file for factory for updating the SLP files and
  10. reinstalling the catalog file.
  11. \****************************************************************************/
  12. //
  13. // Include File(s):
  14. //
  15. #include "factoryp.h"
  16. //
  17. // Internal Define(s):
  18. //
  19. #define REG_KEY_WINLOGON _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon")
  20. #define REG_VAL_DLLCACHE _T("SFCDllCacheDir")
  21. #define DIR_SYSTEM _T("system32")
  22. #define DIR_DLLCACHE _T("dllcache")
  23. //
  24. // Internal Global(s):
  25. //
  26. static LPTSTR s_lpszSlpFiles[] =
  27. {
  28. _T("OEMBIOS.CAT"), // Catalog file needs to be the first in the list.
  29. _T("OEMBIOS.BIN"),
  30. _T("OEMBIOS.DAT"),
  31. _T("OEMBIOS.SIG"),
  32. };
  33. //
  34. // Internal Function Prototype(s):
  35. //
  36. static void GetDestFolder(LPTSTR lpszDest, DWORD cbDest, BOOL bDllCache);
  37. static BOOL CopySlpFile(LPTSTR lpszSrc, LPTSTR lpszDst);
  38. //
  39. // External Function(s):
  40. //
  41. BOOL SlpFiles(LPSTATEDATA lpStateData)
  42. {
  43. BOOL bRet = TRUE;
  44. #if 0
  45. DWORD dwErr;
  46. TCHAR szSrcFile[MAX_PATH];
  47. LPTSTR lpszSourcePath;
  48. if ( lpszSourcePath = IniGetExpand(lpStateData->lpszWinBOMPath, INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_SLPSOURCE, NULL) )
  49. {
  50. // Should support getting the files from the network.
  51. //
  52. FactoryNetworkConnect(lpszSourcePath, lpStateData->lpszWinBOMPath, NULL, TRUE);
  53. // The source should point to a directory that contains all the SLP files.
  54. //
  55. if ( DirectoryExists(lpszSourcePath) )
  56. {
  57. LPTSTR lpszEndSrc;
  58. DWORD x;
  59. // Copy the root source folder into our buffer.
  60. //
  61. lstrcpyn(szSrcFile, lpszSourcePath, AS(szSrcFile));
  62. lpszEndSrc = szSrcFile + lstrlen(szSrcFile);
  63. // Make sure all the files are in the folder as well.
  64. //
  65. for ( x = 0; x < AS(s_lpszSlpFiles); x++ )
  66. {
  67. // Setup the full path to this slp file.
  68. //
  69. AddPathN(szSrcFile, s_lpszSlpFiles[x], AS(szSrcFile));
  70. // Make sure this slp file exists.
  71. //
  72. if ( !FileExists(szSrcFile) )
  73. {
  74. // NEEDLOG: Log that this file doesn't exist.
  75. //
  76. bRet = FALSE;
  77. }
  78. // Don't leave the file name on there for the next guy.
  79. //
  80. *lpszEndSrc = NULLCHR;
  81. }
  82. // If there were no errors, lets try to update the files.
  83. //
  84. if ( bRet )
  85. {
  86. // Call the syssetup function to update the catalog before
  87. // we copy any of the files (the catalog is always the first file).
  88. //
  89. AddPathN(szSrcFile, s_lpszSlpFiles[0], AS(szSrcFile));
  90. if ( NO_ERROR == (dwErr = SetupInstallCatalog(szSrcFile)) )
  91. {
  92. TCHAR szDstCache[MAX_PATH],
  93. szDstSystem[MAX_PATH];
  94. LPTSTR lpszEndCache,
  95. lpszEndSystem;
  96. // Setup the destination folders.
  97. //
  98. GetDestFolder(szDstCache, AS(szDstCache), TRUE);
  99. GetDestFolder(szDstSystem, AS(szDstSystem), FALSE);
  100. lpszEndCache = szDstCache + lstrlen(szDstCache);
  101. lpszEndSystem = szDstSystem + lstrlen(szDstSystem);
  102. // Now copy all the files.
  103. //
  104. for ( x = 0; x < AS(s_lpszSlpFiles); x++ )
  105. {
  106. // First create the path to the source first (it stil has
  107. // the previous file on it, so chop it off first).
  108. //
  109. *lpszEndSrc = NULLCHR;
  110. AddPathN(szSrcFile, s_lpszSlpFiles[x], AS(szSrcFile));
  111. // Now copy it to the dll cache folder.
  112. //
  113. AddPathN(szDstCache, s_lpszSlpFiles[x], AS(szDstCache));
  114. if ( !CopySlpFile(szSrcFile, szDstCache) )
  115. {
  116. // No need to log, the copy function will do that for us.
  117. //
  118. bRet = FALSE;
  119. }
  120. *lpszEndCache = NULLCHR;
  121. // The cat file (which is the first one) does not get copied
  122. // to the system32 folder.
  123. //
  124. if ( x )
  125. {
  126. // Now copy it to the system folder.
  127. //
  128. AddPathN(szDstSystem, s_lpszSlpFiles[x], AS(szDstSystem));
  129. if ( !CopySlpFile(szSrcFile, szDstSystem) )
  130. {
  131. // No need to log, the copy function will do that for us.
  132. //
  133. bRet = FALSE;
  134. }
  135. *lpszEndSystem = NULLCHR;
  136. }
  137. }
  138. }
  139. else
  140. {
  141. // NEEDLOG: Log that the catalog could not be installed (error code is in dwErr).
  142. //
  143. bRet = FALSE;
  144. }
  145. }
  146. }
  147. else
  148. {
  149. // NEEDLOG: Log that the directory doesn't exist.
  150. //
  151. bRet = FALSE;
  152. }
  153. // Remove the network connection if we made one.
  154. //
  155. FactoryNetworkConnect(lpszSourcePath, lpStateData->lpszWinBOMPath, NULL, FALSE);
  156. // Free up the key read from the ini file.
  157. //
  158. FREE(lpszSourcePath);
  159. }
  160. else
  161. {
  162. // If the key isn't present, we still want to reinstall the cat file
  163. // in case they replaced the SLP files offline.
  164. //
  165. GetDestFolder(szSrcFile, AS(szSrcFile), TRUE);
  166. AddPathN(szSrcFile, s_lpszSlpFiles[0], AS(szSrcFile));
  167. if ( ( FileExists(szSrcFile) ) &&
  168. ( NO_ERROR != (dwErr = SetupInstallCatalog(szSrcFile)) ) )
  169. {
  170. // NEEDLOG: Log that the catalog could not be installed (error code is in dwErr).
  171. //
  172. bRet = FALSE;
  173. }
  174. }
  175. #endif
  176. return bRet;
  177. }
  178. BOOL DisplaySlpFiles(LPSTATEDATA lpStateData)
  179. {
  180. return IniSettingExists(lpStateData->lpszWinBOMPath, INI_SEC_WBOM_SETTINGS, INI_KEY_WBOM_SLPSOURCE, NULL);
  181. }
  182. //
  183. // Internal Function(s):
  184. //
  185. static void GetDestFolder(LPTSTR lpszDest, DWORD cbDest, BOOL bDllCache)
  186. {
  187. LPTSTR lpszData;
  188. // See if we want the dll cache folder, and check the registry key if we do.
  189. //
  190. if ( ( bDllCache ) &&
  191. ( lpszData = RegGetExpand(HKLM, REG_KEY_WINLOGON, REG_VAL_DLLCACHE) ) )
  192. {
  193. // Return the registry key.
  194. //
  195. lstrcpyn(lpszDest, lpszData, cbDest);
  196. FREE(lpszData);
  197. }
  198. else
  199. {
  200. // Get the main system directory and tack on the dll cache folder.
  201. //
  202. GetSystemWindowsDirectory(lpszDest, cbDest);
  203. AddPathN(lpszDest, DIR_SYSTEM, cbDest);
  204. if ( bDllCache )
  205. {
  206. AddPathN(lpszDest, DIR_DLLCACHE, cbDest);
  207. }
  208. }
  209. }
  210. static BOOL CopySlpFile(LPTSTR lpszSrc, LPTSTR lpszDst)
  211. {
  212. BOOL bRet = TRUE;
  213. // We make sure the source and destination are not the
  214. // same because the OEM might do something crazy like put
  215. // them in the dllcache folder.
  216. //
  217. if ( ( 0 != lstrcmpi(lpszSrc, lpszDst) ) &&
  218. ( !CopyFile(lpszSrc, lpszDst, FALSE) ) )
  219. {
  220. // NEEDLOG: Log the file that fails.
  221. //
  222. bRet = FALSE;
  223. }
  224. return bRet;
  225. }