/// <summary> /// Add a session into this SessionTable. /// </summary> /// <param name="session">The session to add.</param> /// <exception cref="System.ArgumentNullException">the session is null</exception> /// <exception cref="System.ArgumentException">the session already exists</exception> public void AddSession(IFileServiceServerSession session) { lock (this.sessionTable) { this.sessionTable.Add((ushort)session.SessionId, session); } }
/// <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> /// server response the tree connect request from client. /// </summary> /// <param name="session">the session between server and client</param> /// <param name="requestPacket">the request</param> /// <returns>The tree connect object</returns> public override IFileServiceServerTreeConnect SendTreeConnectResponse( IFileServiceServerSession session, SmbFamilyPacket requestPacket) { SmbPacket response = this.cifsServer.CreateDefaultResponse(session.Connection as CifsServerPerConnection, requestPacket as SmbPacket); this.cifsServer.SendPacket(response, session.Connection as CifsServerPerConnection); return((session as CifsServerPerSession).GetTreeConnect(response.SmbHeader.Tid)); }
/// <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> /// public Constructor /// </summary> public CifsServerPerTreeConnect( IFileServiceServerSession session, string name, int treeConnectId, int treeGlobalId, DateTime creationTime) { this.session = session; this.name = name; this.treeConnectId = treeConnectId; this.treeGlobalId = treeGlobalId; this.creationTime = creationTime; this.openTable = new Dictionary <ushort, IFileServiceServerOpen>(); this.openSearchTable = new Dictionary <ushort, CifsServerPerOpenSearch>(); }
/// <summary> /// public Constructor /// </summary> public CifsServerPerTreeConnect( IFileServiceServerSession session, string name, int treeConnectId, int treeGlobalId, DateTime creationTime) { this.session = session; this.name = name; this.treeConnectId = treeConnectId; this.treeGlobalId = treeGlobalId; this.creationTime = creationTime; this.openTable = new Dictionary<ushort, IFileServiceServerOpen>(); this.openSearchTable = new Dictionary<ushort, CifsServerPerOpenSearch>(); }
/// <summary> /// server response the logoff request from client. /// </summary> /// <param name="session">the session between server and client</param> public override void SendLogoffResponse(IFileServiceServerSession session) { CifsServerPerConnection connection = session.Connection as CifsServerPerConnection; foreach (SmbLogoffAndxRequestPacket request in connection.PendingRequestTable) { if (request != null && request.SmbHeader.Uid == session.SessionId) { SmbPacket response = this.cifsServer.CreateDefaultResponse(connection, request); this.cifsServer.SendPacket(response, connection); return; } } }
/// <summary> /// server response the tree connect request from client. /// </summary> /// <param name="session">the session between server and client</param> /// <param name="requestPacket">the request</param> /// <returns>The tree connect object</returns> public override IFileServiceServerTreeConnect SendTreeConnectResponse( IFileServiceServerSession session, SmbFamilyPacket requestPacket) { SmbPacket response = this.cifsServer.CreateDefaultResponse(session.Connection as CifsServerPerConnection, requestPacket as SmbPacket); this.cifsServer.SendPacket(response, session.Connection as CifsServerPerConnection); return (session as CifsServerPerSession).GetTreeConnect(response.SmbHeader.Tid); }
/// <summary> /// server response the logoff request from client. /// </summary> /// <param name="session">the session between server and client</param> public abstract void SendLogoffResponse(IFileServiceServerSession session);
/// <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> /// 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 tree connect request from client. /// </summary> /// <param name="session">the session between server and client</param> /// <param name="requestPacket">the request</param> /// <returns>The tree connect object</returns> public abstract IFileServiceServerTreeConnect SendTreeConnectResponse( IFileServiceServerSession session, SmbFamilyPacket requestPacket);