Source code of Windows XP (NT5)
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.

323 lines
10 KiB

  1. #include <string.h>
  2. #include <ntverp.h>
  3. #include "priv.h"
  4. #include "ids.h"
  5. #define SECURITY_WIN32
  6. #include <schnlsp.h> //for UNISP_NAME_A
  7. #include <sspi.h> //for SCHANNEL.dll api -- to obtain encryption key size
  8. #include <mluisupp.h>
  9. #include <wininet.h> // INTERNET_MAX_URL_LENGTH
  10. #define MAX_REG_VALUE 256
  11. // Some Static strings that we use to read from the registry
  12. #ifdef UNIX
  13. #define VERSION "IEUNIX Version"
  14. #define UNIX_IE_PRODUCT_ID TEXT("86139-999-2001594-12504")
  15. #ifndef ux10
  16. #define UNIX_IE_PRODUCT_FILE TEXT("%MWDEV%/ie/setup/sunos5/.iepid")
  17. #else
  18. #define UNIX_IE_PRODUCT_FILE TEXT("%MWDEV%/ie/setup/ux10/.iepid")
  19. #endif
  20. #endif
  21. typedef PSecurityFunctionTable (APIENTRY *INITSECURITYINTERFACE_FN_A) (VOID);
  22. // Returns the maximum cipher strength
  23. DWORD GetCipherStrength()
  24. {
  25. DWORD dwKeySize = 0;
  26. HINSTANCE hSecurity;
  27. INITSECURITYINTERFACE_FN_A pfnInitSecurityInterfaceA;
  28. PSecurityFunctionTable pSecFuncTable;
  29. //
  30. // Can't go directly to schannel on NT5. (Note that g_bRunningOnNT5OrHigher
  31. // may not be initialized when fUseSChannel is initialized!)
  32. //
  33. static BOOL fUseSChannel = TRUE;
  34. if (fUseSChannel && !g_bRunningOnNT5OrHigher)
  35. {
  36. //
  37. // This is better for performance. Rather than call through
  38. // SSPI, we go right to the DLL doing the work.
  39. //
  40. hSecurity = LoadLibrary("schannel");
  41. }
  42. else
  43. {
  44. //
  45. // Use SSPI
  46. //
  47. if (g_bRunningOnNT)
  48. {
  49. hSecurity = LoadLibrary("security");
  50. }
  51. else
  52. {
  53. hSecurity = LoadLibrary("secur32");
  54. }
  55. }
  56. if (hSecurity == NULL)
  57. {
  58. return 0;
  59. }
  60. //
  61. // Get the SSPI dispatch table
  62. //
  63. pfnInitSecurityInterfaceA =
  64. (INITSECURITYINTERFACE_FN_A)GetProcAddress(hSecurity, "InitSecurityInterfaceA");
  65. if (pfnInitSecurityInterfaceA == NULL)
  66. {
  67. goto exit;
  68. }
  69. pSecFuncTable = (PSecurityFunctionTable)((*pfnInitSecurityInterfaceA)());
  70. if (pSecFuncTable == NULL)
  71. {
  72. goto exit;
  73. }
  74. if (pSecFuncTable->AcquireCredentialsHandleA && pSecFuncTable->QueryCredentialsAttributesA)
  75. {
  76. TimeStamp tsExpiry;
  77. CredHandle chCred;
  78. SecPkgCred_CipherStrengths cs;
  79. if (SEC_E_OK == (*pSecFuncTable->AcquireCredentialsHandleA)(NULL,
  80. UNISP_NAME_A, // Package
  81. SECPKG_CRED_OUTBOUND,
  82. NULL,
  83. NULL,
  84. NULL,
  85. NULL,
  86. &chCred, // Handle
  87. &tsExpiry ))
  88. {
  89. if (SEC_E_OK == (*pSecFuncTable->QueryCredentialsAttributesA)(&chCred, SECPKG_ATTR_CIPHER_STRENGTHS, &cs))
  90. {
  91. dwKeySize = cs.dwMaximumCipherStrength;
  92. }
  93. // Free the handle if we can
  94. if (pSecFuncTable->FreeCredentialsHandle)
  95. {
  96. (*pSecFuncTable->FreeCredentialsHandle)(&chCred);
  97. }
  98. }
  99. }
  100. exit:
  101. FreeLibrary(hSecurity);
  102. if (dwKeySize == 0 && fUseSChannel)
  103. {
  104. // Failed, so retry using SSPI
  105. fUseSChannel = FALSE;
  106. dwKeySize = GetCipherStrength();
  107. }
  108. return dwKeySize;
  109. }
  110. BOOL SHAboutInfoA(LPSTR lpszInfo, DWORD cchSize)
  111. {
  112. HKEY hkey;
  113. char szVersion[64];
  114. char szUserName[MAX_REG_VALUE];
  115. char szCompanyName[MAX_REG_VALUE];
  116. char szKeySize[11];
  117. char szProductId[MAX_REG_VALUE];
  118. char szUpdateUrl[INTERNET_MAX_URL_LENGTH];
  119. char szIEAKStr[MAX_REG_VALUE];
  120. LPSTR lpszAboutKey;
  121. DWORD dwKeySize = 0;
  122. DWORD cb;
  123. DWORD dwType;
  124. BOOL fIEOrShell = TRUE;
  125. lpszInfo[0] = '\0';
  126. szKeySize[0] = '\0';
  127. #ifndef UNIX
  128. // Are we in the explorer or IE process?
  129. fIEOrShell = GetModuleHandle("EXPLORER.EXE") || GetModuleHandle("IEXPLORE.EXE");
  130. if (g_bRunningOnNT)
  131. lpszAboutKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
  132. else
  133. #endif
  134. lpszAboutKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion";
  135. if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, lpszAboutKey, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
  136. {
  137. // get the encription key size
  138. dwKeySize = GetCipherStrength();
  139. wsprintf(szKeySize, "~%d", dwKeySize);
  140. // get the custom IEAK update url
  141. // (always get from Windows\CurrentVersion because IEAK policy file must be platform
  142. // independent
  143. cb = sizeof(szUpdateUrl);
  144. if(SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion",
  145. "IEAKUpdateUrl", &dwType, (LPBYTE)szUpdateUrl, &cb) != ERROR_SUCCESS)
  146. szUpdateUrl[0] = '\0';
  147. #ifndef UNIX
  148. // Extra Whistler/IE6 code to get the VBL version info
  149. {
  150. char szVBLVersion[64];
  151. char* pszBuildLabKey;
  152. DWORD cbSize;
  153. DWORD dwType;
  154. if (g_bRunningOnNT)
  155. {
  156. pszBuildLabKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
  157. }
  158. else
  159. {
  160. pszBuildLabKey = "SOFTWARE\\Microsoft\\Internet Explorer";
  161. }
  162. cbSize = sizeof(szVBLVersion);
  163. if ((SHGetValueA(HKEY_LOCAL_MACHINE,
  164. pszBuildLabKey,
  165. "BuildLab",
  166. &dwType,
  167. szVBLVersion,
  168. &cbSize) == ERROR_SUCCESS) && (dwType == REG_SZ))
  169. {
  170. // Now szVBLVersion contains the VBL buildnumber in the format: "2204.reinerf.010700"
  171. // Since we are only interested in the latter part, we remove the build # (first 4 digits)
  172. memmove((void*)szVBLVersion, (void*)&szVBLVersion[4], (lstrlenA(szVBLVersion) + 1) * sizeof(char));
  173. }
  174. else
  175. {
  176. szVBLVersion[0] = '\0';
  177. }
  178. // get the Version number (version string is in the following format 5.00.xxxx.x)
  179. szVersion[0] = '\0';
  180. cb = sizeof(szVersion);
  181. if (ERROR_SUCCESS == SHGetValueA(HKEY_LOCAL_MACHINE,
  182. "SOFTWARE\\Microsoft\\Internet Explorer",
  183. "Version", &dwType, (LPVOID)szVersion, &cb))
  184. {
  185. DWORD dwLen;
  186. // if we have a szVBLVersion, tack it onto the end of the IE major/minor version string
  187. if (*szVBLVersion)
  188. {
  189. lstrcatnA(szVersion, szVBLVersion, ARRAYSIZE(szVersion));
  190. }
  191. // added by pritobla on 9/1/98
  192. // CustomizedVersion contains a 2-letter code that identifies what mode was used
  193. // (CORP, ICP, ISP, etc.) in building this version IE using the IEAK.
  194. dwLen = lstrlenA(szVersion);
  195. cb = sizeof(szVersion) - (dwLen * sizeof(char));
  196. SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer",
  197. "CustomizedVersion", &dwType, (LPVOID)&szVersion[dwLen], &cb);
  198. }
  199. }
  200. #else
  201. // Get the version details from ntverp.h / ieverp.h
  202. sprintf(szVersion, "%s.%04d.%04d",VER_PRODUCTVERSION_STRING,
  203. VER_PRODUCTBUILD,
  204. VER_PRODUCTBUILD_QFE);
  205. #endif // UNIX
  206. if (!fIEOrShell)
  207. {
  208. // Not in the explorer or iexplore process so we are doing some side by side stuff so
  209. // reflect this in the version string. Maybe we should get the version out of MSHTML
  210. // but not sure since this still doesn't reflect IE4 or IE5 properly anyway.
  211. MLLoadString(IDS_SIDEBYSIDE, szVersion, ARRAYSIZE(szVersion));
  212. }
  213. // get the custom IEAK branded help string
  214. cb = sizeof(szIEAKStr);
  215. if(RegQueryValueExA(hkey, "IEAKHelpString", 0, &dwType, (LPBYTE)szIEAKStr, &cb) != ERROR_SUCCESS)
  216. szIEAKStr[0] = '\0';
  217. // get the User name.
  218. cb = sizeof(szUserName);
  219. if(RegQueryValueExA(hkey, "RegisteredOwner", 0, &dwType, (LPBYTE)szUserName, &cb) != ERROR_SUCCESS)
  220. szUserName[0] = '\0';
  221. // get the Organization name.
  222. cb = sizeof(szCompanyName);
  223. if(RegQueryValueExA(hkey, "RegisteredOrganization", 0, &dwType, (LPBYTE)szCompanyName, &cb) != ERROR_SUCCESS)
  224. szCompanyName[0] = '\0';
  225. #ifndef UNIX
  226. cb = sizeof(szProductId);
  227. if (SHGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Registration", "ProductId", &dwType, (LPVOID)szProductId, &cb) != ERROR_SUCCESS)
  228. {
  229. szProductId[0] = '\0';
  230. }
  231. #else
  232. HANDLE hPidFile;
  233. char szPidFileName[MAX_PATH];
  234. DWORD dwRead;
  235. SHExpandEnvironmentStrings(UNIX_IE_PRODUCT_FILE, szPidFileName, MAX_PATH);
  236. if ((hPidFile = CreateFileA(szPidFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
  237. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))
  238. == INVALID_HANDLE_VALUE)
  239. {
  240. sprintf(szProductId, "%s", UNIX_IE_PRODUCT_ID);
  241. }
  242. else
  243. {
  244. ReadFile(hPidFile, (LPVOID)szProductId, 23, &dwRead, NULL);
  245. szProductId[dwRead] = 0;
  246. }
  247. CloseHandle(hPidFile);
  248. #endif
  249. lstrcatn(lpszInfo, szVersion, cchSize);
  250. lstrcatn(lpszInfo, "~", cchSize);
  251. lstrcatn(lpszInfo, szUserName, cchSize);
  252. lstrcatn(lpszInfo, "~", cchSize);
  253. lstrcatn(lpszInfo, szCompanyName, cchSize);
  254. lstrcatn(lpszInfo, szKeySize, cchSize);
  255. lstrcatn(lpszInfo, "~", cchSize);
  256. lstrcatn(lpszInfo, szProductId, cchSize);
  257. lstrcatn(lpszInfo, "~", cchSize);
  258. lstrcatn(lpszInfo, szUpdateUrl, cchSize);
  259. lstrcatn(lpszInfo, "~", cchSize);
  260. lstrcatn(lpszInfo, szIEAKStr, cchSize);
  261. RegCloseKey(hkey);
  262. }
  263. else
  264. return FALSE;
  265. return TRUE;
  266. }
  267. BOOL SHAboutInfoW(LPWSTR lpszInfo, DWORD cchSize)
  268. {
  269. LPSTR lpszTmp;
  270. BOOL bRet = FALSE;
  271. lpszInfo[0] = L'\0';
  272. if(NULL != (lpszTmp = (LPSTR)LocalAlloc(LPTR, cchSize)))
  273. if(SHAboutInfoA(lpszTmp, cchSize))
  274. if(MultiByteToWideChar(CP_ACP, 0, lpszTmp, -1, lpszInfo, cchSize) != 0)
  275. bRet = TRUE;
  276. if(lpszTmp)
  277. LocalFree(lpszTmp);
  278. return bRet;
  279. }