View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.net.bsd;
19  
20  import java.io.IOException;
21  
22  /***
23   * RLoginClient is very similar to
24   * {@link org.apache.commons.net.bsd.RCommandClient},
25   * from which it is derived, and uses the rcmd() facility implemented
26   * in RCommandClient to implement the functionality of the rlogin command that
27   * first appeared in 4.2BSD Unix.  rlogin is a command used to login to
28   * a remote machine from a trusted host, sometimes without issuing a
29   * password.  The trust relationship is the same as described in
30   * the documentation for
31   * {@link org.apache.commons.net.bsd.RCommandClient}.
32   * <p>
33   * As with virtually all of the client classes in org.apache.commons.net, this
34   * class derives from SocketClient.  But it relies on the connection
35   * methods defined  in RcommandClient which ensure that the local Socket
36   * will originate from an acceptable rshell port.  The way to use
37   * RLoginClient is to first connect
38   * to the server, call the {@link #rlogin  rlogin() } method,
39   * and then
40   * fetch the connection's input and output streams.
41   * Interaction with the remote command is controlled entirely through the
42   * I/O streams.  Once you have finished processing the streams, you should
43   * invoke {@link org.apache.commons.net.bsd.RExecClient#disconnect disconnect() }
44   *  to clean up properly.
45   * <p>
46   * The standard output and standard error streams of the
47   * remote process are transmitted over the same connection, readable
48   * from the input stream returned by
49   * {@link org.apache.commons.net.bsd.RExecClient#getInputStream getInputStream() }
50   * .  Unlike RExecClient and RCommandClient, it is
51   * not possible to tell the rlogind daemon to return the standard error
52   * stream over a separate connection.
53   * {@link org.apache.commons.net.bsd.RExecClient#getErrorStream getErrorStream() }
54   *  will always return null.
55   * The standard input of the remote process can be written to through
56   * the output stream returned by
57   * {@link org.apache.commons.net.bsd.RExecClient#getOutputStream getOutputSream() }
58   * .
59   * <p>
60   * <p>
61   * @see org.apache.commons.net.SocketClient
62   * @see RExecClient
63   * @see RCommandClient
64   ***/
65  
66  public class RLoginClient extends RCommandClient
67  {
68      /***
69       * The default rlogin port.  Set to 513 in BSD Unix and according
70       * to RFC 1282.
71       ***/
72      public static final int DEFAULT_PORT = 513;
73  
74      /***
75       * The default RLoginClient constructor.  Initializes the
76       * default port to <code> DEFAULT_PORT </code>.
77       ***/
78      public RLoginClient()
79      {
80          setDefaultPort(DEFAULT_PORT);
81      }
82  
83  
84      /***
85       * Logins into a remote machine through the rlogind daemon on the server
86       * to which the RLoginClient is connected.  After calling this method,
87       * you may interact with the remote login shell through its standard input
88       * and output streams.  Standard error is sent over the same stream as
89       * standard output.  You will typically be able to detect
90       * the termination of the remote login shell after reaching end of file
91       * on its standard output (accessible through
92       * {@link #getInputStream  getInputStream() }.  Disconnecting
93       * from the server or closing the process streams before reaching
94       * end of file will terminate the remote login shell in most cases.
95       * <p>
96       * If user authentication fails, the rlogind daemon will request that
97       * a password be entered interactively.  You will be able to read the
98       * prompt from the output stream of the RLoginClient and write the
99       * password to the input stream of the RLoginClient.
100      * <p>
101      * @param localUsername  The user account on the local machine that is
102      *        trying to login to the remote host.
103      * @param remoteUsername  The account name on the server that is
104      *        being logged in to.
105      * @param terminalType   The name of the user's terminal (e.g., "vt100",
106      *        "network", etc.)
107      * @param terminalSpeed  The speed of the user's terminal, expressed
108      *        as a baud rate or bps (e.g., 9600 or 38400)
109      * @exception IOException If the rlogin() attempt fails.  The exception
110      *            will contain a message indicating the nature of the failure.
111      ***/
112     public void rlogin(String localUsername, String remoteUsername,
113                        String terminalType, int terminalSpeed)
114     throws IOException
115     {
116         rexec(localUsername, remoteUsername, terminalType + "/" + terminalSpeed,
117               false);
118     }
119 
120     /***
121      * Same as the other rlogin method, but no terminal speed is defined.
122      ***/
123     public void rlogin(String localUsername, String remoteUsername,
124                        String terminalType)
125     throws IOException
126     {
127         rexec(localUsername, remoteUsername, terminalType, false);
128     }
129 
130 }