1 /* $NetBSD: main.c,v 1.26 2006/12/18 14:18:40 christos Exp $ */
4 * Copyright (c) 1988, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1988, 1990, 1993\
35 The Regents of the University of California. All rights reserved.");
40 static char sccsid
[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
42 __RCSID("$NetBSD: main.c,v 1.26 2006/12/18 14:18:40 christos Exp $");
46 #include <sys/types.h>
47 #include <sys/socket.h>
55 #include <libtelnet/auth.h>
58 #include <libtelnet/encrypt.h>
61 /* These values need to be the same as defined in libtelnet/kerberos5.c */
62 /* Either define them in both places, or put in some common header file. */
63 #define OPTS_FORWARD_CREDS 0x00000002
64 #define OPTS_FORWARDABLE_CREDS 0x00000001
66 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
67 char *ipsec_policy_in
= NULL
;
68 char *ipsec_policy_out
= NULL
;
71 int family
= AF_UNSPEC
;
73 int main(int, char *[]);
76 * Initialize variables.
97 fprintf(stderr
, "usage: %s %s%s%s%s\n",
100 "[-4] [-6] [-8] [-E] [-K] [-L] [-N] [-S tos] [-X atype] [-a] [-c]",
101 "\n\t[-d] [-e char] [-k realm] [-l user] [-f/-F] [-n tracefile] ",
103 "[-4] [-6] [-8] [-E] [-L] [-N] [-S tos] [-a] [-c] [-d] [-e char]",
104 "\n\t[-l user] [-n tracefile] ",
107 # ifdef AUTHENTICATION
108 "[-noasynch] [-noasynctty]\n\t[-noasyncnet] [-r] [-t transcom] ",
110 "[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t[-t transcom]",
118 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
119 "\n\t[-P policy] [host-name [port]]"
121 "\n\t[host-name [port]]"
128 * main. Parse arguments, invoke the protocol or command parser.
133 main(int argc
, char *argv
[])
140 extern int forward_flags
;
143 tninit(); /* Clear out things */
147 if ((prompt
= strrchr(argv
[0], '/')) != NULL
)
154 rlogin
= (strncmp(prompt
, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE
;
157 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
158 #define IPSECOPT "P:"
162 while ((ch
= getopt(argc
, argv
, "468EKLNS:X:acde:fFk:l:n:rt:x"
173 eight
= 3; /* binary output and input */
176 rlogin
= escape
= _POSIX_VDISABLE
;
179 #ifdef AUTHENTICATION
184 eight
|= 2; /* binary output only */
192 "%s: Warning: -S ignored, no parsetos() support.\n",
197 #ifdef AUTHENTICATION
198 auth_disable_name(optarg
);
211 set_escape_char(optarg
);
214 #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
215 if (forward_flags
& OPTS_FORWARD_CREDS
) {
217 "%s: Only one of -f and -F allowed.\n",
221 forward_flags
|= OPTS_FORWARD_CREDS
;
224 "%s: Warning: -f ignored, no Kerberos V5 support.\n",
229 #if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
230 if (forward_flags
& OPTS_FORWARD_CREDS
) {
232 "%s: Only one of -f and -F allowed.\n",
236 forward_flags
|= OPTS_FORWARD_CREDS
;
237 forward_flags
|= OPTS_FORWARDABLE_CREDS
;
240 "%s: Warning: -F ignored, no Kerberos V5 support.\n",
246 "%s: Warning: -k ignored, no Kerberos V4 support.\n",
257 /* distinguish between "-n oasynch" and "-noasynch" */
258 if (argv
[optind
- 1][0] == '-' && argv
[optind
- 1][1]
259 == 'n' && argv
[optind
- 1][2] == 'o') {
260 if (!strcmp(optarg
, "oasynch")) {
263 } else if (!strcmp(optarg
, "oasynchtty"))
265 else if (!strcmp(optarg
, "oasynchnet"))
268 #endif /* defined(TN3270) */
276 (void)strlcpy(tline
, optarg
, sizeof(tline
));
280 "%s: Warning: -t ignored, no TN3270 support.\n",
288 #else /* ENCRYPTION */
290 "%s: Warning: -x ignored, no ENCRYPT support.\n",
292 #endif /* ENCRYPTION */
294 #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
296 if (!strncmp("in", optarg
, 2))
297 ipsec_policy_in
= strdup(optarg
);
298 else if (!strncmp("out", optarg
, 3))
299 ipsec_policy_out
= strdup(optarg
);
311 if (autologin
== -1) { /* esc@magic.fi; force */
312 #if defined(AUTHENTICATION)
315 #if defined(ENCRYPTION)
322 autologin
= (rlogin
== _POSIX_VDISABLE
) ? 0 : 1;
329 char ** volatile argp
; /* avoid longjmp clobbering */
339 *argp
++ = argv
[0]; /* host */
341 *argp
++ = argv
[1]; /* port */
344 if (setjmp(toplevel
) != 0)
346 if (tn(argp
- args
, args
) == 1)
351 (void)setjmp(toplevel
);