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.

236 lines
5.0 KiB

  1. //*****************************************************************************
  2. //
  3. // Name: unpickle.cxx
  4. //
  5. // Description: Library which exports UnpickleEEInfo
  6. //
  7. // History:
  8. // 09/05/01 mauricf Created.
  9. //
  10. //*****************************************************************************
  11. //*****************************************************************************
  12. //
  13. // Copyright (c) 2001 by Microsoft Corp. All rights reserved.
  14. //
  15. //*****************************************************************************
  16. #include <precomp.hxx>
  17. #include "eeinfo.hxx"
  18. RPC_STATUS
  19. UnpickleEEInfo (
  20. IN OUT unsigned char *Buffer,
  21. IN size_t BufferSize,
  22. OUT ExtendedErrorInfo **NewEEInfo
  23. )
  24. /*++
  25. Routine Description:
  26. This routine does the actual pickling in a user supplied buffer.
  27. The buffer must have been allocated large enough to hold all
  28. pickled data. Some of the other functions should have been
  29. used to get the size of the pickled data and the buffer
  30. should have been allocated appropriately
  31. Arguments:
  32. Buffer - the actual Buffer to pickle into
  33. BufferSize - the size of the Buffer.
  34. Return Value:
  35. RPC_S_OK if the pickling was successful.
  36. other RPC_S_* codes if it failed.
  37. --*/
  38. {
  39. ExtendedErrorInfo *EEInfo;
  40. handle_t PickleHandle;
  41. RPC_STATUS RpcStatus;
  42. ExtendedErrorInfoPtr *EEInfoPtr;
  43. RpcStatus = MesDecodeBufferHandleCreate((char *)Buffer, BufferSize, &PickleHandle);
  44. if (RpcStatus != RPC_S_OK)
  45. {
  46. return RpcStatus;
  47. }
  48. EEInfoPtr = &EEInfo;
  49. EEInfo = NULL;
  50. RpcTryExcept
  51. {
  52. ExtendedErrorInfoPtr_Decode(PickleHandle, EEInfoPtr);
  53. }
  54. RpcExcept(I_RpcExceptionFilter(RpcExceptionCode()))
  55. {
  56. RpcStatus = RpcExceptionCode();
  57. }
  58. RpcEndExcept
  59. MesHandleFree(PickleHandle);
  60. if (RpcStatus == RPC_S_OK)
  61. *NewEEInfo = EEInfo;
  62. return RpcStatus;
  63. }
  64. inline void
  65. FreeEEInfoRecordShallow (
  66. IN ExtendedErrorInfo *InfoToFree
  67. )
  68. /*++
  69. Routine Description:
  70. Frees only the eeinfo record - not any of
  71. the pointers contained in it.
  72. Arguments:
  73. InfoToFree - the eeinfo record
  74. Return Value:
  75. void
  76. --*/
  77. {
  78. MIDL_user_free(InfoToFree);
  79. }
  80. void
  81. FreeEEInfoPrivateParam (
  82. IN ExtendedErrorParam *Param
  83. )
  84. {
  85. if ((Param->Type == eeptiAnsiString)
  86. || (Param->Type == eeptiUnicodeString))
  87. {
  88. // AnsiString & UnicodeString occupy the same
  89. // memory location - ok to free any of them
  90. MIDL_user_free(Param->AnsiString.pString);
  91. }
  92. else if (Param->Type == eeptiBinary)
  93. {
  94. MIDL_user_free(Param->Blob.pBlob);
  95. }
  96. }
  97. void
  98. FreeEEInfoPublicParam (
  99. IN OUT RPC_EE_INFO_PARAM *Param,
  100. IN BOOL CopyStrings
  101. )
  102. /*++
  103. Routine Description:
  104. If the type of parameter is string (ansi or unicode)
  105. and CopyStrings, free the string
  106. Arguments:
  107. Param - the parameter to free
  108. CopyStrings - the value of the CopyStrings parameter
  109. when RpcErrorGetNextRecord was called. If non-zero
  110. the string will be freed. Otherwise, the function
  111. is a no-op
  112. Return Value:
  113. void
  114. --*/
  115. {
  116. if ((Param->ParameterType == eeptAnsiString)
  117. || (Param->ParameterType == eeptUnicodeString))
  118. {
  119. if (CopyStrings)
  120. {
  121. RtlFreeHeap(RtlProcessHeap(), 0, Param->u.AnsiString);
  122. }
  123. }
  124. else if (Param->ParameterType == eeptBinary)
  125. {
  126. if (CopyStrings)
  127. {
  128. RtlFreeHeap(RtlProcessHeap(), 0, Param->u.BVal.Buffer);
  129. }
  130. }
  131. }
  132. void
  133. FreeEEInfoRecord (
  134. IN ExtendedErrorInfo *EEInfo
  135. )
  136. /*++
  137. Routine Description:
  138. Frees a single ExtendedErrorInfo record and
  139. all strings within it.
  140. Arguments:
  141. EEInfo - record to free
  142. Return Value:
  143. void
  144. --*/
  145. {
  146. int i;
  147. THREAD *Thread;
  148. for (i = 0; i < EEInfo->nLen; i ++)
  149. {
  150. FreeEEInfoPrivateParam(&EEInfo->Params[i]);
  151. }
  152. if (EEInfo->ComputerName.Type == eecnpPresent)
  153. {
  154. MIDL_user_free(EEInfo->ComputerName.Name.pString);
  155. }
  156. Thread = RpcpGetThreadPointer();
  157. if (Thread)
  158. {
  159. Thread->SetCachedEEInfoBlock(EEInfo, EEInfo->nLen);
  160. }
  161. else
  162. {
  163. FreeEEInfoRecordShallow(EEInfo);
  164. }
  165. }
  166. void
  167. FreeEEInfoChain (
  168. IN ExtendedErrorInfo *EEInfo
  169. )
  170. /*++
  171. Routine Description:
  172. Frees a chain of ExtendedErrorInfo records and
  173. all strings within them.
  174. Arguments:
  175. EEInfo - head of list to free
  176. Return Value:
  177. void
  178. --*/
  179. {
  180. ExtendedErrorInfo *CurrentInfo, *NextInfo;
  181. CurrentInfo = EEInfo;
  182. while (CurrentInfo != NULL)
  183. {
  184. // get the next link while we can
  185. NextInfo = CurrentInfo->Next;
  186. FreeEEInfoRecord(CurrentInfo);
  187. CurrentInfo = NextInfo;
  188. }
  189. }