/// <summary>
            /// Constructor.
            /// </summary>
            public NodeContext(int nodeId, int processId,
#if FEATURE_NAMED_PIPES_FULL_DUPLEX
                               Stream nodePipe,
#else
                               AnonymousPipeServerStream clientToServerStream,
                               AnonymousPipeServerStream serverToClientStream,
#endif
                               INodePacketFactory factory, NodeContextTerminateDelegate terminateDelegate)
            {
                _nodeId    = nodeId;
                _processId = processId;
#if FEATURE_NAMED_PIPES_FULL_DUPLEX
                _clientToServerStream = nodePipe;
                _serverToClientStream = nodePipe;
#else
                _clientToServerStream = clientToServerStream;
                _serverToClientStream = serverToClientStream;
#endif
                _packetFactory     = factory;
                _headerByte        = new byte[5];    // 1 for the packet type, 4 for the body length
                _smallReadBuffer   = new byte[1000]; // 1000 was just an average seen on one profile run.
                _nodeTerminated    = new ManualResetEvent(false);
                _terminateDelegate = terminateDelegate;
                _sharedReadBuffer  = InterningBinaryReader.CreateSharedBuffer();
            }
        /// <summary>
        /// Instantiates an endpoint to act as a client
        /// </summary>
        /// <param name="pipeName">The name of the pipe to which we should connect.</param>
        internal void InternalConstruct(string pipeName)
        {
            ErrorUtilities.VerifyThrowArgumentLength(pipeName, nameof(pipeName));

            _debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1");

            _status           = LinkStatus.Inactive;
            _asyncDataMonitor = new object();
            _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer();

            _packetStream = new MemoryStream();
            _binaryWriter = new BinaryWriter(_packetStream);

#if FEATURE_PIPE_SECURITY && FEATURE_NAMED_PIPE_SECURITY_CONSTRUCTOR
            if (!NativeMethodsShared.IsMono)
            {
                SecurityIdentifier identifier = WindowsIdentity.GetCurrent().Owner;
                PipeSecurity       security   = new PipeSecurity();

                // Restrict access to just this account.  We set the owner specifically here, and on the
                // pipe client side they will check the owner against this one - they must have identical
                // SIDs or the client will reject this server.  This is used to avoid attacks where a
                // hacked server creates a less restricted pipe in an attempt to lure us into using it and
                // then sending build requests to the real pipe client (which is the MSBuild Build Manager.)
                PipeAccessRule rule = new PipeAccessRule(identifier, PipeAccessRights.ReadWrite, AccessControlType.Allow);
                security.AddAccessRule(rule);
                security.SetOwner(identifier);

                _pipeServer = new NamedPipeServerStream
                              (
                    pipeName,
                    PipeDirection.InOut,
                    1, // Only allow one connection at a time.
                    PipeTransmissionMode.Byte,
                    PipeOptions.Asynchronous | PipeOptions.WriteThrough,
                    PipeBufferSize, // Default input buffer
                    PipeBufferSize, // Default output buffer
                    security,
                    HandleInheritability.None
                              );
            }
            else
#endif
            {
                _pipeServer = new NamedPipeServerStream
                              (
                    pipeName,
                    PipeDirection.InOut,
                    1, // Only allow one connection at a time.
                    PipeTransmissionMode.Byte,
                    PipeOptions.Asynchronous | PipeOptions.WriteThrough,
                    PipeBufferSize, // Default input buffer
                    PipeBufferSize  // Default output buffer
                              );
            }
        }
Beispiel #3
0
        /// <summary>
        /// Instantiates an endpoint to act as a client
        /// </summary>
        /// <param name="pipeName">The name of the pipe to which we should connect.</param>
        internal void InternalConstruct(string pipeName)
        {
            ErrorUtilities.VerifyThrowArgumentLength(pipeName, nameof(pipeName));

            _debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1");

            _status           = LinkStatus.Inactive;
            _asyncDataMonitor = new object();
            _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer();
            _pipeServer       = NamedPipeUtil.CreateNamedPipeServer(pipeName, PipeBufferSize, PipeBufferSize);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 public NodeContext(int nodeId, int processId, NamedPipeClientStream nodePipe, INodePacketFactory factory, NodeContextTerminateDelegate terminateDelegate)
 {
     _nodeId            = nodeId;
     _processId         = processId;
     _nodePipe          = nodePipe;
     _packetFactory     = factory;
     _headerByte        = new byte[5];    // 1 for the packet type, 4 for the body length
     _smallReadBuffer   = new byte[1000]; // 1000 was just an average seen on one profile run.
     _nodeTerminated    = new ManualResetEvent(false);
     _terminateDelegate = terminateDelegate;
     _sharedReadBuffer  = InterningBinaryReader.CreateSharedBuffer();
 }
Beispiel #5
0
        internal void InternalConstruct(string clientToServerPipeHandle, string serverToClientPipeHandle)
        {
            ErrorUtilities.VerifyThrowArgumentLength(clientToServerPipeHandle, "clientToServerPipeHandle");
            ErrorUtilities.VerifyThrowArgumentLength(serverToClientPipeHandle, "serverToClientPipeHandle");

            _debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1");

            _status           = LinkStatus.Inactive;
            _asyncDataMonitor = new object();
            _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer();

            _pipeClientToServer = new AnonymousPipeClientStream(PipeDirection.Out, clientToServerPipeHandle);
            _pipeServerToClient = new AnonymousPipeClientStream(PipeDirection.In, serverToClientPipeHandle);
        }
Beispiel #6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public NodeContext(int nodeId, Process process,
                    Stream nodePipe,
                    INodePacketFactory factory, NodeContextTerminateDelegate terminateDelegate)
 {
     _nodeId  = nodeId;
     _process = process;
     _clientToServerStream    = nodePipe;
     _serverToClientStream    = nodePipe;
     _packetFactory           = factory;
     _headerByte              = new byte[5]; // 1 for the packet type, 4 for the body length
     _readBufferMemoryStream  = new MemoryStream();
     _writeBufferMemoryStream = new MemoryStream();
     _terminateDelegate       = terminateDelegate;
     _sharedReadBuffer        = InterningBinaryReader.CreateSharedBuffer();
 }