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.

62 lines
1.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2002.
  5. //
  6. // File: secret.cxx
  7. //
  8. // Contents: Tiny object for wrapping creation & access to a
  9. // guid "secret" for various uses.
  10. //
  11. // History: 09-Oct-02 JSimmons Created
  12. //
  13. //+-------------------------------------------------------------------------
  14. #include <ole2int.h>
  15. #include "secret.hxx"
  16. CProcessSecret gProcessSecret;
  17. // Definitions of statics
  18. GUID CProcessSecret::s_guidOle32Secret = GUID_NULL;
  19. BOOL CProcessSecret::s_fSecretInit = FALSE;
  20. COleStaticMutexSem CProcessSecret::s_SecretLock; // Prevent races on block init
  21. HRESULT CProcessSecret::VerifyMatchingSecret(GUID guidOutsideSecret)
  22. {
  23. GUID guidProcessSecret;
  24. HRESULT hr = GetProcessSecret(&guidProcessSecret);
  25. if (SUCCEEDED(hr))
  26. {
  27. hr = (guidProcessSecret == guidOutsideSecret) ? S_OK : E_INVALIDARG;
  28. }
  29. return hr;
  30. }
  31. HRESULT CProcessSecret::GetProcessSecret(GUID* pguidProcessSecret)
  32. {
  33. HRESULT hr = S_OK;
  34. if (!s_fSecretInit)
  35. {
  36. COleStaticLock lock(s_SecretLock);
  37. if (!s_fSecretInit)
  38. {
  39. hr = CoCreateGuid(&s_guidOle32Secret);
  40. if (SUCCEEDED(hr))
  41. {
  42. s_fSecretInit = TRUE;
  43. }
  44. }
  45. }
  46. if (s_fSecretInit)
  47. {
  48. *pguidProcessSecret = s_guidOle32Secret;
  49. Win4Assert(s_guidOle32Secret != GUID_NULL);
  50. }
  51. return hr;
  52. }