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.

385 lines
15 KiB

  1. /*++ BUILD Version: 0009 // Increment this if a change has global effects
  2. Copyright (c) 1987-1993 Microsoft Corporation
  3. Module Name:
  4. smbcxchng.h
  5. Abstract:
  6. This is the include file that defines all constants and types for
  7. SMB exchange implementation.
  8. Author:
  9. Balan Sethu Raman (SethuR) 06-Feb-95 Created
  10. --*/
  11. #ifndef _TRANSACT_H_
  12. #define _TRANSACT_H_
  13. typedef enum _TRANSACT_EXCHANGE_STATE_ {
  14. TRANSACT_EXCHANGE_START,
  15. TRANSACT_EXCHANGE_ERROR,
  16. TRANSACT_EXCHANGE_SUCCESS,
  17. TRANSACT_EXCHANGE_TRANSMITTED_PRIMARY_REQUEST,
  18. TRANSACT_EXCHANGE_RECEIVED_INTERIM_RESPONSE,
  19. TRANSACT_EXCHANGE_TRANSMITTED_SECONDARY_REQUESTS,
  20. TRANSACT_EXCHANGE_RECEIVED_PRIMARY_RESPONSE
  21. } TRANSACT_EXCHANGE_STATE, *PTRANSACT_EXCHANGE_STATE;
  22. typedef struct _SMB_TRANSACTION_RESUMPTION_CONTEXT{
  23. struct _SMB_TRANSACT_EXCHANGE *pTransactExchange;
  24. SMBCE_RESUMPTION_CONTEXT SmbCeResumptionContext;
  25. ULONG SetupBytesReceived;
  26. ULONG DataBytesReceived;
  27. ULONG ParameterBytesReceived;
  28. NTSTATUS FinalStatusFromServer;
  29. ULONG ServerVersion;
  30. } SMB_TRANSACTION_RESUMPTION_CONTEXT, *PSMB_TRANSACTION_RESUMPTION_CONTEXT;
  31. #define TRAILING_BYTES_BUFFERSIZE 8
  32. typedef struct _SMB_TRANSACT_EXCHANGE {
  33. SMB_EXCHANGE;
  34. TRANSACT_EXCHANGE_STATE State;
  35. // Client supplied parameters for the transact exchange
  36. //PRX_CONTEXT RxContext;
  37. PMDL pSendDataMdl;
  38. ULONG SendDataBufferSize;
  39. ULONG DataBytesSent;
  40. PMDL pReceiveDataMdl;
  41. ULONG ReceiveDataBufferSize;
  42. ULONG DataBytesReceived;
  43. PMDL pSendParamMdl; //used if we cannot subsume
  44. PVOID pSendParamBuffer;
  45. ULONG SendParamBufferSize;
  46. ULONG ParamBytesSent;
  47. PMDL pReceiveParamMdl;
  48. ULONG ReceiveParamBufferSize;
  49. ULONG ParamBytesReceived;
  50. PVOID pSendSetupMdl;
  51. ULONG SendSetupBufferSize;
  52. PMDL pReceiveSetupMdl;
  53. ULONG ReceiveSetupBufferSize;
  54. ULONG SetupBytesReceived;
  55. // Transact exchange intrinsic fields
  56. ULONG PrimaryRequestSmbSize;
  57. PVOID pActualPrimaryRequestSmbHeader; // Original buffer allocated
  58. PSMB_HEADER pPrimaryRequestSmbHeader; // Start of header
  59. ULONG ParameterBytesSeen;
  60. ULONG DataBytesSeen;
  61. LONG PendingCopyRequests; //CODE.IMPROVEMENT this field is useless
  62. BOOLEAN fParamsSubsumedInPrimaryRequest;
  63. UCHAR TransactSmbCommand;
  64. USHORT Flags;
  65. USHORT NtTransactFunction;
  66. SMB_FILE_ID Fid; //CODE.IMPROVEMENT is this used?
  67. ULONG TransactionNameLength;
  68. ULONG MaximumTransmitSmbBufferSize;
  69. //used to cache value and also to force
  70. //smaller value for testing
  71. PSMB_TRANSACTION_RESUMPTION_CONTEXT pResumptionContext;
  72. struct {
  73. MDL TrailingBytesMdl;
  74. ULONG Pages[3]; //you need 2...one pad; this must cover an smbbuf
  75. };
  76. NTSTATUS SaveTheRealStatus;
  77. PVOID DiscardBuffer;
  78. struct {
  79. ULONG Bytes[TRAILING_BYTES_BUFFERSIZE/sizeof(ULONG)];
  80. } TrailingBytesBuffer;
  81. } SMB_TRANSACT_EXCHANGE, *PSMB_TRANSACT_EXCHANGE;
  82. typedef struct SMB_TRANSACTION_PARAMETERS {
  83. USHORT Flags;
  84. USHORT SetupLength; // the steup buffer length
  85. union {
  86. PVOID pSetup; // the setup buffer
  87. PMDL pSetupMdl; // the MDL version of the buffer
  88. };
  89. ULONG ParamLength;
  90. PVOID pParam; //you need the bufptr is you're subsuming
  91. PMDL pParamMdl; //you need the MDL is you can't subsume
  92. PMDL pDataMdl; // the data buffer
  93. ULONG DataLength; // this is total length...not the length
  94. // of the 1st mdl in the chain
  95. } SMB_TRANSACTION_PARAMETERS, *PSMB_TRANSACTION_PARAMETERS;
  96. typedef SMB_TRANSACTION_PARAMETERS SMB_TRANSACTION_SEND_PARAMETERS;
  97. typedef SMB_TRANSACTION_SEND_PARAMETERS* PSMB_TRANSACTION_SEND_PARAMETERS;
  98. typedef SMB_TRANSACTION_PARAMETERS SMB_TRANSACTION_RECEIVE_PARAMETERS;
  99. typedef SMB_TRANSACTION_RECEIVE_PARAMETERS* PSMB_TRANSACTION_RECEIVE_PARAMETERS;
  100. #define SMBCE_DEFAULT_TRANSACTION_TIMEOUT (0xffffffff)
  101. #define SMBCE_TRANSACTION_TIMEOUT_NOT_USED (0x0)
  102. typedef struct SMB_TRANSACTION_OPTIONS {
  103. USHORT NtTransactFunction;
  104. USHORT Flags;
  105. PUNICODE_STRING pTransactionName;
  106. ULONG TimeoutIntervalInMilliSeconds;
  107. ULONG MaximumTransmitSmbBufferSize;
  108. } SMB_TRANSACTION_OPTIONS, *PSMB_TRANSACTION_OPTIONS;
  109. #define DEFAULT_TRANSACTION_OPTIONS {0,0,NULL,SMBCE_TRANSACTION_TIMEOUT_NOT_USED,0xffff}
  110. extern SMB_TRANSACTION_OPTIONS RxDefaultTransactionOptions;
  111. #define TRANSACTION_SEND_PARAMETERS_FLAG (0x1)
  112. #define TRANSACTION_RECEIVE_PARAMETERS_FLAG (0x2)
  113. // xact and xact_options have the same flags so we have to be careful to strip off these bits
  114. // when we format up the smb ( the flags field is a USHORT)
  115. #define SMB_XACT_FLAGS_REPARSE (0x8000)
  116. #define SMB_XACT_FLAGS_FID_NOT_NEEDED (0x4000)
  117. #define SMB_XACT_FLAGS_CALLERS_SENDDATAMDL (0x2000)
  118. #define SMB_XACT_FLAGS_TID_FOR_FID (0x1000)
  119. #define SMB_XACT_FLAGS_MAILSLOT_OPERATION (0x0800)
  120. #define SMB_XACT_FLAGS_INDEFINITE_DELAY_IN_RESPONSE (0x0400)
  121. #define SMB_XACT_FLAGS_DFS_AWARE (0x0200)
  122. #define SMB_XACT_FLAGS_ASYNCHRONOUS (0x0100)
  123. //#define SMB_XACT_FLAGS_COPY_ON_ERROR (0x080)
  124. #define SMB_XACT_INTERNAL_FLAGS_MASK \
  125. ( SMB_XACT_FLAGS_REPARSE \
  126. | SMB_XACT_FLAGS_FID_NOT_NEEDED \
  127. | SMB_XACT_FLAGS_CALLERS_SENDDATAMDL \
  128. | SMB_XACT_FLAGS_TID_FOR_FID \
  129. | SMB_XACT_FLAGS_MAILSLOT_OPERATION \
  130. | SMB_XACT_FLAGS_INDEFINITE_DELAY_IN_RESPONSE \
  131. | SMB_XACT_FLAGS_DFS_AWARE \
  132. | SMB_XACT_FLAGS_ASYNCHRONOUS \
  133. )
  134. #if 0
  135. //CODE.IMROVEMENT.POSTPDC the constant SMB_TRANSACTION_VALID_FLAGS should be
  136. //in smb.h. SMB_TRANSACTION_RECONNECTING and SMB_TRANSACTION_DFSFILE should NOT
  137. //be in SMB.h. here is what's there now
  138. #define SMB_TRANSACTION_DISCONNECT 1
  139. #define SMB_TRANSACTION_NO_RESPONSE 2
  140. #define SMB_TRANSACTION_RECONNECTING 4
  141. #define SMB_TRANSACTION_DFSFILE 8
  142. #endif
  143. #define SMB_TRANSACTION_VALID_FLAGS (\
  144. SMB_TRANSACTION_DISCONNECT \
  145. | SMB_TRANSACTION_NO_RESPONSE \
  146. )
  147. #if ((SMB_XACT_INTERNAL_FLAGS_MASK & SMB_TRANSACTION_VALID_FLAGS) != 0)
  148. #error SMB_XACT_INTERNAL_FLAGS_MASK has overrun the transact flags
  149. #endif
  150. extern NTSTATUS
  151. SmbCeInitializeTransactionParameters(
  152. PVOID pSetup,
  153. USHORT SetupLength,
  154. PVOID pParam,
  155. ULONG ParamLength,
  156. PVOID pData,
  157. ULONG DataLength,
  158. PSMB_TRANSACTION_PARAMETERS pTransactionParameters);
  159. #define SmbCeProvideTransactionDataAsMdl(pTransactionParameters,pMdl,Length) { \
  160. ASSERT( (pTransactionParameters)->DataLength == 0 ); \
  161. ASSERT( (pTransactionParameters)->pDataMdl == NULL ); \
  162. ASSERT( FlagOn((pTransactionParameters)->Flags,TRANSACTION_SEND_PARAMETERS_FLAG) ); \
  163. (pTransactionParameters)->DataLength = Length; \
  164. (pTransactionParameters)->pDataMdl = pMdl; \
  165. (pTransactionParameters)->Flags |= SMB_XACT_FLAGS_CALLERS_SENDDATAMDL; \
  166. }
  167. extern VOID
  168. SmbCeUninitializeTransactionParameters(
  169. PSMB_TRANSACTION_PARAMETERS pTransactionParameters);
  170. extern VOID
  171. SmbCeDiscardTransactExchange(PSMB_TRANSACT_EXCHANGE pTransactExchange);
  172. INLINE NTSTATUS
  173. SmbCeInitializeTransactionSendParameters(
  174. PVOID pSetup,
  175. USHORT SetupLength,
  176. PVOID pParam,
  177. ULONG ParamLength,
  178. PVOID pData,
  179. ULONG DataLength,
  180. PSMB_TRANSACTION_SEND_PARAMETERS pSendParameters)
  181. {
  182. ((PSMB_TRANSACTION_PARAMETERS)pSendParameters)->Flags = TRANSACTION_SEND_PARAMETERS_FLAG;
  183. return SmbCeInitializeTransactionParameters(
  184. pSetup,SetupLength,pParam,ParamLength,pData,DataLength,pSendParameters);
  185. }
  186. INLINE NTSTATUS
  187. SmbCeInitializeTransactionReceiveParameters(
  188. PVOID pSetup,
  189. USHORT SetupLength,
  190. PVOID pParam,
  191. ULONG ParamLength,
  192. PVOID pData,
  193. ULONG DataLength,
  194. PSMB_TRANSACTION_RECEIVE_PARAMETERS pReceiveParameters)
  195. {
  196. ((PSMB_TRANSACTION_PARAMETERS)pReceiveParameters)->Flags = TRANSACTION_RECEIVE_PARAMETERS_FLAG;
  197. return SmbCeInitializeTransactionParameters(
  198. pSetup,SetupLength,pParam,ParamLength,pData,DataLength,pReceiveParameters);
  199. }
  200. #define SmbCeUninitializeTransactionSendParameters(pSendParameters) \
  201. ASSERT((pSendParameters)->Flags & TRANSACTION_SEND_PARAMETERS_FLAG); \
  202. SmbCeUninitializeTransactionParameters(pSendParameters);
  203. #define SmbCeUninitializeTransactionReceiveParameters(pReceiveParameters) \
  204. ASSERT((pReceiveParameters)->Flags & TRANSACTION_RECEIVE_PARAMETERS_FLAG); \
  205. SmbCeUninitializeTransactionParameters(pReceiveParameters)
  206. INLINE VOID
  207. SmbCeInitializeTransactionResumptionContext(
  208. PSMB_TRANSACTION_RESUMPTION_CONTEXT ptResumptionContext)
  209. {
  210. SmbCeInitializeResumptionContext(&(ptResumptionContext)->SmbCeResumptionContext);
  211. ptResumptionContext->SetupBytesReceived = 0;
  212. ptResumptionContext->DataBytesReceived = 0;
  213. ptResumptionContext->ParameterBytesReceived = 0;
  214. ptResumptionContext->FinalStatusFromServer = (STATUS_SUCCESS);
  215. }
  216. INLINE VOID
  217. SmbCeInitializeAsynchronousTransactionResumptionContext(
  218. PSMB_TRANSACTION_RESUMPTION_CONTEXT ptResumptionContext,
  219. PRX_WORKERTHREAD_ROUTINE pResumptionRoutine,
  220. PVOID pResumptionRoutineParam)
  221. {
  222. SmbCeInitializeAsynchronousResumptionContext(
  223. &ptResumptionContext->SmbCeResumptionContext,
  224. pResumptionRoutine,
  225. pResumptionRoutineParam);
  226. ptResumptionContext->SetupBytesReceived = 0;
  227. ptResumptionContext->DataBytesReceived = 0;
  228. ptResumptionContext->ParameterBytesReceived = 0;
  229. ptResumptionContext->FinalStatusFromServer = (STATUS_SUCCESS);
  230. }
  231. INLINE VOID
  232. SmbCeWaitOnTransactionResumptionContext(
  233. PSMB_TRANSACTION_RESUMPTION_CONTEXT pTransactionResumptionContext)
  234. {
  235. SmbCeSuspend(&pTransactionResumptionContext->SmbCeResumptionContext);
  236. }
  237. extern UNICODE_STRING s_NamedPipeTransactionName;
  238. extern UNICODE_STRING s_MailSlotTransactionName;
  239. extern NTSTATUS
  240. SmbCeSubmitTransactionRequest(
  241. PRX_CONTEXT RxContext,
  242. PSMB_TRANSACTION_OPTIONS pOptions,
  243. PSMB_TRANSACTION_PARAMETERS pSendParameters,
  244. PSMB_TRANSACTION_PARAMETERS pReceiveParameters,
  245. PSMB_TRANSACTION_RESUMPTION_CONTEXT pResumptionContext );
  246. extern NTSTATUS
  247. _SmbCeTransact(
  248. PRX_CONTEXT RxContext,
  249. PSMB_TRANSACTION_OPTIONS pOptions,
  250. PVOID pInputSetupBuffer,
  251. ULONG InputSetupBufferlength,
  252. PVOID pOutputSetupBuffer,
  253. ULONG OutputSetupBufferLength,
  254. PVOID pInputParamBuffer,
  255. ULONG InputParamBufferLength,
  256. PVOID pOutputParamBuffer,
  257. ULONG OutputParamBufferLength,
  258. PVOID pInputDataBuffer,
  259. ULONG InputDataBufferLength,
  260. PVOID pOutputDataBuffer,
  261. ULONG OutputDataBufferLength,
  262. PSMB_TRANSACTION_RESUMPTION_CONTEXT pResumptionContext);
  263. INLINE NTSTATUS
  264. SmbCeTransact(
  265. PRX_CONTEXT RxContext,
  266. PSMB_TRANSACTION_OPTIONS pOptions,
  267. PVOID pInputSetupBuffer,
  268. ULONG InputSetupBufferlength,
  269. PVOID pOutputSetupBuffer,
  270. ULONG OutputSetupBufferLength,
  271. PVOID pInputParamBuffer,
  272. ULONG InputParamBufferLength,
  273. PVOID pOutputParamBuffer,
  274. ULONG OutputParamBufferLength,
  275. PVOID pInputDataBuffer,
  276. ULONG InputDataBufferLength,
  277. PVOID pOutputDataBuffer,
  278. ULONG OutputDataBufferLength,
  279. PSMB_TRANSACTION_RESUMPTION_CONTEXT pResumptionContext)
  280. {
  281. SmbCeInitializeTransactionResumptionContext(pResumptionContext);
  282. return _SmbCeTransact(
  283. RxContext,
  284. pOptions,
  285. pInputSetupBuffer,
  286. InputSetupBufferlength,
  287. pOutputSetupBuffer,
  288. OutputSetupBufferLength,
  289. pInputParamBuffer,
  290. InputParamBufferLength,
  291. pOutputParamBuffer,
  292. OutputParamBufferLength,
  293. pInputDataBuffer,
  294. InputDataBufferLength,
  295. pOutputDataBuffer,
  296. OutputDataBufferLength,
  297. pResumptionContext);
  298. }
  299. INLINE NTSTATUS
  300. SmbCeAsynchronousTransact(
  301. PRX_CONTEXT RxContext,
  302. PSMB_TRANSACTION_OPTIONS pOptions,
  303. PVOID pInputSetupBuffer,
  304. ULONG InputSetupBufferlength,
  305. PVOID pOutputSetupBuffer,
  306. ULONG OutputSetupBufferLength,
  307. PVOID pInputParamBuffer,
  308. ULONG InputParamBufferLength,
  309. PVOID pOutputParamBuffer,
  310. ULONG OutputParamBufferLength,
  311. PVOID pInputDataBuffer,
  312. ULONG InputDataBufferLength,
  313. PVOID pOutputDataBuffer,
  314. ULONG OutputDataBufferLength,
  315. PSMB_TRANSACTION_RESUMPTION_CONTEXT pResumptionContext)
  316. {
  317. pOptions->Flags |= SMB_XACT_FLAGS_ASYNCHRONOUS;
  318. return _SmbCeTransact(
  319. RxContext,
  320. pOptions,
  321. pInputSetupBuffer,
  322. InputSetupBufferlength,
  323. pOutputSetupBuffer,
  324. OutputSetupBufferLength,
  325. pInputParamBuffer,
  326. InputParamBufferLength,
  327. pOutputParamBuffer,
  328. OutputParamBufferLength,
  329. pInputDataBuffer,
  330. InputDataBufferLength,
  331. pOutputDataBuffer,
  332. OutputDataBufferLength,
  333. pResumptionContext);
  334. }
  335. #endif // _TRANSACT_H_
  336.