mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-06-06 20:35:27 +02:00
FileSystemShare: Added ability to specify client-side caching policy
This commit is contained in:
parent
c4fa4a9f15
commit
64ac337308
6 changed files with 87 additions and 8 deletions
|
@ -202,6 +202,7 @@
|
||||||
<Compile Include="Server\NameServer.cs" />
|
<Compile Include="Server\NameServer.cs" />
|
||||||
<Compile Include="Server\SessionInformation.cs" />
|
<Compile Include="Server\SessionInformation.cs" />
|
||||||
<Compile Include="Server\Shares\AccessRequestArgs.cs" />
|
<Compile Include="Server\Shares\AccessRequestArgs.cs" />
|
||||||
|
<Compile Include="Server\Shares\Enums\CachingPolicy.cs" />
|
||||||
<Compile Include="Server\Shares\FileSystemShare.cs" />
|
<Compile Include="Server\Shares\FileSystemShare.cs" />
|
||||||
<Compile Include="Server\Shares\ISMBShare.cs" />
|
<Compile Include="Server\Shares\ISMBShare.cs" />
|
||||||
<Compile Include="Server\Shares\NamedPipeShare.cs" />
|
<Compile Include="Server\Shares\NamedPipeShare.cs" />
|
||||||
|
|
|
@ -31,14 +31,15 @@ namespace SMBLibrary.Server.SMB1
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
share = shares.GetShareFromName(shareName);
|
share = shares.GetShareFromName(shareName);
|
||||||
serviceName = ServiceName.DiskShare;
|
|
||||||
supportFlags = OptionalSupportFlags.SMB_SUPPORT_SEARCH_BITS | OptionalSupportFlags.SMB_CSC_CACHE_MANUAL_REINT;
|
|
||||||
if (share == null)
|
if (share == null)
|
||||||
{
|
{
|
||||||
header.Status = NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
|
header.Status = NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
|
||||||
return new ErrorResponse(request.CommandName);
|
return new ErrorResponse(request.CommandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serviceName = ServiceName.DiskShare;
|
||||||
|
supportFlags = OptionalSupportFlags.SMB_SUPPORT_SEARCH_BITS | GetCachingSupportFlags(((FileSystemShare)share).CachingPolicy);
|
||||||
|
|
||||||
if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
|
if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
|
||||||
{
|
{
|
||||||
state.LogToServer(Severity.Verbose, "Tree Connect to '{0}' failed. User '{1}' was denied access.", share.Name, session.UserName);
|
state.LogToServer(Severity.Verbose, "Tree Connect to '{0}' failed. User '{1}' was denied access.", share.Name, session.UserName);
|
||||||
|
@ -64,6 +65,21 @@ namespace SMBLibrary.Server.SMB1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static OptionalSupportFlags GetCachingSupportFlags(CachingPolicy cachingPolicy)
|
||||||
|
{
|
||||||
|
switch (cachingPolicy)
|
||||||
|
{
|
||||||
|
case CachingPolicy.ManualCaching:
|
||||||
|
return OptionalSupportFlags.SMB_CSC_CACHE_MANUAL_REINT;
|
||||||
|
case CachingPolicy.AutoCaching:
|
||||||
|
return OptionalSupportFlags.SMB_CSC_CACHE_AUTO_REINT;
|
||||||
|
case CachingPolicy.VideoCaching:
|
||||||
|
return OptionalSupportFlags.SMB_CSC_CACHE_VDO;
|
||||||
|
default:
|
||||||
|
return OptionalSupportFlags.SMB_CSC_NO_CACHING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static TreeConnectAndXResponse CreateTreeConnectResponse(ServiceName serviceName, OptionalSupportFlags supportFlags)
|
private static TreeConnectAndXResponse CreateTreeConnectResponse(ServiceName serviceName, OptionalSupportFlags supportFlags)
|
||||||
{
|
{
|
||||||
TreeConnectAndXResponse response = new TreeConnectAndXResponse();
|
TreeConnectAndXResponse response = new TreeConnectAndXResponse();
|
||||||
|
|
|
@ -31,13 +31,13 @@ namespace SMBLibrary.Server.SMB2
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
share = shares.GetShareFromName(shareName);
|
share = shares.GetShareFromName(shareName);
|
||||||
shareType = ShareType.Disk;
|
|
||||||
shareFlags = ShareFlags.ManualCaching;
|
|
||||||
if (share == null)
|
if (share == null)
|
||||||
{
|
{
|
||||||
return new ErrorResponse(request.CommandName, NTStatus.STATUS_OBJECT_PATH_NOT_FOUND);
|
return new ErrorResponse(request.CommandName, NTStatus.STATUS_OBJECT_PATH_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shareType = ShareType.Disk;
|
||||||
|
shareFlags = GetShareCachingFlags(((FileSystemShare)share).CachingPolicy);
|
||||||
if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
|
if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
|
||||||
{
|
{
|
||||||
state.LogToServer(Severity.Verbose, "Tree Connect to '{0}' failed. User '{1}' was denied access.", share.Name, session.UserName);
|
state.LogToServer(Severity.Verbose, "Tree Connect to '{0}' failed. User '{1}' was denied access.", share.Name, session.UserName);
|
||||||
|
@ -62,6 +62,21 @@ namespace SMBLibrary.Server.SMB2
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ShareFlags GetShareCachingFlags(CachingPolicy cachingPolicy)
|
||||||
|
{
|
||||||
|
switch (cachingPolicy)
|
||||||
|
{
|
||||||
|
case CachingPolicy.ManualCaching:
|
||||||
|
return ShareFlags.ManualCaching;
|
||||||
|
case CachingPolicy.AutoCaching:
|
||||||
|
return ShareFlags.AutoCaching;
|
||||||
|
case CachingPolicy.VideoCaching:
|
||||||
|
return ShareFlags.VdoCaching;
|
||||||
|
default:
|
||||||
|
return ShareFlags.NoCaching;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static SMB2Command GetTreeDisconnectResponse(TreeDisconnectRequest request, ISMBShare share, SMB2ConnectionState state)
|
internal static SMB2Command GetTreeDisconnectResponse(TreeDisconnectRequest request, ISMBShare share, SMB2ConnectionState state)
|
||||||
{
|
{
|
||||||
SMB2Session session = state.GetSession(request.Header.SessionID);
|
SMB2Session session = state.GetSession(request.Header.SessionID);
|
||||||
|
|
32
SMBLibrary/Server/Shares/Enums/CachingPolicy.cs
Normal file
32
SMBLibrary/Server/Shares/Enums/CachingPolicy.cs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
|
||||||
|
namespace SMBLibrary.Server
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Client-Side Caching Policy
|
||||||
|
/// </summary>
|
||||||
|
public enum CachingPolicy
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The client can cache files that are explicitly selected by the user for offline use.
|
||||||
|
/// Automatic file-by-file reintegration is not allowed.
|
||||||
|
/// </summary>
|
||||||
|
ManualCaching,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The client can automatically cache files that are used by the user for offline access.
|
||||||
|
/// Automatic file-by-file reintegration is allowed.
|
||||||
|
/// </summary>
|
||||||
|
AutoCaching,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The client can automatically cache files that are used by the user for offline access.
|
||||||
|
/// Clients are permitted to work from their local cache even while online.
|
||||||
|
/// </summary>
|
||||||
|
VideoCaching,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// No offline caching is allowed for this share.
|
||||||
|
/// </summary>
|
||||||
|
NoCaching,
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,19 +15,26 @@ namespace SMBLibrary.Server
|
||||||
{
|
{
|
||||||
private string m_name;
|
private string m_name;
|
||||||
private INTFileStore m_fileSystem;
|
private INTFileStore m_fileSystem;
|
||||||
|
private CachingPolicy m_cachingPolicy;
|
||||||
|
|
||||||
public event EventHandler<AccessRequestArgs> AccessRequested;
|
public event EventHandler<AccessRequestArgs> AccessRequested;
|
||||||
|
|
||||||
public FileSystemShare(string shareName, INTFileStore fileSystem)
|
public FileSystemShare(string shareName, INTFileStore fileSystem) : this(shareName, fileSystem, CachingPolicy.ManualCaching)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileSystemShare(string shareName, INTFileStore fileSystem, CachingPolicy cachingPolicy)
|
||||||
{
|
{
|
||||||
m_name = shareName;
|
m_name = shareName;
|
||||||
m_fileSystem = fileSystem;
|
m_fileSystem = fileSystem;
|
||||||
|
m_cachingPolicy = cachingPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileSystemShare(string shareName, IFileSystem fileSystem)
|
public FileSystemShare(string shareName, IFileSystem fileSystem, CachingPolicy cachingPolicy)
|
||||||
{
|
{
|
||||||
m_name = shareName;
|
m_name = shareName;
|
||||||
m_fileSystem = new NTFileSystemAdapter(fileSystem);
|
m_fileSystem = new NTFileSystemAdapter(fileSystem);
|
||||||
|
m_cachingPolicy = cachingPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasReadAccess(SecurityContext securityContext, string path)
|
public bool HasReadAccess(SecurityContext securityContext, string path)
|
||||||
|
@ -68,5 +75,13 @@ namespace SMBLibrary.Server
|
||||||
return m_fileSystem;
|
return m_fileSystem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CachingPolicy CachingPolicy
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_cachingPolicy;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ namespace SMBLibrary.Server
|
||||||
{
|
{
|
||||||
public class SMBShareCollection : List<FileSystemShare>
|
public class SMBShareCollection : List<FileSystemShare>
|
||||||
{
|
{
|
||||||
public void Add(string shareName, IFileSystem fileSystem)
|
public void Add(string shareName, IFileSystem fileSystem, CachingPolicy cachingPolicy)
|
||||||
{
|
{
|
||||||
FileSystemShare share = new FileSystemShare(shareName, fileSystem);
|
FileSystemShare share = new FileSystemShare(shareName, fileSystem, cachingPolicy);
|
||||||
this.Add(share);
|
this.Add(share);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue