Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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