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.

194 lines
5.9 KiB

  1. #include <windows.h>
  2. #include <regstr.h>
  3. #include "sdsutils.h"
  4. const char c_szUNINSTALLDAT[]="ie6bak.dat";
  5. const char c_szUNINSTALLINI[] = "ie6bak.ini";
  6. const char c_szIE4SECTIONNAME[] = "backup";
  7. const char c_szIE4_OPTIONS[] = "Software\\Microsoft\\IE Setup\\Options";
  8. const char c_szIE4_UNINSTALLDIR[] = "UninstallDir";
  9. // the following functions are stolen from ie4.dll
  10. BOOL FileVerGreaterOrEqual(LPSTR lpszFileName, DWORD dwReqMSVer, DWORD dwReqLSVer)
  11. {
  12. DWORD dwMSVer, dwLSVer;
  13. MyGetVersionFromFile(lpszFileName, &dwMSVer, &dwLSVer, TRUE);
  14. return ((dwMSVer > dwReqMSVer) || ((dwMSVer == dwReqMSVer) && (dwLSVer >= dwReqLSVer)));
  15. }
  16. void BuildPath( char *szPath, const char *szDirPath, const char *szFileName )
  17. {
  18. lstrcpy( szPath, szDirPath );
  19. AddPath( szPath, szFileName );
  20. }
  21. ULONG FileSize( LPSTR lpFile )
  22. {
  23. ULONG ulFileSize = (ULONG) -1;
  24. WIN32_FIND_DATA FindFileData;
  25. HANDLE hFile;
  26. if ( lpFile == NULL || *lpFile == 0 )
  27. return ulFileSize;
  28. if ((hFile = FindFirstFile( lpFile, &FindFileData )) != INVALID_HANDLE_VALUE)
  29. {
  30. ulFileSize = (FindFileData.nFileSizeHigh * MAXDWORD) + FindFileData.nFileSizeLow;
  31. FindClose( hFile );
  32. }
  33. return ulFileSize;
  34. }
  35. BOOL ValidateUninstallFiles(LPSTR lpszPath)
  36. {
  37. HKEY hKey;
  38. DWORD dwType;
  39. DWORD dwValue;
  40. DWORD dwSize;
  41. char szTmp[MAX_PATH];
  42. BOOL bValidFiles = FALSE;
  43. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szIE4_OPTIONS, 0, KEY_READ, &hKey))
  44. {
  45. dwSize = sizeof(dwValue);
  46. if ( RegQueryValueEx(hKey, c_szUNINSTALLDAT, NULL, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS )
  47. {
  48. BuildPath(szTmp, lpszPath, c_szUNINSTALLDAT);
  49. if (dwType == REG_DWORD)
  50. bValidFiles = (dwValue == FileSize(szTmp));
  51. }
  52. if (bValidFiles)
  53. {
  54. dwSize = sizeof(dwValue);
  55. if ( RegQueryValueEx(hKey, c_szUNINSTALLINI, NULL, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS )
  56. {
  57. BuildPath(szTmp, lpszPath, c_szUNINSTALLINI);
  58. if (dwType == REG_DWORD)
  59. bValidFiles = (dwValue == FileSize(szTmp));
  60. }
  61. }
  62. RegCloseKey(hKey);
  63. }
  64. return bValidFiles;
  65. }
  66. BOOL GetUninstallDirFromReg(LPSTR lpszUninstallDir)
  67. {
  68. HKEY hKey;
  69. DWORD dwType;
  70. char szValue[MAX_PATH];
  71. DWORD dwSize = MAX_PATH;
  72. *szValue = '\0';
  73. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szIE4_OPTIONS, 0, KEY_READ, &hKey))
  74. {
  75. if ( RegQueryValueEx(hKey, c_szIE4_UNINSTALLDIR, NULL, &dwType, (LPBYTE) szValue, &dwSize) == ERROR_SUCCESS )
  76. {
  77. if (lpszUninstallDir)
  78. lstrcpy (lpszUninstallDir, szValue);
  79. }
  80. RegCloseKey(hKey);
  81. }
  82. return (*szValue != '\0');
  83. }
  84. BOOL FileBackupEntryExists(LPCSTR lpcszFileName)
  85. {
  86. BOOL bRet = FALSE;
  87. char szPath[MAX_PATH];
  88. if (GetUninstallDirFromReg(szPath) && ValidateUninstallFiles(szPath))
  89. {
  90. char szPath[MAX_PATH];
  91. // Get backup directory from registry
  92. if (GetUninstallDirFromReg(szPath))
  93. {
  94. DWORD dwSaveAttribs;
  95. char szLine[MAX_PATH];
  96. AddPath(szPath, c_szUNINSTALLINI);
  97. // c_szUNINSTALLINI has HR attribs set; GetPrivateProfileString might fail because of HR attribs.
  98. // set the attribs to normal and restore the original attribs at the end
  99. dwSaveAttribs = GetFileAttributes(szPath);
  100. SetFileAttributes(szPath, FILE_ATTRIBUTE_NORMAL);
  101. bRet = (GetPrivateProfileString(c_szIE4SECTIONNAME, lpcszFileName, "", szLine, sizeof(szLine), szPath) != 0);
  102. if (dwSaveAttribs != (DWORD) -1)
  103. SetFileAttributes(szPath, dwSaveAttribs);
  104. }
  105. }
  106. return bRet;
  107. }
  108. #define REGSTR_CCS_CONTROL_WINDOWS REGSTR_PATH_CURRENT_CONTROL_SET "\\WINDOWS"
  109. #define CSDVERSION "CSDVersion"
  110. #define NTSP6_VERSION 0x0600
  111. // version updated to SP6!
  112. BOOL CheckForNT4_SP6()
  113. {
  114. HKEY hKey;
  115. DWORD dwCSDVersion;
  116. DWORD dwSize;
  117. static BOOL bNTSP6 = -1;
  118. if ( bNTSP6 == -1)
  119. {
  120. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_CCS_CONTROL_WINDOWS, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
  121. {
  122. // assign the default
  123. bNTSP6 = FALSE;
  124. dwSize = sizeof(dwCSDVersion);
  125. if (RegQueryValueEx(hKey, CSDVERSION, NULL, NULL, (unsigned char*)&dwCSDVersion, &dwSize) == ERROR_SUCCESS)
  126. {
  127. bNTSP6 = (LOWORD(dwCSDVersion) >= NTSP6_VERSION);
  128. }
  129. RegCloseKey(hKey);
  130. }
  131. }
  132. return bNTSP6;
  133. }
  134. #define SP4_CRYPT32_DLL_MAJOR_VER 0x00050083 // 5.131
  135. #define SP4_CRYPT32_DLL_MINOR_VER 0x07550005 // 1877.5 = SP6 level
  136. BOOL FSP4LevelCryptoInstalled()
  137. {
  138. static BOOL bSP4LevelCryptoInstalled = 2;
  139. if (bSP4LevelCryptoInstalled == 2)
  140. {
  141. OSVERSIONINFO VerInfo;
  142. bSP4LevelCryptoInstalled = FALSE;
  143. VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  144. GetVersionEx(&VerInfo);
  145. if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
  146. {
  147. char szCrypt32DLL[MAX_PATH];
  148. GetSystemDirectory(szCrypt32DLL, sizeof(szCrypt32DLL));
  149. AddPath(szCrypt32DLL, "crypt32.dll");
  150. // we have to distinguish the case when a user is upgrading or reinstalling IE5; in this case,
  151. // backup entry for crypt32.dll would exist in ie5bak.ini and bSP4LevelCryptoInstalled should be set to FALSE
  152. if (VerInfo.dwMajorVersion >= 5 || CheckForNT4_SP6() ||
  153. (FileVerGreaterOrEqual(szCrypt32DLL, SP4_CRYPT32_DLL_MAJOR_VER, SP4_CRYPT32_DLL_MINOR_VER) &&
  154. !FileBackupEntryExists(szCrypt32DLL)))
  155. bSP4LevelCryptoInstalled = TRUE;
  156. }
  157. }
  158. return bSP4LevelCryptoInstalled;
  159. }