    View Javadoc
    1   package org.apache.commons.net.bsd;
    2
    3   /* ====================================================================
    4    * The Apache Software License, Version 1.1
    5    *
    6    * Copyright (c) 2001 The Apache Software Foundation.  All rights
    7    * reserved.
    8    *
    9    * Redistribution and use in source and binary forms, with or without
    10   * modification, are permitted provided that the following conditions
    11   * are met:
    12   *
    13   * 1. Redistributions of source code must retain the above copyright
    14   *    notice, this list of conditions and the following disclaimer.
    15   *
    16   * 2. Redistributions in binary form must reproduce the above copyright
    17   *    notice, this list of conditions and the following disclaimer in
    18   *    the documentation and/or other materials provided with the
    19   *    distribution.
    20   *
    21   * 3. The end-user documentation included with the redistribution,
    22   *    if any, must include the following acknowledgment:
    23   *       "This product includes software developed by the
    24   *        Apache Software Foundation (http://www.apache.org/)."
    25   *    Alternately, this acknowledgment may appear in the software itself,
    26   *    if and wherever such third-party acknowledgments normally appear.
    27   *
    28   * 4. The names "Apache" and "Apache Software Foundation" and
    29   *    "Apache Commons" must not be used to endorse or promote products
    30   *    derived from this software without prior written permission. For
    31   *    written permission, please contact apache@apache.org.
    32   *
    33   * 5. Products derived from this software may not be called "Apache",
    34   *    nor may "Apache" appear in their name, without
    35   *    prior written permission of the Apache Software Foundation.
    36   *
    37   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    38   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    39   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    40   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
    41   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    42   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    43   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    44   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    45   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    46   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    47   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    48   * SUCH DAMAGE.
    49   * ====================================================================
    50   *
    51   * This software consists of voluntary contributions made by many
    52   * individuals on behalf of the Apache Software Foundation.  For more
    53   * information on the Apache Software Foundation, please see
    54   * <http://www.apache.org/>;.
    55   */
    56
    57  import java.io.IOException;
    58
    59  /****
    60   * RLoginClient is very similar to
    61   * <a href="org.apache.commons.net.bsd.RCommandClient.html"> RCommandClient </a>,
    62   * from which it is derived, and uses the rcmd() facility implemented
    63   * in RCommandClient to implement the functionality of the rlogin command that
    64   * first appeared in 4.2BSD Unix.  rlogin is a command used to login to
    65   * a remote machine from a trusted host, sometimes without issuing a
    66   * password.  The trust relationship is the same as described in
    67   * the documentation for
    68   * <a href="org.apache.commons.net.bsd.RCommandClient.html"> RCommandClient </a>.
    69   * <p>
    70   * As with virtually all of the client classes in org.apache.commons.net, this
    71   * class derives from SocketClient.  But it relies on the connection
    72   * methods defined  in RcommandClient which ensure that the local Socket
    73   * will originate from an acceptable rshell port.  The way to use
    74   * RLoginClient is to first connect
    75   * to the server, call the <a href="#rlogin"> rlogin() </a> method,
    76   * and then
    77   * fetch the connection's input and output streams.
    78   * Interaction with the remote command is controlled entirely through the
    79   * I/O streams.  Once you have finished processing the streams, you should
    80   * invoke <a href="org.apache.commons.net.bsd.RExecClient.html#disconnect">
    81   * disconnect() </a> to clean up properly.
    82   * <p>
    83   * The standard output and standard error streams of the
    84   * remote process are transmitted over the same connection, readable
    85   * from the input stream returned by
    86   * <a href="org.apache.commons.net.bsd.RExecClient.html#getInputStream">
    87   * getInputStream() </a>.  Unlike RExecClient and RCommandClient, it is
    88   * not possible to tell the rlogind daemon to return the standard error
    89   * stream over a separate connection.
    90   * <a href="org.apache.commons.net.bsd.RExecClient.html#getErrorStream">
    91   * getErrorStream() </a> will always return null.
    92   * The standard input of the remote process can be written to through
    93   * the output stream returned by
    94   * <a href="org.apache.commons.net.bsd.RExecClient.html#getOutputStream">
    95   * getOutputSream() </a>.
    96   * <p>
    97   * <p>
    98   * @author Daniel F. Savarese
    99   * @see org.apache.commons.net.SocketClient
    100  * @see RExecClient
    101  * @see RCommandClient
    102  ***/
    103
    104 public class RLoginClient extends RCommandClient
    105 {
    106     /****
    107      * The default rlogin port.  Set to 513 in BSD Unix and according
    108      * to RFC 1282.
    109      ***/
    110     public static final int DEFAULT_PORT = 513;
    111
    112     /****
    113      * The default RLoginClient constructor.  Initializes the
    114      * default port to <code> DEFAULT_PORT </code>.
    115      ***/
    116     public RLoginClient()
    117     {
    118         setDefaultPort(DEFAULT_PORT);
    119     }
    120
    121
    122     /****
    123      * Logins into a remote machine through the rlogind daemon on the server
    124      * to which the RLoginClient is connected.  After calling this method,
    125      * you may interact with the remote login shell through its standard input
    126      * and output streams.  Standard error is sent over the same stream as
    127      * standard output.  You will typically be able to detect
    128      * the termination of the remote login shell after reaching end of file
    129      * on its standard output (accessible through
    130      * <a href="#getInputStream"> getInputStream() </a>.  Disconnecting
    131      * from the server or closing the process streams before reaching
    132      * end of file will terminate the remote login shell in most cases.
    133      * <p>
    134      * If user authentication fails, the rlogind daemon will request that
    135      * a password be entered interactively.  You will be able to read the
    136      * prompt from the output stream of the RLoginClient and write the
    137      * password to the input stream of the RLoginClient.
    138      * <p>
    139      * @param localUsername  The user account on the local machine that is
    140      *        trying to login to the remote host.
    141      * @param remoteUsername  The account name on the server that is
    142      *        being logged in to.
    143      * @param terminalType   The name of the user's terminal (e.g., "vt100",
    144      *        "network", etc.)
    145      * @param terminalSpeed  The speed of the user's terminal, expressed
    146      *        as a baud rate or bps (e.g., 9600 or 38400)
    147      * @exception IOException If the rlogin() attempt fails.  The exception
    148      *            will contain a message indicating the nature of the failure.
    149      ***/
    150     public void rlogin(String localUsername, String remoteUsername,
    151                        String terminalType, int terminalSpeed)
    152     throws IOException
    153     {
    154         rexec(localUsername, remoteUsername, terminalType + "/" + terminalSpeed,
    155               false);
    156     }
    157
    158     /****
    159      * Same as the other rlogin method, but no terminal speed is defined.
    160      ***/
    161     public void rlogin(String localUsername, String remoteUsername,
    162                        String terminalType)
    163     throws IOException
    164     {
    165         rexec(localUsername, remoteUsername, terminalType, false);
    166     }
    167
    168 }

This page was automatically generated by Maven