public static byte[] openAttrs(int user, int group, int other, long sizea) { XdrBufferEncodingStream xdr = new XdrBufferEncodingStream(1024); //starts encoding xdr.beginEncoding(null, 0); user = 7 << 6; group = 7 << 3; other = 7; mode4 fmode = new mode4(); fmode.value = new uint32_t(group + user + other); fattr4_mode mode = new fattr4_mode(fmode); fattr4_size size = new fattr4_size(new uint64_t(sizea)); size.xdrEncode(xdr); mode.xdrEncode(xdr); xdr.endEncoding(); //end encoding byte[] retBytes = new byte[xdr.getXdrLength()]; Array.Copy(xdr.getXdrData(), 0, retBytes, 0, xdr.getXdrLength()); return(retBytes); }
// // Handle incomming calls... // /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> /// <exception cref="System.IO.IOException"></exception> public virtual void dispatchOncRpcCall(OncRpcCallInformation call, int program, int version, int procedure) { // // Spit out some diagnosis messages... // System.Console.Out.WriteLine("Incomming call for program " + program.ToString("X") + "; version " + version + "; procedure " + procedure.ToString("X") + "; auth type " + call.callMessage.auth.getAuthenticationType()); // // Handle incomming credentials... // if (call.callMessage.auth.getAuthenticationType() == OncRpcAuthType .ONCRPC_AUTH_UNIX) { OncRpcServerAuthUnix auth = (OncRpcServerAuthUnix )call.callMessage.auth; if ((auth.uid != 42) && (auth.gid != 815)) { throw (new OncRpcAuthenticationException(OncRpcAuthStatus .ONCRPC_AUTH_BADCRED)); } // // Suggest shorthand authentication... // XdrBufferEncodingStream xdr = new XdrBufferEncodingStream(8); xdr.beginEncoding(null, 0); xdr.xdrEncodeInt(42); xdr.xdrEncodeInt(~42); xdr.endEncoding(); // // ATTENTION: this will return the *whole* buffer created by the // constructor of XdrBufferEncodingStream(len) above. So make sure // that you really want to return the whole buffer! // auth.setShorthandVerifier(xdr.getXdrData()); } else { if (call.callMessage.auth.getAuthenticationType() == OncRpcAuthType .ONCRPC_AUTH_SHORT) { // // Check shorthand credentials. // OncRpcServerAuthShort auth = (OncRpcServerAuthShort)call.callMessage.auth; XdrBufferDecodingStream xdr = new XdrBufferDecodingStream (auth.getShorthandCred()); xdr.beginDecoding(); int credv1 = xdr.xdrDecodeInt(); int credv2 = xdr.xdrDecodeInt(); xdr.endDecoding(); if (credv1 != ~credv2) { Console.Out.WriteLine("AUTH_SHORT rejected"); throw (new OncRpcAuthenticationException(OncRpcAuthStatus.ONCRPC_AUTH_REJECTEDCRED)); } if ((++shorthandCredCounter % 3) == 0) { System.Console.Out.WriteLine("AUTH_SHORT too old"); throw (new OncRpcAuthenticationException(OncRpcAuthStatus .ONCRPC_AUTH_REJECTEDCRED)); } Console.Out.WriteLine("AUTH_SHORT accepted"); } } switch (procedure) { case 0: { // // Now dispatch incomming calls... // // // The usual ONC/RPC PING (aka "NULL" procedure) // call.retrieveCall(XdrVoid.XDR_VOID); call.reply(XdrVoid.XDR_VOID); break; } case 1: { // // echo string parameter // XdrString param = new XdrString(); call.retrieveCall(param); System.Console.Out.WriteLine("Parameter: \"" + param.stringValue() + "\""); call.reply(param); break; } case 42: { // // This is a special call to shut down the server... // if ((program == 42) && (version == 42)) { call.retrieveCall(XdrVoid.XDR_VOID); call.reply(XdrVoid.XDR_VOID); shutdown(); break; } break; } default: { // // For all unknown calls, send back an error reply. // call.failProcedureUnavailable(); break; } } }