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.

210 lines
4.3 KiB

  1. #ifdef BLDR_KERNEL_RUNTIME
  2. #include <bootdefs.h>
  3. #endif
  4. #include <stddef.h>
  5. #include <ntlmsspi.h>
  6. #include <debug.h>
  7. #include <memory.h>
  8. #include <string.h>
  9. #if 0
  10. PSTRING
  11. SspAllocateStringBlock(
  12. PVOID Value,
  13. int Length
  14. )
  15. {
  16. PSTRING String;
  17. String = (PSTRING) SspAlloc (sizeof(STRING));
  18. if (String == NULL) {
  19. return (NULL);
  20. }
  21. String->Buffer = (PCHAR) SspAlloc (Length);
  22. if (String->Buffer == NULL) {
  23. SspFree (String);
  24. return (NULL);
  25. }
  26. String->Length = String->MaximumLength = Length;
  27. _fmemcpy(String->Buffer, Value, Length);
  28. return (String);
  29. }
  30. PSTRING
  31. SspAllocateString(
  32. PVOID Value
  33. )
  34. {
  35. int Length;
  36. Length = _fstrlen(Value);
  37. return (SspAllocateStringBlock(Value, Length));
  38. }
  39. void
  40. SspFreeString(
  41. PSTRING * String
  42. )
  43. {
  44. if (*String == NULL) {
  45. return;
  46. }
  47. if ((*String)->MaximumLength) {
  48. SspFree ((*String)->Buffer);
  49. }
  50. SspFree (*String);
  51. *String = NULL;
  52. }
  53. void
  54. SspCopyString(
  55. IN PVOID MessageBuffer,
  56. OUT PSTRING OutString,
  57. IN PSTRING InString,
  58. IN OUT PCHAR *Where,
  59. IN BOOLEAN Absolute
  60. )
  61. /*++
  62. Routine Description:
  63. This routine copies the InString into the MessageBuffer at Where.
  64. It then updates OutString to be a descriptor for the copied string. The
  65. descriptor 'address' is an offset from the MessageBuffer unless 'Absolute'
  66. is TRUE.
  67. Where is updated to point to the next available space in the MessageBuffer.
  68. The caller is responsible for any alignment requirements and for ensuring
  69. there is room in the buffer for the string.
  70. Arguments:
  71. MessageBuffer - Specifies the base address of the buffer being copied into.
  72. OutString - Returns a descriptor for the copied string. The descriptor
  73. is relative to the begining of the buffer.
  74. InString - Specifies the string to copy.
  75. Where - On input, points to where the string is to be copied.
  76. On output, points to the first byte after the string.
  77. Absolute - If TRUE, OutString->Buffer will be set to the actual buffer
  78. address rather than an offset.
  79. Return Value:
  80. None.
  81. --*/
  82. {
  83. //
  84. // Copy the data to the Buffer.
  85. //
  86. if ( InString->Buffer != NULL ) {
  87. _fmemcpy( *Where, InString->Buffer, InString->Length );
  88. }
  89. //
  90. // Build a descriptor to the newly copied data.
  91. //
  92. OutString->Length = OutString->MaximumLength = InString->Length;
  93. if ( Absolute ) {
  94. OutString->Buffer = *Where;
  95. } else {
  96. *(unsigned long *) &OutString->Buffer = *Where - ((PCHAR)MessageBuffer);
  97. }
  98. //
  99. // Update Where to point past the copied data.
  100. //
  101. *Where += InString->Length;
  102. }
  103. #endif // 0
  104. void
  105. SspCopyStringFromRaw(
  106. IN PVOID MessageBuffer,
  107. OUT PSTRING OutString,
  108. IN PCHAR InString,
  109. IN int InStringLength,
  110. IN OUT PCHAR *Where
  111. )
  112. /*++
  113. Routine Description:
  114. This routine copies the InString into the MessageBuffer at Where.
  115. It then updates OutString to be a descriptor for the copied string. The
  116. descriptor 'address' is an offset from the MessageBuffer.
  117. Where is updated to point to the next available space in the MessageBuffer.
  118. The caller is responsible for any alignment requirements and for ensuring
  119. there is room in the buffer for the string.
  120. Arguments:
  121. MessageBuffer - Specifies the base address of the buffer being copied into.
  122. OutString - Returns a descriptor for the copied string. The descriptor
  123. is relative to the begining of the buffer. (Always a relative Out).
  124. InString - Specifies the string to copy.
  125. Where - On input, points to where the string is to be copied.
  126. On output, points to the first byte after the string.
  127. Return Value:
  128. None.
  129. --*/
  130. {
  131. //
  132. // Copy the data to the Buffer.
  133. //
  134. if ( InString != NULL ) {
  135. _fmemcpy( *Where, InString, InStringLength );
  136. }
  137. //
  138. // Build a descriptor to the newly copied data.
  139. //
  140. OutString->Length = OutString->MaximumLength = (USHORT)InStringLength;
  141. swapshort(OutString->Length) ;
  142. swapshort(OutString->MaximumLength) ;
  143. *(unsigned long *) &OutString->Buffer = (ULONG)(*Where - ((PCHAR)MessageBuffer));
  144. swaplong(*(unsigned long *) &OutString->Buffer) ; //MACBUG: this is weird !!
  145. //
  146. // Update Where to point past the copied data.
  147. //
  148. *Where += InStringLength;
  149. }
  150. 
  151.