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.

118 lines
2.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-1999.
  5. //
  6. // File: Persist.cpp
  7. //
  8. // Contents: Implementation of persistence
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "compdata.h"
  13. USE_HANDLE_MACROS("CERTTMPL(persist.cpp)")
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. PCWSTR PchGetMachineNameOverride(); // Defined in chooser.cpp
  20. /////////////////////////////////////////////////
  21. // The _dwMagicword is the internal version number.
  22. // Increment this number if you make a file format change.
  23. #define _dwMagicword 10002
  24. /////////////////////////////////////////////////////////////////////
  25. STDMETHODIMP CCertTmplComponentData::Load(IStream __RPC_FAR *pIStream)
  26. {
  27. HRESULT hr = S_OK;;
  28. #ifndef DONT_PERSIST
  29. ASSERT (pIStream);
  30. XSafeInterfacePtr<IStream> pIStreamSafePtr( pIStream );
  31. // Read the magic word from the stream
  32. DWORD dwMagicword;
  33. hr = pIStream->Read( OUT &dwMagicword, sizeof(dwMagicword), NULL );
  34. if ( FAILED(hr) )
  35. {
  36. ASSERT( FALSE );
  37. return hr;
  38. }
  39. if (dwMagicword != _dwMagicword)
  40. {
  41. // We have a version mismatch
  42. _TRACE(0, L"INFO: CCertTmplComponentData::Load() - Wrong Magicword. You need to re-save your .msc file.\n");
  43. return E_FAIL;
  44. }
  45. // read domain name from stream
  46. DWORD dwLen = 0;
  47. hr = pIStream->Read (&dwLen, 4, NULL);
  48. if ( FAILED (hr) )
  49. {
  50. ASSERT (FALSE);
  51. return hr;
  52. }
  53. ASSERT (dwLen <= MAX_PATH * sizeof (WCHAR));
  54. PCWSTR wcszDomainName = (PCWSTR) alloca (dwLen);
  55. hr = pIStream->Read ((PVOID) wcszDomainName, dwLen, NULL);
  56. if ( FAILED (hr) )
  57. {
  58. ASSERT (FALSE);
  59. return hr;
  60. }
  61. m_szManagedDomain = wcszDomainName;
  62. #endif
  63. return S_OK;
  64. }
  65. /////////////////////////////////////////////////////////////////////
  66. STDMETHODIMP CCertTmplComponentData::Save(IStream __RPC_FAR *pIStream, BOOL /*fSameAsLoad*/)
  67. {
  68. HRESULT hr = S_OK;
  69. #ifndef DONT_PERSIST
  70. ASSERT (pIStream);
  71. XSafeInterfacePtr<IStream> pIStreamSafePtr( pIStream );
  72. // Store the magic word to the stream
  73. DWORD dwMagicword = _dwMagicword;
  74. hr = pIStream->Write( IN &dwMagicword, sizeof(dwMagicword), NULL );
  75. if ( FAILED(hr) )
  76. {
  77. ASSERT( FALSE );
  78. return hr;
  79. }
  80. // Persist m_szManagedDomain length and m_szManagedDomain
  81. PCWSTR wcszDomainName = m_szManagedDomain;
  82. size_t dwLen = (::wcslen (wcszDomainName) + 1) * sizeof (WCHAR);
  83. ASSERT( 4 == sizeof(DWORD) );
  84. hr = pIStream->Write (&dwLen, 4, NULL);
  85. if ( FAILED(hr) )
  86. {
  87. ASSERT( FALSE );
  88. return hr;
  89. }
  90. hr = pIStream->Write (wcszDomainName, (ULONG) dwLen, NULL);
  91. if ( FAILED (hr) )
  92. {
  93. ASSERT (FALSE);
  94. return hr;
  95. }
  96. #endif
  97. return S_OK;
  98. }