Home | History | Annotate | Line # | Download | only in telnet
main.c revision 1.1
      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[] = "@(#)main.c	5.4 (Berkeley) 3/22/91";
     42 #endif /* not lint */
     43 
     44 #include <sys/types.h>
     45 
     46 #include "ring.h"
     47 #include "externs.h"
     48 #include "defines.h"
     49 
     50 /*
     51  * Initialize variables.
     52  */
     53     void
     54 tninit()
     55 {
     56     init_terminal();
     57 
     58     init_network();
     59 
     60     init_telnet();
     61 
     62     init_sys();
     63 
     64 #if defined(TN3270)
     65     init_3270();
     66 #endif
     67 }
     68 
     69 	void
     70 usage()
     71 {
     72 	fprintf(stderr, "Usage: %s %s%s%s%s\n",
     73 	    prompt,
     74 #ifdef	AUTHENTICATE
     75 	    " [-8] [-E] [-K] [-L] [-X atype] [-a] [-d] [-e char] [-k realm]",
     76 	    "\n\t[-l user] [-n tracefile] ",
     77 #else
     78 	    " [-8] [-E] [-L] [-a] [-d] [-e char] [-l user] [-n tracefile]",
     79 	    "\n\t",
     80 #endif
     81 #if defined(TN3270) && defined(unix)
     82 # ifdef AUTHENTICATE
     83 	    "[-noasynch] [-noasynctty] [-noasyncnet]\n\t[-r] [-t transcom] ",
     84 # else
     85 	    "[-noasynch] [-noasynctty] [-noasyncnet] [-r] [-t transcom]\n\t",
     86 # endif
     87 #else
     88 	    "[-r] ",
     89 #endif
     90 #ifdef	ENCRYPT
     91 	    "[-x] [host-name [port]]"
     92 #else
     93 	    "[host-name [port]]"
     94 #endif
     95 	);
     96 	exit(1);
     97 }
     98 
     99 /*
    100  * main.  Parse arguments, invoke the protocol or command parser.
    101  */
    102 
    103 
    104 main(argc, argv)
    105 	int argc;
    106 	char *argv[];
    107 {
    108 	extern char *optarg;
    109 	extern int optind;
    110 	int ch;
    111 	char *user, *strrchr();
    112 
    113 	tninit();		/* Clear out things */
    114 #if	defined(CRAY) && !defined(__STDC__)
    115 	_setlist_init();	/* Work around compiler bug */
    116 #endif
    117 
    118 	TerminalSaveState();
    119 
    120 	if (prompt = strrchr(argv[0], '/'))
    121 		++prompt;
    122 	else
    123 		prompt = argv[0];
    124 
    125 	user = NULL;
    126 
    127 	rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
    128 	autologin = -1;
    129 
    130 	while ((ch = getopt(argc, argv, "8EKLS:X:ade:k:l:n:rt:x")) != EOF) {
    131 		switch(ch) {
    132 		case '8':
    133 			eight = 3;	/* binary output and input */
    134 			break;
    135 		case 'E':
    136 			rlogin = escape = _POSIX_VDISABLE;
    137 			break;
    138 		case 'K':
    139 #ifdef	AUTHENTICATE
    140 			autologin = 0;
    141 #endif
    142 			break;
    143 		case 'L':
    144 			eight |= 2;	/* binary output only */
    145 			break;
    146 		case 'S':
    147 		    {
    148 #ifdef	HAS_GETTOS
    149 			extern int tos;
    150 
    151 			if ((tos = parsetos(optarg, "tcp")) < 0)
    152 				fprintf(stderr, "%s%s%s%s\n",
    153 					prompt, ": Bad TOS argument '",
    154 					optarg,
    155 					"; will try to use default TOS");
    156 #else
    157 			fprintf(stderr,
    158 			   "%s: Warning: -S ignored, no parsetos() support.\n",
    159 								prompt);
    160 #endif
    161 		    }
    162 			break;
    163 		case 'X':
    164 #ifdef	AUTHENTICATE
    165 			auth_disable_name(optarg);
    166 #endif
    167 			break;
    168 		case 'a':
    169 			autologin = 1;
    170 			break;
    171 		case 'c':
    172 			skiprc = 1;
    173 			break;
    174 		case 'd':
    175 			debug = 1;
    176 			break;
    177 		case 'e':
    178 			set_escape_char(optarg);
    179 			break;
    180 		case 'k':
    181 #if defined(AUTHENTICATE) && defined(KRB4)
    182 		    {
    183 			extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
    184 			dest_realm = dst_realm_buf;
    185 			(void)strncpy(dest_realm, optarg, dst_realm_sz);
    186 		    }
    187 #else
    188 			fprintf(stderr,
    189 			   "%s: Warning: -k ignored, no Kerberos V4 support.\n",
    190 								prompt);
    191 #endif
    192 			break;
    193 		case 'l':
    194 			autologin = 1;
    195 			user = optarg;
    196 			break;
    197 		case 'n':
    198 #if defined(TN3270) && defined(unix)
    199 			/* distinguish between "-n oasynch" and "-noasynch" */
    200 			if (argv[optind - 1][0] == '-' && argv[optind - 1][1]
    201 			    == 'n' && argv[optind - 1][2] == 'o') {
    202 				if (!strcmp(optarg, "oasynch")) {
    203 					noasynchtty = 1;
    204 					noasynchnet = 1;
    205 				} else if (!strcmp(optarg, "oasynchtty"))
    206 					noasynchtty = 1;
    207 				else if (!strcmp(optarg, "oasynchnet"))
    208 					noasynchnet = 1;
    209 			} else
    210 #endif	/* defined(TN3270) && defined(unix) */
    211 				SetNetTrace(optarg);
    212 			break;
    213 		case 'r':
    214 			rlogin = '~';
    215 			break;
    216 		case 't':
    217 #if defined(TN3270) && defined(unix)
    218 			transcom = tline;
    219 			(void)strcpy(transcom, optarg);
    220 #else
    221 			fprintf(stderr,
    222 			   "%s: Warning: -t ignored, no TN3270 support.\n",
    223 								prompt);
    224 #endif
    225 			break;
    226 		case 'x':
    227 #ifdef	ENCRYPT
    228 			encrypt_auto(1);
    229 			decrypt_auto(1);
    230 #else
    231 			fprintf(stderr,
    232 			    "%s: Warning: -x ignored, no ENCRYPT support.\n",
    233 								prompt);
    234 #endif
    235 			break;
    236 		case '?':
    237 		default:
    238 			usage();
    239 			/* NOTREACHED */
    240 		}
    241 	}
    242 	if (autologin == -1)
    243 		autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
    244 
    245 	argc -= optind;
    246 	argv += optind;
    247 
    248 	if (argc) {
    249 		char *args[7], **argp = args;
    250 
    251 		if (argc > 2)
    252 			usage();
    253 		*argp++ = prompt;
    254 		if (user) {
    255 			*argp++ = "-l";
    256 			*argp++ = user;
    257 		}
    258 		*argp++ = argv[0];		/* host */
    259 		if (argc > 1)
    260 			*argp++ = argv[1];	/* port */
    261 		*argp = 0;
    262 
    263 		if (setjmp(toplevel) != 0)
    264 			Exit(0);
    265 		if (tn(argp - args, args) == 1)
    266 			return (0);
    267 		else
    268 			return (1);
    269 	}
    270 	(void)setjmp(toplevel);
    271 	for (;;) {
    272 #ifdef TN3270
    273 		if (shell_active)
    274 			shell_continue();
    275 		else
    276 #endif
    277 			command(1, 0, 0);
    278 	}
    279 }
    280