예제 #1
0
        public virtual void TestUnprivilegedPort()
        {
            // Don't allow connections from unprivileged ports. Given that this test is
            // presumably not being run by root, this will be the case.
            int serverPort = StartRpcServer(false);
            XDR xdrOut     = CreateGetportMount();
            int bufsize    = 2 * 1024 * 1024;

            byte[] buffer = new byte[bufsize];
            xdrOut.WriteFixedOpaque(buffer);
            // Send the request to the server
            TestRequest(xdrOut, serverPort);
            // Verify the server rejected the request.
            Assert.Equal(0, resultSize);
            // Ensure that the NULL procedure does in fact succeed.
            xdrOut = new XDR();
            CreatePortmapXDRheader(xdrOut, 0);
            int headerSize = xdrOut.Size();

            buffer = new byte[bufsize];
            xdrOut.WriteFixedOpaque(buffer);
            int requestSize = xdrOut.Size() - headerSize;

            // Send the request to the server
            TestRequest(xdrOut, serverPort);
            // Verify the server did not reject the request.
            Assert.Equal(requestSize, resultSize);
        }
예제 #2
0
            public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
            {
                ChannelBuffer buf = (ChannelBuffer)e.GetMessage();

                // Read reply
                if (!ValidMessageLength(buf.ReadableBytes()))
                {
                    e.GetChannel().Close();
                    return;
                }
                // handling fragment header for TCP, 4 bytes.
                byte[] fragmentHeader = Arrays.CopyOfRange(buf.Array(), 0, 4);
                int    fragmentSize   = XDR.FragmentSize(fragmentHeader);
                bool   isLast         = XDR.IsLastFragment(fragmentHeader);

                System.Diagnostics.Debug.Assert((fragmentSize == 28 && isLast == true));
                XDR xdr = new XDR();

                xdr.WriteFixedOpaque(Arrays.CopyOfRange(buf.Array(), 4, buf.ReadableBytes()));
                RpcReply reply = RpcReply.Read(xdr);

                if (reply.GetState() == RpcReply.ReplyState.MsgAccepted)
                {
                    RpcAcceptedReply acceptedReply = (RpcAcceptedReply)reply;
                    Handle(acceptedReply, xdr);
                }
                else
                {
                    RpcDeniedReply deniedReply = (RpcDeniedReply)reply;
                    Handle(deniedReply);
                }
                e.GetChannel().Close();
            }
예제 #3
0
        public virtual void TestFrames()
        {
            int serverPort = StartRpcServer(true);
            XDR xdrOut     = CreateGetportMount();
            int headerSize = xdrOut.Size();
            int bufsize    = 2 * 1024 * 1024;

            byte[] buffer = new byte[bufsize];
            xdrOut.WriteFixedOpaque(buffer);
            int requestSize = xdrOut.Size() - headerSize;

            // Send the request to the server
            TestRequest(xdrOut, serverPort);
            // Verify the server got the request with right size
            Assert.Equal(requestSize, resultSize);
        }