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.

3722 lines
95 KiB

  1. /*++ BUILD Version: 0003 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. srvblock.h
  5. Abstract:
  6. This module defines the standard header for data blocks maintained
  7. by the LAN Manager server.
  8. Author:
  9. Chuck Lenzmeier (chuckl) 1-Dec-1989
  10. David Treadwell (davidtr)
  11. Revision History:
  12. --*/
  13. #ifndef _SRVBLOCK_
  14. #define _SRVBLOCK_
  15. //#include "srvtypes.h"
  16. //
  17. // The following define the various types of data blocks used by the
  18. // server.
  19. //
  20. // *** The pool tag array in heapmgr.c must be maintained in concert
  21. // with these definitions.
  22. //
  23. #define BlockTypeGarbage 0x00
  24. #define BlockTypeBuffer 0x01
  25. #define BlockTypeConnection 0x02
  26. #define BlockTypeEndpoint 0x03
  27. #define BlockTypeLfcb 0x04
  28. #define BlockTypeMfcb 0x05
  29. #define BlockTypeRfcb 0x06
  30. #define BlockTypeSearch 0x07
  31. #define BlockTypeSearchCore 0x08
  32. #ifdef INCLUDE_SMB_PERSISTENT
  33. #define BlockTypeByteRangeLock 0x09
  34. #endif
  35. #define BlockTypeSession 0x0A
  36. #define BlockTypeShare 0x0B
  37. #define BlockTypeTransaction 0x0C
  38. #define BlockTypeTreeConnect 0x0D
  39. #define BlockTypeWaitForOplockBreak 0x0E
  40. #define BlockTypeCommDevice 0x0F
  41. #define BlockTypeWorkContextInitial 0x10
  42. #define BlockTypeWorkContextNormal 0x11
  43. #define BlockTypeWorkContextRaw 0x12
  44. #define BlockTypeWorkContextSpecial 0x13
  45. #define BlockTypeCachedDirectory 0x14
  46. // The following "blocks" do NOT have block headers.
  47. #define BlockTypeDataBuffer 0x15
  48. #define BlockTypeTable 0x16
  49. #define BlockTypeNonpagedHeader 0x17
  50. #define BlockTypePagedConnection 0x18
  51. #define BlockTypePagedRfcb 0x19
  52. #define BlockTypeNonpagedMfcb 0x1A
  53. #define BlockTypeTimer 0x1B
  54. #define BlockTypeAdminCheck 0x1C
  55. #define BlockTypeWorkQueue 0x1D
  56. #define BlockTypeDfs 0x1E
  57. #define BlockTypeLargeReadX 0x1F
  58. #define BlockTypeAdapterStatus 0x20
  59. #define BlockTypeShareRemark 0x21
  60. #define BlockTypeShareSecurityDescriptor 0x22
  61. #define BlockTypeVolumeInformation 0x23
  62. #define BlockTypeFSName 0x24
  63. #define BlockTypeNameInfo 0x25
  64. #define BlockTypeDirectoryInfo 0x26
  65. #define BlockTypeDirCache 0x27
  66. #define BlockTypeMisc 0x28
  67. #define BlockTypeSnapShot 0x29
  68. #ifdef INCLUDE_SMB_PERSISTENT
  69. #define BlockTypePersistentState 0x2A
  70. #define BlockTypePersistentBitMap 0x2B
  71. #define BlockTypePersistShareState 0x2C
  72. // The following is defined just to know how many types there are.
  73. #define BlockTypeMax 0x2D
  74. #else
  75. // The following is defined just to know how many types there are.
  76. #define BlockTypeMax 0x2A
  77. #endif
  78. //
  79. // The following define the various states that blocks can be in.
  80. // Initializing is used (relatively rarely) to indicate that
  81. // creation/initialization of a block is in progress. Active is the
  82. // state blocks are usually in. Closing is used to indicate that a
  83. // block is being prepared for deletion; when the reference count on the
  84. // block reaches 0, the block will be deleted. Dead is used when
  85. // debugging code is enabled to indicate that the block has been
  86. // deleted.
  87. //
  88. #define BlockStateDead 0x00
  89. #define BlockStateInitializing 0x01
  90. #define BlockStateActive 0x02
  91. #define BlockStateClosing 0x03
  92. // The following is defined just to know how many states there are.
  93. #define BlockStateMax 0x04
  94. //
  95. // ALLOCATE_NONPAGED_POOL is a macro that translates to a call to
  96. // SrvAllocateNonPagedPool if debugging is not enabled or to
  97. // SrvAllocateNonPagedPoolDebug if it is enabled.
  98. // DEALLOCATE_NONPAGED_POOL translates to SrvFreeNonPagedPool or
  99. // SrvFreeNonPagedPoolDebug. The Srv routines are used to track pool
  100. // usage by the server.
  101. //
  102. //
  103. // When POOL_TAGGING is on, we pass the block type through to
  104. // SrvAllocateNonPagedPool so that it can pass a tag to the pool
  105. // allocator.
  106. //
  107. #ifdef POOL_TAGGING
  108. #define ALLOCATE_NONPAGED_POOL(size,type) \
  109. SrvAllocateNonPagedPool( (size), (type) )
  110. #else
  111. #define ALLOCATE_NONPAGED_POOL(size,type) \
  112. SrvAllocateNonPagedPool( (size) )
  113. #endif
  114. #define DEALLOCATE_NONPAGED_POOL(addr) SrvFreeNonPagedPool( (addr) )
  115. //
  116. // Routines that track server nonpaged pool usage in order to support the
  117. // "maxnonpagedmemoryusage" configuration parameter.
  118. //
  119. PVOID SRVFASTCALL
  120. SrvAllocateNonPagedPool (
  121. IN CLONG NumberOfBytes
  122. #ifdef POOL_TAGGING
  123. ,IN CLONG BlockType
  124. #endif
  125. );
  126. VOID SRVFASTCALL
  127. SrvFreeNonPagedPool (
  128. IN PVOID Address
  129. );
  130. VOID SRVFASTCALL
  131. SrvClearLookAsideList(
  132. PLOOK_ASIDE_LIST l,
  133. VOID (SRVFASTCALL *FreeRoutine )( PVOID )
  134. );
  135. //
  136. // The _HEAP macros are like the _NONPAGED_POOL macros, except they
  137. // operate on paged pool. The "HEAP" name is historical, from the
  138. // days when the server used process heap instead of paged pool.
  139. //
  140. // *** When SRVDBG2 is enabled, all server control blocks and all
  141. // reference history blocks must be allocated from nonpaged pool,
  142. // because SrvUpdateReferenceHistory touches these thing while
  143. // holding a spin lock (i.e., at raised IRQL). To make this easy,
  144. // the ALLOCATE_HEAP and FREE_HEAP macros are modified to use
  145. // nonpaged pool. This means that ALL memory allocated by the
  146. // server comes out of nonpaged pool when SRVDBG2 is on.
  147. //
  148. #if SRVDBG2
  149. #define ALLOCATE_HEAP(size,type) ALLOCATE_NONPAGED_POOL( (size), (type) )
  150. #define ALLOCATE_HEAP_COLD(size,type) ALLOCATE_NONPAGED_POOL( (size), (type) )
  151. #define FREE_HEAP(addr) DEALLOCATE_NONPAGED_POOL( (addr) )
  152. #else // SRVDBG2
  153. //
  154. // When POOL_TAGGING is on, we pass the block type through to
  155. // SrvAllocateNonPagedPool so that it can pass a tag to the pool
  156. // allocator.
  157. //
  158. #ifdef POOL_TAGGING
  159. #define ALLOCATE_HEAP(size,type) SrvAllocatePagedPool( PagedPool, (size), (type) )
  160. #define ALLOCATE_HEAP_COLD(size,type) SrvAllocatePagedPool( (PagedPool | POOL_COLD_ALLOCATION), (size), (type) )
  161. #else
  162. #define ALLOCATE_HEAP(size,type) SrvAllocatePagedPool( PagedPool, (size) )
  163. #define ALLOCATE_HEAP_COLD(size,type) SrvAllocatePagedPool( (PagedPool | POOL_COLD_ALLOCATION), (size) )
  164. #endif
  165. #define FREE_HEAP(addr) SrvFreePagedPool( (addr) )
  166. #endif // else SRVDBG2
  167. //
  168. // Routines that track server paged pool usage in order to support the
  169. // "maxpagedmemoryusage" configuration parameter.
  170. //
  171. PVOID SRVFASTCALL
  172. SrvAllocatePagedPool (
  173. IN POOL_TYPE PoolType,
  174. IN CLONG NumberOfBytes
  175. #ifdef POOL_TAGGING
  176. ,IN CLONG BlockType
  177. #endif
  178. );
  179. VOID SRVFASTCALL
  180. SrvFreePagedPool (
  181. IN PVOID Address
  182. );
  183. //
  184. // SHARE_TYPE is an enumerated type used to indicate what type of
  185. // resource is being shared. This type corresponds to the server
  186. // table StrShareTypeNames. Keep the two in sync.
  187. //
  188. typedef enum _SHARE_TYPE {
  189. ShareTypeDisk,
  190. ShareTypePrint,
  191. ShareTypePipe,
  192. ShareTypeWild // not a real share type, but can be specified in tcon
  193. } SHARE_TYPE, *PSHARE_TYPE;
  194. //
  195. // SHARE_SNAPSHOT represents a snapshot availible for this share.
  196. //
  197. typedef struct _SHARE_SNAPSHOT
  198. {
  199. LIST_ENTRY SnapShotList;
  200. ULONG Flags;
  201. HANDLE SnapShotRootDirectoryHandle;
  202. LARGE_INTEGER Timestamp;
  203. UNICODE_STRING SnapShotName; // "[email protected]"
  204. UNICODE_STRING SnapShotPath;
  205. } SHARE_SNAPSHOT, *PSHARE_SNAPSHOT;
  206. #define SNAPSHOT_NAME_LENGTH (strlen("@GMT-YYYY.MM.DD-HH.MM.SS")+1)*sizeof(WCHAR)
  207. #define SNAPSHOT_NAME_FORMAT L"@GMT-%04d.%02d.%02d-%02d.%02d.%02d"
  208. #define SRV_SNAP_SHARE_NOT_FOUND 1
  209. //
  210. // For each resource that the server shares, a Share Block is
  211. // maintained. The global share list is anchored at SrvShareHashTable. A
  212. // list of active tree connections using a resource is anchored in the
  213. // Share Block.
  214. //
  215. typedef struct _SHARE {
  216. BLOCK_HEADER BlockHeader; // must be first element
  217. LIST_ENTRY TreeConnectList;
  218. LIST_ENTRY GlobalShareList;
  219. HANDLE RootDirectoryHandle;
  220. UNICODE_STRING ShareName;
  221. UNICODE_STRING NtPathName;
  222. UNICODE_STRING DosPathName;
  223. UNICODE_STRING Remark;
  224. ULONG ShareNameHashValue;
  225. union {
  226. struct {
  227. UNICODE_STRING Name;
  228. OEM_STRING OemName;
  229. } FileSystem;
  230. HANDLE hPrinter;
  231. } Type;
  232. ULONG MaxUses;
  233. ULONG CurrentUses;
  234. ULONG CurrentRootHandleReferences; // used for removable devices
  235. LONG QueryNamePrefixLength;
  236. PSECURITY_DESCRIPTOR SecurityDescriptor; // for tree connects
  237. PSECURITY_DESCRIPTOR FileSecurityDescriptor; // file acls on shares
  238. SHARE_TYPE ShareType;
  239. BOOLEAN Removable; // Is the share storage removable?
  240. BOOLEAN SpecialShare;
  241. BOOLEAN IsDfs; // Is this share in the Dfs?
  242. BOOLEAN IsDfsRoot; // Is this share the root of a Dfs?
  243. BOOLEAN PotentialSystemFile; // Are files in this share potentially
  244. // system files?
  245. BOOLEAN IsCatchShare; // Should the SRVCATCH code be active
  246. BOOLEAN UniqueNames; // Are all names unique or are shortnames used?
  247. #ifdef INCLUDE_SMB_IFMODIFIED
  248. BOOLEAN UsnCapable; // does this volume have a USN journal?
  249. #endif
  250. //
  251. // These flags are returned to the client on a tree connect to instruct the client
  252. // how it can cache the files on this share. The server does not interpret these
  253. // flags -- it is the client's responsibility to do the right thing.
  254. //
  255. ULONG CSCState;
  256. #ifdef INCLUDE_SMB_PERSISTENT
  257. BOOLEAN AllowPersistentHandles; // allow persistent handles on this volume?
  258. PERSISTENT_INFO; // persistent info
  259. PVOID PersistentStateFile;
  260. #endif
  261. PSRV_LOCK SecurityDescriptorLock;
  262. LIST_ENTRY SnapShots;
  263. PSRV_LOCK SnapShotLock;
  264. // WCHAR ShareNameData[ShareName.MaximumLength];
  265. // WCHAR NtPathNameData[PathName.MaximumLength];
  266. // WCHAR DosPathNameData[PathName.MaximumLength];
  267. // SECURITY_DESCRIPTOR SecurityDescriptor;
  268. } SHARE, *PSHARE;
  269. //
  270. // For each network that the server uses, an Endpoint Block is
  271. // maintained. An ENDPOINT contains the network name (for
  272. // administrative purposes), the endpoint name (server address), the
  273. // endpoint (file) handle, a pointer to the endpoint object, a pointer
  274. // to the transport provider's device object, and state information.
  275. // The global endpoint list is anchored at SrvEndpointList. A list of
  276. // active connections created using an endpoint is anchored in the
  277. // Endpoint Block.
  278. //
  279. #if SRVDBG29
  280. #define HISTORY_LENGTH 256
  281. typedef struct {
  282. ULONG Operation;
  283. PVOID Connection;
  284. BLOCK_HEADER ConnectionHeader;
  285. } HISTORY, *PHISTORY;
  286. #define UpdateConnectionHistory(_op,_endp,_conn) { \
  287. PHISTORY history = &(_endp)->History[(_endp)->NextHistoryLocation++]; \
  288. if ((_endp)->NextHistoryLocation >= HISTORY_LENGTH) { \
  289. (_endp)->NextHistoryLocation = 0; \
  290. } \
  291. history->Operation = *(PULONG)(_op); \
  292. history->Connection = (_conn); \
  293. if (_conn) { \
  294. history->ConnectionHeader = *(PBLOCK_HEADER)(_conn); \
  295. } \
  296. }
  297. #endif
  298. struct _CONNECTION;
  299. typedef struct _ENDPOINT {
  300. BLOCK_HEADER BlockHeader; // must be first element
  301. //
  302. // List of free connections.
  303. //
  304. LIST_ENTRY FreeConnectionList;
  305. //
  306. // Table of connections. We use a table instead of a list in order
  307. // to speed up lookup of IPX connections based on the SID stored in
  308. // the SMB header.
  309. //
  310. TABLE_HEADER ConnectionTable;
  311. ORDERED_LIST_ENTRY GlobalEndpointListEntry;
  312. //
  313. // Handle and file/device objects for connection-oriented endpoint
  314. // or for connectionless server data socket.
  315. //
  316. HANDLE EndpointHandle;
  317. PFILE_OBJECT FileObject;
  318. PDEVICE_OBJECT DeviceObject;
  319. PULONG IpxMaxPacketSizeArray;
  320. ULONG MaxAdapters;
  321. //
  322. // Handle and file/device objects for connectionless NetBIOS name
  323. // socket.
  324. //
  325. HANDLE NameSocketHandle;
  326. PFILE_OBJECT NameSocketFileObject;
  327. PDEVICE_OBJECT NameSocketDeviceObject;
  328. PDRIVER_DISPATCH FastTdiSend;
  329. PDRIVER_DISPATCH FastTdiSendDatagram;
  330. TDI_ADDRESS_IPX LocalAddress;
  331. ULONG FreeConnectionCount;
  332. ULONG TotalConnectionCount;
  333. //
  334. // Various flags
  335. //
  336. struct {
  337. ULONG IsConnectionless : 1; // connectionless transport?
  338. ULONG NameInConflict : 1; // unable to claim name?
  339. ULONG IsPrimaryName : 1; // set if not an alternate name
  340. ULONG IsNoNetBios : 1; // set if we are direct hosting on a VC
  341. ULONG RemapPipeNames : 1; // set if we are remapping pipe names for clusters
  342. };
  343. WCHAR NetworkAddressData[12 + 1];
  344. UNICODE_STRING NetworkName; // administrative name
  345. UNICODE_STRING TransportName; // e.g., "\Device\Nbf_Elnkii01"
  346. UNICODE_STRING ServerName; // e.g., L"NTSERVER"
  347. ANSI_STRING TransportAddress; // e.g., "NTSERVER "
  348. UNICODE_STRING NetworkAddress;
  349. UNICODE_STRING DomainName; // domain being served by this endpoint
  350. OEM_STRING OemDomainName; // oem version of domain name
  351. // WCHAR NetworkNameData[NetworkName.MaximumLength/2];
  352. // WCHAR TransportNameData[TransportName.MaximumLength/2];
  353. // WCHAR ServerName[ ServerName.MaximumLength/2 ];
  354. // CHAR TransportAddressData[TransportAddress.MaximumLength];
  355. // WCHAR DomainNameData[ DNLEN + 1];
  356. // CHAR OemDomainNameData[ DNLEN+1 ]
  357. BOOLEAN AlternateAddressFormat; // should this endpoint be included when
  358. // enumerating?
  359. #if SRVDBG29
  360. ULONG NextHistoryLocation;
  361. HISTORY History[HISTORY_LENGTH];
  362. #endif
  363. } ENDPOINT, *PENDPOINT;
  364. //
  365. // Size of search hash table (must be a power of 2)
  366. //
  367. #define SEARCH_HASH_TABLE_SIZE 4
  368. typedef struct _HASH_TABLE_ENTRY {
  369. LIST_ENTRY ListHead;
  370. BOOLEAN Dirty;
  371. } HASH_TABLE_ENTRY, *PHASH_TABLE_ENTRY;
  372. //
  373. // When we discover something which is a directory, we place the name
  374. // in this per-connection cache for quick re-use for CheckPath.
  375. //
  376. typedef struct {
  377. BLOCK_HEADER;
  378. LIST_ENTRY ListEntry; // list is linked through this element
  379. UNICODE_STRING DirectoryName; // canonicalized name of this directory
  380. USHORT Tid; // DirectoryName is relative to this tid
  381. ULONG TimeStamp; // Tick count when this element was cached
  382. } CACHED_DIRECTORY, *PCACHED_DIRECTORY;
  383. //
  384. // For each connection (virtual circuit) that is created, a Connection
  385. // Block is maintained. All connections made over a single endpoint are
  386. // linked through that endpoint. Tables of sessions, tree connects, and
  387. // files created using a connection are anchored in the connection
  388. // block.
  389. //
  390. // The Lock field in the connection protects the data in the connection
  391. // and the data structures associated with the connection, such as
  392. // the tree connects and sessions. However, the list of connections
  393. // linked off the endpoint is protected by the endpoint lock, and
  394. // LFCBs and RFCBs associated with a connection are protected by
  395. // the MFCB's lock.
  396. //
  397. typedef struct _PAGED_CONNECTION {
  398. PAGED_HEADER PagedHeader;
  399. //
  400. // List of active transactions
  401. //
  402. LIST_ENTRY TransactionList;
  403. //
  404. // This list is maintained in order of access, so the entry at the top
  405. // of the list is the oldest, the entry at the bottom is the youngest.
  406. //
  407. LIST_ENTRY CoreSearchList;
  408. //
  409. // This information is used to determine whether oplocks and Raw
  410. // I/O's are allowed. This is determined by information obtained by
  411. // querying the transport provider using TDI_QUERY_CONNECTION_INFO.
  412. //
  413. LARGE_INTEGER LinkInfoValidTime;
  414. LARGE_INTEGER Throughput;
  415. LARGE_INTEGER Delay;
  416. //
  417. // Table headers for session, tree connect, and search tables.
  418. //
  419. TABLE_HEADER SessionTable;
  420. TABLE_HEADER TreeConnectTable;
  421. TABLE_HEADER SearchTable;
  422. HANDLE ConnectionHandle;
  423. //
  424. // The number of sessions active on the connection.
  425. //
  426. USHORT CurrentNumberOfSessions;
  427. USHORT CurrentNumberOfCoreSearches;
  428. //
  429. // Hash table for picking out duplicate core searches
  430. //
  431. HASH_TABLE_ENTRY SearchHashTable[SEARCH_HASH_TABLE_SIZE];
  432. //
  433. // A string for the client's name. The Buffer field points to the
  434. // leading slashes (below), the MaximumLength is
  435. // (COMPUTER_NAME_LENGTH + 3) * sizeof(WCHAR), and Length is the
  436. // number of characters in the name that are not blanks *
  437. // sizeof(WHCAR).
  438. //
  439. UNICODE_STRING ClientMachineNameString;
  440. //
  441. // The following two fields make up the client's name in the form
  442. // "\\client ", including a trailing NULL.
  443. //
  444. WCHAR LeadingSlashes[2];
  445. WCHAR ClientMachineName[COMPUTER_NAME_LENGTH+1];
  446. //
  447. // The encryption key obtained from LsaCallAuthenticationPackage.
  448. // This is a per-VC value--any logon on a given VC uses this
  449. // encryption key.
  450. //
  451. UCHAR EncryptionKey[MSV1_0_CHALLENGE_LENGTH];
  452. //
  453. // If we have an NT5 client, this is its build number (if non-zero)
  454. //
  455. ULONG ClientBuildNumber;
  456. //
  457. // If the client has a persistent connection, here's the info for this
  458. // record in the state file.
  459. //
  460. #ifdef INCLUDE_SMB_PERSISTENT
  461. PERSISTENT_INFO; // persistent info
  462. #endif
  463. //
  464. // Have we logged an invalid SMB for this client yet? We use this
  465. // flag to keep a single client from flooding the event log
  466. //
  467. BOOLEAN LoggedInvalidSmb;
  468. #if SRVNTVERCHK
  469. //
  470. // Have we determined that the client's NT build number is too old to
  471. // allow it to connect to this server?
  472. //
  473. BOOLEAN ClientTooOld;
  474. #endif
  475. } PAGED_CONNECTION, *PPAGED_CONNECTION;
  476. #define MAX_SAVED_RESPONSE_LENGTH 100
  477. typedef struct _CONNECTION {
  478. QUEUEABLE_BLOCK_HEADER ; // must be first element
  479. /* start of spin lock cache line */
  480. //
  481. // Per-connection spin lock.
  482. //
  483. KSPIN_LOCK SpinLock;
  484. //
  485. // Points to the endpoint spinlock that guards this connection's
  486. // entry in the endpoint connection table.
  487. //
  488. PKSPIN_LOCK EndpointSpinLock;
  489. //
  490. // This is the WORK_QUEUE we are queueing on, which may not be the
  491. // same as PreferredWorkQueue due to load balancing
  492. //
  493. PWORK_QUEUE CurrentWorkQueue;
  494. //
  495. // A countdown for the number of operations we'll do before we try
  496. // to pick a better processor for this connection
  497. //
  498. ULONG BalanceCount;
  499. //
  500. // Cached Rfcb
  501. //
  502. struct _RFCB *CachedRfcb;
  503. ULONG CachedFid;
  504. //
  505. // BreakIIToNoneJustSent is set when a oplock break II to none is
  506. // sent, and reset whenever an SMB is received. If a raw read
  507. // arrives while this is set, the raw read is rejected.
  508. //
  509. BOOLEAN BreakIIToNoneJustSent;
  510. //
  511. // Raw io enabled
  512. //
  513. BOOLEAN EnableRawIo;
  514. //
  515. // Sid represents the connection's location in the endpoint's
  516. // connection table.
  517. //
  518. USHORT Sid;
  519. // The SidIndex allows us to use all the 16 bits for the index. For
  520. // regular connections this prevents the aliasing problem that can occur
  521. // in using the IXPSID index since the IPX sequence number takes up 4 bits
  522. USHORT SidIndex;
  523. // additional USHORT to satisfy alignment on dword boundaries
  524. USHORT Pad;
  525. //
  526. // Pointer to the endpoint, fileobject, and deviceobject
  527. //
  528. PENDPOINT Endpoint;
  529. PFILE_OBJECT FileObject;
  530. PDEVICE_OBJECT DeviceObject;
  531. //
  532. // The maximum message size we can send over this connection.
  533. //
  534. ULONG MaximumSendSize;
  535. //
  536. // This is the WORK_QUEUE we would prefer to be on, because this
  537. // queue assigns work to the same procesor that is handling the
  538. // adaptor's DPCs
  539. //
  540. PWORK_QUEUE PreferredWorkQueue;
  541. //
  542. // Table header for file table.
  543. //
  544. TABLE_HEADER FileTable;
  545. //
  546. // The SMB dialect chosen for this connection. Used in fsd.
  547. //
  548. SMB_DIALECT SmbDialect;
  549. //
  550. // List of active work items associated with the connection.
  551. //
  552. LIST_ENTRY InProgressWorkItemList;
  553. //
  554. // Stores the time of the last oplock break resp processed. This is
  555. // used to synchronize readraw processing with the oplock break
  556. // processing.
  557. //
  558. ULONG LatestOplockBreakResponse;
  559. //
  560. // The following two fields descibe operations in progress on this
  561. // connection. It is possible that there are multiple oplock breaks
  562. // in progress. Also, there is a brief window when multiple raw
  563. // reads can be active -- after we've sent the response to one raw
  564. // read, but before we've done postprocessing (so it looks like the
  565. // first one is still in progress), we could receive another raw
  566. // read request.
  567. //
  568. // Interaction between the two fields are controlled using
  569. // SrvFsdSpinLock (see the block comment in oplock.c for details).
  570. //
  571. LONG OplockBreaksInProgress;
  572. ULONG RawReadsInProgress;
  573. //
  574. // Are oplocks allowed?
  575. //
  576. BOOLEAN OplocksAlwaysDisabled;
  577. BOOLEAN EnableOplocks;
  578. //
  579. // Is the client coming in over IPX?
  580. //
  581. BOOLEAN DirectHostIpx;
  582. //
  583. // Are security signatures currently active for this connection?
  584. // Security signatures are not supported for Direct Host IPX connections
  585. // and some W9x clients
  586. //
  587. BOOLEAN SmbSecuritySignatureActive;
  588. union {
  589. //
  590. // The following struct of this union holds relevant state
  591. // when the client is connecting over direct host IPX.
  592. // IpxAddress holds the client's IPX address, when the client
  593. // 'connects' over IPX.
  594. //
  595. struct {
  596. USHORT SequenceNumber;
  597. USHORT LastResponseLength;
  598. USHORT LastResponseBufferLength;
  599. USHORT LastUid;
  600. USHORT LastTid;
  601. NTSTATUS LastResponseStatus;
  602. ULONG IpxDuplicateCount;
  603. ULONG IpxDropDuplicateCount;
  604. ULONG StartupTime;
  605. TDI_ADDRESS_IPX IpxAddress;
  606. PVOID LastResponse;
  607. };
  608. //
  609. // This struct holds relevant state when the client is using
  610. // a virtual circuit.
  611. //
  612. struct {
  613. //
  614. // The following fields are used for security signatures.
  615. //
  616. MD5_CTX Md5Context;
  617. ULONG SmbSecuritySignatureIndex;
  618. // If we are unable to allocate a WORK_CONTEXT
  619. // at receive indicate time, the receive is done
  620. // in SrvFsdServiceNeedResourceQueue. Depending
  621. // on the received SMB, we sometimes do not send
  622. // a response SMB. Since the Tdi lookahead data
  623. // is not available when SrvFsdServiceNeedResourceQueue
  624. // is run, we have to remember not to advance the signature
  625. // index for the response.
  626. BOOLEAN NoResponseSignatureIndex;
  627. //
  628. // The following field, if non-zero is the IP address of the client
  629. //
  630. ULONG ClientIPAddress;
  631. };
  632. };
  633. //
  634. // Pointer to paged part of connection block.
  635. //
  636. PPAGED_CONNECTION PagedConnection;
  637. //
  638. // Per-connection interlock.
  639. //
  640. KSPIN_LOCK Interlock;
  641. //
  642. // Quadword align list entries and large ints
  643. //
  644. LIST_ENTRY EndpointFreeListEntry;
  645. //
  646. // A list of deferred oplock work break items. Oplock breaks are
  647. // deferred if a read raw is in progress, or if the server runs
  648. // out of work context blocks, and cannot send the oplock break
  649. // request.
  650. //
  651. LIST_ENTRY OplockWorkList;
  652. //
  653. // List of RFCBs with batch oplocks that have been cached after
  654. // being closed by the client. Count of such RFCBs.
  655. //
  656. LIST_ENTRY CachedOpenList;
  657. ULONG CachedOpenCount;
  658. //
  659. // List of directories which have been recently identified. This is a list of
  660. // CACHED_DIRECTORY entries.
  661. //
  662. LIST_ENTRY CachedDirectoryList;
  663. ULONG CachedDirectoryCount;
  664. //
  665. // Security context handle for the extensible security negotiate buffer.
  666. //
  667. CtxtHandle NegotiateHandle;
  668. //
  669. // The following represent consumer capabilities.
  670. //
  671. ULONG ClientCapabilities;
  672. //
  673. // Per-connection resource.
  674. //
  675. SRV_LOCK Lock;
  676. //
  677. // Lock for dealing with the license server
  678. //
  679. SRV_LOCK LicenseLock;
  680. //
  681. // Oem version of the client machine name string.
  682. //
  683. OEM_STRING OemClientMachineNameString;
  684. //
  685. // Head of singly linked list of cached transactions.
  686. //
  687. SLIST_HEADER CachedTransactionList;
  688. LONG CachedTransactionCount;
  689. //
  690. // The time when the last message was received for this connection
  691. //
  692. ULONG LastRequestTime;
  693. //
  694. // If we are on the OnNeedResourceQueue for a pending recieve, this
  695. // is the amount of data that was indicated to us.
  696. //
  697. ULONG BytesAvailable;
  698. //
  699. // OnNeedResource is true if this connection is on the global need
  700. // recource queue. This happens if it is waiting for a work context
  701. // block to complete a pending receive or an oplock break request.
  702. //
  703. BOOLEAN OnNeedResourceQueue;
  704. //
  705. // NotReusable is set when an operation fails in such a way that the
  706. // server's idea of the connection state may be different than the
  707. // transport's. For example, a server-initiated disconnect failed.
  708. // If we tried to reuse the connection (by returning it from a
  709. // connect indication), the transport would get confused. When
  710. // NotReusable is set, SrvDereferenceConnection frees the connection
  711. // instead of putting it on the endpoint's free list.
  712. //
  713. BOOLEAN NotReusable;
  714. //
  715. // DisconnectPending indicates that a disconect indication has been
  716. // received from the transport. ReceivePending indicates that the
  717. // server could not assign a work item to handle a receive indication.
  718. //
  719. BOOLEAN DisconnectPending;
  720. BOOLEAN ReceivePending;
  721. //
  722. // Oem version of the client name. We need this because we could
  723. // not do unicode operations in the fsd, where we initially get our
  724. // computer name.
  725. //
  726. CHAR OemClientMachineName[COMPUTER_NAME_LENGTH+1];
  727. //
  728. // Information about the client context.
  729. //
  730. UNICODE_STRING ClientOSType;
  731. UNICODE_STRING ClientLanManType;
  732. UCHAR BuiltinSavedResponse[MAX_SAVED_RESPONSE_LENGTH];
  733. // Used to monitor how many work contexts a client is using up
  734. LONG InProgressWorkContextCount;
  735. LONG OperationsPendingOnTransport;
  736. BOOLEAN IsConnectionSuspect;
  737. DISCONNECT_REASON DisconnectReason;
  738. } CONNECTION, *PCONNECTION;
  739. //
  740. // For each session that is created, a Session Block is maintained. All
  741. // sessions created over a single connection are linked through a table
  742. // owned by that connection. A list of files opened using a session can
  743. // be obtained by searching the file table owned by the connection
  744. // block.
  745. //
  746. // This is copied from ntmsv1_0.h
  747. #define MSV1_0_USER_SESSION_KEY_LENGTH 16
  748. typedef struct _SESSION {
  749. //
  750. // *** NOTE: The reference count field in the session block
  751. // header is not used! Instead, the reference count is
  752. // in the NonpagedHeader structure.
  753. //
  754. BLOCK_HEADER BlockHeader;
  755. PNONPAGED_HEADER NonpagedHeader;
  756. ULONG CurrentFileOpenCount; // count of files open on the session
  757. ULONG CurrentSearchOpenCount; // count of searches open on the session
  758. ORDERED_LIST_ENTRY GlobalSessionListEntry;
  759. PCONNECTION Connection;
  760. //
  761. // If clients are using the GSS-style authentication, we query the
  762. // UserHandle for the user and domain names. If they are using
  763. // old-style authentication, we store the names here. In any case,
  764. // code that needs access to the user and/or domain names should
  765. // call SrvGetUserAndDomainName() and SrvReleaseUserAndDomainName()
  766. //
  767. UNICODE_STRING NtUserName;
  768. UNICODE_STRING NtUserDomain;
  769. LARGE_INTEGER StartTime;
  770. LARGE_INTEGER LastUseTime; // for autologoff
  771. LARGE_INTEGER LogOffTime; // for forced logoff
  772. LARGE_INTEGER KickOffTime; // for forced logoff
  773. LARGE_INTEGER LastExpirationMessage; // for forced logoff
  774. LUID LogonId;
  775. CHAR NtUserSessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  776. CHAR LanManSessionKey[MSV1_0_LANMAN_SESSION_KEY_LENGTH];
  777. CtxtHandle UserHandle; // Security handle to this user
  778. USHORT MaxBufferSize; // Consumer's maximum buffer size
  779. USHORT MaxMpxCount; // Actual max multiplexed pending requests
  780. USHORT Uid;
  781. BOOLEAN UsingUppercasePaths; // Must paths be uppercased?
  782. BOOLEAN GuestLogon; // Is the client logged on as a guest?
  783. BOOLEAN EncryptedLogon; // Was an encrypted password sent?
  784. BOOLEAN LogoffAlertSent;
  785. BOOLEAN TwoMinuteWarningSent;
  786. BOOLEAN FiveMinuteWarningSent;
  787. BOOLEAN IsNullSession; // Is client using a null session?
  788. BOOLEAN IsAdmin; // Is this an administrative user?
  789. BOOLEAN IsLSNotified; // Does license server know about this user?
  790. BOOLEAN LogonSequenceInProgress; // Are we in the middle of an extended logon sequence?
  791. BOOLEAN IsSessionExpired; // Do we need to reauthenticate?
  792. HANDLE hLicense; // if( IsLSNotified ) this is License handle
  793. //
  794. // If the client has a persistent connection, here's the info for this
  795. // record in the state file.
  796. //
  797. #ifdef INCLUDE_SMB_PERSISTENT
  798. PERSISTENT_INFO; // persistent info
  799. #endif
  800. #if SRVNTVERCHK
  801. //
  802. // Have we determined that we don't like this client's domain?
  803. //
  804. BOOLEAN ClientBadDomain;
  805. #endif
  806. //CHAR UserNameBuffer[UserName.MaximumLength];
  807. } SESSION, *PSESSION;
  808. //
  809. // For each tree connect that is made, a Tree Connect Block is
  810. // maintained. All tree connects made over a single connection are
  811. // linked through a table owned by that connection. All tree connects
  812. // made to a single shared resource are linked through that share block.
  813. // A list of files opened using a tree connect can be obtained by
  814. // searching the file table owned by the connection block.
  815. //
  816. typedef struct _TREE_CONNECT {
  817. //
  818. // *** NOTE: The reference count field in the tree connect block
  819. // header is not used! Instead, the reference count is
  820. // in the NonpagedHeader structure.
  821. //
  822. BLOCK_HEADER BlockHeader;
  823. PNONPAGED_HEADER NonpagedHeader;
  824. PCONNECTION Connection;
  825. PSESSION Session;
  826. PSHARE Share;
  827. ORDERED_LIST_ENTRY GlobalTreeConnectListEntry;
  828. ULONG CurrentFileOpenCount;
  829. LIST_ENTRY ShareListEntry;
  830. LIST_ENTRY PrintFileList; // only if print share
  831. LARGE_INTEGER StartTime;
  832. UNICODE_STRING ServerName;
  833. BOOLEAN RemapPipeNames;
  834. USHORT Tid;
  835. } TREE_CONNECT, *PTREE_CONNECT;
  836. //
  837. // Master File Control Block (MFCB) -- one per named file that is open
  838. // at least once. Used to support compatibility mode and oplocks.
  839. //
  840. // Local File Control Block (LFCB) -- one for each local open instance.
  841. // Represents local file object/handle. There may be multiple
  842. // LFCBs linked to a single MFCB.
  843. //
  844. // Remote File Control Block (RFCB) -- one for each remote open instance.
  845. // Represents remote FID. There is usually one RFCB per LFCB, but
  846. // multiple compatibility mode RFCBs may be linked to a single LFCB.
  847. // Multiple remote FCB opens for a single file from a single session
  848. // are folded into one RFCB, because old DOS redirectors only send
  849. // one close.
  850. //
  851. //
  852. // For each disk file that is open, a Master File Control Block (MFCB)
  853. // is maintained. If a given file is open multiple times, there is one
  854. // MFCB for the file and multiple LFCBs, one for each local open
  855. // instance. All MFCBs are linked into the global Master File Table.
  856. // The MFCB has a list of the LFCBs representing open instances for the
  857. // file.
  858. //
  859. typedef struct _NONPAGED_MFCB {
  860. union {
  861. //
  862. // When NONPAGED_MFCB structures are freed, they may be placed
  863. // on the WORK_QUEUE's MfcbFreeList to avoid unnecessary Nonpaged
  864. // pool activity. SingleListEntry is used for the linkage.
  865. //
  866. SINGLE_LIST_ENTRY SingleListEntry;
  867. struct {
  868. ULONG Type;
  869. PVOID PagedBlock;
  870. //
  871. // We must serialize opens to the same file, since 2 concurrent opens
  872. // may be compatibility mode opens. This lock also protects all data
  873. // in this MFCB and the LFCBs and RFCBs associated with this MFCB.
  874. //
  875. SRV_LOCK Lock;
  876. };
  877. };
  878. LARGE_INTEGER OpenFileSize;
  879. ULONG OpenFileAttributes;
  880. } NONPAGED_MFCB, *PNONPAGED_MFCB;
  881. typedef struct _MFCB {
  882. //
  883. // *** NOTE: The reference count field in the mfcb block
  884. // header is not used! Instead, the reference count is
  885. // in the NonpagedHeader structure.
  886. //
  887. BLOCK_HEADER BlockHeader; // must be first element
  888. PNONPAGED_MFCB NonpagedMfcb;
  889. //
  890. // All LFCBs for a given named file are linked to the parent MFCB.
  891. //
  892. LIST_ENTRY LfcbList;
  893. //
  894. // The count of active RFCB for this MFCB. This is used to coordinate
  895. // compatibility opens with non-compatibility mode opens.
  896. //
  897. ULONG ActiveRfcbCount;
  898. //
  899. // The fully qualified name of the file is appended to the MFCB.
  900. // The FileName field is a descriptor for the name.
  901. //
  902. UNICODE_STRING FileName;
  903. //
  904. // Mfcbs are linked into the MfcbHashTable by MfcbHashTableEntry
  905. //
  906. LIST_ENTRY MfcbHashTableEntry;
  907. //
  908. // FileNameHashValue is a hash value derived from the upper case
  909. // version of FileName. It is used to speed up name comparisons, and to
  910. // locate the hash entry
  911. //
  912. ULONG FileNameHashValue;
  913. //
  914. // CompatibilityOpen indicates whether the file is open in
  915. // compatibility mode.
  916. //
  917. BOOLEAN CompatibilityOpen;
  918. //
  919. // Timestamp for SnapShot opens
  920. //
  921. LARGE_INTEGER SnapShotTime;
  922. #if SRVCATCH
  923. BOOLEAN SrvCatch;
  924. #endif
  925. // WCHAR FileNameData[FileName.MaximumLength/2];
  926. } MFCB, *PMFCB;
  927. //
  928. // The MFCBs are all linked into the master MFCB hash table.
  929. //
  930. typedef struct {
  931. LIST_ENTRY List; // the list of MFCBs in this bucket
  932. PSRV_LOCK Lock; // protects this bucket's list
  933. } MFCBHASH, *PMFCBHASH;
  934. //
  935. // For each instance of a local file open, a Local File Control Block
  936. // (LFCB) is maintained. All LFCBs for a particular named file are
  937. // linked through the MFCB for that file.
  938. //
  939. // LFCBs contain information that is specific to the local open, such
  940. // as the file handle and a pointer to the file object. The LFCB also
  941. // contains other information that is common to all child RFCBs, such
  942. // as pointers to the owning connection and tree connect.
  943. //
  944. //
  945. typedef struct _LFCB {
  946. union {
  947. BLOCK_HEADER BlockHeader; // must be first element
  948. SINGLE_LIST_ENTRY SingleListEntry; // used when LFCB is freed
  949. };
  950. //
  951. // Multiple remote opens of a file are folded into a single local
  952. // open by linking the RFCBs to the parent LFCB.
  953. //
  954. LIST_ENTRY RfcbList;
  955. //
  956. // The number of associated active RFCBs.
  957. //
  958. ULONG HandleCount;
  959. //
  960. // LFCBs are linked into their MFCB's open file list.
  961. //
  962. PMFCB Mfcb;
  963. LIST_ENTRY MfcbListEntry;
  964. //
  965. // Connection, Session, and TreeConnect are referenced pointers to
  966. // the respective "owning" blocks.
  967. //
  968. PCONNECTION Connection;
  969. PSESSION Session;
  970. PTREE_CONNECT TreeConnect;
  971. //
  972. // GrantedAccess is the access obtained when the file was opened.
  973. // For a compatibility mode open, this is the maximum access
  974. // available to the client; individual opens may have less access.
  975. //
  976. ACCESS_MASK GrantedAccess;
  977. //
  978. // FileHandle is a handle to the open file. FileObject is a
  979. // referenced pointer. DeviceObject is NOT a referenced pointer;
  980. // the reference to the file object prevents the device object from
  981. // going away.
  982. //
  983. HANDLE FileHandle;
  984. PFILE_OBJECT FileObject;
  985. PDEVICE_OBJECT DeviceObject;
  986. //
  987. // FileMode tracks whether writethrough is enabled for this file
  988. // object.
  989. ULONG FileMode;
  990. //
  991. // The job ID of a print job corresponding to the opened file.
  992. // This is only used for print file opens.
  993. //
  994. ULONG JobId;
  995. //
  996. // Cache these hot-path entry points.
  997. //
  998. PFAST_IO_READ FastIoRead;
  999. PFAST_IO_WRITE FastIoWrite;
  1000. PFAST_IO_LOCK FastIoLock;
  1001. PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
  1002. PFAST_IO_MDL_READ MdlRead;
  1003. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  1004. PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
  1005. PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
  1006. PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
  1007. PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
  1008. PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
  1009. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  1010. //
  1011. // CompatibilityOpen indicates whether the file is open in
  1012. // compatibility mode.
  1013. //
  1014. BOOLEAN CompatibilityOpen;
  1015. //
  1016. // Has this file been modified by any clients? Used to determine when
  1017. // we should write out USN close records on file close.
  1018. //
  1019. #ifdef INCLUDE_SMB_IFMODIFIED
  1020. BOOLEAN FileUpdated;
  1021. #endif
  1022. } LFCB, *PLFCB;
  1023. //
  1024. // For each instance of a remote file open, a Remote File Control Block
  1025. // (RFCB) is maintained. The RFCB points to the LFCB that contains the
  1026. // local file handle. Normally RFCBs and LFCBs exist in one-to-one
  1027. // correspondence, but multiple compatibility mode opens are folded into
  1028. // a single local open, so that the server can enforce the appropriate
  1029. // sharing rules.
  1030. //
  1031. // RFCBs contain information that is specific to the remote open, such
  1032. // as the assigned FID, the PID of the creator, the granted access mask,
  1033. // and the current file position.
  1034. //
  1035. // All RFCBs for a single connection are linked through a table owned by
  1036. // that connection; the FID assigned to the RFCB represents an index
  1037. // into the file table. Pointers to the owning connection and tree
  1038. // connect can be found in the LFCB, which is pointed to by the RFCB. A
  1039. // list of files opened through a given tree connect can be obtained by
  1040. // searching the owning connection's file table for RFCBs whose parent
  1041. // LFCBs point to the tree connect.
  1042. //
  1043. #ifdef SLMDBG
  1044. #define SLMDBG_CLOSE 1
  1045. #define SLMDBG_RENAME 2
  1046. #define SLMDBG_TRACE_COUNT 32
  1047. #define SLMDBG_TRACE_DATA 32
  1048. typedef struct _RFCB_TRACE {
  1049. UCHAR Command;
  1050. UCHAR Flags;
  1051. TIME Time;
  1052. union {
  1053. struct {
  1054. ULONG Offset;
  1055. ULONG Length;
  1056. } ReadWrite;
  1057. struct {
  1058. ULONG Offset;
  1059. ULONG Length;
  1060. } LockUnlock;
  1061. } Data;
  1062. } RFCB_TRACE, *PRFCB_TRACE;
  1063. #endif
  1064. //
  1065. // WRITE_MPX_CONTEXT holds context associated with an active Write Block
  1066. // Multiplexed sequence.
  1067. //
  1068. // !!! This structure is probably big enough to be worth putting
  1069. // outside the RFCB.
  1070. //
  1071. #define MAX_GLOM_RUN_COUNT 8
  1072. typedef struct _WRITE_MPX_RUN {
  1073. USHORT Offset;
  1074. USHORT Length;
  1075. } WRITE_MPX_RUN, *PWRITE_MPX_RUN;
  1076. typedef struct _WRITE_MPX_CONTEXT {
  1077. //
  1078. // ReferenceCount counts the number of Write Mpx SMBs that are
  1079. // currently being processed. When this count goes to zero, and
  1080. // we have received the sequenced command that ends the current
  1081. // mux, we send the response. This method is needed to ensure
  1082. // that we don't process the mux SMBs out-of-order, which leads
  1083. // to performance problems, and even worse, data corruption,
  1084. // thanks to the mask-shifting method used by the Snowball redir.
  1085. //
  1086. ULONG ReferenceCount;
  1087. //
  1088. // Mask holds the logical OR of the masks received in multiplexed
  1089. // write requests. When an IPX client sends the last block of write
  1090. // mpx data, we send back MpxMask to indicate whether we lost any
  1091. // frames.
  1092. //
  1093. ULONG Mask;
  1094. //
  1095. // FileObject is a copy of the file object pointer from the LFCB.
  1096. //
  1097. PFILE_OBJECT FileObject;
  1098. //
  1099. // Mid holds the MID of the current multiplexed write. PreviousMid
  1100. // hold the MID of the previous one. This needs to be retained in
  1101. // order to deal with duplicated write mux SMBs -- if a duplicate
  1102. // SMB arrives AFTER the first SMB of the next write mux (with a new
  1103. // MID), we need to know to toss it, not kill the new write mux.
  1104. //
  1105. USHORT Mid;
  1106. USHORT PreviousMid;
  1107. //
  1108. // SequenceNumber holds the sequence number given in the last
  1109. // request of the mux. This needs to be retained because we
  1110. // may be simultaneously processing previous parts of the mux
  1111. // when we detect that we've received the sequenced comand.
  1112. //
  1113. USHORT SequenceNumber;
  1114. //
  1115. // Glomming is set if the current write mux series is being glommed
  1116. // into one large write.
  1117. //
  1118. // GlomPending is set when the indication for the first packet of
  1119. // a new write mux occurs. It is cleared when the FSP is done
  1120. // preparing the glomming operation. While GlomPending is set,
  1121. // subsequent packets of the write mux are queued to GlomDelayList.
  1122. //
  1123. BOOLEAN Glomming;
  1124. BOOLEAN GlomPending;
  1125. LIST_ENTRY GlomDelayList;
  1126. ULONG StartOffset;
  1127. USHORT Length;
  1128. BOOLEAN GlomComplete;
  1129. //
  1130. // MpxGlommingAllowed is set when the underlying file system
  1131. // supports MDL write.
  1132. //
  1133. BOOLEAN MpxGlommingAllowed;
  1134. PMDL MdlChain;
  1135. ULONG NumberOfRuns;
  1136. WRITE_MPX_RUN RunList[MAX_GLOM_RUN_COUNT];
  1137. } WRITE_MPX_CONTEXT, *PWRITE_MPX_CONTEXT;
  1138. #define NO_OPLOCK_BREAK_IN_PROGRESS ((UCHAR)-1)
  1139. typedef struct _PAGED_RFCB {
  1140. PAGED_HEADER PagedHeader;
  1141. //
  1142. // RFCBs are linked into their parent LFCB's compatibility open
  1143. // list.
  1144. //
  1145. LIST_ENTRY LfcbListEntry;
  1146. //
  1147. // Information about the last lock attempt by the client that failed.
  1148. //
  1149. LARGE_INTEGER LastFailingLockOffset;
  1150. //
  1151. // Current oplock break timeout.
  1152. //
  1153. LARGE_INTEGER OplockBreakTimeoutTime;
  1154. //
  1155. // FcbOpenCount indicates how many remote FCB opens this RFCB
  1156. // represents. (Whether an RFCB represents a compatibility mode
  1157. // open can be determined by looking at the LFCB.)
  1158. //
  1159. // *** Note that FCB opens are treated similarly to compatibility
  1160. // mode opens. However, soft compatibility maps compatibility
  1161. // opens into regular opens, but it does not change an FCB open
  1162. // into a non-FCB open. So it is possible to have an FCB open
  1163. // that is not a compatibility mode open.
  1164. //
  1165. CLONG FcbOpenCount;
  1166. //
  1167. // Per-file context for a direct host IPX smart card, if we have one.
  1168. // The smart card is willing to handle the read operations for this file if
  1169. // IpxSmartCardContext is not NULL.
  1170. //
  1171. PVOID IpxSmartCardContext;
  1172. //
  1173. // list of outstanding byte locks we have for this RFCB
  1174. //
  1175. #ifdef INCLUDE_SMB_PERSISTENT
  1176. LIST_ENTRY ByteRangeLocks;
  1177. //
  1178. // If the client has a persistent connection, here's the info for this
  1179. // record in the state file.
  1180. //
  1181. PERSISTENT_INFO; // persistent info
  1182. #endif
  1183. } PAGED_RFCB, *PPAGED_RFCB;
  1184. typedef struct _RFCB {
  1185. //
  1186. // The list entry in the RFCB's block header is used to queue the
  1187. // RFCB for oplock processing to the nonblocking worker thread work
  1188. // queue, which also contains work context blocks.
  1189. //
  1190. // *** Note that this is an unnamed field, so that its elements can
  1191. // can be referenced directly. The field names defined in
  1192. // QUEUEABLE_BLOCK_HEADER cannot be used elsewhere in this
  1193. // block.
  1194. //
  1195. QUEUEABLE_BLOCK_HEADER ; // must be first element
  1196. /* start of spin lock cache line */
  1197. //
  1198. // These booleans indicate whether we've already been granted
  1199. // read/write/lock access, thus saving a few instructions on every
  1200. // read/write/lock. These are checked during the file open.
  1201. //
  1202. BOOLEAN ReadAccessGranted; // TRUE, if read access in granted
  1203. BOOLEAN WriteAccessGranted; // TRUE, if write access is granted
  1204. BOOLEAN LockAccessGranted; // TRUE, if lock access is granted
  1205. BOOLEAN UnlockAccessGranted; // TRUE, if unlock access is granted
  1206. BOOLEAN AppendAccessGranted; // TRUE, if append access is granted
  1207. //
  1208. // CurrentPosition maintains the file position after the last Read,
  1209. // Write, or Seek by the client. This field is needed only to
  1210. // support relative Seeks. Since clients that use relative seeks only
  1211. // need 32-bits of file position, this field is maintained as a ULONG.
  1212. //
  1213. ULONG CurrentPosition;
  1214. //
  1215. // Type of this share. Accessed in the fsd.
  1216. //
  1217. SHARE_TYPE ShareType;
  1218. //
  1219. // The connection pointer is copied from the LFCB so that we can
  1220. // find the connection at DPC level (the LFCB is paged, as is the
  1221. // pointer to the LFCB in PagedRfcb).
  1222. //
  1223. PCONNECTION Connection;
  1224. //
  1225. // The LFCB is used to find the file handle, file object, etc.
  1226. //
  1227. PLFCB Lfcb;
  1228. //
  1229. // MpxGlommingAllowed is set when the underlying file system
  1230. // supports MDL write.
  1231. //
  1232. BOOLEAN MpxGlommingAllowed;
  1233. //
  1234. // The following two booleans describe the read mode, and blocking
  1235. // mode of a named pipe.
  1236. //
  1237. BOOLEAN BlockingModePipe; // TRUE = Blocking, FALSE = Nonblocking
  1238. BOOLEAN ByteModePipe; // TRUE = Byte mode, FALSE = Message mode
  1239. //
  1240. // Indicates whether this file has been written to.
  1241. //
  1242. BOOLEAN WrittenTo;
  1243. /* end of spin lock cache line */
  1244. //
  1245. // RawWriteSerializationList holds works items that have been queued
  1246. // pending completion of a raw write. When the raw write count is
  1247. // decremented to 0, this list is flushed by restarting all queued
  1248. // work items.
  1249. //
  1250. LIST_ENTRY RawWriteSerializationList;
  1251. //
  1252. // fid << 16. Used for key computations.
  1253. //
  1254. ULONG ShiftedFid;
  1255. //
  1256. // RawWriteCount counts the number of active raw writes. This is
  1257. // used to prevent the file handle from being closed while raw
  1258. // writes are in progress. If Raw writes are in progress when the
  1259. // close happens, we defer the cleanup until the rawwritecount goes
  1260. // to zero.
  1261. //
  1262. ULONG RawWriteCount;
  1263. //
  1264. // SavedError retains the error code when a raw read or a raw write
  1265. // in writebehind mode gets an error. The next access to the file
  1266. // will receive an error indication.
  1267. //
  1268. NTSTATUS SavedError;
  1269. //
  1270. // NumberOfLocks is the count of locks currently on the file.
  1271. // It is here to support the File APis and RFCB cacheing -- you can't
  1272. // cache an RFCB if it has locks in it.
  1273. //
  1274. LONG NumberOfLocks;
  1275. //
  1276. // Fid is the file ID assigned to the file and returned to the
  1277. // client. Pid is the process ID given by the client when the file
  1278. // was opened. Tid is a copy of the parent tree connect's Tid
  1279. // field. Uid is used to ensure that the client using a file handle
  1280. // is the same one that opened the file.
  1281. //
  1282. USHORT Fid;
  1283. USHORT Pid;
  1284. USHORT Tid;
  1285. USHORT Uid;
  1286. //
  1287. // WriteMpx is a WRITE_MPX_CONTEXT structure. It retains context
  1288. // about multiplexed write operations. This structure is not used
  1289. // on connectionless sessions.
  1290. //
  1291. WRITE_MPX_CONTEXT WriteMpx;
  1292. //
  1293. // FileMode tracks whether writethrough is enabled for this file
  1294. // object.
  1295. ULONG FileMode;
  1296. //
  1297. // MFCB points to the Master File Control Block for this file.
  1298. //
  1299. PMFCB Mfcb;
  1300. //
  1301. // Oplock information. The oplock IRP currently in progress, etc.
  1302. // The list entry for queueing the RFCB for oplock break processing
  1303. // is located in the block header.
  1304. //
  1305. PIRP Irp;
  1306. BOOLEAN OnOplockBreaksInProgressList;
  1307. //
  1308. // The oplock level to change to, if there is an oplock break
  1309. // in progress. Otherwise it is always NO_OPLOCK_BREAK_IN_PROGRESS.
  1310. //
  1311. UCHAR NewOplockLevel;
  1312. //
  1313. // This boolean indicates whether or an oplock granted open response
  1314. // need to be sent for this RFCB. If it is FALSE, and an oplock break
  1315. // request needs to be sent, the request must be deferred until after
  1316. // sending the open response.
  1317. //
  1318. // Access to these fields is synchronized using the MFCB lock.
  1319. //
  1320. BOOLEAN OpenResponseSent;
  1321. BOOLEAN DeferredOplockBreak;
  1322. //
  1323. // Pointer to the paged portion of the rfcb
  1324. //
  1325. PPAGED_RFCB PagedRfcb;
  1326. //
  1327. // CachedOpen is set if the RFCB has been cached after being
  1328. // closed by the client.
  1329. //
  1330. LIST_ENTRY CachedOpenListEntry;
  1331. BOOLEAN CachedOpen;
  1332. //
  1333. // See if this rfcb can be cached.
  1334. //
  1335. BOOLEAN IsCacheable;
  1336. //
  1337. // See if the file was accessed in the last scavenger update period.
  1338. // (This is used to update the session last access time).
  1339. //
  1340. BOOLEAN IsActive;
  1341. //
  1342. // Is it ok for us to do MPX writes to this RFCB?
  1343. //
  1344. BOOLEAN MpxWritesOk;
  1345. //
  1346. // Is this file a persistent handle?
  1347. //
  1348. #ifdef INCLUDE_SMB_PERSISTENT
  1349. BOOLEAN PersistentHandle;
  1350. #endif
  1351. //
  1352. // This event is used when the server needs to request an oplock II
  1353. // when the initial oplock request fails.
  1354. //
  1355. PKEVENT RetryOplockRequest;
  1356. //
  1357. // All RFCBs in the server are stored in a global list to support
  1358. // NetFileEnum. This field contains the LIST_ENTRY for the RFCB in
  1359. // the global list and a resume handle to support resuming
  1360. // enumerations.
  1361. //
  1362. ORDERED_LIST_ENTRY GlobalRfcbListEntry;
  1363. //
  1364. // GrantedAccess is the access allowed through this open. This
  1365. // GrantedAccess may allow less access than that given in the parent
  1366. // LFCB for compatibility mode opens.
  1367. //
  1368. ACCESS_MASK GrantedAccess;
  1369. //
  1370. // ShareAccess is the file sharing access specified when the file
  1371. // was opened.
  1372. //
  1373. ULONG ShareAccess;
  1374. //
  1375. // Current oplock state.
  1376. //
  1377. OPLOCK_STATE OplockState;
  1378. //
  1379. // Is it ok for us to do MPX reads to this RFCB?
  1380. //
  1381. BOOLEAN MpxReadsOk;
  1382. #ifdef SRVCATCH
  1383. BOOLEAN SrvCatch;
  1384. #endif
  1385. #ifdef SRVDBG_RFCBHIST
  1386. UCHAR HistoryIndex;
  1387. ULONG History[256];
  1388. #endif
  1389. #ifdef SLMDBG
  1390. ULONG NextTrace;
  1391. ULONG TraceWrapped;
  1392. ULONG WriteCount;
  1393. ULONG OperationCount;
  1394. RFCB_TRACE Trace[SLMDBG_TRACE_COUNT];
  1395. #endif
  1396. } RFCB, *PRFCB;
  1397. #ifdef SRVDBG_RFCBHIST
  1398. VOID UpdateRfcbHistory( PRFCB Rfcb, ULONG Event );
  1399. #else
  1400. #define UpdateRfcbHistory(_rfcb,_event)
  1401. #endif
  1402. #ifdef INCLUDE_SMB_PERSISTENT
  1403. typedef struct _BYTELOCK {
  1404. BLOCK_HEADER BlockHeader;
  1405. //
  1406. // Locks are linked into their parent RFCB's open list.
  1407. //
  1408. LIST_ENTRY RfcbListEntry;
  1409. PRFCB Rfcb;
  1410. //
  1411. // Information about the lock.
  1412. //
  1413. LARGE_INTEGER LockOffset;
  1414. LARGE_INTEGER LockLength;
  1415. BOOLEAN Exclusive;
  1416. //
  1417. // If the client has a persistent connection, here's the info for this
  1418. // record in the state file.
  1419. //
  1420. PERSISTENT_INFO; // persistent info
  1421. } BYTELOCK, *PBYTELOCK;
  1422. #endif
  1423. #ifdef SLMDBG
  1424. NTSTATUS
  1425. SrvValidateSlmStatus (
  1426. IN HANDLE StatusFile,
  1427. IN struct _WORK_CONTEXT *WorkContext,
  1428. OUT PULONG FileOffsetOfInvalidData
  1429. );
  1430. VOID
  1431. SrvReportCorruptSlmStatus (
  1432. IN PUNICODE_STRING StatusFile,
  1433. IN NTSTATUS Status,
  1434. IN ULONG Offset,
  1435. IN ULONG Operation,
  1436. IN PSESSION Session
  1437. );
  1438. VOID
  1439. SrvReportSlmStatusOperations (
  1440. IN PRFCB Rfcb,
  1441. IN BOOLEAN Force
  1442. );
  1443. VOID
  1444. SrvDisallowSlmAccess (
  1445. IN PUNICODE_STRING StatusFile,
  1446. IN HANDLE RootDirectory
  1447. );
  1448. VOID
  1449. SrvDisallowSlmAccessA (
  1450. IN PANSI_STRING StatusFile,
  1451. IN HANDLE RootDirectory
  1452. );
  1453. BOOLEAN
  1454. SrvIsSlmAccessDisallowed (
  1455. IN PUNICODE_STRING StatusFile,
  1456. IN HANDLE RootDirectory
  1457. );
  1458. BOOLEAN
  1459. SrvIsSlmStatus (
  1460. IN PUNICODE_STRING StatusFile
  1461. );
  1462. BOOLEAN
  1463. SrvIsTempSlmStatus (
  1464. IN PUNICODE_STRING StatusFile
  1465. );
  1466. #endif
  1467. //
  1468. // Each incoming (request) and outgoing (response) buffer is represented
  1469. // by a BUFFER structure. This descriptor describes the size of the
  1470. // buffer, its address, and a full and partial MDL that may be used
  1471. // to describe the buffer.
  1472. //
  1473. // *** The descriptor contains a pointer to the real buffer, which is
  1474. // normally allocated out of nonpaged pool. The descriptor itself
  1475. // may be allocated out of the FSP heap, although receive buffer
  1476. // descriptors are allocated from nonpaged pool, so the FSD
  1477. // read/write code can access them.
  1478. //
  1479. typedef struct _BUFFER {
  1480. PVOID Buffer;
  1481. CLONG BufferLength; // Length allocated to buffer
  1482. PMDL Mdl; // MDL describing entire buffer
  1483. PMDL PartialMdl; // Partial MDL for read/write/etc.
  1484. CLONG DataLength; // Length of data currently in buffer
  1485. ULONG Reserved; // Pad to quadword
  1486. } BUFFER, *PBUFFER;
  1487. #define MIN_SEND_SIZE 512
  1488. #define MAX_PARTIAL_BUFFER_SIZE 65535
  1489. //
  1490. // For each search request that is started (Find First or core Search),
  1491. // a search block is allocated. This is used to hold enough information
  1492. // that the search may be quickly restarted or rewound.
  1493. //
  1494. // Ths InUse field is protected by Connection->Lock--this lock must be
  1495. // held when accessing this field of the search block.
  1496. //
  1497. typedef struct _SEARCH {
  1498. BLOCK_HEADER BlockHeader;
  1499. HANDLE DirectoryHandle;
  1500. ULONG LastFileIndexReturned;
  1501. UNICODE_STRING SearchName;
  1502. UNICODE_STRING LastFileNameReturned;
  1503. LARGE_INTEGER LastUseTime;
  1504. LIST_ENTRY LastUseListEntry;
  1505. LIST_ENTRY HashTableEntry;
  1506. PSESSION Session;
  1507. PTREE_CONNECT TreeConnect;
  1508. ULONG SearchStorageType;
  1509. struct _DIRECTORY_CACHE *DirectoryCache;
  1510. USHORT NumberOfCachedFiles;
  1511. USHORT SearchAttributes;
  1512. SHORT CoreSequence;
  1513. SHORT TableIndex;
  1514. USHORT HashTableIndex;
  1515. USHORT Pid;
  1516. USHORT Flags2;
  1517. BOOLEAN Wildcards;
  1518. BOOLEAN InUse;
  1519. // WCHAR SearchNameData[SearchName.MaximumLength/2];
  1520. } SEARCH, *PSEARCH;
  1521. //
  1522. // Each pending transaction request (Transaction, Transaction2, and
  1523. // Ioctl) has a transaction block. It records information that is
  1524. // needed to stage input and output data across multiple SMBs.
  1525. //
  1526. // *******************************************************************
  1527. // * *
  1528. // * DO NOT CHANGE THIS STRUCTURE WITHOUT CHANGING THE CORRESPONDING *
  1529. // * STRUCTURE IN net\inc\xstypes.h! *
  1530. // * *
  1531. // *******************************************************************
  1532. //
  1533. typedef struct _TRANSACTION {
  1534. //
  1535. // *** NOTE: The reference count field in the transaction block
  1536. // header is not used! Instead, the reference count is
  1537. // in the NonpagedHeader structure.
  1538. //
  1539. BLOCK_HEADER BlockHeader;
  1540. PNONPAGED_HEADER NonpagedHeader;
  1541. //
  1542. // The connection, session, and tree connect pointers are referenced
  1543. // pointers if and only if Inserted is TRUE. Otherwise, they are
  1544. // simply copies of the work context block's pointers.
  1545. //
  1546. PCONNECTION Connection;
  1547. PSESSION Session;
  1548. PTREE_CONNECT TreeConnect;
  1549. LIST_ENTRY ConnectionListEntry;
  1550. UNICODE_STRING TransactionName; // not used if Transaction2
  1551. ULONG StartTime;
  1552. ULONG Timeout;
  1553. CLONG cMaxBufferSize; // if needed we stash this here
  1554. //
  1555. // The following pointers point into either the trailing portion
  1556. // of the transaction block or the last received SMB.
  1557. //
  1558. // *** ALL information in buffers pointed to by these parameters
  1559. // should ALWAYS be in little-endian format. Always use the
  1560. // macros defined in srvmacro.h (SmbGetAlignedUshort, etc.) to
  1561. // read from or write into these buffers.
  1562. //
  1563. PSMB_USHORT InSetup;
  1564. PSMB_USHORT OutSetup;
  1565. PCHAR InParameters;
  1566. PCHAR OutParameters;
  1567. PCHAR InData;
  1568. PCHAR OutData;
  1569. //
  1570. // *** Data in all the remaining fields of the transaction block are
  1571. // in native format, so no special macros should be used, except
  1572. // when copying data to/from the actual SMB.
  1573. //
  1574. CLONG SetupCount; // amount received (all in first buffer)
  1575. CLONG MaxSetupCount; // max that can be sent back
  1576. CLONG ParameterCount; // amount received or sent
  1577. CLONG TotalParameterCount; // amount expected
  1578. CLONG MaxParameterCount; // max that can be sent back
  1579. CLONG DataCount; // amount received or sent
  1580. CLONG TotalDataCount; // amount expected
  1581. CLONG MaxDataCount; // max that can be sent back
  1582. USHORT Category; // Ioctl function category
  1583. USHORT Function; // Nt Transaction or ioctl function code
  1584. //
  1585. // The SMB data and paramters may or may not be copied to the
  1586. // transaction buffer. If they are not copied, they are read
  1587. // and/or written directly into an SMB buffer.
  1588. //
  1589. // Setup words are never copied.
  1590. //
  1591. BOOLEAN InputBufferCopied; // if FALSE input buffer is in SMB
  1592. BOOLEAN OutputBufferCopied; // if FALSE output buffer is in SMB
  1593. BOOLEAN OutDataAllocated; // if TRUE OutData buffer has been separately allocated
  1594. USHORT Flags;
  1595. USHORT Tid;
  1596. USHORT Pid;
  1597. USHORT Uid;
  1598. USHORT OtherInfo;
  1599. HANDLE FileHandle; // Used only for CallNamedPipe processing
  1600. PFILE_OBJECT FileObject; // Used only for CallNamedPipe processing
  1601. //
  1602. // The following fields are used while the response is being sent.
  1603. //
  1604. CLONG ParameterDisplacement;
  1605. CLONG DataDisplacement;
  1606. //
  1607. // PipeRequest is set for named pipe transactions. RemoteApiRequest
  1608. // is set for remote API requests.
  1609. //
  1610. BOOLEAN PipeRequest;
  1611. BOOLEAN RemoteApiRequest;
  1612. //
  1613. // The following boolean is TRUE if the transaction has been inserted
  1614. // on the connection's transaction list. It will be FALSE when the
  1615. // transaction can be handled using a single SMB exchange.
  1616. //
  1617. BOOLEAN Inserted;
  1618. //
  1619. // This boolean is TRUE if the transaction is in the state where
  1620. // it is waiting for a transaction secondary request to come in
  1621. // to acknowledge the receipt of the previous piece of a multipiece
  1622. // transaction response.
  1623. //
  1624. BOOLEAN MultipieceIpxSend;
  1625. //
  1626. // This boolean is TRUE if all of the transaction data has been received
  1627. // and the transaction has been scheduled for execution.
  1628. //
  1629. BOOLEAN Executing;
  1630. //
  1631. // The main part of the transaction block is trailed by transaction
  1632. // name data and possibly setup words and parameter and data bytes.
  1633. //
  1634. } TRANSACTION, *PTRANSACTION;
  1635. //
  1636. // Each pending blocking open request has a BLOCKING_OPEN block. This
  1637. // block contains all the info needed to make the call into the file
  1638. // system.
  1639. typedef struct _BLOCKING_OPEN {
  1640. BLOCK_HEADER BlockHeader;
  1641. PMFCB Mfcb;
  1642. PIO_STATUS_BLOCK IoStatusBlock;
  1643. OBJECT_ATTRIBUTES ObjectAttributes;
  1644. UNICODE_STRING RelativeName;
  1645. PVOID EaBuffer;
  1646. CLONG EaLength;
  1647. LARGE_INTEGER AllocationSize;
  1648. ULONG DesiredAccess;
  1649. ULONG FileAttributes;
  1650. ULONG ShareAccess;
  1651. ULONG CreateDisposition;
  1652. ULONG CreateOptions;
  1653. BOOLEAN CaseInsensitive;
  1654. } BLOCKING_OPEN, *PBLOCKING_OPEN;
  1655. //
  1656. // SRV_TIMER is used for timed operations. The server maintains a pool
  1657. // of these structures.
  1658. //
  1659. typedef struct _SRV_TIMER {
  1660. SINGLE_LIST_ENTRY Next;
  1661. KEVENT Event;
  1662. KTIMER Timer;
  1663. KDPC Dpc;
  1664. } SRV_TIMER, *PSRV_TIMER;
  1665. typedef struct _IPX_CLIENT_ADDRESS {
  1666. TA_IPX_ADDRESS IpxAddress;
  1667. TDI_CONNECTION_INFORMATION Descriptor;
  1668. IPX_DATAGRAM_OPTIONS DatagramOptions;
  1669. } IPX_CLIENT_ADDRESS, *PIPX_CLIENT_ADDRESS;
  1670. //
  1671. // The state for an I/O request is maintained in a Work Context Block.
  1672. // Various fields in the block are filled in or not depending upon the
  1673. // request. When a worker thread removes a work item from the FSP work
  1674. // queue, it uses the context block, and items pointed to by the
  1675. // context block, to determine what to do.
  1676. //
  1677. // *** Not all of the back pointers have to be here, because a tree
  1678. // connect points to a session, which points to a connection, which
  1679. // points to an endpoint, etc. However, depending on the operation
  1680. // and the state of the operation, we may have a connection pointer
  1681. // but no session pointer, etc. So we maintain all of the
  1682. // pointers.
  1683. //
  1684. // *** Any changes to the first 2 elements of this structure must be
  1685. // made in concert with the SPECIAL_WORK_ITEM structure in srvtypes.h
  1686. //
  1687. typedef struct _WORK_CONTEXT {
  1688. //
  1689. // The list entry in the block header is used to queue the WC for to
  1690. // the nonblocking or blocking worker thread work queue. The
  1691. // nonblocking work queue also contains RFCBs.
  1692. //
  1693. // *** Note that this is an unnamed field, so that its elements can
  1694. // can be referenced directly. The field names defined in
  1695. // QUEUEABLE_BLOCK_HEADER cannot be used elsewhere in this
  1696. // block.
  1697. //
  1698. // Timestamp (in the block header) is used to calculate the total
  1699. // time this work context block was on the work queue.
  1700. //
  1701. // When the work context block is not in use, Timestamp is used to
  1702. // record the time at which the block was inserted on the free list.
  1703. // This is used to determine when dynamically-allocated work context
  1704. // blocks have been idle long enough justify their deletion.
  1705. //
  1706. // FspRestartRoutine (in the block header) is the routine that is to
  1707. // be called by worker thread when the work item is dequeued from
  1708. // the work queue.
  1709. //
  1710. QUEUEABLE_BLOCK_HEADER ; // must be first element
  1711. //
  1712. // This is the WORK_QUEUE to queue on if we're doing nonblocking work
  1713. // It will always point to a valid WORK_QUEUE, even if we're doing
  1714. // blocking work.
  1715. //
  1716. PWORK_QUEUE CurrentWorkQueue;
  1717. //
  1718. // The free list this should be returned to when work is done
  1719. //
  1720. PSLIST_HEADER FreeList;
  1721. //
  1722. // FsdRestartRoutine is the routine that is to be called by the
  1723. // FSD's I/O completion routine. This routine can do more
  1724. // processing or queue the work item to the FSP. In this case, when
  1725. // a worker thread removes the item from the work queue, it calls
  1726. // FspRestartRoutine.
  1727. //
  1728. PRESTART_ROUTINE FsdRestartRoutine;
  1729. //
  1730. // Linkage field for the in-progress work item list.
  1731. //
  1732. LIST_ENTRY InProgressListEntry;
  1733. //
  1734. // Pointers to various structures that might be used.
  1735. // These pointers are all referenced pointers. It is
  1736. // the responsibility of the SMB processing routines to
  1737. // dereference and clear these pointers when they are no
  1738. // longer needed.
  1739. //
  1740. PRFCB Rfcb;
  1741. PSHARE Share;
  1742. PSESSION Session;
  1743. PTREE_CONNECT TreeConnect;
  1744. //
  1745. // These are gathered in one place to facilitate quick zeroing
  1746. // of their values when the work context is finished
  1747. //
  1748. struct _WorkContextZeroBeforeReuse {
  1749. //
  1750. // unreferenced pointer to the endpoint structure for
  1751. // this work context. Filled in by SrvRestartReceive and
  1752. // available to all SMB processing routines.
  1753. //
  1754. // Endpoint must be the first element in this structure. See
  1755. // INITIALIZE_WORK_CONTEXT in srvmacro.h if changed.
  1756. //
  1757. PENDPOINT Endpoint; // not a referenced pointer
  1758. //
  1759. // referenced pointer to the connection structure for this
  1760. // this work context. Filled in by SrvRestartReceive and
  1761. // available to all SMB processing routines.
  1762. //
  1763. PCONNECTION Connection; // a reference pointer
  1764. //
  1765. // The number of times this SMB has been queued to a worker thread
  1766. // for processing.
  1767. //
  1768. ULONG ProcessingCount;
  1769. //
  1770. // This is a random collection of flags that are needed to steer
  1771. // the WorkItem
  1772. //
  1773. struct {
  1774. //
  1775. // Can the processing of the current SMB block?
  1776. //
  1777. ULONG BlockingOperation : 1;
  1778. //
  1779. // UsingExtraSmbBuffer is TRUE if this work context uses the an extra SMB
  1780. // buffer.
  1781. //
  1782. ULONG UsingExtraSmbBuffer : 1;
  1783. //
  1784. // Did this Work Item cause a successful oplock open to occur?
  1785. //
  1786. ULONG OplockOpen : 1;
  1787. //
  1788. // If we got an ACCESS_DENIED error when opening a file, was it because
  1789. // of share ACL checking?
  1790. ULONG ShareAclFailure : 1;
  1791. //
  1792. // Should the WorkContext be queued to the head of the list?
  1793. //
  1794. ULONG QueueToHead : 1;
  1795. //
  1796. // Even if security signatures are enabled, do not generate a signature for
  1797. // this response.
  1798. //
  1799. ULONG NoResponseSmbSecuritySignature : 1;
  1800. //
  1801. // The indicated message exceeds the SMB buffer size. This is allowed
  1802. // only for specific SMB(s)
  1803. //
  1804. ULONG LargeIndication: 1;
  1805. #if DBG_STUCK
  1806. //
  1807. // Do not include this operation in the StuckOperation catching logic
  1808. // which is in the scavenger
  1809. //
  1810. ULONG IsNotStuck : 1;
  1811. #endif
  1812. };
  1813. // For SnapShot usage
  1814. LARGE_INTEGER SnapShotTime;
  1815. };
  1816. //
  1817. // Pointers to allocated buffers. RequestBuffer is the buffer into
  1818. // which the SMB is read. ResponseBuffer is the buffer into which
  1819. // the response is written.
  1820. //
  1821. // *** Currently, ResponseBuffer is always the same as
  1822. // RequestBuffer. We have separate pointers in order to reduce
  1823. // dependence on this being the case.
  1824. //
  1825. PBUFFER RequestBuffer;
  1826. PBUFFER ResponseBuffer;
  1827. //
  1828. // SMB processing pointers. These are pointers into the request
  1829. // buffer. They are maintained in the work context block in support
  1830. // of SMB processors that do asynchronous I/O.
  1831. //
  1832. // Separate request and response parameter pointers are maintained
  1833. // to make AndX processing simpler and more efficient. RequestHeader
  1834. // is normally the same as ResponseHeader -- both are normally the
  1835. // same as RequestBuffer.Buffer. SMB processing code must not depend
  1836. // on this -- it must not assume the the request and response buffers
  1837. // are the same, nor can it assume that they are different. Special
  1838. // rules around AndX SMBs do allow them to assume that the response
  1839. // to one command will not overwrite the next request.
  1840. //
  1841. PSMB_HEADER RequestHeader;
  1842. PVOID RequestParameters;
  1843. PSMB_HEADER ResponseHeader;
  1844. PVOID ResponseParameters;
  1845. //
  1846. // Pointer to the IRP associated with this work item.
  1847. //
  1848. PIRP Irp;
  1849. //
  1850. // StartTime stores the time at which processing of the current
  1851. // request began so that the turnaround time may be calculated.
  1852. //
  1853. ULONG StartTime;
  1854. //
  1855. // The PartOfInitialAllocation boolean indicates whether this work
  1856. // item is part of the block of work items allocated at server
  1857. // startup (see blkwork.c\SrvAllocateInitialWorkItems). Such work
  1858. // items cannot be deleted during server operation. A work item
  1859. // that is dynamically allocated in response to server load does not
  1860. // have this bit set, and is a candidate for deletion when the
  1861. // server's load decreases.
  1862. //
  1863. ULONG PartOfInitialAllocation;
  1864. //
  1865. // The following field contadins the command code of the next
  1866. // command to be processed in an SMB. The SMB processing
  1867. // initializer and chained (AndX) SMB command processors load this
  1868. // field prior to calling or returning to SrvProcessSmb.
  1869. //
  1870. UCHAR NextCommand;
  1871. //
  1872. // ClientAddress is used when receiving or sending over IPX.
  1873. //
  1874. PIPX_CLIENT_ADDRESS ClientAddress;
  1875. //
  1876. // Spin lock protecting reference count.
  1877. //
  1878. KSPIN_LOCK SpinLock;
  1879. //
  1880. // The security signature index for the request
  1881. //
  1882. ULONG SmbSecuritySignatureIndex;
  1883. //
  1884. // The security signature index for the response
  1885. //
  1886. ULONG ResponseSmbSecuritySignatureIndex;
  1887. //
  1888. // The following union is used to hold request-specific state while
  1889. // a response is being sent or while waiting for more data.
  1890. //
  1891. union {
  1892. //
  1893. // RemainingEchoCount is used when processing the Echo SMB.
  1894. //
  1895. USHORT RemainingEchoCount;
  1896. //
  1897. // Structure used for lock processing. This structure is
  1898. // currently used when processing the Lock, LockingAndX, and the
  1899. // LockAndRead SMBs.
  1900. //
  1901. struct {
  1902. //
  1903. // LockRange is used when processing the LockingAndX SMB. It is
  1904. // really either a PLOCKING_ANDX_RANGE, or a PNTLOCKING_ANDX_RANGE
  1905. // not just a PVOID.
  1906. //
  1907. PVOID LockRange;
  1908. //
  1909. // Timer is a timer and DPC used to timeout lock requests.
  1910. //
  1911. PSRV_TIMER Timer;
  1912. #ifdef INCLUDE_SMB_PERSISTENT
  1913. LARGE_INTEGER Offset; // offset for this lock
  1914. LARGE_INTEGER Length; // length of this lock
  1915. BOOLEAN Exclusive; // is this lock exclusive?
  1916. #endif
  1917. } Lock;
  1918. //
  1919. // Transaction is used when processing the Transaction[2] SMBs.
  1920. // Or when processing a write and X SMB.
  1921. //
  1922. PTRANSACTION Transaction;
  1923. //
  1924. // MdlIo is used when processing the ReadRaw or WriteRaw
  1925. // SMBs when "MDL read" or "MDL write" is used. It
  1926. // retains the status of the response send while the MDL is
  1927. // returned to the file system.
  1928. //
  1929. struct {
  1930. IO_STATUS_BLOCK IoStatus;
  1931. ULONG IrpFlags;
  1932. } MdlIo;
  1933. //
  1934. // LastWriteTime is used when processing any Read or Write SMB
  1935. // that uses RestartChainedClose as a restart routine. This
  1936. // field contains the new last write time to set for the file.
  1937. //
  1938. ULONG LastWriteTime;
  1939. //
  1940. // CurrentTableIndex is used when processing the Flush SMB. It
  1941. // retains the current index into the connection's file table
  1942. // when an asynchronous flush is in progress.
  1943. //
  1944. LONG CurrentTableIndex;
  1945. //
  1946. // ReadRaw is used when processing the Read Block Raw SMB.
  1947. // Offset is the file offset of the read. SavedResponseBuffer
  1948. // points to the original SMB response buffer descriptor, which
  1949. // is temporarily replaced by a descriptor for the raw read
  1950. // buffer. MdlRead indicates whether an MDL read was used,
  1951. // rather than a Copy read.
  1952. //
  1953. struct {
  1954. union {
  1955. //
  1956. // Used for non named pipe reads
  1957. //
  1958. LARGE_INTEGER Offset;
  1959. ULONG Length;
  1960. //
  1961. // Used only for named pipe reads
  1962. //
  1963. PFILE_PIPE_PEEK_BUFFER PipePeekBuffer;
  1964. } ReadRawOtherInfo;
  1965. PBUFFER SavedResponseBuffer;
  1966. BOOLEAN MdlRead;
  1967. } ReadRaw;
  1968. //
  1969. // WriteRaw is used when processing the Write Block Raw SMB.
  1970. // FinalResponseBuffer points to the buffer allocated to contain
  1971. // the final response SMB, if writethrough mode was specified.
  1972. // Offset is the file offset of the write. ImmediateLength is
  1973. // the amount of write data that was sent with the request SMB.
  1974. // Pid is the PID of the writer, used to form the lock key on
  1975. // the write. FileObject is a pointer to the file object copied
  1976. // from the LFCB. (Pid is not used when MDL write is used;
  1977. // FileObject is not used when copy write is used.)
  1978. //
  1979. struct {
  1980. struct _WORK_CONTEXT *RawWorkContext;
  1981. } WriteRawPhase1;
  1982. struct {
  1983. LARGE_INTEGER Offset;
  1984. ULONG Length;
  1985. PVOID FinalResponseBuffer;
  1986. CLONG ImmediateLength;
  1987. PMDL FirstMdl;
  1988. //PFILE_OBJECT FileObject;
  1989. USHORT Pid;
  1990. BOOLEAN MdlWrite;
  1991. BOOLEAN ImmediateWriteDone;
  1992. } WriteRaw;
  1993. //
  1994. // ReadAndXCompressed is the structure used when handling
  1995. // compressed ReadAndX
  1996. //
  1997. struct {
  1998. LARGE_INTEGER ReadOffset; // original read offset
  1999. ULONG ReadLength; // original read length
  2000. ULONG CompressedInfoLength;
  2001. FSRTL_AUXILIARY_BUFFER Aux;
  2002. } ReadAndXCompressed;
  2003. //
  2004. // ReadAndX is the structure used when handling the ReadAndX
  2005. // SMB.
  2006. //
  2007. struct {
  2008. LARGE_INTEGER ReadOffset;
  2009. ULONG ReadLength;
  2010. PCHAR ReadAddress;
  2011. union {
  2012. struct {
  2013. PFILE_PIPE_PEEK_BUFFER PipePeekBuffer;
  2014. ULONG LastWriteTimeInSeconds; // used if Close is chained
  2015. };
  2016. struct { // used for ReadLength > negotiated size
  2017. PBYTE Buffer; // allocated paged pool, if copy read
  2018. PMDL SavedMdl;
  2019. PMDL CacheMdl;
  2020. USHORT PadCount;
  2021. BOOLEAN MdlRead;
  2022. };
  2023. };
  2024. } ReadAndX;
  2025. #define READX_BUFFER_OFFSET (sizeof(SMB_HEADER) + FIELD_OFFSET(RESP_READ_ANDX, Buffer) )
  2026. //
  2027. // WriteAndX is the structure used when handling the flavor of WriteAndX that
  2028. // exceeds the negotiated buffer size
  2029. //
  2030. struct {
  2031. ULONG CurrentWriteLength; // amount of data that was written this time
  2032. LARGE_INTEGER Offset; // file offset for this piece of the write
  2033. ULONG RemainingWriteLength; // amount of data remaining to be read from xport
  2034. ULONG Key; // lock key for the operation
  2035. PCHAR WriteAddress; // address in buffer for the data
  2036. ULONG BufferLength; // Maximum buffer length in this WorkContext
  2037. NTSTATUS FinalStatus; // Final status of the operation
  2038. PMDL MdlAddress; // File MDL if MdlWrite == TRUE
  2039. BOOLEAN InitialComplete; // TRUE if we have written first part to the file
  2040. } WriteAndX;
  2041. //
  2042. // WriteC is used when we are doing compressed writes
  2043. //
  2044. struct {
  2045. LARGE_INTEGER Offset; // File offset for this piece of the write
  2046. ULONG Key; // Lock key for the operation
  2047. ULONG CdiLength; // COMPRESSED_DATA_INFO length if compressed write
  2048. ULONG CompressedDataLength; // Length of compressed data
  2049. ULONG UncompressedDataLength; // Uncompressed length of the write
  2050. PCOMPRESSED_DATA_INFO Cdi; // The compressed data info descriptor for this write
  2051. ULONG InitialFragmentSize; // Amount of CompressedData in initial receive
  2052. FSRTL_AUXILIARY_BUFFER Aux;
  2053. PMDL Mdl; // Mdl we are using for compressed writes
  2054. BOOLEAN MdlCompleted; // Have we called MdlWriteCompleteCompressed yet?
  2055. PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
  2056. PFILE_OBJECT FileObject;
  2057. PDEVICE_OBJECT DeviceObject;
  2058. PBYTE CompressedBuffer; // In case the PrepareMdlWrite failed!
  2059. PBYTE UncompressedBuffer;
  2060. } WriteC;
  2061. //
  2062. // ReadMpx is the structure used when handling the ReadMpx SMB, unless
  2063. // we have a SmartCard accelerating our reads. In this case,
  2064. // SmartCardRead is used.
  2065. //
  2066. struct {
  2067. ULONG Offset;
  2068. USHORT FragmentSize;
  2069. USHORT RemainingLength;
  2070. ULONG ReadLength;
  2071. BOOLEAN MdlRead;
  2072. UCHAR Unused;
  2073. USHORT CurrentMdlOffset; // logically part of MDL read struct below
  2074. union {
  2075. struct {
  2076. PVOID MpxBuffer;
  2077. PMDL MpxBufferMdl;
  2078. PCHAR NextFragmentAddress;
  2079. } ;
  2080. struct {
  2081. PMDL FirstMdl;
  2082. PMDL CurrentMdl;
  2083. } ;
  2084. } ;
  2085. } ReadMpx;
  2086. //
  2087. // SmartCardRead is used to handle direct host read requests if we have
  2088. // a Smart Card accelerating the particular request.
  2089. //
  2090. struct {
  2091. PDEVICE_OBJECT DeviceObject;
  2092. PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
  2093. } SmartCardRead;
  2094. //
  2095. // WriteMpx is the structure used when handling the WriteMpx SMB.
  2096. //
  2097. struct {
  2098. ULONG Offset;
  2099. USHORT WriteLength;
  2100. USHORT Mid;
  2101. BOOLEAN FirstPacketOfGlom;
  2102. PVOID Buffer;
  2103. ULONG ReceiveDatagramFlags;
  2104. PVOID TransportContext;
  2105. PMDL DataMdl;
  2106. } WriteMpx;
  2107. struct {
  2108. LARGE_INTEGER CacheOffset;
  2109. ULONG WriteLength;
  2110. PMDL CacheMdl;
  2111. } WriteMpxMdlWriteComplete;
  2112. //
  2113. // FastTransactNamedPipe is used when handling a small named pipe
  2114. // transaction.
  2115. //
  2116. struct {
  2117. PSMB_USHORT OutSetup;
  2118. PCHAR OutParam;
  2119. PCHAR OutData;
  2120. } FastTransactNamedPipe;
  2121. #ifdef INCLUDE_SMB_PERSISTENT
  2122. struct {
  2123. ULONG ResumeSmbStatus;
  2124. PRESTART_ROUTINE FsdRestartRoutine;
  2125. PRESTART_ROUTINE FspRestartRoutine;
  2126. } MakePersistent;
  2127. #endif
  2128. } Parameters;
  2129. // !!! check whether the compiler leaves a dword gap here!
  2130. //
  2131. // The following union holds state information about SMBs in progress
  2132. // waiting for an oplock break. It is kept separate from the Parameters
  2133. // union, since information from both is needed to process some SMBs.
  2134. //
  2135. union {
  2136. //
  2137. // Open is the structure used when handling the Open,
  2138. // OpenAndX, Open2, Create, or CreateTemporary SMB.
  2139. //
  2140. struct {
  2141. PRFCB Rfcb;
  2142. PFILE_FULL_EA_INFORMATION NtFullEa;
  2143. ULONG EaErrorOffset;
  2144. //
  2145. // The Irp used to open the file is the same Irp used to handle
  2146. // the oplock processing. This can cause us to lose the original
  2147. // iosb->Information. Save it here.
  2148. //
  2149. ULONG_PTR IosbInformation;
  2150. //
  2151. // If TRUE, the file was opened only in order to get a handle
  2152. // so that we can wait for an oplock to break. This handle will
  2153. // be immediately closed, and the open will be retried with the
  2154. // user requested access.
  2155. //
  2156. BOOLEAN TemporaryOpen;
  2157. } Open;
  2158. //
  2159. // FileInformation is the structure used when handling the
  2160. // QueryInformation, SetInformation, QueryPathInformation,
  2161. // or SetPathInformation SMB.
  2162. //
  2163. struct {
  2164. HANDLE FileHandle;
  2165. } FileInformation;
  2166. //
  2167. // LockLength is used to contain the length of a byte range
  2168. // lock since the IRP stack location has no room to hold it.
  2169. LARGE_INTEGER LockLength;
  2170. //
  2171. // StartSend is used by SrvStartSend when queueing a work item
  2172. // to the FSP for handling by the SmbTrace logic.
  2173. //
  2174. struct {
  2175. PRESTART_ROUTINE FspRestartRoutine;
  2176. ULONG SendLength;
  2177. } StartSend;
  2178. } Parameters2;
  2179. //
  2180. // This field is used when the current operation is blocked waiting
  2181. // for an oplock break to occur.
  2182. //
  2183. struct _WAIT_FOR_OPLOCK_BREAK *WaitForOplockBreak;
  2184. union {
  2185. //
  2186. // where we keep the actual client address data.
  2187. //
  2188. IPX_CLIENT_ADDRESS ClientAddressData;
  2189. //
  2190. // For a VC-based client, this is the amount of available data if
  2191. // LargeIndication is set (above)
  2192. //
  2193. ULONG BytesAvailable;
  2194. };
  2195. struct {
  2196. LARGE_INTEGER G_StartTime;
  2197. ULONG ElapseKCPU;
  2198. ULONG ElapseUCPU;
  2199. ULONG ClientAddr;
  2200. PFILE_OBJECT FileObject;
  2201. };
  2202. ULONG KCPUStart;
  2203. ULONG UCPUStart;
  2204. UCHAR PreviousSMB;
  2205. UCHAR bAlreadyTrace;
  2206. USHORT FileNameSize;
  2207. WCHAR strFileName[1024];
  2208. #if DBG_STUCK
  2209. //
  2210. // Time at which this work context was allocated for this current
  2211. // unit of work. This time is examined by debugging code in the
  2212. // scavenger to help find operations which are taking too long
  2213. // to complete.
  2214. //
  2215. LARGE_INTEGER OpStartTime;
  2216. #endif
  2217. } WORK_CONTEXT, *PWORK_CONTEXT;
  2218. //
  2219. // Structure used to maintain information about a thread waiting for
  2220. // an oplock break.
  2221. //
  2222. typedef struct _WAIT_FOR_OPLOCK_BREAK {
  2223. BLOCK_HEADER BlockHeader;
  2224. LIST_ENTRY ListEntry;
  2225. LARGE_INTEGER TimeoutTime;
  2226. PIRP Irp;
  2227. WAIT_STATE WaitState;
  2228. } WAIT_FOR_OPLOCK_BREAK, *PWAIT_FOR_OPLOCK_BREAK;
  2229. //
  2230. // Block manager routines
  2231. //
  2232. //
  2233. // Buffer routines
  2234. //
  2235. VOID
  2236. SrvAllocateBuffer (
  2237. OUT PBUFFER *Buffer,
  2238. IN CLONG BufferLength
  2239. );
  2240. VOID
  2241. SrvFreeBuffer (
  2242. IN PBUFFER Buffer
  2243. );
  2244. //
  2245. // Connection routines
  2246. //
  2247. VOID
  2248. SrvAllocateConnection (
  2249. OUT PCONNECTION *Connection
  2250. );
  2251. VOID
  2252. SrvCloseConnection (
  2253. IN PCONNECTION Connection,
  2254. IN BOOLEAN RemoteDisconnect
  2255. );
  2256. VOID
  2257. SrvCloseConnectionsFromClient(
  2258. IN PCONNECTION Connection,
  2259. IN BOOLEAN OnlyIfNoSessions
  2260. );
  2261. VOID
  2262. SrvCloseFreeConnection (
  2263. IN PCONNECTION Connection
  2264. );
  2265. VOID
  2266. SrvDereferenceConnection (
  2267. IN PCONNECTION Connection
  2268. );
  2269. VOID
  2270. SrvFreeConnection (
  2271. IN PCONNECTION Connection
  2272. );
  2273. #if DBG
  2274. NTSTATUS
  2275. SrvQueryConnections (
  2276. OUT PVOID Buffer,
  2277. IN ULONG BufferLength,
  2278. OUT PULONG BytesWritten
  2279. );
  2280. #endif
  2281. //
  2282. // Endpoint routines
  2283. //
  2284. VOID
  2285. SrvAllocateEndpoint (
  2286. OUT PENDPOINT *Endpoint,
  2287. IN PUNICODE_STRING NetworkName,
  2288. IN PUNICODE_STRING TransportName,
  2289. IN PANSI_STRING TransportAddress,
  2290. IN PUNICODE_STRING DomainName
  2291. );
  2292. BOOLEAN SRVFASTCALL
  2293. SrvCheckAndReferenceEndpoint (
  2294. IN PENDPOINT Endpoint
  2295. );
  2296. VOID
  2297. SrvCloseEndpoint (
  2298. IN PENDPOINT Endpoint
  2299. );
  2300. VOID SRVFASTCALL
  2301. SrvDereferenceEndpoint (
  2302. IN PENDPOINT Endpoint
  2303. );
  2304. VOID
  2305. SrvFreeEndpoint (
  2306. IN PENDPOINT Endpoint
  2307. );
  2308. VOID
  2309. SrvReferenceEndpoint (
  2310. IN PENDPOINT Endpoint
  2311. );
  2312. BOOLEAN
  2313. SrvFindNamedEndpoint (
  2314. IN PUNICODE_STRING ServerName,
  2315. IN PBOOLEAN RemapPipeNames OPTIONAL
  2316. );
  2317. VOID
  2318. EmptyFreeConnectionList (
  2319. IN PENDPOINT Endpoint
  2320. );
  2321. PCONNECTION
  2322. WalkConnectionTable (
  2323. IN PENDPOINT Endpoint,
  2324. IN PUSHORT Index
  2325. );
  2326. //
  2327. // Local File Control Block routines
  2328. //
  2329. VOID
  2330. SrvAllocateLfcb (
  2331. OUT PLFCB *Lfcb,
  2332. IN PWORK_CONTEXT WorkContext
  2333. );
  2334. VOID
  2335. SrvCloseLfcb (
  2336. IN PLFCB Lfcb
  2337. );
  2338. VOID
  2339. SrvDereferenceLfcb (
  2340. IN PLFCB Lfcb
  2341. );
  2342. VOID
  2343. SrvFreeLfcb (
  2344. IN PLFCB Lfcb,
  2345. IN PWORK_QUEUE queue
  2346. );
  2347. VOID
  2348. SrvReferenceLfcb (
  2349. IN PLFCB Lfcb
  2350. );
  2351. //
  2352. // Master File Control Block routines
  2353. //
  2354. PMFCB
  2355. SrvCreateMfcb(
  2356. IN PUNICODE_STRING FileName,
  2357. IN PWORK_CONTEXT WorkContext,
  2358. IN ULONG HashValue
  2359. );
  2360. PMFCB
  2361. SrvFindMfcb(
  2362. IN PUNICODE_STRING FileName,
  2363. IN BOOLEAN CaseInsensitive,
  2364. OUT PSRV_LOCK *Lock,
  2365. OUT PULONG HashValue,
  2366. IN PWORK_CONTEXT WorkContext
  2367. );
  2368. VOID
  2369. SrvDereferenceMfcb (
  2370. IN PMFCB Mfcb
  2371. );
  2372. VOID
  2373. SrvFreeMfcb (
  2374. IN PMFCB Mfcb
  2375. );
  2376. VOID
  2377. SrvUnlinkLfcbFromMfcb (
  2378. IN PLFCB Lfcb
  2379. );
  2380. //
  2381. // Remote File Control Block routines
  2382. //
  2383. VOID SRVFASTCALL
  2384. SrvAllocateRfcb (
  2385. OUT PRFCB *Rfcb,
  2386. IN PWORK_CONTEXT WorkContext
  2387. );
  2388. BOOLEAN SRVFASTCALL
  2389. SrvCheckAndReferenceRfcb (
  2390. IN PRFCB Rfcb
  2391. );
  2392. VOID SRVFASTCALL
  2393. SrvCloseRfcb (
  2394. IN PRFCB Rfcb
  2395. );
  2396. VOID
  2397. SrvCloseRfcbsOnLfcb (
  2398. PLFCB Lfcb
  2399. );
  2400. VOID
  2401. SrvCloseRfcbsOnSessionOrPid (
  2402. IN PSESSION Session,
  2403. IN PUSHORT Pid OPTIONAL
  2404. );
  2405. VOID
  2406. SrvCloseRfcbsOnTree (
  2407. PTREE_CONNECT TreeConnect
  2408. );
  2409. VOID
  2410. SrvCompleteRfcbClose (
  2411. IN PRFCB Rfcb
  2412. );
  2413. VOID SRVFASTCALL
  2414. SrvDereferenceRfcb (
  2415. IN PRFCB Rfcb
  2416. );
  2417. VOID SRVFASTCALL
  2418. SrvFreeRfcb (
  2419. IN PRFCB Rfcb,
  2420. IN PWORK_QUEUE queue
  2421. );
  2422. VOID SRVFASTCALL
  2423. SrvReferenceRfcb (
  2424. IN PRFCB Rfcb
  2425. );
  2426. BOOLEAN
  2427. SrvFindCachedRfcb (
  2428. IN PWORK_CONTEXT WorkContext,
  2429. IN PMFCB Mfcb,
  2430. IN ACCESS_MASK DesiredAccess,
  2431. IN ULONG ShareAccess,
  2432. IN ULONG CreateDisposition,
  2433. IN ULONG CreateOptions,
  2434. IN OPLOCK_TYPE RequestedOplockType,
  2435. OUT PNTSTATUS Status
  2436. );
  2437. VOID
  2438. SrvCloseCachedRfcb (
  2439. IN PRFCB Rfcb,
  2440. IN KIRQL OldIrql
  2441. );
  2442. VOID
  2443. SrvCloseCachedRfcbsOnConnection (
  2444. IN PCONNECTION Connection
  2445. );
  2446. VOID
  2447. SrvCloseCachedRfcbsOnLfcb (
  2448. IN PLFCB Lfcb
  2449. );
  2450. ULONG
  2451. SrvCountCachedRfcbsForTid(
  2452. PCONNECTION connection,
  2453. USHORT Tid
  2454. );
  2455. ULONG
  2456. SrvCountCachedRfcbsForUid(
  2457. PCONNECTION connection,
  2458. USHORT Uid
  2459. );
  2460. //
  2461. // Search Block routines
  2462. //
  2463. typedef
  2464. BOOLEAN
  2465. (*PSEARCH_FILTER_ROUTINE) (
  2466. IN PSEARCH Search,
  2467. IN PVOID FunctionParameter1,
  2468. IN PVOID FunctionParameter2
  2469. );
  2470. VOID
  2471. SrvAllocateSearch (
  2472. OUT PSEARCH *Search,
  2473. IN PUNICODE_STRING SearchName,
  2474. IN BOOLEAN IsCoreSearch
  2475. );
  2476. VOID
  2477. SrvCloseSearch (
  2478. IN PSEARCH Search
  2479. );
  2480. VOID
  2481. SrvCloseSearches (
  2482. IN PCONNECTION Connection,
  2483. IN PSEARCH_FILTER_ROUTINE SearchFilterRoutine,
  2484. IN PVOID FunctionParameter1,
  2485. IN PVOID FunctionParameter2
  2486. );
  2487. VOID
  2488. SrvDereferenceSearch (
  2489. IN PSEARCH Search
  2490. );
  2491. VOID
  2492. SrvFreeSearch (
  2493. IN PSEARCH Search
  2494. );
  2495. VOID
  2496. SrvReferenceSearch (
  2497. IN PSEARCH Search
  2498. );
  2499. BOOLEAN
  2500. SrvSearchOnDelete(
  2501. IN PSEARCH Search,
  2502. IN PUNICODE_STRING DirectoryName,
  2503. IN PTREE_CONNECT TreeConnect
  2504. );
  2505. BOOLEAN
  2506. SrvSearchOnPid(
  2507. IN PSEARCH Search,
  2508. IN USHORT Pid,
  2509. IN PVOID Dummy
  2510. );
  2511. BOOLEAN
  2512. SrvSearchOnSession(
  2513. IN PSEARCH Search,
  2514. IN PSESSION Session,
  2515. IN PVOID Dummy
  2516. );
  2517. BOOLEAN
  2518. SrvSearchOnTreeConnect(
  2519. IN PSEARCH Search,
  2520. IN PTREE_CONNECT TreeConnect,
  2521. IN PVOID Dummy
  2522. );
  2523. VOID
  2524. SrvForceTimeoutSearches(
  2525. IN PCONNECTION Connection
  2526. );
  2527. ULONG
  2528. SrvTimeoutSearches(
  2529. IN PLARGE_INTEGER SearchCutoffTime OPTIONAL,
  2530. IN PCONNECTION Connection,
  2531. IN BOOLEAN OnlyTimeoutOneBlock
  2532. );
  2533. VOID
  2534. RemoveDuplicateCoreSearches(
  2535. IN PPAGED_CONNECTION PagedConnection
  2536. );
  2537. VOID
  2538. SrvAddToSearchHashTable(
  2539. IN PPAGED_CONNECTION PagedConnection,
  2540. IN PSEARCH Search
  2541. );
  2542. //
  2543. // Cached directory routines
  2544. //
  2545. BOOLEAN
  2546. SrvIsDirectoryCached (
  2547. IN PWORK_CONTEXT WorkContext,
  2548. IN PUNICODE_STRING DirectoryName
  2549. );
  2550. VOID
  2551. SrvCacheDirectoryName (
  2552. IN PWORK_CONTEXT WorkContext,
  2553. IN PUNICODE_STRING DirectoryName
  2554. );
  2555. VOID
  2556. SrvRemoveCachedDirectoryName (
  2557. IN PWORK_CONTEXT WorkContext,
  2558. IN PUNICODE_STRING DirectoryName
  2559. );
  2560. VOID
  2561. SrvCloseCachedDirectoryEntries (
  2562. IN PCONNECTION Connection
  2563. );
  2564. //
  2565. // Session routines
  2566. //
  2567. VOID
  2568. SrvAllocateSession (
  2569. OUT PSESSION *Session,
  2570. IN PUNICODE_STRING UserName,
  2571. IN PUNICODE_STRING Domain
  2572. );
  2573. BOOLEAN SRVFASTCALL
  2574. SrvCheckAndReferenceSession (
  2575. IN PSESSION Session
  2576. );
  2577. VOID
  2578. SrvCloseSession (
  2579. IN PSESSION Session
  2580. );
  2581. VOID
  2582. SrvCloseSessionsOnConnection (
  2583. IN PCONNECTION Connection,
  2584. IN PUNICODE_STRING UserName OPTIONAL
  2585. );
  2586. VOID SRVFASTCALL
  2587. SrvDereferenceSession (
  2588. IN PSESSION Session
  2589. );
  2590. VOID
  2591. SrvFreeSession (
  2592. IN PSESSION Session
  2593. );
  2594. //
  2595. // Smb Security Signature Routines
  2596. //
  2597. BOOLEAN SRVFASTCALL
  2598. SrvCheckSmbSecuritySignature(
  2599. IN PWORK_CONTEXT WorkContext
  2600. );
  2601. VOID SRVFASTCALL
  2602. SrvAddSmbSecuritySignature(
  2603. IN OUT PWORK_CONTEXT WorkContext,
  2604. IN PMDL Mdl,
  2605. IN ULONG SendLength
  2606. );
  2607. VOID SRVFASTCALL
  2608. SrvInitializeSmbSecuritySignature(
  2609. IN OUT PCONNECTION Connection,
  2610. IN PUCHAR SessionKey,
  2611. IN PUCHAR ChallengeResponse,
  2612. IN ULONG ChallengeResponseLength
  2613. );
  2614. //
  2615. // Share routines
  2616. //
  2617. VOID
  2618. SrvAllocateShare (
  2619. OUT PSHARE *Share,
  2620. IN PUNICODE_STRING ShareName,
  2621. IN PUNICODE_STRING NtPathName,
  2622. IN PUNICODE_STRING DosPathName,
  2623. IN PUNICODE_STRING Remark,
  2624. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  2625. IN PSECURITY_DESCRIPTOR FileSecurityDescriptor OPTIONAL,
  2626. IN SHARE_TYPE ShareType
  2627. );
  2628. VOID
  2629. SrvCloseShare (
  2630. IN PSHARE Share
  2631. );
  2632. VOID
  2633. SrvDereferenceShare (
  2634. IN PSHARE Share
  2635. );
  2636. VOID
  2637. SrvDereferenceShareForTreeConnect (
  2638. PSHARE Share
  2639. );
  2640. VOID
  2641. SrvFreeShare (
  2642. IN PSHARE Share
  2643. );
  2644. VOID
  2645. SrvReferenceShare (
  2646. IN PSHARE Share
  2647. );
  2648. NTSTATUS
  2649. SrvReferenceShareForTreeConnect (
  2650. PSHARE Share
  2651. );
  2652. //
  2653. // Table routines
  2654. //
  2655. VOID
  2656. SrvAllocateTable (
  2657. IN PTABLE_HEADER TableHeader,
  2658. IN ULONG NumberOfEntries,
  2659. IN BOOLEAN Nonpaged
  2660. );
  2661. #define SrvFreeTable( _table ) { \
  2662. if ( (_table)->Nonpaged ) { \
  2663. DEALLOCATE_NONPAGED_POOL( (_table)->Table ); \
  2664. } else { \
  2665. FREE_HEAP( (_table)->Table ); \
  2666. } \
  2667. DEBUG (_table)->Table = NULL; \
  2668. DEBUG (_table)->TableSize = -1; \
  2669. DEBUG (_table)->FirstFreeEntry = -1; \
  2670. DEBUG (_table)->LastFreeEntry = -1; \
  2671. }
  2672. BOOLEAN
  2673. SrvGrowTable (
  2674. IN PTABLE_HEADER TableHeader,
  2675. IN ULONG NumberOfNewEntries,
  2676. IN ULONG MaxNumberOfEntries,
  2677. OUT NTSTATUS* pStatus
  2678. );
  2679. VOID
  2680. SrvRemoveEntryTable (
  2681. IN PTABLE_HEADER TableHeader,
  2682. IN USHORT Index
  2683. );
  2684. //
  2685. // Transaction routines
  2686. //
  2687. VOID
  2688. SrvAllocateTransaction (
  2689. OUT PTRANSACTION *Transaction,
  2690. OUT PVOID *TrailingBytes,
  2691. IN PCONNECTION Connection,
  2692. IN CLONG TrailingByteCount,
  2693. IN PVOID TransactionName,
  2694. IN PVOID EndOfSourceBuffer OPTIONAL,
  2695. IN BOOLEAN SourceIsUnicode,
  2696. IN BOOLEAN RemoteApiRequest
  2697. );
  2698. VOID
  2699. SrvCloseTransaction (
  2700. IN PTRANSACTION Transaction
  2701. );
  2702. VOID
  2703. SrvCloseTransactionsOnSession (
  2704. PSESSION Session
  2705. );
  2706. VOID
  2707. SrvCloseTransactionsOnTree (
  2708. PTREE_CONNECT TreeConnect
  2709. );
  2710. VOID
  2711. SrvDereferenceTransaction (
  2712. IN PTRANSACTION Transaction
  2713. );
  2714. VOID
  2715. SrvFreeTransaction (
  2716. IN PTRANSACTION Transaction
  2717. );
  2718. PTRANSACTION
  2719. SrvFindTransaction (
  2720. IN PCONNECTION Connection,
  2721. IN PSMB_HEADER Header,
  2722. IN USHORT Fid OPTIONAL
  2723. );
  2724. BOOLEAN
  2725. SrvInsertTransaction (
  2726. IN PTRANSACTION Transaction
  2727. );
  2728. //
  2729. // Tree connect routines
  2730. //
  2731. VOID
  2732. SrvAllocateTreeConnect (
  2733. OUT PTREE_CONNECT *TreeConnect,
  2734. IN PUNICODE_STRING ServerName OPTIONAL
  2735. );
  2736. BOOLEAN SRVFASTCALL
  2737. SrvCheckAndReferenceTreeConnect (
  2738. IN PTREE_CONNECT TreeConnect
  2739. );
  2740. VOID
  2741. SrvCloseTreeConnect (
  2742. IN PTREE_CONNECT TreeConnect
  2743. );
  2744. VOID SRVFASTCALL
  2745. SrvDereferenceTreeConnect (
  2746. IN PTREE_CONNECT TreeConnect
  2747. );
  2748. VOID
  2749. SrvFreeTreeConnect (
  2750. IN PTREE_CONNECT TreeConnect
  2751. );
  2752. VOID
  2753. SrvDisconnectTreeConnectsFromSession (
  2754. PCONNECTION connection,
  2755. PSESSION Session
  2756. );
  2757. VOID
  2758. SrvCloseTreeConnectsOnShare (
  2759. IN PSHARE Share
  2760. );
  2761. //
  2762. // Work item routines (includes work contexts, buffers, MDLs, IRPs, etc)
  2763. //
  2764. NTSTATUS
  2765. SrvAllocateInitialWorkItems (
  2766. VOID
  2767. );
  2768. NTSTATUS
  2769. SrvAllocateNormalWorkItem (
  2770. OUT PWORK_CONTEXT *WorkContext,
  2771. IN PWORK_QUEUE queue
  2772. );
  2773. VOID
  2774. SrvAllocateRawModeWorkItem (
  2775. OUT PWORK_CONTEXT *WorkContext,
  2776. IN PWORK_QUEUE queue
  2777. );
  2778. PWORK_CONTEXT
  2779. SrvGetRawModeWorkItem (
  2780. VOID
  2781. );
  2782. VOID
  2783. SrvRequeueRawModeWorkItem (
  2784. IN PWORK_CONTEXT WorkContext
  2785. );
  2786. VOID SRVFASTCALL
  2787. SrvDereferenceWorkItem (
  2788. IN PWORK_CONTEXT WorkContext
  2789. );
  2790. VOID
  2791. SrvFsdDereferenceWorkItem (
  2792. IN PWORK_CONTEXT WorkContext
  2793. );
  2794. NTSTATUS
  2795. SrvAllocateExtraSmbBuffer (
  2796. IN OUT PWORK_CONTEXT WorkContext
  2797. );
  2798. VOID
  2799. SrvAllocateWaitForOplockBreak (
  2800. OUT PWAIT_FOR_OPLOCK_BREAK *WaitForOplockBreak
  2801. );
  2802. VOID
  2803. SrvDereferenceWaitForOplockBreak (
  2804. IN PWAIT_FOR_OPLOCK_BREAK WaitForOplockBreak
  2805. );
  2806. VOID
  2807. SrvFreeWaitForOplockBreak (
  2808. IN PWAIT_FOR_OPLOCK_BREAK WaitForOplockBreak
  2809. );
  2810. VOID
  2811. SrvOplockWaitTimeout(
  2812. IN PWAIT_FOR_OPLOCK_BREAK WaitForOplockBreak
  2813. );
  2814. NTSTATUS
  2815. SrvCheckOplockWaitState(
  2816. IN PWAIT_FOR_OPLOCK_BREAK WaitForOplockBreak
  2817. );
  2818. NTSTATUS
  2819. SrvWaitForOplockBreak (
  2820. IN PWORK_CONTEXT WorkContext,
  2821. IN HANDLE FileHandle
  2822. );
  2823. NTSTATUS
  2824. SrvStartWaitForOplockBreak (
  2825. IN PWORK_CONTEXT WorkContext,
  2826. IN PRESTART_ROUTINE RestartRoutine,
  2827. IN HANDLE Handle OPTIONAL,
  2828. IN PFILE_OBJECT FileObject OPTIONAL
  2829. );
  2830. VOID
  2831. SrvSendDelayedOplockBreak (
  2832. IN PCONNECTION Connection
  2833. );
  2834. VOID
  2835. SrvFreeInitialWorkItems (
  2836. VOID
  2837. );
  2838. VOID
  2839. SrvFreeNormalWorkItem (
  2840. IN PWORK_CONTEXT WorkContext
  2841. );
  2842. VOID
  2843. SrvFreeRawModeWorkItem (
  2844. IN PWORK_CONTEXT WorkContext
  2845. );
  2846. //
  2847. // Byte range lock routines
  2848. //
  2849. #ifdef INCLUDE_SMB_PERSISTENT
  2850. VOID
  2851. SrvAllocateLock (
  2852. OUT PBYTELOCK *Lock,
  2853. IN PRFCB Rfcb,
  2854. IN LARGE_INTEGER Offset,
  2855. IN LARGE_INTEGER Length,
  2856. IN BOOLEAN Exclusive
  2857. );
  2858. PBYTELOCK
  2859. SrvFindAndReferenceLock (
  2860. IN PRFCB Rfcb,
  2861. IN LARGE_INTEGER Offset,
  2862. IN LARGE_INTEGER Length,
  2863. IN BOOLEAN Exclusive
  2864. );
  2865. VOID
  2866. SrvCloseLock (
  2867. IN PBYTELOCK Lock,
  2868. IN BOOLEAN HaveMfcbLock
  2869. );
  2870. VOID
  2871. SrvCloseLocksOnRfcb (
  2872. IN PRFCB Rfcb
  2873. );
  2874. VOID SRVFASTCALL
  2875. SrvDereferenceLock (
  2876. IN PBYTELOCK Lock
  2877. );
  2878. #endif
  2879. //
  2880. // Timer routines
  2881. //
  2882. PSRV_TIMER
  2883. SrvAllocateTimer (
  2884. VOID
  2885. );
  2886. VOID
  2887. SrvCancelTimer (
  2888. IN PSRV_TIMER Timer
  2889. );
  2890. #define SrvDeleteTimer(_timer) DEALLOCATE_NONPAGED_POOL(_timer)
  2891. #define SrvFreeTimer(_timer) \
  2892. ExInterlockedPushEntrySList(&SrvTimerList, &(_timer)->Next, &GLOBAL_SPIN_LOCK(Timer))
  2893. VOID
  2894. SrvSetTimer (
  2895. IN PSRV_TIMER Timer,
  2896. IN PLARGE_INTEGER Timeout,
  2897. IN PKDEFERRED_ROUTINE TimeoutHandler,
  2898. IN PVOID Context
  2899. );
  2900. #if SRVDBG2
  2901. VOID
  2902. SrvInitializeReferenceHistory (
  2903. IN PBLOCK_HEADER Block,
  2904. IN LONG InitialReferenceCount
  2905. );
  2906. VOID
  2907. SrvUpdateReferenceHistory (
  2908. IN PBLOCK_HEADER Block,
  2909. IN PVOID Caller,
  2910. IN PVOID CallersCaller,
  2911. IN BOOLEAN IsDereference
  2912. );
  2913. VOID
  2914. SrvTerminateReferenceHistory (
  2915. IN PBLOCK_HEADER Block
  2916. );
  2917. #define INITIALIZE_REFERENCE_HISTORY(block) \
  2918. SrvInitializeReferenceHistory( \
  2919. &(block)->BlockHeader, \
  2920. ((PBLOCK_HEADER)(block))->ReferenceCount \
  2921. )
  2922. #define UPDATE_REFERENCE_HISTORY(block,isdereference) \
  2923. { \
  2924. PVOID caller, callerscaller; \
  2925. RtlGetCallersAddress( &caller, &callerscaller ); \
  2926. SrvUpdateReferenceHistory( \
  2927. &(block)->BlockHeader, \
  2928. caller, \
  2929. callerscaller, \
  2930. isdereference \
  2931. ); \
  2932. }
  2933. #define TERMINATE_REFERENCE_HISTORY(block) \
  2934. SrvTerminateReferenceHistory( &(block)->BlockHeader )
  2935. #else
  2936. #define INITIALIZE_REFERENCE_HISTORY(block)
  2937. #define UPDATE_REFERENCE_HISTORY(block,isdereference)
  2938. #define TERMINATE_REFERENCE_HISTORY(block)
  2939. #endif // if SRVDBG2
  2940. #endif // ndef _SRVBLOCK