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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.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
60 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
61 char *ipsec_policy_in = NULL;
62 char *ipsec_policy_out = NULL;
66 extern int quiet_mode;
68 int family = AF_UNSPEC;
71 * Initialize variables.
88 fprintf(stderr, "usage: %s %s%s%s%s\n",
91 "[-4] [-6] [-8] [-B baudrate] [-E] [-K] [-L] [-N] [-S tos] [-X atype]",
92 "\n\t[-c] [-d] [-e char] [-k realm] [-l user] [-f/-F] [-n tracefile] ",
94 "[-4] [-6] [-8] [-B baudrate] [-E] [-L] [-N] [-S tos] [-c] [-d]",
95 "\n\t[-e char] [-l user] [-n tracefile] ",
97 "[-r] [-s src_addr] [-u] ",
98 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
102 "[-y] [host-name [port]]"
103 #else /* ENCRYPTION */
105 #endif /* ENCRYPTION */
111 * main. Parse arguments, invoke the protocol or command parser.
115 main(int argc, char *argv[])
120 char *src_addr = NULL;
122 extern int forward_flags;
125 setbuf(stdout, NULL);
126 setbuf(stderr, NULL);
127 tninit(); /* Clear out things */
131 if ((prompt = strrchr(argv[0], '/')))
138 rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
139 #ifdef AUTHENTICATION
150 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
151 #define IPSECOPT "P:"
155 while ((ch = getopt(argc, argv,
156 "468B:EKLNQS:X:acde:fFk:l:n:rs:uxy" IPSECOPT)) != -1)
169 eight = 3; /* binary output and input */
175 rlogin = escape = _POSIX_VDISABLE;
178 #ifdef AUTHENTICATION
183 eight |= 2; /* binary output only */
194 if ((tos = parsetos(optarg, "tcp")) < 0)
195 fprintf(stderr, "%s%s%s%s\n",
196 prompt, ": Bad TOS argument '",
198 "; will try to use default TOS");
201 ultmp = strtoul(optarg, &ep, 0);
202 if (*ep || ep == optarg || ultmp > MAXTOS)
203 fprintf(stderr, "%s%s%s%s\n",
204 prompt, ": Bad TOS argument '",
206 "; will try to use default TOS");
212 #ifdef AUTHENTICATION
213 auth_disable_name(optarg);
217 #ifdef AUTHENTICATION
218 /* It's the default now, so ignore */
230 set_escape_char(optarg);
233 #ifdef AUTHENTICATION
234 #if defined(KRB5) && defined(FORWARD)
235 if (forward_flags & OPTS_FORWARD_CREDS) {
237 "%s: Only one of -f and -F allowed.\n",
241 forward_flags |= OPTS_FORWARD_CREDS;
244 "%s: Warning: -f ignored, no Kerberos V5 support.\n",
249 "%s: Warning: -f ignored, no Kerberos V5 support.\n",
254 #ifdef AUTHENTICATION
255 #if defined(KRB5) && defined(FORWARD)
256 if (forward_flags & OPTS_FORWARD_CREDS) {
258 "%s: Only one of -f and -F allowed.\n",
262 forward_flags |= OPTS_FORWARD_CREDS;
263 forward_flags |= OPTS_FORWARDABLE_CREDS;
266 "%s: Warning: -F ignored, no Kerberos V5 support.\n",
271 "%s: Warning: -F ignored, no Kerberos V5 support.\n",
276 #ifdef AUTHENTICATION
279 extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
280 dest_realm = dst_realm_buf;
281 (void)strncpy(dest_realm, optarg, dst_realm_sz);
285 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
290 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
295 #ifdef AUTHENTICATION
296 /* This is the default now, so ignore it */
317 "%s: Warning: -x ignored, no ENCRYPT support.\n",
319 #endif /* ENCRYPTION */
327 "%s: Warning: -y ignored, no ENCRYPT support.\n",
329 #endif /* ENCRYPTION */
331 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
333 if (!strncmp("in", optarg, 2))
334 ipsec_policy_in = strdup(optarg);
335 else if (!strncmp("out", optarg, 3))
336 ipsec_policy_out = strdup(optarg);
348 autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
354 char *args[9], **argp = args;
360 *argp++ = strdup("-l");
364 *argp++ = strdup("-s");
367 *argp++ = argv[0]; /* host */
369 *argp++ = argv[1]; /* port */
372 if (setjmp(toplevel) != 0)
374 if (tn(argp - args, args) == 1)
379 (void)setjmp(toplevel);