diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-03-28 23:22:07 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-03-28 23:22:07 +0000 |
commit | dec5be20ee416901a8dc22b58b852c9d03c1cdd1 (patch) | |
tree | 9274bfde6f93cf450bb439ee0bf161ec17593867 /libexec/telnetd/telnetd.c | |
parent | f7c957824795353af8c467307cbe4b14a3a048c4 (diff) |
From NetBSD: merge of 960317
Diffstat (limited to 'libexec/telnetd/telnetd.c')
-rw-r--r-- | libexec/telnetd/telnetd.c | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/libexec/telnetd/telnetd.c b/libexec/telnetd/telnetd.c index 4ba7ae74357..43d6062e23f 100644 --- a/libexec/telnetd/telnetd.c +++ b/libexec/telnetd/telnetd.c @@ -1,3 +1,6 @@ +/* $OpenBSD: telnetd.c,v 1.2 1996/03/28 23:22:03 niklas Exp $ */ +/* $NetBSD: telnetd.c,v 1.5 1996/02/28 20:38:23 thorpej Exp $ */ + /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -38,13 +41,20 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -/* from: static char sccsid[] = "@(#)telnetd.c 8.1 (Berkeley) 6/4/93"; */ -static char *rcsid = "$Id: telnetd.c,v 1.1 1995/10/18 08:43:24 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; +static char rcsid[] = "$NetBSD: telnetd.c,v 1.5 1996/02/28 20:38:23 thorpej Exp $"; +#else +static char rcsid[] = "$OpenBSD: telnetd.c,v 1.2 1996/03/28 23:22:03 niklas Exp $"; +#endif #endif /* not lint */ #include "telnetd.h" #include "pathnames.h" +#include <sys/cdefs.h> +#define P __P + #if defined(_SC_CRAY_SECURE_SYS) && !defined(SCM_SECURITY) /* * UNICOS 6.0/6.1 do not have SCM_SECURITY defined, so we can @@ -435,7 +445,7 @@ main(argc, argv) int szi = sizeof(int); #endif /* SO_SEC_MULTI */ - bzero((char *)&dv, sizeof(dv)); + memset((char *)&dv, 0, sizeof(dv)); if (getsysv(&sysv, sizeof(struct sysv)) != 0) { perror("getsysv"); @@ -606,34 +616,40 @@ getterminaltype(name) static unsigned char sb[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE }; - bcopy(sb, nfrontp, sizeof sb); + memmove(nfrontp, sb, sizeof sb); nfrontp += sizeof sb; + DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2);); } if (his_state_is_will(TELOPT_XDISPLOC)) { static unsigned char sb[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE }; - bcopy(sb, nfrontp, sizeof sb); + memmove(nfrontp, sb, sizeof sb); nfrontp += sizeof sb; + DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2);); } if (his_state_is_will(TELOPT_NEW_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE }; - bcopy(sb, nfrontp, sizeof sb); + memmove(nfrontp, sb, sizeof sb); nfrontp += sizeof sb; + DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2);); } else if (his_state_is_will(TELOPT_OLD_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE }; - bcopy(sb, nfrontp, sizeof sb); + memmove(nfrontp, sb, sizeof sb); nfrontp += sizeof sb; + DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2);); } if (his_state_is_will(TELOPT_TTYPE)) { - bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf); + memmove(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf); nfrontp += sizeof ttytype_sbbuf; + DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2, + sizeof ttytype_sbbuf - 2);); } if (his_state_is_will(TELOPT_TSPEED)) { while (sequenceIs(tspeedsubopt, baseline)) @@ -706,8 +722,10 @@ _gettermname() if (his_state_is_wont(TELOPT_TTYPE)) return; settimer(baseline); - bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf); + memmove(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf); nfrontp += sizeof ttytype_sbbuf; + DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2, + sizeof ttytype_sbbuf - 2);); while (sequenceIs(ttypesubopt, baseline)) ttloop(); } @@ -785,7 +803,7 @@ doit(who) #if defined(_SC_CRAY_SECURE_SYS) /* - * set ttyp line security label + * set ttyp line security label */ if (secflag) { char slave_dev[16]; @@ -805,9 +823,10 @@ doit(who) if (hp == NULL && registerd_host_only) { fatal(net, "Couldn't resolve your address into a host name.\r\n\ - Please contact your net administrator"); + Please contact your net administrator"); } else if (hp && - (strlen(hp->h_name) <= ((utmp_len < 0) ? -utmp_len : utmp_len))) { + (strlen(hp->h_name) <= (unsigned int)((utmp_len < 0) ? -utmp_len + : utmp_len))) { host = hp->h_name; } else { host = inet_ntoa(who->sin_addr); @@ -896,6 +915,7 @@ telnet(f, p, host) char *HN; char *IM; void netflush(); + int nfd; /* * Initialize the slc mapping table. @@ -1125,6 +1145,7 @@ telnet(f, p, host) startslave(host); #endif + nfd = ((f > p) ? f : p) + 1; for (;;) { fd_set ibits, obits, xbits; register int c; @@ -1156,7 +1177,7 @@ telnet(f, p, host) if (!SYNCHing) { FD_SET(f, &xbits); } - if ((c = select(16, &ibits, &obits, &xbits, + if ((c = select(nfd, &ibits, &obits, &xbits, (struct timeval *)0)) < 1) { if (c == -1) { if (errno == EINTR) { @@ -1295,6 +1316,9 @@ telnet(f, p, host) *nfrontp++ = IAC; *nfrontp++ = DM; neturg = nfrontp-1; /* off by one XXX */ + DIAG(TD_OPTIONS, + printoption("td: send IAC", DM)); + #endif } if (his_state_is_will(TELOPT_LFLOW) && @@ -1311,6 +1335,9 @@ telnet(f, p, host) : LFLOW_OFF, IAC, SE); nfrontp += 6; + DIAG(TD_OPTIONS, printsub('>', + (unsigned char *)nfrontp-4, + 4);); } } pcc--; @@ -1369,7 +1396,7 @@ telnet(f, p, host) } cleanup(0); } /* end of telnet */ - + #ifndef TCSIG # ifdef TIOCSIG # define TCSIG TIOCSIG @@ -1445,7 +1472,7 @@ int readstream(p, ibuf, bufsize) tp = (struct termio *) (ibuf+1 + sizeof(struct iocblk)); vstop = tp->c_cc[VSTOP]; vstart = tp->c_cc[VSTART]; - ixon = tp->c_iflag & IXON; + ixon = tp->c_iflag & IXON; break; default: errno = EAGAIN; @@ -1476,6 +1503,14 @@ interrupt() { ptyflush(); /* half-hearted */ +#if defined(STREAMSPTY) && defined(TIOCSIGNAL) + /* Streams PTY style ioctl to post a signal */ + { + int sig = SIGINT; + (void) ioctl(pty, TIOCSIGNAL, &sig); + (void) ioctl(pty, I_FLUSH, FLUSHR); + } +#else #ifdef TCSIG (void) ioctl(pty, TCSIG, (char *)SIGINT); #else /* TCSIG */ @@ -1483,6 +1518,7 @@ interrupt() *pfrontp++ = slctab[SLC_IP].sptr ? (unsigned char)*slctab[SLC_IP].sptr : '\177'; #endif /* TCSIG */ +#endif } /* |