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