1997-09-04 06:11:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-05-04 02:54:49 +00:00
|
|
|
#if 0
|
1997-09-04 06:11:16 +00:00
|
|
|
#ifndef lint
|
1997-09-07 07:02:53 +00:00
|
|
|
static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
|
2001-11-30 21:06:38 +00:00
|
|
|
#endif
|
2003-05-04 02:54:49 +00:00
|
|
|
#endif
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1997-09-04 06:11:16 +00:00
|
|
|
|
2005-01-09 10:24:46 +00:00
|
|
|
#include <sys/param.h>
|
2000-01-27 09:28:38 +00:00
|
|
|
#include <sys/socket.h>
|
1997-09-07 07:02:53 +00:00
|
|
|
#include <stdlib.h>
|
2001-08-20 12:28:40 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
1997-09-04 06:11:16 +00:00
|
|
|
|
|
|
|
#include "ring.h"
|
|
|
|
#include "externs.h"
|
|
|
|
#include "defines.h"
|
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifdef AUTHENTICATION
|
1997-09-07 07:02:53 +00:00
|
|
|
#include <libtelnet/auth.h>
|
|
|
|
#endif
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifdef ENCRYPTION
|
1997-09-07 07:02:53 +00:00
|
|
|
#include <libtelnet/encrypt.h>
|
|
|
|
#endif
|
|
|
|
|
1997-09-04 06:11:16 +00:00
|
|
|
/* These values need to be the same as defined in libtelnet/kerberos5.c */
|
|
|
|
/* Either define them in both places, or put in some common header file. */
|
|
|
|
#define OPTS_FORWARD_CREDS 0x00000002
|
|
|
|
#define OPTS_FORWARDABLE_CREDS 0x00000001
|
|
|
|
|
2000-01-27 09:28:38 +00:00
|
|
|
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
|
|
|
|
char *ipsec_policy_in = NULL;
|
|
|
|
char *ipsec_policy_out = NULL;
|
|
|
|
#endif
|
|
|
|
|
2005-01-09 10:24:46 +00:00
|
|
|
extern int tos;
|
|
|
|
|
2000-01-27 09:28:38 +00:00
|
|
|
int family = AF_UNSPEC;
|
|
|
|
|
1997-09-04 06:11:16 +00:00
|
|
|
/*
|
|
|
|
* Initialize variables.
|
|
|
|
*/
|
2001-11-30 21:06:38 +00:00
|
|
|
void
|
|
|
|
tninit(void)
|
1997-09-04 06:11:16 +00:00
|
|
|
{
|
|
|
|
init_terminal();
|
|
|
|
|
|
|
|
init_network();
|
|
|
|
|
|
|
|
init_telnet();
|
|
|
|
|
|
|
|
init_sys();
|
|
|
|
}
|
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
1997-09-04 06:11:16 +00:00
|
|
|
{
|
2002-09-25 07:26:25 +00:00
|
|
|
fprintf(stderr, "usage: %s %s%s%s%s\n",
|
1997-09-04 06:11:16 +00:00
|
|
|
prompt,
|
|
|
|
#ifdef AUTHENTICATION
|
2001-04-06 15:56:10 +00:00
|
|
|
"[-4] [-6] [-8] [-E] [-K] [-L] [-N] [-S tos] [-X atype] [-c] [-d]",
|
1999-06-17 09:24:37 +00:00
|
|
|
"\n\t[-e char] [-k realm] [-l user] [-f/-F] [-n tracefile] ",
|
1997-09-04 06:11:16 +00:00
|
|
|
#else
|
2001-07-05 14:06:27 +00:00
|
|
|
"[-4] [-6] [-8] [-E] [-L] [-N] [-S tos] [-c] [-d]",
|
|
|
|
"\n\t[-e char] [-l user] [-n tracefile] ",
|
1997-09-04 06:11:16 +00:00
|
|
|
#endif
|
2001-07-05 14:06:27 +00:00
|
|
|
"[-r] [-s src_addr] [-u] ",
|
2000-01-27 09:28:38 +00:00
|
|
|
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
|
2001-07-05 14:06:27 +00:00
|
|
|
"[-P policy] "
|
2000-01-27 09:28:38 +00:00
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
#ifdef ENCRYPTION
|
2001-04-06 15:56:10 +00:00
|
|
|
"[-y] [host-name [port]]"
|
1997-09-04 06:11:16 +00:00
|
|
|
#else /* ENCRYPTION */
|
|
|
|
"[host-name [port]]"
|
|
|
|
#endif /* ENCRYPTION */
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* main. Parse arguments, invoke the protocol or command parser.
|
|
|
|
*/
|
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
1997-09-04 06:11:16 +00:00
|
|
|
{
|
2005-01-09 10:24:46 +00:00
|
|
|
u_long ultmp;
|
1997-09-04 06:11:16 +00:00
|
|
|
int ch;
|
2005-01-09 10:24:46 +00:00
|
|
|
char *ep, *user;
|
1999-06-17 09:24:37 +00:00
|
|
|
char *src_addr = NULL;
|
1997-09-04 06:11:16 +00:00
|
|
|
#ifdef FORWARD
|
|
|
|
extern int forward_flags;
|
|
|
|
#endif /* FORWARD */
|
|
|
|
|
|
|
|
tninit(); /* Clear out things */
|
|
|
|
|
|
|
|
TerminalSaveState();
|
|
|
|
|
1997-09-07 07:02:53 +00:00
|
|
|
if ((prompt = strrchr(argv[0], '/')))
|
1997-09-04 06:11:16 +00:00
|
|
|
++prompt;
|
|
|
|
else
|
|
|
|
prompt = argv[0];
|
|
|
|
|
|
|
|
user = NULL;
|
|
|
|
|
|
|
|
rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
|
2001-08-20 12:28:40 +00:00
|
|
|
#ifdef AUTHENTICATION
|
2001-04-06 15:56:10 +00:00
|
|
|
autologin = 1;
|
2001-08-20 12:28:40 +00:00
|
|
|
#else
|
|
|
|
autologin = -1;
|
|
|
|
#endif
|
2001-04-06 15:56:10 +00:00
|
|
|
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifdef ENCRYPTION
|
2001-04-06 15:56:10 +00:00
|
|
|
encrypt_auto(1);
|
|
|
|
decrypt_auto(1);
|
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
|
2000-01-27 09:28:38 +00:00
|
|
|
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
|
|
|
|
#define IPSECOPT "P:"
|
|
|
|
#else
|
|
|
|
#define IPSECOPT
|
|
|
|
#endif
|
|
|
|
while ((ch = getopt(argc, argv,
|
2005-01-05 09:47:10 +00:00
|
|
|
"468EKLNS:X:acde:fFk:l:n:rs:uxy" IPSECOPT)) != -1)
|
2000-01-27 09:28:38 +00:00
|
|
|
#undef IPSECOPT
|
|
|
|
{
|
1997-09-04 06:11:16 +00:00
|
|
|
switch(ch) {
|
2000-01-27 09:28:38 +00:00
|
|
|
case '4':
|
|
|
|
family = AF_INET;
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case '6':
|
|
|
|
family = AF_INET6;
|
|
|
|
break;
|
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
case '8':
|
|
|
|
eight = 3; /* binary output and input */
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
rlogin = escape = _POSIX_VDISABLE;
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
#ifdef AUTHENTICATION
|
|
|
|
autologin = 0;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
eight |= 2; /* binary output only */
|
|
|
|
break;
|
1999-06-17 09:24:37 +00:00
|
|
|
case 'N':
|
|
|
|
doaddrlookup = 0;
|
|
|
|
break;
|
1997-09-04 06:11:16 +00:00
|
|
|
case 'S':
|
|
|
|
#ifdef HAS_GETTOS
|
|
|
|
|
|
|
|
if ((tos = parsetos(optarg, "tcp")) < 0)
|
|
|
|
fprintf(stderr, "%s%s%s%s\n",
|
|
|
|
prompt, ": Bad TOS argument '",
|
|
|
|
optarg,
|
|
|
|
"; will try to use default TOS");
|
|
|
|
#else
|
2005-01-09 10:24:46 +00:00
|
|
|
#define MAXTOS 255
|
|
|
|
ultmp = strtoul(optarg, &ep, 0);
|
|
|
|
if (*ep || ep == optarg || ultmp > MAXTOS)
|
|
|
|
fprintf(stderr, "%s%s%s%s\n",
|
|
|
|
prompt, ": Bad TOS argument '",
|
|
|
|
optarg,
|
|
|
|
"; will try to use default TOS");
|
|
|
|
else
|
|
|
|
tos = ultmp;
|
1997-09-04 06:11:16 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
#ifdef AUTHENTICATION
|
|
|
|
auth_disable_name(optarg);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'a':
|
2001-08-20 12:28:40 +00:00
|
|
|
#ifdef AUTHENTICATION
|
2001-04-06 15:56:10 +00:00
|
|
|
/* It's the default now, so ignore */
|
2001-08-20 12:28:40 +00:00
|
|
|
#else
|
|
|
|
autologin = 1;
|
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
skiprc = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2003-05-11 18:17:00 +00:00
|
|
|
telnet_debug = 1;
|
1997-09-04 06:11:16 +00:00
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
set_escape_char(optarg);
|
|
|
|
break;
|
|
|
|
case 'f':
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifdef AUTHENTICATION
|
|
|
|
#if defined(KRB5) && defined(FORWARD)
|
1997-09-04 06:11:16 +00:00
|
|
|
if (forward_flags & OPTS_FORWARD_CREDS) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Only one of -f and -F allowed.\n",
|
|
|
|
prompt);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
forward_flags |= OPTS_FORWARD_CREDS;
|
2001-11-30 21:06:38 +00:00
|
|
|
#else
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Warning: -f ignored, no Kerberos V5 support.\n",
|
|
|
|
prompt);
|
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
#else
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Warning: -f ignored, no Kerberos V5 support.\n",
|
|
|
|
prompt);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'F':
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifdef AUTHENTICATION
|
|
|
|
#if defined(KRB5) && defined(FORWARD)
|
1997-09-04 06:11:16 +00:00
|
|
|
if (forward_flags & OPTS_FORWARD_CREDS) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Only one of -f and -F allowed.\n",
|
|
|
|
prompt);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
forward_flags |= OPTS_FORWARD_CREDS;
|
|
|
|
forward_flags |= OPTS_FORWARDABLE_CREDS;
|
2001-11-30 21:06:38 +00:00
|
|
|
#else
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Warning: -F ignored, no Kerberos V5 support.\n",
|
|
|
|
prompt);
|
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
#else
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Warning: -F ignored, no Kerberos V5 support.\n",
|
|
|
|
prompt);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'k':
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifdef AUTHENTICATION
|
|
|
|
#if defined(KRB4)
|
1997-09-04 06:11:16 +00:00
|
|
|
{
|
|
|
|
extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
|
|
|
|
dest_realm = dst_realm_buf;
|
|
|
|
(void)strncpy(dest_realm, optarg, dst_realm_sz);
|
|
|
|
}
|
2001-11-30 21:06:38 +00:00
|
|
|
#else
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Warning: -k ignored, no Kerberos V4 support.\n",
|
|
|
|
prompt);
|
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
#else
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Warning: -k ignored, no Kerberos V4 support.\n",
|
|
|
|
prompt);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case 'l':
|
2001-08-20 12:28:40 +00:00
|
|
|
#ifdef AUTHENTICATION
|
|
|
|
/* This is the default now, so ignore it */
|
|
|
|
#else
|
|
|
|
autologin = 1;
|
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
user = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
SetNetTrace(optarg);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
rlogin = '~';
|
|
|
|
break;
|
1999-06-17 09:24:37 +00:00
|
|
|
case 's':
|
|
|
|
src_addr = optarg;
|
|
|
|
break;
|
2001-07-05 14:06:27 +00:00
|
|
|
case 'u':
|
|
|
|
family = AF_UNIX;
|
|
|
|
break;
|
1997-09-04 06:11:16 +00:00
|
|
|
case 'x':
|
2001-11-30 21:06:38 +00:00
|
|
|
#ifndef ENCRYPTION
|
2001-08-20 12:28:40 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Warning: -x ignored, no ENCRYPT support.\n",
|
|
|
|
prompt);
|
|
|
|
#endif /* ENCRYPTION */
|
2001-04-06 15:56:10 +00:00
|
|
|
break;
|
|
|
|
case 'y':
|
1997-09-04 06:11:16 +00:00
|
|
|
#ifdef ENCRYPTION
|
2001-04-06 15:56:10 +00:00
|
|
|
encrypt_auto(0);
|
|
|
|
decrypt_auto(0);
|
2001-08-20 12:28:40 +00:00
|
|
|
#else
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: Warning: -y ignored, no ENCRYPT support.\n",
|
|
|
|
prompt);
|
1997-09-04 06:11:16 +00:00
|
|
|
#endif /* ENCRYPTION */
|
|
|
|
break;
|
2000-01-27 09:28:38 +00:00
|
|
|
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
|
|
|
|
case 'P':
|
|
|
|
if (!strncmp("in", optarg, 2))
|
|
|
|
ipsec_policy_in = strdup(optarg);
|
|
|
|
else if (!strncmp("out", optarg, 3))
|
|
|
|
ipsec_policy_out = strdup(optarg);
|
|
|
|
else
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
#endif
|
1997-09-04 06:11:16 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
2001-08-20 12:28:40 +00:00
|
|
|
if (autologin == -1)
|
|
|
|
autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
|
2001-03-12 03:54:48 +00:00
|
|
|
|
1997-09-04 06:11:16 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc) {
|
1999-06-17 09:24:37 +00:00
|
|
|
char *args[9], **argp = args;
|
1997-09-04 06:11:16 +00:00
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
usage();
|
|
|
|
*argp++ = prompt;
|
|
|
|
if (user) {
|
2001-11-30 21:06:38 +00:00
|
|
|
*argp++ = strdup("-l");
|
1997-09-04 06:11:16 +00:00
|
|
|
*argp++ = user;
|
|
|
|
}
|
1999-06-17 09:24:37 +00:00
|
|
|
if (src_addr) {
|
2001-11-30 21:06:38 +00:00
|
|
|
*argp++ = strdup("-s");
|
1999-06-17 09:24:37 +00:00
|
|
|
*argp++ = src_addr;
|
|
|
|
}
|
1997-09-04 06:11:16 +00:00
|
|
|
*argp++ = argv[0]; /* host */
|
|
|
|
if (argc > 1)
|
|
|
|
*argp++ = argv[1]; /* port */
|
|
|
|
*argp = 0;
|
|
|
|
|
|
|
|
if (setjmp(toplevel) != 0)
|
|
|
|
Exit(0);
|
|
|
|
if (tn(argp - args, args) == 1)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
(void)setjmp(toplevel);
|
|
|
|
for (;;) {
|
|
|
|
command(1, 0, 0);
|
|
|
|
}
|
1997-09-07 07:02:53 +00:00
|
|
|
return 0;
|
1997-09-04 06:11:16 +00:00
|
|
|
}
|