2 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * Copyright (c) 1988, 1990 Regents of the University of California.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 "@(#) Copyright (c) 1988, 1990 Regents of the University of California.\n"
43 " All rights reserved.\n";
45 static char sccsid
[] = "@(#)main.c 5.5 (Berkeley) 12/18/92";
48 #include <sys/types.h>
54 /* These values need to be the same as defined in libtelnet/kerberos5.c */
55 /* Either define them in both places, or put in some common header file. */
56 #define OPTS_FORWARD_CREDS 0x00000002
57 #define OPTS_FORWARDABLE_CREDS 0x00000001
60 * This flag is incremented, if any of the
61 * Kerberos command line options are used.
63 int krb5auth_flag
= 0;
66 * Initialize variables.
75 if (init_telnet() == 0)
84 #define TELNET_OPTIONS "8EKLS:X:acde:fFk:l:n:rt:x"
86 #define TELNET_OPTIONS "8EKLX:acde:fFk:l:n:rt:x"
92 (void) fprintf(stderr
, "Usage: %s %s\n",
94 " [-8] [-E] [-K] [-L] [-a] [-c] [-d] [-f/-F] [-r] [-x]"
95 "\n\t[-e char] [-k realm] [-l user] [-n tracefile] [-X atype]"
96 "\n\t[host-name [port]]");
101 * main. Parse arguments, invoke the protocol or command parser.
106 main(int argc
, char *argv
[])
110 extern boolean_t auth_enable_encrypt
;
111 extern int forward_flags
;
113 /* Clear out things */
115 return (EXIT_FAILURE
);
117 if (!isatty(fileno(stdin
))) {
120 if (!isatty(fileno(stdout
))) {
121 setbuf(stdout
, NULL
);
126 if (prompt
= strrchr(argv
[0], '/'))
133 rlogin
= (strncmp(prompt
, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE
;
136 while ((ch
= getopt(argc
, argv
, TELNET_OPTIONS
)) != EOF
) {
144 auth_disable_name(optarg
);
153 if (forward_flags
& OPTS_FORWARD_CREDS
) {
154 (void) fprintf(stderr
, gettext(
155 "%s: Only one of -f "
156 "and -F allowed.\n"), prompt
);
159 forward_flags
|= OPTS_FORWARD_CREDS
;
160 forward_flag_set
= 1;
164 if (forward_flags
& OPTS_FORWARD_CREDS
) {
165 (void) fprintf(stderr
, gettext(
166 "%s: Only one of -f "
167 "and -F allowed.\n"), prompt
);
170 forward_flags
|= OPTS_FORWARD_CREDS
;
171 forward_flags
|= OPTS_FORWARDABLE_CREDS
;
172 forwardable_flag_set
= 1;
177 set_krb5_realm(optarg
);
181 if (krb5_privacy_allowed()) {
184 wantencryption
= B_TRUE
;
187 auth_enable_encrypt
= B_TRUE
;
188 encrypt_flag_set
= 1;
191 (void) fprintf(stderr
, gettext(
192 "%s: Encryption not supported.\n"),
198 /* begin common options */
200 eight
= 3; /* binary output and input */
203 escape_valid
= B_FALSE
;
204 rlogin
= escape
= _POSIX_VDISABLE
;
207 eight
|= 2; /* binary output only */
211 (void) fprintf(stderr
,
212 "%s: Warning: -S ignored, no parsetos() support.\n",
223 escape_valid
= B_TRUE
;
224 set_escape_char(optarg
);
238 (void) fprintf(stderr
,
239 "%s: Warning: -t ignored, no TN3270 support.\n",
248 autologin
= (rlogin
== _POSIX_VDISABLE
) ? 0 : 1;
254 char *args
[7], **argp
= args
;
263 *argp
++ = argv
[0]; /* host */
265 *argp
++ = argv
[1]; /* port */
268 if (setjmp(toplevel
) != 0)
270 if (tn(argp
- args
, args
) == 1)
271 return (EXIT_SUCCESS
);
273 return (EXIT_FAILURE
);
275 (void) setjmp(toplevel
);