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
43 "@(#) Copyright (c) 1988, 1990 Regents of the University of California.\n"
44 " All rights reserved.\n";
48 static char sccsid
[] = "@(#)main.c 5.5 (Berkeley) 12/18/92";
52 #include <sys/types.h>
58 /* These values need to be the same as defined in libtelnet/kerberos5.c */
59 /* Either define them in both places, or put in some common header file. */
60 #define OPTS_FORWARD_CREDS 0x00000002
61 #define OPTS_FORWARDABLE_CREDS 0x00000001
64 * This flag is incremented, if any of the
65 * Kerberos command line options are used.
67 int krb5auth_flag
= 0;
70 * Initialize variables.
79 if (init_telnet() == 0)
88 #define TELNET_OPTIONS "8EKLS:X:acde:fFk:l:n:rt:x"
90 #define TELNET_OPTIONS "8EKLX:acde:fFk:l:n:rt:x"
96 (void) fprintf(stderr
, "Usage: %s %s\n",
98 " [-8] [-E] [-K] [-L] [-a] [-c] [-d] [-f/-F] [-r] [-x]"
99 "\n\t[-e char] [-k realm] [-l user] [-n tracefile] [-X atype]"
100 "\n\t[host-name [port]]");
105 * main. Parse arguments, invoke the protocol or command parser.
110 main(int argc
, char *argv
[])
114 extern boolean_t auth_enable_encrypt
;
115 extern int forward_flags
;
117 /* Clear out things */
119 return (EXIT_FAILURE
);
121 if (!isatty(fileno(stdin
))) {
124 if (!isatty(fileno(stdout
))) {
125 setbuf(stdout
, NULL
);
130 if (prompt
= strrchr(argv
[0], '/'))
137 rlogin
= (strncmp(prompt
, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE
;
140 while ((ch
= getopt(argc
, argv
, TELNET_OPTIONS
)) != EOF
) {
148 auth_disable_name(optarg
);
157 if (forward_flags
& OPTS_FORWARD_CREDS
) {
158 (void) fprintf(stderr
, gettext(
159 "%s: Only one of -f "
160 "and -F allowed.\n"), prompt
);
163 forward_flags
|= OPTS_FORWARD_CREDS
;
164 forward_flag_set
= 1;
168 if (forward_flags
& OPTS_FORWARD_CREDS
) {
169 (void) fprintf(stderr
, gettext(
170 "%s: Only one of -f "
171 "and -F allowed.\n"), prompt
);
174 forward_flags
|= OPTS_FORWARD_CREDS
;
175 forward_flags
|= OPTS_FORWARDABLE_CREDS
;
176 forwardable_flag_set
= 1;
181 set_krb5_realm(optarg
);
185 if (krb5_privacy_allowed()) {
188 wantencryption
= B_TRUE
;
191 auth_enable_encrypt
= B_TRUE
;
192 encrypt_flag_set
= 1;
195 (void) fprintf(stderr
, gettext(
196 "%s: Encryption not supported.\n"),
202 /* begin common options */
204 eight
= 3; /* binary output and input */
207 escape_valid
= B_FALSE
;
208 rlogin
= escape
= _POSIX_VDISABLE
;
211 eight
|= 2; /* binary output only */
215 (void) fprintf(stderr
,
216 "%s: Warning: -S ignored, no parsetos() support.\n",
227 escape_valid
= B_TRUE
;
228 set_escape_char(optarg
);
242 (void) fprintf(stderr
,
243 "%s: Warning: -t ignored, no TN3270 support.\n",
252 autologin
= (rlogin
== _POSIX_VDISABLE
) ? 0 : 1;
258 char *args
[7], **argp
= args
;
267 *argp
++ = argv
[0]; /* host */
269 *argp
++ = argv
[1]; /* port */
272 if (setjmp(toplevel
) != 0)
274 if (tn(argp
- args
, args
) == 1)
275 return (EXIT_SUCCESS
);
277 return (EXIT_FAILURE
);
279 (void) setjmp(toplevel
);