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.

167 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1989-91 Microsoft Corporation
  3. Module Name:
  4. mapsupp.c
  5. Abstract:
  6. Support routines used by the LanMan 16/32 mapping routines.
  7. Author:
  8. Dan Hinsley (danhi) 25-Mar-1991
  9. Environment:
  10. User mode only.
  11. Revision History:
  12. 25-Mar-1991 DanHi
  13. Created.
  14. 18-Aug-1991 JohnRo
  15. Implement downlevel NetWksta APIs. (Moved this routine to NetLib for
  16. use by RpcXlate as well as NetCmd/Map32 stuff.)
  17. Changed to allow UNICODE.
  18. Changed name to NetpMoveStrings.
  19. Got rid of tabs in source file.
  20. --*/
  21. // These must be included first:
  22. #include <windef.h> // BOOL, IN, LPTSTR, etc.
  23. // These may be included in any order:
  24. #include <mapsupp.h> // My prototype, LPMOVESTRING.
  25. #include <tstring.h> // STRCPY().
  26. BOOL
  27. NetpMoveStrings(
  28. IN OUT LPTSTR * Floor,
  29. IN LPTSTR pInputBuffer,
  30. OUT LPTSTR pOutputBuffer,
  31. IN LPMOVESTRING MoveStringArray,
  32. IN LPDWORD MoveStringLength
  33. )
  34. /*++
  35. Routine Description:
  36. This function is used to move a variable number of strings into a user's
  37. buffer, and to update pointers in a structure to point to the location
  38. where they are copied. According to the semantics of the LM 2.0 API,
  39. each buffer is filled with fixed length structures from the top, while
  40. variable length strings are copied in from the bottom.
  41. There are two companion arrays, MoveStringArray and MoveStringLength.
  42. MoveStringArray contains the offset to the source string in the input
  43. buffer, and the offset of the pointers in the fixed structure from the
  44. beginning of the output buffer.
  45. MoveStringLength contains an entry for each entry in MoveStringArray,
  46. and this entry is the length of the source string in MoveStringArray.
  47. This was broken into two arrays so that MoveStringArray could be built
  48. at compile time and not be modified at run time.
  49. Arguments:
  50. Floor - This is the bottom of the user's buffer, where the strings
  51. will be copied. This must be updated to reflect the strings
  52. that are copied into the buffer
  53. pInputBuffer - The buffer which contains the source strings.
  54. MoveStringArray contains offsets into this buffer.
  55. pOutputBuffer - The buffer which contains the fixed portion of the info
  56. structure, which contains fields that need to be set to point
  57. to the string locations in the output buffer. MoveStringArray
  58. contains offsets into this buffer.
  59. MoveStringArray - This is an array of MOVESTRING entries, terminated
  60. by an entry with a source offset of MOVESTRING_END_MARKER. Each
  61. entry describes a string, and the address of a variable which will
  62. hold the address where the string is copied.
  63. MoveStringLength - This is a companion array to MoveStringArray.
  64. Each entry contains the length of the matching source string
  65. from MoveStringArray.
  66. Side Effects:
  67. There are pointers in the MoveStringArray that point to pointers in the
  68. fixed length portion of the structure. These are updated with the
  69. location in the buffer where the string is copied.
  70. Return Value:
  71. TRUE if the strings were successfully copied,
  72. FALSE if the strings would not all fit in the buffer.
  73. --*/
  74. {
  75. //
  76. // Move them all in, and update Floor
  77. //
  78. while(MoveStringArray->Source != MOVESTRING_END_MARKER) {
  79. //
  80. // Since the following is a really gross piece of code, let me
  81. // explain:
  82. // pInputBuffer is a pointer to the start of a lanman struct and
  83. // MoveStringArray->Source is an offset from the start of that
  84. // structure to a PSZ.
  85. //
  86. // If this is a 0 length string, just place NULL in the pointer and
  87. // press on.
  88. if (*MoveStringLength == 0) {
  89. *((LPTSTR *) (((LPBYTE) pOutputBuffer)
  90. + MoveStringArray->Destination)) = NULL;
  91. }
  92. else {
  93. //
  94. // Back the pointer up since we're filling the buffer from the
  95. // bottom up, then do the copy
  96. //
  97. *Floor -= *MoveStringLength;
  98. (void) STRCPY(*Floor,
  99. *((LPTSTR*)((LPBYTE)pInputBuffer + MoveStringArray->Source)));
  100. //
  101. // Update the field in the structure which points to the string
  102. //
  103. // pOutputBuffer is a pointer to the start of a lanman struct
  104. // and MoveStringArray->Destination is an offset from the start
  105. // of that structure to a PSZ that needs to have the address of
  106. // the just copied string put into it.
  107. //
  108. *((LPTSTR*) ((LPBYTE)pOutputBuffer + MoveStringArray->Destination)) =
  109. *Floor;
  110. }
  111. //
  112. // Now let's do the next one
  113. //
  114. MoveStringArray++;
  115. MoveStringLength++;
  116. }
  117. return(TRUE);
  118. }