/// <summary> /// Register an ONC/RPC with the given program number, version and protocol /// at the given port with the portmapper. /// </summary> /// <remarks> /// Register an ONC/RPC with the given program number, version and protocol /// at the given port with the portmapper. /// </remarks> /// <param name="program">The number of the program to be registered.</param> /// <param name="version">The version number of the program.</param> /// <param name="protocol"> /// The protocol spoken by the ONC/RPC server. Can be one /// of the /// <see cref="OncRpcProtocols">OncRpcProtocols</see> /// constants. /// </param> /// <param name="port">The port number where the ONC/RPC server can be reached.</param> /// <returns> /// Indicates whether registration succeeded (<code>true</code>) or /// was denied by the portmapper (<code>false</code>). /// </returns> /// <exception cref="OncRpcException"> /// if the portmapper is not available (detail is /// <see cref="OncRpcException.RPC_PMAPFAILURE">OncRpcException.RPC_PMAPFAILURE</see> /// ). /// </exception> /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> public virtual bool setPort(int program, int version, int protocol, int port) { // // Fill in the request parameters. // org.acplt.oncrpc.OncRpcServerIdent @params = new org.acplt.oncrpc.OncRpcServerIdent (program, version, protocol, port); org.acplt.oncrpc.XdrBoolean result = new org.acplt.oncrpc.XdrBoolean(false); // // Try to contact the portmap process. If something goes "boing" // at this stage, then rethrow the exception as a generic portmap // failure exception. // try { portmapClient.call(org.acplt.oncrpc.OncRpcPortmapServices.PMAP_SET, @params, result ); } catch (org.acplt.oncrpc.OncRpcException) { throw (new org.acplt.oncrpc.OncRpcException(org.acplt.oncrpc.OncRpcException.RPC_PMAPFAILURE )); } return(result.booleanValue()); }
/// <summary> /// Retrieves a list of all registered ONC/RPC servers at the same host /// as the contacted portmapper. /// </summary> /// <remarks> /// Retrieves a list of all registered ONC/RPC servers at the same host /// as the contacted portmapper. /// </remarks> /// <returns> /// vector of server descriptions (see /// class /// <see cref="OncRpcServerIdent">OncRpcServerIdent</see> /// ). /// </returns> /// <exception cref="OncRpcException"> /// if the portmapper is not available (detail is /// <see cref="OncRpcException.RPC_PMAPFAILURE">OncRpcException.RPC_PMAPFAILURE</see> /// ). /// </exception> /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> public virtual org.acplt.oncrpc.OncRpcServerIdent[] listServers() { // // Fill in the request parameters. // org.acplt.oncrpc.OncRpcDumpResult result = new org.acplt.oncrpc.OncRpcDumpResult( ); // // Try to contact the portmap process. If something goes "boing" // at this stage, then rethrow the exception as a generic portmap // failure exception. // try { portmapClient.call(org.acplt.oncrpc.OncRpcPortmapServices.PMAP_DUMP, org.acplt.oncrpc.XdrVoid .XDR_VOID, result); } catch (org.acplt.oncrpc.OncRpcException) { throw (new org.acplt.oncrpc.OncRpcException(org.acplt.oncrpc.OncRpcException.RPC_PMAPFAILURE )); } // // Copy the server ident object references from the Vector // into the vector (array). // org.acplt.oncrpc.OncRpcServerIdent[] info = new org.acplt.oncrpc.OncRpcServerIdent [result.servers.Count]; result.servers.CopyTo(info); return(info); }
/// <summary> /// Deregister all port settings for a particular (program, version) for /// all transports (TCP, UDP, ...). /// </summary> /// <remarks> /// Deregister all port settings for a particular (program, version) for /// all transports (TCP, UDP, ...). While these are strange semantics, /// they are compatible with Sun's portmap implementation. /// </remarks> /// <param name="params"> /// (program, version) to deregister. The protocol and port /// fields are not used. /// </param> /// <returns><code>true</code> if deregistration succeeded.</returns> internal virtual XdrBoolean unsetPort(org.acplt.oncrpc.OncRpcServerIdent @params) { bool ok = false; if (@params.program != PMAP_PROGRAM) { // // Only allow clients to deregister ONC/RPC servers other than // the portmap entries. // int size = servers.Count; for (int idx = size - 1; idx >= 0; --idx) { org.acplt.oncrpc.OncRpcServerIdent svr = (org.acplt.oncrpc.OncRpcServerIdent)servers [idx]; if ((svr.program == @params.program) && (svr.version == @params.version)) { servers.RemoveAt(idx); ok = true; } } } return(new org.acplt.oncrpc.XdrBoolean(ok)); }
/// <summary>Register a port number for a particular (program, version, protocol).</summary> /// <remarks> /// Register a port number for a particular (program, version, protocol). /// Note that a caller can not register the same (program, version, /// protocol) for another port. In this case we return false. Thus, a /// caller first needs to deregister any old entries which it whishes to /// update. Always add new registration entries to the end of the list /// (vector). /// </remarks> /// <param name="params">(program, version, protocol, port) to register.</param> /// <returns><code>true</code> if registration succeeded.</returns> internal virtual XdrBoolean setPort(org.acplt.oncrpc.OncRpcServerIdent @params) { if (@params.program != PMAP_PROGRAM) { // // Only accept registration attempts for anything other than // the portmapper. We do not want clients to play tricks on us. // int size = servers.Count; for (int idx = 0; idx < size; ++idx) { org.acplt.oncrpc.OncRpcServerIdent svr = (org.acplt.oncrpc.OncRpcServerIdent)servers [idx]; if ((svr.program == @params.program) && (svr.version == @params.version) && (svr. protocol == @params.protocol)) { // // In case (program, version, protocol) is already // registered only accept, if the port stays the same. // This will silently accept double registrations (i.e., // due to duplicated UDP calls). // return(new org.acplt.oncrpc.XdrBoolean(svr.port == @params.port)); } } // // Add new registration entry to end of the list. // servers.Add(@params); return(new org.acplt.oncrpc.XdrBoolean(true)); } return(new org.acplt.oncrpc.XdrBoolean(false)); }
/// <summary>Lookup port for (program, version, protocol).</summary> /// <remarks> /// Lookup port for (program, version, protocol). If no suitable /// registration entry if found and an entry with another version, but the /// same program and version number is found, this is returned instead. /// This is compatible with the way Sun's portmap implementation works. /// </remarks> /// <param name="params"> /// server identification (program, version, protocol) to /// look up. The port field is not used. /// </param> /// <returns> /// port number where server listens for incomming ONC/RPC calls, /// or <code>0</code>, if no server is registered for (program, protocol). /// </returns> internal virtual OncRpcGetPortResult getPort(org.acplt.oncrpc.OncRpcServerIdent @params) { org.acplt.oncrpc.OncRpcServerIdent ident = null; org.acplt.oncrpc.OncRpcGetPortResult result = new org.acplt.oncrpc.OncRpcGetPortResult (); int size = servers.Count; for (int idx = 0; idx < size; ++idx) { org.acplt.oncrpc.OncRpcServerIdent svr = (org.acplt.oncrpc.OncRpcServerIdent)servers [idx]; if ((svr.program == @params.program) && (svr.protocol == @params.protocol)) { // // (program, protocol) already matches. If it has the same // version, then we're done. Otherwise we remember this // entry for possible later usage and search further through // the list. // if (svr.version == @params.version) { result.port = svr.port; return(result); } ident = svr; } } // // Return port of "best" match, if one was found at all, otherwise // just return 0, which indicates an invalid UDP/TCP port. // if (ident == null) { result.port = 0; } else { result.port = ident.port; } return(result); }
/// <summary> /// Asks the portmapper this <code>OncRpcPortmapClient</code> object is /// a proxy for, for the port number of a particular ONC/RPC server /// identified by the information tuple {program number, program version, /// protocol}. /// </summary> /// <remarks> /// Asks the portmapper this <code>OncRpcPortmapClient</code> object is /// a proxy for, for the port number of a particular ONC/RPC server /// identified by the information tuple {program number, program version, /// protocol}. /// </remarks> /// <param name="program">Program number of the remote procedure call in question.</param> /// <param name="version">Program version number.</param> /// <param name="protocol"> /// Protocol lateron used for communication with the /// ONC/RPC server in question. This can be one of the protocols constants /// defined in the /// <see cref="OncRpcProtocols">OncRpcProtocols</see> /// interface. /// </param> /// <returns>port number of ONC/RPC server in question.</returns> /// <exception cref="OncRpcException"> /// if the portmapper is not available (detail is /// <see cref="OncRpcException.RPC_PMAPFAILURE">OncRpcException.RPC_PMAPFAILURE</see> /// ). /// </exception> /// <exception cref="OncRpcProgramNotRegisteredException"> /// if the requested program /// is not available. /// </exception> /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> public virtual int getPort(int program, int version, int protocol) { // // Fill in the request parameters. Note that params.port is // not used. BTW - it is automatically initialized as 0 by the // constructor of the OncRpcServerParams class. // org.acplt.oncrpc.OncRpcServerIdent @params = new org.acplt.oncrpc.OncRpcServerIdent (program, version, protocol, 0); org.acplt.oncrpc.OncRpcGetPortResult result = new org.acplt.oncrpc.OncRpcGetPortResult (); // // Try to contact the portmap process. If something goes "boing" // at this stage, then rethrow the exception as a generic portmap // failure exception. Otherwise, if the port number returned is // zero, then no appropriate server was found. In this case, // throw an exception, that the program requested could not be // found. // try { portmapClient.call(org.acplt.oncrpc.OncRpcPortmapServices.PMAP_GETPORT, @params, result); } catch (org.acplt.oncrpc.OncRpcException) { throw (new org.acplt.oncrpc.OncRpcException(org.acplt.oncrpc.OncRpcException.RPC_PMAPFAILURE )); } // // In case the program is not registered, throw an exception too. // if (result.port == 0) { throw (new org.acplt.oncrpc.OncRpcProgramNotRegisteredException()); } return(result.port); }
/// <summary> /// Register an ONC/RPC with the given program number, version and protocol /// at the given port with the portmapper. /// </summary> /// <remarks> /// Register an ONC/RPC with the given program number, version and protocol /// at the given port with the portmapper. /// </remarks> /// <param name="program">The number of the program to be registered.</param> /// <param name="version">The version number of the program.</param> /// <param name="protocol"> /// The protocol spoken by the ONC/RPC server. Can be one /// of the /// <see cref="OncRpcProtocols">OncRpcProtocols</see> /// constants. /// </param> /// <param name="port">The port number where the ONC/RPC server can be reached.</param> /// <returns> /// Indicates whether registration succeeded (<code>true</code>) or /// was denied by the portmapper (<code>false</code>). /// </returns> /// <exception cref="OncRpcException"> /// if the portmapper is not available (detail is /// <see cref="OncRpcException.RPC_PMAPFAILURE">OncRpcException.RPC_PMAPFAILURE</see> /// ). /// </exception> /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> public virtual bool setPort(int program, int version, int protocol, int port) { // // Fill in the request parameters. // org.acplt.oncrpc.OncRpcServerIdent @params = new org.acplt.oncrpc.OncRpcServerIdent (program, version, protocol, port); org.acplt.oncrpc.XdrBoolean result = new org.acplt.oncrpc.XdrBoolean(false); // // Try to contact the portmap process. If something goes "boing" // at this stage, then rethrow the exception as a generic portmap // failure exception. // try { portmapClient.call(org.acplt.oncrpc.OncRpcPortmapServices.PMAP_SET, @params, result ); } catch (org.acplt.oncrpc.OncRpcException) { throw (new org.acplt.oncrpc.OncRpcException(org.acplt.oncrpc.OncRpcException.RPC_PMAPFAILURE )); } return result.booleanValue(); }
/// <summary> /// Retrieves a list of all registered ONC/RPC servers at the same host /// as the contacted portmapper. /// </summary> /// <remarks> /// Retrieves a list of all registered ONC/RPC servers at the same host /// as the contacted portmapper. /// </remarks> /// <returns> /// vector of server descriptions (see /// class /// <see cref="OncRpcServerIdent">OncRpcServerIdent</see> /// ). /// </returns> /// <exception cref="OncRpcException"> /// if the portmapper is not available (detail is /// <see cref="OncRpcException.RPC_PMAPFAILURE">OncRpcException.RPC_PMAPFAILURE</see> /// ). /// </exception> /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> public virtual org.acplt.oncrpc.OncRpcServerIdent[] listServers() { // // Fill in the request parameters. // org.acplt.oncrpc.OncRpcDumpResult result = new org.acplt.oncrpc.OncRpcDumpResult( ); // // Try to contact the portmap process. If something goes "boing" // at this stage, then rethrow the exception as a generic portmap // failure exception. // try { portmapClient.call(org.acplt.oncrpc.OncRpcPortmapServices.PMAP_DUMP, org.acplt.oncrpc.XdrVoid .XDR_VOID, result); } catch (org.acplt.oncrpc.OncRpcException) { throw (new org.acplt.oncrpc.OncRpcException(org.acplt.oncrpc.OncRpcException.RPC_PMAPFAILURE )); } // // Copy the server ident object references from the Vector // into the vector (array). // org.acplt.oncrpc.OncRpcServerIdent[] info = new org.acplt.oncrpc.OncRpcServerIdent [result.servers.Count]; result.servers.CopyTo(info); return info; }
/// <summary> /// Asks the portmapper this <code>OncRpcPortmapClient</code> object is /// a proxy for, for the port number of a particular ONC/RPC server /// identified by the information tuple {program number, program version, /// protocol}. /// </summary> /// <remarks> /// Asks the portmapper this <code>OncRpcPortmapClient</code> object is /// a proxy for, for the port number of a particular ONC/RPC server /// identified by the information tuple {program number, program version, /// protocol}. /// </remarks> /// <param name="program">Program number of the remote procedure call in question.</param> /// <param name="version">Program version number.</param> /// <param name="protocol"> /// Protocol lateron used for communication with the /// ONC/RPC server in question. This can be one of the protocols constants /// defined in the /// <see cref="OncRpcProtocols">OncRpcProtocols</see> /// interface. /// </param> /// <returns>port number of ONC/RPC server in question.</returns> /// <exception cref="OncRpcException"> /// if the portmapper is not available (detail is /// <see cref="OncRpcException.RPC_PMAPFAILURE">OncRpcException.RPC_PMAPFAILURE</see> /// ). /// </exception> /// <exception cref="OncRpcProgramNotRegisteredException"> /// if the requested program /// is not available. /// </exception> /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> public virtual int getPort(int program, int version, int protocol) { // // Fill in the request parameters. Note that params.port is // not used. BTW - it is automatically initialized as 0 by the // constructor of the OncRpcServerParams class. // org.acplt.oncrpc.OncRpcServerIdent @params = new org.acplt.oncrpc.OncRpcServerIdent (program, version, protocol, 0); org.acplt.oncrpc.OncRpcGetPortResult result = new org.acplt.oncrpc.OncRpcGetPortResult (); // // Try to contact the portmap process. If something goes "boing" // at this stage, then rethrow the exception as a generic portmap // failure exception. Otherwise, if the port number returned is // zero, then no appropriate server was found. In this case, // throw an exception, that the program requested could not be // found. // try { portmapClient.call(org.acplt.oncrpc.OncRpcPortmapServices.PMAP_GETPORT, @params, result); } catch (org.acplt.oncrpc.OncRpcException) { throw (new org.acplt.oncrpc.OncRpcException(org.acplt.oncrpc.OncRpcException.RPC_PMAPFAILURE )); } // // In case the program is not registered, throw an exception too. // if (result.port == 0) { throw (new org.acplt.oncrpc.OncRpcProgramNotRegisteredException()); } return result.port; }
/// <summary>Dispatch incomming ONC/RPC calls to the individual handler functions.</summary> /// <remarks> /// Dispatch incomming ONC/RPC calls to the individual handler functions. /// The CALLIT method is currently unimplemented. /// </remarks> /// <param name="call"> /// The ONC/RPC call, with references to the transport and /// XDR streams to use for retrieving parameters and sending replies. /// </param> /// <param name="program">the portmap's program number, 100000</param> /// <param name="version">the portmap's protocol version, 2</param> /// <param name="procedure">the procedure to call.</param> /// <exception cref="org.acplt.oncrpc.OncRpcException">if an ONC/RPC error occurs.</exception> /// <exception cref="System.IO.IOException">if an I/O error occurs.</exception> public virtual void dispatchOncRpcCall(org.acplt.oncrpc.server.OncRpcCallInformation call, int program, int version, int procedure) { // // Make sure it's the right program and version that we can handle. // (defensive programming) // if (program == PMAP_PROGRAM) { if (version == PMAP_VERSION) { switch (procedure) { case 0: { // handle NULL call. call.retrieveCall(org.acplt.oncrpc.XdrVoid.XDR_VOID); call.reply(org.acplt.oncrpc.XdrVoid.XDR_VOID); break; } case OncRpcPortmapServices.PMAP_GETPORT: { // handle port query org.acplt.oncrpc.OncRpcServerIdent @params = new org.acplt.oncrpc.OncRpcServerIdent (); call.retrieveCall(@params); org.acplt.oncrpc.OncRpcGetPortResult result = getPort(@params); call.reply(result); break; } case OncRpcPortmapServices.PMAP_SET: { // handle port registration // // ensure that no remote client tries to register // OncRpcServerIdent @params = new OncRpcServerIdent (); call.retrieveCall(@params); org.acplt.oncrpc.XdrBoolean result; if (isLocalAddress(call.peerAddress)) { result = setPort(@params); } else { result = new XdrBoolean(false); } call.reply(result); break; } case OncRpcPortmapServices.PMAP_UNSET: { // handle port deregistration OncRpcServerIdent @params = new OncRpcServerIdent (); call.retrieveCall(@params); org.acplt.oncrpc.XdrBoolean result; if (isLocalAddress(call.peerAddress)) { result = unsetPort(@params); } else { result = new XdrBoolean(false); } call.reply(result); break; } case OncRpcPortmapServices.PMAP_DUMP: { // list all registrations call.retrieveCall(org.acplt.oncrpc.XdrVoid.XDR_VOID); org.acplt.oncrpc.OncRpcDumpResult result = listServers(); call.reply(result); break; } default: { // unknown/unimplemented procedure call.failProcedureUnavailable(); break; } } } else { call.failProgramMismatch(PMAP_VERSION, PMAP_VERSION); } } else { call.failProgramUnavailable(); } }
/// <summary>Dispatch incomming ONC/RPC calls to the individual handler functions.</summary> /// <remarks> /// Dispatch incomming ONC/RPC calls to the individual handler functions. /// The CALLIT method is currently unimplemented. /// </remarks> /// <param name="call"> /// The ONC/RPC call, with references to the transport and /// XDR streams to use for retrieving parameters and sending replies. /// </param> /// <param name="program">the portmap's program number, 100000</param> /// <param name="version">the portmap's protocol version, 2</param> /// <param name="procedure">the procedure to call.</param> /// <exception cref="org.acplt.oncrpc.OncRpcException">if an ONC/RPC error occurs.</exception> /// <exception cref="System.IO.IOException">if an I/O error occurs.</exception> public virtual void dispatchOncRpcCall(org.acplt.oncrpc.server.OncRpcCallInformation call, int program, int version, int procedure) { // // Make sure it's the right program and version that we can handle. // (defensive programming) // if (program == PMAP_PROGRAM) { if (version == PMAP_VERSION) { switch (procedure) { case 0: { // handle NULL call. call.retrieveCall(org.acplt.oncrpc.XdrVoid.XDR_VOID); call.reply(org.acplt.oncrpc.XdrVoid.XDR_VOID); break; } case OncRpcPortmapServices.PMAP_GETPORT: { // handle port query org.acplt.oncrpc.OncRpcServerIdent @params = new org.acplt.oncrpc.OncRpcServerIdent (); call.retrieveCall(@params); org.acplt.oncrpc.OncRpcGetPortResult result = getPort(@params); call.reply(result); break; } case OncRpcPortmapServices.PMAP_SET: { // handle port registration // // ensure that no remote client tries to register // OncRpcServerIdent @params = new OncRpcServerIdent (); call.retrieveCall(@params); org.acplt.oncrpc.XdrBoolean result; if (isLocalAddress(call.peerAddress)) { result = setPort(@params); } else { result = new XdrBoolean(false); } call.reply(result); break; } case OncRpcPortmapServices.PMAP_UNSET: { // handle port deregistration OncRpcServerIdent @params = new OncRpcServerIdent (); call.retrieveCall(@params); org.acplt.oncrpc.XdrBoolean result; if (isLocalAddress(call.peerAddress)) { result = unsetPort(@params); } else { result = new XdrBoolean(false); } call.reply(result); break; } case OncRpcPortmapServices.PMAP_DUMP: { // list all registrations call.retrieveCall(org.acplt.oncrpc.XdrVoid.XDR_VOID); org.acplt.oncrpc.OncRpcDumpResult result = listServers(); call.reply(result); break; } default: { // unknown/unimplemented procedure call.failProcedureUnavailable(); break; } } } else { call.failProgramMismatch(PMAP_VERSION, PMAP_VERSION); } } else { call.failProgramUnavailable(); } }