Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 64632 | Differences between
and this patch

Collapse All | Expand All

(-)./netkit-telnet-0.17/Makefile (-2 / +1 lines)
Lines 1-8 Link Here
1
# You can do "make SUB=blah" to make only a few, or edit here, or both
1
# You can do "make SUB=blah" to make only a few, or edit here, or both
2
# You can also run make directly in the subdirs you want.
2
# You can also run make directly in the subdirs you want.
3
3
4
SUB =   telnet telnetd
4
SUB =   telnet telnetd telnetlogin
5
# not yet: telnetlogin
6
5
7
%.build:
6
%.build:
8
	(cd $(patsubst %.build, %, $@) && $(MAKE))
7
	(cd $(patsubst %.build, %, $@) && $(MAKE))
(-)./netkit-telnet-0.17/__conftest.cc (+7 lines)
Line 0 Link Here
1
#include <stdio.h>
2
int main() {
3
    void *x = (void *)snprintf;
4
    printf("%lx", (long)x);
5
    return 0;
6
}
7
(-)./netkit-telnet-0.17/configure (-2 / +2 lines)
Lines 67-73 Link Here
67
67
68
##################################################
68
##################################################
69
69
70
WARNINGS='-Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline '
70
WARNINGS='-Wall -Wno-trigraphs '
71
71
72
cat << EOF > __conftest.c
72
cat << EOF > __conftest.c
73
    int main() { int class=0; return class; }
73
    int main() { int class=0; return class; }
Lines 117-123 Link Here
117
117
118
cat << EOF > __conftest.cc
118
cat << EOF > __conftest.cc
119
    template <class T> class fnord { public: T x; fnord(T y) { x=y; }};
119
    template <class T> class fnord { public: T x; fnord(T y) { x=y; }};
120
    int main() { fnord<int> a(0); return a.x; }
120
    int main() { fnord<int> *a = new fnord<int>(0); return a->x; }
121
EOF
121
EOF
122
122
123
if [ x"$CXX" = x ]; then
123
if [ x"$CXX" = x ]; then
(-)./netkit-telnet-0.17/telnet/Makefile (-1 / +1 lines)
Lines 7-13 Link Here
7
7
8
# -DAUTHENTICATE
8
# -DAUTHENTICATE
9
CXXFLAGS += -DUSE_TERMIO -DKLUDGELINEMODE
9
CXXFLAGS += -DUSE_TERMIO -DKLUDGELINEMODE
10
LIBS += $(LIBTERMCAP)
10
LIBS = $(LIBTERMCAP)
11
11
12
SRCS = commands.cc main.cc network.cc ring.cc sys_bsd.cc telnet.cc \
12
SRCS = commands.cc main.cc network.cc ring.cc sys_bsd.cc telnet.cc \
13
	terminal.cc tn3270.cc utilities.cc genget.cc environ.cc netlink.cc
13
	terminal.cc tn3270.cc utilities.cc genget.cc environ.cc netlink.cc
(-)./netkit-telnet-0.17/telnet/commands.cc (-89 / +169 lines)
Lines 86-95 Link Here
86
86
87
#define HELPINDENT ((int) sizeof ("connect"))
87
#define HELPINDENT ((int) sizeof ("connect"))
88
88
89
#ifndef       MAXHOSTNAMELEN
90
#define       MAXHOSTNAMELEN 64
91
#endif        MAXHOSTNAMELEN
92
93
#if	defined(HAS_IPPROTO_IP) && defined(IP_TOS)
89
#if	defined(HAS_IPPROTO_IP) && defined(IP_TOS)
94
int tos = -1;
90
int tos = -1;
95
#endif	/* defined(HAS_IPPROTO_IP) && defined(IP_TOS) */
91
#endif	/* defined(HAS_IPPROTO_IP) && defined(IP_TOS) */
Lines 98-104 Link Here
98
94
99
95
100
char	*hostname;
96
char	*hostname;
101
static char _hostname[MAXHOSTNAMELEN];
97
static char *_hostname;
102
98
103
//typedef int (*intrtn_t)(int argc, const char *argv[]);
99
//typedef int (*intrtn_t)(int argc, const char *argv[]);
104
100
Lines 161-167 Link Here
161
	assert(argc>=1);
157
	assert(argc>=1);
162
	if (nargs>=0 && argc!=nargs+1) {
158
	if (nargs>=0 && argc!=nargs+1) {
163
	    fprintf(stderr, "Wrong number of arguments for command.\n");
159
	    fprintf(stderr, "Wrong number of arguments for command.\n");
164
	    fprintf(stderr, "Try %s ? for help\n", argv[0]);
160
	    fprintf(stderr, "Try ? %s for help\n", argv[0]);
165
	    return 0;    /* is this right? */
161
	    return 0;    /* is this right? */
166
	}
162
	}
167
	if (nargs==-2) {
163
	if (nargs==-2) {
Lines 480-485 Link Here
480
int send_tncmd(int (*func)(int, int), const char *cmd, const char *name) {
476
int send_tncmd(int (*func)(int, int), const char *cmd, const char *name) {
481
    char **cpp;
477
    char **cpp;
482
    extern char *telopts[];
478
    extern char *telopts[];
479
    long opt;
483
480
484
    if (isprefix(name, "help") || isprefix(name, "?")) {
481
    if (isprefix(name, "help") || isprefix(name, "?")) {
485
	register int col, len;
482
	register int col, len;
Lines 506-521 Link Here
506
					name, cmd);
503
					name, cmd);
507
	return 0;
504
	return 0;
508
    }
505
    }
506
507
    opt = cpp - telopts;
509
    if (cpp == 0) {
508
    if (cpp == 0) {
510
	fprintf(stderr, "'%s': unknown argument ('send %s ?' for help).\n",
509
	char *end;
510
511
	opt = strtol(name, &end, 10);
512
	if (*end || opt < 0 || opt > 255) {
513
	    fprintf(stderr, "'%s': unknown argument ('send %s ?' for help).\n",
511
					name, cmd);
514
					name, cmd);
512
	return 0;
515
	    return 0;
516
	}
513
    }
517
    }
514
    if (!connected) {
518
    if (!connected) {
515
	printf("?Need to be connected first.\n");
519
	printf("?Need to be connected first.\n");
516
	return 0;
520
	return 0;
517
    }
521
    }
518
    (*func)(cpp - telopts, 1);
522
    (*func)(opt, 1);
519
    return 1;
523
    return 1;
520
}
524
}
521
525
Lines 689-697 Link Here
689
      "print encryption debugging information" },
693
      "print encryption debugging information" },
690
#endif
694
#endif
691
695
692
    { "skiprc", "don't read ~/.telnetrc file",
696
    { "skiprc", "don't read the telnetrc files",
693
      NULL, &skiprc,
697
      NULL, &skiprc,
694
      "read ~/.telnetrc file" },
698
      "read the telnetrc files" },
695
    { "binary",
699
    { "binary",
696
      "sending and receiving of binary data",
700
      "sending and receiving of binary data",
697
      togbinary, NULL,
701
      togbinary, NULL,
Lines 1615-1629 Link Here
1615
#endif
1619
#endif
1616
1620
1617
int tn(int argc, const char *argv[]) {
1621
int tn(int argc, const char *argv[]) {
1618
    register struct hostent *host = 0;
1619
    struct sockaddr_in sn;
1622
    struct sockaddr_in sn;
1620
    struct servent *sp = 0;
1621
    char *srp = NULL;
1623
    char *srp = NULL;
1622
    int srlen;
1624
    int srlen;
1623
1625
    int family = 0;
1624
    const char *cmd, *volatile user = 0;
1626
    const char *cmd, *volatile user = 0, *srchostp = 0;
1625
    const char *portp = NULL;
1627
    const char *portp = NULL;
1626
    char *hostp = NULL;
1628
    char *hostp = NULL;
1629
    char *resolv_hostp;
1630
    struct addrinfo hints;
1631
    struct addrinfo *hostaddr = 0;
1632
    int res;
1633
    char name[NI_MAXHOST];
1634
    char service[NI_MAXSERV];
1635
    struct addrinfo *tmpaddr;
1627
1636
1628
    /* clear the socket address prior to use */
1637
    /* clear the socket address prior to use */
1629
    memset(&sn, 0, sizeof(sn));
1638
    memset(&sn, 0, sizeof(sn));
Lines 1632-1637 Link Here
1632
	printf("?Already connected to %s\n", hostname);
1641
	printf("?Already connected to %s\n", hostname);
1633
	return 0;
1642
	return 0;
1634
    }
1643
    }
1644
    if (_hostname) {
1645
	delete[] _hostname;
1646
	_hostname = 0;
1647
    }
1635
    if (argc < 2) {
1648
    if (argc < 2) {
1636
	(void) strcpy(line, "open ");
1649
	(void) strcpy(line, "open ");
1637
	printf("(to) ");
1650
	printf("(to) ");
Lines 1657-1667 Link Here
1657
	    --argc;
1670
	    --argc;
1658
	    continue;
1671
	    continue;
1659
	}
1672
	}
1673
	if (strcmp(*argv, "-b") == 0) {
1674
	    --argc; ++argv;
1675
	    if (argc == 0)
1676
		goto usage;
1677
	    srchostp = *argv++;
1678
	    --argc;
1679
	    continue;
1680
	}
1660
	if (strcmp(*argv, "-a") == 0) {
1681
	if (strcmp(*argv, "-a") == 0) {
1661
	    --argc; ++argv;
1682
	    --argc; ++argv;
1662
	    autologin = 1;
1683
	    autologin = 1;
1663
	    continue;
1684
	    continue;
1664
	}
1685
	}
1686
	if (strcmp(*argv, "-6") == 0) {
1687
	    --argc; ++argv;
1688
#ifdef AF_INET6
1689
	    family = AF_INET6;
1690
#else
1691
	    puts("IPv6 unsupported");
1692
#endif
1693
	    continue;
1694
	}
1695
	if (strcmp(*argv, "-4") == 0) {
1696
	    --argc; ++argv;
1697
	    family = AF_INET;
1698
	    continue;
1699
	}
1665
	if (hostp == 0) {
1700
	if (hostp == 0) {
1666
	    /* this leaks memory - FIXME */
1701
	    /* this leaks memory - FIXME */
1667
	    hostp = strdup(*argv++);
1702
	    hostp = strdup(*argv++);
Lines 1680-1685 Link Here
1680
    if (hostp == 0)
1715
    if (hostp == 0)
1681
	goto usage;
1716
	goto usage;
1682
1717
1718
    resolv_hostp = hostp;
1719
1683
#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
1720
#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
1684
    if (hostp[0] == '@' || hostp[0] == '!') {
1721
    if (hostp[0] == '@' || hostp[0] == '!') {
1685
	if ((hostname = strrchr(hostp, ':')) == NULL)
1722
	if ((hostname = strrchr(hostp, ':')) == NULL)
Lines 1696-1773 Link Here
1696
	} else {
1733
	} else {
1697
	    sn.sin_addr.s_addr = temp;
1734
	    sn.sin_addr.s_addr = temp;
1698
	    sn.sin_family = AF_INET;
1735
	    sn.sin_family = AF_INET;
1736
	    /*
1737
	     * For source route we just make sure to get the IP given
1738
	     * on the command line when looking up the port.
1739
	     */
1740
	    resolv_hostp = inet_ntoa(sn.sin_addr);
1699
	}
1741
	}
1700
    } 
1742
    } 
1701
    else {
1702
#endif
1703
	if (inet_aton(hostp, &sn.sin_addr)) {
1704
	    sn.sin_family = AF_INET;
1705
	    strcpy(_hostname, hostp);
1706
	    hostname = _hostname;
1707
	} 
1708
	else {
1709
	    host = gethostbyname(hostp);
1710
	    if (host) {
1711
		sn.sin_family = host->h_addrtype;
1712
		if (host->h_length > (int)sizeof(sn.sin_addr)) {
1713
		    host->h_length = sizeof(sn.sin_addr);
1714
		}
1715
#if	defined(h_addr)		/* In 4.3, this is a #define */
1716
		memcpy((caddr_t)&sn.sin_addr,
1717
				host->h_addr_list[0], host->h_length);
1718
#else	/* defined(h_addr) */
1719
		memcpy((caddr_t)&sn.sin_addr, host->h_addr, host->h_length);
1720
#endif	/* defined(h_addr) */
1721
		strncpy(_hostname, host->h_name, sizeof(_hostname));
1722
		_hostname[sizeof(_hostname)-1] = '\0';
1723
		hostname = _hostname;
1724
	    } else {
1725
		herror(hostp);
1726
		return 0;
1727
	    }
1728
	}
1729
#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
1730
    }
1731
#endif
1743
#endif
1744
1745
    /* User port or the default name of telnet. */
1732
    if (portp) {
1746
    if (portp) {
1733
	if (*portp == '-') {
1747
	if (*portp == '-') {
1734
	    portp++;
1748
	    portp++;
1735
	    telnetport = 1;
1749
	    telnetport = 1;
1736
	} else
1750
	} else
1737
	    telnetport = 0;
1751
	    telnetport = 0;
1738
	sn.sin_port = atoi(portp);
1752
    }
1739
	if (sn.sin_port == 0) {
1740
	    sp = getservbyname(portp, "tcp");
1741
	    if (sp)
1742
		sn.sin_port = sp->s_port;
1743
	    else {
1744
		printf("%s: bad port number\n", portp);
1745
		return 0;
1746
	    }
1747
	} 
1748
	else {
1749
	    sn.sin_port = htons(sn.sin_port);
1750
	}
1751
    } 
1752
    else {
1753
    else {
1753
	if (sp == 0) {
1754
	portp = "telnet";
1754
	    sp = getservbyname("telnet", "tcp");
1755
	    if (sp == 0) {
1756
		fprintf(stderr, "telnet: tcp/telnet: unknown service\n");
1757
		return 0;
1758
	    }
1759
	    sn.sin_port = sp->s_port;
1760
	}
1761
	telnetport = 1;
1755
	telnetport = 1;
1762
    }
1756
    }
1763
    printf("Trying %s...\n", inet_ntoa(sn.sin_addr));
1757
1758
    /* We only understand SOCK_STREAM sockets. */
1759
    memset(&hints, 0, sizeof(hints));
1760
    hints.ai_socktype = SOCK_STREAM;
1761
    hints.ai_flags = AI_NUMERICHOST;
1762
    hints.ai_family = family;
1763
1764
    if (srchostp) {
1765
	res = getaddrinfo(srchostp, "0", &hints, &hostaddr);
1766
	if (res) {
1767
	    fprintf(stderr, "telnet: could not resolve %s: %s\n", srchostp,
1768
		    gai_strerror(res));
1769
	    return 0;
1770
	}
1771
	hints.ai_family = hostaddr->ai_family;
1772
	res = nlink.bind(hostaddr);
1773
	freeaddrinfo(hostaddr);
1774
	if (res < 0)
1775
	    return 0;
1776
    }
1777
        
1778
    /* Resolve both the host and service simultaneously. */
1779
    res = getaddrinfo(resolv_hostp, portp, &hints, &hostaddr);
1780
    if (res == EAI_NONAME) {
1781
	hints.ai_flags = AI_CANONNAME;
1782
	res = getaddrinfo(resolv_hostp, portp, &hints, &hostaddr);
1783
    } else if (hostaddr) {
1784
	hostaddr->ai_canonname = 0;
1785
    }
1786
    if (res || !hostaddr) {
1787
	fprintf(stderr, "telnet: could not resolve %s/%s: %s\n", resolv_hostp, portp, gai_strerror(res));
1788
	return 0;
1789
    }
1790
     
1791
    /* Try to connect to every listed round robin IP. */
1792
    tmpaddr = hostaddr;
1793
    errno = 0;
1764
    do {
1794
    do {
1765
	int x = nlink.connect(debug, host, &sn, srp, srlen, tos);
1795
	int x;
1766
	if (!x) return 0;
1796
1767
	else if (x==1) continue;
1797
	if (!tmpaddr) {
1798
	    if (errno)
1799
		perror("telnet: Unable to connect to remote host");
1800
	    else
1801
		fputs("telnet: Unable to connect to remote host: "
1802
		      "Bad port number\n", stderr);
1803
err:
1804
	    freeaddrinfo(hostaddr);
1805
	    return 0;
1806
	}
1807
1808
	if (tmpaddr->ai_family == AF_UNIX) {
1809
nextaddr:
1810
	    tmpaddr = tmpaddr->ai_next;
1811
	    continue;
1812
	}
1813
1814
	getnameinfo(tmpaddr->ai_addr, tmpaddr->ai_addrlen,
1815
		    name, sizeof(name), service, sizeof(service),
1816
		    NI_NUMERICHOST | NI_NUMERICSERV);
1817
1818
	printf("Trying %s...\n", name);
1819
	x = nlink.connect(debug, tmpaddr, srp, srlen, tos);
1820
	if (!x)
1821
	    goto err;
1822
	else if (x==1)
1823
	    goto nextaddr;
1824
1768
	connected++;
1825
	connected++;
1769
    } while (connected == 0);
1826
    } while (connected == 0);
1770
    cmdrc(hostp, hostname);
1827
    if (tmpaddr->ai_canonname == 0) {
1828
	hostname = new char[strlen(hostp)+1];
1829
	strcpy(hostname, hostp);
1830
    }
1831
    else {
1832
	hostname = new char[strlen(tmpaddr->ai_canonname)+1];
1833
	strcpy(hostname, tmpaddr->ai_canonname);
1834
    }
1835
1836
    cmdrc(hostp, hostname, portp);
1837
    freeaddrinfo(hostaddr);
1771
    if (autologin && user == NULL) {
1838
    if (autologin && user == NULL) {
1772
	struct passwd *pw;
1839
	struct passwd *pw;
1773
1840
Lines 2013-2042 Link Here
2013
    return 0;
2080
    return 0;
2014
}
2081
}
2015
2082
2016
static char *rcname = 0;
2083
static void readrc(const char *m1, const char *m2, const char *port,
2017
static char rcbuf[128];
2084
		   const char *rcname)
2018
2085
{
2019
void cmdrc(const char *m1, const char *m2) {
2020
    FILE *rcfile;
2086
    FILE *rcfile;
2021
    int gotmachine = 0;
2087
    int gotmachine = 0;
2022
    int l1 = strlen(m1);
2088
    int l1 = strlen(m1);
2023
    int l2 = strlen(m2);
2089
    int l2 = strlen(m2);
2024
    char m1save[64];
2090
    int lport = strlen(port);
2025
2091
    char m1save[l1 + 1];
2026
    if (skiprc) return;
2092
    char portsave[lport + 1];
2027
2093
2028
    strcpy(m1save, m1);
2094
    strcpy(m1save, m1);
2029
    m1 = m1save;
2095
    m1 = m1save;
2030
2096
    strcpy(portsave, port);
2031
    if (rcname == 0) {
2097
    port = portsave;
2032
	rcname = getenv("HOME");
2033
	if (rcname)
2034
	    strcpy(rcbuf, rcname);
2035
	else
2036
	    rcbuf[0] = '\0';
2037
	strcat(rcbuf, "/.telnetrc");
2038
	rcname = rcbuf;
2039
    }
2040
2098
2041
    rcfile = fopen(rcname, "r");
2099
    rcfile = fopen(rcname, "r");
2042
    if (!rcfile) return;
2100
    if (!rcfile) return;
Lines 2061-2066 Link Here
2061
		strncpy(line, &line[7], sizeof(line) - 7);
2119
		strncpy(line, &line[7], sizeof(line) - 7);
2062
	    else
2120
	    else
2063
		continue;
2121
		continue;
2122
2123
	    if (line[0] == ':') {
2124
		if (!strncasecmp(&line[1], port, lport))
2125
		    continue;
2126
		strncpy(line, &line[lport + 1], sizeof(line) - lport - 1);
2127
	    }
2128
2064
	    if (line[0] != ' ' && line[0] != '\t' && line[0] != '\n')
2129
	    if (line[0] != ' ' && line[0] != '\t' && line[0] != '\n')
2065
		continue;
2130
		continue;
2066
	    gotmachine = 1;
2131
	    gotmachine = 1;
Lines 2073-2078 Link Here
2073
    fclose(rcfile);
2138
    fclose(rcfile);
2074
}
2139
}
2075
2140
2141
void cmdrc(const char *m1, const char *m2, const char *port) {
2142
    char *rcname = NULL;
2143
2144
    if (skiprc) return;
2145
2146
    readrc(m1, m2, port, "/etc/telnetrc");
2147
    if (asprintf (&rcname, "%s/.telnetrc", getenv ("HOME")) == -1)
2148
      {
2149
        perror ("asprintf");
2150
        return;
2151
      }
2152
    readrc(m1, m2, port, rcname);
2153
    free (rcname);
2154
}
2155
2076
#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
2156
#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
2077
2157
2078
/*
2158
/*
(-)./netkit-telnet-0.17/telnet/defines.h (+2 lines)
Lines 50-52 Link Here
50
#define	MODE_COMMAND_LINE(m)	((m)==-1)
50
#define	MODE_COMMAND_LINE(m)	((m)==-1)
51
51
52
#define	CONTROL(x)	((x)&0x1f)		/* CTRL(x) is not portable */
52
#define	CONTROL(x)	((x)&0x1f)		/* CTRL(x) is not portable */
53
54
#define MODE_OUT8	0x8000			/* binary mode sans -opost */
(-)./netkit-telnet-0.17/telnet/externs.h (-3 / +4 lines)
Lines 48-56 Link Here
48
typedef unsigned char cc_t;
48
typedef unsigned char cc_t;
49
#endif
49
#endif
50
50
51
#ifdef __linux__
52
#include <unistd.h>   /* get _POSIX_VDISABLE */
51
#include <unistd.h>   /* get _POSIX_VDISABLE */
53
#endif
54
52
55
#ifndef	_POSIX_VDISABLE
53
#ifndef	_POSIX_VDISABLE
56
#error "Please fix externs.h to define _POSIX_VDISABLE"
54
#error "Please fix externs.h to define _POSIX_VDISABLE"
Lines 60-66 Link Here
60
58
61
extern int autologin;		/* Autologin enabled */
59
extern int autologin;		/* Autologin enabled */
62
extern int skiprc;		/* Don't process the ~/.telnetrc file */
60
extern int skiprc;		/* Don't process the ~/.telnetrc file */
63
extern int eight;		/* use eight bit mode (binary in and/or out */
61
extern int eight;		/* use eight bit mode (binary in and/or out) */
62
extern int binary;		/* use binary option (in and/or out) */
64
extern int flushout;		/* flush output */
63
extern int flushout;		/* flush output */
65
extern int connected;		/* Are we connected to the other side? */
64
extern int connected;		/* Are we connected to the other side? */
66
extern int globalmode;		/* Mode tty should be in */
65
extern int globalmode;		/* Mode tty should be in */
Lines 225-230 Link Here
225
224
226
//#if 0
225
//#if 0
227
extern struct termios new_tc;
226
extern struct termios new_tc;
227
extern struct termios old_tc;
228
228
229
229
#define termEofChar		new_tc.c_cc[VEOF]
230
#define termEofChar		new_tc.c_cc[VEOF]
230
#define termEraseChar		new_tc.c_cc[VERASE]
231
#define termEraseChar		new_tc.c_cc[VERASE]
(-)./netkit-telnet-0.17/telnet/main.cc (-15 / +50 lines)
Lines 45-51 Link Here
45
45
46
#include <sys/types.h>
46
#include <sys/types.h>
47
#include <getopt.h>
47
#include <getopt.h>
48
#include <stdlib.h>
48
#include <string.h>
49
#include <string.h>
50
#include <netdb.h>
51
#include <errno.h>
49
52
50
#include "ring.h"
53
#include "ring.h"
51
#include "externs.h"
54
#include "externs.h"
Lines 80-91 Link Here
80
void usage(void) {
83
void usage(void) {
81
    fprintf(stderr, "Usage: %s %s%s%s%s\n",
84
    fprintf(stderr, "Usage: %s %s%s%s%s\n",
82
	    prompt,
85
	    prompt,
83
	    " [-8] [-E] [-L] [-a] [-d] [-e char] [-l user] [-n tracefile]",
86
	    "[-4] [-6] [-8] [-E] [-L] [-a] [-d] [-e char] [-l user]",
84
	    "\n\t",
87
	    "\n\t[-n tracefile] [ -b addr ]",
85
#ifdef TN3270
88
#ifdef TN3270
89
	    "\n\t"
86
	    "[-noasynch] [-noasynctty] [-noasyncnet] [-r] [-t transcom]\n\t",
90
	    "[-noasynch] [-noasynctty] [-noasyncnet] [-r] [-t transcom]\n\t",
87
#else
91
#else
88
	    "[-r] ",
92
	    " [-r] ",
89
#endif
93
#endif
90
	    "[host-name [port]]"
94
	    "[host-name [port]]"
91
	);
95
	);
Lines 102-108 Link Here
102
	extern char *optarg;
106
	extern char *optarg;
103
	extern int optind;
107
	extern int optind;
104
	int ch;
108
	int ch;
105
	char *user;
109
	char *user, *srcaddr;
110
	int family;
106
111
107
	tninit();		/* Clear out things */
112
	tninit();		/* Clear out things */
108
#if	defined(CRAY) && !defined(__STDC__)
113
#if	defined(CRAY) && !defined(__STDC__)
Lines 110-130 Link Here
110
#endif
115
#endif
111
116
112
	TerminalSaveState();
117
	TerminalSaveState();
118
	if ((old_tc.c_cflag & (CSIZE|PARENB)) != CS8)
119
		eight = 0;
113
120
114
	if ((prompt = strrchr(argv[0], '/'))!=NULL)
121
	if ((prompt = strrchr(argv[0], '/'))!=NULL)
115
		++prompt;
122
		++prompt;
116
	else
123
	else
117
		prompt = argv[0];
124
		prompt = argv[0];
118
125
119
	user = NULL;
126
	user = srcaddr = NULL;
127
	family = 0;
120
128
121
	rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
129
	rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
122
	autologin = -1;
130
	autologin = -1;
123
131
124
	while ((ch = getopt(argc, argv, "8EKLS:X:ade:k:l:n:rt:x")) != EOF) {
132
	while ((ch = getopt(argc, argv,
133
			    "4678EKLS:X:ab:de:k:l:n:rt:x")) != EOF) {
125
		switch(ch) {
134
		switch(ch) {
135
		case '4':
136
			family = AF_INET;
137
			break;
138
		case '6':
139
#ifdef AF_INET6
140
			family = AF_INET6;
141
#else
142
			fputs("IPv6 unsupported\n", stderr);
143
#endif
144
			break;
145
		case '7':
146
			eight = 0;	/* 7-bit ouput and input */
147
			break;
126
		case '8':
148
		case '8':
127
			eight = 3;	/* binary output and input */
149
			binary = 3;	/* binary output and input */
128
			break;
150
			break;
129
		case 'E':
151
		case 'E':
130
			rlogin = escapechar = _POSIX_VDISABLE;
152
			rlogin = escapechar = _POSIX_VDISABLE;
Lines 133-155 Link Here
133
		        //autologin = 0;
155
		        //autologin = 0;
134
			break;
156
			break;
135
		case 'L':
157
		case 'L':
136
			eight |= 2;	/* binary output only */
158
			binary |= 2;	/* binary output only */
137
			break;
159
			break;
138
		case 'S':
160
		case 'S':
139
		    {
161
		    {
140
#ifdef	HAS_GETTOS
141
			extern int tos;
162
			extern int tos;
163
			int num;
142
164
143
			if ((tos = parsetos(optarg, "tcp")) < 0)
165
#ifdef	HAS_GETTOS
166
			if ((num = parsetos(optarg, "tcp")) < 0) {
167
#else
168
			errno = 0;
169
			num = strtol(optarg, 0, 0);
170
			if (errno) {
171
#endif
144
				fprintf(stderr, "%s%s%s%s\n",
172
				fprintf(stderr, "%s%s%s%s\n",
145
					prompt, ": Bad TOS argument '",
173
					prompt, ": Bad TOS argument '",
146
					optarg,
174
					optarg,
147
					"; will try to use default TOS");
175
					"; will try to use default TOS");
148
#else
176
			} else
149
			fprintf(stderr,
177
				tos = num;
150
			   "%s: Warning: -S ignored, no parsetos() support.\n",
151
								prompt);
152
#endif
153
		    }
178
		    }
154
			break;
179
			break;
155
		case 'X':
180
		case 'X':
Lines 210-215 Link Here
210
				"%s: -x ignored, no encryption support.\n",
235
				"%s: -x ignored, no encryption support.\n",
211
				prompt);
236
				prompt);
212
			break;
237
			break;
238
		case 'b':
239
			srcaddr = optarg;
240
			break;
213
		case '?':
241
		case '?':
214
		default:
242
		default:
215
			usage();
243
			usage();
Lines 233-238 Link Here
233
			*argp++ = "-l";
261
			*argp++ = "-l";
234
			*argp++ = user;
262
			*argp++ = user;
235
		}
263
		}
264
		if (srcaddr) {
265
			*argp++ = "-b";
266
			*argp++ = srcaddr;
267
		}
268
		if (family) {
269
			*argp++ = family == AF_INET ? "-4" : "-6";
270
		}
236
		*argp++ = argv[0];		/* host */
271
		*argp++ = argv[0];		/* host */
237
		if (argc > 1)
272
		if (argc > 1)
238
			*argp++ = argv[1];	/* port */
273
			*argp++ = argv[1];	/* port */
(-)./netkit-telnet-0.17/telnet/netlink.cc (-29 / +49 lines)
Lines 79-100 Link Here
79
	shutdown(net, 2);
79
	shutdown(net, 2);
80
    }
80
    }
81
    ::close(net);
81
    ::close(net);
82
    net = -1;
82
}
83
}
83
84
84
int netlink::connect(int debug, struct hostent *host, 
85
int netlink::bind(struct addrinfo *addr)
85
		     struct sockaddr_in *sn, 
86
		     char *srcroute, int srlen, int tos) 
87
{
86
{
88
    int on=1;
87
    int res;
88
89
    res = socket(addr->ai_family);
90
    if (res < 2) {
91
	if (res == 1)
92
	    perror("telnet: socket");
93
	return -1;
94
    }
95
96
    if (::bind(net, addr->ai_addr, addr->ai_addrlen) < 0) {
97
	perror("telnet: bind");
98
	return -1;
99
    }
100
101
    return 0;
102
}
103
104
int netlink::socket(int family)
105
{
106
    if (this->family != family)
107
	close(0);
89
108
90
    net = socket(AF_INET, SOCK_STREAM, 0);
91
    if (net < 0) {
109
    if (net < 0) {
92
	perror("telnet: socket");
110
	this->family = family;
93
	return 0;
111
	net = ::socket(family, SOCK_STREAM, 0);
112
	if (net < 0) {
113
	    if (errno == EAFNOSUPPORT)
114
		return 1;
115
	    perror("telnet: socket");
116
	    return 0;
117
	}
94
    }
118
    }
95
119
120
    return 2;
121
}
122
123
int netlink::connect(int debug, struct addrinfo *addr, 
124
		     char *srcroute, int srlen, int tos) 
125
{
126
    int on=1;
127
    int res;
128
129
    res = socket(addr->ai_family);
130
    if (res < 2)
131
	return res;
132
96
#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
133
#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
97
    if (srcroute) {
134
    if (srcroute) {
135
	if (addr->ai_family != AF_INET)
136
	    fputs("Source route is only supported for IPv4\n", stderr);
98
	if (setsockopt(net, IPPROTO_IP, IP_OPTIONS, srcroute, srlen) < 0)
137
	if (setsockopt(net, IPPROTO_IP, IP_OPTIONS, srcroute, srlen) < 0)
99
	    perror("setsockopt (IP_OPTIONS)");
138
	    perror("setsockopt (IP_OPTIONS)");
100
    }
139
    }
Lines 108-114 Link Here
108
#endif
147
#endif
109
    if (tos < 0) tos = 020;	/* Low Delay bit */
148
    if (tos < 0) tos = 020;	/* Low Delay bit */
110
    if (tos && (setsockopt(net, IPPROTO_IP, IP_TOS, &tos, sizeof(int)) < 0)
149
    if (tos && (setsockopt(net, IPPROTO_IP, IP_TOS, &tos, sizeof(int)) < 0)
111
	&& (errno != ENOPROTOOPT))
150
	&& (errno != ENOPROTOOPT) && (errno != EOPNOTSUPP))
112
	perror("telnet: setsockopt (IP_TOS) (ignored)");
151
	perror("telnet: setsockopt (IP_TOS) (ignored)");
113
#endif	/* defined(IPPROTO_IP) && defined(IP_TOS) */
152
#endif	/* defined(IPPROTO_IP) && defined(IP_TOS) */
114
153
Lines 116-142 Link Here
116
	perror("setsockopt (SO_DEBUG)");
155
	perror("setsockopt (SO_DEBUG)");
117
    }
156
    }
118
    
157
    
119
    if (::connect(net, (struct sockaddr *)sn, sizeof(*sn)) < 0) {
158
    if (::connect(net, addr->ai_addr, addr->ai_addrlen) < 0) {
120
#if defined(h_addr)		/* In 4.3, this is a #define */
159
	return 1;
121
	if (host && host->h_addr_list[1]) {
122
	    int oerrno = errno;
123
	    
124
	    fprintf(stderr, "telnet: connect to address %s: ",
125
		    inet_ntoa(sn->sin_addr));
126
	    errno = oerrno;
127
	    perror(NULL);
128
	    host->h_addr_list++;
129
	    if (host->h_length > (int)sizeof(sn->sin_addr)) {
130
		host->h_length = sizeof(sn->sin_addr);
131
	    }
132
	    memcpy(&sn->sin_addr, host->h_addr_list[0], host->h_length);
133
	    close(net);
134
	    return 1;
135
	}
136
#endif	/* defined(h_addr) */
137
138
	perror("telnet: Unable to connect to remote host");
139
	return 0;
140
    }
160
    }
141
    return 2;
161
    return 2;
142
}
162
}
(-)./netkit-telnet-0.17/telnet/netlink.h (-2 / +5 lines)
Lines 1-13 Link Here
1
1
2
class netlink {
2
class netlink {
3
 private:
4
    int family;
3
 protected:
5
 protected:
4
    int net;
6
    int net;
5
 public:
7
 public:
6
    netlink();
8
    netlink();
7
    ~netlink();
9
    ~netlink();
8
10
9
    int connect(int debug, struct hostent *host, 
11
    int bind(struct addrinfo *hostaddr);
10
		struct sockaddr_in *sin, 
12
    int socket(int family);
13
    int connect(int debug, struct addrinfo *hostaddr, 
11
		char *srcroute, int srlen,
14
		char *srcroute, int srlen,
12
		int tos);
15
		int tos);
13
    void close(int doshutdown);
16
    void close(int doshutdown);
(-)./netkit-telnet-0.17/telnet/network.cc (+1 lines)
Lines 40-45 Link Here
40
#include <sys/types.h>
40
#include <sys/types.h>
41
#include <sys/socket.h>
41
#include <sys/socket.h>
42
#include <sys/time.h>
42
#include <sys/time.h>
43
#include <stdlib.h>
43
#include <errno.h>
44
#include <errno.h>
44
#include <arpa/telnet.h>
45
#include <arpa/telnet.h>
45
46
(-)./netkit-telnet-0.17/telnet/proto.h (-1 / +1 lines)
Lines 13-19 Link Here
13
void auth_encrypt_user(char *);
13
void auth_encrypt_user(char *);
14
void auth_name(unsigned char *, int);
14
void auth_name(unsigned char *, int);
15
void auth_printsub(unsigned char *, int, unsigned char *, int);
15
void auth_printsub(unsigned char *, int, unsigned char *, int);
16
void cmdrc(const char *m1, const char *m2);
16
void cmdrc(const char *, const char *, const char *);
17
void env_init(void);
17
void env_init(void);
18
int getconnmode(void);
18
int getconnmode(void);
19
void init_network(void);
19
void init_network(void);
(-)./netkit-telnet-0.17/telnet/ring.cc (-1 / +1 lines)
Lines 165-171 Link Here
165
165
166
/////////////////////////////////////////////////// supply //////////////
166
/////////////////////////////////////////////////// supply //////////////
167
167
168
void ringbuf::printf(const char *format, ...) {
168
void ringbuf::xprintf(const char *format, ...) {
169
    char xbuf[256];
169
    char xbuf[256];
170
    va_list ap;
170
    va_list ap;
171
    va_start(ap, format);
171
    va_start(ap, format);
(-)./netkit-telnet-0.17/telnet/ring.h (-1 / +1 lines)
Lines 83-89 Link Here
83
    // manual supply
83
    // manual supply
84
    void putch(char c) { write(&c, 1); }
84
    void putch(char c) { write(&c, 1); }
85
    void write(const char *buffer, int ct);
85
    void write(const char *buffer, int ct);
86
    void printf(const char *format, ...);
86
    void xprintf(const char *format, ...);
87
    int empty_count() { return size - count; }
87
    int empty_count() { return size - count; }
88
88
89
    // automatic supply
89
    // automatic supply
(-)./netkit-telnet-0.17/telnet/sys_bsd.cc (+11 lines)
Lines 189-206 Link Here
189
 * Various signal handling routines.
189
 * Various signal handling routines.
190
 */
190
 */
191
191
192
#if 0
192
static void deadpeer(int /*sig*/) {
193
static void deadpeer(int /*sig*/) {
193
    setcommandmode();
194
    setcommandmode();
194
    siglongjmp(peerdied, -1);
195
    siglongjmp(peerdied, -1);
195
}
196
}
197
#endif
196
198
197
static void intr(int /*sig*/) {
199
static void intr(int /*sig*/) {
198
    if (localchars) {
200
    if (localchars) {
199
	intp();
201
	intp();
200
    }
202
    }
201
    else {
203
    else {
204
#if 0
202
        setcommandmode();
205
        setcommandmode();
203
	siglongjmp(toplevel, -1);
206
	siglongjmp(toplevel, -1);
207
#else
208
	signal(SIGINT, SIG_DFL);
209
	raise(SIGINT);
210
#endif
204
    }
211
    }
205
}
212
}
206
213
Lines 214-219 Link Here
214
	    sendabort();
221
	    sendabort();
215
	return;
222
	return;
216
    }
223
    }
224
    signal(SIGQUIT, SIG_DFL);
225
    raise(SIGQUIT);
217
}
226
}
218
227
219
#ifdef	SIGWINCH
228
#ifdef	SIGWINCH
Lines 238-244 Link Here
238
void sys_telnet_init(void) {
247
void sys_telnet_init(void) {
239
    signal(SIGINT, intr);
248
    signal(SIGINT, intr);
240
    signal(SIGQUIT, intr2);
249
    signal(SIGQUIT, intr2);
250
#if 0
241
    signal(SIGPIPE, deadpeer);
251
    signal(SIGPIPE, deadpeer);
252
#endif
242
#ifdef	SIGWINCH
253
#ifdef	SIGWINCH
243
    signal(SIGWINCH, sendwin);
254
    signal(SIGWINCH, sendwin);
244
#endif
255
#endif
(-)./netkit-telnet-0.17/telnet/telnet.1 (-9 / +28 lines)
Lines 42-49 Link Here
42
protocol
42
protocol
43
.Sh SYNOPSIS
43
.Sh SYNOPSIS
44
.Nm telnet
44
.Nm telnet
45
.Op Fl 8ELadr
45
.Op Fl 468ELadr
46
.Op Fl S Ar tos
46
.Op Fl S Ar tos
47
.Op Fl b Ar address
47
.Op Fl e Ar escapechar
48
.Op Fl e Ar escapechar
48
.Op Fl l Ar user
49
.Op Fl l Ar user
49
.Op Fl n Ar tracefile
50
.Op Fl n Ar tracefile
Lines 68-73 Link Here
68
.Pp
69
.Pp
69
Options:
70
Options:
70
.Bl -tag -width indent
71
.Bl -tag -width indent
72
.It Fl 4
73
Force IPv4 address resolution.
74
.It Fl 6
75
Force IPv6 address resolution.
71
.It Fl 8
76
.It Fl 8
72
Request 8-bit operation. This causes an attempt to negotiate the
77
Request 8-bit operation. This causes an attempt to negotiate the
73
.Dv TELNET BINARY
78
.Dv TELNET BINARY
Lines 89-94 Link Here
89
option if supported by the remote system. The username is retrieved
94
option if supported by the remote system. The username is retrieved
90
via
95
via
91
.Xr getlogin 3 .
96
.Xr getlogin 3 .
97
.It Fl b Ar address
98
Use bind(2) on the local socket to bind it to a specific local address.
92
.It Fl d
99
.It Fl d
93
Sets the initial value of the
100
Sets the initial value of the
94
.Ic debug
101
.Ic debug
Lines 474-490 Link Here
474
placing a dash before the port number.
481
placing a dash before the port number.
475
.Pp
482
.Pp
476
After establishing a connection, any commands associated with the
483
After establishing a connection, any commands associated with the
477
remote host in the user's
484
remote host in
485
.Pa /etc/telnetrc
486
and the user's
478
.Pa .telnetrc
487
.Pa .telnetrc
479
file are executed.
488
file are executed, in that order.
480
.Pp
489
.Pp
481
The format of the .telnetrc file is as follows: Lines beginning with a
490
The format of the telnetrc files is as follows: Lines beginning with a
482
#, and blank lines, are ignored.  The rest of the file should consist
491
#, and blank lines, are ignored.  The rest of the file should consist
483
of hostnames and sequences of
492
of hostnames and sequences of
484
.Nm telnet
493
.Nm telnet
485
commands to use with that host. Commands should be one per line,
494
commands to use with that host. Commands should be one per line,
486
indented by whitespace; lines beginning without whitespace are
495
indented by whitespace; lines beginning without whitespace are
487
interpreted as hostnames. Upon connecting to a particular host, the
496
interpreted as hostnames.  Lines beginning with the special hostname
497
.Ql DEFAULT
498
will apply to all hosts.  Hostnames including
499
.Ql DEFAULT
500
may be followed immediately by a colon and a port number or string.
501
If a port is specified it must match exactly with what is specified
502
on the command line.  If no port was specified on the command line,
503
then the value
504
.Ql telnet
505
is used.
506
Upon connecting to a particular host, the
488
commands associated with that host are executed.
507
commands associated with that host are executed.
489
.It Ic quit
508
.It Ic quit
490
Close any open session and exit
509
Close any open session and exit
Lines 1184-1192 Link Here
1184
When the skiprc toggle is
1203
When the skiprc toggle is
1185
.Dv TRUE ,
1204
.Dv TRUE ,
1186
.Tn telnet
1205
.Tn telnet
1187
does not read the 
1206
does not read the telnetrc files.  The initial value for this toggle is
1188
.Pa \&.telnetrc
1189
file.  The initial value for this toggle is
1190
.Dv FALSE.
1207
.Dv FALSE.
1191
.It Ic termdata
1208
.It Ic termdata
1192
Toggles the display of all terminal data (in hexadecimal format).
1209
Toggles the display of all terminal data (in hexadecimal format).
Lines 1239-1245 Link Here
1239
.Dv TELNET ENVIRON
1256
.Dv TELNET ENVIRON
1240
option.
1257
option.
1241
.Sh FILES
1258
.Sh FILES
1242
.Bl -tag -width ~/.telnetrc -compact
1259
.Bl -tag -width /etc/telnetrc -compact
1260
.It Pa /etc/telnetrc
1261
global telnet startup values
1243
.It Pa ~/.telnetrc
1262
.It Pa ~/.telnetrc
1244
user customized telnet startup values
1263
user customized telnet startup values
1245
.El
1264
.El
(-)./netkit-telnet-0.17/telnet/telnet.cc (-15 / +19 lines)
Lines 88-94 Link Here
88
char	will_wont_resp[256];
88
char	will_wont_resp[256];
89
89
90
int
90
int
91
eight = 0,
91
  eight = 3,
92
  binary = 0,
92
  autologin = 0,	/* Autologin anyone? */
93
  autologin = 0,	/* Autologin anyone? */
93
  skiprc = 0,
94
  skiprc = 0,
94
  connected,
95
  connected,
Lines 646-652 Link Here
646
    mklist(termbuf, tname, termtypes);
647
    mklist(termbuf, tname, termtypes);
647
    next = 0;
648
    next = 0;
648
  }
649
  }
649
  if (next==termtypes.num()) next = 0;
650
  if (next==termtypes.num()-1) next = 0;
650
  return termtypes[next++];
651
  return termtypes[next++];
651
}
652
}
652
/*
653
/*
Lines 681-687 Link Here
681
      }
682
      }
682
#endif /* TN3270 */
683
#endif /* TN3270 */
683
      name = gettermname();
684
      name = gettermname();
684
      netoring.printf("%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
685
      netoring.xprintf("%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
685
		      TELQUAL_IS, name, IAC, SE);
686
		      TELQUAL_IS, name, IAC, SE);
686
    }
687
    }
687
    break;
688
    break;
Lines 693-699 Link Here
693
    if (SB_GET() == TELQUAL_SEND) {
694
    if (SB_GET() == TELQUAL_SEND) {
694
      long oospeed, iispeed;
695
      long oospeed, iispeed;
695
      TerminalSpeeds(&iispeed, &oospeed);
696
      TerminalSpeeds(&iispeed, &oospeed);
696
      netoring.printf("%c%c%c%c%ld,%ld%c%c", IAC, SB, TELOPT_TSPEED, 
697
      netoring.xprintf("%c%c%c%c%ld,%ld%c%c", IAC, SB, TELOPT_TSPEED, 
697
		      TELQUAL_IS, oospeed, iispeed, IAC, SE);
698
		      TELQUAL_IS, oospeed, iispeed, IAC, SE);
698
    }
699
    }
699
    break;
700
    break;
Lines 780-786 Link Here
780
	send_wont(TELOPT_XDISPLOC, 1);
781
	send_wont(TELOPT_XDISPLOC, 1);
781
	break;
782
	break;
782
      }
783
      }
783
      netoring.printf("%c%c%c%c%s%c%c", IAC, SB, TELOPT_XDISPLOC,
784
      netoring.xprintf("%c%c%c%c%s%c%c", IAC, SB, TELOPT_XDISPLOC,
784
		      TELQUAL_IS, dp, IAC, SE);
785
		      TELQUAL_IS, dp, IAC, SE);
785
    }
786
    }
786
    break;
787
    break;
Lines 798-804 Link Here
798
    return;
799
    return;
799
  }
800
  }
800
  
801
  
801
  netoring.printf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, 
802
  netoring.xprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, 
802
		  DONT, cmd[0], IAC, SE);
803
		  DONT, cmd[0], IAC, SE);
803
}
804
}
804
805
Lines 815-821 Link Here
815
    /*@*/	printf("lm_do: no command!!!\n");	/* Should not happen... */
816
    /*@*/	printf("lm_do: no command!!!\n");	/* Should not happen... */
816
    return;
817
    return;
817
  }
818
  }
818
  netoring.printf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, 
819
  netoring.xprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, 
819
		  WONT, cmd[0], IAC, SE);
820
		  WONT, cmd[0], IAC, SE);
820
}
821
}
821
822
Lines 838-844 Link Here
838
    k |= MODE_ACK;
839
    k |= MODE_ACK;
839
  }
840
  }
840
  
841
  
841
  netoring.printf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE,
842
  netoring.xprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE,
842
		  k, IAC, SE);
843
		  k, IAC, SE);
843
  
844
  
844
  setconnmode(0);	/* set changed mode */
845
  setconnmode(0);	/* set changed mode */
Lines 933-943 Link Here
933
934
934
void slc_import(int def) {
935
void slc_import(int def) {
935
  if (def) {
936
  if (def) {
936
    netoring.printf("%c%c%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
937
    netoring.xprintf("%c%c%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
937
		    LM_SLC, 0, SLC_DEFAULT, 0, IAC, SE);
938
		    LM_SLC, 0, SLC_DEFAULT, 0, IAC, SE);
938
  }
939
  }
939
  else {
940
  else {
940
    netoring.printf("%c%c%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
941
    netoring.xprintf("%c%c%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
941
		    LM_SLC, 0, SLC_VARIABLE, 0, IAC, SE);
942
		    LM_SLC, 0, SLC_VARIABLE, 0, IAC, SE);
942
  }
943
  }
943
}
944
}
Lines 1142-1147 Link Here
1142
  }
1143
  }
1143
}
1144
}
1144
1145
1146
/* OPT_REPLY_SIZE must be a multiple of 2. */
1145
#define	OPT_REPLY_SIZE	256
1147
#define	OPT_REPLY_SIZE	256
1146
unsigned char *opt_reply;
1148
unsigned char *opt_reply;
1147
unsigned char *opt_replyp;
1149
unsigned char *opt_replyp;
Lines 1173-1178 Link Here
1173
1175
1174
void env_opt_add(const char *ep) {
1176
void env_opt_add(const char *ep) {
1175
  const char *vp;
1177
  const char *vp;
1178
  const unsigned char *tp;
1176
  unsigned char c;
1179
  unsigned char c;
1177
  
1180
  
1178
  if (opt_reply == NULL)		/*XXX*/
1181
  if (opt_reply == NULL)		/*XXX*/
Lines 1185-1195 Link Here
1185
    return;
1188
    return;
1186
  }
1189
  }
1187
  vp = env_getvalue(ep, 1);
1190
  vp = env_getvalue(ep, 1);
1188
  if (opt_replyp + (vp ? strlen(vp) : 0) + strlen(ep) + 6 > opt_replyend)
1191
  tp = opt_replyp + (vp ? strlen(vp) * 2 : 0) + strlen(ep) * 2 + 6;
1192
  if (tp > opt_replyend)
1189
    {
1193
    {
1190
      register int len;
1194
      register int len;
1191
      opt_replyend += OPT_REPLY_SIZE;
1195
      len = ((tp - opt_reply) + OPT_REPLY_SIZE - 1) & ~(OPT_REPLY_SIZE - 1);
1192
      len = opt_replyend - opt_reply;
1196
      opt_replyend = opt_reply + len;
1193
      opt_reply = (unsigned char *)realloc(opt_reply, len);
1197
      opt_reply = (unsigned char *)realloc(opt_reply, len);
1194
      if (opt_reply == NULL) {
1198
      if (opt_reply == NULL) {
1195
	/*@*/			printf("env_opt_add: realloc() failed!!!\n");
1199
	/*@*/			printf("env_opt_add: realloc() failed!!!\n");
Lines 1740-1747 Link Here
1740
    send_do(TELOPT_STATUS, 1);
1744
    send_do(TELOPT_STATUS, 1);
1741
    if (env_getvalue("DISPLAY", 0))
1745
    if (env_getvalue("DISPLAY", 0))
1742
      send_will(TELOPT_XDISPLOC, 1);
1746
      send_will(TELOPT_XDISPLOC, 1);
1743
    if (eight)
1747
    if (binary)
1744
      tel_enter_binary(eight);
1748
      tel_enter_binary(binary);
1745
  }
1749
  }
1746
#endif /* !defined(TN3270) */
1750
#endif /* !defined(TN3270) */
1747
  
1751
  
(-)./netkit-telnet-0.17/telnet/terminal.cc (-5 / +12 lines)
Lines 45-50 Link Here
45
#include <signal.h>
45
#include <signal.h>
46
#include <errno.h>
46
#include <errno.h>
47
#include <stdio.h>
47
#include <stdio.h>
48
#include <string.h>
49
#include <stdlib.h>
48
50
49
#include "ring.h"
51
#include "ring.h"
50
#include "defines.h"
52
#include "defines.h"
Lines 155-163 Link Here
155
    if (localflow)
157
    if (localflow)
156
	mode |= MODE_FLOW;
158
	mode |= MODE_FLOW;
157
159
158
    if (my_want_state_is_will(TELOPT_BINARY))
160
    if ((eight & 1) || my_want_state_is_will(TELOPT_BINARY))
159
	mode |= MODE_INBIN;
161
	mode |= MODE_INBIN;
160
162
163
    if (eight & 2)
164
	mode |= MODE_OUT8;
161
    if (his_want_state_is_will(TELOPT_BINARY))
165
    if (his_want_state_is_will(TELOPT_BINARY))
162
	mode |= MODE_OUTBIN;
166
	mode |= MODE_OUTBIN;
163
167
Lines 449-458 Link Here
449
		// breaks SunOS.
453
		// breaks SunOS.
450
	 	tmp_tc.c_iflag |= ISTRIP;
454
	 	tmp_tc.c_iflag |= ISTRIP;
451
	}
455
	}
452
	if (f & MODE_OUTBIN) {
456
	if (f & (MODE_OUTBIN|MODE_OUT8)) {
453
		tmp_tc.c_cflag &= ~(CSIZE|PARENB);
457
		tmp_tc.c_cflag &= ~(CSIZE|PARENB);
454
		tmp_tc.c_cflag |= CS8;
458
		tmp_tc.c_cflag |= CS8;
455
		tmp_tc.c_oflag &= ~OPOST;
459
		if (f & MODE_OUTBIN)
460
			tmp_tc.c_oflag &= ~OPOST;
461
		else
462
			tmp_tc.c_oflag |= OPOST;
456
	} else {
463
	} else {
457
		tmp_tc.c_cflag &= ~(CSIZE|PARENB);
464
		tmp_tc.c_cflag &= ~(CSIZE|PARENB);
458
		tmp_tc.c_cflag |= old_tc.c_cflag & (CSIZE|PARENB);
465
		tmp_tc.c_cflag |= old_tc.c_cflag & (CSIZE|PARENB);
Lines 468-474 Link Here
468
475
469
#ifdef	SIGINFO
476
#ifdef	SIGINFO
470
	signal(SIGINFO, ayt);
477
	signal(SIGINFO, ayt);
471
#endif	SIGINFO
478
#endif	/* SIGINFO */
472
479
473
#if defined(NOKERNINFO)
480
#if defined(NOKERNINFO)
474
	tmp_tc.c_lflag |= NOKERNINFO;
481
	tmp_tc.c_lflag |= NOKERNINFO;
Lines 504-510 Link Here
504
511
505
#ifdef	SIGINFO
512
#ifdef	SIGINFO
506
	signal(SIGINFO, ayt_status);
513
	signal(SIGINFO, ayt_status);
507
#endif	SIGINFO
514
#endif	/* SIGINFO */
508
515
509
#ifdef	SIGTSTP
516
#ifdef	SIGTSTP
510
	signal(SIGTSTP, SIG_DFL);
517
	signal(SIGTSTP, SIG_DFL);
(-)./netkit-telnet-0.17/telnet/utilities.cc (+2 lines)
Lines 47-52 Link Here
47
#include <sys/socket.h>
47
#include <sys/socket.h>
48
#include <unistd.h>
48
#include <unistd.h>
49
#include <ctype.h>
49
#include <ctype.h>
50
#include <string.h>
51
#include <stdlib.h>
50
52
51
#include "ring.h"
53
#include "ring.h"
52
#include "defines.h"
54
#include "defines.h"
(-)./netkit-telnet-0.17/telnetd/Makefile (-1 / +2 lines)
Lines 9-15 Link Here
9
# take out -DPARANOID_TTYS.
9
# take out -DPARANOID_TTYS.
10
10
11
CFLAGS += '-DISSUE_FILE="/etc/issue.net"' -DPARANOID_TTYS \
11
CFLAGS += '-DISSUE_FILE="/etc/issue.net"' -DPARANOID_TTYS \
12
	   -DNO_REVOKE -DKLUDGELINEMODE -DDIAGNOSTICS
12
	   -DNO_REVOKE -DKLUDGELINEMODE -DDIAGNOSTICS \
13
	   -DLOGIN_WRAPPER=\"/usr/lib/telnetlogin\"
13
# LIBS += $(LIBTERMCAP)
14
# LIBS += $(LIBTERMCAP)
14
15
15
OBJS = telnetd.o state.o termstat.o slc.o sys_term.o utility.o \
16
OBJS = telnetd.o state.o termstat.o slc.o sys_term.o utility.o \
(-)./netkit-telnet-0.17/telnetd/authenc.c (-12 lines)
Lines 42-59 Link Here
42
    return(0);
42
    return(0);
43
}
43
}
44
44
45
void
46
net_encrypt()
47
{
48
#if	defined(ENCRYPT)
49
    char *s = (nclearto > nbackp) ? nclearto : nbackp;
50
    if (s < nfrontp && encrypt_output) {
51
	(*encrypt_output)((unsigned char *)s, nfrontp - s);
52
    }
53
    nclearto = nfrontp;
54
#endif
55
}
56
57
int
45
int
58
telnet_spin()
46
telnet_spin()
59
{
47
{
(-)./netkit-telnet-0.17/telnetd/defs.h (-1 / +2 lines)
Lines 55-64 Link Here
55
#include <fcntl.h>
55
#include <fcntl.h>
56
#include <sys/file.h>
56
#include <sys/file.h>
57
#include <sys/stat.h>
57
#include <sys/stat.h>
58
#include <sys/time.h>
58
#include <time.h>
59
#include <sys/ioctl.h>
59
#include <sys/ioctl.h>
60
#include <netinet/in.h>
60
#include <netinet/in.h>
61
#include <arpa/telnet.h>
61
#include <arpa/telnet.h>
62
#include <sys/uio.h>
62
#include <stdio.h>
63
#include <stdio.h>
63
#include <stdlib.h>
64
#include <stdlib.h>
64
#include <signal.h>
65
#include <signal.h>
(-)./netkit-telnet-0.17/telnetd/ext.h (-9 / +11 lines)
Lines 81-102 Link Here
81
 */
81
 */
82
extern char ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
82
extern char ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
83
extern char netibuf[BUFSIZ], *netip;
83
extern char netibuf[BUFSIZ], *netip;
84
extern char netobuf[BUFSIZ+NETSLOP], *nfrontp, *nbackp;
85
extern char *neturg;		/* one past last byte of urgent data */
86
extern int pcc, ncc;
84
extern int pcc, ncc;
85
extern FILE *netfile;
87
86
88
/* printf into netobuf */
87
/* printf into netobuf */
89
void netoprintf(const char *fmt, ...) __attribute((format (printf, 1, 2))); 
88
#define netoprintf(fmt, ...) fprintf(netfile, fmt, ## __VA_ARGS__)
90
89
91
extern int pty, net;
90
extern int pty, net;
92
extern char *line;
91
extern const char *line;
93
extern int SYNCHing;		/* we are in TELNET SYNCH mode */
92
extern int SYNCHing;		/* we are in TELNET SYNCH mode */
94
93
95
void _termstat(void);
94
void _termstat(void);
96
void add_slc(int, int, int);
95
void add_slc(int, int, int);
97
void check_slc(void);
96
void check_slc(void);
98
void change_slc(int, int, int);
97
void change_slc(int, int, int);
99
void cleanup(int);
98
void cleanup(int) __attribute__ ((noreturn));
100
void clientstat(int, int, int);
99
void clientstat(int, int, int);
101
void copy_termbuf(char *, int);
100
void copy_termbuf(char *, int);
102
void deferslc(void);
101
void deferslc(void);
Lines 106-113 Link Here
106
void dooption(int);
105
void dooption(int);
107
void dontoption(int);
106
void dontoption(int);
108
void edithost(const char *, const char *);
107
void edithost(const char *, const char *);
109
void fatal(int, const char *);
108
void fatal(int, const char *) __attribute__ ((noreturn));
110
void fatalperror(int, const char *);
109
void fatalperror(int, const char *) __attribute__ ((noreturn));
111
void get_slc_defaults(void);
110
void get_slc_defaults(void);
112
void init_env(void);
111
void init_env(void);
113
void init_termbuf(void);
112
void init_termbuf(void);
Lines 115-120 Link Here
115
void localstat(void);
114
void localstat(void);
116
void netclear(void);
115
void netclear(void);
117
void netflush(void);
116
void netflush(void);
117
size_t netbuflen(int);
118
void sendurg(const char *, size_t);
118
119
119
#ifdef DIAGNOSTICS
120
#ifdef DIAGNOSTICS
120
void printoption(const char *, int);
121
void printoption(const char *, int);
Lines 182-191 Link Here
182
void tty_tspeed(int);
183
void tty_tspeed(int);
183
void willoption(int);
184
void willoption(int);
184
void wontoption(int);
185
void wontoption(int);
185
void writenet(unsigned char *, int);
186
#define writenet(b, l) fwrite(b, 1, l, netfile)
187
void netopen(void);
186
188
187
#if defined(ENCRYPT)
189
#if defined(ENCRYPT)
188
extern void (*encrypt_output)(unsigned char *, int);
190
extern void (*encrypt_output)(const unsigned char *, int);
189
extern int (*decrypt_input)(int);
191
extern int (*decrypt_input)(int);
190
extern char *nclearto;
192
extern char *nclearto;
191
#endif
193
#endif
(-)./netkit-telnet-0.17/telnetd/global.c (-3 / +2 lines)
Lines 87-97 Link Here
87
87
88
char	netibuf[BUFSIZ], *netip;
88
char	netibuf[BUFSIZ], *netip;
89
89
90
char	netobuf[BUFSIZ+NETSLOP], *nfrontp, *nbackp;
91
char	*neturg;		/* one past last bye of urgent data */
92
93
int	pcc, ncc;
90
int	pcc, ncc;
94
91
92
FILE	*netfile;
93
95
int	pty, net;
94
int	pty, net;
96
int	SYNCHing;		/* we are in TELNET SYNCH mode */
95
int	SYNCHing;		/* we are in TELNET SYNCH mode */
97
96
(-)./netkit-telnet-0.17/telnetd/issue.net.5 (-1 / +1 lines)
Lines 40-43 Link Here
40
.Sh FILES
40
.Sh FILES
41
.Pa /etc/issue.net
41
.Pa /etc/issue.net
42
.Sh "SEE ALSO"
42
.Sh "SEE ALSO"
43
.Xr telnetd 8
43
.Xr in.telnetd 8
(-)./netkit-telnet-0.17/telnetd/setproctitle.c (-1 / +1 lines)
Lines 139-145 Link Here
139
	(void) strcpy(Argv[0], buf);
139
	(void) strcpy(Argv[0], buf);
140
	p = &Argv[0][i];
140
	p = &Argv[0][i];
141
	while (p < LastArgv)
141
	while (p < LastArgv)
142
		*p++ = ' ';
142
		*p++ = '\0';
143
	Argv[1] = NULL;
143
	Argv[1] = NULL;
144
}
144
}
145
145
(-)./netkit-telnet-0.17/telnetd/state.c (-3 / +2 lines)
Lines 179-184 Link Here
179
		   */
179
		   */
180
	      case AO:
180
	      case AO:
181
		  {
181
		  {
182
		      static const char msg[] = { IAC, DM };
182
		      DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
183
		      DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
183
		      ptyflush();	/* half-hearted */
184
		      ptyflush();	/* half-hearted */
184
		      init_termbuf();
185
		      init_termbuf();
Lines 191-199 Link Here
191
		      }
192
		      }
192
193
193
		      netclear();	/* clear buffer back */
194
		      netclear();	/* clear buffer back */
194
		      *nfrontp++ = (char)IAC;
195
		      sendurg(msg, sizeof(msg));
195
		      *nfrontp++ = (char)DM;
196
		      neturg = nfrontp-1; /* off by one XXX */
197
		      DIAG(TD_OPTIONS, printoption("td: send IAC", DM));
196
		      DIAG(TD_OPTIONS, printoption("td: send IAC", DM));
198
		      break;
197
		      break;
199
		  }
198
		  }
(-)./netkit-telnet-0.17/telnetd/sys_term.c (-20 / +6 lines)
Lines 41-48 Link Here
41
41
42
#include "telnetd.h"
42
#include "telnetd.h"
43
#include "pathnames.h"
43
#include "pathnames.h"
44
#include "logout.h"
45
#include "logwtmp.h"
46
44
47
#if defined(__GLIBC__) && (__GLIBC__ >= 2)
45
#if defined(__GLIBC__) && (__GLIBC__ >= 2)
48
/* mmm, nonstandard */
46
/* mmm, nonstandard */
Lines 206-222 Link Here
206
 *
204
 *
207
 * Returns the file descriptor of the opened pty.
205
 * Returns the file descriptor of the opened pty.
208
 */
206
 */
209
static char linedata[PATH_MAX];
207
const char *line;
210
char *line = linedata;
211
208
212
static int ptyslavefd=-1;
209
static int ptyslavefd=-1;
213
210
214
int getpty(void) {
211
int getpty(void) {
215
    int masterfd;
212
    int masterfd;
216
213
217
    if (openpty(&masterfd, &ptyslavefd, line, NULL, NULL)) {
214
    if (openpty(&masterfd, &ptyslavefd, NULL, NULL, NULL)) {
218
	return -1;
215
	return -1;
219
    }
216
    }
217
    line = ttyname(ptyslavefd);
220
    return masterfd;
218
    return masterfd;
221
}
219
}
222
220
Lines 681-687 Link Here
681
    memcpy(&argvfoo, &avs.argv, sizeof(argvfoo));
679
    memcpy(&argvfoo, &avs.argv, sizeof(argvfoo));
682
    execv(loginprg, argvfoo);
680
    execv(loginprg, argvfoo);
683
681
682
    openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
684
    syslog(LOG_ERR, "%s: %m\n", loginprg);
683
    syslog(LOG_ERR, "%s: %m\n", loginprg);
684
    closelog();
685
    fatalperror(net, loginprg);
685
    fatalperror(net, loginprg);
686
}
686
}
687
687
Lines 720-744 Link Here
720
 * clean up anything that needs to be cleaned up.
720
 * clean up anything that needs to be cleaned up.
721
 */
721
 */
722
void cleanup(int sig) {
722
void cleanup(int sig) {
723
    char *p;
723
    const char *p;
724
    (void)sig;
724
    (void)sig;
725
725
726
    p = line + sizeof("/dev/") - 1;
726
    p = line + sizeof("/dev/") - 1;
727
    if (logout(p)) logwtmp(p, "", "");
727
    if (logout(p)) logwtmp(p, "", "");
728
#ifdef PARANOID_TTYS
729
    /*
730
     * dholland 16-Aug-96 chmod the tty when not in use
731
     * This will make it harder to attach unwanted stuff to it
732
     * (which is a security risk) but will break some programs.
733
     */
734
    chmod(line, 0600);
735
#else
736
    chmod(line, 0666);
737
#endif
738
    chown(line, 0, 0);
739
    *p = 'p';
740
    chmod(line, 0666);
741
    chown(line, 0, 0);
742
    shutdown(net, 2);
728
    shutdown(net, 2);
743
    exit(0);
729
    exit(0);
744
}
730
}
(-)./netkit-telnet-0.17/telnetd/telnetd.8 (-1 / +3 lines)
Lines 161-167 Link Here
161
.It Fl L Ar loginprg
161
.It Fl L Ar loginprg
162
This option may be used to specify a different login program.
162
This option may be used to specify a different login program.
163
By default, 
163
By default, 
164
.Pa /bin/login
164
.Pa /usr/lib/telnetlogin
165
is used.
165
is used.
166
.It Fl n
166
.It Fl n
167
Disable
167
Disable
Lines 406-411 Link Here
406
indicates a willingness to decrypt
406
indicates a willingness to decrypt
407
the data stream.
407
the data stream.
408
.Xr issue.net 5 ) .
408
.Xr issue.net 5 ) .
409
.El
409
.Sh FILES
410
.Sh FILES
410
.Pa /etc/services ,
411
.Pa /etc/services ,
411
.Pa /etc/issue.net
412
.Pa /etc/issue.net
Lines 458-463 Link Here
458
Telnet Environment Option Interoperability Issues
459
Telnet Environment Option Interoperability Issues
459
.It Cm RFC-1572
460
.It Cm RFC-1572
460
Telnet Environment Option
461
Telnet Environment Option
462
.El
461
.Sh BUGS
463
.Sh BUGS
462
Some
464
Some
463
.Tn TELNET
465
.Tn TELNET
(-)./netkit-telnet-0.17/telnetd/telnetd.c (-116 / +152 lines)
Lines 43-54 Link Here
43
43
44
#include "../version.h"
44
#include "../version.h"
45
45
46
#include <sys/socket.h>
46
#include <netdb.h>
47
#include <netdb.h>
47
#include <termcap.h>
48
#include <termcap.h>
48
#include <netinet/in.h>
49
#include <netinet/in.h>
49
/* #include <netinet/ip.h> */ /* Don't think this is used at all here */
50
/* #include <netinet/ip.h> */ /* Don't think this is used at all here */
50
#include <arpa/inet.h>
51
#include <arpa/inet.h>
51
#include <assert.h>
52
#include <assert.h>
53
#include <poll.h>
54
#include <fcntl.h>
55
#include <unistd.h>
52
#include "telnetd.h"
56
#include "telnetd.h"
53
#include "pathnames.h"
57
#include "pathnames.h"
54
#include "setproctitle.h"
58
#include "setproctitle.h"
Lines 68-74 Link Here
68
#define HAS_IPPROTO_IP
72
#define HAS_IPPROTO_IP
69
#endif
73
#endif
70
74
71
static void doit(struct sockaddr_in *who);
75
static void doit(struct sockaddr *who, socklen_t who_len);
72
static int terminaltypeok(const char *s);
76
static int terminaltypeok(const char *s);
73
77
74
/*
78
/*
Lines 82-96 Link Here
82
86
83
int debug = 0;
87
int debug = 0;
84
int keepalive = 1;
88
int keepalive = 1;
89
#ifdef LOGIN_WRAPPER
90
char *loginprg = LOGIN_WRAPPER;
91
#else
85
char *loginprg = _PATH_LOGIN;
92
char *loginprg = _PATH_LOGIN;
86
char *progname;
93
#endif
87
94
88
extern void usage(void);
95
extern void usage(void);
89
96
97
static void
98
wait_for_connection(const char *service)
99
{
100
	struct addrinfo hints;
101
	struct addrinfo *res, *addr;
102
	struct pollfd *fds, *fdp;
103
	int nfds;
104
	int i;
105
	int error;
106
	int on = 1;
107
108
	memset(&hints, 0, sizeof(hints));
109
	hints.ai_family = PF_UNSPEC;
110
	hints.ai_flags = AI_PASSIVE;
111
	hints.ai_socktype = SOCK_STREAM;
112
	error = getaddrinfo(NULL, service, &hints, &res);
113
	if (error) {
114
		char *p;
115
		error = asprintf(&p, "getaddrinfo: %s\n", gai_strerror(error));
116
		fatal(2, error >= 0 ? p : "");
117
	}
118
119
	for (addr = res, nfds = 0; addr; addr = addr->ai_next, nfds++)
120
		;
121
	fds = malloc(sizeof(struct pollfd) * nfds);
122
	for (addr = res, fdp = fds; addr; addr = addr->ai_next, fdp++) {
123
		int s;
124
125
		if (addr->ai_family == AF_LOCAL) {
126
nextaddr:
127
			fdp--;
128
			nfds--;
129
			continue;
130
		}
131
132
		s = socket(addr->ai_family, SOCK_STREAM, 0);
133
		if (s < 0) {
134
			if (errno == EAFNOSUPPORT || errno == EINVAL) {
135
				goto nextaddr;
136
			}
137
			fatalperror(2, "socket");
138
		}
139
		if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) {
140
			fatalperror(2, "setsockopt");
141
		}
142
		if (bind(s, addr->ai_addr, addr->ai_addrlen)) {
143
#ifdef linux
144
			if (fdp != fds && errno == EADDRINUSE) {
145
				close(s);
146
				goto nextaddr;
147
			}
148
#endif
149
			fatalperror(2, "bind");
150
		}
151
		if (listen(s, 1)) {
152
			fatalperror(2, "listen");
153
		}
154
		if (fcntl(s, F_SETFL, O_NONBLOCK)) {
155
			fatalperror(2, "fcntl");
156
		}
157
158
		fdp->fd = s;
159
		fdp->events = POLLIN;
160
	}
161
162
	freeaddrinfo(res);
163
164
	while (1) {
165
		if (poll(fds, nfds, -1) < 0) {
166
			if (errno == EINTR) {
167
				continue;
168
			}
169
			fatalperror(2, "poll");
170
		}
171
172
		for (i = 0, fdp = fds; i < nfds; i++, fdp++) {
173
			int fd;
174
175
			if (!(fdp->revents & POLLIN)) {
176
				continue;
177
			}
178
179
			fd = accept(fdp->fd, 0, 0);
180
			if (fd >= 0) {
181
				dup2(fd, 0);
182
				close(fd);
183
				goto out;
184
			}
185
			if (errno != EAGAIN) {
186
				fatalperror(2, "accept");
187
			}
188
		}
189
	}
190
191
out:
192
	for (i = 0, fdp = fds; i < nfds; i++, fdp++) {
193
		close(fdp->fd);
194
	}
195
	free(fds);
196
}
197
90
int
198
int
91
main(int argc, char *argv[], char *env[])
199
main(int argc, char *argv[], char *env[])
92
{
200
{
93
	struct sockaddr_in from;
201
	struct sockaddr_storage from;
94
	int on = 1;
202
	int on = 1;
95
	socklen_t fromlen;
203
	socklen_t fromlen;
96
	register int ch;
204
	register int ch;
Lines 103-114 Link Here
103
211
104
	pfrontp = pbackp = ptyobuf;
212
	pfrontp = pbackp = ptyobuf;
105
	netip = netibuf;
213
	netip = netibuf;
106
	nfrontp = nbackp = netobuf;
107
#if	defined(ENCRYPT)
108
	nclearto = 0;
109
#endif
110
111
	progname = *argv;
112
214
113
	while ((ch = getopt(argc, argv, "d:a:e:lhnr:I:D:B:sS:a:X:L:")) != EOF) {
215
	while ((ch = getopt(argc, argv, "d:a:e:lhnr:I:D:B:sS:a:X:L:")) != EOF) {
114
		switch(ch) {
216
		switch(ch) {
Lines 249-322 Link Here
249
	argv += optind;
351
	argv += optind;
250
352
251
	if (debug) {
353
	if (debug) {
252
	    int s, ns;
354
		if (argc > 1) {
253
	    socklen_t foo;
355
			usage();
254
	    struct servent *sp;
356
			/* NOTREACHED */
255
	    struct sockaddr_in sn;
256
257
	    memset(&sn, 0, sizeof(sn));
258
	    sn.sin_family = AF_INET;
259
260
	    if (argc > 1) {
261
		usage();
262
		/* NOTREACHED */
263
	    } else if (argc == 1) {
264
		    if ((sp = getservbyname(*argv, "tcp"))!=NULL) {
265
			sn.sin_port = sp->s_port;
266
		    } 
267
		    else {
268
			int pt = atoi(*argv);
269
			if (pt <= 0) {
270
			    fprintf(stderr, "telnetd: %s: bad port number\n",
271
				    *argv);
272
			    usage();
273
			    /* NOTREACHED */
274
			}
275
			sn.sin_port = htons(pt);
276
		   }
277
	    } else {
278
		sp = getservbyname("telnet", "tcp");
279
		if (sp == 0) {
280
		    fprintf(stderr, "telnetd: tcp/telnet: unknown service\n");
281
		    exit(1);
282
		}
357
		}
283
		sn.sin_port = sp->s_port;
284
	    }
285
358
286
	    s = socket(AF_INET, SOCK_STREAM, 0);
359
		wait_for_connection((argc == 1) ? *argv : "telnet");
287
	    if (s < 0) {
288
		    perror("telnetd: socket");;
289
		    exit(1);
290
	    }
291
	    (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
292
	    if (bind(s, (struct sockaddr *)&sn, sizeof(sn)) < 0) {
293
		perror("bind");
294
		exit(1);
295
	    }
296
	    if (listen(s, 1) < 0) {
297
		perror("listen");
298
		exit(1);
299
	    }
300
	    foo = sizeof(sn);
301
	    ns = accept(s, (struct sockaddr *)&sn, &foo);
302
	    if (ns < 0) {
303
		perror("accept");
304
		exit(1);
305
	    }
306
	    (void) dup2(ns, 0);
307
	    (void) close(ns);
308
	    (void) close(s);
309
	} else if (argc > 0) {
310
		usage();
311
		/* NOT REACHED */
312
	}
360
	}
313
361
314
	openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
362
	openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
315
	fromlen = sizeof (from);
363
	fromlen = sizeof (from);
316
	if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
364
	if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
317
		fprintf(stderr, "%s: ", progname);
365
		fatalperror(2, "getpeername");
318
		perror("getpeername");
319
		_exit(1);
320
	}
366
	}
321
	if (keepalive &&
367
	if (keepalive &&
322
	    setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0) {
368
	    setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0) {
Lines 339-345 Link Here
339
	}
385
	}
340
#endif	/* defined(HAS_IPPROTO_IP) && defined(IP_TOS) */
386
#endif	/* defined(HAS_IPPROTO_IP) && defined(IP_TOS) */
341
	net = 0;
387
	net = 0;
342
	doit(&from);
388
	netopen();
389
	doit((struct sockaddr *)&from, fromlen);
343
	/* NOTREACHED */
390
	/* NOTREACHED */
344
	return 0;
391
	return 0;
345
}  /* end of main */
392
}  /* end of main */
Lines 354-360 Link Here
354
#ifdef BFTPDAEMON
401
#ifdef BFTPDAEMON
355
	fprintf(stderr, " [-B]");
402
	fprintf(stderr, " [-B]");
356
#endif
403
#endif
357
	fprintf(stderr, " [-debug]");
404
	fprintf(stderr, " [-debug port]");
358
#ifdef DIAGNOSTICS
405
#ifdef DIAGNOSTICS
359
	fprintf(stderr, " [-D (options|report|exercise|netdata|ptydata)]\n\t");
406
	fprintf(stderr, " [-D (options|report|exercise|netdata|ptydata)]\n\t");
360
#endif
407
#endif
Lines 373-379 Link Here
373
#ifdef	AUTHENTICATE
420
#ifdef	AUTHENTICATE
374
	fprintf(stderr, " [-X auth-type]");
421
	fprintf(stderr, " [-X auth-type]");
375
#endif
422
#endif
376
	fprintf(stderr, " [port]\n");
423
	fprintf(stderr, "\n");
377
	exit(1);
424
	exit(1);
378
}
425
}
379
426
Lines 608-661 Link Here
608
 * Get a pty, scan input lines.
655
 * Get a pty, scan input lines.
609
 */
656
 */
610
static void
657
static void
611
doit(struct sockaddr_in *who)
658
doit(struct sockaddr *who, socklen_t who_len)
612
{
659
{
613
	const char *host;
660
	const char *host;
614
	struct hostent *hp;
615
	int level;
661
	int level;
616
	char user_name[256];
662
	char user_name[256];
663
	int i;
664
	struct addrinfo hints, *res;
617
665
618
	/*
666
	/*
619
	 * Find an available pty to use.
667
	 * Find an available pty to use.
620
	 */
668
	 */
621
	pty = getpty();
669
	pty = getpty();
622
	if (pty < 0)
670
	if (pty < 0)
623
		fatal(net, "All network ports in use");
671
		fatalperror(net, "getpty");
624
672
625
	/* get name of connected client */
673
	/* get name of connected client */
626
	hp = gethostbyaddr((char *)&who->sin_addr, sizeof (struct in_addr),
674
	if (getnameinfo(who, who_len, remote_host_name,
627
		who->sin_family);
675
			sizeof(remote_host_name), 0, 0, 0)) {
628
	if (hp)
676
		syslog(LOG_ERR, "doit: getnameinfo: %m");
629
		host = hp->h_name;
677
		*remote_host_name = 0;
630
	else
678
        }
631
		host = inet_ntoa(who->sin_addr);
679
632
680
	/* Disallow funnies. */
633
	/*
681
	for (i=0; remote_host_name[i]; i++) {
634
	 * We must make a copy because Kerberos is probably going
682
	    if (remote_host_name[i]<=32 || remote_host_name[i]>126) 
635
	 * to also do a gethost* and overwrite the static data...
683
		remote_host_name[i] = '?';
636
	 */
637
	{
638
		int i;
639
		strncpy(remote_host_name, host, sizeof(remote_host_name)-1);
640
		remote_host_name[sizeof(remote_host_name)-1] = 0;
641
642
		/* Disallow funnies. */
643
		for (i=0; remote_host_name[i]; i++) {
644
		    if (remote_host_name[i]<=32 || remote_host_name[i]>126) 
645
			remote_host_name[i] = '?';
646
		}
647
	}
684
	}
648
	host = remote_host_name;
685
	host = remote_host_name;
649
686
650
	/* Get local host name */
687
	/* Get local host name */
651
	{
688
	gethostname(host_name, sizeof(host_name));
652
		struct hostent *h;
689
	memset(&hints, 0, sizeof(hints));
653
		gethostname(host_name, sizeof(host_name));
690
	hints.ai_family = PF_UNSPEC;
654
		h = gethostbyname(host_name);
691
	hints.ai_flags = AI_CANONNAME;
655
		if (h) {
692
	if ((i = getaddrinfo(host_name, 0, &hints, &res)))
656
		    strncpy(host_name, h->h_name, sizeof(host_name));
693
		syslog(LOG_WARNING, "doit: getaddrinfo: %s", gai_strerror(i));
657
		    host_name[sizeof(host_name)-1] = 0;
694
	else {
658
		}
695
		strncpy(host_name, res->ai_canonname, sizeof(host_name)-1);
696
		host_name[sizeof(host_name)-1] = 0;
659
	}
697
	}
660
698
661
#if	defined(AUTHENTICATE) || defined(ENCRYPT)
699
#if	defined(AUTHENTICATE) || defined(ENCRYPT)
Lines 892-898 Link Here
892
	 * Never look for input if there's still
930
	 * Never look for input if there's still
893
	 * stuff in the corresponding output buffer
931
	 * stuff in the corresponding output buffer
894
	 */
932
	 */
895
	if (nfrontp - nbackp || pcc > 0) {
933
	if (netbuflen(1) || pcc > 0) {
896
	    FD_SET(f, &obits);
934
	    FD_SET(f, &obits);
897
	    if (f >= hifd) hifd = f+1;
935
	    if (f >= hifd) hifd = f+1;
898
	} 
936
	} 
Lines 1033-1038 Link Here
1033
		}
1071
		}
1034
#endif	/* LINEMODE */
1072
#endif	/* LINEMODE */
1035
		if (ptyibuf[0] & TIOCPKT_FLUSHWRITE) {
1073
		if (ptyibuf[0] & TIOCPKT_FLUSHWRITE) {
1074
		    static const char msg[] = { IAC, DM };
1036
		    netclear();	/* clear buffer back */
1075
		    netclear();	/* clear buffer back */
1037
#ifndef	NO_URGENT
1076
#ifndef	NO_URGENT
1038
		    /*
1077
		    /*
Lines 1041-1048 Link Here
1041
		     * royally if we send them urgent
1080
		     * royally if we send them urgent
1042
		     * mode data.
1081
		     * mode data.
1043
		     */
1082
		     */
1044
		    netoprintf("%c%c", IAC, DM);
1083
		    sendurg(msg, sizeof(msg));
1045
		    neturg = nfrontp-1; /* off by one XXX */
1046
#endif
1084
#endif
1047
		}
1085
		}
1048
		if (his_state_is_will(TELOPT_LFLOW) &&
1086
		if (his_state_is_will(TELOPT_LFLOW) &&
Lines 1058-1080 Link Here
1058
	    }
1096
	    }
1059
	}
1097
	}
1060
	
1098
	
1061
	while (pcc > 0) {
1099
	while (pcc > 0 && !netbuflen(0)) {
1062
	    if ((&netobuf[BUFSIZ] - nfrontp) < 2)
1063
		break;
1064
	    c = *ptyip++ & 0377, pcc--;
1100
	    c = *ptyip++ & 0377, pcc--;
1065
	    if (c == IAC)
1101
	    if (c == IAC)
1066
		*nfrontp++ = c;
1102
		putc(c, netfile);
1067
	    *nfrontp++ = c;
1103
	    putc(c, netfile);
1068
	    if ((c == '\r'  ) && (my_state_is_wont(TELOPT_BINARY))) {
1104
	    if ((c == '\r'  ) && (my_state_is_wont(TELOPT_BINARY))) {
1069
		if (pcc > 0 && ((*ptyip & 0377) == '\n')) {
1105
		if (pcc > 0 && ((*ptyip & 0377) == '\n')) {
1070
		    *nfrontp++ = *ptyip++ & 0377;
1106
		    putc(*ptyip++ & 0377, netfile);
1071
		    pcc--;
1107
		    pcc--;
1072
		} 
1108
		} 
1073
		else *nfrontp++ = '\0';
1109
		else putc('\0', netfile);
1074
	    }
1110
	    }
1075
	}
1111
	}
1076
1112
1077
	if (FD_ISSET(f, &obits) && (nfrontp - nbackp) > 0)
1113
	if (FD_ISSET(f, &obits))
1078
	    netflush();
1114
	    netflush();
1079
	if (ncc > 0)
1115
	if (ncc > 0)
1080
	    telrcv();
1116
	    telrcv();
(-)./netkit-telnet-0.17/telnetd/utility.c (-193 / +322 lines)
Lines 37-46 Link Here
37
char util_rcsid[] = 
37
char util_rcsid[] = 
38
  "$Id: utility.c,v 1.11 1999/12/12 14:59:45 dholland Exp $";
38
  "$Id: utility.c,v 1.11 1999/12/12 14:59:45 dholland Exp $";
39
39
40
#define _GNU_SOURCE
41
#include <stdio.h>
42
40
#define PRINTOPTIONS
43
#define PRINTOPTIONS
41
44
42
#include <stdarg.h>
45
#include <stdarg.h>
43
#include <sys/utsname.h>
46
#include <sys/utsname.h>
47
#include <sys/time.h>
44
48
45
#ifdef AUTHENTICATE
49
#ifdef AUTHENTICATE
46
#include <libtelnet/auth.h>
50
#include <libtelnet/auth.h>
Lines 48-81 Link Here
48
52
49
#include "telnetd.h"
53
#include "telnetd.h"
50
54
51
/*
55
struct buflist {
52
 * utility functions performing io related tasks
56
	struct buflist *next;
53
 */
57
	char *buf;
54
58
	size_t len;
55
void
59
};
56
netoprintf(const char *fmt, ...)
60
57
{
61
static struct buflist head = { next: &head, buf: 0, len: 0 };
58
   int len, maxsize;
62
static struct buflist *tail = &head;
59
   va_list ap;
63
static size_t skip;
60
   int done=0;
64
static int trailing;
61
65
static size_t listlen;
62
   while (!done) {
66
static int doclear;
63
      maxsize = sizeof(netobuf) - (nfrontp - netobuf);
67
static struct buflist *urg;
64
65
      va_start(ap, fmt);
66
      len = vsnprintf(nfrontp, maxsize, fmt, ap);
67
      va_end(ap);
68
69
      if (len<0 || len==maxsize) {
70
	 /* didn't fit */
71
	 netflush();
72
      }
73
      else {
74
	 done = 1;
75
      }
76
   }
77
   nfrontp += len;
78
}
79
68
80
/*
69
/*
81
 * ttloop
70
 * ttloop
Lines 92-100 Link Here
92
81
93
    DIAG(TD_REPORT, netoprintf("td: ttloop\r\n"););
82
    DIAG(TD_REPORT, netoprintf("td: ttloop\r\n"););
94
		     
83
		     
95
    if (nfrontp-nbackp) {
84
    netflush();
96
	netflush();
97
    }
98
    ncc = read(net, netibuf, sizeof(netibuf));
85
    ncc = read(net, netibuf, sizeof(netibuf));
99
    if (ncc < 0) {
86
    if (ncc < 0) {
100
	syslog(LOG_INFO, "ttloop: read: %m\n");
87
	syslog(LOG_INFO, "ttloop: read: %m\n");
Lines 168-200 Link Here
168
 * character.
155
 * character.
169
 */
156
 */
170
static
157
static
171
char *
158
const char *
172
nextitem(char *current)
159
nextitem(
173
{
160
	const unsigned char *current, const unsigned char *end,
174
    if ((*current&0xff) != IAC) {
161
	const unsigned char *next, const unsigned char *nextend
175
	return current+1;
162
) {
176
    }
163
	if (*current++ != IAC) {
177
    switch (*(current+1)&0xff) {
164
		while (current < end && *current++ != IAC)
178
    case DO:
165
			;
179
    case DONT:
166
		goto out;
180
    case WILL:
167
	}
181
    case WONT:
168
182
	return current+3;
169
	if (current >= end) {
183
    case SB:		/* loop forever looking for the SE */
170
		current = next;
184
	{
171
		if (!current) {
185
	    register char *look = current+2;
172
			return 0;
186
187
	    for (;;) {
188
		if ((*look++&0xff) == IAC) {
189
		    if ((*look++&0xff) == SE) {
190
			return look;
191
		    }
192
		}
173
		}
193
	    }
174
		end = nextend;
175
		next = 0;
194
	}
176
	}
195
    default:
177
196
	return current+2;
178
	switch (*current++) {
197
    }
179
	case DO:
180
	case DONT:
181
	case WILL:
182
	case WONT:
183
		current++;
184
		break;
185
	case SB:		/* loop forever looking for the SE */
186
		for (;;) {
187
			int iac;
188
189
			while (iac = 0, current < end) {
190
				if (*current++ == IAC) {
191
					if (current >= end) {
192
						iac = 1;
193
						break;
194
					}
195
iac:
196
					if (*current++ == SE) {
197
						goto out;
198
					}
199
				}
200
			}
201
202
			current = next;
203
			if (!current) {
204
				return 0;
205
			}
206
			end = nextend;
207
			next = 0;
208
			if (iac) {
209
				goto iac;
210
			}
211
		}
212
	}
213
214
out:
215
	return next ? next + (current - end) : current;
198
}  /* end of nextitem */
216
}  /* end of nextitem */
199
217
200
218
Lines 216-360 Link Here
216
 */
234
 */
217
void netclear(void)
235
void netclear(void)
218
{
236
{
219
    register char *thisitem, *next;
237
	doclear++;
220
    char *good;
238
	netflush();
221
#define	wewant(p)	((nfrontp > p) && ((*p&0xff) == IAC) && \
239
	doclear--;
222
				((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
240
}  /* end of netclear */
223
241
224
#if	defined(ENCRYPT)
242
static void
225
    thisitem = nclearto > netobuf ? nclearto : netobuf;
243
netwritebuf(void)
226
#else
244
{
227
    thisitem = netobuf;
245
	struct iovec *vector;
228
#endif
246
	struct iovec *v;
247
	struct buflist *lp;
248
	ssize_t n;
249
	size_t len;
250
	int ltrailing = trailing;
229
251
230
    while ((next = nextitem(thisitem)) <= nbackp) {
252
	vector = malloc(listlen * sizeof(struct iovec));
231
	thisitem = next;
253
	if (!vector) {
232
    }
254
		return;
255
	}
233
256
234
    /* Now, thisitem is first before/at boundary. */
257
	len = listlen - (doclear & ltrailing);
258
	v = vector;
259
	lp = head.next;
260
	while (lp != &head) {
261
		if (lp == urg) {
262
			len = v - vector;
263
			if (!len) {
264
				n = send(net, lp->buf, 1, MSG_OOB);
265
				if (n > 0) {
266
					urg = 0;
267
				}
268
				goto epi;
269
			}
270
			break;
271
		}
272
		v->iov_base = lp->buf;
273
		v->iov_len = lp->len;
274
		v++;
275
		lp = lp->next;
276
	}
235
277
236
#if	defined(ENCRYPT)
278
	vector->iov_base = (char *)vector->iov_base + skip;
237
    good = nclearto > netobuf ? nclearto : netobuf;
279
	vector->iov_len -= skip;
238
#else
239
    good = netobuf;	/* where the good bytes go */
240
#endif
241
280
242
    while (nfrontp > thisitem) {
281
	n = writev(net, vector, len);
243
	if (wewant(thisitem)) {
282
244
	    int length;
283
epi:
245
284
	free(vector);
246
	    next = thisitem;
285
247
	    do {
286
	if (n < 0) {
248
		next = nextitem(next);
287
		if (errno != EWOULDBLOCK && errno != EINTR)
249
	    } while (wewant(next) && (nfrontp > next));
288
			cleanup(0);
250
	    length = next-thisitem;
289
		return;
251
	    bcopy(thisitem, good, length);
252
	    good += length;
253
	    thisitem = next;
254
	} else {
255
	    thisitem = nextitem(thisitem);
256
	}
290
	}
257
    }
258
291
259
    nbackp = netobuf;
292
	len = n + skip;
260
    nfrontp = good;		/* next byte to be sent */
261
    neturg = 0;
262
}  /* end of netclear */
263
293
264
/*
294
	lp = head.next;
265
 *  netflush
295
	while (lp->len <= len) {
266
 *		Send as much data as possible to the network,
296
		if (lp == tail && ltrailing) {
267
 *	handling requests for urgent data.
297
			break;
268
 */
298
		}
269
extern int not42;
270
void
271
netflush(void)
272
{
273
    int n;
274
299
275
    if ((n = nfrontp - nbackp) > 0) {
300
		len -= lp->len;
276
	DIAG(TD_REPORT,
301
277
	    { netoprintf("td: netflush %d chars\r\n", n);
302
		head.next = lp->next;
278
	      n = nfrontp - nbackp;  /* update count */
303
		listlen--;
279
	    });
304
		free(lp->buf);
280
#if	defined(ENCRYPT)
305
		free(lp);
281
	if (encrypt_output) {
306
282
		char *s = nclearto ? nclearto : nbackp;
307
		lp = head.next;
283
		if (nfrontp - s > 0) {
308
		if (lp == &head) {
284
			(*encrypt_output)((unsigned char *)s, nfrontp-s);
309
			tail = &head;
285
			nclearto = nfrontp;
310
			break;
286
		}
311
		}
287
	}
312
	}
288
#endif
289
	/*
290
	 * if no urgent data, or if the other side appears to be an
291
	 * old 4.2 client (and thus unable to survive TCP urgent data),
292
	 * write the entire buffer in non-OOB mode.
293
	 */
294
	if ((neturg == 0) || (not42 == 0)) {
295
	    n = write(net, nbackp, n);	/* normal write */
296
	} else {
297
	    n = neturg - nbackp;
298
	    /*
299
	     * In 4.2 (and 4.3) systems, there is some question about
300
	     * what byte in a sendOOB operation is the "OOB" data.
301
	     * To make ourselves compatible, we only send ONE byte
302
	     * out of band, the one WE THINK should be OOB (though
303
	     * we really have more the TCP philosophy of urgent data
304
	     * rather than the Unix philosophy of OOB data).
305
	     */
306
	    if (n > 1) {
307
		n = send(net, nbackp, n-1, 0);	/* send URGENT all by itself */
308
	    } else {
309
		n = send(net, nbackp, n, MSG_OOB);	/* URGENT data */
310
	    }
311
	}
312
    }
313
    if (n < 0) {
314
	if (errno == EWOULDBLOCK || errno == EINTR)
315
		return;
316
	cleanup(0);
317
    }
318
    nbackp += n;
319
#if	defined(ENCRYPT)
320
    if (nbackp > nclearto)
321
	nclearto = 0;
322
#endif
323
    if (nbackp >= neturg) {
324
	neturg = 0;
325
    }
326
    if (nbackp == nfrontp) {
327
	nbackp = nfrontp = netobuf;
328
#if	defined(ENCRYPT)
329
	nclearto = 0;
330
#endif
331
    }
332
    return;
333
}  /* end of netflush */
334
313
314
	skip = len;
315
}
335
316
336
/*
317
/*
337
 * writenet
318
 *  netflush
338
 *
319
 *             Send as much data as possible to the network,
339
 * Just a handy little function to write a bit of raw data to the net.
320
 *     handling requests for urgent data.
340
 * It will force a transmit of the buffer if necessary
341
 *
342
 * arguments
343
 *    ptr - A pointer to a character string to write
344
 *    len - How many bytes to write
345
 */
321
 */
346
void writenet(register unsigned char *ptr, register int len)
322
void
323
netflush(void)
347
{
324
{
348
	/* flush buffer if no room for new data) */
325
	if (fflush(netfile)) {
349
	if ((&netobuf[BUFSIZ] - nfrontp) < len) {
326
		/* out of memory? */
350
		/* if this fails, don't worry, buffer is a little big */
327
		cleanup(0);
351
		netflush();
352
	}
328
	}
353
329
	if (listlen) {
354
	bcopy(ptr, nfrontp, len);
330
		netwritebuf();
355
	nfrontp += len;
331
	}
356
332
}
357
}  /* end of writenet */
358
333
359
334
360
/*
335
/*
Lines 391-408 Link Here
391
	fatal(f, buf);
366
	fatal(f, buf);
392
}
367
}
393
368
394
char editedhost[32];
369
char *editedhost;
395
struct utsname kerninfo;
370
struct utsname kerninfo;
396
371
397
void
372
void
398
edithost(const char *pat, const char *host)
373
edithost(const char *pat, const char *host)
399
{
374
{
400
	char *res = editedhost;
375
	char *res;
401
376
402
	uname(&kerninfo);
377
	uname(&kerninfo);
403
378
404
	if (!pat)
379
	if (!pat)
405
		pat = "";
380
		pat = "";
381
382
	res = realloc(editedhost, strlen(pat) + strlen(host) + 1);
383
	if (!res) {
384
		if (editedhost) {
385
			free(editedhost);
386
			editedhost = 0;
387
		}
388
		fprintf(stderr, "edithost: Out of memory\n");
389
		return;
390
	}
391
	editedhost = res;
392
406
	while (*pat) {
393
	while (*pat) {
407
		switch (*pat) {
394
		switch (*pat) {
408
395
Lines 420-437 Link Here
420
			*res++ = *pat;
407
			*res++ = *pat;
421
			break;
408
			break;
422
		}
409
		}
423
		if (res == &editedhost[sizeof editedhost - 1]) {
424
			*res = '\0';
425
			return;
426
		}
427
		pat++;
410
		pat++;
428
	}
411
	}
429
	if (*host)
412
	if (*host)
430
		(void) strncpy(res, host,
413
		(void) strcpy(res, host);
431
				sizeof editedhost - (res - editedhost) -1);
432
	else
414
	else
433
		*res = '\0';
415
		*res = '\0';
434
	editedhost[sizeof editedhost - 1] = '\0';
435
}
416
}
436
417
437
static char *putlocation;
418
static char *putlocation;
Lines 475-481 Link Here
475
			break;
456
			break;
476
457
477
		case 'h':
458
		case 'h':
478
			putstr(editedhost);
459
			if (editedhost) {
460
				putstr(editedhost);
461
			}
479
			break;
462
			break;
480
463
481
		case 'd':
464
		case 'd':
Lines 1118-1128 Link Here
1118
	char xbuf[30];
1101
	char xbuf[30];
1119
1102
1120
	while (cnt) {
1103
	while (cnt) {
1121
		/* flush net output buffer if no room for new data) */
1122
		if ((&netobuf[BUFSIZ] - nfrontp) < 80) {
1123
			netflush();
1124
		}
1125
1126
		/* add a line of output */
1104
		/* add a line of output */
1127
		netoprintf("%s: ", tag);
1105
		netoprintf("%s: ", tag);
1128
		for (i = 0; i < 20 && cnt; i++) {
1106
		for (i = 0; i < 20 && cnt; i++) {
Lines 1143-1145 Link Here
1143
	} 
1121
	} 
1144
}
1122
}
1145
#endif /* DIAGNOSTICS */
1123
#endif /* DIAGNOSTICS */
1124
1125
static struct buflist *
1126
addbuf(const char *buf, size_t len)
1127
{
1128
	struct buflist *bufl;
1129
1130
	bufl = malloc(sizeof(struct buflist));
1131
	if (!bufl) {
1132
		return 0;
1133
	}
1134
	bufl->next = tail->next;
1135
	bufl->buf = malloc(len);
1136
	if (!bufl->buf) {
1137
		free(bufl);
1138
		return 0;
1139
	}
1140
	bufl->len = len;
1141
1142
	tail = tail->next = bufl;
1143
	listlen++;
1144
1145
	memcpy(bufl->buf, buf, len);
1146
	return bufl;
1147
}
1148
1149
static ssize_t
1150
netwrite(void *cookie, const char *buf, size_t len)
1151
{
1152
	size_t ret;
1153
	const char *const end = buf + len;
1154
	int ltrailing = trailing;
1155
	int ldoclear = doclear;
1156
1157
#define	wewant(p)	((*p&0xff) == IAC) && \
1158
				((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL)
1159
1160
	ret = 0;
1161
1162
	if (ltrailing) {
1163
		const char *p;
1164
		size_t l;
1165
		size_t m = tail->len;
1166
1167
		p = nextitem(tail->buf, tail->buf + tail->len, buf, end);
1168
		ltrailing = !p;
1169
		if (ltrailing) {
1170
			p = end;
1171
		}
1172
1173
		l = p - buf;
1174
		tail->len += l;
1175
		tail->buf = realloc(tail->buf, tail->len);
1176
		if (!tail->buf) {
1177
			return -1;
1178
		}
1179
1180
		memcpy(tail->buf + m, buf, l);
1181
		buf += l;
1182
		len -= l;
1183
		ret += l;
1184
		trailing = ltrailing;
1185
	}
1186
1187
	if (ldoclear) {
1188
		struct buflist *lpprev;
1189
1190
		skip = 0;
1191
		lpprev = &head;
1192
		for (;;) {
1193
			struct buflist *lp;
1194
1195
			lp = lpprev->next;
1196
1197
			if (lp == &head) {
1198
				tail = lpprev;
1199
				break;
1200
			}
1201
1202
			if (lp == tail && ltrailing) {
1203
				break;
1204
			}
1205
1206
			if (!wewant(lp->buf)) {
1207
				lpprev->next = lp->next;
1208
				listlen--;
1209
				free(lp->buf);
1210
				free(lp);
1211
			} else {
1212
				lpprev = lp;
1213
			}
1214
		}
1215
	}
1216
1217
	while (len) {
1218
		const char *p;
1219
		size_t l;
1220
1221
		p = nextitem(buf, end, 0, 0);
1222
		ltrailing = !p;
1223
		if (ltrailing) {
1224
			p = end;
1225
		} else if (ldoclear) {
1226
			if (!wewant(buf)) {
1227
				l = p - buf;
1228
				goto cont;
1229
			}
1230
		}
1231
1232
		l = p - buf;
1233
		if (!addbuf(buf, l)) {
1234
			return ret ? ret : -1;
1235
		}
1236
		trailing = ltrailing;
1237
1238
cont:
1239
		buf += l;
1240
		len -= l;
1241
		ret += l;
1242
	}
1243
1244
	netwritebuf();
1245
	return ret;
1246
}
1247
1248
void
1249
netopen() {
1250
	static const cookie_io_functions_t funcs = {
1251
		read: 0, write: netwrite, seek: 0, close: 0
1252
	};
1253
1254
	netfile = fopencookie(0, "w", funcs);
1255
}
1256
1257
extern int not42;
1258
void
1259
sendurg(const char *buf, size_t len) {
1260
	if (!not42) {
1261
		fwrite(buf, 1, len, netfile);
1262
		return;
1263
	}
1264
1265
	urg = addbuf(buf, len);
1266
}
1267
1268
size_t
1269
netbuflen(int flush) {
1270
	if (flush) {
1271
		netflush();
1272
	}
1273
	return listlen != 1 ? listlen : tail->len - skip;
1274
}
(-)./netkit-telnet-0.17/telnetlogin/telnetlogin.8 (-4 / +3 lines)
Lines 40-45 Link Here
40
.Nm telnetlogin
40
.Nm telnetlogin
41
.Op Fl h Ar host
41
.Op Fl h Ar host
42
.Op Fl p
42
.Op Fl p
43
.Op Ar username
43
.Sh DESCRIPTION
44
.Sh DESCRIPTION
44
.Nm telnetlogin
45
.Nm telnetlogin
45
is a setuid wrapper that runs
46
is a setuid wrapper that runs
Lines 62-71 Link Here
62
.Nm telnetd 8
63
.Nm telnetd 8
63
normally provides them in.
64
normally provides them in.
64
.Nm telnetlogin
65
.Nm telnetlogin
65
also only accepts the environment variables
66
also does sanity checks on the environment variables
66
.Ev TERM , 
67
.Ev TERM , 
67
.Ev DISPLAY , 
68
.Ev POSIXLY_CORRECT ,
69
and
68
and
70
.Ev REMOTEHOST .
69
.Ev REMOTEHOST .
71
It also insists that the standard input, output, and error streams are
70
It also insists that the standard input, output, and error streams are
Lines 83-89 Link Here
83
.Nm telnetlogin
82
.Nm telnetlogin
84
does not permit the
83
does not permit the
85
.Fl f
84
.Fl f
86
option to login, and does not permit passing a username, so will not
85
option to login, so will not
87
work with telnetds that perform authentication via Kerberos or SSL.
86
work with telnetds that perform authentication via Kerberos or SSL.
88
.Pp
87
.Pp
89
THIS IS PRESENTLY EXPERIMENTAL CODE; USE WITH CAUTION.
88
THIS IS PRESENTLY EXPERIMENTAL CODE; USE WITH CAUTION.
(-)./netkit-telnet-0.17/telnetlogin/telnetlogin.c (-51 / +26 lines)
Lines 51-70 Link Here
51
#include <string.h>
51
#include <string.h>
52
#include <stdarg.h>
52
#include <stdarg.h>
53
#include <stdio.h>
53
#include <stdio.h>
54
#include <syslog.h>
54
55
55
#ifndef _PATH_LOGIN
56
#ifndef _PATH_LOGIN
56
#define _PATH_LOGIN "/bin/login"
57
#define _PATH_LOGIN "/bin/login"
57
#endif
58
#endif
58
59
60
extern char **environ;
61
59
static const char *remhost = NULL;
62
static const char *remhost = NULL;
60
63
64
static void die(const char *, ...) __attribute__ ((noreturn));
65
61
static void die(const char *fmt, ...) {
66
static void die(const char *fmt, ...) {
62
   va_list ap;
67
   va_list ap;
63
   fprintf(stderr, "telnetlogin: ");
68
   openlog("telnetlogin", LOG_PID, LOG_AUTHPRIV);
64
   va_start(ap, fmt);
69
   va_start(ap, fmt);
65
   vfprintf(stderr, fmt, ap);
70
   vsyslog(LOG_CRIT, fmt, ap);
66
   va_end(ap);
71
   va_end(ap);
67
   fprintf(stderr, "\n");
68
   exit(1);
72
   exit(1);
69
}
73
}
70
74
Lines 86-126 Link Here
86
   return 0;
90
   return 0;
87
}
91
}
88
92
89
static int check_display(char *disp) {
90
   char *colon, *s;
91
   struct hostent *hp;
92
   int num;
93
94
   colon = strchr(disp, ':');
95
   if (!colon) return -1;
96
   *colon = 0;  /* temporarily */
97
98
   if (check_a_hostname(disp)) return -1;
99
100
   hp = gethostbyname(disp);
101
   if (!hp) return -1;
102
103
   *colon = ':';
104
   s = colon+1;
105
   while (*s && isdigit(*s)) s++;
106
   if (*s) {
107
      if (*s!='.') return -1;
108
      s++;
109
      while (*s && isdigit(*s)) s++;
110
   }
111
   if (*s) return -1;
112
113
   num = atoi(colon+1);
114
   if (num<0 || num>99) return -1;
115
116
   return 0;
117
}
118
119
static int check_posixly_correct(char *val) {
120
   if (strlen(val)==0 || !strcmp(val, "1")) return 0;
121
   return -1;
122
}
123
124
static int check_remotehost(char *val) {
93
static int check_remotehost(char *val) {
125
   if (check_a_hostname(val)) return -1;
94
   if (check_a_hostname(val)) return -1;
126
   if (remhost && strcmp(val, remhost)) return -1;
95
   if (remhost && strcmp(val, remhost)) return -1;
Lines 132-139 Link Here
132
   int (*validator)(char *);
101
   int (*validator)(char *);
133
} legal_envs[] = {
102
} legal_envs[] = {
134
   { "TERM", check_term },
103
   { "TERM", check_term },
135
   { "DISPLAY", check_display },
136
   { "POSIXLY_CORRECT", check_posixly_correct },
137
   { "REMOTEHOST", check_remotehost },
104
   { "REMOTEHOST", check_remotehost },
138
   { NULL, NULL }
105
   { NULL, NULL }
139
};
106
};
Lines 166-175 Link Here
166
   static char argv0[] = "login";
133
   static char argv0[] = "login";
167
   int argn, i, j;
134
   int argn, i, j;
168
   const char *rh = NULL;
135
   const char *rh = NULL;
169
   char **envs = __environ;
136
   char **envs = environ;
170
171
   /* make as sure as possible no library routines or anything can use it */
172
   __environ = NULL;
173
137
174
   /* first, make sure our stdin/stdout/stderr are aimed somewhere */
138
   /* first, make sure our stdin/stdout/stderr are aimed somewhere */
175
   i = open("/", O_RDONLY);
139
   i = open("/", O_RDONLY);
Lines 194-199 Link Here
194
   if (argn < argc && !strcmp(argv[argn], "-p")) {
158
   if (argn < argc && !strcmp(argv[argn], "-p")) {
195
      argn++;
159
      argn++;
196
   }
160
   }
161
   if (argn < argc && argv[argn][0] != '-') {
162
      argn++;
163
   }
197
   if (argn < argc) die("Illegal args: too many args");
164
   if (argn < argc) die("Illegal args: too many args");
198
   argv[0] = argv0;
165
   argv[0] = argv0;
199
166
Lines 201-221 Link Here
201
   if (envs) for (i=0; envs[i]; i++) {
168
   if (envs) for (i=0; envs[i]; i++) {
202
      char *testenv = envs[i];
169
      char *testenv = envs[i];
203
      size_t testlen = strlen(testenv);
170
      size_t testlen = strlen(testenv);
204
      int ok = 0;
171
      for (j=0; legal_envs[j].name; j++) {
205
      for (j=0; legal_envs[j].name && !ok; j++) {
206
	 const char *okenv = legal_envs[j].name;
172
	 const char *okenv = legal_envs[j].name;
207
	 size_t oklen = strlen(okenv);
173
	 size_t oklen = strlen(okenv);
174
	 int sign;
208
175
209
	 if (testlen < oklen) continue;
176
	 if (testlen < oklen) continue;
210
	 if (testenv[oklen]!='=') continue;
177
	 if (testenv[oklen]!='=') continue;
211
	 if (memcmp(testenv, okenv, oklen)) continue;
178
	 if ((sign = memcmp(testenv, okenv, oklen)) < 0) {
179
	    continue;
180
	 } else if (sign > 0) {
181
	    break;
182
	 }
212
	 if (legal_envs[j].validator(testenv+oklen+1)) {
183
	 if (legal_envs[j].validator(testenv+oklen+1)) {
213
	    die("Invalid environment: bad value for %s", okenv);
184
	    die("Invalid environment: bad value for %s", okenv);
214
	 }
185
	 }
215
	 ok = 1;
186
	 break;
216
      }
217
      if (!ok) {
218
	 die("Illegal environment: forbidden variable");
219
      }
187
      }
220
   }
188
   }
221
189
Lines 234-239 Link Here
234
    * but, should we insist that ruid==nobody?
202
    * but, should we insist that ruid==nobody?
235
    */
203
    */
236
204
205
#ifdef debian
206
   /*
207
    * Debian's /bin/login doesn't work properly unless we're really root.
208
    */
209
   setuid(0);
210
#endif
211
237
   /*
212
   /*
238
    * don't do anything with limits, itimers, or process priority either
213
    * don't do anything with limits, itimers, or process priority either
239
    */
214
    */

Return to bug 64632