/// <summary>
 /// Add a tree connect file into this TreeConnectTable.
 /// </summary>
 /// <param name="treeConnect">The tree connect to add.</param>
 /// <exception cref="System.ArgumentNullException">the tree connect is null</exception>
 /// <exception cref="System.ArgumentException">the treeConnect already exists</exception>
 public void AddTreeConnect(IFileServiceServerTreeConnect treeConnect)
 {
     lock (this.treeConnectTable)
     {
         this.treeConnectTable.Add((ushort)treeConnect.TreeConnectId, treeConnect);
     }
 }
 /// <summary>
 /// Expect a request. If user is not interested in the packet, please call DefaultSendResponse().
 /// </summary>
 /// <param name="timeout">timeout</param>
 /// <param name="connection">the connection between server and client</param>
 /// <param name="session">the session between server and client</param>
 /// <param name="treeConnect">the tree connect between server and client</param>
 /// <param name="open">the file open between server and client</param>
 /// <param name="requestPacket">the request</param>
 public abstract void ExpectRequest(
     TimeSpan timeout,
     out IFileServiceServerConnection connection,
     out IFileServiceServerSession session,
     out IFileServiceServerTreeConnect treeConnect,
     out IFileServiceServerOpen open,
     out SmbFamilyPacket requestPacket);
 /// <summary>
 /// Constructor.
 /// </summary>
 public CifsServerPerOpenSearch(
     IFileServiceServerTreeConnect treeConnect,
     ushort findSid,
     ushort mid,
     uint pid,
     int searchGlobalId)
 {
     this.treeConnect    = treeConnect;
     this.findSid        = findSid;
     this.mid            = mid;
     this.pid            = pid;
     this.searchGlobalId = searchGlobalId;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public CifsServerPerOpenSearch(
     IFileServiceServerTreeConnect treeConnect,
     ushort findSid,
     ushort mid,
     uint pid,
     int searchGlobalId)
 {
     this.treeConnect = treeConnect;
     this.findSid = findSid;
     this.mid = mid;
     this.pid = pid;
     this.searchGlobalId = searchGlobalId;
 }
        /// <summary>
        /// Automatically response latest request.
        /// </summary>
        /// <param name="connection">the connection between server and client</param>
        /// <param name="session">the session between server and client</param>
        /// <param name="treeConnect">the tree connect between server and client</param>
        /// <param name="open">the file open between server and client</param>
        /// <param name="requestPacket">the request</param>
        public override void DefaultSendResponse(
            IFileServiceServerConnection connection,
            IFileServiceServerSession session,
            IFileServiceServerTreeConnect treeConnect,
            IFileServiceServerOpen open,
            SmbFamilyPacket requestPacket)
        {
            CifsServerPerConnection cifsConnection = connection as CifsServerPerConnection;
            SmbPacket response = this.cifsServer.CreateDefaultResponse(cifsConnection,
                                                                       requestPacket as SmbPacket);

            this.cifsServer.SendPacket(response, cifsConnection);
        }
        /// <summary>
        /// server response the create request from client.
        /// </summary>
        /// <param name="treeConnect">the tree connect between server and client</param>
        /// <param name="requestPacket">the request</param>
        /// <returns>The file open object</returns>
        public override IFileServiceServerOpen SendCreateResponse(
            IFileServiceServerTreeConnect treeConnect,
            SmbFamilyPacket requestPacket)
        {
            CifsServerPerConnection cifsConnection = treeConnect.Session.Connection as CifsServerPerConnection;
            IFileServiceServerOpen  open           = null;
            SmbCreateResponsePacket response       = this.cifsServer.CreateDefaultResponse(cifsConnection, requestPacket
                                                                                           as SmbPacket) as SmbCreateResponsePacket;

            if (response != null)
            {
                this.cifsServer.SendPacket(response, cifsConnection);
                open = (treeConnect as CifsServerPerTreeConnect).GetOpen(response.SmbParameters.FID);
            }
            return(open);
        }
        /// <summary>
        /// server response TransSetNmpipeState request from client.
        /// </summary>
        /// <param name="treeConnect">the tree connect between server and client</param>
        public override void SendTransSetNmpipeStateResponse(IFileServiceServerTreeConnect treeConnect)
        {
            CifsServerPerConnection connection = treeConnect.Session.Connection as CifsServerPerConnection;

            foreach (SmbTransSetNmpipeStateRequestPacket request in connection.PendingRequestTable)
            {
                if (request != null &&
                    request.SmbHeader.Uid == treeConnect.Session.SessionId &&
                    request.SmbHeader.Tid == treeConnect.TreeConnectId)
                {
                    SmbPacket response = this.cifsServer.CreateTransSetNmpipeStateSuccessResponse(
                        connection, request);
                    this.cifsServer.SendPacket(response, connection);
                    return;
                }
            }
        }
 /// <summary>
 /// public Constructor
 /// </summary>
 /// <param name="treeConnect">The SMB tree connect associated with this open.</param>
 /// <param name="pathName">A variable-length string that contains the Unicode path name on which the open 
 /// is performed.</param>
 /// <param name="fileId">The unique (per-connection) 16-bit FID identifying this open.</param>
 /// <param name="opLock">An element indicating the type of OpLock, if any, that has been granted on this open.
 /// This value MUST be one of None, Exclusive, Batch, or Level II.</param>
 /// <param name="grantedAccess">The access granted on this open.</param>
 /// <param name="fileGlobalId">A numeric value obtained by registration with the Server Service Remote Protocol.
 /// </param>
 /// <param name="pid">The unique (per connection) 32-bit PID provided in the client request that created this
 /// open.</param>
 public CifsServerPerOpenFile(
     IFileServiceServerTreeConnect treeConnect,
     string pathName,
     long fileId,
     uint grantedAccess,
     OplockLevelValue opLock,
     int fileGlobalId,
     uint pid)
 {
     this.treeConnect = treeConnect;
     this.pathName = pathName;
     this.fileId = fileId;
     this.fileGlobalId = fileGlobalId;
     this.grantedAccess = grantedAccess;
     this.opLock = opLock;
     this.pid = pid;
     this.locks = new Dictionary<int, object>();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// public Constructor
 /// </summary>
 /// <param name="treeConnect">The SMB tree connect associated with this open.</param>
 /// <param name="pathName">A variable-length string that contains the Unicode path name on which the open
 /// is performed.</param>
 /// <param name="fileId">The unique (per-connection) 16-bit FID identifying this open.</param>
 /// <param name="opLock">An element indicating the type of OpLock, if any, that has been granted on this open.
 /// This value MUST be one of None, Exclusive, Batch, or Level II.</param>
 /// <param name="grantedAccess">The access granted on this open.</param>
 /// <param name="fileGlobalId">A numeric value obtained by registration with the Server Service Remote Protocol.
 /// </param>
 /// <param name="pid">The unique (per connection) 32-bit PID provided in the client request that created this
 /// open.</param>
 public CifsServerPerOpenFile(
     IFileServiceServerTreeConnect treeConnect,
     string pathName,
     long fileId,
     uint grantedAccess,
     OplockLevelValue opLock,
     int fileGlobalId,
     uint pid)
 {
     this.treeConnect   = treeConnect;
     this.pathName      = pathName;
     this.fileId        = fileId;
     this.fileGlobalId  = fileGlobalId;
     this.grantedAccess = grantedAccess;
     this.opLock        = opLock;
     this.pid           = pid;
     this.locks         = new Dictionary <int, object>();
 }
 /// <summary>
 /// server response the tree connect request from client.
 /// </summary>
 /// <param name="treeConnect">the tree connect between server and client</param>
 public abstract void SendTreeDisconnectResponse(IFileServiceServerTreeConnect treeConnect);
 /// <summary>
 /// server response TransSetNmpipeState request from client.
 /// </summary>
 /// <param name="treeConnect">the tree connect between server and client</param>
 public abstract void SendTransSetNmpipeStateResponse(IFileServiceServerTreeConnect treeConnect);
 /// <summary>
 /// server response the create request from client.
 /// </summary>
 /// <param name="treeConnect">the tree connect between server and client</param>
 /// <param name="requestPacket">the request</param>
 /// <returns>The file open object</returns>
 public abstract IFileServiceServerOpen SendCreateResponse(
     IFileServiceServerTreeConnect treeConnect,
     SmbFamilyPacket requestPacket);
 /// <summary>
 /// Expect a request. If user is not interested in the packet, please call DefaultSendResponse().
 /// </summary>
 /// <param name="timeout">timeout</param>
 /// <param name="connection">the connection between server and client</param>
 /// <param name="session">the session between server and client</param>
 /// <param name="treeConnect">the tree connect between server and client</param>
 /// <param name="open">the file open between server and client</param>
 /// <param name="requestPacket">the request</param>
 public abstract void ExpectRequest(
     TimeSpan timeout,
     out IFileServiceServerConnection connection,
     out IFileServiceServerSession session,
     out IFileServiceServerTreeConnect treeConnect,
     out IFileServiceServerOpen open,
     out SmbFamilyPacket requestPacket);
 /// <summary>
 /// Automatically response latest request.
 /// </summary>
 /// <param name="connection">the connection between server and client</param>
 /// <param name="session">the session between server and client</param>
 /// <param name="treeConnect">the tree connect between server and client</param>
 /// <param name="open">the file open between server and client</param>
 /// <param name="requestPacket">the request</param>
 public override void DefaultSendResponse(
     IFileServiceServerConnection connection,
     IFileServiceServerSession session,
     IFileServiceServerTreeConnect treeConnect,
     IFileServiceServerOpen open,
     SmbFamilyPacket requestPacket)
 {
     CifsServerPerConnection cifsConnection = connection as CifsServerPerConnection;
     SmbPacket response = this.cifsServer.CreateDefaultResponse(cifsConnection,
         requestPacket as SmbPacket);
     this.cifsServer.SendPacket(response, cifsConnection);
 }
        /// <summary>
        /// server response the create request from client.
        /// </summary>
        /// <param name="treeConnect">the tree connect between server and client</param>
        /// <param name="requestPacket">the request</param>
        /// <returns>The file open object</returns>
        public override IFileServiceServerOpen SendCreateResponse(
            IFileServiceServerTreeConnect treeConnect,
            SmbFamilyPacket requestPacket)
        {
            CifsServerPerConnection cifsConnection = treeConnect.Session.Connection as CifsServerPerConnection;
            IFileServiceServerOpen open = null;
            SmbCreateResponsePacket response = this.cifsServer.CreateDefaultResponse(cifsConnection, requestPacket
                as SmbPacket) as SmbCreateResponsePacket;

            if (response != null)
            {
                this.cifsServer.SendPacket(response, cifsConnection);
                open = (treeConnect as CifsServerPerTreeConnect).GetOpen(response.SmbParameters.FID);
            }
            return open;
        }
        /// <summary>
        /// Expect a request. If user is not interested in the packet, please call DefaultSendResponse().
        /// </summary>
        /// <param name="timeout">timeout</param>
        /// <param name="connection">the connection between server and client</param>
        /// <param name="session">the session between server and client</param>
        /// <param name="treeConnect">the tree connect between server and client</param>
        /// <param name="open">the file open between server and client</param>
        /// <param name="requestPacket">the request</param>
        public override void ExpectRequest(
            TimeSpan timeout,
            out IFileServiceServerConnection connection,
            out IFileServiceServerSession session,
            out IFileServiceServerTreeConnect treeConnect,
            out IFileServiceServerOpen open,
            out SmbFamilyPacket requestPacket)
        {
            CifsServerPerConnection cifsConnection;
            SmbPacket request = this.cifsServer.ExpectPacket(timeout, out cifsConnection);

            connection    = cifsConnection;
            requestPacket = request;
            session       = null;
            treeConnect   = null;
            open          = null;

            if (request != null)
            {
                session = cifsConnection.GetSession(request.SmbHeader.Uid);
                if (session != null)
                {
                    treeConnect = (session as CifsServerPerSession).GetTreeConnect(request.SmbHeader.Tid);
                    if (treeConnect != null)
                    {
                        ushort fid = 0;
                        SmbTransactionRequestPacket            transactionRequest = request as SmbTransactionRequestPacket;
                        SmbNtTransactIoctlRequestPacket        ioctlRequest       = request as SmbNtTransactIoctlRequestPacket;
                        SmbNtTransactNotifyChangeRequestPacket notifyChange       = request as SmbNtTransactNotifyChangeRequestPacket;

                        if (transactionRequest != null)
                        {
                            //SubCommand(2bytes), FID(2bytes)
                            fid = transactionRequest.SmbParameters.Setup[1];
                        }

                        else if (ioctlRequest != null)
                        {
                            //FunctionCode(4bytes), FID(2bytes), IsFctl(1bytes), IsFlags(1bytes)
                            fid = ioctlRequest.SmbParameters.Setup[2];
                        }
                        else if (notifyChange != null)
                        {
                            //CompletionFilter(4bytes), FID(2bytes), WatchTree(1bytes), Reserved(1bytes)
                            fid = notifyChange.SmbParameters.Setup[2];
                        }
                        else
                        {
                            Type         packetType = request.GetType();
                            PropertyInfo pi         = packetType.GetProperty(
                                "Trans2Parameters", BindingFlags.Instance | BindingFlags.Public);

                            if (pi == null)
                            {
                                pi = packetType.GetProperty(
                                    "NtTransParameters", BindingFlags.Instance | BindingFlags.Public);
                            }
                            if (pi == null)
                            {
                                pi = packetType.GetProperty(
                                    "SmbParameters", BindingFlags.Instance | BindingFlags.Public);
                            }
                            if (pi != null)
                            {
                                object    smbParameters = pi.GetValue(request, null);
                                FieldInfo fi            = smbParameters.GetType().GetField(
                                    "FID",
                                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
                                if (fi != null)
                                {
                                    fid = (ushort)fi.GetValue(smbParameters);
                                }
                            }
                        }

                        if (fid > 0)
                        {
                            open = (treeConnect as CifsServerPerTreeConnect).GetOpen(fid);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Add a tree connect file into this TreeConnectTable.
 /// </summary>
 /// <param name="treeConnect">The tree connect to add.</param>
 /// <exception cref="System.ArgumentNullException">the tree connect is null</exception>
 /// <exception cref="System.ArgumentException">the treeConnect already exists</exception>
 public void AddTreeConnect(IFileServiceServerTreeConnect treeConnect)
 {
     lock (this.treeConnectTable)
     {
         this.treeConnectTable.Add((ushort)treeConnect.TreeConnectId, treeConnect);
     }
 }
 /// <summary>
 /// server response the tree connect request from client.
 /// </summary>
 /// <param name="treeConnect">the tree connect between server and client</param>
 public abstract void SendTreeDisconnectResponse(IFileServiceServerTreeConnect treeConnect);
        /// <summary>
        /// Expect a request. If user is not interested in the packet, please call DefaultSendResponse().
        /// </summary>
        /// <param name="timeout">timeout</param>
        /// <param name="connection">the connection between server and client</param>
        /// <param name="session">the session between server and client</param>
        /// <param name="treeConnect">the tree connect between server and client</param>
        /// <param name="open">the file open between server and client</param>
        /// <param name="requestPacket">the request</param>
        public override void ExpectRequest(
            TimeSpan timeout,
            out IFileServiceServerConnection connection,
            out IFileServiceServerSession session,
            out IFileServiceServerTreeConnect treeConnect,
            out IFileServiceServerOpen open,
            out SmbFamilyPacket requestPacket)
        {
            CifsServerPerConnection cifsConnection;
            SmbPacket request = this.cifsServer.ExpectPacket(timeout, out cifsConnection);
            connection = cifsConnection;
            requestPacket = request;
            session = null;
            treeConnect = null;
            open = null;

            if (request != null)
            {
                session = cifsConnection.GetSession(request.SmbHeader.Uid);
                if (session != null)
                {
                    treeConnect = (session as CifsServerPerSession).GetTreeConnect(request.SmbHeader.Tid);
                    if (treeConnect != null)
                    {
                        ushort fid = 0;
                        SmbTransactionRequestPacket transactionRequest = request as SmbTransactionRequestPacket;
                        SmbNtTransactIoctlRequestPacket ioctlRequest = request as SmbNtTransactIoctlRequestPacket;
                        SmbNtTransactNotifyChangeRequestPacket notifyChange = request as SmbNtTransactNotifyChangeRequestPacket;

                        if (transactionRequest != null)
                        {
                            //SubCommand(2bytes), FID(2bytes)
                            fid = transactionRequest.SmbParameters.Setup[1];
                        }

                        else if (ioctlRequest != null)
                        {
                            //FunctionCode(4bytes), FID(2bytes), IsFctl(1bytes), IsFlags(1bytes)
                            fid = ioctlRequest.SmbParameters.Setup[2];
                        }
                        else if (notifyChange != null)
                        {
                            //CompletionFilter(4bytes), FID(2bytes), WatchTree(1bytes), Reserved(1bytes)
                            fid = notifyChange.SmbParameters.Setup[2];
                        }
                        else
                        {
                            Type packetType = request.GetType();
                            PropertyInfo pi = packetType.GetProperty(
                                "Trans2Parameters", BindingFlags.Instance | BindingFlags.Public);

                            if (pi == null)
                            {
                                pi = packetType.GetProperty(
                                    "NtTransParameters", BindingFlags.Instance | BindingFlags.Public);
                            }
                            if (pi == null)
                            {
                                pi = packetType.GetProperty(
                                    "SmbParameters", BindingFlags.Instance | BindingFlags.Public);
                            }
                            if (pi != null)
                            {
                                object smbParameters = pi.GetValue(request, null);
                                FieldInfo fi = smbParameters.GetType().GetField(
                                    "FID",
                                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
                                if (fi != null)
                                {
                                    fid = (ushort)fi.GetValue(smbParameters);
                                }
                            }
                        }

                        if (fid > 0)
                        {
                            open = (treeConnect as CifsServerPerTreeConnect).GetOpen(fid);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// server response TransSetNmpipeState request from client.
 /// </summary>
 /// <param name="treeConnect">the tree connect between server and client</param>
 public abstract void SendTransSetNmpipeStateResponse(IFileServiceServerTreeConnect treeConnect);
        /// <summary>
        /// server response the tree connect request from client.
        /// </summary>
        /// <param name="treeConnect">the tree connect between server and client</param>
        public override void SendTreeDisconnectResponse(IFileServiceServerTreeConnect treeConnect)
        {
            CifsServerPerConnection connection = treeConnect.Session.Connection as CifsServerPerConnection;

            foreach (SmbTreeDisconnectRequestPacket request in connection.PendingRequestTable)
            {
                if (request != null
                    && request.SmbHeader.Uid == treeConnect.Session.SessionId
                    && request.SmbHeader.Tid == treeConnect.TreeConnectId)
                {
                    SmbTreeDisconnectResponsePacket response = this.cifsServer.CreateTreeDisconnectResponse(
                        connection, request);

                    this.cifsServer.SendPacket(response, connection);
                    return;
                }
            }
        }
 /// <summary>
 /// Automatically response latest request.
 /// </summary>
 /// <param name="connection">the connection between server and client</param>
 /// <param name="session">the session between server and client</param>
 /// <param name="treeConnect">the tree connect between server and client</param>
 /// <param name="open">the file open between server and client</param>
 /// <param name="requestPacket">the request</param>
 public abstract void DefaultSendResponse(
     IFileServiceServerConnection connection,
     IFileServiceServerSession session,
     IFileServiceServerTreeConnect treeConnect,
     IFileServiceServerOpen open,
     SmbFamilyPacket requestPacket);
 /// <summary>
 /// server response the create request from client.
 /// </summary>
 /// <param name="treeConnect">the tree connect between server and client</param>
 /// <param name="requestPacket">the request</param>
 /// <returns>The file open object</returns>
 public abstract IFileServiceServerOpen SendCreateResponse(
     IFileServiceServerTreeConnect treeConnect,
     SmbFamilyPacket requestPacket);
 /// <summary>
 /// Automatically response latest request.
 /// </summary>
 /// <param name="connection">the connection between server and client</param>
 /// <param name="session">the session between server and client</param>
 /// <param name="treeConnect">the tree connect between server and client</param>
 /// <param name="open">the file open between server and client</param>
 /// <param name="requestPacket">the request</param>
 public abstract void DefaultSendResponse(
     IFileServiceServerConnection connection,
     IFileServiceServerSession session,
     IFileServiceServerTreeConnect treeConnect,
     IFileServiceServerOpen open,
     SmbFamilyPacket requestPacket);