SMB1FileStoreHelper.Query.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.FILE_SHARE_READ | ShareAccess.FILE_SHARE_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 QueryInformation result, INTFileStore fileStore, object handle, QueryInformationLevel informationLevel)
  31. {
  32. result = null;
  33. FileInformationClass informationClass;
  34. try
  35. {
  36. informationClass = QueryInformationHelper.ToFileInformationClass(informationLevel);
  37. }
  38. catch (UnsupportedInformationLevelException)
  39. {
  40. return NTStatus.STATUS_OS2_INVALID_LEVEL;
  41. }
  42. FileInformation fileInformation;
  43. NTStatus status = fileStore.GetFileInformation(out fileInformation, handle, informationClass);
  44. if (status != NTStatus.STATUS_SUCCESS)
  45. {
  46. return status;
  47. }
  48. result = QueryInformationHelper.FromFileInformation(fileInformation);
  49. return NTStatus.STATUS_SUCCESS;
  50. }
  51. }
  52. }