1 /* 2 * Copyright (c) 1988, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char copyright[] = 10 "@(#) Copyright (c) 1988, 1990, 1993\n\ 11 The Regents of the University of California. All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 05/30/95"; 16 #endif /* not lint */ 17 18 #include <sys/types.h> 19 20 #include "ring.h" 21 #include "externs.h" 22 #include "defines.h" 23 24 /* These values need to be the same as defined in libtelnet/kerberos5.c */ 25 /* Either define them in both places, or put in some common header file. */ 26 #define OPTS_FORWARD_CREDS 0x00000002 27 #define OPTS_FORWARDABLE_CREDS 0x00000001 28 29 #if 0 30 #define FORWARD 31 #endif 32 33 /* 34 * Initialize variables. 35 */ 36 void 37 tninit() 38 { 39 init_terminal(); 40 41 init_network(); 42 43 init_telnet(); 44 45 init_sys(); 46 47 #if defined(TN3270) 48 init_3270(); 49 #endif 50 } 51 52 void 53 usage() 54 { 55 fprintf(stderr, "Usage: %s %s%s%s%s\n", 56 prompt, 57 #ifdef AUTHENTICATION 58 "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]", 59 "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] ", 60 #else 61 "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]", 62 "\n\t[-n tracefile]", 63 #endif 64 #if defined(TN3270) && defined(unix) 65 # ifdef AUTHENTICATION 66 "[-noasynch] [-noasynctty]\n\t[-noasyncnet] [-r] [-t transcom] ", 67 # else 68 "[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t[-t transcom]", 69 # endif 70 #else 71 "[-r] ", 72 #endif 73 #ifdef ENCRYPTION 74 "[-x] [host-name [port]]" 75 #else /* ENCRYPTION */ 76 "[host-name [port]]" 77 #endif /* ENCRYPTION */ 78 ); 79 exit(1); 80 } 81 82 /* 83 * main. Parse arguments, invoke the protocol or command parser. 84 */ 85 86 87 main(argc, argv) 88 int argc; 89 char *argv[]; 90 { 91 extern char *optarg; 92 extern int optind; 93 int ch; 94 char *user, *strrchr(); 95 #ifdef FORWARD 96 extern int forward_flags; 97 #endif /* FORWARD */ 98 99 tninit(); /* Clear out things */ 100 #if defined(CRAY) && !defined(__STDC__) 101 _setlist_init(); /* Work around compiler bug */ 102 #endif 103 104 TerminalSaveState(); 105 106 if (prompt = strrchr(argv[0], '/')) 107 ++prompt; 108 else 109 prompt = argv[0]; 110 111 user = NULL; 112 113 rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE; 114 autologin = -1; 115 116 while ((ch = getopt(argc, argv, "8EKLS:X:acde:fFk:l:n:rt:x")) != EOF) { 117 switch(ch) { 118 case '8': 119 eight = 3; /* binary output and input */ 120 break; 121 case 'E': 122 rlogin = escape = _POSIX_VDISABLE; 123 break; 124 case 'K': 125 #ifdef AUTHENTICATION 126 autologin = 0; 127 #endif 128 break; 129 case 'L': 130 eight |= 2; /* binary output only */ 131 break; 132 case 'S': 133 { 134 #ifdef HAS_GETTOS 135 extern int tos; 136 137 if ((tos = parsetos(optarg, "tcp")) < 0) 138 fprintf(stderr, "%s%s%s%s\n", 139 prompt, ": Bad TOS argument '", 140 optarg, 141 "; will try to use default TOS"); 142 #else 143 fprintf(stderr, 144 "%s: Warning: -S ignored, no parsetos() support.\n", 145 prompt); 146 #endif 147 } 148 break; 149 case 'X': 150 #ifdef AUTHENTICATION 151 auth_disable_name(optarg); 152 #endif 153 break; 154 case 'a': 155 autologin = 1; 156 break; 157 case 'c': 158 skiprc = 1; 159 break; 160 case 'd': 161 debug = 1; 162 break; 163 case 'e': 164 set_escape_char(optarg); 165 break; 166 case 'f': 167 #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD) 168 if (forward_flags & OPTS_FORWARD_CREDS) { 169 fprintf(stderr, 170 "%s: Only one of -f and -F allowed.\n", 171 prompt); 172 usage(); 173 } 174 forward_flags |= OPTS_FORWARD_CREDS; 175 #else 176 fprintf(stderr, 177 "%s: Warning: -f ignored, no Kerberos V5 support.\n", 178 prompt); 179 #endif 180 break; 181 case 'F': 182 #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD) 183 if (forward_flags & OPTS_FORWARD_CREDS) { 184 fprintf(stderr, 185 "%s: Only one of -f and -F allowed.\n", 186 prompt); 187 usage(); 188 } 189 forward_flags |= OPTS_FORWARD_CREDS; 190 forward_flags |= OPTS_FORWARDABLE_CREDS; 191 #else 192 fprintf(stderr, 193 "%s: Warning: -F ignored, no Kerberos V5 support.\n", 194 prompt); 195 #endif 196 break; 197 case 'k': 198 #if defined(AUTHENTICATION) && defined(KRB4) 199 { 200 extern char *dest_realm, dst_realm_buf[], dst_realm_sz; 201 dest_realm = dst_realm_buf; 202 (void)strncpy(dest_realm, optarg, dst_realm_sz); 203 } 204 #else 205 fprintf(stderr, 206 "%s: Warning: -k ignored, no Kerberos V4 support.\n", 207 prompt); 208 #endif 209 break; 210 case 'l': 211 autologin = 1; 212 user = optarg; 213 break; 214 case 'n': 215 #if defined(TN3270) && defined(unix) 216 /* distinguish between "-n oasynch" and "-noasynch" */ 217 if (argv[optind - 1][0] == '-' && argv[optind - 1][1] 218 == 'n' && argv[optind - 1][2] == 'o') { 219 if (!strcmp(optarg, "oasynch")) { 220 noasynchtty = 1; 221 noasynchnet = 1; 222 } else if (!strcmp(optarg, "oasynchtty")) 223 noasynchtty = 1; 224 else if (!strcmp(optarg, "oasynchnet")) 225 noasynchnet = 1; 226 } else 227 #endif /* defined(TN3270) && defined(unix) */ 228 SetNetTrace(optarg); 229 break; 230 case 'r': 231 rlogin = '~'; 232 break; 233 case 't': 234 #if defined(TN3270) && defined(unix) 235 transcom = tline; 236 (void)strcpy(transcom, optarg); 237 #else 238 fprintf(stderr, 239 "%s: Warning: -t ignored, no TN3270 support.\n", 240 prompt); 241 #endif 242 break; 243 case 'x': 244 #ifdef ENCRYPTION 245 encrypt_auto(1); 246 decrypt_auto(1); 247 #else /* ENCRYPTION */ 248 fprintf(stderr, 249 "%s: Warning: -x ignored, no ENCRYPT support.\n", 250 prompt); 251 #endif /* ENCRYPTION */ 252 break; 253 case '?': 254 default: 255 usage(); 256 /* NOTREACHED */ 257 } 258 } 259 if (autologin == -1) 260 autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1; 261 262 argc -= optind; 263 argv += optind; 264 265 if (argc) { 266 char *args[7], **argp = args; 267 268 if (argc > 2) 269 usage(); 270 *argp++ = prompt; 271 if (user) { 272 *argp++ = "-l"; 273 *argp++ = user; 274 } 275 *argp++ = argv[0]; /* host */ 276 if (argc > 1) 277 *argp++ = argv[1]; /* port */ 278 *argp = 0; 279 280 if (setjmp(toplevel) != 0) 281 Exit(0); 282 if (tn(argp - args, args) == 1) 283 return (0); 284 else 285 return (1); 286 } 287 (void)setjmp(toplevel); 288 for (;;) { 289 #ifdef TN3270 290 if (shell_active) 291 shell_continue(); 292 else 293 #endif 294 command(1, 0, 0); 295 } 296 } 297