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.

298 lines
11 KiB

  1. /*
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. sda.h
  5. Abstract:
  6. This module contains session data area and related data structures.
  7. Author:
  8. Jameel Hyder (microsoft!jameelh)
  9. Revision History:
  10. 25 Apr 1992 Initial Version
  11. Notes: Tab stop: 4
  12. --*/
  13. #ifndef _SDA_
  14. #define _SDA_
  15. // sda_Flags values
  16. #define SDA_USER_NOT_LOGGEDIN 0x0000 //
  17. #define SDA_USER_LOGIN_PARTIAL 0x0001 // Encrypted logon is half-way done
  18. #define SDA_USER_LOGGEDIN 0x0002
  19. #define SDA_LOGIN_MASK 0x0003
  20. #define SDA_REQUEST_IN_PROCESS 0x0004 // A request is being processed
  21. #define SDA_REPLY_IN_PROCESS 0x0008 // A reply has been posted
  22. #define SDA_NAMEXSPACE_IN_USE 0x0010 // NameXSpace is in use by reply processing
  23. #define SDA_DEREF_VOLUME 0x0020 // Dereference volume before reply
  24. #define SDA_DEREF_OFORK 0x0040 // Dereference open-fork before reply
  25. #define SDA_LOGIN_FAILED 0x0080 // Funky stuff for AFP 2.1 Chooser
  26. #define SDA_CLIENT_CLOSE 0x0100 // Set if the close if hapenning from the client side
  27. #define SDA_QUEUE_IF_DPC 0x0200 // Copied from the dispatch table (see afpapi.c)
  28. #define SDA_SESSION_CLOSED 0x0400 // If set, do not close session in deref.
  29. #define SDA_SESSION_CLOSE_COMP 0x0800 // If set, close completion called for this session
  30. #define SDA_SESSION_OVER_TCP 0x1000 // this is an AFP/TCP session
  31. #define SDA_SESSION_NOTIFY_SENT 0x2000 // Server Notification sent to this sda
  32. #define SDA_GUEST_LOGIN 0x4000 // User has logged-in using guest button
  33. #define SDA_CLOSING 0x8000 // Session is marked to die
  34. // sda_ClientType values
  35. #define SDA_CLIENT_GUEST NO_USER_AUTHENT
  36. #define SDA_CLIENT_CLEARTEXT CLEAR_TEXT_AUTHENT
  37. #define SDA_CLIENT_MSUAM_V1 CUSTOM_UAM_V1
  38. #define SDA_CLIENT_MSUAM_V2 CUSTOM_UAM_V2
  39. #define SDA_CLIENT_MSUAM_V3 CUSTOM_UAM_V3
  40. #define SDA_CLIENT_RANDNUM RANDNUM_EXCHANGE
  41. #define SDA_CLIENT_TWOWAY TWOWAY_EXCHANGE
  42. #define SDA_CLIENT_ADMIN AFP_NUM_UAMS
  43. #define MAX_REQ_ENTRIES 7
  44. #define MAX_REQ_ENTRIES_PLUS_1 8 // used to allocate space 1 DWORD more
  45. // than required. The first entry is
  46. // used to store pointer to VolDesc
  47. // or ConnDesc. The extra DWORD is used
  48. // to accomodate 64-bit pointer if we
  49. // have one
  50. #define MAX_VAR_ENTRIES 3
  51. #define SESSION_CHECK_TIME 60 // In seconds
  52. #define SESSION_WARN_TIME SESSION_CHECK_TIME * 10
  53. #define SESSION_KILL_TIME SESSION_CHECK_TIME
  54. // SDA_SIZE is the total size allocated to the SDA pointer
  55. // This includes sizeof(SDA) plus additional buffer allocated for
  56. // copying strings into. This extra space is allocated after the
  57. // first sizeof(SDA) bytes. The size is purely a ball-park figure
  58. // The original design does not mention why the total space was 384
  59. // Currently we are doubling the space to accomodate 64-bit stuff
  60. #ifdef _WIN64
  61. #define SDA_SIZE (((768 - POOL_OVERHEAD)+7) & 0xfffffff8)
  62. #else
  63. #define SDA_SIZE (((450 - POOL_OVERHEAD)+7) & 0xfffffff8)
  64. #endif
  65. // Linked list of deferred request packets. If the session is already
  66. // processing a request, then subsequent requests are queued. These
  67. // are always handled in a FIFO order.
  68. typedef struct _DeferredRequestQueue
  69. {
  70. LIST_ENTRY drq_Link;
  71. PREQUEST drq_pRequest;
  72. } DFRDREQQ, *PDFRDREQQ;
  73. /*
  74. * This is the per-session data area. This is allocated whenever a listen is
  75. * posted. At that point it is in the outstanding session list. When the listen
  76. * is completed, it moves to the active session list.
  77. */
  78. #if DBG
  79. #define SDA_SIGNATURE *(DWORD *)"SDA"
  80. #define VALID_SDA(pSda) (((pSda) != NULL) && \
  81. ((pSda)->Signature == SDA_SIGNATURE))
  82. #else
  83. #define VALID_SDA(pSda) ((pSda) != NULL)
  84. #endif
  85. typedef struct _SessDataArea
  86. {
  87. #if DBG
  88. DWORD Signature;
  89. #endif
  90. struct _SessDataArea * sda_Next; // link to next session in session list
  91. AFP_SPIN_LOCK sda_Lock; // Lock for manipulating certain SDA
  92. // fields
  93. DWORD sda_Flags; // Bit mask of the SDA states
  94. LONG sda_RefCount; // Count of references to this SDA
  95. PASP_XPORT_ENTRIES sda_XportTable; // pointer to ASP's or DSI's entry points
  96. DWORD sda_MaxWriteSize; // 64000 for TCP/IP, 4624 for Appletalk
  97. PVOID sda_SessHandle; // Asp Session handle
  98. PREQUEST sda_Request; // Current request
  99. HANDLE sda_UserToken; // Logon token for this user.
  100. PSID sda_UserSid; // SID representing owner
  101. PSID sda_GroupSid; // SID representing primary group
  102. PTOKEN_GROUPS sda_pGroups; // List of groups this user is member of
  103. #ifdef INHERIT_DIRECTORY_PERMS
  104. DWORD sda_UID; // User Id corres. to sda_UserSid
  105. DWORD sda_GID; // Group Id corres. to sda_GroupSid
  106. #else
  107. PISECURITY_DESCRIPTOR sda_pSecDesc; // Security descriptor used by directory
  108. // Creation API
  109. DWORD sda_Dummy; // For alignment
  110. #endif
  111. PANSI_STRING sda_Message; // The actual message in macintosh ansi
  112. // The above field is used only for
  113. // client specific message. Broadcast
  114. // messages are stored in a global area
  115. UNICODE_STRING sda_WSName; // Workstation name of logged in user
  116. UNICODE_STRING sda_UserName; // User name
  117. UNICODE_STRING sda_DomainName; // DomainName for Login/ChgPwd
  118. #ifdef PROFILING
  119. TIME sda_ApiStartTime; // Time stamp when Api req. was recvd.
  120. TIME sda_QueueTime; // Time spent waiting for worker thread
  121. #endif
  122. DWORD sda_SessionId; // Session Id for use by admin APIs
  123. AFPTIME sda_TimeLoggedOn; // Time when session established
  124. // in macintosh time
  125. DWORD sda_tTillKickOff; // # of seconds before this session will
  126. // be kicked off
  127. struct _ConnDesc * sda_pConnDesc; // List of connections by this session
  128. struct _OpenForkSession sda_OpenForkSess;
  129. // List of open files by this session
  130. LONG sda_cOpenVolumes; // Number of volumes mounted (admin api)
  131. LONG sda_cOpenForks; // Number of forks opened (admin api)
  132. DWORD sda_MaxOForkRefNum; // High-water mark of the fork-ref num assigned
  133. BYTE sda_AfpFunc; // AFP API in execution for FSP
  134. BYTE sda_AfpSubFunc; // Sub function code used by some APIs
  135. BYTE sda_ClientVersion; // AFP Version of the client s/w
  136. // AFP_VER_20
  137. // AFP_VER_21
  138. BYTE sda_ClientType; // One of SDA_CLIENT_XXXX
  139. BYTE sda_PathType; // For all path based calls
  140. USHORT sda_SizeNameXSpace; // Constant, initialized once
  141. USHORT sda_ReplySize; // Size of the reply buffer
  142. #define sda_ReadStatus sda_SecUtilResult
  143. NTSTATUS sda_SecUtilResult; // Result of scurity utitility call
  144. PSID sda_SecUtilSid; // Name to Sid translation. Should be
  145. // freed if non-null.
  146. // The incoming packet is copied here. The parameters from the RequestBuf
  147. // are un-marshalled into this. Each API structures this differently. Make
  148. // sure sda_Name and sda_ReqBlock are together and next to each other AND
  149. // in this order. The code in afpapi.c depends on this while clearing this.
  150. // The extra DWORD is used in cases where the first entry is reused to
  151. // stored pointer values. On 64-bit architecture we require 2 DWORD at
  152. // the start of the ReqBlock.
  153. DWORD sda_ReqBlock[MAX_REQ_ENTRIES_PLUS_1];
  154. ANSI_STRING sda_Name[MAX_VAR_ENTRIES];
  155. #define sda_Name1 sda_Name[0]
  156. #define sda_Name2 sda_Name[1]
  157. #define sda_Name3 sda_Name[2]
  158. #define sda_IOBuf sda_ReplyBuf
  159. #define sda_IOSize sda_ReplySize
  160. PBYTE sda_ReplyBuf; // Reply Buffer (variable size)
  161. AFPAPIWORKER sda_WorkerRoutine; // Api Worker
  162. WORK_ITEM sda_WorkItem; // For queueing up to worker threads
  163. PBYTE sda_Challenge; // Challenge from MSV1_0
  164. LIST_ENTRY sda_DeferredQueue; // Queue of deferred requests
  165. PBYTE sda_NameBuf; // Space is allocated for variable
  166. // part of request buffer here.
  167. PBYTE sda_NameXSpace;
  168. } SDA, *PSDA;
  169. GLOBAL AFP_SPIN_LOCK AfpSdaLock EQU {0};// Lock for session list
  170. GLOBAL PSDA AfpSessionList EQU NULL;
  171. // Linked-List of sessions
  172. // These values are subject to tuning.
  173. GLOBAL LONG AfpNumSessions EQU 0;
  174. GLOBAL UNICODE_STRING AfpDefaultWksta EQU {0, 0, NULL};
  175. extern
  176. NTSTATUS
  177. AfpSdaInit(
  178. VOID
  179. );
  180. extern
  181. VOID
  182. AfpSdaDeInit(
  183. VOID
  184. );
  185. extern
  186. PSDA FASTCALL
  187. AfpSdaCreateNewSession(
  188. IN PVOID SessionHandle,
  189. IN BOOLEAN fOverTcp
  190. );
  191. extern
  192. VOID FASTCALL
  193. afpQueueDeferredRequest(
  194. IN PSDA pSda,
  195. IN PREQUEST pRequest
  196. );
  197. extern
  198. PSDA FASTCALL
  199. AfpSdaReferenceSessionById(
  200. IN DWORD SessId
  201. );
  202. extern
  203. PSDA FASTCALL
  204. AfpSdaReferenceSessionByPointer(
  205. IN PSDA pSda
  206. );
  207. extern
  208. VOID FASTCALL
  209. AfpSdaDereferenceSession(
  210. IN PSDA pSda
  211. );
  212. extern
  213. AFPSTATUS FASTCALL
  214. AfpSdaCloseSession(
  215. IN PSDA pSda
  216. );
  217. extern
  218. AFPSTATUS
  219. AfpAdmWSessionClose(
  220. IN OUT PVOID Inbuf OPTIONAL,
  221. IN LONG OutBufLen OPTIONAL,
  222. OUT PVOID Outbuf OPTIONAL
  223. );
  224. extern
  225. AFPSTATUS FASTCALL
  226. AfpSdaCheckSession(
  227. IN PVOID pContext
  228. );
  229. extern
  230. VOID FASTCALL
  231. AfpKillSessionsOverProtocol(
  232. IN BOOLEAN fAppletalkSessions
  233. );
  234. extern
  235. VOID FASTCALL
  236. afpUpdateDiskQuotaInfo(
  237. IN struct _ConnDesc * pConnDesc
  238. );
  239. #ifdef _SDA_LOCALS
  240. LOCAL DWORD afpNextSessionId = 1;
  241. LOCAL AFPSTATUS FASTCALL
  242. afpCloseSessionAndFreeSda(
  243. IN PSDA pSda
  244. );
  245. #endif // _SDA_LOCALS
  246. #endif // _SDA_