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
33 * @(#)main.c 8.3 (Berkeley) 5/30/95
34 * $FreeBSD: src/crypto/telnet/telnet/main.c,v 1.4.2.5 2002/04/13 10:59:08 markm Exp $
35 * $DragonFly: src/crypto/telnet/telnet/main.c,v 1.2 2003/06/17 04:24:37 dillon Exp $
38 #include <sys/types.h>
39 #include <sys/socket.h>
49 #include <libtelnet/auth.h>
52 #include <libtelnet/encrypt.h>
55 /* These values need to be the same as defined in libtelnet/kerberos5.c */
56 /* Either define them in both places, or put in some common header file. */
57 #define OPTS_FORWARD_CREDS 0x00000002
58 #define OPTS_FORWARDABLE_CREDS 0x00000001
64 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
65 char *ipsec_policy_in
= NULL
;
66 char *ipsec_policy_out
= NULL
;
69 int family
= AF_UNSPEC
;
72 * Initialize variables.
89 fprintf(stderr
, "Usage: %s %s%s%s%s\n",
92 "[-4] [-6] [-8] [-E] [-K] [-L] [-N] [-S tos] [-X atype] [-c] [-d]",
93 "\n\t[-e char] [-k realm] [-l user] [-f/-F] [-n tracefile] ",
95 "[-4] [-6] [-8] [-E] [-L] [-N] [-S tos] [-c] [-d]",
96 "\n\t[-e char] [-l user] [-n tracefile] ",
98 "[-r] [-s src_addr] [-u] ",
99 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
103 "[-y] [host-name [port]]"
104 #else /* ENCRYPTION */
106 #endif /* ENCRYPTION */
112 * main. Parse arguments, invoke the protocol or command parser.
116 main(int argc
, char *argv
[])
120 char *src_addr
= NULL
;
122 extern int forward_flags
;
125 tninit(); /* Clear out things */
129 if ((prompt
= strrchr(argv
[0], '/')))
136 rlogin
= (strncmp(prompt
, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE
;
137 #ifdef AUTHENTICATION
148 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
149 #define IPSECOPT "P:"
153 while ((ch
= getopt(argc
, argv
,
154 "468EKLNS:X:acde:fFk:l:n:rs:t:uxy" IPSECOPT
)) != -1)
167 eight
= 3; /* binary output and input */
170 rlogin
= escape
= _POSIX_VDISABLE
;
173 #ifdef AUTHENTICATION
174 /* It's the default now, so ignore */
178 eight
|= 2; /* binary output only */
188 if ((tos
= parsetos(optarg
, "tcp")) < 0)
189 fprintf(stderr
, "%s%s%s%s\n",
190 prompt
, ": Bad TOS argument '",
192 "; will try to use default TOS");
195 "%s: Warning: -S ignored, no parsetos() support.\n",
201 #ifdef AUTHENTICATION
202 auth_disable_name(optarg
);
215 set_escape_char(optarg
);
218 #ifdef AUTHENTICATION
219 #if defined(KRB5) && defined(FORWARD)
220 if (forward_flags
& OPTS_FORWARD_CREDS
) {
222 "%s: Only one of -f and -F allowed.\n",
226 forward_flags
|= OPTS_FORWARD_CREDS
;
229 "%s: Warning: -f ignored, no Kerberos V5 support.\n",
234 "%s: Warning: -f ignored, no Kerberos V5 support.\n",
239 #ifdef AUTHENTICATION
240 #if defined(KRB5) && defined(FORWARD)
241 if (forward_flags
& OPTS_FORWARD_CREDS
) {
243 "%s: Only one of -f and -F allowed.\n",
247 forward_flags
|= OPTS_FORWARD_CREDS
;
248 forward_flags
|= OPTS_FORWARDABLE_CREDS
;
251 "%s: Warning: -F ignored, no Kerberos V5 support.\n",
256 "%s: Warning: -F ignored, no Kerberos V5 support.\n",
261 #ifdef AUTHENTICATION
264 extern char *dest_realm
, dst_realm_buf
[], dst_realm_sz
;
265 dest_realm
= dst_realm_buf
;
266 (void)strncpy(dest_realm
, optarg
, dst_realm_sz
);
270 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
275 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
280 #ifdef AUTHENTICATION
281 /* This is the default now, so ignore it */
302 "%s: Warning: -x ignored, no ENCRYPT support.\n",
304 #endif /* ENCRYPTION */
312 "%s: Warning: -y ignored, no ENCRYPT support.\n",
314 #endif /* ENCRYPTION */
316 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
318 if (!strncmp("in", optarg
, 2))
319 ipsec_policy_in
= strdup(optarg
);
320 else if (!strncmp("out", optarg
, 3))
321 ipsec_policy_out
= strdup(optarg
);
333 autologin
= (rlogin
== _POSIX_VDISABLE
) ? 0 : 1;
339 char *args
[9], **argp
= args
;
345 *argp
++ = strdup("-l");
349 *argp
++ = strdup("-s");
352 *argp
++ = argv
[0]; /* host */
354 *argp
++ = argv
[1]; /* port */
357 if (setjmp(toplevel
) != 0)
359 if (tn(argp
- args
, args
) == 1)
364 (void)setjmp(toplevel
);