Пример #1
0
 /// <summary>
 /// Throws an exception when session context is null
 /// </summary>
 ///<param name="sessionContext">Context of the session</param>
 ///<exception cref="ArgumentNullException">Thrown when session context is null</exception>
 private void CheckIfSessionContextIsNull(LsaServerSessionContext sessionContext)
 {
     if (sessionContext == null)
     {
         throw new ArgumentNullException("sessionContext");
     }
 }
Пример #2
0
        /// <summary>
        /// Sends RPC response to the client
        /// </summary>
        /// <param name="sessionContext">The session context of the RPC response to send</param>
        /// <param name="messageToSend">The RPC response to send</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when sessionContext or messageToSend is null.
        /// </exception>
        public void SendRpcCallResponse(LsaServerSessionContext sessionContext, LsaResponseStub messageToSend)
        {
            CheckIfSessionContextIsNull(sessionContext);

            if (messageToSend == null)
            {
                throw new ArgumentNullException("messageToSend");
            }

            sessionContext.UpdateSessionContextWithMessageSent(messageToSend);
            rpceLayerServer.SendResponse(sessionContext.RpceLayerSessionContext,
                                         messageToSend.Encode(sessionContext));
        }
 /// <summary>
 ///  Look up the LSA session context using the session context of RPCE
 /// </summary>
 /// <param name="rpceSessionContext">The RPCE layer session context</param>
 /// <param name="sessionContext">The  corresponding LSA session context</param>
 /// <returns>Whether the rpce session is a new session</returns>
 internal bool LookupSessionContext(RpceServerSessionContext rpceSessionContext,
                                    out LsaServerSessionContext sessionContext)
 {
     lock (lockObj)
     {
         if (sessionContextMap.ContainsKey(rpceSessionContext))
         {
             sessionContext = sessionContextMap[rpceSessionContext];
             return(false);
         }
         else
         {
             sessionContext = new LsaServerSessionContext();
             sessionContextMap[rpceSessionContext] = sessionContext;
             return(true);
         }
     }
 }
Пример #4
0
        public T ExpectRpcCall <T>(TimeSpan timeout, out LsaServerSessionContext sessionContext)
            where T : LsaRequestStub
        {
            RpceServerSessionContext rpceSessionContext;
            ushort opnum;

            byte[] requestStub = rpceLayerServer.ExpectCall(timeout, out rpceSessionContext, out opnum);

            if (!Enum.IsDefined(typeof(LsaMethodOpnums), (int)opnum))
            {
                throw new InvalidOperationException("An invalid method is invoked");
            }

            //If there isn't a corresponding lsa session context, it's a new session
            if (contextManager.LookupSessionContext(rpceSessionContext, out sessionContext))
            {
                sessionContext.RpceLayerSessionContext = rpceSessionContext;
            }

            T t;

            if (typeof(T) == typeof(LsaRequestStub))
            {
                t = (T)LsaUtility.CreateLsaRequestStub((LsaMethodOpnums)opnum);
            }
            else
            {
                t = (T)Activator.CreateInstance(typeof(T));
                if ((ushort)t.Opnum != opnum)
                {
                    throw new InvalidOperationException("An unexpected method call is received");
                }
            }

            //Decode the request stub
            t.Decode(sessionContext, requestStub);

            //Update the session context
            sessionContext.UpdateSessionContextWithMessageReceived(t);
            return(t);
        }
Пример #5
0
 public virtual void SendFault(LsaServerSessionContext sessionContext, uint statusCode)
 {
     CheckIfSessionContextIsNull(sessionContext);
     rpceLayerServer.SendFault(sessionContext.RpceLayerSessionContext, statusCode);
 }
Пример #6
0
 /// <summary>
 /// Remove a session context from the context manager
 /// </summary>
 /// <param name="sessionContext">The session context to remove</param>
 /// <exception cref="ArgumentNullException">Thrown when sessionContext is null.</exception>
 public void RemoveSessionContext(LsaServerSessionContext sessionContext)
 {
     CheckIfSessionContextIsNull(sessionContext);
     contextManager.RemoveSessionContext(sessionContext.RpceLayerSessionContext);
 }