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