aboutinf.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 9k
Category:

Windows Kernel

Development Platform:

Visual C++

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