SMB1FileStore.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /* Copyright (C) 2014-2019 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using SMBLibrary.SMB1;
  10. using Utilities;
  11. namespace SMBLibrary.Client
  12. {
  13. public class SMB1FileStore : ISMBFileStore
  14. {
  15. private SMB1Client m_client;
  16. private ushort m_treeID;
  17. public SMB1FileStore(SMB1Client client, ushort treeID)
  18. {
  19. m_client = client;
  20. m_treeID = treeID;
  21. }
  22. public NTStatus CreateFile(out object handle, out FileStatus fileStatus, string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext)
  23. {
  24. handle = null;
  25. fileStatus = FileStatus.FILE_DOES_NOT_EXIST;
  26. NTCreateAndXRequest request = new NTCreateAndXRequest();
  27. request.FileName = path;
  28. request.DesiredAccess = desiredAccess;
  29. request.ExtFileAttributes = ToExtendedFileAttributes(fileAttributes);
  30. request.ShareAccess = shareAccess;
  31. request.CreateDisposition = createDisposition;
  32. request.CreateOptions = createOptions;
  33. request.ImpersonationLevel = ImpersonationLevel.Impersonation;
  34. TrySendMessage(request);
  35. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_NT_CREATE_ANDX);
  36. if (reply != null)
  37. {
  38. if (reply.Commands[0] is NTCreateAndXResponse)
  39. {
  40. NTCreateAndXResponse response = reply.Commands[0] as NTCreateAndXResponse;
  41. handle = response.FID;
  42. fileStatus = ToFileStatus(response.CreateDisposition);
  43. return reply.Header.Status;
  44. }
  45. else if (reply.Commands[0] is ErrorResponse)
  46. {
  47. return reply.Header.Status;
  48. }
  49. }
  50. return NTStatus.STATUS_INVALID_SMB;
  51. }
  52. public NTStatus CloseFile(object handle)
  53. {
  54. CloseRequest request = new CloseRequest();
  55. request.FID = (ushort)handle;
  56. TrySendMessage(request);
  57. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_CLOSE);
  58. if (reply != null)
  59. {
  60. return reply.Header.Status;
  61. }
  62. return NTStatus.STATUS_INVALID_SMB;
  63. }
  64. public NTStatus ReadFile(out byte[] data, object handle, long offset, int maxCount)
  65. {
  66. data = null;
  67. ReadAndXRequest request = new ReadAndXRequest();
  68. request.FID = (ushort)handle;
  69. request.Offset = (ulong)offset;
  70. request.MaxCountLarge = (uint)maxCount;
  71. TrySendMessage(request);
  72. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_READ_ANDX);
  73. if (reply != null)
  74. {
  75. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is ReadAndXResponse)
  76. {
  77. data = ((ReadAndXResponse)reply.Commands[0]).Data;
  78. }
  79. return reply.Header.Status;
  80. }
  81. return NTStatus.STATUS_INVALID_SMB;
  82. }
  83. public NTStatus WriteFile(out int numberOfBytesWritten, object handle, long offset, byte[] data)
  84. {
  85. numberOfBytesWritten = 0;
  86. WriteAndXRequest request = new WriteAndXRequest();
  87. request.FID = (ushort)handle;
  88. request.Offset = (ulong)offset;
  89. request.Data = data;
  90. TrySendMessage(request);
  91. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_WRITE_ANDX);
  92. if (reply != null)
  93. {
  94. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is WriteAndXResponse)
  95. {
  96. numberOfBytesWritten = (int)((WriteAndXResponse)reply.Commands[0]).Count;
  97. }
  98. return reply.Header.Status;
  99. }
  100. return NTStatus.STATUS_INVALID_SMB;
  101. }
  102. public NTStatus FlushFileBuffers(object handle)
  103. {
  104. throw new NotImplementedException();
  105. }
  106. public NTStatus LockFile(object handle, long byteOffset, long length, bool exclusiveLock)
  107. {
  108. throw new NotImplementedException();
  109. }
  110. public NTStatus UnlockFile(object handle, long byteOffset, long length)
  111. {
  112. throw new NotImplementedException();
  113. }
  114. public NTStatus QueryDirectory(out List<QueryDirectoryFileInformation> result, object handle, string fileName, FileInformationClass informationClass)
  115. {
  116. throw new NotImplementedException();
  117. }
  118. public NTStatus QueryDirectory(out List<FindInformation> result, string fileName, FindInformationLevel informationLevel)
  119. {
  120. result = null;
  121. int maxOutputLength = 4096;
  122. Transaction2FindFirst2Request subcommand = new Transaction2FindFirst2Request();
  123. subcommand.SearchAttributes = SMBFileAttributes.Hidden | SMBFileAttributes.System | SMBFileAttributes.Directory;
  124. subcommand.SearchCount = UInt16.MaxValue;
  125. subcommand.Flags = FindFlags.SMB_FIND_CLOSE_AT_EOS;
  126. subcommand.InformationLevel = informationLevel;
  127. subcommand.FileName = fileName;
  128. Transaction2Request request = new Transaction2Request();
  129. request.Setup = subcommand.GetSetup();
  130. request.TransParameters = subcommand.GetParameters(m_client.Unicode);
  131. request.TransData = subcommand.GetData(m_client.Unicode);
  132. request.TotalDataCount = (ushort)request.TransData.Length;
  133. request.TotalParameterCount = (ushort)request.TransParameters.Length;
  134. request.MaxParameterCount = Transaction2FindFirst2Response.ParametersLength;
  135. request.MaxDataCount = (ushort)maxOutputLength;
  136. TrySendMessage(request);
  137. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
  138. if (reply != null)
  139. {
  140. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
  141. {
  142. result = new List<FindInformation>();
  143. Transaction2Response response = (Transaction2Response)reply.Commands[0];
  144. Transaction2FindFirst2Response subcommandResponse = new Transaction2FindFirst2Response(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);
  145. FindInformationList findInformationList = subcommandResponse.GetFindInformationList(subcommand.InformationLevel, reply.Header.UnicodeFlag);
  146. result.AddRange(findInformationList);
  147. bool endOfSearch = subcommandResponse.EndOfSearch;
  148. while (!endOfSearch)
  149. {
  150. Transaction2FindNext2Request nextSubcommand = new Transaction2FindNext2Request();
  151. nextSubcommand.SID = subcommandResponse.SID;
  152. nextSubcommand.SearchCount = UInt16.MaxValue;
  153. nextSubcommand.Flags = FindFlags.SMB_FIND_CLOSE_AT_EOS | FindFlags.SMB_FIND_CONTINUE_FROM_LAST;
  154. nextSubcommand.InformationLevel = informationLevel;
  155. nextSubcommand.FileName = fileName;
  156. request = new Transaction2Request();
  157. request.Setup = nextSubcommand.GetSetup();
  158. request.TransParameters = nextSubcommand.GetParameters(m_client.Unicode);
  159. request.TransData = nextSubcommand.GetData(m_client.Unicode);
  160. request.TotalDataCount = (ushort)request.TransData.Length;
  161. request.TotalParameterCount = (ushort)request.TransParameters.Length;
  162. request.MaxParameterCount = Transaction2FindNext2Response.ParametersLength;
  163. request.MaxDataCount = (ushort)maxOutputLength;
  164. TrySendMessage(request);
  165. reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
  166. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
  167. {
  168. response = (Transaction2Response)reply.Commands[0];
  169. Transaction2FindNext2Response nextSubcommandResponse = new Transaction2FindNext2Response(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);
  170. findInformationList = nextSubcommandResponse.GetFindInformationList(subcommand.InformationLevel, reply.Header.UnicodeFlag);
  171. result.AddRange(findInformationList);
  172. endOfSearch = nextSubcommandResponse.EndOfSearch;
  173. }
  174. else
  175. {
  176. endOfSearch = true;
  177. }
  178. }
  179. }
  180. return reply.Header.Status;
  181. }
  182. return NTStatus.STATUS_INVALID_SMB;
  183. }
  184. public NTStatus GetFileInformation(out FileInformation result, object handle, FileInformationClass informationClass)
  185. {
  186. result = null;
  187. if (m_client.InfoLevelPassthrough)
  188. {
  189. int maxOutputLength = 4096;
  190. Transaction2QueryFileInformationRequest subcommand = new Transaction2QueryFileInformationRequest();
  191. subcommand.FID = (ushort)handle;
  192. subcommand.FileInformationClass = informationClass;
  193. Transaction2Request request = new Transaction2Request();
  194. request.Setup = subcommand.GetSetup();
  195. request.TransParameters = subcommand.GetParameters(m_client.Unicode);
  196. request.TransData = subcommand.GetData(m_client.Unicode);
  197. request.TotalDataCount = (ushort)request.TransData.Length;
  198. request.TotalParameterCount = (ushort)request.TransParameters.Length;
  199. request.MaxParameterCount = Transaction2QueryFileInformationResponse.ParametersLength;
  200. request.MaxDataCount = (ushort)maxOutputLength;
  201. TrySendMessage(request);
  202. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
  203. if (reply != null)
  204. {
  205. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
  206. {
  207. Transaction2Response response = (Transaction2Response)reply.Commands[0];
  208. Transaction2QueryFileInformationResponse subcommandResponse = new Transaction2QueryFileInformationResponse(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);
  209. if (informationClass == FileInformationClass.FileAllInformation)
  210. {
  211. // Windows implementations return SMB_QUERY_FILE_ALL_INFO when a client specifies native NT passthrough level "FileAllInformation".
  212. QueryInformation queryFileAllInfo = subcommandResponse.GetQueryInformation(QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO);
  213. result = QueryInformationHelper.ToFileInformation(queryFileAllInfo);
  214. }
  215. else
  216. {
  217. result = subcommandResponse.GetFileInformation(informationClass);
  218. }
  219. }
  220. return reply.Header.Status;
  221. }
  222. return NTStatus.STATUS_INVALID_SMB;
  223. }
  224. else
  225. {
  226. QueryInformationLevel informationLevel = QueryInformationHelper.ToFileInformationLevel(informationClass);
  227. QueryInformation queryInformation;
  228. NTStatus status = GetFileInformation(out queryInformation, handle, informationLevel);
  229. if (status == NTStatus.STATUS_SUCCESS)
  230. {
  231. result = QueryInformationHelper.ToFileInformation(queryInformation);
  232. }
  233. return status;
  234. }
  235. }
  236. public NTStatus GetFileInformation(out QueryInformation result, object handle, QueryInformationLevel informationLevel)
  237. {
  238. result = null;
  239. int maxOutputLength = 4096;
  240. Transaction2QueryFileInformationRequest subcommand = new Transaction2QueryFileInformationRequest();
  241. subcommand.FID = (ushort)handle;
  242. subcommand.QueryInformationLevel = informationLevel;
  243. Transaction2Request request = new Transaction2Request();
  244. request.Setup = subcommand.GetSetup();
  245. request.TransParameters = subcommand.GetParameters(m_client.Unicode);
  246. request.TransData = subcommand.GetData(m_client.Unicode);
  247. request.TotalDataCount = (ushort)request.TransData.Length;
  248. request.TotalParameterCount = (ushort)request.TransParameters.Length;
  249. request.MaxParameterCount = Transaction2QueryFileInformationResponse.ParametersLength;
  250. request.MaxDataCount = (ushort)maxOutputLength;
  251. TrySendMessage(request);
  252. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
  253. if (reply != null)
  254. {
  255. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
  256. {
  257. Transaction2Response response = (Transaction2Response)reply.Commands[0];
  258. Transaction2QueryFileInformationResponse subcommandResponse = new Transaction2QueryFileInformationResponse(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);
  259. result = subcommandResponse.GetQueryInformation(informationLevel);
  260. }
  261. return reply.Header.Status;
  262. }
  263. return NTStatus.STATUS_INVALID_SMB;
  264. }
  265. public NTStatus SetFileInformation(object handle, FileInformation information)
  266. {
  267. throw new NotImplementedException();
  268. }
  269. public NTStatus SetFileInformation(object handle, SetInformation information)
  270. {
  271. int maxOutputLength = 4096;
  272. Transaction2SetFileInformationRequest subcommand = new Transaction2SetFileInformationRequest();
  273. subcommand.FID = (ushort)handle;
  274. subcommand.SetInformation(information);
  275. Transaction2Request request = new Transaction2Request();
  276. request.Setup = subcommand.GetSetup();
  277. request.TransParameters = subcommand.GetParameters(m_client.Unicode);
  278. request.TransData = subcommand.GetData(m_client.Unicode);
  279. request.TotalDataCount = (ushort)request.TransData.Length;
  280. request.TotalParameterCount = (ushort)request.TransParameters.Length;
  281. request.MaxParameterCount = Transaction2SetFileInformationResponse.ParametersLength;
  282. request.MaxDataCount = (ushort)maxOutputLength;
  283. TrySendMessage(request);
  284. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
  285. if (reply != null)
  286. {
  287. return reply.Header.Status;
  288. }
  289. return NTStatus.STATUS_INVALID_SMB;
  290. }
  291. public NTStatus GetFileSystemInformation(out FileSystemInformation result, FileSystemInformationClass informationClass)
  292. {
  293. if (m_client.InfoLevelPassthrough)
  294. {
  295. result = null;
  296. int maxOutputLength = 4096;
  297. Transaction2QueryFSInformationRequest subcommand = new Transaction2QueryFSInformationRequest();
  298. subcommand.FileSystemInformationClass = informationClass;
  299. Transaction2Request request = new Transaction2Request();
  300. request.Setup = subcommand.GetSetup();
  301. request.TransParameters = subcommand.GetParameters(m_client.Unicode);
  302. request.TransData = subcommand.GetData(m_client.Unicode);
  303. request.TotalDataCount = (ushort)request.TransData.Length;
  304. request.TotalParameterCount = (ushort)request.TransParameters.Length;
  305. request.MaxParameterCount = Transaction2QueryFSInformationResponse.ParametersLength;
  306. request.MaxDataCount = (ushort)maxOutputLength;
  307. TrySendMessage(request);
  308. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
  309. if (reply != null)
  310. {
  311. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
  312. {
  313. Transaction2Response response = (Transaction2Response)reply.Commands[0];
  314. Transaction2QueryFSInformationResponse subcommandResponse = new Transaction2QueryFSInformationResponse(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);
  315. result = subcommandResponse.GetFileSystemInformation(informationClass);
  316. }
  317. return reply.Header.Status;
  318. }
  319. return NTStatus.STATUS_INVALID_SMB;
  320. }
  321. else
  322. {
  323. throw new NotImplementedException();
  324. }
  325. }
  326. public NTStatus GetFileSystemInformation(out QueryFSInformation result, QueryFSInformationLevel informationLevel)
  327. {
  328. result = null;
  329. int maxOutputLength = 4096;
  330. Transaction2QueryFSInformationRequest subcommand = new Transaction2QueryFSInformationRequest();
  331. subcommand.QueryFSInformationLevel = informationLevel;
  332. Transaction2Request request = new Transaction2Request();
  333. request.Setup = subcommand.GetSetup();
  334. request.TransParameters = subcommand.GetParameters(m_client.Unicode);
  335. request.TransData = subcommand.GetData(m_client.Unicode);
  336. request.TotalDataCount = (ushort)request.TransData.Length;
  337. request.TotalParameterCount = (ushort)request.TransParameters.Length;
  338. request.MaxParameterCount = Transaction2QueryFSInformationResponse.ParametersLength;
  339. request.MaxDataCount = (ushort)maxOutputLength;
  340. TrySendMessage(request);
  341. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
  342. if (reply != null)
  343. {
  344. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
  345. {
  346. Transaction2Response response = (Transaction2Response)reply.Commands[0];
  347. Transaction2QueryFSInformationResponse subcommandResponse = new Transaction2QueryFSInformationResponse(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);
  348. result = subcommandResponse.GetQueryFSInformation(informationLevel, reply.Header.UnicodeFlag);
  349. }
  350. return reply.Header.Status;
  351. }
  352. return NTStatus.STATUS_INVALID_SMB;
  353. }
  354. public NTStatus SetFileSystemInformation(FileSystemInformation information)
  355. {
  356. throw new NotImplementedException();
  357. }
  358. public NTStatus GetSecurityInformation(out SecurityDescriptor result, object handle, SecurityInformation securityInformation)
  359. {
  360. result = null;
  361. return NTStatus.STATUS_NOT_SUPPORTED;
  362. }
  363. public NTStatus SetSecurityInformation(object handle, SecurityInformation securityInformation, SecurityDescriptor securityDescriptor)
  364. {
  365. return NTStatus.STATUS_NOT_SUPPORTED;
  366. }
  367. public NTStatus NotifyChange(out object ioRequest, object handle, NotifyChangeFilter completionFilter, bool watchTree, int outputBufferSize, OnNotifyChangeCompleted onNotifyChangeCompleted, object context)
  368. {
  369. throw new NotImplementedException();
  370. }
  371. public NTStatus Cancel(object ioRequest)
  372. {
  373. throw new NotImplementedException();
  374. }
  375. public NTStatus DeviceIOControl(object handle, uint ctlCode, byte[] input, out byte[] output, int maxOutputLength)
  376. {
  377. if ((IoControlCode)ctlCode == IoControlCode.FSCTL_PIPE_TRANSCEIVE)
  378. {
  379. return FsCtlPipeTranscieve(handle, input, out output, maxOutputLength);
  380. }
  381. output = null;
  382. NTTransactIOCTLRequest subcommand = new NTTransactIOCTLRequest();
  383. subcommand.FID = (ushort)handle;
  384. subcommand.FunctionCode = ctlCode;
  385. subcommand.IsFsctl = true;
  386. subcommand.Data = input;
  387. NTTransactRequest request = new NTTransactRequest();
  388. request.Function = subcommand.SubcommandName;
  389. request.Setup = subcommand.GetSetup();
  390. request.TransParameters = subcommand.GetParameters(m_client.Unicode);
  391. request.TransData = subcommand.GetData();
  392. request.TotalDataCount = (uint)request.TransData.Length;
  393. request.TotalParameterCount = (uint)request.TransParameters.Length;
  394. request.MaxParameterCount = 0;
  395. request.MaxDataCount = (uint)maxOutputLength;
  396. TrySendMessage(request);
  397. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_NT_TRANSACT);
  398. if (reply != null)
  399. {
  400. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is NTTransactResponse)
  401. {
  402. NTTransactResponse response = (NTTransactResponse)reply.Commands[0];
  403. NTTransactIOCTLResponse subcommandResponse = new NTTransactIOCTLResponse(response.Setup, response.TransData);
  404. output = subcommandResponse.Data;
  405. }
  406. return reply.Header.Status;
  407. }
  408. return NTStatus.STATUS_INVALID_SMB;
  409. }
  410. public NTStatus FsCtlPipeTranscieve(object handle, byte[] input, out byte[] output, int maxOutputLength)
  411. {
  412. output = null;
  413. TransactionTransactNamedPipeRequest subcommand = new TransactionTransactNamedPipeRequest();
  414. subcommand.FID = (ushort)handle;
  415. subcommand.WriteData = input;
  416. TransactionRequest request = new TransactionRequest();
  417. request.Setup = subcommand.GetSetup();
  418. request.TransParameters = subcommand.GetParameters();
  419. request.TransData = subcommand.GetData(m_client.Unicode);
  420. request.TotalDataCount = (ushort)request.TransData.Length;
  421. request.TotalParameterCount = (ushort)request.TransParameters.Length;
  422. request.MaxParameterCount = 0;
  423. request.MaxDataCount = (ushort)maxOutputLength;
  424. request.Name = @"\PIPE\";
  425. TrySendMessage(request);
  426. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION);
  427. if (reply != null)
  428. {
  429. if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is TransactionResponse)
  430. {
  431. TransactionResponse response = (TransactionResponse)reply.Commands[0];
  432. TransactionTransactNamedPipeResponse subcommandResponse = new TransactionTransactNamedPipeResponse(response.TransData);
  433. output = subcommandResponse.ReadData;
  434. }
  435. return reply.Header.Status;
  436. }
  437. return NTStatus.STATUS_INVALID_SMB;
  438. }
  439. public NTStatus Disconnect()
  440. {
  441. TreeDisconnectRequest request = new TreeDisconnectRequest();
  442. TrySendMessage(request);
  443. SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TREE_DISCONNECT);
  444. if (reply != null)
  445. {
  446. return reply.Header.Status;
  447. }
  448. return NTStatus.STATUS_INVALID_SMB;
  449. }
  450. private void TrySendMessage(SMB1Command request)
  451. {
  452. m_client.TrySendMessage(request, m_treeID);
  453. }
  454. public uint MaxReadSize
  455. {
  456. get
  457. {
  458. return m_client.MaxReadSize;
  459. }
  460. }
  461. public uint MaxWriteSize
  462. {
  463. get
  464. {
  465. return m_client.MaxWriteSize;
  466. }
  467. }
  468. private static ExtendedFileAttributes ToExtendedFileAttributes(FileAttributes fileAttributes)
  469. {
  470. // We only return flags that can be used with NtCreateFile
  471. ExtendedFileAttributes extendedFileAttributes = ExtendedFileAttributes.ReadOnly |
  472. ExtendedFileAttributes.Hidden |
  473. ExtendedFileAttributes.System |
  474. ExtendedFileAttributes.Archive |
  475. ExtendedFileAttributes.Normal |
  476. ExtendedFileAttributes.Temporary |
  477. ExtendedFileAttributes.Offline |
  478. ExtendedFileAttributes.Encrypted;
  479. return (extendedFileAttributes & (ExtendedFileAttributes)fileAttributes);
  480. }
  481. private static FileStatus ToFileStatus(CreateDisposition createDisposition)
  482. {
  483. switch (createDisposition)
  484. {
  485. case CreateDisposition.FILE_SUPERSEDE:
  486. return FileStatus.FILE_SUPERSEDED;
  487. case CreateDisposition.FILE_OPEN:
  488. return FileStatus.FILE_OPENED;
  489. case CreateDisposition.FILE_CREATE:
  490. return FileStatus.FILE_CREATED;
  491. case CreateDisposition.FILE_OPEN_IF:
  492. return FileStatus.FILE_OVERWRITTEN;
  493. case CreateDisposition.FILE_OVERWRITE:
  494. return FileStatus.FILE_EXISTS;
  495. case CreateDisposition.FILE_OVERWRITE_IF:
  496. return FileStatus.FILE_DOES_NOT_EXIST;
  497. default:
  498. return FileStatus.FILE_OPENED;
  499. }
  500. }
  501. }
  502. }