OpenFileObject: Added FileAccess property

This commit is contained in:
Tal Aloni 2017-10-04 17:22:14 +03:00
parent 118ed760c0
commit b978e0b8cc
6 changed files with 22 additions and 14 deletions

View file

@ -16,14 +16,16 @@ namespace SMBLibrary.Server
private string m_shareName;
private string m_path;
private object m_handle;
private FileAccess m_fileAccess;
private DateTime m_openedDT;
public OpenFileObject(uint treeID, string shareName, string path, object handle)
public OpenFileObject(uint treeID, string shareName, string path, object handle, FileAccess fileAccess)
{
m_treeID = treeID;
m_shareName = shareName;
m_path = path;
m_handle = handle;
m_fileAccess = fileAccess;
m_openedDT = DateTime.Now;
}
@ -63,6 +65,14 @@ namespace SMBLibrary.Server
}
}
public FileAccess FileAccess
{
get
{
return m_fileAccess;
}
}
public DateTime OpenedDT
{
get

View file

@ -88,21 +88,16 @@ namespace SMBLibrary.Server
return m_connectedTrees.ContainsKey(treeID);
}
/// <param name="relativePath">Should include the path relative to the share</param>
/// <param name="relativePath">The path relative to the share</param>
/// <returns>FileID</returns>
public ushort? AddOpenFile(ushort treeID, string shareName, string relativePath)
{
return AddOpenFile(treeID, shareName, relativePath, null);
}
public ushort? AddOpenFile(ushort treeID, string shareName, string relativePath, object handle)
public ushort? AddOpenFile(ushort treeID, string shareName, string relativePath, object handle, FileAccess fileAccess)
{
lock (m_connection)
{
ushort? fileID = m_connection.AllocateFileID();
if (fileID.HasValue)
{
m_openFiles.Add(fileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle));
m_openFiles.Add(fileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle, fileAccess));
}
return fileID;
}

View file

@ -130,7 +130,7 @@ namespace SMBLibrary.Server
return null;
}
public FileID? AddOpenFile(uint treeID, string shareName, string relativePath, object handle)
public FileID? AddOpenFile(uint treeID, string shareName, string relativePath, object handle, FileAccess fileAccess)
{
lock (m_openFiles)
{
@ -142,7 +142,7 @@ namespace SMBLibrary.Server
// [MS-SMB2] FileId.Persistent MUST be set to Open.DurableFileId.
// Note: We don't support durable handles so we use volatileFileID.
fileID.Persistent = volatileFileID.Value;
m_openFiles.Add(volatileFileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle));
m_openFiles.Add(volatileFileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle, fileAccess));
return fileID;
}
}

View file

@ -50,7 +50,8 @@ namespace SMBLibrary.Server.SMB1
return new ErrorResponse(request.CommandName);
}
ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle);
FileAccess fileAccess = NTFileStoreHelper.ToFileAccess(desiredAccess);
ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle, fileAccess);
if (!fileID.HasValue)
{
share.FileStore.CloseFile(handle);

View file

@ -63,7 +63,8 @@ namespace SMBLibrary.Server.SMB1
return new ErrorResponse(request.CommandName);
}
ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle);
FileAccess fileAccess = ToFileAccess(request.AccessMode.AccessMode);
ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle, fileAccess);
if (!fileID.HasValue)
{
share.FileStore.CloseFile(handle);

View file

@ -44,7 +44,8 @@ namespace SMBLibrary.Server.SMB2
return new ErrorResponse(request.CommandName, createStatus);
}
FileID? fileID = session.AddOpenFile(request.Header.TreeID, share.Name, path, handle);
FileAccess fileAccess = NTFileStoreHelper.ToFileAccess(desiredAccess);
FileID? fileID = session.AddOpenFile(request.Header.TreeID, share.Name, path, handle, fileAccess);
if (fileID == null)
{
share.FileStore.CloseFile(handle);