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