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); }
private void CrackVerifier(rpcCracker cracker) { uint flavor = cracker.get_uint32(); uint length = cracker.get_uint32(); //Console.WriteLine("{0}: Credentials. flavor:{1}, length:{2}", prog, flavor, length); cracker.jump(length); }
public sattr(rpcCracker cracker) { mode = cracker.get_uint32(); uid = cracker.get_uint32(); gid = cracker.get_uint32(); size = cracker.get_uint32(); atime = new timeval(cracker); mtime = new timeval(cracker); }
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); } }
public fhandle(rpcCracker cracker) { index = cracker.get_uint32(); cracker.get_uint32(); cracker.get_uint32(); cracker.get_uint32(); cracker.get_uint32(); cracker.get_uint32(); cracker.get_uint32(); cracker.get_uint32(); }
private rpcPacker CrackRPC(rpcCracker cracker) { uint xid = cracker.get_uint32(); uint msg_type = cracker.get_uint32(); uint rpcvers = cracker.get_uint32(); uint prog = cracker.get_uint32(); uint vers = cracker.get_uint32(); uint proc = cracker.get_uint32(); #if DEBUG Console.WriteLine("{0}> {1}: xid:{2}, type:{3}, rpcvers:{4}, prog:{5}, vers:{6}, proc:{7}", ++count, this.prog, xid, msg_type, rpcvers, prog, vers, proc); #endif if (msg_type != 0) { return(GarbageArgsReply(xid)); } if (rpcvers != 2) { return(RPCMismatchReply(xid)); } if (this.prog != prog && Prog(prog) != true) { return(ProgMismatchReply(xid)); } CrackCredentials(cracker); CrackVerifier(cracker); try { rpcPacker reply = SuccessReply(xid); if (proc != 0) { Proc(proc, cracker, reply); } return(reply); } catch (Exception e) { System.Console.WriteLine("Whoops: {0}", e); return(ProcUnavilReply(xid)); } }
private void Write(rpcCracker cracker, rpcPacker packer) { fhandle fh = new fhandle(cracker); uint beginOffset = cracker.get_uint32(); uint offset = cracker.get_uint32(); uint totalcount = cracker.get_uint32(); Byte[] data = cracker.getData(); FileStream fs; try { fs = new FileStream(FileTable.LookupFileEntry(fh).Name, FileMode.Open, FileAccess.Write); } catch (System.IO.FileNotFoundException) { FileTable.Remove(fh); throw; } try { fs.Position = offset; fs.Write(data, 0, data.Length); attrstat.PackSuccess(packer, new fattr(fh)); } finally { fs.Close(); } }
private void ReadDir(rpcCracker cracker, rpcPacker packer) { fhandle fh = new fhandle(cracker); uint cookie = cracker.get_uint32(); uint count = cracker.get_uint32(); FileEntry dir = FileTable.LookupFileEntry(fh); //Console.WriteLine("ReadDir:{0}, cookie:{1}, count:{2}, resultsNULL:{3}", dir.Name, cookie, count, results == null); if (cookie == 0 || results == null) { if (dir == null) throw new NFSStatusException(NFSStatus.NFSERR_EXIST); try { results = new readdirres(dir.Name, count); } catch(DirectoryNotFoundException) { FileTable.Remove(fh); throw; } } if (results.Pack(packer, cookie, count) == true) results = null; }
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(); } }
private rpcPacker CrackRPC(rpcCracker cracker) { uint xid = cracker.get_uint32(); uint msg_type = cracker.get_uint32(); uint rpcvers = cracker.get_uint32(); uint prog = cracker.get_uint32(); uint vers = cracker.get_uint32(); uint proc = cracker.get_uint32(); #if DEBUG Console.WriteLine("{0}> {1}: xid:{2}, type:{3}, rpcvers:{4}, prog:{5}, vers:{6}, proc:{7}", ++count, this.prog, xid, msg_type, rpcvers, prog, vers, proc); #endif if (msg_type != 0) return GarbageArgsReply(xid); if (rpcvers != 2) return RPCMismatchReply(xid); if (this.prog != prog && Prog(prog) != true) return ProgMismatchReply(xid); CrackCredentials(cracker); CrackVerifier(cracker); try { rpcPacker reply = SuccessReply(xid); if (proc != 0) Proc(proc, cracker, reply); return reply; } catch (Exception e) { System.Console.WriteLine("Whoops: {0}", e); return ProcUnavilReply(xid); } }
private void UMount(rpcCracker cracker, rpcPacker reply) { uint length = cracker.get_uint32(); string dirPath = ""; for (uint i = 0; i < length; ++i) dirPath += cracker.get_char(); Console.WriteLine("UMount {0}:{1}", length, dirPath); #if FOO uint fh = fileHandles.Find( if (fileHandles.Remove(dirPath) == false) Console.WriteLine("{0} not mounted", dirPath); #endif }
public timeval(rpcCracker cracker) { seconds = cracker.get_uint32(); useconds = cracker.get_uint32(); }