Home | History | Annotate | Line # | Download | only in telnet
main.c revision 1.2
      1 /*
      2  * Copyright (c) 1988, 1990 Regents of the University of California.
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #ifndef lint
     35 char copyright[] =
     36 "@(#) Copyright (c) 1988, 1990 Regents of the University of California.\n\
     37  All rights reserved.\n";
     38 #endif /* not lint */
     39 
     40 #ifndef lint
     41 /*static char sccsid[] = "from: @(#)main.c	5.4 (Berkeley) 3/22/91";*/
     42 static char rcsid[] = "$Id: main.c,v 1.2 1993/08/01 18:07:24 mycroft Exp $";
     43 #endif /* not lint */
     44 
     45 #include <sys/types.h>
     46 
     47 #include "ring.h"
     48 #include "externs.h"
     49 #include "defines.h"
     50 
     51 /*
     52  * Initialize variables.
     53  */
     54     void
     55 tninit()
     56 {
     57     init_terminal();
     58 
     59     init_network();
     60 
     61     init_telnet();
     62 
     63     init_sys();
     64 
     65 #if defined(TN3270)
     66     init_3270();
     67 #endif
     68 }
     69 
     70 	void
     71 usage()
     72 {
     73 	fprintf(stderr, "Usage: %s %s%s%s%s\n",
     74 	    prompt,
     75 #ifdef	AUTHENTICATE
     76 	    " [-8] [-E] [-K] [-L] [-X atype] [-a] [-d] [-e char] [-k realm]",
     77 	    "\n\t[-l user] [-n tracefile] ",
     78 #else
     79 	    " [-8] [-E] [-L] [-a] [-d] [-e char] [-l user] [-n tracefile]",
     80 	    "\n\t",
     81 #endif
     82 #if defined(TN3270) && defined(unix)
     83 # ifdef AUTHENTICATE
     84 	    "[-noasynch] [-noasynctty] [-noasyncnet]\n\t[-r] [-t transcom] ",
     85 # else
     86 	    "[-noasynch] [-noasynctty] [-noasyncnet] [-r] [-t transcom]\n\t",
     87 # endif
     88 #else
     89 	    "[-r] ",
     90 #endif
     91 #ifdef	ENCRYPT
     92 	    "[-x] [host-name [port]]"
     93 #else
     94 	    "[host-name [port]]"
     95 #endif
     96 	);
     97 	exit(1);
     98 }
     99 
    100 /*
    101  * main.  Parse arguments, invoke the protocol or command parser.
    102  */
    103 
    104 
    105 main(argc, argv)
    106 	int argc;
    107 	char *argv[];
    108 {
    109 	extern char *optarg;
    110 	extern int optind;
    111 	int ch;
    112 	char *user, *strrchr();
    113 
    114 	tninit();		/* Clear out things */
    115 #if	defined(CRAY) && !defined(__STDC__)
    116 	_setlist_init();	/* Work around compiler bug */
    117 #endif
    118 
    119 	TerminalSaveState();
    120 
    121 	if (prompt = strrchr(argv[0], '/'))
    122 		++prompt;
    123 	else
    124 		prompt = argv[0];
    125 
    126 	user = NULL;
    127 
    128 	rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
    129 	autologin = -1;
    130 
    131 	while ((ch = getopt(argc, argv, "8EKLS:X:ade:k:l:n:rt:x")) != EOF) {
    132 		switch(ch) {
    133 		case '8':
    134 			eight = 3;	/* binary output and input */
    135 			break;
    136 		case 'E':
    137 			rlogin = escape = _POSIX_VDISABLE;
    138 			break;
    139 		case 'K':
    140 #ifdef	AUTHENTICATE
    141 			autologin = 0;
    142 #endif
    143 			break;
    144 		case 'L':
    145 			eight |= 2;	/* binary output only */
    146 			break;
    147 		case 'S':
    148 		    {
    149 #ifdef	HAS_GETTOS
    150 			extern int tos;
    151 
    152 			if ((tos = parsetos(optarg, "tcp")) < 0)
    153 				fprintf(stderr, "%s%s%s%s\n",
    154 					prompt, ": Bad TOS argument '",
    155 					optarg,
    156 					"; will try to use default TOS");
    157 #else
    158 			fprintf(stderr,
    159 			   "%s: Warning: -S ignored, no parsetos() support.\n",
    160 								prompt);
    161 #endif
    162 		    }
    163 			break;
    164 		case 'X':
    165 #ifdef	AUTHENTICATE
    166 			auth_disable_name(optarg);
    167 #endif
    168 			break;
    169 		case 'a':
    170 			autologin = 1;
    171 			break;
    172 		case 'c':
    173 			skiprc = 1;
    174 			break;
    175 		case 'd':
    176 			debug = 1;
    177 			break;
    178 		case 'e':
    179 			set_escape_char(optarg);
    180 			break;
    181 		case 'k':
    182 #if defined(AUTHENTICATE) && defined(KRB4)
    183 		    {
    184 			extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
    185 			dest_realm = dst_realm_buf;
    186 			(void)strncpy(dest_realm, optarg, dst_realm_sz);
    187 		    }
    188 #else
    189 			fprintf(stderr,
    190 			   "%s: Warning: -k ignored, no Kerberos V4 support.\n",
    191 								prompt);
    192 #endif
    193 			break;
    194 		case 'l':
    195 			autologin = 1;
    196 			user = optarg;
    197 			break;
    198 		case 'n':
    199 #if defined(TN3270) && defined(unix)
    200 			/* distinguish between "-n oasynch" and "-noasynch" */
    201 			if (argv[optind - 1][0] == '-' && argv[optind - 1][1]
    202 			    == 'n' && argv[optind - 1][2] == 'o') {
    203 				if (!strcmp(optarg, "oasynch")) {
    204 					noasynchtty = 1;
    205 					noasynchnet = 1;
    206 				} else if (!strcmp(optarg, "oasynchtty"))
    207 					noasynchtty = 1;
    208 				else if (!strcmp(optarg, "oasynchnet"))
    209 					noasynchnet = 1;
    210 			} else
    211 #endif	/* defined(TN3270) && defined(unix) */
    212 				SetNetTrace(optarg);
    213 			break;
    214 		case 'r':
    215 			rlogin = '~';
    216 			break;
    217 		case 't':
    218 #if defined(TN3270) && defined(unix)
    219 			transcom = tline;
    220 			(void)strcpy(transcom, optarg);
    221 #else
    222 			fprintf(stderr,
    223 			   "%s: Warning: -t ignored, no TN3270 support.\n",
    224 								prompt);
    225 #endif
    226 			break;
    227 		case 'x':
    228 #ifdef	ENCRYPT
    229 			encrypt_auto(1);
    230 			decrypt_auto(1);
    231 #else
    232 			fprintf(stderr,
    233 			    "%s: Warning: -x ignored, no ENCRYPT support.\n",
    234 								prompt);
    235 #endif
    236 			break;
    237 		case '?':
    238 		default:
    239 			usage();
    240 			/* NOTREACHED */
    241 		}
    242 	}
    243 	if (autologin == -1)
    244 		autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
    245 
    246 	argc -= optind;
    247 	argv += optind;
    248 
    249 	if (argc) {
    250 		char *args[7], **argp = args;
    251 
    252 		if (argc > 2)
    253 			usage();
    254 		*argp++ = prompt;
    255 		if (user) {
    256 			*argp++ = "-l";
    257 			*argp++ = user;
    258 		}
    259 		*argp++ = argv[0];		/* host */
    260 		if (argc > 1)
    261 			*argp++ = argv[1];	/* port */
    262 		*argp = 0;
    263 
    264 		if (setjmp(toplevel) != 0)
    265 			Exit(0);
    266 		if (tn(argp - args, args) == 1)
    267 			return (0);
    268 		else
    269 			return (1);
    270 	}
    271 	(void)setjmp(toplevel);
    272 	for (;;) {
    273 #ifdef TN3270
    274 		if (shell_active)
    275 			shell_continue();
    276 		else
    277 #endif
    278 			command(1, 0, 0);
    279 	}
    280 }
    281