telnet/telnet-0.17-sa-01-49.patch

209 lines
5.4 KiB
Diff

diff -up netkit-telnet-0.17/telnetd/ext.h.sa-01-49 netkit-telnet-0.17/telnetd/ext.h
--- netkit-telnet-0.17/telnetd/ext.h.sa-01-49 1999-12-12 15:59:44.000000000 +0100
+++ netkit-telnet-0.17/telnetd/ext.h 2011-01-20 22:39:54.000000000 +0100
@@ -86,7 +86,10 @@ extern char *neturg; /* one past last b
extern int pcc, ncc;
/* printf into netobuf */
-void netoprintf(const char *fmt, ...) __attribute((format (printf, 1, 2)));
+/* void netoprintf(const char *fmt, ...) __attribute((format (printf, 1, 2))); */
+#define netoprintf output_data
+int output_data(const char *, ...) __attribute((format (printf, 1, 2)));
+void output_datalen(const char *, int);
extern int pty, net;
extern char *line;
@@ -182,7 +185,10 @@ void tty_setsofttab(int);
void tty_tspeed(int);
void willoption(int);
void wontoption(int);
+
+#if 0
void writenet(unsigned char *, int);
+#endif
#if defined(ENCRYPT)
extern void (*encrypt_output)(unsigned char *, int);
diff -up netkit-telnet-0.17/telnetd/slc.c.sa-01-49 netkit-telnet-0.17/telnetd/slc.c
--- netkit-telnet-0.17/telnetd/slc.c.sa-01-49 1999-12-12 15:59:44.000000000 +0100
+++ netkit-telnet-0.17/telnetd/slc.c 2011-01-20 22:39:54.000000000 +0100
@@ -183,7 +183,7 @@ int end_slc(unsigned char **bufp) {
else {
snprintf(slcbuf+slcoff, sizeof(slcbuf)-slcoff, "%c%c", IAC, SE);
slcoff += 2;
- writenet(slcbuf, slcoff);
+ output_datalen(slcbuf, slcoff);
netflush(); /* force it out immediately */
}
}
diff -up netkit-telnet-0.17/telnetd/state.c.sa-01-49 netkit-telnet-0.17/telnetd/state.c
--- netkit-telnet-0.17/telnetd/state.c.sa-01-49 1999-12-12 20:41:44.000000000 +0100
+++ netkit-telnet-0.17/telnetd/state.c 2011-01-20 22:43:34.000000000 +0100
@@ -37,6 +37,7 @@
char state_rcsid[] =
"$Id: state.c,v 1.12 1999/12/12 19:41:44 dholland Exp $";
+#include <stdarg.h>
#include "telnetd.h"
int not42 = 1;
@@ -1365,7 +1366,7 @@ void send_status(void) {
ADD(IAC);
ADD(SE);
- writenet(statusbuf, ncp - statusbuf);
+ output_datalen(statusbuf, ncp - statusbuf);
netflush(); /* Send it on its way */
DIAG(TD_OPTIONS, {printsub('>', statusbuf, ncp - statusbuf); netflush();});
diff -up netkit-telnet-0.17/telnetd/termstat.c.sa-01-49 netkit-telnet-0.17/telnetd/termstat.c
--- netkit-telnet-0.17/telnetd/termstat.c.sa-01-49 1999-12-12 15:59:45.000000000 +0100
+++ netkit-telnet-0.17/telnetd/termstat.c 2011-01-20 22:39:54.000000000 +0100
@@ -128,7 +128,6 @@ static int _terminit = 0;
void
localstat()
{
- void netflush();
int need_will_echo = 0;
/*
diff -up netkit-telnet-0.17/telnetd/utility.c.sa-01-49 netkit-telnet-0.17/telnetd/utility.c
--- netkit-telnet-0.17/telnetd/utility.c.sa-01-49 2011-01-20 22:39:54.000000000 +0100
+++ netkit-telnet-0.17/telnetd/utility.c 2011-01-20 22:48:02.000000000 +0100
@@ -38,8 +38,10 @@ char util_rcsid[] =
"$Id: utility.c,v 1.11 1999/12/12 14:59:45 dholland Exp $";
#define PRINTOPTIONS
+#define _GNU_SOURCE
#include <stdarg.h>
+#include <stdio.h>
#include <sys/utsname.h>
#ifdef AUTHENTICATE
@@ -52,6 +54,53 @@ char util_rcsid[] =
* utility functions performing io related tasks
*/
+/*
+ * This function appends data to nfrontp and advances nfrontp.
+ * Returns the number of characters written altogether (the
+ * buffer may have been flushed in the process).
+ */
+
+int
+output_data(const char *format, ...)
+{
+ va_list args;
+ int len;
+ char *buf;
+
+ va_start(args, format);
+ if ((len = vasprintf(&buf, format, args)) == -1)
+ return -1;
+ output_datalen(buf, len);
+ va_end(args);
+ free(buf);
+ return (len);
+}
+
+void
+output_datalen(const char *buf, int len)
+{
+ int remaining, copied;
+
+ remaining = BUFSIZ - (nfrontp - netobuf);
+ while (len > 0) {
+ /* Free up enough space if the room is too low*/
+ if ((len > BUFSIZ ? BUFSIZ : len) > remaining) {
+ netflush();
+ remaining = BUFSIZ - (nfrontp - netobuf);
+ }
+
+ /* Copy out as much as will fit */
+ copied = remaining > len ? len : remaining;
+ memmove(nfrontp, buf, copied);
+ nfrontp += copied;
+ len -= copied;
+ remaining -= copied;
+ buf += copied;
+ }
+ return;
+}
+
+/**
void
netoprintf(const char *fmt, ...)
{
@@ -67,7 +116,7 @@ netoprintf(const char *fmt, ...)
va_end(ap);
if (len<0 || len==maxsize) {
- /* didn't fit */
+ / * did not fit * /
netflush();
}
else {
@@ -76,6 +125,7 @@ netoprintf(const char *fmt, ...)
}
nfrontp += len;
}
+*/
/*
* ttloop
@@ -273,10 +323,15 @@ netflush(void)
int n;
if ((n = nfrontp - nbackp) > 0) {
+
+#if 0
+ /* XXX This causes output_data() to recurse and die */
DIAG(TD_REPORT,
{ netoprintf("td: netflush %d chars\r\n", n);
n = nfrontp - nbackp; /* update count */
});
+#endif
+
#if defined(ENCRYPT)
if (encrypt_output) {
char *s = nclearto ? nclearto : nbackp;
@@ -310,11 +365,14 @@ netflush(void)
}
}
}
- if (n < 0) {
- if (errno == EWOULDBLOCK || errno == EINTR)
- return;
- cleanup(0);
- }
+
+ if (n == -1) {
+ if (errno == EWOULDBLOCK || errno == EINTR)
+ return;
+ cleanup(0);
+ /* NOTREACHED */
+ }
+
nbackp += n;
#if defined(ENCRYPT)
if (nbackp > nclearto)
@@ -332,7 +390,7 @@ netflush(void)
return;
} /* end of netflush */
-
+#if 0
/*
* writenet
*
@@ -355,7 +413,7 @@ void writenet(register unsigned char *pt
nfrontp += len;
} /* end of writenet */
-
+#endif
/*
* miscellaneous functions doing a variety of little jobs follow ...