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.

142 lines
3.6 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. typedef void (STDAPICALLTYPE *PFN_FORCENEXUSLOOKUP)(void);
  24. PFN_FORCENEXUSLOOKUP pfnForceNexusLookup = (PFN_FORCENEXUSLOOKUP)GetProcAddress(hm, "ForceNexusLookup");
  25. if (pfnForceNexusLookup)
  26. {
  27. pfnForceNexusLookup();
  28. }
  29. FreeLibrary(hm);
  30. }
  31. }
  32. HWND _VariantToHWND(const VARIANT& varOwner)
  33. {
  34. HWND hwndResult = NULL;
  35. if (VT_BSTR == varOwner.vt && varOwner.bstrVal && *varOwner.bstrVal != TEXT('\0'))
  36. {
  37. hwndResult = FindWindow(NULL, varOwner.bstrVal);
  38. }
  39. return hwndResult;
  40. }
  41. //
  42. // IPassportManager Interface
  43. //
  44. STDMETHODIMP CPassportManager::get_currentPassport(BSTR* pbstrPassport)
  45. {
  46. if (!pbstrPassport)
  47. return E_POINTER;
  48. *pbstrPassport = NULL;
  49. LPWSTR pszCred = NULL;
  50. if (ERROR_SUCCESS == CredUIReadSSOCredW(NULL, &pszCred))
  51. {
  52. *pbstrPassport = SysAllocString(pszCred);
  53. LocalFree(pszCred);
  54. }
  55. return S_OK;
  56. }
  57. STDMETHODIMP CPassportManager::get_memberServicesURL(BSTR* pbstrURL)
  58. {
  59. if (!pbstrURL)
  60. return E_POINTER;
  61. *pbstrURL = NULL;
  62. BSTR bstrURL = SysAllocStringLen(NULL, INTERNET_MAX_URL_LENGTH);
  63. if (!bstrURL)
  64. return E_OUTOFMEMORY;
  65. // This ensures that the correct reg values are populated.
  66. PassportForceNexusRepopulate();
  67. // Try HKEY_CURRENT_USER first
  68. DWORD cbData = SysStringByteLen(bstrURL);
  69. DWORD dwErr = SHGetValue(HKEY_CURRENT_USER, c_szWininetKey, c_szMemberServicesVal, NULL, bstrURL, &cbData);
  70. if (ERROR_SUCCESS != dwErr)
  71. {
  72. // Not under HKEY_CURRENT_USER, try HKEY_LOCAL_MACHINE instead
  73. cbData = SysStringByteLen(bstrURL);
  74. dwErr = SHGetValue(HKEY_LOCAL_MACHINE, c_szWininetKey, c_szMemberServicesVal, NULL, bstrURL, &cbData);
  75. }
  76. if (ERROR_SUCCESS != dwErr)
  77. {
  78. SysFreeString(bstrURL);
  79. bstrURL = NULL;
  80. }
  81. *pbstrURL = bstrURL;
  82. return S_OK;
  83. }
  84. STDMETHODIMP CPassportManager::showWizard(VARIANT varOwner, VARIANT_BOOL *pbRet)
  85. {
  86. if (!pbRet)
  87. return E_POINTER;
  88. *pbRet = VARIANT_FALSE;
  89. IPassportWizard *pPW;
  90. if (SUCCEEDED(CoCreateInstance(CLSID_PassportWizard, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IPassportWizard, &pPW))))
  91. {
  92. pPW->SetOptions(PPW_LAUNCHEDBYUSER);
  93. if (S_OK == pPW->Show(_VariantToHWND(varOwner)))
  94. {
  95. *pbRet = VARIANT_TRUE;
  96. }
  97. pPW->Release();
  98. }
  99. return S_OK;
  100. }
  101. STDMETHODIMP CPassportManager::showKeyManager(VARIANT varOwner, VARIANT_BOOL *pbRet)
  102. {
  103. if (!pbRet)
  104. return E_POINTER;
  105. // This returns void, so we claim to always succeed
  106. KRShowKeyMgr(_VariantToHWND(varOwner), NULL, NULL, 0);
  107. *pbRet = VARIANT_TRUE;
  108. return S_OK;
  109. }