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.

398 lines
11 KiB

  1. /*++
  2. Copyright (c) 1991-1993 Microsoft Corporation
  3. Module Name:
  4. Rap.h
  5. Abstract:
  6. This header file contains procedure prototypes for Remote Admin Protocol
  7. (RAP) routines. These routines are shared between XactSrv and RpcXlate.
  8. Author:
  9. David Treadwell (davidtr) 08-Jan-1991
  10. Shanku Niyogi (w-shanku)
  11. John Rogers (JohnRo)
  12. Environment:
  13. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  14. Requires ANSI C extensions: slash-slash comments, long external names.
  15. Revision History:
  16. 05-Mar-1991 JohnRo
  17. Extracted Rap routines from XactSrv (Xs) code.
  18. 26-Mar-1991 JohnRo
  19. Added FORMAT_LPDESC (for debugging). Include <ctype.h>.
  20. 21-Apr-1991 JohnRo
  21. Added RapIsValidDescriptorSmb(). Reduced recompiles.
  22. Make it clear that RapAsciiToDecimal updates the pointer it is given.
  23. RapConvertSingleEntry's BytesRequired is not OPTIONAL.
  24. Clarify that OutStructure is OUT, not IN.
  25. 06-May-1991 JohnRo
  26. Added DESC_CHAR typedef.
  27. 14-May-1991 JohnRo
  28. Added DESCLEN() and FORMAT_DESC_CHAR macros.
  29. 15-May-1991 JohnRo
  30. Added conversion mode handling. Added native vs. RAP handling.
  31. 05-Jun-1991 JohnRo
  32. Added RapTotalSize(). Make output structure OPTIONAL for convert
  33. single entry; this will be used by RapTotalSize().
  34. 10-Jul-1991 JohnRo
  35. Added RapStructureAlignment() for use by RxpConvertDataStructures().
  36. 22-Jul-1991 RFirth
  37. Added MAX_DESC_SUBSTRING
  38. 19-Aug-1991 JohnRo
  39. Added DESC_CHAR_IS_DIGIT() macro (to improve UNICODE conversion).
  40. 10-Sep-1991 JohnRo
  41. Added DESC_DIGIT_TO_NUM(), to support changes suggested by PC-LINT.
  42. 07-Oct-1991 JohnRo
  43. Correct MAX_DESC_SUBSTRING.
  44. Use DESC_CHAR_IS_DIGIT() in t-JamesW's new macros.
  45. 07-Feb-1992 JohnRo
  46. Added RapCharSize() macro.
  47. 06-May-1993 JohnRo
  48. RAID 8849: Export RxRemoteApi for DEC and others.
  49. --*/
  50. #ifndef _RAP_
  51. #define _RAP_
  52. // These must be included first:
  53. #include <windef.h> // BOOL, CHAR, DWORD, IN, LPBYTE, etc.
  54. #include <lmcons.h> // NET_API_STATUS
  55. // These may be included in any order:
  56. #include <lmremutl.h> // DESC_CHAR and LPDESC_CHAR typedefs.
  57. #ifndef DESC_CHAR_UNICODE
  58. #include <ctype.h> // isdigit().
  59. #include <string.h> // strlen() (only needed for DESCLEN()).
  60. //
  61. // The descriptor strings are really ASCIIZ strings, and are not expected to
  62. // be translated into Unicode. So, let's define a type for them just to
  63. // make this clearer. (That'll also make it easier to change to Unicode later
  64. // if I'm wrong. --JR)
  65. //
  66. //typedef CHAR DESC_CHAR;
  67. //
  68. // Net buffers contain 32-bit pointers.
  69. //
  70. #define NETPTR DWORD
  71. // DESCLEN(desc): return number of characters (not including null) in desc:
  72. #define DESCLEN(desc) strlen(desc)
  73. // DESC_CHAR_IS_DIGIT(descchar): return nonzero iff descchar is a digit.
  74. #define DESC_CHAR_IS_DIGIT(descchar) isdigit(descchar)
  75. // DESC_DIGIT_TO_NUM(descchar): return integer value of descchar.
  76. #define DESC_DIGIT_TO_NUM(descchar) \
  77. ( (DWORD) ( ((int)(descchar)) - ((int) '0') ) )
  78. //
  79. // Format strings for NetpDbgPrint use (see NetDebug.h). Note that
  80. // FORMAT_LPDESC_CHAR will go away one of these days.
  81. //
  82. #define FORMAT_DESC_CHAR "%c"
  83. #define FORMAT_LPDESC "%s"
  84. #define FORMAT_LPDESC_CHAR "%c"
  85. #else // DESC_CHAR_UNICODE is defined
  86. //
  87. // The descriptor strings are really ASCIIZ strings, and are not expected to
  88. // be translated into Unicode. So, let's define a type for them just to
  89. // make this clearer. (That'll also make it easier to change to Unicode later
  90. // if I'm wrong. --JR)
  91. //
  92. #include <wchar.h> // iswdigit(), wcslen().
  93. //typedef WCHAR DESC_CHAR;
  94. // DESCLEN(desc): return number of characters (not including null) in desc:
  95. #define DESCLEN(desc) wcslen(desc)
  96. // DESC_CHAR_IS_DIGIT(descchar): return nonzero iff descchar is a digit.
  97. #define DESC_CHAR_IS_DIGIT(descchar) iswdigit(descchar)
  98. // DESC_DIGIT_TO_NUM(descchar): return integer value of descchar.
  99. #define DESC_DIGIT_TO_NUM(descchar) \
  100. ( (DWORD) ( ((int)(descchar)) - ((int) L'0') ) )
  101. //
  102. // Format strings for NetpDbgPrint use (see NetDebug.h). Note that
  103. // FORMAT_LPDESC_CHAR will go away one of these days.
  104. //
  105. #define FORMAT_DESC_CHAR "%wc"
  106. #define FORMAT_LPDESC "%ws"
  107. #define FORMAT_LPDESC_CHAR "%wc"
  108. #endif // DESC_CHAR_UNICODE is defined
  109. //typedef DESC_CHAR * LPDESC;
  110. //
  111. // MAX_DESC_SUBSTRING - the maximum number of consecutive characters in a
  112. // descriptor string which can describe a single field in a structure - for
  113. // example "B21" in "B21BWWWzWB9B". So far, largest is "B120".
  114. //
  115. #define MAX_DESC_SUBSTRING 4
  116. //
  117. // Some routines need to know whether a given item is part of a request,
  118. // a response, or both:
  119. //
  120. typedef enum _RAP_TRANSMISSION_MODE {
  121. Request, // only part of request (in)
  122. Response, // only part of response (out)
  123. Both // both (in out).
  124. } RAP_TRANSMISSION_MODE, *LPRAP_TRANSMISSION_MODE;
  125. typedef enum _RAP_CONVERSION_MODE {
  126. NativeToRap, // native format to RAP
  127. RapToNative, // RAP format to native
  128. NativeToNative, // native to native
  129. RapToRap // RAP to RAP
  130. } RAP_CONVERSION_MODE, *LPRAP_CONVERSION_MODE;
  131. //
  132. // The value returned by RapLastPointerOffset for a descriptor string
  133. // which indicates that the structure has no pointers. A very high
  134. // value is returned instead of 0, in order to distinguish between
  135. // a structure with no pointers, such as share_info_0, and a structure
  136. // with only one pointer, at offset 0.
  137. //
  138. #define NO_POINTER_IN_STRUCTURE 0xFFFFFFFF
  139. //
  140. // The value returned by RapAuxDataCount when there is no
  141. // auxiliary data. This will be indicated by the lack of an auxiliary
  142. // data count character in the descriptor string.
  143. //
  144. #define NO_AUX_DATA 0xFFFFFFFF
  145. //
  146. // Helper subroutines and macros.
  147. //
  148. DWORD
  149. RapArrayLength(
  150. IN LPDESC Descriptor,
  151. IN OUT LPDESC * UpdatedDescriptorPtr,
  152. IN RAP_TRANSMISSION_MODE TransmissionMode
  153. );
  154. DWORD
  155. RapAsciiToDecimal (
  156. IN OUT LPDESC *Number
  157. );
  158. DWORD
  159. RapAuxDataCountOffset (
  160. IN LPDESC Descriptor,
  161. IN RAP_TRANSMISSION_MODE TransmissionMode,
  162. IN BOOL Native
  163. );
  164. DWORD
  165. RapAuxDataCount (
  166. IN LPBYTE Buffer,
  167. IN LPDESC Descriptor,
  168. IN RAP_TRANSMISSION_MODE TransmissionMode,
  169. IN BOOL Native
  170. );
  171. // RapCharSize(native): return character size (in bytes) for characters of a
  172. // given format.
  173. //
  174. // DWORD
  175. // RapCharSize(Native)
  176. // IN BOOL Native
  177. // );
  178. //
  179. #define RapCharSize(Native) \
  180. ( (DWORD) ( (Native) ? sizeof(TCHAR) : sizeof(CHAR) ) )
  181. NET_API_STATUS
  182. RapConvertSingleEntry (
  183. IN LPBYTE InStructure,
  184. IN LPDESC InStructureDesc,
  185. IN BOOL MeaninglessInputPointers,
  186. IN LPBYTE OutBufferStart OPTIONAL,
  187. OUT LPBYTE OutStructure OPTIONAL,
  188. IN LPDESC OutStructureDesc,
  189. IN BOOL SetOffsets,
  190. IN OUT LPBYTE *StringLocation OPTIONAL,
  191. IN OUT LPDWORD BytesRequired,
  192. IN RAP_TRANSMISSION_MODE TransmissionMode,
  193. IN RAP_CONVERSION_MODE ConversionMode
  194. );
  195. NET_API_STATUS
  196. RapConvertSingleEntryEx (
  197. IN LPBYTE InStructure,
  198. IN LPDESC InStructureDesc,
  199. IN BOOL MeaninglessInputPointers,
  200. IN LPBYTE OutBufferStart OPTIONAL,
  201. OUT LPBYTE OutStructure OPTIONAL,
  202. IN LPDESC OutStructureDesc,
  203. IN BOOL SetOffsets,
  204. IN OUT LPBYTE *StringLocation OPTIONAL,
  205. IN OUT LPDWORD BytesRequired,
  206. IN RAP_TRANSMISSION_MODE TransmissionMode,
  207. IN RAP_CONVERSION_MODE ConversionMode,
  208. IN UINT_PTR Bias
  209. );
  210. //
  211. //
  212. // RapDescArrayLength(Descriptor) - return the array length if the descriptor
  213. // data has numeric characters, or return default length of 1.
  214. //
  215. // DWORD
  216. // RapDescArrayLength(
  217. // IN OUT LPDESC Descriptor
  218. // );
  219. //
  220. #define RapDescArrayLength( Descriptor ) \
  221. ( ( DESC_CHAR_IS_DIGIT( *(Descriptor) )) ? RapAsciiToDecimal( &(Descriptor) ) : 1 )
  222. //
  223. // RapDescStringLength(Descriptor) - return the array length if the descriptor
  224. // data has numeric characters, or return default length of 0, which indicates
  225. // that there is no limit.
  226. //
  227. // DWORD
  228. // RapDescStringLength(
  229. // IN OUT LPDESC Descriptor
  230. // );
  231. #define RapDescStringLength( Descriptor ) \
  232. ( ( DESC_CHAR_IS_DIGIT( *(Descriptor) )) ? RapAsciiToDecimal( &(Descriptor) ) : 0 )
  233. VOID
  234. RapExamineDescriptor (
  235. IN LPDESC DescriptorString,
  236. IN LPDWORD ParmNum OPTIONAL,
  237. OUT LPDWORD StructureSize OPTIONAL,
  238. OUT LPDWORD LastPointerOffset OPTIONAL,
  239. OUT LPDWORD AuxDataCountOffset OPTIONAL,
  240. OUT LPDESC * ParmNumDescriptor OPTIONAL,
  241. OUT LPDWORD StructureAlignment OPTIONAL,
  242. IN RAP_TRANSMISSION_MODE TransmissionMode,
  243. IN BOOL Native
  244. );
  245. DWORD
  246. RapGetFieldSize(
  247. IN LPDESC TypePointer,
  248. IN OUT LPDESC * TypePointerAddress,
  249. IN RAP_TRANSMISSION_MODE TransmissionMode
  250. );
  251. //
  252. // BOOL
  253. // RapIsPointer(
  254. // IN CHAR DescChar
  255. // );
  256. //
  257. #define RapIsPointer(c) ( ((c) > 'Z') ? TRUE : FALSE )
  258. BOOL
  259. RapIsValidDescriptorSmb (
  260. IN LPDESC Desc
  261. );
  262. DWORD
  263. RapLastPointerOffset (
  264. IN LPDESC Descriptor,
  265. IN RAP_TRANSMISSION_MODE TransmissionMode,
  266. IN BOOL Native
  267. );
  268. LPDESC
  269. RapParmNumDescriptor(
  270. IN LPDESC Descriptor,
  271. IN DWORD ParmNum,
  272. IN RAP_TRANSMISSION_MODE TransmissionMode,
  273. IN BOOL Native
  274. );
  275. // LPVOID
  276. // RapPossiblyAlignCount(
  277. // IN DWORD Count,
  278. // IN DWORD Pow2,
  279. // IN BOOL Native
  280. // );
  281. #define RapPossiblyAlignCount(count,pow2,native) \
  282. ( (!(native)) ? (count) : (ROUND_UP_COUNT( (count), (pow2) )) )
  283. // LPVOID
  284. // RapPossiblyAlignPointer(
  285. // IN LPVOID Ptr,
  286. // IN DWORD Pow2,
  287. // IN BOOL Native
  288. // );
  289. #define RapPossiblyAlignPointer(ptr,pow2,native) \
  290. ( (!(native)) ? (ptr) : (ROUND_UP_POINTER( (ptr), (pow2) )) )
  291. DWORD
  292. RapStructureAlignment (
  293. IN LPDESC Descriptor,
  294. IN RAP_TRANSMISSION_MODE TransmissionMode,
  295. IN BOOL Native
  296. );
  297. DWORD
  298. RapStructureSize (
  299. IN LPDESC Descriptor,
  300. IN RAP_TRANSMISSION_MODE TransmissionMode,
  301. IN BOOL Native
  302. );
  303. DWORD
  304. RapTotalSize (
  305. IN LPBYTE InStructure,
  306. IN LPDESC InStructureDesc,
  307. IN LPDESC OutStructureDesc,
  308. IN BOOL MeaninglessInputPointers,
  309. IN RAP_TRANSMISSION_MODE TransmissionMode,
  310. IN RAP_CONVERSION_MODE ConversionMode
  311. );
  312. //
  313. // RapValueWouldBeTruncated(n): return TRUE if n would lose bits when we try
  314. // to store it in 16 bits.
  315. //
  316. // BOOL
  317. // RapValueWouldBeTruncated(
  318. // IN DWORD Value
  319. // );
  320. //
  321. #define RapValueWouldBeTruncated(n) \
  322. ( ( (n) != (DWORD) (WORD) (n)) ? TRUE : FALSE )
  323. #endif // ndef _RAP_