Commit Graph

94 Commits

Author SHA1 Message Date
Stephen Heumann
f659286e00 Rewrite environment-cleaning code to not directly modify environ or its contents.
The old code didn't work correctly with GNO's environ implementation and could lead to crashes.
2016-01-09 18:04:58 -06:00
Stephen Heumann
e6c2831323 Work around a GNO kernel bug that could cause crashes in error cases.
The issue is that the kernel's pty structures get corrupted if the master side of a pty is opened and then closed without the slave side having been opened. This can happen with telnetd in various error cases. The workaround is to arrange for the slave side to be opened just before telnetd exits in those cases.
2016-01-09 14:50:21 -06:00
Stephen Heumann
8a3b1e25cd When forking the child process, wait until the child has exec'd before continuing in the parent.
Also includes a few other changes for safety, e.g. making the child exit via QuitGS rather than exit() or _exit().

The vfork_and_run() routine is based on code from my port of hush.
2016-01-09 12:46:38 -06:00
Stephen Heumann
494c69cf82 Eliminate large stack-allocated buffers, and set the stack size to 1.5k.
Also includes code to check the stack usage, which in my testing showed a maximum of 1025 bytes.
2016-01-08 23:45:11 -06:00
Stephen Heumann
7f21186a25 Don't try to use pty packet mode on GNO, which doesn't support it. 2016-01-08 17:54:14 -06:00
Stephen Heumann
cc929f87ce Don't generate log messages about "setsockopt (IP_TOS)" not working on GNO.
This isn't currently supported by MariGNOtti, so it always generates the message, but it's really not important.
2016-01-07 20:19:25 -06:00
Stephen Heumann
e761e0fc48 Use correct path for login on GNO. 2016-01-07 20:07:53 -06:00
Stephen Heumann
a995ff4eb5 Environment handling on GNO
*Initialize environ on startup
*Separate child process environment from parent
2016-01-06 20:39:54 -06:00
Stephen Heumann
03a535e170 Change hardcoded fds to STDIN_FILENO and STDERR_FILENO. 2015-06-10 23:23:50 -05:00
Stephen Heumann
7968e76e4a telnetd: Change hardcoded 0s for stdin to STDIN_FILENO. 2015-06-02 21:59:22 -05:00
Stephen Heumann
1d35c61146 Misc. small changes to remove uses of unavailable functions in telnetd.
Also include libutil for login_tty function.
2015-06-01 20:43:53 -05:00
Stephen Heumann
972e6d98ba Fix a couple link errors in telnetd related to ORCA/C's handling of externs. 2015-06-01 16:42:47 -05:00
Stephen Heumann
af6c2cbe7a Add an implementation for GNO of posix_openpt and related functions for handling ptys. 2015-06-01 16:25:56 -05:00
Stephen Heumann
391736d065 Remove source files needed only for authentication or encryption, which we've disabled. 2015-05-31 22:55:19 -05:00
Stephen Heumann
ff78ce7134 Add missing vasprintf function 2015-05-31 21:11:05 -05:00
Stephen Heumann
4f442220c5 Add strlcpy, which GNO's libc doesn't have. 2015-05-31 20:23:06 -05:00
Stephen Heumann
923ec4e425 Transform (v)fork calls to use GNO's fork2 call. 2015-05-31 19:54:10 -05:00
Stephen Heumann
de9fad8d67 More small changes for GNO and ORCA/C compatibility.
In particular, address a couple instances where GNO's sockets implementation doesn't comply with modern standards.
Also, add a few missing prototypes so we can use ORCA/C prototype-checking lint functionality.
2015-05-31 19:52:28 -05:00
Stephen Heumann
9bab5c3dec Add an implementation of getaddrinfo and getnameinfo, which are missing in GNO.
These are adapted from a version in netperf.
2015-05-31 16:56:05 -05:00
Stephen Heumann
581990e767 Misc. small changes for GNO and ORCA/C compatibility 2015-05-31 15:27:34 -05:00
Stephen Heumann
cfa9287257 Back out recently-added code that uses mmap. 2015-05-31 10:12:25 -05:00
Stephen Heumann
e8c6388223 Get rid of __FBSDID macros, which aren't defined in GNO (and thus prevent compilation). 2015-05-30 22:26:48 -05:00
Stephen Heumann
327170235b 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)
2015-05-30 22:12:01 -05:00
052bf438de Add baud rate support to telnet(1)
This implements part of RFC-2217

It's based off a patch originally written by Sujal Patel at Isilon, and
contributions from other Isilon employees.

PR: 173728
Phabric: D995
Reviewed by: markj, markm
MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Division

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2014-11-11 04:06:05 +00:00
2d43ae29e1 Improve upon previous commit:
1.  Check return of mmap(2) (*)
2.  Avoid FD leak when fstat fails.
3.  Fix style(9).

(*) Pointed out by jmg@

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2014-03-02 03:34:06 +00:00
2c30da6c4a Revive support for /etc/issue, lost due revision 81963.
Obtained from:	Juniper Networks, Inc.

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2014-03-02 00:47:47 +00:00
839f5deaca Propagate ancient fix from Junos.
Use of -h is not supposed to depend on AUTHENTICATION being defined.

Reviewed by: markm

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2013-11-07 00:36:39 +00:00
d37ea43702 Fix "automatic" login, broken by revision 69825 (12 years, 5 months ago).
The "automatic" login feature is described as follows:
The USER environment variable holds the name of the person telnetting in.
This is the username of the person on the client machine. The traditional
behaviour is to execute login(1) with this username first, meaning that
login(1) will prompt for the password only. If login fails, login(1) will
retry, but now prompt for the username before prompting for the password.

This feature got broken by how the environment got scrubbed. Before the
change in r69825 we removed variables that we deemed dangerous. Starting
with r69825 we only keep those variable we know to be safe.

The USER environment variable fell through the cracks. It suddenly got
scrubbed (i.e. removed from the environment) while still being checked
for. It also got explicitly removed from the environment to handle the
failed login case.

The fix is to obtain the value of the USER environment variable before
we scrub the environment and used the "cached" in subsequent checks.
This guarantees that the environment does not contain the USER variable
in the end, while still being able to implement "automatic" login.

Obtained from:	Juniper Networks, Inc.

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2013-05-31 17:30:12 +00:00
6b099757e8 Make sure that each va_start has one and only one matching va_end,
especially in error cases.

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2012-09-28 07:51:30 +00:00
bd32956cba In contrib/telnet/telnetd/utility.c, fix a few warnings about format
strings not being literals.

MFC after:	1 week

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2011-12-16 16:53:54 +00:00
b3741997b0 Forgot a part that was missing in the previous commit.
There is no need to call trimdomain() anymore now that ut_host is big
enough to fit decent hostnames.

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2010-01-13 18:46:50 +00:00
22cdf6fd37 Let telnetd build without utmp and logwtmp(3).
Just like rlogind, there is no need to change the ownership of the
terminal during shutdown anymore. Also don't call logwtmp, because the
login(1)/PAM is responsible for doing this. Also use SHUT_RDWR instead
of 2.

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2010-01-13 18:37:42 +00:00
29b3953035 Remove unneeded inclusion of <utmp.h> and dead variables.
git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2009-12-27 11:56:32 +00:00
1d2eb11519 Correctly scrub telnetd's environment.
Approved by:	so (cperciva)
Security:	FreeBSD-SA-09:05.telnetd

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2009-02-16 21:56:17 +00:00
8d9786e342 Use strlcpy() instead of strcpy().
Requested by:	mlaier

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2008-11-13 20:40:38 +00:00
7aa7324a8f Convert telnetd(8) to use posix_openpt(2).
Some time ago I got some reports MPSAFE TTY broke telnetd(8). Even
though it turned out to be a different problem within the TTY code, I
spotted a small issue with telnetd(8). Instead of allocating PTY's using
openpty(3) or posix_openpt(2), it used its own PTY allocation routine.
This means that telnetd(8) still uses /dev/ptyXX-style devices.

I've also increased the size of line[]. Even though 16 should be enough,
we already use 13 bytes ("/dev/pts/999", including '\0'). 32 bytes gives
us a little more freedom.

Also enable -DSTREAMSPTY. Otherwise telnetd(8) strips the PTY's pathname
to the latest slash instead of just removing "/dev/" (e.g. /dev/pts/0 ->
0, instead of pts/0).

Reviewed by:	rink

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2008-11-13 19:05:27 +00:00
180a45c5fb List authentication types supported with "-X" taken from the libtelnet

PR:		121721

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2008-08-29 00:04:37 +00:00
d76e719277 Don't attempt authentication at all if it has been disabled via '-a off'.
This works around a bug in HP-UX's telnet client and also gives a much
saner user experience when using FreeBSD's telnet client.

PR:		bin/19405
Submitted by:	Joel Ray Holveck   joelh of
MFC after:	1 month

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2008-07-28 18:58:16 +00:00
7fe816d452 Remove bogus casts of valid integer ioctl() arguments.
git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2006-09-26 21:46:12 +00:00
b88638bb41 NI_WITHSCOPEID cleanup
git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2005-05-21 15:28:42 +00:00
26fb67c648 - Soften sentence breaks.
- Remove double whitespace.
- Sort sections.

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2005-01-21 21:57:05 +00:00
82ff960df9 o Make telnet[d] -S (IP TOS) flag really work. We do not have
/etc/iptos implementation so only numeric values supported.

o telnetd.8: steal the -S flag description from telnet.1, bump
the date of the document.

MFC after:	6 weeks

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2005-01-09 10:24:46 +00:00
10faff8b17 o Add -4 and -6 flags to a man page and usage(). Bump the man page

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2005-01-05 09:59:38 +00:00
5adbfa7aec Add missing () to function invocation.
git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2004-07-28 05:37:18 +00:00
6a39aef766 Implement what has been documented for a long time: make -debug switch
on socket debugging.

Okay'ed by: markm

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2003-08-13 10:56:40 +00:00
4369ac2a7f Fix up external variables named "debug" that have a horrible habit
of conflicting with other, similarly named functions in static
libraries. This is done mostly by renaming the var if it is shared
amongst modules, or making it static otherwise.

OK'ed by:	re(scottl)

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2003-05-11 18:17:00 +00:00
90a2e082b9 Use __FBSDID vs. rcsid[]. Also protect sccs[] and copyright[] from GCC 3.3.
git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2003-05-04 02:54:49 +00:00
5a5138f8df Catch up with "base" telnet.

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2002-09-25 07:28:04 +00:00
e151b0ff25 Don't risk catching a signal while handling a signal for a dying child, as we
can then end up not properly clearing wtmp/utmp entries.

PR:		bin/37934
Submitted by:	Sandeep Kumar <>
Reviewed by:	markm
MFC after:	2 weeks

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2002-05-27 08:10:24 +00:00
48a0b67941 Don't use non-signal-safe functions (exit(3) in this case) in
signal handlers.  In this case, use _exit(2) instead, following
the call to shutdown(2).

This fixes rare telnetd hangs.

PR:		misc/33672
Submitted by:	Umesh Krishnaswamy <>
MFC after:	1 month

git-svn-id: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2002-02-05 15:20:02 +00:00