Windows NT 4.0 source code leak
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.

475 lines
18 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. connect.h
  5. Abstract:
  6. This module defines the structures used by the NT redirectors connection
  7. management package.
  8. Author:
  9. Larry Osterman (LarryO) 1-Jun-1990
  10. Revision History:
  11. 1-Jun-1990 LarryO
  12. Created
  13. --*/
  14. #ifndef _CONNECT_
  15. #define _CONNECT_
  16. //
  17. // Connection types.
  18. //
  19. // This enum describes the connection types possible for the NT redir.
  20. //
  21. // WARNING: DO NOT MODIFY THIS LIST WITHOUT MODIFYING THE ConnectTypeList
  22. // IN CONNECT.C.!!
  23. //
  24. #define CONNECT_WILD -1
  25. #define CONNECT_DISK 0
  26. #define CONNECT_PRINT 1
  27. #define CONNECT_COMM 2
  28. #define CONNECT_IPC 3
  29. //
  30. // Dialect flags
  31. //
  32. // These flags describe the various and sundry capabilities that
  33. // a server can provide.
  34. //
  35. #define DF_CORE 0x00000001 // Server is a core server
  36. #define DF_MIXEDCASEPW 0x00000002 // Server supports mixed case password
  37. #define DF_OLDRAWIO 0x00000004 // Server supports MSNET 1.03 RAW I/O
  38. #define DF_NEWRAWIO 0x00000008 // Server supports LANMAN Raw I/O
  39. #define DF_LANMAN10 0x00000010 // Server supports LANMAN 1.0 protocol
  40. #define DF_LANMAN20 0x00000020 // Server supports LANMAN 2.0 protocol
  41. #define DF_MIXEDCASE 0x00000040 // Server supports mixed case files
  42. #define DF_LONGNAME 0x00000080 // Server supports long named files
  43. #define DF_EXTENDNEGOT 0x00000100 // Server returns extended negotiate
  44. #define DF_LOCKREAD 0x00000200 // Server supports LockReadWriteUnlock
  45. #define DF_SECURITY 0x00000400 // Server supports enhanced security
  46. #define DF_NTPROTOCOL 0x00000800 // Server supports NT semantics
  47. #define DF_SUPPORTEA 0x00001000 // Server supports extended attribs
  48. #define DF_LANMAN21 0x00002000 // Server supports LANMAN 2.1 protocol
  49. #define DF_CANCEL 0x00004000 // Server supports NT style cancel
  50. #define DF_UNICODE 0x00008000 // Server supports unicode names.
  51. #define DF_NTNEGOTIATE 0x00010000 // Server supports NT style negotiate.
  52. #define DF_LARGE_FILES 0x00020000 // Server supports large files.
  53. #define DF_NT_SMBS 0x00040000 // Server supports NT SMBs
  54. #define DF_RPC_REMOTE 0x00080000 // Server is administrated via RPC
  55. #define DF_NT_STATUS 0x00100000 // Server returns NT style statuses
  56. #define DF_OPLOCK_LVL2 0x00200000 // Server supports level 2 oplocks.
  57. #define DF_TIME_IS_UTC 0x00400000 // Server time is in UTC.
  58. #define DF_WFW 0x00800000 // Server is Windows for workgroups.
  59. #define DF_LARGE_READX 0x01000000 // Server supports oversized ReadAndX requests
  60. #ifdef _CAIRO_
  61. #define DF_KERBEROS 0x01000000 // Server does kerberos authentication
  62. #endif // _CAIRO_
  63. #define DF_TRANS2_FSCTL 0x02000000 // Server accepts remoted fsctls in tran2s
  64. #define DF_DFSAWARE 0x04000000 // Server is Dfs aware
  65. #define DF_NT_FIND 0x08000000 // Server supports NT infolevels
  66. #define DF_NT_40 0x10000000 // Server is NT 4.0
  67. //
  68. // Timeout for failed connects. If a new connect attempt comes in within
  69. // FAILED_CONNECT_TIMEOUT seconds after a failed connect, the new one fails
  70. // with the same status as the failed connect.
  71. //
  72. #define FAILED_CONNECT_TIMEOUT 10
  73. //
  74. //
  75. // ServerListEntry flags
  76. //
  77. //
  78. #define SLE_PAGING_FILE 0x00000001 // There is a paging file on this server
  79. #define SLE_PINGING 0x00000002 // Ping outstanding on TC.
  80. #define SLE_HAS_IP_ADDR 0x00000004 // SLE has IP and NB address info
  81. //
  82. //
  83. // ServerListEntry
  84. //
  85. // The ServerListEntry contains all the information needed to describe
  86. // a discrete server that the NT redirector is connected to.
  87. //
  88. //
  89. //
  90. // Each ServerList entry contains two resource structures. One protects
  91. // the "disconnected" bit in the serverlistentry's Flags field.
  92. //
  93. // The other one is somewhat more interesting. This resource is used
  94. // to gate raw I/O operations to the remote server. The generic SMB
  95. // exchange routines will acquire the resource for shared access. This
  96. // has no effect for the threads that acquire the resource.
  97. //
  98. // When the redirector is about to try to exchange an SMB with the server
  99. // using raw protocols, the Read/Write logic will attempt to acquire the
  100. // resource for exclusive access. If the attempt to gain access to the
  101. // resource fails, the redirector will use core protocols, if it succeeds,
  102. // the redirector will know that this is the only thread in the system
  103. // performing I/O to the remote server, and that it has exclusive access
  104. // to the server. Any subsequent operations to the server will block
  105. // while trying to acquire the resource for shared access until the raw
  106. // operation has completed.
  107. //
  108. //
  109. typedef struct _SERVERLISTENTRY {
  110. CSHORT Signature; //* Serverlist Signature.
  111. CSHORT Size; //* Serverlist Size.
  112. ULONG RefCount; //1 Number of references to SList.
  113. ULONG Flags; //3 Temporary flags about SLE.
  114. ULONG Capabilities; //3 Server capabilities mask.
  115. UNICODE_STRING Text; //* Name of serverlist (LOTHAIR)
  116. //
  117. // The rdr allows connecting to servers via its NetBIOS name, DNS name,
  118. // or \\IP-Address name. We need to set the VcNumber field correctly when
  119. // we have connected to the same server via its different names, or the
  120. // server will only keep one VC alive. So, we capture the server's
  121. // NetBIOS name and IPAddress. The NetBIOS name will be the same as
  122. // the 'Text' field only if 'Text' is the NetBIOS name and we connected
  123. // to the server via NetBT.
  124. //
  125. UNICODE_STRING NBName; //* The NetBIOS name of server
  126. WCHAR NBNameBuffer[16]; //* The buffer for NBName
  127. TDI_ADDRESS_IP IPAddress; //* IP Address of server
  128. NTSTATUS LastConnectStatus;
  129. ULONG LastConnectTime;
  130. #ifdef _CAIRO_
  131. UNICODE_STRING Principal; //3 Name of principal (fully qualified name)
  132. #endif // _CAIRO_
  133. UNICODE_STRING DomainName; // name of remote domain
  134. LIST_ENTRY GlobalNext; //1 Next ServerList structure.
  135. LIST_ENTRY CLEHead; //1 Pointer to ConnectList chain.
  136. LIST_ENTRY DefaultSeList; //5 List of default security entries
  137. LIST_ENTRY ActiveSecurityList; //3 Security Entries on this connection.
  138. LIST_ENTRY PotentialSecurityList; //2 Security Entries on this connection.
  139. LIST_ENTRY ScavengerList; // scavenging list.
  140. PTRANSPORT SpecificTransportProvider;
  141. BOOLEAN IsLoopback; // is this a loopback connection?
  142. BOOLEAN InCancel; //7 True if MPX entries are being scavenged
  143. LARGE_INTEGER TimeZoneBias; //3 NT Time bias to convert to server time
  144. ULONG ConnectionReferenceCount; //3
  145. PRDR_CONNECTION_CONTEXT ConnectionContext; // 3
  146. LONG SecurityEntryCount; //3 Number of security entries.
  147. ULONG SessionKey; //3 Servers session key.
  148. ULONG BufferSize; //3 Servers negotiated buffer size.
  149. USHORT MaximumRequests; //3 Maximum number of outstanding req's
  150. USHORT MaximumVCs; //3 Maximum number of VC's
  151. //
  152. // Fields describing MPX exchange mechanism in this transport connection.
  153. //
  154. //
  155. // A MID (Mpx ID) is composed of two pieces. The low order bits
  156. // are an index into the Mpx Table, the high order bits form a rotating
  157. // counter. This allows all of the MID's issued by the redirector to
  158. // be unique.
  159. //
  160. //
  161. // Pointer to MPX entry table
  162. //
  163. struct _MPX_TABLE *MpxTable; //7 Start of MPX table for VC.
  164. struct _MPX_ENTRY *OpLockMpxEntry; //7 MpxEntry for oplock break on VC.
  165. //
  166. // Number of MPX entries in the current MPX table.
  167. //
  168. ULONG NumberOfEntries; //7 Actual number of entries in list.
  169. //
  170. // Number of outstanding entries in the table at this time.
  171. //
  172. ULONG NumberOfActiveEntries; //7 Number of outstanding entries.
  173. //
  174. // Number of outstanding long term entries in the table at this time.
  175. //
  176. ULONG NumberOfLongTermEntries; //7 Number of outstanding longterm entries.
  177. //
  178. // Maximum number of commands to this server.
  179. //
  180. ULONG MaximumCommands; //7 Max Number of commands for server
  181. //
  182. // This reflects the current value of the rotating MPX counter.
  183. //
  184. USHORT MultiplexedCounter; //7
  185. //
  186. // Adding this value to MpxCounter steps the counter to the next
  187. // counter value.
  188. //
  189. USHORT MultiplexedIncrement; //*
  190. //
  191. // Masking a Mid with this value will result in an index into the MPX table.
  192. //
  193. USHORT MultiplexedMask; //*
  194. USHORT CryptKeyLength; //3 Size of encryption key.
  195. KSEMAPHORE GateSemaphore; // Semaphore gating access to server.
  196. ERESOURCE CreationLock; // Resource synchronizing file creates
  197. // with tree connection modifications
  198. ERESOURCE SessionStateModifiedLock;// Lock synchronizing connect/reconnect
  199. ERESOURCE OutstandingRequestResource;// Resource to prevent disconnect
  200. // while there are outstanding operations
  201. ERESOURCE RawResource; // Resource protecting raw operations.
  202. //
  203. // Calculated maximum number of bytes for RawReads
  204. //
  205. ULONG RawReadMaximum;
  206. //
  207. // Calculated maximum number of bytes for RawWrites
  208. //
  209. ULONG RawWriteMaximum;
  210. //
  211. // Transport provided performance data.
  212. //
  213. ULONG Throughput; //3 Throughput of link in bytes/second
  214. ULONG Delay; //3 Overhead of protocol (small packet time)
  215. ULONG WriteBehindPages; //3 Maximum number of dirty pages for open files.
  216. LARGE_INTEGER ThirtySecondsOfData; //3 # of bytes that can be written in 30 seconds
  217. BOOLEAN Reliable; //3 Transport considers connection reliable
  218. BOOLEAN ReadAhead; //3 Throughput is high enough to enable readahead
  219. BOOLEAN ConnectionValid; //3 True IFF connection is valid.
  220. BOOLEAN DisconnectNeeded; //3 True IFF disconnect is needed on connection.
  221. BOOLEAN UserSecurity; //3 TRUE if user level security
  222. BOOLEAN EncryptPasswords; //3 TRUE if encryption supported.
  223. BOOLEAN SupportsRawRead; //3 TRUE iff server supports raw read.
  224. BOOLEAN SupportsRawWrite; //3 TRUE iff server supports raw write.
  225. BOOLEAN Scanning; //4 Rdr will scan reliability and throughput
  226. UCHAR CryptKey[CRYPT_TXT_LEN]; //* Encryption key.
  227. #ifdef RDRDBG_REQUEST_RESOURCE
  228. KSPIN_LOCK RequestHistoryLock;
  229. ULONG RequestHistoryIndex;
  230. ULONG RequestHistory[64];
  231. #endif
  232. } SERVERLISTENTRY, *PSERVERLISTENTRY;
  233. #ifndef RDRDBG_REQUEST_RESOURCE
  234. #define ACQUIRE_REQUEST_RESOURCE_EXCLUSIVE(_server,_wait,_num) ExAcquireResourceExclusive( &(_server)->OutstandingRequestResource, (_wait) )
  235. #define ACQUIRE_REQUEST_RESOURCE_SHARED(_server,_wait,_num) ExAcquireResourceShared( &(_server)->OutstandingRequestResource, (_wait) )
  236. #define RELEASE_REQUEST_RESOURCE(_server,_num) ExReleaseResource( &(_server)->OutstandingRequestResource )
  237. #define RELEASE_REQUEST_RESOURCE_FOR_THREAD(_server,_thread,_num) ExReleaseResourceForThread( &(_server)->OutstandingRequestResource, (_thread) )
  238. #else
  239. BOOLEAN AcquireRequestResourceExclusive( PSERVERLISTENTRY Server, BOOLEAN Wait, UCHAR Number );
  240. BOOLEAN AcquireRequestResourceShared( PSERVERLISTENTRY Server, BOOLEAN Wait, UCHAR Number );
  241. VOID ReleaseRequestResource( PSERVERLISTENTRY Server, UCHAR Number );
  242. VOID ReleaseRequestResourceForThread( PSERVERLISTENTRY Server, ERESOURCE_THREAD Thread, UCHAR Number );
  243. #define ACQUIRE_REQUEST_RESOURCE_EXCLUSIVE(_server,_wait,_num) AcquireRequestResourceExclusive( (_server), (_wait), (_num) )
  244. #define ACQUIRE_REQUEST_RESOURCE_SHARED(_server,_wait,_num) AcquireRequestResourceShared( (_server), (_wait), (_num) )
  245. #define RELEASE_REQUEST_RESOURCE(_server,_num) ReleaseRequestResource( (_server), (_num) )
  246. #define RELEASE_REQUEST_RESOURCE_FOR_THREAD(_server,_thread,_num) ReleaseRequestResourceForThread( (_server), (_thread), (_num) )
  247. #endif
  248. //
  249. // * - Field is set when SLE is created and never modified.
  250. // 1 - Field is protected by database mutex
  251. // 2 - Field is protected by security mutex
  252. // 3 - Field is protected by SessionStateModified/ConnectionValidLock
  253. // 4 - Field is protected by *******
  254. // 5 - Field is protected by RdrDefaultSeLock
  255. // 6 - Field is protected by OutstandingRequestsLock
  256. // 7 - Field is protected by MpxTableLock
  257. //
  258. //
  259. //
  260. // The CONNECTLISTENTRY structure is maintained in two linked lists. The
  261. // primary connection is based off a SERVERLISTENTRY, however there is a
  262. // global chain of CONNECTLISTENTRYs as well to allow the redirector to
  263. // walk the connectlist chain directly.
  264. //
  265. //
  266. #define CLE_SCANNED 0x00000001 // Connection has been scanned during dormant scan.
  267. #define CLE_DORMANT 0x00000002 // Connection is dormant.
  268. #define CLE_TREECONNECTED 0x00000008 // Connection has a tree connection.
  269. #define CLE_DOESNT_NOTIFY 0x00000010 // ChangeNotify not supported (NT only).
  270. #define CLE_IS_A_DFS_SHARE 0x00000020 // Share is in Dfs
  271. #ifdef PAGING_OVER_THE_NET
  272. #define CLE_PAGING_FILE 0x00000010 // Indicates there may be a paging file on this connection.
  273. #endif
  274. typedef struct _CONNECTLISTENTRY {
  275. USHORT Signature; //* CLE Signature
  276. USHORT Size; //*Size
  277. LONG RefCount; //1 Number of References to CList.
  278. ULONG Type; //3 Type of connection.
  279. ULONG Flags; //1 Assorted connection flags
  280. LONG NumberOfDormantFiles; //5 Number of dormant files (interlocked)
  281. //
  282. // The fields below are pagable.
  283. //
  284. struct _SERVERLISTENTRY *Server; //* Pointer to serverlist
  285. LIST_ENTRY SiblingNext; //1 Pointer to per server next CLE.
  286. LIST_ENTRY GlobalNext; //1 Pointer to global next field
  287. UNICODE_STRING Text; //* Name of connection (SCRATCH)
  288. ULONG SerialNumber; //* Serial number for CLE.
  289. LIST_ENTRY FcbChain; //1 Pointer to per connectlist ICB list
  290. ULONG DormantTimeout; //1 Dormant connection timeout.
  291. #ifdef NOTIFY
  292. LIST_ENTRY DirNotifyList; //2 List for FindNotify.
  293. #endif
  294. LIST_ENTRY DefaultSeList; //4 List of default security entries
  295. #ifdef NOTIFY
  296. PNOTIFY_SYNC NotifySync; // Sychronization for dir notify
  297. #endif
  298. //
  299. // The next field contains the file system's allocation unit
  300. // granularity. It is cached, and is used by NtQueryInformationFile
  301. // to determine a file's allocation information from it's size.
  302. //
  303. // If this field is non zero, then the information has been filled in,
  304. // if it is 0, it has not been filled in.
  305. //
  306. ULONG FileSystemGranularity; //5 Cluster granularity of file system
  307. LARGE_INTEGER FileSystemSize; //5 Size of remote filesystem.
  308. //
  309. // The next 2 fields are similar to FileSystemGranularity. If
  310. // FileSystemAttributes are non zero, then the information in them is
  311. // valid, if they are zero, then the information in them is not valid,
  312. // and it has to be queried from the net.
  313. //
  314. // It is safe for this to be unprotected, the worst thing that could
  315. // happen is for the redirector to query this information twice.
  316. //
  317. ULONG FileSystemAttributes; //5 Attributes of file system
  318. LONG MaximumComponentLength; //5 Name length of file name components
  319. //
  320. // The next 2 fields are used to cache filesystem information, so we don't
  321. // hammer the server too much requesting information again and again
  322. //
  323. FILE_FS_SIZE_INFORMATION FsSizeInformation;
  324. LARGE_INTEGER FsSizeInformationExpiration;// The above data expires at this time.
  325. USHORT FileSystemTypeLength; //3 Length of file system type.
  326. USHORT TreeId; //3 Tree Id returned from server.
  327. BOOLEAN HasTreeId; //3
  328. BOOLEAN Deleted; // True if NetUseDel performed on connection.
  329. WCHAR FileSystemType[LM20_DEVLEN+1]; //3 Lanman 2.1 Supplied File System.
  330. //
  331. // This holds the name of the last successful CHECK_DIRECTORY request to the server.
  332. // Observation shows that NTW tends to repeat requests quite often -- this cache
  333. // is used to locally satisfy the request. 'RdrServerStateUpdated'
  334. // incremented every time this client changes state on the server -- it's value
  335. // is placed in CheckPathServerState when the CHECK_DIRECTORY succeeded. We
  336. // only use this cache if the expiration time has not passed, and if
  337. // CheckPathServerState is still equal to RdrServerStateUpdated.
  338. //
  339. union {
  340. UNICODE_STRING CachedValidCheckPath;
  341. WCHAR _buf[ MAX_PATH + sizeof(UNICODE_STRING) ];
  342. };
  343. LARGE_INTEGER CachedValidCheckPathExpiration; // The above data expires at this time
  344. LONG CheckPathServerState; // Snapshotted value of RdrServerStateUpdated
  345. //
  346. // This may hold the name of a file or directory which we know does not exist on the server
  347. //
  348. union {
  349. UNICODE_STRING CachedInvalidPath;
  350. WCHAR _buf2[ MAX_PATH + sizeof( UNICODE_STRING) ];
  351. };
  352. LARGE_INTEGER CachedInvalidPathExpiration; // The above data expires at this time
  353. ULONG CachedInvalidSmbCount; // Snapshotted value RdrStatistics.SmbsTransmitted
  354. } CONNECTLISTENTRY, *PCONNECTLISTENTRY;
  355. //
  356. //
  357. // * - Field is set when CLE is created and never modified.
  358. // 1 - Field is protected by database mutex
  359. #ifdef NOTIFY
  360. // 2 - Field is protected by NotifySync
  361. #endif
  362. // 3 - Field is protected by Server->SessionStateModifiedLock
  363. // 4 - Field is protected by RdrDefaultSecurityEntrySpinLock
  364. // 5 - Field is unprotected.
  365. //
  366. typedef
  367. VOID
  368. (*PRDR_ENUM_SERVER_CALLBACK)(
  369. IN PSERVERLISTENTRY Server,
  370. IN PVOID Ctx
  371. );
  372. #endif // _CONNECT_