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.

141 lines
3.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 2000.
  5. //
  6. // File: PassportManager.cpp
  7. //
  8. // Contents: implementation of CPassportManager
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "passportmanager.h"
  13. #include <wincrui.h> // credui
  14. #include <wininet.h> // INTERNET_MAX_URL_LENGTH
  15. #include <keymgr.h> // KRShowKeyMgr
  16. const TCHAR c_szWininetKey[] = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Passport");
  17. const TCHAR c_szMemberServicesVal[] = TEXT("Properties");
  18. void PassportForceNexusRepopulate()
  19. {
  20. HMODULE hm = LoadLibrary(TEXT("wininet.dll"));
  21. if (hm)
  22. {
  23. FARPROC fp = GetProcAddress(hm, "ForceNexusLookup");
  24. if (fp)
  25. {
  26. (*fp)();
  27. }
  28. FreeLibrary(hm);
  29. }
  30. }
  31. HWND _VariantToHWND(const VARIANT& varOwner)
  32. {
  33. HWND hwndResult = NULL;
  34. if (VT_BSTR == varOwner.vt && varOwner.bstrVal && *varOwner.bstrVal != TEXT('\0'))
  35. {
  36. hwndResult = FindWindow(NULL, varOwner.bstrVal);
  37. }
  38. return hwndResult;
  39. }
  40. //
  41. // IPassportManager Interface
  42. //
  43. STDMETHODIMP CPassportManager::get_currentPassport(BSTR* pbstrPassport)
  44. {
  45. if (!pbstrPassport)
  46. return E_POINTER;
  47. *pbstrPassport = NULL;
  48. LPWSTR pszCred = NULL;
  49. if (ERROR_SUCCESS == CredUIReadSSOCredW(NULL, &pszCred))
  50. {
  51. *pbstrPassport = SysAllocString(pszCred);
  52. LocalFree(pszCred);
  53. }
  54. return S_OK;
  55. }
  56. STDMETHODIMP CPassportManager::get_memberServicesURL(BSTR* pbstrURL)
  57. {
  58. if (!pbstrURL)
  59. return E_POINTER;
  60. *pbstrURL = NULL;
  61. BSTR bstrURL = SysAllocStringLen(NULL, INTERNET_MAX_URL_LENGTH);
  62. if (!bstrURL)
  63. return E_OUTOFMEMORY;
  64. // This ensures that the correct reg values are populated.
  65. PassportForceNexusRepopulate();
  66. // Try HKEY_CURRENT_USER first
  67. DWORD cbData = SysStringByteLen(bstrURL);
  68. DWORD dwErr = SHGetValue(HKEY_CURRENT_USER, c_szWininetKey, c_szMemberServicesVal, NULL, bstrURL, &cbData);
  69. if (ERROR_SUCCESS != dwErr)
  70. {
  71. // Not under HKEY_CURRENT_USER, try HKEY_LOCAL_MACHINE instead
  72. cbData = SysStringByteLen(bstrURL);
  73. dwErr = SHGetValue(HKEY_LOCAL_MACHINE, c_szWininetKey, c_szMemberServicesVal, NULL, bstrURL, &cbData);
  74. }
  75. if (ERROR_SUCCESS != dwErr)
  76. {
  77. SysFreeString(bstrURL);
  78. bstrURL = NULL;
  79. }
  80. *pbstrURL = bstrURL;
  81. return S_OK;
  82. }
  83. STDMETHODIMP CPassportManager::showWizard(VARIANT varOwner, VARIANT_BOOL *pbRet)
  84. {
  85. if (!pbRet)
  86. return E_POINTER;
  87. *pbRet = VARIANT_FALSE;
  88. IPassportWizard *pPW;
  89. if (SUCCEEDED(CoCreateInstance(CLSID_PassportWizard, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IPassportWizard, &pPW))))
  90. {
  91. pPW->SetOptions(PPW_LAUNCHEDBYUSER);
  92. if (S_OK == pPW->Show(_VariantToHWND(varOwner)))
  93. {
  94. *pbRet = VARIANT_TRUE;
  95. }
  96. pPW->Release();
  97. }
  98. return S_OK;
  99. }
  100. STDMETHODIMP CPassportManager::showKeyManager(VARIANT varOwner, VARIANT_BOOL *pbRet)
  101. {
  102. if (!pbRet)
  103. return E_POINTER;
  104. // This returns void, so we claim to always succeed
  105. KRShowKeyMgr(_VariantToHWND(varOwner), NULL, NULL, 0);
  106. *pbRet = VARIANT_TRUE;
  107. return S_OK;
  108. }