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.

361 lines
6.5 KiB

  1. #include "precomp.h"
  2. #include <stdio.h>
  3. #include <wmimsg.h>
  4. #include "fwdhdr.h"
  5. const DWORD g_dwSig = 0x66696d77;
  6. const BYTE g_chVersionMajor = 1;
  7. const BYTE g_chVersionMinor = 0;
  8. const BYTE g_achPad[] = { 0, 0, 0 };
  9. /**************************************************************************
  10. CFwdMsgHeader
  11. ***************************************************************************/
  12. CFwdMsgHeader::CFwdMsgHeader()
  13. {
  14. ZeroMemory( this, sizeof( CFwdMsgHeader ) );
  15. }
  16. CFwdMsgHeader::CFwdMsgHeader( DWORD dwNumObjs,
  17. DWORD dwQos,
  18. BOOL bAuth,
  19. BOOL bEncrypt,
  20. GUID& rguidExecution,
  21. LPCWSTR wszConsumer,
  22. LPCWSTR wszNamespace,
  23. PBYTE pTargetSD,
  24. ULONG cTargetSD )
  25. : m_dwNumObjs(dwNumObjs), m_chQos(char(dwQos)),
  26. m_chEncrypt(char(bEncrypt)), m_wszConsumer( wszConsumer ),
  27. m_guidExecution(rguidExecution), m_chAuth(char(bAuth)),
  28. m_pTargetSD( pTargetSD ), m_cTargetSD( cTargetSD ),
  29. m_wszNamespace( wszNamespace )
  30. {
  31. }
  32. HRESULT CFwdMsgHeader::Persist( CBuffer& rStrm )
  33. {
  34. HRESULT hr;
  35. //
  36. // write signature.
  37. //
  38. hr = rStrm.Write( &g_dwSig, 4, NULL );
  39. if ( FAILED(hr) )
  40. {
  41. return hr;
  42. }
  43. //
  44. // write version major.
  45. //
  46. hr = rStrm.Write( &g_chVersionMajor, 1, NULL );
  47. if ( FAILED(hr) )
  48. {
  49. return hr;
  50. }
  51. //
  52. // write version minor.
  53. //
  54. hr = rStrm.Write( &g_chVersionMinor, 1, NULL );
  55. if ( FAILED(hr) )
  56. {
  57. return hr;
  58. }
  59. //
  60. // write reserved flags ( currently not used ).
  61. //
  62. DWORD dwReserved = 0;
  63. hr = rStrm.Write( &dwReserved, sizeof(DWORD), NULL );
  64. if ( FAILED(hr) )
  65. {
  66. return hr;
  67. }
  68. //
  69. // write num events contained in data.
  70. //
  71. hr = rStrm.Write( &m_dwNumObjs, sizeof(DWORD), NULL );
  72. if ( FAILED(hr) )
  73. {
  74. return hr;
  75. }
  76. //
  77. // write Qos used
  78. //
  79. hr = rStrm.Write( &m_chQos, 1, NULL );
  80. if ( FAILED(hr) )
  81. {
  82. return hr;
  83. }
  84. //
  85. // write if Auth was used.
  86. //
  87. hr = rStrm.Write( &m_chAuth, 1, NULL );
  88. if ( FAILED(hr) )
  89. {
  90. return hr;
  91. }
  92. //
  93. // write if Encryption was used.
  94. //
  95. hr = rStrm.Write( &m_chEncrypt, 1, NULL );
  96. if ( FAILED(hr) )
  97. {
  98. return hr;
  99. }
  100. //
  101. // pad so that subsequent strings will at least be on 2 byte boundaries
  102. //
  103. hr = rStrm.Write( g_achPad, 1, NULL );
  104. if ( FAILED(hr) )
  105. {
  106. return hr;
  107. }
  108. //
  109. // write execution id.
  110. //
  111. hr = rStrm.Write( &m_guidExecution, sizeof(GUID), NULL );
  112. if ( FAILED(hr) )
  113. {
  114. return hr;
  115. }
  116. //
  117. // write name of forwarding consumer
  118. //
  119. hr = rStrm.WriteLPWSTR( m_wszConsumer );
  120. if ( FAILED(hr) )
  121. {
  122. return hr;
  123. }
  124. //
  125. // write the namespace of the forwarding consumer
  126. //
  127. hr = rStrm.WriteLPWSTR( m_wszNamespace );
  128. if ( FAILED(hr) )
  129. {
  130. return hr;
  131. }
  132. //
  133. // write SD used for the event at Target.
  134. //
  135. hr = rStrm.Write( &m_cTargetSD, sizeof(DWORD), NULL );
  136. if ( FAILED(hr) )
  137. {
  138. return hr;
  139. }
  140. if ( m_cTargetSD > 0 )
  141. {
  142. hr = rStrm.Write( m_pTargetSD, m_cTargetSD, NULL );
  143. if ( FAILED(hr) )
  144. {
  145. return hr;
  146. }
  147. }
  148. return WBEM_S_NO_ERROR;
  149. }
  150. HRESULT CFwdMsgHeader::Unpersist( CBuffer& rStrm )
  151. {
  152. HRESULT hr;
  153. DWORD dwSig;
  154. BYTE chVersionMajor, chVersionMinor;
  155. //
  156. // read and verify signature.
  157. //
  158. hr = rStrm.Read( &dwSig, 4, NULL );
  159. if ( hr != S_OK || dwSig != g_dwSig )
  160. {
  161. return WMIMSG_E_INVALIDMESSAGE;
  162. }
  163. //
  164. // read and check version major (currently no check).
  165. //
  166. hr = rStrm.Read( &chVersionMajor, 1, NULL );
  167. if ( hr != S_OK )
  168. {
  169. return WMIMSG_E_INVALIDMESSAGE;
  170. }
  171. //
  172. // read and check version minor (currently no check).
  173. //
  174. hr = rStrm.Read( &chVersionMinor, 1, NULL );
  175. if ( hr != S_OK )
  176. {
  177. return WMIMSG_E_INVALIDMESSAGE;
  178. }
  179. //
  180. // read reserved
  181. //
  182. DWORD dwReserved;
  183. hr = rStrm.Read( &dwReserved, sizeof(DWORD), NULL );
  184. if ( hr != S_OK )
  185. {
  186. return WMIMSG_E_INVALIDMESSAGE;
  187. }
  188. //
  189. // read num events contained in data.
  190. //
  191. hr = rStrm.Read( &m_dwNumObjs, sizeof(DWORD), NULL );
  192. if ( FAILED(hr) )
  193. {
  194. return WMIMSG_E_INVALIDMESSAGE;
  195. }
  196. //
  197. // read Qos used
  198. //
  199. hr = rStrm.Read( &m_chQos, 1, NULL );
  200. if ( hr != S_OK )
  201. {
  202. return WMIMSG_E_INVALIDMESSAGE;
  203. }
  204. //
  205. // read if Auth was used.
  206. //
  207. hr = rStrm.Read( &m_chAuth, 1, NULL );
  208. if ( hr != S_OK )
  209. {
  210. return WMIMSG_E_INVALIDMESSAGE;
  211. }
  212. //
  213. // read if Encryption was used.
  214. //
  215. hr = rStrm.Read( &m_chEncrypt, 1, NULL );
  216. if ( hr != S_OK )
  217. {
  218. return WMIMSG_E_INVALIDMESSAGE;
  219. }
  220. //
  221. // read byte pad
  222. //
  223. BYTE chPad;
  224. hr = rStrm.Read( &chPad, 1, NULL );
  225. if ( hr != S_OK )
  226. {
  227. return WMIMSG_E_INVALIDMESSAGE;
  228. }
  229. //
  230. // read execution id.
  231. //
  232. hr = rStrm.Read( &m_guidExecution, sizeof(GUID), NULL );
  233. if ( hr != S_OK )
  234. {
  235. return WMIMSG_E_INVALIDMESSAGE;
  236. }
  237. //
  238. // read name of forwarding consumer
  239. //
  240. hr = rStrm.ReadLPWSTR( m_wszConsumer );
  241. if ( hr != S_OK )
  242. {
  243. return WMIMSG_E_INVALIDMESSAGE;
  244. }
  245. //
  246. // read namespace of forwarding consumer
  247. //
  248. hr = rStrm.ReadLPWSTR( m_wszNamespace );
  249. if ( hr != S_OK )
  250. {
  251. return WMIMSG_E_INVALIDMESSAGE;
  252. }
  253. //
  254. // read SD to use for signaling event
  255. //
  256. hr = rStrm.Read( &m_cTargetSD, sizeof(DWORD), NULL );
  257. if ( hr != S_OK || m_cTargetSD > rStrm.GetSize() - rStrm.GetIndex() )
  258. {
  259. return WMIMSG_E_INVALIDMESSAGE;
  260. }
  261. if ( m_cTargetSD > 0 )
  262. {
  263. m_pTargetSD = rStrm.GetRawData() + rStrm.GetIndex();
  264. rStrm.Advance( m_cTargetSD );
  265. }
  266. return WBEM_S_NO_ERROR;
  267. }