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.

196 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. AuxData.c
  5. Abstract:
  6. This module contains Remote Admin Protocol (RAP) routines. These routines
  7. are shared between XactSrv and RpcXlate.
  8. Author:
  9. Shanku Niyogi (w-shanku) 15-Mar-1991
  10. Environment:
  11. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  12. Requires ANSI C extensions: slash-slash comments, long external names.
  13. Revision History:
  14. 08-Apr-1991 JohnRo
  15. Added assertion checking.
  16. 14-Apr-1991 JohnRo
  17. Reduce recompiles.
  18. 15-May-1991 JohnRo
  19. Added native vs. RAP handling.
  20. 10-Jul-1991 JohnRo
  21. RapExamineDescriptor() has yet another parameter.
  22. 20-Sep-1991 JohnRo
  23. Downlevel NetService APIs. (Handle REM_DATA_BLOCK correctly.)
  24. --*/
  25. // These must be included first:
  26. #include <windef.h> // IN, LPDWORD, NULL, OPTIONAL, DWORD, etc.
  27. #include <lmcons.h> // NET_API_STATUS
  28. // These may be included in any order:
  29. #include <align.h> // ALIGN_WORD, etc.
  30. #include <netdebug.h> // NetpAssert().
  31. #include <rap.h> // My prototypes, LPDESC, NO_AUX_DATA, etc.
  32. #include <remtypes.h> // REM_WORD, etc.
  33. #include <smbgtpt.h> // SmbPutUshort(), etc.
  34. #include <string.h> // strchr().
  35. DWORD
  36. RapAuxDataCountOffset (
  37. IN LPDESC Descriptor,
  38. IN RAP_TRANSMISSION_MODE TransmissionMode,
  39. IN BOOL Native
  40. )
  41. /*++
  42. Routine Description:
  43. This routine determines the offset from the start of the structure of
  44. the auxiliary data count ( described by REM_AUX_NUM or REM_AUX_NUM_DWORD
  45. descriptor characters ).
  46. Arguments:
  47. Descriptor - the format of the structure.
  48. Transmission Mode - Indicates whether this array is part of a response,
  49. a request, or both.
  50. Native - TRUE iff the descriptor defines a native structure. (This flag is
  51. used to decide whether or not to align fields.)
  52. Return Value:
  53. DWORD - The offset, in bytes, from the start of the structure to the
  54. count data, or the value NO_AUX_DATA.
  55. --*/
  56. {
  57. DWORD auxDataCountOffset;
  58. NetpAssert(Descriptor != NULL);
  59. NetpAssert(*Descriptor != '\0');
  60. if (Descriptor[0] != REM_DATA_BLOCK) {
  61. //
  62. // Regular structure/whatever.
  63. //
  64. RapExamineDescriptor(
  65. Descriptor,
  66. NULL,
  67. NULL,
  68. NULL,
  69. &auxDataCountOffset,
  70. NULL,
  71. NULL, // don't need to know structure alignment
  72. TransmissionMode,
  73. Native
  74. );
  75. } else {
  76. //
  77. // REM_DATA_BLOCK: Unstructured data.
  78. //
  79. NetpAssert( Descriptor[1] == '\0' );
  80. auxDataCountOffset = NO_AUX_DATA;
  81. }
  82. return auxDataCountOffset;
  83. } // RapAuxDataCountOffset
  84. DWORD
  85. RapAuxDataCount (
  86. IN LPBYTE Buffer,
  87. IN LPDESC Descriptor,
  88. IN RAP_TRANSMISSION_MODE TransmissionMode,
  89. IN BOOL Native
  90. )
  91. /*++
  92. Routine Description:
  93. This routine determines the actual count of the number of auxiliary
  94. structures, taking into consideration whether the count is a 16-bit
  95. or a 32-bit quantity.
  96. Arguments:
  97. Buffer - a pointer to the start of the data buffer.
  98. Descriptor - the format of the structure.
  99. Transmission Mode - Indicates whether this array is part of a response,
  100. a request, or both.
  101. Native - TRUE iff the descriptor defines a native structure. (This flag is
  102. used to decide whether or not to align fields.)
  103. Return Value:
  104. DWORD - The number of auxiliary data structures, or the value NO_AUX_DATA.
  105. --*/
  106. {
  107. DWORD auxDataCountOffset;
  108. NetpAssert(Descriptor != NULL);
  109. NetpAssert(*Descriptor != '\0');
  110. auxDataCountOffset = RapAuxDataCountOffset(
  111. Descriptor,
  112. TransmissionMode,
  113. Native
  114. );
  115. //
  116. // No auxiliary data count offset found. There isn't any auxiliary data.
  117. //
  118. if ( auxDataCountOffset == NO_AUX_DATA) {
  119. return NO_AUX_DATA;
  120. }
  121. //
  122. // Check if the descriptor character was a word or dword count type.
  123. // Get appropriate value, and return it as a dword.
  124. //
  125. NetpAssert(sizeof(DESC_CHAR) == sizeof(char));
  126. NetpAssert(RapPossiblyAlignCount(
  127. auxDataCountOffset, ALIGN_WORD, Native) == auxDataCountOffset );
  128. if ( strchr( Descriptor, REM_AUX_NUM_DWORD ) != NULL ) {
  129. return SmbGetUlong( (LPDWORD)( Buffer + auxDataCountOffset ));
  130. } else {
  131. return (DWORD)SmbGetUshort( (LPWORD)( Buffer + auxDataCountOffset ));
  132. }
  133. } // RapAuxDataCount