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.

740 lines
34 KiB

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