Beispiel #1
0
        /// <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>
 /// 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;
 }
Beispiel #4
0
        /// <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;
        }
Beispiel #5
0
        /// <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();
            }
        }