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.

495 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. srv.h.c
  5. Abstract:
  6. Header for user-level smb server
  7. Author:
  8. Ahmed Mohamed (ahmedm) 1-Feb-2000
  9. Revision History:
  10. --*/
  11. #ifndef __SRV_H__
  12. #define __SRV_H__
  13. #include <nt.h>
  14. #include <ntdef.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. #include <stdlib.h>
  19. #include <winsock2.h>
  20. #include <wsnetbs.h>
  21. #include <stdio.h>
  22. #include <malloc.h>
  23. #ifndef TIME
  24. #define TIME LARGE_INTEGER
  25. #endif
  26. #ifndef CLONG
  27. #define CLONG ULONG
  28. #endif
  29. #pragma pack(1)
  30. #define INCLUDE_SMB_ALL
  31. #include <status.h>
  32. #include <smbtypes.h>
  33. #include <smbmacro.h>
  34. #include <smb.h>
  35. #include <smbtrans.h>
  36. #include <smbgtpt.h>
  37. #include "fs.h"
  38. #define SRV_PACKET_SIZE 0xffff
  39. #define SRV_NUM_WORKERS 16
  40. #define SRV_NUM_SENDERS 8
  41. #define MAX_PACKETS 64
  42. #define SRV_NAME_EXTENSION "$QFS"
  43. #ifndef ERR_STATUS
  44. #define ERR_STATUS 0x4000
  45. #endif
  46. #define SET_DOSERROR(msg, ec, err) { \
  47. msg->out.smb->Status.DosError.ErrorClass = SMB_ERR_CLASS_##ec; \
  48. msg->out.smb->Status.DosError.Error = SMB_ERR_##err; \
  49. }
  50. #define xmalloc(size) VirtualAlloc(NULL, size,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE)
  51. #define xfree(buffer) VirtualFree(buffer, 0, MEM_RELEASE|MEM_DECOMMIT)
  52. typedef void (WINAPI *srv_callback_t)(PVOID, UINT32 status, UINT32 information);
  53. typedef struct _ENDPOINT_ {
  54. struct _ENDPOINT_ *Next;
  55. struct _SRVCTX_ *SrvCtx;
  56. SOCKET Sock;
  57. struct _PACKET_ *PacketList;
  58. LUID LogonId;
  59. DWORD ChallengeBufferSz;
  60. char ChallengeBuffer[128];
  61. char ClientId[NETBIOS_NAME_LENGTH];
  62. }EndPoint_t;
  63. typedef struct _PACKET_ {
  64. union {
  65. OVERLAPPED ov;
  66. struct {
  67. int tag;
  68. srv_callback_t completion;
  69. };
  70. };
  71. struct _PACKET_ *next;
  72. EndPoint_t *endpoint;
  73. DWORD len;
  74. LPVOID buffer;
  75. LPVOID outbuf;
  76. HANDLE ev;
  77. struct {
  78. PNT_SMB_HEADER smb;
  79. DWORD size;
  80. DWORD offset;
  81. USHORT command;
  82. } in;
  83. struct {
  84. PNT_SMB_HEADER smb;
  85. DWORD size;
  86. USHORT valid;
  87. } out;
  88. }Packet_t;
  89. typedef struct _SRVCTX_ {
  90. CRITICAL_SECTION cs;
  91. Packet_t *freelist;
  92. BOOL running;
  93. DWORD waiters;
  94. HANDLE event;
  95. PVOID packet_pool;
  96. PVOID buffer_pool;
  97. SOCKET listen_socket;
  98. HANDLE LsaHandle;
  99. ULONG LsaPack;
  100. EndPoint_t *EndPointList;
  101. WSADATA wsaData;
  102. PVOID FsCtx;
  103. PVOID resHdl;
  104. DWORD nic;
  105. char nb_local_name[NETBIOS_NAME_LENGTH];
  106. HANDLE comport;
  107. int nThreads;
  108. HANDLE* hThreads;
  109. }SrvCtx_t;
  110. typedef struct {
  111. struct {
  112. PREQ_TRANSACTION pReq;
  113. PUCHAR pParameters;
  114. PUCHAR pData;
  115. }in;
  116. struct {
  117. PRESP_TRANSACTION pResp;
  118. USHORT ParameterBytesLeft;
  119. USHORT DataBytesLeft;
  120. PUSHORT pByteCount;
  121. }out;
  122. } Trans2_t;
  123. #define SRV_GET_FS_HANDLE(msg) ((msg)->endpoint->SrvCtx->FsCtx)
  124. #define SRV_ASCII_TO_WCHAR(buf,buflen,name,len) {\
  125. buflen = (len + 1) * sizeof(WCHAR); \
  126. buf = (WCHAR *) LocalAlloc(LMEM_FIXED, buflen); \
  127. if (buf != NULL) { \
  128. buflen = mbstowcs(buf, name, len); \
  129. if (buflen < 0) buflen = 0; \
  130. buf[buflen] = L'\0'; \
  131. } \
  132. }\
  133. #define SRV_ASCII_FREE(buf) ((buf) ? LocalFree(buf) : 0)
  134. void
  135. SrvUtilInit(SrvCtx_t *);
  136. void
  137. SrvUtilExit();
  138. #define DumpSmb(x,y,z)
  139. BOOL
  140. IsSmb(
  141. LPVOID pBuffer,
  142. DWORD nLength
  143. );
  144. void
  145. SrvFinalize(Packet_t *msg);
  146. BOOL
  147. SrvDispatch(
  148. Packet_t* msg
  149. );
  150. BOOL
  151. Trans2Dispatch(
  152. Packet_t* msg,
  153. Trans2_t* trans
  154. );
  155. VOID
  156. InitSmbHeader(
  157. Packet_t* msg
  158. );
  159. LPCSTR
  160. SrvUnparseCommand(
  161. USHORT command
  162. );
  163. LPCSTR
  164. SrvUnparseTrans2(
  165. USHORT code
  166. );
  167. USHORT
  168. attribs_to_smb_attribs(
  169. UINT32 attribs
  170. );
  171. UINT32
  172. smb_attribs_to_attribs(
  173. USHORT smb_attribs
  174. );
  175. UINT32
  176. smb_access_to_flags(
  177. USHORT access
  178. );
  179. UINT32
  180. smb_openfunc_to_flags(
  181. USHORT openfunc
  182. );
  183. void SET_WIN32ERROR(Packet_t* msg, DWORD error );
  184. ULONG // local time
  185. time64_to_smb_timedate(
  186. TIME64 *time // system time
  187. );
  188. void
  189. smb_datetime_to_time64(
  190. const USHORT smbdate,
  191. const USHORT smbtime,
  192. TIME64 *time
  193. );
  194. #define time64_to_smb_datetime(a,b,c) { \
  195. USHORT t1, t2; \
  196. _time64_to_smb_datetime(a,&t1,&t2); \
  197. *b = t1; *c = t2; \
  198. }
  199. void
  200. _time64_to_smb_datetime(
  201. TIME64 *time,
  202. USHORT *smbdate,
  203. USHORT *smbtime
  204. );
  205. ULONG // local time
  206. time64_to_smb_timedate(
  207. TIME64 *time // system time
  208. );
  209. TIME64 // system time
  210. smb_timedate_to_time64(
  211. ULONG smb_timedate // local time
  212. );
  213. BOOL
  214. SrvComUnknown(
  215. Packet_t* msg
  216. );
  217. BOOL
  218. SrvComNegotiate(
  219. Packet_t* msg
  220. );
  221. BOOL
  222. SrvComSessionSetupAndx(
  223. Packet_t* msg
  224. );
  225. BOOL
  226. SrvComTreeConnectAndx(
  227. Packet_t* msg
  228. );
  229. BOOL
  230. SrvComNoAndx(
  231. Packet_t* msg
  232. );
  233. BOOL
  234. SrvComTrans2(
  235. Packet_t* msg
  236. );
  237. BOOL
  238. SrvComTrans(
  239. Packet_t* msg
  240. );
  241. BOOL
  242. SrvComQueryInformation(
  243. Packet_t* msg
  244. );
  245. BOOL
  246. SrvComSetInformation(
  247. Packet_t* msg
  248. );
  249. BOOL
  250. SrvComCheckDirectory(
  251. Packet_t* msg
  252. );
  253. BOOL
  254. SrvComFindClose2(
  255. Packet_t* msg
  256. );
  257. BOOL
  258. SrvComFindNotifyClose(
  259. Packet_t* msg
  260. );
  261. BOOL
  262. SrvComDelete(
  263. Packet_t* msg
  264. );
  265. BOOL
  266. SrvComRename(
  267. Packet_t* msg
  268. );
  269. BOOL
  270. SrvComCreateDirectory(
  271. Packet_t* msg
  272. );
  273. BOOL
  274. SrvComDeleteDirectory(
  275. Packet_t* msg
  276. );
  277. BOOL
  278. SrvComOpenAndx(
  279. Packet_t* msg
  280. );
  281. BOOL
  282. SrvComOpen(
  283. Packet_t* msg
  284. );
  285. BOOL
  286. SrvComWrite(
  287. Packet_t* msg
  288. );
  289. BOOL
  290. SrvComClose(
  291. Packet_t* msg
  292. );
  293. BOOL
  294. SrvComReadAndx(
  295. Packet_t* msg
  296. );
  297. BOOL
  298. SrvComQueryInformation2(
  299. Packet_t* msg
  300. );
  301. BOOL
  302. SrvComSetInformation2(
  303. Packet_t* msg
  304. );
  305. BOOL
  306. SrvComLockingAndx(
  307. Packet_t* msg
  308. );
  309. BOOL
  310. SrvComSeek(
  311. Packet_t* msg
  312. );
  313. BOOL
  314. SrvComFlush(
  315. Packet_t* msg
  316. );
  317. BOOL
  318. SrvComLogoffAndx(
  319. Packet_t* msg
  320. );
  321. BOOL
  322. SrvComTreeDisconnect(
  323. Packet_t* msg
  324. );
  325. BOOL
  326. SrvComSearch(
  327. Packet_t* msg
  328. );
  329. BOOL
  330. SrvComIoctl(
  331. Packet_t* msg
  332. );
  333. BOOL
  334. SrvComEcho(
  335. Packet_t* msg
  336. );
  337. #define SIZEOF_TRANS2_RESP_HEADER(resp) (1 + resp->SetupCount)*sizeof(USHORT)
  338. BOOL
  339. Trans2Unknown(
  340. Packet_t *msg,
  341. Trans2_t *trans
  342. );
  343. BOOL
  344. Trans2QueryFsInfo(
  345. Packet_t *msg,
  346. Trans2_t *trans
  347. );
  348. BOOL
  349. Trans2FindFirst2(
  350. Packet_t *msg,
  351. Trans2_t *trans
  352. );
  353. BOOL
  354. Trans2FindNext2(
  355. Packet_t *msg,
  356. Trans2_t *trans
  357. );
  358. BOOL
  359. Trans2QueryPathInfo(
  360. Packet_t *msg,
  361. Trans2_t *trans
  362. );
  363. BOOL
  364. Trans2SetPathInfo(
  365. Packet_t *msg,
  366. Trans2_t *trans
  367. );
  368. BOOL
  369. Trans2QueryFileInfo(
  370. Packet_t *msg,
  371. Trans2_t *trans
  372. );
  373. BOOL
  374. Trans2SetFileInfo(
  375. Packet_t *msg,
  376. Trans2_t *trans
  377. );
  378. BOOL
  379. Trans2GetDfsReferral(
  380. Packet_t *msg,
  381. Trans2_t *trans
  382. );
  383. #endif