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