main.c revision 1.8 1 /* $NetBSD: main.c,v 1.8 1998/02/28 12:16:56 enami 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.8 1998/02/28 12:16:56 enami Exp $");
47 #endif
48 #endif /* not lint */
49
50 #include <sys/types.h>
51
52 #include <unistd.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. */
60 #define OPTS_FORWARD_CREDS 0x00000002
61 #define OPTS_FORWARDABLE_CREDS 0x00000001
62
63 #if 0
64 #define FORWARD
65 #endif
66
67 int main P((int, char *[]));
68
69 /*
70 * Initialize variables.
71 */
72 void
73 tninit()
74 {
75 init_terminal();
76
77 init_network();
78
79 init_telnet();
80
81 init_sys();
82
83 #if defined(TN3270)
84 init_3270();
85 #endif
86 }
87
88 void
89 usage()
90 {
91 fprintf(stderr, "Usage: %s %s%s%s%s\n",
92 prompt,
93 #ifdef AUTHENTICATION
94 "[-8] [-E] [-K] [-L] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
95 "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] ",
96 #else
97 "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
98 "\n\t[-n tracefile]",
99 #endif
100 #if defined(TN3270) && defined(unix)
101 # ifdef AUTHENTICATION
102 "[-noasynch] [-noasynctty]\n\t[-noasyncnet] [-r] [-t transcom] ",
103 # else
104 "[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t[-t transcom]",
105 # endif
106 #else
107 "[-r] ",
108 #endif
109 "[host-name [port]]"
110 );
111 exit(1);
112 }
113
114 /*
115 * main. Parse arguments, invoke the protocol or command parser.
116 */
117
118
119 int
120 main(argc, argv)
121 int argc;
122 char *argv[];
123 {
124 extern char *optarg;
125 extern int optind;
126 int ch;
127 char *user;
128 #ifdef FORWARD
129 extern int forward_flags;
130 #endif /* FORWARD */
131
132 tninit(); /* Clear out things */
133 #if defined(CRAY) && !defined(__STDC__)
134 _setlist_init(); /* Work around compiler bug */
135 #endif
136
137 TerminalSaveState();
138
139 if ((prompt = strrchr(argv[0], '/')) != NULL)
140 ++prompt;
141 else
142 prompt = argv[0];
143
144 user = NULL;
145
146 rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
147 autologin = -1;
148
149 while ((ch = getopt(argc, argv, "8EKLS:X:acde:fFk:l:n:rt:x")) != -1) {
150 switch(ch) {
151 case '8':
152 eight = 3; /* binary output and input */
153 break;
154 case 'E':
155 rlogin = escape = _POSIX_VDISABLE;
156 break;
157 case 'K':
158 #ifdef AUTHENTICATION
159 autologin = 0;
160 #endif
161 break;
162 case 'L':
163 eight |= 2; /* binary output only */
164 break;
165 case 'S':
166 {
167 #ifdef HAS_GETTOS
168 extern int tos;
169
170 if ((tos = parsetos(optarg, "tcp")) < 0)
171 fprintf(stderr, "%s%s%s%s\n",
172 prompt, ": Bad TOS argument '",
173 optarg,
174 "; will try to use default TOS");
175 #else
176 fprintf(stderr,
177 "%s: Warning: -S ignored, no parsetos() support.\n",
178 prompt);
179 #endif
180 }
181 break;
182 case 'X':
183 #ifdef AUTHENTICATION
184 auth_disable_name(optarg);
185 #endif
186 break;
187 case 'a':
188 autologin = 1;
189 break;
190 case 'c':
191 skiprc = 1;
192 break;
193 case 'd':
194 debug = 1;
195 break;
196 case 'e':
197 set_escape_char(optarg);
198 break;
199 case 'f':
200 #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
201 if (forward_flags & OPTS_FORWARD_CREDS) {
202 fprintf(stderr,
203 "%s: Only one of -f and -F allowed.\n",
204 prompt);
205 usage();
206 }
207 forward_flags |= OPTS_FORWARD_CREDS;
208 #else
209 fprintf(stderr,
210 "%s: Warning: -f ignored, no Kerberos V5 support.\n",
211 prompt);
212 #endif
213 break;
214 case 'F':
215 #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
216 if (forward_flags & OPTS_FORWARD_CREDS) {
217 fprintf(stderr,
218 "%s: Only one of -f and -F allowed.\n",
219 prompt);
220 usage();
221 }
222 forward_flags |= OPTS_FORWARD_CREDS;
223 forward_flags |= OPTS_FORWARDABLE_CREDS;
224 #else
225 fprintf(stderr,
226 "%s: Warning: -F ignored, no Kerberos V5 support.\n",
227 prompt);
228 #endif
229 break;
230 case 'k':
231 #if defined(AUTHENTICATION) && defined(KRB4)
232 {
233 extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
234 dest_realm = dst_realm_buf;
235 (void)strncpy(dest_realm, optarg, dst_realm_sz);
236 }
237 #else
238 fprintf(stderr,
239 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
240 prompt);
241 #endif
242 break;
243 case 'l':
244 autologin = 1;
245 user = optarg;
246 break;
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 #ifdef __GNUC__
296 (void) &argp; /* avoid longjmp clobbering */
297 #endif
298
299 if (argc > 2)
300 usage();
301 *argp++ = prompt;
302 if (user) {
303 *argp++ = "-l";
304 *argp++ = user;
305 }
306 *argp++ = argv[0]; /* host */
307 if (argc > 1)
308 *argp++ = argv[1]; /* port */
309 *argp = 0;
310
311 if (setjmp(toplevel) != 0)
312 Exit(0);
313 if (tn(argp - args, args) == 1)
314 return (0);
315 else
316 return (1);
317 }
318 (void)setjmp(toplevel);
319 for (;;) {
320 #ifdef TN3270
321 if (shell_active)
322 shell_continue();
323 else
324 #endif
325 command(1, 0, 0);
326 }
327 }
328