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