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