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