123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System;
- using System.Collections.Generic;
- using SMBLibrary.SMB1;
- using Utilities;
- namespace SMBLibrary.Server.SMB1
- {
- internal class NotifyChangeHelper
- {
- internal static void ProcessNTTransactNotifyChangeRequest(SMB1Header header, uint maxParameterCount, NTTransactNotifyChangeRequest subcommand, ISMBShare share, SMB1ConnectionState state)
- {
- SMB1Session session = state.GetSession(header.UID);
- OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
- SMB1AsyncContext context = state.CreateAsyncContext(header.UID, header.TID, header.PID, header.MID, subcommand.FID, state);
-
- lock (context)
- {
- header.Status = share.FileStore.NotifyChange(out context.IORequest, openFile.Handle, subcommand.CompletionFilter, subcommand.WatchTree, (int)maxParameterCount, OnNotifyChangeCompleted, context);
- if (header.Status == NTStatus.STATUS_PENDING)
- {
- state.LogToServer(Severity.Verbose, "NotifyChange: Monitoring of '{0}{1}' started. PID: {2}. MID: {3}.", share.Name, openFile.Path, context.PID, context.MID);
- }
- else if (header.Status == NTStatus.STATUS_NOT_SUPPORTED)
- {
-
-
- header.Status = NTStatus.STATUS_NOT_IMPLEMENTED;
- }
- }
- }
- private static void OnNotifyChangeCompleted(NTStatus status, byte[] buffer, object context)
- {
- NTTransactNotifyChangeResponse notifyChangeResponse = new NTTransactNotifyChangeResponse();
- SMB1AsyncContext asyncContext = (SMB1AsyncContext)context;
-
- lock (asyncContext)
- {
- SMB1ConnectionState connection = asyncContext.Connection;
- connection.RemoveAsyncContext(asyncContext);
- SMB1Session session = connection.GetSession(asyncContext.UID);
- if (session != null)
- {
- OpenFileObject openFile = session.GetOpenFileObject(asyncContext.FileID);
- if (openFile != null)
- {
- connection.LogToServer(Severity.Verbose, "NotifyChange: Monitoring of '{0}{1}' completed. NTStatus: {2}. PID: {3}. MID: {4}.", openFile.ShareName, openFile.Path, status, asyncContext.PID, asyncContext.MID);
- }
- }
- SMB1Header header = new SMB1Header();
- header.Command = CommandName.SMB_COM_NT_TRANSACT;
- header.Status = status;
- header.Flags = HeaderFlags.CaseInsensitive | HeaderFlags.CanonicalizedPaths | HeaderFlags.Reply;
-
-
-
- header.Flags2 = HeaderFlags2.LongNamesAllowed | HeaderFlags2.NTStatusCode | HeaderFlags2.Unicode;
- header.UID = asyncContext.UID;
- header.TID = asyncContext.TID;
- header.PID = asyncContext.PID;
- header.MID = asyncContext.MID;
- notifyChangeResponse.FileNotifyInformationBytes = buffer;
- byte[] responseSetup = notifyChangeResponse.GetSetup();
- byte[] responseParameters = notifyChangeResponse.GetParameters(false);
- byte[] responseData = notifyChangeResponse.GetData();
- List<SMB1Command> responseList = NTTransactHelper.GetNTTransactResponse(responseSetup, responseParameters, responseData, asyncContext.Connection.MaxBufferSize);
- foreach (SMB1Command response in responseList)
- {
- SMB1Message reply = new SMB1Message();
- reply.Header = header;
- reply.Commands.Add(response);
- SMBServer.EnqueueMessage(asyncContext.Connection, reply);
- }
- }
- }
- }
- }
|