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