Changes to make telnet & telnetd compile on OS X, and begin adapting them to GNO:

*New makefile
*Refer to local versions of telnet-related headers, rather than system ones
*Use termcap instead of termios
*Change hostname lookup in telnetd back to older code (which assumes IPv4, but that's all GNO supports anyway)
This commit is contained in:
Stephen Heumann 2015-05-30 22:12:01 -05:00
parent 052bf438de
commit 327170235b
25 changed files with 195 additions and 75 deletions

90
Makefile Normal file
View File

@ -0,0 +1,90 @@
LIBTELNET_SRCS = \
libtelnet/auth.c \
libtelnet/enc_des.c \
libtelnet/encrypt.c \
libtelnet/genget.c \
libtelnet/getent.c \
libtelnet/kerberos.c \
libtelnet/kerberos5.c \
libtelnet/krb4encpwd.c \
libtelnet/misc.c \
libtelnet/read_password.c \
libtelnet/rsaencpwd.c \
libtelnet/sra.c
# libtelnet/pk.c
TELNET_SRCS = \
telnet/authenc.c \
telnet/commands.c \
telnet/main.c \
telnet/network.c \
telnet/ring.c \
telnet/sys_bsd.c \
telnet/telnet.c \
telnet/terminal.c \
telnet/utilities.c
TELNETD_SRCS = \
telnetd/authenc.c \
telnetd/global.c \
telnetd/slc.c \
telnetd/state.c \
telnetd/sys_term.c \
telnetd/telnetd.c \
telnetd/termstat.c \
telnetd/utility.c
HEADERS = \
arpa/telnet.h \
libtelnet/auth-proto.h \
libtelnet/auth.h \
libtelnet/enc-proto.h \
libtelnet/encrypt.h \
libtelnet/key-proto.h \
libtelnet/misc-proto.h \
libtelnet/misc.h \
libtelnet/pk.h \
telnet/baud.h \
telnet/defines.h \
telnet/externs.h \
telnet/fdset.h \
telnet/general.h \
telnet/ring.h \
telnet/types.h \
telnetd/defs.h \
telnetd/ext.h \
telnetd/pathnames.h \
telnetd/telnetd.h
LIBTELNET_OBJS = $(LIBTELNET_SRCS:.c=.o)
TELNET_OBJS = $(TELNET_SRCS:.c=.o)
TELNETD_OBJS = $(TELNETD_SRCS:.c=.o)
OBJS = $(LIBTELNET_OBJS) $(TELNET_OBJS) $(TELNETD_OBJS)
INCLUDES = -I libtelnet -I .
TELNET_DEFINES = -DTERMCAP -DKLUDGELINEMODE -DENV_HACK -DOPIE
TELNETD_DEFINES = -DDIAGNOSTICS -DOLD_ENVIRON -DENV_HACK -DSTREAMSPTY
DEFINES = $(TELNET_DEFINES) $(TELNETD_DEFINES)
LIBS = -ltermcap
# CFLAGS suitable for clang or GCC
CFLAGS = -std=c89 -funsigned-char -Wall -Wno-pointer-sign -Wno-unused-variable -Wno-string-plus-int
.PHONY: all
all: telnet/telnet telnetd/telnetd
telnet/telnet: $(TELNET_OBJS) $(LIBTELNET_OBJS)
$(CC) $(LIBS) $(TELNET_OBJS) $(LIBTELNET_OBJS) -o $@
telnetd/telnetd: $(TELNETD_OBJS) $(LIBTELNET_OBJS)
$(CC) $(LIBS) $(TELNETD_OBJS) $(LIBTELNET_OBJS) -o $@
$(OBJS): $(HEADERS)
%.o: %.c
$(CC) $(INCLUDES) \
$(if $(findstring $<,$(TELNET_SRCS)),-I telnet $(TELNET_DEFINES)) \
$(if $(findstring $<,$(TELNETD_SRCS)),-I telnetd $(TELNETD_DEFINES)) \
$(CFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) $(OBJS) telnet/telnet telnetd/telnetd

View File

@ -70,7 +70,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include "encrypt.h"
#include "auth.h"

View File

@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$");
#ifdef ENCRYPTION
# ifdef AUTHENTICATION
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <openssl/des.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -65,7 +65,7 @@ static const char sccsid[] = "@(#)encrypt.c 8.2 (Berkeley) 5/30/95";
#include <sys/types.h>
#define ENCRYPT_NAMES
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -61,7 +61,7 @@ static const char sccsid[] = "@(#)kerberos.c 8.3 (Berkeley) 5/30/95";
#ifdef KRB4
#include <sys/types.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <openssl/des.h> /* BSD wont include this in krb.h, so we do it here */
#include <krb.h>
#include <stdio.h>

View File

@ -57,7 +57,7 @@ __FBSDID("$FreeBSD$");
#ifdef KRB5
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -76,7 +76,7 @@ static char sccsid[] = "@(#)krb4encpwd.c 8.3 (Berkeley) 5/30/95";
#include <sys/types.h>
#include <openssl/des.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <krb.h>
#include <pwd.h>
#include <stdio.h>

View File

@ -75,7 +75,7 @@ static char sccsid[] = "@(#)rsaencpwd.c 8.3 (Berkeley) 5/30/95";
*/
#include <sys/types.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -35,7 +35,7 @@ __FBSDID("$FreeBSD$");
#ifdef SRA
#ifdef ENCRYPTION
#include <sys/types.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -42,11 +42,11 @@ __FBSDID("$FreeBSD$");
#ifdef AUTHENTICATION
#ifdef ENCRYPTION
#include <sys/types.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <pwd.h>
#include <unistd.h>
#include <libtelnet/encrypt.h>
#include <libtelnet/misc.h>
#include "libtelnet/encrypt.h"
#include "libtelnet/misc.h"
#include "general.h"
#include "ring.h"

View File

@ -56,7 +56,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <arpa/inet.h>
#include "general.h"
@ -69,10 +69,10 @@ __FBSDID("$FreeBSD$");
#include "misc.h"
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#include "libtelnet/auth.h"
#endif
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
#include <netinet/in_systm.h>

View File

@ -45,14 +45,11 @@
#define BSD 43
#endif
#ifndef USE_TERMIO
# if BSD > 43 || defined(SYSV_TERMIO)
# define USE_TERMIO
# endif
#endif
#include <stdio.h>
#include <setjmp.h>
#if !defined(USE_TERMIO)
# define USE_OLD_TTY
#endif
#include <sys/ioctl.h>
#include <errno.h>
#ifdef USE_TERMIO
@ -63,7 +60,7 @@
#endif
#if defined(NO_CC_T) || !defined(USE_TERMIO)
# if !defined(USE_TERMIO)
typedef char cc_t;
typedef unsigned char cc_t;
# else
typedef unsigned char cc_t;
# endif
@ -214,7 +211,7 @@ extern int (*decrypt_input)(int);
#define set_his_want_state_dont set_my_want_state_wont
#define set_his_want_state_wont set_my_want_state_dont
#if defined(USE_TERMIO)
#if defined(USE_TERMIO) || defined(__STDC__)
#define SIG_FUNC_RET void
#else
#define SIG_FUNC_RET int

View File

@ -50,10 +50,10 @@ __FBSDID("$FreeBSD$");
#include "defines.h"
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#include "libtelnet/auth.h"
#endif
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
/* These values need to be the same as defined in libtelnet/kerberos5.c */

View File

@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <stdlib.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <unistd.h>
#include "ring.h"

View File

@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$");
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include "ring.h"
#include "fdset.h"

View File

@ -50,10 +50,9 @@ __FBSDID("$FreeBSD$");
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
#include <term.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include "ring.h"
@ -62,13 +61,19 @@ __FBSDID("$FreeBSD$");
#include "types.h"
#include "general.h"
#ifdef USE_TERMIO
# include <term.h>
#else
# include <termcap.h>
#endif
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#include "libtelnet/auth.h"
#endif
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
#include <libtelnet/misc.h>
#include "libtelnet/misc.h"
#define strip(x) ((my_want_state_is_wont(TELOPT_BINARY)) ? ((x)&0x7f) : (x))

View File

@ -39,7 +39,7 @@ static const char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <sys/types.h>
#include <stdlib.h>
@ -50,7 +50,7 @@ __FBSDID("$FreeBSD$");
#include "types.h"
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
Ring ttyoring, ttyiring;

View File

@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
#define TELOPTS
#define TELCMDS
#define SLC_NAMES
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
@ -61,10 +61,10 @@ __FBSDID("$FreeBSD$");
#include "externs.h"
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#include "libtelnet/auth.h"
#endif
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
FILE *NetTrace = 0; /* Not in bss, since needs to stay */

View File

@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$");
/* Above "#ifdef"s actually "or"'ed together. XXX MarkM
*/
#include "telnetd.h"
#include <libtelnet/misc.h>
#include "libtelnet/misc.h"
int
net_write(unsigned char *str, int len)

View File

@ -68,7 +68,7 @@
#include <netinet/in.h>
#include <arpa/telnet.h>
#include "arpa/telnet.h"
#include <stdio.h>
#ifdef __STDC__

View File

@ -42,10 +42,10 @@ __FBSDID("$FreeBSD$");
#include <stdarg.h>
#include "telnetd.h"
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#include "libtelnet/auth.h"
#endif
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
unsigned char doopt[] = { IAC, DO, '%', 'c', 0 };

View File

@ -41,16 +41,13 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/tty.h>
#include <libutil.h>
#include <stdlib.h>
#include "telnetd.h"
#include "pathnames.h"
#include "types.h"
#include "baud.h"
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#include "libtelnet/auth.h"
#endif
int cleanopen(char *);
@ -126,7 +123,6 @@ struct termios termbuf, termbuf2; /* pty control structure */
#endif /* USE_TERMIO */
#include <sys/types.h>
#include <libutil.h>
int cleanopen(char *);
void scrub_env(void);
@ -809,7 +805,11 @@ getptyslave(void)
# ifdef LINEMODE
waslm = tty_linemode();
# endif
# ifdef USE_TERMIO
erase = termbuf.c_cc[VERASE];
# else
erase = termbuf.sg.sg_erase;
# endif
/*
* Make sure that we don't have a controlling tty, and
@ -855,8 +855,13 @@ getptyslave(void)
*/
tty_rspeed((def_rspeed > 0) ? def_rspeed : 9600);
tty_tspeed((def_tspeed > 0) ? def_tspeed : 9600);
if (erase)
if (erase) {
# ifdef USE_TERMIO
termbuf.c_cc[VERASE] = erase;
# else
termbuf.sg.sg_erase = erase;
# endif
}
# ifdef LINEMODE
if (waslm)
tty_setlinemode(1);

View File

@ -44,20 +44,19 @@ __FBSDID("$FreeBSD$");
#include <sys/mman.h>
#include <err.h>
#include <libutil.h>
#include <paths.h>
#include <termcap.h>
#include <arpa/inet.h>
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#include "libtelnet/auth.h"
int auth_level = 0;
#endif
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
#include <libtelnet/misc.h>
#include "libtelnet/misc.h"
char remote_hostname[MAXHOSTNAMELEN];
size_t utmp_len = sizeof(remote_hostname) - 1;
@ -658,10 +657,13 @@ terminaltypeok(char *s)
* Get a pty, scan input lines.
*/
void
doit(struct sockaddr *who)
doit(struct sockaddr *who_)
{
int err_; /* XXX */
char *host = NULL;
struct hostent *hp;
int ptynum;
struct sockaddr_in *who;
/*
* Find an available pty to use.
@ -686,30 +688,51 @@ doit(struct sockaddr *who)
#endif
/* get name of connected client */
if (realhostname_sa(remote_hostname, sizeof(remote_hostname) - 1,
who, who->sa_len) == HOSTNAME_INVALIDADDR && registerd_host_only)
if (who_->sa_family != AF_INET)
fatal(net, "Non-IPv4 addresses are not supported");
who = (struct sockaddr_in *)who_;
hp = gethostbyaddr((char *)&who->sin_addr, sizeof (struct in_addr),
who->sin_family);
if (hp == NULL && registerd_host_only) {
fatal(net, "Couldn't resolve your address into a host name.\r\n\
Please contact your net administrator");
remote_hostname[sizeof(remote_hostname) - 1] = '\0';
Please contact your net administrator");
} else if (hp &&
(strlen(hp->h_name) <= (unsigned int)((utmp_len < 0) ? -utmp_len
: utmp_len))) {
strncpy(remote_hostname, hp->h_name,
sizeof(remote_hostname)-1);
hp = gethostbyname(remote_hostname);
if (hp == NULL)
host = inet_ntoa(who->sin_addr);
else for (; ; hp->h_addr_list++) {
if (hp->h_addr_list[0] == NULL) {
/* End of list - ditch it */
host = inet_ntoa(who->sin_addr);
break;
}
if (!bcmp(hp->h_addr_list[0], (caddr_t)&who->sin_addr,
sizeof(who->sin_addr))) {
host = hp->h_name;
break; /* OK! */
}
}
} else {
host = inet_ntoa(who->sin_addr);
}
/*
* We must make a copy because Kerberos is probably going
* to also do a gethost* and overwrite the static data...
*/
strncpy(remote_hostname, host, sizeof(remote_hostname)-1);
remote_hostname[sizeof(remote_hostname)-1] = 0;
host = remote_hostname;
if (!isdigit(remote_hostname[0]) && strlen(remote_hostname) > utmp_len)
err_ = getnameinfo(who, who->sa_len, remote_hostname,
sizeof(remote_hostname), NULL, 0,
NI_NUMERICHOST);
/* XXX: do 'err_' check */
(void) gethostname(host_name, sizeof(host_name) - 1);
host_name[sizeof(host_name) - 1] = '\0';
(void) gethostname(host_name, sizeof (host_name));
hostname = host_name;
#ifdef AUTHENTICATION
#ifdef ENCRYPTION
/* The above #ifdefs should actually be "or"'ed, not "and"'ed.
* This is a byproduct of needing "#ifdef" and not "#if defined()"
* for unifdef. XXX MarkM
*/
auth_encrypt_init(hostname, remote_hostname, "TELNETD", 1);
#endif
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
auth_encrypt_init(hostname, host, "TELNETD", 1);
#endif
init_env();
@ -720,7 +743,7 @@ doit(struct sockaddr *who)
level = getterminaltype(user_name);
setenv("TERM", terminaltype ? terminaltype : "network", 1);
telnet(net, pty, remote_hostname); /* begin server process */
telnet(net, pty, host); /* begin server process */
/*NOTREACHED*/
} /* end of doit */

View File

@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
#include "telnetd.h"
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
/*

View File

@ -48,10 +48,10 @@ __FBSDID("$FreeBSD$");
#include "telnetd.h"
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#include "libtelnet/auth.h"
#endif
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#include "libtelnet/encrypt.h"
#endif
/*