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.

615 lines
25 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. StffTest.c
  5. Abstract:
  6. Author:
  7. Joe Linn [JoeLinn] 3-20-95
  8. Revision History:
  9. --*/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. #include <stdarg.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text(PAGE, MRxSmbSetFixedStufferStateFields)
  17. #pragma alloc_text(PAGE, SMBStuffHexDump)
  18. #pragma alloc_text(PAGE, MRxSmbFakeUpAnMdl)
  19. #pragma alloc_text(PAGE, MRxSmbStfTestReadAndWrite)
  20. #pragma alloc_text(PAGE, MRxSmbStfTestSessionStuff)
  21. #pragma alloc_text(PAGE, MRxSmbStfTestMoreOpenStuff)
  22. #pragma alloc_text(PAGE, MRxSmbStufferDebug)
  23. #pragma alloc_text(PAGE, MRxSmbBuildSmbHeaderTestSurrogate)
  24. #endif
  25. //
  26. // The local debug trace level
  27. //
  28. RXDT_DefineCategory(STFFTEST);
  29. #define Dbg (DEBUG_TRACE_STFFTEST)
  30. #define SET_INITIAL_SMB_DBGS 'FCX'
  31. VOID
  32. MRxSmbSetFixedStufferStateFields (
  33. IN OUT PSMBSTUFFER_BUFFER_STATE StufferState,
  34. IN PMDL Mdl,
  35. IN PSMB_EXCHANGE pExchange,
  36. IN PRX_CONTEXT RxContext,
  37. IN PBYTE ActualBufferBase,
  38. IN PBYTE BufferBase,
  39. IN PBYTE BufferLimit
  40. )
  41. {
  42. PAGED_CODE();
  43. StufferState->HeaderMdl = Mdl;
  44. StufferState->Exchange = pExchange;
  45. StufferState->RxContext = RxContext;
  46. StufferState->ActualBufferBase = ActualBufferBase;
  47. StufferState->BufferBase = BufferBase;
  48. StufferState->BufferLimit = BufferLimit;
  49. return;
  50. }
  51. #ifndef WIN9X
  52. #define ULONGS_PER_LINE 8
  53. VOID SMBStuffHexDump(
  54. IN PBYTE Base,
  55. IN PBYTE Limit,
  56. IN ULONG AddressOffset
  57. )
  58. {
  59. PBYTE i;
  60. char TextBuffer[128];
  61. char sBuffer[8];
  62. PAGED_CODE();
  63. for (i = Base;i<Limit;){
  64. ULONG j,k;
  65. PBYTE txt=TextBuffer + ULONGS_PER_LINE*9 + 4;
  66. PBYTE hex=TextBuffer + 3;
  67. RxSprintf(TextBuffer,"%03x%120c",i- Base+AddressOffset,' ');
  68. //RxDbgTrace(0, Dbg,("0- %s\n",TextBuffer));
  69. for (j=0;j<ULONGS_PER_LINE;j++) {
  70. if (i>=Limit) break;
  71. *txt++ = *hex++ = ' ';
  72. RxSprintf(hex,"%02lx%02lx%02lx%02lx",*(i+3),*(i+2),*(i+1),*i);
  73. hex+= 8;
  74. *hex = ' '; //intermediate
  75. for (k=0;k<sizeof(ULONG);k++) {
  76. CHAR c = *i++;
  77. // use <= here because we already incremented
  78. if (i<=Limit) {
  79. *txt++ = ( ((c>32)&&(c<127))
  80. ?c
  81. :'.'
  82. );
  83. } else {
  84. *txt++ = ' ';
  85. }
  86. *txt = 0;
  87. }
  88. //RxDbgTrace(0, Dbg,("1- %s\n",TextBuffer));
  89. }
  90. *txt = 0;
  91. RxDbgTrace(0,(DEBUG_TRACE_ALWAYS), (" %s\n",TextBuffer));
  92. }
  93. }
  94. #endif
  95. #if DBG
  96. VOID
  97. MRxSmbDumpStufferState (
  98. IN ULONG PrintLevel,
  99. IN PSZ Msg,
  100. IN PSMBSTUFFER_BUFFER_STATE StufferState //IN OUT for debug
  101. )
  102. {
  103. #ifndef WIN9X
  104. PBYTE i;
  105. ULONG CurrentSize = (ULONG)(StufferState->CurrentPosition - StufferState->BufferBase);
  106. RxDbgTraceLV__norx_reverseaction(0,StufferState->ControlPoint,PrintLevel,return);
  107. RxDbgTrace(0,(DEBUG_TRACE_ALWAYS),("%s Current size = %lx (%ld)\n", Msg, CurrentSize, CurrentSize));
  108. SMBStuffHexDump(StufferState->BufferBase,StufferState->CurrentPosition,0);
  109. if (StufferState->DataSize) {
  110. ULONG AmtToDump;
  111. PMDL Mdl = StufferState->DataMdl;
  112. //CODE.IMPROVEMENT the result of this is that you have to lock down BEFORE you
  113. // call stufferdump....maybe we should have a flag in stffstate that signals this
  114. // and lets you get the base the old way (startva+offset)
  115. PBYTE Base = (PBYTE)(Mdl->MappedSystemVa);
  116. #ifndef WIN9X
  117. ASSERT( Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | MDL_SOURCE_IS_NONPAGED_POOL));
  118. #endif
  119. RxDbgTrace(0, (DEBUG_TRACE_ALWAYS), ("-----------Data size = %lx (%ld)\n", StufferState->DataSize, StufferState->DataSize));
  120. AmtToDump = min(48,Mdl->ByteCount);
  121. SMBStuffHexDump(Base,Base+AmtToDump,CurrentSize);
  122. //CODE.IMPROVEMENT someday we'll have to handle a chain of MDLs
  123. }
  124. #endif // WIN9X
  125. }
  126. #endif // DBG
  127. SMBSTUFFER_BUFFER_STATE SmbStufferState;
  128. VOID
  129. MRxSmbFakeUpAnMdl(
  130. IN OUT PMDL Mdl,
  131. IN PBYTE Base,
  132. IN ULONG Length
  133. )
  134. {
  135. #ifndef WIN9X
  136. Mdl->StartVa = (PVOID)(((ULONG_PTR)Base) & ~(PAGE_SIZE - 1));
  137. Mdl->ByteOffset = (ULONG)(((ULONG_PTR)Base) &(PAGE_SIZE - 1));
  138. Mdl->MappedSystemVa = Base;
  139. #ifndef WIN9X
  140. Mdl->MdlFlags = MDL_SOURCE_IS_NONPAGED_POOL;
  141. #else
  142. Mdl->MdlFlags = 0;
  143. #endif
  144. Mdl->ByteCount = Length;
  145. #endif //win9x
  146. }
  147. VOID MRxSmbStfTestReadAndWrite(){
  148. CHAR Smb[512];
  149. NTSTATUS Status;
  150. //SMBbuf_STATUS SMBbufStatus;
  151. //Try some read&X and write&X operations...............
  152. char smallwritedata[] = "01234567012345670123456701234567";
  153. PAGED_CODE();
  154. MRxSmbSetFixedStufferStateFields(
  155. &SmbStufferState,
  156. NULL, NULL, NULL,
  157. &Smb[0],
  158. &Smb[0],
  159. &Smb[sizeof(Smb)]
  160. );
  161. RtlZeroMemory(SmbStufferState.BufferBase,
  162. SmbStufferState.BufferLimit - SmbStufferState.BufferBase
  163. );
  164. MRxSmbSetInitialSMB( &SmbStufferState STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS) );
  165. MRxSmbDumpStufferState (1,"Initial SMB",&SmbStufferState);
  166. Status = (( //qweee
  167. MRxSmbStartSMBCommand (&SmbStufferState, SetInitialSMB_Never, SMB_COM_READ_ANDX,
  168. SMB_REQUEST_SIZE(NT_READ_ANDX),
  169. NO_EXTRA_DATA,NO_SPECIAL_ALIGNMENT,RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  170. 0,0,0,0 STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS))
  171. )
  172. );
  173. RxDbgTrace(0, Dbg,("First readcommand status = %lu\n",Status));
  174. MRxSmbDumpStufferState (1,"SMB w/ NTREAD&X before stuffing",&SmbStufferState);
  175. //first, a nt_read_andx
  176. MRxSmbStuffSMB (&SmbStufferState,
  177. "XwdwWdW",
  178. 'dF', //Fid
  179. 'tsfO', //offset
  180. 'xM', //maxcnt
  181. SMB_OFFSET_CHECK(READ_ANDX,MinCount)
  182. // for debugging SMB_OFFSET_CHECK(READ_ANDX,MaxCount)
  183. 'nM', //mincnt
  184. 'tuoT', //timeout
  185. SMB_OFFSET_CHECK(READ_ANDX,Remaining)
  186. 'tC', //countleft
  187. StufferCondition(TRUE),"d",
  188. 'hgiH', //NT high offset
  189. STUFFER_CTL_NORMAL, "B!",
  190. SMB_WCT_CHECK(12)
  191. 0
  192. );
  193. MRxSmbDumpStufferState (1,"SMB w/ NTREAD&X after stuffing",&SmbStufferState);
  194. Status = (( //qweee
  195. MRxSmbStartSMBCommand (&SmbStufferState,SetInitialSMB_Never, SMB_COM_READ_ANDX,
  196. SMB_REQUEST_SIZE(NT_READ_ANDX),
  197. NO_EXTRA_DATA,NO_SPECIAL_ALIGNMENT,RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  198. 0,0,0,0 STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS))
  199. )
  200. );
  201. RxDbgTrace(0, Dbg,("Second readcommand status = %lu\n",Status));
  202. MRxSmbDumpStufferState (1,"SMB w/ notNTREAD&X before stuffing",&SmbStufferState);
  203. //next a read_andx....not NT
  204. MRxSmbStuffSMB (&SmbStufferState,
  205. "XwdwWdW",
  206. 'dF', //Fid
  207. 'tsfO', //offset
  208. 'xM', //maxcnt
  209. SMB_OFFSET_CHECK(READ_ANDX,MinCount)
  210. // for debugging SMB_OFFSET_CHECK(READ_ANDX,MaxCount)
  211. 'nM', //mincnt
  212. 'tuoT', //timeout
  213. SMB_OFFSET_CHECK(READ_ANDX,Remaining)
  214. 'tC', //countleft
  215. StufferCondition(FALSE),"d",
  216. 'hgiH', //NT high offset
  217. STUFFER_CTL_NORMAL, "B!",
  218. SMB_WCT_CHECK(10)
  219. 0
  220. );
  221. MRxSmbDumpStufferState (1,"SMB w/ notNTREAD&X after stuffing",&SmbStufferState);
  222. Status = (( //qweee
  223. MRxSmbStartSMBCommand (&SmbStufferState, SetInitialSMB_Never,SMB_COM_WRITE_ANDX,
  224. SMB_REQUEST_SIZE(NT_WRITE_ANDX),
  225. NO_EXTRA_DATA,NO_SPECIAL_ALIGNMENT,RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  226. 0,0,0,0 STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS))
  227. )
  228. );
  229. RxDbgTrace(0, Dbg,("Third readcommand status = %lu\n",Status));
  230. MRxSmbDumpStufferState (1,"SMB w/ NTWRITE&X before stuffing",&SmbStufferState);
  231. //next a NT_write_andX
  232. MRxSmbStuffSMB (&SmbStufferState,
  233. "XwddwWwwq",
  234. 'dF', //Fid
  235. 'tsfO', //offset
  236. 'tuoT', //timeout
  237. 'dM', //writemode
  238. SMB_OFFSET_CHECK(WRITE_ANDX,Remaining)
  239. 'tC', //countleft (remaining)
  240. '--', //reserved
  241. sizeof(smallwritedata), //dsize
  242. //doffset is the 'q'
  243. StufferCondition(TRUE),"d",
  244. 'hgiH', //NT high offset
  245. STUFFER_CTL_NORMAL, "BSc5!",
  246. SMB_WCT_CHECK(14)
  247. sizeof(smallwritedata),smallwritedata,
  248. 0
  249. );
  250. MRxSmbDumpStufferState (1,"SMB w/ NTWRITE&X after stuffing",&SmbStufferState);
  251. //RxDbgTrace(0, Dbg,("Here in stuffer debug\n"));
  252. }
  253. VOID MRxSmbStfTestSessionStuff(){
  254. CHAR Smb[512];
  255. NTSTATUS Status;
  256. //SMBbuf_STATUS SMBbufStatus;
  257. char AsciiPassword[] = "AsciiPassword"; //this causes a pad to word boundary
  258. // before unicode strings
  259. UNICODE_STRING Password,AccountName,PrimaryDomain,NativeOS,NativeLanMan,FileToOpen;
  260. USHORT SSandX_Flags2 = 0;
  261. BOOLEAN NTstyle = TRUE;
  262. NET_ROOT MyNetRoot;
  263. PAGED_CODE();
  264. MRxSmbSetFixedStufferStateFields(
  265. &SmbStufferState,
  266. NULL, NULL, NULL,
  267. &Smb[0],
  268. &Smb[0],
  269. &Smb[sizeof(Smb)]
  270. );
  271. //Try some SS&X and TC&X operations...............
  272. RtlZeroMemory(SmbStufferState.BufferBase,
  273. SmbStufferState.BufferLimit-SmbStufferState.BufferBase
  274. );
  275. RtlInitUnicodeString(&Password, L"Password");
  276. RtlInitUnicodeString(&AccountName, L"AccountName");
  277. RtlInitUnicodeString(&PrimaryDomain, L"PrimaryDomain");
  278. RtlInitUnicodeString(&NativeOS, L"NativeOS");
  279. RtlInitUnicodeString(&NativeLanMan, L"NativeLanMan");
  280. RtlInitUnicodeString(&FileToOpen, L"FileToOpen");
  281. ZeroAndInitializeNodeType(&MyNetRoot, RDBSS_NTC_NETROOT, (NODE_BYTE_SIZE) sizeof(MyNetRoot));
  282. RtlInitUnicodeString(&MyNetRoot.PrefixEntry.Prefix, L"\\SERver\\SHare");
  283. MRxSmbSetInitialSMB( &SmbStufferState STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS));
  284. MRxSmbDumpStufferState (1,"Initial SMB",&SmbStufferState);
  285. Status = (( //qweee
  286. MRxSmbStartSMBCommand (&SmbStufferState, SetInitialSMB_Never,
  287. SMB_COM_SESSION_SETUP_ANDX, SMB_REQUEST_SIZE(NT_SESSION_SETUP_ANDX),
  288. NO_EXTRA_DATA,NO_SPECIAL_ALIGNMENT,RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  289. 0,0,
  290. SMB_FLAGS2_UNICODE,SMB_FLAGS2_UNICODE STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS))
  291. )
  292. );
  293. RxDbgTrace(0, Dbg,("First SS&X command status = %lu\n",Status));
  294. MRxSmbDumpStufferState (1,"SMB w/ NTSESSSS&X before stuffing",&SmbStufferState);
  295. RxDbgTrace(0, Dbg, ("APsize=%lx, UPsize=%lx\n",sizeof(AsciiPassword),Password.Length));
  296. //first, a nt_SS_andx
  297. MRxSmbStuffSMB (&SmbStufferState,
  298. "XwwwDw",
  299. 'fB', //Bufsize
  300. 'xM', //mpxmax
  301. 'cV', //vc_num
  302. SMB_OFFSET_CHECK(SESSION_SETUP_ANDX,SessionKey)
  303. // for debugging SMB_OFFSET_CHECK(READ_ANDX,MaxCount)
  304. 'sseS', //SessionKey
  305. sizeof(AsciiPassword), //apasslen
  306. StufferCondition(NTstyle),"wddBcczzzz",
  307. Password.Length, //upasslen
  308. 'dvsR', //reserved
  309. 'spaC', //capabilities
  310. SMB_WCT_CHECK(13)
  311. sizeof(AsciiPassword),AsciiPassword,
  312. Password.Length,Password.Buffer,
  313. &AccountName,&PrimaryDomain,&NativeOS,&NativeLanMan,
  314. STUFFER_CTL_NORMAL, "!",
  315. 0
  316. );
  317. MRxSmbDumpStufferState (1,"SMB w/ NTSESSSS&X after stuffing",&SmbStufferState);
  318. Status = (( //qweee
  319. MRxSmbStartSMBCommand (&SmbStufferState,SetInitialSMB_Never,
  320. SMB_COM_TREE_CONNECT_ANDX,SMB_REQUEST_SIZE(TREE_CONNECT_ANDX),
  321. NO_EXTRA_DATA,NO_SPECIAL_ALIGNMENT,RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  322. 0,0,
  323. SMB_FLAGS2_UNICODE,SMB_FLAGS2_UNICODE STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS)
  324. )
  325. )
  326. );
  327. RxDbgTrace(0, Dbg,("TC&X command status = %lu\n",Status));
  328. MRxSmbDumpStufferState (1,"SMB w/ TREECON&X before stuffing",&SmbStufferState);
  329. MRxSmbStuffSMB (&SmbStufferState,
  330. "XwwBana!",
  331. 'gF', //Flags
  332. 1, //spaslen
  333. SMB_WCT_CHECK(4)
  334. "",
  335. &MyNetRoot,
  336. "A:",
  337. 0
  338. );
  339. MRxSmbDumpStufferState (1,"SMB w/ TREECON&X after stuffing",&SmbStufferState);
  340. Status = (( //qweee
  341. MRxSmbStartSMBCommand (&SmbStufferState,SetInitialSMB_Never,SMB_COM_NT_CREATE_ANDX,
  342. SMB_REQUEST_SIZE(NT_CREATE_ANDX),
  343. NO_EXTRA_DATA,SMB_BEST_ALIGNMENT(4,0),RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  344. 0,0,0,0 STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS))
  345. )
  346. );
  347. RxDbgTrace(0, Dbg,("Third readcommand status = %lu\n",Status));
  348. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X before stuffing",&SmbStufferState);
  349. MRxSmbStuffSMB (&SmbStufferState,
  350. "XmwdddDdddDddyB",
  351. FileToOpen.Length, //NameLength
  352. 'sglF', //Flags
  353. 'difD', //root directory fid
  354. 'ksaM', //Mask
  355. SMB_OFFSET_CHECK(NT_CREATE_ANDX,AllocationSize)
  356. ' woL','hgiH', //alloc size
  357. 'brtA', //Attributes
  358. 'ccAS', //share Access
  359. SMB_OFFSET_CHECK(NT_CREATE_ANDX,CreateDisposition)
  360. 'psiD', //CreateDisposition
  361. 'ntpO', //CreateOptions
  362. 'lvlI', //ImpersonationLevel
  363. 0xdd, //SecurityFlags (just a byte)
  364. SMB_WCT_CHECK(24)
  365. 0
  366. );
  367. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X midway into stuffing",&SmbStufferState);
  368. {ULONG i;
  369. for (i=0;i<1100;i+=128){
  370. RxDbgTrace(0,Dbg,("Testing for fit: %lu %s\n",
  371. i,(MrxSMBWillThisFit(&SmbStufferState,4,i)?"Fits":"Doesn't Fit")
  372. ));
  373. }}
  374. //proceed with the stuff because we know here that the name fits
  375. MRxSmbStuffSMB (&SmbStufferState,
  376. "v!", &FileToOpen);
  377. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X after stuffing",&SmbStufferState);
  378. }
  379. VOID MRxSmbStfTestMoreOpenStuff(){
  380. CHAR Smb[512];
  381. NTSTATUS Status;
  382. //SMBbuf_STATUS SMBbufStatus;
  383. BOOLEAN NTstyle = TRUE;
  384. UNICODE_STRING FileToOpen,FileToOpen3;
  385. PBYTE RegionPtr;
  386. MDL FakeMdlForFileName;
  387. PAGED_CODE();
  388. MRxSmbSetFixedStufferStateFields(
  389. &SmbStufferState,
  390. NULL, NULL, NULL,
  391. &Smb[0],
  392. &Smb[0],
  393. &Smb[sizeof(Smb)]
  394. );
  395. RtlZeroMemory(SmbStufferState.BufferBase,
  396. SmbStufferState.BufferLimit-SmbStufferState.BufferBase
  397. );
  398. RtlInitUnicodeString(&FileToOpen, L"FileToOpen2");
  399. RtlInitUnicodeString(&FileToOpen3, L"FFFFToOpen3");
  400. MRxSmbFakeUpAnMdl(&FakeMdlForFileName,(PBYTE)FileToOpen.Buffer,FileToOpen.Length);
  401. MRxSmbSetInitialSMB( &SmbStufferState STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS));
  402. MRxSmbDumpStufferState (1,"Initial SMB",&SmbStufferState);
  403. Status = (( //qweee
  404. MRxSmbStartSMBCommand (&SmbStufferState,SetInitialSMB_Never,SMB_COM_NT_CREATE_ANDX,
  405. SMB_REQUEST_SIZE(NT_CREATE_ANDX),
  406. NO_EXTRA_DATA,SMB_BEST_ALIGNMENT(4,0),RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  407. 0,0,0,0 STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS))
  408. )
  409. );
  410. RxDbgTrace(0, Dbg,("Initial NTCREATE&X status = %lu\n",Status));
  411. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X before stuffing",&SmbStufferState);
  412. MRxSmbStuffSMB (&SmbStufferState,
  413. "XmwdddDdddDddyB",
  414. FileToOpen.Length, //NameLength
  415. 'sglF', //Flags
  416. 'difD', //root directory fid
  417. 'ksaM', //Mask
  418. SMB_OFFSET_CHECK(NT_CREATE_ANDX,AllocationSize)
  419. ' woL','hgiH', //alloc size
  420. 'brtA', //Attributes
  421. 'ccAS', //share Access
  422. SMB_OFFSET_CHECK(NT_CREATE_ANDX,CreateDisposition)
  423. 'psiD', //CreateDisposition
  424. 'ntpO', //CreateOptions
  425. 'lvlI', //ImpesonationLevel
  426. 0xdd, //SecurityFlags (just a byte)
  427. SMB_WCT_CHECK(24)
  428. 0
  429. );
  430. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X midway into stuffing",&SmbStufferState);
  431. {ULONG i;
  432. for (i=0;i<1100;i+=128){
  433. RxDbgTrace(0,Dbg,("Testing for fit: %lu %s\n",
  434. i,(MrxSMBWillThisFit(&SmbStufferState,4,i)?"Fits":"Doesn't Fit")
  435. ));
  436. }}
  437. //proceed with the stuff because we know here that the name fits
  438. MRxSmbStuffSMB (&SmbStufferState,
  439. "rv!",
  440. &RegionPtr,0,
  441. &FileToOpen);
  442. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X after stuffing",&SmbStufferState);
  443. if(((ULONG_PTR)RegionPtr)&1) RegionPtr++;
  444. RtlCopyMemory(RegionPtr,FileToOpen3.Buffer,FileToOpen3.Length);
  445. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X after filename replacement",&SmbStufferState);
  446. Status = (( //qweee
  447. MRxSmbStartSMBCommand (&SmbStufferState,SetInitialSMB_Never,SMB_COM_NT_CREATE_ANDX,
  448. SMB_REQUEST_SIZE(NT_CREATE_ANDX),
  449. NO_EXTRA_DATA,SMB_BEST_ALIGNMENT(4,0),RESPONSE_HEADER_SIZE_NOT_SPECIFIED,
  450. 0,0,0,0 STUFFERTRACE(Dbg,SET_INITIAL_SMB_DBGS))
  451. )
  452. );
  453. RxDbgTrace(0, Dbg,("Another NTCREATE&X status = %lu\n",Status));
  454. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X before stuffing",&SmbStufferState);
  455. MRxSmbStuffSMB (&SmbStufferState,
  456. "XmwdddDdddDddyB",
  457. FileToOpen.Length, //NameLength
  458. 'sglF', //Flags
  459. 'difD', //root directory fid
  460. 'ksaM', //Mask
  461. SMB_OFFSET_CHECK(NT_CREATE_ANDX,AllocationSize)
  462. ' woL','hgiH', //alloc size
  463. 'brtA', //Attributes
  464. 'ccAS', //share Access
  465. SMB_OFFSET_CHECK(NT_CREATE_ANDX,CreateDisposition)
  466. 'psiD', //CreateDisposition
  467. 'ntpO', //CreateOptions
  468. 'lvlI', //ImpesonationLevel
  469. 0xdd, //SecurityFlags (just a byte)
  470. SMB_WCT_CHECK(24)
  471. 0
  472. );
  473. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X midway into stuffing",&SmbStufferState);
  474. MRxSmbStuffSMB (&SmbStufferState,
  475. "s?", 2, 0);
  476. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X after alignment",&SmbStufferState);
  477. MRxSmbStuffAppendRawData(&SmbStufferState,&FakeMdlForFileName);
  478. MRxSmbStuffSetByteCount(&SmbStufferState);
  479. MRxSmbDumpStufferState (1,"SMB w/ NTOPEN&X after filename replacement",&SmbStufferState);
  480. }
  481. #include "fsctlbuf.h"
  482. NTSTATUS
  483. MRxSmbStufferDebug(
  484. IN PRX_CONTEXT RxContext
  485. )
  486. {
  487. NTSTATUS Status = STATUS_SUCCESS;
  488. PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
  489. PSZ ControlString = LowIoContext->ParamsFor.FsCtl.pInputBuffer;
  490. ULONG OutputBufferLength = LowIoContext->ParamsFor.FsCtl.OutputBufferLength;
  491. ULONG InputBufferLength = LowIoContext->ParamsFor.FsCtl.InputBufferLength;
  492. ULONG i;
  493. PAGED_CODE();
  494. RxDbgTrace(0, Dbg,("Here in stuffer debug %s, obl = %08lx\n",ControlString, OutputBufferLength));
  495. MRxSmbStfTestReadAndWrite();
  496. MRxSmbStfTestSessionStuff();
  497. MRxSmbStfTestMoreOpenStuff();
  498. //return an obvious string to make sure that darryl is copying the results out correctly
  499. //need to check the lengths i.e. need outputl<=inputl
  500. for (i=0;i<InputBufferLength;i++) {
  501. UCHAR c = ControlString[i];
  502. if (c==0) { break; }
  503. if ((i&3)==2) {
  504. ControlString[i] = '@';
  505. }
  506. }
  507. RxContext->InformationToReturn = i+1;
  508. return(Status);
  509. }
  510. NTSTATUS
  511. MRxSmbBuildSmbHeaderTestSurrogate(
  512. PSMB_EXCHANGE pExchange,
  513. PVOID pBuffer,
  514. ULONG BufferLength,
  515. PULONG pBufferConsumed,
  516. PUCHAR pLastCommandInHeader,
  517. PUCHAR *pNextCommandPtr)
  518. {
  519. PNT_SMB_HEADER NtSmbHeader = (PNT_SMB_HEADER)pBuffer;
  520. PAGED_CODE();
  521. RtlZeroMemory(NtSmbHeader,sizeof(NT_SMB_HEADER));
  522. *(PULONG)(&NtSmbHeader->Protocol) = SMB_HEADER_PROTOCOL;
  523. NtSmbHeader->Command = SMB_COM_NO_ANDX_COMMAND;
  524. SmbPutUshort (&NtSmbHeader->Pid, MRXSMB_PROCESS_ID_ZERO);
  525. SmbPutUshort (&NtSmbHeader->Mid, MRXSMB_MULTIPLX_ID_ZERO);
  526. SmbPutUshort (&NtSmbHeader->Uid, MRXSMB_USER_ID_ZERO);
  527. SmbPutUshort (&NtSmbHeader->Tid, MRXSMB_TREE_ID_ZERO);
  528. *pLastCommandInHeader = SMB_COM_NO_ANDX_COMMAND;
  529. *pNextCommandPtr = &NtSmbHeader->Command;
  530. *pBufferConsumed = sizeof(SMB_HEADER);
  531. return(STATUS_SUCCESS);
  532. }