SMB1FileStoreHelper.Query.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright (C) 2014-2017 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 System.Text;
  10. using SMBLibrary.SMB1;
  11. using Utilities;
  12. namespace SMBLibrary.Server.SMB1
  13. {
  14. internal partial class SMB1FileStoreHelper
  15. {
  16. public static NTStatus GetFileInformation(out QueryInformation result, INTFileStore fileStore, string path, QueryInformationLevel informationLevel, SecurityContext securityContext)
  17. {
  18. object handle;
  19. FileStatus fileStatus;
  20. NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, 0, securityContext);
  21. if (openStatus != NTStatus.STATUS_SUCCESS)
  22. {
  23. result = null;
  24. return openStatus;
  25. }
  26. NTStatus returnStatus = GetFileInformation(out result, fileStore, handle, informationLevel);
  27. fileStore.CloseFile(handle);
  28. return returnStatus;
  29. }
  30. public static NTStatus GetFileInformation(out FileInformation result, INTFileStore fileStore, string path, FileInformationClass informationClass, SecurityContext securityContext)
  31. {
  32. object handle;
  33. FileStatus fileStatus;
  34. NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, 0, securityContext);
  35. if (openStatus != NTStatus.STATUS_SUCCESS)
  36. {
  37. result = null;
  38. return openStatus;
  39. }
  40. NTStatus returnStatus = fileStore.GetFileInformation(out result, handle, informationClass);
  41. fileStore.CloseFile(handle);
  42. return returnStatus;
  43. }
  44. public static NTStatus GetFileInformation(out QueryInformation result, INTFileStore fileStore, object handle, QueryInformationLevel informationLevel)
  45. {
  46. result = null;
  47. FileInformationClass informationClass;
  48. try
  49. {
  50. informationClass = QueryInformationHelper.ToFileInformationClass(informationLevel);
  51. }
  52. catch (UnsupportedInformationLevelException)
  53. {
  54. return NTStatus.STATUS_OS2_INVALID_LEVEL;
  55. }
  56. FileInformation fileInformation;
  57. NTStatus status = fileStore.GetFileInformation(out fileInformation, handle, informationClass);
  58. if (status != NTStatus.STATUS_SUCCESS)
  59. {
  60. return status;
  61. }
  62. result = QueryInformationHelper.FromFileInformation(fileInformation);
  63. return NTStatus.STATUS_SUCCESS;
  64. }
  65. }
  66. }