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