Beispiel #1
0
        /// <summary>
        /// Given a program number "prog", version number "vers", and transport
        /// protocol number "prot", this procedure returns the port number on which the
        /// program is awaiting call requests.
        /// </summary>
        /// <remarks>
        /// Given a program number "prog", version number "vers", and transport
        /// protocol number "prot", this procedure returns the port number on which the
        /// program is awaiting call requests. A port value of zeros means the program
        /// has not been registered. The "port" field of the argument is ignored.
        /// </remarks>
        private XDR Getport(int xid, XDR @in, XDR @out)
        {
            PortmapMapping mapping = PortmapRequest.Mapping(@in);
            string         key     = PortmapMapping.Key(mapping);

            if (Log.IsDebugEnabled())
            {
                Log.Debug("Portmap GETPORT key=" + key + " " + mapping);
            }
            PortmapMapping value = map[key];
            int            res   = 0;

            if (value != null)
            {
                res = value.GetPort();
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Found mapping for key: " + key + " port:" + res);
                }
            }
            else
            {
                Log.Warn("Warning, no mapping for key: " + key);
            }
            return(PortmapResponse.IntReply(@out, xid, res));
        }
Beispiel #2
0
 public override void Serialize(XDR xdr)
 {
     handle.Serialize(xdr);
     xdr.WriteInt(Runtime.GetBytesForString(name, Charsets.Utf8).Length);
     xdr.WriteFixedOpaque(Runtime.GetBytesForString(name, Charsets.Utf8));
     objAttr.Serialize(xdr);
 }
Beispiel #3
0
 /// <summary>Write AuthFlavor and the credentials to the XDR</summary>
 public static void WriteFlavorAndCredentials(Org.Apache.Hadoop.Oncrpc.Security.Credentials
                                              cred, XDR xdr)
 {
     if (cred is CredentialsNone)
     {
         xdr.WriteInt(RpcAuthInfo.AuthFlavor.AuthNone.GetValue());
     }
     else
     {
         if (cred is CredentialsSys)
         {
             xdr.WriteInt(RpcAuthInfo.AuthFlavor.AuthSys.GetValue());
         }
         else
         {
             if (cred is CredentialsGSS)
             {
                 xdr.WriteInt(RpcAuthInfo.AuthFlavor.RpcsecGss.GetValue());
             }
             else
             {
                 throw new NotSupportedException("Cannot recognize the verifier");
             }
         }
     }
     cred.Write(xdr);
 }
        /// <exception cref="System.Exception"/>
        public virtual void TestMkdir()
        {
            //FixME
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(testdir);
            long           dirId   = status.GetFileId();
            XDR            xdr_req = new XDR();
            FileHandle     handle  = new FileHandle(dirId);
            MKDIR3Request  req     = new MKDIR3Request(handle, "fubar1", new SetAttr3());

            req.Serialize(xdr_req);
            // Attempt to mkdir by an unprivileged user should fail.
            MKDIR3Response response1 = nfsd.Mkdir(xdr_req.AsReadOnlyWrap(), securityHandlerUnpriviledged
                                                  , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            XDR           xdr_req2 = new XDR();
            MKDIR3Request req2     = new MKDIR3Request(handle, "fubar2", new SetAttr3());

            req2.Serialize(xdr_req2);
            // Attempt to mkdir by a privileged user should pass.
            MKDIR3Response response2 = nfsd.Mkdir(xdr_req2.AsReadOnlyWrap(), securityHandler,
                                                  new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3Ok, response2
                                            .GetStatus());
        }
        internal static void TestRequest(XDR request)
        {
            RegistrationClient registrationClient = new RegistrationClient("localhost", Nfs3Constant
                                                                           .SunRpcbind, request);

            registrationClient.Run();
        }
Beispiel #6
0
 /// <summary>
 /// Response for RPC call
 /// <see cref="MNTPROC.Export"/>
 ///
 /// </summary>
 public static XDR WriteExportList(XDR xdr, int xid, IList <string> exports, IList <
                                       NfsExports> hostMatcher)
 {
     System.Diagnostics.Debug.Assert((exports.Count == hostMatcher.Count));
     RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(xdr);
     for (int i = 0; i < exports.Count; i++)
     {
         xdr.WriteBoolean(true);
         // Value follows - yes
         xdr.WriteString(exports[i]);
         // List host groups
         string[] hostGroups = hostMatcher[i].GetHostGroupList();
         if (hostGroups.Length > 0)
         {
             for (int j = 0; j < hostGroups.Length; j++)
             {
                 xdr.WriteBoolean(true);
                 // Value follows - yes
                 xdr.WriteVariableOpaque(Runtime.GetBytesForString(hostGroups[j], Charsets
                                                                   .Utf8));
             }
         }
         xdr.WriteBoolean(false);
     }
     // Value follows - no more group
     xdr.WriteBoolean(false);
     // Value follows - no
     return(xdr);
 }
Beispiel #7
0
 public override void Serialize(XDR xdr)
 {
     handle.Serialize(xdr);
     xdr.WriteLongAsHyper(cookie);
     xdr.WriteLongAsHyper(cookieVerf);
     xdr.WriteInt(count);
 }
Beispiel #8
0
 public static Org.Apache.Hadoop.Oncrpc.Security.Credentials ReadFlavorAndCredentials
     (XDR xdr)
 {
     RpcAuthInfo.AuthFlavor flavor = RpcAuthInfo.AuthFlavor.FromValue(xdr.ReadInt());
     Org.Apache.Hadoop.Oncrpc.Security.Credentials credentials;
     if (flavor == RpcAuthInfo.AuthFlavor.AuthNone)
     {
         credentials = new CredentialsNone();
     }
     else
     {
         if (flavor == RpcAuthInfo.AuthFlavor.AuthSys)
         {
             credentials = new CredentialsSys();
         }
         else
         {
             if (flavor == RpcAuthInfo.AuthFlavor.RpcsecGss)
             {
                 credentials = new CredentialsGSS();
             }
             else
             {
                 throw new NotSupportedException("Unsupported Credentials Flavor " + flavor);
             }
         }
     }
     credentials.Read(xdr);
     return(credentials);
 }
Beispiel #9
0
        /// <exception cref="System.IO.IOException"/>
        public static Org.Apache.Hadoop.Nfs.Nfs3.Request.GETATTR3Request Deserialize(XDR
                                                                                     xdr)
        {
            FileHandle handle = ReadHandle(xdr);

            return(new Org.Apache.Hadoop.Nfs.Nfs3.Request.GETATTR3Request(handle));
        }
Beispiel #10
0
        internal static void TestDump()
        {
            XDR xdr_out = new XDR();

            CreatePortmapXDRheader(xdr_out, 4);
            TestRequest(xdr_out, xdr_out);
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestClientAccessPrivilegeForRemove()
        {
            // Configure ro access for nfs1 service
            config.Set("dfs.nfs.exports.allowed.hosts", "* ro");
            // Start nfs
            Org.Apache.Hadoop.Hdfs.Nfs.Nfs3.Nfs3 nfs = new Org.Apache.Hadoop.Hdfs.Nfs.Nfs3.Nfs3
                                                           (config);
            nfs.StartServiceInternal(false);
            RpcProgramNfs3 nfsd = (RpcProgramNfs3)nfs.GetRpcProgram();
            // Create a remove request
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(testdir);
            long           dirId   = status.GetFileId();
            XDR            xdr_req = new XDR();
            FileHandle     handle  = new FileHandle(dirId);

            handle.Serialize(xdr_req);
            xdr_req.WriteString("f1");
            // Remove operation
            REMOVE3Response response = nfsd.Remove(xdr_req.AsReadOnlyWrap(), securityHandler,
                                                   new IPEndPoint("localhost", 1234));

            // Assert on return code
            NUnit.Framework.Assert.AreEqual("Incorrect return code", Nfs3Status.Nfs3errAcces,
                                            response.GetStatus());
        }
Beispiel #12
0
        public static READDIR3Response Deserialize(XDR xdr)
        {
            int status = xdr.ReadInt();

            xdr.ReadBoolean();
            Nfs3FileAttributes postOpDirAttr = Nfs3FileAttributes.Deserialize(xdr);
            long cookieVerf = 0;
            AList <READDIR3Response.Entry3> entries = new AList <READDIR3Response.Entry3>();

            READDIR3Response.DirList3 dirList = null;
            if (status == Nfs3Status.Nfs3Ok)
            {
                cookieVerf = xdr.ReadHyper();
                while (xdr.ReadBoolean())
                {
                    READDIR3Response.Entry3 e = READDIR3Response.Entry3.Deserialzie(xdr);
                    entries.AddItem(e);
                }
                bool eof = xdr.ReadBoolean();
                READDIR3Response.Entry3[] allEntries = new READDIR3Response.Entry3[entries.Count]
                ;
                Collections.ToArray(entries, allEntries);
                dirList = new READDIR3Response.DirList3(allEntries, eof);
            }
            return(new READDIR3Response(status, postOpDirAttr, cookieVerf, dirList));
        }
Beispiel #13
0
        /// <exception cref="System.IO.IOException"/>
        public static Org.Apache.Hadoop.Nfs.Nfs3.Request.MKNOD3Request Deserialize(XDR xdr
                                                                                   )
        {
            FileHandle handle  = ReadHandle(xdr);
            string     name    = xdr.ReadString();
            int        type    = xdr.ReadInt();
            SetAttr3   objAttr = new SetAttr3();

            Nfs3FileAttributes.Specdata3 spec = null;
            if (type == NfsFileType.Nfschr.ToValue() || type == NfsFileType.Nfsblk.ToValue())
            {
                objAttr.Deserialize(xdr);
                spec = new Nfs3FileAttributes.Specdata3(xdr.ReadInt(), xdr.ReadInt());
            }
            else
            {
                if (type == NfsFileType.Nfssock.ToValue() || type == NfsFileType.Nfsfifo.ToValue(
                        ))
                {
                    objAttr.Deserialize(xdr);
                }
            }
            return(new Org.Apache.Hadoop.Nfs.Nfs3.Request.MKNOD3Request(handle, name, type, objAttr
                                                                        , spec));
        }
Beispiel #14
0
 public override void Write(XDR xdr)
 {
     // mStamp + mHostName.length + mHostName + mUID + mGID + mAuxGIDs.count
     mCredentialsLength = 20 + Runtime.GetBytesForString(mHostName, Charsets.Utf8
                                                         ).Length;
     // mAuxGIDs
     if (mAuxGIDs != null && mAuxGIDs.Length > 0)
     {
         mCredentialsLength += mAuxGIDs.Length * 4;
     }
     xdr.WriteInt(mCredentialsLength);
     xdr.WriteInt(mStamp);
     xdr.WriteString(mHostName);
     xdr.WriteInt(mUID);
     xdr.WriteInt(mGID);
     if ((mAuxGIDs == null) || (mAuxGIDs.Length == 0))
     {
         xdr.WriteInt(0);
     }
     else
     {
         xdr.WriteInt(mAuxGIDs.Length);
         for (int i = 0; i < mAuxGIDs.Length; i++)
         {
             xdr.WriteInt(mAuxGIDs[i]);
         }
     }
 }
Beispiel #15
0
        /// <exception cref="System.IO.IOException"/>
        public static Org.Apache.Hadoop.Nfs.Nfs3.Request.CREATE3Request Deserialize(XDR xdr
                                                                                    )
        {
            FileHandle handle  = ReadHandle(xdr);
            string     name    = xdr.ReadString();
            int        mode    = xdr.ReadInt();
            SetAttr3   objAttr = new SetAttr3();
            long       verf    = 0;

            if ((mode == Nfs3Constant.CreateUnchecked) || (mode == Nfs3Constant.CreateGuarded
                                                           ))
            {
                objAttr.Deserialize(xdr);
            }
            else
            {
                if (mode == Nfs3Constant.CreateExclusive)
                {
                    verf = xdr.ReadHyper();
                }
                else
                {
                    throw new IOException("Wrong create mode:" + mode);
                }
            }
            return(new Org.Apache.Hadoop.Nfs.Nfs3.Request.CREATE3Request(handle, name, mode,
                                                                         objAttr, verf));
        }
Beispiel #16
0
 // TODO: convert this to Junit
 internal static void TestRequest(XDR request, XDR request2)
 {
     try
     {
         DatagramSocket clientSocket = new DatagramSocket();
         IPAddress      IPAddress    = Sharpen.Extensions.GetAddressByName("localhost");
         byte[]         sendData     = request.GetBytes();
         byte[]         receiveData  = new byte[65535];
         DatagramPacket sendPacket   = new DatagramPacket(sendData, sendData.Length, IPAddress
                                                          , Nfs3Constant.SunRpcbind);
         clientSocket.Send(sendPacket);
         DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.Length
                                                           );
         clientSocket.Receive(receivePacket);
         clientSocket.Close();
     }
     catch (UnknownHostException)
     {
         System.Console.Error.WriteLine("Don't know about host: localhost.");
         System.Environment.Exit(1);
     }
     catch (IOException)
     {
         System.Console.Error.WriteLine("Couldn't get I/O for " + "the connection to: localhost."
                                        );
         System.Environment.Exit(1);
     }
 }
            public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e)
            {
                // Get handle from create response
                ChannelBuffer buf = (ChannelBuffer)e.GetMessage();
                XDR           rsp = new XDR(buf.Array());

                if (rsp.GetBytes().Length == 0)
                {
                    Log.Info("rsp length is zero, why?");
                    return;
                }
                Log.Info("rsp length=" + rsp.GetBytes().Length);
                RpcReply reply = RpcReply.Read(rsp);
                int      xid   = reply.GetXid();

                // Only process the create response
                if (xid != unchecked ((int)(0x8000004c)))
                {
                    return;
                }
                int status = rsp.ReadInt();

                if (status != Nfs3Status.Nfs3Ok)
                {
                    Log.Error("Create failed, status =" + status);
                    return;
                }
                Log.Info("Create succeeded");
                rsp.ReadBoolean();
                // value follow
                handle = new FileHandle();
                handle.Deserialize(rsp);
                channel = e.GetChannel();
            }
        /// <exception cref="System.Exception"/>
        public virtual void TestWrite()
        {
            HdfsFileStatus status = nn.GetRpcServer().GetFileInfo("/tmp/bar");
            long           dirId  = status.GetFileId();
            FileHandle     handle = new FileHandle(dirId);

            byte[] buffer = new byte[10];
            for (int i = 0; i < 10; i++)
            {
                buffer[i] = unchecked ((byte)i);
            }
            WRITE3Request writeReq = new WRITE3Request(handle, 0, 10, Nfs3Constant.WriteStableHow
                                                       .DataSync, ByteBuffer.Wrap(buffer));
            XDR xdr_req = new XDR();

            writeReq.Serialize(xdr_req);
            // Attempt by an unpriviledged user should fail.
            WRITE3Response response1 = nfsd.Write(xdr_req.AsReadOnlyWrap(), null, 1, securityHandlerUnpriviledged
                                                  , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            // Attempt by a priviledged user should pass.
            WRITE3Response response2 = nfsd.Write(xdr_req.AsReadOnlyWrap(), null, 1, securityHandler
                                                  , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect response:", null, response2);
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestReadlink()
        {
            // Create a symlink first.
            HdfsFileStatus  status  = nn.GetRpcServer().GetFileInfo(testdir);
            long            dirId   = status.GetFileId();
            XDR             xdr_req = new XDR();
            FileHandle      handle  = new FileHandle(dirId);
            SYMLINK3Request req     = new SYMLINK3Request(handle, "fubar", new SetAttr3(), "bar");

            req.Serialize(xdr_req);
            SYMLINK3Response response = nfsd.Symlink(xdr_req.AsReadOnlyWrap(), securityHandler
                                                     , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3Ok, response
                                            .GetStatus());
            // Now perform readlink operations.
            FileHandle       handle2  = response.GetObjFileHandle();
            XDR              xdr_req2 = new XDR();
            READLINK3Request req2     = new READLINK3Request(handle2);

            req2.Serialize(xdr_req2);
            // Attempt by an unpriviledged user should fail.
            READLINK3Response response1 = nfsd.Readlink(xdr_req2.AsReadOnlyWrap(), securityHandlerUnpriviledged
                                                        , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            // Attempt by a priviledged user should pass.
            READLINK3Response response2 = nfsd.Readlink(xdr_req2.AsReadOnlyWrap(), securityHandler
                                                        , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3Ok, response2
                                            .GetStatus());
        }
Beispiel #20
0
 public override XDR Serialize(XDR @out, int xid, Verifier verifier)
 {
     base.Serialize(@out, xid, verifier);
     fromDirWcc.Serialize(@out);
     linkDirWcc.Serialize(@out);
     return(@out);
 }
Beispiel #21
0
 public override XDR NullOp(XDR @out, int xid, IPAddress client)
 {
     if (Log.IsDebugEnabled())
     {
         Log.Debug("MOUNT NULLOP : " + " client: " + client);
     }
     return(RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(@out));
 }
Beispiel #22
0
            internal static READDIR3Response.Entry3 Deserialzie(XDR xdr)
            {
                long   fileId = xdr.ReadHyper();
                string name   = xdr.ReadString();
                long   cookie = xdr.ReadHyper();

                return(new READDIR3Response.Entry3(fileId, name, cookie));
            }
Beispiel #23
0
 public virtual XDR Serialize(XDR xdr)
 {
     xdr.WriteInt(program);
     xdr.WriteInt(version);
     xdr.WriteInt(transport);
     xdr.WriteInt(port);
     return(xdr);
 }
Beispiel #24
0
 public override void Serialize(XDR xdr)
 {
     handle.Serialize(xdr);
     fromDirHandle.Serialize(xdr);
     xdr.WriteInt(fromName.Length);
     xdr.WriteFixedOpaque(Runtime.GetBytesForString(fromName, Charsets.Utf8),
                          fromName.Length);
 }
Beispiel #25
0
        /// <summary>
        /// Write the response, along with the rpc header (including verifier), to the
        /// XDR.
        /// </summary>
        public virtual XDR Serialize(XDR @out, int xid, Verifier verifier)
        {
            RpcAcceptedReply reply = RpcAcceptedReply.GetAcceptInstance(xid, verifier);

            reply.Write(@out);
            @out.WriteInt(this.GetStatus());
            return(@out);
        }
Beispiel #26
0
        /// <exception cref="System.IO.IOException"/>
        public static Org.Apache.Hadoop.Nfs.Nfs3.Request.RMDIR3Request Deserialize(XDR xdr
                                                                                   )
        {
            FileHandle handle = ReadHandle(xdr);
            string     name   = xdr.ReadString();

            return(new Org.Apache.Hadoop.Nfs.Nfs3.Request.RMDIR3Request(handle, name));
        }
Beispiel #27
0
        public static Org.Apache.Hadoop.Nfs.Nfs3.Response.RMDIR3Response Deserialize(XDR
                                                                                     xdr)
        {
            int     status = xdr.ReadInt();
            WccData dirWcc = WccData.Deserialize(xdr);

            return(new Org.Apache.Hadoop.Nfs.Nfs3.Response.RMDIR3Response(status, dirWcc));
        }
Beispiel #28
0
        public static Org.Apache.Hadoop.Nfs.Nfs3.Response.WccAttr Deserialize(XDR xdr)
        {
            long    size  = xdr.ReadHyper();
            NfsTime mtime = NfsTime.Deserialize(xdr);
            NfsTime ctime = NfsTime.Deserialize(xdr);

            return(new Org.Apache.Hadoop.Nfs.Nfs3.Response.WccAttr(size, mtime, ctime));
        }
Beispiel #29
0
 public override void Serialize(XDR xdr)
 {
     handle.Serialize(xdr);
     xdr.WriteLongAsHyper(offset);
     xdr.WriteInt(count);
     xdr.WriteInt(stableHow.GetValue());
     xdr.WriteInt(count);
     xdr.WriteFixedOpaque(((byte[])data.Array()), count);
 }
Beispiel #30
0
 public override XDR Umntall(XDR @out, int xid, IPAddress client)
 {
     if (Log.IsDebugEnabled())
     {
         Log.Debug("MOUNT UMNTALL : " + " client: " + client);
     }
     mounts.Clear();
     return(RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(@out));
 }