2 * Copyright (c) 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 static char *copyright[] = {
35 "@(#) Copyright (c) 1988, 1990, 1993\n"
36 "\tThe Regents of the University of California. All rights reserved.\n",
40 #include "telnet_locl.h"
41 RCSID("$Id: main.c,v 1.38.6.1 2004/03/22 18:16:35 lha Exp $");
48 * Initialize variables.
65 fprintf(stderr, "Usage: %s %s%s%s%s\n", prompt,
67 "[-8] [-E] [-K] [-L] [-G] [-S tos] [-X atype] [-a] [-c] [-d] [-e char]",
68 "\n\t[-k realm] [-l user] [-f/-F] [-n tracefile] ",
70 "[-8] [-E] [-L] [-S tos] [-a] [-c] [-d] [-e char] [-l user]",
75 "[-x] [host-name [port]]"
84 * main. Parse arguments, invoke the protocol or command parser.
89 int forward_option = 0; /* forward flags set from command line */
92 set_forward_options(void)
95 switch(forward_option) {
97 kerberos5_set_forward(1);
98 kerberos5_set_forwardable(0);
101 kerberos5_set_forward(1);
102 kerberos5_set_forwardable(1);
105 kerberos5_set_forward(0);
106 kerberos5_set_forwardable(0);
115 /* XXX ugly hack to setup dns-proxy stuff */
116 #define Authenticator asn1_Authenticator
121 krb5_context context;
124 ret = krb5_init_context(&context);
128 #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
129 if (krb5_config_get_bool (context, NULL,
130 "libdefaults", "forward", NULL)) {
131 kerberos5_set_forward(1);
133 if (krb5_config_get_bool (context, NULL,
134 "libdefaults", "forwardable", NULL)) {
135 kerberos5_set_forwardable(1);
139 if (krb5_config_get_bool (context, NULL,
140 "libdefaults", "encrypt", NULL)) {
148 krb5_free_context(context);
152 #if defined(AUTHENTICATION) && defined(KRB4)
153 extern char *dest_realm, dst_realm_buf[];
154 extern int dst_realm_sz;
158 main(int argc, char **argv)
163 setprogname(argv[0]);
169 tninit(); /* Clear out things */
173 if ((prompt = strrchr(argv[0], '/')))
180 rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
183 * if AUTHENTICATION and ENCRYPTION is set autologin will be
184 * se to true after the getopt switch; unless the -K option is
189 if (argc == 2 && strcmp(argv[1], "--version") == 0) {
194 while((ch = getopt(argc, argv,
195 "78DEKLS:X:abcde:fFk:l:n:rxG")) != -1) {
198 eight = 3; /* binary output and input */
207 /* sometimes we don't want a mangled display */
209 if((p = getenv("DISPLAY")))
210 env_define((unsigned char*)"DISPLAY", (unsigned char*)p);
214 rlogin = escape = _POSIX_VDISABLE;
217 #ifdef AUTHENTICATION
222 eight |= 2; /* binary output only */
229 if ((tos = parsetos(optarg, "tcp")) < 0)
230 fprintf(stderr, "%s%s%s%s\n",
231 prompt, ": Bad TOS argument '",
233 "; will try to use default TOS");
236 "%s: Warning: -S ignored, no parsetos() support.\n",
242 #ifdef AUTHENTICATION
243 auth_disable_name(optarg);
256 set_escape_char(optarg);
261 #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
262 if (forward_option) {
264 "%s: Only one of -f, -F and -G allowed.\n",
271 "%s: Warning: -%c ignored, no Kerberos V5 support.\n",
276 #if defined(AUTHENTICATION) && defined(KRB4)
278 dest_realm = dst_realm_buf;
279 strlcpy(dest_realm, optarg, dst_realm_sz);
283 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
289 fprintf(stderr, "%s: Warning: -K ignored\n", prompt);
308 "%s: Warning: -x ignored, no ENCRYPT support.\n",
320 if (autologin == -1) { /* esc@magic.fi; force */
321 #if defined(AUTHENTICATION)
324 #if defined(ENCRYPTION)
332 autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
338 char *args[7], **argp = args;
347 *argp++ = argv[0]; /* host */
349 *argp++ = argv[1]; /* port */
352 if (setjmp(toplevel) != 0)
354 if (tn(argp - args, args) == 1)