Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions SMBLibrary/Client/SMB2FileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
using System;
using System.Collections.Generic;
using System.Threading;
using SMBLibrary.SMB2;
using Utilities;

Expand All @@ -18,12 +19,15 @@ public class SMB2FileStore : ISMBFileStore
private SMB2Client m_client;
private uint m_treeID;
private bool m_encryptShareData;
private readonly Dictionary<object, bool> _activeNotifies;
private readonly object _lock = new object();

public SMB2FileStore(SMB2Client client, uint treeID, bool encryptShareData)
{
m_client = client;
m_treeID = treeID;
m_encryptShareData = encryptShareData;
_activeNotifies = new Dictionary<object, bool>();
}

public NTStatus CreateFile(out object handle, out FileStatus fileStatus, string path, AccessMask desiredAccess, FileAttributes fileAttributes, ShareAccess shareAccess, CreateDisposition createDisposition, CreateOptions createOptions, SecurityContext securityContext)
Expand Down Expand Up @@ -291,12 +295,57 @@ public NTStatus SetSecurityInformation(object handle, SecurityInformation securi

public NTStatus NotifyChange(out object ioRequest, object handle, NotifyChangeFilter completionFilter, bool watchTree, int outputBufferSize, OnNotifyChangeCompleted onNotifyChangeCompleted, object context)
{
throw new NotImplementedException();
ChangeNotifyRequest request = new ChangeNotifyRequest
{
FileId = (FileID)handle,
CompletionFilter = completionFilter,
WatchTree = watchTree,
OutputBufferLength = (uint)outputBufferSize
};

ioRequest = request;
lock (_lock)
{
_activeNotifies[request] = true;
}

TrySendCommand(request);

ThreadPool.QueueUserWorkItem(_ =>
{
SMB2Command response = m_client.WaitForCommand(request.MessageID);

lock (_lock)
{
if (!_activeNotifies.ContainsKey(request))
{
return;
}
}

if (response.Header.Status == NTStatus.STATUS_SUCCESS)
{
onNotifyChangeCompleted?.Invoke(response.Header.Status, response.GetBytes(), context);
NotifyChange(out _, handle, completionFilter, watchTree, outputBufferSize, onNotifyChangeCompleted, context);
}
else
{
NTStatus error = response == null ? NTStatus.STATUS_INVALID_SMB : response.Header.Status;
onNotifyChangeCompleted?.Invoke(error, null, context);
}
});

return NTStatus.STATUS_PENDING;
}

public NTStatus Cancel(object ioRequest)
{
throw new NotImplementedException();
lock (_lock)
{
_activeNotifies.Remove(ioRequest);
}

return NTStatus.STATUS_SUCCESS;
}

public NTStatus DeviceIOControl(object handle, uint ctlCode, byte[] input, out byte[] output, int maxOutputLength)
Expand Down