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.

195 lines
3.3 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #include "precomp.h"
  8. #include <time.h>
  9. #include <wmimsg.h>
  10. #include "rpchdr.h"
  11. const DWORD g_dwSig = 0x6d696d77;
  12. const BYTE g_chVersionMajor = 1;
  13. const BYTE g_chVersionMinor = 0;
  14. /****************************************************************************
  15. CMsgRpcHdr
  16. *****************************************************************************/
  17. CMsgRpcHdr::CMsgRpcHdr( LPCWSTR wszSource, ULONG cAuxData )
  18. : m_wszSource( wszSource ), m_cAuxData( cAuxData )
  19. {
  20. GetSystemTime( &m_Time );
  21. }
  22. HRESULT CMsgRpcHdr::Unpersist( CBuffer& rStrm )
  23. {
  24. HRESULT hr;
  25. DWORD dwSig;
  26. BYTE chVersionMajor, chVersionMinor;
  27. //
  28. // read and verify signature.
  29. //
  30. hr = rStrm.Read( &dwSig, sizeof(DWORD), NULL );
  31. if ( hr != S_OK || dwSig != g_dwSig )
  32. {
  33. return WMIMSG_E_INVALIDMESSAGE;
  34. }
  35. //
  36. // read and check version major (currently no check).
  37. //
  38. hr = rStrm.Read( &chVersionMajor, 1, NULL );
  39. if ( hr != S_OK )
  40. {
  41. return WMIMSG_E_INVALIDMESSAGE;
  42. }
  43. //
  44. // read and check version minor (currently no check).
  45. //
  46. hr = rStrm.Read( &chVersionMinor, 1, NULL );
  47. if ( hr != S_OK )
  48. {
  49. return WMIMSG_E_INVALIDMESSAGE;
  50. }
  51. //
  52. // read reserved
  53. //
  54. DWORD dwReserved;
  55. hr = rStrm.Read( &dwReserved, sizeof(DWORD), NULL );
  56. if ( hr != S_OK )
  57. {
  58. return WMIMSG_E_INVALIDMESSAGE;
  59. }
  60. //
  61. // read source machine.
  62. //
  63. hr = rStrm.ReadLPWSTR( m_wszSource );
  64. if ( hr != S_OK )
  65. {
  66. return WMIMSG_E_INVALIDMESSAGE;
  67. }
  68. //
  69. // read sent time.
  70. //
  71. hr = rStrm.Read( &m_Time, sizeof(SYSTEMTIME), NULL );
  72. if ( hr != S_OK )
  73. {
  74. return WMIMSG_E_INVALIDMESSAGE;
  75. }
  76. //
  77. // read user header size.
  78. //
  79. hr = rStrm.Read( &m_cAuxData, sizeof(DWORD), NULL );
  80. if ( hr != S_OK )
  81. {
  82. return WMIMSG_E_INVALIDMESSAGE;
  83. }
  84. return WBEM_S_NO_ERROR;
  85. }
  86. HRESULT CMsgRpcHdr::Persist( CBuffer& rStrm )
  87. {
  88. HRESULT hr;
  89. hr = rStrm.Write( &g_dwSig, sizeof(DWORD), NULL );
  90. if ( FAILED(hr) )
  91. {
  92. return hr;
  93. }
  94. //
  95. // write version major.
  96. //
  97. hr = rStrm.Write( &g_chVersionMajor, 1, NULL );
  98. if ( FAILED(hr) )
  99. {
  100. return hr;
  101. }
  102. //
  103. // write version minor.
  104. //
  105. hr = rStrm.Write( &g_chVersionMinor, 1, NULL );
  106. if ( FAILED(hr) )
  107. {
  108. return hr;
  109. }
  110. //
  111. // write reserved flags ( currently not used ).
  112. //
  113. DWORD dwReserved = 0;
  114. hr = rStrm.Write( &dwReserved, sizeof(DWORD), NULL );
  115. if ( FAILED(hr) )
  116. {
  117. return hr;
  118. }
  119. //
  120. // write source machine
  121. //
  122. hr = rStrm.WriteLPWSTR( m_wszSource );
  123. if ( FAILED(hr) )
  124. {
  125. return hr;
  126. }
  127. //
  128. // write time sent.
  129. //
  130. hr = rStrm.Write( &m_Time, sizeof(SYSTEMTIME), NULL );
  131. if ( FAILED(hr) )
  132. {
  133. return hr;
  134. }
  135. //
  136. // write user hdr size.
  137. //
  138. return rStrm.Write( &m_cAuxData, sizeof(DWORD), NULL );
  139. }