Ejemplo n.º 1
0
        internal ServerRemoteSession(PSSenderInfo senderInfo, string configurationProviderId, string initializationParameters, AbstractServerSessionTransportManager transportManager)
        {
            NativeCommandProcessor.IsServerSide = true;
            this._senderInfo = senderInfo;
            this._configProviderId = configurationProviderId;
            this._initParameters = initializationParameters;
            this._cryptoHelper = (PSRemotingCryptoHelperServer) transportManager.CryptoHelper;
			this._cryptoHelper.Session = this;
            this._context = new ServerRemoteSessionContext();
            this._sessionDSHandler = new ServerRemoteSessionDSHandlerlImpl(this, transportManager);
            base.BaseSessionDataStructureHandler = this._sessionDSHandler;
            this._sessionDSHandler.CreateRunspacePoolReceived += new EventHandler<RemoteDataEventArgs>(this.HandleCreateRunspacePool);
            this._sessionDSHandler.NegotiationReceived += new EventHandler<RemoteSessionNegotiationEventArgs>(this.HandleNegotiationReceived);
            this._sessionDSHandler.SessionClosing += new EventHandler<EventArgs>(this.HandleSessionDSHandlerClosing);
            this._sessionDSHandler.PublicKeyReceived += new EventHandler<RemoteDataEventArgs<string>>(this.HandlePublicKeyReceived);
            transportManager.Closing += new EventHandler(this.HandleResourceClosing);
            transportManager.ReceivedDataCollection.MaximumReceivedObjectSize = 0xa00000;
            transportManager.ReceivedDataCollection.MaximumReceivedDataSize = null;
        }
Ejemplo n.º 2
0
 internal OutOfProcessServerSessionTransportManager(OutOfProcessTextWriter outWriter, OutOfProcessTextWriter errWriter, PSRemotingCryptoHelperServer cryptoHelper)
     : base(BaseTransportManager.DefaultFragmentSize, cryptoHelper)
 {
     Dbg.Assert(null != outWriter, "outWriter cannot be null.");
     Dbg.Assert(null != errWriter, "errWriter cannot be null.");
     _stdOutWriter = outWriter;
     _stdErrWriter = errWriter;
     _cmdTransportManagers = new Dictionary<Guid, OutOfProcessServerTransportManager>();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This constructor instantiates a ServerRemoteSession object and 
        /// a ServerRemoteSessionDataStructureHandler object.
        /// </summary>
        /// <param name="senderInfo">
        /// Details about the user creating this session.
        /// </param>
        /// <param name="configurationProviderId">
        /// The resource URI for which this session is being created
        /// </param>
        /// <param name="initializationParameters">
        /// Initialization Parameters xml passed by WSMan API. This data is read from the config
        /// xml.
        /// </param>
        /// <param name="transportManager">
        /// The transport manager this session should use to send/receive data
        /// </param>
        /// <returns></returns>
        internal ServerRemoteSession(PSSenderInfo senderInfo,
            string configurationProviderId,
            string initializationParameters,
            AbstractServerSessionTransportManager transportManager)
        {
            Dbg.Assert(null != transportManager, "transportManager cannot be null.");

            // let input,output and error from native commands redirect as we have
            // to send (or receive) them back to client for action.
            NativeCommandProcessor.IsServerSide = true;
            _senderInfo = senderInfo;
            _configProviderId = configurationProviderId;
            _initParameters = initializationParameters;
#if !UNIX
            _cryptoHelper = (PSRemotingCryptoHelperServer)transportManager.CryptoHelper;
            _cryptoHelper.Session = this;
#else
            _cryptoHelper = null;
#endif

            Context = new ServerRemoteSessionContext();
            SessionDataStructureHandler = new ServerRemoteSessionDSHandlerlImpl(this, transportManager);
            BaseSessionDataStructureHandler = SessionDataStructureHandler;
            SessionDataStructureHandler.CreateRunspacePoolReceived += HandleCreateRunspacePool;
            SessionDataStructureHandler.NegotiationReceived += HandleNegotiationReceived;
            SessionDataStructureHandler.SessionClosing += HandleSessionDSHandlerClosing;
            SessionDataStructureHandler.PublicKeyReceived +=
                new EventHandler<RemoteDataEventArgs<string>>(HandlePublicKeyReceived);
            transportManager.Closing += HandleResourceClosing;

            // update the quotas from sessionState..start with default size..and
            // when Custom Session Configuration is loaded (during runspace creation) update this.
            transportManager.ReceivedDataCollection.MaximumReceivedObjectSize =
                BaseTransportManager.MaximumReceivedObjectSize;

            // session transport manager can receive unlimited data..however each object is limited
            // by maxRecvdObjectSize. this is to allow clients to use a session for an unlimited time..
            // also the messages that can be sent to a session are limited and very controlled.
            // However a command transport manager can be restricted to receive only a fixed amount of data
            // controlled by maxRecvdDataSizeCommand..This is because commands can accept any number of input
            // objects
            transportManager.ReceivedDataCollection.MaximumReceivedDataSize = null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a helper with a test session
        /// </summary>
        /// <returns>helper for testing</returns>
        /// <remarks>To be used only for testing</remarks>
        internal static PSRemotingCryptoHelperServer GetTestRemotingCryptHelperServer()
        {
            PSRemotingCryptoHelperServer helper = new PSRemotingCryptoHelperServer();
            helper.Session = new TestHelperSession();

            return helper;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="initialCommand"></param>
        internal static void Run(string initialCommand)
        {
            lock (SyncObject)
            {
                if (s_singletonInstance != null)
                {
                    Dbg.Assert(false, "Run should not be called multiple times");
                    return;
                }

                s_singletonInstance = new SSHProcessMediator();
            }

            PSRemotingCryptoHelperServer cryptoHelper;
#if !UNIX
            cryptoHelper = new PSRemotingCryptoHelperServer();
#else
            cryptoHelper = null;
#endif

            s_singletonInstance.Start(initialCommand, cryptoHelper);
        }
Ejemplo n.º 6
0
        protected void Start(string initialCommand, PSRemotingCryptoHelperServer cryptoHelper, string configurationName = null)
        {
            _initialCommand = initialCommand;

            sessionTM = CreateSessionTransportManager(configurationName, cryptoHelper);

            try
            {
                do
                {
                    string data = originalStdIn.ReadLine();
                    lock (_syncObject)
                    {
                        if (sessionTM == null)
                        {
                            sessionTM = CreateSessionTransportManager(configurationName, cryptoHelper);
                        }
                    }
                    if (string.IsNullOrEmpty(data))
                    {
                        lock (_syncObject)
                        {
                            // give a chance to runspace/pipelines to close (as it looks like the client died
                            // intermittently)
                            sessionTM.Close(null);
                            sessionTM = null;
                        }
                        throw new PSRemotingTransportException(PSRemotingErrorId.IPCUnknownElementReceived,
                            RemotingErrorIdStrings.IPCUnknownElementReceived, string.Empty);
                    }

                    // process data in a thread pool thread..this way Runspace, Command 
                    // data can be processed concurrently.
#if CORECLR
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessingThreadStart), data);
#else
                    Utils.QueueWorkItemWithImpersonation(
                        _windowsIdentityToImpersonate,
                        new WaitCallback(ProcessingThreadStart),
                        data);
#endif
                } while (true);
            }
            catch (Exception e)
            {
                CommandProcessorBase.CheckForSevereException(e);

                PSEtwLog.LogOperationalError(
                    PSEventId.TransportError, PSOpcode.Open, PSTask.None,
                    PSKeyword.UseAlwaysOperational,
                    Guid.Empty.ToString(),
                    Guid.Empty.ToString(),
                    OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION,
                    e.Message,
                    e.StackTrace);

                PSEtwLog.LogAnalyticError(
                    PSEventId.TransportError_Analytic, PSOpcode.Open, PSTask.None,
                    PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic,
                    Guid.Empty.ToString(),
                    Guid.Empty.ToString(),
                    OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION,
                    e.Message,
                    e.StackTrace);

                if (_exitProcessOnError)
                {
                    // notify the remote client of any errors and fail gracefully
                    originalStdErr.WriteLine(e.Message);

                    Environment.Exit(OutOfProcessUtils.EXITCODE_UNHANDLED_EXCEPTION);
                }
            }
        }
Ejemplo n.º 7
0
        protected OutOfProcessServerSessionTransportManager CreateSessionTransportManager(string configurationName, PSRemotingCryptoHelperServer cryptoHelper)
        {
            PSSenderInfo senderInfo;
#if !UNIX
            WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
            PSPrincipal userPrincipal = new PSPrincipal(new PSIdentity("", true, currentIdentity.Name, null),
                currentIdentity);
            senderInfo = new PSSenderInfo(userPrincipal, "http://localhost");
#else
            PSPrincipal userPrincipal = new PSPrincipal(new PSIdentity("", true, "", null),
                null);
            senderInfo = new PSSenderInfo(userPrincipal, "http://localhost");
#endif

            OutOfProcessServerSessionTransportManager tm = new OutOfProcessServerSessionTransportManager(originalStdOut, originalStdErr, cryptoHelper);

            ServerRemoteSession srvrRemoteSession = ServerRemoteSession.CreateServerRemoteSession(senderInfo,
                _initialCommand, tm, configurationName);

            return tm;
        }