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";
36 #include <sys/param.h>
37 #include <sys/socket.h>
47 #include <libtelnet/auth.h>
50 #include <libtelnet/encrypt.h>
53 /* These values need to be the same as defined in libtelnet/kerberos5.c */
54 /* Either define them in both places, or put in some common header file. */
55 #define OPTS_FORWARD_CREDS 0x00000002
56 #define OPTS_FORWARDABLE_CREDS 0x00000001
58 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
59 char *ipsec_policy_in = NULL;
60 char *ipsec_policy_out = NULL;
64 extern int quiet_mode;
66 int family = AF_UNSPEC;
69 * Initialize variables.
86 fprintf(stderr, "usage: %s %s%s%s%s\n",
89 "[-4] [-6] [-8] [-B baudrate] [-E] [-K] [-L] [-N] [-S tos] [-X atype]",
90 "\n\t[-c] [-d] [-e char] [-k realm] [-l user] [-f/-F] [-n tracefile] ",
92 "[-4] [-6] [-8] [-B baudrate] [-E] [-L] [-N] [-S tos] [-c] [-d]",
93 "\n\t[-e char] [-l user] [-n tracefile] ",
95 "[-r] [-s src_addr] [-u] ",
96 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
100 "[-y] [host-name [port]]"
101 #else /* ENCRYPTION */
103 #endif /* ENCRYPTION */
109 * main. Parse arguments, invoke the protocol or command parser.
113 main(int argc, char *argv[])
118 char *src_addr = NULL;
120 extern int forward_flags;
123 setbuf(stdout, NULL);
124 setbuf(stderr, NULL);
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 "468B:EKLNQS:X:acde:fFk:l:n:rs:uxy" IPSECOPT)) != -1)
167 eight = 3; /* binary output and input */
173 rlogin = escape = _POSIX_VDISABLE;
176 #ifdef AUTHENTICATION
181 eight |= 2; /* binary output only */
192 if ((tos = parsetos(optarg, "tcp")) < 0)
193 fprintf(stderr, "%s%s%s%s\n",
194 prompt, ": Bad TOS argument '",
196 "; will try to use default TOS");
199 ultmp = strtoul(optarg, &ep, 0);
200 if (*ep || ep == optarg || ultmp > MAXTOS)
201 fprintf(stderr, "%s%s%s%s\n",
202 prompt, ": Bad TOS argument '",
204 "; will try to use default TOS");
210 #ifdef AUTHENTICATION
211 auth_disable_name(optarg);
215 #ifdef AUTHENTICATION
216 /* It's the default now, so ignore */
228 set_escape_char(optarg);
231 #ifdef AUTHENTICATION
232 #if defined(KRB5) && defined(FORWARD)
233 if (forward_flags & OPTS_FORWARD_CREDS) {
235 "%s: Only one of -f and -F allowed.\n",
239 forward_flags |= OPTS_FORWARD_CREDS;
242 "%s: Warning: -f ignored, no Kerberos V5 support.\n",
247 "%s: Warning: -f ignored, no Kerberos V5 support.\n",
252 #ifdef AUTHENTICATION
253 #if defined(KRB5) && defined(FORWARD)
254 if (forward_flags & OPTS_FORWARD_CREDS) {
256 "%s: Only one of -f and -F allowed.\n",
260 forward_flags |= OPTS_FORWARD_CREDS;
261 forward_flags |= OPTS_FORWARDABLE_CREDS;
264 "%s: Warning: -F ignored, no Kerberos V5 support.\n",
269 "%s: Warning: -F ignored, no Kerberos V5 support.\n",
274 #ifdef AUTHENTICATION
277 extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
278 dest_realm = dst_realm_buf;
279 (void)strncpy(dest_realm, optarg, dst_realm_sz);
283 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
288 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
293 #ifdef AUTHENTICATION
294 /* This is the default now, so ignore it */
315 "%s: Warning: -x ignored, no ENCRYPT support.\n",
317 #endif /* ENCRYPTION */
325 "%s: Warning: -y ignored, no ENCRYPT support.\n",
327 #endif /* ENCRYPTION */
329 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
331 if (!strncmp("in", optarg, 2))
332 ipsec_policy_in = strdup(optarg);
333 else if (!strncmp("out", optarg, 3))
334 ipsec_policy_out = strdup(optarg);
346 autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
352 char *args[9], **argp = args;
358 *argp++ = strdup("-l");
362 *argp++ = strdup("-s");
365 *argp++ = argv[0]; /* host */
367 *argp++ = argv[1]; /* port */
370 if (setjmp(toplevel) != 0)
372 if (tn(argp - args, args) == 1)
377 (void)setjmp(toplevel);