MFC: no \n in syslog strings. Change -P to -p in flags. EOF -> -1. Use err(3).

git-svn-id: http://svn0.us-east.freebsd.org/base/head/contrib/telnet@31622 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
This commit is contained in:
charnier
1997-12-08 07:41:13 +00:00
parent d16b9a5166
commit 4f7c22a987
9 changed files with 165 additions and 139 deletions

View File

@@ -32,7 +32,11 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static const char sccsid[] = "@(#)authenc.c 8.2 (Berkeley) 5/30/95"; static const char sccsid[] = "@(#)authenc.c 8.2 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#if defined(AUTHENTICATION) || defined(ENCRYPTION) #if defined(AUTHENTICATION) || defined(ENCRYPTION)
@@ -75,7 +79,6 @@ telnet_spin()
telnet_getenv(val) telnet_getenv(val)
char *val; char *val;
{ {
extern char *getenv();
return(getenv(val)); return(getenv(val));
} }

View File

@@ -32,7 +32,11 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static const char sccsid[] = "@(#)global.c 8.1 (Berkeley) 6/4/93"; static const char sccsid[] = "@(#)global.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
/* /*

View File

@@ -32,14 +32,18 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static const char sccsid[] = "@(#)slc.c 8.2 (Berkeley) 5/30/95"; static const char sccsid[] = "@(#)slc.c 8.2 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include "telnetd.h" #include "telnetd.h"
#ifdef LINEMODE #ifdef LINEMODE
/* /*
* local varibles * local variables
*/ */
static unsigned char *def_slcbuf = (unsigned char *)0; static unsigned char *def_slcbuf = (unsigned char *)0;
static int def_slclen = 0; static int def_slclen = 0;

View File

@@ -32,7 +32,11 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static const char sccsid[] = "@(#)state.c 8.5 (Berkeley) 5/30/95"; static const char sccsid[] = "@(#)state.c 8.5 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include "telnetd.h" #include "telnetd.h"
@@ -358,7 +362,7 @@ gotiac: switch (c) {
continue; continue;
default: default:
syslog(LOG_ERR, "telnetd: panic state=%d\n", state); syslog(LOG_ERR, "panic state=%d", state);
printf("telnetd: panic state=%d\n", state); printf("telnetd: panic state=%d\n", state);
exit(1); exit(1);
} }

View File

@@ -32,7 +32,11 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static const char sccsid[] = "@(#)sys_term.c 8.4+1 (Berkeley) 5/30/95"; static const char sccsid[] = "@(#)sys_term.c 8.4+1 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include "telnetd.h" #include "telnetd.h"
@@ -184,6 +188,12 @@ int ttyfd = -1;
# endif # endif
#endif /* USE_TERMIO */ #endif /* USE_TERMIO */
#include <sys/types.h>
#include <libutil.h>
int cleanopen __P((char *));
void scrub_env __P((void));
/* /*
* init_termbuf() * init_termbuf()
* copy_termbuf(cp) * copy_termbuf(cp)
@@ -1000,7 +1010,7 @@ struct termspeeds {
#endif #endif
{ -1, 0 } { -1, 0 }
}; };
#endif /* DECODE_BUAD */ #endif /* DECODE_BAUD */
void void
tty_tspeed(val) tty_tspeed(val)
@@ -1014,9 +1024,9 @@ tty_tspeed(val)
if (tp->speed == -1) /* back up to last valid value */ if (tp->speed == -1) /* back up to last valid value */
--tp; --tp;
cfsetospeed(&termbuf, tp->value); cfsetospeed(&termbuf, tp->value);
#else /* DECODE_BUAD */ #else /* DECODE_BAUD */
cfsetospeed(&termbuf, val); cfsetospeed(&termbuf, val);
#endif /* DECODE_BUAD */ #endif /* DECODE_BAUD */
} }
void void
@@ -1075,8 +1085,7 @@ extern void utmp_sig_notify P((int));
* getptyslave() * getptyslave()
* *
* Open the slave side of the pty, and do any initialization * Open the slave side of the pty, and do any initialization
* that is necessary. The return value is a file descriptor * that is necessary.
* for the slave side.
*/ */
void void
getptyslave() getptyslave()
@@ -1789,7 +1798,7 @@ start_login(host, autologin, name)
} }
execv(altlogin, argv); execv(altlogin, argv);
syslog(LOG_ERR, "%s: %m\n", altlogin); syslog(LOG_ERR, "%s: %m", altlogin);
fatalperror(net, altlogin); fatalperror(net, altlogin);
/*NOTREACHED*/ /*NOTREACHED*/
} }
@@ -2088,7 +2097,7 @@ cleantmp(wtp)
utp = getutid(wtp); utp = getutid(wtp);
if (utp == 0) { if (utp == 0) {
syslog(LOG_ERR, "Can't get /etc/utmp entry to clean TMPDIR"); syslog(LOG_ERR, "can't get /etc/utmp entry to clean TMPDIR");
return(-1); return(-1);
} }
/* /*
@@ -2176,12 +2185,12 @@ cleantmpdir(jid, tpath, user)
{ {
switch(fork()) { switch(fork()) {
case -1: case -1:
syslog(LOG_ERR, "TMPDIR cleanup(%s): fork() failed: %m\n", syslog(LOG_ERR, "TMPDIR cleanup(%s): fork() failed: %m",
tpath); tpath);
break; break;
case 0: case 0:
execl(CLEANTMPCMD, CLEANTMPCMD, user, tpath, 0); execl(CLEANTMPCMD, CLEANTMPCMD, user, tpath, 0);
syslog(LOG_ERR, "TMPDIR cleanup(%s): execl(%s) failed: %m\n", syslog(LOG_ERR, "TMPDIR cleanup(%s): execl(%s) failed: %m",
tpath, CLEANTMPCMD); tpath, CLEANTMPCMD);
exit(1); exit(1);
default: default:

View File

@@ -48,13 +48,13 @@ protocol server
.Op Fl X Ar authtype .Op Fl X Ar authtype
.Op Fl a Ar authmode .Op Fl a Ar authmode
.Op Fl edebug .Op Fl edebug
.Op Fl P Ar loginprog .Op Fl p Ar loginprog
.Op Fl r Ns Ar lowpty-highpty .Op Fl r Ns Ar lowpty-highpty
.Op Fl u Ar len .Op Fl u Ar len
.Op Fl debug Op Ar port .Op Fl debug Op Ar port
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm telnetd .Nm
command is a server which supports the command is a server which supports the
.Tn DARPA .Tn DARPA
standard standard
@@ -68,45 +68,45 @@ for requests to connect to the
port as indicated by the port as indicated by the
.Pa /etc/services .Pa /etc/services
file (see file (see
.Xr services 5 ) . .Xr services 5 ).
The The
.Fl debug .Fl debug
option may be used to start up option may be used to start up
.Nm telnetd .Nm
manually, instead of through manually, instead of through
.Xr inetd 8 . .Xr inetd 8 .
If started up this way, If started up this way,
.Ar port .Ar port
may be specified to run may be specified to run
.Nm telnetd .Nm
on an alternate on an alternate
.Tn TCP .Tn TCP
port number. port number.
.Pp .Pp
The The
.Nm telnetd .Nm
command accepts the following options: command accepts the following options:
.Bl -tag -width "-a authmode" .Bl -tag -width indent
.It Fl a Ar authmode .It Fl a Ar authmode
This option may be used for specifying what mode should This option may be used for specifying what mode should
be used for authentication. be used for authentication.
Note that this option is only useful if Note that this option is only useful if
.Nm telnetd .Nm
has been compiled with support for the has been compiled with support for the
.Dv AUTHENTICATION .Dv AUTHENTICATION
option. option.
There are several valid values for There are several valid values for
.Ar authmode: .Ar authmode :
.Bl -tag -width debug .Bl -tag -width debug
.It debug .It Cm debug
Turns on authentication debugging code. Turn on authentication debugging code.
.It user .It Cm user
Only allow connections when the remote user Only allow connections when the remote user
can provide valid authentication information can provide valid authentication information
to identify the remote user, to identify the remote user,
and is allowed access to the specified account and is allowed access to the specified account
without providing a password. without providing a password.
.It valid .It Cm valid
Only allow connections when the remote user Only allow connections when the remote user
can provide valid authentication information can provide valid authentication information
to identify the remote user. to identify the remote user.
@@ -115,14 +115,14 @@ The
command will provide any additional user verification command will provide any additional user verification
needed if the remote user is not allowed automatic needed if the remote user is not allowed automatic
access to the specified account. access to the specified account.
.It other .It Cm other
Only allow connections that supply some authentication information. Only allow connections that supply some authentication information.
This option is currently not supported This option is currently not supported
by any of the existing authentication mechanisms, by any of the existing authentication mechanisms,
and is thus the same as specifying and is thus the same as specifying
.Fl a .Fl a
.Cm valid . .Cm valid .
.It none .It Cm none
This is the default state. This is the default state.
Authentication information is not required. Authentication information is not required.
If no or insufficient authentication information If no or insufficient authentication information
@@ -130,15 +130,15 @@ is provided, then the
.Xr login 1 .Xr login 1
program will provide the necessary user program will provide the necessary user
verification. verification.
.It off .It Cm off
This disables the authentication code. Disable the authentication code.
All user verification will happen through the All user verification will happen through the
.Xr login 1 .Xr login 1
program. program.
.El .El
.It Fl B .It Fl B
Specifies bftp server mode. In this mode, Specify bftp server mode. In this mode,
.Nm telnetd .Nm
causes login to start a causes login to start a
.Xr bftp 1 .Xr bftp 1
session rather than the user's session rather than the user's
@@ -150,51 +150,51 @@ port.
.It Fl D Ar debugmode .It Fl D Ar debugmode
This option may be used for debugging purposes. This option may be used for debugging purposes.
This allows This allows
.Nm telnetd .Nm
to print out debugging information to print out debugging information
to the connection, allowing the user to see what to the connection, allowing the user to see what
.Nm telnetd .Nm
is doing. is doing.
There are several possible values for There are several possible values for
.Ar debugmode: .Ar debugmode :
.Bl -tag -width exercise .Bl -tag -width exercise
.It Cm options .It Cm options
Prints information about the negotiation of Print information about the negotiation of
.Tn TELNET .Tn TELNET
options. options.
.It Cm report .It Cm report
Prints the Print the
.Cm options .Cm options
information, plus some additional information information, plus some additional information
about what processing is going on. about what processing is going on.
.It Cm netdata .It Cm netdata
Displays the data stream received by Display the data stream received by
.Nm telnetd. .Nm Ns .
.It Cm ptydata .It Cm ptydata
Displays data written to the pty. Display data written to the pty.
.It Cm exercise .It Cm exercise
Has not been implemented yet. Has not been implemented yet.
.El .El
.It Fl debug .It Fl debug
Enables debugging on each socket created by Enable debugging on each socket created by
.Nm telnetd .Nm
(see (see
.Dv SO_DEBUG .Dv SO_DEBUG
in in
.Xr socket 2 ) . .Xr socket 2 ) .
.It Fl edebug .It Fl edebug
If If
.Nm telnetd .Nm
has been compiled with support for data encryption, then the has been compiled with support for data encryption, then the
.Fl edebug .Fl edebug
option may be used to enable encryption debugging code. option may be used to enable encryption debugging code.
.It Fl P Ar loginprog .It Fl p Ar loginprog
Specifies an alternate Specify an alternate
.Xr login 1 .Xr login 1
command to run to complete the login. The alternate command must command to run to complete the login. The alternate command must
understand the same command arguments as the standard login. understand the same command arguments as the standard login.
.It Fl h .It Fl h
Disables the printing of host-specific information before Disable the printing of host-specific information before
login has been completed. login has been completed.
.It Fl I Ar initid .It Fl I Ar initid
This option is only applicable to This option is only applicable to
@@ -210,7 +210,7 @@ is
.Dv fe. .Dv fe.
.It Fl k .It Fl k
This option is only useful if This option is only useful if
.Nm telnetd .Nm
has been compiled with both linemode and kludge linemode has been compiled with both linemode and kludge linemode
support. If the support. If the
.Fl k .Fl k
@@ -218,12 +218,12 @@ option is specified, then if the remote client does not
support the support the
.Dv LINEMODE .Dv LINEMODE
option, then option, then
.Nm telnetd .Nm
will operate in character at a time mode. will operate in character at a time mode.
It will still support kludge linemode, but will only It will still support kludge linemode, but will only
go into kludge linemode if the remote client requests go into kludge linemode if the remote client requests
it. it.
(This is done by by the client sending (This is done by the client sending
.Dv DONT SUPPRESS-GO-AHEAD .Dv DONT SUPPRESS-GO-AHEAD
and and
.Dv DONT ECHO . ) .Dv DONT ECHO . )
@@ -237,7 +237,7 @@ in response to a
.Dv DO TIMING-MARK) .Dv DO TIMING-MARK)
for kludge linemode support. for kludge linemode support.
.It Fl l .It Fl l
Specifies line mode. Tries to force clients to use line- Specify line mode. Try to force clients to use line-
at-a-time mode. at-a-time mode.
If the If the
.Dv LINEMODE .Dv LINEMODE
@@ -247,7 +247,7 @@ into kludge linemode.
Disable Disable
.Dv TCP .Dv TCP
keep-alives. Normally keep-alives. Normally
.Nm telnetd .Nm
enables the enables the
.Tn TCP .Tn TCP
keep-alive mechanism to probe connections that keep-alive mechanism to probe connections that
@@ -257,7 +257,7 @@ from machines that have crashed or can no longer
be reached may be cleaned up. be reached may be cleaned up.
.It Fl r Ar lowpty-highpty .It Fl r Ar lowpty-highpty
This option is only enabled when This option is only enabled when
.Nm telnetd .Nm
is compiled for is compiled for
.Dv UNICOS. .Dv UNICOS.
It specifies an inclusive range of pseudo-terminal devices to It specifies an inclusive range of pseudo-terminal devices to
@@ -273,14 +273,14 @@ may be omitted to allow changing
either end of the search range. If either end of the search range. If
.Ar lowpty .Ar lowpty
is omitted, the - character is still required so that is omitted, the - character is still required so that
.Nm telnetd .Nm
can differentiate can differentiate
.Ar highpty .Ar highpty
from from
.Ar lowpty . .Ar lowpty .
.It Fl s .It Fl s
This option is only enabled if This option is only enabled if
.Nm telnetd .Nm
is compiled with support for is compiled with support for
.Tn SecurID .Tn SecurID
cards. cards.
@@ -317,7 +317,7 @@ file.
.ne 1i .ne 1i
.It Fl U .It Fl U
This option causes This option causes
.Nm telnetd .Nm
to refuse connections from addresses that to refuse connections from addresses that
cannot be mapped back into a symbolic name cannot be mapped back into a symbolic name
via the via the
@@ -325,14 +325,14 @@ via the
routine. routine.
.It Fl X Ar authtype .It Fl X Ar authtype
This option is only valid if This option is only valid if
.Nm telnetd .Nm
has been built with support for the authentication option. has been built with support for the authentication option.
It disables the use of It disables the use of
.Ar authtype .Ar authtype
authentication, and authentication, and
can be used to temporarily disable can be used to temporarily disable
a specific authentication type without having to recompile a specific authentication type without having to recompile
.Nm telnetd . .Nm Ns .
.El .El
.Pp .Pp
.Nm Telnetd .Nm Telnetd
@@ -354,7 +354,7 @@ between the remote client and the login process.
When a When a
.Tn TELNET .Tn TELNET
session is started up, session is started up,
.Nm telnetd .Nm
sends sends
.Tn TELNET .Tn TELNET
options to the client side indicating options to the client side indicating
@@ -403,25 +403,25 @@ current state of terminal echoing.
When terminal echo is not desired, a When terminal echo is not desired, a
.Dv WILL ECHO .Dv WILL ECHO
is sent to indicate that is sent to indicate that
.Tn telnetd .Nm
will take care of echoing any data that needs to be will take care of echoing any data that needs to be
echoed to the terminal, and then nothing is echoed. echoed to the terminal, and then nothing is echoed.
When terminal echo is desired, a When terminal echo is desired, a
.Dv WONT ECHO .Dv WONT ECHO
is sent to indicate that is sent to indicate that
.Tn telnetd .Nm
will not be doing any terminal echoing, so the will not be doing any terminal echoing, so the
client should do any terminal echoing that is needed. client should do any terminal echoing that is needed.
.It "WILL BINARY" .It "WILL BINARY"
Indicates that the client is willing to send a Indicate that the client is willing to send a
8 bits of data, rather than the normal 7 bits 8 bits of data, rather than the normal 7 bits
of the Network Virtual Terminal. of the Network Virtual Terminal.
.It "WILL SGA" .It "WILL SGA"
Indicates that it will not be sending Indicate that it will not be sending
.Dv IAC GA, .Dv IAC GA,
go ahead, commands. go ahead, commands.
.It "WILL STATUS" .It "WILL STATUS"
Indicates a willingness to send the client, upon Indicate a willingness to send the client, upon
request, of the current status of all request, of the current status of all
.Tn TELNET .Tn TELNET
options. options.
@@ -442,7 +442,7 @@ is sent in response, and the
session is shut down. session is shut down.
.It "WILL ENCRYPT" .It "WILL ENCRYPT"
Only sent if Only sent if
.Nm telnetd .Nm
is compiled with support for data encryption, and is compiled with support for data encryption, and
indicates a willingness to decrypt indicates a willingness to decrypt
the data stream. the data stream.
@@ -455,7 +455,7 @@ options:
.Bl -tag -width "DO AUTHENTICATION" .Bl -tag -width "DO AUTHENTICATION"
.It "DO BINARY" .It "DO BINARY"
Sent to indicate that Sent to indicate that
.Tn telnetd .Nm
is willing to receive an 8 bit data stream. is willing to receive an 8 bit data stream.
.It "DO LFLOW" .It "DO LFLOW"
Requests that the client handle flow control Requests that the client handle flow control
@@ -471,38 +471,38 @@ is received, a
.Dv DONT ECHO .Dv DONT ECHO
will be sent in response. will be sent in response.
.It "DO TERMINAL-TYPE" .It "DO TERMINAL-TYPE"
Indicates a desire to be able to request the Indicate a desire to be able to request the
name of the type of terminal that is attached name of the type of terminal that is attached
to the client side of the connection. to the client side of the connection.
.It "DO SGA" .It "DO SGA"
Indicates that it does not need to receive Indicate that it does not need to receive
.Dv IAC GA, .Dv IAC GA,
the go ahead command. the go ahead command.
.It "DO NAWS" .It "DO NAWS"
Requests that the client inform the server when Requests that the client inform the server when
the window (display) size changes. the window (display) size changes.
.It "DO TERMINAL-SPEED" .It "DO TERMINAL-SPEED"
Indicates a desire to be able to request information Indicate a desire to be able to request information
about the speed of the serial line to which about the speed of the serial line to which
the client is attached. the client is attached.
.It "DO XDISPLOC" .It "DO XDISPLOC"
Indicates a desire to be able to request the name Indicate a desire to be able to request the name
of the X windows display that is associated with of the X Window System display that is associated with
the telnet client. the telnet client.
.It "DO NEW-ENVIRON" .It "DO NEW-ENVIRON"
Indicates a desire to be able to request environment Indicate a desire to be able to request environment
variable information, as described in RFC 1572. variable information, as described in RFC 1572.
.It "DO ENVIRON" .It "DO ENVIRON"
Indicates a desire to be able to request environment Indicate a desire to be able to request environment
variable information, as described in RFC 1408. variable information, as described in RFC 1408.
.It "DO LINEMODE" .It "DO LINEMODE"
Only sent if Only sent if
.Nm telnetd .Nm
is compiled with support for linemode, and is compiled with support for linemode, and
requests that the client do line by line processing. requests that the client do line by line processing.
.It "DO TIMING-MARK" .It "DO TIMING-MARK"
Only sent if Only sent if
.Nm telnetd .Nm
is compiled with support for both linemode and is compiled with support for both linemode and
kludge linemode, and the client responded with kludge linemode, and the client responded with
.Dv WONT LINEMODE. .Dv WONT LINEMODE.
@@ -515,28 +515,27 @@ Note that the
option can be used to disable this. option can be used to disable this.
.It "DO AUTHENTICATION" .It "DO AUTHENTICATION"
Only sent if Only sent if
.Nm telnetd .Nm
is compiled with support for authentication, and is compiled with support for authentication, and
indicates a willingness to receive authentication indicates a willingness to receive authentication
information for automatic login. information for automatic login.
.It "DO ENCRYPT" .It "DO ENCRYPT"
Only sent if Only sent if
.Nm telnetd .Nm
is compiled with support for data encryption, and is compiled with support for data encryption, and
indicates a willingness to decrypt indicates a willingness to decrypt
the data stream. the data stream.
.Sh ENVIRONMENT .Sh ENVIRONMENT
.Sh FILES .Sh FILES
.Pa /etc/services .Bl -tag -width /usr/ucb/bftp -compact
.br .It Pa /etc/services
.Pa /etc/inittab .It Pa /etc/inittab
(UNICOS systems only) (UNICOS systems only)
.br .It Pa /etc/iptos
.Pa /etc/iptos
(if supported) (if supported)
.br .It Pa /usr/ucb/bftp
.Pa /usr/ucb/bftp
(if supported) (if supported)
.El
.Sh "SEE ALSO" .Sh "SEE ALSO"
.Xr bftp 1 , .Xr bftp 1 ,
.Xr login 1 , .Xr login 1 ,
@@ -594,7 +593,7 @@ commands are only partially implemented.
.Pp .Pp
Because of bugs in the original 4.2 BSD Because of bugs in the original 4.2 BSD
.Xr telnet 1 , .Xr telnet 1 ,
.Nm telnetd .Nm
performs some dubious protocol exchanges to try to discover if the remote performs some dubious protocol exchanges to try to discover if the remote
client is, in fact, a 4.2 BSD client is, in fact, a 4.2 BSD
.Xr telnet 1 . .Xr telnet 1 .

View File

@@ -38,7 +38,11 @@ static const char copyright[] =
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
#if 0
static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include "telnetd.h" #include "telnetd.h"
@@ -53,6 +57,9 @@ static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
# undef _SC_CRAY_SECURE_SYS # undef _SC_CRAY_SECURE_SYS
#endif #endif
#include <err.h>
#include <arpa/inet.h>
#if defined(_SC_CRAY_SECURE_SYS) #if defined(_SC_CRAY_SECURE_SYS)
#include <sys/sysv.h> #include <sys/sysv.h>
#include <sys/secdev.h> #include <sys/secdev.h>
@@ -132,9 +139,11 @@ int lowpty = 0, highpty; /* low, high pty numbers */
int debug = 0; int debug = 0;
int keepalive = 1; int keepalive = 1;
char *progname;
char *altlogin; char *altlogin;
void doit __P((struct sockaddr_in *));
int terminaltypeok __P((char *));
void startslave __P((char *, int, char *));
extern void usage P((void)); extern void usage P((void));
/* /*
@@ -171,14 +180,13 @@ char valid_opts[] = {
'\0' '\0'
}; };
int
main(argc, argv) main(argc, argv)
char *argv[]; char *argv[];
{ {
struct sockaddr_in from; struct sockaddr_in from;
int on = 1, fromlen; int on = 1, fromlen;
register int ch; register int ch;
extern char *optarg;
extern int optind;
#if defined(IPPROTO_IP) && defined(IP_TOS) #if defined(IPPROTO_IP) && defined(IP_TOS)
int tos = -1; int tos = -1;
#endif #endif
@@ -190,8 +198,6 @@ main(argc, argv)
nclearto = 0; nclearto = 0;
#endif /* ENCRYPTION */ #endif /* ENCRYPTION */
progname = *argv;
/* /*
* This initialization causes linemode to default to a configuration * This initialization causes linemode to default to a configuration
* that works on all telnet clients, including the FreeBSD client. * that works on all telnet clients, including the FreeBSD client.
@@ -216,7 +222,7 @@ main(argc, argv)
highpty = getnpty(); highpty = getnpty();
#endif /* CRAY */ #endif /* CRAY */
while ((ch = getopt(argc, argv, valid_opts)) != EOF) { while ((ch = getopt(argc, argv, valid_opts)) != -1) {
switch(ch) { switch(ch) {
#ifdef AUTHENTICATION #ifdef AUTHENTICATION
@@ -241,8 +247,7 @@ main(argc, argv)
*/ */
auth_level = -1; auth_level = -1;
} else { } else {
fprintf(stderr, warnx("unknown authorization level for -a");
"telnetd: unknown authorization level for -a\n");
} }
break; break;
#endif /* AUTHENTICATION */ #endif /* AUTHENTICATION */
@@ -368,12 +373,11 @@ main(argc, argv)
case 'S': case 'S':
#ifdef HAS_GETTOS #ifdef HAS_GETTOS
if ((tos = parsetos(optarg, "tcp")) < 0) if ((tos = parsetos(optarg, "tcp")) < 0)
fprintf(stderr, "%s%s%s\n", warnx("%s%s%s",
"telnetd: Bad TOS argument '", optarg, "bad TOS argument '", optarg,
"'; will try to use default TOS"); "'; will try to use default TOS");
#else #else
fprintf(stderr, "%s%s\n", "TOS option unavailable; ", warnx("TOS option unavailable; -S flag not supported");
"-S flag not supported\n");
#endif #endif
break; break;
@@ -395,7 +399,7 @@ main(argc, argv)
#endif /* AUTHENTICATION */ #endif /* AUTHENTICATION */
default: default:
fprintf(stderr, "telnetd: %c: unknown option\n", ch); warnx("%c: unknown option", ch);
/* FALLTHROUGH */ /* FALLTHROUGH */
case '?': case '?':
usage(); usage();
@@ -420,7 +424,7 @@ main(argc, argv)
} else { } else {
sin.sin_port = atoi(*argv); sin.sin_port = atoi(*argv);
if ((int)sin.sin_port <= 0) { if ((int)sin.sin_port <= 0) {
fprintf(stderr, "telnetd: %s: bad port #\n", *argv); warnx("%s: bad port #", *argv);
usage(); usage();
/* NOT REACHED */ /* NOT REACHED */
} }
@@ -428,34 +432,24 @@ main(argc, argv)
} }
} else { } else {
sp = getservbyname("telnet", "tcp"); sp = getservbyname("telnet", "tcp");
if (sp == 0) { if (sp == 0)
fprintf(stderr, "telnetd: tcp/telnet: unknown service\n"); errx(1, "tcp/telnet: unknown service");
exit(1);
}
sin.sin_port = sp->s_port; sin.sin_port = sp->s_port;
} }
s = socket(AF_INET, SOCK_STREAM, 0); s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) { if (s < 0)
perror("telnetd: socket");; err(1, "socket");
exit(1);
}
(void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(char *)&on, sizeof(on)); (char *)&on, sizeof(on));
if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0) { if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0)
perror("bind"); err(1, "bind");
exit(1); if (listen(s, 1) < 0)
} err(1, "listen");
if (listen(s, 1) < 0) {
perror("listen");
exit(1);
}
foo = sizeof sin; foo = sizeof sin;
ns = accept(s, (struct sockaddr *)&sin, &foo); ns = accept(s, (struct sockaddr *)&sin, &foo);
if (ns < 0) { if (ns < 0)
perror("accept"); err(1, "accept");
exit(1);
}
(void) dup2(ns, 0); (void) dup2(ns, 0);
(void) close(ns); (void) close(ns);
(void) close(s); (void) close(s);
@@ -483,10 +477,8 @@ main(argc, argv)
memset((char *)&dv, 0, sizeof(dv)); memset((char *)&dv, 0, sizeof(dv));
if (getsysv(&sysv, sizeof(struct sysv)) != 0) { if (getsysv(&sysv, sizeof(struct sysv)) != 0)
perror("getsysv"); err(1, "getsysv");
exit(1);
}
/* /*
* Get socket security label and set device values * Get socket security label and set device values
@@ -497,8 +489,7 @@ main(argc, argv)
(char *)&ss, &szss) < 0) || (char *)&ss, &szss) < 0) ||
(getsockopt(0, SOL_SOCKET, SO_SEC_MULTI, (getsockopt(0, SOL_SOCKET, SO_SEC_MULTI,
(char *)&sock_multi, &szi) < 0)) { (char *)&sock_multi, &szi) < 0)) {
perror("getsockopt"); err(1, "getsockopt");
exit(1);
} else { } else {
dv.dv_actlvl = ss.ss_actlabel.lt_level; dv.dv_actlvl = ss.ss_actlabel.lt_level;
dv.dv_actcmp = ss.ss_actlabel.lt_compart; dv.dv_actcmp = ss.ss_actlabel.lt_compart;
@@ -528,8 +519,7 @@ main(argc, argv)
openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON); openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
fromlen = sizeof (from); fromlen = sizeof (from);
if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) { if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
fprintf(stderr, "%s: ", progname); warn("getpeername");
perror("getpeername");
_exit(1); _exit(1);
} }
if (keepalive && if (keepalive &&
@@ -557,12 +547,13 @@ main(argc, argv)
net = 0; net = 0;
doit(&from); doit(&from);
/* NOTREACHED */ /* NOTREACHED */
return(0);
} /* end of main */ } /* end of main */
void void
usage() usage()
{ {
fprintf(stderr, "Usage: telnetd"); fprintf(stderr, "usage: telnetd");
#ifdef AUTHENTICATION #ifdef AUTHENTICATION
fprintf(stderr, " [-a (debug|other|user|valid|off|none)]\n\t"); fprintf(stderr, " [-a (debug|other|user|valid|off|none)]\n\t");
#endif #endif
@@ -821,11 +812,11 @@ char user_name[256];
/* /*
* Get a pty, scan input lines. * Get a pty, scan input lines.
*/ */
void void
doit(who) doit(who)
struct sockaddr_in *who; struct sockaddr_in *who;
{ {
char *host, *inet_ntoa(); char *host = NULL;
struct hostent *hp; struct hostent *hp;
int ptynum; int ptynum;
@@ -1105,9 +1096,9 @@ telnet(f, p, host)
* side. Set up signal handler now. * side. Set up signal handler now.
*/ */
if ((int)signal(SIGUSR1, termstat) < 0) if ((int)signal(SIGUSR1, termstat) < 0)
perror("signal"); warn("signal");
else if (ioctl(p, TCSIGME, (char *)SIGUSR1) < 0) else if (ioctl(p, TCSIGME, (char *)SIGUSR1) < 0)
perror("ioctl:TCSIGME"); warn("ioctl:TCSIGME");
/* /*
* Make processing loop check terminal characteristics early on. * Make processing loop check terminal characteristics early on.
*/ */

View File

@@ -32,7 +32,11 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static const char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95"; static const char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include "telnetd.h" #include "telnetd.h"

View File

@@ -32,7 +32,11 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static const char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95"; static const char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#ifdef __FreeBSD__ #ifdef __FreeBSD__
@@ -73,10 +77,10 @@ ttloop()
} }
ncc = read(net, netibuf, sizeof netibuf); ncc = read(net, netibuf, sizeof netibuf);
if (ncc < 0) { if (ncc < 0) {
syslog(LOG_INFO, "ttloop: read: %m\n"); syslog(LOG_INFO, "ttloop: read: %m");
exit(1); exit(1);
} else if (ncc == 0) { } else if (ncc == 0) {
syslog(LOG_INFO, "ttloop: peer died: %m\n"); syslog(LOG_INFO, "ttloop: peer died: %m");
exit(1); exit(1);
} }
DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop read %d chars\r\n", ncc); DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop read %d chars\r\n", ncc);
@@ -391,7 +395,6 @@ edithost(pat, host)
register char *host; register char *host;
{ {
register char *res = editedhost; register char *res = editedhost;
char *strncpy();
if (!pat) if (!pat)
pat = ""; pat = "";
@@ -537,8 +540,7 @@ printsub(direction, pointer, length)
unsigned char *pointer; /* where suboption data sits */ unsigned char *pointer; /* where suboption data sits */
int length; /* length of suboption data */ int length; /* length of suboption data */
{ {
register int i; register int i = 0;
char buf[512];
if (!(diagnostic & TD_OPTIONS)) if (!(diagnostic & TD_OPTIONS))
return; return;
@@ -1012,8 +1014,11 @@ printsub(direction, pointer, length)
"MUTUAL" : "ONE-WAY"); "MUTUAL" : "ONE-WAY");
nfrontp += strlen(nfrontp); nfrontp += strlen(nfrontp);
auth_printsub(&pointer[1], length - 1, buf, sizeof(buf)); {
sprintf(nfrontp, "%s", buf); char buf[512];
auth_printsub(&pointer[1], length - 1, buf, sizeof(buf));
sprintf(nfrontp, "%s", buf);
}
nfrontp += strlen(nfrontp); nfrontp += strlen(nfrontp);
break; break;
@@ -1107,8 +1112,11 @@ printsub(direction, pointer, length)
sprintf(nfrontp, " %d (unknown)", pointer[2]); sprintf(nfrontp, " %d (unknown)", pointer[2]);
nfrontp += strlen(nfrontp); nfrontp += strlen(nfrontp);
encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf)); {
sprintf(nfrontp, "%s", buf); char buf[512];
encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf));
sprintf(nfrontp, "%s", buf);
}
nfrontp += strlen(nfrontp); nfrontp += strlen(nfrontp);
break; break;