public virtual void checkEcho(OncRpcClient client, string[] messages ) { for (int idx = 0; idx < messages.Length; ++idx) { XdrString @params = new XdrString(messages[idx] ); XdrString result = new XdrString(); System.Console.Out.Write("checking echo: "); try { client.call(1, @params, result); } catch (OncRpcException e) { System.Console.Out.WriteLine("method call failed unexpectedly:"); System.Console.Out.WriteLine(e.StackTrace); System.Environment.Exit(1); } if ([email protected]().Equals(result.stringValue())) { Console.Out.WriteLine("answer does not match call:"); Console.Out.WriteLine(" expected: \"" + @params.stringValue() + "\""); Console.Out.WriteLine(" but got: \"" + result.stringValue() + "\""); System.Environment.Exit(1); } System.Console.Out.WriteLine(result.stringValue()); } }
// // 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; } } }