Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

783 lines
36 KiB

  1. /*++ BUILD Version: 0009 // Increment this if a change has global effects
  2. Copyright (c) 1987-1993 Microsoft Corporation
  3. Module Name:
  4. smbcedbp.h
  5. Abstract:
  6. This is the include file that defines all constants and types for
  7. implementing the SMB mini redirector connection engine.
  8. This module contains all the implementation details of the connection engine
  9. data structures and should be included only by the implementation modules.
  10. Revision History:
  11. Balan Sethu Raman (SethuR) 06-Mar-95 Created
  12. Notes:
  13. --*/
  14. #ifndef _SMBCEDBP_H_
  15. #define _SMBCEDBP_H_
  16. //
  17. // There is reliance on the fact that SMBCEDB_OT_SENTINEL is the last entry in the
  18. // enumerated type and the types have a range of values from 0. Please ensure that
  19. // this is always true.
  20. //
  21. typedef struct _REFERENCE_RECORD_ {
  22. PVOID FileName;
  23. ULONG FileLine;
  24. } REFERENCE_RECORD,*PREFERENCE_RECORD;
  25. #define REFERENCE_RECORD_SIZE 20
  26. typedef enum _SMBCEDB_OBJECT_TYPE {
  27. SMBCEDB_OT_SERVER,
  28. SMBCEDB_OT_NETROOT,
  29. SMBCEDB_OT_SESSION,
  30. SMBCEDB_OT_REQUEST,
  31. SMBCEDB_OT_VNETROOTCONTEXT,
  32. SMBCEDB_OT_SENTINEL,
  33. SMBCEDB_OT_TRANSPORT
  34. } SMBCEDB_OBJECT_TYPE, *PSMBCEDB_OBJECT_TYPE;
  35. typedef enum _SMBCEDB_OBJECT_STATE_ {
  36. SMBCEDB_ACTIVE, // the instance is in use
  37. SMBCEDB_INVALID, // the instance has been invalidated/disconnected.
  38. SMBCEDB_MARKED_FOR_DELETION, // the instance has been marked for deletion.
  39. SMBCEDB_RECYCLE, // the instance is available for recycling
  40. SMBCEDB_START_CONSTRUCTION, // Initiate construction.
  41. SMBCEDB_CONSTRUCTION_IN_PROGRESS, // the instance construction is in progress
  42. SMBCEDB_DESTRUCTION_IN_PROGRESS, // the instance destruction is in progress
  43. SMBCEDB_RECOVER // the instance need to be recovered
  44. } SMBCEDB_OBJECT_STATE, *PSMBCEDB_OBJECT_STATE;
  45. typedef struct _SMBCE_OBJECT_HEADER_ {
  46. union {
  47. struct {
  48. UCHAR ObjectType; // type of the object
  49. UCHAR ObjectCategory; // Node type for debugging
  50. };
  51. USHORT NodeType;
  52. };
  53. UCHAR Flags; // flags associated with the object, This is implementation dependent
  54. UCHAR Reserved; // padding
  55. LONG SwizzleCount; // Number of swizzled references to this object
  56. LONG State; // State of the object
  57. } SMBCE_OBJECT_HEADER, *PSMBCE_OBJECT_HEADER;
  58. typedef struct _SMBCE_SERVERS_LIST_ {
  59. LIST_ENTRY ListHead;
  60. } SMBCEDB_SERVERS, *PSMBCEDB_SERVERS;
  61. typedef struct _SMBCEDB_SESSIONS_ {
  62. LIST_ENTRY ListHead;
  63. LIST_ENTRY DefaultSessionList;
  64. } SMBCEDB_SESSIONS, *PSMBCEDB_SESSIONS;
  65. typedef struct _SMBCEDB_NET_ROOTS_ {
  66. LIST_ENTRY ListHead;
  67. } SMBCEDB_NET_ROOTS, *PSMBCEDB_NET_ROOTS;
  68. typedef struct _MRX_SMB_V_NET_ROOT_CONTEXTS {
  69. LIST_ENTRY ListHead;
  70. } SMBCE_V_NET_ROOT_CONTEXTS, *PSMBCE_V_NET_ROOT_CONTEXTS;
  71. typedef struct _SMBCEDB_REQUESTS_ {
  72. LIST_ENTRY ListHead;
  73. SMB_MPX_ID NextRequestId;
  74. } SMBCEDB_REQUESTS, *PSMBCEDB_REQUESTS;
  75. typedef enum _SMBCEDB_SERVER_TYPE_ {
  76. SMBCEDB_MAILSLOT_SERVER = 1,
  77. SMBCEDB_FILE_SERVER = 2
  78. } SMBCEDB_SERVER_TYPE, *PSMBCEDB_SERVER_TYPE;
  79. //
  80. // The SMBCEDB_SERVER_ENTRY is the data structure which encapsulates all the information
  81. // w.r.t a remote server for the connection engine. This information includes the dialect
  82. // details as well as the operational data structures required to communicate with the server.
  83. //
  84. // All the dialect related details are further encapsulated in SMBCE_SERVER while the operational
  85. // data structures constitute the remaining parts of the server entry. A pointer to a
  86. // SMBCEDB_SERVER_ENTRY instance is associated with every SRV_CALL that has been hooked
  87. // onto this mini redirector by the wrapper. It is stored in the Context field of MRX_SRV_CALL.
  88. //
  89. // The operational information associated with a server entry includes the Transport related
  90. // information, a collection of requests and a mechanism for associating MID's ( See SMB
  91. // protocol spec.) and a mechanism for posting to threads ( WORK_QUEUE_ITEM ).
  92. //
  93. typedef struct _SMBCEDB_SERVER_ENTRY {
  94. SMBCE_OBJECT_HEADER Header; // struct header.
  95. LIST_ENTRY ServersList; // list of server instances.
  96. PMRX_SRV_CALL pRdbssSrvCall;
  97. UNICODE_STRING Name; // the server name.
  98. UNICODE_STRING DomainName; // the server domain name.
  99. SMBCEDB_SESSIONS Sessions; // the sessions associated with the server
  100. SMBCEDB_NET_ROOTS NetRoots; // the net roots associated with the server.
  101. SMBCE_V_NET_ROOT_CONTEXTS VNetRootContexts; // the V_NET_ROOT contexts
  102. LIST_ENTRY ActiveExchanges; // list of exchanges active for this server
  103. LIST_ENTRY ExpiredExchanges; // exchanges that have been timed out
  104. RX_WORK_QUEUE_ITEM WorkQueueItem; // work queue item for posting
  105. NTSTATUS ServerStatus; // the status of the server as determined by negotiate response
  106. struct _SMBCE_TRANSPORT_ *PreferredTransport;
  107. LONG TransportSpecifiedByUser; // ture if the connection is established on the tranport
  108. // with the name specified
  109. struct SMBCE_SERVER_TRANSPORT *pTransport;
  110. struct SMBCE_SERVER_TRANSPORT *pMailSlotTransport;
  111. SMBCEDB_REQUESTS MidAssignmentRequests;
  112. SMBCEDB_REQUESTS OutstandingRequests;
  113. PMID_ATLAS pMidAtlas;
  114. struct _SMB_EXCHANGE *pNegotiateExchange;
  115. SMBCE_SERVER Server; // the server data structure.
  116. UNICODE_STRING DfsRootName;
  117. UNICODE_STRING DnsName;
  118. PVOID ConstructionContext; // debug only
  119. KEVENT MailSlotTransportRundownEvent;
  120. KEVENT TransportRundownEvent;
  121. BOOLEAN IsTransportDereferenced; // prevent transport from being dereferenced more than once
  122. BOOLEAN NegotiateInProgress; // a negotiate is in progress for this server
  123. BOOLEAN SecuritySignaturesActive; // process the security signature if it is active
  124. BOOLEAN SecuritySignaturesEnabled; // true if the security signature is required by either the
  125. // client or server, and both have the capability.
  126. BOOLEAN ExtSessionSetupInProgress; // a probe server is in progress for security signature
  127. BOOLEAN ResumeRequestsInProgress;
  128. RX_WORK_QUEUE_ITEM WorkQueueItemForResume; // work queue item for posting resume requests
  129. SMBCEDB_REQUESTS SecuritySignatureSyncRequests; // requests waiting on extended session setup for security signature
  130. REFERENCE_RECORD ReferenceRecord[REFERENCE_RECORD_SIZE]; // debug only
  131. RX_WORK_QUEUE_ITEM WorkQueueItemForDisconnect; // work queue item for posting dereference server entry requests
  132. BOOLEAN DisconnectWorkItemOutstanding; // is the disconnect work item in the queue?
  133. RX_CONNECTION_ID ConnectionId;
  134. } SMBCEDB_SERVER_ENTRY, *PSMBCEDB_SERVER_ENTRY;
  135. // The SMBCEDB_NET_ROOT_ENTRY encapsulates all the information associated with a particular
  136. // TREE_CONNECT ( Net use ) made on a server. As with the server entry this data structure
  137. // encapsulates the dialect oriented details as well as the opertaional information
  138. // associated with handling the requests on a net root.
  139. //
  140. // The dialect specific information is encapsulated in the SMBCE_NET_ROOT data structure. A
  141. // pointer to an instance of this data structure is associated with every MRX_NET_ROOT call
  142. // associated with a MRX_SRV_CALL hooked to this mini redirector.
  143. // ********** code.improvement ******* The Name cache control structs should be replaced
  144. // ************************************ with pointers to alloced structs so their size remains the
  145. // ************************************ province of the wrapper.
  146. //
  147. typedef struct _SMBCEDB_NET_ROOT_ENTRY {
  148. SMBCE_OBJECT_HEADER Header; // the struct header
  149. LIST_ENTRY NetRootsList; // the list of net roots asssociated with a server
  150. PMRX_NET_ROOT pRdbssNetRoot; // the associated net root ( purely as a debug aid )
  151. PSMBCEDB_SERVER_ENTRY pServerEntry; // the associated server entry
  152. struct _SMB_EXCHANGE *pExchange; // the exchange which is responsible for construction
  153. SMBCEDB_REQUESTS Requests; // the pending requests for this net root
  154. UNICODE_STRING Name;
  155. ACCESS_MASK MaximalAccessRights;
  156. ACCESS_MASK GuestMaximalAccessRights;
  157. SMBCE_NET_ROOT NetRoot; // the net root data structure.
  158. NAME_CACHE_CONTROL NameCacheCtlGFABasic; // The basic file information name cache control.
  159. NAME_CACHE_CONTROL NameCacheCtlGFAStandard; // The standard file information name cache control.
  160. NAME_CACHE_CONTROL NameCacheCtlGFAInternal; // The internal file information name cache control.
  161. NAME_CACHE_CONTROL NameCacheCtlFNF; // The File not found name cache control.
  162. PFILE_FS_VOLUME_INFORMATION VolumeInfo; // The FS Volume Information cache.
  163. LONG VolumeInfoLength;
  164. LARGE_INTEGER VolumeInfoExpiryTime;
  165. BOOLEAN IsRemoteBoot;
  166. } SMBCEDB_NET_ROOT_ENTRY, *PSMBCEDB_NET_ROOT_ENTRY;
  167. // The SMBCEDB_SESSION_ENTRY encapsulates all the information associated with a session
  168. // established to a remote machine. The session encapsulates all the security information.
  169. // The dialect specific details are encapsulated in teh SMBCE_SESSION data structure. The
  170. // SMBCE_SESSION data structure is available in many flavours depending on the security
  171. // package used. Currently there is support for handling LSA and KERBEROS sessions.
  172. //
  173. // A pointer to an instance of this data structure is associated with every MRX_V_NET_ROOT
  174. // data structure hooked to this mini redirector by the wrapper.
  175. typedef struct _SMBCEDB_SESSION_ENTRY {
  176. SMBCE_OBJECT_HEADER Header; // the struct header
  177. LIST_ENTRY SessionsList; // the list of sessions associated with the server
  178. LIST_ENTRY DefaultSessionLink; // the list of explicit credentials for this server
  179. PSMBCEDB_SERVER_ENTRY pServerEntry; // the associated server entry
  180. struct _SMB_EXCHANGE *pExchange; // the exchange which is responsible for construction
  181. SMBCEDB_REQUESTS Requests; // pending requests
  182. LIST_ENTRY SerializationList; // session construction serialization
  183. PKEVENT pSerializationEvent;
  184. ULONG SessionVCNumber; // the VC number to be packaged with session setup
  185. SMBCE_SESSION Session; // the Session
  186. PUNICODE_STRING pNetRootName; // for share level security only
  187. BOOLEAN SessionRecoverInProgress;
  188. } SMBCEDB_SESSION_ENTRY, *PSMBCEDB_SESSION_ENTRY;
  189. //
  190. // The wrapper exposes three data structures for manipulating and describing
  191. // name spaces set up on remote servers, Viz., MRX_SRV_CALL, MRX_NET_ROOT and
  192. // MRX_V_NET_ROOT. The SRV_CALL corresponds to a remote server, the MRX_NET_ROOT
  193. // corresponds to a share on that machine and V_NET_ROOT encapsulates
  194. // the notion of a view of a MRX_NET_ROOT ( share in SMB terminology)
  195. //
  196. // The mapping between the wrapper level data structures and the SMB notion
  197. // of SMBCEDB_SERVER_ENTRY, SMBCEDB_SESSION_ENTRY and SMBCEDB_NET_ROOT_ENTRY
  198. // is not one to one in all cases.
  199. //
  200. // It is one to one between MRX_SRV_CALL and SMBCEDB_SERVER_ENTRY. It is for this
  201. // reason that a pointer to SMBCEDB_SERVER_ENTRY is stored in the context field
  202. // of the MRX_SRV_CALL instance.
  203. //
  204. // SMBCEDB_SESSION_ENTRY has a one to one mapping with the set of credentials
  205. // supplied to establish a connection to a server. Having established a session
  206. // one can have access to all the shares available on the server.
  207. //
  208. // SMBCEDB_NET_ROOT_ENTRY has a one to one mapping with a share on a given
  209. // server. Since this closely corresponds to the wrappers interpretation of
  210. // MRX_NET_ROOT a pointer to SMBCEDB_NET_ROOT_ENTRY is stored as part of the
  211. // MRX_NET_ROOT instance.
  212. //
  213. // The context associated with every MRX_V_NET_ROOT instance is a pointer to
  214. // an instance of SMBCE_V_NET_ROOT_CONTEXT. This encapsulates the associated session
  215. // entry, the net root entry and the relevant book keeping information.
  216. //
  217. // The bookkeeping information is the UID/TID used in the SMB protocol, a
  218. // reference count and a LIST_ENTRY to thread the instance into the appropriate
  219. // list.
  220. //
  221. #define SMBCE_V_NET_ROOT_CONTEXT_FLAG_VALID_TID (0x1)
  222. #define SMBCE_V_NET_ROOT_CONTEXT_CSCAGENT_INSTANCE (0x2)
  223. typedef struct _SMBCE_V_NET_ROOT_CONTEXT {
  224. SMBCE_OBJECT_HEADER Header;
  225. PMRX_V_NET_ROOT pRdbssVNetRoot; // the associated VNetRoot ( purely as a debug aid)
  226. struct _SMB_EXCHANGE *pExchange; // the exchange which is responsible for construction
  227. SMBCEDB_REQUESTS Requests;
  228. LIST_ENTRY ListEntry;
  229. LARGE_INTEGER ExpireTime;
  230. struct _SMBCEDB_SERVER_ENTRY *pServerEntry;
  231. struct _SMBCEDB_SESSION_ENTRY *pSessionEntry;
  232. struct _SMBCEDB_NET_ROOT_ENTRY *pNetRootEntry;
  233. USHORT Flags;
  234. SMB_TREE_ID TreeId;
  235. REFERENCE_RECORD ReferenceRecord[REFERENCE_RECORD_SIZE]; // debug only
  236. } SMBCE_V_NET_ROOT_CONTEXT, *PSMBCE_V_NET_ROOT_CONTEXT;
  237. //
  238. // An SMBCEDB_REQUEST_ENTRY encapsulates an action being processed by the SMBCE connection
  239. // engine. The requests come in vairous flavours and each of these flavours is associated
  240. // with the appropriate context required for resumption. In order to provide better memory
  241. // management mechanisms the REQUEST_ENTRY encapsulates a union of the requests of various
  242. // flavours. Each SERVER_ENTRY in the connection engine is associated with a list or
  243. // request entries. In order to hide the abstraction of a list which does not scale well to
  244. // the case of GATEWAY redirectors a set of routines are provided to manipulate the
  245. // collection of requests. They provide a mechanism for intializing the collection of requests,
  246. // adding a request, deleting a request and enumeratiung requests in a collection.
  247. //
  248. // Special mechanisms are built in to handle batching of operations. Each operation on the
  249. // collection of requests come in two flavours, a vanila version and a lite version. In the
  250. // lite version it is assumed that the appropriate concurrency control action has been taken
  251. //
  252. // One common scenario that is often encountered in processing the requests is invocation
  253. // of a specific function on the requests in the collection. As an example if a disconnect
  254. // request is received on a server entry then all the outstanding requests must be resumed
  255. // with the appropriate error. Since these indications can potentially occur at DPC levels in
  256. // NT it is not desirable to manipulate the collection while holding onto a spinlock, nor is
  257. // it desirable to repeatedly release and accquire the spin lock. A special operation is
  258. // provided for transferring the requests enmasse from one collection to another and resetting
  259. // the original. With the help of this operation it is sufficient to hold the spinlock only
  260. // for the duration of the transfer. The remainder of the processing can be done on the newly
  261. // created collection.
  262. //
  263. //
  264. // NT Specific Implementation Note:
  265. //
  266. // On NT the transport indications are at DPC level, therefore it is required to protect
  267. // the manipulation of the requests data structure with a spinlock.
  268. //
  269. //
  270. typedef struct _SMBCEDB_REQUEST_ENTRY_ {
  271. SMBCE_OBJECT_HEADER Header; // the struct header
  272. LIST_ENTRY RequestsList; // the next request for the VC.
  273. union {
  274. SMBCE_GENERIC_REQUEST GenericRequest;
  275. SMBCE_REQUEST Request; // the next request.
  276. SMBCE_COPY_DATA_REQUEST CopyDataRequest;
  277. SMBCE_RECONNECT_REQUEST ReconnectRequest;
  278. SMBCE_MID_REQUEST MidRequest;
  279. };
  280. } SMBCEDB_REQUEST_ENTRY, *PSMBCEDB_REQUEST_ENTRY;
  281. #define SmbCeInitializeRequests(pRequests) \
  282. InitializeListHead(&(pRequests)->ListHead); \
  283. (pRequests)->NextRequestId = 0
  284. #define SmbCeAddRequestEntry(pRequestList,pRequestEntry) \
  285. SmbCeAcquireSpinLock(); \
  286. InsertTailList(&(pRequestList)->ListHead,&(pRequestEntry)->RequestsList); \
  287. SmbCeReleaseSpinLock()
  288. #define SmbCeAddRequestEntryLite(pRequestList,pRequestEntry) \
  289. InsertTailList(&(pRequestList)->ListHead,&(pRequestEntry)->RequestsList)
  290. #define SmbCeRemoveRequestEntry(pRequests,pEntry) \
  291. SmbCeAcquireSpinLock(); \
  292. RemoveEntryList(&(pEntry)->RequestsList); \
  293. SmbCeReleaseSpinLock()
  294. #define SmbCeRemoveRequestEntryLite(pRequests,pEntry) \
  295. RemoveEntryList(&(pEntry)->RequestsList)
  296. #define SmbCeGetFirstRequestEntry(pRequestList) \
  297. (IsListEmpty(&(pRequestList)->ListHead) \
  298. ? NULL \
  299. : (PSMBCEDB_REQUEST_ENTRY) \
  300. (CONTAINING_RECORD((pRequestList)->ListHead.Flink, \
  301. SMBCEDB_REQUEST_ENTRY, \
  302. RequestsList)))
  303. #define SmbCeGetNextRequestEntry(pRequestList,pRequestEntry) \
  304. (((pRequestEntry)->RequestsList.Flink == &(pRequestList)->ListHead) \
  305. ? NULL \
  306. : (PSMBCEDB_REQUEST_ENTRY) \
  307. (CONTAINING_RECORD((pRequestEntry)->RequestsList.Flink, \
  308. SMBCEDB_REQUEST_ENTRY, \
  309. RequestsList)))
  310. #define SmbCeTransferRequests(pDestination,pSource) \
  311. if (IsListEmpty(&(pSource)->ListHead)) { \
  312. SmbCeInitializeRequests((pDestination)); \
  313. } else { \
  314. *(pDestination) = *(pSource); \
  315. (pDestination)->ListHead.Flink->Blink = &(pDestination)->ListHead; \
  316. (pDestination)->ListHead.Blink->Flink = &(pDestination)->ListHead; \
  317. SmbCeInitializeRequests((pSource)); \
  318. }
  319. // Much along the lines of a collection of request a collection of all server entries is
  320. // maintained as part of the connection engine. The following operations are supported on
  321. // the colection of server entries
  322. // 1) adding a server entry to the collection
  323. // 2) removing a server entry from the colection
  324. // 3) enumerating the entries in the collection
  325. //
  326. // As in the case of the collection of requests all these operations come in two flavours
  327. // the vanila version in which concurrency control is enforced and the lite version in
  328. // which the concurrency control is left to the user's discretion.
  329. #define SmbCeAddServerEntry(pServerEntry) \
  330. SmbCeAcquireSpinLock(); \
  331. InsertTailList(&s_DbServers.ListHead,&pServerEntry->ServersList); \
  332. SmbCeReleaseSpinLock()
  333. #define SmbCeAddServerEntryLite(pServerEntry) \
  334. InsertTailList(&s_DbServers.ListHead,&pServerEntry->ServersList)
  335. #define SmbCeRemoveServerEntry(pServerEntry) \
  336. SmbCeAcquireSpinLock(); \
  337. RemoveEntryList(&(pServerEntry)->ServersList); \
  338. SmbCeReleaseSpinLock()
  339. #define SmbCeRemoveServerEntryLite(pServerEntry) \
  340. RemoveEntryList(&(pServerEntry)->ServersList)
  341. #define SmbCeGetFirstServerEntry() \
  342. (IsListEmpty(&s_DbServers.ListHead) \
  343. ? NULL \
  344. : (PSMBCEDB_SERVER_ENTRY) \
  345. (CONTAINING_RECORD(s_DbServers.ListHead.Flink, \
  346. SMBCEDB_SERVER_ENTRY, \
  347. ServersList)))
  348. #define SmbCeGetNextServerEntry(pServerEntry) \
  349. (((pServerEntry)->ServersList.Flink == &s_DbServers.ListHead) \
  350. ? NULL \
  351. : (PSMBCEDB_SERVER_ENTRY) \
  352. (CONTAINING_RECORD((pServerEntry)->ServersList.Flink, \
  353. SMBCEDB_SERVER_ENTRY, \
  354. ServersList)))
  355. // Since the mapping between V_NET_ROOT's in the RDBSS and the session entries in the mini
  356. // redirector is a many to one mapping a collection of session entries is maintained as part
  357. // of each server entry. The following operations are supported on the collection of session
  358. // entries
  359. // 1) adding a session entry to the collection
  360. // 2) removing a session entry from the colection
  361. // 3) enumerating the entries in the collection
  362. //
  363. // As in the case of the collection of requests all these operations come in two flavours
  364. // the vanila version in which concurrency control is enforced and the lite version in
  365. // which the concurrency control is left to the user's discretion.
  366. //
  367. // In addition two more methods are specified for retrieving the default session entry and
  368. // setting the default session entry for any given server.
  369. #define SmbCeAddSessionEntry(pServerEntry,pSessionEntry) \
  370. SmbCeAcquireSpinLock(); \
  371. InsertTailList(&(pServerEntry)->Sessions.ListHead,&(pSessionEntry)->SessionsList); \
  372. SmbCeReleaseSpinLock()
  373. #define SmbCeAddSessionEntryLite(pServerEntry,pSessionEntry) \
  374. InsertTailList(&(pServerEntry)->Sessions.ListHead,&(pSessionEntry)->SessionsList)
  375. #define SmbCeRemoveSessionEntry(pServerEntry,pSessionEntry) \
  376. SmbCeAcquireSpinLock(); \
  377. if ((pSessionEntry)->DefaultSessionLink.Flink != NULL) { \
  378. RemoveEntryList(&(pSessionEntry)->DefaultSessionLink); \
  379. pSessionEntry->DefaultSessionLink.Flink = NULL; \
  380. pSessionEntry->DefaultSessionLink.Blink = NULL; \
  381. }; \
  382. RemoveEntryList(&(pSessionEntry)->SessionsList); \
  383. SmbCeReleaseSpinLock()
  384. #define SmbCeRemoveSessionEntryLite(pServerEntry,pSessionEntry) \
  385. ASSERT( SmbCeSpinLockAcquired() ); \
  386. if ((pSessionEntry)->DefaultSessionLink.Flink != NULL) { \
  387. RemoveEntryList(&(pSessionEntry)->DefaultSessionLink); \
  388. pSessionEntry->DefaultSessionLink.Flink = NULL; \
  389. pSessionEntry->DefaultSessionLink.Blink = NULL; \
  390. }; \
  391. RemoveEntryList(&(pSessionEntry)->SessionsList);
  392. #define SmbCeGetFirstSessionEntry(pServerEntry) \
  393. (IsListEmpty(&(pServerEntry)->Sessions.ListHead) \
  394. ? NULL \
  395. : (PSMBCEDB_SESSION_ENTRY) \
  396. (CONTAINING_RECORD((pServerEntry)->Sessions.ListHead.Flink, \
  397. SMBCEDB_SESSION_ENTRY, \
  398. SessionsList)))
  399. #define SmbCeGetNextSessionEntry(pServerEntry,pSessionEntry) \
  400. (((pSessionEntry)->SessionsList.Flink == \
  401. &(pServerEntry)->Sessions.ListHead) \
  402. ? NULL \
  403. : (PSMBCEDB_SESSION_ENTRY) \
  404. (CONTAINING_RECORD((pSessionEntry)->SessionsList.Flink, \
  405. SMBCEDB_SESSION_ENTRY, \
  406. SessionsList)))
  407. #define SmbCeSetDefaultSessionEntry(pServerEntry,pSessionEntry) \
  408. SmbCeAcquireSpinLock(); \
  409. if ((pSessionEntry)->DefaultSessionLink.Flink == NULL) { \
  410. ASSERT( pSessionEntry->DefaultSessionLink.Blink == NULL ); \
  411. InsertHeadList(&(pServerEntry)->Sessions.DefaultSessionList,&(pSessionEntry)->DefaultSessionLink); \
  412. }; \
  413. SmbCeReleaseSpinLock()
  414. extern PSMBCEDB_SESSION_ENTRY
  415. SmbCeGetDefaultSessionEntry(
  416. PSMBCEDB_SERVER_ENTRY pServerEntry,
  417. ULONG SessionId,
  418. PLUID pLogonId
  419. );
  420. VOID
  421. SmbCeRemoveDefaultSessionEntry(
  422. PSMBCEDB_SESSION_ENTRY pDefaultSessionEntry
  423. );
  424. // In order to encapsulate the notion of reconnects and to provide for hot reconnects,
  425. // i.e., reconnection attempts in which the saved state in the server/client prior to
  426. // a transport level disconnect can be reused it is required to mark each net root
  427. // entry associated with a server as invalid on receipt of a transport level disconnect.
  428. //
  429. // Therefore an abstraction of a collection of net root entries is provided and is associated
  430. // with each server entry.
  431. //
  432. // The following operations are supported on the collection of net root entries
  433. // 1) adding a net root entry to the collection
  434. // 2) removing a net root entry from the colection
  435. // 3) enumerating the entries in the collection
  436. //
  437. // As in the case of the collection of requests all these operations come in two flavours
  438. // the vanila version in which concurrency control is enforced and the lite version in
  439. // which the concurrency control is left to the user's discretion.
  440. //
  441. #define SmbCeAddNetRootEntry(pServerEntry,pNetRootEntry) \
  442. SmbCeAcquireSpinLock(); \
  443. InsertTailList(&(pServerEntry)->NetRoots.ListHead,&(pNetRootEntry)->NetRootsList); \
  444. SmbCeReleaseSpinLock()
  445. #define SmbCeAddNetRootEntryLite(pServerEntry,pNetRootEntry) \
  446. InsertTailList(&(pServerEntry)->NetRoots.ListHead,&(pNetRootEntry)->NetRootsList)
  447. #define SmbCeRemoveNetRootEntry(pServerEntry,pNetRootEntry) \
  448. SmbCeAcquireSpinLock(); \
  449. RemoveEntryList(&(pNetRootEntry)->NetRootsList); \
  450. SmbCeReleaseSpinLock()
  451. #define SmbCeRemoveNetRootEntryLite(pServerEntry,pNetRootEntry) \
  452. RemoveEntryList(&(pNetRootEntry)->NetRootsList)
  453. #define SmbCeGetFirstNetRootEntry(pServerEntry) \
  454. (IsListEmpty(&(pServerEntry)->NetRoots.ListHead) \
  455. ? NULL \
  456. : (PSMBCEDB_NET_ROOT_ENTRY) \
  457. (CONTAINING_RECORD((pServerEntry)->NetRoots.ListHead.Flink, \
  458. SMBCEDB_NET_ROOT_ENTRY, \
  459. NetRootsList)))
  460. #define SmbCeGetNextNetRootEntry(pServerEntry,pNetRootEntry) \
  461. (((pNetRootEntry)->NetRootsList.Flink == \
  462. &(pServerEntry)->NetRoots.ListHead) \
  463. ? NULL \
  464. : (PSMBCEDB_NET_ROOT_ENTRY) \
  465. (CONTAINING_RECORD((pNetRootEntry)->NetRootsList.Flink, \
  466. SMBCEDB_NET_ROOT_ENTRY, \
  467. NetRootsList)))
  468. // Macros to manipulate the collection of SMBCE_V_NET_ROOT_CONTEXT instances.
  469. #define SmbCeAddVNetRootContext(pVNetRootContexts,pVNetRootContext) \
  470. SmbCeAcquireSpinLock(); \
  471. InsertTailList(&(pVNetRootContexts)->ListHead,&(pVNetRootContext)->ListEntry); \
  472. SmbCeReleaseSpinLock()
  473. #define SmbCeAddVNetRootContextLite(pVNetRootContexts,pVNetRootContext) \
  474. InsertTailList(&(pVNetRootContexts)->ListHead,&(pVNetRootContext)->ListEntry)
  475. #define SmbCeRemoveVNetRootContext(pVNetRootContexts,pVNetRootContext) \
  476. SmbCeAcquireSpinLock(); \
  477. RemoveEntryList(&(pVNetRootContext)->ListEntry); \
  478. SmbCeReleaseSpinLock()
  479. #define SmbCeRemoveVNetRootContextLite(pVNetRootContexts,pVNetRootContext) \
  480. RemoveEntryList(&(pVNetRootContext)->ListEntry)
  481. #define SmbCeGetFirstVNetRootContext(pVNetRootContexts) \
  482. (IsListEmpty(&((pVNetRootContexts)->ListHead)) \
  483. ? NULL \
  484. : (PSMBCE_V_NET_ROOT_CONTEXT) \
  485. (CONTAINING_RECORD((pVNetRootContexts)->ListHead.Flink, \
  486. SMBCE_V_NET_ROOT_CONTEXT, \
  487. ListEntry)))
  488. #define SmbCeGetNextVNetRootContext(pVNetRootContexts,pVNetRootContext) \
  489. (((pVNetRootContext)->ListEntry.Flink == \
  490. &(pVNetRootContexts)->ListHead) \
  491. ? NULL \
  492. : (PSMBCE_V_NET_ROOT_CONTEXT) \
  493. (CONTAINING_RECORD((pVNetRootContext)->ListEntry.Flink, \
  494. SMBCE_V_NET_ROOT_CONTEXT, \
  495. ListEntry)))
  496. //
  497. // SmbCe database initialization
  498. //
  499. extern NTSTATUS
  500. SmbCeDbInit();
  501. extern VOID
  502. SmbCeDbTearDown();
  503. //
  504. // Object allocation and deallocation
  505. //
  506. extern PSMBCE_OBJECT_HEADER
  507. SmbCeDbAllocateObject(
  508. SMBCEDB_OBJECT_TYPE ObjectType);
  509. extern VOID
  510. SmbCeDbFreeObject(
  511. PVOID pObject);
  512. //
  513. // Object destruction
  514. //
  515. extern VOID
  516. SmbCeTearDownServerEntry(PSMBCEDB_SERVER_ENTRY pServerEntry);
  517. extern VOID
  518. SmbCeTearDownNetRootEntry(PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry);
  519. extern VOID
  520. SmbCeTearDownSessionEntry(PSMBCEDB_SESSION_ENTRY pSessionEntry);
  521. extern VOID
  522. SmbCeTearDownRequestEntry(PSMBCEDB_REQUEST_ENTRY pRequestEntry);
  523. //
  524. // The routines for mapping a MID with an exchange and for associating an exchange with
  525. // a MID
  526. //
  527. extern NTSTATUS
  528. SmbCeAssociateExchangeWithMid(
  529. PSMBCEDB_SERVER_ENTRY pServerEntry,
  530. struct _SMB_EXCHANGE *pExchange);
  531. extern struct _SMB_EXCHANGE *
  532. SmbCeMapMidToExchange(
  533. PSMBCEDB_SERVER_ENTRY pServerEntry,
  534. SMB_MPX_ID Mid);
  535. extern NTSTATUS
  536. SmbCeDissociateMidFromExchange(
  537. PSMBCEDB_SERVER_ENTRY pServerEntry,
  538. struct _SMB_EXCHANGE *pExchange);
  539. extern struct _SMB_EXCHANGE *
  540. SmbCeGetExchangeAssociatedWithBuffer(
  541. PSMBCEDB_SERVER_ENTRY pServerEntry,
  542. PVOID pBuffer);
  543. extern NTSTATUS
  544. SmbCeAssociateBufferWithExchange(
  545. PSMBCEDB_SERVER_ENTRY pServerEntry,
  546. struct _SMB_EXCHANGE * pExchange,
  547. PVOID pBuffer);
  548. extern VOID
  549. SmbCePurgeBuffersAssociatedWithExchange(
  550. PSMBCEDB_SERVER_ENTRY pServerEntry,
  551. struct _SMB_EXCHANGE * pExchange);
  552. extern NTSTATUS
  553. SmbCepDiscardMidAssociatedWithExchange(
  554. struct _SMB_EXCHANGE * pExchange);
  555. extern VOID
  556. SmbCeResumeDiscardedMidAssignmentRequests(
  557. PSMBCEDB_REQUESTS pMidRequests,
  558. NTSTATUS ResumptionStatus);
  559. //
  560. // Routines for handling transport disconnects/invalidation.
  561. //
  562. extern VOID
  563. SmbCeTransportDisconnectIndicated(
  564. PSMBCEDB_SERVER_ENTRY pServerEntry);
  565. extern VOID
  566. SmbCeResumeAllOutstandingRequestsOnError(
  567. PSMBCEDB_SERVER_ENTRY pServerEntry);
  568. extern VOID
  569. SmbCeHandleTransportInvalidation(
  570. struct _SMBCE_TRANSPORT_ *pTransport);
  571. extern VOID
  572. SmbCeFinalizeAllExchangesForNetRoot(
  573. PMRX_NET_ROOT pNetRoot);
  574. extern NTSTATUS
  575. MRxSmbCheckForLoopBack(
  576. IN PSMBCEDB_SERVER_ENTRY pServerEntry);
  577. //
  578. // Resource acquistion/release
  579. //
  580. PVOID SmbCeDbResourceAcquireFile;
  581. ULONG SmbCeDbResourceAcquireLine;
  582. #define SmbCeAcquireResource() \
  583. KeEnterCriticalRegion(); \
  584. ExAcquireResourceExclusiveLite(&s_SmbCeDbResource,TRUE);\
  585. SmbCeDbResourceAcquireFile = __FILE__;\
  586. SmbCeDbResourceAcquireLine = __LINE__
  587. #define SmbCeReleaseResource() \
  588. SmbCeDbResourceAcquireFile = NULL;\
  589. SmbCeDbResourceAcquireLine = 0;\
  590. ExReleaseResourceLite(&s_SmbCeDbResource);\
  591. KeLeaveCriticalRegion()
  592. #define SmbCeIsResourceOwned() ExIsResourceAcquiredExclusiveLite(&s_SmbCeDbResource)
  593. #define SmbCeAcquireSpinLock() \
  594. KeAcquireSpinLock(&s_SmbCeDbSpinLock,&s_SmbCeDbSpinLockSavedIrql); \
  595. s_SmbCeDbSpinLockAcquired = TRUE
  596. #define SmbCeReleaseSpinLock() \
  597. s_SmbCeDbSpinLockAcquired = FALSE; \
  598. KeReleaseSpinLock(&s_SmbCeDbSpinLock,s_SmbCeDbSpinLockSavedIrql)
  599. #define SmbCeSpinLockAcquired() \
  600. (s_SmbCeDbSpinLockAcquired == TRUE)
  601. #define SmbCeAcquireSecuritySignatureResource() \
  602. ExAcquireResourceExclusiveLite(&s_SmbSecuritySignatureResource,TRUE)
  603. #define SmbCeReleaseSecuritySignatureResource() \
  604. ExReleaseResourceLite(&s_SmbSecuritySignatureResource)
  605. //INLINE BOOLEAN SmbCeDbIsEntryInUse(PSMBCE_OBJECT_HEADER pHeader)
  606. /*++
  607. Routine Description:
  608. This routine determines if a SmbCe database entry is in use.
  609. Arguments:
  610. pHeader - the entry header
  611. Return Value:
  612. TRUE if the entry is in use otherwise FALSE
  613. --*/
  614. #define SmbCeIsEntryInUse(pHeader) \
  615. (((PSMBCE_OBJECT_HEADER)(pHeader))->State == SMBCEDB_ACTIVE || \
  616. ((PSMBCE_OBJECT_HEADER)(pHeader))->State == SMBCEDB_INVALID || \
  617. ((PSMBCE_OBJECT_HEADER)(pHeader))->State == SMBCEDB_CONSTRUCTION_IN_PROGRESS)
  618. #define SmbCeSetServerType(pServerEntry,ServerType) \
  619. (pServerEntry)->Header.Flags = (UCHAR)(ServerType)
  620. #define SmbCeGetServerType(pServerEntry) \
  621. ((SMBCEDB_SERVER_TYPE)(pServerEntry)->Header.Flags)
  622. //
  623. // Static variable declarations that constitute the SmbCe database.
  624. //
  625. extern SMBCEDB_SERVERS s_DbServers;
  626. //
  627. // Currently there is only one resource for synchronizing the access to all the
  628. // entities in the connection engine database. It is possible to customize it
  629. // subsequently since the acquistion/release methods take the type of the object
  630. // as a parameter.
  631. //
  632. extern ERESOURCE s_SmbCeDbResource;
  633. extern RX_SPIN_LOCK s_SmbCeDbSpinLock;
  634. extern KIRQL s_SmbCeDbSpinLockSavedIrql;
  635. extern BOOLEAN s_SmbCeDbSpinLockAcquired;
  636. #endif // _SMBCEDBP_H_
  637.