/// <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); }
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)); }
/// <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); }
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)); }
public static XDR PmapList(XDR xdr, int xid, PortmapMapping[] list) { RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(xdr); foreach (PortmapMapping mapping in list) { xdr.WriteBoolean(true); // Value follows mapping.Serialize(xdr); } xdr.WriteBoolean(false); // No value follows return(xdr); }
/// <summary> /// Response for RPC call /// <see cref="MNTPROC.Mnt"/> /// /// </summary> public static XDR WriteMNTResponse(int status, XDR xdr, int xid, byte[] handle) { RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(xdr); xdr.WriteInt(status); if (status == MntOk) { xdr.WriteVariableOpaque(handle); // Only MountV3 returns a list of supported authFlavors xdr.WriteInt(1); xdr.WriteInt(RpcAuthInfo.AuthFlavor.AuthSys.GetValue()); } return(xdr); }
public override XDR Umnt(XDR xdr, XDR @out, int xid, IPAddress client) { string path = xdr.ReadString(); if (Log.IsDebugEnabled()) { Log.Debug("MOUNT UMNT path: " + path + " client: " + client); } string host = client.GetHostName(); mounts.Remove(new MountEntry(host, path)); RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(@out); return(@out); }
/// <summary> /// Response for RPC call /// <see cref="MNTPROC.Dump"/> /// /// </summary> public static XDR WriteMountList(XDR xdr, int xid, IList <MountEntry> mounts) { RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(xdr); foreach (MountEntry mountEntry in mounts) { xdr.WriteBoolean(true); // Value follows yes xdr.WriteString(mountEntry.GetHost()); xdr.WriteString(mountEntry.GetPath()); } xdr.WriteBoolean(false); // Value follows no return(xdr); }
protected override void HandleInternal(ChannelHandlerContext ctx, RpcInfo info) { RpcCall rpcCall = (RpcCall)info.Header(); MountInterface.MNTPROC mntproc = MountInterface.MNTPROC.FromValue(rpcCall.GetProcedure ()); int xid = rpcCall.GetXid(); byte[] data = new byte[info.Data().ReadableBytes()]; info.Data().ReadBytes(data); XDR xdr = new XDR(data); XDR @out = new XDR(); IPAddress client = ((IPEndPoint)info.RemoteAddress()).Address; if (mntproc == MountInterface.MNTPROC.Null) { @out = NullOp(@out, xid, client); } else { if (mntproc == MountInterface.MNTPROC.Mnt) { // Only do port monitoring for MNT if (!DoPortMonitoring(info.RemoteAddress())) { @out = MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null); } else { @out = Mnt(xdr, @out, xid, client); } } else { if (mntproc == MountInterface.MNTPROC.Dump) { @out = Dump(@out, xid, client); } else { if (mntproc == MountInterface.MNTPROC.Umnt) { @out = Umnt(xdr, @out, xid, client); } else { if (mntproc == MountInterface.MNTPROC.Umntall) { Umntall(@out, xid, client); } else { if (mntproc == MountInterface.MNTPROC.Export) { // Currently only support one NFS export IList <NfsExports> hostsMatchers = new AList <NfsExports>(); if (hostsMatcher != null) { hostsMatchers.AddItem(hostsMatcher); @out = MountResponse.WriteExportList(@out, xid, exports, hostsMatchers); } else { // This means there are no valid exports provided. RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone ()).Write(@out); } } else { // Invalid procedure RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone ()).Write(@out); } } } } } } ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer()); RpcResponse rsp = new RpcResponse(buf, info.RemoteAddress()); RpcUtil.SendRpcResponse(ctx, rsp); }
public static XDR VoidReply(XDR xdr, int xid) { RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(xdr); return(xdr); }
public static XDR BooleanReply(XDR xdr, int xid, bool value) { RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(xdr); xdr.WriteBoolean(value); return(xdr); }
public static XDR IntReply(XDR xdr, int xid, int value) { RpcAcceptedReply.GetAcceptInstance(xid, new VerifierNone()).Write(xdr); xdr.WriteInt(value); return(xdr); }
/// <exception cref="System.Exception"/> public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e) { RpcInfo info = (RpcInfo)e.GetMessage(); RpcCall rpcCall = (RpcCall)info.Header(); int portmapProc = rpcCall.GetProcedure(); int xid = rpcCall.GetXid(); XDR @in = new XDR(info.Data().ToByteBuffer().AsReadOnlyBuffer(), XDR.State.Reading ); XDR @out = new XDR(); if (portmapProc == PmapprocNull) { @out = NullOp(xid, @in, @out); } else { if (portmapProc == PmapprocSet) { @out = Set(xid, @in, @out); } else { if (portmapProc == PmapprocUnset) { @out = Unset(xid, @in, @out); } else { if (portmapProc == PmapprocDump) { @out = Dump(xid, @in, @out); } else { if (portmapProc == PmapprocGetport) { @out = Getport(xid, @in, @out); } else { if (portmapProc == PmapprocGetversaddr) { @out = Getport(xid, @in, @out); } else { Log.Info("PortmapHandler unknown rpc procedure=" + portmapProc); RpcAcceptedReply reply = RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState .ProcUnavail, new VerifierNone()); reply.Write(@out); } } } } } } ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer()); RpcResponse rsp = new RpcResponse(buf, info.RemoteAddress()); RpcUtil.SendRpcResponse(ctx, rsp); }