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.

201 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1987-1992 Microsoft Corporation
  3. Module Name:
  4. ArrayLen.c
  5. Abstract:
  6. This module contains Remote Admin Protocol (RAP) routines. These routines
  7. are shared between XactSrv and RpcXlate.
  8. Author:
  9. (Various LanMan 2.x people.)
  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. 12-Mar-1991 JohnRo
  15. Converted from LanMan 2.x to NT Rap (Remote Admin Protocol) routines.
  16. 14-Apr-1991 JohnRo
  17. Reduced recompiles. Got rid of tabs in file.
  18. 29-Sep-1991 JohnRo
  19. Made changes suggested by PC-LINT. Work toward possible conversion of
  20. descs to UNICODE.
  21. 16-Aug-1992 JohnRo
  22. RAID 2920: Support UTC timezone in net code.
  23. Use PREFIX_ equates.
  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 <netdebug.h> // NetpAssert(), NetpDbg routines.
  30. #include <prefix.h> // PREFIX_ equates.
  31. #include <rap.h> // LPDESC, my non-private prototypes, etc.
  32. #include <remtypes.h> // REM_WORD, etc.
  33. DWORD
  34. RapArrayLength(
  35. IN LPDESC Descriptor,
  36. IN OUT LPDESC * UpdatedDescriptorPtr,
  37. IN RAP_TRANSMISSION_MODE TransmissionMode
  38. )
  39. /*++
  40. Routine Description:
  41. RapArrayLength gets the length of an array described by type descriptor
  42. element. This routine also updates the descriptor string pointer to point
  43. to the last char in the element of the descriptor string.
  44. Arguments:
  45. Descriptor - Points to first character in the descriptor element to be
  46. processed.
  47. UpdatedDescriptorPtr - The address of the pointer passed as Descriptor.
  48. On exit, this will be updated to point to last character in descriptor
  49. element.
  50. Transmission Mode - Indicates whether this array is part of a response,
  51. a request, or both.
  52. Return Value:
  53. DWORD - Length, in bytes of the array described by the descriptor string
  54. element. This may be zero, depending on the value of Transmission
  55. Mode.
  56. --*/
  57. {
  58. DWORD num_elements;
  59. DWORD element_length;
  60. // First set length of an element in the array.
  61. switch (*Descriptor) {
  62. case REM_BYTE :
  63. element_length = sizeof(BYTE);
  64. break;
  65. case REM_WORD :
  66. element_length = sizeof(WORD);
  67. break;
  68. case REM_DWORD :
  69. case REM_SIGNED_DWORD :
  70. element_length = sizeof(DWORD);
  71. break;
  72. case REM_BYTE_PTR :
  73. element_length = sizeof(BYTE);
  74. break;
  75. case REM_WORD_PTR :
  76. element_length = sizeof(WORD);
  77. break;
  78. case REM_DWORD_PTR :
  79. element_length = sizeof(DWORD);
  80. break;
  81. case REM_RCV_BYTE_PTR :
  82. if (TransmissionMode == Request) {
  83. return (0);
  84. }
  85. element_length = sizeof(BYTE);
  86. break;
  87. case REM_RCV_WORD_PTR :
  88. if (TransmissionMode == Request) {
  89. return (0);
  90. }
  91. element_length = sizeof(WORD);
  92. break;
  93. case REM_RCV_DWORD_PTR :
  94. if (TransmissionMode == Request) {
  95. return (0);
  96. }
  97. element_length = sizeof(DWORD);
  98. break;
  99. case REM_NULL_PTR :
  100. return (0);
  101. case REM_FILL_BYTES :
  102. element_length = sizeof(BYTE);
  103. break;
  104. case REM_SEND_BUF_PTR :
  105. NetpAssert(TransmissionMode != Response);
  106. return (0);
  107. /*
  108. * Warning: following fixes a bug in which "b21" type
  109. * combinations in parmeter string will be
  110. * handled correctly when pointer to such "bit map"
  111. * in the struct is NULL. These two dumbos could
  112. * interfere so we force a success return.
  113. */
  114. case REM_SEND_LENBUF:
  115. return (0);
  116. //
  117. // Set element length to zero since strings don't get stored in
  118. // the structure, but fall through so UpdatedDescriptorPtr is still
  119. // incremented to point past the maximum length count, if present.
  120. //
  121. case REM_ASCIZ:
  122. case REM_ASCIZ_TRUNCATABLE:
  123. element_length = 0;
  124. break;
  125. case REM_EPOCH_TIME_GMT: /*FALLTHROUGH*/
  126. case REM_EPOCH_TIME_LOCAL: /*FALLTHROUGH*/
  127. element_length = sizeof(DWORD);
  128. break;
  129. default:
  130. NetpKdPrint(( PREFIX_NETRAP
  131. "RapArrayLength: Unexpected desc char '" FORMAT_DESC_CHAR
  132. "'.\n", *Descriptor));
  133. NetpBreakPoint();
  134. return (0);
  135. }
  136. // Now get number of elements in the array.
  137. for ( num_elements = 0, Descriptor++;
  138. DESC_CHAR_IS_DIGIT( *Descriptor );
  139. Descriptor++, (*UpdatedDescriptorPtr)++) {
  140. num_elements = (10 * num_elements) + DESC_DIGIT_TO_NUM( *Descriptor );
  141. }
  142. return (element_length == 0)
  143. ? 0
  144. : ( num_elements == 0
  145. ? element_length
  146. : element_length * num_elements );
  147. } // RapArrayLength