FileSystemShare.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.IO;
  10. using Utilities;
  11. namespace SMBLibrary.Server
  12. {
  13. public class FileSystemShare : ISMBShare
  14. {
  15. private string m_name;
  16. private INTFileStore m_fileSystem;
  17. private CachingPolicy m_cachingPolicy;
  18. public event EventHandler<AccessRequestArgs> AccessRequested;
  19. public FileSystemShare(string shareName, INTFileStore fileSystem) : this(shareName, fileSystem, CachingPolicy.ManualCaching)
  20. {
  21. }
  22. public FileSystemShare(string shareName, INTFileStore fileSystem, CachingPolicy cachingPolicy)
  23. {
  24. m_name = shareName;
  25. m_fileSystem = fileSystem;
  26. m_cachingPolicy = cachingPolicy;
  27. }
  28. public FileSystemShare(string shareName, IFileSystem fileSystem, CachingPolicy cachingPolicy)
  29. {
  30. m_name = shareName;
  31. m_fileSystem = new NTFileSystemAdapter(fileSystem);
  32. m_cachingPolicy = cachingPolicy;
  33. }
  34. public bool HasReadAccess(SecurityContext securityContext, string path)
  35. {
  36. return HasAccess(securityContext, path, FileAccess.Read);
  37. }
  38. public bool HasWriteAccess(SecurityContext securityContext, string path)
  39. {
  40. return HasAccess(securityContext, path, FileAccess.Write);
  41. }
  42. public bool HasAccess(SecurityContext securityContext, string path, FileAccess requestedAccess)
  43. {
  44. // To be thread-safe we must capture the delegate reference first
  45. EventHandler<AccessRequestArgs> handler = AccessRequested;
  46. if (handler != null)
  47. {
  48. AccessRequestArgs args = new AccessRequestArgs(securityContext.UserName, path, requestedAccess, securityContext.MachineName, securityContext.ClientEndPoint);
  49. handler(this, args);
  50. return args.Allow;
  51. }
  52. return true;
  53. }
  54. public string Name
  55. {
  56. get
  57. {
  58. return m_name;
  59. }
  60. }
  61. public INTFileStore FileStore
  62. {
  63. get
  64. {
  65. return m_fileSystem;
  66. }
  67. }
  68. public CachingPolicy CachingPolicy
  69. {
  70. get
  71. {
  72. return m_cachingPolicy;
  73. }
  74. }
  75. }
  76. }