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