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 examples; 19 20 import java.io.IOException; 21 import org.apache.commons.net.bsd.RLoginClient; 22 23 /*** 24 * This is an example program demonstrating how to use the RLoginClient 25 * class. This program connects to an rlogin daemon and begins to 26 * interactively read input from stdin (this will be line buffered on most 27 * systems, so don't expect character at a time interactivity), passing it 28 * to the remote login process and writing the remote stdout and stderr 29 * to local stdout. If you don't have .rhosts or hosts.equiv files set up, 30 * the rlogin daemon will prompt you for a password. 31 * <p> 32 * On Unix systems you will not be able to use the rshell capability 33 * unless the process runs as root since only root can bind port addresses 34 * lower than 1024. 35 * <p> 36 * JVM's using green threads will likely have problems if the rlogin daemon 37 * requests a password. This program is merely a demonstration and is 38 * not suitable for use as an application, especially given that it relies 39 * on line buffered input from System.in. The best way to run this example 40 * is probably from a Win95 dos box into a Unix host. 41 * <p> 42 * Example: java rlogin myhost localusername remoteusername vt100 43 * <p> 44 * Usage: rlogin <hostname> <localuser> <remoteuser> <terminal> 45 * <p> 46 ***/ 47 48 // This class requires the IOUtil support class! 49 public final class rlogin 50 { 51 52 public static final void main(String[] args) 53 { 54 String server, localuser, remoteuser, terminal; 55 RLoginClient client; 56 57 if (args.length != 4) 58 { 59 System.err.println( 60 "Usage: rlogin <hostname> <localuser> <remoteuser> <terminal>"); 61 System.exit(1); 62 return ; // so compiler can do proper flow control analysis 63 } 64 65 client = new RLoginClient(); 66 67 server = args[0]; 68 localuser = args[1]; 69 remoteuser = args[2]; 70 terminal = args[3]; 71 72 try 73 { 74 client.connect(server); 75 } 76 catch (IOException e) 77 { 78 System.err.println("Could not connect to server."); 79 e.printStackTrace(); 80 System.exit(1); 81 } 82 83 try 84 { 85 client.rlogin(localuser, remoteuser, terminal); 86 } 87 catch (IOException e) 88 { 89 try 90 { 91 client.disconnect(); 92 } 93 catch (IOException f) 94 {} 95 e.printStackTrace(); 96 System.err.println("rlogin authentication failed."); 97 System.exit(1); 98 } 99 100 101 IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), 102 System.in, System.out); 103 104 try 105 { 106 client.disconnect(); 107 } 108 catch (IOException e) 109 { 110 e.printStackTrace(); 111 System.exit(1); 112 } 113 114 System.exit(0); 115 } 116 117 } 118