setUint32() публичный Метод

public setUint32 ( uint value ) : void
value uint
Результат void
Пример #1
0
        private rpcPacker ProgMismatchReply(uint xid)
        {
            rpcPacker reply = NewAcceptReply(xid, 2);

            reply.setUint32(prog);              // rpc_msg.reply_body.accepted_reply.mismatch_info.low
            reply.setUint32(prog);              // rpc_msg.reply_body.accepted_reply.mismatch_info.high

            return(reply);
        }
Пример #2
0
        private void GetPort(rpcCracker cracker, rpcPacker packer)
        {
            const uint IPPROTO_UDP = 17;

            uint prog = cracker.get_uint32();
            uint vers = cracker.get_uint32();
            uint prot = cracker.get_uint32();
            uint port = cracker.get_uint32();

            Console.WriteLine("prog:{0}, vers:{1}, prot:{2}, port:{3}", prog, vers, prot, port);

            uint registeredPort = 0;

            if (prot == IPPROTO_UDP)
            {
                if (prog == (uint)Progs.mountd && vers == (uint)Vers.mountd)
                {
                    registeredPort = (uint)Ports.mountd;
                }
                else if (prog == (uint)Progs.nfsd && vers == (uint)Vers.nfsd)
                {
                    registeredPort = (uint)Ports.nfsd;
                }
            }

            packer.setUint32(registeredPort);
        }
Пример #3
0
        public void Pack(rpcPacker packer)
        {
            packer.setUint32(index);

            // Pad
            packer.setUint32(0);
            packer.setUint32(0);
            packer.setUint32(0);
            packer.setUint32(0);
            packer.setUint32(0);
            packer.setUint32(0);
            packer.setUint32(0);
        }
Пример #4
0
        private rpcPacker RPCMismatchReply(uint xid)
        {
            rpcPacker reply = new rpcPacker();

            reply.setUint32(xid);
            reply.setUint32(1);                         // rpc_msg.REPLY
            reply.setUint32(1);                         // rpc_msg.reply_body.MSG_DENIED
            reply.setUint32(0);                         // rpc_msg.reply_body.rejected_reply.RPC_MISMATCH
            reply.setUint32(2);                         // rpc_msg.reply_body.rejected_reply.mismatch_info.low
            reply.setUint32(2);                         // rpc_msg.reply_body.rejected_reply.mismatch_info.low

            return(reply);
        }
Пример #5
0
        private rpcPacker NewAcceptReply(uint xid, uint acceptStatus)
        {
            rpcPacker reply = new rpcPacker();

            reply.setUint32(xid);
            reply.setUint32(1);                         // rpc_msg.REPLY
            reply.setUint32(0);                         // rpc_msg.reply_body.MSG_ACCEPTED
            reply.setUint32(0);                         // rpc_msg.reply_body.accepted_reply.opaque_auth.NULL
            reply.setUint32(0);                         // rpc_msg.reply_body.accepted_reply.opaque_auth.<datsize>

            // rpc_msg.reply_body.accepted_reply.<case>
            reply.setUint32(acceptStatus);

            return(reply);
        }
Пример #6
0
        private void ReadLink(rpcCracker cracker, rpcPacker packer)
        {
            fhandle fh = new fhandle(cracker);

            FileStream fs;

            try
            {
                fs = new FileStream(FileTable.LookupFileEntry(fh).Name, FileMode.Open, FileAccess.Read);
            }
            catch (System.IO.FileNotFoundException)
            {
                FileTable.Remove(fh);
                throw;
            }

            try
            {
                Byte[] buf = new Byte[MAXPATHLEN];

                int bytesRead = fs.Read(buf, 0, MAXPATHLEN);

                packer.setUint32((uint)NFSStatus.NFS_OK);
                packer.setData(buf, buf.Length);
            }
            finally
            {
                fs.Close();
            }
        }
Пример #7
0
        private void Read(rpcCracker cracker, rpcPacker packer)
        {
            fhandle fh			= new fhandle(cracker);
            uint	offset		= cracker.get_uint32();
            uint	count		= cracker.get_uint32();
            uint	totalCount	= cracker.get_uint32();

            FileStream fs;

            try
            {
                fs = new FileStream(FileTable.LookupFileEntry(fh).Name, FileMode.Open, FileAccess.Read);
            }
            catch (System.IO.FileNotFoundException)
            {
                FileTable.Remove(fh);
                throw;
            }

            try
            {
                fs.Position = offset;

                Byte[] buf = new Byte[count];

                int bytesRead = fs.Read(buf, 0, (int)count);

                fattr attr = new fattr(fh);

                if (attr.IsFile() == false) throw new NFSStatusException(NFSStatus.NFSERR_ISDIR);

                packer.setUint32((uint)NFSStatus.NFS_OK);
                attr.Pack(packer);
                packer.setData(buf, bytesRead);
            }
            finally
            {
                fs.Close();
            }
        }
Пример #8
0
        private rpcPacker RPCMismatchReply(uint xid)
        {
            rpcPacker reply = new rpcPacker();

            reply.setUint32(xid);
            reply.setUint32(1);		// rpc_msg.REPLY
            reply.setUint32(1);		// rpc_msg.reply_body.MSG_DENIED
            reply.setUint32(0);		// rpc_msg.reply_body.rejected_reply.RPC_MISMATCH
            reply.setUint32(2);		// rpc_msg.reply_body.rejected_reply.mismatch_info.low
            reply.setUint32(2);		// rpc_msg.reply_body.rejected_reply.mismatch_info.low

            return reply;
        }
Пример #9
0
 public void Pack(rpcPacker packer)
 {
     packer.setUint32((uint)type);
     packer.setUint32(mode);
     packer.setUint32(nlink);
     packer.setUint32(uid);
     packer.setUint32(gid);
     packer.setUint32(size);
     packer.setUint32(blocksize);
     packer.setUint32(rdev);
     packer.setUint32(blocks);
     packer.setUint32(fsid);
     packer.setUint32(fileid);
     atime.Pack(packer);
     mtime.Pack(packer);
     mtime.Pack(packer);
 }
Пример #10
0
 protected override void Proc(uint proc, rpcCracker cracker, rpcPacker packer)
 {
     try
     {
         switch(proc)
         {
             case 1:
                 GetAttr(cracker, packer);
                 break;
             case 2:
                 SetAttr(cracker, packer);
                 break;
             case 3:
                 // Root(). No-op.
                 break;
             case 4:
                 Lookup(cracker, packer);
                 break;
             case 5:
                 ReadLink(cracker, packer);
                 break;
             case 6:
                 Read(cracker, packer);
                 break;
             case 8:
                 Write(cracker, packer);
                 break;
             case 9:
                 Create(cracker, packer);
                 break;
             case 10:
                 Remove(cracker, packer);
                 break;
             case 11:
                 Rename(cracker, packer);
                 break;
             case 13:
                 SymLink(cracker, packer);
                 break;
             case 14:
                 MkDir(cracker, packer);
                 break;
             case 15:
                 RmDir(cracker, packer);
                 break;
             case 16:
                 ReadDir(cracker, packer);
                 break;
             case 17:
                 StatFS(cracker, packer);
                 break;
             default:
                 throw new BadProc();
         }
     }
     catch(BadProc)
     {
         throw;
     }
     catch(NFSStatusException e)
     {
         packer.setUint32((uint)e.Status);
     }
     catch (System.IO.FileNotFoundException)
     {
         packer.setUint32((uint)NFSStatus.NFSERR_NOENT);
     }
     catch(UnauthorizedAccessException)
     {
         packer.setUint32((uint)NFSStatus.NFSERR_PERM);
     }
     catch(PathTooLongException)
     {
         packer.setUint32((uint)NFSStatus.NFSERR_NAMETOOLONG);
     }
     catch(DirectoryNotFoundException)
     {
         packer.setUint32((uint)NFSStatus.NFSERR_NOTDIR);
     }
     catch(Exception e)
     {
         Console.WriteLine("nfsd error:{0}", e);
         packer.setUint32((uint)NFSStatus.NFSERR_IO);
     }
 }
Пример #11
0
        private void RmDir(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);

            String removePath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName;

            Console.WriteLine(@"RmDir: {0}", removePath);

            fhandle fh = FileTable.LookupFileHandle(removePath);

            try
            {
                new DirectoryInfo(removePath).Delete(false);
            }
            catch (IOException)
            {
                if (new DirectoryInfo(removePath).GetFileSystemInfos().Length > 0)
                    throw new NFSStatusException(NFSStatus.NFSERR_NOTEMPTY);
                else
                        throw new NFSStatusException(NFSStatus.NFSERR_PERM);
            }

            if (fh != null) FileTable.Remove(fh);

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Пример #12
0
        public bool Pack(rpcPacker packer, uint cookie, uint count)
        {
            packer.setUint32((uint)NFSStatus.NFS_OK);

              		uint size = 8;	// First pointer + EOF

            if (cookie >= entries.Length)
            {
                // nothing
            }
            else
            {
                do
                {
                    entry next = entries[cookie];

                    if (size + next.Size > count)
                        break;
                    else
                        size += next.Size;

                    // true as in yes, more follows.  This is *entry.
                    packer.setUint32(1);

                    next.Pack(packer);
                }
                while (++cookie < entries.Length);
            }

            // false as in no more follow.  This is *entry.
            // Unlike EOF which is set only when all entries have been sent
            // *entry is reset to false following the last entry in each
            // batch.
            packer.setUint32(0);

            //Console.WriteLine("ReadDir: Pack done.  cookie:{0}, size:{1}", cookie, size);

            // EOF
            if (cookie >= entries.Length)
            {
                packer.setUint32((uint)1);	// yes
                return true;
            }
            else
            {
                packer.setUint32((uint)0);	// no
                return false;
            }
        }
Пример #13
0
        private void Mount(rpcCracker cracker, rpcPacker reply)
        {
            uint length = cracker.get_uint32();

            string dirPath = "";

            for (uint i = 0; i < length; ++i)
                dirPath += cracker.get_char();

            Console.WriteLine("Mount {0}:{1}", length, dirPath);

            if (Directory.Exists(dirPath) == false)
            {
                reply.setUint32(2);	// Errno for no such file or directory
                reply.setUint32(0);	// Where fh would go
            }
            else
            {
                fhandle fh = FileTable.Add(new FileEntry(dirPath));

                reply.setUint32(0);		// Success

                fh.Pack(reply);
            }
        }
Пример #14
0
 public static void PackSuccess(rpcPacker packer, fattr attr)
 {
     packer.setUint32((uint)NFSStatus.NFS_OK);
     attr.Pack(packer);
 }
Пример #15
0
 public static void PackError(rpcPacker packer, NFSStatus error)
 {
     packer.setUint32((uint)error);
 }
Пример #16
0
        private void Remove(rpcCracker cracker, rpcPacker packer)
        {
            diropargs args = new diropargs(cracker);

            String removePath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName;

            FileInfo info = new FileInfo(removePath);

            if (info.Exists == false)
            {
                removePath += ".sl";
                info = new FileInfo(removePath);
            }

            Console.WriteLine(@"Remove: {0}", removePath);

            fhandle fh = FileTable.LookupFileHandle(removePath);

            info.Delete();
            // If UnauthorizedAccessException is thrown & caught should
            // probably stat file to determine if the cause is because
            // the path is a dir rather than a directory.

            if (fh != null) FileTable.Remove(fh);

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Пример #17
0
        private void Rename(rpcCracker cracker, rpcPacker packer)
        {
            diropargs from	= new diropargs(cracker);
            diropargs to	= new diropargs(cracker);

            string fromPath = FileTable.LookupFileEntry(from.DirHandle).Name + @"\" + from.FileName;
            string toPath = FileTable.LookupFileEntry(to.DirHandle).Name + @"\" + to.FileName;

            Console.WriteLine("Rename {0} to {1}", fromPath, toPath);

            if (File.Exists(toPath) == true)
                File.Delete(toPath);

            File.Move(fromPath, toPath);

            // Only bother updating the FileTable if the operation was successful
            FileTable.Rename(fromPath, toPath);

            packer.setUint32((uint)NFSStatus.NFS_OK);
        }
Пример #18
0
        public void Pack(rpcPacker packer)
        {
            //Console.WriteLine("entry pack name:{0}", name);

            packer.setUint32(fileid);
            packer.setString(name);
            packer.setUint32(cookie);
        }
Пример #19
0
        private void StatFS(rpcCracker cracker, rpcPacker packer)
        {
            const uint BLOCK_SIZE = 4096;

            fhandle fh = new fhandle(cracker);

            FileEntry file = FileTable.LookupFileEntry(fh);

            Console.WriteLine("StatFS: {0}", file.Name);

            System.UInt64 freeBytesAvailable		= 0;
            System.UInt64 totalNumberOfBytes		= 0;
            System.UInt64 totalNumberOfFreeBytes	= 0;

            if (UnmanagedWin32API.GetDiskFreeSpaceEx(file.Name, ref freeBytesAvailable, ref totalNumberOfBytes, ref totalNumberOfFreeBytes) == false)
                throw new NFSStatusException(NFSStatus.NFSERR_EXIST);

            freeBytesAvailable		/= BLOCK_SIZE;
            totalNumberOfBytes		/= BLOCK_SIZE;
            totalNumberOfFreeBytes	/= BLOCK_SIZE;

            packer.setUint32((uint)NFSStatus.NFS_OK);
            packer.setUint32(BLOCK_SIZE);				// tsize: optimum transfer size
            packer.setUint32(BLOCK_SIZE);				// Block size of FS
            packer.setUint32((uint)totalNumberOfBytes);		// Total # of blocks (of the above size)
            packer.setUint32((uint)totalNumberOfFreeBytes);	// Free blocks
            packer.setUint32((uint)freeBytesAvailable);		// Free blocks available to non-priv. users
        }
Пример #20
0
        private rpcPacker NewAcceptReply(uint xid, uint acceptStatus)
        {
            rpcPacker reply = new rpcPacker();

            reply.setUint32(xid);
            reply.setUint32(1);		// rpc_msg.REPLY
            reply.setUint32(0);		// rpc_msg.reply_body.MSG_ACCEPTED
            reply.setUint32(0);		// rpc_msg.reply_body.accepted_reply.opaque_auth.NULL
            reply.setUint32(0);		// rpc_msg.reply_body.accepted_reply.opaque_auth.<datsize>

            // rpc_msg.reply_body.accepted_reply.<case>
            reply.setUint32(acceptStatus);

            return reply;
        }
Пример #21
0
        private void SymLink(rpcCracker cracker, rpcPacker packer)
        {
            diropargs	args	= new diropargs(cracker);
            string		path	= cracker.get_String();
            sattr		attr	= new sattr(cracker);

            String createPath = FileTable.LookupFileEntry(args.DirHandle).Name + @"\" + args.FileName + ".sl";

            Console.WriteLine("Symlink: {0}->{1}", createPath, path);

            fhandle fh;

            if ((fh = FileTable.LookupFileHandle(createPath)) == null)
                fh = FileTable.Add(new FileEntry(createPath));

            try
            {
                FileStream symlink = new FileStream(createPath, FileMode.CreateNew, FileAccess.Write);

                try
                {
                    UTF8Encoding pathUTF8 = new UTF8Encoding();

                    byte[] buf = pathUTF8.GetBytes(path);

                    symlink.Write(buf, 0, buf.Length);

                    packer.setUint32((uint)NFSStatus.NFS_OK);
                }
                finally
                {
                    symlink.Close();
                }
            }
            catch(IOException)
            {
                if (new FileInfo(createPath).Exists == true)
                    throw new NFSStatusException(NFSStatus.NFSERR_EXIST);
                else
                    throw;
            }
        }
Пример #22
0
 public void Pack(rpcPacker packer)
 {
     packer.setUint32(seconds);
     packer.setUint32(useconds);
 }