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.

3370 lines
122 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. fileinfo.c
  5. Abstract:
  6. This module implements the mini redirector call down routines pertaining to retrieval/
  7. update of file/directory/volume information.
  8. Author:
  9. Joe Linn [JoeLi] 7-March-1995
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #pragma warning(error:4101) // Unreferenced local variable
  15. RXDT_DefineCategory(DIRCTRL);
  16. #define Dbg (DEBUG_TRACE_DIRCTRL)
  17. #ifdef ALLOC_PRAGMA
  18. #pragma alloc_text(PAGE, __MRxSmbAllocateSideBuffer)
  19. #pragma alloc_text(PAGE, MRxSmbDeallocateSideBuffer)
  20. #pragma alloc_text(PAGE, MRxSmbTranslateLanManFindBuffer)
  21. #pragma alloc_text(PAGE, MrxSmbUnalignedDirEntryCopyTail)
  22. #pragma alloc_text(PAGE, MRxSmbQueryDirectory)
  23. #pragma alloc_text(PAGE, MRxSmbQueryVolumeInformation)
  24. #pragma alloc_text(PAGE, MRxSmbQueryVolumeInformationWithFullBuffer)
  25. #pragma alloc_text(PAGE, MRxSmbSetVolumeInformation)
  26. #pragma alloc_text(PAGE, MRxSmbQueryFileInformation)
  27. #pragma alloc_text(PAGE, MRxSmbSetFileInformation)
  28. #pragma alloc_text(PAGE, MRxSmbQueryNamedPipeInformation)
  29. #pragma alloc_text(PAGE, MRxSmbSetNamedPipeInformation)
  30. #pragma alloc_text(PAGE, MRxSmbSetFileInformationAtCleanup)
  31. #pragma alloc_text(PAGE, MRxSmbIsValidDirectory)
  32. #pragma alloc_text(PAGE, MRxSmbQueryFileInformationFromPseudoOpen)
  33. #endif
  34. #define MRxSmbForceCoreInfo FALSE
  35. //#define FORCECOREINFO
  36. #if DBG
  37. #ifdef FORCECOREINFO
  38. #undef MRxSmbForceCoreInfo
  39. BOOLEAN MRxSmbForceCoreInfo = TRUE;
  40. #endif
  41. #endif
  42. BOOLEAN MRxSmbBypassDownLevelRename = FALSE;
  43. //BOOLEAN MRxSmbBypassDownLevelRename = TRUE;
  44. ULONG UnalignedDirEntrySideBufferSize = 16384;
  45. //
  46. // All T2Find requests to the remote server request the 32 bit resume key
  47. // so SMB_RFIND_BUFFER2 is used instead of SMB_FIND_BUFFER2.
  48. //
  49. typedef struct _SMB_FIND_BUFFER2_WITH_RESUME {
  50. _ULONG( ResumeKey );
  51. SMB_FIND_BUFFER2;
  52. } SMB_FIND_BUFFER2_WITH_RESUME;
  53. typedef SMB_FIND_BUFFER2_WITH_RESUME SMB_UNALIGNED *PSMB_FIND_BUFFER2_WITH_RESUME;
  54. //CODE.IMPROVEMENT we should have a nondebug version of this sidebuffer stuff
  55. // that basically just does a allocatepool/freepool
  56. LIST_ENTRY MRxSmbSideBuffersList = {NULL,NULL};
  57. ULONG MRxSmbSideBuffersSpinLock = 0;
  58. ULONG MRxSmbSideBuffersCount = 0;
  59. ULONG MRxSmbSideBuffersSerialNumber = 0;
  60. BOOLEAN MRxSmbLoudSideBuffers = FALSE;
  61. extern BOOLEAN UniqueFileNames;
  62. typedef struct _SIDE_BUFFER {
  63. ULONG Signature;
  64. LIST_ENTRY ListEntry;
  65. PMRX_FCB Fcb;
  66. PMRX_FOBX Fobx;
  67. PMRX_SMB_FOBX smbFobx;
  68. ULONG SerialNumber;
  69. BYTE Buffer;
  70. } SIDE_BUFFER, *PSIDE_BUFFER;
  71. #if DBG
  72. #define MRxSmbAllocateSideBuffer(a,b,c,d) __MRxSmbAllocateSideBuffer(a,b,c,d)
  73. #else
  74. #define MRxSmbAllocateSideBuffer(a,b,c,d) __MRxSmbAllocateSideBuffer(a,b,c)
  75. #endif
  76. NTSTATUS
  77. MRxSmbCoreCheckPath(
  78. SMBPSE_ORDINARY_EXCHANGE_ARGUMENT_SIGNATURE
  79. );
  80. VOID
  81. __MRxSmbAllocateSideBuffer(
  82. IN OUT PRX_CONTEXT RxContext,
  83. IN OUT PMRX_SMB_FOBX smbFobx,
  84. IN USHORT Setup
  85. #if DBG
  86. ,IN PUNICODE_STRING smbtemplate
  87. #endif
  88. )
  89. {
  90. RxCaptureFcb;RxCaptureFobx;
  91. PSIDE_BUFFER SideBuffer;
  92. ULONG SideBufferSize = UnalignedDirEntrySideBufferSize+sizeof(SIDE_BUFFER);
  93. POOL_TYPE PoolType;
  94. PAGED_CODE();
  95. ASSERT( smbFobx->Enumeration.UnalignedDirEntrySideBuffer == NULL);
  96. #ifdef _WIN64
  97. //
  98. // NT64: When PagedPool is used here, we get memory corruption on
  99. // some findfirst/findnext operations. Find out why.
  100. //
  101. PoolType = NonPagedPool;
  102. #else
  103. PoolType = PagedPool;
  104. #endif
  105. SideBuffer = (PSIDE_BUFFER)RxAllocatePoolWithTag(
  106. PoolType,
  107. SideBufferSize,
  108. MRXSMB_DIRCTL_POOLTAG);
  109. if (SideBuffer==NULL) {
  110. return;
  111. }
  112. ASSERT( smbFobx->Enumeration.UnalignedDirEntrySideBuffer == NULL);
  113. SideBuffer->Signature = 'JLBS';
  114. SideBuffer->smbFobx = smbFobx;
  115. SideBuffer->Fobx = capFobx;
  116. SideBuffer->Fcb = capFcb;
  117. smbFobx->Enumeration.UnalignedDirEntrySideBuffer = &SideBuffer->Buffer;
  118. RxLog(("Allocsidebuf %lx fo/f=%lx,%lx\n",
  119. smbFobx->Enumeration.UnalignedDirEntrySideBuffer,
  120. capFobx,capFcb));
  121. SmbLog(LOG,
  122. MRxSmbAllocateSideBuffer,
  123. LOGPTR(smbFobx->Enumeration.UnalignedDirEntrySideBuffer)
  124. LOGPTR(capFobx)
  125. LOGPTR(capFcb));
  126. smbFobx->Enumeration.SerialNumber = SideBuffer->SerialNumber = InterlockedIncrement(&MRxSmbSideBuffersSerialNumber);
  127. InterlockedIncrement(&MRxSmbSideBuffersCount);
  128. if (MRxSmbSideBuffersList.Flink==NULL) {
  129. InitializeListHead(&MRxSmbSideBuffersList);
  130. }
  131. ExAcquireFastMutex(&MRxSmbSerializationMutex);
  132. InsertTailList(&MRxSmbSideBuffersList,&SideBuffer->ListEntry);
  133. ExReleaseFastMutex(&MRxSmbSerializationMutex);
  134. if (!MRxSmbLoudSideBuffers) return;
  135. KdPrint(("Allocating side buffer %08lx %08lx %08lx %08lx %08lxon <%wZ> %s %wZ\n",
  136. &SideBuffer->Buffer,
  137. MRxSmbSideBuffersCount,
  138. smbFobx,capFobx,capFobx->pSrvOpen,
  139. GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext),
  140. (Setup == TRANS2_FIND_FIRST2)?"First":"Next",
  141. smbtemplate
  142. ));
  143. }
  144. VOID
  145. MRxSmbDeallocateSideBuffer(
  146. IN OUT PRX_CONTEXT RxContext,
  147. IN OUT PMRX_SMB_FOBX smbFobx,
  148. IN PSZ where
  149. )
  150. {
  151. PSIDE_BUFFER SideBuffer;
  152. RxCaptureFcb;RxCaptureFobx;
  153. PAGED_CODE();
  154. if( smbFobx->Enumeration.UnalignedDirEntrySideBuffer == NULL) return;
  155. SideBuffer = CONTAINING_RECORD(smbFobx->Enumeration.UnalignedDirEntrySideBuffer,SIDE_BUFFER,Buffer);
  156. if (MRxSmbLoudSideBuffers){
  157. DbgPrint("D--------- side buffer %08lx %08lx %08lx %08lx %08lxon <%wZ> %s\n",
  158. &SideBuffer->Buffer,
  159. MRxSmbSideBuffersCount,
  160. smbFobx,capFobx,capFobx->pSrvOpen,
  161. GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext),
  162. where
  163. );
  164. }
  165. ASSERT(SideBuffer->Signature == 'JLBS');
  166. ASSERT(SideBuffer->Fobx == capFobx);
  167. ASSERT(SideBuffer->Fcb == capFcb);
  168. ASSERT(SideBuffer->smbFobx == smbFobx);
  169. ASSERT(smbFobx->Enumeration.SerialNumber == SideBuffer->SerialNumber);
  170. ExAcquireFastMutex(&MRxSmbSerializationMutex);
  171. InterlockedDecrement(&MRxSmbSideBuffersCount);
  172. RemoveEntryList(&SideBuffer->ListEntry);
  173. ExReleaseFastMutex(&MRxSmbSerializationMutex);
  174. RxLog(("Deallocsidebuf %lx fo/f=%lx,%lx\n",
  175. smbFobx->Enumeration.UnalignedDirEntrySideBuffer,
  176. capFobx,capFcb));
  177. SmbLog(LOG,
  178. MRxSmbDeallocateSideBuffer,
  179. LOGPTR(smbFobx->Enumeration.UnalignedDirEntrySideBuffer)
  180. LOGPTR(capFobx)
  181. LOGPTR(capFcb));
  182. RxFreePool(SideBuffer);
  183. smbFobx->Enumeration.UnalignedDirEntrySideBuffer = NULL;
  184. }
  185. #if 0
  186. //
  187. // The NtQueryDirectory response contains one of the following three structures. We use this union
  188. // to reduce the amount of casting needed
  189. //
  190. typedef union _SMB_RFIND_BUFFER_NT {
  191. FILE_NAMES_INFORMATION Names;
  192. FILE_DIRECTORY_INFORMATION Dir;
  193. FILE_FULL_DIR_INFORMATION FullDir;
  194. FILE_BOTH_DIR_INFORMATION BothDir;
  195. } SMB_RFIND_BUFFER_NT;
  196. typedef SMB_RFIND_BUFFER_NT SMB_UNALIGNED *PSMB_RFIND_BUFFER_NT;
  197. #endif
  198. VOID
  199. MRxSmbTranslateLanManFindBuffer(
  200. PRX_CONTEXT RxContext,
  201. PULONG PreviousReturnedEntry,
  202. PBYTE ThisEntryInBuffer
  203. )
  204. {
  205. RxCaptureFcb; RxCaptureFobx;
  206. PSMBCEDB_SERVER_ENTRY pServerEntry;
  207. PSMBCE_SERVER Server;
  208. ULONG FileInformationClass = RxContext->Info.FileInformationClass;
  209. PFILE_FULL_DIR_INFORMATION NtBuffer = (PFILE_FULL_DIR_INFORMATION)PreviousReturnedEntry;
  210. PSMB_FIND_BUFFER2_WITH_RESUME SmbBuffer = (PSMB_FIND_BUFFER2_WITH_RESUME)ThisEntryInBuffer;
  211. SMB_TIME Time;
  212. SMB_DATE Date;
  213. PAGED_CODE();
  214. if (FileInformationClass==FileNamesInformation) { return; }
  215. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  216. //CODE.IMPROVEMENT we should cacheup the server somewhere....getting it everytime is uneficient
  217. Server = &pServerEntry->Server;
  218. SmbMoveTime (&Time, &SmbBuffer->CreationTime);
  219. SmbMoveDate (&Date, &SmbBuffer->CreationDate);
  220. NtBuffer->CreationTime = MRxSmbConvertSmbTimeToTime(Server, Time, Date);
  221. SmbMoveTime (&Time, &SmbBuffer->LastAccessTime);
  222. SmbMoveDate (&Date, &SmbBuffer->LastAccessDate);
  223. NtBuffer->LastAccessTime = MRxSmbConvertSmbTimeToTime(Server, Time, Date);
  224. SmbMoveTime (&Time, &SmbBuffer->LastWriteTime);
  225. SmbMoveDate (&Date, &SmbBuffer->LastWriteDate);
  226. NtBuffer->LastWriteTime = MRxSmbConvertSmbTimeToTime(Server, Time, Date);
  227. NtBuffer->ChangeTime.QuadPart = 0;
  228. NtBuffer->EndOfFile.QuadPart = SmbGetUlong(&SmbBuffer->DataSize);
  229. NtBuffer->AllocationSize.QuadPart = SmbGetUlong(&SmbBuffer->AllocationSize);
  230. NtBuffer->FileAttributes = MRxSmbMapSmbAttributes(SmbBuffer->Attributes);
  231. if ((FileInformationClass==FileFullDirectoryInformation)
  232. || (FileInformationClass==FileBothDirectoryInformation)) {
  233. NtBuffer->EaSize = SmbGetUlong(&SmbBuffer->EaSize);
  234. }
  235. }
  236. NTSTATUS
  237. MrxSmbUnalignedDirEntryCopyTail(
  238. IN OUT PRX_CONTEXT RxContext,
  239. IN FILE_INFORMATION_CLASS FileInformationClass,
  240. IN OUT PVOID pBuffer,
  241. IN OUT PULONG pLengthRemaining,
  242. IN OUT PMRX_SMB_FOBX smbFobx
  243. )
  244. /*++
  245. Routine Description:
  246. This routine copies the data from the side buffer into the users buffer and adjusts the
  247. lengths remaining appropriately. this is called either if the server doesn't do unicode (w95) OR
  248. if the server does not promise to quadalign entries OR if the user's buffer is not quadaligned.
  249. CODE.IMPROVEMENT if the user's buffer isn't quadaligned we could still get by in most cases by reading the data
  250. into the moved up buffer and then just copying the first entry.
  251. this routine can be entered after a T2 finishes or to copy the last entries from a previous T2. in the second case, the
  252. pUnalignedDirEntrySideBuffer ptr will be null and it will go to acquire the correct pointer from the smbFobx.
  253. this routine has the responsibility to free the sidebufferptr when it is exhausted.
  254. //CODE.IMPROVEMENT.ASHAMED (joe) i apologize for this code.....it is so ugly....but it does
  255. handle nt, win95/samba, and lanman in the same routine. the transformation is nontrivial even
  256. tho it is straightforward to implement.
  257. Arguments:
  258. RxContext - the RDBSS context
  259. Return Value:
  260. RXSTATUS - The return status for the operation
  261. --*/
  262. {
  263. NTSTATUS Status = STATUS_SUCCESS;
  264. RxCaptureFcb;
  265. ULONG i,NameSizeInUnicode;
  266. LONG LocalLengthRemaining; //signed arithmetic makes it easier
  267. PULONG PreviousReturnedEntry = NULL;
  268. ULONG FileNameLengthOffset = smbFobx->Enumeration.FileNameLengthOffset;
  269. ULONG FileNameOffset = smbFobx->Enumeration.FileNameOffset;
  270. PBYTE UnalignedDirEntrySideBuffer = smbFobx->Enumeration.UnalignedDirEntrySideBuffer;
  271. BOOLEAN IsUnicode = smbFobx->Enumeration.IsUnicode;
  272. BOOLEAN IsNonNtT2Find = smbFobx->Enumeration.IsNonNtT2Find;
  273. PMRX_SMB_DIRECTORY_RESUME_INFO ResumeInfo = smbFobx->Enumeration.ResumeInfo;
  274. ULONG FilesReturned = smbFobx->Enumeration.FilesReturned;
  275. ULONG EntryOffset = smbFobx->Enumeration.EntryOffset;
  276. ULONG ReturnedEntryOffset = 0;// = smbFobx->Enumeration.ReturnedEntryOffset; //CODE.IMPROVEMENT get rid of this variable.....
  277. BOOLEAN EndOfSearchReached = smbFobx->Enumeration.EndOfSearchReached;
  278. ULONG TotalDataBytesReturned = smbFobx->Enumeration.TotalDataBytesReturned;
  279. BOOLEAN FilterFailure = FALSE;
  280. PAGED_CODE();
  281. LocalLengthRemaining = (LONG)(*pLengthRemaining);
  282. //
  283. // keep looping until we've filled in all we can or there're no more entries
  284. for (i=ReturnedEntryOffset=0;;) {
  285. ULONG FileNameLength,ThisEntrySize; PCHAR FileNameBuffer;
  286. UNICODE_STRING ReturnedFileName;
  287. OEM_STRING FileName;
  288. NTSTATUS StringStatus;
  289. BOOLEAN TwoExtraBytes = TRUE;
  290. ULONG resumekey,NextEntryOffsetinBuffer;
  291. PULONG PreviousPreviousReturnedEntry = NULL;
  292. PBYTE ThisEntryInBuffer = UnalignedDirEntrySideBuffer+EntryOffset;
  293. //
  294. // don't EVER let yourself get past the data returned...servers return funny stuff.......
  295. if (EntryOffset>=TotalDataBytesReturned){
  296. FilterFailure = TRUE;
  297. FilesReturned = i; //we're done with this buffer........
  298. break;
  299. }
  300. //
  301. // find the name, the length, and the resume key based on whether it is a NT-T2find or a nonNT
  302. if (!IsNonNtT2Find) {
  303. //
  304. // NT, we use the offsets that we stored earlier.........
  305. FileNameLength = SmbGetUlong(ThisEntryInBuffer+FileNameLengthOffset);
  306. FileNameBuffer = ThisEntryInBuffer+FileNameOffset;
  307. resumekey = SmbGetUlong(ThisEntryInBuffer
  308. +FIELD_OFFSET(FILE_FULL_DIR_INFORMATION,FileIndex));
  309. NextEntryOffsetinBuffer = SmbGetUlong(ThisEntryInBuffer);
  310. } else {
  311. //
  312. // for lanman, we always ask for stuff using the SMB_FIND_BUFFER2 to which
  313. // we have prepended a resume key. so, the name is always at a fixed offset.
  314. // Also, for nonNT we have read all the files and must filter out correctly; we
  315. // save where we are in the user's buffer so that we can roll back.
  316. FileNameLength = *(ThisEntryInBuffer
  317. +FIELD_OFFSET(SMB_FIND_BUFFER2_WITH_RESUME,FileNameLength));
  318. FileNameBuffer = ThisEntryInBuffer
  319. +FIELD_OFFSET(SMB_FIND_BUFFER2_WITH_RESUME,FileName[0]);
  320. resumekey = SmbGetUlong(ThisEntryInBuffer+
  321. +FIELD_OFFSET(SMB_FIND_BUFFER2_WITH_RESUME,ResumeKey));
  322. NextEntryOffsetinBuffer = FIELD_OFFSET(SMB_FIND_BUFFER2_WITH_RESUME,FileName[0])
  323. + FileNameLength + 1; //the +1 is for the null..we could have said Filename{1]
  324. PreviousPreviousReturnedEntry = PreviousReturnedEntry; //save this for rollback on filterfail
  325. }
  326. // some servers lie about how many entries were returned and/or send partial entries
  327. // dont let them trick us..........
  328. if (EntryOffset+NextEntryOffsetinBuffer>TotalDataBytesReturned){
  329. FilterFailure = TRUE;
  330. FilesReturned = i; //we're done with this buffer........
  331. break;
  332. }
  333. if (FileNameLength > 0xFFFF) {
  334. Status = STATUS_INVALID_NETWORK_RESPONSE;
  335. break;
  336. }
  337. FileName.Buffer = FileNameBuffer;
  338. FileName.Length = (USHORT)FileNameLength;
  339. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: EO,REO=%08lx,%08lx\n",
  340. EntryOffset,ReturnedEntryOffset));
  341. //check to see if this entry will fit
  342. if (IsUnicode) {
  343. NameSizeInUnicode = FileNameLength;
  344. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: length=%08lx/%08lx, name = %wZ\n",
  345. FileNameLength,NameSizeInUnicode,&FileName));
  346. } else {
  347. //CODE.IMPROVEMENT should i use RtlOemStringToUnicodeSize???
  348. NameSizeInUnicode = RtlxOemStringToUnicodeSize(&FileName)-sizeof(WCHAR);
  349. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: length=%08lx/%08lx, name = %.*s\n",
  350. FileNameLength,NameSizeInUnicode,FileNameLength,FileNameBuffer));
  351. }
  352. //
  353. // now that we know the size of the name and its location, we need to copy it
  354. // to the user's buffer
  355. ThisEntrySize = FileNameOffset+NameSizeInUnicode;
  356. if ((!IsNonNtT2Find ||
  357. smbFobx->Enumeration.WildCardsFound) &&
  358. ((LONG)ThisEntrySize)>LocalLengthRemaining) {
  359. break;
  360. }
  361. if (((LONG)ThisEntrySize)>LocalLengthRemaining-(LONG)sizeof(WCHAR)) {
  362. TwoExtraBytes = FALSE;
  363. }
  364. ThisEntrySize = LongAlign(ThisEntrySize);
  365. PreviousReturnedEntry = (PULONG)(((PBYTE)pBuffer)+ReturnedEntryOffset);
  366. //
  367. // next we compute where the next entry after this one will start. the definition is
  368. // that it must be 8-byte aligned. we know already that it's 4byte aligned.
  369. if (!IsPtrQuadAligned((PCHAR)(PreviousReturnedEntry)+ThisEntrySize) ){
  370. ThisEntrySize += sizeof(ULONG);
  371. }
  372. if (i!=0) {
  373. ASSERT(IsPtrQuadAligned(PreviousReturnedEntry));
  374. }
  375. //
  376. // if this is an NT find, we can copy in the data now. for lanman, we
  377. // copy in the data later........
  378. if (!IsNonNtT2Find) {
  379. //copy everything in the entry up to but not including the name info
  380. RtlCopyMemory(PreviousReturnedEntry,UnalignedDirEntrySideBuffer+EntryOffset,FileNameOffset);
  381. } else {
  382. // clear out all fields i cannot support.
  383. RtlZeroMemory(PreviousReturnedEntry,FileNameOffset);
  384. }
  385. // store the length of this entry and the size of the name...if this is the last
  386. // entry returned, then the offset field will be cleared later
  387. *PreviousReturnedEntry = ThisEntrySize;
  388. *((PULONG)(((PBYTE)PreviousReturnedEntry)+FileNameLengthOffset)) = NameSizeInUnicode;
  389. //copy in the name .........this is made difficult by the oem-->unicode routine that
  390. // requires space for a NULL! CODE.IMPROVEMENT maybe we should have own routine that
  391. // doesn't require space for the null
  392. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: REO/buf/pentry=%08lx/%08lx/%08lx\n",
  393. pBuffer,ReturnedEntryOffset,PreviousReturnedEntry));
  394. ReturnedFileName.Buffer = (PWCH)(((PBYTE)PreviousReturnedEntry)+FileNameOffset);
  395. if (!IsUnicode) {
  396. if (TwoExtraBytes) {
  397. ReturnedFileName.MaximumLength = sizeof(WCHAR)+(USHORT)NameSizeInUnicode;
  398. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: filenamebuf,length=%08lx/%08lx\n",
  399. ReturnedFileName.Buffer,ReturnedFileName.MaximumLength));
  400. StringStatus = RtlOemStringToUnicodeString(&ReturnedFileName,&FileName,FALSE); //false means don;t allocate
  401. } else {
  402. ReturnedFileName.MaximumLength = (USHORT)NameSizeInUnicode;
  403. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: filenamebuf,length=%08lx/%08lx\n",
  404. ReturnedFileName.Buffer,ReturnedFileName.MaximumLength));
  405. StringStatus = RtlOemStringToCountedUnicodeString(&ReturnedFileName,&FileName,FALSE); //false means don;t allocate
  406. ASSERT(StringStatus==RX_MAP_STATUS(SUCCESS));
  407. }
  408. ASSERT(StringStatus==RX_MAP_STATUS(SUCCESS));
  409. // Win95 returns the shortname in ascii....spread it out
  410. if ((FileInformationClass == FileBothDirectoryInformation) && !IsNonNtT2Find) {
  411. PFILE_BOTH_DIR_INFORMATION BothInfo = (PFILE_BOTH_DIR_INFORMATION)PreviousReturnedEntry;
  412. OEM_STRING oemName;
  413. UNICODE_STRING UnicodeName;
  414. WCHAR wcharBuffer[MAX_PATH];
  415. oemName.Buffer = (PBYTE)(&BothInfo->ShortName[0]);
  416. oemName.Length =
  417. oemName.MaximumLength = BothInfo->ShortNameLength;
  418. UnicodeName.Buffer = wcharBuffer;
  419. UnicodeName.Length = 0;
  420. UnicodeName.MaximumLength = MAX_PATH * sizeof(WCHAR);
  421. StringStatus = RtlOemStringToUnicodeString(&UnicodeName, &oemName, FALSE);
  422. ASSERT(StringStatus==RX_MAP_STATUS(SUCCESS));
  423. BothInfo->ShortNameLength = (CHAR)UnicodeName.Length;
  424. RtlCopyMemory(BothInfo->ShortName, UnicodeName.Buffer, UnicodeName.Length);
  425. IF_DEBUG {
  426. UNICODE_STRING LastName;
  427. LastName.Buffer = (PWCHAR)wcharBuffer;
  428. LastName.Length = (USHORT)UnicodeName.Length;
  429. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: unicodeshortnamename = %wZ\n", &LastName));
  430. }
  431. }
  432. } else {
  433. //here, it's already unicode.....just copy the bytes
  434. RtlCopyMemory(ReturnedFileName.Buffer,FileName.Buffer,FileName.Length);
  435. }
  436. IF_DEBUG {
  437. UNICODE_STRING LastName;
  438. LastName.Buffer = ReturnedFileName.Buffer;
  439. LastName.Length = (USHORT)NameSizeInUnicode;
  440. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: unicodename = %wZ\n", &LastName));
  441. }
  442. //now...setup to resume based on this entry
  443. if (ResumeInfo != NULL) {
  444. PREQ_FIND_NEXT2 pFindNext2Request = &ResumeInfo->FindNext2_Request;
  445. //ULONG resumekey = ((PFILE_FULL_DIR_INFORMATION)PreviousReturnedEntry)->FileIndex;
  446. //CODE.IMPROVEMENT put asserts here that all of the levels have the fileindex in the same spot
  447. // for goodness sake.....use a macro. actually, this code should go up above
  448. // where (a) all the types are visible and (b) it will execute on the NT path as well
  449. pFindNext2Request->ResumeKey = resumekey;
  450. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectoryWin95: resumekey = %08lx\n", resumekey));
  451. RtlCopyMemory(&pFindNext2Request->Buffer[0],FileNameBuffer,FileNameLength);
  452. //buffer is a UCHAR...not WCHAR
  453. if (IsUnicode) {
  454. // In the case of UNICODE strings an additional NULL is required ( WCHAR NULL )
  455. pFindNext2Request->Buffer[FileNameLength] = 0; //nullterminated
  456. pFindNext2Request->Buffer[FileNameLength + 1] = 0; //nullterminated
  457. smbFobx->Enumeration.ResumeInfo->ParametersLength
  458. = (USHORT)(&pFindNext2Request->Buffer[FileNameLength+2] - (PBYTE)pFindNext2Request);
  459. } else {
  460. pFindNext2Request->Buffer[FileNameLength] = 0; //nullterminated
  461. smbFobx->Enumeration.ResumeInfo->ParametersLength
  462. = (USHORT)(&pFindNext2Request->Buffer[FileNameLength+1] - (PBYTE)pFindNext2Request);
  463. }
  464. }
  465. //ASSERT(!IsNonNtT2Find);
  466. //at this point, we have copied the name and the resume key. BUT, for nonnt we have to
  467. //filter the names so we still may have to roll back
  468. if (!IsNonNtT2Find) {
  469. //no need for filtering on NT
  470. FilterFailure = FALSE;
  471. } else {
  472. // here we have to filter out based on the template
  473. RxCaptureFobx; //do this here so it's not on the NT path
  474. FilterFailure = FALSE;
  475. if (smbFobx->Enumeration.WildCardsFound ) {
  476. try
  477. {
  478. FilterFailure = !FsRtlIsNameInExpression(
  479. &capFobx->UnicodeQueryTemplate,
  480. &ReturnedFileName,
  481. TRUE,
  482. NULL );
  483. }
  484. except(EXCEPTION_EXECUTE_HANDLER)
  485. {
  486. FilterFailure = TRUE;
  487. }
  488. } else {
  489. FilterFailure = !RtlEqualUnicodeString(
  490. &capFobx->UnicodeQueryTemplate,
  491. &ReturnedFileName,
  492. TRUE ); //case-insensitive
  493. }
  494. if (!FilterFailure) {
  495. if (((LONG)ThisEntrySize)>LocalLengthRemaining) {
  496. break;
  497. }
  498. // since we didn't copy the data before, we have to copy it now...
  499. MRxSmbTranslateLanManFindBuffer(RxContext,PreviousReturnedEntry,ThisEntryInBuffer);
  500. } else {
  501. PreviousReturnedEntry = PreviousPreviousReturnedEntry; //rollback on filterfail
  502. }
  503. }
  504. if (!FilterFailure) {
  505. // filtering succeeded..... adjust returned sizes and counts
  506. LocalLengthRemaining -= ThisEntrySize;
  507. i++;
  508. ReturnedEntryOffset += ThisEntrySize;
  509. } else {
  510. FilesReturned--; //we exit the loop if i passes filesreturned
  511. }
  512. //
  513. // complicated test to keep going.......
  514. //EntryOffset += SmbGetUlong(UnalignedDirEntrySideBuffer+EntryOffset);
  515. EntryOffset += NextEntryOffsetinBuffer;
  516. if ((i>=FilesReturned)
  517. ||(LocalLengthRemaining<0)
  518. || (RxContext->QueryDirectory.ReturnSingleEntry&&(i>0)) ) {
  519. //CODE.IMPROVEMENT we could be more agressive than 0 in the compare against
  520. // locallengthremaining....it's actually whatever
  521. // the minimum recordsize is..........probably FileNameOffset
  522. break;
  523. }
  524. }
  525. if (Status == STATUS_SUCCESS) {
  526. //
  527. // if we are not returning even one entry, either we didn't have space for even one entry
  528. // OR we're filtering and no guys passed the filter. return an appropriate error in each case
  529. if (i==0) {
  530. Status = FilterFailure?STATUS_MORE_PROCESSING_REQUIRED:STATUS_BUFFER_OVERFLOW;
  531. } else {
  532. *PreviousReturnedEntry = 0; // this clears the "next" link for the last returned entry
  533. }
  534. //
  535. // send back the right size
  536. if (LocalLengthRemaining <= 0) {
  537. *pLengthRemaining = 0;
  538. } else {
  539. *pLengthRemaining = (ULONG)LocalLengthRemaining;
  540. }
  541. //
  542. // if we're finished with the sidebuffer, deallocate it.
  543. // otherwise setup to resume........
  544. if (i>=FilesReturned) {
  545. RxLog(("sidebufdealloc %lx %lx\n",RxContext,smbFobx));
  546. SmbLog(LOG,
  547. MrxSmbUnalignedDirEntryCopyTail,
  548. LOGPTR(RxContext)
  549. LOGPTR(smbFobx));
  550. MRxSmbDeallocateSideBuffer(RxContext,smbFobx,"Tail");
  551. if (EndOfSearchReached) {
  552. //smbFobx->Enumeration.Flags &= ~SMBFOBX_ENUMFLAG_SEARCH_HANDLE_OPEN;
  553. //we will close the search handle when the user's handle closes
  554. smbFobx->Enumeration.ErrorStatus = STATUS_NO_MORE_FILES;
  555. }
  556. } else {
  557. //set up to resume here
  558. ASSERT(smbFobx->Enumeration.UnalignedDirEntrySideBuffer == UnalignedDirEntrySideBuffer);
  559. smbFobx->Enumeration.EntryOffset = EntryOffset;
  560. smbFobx->Enumeration.FilesReturned = FilesReturned - i;
  561. }
  562. } else {
  563. smbFobx->Enumeration.ErrorStatus = Status;
  564. RxLog(("sidebufdealloc %lx %lx\n",RxContext,smbFobx));
  565. SmbLog(LOG,
  566. MrxSmbUnalignedDirEntryCopyTail,
  567. LOGPTR(RxContext)
  568. LOGPTR(smbFobx));
  569. MRxSmbDeallocateSideBuffer(RxContext,smbFobx,"Tail");
  570. }
  571. return(Status);
  572. }
  573. NTSTATUS
  574. MRxSmbQueryDirectoryFromCache (
  575. PRX_CONTEXT RxContext,
  576. PSMBPSE_FILEINFO_BUNDLE FileInfo
  577. )
  578. /*++
  579. Routine Description:
  580. This routine copies the data from the file information cache into the users buffer and adjusts the
  581. lengths remaining appropriately. This will avoid to send the FindFirst and FindClose requests to
  582. the server.
  583. Arguments:
  584. RxContext - the RDBSS context
  585. FileInfo - the basic and standard file information
  586. Return Value:
  587. NTSTATUS - The return status for the operation
  588. Notes:
  589. --*/
  590. {
  591. NTSTATUS Status = STATUS_SUCCESS;
  592. RxCaptureFcb;
  593. RxCaptureFobx;
  594. PMRX_SMB_FCB smbFcb = MRxSmbGetFcbExtension(capFcb);
  595. PMRX_SMB_FOBX smbFobx = MRxSmbGetFileObjectExtension(capFobx);
  596. PBYTE pBuffer = RxContext->Info.Buffer;
  597. PULONG pLengthRemaining = &RxContext->Info.LengthRemaining;
  598. FILE_INFORMATION_CLASS FileInformationClass = RxContext->Info.FileInformationClass;
  599. PUNICODE_STRING FileName = &capFobx->UnicodeQueryTemplate;
  600. ULONG SpaceNeeded = smbFobx->Enumeration.FileNameOffset+FileName->Length;
  601. RxDbgTrace(+1, Dbg,
  602. ("MRxSmbQueryDirectoryFromCache entry(%08lx)...%08lx %08lx %08lx %08lx\n",
  603. RxContext,
  604. FileInformationClass,pBuffer,*pLengthRemaining,
  605. smbFobx->Enumeration.ResumeInfo ));
  606. if (SpaceNeeded > *pLengthRemaining) {
  607. Status = STATUS_BUFFER_OVERFLOW;
  608. goto FINALLY;
  609. }
  610. RtlZeroMemory(pBuffer,smbFobx->Enumeration.FileNameOffset);
  611. switch (FileInformationClass) {
  612. case FileNamesInformation:
  613. Status = STATUS_MORE_PROCESSING_REQUIRED;
  614. goto FINALLY;
  615. break;
  616. case FileBothDirectoryInformation:
  617. if (!UniqueFileNames) {
  618. Status = STATUS_MORE_PROCESSING_REQUIRED;
  619. goto FINALLY;
  620. }
  621. // lack of break is intentional
  622. case FileDirectoryInformation:
  623. case FileFullDirectoryInformation: {
  624. PFILE_DIRECTORY_INFORMATION pThisBuffer = (PFILE_DIRECTORY_INFORMATION)pBuffer;
  625. pThisBuffer->FileAttributes = FileInfo->Basic.FileAttributes;
  626. pThisBuffer->CreationTime = FileInfo->Basic.CreationTime;
  627. pThisBuffer->LastAccessTime = FileInfo->Basic.LastAccessTime;
  628. pThisBuffer->LastWriteTime = FileInfo->Basic.LastWriteTime;
  629. pThisBuffer->EndOfFile = FileInfo->Standard.EndOfFile;
  630. pThisBuffer->AllocationSize = FileInfo->Standard.AllocationSize;
  631. break;
  632. }
  633. default:
  634. RxDbgTrace( 0, Dbg, ("MRxSmbCoreFileSearch: Invalid FS information class\n"));
  635. ASSERT(!"this can't happen");
  636. Status = STATUS_INVALID_PARAMETER;
  637. goto FINALLY;
  638. }
  639. RtlCopyMemory(pBuffer+smbFobx->Enumeration.FileNameOffset,
  640. FileName->Buffer,
  641. FileName->Length);
  642. *((PULONG)(pBuffer+smbFobx->Enumeration.FileNameLengthOffset)) = FileName->Length;
  643. *pLengthRemaining -= SpaceNeeded;
  644. FINALLY:
  645. RxDbgTrace(-1, Dbg, ("MRxSmbQueryDirectoryFromCache exit-> %08lx %08lx\n", RxContext, Status ));
  646. return Status;
  647. }
  648. ULONG MRxSmbWin95Retries = 0;
  649. NTSTATUS
  650. MRxSmbQueryDirectory(
  651. IN OUT PRX_CONTEXT RxContext
  652. )
  653. /*++
  654. Routine Description:
  655. This routine does a directory query. Only the NT-->NT path is implemented.
  656. //CODE.IMPROVEMENT.ASHAMED this code is UGLY and has no reasonable modularity............
  657. Arguments:
  658. RxContext - the RDBSS context
  659. Return Value:
  660. RXSTATUS - The return status for the operation
  661. --*/
  662. {
  663. NTSTATUS Status;
  664. RxCaptureFcb;
  665. RxCaptureFobx;
  666. PMRX_SMB_FCB smbFcb = MRxSmbGetFcbExtension(capFcb);
  667. PMRX_SMB_FOBX smbFobx = MRxSmbGetFileObjectExtension(capFobx);
  668. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  669. PMRX_SMB_SRV_OPEN smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  670. PSMBCE_V_NET_ROOT_CONTEXT pVNetRootContext = SmbCeGetAssociatedVNetRootContext(SrvOpen->pVNetRoot);
  671. PSMBCE_SESSION pSession = &pVNetRootContext->pSessionEntry->Session;
  672. FILE_INFORMATION_CLASS FileInformationClass;
  673. PVOID Buffer;
  674. PULONG pLengthRemaining;
  675. USHORT SmbFileInfoLevel;
  676. ULONG FilesReturned;
  677. ULONG RetryCount = 0;
  678. USHORT Setup;
  679. PSMBCEDB_SERVER_ENTRY pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  680. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  681. PSMB_TRANSACTION_OPTIONS pTransactionOptions = &RxDefaultTransactionOptions;
  682. //REQ_FIND_NEXT2 FindNext2Request;
  683. PREQ_FIND_FIRST2 pFindFirst2Request = NULL;
  684. PBYTE SendParamsBuffer,ReceiveParamsBuffer;
  685. PBYTE UnalignedDirEntrySideBuffer;
  686. BOOLEAN DirEntriesAreUaligned = FALSE;
  687. BOOLEAN IsUnicode = TRUE;
  688. BOOLEAN IsNonNtT2Find;
  689. USHORT SearchFlags = SMB_FIND_CLOSE_AT_EOS|SMB_FIND_RETURN_RESUME_KEYS;
  690. USHORT NumEntries;
  691. ULONG SendParamsBufferLength,ReceiveParamsBufferLength;
  692. //CODE.IMPROVEMENT this should be overallocated and unioned
  693. RESP_FIND_FIRST2 FindFirst2Response;
  694. SMBPSE_FILEINFO_BUNDLE FileInfo;
  695. UNICODE_STRING FileName = {0,0,NULL};
  696. struct {
  697. RESP_FIND_NEXT2 FindNext2Response;
  698. ULONG Pad; //nonnt needs this
  699. } XX;
  700. #if DBG
  701. UNICODE_STRING smbtemplate = {0,0,NULL};
  702. #endif
  703. PAGED_CODE();
  704. TURN_BACK_ASYNCHRONOUS_OPERATIONS();
  705. FileInformationClass = RxContext->Info.FileInformationClass;
  706. Buffer = RxContext->Info.Buffer;
  707. pLengthRemaining = &RxContext->Info.LengthRemaining;
  708. RxDbgTrace(+1, Dbg, ("MRxSmbQueryDirectory: directory=<%wZ>\n",
  709. GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext)
  710. ));
  711. #define __GET_NAME_PARAMS_FOR_TYPE(___type___) { \
  712. smbFobx->Enumeration.FileNameOffset = (USHORT)FIELD_OFFSET(___type___,FileName[0]); \
  713. smbFobx->Enumeration.FileNameLengthOffset = (USHORT)FIELD_OFFSET(___type___,FileNameLength); \
  714. }
  715. switch (FileInformationClass) {
  716. case FileDirectoryInformation:
  717. SmbFileInfoLevel = SMB_FIND_FILE_DIRECTORY_INFO;
  718. __GET_NAME_PARAMS_FOR_TYPE(FILE_DIRECTORY_INFORMATION);
  719. break;
  720. case FileFullDirectoryInformation:
  721. SmbFileInfoLevel = SMB_FIND_FILE_FULL_DIRECTORY_INFO;
  722. __GET_NAME_PARAMS_FOR_TYPE(FILE_FULL_DIR_INFORMATION);
  723. break;
  724. case FileBothDirectoryInformation:
  725. SmbFileInfoLevel = SMB_FIND_FILE_BOTH_DIRECTORY_INFO;
  726. __GET_NAME_PARAMS_FOR_TYPE(FILE_BOTH_DIR_INFORMATION);
  727. break;
  728. case FileNamesInformation:
  729. SmbFileInfoLevel = SMB_FIND_FILE_NAMES_INFO;
  730. __GET_NAME_PARAMS_FOR_TYPE(FILE_NAMES_INFORMATION);
  731. break;
  732. case FileIdFullDirectoryInformation:
  733. SmbFileInfoLevel = SMB_FIND_FILE_ID_FULL_DIRECTORY_INFO;
  734. __GET_NAME_PARAMS_FOR_TYPE(FILE_ID_FULL_DIR_INFORMATION);
  735. break;
  736. case FileIdBothDirectoryInformation:
  737. SmbFileInfoLevel = SMB_FIND_FILE_ID_BOTH_DIRECTORY_INFO;
  738. __GET_NAME_PARAMS_FOR_TYPE(FILE_ID_BOTH_DIR_INFORMATION);
  739. break;
  740. default:
  741. RxDbgTrace( 0, Dbg, ("MRxSmbQueryDirectory: Invalid FS information class\n"));
  742. Status = STATUS_INVALID_PARAMETER;
  743. goto FINALLY;
  744. }
  745. IF_NOT_MRXSMB_BUILD_FOR_DISCONNECTED_CSC{
  746. NOTHING;
  747. } else {
  748. if (CscPerformOperationInDisconnectedMode(RxContext)){
  749. NTSTATUS DirCtrlNtStatus;
  750. DirCtrlNtStatus = MRxSmbDCscQueryDirectory(RxContext);
  751. if (DirCtrlNtStatus != STATUS_MORE_PROCESSING_REQUIRED) {
  752. RxDbgTrace(0, Dbg,
  753. ("MRxSmbQueryVolumeInfo returningDCON with status=%08lx\n",
  754. DirCtrlNtStatus ));
  755. Status = DirCtrlNtStatus;
  756. goto FINALLY;
  757. } else {
  758. NOTHING;
  759. }
  760. }
  761. }
  762. #if DBG
  763. if (MRxSmbLoudSideBuffers) {
  764. SetFlag(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_LOUD_FINALIZE);
  765. }
  766. #endif
  767. if( RxContext->QueryDirectory.RestartScan )
  768. {
  769. ClearFlag( smbFobx->Enumeration.Flags, SMBFOBX_ENUMFLAG_SEARCH_NOT_THE_FIRST );
  770. MRxSmbDeallocateSideBuffer(RxContext,smbFobx,"Restart");
  771. }
  772. if (FlagOn(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_SEARCH_NOT_THE_FIRST) &&
  773. (FlagOn(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_NO_WILDCARD) ||
  774. FlagOn(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_READ_FROM_CACHE))) {
  775. // if the FindFirst has been satisfied basied on local file information cache,
  776. // we should fail the FindNext since the file has been found with the exact name.
  777. Status = RX_MAP_STATUS(NO_MORE_FILES);
  778. smbFobx->Enumeration.EndOfSearchReached = TRUE;
  779. smbFobx->Enumeration.ErrorStatus = RX_MAP_STATUS(NO_MORE_FILES);
  780. ClearFlag(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_READ_FROM_CACHE);
  781. goto FINALLY;
  782. }
  783. if (capFobx->UnicodeQueryTemplate.Length != 0 &&
  784. !FsRtlDoesNameContainWildCards(&capFobx->UnicodeQueryTemplate) &&
  785. !FlagOn(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_SEARCH_NOT_THE_FIRST)) {
  786. // if it is the FindFirst, we try to find the file on local file information cache.
  787. PUNICODE_STRING DirectoryName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
  788. PUNICODE_STRING Template = &capFobx->UnicodeQueryTemplate;
  789. UNICODE_STRING TargetName = {0,0,NULL};
  790. TargetName.Length = DirectoryName->Length + Template->Length + sizeof(WCHAR);
  791. TargetName.MaximumLength = TargetName.Length;
  792. TargetName.Buffer = (PWCHAR)RxAllocatePoolWithTag(PagedPool,
  793. TargetName.Length,
  794. MRXSMB_DIRCTL_POOLTAG);
  795. if (TargetName.Buffer == NULL) {
  796. Status = STATUS_INSUFFICIENT_RESOURCES;
  797. goto FINALLY;
  798. }
  799. RtlCopyMemory(TargetName.Buffer,
  800. DirectoryName->Buffer,
  801. DirectoryName->Length);
  802. TargetName.Buffer[DirectoryName->Length/sizeof(WCHAR)] = L'\\';
  803. RtlCopyMemory(&TargetName.Buffer[DirectoryName->Length/sizeof(WCHAR)+1],
  804. Template->Buffer,
  805. Template->Length);
  806. if (MRxSmbIsFileInfoCacheFound(RxContext,
  807. &FileInfo,
  808. &Status,
  809. &TargetName)) {
  810. // if the file has been found on the local cache, we satisfy the FindFirst
  811. // basied on the cache.
  812. if (Status == STATUS_SUCCESS) {
  813. Status = MRxSmbQueryDirectoryFromCache(RxContext, &FileInfo);
  814. if (Status != STATUS_MORE_PROCESSING_REQUIRED) {
  815. SetFlag(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_READ_FROM_CACHE);
  816. RxFreePool(TargetName.Buffer);
  817. goto FINALLY;
  818. }
  819. }
  820. }
  821. RxFreePool(TargetName.Buffer);
  822. SearchFlags |= SMB_FIND_CLOSE_AFTER_REQUEST;
  823. SetFlag(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_NO_WILDCARD);
  824. }
  825. if (FlagOn(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_DEFERRED_OPEN)) {
  826. BOOLEAN AcquireExclusive = RxIsFcbAcquiredExclusive(capFcb);
  827. BOOLEAN AcquireShare = RxIsFcbAcquiredShared(capFcb) > 0;
  828. if (AcquireExclusive || AcquireShare) {
  829. RxReleaseFcbResourceInMRx(capFcb );
  830. }
  831. // connection could have been timed out, try to reconnect.
  832. Status = SmbCeReconnect(SrvOpen->pVNetRoot);
  833. if (AcquireExclusive) {
  834. RxAcquireExclusiveFcbResourceInMRx( capFcb );
  835. } else if (AcquireShare) {
  836. RxAcquireExclusiveFcbResourceInMRx( capFcb );
  837. }
  838. if (Status != STATUS_SUCCESS) {
  839. // connection cannot be recovered.
  840. goto FINALLY;
  841. }
  842. }
  843. //RxPurgeRelatedFobxs((PNET_ROOT)(capFcb->pNetRoot), RxContext, FALSE);
  844. //RxScavengeFobxsForNetRoot((PNET_ROOT)(capFcb->pNetRoot));
  845. if (MRxSmbForceCoreInfo ||
  846. !(pServerEntry->Server.DialectFlags&(DF_NT_SMBS|DF_W95|DF_LANMAN20))) {
  847. return MRxSmbCoreInformation(RxContext,
  848. (ULONG)SmbFileInfoLevel,
  849. Buffer,
  850. pLengthRemaining,
  851. SMBPSE_OE_FROM_QUERYDIRECTORY
  852. );
  853. }
  854. if (smbFobx->Enumeration.UnalignedDirEntrySideBuffer != NULL){
  855. RxDbgTrace( 0, Dbg, ("MRxSmbQueryDirectory: win95 internal resume\n"));
  856. Status = MrxSmbUnalignedDirEntryCopyTail(RxContext,
  857. FileInformationClass,
  858. Buffer,
  859. pLengthRemaining, //CODE.IMPROVEMENT dont pass args 2-4
  860. smbFobx);
  861. if (Status != STATUS_MORE_PROCESSING_REQUIRED) {
  862. return(Status);
  863. } else {
  864. Status = STATUS_SUCCESS;
  865. }
  866. }
  867. NumEntries = RxContext->QueryDirectory.ReturnSingleEntry?1:2000;
  868. IsUnicode = BooleanFlagOn(pServerEntry->Server.DialectFlags,DF_UNICODE);
  869. IsNonNtT2Find = !(pServerEntry->Server.Dialect==NTLANMAN_DIALECT);
  870. //CODE.IMPROVEMENT.ASHAMED put in the quadaligned optimization
  871. if (TRUE || FlagOn(pServerEntry->Server.DialectFlags,DF_W95)){
  872. DirEntriesAreUaligned = TRUE;
  873. //SearchFlags = SMB_FIND_RETURN_RESUME_KEYS;
  874. //SearchFlags = SMB_FIND_CLOSE_AT_EOS;
  875. NumEntries = (USHORT)(1+ UnalignedDirEntrySideBufferSize
  876. /(IsNonNtT2Find?FIELD_OFFSET(SMB_FIND_BUFFER2_WITH_RESUME, FileName)
  877. :FIELD_OFFSET(FILE_NAMES_INFORMATION, FileName)));
  878. }
  879. if (FlagOn(pServerEntry->Server.DialectFlags,DF_NT_SMBS)
  880. && FlagOn(capFobx->Flags,FOBX_FLAG_BACKUP_INTENT)){
  881. SearchFlags |= SMB_FIND_WITH_BACKUP_INTENT;
  882. //CODE.IMPROVEMENT turn this back on!
  883. //SearchFlags |= SMB_FIND_CLOSE_AT_EOS;
  884. }
  885. if (IsNonNtT2Find) {
  886. SearchFlags &= ~(SMB_FIND_CLOSE_AT_EOS | SMB_FIND_CLOSE_AFTER_REQUEST);
  887. }
  888. RETRY_____:
  889. if (FlagOn(pSession->Flags,SMBCE_SESSION_FLAGS_REMOTE_BOOT_SESSION) &&
  890. FlagOn(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_SEARCH_NOT_THE_FIRST)) {
  891. if (smbFobx->Enumeration.Version != pServerEntry->Server.Version) {
  892. ClearFlag(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_SEARCH_NOT_THE_FIRST);
  893. }
  894. }
  895. if (!FlagOn(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_SEARCH_NOT_THE_FIRST)) {
  896. //this is the first time thru
  897. PUNICODE_STRING DirectoryName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
  898. PUNICODE_STRING Template = &capFobx->UnicodeQueryTemplate;
  899. ULONG DirectoryNameLength,TemplateLength,AllocationLength;
  900. PBYTE SmbFileName;
  901. RxDbgTrace(0, Dbg, ("-->FINFDIRST\n"));
  902. smbFobx->Enumeration.ErrorStatus = RX_MAP_STATUS(SUCCESS);
  903. if (smbFobx->Enumeration.WildCardsFound = FsRtlDoesNameContainWildCards(Template)){
  904. //we need an upcased template for
  905. RtlUpcaseUnicodeString( Template, Template, FALSE );
  906. }
  907. Setup = TRANS2_FIND_FIRST2;
  908. DirectoryNameLength = DirectoryName->Length;
  909. TemplateLength = Template->Length;
  910. AllocationLength = sizeof(REQ_FIND_FIRST2) //NOTE: this buffer is bigger than w95 needs
  911. +2*sizeof(WCHAR)
  912. +DirectoryNameLength
  913. +TemplateLength;
  914. //CODE.IMPROVEMENT this would be a good place to have the xact studcode working......
  915. pFindFirst2Request = (PREQ_FIND_FIRST2)RxAllocatePoolWithTag(
  916. PagedPool,
  917. AllocationLength,
  918. MRXSMB_DIRCTL_POOLTAG);
  919. if (pFindFirst2Request==NULL) {
  920. RxDbgTrace(0, Dbg, (" --> Couldn't get the pFindFirst2Request!\n"));
  921. Status = STATUS_INSUFFICIENT_RESOURCES;
  922. goto FINALLY;
  923. }
  924. SmbFileName = &pFindFirst2Request->Buffer[0];
  925. if (IsUnicode) {
  926. RtlCopyMemory(SmbFileName,DirectoryName->Buffer,DirectoryNameLength);
  927. SmbFileName += DirectoryNameLength;
  928. if (*((PWCHAR)(SmbFileName-sizeof(WCHAR))) != L'\\') {
  929. *((PWCHAR)SmbFileName) = L'\\'; SmbFileName+= sizeof(WCHAR);
  930. }
  931. RtlCopyMemory(SmbFileName,Template->Buffer,TemplateLength);
  932. SmbFileName += TemplateLength;
  933. *((PWCHAR)SmbFileName) = 0; SmbFileName+= sizeof(WCHAR); //trailing NULL;
  934. IF_DEBUG {
  935. DbgDoit(smbtemplate.Buffer = (PWCHAR)&pFindFirst2Request->Buffer[0];);
  936. DbgDoit(smbtemplate.Length = (USHORT)(SmbFileName - (PBYTE)smbtemplate.Buffer););
  937. RxDbgTrace(0, Dbg, (" --> smbtemplate <%wZ>!\n",&smbtemplate));
  938. }
  939. } else {
  940. ULONG BufSize = AllocationLength;
  941. PUNICODE_STRING FinalTemplate = Template;
  942. UNICODE_STRING AllFiles;
  943. SmbPutUnicodeStringAsOemString(&SmbFileName,DirectoryName,&AllocationLength);
  944. // append a backslash if it doesn't exist in the unicode version
  945. // NB !!! Don't compare with OEM string
  946. // it busts DBCS characters with 0x5c at the end
  947. if (!DirectoryName->Length || (DirectoryName->Buffer[(DirectoryName->Length/sizeof(USHORT))-1] != (USHORT)'\\'))
  948. {
  949. *(SmbFileName-1) = '\\';
  950. }
  951. else
  952. {
  953. // there is already a backslash, backup one character
  954. SmbFileName -= 1; AllocationLength += 1;
  955. }
  956. if (IsNonNtT2Find) {
  957. //we'll get them all and filter on out side
  958. //CODE.IMPROVEMENT don't do that...translate the pattern
  959. RtlInitUnicodeString(&AllFiles, L"*.*");
  960. FinalTemplate = &AllFiles;
  961. }
  962. SmbPutUnicodeStringAsOemString(&SmbFileName,FinalTemplate,&AllocationLength);
  963. //already padded *SmbFileName = 0; SmbFileName+= sizeof(CHAR); //trailing NULL;
  964. IF_DEBUG {
  965. DbgDoit(smbtemplate.Buffer = (PWCHAR)&pFindFirst2Request->Buffer[0];);
  966. DbgDoit(smbtemplate.Length = (USHORT)(SmbFileName - (PBYTE)smbtemplate.Buffer););
  967. RxDbgTrace(0, Dbg, (" --> smbtemplate <%s>!\n",&pFindFirst2Request->Buffer[0]));
  968. }
  969. }
  970. // SearchAttributes is hardcoded to the magic number 0x16
  971. pFindFirst2Request->SearchAttributes =
  972. (SMB_FILE_ATTRIBUTE_DIRECTORY
  973. | SMB_FILE_ATTRIBUTE_SYSTEM | SMB_FILE_ATTRIBUTE_HIDDEN);
  974. pFindFirst2Request->SearchCount = NumEntries;
  975. pFindFirst2Request->Flags = SearchFlags;
  976. pFindFirst2Request->InformationLevel = IsNonNtT2Find?SMB_INFO_QUERY_EA_SIZE:SmbFileInfoLevel;
  977. pFindFirst2Request->SearchStorageType = 0;
  978. SendParamsBuffer = (PBYTE)pFindFirst2Request;
  979. SendParamsBufferLength = (ULONG)(SmbFileName - SendParamsBuffer);
  980. ReceiveParamsBuffer = (PBYTE)&FindFirst2Response;
  981. ReceiveParamsBufferLength = sizeof(FindFirst2Response);
  982. } else {
  983. if (smbFobx->Enumeration.ResumeInfo!=NULL) {
  984. PREQ_FIND_NEXT2 pFindNext2Request;
  985. RxDbgTrace(0, Dbg, ("-->FINDNEXT\n"));
  986. if (smbFobx->Enumeration.ErrorStatus != RX_MAP_STATUS(SUCCESS)) {
  987. Status = smbFobx->Enumeration.ErrorStatus;
  988. RxDbgTrace(0, Dbg, ("-->ERROR EARLY OUT\n"));
  989. goto FINALLY;
  990. }
  991. Setup = TRANS2_FIND_NEXT2;
  992. pFindNext2Request = &smbFobx->Enumeration.ResumeInfo->FindNext2_Request;
  993. pFindNext2Request->Sid = smbFobx->Enumeration.SearchHandle;
  994. pFindNext2Request->SearchCount = NumEntries;
  995. pFindNext2Request->InformationLevel = IsNonNtT2Find?SMB_INFO_QUERY_EA_SIZE:SmbFileInfoLevel;
  996. //pFindNext2Request->ResumeKey and pFindNext2Request->Buffer are setup by the previous pass
  997. pFindNext2Request->Flags = SearchFlags;
  998. SendParamsBuffer = (PBYTE)pFindNext2Request;
  999. SendParamsBufferLength = smbFobx->Enumeration.ResumeInfo->ParametersLength;
  1000. ReceiveParamsBuffer = (PBYTE)&XX.FindNext2Response;
  1001. ReceiveParamsBufferLength = sizeof(XX.FindNext2Response);
  1002. if (IsNonNtT2Find) {
  1003. //
  1004. // The LMX server wants this to be 10 instead of 8, for some reason.
  1005. // If you set it to 8, the server gets very confused. Also, warp.
  1006. //
  1007. ReceiveParamsBufferLength = 10; //....sigh
  1008. }
  1009. } else {
  1010. // if the ResumeInfo buffer was not allocated, the end of the search has been reached.
  1011. Status = RX_MAP_STATUS(NO_MORE_FILES);
  1012. smbFobx->Enumeration.EndOfSearchReached = TRUE;
  1013. smbFobx->Enumeration.ErrorStatus = RX_MAP_STATUS(NO_MORE_FILES);
  1014. ClearFlag(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_READ_FROM_CACHE);
  1015. goto FINALLY;
  1016. }
  1017. }
  1018. //NTRAID-455632-2/2/2000-yunlin A smaller buffer should be used
  1019. if ((DirEntriesAreUaligned) &&
  1020. (smbFobx->Enumeration.UnalignedDirEntrySideBuffer == NULL)) {
  1021. MRxSmbAllocateSideBuffer(RxContext,smbFobx,
  1022. Setup, &smbtemplate
  1023. );
  1024. if (smbFobx->Enumeration.UnalignedDirEntrySideBuffer == NULL) {
  1025. RxDbgTrace(0, Dbg, (" --> Couldn't get the win95 sidebuffer!\n"));
  1026. Status = STATUS_INSUFFICIENT_RESOURCES;
  1027. goto FINALLY;
  1028. }
  1029. UnalignedDirEntrySideBuffer = smbFobx->Enumeration.UnalignedDirEntrySideBuffer;
  1030. smbFobx->Enumeration.IsUnicode = IsUnicode;
  1031. smbFobx->Enumeration.IsNonNtT2Find = IsNonNtT2Find;
  1032. }
  1033. {
  1034. PSIDE_BUFFER SideBuffer;
  1035. SideBuffer = (PSIDE_BUFFER)CONTAINING_RECORD(
  1036. smbFobx->Enumeration.UnalignedDirEntrySideBuffer,
  1037. SIDE_BUFFER,
  1038. Buffer);
  1039. ASSERT(SideBuffer->Signature == 'JLBS');
  1040. ASSERT(SideBuffer->Fobx == capFobx);
  1041. ASSERT(SideBuffer->Fcb == capFcb);
  1042. ASSERT(SideBuffer->smbFobx == smbFobx);
  1043. ASSERT(smbFobx->Enumeration.SerialNumber == SideBuffer->SerialNumber);
  1044. }
  1045. Status = SmbCeTransact(
  1046. RxContext,
  1047. pTransactionOptions,
  1048. &Setup,
  1049. sizeof(Setup),
  1050. NULL,
  1051. 0,
  1052. SendParamsBuffer,
  1053. SendParamsBufferLength,
  1054. ReceiveParamsBuffer,
  1055. ReceiveParamsBufferLength,
  1056. NULL,
  1057. 0,
  1058. DirEntriesAreUaligned?UnalignedDirEntrySideBuffer:Buffer, // the buffer for data
  1059. DirEntriesAreUaligned?UnalignedDirEntrySideBufferSize:*pLengthRemaining, // the length of the buffer
  1060. &ResumptionContext);
  1061. if (NT_SUCCESS(Status)) {
  1062. BOOLEAN EndOfSearchReached;
  1063. {
  1064. PSIDE_BUFFER SideBuffer;
  1065. SideBuffer = (PSIDE_BUFFER)CONTAINING_RECORD(
  1066. smbFobx->Enumeration.UnalignedDirEntrySideBuffer,
  1067. SIDE_BUFFER,
  1068. Buffer);
  1069. ASSERT(SideBuffer->Signature == 'JLBS');
  1070. ASSERT(SideBuffer->Fobx == capFobx);
  1071. ASSERT(SideBuffer->Fcb == capFcb);
  1072. ASSERT(SideBuffer->smbFobx == smbFobx);
  1073. ASSERT(smbFobx->Enumeration.SerialNumber == SideBuffer->SerialNumber);
  1074. }
  1075. if (NT_SUCCESS(Status)) {
  1076. // a) need to set the length remaining correctly
  1077. // b) need to setup for a resume and see if the search was closed
  1078. ULONG LastNameOffset=0;
  1079. PMRX_SMB_DIRECTORY_RESUME_INFO ResumeInfo = NULL;
  1080. ULONG OriginalBufferLength = *pLengthRemaining;
  1081. IF_DEBUG { LastNameOffset = 0x40000000; }
  1082. RetryCount = 0;
  1083. smbFobx->Enumeration.Flags |= SMBFOBX_ENUMFLAG_SEARCH_NOT_THE_FIRST;
  1084. smbFobx->Enumeration.TotalDataBytesReturned = ResumptionContext.DataBytesReceived;
  1085. if (Setup == TRANS2_FIND_FIRST2) {
  1086. smbFobx->Enumeration.SearchHandle = FindFirst2Response.Sid;
  1087. smbFobx->Enumeration.Version = ResumptionContext.ServerVersion;
  1088. smbFobx->Enumeration.Flags |= SMBFOBX_ENUMFLAG_SEARCH_HANDLE_OPEN; //but look right below
  1089. //CODE.IMPROVEMENT since the responses look so much alike we could coalesce this code....
  1090. EndOfSearchReached = (BOOLEAN)FindFirst2Response.EndOfSearch;
  1091. FilesReturned = FindFirst2Response.SearchCount;
  1092. LastNameOffset = FindFirst2Response.LastNameOffset;
  1093. } else {
  1094. EndOfSearchReached = (BOOLEAN)XX.FindNext2Response.EndOfSearch;
  1095. FilesReturned = XX.FindNext2Response.SearchCount;
  1096. LastNameOffset = XX.FindNext2Response.LastNameOffset;
  1097. }
  1098. //
  1099. // Please note: LANMAN 2.x servers prematurely set the
  1100. // EndOfSearch flag, so we must ignore it on LM 2.x servers.
  1101. //
  1102. // NT Returns the correct information, none of the LM varients
  1103. // appear to do so.
  1104. //
  1105. if (IsNonNtT2Find) {
  1106. EndOfSearchReached = FALSE;
  1107. }
  1108. if (Status==RX_MAP_STATUS(SUCCESS) && FilesReturned==0) {
  1109. RxDbgTrace( 0, Dbg, ("MRxSmbQueryDirectory: no files returned...switch status\n"));
  1110. EndOfSearchReached = TRUE;
  1111. Status = RX_MAP_STATUS(NO_MORE_FILES);
  1112. }
  1113. if (!DirEntriesAreUaligned) {
  1114. *pLengthRemaining -= ResumptionContext.DataBytesReceived;
  1115. if (EndOfSearchReached) {
  1116. smbFobx->Enumeration.ErrorStatus = RX_MAP_STATUS(NO_MORE_FILES);
  1117. }
  1118. }
  1119. if (EndOfSearchReached ||
  1120. SearchFlags & SMB_FIND_CLOSE_AFTER_REQUEST) {
  1121. ClearFlag(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_SEARCH_HANDLE_OPEN);
  1122. }
  1123. if (FlagOn(smbFobx->Enumeration.Flags,SMBFOBX_ENUMFLAG_SEARCH_HANDLE_OPEN)) {
  1124. //if the search handle is open, then we set up to resume
  1125. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectory: rinfo = %08lx\n", smbFobx->Enumeration.ResumeInfo));
  1126. if (smbFobx->Enumeration.ResumeInfo==NULL) {
  1127. smbFobx->Enumeration.ResumeInfo =
  1128. (PMRX_SMB_DIRECTORY_RESUME_INFO)RxAllocatePoolWithTag(
  1129. PagedPool,
  1130. sizeof(MRX_SMB_DIRECTORY_RESUME_INFO),
  1131. MRXSMB_DIRCTL_POOLTAG);
  1132. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectory: allocatedinfo = %08lx\n", ResumeInfo));
  1133. if (smbFobx->Enumeration.ResumeInfo == NULL) {
  1134. Status = STATUS_INSUFFICIENT_RESOURCES;
  1135. goto FINALLY;
  1136. }
  1137. }
  1138. ResumeInfo = smbFobx->Enumeration.ResumeInfo;
  1139. ASSERT (ResumeInfo!=NULL);
  1140. {
  1141. PSIDE_BUFFER SideBuffer;
  1142. SideBuffer = (PSIDE_BUFFER)CONTAINING_RECORD(
  1143. smbFobx->Enumeration.UnalignedDirEntrySideBuffer,
  1144. SIDE_BUFFER,
  1145. Buffer);
  1146. ASSERT(SideBuffer->Signature == 'JLBS');
  1147. ASSERT(SideBuffer->Fobx == capFobx);
  1148. ASSERT(SideBuffer->Fcb == capFcb);
  1149. ASSERT(SideBuffer->smbFobx == smbFobx);
  1150. ASSERT(smbFobx->Enumeration.SerialNumber == SideBuffer->SerialNumber);
  1151. }
  1152. RxLog(("MRxqdir: rinfo = %lx", smbFobx->Enumeration.ResumeInfo));
  1153. RxLog(("MRxqdir2: olen = %lx, thisl = %lx",
  1154. OriginalBufferLength, ResumptionContext.DataBytesReceived));
  1155. SmbLog(LOG,
  1156. MRxSmbQueryDirectory,
  1157. LOGPTR(smbFobx->Enumeration.ResumeInfo)
  1158. LOGULONG(OriginalBufferLength)
  1159. LOGULONG(ResumptionContext.DataBytesReceived));
  1160. if (!DirEntriesAreUaligned) {
  1161. PBYTE LastEntry = ((PBYTE)Buffer)+LastNameOffset;
  1162. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectory: lastentry = %08lx\n", LastEntry));
  1163. //this is for NT....the data is already in the buffer.......just setup the resume info
  1164. if (SmbFileInfoLevel>=SMB_FIND_FILE_DIRECTORY_INFO) { //we may start sending nonNT levels...could be an assert
  1165. PREQ_FIND_NEXT2 pFindNext2Request = &ResumeInfo->FindNext2_Request;
  1166. ULONG resumekey = ((PFILE_FULL_DIR_INFORMATION)LastEntry)->FileIndex;
  1167. ULONG FileNameLength; PWCHAR FileNameBuffer;
  1168. pFindNext2Request->ResumeKey = resumekey;
  1169. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectory: resumekey = %08lx\n", resumekey));
  1170. FileNameLength = *((PULONG)(LastEntry+smbFobx->Enumeration.FileNameLengthOffset));
  1171. FileNameBuffer = (PWCHAR)(LastEntry+smbFobx->Enumeration.FileNameOffset);
  1172. IF_DEBUG {
  1173. UNICODE_STRING LastName;
  1174. LastName.Buffer = FileNameBuffer;
  1175. LastName.Length = (USHORT)FileNameLength;
  1176. RxDbgTrace(0,Dbg,("MRxSmbQueryDirectory: resumename = %wZ\n", &LastName));
  1177. }
  1178. ASSERT ( (((PBYTE)FileNameBuffer)+FileNameLength)
  1179. <=(((PBYTE)Buffer)+OriginalBufferLength) );
  1180. RtlCopyMemory(&pFindNext2Request->Buffer[0],FileNameBuffer,FileNameLength);
  1181. //buffer is a UCHAR...not WCHAR
  1182. pFindNext2Request->Buffer[FileNameLength] = 0; //nullterminated in unicode
  1183. pFindNext2Request->Buffer[FileNameLength+1] = 0; //nullterminated in unicode
  1184. smbFobx->Enumeration.ResumeInfo->ParametersLength
  1185. = (USHORT)(&pFindNext2Request->Buffer[FileNameLength+2] - (PBYTE)pFindNext2Request);
  1186. } else {
  1187. ASSERT(!"don't know how to get resume key/name for nonNT");
  1188. }
  1189. }
  1190. }
  1191. {
  1192. PSIDE_BUFFER SideBuffer;
  1193. SideBuffer = (PSIDE_BUFFER)CONTAINING_RECORD(
  1194. smbFobx->Enumeration.UnalignedDirEntrySideBuffer,
  1195. SIDE_BUFFER,
  1196. Buffer);
  1197. ASSERT(SideBuffer->Signature == 'JLBS');
  1198. ASSERT(SideBuffer->Fobx == capFobx);
  1199. ASSERT(SideBuffer->Fcb == capFcb);
  1200. ASSERT(SideBuffer->smbFobx == smbFobx);
  1201. ASSERT(smbFobx->Enumeration.SerialNumber == SideBuffer->SerialNumber);
  1202. }
  1203. //for NT we are finished. for win95 we have to go thru the side buffer and
  1204. // 1) copy in the data transforming ascii->unicode on the names, and
  1205. // 2) remember the resume key and the filename of the last guy that we process
  1206. // because win95 doesn't 8byte aling things and because of unicode, we could end up
  1207. // with more data in the sidebuffer than we can return. this is very unfortunate.
  1208. // what would be cool CODE.IMPROVEMENT, would be to implement buffering in the wrapper
  1209. // the code is moved down because we want to do it after the unlock
  1210. }
  1211. if (DirEntriesAreUaligned && (Status == STATUS_SUCCESS)) {
  1212. smbFobx->Enumeration.FilesReturned = FilesReturned;
  1213. smbFobx->Enumeration.EntryOffset = 0;
  1214. smbFobx->Enumeration.EndOfSearchReached = EndOfSearchReached;
  1215. Status = MrxSmbUnalignedDirEntryCopyTail(RxContext,
  1216. FileInformationClass,
  1217. Buffer,
  1218. pLengthRemaining,
  1219. smbFobx);
  1220. }
  1221. } else {
  1222. // CODE IMPROVEMENT we should cache the file not found for findfirst as well
  1223. }
  1224. FINALLY:
  1225. //for downlevel-T2, we will have to go back to the server for some more.....sigh.......
  1226. if (Status==STATUS_MORE_PROCESSING_REQUIRED) {
  1227. goto RETRY_____;
  1228. }
  1229. //
  1230. // under stress, the win95 server returns this......
  1231. if ( (Status == STATUS_UNEXPECTED_NETWORK_ERROR)
  1232. && FlagOn(pServerEntry->Server.DialectFlags,DF_W95)
  1233. && (RetryCount < 10) ) {
  1234. RetryCount++;
  1235. MRxSmbWin95Retries++;
  1236. goto RETRY_____;
  1237. }
  1238. if (pFindFirst2Request) RxFreePool(pFindFirst2Request);
  1239. if (!NT_SUCCESS(Status)) {
  1240. RxDbgTrace( 0, Dbg, ("MRxSmbQueryDirectory: Failed .. returning %lx\n",Status));
  1241. //smbFobx->Enumeration.Flags &= ~SMBFOBX_ENUMFLAG_SEARCH_HANDLE_OPEN;
  1242. smbFobx->Enumeration.ErrorStatus = Status; //keep returning this
  1243. MRxSmbDeallocateSideBuffer(RxContext,smbFobx,"ErrOut");
  1244. if (smbFobx->Enumeration.ResumeInfo!=NULL) {
  1245. RxFreePool(smbFobx->Enumeration.ResumeInfo);
  1246. smbFobx->Enumeration.ResumeInfo = NULL;
  1247. }
  1248. }
  1249. RxDbgTraceUnIndent(-1,Dbg);
  1250. return Status;
  1251. }
  1252. RXDT_DefineCategory(VOLINFO);
  1253. #undef Dbg
  1254. #define Dbg (DEBUG_TRACE_VOLINFO)
  1255. NTSTATUS
  1256. MRxSmbQueryVolumeInformationWithFullBuffer(
  1257. IN OUT PRX_CONTEXT RxContext
  1258. );
  1259. NTSTATUS
  1260. MRxSmbQueryVolumeInformation(
  1261. IN OUT PRX_CONTEXT RxContext
  1262. )
  1263. /*++
  1264. Routine Description:
  1265. This routine queries the volume information. Since the NT server does not
  1266. handle bufferoverflow gracefully on query-fs-info, we allocate a buffer here
  1267. that is big enough to hold anything passed back; then we call the "real"
  1268. queryvolinfo routine.
  1269. Arguments:
  1270. pRxContext - the RDBSS context
  1271. Return Value:
  1272. RXSTATUS - The return status for the operation
  1273. --*/
  1274. {
  1275. NTSTATUS Status;
  1276. RxCaptureFcb; RxCaptureFobx;
  1277. PVOID OriginalBuffer;
  1278. ULONG OriginalLength = RxContext->Info.LengthRemaining;
  1279. ULONG ReturnedLength;
  1280. BOOLEAN UsingSideBuffer = FALSE;
  1281. struct {
  1282. union {
  1283. FILE_FS_LABEL_INFORMATION labelinfo;
  1284. FILE_FS_VOLUME_INFORMATION volumeinfo;
  1285. FILE_FS_SIZE_INFORMATION sizeinfo;
  1286. FILE_FS_DEVICE_INFORMATION deviceinfo;
  1287. FILE_FS_ATTRIBUTE_INFORMATION attributeinfo;
  1288. FILE_FS_CONTROL_INFORMATION controlinfo;
  1289. } Info;
  1290. WCHAR VolumeName[MAXIMUM_FILENAME_LENGTH];
  1291. } SideBuffer;
  1292. PAGED_CODE();
  1293. if( RxContext->Info.LengthRemaining < sizeof( SideBuffer ) ) {
  1294. //
  1295. // i replace the buffer and length in the context with my stuff.
  1296. // This, of course, means that we can't go async....for that we'd
  1297. // have to allocate in stead of using a stack-allocated buffer.
  1298. // In that case we would have to store the buffer somewhere in the
  1299. // context for use with [CODE.IMPROVEMENT] downlevel guys. what would make
  1300. // this work would be if CreateOE saved the exchange and stufferstate
  1301. // values in the context before it overwrote them with its own.
  1302. //
  1303. // it's not immediately obvious that we should be allocating such a large
  1304. // structure on the stack. CODE.IMPROVEMENT..........
  1305. UsingSideBuffer = TRUE;
  1306. OriginalBuffer = RxContext->Info.Buffer;
  1307. RxContext->Info.Buffer = &SideBuffer;
  1308. RxContext->Info.LengthRemaining = sizeof(SideBuffer);
  1309. }
  1310. Status = MRxSmbQueryVolumeInformationWithFullBuffer(RxContext);
  1311. if (Status != STATUS_SUCCESS) {
  1312. goto FINALLY;
  1313. }
  1314. if( UsingSideBuffer == TRUE ) {
  1315. ReturnedLength = sizeof(SideBuffer) - RxContext->Info.LengthRemaining;
  1316. } else {
  1317. ReturnedLength = OriginalLength - RxContext->Info.LengthRemaining;
  1318. }
  1319. if (ReturnedLength > OriginalLength) {
  1320. Status = STATUS_BUFFER_OVERFLOW;
  1321. ReturnedLength = OriginalLength;
  1322. }
  1323. if( UsingSideBuffer == TRUE ) {
  1324. RtlCopyMemory(OriginalBuffer,&SideBuffer,ReturnedLength);
  1325. }
  1326. RxContext->Info.LengthRemaining = OriginalLength - ReturnedLength;
  1327. FINALLY:
  1328. return Status;
  1329. }
  1330. NTSTATUS
  1331. MRxSmbQueryVolumeInformationWithFullBuffer(
  1332. IN OUT PRX_CONTEXT RxContext
  1333. )
  1334. /*++
  1335. Routine Description:
  1336. This routine queries the volume information
  1337. Arguments:
  1338. pRxContext - the RDBSS context
  1339. FsInformationClass - the kind of Fs information desired.
  1340. pBuffer - the buffer for copying the information
  1341. pBufferLength - the buffer length ( set to buffer length on input and set
  1342. to the remaining length on output)
  1343. Return Value:
  1344. RXSTATUS - The return status for the operation
  1345. --*/
  1346. {
  1347. NTSTATUS Status;
  1348. RxCaptureFcb;
  1349. PMRX_SMB_FCB smbFcb = MRxSmbGetFcbExtension(capFcb);
  1350. RxCaptureFobx;
  1351. PMRX_SRV_OPEN SrvOpen;
  1352. PMRX_SMB_SRV_OPEN smbSrvOpen;
  1353. FS_INFORMATION_CLASS FsInformationClass = RxContext->Info.FsInformationClass;
  1354. PVOID pBuffer = RxContext->Info.Buffer;
  1355. PLONG pLengthRemaining = &RxContext->Info.LengthRemaining;
  1356. LONG OriginalLength = *pLengthRemaining;
  1357. PSMBCEDB_SERVER_ENTRY pServerEntry;
  1358. PSMBCE_V_NET_ROOT_CONTEXT pVNetRootContext;
  1359. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry;
  1360. LARGE_INTEGER CurrentTime;
  1361. BOOLEAN DoAsDownLevel;
  1362. PVOID pInputParamBuffer;
  1363. ULONG InputParamBufferLength;
  1364. USHORT InformationLevel;
  1365. USHORT Setup;
  1366. REQ_QUERY_FS_INFORMATION QueryFsInformationRequest;
  1367. REQ_QUERY_FS_INFORMATION_FID DfsQueryFsInformationRequest;
  1368. PAGED_CODE();
  1369. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  1370. if ( FsInformationClass == FileFsDeviceInformation ) {
  1371. PFILE_FS_DEVICE_INFORMATION UsersBuffer = (PFILE_FS_DEVICE_INFORMATION)pBuffer;
  1372. PMRX_NET_ROOT NetRoot = capFcb->pNetRoot;
  1373. UsersBuffer->Characteristics = FILE_REMOTE_DEVICE;
  1374. if (NetRoot->Type==NET_ROOT_PIPE) {
  1375. NetRoot->DeviceType = RxDeviceType(NAMED_PIPE);
  1376. }
  1377. UsersBuffer->DeviceType = NetRoot->DeviceType;
  1378. *pLengthRemaining -= (sizeof(FILE_FS_DEVICE_INFORMATION));
  1379. RxDbgTrace( 0, Dbg, ("MRxSmbQueryVolumeInformation: devinfo .. returning\n"));
  1380. return RX_MAP_STATUS(SUCCESS);
  1381. }
  1382. if (capFobx != NULL) {
  1383. SrvOpen = capFobx->pSrvOpen;
  1384. smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  1385. pVNetRootContext = SmbCeGetAssociatedVNetRootContext(SrvOpen->pVNetRoot);
  1386. pNetRootEntry = pVNetRootContext->pNetRootEntry;
  1387. } else {
  1388. return RX_MAP_STATUS(INVALID_PARAMETER);
  1389. }
  1390. TURN_BACK_ASYNCHRONOUS_OPERATIONS();
  1391. IF_NOT_MRXSMB_BUILD_FOR_DISCONNECTED_CSC{
  1392. NOTHING;
  1393. } else {
  1394. if (CscPerformOperationInDisconnectedMode(RxContext)){
  1395. NTSTATUS VolInfoNtStatus;
  1396. VolInfoNtStatus = MRxSmbDCscQueryVolumeInformation(RxContext);
  1397. if (VolInfoNtStatus != STATUS_MORE_PROCESSING_REQUIRED) {
  1398. RxDbgTrace(-1, Dbg,
  1399. ("MRxSmbQueryVolumeInfo returningDCON with status=%08lx\n",
  1400. VolInfoNtStatus ));
  1401. return(VolInfoNtStatus);
  1402. } else {
  1403. NOTHING;
  1404. //RxDbgTrace(0, Dbg,
  1405. // ("MRxSmbQueryVolumeInfo continueingDCON with status=%08lx\n",
  1406. // VolInfoNtStatus ));
  1407. }
  1408. }
  1409. }
  1410. if (FsInformationClass == FileFsVolumeInformation) {
  1411. KeQueryTickCount(&CurrentTime);
  1412. if (CurrentTime.QuadPart < pNetRootEntry->VolumeInfoExpiryTime.QuadPart) {
  1413. // use the cached volume information if it is not expired
  1414. RtlCopyMemory(pBuffer,
  1415. pNetRootEntry->VolumeInfo,
  1416. pNetRootEntry->VolumeInfoLength);
  1417. *pLengthRemaining -= pNetRootEntry->VolumeInfoLength;
  1418. return STATUS_SUCCESS;
  1419. }
  1420. }
  1421. for (;;) {
  1422. if (capFobx != NULL) {
  1423. PMRX_V_NET_ROOT pVNetRoot;
  1424. // Avoid device opens for which the FOBX is the VNET_ROOT instance
  1425. pVNetRoot = (PMRX_V_NET_ROOT)capFobx;
  1426. if (NodeType(pVNetRoot) != RDBSS_NTC_V_NETROOT) {
  1427. PUNICODE_STRING AlreadyPrefixedName =
  1428. GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
  1429. ULONG FcbAlreadyPrefixedNameLength = AlreadyPrefixedName->Length;
  1430. ULONG NetRootInnerNamePrefixLength = capFcb->pNetRoot->InnerNamePrefix.Length;
  1431. PWCHAR pName = AlreadyPrefixedName->Buffer;
  1432. // If an FSCTL is being attempted against the root of a share.
  1433. // The AlreadyPrefixedName associated with the FCB is the same as
  1434. // the AlreadyPrefixedName length associated with the NET_ROOT instance
  1435. // or atmost one character greater than it ( appending a \) try and
  1436. // reestablish the connection before attempting the FSCTL.
  1437. // This solves thorny issues regarding deletion/creation of shares
  1438. // on the server sides, DFS referrals etc.
  1439. if ((FcbAlreadyPrefixedNameLength == NetRootInnerNamePrefixLength) ||
  1440. ((FcbAlreadyPrefixedNameLength == NetRootInnerNamePrefixLength + sizeof(WCHAR)) &&
  1441. (*((PCHAR)pName + FcbAlreadyPrefixedNameLength - sizeof(WCHAR)) ==
  1442. L'\\'))) {
  1443. Status = SmbCeReconnect(capFobx->pSrvOpen->pVNetRoot);
  1444. }
  1445. }
  1446. }
  1447. DoAsDownLevel = MRxSmbForceCoreInfo;
  1448. if (!FlagOn(pServerEntry->Server.DialectFlags,DF_NT_SMBS)) {
  1449. DoAsDownLevel = TRUE;
  1450. }
  1451. if (FlagOn(pServerEntry->Server.DialectFlags,DF_W95)
  1452. && (FsInformationClass==FileFsAttributeInformation)){ //use uplevel for w95 attribute info
  1453. DoAsDownLevel = FALSE;
  1454. }
  1455. if (DoAsDownLevel) {
  1456. Status = MRxSmbCoreInformation(RxContext,
  1457. (ULONG)FsInformationClass,
  1458. pBuffer,
  1459. pLengthRemaining, //CODE.IMPROVEMENT dont pass args 2-4
  1460. SMBPSE_OE_FROM_QUERYVOLUMEINFO
  1461. );
  1462. goto FINALLY;
  1463. }
  1464. Status = STATUS_MORE_PROCESSING_REQUIRED;
  1465. switch (FsInformationClass) {
  1466. case FileFsVolumeInformation :
  1467. InformationLevel = SMB_QUERY_FS_VOLUME_INFO;
  1468. break;
  1469. case FileFsLabelInformation :
  1470. InformationLevel = SMB_QUERY_FS_LABEL_INFO;
  1471. break;
  1472. case FileFsSizeInformation :
  1473. InformationLevel = SMB_QUERY_FS_SIZE_INFO;
  1474. break;
  1475. case FileFsAttributeInformation :
  1476. InformationLevel = SMB_QUERY_FS_ATTRIBUTE_INFO;
  1477. break;
  1478. default:
  1479. if( FlagOn( pServerEntry->Server.DialectFlags, DF_NT_INFO_PASSTHROUGH ) ) {
  1480. InformationLevel = FsInformationClass + SMB_INFO_PASSTHROUGH;
  1481. } else {
  1482. RxDbgTrace( 0, Dbg, ("MRxSmbQueryVolumeInformation: Invalid FS information class\n"));
  1483. Status = STATUS_INVALID_PARAMETER;
  1484. }
  1485. break;
  1486. }
  1487. if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
  1488. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  1489. PSMB_TRANSACTION_OPTIONS pTransactionOptions = &RxDefaultTransactionOptions;
  1490. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  1491. PMRX_SMB_SRV_OPEN smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  1492. if (!FlagOn(pServerEntry->Server.DialectFlags,DF_DFS_TRANS2)) {
  1493. Setup = TRANS2_QUERY_FS_INFORMATION;
  1494. QueryFsInformationRequest.InformationLevel = InformationLevel;
  1495. pInputParamBuffer = &QueryFsInformationRequest;
  1496. InputParamBufferLength = sizeof(QueryFsInformationRequest);
  1497. } else {
  1498. Setup = TRANS2_QUERY_FS_INFORMATION_FID;
  1499. DfsQueryFsInformationRequest.InformationLevel = InformationLevel;
  1500. DfsQueryFsInformationRequest.Fid = smbSrvOpen->Fid;
  1501. pInputParamBuffer = &DfsQueryFsInformationRequest;
  1502. InputParamBufferLength = sizeof(DfsQueryFsInformationRequest);
  1503. }
  1504. Status = SmbCeTransact(
  1505. RxContext,
  1506. pTransactionOptions,
  1507. &Setup,
  1508. sizeof(Setup),
  1509. NULL,
  1510. 0,
  1511. pInputParamBuffer,
  1512. InputParamBufferLength,
  1513. NULL,
  1514. 0,
  1515. NULL,
  1516. 0,
  1517. pBuffer,
  1518. *pLengthRemaining,
  1519. &ResumptionContext);
  1520. if (NT_SUCCESS(Status)) {
  1521. *pLengthRemaining -= ResumptionContext.DataBytesReceived;
  1522. //CODE.IMPROVEMENT if this is a size query, we should store the clustersize in the netroot
  1523. // this would save us one packet later.
  1524. }
  1525. }
  1526. if (!NT_SUCCESS(Status)) {
  1527. RxDbgTrace( 0, Dbg, ("MRxSmbQueryVolumeInformation: Failed .. returning %lx\n",Status));
  1528. }
  1529. if (Status != STATUS_NETWORK_NAME_DELETED) {
  1530. break;
  1531. }
  1532. }
  1533. FINALLY:
  1534. if ((Status == STATUS_SUCCESS) &&
  1535. (FsInformationClass == FileFsVolumeInformation)) {
  1536. LARGE_INTEGER ExpiryTimeInTicks;
  1537. LONG VolumeInfoLength = OriginalLength - *pLengthRemaining;
  1538. if (VolumeInfoLength > pNetRootEntry->VolumeInfoLength) {
  1539. // If the Volume Label gets longer, allocate a new buffer
  1540. if (pNetRootEntry->VolumeInfo != NULL) {
  1541. RxFreePool(pNetRootEntry->VolumeInfo);
  1542. }
  1543. pNetRootEntry->VolumeInfo = RxAllocatePoolWithTag(PagedPool,
  1544. VolumeInfoLength,
  1545. MRXSMB_QPINFO_POOLTAG);
  1546. }
  1547. if (pNetRootEntry->VolumeInfo != NULL) {
  1548. KeQueryTickCount(&CurrentTime);
  1549. ExpiryTimeInTicks.QuadPart = (1000 * 1000 * 10) / KeQueryTimeIncrement();
  1550. ExpiryTimeInTicks.QuadPart = ExpiryTimeInTicks.QuadPart * NAME_CACHE_OBJ_GET_FILE_ATTRIB_LIFETIME;
  1551. pNetRootEntry->VolumeInfoExpiryTime.QuadPart = CurrentTime.QuadPart + ExpiryTimeInTicks.QuadPart;
  1552. RtlCopyMemory(pNetRootEntry->VolumeInfo,
  1553. pBuffer,
  1554. VolumeInfoLength);
  1555. pNetRootEntry->VolumeInfoLength = VolumeInfoLength;
  1556. } else {
  1557. pNetRootEntry->VolumeInfoLength = 0;
  1558. }
  1559. }
  1560. return Status;
  1561. }
  1562. NTSTATUS
  1563. MRxSmbSetVolumeInformation(
  1564. IN OUT PRX_CONTEXT RxContext
  1565. )
  1566. /*++
  1567. Routine Description:
  1568. This routine sets the volume information
  1569. Arguments:
  1570. pRxContext - the RDBSS context
  1571. FsInformationClass - the kind of Fs information desired.
  1572. pBuffer - the buffer for copying the information
  1573. BufferLength - the buffer length
  1574. Return Value:
  1575. RXSTATUS - The return status for the operation
  1576. --*/
  1577. {
  1578. NTSTATUS Status;
  1579. RxCaptureFcb;
  1580. RxCaptureFobx;
  1581. FILE_INFORMATION_CLASS FileInformationClass;
  1582. PVOID pBuffer;
  1583. ULONG BufferLength;
  1584. PSMBCEDB_SERVER_ENTRY pServerEntry;
  1585. BOOLEAN ServerSupportsPassThroughForSetInfo = FALSE;
  1586. PAGED_CODE();
  1587. TURN_BACK_ASYNCHRONOUS_OPERATIONS();
  1588. IF_NOT_MRXSMB_BUILD_FOR_DISCONNECTED_CSC{
  1589. NOTHING;
  1590. } else {
  1591. if (CscPerformOperationInDisconnectedMode(RxContext)){
  1592. return STATUS_NOT_SUPPORTED;
  1593. }
  1594. }
  1595. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  1596. FileInformationClass = RxContext->Info.FileInformationClass;
  1597. pBuffer = RxContext->Info.Buffer;
  1598. BufferLength = RxContext->Info.Length;
  1599. if (!MRxSmbForceCoreInfo &&
  1600. FlagOn( pServerEntry->Server.DialectFlags, DF_NT_INFO_PASSTHROUGH)) {
  1601. ServerSupportsPassThroughForSetInfo = TRUE;
  1602. }
  1603. if (ServerSupportsPassThroughForSetInfo) {
  1604. USHORT Setup = TRANS2_SET_FS_INFORMATION;
  1605. REQ_SET_FS_INFORMATION SetFsInfoRequest;
  1606. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  1607. PSMB_TRANSACTION_OPTIONS pTransactionOptions = &RxDefaultTransactionOptions;
  1608. if (capFobx != NULL) {
  1609. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  1610. PMRX_SMB_SRV_OPEN smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  1611. SetFsInfoRequest.Fid = smbSrvOpen->Fid;
  1612. SetFsInfoRequest.InformationLevel = FileInformationClass +
  1613. SMB_INFO_PASSTHROUGH;
  1614. Status = SmbCeTransact(
  1615. RxContext,
  1616. pTransactionOptions,
  1617. &Setup,
  1618. sizeof(Setup),
  1619. NULL,
  1620. 0,
  1621. &SetFsInfoRequest,
  1622. sizeof(SetFsInfoRequest),
  1623. NULL,
  1624. 0,
  1625. pBuffer,
  1626. BufferLength,
  1627. NULL,
  1628. 0,
  1629. &ResumptionContext);
  1630. } else {
  1631. Status = STATUS_INVALID_PARAMETER;
  1632. }
  1633. } else {
  1634. Status = STATUS_NOT_SUPPORTED;
  1635. }
  1636. if (!NT_SUCCESS(Status)) {
  1637. RxDbgTrace( 0, Dbg, ("MRxSmbSetFile: Failed .. returning %lx\n",Status));
  1638. }
  1639. RxDbgTraceUnIndent(-1,Dbg);
  1640. return Status;
  1641. }
  1642. RXDT_DefineCategory(FILEINFO);
  1643. #undef Dbg
  1644. #define Dbg (DEBUG_TRACE_FILEINFO)
  1645. LONG GFAFromLocal;
  1646. NTSTATUS
  1647. MRxSmbQueryFileInformation(
  1648. IN PRX_CONTEXT RxContext )
  1649. /*++
  1650. Routine Description:
  1651. This routine does a query file info.
  1652. Arguments:
  1653. RxContext - the RDBSS context
  1654. Return Value:
  1655. NTSTATUS - The return status for the operation
  1656. --*/
  1657. {
  1658. NTSTATUS Status;
  1659. RxCaptureFcb;
  1660. RxCaptureFobx;
  1661. FILE_INFORMATION_CLASS FileInformationClass;
  1662. PVOID pBuffer;
  1663. PULONG pLengthRemaining;
  1664. PSMBCEDB_SERVER_ENTRY pServerEntry;
  1665. PMRX_SMB_FCB smbFcb = MRxSmbGetFcbExtension(capFcb);
  1666. PMRX_SMB_FOBX smbFobx = MRxSmbGetFileObjectExtension(capFobx);
  1667. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  1668. PMRX_SMB_SRV_OPEN smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  1669. PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME_FROM_CONTEXT(RxContext);
  1670. PMRX_NET_ROOT NetRoot = capFcb->pNetRoot;
  1671. PSMBCE_V_NET_ROOT_CONTEXT pVNetRootContext = (PSMBCE_V_NET_ROOT_CONTEXT)SrvOpen->pVNetRoot->Context;
  1672. PSMBCE_NET_ROOT pSmbNetRoot = &pVNetRootContext->pNetRootEntry->NetRoot;
  1673. USHORT SmbFileInfoLevel;
  1674. USHORT Setup;
  1675. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  1676. PSMB_TRANSACTION_OPTIONS pTransactionOptions = &RxDefaultTransactionOptions;
  1677. REQ_QUERY_FILE_INFORMATION QueryFileInfoRequest;
  1678. RESP_QUERY_FILE_INFORMATION QueryFileInfoResponse;
  1679. PREQ_QUERY_PATH_INFORMATION pQueryFilePathRequest = NULL;
  1680. PVOID pSendParameterBuffer;
  1681. ULONG SendParameterBufferLength;
  1682. PAGED_CODE();
  1683. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  1684. FileInformationClass = RxContext->Info.FileInformationClass;
  1685. pBuffer = RxContext->Info.Buffer;
  1686. pLengthRemaining = &RxContext->Info.LengthRemaining;
  1687. RxDbgTrace(+1, Dbg, ("MRxSmbQueryFileInformation: class=%08lx\n",FileInformationClass));
  1688. //CODE.IMPROVEMENT.ASHAMED it is a real SHAME is that we don't do a SMB_QUERY_FILE_ALL_INFO
  1689. // in response to a FileAllInformation request. what we should do is to call down with all_info;
  1690. // if the mini returns SNI then we do the individual pieces. the problem with all_info is that
  1691. // it contains the name and that might cause it to overflow my buffer! however, a name can only be 32k
  1692. // so i could waltz around that with a big buffer.
  1693. TURN_BACK_ASYNCHRONOUS_OPERATIONS();
  1694. /*
  1695. // begin init code to replace switch with table lookup
  1696. #define SMB_QUERY_FILE_INFO_INVALID_REQ 0xFFF
  1697. #define SMB_QUERY_FILE_INFO_PIPE_REQ 0xFFE
  1698. USHORT NtToSmbQueryFileInfo[FileMaximumInformation];
  1699. for (i=0; i < FileMaximumInformation; i++) {
  1700. NtToSmbQueryFileInfo[i] = SMB_QUERY_FILE_INFO_INVALID_REQ;
  1701. }
  1702. NtToSmbQueryFileInfo[FileBasicInformation] = SMB_QUERY_FILE_BASIC_INFO;
  1703. NtToSmbQueryFileInfo[FileStandardInformation] = SMB_QUERY_FILE_STANDARD_INFO;
  1704. NtToSmbQueryFileInfo[FileEaInformation] = SMB_QUERY_FILE_EA_INFO;
  1705. NtToSmbQueryFileInfo[FileAllocationInformation] = SMB_QUERY_FILE_ALLOCATION_INFO;
  1706. NtToSmbQueryFileInfo[FileEndOfFileInformation] = SMB_QUERY_FILE_END_OF_FILEINFO;
  1707. NtToSmbQueryFileInfo[FileAlternateNameInformation] = SMB_QUERY_FILE_ALT_NAME_INFO;
  1708. NtToSmbQueryFileInfo[FileStreamInformation] = SMB_QUERY_FILE_STREAM_INFO;
  1709. NtToSmbQueryFileInfo[FilePipeInformation] = SMB_QUERY_FILE_INFO_PIPE_REQ;
  1710. NtToSmbQueryFileInfo[FilePipeLocalInformation] = SMB_QUERY_FILE_INFO_PIPE_REQ;
  1711. NtToSmbQueryFileInfo[FilePipeRemoteInformation] = SMB_QUERY_FILE_INFO_PIPE_REQ;
  1712. NtToSmbQueryFileInfo[FileCompressionInformation] = SMB_QUERY_FILE_COMPRESSION_INFO;
  1713. // end init
  1714. if (FileInformationClass < FileMaximumInformation) {
  1715. SmbFileInfoLevel = NtToSmbQueryFileInfo[FileInformationClass];
  1716. } else {
  1717. SmbFileInfoLevel = SMB_QUERY_FILE_INFO_INVALID_REQ;
  1718. }
  1719. if (SmbFileInfoLevel == SMB_QUERY_FILE_INFO_PIPE_REQ) {
  1720. //CODE.IMPROVEMENT the last thress params should not be passed...........
  1721. return MRxSmbQueryNamedPipeInformation(RxContext,FileInformationClass,pBuffer,pLengthRemaining);
  1722. } else if (SmbFileInfoLevel == SMB_QUERY_FILE_INFO_INVALID_REQ) {
  1723. RxDbgTrace( 0, Dbg, ("MRxSmbQueryFile: Invalid FS information class\n"));
  1724. Status = STATUS_INVALID_PARAMETER;
  1725. goto FINALLY;
  1726. }
  1727. */
  1728. if( FileInformationClass == FilePipeLocalInformation ||
  1729. FileInformationClass == FilePipeInformation ||
  1730. FileInformationClass == FilePipeRemoteInformation ) {
  1731. return MRxSmbQueryNamedPipeInformation(
  1732. RxContext,
  1733. FileInformationClass,
  1734. pBuffer,
  1735. pLengthRemaining);
  1736. }
  1737. Status = STATUS_SUCCESS;
  1738. switch (FileInformationClass) {
  1739. case FileEaInformation:
  1740. if (smbSrvOpen->IsNtCreate &&
  1741. smbSrvOpen->FileStatusFlags & SMB_FSF_NO_EAS &&
  1742. (smbSrvOpen->OplockLevel == SMB_OPLOCK_LEVEL_BATCH ||
  1743. smbSrvOpen->OplockLevel == SMB_OPLOCK_LEVEL_EXCLUSIVE)) {
  1744. PFILE_EA_INFORMATION EaBuffer = (PFILE_EA_INFORMATION)pBuffer;
  1745. EaBuffer->EaSize = 0;
  1746. RxContext->Info.LengthRemaining -= sizeof(FILE_EA_INFORMATION);
  1747. goto FINALLY;
  1748. }
  1749. break;
  1750. case FileStreamInformation:
  1751. if (pSmbNetRoot->NetRootFileSystem == NET_ROOT_FILESYSTEM_FAT) {
  1752. // FAT doesn't have the stream
  1753. Status = STATUS_INVALID_PARAMETER;
  1754. goto FINALLY;
  1755. }
  1756. break;
  1757. case FileAttributeTagInformation:
  1758. if (pSmbNetRoot->NetRootFileSystem == NET_ROOT_FILESYSTEM_FAT ||
  1759. !(smbSrvOpen->FileInfo.Basic.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) ||
  1760. smbSrvOpen->IsNtCreate &&
  1761. smbSrvOpen->FileStatusFlags & SMB_FSF_NO_REPARSETAG &&
  1762. (smbSrvOpen->OplockLevel == SMB_OPLOCK_LEVEL_BATCH ||
  1763. smbSrvOpen->OplockLevel == SMB_OPLOCK_LEVEL_EXCLUSIVE)) {
  1764. PFILE_ATTRIBUTE_TAG_INFORMATION TagBuffer = (PFILE_ATTRIBUTE_TAG_INFORMATION)pBuffer;
  1765. TagBuffer->FileAttributes = smbSrvOpen->FileInfo.Basic.FileAttributes;
  1766. TagBuffer->ReparseTag = 0;
  1767. RxContext->Info.LengthRemaining -= sizeof(FILE_ATTRIBUTE_TAG_INFORMATION);
  1768. goto FINALLY;
  1769. }
  1770. }
  1771. if( MRxSmbForceCoreInfo ||
  1772. !FlagOn( pServerEntry->Server.DialectFlags, DF_NT_INFO_PASSTHROUGH ) ||
  1773. MRxSmbIsThisADisconnectedOpen(capFobx->pSrvOpen)) {
  1774. switch (FileInformationClass) {
  1775. case FileBasicInformation:
  1776. SmbFileInfoLevel = SMB_QUERY_FILE_BASIC_INFO;
  1777. break;
  1778. case FileStandardInformation:
  1779. SmbFileInfoLevel = SMB_QUERY_FILE_STANDARD_INFO;
  1780. break;
  1781. case FileEaInformation:
  1782. SmbFileInfoLevel = SMB_QUERY_FILE_EA_INFO;
  1783. break;
  1784. case FileAllocationInformation:
  1785. SmbFileInfoLevel = SMB_QUERY_FILE_ALLOCATION_INFO;
  1786. break;
  1787. case FileEndOfFileInformation:
  1788. SmbFileInfoLevel = SMB_QUERY_FILE_END_OF_FILEINFO;
  1789. break;
  1790. case FileAlternateNameInformation:
  1791. SmbFileInfoLevel = SMB_QUERY_FILE_ALT_NAME_INFO;
  1792. break;
  1793. case FileStreamInformation:
  1794. SmbFileInfoLevel = SMB_QUERY_FILE_STREAM_INFO;
  1795. break;
  1796. case FileCompressionInformation:
  1797. SmbFileInfoLevel = SMB_QUERY_FILE_COMPRESSION_INFO;
  1798. break;
  1799. case FileInternalInformation:
  1800. {
  1801. PFILE_INTERNAL_INFORMATION UsersBuffer = (PFILE_INTERNAL_INFORMATION)pBuffer;
  1802. //
  1803. // Note: We use the address of the FCB to determine the
  1804. // index number of the file. If we have to maintain persistance between
  1805. // file opens for this request, then we might have to do something
  1806. // like checksuming the reserved fields on a FUNIQUE SMB response.
  1807. //
  1808. //
  1809. // NT64: the address of capFcb used to be stuffed into
  1810. // IndexNumber.LowPart, with HighPart being zeroed.
  1811. //
  1812. // Whoever is asking for this pointer value should be
  1813. // prepared to deal with the returned 64-bit value.
  1814. //
  1815. UsersBuffer->IndexNumber.QuadPart = (ULONG_PTR)capFcb;
  1816. *pLengthRemaining -= sizeof(FILE_INTERNAL_INFORMATION);
  1817. Status = STATUS_SUCCESS;
  1818. }
  1819. goto FINALLY;
  1820. default:
  1821. RxDbgTrace( 0, Dbg, ("MRxSmbQueryFile: Invalid FS information class\n"));
  1822. Status = STATUS_INVALID_PARAMETER;
  1823. goto FINALLY;
  1824. }
  1825. } else {
  1826. //
  1827. // This server supports transparent NT information level passthrough. So
  1828. // just pass the request on to the server.
  1829. //
  1830. SmbFileInfoLevel = FileInformationClass + SMB_INFO_PASSTHROUGH;
  1831. }
  1832. IF_NOT_MRXSMB_BUILD_FOR_DISCONNECTED_CSC{
  1833. NOTHING;
  1834. } else {
  1835. if (CscPerformOperationInDisconnectedMode(RxContext) ||
  1836. FlagOn(smbSrvOpen->Flags, SMB_SRVOPEN_FLAG_LOCAL_OPEN)){
  1837. NTSTATUS QFINtStatus;
  1838. QFINtStatus = MRxSmbDCscQueryFileInfo(RxContext);
  1839. if (QFINtStatus != STATUS_MORE_PROCESSING_REQUIRED) {
  1840. RxDbgTrace(0, Dbg,
  1841. ("MRxSmbQueryFileInformation returningDCON with status=%08lx\n",
  1842. QFINtStatus ));
  1843. Status = QFINtStatus;
  1844. goto FINALLY;
  1845. }
  1846. }
  1847. }
  1848. if (MRxSmbIsFileNotFoundCached(RxContext)) {
  1849. Status = STATUS_OBJECT_NAME_NOT_FOUND;
  1850. RxDbgTrace( 0, Dbg, ("MRxSmbQueryFileInformation: FNF cached\n"));
  1851. goto FINALLY;
  1852. }
  1853. // Don't use cached information for the request from create against an aliased server
  1854. // so that we can be sure if it exists on the server.
  1855. if ((!pServerEntry->Server.AliasedServers ||
  1856. !FlagOn(RxContext->Flags,RX_CONTEXT_FLAG_MINIRDR_INITIATED)) &&
  1857. (FlagOn(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_NOT_REALLY_OPEN) ||
  1858. FlagOn(capFcb->FcbState,FCB_STATE_FILESIZECACHEING_ENABLED) ||
  1859. FileInformationClass == FileInternalInformation)) {
  1860. switch (FileInformationClass) {
  1861. case FileBasicInformation:
  1862. if (MRxSmbIsBasicFileInfoCacheFound(RxContext,
  1863. (PFILE_BASIC_INFORMATION)pBuffer,
  1864. &Status,
  1865. NULL)){
  1866. *pLengthRemaining -= sizeof(FILE_BASIC_INFORMATION);
  1867. RxDbgTrace( 0, Dbg, ("MRxSmbQueryFileInformation: Local Basic Info\n"));
  1868. return Status;
  1869. }
  1870. break;
  1871. case FileStandardInformation:
  1872. if (MRxSmbIsStandardFileInfoCacheFound(RxContext,
  1873. (PFILE_STANDARD_INFORMATION)pBuffer,
  1874. &Status,
  1875. NULL)){
  1876. *pLengthRemaining -= sizeof(FILE_STANDARD_INFORMATION);
  1877. RxDbgTrace( 0, Dbg, ("MRxSmbQueryFileInformation: Local Standard Info\n"));
  1878. return Status;
  1879. }
  1880. break;
  1881. case FileEndOfFileInformation:
  1882. {
  1883. FILE_STANDARD_INFORMATION Standard;
  1884. if (MRxSmbIsStandardFileInfoCacheFound(RxContext,
  1885. &Standard,
  1886. &Status,
  1887. NULL)){
  1888. ((PFILE_END_OF_FILE_INFORMATION)pBuffer)->EndOfFile.QuadPart = Standard.EndOfFile.QuadPart;
  1889. *pLengthRemaining -= sizeof(FILE_END_OF_FILE_INFORMATION);
  1890. RxDbgTrace( 0, Dbg, ("MRxSmbQueryFileInformation: Local EndOfFile Info\n"));
  1891. return Status;
  1892. }
  1893. }
  1894. break;
  1895. case FileInternalInformation:
  1896. if (MRxSmbIsInternalFileInfoCacheFound(RxContext,
  1897. (PFILE_INTERNAL_INFORMATION)pBuffer,
  1898. &Status,
  1899. NULL)){
  1900. *pLengthRemaining -= sizeof(FILE_INTERNAL_INFORMATION);
  1901. RxDbgTrace( 0, Dbg, ("MRxSmbQueryFileInformation: Local Internal Info\n"));
  1902. return Status;
  1903. }
  1904. break;
  1905. }
  1906. }
  1907. if (MRxSmbForceCoreInfo ||
  1908. FlagOn(pServerEntry->Server.DialectFlags,DF_W95) ||
  1909. !FlagOn(pServerEntry->Server.DialectFlags,DF_NT_SMBS)) {
  1910. // Win9x server supports NT SMB but doesn't support transact2. Therefore we use core.
  1911. return MRxSmbCoreInformation(
  1912. RxContext,
  1913. (ULONG)SmbFileInfoLevel,
  1914. pBuffer,
  1915. pLengthRemaining,
  1916. SMBPSE_OE_FROM_QUERYFILEINFO
  1917. );
  1918. }
  1919. Status = STATUS_SUCCESS;
  1920. if (!FlagOn(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_NOT_REALLY_OPEN)) {
  1921. //here, the FID is valid. do a t2_QFI
  1922. Setup = TRANS2_QUERY_FILE_INFORMATION;
  1923. QueryFileInfoRequest.Fid = smbSrvOpen->Fid;
  1924. QueryFileInfoRequest.InformationLevel = SmbFileInfoLevel;
  1925. pSendParameterBuffer = &QueryFileInfoRequest;
  1926. SendParameterBufferLength = sizeof(QueryFileInfoRequest);
  1927. RxDbgTrace(0, Dbg, (" fid,smbclass=%08lx,%08lx\n",smbSrvOpen->Fid,SmbFileInfoLevel));
  1928. } else {
  1929. OEM_STRING OemName;
  1930. BOOLEAN FreeOemName = FALSE;
  1931. Setup = TRANS2_QUERY_PATH_INFORMATION;
  1932. if (!FlagOn(pServerEntry->Server.DialectFlags,DF_UNICODE)) {
  1933. if (FlagOn(pServerEntry->Server.DialectFlags,DF_LONGNAME)) {
  1934. Status = RtlUnicodeStringToOemString(&OemName, RemainingName, TRUE);
  1935. } else {
  1936. Status = RtlUpcaseUnicodeStringToOemString(&OemName, RemainingName, TRUE);
  1937. }
  1938. if (Status == STATUS_SUCCESS) {
  1939. SendParameterBufferLength = FIELD_OFFSET(REQ_QUERY_PATH_INFORMATION,Buffer[0])
  1940. + OemName.Length + sizeof(CHAR); //null-terminated
  1941. FreeOemName = TRUE;
  1942. }
  1943. } else {
  1944. SendParameterBufferLength = FIELD_OFFSET(REQ_QUERY_PATH_INFORMATION,Buffer[0])
  1945. + RemainingName->Length + sizeof(WCHAR); //null-terminated
  1946. }
  1947. if (Status == STATUS_SUCCESS) {
  1948. pSendParameterBuffer = RxAllocatePoolWithTag(PagedPool,
  1949. SendParameterBufferLength,
  1950. MRXSMB_QPINFO_POOLTAG);
  1951. pQueryFilePathRequest = pSendParameterBuffer;
  1952. if (pQueryFilePathRequest != NULL) {
  1953. pQueryFilePathRequest->InformationLevel = SmbFileInfoLevel;
  1954. SmbPutUlong(&pQueryFilePathRequest->Reserved,0);
  1955. if (FlagOn(pServerEntry->Server.DialectFlags,DF_UNICODE)) {
  1956. RtlCopyMemory(&pQueryFilePathRequest->Buffer[0],RemainingName->Buffer,RemainingName->Length);
  1957. *((PWCHAR)(&pQueryFilePathRequest->Buffer[RemainingName->Length])) = 0;
  1958. } else {
  1959. RtlCopyMemory(&pQueryFilePathRequest->Buffer[0],OemName.Buffer,OemName.Length);
  1960. *((PCHAR)(&pQueryFilePathRequest->Buffer[OemName.Length])) = 0;
  1961. }
  1962. } else {
  1963. Status = STATUS_INSUFFICIENT_RESOURCES;
  1964. }
  1965. }
  1966. if (FreeOemName) {
  1967. RtlFreeOemString(&OemName);
  1968. }
  1969. }
  1970. if (Status == STATUS_SUCCESS) {
  1971. Status = SmbCeTransact(
  1972. RxContext,
  1973. pTransactionOptions,
  1974. &Setup,
  1975. sizeof(Setup),
  1976. NULL,
  1977. 0,
  1978. pSendParameterBuffer,
  1979. SendParameterBufferLength,
  1980. &QueryFileInfoResponse,
  1981. sizeof(QueryFileInfoResponse),
  1982. NULL,
  1983. 0,
  1984. pBuffer,
  1985. *pLengthRemaining,
  1986. &ResumptionContext);
  1987. if (NT_SUCCESS(Status)) {
  1988. *pLengthRemaining -= ResumptionContext.DataBytesReceived;
  1989. }
  1990. }
  1991. //
  1992. // Check for file not found status. If this is the case then create a
  1993. // name cache entry in the NetRoot name cache and record the status,
  1994. // the smb received count and set the expiration time for 5 seconds.
  1995. // Why: NB4 case of back to back srv reqs with 2nd req upcased.
  1996. //
  1997. if (NT_SUCCESS(Status)) {
  1998. //
  1999. // The request succeeded so free up the name cache entry.
  2000. //
  2001. MRxSmbInvalidateFileNotFoundCache(RxContext);
  2002. // cache the file info returned from the server.
  2003. switch (FileInformationClass) {
  2004. case FileBasicInformation:
  2005. MRxSmbCreateBasicFileInfoCache(RxContext,
  2006. (PFILE_BASIC_INFORMATION)pBuffer,
  2007. pServerEntry,
  2008. Status);
  2009. break;
  2010. case FileStandardInformation:
  2011. if (FlagOn(capFcb->FcbState,FCB_STATE_WRITEBUFFERING_ENABLED) &&
  2012. !FlagOn(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_NOT_REALLY_OPEN)) {
  2013. PFILE_STANDARD_INFORMATION Standard = (PFILE_STANDARD_INFORMATION)pBuffer;
  2014. RxGetFileSizeWithLock((PFCB)capFcb,&Standard->EndOfFile.QuadPart);
  2015. }
  2016. MRxSmbCreateStandardFileInfoCache(RxContext,
  2017. (PFILE_STANDARD_INFORMATION)pBuffer,
  2018. pServerEntry,
  2019. Status);
  2020. break;
  2021. case FileEndOfFileInformation:
  2022. MRxSmbUpdateFileInfoCacheFileSize(RxContext,
  2023. &((PFILE_END_OF_FILE_INFORMATION)pBuffer)->EndOfFile);
  2024. break;
  2025. case FileInternalInformation:
  2026. MRxSmbCreateInternalFileInfoCache(RxContext,
  2027. (PFILE_INTERNAL_INFORMATION)pBuffer,
  2028. pServerEntry,
  2029. Status);
  2030. break;
  2031. }
  2032. } else {
  2033. if (Status == STATUS_OBJECT_NAME_NOT_FOUND ||
  2034. Status == STATUS_OBJECT_PATH_NOT_FOUND) {
  2035. // create the name based file not found cache
  2036. MRxSmbCacheFileNotFound(RxContext);
  2037. } else {
  2038. // invalid the name based file not found cache if other error happens
  2039. MRxSmbInvalidateFileNotFoundCache(RxContext);
  2040. }
  2041. // invalid the name based file info cache
  2042. MRxSmbInvalidateFileInfoCache(RxContext);
  2043. }
  2044. FINALLY:
  2045. if (pQueryFilePathRequest != NULL) {
  2046. RxFreePool(pQueryFilePathRequest);
  2047. }
  2048. if (!NT_SUCCESS(Status)) {
  2049. RxDbgTrace( 0, Dbg, ("MRxSmbQueryFile: Failed .. returning %lx\n",Status));
  2050. }
  2051. RxDbgTraceUnIndent(-1,Dbg);
  2052. return Status;
  2053. }
  2054. NTSTATUS
  2055. MRxSmbQueryFileInformationFromPseudoOpen(
  2056. SMBPSE_ORDINARY_EXCHANGE_ARGUMENT_SIGNATURE,
  2057. FILE_INFORMATION_CLASS FileInformationClass
  2058. )
  2059. /*++
  2060. Routine Description:
  2061. This routine does a query file basic info from pseudo open.
  2062. Arguments:
  2063. RxContext - the RDBSS context
  2064. Return Value:
  2065. NTSTATUS - The return status for the operation
  2066. --*/
  2067. {
  2068. NTSTATUS Status;
  2069. PRX_CONTEXT LocalRxContext;
  2070. PAGED_CODE();
  2071. LocalRxContext = RxAllocatePoolWithTag(NonPagedPool,
  2072. sizeof(RX_CONTEXT),
  2073. MRXSMB_RXCONTEXT_POOLTAG);
  2074. if (LocalRxContext == NULL) {
  2075. Status = STATUS_INSUFFICIENT_RESOURCES;
  2076. } else {
  2077. RtlZeroMemory(
  2078. LocalRxContext,
  2079. sizeof(RX_CONTEXT));
  2080. RxInitializeContext(
  2081. NULL,
  2082. RxContext->RxDeviceObject,
  2083. 0,
  2084. LocalRxContext );
  2085. LocalRxContext->pFcb = RxContext->pFcb;
  2086. LocalRxContext->pFobx = RxContext->pFobx;
  2087. LocalRxContext->CurrentIrp = RxContext->CurrentIrp;
  2088. LocalRxContext->CurrentIrpSp = RxContext->CurrentIrpSp;
  2089. LocalRxContext->NonPagedFcb = RxContext->NonPagedFcb;
  2090. LocalRxContext->MajorFunction = IRP_MJ_CREATE;
  2091. LocalRxContext->pRelevantSrvOpen = RxContext->pRelevantSrvOpen;;
  2092. LocalRxContext->Flags = RX_CONTEXT_FLAG_MINIRDR_INITIATED|RX_CONTEXT_FLAG_WAIT|RX_CONTEXT_FLAG_BYPASS_VALIDOP_CHECK;
  2093. switch (FileInformationClass) {
  2094. case FileBasicInformation:
  2095. LocalRxContext->Info.LengthRemaining = sizeof(FILE_BASIC_INFORMATION);
  2096. LocalRxContext->Info.Buffer = &OrdinaryExchange->Create.FileInfo.Basic;
  2097. break;
  2098. case FileInternalInformation:
  2099. LocalRxContext->Info.LengthRemaining = sizeof(FILE_INTERNAL_INFORMATION);
  2100. LocalRxContext->Info.Buffer = &OrdinaryExchange->Create.FileInfo.Internal;
  2101. //DbgPrint("Query file internal information from create\n");
  2102. break;
  2103. }
  2104. LocalRxContext->Info.FileInformationClass = FileInformationClass;
  2105. LocalRxContext->Create = RxContext->Create;
  2106. Status = MRxSmbQueryFileInformation(LocalRxContext);
  2107. RxFreePool(LocalRxContext);
  2108. }
  2109. if ((Status == STATUS_SUCCESS) &&
  2110. (FileInformationClass == FileBasicInformation)) {
  2111. OrdinaryExchange->Create.FileInfo.Standard.Directory =
  2112. BooleanFlagOn(OrdinaryExchange->Create.FileInfo.Basic.FileAttributes,FILE_ATTRIBUTE_DIRECTORY);
  2113. OrdinaryExchange->Create.StorageTypeFromGFA =
  2114. OrdinaryExchange->Create.FileInfo.Standard.Directory ?
  2115. FileTypeDirectory : FileTypeFile;
  2116. }
  2117. return Status;
  2118. }
  2119. typedef enum _INTERESTING_SFI_FOLLOWONS {
  2120. SFI_FOLLOWON_NOTHING,
  2121. SFI_FOLLOWON_DISPOSITION_SENT
  2122. } INTERESTING_SFI_FOLLOWONS;
  2123. NTSTATUS
  2124. MRxSmbSetFileInformation (
  2125. IN PRX_CONTEXT RxContext
  2126. )
  2127. /*++
  2128. Routine Description:
  2129. This routine does a set file info. Only the NT-->NT path is implemented.
  2130. The NT-->NT path works by just remoting the call basically without further ado.
  2131. The file is not really open if it is created for delete. In this case, set dispostion info
  2132. will be delayed until file is closed.
  2133. Arguments:
  2134. RxContext - the RDBSS context
  2135. Return Value:
  2136. RXSTATUS - The return status for the operation
  2137. --*/
  2138. {
  2139. NTSTATUS Status = STATUS_SUCCESS;
  2140. RxCaptureFcb;
  2141. RxCaptureFobx;
  2142. FILE_INFORMATION_CLASS FileInformationClass;
  2143. PVOID pBuffer;
  2144. ULONG BufferLength;
  2145. PMRX_SRV_OPEN SrvOpen = capFobx->pSrvOpen;
  2146. PMRX_SMB_FCB smbFcb = MRxSmbGetFcbExtension(capFcb);
  2147. PMRX_SMB_FOBX smbFobx = MRxSmbGetFileObjectExtension(capFobx);
  2148. PMRX_SMB_SRV_OPEN smbSrvOpen = MRxSmbGetSrvOpenExtension(SrvOpen);
  2149. PSMBCE_V_NET_ROOT_CONTEXT pVNetRootContext = (PSMBCE_V_NET_ROOT_CONTEXT)SrvOpen->pVNetRoot->Context;
  2150. PSMBCE_NET_ROOT pSmbNetRoot = &pVNetRootContext->pNetRootEntry->NetRoot;
  2151. PSMBCEDB_SERVER_ENTRY pServerEntry;
  2152. USHORT SmbFileInfoLevel;
  2153. USHORT Setup;
  2154. INTERESTING_SFI_FOLLOWONS FollowOn = SFI_FOLLOWON_NOTHING;
  2155. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  2156. PSMB_TRANSACTION_OPTIONS pTransactionOptions = &RxDefaultTransactionOptions;
  2157. REQ_SET_FILE_INFORMATION SetFileInfoRequest;
  2158. RESP_SET_FILE_INFORMATION SetFileInfoResponse;
  2159. PREQ_SET_PATH_INFORMATION pSetFilePathRequest = NULL;
  2160. PVOID pSendParameterBuffer;
  2161. ULONG SendParameterBufferLength;
  2162. BOOLEAN fDoneCSCPart=FALSE;
  2163. BOOLEAN UseCore = FALSE;
  2164. PAGED_CODE();
  2165. TURN_BACK_ASYNCHRONOUS_OPERATIONS();
  2166. FileInformationClass = RxContext->Info.FileInformationClass;
  2167. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  2168. pBuffer = RxContext->Info.Buffer;
  2169. BufferLength = RxContext->Info.Length;
  2170. RxDbgTrace(+1, Dbg, ("MRxSmbSetFile: Class %08lx size %08lx\n",FileInformationClass,BufferLength));
  2171. IF_NOT_MRXSMB_BUILD_FOR_DISCONNECTED_CSC{
  2172. NOTHING;
  2173. } else {
  2174. if (CscPerformOperationInDisconnectedMode(RxContext)){
  2175. NTSTATUS SFINtStatus;
  2176. SFINtStatus = MRxSmbDCscSetFileInfo(RxContext);
  2177. fDoneCSCPart = TRUE;
  2178. if (SFINtStatus != STATUS_MORE_PROCESSING_REQUIRED) {
  2179. RxDbgTrace(0, Dbg,
  2180. ("MRxSmbSetFileInformation returningDCON with status=%08lx\n",
  2181. SFINtStatus ));
  2182. #ifdef LocalOpen
  2183. if (FlagOn(smbSrvOpen->Flags, SMB_SRVOPEN_FLAG_LOCAL_OPEN)) {
  2184. switch( FileInformationClass ) {
  2185. case FileRenameInformation:
  2186. MRxSmbRename( RxContext );
  2187. break;
  2188. }
  2189. }
  2190. #endif
  2191. Status = SFINtStatus;
  2192. goto FINALLY;
  2193. } else {
  2194. NOTHING;
  2195. }
  2196. }
  2197. else if (FileInformationClass == FileDispositionInformation)
  2198. {
  2199. if(CSCCheckLocalOpens(RxContext))
  2200. {
  2201. // disallow deletes if there are local open on this file
  2202. // This happens only on a VDO marked share
  2203. Status = STATUS_ACCESS_DENIED;
  2204. goto FINALLY;
  2205. }
  2206. }
  2207. }
  2208. if (MRxSmbIsFileNotFoundCached(RxContext)) {
  2209. Status = STATUS_OBJECT_NAME_NOT_FOUND;
  2210. RxDbgTrace( 0, Dbg, ("MRxSmbSetFileInformation: FNF cached\n"));
  2211. goto FINALLY;
  2212. }
  2213. if (FileInformationClass != FileBasicInformation &&
  2214. FileInformationClass != FileDispositionInformation &&
  2215. FlagOn(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_NOT_REALLY_OPEN)) {
  2216. Status = MRxSmbDeferredCreate(RxContext);
  2217. if (Status != STATUS_SUCCESS) {
  2218. goto FINALLY;
  2219. }
  2220. }
  2221. if( FileInformationClass == FilePipeLocalInformation ||
  2222. FileInformationClass == FilePipeInformation ||
  2223. FileInformationClass == FilePipeRemoteInformation ) {
  2224. return MRxSmbSetNamedPipeInformation(
  2225. RxContext,
  2226. FileInformationClass,
  2227. pBuffer,
  2228. BufferLength);
  2229. }
  2230. if (!MRxSmbForceCoreInfo &&
  2231. !FlagOn(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_NOT_REALLY_OPEN) &&
  2232. FlagOn( pServerEntry->Server.DialectFlags, DF_NT_INFO_PASSTHROUGH)) {
  2233. SmbFileInfoLevel = FileInformationClass + SMB_INFO_PASSTHROUGH;
  2234. if( FileInformationClass == FileRenameInformation ) {
  2235. PFILE_RENAME_INFORMATION pRenameInformation;
  2236. // The current implementation of pass through for rename information
  2237. // on the server does not go all the way in implementing the
  2238. // NT_TRANSACT, NT_RENAME function defined in SMBs. Therefore we need
  2239. // to special case the code to accomodate the server implementation
  2240. // The two cases that are not permitted are relative renames,
  2241. // specifying a non null root directory and deep renames which
  2242. // transcend the current directory structure. For these cases we will
  2243. // have to revert back to what we had before.
  2244. pRenameInformation = (PFILE_RENAME_INFORMATION)pBuffer;
  2245. if (pRenameInformation->RootDirectory == NULL) {
  2246. // Scan the name given for rename to determine if it is in
  2247. // some other directory.
  2248. ULONG NameLengthInBytes = pRenameInformation->FileNameLength;
  2249. PWCHAR pRenameTarget = pRenameInformation->FileName;
  2250. while ((NameLengthInBytes > 0) &&
  2251. (*pRenameTarget != OBJ_NAME_PATH_SEPARATOR)) {
  2252. NameLengthInBytes -= sizeof(WCHAR);
  2253. }
  2254. if (NameLengthInBytes > 0) {
  2255. UseCore = TRUE;
  2256. }
  2257. } else {
  2258. UseCore = TRUE;
  2259. }
  2260. #ifdef _WIN64
  2261. // Don't thunk the data if we're going to take the downlevel path (since the data will be mapped into an SMB_RENAME
  2262. if( !(UseCore ||
  2263. MRxSmbForceCoreInfo ||
  2264. !FlagOn(pServerEntry->Server.DialectFlags,DF_NT_SMBS) ||
  2265. FlagOn(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_NOT_REALLY_OPEN)) )
  2266. {
  2267. PBYTE pNewBuffer = Smb64ThunkFileRenameInfo( pRenameInformation, &BufferLength, &Status );
  2268. if( !NT_SUCCESS(Status) )
  2269. {
  2270. goto FINALLY;
  2271. }
  2272. else
  2273. {
  2274. pBuffer = pNewBuffer;
  2275. }
  2276. }
  2277. #endif
  2278. }
  2279. if (FileInformationClass == FileLinkInformation) {
  2280. UseCore = TRUE;
  2281. }
  2282. } else {
  2283. switch( FileInformationClass ) {
  2284. case FileBasicInformation:
  2285. SmbFileInfoLevel = SMB_SET_FILE_BASIC_INFO;
  2286. break;
  2287. case FileDispositionInformation:
  2288. SmbFileInfoLevel = SMB_SET_FILE_DISPOSITION_INFO;
  2289. break;
  2290. case FileAllocationInformation:
  2291. SmbFileInfoLevel = SMB_SET_FILE_ALLOCATION_INFO;
  2292. break;
  2293. case FileEndOfFileInformation:
  2294. SmbFileInfoLevel = SMB_SET_FILE_END_OF_FILE_INFO;
  2295. break;
  2296. case FileLinkInformation:
  2297. case FileRenameInformation:
  2298. UseCore = TRUE;
  2299. break;
  2300. default:
  2301. Status = STATUS_INVALID_PARAMETER;
  2302. goto FINALLY;
  2303. }
  2304. }
  2305. if (UseCore ||
  2306. MRxSmbForceCoreInfo ||
  2307. !FlagOn(pServerEntry->Server.DialectFlags,DF_NT_SMBS) ||
  2308. FlagOn(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_NOT_REALLY_OPEN)) {
  2309. if (FileInformationClass == FileLinkInformation ||
  2310. FileInformationClass == FileRenameInformation) {
  2311. Status = MRxSmbBypassDownLevelRename ?
  2312. STATUS_INVALID_PARAMETER :
  2313. MRxSmbRename( RxContext );
  2314. } else {
  2315. Status = MRxSmbCoreInformation(
  2316. RxContext,
  2317. FileInformationClass,
  2318. pBuffer,
  2319. &BufferLength,
  2320. SMBPSE_OE_FROM_SETFILEINFO
  2321. );
  2322. }
  2323. goto FINALLY;
  2324. }
  2325. Setup = TRANS2_SET_FILE_INFORMATION;
  2326. SetFileInfoRequest.Fid = smbSrvOpen->Fid;
  2327. SetFileInfoRequest.InformationLevel = SmbFileInfoLevel;
  2328. SetFileInfoRequest.Flags = 0;
  2329. pSendParameterBuffer = &SetFileInfoRequest;
  2330. SendParameterBufferLength = sizeof(SetFileInfoRequest);
  2331. RxDbgTrace(0, Dbg, (" fid,smbclass=%08lx,%08lx\n",smbSrvOpen->Fid,SmbFileInfoLevel));
  2332. Status = SmbCeTransact(
  2333. RxContext,
  2334. pTransactionOptions,
  2335. &Setup,
  2336. sizeof(Setup),
  2337. NULL,
  2338. 0,
  2339. pSendParameterBuffer,
  2340. SendParameterBufferLength,
  2341. &SetFileInfoResponse,
  2342. sizeof(SetFileInfoResponse),
  2343. pBuffer,
  2344. BufferLength,
  2345. NULL,
  2346. 0,
  2347. &ResumptionContext);
  2348. if (Status == STATUS_SUCCESS &&
  2349. (FileInformationClass == FileRenameInformation ||
  2350. FileInformationClass == FileDispositionInformation)) {
  2351. // create the name based file not found cache
  2352. MRxSmbCacheFileNotFound(RxContext);
  2353. // invalidate the name based file info cache
  2354. MRxSmbInvalidateFileInfoCache(RxContext);
  2355. MRxSmbInvalidateInternalFileInfoCache(RxContext);
  2356. if (FileInformationClass == FileDispositionInformation) {
  2357. PMRX_SMB_FCB smbFcb = MRxSmbGetFcbExtension(capFcb);
  2358. SetFlag((((PMRX_SMB_FCB)smbFcb)->MFlags),SMB_FCB_FLAG_SENT_DISPOSITION_INFO);
  2359. SetFlag(smbSrvOpen->Flags,SMB_SRVOPEN_FLAG_FILE_DELETED);
  2360. }
  2361. }
  2362. FINALLY:
  2363. if (NT_SUCCESS(Status)) {
  2364. switch(FileInformationClass) {
  2365. case FileBasicInformation:
  2366. if (pServerEntry->Server.Dialect == NTLANMAN_DIALECT &&
  2367. pSmbNetRoot->NetRootFileSystem == NET_ROOT_FILESYSTEM_NTFS) {
  2368. MRxSmbUpdateBasicFileInfoCacheAll(RxContext,
  2369. (PFILE_BASIC_INFORMATION)pBuffer);
  2370. } else {
  2371. // some file system, i.e. FAT, has the time stamp with granularity of 2 seconds.
  2372. // RDR cannot predict what the time stamp on the server, therefore invalid the cache
  2373. MRxSmbInvalidateBasicFileInfoCache(RxContext);
  2374. }
  2375. break;
  2376. case FileEndOfFileInformation:
  2377. MRxSmbUpdateFileInfoCacheFileSize(RxContext,
  2378. &((PFILE_END_OF_FILE_INFORMATION)pBuffer)->EndOfFile);
  2379. break;
  2380. case FileStandardInformation:
  2381. MRxSmbUpdateStandardFileInfoCache(RxContext,
  2382. (PFILE_STANDARD_INFORMATION)pBuffer,
  2383. FALSE);
  2384. break;
  2385. case FileEaInformation:
  2386. smbSrvOpen->FileStatusFlags &= ~SMB_FSF_NO_EAS;
  2387. break;
  2388. case FileAttributeTagInformation:
  2389. smbSrvOpen->FileStatusFlags &= ~SMB_FSF_NO_REPARSETAG;
  2390. break;
  2391. #ifdef _WIN64
  2392. case FileRenameInformation:
  2393. // Clean up the Thunk data if necessary
  2394. if( pBuffer != RxContext->Info.Buffer )
  2395. {
  2396. Smb64ReleaseThunkData( pBuffer );
  2397. pBuffer = RxContext->Info.Buffer;
  2398. }
  2399. break;
  2400. #endif
  2401. }
  2402. } else {
  2403. if (Status == STATUS_OBJECT_NAME_NOT_FOUND ||
  2404. Status == STATUS_OBJECT_PATH_NOT_FOUND) {
  2405. // create the name based file not found cache
  2406. MRxSmbCacheFileNotFound(RxContext);
  2407. } else {
  2408. // invalid the name based file not found cache if other error happens
  2409. MRxSmbInvalidateFileNotFoundCache(RxContext);
  2410. }
  2411. // invalid the name based file info cache
  2412. MRxSmbInvalidateFileInfoCache(RxContext);
  2413. RxDbgTrace( 0, Dbg, ("MRxSmbSetFile: Failed .. returning %lx\n",Status));
  2414. }
  2415. // update shadow as appropriate. This needs to be done only for NT servers
  2416. // since pinning/CSC is not supported against non NT servers.
  2417. IF_NOT_MRXSMB_CSC_ENABLED{
  2418. ASSERT(MRxSmbGetSrvOpenExtension(SrvOpen)->hfShadow == 0);
  2419. } else {
  2420. if (!fDoneCSCPart) {
  2421. if (FileInformationClass == FileRenameInformation) {
  2422. MRxSmbCscRenameEpilogue(RxContext,&Status);
  2423. } else {
  2424. MRxSmbCscSetFileInfoEpilogue(RxContext, &Status);
  2425. }
  2426. }
  2427. }
  2428. RxDbgTraceUnIndent(-1,Dbg);
  2429. return Status;
  2430. }
  2431. NTSTATUS
  2432. MRxSmbQueryNamedPipeInformation(
  2433. IN PRX_CONTEXT RxContext,
  2434. IN FILE_INFORMATION_CLASS FileInformationClass,
  2435. IN OUT PVOID pBuffer,
  2436. IN OUT PULONG pLengthRemaining)
  2437. {
  2438. RxCaptureFobx;
  2439. PMRX_SMB_SRV_OPEN pSmbSrvOpen;
  2440. NTSTATUS Status;
  2441. USHORT Setup[2];
  2442. USHORT Level;
  2443. PBYTE pInputDataBuffer = NULL;
  2444. PBYTE pOutputParamBuffer = NULL;
  2445. PBYTE pOutputDataBuffer = NULL;
  2446. ULONG OutputParamBufferLength = 0;
  2447. ULONG InputDataBufferLength = 0;
  2448. ULONG OutputDataBufferLength = 0;
  2449. ULONG SmbPipeInformationLength;
  2450. PNAMED_PIPE_INFORMATION_1 pSmbPipeInformation;
  2451. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  2452. SMB_TRANSACTION_OPTIONS TransactionOptions;
  2453. PAGED_CODE();
  2454. ASSERT(*pLengthRemaining >= sizeof(FILE_PIPE_LOCAL_INFORMATION));
  2455. ASSERT(capFobx != NULL);
  2456. pSmbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
  2457. // The SMB data structures defines a response that is significantly different from the
  2458. // FILE_PIPE_LOCAL_INFORMATION data structures. This mismatch is resolved by obtaining
  2459. // the SMB results in a different buffer and then copying the relevant pieces of
  2460. // information onto the query information buffer. SInce the SMB definition involves the
  2461. // pipe name as well a buffer that is large enough to hold the path name needs to be
  2462. // defined.
  2463. SmbPipeInformationLength = sizeof(NAMED_PIPE_INFORMATION_1) +
  2464. MAXIMUM_FILENAME_LENGTH;
  2465. pSmbPipeInformation = RxAllocatePoolWithTag(
  2466. PagedPool,
  2467. SmbPipeInformationLength,
  2468. MRXSMB_PIPEINFO_POOLTAG);
  2469. if (pSmbPipeInformation == NULL) {
  2470. return STATUS_INSUFFICIENT_RESOURCES;
  2471. }
  2472. Setup[0] = TRANS_QUERY_NMPIPE_INFO;
  2473. Setup[1] = pSmbSrvOpen->Fid;
  2474. Level = 1; // Information Level Desired
  2475. TransactionOptions = RxDefaultTransactionOptions;
  2476. TransactionOptions.pTransactionName = &s_NamedPipeTransactionName;
  2477. Status = SmbCeTransact(
  2478. RxContext, // the RXContext for the transaction
  2479. &TransactionOptions, // transaction options
  2480. Setup, // the setup buffer
  2481. sizeof(Setup), // setup buffer length
  2482. NULL,
  2483. 0,
  2484. &Level, // Input Param Buffer
  2485. sizeof(Level), // Input param buffer length
  2486. pOutputParamBuffer, // Output param buffer
  2487. OutputParamBufferLength, // output param buffer length
  2488. pInputDataBuffer, // Input data buffer
  2489. InputDataBufferLength, // Input data buffer length
  2490. pSmbPipeInformation, // output data buffer
  2491. SmbPipeInformationLength, // output data buffer length
  2492. &ResumptionContext // the resumption context
  2493. );
  2494. if (NT_SUCCESS(Status)) {
  2495. PFILE_PIPE_LOCAL_INFORMATION pFilePipeInformation = (PFILE_PIPE_LOCAL_INFORMATION)pBuffer;
  2496. // MaximumInstances and CurrentInstances are UCHAR fields ...
  2497. pFilePipeInformation->MaximumInstances = (ULONG)pSmbPipeInformation->MaximumInstances;
  2498. pFilePipeInformation->CurrentInstances = (ULONG)pSmbPipeInformation->CurrentInstances;
  2499. pFilePipeInformation->InboundQuota = SmbGetUshort(&pSmbPipeInformation->InputBufferSize);
  2500. pFilePipeInformation->ReadDataAvailable = 0xffffffff;
  2501. pFilePipeInformation->OutboundQuota = SmbGetUshort(&pSmbPipeInformation->OutputBufferSize);
  2502. pFilePipeInformation->WriteQuotaAvailable = 0xffffffff;
  2503. pFilePipeInformation->NamedPipeState = FILE_PIPE_CONNECTED_STATE;// Since no error
  2504. pFilePipeInformation->NamedPipeEnd = FILE_PIPE_CLIENT_END;
  2505. RxDbgTrace( 0, Dbg, ("MRxSmbQueryNamedPipeInformation: Pipe Name .. %s\n",pSmbPipeInformation->PipeName));
  2506. *pLengthRemaining -= sizeof(FILE_PIPE_LOCAL_INFORMATION);
  2507. }
  2508. RxFreePool(pSmbPipeInformation);
  2509. RxDbgTrace( 0, Dbg, ("MRxSmbQueryNamedPipeInformation: ...returning %lx\n",Status));
  2510. return Status;
  2511. }
  2512. NTSTATUS
  2513. MRxSmbSetNamedPipeInformation(
  2514. IN PRX_CONTEXT RxContext,
  2515. IN FILE_INFORMATION_CLASS FileInformationClass,
  2516. IN PVOID pBuffer,
  2517. IN ULONG BufferLength)
  2518. {
  2519. RxCaptureFobx;
  2520. PMRX_SMB_SRV_OPEN pSmbSrvOpen;
  2521. NTSTATUS Status;
  2522. USHORT Setup[2];
  2523. USHORT NewState;
  2524. PBYTE pInputDataBuffer = NULL;
  2525. PBYTE pOutputParamBuffer = NULL;
  2526. PBYTE pOutputDataBuffer = NULL;
  2527. ULONG OutputParamBufferLength = 0;
  2528. ULONG InputDataBufferLength = 0;
  2529. ULONG OutputDataBufferLength = 0;
  2530. PFILE_PIPE_INFORMATION pPipeInformation;
  2531. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  2532. SMB_TRANSACTION_OPTIONS TransactionOptions;
  2533. PAGED_CODE();
  2534. pSmbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
  2535. if (BufferLength < sizeof(FILE_PIPE_INFORMATION)) {
  2536. return STATUS_BUFFER_TOO_SMALL;
  2537. }
  2538. if (FileInformationClass != FilePipeInformation) {
  2539. return STATUS_INVALID_PARAMETER;
  2540. }
  2541. pPipeInformation = (PFILE_PIPE_INFORMATION)pBuffer;
  2542. NewState = 0;
  2543. if (pPipeInformation->ReadMode == FILE_PIPE_MESSAGE_MODE) {
  2544. NewState |= SMB_PIPE_READMODE_MESSAGE;
  2545. }
  2546. if (pPipeInformation->CompletionMode == FILE_PIPE_COMPLETE_OPERATION) {
  2547. NewState |= SMB_PIPE_NOWAIT;
  2548. }
  2549. Setup[0] = TRANS_SET_NMPIPE_STATE;
  2550. Setup[1] = pSmbSrvOpen->Fid;
  2551. TransactionOptions = RxDefaultTransactionOptions;
  2552. TransactionOptions.pTransactionName = &s_NamedPipeTransactionName;
  2553. Status = SmbCeTransact(
  2554. RxContext, // the RXContext for the transaction
  2555. &TransactionOptions, // transaction options
  2556. Setup, // the setup buffer
  2557. sizeof(Setup), // setup buffer length
  2558. NULL,
  2559. 0,
  2560. &NewState, // Input Param Buffer
  2561. sizeof(NewState), // Input param buffer length
  2562. pOutputParamBuffer, // Output param buffer
  2563. OutputParamBufferLength, // output param buffer length
  2564. pInputDataBuffer, // Input data buffer
  2565. InputDataBufferLength, // Input data buffer length
  2566. pOutputDataBuffer, // output data buffer
  2567. OutputDataBufferLength, // output data buffer length
  2568. &ResumptionContext // the resumption context
  2569. );
  2570. RxDbgTrace( 0, Dbg, ("MRxSmbQueryNamedPipeInformation: ...returning %lx\n",Status));
  2571. return Status;
  2572. }
  2573. NTSTATUS
  2574. MRxSmbSetFileInformationAtCleanup(
  2575. IN PRX_CONTEXT RxContext
  2576. )
  2577. /*++
  2578. Routine Description:
  2579. This routine sets the file information on cleanup. the old rdr just swallows this operation (i.e.
  2580. it doesn't generate it). we are doing the same..........
  2581. Arguments:
  2582. pRxContext - the RDBSS context
  2583. Return Value:
  2584. NTSTATUS - The return status for the operation
  2585. --*/
  2586. {
  2587. return STATUS_SUCCESS;
  2588. }
  2589. NTSTATUS
  2590. MRxSmbIsValidDirectory(
  2591. IN OUT PRX_CONTEXT RxContext,
  2592. IN PUNICODE_STRING DirectoryName
  2593. )
  2594. /*++
  2595. Routine Description:
  2596. This routine checks a remote directory.
  2597. Arguments:
  2598. RxContext - the RDBSS context
  2599. DirectoryName - the directory needs to be checked
  2600. Return Value:
  2601. RXSTATUS - The return status for the operation
  2602. --*/
  2603. {
  2604. NTSTATUS Status;
  2605. BOOLEAN FinalizationComplete;
  2606. PSMB_PSE_ORDINARY_EXCHANGE OrdinaryExchange = NULL;
  2607. PSMBSTUFFER_BUFFER_STATE StufferState;
  2608. KEVENT SyncEvent;
  2609. PAGED_CODE();
  2610. RxDbgTrace(+1, Dbg, ("MRxSmbIsValidDirectory\n", 0 ));
  2611. IF_NOT_MRXSMB_BUILD_FOR_DISCONNECTED_CSC{
  2612. NOTHING;
  2613. } else {
  2614. PSMBCEDB_SERVER_ENTRY pServerEntry;
  2615. pServerEntry = SmbCeGetAssociatedServerEntry(RxContext->Create.pSrvCall);
  2616. if (SmbCeIsServerInDisconnectedMode(pServerEntry)){
  2617. NTSTATUS CscStatus;
  2618. CscStatus = MRxSmbDCscIsValidDirectory(RxContext,DirectoryName);
  2619. if (CscStatus != STATUS_MORE_PROCESSING_REQUIRED) {
  2620. RxDbgTrace(0, Dbg,
  2621. ("MRxSmbQueryVolumeInfo returningDCON with status=%08lx\n",
  2622. CscStatus ));
  2623. Status = CscStatus;
  2624. goto FINALLY;
  2625. } else {
  2626. NOTHING;
  2627. }
  2628. }
  2629. }
  2630. Status = SmbCeReconnect(RxContext->Create.pVNetRoot);
  2631. if (Status != STATUS_SUCCESS) {
  2632. goto FINALLY;
  2633. }
  2634. Status= SmbPseCreateOrdinaryExchange(
  2635. RxContext,
  2636. RxContext->Create.pVNetRoot,
  2637. SMBPSE_OE_FROM_CREATE,
  2638. MRxSmbCoreCheckPath,
  2639. &OrdinaryExchange
  2640. );
  2641. if (Status != STATUS_SUCCESS) {
  2642. RxDbgTrace(-1, Dbg, ("Couldn't get the smb buf!\n"));
  2643. goto FINALLY;
  2644. }
  2645. OrdinaryExchange->pPathArgument1 = DirectoryName;
  2646. OrdinaryExchange->SmbCeFlags |= SMBCE_EXCHANGE_ATTEMPT_RECONNECTS;
  2647. OrdinaryExchange->AssociatedStufferState.CurrentCommand = SMB_COM_NO_ANDX_COMMAND;
  2648. OrdinaryExchange->pSmbCeSynchronizationEvent = &SyncEvent;
  2649. StufferState = &OrdinaryExchange->AssociatedStufferState;
  2650. MRxSmbSetInitialSMB(StufferState STUFFERTRACE(Dbg,'FC'));
  2651. Status = SmbPseInitiateOrdinaryExchange(OrdinaryExchange);
  2652. ASSERT(Status != STATUS_PENDING);
  2653. if (Status != STATUS_SUCCESS) {
  2654. Status = STATUS_BAD_NETWORK_PATH;
  2655. }
  2656. FinalizationComplete = SmbPseFinalizeOrdinaryExchange(OrdinaryExchange);
  2657. ASSERT(FinalizationComplete);
  2658. FINALLY:
  2659. RxDbgTrace(-1, Dbg, ("MRxSmbIsValidDirectory exit with status=%08lx\n", Status ));
  2660. return(Status);
  2661. }