summaryrefslogtreecommitdiff
path: root/exploits/7350855-netkit
diff options
context:
space:
mode:
authorRoot THC2026-02-24 12:42:47 +0000
committerRoot THC2026-02-24 12:42:47 +0000
commitc9cbeced5b3f2bdd7407e29c0811e65954132540 (patch)
treeaefc355416b561111819de159ccbd86c3004cf88 /exploits/7350855-netkit
parent073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff)
initial
Diffstat (limited to 'exploits/7350855-netkit')
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/BUGS24
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/ChangeLog152
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/MCONFIG20
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/MCONFIG.in30
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/MRULES8
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/Makefile20
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/README102
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/configure571
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/changelog139
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/control21
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/copyright18
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/dirs2
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/docs2
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/login.c23
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/rules77
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.dirs4
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.postinst45
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.postrm29
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.prerm9
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/pty-hang.patch99
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/Makefile30
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/NetKit-B-0.06-telnet.patch27
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/README26
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/README.old566
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/TODO13
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h97
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/authenc.cc114
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/commands.cc2233
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/commands.obin0 -> 44868 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/defines.h52
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/depend.mk17
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.cc200
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.h10
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.obin0 -> 6120 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/externs.h365
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/fdset.h50
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/general.h46
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.cc91
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.h5
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.obin0 -> 1324 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/main.cc257
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/main.obin0 -> 4460 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.cc199
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.h26
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.obin0 -> 7068 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/network.cc91
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/network.obin0 -> 1744 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/proto.h41
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/ptrarray.h92
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.cc209
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.h111
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.obin0 -> 4984 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/sys_bsd.cc406
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/sys_bsd.obin0 -> 4284 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnetbin0 -> 123042 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.11263
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.cc2069
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.obin0 -> 27488 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.cc718
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.h11
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.obin0 -> 9248 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/tn3270.cc366
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/tn3270.obin0 -> 829 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/types.h52
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/utilities.cc673
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/utilities.obin0 -> 13444 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/Makefile38
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/authenc.c83
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/defs.h215
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/ext.h212
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/getent.c71
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/global.c98
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/issue.net.543
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/login.3107
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/logout.h1
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/logwtmp.h5
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/pathnames.h41
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.373
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.c145
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.h4
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/slc.c456
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/state.c1408
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/sys_term.c744
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/t.c2
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.8486
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.c1163
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.h50
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/termstat.c588
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnetd/utility.c1145
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/version.h5
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/BUGS24
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/ChangeLog170
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/MCONFIG.in30
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/MRULES8
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/Makefile20
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/README127
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/configure572
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/changelog244
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/control25
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/copyright18
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/dirs3
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/docs2
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/menu3
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/postinst8
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/prerm7
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/rules85
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.dirs4
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.docs2
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.postinst57
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.postrm25
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.prerm6
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/pty-hang.patch99
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/Makefile30
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/README26
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/README.old566
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/TODO13
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/array.h97
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/authenc.cc116
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/commands.cc2262
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/defines.h52
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/depend.mk17
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/environ.cc201
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/environ.h10
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/externs.h365
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/fdset.h50
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/general.h46
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/genget.cc91
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/genget.h5
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/main.cc275
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/netlink.cc177
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/netlink.h25
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/network.cc92
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/proto.h41
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/ptrarray.h92
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/ring.cc213
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/ring.h111
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/sys_bsd.cc413
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/telnet.11267
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/telnet.cc2071
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/terminal.cc720
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/terminal.h11
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/tn3270.cc366
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/types.h52
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnet/utilities.cc675
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/Makefile38
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/authenc.c71
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/defs.h216
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/ext.h214
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/getent.c71
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/global.c97
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/issue.net.543
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/login.3107
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/logout.h1
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/logwtmp.h5
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/pathnames.h41
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.373
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.c145
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.h4
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/slc.c456
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/state.c1407
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/sys_term.c744
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.8486
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.c1208
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.h50
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/termstat.c588
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetd/utility.c1266
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/Makefile18
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/telnetlogin.891
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/telnetlogin.c230
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.17/version.h5
-rw-r--r--exploits/7350855-netkit/netkit-telnet_0.16-4potato.1.diff.gzbin0 -> 8327 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet_0.16-4potato.1.dsc23
-rw-r--r--exploits/7350855-netkit/netkit-telnet_0.16.orig.tar.gzbin0 -> 130043 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet_0.17-14.diff.gzbin0 -> 20569 bytes
-rw-r--r--exploits/7350855-netkit/netkit-telnet_0.17-14.dsc24
-rw-r--r--exploits/7350855-netkit/netkit-telnet_0.17.orig.tar.gzbin0 -> 133749 bytes
-rw-r--r--exploits/7350855-netkit/telnetd-0.16.tgzbin0 -> 26640 bytes
-rw-r--r--exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/lib/telnetd/loginbin0 -> 2988 bytes
-rw-r--r--exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/changelog.Debian.gzbin0 -> 1477 bytes
-rw-r--r--exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/changelog.gzbin0 -> 2550 bytes
-rw-r--r--exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/copyright18
-rw-r--r--exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man5/issue.net.5.gzbin0 -> 676 bytes
-rw-r--r--exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man8/in.telnetd.8.gzbin0 -> 4700 bytes
l---------exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man8/telnetd.8.gz1
-rw-r--r--exploits/7350855-netkit/telnetd_0.16-4potato.1.debbin0 -> 29366 bytes
-rw-r--r--exploits/7350855-netkit/telnetd_0.17-13_i386.debbin0 -> 37522 bytes
186 files changed, 38932 insertions, 0 deletions
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/BUGS b/exploits/7350855-netkit/netkit-telnet-0.16/BUGS
new file mode 100644
index 0000000..484d00d
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/BUGS
@@ -0,0 +1,24 @@
1telnet:
2 - will apparently sometimes assert in ungetch. I think I've
3 fixed this, so if you still see it let me know.
4 - hangs if you telnet to chargen port and push ^Z
5 (due to bogus protocol negotiation attempts)
6 - binary mode doesn't handle crlf right
7 - should warn if the connection isn't encrypted
8
9telnetd:
10 - hangs if you do the following:
11 telnet
12 log in
13 cat >/dev/null
14 type 256 'a's with no CRs
15 *THIS IS A KERNEL BUG* Patch enclosed.
16
17 - crashes in ncurses if the terminal type is undefined,
18 with some versions of ncurses.
19 - should allow passing random user envs as "TELNET_*"
20 - should set REMOTEHOST to the remote hostname
21 - passes login the -p flag instead of sending envs explicitly
22 - should only use included logout() et al. if real ones aren't
23 available in system libs.
24 - addarg() in sys_term.c does some very questionable casts.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/ChangeLog b/exploits/7350855-netkit/netkit-telnet-0.16/ChangeLog
new file mode 100644
index 0000000..01b552e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/ChangeLog
@@ -0,0 +1,152 @@
113-Dec-1999:
2 Per recommendation of the linux-security-audit list, don't bother
3 (in telnetd) to ask termcap/ncurses if a terminal type is good;
4 assume it is. This means telnetd no longer links against termcap.
5
612-Dec-1999:
7 Massive buffer cleanup in telnetd; minor cleanup to telnet.
8
95-Dec-1999:
10 Remove some more bogus #ifdefs in telnet.
11
1229-Oct-1999:
13 Fix latent bug in the array classes used in telnet.
14
1514-Sep-1999:
16 Merge old fix to keep telnet from hanging up when under heavy load
17 (Olaf Kirch, okir@caldera.de)
18
1919-Aug-1999:
20 Patches for compiling with gcc 2.95. (Jeremy Buhler,
21 jbuhler@cs.washington.edu)
22
2318-Aug-1999:
24 netkit-telnet-0.14 released.
25
2617-Aug-1999:
27 telnetd patch from Chris Evans to reject termcap entries with
28 '/' in them, as libtermcap will treat them as paths and open
29 them as root, with various interesting consequences...
30 Issue found by Tymm Twillman (tymm@coe.missouri.edu).
31
321-Aug-1999:
33 Massive cleanup of telnetd. Changed telnetd to use openpty() from
34 libutil, so we can let libc deal with changes in pty management.
35
361-Aug-1999:
37 Did complete y2k and y2038 audit.
38
3931-Jul-1999:
40 Redid makefiles/config stuff for new confgen version.
41
4215-Jul-1999:
43 Set the process title (visible with ps) to show the remote host name.
44 Also filter control characters from the remote host name, just in case.
45 Set environment variable REMOTEHOST also.
46
4716-Oct-1997:
48 Added OPOST to the terminal stuff a la NCSA telnet fixup
49
5023-Sep-1997:
51 Assorted signed/unsigned character fixes and hacking in telnet.
52 (Martin Mares, mj@mj.gts.cz)
53 Fix various crashes in telnet arising from undefining environment
54 variables.
55 "telnet h" no longer prints a usage message.
56
5712-Jun-1997:
58 netkit-telnet-0.10 released.
59
6008-Jun-1997:
61 More adjustments for glibc.
62 Include kernel patch to fix hang on long input; thanks to Bill
63 Hawes (whawes@star.net).
64
6519-May-1997:
66 Fix some nonsense with ayt and signals, since glibc has SIGINFO.
67
6813-May-1997:
69 8-bit fix to telnet. (Lukas Wunner, lukas@design.de)
70 Set ut_type correctly in telnetd's logout. (Steve Coile,
71 steve@patriot.net)
72
7305-Apr-1997:
74 Added configure script to generate MCONFIG.
75 Better utmp handling in telnetd.
76
7708-Mar-1997:
78 Split from full NetKit package.
79 Generated this change log from NetKit's.
80
8129-Dec-1996
82 NetKit-0.09 released.
83 Assorted alpha/glibc patches. (Erik Troan, ewt@redhat.com)
84 Assorted bug fixes from Debian. (Peter Tobias,
85 tobias@et-inf.fho-emden.de)
86 Telnetd supports -L option for alternate login program. (Peter Tobias)
87 Hardened programs against DNS h_length spoofing attacks.
88 Use inet_aton() everywhere instead of inet_addr().
89 Fixed crash in telnet caused by ^C or ^Z or ^\ under
90 certain circumstances.
91 Rewrote telnet and telnetd man pages.
92
9322-Aug-1996
94 NetKit-B-0.08 released.
95 (almost) everything now compiles with lots of warnings turned on.
96 Massive hacking on telnet.
97 telnet honors the -E flag (was broken in .07, .07A)
98 telnetd intercepts ENV environment variable.
99 Merged libtelnet into telnet and telnetd dirs.
100 telnetd now sets idle tty devices to root.root mode 600.
101
10225-Jul-1996
103 NetKit-B-0.07A released.
104 Fixed a bug in telnet where the escape character was being ignored.
105 Fixed a bug in telnetd; now uses the correct names for the last ptys
106 (that is, ptya0-ptyef, not ptyA0-ptyEf.)
107
10823-Jul-1996
109 NetKit-B-0.07 released.
110 Integrated a collection of patches that had been lurking on the net,
111 including the 256-ptys support for telnetd and passive mode ftp.
112 Major security fixes, including to fingerd, lpr, rlogin, rsh, talkd,
113 and telnetd. Do *not* use the sliplogin from earlier versions of this
114 package, either.
115 Much of the code builds without libbsd.a or bsd includes.
116 Massive code cleanup. Almost everything compiles clean with gcc
117 -Wall now. rusers and rusersd do not; patches to rpcgen to fix
118 this would be appreciated if anyone feels like it.
119 Kerberos support has been removed. It didn't work anyway, and
120 proper Kerberos tools come with Kerberos.
121 New maintainer: David A. Holland, dholland@hcs.harvard.edu
122
123date not known
124 NetKit-B-0.06 released.
125
126date not known
127 NetKit-B-0.05 released.
128 Fixed writing entries to /var/adm/wtmp by ftpd, rlogind and
129 telnetd. (logwtmp.c) Florian
130 This is only necessary for the GNU last, not for the one
131 in util-linux...
132
133date not known
134 NetKit-B-0.04 released.
135 Did some nasty changes to telnet/extern.h. I should really take
136 the current version from NetBSD again and make a clean port of
137 it. (signals).
138
139date not known
140 NetKit-B-0.03 released.
141 telnetd: changed the default 'etc/issue.net' to not output the
142 hostname and then the domainname (that should be the fqdn, but
143 is wrong!) Changed also the man page issue.net.5
144 changed telnetd to get the fqdn and not only use what
145 'gethostname' returns
146 telnetd: changed some code back to original form to properly
147 enable binary mode negotiation (outgoing data wasn't binary)
148 Please test this out: do "telnet some_other_not_linux_host" and
149 then do "vi TEST_FILE" and test some strange characters >127
150 like ° or §.
151 telnetd: added issue.net.5 to "make install"
152
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/MCONFIG b/exploits/7350855-netkit/netkit-telnet-0.16/MCONFIG
new file mode 100644
index 0000000..2e529ea
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/MCONFIG
@@ -0,0 +1,20 @@
1# Generated by configure (confgen version 2) on Tue Aug 14 21:32:08 CEST 2001
2#
3
4BINDIR=/usr/bin
5SBINDIR=/usr/sbin
6MANDIR=/usr/man
7BINMODE=755
8DAEMONMODE=755
9MANMODE=644
10PREFIX=/usr
11EXECPREFIX=/usr
12INSTALLROOT=
13CC=gcc
14CXX=gcc
15CFLAGS=-O2 -Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline
16CXXFLAGS=-O2 -fno-rtti -fno-exceptions -Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline
17LDFLAGS=
18LIBS=-lutil -lutil
19LIBTERMCAP=-lncurses
20USE_GLIBC=1
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/MCONFIG.in b/exploits/7350855-netkit/netkit-telnet-0.16/MCONFIG.in
new file mode 100644
index 0000000..cedb9d1
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/MCONFIG.in
@@ -0,0 +1,30 @@
1# Dirs
2INSTALLROOT
3BINDIR
4MANDIR
5SBINDIR
6
7# Modes
8BINMODE
9DAEMONMODE
10MANMODE
11
12# Compiling
13ALLWARNINGS
14CC
15CXX
16CFLAGS
17CXXFLAGS
18LDFLAGS
19LIBS
20
21# Features
22FN(snprintf)
23FN(logwtmp)
24LIBTERMCAP
25GLIBC
26BSDSIGNAL
27
28# We actually use openpty, but they come from the same place on all systems
29# I know.
30FN(forkpty)
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/MRULES b/exploits/7350855-netkit/netkit-telnet-0.16/MRULES
new file mode 100644
index 0000000..6d8015e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/MRULES
@@ -0,0 +1,8 @@
1# Standard compilation rules (don't use make builtins)
2
3%.o: %.c
4 $(CC) $(CFLAGS) $< -c
5
6%.o: %.cc
7 $(CXX) $(CXXFLAGS) $< -c
8
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/Makefile b/exploits/7350855-netkit/netkit-telnet-0.16/Makefile
new file mode 100644
index 0000000..1942aee
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/Makefile
@@ -0,0 +1,20 @@
1# You can do "make SUB=blah" to make only a few, or edit here, or both
2# You can also run make directly in the subdirs you want.
3
4SUB = telnet telnetd
5
6%.build:
7 (cd $(patsubst %.build, %, $@) && $(MAKE))
8
9%.install:
10 (cd $(patsubst %.install, %, $@) && $(MAKE) install)
11
12%.clean:
13 (cd $(patsubst %.clean, %, $@) && $(MAKE) clean)
14
15all: $(patsubst %, %.build, $(SUB))
16install: $(patsubst %, %.install, $(SUB))
17clean: $(patsubst %, %.clean, $(SUB))
18
19distclean: clean
20 rm -f MCONFIG
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/README b/exploits/7350855-netkit/netkit-telnet-0.16/README
new file mode 100644
index 0000000..c9b4f49
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/README
@@ -0,0 +1,102 @@
1This is netkit-telnet-0.16.
2
3This package updates netkit-telnet-0.14.
4
5If you're reading this off a CD, go right away and check the net
6archives for later versions and security fixes.
7
8Contents:
9 telnet Client for telnet protocol
10 telnetd Daemon for telnet protocol
11
12Note: These programs do not provide encryption or strong
13authentication of network connections. As such, their use for remote
14logins is discouraged. The "ssh" protocol and package can be used
15instead.
16
17Requires:
18 Working compiler, libc, and kernel, and a recent version of
19 ncurses or libtermcap.
20
21Security:
22 This release probably does not contain new security fixes. On
23 the other hand, vast amounts of suspicious pointer manipulation
24 in telnetd were cleaned up, so it is quite likely that this
25 version is less dangerous than previous ones.
26
27 In any event, telnetd is evil legacy code and is not
28 trustworthy - do not run it unless you absolutely need it.
29
30
31 netkit-telnet-0.14 contained a fix for a set of remote (and
32 possibly serious) denial of service attacks possible against
33 older versions of the telnet daemon.
34
35 Do not under any circumstances use telnetd older than
36 NetKit-0.09!
37
38DEC Alpha:
39 The currently available Compaq C compiler does not provide
40 a C++ compiler, so it cannot compile telnet. Compiling
41 telnetd it may produce a few warnings, but they should be
42 harmless.
43
44Installation:
45 Do "./configure --help" and decide what options you want. The
46 defaults should be suitable for most Linux systems. Then run
47 the configure script.
48
49 Do "make" to compile.
50 Then (as root) do "make install".
51
52 Save a backup copy of any mission-critical program in case the
53 new one doesn't work, and so forth. We warned you.
54
55 *** If you have an old kernel, you may need to apply the enclosed
56 pty-hang patch to it. I don't unfortunately know at the moment
57 which kernel versions need the patch, but current 2.0.x and
58 2.2.x should be ok without it.
59
60 The following test will tell you if you need the patch: telnet
61 to localhost, do "cat >/dev/null", and type 256 characters
62 without any newlines. If you need the patch, telnetd will hang
63 completely at this point. If it refuses to accept more input,
64 but does not hang, you do not need the patch.
65
66Bugs:
67 Please make sure the header files in /usr/include match the
68 libc version installed in /lib and /usr/lib. If you have weird
69 problems this is the most likely culprit.
70
71 Also, before reporting a bug, be sure you're working with the
72 latest version.
73
74 If something doesn't compile for you, fix it and send diffs.
75 If you can't, send the compiler's error output.
76
77 If it compiles but doesn't work, send as complete a bug report as
78 you can. Patches and fixes are welcome, as long as you describe
79 adequately what they're supposed to fix. Please, one patch per
80 distinct fix. Please do NOT send the whole archive back or
81 reindent the source.
82
83 Be sure to send all correspondence in e-mail. Postings to netnews
84 will not be seen due to the enormous volume.
85
86 Please don't report known bugs (see the BUGS file(s)) unless you
87 are including fixes. :-)
88
89 Mail should be sent to: netbug@ftp.uk.linux.org
90
91
92Note: please see http://www.hcs.harvard.edu/~dholland/computers/netkit.html
93if you are curious why it's been so long since the last NetKit release.
94(The short version is that I gave things to some other people, who let
95them kind of slide.)
96
97I do not currently plan to continue maintaining NetKit; I am doing this
98release and perhaps one or two more, and then I intend to give the source
99tree to Red Hat or some similar organization for long-term maintenance.
100
101David A. Holland
10212 December 1999
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/configure b/exploits/7350855-netkit/netkit-telnet-0.16/configure
new file mode 100644
index 0000000..a17f8f5
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/configure
@@ -0,0 +1,571 @@
1#!/bin/sh
2#
3# This file was generated by confgen version 2.
4# Do not edit.
5#
6
7PREFIX='/usr'
8#EXECPREFIX='$PREFIX'
9INSTALLROOT=''
10BINMODE='755'
11#DAEMONMODE='$BINMODE'
12MANMODE='644'
13
14while [ x$1 != x ]; do case $1 in
15
16 --help)
17 cat <<EOF
18Usage: configure [options]
19 --help Show this message
20 --with-debug Enable debugging
21 --prefix=path Prefix for location of files [/usr]
22 --exec-prefix=path Location for arch-depedent files [prefix]
23 --installroot=root Top of filesystem tree to install in [/]
24 --binmode=mode Mode for binaries [755]
25 --daemonmode=mode Mode for daemon binaries [same as binmode]
26 --manmode=mode Mode for manual pages [644]
27 --with-c-compiler=cc Program for compiling C source [guessed]
28 --with-c++-compiler=cc Program for compiling C++ source [guessed]
29EOF
30 exit 0;;
31 --verbose) ;;
32 --quiet) ;;
33
34 --subdir) . ../configure.defs;;
35
36 --with-debug|--debug) DEBUG=1;;
37 --prefix=*) PREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;
38 --exec-prefix=*) EXECPREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;
39 --installroot=*) INSTALLROOT=`echo $1 | sed 's/^[^=]*=//'` ;;
40 --binmode=*) BINMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
41 --daemonmode=*) DAEMONMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
42 --manmode=*) MANMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
43 --with-c-compiler=*) CC=`echo $1 | sed 's/^[^=]*=//'` ;;
44 --with-c++-compiler=*) CXX=`echo $1 | sed 's/^[^=]*=//'` ;;
45 --without-pam|--disable-pam) WITHOUT_PAM=1;;
46 --without-readline|--disable-readline) WITHOUT_READLINE=1;;
47 --without-shadow|--disable-shadow) WITHOUT_SHADOW=1;;
48 *) echo "Unrecognized option: $1"; exit 1;;
49esac
50shift
51done
52
53if [ x$EXECPREFIX = x ]; then
54 EXECPREFIX="$PREFIX"
55fi
56
57if [ x$DAEMONMODE = x ]; then
58 DAEMONMODE="$BINMODE"
59fi
60
61BINDIR="$EXECPREFIX/bin"
62SBINDIR="$EXECPREFIX/sbin"
63MANDIR="$PREFIX/man"
64
65echo "Directories: $BINDIR $SBINDIR $MANDIR "
66
67if [ x$INSTALLROOT != x ]; then
68 echo "Installing in chroot tree rooted at $INSTALLROOT"
69fi
70
71##################################################
72
73WARNINGS='-Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline '
74
75cat << EOF > __conftest.c
76 int main() { int class=0; return class; }
77EOF
78
79if [ x"$CC" = x ]; then
80 echo -n 'Looking for a C compiler... '
81 for TRY in egcs gcc g++ CC c++ cc; do
82 (
83 $TRY __conftest.c -o __conftest || exit 1;
84 ./__conftest || exit 1;
85 ) >/dev/null 2>&1 || continue;
86 CC=$TRY
87 break;
88 done
89 if [ x"$CC" = x ]; then
90 echo 'failed.'
91 echo 'Cannot find a C compiler. Run configure with --with-c-compiler.'
92 rm -f __conftest*
93 exit
94 fi
95 echo "$CC"
96else
97 echo -n 'Checking if C compiler works... '
98 if (
99 $CC __conftest.c -o __conftest || exit 1
100 ./__conftest || exit 1
101 ) >/dev/null 2>&1; then
102 echo 'yes'
103 else
104 echo 'no'
105 echo 'Compiler '"$CC"' does not exist or cannot compile C; try another.'
106 rm -f __conftest*
107 exit
108 fi
109fi
110
111echo -n "Checking if $CC accepts gcc warnings... "
112if (
113 $CC $WARNINGS __conftest.c -o __conftest || exit 1
114 ) >/dev/null 2>&1; then
115 echo 'yes'
116 CC_WARNINGS=1
117else
118 echo 'no'
119fi
120
121cat << EOF > __conftest.cc
122 template <class T> class fnord { public: T x; fnord(T y) { x=y; }};
123 int main() { fnord<int> a(0); return a.x; }
124EOF
125
126if [ x"$CXX" = x ]; then
127 echo -n 'Looking for a C++ compiler... '
128 for TRY in egcs gcc g++ CC c++ cc; do
129 (
130 $TRY __conftest.cc -o __conftest || exit 1;
131 ./__conftest || exit 1;
132 ) >/dev/null 2>&1 || continue;
133 CXX=$TRY
134 break;
135 done
136 if [ x"$CXX" = x ]; then
137 echo 'failed.'
138 echo 'Cannot find a C++ compiler. Run configure with --with-cpp-compiler.'
139 rm -f __conftest*
140 exit
141 fi
142 echo "$CXX"
143else
144 echo -n 'Checking if C++ compiler works... '
145 if (
146 $CXX __conftest.cc -o __conftest || exit 1
147 ./__conftest || exit 1
148 ) >/dev/null 2>&1; then
149 echo 'yes'
150 else
151 echo 'no'
152 echo 'Compiler '"$CXX"' does not exist or cannot compile C++; try another.'
153 rm -f __conftest*
154 exit
155 fi
156fi
157
158echo -n "Checking if $CXX accepts gcc warnings... "
159if (
160 $CXX $WARNINGS __conftest.cc -o __conftest || exit 1
161 ) >/dev/null 2>&1; then
162 echo 'yes'
163 CXX_WARNINGS=1
164else
165 echo 'no'
166fi
167
168if [ x$DEBUG != x ]; then
169 echo -n "Checking if $CC accepts -g... "
170 if (
171 $CC -g __conftest.c -o __conftest
172 ) >/dev/null 2>&1; then
173 echo 'yes'
174 CFLAGS="$CFLAGS -g"
175 else
176 echo 'no'
177 fi
178fi
179
180echo -n "Checking if $CC accepts -O2... "
181if (
182 $CC -O2 __conftest.c -o __conftest
183 ) >/dev/null 2>&1; then
184 echo 'yes'
185 CFLAGS="$CFLAGS -O2"
186else
187 echo 'no'
188 echo -n "Checking if $CC accepts -O... "
189 if (
190 $CC -O __conftest.c -o __conftest
191 ) >/dev/null 2>&1; then
192 echo 'yes'
193 CFLAGS="$CFLAGS -O"
194 else
195 echo 'no'
196 fi
197fi
198
199if [ x"$CC" != x"$CXX" ]; then
200 if [ x$DEBUG != x ]; then
201 echo -n "Checking if $CXX accepts -g... "
202 if (
203 $CXX -g __conftest.cc -o __conftest
204 ) >/dev/null 2>&1; then
205 echo 'yes'
206 CXXFLAGS="$CXXFLAGS -g"
207 else
208 echo 'no'
209 fi
210
211 fi
212 echo -n "Checking if $CXX accepts -O2... "
213 if (
214 $CXX -O2 __conftest.cc -o __conftest
215 ) >/dev/null 2>&1; then
216 echo 'yes'
217 CXXFLAGS="$CXXFLAGS -O2"
218 else
219 echo 'no'
220 echo -n "Checking if $CXX accepts -O... "
221 if (
222 $CXX -O __conftest.cc -o __conftest
223 ) >/dev/null 2>&1; then
224 echo 'yes'
225 CXXFLAGS="$CXXFLAGS -O"
226 else
227 echo 'no'
228 fi
229 fi
230else
231 CXXFLAGS="$CFLAGS"
232fi
233echo -n "Checking if $CXX accepts -fno-rtti... "
234if (
235 $CXX -fno-rtti __conftest.cc -o __conftest
236 ) >/dev/null 2>&1; then
237 echo 'yes'
238 CXXFLAGS="$CXXFLAGS -fno-rtti"
239else
240 echo 'no'
241fi
242
243echo -n "Checking if $CXX accepts -fno-exceptions... "
244if (
245 $CXX -fno-exceptions __conftest.cc -o __conftest
246 ) >/dev/null 2>&1; then
247 echo 'yes'
248 CXXFLAGS="$CXXFLAGS -fno-exceptions"
249else
250 echo 'no'
251fi
252
253
254LDFLAGS=
255LIBS=
256
257rm -f __conftest*
258
259##################################################
260
261echo -n 'Checking for BSD signal semantics... '
262cat <<EOF >__conftest.cc
263#include <unistd.h>
264#include <signal.h>
265int count=0;
266void handle(int foo) { count++; }
267int main() {
268 int pid=getpid();
269 signal(SIGINT, handle);
270 kill(pid,SIGINT);
271 kill(pid,SIGINT);
272 kill(pid,SIGINT);
273 if (count!=3) return 1;
274 return 0;
275}
276
277EOF
278if (
279 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
280 ./__conftest || exit 1
281 ) >/dev/null 2>&1; then
282 echo 'yes'
283else
284 if (
285 $CXX $CXXFLAGS -D__USE_BSD_SIGNAL __conftest.cc -o __conftest || exit 1
286 ./__conftest || exit 1
287 ) >/dev/null 2>&1; then
288 echo '-D__USE_BSD_SIGNAL'
289 CFLAGS="$CFLAGS -D__USE_BSD_SIGNAL"
290 CXXFLAGS="$CXXFLAGS -D__USE_BSD_SIGNAL"
291 else
292 echo 'no'
293 echo 'This package needs BSD signal semantics to run.'
294 rm -f __conftest*
295 exit
296 fi
297fi
298rm -f __conftest*
299
300##################################################
301
302echo -n 'Checking for ncurses... '
303cat <<EOF >__conftest.cc
304#include <stdio.h>
305#include <curses.h>
306#ifndef KEY_DOWN
307syntax error. /* not ncurses */
308#endif
309int main() {
310 endwin();
311 return 0;
312}
313
314EOF
315if (
316 $CXX $CXXFLAGS __conftest.cc -lncurses -o __conftest || exit 1
317 ) >/dev/null 2>&1; then
318 echo 'yes'
319 NCURSES=1
320else
321 if (
322 $CXX $CXXFLAGS -I/usr/include/ncurses __conftest.cc -lncurses -o __conftest || exit 1
323 ) >/dev/null 2>&1; then
324 echo '-I/usr/include/ncurses'
325 CFLAGS="$CFLAGS -I/usr/include/ncurses"
326 CXXFLAGS="$CXXFLAGS -I/usr/include/ncurses"
327 NCURSES=1
328 else
329 echo 'no'
330 fi
331fi
332
333if [ x$NCURSES != x ]; then
334 LIBTERMCAP=-lncurses
335else
336 echo -n 'Checking for traditional termcap... '
337cat <<EOF >__conftest.cc
338#include <stdio.h>
339#include <termcap.h>
340int main() {
341 tgetent(NULL, NULL); return 0;
342}
343
344EOF
345 if (
346 $CXX $CXXFLAGS __conftest.cc -ltermcap -o __conftest || exit 1
347 ) >/dev/null 2>&1; then
348 echo '-ltermcap'
349 LIBTERMCAP=-ltermcap
350 else
351 echo 'not found'
352 echo 'This package needs termcap to run.'
353 rm -f __conftest*
354 exit
355 fi
356fi
357rm -f __conftest*
358
359##################################################
360
361echo -n 'Checking for GNU libc... '
362cat <<EOF >__conftest.cc
363#include <stdio.h>
364#if defined(__GLIBC__) && (__GLIBC__ >= 2)
365int tester;
366#endif
367int main() { tester=6; return 0; }
368
369EOF
370if (
371 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
372 ) >/dev/null 2>&1; then
373 echo 'yes'
374 USE_GLIBC=1
375else
376 echo 'no'
377fi
378rm -f __conftest*
379
380##################################################
381
382echo -n 'Checking for forkpty... '
383cat <<EOF >__conftest.cc
384#include <pty.h>
385int main() { forkpty(0, 0, 0, 0); }
386
387EOF
388if (
389 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
390 ) >/dev/null 2>&1; then
391 echo 'yes'
392else
393 if (
394 $CXX $CXXFLAGS __conftest.cc -lutil -o __conftest || exit 1
395 ) >/dev/null 2>&1; then
396 echo '-lutil'
397 LIBS="$LIBS -lutil"
398 else
399 if (
400 $CXX $CXXFLAGS __conftest.cc -lbsd -o __conftest || exit 1
401 ) >/dev/null 2>&1; then
402 echo '-lbsd'
403 LIBBSD="-lbsd"
404 else
405 echo 'no'
406 echo 'This package requires forkpty.'
407 rm -f __conftest*
408 exit
409 fi
410 fi
411fi
412rm -f __conftest*
413
414##################################################
415
416echo -n 'Checking for logwtmp... '
417cat <<EOF >__conftest.cc
418#ifdef __cplusplus
419extern "C"
420#endif
421void logwtmp(const char *, const char *, const char *);
422int main() { logwtmp(0, 0, 0); }
423
424EOF
425if (
426 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
427 ) >/dev/null 2>&1; then
428 echo 'yes'
429else
430 if (
431 $CXX $CXXFLAGS __conftest.cc -lutil -o __conftest || exit 1
432 ) >/dev/null 2>&1; then
433 echo '-lutil'
434 LIBS="$LIBS -lutil"
435 else
436 if (
437 $CXX $CXXFLAGS __conftest.cc -lbsd -o __conftest || exit 1
438 ) >/dev/null 2>&1; then
439 echo '-lbsd'
440 LIBBSD="-lbsd"
441 else
442 echo 'no'
443 echo 'This package requires logwtmp.'
444 rm -f __conftest*
445 exit
446 fi
447 fi
448fi
449rm -f __conftest*
450
451##################################################
452
453echo -n 'Checking for snprintf declaration... '
454cat <<EOF >__conftest.cc
455#include <stdio.h>
456int main() {
457 void *x = (void *)snprintf;
458 printf("%lx", (long)x);
459 return 0;
460}
461
462EOF
463if (
464 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
465 ) >/dev/null 2>&1; then
466 echo 'ok'
467else
468 if (
469 $CXX $CXXFLAGS -D_GNU_SOURCE __conftest.cc -o __conftest || exit 1
470 ./__conftest || exit 1
471 ) >/dev/null 2>&1; then
472 echo '-D_GNU_SOURCE'
473 CFLAGS="$CFLAGS -D_GNU_SOURCE"
474 CXXFLAGS="$CXXFLAGS -D_GNU_SOURCE"
475 else
476 echo 'manual'
477 CFLAGS="$CFLAGS -DDECLARE_SNPRINTF"
478 CXXFLAGS="$CXXFLAGS -DDECLARE_SNPRINTF"
479 fi
480fi
481rm -f __conftest*
482
483echo -n 'Checking for snprintf implementation... '
484cat <<EOF >__conftest.cc
485#include <stdio.h>
486#include <string.h>
487#ifdef DECLARE_SNPRINTF
488#ifdef __cplusplus
489extern "C"
490#endif /*__cplusplus*/
491int snprintf(char *, int, const char *, ...);
492#endif /*DECLARE_SNPRINTF*/
493int main() {
494 char buf[32];
495 snprintf(buf, 8, "%s", "1234567890");
496 if (strlen(buf)!=7) return 1;
497 return 0;
498}
499
500EOF
501if (
502 $CXX $CXXFLAGS __conftest.cc $(LIBBSD) -o __conftest || exit 1
503 ./__conftest || exit 1
504 ) >/dev/null 2>&1; then
505 echo 'ok'
506else
507 if (
508 $CXX $CXXFLAGS __conftest.cc -lsnprintf $(LIBBSD) -o __conftest || exit 1
509 ./__conftest || exit 1
510 ) >/dev/null 2>&1; then
511 echo '-lsnprintf'
512 LIBS="$LIBS -lsnprintf"
513 else
514 if (
515 $CXX $CXXFLAGS __conftest.cc -ldb $(LIBBSD) -o __conftest || exit 1
516 ./__conftest || exit 1
517 ) >/dev/null 2>&1; then
518 echo '-ldb'
519 LIBS="$LIBS -ldb"
520 else
521 echo 'missing'
522 echo 'This package requires snprintf.'
523 rm -f __conftest*
524 exit
525 fi
526 fi
527fi
528rm -f __conftest*
529
530##################################################
531
532## libbsd should go last in case it's broken
533if [ "x$LIBBSD" != x ]; then
534 LIBS="$LIBS $LIBBSD"
535fi
536
537echo 'Generating MCONFIG...'
538(
539 echo -n '# Generated by configure (confgen version 2) on '
540 date
541 echo '#'
542 echo
543
544 echo "BINDIR=$BINDIR"
545 echo "SBINDIR=$SBINDIR"
546 echo "MANDIR=$MANDIR"
547 echo "BINMODE=$BINMODE"
548 echo "DAEMONMODE=$DAEMONMODE"
549 echo "MANMODE=$MANMODE"
550 echo "PREFIX=$PREFIX"
551 echo "EXECPREFIX=$EXECPREFIX"
552 echo "INSTALLROOT=$INSTALLROOT"
553 echo "CC=$CC"
554 echo "CXX=$CXX"
555 if [ x$CC_WARNINGS != x ]; then
556 CFLAGS="$CFLAGS $WARNINGS"
557 fi
558
559 if [ x$CXX_WARNINGS != x ]; then
560 CXXFLAGS="$CXXFLAGS $WARNINGS"
561 fi
562
563 echo "CFLAGS=$CFLAGS" | sed 's/= */=/'
564 echo "CXXFLAGS=$CXXFLAGS" | sed 's/= */=/'
565 echo "LDFLAGS=$LDFLAGS" | sed 's/= */=/'
566 echo "LIBS=$LIBS" | sed 's/= */=/'
567
568 echo "LIBTERMCAP=$LIBTERMCAP"
569 echo "USE_GLIBC=$USE_GLIBC"
570) > MCONFIG
571
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/changelog b/exploits/7350855-netkit/netkit-telnet-0.16/debian/changelog
new file mode 100644
index 0000000..a15309b
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/changelog
@@ -0,0 +1,139 @@
1netkit-telnet (0.16-4potato.1) stable; urgency=low
2
3 * Fixed a memory allocation bug.
4
5 -- Herbert Xu <herbert@debian.org> Fri, 22 Sep 2000 23:30:18 +1100
6
7netkit-telnet (0.16-4) frozen unstable; urgency=low
8
9 * Disabled signal handling that does not work (closes: #62388). Patches
10 that provide correct signal handling are welcome.
11
12 -- Herbert Xu <herbert@debian.org> Mon, 24 Apr 2000 16:58:22 +1000
13
14netkit-telnet (0.16-3) frozen unstable; urgency=medium
15
16 * Restored the default to not being 8-bit clean since it breaks SunOS
17 (closes: #60352, #60386). People who need 8-bit cleanness should use -8.
18 * Made FHS compliant.
19
20 -- Herbert Xu <herbert@debian.org> Wed, 15 Mar 2000 10:39:00 +1100
21
22netkit-telnet (0.16-2) frozen unstable; urgency=low
23
24 * Recompiled with libncurses5.
25 * Changed the permission of /usr/lib/telnetd/login to 4754 (closes: #58786).
26 * telnet is now 8-bit clean by default since it appeared to be so in slink,
27 albeit unintentionally (closes: #57685).
28
29 -- Herbert Xu <herbert@debian.org> Sun, 12 Mar 2000 21:10:47 +1100
30
31netkit-telnet (0.16-1) frozen unstable; urgency=low
32
33 * New upstream release with security fixes.
34 * Run as root if devpts is not present.
35
36 -- Herbert Xu <herbert@debian.org> Thu, 3 Feb 2000 13:42:29 +1100
37
38netkit-telnet (0.14-9) unstable; urgency=low
39
40 * Compile login with -g -O2 -Wall.
41 * Fixed path to default login in in.telnetd(8).
42 * Fixed usage() output (closes: #51498).
43
44 -- Herbert Xu <herbert@debian.org> Tue, 30 Nov 1999 22:43:39 +1100
45
46netkit-telnet (0.14-8) unstable; urgency=low
47
48 * Call fatalperror() instead of fatal() when getpty() fails.
49 * Delete telnetd group before creating telnetd (closes: #46659).
50
51 -- Herbert Xu <herbert@debian.org> Tue, 5 Oct 1999 17:52:36 +1000
52
53netkit-telnet (0.14-7) unstable; urgency=low
54
55 * Redirect stderr for group existence check to /dev/null.
56
57 -- Herbert Xu <herbert@debian.org> Sat, 25 Sep 1999 22:00:31 +1000
58
59netkit-telnet (0.14-6) unstable; urgency=low
60
61 * Check for existence of user/group before removing (fixes #45651).
62
63 -- Herbert Xu <herbert@debian.org> Tue, 21 Sep 1999 21:07:18 +1000
64
65netkit-telnet (0.14-5) unstable; urgency=low
66
67 * Depend on base-files (>= 2.1.8) for group utmp (fixes #44687).
68
69 -- Herbert Xu <herbert@debian.org> Sat, 11 Sep 1999 12:53:08 +1000
70
71netkit-telnet (0.14-4) unstable; urgency=low
72
73 * Rebuilt with working fakeroot (fixes #44043, #44044).
74
75 -- Herbert Xu <herbert@debian.org> Fri, 3 Sep 1999 20:32:28 +1000
76
77netkit-telnet (0.14-3) unstable; urgency=medium
78
79 * telnetd is now a member of utmp (fixes #43543).
80 * Call adduser with --quiet (fixes #43587).
81 * configure now works with egcs 2.95 (fixes #43580, #43747)
82
83 -- Herbert Xu <herbert@debian.org> Thu, 2 Sep 1999 21:18:06 +1000
84
85netkit-telnet (0.14-2) unstable; urgency=low
86
87 * telnetd now depends on adduser and passwd (fixes #43515).
88
89 -- Herbert Xu <herbert@debian.org> Thu, 26 Aug 1999 14:49:25 +1000
90
91netkit-telnet (0.14-1) unstable; urgency=low
92
93 * New upstream release.
94 * Installed the login wrapper (fixes #42092).
95 * Reopen logging if necessary (fixes #36149).
96
97 -- Herbert Xu <herbert@debian.org> Tue, 24 Aug 1999 09:17:24 +1000
98
99netkit-telnet (0.12-6) unstable; urgency=low
100
101 * Applied patch from Matt McLean for openpty support (fixes #35629).
102 * Use glibc versions of logout/logwtmp.
103
104 -- Herbert Xu <herbert@debian.org> Tue, 29 Jun 1999 14:16:14 +1000
105
106netkit-telnet (0.12-5) unstable; urgency=low
107
108 * Fixed a bug with hostnames longer than 64 characters (fixes #33559).
109
110 -- Herbert Xu <herbert@debian.org> Tue, 16 Mar 1999 15:24:36 +1100
111
112netkit-telnet (0.12-4) frozen unstable; urgency=low
113
114 * Uploaded to slink.
115
116 -- Herbert Xu <herbert@debian.org> Sun, 15 Nov 1998 15:04:40 +1100
117
118netkit-telnet (0.12-3) unstable; urgency=low
119
120 * Rebuilt with libncurses4.
121
122 -- Herbert Xu <herbert@debian.org> Sun, 1 Nov 1998 19:38:49 +1100
123
124netkit-telnet (0.12-2) unstable; urgency=low
125
126 * Rebuilt with libstdc++2.9 (fixes #27789).
127
128 -- Herbert Xu <herbert@debian.org> Thu, 15 Oct 1998 22:32:04 +1000
129
130netkit-telnet (0.12-1) unstable; urgency=low
131
132 * Initial Release.
133
134 -- Herbert Xu <herbert@debian.org> Mon, 28 Sep 1998 16:50:43 +1000
135
136Local variables:
137mode: debian-changelog
138add-log-mailing-address: "herbert@debian.org"
139End:
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/control b/exploits/7350855-netkit/netkit-telnet-0.16/debian/control
new file mode 100644
index 0000000..fe25130
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/control
@@ -0,0 +1,21 @@
1Source: netkit-telnet
2Section: net
3Priority: standard
4Maintainer: Herbert Xu <herbert@debian.org>
5Standards-Version: 3.0.1
6
7Package: telnet
8Architecture: any
9Depends: ${shlibs:Depends}
10Replaces: netstd
11Description: The telnet client.
12 The telnet command is used for interactive communication with another host
13 using the TELNET protocol.
14
15Package: telnetd
16Architecture: any
17Depends: netbase, adduser, base-files (>= 2.1.8), ${shlibs:Depends}
18Replaces: netstd
19Description: The telnet server.
20 The in.telnetd program is a server which supports the DARPA telnet interactive
21 communication protocol.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/copyright b/exploits/7350855-netkit/netkit-telnet-0.16/debian/copyright
new file mode 100644
index 0000000..94881eb
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/copyright
@@ -0,0 +1,18 @@
1This package was split from netstd by Herbert Xu herbert@debian.org on
2Mon, 28 Sep 1998 16:50:43 +1000.
3
4netstd was created by Peter Tobias tobias@et-inf.fho-emden.de on
5Wed, 20 Jul 1994 17:23:21 +0200.
6
7It was downloaded from ftp://ftp.uk.linux.org/pub/linux/Networking/telnet+ftp/.
8
9Copyright:
10
11Copyright (c) 1988, 1993 The Regents of the University of California.
12Copyright (c) 1995 David A. Holland
13Copyright (c) 1994 Peter Tobias (issue.net(5))
14Copyright (c) 1983, 1995 Eric P. Allman (setproctitle.[ch])
15
16The license can be found at /usr/doc/copyright/BSD.
17
18$Id: copyright,v 1.2 2000/03/08 01:14:59 herbert Exp $
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/dirs b/exploits/7350855-netkit/netkit-telnet-0.16/debian/dirs
new file mode 100644
index 0000000..98d1583
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/dirs
@@ -0,0 +1,2 @@
1usr/bin
2usr/share/man/man1
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/docs b/exploits/7350855-netkit/netkit-telnet-0.16/debian/docs
new file mode 100644
index 0000000..9632452
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/docs
@@ -0,0 +1,2 @@
1BUGS
2README
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/login.c b/exploits/7350855-netkit/netkit-telnet-0.16/debian/login.c
new file mode 100644
index 0000000..653129e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/login.c
@@ -0,0 +1,23 @@
1#include <unistd.h>
2#include <paths.h>
3#include <syslog.h>
4
5#ifndef _PATH_LOGIN
6#define _PATH_LOGIN "/bin/login"
7#endif
8
9int main(int argc, char **argv)
10{
11 while(argc--) {
12 if((argv[argc][0] == '-')
13 && (argv[argc][1] == 'f')) {
14 openlog("login.telnetd", LOG_PID, LOG_AUTHPRIV);
15 syslog(LOG_CRIT, "login.telnetd tried to use \"-f\"");
16 closelog();
17 return 1;
18 }
19 }
20 setuid(geteuid());
21 argv[0] = _PATH_LOGIN;
22 return execv(argv[0], argv);
23}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/rules b/exploits/7350855-netkit/netkit-telnet-0.16/debian/rules
new file mode 100644
index 0000000..ef60a05
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/rules
@@ -0,0 +1,77 @@
1#!/usr/bin/make -f
2# $Id: rules,v 1.6 2000/03/14 23:43:29 herbert Exp $
3# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
4
5# Uncomment this to turn on verbose mode.
6#export DH_VERBOSE=1
7
8CFLAGS=-g -O2 -Wall
9
10build: build-stamp
11build-stamp: debian/login
12 dh_testdir
13
14 if [ ! -f MCONFIG ]; then ./configure --debug; fi
15 $(MAKE)
16
17 touch build-stamp
18
19clean:
20 dh_testdir
21 dh_testroot
22 rm -f build-stamp install-stamp
23
24 -$(MAKE) distclean
25 rm -f debian/login debian/login.o
26
27 dh_clean
28
29install: install-stamp
30install-stamp: build-stamp
31 dh_testdir
32 dh_testroot
33 dh_clean -k
34 dh_installdirs
35
36 $(MAKE) -C telnet INSTALLROOT=`pwd`/debian/tmp MANDIR=/usr/share/man \
37 install
38 $(MAKE) -C telnetd INSTALLROOT=`pwd`/debian/telnetd \
39 MANDIR=/usr/share/man install
40 cp debian/login debian/telnetd/usr/lib/telnetd
41
42 touch install-stamp
43
44# Build architecture-independent files here.
45binary-indep: build install
46# We have nothing to do by default.
47
48# Build architecture-dependent files here.
49binary-arch: build install
50# dh_testversion
51 dh_testdir
52 dh_testroot
53 dh_installdocs
54 dh_installexamples
55 dh_installmenu
56# dh_installemacsen
57# dh_installinit
58 dh_installcron
59# dh_installmanpages
60# dh_undocumented
61 dh_installchangelogs ChangeLog
62 dh_strip
63 dh_compress
64 dh_fixperms
65 dh_suidregister
66 dh_installdeb
67 dh_shlibdeps
68 dh_gencontrol
69# dh_makeshlibs
70 dh_md5sums
71 dh_builddeb
72
73source diff:
74 @echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
75
76binary: binary-indep binary-arch
77.PHONY: build clean binary-indep binary-arch binary
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.dirs b/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.dirs
new file mode 100644
index 0000000..8759ade
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.dirs
@@ -0,0 +1,4 @@
1usr/lib/telnetd
2usr/share/man/man5
3usr/share/man/man8
4usr/sbin
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.postinst b/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.postinst
new file mode 100644
index 0000000..6ff8f5c
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.postinst
@@ -0,0 +1,45 @@
1#!/bin/sh -e
2# $Id: telnetd.postinst,v 1.9 2000/03/08 01:13:20 herbert Exp $
3
4if ! id -u telnetd >/dev/null 2>&1; then
5 if sg telnetd -c true 2>/dev/null; then
6 groupdel telnetd
7 fi
8 adduser --quiet --system --group --home /usr/lib/telnetd telnetd
9fi
10adduser --quiet telnetd utmp
11if [ -e /etc/suid.conf -a -x /usr/sbin/suidregister ]; then
12 suidregister -s telnetd /usr/lib/telnetd/login root telnetd 4754
13else
14 chown root.telnetd /usr/lib/telnetd/login
15 chmod 4754 /usr/lib/telnetd/login
16fi
17
18if grep -q "^devpts " /proc/mounts; then
19 REMOVE="telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.telnetd"
20 ADD="telnet stream tcp nowait telnetd.telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd"
21else
22 REMOVE="telnet stream tcp nowait telnetd.telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd"
23 ADD="telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.telnetd"
24fi
25
26case "$1" in
27abort-upgrade | abort-deconfigure | abort-remove)
28 update-inetd --enable telnet
29 ;;
30configure)
31 if [ -n "$2" ] && dpkg --compare-versions "$2" ge 0.14-1 &&
32 ! grep -q "^$REMOVE" /etc/inetd.conf; then
33 update-inetd --enable telnet
34 else
35 update-inetd --remove "$REMOVE"
36 update-inetd --group STANDARD --add "$ADD"
37 fi
38 ;;
39*)
40 printf "$0: incorrect arguments: $*\n" >&2
41 exit 1
42 ;;
43esac
44
45#DEBHELPER#
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.postrm b/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.postrm
new file mode 100644
index 0000000..cc0531c
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.postrm
@@ -0,0 +1,29 @@
1#!/bin/sh -e
2# $Id: telnetd.postrm,v 1.6 1999/11/25 21:27:08 herbert Exp $
3
4if [ -e /etc/suid.conf -a -x /usr/sbin/suidunregister ]; then
5 suidunregister -s telnetd /usr/lib/telnetd/login
6fi
7
8case "$1" in
9abort-install | remove | abort-upgrade | upgrade | failed-upgrade | disappear)
10 ;;
11purge)
12 if id telnetd >/dev/null 2>&1; then
13 userdel telnetd
14 fi
15 if sg telnetd -c true 2>/dev/null; then
16 groupdel telnetd
17 fi
18 # If netbase is not installed, then we don't need to do the remove.
19 if command -v update-inetd >/dev/null 2>&1; then
20 update-inetd --remove "telnet .* /usr/sbin/in.telnetd"
21 fi
22 ;;
23*)
24 echo "$0: incorrect arguments: $*" >&2
25 exit 1
26 ;;
27esac
28
29#DEBHELPER#
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.prerm b/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.prerm
new file mode 100644
index 0000000..47a26d2
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/debian/telnetd.prerm
@@ -0,0 +1,9 @@
1#!/bin/sh -e
2# $Id: telnetd.prerm,v 1.2 1999/08/27 10:45:45 herbert Exp $
3
4# If netbase is not installed, then we don't need to do the remove.
5if command -v update-inetd >/dev/null 2>&1; then
6 update-inetd --disable telnet
7fi
8
9#DEBHELPER#
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/pty-hang.patch b/exploits/7350855-netkit/netkit-telnet-0.16/pty-hang.patch
new file mode 100644
index 0000000..850f4b9
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/pty-hang.patch
@@ -0,0 +1,99 @@
1From whawes@star.net Sun May 25 11:17:36 1997
2Received: from venus.star.net (root@venus.star.net [199.232.114.5]) by hcs.harvard.edu (8.8.5/8.8.3) with ESMTP id LAA15293 for <dholland@hcs.harvard.edu>; Sun, 25 May 1997 11:17:35 -0400 (EDT)
3Received: from hawes (bos221p.star.net [199.232.112.221]) by venus.star.net (8.8.5/8.7.3) with ESMTP id LAA29775; Sun, 25 May 1997 11:17:08 -0400
4Message-ID: <33885894.B2043F5E@star.net>
5Date: Sun, 25 May 1997 11:19:48 -0400
6From: Bill Hawes <whawes@star.net>
7X-Mailer: Mozilla 4.0b3 [en] (WinNT; I)
8MIME-Version: 1.0
9To: David Holland <dholland@hcs.harvard.edu>,
10 Alan Cox <net-patches@lxorguk.ukuu.org.uk>,
11 Peter Tobias <tobias@server.et-inf.fho-emden.de>,
12 "Theodore Ts'o" <tytso@MIT.EDU>
13Subject: kernel patch to fix telnetd deadlock
14X-Priority: 3 (Normal)
15Content-Type: multipart/mixed; boundary="------------B47A35BD86775A5D9DA0F308"
16Status: RO
17
18This is a multi-part message in MIME format.
19--------------B47A35BD86775A5D9DA0F308
20Content-Type: text/plain; charset=us-ascii
21Content-Transfer-Encoding: 7bit
22
23Attached is a patch for drivers/char/n_tty.c that fixes the telnetd
24deadlock when more than 256 chars are typed without a newline. With
25this patch in place, the total of typed-ahead and entered commands is
26still limited to 256 chars, but telnetd comes back to life when the
27buffer is emptied.
28
29Here's what the problem was:
30telnetd does a select() on the master side of a pty to see when it's
31safe to write a character without blocking.
32
33The N_TTY line discipline select() calls the pty driver's
34chars_in_buffer() function to see how many characters are buffered.
35If there are more than 256, the caller has to wait.
36
37The pty driver.chars_in_buffer calls the other side's ldisc
38chars_in_buffer() function. Here's where the problem arises: the slave
39pty is in canonical mode, so that no characters can be read until a
40newline is entered. But the n_tty_chars_in_buffer was returning the
41full number of characters entered, even if no newline had been entered.
42Hence after 256 characters were typed, select() makes telnetd wait, and
43the newline can never arrive.
44
45The patch corrects n_tty_chars_in_buffer() by checking for canonical
46mode and returning 0 if no data is available to be read.
47
48I've tested this on 2.0.30, and it should apply to 2.1.40 as well.
49Please check it out and forward it as you see wish.
50
51I'm working on a patch for pty.c to allow a greater amount of type-ahead
52while still avoiding a deadlock.
53
54Regards,
55Bill Hawes
56--------------B47A35BD86775A5D9DA0F308
57Content-Type: text/plain; charset=us-ascii; name="n_tty-chars-patch"
58Content-Transfer-Encoding: 7bit
59Content-Disposition: inline; filename="n_tty-chars-patch"
60
61--- drivers/char/n_tty.c.old Mon Sep 2 08:18:26 1996
62+++ drivers/char/n_tty.c Sun May 25 10:10:29 1997
63@@ -86,10 +86,31 @@
64
65 /*
66 * Return number of characters buffered to be delivered to user
67+ * WSH 05/20/97: Added check for canonical mode
68+ * In canonical mode, no characters are available to be read until
69+ * the first newline has been entered. (Any characters in the buffer
70+ * may yet be erased ...)
71+ *
72+ * This was causing a deadlock in telnetd: select() thought the buffer
73+ * was already too full, so telnetd couldn't send a newline, but the
74+ * slave PTY couldn't read anything because there was no newline.
75 */
76 int n_tty_chars_in_buffer(struct tty_struct *tty)
77 {
78- return tty->read_cnt;
79+ /* Check first for canonical mode ... */
80+ if (tty->icanon) {
81+ if (!tty->canon_data) return 0;
82+
83+ /* Would prefer to just fall through and return the true
84+ * count, but that could still cause deadlocks until some
85+ * other routines are patched. For now, calculate the
86+ * characters actually available for reading.
87+ */
88+ return (tty->canon_head > tty->read_tail) ?
89+ tty->canon_head - tty->read_tail :
90+ tty->canon_head + (N_TTY_BUF_SIZE - tty->read_tail);
91+ }
92+ return tty->read_cnt; /* all characters available */
93 }
94
95 /*
96
97--------------B47A35BD86775A5D9DA0F308--
98
99
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/Makefile b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/Makefile
new file mode 100644
index 0000000..cef866f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/Makefile
@@ -0,0 +1,30 @@
1all: telnet
2
3include ../MCONFIG
4include ../MRULES
5
6#CXXFLAGS:=$(patsubst -O2, -g, $(CXXFLAGS))
7
8# -DAUTHENTICATE
9CXXFLAGS += -DUSE_TERMIO -DKLUDGELINEMODE
10LIBS += $(LIBTERMCAP)
11
12SRCS = commands.cc main.cc network.cc ring.cc sys_bsd.cc telnet.cc \
13 terminal.cc tn3270.cc utilities.cc genget.cc environ.cc netlink.cc
14
15OBJS = $(patsubst %.cc, %.o, $(SRCS))
16
17telnet: $(OBJS)
18 $(CXX) $(LDFLAGS) $^ $(LIBS) -o $@
19
20include depend.mk
21depend:
22 $(CXX) $(CXXFLAGS) -MM $(SRCS) >depend.mk
23
24install: telnet
25 install -s -m$(BINMODE) telnet $(INSTALLROOT)$(BINDIR)
26 install -m$(MANMODE) telnet.1 $(INSTALLROOT)$(MANDIR)/man1
27
28clean:
29 rm -f *.o telnet
30
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/NetKit-B-0.06-telnet.patch b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/NetKit-B-0.06-telnet.patch
new file mode 100644
index 0000000..892423b
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/NetKit-B-0.06-telnet.patch
@@ -0,0 +1,27 @@
1diff -ur NetKit-B-0.06.orig/telnet/defines.h NetKit-B-0.06/telnet/defines.h
2--- NetKit-B-0.06.orig/telnet/defines.h Fri Dec 17 07:18:16 1993
3+++ NetKit-B-0.06/telnet/defines.h Mon Jun 5 15:34:51 1995
4@@ -34,6 +34,10 @@
5 * $Id: NetKit-B-0.06-telnet.patch,v 1.1 1996/07/16 05:17:22 dholland Exp $
6 */
7
8+#define ENV_VAR NEW_ENV_VAR
9+#define ENV_VALUE NEW_ENV_VALUE
10+#define TELOPT_ENVIRON TELOPT_NEW_ENVIRON
11+
12 #define settimer(x) clocks.x = clocks.system++
13
14 #if !defined(TN3270)
15diff -ur NetKit-B-0.06.orig/telnetd/defs.h NetKit-B-0.06/telnetd/defs.h
16--- NetKit-B-0.06.orig/telnetd/defs.h Mon May 23 09:11:57 1994
17+++ NetKit-B-0.06/telnetd/defs.h Mon Jun 5 15:34:39 1995
18@@ -40,6 +40,9 @@
19 #include <sys/types.h>
20 #include <sys/param.h>
21
22+#define ENV_VAR NEW_ENV_VAR
23+#define ENV_VALUE NEW_ENV_VALUE
24+#define TELOPT_ENVIRON TELOPT_NEW_ENVIRON
25
26 #ifndef BSD
27 # define BSD 43
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/README b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/README
new file mode 100644
index 0000000..cd18f9a
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/README
@@ -0,0 +1,26 @@
1
2Telnet has been massively hacked up for this release.
3
4It presently requires a C++ compiler (gcc 2.7.2 or higher
5recommended), but not libg++ or libstdc++. That is, unless you went to
6special effort to not install the C++ compiler when you installed gcc,
7you'll be fine.
8
9Large amounts of further hacking are expected. If you're interested in
10working on it, please contact me, as diffs are likely to become
11useless very quickly.
12
13Support for assorted old/broken systems has been dropped. Some such
14support may be reinstated in the future once the code has been cleaned
15up sufficiently. On the other hand, it may not.
16
17Known bugs/shortcomings at this point:
18
19 - Under some circumstances it can theoretically encounter a
20 buffer overflow condition and drop data on the floor. If
21 anyone actually observes this ``in the wild'' I'd appreciate
22 knowing the circumstances. I'm also not convinced the old
23 behavior was any better.
24 - Various of the debug/trace modes don't work. This probably
25 doesn't matter to anyone not actually coding on it.
26
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/README.old b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/README.old
new file mode 100644
index 0000000..086c88f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/README.old
@@ -0,0 +1,566 @@
1
2
3This is a distribution of both client and server telnet. These programs
4have been compiled on:
5 telnet telnetd
6 BSD 4.3 Reno X X
7 UNICOS 5.1 X X
8 UNICOS 6.0 X X
9 UNICOS 6.1 X X
10 UNICOS 7.0 X X
11 SunOs 3.5 X X (no linemode in server)
12 SunOs 4.1 X X (no linemode in server)
13 DYNIX V3.0.17.9 X X (no linemode in server)
14 Ultrix 3.1 X X (no linemode in server)
15 Ultrix 4.0 X X (no linemode in server)
16
17In addition, previous versions have been compiled on the following
18machines, but were not available for testing this version.
19 telnet telnetd
20 SunOs 4.0.3c X X (no linemode in server)
21 BSD 4.3 X X (no linemode in server)
22 DYNIX V3.0.12 X X (no linemode in server)
23
24Februrary 22, 1991:
25
26 Features:
27
28 This version of telnet/telnetd has support for both
29 the AUTHENTICATION and ENCRYPTION options. The
30 AUTHENTICATION option is fairly well defined, and
31 an option number has been assigned to it. The
32 ENCRYPTION option is still in a state of flux; an
33 option number has NOT been assigned to it yet.
34 The code is provided in this release for experimental
35 and testing purposes.
36
37 The telnet "send" command can now be used to send
38 do/dont/will/wont commands, with any telnet option
39 name. The rules for when do/dont/will/wont are sent
40 are still followed, so just because the user requests
41 that one of these be sent doesn't mean that it will
42 be sent...
43
44 The telnet "getstatus" command no longer requires
45 that option printing be enabled to see the response
46 to the "DO STATUS" command.
47
48 A -n flag has been added to telnetd to disable
49 keepalives.
50
51 A new telnet command, "auth" has been added (if
52 AUTHENTICATE is defined). It has four sub-commands,
53 "status", "debug", "disable", "enable" and "help".
54
55 A new telnet command, "encrypt" has been added (if
56 ENCRYPT is defined). It has many sub-commands:
57 "enable", "type", "start", "stop", "input",
58 "-input", "output", "-output", "status", "auto",
59 "verbose", "debug", and "help".
60
61 An "rlogin" interface has been added. If the program
62 is named "rlogin", or the "-r" flag is given, then
63 an rlogin type of interface will be used.
64 ~. Terminates the session
65 ~<susp> Suspend the session
66 ~^] Escape to telnet command mode
67 ~~ Pass through the ~.
68 BUG: If you type the rlogin escape character
69 in the middle of a line while in rlogin
70 mode, you cannot erase it or any characters
71 before it. Hopefully this can be fixed
72 in a future release...
73
74 General changes:
75
76 A "libtelnet.a" has now been created. This libraray
77 contains code that is common to both telnet and
78 telnetd. This is also where library routines that
79 are needed, but are not in the standard C library,
80 are placed.
81
82 The makefiles have been re-done. All of the site
83 specific configuration information has now been put
84 into a single "Config.generic" file, in the top level
85 directory. Changing this one file will take care of
86 all three subdirectories. Also, to add a new/local
87 definition, a "Config.local" file may be created
88 at the top level; if that file exists, the subdirectories
89 will use that file instead of "Config.generic".
90
91 Many 1-2 line functions in commands.c have been
92 removed, and just inserted in-line, or replaced
93 with a macro.
94
95 Bug Fixes:
96
97 The non-termio code in both telnet and telnetd was
98 setting/clearing CTLECH in the sg_flags word. This
99 was incorrect, and has been changed to set/clear the
100 LCTLECH bit in the local mode word.
101
102 The SRCRT #define has been removed. If IP_OPTIONS
103 and IPPROTO_IP are defined on the system, then the
104 source route code is automatically enabled.
105
106 The NO_GETTYTAB #define has been removed; there
107 is a compatability routine that can be built into
108 libtelnet to achive the same results.
109
110 The server, telnetd, has been switched to use getopt()
111 for parsing the argument list.
112
113 The code for getting the input/output speeds via
114 cfgetispeed()/cfgetospeed() was still not quite
115 right in telnet. Posix says if the ispeed is 0,
116 then it is really equal to the ospeed.
117
118 The suboption processing code in telnet now has
119 explicit checks to make sure that we received
120 the entire suboption (telnetd was already doing this).
121
122 The telnet code for processing the terminal type
123 could cause a core dump if an existing connection
124 was closed, and a new connection opened without
125 exiting telnet.
126
127 Telnetd was doing a TCSADRAIN when setting the new
128 terminal settings; This is not good, because it means
129 that the tcsetattr() will hang waiting for output to
130 drain, and telnetd is the only one that will drain
131 the output... The fix is to use TCSANOW which does
132 not wait.
133
134 Telnetd was improperly setting/clearing the ISTRIP
135 flag in the c_lflag field, it should be using the
136 c_iflag field.
137
138 When the child process of telnetd was opening the
139 slave side of the pty, it was re-setting the EXTPROC
140 bit too early, and some of the other initialization
141 code was wiping it out. This would cause telnetd
142 to go out of linemode and into single character mode.
143
144 One instance of leaving linemode in telnetd forgot
145 to send a WILL ECHO to the client, the net result
146 would be that the user would see double character
147 echo.
148
149 If the MODE was being changed several times very
150 quickly, telnetd could get out of sync with the
151 state changes and the returning acks; and wind up
152 being left in the wrong state.
153
154September 14, 1990:
155
156 Switch the client to use getopt() for parsing the
157 argument list. The 4.3Reno getopt.c is included for
158 systems that don't have getopt().
159
160 Use the posix _POSIX_VDISABLE value for what value
161 to use when disabling special characters. If this
162 is undefined, it defaults to 0x3ff.
163
164 For non-termio systems, TIOCSETP was being used to
165 change the state of the terminal. This causes the
166 input queue to be flushed, which we don't want. This
167 is now changed to TIOCSETN.
168
169 Take out the "#ifdef notdef" around the code in the
170 server that generates a "sync" when the pty oputput
171 is flushed. The potential problem is that some older
172 telnet clients may go into an infinate loop when they
173 receive a "sync", if so, the server can be compiled
174 with "NO_URGENT" defined.
175
176 Fix the client where it was setting/clearing the OPOST
177 bit in the c_lflag field, not the c_oflag field.
178
179 Fix the client where it was setting/clearing the ISTRIP
180 bit in the c_lflag field, not the c_iflag field. (On
181 4.3Reno, this is the ECHOPRT bit in the c_lflag field.)
182 The client also had its interpretation of WILL BINARY
183 and DO BINARY reversed.
184
185 Fix a bug in client that would cause a core dump when
186 attempting to remove the last environment variable.
187
188 In the client, there were a few places were switch()
189 was being passed a character, and if it was a negative
190 value, it could get sign extended, and not match
191 the 8 bit case statements. The fix is to and the
192 switch value with 0xff.
193
194 Add a couple more printoption() calls in the client, I
195 don't think there are any more places were a telnet
196 command can be received and not printed out when
197 "options" is on.
198
199 A new flag has been added to the client, "-a". Currently,
200 this just causes the USER name to be sent across, in
201 the future this may be used to signify that automatic
202 authentication is requested.
203
204 The USER variable is now only sent by the client if
205 the "-a" or "-l user" options are explicity used, or
206 if the user explicitly asks for the "USER" environment
207 variable to be exported. In the server, if it receives
208 the "USER" environment variable, it won't print out the
209 banner message, so that only "Password:" will be printed.
210 This makes the symantics more like rlogin, and should be
211 more familiar to the user. (People are not used to
212 getting a banner message, and then getting just a
213 "Password:" prompt.)
214
215 Re-vamp the code for starting up the child login
216 process. The code was getting ugly, and it was
217 hard to tell what was really going on. What we
218 do now is after the fork(), in the child:
219 1) make sure we have no controlling tty
220 2) open and initialize the tty
221 3) do a setsid()/setpgrp()
222 4) makes the tty our controlling tty.
223 On some systems, #2 makes the tty our controlling
224 tty, and #4 is a no-op. The parent process does
225 a gets rid of any controlling tty after the child
226 is fork()ed.
227
228 Use the strdup() library routine in telnet, instead
229 of the local savestr() routine. If you don't have
230 strdup(), you need to define NO_STRDUP.
231
232 Add support for ^T (SIGINFO/VSTATUS), found in the
233 4.3Reno distribution. This maps to the AYT character.
234 You need a 4-line bugfix in the kernel to get this
235 to work properly:
236
237 > *** tty_pty.c.ORG Tue Sep 11 09:41:53 1990
238 > --- tty_pty.c Tue Sep 11 17:48:03 1990
239 > ***************
240 > *** 609,613 ****
241 > if ((tp->t_lflag&NOFLSH) == 0)
242 > ttyflush(tp, FREAD|FWRITE);
243 > ! pgsignal(tp->t_pgrp, *(unsigned int *)data);
244 > return(0);
245 > }
246 > --- 609,616 ----
247 > if ((tp->t_lflag&NOFLSH) == 0)
248 > ttyflush(tp, FREAD|FWRITE);
249 > ! pgsignal(tp->t_pgrp, *(unsigned int *)data, 1);
250 > ! if ((*(unsigned int *)data == SIGINFO) &&
251 > ! ((tp->t_lflag&NOKERNINFO) == 0))
252 > ! ttyinfo(tp);
253 > return(0);
254 > }
255
256 The client is now smarter when setting the telnet escape
257 character; it only sets it to one of VEOL and VEOL2 if
258 one of them is undefined, and the other one is not already
259 defined to the telnet escape character.
260
261 Handle TERMIOS systems that have seperate input and output
262 line speed settings imbedded in the flags.
263
264 Many other minor bug fixes.
265
266June 20, 1990:
267 Re-organize makefiles and source tree. The telnet/Source
268 directory is now gone, and all the source that was in
269 telnet/Source is now just in the telnet directory.
270
271 Seperate makefile for each system are now gone. There
272 are two makefiles, Makefile and Makefile.generic.
273 The "Makefile" has the definitions for the various
274 system, and "Makefile.generic" does all the work.
275 There is a variable called "WHAT" that is used to
276 specify what to make. For example, in the telnet
277 directory, you might say:
278 make 4.4bsd WHAT=clean
279 to clean out the directory.
280
281 Add support for the ENVIRON and XDISPLOC options.
282 In order for the server to work, login has to have
283 the "-p" option to preserve environment variables.
284
285 Add the SOFT_TAB and LIT_ECHO modes in the LINEMODE support.
286
287 Add the "-l user" option to command line and open command
288 (This is passed through the ENVIRON option).
289
290 Add the "-e" command line option, for setting the escape
291 character.
292
293 Add the "-D", diagnostic, option to the server. This allows
294 the server to print out debug information, which is very
295 useful when trying to debug a telnet that doesn't have any
296 debugging ability.
297
298 Turn off the literal next character when not in LINEMODE.
299
300 Don't recognize ^Y locally, just pass it through.
301
302 Make minor modifications for Sun4.0 and Sun4.1
303
304 Add support for both FORW1 and FORW2 characters. The
305 telnet escpape character is set to whichever of the
306 two is not being used. If both are in use, the escape
307 character is not set, so when in linemode the user will
308 have to follow the escape character with a <CR> or <EOF)
309 to get it passed through.
310
311 Commands can now be put in single and double quotes, and
312 a backslash is now an escape character. This is needed
313 for allowing arbitrary strings to be assigned to environment
314 variables.
315
316 Switch telnetd to use macros like telnet for keeping
317 track of the state of all the options.
318
319 Fix telnetd's processing of options so that we always do
320 the right processing of the LINEMODE option, regardless
321 of who initiates the request to turn it on. Also, make
322 sure that if the other side went "WILL ECHO" in response
323 to our "DO ECHO", that we send a "DONT ECHO" to get the
324 option turned back off!
325
326 Fix the TERMIOS setting of the terminal speed to handle both
327 BSD's seperate fields, and the SYSV method of CBAUD bits.
328
329 Change how we deal with the other side refusing to enable
330 an option. The sequence used to be: send DO option; receive
331 WONT option; send DONT option. Now, the sequence is: send
332 DO option; receive WONT option. Both should be valid
333 according to the spec, but there has been at least one
334 client implementation of telnet identified that can get
335 really confused by this. (The exact sequence, from a trace
336 on the server side, is (numbers are number of responses that
337 we expect to get after that line...):
338
339 send WILL ECHO 1 (initial request)
340 send WONT ECHO 2 (server is changing state)
341 recv DO ECHO 1 (first reply, ok. expect DONT ECHO next)
342 send WILL ECHO 2 (server changes state again)
343 recv DONT ECHO 1 (second reply, ok. expect DO ECHO next)
344 recv DONT ECHO 0 (third reply, wrong answer. got DONT!!!)
345 *** send WONT ECHO (send WONT to acknowledge the DONT)
346 send WILL ECHO 1 (ask again to enable option)
347 recv DO ECHO 0
348
349 recv DONT ECHO 0
350 send WONT ECHO 1
351 recv DONT ECHO 0
352 recv DO ECHO 1
353 send WILL ECHO 0
354 (and the last 5 lines loop forever)
355
356 The line with the "***" is last of the WILL/DONT/WONT sequence.
357 The change to the server to not generate that makes this same
358 example become:
359
360 send will ECHO 1
361 send wont ECHO 2
362 recv do ECHO 1
363 send will ECHO 2
364 recv dont ECHO 1
365 recv dont ECHO 0
366 recv do ECHO 1
367 send will ECHO 0
368
369 There is other option negotiation going on, and not sending
370 the third part changes some of the timings, but this specific
371 example no longer gets stuck in a loop. The "telnet.state"
372 file has been modified to reflect this change to the algorithm.
373
374 A bunch of miscellaneous bug fixes and changes to make
375 lint happier.
376
377 This version of telnet also has some KERBEROS stuff in
378 it. This has not been tested, it uses an un-authorized
379 telnet option number, and uses an out-of-date version
380 of the (still being defined) AUTHENTICATION option.
381 There is no support for this code, do not enable it.
382
383
384March 1, 1990:
385CHANGES/BUGFIXES SINCE LAST RELEASE:
386 Some support for IP TOS has been added. Requires that the
387 kernel support the IP_TOS socket option (currently this
388 is only in UNICOS 6.0).
389
390 Both telnet and telnetd now use the cc_t typedef. typedefs are
391 included for systems that don't have it (in termios.h).
392
393 SLC_SUSP was not supported properly before. It is now.
394
395 IAC EOF was not translated properly in telnetd for SYSV_TERMIO
396 when not in linemode. It now saves a copy of the VEOF character,
397 so that when ICANON is turned off and we can't trust it anymore
398 (because it is now the VMIN character) we use the saved value.
399
400 There were two missing "break" commands in the linemode
401 processing code in telnetd.
402
403 Telnetd wasn't setting the kernel window size information
404 properly. It was using the rows for both rows and columns...
405
406Questions/comments go to
407 David Borman
408 Cray Research, Inc.
409 655F Lone Oak Drive
410 Eagan, MN 55123
411 dab@cray.com.
412
413README: You are reading it.
414
415Config.generic:
416 This file contains all the OS specific definitions. It
417 has pre-definitions for many common system types, and is
418 in standard makefile fromat. See the comments at the top
419 of the file for more information.
420
421Config.local:
422 This is not part of the distribution, but if this file exists,
423 it is used instead of "Config.generic". This allows site
424 specific configuration without having to modify the distributed
425 "Config.generic" file.
426
427kern.diff:
428 This file contains the diffs for the changes needed for the
429 kernel to support LINEMODE is the server. These changes are
430 for a 4.3BSD system. You may need to make some changes for
431 your particular system.
432
433 There is a new bit in the terminal state word, TS_EXTPROC.
434 When this bit is set, several aspects of the terminal driver
435 are disabled. Input line editing, character echo, and
436 mapping of signals are all disabled. This allows the telnetd
437 to turn of these functions when in linemode, but still keep
438 track of what state the user wants the terminal to be in.
439
440 New ioctl()s:
441
442 TIOCEXT Turn on/off the TS_EXTPROC bit
443 TIOCGSTATE Get t_state of tty to look at TS_EXTPROC bit
444 TIOCSIG Generate a signal to processes in the
445 current process group of the pty.
446
447 There is a new mode for packet driver, the TIOCPKT_IOCTL bit.
448 When packet mode is turned on in the pty, and the TS_EXTPROC
449 bit is set, then whenever the state of the pty is changed, the
450 next read on the master side of the pty will have the TIOCPKT_IOCTL
451 bit set, and the data will contain the following:
452 struct xx {
453 struct sgttyb a;
454 struct tchars b;
455 struct ltchars c;
456 int t_state;
457 int t_flags;
458 }
459 This allows the process on the server side of the pty to know
460 when the state of the terminal has changed, and what the new
461 state is.
462
463 However, if you define USE_TERMIO or SYSV_TERMIO, the code will
464 expect that the structure returned in the TIOCPKT_IOCTL is
465 the termio/termios structure.
466
467stty.diff:
468 This file contains the changes needed for the stty(1) program
469 to report on the current status of the TS_EXTPROC bit. It also
470 allows the user to turn on/off the TS_EXTPROC bit. This is useful
471 because it allows the user to say "stty -extproc", and the
472 LINEMODE option will be automatically disabled, and saying "stty
473 extproc" will re-enable the LINEMODE option.
474
475telnet.state:
476 Both the client and server have code in them to deal
477 with option negotiation loops. The algorithm that is
478 used is described in this file.
479
480tmac.doc:
481 Macros for use in formatting the man pages on non-4.3Reno
482 systems.
483
484telnet:
485 This directory contains the client code. No kernel changes are
486 needed to use this code.
487
488telnetd:
489 This directory contains the server code. If LINEMODE or KLUDGELINEMODE
490 are defined, then the kernel modifications listed above are needed.
491
492libtelnet:
493 This directory contains code that is common to both the client
494 and the server.
495
496arpa:
497 This directory has a new <arpa/telnet.h>
498
499
500The following TELNET options are supported:
501
502 LINEMODE:
503 The LINEMODE option is supported as per RFC1116. The
504 FORWARDMASK option is not currently supported.
505
506 BINARY: The client has the ability to turn on/off the BINARY
507 option in each direction. Turning on BINARY from
508 server to client causes the LITOUT bit to get set in
509 the terminal driver on both ends, turning on BINARY
510 from the client to the server causes the PASS8 bit
511 to get set in the terminal driver on both ends.
512
513 TERMINAL-TYPE:
514 This is supported as per RFC1091. On the server side,
515 when a terminal type is received, termcap/terminfo
516 is consulted to determine if it is a known terminal
517 type. It keeps requesting terminal types until it
518 gets one that it recongnizes, or hits the end of the
519 list. The server side looks up the entry in the
520 termcap/terminfo data base, and generates a list of
521 names which it then passes one at a time to each
522 request for a terminal type, duplicating the last
523 entry in the list before cycling back to the beginning.
524
525 NAWS: The Negotiate about Window Size, as per RFC 1073.
526
527 TERMINAL-SPEED:
528 Implemented as per RFC 1079
529
530 TOGGLE-FLOW-CONTROL:
531 Implemented as per RFC 1080
532
533 TIMING-MARK:
534 As per RFC 860
535
536 SGA: As per RFC 858
537
538 ECHO: As per RFC 857
539
540 STATUS:
541 The server will send its current status upon
542 request. It does not ask for the clients status.
543 The client will request the servers current status
544 from the "send getstatus" command.
545
546 ENVIRON:
547 This option is currently being defined by the IETF
548 Telnet Working Group, and an RFC has not yet been
549 issued, but should be in the near future...
550
551 X-DISPLAY-LOCATION:
552 This functionality can be done through the ENVIRON
553 option, it is added here for completeness.
554
555 AUTHENTICATION:
556 This option is currently being defined by the IETF
557 Telnet Working Group, and an RFC has not yet been
558 issued. The basic framework is pretty much decided,
559 but the definitions for the specific authentication
560 schemes is still in a state of flux.
561
562 ENCRYPT:
563 This option is currently being defined by the IETF
564 Telnet Working Group, and an RFC has not yet been
565 issued. The draft RFC is still in a state of flux,
566 so this code may change in the future.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/TODO b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/TODO
new file mode 100644
index 0000000..f67f253
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/TODO
@@ -0,0 +1,13 @@
1eliminate global variables
2 clean up command processing
3 fix "send" command
4 clean up option processing
5
6add empty encrypt hooks (layer over ring buffers)
7flushout --> use nullsink
8
9fix ring buffer so it allocates more buf instead of overflowing
10
11put tracing back in
12
13authentication?
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h
new file mode 100644
index 0000000..56f1123
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h
@@ -0,0 +1,97 @@
1//
2// File: array.h
3// Date: 16-Jul-95
4// Description: array template
5//
6/*
7 * Copyright (c) 1995 David A. Holland.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Author nor the names of any contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef ARRAY_H
36#define ARRAY_H
37
38#ifndef assert
39#include <assert.h>
40#endif
41
42#ifndef NULL
43#define NULL 0
44#endif
45
46inline void *operator new(size_t, void *v) { return v; }
47
48template <class T>
49class array {
50 protected:
51 T *v;
52 int n, max;
53
54 void reallocto(int newsize) {
55 while (max<newsize) max += 16;
56 char *x = new char[max*sizeof(T)];
57 memcpy(x,v,n*sizeof(T));
58 delete []((char *)v);
59 v = (T *) x;
60 }
61 public:
62 array() { v=NULL; n=max=0; }
63 ~array() { setsize(0); delete []((char *)v); }
64
65 int num() const { return n; }
66
67 void setsize(int newsize) {
68 if (newsize>max) reallocto(newsize);
69 if (newsize>n) {
70 // call default constructors
71 for (int i=n; i<newsize; i++) (void) new(&v[i]) T;
72 }
73 else {
74 // call destructors
75 for (int i=newsize; i<n; i++) v[i].~T();
76 }
77 n = newsize;
78 }
79
80 T &operator [] (int ix) const {
81 assert(ix>=0 && ix<n);
82 return v[ix];
83 }
84
85 int add(const T &val) {
86 int ix = n;
87 setsize(n+1);
88 v[ix] = val;
89 return ix;
90 }
91
92 void push(const T &val) { add(val); }
93
94 T pop() { T t = (*this)[n-1]; setsize(n-1); return t; }
95};
96
97#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/authenc.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/authenc.cc
new file mode 100644
index 0000000..5a12a11
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/authenc.cc
@@ -0,0 +1,114 @@
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)authenc.c 5.1 (Berkeley) 3/1/91
36 */
37char au_rcsid[] =
38 "$Id: authenc.cc,v 1.5 1996/08/02 01:06:31 dholland Exp $";
39
40#if defined(ENCRYPT) || defined(AUTHENTICATE)
41#include <sys/types.h>
42#include <arpa/telnet.h>
43#include <libtelnet/encrypt.h>
44#include <libtelnet/misc.h>
45
46#include "ring.h"
47#include "externs.h"
48#include "defines.h"
49#include "types.h"
50#include "proto.h"
51
52 int
53net_write(str, len)
54 unsigned char *str;
55 int len;
56{
57 if (NETROOM() > len) {
58 netoring.supply_data(str, len);
59 if (str[0] == IAC && str[1] == SE)
60 printsub('>', &str[2], len-2);
61 return(len);
62 }
63 return(0);
64}
65
66 void
67net_encrypt()
68{
69#if defined(ENCRYPT)
70 if (encrypt_output)
71 ring_encrypt(&netoring, encrypt_output);
72 else
73 ring_clearto(&netoring);
74#endif
75}
76
77 int
78telnet_spin()
79{
80 return(-1);
81}
82
83 char *
84telnet_getenv(val)
85 char *val;
86{
87 return((char *)env_getvalue((unsigned char *)val));
88}
89
90 char *
91telnet_gets(prompt, result, length, echo)
92 char *prompt;
93 char *result;
94 int length;
95 int echo;
96{
97 extern char *getpass();
98 extern int globalmode;
99 int om = globalmode;
100 char *res;
101
102 TerminalNewMode(-1);
103 if (echo) {
104 printf("%s", prompt);
105 res = fgets(result, length, stdin);
106 }
107 else if ((res = getpass(prompt))!=NULL) {
108 strncpy(result, res, length);
109 res = result;
110 }
111 TerminalNewMode(om);
112 return(res);
113}
114#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/commands.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/commands.cc
new file mode 100644
index 0000000..b3a2a3c
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/commands.cc
@@ -0,0 +1,2233 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)commands.c 5.5 (Berkeley) 3/22/91
36 */
37char cmd_rcsid[] =
38 "$Id: commands.cc,v 1.32 1999/09/28 16:29:24 dholland Exp $";
39
40#include <string.h>
41
42#include <sys/param.h>
43#include <sys/file.h>
44#include <sys/types.h>
45#include <sys/socket.h>
46#include <netinet/in.h>
47#include <netinet/ip.h>
48
49#ifdef CRAY
50#include <fcntl.h>
51#endif /* CRAY */
52
53#include <sys/wait.h>
54#include <signal.h>
55#include <netdb.h>
56#include <ctype.h>
57#include <pwd.h>
58#include <stdarg.h>
59#include <errno.h>
60#include <unistd.h>
61#include <stdlib.h>
62#include <arpa/inet.h>
63#include <arpa/telnet.h>
64
65#include "ring.h"
66
67#include "externs.h"
68#include "defines.h"
69#include "types.h"
70#include "genget.h"
71#include "environ.h"
72#include "proto.h"
73#include "ptrarray.h"
74#include "netlink.h"
75
76#ifdef __linux__
77#define HAS_IPPROTO_IP
78#endif
79
80#ifdef IPPROTO_IP
81#define HAS_IPPROTO_IP
82#endif
83
84#ifndef CRAY
85#if (defined(vax) || defined(tahoe) || defined(hp300)) && !defined(ultrix)
86#include <machine/endian.h>
87#endif /* vax */
88#endif /* CRAY */
89
90#define HELPINDENT ((int) sizeof ("connect"))
91
92#if defined(HAS_IPPROTO_IP) && defined(IP_TOS)
93int tos = -1;
94#endif /* defined(HAS_IPPROTO_IP) && defined(IP_TOS) */
95
96static unsigned long sourceroute(char *arg, char **cpp, int *lenp);
97
98
99char *hostname;
100static char *_hostname;
101
102//typedef int (*intrtn_t)(int argc, const char *argv[]);
103
104class command_entry;
105typedef ptrarray<command_entry> command_table;
106
107static int process_command(command_table *tab, int argc, const char **argv);
108
109
110class command_entry {
111 protected:
112 const char *name; /* command name */
113 const char *help; /* help string (NULL for no help) */
114
115 int nargs;
116 union { /* routine which executes command */
117 command_table *subhandler;
118 int (*handlern)(int, const char **);
119 int (*handler0)(void);
120 int (*handler1)(const char *);
121 int (*handler2)(const char *, const char *);
122 };
123 public:
124 command_entry(const char *n, const char *e,
125 int (*h)(int, const char **))
126 {
127 name = n;
128 help = e;
129 nargs = -1; handlern = h;
130 }
131 command_entry(const char *n, const char *e,
132 int (*h)(void))
133 {
134 name = n;
135 help = e;
136 nargs = 0; handler0 = h;
137 }
138 command_entry(const char *n, const char *e,
139 int (*h)(const char *))
140 {
141 name = n;
142 help = e;
143 nargs = 1; handler1 = h;
144 }
145 command_entry(const char *n, const char *e,
146 int (*h)(const char *, const char *))
147 {
148 name = n;
149 help = e;
150 nargs = 2; handler2 = h;
151 }
152 command_entry(const char *n, const char *e, command_table *sub) {
153 name = n;
154 help = e;
155 nargs = -2;
156 subhandler = sub;
157 }
158
159 int call(int argc, const char *argv[]) {
160 assert(argc>=1);
161 if (nargs>=0 && argc!=nargs+1) {
162 fprintf(stderr, "Wrong number of arguments for command.\n");
163 fprintf(stderr, "Try %s ? for help\n", argv[0]);
164 return 0; /* is this right? */
165 }
166 if (nargs==-2) {
167 if (argc<2) {
168 fprintf(stderr, "`%s' requires a subcommand.\n", argv[0]);
169 fprintf(stderr, "Try %s ? for help\n", argv[0]);
170 return 0; /* is this right? */
171 }
172 return process_command(subhandler, argc-1, argv+1);
173 }
174 else if (nargs==-1) return handlern(argc, argv);
175 else if (nargs==0) return handler0();
176 else if (nargs==1) return handler1(argv[1]);
177 else if (nargs==2) return handler2(argv[1], argv[2]);
178 return 0;
179 }
180
181 void describe() {
182 if (help) printf("%-*s\t%s\n", HELPINDENT, name, help);
183 }
184 void gethelp() {
185 if (help) printf("%s\n", help);
186 else printf("No help available\n");
187 }
188
189 const char *getname() const { return name; }
190};
191
192static char line[256];
193static char saveline[256];
194static int margc;
195static const char *margv[20];
196
197static void makeargv(void) {
198 register char *cp, *cp2, c;
199 register const char **argp = margv;
200
201 margc = 0;
202 cp = line;
203 if (*cp == '!') { /* Special case shell escape */
204 strcpy(saveline, line); /* save for shell command */
205 *argp++ = "!"; /* No room in string to get this */
206 margc++;
207 cp++;
208 }
209 while ((c = *cp)!=0) {
210 register int inquote = 0;
211 while (isspace(c))
212 c = *++cp;
213 if (c == '\0')
214 break;
215 *argp++ = cp;
216 margc += 1;
217 for (cp2 = cp; c != '\0'; c = *++cp) {
218 if (inquote) {
219 if (c == inquote) {
220 inquote = 0;
221 continue;
222 }
223 } else {
224 if (c == '\\') {
225 if ((c = *++cp) == '\0')
226 break;
227 } else if (c == '"') {
228 inquote = '"';
229 continue;
230 } else if (c == '\'') {
231 inquote = '\'';
232 continue;
233 } else if (isspace(c))
234 break;
235 }
236 *cp2++ = c;
237 }
238 *cp2 = '\0';
239 if (c == '\0')
240 break;
241 cp++;
242 }
243 *argp++ = 0;
244}
245
246/*
247 * Make a character string into a number.
248 *
249 * Todo: 1. Could take random integers (12, 0x12, 012, 0b1).
250 */
251
252static int special(const char *s) {
253 char c;
254 char b;
255
256 switch (*s) {
257 case '^':
258 b = *++s;
259 if (b == '?') {
260 c = b | 0x40; /* DEL */
261 }
262 else {
263 c = b & 0x1f;
264 }
265 break;
266 default:
267 c = *s;
268 break;
269 }
270 return c;
271}
272
273/*
274 * Construct a control character sequence
275 * for a special character.
276 */
277static const char *control(cc_t c)
278{
279 static char buf[5];
280 /*
281 * The only way I could get the Sun 3.5 compiler
282 * to shut up about
283 * if ((unsigned int)c >= 0x80)
284 * was to assign "c" to an unsigned int variable...
285 * Arggg....
286 */
287 register unsigned int uic = (unsigned int)c;
288
289 if (uic == 0x7f)
290 return ("^?");
291 if (c == (cc_t)_POSIX_VDISABLE) {
292 return "off";
293 }
294 if (uic >= 0x80) {
295 buf[0] = '\\';
296 buf[1] = ((c>>6)&07) + '0';
297 buf[2] = ((c>>3)&07) + '0';
298 buf[3] = (c&07) + '0';
299 buf[4] = 0;
300 } else if (uic >= 0x20) {
301 buf[0] = c;
302 buf[1] = 0;
303 } else {
304 buf[0] = '^';
305 buf[1] = '@'+c;
306 buf[2] = 0;
307 }
308 return (buf);
309}
310
311
312
313/*
314 * The following are data structures and routines for
315 * the "send" command.
316 *
317 */
318
319struct sendlist {
320 const char *name; /* How user refers to it (case independent) */
321 const char *help; /* Help information (0 ==> no help) */
322 int needconnect; /* Need to be connected */
323 int narg; /* Number of arguments */
324 int (*handler)(const char *, const char *);
325 /* Routine to perform (for special ops) */
326 int nbyte; /* Number of bytes to send this command */
327 int what; /* Character to be sent (<0 ==> special) */
328};
329
330static int send_esc(const char *, const char *);
331static int send_help(const char *, const char *);
332static int send_docmd(const char *, const char *);
333static int send_dontcmd(const char *, const char *);
334static int send_willcmd(const char *, const char *);
335static int send_wontcmd(const char *, const char *);
336
337extern int send_do(int, int);
338extern int send_dont(int, int);
339extern int send_will(int, int);
340extern int send_wont(int, int);
341
342static int dosynch1(const char *, const char *) { return dosynch(); }
343
344static struct sendlist Sendlist[] = {
345 { "ao", "Send Telnet Abort output", 1, 0, 0, 2, AO },
346 { "ayt", "Send Telnet 'Are You There'", 1, 0, 0, 2, AYT },
347 { "brk", "Send Telnet Break", 1, 0, 0, 2, BREAK },
348 { "break", 0, 1, 0, 0, 2, BREAK },
349 { "ec", "Send Telnet Erase Character", 1, 0, 0, 2, EC },
350 { "el", "Send Telnet Erase Line", 1, 0, 0, 2, EL },
351 { "escape", "Send current escape character", 1, 0, send_esc, 1, 0 },
352 { "ga", "Send Telnet 'Go Ahead' sequence", 1, 0, 0, 2, GA },
353 { "ip", "Send Telnet Interrupt Process", 1, 0, 0, 2, IP },
354 { "intp", 0, 1, 0, 0, 2, IP },
355 { "interrupt", 0, 1, 0, 0, 2, IP },
356 { "intr", 0, 1, 0, 0, 2, IP },
357 { "nop", "Send Telnet 'No operation'", 1, 0, 0, 2, NOP },
358 { "eor", "Send Telnet 'End of Record'", 1, 0, 0, 2, EOR },
359 { "abort", "Send Telnet 'Abort Process'", 1, 0, 0, 2, ABORT },
360 { "susp", "Send Telnet 'Suspend Process'", 1, 0, 0, 2, SUSP },
361 { "eof", "Send Telnet End of File Character", 1, 0, 0, 2, xEOF },
362 { "synch", "Perform Telnet 'Synch operation'", 1, 0, dosynch1, 2, 0 },
363 { "getstatus", "Send request for STATUS", 1, 0, get_status, 6, 0 },
364 { "?", "Display send options", 0, 0, send_help, 0, 0 },
365 { "help", 0, 0, 0, send_help, 0, 0 },
366 { "do", 0, 0, 1, send_docmd, 3, 0 },
367 { "dont", 0, 0, 1, send_dontcmd, 3, 0 },
368 { "will", 0, 0, 1, send_willcmd, 3, 0 },
369 { "wont", 0, 0, 1, send_wontcmd, 3, 0 },
370 { 0, 0, 0, 0, 0, 0, 0 }
371};
372
373#define GETSEND(name) ((struct sendlist *) genget(name, (char **) Sendlist, \
374 sizeof(struct sendlist)))
375
376static int sendcmd(int argc, const char *argv[]) {
377 int count; /* how many bytes we are going to need to send */
378 int i;
379/* int question = 0;*/ /* was at least one argument a question */
380 struct sendlist *s; /* pointer to current command */
381 int success = 0;
382 int needconnect = 0;
383
384 if (argc < 2) {
385 printf("need at least one argument for 'send' command\n");
386 printf("'send ?' for help\n");
387 return 0;
388 }
389 /*
390 * First, validate all the send arguments.
391 * In addition, we see how much space we are going to need, and
392 * whether or not we will be doing a "SYNCH" operation (which
393 * flushes the network queue).
394 */
395 count = 0;
396 for (i = 1; i < argc; i++) {
397 s = GETSEND(argv[i]);
398 if (s == 0) {
399 printf("Unknown send argument '%s'\n'send ?' for help.\n",
400 argv[i]);
401 return 0;
402 }
403 else if (s == AMBIGUOUS) {
404 printf("Ambiguous send argument '%s'\n'send ?' for help.\n",
405 argv[i]);
406 return 0;
407 }
408 if (i + s->narg >= argc) {
409 fprintf(stderr,
410 "Need %d argument%s to 'send %s' command. 'send %s ?' for help.\n",
411 s->narg, s->narg == 1 ? "" : "s", s->name, s->name);
412 return 0;
413 }
414 count += s->nbyte;
415 if (s->handler == send_help) {
416 send_help(NULL, NULL);
417 return 0;
418 }
419
420 i += s->narg;
421 needconnect += s->needconnect;
422 }
423 if (!connected && needconnect) {
424 printf("?Need to be connected first.\n");
425 printf("'send ?' for help\n");
426 return 0;
427 }
428 /* Now, do we have enough room? */
429 if (netoring.empty_count() < count) {
430 printf("There is not enough room in the buffer TO the network\n");
431 printf("to process your request. Nothing will be done.\n");
432 printf("('send synch' will throw away most data in the network\n");
433 printf("buffer, if this might help.)\n");
434 return 0;
435 }
436 /* OK, they are all OK, now go through again and actually send */
437 count = 0;
438 for (i = 1; i < argc; i++) {
439 if ((s = GETSEND(argv[i])) == 0) {
440 fprintf(stderr, "Telnet 'send' error - argument disappeared!\n");
441 quit();
442 /*NOTREACHED*/
443 }
444 if (s->handler) {
445 count++;
446 success += (*s->handler)((s->narg > 0) ? argv[i+1] : 0,
447 (s->narg > 1) ? argv[i+2] : 0);
448 i += s->narg;
449 }
450 else {
451 NET2ADD(IAC, s->what);
452 printoption("SENT", IAC, s->what);
453 }
454 }
455 return (count == success);
456}
457
458static int send_esc(const char *, const char *) {
459 NETADD(escapechar);
460 return 1;
461}
462
463static int send_docmd(const char *name, const char *) {
464 return send_tncmd(send_do, "do", name);
465}
466
467static int send_dontcmd(const char *name, const char *) {
468 return(send_tncmd(send_dont, "dont", name));
469}
470
471static int send_willcmd(const char *name, const char *) {
472 return(send_tncmd(send_will, "will", name));
473}
474
475static int send_wontcmd(const char *name, const char *) {
476 return(send_tncmd(send_wont, "wont", name));
477}
478
479int send_tncmd(int (*func)(int, int), const char *cmd, const char *name) {
480 char **cpp;
481 extern char *telopts[];
482
483 if (isprefix(name, "help") || isprefix(name, "?")) {
484 register int col, len;
485
486 printf("Usage: send %s <option>\n", cmd);
487 printf("Valid options are:\n\t");
488
489 col = 8;
490 for (cpp = telopts; *cpp; cpp++) {
491 len = strlen(*cpp) + 1;
492 if (col + len > 65) {
493 printf("\n\t");
494 col = 8;
495 }
496 printf(" %s", *cpp);
497 col += len;
498 }
499 printf("\n");
500 return 0;
501 }
502 cpp = genget(name, telopts, sizeof(char *));
503 if (cpp == AMBIGUOUS) {
504 fprintf(stderr,"'%s': ambiguous argument ('send %s ?' for help).\n",
505 name, cmd);
506 return 0;
507 }
508 if (cpp == 0) {
509 fprintf(stderr, "'%s': unknown argument ('send %s ?' for help).\n",
510 name, cmd);
511 return 0;
512 }
513 if (!connected) {
514 printf("?Need to be connected first.\n");
515 return 0;
516 }
517 (*func)(cpp - telopts, 1);
518 return 1;
519}
520
521static int send_help(const char *, const char *) {
522 struct sendlist *s; /* pointer to current command */
523 for (s = Sendlist; s->name; s++) {
524 if (s->help)
525 printf("%-15s %s\n", s->name, s->help);
526 }
527 return(0);
528}
529
530/*
531 * The following are the routines and data structures referred
532 * to by the arguments to the "toggle" command.
533 */
534
535static int lclchars(int) {
536 donelclchars = 1;
537 return 1;
538}
539
540static int togdebug(int) {
541 return nlink.setdebug(debug);
542}
543
544
545static int togcrlf(int) {
546 if (crlf) {
547 printf("Will send carriage returns as telnet <CR><LF>.\n");
548 }
549 else {
550 printf("Will send carriage returns as telnet <CR><NUL>.\n");
551 }
552 return 1;
553}
554
555int binmode;
556
557static int togbinary(int val) {
558 donebinarytoggle = 1;
559
560 if (val >= 0) {
561 binmode = val;
562 } else {
563 if (my_want_state_is_will(TELOPT_BINARY) &&
564 my_want_state_is_do(TELOPT_BINARY)) {
565 binmode = 1;
566 } else if (my_want_state_is_wont(TELOPT_BINARY) &&
567 my_want_state_is_dont(TELOPT_BINARY)) {
568 binmode = 0;
569 }
570 val = binmode ? 0 : 1;
571 }
572
573 if (val == 1) {
574 if (my_want_state_is_will(TELOPT_BINARY) &&
575 my_want_state_is_do(TELOPT_BINARY)) {
576 printf("Already operating in binary mode with remote host.\n");
577 } else {
578 printf("Negotiating binary mode with remote host.\n");
579 tel_enter_binary(3);
580 }
581 } else {
582 if (my_want_state_is_wont(TELOPT_BINARY) &&
583 my_want_state_is_dont(TELOPT_BINARY)) {
584 printf("Already in network ascii mode with remote host.\n");
585 } else {
586 printf("Negotiating network ascii mode with remote host.\n");
587 tel_leave_binary(3);
588 }
589 }
590 return 1;
591}
592
593static int togrbinary(int val) {
594 donebinarytoggle = 1;
595
596 if (val == -1)
597 val = my_want_state_is_do(TELOPT_BINARY) ? 0 : 1;
598
599 if (val == 1) {
600 if (my_want_state_is_do(TELOPT_BINARY)) {
601 printf("Already receiving in binary mode.\n");
602 }
603 else {
604 printf("Negotiating binary mode on input.\n");
605 tel_enter_binary(1);
606 }
607 }
608 else {
609 if (my_want_state_is_dont(TELOPT_BINARY)) {
610 printf("Already receiving in network ascii mode.\n");
611 } else {
612 printf("Negotiating network ascii mode on input.\n");
613 tel_leave_binary(1);
614 }
615 }
616 return 1;
617}
618
619static int togxbinary(int val) {
620 donebinarytoggle = 1;
621
622 if (val == -1)
623 val = my_want_state_is_will(TELOPT_BINARY) ? 0 : 1;
624
625 if (val == 1) {
626 if (my_want_state_is_will(TELOPT_BINARY)) {
627 printf("Already transmitting in binary mode.\n");
628 }
629 else {
630 printf("Negotiating binary mode on output.\n");
631 tel_enter_binary(2);
632 }
633 }
634 else {
635 if (my_want_state_is_wont(TELOPT_BINARY)) {
636 printf("Already transmitting in network ascii mode.\n");
637 }
638 else {
639 printf("Negotiating network ascii mode on output.\n");
640 tel_leave_binary(2);
641 }
642 }
643 return 1;
644}
645
646
647static int netdata; /* Print out network data flow */
648static int prettydump; /* Print "netdata" output in user readable format */
649static int termdata; /* Print out terminal data flow */
650
651static int togglehelp(int);
652
653struct togglelist {
654 const char *name; /* name of toggle */
655 const char *help; /* help message */
656 int (*handler)(int); /* routine to do actual setting */
657 int *variable;
658 const char *actionexplanation;
659};
660
661static struct togglelist Togglelist[] = {
662 { "autoflush", "flushing of output when sending interrupt characters",
663 NULL, &autoflush,
664 "flush output when sending interrupt characters" },
665
666 { "autosynch", "automatic sending of interrupt characters in urgent mode",
667 NULL, &autosynch,
668 "send interrupt characters in urgent mode" },
669
670#if 0
671 { "autologin", "automatic sending of login and/or authentication info",
672 NULL, &autologin,
673 "send login name and/or authentication information" },
674 { "authdebug", "Toggle authentication debugging",
675 auth_togdebug, NULL,
676 "print authentication debugging information" },
677 { "autoencrypt", "automatic encryption of data stream",
678 EncryptAutoEnc, NULL,
679 "automatically encrypt output" },
680 { "autodecrypt", "automatic decryption of data stream",
681 EncryptAutoDec, NULL,
682 "automatically decrypt input" },
683 { "verbose_encrypt", "Toggle verbose encryption output",
684 EncryptVerbose, NULL,
685 "print verbose encryption output" },
686 { "encdebug", "Toggle encryption debugging",
687 EncryptDebug, NULL,
688 "print encryption debugging information" },
689#endif
690
691 { "skiprc", "don't read ~/.telnetrc file",
692 NULL, &skiprc,
693 "read ~/.telnetrc file" },
694 { "binary",
695 "sending and receiving of binary data",
696 togbinary, NULL,
697 NULL },
698 { "inbinary", "receiving of binary data",
699 togrbinary, NULL,
700 NULL },
701 { "outbinary", "sending of binary data",
702 togxbinary, 0,
703 NULL },
704 { "crlf", "sending carriage returns as telnet <CR><LF>",
705 togcrlf, &crlf,
706 NULL },
707 { "crmod", "mapping of received carriage returns",
708 NULL, &crmod,
709 "map carriage return on output" },
710 { "localchars", "local recognition of certain control characters",
711 lclchars, &localchars,
712 "recognize certain control characters" },
713
714 { " ", "", 0, 0, 0 }, /* empty line */
715
716#if defined(TN3270) && !defined(__linux__)
717 { "apitrace", "(debugging) toggle tracing of API transactions",
718 NULL, &apitrace,
719 "trace API transactions" },
720 { "cursesdata", "(debugging) toggle printing of hexadecimal curses data",
721 NULL, &cursesdata,
722 "print hexadecimal representation of curses data" },
723#endif /* TN3270 and not linux */
724
725 { "debug", "debugging",
726 togdebug, &debug,
727 "turn on socket level debugging" },
728 { "netdata", "printing of hexadecimal network data (debugging)",
729 NULL, &netdata,
730 "print hexadecimal representation of network traffic" },
731 { "prettydump","output of \"netdata\" to user readable format (debugging)",
732 NULL, &prettydump,
733 "print user readable output for \"netdata\"" },
734 { "options", "viewing of options processing (debugging)",
735 NULL, &showoptions,
736 "show option processing" },
737
738 { "termdata", "(debugging) toggle printing of hexadecimal terminal data",
739 NULL, &termdata,
740 "print hexadecimal representation of terminal traffic" },
741
742 { "?", NULL, togglehelp, 0, 0 },
743 { "help", NULL, togglehelp, 0, 0 },
744 { 0, 0, 0, 0, 0 }
745};
746
747static int togglehelp(int) {
748 struct togglelist *c;
749
750 for (c = Togglelist; c->name; c++) {
751 if (c->help) {
752 if (*c->help)
753 printf("%-15s toggle %s\n", c->name, c->help);
754 else
755 printf("\n");
756 }
757 }
758 printf("\n");
759 printf("%-15s %s\n", "?", "display help information");
760 return 0;
761}
762
763static void settogglehelp(int set) {
764 struct togglelist *c;
765
766 for (c = Togglelist; c->name; c++) {
767 if (c->help) {
768 if (*c->help)
769 printf("%-15s %s %s\n", c->name, set ? "enable" : "disable",
770 c->help);
771 else
772 printf("\n");
773 }
774 }
775}
776
777#define GETTOGGLE(name) (struct togglelist *) \
778 genget(name, (char **) Togglelist, sizeof(struct togglelist))
779
780static int toggle(int argc, const char *argv[]) {
781 int retval = 1;
782 const char *name;
783 struct togglelist *c;
784
785 if (argc < 2) {
786 fprintf(stderr,
787 "Need an argument to 'toggle' command. 'toggle ?' for help.\n");
788 return 0;
789 }
790 argc--;
791 argv++;
792 while (argc--) {
793 name = *argv++;
794 c = GETTOGGLE(name);
795 if (c == AMBIGUOUS) {
796 fprintf(stderr, "'%s': ambiguous argument ('toggle ?' for help).\n",
797 name);
798 return 0;
799 }
800 else if (c == 0) {
801 fprintf(stderr, "'%s': unknown argument ('toggle ?' for help).\n",
802 name);
803 return 0;
804 }
805 else {
806 if (c->variable) {
807 *c->variable = !*c->variable; /* invert it */
808 if (c->actionexplanation) {
809 printf("%s %s.\n", *c->variable? "Will" : "Won't",
810 c->actionexplanation);
811 }
812 }
813 if (c->handler) {
814 retval &= (*c->handler)(-1);
815 }
816 }
817 }
818 return retval;
819}
820
821/*
822 * The following perform the "set" command.
823 */
824
825struct setlist {
826 const char *name; /* name */
827 const char *help; /* help information */
828 void (*handler)(const char *);
829 cc_t *charp; /* where it is located at */
830};
831
832static struct setlist Setlist[] = {
833#ifdef KLUDGELINEMODE
834 { "echo", "character to toggle local echoing on/off", 0, &echoc },
835#endif
836 { "escape", "character to escape back to telnet command mode", 0, &escapechar },
837 { "rlogin", "rlogin escape character", 0, &rlogin },
838 { "tracefile", "file to write trace information to", SetNetTrace, (cc_t *)NetTraceFile},
839 { " ", "", 0, 0 },
840 { " ", "The following need 'localchars' to be toggled true", 0, 0 },
841 { "flushoutput", "character to cause an Abort Output", 0, termFlushCharp },
842 { "interrupt", "character to cause an Interrupt Process", 0, termIntCharp },
843 { "quit", "character to cause an Abort process", 0, termQuitCharp },
844 { "eof", "character to cause an EOF ", 0, termEofCharp },
845 { " ", "", 0, 0 },
846 { " ", "The following are for local editing in linemode", 0, 0 },
847 { "erase", "character to use to erase a character", 0, termEraseCharp },
848 { "kill", "character to use to erase a line", 0, termKillCharp },
849 { "lnext", "character to use for literal next", 0, termLiteralNextCharp },
850 { "susp", "character to cause a Suspend Process", 0, termSuspCharp },
851 { "reprint", "character to use for line reprint", 0, termRprntCharp },
852 { "worderase", "character to use to erase a word", 0, termWerasCharp },
853 { "start", "character to use for XON", 0, termStartCharp },
854 { "stop", "character to use for XOFF", 0, termStopCharp },
855 { "forw1", "alternate end of line character", 0, termForw1Charp },
856 { "forw2", "alternate end of line character", 0, termForw2Charp },
857 { "ayt", "alternate AYT character", 0, termAytCharp },
858 { 0, 0, 0, 0 }
859};
860
861#if defined(CRAY) && !defined(__STDC__)
862/* Work around compiler bug in pcc 4.1.5 */
863 void
864_setlist_init()
865{
866#ifndef KLUDGELINEMODE
867#define N 5
868#else
869#define N 6
870#endif
871 Setlist[N+0].charp = &termFlushChar;
872 Setlist[N+1].charp = &termIntChar;
873 Setlist[N+2].charp = &termQuitChar;
874 Setlist[N+3].charp = &termEofChar;
875 Setlist[N+6].charp = &termEraseChar;
876 Setlist[N+7].charp = &termKillChar;
877 Setlist[N+8].charp = &termLiteralNextChar;
878 Setlist[N+9].charp = &termSuspChar;
879 Setlist[N+10].charp = &termRprntChar;
880 Setlist[N+11].charp = &termWerasChar;
881 Setlist[N+12].charp = &termStartChar;
882 Setlist[N+13].charp = &termStopChar;
883 Setlist[N+14].charp = &termForw1Char;
884 Setlist[N+15].charp = &termForw2Char;
885 Setlist[N+16].charp = &termAytChar;
886#undef N
887}
888#endif /* defined(CRAY) && !defined(__STDC__) */
889
890static struct setlist *
891getset(const char *name)
892{
893 return (struct setlist *)
894 genget(name, (char **) Setlist, sizeof(struct setlist));
895}
896
897void set_escape_char(char *s) {
898 if (rlogin != _POSIX_VDISABLE) {
899 rlogin = (s && *s) ? special(s) : _POSIX_VDISABLE;
900 printf("Telnet rlogin escape character is '%s'.\n",
901 control(rlogin));
902 }
903 else {
904 escapechar = (s && *s) ? special(s) : _POSIX_VDISABLE;
905 printf("Telnet escape character is '%s'.\n", control(escapechar));
906 }
907}
908
909static int setcmd(int argc, const char *argv[]) {
910 int value;
911 struct setlist *ct;
912 struct togglelist *c;
913
914 if (argc < 2 || argc > 3) {
915 printf("Format is 'set Name Value'\n'set ?' for help.\n");
916 return 0;
917 }
918 if ((argc == 2) && (isprefix(argv[1], "?") || isprefix(argv[1], "help"))) {
919 for (ct = Setlist; ct->name; ct++)
920 printf("%-15s %s\n", ct->name, ct->help);
921 printf("\n");
922 settogglehelp(1);
923 printf("%-15s %s\n", "?", "display help information");
924 return 0;
925 }
926
927 ct = getset(argv[1]);
928 if (ct == 0) {
929 c = GETTOGGLE(argv[1]);
930 if (c == 0) {
931 fprintf(stderr, "'%s': unknown argument ('set ?' for help).\n",
932 argv[1]);
933 return 0;
934 }
935 else if (c == AMBIGUOUS) {
936 fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",
937 argv[1]);
938 return 0;
939 }
940 if (c->variable) {
941 if ((argc == 2) || (strcmp("on", argv[2]) == 0))
942 *c->variable = 1;
943 else if (strcmp("off", argv[2]) == 0)
944 *c->variable = 0;
945 else {
946 printf("Format is 'set togglename [on|off]'\n'set ?' for help.\n");
947 return 0;
948 }
949 if (c->actionexplanation) {
950 printf("%s %s.\n", *c->variable? "Will" : "Won't",
951 c->actionexplanation);
952 }
953 }
954 if (c->handler)
955 (*c->handler)(1);
956 }
957 else if (argc != 3) {
958 printf("Format is 'set Name Value'\n'set ?' for help.\n");
959 return 0;
960 }
961 else if (ct == AMBIGUOUS) {
962 fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",
963 argv[1]);
964 return 0;
965 }
966 else if (ct->handler) {
967 (*ct->handler)(argv[2]);
968 printf("%s set to \"%s\".\n", ct->name, (char *)ct->charp);
969 }
970 else {
971 if (strcmp("off", argv[2])) {
972 value = special(argv[2]);
973 } else {
974 value = _POSIX_VDISABLE;
975 }
976 *(ct->charp) = (cc_t)value;
977 printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
978 }
979 slc_check();
980 return 1;
981}
982
983static int unsetcmd(int argc, const char *argv[]) {
984 struct setlist *ct;
985 struct togglelist *c;
986 const char *name;
987
988 if (argc < 2) {
989 fprintf(stderr,
990 "Need an argument to 'unset' command. 'unset ?' for help.\n");
991 return 0;
992 }
993 if (isprefix(argv[1], "?") || isprefix(argv[1], "help")) {
994 for (ct = Setlist; ct->name; ct++)
995 printf("%-15s %s\n", ct->name, ct->help);
996 printf("\n");
997 settogglehelp(0);
998 printf("%-15s %s\n", "?", "display help information");
999 return 0;
1000 }
1001
1002 argc--;
1003 argv++;
1004 while (argc--) {
1005 name = *argv++;
1006 ct = getset(name);
1007 if (ct == 0) {
1008 c = GETTOGGLE(name);
1009 if (c == 0) {
1010 fprintf(stderr, "'%s': unknown argument ('unset ?' for help).\n",
1011 name);
1012 return 0;
1013 }
1014 else if (c == AMBIGUOUS) {
1015 fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",
1016 name);
1017 return 0;
1018 }
1019 if (c->variable) {
1020 *c->variable = 0;
1021 if (c->actionexplanation) {
1022 printf("%s %s.\n", *c->variable? "Will" : "Won't",
1023 c->actionexplanation);
1024 }
1025 }
1026 if (c->handler)
1027 (*c->handler)(0);
1028 }
1029 else if (ct == AMBIGUOUS) {
1030 fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",
1031 name);
1032 return 0;
1033 }
1034 else if (ct->handler) {
1035 (*ct->handler)(0);
1036 printf("%s reset to \"%s\".\n", ct->name, (char *)ct->charp);
1037 }
1038 else {
1039 *(ct->charp) = _POSIX_VDISABLE;
1040 printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
1041 }
1042 }
1043 return 1;
1044}
1045
1046/*
1047 * The following are the data structures and routines for the
1048 * 'mode' command.
1049 */
1050#ifdef KLUDGELINEMODE
1051extern int kludgelinemode;
1052
1053static int dokludgemode(int) {
1054 kludgelinemode = 1;
1055 send_wont(TELOPT_LINEMODE, 1);
1056 send_dont(TELOPT_SGA, 1);
1057 send_dont(TELOPT_ECHO, 1);
1058 return 0;
1059}
1060#endif
1061
1062static int dolinemode(int) {
1063#ifdef KLUDGELINEMODE
1064 if (kludgelinemode)
1065 send_dont(TELOPT_SGA, 1);
1066#endif
1067 send_will(TELOPT_LINEMODE, 1);
1068 send_dont(TELOPT_ECHO, 1);
1069 return 1;
1070}
1071
1072static int docharmode(int) {
1073#ifdef KLUDGELINEMODE
1074 if (kludgelinemode)
1075 send_do(TELOPT_SGA, 1);
1076 else
1077#endif
1078 send_wont(TELOPT_LINEMODE, 1);
1079 send_do(TELOPT_ECHO, 1);
1080 return 1;
1081}
1082
1083static int dolmmode(int bit, int on) {
1084 unsigned char c;
1085 extern int linemode;
1086
1087 if (my_want_state_is_wont(TELOPT_LINEMODE)) {
1088 printf("?Need to have LINEMODE option enabled first.\n");
1089 printf("'mode ?' for help.\n");
1090 return 0;
1091 }
1092
1093 if (on)
1094 c = (linemode | bit);
1095 else
1096 c = (linemode & ~bit);
1097 lm_mode(&c, 1, 1);
1098 return 1;
1099}
1100
1101int setmode(int bit) {
1102 return dolmmode(bit, 1);
1103}
1104
1105int clearmode(int bit) {
1106 return dolmmode(bit, 0);
1107}
1108
1109struct modelist {
1110 const char *name; /* command name */
1111 const char *help; /* help string */
1112 int (*handler)(int); /* routine which executes command */
1113 int needconnect; /* Do we need to be connected to execute? */
1114 int arg1;
1115};
1116
1117extern int modehelp(int);
1118
1119static struct modelist ModeList[] = {
1120 { "character", "Disable LINEMODE option", docharmode, 1,0},
1121#ifdef KLUDGELINEMODE
1122 { "", "(or disable obsolete line-by-line mode)", NULL, 0,0 },
1123#endif
1124 { "line", "Enable LINEMODE option", dolinemode, 1,0},
1125#ifdef KLUDGELINEMODE
1126 { "", "(or enable obsolete line-by-line mode)", NULL, 0,0 },
1127#endif
1128 { "", "", NULL, 0, 0 },
1129 { "", "These require the LINEMODE option to be enabled", NULL, 0, 0},
1130 { "isig", "Enable signal trapping", setmode, 1, MODE_TRAPSIG },
1131 { "+isig", 0, setmode, 1, MODE_TRAPSIG },
1132 { "-isig", "Disable signal trapping", clearmode, 1, MODE_TRAPSIG },
1133 { "edit", "Enable character editing", setmode, 1, MODE_EDIT },
1134 { "+edit", 0, setmode, 1, MODE_EDIT },
1135 { "-edit", "Disable character editing", clearmode, 1, MODE_EDIT },
1136 { "softtabs", "Enable tab expansion", setmode, 1, MODE_SOFT_TAB },
1137 { "+softtabs", 0, setmode, 1, MODE_SOFT_TAB },
1138 { "-softtabs", "Disable character editing", clearmode, 1, MODE_SOFT_TAB },
1139 { "litecho", "Enable literal character echo", setmode, 1, MODE_LIT_ECHO },
1140 { "+litecho", 0, setmode, 1, MODE_LIT_ECHO },
1141 { "-litecho", "Disable literal character echo", clearmode, 1, MODE_LIT_ECHO },
1142 { "help", 0, modehelp, 0, 0 },
1143#ifdef KLUDGELINEMODE
1144 { "kludgeline", 0, dokludgemode, 1, 0 },
1145#endif
1146 { "", "", 0, 0, 0 },
1147 { "?", "Print help information", modehelp, 0, 0 },
1148 { 0, 0, 0, 0, 0 },
1149};
1150
1151
1152int modehelp(int) {
1153 struct modelist *mt;
1154
1155 printf("format is: 'mode Mode', where 'Mode' is one of:\n\n");
1156 for (mt = ModeList; mt->name; mt++) {
1157 if (mt->help) {
1158 if (*mt->help)
1159 printf("%-15s %s\n", mt->name, mt->help);
1160 else
1161 printf("\n");
1162 }
1163 }
1164 return 0;
1165}
1166
1167#define GETMODECMD(name) (struct modelist *) \
1168 genget(name, (char **) ModeList, sizeof(struct modelist))
1169
1170static int modecmd(const char *arg) {
1171 struct modelist *mt;
1172
1173 mt = GETMODECMD(arg);
1174 if (mt == 0) {
1175 fprintf(stderr, "Unknown mode '%s' ('mode ?' for help).\n", arg);
1176 }
1177 else if (mt == AMBIGUOUS) {
1178 fprintf(stderr, "Ambiguous mode '%s' ('mode ?' for help).\n", arg);
1179 }
1180 else if (mt->needconnect && !connected) {
1181 printf("?Need to be connected first.\n");
1182 printf("'mode ?' for help.\n");
1183 }
1184 else if (mt->handler) {
1185 return (*mt->handler)(mt->arg1);
1186 }
1187 return 0;
1188}
1189
1190/*
1191 * The following data structures and routines implement the
1192 * "display" command.
1193 */
1194
1195static void dotog(struct togglelist *tl) {
1196 if (tl->variable && tl->actionexplanation) {
1197 if (*tl->variable) {
1198 printf("will");
1199 }
1200 else {
1201 printf("won't");
1202 }
1203 printf(" %s.\n", tl->actionexplanation);
1204 }
1205}
1206
1207static void doset(struct setlist *sl) {
1208 if (sl->name && *sl->name != ' ') {
1209 if (sl->handler == 0) {
1210 printf("%-15s [%s]\n", sl->name, control(*sl->charp));
1211 }
1212 else {
1213 printf("%-15s \"%s\"\n", sl->name, (char *)sl->charp);
1214 }
1215 }
1216}
1217
1218static int display(int argc, const char *argv[]) {
1219 struct togglelist *tl;
1220 struct setlist *sl;
1221
1222 if (argc == 1) {
1223 for (tl = Togglelist; tl->name; tl++) {
1224 dotog(tl);
1225 }
1226 printf("\n");
1227 for (sl = Setlist; sl->name; sl++) {
1228 doset(sl);
1229 }
1230 }
1231 else {
1232 int i;
1233
1234 for (i = 1; i < argc; i++) {
1235 sl = getset(argv[i]);
1236 tl = GETTOGGLE(argv[i]);
1237 if (sl == AMBIGUOUS || tl == AMBIGUOUS) {
1238 printf("?Ambiguous argument '%s'.\n", argv[i]);
1239 return 0;
1240 }
1241 else if (!sl && !tl) {
1242 printf("?Unknown argument '%s'.\n", argv[i]);
1243 return 0;
1244 }
1245 else {
1246 if (tl) {
1247 dotog(tl);
1248 }
1249 if (sl) {
1250 doset(sl);
1251 }
1252 }
1253 }
1254 }
1255 optionstatus();
1256 return 1;
1257}
1258
1259/*
1260 * The following are the data structures, and many of the routines,
1261 * relating to command processing.
1262 */
1263
1264/*
1265 * Set the escape character.
1266 */
1267static int setescape(int argc, const char *argv[]) {
1268 const char *arg;
1269 char buf[50];
1270
1271 printf(
1272 "Deprecated usage - please use 'set escape%s%s' in the future.\n",
1273 (argc > 2)? " ":"", (argc > 2)? argv[1]: "");
1274 if (argc > 2) {
1275 arg = argv[1];
1276 }
1277 else {
1278 printf("new escape character: ");
1279 (void) fgets(buf, sizeof(buf), stdin);
1280 arg = buf;
1281 }
1282 if (arg[0] != '\0')
1283 escapechar = arg[0];
1284 if (!In3270) {
1285 printf("Escape character is '%s'.\n", control(escapechar));
1286 }
1287 (void) fflush(stdout);
1288 return 1;
1289}
1290
1291static int togcrmod(void) {
1292 crmod = !crmod;
1293 printf("Deprecated usage - please use 'toggle crmod' in the future.\n");
1294 printf("%s map carriage return on output.\n", crmod ? "Will" : "Won't");
1295 fflush(stdout);
1296 return 1;
1297}
1298
1299int suspend(void) {
1300#ifdef SIGTSTP
1301 setcommandmode();
1302 {
1303 long oldrows, oldcols, newrows, newcols, err;
1304
1305 err = TerminalWindowSize(&oldrows, &oldcols);
1306 (void) kill(0, SIGTSTP);
1307 err += TerminalWindowSize(&newrows, &newcols);
1308 if (connected && !err &&
1309 ((oldrows != newrows) || (oldcols != newcols))) {
1310 sendnaws();
1311 }
1312 }
1313 /* reget parameters in case they were changed */
1314 TerminalSaveState();
1315 setconnmode(0);
1316#else
1317 printf("Suspend is not supported. Try the '!' command instead\n");
1318#endif
1319 return 1;
1320}
1321
1322#if !defined(TN3270)
1323int shell(int argc, const char **) {
1324 setcommandmode();
1325 switch(vfork()) {
1326 case -1:
1327 perror("Fork failed\n");
1328 break;
1329
1330 case 0:
1331 {
1332 /*
1333 * Fire up the shell in the child.
1334 */
1335 const char *shellp, *shellname;
1336
1337 shellp = getenv("SHELL");
1338 if (shellp == NULL)
1339 shellp = "/bin/sh";
1340 if ((shellname = rindex(shellp, '/')) == 0)
1341 shellname = shellp;
1342 else
1343 shellname++;
1344 if (argc > 1)
1345 execl(shellp, shellname, "-c", &saveline[1], 0);
1346 else
1347 execl(shellp, shellname, 0);
1348 perror("Execl");
1349 _exit(1);
1350 }
1351 default:
1352 wait(NULL); /* Wait for the shell to complete */
1353 }
1354 return 1;
1355}
1356#endif /* !defined(TN3270) */
1357
1358static int dobye(int isfromquit) {
1359 extern int resettermname;
1360
1361 if (connected) {
1362 nlink.close(1);
1363 printf("Connection closed.\n");
1364 connected = 0;
1365 resettermname = 1;
1366
1367 /* reset options */
1368 tninit();
1369#if defined(TN3270)
1370 SetIn3270(); /* Get out of 3270 mode */
1371#endif /* defined(TN3270) */
1372 }
1373 if (!isfromquit) {
1374 siglongjmp(toplevel, 1);
1375 /* NOTREACHED */
1376 }
1377 return 1; /* Keep lint, etc., happy */
1378}
1379
1380static int bye(void) {
1381 if (!connected) {
1382 printf("Need to be connected first for `bye'.\n");
1383 return 0;
1384 }
1385 return dobye(0);
1386}
1387
1388void quit(void) {
1389 dobye(1);
1390 Exit(0);
1391}
1392
1393int logout(void) {
1394 if (!connected) {
1395 printf("Need to be connected first for `logout'.\n");
1396 return 0;
1397 }
1398 send_do(TELOPT_LOGOUT, 1);
1399 netflush();
1400 return 1;
1401}
1402
1403/*
1404 * The ENVIRON command.
1405 */
1406
1407struct envcmd {
1408 const char *name;
1409 const char *help;
1410 void (*handler)(const char *, const char *);
1411 int narg;
1412};
1413
1414static void env_help(const char *, const char *);
1415
1416typedef void (*envfunc)(const char *, const char *);
1417
1418struct envcmd EnvList[] = {
1419 { "define", "Define an environment variable",
1420 env_define, 2 },
1421 { "undefine", "Undefine an environment variable",
1422 (envfunc) env_undefine, 1 },
1423 { "export", "Mark an environment variable for automatic export",
1424 (envfunc) env_export, 1 },
1425 { "unexport", "Don't mark an environment variable for automatic export",
1426 (envfunc) env_unexport, 1 },
1427 { "send", "Send an environment variable", (envfunc) env_send, 1 },
1428 { "list", "List the current environment variables",
1429 (envfunc) env_list, 0 },
1430 { "help", 0, env_help, 0 },
1431 { "?", "Print help information", env_help, 0 },
1432 { 0, 0, 0, 0 },
1433};
1434
1435static void env_help(const char *, const char *) {
1436 struct envcmd *c;
1437
1438 for (c = EnvList; c->name; c++) {
1439 if (c->help) {
1440 if (*c->help)
1441 printf("%-15s %s\n", c->name, c->help);
1442 else
1443 printf("\n");
1444 }
1445 }
1446}
1447
1448static struct envcmd *getenvcmd(const char *name) {
1449 return (struct envcmd *)
1450 genget(name, (char **) EnvList, sizeof(struct envcmd));
1451}
1452
1453int env_cmd(int argc, const char *argv[]) {
1454 struct envcmd *c;
1455
1456 if (argc < 2) {
1457 fprintf(stderr,
1458 "Need an argument to 'environ' command. 'environ ?' for help.\n");
1459 return 0;
1460 }
1461 c = getenvcmd(argv[1]);
1462 if (c == 0) {
1463 fprintf(stderr, "'%s': unknown argument ('environ ?' for help).\n",
1464 argv[1]);
1465 return 0;
1466 }
1467 if (c == AMBIGUOUS) {
1468 fprintf(stderr, "'%s': ambiguous argument ('environ ?' for help).\n",
1469 argv[1]);
1470 return 0;
1471 }
1472 if (c->narg + 2 != argc) {
1473 fprintf(stderr,
1474 "Need %s%d argument%s to 'environ %s' command. 'environ ?' for help.\n",
1475 c->narg < argc + 2 ? "only " : "",
1476 c->narg, c->narg == 1 ? "" : "s", c->name);
1477 return 0;
1478 }
1479 (*c->handler)(argv[2], argv[3]);
1480 return 1;
1481}
1482
1483
1484/*
1485 * The AUTHENTICATE command.
1486 *
1487 * auth status Display status
1488 * auth disable Disable an authentication type
1489 * auth enable Enable an authentication type
1490 *
1491 * The ENCRYPT command.
1492 *
1493 * encrypt enable Enable encryption
1494 * encrypt disable Disable encryption
1495 * encrypt type foo Set encryption type
1496 * encrypt start Start encryption
1497 * encrypt stop Stop encryption
1498 * encrypt input Start encrypting input stream
1499 * encrypt -input Stop encrypting input stream
1500 * encrypt output Start encrypting output stream
1501 * encrypt -output Stop encrypting output stream
1502 * encrypt status Print status
1503 */
1504
1505
1506#ifdef TN3270
1507char *oflgs[] = { "read-only", "write-only", "read-write" };
1508
1509static void filestuff(int fd) {
1510 int res;
1511
1512#ifdef F_GETOWN
1513 setconnmode(0);
1514 res = fcntl(fd, F_GETOWN, 0);
1515 setcommandmode();
1516
1517 if (res == -1) {
1518 perror("fcntl");
1519 return;
1520 }
1521 printf("\tOwner is %d.\n", res);
1522#endif
1523
1524 setconnmode(0);
1525 res = fcntl(fd, F_GETFL, 0);
1526 setcommandmode();
1527
1528 if (res == -1) {
1529 perror("fcntl");
1530 return;
1531 }
1532 printf("\tFlags are 0x%x: %s\n", res, oflgs[res]);
1533}
1534#endif /* TN3270 */
1535
1536/*
1537 * Print status about the connection.
1538 */
1539static int dostatus(int notmuch) {
1540 if (connected) {
1541 printf("Connected to %s.\n", hostname);
1542 if (!notmuch) {
1543 int mode = getconnmode();
1544
1545 if (my_want_state_is_will(TELOPT_LINEMODE)) {
1546 printf("Operating with LINEMODE option\n");
1547 printf("%s line editing\n", (mode&MODE_EDIT) ? "Local" : "No");
1548 printf("%s catching of signals\n",
1549 (mode&MODE_TRAPSIG) ? "Local" : "No");
1550 slcstate();
1551#ifdef KLUDGELINEMODE
1552 }
1553 else if (kludgelinemode && my_want_state_is_dont(TELOPT_SGA)) {
1554 printf("Operating in obsolete linemode\n");
1555#endif
1556 }
1557 else {
1558 printf("Operating in single character mode\n");
1559 if (localchars)
1560 printf("Catching signals locally\n");
1561 }
1562 printf("%s character echo\n", (mode&MODE_ECHO) ? "Local" : "Remote");
1563 if (my_want_state_is_will(TELOPT_LFLOW))
1564 printf("%s flow control\n", (mode&MODE_FLOW) ? "Local" : "No");
1565 }
1566 }
1567 else {
1568 printf("No connection.\n");
1569 }
1570#if !defined(TN3270)
1571 printf("Escape character is '%s'.\n", control(escapechar));
1572 (void) fflush(stdout);
1573#else /* !defined(TN3270) */
1574 if ((!In3270) && !notmuch) {
1575 printf("Escape character is '%s'.\n", control(escape));
1576 }
1577 if ((argc >= 2) && !strcmp(argv[1], "everything")) {
1578 printf("SIGIO received %d time%s.\n",
1579 sigiocount, (sigiocount == 1)? "":"s");
1580 if (In3270) {
1581 printf("Process ID %d, process group %d.\n",
1582 getpid(), getpgrp(getpid()));
1583 printf("Terminal input:\n");
1584 filestuff(tin);
1585 printf("Terminal output:\n");
1586 filestuff(tout);
1587 printf("Network socket:\n");
1588 filestuff(net);
1589 }
1590 }
1591 if (In3270 && transcom) {
1592 printf("Transparent mode command is '%s'.\n", transcom);
1593 }
1594 fflush(stdout);
1595 if (In3270) {
1596 return 0;
1597 }
1598#endif /* TN3270 */
1599 return 1;
1600}
1601
1602static int status(void) {
1603 int notmuch = 1;
1604 return dostatus(notmuch);
1605}
1606
1607#ifdef SIGINFO
1608/*
1609 * Function that gets called when SIGINFO is received.
1610 */
1611void ayt_status(int) {
1612 dostatus(1);
1613}
1614#endif
1615
1616int tn(int argc, const char *argv[]) {
1617 register struct hostent *host = 0;
1618 struct sockaddr_in sn;
1619 struct servent *sp = 0;
1620 char *srp = NULL;
1621 int srlen;
1622
1623 const char *cmd, *volatile user = 0;
1624 const char *portp = NULL;
1625 char *hostp = NULL;
1626
1627 /* clear the socket address prior to use */
1628 memset(&sn, 0, sizeof(sn));
1629
1630 if (connected) {
1631 printf("?Already connected to %s\n", hostname);
1632 setuid(getuid());
1633 return 0;
1634 }
1635 if (_hostname) {
1636 delete[] _hostname;
1637 _hostname = 0;
1638 }
1639 if (argc < 2) {
1640 (void) strcpy(line, "open ");
1641 printf("(to) ");
1642 (void) fgets(&line[strlen(line)], sizeof(line) - strlen(line), stdin);
1643 makeargv();
1644 argc = margc;
1645 argv = margv;
1646 }
1647 cmd = *argv;
1648 --argc; ++argv;
1649 while (argc) {
1650 /*
1651 * Having "telnet h" print usage is really stupid...
1652 * suppose your hostname is h?
1653 */
1654 if (/*isprefix(*argv, "help") ||*/ isprefix(*argv, "?"))
1655 goto usage;
1656 if (strcmp(*argv, "-l") == 0) {
1657 --argc; ++argv;
1658 if (argc == 0)
1659 goto usage;
1660 user = *argv++;
1661 --argc;
1662 continue;
1663 }
1664 if (strcmp(*argv, "-a") == 0) {
1665 --argc; ++argv;
1666 autologin = 1;
1667 continue;
1668 }
1669 if (hostp == 0) {
1670 /* this leaks memory - FIXME */
1671 hostp = strdup(*argv++);
1672 --argc;
1673 continue;
1674 }
1675 if (portp == 0) {
1676 portp = *argv++;
1677 --argc;
1678 continue;
1679 }
1680 usage:
1681 printf("usage: %s [-l user] [-a] host-name [port]\n", cmd);
1682 setuid(getuid());
1683 return 0;
1684 }
1685 if (hostp == 0)
1686 goto usage;
1687
1688#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
1689 if (hostp[0] == '@' || hostp[0] == '!') {
1690 if ((hostname = strrchr(hostp, ':')) == NULL)
1691 hostname = strrchr(hostp, '@');
1692 hostname++;
1693 srp = 0;
1694 int temp = sourceroute(hostp, &srp, &srlen);
1695 if (temp == 0) {
1696 herror(srp);
1697 setuid(getuid());
1698 return 0;
1699 } else if (temp == -1) {
1700 printf("Bad source route option: %s\n", hostp);
1701 setuid(getuid());
1702 return 0;
1703 } else {
1704 sn.sin_addr.s_addr = temp;
1705 sn.sin_family = AF_INET;
1706 }
1707 }
1708 else {
1709#endif
1710 if (inet_aton(hostp, &sn.sin_addr)) {
1711 sn.sin_family = AF_INET;
1712 _hostname = new char[strlen(hostp) + 1];
1713 strcpy(_hostname, hostp);
1714 hostname = _hostname;
1715 }
1716 else {
1717 host = gethostbyname(hostp);
1718 if (host) {
1719 sn.sin_family = host->h_addrtype;
1720 if (host->h_length > (int)sizeof(sn.sin_addr)) {
1721 host->h_length = sizeof(sn.sin_addr);
1722 }
1723#if defined(h_addr) /* In 4.3, this is a #define */
1724 memcpy((caddr_t)&sn.sin_addr,
1725 host->h_addr_list[0], host->h_length);
1726#else /* defined(h_addr) */
1727 memcpy((caddr_t)&sn.sin_addr, host->h_addr, host->h_length);
1728#endif /* defined(h_addr) */
1729 _hostname = new char [strlen(host->h_name) + 1];
1730 strcpy(_hostname, host->h_name);
1731 hostname = _hostname;
1732 } else {
1733 herror(hostp);
1734 setuid(getuid());
1735 return 0;
1736 }
1737 }
1738#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
1739 }
1740#endif
1741 if (portp) {
1742 if (*portp == '-') {
1743 portp++;
1744 telnetport = 1;
1745 } else
1746 telnetport = 0;
1747 sn.sin_port = atoi(portp);
1748 if (sn.sin_port == 0) {
1749 sp = getservbyname(portp, "tcp");
1750 if (sp)
1751 sn.sin_port = sp->s_port;
1752 else {
1753 printf("%s: bad port number\n", portp);
1754 setuid(getuid());
1755 return 0;
1756 }
1757 }
1758 else {
1759 sn.sin_port = htons(sn.sin_port);
1760 }
1761 }
1762 else {
1763 if (sp == 0) {
1764 sp = getservbyname("telnet", "tcp");
1765 if (sp == 0) {
1766 fprintf(stderr, "telnet: tcp/telnet: unknown service\n");
1767 setuid(getuid());
1768 return 0;
1769 }
1770 sn.sin_port = sp->s_port;
1771 }
1772 telnetport = 1;
1773 }
1774 printf("Trying %s...\n", inet_ntoa(sn.sin_addr));
1775 do {
1776 int x = nlink.connect(debug, host, &sn, srp, srlen, tos);
1777 if (!x) return 0;
1778 else if (x==1) continue;
1779 connected++;
1780 } while (connected == 0);
1781 cmdrc(hostp, hostname);
1782 if (autologin && user == NULL) {
1783 struct passwd *pw;
1784
1785 user = getenv("USER");
1786 if (user == NULL ||
1787 ((pw = getpwnam(user))!=NULL && pw->pw_uid != getuid())) {
1788 if ((pw = getpwuid(getuid()))!=NULL)
1789 user = pw->pw_name;
1790 else
1791 user = NULL;
1792 }
1793 }
1794 if (user) {
1795 env_define("USER", user);
1796 env_export("USER");
1797 }
1798 dostatus(1);
1799 if (sigsetjmp(peerdied, 1) == 0)
1800 telnet(user);
1801 nlink.close(0);
1802 ExitString("Connection closed by foreign host.\n",1);
1803 /*NOTREACHED*/
1804 return 0;
1805}
1806
1807static char
1808 openhelp[] = "connect to a site",
1809 closehelp[] = "close current connection",
1810 logouthelp[] = "forcibly logout remote user and close the connection",
1811 quithelp[] = "exit telnet",
1812 statushelp[] = "print status information",
1813 sendhelp[] = "transmit special characters ('send ?' for more)",
1814 sethelp[] = "set operating parameters ('set ?' for more)",
1815 unsethelp[] = "unset operating parameters ('unset ?' for more)",
1816 togglestring[] ="toggle operating parameters ('toggle ?' for more)",
1817 displayhelp[] = "display operating parameters",
1818#ifdef TN3270
1819 transcomhelp[] = "specify Unix command for transparent mode pipe",
1820#endif /* TN3270 */
1821 zhelp[] = "suspend telnet",
1822/* shellhelp[] = "invoke a subshell", */
1823 envhelp[] = "change environment variables ('environ ?' for more)",
1824 modestring[] = "try to enter line or character mode ('mode ?' for more)";
1825
1826static char crmodhelp[] = "deprecated command -- use 'toggle crmod' instead";
1827static char escapehelp[] = "deprecated command -- use 'set escape' instead";
1828
1829static int help(command_table *, int, const char **);
1830
1831static int doquit(void) {
1832 quit();
1833 return 0;
1834}
1835
1836static int slc_mode_import_0(void) {
1837 slc_mode_import(0);
1838 return 1;
1839}
1840
1841static int slc_mode_import_1(void) {
1842 slc_mode_import(1);
1843 return 1;
1844}
1845
1846static int do_slc_mode_export(void) {
1847 slc_mode_export();
1848 return 1;
1849}
1850
1851static ptrarray<command_entry> cmdtab;
1852static ptrarray<command_entry> cmdtab2;
1853static ptrarray<command_entry> slctab;
1854
1855#define BIND(a,b,c) cmdtab.add(new command_entry(a,b,c))
1856#define BIND2(a,b,c) cmdtab2.add(new command_entry(a,b,c))
1857#define BINDS(a,b,c) slctab.add(new command_entry(a,b,c))
1858
1859
1860void cmdtab_init(void) {
1861 BIND("close", closehelp, bye);
1862 BIND("logout", logouthelp, logout);
1863 BIND("display", displayhelp, display);
1864 BIND("mode", modestring, modecmd);
1865 BIND("open", openhelp, tn);
1866 BIND("quit", quithelp, doquit);
1867 BIND("send", sendhelp, sendcmd);
1868 BIND("set", sethelp, setcmd);
1869 BIND("unset", unsethelp, unsetcmd);
1870 BIND("status", statushelp, status);
1871 BIND("toggle", togglestring, toggle);
1872 BIND("slc", "set treatment of special characters\n", &slctab);
1873
1874#ifdef TN3270
1875 BIND("transcom", transcomhelp, settranscom);
1876#endif /* TN3270 */
1877
1878 // BIND("auth", authhelp, auth_cmd);
1879 // BIND("encrypt", encrypthelp, encrypt_cmd);
1880
1881 BIND("z", zhelp, suspend);
1882
1883#if defined(TN3270) /* why?! */
1884 BIND("!", shellhelp, shell);
1885#endif
1886
1887 BIND("environ", envhelp, env_cmd);
1888
1889 BINDS("export", "Use local special character definitions",
1890 do_slc_mode_export);
1891 BINDS("import", "Use remote special character definitions",
1892 slc_mode_import_1);
1893 BINDS("check", "Verify remote special character definitions",
1894 slc_mode_import_0);
1895
1896 BIND2("escape", escapehelp, setescape);
1897 BIND2("crmod", crmodhelp, togcrmod);
1898}
1899
1900
1901static command_entry *getcmd(command_table *tab, const char *name) {
1902 if (!strcasecmp(name, "?") ||
1903 !strcasecmp(name, "h") ||
1904 !strcasecmp(name, "help")) return (command_entry *)HELP;
1905
1906 command_entry *found = NULL;
1907
1908 for (int i=0; i<tab->num(); i++) {
1909 command_entry *c = (*tab)[i];
1910 if (!strcasecmp(c->getname(), name)) return c;
1911 if (!strncasecmp(c->getname(), name, strlen(name))) {
1912 if (found) return (command_entry *)AMBIGUOUS;
1913 found = c;
1914 }
1915 }
1916 if (tab==&cmdtab && !found) return getcmd(&cmdtab2, name);
1917
1918 return found;
1919}
1920
1921static int process_command(command_table *tab, int argc, const char **argv) {
1922 command_entry *c;
1923 c = getcmd(tab, argv[0]);
1924 if (c == HELP) {
1925 help(tab, argc, argv);
1926 }
1927 else if (c == AMBIGUOUS) {
1928 printf("?Ambiguous command\n");
1929 }
1930 else if (c == NULL) {
1931 printf("?Invalid command\n");
1932 }
1933 else {
1934 if (c->call(argc, argv)) return 1;
1935 }
1936 return 0;
1937}
1938
1939void command(int top, const char *tbuf, int cnt) {
1940
1941 setcommandmode();
1942 if (!top) {
1943 putchar('\n');
1944 }
1945 else {
1946 signal(SIGINT, SIG_DFL);
1947 signal(SIGQUIT, SIG_DFL);
1948 }
1949 for (;;) {
1950 if (rlogin == _POSIX_VDISABLE)
1951 printf("%s> ", prompt);
1952 if (tbuf) {
1953 char *cp = line;
1954 while (cnt > 0 && (*cp++ = *tbuf++) != '\n')
1955 cnt--;
1956 tbuf = 0;
1957 if (cp == line || *--cp != '\n' || cp == line)
1958 goto getline;
1959 *cp = '\0';
1960 if (rlogin == _POSIX_VDISABLE)
1961 printf("%s\n", line);
1962 }
1963 else {
1964 getline:
1965 if (rlogin != _POSIX_VDISABLE)
1966 printf("%s> ", prompt);
1967 if (fgets(line, sizeof(line), stdin) == NULL) {
1968 if (feof(stdin) || ferror(stdin)) {
1969 quit();
1970 /*NOTREACHED*/
1971 }
1972 break;
1973 }
1974 }
1975 if (line[0] == 0)
1976 break;
1977 makeargv();
1978 if (margv[0] == 0) {
1979 break;
1980 }
1981 if (process_command(&cmdtab, margc, margv)) break;
1982 }
1983 if (!top) {
1984 if (!connected) {
1985 siglongjmp(toplevel, 1);
1986 /*NOTREACHED*/
1987 }
1988#if defined(TN3270)
1989 if (shell_active == 0) {
1990 setconnmode(0);
1991 }
1992#else /* defined(TN3270) */
1993 setconnmode(0);
1994#endif /* defined(TN3270) */
1995 }
1996}
1997
1998/*
1999 * Help command.
2000 */
2001static int help(command_table *tab, int argc, const char *argv[]) {
2002 int i;
2003
2004 if (argc == 1) {
2005 printf("Commands may be abbreviated. Commands are:\n\n");
2006 for (i = 0; i<tab->num(); i++) (*tab)[i]->describe();
2007 return 0;
2008 }
2009 for (i=1; i<argc; i++) {
2010 command_entry *c = getcmd(tab, argv[i]);
2011 if (c == HELP) {
2012 printf("Print help information\n");
2013 }
2014 else if (c == AMBIGUOUS) {
2015 printf("?Ambiguous help command %s\n", argv[i]);
2016 }
2017 else if (c == NULL) {
2018 printf("?Invalid help command %s\n", argv[i]);
2019 }
2020 else {
2021 c->gethelp();
2022 }
2023 }
2024 return 0;
2025}
2026
2027static char *rcname = 0;
2028static char rcbuf[128];
2029
2030void cmdrc(const char *m1, const char *m2) {
2031 FILE *rcfile;
2032 int gotmachine = 0;
2033 int l1 = strlen(m1);
2034 int l2 = strlen(m2);
2035 char m1save[strlen(m1) + 1];
2036
2037 if (skiprc) return;
2038
2039 strcpy(m1save, m1);
2040 m1 = m1save;
2041
2042 if (rcname == 0) {
2043 rcname = getenv("HOME");
2044 if (rcname)
2045 strcpy(rcbuf, rcname);
2046 else
2047 rcbuf[0] = '\0';
2048 strcat(rcbuf, "/.telnetrc");
2049 rcname = rcbuf;
2050 }
2051
2052 rcfile = fopen(rcname, "r");
2053 if (!rcfile) return;
2054
2055 while (fgets(line, sizeof(line), rcfile)) {
2056 if (line[0] == 0)
2057 break;
2058 if (line[0] == '#')
2059 continue;
2060 if (gotmachine) {
2061 if (!isspace(line[0]))
2062 gotmachine = 0;
2063 }
2064 if (gotmachine == 0) {
2065 if (isspace(line[0]))
2066 continue;
2067 if (strncasecmp(line, m1, l1) == 0)
2068 strncpy(line, &line[l1], sizeof(line) - l1);
2069 else if (strncasecmp(line, m2, l2) == 0)
2070 strncpy(line, &line[l2], sizeof(line) - l2);
2071 else if (strncasecmp(line, "DEFAULT", 7) == 0)
2072 strncpy(line, &line[7], sizeof(line) - 7);
2073 else
2074 continue;
2075 if (line[0] != ' ' && line[0] != '\t' && line[0] != '\n')
2076 continue;
2077 gotmachine = 1;
2078 }
2079 makeargv();
2080 if (margv[0] == 0)
2081 continue;
2082 process_command(&cmdtab, margc, margv);
2083 }
2084 fclose(rcfile);
2085}
2086
2087#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
2088
2089/*
2090 * Source route is handed in as
2091 * [!]@hop1@hop2...[@|:]dst
2092 * If the leading ! is present, it is a
2093 * strict source route, otherwise it is
2094 * assmed to be a loose source route.
2095 *
2096 * We fill in the source route option as
2097 * hop1,hop2,hop3...dest
2098 * and return a pointer to hop1, which will
2099 * be the address to connect() to.
2100 *
2101 * Arguments:
2102 * arg: pointer to route list to decipher
2103 *
2104 * cpp: If *cpp is not equal to NULL, this is a
2105 * pointer to a pointer to a character array
2106 * that should be filled in with the option.
2107 *
2108 * lenp: pointer to an integer that contains the
2109 * length of *cpp if *cpp != NULL.
2110 *
2111 * Return values:
2112 *
2113 * Returns the address of the host to connect to. If the
2114 * return value is -1, there was a syntax error in the
2115 * option, either unknown characters, or too many hosts.
2116 * If the return value is 0, one of the hostnames in the
2117 * path is unknown, and *cpp is set to point to the bad
2118 * hostname.
2119 *
2120 * *cpp: If *cpp was equal to NULL, it will be filled
2121 * in with a pointer to our static area that has
2122 * the option filled in. This will be 32bit aligned.
2123 *
2124 * *lenp: This will be filled in with how long the option
2125 * pointed to by *cpp is.
2126 *
2127 */
2128static unsigned long sourceroute(char *arg, char **cpp, int *lenp) {
2129 static char lsr[44];
2130 char *cp, *cp2, *lsrp, *lsrep;
2131 struct in_addr sin_addr;
2132 register struct hostent *host = 0;
2133 register char c;
2134
2135 /*
2136 * Verify the arguments, and make sure we have
2137 * at least 7 bytes for the option.
2138 */
2139 if (cpp == NULL || lenp == NULL)
2140 return((unsigned long)-1);
2141 if (*cpp != NULL && *lenp < 7)
2142 return((unsigned long)-1);
2143 /*
2144 * Decide whether we have a buffer passed to us,
2145 * or if we need to use our own static buffer.
2146 */
2147 if (*cpp) {
2148 lsrp = *cpp;
2149 lsrep = lsrp + *lenp;
2150 }
2151 else {
2152 *cpp = lsrp = lsr;
2153 lsrep = lsrp + 44;
2154 }
2155
2156 cp = arg;
2157
2158 /*
2159 * Next, decide whether we have a loose source
2160 * route or a strict source route, and fill in
2161 * the begining of the option.
2162 */
2163 if (*cp == '!') {
2164 cp++;
2165 *lsrp++ = IPOPT_SSRR;
2166 }
2167 else *lsrp++ = IPOPT_LSRR;
2168
2169 if (*cp != '@')
2170 return((unsigned long)-1);
2171
2172 lsrp++; /* skip over length, we'll fill it in later */
2173 *lsrp++ = 4;
2174
2175 cp++;
2176
2177 sin_addr.s_addr = 0;
2178
2179 for (c = 0;;) {
2180 if (c == ':')
2181 cp2 = 0;
2182 else for (cp2 = cp; (c = *cp2) != 0; cp2++) {
2183 if (c == ',') {
2184 *cp2++ = '\0';
2185 if (*cp2 == '@')
2186 cp2++;
2187 } else if (c == '@') {
2188 *cp2++ = '\0';
2189 } else if (c == ':') {
2190 *cp2++ = '\0';
2191 } else
2192 continue;
2193 break;
2194 }
2195 if (!c)
2196 cp2 = 0;
2197
2198 if (inet_aton(cp, &sin_addr)) ; /* nothing */
2199 else if ((host = gethostbyname(cp))!=NULL) {
2200 if (host->h_length > (int)sizeof(sin_addr)) {
2201 host->h_length = sizeof(sin_addr);
2202 }
2203#if defined(h_addr)
2204 memcpy(&sin_addr, host->h_addr_list[0], host->h_length);
2205#else
2206 memcpy(&sin_addr, host->h_addr, host->h_length);
2207#endif
2208 } else {
2209 *cpp = cp;
2210 return(0);
2211 }
2212 memcpy(lsrp, (char *)&sin_addr, 4);
2213 lsrp += 4;
2214 if (cp2)
2215 cp = cp2;
2216 else
2217 break;
2218 /*
2219 * Check to make sure there is space for next address
2220 */
2221 if (lsrp + 4 > lsrep)
2222 return((unsigned long)-1);
2223 }
2224 if ((*(*cpp+IPOPT_OLEN) = lsrp - *cpp) <= 7) {
2225 *cpp = 0;
2226 *lenp = 0;
2227 return((unsigned long)-1);
2228 }
2229 *lsrp++ = IPOPT_NOP; /* 32 bit word align it */
2230 *lenp = lsrp - *cpp;
2231 return(sin_addr.s_addr);
2232}
2233#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/commands.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/commands.o
new file mode 100644
index 0000000..d02baf8
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/commands.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/defines.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/defines.h
new file mode 100644
index 0000000..2784400
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/defines.h
@@ -0,0 +1,52 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)defines.h 5.1 (Berkeley) 9/14/90
34 * $Id: defines.h,v 1.5 1996/08/04 23:44:43 dholland Exp $
35 */
36
37#define ENV_VAR NEW_ENV_VAR
38#define ENV_VALUE NEW_ENV_VALUE
39#define TELOPT_ENVIRON TELOPT_NEW_ENVIRON
40
41#define settimer(x) clocks.x = clocks.system++
42
43#if !defined(TN3270)
44#define SetIn3270()
45#endif
46
47/* Various modes */
48#define MODE_LOCAL_CHARS(m) ((m)&(MODE_EDIT|MODE_TRAPSIG))
49#define MODE_LOCAL_ECHO(m) ((m)&MODE_ECHO)
50#define MODE_COMMAND_LINE(m) ((m)==-1)
51
52#define CONTROL(x) ((x)&0x1f) /* CTRL(x) is not portable */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/depend.mk b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/depend.mk
new file mode 100644
index 0000000..fe6eaa0
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/depend.mk
@@ -0,0 +1,17 @@
1commands.o: commands.cc ring.h externs.h defines.h types.h genget.h \
2 environ.h proto.h ptrarray.h netlink.h
3main.o: main.cc ../version.h ring.h externs.h defines.h proto.h
4network.o: network.cc ring.h defines.h externs.h proto.h netlink.h
5ring.o: ring.cc ring.h
6sys_bsd.o: sys_bsd.cc ring.h defines.h externs.h types.h proto.h \
7 netlink.h terminal.h
8telnet.o: telnet.cc ring.h defines.h externs.h types.h environ.h \
9 proto.h ptrarray.h netlink.h terminal.h
10terminal.o: terminal.cc ring.h defines.h externs.h types.h proto.h \
11 terminal.h
12tn3270.o: tn3270.cc defines.h ring.h externs.h proto.h
13utilities.o: utilities.cc ring.h defines.h externs.h proto.h \
14 terminal.h
15genget.o: genget.cc genget.h
16environ.o: environ.cc ring.h defines.h externs.h environ.h array.h
17netlink.o: netlink.cc netlink.h proto.h ring.h
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.cc
new file mode 100644
index 0000000..3950f04
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.cc
@@ -0,0 +1,200 @@
1#include <unistd.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <arpa/telnet.h>
6#include "ring.h"
7#include "defines.h"
8#include "externs.h"
9#include "environ.h"
10#include "array.h"
11
12class enviro {
13 protected:
14 char *var; /* pointer to variable name */
15 char *value; /* pointer to variable's value */
16 int doexport; /* 1 -> export with default list of variables */
17
18 void clean() { if (var) delete []var; if (value) delete []value; }
19 public:
20 enviro() { var = value = NULL; doexport = 0; }
21 ~enviro() { clean(); }
22
23 const char *getname() const { return var; }
24 const char *getval() const { return value; }
25
26 void define(const char *vr, const char *vl) {
27 clean();
28 var = strcpy(new char[strlen(vr)+1], vr);
29 value = strcpy(new char[strlen(vl)+1], vl);
30 }
31
32 void clear() { clean(); var = value = NULL; }
33
34 void setexport(int ex) { doexport = ex; }
35 int getexport() const { return doexport; }
36};
37
38static array<enviro> vars;
39
40static enviro *env_find(const char *var) {
41 for (int i=0; i<vars.num(); i++) if (vars[i].getname()) {
42 if (!strcmp(vars[i].getname(), var))
43 return &vars[i];
44 }
45 return NULL;
46}
47
48static void env_put(const char *var, const char *val, int exp) {
49 enviro *ep = env_find(var);
50 if (!ep) {
51 int x = vars.num();
52 vars.setsize(x+1);
53 ep = &vars[x];
54 }
55 ep->define(var, val);
56 ep->setexport(exp);
57}
58
59static void env_copy(void) {
60 extern char **environ;
61
62 char *s;
63 int i;
64
65 for (i=0; environ[i]; i++) {
66 s = strchr(environ[i], '=');
67 if (s) {
68 *s=0;
69 env_put(environ[i], s+1, 0);
70 *s='=';
71 }
72 }
73}
74
75/*
76 * Special case for DISPLAY variable. If it is ":0.0" or
77 * "unix:0.0", we have to get rid of "unix" and insert our
78 * hostname.
79 */
80static void env_fix_display(void) {
81 enviro *ep = env_find("DISPLAY");
82 if (!ep) return;
83 ep->setexport(1);
84
85 if (strncmp(ep->getval(), ":", 1) && strncmp(ep->getval(), "unix:", 5)) {
86 return;
87 }
88 char hbuf[256];
89 const char *cp2 = strrchr(ep->getval(), ':');
90 int maxlen = sizeof(hbuf)-strlen(cp2)-1;
91 gethostname(hbuf, maxlen);
92 hbuf[maxlen] = 0; /* ensure null termination */
93
94 /*
95 * dholland 7/30/96 if not a FQDN ask DNS
96 */
97 if (!strchr(hbuf, '.')) {
98 struct hostent *h = gethostbyname(hbuf);
99 if (h) {
100 strncpy(hbuf, h->h_name, maxlen);
101 hbuf[maxlen] = 0; /* ensure null termination */
102 }
103 }
104
105 strcat(hbuf, cp2);
106
107 ep->define("DISPLAY", hbuf);
108}
109
110/*********************************************** interface ***********/
111
112void env_init(void) {
113 env_copy();
114 env_fix_display();
115
116 /*
117 * If USER is not defined, but LOGNAME is, then add
118 * USER with the value from LOGNAME. By default, we
119 * don't export the USER variable.
120 */
121 if (!env_find("USER")) {
122 enviro *ep = env_find("LOGNAME");
123 if (ep) env_put("USER", ep->getval(), 0);
124 }
125
126 enviro *ep = env_find("PRINTER");
127 if (ep) ep->setexport(1);
128}
129
130void env_define(const char *var, const char *value) {
131 env_put(var, value, 1);
132}
133
134void env_undefine(const char *var) {
135 enviro *ep = env_find(var);
136 if (ep) {
137 /*
138 * We don't make any effort to reuse cleared environment spaces.
139 * It's highly unlikely to be worth the trouble.
140 */
141 ep->clear();
142 }
143}
144
145void env_export(const char *var) {
146 enviro *ep = env_find(var);
147 if (ep) ep->setexport(1);
148}
149
150void env_unexport(const char *var) {
151 enviro *ep = env_find(var);
152 if (ep) ep->setexport(0);
153}
154
155void env_send(const char *var) {
156 if (my_state_is_wont(TELOPT_ENVIRON)) {
157 fprintf(stderr, "Cannot send '%s': Telnet ENVIRON option disabled\n",
158 var);
159 return;
160 }
161
162 enviro *ep = env_find(var);
163 if (!ep) {
164 fprintf(stderr, "Cannot send '%s': variable not defined\n", var);
165 return;
166 }
167 env_opt_start_info();
168 env_opt_add(ep->getname());
169 env_opt_end(0);
170}
171
172void env_list(void) {
173 for (int i=0; i<vars.num(); i++) if (vars[i].getname()) {
174 printf("%c %-20s %s\n", vars[i].getexport() ? '*' : ' ',
175 vars[i].getname(), vars[i].getval());
176 }
177}
178
179void env_iterate(int *iter, int /*exported_only*/) {
180 *iter = 0;
181}
182
183const char *env_next(int *iter, int exported_only) {
184 while (*iter>=0 && *iter<vars.num()) {
185 int k = (*iter)++;
186
187 if (!vars[k].getname()) continue; // deleted variable
188
189 if (vars[k].getexport() || !exported_only) {
190 return vars[k].getname();
191 }
192 }
193 return NULL;
194}
195
196const char *env_getvalue(const char *var) {
197 enviro *ep = env_find(var);
198 if (ep) return ep->getval();
199 return NULL;
200}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.h
new file mode 100644
index 0000000..bc45c08
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.h
@@ -0,0 +1,10 @@
1void env_define(const char *var, const char *val);
2void env_undefine(const char *var);
3void env_export(const char *var);
4void env_unexport(const char *);
5void env_send(const char *);
6void env_list(void);
7const char *env_getvalue(const char *);
8
9void env_iterate(int *, int exported_only);
10const char *env_next(int *, int exported_only);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.o
new file mode 100644
index 0000000..b506e8a
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/environ.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/externs.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/externs.h
new file mode 100644
index 0000000..955df79
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/externs.h
@@ -0,0 +1,365 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)externs.h 5.3 (Berkeley) 3/22/91
34 * $Id: externs.h,v 1.20 1999/08/19 09:34:15 dholland Exp $
35 */
36
37#ifndef BSD
38#define BSD 43
39#endif
40
41#include <stdio.h>
42#include <setjmp.h>
43#include <sys/ioctl.h>
44#include <features.h>
45#include <termios.h>
46
47#if defined(NO_CC_T)
48typedef unsigned char cc_t;
49#endif
50
51#ifdef __linux__
52#include <unistd.h> /* get _POSIX_VDISABLE */
53#endif
54
55#ifndef _POSIX_VDISABLE
56#error "Please fix externs.h to define _POSIX_VDISABLE"
57#endif
58
59#define SUBBUFSIZE 256
60
61extern int autologin; /* Autologin enabled */
62extern int skiprc; /* Don't process the ~/.telnetrc file */
63extern int eight; /* use eight bit mode (binary in and/or out */
64extern int flushout; /* flush output */
65extern int connected; /* Are we connected to the other side? */
66extern int globalmode; /* Mode tty should be in */
67extern int In3270; /* Are we in 3270 mode? */
68extern int telnetport; /* Are we connected to the telnet port? */
69extern int localflow; /* Flow control handled locally */
70extern int localchars; /* we recognize interrupt/quit */
71extern int donelclchars; /* the user has set "localchars" */
72extern int showoptions;
73
74extern int crlf; /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
75extern int autoflush; /* flush output when interrupting? */
76extern int autosynch; /* send interrupt characters with SYNCH? */
77extern int SYNCHing; /* Is the stream in telnet SYNCH mode? */
78extern int donebinarytoggle; /* the user has put us in binary */
79extern int dontlecho; /* do we suppress local echoing right now? */
80extern int crmod;
81//extern int netdata; /* Print out network data flow */
82//extern int prettydump; /* Print "netdata" output in user readable format */
83extern int debug; /* Debug level */
84
85#ifdef TN3270
86extern int cursesdata; /* Print out curses data flow */
87#endif /* unix and TN3270 */
88
89extern cc_t escapechar; /* Escape to command mode */
90extern cc_t rlogin; /* Rlogin mode escape character */
91#ifdef KLUDGELINEMODE
92extern cc_t echoc; /* Toggle local echoing */
93#endif
94
95extern char *prompt; /* Prompt for command. */
96
97extern char doopt[];
98extern char dont[];
99extern char will[];
100extern char wont[];
101extern char options[]; /* All the little options */
102extern char *hostname; /* Who are we connected to? */
103
104/*
105 * We keep track of each side of the option negotiation.
106 */
107
108#define MY_STATE_WILL 0x01
109#define MY_WANT_STATE_WILL 0x02
110#define MY_STATE_DO 0x04
111#define MY_WANT_STATE_DO 0x08
112
113/*
114 * Macros to check the current state of things
115 */
116
117#define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
118#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
119#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
120#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
121
122#define my_state_is_dont(opt) (!my_state_is_do(opt))
123#define my_state_is_wont(opt) (!my_state_is_will(opt))
124#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
125#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
126
127#define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;}
128#define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;}
129#define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;}
130#define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;}
131
132#define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;}
133#define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;}
134#define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;}
135#define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;}
136
137/*
138 * Make everything symmetric
139 */
140
141#define HIS_STATE_WILL MY_STATE_DO
142#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
143#define HIS_STATE_DO MY_STATE_WILL
144#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
145
146#define his_state_is_do my_state_is_will
147#define his_state_is_will my_state_is_do
148#define his_want_state_is_do my_want_state_is_will
149#define his_want_state_is_will my_want_state_is_do
150
151#define his_state_is_dont my_state_is_wont
152#define his_state_is_wont my_state_is_dont
153#define his_want_state_is_dont my_want_state_is_wont
154#define his_want_state_is_wont my_want_state_is_dont
155
156#define set_his_state_do set_my_state_will
157#define set_his_state_will set_my_state_do
158#define set_his_want_state_do set_my_want_state_will
159#define set_his_want_state_will set_my_want_state_do
160
161#define set_his_state_dont set_my_state_wont
162#define set_his_state_wont set_my_state_dont
163#define set_his_want_state_dont set_my_want_state_wont
164#define set_his_want_state_wont set_my_want_state_dont
165
166
167extern FILE *NetTrace; /* Where debugging output goes */
168extern char NetTraceFile[]; /* Name of file where debugging output goes */
169
170void SetNetTrace(const char *); /* Function to change where debugging goes */
171
172extern sigjmp_buf peerdied;
173extern sigjmp_buf toplevel; /* For error conditions. */
174
175void command(int, const char *, int);
176void Dump (int, char *, int);
177void init_3270 (void);
178void printoption(const char *, int, int);
179void printsub (int, unsigned char *, int);
180void sendnaws (void);
181void setconnmode(int);
182void setcommandmode (void);
183void setneturg (void);
184void sys_telnet_init (void);
185void telnet(const char *);
186void tel_enter_binary(int);
187void TerminalFlushOutput(void);
188void TerminalNewMode(int);
189void TerminalRestoreState(void);
190void TerminalSaveState(void);
191void tninit(void);
192void upcase(char *);
193void willoption(int);
194void wontoption(int);
195
196void lm_will(unsigned char *, int);
197void lm_wont(unsigned char *, int);
198void lm_do(unsigned char *, int);
199void lm_dont(unsigned char *, int);
200void lm_mode(unsigned char *, int, int);
201
202void slc_init(void);
203void slcstate(void);
204void slc_mode_export(void);
205void slc_mode_import(int);
206void slc_import(int);
207void slc_export(void);
208void slc(unsigned char *, int);
209void slc_check(void);
210void slc_start_reply(void);
211void slc_add_reply(int, int, int);
212void slc_end_reply(void);
213int slc_update(void);
214
215void env_opt(unsigned char *, int);
216void env_opt_start(void);
217void env_opt_start_info(void);
218void env_opt_add(const char *);
219void env_opt_end(int);
220
221int get_status(const char *, const char *);
222int dosynch(void);
223
224cc_t *tcval(int);
225
226//#if 0
227extern struct termios new_tc;
228
229#define termEofChar new_tc.c_cc[VEOF]
230#define termEraseChar new_tc.c_cc[VERASE]
231#define termIntChar new_tc.c_cc[VINTR]
232#define termKillChar new_tc.c_cc[VKILL]
233#define termQuitChar new_tc.c_cc[VQUIT]
234
235#ifndef VSUSP
236extern cc_t termSuspChar;
237#else
238#define termSuspChar new_tc.c_cc[VSUSP]
239#endif
240
241#if defined(VFLUSHO) && !defined(VDISCARD)
242#define VDISCARD VFLUSHO
243#endif
244#ifndef VDISCARD
245extern cc_t termFlushChar;
246#else
247#define termFlushChar new_tc.c_cc[VDISCARD]
248#endif
249
250#ifndef VWERASE
251extern cc_t termWerasChar;
252#else
253#define termWerasChar new_tc.c_cc[VWERASE]
254#endif
255
256#ifndef VREPRINT
257extern cc_t termRprntChar;
258#else
259#define termRprntChar new_tc.c_cc[VREPRINT]
260#endif
261
262#ifndef VLNEXT
263extern cc_t termLiteralNextChar;
264#else
265#define termLiteralNextChar new_tc.c_cc[VLNEXT]
266#endif
267
268#ifndef VSTART
269extern cc_t termStartChar;
270#else
271#define termStartChar new_tc.c_cc[VSTART]
272#endif
273
274#ifndef VSTOP
275extern cc_t termStopChar;
276#else
277#define termStopChar new_tc.c_cc[VSTOP]
278#endif
279
280#ifndef VEOL
281extern cc_t termForw1Char;
282#else
283#define termForw1Char new_tc.c_cc[VEOL]
284#endif
285
286#ifndef VEOL2
287extern cc_t termForw2Char;
288#else
289#define termForw2Char new_tc.c_cc[VEOL]
290#endif
291
292#ifndef VSTATUS
293extern cc_t termAytChar;
294#else
295#define termAytChar new_tc.c_cc[VSTATUS]
296#endif
297
298//#endif /* 0 */
299
300//#if 0
301#if !defined(CRAY) || defined(__STDC__)
302#define termEofCharp &termEofChar
303#define termEraseCharp &termEraseChar
304#define termIntCharp &termIntChar
305#define termKillCharp &termKillChar
306#define termQuitCharp &termQuitChar
307#define termSuspCharp &termSuspChar
308#define termFlushCharp &termFlushChar
309#define termWerasCharp &termWerasChar
310#define termRprntCharp &termRprntChar
311#define termLiteralNextCharp &termLiteralNextChar
312#define termStartCharp &termStartChar
313#define termStopCharp &termStopChar
314#define termForw1Charp &termForw1Char
315#define termForw2Charp &termForw2Char
316#define termAytCharp &termAytChar
317#else
318 /* Work around a compiler bug */
319#define termEofCharp 0
320#define termEraseCharp 0
321#define termIntCharp 0
322#define termKillCharp 0
323#define termQuitCharp 0
324#define termSuspCharp 0
325#define termFlushCharp 0
326#define termWerasCharp 0
327#define termRprntCharp 0
328#define termLiteralNextCharp 0
329#define termStartCharp 0
330#define termStopCharp 0
331#define termForw1Charp 0
332#define termForw2Charp 0
333#define termAytCharp 0
334#endif
335
336//#endif /* 0 */
337
338
339/* Ring buffer structures which are shared */
340
341extern ringbuf netoring;
342extern ringbuf netiring;
343extern ringbuf ttyoring;
344extern ringbuf ttyiring;
345
346/* Tn3270 section */
347#if defined(TN3270)
348
349extern int HaveInput; /* Whether an asynchronous I/O indication came in */
350extern int noasynchtty; /* Don't do signals on I/O (SIGURG, SIGIO) */
351extern int noasynchnet; /* Don't do signals on I/O (SIGURG, SIGIO) */
352extern int sigiocount; /* Count of SIGIO receptions */
353extern int shell_active; /* Subshell is active */
354
355extern char *Ibackp; /* Oldest byte of 3270 data */
356extern char Ibuf[]; /* 3270 buffer */
357extern char *Ifrontp; /* Where next 3270 byte goes */
358extern char tline[];
359extern char *transcom; /* Transparent command */
360
361void settranscom(int, char**);
362int shell(int, char**);
363void inputAvailable(void);
364
365#endif /* defined(TN3270) */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/fdset.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/fdset.h
new file mode 100644
index 0000000..7542166
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/fdset.h
@@ -0,0 +1,50 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)fdset.h 5.1 (Berkeley) 9/14/90
34 * $Id: fdset.h,v 1.1 1996/07/16 05:17:22 dholland Exp $
35 */
36
37/*
38 * The following is defined just in case someone should want to run
39 * this telnet on a 4.2 system.
40 *
41 */
42
43#ifndef FD_SETSIZE
44
45#define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
46#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
47#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
48#define FD_ZERO(p) ((p)->fds_bits[0] = 0)
49
50#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/general.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/general.h
new file mode 100644
index 0000000..1d9df66
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/general.h
@@ -0,0 +1,46 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)general.h 5.2 (Berkeley) 3/1/91
34 * $Id: general.h,v 1.1 1996/07/16 05:17:22 dholland Exp $
35 */
36
37/*
38 * Some general definitions.
39 */
40
41
42#define numberof(x) (sizeof x/sizeof x[0])
43#define highestof(x) (numberof(x)-1)
44
45#define ClearElement(x) memset((char *)&x, 0, sizeof x)
46#define ClearArray(x) memset((char *)x, 0, sizeof x)
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.cc
new file mode 100644
index 0000000..3f835b3
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.cc
@@ -0,0 +1,91 @@
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)genget.c 5.1 (Berkeley) 2/28/91
36 */
37char gg_rcsid[] =
38 "$Id: genget.cc,v 1.3 1996/07/26 09:54:09 dholland Exp $";
39
40#include <string.h>
41#include <ctype.h>
42
43#include "genget.h"
44
45#define LOWER(x) (isupper(x) ? tolower(x) : (x))
46/*
47 * The prefix function returns 0 if *s1 is not a prefix
48 * of *s2. If *s1 exactly matches *s2, the negative of
49 * the length is returned. If *s1 is a prefix of *s2,
50 * the length of *s1 is returned.
51 */
52int isprefix(const char *s1, const char *s2) {
53 const char *os1;
54 char c1, c2;
55
56 if (*s1 == 0) return -1;
57
58 os1 = s1;
59 c1 = *s1;
60 c2 = *s2;
61
62 while (LOWER(c1) == LOWER(c2)) {
63 if (c1 == 0) break;
64 c1 = *++s1;
65 c2 = *++s2;
66 }
67 if (*s1) return 0;
68 return *s2 ? (s1 - os1) : (os1 - s1);
69}
70
71/*
72 * name: name to match
73 * table: name entry in table
74 */
75char **genget(const char *name, char **table, int stlen) {
76 char **c, **found;
77 int n;
78
79 if (!name) return NULL;
80
81 found = NULL;
82 for (c = table; *c; c = (char **)((char *)c + stlen)) {
83 n = isprefix(name, *c);
84 if (n == 0) continue;
85 if (n < 0) return c; /* exact match */
86 if (found) return (char **)AMBIGUOUS;
87 found = c;
88 }
89 return found;
90}
91
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.h
new file mode 100644
index 0000000..891a42f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.h
@@ -0,0 +1,5 @@
1int isprefix(const char *, const char *);
2char **genget(const char *, char **, int);
3
4#define AMBIGUOUS ((void *)1)
5#define HELP ((void *)2)
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.o
new file mode 100644
index 0000000..b35bb1b
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/genget.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/main.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/main.cc
new file mode 100644
index 0000000..b67f2ce
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/main.cc
@@ -0,0 +1,257 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34char copyright[] =
35 "@(#) Copyright (c) 1988, 1990 Regents of the University of California.\n"
36 "All rights reserved.\n";
37
38/*
39 * From: @(#)main.c 5.4 (Berkeley) 3/22/91
40 */
41char main_rcsid[] =
42 "$Id: main.cc,v 1.14 1999/08/01 05:06:37 dholland Exp $";
43
44#include "../version.h"
45
46#include <sys/types.h>
47#include <getopt.h>
48#include <string.h>
49
50#include "ring.h"
51#include "externs.h"
52#include "defines.h"
53#include "proto.h"
54
55/*
56 * Initialize variables.
57 */
58void
59tninit(void)
60{
61 init_terminal();
62
63 init_network();
64
65 init_telnet();
66
67 init_sys();
68
69#if defined(TN3270)
70 init_3270();
71#endif
72}
73
74/*
75 * note: -x should mean use encryption
76 * -k <realm> to set kerberos realm
77 * -K don't auto-login
78 * -X <atype> disable specified auth type
79 */
80void usage(void) {
81 fprintf(stderr, "Usage: %s %s%s%s%s\n",
82 prompt,
83 " [-8] [-E] [-L] [-a] [-d] [-e char] [-l user] [-n tracefile]",
84 "\n\t",
85#ifdef TN3270
86 "[-noasynch] [-noasynctty] [-noasyncnet] [-r] [-t transcom]\n\t",
87#else
88 "[-r] ",
89#endif
90 "[host-name [port]]"
91 );
92 exit(1);
93}
94
95/*
96 * main. Parse arguments, invoke the protocol or command parser.
97 */
98
99int
100main(int argc, char *argv[])
101{
102 extern char *optarg;
103 extern int optind;
104 int ch;
105 char *user;
106
107 tninit(); /* Clear out things */
108#if defined(CRAY) && !defined(__STDC__)
109 _setlist_init(); /* Work around compiler bug */
110#endif
111
112 TerminalSaveState();
113
114 if ((prompt = strrchr(argv[0], '/'))!=NULL)
115 ++prompt;
116 else
117 prompt = argv[0];
118
119 user = NULL;
120
121 rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
122 autologin = -1;
123
124 while ((ch = getopt(argc, argv, "8EKLS:X:ade:k:l:n:rt:x")) != EOF) {
125 switch(ch) {
126 case '8':
127 eight = 3; /* binary output and input */
128 break;
129 case 'E':
130 rlogin = escapechar = _POSIX_VDISABLE;
131 break;
132 case 'K':
133 //autologin = 0;
134 break;
135 case 'L':
136 eight |= 2; /* binary output only */
137 break;
138 case 'S':
139 {
140#ifdef HAS_GETTOS
141 extern int tos;
142
143 if ((tos = parsetos(optarg, "tcp")) < 0)
144 fprintf(stderr, "%s%s%s%s\n",
145 prompt, ": Bad TOS argument '",
146 optarg,
147 "; will try to use default TOS");
148#else
149 fprintf(stderr,
150 "%s: Warning: -S ignored, no parsetos() support.\n",
151 prompt);
152#endif
153 }
154 break;
155 case 'X':
156 // disable authentication type "optarg"
157 break;
158 case 'a':
159 autologin = 1;
160 break;
161 case 'c':
162 skiprc = 1;
163 break;
164 case 'd':
165 debug = 1;
166 break;
167 case 'e':
168 set_escape_char(optarg);
169 break;
170 case 'k':
171 fprintf(stderr,
172 "%s: -k ignored, no Kerberos V4 support.\n",
173 prompt);
174 break;
175 case 'l':
176 autologin = 1;
177 user = optarg;
178 break;
179 case 'n':
180#ifdef TN3270
181 /* distinguish between "-n oasynch" and "-noasynch" */
182 if (argv[optind - 1][0] == '-' && argv[optind - 1][1]
183 == 'n' && argv[optind - 1][2] == 'o') {
184 if (!strcmp(optarg, "oasynch")) {
185 noasynchtty = 1;
186 noasynchnet = 1;
187 } else if (!strcmp(optarg, "oasynchtty"))
188 noasynchtty = 1;
189 else if (!strcmp(optarg, "oasynchnet"))
190 noasynchnet = 1;
191 } else
192#endif /* TN3270 */
193 SetNetTrace(optarg);
194 break;
195 case 'r':
196 rlogin = '~';
197 break;
198 case 't':
199#ifdef TN3270
200 transcom = tline;
201 (void)strcpy(transcom, optarg);
202#else
203 fprintf(stderr,
204 "%s: Warning: -t ignored, no TN3270 support.\n",
205 prompt);
206#endif
207 break;
208 case 'x':
209 fprintf(stderr,
210 "%s: -x ignored, no encryption support.\n",
211 prompt);
212 break;
213 case '?':
214 default:
215 usage();
216 /* NOTREACHED */
217 }
218 }
219 if (autologin == -1)
220 autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
221
222 argc -= optind;
223 argv += optind;
224
225 if (argc) {
226 const char *args[7];
227 const char **volatile argp = args;
228
229 if (argc > 2)
230 usage();
231 *argp++ = prompt;
232 if (user) {
233 *argp++ = "-l";
234 *argp++ = user;
235 }
236 *argp++ = argv[0]; /* host */
237 if (argc > 1)
238 *argp++ = argv[1]; /* port */
239 *argp = 0;
240
241 if (sigsetjmp(toplevel, 1) != 0)
242 Exit(0);
243 if (tn(argp - args, args) == 1)
244 return (0);
245 else
246 return (1);
247 }
248 (void)sigsetjmp(toplevel, 1);
249 for (;;) {
250#ifdef TN3270
251 if (shell_active)
252 shell_continue();
253 else
254#endif
255 command(1, 0, 0);
256 }
257}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/main.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/main.o
new file mode 100644
index 0000000..2e602f9
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/main.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.cc
new file mode 100644
index 0000000..c418993
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.cc
@@ -0,0 +1,199 @@
1#include <errno.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <stdlib.h>
5#include <sys/socket.h>
6#include <netinet/in.h>
7#include <arpa/inet.h>
8#include <sys/ioctl.h>
9#include <sys/time.h>
10#include <netdb.h>
11#include "netlink.h"
12#include "proto.h"
13#include "ring.h"
14
15/* In linux, this is an enum */
16#ifdef __linux__
17#define HAS_IPPROTO_IP
18#endif
19
20#ifdef IPPROTO_IP
21#define HAS_IPPROTO_IP
22#endif
23
24
25netlink nlink;
26
27class netchannel : public ringbuf::source {
28 public:
29 virtual int read(char *buf, int maxlen) {
30 int net = nlink.getfd();
31 int l = recv(net, buf, maxlen, 0);
32 if (l<0 && errno == EWOULDBLOCK) l = 0;
33 return l;
34 }
35};
36
37class netchannel2 : public datasink {
38 public:
39 virtual int write(const char *buf, int len) {
40 int r = nlink.send(buf, len, 0);
41 if (r==-1 && (errno==ENOBUFS || errno==EWOULDBLOCK)) return 0;
42 return r;
43 }
44 virtual int writeurg(const char *buf, int len) {
45 /*
46 * In 4.2 (and 4.3) systems, there is some question about
47 * what byte in a sendOOB operation is the "OOB" data.
48 * To make ourselves compatible, we only send ONE byte
49 * out of band, the one WE THINK should be OOB (though
50 * we really have more the TCP philosophy of urgent data
51 * rather than the Unix philosophy of OOB data).
52 */
53 if (len==0) return 0;
54 int r = nlink.send(buf, 1, MSG_OOB);
55 if (r==-1 && (errno==ENOBUFS || errno==EWOULDBLOCK)) r = 0;
56 if (r<=0) return r;
57 int rr = nlink.send(buf+1, len-r, 0);
58 if (rr==-1 && (errno==ENOBUFS || errno==EWOULDBLOCK)) rr = 0;
59 if (rr<=0) return r; /* less than ideal */
60 return r+rr;
61 }
62};
63
64static netchannel chan;
65static netchannel2 chan2;
66datasink *netsink = &chan2;
67ringbuf::source *netsrc = &chan;
68
69
70netlink::netlink() { net = -1; }
71netlink::~netlink() { ::close(net); }
72
73
74int netlink::setdebug(int debug) {
75 if (net > 0 &&
76 (setsockopt(net, SOL_SOCKET, SO_DEBUG, &debug, sizeof(debug))) < 0) {
77 perror("setsockopt (SO_DEBUG)");
78 }
79 return 1;
80}
81
82void netlink::close(int doshutdown) {
83 if (doshutdown) {
84 shutdown(net, 2);
85 }
86 ::close(net);
87}
88
89int netlink::connect(int debug, struct hostent *host,
90 struct sockaddr_in *sn,
91 char *srcroute, int srlen, int tos)
92{
93 int on=1;
94
95 net = socket(AF_INET, SOCK_STREAM, 0);
96 setuid(getuid());
97 if (net < 0) {
98 perror("telnet: socket");
99 return 0;
100 }
101
102#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
103 if (srcroute) {
104 if (setsockopt(net, IPPROTO_IP, IP_OPTIONS, srcroute, srlen) < 0)
105 perror("setsockopt (IP_OPTIONS)");
106 }
107#endif
108
109#if defined(HAS_IPPROTO_IP) && defined(IP_TOS)
110#if defined(HAS_GETTOS)
111 struct tosent *tp;
112 if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
113 tos = tp->t_tos;
114#endif
115 if (tos < 0) tos = 020; /* Low Delay bit */
116 if (tos && (setsockopt(net, IPPROTO_IP, IP_TOS, &tos, sizeof(int)) < 0)
117 && (errno != ENOPROTOOPT))
118 perror("telnet: setsockopt (IP_TOS) (ignored)");
119#endif /* defined(IPPROTO_IP) && defined(IP_TOS) */
120
121 if (debug && setsockopt(net, SOL_SOCKET, SO_DEBUG, &on, sizeof(on)) < 0) {
122 perror("setsockopt (SO_DEBUG)");
123 }
124
125 if (::connect(net, (struct sockaddr *)sn, sizeof(*sn)) < 0) {
126#if defined(h_addr) /* In 4.3, this is a #define */
127 if (host && host->h_addr_list[1]) {
128 int oerrno = errno;
129
130 fprintf(stderr, "telnet: connect to address %s: ",
131 inet_ntoa(sn->sin_addr));
132 errno = oerrno;
133 perror(NULL);
134 host->h_addr_list++;
135 if (host->h_length > (int)sizeof(sn->sin_addr)) {
136 host->h_length = sizeof(sn->sin_addr);
137 }
138 memcpy(&sn->sin_addr, host->h_addr_list[0], host->h_length);
139 close(net);
140 return 1;
141 }
142#endif /* defined(h_addr) */
143
144 perror("telnet: Unable to connect to remote host");
145 return 0;
146 }
147 return 2;
148}
149
150
151void netlink::oobinline() {
152 int on=1;
153
154 /* Systems without SO_OOBINLINE probably won't work */
155 if (setsockopt(net, SOL_SOCKET, SO_OOBINLINE, &on, sizeof(on)) == -1) {
156 perror("setsockopt");
157 }
158}
159
160
161/*
162 * Check to see if any out-of-band data exists on a socket (for
163 * Telnet "synch" processing).
164 */
165
166int netlink::stilloob(void) {
167 static struct timeval timeout = { 0, 0 };
168 fd_set excepts;
169 int value;
170
171 do {
172 FD_ZERO(&excepts);
173 FD_SET(net, &excepts);
174 value = select(net+1, NULL, NULL, &excepts, &timeout);
175 } while ((value == -1) && (errno == EINTR));
176
177 if (value < 0) {
178 perror("select");
179 quit();
180 /* NOTREACHED */
181 }
182 if (FD_ISSET(net, &excepts)) {
183 return 1;
184 } else {
185 return 0;
186 }
187}
188
189int netlink::send(const char *s, int n, int f) {
190 return ::send(net, s, n, f);
191}
192
193void netlink::nonblock(int onoff) {
194 ioctl(net, FIONBIO, &onoff);
195}
196
197int netlink::getfd() {
198 return net;
199}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.h
new file mode 100644
index 0000000..9852b30
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.h
@@ -0,0 +1,26 @@
1
2class netlink {
3 protected:
4 int net;
5 public:
6 netlink();
7 ~netlink();
8
9 int connect(int debug, struct hostent *host,
10 struct sockaddr_in *sin,
11 char *srcroute, int srlen,
12 int tos);
13 void close(int doshutdown);
14
15 int setdebug(int debug);
16 void oobinline();
17 void nonblock(int onoff);
18
19 int stilloob();
20
21 int send(const char *buf, int len, int flags);
22
23 int getfd();
24};
25
26extern netlink nlink;
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.o
new file mode 100644
index 0000000..9d45f84
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/netlink.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/network.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/network.cc
new file mode 100644
index 0000000..6a2c374
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/network.cc
@@ -0,0 +1,91 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)network.c 5.2 (Berkeley) 3/1/91
36 */
37char net_rcsid[] =
38 "$Id: network.cc,v 1.15 1996/08/13 08:09:58 dholland Exp $";
39
40#include <sys/types.h>
41#include <sys/socket.h>
42#include <sys/time.h>
43#include <errno.h>
44#include <arpa/telnet.h>
45
46#include "ring.h"
47#include "defines.h"
48#include "externs.h"
49#include "proto.h"
50#include "netlink.h"
51
52ringbuf netoring;
53ringbuf netiring;
54
55/*
56 * Initialize internal network data structures.
57 */
58
59void init_network(void) {
60 if (netoring.init(2*BUFSIZ, netsink, NULL) != 1) {
61 exit(1);
62 }
63 if (netiring.init(BUFSIZ, NULL, netsrc) != 1) {
64 exit(1);
65 }
66 NetTrace = stdout;
67}
68
69
70/*
71 * netflush
72 * Send as much data as possible to the network,
73 * handling requests for urgent data.
74 *
75 * The return value indicates whether we did any
76 * useful work.
77 */
78
79
80int netflush(void) {
81 int r = netoring.flush();
82 if (r < -1) {
83 setcommandmode();
84 perror(hostname);
85 nlink.close(0);
86 netoring.clear_mark();
87 siglongjmp(peerdied, -1);
88 /*NOTREACHED*/
89 }
90 return r>0;
91}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/network.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/network.o
new file mode 100644
index 0000000..98df4b4
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/network.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/proto.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/proto.h
new file mode 100644
index 0000000..8be4a39
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/proto.h
@@ -0,0 +1,41 @@
1#if 0
2void auth_encrypt_connect(void);
3void auth_encrypt_init(void);
4#endif
5
6void Exit(int);
7void ExitString(const char *, int);
8int TerminalAutoFlush(void);
9void TerminalDefaultChars(void);
10int TerminalSpecialChars(int);
11void TerminalSpeeds(long *ispeed, long *ospeed);
12int TerminalWindowSize(long *rows, long *cols);
13void auth_encrypt_user(char *);
14void auth_name(unsigned char *, int);
15void auth_printsub(unsigned char *, int, unsigned char *, int);
16void cmdrc(const char *m1, const char *m2);
17void env_init(void);
18int getconnmode(void);
19void init_network(void);
20void init_sys(void);
21void init_telnet(void);
22void init_terminal(void);
23int netflush(void);
24void optionstatus(void);
25int process_rings(int, int, int, int, int, int);
26void quit(void);
27int rlogin_susp(void);
28int send_tncmd(int (*func)(int, int), const char *cmd, const char *name);
29void sendeof(void);
30void sendsusp(void);
31void set_escape_char(char *);
32void tel_leave_binary(int);
33int telrcv(void);
34int tn(int argc, const char *argv[]);
35int ttyflush(int);
36void sendayt(void);
37void ayt_status(int);
38void ayt(int sig);
39
40/* commands.c */
41void cmdtab_init(void);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ptrarray.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ptrarray.h
new file mode 100644
index 0000000..3a5d12f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ptrarray.h
@@ -0,0 +1,92 @@
1//
2// File: ptrarray.h
3// Date: 16-Jul-95
4// Description: Array of pointers
5//
6/*
7 * Copyright (c) 1995 David A. Holland.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Author nor the names of any contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef PTRARRAY_H
36#define PTRARRAY_H
37
38#ifndef assert
39#include <assert.h>
40#endif
41
42#ifndef NULL
43#define NULL 0
44#endif
45
46template <class T>
47class ptrarray {
48 protected:
49 T **v;
50 int n, max;
51 void reallocto(int x) {
52 while (max<x) max += 16;
53 T **q = new T* [max];
54 for (int i=0; i<n; i++) q[i] = v[i];
55 delete []v;
56 v = q;
57 }
58 public:
59 ptrarray() { v=NULL; n=max=0; }
60 ~ptrarray() { delete []v; }
61
62 int num() const { return n; }
63
64 void setsize(int newsize) {
65 if (newsize>max) reallocto(newsize);
66 if (newsize>n) {
67 for (int i=n; i<newsize; i++) v[i] = NULL;
68 }
69 else {
70 // do nothing
71 }
72 n = newsize;
73 }
74
75 T *&operator [] (int ix) const {
76 assert(ix>=0 && ix<n);
77 return v[ix];
78 }
79
80 int add(T *val) {
81 int ix = n;
82 setsize(n+1);
83 v[ix] = val;
84 return ix;
85 }
86
87 void push(T *val) { add(val); }
88
89 void pop() { setsize(n-1); }
90};
91
92#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.cc
new file mode 100644
index 0000000..fdff63e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.cc
@@ -0,0 +1,209 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)ring.c 5.2 (Berkeley) 3/1/91
36 */
37char ring_rcsid[] =
38 "$Id: ring.cc,v 1.22 1997/09/23 11:33:16 dholland Exp $";
39
40/*
41 * This defines a structure for a ring buffer.
42 */
43
44#include <stdio.h>
45#include <stdarg.h>
46#include <assert.h>
47#include "ring.h"
48
49class devnull : public datasink {
50 virtual int write(const char *, int n) { return n; }
51 virtual int writeurg(const char *, int n) { return n; }
52};
53static devnull nullsink_obj;
54datasink *nullsink = &nullsink_obj;
55
56
57
58int ringbuf::init(int sz, datasink *sink, source *src) {
59 buf = new char[sz];
60 size = sz;
61 head = tail = 0;
62 count = 0;
63 marked = -1;
64
65 binding = sink;
66 srcbinding = src;
67
68 return 1;
69}
70
71/////////////////////////////////////////////////// consume //////////////
72
73int ringbuf::gets(char *rbuf, int max) {
74 int i=0, ch;
75 assert(max>0);
76 while (getch(&ch)>0 && i<max-1) rbuf[i++] = ch;
77 rbuf[i]=0;
78 return i;
79}
80
81int ringbuf::getch(int *ch) {
82 int rv = 0;
83 if (count > 0) {
84 if (tail==marked) {
85 rv = 2;
86 marked = -1;
87 }
88 else rv = 1;
89 *ch = (unsigned char) buf[tail++];
90 if (tail>=size) tail -= size;
91 count--;
92 }
93 return rv; /* 0 = no more chars available */
94}
95
96void ringbuf::ungetch(int ch) {
97 int x = tail;
98 x--;
99 if (x<0) x += size;
100 int och = buf[x]; /* avoid sign-extension and other such problems */
101 if ((och&0xff) == (ch&0xff)) {
102 tail = x;
103 count++;
104 }
105 else {
106 //assert(!"Bad ungetch");
107 tail = x;
108 count++;
109 }
110}
111
112/*
113 * Return value:
114 * -2: Significant error occurred.
115 * -1: No useful work done, data waiting to go out.
116 * 0: No data was waiting, so nothing was done.
117 * 1: All waiting data was written out.
118 * n: Some data written, n-1 bytes left.
119 */
120int ringbuf::flush() {
121 assert(binding);
122 assert(count>=0);
123 if (count==0) return 0;
124
125 static int busy=0;
126 if (busy) {
127 return -1;
128 }
129 busy=1;
130
131 /* should always be true */
132 assert(((size+head-tail)%size)==count);
133
134 while (count > 0) {
135 int bot = tail;
136 int top = head;
137 if (top < bot) top = size;
138 if (marked > bot) top = marked;
139 assert(top-bot > 0 && top-bot <= count);
140
141 int n;
142 if (marked==bot) n = binding->writeurg(buf+bot, top-bot);
143 else n = binding->write(buf+bot, top-bot);
144 if (n < 0) { busy=0; return -2; }
145 else if (n==0) { busy=0; return -1; }
146
147 if (marked==bot) marked = -1;
148 tail += n;
149 if (tail >= size) tail -= size;
150 count -= n;
151 assert(((size+head-tail)%size)==count);
152
153 if (n > 0 && n < top-bot) { busy=0; return n+1; }
154 /* otherwise (if we wrote all data) loop */
155 }
156 assert(((size+head-tail)%size)==count);
157 busy=0;
158 return 1;
159}
160
161
162/////////////////////////////////////////////////// supply //////////////
163
164void ringbuf::printf(const char *format, ...) {
165 char xbuf[256];
166 va_list ap;
167 va_start(ap, format);
168 int l = vsnprintf(xbuf, sizeof(xbuf), format, ap);
169 va_end(ap);
170 write(xbuf, l);
171}
172
173void ringbuf::write(const char *buffer, int ct) {
174 if (ct > size - count) {
175 // Oops. We're about to overflow our buffer.
176 // In practice this shouldn't ever actually happen.
177 // We could return a short count, but then we'd have to check
178 // and retry every call, which ranges somewhere between painful
179 // and impossible.
180 // Instead, we drop the data on the floor. This should only happen
181 // if (1) the tty hangs, (2) the network hangs while we're trying
182 // to send large volumes of data, or (3) massive internal logic errors.
183 fprintf(stderr, "\n\ntelnet: buffer overflow, losing data, sorry\n");
184 ct = size - count;
185 }
186 for (int i=0; i<ct; i++) {
187 buf[head++] = buffer[i];
188 if (head>=size) head -= size;
189 count++;
190 }
191}
192
193int ringbuf::read_source() {
194 int bot = head;
195 int top = tail-1; /* leave room for an ungetc */
196 if (top<0) top += size;
197 if (top < bot) top = size;
198
199 if (top==bot) return 0;
200
201 int l = srcbinding->read(buf+bot, top-bot);
202 if (l>=0) {
203 head += l;
204 if (head>=size) head -= size;
205 count += l;
206 }
207 if (l==0) l = -1;
208 return l;
209}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.h
new file mode 100644
index 0000000..15d3f3f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.h
@@ -0,0 +1,111 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)ring.h 5.2 (Berkeley) 3/1/91
34 * $Id: ring.h,v 1.13 1996/08/13 08:43:28 dholland Exp $
35 */
36
37class datasink {
38 public:
39 virtual ~datasink() {}
40 virtual int write(const char *buf, int len) = 0;
41 virtual int writeurg(const char *buf, int len) = 0;
42};
43
44/*
45 * This defines a structure for a ring buffer.
46 */
47class ringbuf {
48 public:
49 class source {
50 public:
51 virtual ~source() {}
52 virtual int read(char *buf, int len) = 0;
53 };
54 protected:
55 datasink *binding;
56 source *srcbinding;
57
58 char *buf;
59 int size; /* total size of buffer */
60 int head; /* next input character goes here */
61 int tail; /* next output character comes from here */
62 int count; /* chars presently stored in buffer */
63 // The buffer is empty when head==tail.
64
65 int marked; /* this character is marked */
66
67 public:
68 /////// consume end
69
70 // manual consume
71 int gets(char *buf, int max);
72 int getch(int *ch);
73 void ungetch(int ch);
74 int full_count() {
75 return count;
76 }
77
78 // automatic consume
79 int flush();
80
81 /////// supply end
82
83 // manual supply
84 void putch(char c) { write(&c, 1); }
85 void write(const char *buffer, int ct);
86 void printf(const char *format, ...);
87 int empty_count() { return size - count; }
88
89 // automatic supply
90 int read_source();
91
92 /////// others
93 void clear_mark() { marked = -1; }
94 void set_mark() { marked = head; }
95
96 int init(int size, datasink *sink, source *src);
97
98 datasink *setsink(datasink *nu) {
99 datasink *old = binding;
100 binding = nu;
101 return old;
102 }
103
104};
105
106extern datasink *netsink, *ttysink, *nullsink;
107extern ringbuf::source *netsrc, *ttysrc;
108
109#define NETADD(c) { netoring.putch(c); }
110#define NET2ADD(c1,c2) { NETADD(c1); NETADD(c2); }
111
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.o
new file mode 100644
index 0000000..65d6c92
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/ring.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/sys_bsd.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/sys_bsd.cc
new file mode 100644
index 0000000..63f89e9
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/sys_bsd.cc
@@ -0,0 +1,406 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)sys_bsd.c 5.2 (Berkeley) 3/1/91
36 */
37char bsd_rcsid[] =
38 "$Id: sys_bsd.cc,v 1.24 1999/09/28 16:29:24 dholland Exp $";
39
40/*
41 * The following routines try to encapsulate what is system dependent
42 * (at least between 4.x and dos) which is used in telnet.c.
43 */
44
45#include <fcntl.h>
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/socket.h>
49#include <signal.h>
50#include <errno.h>
51#include <unistd.h>
52#include <stdlib.h>
53#include <sys/ioctl.h>
54#include <arpa/telnet.h>
55
56#include "ring.h"
57
58#include "defines.h"
59#include "externs.h"
60#include "types.h"
61#include "proto.h"
62#include "netlink.h"
63#include "terminal.h"
64
65static fd_set ibits, obits, xbits;
66
67void init_sys(void)
68{
69 tlink_init();
70 FD_ZERO(&ibits);
71 FD_ZERO(&obits);
72 FD_ZERO(&xbits);
73
74 errno = 0;
75}
76
77
78#ifdef KLUDGELINEMODE
79extern int kludgelinemode;
80#endif
81/*
82 * TerminalSpecialChars()
83 *
84 * Look at an input character to see if it is a special character
85 * and decide what to do.
86 *
87 * Output:
88 *
89 * 0 Don't add this character.
90 * 1 Do add this character
91 */
92
93void intp(), sendbrk(), sendabort();
94
95int
96TerminalSpecialChars(int c)
97{
98 void xmitAO(), xmitEL(), xmitEC();
99
100 if (c == termIntChar) {
101 intp();
102 return 0;
103 } else if (c == termQuitChar) {
104#ifdef KLUDGELINEMODE
105 if (kludgelinemode)
106 sendbrk();
107 else
108#endif
109 sendabort();
110 return 0;
111 } else if (c == termEofChar) {
112 if (my_want_state_is_will(TELOPT_LINEMODE)) {
113 sendeof();
114 return 0;
115 }
116 return 1;
117 } else if (c == termSuspChar) {
118 sendsusp();
119 return(0);
120 } else if (c == termFlushChar) {
121 xmitAO(); /* Transmit Abort Output */
122 return 0;
123 } else if (!MODE_LOCAL_CHARS(globalmode)) {
124 if (c == termKillChar) {
125 xmitEL();
126 return 0;
127 } else if (c == termEraseChar) {
128 xmitEC(); /* Transmit Erase Character */
129 return 0;
130 }
131 }
132 return 1;
133}
134
135
136
137cc_t *tcval(int func) {
138 switch(func) {
139 case SLC_IP: return(&termIntChar);
140 case SLC_ABORT: return(&termQuitChar);
141 case SLC_EOF: return(&termEofChar);
142 case SLC_EC: return(&termEraseChar);
143 case SLC_EL: return(&termKillChar);
144 case SLC_XON: return(&termStartChar);
145 case SLC_XOFF: return(&termStopChar);
146 case SLC_FORW1: return(&termForw1Char);
147 case SLC_FORW2: return(&termForw2Char);
148#ifdef VDISCARD
149 case SLC_AO: return(&termFlushChar);
150#endif
151#ifdef VSUSP
152 case SLC_SUSP: return(&termSuspChar);
153#endif
154#ifdef VWERASE
155 case SLC_EW: return(&termWerasChar);
156#endif
157#ifdef VREPRINT
158 case SLC_RP: return(&termRprntChar);
159#endif
160#ifdef VLNEXT
161 case SLC_LNEXT: return(&termLiteralNextChar);
162#endif
163#ifdef VSTATUS
164 case SLC_AYT: return(&termAytChar);
165#endif
166
167 case SLC_SYNCH:
168 case SLC_BRK:
169 case SLC_EOR:
170 default:
171 return NULL;
172 }
173}
174
175#if defined(TN3270)
176void NetSigIO(int fd, int onoff) {
177 ioctl(fd, FIOASYNC, (char *)&onoff); /* hear about input */
178}
179
180void NetSetPgrp(int fd) {
181 int myPid;
182
183 myPid = getpid();
184 fcntl(fd, F_SETOWN, myPid);
185}
186#endif /*defined(TN3270)*/
187
188/*
189 * Various signal handling routines.
190 */
191
192#if 0
193static void deadpeer(int /*sig*/) {
194 setcommandmode();
195 siglongjmp(peerdied, -1);
196}
197
198static void intr(int /*sig*/) {
199 if (localchars) {
200 intp();
201 }
202 else {
203 setcommandmode();
204 siglongjmp(toplevel, -1);
205 }
206}
207
208static void intr2(int /*sig*/) {
209 if (localchars) {
210#ifdef KLUDGELINEMODE
211 if (kludgelinemode)
212 sendbrk();
213 else
214#endif
215 sendabort();
216 return;
217 }
218}
219#endif
220
221#ifdef SIGWINCH
222static void sendwin(int /*sig*/) {
223 if (connected) {
224 sendnaws();
225 }
226}
227#endif
228
229#ifdef SIGINFO
230void ayt(int sig) {
231 (void)sig;
232
233 if (connected)
234 sendayt();
235 else
236 ayt_status(0);
237}
238#endif
239
240void sys_telnet_init(void) {
241#if 0
242 signal(SIGINT, intr);
243 signal(SIGQUIT, intr2);
244 signal(SIGPIPE, deadpeer);
245#endif
246#ifdef SIGWINCH
247 signal(SIGWINCH, sendwin);
248#endif
249#ifdef SIGINFO
250 signal(SIGINFO, ayt);
251#endif
252
253 setconnmode(0);
254
255 nlink.nonblock(1);
256
257#if defined(TN3270)
258 if (noasynchnet == 0) { /* DBX can't handle! */
259 NetSigIO(net, 1);
260 NetSetPgrp(net);
261 }
262#endif /* defined(TN3270) */
263
264 nlink.oobinline();
265}
266
267/*
268 * Process rings -
269 *
270 * This routine tries to fill up/empty our various rings.
271 *
272 * The parameter specifies whether this is a poll operation,
273 * or a block-until-something-happens operation.
274 *
275 * The return value is 1 if something happened, 0 if not.
276 */
277
278int process_rings(int netin, int netout, int netex, int ttyin, int ttyout,
279 int poll /* If 0, then block until something to do */)
280{
281 register int c, maxfd;
282 /* One wants to be a bit careful about setting returnValue
283 * to one, since a one implies we did some useful work,
284 * and therefore probably won't be called to block next
285 * time (TN3270 mode only).
286 */
287 int returnValue = 0;
288 static struct timeval TimeValue = { 0, 0 };
289
290 int net = nlink.getfd();
291 int tin = tlink_getifd();
292 int tout = tlink_getofd();
293
294 if (netout) {
295 FD_SET(net, &obits);
296 }
297 if (ttyout) {
298 FD_SET(tout, &obits);
299 }
300 if (ttyin) {
301 FD_SET(tin, &ibits);
302 }
303 if (netin) {
304 FD_SET(net, &ibits);
305 }
306 if (netex) {
307 FD_SET(net, &xbits);
308 }
309
310 maxfd = net;
311 if (maxfd < tin) maxfd=tin;
312 if (maxfd < tout) maxfd=tout;
313
314 if ((c = select(maxfd+1, &ibits, &obits, &xbits,
315 (poll == 0)? (struct timeval *)0 : &TimeValue)) < 0) {
316 if (c == -1) {
317 /*
318 * we can get EINTR if we are in line mode,
319 * and the user does an escape (TSTP), or
320 * some other signal generator.
321 */
322 if (errno == EINTR) {
323 return 0;
324 }
325#if defined(TN3270)
326 /*
327 * we can get EBADF if we were in transparent
328 * mode, and the transcom process died.
329 */
330 if (errno == EBADF) {
331 /*
332 * zero the bits (even though kernel does it)
333 * to make sure we are selecting on the right
334 * ones.
335 */
336 FD_ZERO(&ibits);
337 FD_ZERO(&obits);
338 FD_ZERO(&xbits);
339 return 0;
340 }
341#endif /* TN3270 */
342 /* I don't like this, does it ever happen? */
343 printf("sleep(5) from telnet, after select\r\n");
344 sleep(5);
345 }
346 return 0;
347 }
348
349 /*
350 * Any urgent data?
351 */
352 if (FD_ISSET(net, &xbits)) {
353 FD_CLR(net, &xbits);
354 SYNCHing = 1;
355 (void) ttyflush(1); /* flush already enqueued data */
356 }
357
358 /*
359 * Should flush output buffers first to make room for new input. --okir
360 */
361 if (FD_ISSET(net, &obits)) {
362 FD_CLR(net, &obits);
363 returnValue |= netflush();
364 }
365 if (FD_ISSET(tout, &obits)) {
366 FD_CLR(tout, &obits);
367 returnValue |= (ttyflush(SYNCHing|flushout) > 0);
368 }
369
370 /*
371 * Something to read from the network...
372 */
373 if (FD_ISSET(net, &ibits)) {
374 /* hacks for systems without SO_OOBINLINE removed */
375
376 FD_CLR(net, &ibits);
377 /* Only call network input routine if there is room. Otherwise
378 * we will try a 0 byte read, which we happily interpret as the
379 * server having dropped the connection...
380 * NB the input routine reserves 1 byte for ungetc.
381 * 12.3.97 --okir */
382 returnValue = 1;
383 if (netiring.empty_count() > 1) {
384 c = netiring.read_source();
385 if (c <= 0)
386 return -1;
387 else if (c == 0)
388 returnValue = 0;
389 }
390 }
391
392 /*
393 * Something to read from the tty...
394 */
395 if (FD_ISSET(tin, &ibits)) {
396 FD_CLR(tin, &ibits);
397 c = ttyiring.read_source();
398 if (c < 0) {
399 return -1;
400 }
401 else if (c==0) returnValue = 0;
402 else returnValue = 1; /* did something useful */
403 }
404
405 return returnValue;
406}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/sys_bsd.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/sys_bsd.o
new file mode 100644
index 0000000..3542c01
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/sys_bsd.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet
new file mode 100644
index 0000000..fb88784
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.1 b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.1
new file mode 100644
index 0000000..543d794
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.1
@@ -0,0 +1,1263 @@
1.\" Copyright (c) 1983, 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" from: @(#)telnet.1 6.16 (Berkeley) 7/27/91
33.\" $Id: telnet.1,v 1.10 1999/12/14 12:53:02 dholland Exp $
34.\"
35.Dd August 15, 1999
36.Dt TELNET 1
37.Os "Linux NetKit (0.16)"
38.Sh NAME
39.Nm telnet
40.Nd user interface to the
41.Tn TELNET
42protocol
43.Sh SYNOPSIS
44.Nm telnet
45.Op Fl 8ELadr
46.Op Fl S Ar tos
47.Op Fl e Ar escapechar
48.Op Fl l Ar user
49.Op Fl n Ar tracefile
50.Oo
51.Ar host
52.Op Ar port
53.Oc
54.Sh DESCRIPTION
55The
56.Nm telnet
57command
58is used for interactive communication with another host using the
59.Tn TELNET
60protocol. It begins in command mode, where it prints a telnet prompt
61("telnet\&> "). If
62.Nm telnet
63is invoked with a
64.Ar host
65argument, it performs an
66.Ic open
67command implicitly; see the description below.
68.Pp
69Options:
70.Bl -tag -width indent
71.It Fl 8
72Request 8-bit operation. This causes an attempt to negotiate the
73.Dv TELNET BINARY
74option for both input and output. By default telnet is not 8-bit
75clean.
76.It Fl E
77Disables the escape character functionality; that is, sets the escape
78character to ``no character''.
79.It Fl L
80Specifies an 8-bit data path on output. This causes the
81.Dv TELNET BINARY
82option to be negotiated on just output.
83.It Fl a
84Attempt automatic login. Currently, this sends the user name via the
85.Ev USER
86variable
87of the
88.Ev ENVIRON
89option if supported by the remote system. The username is retrieved
90via
91.Xr getlogin 3 .
92.It Fl d
93Sets the initial value of the
94.Ic debug
95toggle to
96.Dv TRUE.
97.It Fl r
98Emulate
99.Xr rlogin 1 .
100In this mode, the default escape character is a tilde. Also, the
101interpretation of the escape character is changed: an escape character
102followed by a dot causes
103.Nm telnet
104to disconnect from the remote host. A ^Z instead of a dot suspends
105.Nm telnet ,
106and a ^] (the default
107.Nm telnet
108escape character) generates a normal telnet prompt. These codes are
109accepted only at the beginning of a line.
110.It Fl S Ar tos
111Sets the IP type-of-service (TOS) option for the telnet
112connection to the value
113.Ar tos .
114.It Fl e Ar escapechar
115Sets the escape character to
116.Ar escapechar.
117If no character is supplied, no escape character will be used.
118Entering the escape character while connected causes telnet to drop to
119command mode.
120.It Fl l Ar user
121Specify
122.Ar user
123as the user to log in as on the remote system. This is accomplished by
124sending the specified name as the
125.Dv USER
126environment variable, so it requires that the remote system support the
127.Ev TELNET ENVIRON
128option. This option implies the
129.Fl a
130option, and may also be used with the
131.Ic open
132command.
133.It Fl n Ar tracefile
134Opens
135.Ar tracefile
136for recording trace information.
137See the
138.Ic set tracefile
139command below.
140.It Ar host
141Specifies a host to contact over the network.
142.It Ar port
143Specifies a port number or service name to contact. If not specified,
144the
145.Nm telnet
146port (23) is used.
147.El
148.Pp
149Protocol:
150.Pp
151Once a connection has been opened,
152.Nm telnet
153will attempt to enable the
154.Dv TELNET LINEMODE
155option.
156If this fails, then
157.Nm telnet
158will revert to one of two input modes:
159either \*(Lqcharacter at a time\*(Rq
160or \*(Lqold line by line\*(Rq
161depending on what the remote system supports.
162.Pp
163When
164.Dv LINEMODE
165is enabled, character processing is done on the
166local system, under the control of the remote system. When input
167editing or character echoing is to be disabled, the remote system
168will relay that information. The remote system will also relay
169changes to any special characters that happen on the remote
170system, so that they can take effect on the local system.
171.Pp
172In \*(Lqcharacter at a time\*(Rq mode, most
173text typed is immediately sent to the remote host for processing.
174.Pp
175In \*(Lqold line by line\*(Rq mode, all text is echoed locally,
176and (normally) only completed lines are sent to the remote host.
177The \*(Lqlocal echo character\*(Rq (initially \*(Lq^E\*(Rq) may be used
178to turn off and on the local echo
179(this would mostly be used to enter passwords
180without the password being echoed).
181.Pp
182If the
183.Dv LINEMODE
184option is enabled, or if the
185.Ic localchars
186toggle is
187.Dv TRUE
188(the default for \*(Lqold line by line\*(Lq; see below),
189the user's
190.Ic quit ,
191.Ic intr ,
192and
193.Ic flush
194characters are trapped locally, and sent as
195.Tn TELNET
196protocol sequences to the remote side.
197If
198.Dv LINEMODE
199has ever been enabled, then the user's
200.Ic susp
201and
202.Ic eof
203are also sent as
204.Tn TELNET
205protocol sequences,
206and
207.Ic quit
208is sent as a
209.Dv TELNET ABORT
210instead of
211.Dv BREAK
212There are options (see
213.Ic toggle
214.Ic autoflush
215and
216.Ic toggle
217.Ic autosynch
218below)
219which cause this action to flush subsequent output to the terminal
220(until the remote host acknowledges the
221.Tn TELNET
222sequence) and flush previous terminal input
223(in the case of
224.Ic quit
225and
226.Ic intr ) .
227.Pp
228Commands:
229.Pp
230The following
231.Nm telnet
232commands are available. Unique prefixes are understood as abbreviations.
233.Pp
234.Bl -tag -width "mode type"
235.It Ic auth Ar argument ...
236The
237.Ic auth
238command controls the
239.Dv TELNET AUTHENTICATE
240protocol option. If
241.Nm telnet
242was compiled without authentication, the
243.Ic auth
244command will not be supported.
245Valid arguments are as follows:
246.Bl -tag -width "disable type"
247.It Ic disable Ar type
248Disable the specified type of authentication. To
249obtain a list of available types, use the
250.Ic auth disable \&?
251command.
252.It Ic enable Ar type
253Enable the specified type of authentication. To
254obtain a list of available types, use the
255.Ic auth enable \&?
256command.
257.It Ic status
258List the current status of the various types of
259authentication.
260.El
261.Pp
262Note that the current version of
263.Nm telnet
264does not support authentication.
265.It Ic close
266Close the connection to the remote host, if any, and return to command
267mode.
268.It Ic display Ar argument ...
269Display all, or some, of the
270.Ic set
271and
272.Ic toggle
273values (see below).
274.It Ic encrypt Ar argument ...
275The encrypt command controls the
276.Dv TELNET ENCRYPT
277protocol option. If
278.Nm telnet
279was compiled without encryption, the
280.Ic encrypt
281command will not be supported.
282.Pp
283Valid arguments are as follows:
284.Bl -tag -width Ar
285.It Ic disable Ar type Ic [input|output]
286Disable the specified type of encryption. If you do not specify input
287or output, encryption of both is disabled. To obtain a list of
288available types, use ``encrypt disable \&?''.
289.It Ic enable Ar type Ic [input|output]
290Enable the specified type of encryption. If you do not specify input
291or output, encryption of both is enabled. To obtain a list of
292available types, use ``encrypt enable \&?''.
293.It Ic input
294This is the same as ``encrypt start input''.
295.It Ic -input
296This is the same as ``encrypt stop input''.
297.It Ic output
298This is the same as ``encrypt start output''.
299.It Ic -output
300This is the same as ``encrypt stop output''.
301.It Ic start Ic [input|output]
302Attempt to begin encrypting. If you do not specify input or output,
303encryption of both input and output is started.
304.It Ic status
305Display the current status of the encryption module.
306.It Ic stop Ic [input|output]
307Stop encrypting. If you do not specify input or output, encryption of
308both is stopped.
309.It Ic type Ar type
310Sets the default type of encryption to be used with later ``encrypt start''
311or ``encrypt stop'' commands.
312.El
313.Pp
314Note that the current version of
315.Nm telnet
316does not support encryption.
317.It Ic environ Ar arguments...
318The
319.Ic environ
320command is used to propagate environment variables across the
321.Nm telnet
322link using the
323.Dv TELNET ENVIRON
324protocol option.
325All variables exported from the shell are defined, but only the
326.Ev DISPLAY
327and
328.Ev PRINTER
329variables are marked to be sent by default. The
330.Ev USER
331variable is marked to be sent if the
332.Fl a
333or
334.Fl l
335command-line options were used.
336.Pp
337Valid arguments for the
338.Ic environ
339command are:
340.Bl -tag -width Fl
341.It Ic define Ar variable value
342Define the variable
343.Ar variable
344to have a value of
345.Ar value.
346Any variables defined by this command are automatically marked for
347propagation (``exported'').
348The
349.Ar value
350may be enclosed in single or double quotes so
351that tabs and spaces may be included.
352.It Ic undefine Ar variable
353Remove any existing definition of
354.Ar variable .
355.It Ic export Ar variable
356Mark the specified variable for propagation to the remote host.
357.It Ic unexport Ar variable
358Do not mark the specified variable for propagation to the remote
359host. The remote host may still ask explicitly for variables that are
360not exported.
361.It Ic list
362List the current set of environment variables.
363Those marked with a
364.Cm *
365will be propagated to the remote host. The remote host may still ask
366explicitly for the rest.
367.It Ic \&?
368Prints out help information for the
369.Ic environ
370command.
371.El
372.It Ic logout
373Send the
374.Dv TELNET LOGOUT
375protocol option to the remote host.
376This command is similar to a
377.Ic close
378command. If the remote host does not support the
379.Dv LOGOUT
380option, nothing happens. But if it does, this command should cause it
381to close the connection. If the remote side also supports the concept
382of suspending a user's session for later reattachment, the logout
383command indicates that the session should be terminated immediately.
384.It Ic mode Ar type
385.Ar Type
386is one of several options, depending on the state of the session.
387.Tn Telnet
388asks the remote host to go into the requested mode. If the remote host
389says it can, that mode takes effect.
390.Bl -tag -width Ar
391.It Ic character
392Disable the
393.Dv TELNET LINEMODE
394option, or, if the remote side does not understand the
395.Dv LINEMODE
396option, then enter \*(Lqcharacter at a time\*(Lq mode.
397.It Ic line
398Enable the
399.Dv TELNET LINEMODE
400option, or, if the remote side does not understand the
401.Dv LINEMODE
402option, then attempt to enter \*(Lqold-line-by-line\*(Lq mode.
403.It Ic isig Pq Ic \-isig
404Attempt to enable (disable) the
405.Dv TRAPSIG
406mode of the
407.Dv LINEMODE
408option.
409This requires that the
410.Dv LINEMODE
411option be enabled.
412.It Ic edit Pq Ic \-edit
413Attempt to enable (disable) the
414.Dv EDIT
415mode of the
416.Dv LINEMODE
417option.
418This requires that the
419.Dv LINEMODE
420option be enabled.
421.It Ic softtabs Pq Ic \-softtabs
422Attempt to enable (disable) the
423.Dv SOFT_TAB
424mode of the
425.Dv LINEMODE
426option.
427This requires that the
428.Dv LINEMODE
429option be enabled.
430.It Ic litecho Pq Ic \-litecho
431Attempt to enable (disable) the
432.Dv LIT_ECHO
433mode of the
434.Dv LINEMODE
435option.
436This requires that the
437.Dv LINEMODE
438option be enabled.
439.It Ic \&?
440Prints out help information for the
441.Ic mode
442command.
443.El
444.It Xo
445.Ic open Ar host
446.Oo Op Fl l
447.Ar user
448.Oc Ns Oo Fl
449.Ar port Oc
450.Xc
451Open a connection to the named host. If no port number is specified,
452.Nm telnet
453will attempt to contact a
454.Tn telnet
455daemon at the standard port (23).
456The host specification may be a host name or IP address.
457The
458.Fl l
459option may be used to specify a user name to be passed to the remote
460system, like the
461.Fl l
462command-line option.
463.Pp
464When connecting to ports other than the
465.Nm telnet
466port,
467.Nm telnet
468does not attempt
469.Tn telnet
470protocol negotiations. This makes it possible to connect to services
471that do not support the
472.Tn telnet
473protocol without making a mess. Protocol negotiation can be forced by
474placing a dash before the port number.
475.Pp
476After establishing a connection, any commands associated with the
477remote host in the user's
478.Pa .telnetrc
479file are executed.
480.Pp
481The format of the .telnetrc file is as follows: Lines beginning with a
482#, and blank lines, are ignored. The rest of the file should consist
483of hostnames and sequences of
484.Nm telnet
485commands to use with that host. Commands should be one per line,
486indented by whitespace; lines beginning without whitespace are
487interpreted as hostnames. Upon connecting to a particular host, the
488commands associated with that host are executed.
489.It Ic quit
490Close any open session and exit
491.Nm telnet .
492An end of file condition on input, when in command mode, will trigger
493this operation as well.
494.It Ic send Ar arguments
495Send one or more special
496.Tn telnet
497protocol character sequences to the remote host. The following are
498the codes which may be specified (more than one may be used in one
499command):
500.Pp
501.Bl -tag -width escape
502.It Ic abort
503Sends the
504.Dv TELNET ABORT
505(Abort Processes) sequence.
506.It Ic ao
507Sends the
508.Dv TELNET AO
509(Abort Output) sequence, which should cause the remote system to flush
510all output
511.Em from
512the remote system
513.Em to
514the user's terminal.
515.It Ic ayt
516Sends the
517.Dv TELNET AYT
518(Are You There?) sequence, to which the remote system may or may not
519choose to respond.
520.It Ic brk
521Sends the
522.Dv TELNET BRK
523(Break) sequence, which may have significance to the remote
524system.
525.It Ic ec
526Sends the
527.Dv TELNET EC
528(Erase Character)
529sequence, which should cause the remote system to erase the last character
530entered.
531.It Ic el
532Sends the
533.Dv TELNET EL
534(Erase Line)
535sequence, which should cause the remote system to erase the line currently
536being entered.
537.It Ic eof
538Sends the
539.Dv TELNET EOF
540(End Of File)
541sequence.
542.It Ic eor
543Sends the
544.Dv TELNET EOR
545(End of Record)
546sequence.
547.It Ic escape
548Sends the current
549.Nm telnet
550escape character.
551.It Ic ga
552Sends the
553.Dv TELNET GA
554(Go Ahead)
555sequence, which likely has no significance to the remote system.
556.It Ic getstatus
557If the remote side supports the
558.Dv TELNET STATUS
559command,
560.Ic getstatus
561will send the subnegotiation to request that the server send
562its current option status.
563.It Ic ip
564Sends the
565.Dv TELNET IP
566(Interrupt Process) sequence, which should cause the remote
567system to abort the currently running process.
568.It Ic nop
569Sends the
570.Dv TELNET NOP
571(No Operation)
572sequence.
573.It Ic susp
574Sends the
575.Dv TELNET SUSP
576(Suspend Process)
577sequence.
578.It Ic synch
579Sends the
580.Dv TELNET SYNCH
581sequence.
582This sequence causes the remote system to discard all previously typed
583(but not yet read) input.
584This sequence is sent as
585.Tn TCP
586urgent
587data (and may not work if the remote system is a
588.Bx 4.2
589system -- if
590it doesn't work, a lower case \*(Lqr\*(Rq may be echoed on the terminal).
591.It Ic do Ar cmd
592.It Ic dont Ar cmd
593.It Ic will Ar cmd
594.It Ic wont Ar cmd
595Sends the
596.Dv TELNET DO
597.Ar cmd
598sequence.
599.Ar cmd
600can be either a decimal number between 0 and 255,
601or a symbolic name for a specific
602.Dv TELNET
603command.
604.Ar cmd
605can also be either
606.Ic help
607or
608.Ic \&?
609to print out help information, including
610a list of known symbolic names.
611.It Ic \&?
612Prints out help information for the
613.Ic send
614command.
615.El
616.It Ic set Ar argument value
617.It Ic unset Ar argument value
618The
619.Ic set
620command will set any one of a number of
621.Nm telnet
622variables to a specific value or to
623.Dv TRUE .
624The special value
625.Ic off
626turns off the function associated with
627the variable. This is equivalent to using the
628.Ic unset
629command.
630The
631.Ic unset
632command will disable or set to
633.Dv FALSE
634any of the specified variables.
635The values of variables may be interrogated with the
636.Ic display
637command.
638The variables which may be set or unset, but not toggled, are
639listed here. In addition, any of the variables for the
640.Ic toggle
641command may be explicitly set or unset.
642.Bl -tag -width escape
643.It Ic ayt
644If
645.Tn telnet
646is in localchars mode, or
647.Dv LINEMODE
648is enabled, and the status character is typed, a
649.Dv TELNET AYT
650sequence is sent to the remote host. The initial value for the "Are
651You There" character is the terminal's status character.
652.It Ic echo
653This is the value (initially \*(Lq^E\*(Rq) which, when in
654\*(Lqline by line\*(Rq mode, toggles between doing local echoing
655of entered characters (for normal processing), and suppressing
656echoing of entered characters (for entering, say, a password).
657.It Ic eof
658If
659.Nm telnet
660is operating in
661.Dv LINEMODE
662or \*(Lqold line by line\*(Rq mode, entering this character
663as the first character on a line will cause this character to be
664sent to the remote system.
665The initial value of the eof character is taken to be the terminal's
666.Ic eof
667character.
668.It Ic erase
669If
670.Nm telnet
671is in
672.Ic localchars
673mode (see
674.Ic toggle
675.Ic localchars
676below),
677.Sy and
678if
679.Nm telnet
680is operating in \*(Lqcharacter at a time\*(Rq mode, then when this
681character is typed, a
682.Dv TELNET EC
683sequence (see
684.Ic send
685.Ic ec
686above)
687is sent to the remote system.
688The initial value for the erase character is taken to be
689the terminal's
690.Ic erase
691character.
692.It Ic escape
693This is the
694.Nm telnet
695escape character (initially \*(Lq^[\*(Rq) which causes entry
696into
697.Nm telnet
698command mode (when connected to a remote system).
699.It Ic flushoutput
700If
701.Nm telnet
702is in
703.Ic localchars
704mode (see
705.Ic toggle
706.Ic localchars
707below)
708and the
709.Ic flushoutput
710character is typed, a
711.Dv TELNET AO
712sequence (see
713.Ic send
714.Ic ao
715above)
716is sent to the remote host.
717The initial value for the flush character is taken to be
718the terminal's
719.Ic flush
720character.
721.It Ic forw1
722.It Ic forw2
723If
724.Tn TELNET
725is operating in
726.Dv LINEMODE ,
727these are the
728characters that, when typed, cause partial lines to be
729forwarded to the remote system. The initial value for
730the forwarding characters are taken from the terminal's
731eol and eol2 characters.
732.It Ic interrupt
733If
734.Nm telnet
735is in
736.Ic localchars
737mode (see
738.Ic toggle
739.Ic localchars
740below)
741and the
742.Ic interrupt
743character is typed, a
744.Dv TELNET IP
745sequence (see
746.Ic send
747.Ic ip
748above)
749is sent to the remote host.
750The initial value for the interrupt character is taken to be
751the terminal's
752.Ic intr
753character.
754.It Ic kill
755If
756.Nm telnet
757is in
758.Ic localchars
759mode (see
760.Ic toggle
761.Ic localchars
762below),
763.Ic and
764if
765.Nm telnet
766is operating in \*(Lqcharacter at a time\*(Rq mode, then when this
767character is typed, a
768.Dv TELNET EL
769sequence (see
770.Ic send
771.Ic el
772above)
773is sent to the remote system.
774The initial value for the kill character is taken to be
775the terminal's
776.Ic kill
777character.
778.It Ic lnext
779If
780.Nm telnet
781is operating in
782.Dv LINEMODE
783or \*(Lqold line by line\*(Lq mode, then this character is taken to
784be the terminal's
785.Ic lnext
786character.
787The initial value for the lnext character is taken to be
788the terminal's
789.Ic lnext
790character.
791.It Ic quit
792If
793.Nm telnet
794is in
795.Ic localchars
796mode (see
797.Ic toggle
798.Ic localchars
799below)
800and the
801.Ic quit
802character is typed, a
803.Dv TELNET BRK
804sequence (see
805.Ic send
806.Ic brk
807above)
808is sent to the remote host.
809The initial value for the quit character is taken to be
810the terminal's
811.Ic quit
812character.
813.It Ic reprint
814If
815.Nm telnet
816is operating in
817.Dv LINEMODE
818or \*(Lqold line by line\*(Lq mode, then this character is taken to
819be the terminal's
820.Ic reprint
821character.
822The initial value for the reprint character is taken to be
823the terminal's
824.Ic reprint
825character.
826.It Ic rlogin
827This is the rlogin mode escape character. Setting it enables rlogin
828mode, as with the
829.Ar r
830command-line option (q.v.)
831.It Ic start
832If the
833.Dv TELNET TOGGLE-FLOW-CONTROL
834option has been enabled,
835then this character is taken to
836be the terminal's
837.Ic start
838character.
839The initial value for the kill character is taken to be
840the terminal's
841.Ic start
842character.
843.It Ic stop
844If the
845.Dv TELNET TOGGLE-FLOW-CONTROL
846option has been enabled,
847then this character is taken to
848be the terminal's
849.Ic stop
850character.
851The initial value for the kill character is taken to be
852the terminal's
853.Ic stop
854character.
855.It Ic susp
856If
857.Nm telnet
858is in
859.Ic localchars
860mode, or
861.Dv LINEMODE
862is enabled, and the
863.Ic suspend
864character is typed, a
865.Dv TELNET SUSP
866sequence (see
867.Ic send
868.Ic susp
869above)
870is sent to the remote host.
871The initial value for the suspend character is taken to be
872the terminal's
873.Ic suspend
874character.
875.It Ic tracefile
876This is the file to which the output, caused by
877.Ic netdata
878or
879.Ic option
880tracing being
881.Dv TRUE ,
882will be written. If it is set to
883.Dq Fl ,
884then tracing information will be written to standard output (the default).
885.It Ic worderase
886If
887.Nm telnet
888is operating in
889.Dv LINEMODE
890or \*(Lqold line by line\*(Lq mode, then this character is taken to
891be the terminal's
892.Ic worderase
893character.
894The initial value for the worderase character is taken to be
895the terminal's
896.Ic worderase
897character.
898.It Ic \&?
899Displays the legal
900.Ic set
901.Pq Ic unset
902commands.
903.El
904.It Ic slc Ar state
905The
906.Ic slc
907command (Set Local Characters) is used to set
908or change the state of the the special
909characters when the
910.Dv TELNET LINEMODE
911option has
912been enabled. Special characters are characters that get
913mapped to
914.Tn TELNET
915commands sequences (like
916.Ic ip
917or
918.Ic quit )
919or line editing characters (like
920.Ic erase
921and
922.Ic kill ) .
923By default, the local special characters are exported.
924.Bl -tag -width Fl
925.It Ic check
926Verify the current settings for the current special characters.
927The remote side is requested to send all the current special
928character settings, and if there are any discrepancies with
929the local side, the local side will switch to the remote value.
930.It Ic export
931Switch to the local defaults for the special characters. The
932local default characters are those of the local terminal at
933the time when
934.Nm telnet
935was started.
936.It Ic import
937Switch to the remote defaults for the special characters.
938The remote default characters are those of the remote system
939at the time when the
940.Tn TELNET
941connection was established.
942.It Ic \&?
943Prints out help information for the
944.Ic slc
945command.
946.El
947.It Ic status
948Show the current status of
949.Nm telnet .
950This includes the name of the remote host, if any, as well as the
951current mode.
952.It Ic toggle Ar arguments ...
953Toggle (between
954.Dv TRUE
955and
956.Dv FALSE )
957various flags that control how
958.Nm telnet
959responds to events.
960These flags may be set explicitly to
961.Dv TRUE
962or
963.Dv FALSE
964using the
965.Ic set
966and
967.Ic unset
968commands.
969More than one flag may be toggled at once.
970The state of these flags may be examined with the
971.Ic display
972command.
973Valid flags are:
974.Bl -tag -width Ar
975.It Ic authdebug
976Turns on debugging for the authentication code. This flag only exists
977if authentication support is enabled.
978.It Ic autoflush
979If
980.Ic autoflush
981and
982.Ic localchars
983are both
984.Dv TRUE ,
985then when the
986.Ic ao ,
987or
988.Ic quit
989characters are recognized (and transformed into
990.Tn TELNET
991sequences; see
992.Ic set
993above for details),
994.Nm telnet
995refuses to display any data on the user's terminal
996until the remote system acknowledges (via a
997.Dv TELNET TIMING MARK
998option)
999that it has processed those
1000.Tn TELNET
1001sequences.
1002The initial value for this toggle is
1003.Dv TRUE
1004if the terminal user had not
1005done an "stty noflsh", otherwise
1006.Dv FALSE
1007(see
1008.Xr stty 1 ) .
1009.It Ic autodecrypt
1010When the
1011.Dv TELNET ENCRYPT
1012option is negotiated, by
1013default the actual encryption (decryption) of the data
1014stream does not start automatically. The autoencrypt
1015(autodecrypt) command states that encryption of the
1016output (input) stream should be enabled as soon as
1017possible.
1018.Pp
1019Note that this flag exists only if encryption support is enabled.
1020.It Ic autologin
1021If the remote side supports the
1022.Dv TELNET AUTHENTICATION
1023option,
1024.Tn telnet
1025attempts to use it to perform automatic authentication. If the
1026.Dv TELNET AUTHENTICATION
1027option is not supported, the user's login name is propagated using the
1028.Dv TELNET ENVIRON
1029option.
1030Setting this flag is the same as specifying the
1031.Ar a
1032option to the
1033.Ic open
1034command or on the command line.
1035.It Ic autosynch
1036If
1037.Ic autosynch
1038and
1039.Ic localchars
1040are both
1041.Dv TRUE ,
1042then when either the
1043.Ic intr
1044or
1045.Ic quit
1046characters is typed (see
1047.Ic set
1048above for descriptions of the
1049.Ic intr
1050and
1051.Ic quit
1052characters), the resulting
1053.Tn telnet
1054sequence sent is followed by the
1055.Dv TELNET SYNCH
1056sequence.
1057This procedure
1058.Ic should
1059cause the remote system to begin throwing away all previously
1060typed input until both of the
1061.Tn telnet
1062sequences have been read and acted upon.
1063The initial value of this toggle is
1064.Dv FALSE .
1065.It Ic binary
1066Enable or disable the
1067.Dv TELNET BINARY
1068option on both input and output.
1069.It Ic inbinary
1070Enable or disable the
1071.Dv TELNET BINARY
1072option on input.
1073.It Ic outbinary
1074Enable or disable the
1075.Dv TELNET BINARY
1076option on output.
1077.It Ic crlf
1078If this is
1079.Dv TRUE ,
1080then carriage returns will be sent as
1081.Li <CR><LF> .
1082If this is
1083.Dv FALSE ,
1084then carriage returns will be send as
1085.Li <CR><NUL> .
1086The initial value for this toggle is
1087.Dv FALSE .
1088.It Ic crmod
1089Toggle carriage return mode.
1090When this mode is enabled, most carriage return characters received from
1091the remote host will be mapped into a carriage return followed by
1092a line feed.
1093This mode does not affect those characters typed by the user, only
1094those received from the remote host.
1095This mode is not very useful unless the remote host
1096only sends carriage return, but never line feed.
1097The initial value for this toggle is
1098.Dv FALSE .
1099.It Ic debug
1100Toggles socket level debugging (useful only to the
1101.Ic super user ) .
1102The initial value for this toggle is
1103.Dv FALSE .
1104.It Ic encdebug
1105Turns on debugging information for the encryption code.
1106Note that this flag only exists if encryption support is available.
1107.It Ic localchars
1108If this is
1109.Dv TRUE ,
1110then the
1111.Ic flush ,
1112.Ic interrupt ,
1113.Ic quit ,
1114.Ic erase ,
1115and
1116.Ic kill
1117characters (see
1118.Ic set
1119above) are recognized locally, and transformed into (hopefully) appropriate
1120.Tn TELNET
1121control sequences
1122(respectively
1123.Ic ao ,
1124.Ic ip ,
1125.Ic brk ,
1126.Ic ec ,
1127and
1128.Ic el ;
1129see
1130.Ic send
1131above).
1132The initial value for this toggle is
1133.Dv TRUE
1134in \*(Lqold line by line\*(Rq mode,
1135and
1136.Dv FALSE
1137in \*(Lqcharacter at a time\*(Rq mode.
1138When the
1139.Dv LINEMODE
1140option is enabled, the value of
1141.Ic localchars
1142is ignored, and assumed to always be
1143.Dv TRUE .
1144If
1145.Dv LINEMODE
1146has ever been enabled, then
1147.Ic quit
1148is sent as
1149.Ic abort ,
1150and
1151.Ic eof and
1152.B suspend
1153are sent as
1154.Ic eof and
1155.Ic susp ,
1156see
1157.Ic send
1158above).
1159.It Ic netdata
1160Toggles the display of all network data (in hexadecimal format).
1161The initial value for this toggle is
1162.Dv FALSE .
1163.It Ic options
1164Toggles the display of some internal
1165.Nm telnet
1166protocol processing (having to do with
1167.Tn telnet
1168options).
1169The initial value for this toggle is
1170.Dv FALSE .
1171.It Ic prettydump
1172When the
1173.Ic netdata
1174toggle is enabled, if
1175.Ic prettydump
1176is enabled the output from the
1177.Ic netdata
1178command will be formatted in a more user-readable format.
1179Spaces are put between each character in the output, and the
1180beginning of
1181.Tn telnet
1182escape sequences are preceded by a '*' to aid in locating them.
1183.It Ic skiprc
1184When the skiprc toggle is
1185.Dv TRUE ,
1186.Tn telnet
1187does not read the
1188.Pa \&.telnetrc
1189file. The initial value for this toggle is
1190.Dv FALSE.
1191.It Ic termdata
1192Toggles the display of all terminal data (in hexadecimal format).
1193The initial value for this toggle is
1194.Dv FALSE .
1195.It Ic verbose_encrypt
1196When the
1197.Ic verbose_encrypt
1198toggle is
1199.Dv TRUE ,
1200.Tn TELNET
1201prints out a message each time encryption is enabled or
1202disabled. The initial value for this toggle is
1203.Dv FALSE.
1204This flag only exists if encryption support is available.
1205.It Ic \&?
1206Displays the legal
1207.Ic toggle
1208commands.
1209.El
1210.It Ic z
1211Suspend
1212.Nm telnet .
1213This command only works when the user is using the
1214.Xr csh 1 .
1215.It Ic \&! Op Ar command
1216Execute a single command in a subshell on the local
1217system. If
1218.Ic command
1219is omitted, then an interactive subshell is invoked.
1220.It Ic \&? Op Ar command
1221Get help. With no arguments,
1222.Nm telnet
1223prints a help summary.
1224If a command is specified,
1225.Nm telnet
1226will print the help information for just that command.
1227.El
1228.Sh ENVIRONMENT
1229.Nm Telnet
1230uses at least the
1231.Ev HOME ,
1232.Ev SHELL ,
1233.Ev DISPLAY ,
1234and
1235.Ev TERM
1236environment variables.
1237Other environment variables may be propagated
1238to the other side via the
1239.Dv TELNET ENVIRON
1240option.
1241.Sh FILES
1242.Bl -tag -width ~/.telnetrc -compact
1243.It Pa ~/.telnetrc
1244user customized telnet startup values
1245.El
1246.Sh HISTORY
1247The
1248.Nm Telnet
1249command appeared in
1250.Bx 4.2 .
1251.Sh NOTES
1252.Pp
1253On some remote systems, echo has to be turned off manually when in
1254\*(Lqold line by line\*(Rq mode.
1255.Pp
1256In \*(Lqold line by line\*(Rq mode or
1257.Dv LINEMODE
1258the terminal's
1259.Ic eof
1260character is only recognized (and sent to the remote system)
1261when it is the first character on a line.
1262.Sh BUGS
1263The source code is not comprehensible.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.cc
new file mode 100644
index 0000000..7a68259
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.cc
@@ -0,0 +1,2069 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)telnet.c 5.53 (Berkeley) 3/22/91
36 */
37char telnet_rcsid[] =
38"$Id: telnet.cc,v 1.34 1999/08/19 09:34:15 dholland Exp $";
39
40#include <string.h>
41#include <sys/types.h>
42#include <stdlib.h>
43#include <unistd.h>
44#include <signal.h>
45
46#include <arpa/telnet.h>
47
48#include <ctype.h>
49
50#include "ring.h"
51#include "defines.h"
52#include "externs.h"
53#include "types.h"
54#include "environ.h"
55#include "proto.h"
56#include "ptrarray.h"
57#include "netlink.h"
58#include "terminal.h"
59
60/*
61 * Due to lossage in some linux distributions/kernel releases/libc versions
62 * this must come *after* termios.h (which is included in externs.h)
63 */
64#include <termcap.h>
65
66#ifdef USE_NCURSES
67#include <term.h>
68#endif
69
70
71#define strip(x) ((x)&0x7f)
72
73static unsigned char subbuffer[SUBBUFSIZE];
74static unsigned char *subpointer, *subend; /* buffer for sub-options */
75#define SB_CLEAR() subpointer = subbuffer;
76#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
77#define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
78 *subpointer++ = (c); \
79 }
80
81#define SB_GET() (*subpointer++)
82#define SB_PEEK() (*subpointer)
83#define SB_EOF() (subpointer >= subend)
84#define SB_LEN() (subend - subpointer)
85
86char options[256]; /* The combined options */
87char do_dont_resp[256];
88char will_wont_resp[256];
89
90int
91eight = 0,
92 autologin = 0, /* Autologin anyone? */
93 skiprc = 0,
94 connected,
95 showoptions,
96 In3270, /* Are we in 3270 mode? */
97 ISend, /* trying to send network data in */
98 debug = 0,
99 crmod,
100 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
101#if defined(TN3270)
102 noasynchtty = 0,/* User specified "-noasynch" on command line */
103 noasynchnet = 0,/* User specified "-noasynch" on command line */
104 askedSGA = 0, /* We have talked about suppress go ahead */
105#endif /* defined(TN3270) */
106 telnetport,
107 SYNCHing, /* we are in TELNET SYNCH mode */
108 flushout, /* flush output */
109 autoflush = 0, /* flush output when interrupting? */
110 autosynch, /* send interrupt characters with SYNCH? */
111 localflow, /* we handle flow control locally */
112 localchars, /* we recognize interrupt/quit */
113 donelclchars, /* the user has set "localchars" */
114 donebinarytoggle, /* the user has put us in binary */
115 dontlecho, /* do we suppress local echoing right now? */
116 globalmode;
117
118char *prompt = 0;
119
120cc_t escapechar;
121cc_t rlogin;
122#ifdef KLUDGELINEMODE
123cc_t echoc;
124#endif
125
126/*
127 * Telnet receiver states for fsm
128 */
129#define TS_DATA 0
130#define TS_IAC 1
131#define TS_WILL 2
132#define TS_WONT 3
133#define TS_DO 4
134#define TS_DONT 5
135#define TS_CR 6
136#define TS_SB 7 /* sub-option collection */
137#define TS_SE 8 /* looking for sub-option end */
138
139static int telrcv_state;
140
141sigjmp_buf toplevel;
142sigjmp_buf peerdied;
143
144int flushline;
145int linemode;
146
147#ifdef KLUDGELINEMODE
148int kludgelinemode = 1;
149#endif
150
151/*
152 * The following are some clocks used to decide how to interpret
153 * the relationship between various variables.
154 */
155
156Clocks clocks;
157
158#ifdef notdef
159Modelist modelist[] = {
160 { "telnet command mode", COMMAND_LINE },
161 { "character-at-a-time mode", 0 },
162 { "character-at-a-time mode (local echo)", LOCAL_ECHO|LOCAL_CHARS },
163 { "line-by-line mode (remote echo)", LINE | LOCAL_CHARS },
164 { "line-by-line mode", LINE | LOCAL_ECHO | LOCAL_CHARS },
165 { "line-by-line mode (local echoing suppressed)", LINE | LOCAL_CHARS },
166 { "3270 mode", 0 },
167};
168#endif
169
170/*
171 * Initialize telnet environment.
172 */
173void init_telnet(void) {
174 env_init();
175 cmdtab_init();
176
177 SB_CLEAR();
178 memset(options, 0, sizeof(options));
179
180 connected = In3270 = ISend = localflow = donebinarytoggle = 0;
181
182 SYNCHing = 0;
183
184 /* Don't change NetTrace */
185
186 escapechar = CONTROL(']');
187 rlogin = _POSIX_VDISABLE;
188#ifdef KLUDGELINEMODE
189 echoc = CONTROL('E');
190#endif
191
192 flushline = 1;
193 telrcv_state = TS_DATA;
194}
195
196
197#if 0
198#include <stdarg.h>
199
200static void printring(Ring *ring, const char *format, ...) {
201 va_list ap;
202 char buffer[100]; /* where things go */
203 char *ptr;
204 char *string;
205 int i;
206
207 va_start(ap, format);
208
209 ptr = buffer;
210
211 while ((i = *format++) != 0) {
212 if (i == '%') {
213 i = *format++;
214 switch (i) {
215 case 'c':
216 *ptr++ = va_arg(ap, int);
217 break;
218 case 's':
219 string = va_arg(ap, char *);
220 ring->supply_data(buffer, ptr-buffer);
221 ring->supply_data(string, strlen(string));
222 ptr = buffer;
223 break;
224 case 0:
225 ExitString("printring: trailing %%.\n", 1);
226 /*NOTREACHED*/
227 default:
228 ExitString("printring: unknown format character.\n", 1);
229 /*NOTREACHED*/
230 }
231 }
232 else {
233 *ptr++ = i;
234 }
235 }
236 ring->supply_data(buffer, ptr-buffer);
237}
238#endif
239
240/*
241 * These routines are in charge of sending option negotiations
242 * to the other side.
243 *
244 * The basic idea is that we send the negotiation if either side
245 * is in disagreement as to what the current state should be.
246 */
247
248void send_do(int c, int init) {
249 if (init) {
250 if (((do_dont_resp[c] == 0) && my_state_is_do(c)) ||
251 my_want_state_is_do(c))
252 return;
253 set_my_want_state_do(c);
254 do_dont_resp[c]++;
255 }
256 NET2ADD(IAC, DO);
257 NETADD(c);
258 printoption("SENT", DO, c);
259}
260
261void send_dont(int c, int init) {
262 if (init) {
263 if (((do_dont_resp[c] == 0) && my_state_is_dont(c)) ||
264 my_want_state_is_dont(c))
265 return;
266 set_my_want_state_dont(c);
267 do_dont_resp[c]++;
268 }
269 NET2ADD(IAC, DONT);
270 NETADD(c);
271 printoption("SENT", DONT, c);
272}
273
274void send_will(int c, int init) {
275 if (init) {
276 if (((will_wont_resp[c] == 0) && my_state_is_will(c)) ||
277 my_want_state_is_will(c))
278 return;
279 set_my_want_state_will(c);
280 will_wont_resp[c]++;
281 }
282 NET2ADD(IAC, WILL);
283 NETADD(c);
284 printoption("SENT", WILL, c);
285}
286
287void send_wont(int c, int init) {
288 if (init) {
289 if (((will_wont_resp[c] == 0) && my_state_is_wont(c)) ||
290 my_want_state_is_wont(c))
291 return;
292 set_my_want_state_wont(c);
293 will_wont_resp[c]++;
294 }
295 NET2ADD(IAC, WONT);
296 NETADD(c);
297 printoption("SENT", WONT, c);
298}
299
300
301void willoption(int option) {
302 int new_state_ok = 0;
303
304 if (do_dont_resp[option]) {
305 --do_dont_resp[option];
306 if (do_dont_resp[option] && my_state_is_do(option))
307 --do_dont_resp[option];
308 }
309
310 if ((do_dont_resp[option] == 0) && my_want_state_is_dont(option)) {
311 switch (option) {
312 case TELOPT_ECHO:
313#if defined(TN3270)
314 /*
315 * The following is a pain in the rear-end.
316 * Various IBM servers (some versions of Wiscnet,
317 * possibly Fibronics/Spartacus, and who knows who
318 * else) will NOT allow us to send "DO SGA" too early
319 * in the setup proceedings. On the other hand,
320 * 4.2 servers (telnetd) won't set SGA correctly.
321 * So, we are stuck. Empirically (but, based on
322 * a VERY small sample), the IBM servers don't send
323 * out anything about ECHO, so we postpone our sending
324 * "DO SGA" until we see "WILL ECHO" (which 4.2 servers
325 * DO send).
326 */
327 {
328 if (askedSGA == 0) {
329 askedSGA = 1;
330 if (my_want_state_is_dont(TELOPT_SGA))
331 send_do(TELOPT_SGA, 1);
332 }
333 }
334 /* Fall through */
335 case TELOPT_EOR:
336#endif /* TN3270 */
337 case TELOPT_BINARY:
338 case TELOPT_SGA:
339 settimer(modenegotiated);
340 /* FALL THROUGH */
341 case TELOPT_STATUS:
342 new_state_ok = 1;
343 break;
344
345 case TELOPT_TM:
346 if (flushout)
347 flushout = 0;
348 /*
349 * Special case for TM. If we get back a WILL,
350 * pretend we got back a WONT.
351 */
352 set_my_want_state_dont(option);
353 set_my_state_dont(option);
354 return; /* Never reply to TM will's/wont's */
355
356 case TELOPT_LINEMODE:
357 default:
358 break;
359 }
360
361 if (new_state_ok) {
362 set_my_want_state_do(option);
363 send_do(option, 0);
364 setconnmode(0); /* possibly set new tty mode */
365 }
366 else {
367 do_dont_resp[option]++;
368 send_dont(option, 0);
369 }
370 }
371 set_my_state_do(option);
372}
373
374void wontoption(int option) {
375 if (do_dont_resp[option]) {
376 --do_dont_resp[option];
377 if (do_dont_resp[option] && my_state_is_dont(option))
378 --do_dont_resp[option];
379 }
380
381 if ((do_dont_resp[option] == 0) && my_want_state_is_do(option)) {
382
383 switch (option) {
384
385#ifdef KLUDGELINEMODE
386 case TELOPT_SGA:
387 if (!kludgelinemode)
388 break;
389 /* FALL THROUGH */
390#endif
391 case TELOPT_ECHO:
392 settimer(modenegotiated);
393 break;
394
395 case TELOPT_TM:
396 if (flushout)
397 flushout = 0;
398 set_my_want_state_dont(option);
399 set_my_state_dont(option);
400 return; /* Never reply to TM will's/wont's */
401
402 default:
403 break;
404 }
405 set_my_want_state_dont(option);
406 if (my_state_is_do(option))
407 send_dont(option, 0);
408 setconnmode(0); /* Set new tty mode */
409 }
410 else if (option == TELOPT_TM) {
411 /*
412 * Special case for TM.
413 */
414 if (flushout)
415 flushout = 0;
416 set_my_want_state_dont(option);
417 }
418 set_my_state_dont(option);
419}
420
421static void dooption(int option) {
422 int new_state_ok = 0;
423
424 if (will_wont_resp[option]) {
425 --will_wont_resp[option];
426 if (will_wont_resp[option] && my_state_is_will(option))
427 --will_wont_resp[option];
428 }
429
430 if (will_wont_resp[option] == 0) {
431 if (my_want_state_is_wont(option)) {
432
433 switch (option) {
434
435 case TELOPT_TM:
436 /*
437 * Special case for TM. We send a WILL, but pretend
438 * we sent WONT.
439 */
440 send_will(option, 0);
441 set_my_want_state_wont(TELOPT_TM);
442 set_my_state_wont(TELOPT_TM);
443 return;
444
445# if defined(TN3270)
446 case TELOPT_EOR: /* end of record */
447# endif /* defined(TN3270) */
448 case TELOPT_BINARY: /* binary mode */
449 case TELOPT_NAWS: /* window size */
450 case TELOPT_TSPEED: /* terminal speed */
451 case TELOPT_LFLOW: /* local flow control */
452 case TELOPT_TTYPE: /* terminal type option */
453 case TELOPT_SGA: /* no big deal */
454 case TELOPT_ENVIRON: /* environment variable option */
455 new_state_ok = 1;
456 break;
457
458 case TELOPT_XDISPLOC: /* X Display location */
459 if (env_getvalue("DISPLAY"))
460 new_state_ok = 1;
461 break;
462
463 case TELOPT_LINEMODE:
464#ifdef KLUDGELINEMODE
465 kludgelinemode = 0;
466 send_do(TELOPT_SGA, 1);
467#endif
468 set_my_want_state_will(TELOPT_LINEMODE);
469 send_will(option, 0);
470 set_my_state_will(TELOPT_LINEMODE);
471 slc_init();
472 return;
473
474 case TELOPT_ECHO: /* We're never going to echo... */
475 default:
476 break;
477 }
478
479 if (new_state_ok) {
480 set_my_want_state_will(option);
481 send_will(option, 0);
482 setconnmode(0); /* Set new tty fmode */
483 }
484 else {
485 will_wont_resp[option]++;
486 send_wont(option, 0);
487 }
488 }
489 else {
490 /*
491 * Handle options that need more things done after the
492 * other side has acknowledged the option.
493 */
494 switch (option) {
495 case TELOPT_LINEMODE:
496#ifdef KLUDGELINEMODE
497 kludgelinemode = 0;
498 send_do(TELOPT_SGA, 1);
499#endif
500 set_my_state_will(option);
501 slc_init();
502 send_do(TELOPT_SGA, 0);
503 return;
504 }
505 }
506 }
507 set_my_state_will(option);
508}
509
510static void dontoption(int option) {
511 if (will_wont_resp[option]) {
512 --will_wont_resp[option];
513 if (will_wont_resp[option] && my_state_is_wont(option))
514 --will_wont_resp[option];
515 }
516
517 if ((will_wont_resp[option] == 0) && my_want_state_is_will(option)) {
518 switch (option) {
519 case TELOPT_LINEMODE:
520 linemode = 0; /* put us back to the default state */
521 break;
522 }
523 /* we always accept a DONT */
524 set_my_want_state_wont(option);
525 if (my_state_is_will(option))
526 send_wont(option, 0);
527 setconnmode(0); /* Set new tty mode */
528 }
529 set_my_state_wont(option);
530}
531
532/*
533 * Given a buffer returned by tgetent(), this routine will turn
534 * the pipe seperated list of names in the buffer into an array
535 * of pointers to null terminated names. We toss out any bad,
536 * duplicate, or verbose names (names with spaces).
537 */
538
539typedef ptrarray<const char> stringarray;
540
541static int is_unique(const char *name, const stringarray &ar) {
542 for (int i=0; i<ar.num(); i++) if (!strcasecmp(ar[i], name)) return 0;
543 return 1;
544}
545
546static void mklist(char *buf, const char *name, stringarray &fill) {
547 char *cp;
548
549 fill.setsize(0);
550 cp = strchr(buf, ':');
551 if (cp) *cp = 0;
552 for (cp = strtok(buf, "|:"); cp; cp = strtok(NULL, "|:")) {
553 /*
554 * Skip entries longer than 40 characters.
555 * Skip entries with spaces or non-ascii values.
556 * Convert lower case letters to upper case.
557 */
558 if (strlen(cp)>40) continue;
559 int bad = 0;
560 for (int i=0; cp[i]; i++) if (!isascii(cp[i]) || cp[i]==' ') bad=1;
561 if (bad) continue;
562 upcase(cp);
563 if (is_unique(cp, fill)) fill.add(cp);
564 }
565
566 /*
567 * Move the name we were passed to the beginning if it's not already
568 * there.
569 */
570 for (int j=1; j<fill.num(); j++) if (!strcasecmp(name, fill[j])) {
571 const char *temp = fill[j];
572 fill[j] = fill[0];
573 fill[0] = temp;
574 }
575
576 /*
577 * Check for an old V6 2 character name. If present,
578 * move it to the end of the array.
579 */
580 for (int k=1; k<fill.num()-1; k++) {
581 if (strlen(fill[k])==2 && fill[k]==buf) {
582 const char *temp = fill[fill.num()-1];
583 fill[fill.num()-1] = fill[k];
584 fill[k] = temp;
585 }
586 }
587
588 /*
589 * If we got nothing, add in what we were passed
590 */
591 if (fill.num()==0) {
592 if (name && strlen(name)<40) fill.add(name);
593 else fill.add("UNKNOWN");
594 }
595
596 /*
597 * Duplicate last name, for TTYPE option, and null
598 * terminate the array. If we didn't find a match on
599 * our terminal name, put that name at the beginning.
600 */
601
602 fill.add(fill[fill.num()-1]);
603 fill.add(NULL);
604}
605
606char termbuf[2048];
607
608static int my_setupterm(const char *tname, int /*fd*/, int *errp) {
609 if (tgetent(termbuf, tname) == 1) {
610 /* its Sun Mar 15 00:03:36 PST 1998 this could never have worked with
611 * ncurses. The ncurses tgetent() ignores its first parameter
612 */
613
614#ifndef USE_NCURSES
615 termbuf[1023] = '\0';
616#else
617 strncpy(termbuf, CUR term_names, sizeof(termbuf));
618#endif
619
620 if (errp)
621 *errp = 1;
622 return 0;
623 }
624 if (errp) *errp = 0;
625 return -1;
626}
627
628int resettermname = 1;
629
630static const char *gettermname(void) {
631 static stringarray termtypes;
632 static int next;
633
634 const char *tname;
635 int err;
636
637 if (resettermname) {
638 resettermname = 0;
639 tname = env_getvalue("TERM");
640 if (!tname || my_setupterm(tname, 1, &err)) {
641 termbuf[0] = 0;
642 tname = "UNKNOWN";
643 }
644 mklist(termbuf, tname, termtypes);
645 next = 0;
646 }
647 if (next==termtypes.num()) next = 0;
648 return termtypes[next++];
649}
650/*
651 * suboption()
652 *
653 * Look at the sub-option buffer, and try to be helpful to the other
654 * side.
655 *
656 * Currently we recognize:
657 *
658 * Terminal type, send request.
659 * Terminal speed (send request).
660 * Local flow control (is request).
661 * Linemode
662 */
663
664static void suboption(void) {
665 printsub('<', subbuffer, SB_LEN()+2);
666 switch (SB_GET()) {
667 case TELOPT_TTYPE:
668 if (my_want_state_is_wont(TELOPT_TTYPE))
669 return;
670 if (SB_EOF() || SB_GET() != TELQUAL_SEND) {
671 return;
672 }
673 else {
674 const char *name;
675
676#if defined(TN3270)
677 if (tn3270_ttype()) {
678 return;
679 }
680#endif /* TN3270 */
681 name = gettermname();
682 netoring.printf("%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
683 TELQUAL_IS, name, IAC, SE);
684 }
685 break;
686 case TELOPT_TSPEED:
687 if (my_want_state_is_wont(TELOPT_TSPEED))
688 return;
689 if (SB_EOF())
690 return;
691 if (SB_GET() == TELQUAL_SEND) {
692 long oospeed, iispeed;
693 TerminalSpeeds(&iispeed, &oospeed);
694 netoring.printf("%c%c%c%c%ld,%ld%c%c", IAC, SB, TELOPT_TSPEED,
695 TELQUAL_IS, oospeed, iispeed, IAC, SE);
696 }
697 break;
698 case TELOPT_LFLOW:
699 if (my_want_state_is_wont(TELOPT_LFLOW))
700 return;
701 if (SB_EOF())
702 return;
703 switch(SB_GET()) {
704 case 1:
705 localflow = 1;
706 break;
707 case 0:
708 localflow = 0;
709 break;
710 default:
711 return;
712 }
713 setcommandmode();
714 setconnmode(0);
715 break;
716
717 case TELOPT_LINEMODE:
718 if (my_want_state_is_wont(TELOPT_LINEMODE))
719 return;
720 if (SB_EOF())
721 return;
722 switch (SB_GET()) {
723 case WILL:
724 lm_will(subpointer, SB_LEN());
725 break;
726 case WONT:
727 lm_wont(subpointer, SB_LEN());
728 break;
729 case DO:
730 lm_do(subpointer, SB_LEN());
731 break;
732 case DONT:
733 lm_dont(subpointer, SB_LEN());
734 break;
735 case LM_SLC:
736 slc(subpointer, SB_LEN());
737 break;
738 case LM_MODE:
739 lm_mode(subpointer, SB_LEN(), 0);
740 break;
741 default:
742 break;
743 }
744 break;
745
746 case TELOPT_ENVIRON:
747 if (SB_EOF())
748 return;
749 switch(SB_PEEK()) {
750 case TELQUAL_IS:
751 case TELQUAL_INFO:
752 if (my_want_state_is_dont(TELOPT_ENVIRON))
753 return;
754 break;
755 case TELQUAL_SEND:
756 if (my_want_state_is_wont(TELOPT_ENVIRON)) {
757 return;
758 }
759 break;
760 default:
761 return;
762 }
763 env_opt(subpointer, SB_LEN());
764 break;
765
766 case TELOPT_XDISPLOC:
767 if (my_want_state_is_wont(TELOPT_XDISPLOC))
768 return;
769 if (SB_EOF())
770 return;
771 if (SB_GET() == TELQUAL_SEND) {
772 const char *dp = env_getvalue("DISPLAY");
773 if (dp == NULL) {
774 /*
775 * Something happened, we no longer have a DISPLAY
776 * variable. So, turn off the option.
777 */
778 send_wont(TELOPT_XDISPLOC, 1);
779 break;
780 }
781 netoring.printf("%c%c%c%c%s%c%c", IAC, SB, TELOPT_XDISPLOC,
782 TELQUAL_IS, dp, IAC, SE);
783 }
784 break;
785
786 default:
787 break;
788 }
789}
790
791//static char str_lm[] = { IAC, SB, TELOPT_LINEMODE, 0, 0, IAC, SE };
792
793void lm_will(unsigned char *cmd, int len) {
794 if (len < 1) {
795 /*@*/ printf("lm_will: no command!!!\n"); /* Should not happen... */
796 return;
797 }
798
799 netoring.printf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
800 DONT, cmd[0], IAC, SE);
801}
802
803void lm_wont(unsigned char * /*cmd*/, int len) {
804 if (len < 1) {
805 /*@*/ printf("lm_wont: no command!!!\n"); /* Should not happen... */
806 return;
807 }
808 /* We are always DONT, so don't respond */
809}
810
811void lm_do(unsigned char *cmd, int len) {
812 if (len < 1) {
813 /*@*/ printf("lm_do: no command!!!\n"); /* Should not happen... */
814 return;
815 }
816 netoring.printf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
817 WONT, cmd[0], IAC, SE);
818}
819
820void lm_dont(unsigned char * /*cmd*/, int len) {
821 if (len < 1) {
822 /*@*/ printf("lm_dont: no command!!!\n"); /* Should not happen... */
823 return;
824 }
825 /* we are always WONT, so don't respond */
826}
827
828void lm_mode(unsigned char *cmd, int len, int init) {
829 if (len != 1) return;
830 if ((linemode&MODE_MASK&~MODE_ACK) == *cmd) return;
831 if (*cmd&MODE_ACK) return;
832
833 linemode = *cmd&(MODE_MASK&~MODE_ACK);
834 int k = linemode;
835 if (!init) {
836 k |= MODE_ACK;
837 }
838
839 netoring.printf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE,
840 k, IAC, SE);
841
842 setconnmode(0); /* set changed mode */
843}
844
845
846/*
847 * slc()
848 * Handle special character suboption of LINEMODE.
849 */
850
851struct spc {
852 cc_t val;
853 cc_t *valp;
854 char flags; /* Current flags & level */
855 char mylevel; /* Maximum level & flags */
856} spc_data[NSLC+1];
857
858#define SLC_IMPORT 0
859#define SLC_EXPORT 1
860#define SLC_RVALUE 2
861static int slc_mode = SLC_EXPORT;
862
863void slc_init(void) {
864 register struct spc *spcp;
865
866 localchars = 1;
867 for (spcp = spc_data; spcp < &spc_data[NSLC+1]; spcp++) {
868 spcp->val = 0;
869 spcp->valp = 0;
870 spcp->flags = spcp->mylevel = SLC_NOSUPPORT;
871 }
872
873#define initfunc(func, flags) { \
874 spcp = &spc_data[func]; \
875 if ((spcp->valp = tcval(func))) { \
876 spcp->val = *spcp->valp; \
877 spcp->mylevel = SLC_VARIABLE|flags; \
878 } else { \
879 spcp->val = 0; \
880 spcp->mylevel = SLC_DEFAULT; \
881 } \
882 }
883
884 initfunc(SLC_SYNCH, 0);
885 /* No BRK */
886 initfunc(SLC_AO, 0);
887 initfunc(SLC_AYT, 0);
888 /* No EOR */
889 initfunc(SLC_ABORT, SLC_FLUSHIN|SLC_FLUSHOUT);
890 initfunc(SLC_EOF, 0);
891 initfunc(SLC_SUSP, SLC_FLUSHIN);
892
893 initfunc(SLC_EC, 0);
894 initfunc(SLC_EL, 0);
895
896 initfunc(SLC_XON, 0);
897 initfunc(SLC_XOFF, 0);
898
899 initfunc(SLC_FORW1, 0);
900 initfunc(SLC_FORW2, 0);
901 /* No FORW2 */
902
903 initfunc(SLC_IP, SLC_FLUSHIN|SLC_FLUSHOUT);
904#undef initfunc
905
906 if (slc_mode == SLC_EXPORT)
907 slc_export();
908 else
909 slc_import(1);
910
911}
912
913void slcstate(void) {
914 printf("Special characters are %s values\n",
915 slc_mode == SLC_IMPORT ? "remote default" :
916 slc_mode == SLC_EXPORT ? "local" :
917 "remote");
918}
919
920void slc_mode_export(void) {
921 slc_mode = SLC_EXPORT;
922 if (my_state_is_will(TELOPT_LINEMODE))
923 slc_export();
924}
925
926void slc_mode_import(int def) {
927 slc_mode = def ? SLC_IMPORT : SLC_RVALUE;
928 if (my_state_is_will(TELOPT_LINEMODE))
929 slc_import(def);
930}
931
932void slc_import(int def) {
933 if (def) {
934 netoring.printf("%c%c%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
935 LM_SLC, 0, SLC_DEFAULT, 0, IAC, SE);
936 }
937 else {
938 netoring.printf("%c%c%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
939 LM_SLC, 0, SLC_VARIABLE, 0, IAC, SE);
940 }
941}
942
943void slc_export(void) {
944 register struct spc *spcp;
945
946 TerminalDefaultChars();
947
948 slc_start_reply();
949 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
950 if (spcp->mylevel != SLC_NOSUPPORT) {
951 if (spcp->val == (cc_t)(_POSIX_VDISABLE))
952 spcp->flags = SLC_NOSUPPORT;
953 else
954 spcp->flags = spcp->mylevel;
955 if (spcp->valp)
956 spcp->val = *spcp->valp;
957 slc_add_reply(spcp - spc_data, spcp->flags, spcp->val);
958 }
959 }
960 slc_end_reply();
961 (void)slc_update();
962 setconnmode(1); /* Make sure the character values are set */
963}
964
965void slc(unsigned char *cp, int len) {
966 register struct spc *spcp;
967 register int func,level;
968
969 slc_start_reply();
970
971 for (; len >= 3; len -=3, cp +=3) {
972
973 func = cp[SLC_FUNC];
974
975 if (func == 0) {
976 /*
977 * Client side: always ignore 0 function.
978 */
979 continue;
980 }
981 if (func > NSLC) {
982 if ((cp[SLC_FLAGS] & SLC_LEVELBITS) != SLC_NOSUPPORT)
983 slc_add_reply(func, SLC_NOSUPPORT, 0);
984 continue;
985 }
986
987 spcp = &spc_data[func];
988
989 level = cp[SLC_FLAGS]&(SLC_LEVELBITS|SLC_ACK);
990
991 if ((cp[SLC_VALUE] == spcp->val) &&
992 ((level&SLC_LEVELBITS) == (spcp->flags&SLC_LEVELBITS))) {
993 continue;
994 }
995
996 if (level == (SLC_DEFAULT|SLC_ACK)) {
997 /*
998 * This is an error condition, the SLC_ACK
999 * bit should never be set for the SLC_DEFAULT
1000 * level. Our best guess to recover is to
1001 * ignore the SLC_ACK bit.
1002 */
1003 cp[SLC_FLAGS] &= ~SLC_ACK;
1004 }
1005
1006 if (level == ((spcp->flags&SLC_LEVELBITS)|SLC_ACK)) {
1007 spcp->val = (cc_t)cp[SLC_VALUE];
1008 spcp->flags = cp[SLC_FLAGS]; /* include SLC_ACK */
1009 continue;
1010 }
1011
1012 level &= ~SLC_ACK;
1013
1014 if (level <= (spcp->mylevel&SLC_LEVELBITS)) {
1015 spcp->flags = cp[SLC_FLAGS]|SLC_ACK;
1016 spcp->val = (cc_t)cp[SLC_VALUE];
1017 }
1018 if (level == SLC_DEFAULT) {
1019 if ((spcp->mylevel&SLC_LEVELBITS) != SLC_DEFAULT)
1020 spcp->flags = spcp->mylevel;
1021 else
1022 spcp->flags = SLC_NOSUPPORT;
1023 }
1024 slc_add_reply(func, spcp->flags, spcp->val);
1025 }
1026 slc_end_reply();
1027 if (slc_update())
1028 setconnmode(1); /* set the new character values */
1029}
1030
1031void slc_check(void) {
1032 register struct spc *spcp;
1033
1034 slc_start_reply();
1035 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
1036 if (spcp->valp && spcp->val != *spcp->valp) {
1037 spcp->val = *spcp->valp;
1038 if (spcp->val == (cc_t)(_POSIX_VDISABLE))
1039 spcp->flags = SLC_NOSUPPORT;
1040 else
1041 spcp->flags = spcp->mylevel;
1042 slc_add_reply(spcp - spc_data, spcp->flags, spcp->val);
1043 }
1044 }
1045 slc_end_reply();
1046 setconnmode(1);
1047}
1048
1049
1050unsigned char slc_reply[128];
1051unsigned char *slc_replyp;
1052
1053void slc_start_reply(void) {
1054 slc_replyp = slc_reply;
1055 *slc_replyp++ = IAC;
1056 *slc_replyp++ = SB;
1057 *slc_replyp++ = TELOPT_LINEMODE;
1058 *slc_replyp++ = LM_SLC;
1059}
1060
1061void slc_add_reply(int func, int flags, int value) {
1062 if ((*slc_replyp++ = func) == IAC)
1063 *slc_replyp++ = IAC;
1064 if ((*slc_replyp++ = flags) == IAC)
1065 *slc_replyp++ = IAC;
1066 if ((*slc_replyp++ = value) == IAC)
1067 *slc_replyp++ = IAC;
1068}
1069
1070void slc_end_reply(void) {
1071 register int len;
1072
1073 *slc_replyp++ = IAC;
1074 *slc_replyp++ = SE;
1075 len = slc_replyp - slc_reply;
1076 if (len <= 6) return;
1077
1078 printsub('>', &slc_reply[2], len - 2);
1079 netoring.write((char *)slc_reply, len);
1080}
1081
1082int slc_update(void) {
1083 struct spc *spcp;
1084 int need_update = 0;
1085
1086 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
1087 if (!(spcp->flags&SLC_ACK))
1088 continue;
1089 spcp->flags &= ~SLC_ACK;
1090 if (spcp->valp && (*spcp->valp != spcp->val)) {
1091 *spcp->valp = spcp->val;
1092 need_update = 1;
1093 }
1094 }
1095 return(need_update);
1096}
1097
1098void env_opt(unsigned char *buf, int len) {
1099 unsigned char *ep = 0, *epc = 0;
1100 int i;
1101
1102 switch(buf[0]) {
1103 case TELQUAL_SEND:
1104 env_opt_start();
1105 if (len == 1) {
1106 env_opt_add(NULL);
1107 }
1108 else for (i = 1; i < len; i++) {
1109 switch (buf[i]) {
1110 case ENV_VALUE:
1111 if (ep) {
1112 *epc = 0;
1113 env_opt_add((const char *)ep);
1114 }
1115 ep = epc = &buf[i+1];
1116 break;
1117 case ENV_ESC:
1118 i++;
1119 /*FALL THROUGH*/
1120 default:
1121 if (epc)
1122 *epc++ = buf[i];
1123 break;
1124 }
1125 if (ep) {
1126 *epc = 0;
1127 env_opt_add((const char *)ep);
1128 }
1129 }
1130 env_opt_end(1);
1131 break;
1132
1133 case TELQUAL_IS:
1134 case TELQUAL_INFO:
1135 /* Ignore for now. We shouldn't get it anyway. */
1136 break;
1137
1138 default:
1139 break;
1140 }
1141}
1142
1143/* OPT_REPLY_SIZE must be a multiple of 2. */
1144#define OPT_REPLY_SIZE 256
1145unsigned char *opt_reply;
1146unsigned char *opt_replyp;
1147unsigned char *opt_replyend;
1148
1149void env_opt_start(void) {
1150 if (opt_reply)
1151 opt_reply = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
1152 else
1153 opt_reply = (unsigned char *)malloc(OPT_REPLY_SIZE);
1154 if (opt_reply == NULL) {
1155 /*@*/ printf("env_opt_start: malloc()/realloc() failed!!!\n");
1156 opt_reply = opt_replyp = opt_replyend = NULL;
1157 return;
1158 }
1159 opt_replyp = opt_reply;
1160 opt_replyend = opt_reply + OPT_REPLY_SIZE;
1161 *opt_replyp++ = IAC;
1162 *opt_replyp++ = SB;
1163 *opt_replyp++ = TELOPT_ENVIRON;
1164 *opt_replyp++ = TELQUAL_IS;
1165}
1166
1167void env_opt_start_info(void) {
1168 env_opt_start();
1169 if (opt_replyp)
1170 opt_replyp[-1] = TELQUAL_INFO;
1171}
1172
1173void env_opt_add(const char *ep) {
1174 const char *vp;
1175 const unsigned char *tp;
1176 unsigned char c;
1177
1178 if (opt_reply == NULL) /*XXX*/
1179 return; /*XXX*/
1180
1181 if (ep == NULL || *ep == '\0') {
1182 int i;
1183 env_iterate(&i, 1);
1184 for (ep = env_next(&i,1); ep; ep = env_next(&i,1)) env_opt_add(ep);
1185 return;
1186 }
1187 vp = env_getvalue(ep);
1188 tp = opt_replyp + (vp ? strlen(vp) * 2 : 0) + strlen(ep) * 2 + 6;
1189 if (tp > opt_replyend)
1190 {
1191 register int len;
1192 len = ((tp - opt_reply) + OPT_REPLY_SIZE - 1) & ~(OPT_REPLY_SIZE - 1);
1193 opt_replyend = opt_reply + len;
1194 opt_reply = (unsigned char *)realloc(opt_reply, len);
1195 if (opt_reply == NULL) {
1196 /*@*/ printf("env_opt_add: realloc() failed!!!\n");
1197 opt_reply = opt_replyp = opt_replyend = NULL;
1198 return;
1199 }
1200 opt_replyp = opt_reply + len - (opt_replyend - opt_replyp);
1201 opt_replyend = opt_reply + len;
1202 }
1203 *opt_replyp++ = ENV_VAR;
1204 for (;;) {
1205 while ((c = *ep++)!=0) {
1206 switch(c) {
1207 case IAC:
1208 *opt_replyp++ = IAC;
1209 break;
1210 case ENV_VALUE:
1211 case ENV_VAR:
1212 case ENV_ESC:
1213 *opt_replyp++ = ENV_ESC;
1214 break;
1215 }
1216 *opt_replyp++ = c;
1217 }
1218 if ((ep = vp)!=NULL) {
1219 *opt_replyp++ = ENV_VALUE;
1220 vp = NULL;
1221 } else
1222 break;
1223 }
1224}
1225
1226void env_opt_end(int emptyok) {
1227 register int len;
1228
1229 len = opt_replyp - opt_reply + 2;
1230 if (emptyok || len > 6) {
1231 *opt_replyp++ = IAC;
1232 *opt_replyp++ = SE;
1233 printsub('>', &opt_reply[2], len - 2);
1234 netoring.write((char *)opt_reply, len);
1235 }
1236 if (opt_reply) {
1237 free(opt_reply);
1238 opt_reply = opt_replyp = opt_replyend = NULL;
1239 }
1240}
1241
1242
1243int telrcv(void) {
1244 int c;
1245 int returnValue = 0;
1246
1247 while (TTYROOM() > 2) {
1248 if (!netiring.getch(&c)) {
1249 /* No more data coming in */
1250 break;
1251 }
1252 returnValue = 1;
1253
1254 switch (telrcv_state) {
1255 case TS_CR:
1256 telrcv_state = TS_DATA;
1257 if (c == '\0') {
1258 break; /* Ignore \0 after CR */
1259 }
1260 else if ((c == '\n') &&
1261 my_want_state_is_dont(TELOPT_ECHO) &&
1262 !crmod)
1263 {
1264 TTYADD(c);
1265 break;
1266 }
1267 /* Else, fall through */
1268
1269 case TS_DATA:
1270 if (c == IAC) {
1271 telrcv_state = TS_IAC;
1272 break;
1273 }
1274#if defined(TN3270)
1275 if (In3270) {
1276 *Ifrontp++ = c;
1277 while (netiring.getch(&c)) {
1278 if (c == IAC) {
1279 telrcv_state = TS_IAC;
1280 break;
1281 }
1282 *Ifrontp++ = c;
1283 }
1284 } else
1285#endif /* defined(TN3270) */
1286 /*
1287 * The 'crmod' hack (see following) is needed
1288 * since we can't * set CRMOD on output only.
1289 * Machines like MULTICS like to send \r without
1290 * \n; since we must turn off CRMOD to get proper
1291 * input, the mapping is done here (sigh).
1292 */
1293 if ((c == '\r') && my_want_state_is_dont(TELOPT_BINARY)) {
1294 if (netiring.getch(&c)) {
1295 if (c == 0) {
1296 /* a "true" CR */
1297 TTYADD('\r');
1298 }
1299 else if (my_want_state_is_dont(TELOPT_ECHO) &&
1300 (c == '\n')) {
1301 TTYADD('\n');
1302 }
1303 else {
1304 netiring.ungetch(c);
1305 TTYADD('\r');
1306 if (crmod) TTYADD('\n');
1307 }
1308 }
1309 else {
1310 telrcv_state = TS_CR;
1311 TTYADD('\r');
1312 if (crmod) TTYADD('\n');
1313 }
1314 }
1315 else {
1316 TTYADD(c);
1317 }
1318 continue;
1319
1320 case TS_IAC:
1321 process_iac:
1322 switch (c) {
1323 case WILL:
1324 telrcv_state = TS_WILL;
1325 continue;
1326 case WONT:
1327 telrcv_state = TS_WONT;
1328 continue;
1329 case DO:
1330 telrcv_state = TS_DO;
1331 continue;
1332 case DONT:
1333 telrcv_state = TS_DONT;
1334 continue;
1335 case DM:
1336 /*
1337 * We may have missed an urgent notification,
1338 * so make sure we flush whatever is in the
1339 * buffer currently.
1340 */
1341 printoption("RCVD", IAC, DM);
1342 SYNCHing = 1;
1343 ttyflush(1);
1344 SYNCHing = nlink.stilloob();
1345 settimer(gotDM);
1346 break;
1347 case SB:
1348 SB_CLEAR();
1349 telrcv_state = TS_SB;
1350 continue;
1351
1352#if defined(TN3270)
1353 case EOR:
1354 if (In3270) {
1355 if (Ibackp == Ifrontp) {
1356 Ibackp = Ifrontp = Ibuf;
1357 ISend = 0; /* should have been! */
1358 }
1359 else {
1360 Ibackp += DataFromNetwork(Ibackp, Ifrontp-Ibackp, 1);
1361 ISend = 1;
1362 }
1363 }
1364 printoption("RCVD", IAC, EOR);
1365 break;
1366#endif /* defined(TN3270) */
1367
1368 case IAC:
1369#if !defined(TN3270)
1370 TTYADD(IAC);
1371#else /* !defined(TN3270) */
1372 if (In3270) {
1373 *Ifrontp++ = IAC;
1374 }
1375 else {
1376 TTYADD(IAC);
1377 }
1378#endif /* !defined(TN3270) */
1379 break;
1380
1381 case NOP:
1382 case GA:
1383 default:
1384 printoption("RCVD", IAC, c);
1385 break;
1386 }
1387 telrcv_state = TS_DATA;
1388 continue;
1389
1390 case TS_WILL:
1391 printoption("RCVD", WILL, c);
1392 willoption(c);
1393 SetIn3270();
1394 telrcv_state = TS_DATA;
1395 continue;
1396
1397 case TS_WONT:
1398 printoption("RCVD", WONT, c);
1399 wontoption(c);
1400 SetIn3270();
1401 telrcv_state = TS_DATA;
1402 continue;
1403
1404 case TS_DO:
1405 printoption("RCVD", DO, c);
1406 dooption(c);
1407 SetIn3270();
1408 if (c == TELOPT_NAWS) {
1409 sendnaws();
1410 }
1411 else if (c == TELOPT_LFLOW) {
1412 localflow = 1;
1413 setcommandmode();
1414 setconnmode(0);
1415 }
1416 telrcv_state = TS_DATA;
1417 continue;
1418
1419 case TS_DONT:
1420 printoption("RCVD", DONT, c);
1421 dontoption(c);
1422 flushline = 1;
1423 setconnmode(0); /* set new tty mode (maybe) */
1424 SetIn3270();
1425 telrcv_state = TS_DATA;
1426 continue;
1427
1428 case TS_SB:
1429 if (c == IAC) {
1430 telrcv_state = TS_SE;
1431 }
1432 else {
1433 SB_ACCUM(c);
1434 }
1435 continue;
1436
1437 case TS_SE:
1438 if (c != SE) {
1439 if (c != IAC) {
1440 /*
1441 * This is an error. We only expect to get
1442 * "IAC IAC" or "IAC SE". Several things may
1443 * have happend. An IAC was not doubled, the
1444 * IAC SE was left off, or another option got
1445 * inserted into the suboption are all possibilities.
1446 * If we assume that the IAC was not doubled,
1447 * and really the IAC SE was left off, we could
1448 * get into an infinate loop here. So, instead,
1449 * we terminate the suboption, and process the
1450 * partial suboption if we can.
1451 */
1452 SB_ACCUM(IAC);
1453 SB_ACCUM(c);
1454 subpointer -= 2;
1455 SB_TERM();
1456
1457 printoption("In SUBOPTION processing, RCVD", IAC, c);
1458 suboption(); /* handle sub-option */
1459 SetIn3270();
1460 telrcv_state = TS_IAC;
1461 goto process_iac;
1462 }
1463 SB_ACCUM(c);
1464 telrcv_state = TS_SB;
1465 }
1466 else {
1467 SB_ACCUM(IAC);
1468 SB_ACCUM(SE);
1469 subpointer -= 2;
1470 SB_TERM();
1471 suboption(); /* handle sub-option */
1472 SetIn3270();
1473 telrcv_state = TS_DATA;
1474 }
1475 }
1476
1477 }
1478 return returnValue;
1479}
1480
1481static int bol = 1, local = 0;
1482
1483int rlogin_susp(void) {
1484 if (local) {
1485 local = 0;
1486 bol = 1;
1487 command(0, "z\n", 2);
1488 return(1);
1489 }
1490 return(0);
1491}
1492
1493static int telsnd(void) {
1494 // int tcc;
1495 // int count;
1496 int returnValue = 0;
1497 // const char *tbp = NULL;
1498
1499 // tcc = 0;
1500 // count = 0;
1501 while (netoring.empty_count() > 2) {
1502 int c, sc;
1503
1504 if (!ttyiring.getch(&c)) {
1505 break;
1506 }
1507 returnValue = 1;
1508
1509 sc = strip(c);
1510
1511 if (rlogin != _POSIX_VDISABLE) {
1512 if (bol) {
1513 bol = 0;
1514 if (sc == rlogin) {
1515 local = 1;
1516 continue;
1517 }
1518 }
1519 else if (local) {
1520 local = 0;
1521 if (sc == '.' || c == termEofChar) {
1522 bol = 1;
1523 command(0, "close\n", 6);
1524 continue;
1525 }
1526 if (sc == termSuspChar) {
1527 bol = 1;
1528 command(0, "z\n", 2);
1529 continue;
1530 }
1531 if (sc == escapechar && escapechar !=_POSIX_VDISABLE) {
1532 int l;
1533 char buf[128];
1534 l = ttyiring.gets(buf, sizeof(buf));
1535 command(0, buf, l);
1536 bol = 1;
1537 flushline = 1;
1538 break;
1539 }
1540 if (sc != rlogin) {
1541 ttyiring.ungetch(c);
1542 c = sc = rlogin;
1543 }
1544 }
1545 if ((sc == '\n') || (sc == '\r'))
1546 bol = 1;
1547 }
1548 else if (sc == escapechar && escapechar != _POSIX_VDISABLE) {
1549 int ignore = 0;
1550 /*
1551 * Double escape is a pass through of a single escape character.
1552 */
1553 if (ttyiring.getch(&c)) {
1554 if (strip(c) != escapechar) ttyiring.ungetch(c);
1555 else {
1556 bol = 0;
1557 ignore = 1;
1558 }
1559 }
1560 if (!ignore) {
1561 int l;
1562 char buf[128];
1563 l = ttyiring.gets(buf, sizeof(buf));
1564 command(0, buf, l);
1565 bol = 1;
1566 flushline = 1;
1567 break;
1568 }
1569 }
1570 else {
1571 bol = 0;
1572 }
1573#ifdef KLUDGELINEMODE
1574 if (kludgelinemode && (globalmode&MODE_EDIT) && (sc == echoc)) {
1575 int ignore=0;
1576 if (ttyiring.getch(&c) > 0) {
1577 if (strip(c) != echoc) ttyiring.ungetch(c);
1578 else ignore=1;
1579 }
1580 if (!ignore) {
1581 dontlecho = !dontlecho;
1582 settimer(echotoggle);
1583 setconnmode(0);
1584 flushline = 1;
1585 break;
1586 }
1587 }
1588#endif
1589 if (MODE_LOCAL_CHARS(globalmode)) {
1590 if (TerminalSpecialChars(sc) == 0) {
1591 bol = 1;
1592 break;
1593 }
1594 }
1595 if (my_want_state_is_wont(TELOPT_BINARY)) {
1596 switch (c) {
1597 case '\n':
1598 /*
1599 * If we are in CRMOD mode (\r ==> \n)
1600 * on our local machine, then probably
1601 * a newline (unix) is CRLF (TELNET).
1602 */
1603 if (MODE_LOCAL_CHARS(globalmode)) {
1604 NETADD('\r');
1605 }
1606 NETADD('\n');
1607 bol = flushline = 1;
1608 break;
1609 case '\r':
1610 if (!crlf) {
1611 NET2ADD('\r', '\0');
1612 }
1613 else {
1614 NET2ADD('\r', '\n');
1615 }
1616 bol = flushline = 1;
1617 break;
1618 case IAC:
1619 NET2ADD(IAC, IAC);
1620 break;
1621 default:
1622 NETADD(c);
1623 break;
1624 }
1625 }
1626 else if (c == IAC) {
1627 NET2ADD(IAC, IAC);
1628 }
1629 else {
1630 NETADD(c);
1631 }
1632 }
1633
1634 return returnValue; /* Non-zero if we did anything */
1635}
1636
1637/*
1638 * Scheduler()
1639 *
1640 * Try to do something.
1641 *
1642 * If we do something useful, return 1; else return 0.
1643 *
1644 */
1645
1646/* block: should we block in the select ? */
1647int Scheduler(int block) {
1648 /* One wants to be a bit careful about setting returnValue
1649 * to one, since a one implies we did some useful work,
1650 * and therefore probably won't be called to block next
1651 * time (TN3270 mode only).
1652 */
1653 int returnValue;
1654 int netin, netout, netex, ttyin, ttyout;
1655
1656 /* Decide which rings should be processed */
1657
1658 netout = netoring.full_count() &&
1659 (flushline ||
1660 (my_want_state_is_wont(TELOPT_LINEMODE)
1661#ifdef KLUDGELINEMODE
1662 && (!kludgelinemode || my_want_state_is_do(TELOPT_SGA))
1663#endif
1664 ) ||
1665 my_want_state_is_will(TELOPT_BINARY));
1666 ttyout = ttyoring.full_count();
1667
1668#if defined(TN3270)
1669 ttyin = ttyiring.empty_count() && (shell_active == 0);
1670#else /* defined(TN3270) */
1671 ttyin = ttyiring.empty_count();
1672#endif /* defined(TN3270) */
1673
1674#if defined(TN3270)
1675 netin = netiring.empty_count();
1676#else /* !defined(TN3270) */
1677 netin = !ISend && netiring.empty_count();
1678#endif /* !defined(TN3270) */
1679
1680 netex = !SYNCHing;
1681
1682 /* If we have seen a signal recently, reset things */
1683#ifdef TN3270
1684 if (HaveInput) {
1685 HaveInput = 0;
1686 (void) signal(SIGIO, inputAvailable);
1687 }
1688#endif /* TN3270 */
1689
1690 /* Call to system code to process rings */
1691
1692 returnValue = process_rings(netin, netout, netex, ttyin, ttyout, !block);
1693
1694 /* Now, look at the input rings, looking for work to do. */
1695
1696 if (ttyiring.full_count()) {
1697#if defined(TN3270)
1698 if (In3270) {
1699 int c;
1700
1701 c = DataFromTerminal(ttyiring.consume,
1702 ring_full_consecutive(&ttyiring));
1703 if (c) {
1704 returnValue = 1;
1705 ring_consumed(&ttyiring, c);
1706 }
1707 } else {
1708#endif /* defined(TN3270) */
1709 returnValue |= telsnd();
1710#if defined(TN3270)
1711 }
1712#endif /* defined(TN3270) */
1713 }
1714
1715 if (netiring.full_count()) {
1716# if !defined(TN3270)
1717 returnValue |= telrcv();
1718# else /* !defined(TN3270) */
1719 returnValue = Push3270();
1720# endif /* !defined(TN3270) */
1721 }
1722 return returnValue;
1723}
1724
1725/*
1726 * Select from tty and network...
1727 */
1728void telnet(const char * /*user*/) {
1729 sys_telnet_init();
1730
1731
1732#if !defined(TN3270)
1733 if (telnetport) {
1734 send_do(TELOPT_SGA, 1);
1735 send_will(TELOPT_TTYPE, 1);
1736 send_will(TELOPT_NAWS, 1);
1737 send_will(TELOPT_TSPEED, 1);
1738 send_will(TELOPT_LFLOW, 1);
1739 send_will(TELOPT_LINEMODE, 1);
1740 send_will(TELOPT_ENVIRON, 1);
1741 send_do(TELOPT_STATUS, 1);
1742 if (env_getvalue("DISPLAY"))
1743 send_will(TELOPT_XDISPLOC, 1);
1744 if (eight)
1745 tel_enter_binary(eight);
1746 }
1747#endif /* !defined(TN3270) */
1748
1749#if !defined(TN3270)
1750 for (;;) {
1751 int schedValue;
1752
1753 while ((schedValue = Scheduler(0)) != 0) {
1754 if (schedValue == -1) {
1755 setcommandmode();
1756 return;
1757 }
1758 }
1759
1760 if (Scheduler(1) == -1) {
1761 setcommandmode();
1762 return;
1763 }
1764 }
1765#else /* !defined(TN3270) */
1766 for (;;) {
1767 int schedValue;
1768
1769 while (!In3270 && !shell_active) {
1770 if (Scheduler(1) == -1) {
1771 setcommandmode();
1772 return;
1773 }
1774 }
1775
1776 while ((schedValue = Scheduler(0)) != 0) {
1777 if (schedValue == -1) {
1778 setcommandmode();
1779 return;
1780 }
1781 }
1782 /* If there is data waiting to go out to terminal, don't
1783 * schedule any more data for the terminal.
1784 */
1785 if (ring_full_count(&ttyoring)) {
1786 schedValue = 1;
1787 } else {
1788 if (shell_active) {
1789 if (shell_continue() == 0) {
1790 ConnectScreen();
1791 }
1792 } else if (In3270) {
1793 schedValue = DoTerminalOutput();
1794 }
1795 }
1796 if (schedValue && (shell_active == 0)) {
1797 if (Scheduler(1) == -1) {
1798 setcommandmode();
1799 return;
1800 }
1801 }
1802 }
1803#endif /* !defined(TN3270) */
1804}
1805
1806#if 0 /* XXX - this not being in is a bug */
1807/*
1808 * nextitem()
1809 *
1810 * Return the address of the next "item" in the TELNET data
1811 * stream. This will be the address of the next character if
1812 * the current address is a user data character, or it will
1813 * be the address of the character following the TELNET command
1814 * if the current address is a TELNET IAC ("I Am a Command")
1815 * character.
1816 */
1817
1818static unsigned char *nextitem(unsigned char *current) {
1819 if (*current != IAC) {
1820 return current+1;
1821 }
1822 switch (current[1]) {
1823 case DO:
1824 case DONT:
1825 case WILL:
1826 case WONT:
1827 return current+3;
1828 case SB: /* loop forever looking for the SE */
1829 {
1830 unsigned char *look = current+2;
1831
1832 for (;;) {
1833 if (*look++ == IAC) {
1834 if (*look++ == SE) {
1835 return look;
1836 }
1837 }
1838 }
1839 }
1840 default:
1841 return current+2;
1842 }
1843}
1844#endif /* 0 */
1845
1846/*
1847 * netclear()
1848 *
1849 * We are about to do a TELNET SYNCH operation. Clear
1850 * the path to the network.
1851 *
1852 * Things are a bit tricky since we may have sent the first
1853 * byte or so of a previous TELNET command into the network.
1854 * So, we have to scan the network buffer from the beginning
1855 * until we are up to where we want to be.
1856 *
1857 * A side effect of what we do, just to keep things
1858 * simple, is to clear the urgent data pointer. The principal
1859 * caller should be setting the urgent data pointer AFTER calling
1860 * us in any case.
1861 */
1862
1863static void netclear(void) {
1864#if 0 /* XXX */
1865 register char *thisitem, *next;
1866 char *good;
1867#define wewant(p) ((nfrontp > p) && (*p == IAC) && \
1868 (p[1] != EC) && (p[1] != EL))
1869
1870 thisitem = netobuf;
1871
1872 while ((next = nextitem(thisitem)) <= netobuf.send) {
1873 thisitem = next;
1874 }
1875
1876 /* Now, thisitem is first before/at boundary. */
1877
1878 good = netobuf; /* where the good bytes go */
1879
1880 while (netoring.add > thisitem) {
1881 if (wewant(thisitem)) {
1882 int length;
1883
1884 next = thisitem;
1885 do {
1886 next = nextitem(next);
1887 } while (wewant(next) && (nfrontp > next));
1888 length = next-thisitem;
1889 memcpy(good, thisitem, length);
1890 good += length;
1891 thisitem = next;
1892 } else {
1893 thisitem = nextitem(thisitem);
1894 }
1895 }
1896
1897#endif /* 0 */
1898}
1899
1900/*
1901 * These routines add various telnet commands to the data stream.
1902 */
1903
1904static void doflush(void) {
1905 NET2ADD(IAC, DO);
1906 NETADD(TELOPT_TM);
1907 flushline = 1;
1908 flushout = 1;
1909 (void) ttyflush(1); /* Flush/drop output */
1910 /* do printoption AFTER flush, otherwise the output gets tossed... */
1911 printoption("SENT", DO, TELOPT_TM);
1912}
1913
1914void xmitAO(void) {
1915 NET2ADD(IAC, AO);
1916 printoption("SENT", IAC, AO);
1917 if (autoflush) {
1918 doflush();
1919 }
1920}
1921
1922
1923void xmitEL(void) {
1924 NET2ADD(IAC, EL);
1925 printoption("SENT", IAC, EL);
1926}
1927
1928void xmitEC(void) {
1929 NET2ADD(IAC, EC);
1930 printoption("SENT", IAC, EC);
1931}
1932
1933
1934int dosynch(void) {
1935 netclear(); /* clear the path to the network */
1936 NETADD(IAC);
1937 netoring.set_mark();
1938 NETADD(DM);
1939 printoption("SENT", IAC, DM);
1940 return 1;
1941}
1942
1943int want_status_response = 0;
1944
1945int get_status(const char *, const char *) {
1946 unsigned char tmp[16];
1947 unsigned char *cp;
1948
1949 if (my_want_state_is_dont(TELOPT_STATUS)) {
1950 printf("Remote side does not support STATUS option\n");
1951 return 0;
1952 }
1953 cp = tmp;
1954
1955 *cp++ = IAC;
1956 *cp++ = SB;
1957 *cp++ = TELOPT_STATUS;
1958 *cp++ = TELQUAL_SEND;
1959 *cp++ = IAC;
1960 *cp++ = SE;
1961 printsub('>', tmp+2, cp - tmp - 2);
1962 netoring.write((char *)tmp, cp-tmp);
1963 ++want_status_response;
1964 return 1;
1965}
1966
1967void intp(void) {
1968 NET2ADD(IAC, IP);
1969 printoption("SENT", IAC, IP);
1970 flushline = 1;
1971 if (autoflush) {
1972 doflush();
1973 }
1974 if (autosynch) {
1975 dosynch();
1976 }
1977}
1978
1979void sendbrk(void) {
1980 NET2ADD(IAC, BREAK);
1981 printoption("SENT", IAC, BREAK);
1982 flushline = 1;
1983 if (autoflush) {
1984 doflush();
1985 }
1986 if (autosynch) {
1987 dosynch();
1988 }
1989}
1990
1991void sendabort(void) {
1992 NET2ADD(IAC, ABORT);
1993 printoption("SENT", IAC, ABORT);
1994 flushline = 1;
1995 if (autoflush) {
1996 doflush();
1997 }
1998 if (autosynch) {
1999 dosynch();
2000 }
2001}
2002
2003void sendsusp(void) {
2004 NET2ADD(IAC, SUSP);
2005 printoption("SENT", IAC, SUSP);
2006 flushline = 1;
2007 if (autoflush) {
2008 doflush();
2009 }
2010 if (autosynch) {
2011 dosynch();
2012 }
2013}
2014
2015void sendeof(void) {
2016 NET2ADD(IAC, xEOF);
2017 printoption("SENT", IAC, xEOF);
2018}
2019
2020void sendayt(void) {
2021 NET2ADD(IAC, AYT);
2022 printoption("SENT", IAC, AYT);
2023}
2024
2025/*
2026 * Send a window size update to the remote system.
2027 */
2028
2029void sendnaws(void) {
2030 long rows, cols;
2031 unsigned char tmp[16];
2032 unsigned char *cp;
2033
2034 if (my_state_is_wont(TELOPT_NAWS))
2035 return;
2036
2037#define PUTSHORT(cp, x) { if ((*cp++ = ((x)>>8)&0xff) == IAC) *cp++ = IAC; \
2038 if ((*cp++ = ((x))&0xff) == IAC) *cp++ = IAC; }
2039
2040 if (TerminalWindowSize(&rows, &cols) == 0) { /* Failed */
2041 return;
2042 }
2043
2044 cp = tmp;
2045
2046 *cp++ = IAC;
2047 *cp++ = SB;
2048 *cp++ = TELOPT_NAWS;
2049 PUTSHORT(cp, cols);
2050 PUTSHORT(cp, rows);
2051 *cp++ = IAC;
2052 *cp++ = SE;
2053 printsub('>', tmp+2, cp - tmp - 2);
2054 netoring.write((char *)tmp, cp-tmp);
2055}
2056
2057void tel_enter_binary(int rw) {
2058 if (rw&1)
2059 send_do(TELOPT_BINARY, 1);
2060 if (rw&2)
2061 send_will(TELOPT_BINARY, 1);
2062}
2063
2064void tel_leave_binary(int rw) {
2065 if (rw&1)
2066 send_dont(TELOPT_BINARY, 1);
2067 if (rw&2)
2068 send_wont(TELOPT_BINARY, 1);
2069}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.o
new file mode 100644
index 0000000..a40a0f3
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/telnet.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.cc
new file mode 100644
index 0000000..9eb47ae
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.cc
@@ -0,0 +1,718 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)terminal.c 5.3 (Berkeley) 3/22/91
36 */
37char terminal_rcsid[] =
38 "$Id: terminal.cc,v 1.25 1999/12/12 19:48:05 dholland Exp $";
39
40#include <arpa/telnet.h>
41#include <sys/types.h>
42#include <sys/time.h>
43#include <termios.h>
44#include <unistd.h>
45#include <signal.h>
46#include <errno.h>
47#include <stdio.h>
48
49#include "ring.h"
50#include "defines.h"
51#include "externs.h"
52#include "types.h"
53#include "proto.h"
54#include "terminal.h"
55
56static int TerminalWrite(const char *buf, int n);
57static int TerminalRead(char *buf, int n);
58
59ringbuf ttyoring, ttyiring;
60
61#ifndef VDISCARD
62cc_t termFlushChar;
63#endif
64
65#ifndef VLNEXT
66cc_t termLiteralNextChar;
67#endif
68
69#ifndef VSUSP
70cc_t termSuspChar;
71#endif
72
73#ifndef VWERASE
74cc_t termWerasChar;
75#endif
76
77#ifndef VREPRINT
78cc_t termRprntChar;
79#endif
80
81#ifndef VSTART
82cc_t termStartChar;
83#endif
84
85#ifndef VSTOP
86cc_t termStopChar;
87#endif
88
89#ifndef VEOL
90cc_t termForw1Char;
91#endif
92
93#ifndef VEOL2
94cc_t termForw2Char;
95#endif
96
97#ifndef VSTATUS
98cc_t termAytChar;
99#endif
100
101/*
102 * initialize the terminal data structures.
103 */
104void init_terminal(void) {
105 if (ttyoring.init(2*BUFSIZ, ttysink, NULL) != 1) {
106 exit(1);
107 }
108 if (ttyiring.init(BUFSIZ, NULL, ttysrc) != 1) {
109 exit(1);
110 }
111 autoflush = TerminalAutoFlush();
112}
113
114
115/*
116 * Send as much data as possible to the terminal.
117 * if arg "drop" is nonzero, drop data on the floor instead.
118 *
119 * Return value:
120 * -1: No useful work done, data waiting to go out.
121 * 0: No data was waiting, so nothing was done.
122 * 1: All waiting data was written out.
123 * n: All data - n was written out.
124 */
125int ttyflush(int drop) {
126 datasink *s = NULL;
127 if (drop) {
128 TerminalFlushOutput();
129 s = ttyoring.setsink(nullsink);
130 }
131 int rv = ttyoring.flush();
132 if (s) ttyoring.setsink(s);
133 return rv;
134}
135
136
137
138/*
139 * These routines decides on what the mode should be (based on the values
140 * of various global variables).
141 */
142int getconnmode(void) {
143 extern int linemode;
144 int mode = 0;
145#ifdef KLUDGELINEMODE
146 extern int kludgelinemode;
147#endif
148
149 if (In3270)
150 return(MODE_FLOW);
151
152 if (my_want_state_is_dont(TELOPT_ECHO))
153 mode |= MODE_ECHO;
154
155 if (localflow)
156 mode |= MODE_FLOW;
157
158 if (my_want_state_is_will(TELOPT_BINARY))
159 mode |= MODE_INBIN;
160
161 if (his_want_state_is_will(TELOPT_BINARY))
162 mode |= MODE_OUTBIN;
163
164#ifdef KLUDGELINEMODE
165 if (kludgelinemode) {
166 if (my_want_state_is_dont(TELOPT_SGA)) {
167 mode |= (MODE_TRAPSIG|MODE_EDIT);
168 if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) {
169 mode &= ~MODE_ECHO;
170 }
171 }
172 return(mode);
173 }
174#endif
175 if (my_want_state_is_will(TELOPT_LINEMODE))
176 mode |= linemode;
177 return(mode);
178}
179
180void setconnmode(int force) {
181 int newmode;
182
183 newmode = getconnmode()|(force?MODE_FORCE:0);
184
185 TerminalNewMode(newmode);
186
187}
188
189
190void setcommandmode(void) {
191 TerminalNewMode(-1);
192}
193
194
195/*********************/
196
197static int tout; /* Output file descriptor */
198static int tin; /* Input file descriptor */
199
200
201class ttysynk : public datasink {
202 public:
203 virtual int write(const char *buf, int len) {
204 return TerminalWrite(buf, len);
205 }
206 virtual int writeurg(const char *buf, int len) {
207 return TerminalWrite(buf, len);
208 }
209};
210
211class ttysorc : public ringbuf::source {
212 virtual int read(char *buf, int maxlen) {
213 int l = TerminalRead(buf, maxlen);
214 if (l<0 && errno==EWOULDBLOCK) l = 0;
215 else if (l==0 && MODE_LOCAL_CHARS(globalmode) && isatty(tin)) {
216 /* EOF detection for line mode!!!! */
217 /* must be an EOF... */
218 *buf = termEofChar;
219 l = 1;
220 }
221 return l;
222 }
223};
224
225static ttysynk chan1;
226static ttysorc chan2;
227datasink *ttysink = &chan1;
228ringbuf::source *ttysrc = &chan2;
229
230
231struct termios old_tc;
232struct termios new_tc;
233
234#ifndef TCSANOW
235
236#if defined(TCSETS)
237#define TCSANOW TCSETS
238#define TCSADRAIN TCSETSW
239#define tcgetattr(f, t) ioctl(f, TCGETS, (char *)t)
240
241#elif defined(TCSETA)
242#define TCSANOW TCSETA
243#define TCSADRAIN TCSETAW
244#define tcgetattr(f, t) ioctl(f, TCGETA, (char *)t)
245
246#else
247#define TCSANOW TIOCSETA
248#define TCSADRAIN TIOCSETAW
249#define tcgetattr(f, t) ioctl(f, TIOCGETA, (char *)t)
250
251#endif
252
253#define tcsetattr(f, a, t) ioctl(f, a, (char *)t)
254#define cfgetospeed(ptr) ((ptr)->c_cflag&CBAUD)
255#ifdef CIBAUD
256#define cfgetispeed(ptr) (((ptr)->c_cflag&CIBAUD) >> IBSHIFT)
257#else
258#define cfgetispeed(ptr) cfgetospeed(ptr)
259#endif
260
261#endif /* no TCSANOW */
262
263
264static void susp(int sig);
265
266void tlink_init(void) {
267#ifdef SIGTSTP
268 signal(SIGTSTP, susp);
269#endif
270 tout = fileno(stdout);
271 tin = fileno(stdin);
272}
273
274int tlink_getifd(void) {
275 return tin;
276}
277
278int tlink_getofd(void) {
279 return tout;
280}
281
282static int TerminalWrite(const char *buf, int n) {
283 int r;
284 do {
285 r = write(tout, buf, n);
286 } while (r<0 && errno==EINTR);
287 if (r<0 && (errno==ENOBUFS || errno==EWOULDBLOCK)) r = 0;
288 return r;
289}
290
291static int TerminalRead(char *buf, int n) {
292 int r;
293 do {
294 r = read(tin, buf, n);
295 } while (r<0 && errno==EINTR);
296 return r;
297}
298
299#ifdef SIGTSTP
300static void susp(int /*sig*/) {
301 if ((rlogin != _POSIX_VDISABLE) && rlogin_susp())
302 return;
303 if (localchars)
304 sendsusp();
305}
306#endif
307
308/*
309 * TerminalNewMode - set up terminal to a specific mode.
310 * MODE_ECHO: do local terminal echo
311 * MODE_FLOW: do local flow control
312 * MODE_TRAPSIG: do local mapping to TELNET IAC sequences
313 * MODE_EDIT: do local line editing
314 *
315 * Command mode:
316 * MODE_ECHO|MODE_EDIT|MODE_FLOW|MODE_TRAPSIG
317 * local echo
318 * local editing
319 * local xon/xoff
320 * local signal mapping
321 *
322 * Linemode:
323 * local/no editing
324 * Both Linemode and Single Character mode:
325 * local/remote echo
326 * local/no xon/xoff
327 * local/no signal mapping
328 */
329
330void TerminalNewMode(int f)
331{
332 static int prevmode = 0;
333 struct termios tmp_tc;
334
335 int onoff;
336 int old;
337 cc_t esc;
338
339 globalmode = f&~MODE_FORCE;
340 if (prevmode == f)
341 return;
342
343 /*
344 * Write any outstanding data before switching modes
345 * ttyflush() returns 0 only when there is no more data
346 * left to write out, it returns -1 if it couldn't do
347 * anything at all, otherwise it returns 1 + the number
348 * of characters left to write.
349 */
350 old = ttyflush(SYNCHing|flushout);
351 if (old < 0 || old > 1) {
352 tcgetattr(tin, &tmp_tc);
353 do {
354 /*
355 * Wait for data to drain, then flush again.
356 */
357 tcsetattr(tin, TCSADRAIN, &tmp_tc);
358 old = ttyflush(SYNCHing|flushout);
359 } while (old < 0 || old > 1);
360 }
361
362 old = prevmode;
363 prevmode = f&~MODE_FORCE;
364 tmp_tc = new_tc;
365
366 if (f&MODE_ECHO) {
367 tmp_tc.c_lflag |= ECHO;
368 tmp_tc.c_oflag |= ONLCR;
369 if (crlf)
370 tmp_tc.c_iflag |= ICRNL;
371 }
372 else {
373 tmp_tc.c_lflag &= ~ECHO;
374 tmp_tc.c_oflag &= ~ONLCR;
375 if (crlf) tmp_tc.c_iflag &= ~ICRNL;
376 }
377
378 if ((f&MODE_FLOW) == 0) {
379 tmp_tc.c_iflag &= ~(IXANY|IXOFF|IXON);
380 }
381 else {
382 tmp_tc.c_iflag |= IXANY|IXOFF|IXON;
383 }
384
385 if ((f&MODE_TRAPSIG) == 0) {
386 tmp_tc.c_lflag &= ~ISIG;
387 localchars = 0;
388 }
389 else {
390 tmp_tc.c_lflag |= ISIG;
391 localchars = 1;
392 }
393
394 if (f&MODE_EDIT) {
395 tmp_tc.c_lflag |= ICANON;
396 }
397 else {
398 tmp_tc.c_lflag &= ~ICANON;
399 tmp_tc.c_iflag &= ~ICRNL;
400 tmp_tc.c_cc[VMIN] = 1;
401 tmp_tc.c_cc[VTIME] = 0;
402 }
403
404 if ((f&(MODE_EDIT|MODE_TRAPSIG)) == 0) {
405#ifdef VLNEXT
406 tmp_tc.c_cc[VLNEXT] = (cc_t)(_POSIX_VDISABLE);
407#endif
408 }
409
410 if (f&MODE_SOFT_TAB) {
411#ifdef OXTABS
412 tmp_tc.c_oflag |= OXTABS;
413#endif
414#ifdef TABDLY
415 tmp_tc.c_oflag &= ~TABDLY;
416 tmp_tc.c_oflag |= TAB3;
417#endif
418 }
419 else {
420#ifdef OXTABS
421 tmp_tc.c_oflag &= ~OXTABS;
422#endif
423#ifdef TABDLY
424 tmp_tc.c_oflag &= ~TABDLY;
425#endif
426 }
427
428 if (f&MODE_LIT_ECHO) {
429#ifdef ECHOCTL
430 tmp_tc.c_lflag &= ~ECHOCTL;
431#endif
432 }
433 else {
434#ifdef ECHOCTL
435 tmp_tc.c_lflag |= ECHOCTL;
436#endif
437 }
438
439 if (f == -1) {
440 onoff = 0;
441 }
442 else {
443 if (f & MODE_INBIN) {
444 tmp_tc.c_iflag &= ~ISTRIP;
445 }
446 else {
447 // Commented this out 5/97 so it works with 8-bit characters
448 // ...and put it back 12/99 because it violates the RFC and
449 // breaks SunOS.
450 tmp_tc.c_iflag |= ISTRIP;
451 }
452 if (f & MODE_OUTBIN) {
453 tmp_tc.c_cflag &= ~(CSIZE|PARENB);
454 tmp_tc.c_cflag |= CS8;
455 tmp_tc.c_oflag &= ~OPOST;
456 } else {
457 tmp_tc.c_cflag &= ~(CSIZE|PARENB);
458 tmp_tc.c_cflag |= old_tc.c_cflag & (CSIZE|PARENB);
459 tmp_tc.c_oflag |= OPOST;
460 }
461 onoff = 1;
462 }
463
464 if (f != -1) {
465#ifdef SIGTSTP
466 signal(SIGTSTP, susp);
467#endif /* SIGTSTP */
468
469#ifdef SIGINFO
470 signal(SIGINFO, ayt);
471#endif SIGINFO
472
473#if defined(NOKERNINFO)
474 tmp_tc.c_lflag |= NOKERNINFO;
475#endif
476 /*
477 * We don't want to process ^Y here. It's just another
478 * character that we'll pass on to the back end. It has
479 * to process it because it will be processed when the
480 * user attempts to read it, not when we send it.
481 */
482#ifdef VDSUSP
483 tmp_tc.c_cc[VDSUSP] = (cc_t)(_POSIX_VDISABLE);
484#endif
485 /*
486 * If the VEOL character is already set, then use VEOL2,
487 * otherwise use VEOL.
488 */
489 esc = (rlogin != _POSIX_VDISABLE) ? rlogin : escapechar;
490 if ((tmp_tc.c_cc[VEOL] != esc)
491#ifdef VEOL2
492 && (tmp_tc.c_cc[VEOL2] != esc)
493#endif
494 ) {
495 if (tmp_tc.c_cc[VEOL] == (cc_t)(_POSIX_VDISABLE))
496 tmp_tc.c_cc[VEOL] = esc;
497#ifdef VEOL2
498 else if (tmp_tc.c_cc[VEOL2] == (cc_t)(_POSIX_VDISABLE))
499 tmp_tc.c_cc[VEOL2] = esc;
500#endif
501 }
502 }
503 else {
504
505#ifdef SIGINFO
506 signal(SIGINFO, ayt_status);
507#endif SIGINFO
508
509#ifdef SIGTSTP
510 signal(SIGTSTP, SIG_DFL);
511/* (void) sigsetmask(sigblock(0) & ~(1<<(SIGTSTP-1))); */
512#endif /* SIGTSTP */
513
514 tmp_tc = old_tc;
515 }
516 if (tcsetattr(tin, TCSADRAIN, &tmp_tc) < 0)
517 tcsetattr(tin, TCSANOW, &tmp_tc);
518
519 ioctl(tin, FIONBIO, (char *)&onoff);
520 ioctl(tout, FIONBIO, (char *)&onoff);
521
522#if defined(TN3270)
523 if (noasynchtty == 0) {
524 ioctl(tin, FIOASYNC, (char *)&onoff);
525 }
526#endif /* defined(TN3270) */
527
528}
529
530#ifndef B19200
531#define B19200 B9600
532#endif
533
534#ifndef B38400
535#define B38400 B19200
536#endif
537
538#ifndef B57600
539#define B57600 B38400
540#endif
541
542#ifndef B115200
543#define B115200 B57600
544#endif
545
546/*
547 * This code assumes that the values B0, B50, B75...
548 * are in ascending order. They do not have to be
549 * contiguous.
550 */
551struct termspeeds {
552 long speed;
553 long value;
554} termspeeds[] = {
555 { 0, B0 }, { 50, B50 }, { 75, B75 },
556 { 110, B110 }, { 134, B134 }, { 150, B150 },
557 { 200, B200 }, { 300, B300 }, { 600, B600 },
558 { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
559 { 4800, B4800 }, { 9600, B9600 }, { 19200, B19200 },
560 { 38400, B38400 }, { 57600, B57600 }, { 115200, B115200 },
561 { -1, B115200 }
562};
563
564void TerminalSpeeds(long *ispeed, long *ospeed) {
565 register struct termspeeds *tp;
566 register long in, out;
567
568 out = cfgetospeed(&old_tc);
569 in = cfgetispeed(&old_tc);
570 if (in == 0)
571 in = out;
572
573 tp = termspeeds;
574 while ((tp->speed != -1) && (tp->value < in))
575 tp++;
576 *ispeed = tp->speed;
577
578 tp = termspeeds;
579 while ((tp->speed != -1) && (tp->value < out))
580 tp++;
581 *ospeed = tp->speed;
582}
583
584int TerminalWindowSize(long *rows, long *cols) {
585#ifdef TIOCGWINSZ
586 struct winsize ws;
587
588 if (ioctl(fileno(stdin), TIOCGWINSZ, (char *)&ws) >= 0) {
589 *rows = ws.ws_row;
590 *cols = ws.ws_col;
591 return 1;
592 }
593#endif /* TIOCGWINSZ */
594 return 0;
595}
596
597
598/*
599 * EmptyTerminal - called to make sure that the terminal buffer is
600 * empty. Note that we consider the buffer to run all the way to the
601 * kernel (thus the select).
602 */
603void EmptyTerminal(void) {
604 fd_set o;
605 FD_ZERO(&o);
606
607 if (TTYBYTES() == 0) {
608 FD_SET(tout, &o);
609 select(tout+1, NULL, &o, NULL, NULL); /* wait for TTLOWAT */
610 }
611 else {
612 while (TTYBYTES()) {
613 ttyflush(0);
614 FD_SET(tout, &o);
615 select(tout+1, NULL, &o, NULL, NULL); /* wait for TTLOWAT */
616 }
617 }
618}
619
620int
621TerminalAutoFlush(void)
622{
623#if defined(LNOFLSH)
624 int flush;
625
626 ioctl(tin, TIOCLGET, (char *)&flush);
627 return !(flush&LNOFLSH); /* if LNOFLSH, no autoflush */
628#else /* LNOFLSH */
629 return 1;
630#endif /* LNOFLSH */
631}
632
633/*
634 * Flush output to the terminal
635 */
636 void
637TerminalFlushOutput()
638{
639#ifdef TIOCFLUSH
640 (void) ioctl(fileno(stdout), TIOCFLUSH, (char *) 0);
641#else
642 (void) ioctl(fileno(stdout), TCFLSH, (char *) 0);
643#endif
644}
645
646 void
647TerminalSaveState()
648{
649#ifndef USE_TERMIO
650 ioctl(0, TIOCGETP, (char *)&ottyb);
651 ioctl(0, TIOCGETC, (char *)&otc);
652 ioctl(0, TIOCGLTC, (char *)&oltc);
653 ioctl(0, TIOCLGET, (char *)&olmode);
654
655 ntc = otc;
656 nltc = oltc;
657 nttyb = ottyb;
658
659#else /* USE_TERMIO */
660 tcgetattr(0, &old_tc);
661
662 new_tc = old_tc;
663
664#ifndef VDISCARD
665 termFlushChar = CONTROL('O');
666#endif
667#ifndef VWERASE
668 termWerasChar = CONTROL('W');
669#endif
670#ifndef VREPRINT
671 termRprntChar = CONTROL('R');
672#endif
673#ifndef VLNEXT
674 termLiteralNextChar = CONTROL('V');
675#endif
676#ifndef VSTART
677 termStartChar = CONTROL('Q');
678#endif
679#ifndef VSTOP
680 termStopChar = CONTROL('S');
681#endif
682#ifndef VSTATUS
683 termAytChar = CONTROL('T');
684#endif
685#endif /* USE_TERMIO */
686}
687
688void TerminalDefaultChars(void) {
689#ifndef USE_TERMIO
690 ntc = otc;
691 nltc = oltc;
692 nttyb.sg_kill = ottyb.sg_kill;
693 nttyb.sg_erase = ottyb.sg_erase;
694#else /* USE_TERMIO */
695 memcpy(new_tc.c_cc, old_tc.c_cc, sizeof(old_tc.c_cc));
696#ifndef VDISCARD
697 termFlushChar = CONTROL('O');
698#endif
699#ifndef VWERASE
700 termWerasChar = CONTROL('W');
701#endif
702#ifndef VREPRINT
703 termRprntChar = CONTROL('R');
704#endif
705#ifndef VLNEXT
706 termLiteralNextChar = CONTROL('V');
707#endif
708#ifndef VSTART
709 termStartChar = CONTROL('Q');
710#endif
711#ifndef VSTOP
712 termStopChar = CONTROL('S');
713#endif
714#ifndef VSTATUS
715 termAytChar = CONTROL('T');
716#endif
717#endif /* USE_TERMIO */
718}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.h
new file mode 100644
index 0000000..8fcfb83
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.h
@@ -0,0 +1,11 @@
1#define TTYADD(c) { if (!(SYNCHing||flushout)) ttyoring.putch(c); }
2#define TTYBYTES() (ttyoring.full_count())
3#define TTYROOM() (ttyoring.empty_count())
4
5void tlink_init(void);
6
7void EmptyTerminal(void);
8
9
10int tlink_getifd(void);
11int tlink_getofd(void);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.o
new file mode 100644
index 0000000..1d0c95a
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/terminal.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/tn3270.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/tn3270.cc
new file mode 100644
index 0000000..19f13fe
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/tn3270.cc
@@ -0,0 +1,366 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)tn3270.c 5.2 (Berkeley) 3/1/91
36 */
37char tn3270_rcsid[] =
38 "$Id: tn3270.cc,v 1.9 1996/08/13 09:08:34 dholland Exp $";
39
40#include <sys/types.h>
41#include <arpa/telnet.h>
42
43#include "defines.h"
44#include "ring.h"
45#include "externs.h"
46#include "proto.h"
47
48#if defined(TN3270)
49
50#include "../tn3270/ctlr/screen.h"
51#include "../tn3270/general/globals.h"
52
53#include "../tn3270/telextrn.h"
54#include "../tn3270/ctlr/externs.h"
55
56int HaveInput; /* There is input available to scan */
57int cursesdata; /* Do we dump curses data? */
58int sigiocount; /* Number of times we got a SIGIO */
59
60char tline[200];
61char *transcom = 0; /* transparent mode command (default: none) */
62
63char Ibuf[8*BUFSIZ], *Ifrontp, *Ibackp;
64
65static char sb_terminal[] = { IAC, SB,
66 TELOPT_TTYPE, TELQUAL_IS,
67 'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2',
68 IAC, SE };
69#define SBTERMMODEL 13
70
71static int Sent3270TerminalType; /* Have we said we are a 3270? */
72
73#endif /* defined(TN3270) */
74
75
76void init_3270(void) {
77#if defined(TN3270)
78 HaveInput = 0;
79 sigiocount = 0;
80 Sent3270TerminalType = 0;
81 Ifrontp = Ibackp = Ibuf;
82 init_ctlr(); /* Initialize some things */
83 init_keyboard();
84 init_screen();
85 init_system();
86#endif /* TN3270 */
87}
88
89#if defined(TN3270)
90
91/*
92 * DataToNetwork - queue up some data to go to network. If "done" is set,
93 * then when last byte is queued, we add on an IAC EOR sequence (so,
94 * don't call us with "done" until you want that done...)
95 *
96 * We actually do send all the data to the network buffer, since our
97 * only client needs for us to do that.
98 */
99
100/*
101 * buffer: where the data is
102 * count: how much to send
103 * done: is this the last of a logical block
104 */
105int DataToNetwork(char *buffer, int count, int done) {
106 register int loop, c;
107 int origCount;
108
109 origCount = count;
110
111 while (count) {
112 /* If not enough room for EORs, IACs, etc., wait */
113 if (NETROOM() < 6) {
114 fd_set o;
115
116 FD_ZERO(&o);
117 netflush();
118 while (NETROOM() < 6) {
119 FD_SET(net, &o);
120 select(net+1, (fd_set *) 0, &o, (fd_set *) 0,
121 (struct timeval *) 0);
122 netflush();
123 }
124 }
125 c = ring_empty_count(&netoring);
126 if (c > count) {
127 c = count;
128 }
129 loop = c;
130 while (loop) {
131 if (((unsigned char)*buffer) == IAC) {
132 break;
133 }
134 buffer++;
135 loop--;
136 }
137 if ((c = c-loop)) {
138 netoring.supply_data(buffer-c, c);
139 count -= c;
140 }
141 if (loop) {
142 NET2ADD(IAC, IAC);
143 count--;
144 buffer++;
145 }
146 }
147
148 if (done) {
149 NET2ADD(IAC, EOR);
150 netflush(); /* try to move along as quickly as ... */
151 }
152 return(origCount - count);
153}
154
155void inputAvailable(void) {
156 HaveInput = 1;
157 sigiocount++;
158}
159
160void outputPurge(void) {
161 ttyflush(1);
162}
163
164
165/*
166 * The following routines are places where the various tn3270
167 * routines make calls into telnet.c.
168 */
169
170/*
171 * DataToTerminal - queue up some data to go to terminal.
172 *
173 * Note: there are people who call us and depend on our processing
174 * *all* the data at one time (thus the select).
175 */
176
177/*
178 * buffer: where the data is
179 * count: how much to send
180 */
181int DataToTerminal(char *buffer, int count) {
182 register int c;
183 int origCount;
184
185 origCount = count;
186
187 while (count) {
188 if (TTYROOM() == 0) {
189
190 fd_set o;
191 FD_ZERO(&o);
192 ttyflush(0);
193 while (TTYROOM() == 0) {
194 FD_SET(tout, &o);
195 select(tout+1, NULL, &o, NULL, NULL);
196 ttyflush(0);
197 }
198 }
199 c = TTYROOM();
200 if (c > count) {
201 c = count;
202 }
203 ttyoring.supply_data(buffer, c);
204 count -= c;
205 buffer += c;
206 }
207 return origCount;
208}
209
210
211/*
212 * Push3270 - Try to send data along the 3270 output (to screen) direction.
213 */
214int Push3270(void) {
215 int save = ring_full_count(&netiring);
216
217 if (save) {
218 if (Ifrontp+save > Ibuf+sizeof Ibuf) {
219 if (Ibackp != Ibuf) {
220 memcpy(Ibuf, Ibackp, Ifrontp-Ibackp);
221 Ifrontp -= (Ibackp-Ibuf);
222 Ibackp = Ibuf;
223 }
224 }
225 if (Ifrontp+save < Ibuf+sizeof Ibuf) {
226 (void)telrcv();
227 }
228 }
229 return save != ring_full_count(&netiring);
230}
231
232
233/*
234 * Finish3270 - get the last dregs of 3270 data out to the terminal
235 * before quitting.
236 */
237void Finish3270(void) {
238 while (Push3270() || !DoTerminalOutput()) {
239 HaveInput = 0;
240 }
241}
242
243
244/* StringToTerminal - output a null terminated string to the terminal */
245void StringToTerminal(char *s) {
246 int count = strlen(s);
247 if (count) {
248 DataToTerminal(s, count); /* we know it always goes... */
249 }
250}
251
252
253#if ((!defined(NOT43)) || defined(PUTCHAR))
254/* _putchar - output a single character to the terminal. This name is so that
255 * curses(3x) can call us to send out data.
256 */
257
258void _putchar(char c) {
259#if defined(sun) /* SunOS 4.0 bug */
260 c &= 0x7f;
261#endif
262 if (cursesdata) {
263 Dump('>', &c, 1);
264 }
265 if (!TTYROOM()) {
266 DataToTerminal(&c, 1);
267 }
268 else {
269 TTYADD(c);
270 }
271}
272#endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
273
274void SetIn3270(void) {
275 if (Sent3270TerminalType && my_want_state_is_will(TELOPT_BINARY)
276 && my_want_state_is_do(TELOPT_BINARY) && !donebinarytoggle)
277 {
278 if (!In3270) {
279 In3270 = 1;
280 Init3270(); /* Initialize 3270 functions */
281 /* initialize terminal key mapping */
282 InitTerminal(); /* Start terminal going */
283 setconnmode(0);
284 }
285 }
286 else {
287 if (In3270) {
288 StopScreen(1);
289 In3270 = 0;
290 Stop3270(); /* Tell 3270 we aren't here anymore */
291 setconnmode(0);
292 }
293 }
294}
295
296/*
297 * tn3270_ttype()
298 *
299 * Send a response to a terminal type negotiation.
300 *
301 * Return '0' if no more responses to send; '1' if a response sent.
302 */
303
304int tn3270_ttype(void) {
305 /*
306 * Try to send a 3270 type terminal name. Decide which one based
307 * on the format of our screen, and (in the future) color
308 * capaiblities.
309 */
310 InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */
311 if ((MaxNumberLines >= 24) && (MaxNumberColumns >= 80)) {
312 Sent3270TerminalType = 1;
313 if ((MaxNumberLines >= 27) && (MaxNumberColumns >= 132)) {
314 MaxNumberLines = 27;
315 MaxNumberColumns = 132;
316 sb_terminal[SBTERMMODEL] = '5';
317 }
318 else if (MaxNumberLines >= 43) {
319 MaxNumberLines = 43;
320 MaxNumberColumns = 80;
321 sb_terminal[SBTERMMODEL] = '4';
322 }
323 else if (MaxNumberLines >= 32) {
324 MaxNumberLines = 32;
325 MaxNumberColumns = 80;
326 sb_terminal[SBTERMMODEL] = '3';
327 }
328 else {
329 MaxNumberLines = 24;
330 MaxNumberColumns = 80;
331 sb_terminal[SBTERMMODEL] = '2';
332 }
333 NumberLines = 24; /* before we start out... */
334 NumberColumns = 80;
335 ScreenSize = NumberLines*NumberColumns;
336 if ((MaxNumberLines*MaxNumberColumns) > MAXSCREENSIZE) {
337 ExitString("Programming error: MAXSCREENSIZE too small.\n",
338 1);
339 /*NOTREACHED*/
340 }
341 printsub('>', sb_terminal+2, sizeof sb_terminal-2);
342 netoring.supply_data(sb_terminal, sizeof(sb_terminal));
343 return 1;
344 }
345 else {
346 return 0;
347 }
348}
349
350int settranscom(int argc, char *argv[]) {
351 int i;
352 if (argc == 1 && transcom) {
353 transcom = 0;
354 }
355 if (argc == 1) {
356 return;
357 }
358 transcom = tline;
359 strcpy(transcom, argv[1]);
360 for (i = 2; i < argc; ++i) {
361 strcat(transcom, " ");
362 strcat(transcom, argv[i]);
363 }
364}
365
366#endif /* defined(TN3270) */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/tn3270.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/tn3270.o
new file mode 100644
index 0000000..5dc7fab
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/tn3270.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/types.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/types.h
new file mode 100644
index 0000000..00cddfb
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/types.h
@@ -0,0 +1,52 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)types.h 5.1 (Berkeley) 9/14/90
34 * $Id: types.h,v 1.2 1996/07/27 00:45:54 dholland Exp $
35 */
36
37typedef struct {
38 char *modedescriptions;
39 char modetype;
40} Modelist;
41
42extern Modelist modelist[];
43
44typedef struct {
45 int system; /* what the current time is */
46 int echotoggle; /* last time user entered echo character */
47 int modenegotiated; /* last time operating mode negotiated */
48 int didnetreceive; /* last time we read data from network */
49 int gotDM; /* when did we last see a data mark */
50} Clocks;
51
52extern Clocks clocks;
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/utilities.cc b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/utilities.cc
new file mode 100644
index 0000000..0448f0a
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/utilities.cc
@@ -0,0 +1,673 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)utilities.c 5.3 (Berkeley) 3/22/91
36 */
37char util_rcsid[] =
38 "$Id: utilities.cc,v 1.19 1999/12/12 15:33:40 dholland Exp $";
39
40#define TELOPTS
41#define TELCMDS
42#define SLC_NAMES
43
44#include <arpa/telnet.h>
45#include <sys/types.h>
46#include <sys/time.h>
47#include <sys/socket.h>
48#include <unistd.h>
49#include <ctype.h>
50
51#include "ring.h"
52#include "defines.h"
53#include "externs.h"
54#include "proto.h"
55#include "terminal.h"
56
57FILE *NetTrace = 0; /* Not in bss, since needs to stay */ /* ? */
58char NetTraceFile[256] = "(standard output)";
59
60/*
61 * upcase()
62 *
63 * Upcase (in place) the argument.
64 */
65void upcase(char *str) {
66 for (int i=0; str[i]; i++) {
67 if (islower(str[i])) str[i] = toupper(str[i]);
68 }
69}
70
71/*
72 * The following are routines used to print out debugging information.
73 */
74
75void SetNetTrace(const char *file) {
76 if (NetTrace && NetTrace != stdout)
77 fclose(NetTrace);
78 if (file && strcmp(file, "-")) {
79 NetTrace = fopen(file, "w");
80 if (NetTrace) {
81 strcpy((char *)NetTraceFile, file);
82 return;
83 }
84 fprintf(stderr, "Cannot open %s.\n", file);
85 }
86 NetTrace = stdout;
87 strcpy((char *)NetTraceFile, "(standard output)");
88}
89
90#define BYTES_PER_LINE 32
91#define min(x,y) ((x<y)? x:y)
92
93void Dump(int direction, char *buffer, int length) {
94 char *pThis;
95 int offset;
96
97 offset = 0;
98
99 while (length) {
100 /* print one line */
101 fprintf(NetTrace, "%c 0x%x\t", direction, offset);
102 pThis = buffer;
103 if (0 /*prettydump*/) {
104 buffer = buffer + min(length, BYTES_PER_LINE/2);
105 while (pThis < buffer) {
106 fprintf(NetTrace, "%c%.2x",
107 (((*pThis)&0xff) == 0xff) ? '*' : ' ',
108 (*pThis)&0xff);
109 pThis++;
110 }
111 length -= BYTES_PER_LINE/2;
112 offset += BYTES_PER_LINE/2;
113 }
114 else {
115 buffer = buffer + min(length, BYTES_PER_LINE);
116 while (pThis < buffer) {
117 fprintf(NetTrace, "%.2x", (*pThis)&0xff);
118 pThis++;
119 }
120 length -= BYTES_PER_LINE;
121 offset += BYTES_PER_LINE;
122 }
123 if (NetTrace == stdout) {
124 fprintf(NetTrace, "\r\n");
125 }
126 else {
127 fprintf(NetTrace, "\n");
128 }
129 if (length < 0) {
130 fflush(NetTrace);
131 return;
132 }
133 /* find next unique line */
134 }
135 fflush(NetTrace);
136}
137
138
139void printoption(const char *direction, int cmd, int option) {
140 if (!showoptions)
141 return;
142 if (cmd == IAC) {
143 if (TELCMD_OK(option))
144 fprintf(NetTrace, "%s IAC %s", direction, TELCMD(option));
145 else
146 fprintf(NetTrace, "%s IAC %d", direction, option);
147 }
148 else {
149 const char *fmt;
150 fmt = (cmd == WILL) ? "WILL" : (cmd == WONT) ? "WONT" :
151 (cmd == DO) ? "DO" : (cmd == DONT) ? "DONT" : 0;
152 if (fmt) {
153 fprintf(NetTrace, "%s %s ", direction, fmt);
154 if (TELOPT_OK(option))
155 fprintf(NetTrace, "%s", TELOPT(option));
156 else if (option == TELOPT_EXOPL)
157 fprintf(NetTrace, "EXOPL");
158 else
159 fprintf(NetTrace, "%d", option);
160 }
161 else
162 fprintf(NetTrace, "%s %d %d", direction, cmd, option);
163 }
164 if (NetTrace == stdout)
165 fprintf(NetTrace, "\r\n");
166 else
167 fprintf(NetTrace, "\n");
168 return;
169}
170
171void optionstatus(void) {
172 int i;
173 extern char will_wont_resp[], do_dont_resp[];
174
175 for (i = 0; i < 256; i++) {
176 if (do_dont_resp[i]) {
177 if (TELOPT_OK(i))
178 printf("resp DO_DONT %s: %d\n", TELOPT(i), do_dont_resp[i]);
179 else if (TELCMD_OK(i))
180 printf("resp DO_DONT %s: %d\n", TELCMD(i), do_dont_resp[i]);
181 else
182 printf("resp DO_DONT %d: %d\n", i, do_dont_resp[i]);
183 if (my_want_state_is_do(i)) {
184 if (TELOPT_OK(i))
185 printf("want DO %s\n", TELOPT(i));
186 else if (TELCMD_OK(i))
187 printf("want DO %s\n", TELCMD(i));
188 else
189 printf("want DO %d\n", i);
190 }
191 else {
192 if (TELOPT_OK(i))
193 printf("want DONT %s\n", TELOPT(i));
194 else if (TELCMD_OK(i))
195 printf("want DONT %s\n", TELCMD(i));
196 else
197 printf("want DONT %d\n", i);
198 }
199 }
200 else {
201 if (my_state_is_do(i)) {
202 if (TELOPT_OK(i))
203 printf(" DO %s\n", TELOPT(i));
204 else if (TELCMD_OK(i))
205 printf(" DO %s\n", TELCMD(i));
206 else
207 printf(" DO %d\n", i);
208 }
209 }
210 if (will_wont_resp[i]) {
211 if (TELOPT_OK(i))
212 printf("resp WILL_WONT %s: %d\n", TELOPT(i), will_wont_resp[i]);
213 else if (TELCMD_OK(i))
214 printf("resp WILL_WONT %s: %d\n", TELCMD(i), will_wont_resp[i]);
215 else
216 printf("resp WILL_WONT %d: %d\n",
217 i, will_wont_resp[i]);
218 if (my_want_state_is_will(i)) {
219 if (TELOPT_OK(i))
220 printf("want WILL %s\n", TELOPT(i));
221 else if (TELCMD_OK(i))
222 printf("want WILL %s\n", TELCMD(i));
223 else
224 printf("want WILL %d\n", i);
225 }
226 else {
227 if (TELOPT_OK(i))
228 printf("want WONT %s\n", TELOPT(i));
229 else if (TELCMD_OK(i))
230 printf("want WONT %s\n", TELCMD(i));
231 else
232 printf("want WONT %d\n", i);
233 }
234 }
235 else {
236 if (my_state_is_will(i)) {
237 if (TELOPT_OK(i))
238 printf(" WILL %s\n", TELOPT(i));
239 else if (TELCMD_OK(i))
240 printf(" WILL %s\n", TELCMD(i));
241 else
242 printf(" WILL %d\n", i);
243 }
244 }
245 }
246
247}
248
249/* direction: '<' or '>' */
250/* pointer: where suboption data sits */
251/* length: length of suboption data */
252void printsub(int direction, unsigned char *pointer, int length) {
253 register int i = 0;
254
255 extern int want_status_response;
256
257 if (showoptions || direction == 0 ||
258 (want_status_response && (pointer[0] == TELOPT_STATUS))) {
259 if (direction) {
260 fprintf(NetTrace, "%s IAC SB ",
261 (direction == '<')? "RCVD":"SENT");
262 if (length >= 3) {
263 register int j;
264
265 i = pointer[length-2];
266 j = pointer[length-1];
267
268 if (i != IAC || j != SE) {
269 fprintf(NetTrace, "(terminated by ");
270 if (TELOPT_OK(i))
271 fprintf(NetTrace, "%s ", TELOPT(i));
272 else if (TELCMD_OK(i))
273 fprintf(NetTrace, "%s ", TELCMD(i));
274 else
275 fprintf(NetTrace, "%d ", i);
276 if (TELOPT_OK(j))
277 fprintf(NetTrace, "%s", TELOPT(j));
278 else if (TELCMD_OK(j))
279 fprintf(NetTrace, "%s", TELCMD(j));
280 else
281 fprintf(NetTrace, "%d", j);
282 fprintf(NetTrace, ", not IAC SE!) ");
283 }
284 }
285 length -= 2;
286 }
287 if (length < 1) {
288 fprintf(NetTrace, "(Empty suboption???)");
289 return;
290 }
291 switch ((unsigned char)(pointer[0])) {
292 case TELOPT_TTYPE:
293 fprintf(NetTrace, "TERMINAL-TYPE ");
294 switch (pointer[1]) {
295 case TELQUAL_IS:
296 fprintf(NetTrace, "IS \"%.*s\"", length-2, (char *)pointer+2);
297 break;
298 case TELQUAL_SEND:
299 fprintf(NetTrace, "SEND");
300 break;
301 default:
302 fprintf(NetTrace,
303 "- unknown qualifier %d (0x%x).",
304 pointer[1], pointer[1]);
305 }
306 break;
307 case TELOPT_TSPEED:
308 fprintf(NetTrace, "TERMINAL-SPEED");
309 if (length < 2) {
310 fprintf(NetTrace, " (empty suboption???)");
311 break;
312 }
313 switch (pointer[1]) {
314 case TELQUAL_IS:
315 fprintf(NetTrace, " IS ");
316 fprintf(NetTrace, "%.*s", length-2, (char *)pointer+2);
317 break;
318 default:
319 if (pointer[1] == 1)
320 fprintf(NetTrace, " SEND");
321 else
322 fprintf(NetTrace, " %d (unknown)", pointer[1]);
323 for (i = 2; i < length; i++)
324 fprintf(NetTrace, " ?%d?", pointer[i]);
325 break;
326 }
327 break;
328
329 case TELOPT_LFLOW:
330 fprintf(NetTrace, "TOGGLE-FLOW-CONTROL");
331 if (length < 2) {
332 fprintf(NetTrace, " (empty suboption???)");
333 break;
334 }
335 switch (pointer[1]) {
336 case 0:
337 fprintf(NetTrace, " OFF"); break;
338 case 1:
339 fprintf(NetTrace, " ON"); break;
340 default:
341 fprintf(NetTrace, " %d (unknown)", pointer[1]);
342 }
343 for (i = 2; i < length; i++)
344 fprintf(NetTrace, " ?%d?", pointer[i]);
345 break;
346
347 case TELOPT_NAWS:
348 fprintf(NetTrace, "NAWS");
349 if (length < 2) {
350 fprintf(NetTrace, " (empty suboption???)");
351 break;
352 }
353 if (length == 2) {
354 fprintf(NetTrace, " ?%d?", pointer[1]);
355 break;
356 }
357 fprintf(NetTrace, " %d %d (%d)",
358 pointer[1], pointer[2],
359 (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
360 if (length == 4) {
361 fprintf(NetTrace, " ?%d?", pointer[3]);
362 break;
363 }
364 fprintf(NetTrace, " %d %d (%d)",
365 pointer[3], pointer[4],
366 (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
367 for (i = 5; i < length; i++)
368 fprintf(NetTrace, " ?%d?", pointer[i]);
369 break;
370
371 case TELOPT_LINEMODE:
372 fprintf(NetTrace, "LINEMODE ");
373 if (length < 2) {
374 fprintf(NetTrace, " (empty suboption???)");
375 break;
376 }
377 switch ((unsigned char)(pointer[1])) {
378 case WILL:
379 fprintf(NetTrace, "WILL ");
380 goto common;
381 case WONT:
382 fprintf(NetTrace, "WONT ");
383 goto common;
384 case DO:
385 fprintf(NetTrace, "DO ");
386 goto common;
387 case DONT:
388 fprintf(NetTrace, "DONT ");
389 common:
390 if (length < 3) {
391 fprintf(NetTrace, "(no option???)");
392 break;
393 }
394 switch ((unsigned char)(pointer[2])) {
395 case LM_FORWARDMASK:
396 fprintf(NetTrace, "Forward Mask");
397 for (i = 3; i < length; i++)
398 fprintf(NetTrace, " %x", pointer[i]);
399 break;
400 default:
401 fprintf(NetTrace, "%d (unknown)", pointer[2]);
402 for (i = 3; i < length; i++)
403 fprintf(NetTrace, " %d", pointer[i]);
404 break;
405 }
406 break;
407
408 case LM_SLC:
409 fprintf(NetTrace, "SLC");
410 for (i = 2; i < length - 2; i += 3) {
411 if (SLC_NAME_OK(pointer[i+SLC_FUNC]))
412 fprintf(NetTrace, " %s", SLC_NAME(pointer[i+SLC_FUNC]));
413 else
414 fprintf(NetTrace, " %d", pointer[i+SLC_FUNC]);
415 switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {
416 case SLC_NOSUPPORT:
417 fprintf(NetTrace, " NOSUPPORT"); break;
418 case SLC_CANTCHANGE:
419 fprintf(NetTrace, " CANTCHANGE"); break;
420 case SLC_VARIABLE:
421 fprintf(NetTrace, " VARIABLE"); break;
422 case SLC_DEFAULT:
423 fprintf(NetTrace, " DEFAULT"); break;
424 }
425 fprintf(NetTrace, "%s%s%s",
426 pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",
427 pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",
428 pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");
429 if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|
430 SLC_FLUSHOUT| SLC_LEVELBITS))
431 fprintf(NetTrace, "(0x%x)", pointer[i+SLC_FLAGS]);
432 fprintf(NetTrace, " %d;", pointer[i+SLC_VALUE]);
433 if ((pointer[i+SLC_VALUE] == IAC) &&
434 (pointer[i+SLC_VALUE+1] == IAC))
435 i++;
436 }
437 for (; i < length; i++)
438 fprintf(NetTrace, " ?%d?", pointer[i]);
439 break;
440
441 case LM_MODE:
442 fprintf(NetTrace, "MODE ");
443 if (length < 3) {
444 fprintf(NetTrace, "(no mode???)");
445 break;
446 }
447 {
448 char tbuf[64];
449 snprintf(tbuf, sizeof(tbuf), "%s%s%s%s%s",
450 pointer[2]&MODE_EDIT ? "|EDIT" : "",
451 pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
452 pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
453 pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
454 pointer[2]&MODE_ACK ? "|ACK" : "");
455 fprintf(NetTrace, "%s", tbuf[1] ? &tbuf[1] : "0");
456 }
457 if (pointer[2]&~(MODE_MASK))
458 fprintf(NetTrace, " (0x%x)", pointer[2]);
459 for (i = 3; i < length; i++)
460 fprintf(NetTrace, " ?0x%x?", pointer[i]);
461 break;
462 default:
463 fprintf(NetTrace, "%d (unknown)", pointer[1]);
464 for (i = 2; i < length; i++)
465 fprintf(NetTrace, " %d", pointer[i]);
466 }
467 break;
468
469 case TELOPT_STATUS: {
470 const char *cp;
471 int j, k;
472
473 fprintf(NetTrace, "STATUS");
474
475 switch (pointer[1]) {
476 default:
477 if (pointer[1] == TELQUAL_SEND)
478 fprintf(NetTrace, " SEND");
479 else
480 fprintf(NetTrace, " %d (unknown)", pointer[1]);
481 for (i = 2; i < length; i++)
482 fprintf(NetTrace, " ?%d?", pointer[i]);
483 break;
484 case TELQUAL_IS:
485 if (--want_status_response < 0)
486 want_status_response = 0;
487 if (NetTrace == stdout)
488 fprintf(NetTrace, " IS\r\n");
489 else
490 fprintf(NetTrace, " IS\n");
491
492 for (i = 2; i < length; i++) {
493 switch((unsigned char)(pointer[i])) {
494 case DO: cp = "DO"; goto common2;
495 case DONT: cp = "DONT"; goto common2;
496 case WILL: cp = "WILL"; goto common2;
497 case WONT: cp = "WONT"; goto common2;
498 common2:
499 i++;
500 if (TELOPT_OK((int)pointer[i]))
501 fprintf(NetTrace, " %s %s", cp, TELOPT(pointer[i]));
502 else
503 fprintf(NetTrace, " %s %d", cp, pointer[i]);
504
505 if (NetTrace == stdout)
506 fprintf(NetTrace, "\r\n");
507 else
508 fprintf(NetTrace, "\n");
509 break;
510
511 case SB:
512 fprintf(NetTrace, " SB ");
513 i++;
514 j = k = i;
515 while (j < length) {
516 if (pointer[j] == SE) {
517 if (j+1 == length)
518 break;
519 if (pointer[j+1] == SE)
520 j++;
521 else
522 break;
523 }
524 pointer[k++] = pointer[j++];
525 }
526 printsub(0, &pointer[i], k - i);
527 if (i < length) {
528 fprintf(NetTrace, " SE");
529 i = j;
530 } else
531 i = j - 1;
532
533 if (NetTrace == stdout)
534 fprintf(NetTrace, "\r\n");
535 else
536 fprintf(NetTrace, "\n");
537
538 break;
539
540 default:
541 fprintf(NetTrace, " %d", pointer[i]);
542 break;
543 }
544 }
545 break;
546 }
547 break;
548 }
549
550 case TELOPT_XDISPLOC:
551 fprintf(NetTrace, "X-DISPLAY-LOCATION ");
552 switch (pointer[1]) {
553 case TELQUAL_IS:
554 fprintf(NetTrace, "IS \"%.*s\"", length-2, (char *)pointer+2);
555 break;
556 case TELQUAL_SEND:
557 fprintf(NetTrace, "SEND");
558 break;
559 default:
560 fprintf(NetTrace, "- unknown qualifier %d (0x%x).",
561 pointer[1], pointer[1]);
562 }
563 break;
564
565 case TELOPT_ENVIRON:
566 fprintf(NetTrace, "ENVIRON ");
567 switch (pointer[1]) {
568 case TELQUAL_IS:
569 fprintf(NetTrace, "IS ");
570 goto env_common;
571 case TELQUAL_SEND:
572 fprintf(NetTrace, "SEND ");
573 goto env_common;
574 case TELQUAL_INFO:
575 fprintf(NetTrace, "INFO ");
576 env_common:
577 {
578 register int noquote = 2;
579 for (i = 2; i < length; i++ ) {
580 switch (pointer[i]) {
581 case ENV_VAR:
582 if (pointer[1] == TELQUAL_SEND)
583 goto def_case;
584 fprintf(NetTrace, "\" VAR " + noquote);
585 noquote = 2;
586 break;
587
588 case ENV_VALUE:
589 fprintf(NetTrace, "\" VALUE " + noquote);
590 noquote = 2;
591 break;
592
593 case ENV_ESC:
594 fprintf(NetTrace, "\" ESC " + noquote);
595 noquote = 2;
596 break;
597
598 default:
599 def_case:
600 if (isprint(pointer[i]) && pointer[i] != '"') {
601 if (noquote) {
602 putc('"', NetTrace);
603 noquote = 0;
604 }
605 putc(pointer[i], NetTrace);
606 } else {
607 fprintf(NetTrace, "\" %03o " + noquote,
608 pointer[i]);
609 noquote = 2;
610 }
611 break;
612 }
613 }
614 if (!noquote)
615 putc('"', NetTrace);
616 break;
617 }
618 }
619 break;
620
621 default:
622 if (TELOPT_OK(pointer[0]))
623 fprintf(NetTrace, "%s (unknown)", TELOPT(pointer[0]));
624 else
625 fprintf(NetTrace, "%d (unknown)", pointer[i]);
626 for (i = 1; i < length; i++)
627 fprintf(NetTrace, " %d", pointer[i]);
628 break;
629 }
630 if (direction) {
631 if (NetTrace == stdout)
632 fprintf(NetTrace, "\r\n");
633 else
634 fprintf(NetTrace, "\n");
635 }
636 }
637}
638
639void SetForExit(void) {
640 setconnmode(0);
641#if defined(TN3270)
642 if (In3270) {
643 Finish3270();
644 }
645#else /* defined(TN3270) */
646 do {
647 telrcv(); /* Process any incoming data */
648 EmptyTerminal();
649 } while (netiring.full_count()); /* While there is any */
650#endif /* defined(TN3270) */
651 setcommandmode();
652 fflush(stdout);
653 fflush(stderr);
654#if defined(TN3270)
655 if (In3270) {
656 StopScreen(1);
657 }
658#endif /* defined(TN3270) */
659 setconnmode(0);
660 EmptyTerminal(); /* Flush the path to the tty */
661 setcommandmode();
662}
663
664void Exit(int returnCode) {
665 SetForExit();
666 exit(returnCode);
667}
668
669void ExitString(const char *string, int returnCode) {
670 SetForExit();
671 fwrite(string, 1, strlen(string), stderr);
672 exit(returnCode);
673}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/utilities.o b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/utilities.o
new file mode 100644
index 0000000..0cc0eb1
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/utilities.o
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/Makefile b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/Makefile
new file mode 100644
index 0000000..9b80e98
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/Makefile
@@ -0,0 +1,38 @@
1all: telnetd
2
3include ../MCONFIG
4include ../MRULES
5
6# -DAUTHENTICATE
7
8# If having unused tty devices root.root and mode 600 bugs you,
9# take out -DPARANOID_TTYS.
10
11CFLAGS += '-DISSUE_FILE="/etc/issue.net"' -DPARANOID_TTYS \
12 -DNO_REVOKE -DKLUDGELINEMODE -DDIAGNOSTICS \
13 -DLOGIN_WRAPPER=\"/usr/lib/telnetd/login\"
14# LIBS += $(LIBTERMCAP)
15
16OBJS = telnetd.o state.o termstat.o slc.o sys_term.o utility.o \
17 global.o setproctitle.o
18
19# authenc.o (empty)
20
21# logout.o logwtmp.o (now from -lutil)
22
23
24telnetd: $(OBJS)
25 $(CC) $(LDFLAGS) $^ $(LIBS) -o $@
26
27$(OBJS): defs.h ext.h pathnames.h telnetd.h logwtmp.h logout.h setproctitle.h
28telnetd.o: ../version.h
29
30install: telnetd
31 install -s -m$(DAEMONMODE) telnetd $(INSTALLROOT)$(SBINDIR)/in.telnetd
32 install -m$(MANMODE) issue.net.5 $(INSTALLROOT)$(MANDIR)/man5/
33 install -m$(MANMODE) telnetd.8 $(INSTALLROOT)$(MANDIR)/man8/in.telnetd.8
34 ln -sf in.telnetd.8 $(INSTALLROOT)$(MANDIR)/man8/telnetd.8
35
36clean:
37 rm -f *.o telnetd
38
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/authenc.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/authenc.c
new file mode 100644
index 0000000..d11a724
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/authenc.c
@@ -0,0 +1,83 @@
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted provided
6 * that: (1) source distributions retain this entire copyright notice and
7 * comment, and (2) distributions including binaries display the following
8 * acknowledgement: ``This product includes software developed by the
9 * University of California, Berkeley and its contributors'' in the
10 * documentation or other materials provided with the distribution and in
11 * all advertising materials mentioning features or use of this software.
12 * Neither the name of the University nor the names of its contributors may
13 * be used to endorse or promote products derived from this software without
14 * specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20#if 0 /* dead code */
21
22/*
23 * From: @(#)authenc.c 5.1 (Berkeley) 3/1/91
24 */
25char authenc_rcsid[] =
26 "$Id: authenc.c,v 1.5 1999/12/12 14:59:44 dholland Exp $";
27
28#if defined(ENCRYPT) || defined(AUTHENTICATE)
29#include "telnetd.h"
30#include <libtelnet/misc.h>
31
32int
33net_write(str, len)
34 unsigned char *str;
35 int len;
36{
37 if (nfrontp + len < netobuf + BUFSIZ) {
38 bcopy((void *)str, (void *)nfrontp, len);
39 nfrontp += len;
40 return(len);
41 }
42 return(0);
43}
44
45void
46net_encrypt()
47{
48#if defined(ENCRYPT)
49 char *s = (nclearto > nbackp) ? nclearto : nbackp;
50 if (s < nfrontp && encrypt_output) {
51 (*encrypt_output)((unsigned char *)s, nfrontp - s);
52 }
53 nclearto = nfrontp;
54#endif
55}
56
57int
58telnet_spin()
59{
60 ttloop();
61 return(0);
62}
63
64char *
65telnet_getenv(val)
66 char *val;
67{
68 extern char *getenv();
69 return(getenv(val));
70}
71
72char *
73telnet_gets(prompt, result, length, echo)
74 char *prompt;
75 char *result;
76 int length;
77 int echo;
78{
79 return((char *)0);
80}
81#endif
82
83#endif /* 0 */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/defs.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/defs.h
new file mode 100644
index 0000000..ea1997f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/defs.h
@@ -0,0 +1,215 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)defs.h 5.10 (Berkeley) 3/1/91
34 * $Id: defs.h,v 1.7 1999/08/02 03:14:03 dholland Exp $
35 */
36
37/*
38 * Telnet server defines
39 */
40#include <sys/types.h>
41#include <sys/param.h>
42
43#define ENV_VAR NEW_ENV_VAR
44#define ENV_VALUE NEW_ENV_VALUE
45#define TELOPT_ENVIRON TELOPT_NEW_ENVIRON
46
47#if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
48#define TELOPTS
49#define TELCMDS
50#define SLC_NAMES
51#endif
52
53#include <sys/socket.h>
54#include <sys/wait.h>
55#include <fcntl.h>
56#include <sys/file.h>
57#include <sys/stat.h>
58#include <sys/time.h>
59#include <sys/ioctl.h>
60#include <netinet/in.h>
61#include <arpa/telnet.h>
62#include <stdio.h>
63#include <stdlib.h>
64#include <signal.h>
65#include <errno.h>
66#include <netdb.h>
67#include <syslog.h>
68
69#ifndef LOG_DAEMON
70#define LOG_DAEMON 0
71#endif
72
73#ifndef LOG_ODELAY
74#define LOG_ODELAY 0
75#endif
76
77#include <ctype.h>
78#include <string.h>
79#include <termios.h>
80
81#ifdef __STDC__
82#include <unistd.h>
83#endif
84
85#ifndef _POSIX_VDISABLE
86#ifdef VDISABLE
87#define _POSIX_VDISABLE VDISABLE
88#else
89#define _POSIX_VDISABLE ((unsigned char)'\377')
90#endif
91#endif
92
93/*
94 * I/O data buffers defines
95 */
96#define NETSLOP 64
97
98#define NIACCUM(c) { *netip++ = c; \
99 ncc++; \
100 }
101
102/* clock manipulations */
103#define settimer(x) (clocks.x = ++clocks.system)
104#define sequenceIs(x,y) (clocks.x < clocks.y)
105
106/*
107 * Linemode support states, in decreasing order of importance
108 */
109#define REAL_LINEMODE 0x02
110#define KLUDGE_LINEMODE 0x01
111#define NO_LINEMODE 0x00
112
113/*
114 * Structures of information for each special character function.
115 */
116typedef struct {
117 unsigned char flag; /* the flags for this function */
118 cc_t val; /* the value of the special character */
119} slcent, *Slcent;
120
121typedef struct {
122 slcent defset; /* the default settings */
123 slcent current; /* the current settings */
124 cc_t *sptr; /* a pointer to the char in */
125 /* system data structures */
126} slcfun, *Slcfun;
127
128#ifdef DIAGNOSTICS
129/*
130 * Diagnostics capabilities
131 */
132#define TD_REPORT 0x01 /* Report operations to client */
133#define TD_EXERCISE 0x02 /* Exercise client's implementation */
134#define TD_NETDATA 0x04 /* Display received data stream */
135#define TD_PTYDATA 0x08 /* Display data passed to pty */
136#define TD_OPTIONS 0x10 /* Report just telnet options */
137#endif /* DIAGNOSTICS */
138
139/*
140 * We keep track of each side of the option negotiation.
141 */
142
143#define MY_STATE_WILL 0x01
144#define MY_WANT_STATE_WILL 0x02
145#define MY_STATE_DO 0x04
146#define MY_WANT_STATE_DO 0x08
147
148/*
149 * Macros to check the current state of things
150 */
151
152#define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
153#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
154#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
155#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
156
157#define my_state_is_dont(opt) (!my_state_is_do(opt))
158#define my_state_is_wont(opt) (!my_state_is_will(opt))
159#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
160#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
161
162#define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
163#define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
164#define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
165#define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
166
167#define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
168#define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
169#define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
170#define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
171
172/*
173 * Tricky code here. What we want to know is if the MY_STATE_WILL
174 * and MY_WANT_STATE_WILL bits have the same value. Since the two
175 * bits are adjacent, a little arithmatic will show that by adding
176 * in the lower bit, the upper bit will be set if the two bits were
177 * different, and clear if they were the same.
178 */
179#define my_will_wont_is_changing(opt) \
180 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
181
182#define my_do_dont_is_changing(opt) \
183 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
184
185/*
186 * Make everything symetrical
187 */
188
189#define HIS_STATE_WILL MY_STATE_DO
190#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
191#define HIS_STATE_DO MY_STATE_WILL
192#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
193
194#define his_state_is_do my_state_is_will
195#define his_state_is_will my_state_is_do
196#define his_want_state_is_do my_want_state_is_will
197#define his_want_state_is_will my_want_state_is_do
198
199#define his_state_is_dont my_state_is_wont
200#define his_state_is_wont my_state_is_dont
201#define his_want_state_is_dont my_want_state_is_wont
202#define his_want_state_is_wont my_want_state_is_dont
203
204#define set_his_state_do set_my_state_will
205#define set_his_state_will set_my_state_do
206#define set_his_want_state_do set_my_want_state_will
207#define set_his_want_state_will set_my_want_state_do
208
209#define set_his_state_dont set_my_state_wont
210#define set_his_state_wont set_my_state_dont
211#define set_his_want_state_dont set_my_want_state_wont
212#define set_his_want_state_wont set_my_want_state_dont
213
214#define his_will_wont_is_changing my_do_dont_is_changing
215#define his_do_dont_is_changing my_will_wont_is_changing
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/ext.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/ext.h
new file mode 100644
index 0000000..b98d6ec
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/ext.h
@@ -0,0 +1,212 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)ext.h 5.7 (Berkeley) 3/1/91
34 * $Id: ext.h,v 1.9 1999/12/12 14:59:44 dholland Exp $
35 */
36
37/*
38 * Telnet server variable declarations
39 */
40extern char options[256];
41extern char do_dont_resp[256];
42extern char will_wont_resp[256];
43extern int linemode; /* linemode on/off */
44
45#ifdef LINEMODE
46extern int uselinemode; /* what linemode to use (on/off) */
47extern int editmode; /* edit modes in use */
48extern int useeditmode; /* edit modes to use */
49extern int alwayslinemode; /* command line option */
50#ifdef KLUDGELINEMODE
51extern int lmodetype; /* Client support for linemode */
52#endif /* KLUDGELINEMODE */
53#endif /* LINEMODE */
54
55extern int flowmode; /* current flow control state */
56
57#ifdef DIAGNOSTICS
58extern int diagnostic; /* telnet diagnostic capabilities */
59#endif /* DIAGNOSTICS */
60
61#ifdef BFTPDAEMON
62extern int bftpd; /* behave as bftp daemon */
63#endif /* BFTPDAEMON */
64
65#if defined(SecurID)
66extern int require_SecurID;
67#endif
68
69#if defined(AUTHENTICATE)
70extern int auth_level;
71#endif
72
73extern slcfun slctab[NSLC + 1]; /* slc mapping table */
74
75extern char *terminaltype;
76
77extern char *loginprg;
78
79/*
80 * I/O data buffers, pointers, and counters.
81 */
82extern char ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
83extern char netibuf[BUFSIZ], *netip;
84extern char netobuf[BUFSIZ+NETSLOP], *nfrontp, *nbackp;
85extern char *neturg; /* one past last byte of urgent data */
86extern int pcc, ncc;
87
88/* printf into netobuf */
89void netoprintf(const char *fmt, ...) __attribute((format (printf, 1, 2)));
90
91extern int pty, net;
92extern char *line;
93extern int SYNCHing; /* we are in TELNET SYNCH mode */
94
95void _termstat(void);
96void add_slc(int, int, int);
97void check_slc(void);
98void change_slc(int, int, int);
99void cleanup(int);
100void clientstat(int, int, int);
101void copy_termbuf(char *, int);
102void deferslc(void);
103void defer_terminit(void);
104void do_opt_slc(unsigned char *, int);
105void doeof(void);
106void dooption(int);
107void dontoption(int);
108void edithost(const char *, const char *);
109void fatal(int, const char *);
110void fatalperror(int, const char *);
111void get_slc_defaults(void);
112void init_env(void);
113void init_termbuf(void);
114void interrupt(void);
115void localstat(void);
116void netclear(void);
117void netflush(void);
118
119#ifdef DIAGNOSTICS
120void printoption(const char *, int);
121void printdata(const char *, const char *, int);
122void printsub(char, unsigned char *, int);
123#endif
124
125void ptyflush(void);
126void putchr(int);
127void putf(const char *, char *);
128void recv_ayt(void);
129void send_do(int, int);
130void send_dont(int, int);
131void send_slc(void);
132void send_status(void);
133void send_will(int, int);
134void send_wont(int, int);
135void sendbrk(void);
136void sendsusp(void);
137void set_termbuf(void);
138void start_login(const char *, int, const char *);
139void start_slc(int);
140void startslave(const char *host, int autologin, char *autoname);
141
142#if defined(AUTHENTICATE)
143void start_slave(char *);
144#else
145void start_slave(char *, int, char *);
146#endif
147
148void suboption(void);
149void telrcv(void);
150void ttloop(void);
151void tty_binaryin(int);
152void tty_binaryout(int);
153
154int end_slc(unsigned char **);
155int getnpty(void);
156int getpty(void);
157int login_tty(int);
158int spcset(int, cc_t *, cc_t **);
159int stilloob(int);
160int terminit(void);
161int termstat(void);
162int tty_flowmode(void);
163int tty_isbinaryin(void);
164int tty_isbinaryout(void);
165int tty_iscrnl(void);
166int tty_isecho(void);
167int tty_isediting(void);
168int tty_islitecho(void);
169int tty_isnewmap(void);
170int tty_israw(void);
171int tty_issofttab(void);
172int tty_istrapsig(void);
173int tty_linemode(void);
174
175void tty_rspeed(int);
176void tty_setecho(int);
177void tty_setedit(int);
178void tty_setlinemode(int);
179void tty_setlitecho(int);
180void tty_setsig(int);
181void tty_setsofttab(int);
182void tty_tspeed(int);
183void willoption(int);
184void wontoption(int);
185void writenet(unsigned char *, int);
186
187#if defined(ENCRYPT)
188extern void (*encrypt_output)(unsigned char *, int);
189extern int (*decrypt_input)(int);
190extern char *nclearto;
191#endif
192
193
194/*
195 * The following are some clocks used to decide how to interpret
196 * the relationship between various variables.
197 */
198
199extern struct _clocks {
200 int system; /* what the current time is */
201 int echotoggle; /* last time user entered echo character */
202 int modenegotiated; /* last time operating mode negotiated */
203 int didnetreceive; /* last time we read data from network */
204 int ttypesubopt; /* ttype subopt is received */
205 int tspeedsubopt; /* tspeed subopt is received */
206 int environsubopt; /* environ subopt is received */
207 int xdisplocsubopt; /* xdisploc subopt is received */
208 int baseline; /* time started to do timed action */
209 int gotDM; /* when did we last see a data mark */
210} clocks;
211
212#define DEFAULT_IM "%i\r\n%s %r (%h) (%t)\r\n\r\n"
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/getent.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/getent.c
new file mode 100644
index 0000000..9e0d0f3
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/getent.c
@@ -0,0 +1,71 @@
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)getent.c 5.1 (Berkeley) 2/28/91
36 */
37char ge_rcsid[] =
38 "$Id: getent.c,v 1.3 1996/08/15 06:23:28 dholland Exp $";
39
40/*
41 * Copyright (c) 1991 Regents of the University of California.
42 * All rights reserved.
43 *
44 * Redistribution and use in source and binary forms are permitted provided
45 * that: (1) source distributions retain this entire copyright notice and
46 * comment, and (2) distributions including binaries display the following
47 * acknowledgement: ``This product includes software developed by the
48 * University of California, Berkeley and its contributors'' in the
49 * documentation or other materials provided with the distribution and in
50 * all advertising materials mentioning features or use of this software.
51 * Neither the name of the University nor the names of its contributors may
52 * be used to endorse or promote products derived from this software without
53 * specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
55 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
56 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
57 */
58
59#include <stdlib.h>
60
61int getent(char *cp, char *name) {
62 (void)cp;
63 (void)name;
64 return 0;
65}
66
67char *getstr(char *cp, char **cpp) {
68 (void)cp;
69 (void)cpp;
70 return NULL;
71}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/global.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/global.c
new file mode 100644
index 0000000..badd4d5
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/global.c
@@ -0,0 +1,98 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)global.c 5.2 (Berkeley) 6/1/90
36 */
37char global_rcsid[] =
38 "$Id: global.c,v 1.4 1999/12/12 14:59:44 dholland Exp $";
39
40/*
41 * Allocate global variables.
42 */
43
44#include "defs.h"
45#include "ext.h"
46
47/*
48 * Telnet server variable declarations
49 */
50char options[256];
51char do_dont_resp[256];
52char will_wont_resp[256];
53int linemode; /* linemode on/off */
54
55#ifdef LINEMODE
56int uselinemode; /* what linemode to use (on/off) */
57int editmode; /* edit modes in use */
58int useeditmode; /* edit modes to use */
59int alwayslinemode; /* command line option */
60# ifdef KLUDGELINEMODE
61int lmodetype; /* Client support for linemode */
62# endif /* KLUDGELINEMODE */
63#endif /* LINEMODE */
64
65int flowmode; /* current flow control state */
66
67#ifdef DIAGNOSTICS
68int diagnostic; /* telnet diagnostic capabilities */
69#endif /* DIAGNOSTICS */
70
71#ifdef BFTPDAEMON
72int bftpd; /* behave as bftp daemon */
73#endif /* BFTPDAEMON */
74
75#if defined(SecurID)
76int require_SecurID;
77#endif
78
79slcfun slctab[NSLC + 1]; /* slc mapping table */
80
81char *terminaltype;
82
83/*
84 * I/O data buffers, pointers, and counters.
85 */
86char ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
87
88char netibuf[BUFSIZ], *netip;
89
90char netobuf[BUFSIZ+NETSLOP], *nfrontp, *nbackp;
91char *neturg; /* one past last bye of urgent data */
92
93int pcc, ncc;
94
95int pty, net;
96int SYNCHing; /* we are in TELNET SYNCH mode */
97
98struct _clocks clocks;
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/issue.net.5 b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/issue.net.5
new file mode 100644
index 0000000..c3337ee
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/issue.net.5
@@ -0,0 +1,43 @@
1.\" Copyright (c) 1994 Peter Tobias <tobias@server.et-inf.fho-emden.de>
2.\" This file may be distributed under the GNU General Public License.
3.\"
4.\" Changed to -mdoc by David A. Holland <dholland@ftp.uk.linux.org>
5.\" in order to work better with some NetKit maintenance scripts.
6.\"
7.Dd May 22, 1994
8.Dt ISSUE.NET 5
9.Os "Linux NetKit (0.16)"
10.Sh NAME
11.Nm issue.net
12.Nd identification file for telnet sessions
13.Sh DESCRIPTION
14The file
15.Pa /etc/issue.net
16is a text file which contains a message or system identification to be
17printed before the login prompt of a telnet session. It may contain
18various `%-char' sequences. The following sequences are supported by
19.Ic telnetd :
20.Bl -tag -offset indent -compact -width "abcde"
21.It %t
22- show the current tty
23.It %h
24- show the system node name (FQDN)
25.It %D
26- show the name of the NIS domain
27.It %d
28- show the current time and date
29.It %s
30- show the name of the operating system
31.It %m
32- show the machine (hardware) type
33.It %r
34- show the operating system release
35.It %v
36- show the operating system version
37.It %%
38- display a single '%' character
39.El
40.Sh FILES
41.Pa /etc/issue.net
42.Sh "SEE ALSO"
43.Xr in.telnetd 8
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/login.3 b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/login.3
new file mode 100644
index 0000000..f059f60
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/login.3
@@ -0,0 +1,107 @@
1.\" Copyright (c) 1995
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" This code is derived from software developed by the Computer Systems
5.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
6.\" BG 91-66 and contributed to Berkeley.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.Dd December 14, 1995
37.Dt LOGIN 3
38.Os "Linux NetKit (0.16)"
39.Sh NAME
40.Nm login ,
41.Nm logout ,
42.Nm logwtmp
43.Nd login utility functions
44.Sh SYNOPSIS
45.Fd #include <util.h>
46.Ft void
47.Fn login "struct utmp *ut"
48.Ft int
49.Fn logout "const char *line"
50.Ft void
51.Fn logwtmp "const char *line" "const char *name" "const char *host"
52.Sh DESCRIPTION
53The
54.Fn login ,
55.Fn logout ,
56and
57.Fn logwtmp
58functions operate on the database of current users in
59.Pa /var/run/utmp
60and on the logfile
61.Pa /var/log/wtmp
62of logins and logouts.
63.Pp
64The
65.Fn login
66function updates the
67.Pa /var/run/utmp
68and
69.Pa /var/log/wtmp
70files with user information contained in
71.Fa ut .
72.Pp
73The
74.Fn logout
75function removes the entry from
76.Pa /var/run/utmp
77corresponding to the device
78.Fa line .
79.Pp
80The
81.Fn logwtmp
82function adds an entry to
83.Pa /var/log/wtmp .
84Since
85.Fn login
86will add the appropriate entry for
87.Pa /var/log/wtmp
88during a login,
89.Fn logwtmp
90is usually used for logouts.
91.Sh RETURN VALUES
92.Fn logout
93returns non-zero if it was able to find and delete an entry for
94.Fa line ,
95and zero if there is no entry for
96.Fa line
97in
98.Pa /var/run/utmp .
99.Sh FILES
100.Bl -tag -width /var/run/wtmp -compact
101.It Pa /dev/\(**
102.It Pa /etc/ttys
103.It Pa /var/run/utmp
104.It Pa /var/log/wtmp
105.El
106.Sh SEE ALSO
107.Xr utmp 5
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/logout.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/logout.h
new file mode 100644
index 0000000..4141e31
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/logout.h
@@ -0,0 +1 @@
int logout(const char *line);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/logwtmp.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/logwtmp.h
new file mode 100644
index 0000000..3843a31
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/logwtmp.h
@@ -0,0 +1,5 @@
1/*
2 * Put this here instead of including <util.h>, since Linux is messed up
3 * and doesn't have <util.h>.
4 */
5void logwtmp(const char *_line, const char *name, const char *host);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/pathnames.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/pathnames.h
new file mode 100644
index 0000000..7af84bd
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/pathnames.h
@@ -0,0 +1,41 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)pathnames.h 5.5 (Berkeley) 6/28/90
34 * $Id: pathnames.h,v 1.3 1996/08/29 22:31:24 dholland Exp $
35 */
36
37#include <paths.h>
38
39#ifndef _PATH_LOGIN
40#define _PATH_LOGIN "/bin/login"
41#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.3 b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.3
new file mode 100644
index 0000000..541fa50
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.3
@@ -0,0 +1,73 @@
1.\" OpenBSD: setproctitle.3,v 1.4 1996/10/08 01:20:08 michaels Exp
2.\" $Id: setproctitle.3,v 1.8 1999/12/14 12:53:06 dholland Exp $
3.\"
4.\" Copyright (c) 1994, 1995 Christopher G. Demetriou
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\" must display the following acknowledgement:
17.\" This product includes software developed by Christopher G. Demetriou
18.\" for the NetBSD Project.
19.\" 3. The name of the author may not be used to endorse or promote products
20.\" derived from this software without specific prior written permission
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"
33.Dd April 13, 1994
34.Dt SETPROCTITLE 3
35.Os "Linux NetKit (0.16)"
36.Sh NAME
37.Nm setproctitle
38.Nd set process title
39.Sh SYNOPSIS
40.Fd #include <stdlib.h>
41.Ft void
42.Fn setproctitle "const char *fmt" "..."
43.Sh DESCRIPTION
44The
45.Fn setproctitle
46function sets the invoking process's title.
47The process title is set to the last component of the program
48name, followed by a colon and the formatted string specified
49by
50.Va fmt .
51If
52.Va fmt
53is NULL, the colon and formatted string are omitted.
54The length of a process title is limited to 2048 bytes.
55.Sh EXAMPLES
56Set the process title to the program name, with no further information:
57.Bd -literal -offset indent
58setproctitle(NULL);
59.Ed
60.Pp
61Set the process title to the program name, an informational string,
62and the process id:
63.Bd -literal -offset indent
64setproctitle("foo! (%d)", getpid());
65.Ed
66.Sh SEE ALSO
67.Xr ps 1 ,
68.Xr w 1 ,
69.Xr printf 3
70.Sh HISTORY
71The
72.Fn setproctitle
73function first appeared in NetBSD 0.9a.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.c
new file mode 100644
index 0000000..c207d05
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.c
@@ -0,0 +1,145 @@
1/*
2 * setproctitle implementation for linux.
3 * Stolen from sendmail 8.7.4 and bashed around by David A. Holland
4 */
5
6/*
7 * Copyright (c) 1983, 1995 Eric P. Allman
8 * Copyright (c) 1988, 1993
9 * The Regents of the University of California. All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * From: @(#)conf.c 8.243 (Berkeley) 11/20/95
40 */
41char setproctitle_rcsid[] =
42 "$Id: setproctitle.c,v 1.3 1999/12/10 23:06:39 bryce Exp $";
43
44#include <stdlib.h>
45#include <string.h>
46#include <unistd.h>
47#include <stdarg.h>
48#include <stdio.h>
49
50#include "setproctitle.h"
51/*
52** SETPROCTITLE -- set process title for ps
53**
54** Parameters:
55** fmt -- a printf style format string.
56** a, b, c -- possible parameters to fmt.
57**
58** Returns:
59** none.
60**
61** Side Effects:
62** Clobbers argv of our main procedure so ps(1) will
63** display the title.
64*/
65
66
67/*
68** Pointers for setproctitle.
69** This allows "ps" listings to give more useful information.
70*/
71
72static char **Argv = NULL; /* pointer to argument vector */
73static char *LastArgv = NULL; /* end of argv */
74static char Argv0[128]; /* program name */
75
76void
77initsetproctitle(int argc, char **argv, char **envp)
78{
79 register int i;
80 char *tmp;
81
82 /*
83 ** Move the environment so setproctitle can use the space at
84 ** the top of memory.
85 */
86
87 for (i = 0; envp[i] != NULL; i++)
88 continue;
89 __environ = (char **) malloc(sizeof (char *) * (i + 1));
90 for (i = 0; envp[i] != NULL; i++)
91 __environ[i] = strdup(envp[i]);
92 __environ[i] = NULL;
93
94 /*
95 ** Save start and extent of argv for setproctitle.
96 */
97
98 Argv = argv;
99 if (i > 0)
100 LastArgv = envp[i - 1] + strlen(envp[i - 1]);
101 else
102 LastArgv = argv[argc - 1] + strlen(argv[argc - 1]);
103
104 tmp = strrchr(argv[0], '/');
105 if (!tmp) tmp = argv[0];
106 else tmp++;
107 strncpy(Argv0, tmp, sizeof(Argv0));
108 Argv0[sizeof(Argv0)-1] = 0;
109}
110
111void
112setproctitle(const char *fmt, ...)
113{
114 register char *p;
115 register int i=0;
116 static char buf[2048];
117 va_list ap;
118
119 p = buf;
120
121 /* print progname: heading for grep */
122 /* This can't overflow buf due to the relative size of Argv0. */
123 (void) strcpy(p, Argv0);
124 (void) strcat(p, ": ");
125 p += strlen(p);
126
127 /* print the argument string */
128 va_start(ap, fmt);
129 (void) vsnprintf(p, sizeof(buf) - (p - buf), fmt, ap);
130 va_end(ap);
131
132 i = strlen(buf);
133
134 if (i > LastArgv - Argv[0] - 2)
135 {
136 i = LastArgv - Argv[0] - 2;
137 buf[i] = '\0';
138 }
139 (void) strcpy(Argv[0], buf);
140 p = &Argv[0][i];
141 while (p < LastArgv)
142 *p++ = '\0';
143 Argv[1] = NULL;
144}
145
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.h
new file mode 100644
index 0000000..8652ee8
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/setproctitle.h
@@ -0,0 +1,4 @@
1/* Call this from main. */
2void initsetproctitle(int argc, char **argv, char **envp);
3
4void setproctitle(const char *fmt, ...);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/slc.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/slc.c
new file mode 100644
index 0000000..54579ea
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/slc.c
@@ -0,0 +1,456 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)slc.c 5.7 (Berkeley) 3/1/91
36 */
37char slc_rcsid[] =
38 "$Id: slc.c,v 1.5 1999/12/12 14:59:44 dholland Exp $";
39
40#include "telnetd.h"
41
42#ifdef LINEMODE
43/*
44 * local varibles
45 */
46static unsigned char *def_slcbuf = (unsigned char *)0;
47static int def_slclen = 0;
48static int slcchange; /* change to slc is requested */
49static int slcoff; /* offset into slc buffer */
50static unsigned char slcbuf[NSLC*6]; /* buffer for slc negotiation */
51
52static void add_slcbuf_raw_char(unsigned char ch) {
53 if (slcoff < sizeof(slcbuf)) {
54 slcbuf[slcoff++] = ch;
55 }
56}
57
58static void add_slcbuf_char(unsigned char ch) {
59 add_slcbuf_raw_char(ch);
60 if (ch==0xff) {
61 add_slcbuf_raw_char(0xff);
62 }
63}
64
65/*
66 * send_slc
67 *
68 * Write out the current special characters to the client.
69 */
70void send_slc(void) {
71 int i;
72
73 /*
74 * Send out list of triplets of special characters
75 * to client. We only send info on the characters
76 * that are currently supported.
77 */
78 for (i = 1; i <= NSLC; i++) {
79 if ((slctab[i].defset.flag & SLC_LEVELBITS) == SLC_NOSUPPORT)
80 continue;
81 add_slc((unsigned char)i, slctab[i].current.flag,
82 slctab[i].current.val);
83 }
84}
85
86/*
87 * default_slc
88 *
89 * Set pty special characters to all the defaults.
90 */
91void default_slc(void) {
92 int i;
93 for (i = 1; i <= NSLC; i++) {
94 slctab[i].current.val = slctab[i].defset.val;
95 if (slctab[i].current.val == (cc_t)(_POSIX_VDISABLE)) {
96 slctab[i].current.flag = SLC_NOSUPPORT;
97 }
98 else {
99 slctab[i].current.flag = slctab[i].defset.flag;
100 }
101 if (slctab[i].sptr) {
102 *(slctab[i].sptr) = slctab[i].defset.val;
103 }
104 }
105 slcchange = 1;
106}
107
108#endif /* LINEMODE */
109
110/*
111 * get_slc_defaults
112 *
113 * Initialize the slc mapping table.
114 */
115void get_slc_defaults(void) {
116 int i;
117 init_termbuf();
118 for (i = 1; i <= NSLC; i++) {
119 slctab[i].defset.flag = spcset(i, &slctab[i].defset.val,
120 &slctab[i].sptr);
121 slctab[i].current.flag = SLC_NOSUPPORT;
122 slctab[i].current.val = 0;
123 }
124}
125
126#ifdef LINEMODE
127/*
128 * add_slc
129 *
130 * Add an slc triplet to the slc buffer.
131 */
132void add_slc(char func, char flag, cc_t val) {
133 add_slcbuf_char(func);
134 add_slcbuf_char(flag);
135 add_slcbuf_char(val);
136}
137
138/*
139 * start_slc
140 *
141 * Get ready to process incoming slc's and respond to them.
142 *
143 * The parameter getit is non-zero if it is necessary to grab a copy
144 * of the terminal control structures.
145 */
146void start_slc(int getit) {
147 slcchange = 0;
148 if (getit) init_termbuf();
149 snprintf(slcbuf, sizeof(slcbuf), "%c%c%c%c",
150 IAC, SB, TELOPT_LINEMODE, LM_SLC);
151 slcoff = 4;
152}
153
154/*
155 * end_slc
156 *
157 * Finish up the slc negotiation. If something to send, then send it.
158 */
159int end_slc(unsigned char **bufp) {
160 /*
161 * If a change has occured, store the new terminal control
162 * structures back to the terminal driver.
163 */
164 if (slcchange) {
165 set_termbuf();
166 }
167
168 /*
169 * If the pty state has not yet been fully processed and there is a
170 * deferred slc request from the client, then do not send any
171 * sort of slc negotiation now. We will respond to the client's
172 * request very soon.
173 */
174 if (def_slcbuf && (terminit() == 0)) {
175 return 0;
176 }
177
178 if (slcoff > 4) {
179 if (bufp) {
180 *bufp = &slcbuf[4];
181 return(slcoff - 4);
182 }
183 else {
184 snprintf(slcbuf+slcoff, sizeof(slcbuf)-slcoff, "%c%c", IAC, SE);
185 slcoff += 2;
186 writenet(slcbuf, slcoff);
187 netflush(); /* force it out immediately */
188 }
189 }
190 return 0;
191}
192
193/*
194 * process_slc
195 *
196 * Figure out what to do about the client's slc
197 */
198void process_slc(unsigned char func, unsigned char flag, cc_t val) {
199 register int hislevel, mylevel, ack;
200
201 /*
202 * Ensure that we know something about this function
203 */
204 if (func > NSLC) {
205 add_slc(func, SLC_NOSUPPORT, 0);
206 return;
207 }
208
209 /*
210 * Process the special case requests of 0 SLC_DEFAULT 0
211 * and 0 SLC_VARIABLE 0. Be a little forgiving here, don't
212 * worry about whether the value is actually 0 or not.
213 */
214 if (func == 0) {
215 if ((flag = flag & SLC_LEVELBITS) == SLC_DEFAULT) {
216 default_slc();
217 send_slc();
218 }
219 else if (flag == SLC_VARIABLE) {
220 send_slc();
221 }
222 return;
223 }
224
225 /*
226 * Appears to be a function that we know something about. So
227 * get on with it and see what we know.
228 */
229
230 hislevel = flag & SLC_LEVELBITS;
231 mylevel = slctab[func].current.flag & SLC_LEVELBITS;
232 ack = flag & SLC_ACK;
233 /*
234 * ignore the command if:
235 * the function value and level are the same as what we already have;
236 * or the level is the same and the ack bit is set
237 */
238 if (hislevel == mylevel && (val == slctab[func].current.val || ack)) {
239 return;
240 }
241 else if (ack) {
242 /*
243 * If we get here, we got an ack, but the levels don't match.
244 * This shouldn't happen. If it does, it is probably because
245 * we have sent two requests to set a variable without getting
246 * a response between them, and this is the first response.
247 * So, ignore it, and wait for the next response.
248 */
249 return;
250 }
251 else {
252 change_slc(func, flag, val);
253 }
254}
255
256/*
257 * change_slc
258 *
259 * Process a request to change one of our special characters.
260 * Compare client's request with what we are capable of supporting.
261 */
262void change_slc(char func, char flag, cc_t val) {
263 register int hislevel, mylevel;
264
265 hislevel = flag & SLC_LEVELBITS;
266 mylevel = slctab[func].defset.flag & SLC_LEVELBITS;
267 /*
268 * If client is setting a function to NOSUPPORT
269 * or DEFAULT, then we can easily and directly
270 * accomodate the request.
271 */
272 if (hislevel == SLC_NOSUPPORT) {
273 slctab[func].current.flag = flag;
274 slctab[func].current.val = (cc_t)_POSIX_VDISABLE;
275 flag |= SLC_ACK;
276 add_slc(func, flag, val);
277 return;
278 }
279 if (hislevel == SLC_DEFAULT) {
280 /*
281 * Special case here. If client tells us to use
282 * the default on a function we don't support, then
283 * return NOSUPPORT instead of what we may have as a
284 * default level of DEFAULT.
285 */
286 if (mylevel == SLC_DEFAULT) {
287 slctab[func].current.flag = SLC_NOSUPPORT;
288 }
289 else {
290 slctab[func].current.flag = slctab[func].defset.flag;
291 }
292 slctab[func].current.val = slctab[func].defset.val;
293 add_slc(func, slctab[func].current.flag,
294 slctab[func].current.val);
295 return;
296 }
297
298 /*
299 * Client wants us to change to a new value or he
300 * is telling us that he can't change to our value.
301 * Some of the slc's we support and can change,
302 * some we do support but can't change,
303 * and others we don't support at all.
304 * If we can change it then we have a pointer to
305 * the place to put the new value, so change it,
306 * otherwise, continue the negotiation.
307 */
308 if (slctab[func].sptr) {
309 /*
310 * We can change this one.
311 */
312 slctab[func].current.val = val;
313 *(slctab[func].sptr) = val;
314 slctab[func].current.flag = flag;
315 flag |= SLC_ACK;
316 slcchange = 1;
317 add_slc(func, flag, val);
318 }
319 else {
320 /*
321 * It is not possible for us to support this
322 * request as he asks.
323 *
324 * If our level is DEFAULT, then just ack whatever was
325 * sent.
326 *
327 * If he can't change and we can't change,
328 * then degenerate to NOSUPPORT.
329 *
330 * Otherwise we send our level back to him, (CANTCHANGE
331 * or NOSUPPORT) and if CANTCHANGE, send
332 * our value as well.
333 */
334 if (mylevel == SLC_DEFAULT) {
335 slctab[func].current.flag = flag;
336 slctab[func].current.val = val;
337 flag |= SLC_ACK;
338 }
339 else if (hislevel == SLC_CANTCHANGE && mylevel == SLC_CANTCHANGE) {
340 flag &= ~SLC_LEVELBITS;
341 flag |= SLC_NOSUPPORT;
342 slctab[func].current.flag = flag;
343 }
344 else {
345 flag &= ~SLC_LEVELBITS;
346 flag |= mylevel;
347 slctab[func].current.flag = flag;
348 if (mylevel == SLC_CANTCHANGE) {
349 slctab[func].current.val = slctab[func].defset.val;
350 val = slctab[func].current.val;
351 }
352 }
353 add_slc(func, flag, val);
354 }
355}
356
357#if (VEOF == VMIN)
358cc_t oldeofc = '\004';
359#endif
360
361/*
362 * check_slc
363 *
364 * Check the special characters in use and notify the client if any have
365 * changed. Only those characters that are capable of being changed are
366 * likely to have changed. If a local change occurs, kick the support level
367 * and flags up to the defaults.
368 */
369void check_slc(void) {
370 int i;
371 for (i = 1; i <= NSLC; i++) {
372#if (VEOF == VMIN)
373 /*
374 * In a perfect world this would be a neat little
375 * function. But in this world, we should not notify
376 * client of changes to the VEOF char when
377 * ICANON is off, because it is not representing
378 * a special character.
379 */
380 if (i == SLC_EOF) {
381 if (!tty_isediting()) continue;
382 else if (slctab[i].sptr) oldeofc = *(slctab[i].sptr);
383 }
384#endif /* VEOF==VMIN */
385
386 if (slctab[i].sptr && (*(slctab[i].sptr) != slctab[i].current.val)) {
387 slctab[i].current.val = *(slctab[i].sptr);
388 if (*(slctab[i].sptr) == (cc_t)_POSIX_VDISABLE) {
389 slctab[i].current.flag = SLC_NOSUPPORT;
390 }
391 else {
392 slctab[i].current.flag = slctab[i].defset.flag;
393 }
394 add_slc((unsigned char)i, slctab[i].current.flag,
395 slctab[i].current.val);
396 }
397 }
398}
399
400/*
401 * do_opt_slc
402 *
403 * Process an slc option buffer. Defer processing of incoming slc's
404 * until after the terminal state has been processed. Save the first slc
405 * request that comes along, but discard all others.
406 *
407 * ptr points to the beginning of the buffer, len is the length.
408 */
409void do_opt_slc(unsigned char *ptr, int len) {
410 unsigned char func, flag;
411 cc_t val;
412 unsigned char *end = ptr + len;
413
414 if (terminit()) { /* go ahead */
415 while (ptr < end) {
416 func = *ptr++;
417 if (ptr >= end) break;
418 flag = *ptr++;
419 if (ptr >= end) break;
420 val = (cc_t)*ptr++;
421
422 process_slc(func, flag, val);
423
424 }
425 }
426 else {
427 /*
428 * save this slc buffer if it is the first, otherwise dump
429 * it.
430 */
431 if (def_slcbuf == NULL) {
432 def_slclen = len;
433 def_slcbuf = malloc((unsigned)len);
434 if (def_slcbuf == NULL) return; /* too bad */
435 bcopy(ptr, def_slcbuf, len);
436 }
437 }
438}
439
440/*
441 * deferslc
442 *
443 * Do slc stuff that was deferred.
444 */
445void deferslc(void) {
446 if (def_slcbuf) {
447 start_slc(1);
448 do_opt_slc(def_slcbuf, def_slclen);
449 end_slc(0);
450 free(def_slcbuf);
451 def_slcbuf = (unsigned char *)0;
452 def_slclen = 0;
453 }
454}
455
456#endif /* LINEMODE */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/state.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/state.c
new file mode 100644
index 0000000..b757411
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/state.c
@@ -0,0 +1,1408 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)state.c 5.10 (Berkeley) 3/22/91
36 */
37char state_rcsid[] =
38 "$Id: state.c,v 1.12 1999/12/12 19:41:44 dholland Exp $";
39
40#include "telnetd.h"
41
42int not42 = 1;
43
44static int envvarok(char *varp);
45
46static unsigned char doopt[] = { IAC, DO, '%', 'c', 0 };
47static unsigned char dont[] = { IAC, DONT, '%', 'c', 0 };
48unsigned char will[] = { IAC, WILL, '%', 'c', 0 };
49unsigned char wont[] = { IAC, WONT, '%', 'c', 0 };
50
51/*
52 * Buffer for sub-options, and macros
53 * for suboptions buffer manipulations
54 */
55unsigned char subbuffer[512], *subpointer=subbuffer, *subend=subbuffer;
56
57#define SB_CLEAR() subpointer = subbuffer;
58#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
59#define SB_ACCUM(c) if (subpointer < (subbuffer + sizeof(subbuffer)-1)) { \
60 *subpointer++ = (c); \
61 }
62#define SB_GET() ((*subpointer++)&0xff)
63#define SB_EOF() (subpointer >= subend)
64#define SB_LEN() (subend - subpointer)
65
66
67
68/*
69 * State for recv fsm
70 */
71#define TS_DATA 0 /* base state */
72#define TS_IAC 1 /* look for double IAC's */
73#define TS_CR 2 /* CR-LF ->'s CR */
74#define TS_SB 3 /* throw away begin's... */
75#define TS_SE 4 /* ...end's (suboption negotiation) */
76#define TS_WILL 5 /* will option negotiation */
77#define TS_WONT 6 /* wont " */
78#define TS_DO 7 /* do " */
79#define TS_DONT 8 /* dont " */
80
81void telrcv(void) {
82 register int c;
83 static int state = TS_DATA;
84
85 while (ncc > 0) {
86 if ((&ptyobuf[BUFSIZ] - pfrontp) < 2) break;
87 c = *netip++ & 0377;
88 ncc--;
89
90#if defined(ENCRYPT)
91 if (decrypt_input) {
92 c = (*decrypt_input)(c);
93 }
94#endif
95 switch (state) {
96 case TS_CR:
97 state = TS_DATA;
98 /* Strip off \n or \0 after a \r */
99 if ((c == 0) || (c == '\n')) {
100 break;
101 }
102 /* FALL THROUGH */
103
104 case TS_DATA:
105 if (c == IAC) {
106 state = TS_IAC;
107 break;
108 }
109 /*
110 * We now map \r\n ==> \r for pragmatic reasons.
111 * Many client implementations send \r\n when
112 * the user hits the CarriageReturn key.
113 *
114 * We USED to map \r\n ==> \n, since \r\n says
115 * that we want to be in column 1 of the next
116 * printable line, and \n is the standard
117 * unix way of saying that (\r is only good
118 * if CRMOD is set, which it normally is).
119 */
120 if ((c == '\r') && his_state_is_wont(TELOPT_BINARY)) {
121#if defined(ENCRYPT)
122 int nc = *netip;
123 if (decrypt_input) {
124 nc = (*decrypt_input)(nc & 0xff);
125 }
126#endif
127#ifdef LINEMODE
128 /*
129 * If we are operating in linemode,
130 * convert to local end-of-line.
131 */
132 if (linemode && (ncc > 0) && (('\n' == nc) ||
133 ((0 == nc) && tty_iscrnl())) ) {
134 netip++; ncc--;
135 c = '\n';
136 }
137 else
138#endif
139 {
140#if defined(ENCRYPT)
141 if (decrypt_input)
142 (void)(*decrypt_input)(-1);
143#endif
144 state = TS_CR;
145 }
146 }
147 *pfrontp++ = c;
148 break;
149
150 case TS_IAC:
151 gotiac:
152 switch (c) {
153
154 /*
155 * Send the process on the pty side an
156 * interrupt. Do this with a NULL or
157 * interrupt char; depending on the tty mode.
158 */
159 case IP:
160 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
161 interrupt();
162 break;
163 case BREAK:
164 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
165 sendbrk();
166 break;
167
168 /*
169 * Are You There?
170 */
171 case AYT:
172 DIAG(TD_OPTIONS,
173 printoption("td: recv IAC", c));
174 recv_ayt();
175 break;
176
177 /*
178 * Abort Output
179 */
180 case AO:
181 {
182 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
183 ptyflush(); /* half-hearted */
184 init_termbuf();
185
186 if (slctab[SLC_AO].sptr &&
187 *slctab[SLC_AO].sptr != (cc_t)(_POSIX_VDISABLE))
188 {
189 *pfrontp++ =
190 (unsigned char)*slctab[SLC_AO].sptr;
191 }
192
193 netclear(); /* clear buffer back */
194 *nfrontp++ = (char)IAC;
195 *nfrontp++ = (char)DM;
196 neturg = nfrontp-1; /* off by one XXX */
197 DIAG(TD_OPTIONS, printoption("td: send IAC", DM));
198 break;
199 }
200
201 /*
202 * Erase Character and
203 * Erase Line
204 */
205 case EC:
206 case EL:
207 {
208 cc_t ch;
209 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
210 ptyflush(); /* half-hearted */
211 init_termbuf();
212 if (c == EC) ch = *slctab[SLC_EC].sptr;
213 else ch = *slctab[SLC_EL].sptr;
214 if (ch != (cc_t)(_POSIX_VDISABLE))
215 *pfrontp++ = (unsigned char)ch;
216 break;
217 }
218
219 /*
220 * Check for urgent data...
221 */
222 case DM:
223 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
224 SYNCHing = stilloob(net);
225 settimer(gotDM);
226 break;
227
228 /*
229 * Begin option subnegotiation...
230 */
231 case SB:
232 state = TS_SB;
233 SB_CLEAR();
234 continue;
235
236 case WILL:
237 state = TS_WILL;
238 continue;
239
240 case WONT:
241 state = TS_WONT;
242 continue;
243
244 case DO:
245 state = TS_DO;
246 continue;
247
248 case DONT:
249 state = TS_DONT;
250 continue;
251
252 case EOR:
253 if (his_state_is_will(TELOPT_EOR)) doeof();
254 break;
255
256 /*
257 * Handle RFC 10xx Telnet linemode option additions
258 * to command stream (EOF, SUSP, ABORT).
259 */
260 case xEOF:
261 doeof();
262 break;
263
264 case SUSP:
265 sendsusp();
266 break;
267
268 case ABORT:
269 sendbrk();
270 break;
271
272 case IAC:
273 *pfrontp++ = c;
274 break;
275 }
276 state = TS_DATA;
277 break;
278
279 case TS_SB:
280 if (c == IAC) {
281 state = TS_SE;
282 }
283 else {
284 SB_ACCUM(c);
285 }
286 break;
287
288 case TS_SE:
289 if (c != SE) {
290 if (c != IAC) {
291 /*
292 * bad form of suboption negotiation.
293 * handle it in such a way as to avoid
294 * damage to local state. Parse
295 * suboption buffer found so far,
296 * then treat remaining stream as
297 * another command sequence.
298 */
299
300 /* for DIAGNOSTICS */
301 SB_ACCUM(IAC);
302 SB_ACCUM(c);
303 subpointer -= 2;
304
305 SB_TERM();
306 suboption();
307 state = TS_IAC;
308 goto gotiac;
309 }
310 SB_ACCUM(c);
311 state = TS_SB;
312 }
313 else {
314 /* for DIAGNOSTICS */
315 SB_ACCUM(IAC);
316 SB_ACCUM(SE);
317 subpointer -= 2;
318
319 SB_TERM();
320 suboption(); /* handle sub-option */
321 state = TS_DATA;
322 }
323 break;
324
325 case TS_WILL:
326 willoption(c);
327 state = TS_DATA;
328 continue;
329
330 case TS_WONT:
331 wontoption(c);
332 state = TS_DATA;
333 continue;
334
335 case TS_DO:
336 dooption(c);
337 state = TS_DATA;
338 continue;
339
340 case TS_DONT:
341 dontoption(c);
342 state = TS_DATA;
343 continue;
344
345 default:
346 syslog(LOG_ERR, "telnetd: panic state=%d\n", state);
347 printf("telnetd: panic state=%d\n", state);
348 exit(1);
349 }
350 }
351}
352
353/*
354 * The will/wont/do/dont state machines are based on Dave Borman's
355 * Telnet option processing state machine.
356 *
357 * These correspond to the following states:
358 * my_state = the last negotiated state
359 * want_state = what I want the state to go to
360 * want_resp = how many requests I have sent
361 * All state defaults are negative, and resp defaults to 0.
362 *
363 * When initiating a request to change state to new_state:
364 *
365 * if ((want_resp == 0 && new_state == my_state) || want_state == new_state) {
366 * do nothing;
367 * } else {
368 * want_state = new_state;
369 * send new_state;
370 * want_resp++;
371 * }
372 *
373 * When receiving new_state:
374 *
375 * if (want_resp) {
376 * want_resp--;
377 * if (want_resp && (new_state == my_state))
378 * want_resp--;
379 * }
380 * if ((want_resp == 0) && (new_state != want_state)) {
381 * if (ok_to_switch_to new_state)
382 * want_state = new_state;
383 * else
384 * want_resp++;
385 * send want_state;
386 * }
387 * my_state = new_state;
388 *
389 * Note that new_state is implied in these functions by the function itself.
390 * will and do imply positive new_state, wont and dont imply negative.
391 *
392 * Finally, there is one catch. If we send a negative response to a
393 * positive request, my_state will be the positive while want_state will
394 * remain negative. my_state will revert to negative when the negative
395 * acknowlegment arrives from the peer. Thus, my_state generally tells
396 * us not only the last negotiated state, but also tells us what the peer
397 * wants to be doing as well. It is important to understand this difference
398 * as we may wish to be processing data streams based on our desired state
399 * (want_state) or based on what the peer thinks the state is (my_state).
400 *
401 * This all works fine because if the peer sends a positive request, the data
402 * that we receive prior to negative acknowlegment will probably be affected
403 * by the positive state, and we can process it as such (if we can; if we
404 * can't then it really doesn't matter). If it is that important, then the
405 * peer probably should be buffering until this option state negotiation
406 * is complete.
407 *
408 */
409void send_do(int option, int init) {
410 if (init) {
411 if ((do_dont_resp[option] == 0 && his_state_is_will(option)) ||
412 his_want_state_is_will(option))
413 return;
414 /*
415 * Special case for TELOPT_TM: We send a DO, but pretend
416 * that we sent a DONT, so that we can send more DOs if
417 * we want to.
418 */
419 if (option == TELOPT_TM)
420 set_his_want_state_wont(option);
421 else
422 set_his_want_state_will(option);
423 do_dont_resp[option]++;
424 }
425 netoprintf((char *)doopt, option);
426
427 DIAG(TD_OPTIONS, printoption("td: send do", option));
428}
429
430#ifdef AUTHENTICATE
431extern void auth_request();
432#endif
433
434#ifdef LINEMODE
435static void doclientstat(void);
436#endif
437
438#ifdef ENCRYPT
439extern void encrypt_send_support();
440#endif
441
442void willoption(int option) {
443 int changeok = 0;
444 void (*func)(void) = 0;
445
446 /*
447 * process input from peer.
448 */
449
450 DIAG(TD_OPTIONS, printoption("td: recv will", option));
451
452 if (do_dont_resp[option]) {
453 do_dont_resp[option]--;
454 if (do_dont_resp[option] && his_state_is_will(option))
455 do_dont_resp[option]--;
456 }
457 if (do_dont_resp[option] == 0) {
458 if (his_want_state_is_wont(option)) {
459 switch (option) {
460
461 case TELOPT_BINARY:
462 init_termbuf();
463 tty_binaryin(1);
464 set_termbuf();
465 changeok++;
466 break;
467
468 case TELOPT_ECHO:
469 /*
470 * See comments below for more info.
471 */
472 not42 = 0; /* looks like a 4.2 system */
473 break;
474
475 case TELOPT_TM:
476#if defined(LINEMODE) && defined(KLUDGELINEMODE)
477 /*
478 * This telnetd implementation does not really
479 * support timing marks, it just uses them to
480 * support the kludge linemode stuff. If we
481 * receive a will or wont TM in response to our
482 * do TM request that may have been sent to
483 * determine kludge linemode support, process
484 * it, otherwise TM should get a negative
485 * response back.
486 */
487 /*
488 * Handle the linemode kludge stuff.
489 * If we are not currently supporting any
490 * linemode at all, then we assume that this
491 * is the client telling us to use kludge
492 * linemode in response to our query. Set the
493 * linemode type that is to be supported, note
494 * that the client wishes to use linemode, and
495 * eat the will TM as though it never arrived.
496 */
497 if (lmodetype < KLUDGE_LINEMODE) {
498 lmodetype = KLUDGE_LINEMODE;
499 clientstat(TELOPT_LINEMODE, WILL, 0);
500 send_wont(TELOPT_SGA, 1);
501 }
502#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
503 /*
504 * We never respond to a WILL TM, and
505 * we leave the state WONT.
506 */
507 return;
508
509 case TELOPT_LFLOW:
510 /*
511 * If we are going to support flow control
512 * option, then don't worry peer that we can't
513 * change the flow control characters.
514 */
515 slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS;
516 slctab[SLC_XON].defset.flag |= SLC_DEFAULT;
517 slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS;
518 slctab[SLC_XOFF].defset.flag |= SLC_DEFAULT;
519 case TELOPT_TTYPE:
520 case TELOPT_SGA:
521 case TELOPT_NAWS:
522 case TELOPT_TSPEED:
523 case TELOPT_XDISPLOC:
524 case TELOPT_ENVIRON:
525 changeok++;
526 break;
527
528#ifdef LINEMODE
529 case TELOPT_LINEMODE:
530#ifdef KLUDGELINEMODE
531 /*
532 * Note client's desire to use linemode.
533 */
534 lmodetype = REAL_LINEMODE;
535#endif /* KLUDGELINEMODE */
536 func = doclientstat;
537 changeok++;
538 break;
539#endif /* LINEMODE */
540
541#ifdef AUTHENTICATE
542 case TELOPT_AUTHENTICATION:
543 func = auth_request;
544 changeok++;
545 break;
546#endif
547
548#ifdef ENCRYPT
549 case TELOPT_ENCRYPT:
550 func = encrypt_send_support;
551 changeok++;
552 break;
553#endif
554
555 default:
556 break;
557 }
558 if (changeok) {
559 set_his_want_state_will(option);
560 send_do(option, 0);
561 }
562 else {
563 do_dont_resp[option]++;
564 send_dont(option, 0);
565 }
566 }
567 else {
568 /*
569 * Option processing that should happen when
570 * we receive conformation of a change in
571 * state that we had requested.
572 */
573 switch (option) {
574 case TELOPT_ECHO:
575 not42 = 0; /* looks like a 4.2 system */
576 /*
577 * Egads, he responded "WILL ECHO". Turn
578 * it off right now!
579 */
580 send_dont(option, 1);
581 /*
582 * "WILL ECHO". Kludge upon kludge!
583 * A 4.2 client is now echoing user input at
584 * the tty. This is probably undesireable and
585 * it should be stopped. The client will
586 * respond WONT TM to the DO TM that we send to
587 * check for kludge linemode. When the WONT TM
588 * arrives, linemode will be turned off and a
589 * change propogated to the pty. This change
590 * will cause us to process the new pty state
591 * in localstat(), which will notice that
592 * linemode is off and send a WILL ECHO
593 * so that we are properly in character mode and
594 * all is well.
595 */
596 break;
597#ifdef LINEMODE
598 case TELOPT_LINEMODE:
599# ifdef KLUDGELINEMODE
600 /*
601 * Note client's desire to use linemode.
602 */
603 lmodetype = REAL_LINEMODE;
604# endif /* KLUDGELINEMODE */
605 func = doclientstat;
606 break;
607#endif /* LINEMODE */
608
609#ifdef AUTHENTICATE
610 case TELOPT_AUTHENTICATION:
611 func = auth_request;
612 break;
613#endif
614
615#ifdef ENCRYPT
616 case TELOPT_ENCRYPT:
617 func = encrypt_send_support;
618 break;
619#endif
620 }
621 }
622 }
623 set_his_state_will(option);
624 if (func) (*func)();
625}
626
627void send_dont(int option, int init) {
628 if (init) {
629 if ((do_dont_resp[option] == 0 && his_state_is_wont(option)) ||
630 his_want_state_is_wont(option))
631 return;
632 set_his_want_state_wont(option);
633 do_dont_resp[option]++;
634 }
635 netoprintf((char *) dont, option);
636
637 DIAG(TD_OPTIONS, printoption("td: send dont", option));
638}
639
640void wontoption(int option) {
641 /*
642 * Process client input.
643 */
644
645 DIAG(TD_OPTIONS, printoption("td: recv wont", option));
646
647 if (do_dont_resp[option]) {
648 do_dont_resp[option]--;
649 if (do_dont_resp[option] && his_state_is_wont(option))
650 do_dont_resp[option]--;
651 }
652 if (do_dont_resp[option] == 0) {
653 if (his_want_state_is_will(option)) {
654 /* it is always ok to change to negative state */
655 switch (option) {
656 case TELOPT_ECHO:
657 not42 = 1; /* doesn't seem to be a 4.2 system */
658 break;
659
660 case TELOPT_BINARY:
661 init_termbuf();
662 tty_binaryin(0);
663 set_termbuf();
664 break;
665
666#ifdef LINEMODE
667 case TELOPT_LINEMODE:
668#ifdef KLUDGELINEMODE
669 /*
670 * If real linemode is supported, then client is
671 * asking to turn linemode off.
672 */
673 if (lmodetype != REAL_LINEMODE)
674 break;
675 lmodetype = KLUDGE_LINEMODE;
676# endif /* KLUDGELINEMODE */
677 clientstat(TELOPT_LINEMODE, WONT, 0);
678 break;
679#endif /* LINEMODE */
680
681 case TELOPT_TM:
682 /*
683 * If we get a WONT TM, and had sent a DO TM,
684 * don't respond with a DONT TM, just leave it
685 * as is. Short circut the state machine to
686 * achive this.
687 */
688 set_his_want_state_wont(TELOPT_TM);
689 return;
690
691 case TELOPT_LFLOW:
692 /*
693 * If we are not going to support flow control
694 * option, then let peer know that we can't
695 * change the flow control characters.
696 */
697 slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS;
698 slctab[SLC_XON].defset.flag |= SLC_CANTCHANGE;
699 slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS;
700 slctab[SLC_XOFF].defset.flag |= SLC_CANTCHANGE;
701 break;
702
703#if defined(AUTHENTICATE)
704 case TELOPT_AUTHENTICATION:
705 auth_finished(0, AUTH_REJECT);
706 break;
707#endif
708
709 /*
710 * For options that we might spin waiting for
711 * sub-negotiation, if the client turns off the
712 * option rather than responding to the request,
713 * we have to treat it here as if we got a response
714 * to the sub-negotiation, (by updating the timers)
715 * so that we'll break out of the loop.
716 */
717 case TELOPT_TTYPE:
718 settimer(ttypesubopt);
719 break;
720
721 case TELOPT_TSPEED:
722 settimer(tspeedsubopt);
723 break;
724
725 case TELOPT_XDISPLOC:
726 settimer(xdisplocsubopt);
727 break;
728
729 case TELOPT_ENVIRON:
730 settimer(environsubopt);
731 break;
732
733 default:
734 break;
735 }
736 set_his_want_state_wont(option);
737 if (his_state_is_will(option)) send_dont(option, 0);
738 }
739 else {
740 switch (option) {
741 case TELOPT_TM:
742#if defined(LINEMODE) && defined(KLUDGELINEMODE)
743 if (lmodetype < REAL_LINEMODE) {
744 lmodetype = NO_LINEMODE;
745 clientstat(TELOPT_LINEMODE, WONT, 0);
746 send_will(TELOPT_SGA, 1);
747 send_will(TELOPT_ECHO, 1);
748 }
749#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
750 break;
751
752#if defined(AUTHENTICATE)
753 case TELOPT_AUTHENTICATION:
754 auth_finished(0, AUTH_REJECT);
755 break;
756#endif
757 default:
758 break;
759 }
760 }
761 }
762} /* end of wontoption */
763
764void send_will(int option, int init) {
765 if (init) {
766 if ((will_wont_resp[option] == 0 && my_state_is_will(option))||
767 my_want_state_is_will(option))
768 return;
769 set_my_want_state_will(option);
770 will_wont_resp[option]++;
771 }
772 netoprintf((char *) will, option);
773
774 DIAG(TD_OPTIONS, printoption("td: send will", option));
775}
776
777#if !defined(LINEMODE) || !defined(KLUDGELINEMODE)
778/*
779 * When we get a DONT SGA, we will try once to turn it
780 * back on. If the other side responds DONT SGA, we
781 * leave it at that. This is so that when we talk to
782 * clients that understand KLUDGELINEMODE but not LINEMODE,
783 * we'll keep them in char-at-a-time mode.
784 */
785int turn_on_sga = 0;
786#endif
787
788void dooption(int option) {
789 int changeok = 0;
790
791 /*
792 * Process client input.
793 */
794
795 DIAG(TD_OPTIONS, printoption("td: recv do", option));
796
797 if (will_wont_resp[option]) {
798 will_wont_resp[option]--;
799 if (will_wont_resp[option] && my_state_is_will(option))
800 will_wont_resp[option]--;
801 }
802 if ((will_wont_resp[option] == 0) && (my_want_state_is_wont(option))) {
803 switch (option) {
804 case TELOPT_ECHO:
805#ifdef LINEMODE
806#ifdef KLUDGELINEMODE
807 if (lmodetype == NO_LINEMODE)
808#else
809 if (his_state_is_wont(TELOPT_LINEMODE))
810#endif
811#endif
812 {
813 init_termbuf();
814 tty_setecho(1);
815 set_termbuf();
816 }
817 changeok++;
818 break;
819
820 case TELOPT_BINARY:
821 init_termbuf();
822 tty_binaryout(1);
823 set_termbuf();
824 changeok++;
825 break;
826
827 case TELOPT_SGA:
828#if defined(LINEMODE) && defined(KLUDGELINEMODE)
829 /*
830 * If kludge linemode is in use, then we must
831 * process an incoming do SGA for linemode
832 * purposes.
833 */
834 if (lmodetype == KLUDGE_LINEMODE) {
835 /*
836 * Receipt of "do SGA" in kludge
837 * linemode is the peer asking us to
838 * turn off linemode. Make note of
839 * the request.
840 */
841 clientstat(TELOPT_LINEMODE, WONT, 0);
842 /*
843 * If linemode did not get turned off
844 * then don't tell peer that we did.
845 * Breaking here forces a wont SGA to
846 * be returned.
847 */
848 if (linemode) break;
849 }
850#else
851 turn_on_sga = 0;
852#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
853 changeok++;
854 break;
855
856 case TELOPT_STATUS:
857 changeok++;
858 break;
859
860 case TELOPT_TM:
861 /*
862 * Special case for TM. We send a WILL, but
863 * pretend we sent a WONT.
864 */
865 send_will(option, 0);
866 set_my_want_state_wont(option);
867 set_my_state_wont(option);
868 return;
869
870 case TELOPT_LOGOUT:
871 /*
872 * When we get a LOGOUT option, respond
873 * with a WILL LOGOUT, make sure that
874 * it gets written out to the network,
875 * and then just go away...
876 */
877 set_my_want_state_will(TELOPT_LOGOUT);
878 send_will(TELOPT_LOGOUT, 0);
879 set_my_state_will(TELOPT_LOGOUT);
880 (void)netflush();
881 cleanup(0);
882 /* NOT REACHED */
883 break;
884
885#if defined(ENCRYPT)
886 case TELOPT_ENCRYPT:
887 changeok++;
888 break;
889#endif
890 case TELOPT_LINEMODE:
891 case TELOPT_TTYPE:
892 case TELOPT_NAWS:
893 case TELOPT_TSPEED:
894 case TELOPT_LFLOW:
895 case TELOPT_XDISPLOC:
896 case TELOPT_ENVIRON:
897 default:
898 break;
899 }
900 if (changeok) {
901 set_my_want_state_will(option);
902 send_will(option, 0);
903 }
904 else {
905 will_wont_resp[option]++;
906 send_wont(option, 0);
907 }
908 }
909 set_my_state_will(option);
910}
911
912void send_wont(int option, int init) {
913 if (init) {
914 if ((will_wont_resp[option] == 0 && my_state_is_wont(option)) ||
915 my_want_state_is_wont(option))
916 return;
917 set_my_want_state_wont(option);
918 will_wont_resp[option]++;
919 }
920 netoprintf((char *)wont, option);
921
922 DIAG(TD_OPTIONS, printoption("td: send wont", option));
923}
924
925void dontoption(int option) {
926 /*
927 * Process client input.
928 */
929 DIAG(TD_OPTIONS, printoption("td: recv dont", option));
930
931 if (will_wont_resp[option]) {
932 will_wont_resp[option]--;
933 if (will_wont_resp[option] && my_state_is_wont(option))
934 will_wont_resp[option]--;
935 }
936 if ((will_wont_resp[option] == 0) && (my_want_state_is_will(option))) {
937 switch (option) {
938 case TELOPT_BINARY:
939 init_termbuf();
940 tty_binaryout(0);
941 set_termbuf();
942 break;
943
944 case TELOPT_ECHO: /* we should stop echoing */
945#ifdef LINEMODE
946#ifdef KLUDGELINEMODE
947 if (lmodetype == NO_LINEMODE)
948#else
949 if (his_state_is_wont(TELOPT_LINEMODE))
950#endif
951#endif
952 {
953 init_termbuf();
954 tty_setecho(0);
955 set_termbuf();
956 }
957 break;
958
959 case TELOPT_SGA:
960#if defined(LINEMODE) && defined(KLUDGELINEMODE)
961 /*
962 * If kludge linemode is in use, then we
963 * must process an incoming do SGA for
964 * linemode purposes.
965 */
966 if (lmodetype == KLUDGE_LINEMODE) {
967 /*
968 * The client is asking us to turn
969 * linemode on.
970 */
971 clientstat(TELOPT_LINEMODE, WILL, 0);
972 /*
973 * If we did not turn line mode on,
974 * then what do we say? Will SGA?
975 * This violates design of telnet.
976 * Gross. Very Gross.
977 */
978 }
979 break;
980#else
981 set_my_want_state_wont(option);
982 if (my_state_is_will(option))
983 send_wont(option, 0);
984 set_my_state_wont(option);
985 if (turn_on_sga ^= 1) send_will(option,1);
986 return;
987#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
988
989 default:
990 break;
991 }
992
993 set_my_want_state_wont(option);
994 if (my_state_is_will(option))
995 send_wont(option, 0);
996 }
997 set_my_state_wont(option);
998}
999
1000/*
1001 * suboption()
1002 *
1003 * Look at the sub-option buffer, and try to be helpful to the other
1004 * side.
1005 *
1006 * Currently we recognize:
1007 *
1008 * Terminal type is
1009 * Linemode
1010 * Window size
1011 * Terminal speed
1012 */
1013void suboption(void) {
1014 int subchar;
1015
1016 DIAG(TD_OPTIONS, {netflush(); printsub('<', subpointer, SB_LEN()+2);});
1017
1018 subchar = SB_GET();
1019 switch (subchar) {
1020 case TELOPT_TSPEED: {
1021 int xspeed, rspeed;
1022 if (his_state_is_wont(TELOPT_TSPEED)) /* Ignore if option disabled */
1023 break;
1024
1025 settimer(tspeedsubopt);
1026 if (SB_EOF() || SB_GET() != TELQUAL_IS) return;
1027 xspeed = atoi((char *)subpointer);
1028
1029 while (SB_GET() != ',' && !SB_EOF());
1030 if (SB_EOF()) return;
1031
1032 rspeed = atoi((char *)subpointer);
1033 clientstat(TELOPT_TSPEED, xspeed, rspeed);
1034 break;
1035 }
1036
1037 case TELOPT_TTYPE: { /* Yaaaay! */
1038 static char terminalname[41];
1039
1040 if (his_state_is_wont(TELOPT_TTYPE)) /* Ignore if option disabled */
1041 break;
1042 settimer(ttypesubopt);
1043
1044 if (SB_EOF() || SB_GET() != TELQUAL_IS) {
1045 return; /* ??? XXX but, this is the most robust */
1046 }
1047
1048 terminaltype = terminalname;
1049
1050 while ((terminaltype < (terminalname + sizeof (terminalname) -1) ) &&
1051 !SB_EOF())
1052 {
1053 int c;
1054 c = SB_GET();
1055 if (isupper(c)) {
1056 c = tolower(c);
1057 }
1058 *terminaltype++ = c; /* accumulate name */
1059 }
1060 *terminaltype = 0;
1061 terminaltype = terminalname;
1062 break;
1063 }
1064
1065 case TELOPT_NAWS: {
1066 int xwinsize, ywinsize;
1067 if (his_state_is_wont(TELOPT_NAWS)) /* Ignore if option disabled */
1068 break;
1069
1070 if (SB_EOF()) return;
1071 xwinsize = SB_GET() << 8;
1072 if (SB_EOF()) return;
1073 xwinsize |= SB_GET();
1074 if (SB_EOF()) return;
1075 ywinsize = SB_GET() << 8;
1076 if (SB_EOF()) return;
1077 ywinsize |= SB_GET();
1078 clientstat(TELOPT_NAWS, xwinsize, ywinsize);
1079 break;
1080 }
1081
1082#ifdef LINEMODE
1083 case TELOPT_LINEMODE: {
1084 register int request;
1085
1086 if (his_state_is_wont(TELOPT_LINEMODE)) /* Ignore if option disabled */
1087 break;
1088 /*
1089 * Process linemode suboptions.
1090 */
1091 if (SB_EOF())
1092 break; /* garbage was sent */
1093 request = SB_GET(); /* get will/wont */
1094
1095 if (SB_EOF())
1096 break; /* another garbage check */
1097
1098 if (request == LM_SLC) { /* SLC is not preceeded by WILL or WONT */
1099 /*
1100 * Process suboption buffer of slc's
1101 */
1102 start_slc(1);
1103 do_opt_slc(subpointer, subend - subpointer);
1104 (void) end_slc(0);
1105 break;
1106 } else if (request == LM_MODE) {
1107 if (SB_EOF())
1108 return;
1109 useeditmode = SB_GET(); /* get mode flag */
1110 clientstat(LM_MODE, 0, 0);
1111 break;
1112 }
1113
1114 if (SB_EOF())
1115 break;
1116 switch (SB_GET()) { /* what suboption? */
1117 case LM_FORWARDMASK:
1118 /*
1119 * According to spec, only server can send request for
1120 * forwardmask, and client can only return a positive response.
1121 * So don't worry about it.
1122 */
1123
1124 default:
1125 break;
1126 }
1127 break;
1128 } /* end of case TELOPT_LINEMODE */
1129#endif
1130 case TELOPT_STATUS: {
1131 int mode;
1132
1133 if (SB_EOF())
1134 break;
1135 mode = SB_GET();
1136 switch (mode) {
1137 case TELQUAL_SEND:
1138 if (my_state_is_will(TELOPT_STATUS))
1139 send_status();
1140 break;
1141
1142 case TELQUAL_IS:
1143 break;
1144
1145 default:
1146 break;
1147 }
1148 break;
1149 } /* end of case TELOPT_STATUS */
1150
1151 case TELOPT_XDISPLOC: {
1152 if (SB_EOF() || SB_GET() != TELQUAL_IS)
1153 return;
1154 settimer(xdisplocsubopt);
1155 subpointer[SB_LEN()] = '\0';
1156 (void)setenv("DISPLAY", (char *)subpointer, 1);
1157 break;
1158 } /* end of case TELOPT_XDISPLOC */
1159
1160 case TELOPT_ENVIRON: {
1161 register int c;
1162 register char *cp, *varp, *valp;
1163
1164 if (SB_EOF())
1165 return;
1166 c = SB_GET();
1167 if (c == TELQUAL_IS)
1168 settimer(environsubopt);
1169 else if (c != TELQUAL_INFO)
1170 return;
1171
1172 while (!SB_EOF() && SB_GET() != ENV_VAR)
1173 ;
1174
1175 if (SB_EOF())
1176 return;
1177
1178 cp = varp = (char *)subpointer;
1179 valp = 0;
1180
1181 while (!SB_EOF()) {
1182 switch (c = SB_GET()) {
1183 case ENV_VALUE:
1184 *cp = '\0';
1185 cp = valp = (char *)subpointer;
1186 break;
1187
1188 case ENV_VAR:
1189 *cp = '\0';
1190 if (envvarok(varp)) {
1191 if (valp)
1192 (void)setenv(varp, valp, 1);
1193 else
1194 unsetenv(varp);
1195 }
1196 cp = varp = (char *)subpointer;
1197 valp = 0;
1198 break;
1199
1200 case ENV_ESC:
1201 if (SB_EOF())
1202 break;
1203 c = SB_GET();
1204 /* FALL THROUGH */
1205 default:
1206 /* I think this test is correct... */
1207 if (cp < subbuffer+sizeof(subbuffer)-1) *cp++ = c;
1208 break;
1209 }
1210 }
1211 *cp = '\0';
1212 if (envvarok(varp)) {
1213 if (valp)
1214 (void)setenv(varp, valp, 1);
1215 else
1216 unsetenv(varp);
1217 }
1218 break;
1219 } /* end of case TELOPT_ENVIRON */
1220#if defined(AUTHENTICATE)
1221 case TELOPT_AUTHENTICATION:
1222 if (SB_EOF())
1223 break;
1224 switch(SB_GET()) {
1225 case TELQUAL_SEND:
1226 case TELQUAL_REPLY:
1227 /*
1228 * These are sent by us and cannot be sent by
1229 * the client.
1230 */
1231 break;
1232 case TELQUAL_IS:
1233 auth_is(subpointer, SB_LEN());
1234 break;
1235 case TELQUAL_NAME:
1236 auth_name(subpointer, SB_LEN());
1237 break;
1238 }
1239 break;
1240#endif
1241#if defined(ENCRYPT)
1242 case TELOPT_ENCRYPT:
1243 if (SB_EOF())
1244 break;
1245 switch(SB_GET()) {
1246 case ENCRYPT_SUPPORT:
1247 encrypt_support(subpointer, SB_LEN());
1248 break;
1249 case ENCRYPT_IS:
1250 encrypt_is(subpointer, SB_LEN());
1251 break;
1252 case ENCRYPT_REPLY:
1253 encrypt_reply(subpointer, SB_LEN());
1254 break;
1255 case ENCRYPT_START:
1256 encrypt_start(subpointer, SB_LEN());
1257 break;
1258 case ENCRYPT_END:
1259 encrypt_end();
1260 break;
1261 case ENCRYPT_REQSTART:
1262 encrypt_request_start(subpointer, SB_LEN());
1263 break;
1264 case ENCRYPT_REQEND:
1265 /*
1266 * We can always send an REQEND so that we cannot
1267 * get stuck encrypting. We should only get this
1268 * if we have been able to get in the correct mode
1269 * anyhow.
1270 */
1271 encrypt_request_end();
1272 break;
1273 case ENCRYPT_ENC_KEYID:
1274 encrypt_enc_keyid(subpointer, SB_LEN());
1275 break;
1276 case ENCRYPT_DEC_KEYID:
1277 encrypt_dec_keyid(subpointer, SB_LEN());
1278 break;
1279 default:
1280 break;
1281 }
1282 break;
1283#endif
1284
1285 default:
1286 break;
1287 } /* end of switch */
1288
1289} /* end of suboption */
1290
1291#ifdef LINEMODE
1292static void doclientstat(void) {
1293 clientstat(TELOPT_LINEMODE, WILL, 0);
1294}
1295#endif
1296
1297#define ADD(c) *ncp++ = c;
1298#define ADD_DATA(c) { *ncp++ = c; if (c == SE) *ncp++ = c; }
1299
1300void send_status(void) {
1301 unsigned char statusbuf[256];
1302 register unsigned char *ncp;
1303 register unsigned char i;
1304
1305 ncp = statusbuf;
1306
1307 netflush(); /* get rid of anything waiting to go out */
1308
1309 ADD(IAC);
1310 ADD(SB);
1311 ADD(TELOPT_STATUS);
1312 ADD(TELQUAL_IS);
1313
1314 /*
1315 * We check the want_state rather than the current state,
1316 * because if we received a DO/WILL for an option that we
1317 * don't support, and the other side didn't send a DONT/WONT
1318 * in response to our WONT/DONT, then the "state" will be
1319 * WILL/DO, and the "want_state" will be WONT/DONT. We
1320 * need to go by the latter.
1321 */
1322 for (i = 0; i < NTELOPTS; i++) {
1323 if (my_want_state_is_will(i)) {
1324 ADD(WILL);
1325 ADD_DATA(i);
1326 if (i == IAC) ADD(IAC);
1327 }
1328 if (his_want_state_is_will(i)) {
1329 ADD(DO);
1330 ADD_DATA(i);
1331 if (i == IAC) ADD(IAC);
1332 }
1333 }
1334
1335 if (his_want_state_is_will(TELOPT_LFLOW)) {
1336 ADD(SB);
1337 ADD(TELOPT_LFLOW);
1338 ADD(flowmode);
1339 ADD(SE);
1340 }
1341
1342#ifdef LINEMODE
1343 if (his_want_state_is_will(TELOPT_LINEMODE)) {
1344 unsigned char *cp, *cpe;
1345 int len;
1346
1347 ADD(SB);
1348 ADD(TELOPT_LINEMODE);
1349 ADD(LM_MODE);
1350 ADD_DATA(editmode);
1351 if (editmode == IAC) ADD(IAC);
1352 ADD(SE);
1353
1354 ADD(SB);
1355 ADD(TELOPT_LINEMODE);
1356 ADD(LM_SLC);
1357 start_slc(0);
1358 send_slc();
1359 len = end_slc(&cp);
1360 for (cpe = cp + len; cp < cpe; cp++) ADD_DATA(*cp);
1361 ADD(SE);
1362 }
1363#endif /* LINEMODE */
1364
1365 ADD(IAC);
1366 ADD(SE);
1367
1368 writenet(statusbuf, ncp - statusbuf);
1369 netflush(); /* Send it on its way */
1370
1371 DIAG(TD_OPTIONS, {printsub('>', statusbuf, ncp - statusbuf); netflush();});
1372}
1373
1374/* check that variable is safe to pass to login or shell */
1375#if 0 /* insecure version */
1376static int envvarok(char *varp) {
1377 if (strncmp(varp, "LD_", strlen("LD_")) &&
1378 strncmp(varp, "ELF_LD_", strlen("ELF_LD_")) &&
1379 strncmp(varp, "AOUT_LD_", strlen("AOUT_LD_")) &&
1380 strncmp(varp, "_RLD_", strlen("_RLD_")) &&
1381 strcmp(varp, "LIBPATH") &&
1382 strcmp(varp, "ENV") &&
1383 strcmp(varp, "IFS"))
1384 {
1385 return 1;
1386 }
1387 else {
1388 /* optionally syslog(LOG_INFO) here */
1389 return 0;
1390 }
1391}
1392
1393#else
1394static int envvarok(char *varp) {
1395 /*
1396 * Allow only these variables.
1397 */
1398 if (!strcmp(varp, "TERM")) return 1;
1399 if (!strcmp(varp, "DISPLAY")) return 1;
1400 if (!strcmp(varp, "USER")) return 1;
1401 if (!strcmp(varp, "LOGNAME")) return 1;
1402 if (!strcmp(varp, "POSIXLY_CORRECT")) return 1;
1403
1404 /* optionally syslog(LOG_INFO) here */
1405 return 0;
1406}
1407
1408#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/sys_term.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/sys_term.c
new file mode 100644
index 0000000..57db624
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/sys_term.c
@@ -0,0 +1,744 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)sys_term.c 5.16 (Berkeley) 3/22/91
36 */
37char st_rcsid[] =
38 "$Id: sys_term.c,v 1.16 1999/12/12 14:59:45 dholland Exp $";
39
40#include <utmp.h>
41
42#include "telnetd.h"
43#include "pathnames.h"
44
45#if defined(__GLIBC__) && (__GLIBC__ >= 2)
46/* mmm, nonstandard */
47#include <pty.h>
48#else
49int openpty(int *, int *, char *, struct termios *, struct winsize *);
50#endif
51
52#define ARCH64 ((sizeof(void *)) == 8)
53#define ARCH32 ((sizeof(void *)) == 4)
54
55#if defined(AUTHENTICATE)
56#include <libtelnet/auth.h>
57#endif
58
59static struct termios termbuf, termbuf2; /* pty control structure */
60
61/*static int cleanopen(char *line);*/
62
63/*
64 * init_termbuf()
65 * copy_termbuf(cp)
66 * set_termbuf()
67 *
68 * These three routines are used to get and set the "termbuf" structure
69 * to and from the kernel. init_termbuf() gets the current settings.
70 * copy_termbuf() hands in a new "termbuf" to write to the kernel, and
71 * set_termbuf() writes the structure into the kernel.
72 */
73
74void init_termbuf(void) {
75 tcgetattr(pty, &termbuf);
76 termbuf2 = termbuf;
77}
78
79#if defined(LINEMODE) && defined(TIOCPKT_IOCTL)
80/*
81 * ?
82 */
83void copy_termbuf(char *cp, int len) {
84 if (len > sizeof(termbuf)) len = sizeof(termbuf);
85 bcopy(cp, (char *)&termbuf, len);
86 termbuf2 = termbuf;
87}
88#endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */
89
90void set_termbuf(void) {
91 if (memcmp(&termbuf, &termbuf2, sizeof(termbuf))) {
92 tcsetattr(pty, TCSANOW, &termbuf);
93 }
94}
95
96
97/*
98 * spcset(func, valp, valpp)
99 *
100 * This function takes various special characters (func), and
101 * sets *valp to the current value of that character, and
102 * *valpp to point to where in the "termbuf" structure that
103 * value is kept.
104 *
105 * It returns the SLC_ level of support for this function.
106 */
107
108
109int spcset(int func, cc_t *valp, cc_t **valpp) {
110
111#define setval(a, b) *valp = termbuf.c_cc[a]; \
112 *valpp = &termbuf.c_cc[a]; \
113 return(b);
114#define defval(a) *valp = ((cc_t)a); *valpp = (cc_t *)0; return(SLC_DEFAULT);
115
116 switch(func) {
117 case SLC_EOF:
118 setval(VEOF, SLC_VARIABLE);
119 case SLC_EC:
120 setval(VERASE, SLC_VARIABLE);
121 case SLC_EL:
122 setval(VKILL, SLC_VARIABLE);
123 case SLC_IP:
124 setval(VINTR, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
125 case SLC_ABORT:
126 setval(VQUIT, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
127 case SLC_XON:
128#ifdef VSTART
129 setval(VSTART, SLC_VARIABLE);
130#else
131 defval(0x13);
132#endif
133 case SLC_XOFF:
134#ifdef VSTOP
135 setval(VSTOP, SLC_VARIABLE);
136#else
137 defval(0x11);
138#endif
139 case SLC_EW:
140#ifdef VWERASE
141 setval(VWERASE, SLC_VARIABLE);
142#else
143 defval(0);
144#endif
145 case SLC_RP:
146#ifdef VREPRINT
147 setval(VREPRINT, SLC_VARIABLE);
148#else
149 defval(0);
150#endif
151 case SLC_LNEXT:
152#ifdef VLNEXT
153 setval(VLNEXT, SLC_VARIABLE);
154#else
155 defval(0);
156#endif
157 case SLC_AO:
158#if !defined(VDISCARD) && defined(VFLUSHO)
159# define VDISCARD VFLUSHO
160#endif
161#ifdef VDISCARD
162 setval(VDISCARD, SLC_VARIABLE|SLC_FLUSHOUT);
163#else
164 defval(0);
165#endif
166 case SLC_SUSP:
167#ifdef VSUSP
168 setval(VSUSP, SLC_VARIABLE|SLC_FLUSHIN);
169#else
170 defval(0);
171#endif
172#ifdef VEOL
173 case SLC_FORW1:
174 setval(VEOL, SLC_VARIABLE);
175#endif
176#ifdef VEOL2
177 case SLC_FORW2:
178 setval(VEOL2, SLC_VARIABLE);
179#endif
180 case SLC_AYT:
181#ifdef VSTATUS
182 setval(VSTATUS, SLC_VARIABLE);
183#else
184 defval(0);
185#endif
186
187 case SLC_BRK:
188 case SLC_SYNCH:
189 case SLC_EOR:
190 defval(0);
191
192 default:
193 *valp = 0;
194 *valpp = 0;
195 return(SLC_NOSUPPORT);
196 }
197}
198
199/*
200 * getpty()
201 *
202 * Allocate a pty. As a side effect, the external character
203 * array "line" contains the name of the slave side.
204 *
205 * Returns the file descriptor of the opened pty.
206 */
207static char linedata[PATH_MAX];
208char *line = linedata;
209
210static int ptyslavefd=-1;
211
212int getpty(void) {
213 int masterfd;
214
215 if (openpty(&masterfd, &ptyslavefd, line, NULL, NULL)) {
216 return -1;
217 }
218 return masterfd;
219}
220
221#ifdef LINEMODE
222/*
223 * tty_flowmode() Find out if flow control is enabled or disabled.
224 * tty_linemode() Find out if linemode (external processing) is enabled.
225 * tty_setlinemod(on) Turn on/off linemode.
226 * tty_isecho() Find out if echoing is turned on.
227 * tty_setecho(on) Enable/disable character echoing.
228 * tty_israw() Find out if terminal is in RAW mode.
229 * tty_binaryin(on) Turn on/off BINARY on input.
230 * tty_binaryout(on) Turn on/off BINARY on output.
231 * tty_isediting() Find out if line editing is enabled.
232 * tty_istrapsig() Find out if signal trapping is enabled.
233 * tty_setedit(on) Turn on/off line editing.
234 * tty_setsig(on) Turn on/off signal trapping.
235 * tty_issofttab() Find out if tab expansion is enabled.
236 * tty_setsofttab(on) Turn on/off soft tab expansion.
237 * tty_islitecho() Find out if typed control chars are echoed literally
238 * tty_setlitecho() Turn on/off literal echo of control chars
239 * tty_tspeed(val) Set transmit speed to val.
240 * tty_rspeed(val) Set receive speed to val.
241 */
242
243int tty_flowmode(void) {
244 return (termbuf.c_iflag & IXON ? 1 : 0);
245}
246
247int tty_linemode(void) {
248 return (termbuf.c_lflag & EXTPROC);
249}
250
251void tty_setlinemode(int on) {
252#ifdef TIOCEXT
253 set_termbuf();
254 ioctl(pty, TIOCEXT, (char *)&on);
255 init_termbuf();
256#else /* !TIOCEXT */
257# ifdef EXTPROC
258 if (on) termbuf.c_lflag |= EXTPROC;
259 else termbuf.c_lflag &= ~EXTPROC;
260# endif
261#endif /* TIOCEXT */
262}
263
264int tty_isecho(void) {
265 return (termbuf.c_lflag & ECHO);
266}
267#endif /* LINEMODE */
268
269void tty_setecho(int on) {
270 if (on) termbuf.c_lflag |= ECHO;
271 else termbuf.c_lflag &= ~ECHO;
272}
273
274#if defined(LINEMODE) && defined(KLUDGELINEMODE)
275int tty_israw(void) {
276 return(!(termbuf.c_lflag & ICANON));
277}
278#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
279
280void tty_binaryin(int on) {
281 if (on) {
282 termbuf.c_iflag &= ~ISTRIP;
283 }
284 else {
285 termbuf.c_iflag |= ISTRIP;
286 }
287}
288
289void tty_binaryout(int on) {
290 if (on) {
291 termbuf.c_cflag &= ~(CSIZE|PARENB);
292 termbuf.c_cflag |= CS8;
293 termbuf.c_oflag &= ~OPOST;
294 }
295 else {
296 termbuf.c_cflag &= ~CSIZE;
297 termbuf.c_cflag |= CS7|PARENB;
298 termbuf.c_oflag |= OPOST;
299 }
300}
301
302int tty_isbinaryin(void) {
303 return (!(termbuf.c_iflag & ISTRIP));
304}
305
306int tty_isbinaryout(void) {
307 return (!(termbuf.c_oflag&OPOST));
308}
309
310#ifdef LINEMODE
311int tty_isediting(void) {
312 return(termbuf.c_lflag & ICANON);
313}
314
315int tty_istrapsig(void) {
316 return(termbuf.c_lflag & ISIG);
317}
318
319void tty_setedit(int on) {
320 if (on) termbuf.c_lflag |= ICANON;
321 else termbuf.c_lflag &= ~ICANON;
322}
323
324void tty_setsig(int on) {
325 if (on) termbuf.c_lflag |= ISIG;
326 else termbuf.c_lflag &= ~ISIG;
327}
328#endif /* LINEMODE */
329
330int tty_issofttab(void) {
331#ifdef OXTABS
332 return (termbuf.c_oflag & OXTABS);
333#endif
334#ifdef TABDLY
335 return ((termbuf.c_oflag & TABDLY) == TAB3);
336#endif
337}
338
339void tty_setsofttab(int on) {
340 if (on) {
341#ifdef OXTABS
342 termbuf.c_oflag |= OXTABS;
343#endif
344#ifdef TABDLY
345 termbuf.c_oflag &= ~TABDLY;
346 termbuf.c_oflag |= TAB3;
347#endif
348 }
349 else {
350#ifdef OXTABS
351 termbuf.c_oflag &= ~OXTABS;
352#endif
353#ifdef TABDLY
354 termbuf.c_oflag &= ~TABDLY;
355 termbuf.c_oflag |= TAB0;
356#endif
357 }
358}
359
360int tty_islitecho(void) {
361 return (!(termbuf.c_lflag & ECHOCTL));
362}
363
364void tty_setlitecho(int on) {
365 if (on) termbuf.c_lflag &= ~ECHOCTL;
366 else termbuf.c_lflag |= ECHOCTL;
367}
368
369int tty_iscrnl(void) {
370 return (termbuf.c_iflag & ICRNL);
371}
372
373/*
374 * A table of available terminal speeds
375 */
376struct termspeeds {
377 int speed;
378 int value;
379} termspeeds[] = {
380 { 0, B0 }, { 50, B50 }, { 75, B75 },
381 { 110, B110 }, { 134, B134 }, { 150, B150 },
382 { 200, B200 }, { 300, B300 }, { 600, B600 },
383 { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
384 { 4800, B4800 }, { 9600, B9600 }, { 19200, B9600 },
385 { 38400, B9600 }, { -1, B9600 }
386};
387
388void tty_tspeed(int val) {
389 struct termspeeds *tp;
390 for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++);
391 cfsetospeed(&termbuf, tp->value);
392}
393
394void tty_rspeed(int val) {
395 struct termspeeds *tp;
396 for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++);
397 cfsetispeed(&termbuf, tp->value);
398}
399
400/*
401 * getptyslave()
402 *
403 * Open the slave side of the pty, and do any initialization
404 * that is necessary. The return value is a file descriptor
405 * for the slave side.
406 */
407#ifdef TIOCGWINSZ
408extern int def_row, def_col;
409#endif
410extern int def_tspeed, def_rspeed;
411
412static int getptyslave(void) {
413#if 0
414 register int t = -1;
415
416# ifdef LINEMODE
417 int waslm;
418# endif
419# ifdef TIOCGWINSZ
420 struct winsize ws;
421# endif
422 /*
423 * Opening the slave side may cause initilization of the
424 * kernel tty structure. We need remember the state of
425 * if linemode was turned on
426 * terminal window size
427 * terminal speed
428 * so that we can re-set them if we need to.
429 */
430# ifdef LINEMODE
431 waslm = tty_linemode();
432# endif
433
434
435 /*
436 * Make sure that we don't have a controlling tty, and
437 * that we are the session (process group) leader.
438 */
439 t = open(_PATH_TTY, O_RDWR);
440 if (t >= 0) {
441 ioctl(t, TIOCNOTTY, (char *)0);
442 close(t);
443 }
444
445 t = cleanopen(line);
446 if (t < 0) fatalperror(net, line);
447#endif /* 0 */
448
449 struct winsize ws;
450 int t = ptyslavefd;
451
452 /*
453 * set up the tty modes as we like them to be.
454 */
455 init_termbuf();
456# ifdef TIOCGWINSZ
457 if (def_row || def_col) {
458 bzero((char *)&ws, sizeof(ws));
459 ws.ws_col = def_col;
460 ws.ws_row = def_row;
461 ioctl(t, TIOCSWINSZ, (char *)&ws);
462 }
463# endif
464
465 /*
466 * Settings for all other termios/termio based
467 * systems, other than 4.4BSD. In 4.4BSD the
468 * kernel does the initial terminal setup.
469 *
470 * XXX what about linux?
471 */
472# ifndef OXTABS
473# define OXTABS 0
474# endif
475 termbuf.c_lflag |= ECHO;
476 termbuf.c_oflag |= OPOST|ONLCR|OXTABS;
477 termbuf.c_iflag |= ICRNL;
478 termbuf.c_iflag &= ~IXOFF;
479
480 tty_rspeed((def_rspeed > 0) ? def_rspeed : 9600);
481 tty_tspeed((def_tspeed > 0) ? def_tspeed : 9600);
482# ifdef LINEMODE
483 if (waslm) tty_setlinemode(1);
484# endif /* LINEMODE */
485
486 /*
487 * Set the tty modes, and make this our controlling tty.
488 */
489 set_termbuf();
490 if (login_tty(t) == -1) fatalperror(net, "login_tty");
491
492 if (net > 2) close(net);
493 if (pty > 2) close(pty);
494 return t;
495}
496
497#if 0
498#ifndef O_NOCTTY
499#define O_NOCTTY 0
500#endif
501/*
502 * Open the specified slave side of the pty,
503 * making sure that we have a clean tty.
504 */
505static int cleanopen(char *lyne) {
506 register int t;
507
508 /*
509 * Make sure that other people can't open the
510 * slave side of the connection.
511 */
512 chown(lyne, 0, 0);
513 chmod(lyne, 0600);
514
515#ifndef NO_REVOKE
516 revoke(lyne);
517#endif
518
519 t = open(lyne, O_RDWR|O_NOCTTY);
520 if (t < 0) return(-1);
521
522 /*
523 * Hangup anybody else using this ttyp, then reopen it for
524 * ourselves.
525 */
526# if !defined(__linux__)
527 /* this looks buggy to me, our ctty is really a pty at this point */
528 signal(SIGHUP, SIG_IGN);
529 vhangup();
530 signal(SIGHUP, SIG_DFL);
531 t = open(lyne, O_RDWR|O_NOCTTY);
532 if (t < 0) return(-1);
533# endif
534 return(t);
535}
536#endif /* 0 */
537
538int login_tty(int t) {
539 if (setsid() < 0) fatalperror(net, "setsid()");
540 if (ioctl(t, TIOCSCTTY, (char *)0) < 0) {
541 fatalperror(net, "ioctl(sctty)");
542 }
543 if (t != 0) dup2(t, 0);
544 if (t != 1) dup2(t, 1);
545 if (t != 2) dup2(t, 2);
546 if (t > 2) close(t);
547 return 0;
548}
549
550/*
551 * startslave(host)
552 *
553 * Given a hostname, do whatever
554 * is necessary to startup the login process on the slave side of the pty.
555 */
556
557/* ARGSUSED */
558void startslave(const char *host, int autologin, char *autoname) {
559 int i;
560
561#if defined(AUTHENTICATE)
562 if (!autoname || !autoname[0]) autologin = 0;
563 if (autologin < auth_level) {
564 fatal(net, "Authorization failed");
565 exit(1);
566 }
567#endif
568
569 i = fork();
570 if (i < 0) fatalperror(net, "fork");
571 if (i) {
572 /* parent */
573 signal(SIGHUP,SIG_IGN);
574 close(ptyslavefd);
575 }
576 else {
577 /* child */
578 signal(SIGHUP,SIG_IGN);
579 getptyslave();
580 start_login(host, autologin, autoname);
581 /*NOTREACHED*/
582 }
583}
584
585char *envinit[3];
586
587void init_env(void) {
588 char **envp;
589 envp = envinit;
590 if ((*envp = getenv("TZ"))!=NULL)
591 *envp++ -= 3;
592 *envp = 0;
593 environ = envinit;
594}
595
596/*
597 * start_login(host)
598 *
599 * Assuming that we are now running as a child processes, this
600 * function will turn us into the login process.
601 */
602
603struct argv_stuff {
604 const char **argv;
605 int argc;
606 int argmax;
607};
608
609static void addarg(struct argv_stuff *, const char *);
610static void initarg(struct argv_stuff *);
611
612void start_login(const char *host, int autologin, const char *name) {
613 struct argv_stuff avs;
614 char *const *argvfoo;
615 (void)autologin;
616
617 initarg(&avs);
618
619 /*
620 * -h : pass on name of host.
621 * WARNING: -h is accepted by login if and only if
622 * getuid() == 0.
623 * -p : don't clobber the environment (so terminal type stays set).
624 *
625 * -f : force this login, he has already been authenticated
626 */
627 addarg(&avs, loginprg);
628 addarg(&avs, "-h");
629 addarg(&avs, host);
630#if !defined(NO_LOGIN_P)
631 addarg(&avs, "-p");
632#endif
633#ifdef BFTPDAEMON
634 /*
635 * Are we working as the bftp daemon? If so, then ask login
636 * to start bftp instead of shell.
637 */
638 if (bftpd) {
639 addarg(&avs, "-e");
640 addarg(&avs, BFTPPATH);
641 }
642 else
643#endif
644 {
645#if defined (SecurID)
646 /*
647 * don't worry about the -f that might get sent.
648 * A -s is supposed to override it anyhow.
649 */
650 if (require_SecurID) addarg(&avs, "-s");
651#endif
652 if (*name=='-') {
653 syslog(LOG_ERR, "Attempt to login with an option!");
654 name = "";
655 }
656#if defined (AUTHENTICATE)
657 if (auth_level >= 0 && autologin == AUTH_VALID) {
658# if !defined(NO_LOGIN_F)
659 addarg(&avs, "-f");
660# endif
661 addarg(&avs, name);
662 }
663 else
664#endif
665 {
666 if (getenv("USER")) {
667 addarg(&avs, getenv("USER"));
668 if (*getenv("USER") == '-') {
669 write(1,"I don't hear you!\r\n",19);
670 syslog(LOG_ERR,"Attempt to login with an option!");
671 exit(1);
672 }
673 }
674 }
675 }
676 closelog();
677 /* execv() should really take char const* const *, but it can't */
678 /*argvfoo = argv*/;
679 memcpy(&argvfoo, &avs.argv, sizeof(argvfoo));
680 execv(loginprg, argvfoo);
681
682 openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
683 syslog(LOG_ERR, "%s: %m\n", loginprg);
684 closelog();
685 fatalperror(net, loginprg);
686}
687
688static void initarg(struct argv_stuff *avs) {
689 /*
690 * 10 entries and a null
691 */
692 avs->argmax = 11;
693 avs->argv = malloc(sizeof(avs->argv[0]) * avs->argmax);
694 if (avs->argv == NULL) {
695 fprintf(stderr, "Out of memory\n");
696 exit(1);
697 }
698 avs->argc = 0;
699 avs->argv[0] = NULL;
700}
701
702static void addarg(struct argv_stuff *avs, const char *val) {
703 if (avs->argc>=avs->argmax-1) {
704 avs->argmax += 10;
705 avs->argv = realloc(avs->argv, sizeof(avs->argv[0])*avs->argmax);
706 if (avs->argv == NULL) {
707 fprintf(stderr, "Out of memory\n");
708 exit(1);
709 }
710 }
711
712 avs->argv[avs->argc++] = val;
713 avs->argv[avs->argc] = NULL;
714}
715
716/*
717 * cleanup()
718 *
719 * This is the routine to call when we are all through, to
720 * clean up anything that needs to be cleaned up.
721 */
722void cleanup(int sig) {
723 char *p;
724 (void)sig;
725
726 p = line + sizeof("/dev/") - 1;
727 if (logout(p)) logwtmp(p, "", "");
728#ifdef PARANOID_TTYS
729 /*
730 * dholland 16-Aug-96 chmod the tty when not in use
731 * This will make it harder to attach unwanted stuff to it
732 * (which is a security risk) but will break some programs.
733 */
734 chmod(line, 0600);
735#else
736 chmod(line, 0666);
737#endif
738 chown(line, 0, 0);
739 *p = 'p';
740 chmod(line, 0666);
741 chown(line, 0, 0);
742 shutdown(net, 2);
743 exit(1);
744}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/t.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/t.c
new file mode 100644
index 0000000..f1d76d1
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/t.c
@@ -0,0 +1,2 @@
1#include <stdio.h>
2int main(){printf ("%d\n", BUFSIZ);}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.8 b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.8
new file mode 100644
index 0000000..7353448
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.8
@@ -0,0 +1,486 @@
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" from: @(#)telnetd.8 6.8 (Berkeley) 4/20/91
33.\" $Id: telnetd.8,v 1.13 1999/12/14 12:53:06 dholland Exp $
34.\"
35.Dd December 29, 1996
36.Dt IN.TELNETD 8
37.Os "Linux NetKit (0.16)"
38.Sh NAME
39.Nm in.telnetd
40.Nd DARPA
41.Tn telnet
42protocol server
43.Sh SYNOPSIS
44.Nm /usr/sbin/in.telnetd
45.Op Fl hns
46.Op Fl a Ar authmode
47.Op Fl D Ar debugmode
48.Op Fl L Ar loginprg
49.Op Fl S Ar tos
50.Op Fl X Ar authtype
51.Op Fl edebug
52.Op Fl debug Ar port
53.Sh DESCRIPTION
54The
55.Nm in.telnetd
56program is a server which supports the
57.Tn DARPA
58.Tn telnet
59interactive communication protocol.
60.Nm In.telnetd
61is normally invoked by the internet server (see
62.Xr inetd 8 )
63for requests to connect to the
64.Tn telnet
65port as indicated by the
66.Pa /etc/services
67file (see
68.Xr services 5 ) .
69The
70.Fl debug
71option may be used to start up
72.Nm in.telnetd
73manually, instead of through
74.Xr inetd 8 .
75If started up this way,
76.Ar port
77may be specified to run
78.Nm in.telnetd
79on an alternate
80.Tn TCP
81port number.
82.Pp
83The
84.Nm in.telnetd
85program accepts the following options:
86.Bl -tag -width "-a authmode"
87.It Fl a Ar authmode
88This option may be used for specifying what mode should
89be used for authentication.
90Note that this option is only useful if
91.Nm in.telnetd
92has been compiled with support for authentication, which is not
93available in the current version. The following values of
94.Ar authmode
95are understood:
96.Bl -tag -width debug
97.It debug
98Turns on authentication debugging code.
99.It user
100Only allow connections when the remote user can provide valid
101authentication information to identify the remote user, and is allowed
102access to the specified account without providing a password.
103.It valid
104Only allow connections when the remote user can provide valid
105authentication information to identify the remote user. The
106.Xr login 1
107command will provide any additional user verification needed if the
108remote user is not allowed automatic access to the specified account.
109.It other
110Only allow connections that supply some authentication information.
111This option is currently not supported by any of the existing
112authentication mechanisms, and is thus the same as specifying
113.Cm valid .
114.It none
115This is the default state. Authentication information is not
116required. If no or insufficient authentication information is
117provided, then the
118.Xr login 1
119program will provide the necessary user verification.
120.It off
121This disables the authentication code. All user verification will
122happen through the
123.Xr login 1
124program.
125.El
126.It Fl D Ar debugmode
127This option may be used for debugging purposes. This allows
128.Nm in.telnetd
129to print out debugging information to the connection, allowing the
130user to see what
131.Nm in.telnetd
132is doing. There are several possible values for
133.Ar debugmode:
134.Bl -tag -width exercise
135.It Cm options
136Prints information about the negotiation of
137.Tn telnet
138options.
139.It Cm report
140Prints the
141.Cm options
142information, plus some additional information about what processing is
143going on.
144.It Cm netdata
145Displays the data stream received by
146.Nm in.telnetd.
147.It Cm ptydata
148Displays data written to the pty.
149.It Cm exercise
150Has not been implemented yet.
151.El
152.It Fl edebug
153If
154.Nm in.telnetd
155has been compiled with support for encryption, then the
156.Fl edebug
157option may be used to enable encryption debugging code.
158.It Fl h
159Disables the printing of host-specific information before
160login has been completed.
161.It Fl L Ar loginprg
162This option may be used to specify a different login program.
163By default,
164.Pa /usr/lib/telnetd/login
165is used.
166.It Fl n
167Disable
168.Dv TCP
169keep-alives. Normally
170.Nm in.telnetd
171enables the
172.Tn TCP
173keep-alive mechanism to probe connections that
174have been idle for some period of time to determine
175if the client is still there, so that idle connections
176from machines that have crashed or can no longer
177be reached may be cleaned up.
178.It Fl s
179This option is only enabled if
180.Nm in.telnetd
181is compiled with support for
182.Tn SecurID
183cards.
184It causes the
185.Fl s
186option to be passed on to
187.Xr login 1 ,
188and thus is only useful if
189.Xr login 1
190supports the
191.Fl s
192flag to indicate that only
193.Tn SecurID
194validated logins are allowed. This is usually useful for controlling
195remote logins from outside of a firewall.
196.It Fl S Ar tos
197Sets the IP type-of-service (TOS) option for the telnet
198connection to the value
199.Ar tos .
200.It Fl X Ar authtype
201This option is only valid if
202.Nm in.telnetd
203has been built with support for the authentication option.
204It disables the use of
205.Ar authtype
206authentication, and
207can be used to temporarily disable
208a specific authentication type without having to recompile
209.Nm in.telnetd .
210.El
211.Pp
212If the file
213.Pa /etc/issue.net
214is present,
215.Nm in.telnetd
216will display its contents before the login prompt of a telnet session (see
217.Xr issue.net 5 ) .
218.Pp
219.Nm In.telnetd
220operates by allocating a pseudo-terminal device (see
221.Xr pty 4 )
222for a client, then creating a login process which has
223the slave side of the pseudo-terminal as
224.Dv stdin ,
225.Dv stdout ,
226and
227.Dv stderr .
228.Nm In.telnetd
229manipulates the master side of the pseudo-terminal,
230implementing the
231.Tn telnet
232protocol and passing characters
233between the remote client and the login process.
234.Pp
235When a
236.Tn telnet
237session is started up,
238.Nm in.telnetd
239sends
240.Tn telnet
241options to the client side indicating
242a willingness to do the
243following
244.Tn telnet
245options, which are described in more detail below:
246.Bd -literal -offset indent
247DO AUTHENTICATION
248WILL ENCRYPT
249DO TERMINAL TYPE
250DO TSPEED
251DO XDISPLOC
252DO NEW-ENVIRON
253DO ENVIRON
254WILL SUPPRESS GO AHEAD
255DO ECHO
256DO LINEMODE
257DO NAWS
258WILL STATUS
259DO LFLOW
260DO TIMING-MARK
261.Ed
262.Pp
263The pseudo-terminal allocated to the client is configured
264to operate in \*(lqcooked\*(rq mode, and with
265.Dv XTABS
266.Dv CRMOD
267enabled (see
268.Xr tty 4 ) .
269.Pp
270.Nm In.telnetd
271has support for enabling locally the following
272.Tn telnet
273options:
274.Bl -tag -width "DO AUTHENTICATION"
275.It "WILL ECHO"
276When the
277.Dv LINEMODE
278option is enabled, a
279.Dv WILL ECHO
280or
281.Dv WONT ECHO
282will be sent to the client to indicate the
283current state of terminal echoing.
284When terminal echo is not desired, a
285.Dv WILL ECHO
286is sent to indicate that
287.Tn in.telnetd
288will take care of echoing any data that needs to be
289echoed to the terminal, and then nothing is echoed.
290When terminal echo is desired, a
291.Dv WONT ECHO
292is sent to indicate that
293.Tn in.telnetd
294will not be doing any terminal echoing, so the
295client should do any terminal echoing that is needed.
296.It "WILL BINARY"
297Indicates that the client is willing to send a
2988 bits of data, rather than the normal 7 bits
299of the Network Virtual Terminal.
300.It "WILL SGA"
301Indicates that it will not be sending
302.Dv IAC GA,
303go ahead, commands.
304.It "WILL STATUS"
305Indicates a willingness to send the client, upon
306request, of the current status of all
307.Tn TELNET
308options.
309.It "WILL TIMING-MARK"
310Whenever a
311.Dv DO TIMING-MARK
312command is received, it is always responded
313to with a
314.Dv WILL TIMING-MARK
315.It "WILL LOGOUT"
316When a
317.Dv DO LOGOUT
318is received, a
319.Dv WILL LOGOUT
320is sent in response, and the
321.Tn TELNET
322session is shut down.
323.It "WILL ENCRYPT"
324Only sent if
325.Nm in.telnetd
326is compiled with support for data encryption, and
327indicates a willingness to decrypt
328the data stream.
329.El
330.Pp
331.Nm In.telnetd
332has support for enabling remotely the following
333.Tn TELNET
334options:
335.Bl -tag -width "DO AUTHENTICATION"
336.It "DO BINARY"
337Sent to indicate that
338.Tn in.telnetd
339is willing to receive an 8 bit data stream.
340.It "DO LFLOW"
341Requests that the client handle flow control
342characters remotely.
343.It "DO ECHO"
344This is not really supported, but is sent to identify a 4.2BSD
345.Xr telnet 1
346client, which will improperly respond with
347.Dv WILL ECHO.
348If a
349.Dv WILL ECHO
350is received, a
351.Dv DONT ECHO
352will be sent in response.
353.It "DO TERMINAL-TYPE"
354Indicates a desire to be able to request the
355name of the type of terminal that is attached
356to the client side of the connection.
357.It "DO SGA"
358Indicates that it does not need to receive
359.Dv IAC GA,
360the go ahead command.
361.It "DO NAWS"
362Requests that the client inform the server when
363the window (display) size changes.
364.It "DO TERMINAL-SPEED"
365Indicates a desire to be able to request information
366about the speed of the serial line to which
367the client is attached.
368.It "DO XDISPLOC"
369Indicates a desire to be able to request the name
370of the X windows display that is associated with
371the telnet client.
372.It "DO NEW-ENVIRON"
373Indicates a desire to be able to request environment
374variable information, as described in RFC 1572.
375.It "DO ENVIRON"
376Indicates a desire to be able to request environment
377variable information, as described in RFC 1408.
378.It "DO LINEMODE"
379Only sent if
380.Nm in.telnetd
381is compiled with support for linemode, and
382requests that the client do line by line processing.
383.It "DO TIMING-MARK"
384Only sent if
385.Nm in.telnetd
386is compiled with support for both linemode and
387kludge linemode, and the client responded with
388.Dv WONT LINEMODE.
389If the client responds with
390.Dv WILL TM,
391the it is assumed that the client supports
392kludge linemode.
393Note that the
394.Op Fl k
395option can be used to disable this.
396.It "DO AUTHENTICATION"
397Only sent if
398.Nm in.telnetd
399is compiled with support for authentication, and
400indicates a willingness to receive authentication
401information for automatic login.
402.It "DO ENCRYPT"
403Only sent if
404.Nm in.telnetd
405is compiled with support for data encryption, and
406indicates a willingness to decrypt
407the data stream.
408.Xr issue.net 5 ) .
409.Sh FILES
410.Pa /etc/services ,
411.Pa /etc/issue.net
412.Sh "SEE ALSO"
413.Xr telnet 1 ,
414.Xr login 1 ,
415.Xr issue.net 5 ,
416.Sh STANDARDS
417.Bl -tag -compact -width RFC-1572
418.It Cm RFC-854
419.Tn TELNET
420PROTOCOL SPECIFICATION
421.It Cm RFC-855
422TELNET OPTION SPECIFICATIONS
423.It Cm RFC-856
424TELNET BINARY TRANSMISSION
425.It Cm RFC-857
426TELNET ECHO OPTION
427.It Cm RFC-858
428TELNET SUPPRESS GO AHEAD OPTION
429.It Cm RFC-859
430TELNET STATUS OPTION
431.It Cm RFC-860
432TELNET TIMING MARK OPTION
433.It Cm RFC-861
434TELNET EXTENDED OPTIONS - LIST OPTION
435.It Cm RFC-885
436TELNET END OF RECORD OPTION
437.It Cm RFC-1073
438Telnet Window Size Option
439.It Cm RFC-1079
440Telnet Terminal Speed Option
441.It Cm RFC-1091
442Telnet Terminal-Type Option
443.It Cm RFC-1096
444Telnet X Display Location Option
445.It Cm RFC-1123
446Requirements for Internet Hosts -- Application and Support
447.It Cm RFC-1184
448Telnet Linemode Option
449.It Cm RFC-1372
450Telnet Remote Flow Control Option
451.It Cm RFC-1416
452Telnet Authentication Option
453.It Cm RFC-1411
454Telnet Authentication: Kerberos Version 4
455.It Cm RFC-1412
456Telnet Authentication: SPX
457.It Cm RFC-1571
458Telnet Environment Option Interoperability Issues
459.It Cm RFC-1572
460Telnet Environment Option
461.Sh BUGS
462Some
463.Tn TELNET
464commands are only partially implemented.
465.Pp
466Because of bugs in the original 4.2 BSD
467.Xr telnet 1 ,
468.Nm in.telnetd
469performs some dubious protocol exchanges to try to discover if the remote
470client is, in fact, a 4.2 BSD
471.Xr telnet 1 .
472.Pp
473Binary mode
474has no common interpretation except between similar operating systems
475(Unix in this case).
476.Pp
477The terminal type name received from the remote client is converted to
478lower case.
479.Pp
480.Nm In.telnetd
481never sends
482.Tn TELNET
483.Dv IAC GA
484(go ahead) commands.
485.Pp
486The source code is not comprehensible.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.c
new file mode 100644
index 0000000..ffa49e8
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.c
@@ -0,0 +1,1163 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34char copyright[] =
35 "@(#) Copyright (c) 1989 Regents of the University of California.\n"
36 "All rights reserved.\n";
37
38/*
39 * From: @(#)telnetd.c 5.48 (Berkeley) 3/1/91
40 */
41char telnetd_rcsid[] =
42 "$Id: telnetd.c,v 1.23 1999/12/14 00:43:31 dholland Exp $";
43
44#include "../version.h"
45
46#include <netdb.h>
47#include <termcap.h>
48#include <netinet/in.h>
49/* #include <netinet/ip.h> */ /* Don't think this is used at all here */
50#include <arpa/inet.h>
51#include <assert.h>
52#include "telnetd.h"
53#include "pathnames.h"
54#include "setproctitle.h"
55
56#if defined(AUTHENTICATE)
57#include <libtelnet/auth.h>
58#include <libtelnet/auth-proto.h>
59#include <libtelnet/misc-proto.h>
60int auth_level = 0;
61#endif
62#if defined(SecurID)
63int require_SecurID = 0;
64#endif
65
66static void doit(struct sockaddr_in *who);
67static int terminaltypeok(const char *s);
68
69/*
70 * I/O data buffers,
71 * pointers, and counters.
72 */
73char ptyibuf[BUFSIZ], *ptyip = ptyibuf;
74char ptyibuf2[BUFSIZ];
75
76int hostinfo = 1; /* do we print login banner? */
77
78int debug = 0;
79int keepalive = 1;
80#ifdef LOGIN_WRAPPER
81char *loginprg = LOGIN_WRAPPER;
82#else
83char *loginprg = _PATH_LOGIN;
84#endif
85char *progname;
86
87extern void usage(void);
88
89int
90main(int argc, char *argv[], char *env[])
91{
92 struct sockaddr_in from;
93 int on = 1;
94 socklen_t fromlen;
95 register int ch;
96
97#if defined(IPPROTO_IP) && defined(IP_TOS)
98 int tos = -1;
99#endif
100
101 initsetproctitle(argc, argv, env);
102
103 pfrontp = pbackp = ptyobuf;
104 netip = netibuf;
105 nfrontp = nbackp = netobuf;
106#if defined(ENCRYPT)
107 nclearto = 0;
108#endif
109
110 progname = strdup(*argv);
111
112 while ((ch = getopt(argc, argv, "d:a:e:lhnr:I:D:B:sS:a:X:L:")) != EOF) {
113 switch(ch) {
114
115#ifdef AUTHENTICATE
116 case 'a':
117 /*
118 * Check for required authentication level
119 */
120 if (strcmp(optarg, "debug") == 0) {
121 extern int auth_debug_mode;
122 auth_debug_mode = 1;
123 } else if (strcasecmp(optarg, "none") == 0) {
124 auth_level = 0;
125 } else if (strcasecmp(optarg, "other") == 0) {
126 auth_level = AUTH_OTHER;
127 } else if (strcasecmp(optarg, "user") == 0) {
128 auth_level = AUTH_USER;
129 } else if (strcasecmp(optarg, "valid") == 0) {
130 auth_level = AUTH_VALID;
131 } else if (strcasecmp(optarg, "off") == 0) {
132 /*
133 * This hack turns off authentication
134 */
135 auth_level = -1;
136 } else {
137 fprintf(stderr,
138 "telnetd: unknown authorization level for -a\n");
139 }
140 break;
141#endif /* AUTHENTICATE */
142
143#ifdef BFTPDAEMON
144 case 'B':
145 bftpd++;
146 break;
147#endif /* BFTPDAEMON */
148
149 case 'd':
150 if (strcmp(optarg, "ebug") == 0) {
151 debug++;
152 break;
153 }
154 usage();
155 /* NOTREACHED */
156 break;
157
158#ifdef DIAGNOSTICS
159 case 'D':
160 /*
161 * Check for desired diagnostics capabilities.
162 */
163 if (!strcmp(optarg, "report")) {
164 diagnostic |= TD_REPORT|TD_OPTIONS;
165 } else if (!strcmp(optarg, "exercise")) {
166 diagnostic |= TD_EXERCISE;
167 } else if (!strcmp(optarg, "netdata")) {
168 diagnostic |= TD_NETDATA;
169 } else if (!strcmp(optarg, "ptydata")) {
170 diagnostic |= TD_PTYDATA;
171 } else if (!strcmp(optarg, "options")) {
172 diagnostic |= TD_OPTIONS;
173 } else {
174 usage();
175 /* NOT REACHED */
176 }
177 break;
178#endif /* DIAGNOSTICS */
179
180#ifdef AUTHENTICATE
181 case 'e':
182 if (strcmp(optarg, "debug") == 0) {
183 extern int auth_debug_mode;
184 auth_debug_mode = 1;
185 break;
186 }
187 usage();
188 /* NOTREACHED */
189 break;
190#endif /* AUTHENTICATE */
191
192 case 'h':
193 hostinfo = 0;
194 break;
195
196#ifdef LINEMODE
197 case 'l':
198 alwayslinemode = 1;
199 break;
200#endif /* LINEMODE */
201
202 case 'L':
203 loginprg = strdup(optarg);
204 /* XXX what if strdup fails? */
205 break;
206
207 case 'n':
208 keepalive = 0;
209 break;
210
211#ifdef SecurID
212 case 's':
213 /* SecurID required */
214 require_SecurID = 1;
215 break;
216#endif /* SecurID */
217 case 'S':
218#ifdef HAS_GETTOS
219 if ((tos = parsetos(optarg, "tcp")) < 0)
220 fprintf(stderr, "%s%s%s\n",
221 "telnetd: Bad TOS argument '", optarg,
222 "'; will try to use default TOS");
223#else
224 fprintf(stderr, "%s%s\n", "TOS option unavailable; ",
225 "-S flag not supported\n");
226#endif
227 break;
228
229#ifdef AUTHENTICATE
230 case 'X':
231 /*
232 * Check for invalid authentication types
233 */
234 auth_disable_name(optarg);
235 break;
236#endif /* AUTHENTICATE */
237
238 default:
239 fprintf(stderr, "telnetd: %c: unknown option\n", ch);
240 /* FALLTHROUGH */
241 case '?':
242 usage();
243 /* NOTREACHED */
244 }
245 }
246
247 argc -= optind;
248 argv += optind;
249
250 if (debug) {
251 int s, ns;
252 socklen_t foo;
253 struct servent *sp;
254 struct sockaddr_in sn;
255
256 memset(&sn, 0, sizeof(sn));
257 sn.sin_family = AF_INET;
258
259 if (argc > 1) {
260 usage();
261 /* NOTREACHED */
262 } else if (argc == 1) {
263 if ((sp = getservbyname(*argv, "tcp"))!=NULL) {
264 sn.sin_port = sp->s_port;
265 }
266 else {
267 int pt = atoi(*argv);
268 if (pt <= 0) {
269 fprintf(stderr, "telnetd: %s: bad port number\n",
270 *argv);
271 usage();
272 /* NOTREACHED */
273 }
274 sn.sin_port = htons(pt);
275 }
276 } else {
277 sp = getservbyname("telnet", "tcp");
278 if (sp == 0) {
279 fprintf(stderr, "telnetd: tcp/telnet: unknown service\n");
280 exit(1);
281 }
282 sn.sin_port = sp->s_port;
283 }
284
285 s = socket(AF_INET, SOCK_STREAM, 0);
286 if (s < 0) {
287 perror("telnetd: socket");;
288 exit(1);
289 }
290 (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
291 if (bind(s, (struct sockaddr *)&sn, sizeof(sn)) < 0) {
292 perror("bind");
293 exit(1);
294 }
295 if (listen(s, 1) < 0) {
296 perror("listen");
297 exit(1);
298 }
299 foo = sizeof(sn);
300 ns = accept(s, (struct sockaddr *)&sn, &foo);
301 if (ns < 0) {
302 perror("accept");
303 exit(1);
304 }
305 (void) dup2(ns, 0);
306 (void) close(ns);
307 (void) close(s);
308 } else if (argc > 0) {
309 usage();
310 /* NOT REACHED */
311 }
312
313 openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
314 fromlen = sizeof (from);
315 if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
316 fprintf(stderr, "%s: ", progname);
317 perror("getpeername");
318 _exit(1);
319 }
320 if (keepalive &&
321 setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0) {
322 syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
323 }
324
325#if defined(IPPROTO_IP) && defined(IP_TOS)
326 {
327# if defined(HAS_GETTOS)
328 struct tosent *tp;
329 if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
330 tos = tp->t_tos;
331# endif
332 if (tos < 0)
333 tos = 020; /* Low Delay bit */
334 if (tos
335 && (setsockopt(0, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0)
336 && (errno != ENOPROTOOPT) )
337 syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
338 }
339#endif /* defined(IPPROTO_IP) && defined(IP_TOS) */
340 net = 0;
341 doit(&from);
342 /* NOTREACHED */
343 return 0;
344} /* end of main */
345
346void
347usage(void)
348{
349 fprintf(stderr, "Usage: telnetd");
350#ifdef AUTHENTICATE
351 fprintf(stderr, " [-a (debug|other|user|valid|off)]\n\t");
352#endif
353#ifdef BFTPDAEMON
354 fprintf(stderr, " [-B]");
355#endif
356 fprintf(stderr, " [-debug port]");
357#ifdef DIAGNOSTICS
358 fprintf(stderr, " [-D (options|report|exercise|netdata|ptydata)]\n\t");
359#endif
360#ifdef AUTHENTICATE
361 fprintf(stderr, " [-edebug]");
362#endif
363 fprintf(stderr, " [-h]");
364#ifdef LINEMODE
365 fprintf(stderr, " [-l]");
366#endif
367 fprintf(stderr, " [-L login_program]");
368 fprintf(stderr, " [-n]");
369#ifdef SecurID
370 fprintf(stderr, " [-s]");
371#endif
372#ifdef AUTHENTICATE
373 fprintf(stderr, " [-X auth-type]");
374#endif
375 fprintf(stderr, "\n");
376 exit(1);
377}
378
379/*
380 * getterminaltype
381 *
382 * Ask the other end to send along its terminal type and speed.
383 * Output is the variable terminaltype filled in.
384 */
385
386static void _gettermname(void);
387
388static
389int
390getterminaltype(char *name)
391{
392 int retval = -1;
393 (void)name;
394
395 settimer(baseline);
396#if defined(AUTHENTICATE)
397 /*
398 * Handle the Authentication option before we do anything else.
399 */
400 send_do(TELOPT_AUTHENTICATION, 1);
401 while (his_will_wont_is_changing(TELOPT_AUTHENTICATION))
402 ttloop();
403 if (his_state_is_will(TELOPT_AUTHENTICATION)) {
404 retval = auth_wait(name);
405 }
406#endif
407
408#if defined(ENCRYPT)
409 send_will(TELOPT_ENCRYPT, 1);
410#endif
411 send_do(TELOPT_TTYPE, 1);
412 send_do(TELOPT_TSPEED, 1);
413 send_do(TELOPT_XDISPLOC, 1);
414 send_do(TELOPT_ENVIRON, 1);
415 while (
416#if defined(ENCRYPT)
417 his_do_dont_is_changing(TELOPT_ENCRYPT) ||
418#endif
419 his_will_wont_is_changing(TELOPT_TTYPE) ||
420 his_will_wont_is_changing(TELOPT_TSPEED) ||
421 his_will_wont_is_changing(TELOPT_XDISPLOC) ||
422 his_will_wont_is_changing(TELOPT_ENVIRON)) {
423 ttloop();
424 }
425#if defined(ENCRYPT)
426 /*
427 * Wait for the negotiation of what type of encryption we can
428 * send with. If autoencrypt is not set, this will just return.
429 */
430 if (his_state_is_will(TELOPT_ENCRYPT)) {
431 encrypt_wait();
432 }
433#endif
434 if (his_state_is_will(TELOPT_TSPEED)) {
435 netoprintf("%c%c%c%c%c%c",
436 IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE);
437 }
438 if (his_state_is_will(TELOPT_XDISPLOC)) {
439 netoprintf("%c%c%c%c%c%c",
440 IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE);
441 }
442 if (his_state_is_will(TELOPT_ENVIRON)) {
443 netoprintf("%c%c%c%c%c%c",
444 IAC, SB, TELOPT_ENVIRON, TELQUAL_SEND, IAC, SE);
445 }
446 if (his_state_is_will(TELOPT_TTYPE)) {
447 netoprintf("%c%c%c%c%c%c",
448 IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE);
449 }
450 if (his_state_is_will(TELOPT_TSPEED)) {
451 while (sequenceIs(tspeedsubopt, baseline))
452 ttloop();
453 }
454 if (his_state_is_will(TELOPT_XDISPLOC)) {
455 while (sequenceIs(xdisplocsubopt, baseline))
456 ttloop();
457 }
458 if (his_state_is_will(TELOPT_ENVIRON)) {
459 while (sequenceIs(environsubopt, baseline))
460 ttloop();
461 }
462 if (his_state_is_will(TELOPT_TTYPE)) {
463 char first[256], last[256];
464
465 while (sequenceIs(ttypesubopt, baseline))
466 ttloop();
467
468 /*
469 * If the other side has already disabled the option, then
470 * we have to just go with what we (might) have already gotten.
471 */
472 if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) {
473 /*
474 * Due to state.c, terminaltype points to a static char[41].
475 * Therefore, this assert cannot fail, and therefore, strings
476 * arising from "terminaltype" can be safely strcpy'd into
477 * first[] or last[].
478 */
479 assert(strlen(terminaltype) < sizeof(first));
480
481 strcpy(first, terminaltype);
482
483 for(;;) {
484 /*
485 * Save the unknown name, and request the next name.
486 */
487 strcpy(last, terminaltype);
488
489 _gettermname();
490 assert(strlen(terminaltype) < sizeof(first));
491
492 if (terminaltypeok(terminaltype))
493 break;
494
495 if (!strcmp(last, terminaltype) ||
496 his_state_is_wont(TELOPT_TTYPE)) {
497 /*
498 * We've hit the end. If this is the same as
499 * the first name, just go with it.
500 */
501 if (!strcmp(first, terminaltype))
502 break;
503 /*
504 * Get the terminal name one more time, so that
505 * RFC1091 compliant telnets will cycle back to
506 * the start of the list.
507 */
508 _gettermname();
509 assert(strlen(terminaltype) < sizeof(first));
510
511 if (strcmp(first, terminaltype)) {
512 /*
513 * first[] came from terminaltype, so it must fit
514 * back in.
515 */
516 strcpy(terminaltype, first);
517 }
518 break;
519 }
520 }
521 }
522 }
523 return(retval);
524} /* end of getterminaltype */
525
526static
527void
528_gettermname(void)
529{
530 /*
531 * If the client turned off the option,
532 * we can't send another request, so we
533 * just return.
534 */
535 if (his_state_is_wont(TELOPT_TTYPE))
536 return;
537
538 settimer(baseline);
539 netoprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE);
540 while (sequenceIs(ttypesubopt, baseline))
541 ttloop();
542}
543
544static int
545terminaltypeok(const char *s)
546{
547 /* char buf[2048]; */
548
549 if (terminaltype == NULL)
550 return(1);
551
552 /*
553 * Fix from Chris Evans: if it has a / in it, termcap will
554 * treat it as a filename. Oops.
555 */
556 if (strchr(s, '/')) {
557 return 0;
558 }
559
560 /*
561 * If it's absurdly long, accept it without asking termcap.
562 *
563 * This means that it won't get seen again until after login,
564 * at which point exploiting buffer problems in termcap doesn't
565 * gain one anything.
566 *
567 * It's possible this limit ought to be raised to 128, but nothing
568 * in my termcap is more than 64, 64 is _plenty_ for most, and while
569 * buffers aren't likely to be smaller than 64, they might be 80 and
570 * thus less than 128.
571 */
572 if (strlen(s) > 63) {
573 return 0;
574 }
575
576 /*
577 * tgetent() will return 1 if the type is known, and
578 * 0 if it is not known. If it returns -1, it couldn't
579 * open the database. But if we can't open the database,
580 * it won't help to say we failed, because we won't be
581 * able to verify anything else. So, we treat -1 like 1.
582 */
583
584 /*
585 * Don't do this - tgetent is not really trustworthy. Assume
586 * the terminal type is one we know; terminal types are pretty
587 * standard now. And if it isn't, it's unlikely we're going to
588 * know anything else the remote telnet might send as an alias
589 * for it.
590 *
591 * if (tgetent(buf, s) == 0)
592 * return(0);
593 */
594 return(1);
595}
596
597#ifndef MAXHOSTNAMELEN
598#define MAXHOSTNAMELEN 64
599#endif /* MAXHOSTNAMELEN */
600
601char host_name[MAXHOSTNAMELEN];
602char remote_host_name[MAXHOSTNAMELEN];
603
604extern void telnet(int, int);
605
606/*
607 * Get a pty, scan input lines.
608 */
609static void
610doit(struct sockaddr_in *who)
611{
612 const char *host;
613 struct hostent *hp;
614 int level;
615 char user_name[256];
616
617 /*
618 * Find an available pty to use.
619 */
620 pty = getpty();
621 if (pty < 0)
622 fatalperror(net, "getpty");
623
624 /* get name of connected client */
625 hp = gethostbyaddr((char *)&who->sin_addr, sizeof (struct in_addr),
626 who->sin_family);
627 if (hp)
628 host = hp->h_name;
629 else
630 host = inet_ntoa(who->sin_addr);
631
632 /*
633 * We must make a copy because Kerberos is probably going
634 * to also do a gethost* and overwrite the static data...
635 */
636 {
637 int i;
638 strncpy(remote_host_name, host, sizeof(remote_host_name)-1);
639 remote_host_name[sizeof(remote_host_name)-1] = 0;
640
641 /* Disallow funnies. */
642 for (i=0; remote_host_name[i]; i++) {
643 if (remote_host_name[i]<=32 || remote_host_name[i]>126)
644 remote_host_name[i] = '?';
645 }
646 }
647 host = remote_host_name;
648
649 /* Get local host name */
650 {
651 struct hostent *h;
652 gethostname(host_name, sizeof(host_name));
653 h = gethostbyname(host_name);
654 if (h) {
655 strncpy(host_name, h->h_name, sizeof(host_name));
656 host_name[sizeof(host_name)-1] = 0;
657 }
658 }
659
660#if defined(AUTHENTICATE) || defined(ENCRYPT)
661 auth_encrypt_init(host_name, host, "TELNETD", 1);
662#endif
663
664 init_env();
665 /*
666 * get terminal type.
667 */
668 *user_name = 0;
669 level = getterminaltype(user_name);
670 setenv("TERM", terminaltype ? terminaltype : "network", 1);
671
672 /* TODO list stuff provided by Laszlo Vecsey <master@internexus.net> */
673
674 /*
675 * Set REMOTEHOST environment variable
676 */
677 setproctitle("%s", host);
678 setenv("REMOTEHOST", host, 0);
679
680 /*
681 * Start up the login process on the slave side of the terminal
682 */
683 startslave(host, level, user_name);
684
685 telnet(net, pty); /* begin server processing */
686
687 /*NOTREACHED*/
688} /* end of doit */
689
690/*
691 * Main loop. Select from pty and network, and
692 * hand data to telnet receiver finite state machine.
693 */
694void telnet(int f, int p)
695{
696 int on = 1;
697 char *HE;
698 const char *IM;
699
700 /*
701 * Initialize the slc mapping table.
702 */
703 get_slc_defaults();
704
705 /*
706 * Do some tests where it is desireable to wait for a response.
707 * Rather than doing them slowly, one at a time, do them all
708 * at once.
709 */
710 if (my_state_is_wont(TELOPT_SGA))
711 send_will(TELOPT_SGA, 1);
712 /*
713 * Is the client side a 4.2 (NOT 4.3) system? We need to know this
714 * because 4.2 clients are unable to deal with TCP urgent data.
715 *
716 * To find out, we send out a "DO ECHO". If the remote system
717 * answers "WILL ECHO" it is probably a 4.2 client, and we note
718 * that fact ("WILL ECHO" ==> that the client will echo what
719 * WE, the server, sends it; it does NOT mean that the client will
720 * echo the terminal input).
721 */
722 send_do(TELOPT_ECHO, 1);
723
724#ifdef LINEMODE
725 if (his_state_is_wont(TELOPT_LINEMODE)) {
726 /*
727 * Query the peer for linemode support by trying to negotiate
728 * the linemode option.
729 */
730 linemode = 0;
731 editmode = 0;
732 send_do(TELOPT_LINEMODE, 1); /* send do linemode */
733 }
734#endif /* LINEMODE */
735
736 /*
737 * Send along a couple of other options that we wish to negotiate.
738 */
739 send_do(TELOPT_NAWS, 1);
740 send_will(TELOPT_STATUS, 1);
741 flowmode = 1; /* default flow control state */
742 send_do(TELOPT_LFLOW, 1);
743
744 /*
745 * Spin, waiting for a response from the DO ECHO. However,
746 * some REALLY DUMB telnets out there might not respond
747 * to the DO ECHO. So, we spin looking for NAWS, (most dumb
748 * telnets so far seem to respond with WONT for a DO that
749 * they don't understand...) because by the time we get the
750 * response, it will already have processed the DO ECHO.
751 * Kludge upon kludge.
752 */
753 while (his_will_wont_is_changing(TELOPT_NAWS)) {
754 ttloop();
755 }
756
757 /*
758 * But...
759 * The client might have sent a WILL NAWS as part of its
760 * startup code; if so, we'll be here before we get the
761 * response to the DO ECHO. We'll make the assumption
762 * that any implementation that understands about NAWS
763 * is a modern enough implementation that it will respond
764 * to our DO ECHO request; hence we'll do another spin
765 * waiting for the ECHO option to settle down, which is
766 * what we wanted to do in the first place...
767 */
768 if (his_want_state_is_will(TELOPT_ECHO) &&
769 his_state_is_will(TELOPT_NAWS)) {
770 while (his_will_wont_is_changing(TELOPT_ECHO))
771 ttloop();
772 }
773 /*
774 * On the off chance that the telnet client is broken and does not
775 * respond to the DO ECHO we sent, (after all, we did send the
776 * DO NAWS negotiation after the DO ECHO, and we won't get here
777 * until a response to the DO NAWS comes back) simulate the
778 * receipt of a will echo. This will also send a WONT ECHO
779 * to the client, since we assume that the client failed to
780 * respond because it believes that it is already in DO ECHO
781 * mode, which we do not want.
782 */
783 if (his_want_state_is_will(TELOPT_ECHO)) {
784 DIAG(TD_OPTIONS, netoprintf("td: simulating recv\r\n"););
785 willoption(TELOPT_ECHO);
786 }
787
788 /*
789 * Finally, to clean things up, we turn on our echo. This
790 * will break stupid 4.2 telnets out of local terminal echo.
791 */
792
793 if (my_state_is_wont(TELOPT_ECHO))
794 send_will(TELOPT_ECHO, 1);
795
796 /*
797 * Turn on packet mode
798 */
799 ioctl(p, TIOCPKT, (char *)&on);
800#if defined(LINEMODE) && defined(KLUDGELINEMODE)
801 /*
802 * Continuing line mode support. If client does not support
803 * real linemode, attempt to negotiate kludge linemode by sending
804 * the do timing mark sequence.
805 */
806 if (lmodetype < REAL_LINEMODE)
807 send_do(TELOPT_TM, 1);
808#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
809
810 /*
811 * Call telrcv() once to pick up anything received during
812 * terminal type negotiation, 4.2/4.3 determination, and
813 * linemode negotiation.
814 */
815 telrcv();
816
817 ioctl(f, FIONBIO, (char *)&on);
818 ioctl(p, FIONBIO, (char *)&on);
819
820#if defined(SO_OOBINLINE)
821 setsockopt(net, SOL_SOCKET, SO_OOBINLINE, &on, sizeof on);
822#endif /* defined(SO_OOBINLINE) */
823
824#ifdef SIGTSTP
825 signal(SIGTSTP, SIG_IGN);
826#endif
827#ifdef SIGTTOU
828 /*
829 * Ignoring SIGTTOU keeps the kernel from blocking us
830 * in ttioct() in /sys/tty.c.
831 */
832 signal(SIGTTOU, SIG_IGN);
833#endif
834
835 signal(SIGCHLD, cleanup);
836
837#ifdef TIOCNOTTY
838 {
839 register int t;
840 t = open(_PATH_TTY, O_RDWR);
841 if (t >= 0) {
842 (void) ioctl(t, TIOCNOTTY, (char *)0);
843 (void) close(t);
844 }
845 }
846#endif
847
848 /*
849 * Show banner that getty never gave.
850 *
851 * We put the banner in the pty input buffer. This way, it
852 * gets carriage return null processing, etc., just like all
853 * other pty --> client data.
854 */
855
856 if (getenv("USER"))
857 hostinfo = 0;
858
859 IM = DEFAULT_IM;
860 HE = 0;
861
862 edithost(HE, host_name);
863 if (hostinfo && *IM)
864 putf(IM, ptyibuf2);
865
866 if (pcc) strncat(ptyibuf2, ptyip, pcc+1);
867 ptyip = ptyibuf2;
868 pcc = strlen(ptyip);
869#ifdef LINEMODE
870 /*
871 * Last check to make sure all our states are correct.
872 */
873 init_termbuf();
874 localstat();
875#endif /* LINEMODE */
876
877 DIAG(TD_REPORT, netoprintf("td: Entering processing loop\r\n"););
878
879 for (;;) {
880 fd_set ibits, obits, xbits;
881 int c, hifd;
882
883 if (ncc < 0 && pcc < 0)
884 break;
885
886 FD_ZERO(&ibits);
887 FD_ZERO(&obits);
888 FD_ZERO(&xbits);
889 hifd=0;
890 /*
891 * Never look for input if there's still
892 * stuff in the corresponding output buffer
893 */
894 if (nfrontp - nbackp || pcc > 0) {
895 FD_SET(f, &obits);
896 if (f >= hifd) hifd = f+1;
897 }
898 else {
899 FD_SET(p, &ibits);
900 if (p >= hifd) hifd = p+1;
901 }
902 if (pfrontp - pbackp || ncc > 0) {
903 FD_SET(p, &obits);
904 if (p >= hifd) hifd = p+1;
905 }
906 else {
907 FD_SET(f, &ibits);
908 if (f >= hifd) hifd = f+1;
909 }
910 if (!SYNCHing) {
911 FD_SET(f, &xbits);
912 if (f >= hifd) hifd = f+1;
913 }
914 if ((c = select(hifd, &ibits, &obits, &xbits,
915 (struct timeval *)0)) < 1) {
916 if (c == -1) {
917 if (errno == EINTR) {
918 continue;
919 }
920 }
921 sleep(5);
922 continue;
923 }
924
925 /*
926 * Any urgent data?
927 */
928 if (FD_ISSET(net, &xbits)) {
929 SYNCHing = 1;
930 }
931
932 /*
933 * Something to read from the network...
934 */
935 if (FD_ISSET(net, &ibits)) {
936#if !defined(SO_OOBINLINE)
937 /*
938 * In 4.2 (and 4.3 beta) systems, the
939 * OOB indication and data handling in the kernel
940 * is such that if two separate TCP Urgent requests
941 * come in, one byte of TCP data will be overlaid.
942 * This is fatal for Telnet, but we try to live
943 * with it.
944 *
945 * In addition, in 4.2 (and...), a special protocol
946 * is needed to pick up the TCP Urgent data in
947 * the correct sequence.
948 *
949 * What we do is: if we think we are in urgent
950 * mode, we look to see if we are "at the mark".
951 * If we are, we do an OOB receive. If we run
952 * this twice, we will do the OOB receive twice,
953 * but the second will fail, since the second
954 * time we were "at the mark", but there wasn't
955 * any data there (the kernel doesn't reset
956 * "at the mark" until we do a normal read).
957 * Once we've read the OOB data, we go ahead
958 * and do normal reads.
959 *
960 * There is also another problem, which is that
961 * since the OOB byte we read doesn't put us
962 * out of OOB state, and since that byte is most
963 * likely the TELNET DM (data mark), we would
964 * stay in the TELNET SYNCH (SYNCHing) state.
965 * So, clocks to the rescue. If we've "just"
966 * received a DM, then we test for the
967 * presence of OOB data when the receive OOB
968 * fails (and AFTER we did the normal mode read
969 * to clear "at the mark").
970 */
971 if (SYNCHing) {
972 int atmark;
973
974 ioctl(net, SIOCATMARK, (char *)&atmark);
975 if (atmark) {
976 ncc = recv(net, netibuf, sizeof (netibuf), MSG_OOB);
977 if ((ncc == -1) && (errno == EINVAL)) {
978 ncc = read(net, netibuf, sizeof (netibuf));
979 if (sequenceIs(didnetreceive, gotDM)) {
980 SYNCHing = stilloob(net);
981 }
982 }
983 }
984 else {
985 ncc = read(net, netibuf, sizeof (netibuf));
986 }
987 }
988 else {
989 ncc = read(net, netibuf, sizeof (netibuf));
990 }
991 settimer(didnetreceive);
992#else /* !defined(SO_OOBINLINE)) */
993 ncc = read(net, netibuf, sizeof (netibuf));
994#endif /* !defined(SO_OOBINLINE)) */
995 if (ncc < 0 && errno == EWOULDBLOCK)
996 ncc = 0;
997 else {
998 if (ncc <= 0) {
999 break;
1000 }
1001 netip = netibuf;
1002 }
1003 DIAG((TD_REPORT | TD_NETDATA),
1004 netoprintf("td: netread %d chars\r\n", ncc););
1005 DIAG(TD_NETDATA, printdata("nd", netip, ncc));
1006 }
1007
1008 /*
1009 * Something to read from the pty...
1010 */
1011 if (FD_ISSET(p, &ibits)) {
1012 pcc = read(p, ptyibuf, BUFSIZ);
1013 /*
1014 * On some systems, if we try to read something
1015 * off the master side before the slave side is
1016 * opened, we get EIO.
1017 */
1018 if (pcc < 0 && (errno == EWOULDBLOCK || errno == EIO)) {
1019 pcc = 0;
1020 }
1021 else {
1022 if (pcc <= 0)
1023 break;
1024#ifdef LINEMODE
1025 /*
1026 * If ioctl from pty, pass it through net
1027 */
1028 if (ptyibuf[0] & TIOCPKT_IOCTL) {
1029 copy_termbuf(ptyibuf+1, pcc-1);
1030 localstat();
1031 pcc = 1;
1032 }
1033#endif /* LINEMODE */
1034 if (ptyibuf[0] & TIOCPKT_FLUSHWRITE) {
1035 netclear(); /* clear buffer back */
1036#ifndef NO_URGENT
1037 /*
1038 * There are client telnets on some
1039 * operating systems get screwed up
1040 * royally if we send them urgent
1041 * mode data.
1042 */
1043 netoprintf("%c%c", IAC, DM);
1044 neturg = nfrontp-1; /* off by one XXX */
1045#endif
1046 }
1047 if (his_state_is_will(TELOPT_LFLOW) &&
1048 (ptyibuf[0] &
1049 (TIOCPKT_NOSTOP|TIOCPKT_DOSTOP))) {
1050 netoprintf("%c%c%c%c%c%c",
1051 IAC, SB, TELOPT_LFLOW,
1052 ptyibuf[0] & TIOCPKT_DOSTOP ? 1 : 0,
1053 IAC, SE);
1054 }
1055 pcc--;
1056 ptyip = ptyibuf+1;
1057 }
1058 }
1059
1060 while (pcc > 0) {
1061 if ((&netobuf[BUFSIZ] - nfrontp) < 2)
1062 break;
1063 c = *ptyip++ & 0377, pcc--;
1064 if (c == IAC)
1065 *nfrontp++ = c;
1066 *nfrontp++ = c;
1067 if ((c == '\r' ) && (my_state_is_wont(TELOPT_BINARY))) {
1068 if (pcc > 0 && ((*ptyip & 0377) == '\n')) {
1069 *nfrontp++ = *ptyip++ & 0377;
1070 pcc--;
1071 }
1072 else *nfrontp++ = '\0';
1073 }
1074 }
1075
1076 if (FD_ISSET(f, &obits) && (nfrontp - nbackp) > 0)
1077 netflush();
1078 if (ncc > 0)
1079 telrcv();
1080 if (FD_ISSET(p, &obits) && (pfrontp - pbackp) > 0)
1081 ptyflush();
1082 }
1083 cleanup(0);
1084} /* end of telnet */
1085
1086#ifndef TCSIG
1087# ifdef TIOCSIG
1088# define TCSIG TIOCSIG
1089# endif
1090#endif
1091
1092/*
1093 * Send interrupt to process on other side of pty.
1094 * If it is in raw mode, just write NULL;
1095 * otherwise, write intr char.
1096 */
1097void interrupt(void) {
1098 ptyflush(); /* half-hearted */
1099
1100#ifdef TCSIG
1101 (void) ioctl(pty, TCSIG, (char *)SIGINT);
1102#else /* TCSIG */
1103 init_termbuf();
1104 *pfrontp++ = slctab[SLC_IP].sptr ?
1105 (unsigned char)*slctab[SLC_IP].sptr : '\177';
1106#endif /* TCSIG */
1107}
1108
1109/*
1110 * Send quit to process on other side of pty.
1111 * If it is in raw mode, just write NULL;
1112 * otherwise, write quit char.
1113 */
1114void sendbrk(void) {
1115 ptyflush(); /* half-hearted */
1116#ifdef TCSIG
1117 (void) ioctl(pty, TCSIG, (char *)SIGQUIT);
1118#else /* TCSIG */
1119 init_termbuf();
1120 *pfrontp++ = slctab[SLC_ABORT].sptr ?
1121 (unsigned char)*slctab[SLC_ABORT].sptr : '\034';
1122#endif /* TCSIG */
1123}
1124
1125void sendsusp(void) {
1126#ifdef SIGTSTP
1127 ptyflush(); /* half-hearted */
1128# ifdef TCSIG
1129 (void) ioctl(pty, TCSIG, (char *)SIGTSTP);
1130# else /* TCSIG */
1131 *pfrontp++ = slctab[SLC_SUSP].sptr ?
1132 (unsigned char)*slctab[SLC_SUSP].sptr : '\032';
1133# endif /* TCSIG */
1134#endif /* SIGTSTP */
1135}
1136
1137/*
1138 * When we get an AYT, if ^T is enabled, use that. Otherwise,
1139 * just send back "[Yes]".
1140 */
1141void recv_ayt(void) {
1142#if defined(SIGINFO) && defined(TCSIG)
1143 if (slctab[SLC_AYT].sptr && *slctab[SLC_AYT].sptr != _POSIX_VDISABLE) {
1144 (void) ioctl(pty, TCSIG, (char *)SIGINFO);
1145 return;
1146 }
1147#endif
1148 netoprintf("\r\n[%s : yes]\r\n", host_name);
1149}
1150
1151void doeof(void) {
1152 init_termbuf();
1153
1154#if defined(LINEMODE) && (VEOF == VMIN)
1155 if (!tty_isediting()) {
1156 extern char oldeofc;
1157 *pfrontp++ = oldeofc;
1158 return;
1159 }
1160#endif
1161 *pfrontp++ = slctab[SLC_EOF].sptr ?
1162 (unsigned char)*slctab[SLC_EOF].sptr : '\004';
1163}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.h
new file mode 100644
index 0000000..4c66824
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/telnetd.h
@@ -0,0 +1,50 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)telnetd.h 5.3 (Berkeley) 3/1/91
34 * $Id: telnetd.h,v 1.2 1999/03/27 07:46:21 dholland Exp $
35 */
36
37
38#include "defs.h"
39#include "ext.h"
40#include <errno.h>
41
42#ifdef DIAGNOSTICS
43#define DIAG(a,b) if (diagnostic & (a)) b
44#else
45#define DIAG(a,b)
46#endif
47
48/* other external variables */
49extern char **environ;
50
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/termstat.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/termstat.c
new file mode 100644
index 0000000..1871480
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/termstat.c
@@ -0,0 +1,588 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)termstat.c 5.10 (Berkeley) 3/22/91
36 */
37char termstat_rcsid[] =
38 "$Id: termstat.c,v 1.6 1999/12/12 14:59:45 dholland Exp $";
39
40#include "telnetd.h"
41
42/*
43 * local variables
44 */
45int def_tspeed = -1, def_rspeed = -1;
46#ifdef TIOCSWINSZ
47int def_row = 0, def_col = 0;
48#endif
49#ifdef LINEMODE
50static int _terminit = 0;
51#endif /* LINEMODE */
52
53#ifdef LINEMODE
54/*
55 * localstat
56 *
57 * This function handles all management of linemode.
58 *
59 * Linemode allows the client to do the local editing of data
60 * and send only complete lines to the server. Linemode state is
61 * based on the state of the pty driver. If the pty is set for
62 * external processing, then we can use linemode. Further, if we
63 * can use real linemode, then we can look at the edit control bits
64 * in the pty to determine what editing the client should do.
65 *
66 * Linemode support uses the following state flags to keep track of
67 * current and desired linemode state.
68 * alwayslinemode : true if -l was specified on the telnetd
69 * command line. It means to have linemode on as much as
70 * possible.
71 *
72 * lmodetype: signifies whether the client can
73 * handle real linemode, or if use of kludgeomatic linemode
74 * is preferred. It will be set to one of the following:
75 * REAL_LINEMODE : use linemode option
76 * KLUDGE_LINEMODE : use kludge linemode
77 * NO_LINEMODE : client is ignorant of linemode
78 *
79 * linemode, uselinemode : linemode is true if linemode
80 * is currently on, uselinemode is the state that we wish
81 * to be in. If another function wishes to turn linemode
82 * on or off, it sets or clears uselinemode.
83 *
84 * editmode, useeditmode : like linemode/uselinemode, but
85 * these contain the edit mode states (edit and trapsig).
86 *
87 * The state variables correspond to some of the state information
88 * in the pty.
89 * linemode:
90 * In real linemode, this corresponds to whether the pty
91 * expects external processing of incoming data.
92 * In kludge linemode, this more closely corresponds to the
93 * whether normal processing is on or not. (ICANON in
94 * system V, or COOKED mode in BSD.)
95 * If the -l option was specified (alwayslinemode), then
96 * an attempt is made to force external processing on at
97 * all times.
98 *
99 * The following heuristics are applied to determine linemode
100 * handling within the server.
101 * 1) Early on in starting up the server, an attempt is made
102 * to negotiate the linemode option. If this succeeds
103 * then lmodetype is set to REAL_LINEMODE and all linemode
104 * processing occurs in the context of the linemode option.
105 * 2) If the attempt to negotiate the linemode option failed,
106 * then we try to use kludge linemode. We test for this
107 * capability by sending "do Timing Mark". If a positive
108 * response comes back, then we assume that the client
109 * understands kludge linemode (ech!) and the
110 * lmodetype flag is set to KLUDGE_LINEMODE.
111 * 3) Otherwise, linemode is not supported at all and
112 * lmodetype remains set to NO_LINEMODE (which happens
113 * to be 0 for convenience).
114 * 4) At any time a command arrives that implies a higher
115 * state of linemode support in the client, we move to that
116 * linemode support.
117 *
118 * A short explanation of kludge linemode is in order here.
119 * 1) The heuristic to determine support for kludge linemode
120 * is to send a do timing mark. We assume that a client
121 * that supports timing marks also supports kludge linemode.
122 * A risky proposition at best.
123 * 2) Further negotiation of linemode is done by changing the
124 * the server's state regarding SGA. If server will SGA,
125 * then linemode is off, if server won't SGA, then linemode
126 * is on.
127 */
128 void
129localstat()
130{
131 void netflush();
132 int need_will_echo = 0;
133
134 /*
135 * Check for state of BINARY options.
136 */
137 if (tty_isbinaryin()) {
138 if (his_want_state_is_wont(TELOPT_BINARY))
139 send_do(TELOPT_BINARY, 1);
140 } else {
141 if (his_want_state_is_will(TELOPT_BINARY))
142 send_dont(TELOPT_BINARY, 1);
143 }
144
145 if (tty_isbinaryout()) {
146 if (my_want_state_is_wont(TELOPT_BINARY))
147 send_will(TELOPT_BINARY, 1);
148 } else {
149 if (my_want_state_is_will(TELOPT_BINARY))
150 send_wont(TELOPT_BINARY, 1);
151 }
152
153 /*
154 * Check for changes to flow control if client supports it.
155 */
156 if (his_state_is_will(TELOPT_LFLOW)) {
157 if (tty_flowmode() != flowmode) {
158 flowmode = tty_flowmode();
159 (void) netoprintf("%c%c%c%c%c%c", IAC, SB,
160 TELOPT_LFLOW, flowmode, IAC, SE);
161 }
162 }
163
164 /*
165 * Check linemode on/off state
166 */
167 uselinemode = tty_linemode();
168
169 /*
170 * If alwayslinemode is on, and pty is changing to turn it off, then
171 * force linemode back on.
172 */
173 if (alwayslinemode && linemode && !uselinemode) {
174 uselinemode = 1;
175 tty_setlinemode(uselinemode);
176 }
177
178#if defined(ENCRYPT)
179 /*
180 * If the terminal is not echoing, but editing is enabled,
181 * something like password input is going to happen, so
182 * if we the other side is not currently sending encrypted
183 * data, ask the other side to start encrypting.
184 */
185 if (his_state_is_will(TELOPT_ENCRYPT)) {
186 static int enc_passwd = 0;
187 if (uselinemode && !tty_isecho() && tty_isediting()
188 && (enc_passwd == 0) && !decrypt_input) {
189 encrypt_send_request_start();
190 enc_passwd = 1;
191 } else if (enc_passwd) {
192 encrypt_send_request_end();
193 enc_passwd = 0;
194 }
195 }
196#endif
197
198 /*
199 * Do echo mode handling as soon as we know what the
200 * linemode is going to be.
201 * If the pty has echo turned off, then tell the client that
202 * the server will echo. If echo is on, then the server
203 * will echo if in character mode, but in linemode the
204 * client should do local echoing. The state machine will
205 * not send anything if it is unnecessary, so don't worry
206 * about that here.
207 *
208 * If we need to send the WILL ECHO (because echo is off),
209 * then delay that until after we have changed the MODE.
210 * This way, when the user is turning off both editing
211 * and echo, the client will get editing turned off first.
212 * This keeps the client from going into encryption mode
213 * and then right back out if it is doing auto-encryption
214 * when passwords are being typed.
215 */
216 if (uselinemode) {
217 if (tty_isecho())
218 send_wont(TELOPT_ECHO, 1);
219 else
220 need_will_echo = 1;
221 }
222
223 /*
224 * If linemode is being turned off, send appropriate
225 * command and then we're all done.
226 */
227 if (!uselinemode && linemode) {
228# ifdef KLUDGELINEMODE
229 if (lmodetype == REAL_LINEMODE) {
230# endif /* KLUDGELINEMODE */
231 send_dont(TELOPT_LINEMODE, 1);
232# ifdef KLUDGELINEMODE
233 } else if (lmodetype == KLUDGE_LINEMODE)
234 send_will(TELOPT_SGA, 1);
235# endif /* KLUDGELINEMODE */
236 send_will(TELOPT_ECHO, 1);
237 linemode = uselinemode;
238 goto done;
239 }
240
241# ifdef KLUDGELINEMODE
242 /*
243 * If using real linemode check edit modes for possible later use.
244 * If we are in kludge linemode, do the SGA negotiation.
245 */
246 if (lmodetype == REAL_LINEMODE) {
247# endif /* KLUDGELINEMODE */
248 useeditmode = 0;
249 if (tty_isediting())
250 useeditmode |= MODE_EDIT;
251 if (tty_istrapsig())
252 useeditmode |= MODE_TRAPSIG;
253 if (tty_issofttab())
254 useeditmode |= MODE_SOFT_TAB;
255 if (tty_islitecho())
256 useeditmode |= MODE_LIT_ECHO;
257# ifdef KLUDGELINEMODE
258 } else if (lmodetype == KLUDGE_LINEMODE) {
259 if (tty_isediting() && uselinemode)
260 send_wont(TELOPT_SGA, 1);
261 else
262 send_will(TELOPT_SGA, 1);
263 }
264# endif /* KLUDGELINEMODE */
265
266 /*
267 * Negotiate linemode on if pty state has changed to turn it on.
268 * Send appropriate command and send along edit mode, then all done.
269 */
270 if (uselinemode && !linemode) {
271# ifdef KLUDGELINEMODE
272 if (lmodetype == KLUDGE_LINEMODE) {
273 send_wont(TELOPT_SGA, 1);
274 } else if (lmodetype == REAL_LINEMODE) {
275# endif /* KLUDGELINEMODE */
276 send_do(TELOPT_LINEMODE, 1);
277 /* send along edit modes */
278 (void) netoprintf("%c%c%c%c%c%c%c", IAC, SB,
279 TELOPT_LINEMODE, LM_MODE, useeditmode,
280 IAC, SE);
281 editmode = useeditmode;
282# ifdef KLUDGELINEMODE
283 }
284# endif /* KLUDGELINEMODE */
285 linemode = uselinemode;
286 goto done;
287 }
288
289# ifdef KLUDGELINEMODE
290 /*
291 * None of what follows is of any value if not using
292 * real linemode.
293 */
294 if (lmodetype < REAL_LINEMODE)
295 goto done;
296# endif /* KLUDGELINEMODE */
297
298 if (linemode && his_state_is_will(TELOPT_LINEMODE)) {
299 /*
300 * If edit mode changed, send edit mode.
301 */
302 if (useeditmode != editmode) {
303 /*
304 * Send along appropriate edit mode mask.
305 */
306 (void) netoprintf("%c%c%c%c%c%c%c", IAC, SB,
307 TELOPT_LINEMODE, LM_MODE, useeditmode,
308 IAC, SE);
309 editmode = useeditmode;
310 }
311
312
313 /*
314 * Check for changes to special characters in use.
315 */
316 start_slc(0);
317 check_slc();
318 (void) end_slc(0);
319 }
320
321done:
322 if (need_will_echo)
323 send_will(TELOPT_ECHO, 1);
324 /*
325 * Some things should be deferred until after the pty state has
326 * been set by the local process. Do those things that have been
327 * deferred now. This only happens once.
328 */
329 if (_terminit == 0) {
330 _terminit = 1;
331 defer_terminit();
332 }
333
334 netflush();
335 set_termbuf();
336 return;
337
338} /* end of localstat */
339#endif /* LINEMODE */
340
341
342/*
343 * clientstat
344 *
345 * Process linemode related requests from the client.
346 * Client can request a change to only one of linemode, editmode or slc's
347 * at a time, and if using kludge linemode, then only linemode may be
348 * affected.
349 */
350void clientstat(register int code, register int parm1, register int parm2)
351{
352 /*
353 * Get a copy of terminal characteristics.
354 */
355 init_termbuf();
356
357 /*
358 * Process request from client. code tells what it is.
359 */
360 switch (code) {
361#ifdef LINEMODE
362 case TELOPT_LINEMODE:
363 /*
364 * Don't do anything unless client is asking us to change
365 * modes.
366 */
367 uselinemode = (parm1 == WILL);
368 if (uselinemode != linemode) {
369# ifdef KLUDGELINEMODE
370 /*
371 * If using kludge linemode, make sure that
372 * we can do what the client asks.
373 * We can not turn off linemode if alwayslinemode
374 * and the ICANON bit is set.
375 */
376 if (lmodetype == KLUDGE_LINEMODE) {
377 if (alwayslinemode && tty_isediting()) {
378 uselinemode = 1;
379 }
380 }
381
382 /*
383 * Quit now if we can't do it.
384 */
385 if (uselinemode == linemode)
386 return;
387
388 /*
389 * If using real linemode and linemode is being
390 * turned on, send along the edit mode mask.
391 */
392 if (lmodetype == REAL_LINEMODE && uselinemode)
393# else /* KLUDGELINEMODE */
394 if (uselinemode)
395# endif /* KLUDGELINEMODE */
396 {
397 useeditmode = 0;
398 if (tty_isediting())
399 useeditmode |= MODE_EDIT;
400 if (tty_istrapsig)
401 useeditmode |= MODE_TRAPSIG;
402 if (tty_issofttab())
403 useeditmode |= MODE_SOFT_TAB;
404 if (tty_islitecho())
405 useeditmode |= MODE_LIT_ECHO;
406 (void) netoprintf("%c%c%c%c%c%c%c", IAC,
407 SB, TELOPT_LINEMODE, LM_MODE,
408 useeditmode, IAC, SE);
409 editmode = useeditmode;
410 }
411
412
413 tty_setlinemode(uselinemode);
414
415 linemode = uselinemode;
416
417 }
418 break;
419
420 case LM_MODE:
421 {
422 register int ack, changed;
423
424 /*
425 * Client has sent along a mode mask. If it agrees with
426 * what we are currently doing, ignore it; if not, it could
427 * be viewed as a request to change. Note that the server
428 * will change to the modes in an ack if it is different from
429 * what we currently have, but we will not ack the ack.
430 */
431 useeditmode &= MODE_MASK;
432 ack = (useeditmode & MODE_ACK);
433 useeditmode &= ~MODE_ACK;
434
435 if (changed = (useeditmode ^ editmode)) {
436 /*
437 * This check is for a timing problem. If the
438 * state of the tty has changed (due to the user
439 * application) we need to process that info
440 * before we write in the state contained in the
441 * ack!!! This gets out the new MODE request,
442 * and when the ack to that command comes back
443 * we'll set it and be in the right mode.
444 */
445 if (ack)
446 localstat();
447 if (changed & MODE_EDIT)
448 tty_setedit(useeditmode & MODE_EDIT);
449
450 if (changed & MODE_TRAPSIG)
451 tty_setsig(useeditmode & MODE_TRAPSIG);
452
453 if (changed & MODE_SOFT_TAB)
454 tty_setsofttab(useeditmode & MODE_SOFT_TAB);
455
456 if (changed & MODE_LIT_ECHO)
457 tty_setlitecho(useeditmode & MODE_LIT_ECHO);
458
459 set_termbuf();
460
461 if (!ack) {
462 (void) netoprintf("%c%c%c%c%c%c%c", IAC,
463 SB, TELOPT_LINEMODE, LM_MODE,
464 useeditmode|MODE_ACK,
465 IAC, SE);
466 }
467
468 editmode = useeditmode;
469 }
470
471 break;
472
473 } /* end of case LM_MODE */
474#endif /* LINEMODE */
475
476 case TELOPT_NAWS:
477#ifdef TIOCSWINSZ
478 {
479 struct winsize ws;
480
481 def_col = parm1;
482 def_row = parm2;
483#ifdef LINEMODE
484 /*
485 * Defer changing window size until after terminal is
486 * initialized.
487 */
488 if (terminit() == 0)
489 return;
490#endif /* LINEMODE */
491
492 /*
493 * Change window size as requested by client.
494 */
495
496 ws.ws_col = parm1;
497 ws.ws_row = parm2;
498 (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
499 }
500#endif /* TIOCSWINSZ */
501
502 break;
503
504 case TELOPT_TSPEED:
505 {
506 def_tspeed = parm1;
507 def_rspeed = parm2;
508#ifdef LINEMODE
509 /*
510 * Defer changing the terminal speed.
511 */
512 if (terminit() == 0)
513 return;
514#endif /* LINEMODE */
515 /*
516 * Change terminal speed as requested by client.
517 * We set the receive speed first, so that if we can't
518 * store seperate receive and transmit speeds, the transmit
519 * speed will take precedence.
520 */
521 tty_rspeed(parm2);
522 tty_tspeed(parm1);
523 set_termbuf();
524
525 break;
526
527 } /* end of case TELOPT_TSPEED */
528
529 default:
530 /* What? */
531 break;
532 } /* end of switch */
533
534 netflush();
535
536} /* end of clientstat */
537
538#ifdef LINEMODE
539/*
540 * defer_terminit
541 *
542 * Some things should not be done until after the login process has started
543 * and all the pty modes are set to what they are supposed to be. This
544 * function is called when the pty state has been processed for the first time.
545 * It calls other functions that do things that were deferred in each module.
546 */
547 void
548defer_terminit()
549{
550
551 /*
552 * local stuff that got deferred.
553 */
554 if (def_tspeed != -1) {
555 clientstat(TELOPT_TSPEED, def_tspeed, def_rspeed);
556 def_tspeed = def_rspeed = 0;
557 }
558
559#ifdef TIOCSWINSZ
560 if (def_col || def_row) {
561 struct winsize ws;
562
563 bzero((char *)&ws, sizeof(ws));
564 ws.ws_col = def_col;
565 ws.ws_row = def_row;
566 (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
567 }
568#endif
569
570 /*
571 * The only other module that currently defers anything.
572 */
573 deferslc();
574
575} /* end of defer_terminit */
576
577/*
578 * terminit
579 *
580 * Returns true if the pty state has been processed yet.
581 */
582 int
583terminit()
584{
585 return _terminit;
586
587} /* end of terminit */
588#endif /* LINEMODE */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/utility.c b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/utility.c
new file mode 100644
index 0000000..29b7da1
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnetd/utility.c
@@ -0,0 +1,1145 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)utility.c 5.8 (Berkeley) 3/22/91
36 */
37char util_rcsid[] =
38 "$Id: utility.c,v 1.11 1999/12/12 14:59:45 dholland Exp $";
39
40#define PRINTOPTIONS
41
42#include <stdarg.h>
43#include <sys/utsname.h>
44
45#ifdef AUTHENTICATE
46#include <libtelnet/auth.h>
47#endif
48
49#include "telnetd.h"
50
51/*
52 * utility functions performing io related tasks
53 */
54
55void
56netoprintf(const char *fmt, ...)
57{
58 int len, maxsize;
59 va_list ap;
60 int done=0;
61
62 while (!done) {
63 maxsize = sizeof(netobuf) - (nfrontp - netobuf);
64
65 va_start(ap, fmt);
66 len = vsnprintf(nfrontp, maxsize, fmt, ap);
67 va_end(ap);
68
69 if (len<0 || len==maxsize) {
70 /* didn't fit */
71 netflush();
72 }
73 else {
74 done = 1;
75 }
76 }
77 nfrontp += len;
78}
79
80/*
81 * ttloop
82 *
83 * A small subroutine to flush the network output buffer, get some data
84 * from the network, and pass it through the telnet state machine. We
85 * also flush the pty input buffer (by dropping its data) if it becomes
86 * too full.
87 */
88
89void
90ttloop(void)
91{
92
93 DIAG(TD_REPORT, netoprintf("td: ttloop\r\n"););
94
95 if (nfrontp-nbackp) {
96 netflush();
97 }
98 ncc = read(net, netibuf, sizeof(netibuf));
99 if (ncc < 0) {
100 syslog(LOG_INFO, "ttloop: read: %m\n");
101 exit(1);
102 } else if (ncc == 0) {
103 syslog(LOG_INFO, "ttloop: peer died: EOF\n");
104 exit(1);
105 }
106 DIAG(TD_REPORT, netoprintf("td: ttloop read %d chars\r\n", ncc););
107 netip = netibuf;
108 telrcv(); /* state machine */
109 if (ncc > 0) {
110 pfrontp = pbackp = ptyobuf;
111 telrcv();
112 }
113} /* end of ttloop */
114
115/*
116 * Check a descriptor to see if out of band data exists on it.
117 */
118int stilloob(int s) /* socket number */
119{
120 static struct timeval timeout = { 0, 0 };
121 fd_set excepts;
122 int value;
123
124 do {
125 FD_ZERO(&excepts);
126 FD_SET(s, &excepts);
127 value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
128 } while ((value == -1) && (errno == EINTR));
129
130 if (value < 0) {
131 fatalperror(pty, "select");
132 }
133 if (FD_ISSET(s, &excepts)) {
134 return 1;
135 } else {
136 return 0;
137 }
138}
139
140void ptyflush(void)
141{
142 int n;
143
144 if ((n = pfrontp - pbackp) > 0) {
145 DIAG((TD_REPORT | TD_PTYDATA),
146 netoprintf("td: ptyflush %d chars\r\n", n););
147 DIAG(TD_PTYDATA, printdata("pd", pbackp, n));
148 n = write(pty, pbackp, n);
149 }
150 if (n < 0) {
151 if (errno == EWOULDBLOCK || errno == EINTR)
152 return;
153 cleanup(0);
154 }
155 pbackp += n;
156 if (pbackp == pfrontp)
157 pbackp = pfrontp = ptyobuf;
158}
159
160/*
161 * nextitem()
162 *
163 * Return the address of the next "item" in the TELNET data
164 * stream. This will be the address of the next character if
165 * the current address is a user data character, or it will
166 * be the address of the character following the TELNET command
167 * if the current address is a TELNET IAC ("I Am a Command")
168 * character.
169 */
170static
171char *
172nextitem(char *current)
173{
174 if ((*current&0xff) != IAC) {
175 return current+1;
176 }
177 switch (*(current+1)&0xff) {
178 case DO:
179 case DONT:
180 case WILL:
181 case WONT:
182 return current+3;
183 case SB: /* loop forever looking for the SE */
184 {
185 register char *look = current+2;
186
187 for (;;) {
188 if ((*look++&0xff) == IAC) {
189 if ((*look++&0xff) == SE) {
190 return look;
191 }
192 }
193 }
194 }
195 default:
196 return current+2;
197 }
198} /* end of nextitem */
199
200
201/*
202 * netclear()
203 *
204 * We are about to do a TELNET SYNCH operation. Clear
205 * the path to the network.
206 *
207 * Things are a bit tricky since we may have sent the first
208 * byte or so of a previous TELNET command into the network.
209 * So, we have to scan the network buffer from the beginning
210 * until we are up to where we want to be.
211 *
212 * A side effect of what we do, just to keep things
213 * simple, is to clear the urgent data pointer. The principal
214 * caller should be setting the urgent data pointer AFTER calling
215 * us in any case.
216 */
217void netclear(void)
218{
219 register char *thisitem, *next;
220 char *good;
221#define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \
222 ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
223
224#if defined(ENCRYPT)
225 thisitem = nclearto > netobuf ? nclearto : netobuf;
226#else
227 thisitem = netobuf;
228#endif
229
230 while ((next = nextitem(thisitem)) <= nbackp) {
231 thisitem = next;
232 }
233
234 /* Now, thisitem is first before/at boundary. */
235
236#if defined(ENCRYPT)
237 good = nclearto > netobuf ? nclearto : netobuf;
238#else
239 good = netobuf; /* where the good bytes go */
240#endif
241
242 while (nfrontp > thisitem) {
243 if (wewant(thisitem)) {
244 int length;
245
246 next = thisitem;
247 do {
248 next = nextitem(next);
249 } while (wewant(next) && (nfrontp > next));
250 length = next-thisitem;
251 bcopy(thisitem, good, length);
252 good += length;
253 thisitem = next;
254 } else {
255 thisitem = nextitem(thisitem);
256 }
257 }
258
259 nbackp = netobuf;
260 nfrontp = good; /* next byte to be sent */
261 neturg = 0;
262} /* end of netclear */
263
264/*
265 * netflush
266 * Send as much data as possible to the network,
267 * handling requests for urgent data.
268 */
269extern int not42;
270void
271netflush(void)
272{
273 int n;
274
275 if ((n = nfrontp - nbackp) > 0) {
276 DIAG(TD_REPORT,
277 { netoprintf("td: netflush %d chars\r\n", n);
278 n = nfrontp - nbackp; /* update count */
279 });
280#if defined(ENCRYPT)
281 if (encrypt_output) {
282 char *s = nclearto ? nclearto : nbackp;
283 if (nfrontp - s > 0) {
284 (*encrypt_output)((unsigned char *)s, nfrontp-s);
285 nclearto = nfrontp;
286 }
287 }
288#endif
289 /*
290 * if no urgent data, or if the other side appears to be an
291 * old 4.2 client (and thus unable to survive TCP urgent data),
292 * write the entire buffer in non-OOB mode.
293 */
294 if ((neturg == 0) || (not42 == 0)) {
295 n = write(net, nbackp, n); /* normal write */
296 } else {
297 n = neturg - nbackp;
298 /*
299 * In 4.2 (and 4.3) systems, there is some question about
300 * what byte in a sendOOB operation is the "OOB" data.
301 * To make ourselves compatible, we only send ONE byte
302 * out of band, the one WE THINK should be OOB (though
303 * we really have more the TCP philosophy of urgent data
304 * rather than the Unix philosophy of OOB data).
305 */
306 if (n > 1) {
307 n = send(net, nbackp, n-1, 0); /* send URGENT all by itself */
308 } else {
309 n = send(net, nbackp, n, MSG_OOB); /* URGENT data */
310 }
311 }
312 }
313 if (n < 0) {
314 if (errno == EWOULDBLOCK || errno == EINTR)
315 return;
316 cleanup(0);
317 }
318 nbackp += n;
319#if defined(ENCRYPT)
320 if (nbackp > nclearto)
321 nclearto = 0;
322#endif
323 if (nbackp >= neturg) {
324 neturg = 0;
325 }
326 if (nbackp == nfrontp) {
327 nbackp = nfrontp = netobuf;
328#if defined(ENCRYPT)
329 nclearto = 0;
330#endif
331 }
332 return;
333} /* end of netflush */
334
335
336/*
337 * writenet
338 *
339 * Just a handy little function to write a bit of raw data to the net.
340 * It will force a transmit of the buffer if necessary
341 *
342 * arguments
343 * ptr - A pointer to a character string to write
344 * len - How many bytes to write
345 */
346void writenet(register unsigned char *ptr, register int len)
347{
348 /* flush buffer if no room for new data) */
349 if ((&netobuf[BUFSIZ] - nfrontp) < len) {
350 /* if this fails, don't worry, buffer is a little big */
351 netflush();
352 }
353
354 bcopy(ptr, nfrontp, len);
355 nfrontp += len;
356
357} /* end of writenet */
358
359
360/*
361 * miscellaneous functions doing a variety of little jobs follow ...
362 */
363
364
365void
366fatal(int f, const char *msg)
367{
368 char buf[BUFSIZ];
369
370 (void) snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg);
371#if defined(ENCRYPT)
372 if (encrypt_output) {
373 /*
374 * Better turn off encryption first....
375 * Hope it flushes...
376 */
377 encrypt_send_end();
378 netflush();
379 }
380#endif
381 (void) write(f, buf, (int)strlen(buf));
382 sleep(1); /*XXX*/
383 exit(1);
384}
385
386void
387fatalperror(int f, const char *msg)
388{
389 char buf[BUFSIZ];
390 snprintf(buf, sizeof(buf), "%s: %s\r\n", msg, strerror(errno));
391 fatal(f, buf);
392}
393
394char editedhost[32];
395struct utsname kerninfo;
396
397void
398edithost(const char *pat, const char *host)
399{
400 char *res = editedhost;
401
402 uname(&kerninfo);
403
404 if (!pat)
405 pat = "";
406 while (*pat) {
407 switch (*pat) {
408
409 case '#':
410 if (*host)
411 host++;
412 break;
413
414 case '@':
415 if (*host)
416 *res++ = *host++;
417 break;
418
419 default:
420 *res++ = *pat;
421 break;
422 }
423 if (res == &editedhost[sizeof editedhost - 1]) {
424 *res = '\0';
425 return;
426 }
427 pat++;
428 }
429 if (*host)
430 (void) strncpy(res, host,
431 sizeof editedhost - (res - editedhost) -1);
432 else
433 *res = '\0';
434 editedhost[sizeof editedhost - 1] = '\0';
435}
436
437static char *putlocation;
438
439static
440void
441putstr(const char *s)
442{
443 while (*s) putchr(*s++);
444}
445
446void putchr(int cc)
447{
448 *putlocation++ = cc;
449}
450
451static char fmtstr[] = { "%H:%M on %A, %d %B %Y" };
452
453void putf(const char *cp, char *where)
454{
455 char *slash;
456 time_t t;
457 char db[100];
458
459 if (where)
460 putlocation = where;
461
462 while (*cp) {
463 if (*cp != '%') {
464 putchr(*cp++);
465 continue;
466 }
467 switch (*++cp) {
468
469 case 't':
470 slash = strrchr(line, '/');
471 if (slash == NULL)
472 putstr(line);
473 else
474 putstr(slash+1);
475 break;
476
477 case 'h':
478 putstr(editedhost);
479 break;
480
481 case 'd':
482 (void)time(&t);
483 (void)strftime(db, sizeof(db), fmtstr, localtime(&t));
484 putstr(db);
485 break;
486
487 case '%':
488 putchr('%');
489 break;
490
491 case 'D':
492 {
493 char buff[128];
494
495 if (getdomainname(buff,sizeof(buff)) < 0
496 || buff[0] == '\0'
497 || strcmp(buff, "(none)") == 0)
498 break;
499 putstr(buff);
500 }
501 break;
502
503 case 'i':
504 {
505 char buff[3];
506 FILE *fp;
507 int p, c;
508
509 if ((fp = fopen(ISSUE_FILE, "r")) == NULL)
510 break;
511 p = '\n';
512 while ((c = fgetc(fp)) != EOF) {
513 if (p == '\n' && c == '#') {
514 do {
515 c = fgetc(fp);
516 } while (c != EOF && c != '\n');
517 continue;
518 } else if (c == '%') {
519 buff[0] = c;
520 c = fgetc(fp);
521 if (c == EOF) break;
522 buff[1] = c;
523 buff[2] = '\0';
524 putf(buff, NULL);
525 } else {
526 if (c == '\n') putchr('\r');
527 putchr(c);
528 p = c;
529 }
530 };
531 (void) fclose(fp);
532 }
533 return; /* ignore remainder of the banner string */
534 /*NOTREACHED*/
535
536 case 's':
537 putstr(kerninfo.sysname);
538 break;
539
540 case 'm':
541 putstr(kerninfo.machine);
542 break;
543
544 case 'r':
545 putstr(kerninfo.release);
546 break;
547
548 case 'v':
549#ifdef __linux__
550 putstr(kerninfo.version);
551#else
552 puts(kerninfo.version);
553#endif
554 break;
555 }
556 cp++;
557 }
558}
559
560#ifdef DIAGNOSTICS
561/*
562 * Print telnet options and commands in plain text, if possible.
563 */
564void
565printoption(const char *fmt, int option)
566{
567 if (TELOPT_OK(option))
568 netoprintf("%s %s\r\n", fmt, TELOPT(option));
569 else if (TELCMD_OK(option))
570 netoprintf("%s %s\r\n", fmt, TELCMD(option));
571 else
572 netoprintf("%s %d\r\n", fmt, option);
573}
574
575/* direction: '<' or '>' */
576/* pointer: where suboption data sits */
577/* length: length of suboption data */
578void
579printsub(char direction, unsigned char *pointer, int length)
580{
581 register int i = -1;
582#ifdef AUTHENTICATE
583 char buf[512];
584#endif
585
586 if (!(diagnostic & TD_OPTIONS))
587 return;
588
589 if (direction) {
590 netoprintf("td: %s suboption ",
591 direction == '<' ? "recv" : "send");
592 if (length >= 3) {
593 register int j;
594
595 i = pointer[length-2];
596 j = pointer[length-1];
597
598 if (i != IAC || j != SE) {
599 netoprintf("(terminated by ");
600 if (TELOPT_OK(i))
601 netoprintf("%s ", TELOPT(i));
602 else if (TELCMD_OK(i))
603 netoprintf("%s ", TELCMD(i));
604 else
605 netoprintf("%d ", i);
606 if (TELOPT_OK(j))
607 netoprintf("%s", TELOPT(j));
608 else if (TELCMD_OK(j))
609 netoprintf("%s", TELCMD(j));
610 else
611 netoprintf("%d", j);
612 netoprintf(", not IAC SE!) ");
613 }
614 }
615 length -= 2;
616 }
617 if (length < 1) {
618 netoprintf("(Empty suboption???)");
619 return;
620 }
621 switch (pointer[0]) {
622 case TELOPT_TTYPE:
623 netoprintf("TERMINAL-TYPE ");
624 switch (pointer[1]) {
625 case TELQUAL_IS:
626 netoprintf("IS \"%.*s\"", length-2, (char *)pointer+2);
627 break;
628 case TELQUAL_SEND:
629 netoprintf("SEND");
630 break;
631 default:
632 netoprintf("- unknown qualifier %d (0x%x).",
633 pointer[1], pointer[1]);
634 }
635 break;
636 case TELOPT_TSPEED:
637 netoprintf("TERMINAL-SPEED");
638 if (length < 2) {
639 netoprintf(" (empty suboption???)");
640 break;
641 }
642 switch (pointer[1]) {
643 case TELQUAL_IS:
644 netoprintf(" IS %.*s", length-2, (char *)pointer+2);
645 break;
646 default:
647 if (pointer[1] == 1)
648 netoprintf(" SEND");
649 else
650 netoprintf(" %d (unknown)", pointer[1]);
651 for (i = 2; i < length; i++) {
652 netoprintf(" ?%d?", pointer[i]);
653 }
654 break;
655 }
656 break;
657
658 case TELOPT_LFLOW:
659 netoprintf("TOGGLE-FLOW-CONTROL");
660 if (length < 2) {
661 netoprintf(" (empty suboption???)");
662 break;
663 }
664 switch (pointer[1]) {
665 case 0:
666 netoprintf(" OFF"); break;
667 case 1:
668 netoprintf(" ON"); break;
669 default:
670 netoprintf(" %d (unknown)", pointer[1]);
671 }
672 for (i = 2; i < length; i++) {
673 netoprintf(" ?%d?", pointer[i]);
674 }
675 break;
676
677 case TELOPT_NAWS:
678 netoprintf("NAWS");
679 if (length < 2) {
680 netoprintf(" (empty suboption???)");
681 break;
682 }
683 if (length == 2) {
684 netoprintf(" ?%d?", pointer[1]);
685 break;
686 }
687 netoprintf(" %d %d (%d)",
688 pointer[1], pointer[2],
689 (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
690 if (length == 4) {
691 netoprintf(" ?%d?", pointer[3]);
692 break;
693 }
694 netoprintf(" %d %d (%d)",
695 pointer[3], pointer[4],
696 (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
697 for (i = 5; i < length; i++) {
698 netoprintf(" ?%d?", pointer[i]);
699 }
700 break;
701
702 case TELOPT_LINEMODE:
703 netoprintf("LINEMODE ");
704 if (length < 2) {
705 netoprintf(" (empty suboption???)");
706 break;
707 }
708 switch (pointer[1]) {
709 case WILL:
710 netoprintf("WILL ");
711 goto common;
712 case WONT:
713 netoprintf("WONT ");
714 goto common;
715 case DO:
716 netoprintf("DO ");
717 goto common;
718 case DONT:
719 netoprintf("DONT ");
720 common:
721 if (length < 3) {
722 netoprintf("(no option???)");
723 break;
724 }
725 switch (pointer[2]) {
726 case LM_FORWARDMASK:
727 netoprintf("Forward Mask");
728 for (i = 3; i < length; i++) {
729 netoprintf(" %x", pointer[i]);
730 }
731 break;
732 default:
733 netoprintf("%d (unknown)", pointer[2]);
734 for (i = 3; i < length; i++) {
735 netoprintf(" %d", pointer[i]);
736 }
737 break;
738 }
739 break;
740
741 case LM_SLC:
742 netoprintf("SLC");
743 for (i = 2; i < length - 2; i += 3) {
744 if (SLC_NAME_OK(pointer[i+SLC_FUNC]))
745 netoprintf(" %s", SLC_NAME(pointer[i+SLC_FUNC]));
746 else
747 netoprintf(" %d", pointer[i+SLC_FUNC]);
748 switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {
749 case SLC_NOSUPPORT:
750 netoprintf(" NOSUPPORT"); break;
751 case SLC_CANTCHANGE:
752 netoprintf(" CANTCHANGE"); break;
753 case SLC_VARIABLE:
754 netoprintf(" VARIABLE"); break;
755 case SLC_DEFAULT:
756 netoprintf(" DEFAULT"); break;
757 }
758 netoprintf("%s%s%s",
759 pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",
760 pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",
761 pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");
762 if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|
763 SLC_FLUSHOUT| SLC_LEVELBITS)) {
764 netoprintf("(0x%x)", pointer[i+SLC_FLAGS]);
765 }
766 netoprintf(" %d;", pointer[i+SLC_VALUE]);
767 if ((pointer[i+SLC_VALUE] == IAC) &&
768 (pointer[i+SLC_VALUE+1] == IAC))
769 i++;
770 }
771 for (; i < length; i++) {
772 netoprintf(" ?%d?", pointer[i]);
773 }
774 break;
775
776 case LM_MODE:
777 netoprintf("MODE ");
778 if (length < 3) {
779 netoprintf("(no mode???)");
780 break;
781 }
782 {
783 char tbuf[32];
784 snprintf(tbuf, sizeof(tbuf), "%s%s%s%s%s",
785 pointer[2]&MODE_EDIT ? "|EDIT" : "",
786 pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
787 pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
788 pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
789 pointer[2]&MODE_ACK ? "|ACK" : "");
790 netoprintf("%s", tbuf[1] ? &tbuf[1] : "0");
791 }
792 if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) {
793 netoprintf(" (0x%x)", pointer[2]);
794 }
795 for (i = 3; i < length; i++) {
796 netoprintf(" ?0x%x?", pointer[i]);
797 }
798 break;
799 default:
800 netoprintf("%d (unknown)", pointer[1]);
801 for (i = 2; i < length; i++) {
802 netoprintf(" %d", pointer[i]);
803 }
804 }
805 break;
806
807 case TELOPT_STATUS: {
808 const char *cp;
809 register int j, k;
810
811 netoprintf("STATUS");
812
813 switch (pointer[1]) {
814 default:
815 if (pointer[1] == TELQUAL_SEND)
816 netoprintf(" SEND");
817 else
818 netoprintf(" %d (unknown)", pointer[1]);
819 for (i = 2; i < length; i++) {
820 netoprintf(" ?%d?", pointer[i]);
821 }
822 break;
823 case TELQUAL_IS:
824 netoprintf(" IS\r\n");
825
826 for (i = 2; i < length; i++) {
827 switch(pointer[i]) {
828 case DO: cp = "DO"; goto common2;
829 case DONT: cp = "DONT"; goto common2;
830 case WILL: cp = "WILL"; goto common2;
831 case WONT: cp = "WONT"; goto common2;
832 common2:
833 i++;
834 if (TELOPT_OK((int)pointer[i]))
835 netoprintf(" %s %s", cp, TELOPT(pointer[i]));
836 else
837 netoprintf(" %s %d", cp, pointer[i]);
838
839 netoprintf("\r\n");
840 break;
841
842 case SB:
843 netoprintf(" SB ");
844 i++;
845 j = k = i;
846 while (j < length) {
847 if (pointer[j] == SE) {
848 if (j+1 == length)
849 break;
850 if (pointer[j+1] == SE)
851 j++;
852 else
853 break;
854 }
855 pointer[k++] = pointer[j++];
856 }
857 printsub(0, &pointer[i], k - i);
858 if (i < length) {
859 netoprintf(" SE");
860 i = j;
861 } else
862 i = j - 1;
863
864 netoprintf("\r\n");
865
866 break;
867
868 default:
869 netoprintf(" %d", pointer[i]);
870 break;
871 }
872 }
873 break;
874 }
875 break;
876 }
877
878 case TELOPT_XDISPLOC:
879 netoprintf("X-DISPLAY-LOCATION ");
880 switch (pointer[1]) {
881 case TELQUAL_IS:
882 netoprintf("IS \"%.*s\"", length-2, (char *)pointer+2);
883 break;
884 case TELQUAL_SEND:
885 netoprintf("SEND");
886 break;
887 default:
888 netoprintf("- unknown qualifier %d (0x%x).",
889 pointer[1], pointer[1]);
890 }
891 break;
892
893 case TELOPT_ENVIRON:
894 netoprintf("ENVIRON ");
895 switch (pointer[1]) {
896 case TELQUAL_IS:
897 netoprintf("IS ");
898 goto env_common;
899 case TELQUAL_SEND:
900 netoprintf("SEND ");
901 goto env_common;
902 case TELQUAL_INFO:
903 netoprintf("INFO ");
904 env_common:
905 {
906 register int noquote = 2;
907 for (i = 2; i < length; i++ ) {
908 switch (pointer[i]) {
909 case ENV_VAR:
910 if (pointer[1] == TELQUAL_SEND)
911 goto def_case;
912 netoprintf("\" VAR " + noquote);
913 noquote = 2;
914 break;
915
916 case ENV_VALUE:
917 netoprintf("\" VALUE " + noquote);
918 noquote = 2;
919 break;
920
921 case ENV_ESC:
922 netoprintf("\" ESC " + noquote);
923 noquote = 2;
924 break;
925
926 default:
927 def_case:
928 if (isprint(pointer[i]) && pointer[i] != '"') {
929 if (noquote) {
930 netoprintf("\"");
931 noquote = 0;
932 }
933 netoprintf("%c", pointer[i]);
934 } else {
935 netoprintf("\" %03o " + noquote,
936 pointer[i]);
937 noquote = 2;
938 }
939 break;
940 }
941 }
942 if (!noquote)
943 netoprintf("\"");
944 break;
945 }
946 }
947 break;
948
949#if defined(AUTHENTICATE)
950 case TELOPT_AUTHENTICATION:
951 netoprintf("AUTHENTICATION");
952
953 if (length < 2) {
954 netoprintf(" (empty suboption???)");
955 break;
956 }
957 switch (pointer[1]) {
958 case TELQUAL_REPLY:
959 case TELQUAL_IS:
960 netoprintf(" %s ", (pointer[1] == TELQUAL_IS) ?
961 "IS" : "REPLY");
962 if (AUTHTYPE_NAME_OK(pointer[2]))
963 netoprintf("%s ", AUTHTYPE_NAME(pointer[2]));
964 else
965 netoprintf("%d ", pointer[2]);
966 if (length < 3) {
967 netoprintf("(partial suboption???)");
968 break;
969 }
970 netoprintf("%s|%s",
971 ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
972 "CLIENT" : "SERVER",
973 ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
974 "MUTUAL" : "ONE-WAY");
975
976 auth_printsub(&pointer[1], length - 1, buf, sizeof(buf));
977 netoprintf("%s", buf);
978 break;
979
980 case TELQUAL_SEND:
981 i = 2;
982 netoprintf(" SEND ");
983 while (i < length) {
984 if (AUTHTYPE_NAME_OK(pointer[i]))
985 netoprintf("%s ", AUTHTYPE_NAME(pointer[i]));
986 else
987 netoprintf("%d ", pointer[i]);
988 if (++i >= length) {
989 netoprintf("(partial suboption???)");
990 break;
991 }
992 netoprintf("%s|%s ",
993 ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
994 "CLIENT" : "SERVER",
995 ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
996 "MUTUAL" : "ONE-WAY");
997 ++i;
998 }
999 break;
1000
1001 case TELQUAL_NAME:
1002 i = 2;
1003 netoprintf(" NAME \"");
1004 /*
1005 * Was:
1006 * while (i < length)
1007 * *nfrontp += pointer[i++];
1008 * *nfrontp += '"';
1009 *
1010 * but I'm pretty sure that's wrong...
1011 */
1012 while (i < length)
1013 netoprintf("%c", pointer[i++]);
1014 netoprintf("\"");
1015 break;
1016
1017 default:
1018 for (i = 2; i < length; i++) {
1019 netoprintf(" ?%d?", pointer[i]);
1020 }
1021 break;
1022 }
1023 break;
1024#endif
1025
1026#if defined(ENCRYPT)
1027 case TELOPT_ENCRYPT:
1028 netoprintf("ENCRYPT");
1029 if (length < 2) {
1030 netoprintf(" (empty suboption???)");
1031 break;
1032 }
1033 switch (pointer[1]) {
1034 case ENCRYPT_START:
1035 netoprintf(" START");
1036 break;
1037
1038 case ENCRYPT_END:
1039 netoprintf(" END");
1040 break;
1041
1042 case ENCRYPT_REQSTART:
1043 netoprintf(" REQUEST-START");
1044 break;
1045
1046 case ENCRYPT_REQEND:
1047 netoprintf(" REQUEST-END");
1048 break;
1049
1050 case ENCRYPT_IS:
1051 case ENCRYPT_REPLY:
1052 netoprintf(" %s ", (pointer[1] == ENCRYPT_IS) ?
1053 "IS" : "REPLY");
1054 if (length < 3) {
1055 netoprintf(" (partial suboption???)");
1056 break;
1057 }
1058 if (ENCTYPE_NAME_OK(pointer[2]))
1059 netoprintf("%s ", ENCTYPE_NAME(pointer[2]));
1060 else
1061 netoprintf(" %d (unknown)", pointer[2]);
1062
1063 encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf));
1064 netoprintf("%s", buf);
1065 break;
1066
1067 case ENCRYPT_SUPPORT:
1068 i = 2;
1069 netoprintf(" SUPPORT ");
1070 while (i < length) {
1071 if (ENCTYPE_NAME_OK(pointer[i]))
1072 netoprintf("%s ", ENCTYPE_NAME(pointer[i]));
1073 else
1074 netoprintf("%d ", pointer[i]);
1075 i++;
1076 }
1077 break;
1078
1079 case ENCRYPT_ENC_KEYID:
1080 netoprintf(" ENC_KEYID", pointer[1]);
1081 goto encommon;
1082
1083 case ENCRYPT_DEC_KEYID:
1084 netoprintf(" DEC_KEYID", pointer[1]);
1085 goto encommon;
1086
1087 default:
1088 netoprintf(" %d (unknown)", pointer[1]);
1089 encommon:
1090 for (i = 2; i < length; i++) {
1091 netoprintf(" %d", pointer[i]);
1092 }
1093 break;
1094 }
1095 break;
1096#endif
1097
1098 default:
1099 if (TELOPT_OK(pointer[0]))
1100 netoprintf("%s (unknown)", TELOPT(pointer[0]));
1101 else
1102 netoprintf("%d (unknown)", pointer[i]);
1103 for (i = 1; i < length; i++) {
1104 netoprintf(" %d", pointer[i]);
1105 }
1106 break;
1107 }
1108 netoprintf("\r\n");
1109}
1110
1111/*
1112 * Dump a data buffer in hex and ascii to the output data stream.
1113 */
1114void
1115printdata(const char *tag, const char *ptr, int cnt)
1116{
1117 register int i;
1118 char xbuf[30];
1119
1120 while (cnt) {
1121 /* flush net output buffer if no room for new data) */
1122 if ((&netobuf[BUFSIZ] - nfrontp) < 80) {
1123 netflush();
1124 }
1125
1126 /* add a line of output */
1127 netoprintf("%s: ", tag);
1128 for (i = 0; i < 20 && cnt; i++) {
1129 netoprintf("%02x", *ptr);
1130 if (isprint(*ptr)) {
1131 xbuf[i] = *ptr;
1132 } else {
1133 xbuf[i] = '.';
1134 }
1135 if (i % 2) {
1136 netoprintf(" ");
1137 }
1138 cnt--;
1139 ptr++;
1140 }
1141 xbuf[i] = '\0';
1142 netoprintf(" %s\r\n", xbuf );
1143 }
1144}
1145#endif /* DIAGNOSTICS */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/version.h b/exploits/7350855-netkit/netkit-telnet-0.16/version.h
new file mode 100644
index 0000000..3cfe28f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/version.h
@@ -0,0 +1,5 @@
1/*
2 * String to embed in binaries to identify package
3 */
4
5char pkg[]="$NetKit: netkit-telnet-0.16 $";
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/BUGS b/exploits/7350855-netkit/netkit-telnet-0.17/BUGS
new file mode 100644
index 0000000..484d00d
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/BUGS
@@ -0,0 +1,24 @@
1telnet:
2 - will apparently sometimes assert in ungetch. I think I've
3 fixed this, so if you still see it let me know.
4 - hangs if you telnet to chargen port and push ^Z
5 (due to bogus protocol negotiation attempts)
6 - binary mode doesn't handle crlf right
7 - should warn if the connection isn't encrypted
8
9telnetd:
10 - hangs if you do the following:
11 telnet
12 log in
13 cat >/dev/null
14 type 256 'a's with no CRs
15 *THIS IS A KERNEL BUG* Patch enclosed.
16
17 - crashes in ncurses if the terminal type is undefined,
18 with some versions of ncurses.
19 - should allow passing random user envs as "TELNET_*"
20 - should set REMOTEHOST to the remote hostname
21 - passes login the -p flag instead of sending envs explicitly
22 - should only use included logout() et al. if real ones aren't
23 available in system libs.
24 - addarg() in sys_term.c does some very questionable casts.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/ChangeLog b/exploits/7350855-netkit/netkit-telnet-0.17/ChangeLog
new file mode 100644
index 0000000..7ef5e3e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/ChangeLog
@@ -0,0 +1,170 @@
122-Jul-2000:
2 Bug fixes for environment processing from Olaf Kirch. Also fixes
3 privacy issue noticed by Steve Bellovin. Also fix a wrong
4 assert().
5
621-May-2000:
7 Fix bug found by Herbert Xu (herbert@gondor.apana.org.au) - telnet
8 was sending terminal type "(null)" as part of the terminal type
9 list.
10
1112-Apr-2000:
12 IPPROTO_IP is not a macro in Linux, so don't check it with #ifdef.
13 Also, add initial experimental login wrapper, but don't make it
14 part of the default build.
15
1614-Dec-1999:
17 netkit-telnet-0.16 is released.
18
1913-Dec-1999:
20 Per recommendation of the linux-security-audit list, don't bother
21 (in telnetd) to ask termcap/ncurses if a terminal type is good;
22 assume it is. This means telnetd no longer links against termcap.
23
2412-Dec-1999:
25 Massive buffer cleanup in telnetd; minor cleanup to telnet.
26
275-Dec-1999:
28 Remove some more bogus #ifdefs in telnet.
29
3029-Oct-1999:
31 Fix latent bug in the array classes used in telnet.
32
3314-Sep-1999:
34 Merge old fix to keep telnet from hanging up when under heavy load
35 (Olaf Kirch, okir@caldera.de)
36
3719-Aug-1999:
38 Patches for compiling with gcc 2.95. (Jeremy Buhler,
39 jbuhler@cs.washington.edu)
40
4118-Aug-1999:
42 netkit-telnet-0.14 released.
43
4417-Aug-1999:
45 telnetd patch from Chris Evans to reject termcap entries with
46 '/' in them, as libtermcap will treat them as paths and open
47 them as root, with various interesting consequences...
48 Issue found by Tymm Twillman (tymm@coe.missouri.edu).
49
501-Aug-1999:
51 Massive cleanup of telnetd. Changed telnetd to use openpty() from
52 libutil, so we can let libc deal with changes in pty management.
53
541-Aug-1999:
55 Did complete y2k and y2038 audit.
56
5731-Jul-1999:
58 Redid makefiles/config stuff for new confgen version.
59
6015-Jul-1999:
61 Set the process title (visible with ps) to show the remote host name.
62 Also filter control characters from the remote host name, just in case.
63 Set environment variable REMOTEHOST also.
64
6516-Oct-1997:
66 Added OPOST to the terminal stuff a la NCSA telnet fixup
67
6823-Sep-1997:
69 Assorted signed/unsigned character fixes and hacking in telnet.
70 (Martin Mares, mj@mj.gts.cz)
71 Fix various crashes in telnet arising from undefining environment
72 variables.
73 "telnet h" no longer prints a usage message.
74
7512-Jun-1997:
76 netkit-telnet-0.10 released.
77
7808-Jun-1997:
79 More adjustments for glibc.
80 Include kernel patch to fix hang on long input; thanks to Bill
81 Hawes (whawes@star.net).
82
8319-May-1997:
84 Fix some nonsense with ayt and signals, since glibc has SIGINFO.
85
8613-May-1997:
87 8-bit fix to telnet. (Lukas Wunner, lukas@design.de)
88 Set ut_type correctly in telnetd's logout. (Steve Coile,
89 steve@patriot.net)
90
9105-Apr-1997:
92 Added configure script to generate MCONFIG.
93 Better utmp handling in telnetd.
94
9508-Mar-1997:
96 Split from full NetKit package.
97 Generated this change log from NetKit's.
98
9929-Dec-1996
100 NetKit-0.09 released.
101 Assorted alpha/glibc patches. (Erik Troan, ewt@redhat.com)
102 Assorted bug fixes from Debian. (Peter Tobias,
103 tobias@et-inf.fho-emden.de)
104 Telnetd supports -L option for alternate login program. (Peter Tobias)
105 Hardened programs against DNS h_length spoofing attacks.
106 Use inet_aton() everywhere instead of inet_addr().
107 Fixed crash in telnet caused by ^C or ^Z or ^\ under
108 certain circumstances.
109 Rewrote telnet and telnetd man pages.
110
11122-Aug-1996
112 NetKit-B-0.08 released.
113 (almost) everything now compiles with lots of warnings turned on.
114 Massive hacking on telnet.
115 telnet honors the -E flag (was broken in .07, .07A)
116 telnetd intercepts ENV environment variable.
117 Merged libtelnet into telnet and telnetd dirs.
118 telnetd now sets idle tty devices to root.root mode 600.
119
12025-Jul-1996
121 NetKit-B-0.07A released.
122 Fixed a bug in telnet where the escape character was being ignored.
123 Fixed a bug in telnetd; now uses the correct names for the last ptys
124 (that is, ptya0-ptyef, not ptyA0-ptyEf.)
125
12623-Jul-1996
127 NetKit-B-0.07 released.
128 Integrated a collection of patches that had been lurking on the net,
129 including the 256-ptys support for telnetd and passive mode ftp.
130 Major security fixes, including to fingerd, lpr, rlogin, rsh, talkd,
131 and telnetd. Do *not* use the sliplogin from earlier versions of this
132 package, either.
133 Much of the code builds without libbsd.a or bsd includes.
134 Massive code cleanup. Almost everything compiles clean with gcc
135 -Wall now. rusers and rusersd do not; patches to rpcgen to fix
136 this would be appreciated if anyone feels like it.
137 Kerberos support has been removed. It didn't work anyway, and
138 proper Kerberos tools come with Kerberos.
139 New maintainer: David A. Holland, dholland@hcs.harvard.edu
140
141date not known
142 NetKit-B-0.06 released.
143
144date not known
145 NetKit-B-0.05 released.
146 Fixed writing entries to /var/adm/wtmp by ftpd, rlogind and
147 telnetd. (logwtmp.c) Florian
148 This is only necessary for the GNU last, not for the one
149 in util-linux...
150
151date not known
152 NetKit-B-0.04 released.
153 Did some nasty changes to telnet/extern.h. I should really take
154 the current version from NetBSD again and make a clean port of
155 it. (signals).
156
157date not known
158 NetKit-B-0.03 released.
159 telnetd: changed the default 'etc/issue.net' to not output the
160 hostname and then the domainname (that should be the fqdn, but
161 is wrong!) Changed also the man page issue.net.5
162 changed telnetd to get the fqdn and not only use what
163 'gethostname' returns
164 telnetd: changed some code back to original form to properly
165 enable binary mode negotiation (outgoing data wasn't binary)
166 Please test this out: do "telnet some_other_not_linux_host" and
167 then do "vi TEST_FILE" and test some strange characters >127
168 like ° or §.
169 telnetd: added issue.net.5 to "make install"
170
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/MCONFIG.in b/exploits/7350855-netkit/netkit-telnet-0.17/MCONFIG.in
new file mode 100644
index 0000000..cedb9d1
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/MCONFIG.in
@@ -0,0 +1,30 @@
1# Dirs
2INSTALLROOT
3BINDIR
4MANDIR
5SBINDIR
6
7# Modes
8BINMODE
9DAEMONMODE
10MANMODE
11
12# Compiling
13ALLWARNINGS
14CC
15CXX
16CFLAGS
17CXXFLAGS
18LDFLAGS
19LIBS
20
21# Features
22FN(snprintf)
23FN(logwtmp)
24LIBTERMCAP
25GLIBC
26BSDSIGNAL
27
28# We actually use openpty, but they come from the same place on all systems
29# I know.
30FN(forkpty)
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/MRULES b/exploits/7350855-netkit/netkit-telnet-0.17/MRULES
new file mode 100644
index 0000000..6d8015e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/MRULES
@@ -0,0 +1,8 @@
1# Standard compilation rules (don't use make builtins)
2
3%.o: %.c
4 $(CC) $(CFLAGS) $< -c
5
6%.o: %.cc
7 $(CXX) $(CXXFLAGS) $< -c
8
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/Makefile b/exploits/7350855-netkit/netkit-telnet-0.17/Makefile
new file mode 100644
index 0000000..06c8e1e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/Makefile
@@ -0,0 +1,20 @@
1# You can do "make SUB=blah" to make only a few, or edit here, or both
2# You can also run make directly in the subdirs you want.
3
4SUB = telnet telnetd telnetlogin
5
6%.build:
7 (cd $(patsubst %.build, %, $@) && $(MAKE))
8
9%.install:
10 (cd $(patsubst %.install, %, $@) && $(MAKE) install)
11
12%.clean:
13 (cd $(patsubst %.clean, %, $@) && $(MAKE) clean)
14
15all: $(patsubst %, %.build, $(SUB))
16install: $(patsubst %, %.install, $(SUB))
17clean: $(patsubst %, %.clean, $(SUB))
18
19distclean: clean
20 rm -f MCONFIG
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/README b/exploits/7350855-netkit/netkit-telnet-0.17/README
new file mode 100644
index 0000000..87f56d2
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/README
@@ -0,0 +1,127 @@
1This is netkit-telnet-0.17 for Linux.
2
3This package updates netkit-telnet-0.16.
4
5If you're reading this off a CD, go right away and check the net
6archives for later versions and security fixes. As of this writing the
7home site for NetKit is
8 ftp://ftp.uk.linux.org/pub/linux/Networking/netkit
9
10Contents:
11 telnet Client for telnet protocol
12 telnetd Daemon for telnet protocol
13
14Note: These programs do not provide encryption or strong
15authentication of network connections. As such, their use for remote
16logins is discouraged. The "ssh" protocol and package can be used
17instead.
18
19Requires:
20 Working compiler, libc, and kernel, and a recent version of
21 ncurses or libtermcap.
22
23 Note that while telnet uses the C++ compiler, it neither requires
24 nor uses libstdc++.
25
26Security:
27 This release contains no security fixes relative to
28 netkit-telnet-0.16. However, versions prior to that should not be
29 used.
30
31 Telnetd is evil legacy code and is not trustworthy - do not
32 run it unless you absolutely need it.
33
34 This release contains experimental login wrapper code to permit
35 running telnetd as a non-root user. This code is not built by
36 default. Look in the "telnetlogin" directory and the telnetlogin
37 man page contained therein for more information.
38
39Old kernels:
40 If you have an old kernel, you may need to apply the enclosed
41 pty-hang patch to it. I don't unfortunately know at the moment
42 which kernel versions need the patch, but current 2.0.x and
43 2.2.x should be ok without it.
44
45 The following test will tell you if you need the patch: telnet
46 to localhost, do "cat >/dev/null", and type 256 characters
47 without any newlines. If you need the patch, telnetd will hang
48 completely at this point. If it refuses to accept more input,
49 but does not hang, you do not need the patch.
50
51Installation:
52 Do "./configure --help" and decide what options you want. The
53 defaults should be suitable for most Linux systems. Then run
54 the configure script.
55
56 Do "make" to compile.
57 Then (as root) do "make install".
58
59 Save a backup copy of any mission-critical program in case the
60 new one doesn't work, and so forth. We warned you.
61
62 If you get gcc warnings from files in /usr/include, they are
63 due to problems in your libc, not netkit. (You may only see
64 them when compiling netkit because netkit turns on a lot of
65 compiler warnings.)
66
67DEC CC:
68 The DEC compiler for the Alpha is now freely available. This
69 is a much better compiler with gcc, that is, it generates much
70 better code. If you have the DEC compiler, you can explicitly
71 use the DEC compiler instead of gcc by configuring like this:
72
73 ./configure --with-c-compiler=ccc
74
75 It is known to generate spurious warnings on some files. Also,
76 some headers from some versions of glibc confuse it; that may
77 prevent netkit from working. Other problems should be reported
78 as bugs.
79
80 Note that there is no corresponding C++ compiler, so telnet
81 will be compiled with g++ anyway.
82
83Bugs:
84 Please make sure the header files in /usr/include match the
85 libc version installed in /lib and /usr/lib. If you have weird
86 problems this is the most likely culprit.
87
88 Also, before reporting a bug, be sure you're working with the
89 latest version.
90
91 If something doesn't compile for you, fix it and send diffs.
92 If you can't, send the compiler's error output.
93
94 If it compiles but doesn't work, send as complete a bug report as
95 you can. Patches and fixes are welcome, as long as you describe
96 adequately what they're supposed to fix. Please, one patch per
97 distinct fix. Please do NOT send the whole archive back or
98 reindent the source.
99
100 Be sure to send all correspondence in e-mail to the netkit address.
101 Postings to netnews or mailing lists will not be seen due to the
102 enormous volume. Also, anything that doesn't get filed in the bug
103 database is quite likely to end up forgotten.
104
105 Please don't report known bugs (see the BUGS file(s)) unless you
106 are including fixes. :-)
107
108 Mail should be sent to: netbug@ftp.uk.linux.org
109
110
111Early in April 2000, a hacker broke into the machine that was hosting
112the netkit bug database for me and trashed it. Unfortunately, it seems
113backups hadn't gotten done for a while, so three months of mail (since
114mid-January) was lost. So, if you sent something and didn't hear back,
115or you sent something, heard back, but the changes failed to appear in
116this release (unlikely but possible) - please resend.
117
118Please see http://www.hcs.harvard.edu/~dholland/computers/netkit.html
119if you are curious why it was so long between the 0.10 and 0.16 releases.
120
121Future plans for netkit maintenance are still up in the air, but in the
122meantime new releases will still appear from time to time. I don't have
123a whole lot of cycles to spare to work on netkit, so things are likely
124to continue to be fairly slow.
125
126David A. Holland
12723 July 2000
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/configure b/exploits/7350855-netkit/netkit-telnet-0.17/configure
new file mode 100644
index 0000000..eb04933
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/configure
@@ -0,0 +1,572 @@
1#!/bin/sh
2#
3# This file was generated by confgen version 2.
4# Do not edit.
5#
6
7PREFIX='/usr'
8#EXECPREFIX='$PREFIX'
9INSTALLROOT=''
10BINMODE='755'
11#DAEMONMODE='$BINMODE'
12MANMODE='644'
13
14while [ x$1 != x ]; do case $1 in
15
16 --help)
17 cat <<EOF
18Usage: configure [options]
19 --help Show this message
20 --with-debug Enable debugging
21 --prefix=path Prefix for location of files [/usr]
22 --exec-prefix=path Location for arch-depedent files [prefix]
23 --installroot=root Top of filesystem tree to install in [/]
24 --binmode=mode Mode for binaries [755]
25 --daemonmode=mode Mode for daemon binaries [same as binmode]
26 --manmode=mode Mode for manual pages [644]
27 --with-c-compiler=cc Program for compiling C source [guessed]
28 --with-c++-compiler=cc Program for compiling C++ source [guessed]
29EOF
30 exit 0;;
31 --verbose) ;;
32 --quiet) ;;
33
34 --subdir) . ../configure.defs;;
35
36 --with-debug|--debug) DEBUG=1;;
37 --prefix=*) PREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;
38 --exec-prefix=*) EXECPREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;
39 --installroot=*) INSTALLROOT=`echo $1 | sed 's/^[^=]*=//'` ;;
40 --binmode=*) BINMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
41 --daemonmode=*) DAEMONMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
42 --manmode=*) MANMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
43 --with-c-compiler=*) CC=`echo $1 | sed 's/^[^=]*=//'` ;;
44 --with-c++-compiler=*) CXX=`echo $1 | sed 's/^[^=]*=//'` ;;
45 *) echo "Unrecognized option: $1"; exit 1;;
46esac
47shift
48done
49
50if [ x$EXECPREFIX = x ]; then
51 EXECPREFIX="$PREFIX"
52fi
53
54if [ x$DAEMONMODE = x ]; then
55 DAEMONMODE="$BINMODE"
56fi
57
58BINDIR="$EXECPREFIX/bin"
59SBINDIR="$EXECPREFIX/sbin"
60MANDIR="$PREFIX/man"
61
62echo "Directories: $BINDIR $SBINDIR $MANDIR "
63
64if [ x$INSTALLROOT != x ]; then
65 echo "Installing in chroot tree rooted at $INSTALLROOT"
66fi
67
68##################################################
69
70WARNINGS='-Wall -W -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline '
71
72cat << EOF > __conftest.c
73 int main() { int class=0; return class; }
74EOF
75
76if [ x"$CC" = x ]; then
77 echo -n 'Looking for a C compiler... '
78 for TRY in egcs gcc g++ CC c++ cc; do
79 (
80 $TRY __conftest.c -o __conftest || exit 1;
81 ./__conftest || exit 1;
82 ) >/dev/null 2>&1 || continue;
83 CC=$TRY
84 break;
85 done
86 if [ x"$CC" = x ]; then
87 echo 'failed.'
88 echo 'Cannot find a C compiler. Run configure with --with-c-compiler.'
89 rm -f __conftest*
90 exit
91 fi
92 echo "$CC"
93else
94 echo -n 'Checking if C compiler works... '
95 if (
96 $CC __conftest.c -o __conftest || exit 1
97 ./__conftest || exit 1
98 ) >/dev/null 2>&1; then
99 echo 'yes'
100 else
101 echo 'no'
102 echo 'Compiler '"$CC"' does not exist or cannot compile C; try another.'
103 rm -f __conftest*
104 exit
105 fi
106fi
107
108echo -n "Checking if $CC accepts gcc warnings... "
109if (
110 $CC $WARNINGS __conftest.c -o __conftest || exit 1
111 ) >/dev/null 2>&1; then
112 echo 'yes'
113 CC_WARNINGS=1
114else
115 echo 'no'
116fi
117
118cat << EOF > __conftest.cc
119 template <class T> class fnord { public: T x; fnord(T y) { x=y; }};
120 int main() { fnord<int> *a = new fnord<int>(0); return a->x; }
121EOF
122
123if [ x"$CXX" = x ]; then
124 echo -n 'Looking for a C++ compiler... '
125 for TRY in egcs gcc g++ CC c++ cc; do
126 (
127 $TRY __conftest.cc -o __conftest || exit 1;
128 ./__conftest || exit 1;
129 ) >/dev/null 2>&1 || continue;
130 CXX=$TRY
131 break;
132 done
133 if [ x"$CXX" = x ]; then
134 echo 'failed.'
135 echo 'Cannot find a C++ compiler. Run configure with --with-cpp-compiler.'
136 rm -f __conftest*
137 exit
138 fi
139 echo "$CXX"
140else
141 echo -n 'Checking if C++ compiler works... '
142 if (
143 $CXX __conftest.cc -o __conftest || exit 1
144 ./__conftest || exit 1
145 ) >/dev/null 2>&1; then
146 echo 'yes'
147 else
148 echo 'no'
149 echo 'Compiler '"$CXX"' does not exist or cannot compile C++; try another.'
150 rm -f __conftest*
151 exit
152 fi
153fi
154
155echo -n "Checking if $CXX accepts gcc warnings... "
156if (
157 $CXX $WARNINGS __conftest.cc -o __conftest || exit 1
158 ) >/dev/null 2>&1; then
159 echo 'yes'
160 CXX_WARNINGS=1
161else
162 echo 'no'
163fi
164
165if [ x$DEBUG = x ]; then
166 echo -n "Checking if $CC accepts -O2... "
167 if (
168 $CC -O2 __conftest.c -o __conftest
169 ) >/dev/null 2>&1; then
170 echo 'yes'
171 CFLAGS="$CFLAGS -O2"
172 else
173 echo 'no'
174 echo -n "Checking if $CC accepts -O... "
175 if (
176 $CC -O __conftest.c -o __conftest
177 ) >/dev/null 2>&1; then
178 echo 'yes'
179 CFLAGS="$CFLAGS -O"
180 else
181 echo 'no'
182 fi
183 fi
184
185else
186 echo -n "Checking if $CC accepts -g... "
187 if (
188 $CC -g __conftest.c -o __conftest
189 ) >/dev/null 2>&1; then
190 echo 'yes'
191 CFLAGS="$CFLAGS -g"
192 else
193 echo 'no'
194 fi
195
196fi
197
198if [ x"$CC" != x"$CXX" ]; then
199 if [ x$DEBUG = x ]; then
200 echo -n "Checking if $CXX accepts -O2... "
201 if (
202 $CXX -O2 __conftest.cc -o __conftest
203 ) >/dev/null 2>&1; then
204 echo 'yes'
205 CXXFLAGS="$CXXFLAGS -O2"
206 else
207 echo 'no'
208 echo -n "Checking if $CXX accepts -O... "
209 if (
210 $CXX -O __conftest.cc -o __conftest
211 ) >/dev/null 2>&1; then
212 echo 'yes'
213 CXXFLAGS="$CXXFLAGS -O"
214 else
215 echo 'no'
216 fi
217 fi
218
219 else
220 echo -n "Checking if $CXX accepts -g... "
221 if (
222 $CXX -g __conftest.cc -o __conftest
223 ) >/dev/null 2>&1; then
224 echo 'yes'
225 CXXFLAGS="$CXXFLAGS -g"
226 else
227 echo 'no'
228 fi
229
230 fi
231else
232 CXXFLAGS="$CFLAGS"
233fi
234echo -n "Checking if $CXX accepts -fno-rtti... "
235if (
236 $CXX -fno-rtti __conftest.cc -o __conftest
237 ) >/dev/null 2>&1; then
238 echo 'yes'
239 CXXFLAGS="$CXXFLAGS -fno-rtti"
240else
241 echo 'no'
242fi
243
244echo -n "Checking if $CXX accepts -fno-exceptions... "
245if (
246 $CXX -fno-exceptions __conftest.cc -o __conftest
247 ) >/dev/null 2>&1; then
248 echo 'yes'
249 CXXFLAGS="$CXXFLAGS -fno-exceptions"
250else
251 echo 'no'
252fi
253
254
255LDFLAGS=
256LIBS=
257
258rm -f __conftest*
259
260##################################################
261
262echo -n 'Checking for BSD signal semantics... '
263cat <<EOF >__conftest.cc
264#include <unistd.h>
265#include <signal.h>
266int count=0;
267void handle(int foo) { count++; }
268int main() {
269 int pid=getpid();
270 signal(SIGINT, handle);
271 kill(pid,SIGINT);
272 kill(pid,SIGINT);
273 kill(pid,SIGINT);
274 if (count!=3) return 1;
275 return 0;
276}
277
278EOF
279if (
280 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
281 ./__conftest || exit 1
282 ) >/dev/null 2>&1; then
283 echo 'yes'
284else
285 if (
286 $CXX $CXXFLAGS -D__USE_BSD_SIGNAL __conftest.cc -o __conftest || exit 1
287 ./__conftest || exit 1
288 ) >/dev/null 2>&1; then
289 echo '-D__USE_BSD_SIGNAL'
290 CFLAGS="$CFLAGS -D__USE_BSD_SIGNAL"
291 CXXFLAGS="$CXXFLAGS -D__USE_BSD_SIGNAL"
292 else
293 echo 'no'
294 echo 'This package needs BSD signal semantics to run.'
295 rm -f __conftest*
296 exit
297 fi
298fi
299rm -f __conftest*
300
301##################################################
302
303echo -n 'Checking for ncurses... '
304cat <<EOF >__conftest.cc
305#include <stdio.h>
306#include <curses.h>
307#ifndef KEY_DOWN
308syntax error. /* not ncurses */
309#endif
310int main() {
311 endwin();
312 return 0;
313}
314
315EOF
316if (
317 $CXX $CXXFLAGS __conftest.cc -lncurses -o __conftest || exit 1
318 ) >/dev/null 2>&1; then
319 echo 'yes'
320 NCURSES=1
321else
322 if (
323 $CXX $CXXFLAGS -I/usr/include/ncurses __conftest.cc -lncurses -o __conftest || exit 1
324 ) >/dev/null 2>&1; then
325 echo '-I/usr/include/ncurses'
326 CFLAGS="$CFLAGS -I/usr/include/ncurses"
327 CXXFLAGS="$CXXFLAGS -I/usr/include/ncurses"
328 NCURSES=1
329 else
330 echo 'no'
331 fi
332fi
333
334if [ x$NCURSES != x ]; then
335 LIBTERMCAP=-lncurses
336else
337 echo -n 'Checking for traditional termcap... '
338cat <<EOF >__conftest.cc
339#include <stdio.h>
340#include <termcap.h>
341int main() {
342 tgetent(NULL, NULL); return 0;
343}
344
345EOF
346 if (
347 $CXX $CXXFLAGS __conftest.cc -ltermcap -o __conftest || exit 1
348 ) >/dev/null 2>&1; then
349 echo '-ltermcap'
350 LIBTERMCAP=-ltermcap
351 else
352 echo 'not found'
353 echo 'This package needs termcap to run.'
354 rm -f __conftest*
355 exit
356 fi
357fi
358rm -f __conftest*
359
360##################################################
361
362echo -n 'Checking for GNU libc... '
363cat <<EOF >__conftest.cc
364#include <stdio.h>
365#if defined(__GLIBC__) && (__GLIBC__ >= 2)
366int tester;
367#endif
368int main() { tester=6; return 0; }
369
370EOF
371if (
372 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
373 ) >/dev/null 2>&1; then
374 echo 'yes'
375 USE_GLIBC=1
376else
377 echo 'no'
378fi
379rm -f __conftest*
380
381##################################################
382
383echo -n 'Checking for forkpty... '
384cat <<EOF >__conftest.cc
385#include <pty.h>
386int main() { forkpty(0, 0, 0, 0); }
387
388EOF
389if (
390 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
391 ) >/dev/null 2>&1; then
392 echo 'yes'
393else
394 if (
395 $CXX $CXXFLAGS __conftest.cc -lutil -o __conftest || exit 1
396 ) >/dev/null 2>&1; then
397 echo '-lutil'
398 LIBS="$LIBS -lutil"
399 else
400 if (
401 $CXX $CXXFLAGS __conftest.cc -lbsd -o __conftest || exit 1
402 ) >/dev/null 2>&1; then
403 echo '-lbsd'
404 LIBBSD="-lbsd"
405 else
406 echo 'no'
407 echo 'This package requires forkpty.'
408 rm -f __conftest*
409 exit
410 fi
411 fi
412fi
413rm -f __conftest*
414
415##################################################
416
417echo -n 'Checking for logwtmp... '
418cat <<EOF >__conftest.cc
419#ifdef __cplusplus
420extern "C"
421#endif
422void logwtmp(const char *, const char *, const char *);
423int main() { logwtmp(0, 0, 0); }
424
425EOF
426if (
427 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
428 ) >/dev/null 2>&1; then
429 echo 'yes'
430else
431 if (
432 $CXX $CXXFLAGS __conftest.cc -lutil -o __conftest || exit 1
433 ) >/dev/null 2>&1; then
434 echo '-lutil'
435 LIBS="$LIBS -lutil"
436 else
437 if (
438 $CXX $CXXFLAGS __conftest.cc -lbsd -o __conftest || exit 1
439 ) >/dev/null 2>&1; then
440 echo '-lbsd'
441 LIBBSD="-lbsd"
442 else
443 echo 'no'
444 echo 'This package requires logwtmp.'
445 rm -f __conftest*
446 exit
447 fi
448 fi
449fi
450rm -f __conftest*
451
452##################################################
453
454echo -n 'Checking for snprintf declaration... '
455cat <<EOF >__conftest.cc
456#include <stdio.h>
457int main() {
458 void *x = (void *)snprintf;
459 printf("%lx", (long)x);
460 return 0;
461}
462
463EOF
464if (
465 $CXX $CXXFLAGS __conftest.cc -o __conftest || exit 1
466 ) >/dev/null 2>&1; then
467 echo 'ok'
468else
469 if (
470 $CXX $CXXFLAGS -D_GNU_SOURCE __conftest.cc -o __conftest || exit 1
471 ./__conftest || exit 1
472 ) >/dev/null 2>&1; then
473 echo '-D_GNU_SOURCE'
474 CFLAGS="$CFLAGS -D_GNU_SOURCE"
475 CXXFLAGS="$CXXFLAGS -D_GNU_SOURCE"
476 else
477 echo 'manual'
478 CFLAGS="$CFLAGS -DDECLARE_SNPRINTF"
479 CXXFLAGS="$CXXFLAGS -DDECLARE_SNPRINTF"
480 fi
481fi
482rm -f __conftest*
483
484echo -n 'Checking for snprintf implementation... '
485cat <<EOF >__conftest.cc
486#include <stdio.h>
487#include <string.h>
488#ifdef DECLARE_SNPRINTF
489#ifdef __cplusplus
490extern "C"
491#endif /*__cplusplus*/
492int snprintf(char *, int, const char *, ...);
493#endif /*DECLARE_SNPRINTF*/
494int main() {
495 char buf[32];
496 snprintf(buf, 8, "%s", "1234567890");
497 if (strlen(buf)!=7) return 1;
498 return 0;
499}
500
501EOF
502if (
503 $CXX $CXXFLAGS __conftest.cc $LIBBSD -o __conftest || exit 1
504 ./__conftest || exit 1
505 ) >/dev/null 2>&1; then
506 echo 'ok'
507else
508 if (
509 $CXX $CXXFLAGS __conftest.cc -lsnprintf $LIBBSD -o __conftest || exit 1
510 ./__conftest || exit 1
511 ) >/dev/null 2>&1; then
512 echo '-lsnprintf'
513 LIBS="$LIBS -lsnprintf"
514 else
515 if (
516 $CXX $CXXFLAGS __conftest.cc -ldb $LIBBSD -o __conftest || exit 1
517 ./__conftest || exit 1
518 ) >/dev/null 2>&1; then
519 echo '-ldb'
520 LIBS="$LIBS -ldb"
521 else
522 echo 'missing'
523 echo 'This package requires snprintf.'
524 rm -f __conftest*
525 exit
526 fi
527 fi
528fi
529rm -f __conftest*
530
531##################################################
532
533## libbsd should go last in case it's broken
534if [ "x$LIBBSD" != x ]; then
535 LIBS="$LIBS $LIBBSD"
536fi
537
538echo 'Generating MCONFIG...'
539(
540 echo -n '# Generated by configure (confgen version 2) on '
541 date
542 echo '#'
543 echo
544
545 echo "BINDIR=$BINDIR"
546 echo "SBINDIR=$SBINDIR"
547 echo "MANDIR=$MANDIR"
548 echo "BINMODE=$BINMODE"
549 echo "DAEMONMODE=$DAEMONMODE"
550 echo "MANMODE=$MANMODE"
551 echo "PREFIX=$PREFIX"
552 echo "EXECPREFIX=$EXECPREFIX"
553 echo "INSTALLROOT=$INSTALLROOT"
554 echo "CC=$CC"
555 echo "CXX=$CXX"
556 if [ x$CC_WARNINGS != x ]; then
557 CFLAGS="$CFLAGS $WARNINGS"
558 fi
559
560 if [ x$CXX_WARNINGS != x ]; then
561 CXXFLAGS="$CXXFLAGS $WARNINGS"
562 fi
563
564 echo "CFLAGS=$CFLAGS" | sed 's/= */=/'
565 echo "CXXFLAGS=$CXXFLAGS" | sed 's/= */=/'
566 echo "LDFLAGS=$LDFLAGS" | sed 's/= */=/'
567 echo "LIBS=$LIBS" | sed 's/= */=/'
568
569 echo "LIBTERMCAP=$LIBTERMCAP"
570 echo "USE_GLIBC=$USE_GLIBC"
571) > MCONFIG
572
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/changelog b/exploits/7350855-netkit/netkit-telnet-0.17/debian/changelog
new file mode 100644
index 0000000..4bdcc10
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/changelog
@@ -0,0 +1,244 @@
1netkit-telnet (0.17-14) unstable; urgency=high
2
3 * Fixed netobuf buffer overflows.
4
5 -- Herbert Xu <herbert@debian.org> Sat, 11 Aug 2001 17:52:25 +1000
6
7netkit-telnet (0.17-13) unstable; urgency=medium
8
9 * Updated devpts check to include devfs as well.
10
11 -- Herbert Xu <herbert@debian.org> Sat, 19 May 2001 15:33:41 +1000
12
13netkit-telnet (0.17-12) unstable; urgency=low
14
15 * Added include <sys/time.h> to telnetd/utility.c (closes: #96803).
16
17 -- Herbert Xu <herbert@debian.org> Wed, 9 May 2001 21:17:12 +1000
18
19netkit-telnet (0.17-11) unstable; urgency=low
20
21 * Added exit 0 to telnetd.postrm (closes: #93934).
22 * Changed misleading help message (closes: #94231).
23
24 -- Herbert Xu <herbert@debian.org> Sat, 21 Apr 2001 22:52:11 +1000
25
26netkit-telnet (0.17-10) unstable; urgency=low
27
28 * Renamed member printf to xprintf (closes: #91351).
29 * Use new in C++ compiler test (closes: #91353).
30
31 -- Herbert Xu <herbert@debian.org> Fri, 13 Apr 2001 19:34:12 +1000
32
33netkit-telnet (0.17-9) unstable; urgency=low
34
35 * Fixed path to license file (Christoph Martin, closes: #86476).
36 * Added missing #DEBHELPER# tag to telnet.prerm (Hiroyuki YAMAMORI,
37 closes: #86894).
38 * Only call update-alternatives in prerm if removing or deconfiguring
39 (closes: #87330).
40
41 -- Herbert Xu <herbert@debian.org> Sun, 25 Feb 2001 00:00:59 +1100
42
43netkit-telnet (0.17-8) unstable; urgency=low
44
45 * Removed remnant of suidregister from telnetd (closes: #85882).
46 * Fixed handling of sockaddr lengths (closes: #86177).
47 * Dynamically allocate editedhost (closes: #86080).
48
49 -- Herbert Xu <herbert@debian.org> Sat, 17 Feb 2001 12:53:11 +1100
50
51netkit-telnet (0.17-7) unstable; urgency=low
52
53 * Added includes for gcc 2.97 (Randolph Chung, closes: #83337).
54 * Avoid DNS lookups if the address is numerical (closes: #83828).
55 * Added menu hint (closes: #80161).
56
57 -- Herbert Xu <herbert@debian.org> Mon, 29 Jan 2001 21:10:59 +1100
58
59netkit-telnet (0.17-6) unstable; urgency=low
60
61 * Added menu entry for telnet (closes: #74845).
62
63 -- Herbert Xu <herbert@debian.org> Sat, 21 Oct 2000 11:08:44 +1100
64
65netkit-telnet (0.17-5) unstable; urgency=low
66
67 * Fixed a memory allocation bug.
68
69 -- Herbert Xu <herbert@debian.org> Fri, 22 Sep 2000 23:12:57 +1100
70
71netkit-telnet (0.17-4) unstable; urgency=low
72
73 * Relaxed telnetlogin a bit.
74 * Provide telnet-client (closes: #70549).
75
76 -- Herbert Xu <herbert@debian.org> Sat, 9 Sep 2000 17:42:53 +1100
77
78netkit-telnet (0.17-3) unstable; urgency=low
79
80 * Check for EAFNOSUPPORT after calling socket(2) in telnet.
81 * Added IPv6 support for telnetd.
82
83 -- Herbert Xu <herbert@debian.org> Sun, 27 Aug 2000 11:28:48 +1100
84
85netkit-telnet (0.17-2) unstable; urgency=low
86
87 * Install telnetlogin ourselves (closes: #69773).
88 * Fixed alternatives typo (closes: #69597).
89
90 -- Herbert Xu <herbert@debian.org> Wed, 23 Aug 2000 20:01:38 +1000
91
92netkit-telnet (0.17-1) unstable; urgency=low
93
94 * New upstream release.
95 * Applied a modified version of Jason Gunthorpe's IPv6 patch for telnet
96 (closes: #68998).
97 * Read /etc/telnetrc before .telnetrc if it exists. The idea was from
98 Robert Luberda. Documented the special hostname DEFAULT (closes: #69113).
99 * Use alternatives for /usr/bin/telnet (closes: #56754).
100
101 -- Herbert Xu <herbert@debian.org> Sat, 19 Aug 2000 14:06:48 +1000
102
103netkit-telnet (0.16-6) unstable; urgency=low
104
105 * Handle localchars correctly (closes: #66039).
106
107 -- Herbert Xu <herbert@debian.org> Mon, 26 Jun 2000 15:01:42 +1000
108
109netkit-telnet (0.16-5) unstable; urgency=low
110
111 * Fixed a bug in responses to TTYPE queries where a (null) could be sent
112 instead of the correct terminal type (closes: #63155).
113
114 -- Herbert Xu <herbert@debian.org> Sat, 6 May 2000 09:42:58 +1000
115
116netkit-telnet (0.16-4) frozen unstable; urgency=low
117
118 * Disabled signal handling that does not work (closes: #62388). Patches
119 that provide correct signal handling are welcome.
120
121 -- Herbert Xu <herbert@debian.org> Mon, 24 Apr 2000 16:58:22 +1000
122
123netkit-telnet (0.16-3) frozen unstable; urgency=medium
124
125 * Restored the default to not being 8-bit clean since it breaks SunOS
126 (closes: #60352, #60386). People who need 8-bit cleanness should use -8.
127 * Made FHS compliant.
128
129 -- Herbert Xu <herbert@debian.org> Wed, 15 Mar 2000 10:39:00 +1100
130
131netkit-telnet (0.16-2) frozen unstable; urgency=low
132
133 * Recompiled with libncurses5.
134 * Changed the permission of /usr/lib/telnetd/login to 4754 (closes: #58786).
135 * telnet is now 8-bit clean by default since it appeared to be so in slink,
136 albeit unintentionally (closes: #57685).
137
138 -- Herbert Xu <herbert@debian.org> Sun, 12 Mar 2000 21:10:47 +1100
139
140netkit-telnet (0.16-1) frozen unstable; urgency=low
141
142 * New upstream release with security fixes.
143 * Run as root if devpts is not present.
144
145 -- Herbert Xu <herbert@debian.org> Thu, 3 Feb 2000 13:42:29 +1100
146
147netkit-telnet (0.14-9) unstable; urgency=low
148
149 * Compile login with -g -O2 -Wall.
150 * Fixed path to default login in in.telnetd(8).
151 * Fixed usage() output (closes: #51498).
152
153 -- Herbert Xu <herbert@debian.org> Tue, 30 Nov 1999 22:43:39 +1100
154
155netkit-telnet (0.14-8) unstable; urgency=low
156
157 * Call fatalperror() instead of fatal() when getpty() fails.
158 * Delete telnetd group before creating telnetd (closes: #46659).
159
160 -- Herbert Xu <herbert@debian.org> Tue, 5 Oct 1999 17:52:36 +1000
161
162netkit-telnet (0.14-7) unstable; urgency=low
163
164 * Redirect stderr for group existence check to /dev/null.
165
166 -- Herbert Xu <herbert@debian.org> Sat, 25 Sep 1999 22:00:31 +1000
167
168netkit-telnet (0.14-6) unstable; urgency=low
169
170 * Check for existence of user/group before removing (fixes #45651).
171
172 -- Herbert Xu <herbert@debian.org> Tue, 21 Sep 1999 21:07:18 +1000
173
174netkit-telnet (0.14-5) unstable; urgency=low
175
176 * Depend on base-files (>= 2.1.8) for group utmp (fixes #44687).
177
178 -- Herbert Xu <herbert@debian.org> Sat, 11 Sep 1999 12:53:08 +1000
179
180netkit-telnet (0.14-4) unstable; urgency=low
181
182 * Rebuilt with working fakeroot (fixes #44043, #44044).
183
184 -- Herbert Xu <herbert@debian.org> Fri, 3 Sep 1999 20:32:28 +1000
185
186netkit-telnet (0.14-3) unstable; urgency=medium
187
188 * telnetd is now a member of utmp (fixes #43543).
189 * Call adduser with --quiet (fixes #43587).
190 * configure now works with egcs 2.95 (fixes #43580, #43747)
191
192 -- Herbert Xu <herbert@debian.org> Thu, 2 Sep 1999 21:18:06 +1000
193
194netkit-telnet (0.14-2) unstable; urgency=low
195
196 * telnetd now depends on adduser and passwd (fixes #43515).
197
198 -- Herbert Xu <herbert@debian.org> Thu, 26 Aug 1999 14:49:25 +1000
199
200netkit-telnet (0.14-1) unstable; urgency=low
201
202 * New upstream release.
203 * Installed the login wrapper (fixes #42092).
204 * Reopen logging if necessary (fixes #36149).
205
206 -- Herbert Xu <herbert@debian.org> Tue, 24 Aug 1999 09:17:24 +1000
207
208netkit-telnet (0.12-6) unstable; urgency=low
209
210 * Applied patch from Matt McLean for openpty support (fixes #35629).
211 * Use glibc versions of logout/logwtmp.
212
213 -- Herbert Xu <herbert@debian.org> Tue, 29 Jun 1999 14:16:14 +1000
214
215netkit-telnet (0.12-5) unstable; urgency=low
216
217 * Fixed a bug with hostnames longer than 64 characters (fixes #33559).
218
219 -- Herbert Xu <herbert@debian.org> Tue, 16 Mar 1999 15:24:36 +1100
220
221netkit-telnet (0.12-4) frozen unstable; urgency=low
222
223 * Uploaded to slink.
224
225 -- Herbert Xu <herbert@debian.org> Sun, 15 Nov 1998 15:04:40 +1100
226
227netkit-telnet (0.12-3) unstable; urgency=low
228
229 * Rebuilt with libncurses4.
230
231 -- Herbert Xu <herbert@debian.org> Sun, 1 Nov 1998 19:38:49 +1100
232
233netkit-telnet (0.12-2) unstable; urgency=low
234
235 * Rebuilt with libstdc++2.9 (fixes #27789).
236
237 -- Herbert Xu <herbert@debian.org> Thu, 15 Oct 1998 22:32:04 +1000
238
239netkit-telnet (0.12-1) unstable; urgency=low
240
241 * Initial Release.
242
243 -- Herbert Xu <herbert@debian.org> Mon, 28 Sep 1998 16:50:43 +1000
244
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/control b/exploits/7350855-netkit/netkit-telnet-0.17/debian/control
new file mode 100644
index 0000000..69e4a3a
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/control
@@ -0,0 +1,25 @@
1Source: netkit-telnet
2Section: net
3Priority: standard
4Maintainer: Herbert Xu <herbert@debian.org>
5Standards-Version: 3.5.6
6Build-Depends: debhelper, libncurses-dev
7
8Package: telnet
9Architecture: any
10Depends: ${shlibs:Depends}
11Replaces: netstd
12Provides: telnet-client
13Description: The telnet client.
14 The telnet command is used for interactive communication with another host
15 using the TELNET protocol.
16
17Package: telnetd
18Architecture: any
19Priority: optional
20Depends: adduser, base-files (>= 2.1.8), dpkg (>= 1.7.0), netbase, passwd, ${shlibs:Depends}
21Replaces: netstd
22Conflicts: suidmanager (<< 0.50)
23Description: The telnet server.
24 The in.telnetd program is a server which supports the DARPA telnet interactive
25 communication protocol.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/copyright b/exploits/7350855-netkit/netkit-telnet-0.17/debian/copyright
new file mode 100644
index 0000000..35d61af
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/copyright
@@ -0,0 +1,18 @@
1This package was split from netstd by Herbert Xu herbert@debian.org on
2Mon, 28 Sep 1998 16:50:43 +1000.
3
4netstd was created by Peter Tobias tobias@et-inf.fho-emden.de on
5Wed, 20 Jul 1994 17:23:21 +0200.
6
7It was downloaded from ftp://ftp.uk.linux.org/pub/linux/Networking/netkit/.
8
9Copyright:
10
11Copyright (c) 1988, 1993 The Regents of the University of California.
12Copyright (c) 1995 David A. Holland
13Copyright (c) 1994 Peter Tobias (issue.net(5))
14Copyright (c) 1983, 1995 Eric P. Allman (setproctitle.[ch])
15
16The license can be found at /usr/share/common-licenses/BSD.
17
18$Id: copyright,v 1.4 2001/02/18 20:28:33 herbert Exp $
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/dirs b/exploits/7350855-netkit/netkit-telnet-0.17/debian/dirs
new file mode 100644
index 0000000..b078dea
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/dirs
@@ -0,0 +1,3 @@
1usr/bin
2usr/share/doc/telnet
3usr/share/man/man1
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/docs b/exploits/7350855-netkit/netkit-telnet-0.17/debian/docs
new file mode 100644
index 0000000..9632452
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/docs
@@ -0,0 +1,2 @@
1BUGS
2README
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/menu b/exploits/7350855-netkit/netkit-telnet-0.17/debian/menu
new file mode 100644
index 0000000..f8d50c6
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/menu
@@ -0,0 +1,3 @@
1?package(telnet): \
2 needs="text" section="Apps/Net" title="Telnet" command="telnet" \
3 hints="Terminal"
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/postinst b/exploits/7350855-netkit/netkit-telnet-0.17/debian/postinst
new file mode 100644
index 0000000..9e6119f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/postinst
@@ -0,0 +1,8 @@
1#!/bin/sh -e
2# $Id: postinst,v 1.4 2000/08/23 10:08:42 herbert Exp $
3
4update-alternatives --install /usr/bin/telnet telnet /usr/bin/telnet.netkit \
5 100 --slave /usr/share/man/man1/telnet.1.gz telnet.1.gz \
6 /usr/share/man/man1/telnet.netkit.1.gz
7
8#DEBHELPER#
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/prerm b/exploits/7350855-netkit/netkit-telnet-0.17/debian/prerm
new file mode 100644
index 0000000..5d58010
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/prerm
@@ -0,0 +1,7 @@
1#!/bin/sh
2
3if [ "$1" = remove ] || [ "$1" = deconfigure ]; then
4 update-alternatives --remove telnet /usr/bin/telnet.netkit
5fi
6
7#DEBHELPER#
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/rules b/exploits/7350855-netkit/netkit-telnet-0.17/debian/rules
new file mode 100644
index 0000000..ebbb79b
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/rules
@@ -0,0 +1,85 @@
1#!/usr/bin/make -f
2# $Id: rules,v 1.11 2001/01/28 11:03:24 herbert Exp $
3# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
4
5# Uncomment this to turn on verbose mode.
6#export DH_VERBOSE=1
7
8build: build-stamp
9build-stamp:
10 dh_testdir
11
12 if [ ! -f MCONFIG ]; then \
13 ./configure; \
14 sed -e 's/^CFLAGS=\(.*\)$$/CFLAGS= -Ddebian -D_GNU_SOURCE -g \1/' \
15 -e 's/^CXXFLAGS=\(.*\)$$/CXXFLAGS= -Ddebian -D_GNU_SOURCE -g \1/' \
16 MCONFIG > MCONFIG.new; \
17 mv MCONFIG.new MCONFIG; \
18 fi
19 $(MAKE)
20
21 touch build-stamp
22
23clean:
24 dh_testdir
25 dh_testroot
26 rm -f build-stamp install-stamp
27
28 -$(MAKE) distclean
29
30 dh_clean
31
32install: install-stamp
33install-stamp: build-stamp
34 dh_testdir
35 dh_testroot
36 dh_clean -k
37 dh_installdirs
38
39 $(MAKE) -C telnet INSTALLROOT=`pwd`/debian/tmp MANDIR=/usr/share/man \
40 install
41 mv debian/tmp/usr/bin/telnet debian/tmp/usr/bin/telnet.netkit
42 mv debian/tmp/usr/share/man/man1/telnet.1 \
43 debian/tmp/usr/share/man/man1/telnet.netkit.1
44 cp telnet/README debian/tmp/usr/share/doc/telnet/README.telnet
45 cp telnet/README.old debian/tmp/usr/share/doc/telnet/README.telnet.old
46 $(MAKE) -C telnetd INSTALLROOT=`pwd`/debian/telnetd \
47 MANDIR=/usr/share/man install
48 cp telnetlogin/telnetlogin.8 debian/telnetd/usr/share/man/man8
49 cp telnetlogin/telnetlogin debian/telnetd/usr/lib
50
51 touch install-stamp
52
53# Build architecture-independent files here.
54binary-indep: build install
55# We have nothing to do by default.
56
57# Build architecture-dependent files here.
58binary-arch: build install
59# dh_testversion
60 dh_testdir
61 dh_testroot
62 dh_installdocs
63 dh_installexamples
64 dh_installmenu
65# dh_installemacsen
66# dh_installinit
67 dh_installcron
68# dh_installmanpages
69# dh_undocumented
70 dh_installchangelogs ChangeLog
71 dh_strip
72 dh_compress
73 dh_fixperms
74 dh_installdeb
75 dh_shlibdeps
76 dh_gencontrol
77# dh_makeshlibs
78 dh_md5sums
79 dh_builddeb
80
81source diff:
82 @echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
83
84binary: binary-indep binary-arch
85.PHONY: build clean binary-indep binary-arch binary
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.dirs b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.dirs
new file mode 100644
index 0000000..710b719
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.dirs
@@ -0,0 +1,4 @@
1usr/lib
2usr/share/man/man5
3usr/share/man/man8
4usr/sbin
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.docs b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.docs
new file mode 100644
index 0000000..9632452
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.docs
@@ -0,0 +1,2 @@
1BUGS
2README
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.postinst b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.postinst
new file mode 100644
index 0000000..48c3981
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.postinst
@@ -0,0 +1,57 @@
1#!/bin/sh -e
2# $Id: telnetd.postinst,v 1.13 2001/05/19 05:34:26 herbert Exp $
3
4update_inetd_entry() {
5 if [ $2 ]; then
6 update-inetd --remove "$rootent"
7 update-inetd --group STANDARD --add "$telnetdent"
8 else
9 update-inetd --remove "$telnetdent"
10 update-inetd --group STANDARD --add "$rootent"
11 fi
12}
13
14if ! id -u telnetd >/dev/null 2>&1; then
15 if sg telnetd -c true 2>/dev/null; then
16 adduser --quiet --system --ingroup telnetd \
17 --home /usr/lib/telnetd telnetd
18 else
19 adduser --quiet --system --group --home /usr/lib/telnetd \
20 telnetd
21 fi
22 adduser --quiet --system --group --home /usr/lib/telnetd telnetd
23fi
24adduser --quiet telnetd utmp
25
26if [ -z "$(dpkg-statoverride --list /usr/lib/telnetlogin)" ]; then
27 chown root.telnetd /usr/lib/telnetlogin
28 chmod 4754 /usr/lib/telnetlogin
29fi
30
31rootent="telnet stream tcp nowait root /usr/sbin/tcpd /usr/sbin/in.telnetd"
32telnetdent="telnet stream tcp nowait telnetd.telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd"
33
34if egrep -q "^(devpts /dev/pts|devfs /dev) " /proc/mounts; then
35 devpts=yes
36else
37 devpts=
38fi
39
40case "$1" in
41abort-upgrade | abort-deconfigure | abort-remove)
42 update-inetd --enable telnet
43 ;;
44configure)
45 if [ -z "$2" ] || dpkg --compare-versions "$2" lt 0.17-13; then
46 update_inetd_entry "$2" $devpts
47 else
48 update-inetd --enable telnet
49 fi
50 ;;
51*)
52 printf "$0: incorrect arguments: $*\n" >&2
53 exit 1
54 ;;
55esac
56
57#DEBHELPER#
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.postrm b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.postrm
new file mode 100644
index 0000000..2178a8c
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.postrm
@@ -0,0 +1,25 @@
1#!/bin/sh -e
2# $Id: telnetd.postrm,v 1.9 2001/04/14 07:02:13 herbert Exp $
3
4case "$1" in
5abort-install | abort-upgrade | upgrade | failed-upgrade)
6 ;;
7remove | disappear)
8 id telnetd > /dev/null 2>&1 && userdel telnetd
9 sg telnetd -c true 2> /dev/null && groupdel telnetd
10 ;;
11purge)
12 # If netbase is not installed, then we don't need to do the remove.
13 if command -v update-inetd >/dev/null 2>&1; then
14 update-inetd --remove "telnet .* /usr/sbin/in.telnetd"
15 fi
16 ;;
17*)
18 echo "$0: incorrect arguments: $*" >&2
19 exit 1
20 ;;
21esac
22
23#DEBHELPER#
24
25exit 0
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.prerm b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.prerm
new file mode 100644
index 0000000..0d344ed
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/debian/telnetd.prerm
@@ -0,0 +1,6 @@
1#!/bin/sh -e
2# $Id: telnetd.prerm,v 1.3 2001/03/15 20:38:36 herbert Exp $
3
4update-inetd --disable telnet
5
6#DEBHELPER#
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/pty-hang.patch b/exploits/7350855-netkit/netkit-telnet-0.17/pty-hang.patch
new file mode 100644
index 0000000..850f4b9
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/pty-hang.patch
@@ -0,0 +1,99 @@
1From whawes@star.net Sun May 25 11:17:36 1997
2Received: from venus.star.net (root@venus.star.net [199.232.114.5]) by hcs.harvard.edu (8.8.5/8.8.3) with ESMTP id LAA15293 for <dholland@hcs.harvard.edu>; Sun, 25 May 1997 11:17:35 -0400 (EDT)
3Received: from hawes (bos221p.star.net [199.232.112.221]) by venus.star.net (8.8.5/8.7.3) with ESMTP id LAA29775; Sun, 25 May 1997 11:17:08 -0400
4Message-ID: <33885894.B2043F5E@star.net>
5Date: Sun, 25 May 1997 11:19:48 -0400
6From: Bill Hawes <whawes@star.net>
7X-Mailer: Mozilla 4.0b3 [en] (WinNT; I)
8MIME-Version: 1.0
9To: David Holland <dholland@hcs.harvard.edu>,
10 Alan Cox <net-patches@lxorguk.ukuu.org.uk>,
11 Peter Tobias <tobias@server.et-inf.fho-emden.de>,
12 "Theodore Ts'o" <tytso@MIT.EDU>
13Subject: kernel patch to fix telnetd deadlock
14X-Priority: 3 (Normal)
15Content-Type: multipart/mixed; boundary="------------B47A35BD86775A5D9DA0F308"
16Status: RO
17
18This is a multi-part message in MIME format.
19--------------B47A35BD86775A5D9DA0F308
20Content-Type: text/plain; charset=us-ascii
21Content-Transfer-Encoding: 7bit
22
23Attached is a patch for drivers/char/n_tty.c that fixes the telnetd
24deadlock when more than 256 chars are typed without a newline. With
25this patch in place, the total of typed-ahead and entered commands is
26still limited to 256 chars, but telnetd comes back to life when the
27buffer is emptied.
28
29Here's what the problem was:
30telnetd does a select() on the master side of a pty to see when it's
31safe to write a character without blocking.
32
33The N_TTY line discipline select() calls the pty driver's
34chars_in_buffer() function to see how many characters are buffered.
35If there are more than 256, the caller has to wait.
36
37The pty driver.chars_in_buffer calls the other side's ldisc
38chars_in_buffer() function. Here's where the problem arises: the slave
39pty is in canonical mode, so that no characters can be read until a
40newline is entered. But the n_tty_chars_in_buffer was returning the
41full number of characters entered, even if no newline had been entered.
42Hence after 256 characters were typed, select() makes telnetd wait, and
43the newline can never arrive.
44
45The patch corrects n_tty_chars_in_buffer() by checking for canonical
46mode and returning 0 if no data is available to be read.
47
48I've tested this on 2.0.30, and it should apply to 2.1.40 as well.
49Please check it out and forward it as you see wish.
50
51I'm working on a patch for pty.c to allow a greater amount of type-ahead
52while still avoiding a deadlock.
53
54Regards,
55Bill Hawes
56--------------B47A35BD86775A5D9DA0F308
57Content-Type: text/plain; charset=us-ascii; name="n_tty-chars-patch"
58Content-Transfer-Encoding: 7bit
59Content-Disposition: inline; filename="n_tty-chars-patch"
60
61--- drivers/char/n_tty.c.old Mon Sep 2 08:18:26 1996
62+++ drivers/char/n_tty.c Sun May 25 10:10:29 1997
63@@ -86,10 +86,31 @@
64
65 /*
66 * Return number of characters buffered to be delivered to user
67+ * WSH 05/20/97: Added check for canonical mode
68+ * In canonical mode, no characters are available to be read until
69+ * the first newline has been entered. (Any characters in the buffer
70+ * may yet be erased ...)
71+ *
72+ * This was causing a deadlock in telnetd: select() thought the buffer
73+ * was already too full, so telnetd couldn't send a newline, but the
74+ * slave PTY couldn't read anything because there was no newline.
75 */
76 int n_tty_chars_in_buffer(struct tty_struct *tty)
77 {
78- return tty->read_cnt;
79+ /* Check first for canonical mode ... */
80+ if (tty->icanon) {
81+ if (!tty->canon_data) return 0;
82+
83+ /* Would prefer to just fall through and return the true
84+ * count, but that could still cause deadlocks until some
85+ * other routines are patched. For now, calculate the
86+ * characters actually available for reading.
87+ */
88+ return (tty->canon_head > tty->read_tail) ?
89+ tty->canon_head - tty->read_tail :
90+ tty->canon_head + (N_TTY_BUF_SIZE - tty->read_tail);
91+ }
92+ return tty->read_cnt; /* all characters available */
93 }
94
95 /*
96
97--------------B47A35BD86775A5D9DA0F308--
98
99
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/Makefile b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/Makefile
new file mode 100644
index 0000000..70246fe
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/Makefile
@@ -0,0 +1,30 @@
1all: telnet
2
3include ../MCONFIG
4include ../MRULES
5
6#CXXFLAGS:=$(patsubst -O2, -g, $(CXXFLAGS))
7
8# -DAUTHENTICATE
9CXXFLAGS += -DUSE_TERMIO -DKLUDGELINEMODE
10LIBS = $(LIBTERMCAP)
11
12SRCS = commands.cc main.cc network.cc ring.cc sys_bsd.cc telnet.cc \
13 terminal.cc tn3270.cc utilities.cc genget.cc environ.cc netlink.cc
14
15OBJS = $(patsubst %.cc, %.o, $(SRCS))
16
17telnet: $(OBJS)
18 $(CXX) $(LDFLAGS) $^ $(LIBS) -o $@
19
20include depend.mk
21depend:
22 $(CXX) $(CXXFLAGS) -MM $(SRCS) >depend.mk
23
24install: telnet
25 install -s -m$(BINMODE) telnet $(INSTALLROOT)$(BINDIR)
26 install -m$(MANMODE) telnet.1 $(INSTALLROOT)$(MANDIR)/man1
27
28clean:
29 rm -f *.o telnet
30
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/README b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/README
new file mode 100644
index 0000000..cd18f9a
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/README
@@ -0,0 +1,26 @@
1
2Telnet has been massively hacked up for this release.
3
4It presently requires a C++ compiler (gcc 2.7.2 or higher
5recommended), but not libg++ or libstdc++. That is, unless you went to
6special effort to not install the C++ compiler when you installed gcc,
7you'll be fine.
8
9Large amounts of further hacking are expected. If you're interested in
10working on it, please contact me, as diffs are likely to become
11useless very quickly.
12
13Support for assorted old/broken systems has been dropped. Some such
14support may be reinstated in the future once the code has been cleaned
15up sufficiently. On the other hand, it may not.
16
17Known bugs/shortcomings at this point:
18
19 - Under some circumstances it can theoretically encounter a
20 buffer overflow condition and drop data on the floor. If
21 anyone actually observes this ``in the wild'' I'd appreciate
22 knowing the circumstances. I'm also not convinced the old
23 behavior was any better.
24 - Various of the debug/trace modes don't work. This probably
25 doesn't matter to anyone not actually coding on it.
26
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/README.old b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/README.old
new file mode 100644
index 0000000..086c88f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/README.old
@@ -0,0 +1,566 @@
1
2
3This is a distribution of both client and server telnet. These programs
4have been compiled on:
5 telnet telnetd
6 BSD 4.3 Reno X X
7 UNICOS 5.1 X X
8 UNICOS 6.0 X X
9 UNICOS 6.1 X X
10 UNICOS 7.0 X X
11 SunOs 3.5 X X (no linemode in server)
12 SunOs 4.1 X X (no linemode in server)
13 DYNIX V3.0.17.9 X X (no linemode in server)
14 Ultrix 3.1 X X (no linemode in server)
15 Ultrix 4.0 X X (no linemode in server)
16
17In addition, previous versions have been compiled on the following
18machines, but were not available for testing this version.
19 telnet telnetd
20 SunOs 4.0.3c X X (no linemode in server)
21 BSD 4.3 X X (no linemode in server)
22 DYNIX V3.0.12 X X (no linemode in server)
23
24Februrary 22, 1991:
25
26 Features:
27
28 This version of telnet/telnetd has support for both
29 the AUTHENTICATION and ENCRYPTION options. The
30 AUTHENTICATION option is fairly well defined, and
31 an option number has been assigned to it. The
32 ENCRYPTION option is still in a state of flux; an
33 option number has NOT been assigned to it yet.
34 The code is provided in this release for experimental
35 and testing purposes.
36
37 The telnet "send" command can now be used to send
38 do/dont/will/wont commands, with any telnet option
39 name. The rules for when do/dont/will/wont are sent
40 are still followed, so just because the user requests
41 that one of these be sent doesn't mean that it will
42 be sent...
43
44 The telnet "getstatus" command no longer requires
45 that option printing be enabled to see the response
46 to the "DO STATUS" command.
47
48 A -n flag has been added to telnetd to disable
49 keepalives.
50
51 A new telnet command, "auth" has been added (if
52 AUTHENTICATE is defined). It has four sub-commands,
53 "status", "debug", "disable", "enable" and "help".
54
55 A new telnet command, "encrypt" has been added (if
56 ENCRYPT is defined). It has many sub-commands:
57 "enable", "type", "start", "stop", "input",
58 "-input", "output", "-output", "status", "auto",
59 "verbose", "debug", and "help".
60
61 An "rlogin" interface has been added. If the program
62 is named "rlogin", or the "-r" flag is given, then
63 an rlogin type of interface will be used.
64 ~. Terminates the session
65 ~<susp> Suspend the session
66 ~^] Escape to telnet command mode
67 ~~ Pass through the ~.
68 BUG: If you type the rlogin escape character
69 in the middle of a line while in rlogin
70 mode, you cannot erase it or any characters
71 before it. Hopefully this can be fixed
72 in a future release...
73
74 General changes:
75
76 A "libtelnet.a" has now been created. This libraray
77 contains code that is common to both telnet and
78 telnetd. This is also where library routines that
79 are needed, but are not in the standard C library,
80 are placed.
81
82 The makefiles have been re-done. All of the site
83 specific configuration information has now been put
84 into a single "Config.generic" file, in the top level
85 directory. Changing this one file will take care of
86 all three subdirectories. Also, to add a new/local
87 definition, a "Config.local" file may be created
88 at the top level; if that file exists, the subdirectories
89 will use that file instead of "Config.generic".
90
91 Many 1-2 line functions in commands.c have been
92 removed, and just inserted in-line, or replaced
93 with a macro.
94
95 Bug Fixes:
96
97 The non-termio code in both telnet and telnetd was
98 setting/clearing CTLECH in the sg_flags word. This
99 was incorrect, and has been changed to set/clear the
100 LCTLECH bit in the local mode word.
101
102 The SRCRT #define has been removed. If IP_OPTIONS
103 and IPPROTO_IP are defined on the system, then the
104 source route code is automatically enabled.
105
106 The NO_GETTYTAB #define has been removed; there
107 is a compatability routine that can be built into
108 libtelnet to achive the same results.
109
110 The server, telnetd, has been switched to use getopt()
111 for parsing the argument list.
112
113 The code for getting the input/output speeds via
114 cfgetispeed()/cfgetospeed() was still not quite
115 right in telnet. Posix says if the ispeed is 0,
116 then it is really equal to the ospeed.
117
118 The suboption processing code in telnet now has
119 explicit checks to make sure that we received
120 the entire suboption (telnetd was already doing this).
121
122 The telnet code for processing the terminal type
123 could cause a core dump if an existing connection
124 was closed, and a new connection opened without
125 exiting telnet.
126
127 Telnetd was doing a TCSADRAIN when setting the new
128 terminal settings; This is not good, because it means
129 that the tcsetattr() will hang waiting for output to
130 drain, and telnetd is the only one that will drain
131 the output... The fix is to use TCSANOW which does
132 not wait.
133
134 Telnetd was improperly setting/clearing the ISTRIP
135 flag in the c_lflag field, it should be using the
136 c_iflag field.
137
138 When the child process of telnetd was opening the
139 slave side of the pty, it was re-setting the EXTPROC
140 bit too early, and some of the other initialization
141 code was wiping it out. This would cause telnetd
142 to go out of linemode and into single character mode.
143
144 One instance of leaving linemode in telnetd forgot
145 to send a WILL ECHO to the client, the net result
146 would be that the user would see double character
147 echo.
148
149 If the MODE was being changed several times very
150 quickly, telnetd could get out of sync with the
151 state changes and the returning acks; and wind up
152 being left in the wrong state.
153
154September 14, 1990:
155
156 Switch the client to use getopt() for parsing the
157 argument list. The 4.3Reno getopt.c is included for
158 systems that don't have getopt().
159
160 Use the posix _POSIX_VDISABLE value for what value
161 to use when disabling special characters. If this
162 is undefined, it defaults to 0x3ff.
163
164 For non-termio systems, TIOCSETP was being used to
165 change the state of the terminal. This causes the
166 input queue to be flushed, which we don't want. This
167 is now changed to TIOCSETN.
168
169 Take out the "#ifdef notdef" around the code in the
170 server that generates a "sync" when the pty oputput
171 is flushed. The potential problem is that some older
172 telnet clients may go into an infinate loop when they
173 receive a "sync", if so, the server can be compiled
174 with "NO_URGENT" defined.
175
176 Fix the client where it was setting/clearing the OPOST
177 bit in the c_lflag field, not the c_oflag field.
178
179 Fix the client where it was setting/clearing the ISTRIP
180 bit in the c_lflag field, not the c_iflag field. (On
181 4.3Reno, this is the ECHOPRT bit in the c_lflag field.)
182 The client also had its interpretation of WILL BINARY
183 and DO BINARY reversed.
184
185 Fix a bug in client that would cause a core dump when
186 attempting to remove the last environment variable.
187
188 In the client, there were a few places were switch()
189 was being passed a character, and if it was a negative
190 value, it could get sign extended, and not match
191 the 8 bit case statements. The fix is to and the
192 switch value with 0xff.
193
194 Add a couple more printoption() calls in the client, I
195 don't think there are any more places were a telnet
196 command can be received and not printed out when
197 "options" is on.
198
199 A new flag has been added to the client, "-a". Currently,
200 this just causes the USER name to be sent across, in
201 the future this may be used to signify that automatic
202 authentication is requested.
203
204 The USER variable is now only sent by the client if
205 the "-a" or "-l user" options are explicity used, or
206 if the user explicitly asks for the "USER" environment
207 variable to be exported. In the server, if it receives
208 the "USER" environment variable, it won't print out the
209 banner message, so that only "Password:" will be printed.
210 This makes the symantics more like rlogin, and should be
211 more familiar to the user. (People are not used to
212 getting a banner message, and then getting just a
213 "Password:" prompt.)
214
215 Re-vamp the code for starting up the child login
216 process. The code was getting ugly, and it was
217 hard to tell what was really going on. What we
218 do now is after the fork(), in the child:
219 1) make sure we have no controlling tty
220 2) open and initialize the tty
221 3) do a setsid()/setpgrp()
222 4) makes the tty our controlling tty.
223 On some systems, #2 makes the tty our controlling
224 tty, and #4 is a no-op. The parent process does
225 a gets rid of any controlling tty after the child
226 is fork()ed.
227
228 Use the strdup() library routine in telnet, instead
229 of the local savestr() routine. If you don't have
230 strdup(), you need to define NO_STRDUP.
231
232 Add support for ^T (SIGINFO/VSTATUS), found in the
233 4.3Reno distribution. This maps to the AYT character.
234 You need a 4-line bugfix in the kernel to get this
235 to work properly:
236
237 > *** tty_pty.c.ORG Tue Sep 11 09:41:53 1990
238 > --- tty_pty.c Tue Sep 11 17:48:03 1990
239 > ***************
240 > *** 609,613 ****
241 > if ((tp->t_lflag&NOFLSH) == 0)
242 > ttyflush(tp, FREAD|FWRITE);
243 > ! pgsignal(tp->t_pgrp, *(unsigned int *)data);
244 > return(0);
245 > }
246 > --- 609,616 ----
247 > if ((tp->t_lflag&NOFLSH) == 0)
248 > ttyflush(tp, FREAD|FWRITE);
249 > ! pgsignal(tp->t_pgrp, *(unsigned int *)data, 1);
250 > ! if ((*(unsigned int *)data == SIGINFO) &&
251 > ! ((tp->t_lflag&NOKERNINFO) == 0))
252 > ! ttyinfo(tp);
253 > return(0);
254 > }
255
256 The client is now smarter when setting the telnet escape
257 character; it only sets it to one of VEOL and VEOL2 if
258 one of them is undefined, and the other one is not already
259 defined to the telnet escape character.
260
261 Handle TERMIOS systems that have seperate input and output
262 line speed settings imbedded in the flags.
263
264 Many other minor bug fixes.
265
266June 20, 1990:
267 Re-organize makefiles and source tree. The telnet/Source
268 directory is now gone, and all the source that was in
269 telnet/Source is now just in the telnet directory.
270
271 Seperate makefile for each system are now gone. There
272 are two makefiles, Makefile and Makefile.generic.
273 The "Makefile" has the definitions for the various
274 system, and "Makefile.generic" does all the work.
275 There is a variable called "WHAT" that is used to
276 specify what to make. For example, in the telnet
277 directory, you might say:
278 make 4.4bsd WHAT=clean
279 to clean out the directory.
280
281 Add support for the ENVIRON and XDISPLOC options.
282 In order for the server to work, login has to have
283 the "-p" option to preserve environment variables.
284
285 Add the SOFT_TAB and LIT_ECHO modes in the LINEMODE support.
286
287 Add the "-l user" option to command line and open command
288 (This is passed through the ENVIRON option).
289
290 Add the "-e" command line option, for setting the escape
291 character.
292
293 Add the "-D", diagnostic, option to the server. This allows
294 the server to print out debug information, which is very
295 useful when trying to debug a telnet that doesn't have any
296 debugging ability.
297
298 Turn off the literal next character when not in LINEMODE.
299
300 Don't recognize ^Y locally, just pass it through.
301
302 Make minor modifications for Sun4.0 and Sun4.1
303
304 Add support for both FORW1 and FORW2 characters. The
305 telnet escpape character is set to whichever of the
306 two is not being used. If both are in use, the escape
307 character is not set, so when in linemode the user will
308 have to follow the escape character with a <CR> or <EOF)
309 to get it passed through.
310
311 Commands can now be put in single and double quotes, and
312 a backslash is now an escape character. This is needed
313 for allowing arbitrary strings to be assigned to environment
314 variables.
315
316 Switch telnetd to use macros like telnet for keeping
317 track of the state of all the options.
318
319 Fix telnetd's processing of options so that we always do
320 the right processing of the LINEMODE option, regardless
321 of who initiates the request to turn it on. Also, make
322 sure that if the other side went "WILL ECHO" in response
323 to our "DO ECHO", that we send a "DONT ECHO" to get the
324 option turned back off!
325
326 Fix the TERMIOS setting of the terminal speed to handle both
327 BSD's seperate fields, and the SYSV method of CBAUD bits.
328
329 Change how we deal with the other side refusing to enable
330 an option. The sequence used to be: send DO option; receive
331 WONT option; send DONT option. Now, the sequence is: send
332 DO option; receive WONT option. Both should be valid
333 according to the spec, but there has been at least one
334 client implementation of telnet identified that can get
335 really confused by this. (The exact sequence, from a trace
336 on the server side, is (numbers are number of responses that
337 we expect to get after that line...):
338
339 send WILL ECHO 1 (initial request)
340 send WONT ECHO 2 (server is changing state)
341 recv DO ECHO 1 (first reply, ok. expect DONT ECHO next)
342 send WILL ECHO 2 (server changes state again)
343 recv DONT ECHO 1 (second reply, ok. expect DO ECHO next)
344 recv DONT ECHO 0 (third reply, wrong answer. got DONT!!!)
345 *** send WONT ECHO (send WONT to acknowledge the DONT)
346 send WILL ECHO 1 (ask again to enable option)
347 recv DO ECHO 0
348
349 recv DONT ECHO 0
350 send WONT ECHO 1
351 recv DONT ECHO 0
352 recv DO ECHO 1
353 send WILL ECHO 0
354 (and the last 5 lines loop forever)
355
356 The line with the "***" is last of the WILL/DONT/WONT sequence.
357 The change to the server to not generate that makes this same
358 example become:
359
360 send will ECHO 1
361 send wont ECHO 2
362 recv do ECHO 1
363 send will ECHO 2
364 recv dont ECHO 1
365 recv dont ECHO 0
366 recv do ECHO 1
367 send will ECHO 0
368
369 There is other option negotiation going on, and not sending
370 the third part changes some of the timings, but this specific
371 example no longer gets stuck in a loop. The "telnet.state"
372 file has been modified to reflect this change to the algorithm.
373
374 A bunch of miscellaneous bug fixes and changes to make
375 lint happier.
376
377 This version of telnet also has some KERBEROS stuff in
378 it. This has not been tested, it uses an un-authorized
379 telnet option number, and uses an out-of-date version
380 of the (still being defined) AUTHENTICATION option.
381 There is no support for this code, do not enable it.
382
383
384March 1, 1990:
385CHANGES/BUGFIXES SINCE LAST RELEASE:
386 Some support for IP TOS has been added. Requires that the
387 kernel support the IP_TOS socket option (currently this
388 is only in UNICOS 6.0).
389
390 Both telnet and telnetd now use the cc_t typedef. typedefs are
391 included for systems that don't have it (in termios.h).
392
393 SLC_SUSP was not supported properly before. It is now.
394
395 IAC EOF was not translated properly in telnetd for SYSV_TERMIO
396 when not in linemode. It now saves a copy of the VEOF character,
397 so that when ICANON is turned off and we can't trust it anymore
398 (because it is now the VMIN character) we use the saved value.
399
400 There were two missing "break" commands in the linemode
401 processing code in telnetd.
402
403 Telnetd wasn't setting the kernel window size information
404 properly. It was using the rows for both rows and columns...
405
406Questions/comments go to
407 David Borman
408 Cray Research, Inc.
409 655F Lone Oak Drive
410 Eagan, MN 55123
411 dab@cray.com.
412
413README: You are reading it.
414
415Config.generic:
416 This file contains all the OS specific definitions. It
417 has pre-definitions for many common system types, and is
418 in standard makefile fromat. See the comments at the top
419 of the file for more information.
420
421Config.local:
422 This is not part of the distribution, but if this file exists,
423 it is used instead of "Config.generic". This allows site
424 specific configuration without having to modify the distributed
425 "Config.generic" file.
426
427kern.diff:
428 This file contains the diffs for the changes needed for the
429 kernel to support LINEMODE is the server. These changes are
430 for a 4.3BSD system. You may need to make some changes for
431 your particular system.
432
433 There is a new bit in the terminal state word, TS_EXTPROC.
434 When this bit is set, several aspects of the terminal driver
435 are disabled. Input line editing, character echo, and
436 mapping of signals are all disabled. This allows the telnetd
437 to turn of these functions when in linemode, but still keep
438 track of what state the user wants the terminal to be in.
439
440 New ioctl()s:
441
442 TIOCEXT Turn on/off the TS_EXTPROC bit
443 TIOCGSTATE Get t_state of tty to look at TS_EXTPROC bit
444 TIOCSIG Generate a signal to processes in the
445 current process group of the pty.
446
447 There is a new mode for packet driver, the TIOCPKT_IOCTL bit.
448 When packet mode is turned on in the pty, and the TS_EXTPROC
449 bit is set, then whenever the state of the pty is changed, the
450 next read on the master side of the pty will have the TIOCPKT_IOCTL
451 bit set, and the data will contain the following:
452 struct xx {
453 struct sgttyb a;
454 struct tchars b;
455 struct ltchars c;
456 int t_state;
457 int t_flags;
458 }
459 This allows the process on the server side of the pty to know
460 when the state of the terminal has changed, and what the new
461 state is.
462
463 However, if you define USE_TERMIO or SYSV_TERMIO, the code will
464 expect that the structure returned in the TIOCPKT_IOCTL is
465 the termio/termios structure.
466
467stty.diff:
468 This file contains the changes needed for the stty(1) program
469 to report on the current status of the TS_EXTPROC bit. It also
470 allows the user to turn on/off the TS_EXTPROC bit. This is useful
471 because it allows the user to say "stty -extproc", and the
472 LINEMODE option will be automatically disabled, and saying "stty
473 extproc" will re-enable the LINEMODE option.
474
475telnet.state:
476 Both the client and server have code in them to deal
477 with option negotiation loops. The algorithm that is
478 used is described in this file.
479
480tmac.doc:
481 Macros for use in formatting the man pages on non-4.3Reno
482 systems.
483
484telnet:
485 This directory contains the client code. No kernel changes are
486 needed to use this code.
487
488telnetd:
489 This directory contains the server code. If LINEMODE or KLUDGELINEMODE
490 are defined, then the kernel modifications listed above are needed.
491
492libtelnet:
493 This directory contains code that is common to both the client
494 and the server.
495
496arpa:
497 This directory has a new <arpa/telnet.h>
498
499
500The following TELNET options are supported:
501
502 LINEMODE:
503 The LINEMODE option is supported as per RFC1116. The
504 FORWARDMASK option is not currently supported.
505
506 BINARY: The client has the ability to turn on/off the BINARY
507 option in each direction. Turning on BINARY from
508 server to client causes the LITOUT bit to get set in
509 the terminal driver on both ends, turning on BINARY
510 from the client to the server causes the PASS8 bit
511 to get set in the terminal driver on both ends.
512
513 TERMINAL-TYPE:
514 This is supported as per RFC1091. On the server side,
515 when a terminal type is received, termcap/terminfo
516 is consulted to determine if it is a known terminal
517 type. It keeps requesting terminal types until it
518 gets one that it recongnizes, or hits the end of the
519 list. The server side looks up the entry in the
520 termcap/terminfo data base, and generates a list of
521 names which it then passes one at a time to each
522 request for a terminal type, duplicating the last
523 entry in the list before cycling back to the beginning.
524
525 NAWS: The Negotiate about Window Size, as per RFC 1073.
526
527 TERMINAL-SPEED:
528 Implemented as per RFC 1079
529
530 TOGGLE-FLOW-CONTROL:
531 Implemented as per RFC 1080
532
533 TIMING-MARK:
534 As per RFC 860
535
536 SGA: As per RFC 858
537
538 ECHO: As per RFC 857
539
540 STATUS:
541 The server will send its current status upon
542 request. It does not ask for the clients status.
543 The client will request the servers current status
544 from the "send getstatus" command.
545
546 ENVIRON:
547 This option is currently being defined by the IETF
548 Telnet Working Group, and an RFC has not yet been
549 issued, but should be in the near future...
550
551 X-DISPLAY-LOCATION:
552 This functionality can be done through the ENVIRON
553 option, it is added here for completeness.
554
555 AUTHENTICATION:
556 This option is currently being defined by the IETF
557 Telnet Working Group, and an RFC has not yet been
558 issued. The basic framework is pretty much decided,
559 but the definitions for the specific authentication
560 schemes is still in a state of flux.
561
562 ENCRYPT:
563 This option is currently being defined by the IETF
564 Telnet Working Group, and an RFC has not yet been
565 issued. The draft RFC is still in a state of flux,
566 so this code may change in the future.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/TODO b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/TODO
new file mode 100644
index 0000000..f67f253
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/TODO
@@ -0,0 +1,13 @@
1eliminate global variables
2 clean up command processing
3 fix "send" command
4 clean up option processing
5
6add empty encrypt hooks (layer over ring buffers)
7flushout --> use nullsink
8
9fix ring buffer so it allocates more buf instead of overflowing
10
11put tracing back in
12
13authentication?
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/array.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/array.h
new file mode 100644
index 0000000..56f1123
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/array.h
@@ -0,0 +1,97 @@
1//
2// File: array.h
3// Date: 16-Jul-95
4// Description: array template
5//
6/*
7 * Copyright (c) 1995 David A. Holland.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Author nor the names of any contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef ARRAY_H
36#define ARRAY_H
37
38#ifndef assert
39#include <assert.h>
40#endif
41
42#ifndef NULL
43#define NULL 0
44#endif
45
46inline void *operator new(size_t, void *v) { return v; }
47
48template <class T>
49class array {
50 protected:
51 T *v;
52 int n, max;
53
54 void reallocto(int newsize) {
55 while (max<newsize) max += 16;
56 char *x = new char[max*sizeof(T)];
57 memcpy(x,v,n*sizeof(T));
58 delete []((char *)v);
59 v = (T *) x;
60 }
61 public:
62 array() { v=NULL; n=max=0; }
63 ~array() { setsize(0); delete []((char *)v); }
64
65 int num() const { return n; }
66
67 void setsize(int newsize) {
68 if (newsize>max) reallocto(newsize);
69 if (newsize>n) {
70 // call default constructors
71 for (int i=n; i<newsize; i++) (void) new(&v[i]) T;
72 }
73 else {
74 // call destructors
75 for (int i=newsize; i<n; i++) v[i].~T();
76 }
77 n = newsize;
78 }
79
80 T &operator [] (int ix) const {
81 assert(ix>=0 && ix<n);
82 return v[ix];
83 }
84
85 int add(const T &val) {
86 int ix = n;
87 setsize(n+1);
88 v[ix] = val;
89 return ix;
90 }
91
92 void push(const T &val) { add(val); }
93
94 T pop() { T t = (*this)[n-1]; setsize(n-1); return t; }
95};
96
97#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/authenc.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/authenc.cc
new file mode 100644
index 0000000..8cc6e57
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/authenc.cc
@@ -0,0 +1,116 @@
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)authenc.c 5.1 (Berkeley) 3/1/91
36 */
37char au_rcsid[] =
38 "$Id: authenc.cc,v 1.6 2000/07/23 03:24:53 dholland Exp $";
39
40#if defined(ENCRYPT) || defined(AUTHENTICATE)
41#include <sys/types.h>
42#include <arpa/telnet.h>
43#include <libtelnet/encrypt.h>
44#include <libtelnet/misc.h>
45
46#include "ring.h"
47#include "externs.h"
48#include "defines.h"
49#include "types.h"
50#include "proto.h"
51
52 int
53net_write(str, len)
54 unsigned char *str;
55 int len;
56{
57 if (NETROOM() > len) {
58 netoring.supply_data(str, len);
59 if (str[0] == IAC && str[1] == SE)
60 printsub('>', &str[2], len-2);
61 return(len);
62 }
63 return(0);
64}
65
66 void
67net_encrypt()
68{
69#if defined(ENCRYPT)
70 if (encrypt_output)
71 ring_encrypt(&netoring, encrypt_output);
72 else
73 ring_clearto(&netoring);
74#endif
75}
76
77 int
78telnet_spin()
79{
80 return(-1);
81}
82
83 char *
84telnet_getenv(val)
85 char *val;
86{
87 /* not sure about the export_only flag, but this code
88 * isn't used anyway --okir */
89 return((char *)env_getvalue((unsigned char *)val, 1));
90}
91
92 char *
93telnet_gets(prompt, result, length, echo)
94 char *prompt;
95 char *result;
96 int length;
97 int echo;
98{
99 extern char *getpass();
100 extern int globalmode;
101 int om = globalmode;
102 char *res;
103
104 TerminalNewMode(-1);
105 if (echo) {
106 printf("%s", prompt);
107 res = fgets(result, length, stdin);
108 }
109 else if ((res = getpass(prompt))!=NULL) {
110 strncpy(result, res, length);
111 res = result;
112 }
113 TerminalNewMode(om);
114 return(res);
115}
116#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/commands.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/commands.cc
new file mode 100644
index 0000000..b7460fa
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/commands.cc
@@ -0,0 +1,2262 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)commands.c 5.5 (Berkeley) 3/22/91
36 */
37char cmd_rcsid[] =
38 "$Id: commands.cc,v 1.34 2000/07/23 04:16:24 dholland Exp $";
39
40#include <string.h>
41
42#include <sys/param.h>
43#include <sys/file.h>
44#include <sys/types.h>
45#include <sys/socket.h>
46#include <netinet/in.h>
47#include <netinet/ip.h>
48
49#ifdef CRAY
50#include <fcntl.h>
51#endif /* CRAY */
52
53#include <sys/wait.h>
54#include <signal.h>
55#include <netdb.h>
56#include <ctype.h>
57#include <pwd.h>
58#include <stdarg.h>
59#include <errno.h>
60#include <unistd.h>
61#include <stdlib.h>
62#include <arpa/inet.h>
63#include <arpa/telnet.h>
64
65#include "ring.h"
66
67#include "externs.h"
68#include "defines.h"
69#include "types.h"
70#include "genget.h"
71#include "environ.h"
72#include "proto.h"
73#include "ptrarray.h"
74#include "netlink.h"
75
76/* In Linux, this is an enum */
77#if defined(__linux__) || defined(IPPROTO_IP)
78#define HAS_IPPROTO_IP
79#endif
80
81#ifndef CRAY
82#if (defined(vax) || defined(tahoe) || defined(hp300)) && !defined(ultrix)
83#include <machine/endian.h>
84#endif /* vax */
85#endif /* CRAY */
86
87#define HELPINDENT ((int) sizeof ("connect"))
88
89#if defined(HAS_IPPROTO_IP) && defined(IP_TOS)
90int tos = -1;
91#endif /* defined(HAS_IPPROTO_IP) && defined(IP_TOS) */
92
93static unsigned long sourceroute(char *arg, char **cpp, int *lenp);
94
95
96char *hostname;
97static char *_hostname;
98
99//typedef int (*intrtn_t)(int argc, const char *argv[]);
100
101class command_entry;
102typedef ptrarray<command_entry> command_table;
103
104static int process_command(command_table *tab, int argc, const char **argv);
105
106
107class command_entry {
108 protected:
109 const char *name; /* command name */
110 const char *help; /* help string (NULL for no help) */
111
112 int nargs;
113 union { /* routine which executes command */
114 command_table *subhandler;
115 int (*handlern)(int, const char **);
116 int (*handler0)(void);
117 int (*handler1)(const char *);
118 int (*handler2)(const char *, const char *);
119 };
120 public:
121 command_entry(const char *n, const char *e,
122 int (*h)(int, const char **))
123 {
124 name = n;
125 help = e;
126 nargs = -1; handlern = h;
127 }
128 command_entry(const char *n, const char *e,
129 int (*h)(void))
130 {
131 name = n;
132 help = e;
133 nargs = 0; handler0 = h;
134 }
135 command_entry(const char *n, const char *e,
136 int (*h)(const char *))
137 {
138 name = n;
139 help = e;
140 nargs = 1; handler1 = h;
141 }
142 command_entry(const char *n, const char *e,
143 int (*h)(const char *, const char *))
144 {
145 name = n;
146 help = e;
147 nargs = 2; handler2 = h;
148 }
149 command_entry(const char *n, const char *e, command_table *sub) {
150 name = n;
151 help = e;
152 nargs = -2;
153 subhandler = sub;
154 }
155
156 int call(int argc, const char *argv[]) {
157 assert(argc>=1);
158 if (nargs>=0 && argc!=nargs+1) {
159 fprintf(stderr, "Wrong number of arguments for command.\n");
160 fprintf(stderr, "Try ? %s for help\n", argv[0]);
161 return 0; /* is this right? */
162 }
163 if (nargs==-2) {
164 if (argc<2) {
165 fprintf(stderr, "`%s' requires a subcommand.\n", argv[0]);
166 fprintf(stderr, "Try %s ? for help\n", argv[0]);
167 return 0; /* is this right? */
168 }
169 return process_command(subhandler, argc-1, argv+1);
170 }
171 else if (nargs==-1) return handlern(argc, argv);
172 else if (nargs==0) return handler0();
173 else if (nargs==1) return handler1(argv[1]);
174 else if (nargs==2) return handler2(argv[1], argv[2]);
175 return 0;
176 }
177
178 void describe() {
179 if (help) printf("%-*s\t%s\n", HELPINDENT, name, help);
180 }
181 void gethelp() {
182 if (help) printf("%s\n", help);
183 else printf("No help available\n");
184 }
185
186 const char *getname() const { return name; }
187};
188
189static char line[256];
190static char saveline[256];
191static int margc;
192static const char *margv[20];
193
194static void makeargv(void) {
195 register char *cp, *cp2, c;
196 register const char **argp = margv;
197
198 margc = 0;
199 cp = line;
200 if (*cp == '!') { /* Special case shell escape */
201 strcpy(saveline, line); /* save for shell command */
202 *argp++ = "!"; /* No room in string to get this */
203 margc++;
204 cp++;
205 }
206 while ((c = *cp)!=0) {
207 register int inquote = 0;
208 while (isspace(c))
209 c = *++cp;
210 if (c == '\0')
211 break;
212 *argp++ = cp;
213 margc += 1;
214 for (cp2 = cp; c != '\0'; c = *++cp) {
215 if (inquote) {
216 if (c == inquote) {
217 inquote = 0;
218 continue;
219 }
220 } else {
221 if (c == '\\') {
222 if ((c = *++cp) == '\0')
223 break;
224 } else if (c == '"') {
225 inquote = '"';
226 continue;
227 } else if (c == '\'') {
228 inquote = '\'';
229 continue;
230 } else if (isspace(c))
231 break;
232 }
233 *cp2++ = c;
234 }
235 *cp2 = '\0';
236 if (c == '\0')
237 break;
238 cp++;
239 }
240 *argp++ = 0;
241}
242
243/*
244 * Make a character string into a number.
245 *
246 * Todo: 1. Could take random integers (12, 0x12, 012, 0b1).
247 */
248
249static int special(const char *s) {
250 char c;
251 char b;
252
253 switch (*s) {
254 case '^':
255 b = *++s;
256 if (b == '?') {
257 c = b | 0x40; /* DEL */
258 }
259 else {
260 c = b & 0x1f;
261 }
262 break;
263 default:
264 c = *s;
265 break;
266 }
267 return c;
268}
269
270/*
271 * Construct a control character sequence
272 * for a special character.
273 */
274static const char *control(cc_t c)
275{
276 static char buf[5];
277 /*
278 * The only way I could get the Sun 3.5 compiler
279 * to shut up about
280 * if ((unsigned int)c >= 0x80)
281 * was to assign "c" to an unsigned int variable...
282 * Arggg....
283 */
284 register unsigned int uic = (unsigned int)c;
285
286 if (uic == 0x7f)
287 return ("^?");
288 if (c == (cc_t)_POSIX_VDISABLE) {
289 return "off";
290 }
291 if (uic >= 0x80) {
292 buf[0] = '\\';
293 buf[1] = ((c>>6)&07) + '0';
294 buf[2] = ((c>>3)&07) + '0';
295 buf[3] = (c&07) + '0';
296 buf[4] = 0;
297 } else if (uic >= 0x20) {
298 buf[0] = c;
299 buf[1] = 0;
300 } else {
301 buf[0] = '^';
302 buf[1] = '@'+c;
303 buf[2] = 0;
304 }
305 return (buf);
306}
307
308
309
310/*
311 * The following are data structures and routines for
312 * the "send" command.
313 *
314 */
315
316struct sendlist {
317 const char *name; /* How user refers to it (case independent) */
318 const char *help; /* Help information (0 ==> no help) */
319 int needconnect; /* Need to be connected */
320 int narg; /* Number of arguments */
321 int (*handler)(const char *, const char *);
322 /* Routine to perform (for special ops) */
323 int nbyte; /* Number of bytes to send this command */
324 int what; /* Character to be sent (<0 ==> special) */
325};
326
327static int send_esc(const char *, const char *);
328static int send_help(const char *, const char *);
329static int send_docmd(const char *, const char *);
330static int send_dontcmd(const char *, const char *);
331static int send_willcmd(const char *, const char *);
332static int send_wontcmd(const char *, const char *);
333
334extern int send_do(int, int);
335extern int send_dont(int, int);
336extern int send_will(int, int);
337extern int send_wont(int, int);
338
339static int dosynch1(const char *, const char *) { return dosynch(); }
340
341static struct sendlist Sendlist[] = {
342 { "ao", "Send Telnet Abort output", 1, 0, 0, 2, AO },
343 { "ayt", "Send Telnet 'Are You There'", 1, 0, 0, 2, AYT },
344 { "brk", "Send Telnet Break", 1, 0, 0, 2, BREAK },
345 { "break", 0, 1, 0, 0, 2, BREAK },
346 { "ec", "Send Telnet Erase Character", 1, 0, 0, 2, EC },
347 { "el", "Send Telnet Erase Line", 1, 0, 0, 2, EL },
348 { "escape", "Send current escape character", 1, 0, send_esc, 1, 0 },
349 { "ga", "Send Telnet 'Go Ahead' sequence", 1, 0, 0, 2, GA },
350 { "ip", "Send Telnet Interrupt Process", 1, 0, 0, 2, IP },
351 { "intp", 0, 1, 0, 0, 2, IP },
352 { "interrupt", 0, 1, 0, 0, 2, IP },
353 { "intr", 0, 1, 0, 0, 2, IP },
354 { "nop", "Send Telnet 'No operation'", 1, 0, 0, 2, NOP },
355 { "eor", "Send Telnet 'End of Record'", 1, 0, 0, 2, EOR },
356 { "abort", "Send Telnet 'Abort Process'", 1, 0, 0, 2, ABORT },
357 { "susp", "Send Telnet 'Suspend Process'", 1, 0, 0, 2, SUSP },
358 { "eof", "Send Telnet End of File Character", 1, 0, 0, 2, xEOF },
359 { "synch", "Perform Telnet 'Synch operation'", 1, 0, dosynch1, 2, 0 },
360 { "getstatus", "Send request for STATUS", 1, 0, get_status, 6, 0 },
361 { "?", "Display send options", 0, 0, send_help, 0, 0 },
362 { "help", 0, 0, 0, send_help, 0, 0 },
363 { "do", 0, 0, 1, send_docmd, 3, 0 },
364 { "dont", 0, 0, 1, send_dontcmd, 3, 0 },
365 { "will", 0, 0, 1, send_willcmd, 3, 0 },
366 { "wont", 0, 0, 1, send_wontcmd, 3, 0 },
367 { 0, 0, 0, 0, 0, 0, 0 }
368};
369
370#define GETSEND(name) ((struct sendlist *) genget(name, (char **) Sendlist, \
371 sizeof(struct sendlist)))
372
373static int sendcmd(int argc, const char *argv[]) {
374 int count; /* how many bytes we are going to need to send */
375 int i;
376/* int question = 0;*/ /* was at least one argument a question */
377 struct sendlist *s; /* pointer to current command */
378 int success = 0;
379 int needconnect = 0;
380
381 if (argc < 2) {
382 printf("need at least one argument for 'send' command\n");
383 printf("'send ?' for help\n");
384 return 0;
385 }
386 /*
387 * First, validate all the send arguments.
388 * In addition, we see how much space we are going to need, and
389 * whether or not we will be doing a "SYNCH" operation (which
390 * flushes the network queue).
391 */
392 count = 0;
393 for (i = 1; i < argc; i++) {
394 s = GETSEND(argv[i]);
395 if (s == 0) {
396 printf("Unknown send argument '%s'\n'send ?' for help.\n",
397 argv[i]);
398 return 0;
399 }
400 else if (s == AMBIGUOUS) {
401 printf("Ambiguous send argument '%s'\n'send ?' for help.\n",
402 argv[i]);
403 return 0;
404 }
405 if (i + s->narg >= argc) {
406 fprintf(stderr,
407 "Need %d argument%s to 'send %s' command. 'send %s ?' for help.\n",
408 s->narg, s->narg == 1 ? "" : "s", s->name, s->name);
409 return 0;
410 }
411 count += s->nbyte;
412 if (s->handler == send_help) {
413 send_help(NULL, NULL);
414 return 0;
415 }
416
417 i += s->narg;
418 needconnect += s->needconnect;
419 }
420 if (!connected && needconnect) {
421 printf("?Need to be connected first.\n");
422 printf("'send ?' for help\n");
423 return 0;
424 }
425 /* Now, do we have enough room? */
426 if (netoring.empty_count() < count) {
427 printf("There is not enough room in the buffer TO the network\n");
428 printf("to process your request. Nothing will be done.\n");
429 printf("('send synch' will throw away most data in the network\n");
430 printf("buffer, if this might help.)\n");
431 return 0;
432 }
433 /* OK, they are all OK, now go through again and actually send */
434 count = 0;
435 for (i = 1; i < argc; i++) {
436 if ((s = GETSEND(argv[i])) == 0) {
437 fprintf(stderr, "Telnet 'send' error - argument disappeared!\n");
438 quit();
439 /*NOTREACHED*/
440 }
441 if (s->handler) {
442 count++;
443 success += (*s->handler)((s->narg > 0) ? argv[i+1] : 0,
444 (s->narg > 1) ? argv[i+2] : 0);
445 i += s->narg;
446 }
447 else {
448 NET2ADD(IAC, s->what);
449 printoption("SENT", IAC, s->what);
450 }
451 }
452 return (count == success);
453}
454
455static int send_esc(const char *, const char *) {
456 NETADD(escapechar);
457 return 1;
458}
459
460static int send_docmd(const char *name, const char *) {
461 return send_tncmd(send_do, "do", name);
462}
463
464static int send_dontcmd(const char *name, const char *) {
465 return(send_tncmd(send_dont, "dont", name));
466}
467
468static int send_willcmd(const char *name, const char *) {
469 return(send_tncmd(send_will, "will", name));
470}
471
472static int send_wontcmd(const char *name, const char *) {
473 return(send_tncmd(send_wont, "wont", name));
474}
475
476int send_tncmd(int (*func)(int, int), const char *cmd, const char *name) {
477 char **cpp;
478 extern char *telopts[];
479
480 if (isprefix(name, "help") || isprefix(name, "?")) {
481 register int col, len;
482
483 printf("Usage: send %s <option>\n", cmd);
484 printf("Valid options are:\n\t");
485
486 col = 8;
487 for (cpp = telopts; *cpp; cpp++) {
488 len = strlen(*cpp) + 1;
489 if (col + len > 65) {
490 printf("\n\t");
491 col = 8;
492 }
493 printf(" %s", *cpp);
494 col += len;
495 }
496 printf("\n");
497 return 0;
498 }
499 cpp = genget(name, telopts, sizeof(char *));
500 if (cpp == AMBIGUOUS) {
501 fprintf(stderr,"'%s': ambiguous argument ('send %s ?' for help).\n",
502 name, cmd);
503 return 0;
504 }
505 if (cpp == 0) {
506 fprintf(stderr, "'%s': unknown argument ('send %s ?' for help).\n",
507 name, cmd);
508 return 0;
509 }
510 if (!connected) {
511 printf("?Need to be connected first.\n");
512 return 0;
513 }
514 (*func)(cpp - telopts, 1);
515 return 1;
516}
517
518static int send_help(const char *, const char *) {
519 struct sendlist *s; /* pointer to current command */
520 for (s = Sendlist; s->name; s++) {
521 if (s->help)
522 printf("%-15s %s\n", s->name, s->help);
523 }
524 return(0);
525}
526
527/*
528 * The following are the routines and data structures referred
529 * to by the arguments to the "toggle" command.
530 */
531
532static int lclchars(int) {
533 donelclchars = 1;
534 return 1;
535}
536
537static int togdebug(int) {
538 return nlink.setdebug(debug);
539}
540
541
542static int togcrlf(int) {
543 if (crlf) {
544 printf("Will send carriage returns as telnet <CR><LF>.\n");
545 }
546 else {
547 printf("Will send carriage returns as telnet <CR><NUL>.\n");
548 }
549 return 1;
550}
551
552int binmode;
553
554static int togbinary(int val) {
555 donebinarytoggle = 1;
556
557 if (val >= 0) {
558 binmode = val;
559 } else {
560 if (my_want_state_is_will(TELOPT_BINARY) &&
561 my_want_state_is_do(TELOPT_BINARY)) {
562 binmode = 1;
563 } else if (my_want_state_is_wont(TELOPT_BINARY) &&
564 my_want_state_is_dont(TELOPT_BINARY)) {
565 binmode = 0;
566 }
567 val = binmode ? 0 : 1;
568 }
569
570 if (val == 1) {
571 if (my_want_state_is_will(TELOPT_BINARY) &&
572 my_want_state_is_do(TELOPT_BINARY)) {
573 printf("Already operating in binary mode with remote host.\n");
574 } else {
575 printf("Negotiating binary mode with remote host.\n");
576 tel_enter_binary(3);
577 }
578 } else {
579 if (my_want_state_is_wont(TELOPT_BINARY) &&
580 my_want_state_is_dont(TELOPT_BINARY)) {
581 printf("Already in network ascii mode with remote host.\n");
582 } else {
583 printf("Negotiating network ascii mode with remote host.\n");
584 tel_leave_binary(3);
585 }
586 }
587 return 1;
588}
589
590static int togrbinary(int val) {
591 donebinarytoggle = 1;
592
593 if (val == -1)
594 val = my_want_state_is_do(TELOPT_BINARY) ? 0 : 1;
595
596 if (val == 1) {
597 if (my_want_state_is_do(TELOPT_BINARY)) {
598 printf("Already receiving in binary mode.\n");
599 }
600 else {
601 printf("Negotiating binary mode on input.\n");
602 tel_enter_binary(1);
603 }
604 }
605 else {
606 if (my_want_state_is_dont(TELOPT_BINARY)) {
607 printf("Already receiving in network ascii mode.\n");
608 } else {
609 printf("Negotiating network ascii mode on input.\n");
610 tel_leave_binary(1);
611 }
612 }
613 return 1;
614}
615
616static int togxbinary(int val) {
617 donebinarytoggle = 1;
618
619 if (val == -1)
620 val = my_want_state_is_will(TELOPT_BINARY) ? 0 : 1;
621
622 if (val == 1) {
623 if (my_want_state_is_will(TELOPT_BINARY)) {
624 printf("Already transmitting in binary mode.\n");
625 }
626 else {
627 printf("Negotiating binary mode on output.\n");
628 tel_enter_binary(2);
629 }
630 }
631 else {
632 if (my_want_state_is_wont(TELOPT_BINARY)) {
633 printf("Already transmitting in network ascii mode.\n");
634 }
635 else {
636 printf("Negotiating network ascii mode on output.\n");
637 tel_leave_binary(2);
638 }
639 }
640 return 1;
641}
642
643
644static int netdata; /* Print out network data flow */
645static int prettydump; /* Print "netdata" output in user readable format */
646static int termdata; /* Print out terminal data flow */
647
648static int togglehelp(int);
649
650struct togglelist {
651 const char *name; /* name of toggle */
652 const char *help; /* help message */
653 int (*handler)(int); /* routine to do actual setting */
654 int *variable;
655 const char *actionexplanation;
656};
657
658static struct togglelist Togglelist[] = {
659 { "autoflush", "flushing of output when sending interrupt characters",
660 NULL, &autoflush,
661 "flush output when sending interrupt characters" },
662
663 { "autosynch", "automatic sending of interrupt characters in urgent mode",
664 NULL, &autosynch,
665 "send interrupt characters in urgent mode" },
666
667#if 0
668 { "autologin", "automatic sending of login and/or authentication info",
669 NULL, &autologin,
670 "send login name and/or authentication information" },
671 { "authdebug", "Toggle authentication debugging",
672 auth_togdebug, NULL,
673 "print authentication debugging information" },
674 { "autoencrypt", "automatic encryption of data stream",
675 EncryptAutoEnc, NULL,
676 "automatically encrypt output" },
677 { "autodecrypt", "automatic decryption of data stream",
678 EncryptAutoDec, NULL,
679 "automatically decrypt input" },
680 { "verbose_encrypt", "Toggle verbose encryption output",
681 EncryptVerbose, NULL,
682 "print verbose encryption output" },
683 { "encdebug", "Toggle encryption debugging",
684 EncryptDebug, NULL,
685 "print encryption debugging information" },
686#endif
687
688 { "skiprc", "don't read the telnetrc files",
689 NULL, &skiprc,
690 "read the telnetrc files" },
691 { "binary",
692 "sending and receiving of binary data",
693 togbinary, NULL,
694 NULL },
695 { "inbinary", "receiving of binary data",
696 togrbinary, NULL,
697 NULL },
698 { "outbinary", "sending of binary data",
699 togxbinary, 0,
700 NULL },
701 { "crlf", "sending carriage returns as telnet <CR><LF>",
702 togcrlf, &crlf,
703 NULL },
704 { "crmod", "mapping of received carriage returns",
705 NULL, &crmod,
706 "map carriage return on output" },
707 { "localchars", "local recognition of certain control characters",
708 lclchars, &localchars,
709 "recognize certain control characters" },
710
711 { " ", "", 0, 0, 0 }, /* empty line */
712
713#if defined(TN3270) && !defined(__linux__)
714 { "apitrace", "(debugging) toggle tracing of API transactions",
715 NULL, &apitrace,
716 "trace API transactions" },
717 { "cursesdata", "(debugging) toggle printing of hexadecimal curses data",
718 NULL, &cursesdata,
719 "print hexadecimal representation of curses data" },
720#endif /* TN3270 and not linux */
721
722 { "debug", "debugging",
723 togdebug, &debug,
724 "turn on socket level debugging" },
725 { "netdata", "printing of hexadecimal network data (debugging)",
726 NULL, &netdata,
727 "print hexadecimal representation of network traffic" },
728 { "prettydump","output of \"netdata\" to user readable format (debugging)",
729 NULL, &prettydump,
730 "print user readable output for \"netdata\"" },
731 { "options", "viewing of options processing (debugging)",
732 NULL, &showoptions,
733 "show option processing" },
734
735 { "termdata", "(debugging) toggle printing of hexadecimal terminal data",
736 NULL, &termdata,
737 "print hexadecimal representation of terminal traffic" },
738
739 { "?", NULL, togglehelp, 0, 0 },
740 { "help", NULL, togglehelp, 0, 0 },
741 { 0, 0, 0, 0, 0 }
742};
743
744static int togglehelp(int) {
745 struct togglelist *c;
746
747 for (c = Togglelist; c->name; c++) {
748 if (c->help) {
749 if (*c->help)
750 printf("%-15s toggle %s\n", c->name, c->help);
751 else
752 printf("\n");
753 }
754 }
755 printf("\n");
756 printf("%-15s %s\n", "?", "display help information");
757 return 0;
758}
759
760static void settogglehelp(int set) {
761 struct togglelist *c;
762
763 for (c = Togglelist; c->name; c++) {
764 if (c->help) {
765 if (*c->help)
766 printf("%-15s %s %s\n", c->name, set ? "enable" : "disable",
767 c->help);
768 else
769 printf("\n");
770 }
771 }
772}
773
774#define GETTOGGLE(name) (struct togglelist *) \
775 genget(name, (char **) Togglelist, sizeof(struct togglelist))
776
777static int toggle(int argc, const char *argv[]) {
778 int retval = 1;
779 const char *name;
780 struct togglelist *c;
781
782 if (argc < 2) {
783 fprintf(stderr,
784 "Need an argument to 'toggle' command. 'toggle ?' for help.\n");
785 return 0;
786 }
787 argc--;
788 argv++;
789 while (argc--) {
790 name = *argv++;
791 c = GETTOGGLE(name);
792 if (c == AMBIGUOUS) {
793 fprintf(stderr, "'%s': ambiguous argument ('toggle ?' for help).\n",
794 name);
795 return 0;
796 }
797 else if (c == 0) {
798 fprintf(stderr, "'%s': unknown argument ('toggle ?' for help).\n",
799 name);
800 return 0;
801 }
802 else {
803 if (c->variable) {
804 *c->variable = !*c->variable; /* invert it */
805 if (c->actionexplanation) {
806 printf("%s %s.\n", *c->variable? "Will" : "Won't",
807 c->actionexplanation);
808 }
809 }
810 if (c->handler) {
811 retval &= (*c->handler)(-1);
812 }
813 }
814 }
815 return retval;
816}
817
818/*
819 * The following perform the "set" command.
820 */
821
822struct setlist {
823 const char *name; /* name */
824 const char *help; /* help information */
825 void (*handler)(const char *);
826 cc_t *charp; /* where it is located at */
827};
828
829static struct setlist Setlist[] = {
830#ifdef KLUDGELINEMODE
831 { "echo", "character to toggle local echoing on/off", 0, &echoc },
832#endif
833 { "escape", "character to escape back to telnet command mode", 0, &escapechar },
834 { "rlogin", "rlogin escape character", 0, &rlogin },
835 { "tracefile", "file to write trace information to", SetNetTrace, (cc_t *)NetTraceFile},
836 { " ", "", 0, 0 },
837 { " ", "The following need 'localchars' to be toggled true", 0, 0 },
838 { "flushoutput", "character to cause an Abort Output", 0, termFlushCharp },
839 { "interrupt", "character to cause an Interrupt Process", 0, termIntCharp },
840 { "quit", "character to cause an Abort process", 0, termQuitCharp },
841 { "eof", "character to cause an EOF ", 0, termEofCharp },
842 { " ", "", 0, 0 },
843 { " ", "The following are for local editing in linemode", 0, 0 },
844 { "erase", "character to use to erase a character", 0, termEraseCharp },
845 { "kill", "character to use to erase a line", 0, termKillCharp },
846 { "lnext", "character to use for literal next", 0, termLiteralNextCharp },
847 { "susp", "character to cause a Suspend Process", 0, termSuspCharp },
848 { "reprint", "character to use for line reprint", 0, termRprntCharp },
849 { "worderase", "character to use to erase a word", 0, termWerasCharp },
850 { "start", "character to use for XON", 0, termStartCharp },
851 { "stop", "character to use for XOFF", 0, termStopCharp },
852 { "forw1", "alternate end of line character", 0, termForw1Charp },
853 { "forw2", "alternate end of line character", 0, termForw2Charp },
854 { "ayt", "alternate AYT character", 0, termAytCharp },
855 { 0, 0, 0, 0 }
856};
857
858#if defined(CRAY) && !defined(__STDC__)
859/* Work around compiler bug in pcc 4.1.5 */
860 void
861_setlist_init()
862{
863#ifndef KLUDGELINEMODE
864#define N 5
865#else
866#define N 6
867#endif
868 Setlist[N+0].charp = &termFlushChar;
869 Setlist[N+1].charp = &termIntChar;
870 Setlist[N+2].charp = &termQuitChar;
871 Setlist[N+3].charp = &termEofChar;
872 Setlist[N+6].charp = &termEraseChar;
873 Setlist[N+7].charp = &termKillChar;
874 Setlist[N+8].charp = &termLiteralNextChar;
875 Setlist[N+9].charp = &termSuspChar;
876 Setlist[N+10].charp = &termRprntChar;
877 Setlist[N+11].charp = &termWerasChar;
878 Setlist[N+12].charp = &termStartChar;
879 Setlist[N+13].charp = &termStopChar;
880 Setlist[N+14].charp = &termForw1Char;
881 Setlist[N+15].charp = &termForw2Char;
882 Setlist[N+16].charp = &termAytChar;
883#undef N
884}
885#endif /* defined(CRAY) && !defined(__STDC__) */
886
887static struct setlist *
888getset(const char *name)
889{
890 return (struct setlist *)
891 genget(name, (char **) Setlist, sizeof(struct setlist));
892}
893
894void set_escape_char(char *s) {
895 if (rlogin != _POSIX_VDISABLE) {
896 rlogin = (s && *s) ? special(s) : _POSIX_VDISABLE;
897 printf("Telnet rlogin escape character is '%s'.\n",
898 control(rlogin));
899 }
900 else {
901 escapechar = (s && *s) ? special(s) : _POSIX_VDISABLE;
902 printf("Telnet escape character is '%s'.\n", control(escapechar));
903 }
904}
905
906static int setcmd(int argc, const char *argv[]) {
907 int value;
908 struct setlist *ct;
909 struct togglelist *c;
910
911 if (argc < 2 || argc > 3) {
912 printf("Format is 'set Name Value'\n'set ?' for help.\n");
913 return 0;
914 }
915 if ((argc == 2) && (isprefix(argv[1], "?") || isprefix(argv[1], "help"))) {
916 for (ct = Setlist; ct->name; ct++)
917 printf("%-15s %s\n", ct->name, ct->help);
918 printf("\n");
919 settogglehelp(1);
920 printf("%-15s %s\n", "?", "display help information");
921 return 0;
922 }
923
924 ct = getset(argv[1]);
925 if (ct == 0) {
926 c = GETTOGGLE(argv[1]);
927 if (c == 0) {
928 fprintf(stderr, "'%s': unknown argument ('set ?' for help).\n",
929 argv[1]);
930 return 0;
931 }
932 else if (c == AMBIGUOUS) {
933 fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",
934 argv[1]);
935 return 0;
936 }
937 if (c->variable) {
938 if ((argc == 2) || (strcmp("on", argv[2]) == 0))
939 *c->variable = 1;
940 else if (strcmp("off", argv[2]) == 0)
941 *c->variable = 0;
942 else {
943 printf("Format is 'set togglename [on|off]'\n'set ?' for help.\n");
944 return 0;
945 }
946 if (c->actionexplanation) {
947 printf("%s %s.\n", *c->variable? "Will" : "Won't",
948 c->actionexplanation);
949 }
950 }
951 if (c->handler)
952 (*c->handler)(1);
953 }
954 else if (argc != 3) {
955 printf("Format is 'set Name Value'\n'set ?' for help.\n");
956 return 0;
957 }
958 else if (ct == AMBIGUOUS) {
959 fprintf(stderr, "'%s': ambiguous argument ('set ?' for help).\n",
960 argv[1]);
961 return 0;
962 }
963 else if (ct->handler) {
964 (*ct->handler)(argv[2]);
965 printf("%s set to \"%s\".\n", ct->name, (char *)ct->charp);
966 }
967 else {
968 if (strcmp("off", argv[2])) {
969 value = special(argv[2]);
970 } else {
971 value = _POSIX_VDISABLE;
972 }
973 *(ct->charp) = (cc_t)value;
974 printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
975 }
976 slc_check();
977 return 1;
978}
979
980static int unsetcmd(int argc, const char *argv[]) {
981 struct setlist *ct;
982 struct togglelist *c;
983 const char *name;
984
985 if (argc < 2) {
986 fprintf(stderr,
987 "Need an argument to 'unset' command. 'unset ?' for help.\n");
988 return 0;
989 }
990 if (isprefix(argv[1], "?") || isprefix(argv[1], "help")) {
991 for (ct = Setlist; ct->name; ct++)
992 printf("%-15s %s\n", ct->name, ct->help);
993 printf("\n");
994 settogglehelp(0);
995 printf("%-15s %s\n", "?", "display help information");
996 return 0;
997 }
998
999 argc--;
1000 argv++;
1001 while (argc--) {
1002 name = *argv++;
1003 ct = getset(name);
1004 if (ct == 0) {
1005 c = GETTOGGLE(name);
1006 if (c == 0) {
1007 fprintf(stderr, "'%s': unknown argument ('unset ?' for help).\n",
1008 name);
1009 return 0;
1010 }
1011 else if (c == AMBIGUOUS) {
1012 fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",
1013 name);
1014 return 0;
1015 }
1016 if (c->variable) {
1017 *c->variable = 0;
1018 if (c->actionexplanation) {
1019 printf("%s %s.\n", *c->variable? "Will" : "Won't",
1020 c->actionexplanation);
1021 }
1022 }
1023 if (c->handler)
1024 (*c->handler)(0);
1025 }
1026 else if (ct == AMBIGUOUS) {
1027 fprintf(stderr, "'%s': ambiguous argument ('unset ?' for help).\n",
1028 name);
1029 return 0;
1030 }
1031 else if (ct->handler) {
1032 (*ct->handler)(0);
1033 printf("%s reset to \"%s\".\n", ct->name, (char *)ct->charp);
1034 }
1035 else {
1036 *(ct->charp) = _POSIX_VDISABLE;
1037 printf("%s character is '%s'.\n", ct->name, control(*(ct->charp)));
1038 }
1039 }
1040 return 1;
1041}
1042
1043/*
1044 * The following are the data structures and routines for the
1045 * 'mode' command.
1046 */
1047#ifdef KLUDGELINEMODE
1048extern int kludgelinemode;
1049
1050static int dokludgemode(int) {
1051 kludgelinemode = 1;
1052 send_wont(TELOPT_LINEMODE, 1);
1053 send_dont(TELOPT_SGA, 1);
1054 send_dont(TELOPT_ECHO, 1);
1055 return 0;
1056}
1057#endif
1058
1059static int dolinemode(int) {
1060#ifdef KLUDGELINEMODE
1061 if (kludgelinemode)
1062 send_dont(TELOPT_SGA, 1);
1063#endif
1064 send_will(TELOPT_LINEMODE, 1);
1065 send_dont(TELOPT_ECHO, 1);
1066 return 1;
1067}
1068
1069static int docharmode(int) {
1070#ifdef KLUDGELINEMODE
1071 if (kludgelinemode)
1072 send_do(TELOPT_SGA, 1);
1073 else
1074#endif
1075 send_wont(TELOPT_LINEMODE, 1);
1076 send_do(TELOPT_ECHO, 1);
1077 return 1;
1078}
1079
1080static int dolmmode(int bit, int on) {
1081 unsigned char c;
1082 extern int linemode;
1083
1084 if (my_want_state_is_wont(TELOPT_LINEMODE)) {
1085 printf("?Need to have LINEMODE option enabled first.\n");
1086 printf("'mode ?' for help.\n");
1087 return 0;
1088 }
1089
1090 if (on)
1091 c = (linemode | bit);
1092 else
1093 c = (linemode & ~bit);
1094 lm_mode(&c, 1, 1);
1095 return 1;
1096}
1097
1098int setmode(int bit) {
1099 return dolmmode(bit, 1);
1100}
1101
1102int clearmode(int bit) {
1103 return dolmmode(bit, 0);
1104}
1105
1106struct modelist {
1107 const char *name; /* command name */
1108 const char *help; /* help string */
1109 int (*handler)(int); /* routine which executes command */
1110 int needconnect; /* Do we need to be connected to execute? */
1111 int arg1;
1112};
1113
1114extern int modehelp(int);
1115
1116static struct modelist ModeList[] = {
1117 { "character", "Disable LINEMODE option", docharmode, 1,0},
1118#ifdef KLUDGELINEMODE
1119 { "", "(or disable obsolete line-by-line mode)", NULL, 0,0 },
1120#endif
1121 { "line", "Enable LINEMODE option", dolinemode, 1,0},
1122#ifdef KLUDGELINEMODE
1123 { "", "(or enable obsolete line-by-line mode)", NULL, 0,0 },
1124#endif
1125 { "", "", NULL, 0, 0 },
1126 { "", "These require the LINEMODE option to be enabled", NULL, 0, 0},
1127 { "isig", "Enable signal trapping", setmode, 1, MODE_TRAPSIG },
1128 { "+isig", 0, setmode, 1, MODE_TRAPSIG },
1129 { "-isig", "Disable signal trapping", clearmode, 1, MODE_TRAPSIG },
1130 { "edit", "Enable character editing", setmode, 1, MODE_EDIT },
1131 { "+edit", 0, setmode, 1, MODE_EDIT },
1132 { "-edit", "Disable character editing", clearmode, 1, MODE_EDIT },
1133 { "softtabs", "Enable tab expansion", setmode, 1, MODE_SOFT_TAB },
1134 { "+softtabs", 0, setmode, 1, MODE_SOFT_TAB },
1135 { "-softtabs", "Disable character editing", clearmode, 1, MODE_SOFT_TAB },
1136 { "litecho", "Enable literal character echo", setmode, 1, MODE_LIT_ECHO },
1137 { "+litecho", 0, setmode, 1, MODE_LIT_ECHO },
1138 { "-litecho", "Disable literal character echo", clearmode, 1, MODE_LIT_ECHO },
1139 { "help", 0, modehelp, 0, 0 },
1140#ifdef KLUDGELINEMODE
1141 { "kludgeline", 0, dokludgemode, 1, 0 },
1142#endif
1143 { "", "", 0, 0, 0 },
1144 { "?", "Print help information", modehelp, 0, 0 },
1145 { 0, 0, 0, 0, 0 },
1146};
1147
1148
1149int modehelp(int) {
1150 struct modelist *mt;
1151
1152 printf("format is: 'mode Mode', where 'Mode' is one of:\n\n");
1153 for (mt = ModeList; mt->name; mt++) {
1154 if (mt->help) {
1155 if (*mt->help)
1156 printf("%-15s %s\n", mt->name, mt->help);
1157 else
1158 printf("\n");
1159 }
1160 }
1161 return 0;
1162}
1163
1164#define GETMODECMD(name) (struct modelist *) \
1165 genget(name, (char **) ModeList, sizeof(struct modelist))
1166
1167static int modecmd(const char *arg) {
1168 struct modelist *mt;
1169
1170 mt = GETMODECMD(arg);
1171 if (mt == 0) {
1172 fprintf(stderr, "Unknown mode '%s' ('mode ?' for help).\n", arg);
1173 }
1174 else if (mt == AMBIGUOUS) {
1175 fprintf(stderr, "Ambiguous mode '%s' ('mode ?' for help).\n", arg);
1176 }
1177 else if (mt->needconnect && !connected) {
1178 printf("?Need to be connected first.\n");
1179 printf("'mode ?' for help.\n");
1180 }
1181 else if (mt->handler) {
1182 return (*mt->handler)(mt->arg1);
1183 }
1184 return 0;
1185}
1186
1187/*
1188 * The following data structures and routines implement the
1189 * "display" command.
1190 */
1191
1192static void dotog(struct togglelist *tl) {
1193 if (tl->variable && tl->actionexplanation) {
1194 if (*tl->variable) {
1195 printf("will");
1196 }
1197 else {
1198 printf("won't");
1199 }
1200 printf(" %s.\n", tl->actionexplanation);
1201 }
1202}
1203
1204static void doset(struct setlist *sl) {
1205 if (sl->name && *sl->name != ' ') {
1206 if (sl->handler == 0) {
1207 printf("%-15s [%s]\n", sl->name, control(*sl->charp));
1208 }
1209 else {
1210 printf("%-15s \"%s\"\n", sl->name, (char *)sl->charp);
1211 }
1212 }
1213}
1214
1215static int display(int argc, const char *argv[]) {
1216 struct togglelist *tl;
1217 struct setlist *sl;
1218
1219 if (argc == 1) {
1220 for (tl = Togglelist; tl->name; tl++) {
1221 dotog(tl);
1222 }
1223 printf("\n");
1224 for (sl = Setlist; sl->name; sl++) {
1225 doset(sl);
1226 }
1227 }
1228 else {
1229 int i;
1230
1231 for (i = 1; i < argc; i++) {
1232 sl = getset(argv[i]);
1233 tl = GETTOGGLE(argv[i]);
1234 if (sl == AMBIGUOUS || tl == AMBIGUOUS) {
1235 printf("?Ambiguous argument '%s'.\n", argv[i]);
1236 return 0;
1237 }
1238 else if (!sl && !tl) {
1239 printf("?Unknown argument '%s'.\n", argv[i]);
1240 return 0;
1241 }
1242 else {
1243 if (tl) {
1244 dotog(tl);
1245 }
1246 if (sl) {
1247 doset(sl);
1248 }
1249 }
1250 }
1251 }
1252 optionstatus();
1253 return 1;
1254}
1255
1256/*
1257 * The following are the data structures, and many of the routines,
1258 * relating to command processing.
1259 */
1260
1261/*
1262 * Set the escape character.
1263 */
1264static int setescape(int argc, const char *argv[]) {
1265 const char *arg;
1266 char buf[50];
1267
1268 printf(
1269 "Deprecated usage - please use 'set escape%s%s' in the future.\n",
1270 (argc > 2)? " ":"", (argc > 2)? argv[1]: "");
1271 if (argc > 2) {
1272 arg = argv[1];
1273 }
1274 else {
1275 printf("new escape character: ");
1276 (void) fgets(buf, sizeof(buf), stdin);
1277 arg = buf;
1278 }
1279 if (arg[0] != '\0')
1280 escapechar = arg[0];
1281 if (!In3270) {
1282 printf("Escape character is '%s'.\n", control(escapechar));
1283 }
1284 (void) fflush(stdout);
1285 return 1;
1286}
1287
1288static int togcrmod(void) {
1289 crmod = !crmod;
1290 printf("Deprecated usage - please use 'toggle crmod' in the future.\n");
1291 printf("%s map carriage return on output.\n", crmod ? "Will" : "Won't");
1292 fflush(stdout);
1293 return 1;
1294}
1295
1296int suspend(void) {
1297#ifdef SIGTSTP
1298 setcommandmode();
1299 {
1300 long oldrows, oldcols, newrows, newcols, err;
1301
1302 err = TerminalWindowSize(&oldrows, &oldcols);
1303 (void) kill(0, SIGTSTP);
1304 err += TerminalWindowSize(&newrows, &newcols);
1305 if (connected && !err &&
1306 ((oldrows != newrows) || (oldcols != newcols))) {
1307 sendnaws();
1308 }
1309 }
1310 /* reget parameters in case they were changed */
1311 TerminalSaveState();
1312 setconnmode(0);
1313#else
1314 printf("Suspend is not supported. Try the '!' command instead\n");
1315#endif
1316 return 1;
1317}
1318
1319#if !defined(TN3270)
1320int shell(int argc, const char **) {
1321 setcommandmode();
1322 switch(vfork()) {
1323 case -1:
1324 perror("Fork failed\n");
1325 break;
1326
1327 case 0:
1328 {
1329 /*
1330 * Fire up the shell in the child.
1331 */
1332 const char *shellp, *shellname;
1333
1334 shellp = getenv("SHELL");
1335 if (shellp == NULL)
1336 shellp = "/bin/sh";
1337 if ((shellname = rindex(shellp, '/')) == 0)
1338 shellname = shellp;
1339 else
1340 shellname++;
1341 if (argc > 1)
1342 execl(shellp, shellname, "-c", &saveline[1], 0);
1343 else
1344 execl(shellp, shellname, 0);
1345 perror("Execl");
1346 _exit(1);
1347 }
1348 default:
1349 wait(NULL); /* Wait for the shell to complete */
1350 }
1351 return 1;
1352}
1353#endif /* !defined(TN3270) */
1354
1355static int dobye(int isfromquit) {
1356 extern int resettermname;
1357
1358 if (connected) {
1359 nlink.close(1);
1360 printf("Connection closed.\n");
1361 connected = 0;
1362 resettermname = 1;
1363
1364 /* reset options */
1365 tninit();
1366#if defined(TN3270)
1367 SetIn3270(); /* Get out of 3270 mode */
1368#endif /* defined(TN3270) */
1369 }
1370 if (!isfromquit) {
1371 siglongjmp(toplevel, 1);
1372 /* NOTREACHED */
1373 }
1374 return 1; /* Keep lint, etc., happy */
1375}
1376
1377static int bye(void) {
1378 if (!connected) {
1379 printf("Need to be connected first for `bye'.\n");
1380 return 0;
1381 }
1382 return dobye(0);
1383}
1384
1385void quit(void) {
1386 dobye(1);
1387 Exit(0);
1388}
1389
1390int logout(void) {
1391 if (!connected) {
1392 printf("Need to be connected first for `logout'.\n");
1393 return 0;
1394 }
1395 send_do(TELOPT_LOGOUT, 1);
1396 netflush();
1397 return 1;
1398}
1399
1400/*
1401 * The ENVIRON command.
1402 */
1403
1404struct envcmd {
1405 const char *name;
1406 const char *help;
1407 void (*handler)(const char *, const char *);
1408 int narg;
1409};
1410
1411static void env_help(const char *, const char *);
1412
1413typedef void (*envfunc)(const char *, const char *);
1414
1415struct envcmd EnvList[] = {
1416 { "define", "Define an environment variable",
1417 env_define, 2 },
1418 { "undefine", "Undefine an environment variable",
1419 (envfunc) env_undefine, 1 },
1420 { "export", "Mark an environment variable for automatic export",
1421 (envfunc) env_export, 1 },
1422 { "unexport", "Don't mark an environment variable for automatic export",
1423 (envfunc) env_unexport, 1 },
1424 { "send", "Send an environment variable", (envfunc) env_send, 1 },
1425 { "list", "List the current environment variables",
1426 (envfunc) env_list, 0 },
1427 { "help", 0, env_help, 0 },
1428 { "?", "Print help information", env_help, 0 },
1429 { 0, 0, 0, 0 },
1430};
1431
1432static void env_help(const char *, const char *) {
1433 struct envcmd *c;
1434
1435 for (c = EnvList; c->name; c++) {
1436 if (c->help) {
1437 if (*c->help)
1438 printf("%-15s %s\n", c->name, c->help);
1439 else
1440 printf("\n");
1441 }
1442 }
1443}
1444
1445static struct envcmd *getenvcmd(const char *name) {
1446 return (struct envcmd *)
1447 genget(name, (char **) EnvList, sizeof(struct envcmd));
1448}
1449
1450int env_cmd(int argc, const char *argv[]) {
1451 struct envcmd *c;
1452
1453 if (argc < 2) {
1454 fprintf(stderr,
1455 "Need an argument to 'environ' command. 'environ ?' for help.\n");
1456 return 0;
1457 }
1458 c = getenvcmd(argv[1]);
1459 if (c == 0) {
1460 fprintf(stderr, "'%s': unknown argument ('environ ?' for help).\n",
1461 argv[1]);
1462 return 0;
1463 }
1464 if (c == AMBIGUOUS) {
1465 fprintf(stderr, "'%s': ambiguous argument ('environ ?' for help).\n",
1466 argv[1]);
1467 return 0;
1468 }
1469 if (c->narg + 2 != argc) {
1470 fprintf(stderr,
1471 "Need %s%d argument%s to 'environ %s' command. 'environ ?' for help.\n",
1472 c->narg < argc + 2 ? "only " : "",
1473 c->narg, c->narg == 1 ? "" : "s", c->name);
1474 return 0;
1475 }
1476 (*c->handler)(argv[2], argv[3]);
1477 return 1;
1478}
1479
1480
1481/*
1482 * The AUTHENTICATE command.
1483 *
1484 * auth status Display status
1485 * auth disable Disable an authentication type
1486 * auth enable Enable an authentication type
1487 *
1488 * The ENCRYPT command.
1489 *
1490 * encrypt enable Enable encryption
1491 * encrypt disable Disable encryption
1492 * encrypt type foo Set encryption type
1493 * encrypt start Start encryption
1494 * encrypt stop Stop encryption
1495 * encrypt input Start encrypting input stream
1496 * encrypt -input Stop encrypting input stream
1497 * encrypt output Start encrypting output stream
1498 * encrypt -output Stop encrypting output stream
1499 * encrypt status Print status
1500 */
1501
1502
1503#ifdef TN3270
1504char *oflgs[] = { "read-only", "write-only", "read-write" };
1505
1506static void filestuff(int fd) {
1507 int res;
1508
1509#ifdef F_GETOWN
1510 setconnmode(0);
1511 res = fcntl(fd, F_GETOWN, 0);
1512 setcommandmode();
1513
1514 if (res == -1) {
1515 perror("fcntl");
1516 return;
1517 }
1518 printf("\tOwner is %d.\n", res);
1519#endif
1520
1521 setconnmode(0);
1522 res = fcntl(fd, F_GETFL, 0);
1523 setcommandmode();
1524
1525 if (res == -1) {
1526 perror("fcntl");
1527 return;
1528 }
1529 printf("\tFlags are 0x%x: %s\n", res, oflgs[res]);
1530}
1531#endif /* TN3270 */
1532
1533/*
1534 * Print status about the connection.
1535 */
1536static int dostatus(int notmuch) {
1537 if (connected) {
1538 printf("Connected to %s.\n", hostname);
1539 if (!notmuch) {
1540 int mode = getconnmode();
1541
1542 if (my_want_state_is_will(TELOPT_LINEMODE)) {
1543 printf("Operating with LINEMODE option\n");
1544 printf("%s line editing\n", (mode&MODE_EDIT) ? "Local" : "No");
1545 printf("%s catching of signals\n",
1546 (mode&MODE_TRAPSIG) ? "Local" : "No");
1547 slcstate();
1548#ifdef KLUDGELINEMODE
1549 }
1550 else if (kludgelinemode && my_want_state_is_dont(TELOPT_SGA)) {
1551 printf("Operating in obsolete linemode\n");
1552#endif
1553 }
1554 else {
1555 printf("Operating in single character mode\n");
1556 if (localchars)
1557 printf("Catching signals locally\n");
1558 }
1559 printf("%s character echo\n", (mode&MODE_ECHO) ? "Local" : "Remote");
1560 if (my_want_state_is_will(TELOPT_LFLOW))
1561 printf("%s flow control\n", (mode&MODE_FLOW) ? "Local" : "No");
1562 }
1563 }
1564 else {
1565 printf("No connection.\n");
1566 }
1567#if !defined(TN3270)
1568 printf("Escape character is '%s'.\n", control(escapechar));
1569 (void) fflush(stdout);
1570#else /* !defined(TN3270) */
1571 if ((!In3270) && !notmuch) {
1572 printf("Escape character is '%s'.\n", control(escape));
1573 }
1574 if ((argc >= 2) && !strcmp(argv[1], "everything")) {
1575 printf("SIGIO received %d time%s.\n",
1576 sigiocount, (sigiocount == 1)? "":"s");
1577 if (In3270) {
1578 printf("Process ID %d, process group %d.\n",
1579 getpid(), getpgrp(getpid()));
1580 printf("Terminal input:\n");
1581 filestuff(tin);
1582 printf("Terminal output:\n");
1583 filestuff(tout);
1584 printf("Network socket:\n");
1585 filestuff(net);
1586 }
1587 }
1588 if (In3270 && transcom) {
1589 printf("Transparent mode command is '%s'.\n", transcom);
1590 }
1591 fflush(stdout);
1592 if (In3270) {
1593 return 0;
1594 }
1595#endif /* TN3270 */
1596 return 1;
1597}
1598
1599static int status(void) {
1600 int notmuch = 1;
1601 return dostatus(notmuch);
1602}
1603
1604#ifdef SIGINFO
1605/*
1606 * Function that gets called when SIGINFO is received.
1607 */
1608void ayt_status(int) {
1609 dostatus(1);
1610}
1611#endif
1612
1613int tn(int argc, const char *argv[]) {
1614 struct sockaddr_in sn;
1615 char *srp = NULL;
1616 int srlen;
1617 int family = 0;
1618 const char *cmd, *volatile user = 0;
1619 const char *portp = NULL;
1620 char *hostp = NULL;
1621 char *resolv_hostp;
1622 struct addrinfo hints;
1623 struct addrinfo *hostaddr = 0;
1624 int res;
1625 char name[NI_MAXHOST];
1626 char service[NI_MAXSERV];
1627 struct addrinfo *tmpaddr;
1628
1629 /* clear the socket address prior to use */
1630 memset(&sn, 0, sizeof(sn));
1631
1632 if (connected) {
1633 printf("?Already connected to %s\n", hostname);
1634 return 0;
1635 }
1636 if (_hostname) {
1637 delete[] _hostname;
1638 _hostname = 0;
1639 }
1640 if (argc < 2) {
1641 (void) strcpy(line, "open ");
1642 printf("(to) ");
1643 (void) fgets(&line[strlen(line)], sizeof(line) - strlen(line), stdin);
1644 makeargv();
1645 argc = margc;
1646 argv = margv;
1647 }
1648 cmd = *argv;
1649 --argc; ++argv;
1650 while (argc) {
1651 /*
1652 * Having "telnet h" print usage is really stupid...
1653 * suppose your hostname is h?
1654 */
1655 if (/*isprefix(*argv, "help") ||*/ isprefix(*argv, "?"))
1656 goto usage;
1657 if (strcmp(*argv, "-l") == 0) {
1658 --argc; ++argv;
1659 if (argc == 0)
1660 goto usage;
1661 user = *argv++;
1662 --argc;
1663 continue;
1664 }
1665 if (strcmp(*argv, "-a") == 0) {
1666 --argc; ++argv;
1667 autologin = 1;
1668 continue;
1669 }
1670 if (strcmp(*argv, "-6") == 0) {
1671 --argc; ++argv;
1672#ifdef AF_INET6
1673 family = AF_INET6;
1674#else
1675 puts("IPv6 unsupported");
1676#endif
1677 continue;
1678 }
1679 if (strcmp(*argv, "-4") == 0) {
1680 --argc; ++argv;
1681 family = AF_INET;
1682 continue;
1683 }
1684 if (hostp == 0) {
1685 /* this leaks memory - FIXME */
1686 hostp = strdup(*argv++);
1687 --argc;
1688 continue;
1689 }
1690 if (portp == 0) {
1691 portp = *argv++;
1692 --argc;
1693 continue;
1694 }
1695 usage:
1696 printf("usage: %s [-l user] [-a] host-name [port]\n", cmd);
1697 return 0;
1698 }
1699 if (hostp == 0)
1700 goto usage;
1701
1702#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
1703 resolv_hostp = hostp;
1704 if (hostp[0] == '@' || hostp[0] == '!') {
1705 if ((hostname = strrchr(hostp, ':')) == NULL)
1706 hostname = strrchr(hostp, '@');
1707 hostname++;
1708 srp = 0;
1709 int temp = sourceroute(hostp, &srp, &srlen);
1710 if (temp == 0) {
1711 herror(srp);
1712 return 0;
1713 } else if (temp == -1) {
1714 printf("Bad source route option: %s\n", hostp);
1715 return 0;
1716 } else {
1717 sn.sin_addr.s_addr = temp;
1718 sn.sin_family = AF_INET;
1719 /*
1720 * For source route we just make sure to get the IP given
1721 * on the command line when looking up the port.
1722 */
1723 resolv_hostp = inet_ntoa(sn.sin_addr);
1724 }
1725 }
1726#endif
1727
1728 /* User port or the default name of telnet. */
1729 if (portp) {
1730 if (*portp == '-') {
1731 portp++;
1732 telnetport = 1;
1733 } else
1734 telnetport = 0;
1735 }
1736 else {
1737 portp = "telnet";
1738 telnetport = 1;
1739 }
1740
1741 /* We only understand SOCK_STREAM sockets. */
1742 memset(&hints, 0, sizeof(hints));
1743 hints.ai_socktype = SOCK_STREAM;
1744 hints.ai_flags = AI_NUMERICHOST;
1745 hints.ai_family = family;
1746
1747 /* Resolve both the host and service simultaneously. */
1748 res = getaddrinfo(resolv_hostp, portp, &hints, &hostaddr);
1749 if (res == EAI_NONAME) {
1750 hints.ai_flags = AI_CANONNAME;
1751 res = getaddrinfo(resolv_hostp, portp, &hints, &hostaddr);
1752 } else if (hostaddr) {
1753 hostaddr->ai_canonname = 0;
1754 }
1755 if (res || !hostaddr) {
1756 fprintf(stderr, "telnet: could not resolve %s/%s: %s\n", resolv_hostp, portp, gai_strerror(res));
1757 return 0;
1758 }
1759
1760 /* Try to connect to every listed round robin IP. */
1761 tmpaddr = hostaddr;
1762 errno = 0;
1763 do {
1764 int x;
1765
1766 if (!tmpaddr) {
1767 if (errno)
1768 perror("telnet: Unable to connect to remote host");
1769 else
1770 fputs("telnet: Unable to connect to remote host: "
1771 "Bad port number\n", stderr);
1772err:
1773 freeaddrinfo(hostaddr);
1774 return 0;
1775 }
1776
1777 if (tmpaddr->ai_family == AF_UNIX) {
1778nextaddr:
1779 tmpaddr = tmpaddr->ai_next;
1780 continue;
1781 }
1782
1783 getnameinfo(tmpaddr->ai_addr, tmpaddr->ai_addrlen,
1784 name, sizeof(name), service, sizeof(service),
1785 NI_NUMERICHOST | NI_NUMERICSERV);
1786
1787 printf("Trying %s...\n", name);
1788 x = nlink.connect(debug, tmpaddr, srp, srlen, tos);
1789 if (!x)
1790 goto err;
1791 else if (x==1)
1792 goto nextaddr;
1793
1794 connected++;
1795 } while (connected == 0);
1796 if (hostaddr->ai_canonname == 0) {
1797 hostname = new char[strlen(hostp)+1];
1798 strcpy(hostname, hostp);
1799 }
1800 else {
1801 hostname = new char[strlen(hostaddr->ai_canonname)+1];
1802 strcpy(hostname, hostaddr->ai_canonname);
1803 }
1804
1805 cmdrc(hostp, hostname);
1806 freeaddrinfo(hostaddr);
1807 if (autologin && user == NULL) {
1808 struct passwd *pw;
1809
1810 user = getenv("USER");
1811 if (user == NULL ||
1812 ((pw = getpwnam(user))!=NULL && pw->pw_uid != getuid())) {
1813 if ((pw = getpwuid(getuid()))!=NULL)
1814 user = pw->pw_name;
1815 else
1816 user = NULL;
1817 }
1818 }
1819 if (user) {
1820 env_define("USER", user);
1821 env_export("USER");
1822 }
1823 dostatus(1);
1824 if (sigsetjmp(peerdied, 1) == 0)
1825 telnet(user);
1826 nlink.close(0);
1827 ExitString("Connection closed by foreign host.\n",1);
1828 /*NOTREACHED*/
1829 return 0;
1830}
1831
1832static char
1833 openhelp[] = "connect to a site",
1834 closehelp[] = "close current connection",
1835 logouthelp[] = "forcibly logout remote user and close the connection",
1836 quithelp[] = "exit telnet",
1837 statushelp[] = "print status information",
1838 sendhelp[] = "transmit special characters ('send ?' for more)",
1839 sethelp[] = "set operating parameters ('set ?' for more)",
1840 unsethelp[] = "unset operating parameters ('unset ?' for more)",
1841 togglestring[] ="toggle operating parameters ('toggle ?' for more)",
1842 displayhelp[] = "display operating parameters",
1843#ifdef TN3270
1844 transcomhelp[] = "specify Unix command for transparent mode pipe",
1845#endif /* TN3270 */
1846 zhelp[] = "suspend telnet",
1847/* shellhelp[] = "invoke a subshell", */
1848 envhelp[] = "change environment variables ('environ ?' for more)",
1849 modestring[] = "try to enter line or character mode ('mode ?' for more)";
1850
1851static char crmodhelp[] = "deprecated command -- use 'toggle crmod' instead";
1852static char escapehelp[] = "deprecated command -- use 'set escape' instead";
1853
1854static int help(command_table *, int, const char **);
1855
1856static int doquit(void) {
1857 quit();
1858 return 0;
1859}
1860
1861static int slc_mode_import_0(void) {
1862 slc_mode_import(0);
1863 return 1;
1864}
1865
1866static int slc_mode_import_1(void) {
1867 slc_mode_import(1);
1868 return 1;
1869}
1870
1871static int do_slc_mode_export(void) {
1872 slc_mode_export();
1873 return 1;
1874}
1875
1876static ptrarray<command_entry> cmdtab;
1877static ptrarray<command_entry> cmdtab2;
1878static ptrarray<command_entry> slctab;
1879
1880#define BIND(a,b,c) cmdtab.add(new command_entry(a,b,c))
1881#define BIND2(a,b,c) cmdtab2.add(new command_entry(a,b,c))
1882#define BINDS(a,b,c) slctab.add(new command_entry(a,b,c))
1883
1884
1885void cmdtab_init(void) {
1886 BIND("close", closehelp, bye);
1887 BIND("logout", logouthelp, logout);
1888 BIND("display", displayhelp, display);
1889 BIND("mode", modestring, modecmd);
1890 BIND("open", openhelp, tn);
1891 BIND("quit", quithelp, doquit);
1892 BIND("send", sendhelp, sendcmd);
1893 BIND("set", sethelp, setcmd);
1894 BIND("unset", unsethelp, unsetcmd);
1895 BIND("status", statushelp, status);
1896 BIND("toggle", togglestring, toggle);
1897 BIND("slc", "set treatment of special characters\n", &slctab);
1898
1899#ifdef TN3270
1900 BIND("transcom", transcomhelp, settranscom);
1901#endif /* TN3270 */
1902
1903 // BIND("auth", authhelp, auth_cmd);
1904 // BIND("encrypt", encrypthelp, encrypt_cmd);
1905
1906 BIND("z", zhelp, suspend);
1907
1908#if defined(TN3270) /* why?! */
1909 BIND("!", shellhelp, shell);
1910#endif
1911
1912 BIND("environ", envhelp, env_cmd);
1913
1914 BINDS("export", "Use local special character definitions",
1915 do_slc_mode_export);
1916 BINDS("import", "Use remote special character definitions",
1917 slc_mode_import_1);
1918 BINDS("check", "Verify remote special character definitions",
1919 slc_mode_import_0);
1920
1921 BIND2("escape", escapehelp, setescape);
1922 BIND2("crmod", crmodhelp, togcrmod);
1923}
1924
1925
1926static command_entry *getcmd(command_table *tab, const char *name) {
1927 if (!strcasecmp(name, "?") ||
1928 !strcasecmp(name, "h") ||
1929 !strcasecmp(name, "help")) return (command_entry *)HELP;
1930
1931 command_entry *found = NULL;
1932
1933 for (int i=0; i<tab->num(); i++) {
1934 command_entry *c = (*tab)[i];
1935 if (!strcasecmp(c->getname(), name)) return c;
1936 if (!strncasecmp(c->getname(), name, strlen(name))) {
1937 if (found) return (command_entry *)AMBIGUOUS;
1938 found = c;
1939 }
1940 }
1941 if (tab==&cmdtab && !found) return getcmd(&cmdtab2, name);
1942
1943 return found;
1944}
1945
1946static int process_command(command_table *tab, int argc, const char **argv) {
1947 command_entry *c;
1948 c = getcmd(tab, argv[0]);
1949 if (c == HELP) {
1950 help(tab, argc, argv);
1951 }
1952 else if (c == AMBIGUOUS) {
1953 printf("?Ambiguous command\n");
1954 }
1955 else if (c == NULL) {
1956 printf("?Invalid command\n");
1957 }
1958 else {
1959 if (c->call(argc, argv)) return 1;
1960 }
1961 return 0;
1962}
1963
1964void command(int top, const char *tbuf, int cnt) {
1965
1966 setcommandmode();
1967 if (!top) {
1968 putchar('\n');
1969 }
1970 else {
1971 signal(SIGINT, SIG_DFL);
1972 signal(SIGQUIT, SIG_DFL);
1973 }
1974 for (;;) {
1975 if (rlogin == _POSIX_VDISABLE)
1976 printf("%s> ", prompt);
1977 if (tbuf) {
1978 char *cp = line;
1979 while (cnt > 0 && (*cp++ = *tbuf++) != '\n')
1980 cnt--;
1981 tbuf = 0;
1982 if (cp == line || *--cp != '\n' || cp == line)
1983 goto getline;
1984 *cp = '\0';
1985 if (rlogin == _POSIX_VDISABLE)
1986 printf("%s\n", line);
1987 }
1988 else {
1989 getline:
1990 if (rlogin != _POSIX_VDISABLE)
1991 printf("%s> ", prompt);
1992 if (fgets(line, sizeof(line), stdin) == NULL) {
1993 if (feof(stdin) || ferror(stdin)) {
1994 quit();
1995 /*NOTREACHED*/
1996 }
1997 break;
1998 }
1999 }
2000 if (line[0] == 0)
2001 break;
2002 makeargv();
2003 if (margv[0] == 0) {
2004 break;
2005 }
2006 if (process_command(&cmdtab, margc, margv)) break;
2007 }
2008 if (!top) {
2009 if (!connected) {
2010 siglongjmp(toplevel, 1);
2011 /*NOTREACHED*/
2012 }
2013#if defined(TN3270)
2014 if (shell_active == 0) {
2015 setconnmode(0);
2016 }
2017#else /* defined(TN3270) */
2018 setconnmode(0);
2019#endif /* defined(TN3270) */
2020 }
2021}
2022
2023/*
2024 * Help command.
2025 */
2026static int help(command_table *tab, int argc, const char *argv[]) {
2027 int i;
2028
2029 if (argc == 1) {
2030 printf("Commands may be abbreviated. Commands are:\n\n");
2031 for (i = 0; i<tab->num(); i++) (*tab)[i]->describe();
2032 return 0;
2033 }
2034 for (i=1; i<argc; i++) {
2035 command_entry *c = getcmd(tab, argv[i]);
2036 if (c == HELP) {
2037 printf("Print help information\n");
2038 }
2039 else if (c == AMBIGUOUS) {
2040 printf("?Ambiguous help command %s\n", argv[i]);
2041 }
2042 else if (c == NULL) {
2043 printf("?Invalid help command %s\n", argv[i]);
2044 }
2045 else {
2046 c->gethelp();
2047 }
2048 }
2049 return 0;
2050}
2051
2052static void readrc(const char *m1, const char *m2, const char *rcname) {
2053 FILE *rcfile;
2054 int gotmachine = 0;
2055 int l1 = strlen(m1);
2056 int l2 = strlen(m2);
2057 char m1save[strlen(m1) + 1];
2058
2059 strcpy(m1save, m1);
2060 m1 = m1save;
2061
2062 rcfile = fopen(rcname, "r");
2063 if (!rcfile) return;
2064
2065 while (fgets(line, sizeof(line), rcfile)) {
2066 if (line[0] == 0)
2067 break;
2068 if (line[0] == '#')
2069 continue;
2070 if (gotmachine) {
2071 if (!isspace(line[0]))
2072 gotmachine = 0;
2073 }
2074 if (gotmachine == 0) {
2075 if (isspace(line[0]))
2076 continue;
2077 if (strncasecmp(line, m1, l1) == 0)
2078 strncpy(line, &line[l1], sizeof(line) - l1);
2079 else if (strncasecmp(line, m2, l2) == 0)
2080 strncpy(line, &line[l2], sizeof(line) - l2);
2081 else if (strncasecmp(line, "DEFAULT", 7) == 0)
2082 strncpy(line, &line[7], sizeof(line) - 7);
2083 else
2084 continue;
2085 if (line[0] != ' ' && line[0] != '\t' && line[0] != '\n')
2086 continue;
2087 gotmachine = 1;
2088 }
2089 makeargv();
2090 if (margv[0] == 0)
2091 continue;
2092 process_command(&cmdtab, margc, margv);
2093 }
2094 fclose(rcfile);
2095}
2096
2097void cmdrc(const char *m1, const char *m2) {
2098 static char *rcname = 0;
2099 static char rcbuf[128];
2100
2101 if (skiprc) return;
2102
2103 readrc(m1, m2, "/etc/telnetrc");
2104 if (rcname == 0) {
2105 rcname = getenv("HOME");
2106 if (rcname)
2107 strcpy(rcbuf, rcname);
2108 else
2109 rcbuf[0] = '\0';
2110 strcat(rcbuf, "/.telnetrc");
2111 rcname = rcbuf;
2112 }
2113 readrc(m1, m2, rcname);
2114}
2115
2116#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
2117
2118/*
2119 * Source route is handed in as
2120 * [!]@hop1@hop2...[@|:]dst
2121 * If the leading ! is present, it is a
2122 * strict source route, otherwise it is
2123 * assmed to be a loose source route.
2124 *
2125 * We fill in the source route option as
2126 * hop1,hop2,hop3...dest
2127 * and return a pointer to hop1, which will
2128 * be the address to connect() to.
2129 *
2130 * Arguments:
2131 * arg: pointer to route list to decipher
2132 *
2133 * cpp: If *cpp is not equal to NULL, this is a
2134 * pointer to a pointer to a character array
2135 * that should be filled in with the option.
2136 *
2137 * lenp: pointer to an integer that contains the
2138 * length of *cpp if *cpp != NULL.
2139 *
2140 * Return values:
2141 *
2142 * Returns the address of the host to connect to. If the
2143 * return value is -1, there was a syntax error in the
2144 * option, either unknown characters, or too many hosts.
2145 * If the return value is 0, one of the hostnames in the
2146 * path is unknown, and *cpp is set to point to the bad
2147 * hostname.
2148 *
2149 * *cpp: If *cpp was equal to NULL, it will be filled
2150 * in with a pointer to our static area that has
2151 * the option filled in. This will be 32bit aligned.
2152 *
2153 * *lenp: This will be filled in with how long the option
2154 * pointed to by *cpp is.
2155 *
2156 */
2157static unsigned long sourceroute(char *arg, char **cpp, int *lenp) {
2158 static char lsr[44];
2159 char *cp, *cp2, *lsrp, *lsrep;
2160 struct in_addr sin_addr;
2161 register struct hostent *host = 0;
2162 register char c;
2163
2164 /*
2165 * Verify the arguments, and make sure we have
2166 * at least 7 bytes for the option.
2167 */
2168 if (cpp == NULL || lenp == NULL)
2169 return((unsigned long)-1);
2170 if (*cpp != NULL && *lenp < 7)
2171 return((unsigned long)-1);
2172 /*
2173 * Decide whether we have a buffer passed to us,
2174 * or if we need to use our own static buffer.
2175 */
2176 if (*cpp) {
2177 lsrp = *cpp;
2178 lsrep = lsrp + *lenp;
2179 }
2180 else {
2181 *cpp = lsrp = lsr;
2182 lsrep = lsrp + 44;
2183 }
2184
2185 cp = arg;
2186
2187 /*
2188 * Next, decide whether we have a loose source
2189 * route or a strict source route, and fill in
2190 * the begining of the option.
2191 */
2192 if (*cp == '!') {
2193 cp++;
2194 *lsrp++ = IPOPT_SSRR;
2195 }
2196 else *lsrp++ = IPOPT_LSRR;
2197
2198 if (*cp != '@')
2199 return((unsigned long)-1);
2200
2201 lsrp++; /* skip over length, we'll fill it in later */
2202 *lsrp++ = 4;
2203
2204 cp++;
2205
2206 sin_addr.s_addr = 0;
2207
2208 for (c = 0;;) {
2209 if (c == ':')
2210 cp2 = 0;
2211 else for (cp2 = cp; (c = *cp2) != 0; cp2++) {
2212 if (c == ',') {
2213 *cp2++ = '\0';
2214 if (*cp2 == '@')
2215 cp2++;
2216 } else if (c == '@') {
2217 *cp2++ = '\0';
2218 } else if (c == ':') {
2219 *cp2++ = '\0';
2220 } else
2221 continue;
2222 break;
2223 }
2224 if (!c)
2225 cp2 = 0;
2226
2227 if (inet_aton(cp, &sin_addr)) ; /* nothing */
2228 else if ((host = gethostbyname(cp))!=NULL) {
2229 if (host->h_length > (int)sizeof(sin_addr)) {
2230 host->h_length = sizeof(sin_addr);
2231 }
2232#if defined(h_addr)
2233 memcpy(&sin_addr, host->h_addr_list[0], host->h_length);
2234#else
2235 memcpy(&sin_addr, host->h_addr, host->h_length);
2236#endif
2237 } else {
2238 *cpp = cp;
2239 return(0);
2240 }
2241 memcpy(lsrp, (char *)&sin_addr, 4);
2242 lsrp += 4;
2243 if (cp2)
2244 cp = cp2;
2245 else
2246 break;
2247 /*
2248 * Check to make sure there is space for next address
2249 */
2250 if (lsrp + 4 > lsrep)
2251 return((unsigned long)-1);
2252 }
2253 if ((*(*cpp+IPOPT_OLEN) = lsrp - *cpp) <= 7) {
2254 *cpp = 0;
2255 *lenp = 0;
2256 return((unsigned long)-1);
2257 }
2258 *lsrp++ = IPOPT_NOP; /* 32 bit word align it */
2259 *lenp = lsrp - *cpp;
2260 return(sin_addr.s_addr);
2261}
2262#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/defines.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/defines.h
new file mode 100644
index 0000000..2784400
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/defines.h
@@ -0,0 +1,52 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)defines.h 5.1 (Berkeley) 9/14/90
34 * $Id: defines.h,v 1.5 1996/08/04 23:44:43 dholland Exp $
35 */
36
37#define ENV_VAR NEW_ENV_VAR
38#define ENV_VALUE NEW_ENV_VALUE
39#define TELOPT_ENVIRON TELOPT_NEW_ENVIRON
40
41#define settimer(x) clocks.x = clocks.system++
42
43#if !defined(TN3270)
44#define SetIn3270()
45#endif
46
47/* Various modes */
48#define MODE_LOCAL_CHARS(m) ((m)&(MODE_EDIT|MODE_TRAPSIG))
49#define MODE_LOCAL_ECHO(m) ((m)&MODE_ECHO)
50#define MODE_COMMAND_LINE(m) ((m)==-1)
51
52#define CONTROL(x) ((x)&0x1f) /* CTRL(x) is not portable */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/depend.mk b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/depend.mk
new file mode 100644
index 0000000..fe6eaa0
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/depend.mk
@@ -0,0 +1,17 @@
1commands.o: commands.cc ring.h externs.h defines.h types.h genget.h \
2 environ.h proto.h ptrarray.h netlink.h
3main.o: main.cc ../version.h ring.h externs.h defines.h proto.h
4network.o: network.cc ring.h defines.h externs.h proto.h netlink.h
5ring.o: ring.cc ring.h
6sys_bsd.o: sys_bsd.cc ring.h defines.h externs.h types.h proto.h \
7 netlink.h terminal.h
8telnet.o: telnet.cc ring.h defines.h externs.h types.h environ.h \
9 proto.h ptrarray.h netlink.h terminal.h
10terminal.o: terminal.cc ring.h defines.h externs.h types.h proto.h \
11 terminal.h
12tn3270.o: tn3270.cc defines.h ring.h externs.h proto.h
13utilities.o: utilities.cc ring.h defines.h externs.h proto.h \
14 terminal.h
15genget.o: genget.cc genget.h
16environ.o: environ.cc ring.h defines.h externs.h environ.h array.h
17netlink.o: netlink.cc netlink.h proto.h ring.h
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/environ.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/environ.cc
new file mode 100644
index 0000000..62d45fe
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/environ.cc
@@ -0,0 +1,201 @@
1#include <unistd.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <arpa/telnet.h>
6#include "ring.h"
7#include "defines.h"
8#include "externs.h"
9#include "environ.h"
10#include "array.h"
11
12class enviro {
13 protected:
14 char *var; /* pointer to variable name */
15 char *value; /* pointer to variable's value */
16 int doexport; /* 1 -> export with default list of variables */
17
18 void clean() { if (var) delete []var; if (value) delete []value; }
19 public:
20 enviro() { var = value = NULL; doexport = 0; }
21 ~enviro() { clean(); }
22
23 const char *getname() const { return var; }
24 const char *getval() const { return value; }
25
26 void define(const char *vr, const char *vl) {
27 clean();
28 var = strcpy(new char[strlen(vr)+1], vr);
29 value = strcpy(new char[strlen(vl)+1], vl);
30 }
31
32 void clear() { clean(); var = value = NULL; }
33
34 void setexport(int ex) { doexport = ex; }
35 int getexport() const { return doexport; }
36};
37
38static array<enviro> vars;
39
40static enviro *env_find(const char *var) {
41 for (int i=0; i<vars.num(); i++) if (vars[i].getname()) {
42 if (!strcmp(vars[i].getname(), var))
43 return &vars[i];
44 }
45 return NULL;
46}
47
48static void env_put(const char *var, const char *val, int exp) {
49 enviro *ep = env_find(var);
50 if (!ep) {
51 int x = vars.num();
52 vars.setsize(x+1);
53 ep = &vars[x];
54 }
55 ep->define(var, val);
56 ep->setexport(exp);
57}
58
59static void env_copy(void) {
60 extern char **environ;
61
62 char *s;
63 int i;
64
65 for (i=0; environ[i]; i++) {
66 s = strchr(environ[i], '=');
67 if (s) {
68 *s=0;
69 env_put(environ[i], s+1, 0);
70 *s='=';
71 }
72 }
73}
74
75/*
76 * Special case for DISPLAY variable. If it is ":0.0" or
77 * "unix:0.0", we have to get rid of "unix" and insert our
78 * hostname.
79 */
80static void env_fix_display(void) {
81 enviro *ep = env_find("DISPLAY");
82 if (!ep) return;
83 ep->setexport(1);
84
85 if (strncmp(ep->getval(), ":", 1) && strncmp(ep->getval(), "unix:", 5)) {
86 return;
87 }
88 char hbuf[256];
89 const char *cp2 = strrchr(ep->getval(), ':');
90 int maxlen = sizeof(hbuf)-strlen(cp2)-1;
91 gethostname(hbuf, maxlen);
92 hbuf[maxlen] = 0; /* ensure null termination */
93
94 /*
95 * dholland 7/30/96 if not a FQDN ask DNS
96 */
97 if (!strchr(hbuf, '.')) {
98 struct hostent *h = gethostbyname(hbuf);
99 if (h) {
100 strncpy(hbuf, h->h_name, maxlen);
101 hbuf[maxlen] = 0; /* ensure null termination */
102 }
103 }
104
105 strcat(hbuf, cp2);
106
107 ep->define("DISPLAY", hbuf);
108}
109
110/*********************************************** interface ***********/
111
112void env_init(void) {
113 env_copy();
114 env_fix_display();
115
116 /*
117 * If USER is not defined, but LOGNAME is, then add
118 * USER with the value from LOGNAME. By default, we
119 * don't export the USER variable.
120 */
121 if (!env_find("USER")) {
122 enviro *ep = env_find("LOGNAME");
123 if (ep) env_put("USER", ep->getval(), 0);
124 }
125
126 enviro *ep = env_find("PRINTER");
127 if (ep) ep->setexport(1);
128}
129
130void env_define(const char *var, const char *value) {
131 env_put(var, value, 1);
132}
133
134void env_undefine(const char *var) {
135 enviro *ep = env_find(var);
136 if (ep) {
137 /*
138 * We don't make any effort to reuse cleared environment spaces.
139 * It's highly unlikely to be worth the trouble.
140 */
141 ep->clear();
142 }
143}
144
145void env_export(const char *var) {
146 enviro *ep = env_find(var);
147 if (ep) ep->setexport(1);
148}
149
150void env_unexport(const char *var) {
151 enviro *ep = env_find(var);
152 if (ep) ep->setexport(0);
153}
154
155void env_send(const char *var) {
156 if (my_state_is_wont(TELOPT_ENVIRON)) {
157 fprintf(stderr, "Cannot send '%s': Telnet ENVIRON option disabled\n",
158 var);
159 return;
160 }
161
162 enviro *ep = env_find(var);
163 if (!ep) {
164 fprintf(stderr, "Cannot send '%s': variable not defined\n", var);
165 return;
166 }
167 env_opt_start_info();
168 env_opt_add(ep->getname());
169 env_opt_end(0);
170}
171
172void env_list(void) {
173 for (int i=0; i<vars.num(); i++) if (vars[i].getname()) {
174 printf("%c %-20s %s\n", vars[i].getexport() ? '*' : ' ',
175 vars[i].getname(), vars[i].getval());
176 }
177}
178
179void env_iterate(int *iter, int /*exported_only*/) {
180 *iter = 0;
181}
182
183const char *env_next(int *iter, int exported_only) {
184 while (*iter>=0 && *iter<vars.num()) {
185 int k = (*iter)++;
186
187 if (!vars[k].getname()) continue; // deleted variable
188
189 if (vars[k].getexport() || !exported_only) {
190 return vars[k].getname();
191 }
192 }
193 return NULL;
194}
195
196const char *env_getvalue(const char *var, int exported_only) {
197 enviro *ep = env_find(var);
198 if (ep && (!exported_only || ep->getexport()))
199 return ep->getval();
200 return NULL;
201}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/environ.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/environ.h
new file mode 100644
index 0000000..81ad751
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/environ.h
@@ -0,0 +1,10 @@
1void env_define(const char *var, const char *val);
2void env_undefine(const char *var);
3void env_export(const char *var);
4void env_unexport(const char *);
5void env_send(const char *);
6void env_list(void);
7const char *env_getvalue(const char *, int exported_only);
8
9void env_iterate(int *, int exported_only);
10const char *env_next(int *, int exported_only);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/externs.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/externs.h
new file mode 100644
index 0000000..955df79
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/externs.h
@@ -0,0 +1,365 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)externs.h 5.3 (Berkeley) 3/22/91
34 * $Id: externs.h,v 1.20 1999/08/19 09:34:15 dholland Exp $
35 */
36
37#ifndef BSD
38#define BSD 43
39#endif
40
41#include <stdio.h>
42#include <setjmp.h>
43#include <sys/ioctl.h>
44#include <features.h>
45#include <termios.h>
46
47#if defined(NO_CC_T)
48typedef unsigned char cc_t;
49#endif
50
51#ifdef __linux__
52#include <unistd.h> /* get _POSIX_VDISABLE */
53#endif
54
55#ifndef _POSIX_VDISABLE
56#error "Please fix externs.h to define _POSIX_VDISABLE"
57#endif
58
59#define SUBBUFSIZE 256
60
61extern int autologin; /* Autologin enabled */
62extern int skiprc; /* Don't process the ~/.telnetrc file */
63extern int eight; /* use eight bit mode (binary in and/or out */
64extern int flushout; /* flush output */
65extern int connected; /* Are we connected to the other side? */
66extern int globalmode; /* Mode tty should be in */
67extern int In3270; /* Are we in 3270 mode? */
68extern int telnetport; /* Are we connected to the telnet port? */
69extern int localflow; /* Flow control handled locally */
70extern int localchars; /* we recognize interrupt/quit */
71extern int donelclchars; /* the user has set "localchars" */
72extern int showoptions;
73
74extern int crlf; /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
75extern int autoflush; /* flush output when interrupting? */
76extern int autosynch; /* send interrupt characters with SYNCH? */
77extern int SYNCHing; /* Is the stream in telnet SYNCH mode? */
78extern int donebinarytoggle; /* the user has put us in binary */
79extern int dontlecho; /* do we suppress local echoing right now? */
80extern int crmod;
81//extern int netdata; /* Print out network data flow */
82//extern int prettydump; /* Print "netdata" output in user readable format */
83extern int debug; /* Debug level */
84
85#ifdef TN3270
86extern int cursesdata; /* Print out curses data flow */
87#endif /* unix and TN3270 */
88
89extern cc_t escapechar; /* Escape to command mode */
90extern cc_t rlogin; /* Rlogin mode escape character */
91#ifdef KLUDGELINEMODE
92extern cc_t echoc; /* Toggle local echoing */
93#endif
94
95extern char *prompt; /* Prompt for command. */
96
97extern char doopt[];
98extern char dont[];
99extern char will[];
100extern char wont[];
101extern char options[]; /* All the little options */
102extern char *hostname; /* Who are we connected to? */
103
104/*
105 * We keep track of each side of the option negotiation.
106 */
107
108#define MY_STATE_WILL 0x01
109#define MY_WANT_STATE_WILL 0x02
110#define MY_STATE_DO 0x04
111#define MY_WANT_STATE_DO 0x08
112
113/*
114 * Macros to check the current state of things
115 */
116
117#define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
118#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
119#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
120#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
121
122#define my_state_is_dont(opt) (!my_state_is_do(opt))
123#define my_state_is_wont(opt) (!my_state_is_will(opt))
124#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
125#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
126
127#define set_my_state_do(opt) {options[opt] |= MY_STATE_DO;}
128#define set_my_state_will(opt) {options[opt] |= MY_STATE_WILL;}
129#define set_my_want_state_do(opt) {options[opt] |= MY_WANT_STATE_DO;}
130#define set_my_want_state_will(opt) {options[opt] |= MY_WANT_STATE_WILL;}
131
132#define set_my_state_dont(opt) {options[opt] &= ~MY_STATE_DO;}
133#define set_my_state_wont(opt) {options[opt] &= ~MY_STATE_WILL;}
134#define set_my_want_state_dont(opt) {options[opt] &= ~MY_WANT_STATE_DO;}
135#define set_my_want_state_wont(opt) {options[opt] &= ~MY_WANT_STATE_WILL;}
136
137/*
138 * Make everything symmetric
139 */
140
141#define HIS_STATE_WILL MY_STATE_DO
142#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
143#define HIS_STATE_DO MY_STATE_WILL
144#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
145
146#define his_state_is_do my_state_is_will
147#define his_state_is_will my_state_is_do
148#define his_want_state_is_do my_want_state_is_will
149#define his_want_state_is_will my_want_state_is_do
150
151#define his_state_is_dont my_state_is_wont
152#define his_state_is_wont my_state_is_dont
153#define his_want_state_is_dont my_want_state_is_wont
154#define his_want_state_is_wont my_want_state_is_dont
155
156#define set_his_state_do set_my_state_will
157#define set_his_state_will set_my_state_do
158#define set_his_want_state_do set_my_want_state_will
159#define set_his_want_state_will set_my_want_state_do
160
161#define set_his_state_dont set_my_state_wont
162#define set_his_state_wont set_my_state_dont
163#define set_his_want_state_dont set_my_want_state_wont
164#define set_his_want_state_wont set_my_want_state_dont
165
166
167extern FILE *NetTrace; /* Where debugging output goes */
168extern char NetTraceFile[]; /* Name of file where debugging output goes */
169
170void SetNetTrace(const char *); /* Function to change where debugging goes */
171
172extern sigjmp_buf peerdied;
173extern sigjmp_buf toplevel; /* For error conditions. */
174
175void command(int, const char *, int);
176void Dump (int, char *, int);
177void init_3270 (void);
178void printoption(const char *, int, int);
179void printsub (int, unsigned char *, int);
180void sendnaws (void);
181void setconnmode(int);
182void setcommandmode (void);
183void setneturg (void);
184void sys_telnet_init (void);
185void telnet(const char *);
186void tel_enter_binary(int);
187void TerminalFlushOutput(void);
188void TerminalNewMode(int);
189void TerminalRestoreState(void);
190void TerminalSaveState(void);
191void tninit(void);
192void upcase(char *);
193void willoption(int);
194void wontoption(int);
195
196void lm_will(unsigned char *, int);
197void lm_wont(unsigned char *, int);
198void lm_do(unsigned char *, int);
199void lm_dont(unsigned char *, int);
200void lm_mode(unsigned char *, int, int);
201
202void slc_init(void);
203void slcstate(void);
204void slc_mode_export(void);
205void slc_mode_import(int);
206void slc_import(int);
207void slc_export(void);
208void slc(unsigned char *, int);
209void slc_check(void);
210void slc_start_reply(void);
211void slc_add_reply(int, int, int);
212void slc_end_reply(void);
213int slc_update(void);
214
215void env_opt(unsigned char *, int);
216void env_opt_start(void);
217void env_opt_start_info(void);
218void env_opt_add(const char *);
219void env_opt_end(int);
220
221int get_status(const char *, const char *);
222int dosynch(void);
223
224cc_t *tcval(int);
225
226//#if 0
227extern struct termios new_tc;
228
229#define termEofChar new_tc.c_cc[VEOF]
230#define termEraseChar new_tc.c_cc[VERASE]
231#define termIntChar new_tc.c_cc[VINTR]
232#define termKillChar new_tc.c_cc[VKILL]
233#define termQuitChar new_tc.c_cc[VQUIT]
234
235#ifndef VSUSP
236extern cc_t termSuspChar;
237#else
238#define termSuspChar new_tc.c_cc[VSUSP]
239#endif
240
241#if defined(VFLUSHO) && !defined(VDISCARD)
242#define VDISCARD VFLUSHO
243#endif
244#ifndef VDISCARD
245extern cc_t termFlushChar;
246#else
247#define termFlushChar new_tc.c_cc[VDISCARD]
248#endif
249
250#ifndef VWERASE
251extern cc_t termWerasChar;
252#else
253#define termWerasChar new_tc.c_cc[VWERASE]
254#endif
255
256#ifndef VREPRINT
257extern cc_t termRprntChar;
258#else
259#define termRprntChar new_tc.c_cc[VREPRINT]
260#endif
261
262#ifndef VLNEXT
263extern cc_t termLiteralNextChar;
264#else
265#define termLiteralNextChar new_tc.c_cc[VLNEXT]
266#endif
267
268#ifndef VSTART
269extern cc_t termStartChar;
270#else
271#define termStartChar new_tc.c_cc[VSTART]
272#endif
273
274#ifndef VSTOP
275extern cc_t termStopChar;
276#else
277#define termStopChar new_tc.c_cc[VSTOP]
278#endif
279
280#ifndef VEOL
281extern cc_t termForw1Char;
282#else
283#define termForw1Char new_tc.c_cc[VEOL]
284#endif
285
286#ifndef VEOL2
287extern cc_t termForw2Char;
288#else
289#define termForw2Char new_tc.c_cc[VEOL]
290#endif
291
292#ifndef VSTATUS
293extern cc_t termAytChar;
294#else
295#define termAytChar new_tc.c_cc[VSTATUS]
296#endif
297
298//#endif /* 0 */
299
300//#if 0
301#if !defined(CRAY) || defined(__STDC__)
302#define termEofCharp &termEofChar
303#define termEraseCharp &termEraseChar
304#define termIntCharp &termIntChar
305#define termKillCharp &termKillChar
306#define termQuitCharp &termQuitChar
307#define termSuspCharp &termSuspChar
308#define termFlushCharp &termFlushChar
309#define termWerasCharp &termWerasChar
310#define termRprntCharp &termRprntChar
311#define termLiteralNextCharp &termLiteralNextChar
312#define termStartCharp &termStartChar
313#define termStopCharp &termStopChar
314#define termForw1Charp &termForw1Char
315#define termForw2Charp &termForw2Char
316#define termAytCharp &termAytChar
317#else
318 /* Work around a compiler bug */
319#define termEofCharp 0
320#define termEraseCharp 0
321#define termIntCharp 0
322#define termKillCharp 0
323#define termQuitCharp 0
324#define termSuspCharp 0
325#define termFlushCharp 0
326#define termWerasCharp 0
327#define termRprntCharp 0
328#define termLiteralNextCharp 0
329#define termStartCharp 0
330#define termStopCharp 0
331#define termForw1Charp 0
332#define termForw2Charp 0
333#define termAytCharp 0
334#endif
335
336//#endif /* 0 */
337
338
339/* Ring buffer structures which are shared */
340
341extern ringbuf netoring;
342extern ringbuf netiring;
343extern ringbuf ttyoring;
344extern ringbuf ttyiring;
345
346/* Tn3270 section */
347#if defined(TN3270)
348
349extern int HaveInput; /* Whether an asynchronous I/O indication came in */
350extern int noasynchtty; /* Don't do signals on I/O (SIGURG, SIGIO) */
351extern int noasynchnet; /* Don't do signals on I/O (SIGURG, SIGIO) */
352extern int sigiocount; /* Count of SIGIO receptions */
353extern int shell_active; /* Subshell is active */
354
355extern char *Ibackp; /* Oldest byte of 3270 data */
356extern char Ibuf[]; /* 3270 buffer */
357extern char *Ifrontp; /* Where next 3270 byte goes */
358extern char tline[];
359extern char *transcom; /* Transparent command */
360
361void settranscom(int, char**);
362int shell(int, char**);
363void inputAvailable(void);
364
365#endif /* defined(TN3270) */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/fdset.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/fdset.h
new file mode 100644
index 0000000..7542166
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/fdset.h
@@ -0,0 +1,50 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)fdset.h 5.1 (Berkeley) 9/14/90
34 * $Id: fdset.h,v 1.1 1996/07/16 05:17:22 dholland Exp $
35 */
36
37/*
38 * The following is defined just in case someone should want to run
39 * this telnet on a 4.2 system.
40 *
41 */
42
43#ifndef FD_SETSIZE
44
45#define FD_SET(n, p) ((p)->fds_bits[0] |= (1<<(n)))
46#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1<<(n)))
47#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1<<(n)))
48#define FD_ZERO(p) ((p)->fds_bits[0] = 0)
49
50#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/general.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/general.h
new file mode 100644
index 0000000..1d9df66
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/general.h
@@ -0,0 +1,46 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)general.h 5.2 (Berkeley) 3/1/91
34 * $Id: general.h,v 1.1 1996/07/16 05:17:22 dholland Exp $
35 */
36
37/*
38 * Some general definitions.
39 */
40
41
42#define numberof(x) (sizeof x/sizeof x[0])
43#define highestof(x) (numberof(x)-1)
44
45#define ClearElement(x) memset((char *)&x, 0, sizeof x)
46#define ClearArray(x) memset((char *)x, 0, sizeof x)
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/genget.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/genget.cc
new file mode 100644
index 0000000..3f835b3
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/genget.cc
@@ -0,0 +1,91 @@
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)genget.c 5.1 (Berkeley) 2/28/91
36 */
37char gg_rcsid[] =
38 "$Id: genget.cc,v 1.3 1996/07/26 09:54:09 dholland Exp $";
39
40#include <string.h>
41#include <ctype.h>
42
43#include "genget.h"
44
45#define LOWER(x) (isupper(x) ? tolower(x) : (x))
46/*
47 * The prefix function returns 0 if *s1 is not a prefix
48 * of *s2. If *s1 exactly matches *s2, the negative of
49 * the length is returned. If *s1 is a prefix of *s2,
50 * the length of *s1 is returned.
51 */
52int isprefix(const char *s1, const char *s2) {
53 const char *os1;
54 char c1, c2;
55
56 if (*s1 == 0) return -1;
57
58 os1 = s1;
59 c1 = *s1;
60 c2 = *s2;
61
62 while (LOWER(c1) == LOWER(c2)) {
63 if (c1 == 0) break;
64 c1 = *++s1;
65 c2 = *++s2;
66 }
67 if (*s1) return 0;
68 return *s2 ? (s1 - os1) : (os1 - s1);
69}
70
71/*
72 * name: name to match
73 * table: name entry in table
74 */
75char **genget(const char *name, char **table, int stlen) {
76 char **c, **found;
77 int n;
78
79 if (!name) return NULL;
80
81 found = NULL;
82 for (c = table; *c; c = (char **)((char *)c + stlen)) {
83 n = isprefix(name, *c);
84 if (n == 0) continue;
85 if (n < 0) return c; /* exact match */
86 if (found) return (char **)AMBIGUOUS;
87 found = c;
88 }
89 return found;
90}
91
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/genget.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/genget.h
new file mode 100644
index 0000000..891a42f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/genget.h
@@ -0,0 +1,5 @@
1int isprefix(const char *, const char *);
2char **genget(const char *, char **, int);
3
4#define AMBIGUOUS ((void *)1)
5#define HELP ((void *)2)
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/main.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/main.cc
new file mode 100644
index 0000000..97028d9
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/main.cc
@@ -0,0 +1,275 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34char copyright[] =
35 "@(#) Copyright (c) 1988, 1990 Regents of the University of California.\n"
36 "All rights reserved.\n";
37
38/*
39 * From: @(#)main.c 5.4 (Berkeley) 3/22/91
40 */
41char main_rcsid[] =
42 "$Id: main.cc,v 1.14 1999/08/01 05:06:37 dholland Exp $";
43
44#include "../version.h"
45
46#include <sys/types.h>
47#include <getopt.h>
48#include <stdlib.h>
49#include <string.h>
50#include <netdb.h>
51
52#include "ring.h"
53#include "externs.h"
54#include "defines.h"
55#include "proto.h"
56
57/*
58 * Initialize variables.
59 */
60void
61tninit(void)
62{
63 init_terminal();
64
65 init_network();
66
67 init_telnet();
68
69 init_sys();
70
71#if defined(TN3270)
72 init_3270();
73#endif
74}
75
76/*
77 * note: -x should mean use encryption
78 * -k <realm> to set kerberos realm
79 * -K don't auto-login
80 * -X <atype> disable specified auth type
81 */
82void usage(void) {
83 fprintf(stderr, "Usage: %s %s%s%s%s\n",
84 prompt,
85 "[-4] [-6] [-8] [-E] [-L] [-a] [-d] [-e char] [-l user]",
86 "\n\t[-n tracefile]",
87#ifdef TN3270
88 "\n\t"
89 "[-noasynch] [-noasynctty] [-noasyncnet] [-r] [-t transcom]\n\t",
90#else
91 " [-r] ",
92#endif
93 "[host-name [port]]"
94 );
95 exit(1);
96}
97
98/*
99 * main. Parse arguments, invoke the protocol or command parser.
100 */
101
102int
103main(int argc, char *argv[])
104{
105 extern char *optarg;
106 extern int optind;
107 int ch;
108 char *user;
109 int family;
110
111 tninit(); /* Clear out things */
112#if defined(CRAY) && !defined(__STDC__)
113 _setlist_init(); /* Work around compiler bug */
114#endif
115
116 TerminalSaveState();
117
118 if ((prompt = strrchr(argv[0], '/'))!=NULL)
119 ++prompt;
120 else
121 prompt = argv[0];
122
123 user = NULL;
124 family = 0;
125
126 rlogin = (strncmp(prompt, "rlog", 4) == 0) ? '~' : _POSIX_VDISABLE;
127 autologin = -1;
128
129 while ((ch = getopt(argc, argv, "468EKLS:X:ade:k:l:n:rt:x")) != EOF) {
130 switch(ch) {
131 case '4':
132 family = AF_INET;
133 break;
134 case '6':
135#ifdef AF_INET6
136 family = AF_INET6;
137#else
138 fputs("IPv6 unsupported\n", stderr);
139#endif
140 break;
141 case '8':
142 eight = 3; /* binary output and input */
143 break;
144 case 'E':
145 rlogin = escapechar = _POSIX_VDISABLE;
146 break;
147 case 'K':
148 //autologin = 0;
149 break;
150 case 'L':
151 eight |= 2; /* binary output only */
152 break;
153 case 'S':
154 {
155#ifdef HAS_GETTOS
156 extern int tos;
157
158 if ((tos = parsetos(optarg, "tcp")) < 0)
159 fprintf(stderr, "%s%s%s%s\n",
160 prompt, ": Bad TOS argument '",
161 optarg,
162 "; will try to use default TOS");
163#else
164 fprintf(stderr,
165 "%s: Warning: -S ignored, no parsetos() support.\n",
166 prompt);
167#endif
168 }
169 break;
170 case 'X':
171 // disable authentication type "optarg"
172 break;
173 case 'a':
174 autologin = 1;
175 break;
176 case 'c':
177 skiprc = 1;
178 break;
179 case 'd':
180 debug = 1;
181 break;
182 case 'e':
183 set_escape_char(optarg);
184 break;
185 case 'k':
186 fprintf(stderr,
187 "%s: -k ignored, no Kerberos V4 support.\n",
188 prompt);
189 break;
190 case 'l':
191 autologin = 1;
192 user = optarg;
193 break;
194 case 'n':
195#ifdef TN3270
196 /* distinguish between "-n oasynch" and "-noasynch" */
197 if (argv[optind - 1][0] == '-' && argv[optind - 1][1]
198 == 'n' && argv[optind - 1][2] == 'o') {
199 if (!strcmp(optarg, "oasynch")) {
200 noasynchtty = 1;
201 noasynchnet = 1;
202 } else if (!strcmp(optarg, "oasynchtty"))
203 noasynchtty = 1;
204 else if (!strcmp(optarg, "oasynchnet"))
205 noasynchnet = 1;
206 } else
207#endif /* TN3270 */
208 SetNetTrace(optarg);
209 break;
210 case 'r':
211 rlogin = '~';
212 break;
213 case 't':
214#ifdef TN3270
215 transcom = tline;
216 (void)strcpy(transcom, optarg);
217#else
218 fprintf(stderr,
219 "%s: Warning: -t ignored, no TN3270 support.\n",
220 prompt);
221#endif
222 break;
223 case 'x':
224 fprintf(stderr,
225 "%s: -x ignored, no encryption support.\n",
226 prompt);
227 break;
228 case '?':
229 default:
230 usage();
231 /* NOTREACHED */
232 }
233 }
234 if (autologin == -1)
235 autologin = (rlogin == _POSIX_VDISABLE) ? 0 : 1;
236
237 argc -= optind;
238 argv += optind;
239
240 if (argc) {
241 const char *args[7];
242 const char **volatile argp = args;
243
244 if (argc > 2)
245 usage();
246 *argp++ = prompt;
247 if (user) {
248 *argp++ = "-l";
249 *argp++ = user;
250 }
251 if (family) {
252 *argp++ = family == AF_INET ? "-4" : "-6";
253 }
254 *argp++ = argv[0]; /* host */
255 if (argc > 1)
256 *argp++ = argv[1]; /* port */
257 *argp = 0;
258
259 if (sigsetjmp(toplevel, 1) != 0)
260 Exit(0);
261 if (tn(argp - args, args) == 1)
262 return (0);
263 else
264 return (1);
265 }
266 (void)sigsetjmp(toplevel, 1);
267 for (;;) {
268#ifdef TN3270
269 if (shell_active)
270 shell_continue();
271 else
272#endif
273 command(1, 0, 0);
274 }
275}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/netlink.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/netlink.cc
new file mode 100644
index 0000000..95c0d74
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/netlink.cc
@@ -0,0 +1,177 @@
1#include <errno.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <stdlib.h>
5#include <sys/socket.h>
6#include <netinet/in.h>
7#include <arpa/inet.h>
8#include <sys/ioctl.h>
9#include <sys/time.h>
10#include <netdb.h>
11#include "netlink.h"
12#include "proto.h"
13#include "ring.h"
14
15/* In Linux, this is an enum */
16#if defined(__linux__) || defined(IPPROTO_IP)
17#define HAS_IPPROTO_IP
18#endif
19
20netlink nlink;
21
22class netchannel : public ringbuf::source {
23 public:
24 virtual int read(char *buf, int maxlen) {
25 int net = nlink.getfd();
26 int l = recv(net, buf, maxlen, 0);
27 if (l<0 && errno == EWOULDBLOCK) l = 0;
28 return l;
29 }
30};
31
32class netchannel2 : public datasink {
33 public:
34 virtual int write(const char *buf, int len) {
35 int r = nlink.send(buf, len, 0);
36 if (r==-1 && (errno==ENOBUFS || errno==EWOULDBLOCK)) return 0;
37 return r;
38 }
39 virtual int writeurg(const char *buf, int len) {
40 /*
41 * In 4.2 (and 4.3) systems, there is some question about
42 * what byte in a sendOOB operation is the "OOB" data.
43 * To make ourselves compatible, we only send ONE byte
44 * out of band, the one WE THINK should be OOB (though
45 * we really have more the TCP philosophy of urgent data
46 * rather than the Unix philosophy of OOB data).
47 */
48 if (len==0) return 0;
49 int r = nlink.send(buf, 1, MSG_OOB);
50 if (r==-1 && (errno==ENOBUFS || errno==EWOULDBLOCK)) r = 0;
51 if (r<=0) return r;
52 int rr = nlink.send(buf+1, len-r, 0);
53 if (rr==-1 && (errno==ENOBUFS || errno==EWOULDBLOCK)) rr = 0;
54 if (rr<=0) return r; /* less than ideal */
55 return r+rr;
56 }
57};
58
59static netchannel chan;
60static netchannel2 chan2;
61datasink *netsink = &chan2;
62ringbuf::source *netsrc = &chan;
63
64
65netlink::netlink() { net = -1; }
66netlink::~netlink() { ::close(net); }
67
68
69int netlink::setdebug(int debug) {
70 if (net > 0 &&
71 (setsockopt(net, SOL_SOCKET, SO_DEBUG, &debug, sizeof(debug))) < 0) {
72 perror("setsockopt (SO_DEBUG)");
73 }
74 return 1;
75}
76
77void netlink::close(int doshutdown) {
78 if (doshutdown) {
79 shutdown(net, 2);
80 }
81 ::close(net);
82}
83
84int netlink::connect(int debug, struct addrinfo *addr,
85 char *srcroute, int srlen, int tos)
86{
87 int on=1;
88
89 net = socket(addr->ai_family, SOCK_STREAM, 0);
90 if (net < 0) {
91 if (errno == EAFNOSUPPORT || errno == EINVAL)
92 return 1;
93 perror("telnet: socket");
94 return 0;
95 }
96
97#if defined(IP_OPTIONS) && defined(HAS_IPPROTO_IP)
98 if (srcroute) {
99 if (addr->ai_family != AF_INET)
100 fputs("Source route is only supported for IPv4\n", stderr);
101 if (setsockopt(net, IPPROTO_IP, IP_OPTIONS, srcroute, srlen) < 0)
102 perror("setsockopt (IP_OPTIONS)");
103 }
104#endif
105
106#if defined(HAS_IPPROTO_IP) && defined(IP_TOS)
107#if defined(HAS_GETTOS)
108 struct tosent *tp;
109 if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
110 tos = tp->t_tos;
111#endif
112 if (tos < 0) tos = 020; /* Low Delay bit */
113 if (tos && (setsockopt(net, IPPROTO_IP, IP_TOS, &tos, sizeof(int)) < 0)
114 && (errno != ENOPROTOOPT) && (errno != EOPNOTSUPP))
115 perror("telnet: setsockopt (IP_TOS) (ignored)");
116#endif /* defined(IPPROTO_IP) && defined(IP_TOS) */
117
118 if (debug && setsockopt(net, SOL_SOCKET, SO_DEBUG, &on, sizeof(on)) < 0) {
119 perror("setsockopt (SO_DEBUG)");
120 }
121
122 if (::connect(net, addr->ai_addr, addr->ai_addrlen) < 0) {
123 return 1;
124 }
125 return 2;
126}
127
128
129void netlink::oobinline() {
130 int on=1;
131
132 /* Systems without SO_OOBINLINE probably won't work */
133 if (setsockopt(net, SOL_SOCKET, SO_OOBINLINE, &on, sizeof(on)) == -1) {
134 perror("setsockopt");
135 }
136}
137
138
139/*
140 * Check to see if any out-of-band data exists on a socket (for
141 * Telnet "synch" processing).
142 */
143
144int netlink::stilloob(void) {
145 static struct timeval timeout = { 0, 0 };
146 fd_set excepts;
147 int value;
148
149 do {
150 FD_ZERO(&excepts);
151 FD_SET(net, &excepts);
152 value = select(net+1, NULL, NULL, &excepts, &timeout);
153 } while ((value == -1) && (errno == EINTR));
154
155 if (value < 0) {
156 perror("select");
157 quit();
158 /* NOTREACHED */
159 }
160 if (FD_ISSET(net, &excepts)) {
161 return 1;
162 } else {
163 return 0;
164 }
165}
166
167int netlink::send(const char *s, int n, int f) {
168 return ::send(net, s, n, f);
169}
170
171void netlink::nonblock(int onoff) {
172 ioctl(net, FIONBIO, &onoff);
173}
174
175int netlink::getfd() {
176 return net;
177}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/netlink.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/netlink.h
new file mode 100644
index 0000000..095bac5
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/netlink.h
@@ -0,0 +1,25 @@
1
2class netlink {
3 protected:
4 int net;
5 public:
6 netlink();
7 ~netlink();
8
9 int connect(int debug, struct addrinfo *hostaddr,
10 char *srcroute, int srlen,
11 int tos);
12 void close(int doshutdown);
13
14 int setdebug(int debug);
15 void oobinline();
16 void nonblock(int onoff);
17
18 int stilloob();
19
20 int send(const char *buf, int len, int flags);
21
22 int getfd();
23};
24
25extern netlink nlink;
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/network.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/network.cc
new file mode 100644
index 0000000..0dcf3e2
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/network.cc
@@ -0,0 +1,92 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)network.c 5.2 (Berkeley) 3/1/91
36 */
37char net_rcsid[] =
38 "$Id: network.cc,v 1.15 1996/08/13 08:09:58 dholland Exp $";
39
40#include <sys/types.h>
41#include <sys/socket.h>
42#include <sys/time.h>
43#include <stdlib.h>
44#include <errno.h>
45#include <arpa/telnet.h>
46
47#include "ring.h"
48#include "defines.h"
49#include "externs.h"
50#include "proto.h"
51#include "netlink.h"
52
53ringbuf netoring;
54ringbuf netiring;
55
56/*
57 * Initialize internal network data structures.
58 */
59
60void init_network(void) {
61 if (netoring.init(2*BUFSIZ, netsink, NULL) != 1) {
62 exit(1);
63 }
64 if (netiring.init(BUFSIZ, NULL, netsrc) != 1) {
65 exit(1);
66 }
67 NetTrace = stdout;
68}
69
70
71/*
72 * netflush
73 * Send as much data as possible to the network,
74 * handling requests for urgent data.
75 *
76 * The return value indicates whether we did any
77 * useful work.
78 */
79
80
81int netflush(void) {
82 int r = netoring.flush();
83 if (r < -1) {
84 setcommandmode();
85 perror(hostname);
86 nlink.close(0);
87 netoring.clear_mark();
88 siglongjmp(peerdied, -1);
89 /*NOTREACHED*/
90 }
91 return r>0;
92}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/proto.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/proto.h
new file mode 100644
index 0000000..8be4a39
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/proto.h
@@ -0,0 +1,41 @@
1#if 0
2void auth_encrypt_connect(void);
3void auth_encrypt_init(void);
4#endif
5
6void Exit(int);
7void ExitString(const char *, int);
8int TerminalAutoFlush(void);
9void TerminalDefaultChars(void);
10int TerminalSpecialChars(int);
11void TerminalSpeeds(long *ispeed, long *ospeed);
12int TerminalWindowSize(long *rows, long *cols);
13void auth_encrypt_user(char *);
14void auth_name(unsigned char *, int);
15void auth_printsub(unsigned char *, int, unsigned char *, int);
16void cmdrc(const char *m1, const char *m2);
17void env_init(void);
18int getconnmode(void);
19void init_network(void);
20void init_sys(void);
21void init_telnet(void);
22void init_terminal(void);
23int netflush(void);
24void optionstatus(void);
25int process_rings(int, int, int, int, int, int);
26void quit(void);
27int rlogin_susp(void);
28int send_tncmd(int (*func)(int, int), const char *cmd, const char *name);
29void sendeof(void);
30void sendsusp(void);
31void set_escape_char(char *);
32void tel_leave_binary(int);
33int telrcv(void);
34int tn(int argc, const char *argv[]);
35int ttyflush(int);
36void sendayt(void);
37void ayt_status(int);
38void ayt(int sig);
39
40/* commands.c */
41void cmdtab_init(void);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ptrarray.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ptrarray.h
new file mode 100644
index 0000000..3a5d12f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ptrarray.h
@@ -0,0 +1,92 @@
1//
2// File: ptrarray.h
3// Date: 16-Jul-95
4// Description: Array of pointers
5//
6/*
7 * Copyright (c) 1995 David A. Holland.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Author nor the names of any contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef PTRARRAY_H
36#define PTRARRAY_H
37
38#ifndef assert
39#include <assert.h>
40#endif
41
42#ifndef NULL
43#define NULL 0
44#endif
45
46template <class T>
47class ptrarray {
48 protected:
49 T **v;
50 int n, max;
51 void reallocto(int x) {
52 while (max<x) max += 16;
53 T **q = new T* [max];
54 for (int i=0; i<n; i++) q[i] = v[i];
55 delete []v;
56 v = q;
57 }
58 public:
59 ptrarray() { v=NULL; n=max=0; }
60 ~ptrarray() { delete []v; }
61
62 int num() const { return n; }
63
64 void setsize(int newsize) {
65 if (newsize>max) reallocto(newsize);
66 if (newsize>n) {
67 for (int i=n; i<newsize; i++) v[i] = NULL;
68 }
69 else {
70 // do nothing
71 }
72 n = newsize;
73 }
74
75 T *&operator [] (int ix) const {
76 assert(ix>=0 && ix<n);
77 return v[ix];
78 }
79
80 int add(T *val) {
81 int ix = n;
82 setsize(n+1);
83 v[ix] = val;
84 return ix;
85 }
86
87 void push(T *val) { add(val); }
88
89 void pop() { setsize(n-1); }
90};
91
92#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ring.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ring.cc
new file mode 100644
index 0000000..772c6c5
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ring.cc
@@ -0,0 +1,213 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)ring.c 5.2 (Berkeley) 3/1/91
36 */
37char ring_rcsid[] =
38 "$Id: ring.cc,v 1.23 2000/07/23 03:25:09 dholland Exp $";
39
40/*
41 * This defines a structure for a ring buffer.
42 */
43
44#include <stdio.h>
45#include <stdarg.h>
46#include <assert.h>
47#include "ring.h"
48
49class devnull : public datasink {
50 virtual int write(const char *, int n) { return n; }
51 virtual int writeurg(const char *, int n) { return n; }
52};
53static devnull nullsink_obj;
54datasink *nullsink = &nullsink_obj;
55
56
57
58int ringbuf::init(int sz, datasink *sink, source *src) {
59 buf = new char[sz];
60 size = sz;
61 head = tail = 0;
62 count = 0;
63 marked = -1;
64
65 binding = sink;
66 srcbinding = src;
67
68 return 1;
69}
70
71/////////////////////////////////////////////////// consume //////////////
72
73int ringbuf::gets(char *rbuf, int max) {
74 int i=0, ch;
75 assert(max>0);
76 while (getch(&ch)>0 && i<max-1) rbuf[i++] = ch;
77 rbuf[i]=0;
78 return i;
79}
80
81int ringbuf::getch(int *ch) {
82 int rv = 0;
83 if (count > 0) {
84 if (tail==marked) {
85 rv = 2;
86 marked = -1;
87 }
88 else rv = 1;
89 *ch = (unsigned char) buf[tail++];
90 if (tail>=size) tail -= size;
91 count--;
92 }
93 return rv; /* 0 = no more chars available */
94}
95
96void ringbuf::ungetch(int ch) {
97 int x = tail;
98 x--;
99 if (x<0) x += size;
100 int och = buf[x]; /* avoid sign-extension and other such problems */
101 if ((och&0xff) == (ch&0xff)) {
102 tail = x;
103 count++;
104 }
105 else {
106 //assert(!"Bad ungetch");
107 tail = x;
108 count++;
109 }
110}
111
112/*
113 * Return value:
114 * -2: Significant error occurred.
115 * -1: No useful work done, data waiting to go out.
116 * 0: No data was waiting, so nothing was done.
117 * 1: All waiting data was written out.
118 * n: Some data written, n-1 bytes left.
119 */
120int ringbuf::flush() {
121 assert(binding);
122 assert(count>=0);
123 if (count==0) return 0;
124
125 static int busy=0;
126 if (busy) {
127 return -1;
128 }
129 busy=1;
130
131 /* should always be true */
132 /* assert(((size+head-tail)%size)==count); */
133 /* Nope! The above fails if the buffer is full; then:
134 * head == tail (so LHS is 0), but count == size.
135 * The following formula should be better. --okir */
136 assert(((head - tail - count) % size) == 0);
137
138 while (count > 0) {
139 int bot = tail;
140 int top = head;
141 if (top < bot) top = size;
142 if (marked > bot) top = marked;
143 assert(top-bot > 0 && top-bot <= count);
144
145 int n;
146 if (marked==bot) n = binding->writeurg(buf+bot, top-bot);
147 else n = binding->write(buf+bot, top-bot);
148 if (n < 0) { busy=0; return -2; }
149 else if (n==0) { busy=0; return -1; }
150
151 if (marked==bot) marked = -1;
152 tail += n;
153 if (tail >= size) tail -= size;
154 count -= n;
155 assert(((size+head-tail)%size)==count);
156
157 if (n > 0 && n < top-bot) { busy=0; return n+1; }
158 /* otherwise (if we wrote all data) loop */
159 }
160 assert(((size+head-tail)%size)==count);
161 busy=0;
162 return 1;
163}
164
165
166/////////////////////////////////////////////////// supply //////////////
167
168void ringbuf::xprintf(const char *format, ...) {
169 char xbuf[256];
170 va_list ap;
171 va_start(ap, format);
172 int l = vsnprintf(xbuf, sizeof(xbuf), format, ap);
173 va_end(ap);
174 write(xbuf, l);
175}
176
177void ringbuf::write(const char *buffer, int ct) {
178 if (ct > size - count) {
179 // Oops. We're about to overflow our buffer.
180 // In practice this shouldn't ever actually happen.
181 // We could return a short count, but then we'd have to check
182 // and retry every call, which ranges somewhere between painful
183 // and impossible.
184 // Instead, we drop the data on the floor. This should only happen
185 // if (1) the tty hangs, (2) the network hangs while we're trying
186 // to send large volumes of data, or (3) massive internal logic errors.
187 fprintf(stderr, "\n\ntelnet: buffer overflow, losing data, sorry\n");
188 ct = size - count;
189 }
190 for (int i=0; i<ct; i++) {
191 buf[head++] = buffer[i];
192 if (head>=size) head -= size;
193 count++;
194 }
195}
196
197int ringbuf::read_source() {
198 int bot = head;
199 int top = tail-1; /* leave room for an ungetc */
200 if (top<0) top += size;
201 if (top < bot) top = size;
202
203 if (top==bot) return 0;
204
205 int l = srcbinding->read(buf+bot, top-bot);
206 if (l>=0) {
207 head += l;
208 if (head>=size) head -= size;
209 count += l;
210 }
211 if (l==0) l = -1;
212 return l;
213}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ring.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ring.h
new file mode 100644
index 0000000..049377e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/ring.h
@@ -0,0 +1,111 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)ring.h 5.2 (Berkeley) 3/1/91
34 * $Id: ring.h,v 1.13 1996/08/13 08:43:28 dholland Exp $
35 */
36
37class datasink {
38 public:
39 virtual ~datasink() {}
40 virtual int write(const char *buf, int len) = 0;
41 virtual int writeurg(const char *buf, int len) = 0;
42};
43
44/*
45 * This defines a structure for a ring buffer.
46 */
47class ringbuf {
48 public:
49 class source {
50 public:
51 virtual ~source() {}
52 virtual int read(char *buf, int len) = 0;
53 };
54 protected:
55 datasink *binding;
56 source *srcbinding;
57
58 char *buf;
59 int size; /* total size of buffer */
60 int head; /* next input character goes here */
61 int tail; /* next output character comes from here */
62 int count; /* chars presently stored in buffer */
63 // The buffer is empty when head==tail.
64
65 int marked; /* this character is marked */
66
67 public:
68 /////// consume end
69
70 // manual consume
71 int gets(char *buf, int max);
72 int getch(int *ch);
73 void ungetch(int ch);
74 int full_count() {
75 return count;
76 }
77
78 // automatic consume
79 int flush();
80
81 /////// supply end
82
83 // manual supply
84 void putch(char c) { write(&c, 1); }
85 void write(const char *buffer, int ct);
86 void xprintf(const char *format, ...);
87 int empty_count() { return size - count; }
88
89 // automatic supply
90 int read_source();
91
92 /////// others
93 void clear_mark() { marked = -1; }
94 void set_mark() { marked = head; }
95
96 int init(int size, datasink *sink, source *src);
97
98 datasink *setsink(datasink *nu) {
99 datasink *old = binding;
100 binding = nu;
101 return old;
102 }
103
104};
105
106extern datasink *netsink, *ttysink, *nullsink;
107extern ringbuf::source *netsrc, *ttysrc;
108
109#define NETADD(c) { netoring.putch(c); }
110#define NET2ADD(c1,c2) { NETADD(c1); NETADD(c2); }
111
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/sys_bsd.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/sys_bsd.cc
new file mode 100644
index 0000000..a8c9aab
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/sys_bsd.cc
@@ -0,0 +1,413 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)sys_bsd.c 5.2 (Berkeley) 3/1/91
36 */
37char bsd_rcsid[] =
38 "$Id: sys_bsd.cc,v 1.24 1999/09/28 16:29:24 dholland Exp $";
39
40/*
41 * The following routines try to encapsulate what is system dependent
42 * (at least between 4.x and dos) which is used in telnet.c.
43 */
44
45#include <fcntl.h>
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/socket.h>
49#include <signal.h>
50#include <errno.h>
51#include <unistd.h>
52#include <stdlib.h>
53#include <sys/ioctl.h>
54#include <arpa/telnet.h>
55
56#include "ring.h"
57
58#include "defines.h"
59#include "externs.h"
60#include "types.h"
61#include "proto.h"
62#include "netlink.h"
63#include "terminal.h"
64
65static fd_set ibits, obits, xbits;
66
67void init_sys(void)
68{
69 tlink_init();
70 FD_ZERO(&ibits);
71 FD_ZERO(&obits);
72 FD_ZERO(&xbits);
73
74 errno = 0;
75}
76
77
78#ifdef KLUDGELINEMODE
79extern int kludgelinemode;
80#endif
81/*
82 * TerminalSpecialChars()
83 *
84 * Look at an input character to see if it is a special character
85 * and decide what to do.
86 *
87 * Output:
88 *
89 * 0 Don't add this character.
90 * 1 Do add this character
91 */
92
93void intp(), sendbrk(), sendabort();
94
95int
96TerminalSpecialChars(int c)
97{
98 void xmitAO(), xmitEL(), xmitEC();
99
100 if (c == termIntChar) {
101 intp();
102 return 0;
103 } else if (c == termQuitChar) {
104#ifdef KLUDGELINEMODE
105 if (kludgelinemode)
106 sendbrk();
107 else
108#endif
109 sendabort();
110 return 0;
111 } else if (c == termEofChar) {
112 if (my_want_state_is_will(TELOPT_LINEMODE)) {
113 sendeof();
114 return 0;
115 }
116 return 1;
117 } else if (c == termSuspChar) {
118 sendsusp();
119 return(0);
120 } else if (c == termFlushChar) {
121 xmitAO(); /* Transmit Abort Output */
122 return 0;
123 } else if (!MODE_LOCAL_CHARS(globalmode)) {
124 if (c == termKillChar) {
125 xmitEL();
126 return 0;
127 } else if (c == termEraseChar) {
128 xmitEC(); /* Transmit Erase Character */
129 return 0;
130 }
131 }
132 return 1;
133}
134
135
136
137cc_t *tcval(int func) {
138 switch(func) {
139 case SLC_IP: return(&termIntChar);
140 case SLC_ABORT: return(&termQuitChar);
141 case SLC_EOF: return(&termEofChar);
142 case SLC_EC: return(&termEraseChar);
143 case SLC_EL: return(&termKillChar);
144 case SLC_XON: return(&termStartChar);
145 case SLC_XOFF: return(&termStopChar);
146 case SLC_FORW1: return(&termForw1Char);
147 case SLC_FORW2: return(&termForw2Char);
148#ifdef VDISCARD
149 case SLC_AO: return(&termFlushChar);
150#endif
151#ifdef VSUSP
152 case SLC_SUSP: return(&termSuspChar);
153#endif
154#ifdef VWERASE
155 case SLC_EW: return(&termWerasChar);
156#endif
157#ifdef VREPRINT
158 case SLC_RP: return(&termRprntChar);
159#endif
160#ifdef VLNEXT
161 case SLC_LNEXT: return(&termLiteralNextChar);
162#endif
163#ifdef VSTATUS
164 case SLC_AYT: return(&termAytChar);
165#endif
166
167 case SLC_SYNCH:
168 case SLC_BRK:
169 case SLC_EOR:
170 default:
171 return NULL;
172 }
173}
174
175#if defined(TN3270)
176void NetSigIO(int fd, int onoff) {
177 ioctl(fd, FIOASYNC, (char *)&onoff); /* hear about input */
178}
179
180void NetSetPgrp(int fd) {
181 int myPid;
182
183 myPid = getpid();
184 fcntl(fd, F_SETOWN, myPid);
185}
186#endif /*defined(TN3270)*/
187
188/*
189 * Various signal handling routines.
190 */
191
192#if 0
193static void deadpeer(int /*sig*/) {
194 setcommandmode();
195 siglongjmp(peerdied, -1);
196}
197#endif
198
199static void intr(int /*sig*/) {
200 if (localchars) {
201 intp();
202 }
203 else {
204#if 0
205 setcommandmode();
206 siglongjmp(toplevel, -1);
207#else
208 signal(SIGINT, SIG_DFL);
209 raise(SIGINT);
210#endif
211 }
212}
213
214static void intr2(int /*sig*/) {
215 if (localchars) {
216#ifdef KLUDGELINEMODE
217 if (kludgelinemode)
218 sendbrk();
219 else
220#endif
221 sendabort();
222 return;
223 }
224 signal(SIGQUIT, SIG_DFL);
225 raise(SIGQUIT);
226}
227
228#ifdef SIGWINCH
229static void sendwin(int /*sig*/) {
230 if (connected) {
231 sendnaws();
232 }
233}
234#endif
235
236#ifdef SIGINFO
237void ayt(int sig) {
238 (void)sig;
239
240 if (connected)
241 sendayt();
242 else
243 ayt_status(0);
244}
245#endif
246
247void sys_telnet_init(void) {
248 signal(SIGINT, intr);
249 signal(SIGQUIT, intr2);
250#if 0
251 signal(SIGPIPE, deadpeer);
252#endif
253#ifdef SIGWINCH
254 signal(SIGWINCH, sendwin);
255#endif
256#ifdef SIGINFO
257 signal(SIGINFO, ayt);
258#endif
259
260 setconnmode(0);
261
262 nlink.nonblock(1);
263
264#if defined(TN3270)
265 if (noasynchnet == 0) { /* DBX can't handle! */
266 NetSigIO(net, 1);
267 NetSetPgrp(net);
268 }
269#endif /* defined(TN3270) */
270
271 nlink.oobinline();
272}
273
274/*
275 * Process rings -
276 *
277 * This routine tries to fill up/empty our various rings.
278 *
279 * The parameter specifies whether this is a poll operation,
280 * or a block-until-something-happens operation.
281 *
282 * The return value is 1 if something happened, 0 if not.
283 */
284
285int process_rings(int netin, int netout, int netex, int ttyin, int ttyout,
286 int poll /* If 0, then block until something to do */)
287{
288 register int c, maxfd;
289 /* One wants to be a bit careful about setting returnValue
290 * to one, since a one implies we did some useful work,
291 * and therefore probably won't be called to block next
292 * time (TN3270 mode only).
293 */
294 int returnValue = 0;
295 static struct timeval TimeValue = { 0, 0 };
296
297 int net = nlink.getfd();
298 int tin = tlink_getifd();
299 int tout = tlink_getofd();
300
301 if (netout) {
302 FD_SET(net, &obits);
303 }
304 if (ttyout) {
305 FD_SET(tout, &obits);
306 }
307 if (ttyin) {
308 FD_SET(tin, &ibits);
309 }
310 if (netin) {
311 FD_SET(net, &ibits);
312 }
313 if (netex) {
314 FD_SET(net, &xbits);
315 }
316
317 maxfd = net;
318 if (maxfd < tin) maxfd=tin;
319 if (maxfd < tout) maxfd=tout;
320
321 if ((c = select(maxfd+1, &ibits, &obits, &xbits,
322 (poll == 0)? (struct timeval *)0 : &TimeValue)) < 0) {
323 if (c == -1) {
324 /*
325 * we can get EINTR if we are in line mode,
326 * and the user does an escape (TSTP), or
327 * some other signal generator.
328 */
329 if (errno == EINTR) {
330 return 0;
331 }
332#if defined(TN3270)
333 /*
334 * we can get EBADF if we were in transparent
335 * mode, and the transcom process died.
336 */
337 if (errno == EBADF) {
338 /*
339 * zero the bits (even though kernel does it)
340 * to make sure we are selecting on the right
341 * ones.
342 */
343 FD_ZERO(&ibits);
344 FD_ZERO(&obits);
345 FD_ZERO(&xbits);
346 return 0;
347 }
348#endif /* TN3270 */
349 /* I don't like this, does it ever happen? */
350 printf("sleep(5) from telnet, after select\r\n");
351 sleep(5);
352 }
353 return 0;
354 }
355
356 /*
357 * Any urgent data?
358 */
359 if (FD_ISSET(net, &xbits)) {
360 FD_CLR(net, &xbits);
361 SYNCHing = 1;
362 (void) ttyflush(1); /* flush already enqueued data */
363 }
364
365 /*
366 * Should flush output buffers first to make room for new input. --okir
367 */
368 if (FD_ISSET(net, &obits)) {
369 FD_CLR(net, &obits);
370 returnValue |= netflush();
371 }
372 if (FD_ISSET(tout, &obits)) {
373 FD_CLR(tout, &obits);
374 returnValue |= (ttyflush(SYNCHing|flushout) > 0);
375 }
376
377 /*
378 * Something to read from the network...
379 */
380 if (FD_ISSET(net, &ibits)) {
381 /* hacks for systems without SO_OOBINLINE removed */
382
383 FD_CLR(net, &ibits);
384 /* Only call network input routine if there is room. Otherwise
385 * we will try a 0 byte read, which we happily interpret as the
386 * server having dropped the connection...
387 * NB the input routine reserves 1 byte for ungetc.
388 * 12.3.97 --okir */
389 returnValue = 1;
390 if (netiring.empty_count() > 1) {
391 c = netiring.read_source();
392 if (c <= 0)
393 return -1;
394 else if (c == 0)
395 returnValue = 0;
396 }
397 }
398
399 /*
400 * Something to read from the tty...
401 */
402 if (FD_ISSET(tin, &ibits)) {
403 FD_CLR(tin, &ibits);
404 c = ttyiring.read_source();
405 if (c < 0) {
406 return -1;
407 }
408 else if (c==0) returnValue = 0;
409 else returnValue = 1; /* did something useful */
410 }
411
412 return returnValue;
413}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/telnet.1 b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/telnet.1
new file mode 100644
index 0000000..c939de9
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/telnet.1
@@ -0,0 +1,1267 @@
1.\" Copyright (c) 1983, 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" from: @(#)telnet.1 6.16 (Berkeley) 7/27/91
33.\" $Id: telnet.1,v 1.15 2000/07/30 23:57:08 dholland Exp $
34.\"
35.Dd August 15, 1999
36.Dt TELNET 1
37.Os "Linux NetKit (0.17)"
38.Sh NAME
39.Nm telnet
40.Nd user interface to the
41.Tn TELNET
42protocol
43.Sh SYNOPSIS
44.Nm telnet
45.Op Fl 8ELadr
46.Op Fl S Ar tos
47.Op Fl e Ar escapechar
48.Op Fl l Ar user
49.Op Fl n Ar tracefile
50.Oo
51.Ar host
52.Op Ar port
53.Oc
54.Sh DESCRIPTION
55The
56.Nm telnet
57command
58is used for interactive communication with another host using the
59.Tn TELNET
60protocol. It begins in command mode, where it prints a telnet prompt
61("telnet\&> "). If
62.Nm telnet
63is invoked with a
64.Ar host
65argument, it performs an
66.Ic open
67command implicitly; see the description below.
68.Pp
69Options:
70.Bl -tag -width indent
71.It Fl 8
72Request 8-bit operation. This causes an attempt to negotiate the
73.Dv TELNET BINARY
74option for both input and output. By default telnet is not 8-bit
75clean.
76.It Fl E
77Disables the escape character functionality; that is, sets the escape
78character to ``no character''.
79.It Fl L
80Specifies an 8-bit data path on output. This causes the
81.Dv TELNET BINARY
82option to be negotiated on just output.
83.It Fl a
84Attempt automatic login. Currently, this sends the user name via the
85.Ev USER
86variable
87of the
88.Ev ENVIRON
89option if supported by the remote system. The username is retrieved
90via
91.Xr getlogin 3 .
92.It Fl d
93Sets the initial value of the
94.Ic debug
95toggle to
96.Dv TRUE.
97.It Fl r
98Emulate
99.Xr rlogin 1 .
100In this mode, the default escape character is a tilde. Also, the
101interpretation of the escape character is changed: an escape character
102followed by a dot causes
103.Nm telnet
104to disconnect from the remote host. A ^Z instead of a dot suspends
105.Nm telnet ,
106and a ^] (the default
107.Nm telnet
108escape character) generates a normal telnet prompt. These codes are
109accepted only at the beginning of a line.
110.It Fl S Ar tos
111Sets the IP type-of-service (TOS) option for the telnet
112connection to the value
113.Ar tos .
114.It Fl e Ar escapechar
115Sets the escape character to
116.Ar escapechar.
117If no character is supplied, no escape character will be used.
118Entering the escape character while connected causes telnet to drop to
119command mode.
120.It Fl l Ar user
121Specify
122.Ar user
123as the user to log in as on the remote system. This is accomplished by
124sending the specified name as the
125.Dv USER
126environment variable, so it requires that the remote system support the
127.Ev TELNET ENVIRON
128option. This option implies the
129.Fl a
130option, and may also be used with the
131.Ic open
132command.
133.It Fl n Ar tracefile
134Opens
135.Ar tracefile
136for recording trace information.
137See the
138.Ic set tracefile
139command below.
140.It Ar host
141Specifies a host to contact over the network.
142.It Ar port
143Specifies a port number or service name to contact. If not specified,
144the
145.Nm telnet
146port (23) is used.
147.El
148.Pp
149Protocol:
150.Pp
151Once a connection has been opened,
152.Nm telnet
153will attempt to enable the
154.Dv TELNET LINEMODE
155option.
156If this fails, then
157.Nm telnet
158will revert to one of two input modes:
159either \*(Lqcharacter at a time\*(Rq
160or \*(Lqold line by line\*(Rq
161depending on what the remote system supports.
162.Pp
163When
164.Dv LINEMODE
165is enabled, character processing is done on the
166local system, under the control of the remote system. When input
167editing or character echoing is to be disabled, the remote system
168will relay that information. The remote system will also relay
169changes to any special characters that happen on the remote
170system, so that they can take effect on the local system.
171.Pp
172In \*(Lqcharacter at a time\*(Rq mode, most
173text typed is immediately sent to the remote host for processing.
174.Pp
175In \*(Lqold line by line\*(Rq mode, all text is echoed locally,
176and (normally) only completed lines are sent to the remote host.
177The \*(Lqlocal echo character\*(Rq (initially \*(Lq^E\*(Rq) may be used
178to turn off and on the local echo
179(this would mostly be used to enter passwords
180without the password being echoed).
181.Pp
182If the
183.Dv LINEMODE
184option is enabled, or if the
185.Ic localchars
186toggle is
187.Dv TRUE
188(the default for \*(Lqold line by line\*(Lq; see below),
189the user's
190.Ic quit ,
191.Ic intr ,
192and
193.Ic flush
194characters are trapped locally, and sent as
195.Tn TELNET
196protocol sequences to the remote side.
197If
198.Dv LINEMODE
199has ever been enabled, then the user's
200.Ic susp
201and
202.Ic eof
203are also sent as
204.Tn TELNET
205protocol sequences,
206and
207.Ic quit
208is sent as a
209.Dv TELNET ABORT
210instead of
211.Dv BREAK
212There are options (see
213.Ic toggle
214.Ic autoflush
215and
216.Ic toggle
217.Ic autosynch
218below)
219which cause this action to flush subsequent output to the terminal
220(until the remote host acknowledges the
221.Tn TELNET
222sequence) and flush previous terminal input
223(in the case of
224.Ic quit
225and
226.Ic intr ) .
227.Pp
228Commands:
229.Pp
230The following
231.Nm telnet
232commands are available. Unique prefixes are understood as abbreviations.
233.Pp
234.Bl -tag -width "mode type"
235.It Ic auth Ar argument ...
236The
237.Ic auth
238command controls the
239.Dv TELNET AUTHENTICATE
240protocol option. If
241.Nm telnet
242was compiled without authentication, the
243.Ic auth
244command will not be supported.
245Valid arguments are as follows:
246.Bl -tag -width "disable type"
247.It Ic disable Ar type
248Disable the specified type of authentication. To
249obtain a list of available types, use the
250.Ic auth disable \&?
251command.
252.It Ic enable Ar type
253Enable the specified type of authentication. To
254obtain a list of available types, use the
255.Ic auth enable \&?
256command.
257.It Ic status
258List the current status of the various types of
259authentication.
260.El
261.Pp
262Note that the current version of
263.Nm telnet
264does not support authentication.
265.It Ic close
266Close the connection to the remote host, if any, and return to command
267mode.
268.It Ic display Ar argument ...
269Display all, or some, of the
270.Ic set
271and
272.Ic toggle
273values (see below).
274.It Ic encrypt Ar argument ...
275The encrypt command controls the
276.Dv TELNET ENCRYPT
277protocol option. If
278.Nm telnet
279was compiled without encryption, the
280.Ic encrypt
281command will not be supported.
282.Pp
283Valid arguments are as follows:
284.Bl -tag -width Ar
285.It Ic disable Ar type Ic [input|output]
286Disable the specified type of encryption. If you do not specify input
287or output, encryption of both is disabled. To obtain a list of
288available types, use ``encrypt disable \&?''.
289.It Ic enable Ar type Ic [input|output]
290Enable the specified type of encryption. If you do not specify input
291or output, encryption of both is enabled. To obtain a list of
292available types, use ``encrypt enable \&?''.
293.It Ic input
294This is the same as ``encrypt start input''.
295.It Ic -input
296This is the same as ``encrypt stop input''.
297.It Ic output
298This is the same as ``encrypt start output''.
299.It Ic -output
300This is the same as ``encrypt stop output''.
301.It Ic start Ic [input|output]
302Attempt to begin encrypting. If you do not specify input or output,
303encryption of both input and output is started.
304.It Ic status
305Display the current status of the encryption module.
306.It Ic stop Ic [input|output]
307Stop encrypting. If you do not specify input or output, encryption of
308both is stopped.
309.It Ic type Ar type
310Sets the default type of encryption to be used with later ``encrypt start''
311or ``encrypt stop'' commands.
312.El
313.Pp
314Note that the current version of
315.Nm telnet
316does not support encryption.
317.It Ic environ Ar arguments...
318The
319.Ic environ
320command is used to propagate environment variables across the
321.Nm telnet
322link using the
323.Dv TELNET ENVIRON
324protocol option.
325All variables exported from the shell are defined, but only the
326.Ev DISPLAY
327and
328.Ev PRINTER
329variables are marked to be sent by default. The
330.Ev USER
331variable is marked to be sent if the
332.Fl a
333or
334.Fl l
335command-line options were used.
336.Pp
337Valid arguments for the
338.Ic environ
339command are:
340.Bl -tag -width Fl
341.It Ic define Ar variable value
342Define the variable
343.Ar variable
344to have a value of
345.Ar value.
346Any variables defined by this command are automatically marked for
347propagation (``exported'').
348The
349.Ar value
350may be enclosed in single or double quotes so
351that tabs and spaces may be included.
352.It Ic undefine Ar variable
353Remove any existing definition of
354.Ar variable .
355.It Ic export Ar variable
356Mark the specified variable for propagation to the remote host.
357.It Ic unexport Ar variable
358Do not mark the specified variable for propagation to the remote
359host. The remote host may still ask explicitly for variables that are
360not exported.
361.It Ic list
362List the current set of environment variables.
363Those marked with a
364.Cm *
365will be propagated to the remote host. The remote host may still ask
366explicitly for the rest.
367.It Ic \&?
368Prints out help information for the
369.Ic environ
370command.
371.El
372.It Ic logout
373Send the
374.Dv TELNET LOGOUT
375protocol option to the remote host.
376This command is similar to a
377.Ic close
378command. If the remote host does not support the
379.Dv LOGOUT
380option, nothing happens. But if it does, this command should cause it
381to close the connection. If the remote side also supports the concept
382of suspending a user's session for later reattachment, the logout
383command indicates that the session should be terminated immediately.
384.It Ic mode Ar type
385.Ar Type
386is one of several options, depending on the state of the session.
387.Tn Telnet
388asks the remote host to go into the requested mode. If the remote host
389says it can, that mode takes effect.
390.Bl -tag -width Ar
391.It Ic character
392Disable the
393.Dv TELNET LINEMODE
394option, or, if the remote side does not understand the
395.Dv LINEMODE
396option, then enter \*(Lqcharacter at a time\*(Lq mode.
397.It Ic line
398Enable the
399.Dv TELNET LINEMODE
400option, or, if the remote side does not understand the
401.Dv LINEMODE
402option, then attempt to enter \*(Lqold-line-by-line\*(Lq mode.
403.It Ic isig Pq Ic \-isig
404Attempt to enable (disable) the
405.Dv TRAPSIG
406mode of the
407.Dv LINEMODE
408option.
409This requires that the
410.Dv LINEMODE
411option be enabled.
412.It Ic edit Pq Ic \-edit
413Attempt to enable (disable) the
414.Dv EDIT
415mode of the
416.Dv LINEMODE
417option.
418This requires that the
419.Dv LINEMODE
420option be enabled.
421.It Ic softtabs Pq Ic \-softtabs
422Attempt to enable (disable) the
423.Dv SOFT_TAB
424mode of the
425.Dv LINEMODE
426option.
427This requires that the
428.Dv LINEMODE
429option be enabled.
430.It Ic litecho Pq Ic \-litecho
431Attempt to enable (disable) the
432.Dv LIT_ECHO
433mode of the
434.Dv LINEMODE
435option.
436This requires that the
437.Dv LINEMODE
438option be enabled.
439.It Ic \&?
440Prints out help information for the
441.Ic mode
442command.
443.El
444.It Xo
445.Ic open Ar host
446.Oo Op Fl l
447.Ar user
448.Oc Ns Oo Fl
449.Ar port Oc
450.Xc
451Open a connection to the named host. If no port number is specified,
452.Nm telnet
453will attempt to contact a
454.Tn telnet
455daemon at the standard port (23).
456The host specification may be a host name or IP address.
457The
458.Fl l
459option may be used to specify a user name to be passed to the remote
460system, like the
461.Fl l
462command-line option.
463.Pp
464When connecting to ports other than the
465.Nm telnet
466port,
467.Nm telnet
468does not attempt
469.Tn telnet
470protocol negotiations. This makes it possible to connect to services
471that do not support the
472.Tn telnet
473protocol without making a mess. Protocol negotiation can be forced by
474placing a dash before the port number.
475.Pp
476After establishing a connection, any commands associated with the
477remote host in
478.Pa /etc/telnetrc
479and the user's
480.Pa .telnetrc
481file are executed, in that order.
482.Pp
483The format of the telnetrc files is as follows: Lines beginning with a
484#, and blank lines, are ignored. The rest of the file should consist
485of hostnames and sequences of
486.Nm telnet
487commands to use with that host. Commands should be one per line,
488indented by whitespace; lines beginning without whitespace are
489interpreted as hostnames. Lines beginning with the special hostname
490.Ql DEFAULT
491will apply to all hosts. Upon connecting to a particular host, the
492commands associated with that host are executed.
493.It Ic quit
494Close any open session and exit
495.Nm telnet .
496An end of file condition on input, when in command mode, will trigger
497this operation as well.
498.It Ic send Ar arguments
499Send one or more special
500.Tn telnet
501protocol character sequences to the remote host. The following are
502the codes which may be specified (more than one may be used in one
503command):
504.Pp
505.Bl -tag -width escape
506.It Ic abort
507Sends the
508.Dv TELNET ABORT
509(Abort Processes) sequence.
510.It Ic ao
511Sends the
512.Dv TELNET AO
513(Abort Output) sequence, which should cause the remote system to flush
514all output
515.Em from
516the remote system
517.Em to
518the user's terminal.
519.It Ic ayt
520Sends the
521.Dv TELNET AYT
522(Are You There?) sequence, to which the remote system may or may not
523choose to respond.
524.It Ic brk
525Sends the
526.Dv TELNET BRK
527(Break) sequence, which may have significance to the remote
528system.
529.It Ic ec
530Sends the
531.Dv TELNET EC
532(Erase Character)
533sequence, which should cause the remote system to erase the last character
534entered.
535.It Ic el
536Sends the
537.Dv TELNET EL
538(Erase Line)
539sequence, which should cause the remote system to erase the line currently
540being entered.
541.It Ic eof
542Sends the
543.Dv TELNET EOF
544(End Of File)
545sequence.
546.It Ic eor
547Sends the
548.Dv TELNET EOR
549(End of Record)
550sequence.
551.It Ic escape
552Sends the current
553.Nm telnet
554escape character.
555.It Ic ga
556Sends the
557.Dv TELNET GA
558(Go Ahead)
559sequence, which likely has no significance to the remote system.
560.It Ic getstatus
561If the remote side supports the
562.Dv TELNET STATUS
563command,
564.Ic getstatus
565will send the subnegotiation to request that the server send
566its current option status.
567.It Ic ip
568Sends the
569.Dv TELNET IP
570(Interrupt Process) sequence, which should cause the remote
571system to abort the currently running process.
572.It Ic nop
573Sends the
574.Dv TELNET NOP
575(No Operation)
576sequence.
577.It Ic susp
578Sends the
579.Dv TELNET SUSP
580(Suspend Process)
581sequence.
582.It Ic synch
583Sends the
584.Dv TELNET SYNCH
585sequence.
586This sequence causes the remote system to discard all previously typed
587(but not yet read) input.
588This sequence is sent as
589.Tn TCP
590urgent
591data (and may not work if the remote system is a
592.Bx 4.2
593system -- if
594it doesn't work, a lower case \*(Lqr\*(Rq may be echoed on the terminal).
595.It Ic do Ar cmd
596.It Ic dont Ar cmd
597.It Ic will Ar cmd
598.It Ic wont Ar cmd
599Sends the
600.Dv TELNET DO
601.Ar cmd
602sequence.
603.Ar cmd
604can be either a decimal number between 0 and 255,
605or a symbolic name for a specific
606.Dv TELNET
607command.
608.Ar cmd
609can also be either
610.Ic help
611or
612.Ic \&?
613to print out help information, including
614a list of known symbolic names.
615.It Ic \&?
616Prints out help information for the
617.Ic send
618command.
619.El
620.It Ic set Ar argument value
621.It Ic unset Ar argument value
622The
623.Ic set
624command will set any one of a number of
625.Nm telnet
626variables to a specific value or to
627.Dv TRUE .
628The special value
629.Ic off
630turns off the function associated with
631the variable. This is equivalent to using the
632.Ic unset
633command.
634The
635.Ic unset
636command will disable or set to
637.Dv FALSE
638any of the specified variables.
639The values of variables may be interrogated with the
640.Ic display
641command.
642The variables which may be set or unset, but not toggled, are
643listed here. In addition, any of the variables for the
644.Ic toggle
645command may be explicitly set or unset.
646.Bl -tag -width escape
647.It Ic ayt
648If
649.Tn telnet
650is in localchars mode, or
651.Dv LINEMODE
652is enabled, and the status character is typed, a
653.Dv TELNET AYT
654sequence is sent to the remote host. The initial value for the "Are
655You There" character is the terminal's status character.
656.It Ic echo
657This is the value (initially \*(Lq^E\*(Rq) which, when in
658\*(Lqline by line\*(Rq mode, toggles between doing local echoing
659of entered characters (for normal processing), and suppressing
660echoing of entered characters (for entering, say, a password).
661.It Ic eof
662If
663.Nm telnet
664is operating in
665.Dv LINEMODE
666or \*(Lqold line by line\*(Rq mode, entering this character
667as the first character on a line will cause this character to be
668sent to the remote system.
669The initial value of the eof character is taken to be the terminal's
670.Ic eof
671character.
672.It Ic erase
673If
674.Nm telnet
675is in
676.Ic localchars
677mode (see
678.Ic toggle
679.Ic localchars
680below),
681.Sy and
682if
683.Nm telnet
684is operating in \*(Lqcharacter at a time\*(Rq mode, then when this
685character is typed, a
686.Dv TELNET EC
687sequence (see
688.Ic send
689.Ic ec
690above)
691is sent to the remote system.
692The initial value for the erase character is taken to be
693the terminal's
694.Ic erase
695character.
696.It Ic escape
697This is the
698.Nm telnet
699escape character (initially \*(Lq^[\*(Rq) which causes entry
700into
701.Nm telnet
702command mode (when connected to a remote system).
703.It Ic flushoutput
704If
705.Nm telnet
706is in
707.Ic localchars
708mode (see
709.Ic toggle
710.Ic localchars
711below)
712and the
713.Ic flushoutput
714character is typed, a
715.Dv TELNET AO
716sequence (see
717.Ic send
718.Ic ao
719above)
720is sent to the remote host.
721The initial value for the flush character is taken to be
722the terminal's
723.Ic flush
724character.
725.It Ic forw1
726.It Ic forw2
727If
728.Tn TELNET
729is operating in
730.Dv LINEMODE ,
731these are the
732characters that, when typed, cause partial lines to be
733forwarded to the remote system. The initial value for
734the forwarding characters are taken from the terminal's
735eol and eol2 characters.
736.It Ic interrupt
737If
738.Nm telnet
739is in
740.Ic localchars
741mode (see
742.Ic toggle
743.Ic localchars
744below)
745and the
746.Ic interrupt
747character is typed, a
748.Dv TELNET IP
749sequence (see
750.Ic send
751.Ic ip
752above)
753is sent to the remote host.
754The initial value for the interrupt character is taken to be
755the terminal's
756.Ic intr
757character.
758.It Ic kill
759If
760.Nm telnet
761is in
762.Ic localchars
763mode (see
764.Ic toggle
765.Ic localchars
766below),
767.Ic and
768if
769.Nm telnet
770is operating in \*(Lqcharacter at a time\*(Rq mode, then when this
771character is typed, a
772.Dv TELNET EL
773sequence (see
774.Ic send
775.Ic el
776above)
777is sent to the remote system.
778The initial value for the kill character is taken to be
779the terminal's
780.Ic kill
781character.
782.It Ic lnext
783If
784.Nm telnet
785is operating in
786.Dv LINEMODE
787or \*(Lqold line by line\*(Lq mode, then this character is taken to
788be the terminal's
789.Ic lnext
790character.
791The initial value for the lnext character is taken to be
792the terminal's
793.Ic lnext
794character.
795.It Ic quit
796If
797.Nm telnet
798is in
799.Ic localchars
800mode (see
801.Ic toggle
802.Ic localchars
803below)
804and the
805.Ic quit
806character is typed, a
807.Dv TELNET BRK
808sequence (see
809.Ic send
810.Ic brk
811above)
812is sent to the remote host.
813The initial value for the quit character is taken to be
814the terminal's
815.Ic quit
816character.
817.It Ic reprint
818If
819.Nm telnet
820is operating in
821.Dv LINEMODE
822or \*(Lqold line by line\*(Lq mode, then this character is taken to
823be the terminal's
824.Ic reprint
825character.
826The initial value for the reprint character is taken to be
827the terminal's
828.Ic reprint
829character.
830.It Ic rlogin
831This is the rlogin mode escape character. Setting it enables rlogin
832mode, as with the
833.Ar r
834command-line option (q.v.)
835.It Ic start
836If the
837.Dv TELNET TOGGLE-FLOW-CONTROL
838option has been enabled,
839then this character is taken to
840be the terminal's
841.Ic start
842character.
843The initial value for the kill character is taken to be
844the terminal's
845.Ic start
846character.
847.It Ic stop
848If the
849.Dv TELNET TOGGLE-FLOW-CONTROL
850option has been enabled,
851then this character is taken to
852be the terminal's
853.Ic stop
854character.
855The initial value for the kill character is taken to be
856the terminal's
857.Ic stop
858character.
859.It Ic susp
860If
861.Nm telnet
862is in
863.Ic localchars
864mode, or
865.Dv LINEMODE
866is enabled, and the
867.Ic suspend
868character is typed, a
869.Dv TELNET SUSP
870sequence (see
871.Ic send
872.Ic susp
873above)
874is sent to the remote host.
875The initial value for the suspend character is taken to be
876the terminal's
877.Ic suspend
878character.
879.It Ic tracefile
880This is the file to which the output, caused by
881.Ic netdata
882or
883.Ic option
884tracing being
885.Dv TRUE ,
886will be written. If it is set to
887.Dq Fl ,
888then tracing information will be written to standard output (the default).
889.It Ic worderase
890If
891.Nm telnet
892is operating in
893.Dv LINEMODE
894or \*(Lqold line by line\*(Lq mode, then this character is taken to
895be the terminal's
896.Ic worderase
897character.
898The initial value for the worderase character is taken to be
899the terminal's
900.Ic worderase
901character.
902.It Ic \&?
903Displays the legal
904.Ic set
905.Pq Ic unset
906commands.
907.El
908.It Ic slc Ar state
909The
910.Ic slc
911command (Set Local Characters) is used to set
912or change the state of the the special
913characters when the
914.Dv TELNET LINEMODE
915option has
916been enabled. Special characters are characters that get
917mapped to
918.Tn TELNET
919commands sequences (like
920.Ic ip
921or
922.Ic quit )
923or line editing characters (like
924.Ic erase
925and
926.Ic kill ) .
927By default, the local special characters are exported.
928.Bl -tag -width Fl
929.It Ic check
930Verify the current settings for the current special characters.
931The remote side is requested to send all the current special
932character settings, and if there are any discrepancies with
933the local side, the local side will switch to the remote value.
934.It Ic export
935Switch to the local defaults for the special characters. The
936local default characters are those of the local terminal at
937the time when
938.Nm telnet
939was started.
940.It Ic import
941Switch to the remote defaults for the special characters.
942The remote default characters are those of the remote system
943at the time when the
944.Tn TELNET
945connection was established.
946.It Ic \&?
947Prints out help information for the
948.Ic slc
949command.
950.El
951.It Ic status
952Show the current status of
953.Nm telnet .
954This includes the name of the remote host, if any, as well as the
955current mode.
956.It Ic toggle Ar arguments ...
957Toggle (between
958.Dv TRUE
959and
960.Dv FALSE )
961various flags that control how
962.Nm telnet
963responds to events.
964These flags may be set explicitly to
965.Dv TRUE
966or
967.Dv FALSE
968using the
969.Ic set
970and
971.Ic unset
972commands.
973More than one flag may be toggled at once.
974The state of these flags may be examined with the
975.Ic display
976command.
977Valid flags are:
978.Bl -tag -width Ar
979.It Ic authdebug
980Turns on debugging for the authentication code. This flag only exists
981if authentication support is enabled.
982.It Ic autoflush
983If
984.Ic autoflush
985and
986.Ic localchars
987are both
988.Dv TRUE ,
989then when the
990.Ic ao ,
991or
992.Ic quit
993characters are recognized (and transformed into
994.Tn TELNET
995sequences; see
996.Ic set
997above for details),
998.Nm telnet
999refuses to display any data on the user's terminal
1000until the remote system acknowledges (via a
1001.Dv TELNET TIMING MARK
1002option)
1003that it has processed those
1004.Tn TELNET
1005sequences.
1006The initial value for this toggle is
1007.Dv TRUE
1008if the terminal user had not
1009done an "stty noflsh", otherwise
1010.Dv FALSE
1011(see
1012.Xr stty 1 ) .
1013.It Ic autodecrypt
1014When the
1015.Dv TELNET ENCRYPT
1016option is negotiated, by
1017default the actual encryption (decryption) of the data
1018stream does not start automatically. The autoencrypt
1019(autodecrypt) command states that encryption of the
1020output (input) stream should be enabled as soon as
1021possible.
1022.Pp
1023Note that this flag exists only if encryption support is enabled.
1024.It Ic autologin
1025If the remote side supports the
1026.Dv TELNET AUTHENTICATION
1027option,
1028.Tn telnet
1029attempts to use it to perform automatic authentication. If the
1030.Dv TELNET AUTHENTICATION
1031option is not supported, the user's login name is propagated using the
1032.Dv TELNET ENVIRON
1033option.
1034Setting this flag is the same as specifying the
1035.Ar a
1036option to the
1037.Ic open
1038command or on the command line.
1039.It Ic autosynch
1040If
1041.Ic autosynch
1042and
1043.Ic localchars
1044are both
1045.Dv TRUE ,
1046then when either the
1047.Ic intr
1048or
1049.Ic quit
1050characters is typed (see
1051.Ic set
1052above for descriptions of the
1053.Ic intr
1054and
1055.Ic quit
1056characters), the resulting
1057.Tn telnet
1058sequence sent is followed by the
1059.Dv TELNET SYNCH
1060sequence.
1061This procedure
1062.Ic should
1063cause the remote system to begin throwing away all previously
1064typed input until both of the
1065.Tn telnet
1066sequences have been read and acted upon.
1067The initial value of this toggle is
1068.Dv FALSE .
1069.It Ic binary
1070Enable or disable the
1071.Dv TELNET BINARY
1072option on both input and output.
1073.It Ic inbinary
1074Enable or disable the
1075.Dv TELNET BINARY
1076option on input.
1077.It Ic outbinary
1078Enable or disable the
1079.Dv TELNET BINARY
1080option on output.
1081.It Ic crlf
1082If this is
1083.Dv TRUE ,
1084then carriage returns will be sent as
1085.Li <CR><LF> .
1086If this is
1087.Dv FALSE ,
1088then carriage returns will be send as
1089.Li <CR><NUL> .
1090The initial value for this toggle is
1091.Dv FALSE .
1092.It Ic crmod
1093Toggle carriage return mode.
1094When this mode is enabled, most carriage return characters received from
1095the remote host will be mapped into a carriage return followed by
1096a line feed.
1097This mode does not affect those characters typed by the user, only
1098those received from the remote host.
1099This mode is not very useful unless the remote host
1100only sends carriage return, but never line feed.
1101The initial value for this toggle is
1102.Dv FALSE .
1103.It Ic debug
1104Toggles socket level debugging (useful only to the
1105.Ic super user ) .
1106The initial value for this toggle is
1107.Dv FALSE .
1108.It Ic encdebug
1109Turns on debugging information for the encryption code.
1110Note that this flag only exists if encryption support is available.
1111.It Ic localchars
1112If this is
1113.Dv TRUE ,
1114then the
1115.Ic flush ,
1116.Ic interrupt ,
1117.Ic quit ,
1118.Ic erase ,
1119and
1120.Ic kill
1121characters (see
1122.Ic set
1123above) are recognized locally, and transformed into (hopefully) appropriate
1124.Tn TELNET
1125control sequences
1126(respectively
1127.Ic ao ,
1128.Ic ip ,
1129.Ic brk ,
1130.Ic ec ,
1131and
1132.Ic el ;
1133see
1134.Ic send
1135above).
1136The initial value for this toggle is
1137.Dv TRUE
1138in \*(Lqold line by line\*(Rq mode,
1139and
1140.Dv FALSE
1141in \*(Lqcharacter at a time\*(Rq mode.
1142When the
1143.Dv LINEMODE
1144option is enabled, the value of
1145.Ic localchars
1146is ignored, and assumed to always be
1147.Dv TRUE .
1148If
1149.Dv LINEMODE
1150has ever been enabled, then
1151.Ic quit
1152is sent as
1153.Ic abort ,
1154and
1155.Ic eof and
1156.B suspend
1157are sent as
1158.Ic eof and
1159.Ic susp ,
1160see
1161.Ic send
1162above).
1163.It Ic netdata
1164Toggles the display of all network data (in hexadecimal format).
1165The initial value for this toggle is
1166.Dv FALSE .
1167.It Ic options
1168Toggles the display of some internal
1169.Nm telnet
1170protocol processing (having to do with
1171.Tn telnet
1172options).
1173The initial value for this toggle is
1174.Dv FALSE .
1175.It Ic prettydump
1176When the
1177.Ic netdata
1178toggle is enabled, if
1179.Ic prettydump
1180is enabled the output from the
1181.Ic netdata
1182command will be formatted in a more user-readable format.
1183Spaces are put between each character in the output, and the
1184beginning of
1185.Tn telnet
1186escape sequences are preceded by a '*' to aid in locating them.
1187.It Ic skiprc
1188When the skiprc toggle is
1189.Dv TRUE ,
1190.Tn telnet
1191does not read the telnetrc files. The initial value for this toggle is
1192.Dv FALSE.
1193.It Ic termdata
1194Toggles the display of all terminal data (in hexadecimal format).
1195The initial value for this toggle is
1196.Dv FALSE .
1197.It Ic verbose_encrypt
1198When the
1199.Ic verbose_encrypt
1200toggle is
1201.Dv TRUE ,
1202.Tn TELNET
1203prints out a message each time encryption is enabled or
1204disabled. The initial value for this toggle is
1205.Dv FALSE.
1206This flag only exists if encryption support is available.
1207.It Ic \&?
1208Displays the legal
1209.Ic toggle
1210commands.
1211.El
1212.It Ic z
1213Suspend
1214.Nm telnet .
1215This command only works when the user is using the
1216.Xr csh 1 .
1217.It Ic \&! Op Ar command
1218Execute a single command in a subshell on the local
1219system. If
1220.Ic command
1221is omitted, then an interactive subshell is invoked.
1222.It Ic \&? Op Ar command
1223Get help. With no arguments,
1224.Nm telnet
1225prints a help summary.
1226If a command is specified,
1227.Nm telnet
1228will print the help information for just that command.
1229.El
1230.Sh ENVIRONMENT
1231.Nm Telnet
1232uses at least the
1233.Ev HOME ,
1234.Ev SHELL ,
1235.Ev DISPLAY ,
1236and
1237.Ev TERM
1238environment variables.
1239Other environment variables may be propagated
1240to the other side via the
1241.Dv TELNET ENVIRON
1242option.
1243.Sh FILES
1244.Bl -tag -width /etc/telnetrc -compact
1245.It Pa /etc/telnetrc
1246global telnet startup values
1247.It Pa ~/.telnetrc
1248user customized telnet startup values
1249.El
1250.Sh HISTORY
1251The
1252.Nm Telnet
1253command appeared in
1254.Bx 4.2 .
1255.Sh NOTES
1256.Pp
1257On some remote systems, echo has to be turned off manually when in
1258\*(Lqold line by line\*(Rq mode.
1259.Pp
1260In \*(Lqold line by line\*(Rq mode or
1261.Dv LINEMODE
1262the terminal's
1263.Ic eof
1264character is only recognized (and sent to the remote system)
1265when it is the first character on a line.
1266.Sh BUGS
1267The source code is not comprehensible.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/telnet.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/telnet.cc
new file mode 100644
index 0000000..e5c613d
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/telnet.cc
@@ -0,0 +1,2071 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)telnet.c 5.53 (Berkeley) 3/22/91
36 */
37char telnet_rcsid[] =
38"$Id: telnet.cc,v 1.36 2000/07/23 03:24:53 dholland Exp $";
39
40#include <string.h>
41#include <sys/types.h>
42#include <stdlib.h>
43#include <unistd.h>
44#include <signal.h>
45
46#include <arpa/telnet.h>
47
48#include <ctype.h>
49
50#include "ring.h"
51#include "defines.h"
52#include "externs.h"
53#include "types.h"
54#include "environ.h"
55#include "proto.h"
56#include "ptrarray.h"
57#include "netlink.h"
58#include "terminal.h"
59
60/*
61 * Due to lossage in some linux distributions/kernel releases/libc versions
62 * this must come *after* termios.h (which is included in externs.h)
63 */
64#include <termcap.h>
65
66#ifdef USE_NCURSES
67#include <term.h>
68#endif
69
70
71#define strip(x) ((x)&0x7f)
72
73static unsigned char subbuffer[SUBBUFSIZE];
74static unsigned char *subpointer, *subend; /* buffer for sub-options */
75#define SB_CLEAR() subpointer = subbuffer;
76#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
77#define SB_ACCUM(c) if (subpointer < (subbuffer+sizeof subbuffer)) { \
78 *subpointer++ = (c); \
79 }
80
81#define SB_GET() (*subpointer++)
82#define SB_PEEK() (*subpointer)
83#define SB_EOF() (subpointer >= subend)
84#define SB_LEN() (subend - subpointer)
85
86char options[256]; /* The combined options */
87char do_dont_resp[256];
88char will_wont_resp[256];
89
90int
91eight = 0,
92 autologin = 0, /* Autologin anyone? */
93 skiprc = 0,
94 connected,
95 showoptions,
96 In3270, /* Are we in 3270 mode? */
97 ISend, /* trying to send network data in */
98 debug = 0,
99 crmod,
100 crlf, /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
101#if defined(TN3270)
102 noasynchtty = 0,/* User specified "-noasynch" on command line */
103 noasynchnet = 0,/* User specified "-noasynch" on command line */
104 askedSGA = 0, /* We have talked about suppress go ahead */
105#endif /* defined(TN3270) */
106 telnetport,
107 SYNCHing, /* we are in TELNET SYNCH mode */
108 flushout, /* flush output */
109 autoflush = 0, /* flush output when interrupting? */
110 autosynch, /* send interrupt characters with SYNCH? */
111 localflow, /* we handle flow control locally */
112 localchars, /* we recognize interrupt/quit */
113 donelclchars, /* the user has set "localchars" */
114 donebinarytoggle, /* the user has put us in binary */
115 dontlecho, /* do we suppress local echoing right now? */
116 globalmode;
117
118char *prompt = 0;
119
120cc_t escapechar;
121cc_t rlogin;
122#ifdef KLUDGELINEMODE
123cc_t echoc;
124#endif
125
126/*
127 * Telnet receiver states for fsm
128 */
129#define TS_DATA 0
130#define TS_IAC 1
131#define TS_WILL 2
132#define TS_WONT 3
133#define TS_DO 4
134#define TS_DONT 5
135#define TS_CR 6
136#define TS_SB 7 /* sub-option collection */
137#define TS_SE 8 /* looking for sub-option end */
138
139static int telrcv_state;
140
141sigjmp_buf toplevel;
142sigjmp_buf peerdied;
143
144int flushline;
145int linemode;
146
147#ifdef KLUDGELINEMODE
148int kludgelinemode = 1;
149#endif
150
151/*
152 * The following are some clocks used to decide how to interpret
153 * the relationship between various variables.
154 */
155
156Clocks clocks;
157
158#ifdef notdef
159Modelist modelist[] = {
160 { "telnet command mode", COMMAND_LINE },
161 { "character-at-a-time mode", 0 },
162 { "character-at-a-time mode (local echo)", LOCAL_ECHO|LOCAL_CHARS },
163 { "line-by-line mode (remote echo)", LINE | LOCAL_CHARS },
164 { "line-by-line mode", LINE | LOCAL_ECHO | LOCAL_CHARS },
165 { "line-by-line mode (local echoing suppressed)", LINE | LOCAL_CHARS },
166 { "3270 mode", 0 },
167};
168#endif
169
170/*
171 * Initialize telnet environment.
172 */
173void init_telnet(void) {
174 env_init();
175 cmdtab_init();
176
177 SB_CLEAR();
178 memset(options, 0, sizeof(options));
179
180 connected = In3270 = ISend = localflow = donebinarytoggle = 0;
181
182 SYNCHing = 0;
183
184 /* Don't change NetTrace */
185
186 escapechar = CONTROL(']');
187 rlogin = _POSIX_VDISABLE;
188#ifdef KLUDGELINEMODE
189 echoc = CONTROL('E');
190#endif
191
192 flushline = 1;
193 telrcv_state = TS_DATA;
194}
195
196
197#if 0
198#include <stdarg.h>
199
200static void printring(Ring *ring, const char *format, ...) {
201 va_list ap;
202 char buffer[100]; /* where things go */
203 char *ptr;
204 char *string;
205 int i;
206
207 va_start(ap, format);
208
209 ptr = buffer;
210
211 while ((i = *format++) != 0) {
212 if (i == '%') {
213 i = *format++;
214 switch (i) {
215 case 'c':
216 *ptr++ = va_arg(ap, int);
217 break;
218 case 's':
219 string = va_arg(ap, char *);
220 ring->supply_data(buffer, ptr-buffer);
221 ring->supply_data(string, strlen(string));
222 ptr = buffer;
223 break;
224 case 0:
225 ExitString("printring: trailing %%.\n", 1);
226 /*NOTREACHED*/
227 default:
228 ExitString("printring: unknown format character.\n", 1);
229 /*NOTREACHED*/
230 }
231 }
232 else {
233 *ptr++ = i;
234 }
235 }
236 ring->supply_data(buffer, ptr-buffer);
237}
238#endif
239
240/*
241 * These routines are in charge of sending option negotiations
242 * to the other side.
243 *
244 * The basic idea is that we send the negotiation if either side
245 * is in disagreement as to what the current state should be.
246 */
247
248void send_do(int c, int init) {
249 if (init) {
250 if (((do_dont_resp[c] == 0) && my_state_is_do(c)) ||
251 my_want_state_is_do(c))
252 return;
253 set_my_want_state_do(c);
254 do_dont_resp[c]++;
255 }
256 NET2ADD(IAC, DO);
257 NETADD(c);
258 printoption("SENT", DO, c);
259}
260
261void send_dont(int c, int init) {
262 if (init) {
263 if (((do_dont_resp[c] == 0) && my_state_is_dont(c)) ||
264 my_want_state_is_dont(c))
265 return;
266 set_my_want_state_dont(c);
267 do_dont_resp[c]++;
268 }
269 NET2ADD(IAC, DONT);
270 NETADD(c);
271 printoption("SENT", DONT, c);
272}
273
274void send_will(int c, int init) {
275 if (init) {
276 if (((will_wont_resp[c] == 0) && my_state_is_will(c)) ||
277 my_want_state_is_will(c))
278 return;
279 set_my_want_state_will(c);
280 will_wont_resp[c]++;
281 }
282 NET2ADD(IAC, WILL);
283 NETADD(c);
284 printoption("SENT", WILL, c);
285}
286
287void send_wont(int c, int init) {
288 if (init) {
289 if (((will_wont_resp[c] == 0) && my_state_is_wont(c)) ||
290 my_want_state_is_wont(c))
291 return;
292 set_my_want_state_wont(c);
293 will_wont_resp[c]++;
294 }
295 NET2ADD(IAC, WONT);
296 NETADD(c);
297 printoption("SENT", WONT, c);
298}
299
300
301void willoption(int option) {
302 int new_state_ok = 0;
303
304 if (do_dont_resp[option]) {
305 --do_dont_resp[option];
306 if (do_dont_resp[option] && my_state_is_do(option))
307 --do_dont_resp[option];
308 }
309
310 if ((do_dont_resp[option] == 0) && my_want_state_is_dont(option)) {
311 switch (option) {
312 case TELOPT_ECHO:
313#if defined(TN3270)
314 /*
315 * The following is a pain in the rear-end.
316 * Various IBM servers (some versions of Wiscnet,
317 * possibly Fibronics/Spartacus, and who knows who
318 * else) will NOT allow us to send "DO SGA" too early
319 * in the setup proceedings. On the other hand,
320 * 4.2 servers (telnetd) won't set SGA correctly.
321 * So, we are stuck. Empirically (but, based on
322 * a VERY small sample), the IBM servers don't send
323 * out anything about ECHO, so we postpone our sending
324 * "DO SGA" until we see "WILL ECHO" (which 4.2 servers
325 * DO send).
326 */
327 {
328 if (askedSGA == 0) {
329 askedSGA = 1;
330 if (my_want_state_is_dont(TELOPT_SGA))
331 send_do(TELOPT_SGA, 1);
332 }
333 }
334 /* Fall through */
335 case TELOPT_EOR:
336#endif /* TN3270 */
337 case TELOPT_BINARY:
338 case TELOPT_SGA:
339 settimer(modenegotiated);
340 /* FALL THROUGH */
341 case TELOPT_STATUS:
342 new_state_ok = 1;
343 break;
344
345 case TELOPT_TM:
346 if (flushout)
347 flushout = 0;
348 /*
349 * Special case for TM. If we get back a WILL,
350 * pretend we got back a WONT.
351 */
352 set_my_want_state_dont(option);
353 set_my_state_dont(option);
354 return; /* Never reply to TM will's/wont's */
355
356 case TELOPT_LINEMODE:
357 default:
358 break;
359 }
360
361 if (new_state_ok) {
362 set_my_want_state_do(option);
363 send_do(option, 0);
364 setconnmode(0); /* possibly set new tty mode */
365 }
366 else {
367 do_dont_resp[option]++;
368 send_dont(option, 0);
369 }
370 }
371 set_my_state_do(option);
372}
373
374void wontoption(int option) {
375 if (do_dont_resp[option]) {
376 --do_dont_resp[option];
377 if (do_dont_resp[option] && my_state_is_dont(option))
378 --do_dont_resp[option];
379 }
380
381 if ((do_dont_resp[option] == 0) && my_want_state_is_do(option)) {
382
383 switch (option) {
384
385#ifdef KLUDGELINEMODE
386 case TELOPT_SGA:
387 if (!kludgelinemode)
388 break;
389 /* FALL THROUGH */
390#endif
391 case TELOPT_ECHO:
392 settimer(modenegotiated);
393 break;
394
395 case TELOPT_TM:
396 if (flushout)
397 flushout = 0;
398 set_my_want_state_dont(option);
399 set_my_state_dont(option);
400 return; /* Never reply to TM will's/wont's */
401
402 default:
403 break;
404 }
405 set_my_want_state_dont(option);
406 if (my_state_is_do(option))
407 send_dont(option, 0);
408 setconnmode(0); /* Set new tty mode */
409 }
410 else if (option == TELOPT_TM) {
411 /*
412 * Special case for TM.
413 */
414 if (flushout)
415 flushout = 0;
416 set_my_want_state_dont(option);
417 }
418 set_my_state_dont(option);
419}
420
421static void dooption(int option) {
422 int new_state_ok = 0;
423
424 if (will_wont_resp[option]) {
425 --will_wont_resp[option];
426 if (will_wont_resp[option] && my_state_is_will(option))
427 --will_wont_resp[option];
428 }
429
430 if (will_wont_resp[option] == 0) {
431 if (my_want_state_is_wont(option)) {
432
433 switch (option) {
434
435 case TELOPT_TM:
436 /*
437 * Special case for TM. We send a WILL, but pretend
438 * we sent WONT.
439 */
440 send_will(option, 0);
441 set_my_want_state_wont(TELOPT_TM);
442 set_my_state_wont(TELOPT_TM);
443 return;
444
445# if defined(TN3270)
446 case TELOPT_EOR: /* end of record */
447# endif /* defined(TN3270) */
448 case TELOPT_BINARY: /* binary mode */
449 case TELOPT_NAWS: /* window size */
450 case TELOPT_TSPEED: /* terminal speed */
451 case TELOPT_LFLOW: /* local flow control */
452 case TELOPT_TTYPE: /* terminal type option */
453 case TELOPT_SGA: /* no big deal */
454 case TELOPT_ENVIRON: /* environment variable option */
455 new_state_ok = 1;
456 break;
457
458 case TELOPT_XDISPLOC: /* X Display location */
459 if (env_getvalue("DISPLAY", 0))
460 new_state_ok = 1;
461 break;
462
463 case TELOPT_LINEMODE:
464#ifdef KLUDGELINEMODE
465 kludgelinemode = 0;
466 send_do(TELOPT_SGA, 1);
467#endif
468 set_my_want_state_will(TELOPT_LINEMODE);
469 send_will(option, 0);
470 set_my_state_will(TELOPT_LINEMODE);
471 slc_init();
472 return;
473
474 case TELOPT_ECHO: /* We're never going to echo... */
475 default:
476 break;
477 }
478
479 if (new_state_ok) {
480 set_my_want_state_will(option);
481 send_will(option, 0);
482 setconnmode(0); /* Set new tty fmode */
483 }
484 else {
485 will_wont_resp[option]++;
486 send_wont(option, 0);
487 }
488 }
489 else {
490 /*
491 * Handle options that need more things done after the
492 * other side has acknowledged the option.
493 */
494 switch (option) {
495 case TELOPT_LINEMODE:
496#ifdef KLUDGELINEMODE
497 kludgelinemode = 0;
498 send_do(TELOPT_SGA, 1);
499#endif
500 set_my_state_will(option);
501 slc_init();
502 send_do(TELOPT_SGA, 0);
503 return;
504 }
505 }
506 }
507 set_my_state_will(option);
508}
509
510static void dontoption(int option) {
511 if (will_wont_resp[option]) {
512 --will_wont_resp[option];
513 if (will_wont_resp[option] && my_state_is_wont(option))
514 --will_wont_resp[option];
515 }
516
517 if ((will_wont_resp[option] == 0) && my_want_state_is_will(option)) {
518 switch (option) {
519 case TELOPT_LINEMODE:
520 linemode = 0; /* put us back to the default state */
521 break;
522 }
523 /* we always accept a DONT */
524 set_my_want_state_wont(option);
525 if (my_state_is_will(option))
526 send_wont(option, 0);
527 setconnmode(0); /* Set new tty mode */
528 }
529 set_my_state_wont(option);
530}
531
532/*
533 * Given a buffer returned by tgetent(), this routine will turn
534 * the pipe seperated list of names in the buffer into an array
535 * of pointers to null terminated names. We toss out any bad,
536 * duplicate, or verbose names (names with spaces).
537 */
538
539typedef ptrarray<const char> stringarray;
540
541static int is_unique(const char *name, const stringarray &ar) {
542 for (int i=0; i<ar.num(); i++) if (!strcasecmp(ar[i], name)) return 0;
543 return 1;
544}
545
546static void mklist(char *buf, const char *name, stringarray &fill) {
547 char *cp;
548
549 fill.setsize(0);
550 cp = strchr(buf, ':');
551 if (cp) *cp = 0;
552 for (cp = strtok(buf, "|:"); cp; cp = strtok(NULL, "|:")) {
553 /*
554 * Skip entries longer than 40 characters.
555 * Skip entries with spaces or non-ascii values.
556 * Convert lower case letters to upper case.
557 */
558 if (strlen(cp)>40) continue;
559 int bad = 0;
560 for (int i=0; cp[i]; i++) if (!isascii(cp[i]) || cp[i]==' ') bad=1;
561 if (bad) continue;
562 upcase(cp);
563 if (is_unique(cp, fill)) fill.add(cp);
564 }
565
566 /*
567 * Move the name we were passed to the beginning if it's not already
568 * there.
569 */
570 for (int j=1; j<fill.num(); j++) if (!strcasecmp(name, fill[j])) {
571 const char *temp = fill[j];
572 fill[j] = fill[0];
573 fill[0] = temp;
574 }
575
576 /*
577 * Check for an old V6 2 character name. If present,
578 * move it to the end of the array.
579 */
580 for (int k=1; k<fill.num()-1; k++) {
581 if (strlen(fill[k])==2 && fill[k]==buf) {
582 const char *temp = fill[fill.num()-1];
583 fill[fill.num()-1] = fill[k];
584 fill[k] = temp;
585 }
586 }
587
588 /*
589 * If we got nothing, add in what we were passed
590 */
591 if (fill.num()==0) {
592 if (name && strlen(name)<40) fill.add(name);
593 else fill.add("UNKNOWN");
594 }
595
596 /*
597 * Duplicate last name, for TTYPE option, and null
598 * terminate the array. If we didn't find a match on
599 * our terminal name, put that name at the beginning.
600 */
601
602 fill.add(fill[fill.num()-1]);
603
604 /* dholland 21-May-2000 I think this is bogus */
605 /*fill.add(NULL);*/
606}
607
608char termbuf[2048];
609
610static int my_setupterm(const char *tname, int /*fd*/, int *errp) {
611 if (tgetent(termbuf, tname) == 1) {
612 /* its Sun Mar 15 00:03:36 PST 1998 this could never have worked with
613 * ncurses. The ncurses tgetent() ignores its first parameter
614 */
615
616#ifndef USE_NCURSES
617 termbuf[1023] = '\0';
618#else
619 strncpy(termbuf, CUR term_names, sizeof(termbuf));
620#endif
621
622 if (errp)
623 *errp = 1;
624 return 0;
625 }
626 if (errp) *errp = 0;
627 return -1;
628}
629
630int resettermname = 1;
631
632static const char *gettermname(void) {
633 static stringarray termtypes;
634 static int next;
635
636 const char *tname;
637 int err;
638
639 if (resettermname) {
640 resettermname = 0;
641 tname = env_getvalue("TERM", 0);
642 if (!tname || my_setupterm(tname, 1, &err)) {
643 termbuf[0] = 0;
644 tname = "UNKNOWN";
645 }
646 mklist(termbuf, tname, termtypes);
647 next = 0;
648 }
649 if (next==termtypes.num()-1) next = 0;
650 return termtypes[next++];
651}
652/*
653 * suboption()
654 *
655 * Look at the sub-option buffer, and try to be helpful to the other
656 * side.
657 *
658 * Currently we recognize:
659 *
660 * Terminal type, send request.
661 * Terminal speed (send request).
662 * Local flow control (is request).
663 * Linemode
664 */
665
666static void suboption(void) {
667 printsub('<', subbuffer, SB_LEN()+2);
668 switch (SB_GET()) {
669 case TELOPT_TTYPE:
670 if (my_want_state_is_wont(TELOPT_TTYPE))
671 return;
672 if (SB_EOF() || SB_GET() != TELQUAL_SEND) {
673 return;
674 }
675 else {
676 const char *name;
677
678#if defined(TN3270)
679 if (tn3270_ttype()) {
680 return;
681 }
682#endif /* TN3270 */
683 name = gettermname();
684 netoring.xprintf("%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
685 TELQUAL_IS, name, IAC, SE);
686 }
687 break;
688 case TELOPT_TSPEED:
689 if (my_want_state_is_wont(TELOPT_TSPEED))
690 return;
691 if (SB_EOF())
692 return;
693 if (SB_GET() == TELQUAL_SEND) {
694 long oospeed, iispeed;
695 TerminalSpeeds(&iispeed, &oospeed);
696 netoring.xprintf("%c%c%c%c%ld,%ld%c%c", IAC, SB, TELOPT_TSPEED,
697 TELQUAL_IS, oospeed, iispeed, IAC, SE);
698 }
699 break;
700 case TELOPT_LFLOW:
701 if (my_want_state_is_wont(TELOPT_LFLOW))
702 return;
703 if (SB_EOF())
704 return;
705 switch(SB_GET()) {
706 case 1:
707 localflow = 1;
708 break;
709 case 0:
710 localflow = 0;
711 break;
712 default:
713 return;
714 }
715 setcommandmode();
716 setconnmode(0);
717 break;
718
719 case TELOPT_LINEMODE:
720 if (my_want_state_is_wont(TELOPT_LINEMODE))
721 return;
722 if (SB_EOF())
723 return;
724 switch (SB_GET()) {
725 case WILL:
726 lm_will(subpointer, SB_LEN());
727 break;
728 case WONT:
729 lm_wont(subpointer, SB_LEN());
730 break;
731 case DO:
732 lm_do(subpointer, SB_LEN());
733 break;
734 case DONT:
735 lm_dont(subpointer, SB_LEN());
736 break;
737 case LM_SLC:
738 slc(subpointer, SB_LEN());
739 break;
740 case LM_MODE:
741 lm_mode(subpointer, SB_LEN(), 0);
742 break;
743 default:
744 break;
745 }
746 break;
747
748 case TELOPT_ENVIRON:
749 if (SB_EOF())
750 return;
751 switch(SB_PEEK()) {
752 case TELQUAL_IS:
753 case TELQUAL_INFO:
754 if (my_want_state_is_dont(TELOPT_ENVIRON))
755 return;
756 break;
757 case TELQUAL_SEND:
758 if (my_want_state_is_wont(TELOPT_ENVIRON)) {
759 return;
760 }
761 break;
762 default:
763 return;
764 }
765 env_opt(subpointer, SB_LEN());
766 break;
767
768 case TELOPT_XDISPLOC:
769 if (my_want_state_is_wont(TELOPT_XDISPLOC))
770 return;
771 if (SB_EOF())
772 return;
773 if (SB_GET() == TELQUAL_SEND) {
774 const char *dp = env_getvalue("DISPLAY", 0);
775 if (dp == NULL) {
776 /*
777 * Something happened, we no longer have a DISPLAY
778 * variable. So, turn off the option.
779 */
780 send_wont(TELOPT_XDISPLOC, 1);
781 break;
782 }
783 netoring.xprintf("%c%c%c%c%s%c%c", IAC, SB, TELOPT_XDISPLOC,
784 TELQUAL_IS, dp, IAC, SE);
785 }
786 break;
787
788 default:
789 break;
790 }
791}
792
793//static char str_lm[] = { IAC, SB, TELOPT_LINEMODE, 0, 0, IAC, SE };
794
795void lm_will(unsigned char *cmd, int len) {
796 if (len < 1) {
797 /*@*/ printf("lm_will: no command!!!\n"); /* Should not happen... */
798 return;
799 }
800
801 netoring.xprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
802 DONT, cmd[0], IAC, SE);
803}
804
805void lm_wont(unsigned char * /*cmd*/, int len) {
806 if (len < 1) {
807 /*@*/ printf("lm_wont: no command!!!\n"); /* Should not happen... */
808 return;
809 }
810 /* We are always DONT, so don't respond */
811}
812
813void lm_do(unsigned char *cmd, int len) {
814 if (len < 1) {
815 /*@*/ printf("lm_do: no command!!!\n"); /* Should not happen... */
816 return;
817 }
818 netoring.xprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
819 WONT, cmd[0], IAC, SE);
820}
821
822void lm_dont(unsigned char * /*cmd*/, int len) {
823 if (len < 1) {
824 /*@*/ printf("lm_dont: no command!!!\n"); /* Should not happen... */
825 return;
826 }
827 /* we are always WONT, so don't respond */
828}
829
830void lm_mode(unsigned char *cmd, int len, int init) {
831 if (len != 1) return;
832 if ((linemode&MODE_MASK&~MODE_ACK) == *cmd) return;
833 if (*cmd&MODE_ACK) return;
834
835 linemode = *cmd&(MODE_MASK&~MODE_ACK);
836 int k = linemode;
837 if (!init) {
838 k |= MODE_ACK;
839 }
840
841 netoring.xprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE,
842 k, IAC, SE);
843
844 setconnmode(0); /* set changed mode */
845}
846
847
848/*
849 * slc()
850 * Handle special character suboption of LINEMODE.
851 */
852
853struct spc {
854 cc_t val;
855 cc_t *valp;
856 char flags; /* Current flags & level */
857 char mylevel; /* Maximum level & flags */
858} spc_data[NSLC+1];
859
860#define SLC_IMPORT 0
861#define SLC_EXPORT 1
862#define SLC_RVALUE 2
863static int slc_mode = SLC_EXPORT;
864
865void slc_init(void) {
866 register struct spc *spcp;
867
868 localchars = 1;
869 for (spcp = spc_data; spcp < &spc_data[NSLC+1]; spcp++) {
870 spcp->val = 0;
871 spcp->valp = 0;
872 spcp->flags = spcp->mylevel = SLC_NOSUPPORT;
873 }
874
875#define initfunc(func, flags) { \
876 spcp = &spc_data[func]; \
877 if ((spcp->valp = tcval(func))) { \
878 spcp->val = *spcp->valp; \
879 spcp->mylevel = SLC_VARIABLE|flags; \
880 } else { \
881 spcp->val = 0; \
882 spcp->mylevel = SLC_DEFAULT; \
883 } \
884 }
885
886 initfunc(SLC_SYNCH, 0);
887 /* No BRK */
888 initfunc(SLC_AO, 0);
889 initfunc(SLC_AYT, 0);
890 /* No EOR */
891 initfunc(SLC_ABORT, SLC_FLUSHIN|SLC_FLUSHOUT);
892 initfunc(SLC_EOF, 0);
893 initfunc(SLC_SUSP, SLC_FLUSHIN);
894
895 initfunc(SLC_EC, 0);
896 initfunc(SLC_EL, 0);
897
898 initfunc(SLC_XON, 0);
899 initfunc(SLC_XOFF, 0);
900
901 initfunc(SLC_FORW1, 0);
902 initfunc(SLC_FORW2, 0);
903 /* No FORW2 */
904
905 initfunc(SLC_IP, SLC_FLUSHIN|SLC_FLUSHOUT);
906#undef initfunc
907
908 if (slc_mode == SLC_EXPORT)
909 slc_export();
910 else
911 slc_import(1);
912
913}
914
915void slcstate(void) {
916 printf("Special characters are %s values\n",
917 slc_mode == SLC_IMPORT ? "remote default" :
918 slc_mode == SLC_EXPORT ? "local" :
919 "remote");
920}
921
922void slc_mode_export(void) {
923 slc_mode = SLC_EXPORT;
924 if (my_state_is_will(TELOPT_LINEMODE))
925 slc_export();
926}
927
928void slc_mode_import(int def) {
929 slc_mode = def ? SLC_IMPORT : SLC_RVALUE;
930 if (my_state_is_will(TELOPT_LINEMODE))
931 slc_import(def);
932}
933
934void slc_import(int def) {
935 if (def) {
936 netoring.xprintf("%c%c%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
937 LM_SLC, 0, SLC_DEFAULT, 0, IAC, SE);
938 }
939 else {
940 netoring.xprintf("%c%c%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE,
941 LM_SLC, 0, SLC_VARIABLE, 0, IAC, SE);
942 }
943}
944
945void slc_export(void) {
946 register struct spc *spcp;
947
948 TerminalDefaultChars();
949
950 slc_start_reply();
951 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
952 if (spcp->mylevel != SLC_NOSUPPORT) {
953 if (spcp->val == (cc_t)(_POSIX_VDISABLE))
954 spcp->flags = SLC_NOSUPPORT;
955 else
956 spcp->flags = spcp->mylevel;
957 if (spcp->valp)
958 spcp->val = *spcp->valp;
959 slc_add_reply(spcp - spc_data, spcp->flags, spcp->val);
960 }
961 }
962 slc_end_reply();
963 (void)slc_update();
964 setconnmode(1); /* Make sure the character values are set */
965}
966
967void slc(unsigned char *cp, int len) {
968 register struct spc *spcp;
969 register int func,level;
970
971 slc_start_reply();
972
973 for (; len >= 3; len -=3, cp +=3) {
974
975 func = cp[SLC_FUNC];
976
977 if (func == 0) {
978 /*
979 * Client side: always ignore 0 function.
980 */
981 continue;
982 }
983 if (func > NSLC) {
984 if ((cp[SLC_FLAGS] & SLC_LEVELBITS) != SLC_NOSUPPORT)
985 slc_add_reply(func, SLC_NOSUPPORT, 0);
986 continue;
987 }
988
989 spcp = &spc_data[func];
990
991 level = cp[SLC_FLAGS]&(SLC_LEVELBITS|SLC_ACK);
992
993 if ((cp[SLC_VALUE] == spcp->val) &&
994 ((level&SLC_LEVELBITS) == (spcp->flags&SLC_LEVELBITS))) {
995 continue;
996 }
997
998 if (level == (SLC_DEFAULT|SLC_ACK)) {
999 /*
1000 * This is an error condition, the SLC_ACK
1001 * bit should never be set for the SLC_DEFAULT
1002 * level. Our best guess to recover is to
1003 * ignore the SLC_ACK bit.
1004 */
1005 cp[SLC_FLAGS] &= ~SLC_ACK;
1006 }
1007
1008 if (level == ((spcp->flags&SLC_LEVELBITS)|SLC_ACK)) {
1009 spcp->val = (cc_t)cp[SLC_VALUE];
1010 spcp->flags = cp[SLC_FLAGS]; /* include SLC_ACK */
1011 continue;
1012 }
1013
1014 level &= ~SLC_ACK;
1015
1016 if (level <= (spcp->mylevel&SLC_LEVELBITS)) {
1017 spcp->flags = cp[SLC_FLAGS]|SLC_ACK;
1018 spcp->val = (cc_t)cp[SLC_VALUE];
1019 }
1020 if (level == SLC_DEFAULT) {
1021 if ((spcp->mylevel&SLC_LEVELBITS) != SLC_DEFAULT)
1022 spcp->flags = spcp->mylevel;
1023 else
1024 spcp->flags = SLC_NOSUPPORT;
1025 }
1026 slc_add_reply(func, spcp->flags, spcp->val);
1027 }
1028 slc_end_reply();
1029 if (slc_update())
1030 setconnmode(1); /* set the new character values */
1031}
1032
1033void slc_check(void) {
1034 register struct spc *spcp;
1035
1036 slc_start_reply();
1037 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
1038 if (spcp->valp && spcp->val != *spcp->valp) {
1039 spcp->val = *spcp->valp;
1040 if (spcp->val == (cc_t)(_POSIX_VDISABLE))
1041 spcp->flags = SLC_NOSUPPORT;
1042 else
1043 spcp->flags = spcp->mylevel;
1044 slc_add_reply(spcp - spc_data, spcp->flags, spcp->val);
1045 }
1046 }
1047 slc_end_reply();
1048 setconnmode(1);
1049}
1050
1051
1052unsigned char slc_reply[128];
1053unsigned char *slc_replyp;
1054
1055void slc_start_reply(void) {
1056 slc_replyp = slc_reply;
1057 *slc_replyp++ = IAC;
1058 *slc_replyp++ = SB;
1059 *slc_replyp++ = TELOPT_LINEMODE;
1060 *slc_replyp++ = LM_SLC;
1061}
1062
1063void slc_add_reply(int func, int flags, int value) {
1064 if ((*slc_replyp++ = func) == IAC)
1065 *slc_replyp++ = IAC;
1066 if ((*slc_replyp++ = flags) == IAC)
1067 *slc_replyp++ = IAC;
1068 if ((*slc_replyp++ = value) == IAC)
1069 *slc_replyp++ = IAC;
1070}
1071
1072void slc_end_reply(void) {
1073 register int len;
1074
1075 *slc_replyp++ = IAC;
1076 *slc_replyp++ = SE;
1077 len = slc_replyp - slc_reply;
1078 if (len <= 6) return;
1079
1080 printsub('>', &slc_reply[2], len - 2);
1081 netoring.write((char *)slc_reply, len);
1082}
1083
1084int slc_update(void) {
1085 struct spc *spcp;
1086 int need_update = 0;
1087
1088 for (spcp = &spc_data[1]; spcp < &spc_data[NSLC+1]; spcp++) {
1089 if (!(spcp->flags&SLC_ACK))
1090 continue;
1091 spcp->flags &= ~SLC_ACK;
1092 if (spcp->valp && (*spcp->valp != spcp->val)) {
1093 *spcp->valp = spcp->val;
1094 need_update = 1;
1095 }
1096 }
1097 return(need_update);
1098}
1099
1100void env_opt(unsigned char *buf, int len) {
1101 unsigned char *ep = 0, *epc = 0;
1102 int i;
1103
1104 switch(buf[0]) {
1105 case TELQUAL_SEND:
1106 env_opt_start();
1107 if (len == 1) {
1108 env_opt_add(NULL);
1109 }
1110 else for (i = 1; i < len; i++) {
1111 switch (buf[i]) {
1112 case ENV_VALUE:
1113 if (ep) {
1114 *epc = 0;
1115 env_opt_add((const char *)ep);
1116 }
1117 ep = epc = &buf[i+1];
1118 break;
1119 case ENV_ESC:
1120 i++;
1121 /*FALL THROUGH*/
1122 default:
1123 if (epc)
1124 *epc++ = buf[i];
1125 break;
1126 }
1127 if (ep) {
1128 *epc = 0;
1129 env_opt_add((const char *)ep);
1130 }
1131 }
1132 env_opt_end(1);
1133 break;
1134
1135 case TELQUAL_IS:
1136 case TELQUAL_INFO:
1137 /* Ignore for now. We shouldn't get it anyway. */
1138 break;
1139
1140 default:
1141 break;
1142 }
1143}
1144
1145/* OPT_REPLY_SIZE must be a multiple of 2. */
1146#define OPT_REPLY_SIZE 256
1147unsigned char *opt_reply;
1148unsigned char *opt_replyp;
1149unsigned char *opt_replyend;
1150
1151void env_opt_start(void) {
1152 if (opt_reply)
1153 opt_reply = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
1154 else
1155 opt_reply = (unsigned char *)malloc(OPT_REPLY_SIZE);
1156 if (opt_reply == NULL) {
1157 /*@*/ printf("env_opt_start: malloc()/realloc() failed!!!\n");
1158 opt_reply = opt_replyp = opt_replyend = NULL;
1159 return;
1160 }
1161 opt_replyp = opt_reply;
1162 opt_replyend = opt_reply + OPT_REPLY_SIZE;
1163 *opt_replyp++ = IAC;
1164 *opt_replyp++ = SB;
1165 *opt_replyp++ = TELOPT_ENVIRON;
1166 *opt_replyp++ = TELQUAL_IS;
1167}
1168
1169void env_opt_start_info(void) {
1170 env_opt_start();
1171 if (opt_replyp)
1172 opt_replyp[-1] = TELQUAL_INFO;
1173}
1174
1175void env_opt_add(const char *ep) {
1176 const char *vp;
1177 const unsigned char *tp;
1178 unsigned char c;
1179
1180 if (opt_reply == NULL) /*XXX*/
1181 return; /*XXX*/
1182
1183 if (ep == NULL || *ep == '\0') {
1184 int i;
1185 env_iterate(&i, 1);
1186 for (ep = env_next(&i,1); ep; ep = env_next(&i,1)) env_opt_add(ep);
1187 return;
1188 }
1189 vp = env_getvalue(ep, 1);
1190 tp = opt_replyp + (vp ? strlen(vp) * 2 : 0) + strlen(ep) * 2 + 6;
1191 if (tp > opt_replyend)
1192 {
1193 register int len;
1194 len = ((tp - opt_reply) + OPT_REPLY_SIZE - 1) & ~(OPT_REPLY_SIZE - 1);
1195 opt_replyend = opt_reply + len;
1196 opt_reply = (unsigned char *)realloc(opt_reply, len);
1197 if (opt_reply == NULL) {
1198 /*@*/ printf("env_opt_add: realloc() failed!!!\n");
1199 opt_reply = opt_replyp = opt_replyend = NULL;
1200 return;
1201 }
1202 opt_replyp = opt_reply + len - (opt_replyend - opt_replyp);
1203 opt_replyend = opt_reply + len;
1204 }
1205 *opt_replyp++ = ENV_VAR;
1206 for (;;) {
1207 while ((c = *ep++)!=0) {
1208 switch(c) {
1209 case IAC:
1210 *opt_replyp++ = IAC;
1211 break;
1212 case ENV_VALUE:
1213 case ENV_VAR:
1214 case ENV_ESC:
1215 *opt_replyp++ = ENV_ESC;
1216 break;
1217 }
1218 *opt_replyp++ = c;
1219 }
1220 if ((ep = vp)!=NULL) {
1221 *opt_replyp++ = ENV_VALUE;
1222 vp = NULL;
1223 } else
1224 break;
1225 }
1226}
1227
1228void env_opt_end(int emptyok) {
1229 register int len;
1230
1231 len = opt_replyp - opt_reply + 2;
1232 if (emptyok || len > 6) {
1233 *opt_replyp++ = IAC;
1234 *opt_replyp++ = SE;
1235 printsub('>', &opt_reply[2], len - 2);
1236 netoring.write((char *)opt_reply, len);
1237 }
1238 if (opt_reply) {
1239 free(opt_reply);
1240 opt_reply = opt_replyp = opt_replyend = NULL;
1241 }
1242}
1243
1244
1245int telrcv(void) {
1246 int c;
1247 int returnValue = 0;
1248
1249 while (TTYROOM() > 2) {
1250 if (!netiring.getch(&c)) {
1251 /* No more data coming in */
1252 break;
1253 }
1254 returnValue = 1;
1255
1256 switch (telrcv_state) {
1257 case TS_CR:
1258 telrcv_state = TS_DATA;
1259 if (c == '\0') {
1260 break; /* Ignore \0 after CR */
1261 }
1262 else if ((c == '\n') &&
1263 my_want_state_is_dont(TELOPT_ECHO) &&
1264 !crmod)
1265 {
1266 TTYADD(c);
1267 break;
1268 }
1269 /* Else, fall through */
1270
1271 case TS_DATA:
1272 if (c == IAC) {
1273 telrcv_state = TS_IAC;
1274 break;
1275 }
1276#if defined(TN3270)
1277 if (In3270) {
1278 *Ifrontp++ = c;
1279 while (netiring.getch(&c)) {
1280 if (c == IAC) {
1281 telrcv_state = TS_IAC;
1282 break;
1283 }
1284 *Ifrontp++ = c;
1285 }
1286 } else
1287#endif /* defined(TN3270) */
1288 /*
1289 * The 'crmod' hack (see following) is needed
1290 * since we can't * set CRMOD on output only.
1291 * Machines like MULTICS like to send \r without
1292 * \n; since we must turn off CRMOD to get proper
1293 * input, the mapping is done here (sigh).
1294 */
1295 if ((c == '\r') && my_want_state_is_dont(TELOPT_BINARY)) {
1296 if (netiring.getch(&c)) {
1297 if (c == 0) {
1298 /* a "true" CR */
1299 TTYADD('\r');
1300 }
1301 else if (my_want_state_is_dont(TELOPT_ECHO) &&
1302 (c == '\n')) {
1303 TTYADD('\n');
1304 }
1305 else {
1306 netiring.ungetch(c);
1307 TTYADD('\r');
1308 if (crmod) TTYADD('\n');
1309 }
1310 }
1311 else {
1312 telrcv_state = TS_CR;
1313 TTYADD('\r');
1314 if (crmod) TTYADD('\n');
1315 }
1316 }
1317 else {
1318 TTYADD(c);
1319 }
1320 continue;
1321
1322 case TS_IAC:
1323 process_iac:
1324 switch (c) {
1325 case WILL:
1326 telrcv_state = TS_WILL;
1327 continue;
1328 case WONT:
1329 telrcv_state = TS_WONT;
1330 continue;
1331 case DO:
1332 telrcv_state = TS_DO;
1333 continue;
1334 case DONT:
1335 telrcv_state = TS_DONT;
1336 continue;
1337 case DM:
1338 /*
1339 * We may have missed an urgent notification,
1340 * so make sure we flush whatever is in the
1341 * buffer currently.
1342 */
1343 printoption("RCVD", IAC, DM);
1344 SYNCHing = 1;
1345 ttyflush(1);
1346 SYNCHing = nlink.stilloob();
1347 settimer(gotDM);
1348 break;
1349 case SB:
1350 SB_CLEAR();
1351 telrcv_state = TS_SB;
1352 continue;
1353
1354#if defined(TN3270)
1355 case EOR:
1356 if (In3270) {
1357 if (Ibackp == Ifrontp) {
1358 Ibackp = Ifrontp = Ibuf;
1359 ISend = 0; /* should have been! */
1360 }
1361 else {
1362 Ibackp += DataFromNetwork(Ibackp, Ifrontp-Ibackp, 1);
1363 ISend = 1;
1364 }
1365 }
1366 printoption("RCVD", IAC, EOR);
1367 break;
1368#endif /* defined(TN3270) */
1369
1370 case IAC:
1371#if !defined(TN3270)
1372 TTYADD(IAC);
1373#else /* !defined(TN3270) */
1374 if (In3270) {
1375 *Ifrontp++ = IAC;
1376 }
1377 else {
1378 TTYADD(IAC);
1379 }
1380#endif /* !defined(TN3270) */
1381 break;
1382
1383 case NOP:
1384 case GA:
1385 default:
1386 printoption("RCVD", IAC, c);
1387 break;
1388 }
1389 telrcv_state = TS_DATA;
1390 continue;
1391
1392 case TS_WILL:
1393 printoption("RCVD", WILL, c);
1394 willoption(c);
1395 SetIn3270();
1396 telrcv_state = TS_DATA;
1397 continue;
1398
1399 case TS_WONT:
1400 printoption("RCVD", WONT, c);
1401 wontoption(c);
1402 SetIn3270();
1403 telrcv_state = TS_DATA;
1404 continue;
1405
1406 case TS_DO:
1407 printoption("RCVD", DO, c);
1408 dooption(c);
1409 SetIn3270();
1410 if (c == TELOPT_NAWS) {
1411 sendnaws();
1412 }
1413 else if (c == TELOPT_LFLOW) {
1414 localflow = 1;
1415 setcommandmode();
1416 setconnmode(0);
1417 }
1418 telrcv_state = TS_DATA;
1419 continue;
1420
1421 case TS_DONT:
1422 printoption("RCVD", DONT, c);
1423 dontoption(c);
1424 flushline = 1;
1425 setconnmode(0); /* set new tty mode (maybe) */
1426 SetIn3270();
1427 telrcv_state = TS_DATA;
1428 continue;
1429
1430 case TS_SB:
1431 if (c == IAC) {
1432 telrcv_state = TS_SE;
1433 }
1434 else {
1435 SB_ACCUM(c);
1436 }
1437 continue;
1438
1439 case TS_SE:
1440 if (c != SE) {
1441 if (c != IAC) {
1442 /*
1443 * This is an error. We only expect to get
1444 * "IAC IAC" or "IAC SE". Several things may
1445 * have happend. An IAC was not doubled, the
1446 * IAC SE was left off, or another option got
1447 * inserted into the suboption are all possibilities.
1448 * If we assume that the IAC was not doubled,
1449 * and really the IAC SE was left off, we could
1450 * get into an infinate loop here. So, instead,
1451 * we terminate the suboption, and process the
1452 * partial suboption if we can.
1453 */
1454 SB_ACCUM(IAC);
1455 SB_ACCUM(c);
1456 subpointer -= 2;
1457 SB_TERM();
1458
1459 printoption("In SUBOPTION processing, RCVD", IAC, c);
1460 suboption(); /* handle sub-option */
1461 SetIn3270();
1462 telrcv_state = TS_IAC;
1463 goto process_iac;
1464 }
1465 SB_ACCUM(c);
1466 telrcv_state = TS_SB;
1467 }
1468 else {
1469 SB_ACCUM(IAC);
1470 SB_ACCUM(SE);
1471 subpointer -= 2;
1472 SB_TERM();
1473 suboption(); /* handle sub-option */
1474 SetIn3270();
1475 telrcv_state = TS_DATA;
1476 }
1477 }
1478
1479 }
1480 return returnValue;
1481}
1482
1483static int bol = 1, local = 0;
1484
1485int rlogin_susp(void) {
1486 if (local) {
1487 local = 0;
1488 bol = 1;
1489 command(0, "z\n", 2);
1490 return(1);
1491 }
1492 return(0);
1493}
1494
1495static int telsnd(void) {
1496 // int tcc;
1497 // int count;
1498 int returnValue = 0;
1499 // const char *tbp = NULL;
1500
1501 // tcc = 0;
1502 // count = 0;
1503 while (netoring.empty_count() > 2) {
1504 int c, sc;
1505
1506 if (!ttyiring.getch(&c)) {
1507 break;
1508 }
1509 returnValue = 1;
1510
1511 sc = strip(c);
1512
1513 if (rlogin != _POSIX_VDISABLE) {
1514 if (bol) {
1515 bol = 0;
1516 if (sc == rlogin) {
1517 local = 1;
1518 continue;
1519 }
1520 }
1521 else if (local) {
1522 local = 0;
1523 if (sc == '.' || c == termEofChar) {
1524 bol = 1;
1525 command(0, "close\n", 6);
1526 continue;
1527 }
1528 if (sc == termSuspChar) {
1529 bol = 1;
1530 command(0, "z\n", 2);
1531 continue;
1532 }
1533 if (sc == escapechar && escapechar !=_POSIX_VDISABLE) {
1534 int l;
1535 char buf[128];
1536 l = ttyiring.gets(buf, sizeof(buf));
1537 command(0, buf, l);
1538 bol = 1;
1539 flushline = 1;
1540 break;
1541 }
1542 if (sc != rlogin) {
1543 ttyiring.ungetch(c);
1544 c = sc = rlogin;
1545 }
1546 }
1547 if ((sc == '\n') || (sc == '\r'))
1548 bol = 1;
1549 }
1550 else if (sc == escapechar && escapechar != _POSIX_VDISABLE) {
1551 int ignore = 0;
1552 /*
1553 * Double escape is a pass through of a single escape character.
1554 */
1555 if (ttyiring.getch(&c)) {
1556 if (strip(c) != escapechar) ttyiring.ungetch(c);
1557 else {
1558 bol = 0;
1559 ignore = 1;
1560 }
1561 }
1562 if (!ignore) {
1563 int l;
1564 char buf[128];
1565 l = ttyiring.gets(buf, sizeof(buf));
1566 command(0, buf, l);
1567 bol = 1;
1568 flushline = 1;
1569 break;
1570 }
1571 }
1572 else {
1573 bol = 0;
1574 }
1575#ifdef KLUDGELINEMODE
1576 if (kludgelinemode && (globalmode&MODE_EDIT) && (sc == echoc)) {
1577 int ignore=0;
1578 if (ttyiring.getch(&c) > 0) {
1579 if (strip(c) != echoc) ttyiring.ungetch(c);
1580 else ignore=1;
1581 }
1582 if (!ignore) {
1583 dontlecho = !dontlecho;
1584 settimer(echotoggle);
1585 setconnmode(0);
1586 flushline = 1;
1587 break;
1588 }
1589 }
1590#endif
1591 if (MODE_LOCAL_CHARS(globalmode)) {
1592 if (TerminalSpecialChars(sc) == 0) {
1593 bol = 1;
1594 break;
1595 }
1596 }
1597 if (my_want_state_is_wont(TELOPT_BINARY)) {
1598 switch (c) {
1599 case '\n':
1600 /*
1601 * If we are in CRMOD mode (\r ==> \n)
1602 * on our local machine, then probably
1603 * a newline (unix) is CRLF (TELNET).
1604 */
1605 if (MODE_LOCAL_CHARS(globalmode)) {
1606 NETADD('\r');
1607 }
1608 NETADD('\n');
1609 bol = flushline = 1;
1610 break;
1611 case '\r':
1612 if (!crlf) {
1613 NET2ADD('\r', '\0');
1614 }
1615 else {
1616 NET2ADD('\r', '\n');
1617 }
1618 bol = flushline = 1;
1619 break;
1620 case IAC:
1621 NET2ADD(IAC, IAC);
1622 break;
1623 default:
1624 NETADD(c);
1625 break;
1626 }
1627 }
1628 else if (c == IAC) {
1629 NET2ADD(IAC, IAC);
1630 }
1631 else {
1632 NETADD(c);
1633 }
1634 }
1635
1636 return returnValue; /* Non-zero if we did anything */
1637}
1638
1639/*
1640 * Scheduler()
1641 *
1642 * Try to do something.
1643 *
1644 * If we do something useful, return 1; else return 0.
1645 *
1646 */
1647
1648/* block: should we block in the select ? */
1649int Scheduler(int block) {
1650 /* One wants to be a bit careful about setting returnValue
1651 * to one, since a one implies we did some useful work,
1652 * and therefore probably won't be called to block next
1653 * time (TN3270 mode only).
1654 */
1655 int returnValue;
1656 int netin, netout, netex, ttyin, ttyout;
1657
1658 /* Decide which rings should be processed */
1659
1660 netout = netoring.full_count() &&
1661 (flushline ||
1662 (my_want_state_is_wont(TELOPT_LINEMODE)
1663#ifdef KLUDGELINEMODE
1664 && (!kludgelinemode || my_want_state_is_do(TELOPT_SGA))
1665#endif
1666 ) ||
1667 my_want_state_is_will(TELOPT_BINARY));
1668 ttyout = ttyoring.full_count();
1669
1670#if defined(TN3270)
1671 ttyin = ttyiring.empty_count() && (shell_active == 0);
1672#else /* defined(TN3270) */
1673 ttyin = ttyiring.empty_count();
1674#endif /* defined(TN3270) */
1675
1676#if defined(TN3270)
1677 netin = netiring.empty_count();
1678#else /* !defined(TN3270) */
1679 netin = !ISend && netiring.empty_count();
1680#endif /* !defined(TN3270) */
1681
1682 netex = !SYNCHing;
1683
1684 /* If we have seen a signal recently, reset things */
1685#ifdef TN3270
1686 if (HaveInput) {
1687 HaveInput = 0;
1688 (void) signal(SIGIO, inputAvailable);
1689 }
1690#endif /* TN3270 */
1691
1692 /* Call to system code to process rings */
1693
1694 returnValue = process_rings(netin, netout, netex, ttyin, ttyout, !block);
1695
1696 /* Now, look at the input rings, looking for work to do. */
1697
1698 if (ttyiring.full_count()) {
1699#if defined(TN3270)
1700 if (In3270) {
1701 int c;
1702
1703 c = DataFromTerminal(ttyiring.consume,
1704 ring_full_consecutive(&ttyiring));
1705 if (c) {
1706 returnValue = 1;
1707 ring_consumed(&ttyiring, c);
1708 }
1709 } else {
1710#endif /* defined(TN3270) */
1711 returnValue |= telsnd();
1712#if defined(TN3270)
1713 }
1714#endif /* defined(TN3270) */
1715 }
1716
1717 if (netiring.full_count()) {
1718# if !defined(TN3270)
1719 returnValue |= telrcv();
1720# else /* !defined(TN3270) */
1721 returnValue = Push3270();
1722# endif /* !defined(TN3270) */
1723 }
1724 return returnValue;
1725}
1726
1727/*
1728 * Select from tty and network...
1729 */
1730void telnet(const char * /*user*/) {
1731 sys_telnet_init();
1732
1733
1734#if !defined(TN3270)
1735 if (telnetport) {
1736 send_do(TELOPT_SGA, 1);
1737 send_will(TELOPT_TTYPE, 1);
1738 send_will(TELOPT_NAWS, 1);
1739 send_will(TELOPT_TSPEED, 1);
1740 send_will(TELOPT_LFLOW, 1);
1741 send_will(TELOPT_LINEMODE, 1);
1742 send_will(TELOPT_ENVIRON, 1);
1743 send_do(TELOPT_STATUS, 1);
1744 if (env_getvalue("DISPLAY", 0))
1745 send_will(TELOPT_XDISPLOC, 1);
1746 if (eight)
1747 tel_enter_binary(eight);
1748 }
1749#endif /* !defined(TN3270) */
1750
1751#if !defined(TN3270)
1752 for (;;) {
1753 int schedValue;
1754
1755 while ((schedValue = Scheduler(0)) != 0) {
1756 if (schedValue == -1) {
1757 setcommandmode();
1758 return;
1759 }
1760 }
1761
1762 if (Scheduler(1) == -1) {
1763 setcommandmode();
1764 return;
1765 }
1766 }
1767#else /* !defined(TN3270) */
1768 for (;;) {
1769 int schedValue;
1770
1771 while (!In3270 && !shell_active) {
1772 if (Scheduler(1) == -1) {
1773 setcommandmode();
1774 return;
1775 }
1776 }
1777
1778 while ((schedValue = Scheduler(0)) != 0) {
1779 if (schedValue == -1) {
1780 setcommandmode();
1781 return;
1782 }
1783 }
1784 /* If there is data waiting to go out to terminal, don't
1785 * schedule any more data for the terminal.
1786 */
1787 if (ring_full_count(&ttyoring)) {
1788 schedValue = 1;
1789 } else {
1790 if (shell_active) {
1791 if (shell_continue() == 0) {
1792 ConnectScreen();
1793 }
1794 } else if (In3270) {
1795 schedValue = DoTerminalOutput();
1796 }
1797 }
1798 if (schedValue && (shell_active == 0)) {
1799 if (Scheduler(1) == -1) {
1800 setcommandmode();
1801 return;
1802 }
1803 }
1804 }
1805#endif /* !defined(TN3270) */
1806}
1807
1808#if 0 /* XXX - this not being in is a bug */
1809/*
1810 * nextitem()
1811 *
1812 * Return the address of the next "item" in the TELNET data
1813 * stream. This will be the address of the next character if
1814 * the current address is a user data character, or it will
1815 * be the address of the character following the TELNET command
1816 * if the current address is a TELNET IAC ("I Am a Command")
1817 * character.
1818 */
1819
1820static unsigned char *nextitem(unsigned char *current) {
1821 if (*current != IAC) {
1822 return current+1;
1823 }
1824 switch (current[1]) {
1825 case DO:
1826 case DONT:
1827 case WILL:
1828 case WONT:
1829 return current+3;
1830 case SB: /* loop forever looking for the SE */
1831 {
1832 unsigned char *look = current+2;
1833
1834 for (;;) {
1835 if (*look++ == IAC) {
1836 if (*look++ == SE) {
1837 return look;
1838 }
1839 }
1840 }
1841 }
1842 default:
1843 return current+2;
1844 }
1845}
1846#endif /* 0 */
1847
1848/*
1849 * netclear()
1850 *
1851 * We are about to do a TELNET SYNCH operation. Clear
1852 * the path to the network.
1853 *
1854 * Things are a bit tricky since we may have sent the first
1855 * byte or so of a previous TELNET command into the network.
1856 * So, we have to scan the network buffer from the beginning
1857 * until we are up to where we want to be.
1858 *
1859 * A side effect of what we do, just to keep things
1860 * simple, is to clear the urgent data pointer. The principal
1861 * caller should be setting the urgent data pointer AFTER calling
1862 * us in any case.
1863 */
1864
1865static void netclear(void) {
1866#if 0 /* XXX */
1867 register char *thisitem, *next;
1868 char *good;
1869#define wewant(p) ((nfrontp > p) && (*p == IAC) && \
1870 (p[1] != EC) && (p[1] != EL))
1871
1872 thisitem = netobuf;
1873
1874 while ((next = nextitem(thisitem)) <= netobuf.send) {
1875 thisitem = next;
1876 }
1877
1878 /* Now, thisitem is first before/at boundary. */
1879
1880 good = netobuf; /* where the good bytes go */
1881
1882 while (netoring.add > thisitem) {
1883 if (wewant(thisitem)) {
1884 int length;
1885
1886 next = thisitem;
1887 do {
1888 next = nextitem(next);
1889 } while (wewant(next) && (nfrontp > next));
1890 length = next-thisitem;
1891 memcpy(good, thisitem, length);
1892 good += length;
1893 thisitem = next;
1894 } else {
1895 thisitem = nextitem(thisitem);
1896 }
1897 }
1898
1899#endif /* 0 */
1900}
1901
1902/*
1903 * These routines add various telnet commands to the data stream.
1904 */
1905
1906static void doflush(void) {
1907 NET2ADD(IAC, DO);
1908 NETADD(TELOPT_TM);
1909 flushline = 1;
1910 flushout = 1;
1911 (void) ttyflush(1); /* Flush/drop output */
1912 /* do printoption AFTER flush, otherwise the output gets tossed... */
1913 printoption("SENT", DO, TELOPT_TM);
1914}
1915
1916void xmitAO(void) {
1917 NET2ADD(IAC, AO);
1918 printoption("SENT", IAC, AO);
1919 if (autoflush) {
1920 doflush();
1921 }
1922}
1923
1924
1925void xmitEL(void) {
1926 NET2ADD(IAC, EL);
1927 printoption("SENT", IAC, EL);
1928}
1929
1930void xmitEC(void) {
1931 NET2ADD(IAC, EC);
1932 printoption("SENT", IAC, EC);
1933}
1934
1935
1936int dosynch(void) {
1937 netclear(); /* clear the path to the network */
1938 NETADD(IAC);
1939 netoring.set_mark();
1940 NETADD(DM);
1941 printoption("SENT", IAC, DM);
1942 return 1;
1943}
1944
1945int want_status_response = 0;
1946
1947int get_status(const char *, const char *) {
1948 unsigned char tmp[16];
1949 unsigned char *cp;
1950
1951 if (my_want_state_is_dont(TELOPT_STATUS)) {
1952 printf("Remote side does not support STATUS option\n");
1953 return 0;
1954 }
1955 cp = tmp;
1956
1957 *cp++ = IAC;
1958 *cp++ = SB;
1959 *cp++ = TELOPT_STATUS;
1960 *cp++ = TELQUAL_SEND;
1961 *cp++ = IAC;
1962 *cp++ = SE;
1963 printsub('>', tmp+2, cp - tmp - 2);
1964 netoring.write((char *)tmp, cp-tmp);
1965 ++want_status_response;
1966 return 1;
1967}
1968
1969void intp(void) {
1970 NET2ADD(IAC, IP);
1971 printoption("SENT", IAC, IP);
1972 flushline = 1;
1973 if (autoflush) {
1974 doflush();
1975 }
1976 if (autosynch) {
1977 dosynch();
1978 }
1979}
1980
1981void sendbrk(void) {
1982 NET2ADD(IAC, BREAK);
1983 printoption("SENT", IAC, BREAK);
1984 flushline = 1;
1985 if (autoflush) {
1986 doflush();
1987 }
1988 if (autosynch) {
1989 dosynch();
1990 }
1991}
1992
1993void sendabort(void) {
1994 NET2ADD(IAC, ABORT);
1995 printoption("SENT", IAC, ABORT);
1996 flushline = 1;
1997 if (autoflush) {
1998 doflush();
1999 }
2000 if (autosynch) {
2001 dosynch();
2002 }
2003}
2004
2005void sendsusp(void) {
2006 NET2ADD(IAC, SUSP);
2007 printoption("SENT", IAC, SUSP);
2008 flushline = 1;
2009 if (autoflush) {
2010 doflush();
2011 }
2012 if (autosynch) {
2013 dosynch();
2014 }
2015}
2016
2017void sendeof(void) {
2018 NET2ADD(IAC, xEOF);
2019 printoption("SENT", IAC, xEOF);
2020}
2021
2022void sendayt(void) {
2023 NET2ADD(IAC, AYT);
2024 printoption("SENT", IAC, AYT);
2025}
2026
2027/*
2028 * Send a window size update to the remote system.
2029 */
2030
2031void sendnaws(void) {
2032 long rows, cols;
2033 unsigned char tmp[16];
2034 unsigned char *cp;
2035
2036 if (my_state_is_wont(TELOPT_NAWS))
2037 return;
2038
2039#define PUTSHORT(cp, x) { if ((*cp++ = ((x)>>8)&0xff) == IAC) *cp++ = IAC; \
2040 if ((*cp++ = ((x))&0xff) == IAC) *cp++ = IAC; }
2041
2042 if (TerminalWindowSize(&rows, &cols) == 0) { /* Failed */
2043 return;
2044 }
2045
2046 cp = tmp;
2047
2048 *cp++ = IAC;
2049 *cp++ = SB;
2050 *cp++ = TELOPT_NAWS;
2051 PUTSHORT(cp, cols);
2052 PUTSHORT(cp, rows);
2053 *cp++ = IAC;
2054 *cp++ = SE;
2055 printsub('>', tmp+2, cp - tmp - 2);
2056 netoring.write((char *)tmp, cp-tmp);
2057}
2058
2059void tel_enter_binary(int rw) {
2060 if (rw&1)
2061 send_do(TELOPT_BINARY, 1);
2062 if (rw&2)
2063 send_will(TELOPT_BINARY, 1);
2064}
2065
2066void tel_leave_binary(int rw) {
2067 if (rw&1)
2068 send_dont(TELOPT_BINARY, 1);
2069 if (rw&2)
2070 send_wont(TELOPT_BINARY, 1);
2071}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/terminal.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/terminal.cc
new file mode 100644
index 0000000..c1adf18
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/terminal.cc
@@ -0,0 +1,720 @@
1/*
2 * Copyright (c) 1988, 1990 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)terminal.c 5.3 (Berkeley) 3/22/91
36 */
37char terminal_rcsid[] =
38 "$Id: terminal.cc,v 1.25 1999/12/12 19:48:05 dholland Exp $";
39
40#include <arpa/telnet.h>
41#include <sys/types.h>
42#include <sys/time.h>
43#include <termios.h>
44#include <unistd.h>
45#include <signal.h>
46#include <errno.h>
47#include <stdio.h>
48#include <string.h>
49#include <stdlib.h>
50
51#include "ring.h"
52#include "defines.h"
53#include "externs.h"
54#include "types.h"
55#include "proto.h"
56#include "terminal.h"
57
58static int TerminalWrite(const char *buf, int n);
59static int TerminalRead(char *buf, int n);
60
61ringbuf ttyoring, ttyiring;
62
63#ifndef VDISCARD
64cc_t termFlushChar;
65#endif
66
67#ifndef VLNEXT
68cc_t termLiteralNextChar;
69#endif
70
71#ifndef VSUSP
72cc_t termSuspChar;
73#endif
74
75#ifndef VWERASE
76cc_t termWerasChar;
77#endif
78
79#ifndef VREPRINT
80cc_t termRprntChar;
81#endif
82
83#ifndef VSTART
84cc_t termStartChar;
85#endif
86
87#ifndef VSTOP
88cc_t termStopChar;
89#endif
90
91#ifndef VEOL
92cc_t termForw1Char;
93#endif
94
95#ifndef VEOL2
96cc_t termForw2Char;
97#endif
98
99#ifndef VSTATUS
100cc_t termAytChar;
101#endif
102
103/*
104 * initialize the terminal data structures.
105 */
106void init_terminal(void) {
107 if (ttyoring.init(2*BUFSIZ, ttysink, NULL) != 1) {
108 exit(1);
109 }
110 if (ttyiring.init(BUFSIZ, NULL, ttysrc) != 1) {
111 exit(1);
112 }
113 autoflush = TerminalAutoFlush();
114}
115
116
117/*
118 * Send as much data as possible to the terminal.
119 * if arg "drop" is nonzero, drop data on the floor instead.
120 *
121 * Return value:
122 * -1: No useful work done, data waiting to go out.
123 * 0: No data was waiting, so nothing was done.
124 * 1: All waiting data was written out.
125 * n: All data - n was written out.
126 */
127int ttyflush(int drop) {
128 datasink *s = NULL;
129 if (drop) {
130 TerminalFlushOutput();
131 s = ttyoring.setsink(nullsink);
132 }
133 int rv = ttyoring.flush();
134 if (s) ttyoring.setsink(s);
135 return rv;
136}
137
138
139
140/*
141 * These routines decides on what the mode should be (based on the values
142 * of various global variables).
143 */
144int getconnmode(void) {
145 extern int linemode;
146 int mode = 0;
147#ifdef KLUDGELINEMODE
148 extern int kludgelinemode;
149#endif
150
151 if (In3270)
152 return(MODE_FLOW);
153
154 if (my_want_state_is_dont(TELOPT_ECHO))
155 mode |= MODE_ECHO;
156
157 if (localflow)
158 mode |= MODE_FLOW;
159
160 if (my_want_state_is_will(TELOPT_BINARY))
161 mode |= MODE_INBIN;
162
163 if (his_want_state_is_will(TELOPT_BINARY))
164 mode |= MODE_OUTBIN;
165
166#ifdef KLUDGELINEMODE
167 if (kludgelinemode) {
168 if (my_want_state_is_dont(TELOPT_SGA)) {
169 mode |= (MODE_TRAPSIG|MODE_EDIT);
170 if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) {
171 mode &= ~MODE_ECHO;
172 }
173 }
174 return(mode);
175 }
176#endif
177 if (my_want_state_is_will(TELOPT_LINEMODE))
178 mode |= linemode;
179 return(mode);
180}
181
182void setconnmode(int force) {
183 int newmode;
184
185 newmode = getconnmode()|(force?MODE_FORCE:0);
186
187 TerminalNewMode(newmode);
188
189}
190
191
192void setcommandmode(void) {
193 TerminalNewMode(-1);
194}
195
196
197/*********************/
198
199static int tout; /* Output file descriptor */
200static int tin; /* Input file descriptor */
201
202
203class ttysynk : public datasink {
204 public:
205 virtual int write(const char *buf, int len) {
206 return TerminalWrite(buf, len);
207 }
208 virtual int writeurg(const char *buf, int len) {
209 return TerminalWrite(buf, len);
210 }
211};
212
213class ttysorc : public ringbuf::source {
214 virtual int read(char *buf, int maxlen) {
215 int l = TerminalRead(buf, maxlen);
216 if (l<0 && errno==EWOULDBLOCK) l = 0;
217 else if (l==0 && MODE_LOCAL_CHARS(globalmode) && isatty(tin)) {
218 /* EOF detection for line mode!!!! */
219 /* must be an EOF... */
220 *buf = termEofChar;
221 l = 1;
222 }
223 return l;
224 }
225};
226
227static ttysynk chan1;
228static ttysorc chan2;
229datasink *ttysink = &chan1;
230ringbuf::source *ttysrc = &chan2;
231
232
233struct termios old_tc;
234struct termios new_tc;
235
236#ifndef TCSANOW
237
238#if defined(TCSETS)
239#define TCSANOW TCSETS
240#define TCSADRAIN TCSETSW
241#define tcgetattr(f, t) ioctl(f, TCGETS, (char *)t)
242
243#elif defined(TCSETA)
244#define TCSANOW TCSETA
245#define TCSADRAIN TCSETAW
246#define tcgetattr(f, t) ioctl(f, TCGETA, (char *)t)
247
248#else
249#define TCSANOW TIOCSETA
250#define TCSADRAIN TIOCSETAW
251#define tcgetattr(f, t) ioctl(f, TIOCGETA, (char *)t)
252
253#endif
254
255#define tcsetattr(f, a, t) ioctl(f, a, (char *)t)
256#define cfgetospeed(ptr) ((ptr)->c_cflag&CBAUD)
257#ifdef CIBAUD
258#define cfgetispeed(ptr) (((ptr)->c_cflag&CIBAUD) >> IBSHIFT)
259#else
260#define cfgetispeed(ptr) cfgetospeed(ptr)
261#endif
262
263#endif /* no TCSANOW */
264
265
266static void susp(int sig);
267
268void tlink_init(void) {
269#ifdef SIGTSTP
270 signal(SIGTSTP, susp);
271#endif
272 tout = fileno(stdout);
273 tin = fileno(stdin);
274}
275
276int tlink_getifd(void) {
277 return tin;
278}
279
280int tlink_getofd(void) {
281 return tout;
282}
283
284static int TerminalWrite(const char *buf, int n) {
285 int r;
286 do {
287 r = write(tout, buf, n);
288 } while (r<0 && errno==EINTR);
289 if (r<0 && (errno==ENOBUFS || errno==EWOULDBLOCK)) r = 0;
290 return r;
291}
292
293static int TerminalRead(char *buf, int n) {
294 int r;
295 do {
296 r = read(tin, buf, n);
297 } while (r<0 && errno==EINTR);
298 return r;
299}
300
301#ifdef SIGTSTP
302static void susp(int /*sig*/) {
303 if ((rlogin != _POSIX_VDISABLE) && rlogin_susp())
304 return;
305 if (localchars)
306 sendsusp();
307}
308#endif
309
310/*
311 * TerminalNewMode - set up terminal to a specific mode.
312 * MODE_ECHO: do local terminal echo
313 * MODE_FLOW: do local flow control
314 * MODE_TRAPSIG: do local mapping to TELNET IAC sequences
315 * MODE_EDIT: do local line editing
316 *
317 * Command mode:
318 * MODE_ECHO|MODE_EDIT|MODE_FLOW|MODE_TRAPSIG
319 * local echo
320 * local editing
321 * local xon/xoff
322 * local signal mapping
323 *
324 * Linemode:
325 * local/no editing
326 * Both Linemode and Single Character mode:
327 * local/remote echo
328 * local/no xon/xoff
329 * local/no signal mapping
330 */
331
332void TerminalNewMode(int f)
333{
334 static int prevmode = 0;
335 struct termios tmp_tc;
336
337 int onoff;
338 int old;
339 cc_t esc;
340
341 globalmode = f&~MODE_FORCE;
342 if (prevmode == f)
343 return;
344
345 /*
346 * Write any outstanding data before switching modes
347 * ttyflush() returns 0 only when there is no more data
348 * left to write out, it returns -1 if it couldn't do
349 * anything at all, otherwise it returns 1 + the number
350 * of characters left to write.
351 */
352 old = ttyflush(SYNCHing|flushout);
353 if (old < 0 || old > 1) {
354 tcgetattr(tin, &tmp_tc);
355 do {
356 /*
357 * Wait for data to drain, then flush again.
358 */
359 tcsetattr(tin, TCSADRAIN, &tmp_tc);
360 old = ttyflush(SYNCHing|flushout);
361 } while (old < 0 || old > 1);
362 }
363
364 old = prevmode;
365 prevmode = f&~MODE_FORCE;
366 tmp_tc = new_tc;
367
368 if (f&MODE_ECHO) {
369 tmp_tc.c_lflag |= ECHO;
370 tmp_tc.c_oflag |= ONLCR;
371 if (crlf)
372 tmp_tc.c_iflag |= ICRNL;
373 }
374 else {
375 tmp_tc.c_lflag &= ~ECHO;
376 tmp_tc.c_oflag &= ~ONLCR;
377 if (crlf) tmp_tc.c_iflag &= ~ICRNL;
378 }
379
380 if ((f&MODE_FLOW) == 0) {
381 tmp_tc.c_iflag &= ~(IXANY|IXOFF|IXON);
382 }
383 else {
384 tmp_tc.c_iflag |= IXANY|IXOFF|IXON;
385 }
386
387 if ((f&MODE_TRAPSIG) == 0) {
388 tmp_tc.c_lflag &= ~ISIG;
389 localchars = 0;
390 }
391 else {
392 tmp_tc.c_lflag |= ISIG;
393 localchars = 1;
394 }
395
396 if (f&MODE_EDIT) {
397 tmp_tc.c_lflag |= ICANON;
398 }
399 else {
400 tmp_tc.c_lflag &= ~ICANON;
401 tmp_tc.c_iflag &= ~ICRNL;
402 tmp_tc.c_cc[VMIN] = 1;
403 tmp_tc.c_cc[VTIME] = 0;
404 }
405
406 if ((f&(MODE_EDIT|MODE_TRAPSIG)) == 0) {
407#ifdef VLNEXT
408 tmp_tc.c_cc[VLNEXT] = (cc_t)(_POSIX_VDISABLE);
409#endif
410 }
411
412 if (f&MODE_SOFT_TAB) {
413#ifdef OXTABS
414 tmp_tc.c_oflag |= OXTABS;
415#endif
416#ifdef TABDLY
417 tmp_tc.c_oflag &= ~TABDLY;
418 tmp_tc.c_oflag |= TAB3;
419#endif
420 }
421 else {
422#ifdef OXTABS
423 tmp_tc.c_oflag &= ~OXTABS;
424#endif
425#ifdef TABDLY
426 tmp_tc.c_oflag &= ~TABDLY;
427#endif
428 }
429
430 if (f&MODE_LIT_ECHO) {
431#ifdef ECHOCTL
432 tmp_tc.c_lflag &= ~ECHOCTL;
433#endif
434 }
435 else {
436#ifdef ECHOCTL
437 tmp_tc.c_lflag |= ECHOCTL;
438#endif
439 }
440
441 if (f == -1) {
442 onoff = 0;
443 }
444 else {
445 if (f & MODE_INBIN) {
446 tmp_tc.c_iflag &= ~ISTRIP;
447 }
448 else {
449 // Commented this out 5/97 so it works with 8-bit characters
450 // ...and put it back 12/99 because it violates the RFC and
451 // breaks SunOS.
452 tmp_tc.c_iflag |= ISTRIP;
453 }
454 if (f & MODE_OUTBIN) {
455 tmp_tc.c_cflag &= ~(CSIZE|PARENB);
456 tmp_tc.c_cflag |= CS8;
457 tmp_tc.c_oflag &= ~OPOST;
458 } else {
459 tmp_tc.c_cflag &= ~(CSIZE|PARENB);
460 tmp_tc.c_cflag |= old_tc.c_cflag & (CSIZE|PARENB);
461 tmp_tc.c_oflag |= OPOST;
462 }
463 onoff = 1;
464 }
465
466 if (f != -1) {
467#ifdef SIGTSTP
468 signal(SIGTSTP, susp);
469#endif /* SIGTSTP */
470
471#ifdef SIGINFO
472 signal(SIGINFO, ayt);
473#endif SIGINFO
474
475#if defined(NOKERNINFO)
476 tmp_tc.c_lflag |= NOKERNINFO;
477#endif
478 /*
479 * We don't want to process ^Y here. It's just another
480 * character that we'll pass on to the back end. It has
481 * to process it because it will be processed when the
482 * user attempts to read it, not when we send it.
483 */
484#ifdef VDSUSP
485 tmp_tc.c_cc[VDSUSP] = (cc_t)(_POSIX_VDISABLE);
486#endif
487 /*
488 * If the VEOL character is already set, then use VEOL2,
489 * otherwise use VEOL.
490 */
491 esc = (rlogin != _POSIX_VDISABLE) ? rlogin : escapechar;
492 if ((tmp_tc.c_cc[VEOL] != esc)
493#ifdef VEOL2
494 && (tmp_tc.c_cc[VEOL2] != esc)
495#endif
496 ) {
497 if (tmp_tc.c_cc[VEOL] == (cc_t)(_POSIX_VDISABLE))
498 tmp_tc.c_cc[VEOL] = esc;
499#ifdef VEOL2
500 else if (tmp_tc.c_cc[VEOL2] == (cc_t)(_POSIX_VDISABLE))
501 tmp_tc.c_cc[VEOL2] = esc;
502#endif
503 }
504 }
505 else {
506
507#ifdef SIGINFO
508 signal(SIGINFO, ayt_status);
509#endif SIGINFO
510
511#ifdef SIGTSTP
512 signal(SIGTSTP, SIG_DFL);
513/* (void) sigsetmask(sigblock(0) & ~(1<<(SIGTSTP-1))); */
514#endif /* SIGTSTP */
515
516 tmp_tc = old_tc;
517 }
518 if (tcsetattr(tin, TCSADRAIN, &tmp_tc) < 0)
519 tcsetattr(tin, TCSANOW, &tmp_tc);
520
521 ioctl(tin, FIONBIO, (char *)&onoff);
522 ioctl(tout, FIONBIO, (char *)&onoff);
523
524#if defined(TN3270)
525 if (noasynchtty == 0) {
526 ioctl(tin, FIOASYNC, (char *)&onoff);
527 }
528#endif /* defined(TN3270) */
529
530}
531
532#ifndef B19200
533#define B19200 B9600
534#endif
535
536#ifndef B38400
537#define B38400 B19200
538#endif
539
540#ifndef B57600
541#define B57600 B38400
542#endif
543
544#ifndef B115200
545#define B115200 B57600
546#endif
547
548/*
549 * This code assumes that the values B0, B50, B75...
550 * are in ascending order. They do not have to be
551 * contiguous.
552 */
553struct termspeeds {
554 long speed;
555 long value;
556} termspeeds[] = {
557 { 0, B0 }, { 50, B50 }, { 75, B75 },
558 { 110, B110 }, { 134, B134 }, { 150, B150 },
559 { 200, B200 }, { 300, B300 }, { 600, B600 },
560 { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
561 { 4800, B4800 }, { 9600, B9600 }, { 19200, B19200 },
562 { 38400, B38400 }, { 57600, B57600 }, { 115200, B115200 },
563 { -1, B115200 }
564};
565
566void TerminalSpeeds(long *ispeed, long *ospeed) {
567 register struct termspeeds *tp;
568 register long in, out;
569
570 out = cfgetospeed(&old_tc);
571 in = cfgetispeed(&old_tc);
572 if (in == 0)
573 in = out;
574
575 tp = termspeeds;
576 while ((tp->speed != -1) && (tp->value < in))
577 tp++;
578 *ispeed = tp->speed;
579
580 tp = termspeeds;
581 while ((tp->speed != -1) && (tp->value < out))
582 tp++;
583 *ospeed = tp->speed;
584}
585
586int TerminalWindowSize(long *rows, long *cols) {
587#ifdef TIOCGWINSZ
588 struct winsize ws;
589
590 if (ioctl(fileno(stdin), TIOCGWINSZ, (char *)&ws) >= 0) {
591 *rows = ws.ws_row;
592 *cols = ws.ws_col;
593 return 1;
594 }
595#endif /* TIOCGWINSZ */
596 return 0;
597}
598
599
600/*
601 * EmptyTerminal - called to make sure that the terminal buffer is
602 * empty. Note that we consider the buffer to run all the way to the
603 * kernel (thus the select).
604 */
605void EmptyTerminal(void) {
606 fd_set o;
607 FD_ZERO(&o);
608
609 if (TTYBYTES() == 0) {
610 FD_SET(tout, &o);
611 select(tout+1, NULL, &o, NULL, NULL); /* wait for TTLOWAT */
612 }
613 else {
614 while (TTYBYTES()) {
615 ttyflush(0);
616 FD_SET(tout, &o);
617 select(tout+1, NULL, &o, NULL, NULL); /* wait for TTLOWAT */
618 }
619 }
620}
621
622int
623TerminalAutoFlush(void)
624{
625#if defined(LNOFLSH)
626 int flush;
627
628 ioctl(tin, TIOCLGET, (char *)&flush);
629 return !(flush&LNOFLSH); /* if LNOFLSH, no autoflush */
630#else /* LNOFLSH */
631 return 1;
632#endif /* LNOFLSH */
633}
634
635/*
636 * Flush output to the terminal
637 */
638 void
639TerminalFlushOutput()
640{
641#ifdef TIOCFLUSH
642 (void) ioctl(fileno(stdout), TIOCFLUSH, (char *) 0);
643#else
644 (void) ioctl(fileno(stdout), TCFLSH, (char *) 0);
645#endif
646}
647
648 void
649TerminalSaveState()
650{
651#ifndef USE_TERMIO
652 ioctl(0, TIOCGETP, (char *)&ottyb);
653 ioctl(0, TIOCGETC, (char *)&otc);
654 ioctl(0, TIOCGLTC, (char *)&oltc);
655 ioctl(0, TIOCLGET, (char *)&olmode);
656
657 ntc = otc;
658 nltc = oltc;
659 nttyb = ottyb;
660
661#else /* USE_TERMIO */
662 tcgetattr(0, &old_tc);
663
664 new_tc = old_tc;
665
666#ifndef VDISCARD
667 termFlushChar = CONTROL('O');
668#endif
669#ifndef VWERASE
670 termWerasChar = CONTROL('W');
671#endif
672#ifndef VREPRINT
673 termRprntChar = CONTROL('R');
674#endif
675#ifndef VLNEXT
676 termLiteralNextChar = CONTROL('V');
677#endif
678#ifndef VSTART
679 termStartChar = CONTROL('Q');
680#endif
681#ifndef VSTOP
682 termStopChar = CONTROL('S');
683#endif
684#ifndef VSTATUS
685 termAytChar = CONTROL('T');
686#endif
687#endif /* USE_TERMIO */
688}
689
690void TerminalDefaultChars(void) {
691#ifndef USE_TERMIO
692 ntc = otc;
693 nltc = oltc;
694 nttyb.sg_kill = ottyb.sg_kill;
695 nttyb.sg_erase = ottyb.sg_erase;
696#else /* USE_TERMIO */
697 memcpy(new_tc.c_cc, old_tc.c_cc, sizeof(old_tc.c_cc));
698#ifndef VDISCARD
699 termFlushChar = CONTROL('O');
700#endif
701#ifndef VWERASE
702 termWerasChar = CONTROL('W');
703#endif
704#ifndef VREPRINT
705 termRprntChar = CONTROL('R');
706#endif
707#ifndef VLNEXT
708 termLiteralNextChar = CONTROL('V');
709#endif
710#ifndef VSTART
711 termStartChar = CONTROL('Q');
712#endif
713#ifndef VSTOP
714 termStopChar = CONTROL('S');
715#endif
716#ifndef VSTATUS
717 termAytChar = CONTROL('T');
718#endif
719#endif /* USE_TERMIO */
720}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/terminal.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/terminal.h
new file mode 100644
index 0000000..8fcfb83
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/terminal.h
@@ -0,0 +1,11 @@
1#define TTYADD(c) { if (!(SYNCHing||flushout)) ttyoring.putch(c); }
2#define TTYBYTES() (ttyoring.full_count())
3#define TTYROOM() (ttyoring.empty_count())
4
5void tlink_init(void);
6
7void EmptyTerminal(void);
8
9
10int tlink_getifd(void);
11int tlink_getofd(void);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/tn3270.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/tn3270.cc
new file mode 100644
index 0000000..19f13fe
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/tn3270.cc
@@ -0,0 +1,366 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)tn3270.c 5.2 (Berkeley) 3/1/91
36 */
37char tn3270_rcsid[] =
38 "$Id: tn3270.cc,v 1.9 1996/08/13 09:08:34 dholland Exp $";
39
40#include <sys/types.h>
41#include <arpa/telnet.h>
42
43#include "defines.h"
44#include "ring.h"
45#include "externs.h"
46#include "proto.h"
47
48#if defined(TN3270)
49
50#include "../tn3270/ctlr/screen.h"
51#include "../tn3270/general/globals.h"
52
53#include "../tn3270/telextrn.h"
54#include "../tn3270/ctlr/externs.h"
55
56int HaveInput; /* There is input available to scan */
57int cursesdata; /* Do we dump curses data? */
58int sigiocount; /* Number of times we got a SIGIO */
59
60char tline[200];
61char *transcom = 0; /* transparent mode command (default: none) */
62
63char Ibuf[8*BUFSIZ], *Ifrontp, *Ibackp;
64
65static char sb_terminal[] = { IAC, SB,
66 TELOPT_TTYPE, TELQUAL_IS,
67 'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2',
68 IAC, SE };
69#define SBTERMMODEL 13
70
71static int Sent3270TerminalType; /* Have we said we are a 3270? */
72
73#endif /* defined(TN3270) */
74
75
76void init_3270(void) {
77#if defined(TN3270)
78 HaveInput = 0;
79 sigiocount = 0;
80 Sent3270TerminalType = 0;
81 Ifrontp = Ibackp = Ibuf;
82 init_ctlr(); /* Initialize some things */
83 init_keyboard();
84 init_screen();
85 init_system();
86#endif /* TN3270 */
87}
88
89#if defined(TN3270)
90
91/*
92 * DataToNetwork - queue up some data to go to network. If "done" is set,
93 * then when last byte is queued, we add on an IAC EOR sequence (so,
94 * don't call us with "done" until you want that done...)
95 *
96 * We actually do send all the data to the network buffer, since our
97 * only client needs for us to do that.
98 */
99
100/*
101 * buffer: where the data is
102 * count: how much to send
103 * done: is this the last of a logical block
104 */
105int DataToNetwork(char *buffer, int count, int done) {
106 register int loop, c;
107 int origCount;
108
109 origCount = count;
110
111 while (count) {
112 /* If not enough room for EORs, IACs, etc., wait */
113 if (NETROOM() < 6) {
114 fd_set o;
115
116 FD_ZERO(&o);
117 netflush();
118 while (NETROOM() < 6) {
119 FD_SET(net, &o);
120 select(net+1, (fd_set *) 0, &o, (fd_set *) 0,
121 (struct timeval *) 0);
122 netflush();
123 }
124 }
125 c = ring_empty_count(&netoring);
126 if (c > count) {
127 c = count;
128 }
129 loop = c;
130 while (loop) {
131 if (((unsigned char)*buffer) == IAC) {
132 break;
133 }
134 buffer++;
135 loop--;
136 }
137 if ((c = c-loop)) {
138 netoring.supply_data(buffer-c, c);
139 count -= c;
140 }
141 if (loop) {
142 NET2ADD(IAC, IAC);
143 count--;
144 buffer++;
145 }
146 }
147
148 if (done) {
149 NET2ADD(IAC, EOR);
150 netflush(); /* try to move along as quickly as ... */
151 }
152 return(origCount - count);
153}
154
155void inputAvailable(void) {
156 HaveInput = 1;
157 sigiocount++;
158}
159
160void outputPurge(void) {
161 ttyflush(1);
162}
163
164
165/*
166 * The following routines are places where the various tn3270
167 * routines make calls into telnet.c.
168 */
169
170/*
171 * DataToTerminal - queue up some data to go to terminal.
172 *
173 * Note: there are people who call us and depend on our processing
174 * *all* the data at one time (thus the select).
175 */
176
177/*
178 * buffer: where the data is
179 * count: how much to send
180 */
181int DataToTerminal(char *buffer, int count) {
182 register int c;
183 int origCount;
184
185 origCount = count;
186
187 while (count) {
188 if (TTYROOM() == 0) {
189
190 fd_set o;
191 FD_ZERO(&o);
192 ttyflush(0);
193 while (TTYROOM() == 0) {
194 FD_SET(tout, &o);
195 select(tout+1, NULL, &o, NULL, NULL);
196 ttyflush(0);
197 }
198 }
199 c = TTYROOM();
200 if (c > count) {
201 c = count;
202 }
203 ttyoring.supply_data(buffer, c);
204 count -= c;
205 buffer += c;
206 }
207 return origCount;
208}
209
210
211/*
212 * Push3270 - Try to send data along the 3270 output (to screen) direction.
213 */
214int Push3270(void) {
215 int save = ring_full_count(&netiring);
216
217 if (save) {
218 if (Ifrontp+save > Ibuf+sizeof Ibuf) {
219 if (Ibackp != Ibuf) {
220 memcpy(Ibuf, Ibackp, Ifrontp-Ibackp);
221 Ifrontp -= (Ibackp-Ibuf);
222 Ibackp = Ibuf;
223 }
224 }
225 if (Ifrontp+save < Ibuf+sizeof Ibuf) {
226 (void)telrcv();
227 }
228 }
229 return save != ring_full_count(&netiring);
230}
231
232
233/*
234 * Finish3270 - get the last dregs of 3270 data out to the terminal
235 * before quitting.
236 */
237void Finish3270(void) {
238 while (Push3270() || !DoTerminalOutput()) {
239 HaveInput = 0;
240 }
241}
242
243
244/* StringToTerminal - output a null terminated string to the terminal */
245void StringToTerminal(char *s) {
246 int count = strlen(s);
247 if (count) {
248 DataToTerminal(s, count); /* we know it always goes... */
249 }
250}
251
252
253#if ((!defined(NOT43)) || defined(PUTCHAR))
254/* _putchar - output a single character to the terminal. This name is so that
255 * curses(3x) can call us to send out data.
256 */
257
258void _putchar(char c) {
259#if defined(sun) /* SunOS 4.0 bug */
260 c &= 0x7f;
261#endif
262 if (cursesdata) {
263 Dump('>', &c, 1);
264 }
265 if (!TTYROOM()) {
266 DataToTerminal(&c, 1);
267 }
268 else {
269 TTYADD(c);
270 }
271}
272#endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
273
274void SetIn3270(void) {
275 if (Sent3270TerminalType && my_want_state_is_will(TELOPT_BINARY)
276 && my_want_state_is_do(TELOPT_BINARY) && !donebinarytoggle)
277 {
278 if (!In3270) {
279 In3270 = 1;
280 Init3270(); /* Initialize 3270 functions */
281 /* initialize terminal key mapping */
282 InitTerminal(); /* Start terminal going */
283 setconnmode(0);
284 }
285 }
286 else {
287 if (In3270) {
288 StopScreen(1);
289 In3270 = 0;
290 Stop3270(); /* Tell 3270 we aren't here anymore */
291 setconnmode(0);
292 }
293 }
294}
295
296/*
297 * tn3270_ttype()
298 *
299 * Send a response to a terminal type negotiation.
300 *
301 * Return '0' if no more responses to send; '1' if a response sent.
302 */
303
304int tn3270_ttype(void) {
305 /*
306 * Try to send a 3270 type terminal name. Decide which one based
307 * on the format of our screen, and (in the future) color
308 * capaiblities.
309 */
310 InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */
311 if ((MaxNumberLines >= 24) && (MaxNumberColumns >= 80)) {
312 Sent3270TerminalType = 1;
313 if ((MaxNumberLines >= 27) && (MaxNumberColumns >= 132)) {
314 MaxNumberLines = 27;
315 MaxNumberColumns = 132;
316 sb_terminal[SBTERMMODEL] = '5';
317 }
318 else if (MaxNumberLines >= 43) {
319 MaxNumberLines = 43;
320 MaxNumberColumns = 80;
321 sb_terminal[SBTERMMODEL] = '4';
322 }
323 else if (MaxNumberLines >= 32) {
324 MaxNumberLines = 32;
325 MaxNumberColumns = 80;
326 sb_terminal[SBTERMMODEL] = '3';
327 }
328 else {
329 MaxNumberLines = 24;
330 MaxNumberColumns = 80;
331 sb_terminal[SBTERMMODEL] = '2';
332 }
333 NumberLines = 24; /* before we start out... */
334 NumberColumns = 80;
335 ScreenSize = NumberLines*NumberColumns;
336 if ((MaxNumberLines*MaxNumberColumns) > MAXSCREENSIZE) {
337 ExitString("Programming error: MAXSCREENSIZE too small.\n",
338 1);
339 /*NOTREACHED*/
340 }
341 printsub('>', sb_terminal+2, sizeof sb_terminal-2);
342 netoring.supply_data(sb_terminal, sizeof(sb_terminal));
343 return 1;
344 }
345 else {
346 return 0;
347 }
348}
349
350int settranscom(int argc, char *argv[]) {
351 int i;
352 if (argc == 1 && transcom) {
353 transcom = 0;
354 }
355 if (argc == 1) {
356 return;
357 }
358 transcom = tline;
359 strcpy(transcom, argv[1]);
360 for (i = 2; i < argc; ++i) {
361 strcat(transcom, " ");
362 strcat(transcom, argv[i]);
363 }
364}
365
366#endif /* defined(TN3270) */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/types.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/types.h
new file mode 100644
index 0000000..00cddfb
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/types.h
@@ -0,0 +1,52 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)types.h 5.1 (Berkeley) 9/14/90
34 * $Id: types.h,v 1.2 1996/07/27 00:45:54 dholland Exp $
35 */
36
37typedef struct {
38 char *modedescriptions;
39 char modetype;
40} Modelist;
41
42extern Modelist modelist[];
43
44typedef struct {
45 int system; /* what the current time is */
46 int echotoggle; /* last time user entered echo character */
47 int modenegotiated; /* last time operating mode negotiated */
48 int didnetreceive; /* last time we read data from network */
49 int gotDM; /* when did we last see a data mark */
50} Clocks;
51
52extern Clocks clocks;
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnet/utilities.cc b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/utilities.cc
new file mode 100644
index 0000000..66839ab
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnet/utilities.cc
@@ -0,0 +1,675 @@
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)utilities.c 5.3 (Berkeley) 3/22/91
36 */
37char util_rcsid[] =
38 "$Id: utilities.cc,v 1.19 1999/12/12 15:33:40 dholland Exp $";
39
40#define TELOPTS
41#define TELCMDS
42#define SLC_NAMES
43
44#include <arpa/telnet.h>
45#include <sys/types.h>
46#include <sys/time.h>
47#include <sys/socket.h>
48#include <unistd.h>
49#include <ctype.h>
50#include <string.h>
51#include <stdlib.h>
52
53#include "ring.h"
54#include "defines.h"
55#include "externs.h"
56#include "proto.h"
57#include "terminal.h"
58
59FILE *NetTrace = 0; /* Not in bss, since needs to stay */ /* ? */
60char NetTraceFile[256] = "(standard output)";
61
62/*
63 * upcase()
64 *
65 * Upcase (in place) the argument.
66 */
67void upcase(char *str) {
68 for (int i=0; str[i]; i++) {
69 if (islower(str[i])) str[i] = toupper(str[i]);
70 }
71}
72
73/*
74 * The following are routines used to print out debugging information.
75 */
76
77void SetNetTrace(const char *file) {
78 if (NetTrace && NetTrace != stdout)
79 fclose(NetTrace);
80 if (file && strcmp(file, "-")) {
81 NetTrace = fopen(file, "w");
82 if (NetTrace) {
83 strcpy((char *)NetTraceFile, file);
84 return;
85 }
86 fprintf(stderr, "Cannot open %s.\n", file);
87 }
88 NetTrace = stdout;
89 strcpy((char *)NetTraceFile, "(standard output)");
90}
91
92#define BYTES_PER_LINE 32
93#define min(x,y) ((x<y)? x:y)
94
95void Dump(int direction, char *buffer, int length) {
96 char *pThis;
97 int offset;
98
99 offset = 0;
100
101 while (length) {
102 /* print one line */
103 fprintf(NetTrace, "%c 0x%x\t", direction, offset);
104 pThis = buffer;
105 if (0 /*prettydump*/) {
106 buffer = buffer + min(length, BYTES_PER_LINE/2);
107 while (pThis < buffer) {
108 fprintf(NetTrace, "%c%.2x",
109 (((*pThis)&0xff) == 0xff) ? '*' : ' ',
110 (*pThis)&0xff);
111 pThis++;
112 }
113 length -= BYTES_PER_LINE/2;
114 offset += BYTES_PER_LINE/2;
115 }
116 else {
117 buffer = buffer + min(length, BYTES_PER_LINE);
118 while (pThis < buffer) {
119 fprintf(NetTrace, "%.2x", (*pThis)&0xff);
120 pThis++;
121 }
122 length -= BYTES_PER_LINE;
123 offset += BYTES_PER_LINE;
124 }
125 if (NetTrace == stdout) {
126 fprintf(NetTrace, "\r\n");
127 }
128 else {
129 fprintf(NetTrace, "\n");
130 }
131 if (length < 0) {
132 fflush(NetTrace);
133 return;
134 }
135 /* find next unique line */
136 }
137 fflush(NetTrace);
138}
139
140
141void printoption(const char *direction, int cmd, int option) {
142 if (!showoptions)
143 return;
144 if (cmd == IAC) {
145 if (TELCMD_OK(option))
146 fprintf(NetTrace, "%s IAC %s", direction, TELCMD(option));
147 else
148 fprintf(NetTrace, "%s IAC %d", direction, option);
149 }
150 else {
151 const char *fmt;
152 fmt = (cmd == WILL) ? "WILL" : (cmd == WONT) ? "WONT" :
153 (cmd == DO) ? "DO" : (cmd == DONT) ? "DONT" : 0;
154 if (fmt) {
155 fprintf(NetTrace, "%s %s ", direction, fmt);
156 if (TELOPT_OK(option))
157 fprintf(NetTrace, "%s", TELOPT(option));
158 else if (option == TELOPT_EXOPL)
159 fprintf(NetTrace, "EXOPL");
160 else
161 fprintf(NetTrace, "%d", option);
162 }
163 else
164 fprintf(NetTrace, "%s %d %d", direction, cmd, option);
165 }
166 if (NetTrace == stdout)
167 fprintf(NetTrace, "\r\n");
168 else
169 fprintf(NetTrace, "\n");
170 return;
171}
172
173void optionstatus(void) {
174 int i;
175 extern char will_wont_resp[], do_dont_resp[];
176
177 for (i = 0; i < 256; i++) {
178 if (do_dont_resp[i]) {
179 if (TELOPT_OK(i))
180 printf("resp DO_DONT %s: %d\n", TELOPT(i), do_dont_resp[i]);
181 else if (TELCMD_OK(i))
182 printf("resp DO_DONT %s: %d\n", TELCMD(i), do_dont_resp[i]);
183 else
184 printf("resp DO_DONT %d: %d\n", i, do_dont_resp[i]);
185 if (my_want_state_is_do(i)) {
186 if (TELOPT_OK(i))
187 printf("want DO %s\n", TELOPT(i));
188 else if (TELCMD_OK(i))
189 printf("want DO %s\n", TELCMD(i));
190 else
191 printf("want DO %d\n", i);
192 }
193 else {
194 if (TELOPT_OK(i))
195 printf("want DONT %s\n", TELOPT(i));
196 else if (TELCMD_OK(i))
197 printf("want DONT %s\n", TELCMD(i));
198 else
199 printf("want DONT %d\n", i);
200 }
201 }
202 else {
203 if (my_state_is_do(i)) {
204 if (TELOPT_OK(i))
205 printf(" DO %s\n", TELOPT(i));
206 else if (TELCMD_OK(i))
207 printf(" DO %s\n", TELCMD(i));
208 else
209 printf(" DO %d\n", i);
210 }
211 }
212 if (will_wont_resp[i]) {
213 if (TELOPT_OK(i))
214 printf("resp WILL_WONT %s: %d\n", TELOPT(i), will_wont_resp[i]);
215 else if (TELCMD_OK(i))
216 printf("resp WILL_WONT %s: %d\n", TELCMD(i), will_wont_resp[i]);
217 else
218 printf("resp WILL_WONT %d: %d\n",
219 i, will_wont_resp[i]);
220 if (my_want_state_is_will(i)) {
221 if (TELOPT_OK(i))
222 printf("want WILL %s\n", TELOPT(i));
223 else if (TELCMD_OK(i))
224 printf("want WILL %s\n", TELCMD(i));
225 else
226 printf("want WILL %d\n", i);
227 }
228 else {
229 if (TELOPT_OK(i))
230 printf("want WONT %s\n", TELOPT(i));
231 else if (TELCMD_OK(i))
232 printf("want WONT %s\n", TELCMD(i));
233 else
234 printf("want WONT %d\n", i);
235 }
236 }
237 else {
238 if (my_state_is_will(i)) {
239 if (TELOPT_OK(i))
240 printf(" WILL %s\n", TELOPT(i));
241 else if (TELCMD_OK(i))
242 printf(" WILL %s\n", TELCMD(i));
243 else
244 printf(" WILL %d\n", i);
245 }
246 }
247 }
248
249}
250
251/* direction: '<' or '>' */
252/* pointer: where suboption data sits */
253/* length: length of suboption data */
254void printsub(int direction, unsigned char *pointer, int length) {
255 register int i = 0;
256
257 extern int want_status_response;
258
259 if (showoptions || direction == 0 ||
260 (want_status_response && (pointer[0] == TELOPT_STATUS))) {
261 if (direction) {
262 fprintf(NetTrace, "%s IAC SB ",
263 (direction == '<')? "RCVD":"SENT");
264 if (length >= 3) {
265 register int j;
266
267 i = pointer[length-2];
268 j = pointer[length-1];
269
270 if (i != IAC || j != SE) {
271 fprintf(NetTrace, "(terminated by ");
272 if (TELOPT_OK(i))
273 fprintf(NetTrace, "%s ", TELOPT(i));
274 else if (TELCMD_OK(i))
275 fprintf(NetTrace, "%s ", TELCMD(i));
276 else
277 fprintf(NetTrace, "%d ", i);
278 if (TELOPT_OK(j))
279 fprintf(NetTrace, "%s", TELOPT(j));
280 else if (TELCMD_OK(j))
281 fprintf(NetTrace, "%s", TELCMD(j));
282 else
283 fprintf(NetTrace, "%d", j);
284 fprintf(NetTrace, ", not IAC SE!) ");
285 }
286 }
287 length -= 2;
288 }
289 if (length < 1) {
290 fprintf(NetTrace, "(Empty suboption???)");
291 return;
292 }
293 switch ((unsigned char)(pointer[0])) {
294 case TELOPT_TTYPE:
295 fprintf(NetTrace, "TERMINAL-TYPE ");
296 switch (pointer[1]) {
297 case TELQUAL_IS:
298 fprintf(NetTrace, "IS \"%.*s\"", length-2, (char *)pointer+2);
299 break;
300 case TELQUAL_SEND:
301 fprintf(NetTrace, "SEND");
302 break;
303 default:
304 fprintf(NetTrace,
305 "- unknown qualifier %d (0x%x).",
306 pointer[1], pointer[1]);
307 }
308 break;
309 case TELOPT_TSPEED:
310 fprintf(NetTrace, "TERMINAL-SPEED");
311 if (length < 2) {
312 fprintf(NetTrace, " (empty suboption???)");
313 break;
314 }
315 switch (pointer[1]) {
316 case TELQUAL_IS:
317 fprintf(NetTrace, " IS ");
318 fprintf(NetTrace, "%.*s", length-2, (char *)pointer+2);
319 break;
320 default:
321 if (pointer[1] == 1)
322 fprintf(NetTrace, " SEND");
323 else
324 fprintf(NetTrace, " %d (unknown)", pointer[1]);
325 for (i = 2; i < length; i++)
326 fprintf(NetTrace, " ?%d?", pointer[i]);
327 break;
328 }
329 break;
330
331 case TELOPT_LFLOW:
332 fprintf(NetTrace, "TOGGLE-FLOW-CONTROL");
333 if (length < 2) {
334 fprintf(NetTrace, " (empty suboption???)");
335 break;
336 }
337 switch (pointer[1]) {
338 case 0:
339 fprintf(NetTrace, " OFF"); break;
340 case 1:
341 fprintf(NetTrace, " ON"); break;
342 default:
343 fprintf(NetTrace, " %d (unknown)", pointer[1]);
344 }
345 for (i = 2; i < length; i++)
346 fprintf(NetTrace, " ?%d?", pointer[i]);
347 break;
348
349 case TELOPT_NAWS:
350 fprintf(NetTrace, "NAWS");
351 if (length < 2) {
352 fprintf(NetTrace, " (empty suboption???)");
353 break;
354 }
355 if (length == 2) {
356 fprintf(NetTrace, " ?%d?", pointer[1]);
357 break;
358 }
359 fprintf(NetTrace, " %d %d (%d)",
360 pointer[1], pointer[2],
361 (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
362 if (length == 4) {
363 fprintf(NetTrace, " ?%d?", pointer[3]);
364 break;
365 }
366 fprintf(NetTrace, " %d %d (%d)",
367 pointer[3], pointer[4],
368 (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
369 for (i = 5; i < length; i++)
370 fprintf(NetTrace, " ?%d?", pointer[i]);
371 break;
372
373 case TELOPT_LINEMODE:
374 fprintf(NetTrace, "LINEMODE ");
375 if (length < 2) {
376 fprintf(NetTrace, " (empty suboption???)");
377 break;
378 }
379 switch ((unsigned char)(pointer[1])) {
380 case WILL:
381 fprintf(NetTrace, "WILL ");
382 goto common;
383 case WONT:
384 fprintf(NetTrace, "WONT ");
385 goto common;
386 case DO:
387 fprintf(NetTrace, "DO ");
388 goto common;
389 case DONT:
390 fprintf(NetTrace, "DONT ");
391 common:
392 if (length < 3) {
393 fprintf(NetTrace, "(no option???)");
394 break;
395 }
396 switch ((unsigned char)(pointer[2])) {
397 case LM_FORWARDMASK:
398 fprintf(NetTrace, "Forward Mask");
399 for (i = 3; i < length; i++)
400 fprintf(NetTrace, " %x", pointer[i]);
401 break;
402 default:
403 fprintf(NetTrace, "%d (unknown)", pointer[2]);
404 for (i = 3; i < length; i++)
405 fprintf(NetTrace, " %d", pointer[i]);
406 break;
407 }
408 break;
409
410 case LM_SLC:
411 fprintf(NetTrace, "SLC");
412 for (i = 2; i < length - 2; i += 3) {
413 if (SLC_NAME_OK(pointer[i+SLC_FUNC]))
414 fprintf(NetTrace, " %s", SLC_NAME(pointer[i+SLC_FUNC]));
415 else
416 fprintf(NetTrace, " %d", pointer[i+SLC_FUNC]);
417 switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {
418 case SLC_NOSUPPORT:
419 fprintf(NetTrace, " NOSUPPORT"); break;
420 case SLC_CANTCHANGE:
421 fprintf(NetTrace, " CANTCHANGE"); break;
422 case SLC_VARIABLE:
423 fprintf(NetTrace, " VARIABLE"); break;
424 case SLC_DEFAULT:
425 fprintf(NetTrace, " DEFAULT"); break;
426 }
427 fprintf(NetTrace, "%s%s%s",
428 pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",
429 pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",
430 pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");
431 if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|
432 SLC_FLUSHOUT| SLC_LEVELBITS))
433 fprintf(NetTrace, "(0x%x)", pointer[i+SLC_FLAGS]);
434 fprintf(NetTrace, " %d;", pointer[i+SLC_VALUE]);
435 if ((pointer[i+SLC_VALUE] == IAC) &&
436 (pointer[i+SLC_VALUE+1] == IAC))
437 i++;
438 }
439 for (; i < length; i++)
440 fprintf(NetTrace, " ?%d?", pointer[i]);
441 break;
442
443 case LM_MODE:
444 fprintf(NetTrace, "MODE ");
445 if (length < 3) {
446 fprintf(NetTrace, "(no mode???)");
447 break;
448 }
449 {
450 char tbuf[64];
451 snprintf(tbuf, sizeof(tbuf), "%s%s%s%s%s",
452 pointer[2]&MODE_EDIT ? "|EDIT" : "",
453 pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
454 pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
455 pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
456 pointer[2]&MODE_ACK ? "|ACK" : "");
457 fprintf(NetTrace, "%s", tbuf[1] ? &tbuf[1] : "0");
458 }
459 if (pointer[2]&~(MODE_MASK))
460 fprintf(NetTrace, " (0x%x)", pointer[2]);
461 for (i = 3; i < length; i++)
462 fprintf(NetTrace, " ?0x%x?", pointer[i]);
463 break;
464 default:
465 fprintf(NetTrace, "%d (unknown)", pointer[1]);
466 for (i = 2; i < length; i++)
467 fprintf(NetTrace, " %d", pointer[i]);
468 }
469 break;
470
471 case TELOPT_STATUS: {
472 const char *cp;
473 int j, k;
474
475 fprintf(NetTrace, "STATUS");
476
477 switch (pointer[1]) {
478 default:
479 if (pointer[1] == TELQUAL_SEND)
480 fprintf(NetTrace, " SEND");
481 else
482 fprintf(NetTrace, " %d (unknown)", pointer[1]);
483 for (i = 2; i < length; i++)
484 fprintf(NetTrace, " ?%d?", pointer[i]);
485 break;
486 case TELQUAL_IS:
487 if (--want_status_response < 0)
488 want_status_response = 0;
489 if (NetTrace == stdout)
490 fprintf(NetTrace, " IS\r\n");
491 else
492 fprintf(NetTrace, " IS\n");
493
494 for (i = 2; i < length; i++) {
495 switch((unsigned char)(pointer[i])) {
496 case DO: cp = "DO"; goto common2;
497 case DONT: cp = "DONT"; goto common2;
498 case WILL: cp = "WILL"; goto common2;
499 case WONT: cp = "WONT"; goto common2;
500 common2:
501 i++;
502 if (TELOPT_OK((int)pointer[i]))
503 fprintf(NetTrace, " %s %s", cp, TELOPT(pointer[i]));
504 else
505 fprintf(NetTrace, " %s %d", cp, pointer[i]);
506
507 if (NetTrace == stdout)
508 fprintf(NetTrace, "\r\n");
509 else
510 fprintf(NetTrace, "\n");
511 break;
512
513 case SB:
514 fprintf(NetTrace, " SB ");
515 i++;
516 j = k = i;
517 while (j < length) {
518 if (pointer[j] == SE) {
519 if (j+1 == length)
520 break;
521 if (pointer[j+1] == SE)
522 j++;
523 else
524 break;
525 }
526 pointer[k++] = pointer[j++];
527 }
528 printsub(0, &pointer[i], k - i);
529 if (i < length) {
530 fprintf(NetTrace, " SE");
531 i = j;
532 } else
533 i = j - 1;
534
535 if (NetTrace == stdout)
536 fprintf(NetTrace, "\r\n");
537 else
538 fprintf(NetTrace, "\n");
539
540 break;
541
542 default:
543 fprintf(NetTrace, " %d", pointer[i]);
544 break;
545 }
546 }
547 break;
548 }
549 break;
550 }
551
552 case TELOPT_XDISPLOC:
553 fprintf(NetTrace, "X-DISPLAY-LOCATION ");
554 switch (pointer[1]) {
555 case TELQUAL_IS:
556 fprintf(NetTrace, "IS \"%.*s\"", length-2, (char *)pointer+2);
557 break;
558 case TELQUAL_SEND:
559 fprintf(NetTrace, "SEND");
560 break;
561 default:
562 fprintf(NetTrace, "- unknown qualifier %d (0x%x).",
563 pointer[1], pointer[1]);
564 }
565 break;
566
567 case TELOPT_ENVIRON:
568 fprintf(NetTrace, "ENVIRON ");
569 switch (pointer[1]) {
570 case TELQUAL_IS:
571 fprintf(NetTrace, "IS ");
572 goto env_common;
573 case TELQUAL_SEND:
574 fprintf(NetTrace, "SEND ");
575 goto env_common;
576 case TELQUAL_INFO:
577 fprintf(NetTrace, "INFO ");
578 env_common:
579 {
580 register int noquote = 2;
581 for (i = 2; i < length; i++ ) {
582 switch (pointer[i]) {
583 case ENV_VAR:
584 if (pointer[1] == TELQUAL_SEND)
585 goto def_case;
586 fprintf(NetTrace, "\" VAR " + noquote);
587 noquote = 2;
588 break;
589
590 case ENV_VALUE:
591 fprintf(NetTrace, "\" VALUE " + noquote);
592 noquote = 2;
593 break;
594
595 case ENV_ESC:
596 fprintf(NetTrace, "\" ESC " + noquote);
597 noquote = 2;
598 break;
599
600 default:
601 def_case:
602 if (isprint(pointer[i]) && pointer[i] != '"') {
603 if (noquote) {
604 putc('"', NetTrace);
605 noquote = 0;
606 }
607 putc(pointer[i], NetTrace);
608 } else {
609 fprintf(NetTrace, "\" %03o " + noquote,
610 pointer[i]);
611 noquote = 2;
612 }
613 break;
614 }
615 }
616 if (!noquote)
617 putc('"', NetTrace);
618 break;
619 }
620 }
621 break;
622
623 default:
624 if (TELOPT_OK(pointer[0]))
625 fprintf(NetTrace, "%s (unknown)", TELOPT(pointer[0]));
626 else
627 fprintf(NetTrace, "%d (unknown)", pointer[i]);
628 for (i = 1; i < length; i++)
629 fprintf(NetTrace, " %d", pointer[i]);
630 break;
631 }
632 if (direction) {
633 if (NetTrace == stdout)
634 fprintf(NetTrace, "\r\n");
635 else
636 fprintf(NetTrace, "\n");
637 }
638 }
639}
640
641void SetForExit(void) {
642 setconnmode(0);
643#if defined(TN3270)
644 if (In3270) {
645 Finish3270();
646 }
647#else /* defined(TN3270) */
648 do {
649 telrcv(); /* Process any incoming data */
650 EmptyTerminal();
651 } while (netiring.full_count()); /* While there is any */
652#endif /* defined(TN3270) */
653 setcommandmode();
654 fflush(stdout);
655 fflush(stderr);
656#if defined(TN3270)
657 if (In3270) {
658 StopScreen(1);
659 }
660#endif /* defined(TN3270) */
661 setconnmode(0);
662 EmptyTerminal(); /* Flush the path to the tty */
663 setcommandmode();
664}
665
666void Exit(int returnCode) {
667 SetForExit();
668 exit(returnCode);
669}
670
671void ExitString(const char *string, int returnCode) {
672 SetForExit();
673 fwrite(string, 1, strlen(string), stderr);
674 exit(returnCode);
675}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/Makefile b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/Makefile
new file mode 100644
index 0000000..8ebd78e
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/Makefile
@@ -0,0 +1,38 @@
1all: telnetd
2
3include ../MCONFIG
4include ../MRULES
5
6# -DAUTHENTICATE
7
8# If having unused tty devices root.root and mode 600 bugs you,
9# take out -DPARANOID_TTYS.
10
11CFLAGS += '-DISSUE_FILE="/etc/issue.net"' -DPARANOID_TTYS \
12 -DNO_REVOKE -DKLUDGELINEMODE -DDIAGNOSTICS \
13 -DLOGIN_WRAPPER=\"/usr/lib/telnetlogin\"
14# LIBS += $(LIBTERMCAP)
15
16OBJS = telnetd.o state.o termstat.o slc.o sys_term.o utility.o \
17 global.o setproctitle.o
18
19# authenc.o (empty)
20
21# logout.o logwtmp.o (now from -lutil)
22
23
24telnetd: $(OBJS)
25 $(CC) $(LDFLAGS) $^ $(LIBS) -o $@
26
27$(OBJS): defs.h ext.h pathnames.h telnetd.h logwtmp.h logout.h setproctitle.h
28telnetd.o: ../version.h
29
30install: telnetd
31 install -s -m$(DAEMONMODE) telnetd $(INSTALLROOT)$(SBINDIR)/in.telnetd
32 install -m$(MANMODE) issue.net.5 $(INSTALLROOT)$(MANDIR)/man5/
33 install -m$(MANMODE) telnetd.8 $(INSTALLROOT)$(MANDIR)/man8/in.telnetd.8
34 ln -sf in.telnetd.8 $(INSTALLROOT)$(MANDIR)/man8/telnetd.8
35
36clean:
37 rm -f *.o telnetd
38
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/authenc.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/authenc.c
new file mode 100644
index 0000000..c01dfbc
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/authenc.c
@@ -0,0 +1,71 @@
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted provided
6 * that: (1) source distributions retain this entire copyright notice and
7 * comment, and (2) distributions including binaries display the following
8 * acknowledgement: ``This product includes software developed by the
9 * University of California, Berkeley and its contributors'' in the
10 * documentation or other materials provided with the distribution and in
11 * all advertising materials mentioning features or use of this software.
12 * Neither the name of the University nor the names of its contributors may
13 * be used to endorse or promote products derived from this software without
14 * specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20#if 0 /* dead code */
21
22/*
23 * From: @(#)authenc.c 5.1 (Berkeley) 3/1/91
24 */
25char authenc_rcsid[] =
26 "$Id: authenc.c,v 1.5 1999/12/12 14:59:44 dholland Exp $";
27
28#if defined(ENCRYPT) || defined(AUTHENTICATE)
29#include "telnetd.h"
30#include <libtelnet/misc.h>
31
32int
33net_write(str, len)
34 unsigned char *str;
35 int len;
36{
37 if (nfrontp + len < netobuf + BUFSIZ) {
38 bcopy((void *)str, (void *)nfrontp, len);
39 nfrontp += len;
40 return(len);
41 }
42 return(0);
43}
44
45int
46telnet_spin()
47{
48 ttloop();
49 return(0);
50}
51
52char *
53telnet_getenv(val)
54 char *val;
55{
56 extern char *getenv();
57 return(getenv(val));
58}
59
60char *
61telnet_gets(prompt, result, length, echo)
62 char *prompt;
63 char *result;
64 int length;
65 int echo;
66{
67 return((char *)0);
68}
69#endif
70
71#endif /* 0 */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/defs.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/defs.h
new file mode 100644
index 0000000..397948c
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/defs.h
@@ -0,0 +1,216 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)defs.h 5.10 (Berkeley) 3/1/91
34 * $Id: defs.h,v 1.7 1999/08/02 03:14:03 dholland Exp $
35 */
36
37/*
38 * Telnet server defines
39 */
40#include <sys/types.h>
41#include <sys/param.h>
42
43#define ENV_VAR NEW_ENV_VAR
44#define ENV_VALUE NEW_ENV_VALUE
45#define TELOPT_ENVIRON TELOPT_NEW_ENVIRON
46
47#if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
48#define TELOPTS
49#define TELCMDS
50#define SLC_NAMES
51#endif
52
53#include <sys/socket.h>
54#include <sys/wait.h>
55#include <fcntl.h>
56#include <sys/file.h>
57#include <sys/stat.h>
58#include <time.h>
59#include <sys/ioctl.h>
60#include <netinet/in.h>
61#include <arpa/telnet.h>
62#include <sys/uio.h>
63#include <stdio.h>
64#include <stdlib.h>
65#include <signal.h>
66#include <errno.h>
67#include <netdb.h>
68#include <syslog.h>
69
70#ifndef LOG_DAEMON
71#define LOG_DAEMON 0
72#endif
73
74#ifndef LOG_ODELAY
75#define LOG_ODELAY 0
76#endif
77
78#include <ctype.h>
79#include <string.h>
80#include <termios.h>
81
82#ifdef __STDC__
83#include <unistd.h>
84#endif
85
86#ifndef _POSIX_VDISABLE
87#ifdef VDISABLE
88#define _POSIX_VDISABLE VDISABLE
89#else
90#define _POSIX_VDISABLE ((unsigned char)'\377')
91#endif
92#endif
93
94/*
95 * I/O data buffers defines
96 */
97#define NETSLOP 64
98
99#define NIACCUM(c) { *netip++ = c; \
100 ncc++; \
101 }
102
103/* clock manipulations */
104#define settimer(x) (clocks.x = ++clocks.system)
105#define sequenceIs(x,y) (clocks.x < clocks.y)
106
107/*
108 * Linemode support states, in decreasing order of importance
109 */
110#define REAL_LINEMODE 0x02
111#define KLUDGE_LINEMODE 0x01
112#define NO_LINEMODE 0x00
113
114/*
115 * Structures of information for each special character function.
116 */
117typedef struct {
118 unsigned char flag; /* the flags for this function */
119 cc_t val; /* the value of the special character */
120} slcent, *Slcent;
121
122typedef struct {
123 slcent defset; /* the default settings */
124 slcent current; /* the current settings */
125 cc_t *sptr; /* a pointer to the char in */
126 /* system data structures */
127} slcfun, *Slcfun;
128
129#ifdef DIAGNOSTICS
130/*
131 * Diagnostics capabilities
132 */
133#define TD_REPORT 0x01 /* Report operations to client */
134#define TD_EXERCISE 0x02 /* Exercise client's implementation */
135#define TD_NETDATA 0x04 /* Display received data stream */
136#define TD_PTYDATA 0x08 /* Display data passed to pty */
137#define TD_OPTIONS 0x10 /* Report just telnet options */
138#endif /* DIAGNOSTICS */
139
140/*
141 * We keep track of each side of the option negotiation.
142 */
143
144#define MY_STATE_WILL 0x01
145#define MY_WANT_STATE_WILL 0x02
146#define MY_STATE_DO 0x04
147#define MY_WANT_STATE_DO 0x08
148
149/*
150 * Macros to check the current state of things
151 */
152
153#define my_state_is_do(opt) (options[opt]&MY_STATE_DO)
154#define my_state_is_will(opt) (options[opt]&MY_STATE_WILL)
155#define my_want_state_is_do(opt) (options[opt]&MY_WANT_STATE_DO)
156#define my_want_state_is_will(opt) (options[opt]&MY_WANT_STATE_WILL)
157
158#define my_state_is_dont(opt) (!my_state_is_do(opt))
159#define my_state_is_wont(opt) (!my_state_is_will(opt))
160#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt))
161#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt))
162
163#define set_my_state_do(opt) (options[opt] |= MY_STATE_DO)
164#define set_my_state_will(opt) (options[opt] |= MY_STATE_WILL)
165#define set_my_want_state_do(opt) (options[opt] |= MY_WANT_STATE_DO)
166#define set_my_want_state_will(opt) (options[opt] |= MY_WANT_STATE_WILL)
167
168#define set_my_state_dont(opt) (options[opt] &= ~MY_STATE_DO)
169#define set_my_state_wont(opt) (options[opt] &= ~MY_STATE_WILL)
170#define set_my_want_state_dont(opt) (options[opt] &= ~MY_WANT_STATE_DO)
171#define set_my_want_state_wont(opt) (options[opt] &= ~MY_WANT_STATE_WILL)
172
173/*
174 * Tricky code here. What we want to know is if the MY_STATE_WILL
175 * and MY_WANT_STATE_WILL bits have the same value. Since the two
176 * bits are adjacent, a little arithmatic will show that by adding
177 * in the lower bit, the upper bit will be set if the two bits were
178 * different, and clear if they were the same.
179 */
180#define my_will_wont_is_changing(opt) \
181 ((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
182
183#define my_do_dont_is_changing(opt) \
184 ((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
185
186/*
187 * Make everything symetrical
188 */
189
190#define HIS_STATE_WILL MY_STATE_DO
191#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO
192#define HIS_STATE_DO MY_STATE_WILL
193#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL
194
195#define his_state_is_do my_state_is_will
196#define his_state_is_will my_state_is_do
197#define his_want_state_is_do my_want_state_is_will
198#define his_want_state_is_will my_want_state_is_do
199
200#define his_state_is_dont my_state_is_wont
201#define his_state_is_wont my_state_is_dont
202#define his_want_state_is_dont my_want_state_is_wont
203#define his_want_state_is_wont my_want_state_is_dont
204
205#define set_his_state_do set_my_state_will
206#define set_his_state_will set_my_state_do
207#define set_his_want_state_do set_my_want_state_will
208#define set_his_want_state_will set_my_want_state_do
209
210#define set_his_state_dont set_my_state_wont
211#define set_his_state_wont set_my_state_dont
212#define set_his_want_state_dont set_my_want_state_wont
213#define set_his_want_state_wont set_my_want_state_dont
214
215#define his_will_wont_is_changing my_do_dont_is_changing
216#define his_do_dont_is_changing my_will_wont_is_changing
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/ext.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/ext.h
new file mode 100644
index 0000000..c21587f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/ext.h
@@ -0,0 +1,214 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)ext.h 5.7 (Berkeley) 3/1/91
34 * $Id: ext.h,v 1.9 1999/12/12 14:59:44 dholland Exp $
35 */
36
37/*
38 * Telnet server variable declarations
39 */
40extern char options[256];
41extern char do_dont_resp[256];
42extern char will_wont_resp[256];
43extern int linemode; /* linemode on/off */
44
45#ifdef LINEMODE
46extern int uselinemode; /* what linemode to use (on/off) */
47extern int editmode; /* edit modes in use */
48extern int useeditmode; /* edit modes to use */
49extern int alwayslinemode; /* command line option */
50#ifdef KLUDGELINEMODE
51extern int lmodetype; /* Client support for linemode */
52#endif /* KLUDGELINEMODE */
53#endif /* LINEMODE */
54
55extern int flowmode; /* current flow control state */
56
57#ifdef DIAGNOSTICS
58extern int diagnostic; /* telnet diagnostic capabilities */
59#endif /* DIAGNOSTICS */
60
61#ifdef BFTPDAEMON
62extern int bftpd; /* behave as bftp daemon */
63#endif /* BFTPDAEMON */
64
65#if defined(SecurID)
66extern int require_SecurID;
67#endif
68
69#if defined(AUTHENTICATE)
70extern int auth_level;
71#endif
72
73extern slcfun slctab[NSLC + 1]; /* slc mapping table */
74
75extern char *terminaltype;
76
77extern char *loginprg;
78
79/*
80 * I/O data buffers, pointers, and counters.
81 */
82extern char ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
83extern char netibuf[BUFSIZ], *netip;
84extern int pcc, ncc;
85extern FILE *netfile;
86
87/* printf into netobuf */
88#define netoprintf(fmt, ...) fprintf(netfile, fmt, ## __VA_ARGS__)
89
90extern int pty, net;
91extern char *line;
92extern int SYNCHing; /* we are in TELNET SYNCH mode */
93
94void _termstat(void);
95void add_slc(int, int, int);
96void check_slc(void);
97void change_slc(int, int, int);
98void cleanup(int) __attribute__ ((noreturn));
99void clientstat(int, int, int);
100void copy_termbuf(char *, int);
101void deferslc(void);
102void defer_terminit(void);
103void do_opt_slc(unsigned char *, int);
104void doeof(void);
105void dooption(int);
106void dontoption(int);
107void edithost(const char *, const char *);
108void fatal(int, const char *);
109void fatalperror(int, const char *);
110void get_slc_defaults(void);
111void init_env(void);
112void init_termbuf(void);
113void interrupt(void);
114void localstat(void);
115void netclear(void);
116void netflush(void);
117size_t netbuflen(int);
118void sendurg(const char *, size_t);
119
120#ifdef DIAGNOSTICS
121void printoption(const char *, int);
122void printdata(const char *, const char *, int);
123void printsub(char, unsigned char *, int);
124#endif
125
126void ptyflush(void);
127void putchr(int);
128void putf(const char *, char *);
129void recv_ayt(void);
130void send_do(int, int);
131void send_dont(int, int);
132void send_slc(void);
133void send_status(void);
134void send_will(int, int);
135void send_wont(int, int);
136void sendbrk(void);
137void sendsusp(void);
138void set_termbuf(void);
139void start_login(const char *, int, const char *);
140void start_slc(int);
141void startslave(const char *host, int autologin, char *autoname);
142
143#if defined(AUTHENTICATE)
144void start_slave(char *);
145#else
146void start_slave(char *, int, char *);
147#endif
148
149void suboption(void);
150void telrcv(void);
151void ttloop(void);
152void tty_binaryin(int);
153void tty_binaryout(int);
154
155int end_slc(unsigned char **);
156int getnpty(void);
157int getpty(void);
158int login_tty(int);
159int spcset(int, cc_t *, cc_t **);
160int stilloob(int);
161int terminit(void);
162int termstat(void);
163int tty_flowmode(void);
164int tty_isbinaryin(void);
165int tty_isbinaryout(void);
166int tty_iscrnl(void);
167int tty_isecho(void);
168int tty_isediting(void);
169int tty_islitecho(void);
170int tty_isnewmap(void);
171int tty_israw(void);
172int tty_issofttab(void);
173int tty_istrapsig(void);
174int tty_linemode(void);
175
176void tty_rspeed(int);
177void tty_setecho(int);
178void tty_setedit(int);
179void tty_setlinemode(int);
180void tty_setlitecho(int);
181void tty_setsig(int);
182void tty_setsofttab(int);
183void tty_tspeed(int);
184void willoption(int);
185void wontoption(int);
186#define writenet(b, l) fwrite(b, 1, l, netfile)
187void netopen(void);
188
189#if defined(ENCRYPT)
190extern void (*encrypt_output)(const unsigned char *, int);
191extern int (*decrypt_input)(int);
192extern char *nclearto;
193#endif
194
195
196/*
197 * The following are some clocks used to decide how to interpret
198 * the relationship between various variables.
199 */
200
201extern struct _clocks {
202 int system; /* what the current time is */
203 int echotoggle; /* last time user entered echo character */
204 int modenegotiated; /* last time operating mode negotiated */
205 int didnetreceive; /* last time we read data from network */
206 int ttypesubopt; /* ttype subopt is received */
207 int tspeedsubopt; /* tspeed subopt is received */
208 int environsubopt; /* environ subopt is received */
209 int xdisplocsubopt; /* xdisploc subopt is received */
210 int baseline; /* time started to do timed action */
211 int gotDM; /* when did we last see a data mark */
212} clocks;
213
214#define DEFAULT_IM "%i\r\n%s %r (%h) (%t)\r\n\r\n"
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/getent.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/getent.c
new file mode 100644
index 0000000..9e0d0f3
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/getent.c
@@ -0,0 +1,71 @@
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)getent.c 5.1 (Berkeley) 2/28/91
36 */
37char ge_rcsid[] =
38 "$Id: getent.c,v 1.3 1996/08/15 06:23:28 dholland Exp $";
39
40/*
41 * Copyright (c) 1991 Regents of the University of California.
42 * All rights reserved.
43 *
44 * Redistribution and use in source and binary forms are permitted provided
45 * that: (1) source distributions retain this entire copyright notice and
46 * comment, and (2) distributions including binaries display the following
47 * acknowledgement: ``This product includes software developed by the
48 * University of California, Berkeley and its contributors'' in the
49 * documentation or other materials provided with the distribution and in
50 * all advertising materials mentioning features or use of this software.
51 * Neither the name of the University nor the names of its contributors may
52 * be used to endorse or promote products derived from this software without
53 * specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
55 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
56 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
57 */
58
59#include <stdlib.h>
60
61int getent(char *cp, char *name) {
62 (void)cp;
63 (void)name;
64 return 0;
65}
66
67char *getstr(char *cp, char **cpp) {
68 (void)cp;
69 (void)cpp;
70 return NULL;
71}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/global.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/global.c
new file mode 100644
index 0000000..c8d1d2b
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/global.c
@@ -0,0 +1,97 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)global.c 5.2 (Berkeley) 6/1/90
36 */
37char global_rcsid[] =
38 "$Id: global.c,v 1.4 1999/12/12 14:59:44 dholland Exp $";
39
40/*
41 * Allocate global variables.
42 */
43
44#include "defs.h"
45#include "ext.h"
46
47/*
48 * Telnet server variable declarations
49 */
50char options[256];
51char do_dont_resp[256];
52char will_wont_resp[256];
53int linemode; /* linemode on/off */
54
55#ifdef LINEMODE
56int uselinemode; /* what linemode to use (on/off) */
57int editmode; /* edit modes in use */
58int useeditmode; /* edit modes to use */
59int alwayslinemode; /* command line option */
60# ifdef KLUDGELINEMODE
61int lmodetype; /* Client support for linemode */
62# endif /* KLUDGELINEMODE */
63#endif /* LINEMODE */
64
65int flowmode; /* current flow control state */
66
67#ifdef DIAGNOSTICS
68int diagnostic; /* telnet diagnostic capabilities */
69#endif /* DIAGNOSTICS */
70
71#ifdef BFTPDAEMON
72int bftpd; /* behave as bftp daemon */
73#endif /* BFTPDAEMON */
74
75#if defined(SecurID)
76int require_SecurID;
77#endif
78
79slcfun slctab[NSLC + 1]; /* slc mapping table */
80
81char *terminaltype;
82
83/*
84 * I/O data buffers, pointers, and counters.
85 */
86char ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
87
88char netibuf[BUFSIZ], *netip;
89
90int pcc, ncc;
91
92FILE *netfile;
93
94int pty, net;
95int SYNCHing; /* we are in TELNET SYNCH mode */
96
97struct _clocks clocks;
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/issue.net.5 b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/issue.net.5
new file mode 100644
index 0000000..ff5de09
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/issue.net.5
@@ -0,0 +1,43 @@
1.\" Copyright (c) 1994 Peter Tobias <tobias@server.et-inf.fho-emden.de>
2.\" This file may be distributed under the GNU General Public License.
3.\"
4.\" Changed to -mdoc by David A. Holland <dholland@ftp.uk.linux.org>
5.\" in order to work better with some NetKit maintenance scripts.
6.\"
7.Dd May 22, 1994
8.Dt ISSUE.NET 5
9.Os "Linux NetKit (0.17)"
10.Sh NAME
11.Nm issue.net
12.Nd identification file for telnet sessions
13.Sh DESCRIPTION
14The file
15.Pa /etc/issue.net
16is a text file which contains a message or system identification to be
17printed before the login prompt of a telnet session. It may contain
18various `%-char' sequences. The following sequences are supported by
19.Ic telnetd :
20.Bl -tag -offset indent -compact -width "abcde"
21.It %t
22- show the current tty
23.It %h
24- show the system node name (FQDN)
25.It %D
26- show the name of the NIS domain
27.It %d
28- show the current time and date
29.It %s
30- show the name of the operating system
31.It %m
32- show the machine (hardware) type
33.It %r
34- show the operating system release
35.It %v
36- show the operating system version
37.It %%
38- display a single '%' character
39.El
40.Sh FILES
41.Pa /etc/issue.net
42.Sh "SEE ALSO"
43.Xr in.telnetd 8
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/login.3 b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/login.3
new file mode 100644
index 0000000..5a8d20b
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/login.3
@@ -0,0 +1,107 @@
1.\" Copyright (c) 1995
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" This code is derived from software developed by the Computer Systems
5.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
6.\" BG 91-66 and contributed to Berkeley.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.Dd December 14, 1995
37.Dt LOGIN 3
38.Os "Linux NetKit (0.17)"
39.Sh NAME
40.Nm login ,
41.Nm logout ,
42.Nm logwtmp
43.Nd login utility functions
44.Sh SYNOPSIS
45.Fd #include <util.h>
46.Ft void
47.Fn login "struct utmp *ut"
48.Ft int
49.Fn logout "const char *line"
50.Ft void
51.Fn logwtmp "const char *line" "const char *name" "const char *host"
52.Sh DESCRIPTION
53The
54.Fn login ,
55.Fn logout ,
56and
57.Fn logwtmp
58functions operate on the database of current users in
59.Pa /var/run/utmp
60and on the logfile
61.Pa /var/log/wtmp
62of logins and logouts.
63.Pp
64The
65.Fn login
66function updates the
67.Pa /var/run/utmp
68and
69.Pa /var/log/wtmp
70files with user information contained in
71.Fa ut .
72.Pp
73The
74.Fn logout
75function removes the entry from
76.Pa /var/run/utmp
77corresponding to the device
78.Fa line .
79.Pp
80The
81.Fn logwtmp
82function adds an entry to
83.Pa /var/log/wtmp .
84Since
85.Fn login
86will add the appropriate entry for
87.Pa /var/log/wtmp
88during a login,
89.Fn logwtmp
90is usually used for logouts.
91.Sh RETURN VALUES
92.Fn logout
93returns non-zero if it was able to find and delete an entry for
94.Fa line ,
95and zero if there is no entry for
96.Fa line
97in
98.Pa /var/run/utmp .
99.Sh FILES
100.Bl -tag -width /var/run/wtmp -compact
101.It Pa /dev/\(**
102.It Pa /etc/ttys
103.It Pa /var/run/utmp
104.It Pa /var/log/wtmp
105.El
106.Sh SEE ALSO
107.Xr utmp 5
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/logout.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/logout.h
new file mode 100644
index 0000000..4141e31
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/logout.h
@@ -0,0 +1 @@
int logout(const char *line);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/logwtmp.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/logwtmp.h
new file mode 100644
index 0000000..3843a31
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/logwtmp.h
@@ -0,0 +1,5 @@
1/*
2 * Put this here instead of including <util.h>, since Linux is messed up
3 * and doesn't have <util.h>.
4 */
5void logwtmp(const char *_line, const char *name, const char *host);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/pathnames.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/pathnames.h
new file mode 100644
index 0000000..7af84bd
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/pathnames.h
@@ -0,0 +1,41 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)pathnames.h 5.5 (Berkeley) 6/28/90
34 * $Id: pathnames.h,v 1.3 1996/08/29 22:31:24 dholland Exp $
35 */
36
37#include <paths.h>
38
39#ifndef _PATH_LOGIN
40#define _PATH_LOGIN "/bin/login"
41#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.3 b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.3
new file mode 100644
index 0000000..9eb43e8
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.3
@@ -0,0 +1,73 @@
1.\" OpenBSD: setproctitle.3,v 1.4 1996/10/08 01:20:08 michaels Exp
2.\" $Id: setproctitle.3,v 1.13 2000/07/30 23:57:09 dholland Exp $
3.\"
4.\" Copyright (c) 1994, 1995 Christopher G. Demetriou
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\" must display the following acknowledgement:
17.\" This product includes software developed by Christopher G. Demetriou
18.\" for the NetBSD Project.
19.\" 3. The name of the author may not be used to endorse or promote products
20.\" derived from this software without specific prior written permission
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"
33.Dd April 13, 1994
34.Dt SETPROCTITLE 3
35.Os "Linux NetKit (0.17)"
36.Sh NAME
37.Nm setproctitle
38.Nd set process title
39.Sh SYNOPSIS
40.Fd #include <stdlib.h>
41.Ft void
42.Fn setproctitle "const char *fmt" "..."
43.Sh DESCRIPTION
44The
45.Fn setproctitle
46function sets the invoking process's title.
47The process title is set to the last component of the program
48name, followed by a colon and the formatted string specified
49by
50.Va fmt .
51If
52.Va fmt
53is NULL, the colon and formatted string are omitted.
54The length of a process title is limited to 2048 bytes.
55.Sh EXAMPLES
56Set the process title to the program name, with no further information:
57.Bd -literal -offset indent
58setproctitle(NULL);
59.Ed
60.Pp
61Set the process title to the program name, an informational string,
62and the process id:
63.Bd -literal -offset indent
64setproctitle("foo! (%d)", getpid());
65.Ed
66.Sh SEE ALSO
67.Xr ps 1 ,
68.Xr w 1 ,
69.Xr printf 3
70.Sh HISTORY
71The
72.Fn setproctitle
73function first appeared in NetBSD 0.9a.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.c
new file mode 100644
index 0000000..c207d05
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.c
@@ -0,0 +1,145 @@
1/*
2 * setproctitle implementation for linux.
3 * Stolen from sendmail 8.7.4 and bashed around by David A. Holland
4 */
5
6/*
7 * Copyright (c) 1983, 1995 Eric P. Allman
8 * Copyright (c) 1988, 1993
9 * The Regents of the University of California. All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * From: @(#)conf.c 8.243 (Berkeley) 11/20/95
40 */
41char setproctitle_rcsid[] =
42 "$Id: setproctitle.c,v 1.3 1999/12/10 23:06:39 bryce Exp $";
43
44#include <stdlib.h>
45#include <string.h>
46#include <unistd.h>
47#include <stdarg.h>
48#include <stdio.h>
49
50#include "setproctitle.h"
51/*
52** SETPROCTITLE -- set process title for ps
53**
54** Parameters:
55** fmt -- a printf style format string.
56** a, b, c -- possible parameters to fmt.
57**
58** Returns:
59** none.
60**
61** Side Effects:
62** Clobbers argv of our main procedure so ps(1) will
63** display the title.
64*/
65
66
67/*
68** Pointers for setproctitle.
69** This allows "ps" listings to give more useful information.
70*/
71
72static char **Argv = NULL; /* pointer to argument vector */
73static char *LastArgv = NULL; /* end of argv */
74static char Argv0[128]; /* program name */
75
76void
77initsetproctitle(int argc, char **argv, char **envp)
78{
79 register int i;
80 char *tmp;
81
82 /*
83 ** Move the environment so setproctitle can use the space at
84 ** the top of memory.
85 */
86
87 for (i = 0; envp[i] != NULL; i++)
88 continue;
89 __environ = (char **) malloc(sizeof (char *) * (i + 1));
90 for (i = 0; envp[i] != NULL; i++)
91 __environ[i] = strdup(envp[i]);
92 __environ[i] = NULL;
93
94 /*
95 ** Save start and extent of argv for setproctitle.
96 */
97
98 Argv = argv;
99 if (i > 0)
100 LastArgv = envp[i - 1] + strlen(envp[i - 1]);
101 else
102 LastArgv = argv[argc - 1] + strlen(argv[argc - 1]);
103
104 tmp = strrchr(argv[0], '/');
105 if (!tmp) tmp = argv[0];
106 else tmp++;
107 strncpy(Argv0, tmp, sizeof(Argv0));
108 Argv0[sizeof(Argv0)-1] = 0;
109}
110
111void
112setproctitle(const char *fmt, ...)
113{
114 register char *p;
115 register int i=0;
116 static char buf[2048];
117 va_list ap;
118
119 p = buf;
120
121 /* print progname: heading for grep */
122 /* This can't overflow buf due to the relative size of Argv0. */
123 (void) strcpy(p, Argv0);
124 (void) strcat(p, ": ");
125 p += strlen(p);
126
127 /* print the argument string */
128 va_start(ap, fmt);
129 (void) vsnprintf(p, sizeof(buf) - (p - buf), fmt, ap);
130 va_end(ap);
131
132 i = strlen(buf);
133
134 if (i > LastArgv - Argv[0] - 2)
135 {
136 i = LastArgv - Argv[0] - 2;
137 buf[i] = '\0';
138 }
139 (void) strcpy(Argv[0], buf);
140 p = &Argv[0][i];
141 while (p < LastArgv)
142 *p++ = '\0';
143 Argv[1] = NULL;
144}
145
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.h
new file mode 100644
index 0000000..8652ee8
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/setproctitle.h
@@ -0,0 +1,4 @@
1/* Call this from main. */
2void initsetproctitle(int argc, char **argv, char **envp);
3
4void setproctitle(const char *fmt, ...);
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/slc.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/slc.c
new file mode 100644
index 0000000..54579ea
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/slc.c
@@ -0,0 +1,456 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)slc.c 5.7 (Berkeley) 3/1/91
36 */
37char slc_rcsid[] =
38 "$Id: slc.c,v 1.5 1999/12/12 14:59:44 dholland Exp $";
39
40#include "telnetd.h"
41
42#ifdef LINEMODE
43/*
44 * local varibles
45 */
46static unsigned char *def_slcbuf = (unsigned char *)0;
47static int def_slclen = 0;
48static int slcchange; /* change to slc is requested */
49static int slcoff; /* offset into slc buffer */
50static unsigned char slcbuf[NSLC*6]; /* buffer for slc negotiation */
51
52static void add_slcbuf_raw_char(unsigned char ch) {
53 if (slcoff < sizeof(slcbuf)) {
54 slcbuf[slcoff++] = ch;
55 }
56}
57
58static void add_slcbuf_char(unsigned char ch) {
59 add_slcbuf_raw_char(ch);
60 if (ch==0xff) {
61 add_slcbuf_raw_char(0xff);
62 }
63}
64
65/*
66 * send_slc
67 *
68 * Write out the current special characters to the client.
69 */
70void send_slc(void) {
71 int i;
72
73 /*
74 * Send out list of triplets of special characters
75 * to client. We only send info on the characters
76 * that are currently supported.
77 */
78 for (i = 1; i <= NSLC; i++) {
79 if ((slctab[i].defset.flag & SLC_LEVELBITS) == SLC_NOSUPPORT)
80 continue;
81 add_slc((unsigned char)i, slctab[i].current.flag,
82 slctab[i].current.val);
83 }
84}
85
86/*
87 * default_slc
88 *
89 * Set pty special characters to all the defaults.
90 */
91void default_slc(void) {
92 int i;
93 for (i = 1; i <= NSLC; i++) {
94 slctab[i].current.val = slctab[i].defset.val;
95 if (slctab[i].current.val == (cc_t)(_POSIX_VDISABLE)) {
96 slctab[i].current.flag = SLC_NOSUPPORT;
97 }
98 else {
99 slctab[i].current.flag = slctab[i].defset.flag;
100 }
101 if (slctab[i].sptr) {
102 *(slctab[i].sptr) = slctab[i].defset.val;
103 }
104 }
105 slcchange = 1;
106}
107
108#endif /* LINEMODE */
109
110/*
111 * get_slc_defaults
112 *
113 * Initialize the slc mapping table.
114 */
115void get_slc_defaults(void) {
116 int i;
117 init_termbuf();
118 for (i = 1; i <= NSLC; i++) {
119 slctab[i].defset.flag = spcset(i, &slctab[i].defset.val,
120 &slctab[i].sptr);
121 slctab[i].current.flag = SLC_NOSUPPORT;
122 slctab[i].current.val = 0;
123 }
124}
125
126#ifdef LINEMODE
127/*
128 * add_slc
129 *
130 * Add an slc triplet to the slc buffer.
131 */
132void add_slc(char func, char flag, cc_t val) {
133 add_slcbuf_char(func);
134 add_slcbuf_char(flag);
135 add_slcbuf_char(val);
136}
137
138/*
139 * start_slc
140 *
141 * Get ready to process incoming slc's and respond to them.
142 *
143 * The parameter getit is non-zero if it is necessary to grab a copy
144 * of the terminal control structures.
145 */
146void start_slc(int getit) {
147 slcchange = 0;
148 if (getit) init_termbuf();
149 snprintf(slcbuf, sizeof(slcbuf), "%c%c%c%c",
150 IAC, SB, TELOPT_LINEMODE, LM_SLC);
151 slcoff = 4;
152}
153
154/*
155 * end_slc
156 *
157 * Finish up the slc negotiation. If something to send, then send it.
158 */
159int end_slc(unsigned char **bufp) {
160 /*
161 * If a change has occured, store the new terminal control
162 * structures back to the terminal driver.
163 */
164 if (slcchange) {
165 set_termbuf();
166 }
167
168 /*
169 * If the pty state has not yet been fully processed and there is a
170 * deferred slc request from the client, then do not send any
171 * sort of slc negotiation now. We will respond to the client's
172 * request very soon.
173 */
174 if (def_slcbuf && (terminit() == 0)) {
175 return 0;
176 }
177
178 if (slcoff > 4) {
179 if (bufp) {
180 *bufp = &slcbuf[4];
181 return(slcoff - 4);
182 }
183 else {
184 snprintf(slcbuf+slcoff, sizeof(slcbuf)-slcoff, "%c%c", IAC, SE);
185 slcoff += 2;
186 writenet(slcbuf, slcoff);
187 netflush(); /* force it out immediately */
188 }
189 }
190 return 0;
191}
192
193/*
194 * process_slc
195 *
196 * Figure out what to do about the client's slc
197 */
198void process_slc(unsigned char func, unsigned char flag, cc_t val) {
199 register int hislevel, mylevel, ack;
200
201 /*
202 * Ensure that we know something about this function
203 */
204 if (func > NSLC) {
205 add_slc(func, SLC_NOSUPPORT, 0);
206 return;
207 }
208
209 /*
210 * Process the special case requests of 0 SLC_DEFAULT 0
211 * and 0 SLC_VARIABLE 0. Be a little forgiving here, don't
212 * worry about whether the value is actually 0 or not.
213 */
214 if (func == 0) {
215 if ((flag = flag & SLC_LEVELBITS) == SLC_DEFAULT) {
216 default_slc();
217 send_slc();
218 }
219 else if (flag == SLC_VARIABLE) {
220 send_slc();
221 }
222 return;
223 }
224
225 /*
226 * Appears to be a function that we know something about. So
227 * get on with it and see what we know.
228 */
229
230 hislevel = flag & SLC_LEVELBITS;
231 mylevel = slctab[func].current.flag & SLC_LEVELBITS;
232 ack = flag & SLC_ACK;
233 /*
234 * ignore the command if:
235 * the function value and level are the same as what we already have;
236 * or the level is the same and the ack bit is set
237 */
238 if (hislevel == mylevel && (val == slctab[func].current.val || ack)) {
239 return;
240 }
241 else if (ack) {
242 /*
243 * If we get here, we got an ack, but the levels don't match.
244 * This shouldn't happen. If it does, it is probably because
245 * we have sent two requests to set a variable without getting
246 * a response between them, and this is the first response.
247 * So, ignore it, and wait for the next response.
248 */
249 return;
250 }
251 else {
252 change_slc(func, flag, val);
253 }
254}
255
256/*
257 * change_slc
258 *
259 * Process a request to change one of our special characters.
260 * Compare client's request with what we are capable of supporting.
261 */
262void change_slc(char func, char flag, cc_t val) {
263 register int hislevel, mylevel;
264
265 hislevel = flag & SLC_LEVELBITS;
266 mylevel = slctab[func].defset.flag & SLC_LEVELBITS;
267 /*
268 * If client is setting a function to NOSUPPORT
269 * or DEFAULT, then we can easily and directly
270 * accomodate the request.
271 */
272 if (hislevel == SLC_NOSUPPORT) {
273 slctab[func].current.flag = flag;
274 slctab[func].current.val = (cc_t)_POSIX_VDISABLE;
275 flag |= SLC_ACK;
276 add_slc(func, flag, val);
277 return;
278 }
279 if (hislevel == SLC_DEFAULT) {
280 /*
281 * Special case here. If client tells us to use
282 * the default on a function we don't support, then
283 * return NOSUPPORT instead of what we may have as a
284 * default level of DEFAULT.
285 */
286 if (mylevel == SLC_DEFAULT) {
287 slctab[func].current.flag = SLC_NOSUPPORT;
288 }
289 else {
290 slctab[func].current.flag = slctab[func].defset.flag;
291 }
292 slctab[func].current.val = slctab[func].defset.val;
293 add_slc(func, slctab[func].current.flag,
294 slctab[func].current.val);
295 return;
296 }
297
298 /*
299 * Client wants us to change to a new value or he
300 * is telling us that he can't change to our value.
301 * Some of the slc's we support and can change,
302 * some we do support but can't change,
303 * and others we don't support at all.
304 * If we can change it then we have a pointer to
305 * the place to put the new value, so change it,
306 * otherwise, continue the negotiation.
307 */
308 if (slctab[func].sptr) {
309 /*
310 * We can change this one.
311 */
312 slctab[func].current.val = val;
313 *(slctab[func].sptr) = val;
314 slctab[func].current.flag = flag;
315 flag |= SLC_ACK;
316 slcchange = 1;
317 add_slc(func, flag, val);
318 }
319 else {
320 /*
321 * It is not possible for us to support this
322 * request as he asks.
323 *
324 * If our level is DEFAULT, then just ack whatever was
325 * sent.
326 *
327 * If he can't change and we can't change,
328 * then degenerate to NOSUPPORT.
329 *
330 * Otherwise we send our level back to him, (CANTCHANGE
331 * or NOSUPPORT) and if CANTCHANGE, send
332 * our value as well.
333 */
334 if (mylevel == SLC_DEFAULT) {
335 slctab[func].current.flag = flag;
336 slctab[func].current.val = val;
337 flag |= SLC_ACK;
338 }
339 else if (hislevel == SLC_CANTCHANGE && mylevel == SLC_CANTCHANGE) {
340 flag &= ~SLC_LEVELBITS;
341 flag |= SLC_NOSUPPORT;
342 slctab[func].current.flag = flag;
343 }
344 else {
345 flag &= ~SLC_LEVELBITS;
346 flag |= mylevel;
347 slctab[func].current.flag = flag;
348 if (mylevel == SLC_CANTCHANGE) {
349 slctab[func].current.val = slctab[func].defset.val;
350 val = slctab[func].current.val;
351 }
352 }
353 add_slc(func, flag, val);
354 }
355}
356
357#if (VEOF == VMIN)
358cc_t oldeofc = '\004';
359#endif
360
361/*
362 * check_slc
363 *
364 * Check the special characters in use and notify the client if any have
365 * changed. Only those characters that are capable of being changed are
366 * likely to have changed. If a local change occurs, kick the support level
367 * and flags up to the defaults.
368 */
369void check_slc(void) {
370 int i;
371 for (i = 1; i <= NSLC; i++) {
372#if (VEOF == VMIN)
373 /*
374 * In a perfect world this would be a neat little
375 * function. But in this world, we should not notify
376 * client of changes to the VEOF char when
377 * ICANON is off, because it is not representing
378 * a special character.
379 */
380 if (i == SLC_EOF) {
381 if (!tty_isediting()) continue;
382 else if (slctab[i].sptr) oldeofc = *(slctab[i].sptr);
383 }
384#endif /* VEOF==VMIN */
385
386 if (slctab[i].sptr && (*(slctab[i].sptr) != slctab[i].current.val)) {
387 slctab[i].current.val = *(slctab[i].sptr);
388 if (*(slctab[i].sptr) == (cc_t)_POSIX_VDISABLE) {
389 slctab[i].current.flag = SLC_NOSUPPORT;
390 }
391 else {
392 slctab[i].current.flag = slctab[i].defset.flag;
393 }
394 add_slc((unsigned char)i, slctab[i].current.flag,
395 slctab[i].current.val);
396 }
397 }
398}
399
400/*
401 * do_opt_slc
402 *
403 * Process an slc option buffer. Defer processing of incoming slc's
404 * until after the terminal state has been processed. Save the first slc
405 * request that comes along, but discard all others.
406 *
407 * ptr points to the beginning of the buffer, len is the length.
408 */
409void do_opt_slc(unsigned char *ptr, int len) {
410 unsigned char func, flag;
411 cc_t val;
412 unsigned char *end = ptr + len;
413
414 if (terminit()) { /* go ahead */
415 while (ptr < end) {
416 func = *ptr++;
417 if (ptr >= end) break;
418 flag = *ptr++;
419 if (ptr >= end) break;
420 val = (cc_t)*ptr++;
421
422 process_slc(func, flag, val);
423
424 }
425 }
426 else {
427 /*
428 * save this slc buffer if it is the first, otherwise dump
429 * it.
430 */
431 if (def_slcbuf == NULL) {
432 def_slclen = len;
433 def_slcbuf = malloc((unsigned)len);
434 if (def_slcbuf == NULL) return; /* too bad */
435 bcopy(ptr, def_slcbuf, len);
436 }
437 }
438}
439
440/*
441 * deferslc
442 *
443 * Do slc stuff that was deferred.
444 */
445void deferslc(void) {
446 if (def_slcbuf) {
447 start_slc(1);
448 do_opt_slc(def_slcbuf, def_slclen);
449 end_slc(0);
450 free(def_slcbuf);
451 def_slcbuf = (unsigned char *)0;
452 def_slclen = 0;
453 }
454}
455
456#endif /* LINEMODE */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/state.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/state.c
new file mode 100644
index 0000000..0054ce9
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/state.c
@@ -0,0 +1,1407 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)state.c 5.10 (Berkeley) 3/22/91
36 */
37char state_rcsid[] =
38 "$Id: state.c,v 1.12 1999/12/12 19:41:44 dholland Exp $";
39
40#include "telnetd.h"
41
42int not42 = 1;
43
44static int envvarok(char *varp);
45
46static unsigned char doopt[] = { IAC, DO, '%', 'c', 0 };
47static unsigned char dont[] = { IAC, DONT, '%', 'c', 0 };
48unsigned char will[] = { IAC, WILL, '%', 'c', 0 };
49unsigned char wont[] = { IAC, WONT, '%', 'c', 0 };
50
51/*
52 * Buffer for sub-options, and macros
53 * for suboptions buffer manipulations
54 */
55unsigned char subbuffer[512], *subpointer=subbuffer, *subend=subbuffer;
56
57#define SB_CLEAR() subpointer = subbuffer;
58#define SB_TERM() { subend = subpointer; SB_CLEAR(); }
59#define SB_ACCUM(c) if (subpointer < (subbuffer + sizeof(subbuffer)-1)) { \
60 *subpointer++ = (c); \
61 }
62#define SB_GET() ((*subpointer++)&0xff)
63#define SB_EOF() (subpointer >= subend)
64#define SB_LEN() (subend - subpointer)
65
66
67
68/*
69 * State for recv fsm
70 */
71#define TS_DATA 0 /* base state */
72#define TS_IAC 1 /* look for double IAC's */
73#define TS_CR 2 /* CR-LF ->'s CR */
74#define TS_SB 3 /* throw away begin's... */
75#define TS_SE 4 /* ...end's (suboption negotiation) */
76#define TS_WILL 5 /* will option negotiation */
77#define TS_WONT 6 /* wont " */
78#define TS_DO 7 /* do " */
79#define TS_DONT 8 /* dont " */
80
81void telrcv(void) {
82 register int c;
83 static int state = TS_DATA;
84
85 while (ncc > 0) {
86 if ((&ptyobuf[BUFSIZ] - pfrontp) < 2) break;
87 c = *netip++ & 0377;
88 ncc--;
89
90#if defined(ENCRYPT)
91 if (decrypt_input) {
92 c = (*decrypt_input)(c);
93 }
94#endif
95 switch (state) {
96 case TS_CR:
97 state = TS_DATA;
98 /* Strip off \n or \0 after a \r */
99 if ((c == 0) || (c == '\n')) {
100 break;
101 }
102 /* FALL THROUGH */
103
104 case TS_DATA:
105 if (c == IAC) {
106 state = TS_IAC;
107 break;
108 }
109 /*
110 * We now map \r\n ==> \r for pragmatic reasons.
111 * Many client implementations send \r\n when
112 * the user hits the CarriageReturn key.
113 *
114 * We USED to map \r\n ==> \n, since \r\n says
115 * that we want to be in column 1 of the next
116 * printable line, and \n is the standard
117 * unix way of saying that (\r is only good
118 * if CRMOD is set, which it normally is).
119 */
120 if ((c == '\r') && his_state_is_wont(TELOPT_BINARY)) {
121#if defined(ENCRYPT)
122 int nc = *netip;
123 if (decrypt_input) {
124 nc = (*decrypt_input)(nc & 0xff);
125 }
126#endif
127#ifdef LINEMODE
128 /*
129 * If we are operating in linemode,
130 * convert to local end-of-line.
131 */
132 if (linemode && (ncc > 0) && (('\n' == nc) ||
133 ((0 == nc) && tty_iscrnl())) ) {
134 netip++; ncc--;
135 c = '\n';
136 }
137 else
138#endif
139 {
140#if defined(ENCRYPT)
141 if (decrypt_input)
142 (void)(*decrypt_input)(-1);
143#endif
144 state = TS_CR;
145 }
146 }
147 *pfrontp++ = c;
148 break;
149
150 case TS_IAC:
151 gotiac:
152 switch (c) {
153
154 /*
155 * Send the process on the pty side an
156 * interrupt. Do this with a NULL or
157 * interrupt char; depending on the tty mode.
158 */
159 case IP:
160 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
161 interrupt();
162 break;
163 case BREAK:
164 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
165 sendbrk();
166 break;
167
168 /*
169 * Are You There?
170 */
171 case AYT:
172 DIAG(TD_OPTIONS,
173 printoption("td: recv IAC", c));
174 recv_ayt();
175 break;
176
177 /*
178 * Abort Output
179 */
180 case AO:
181 {
182 static const char msg[] = { IAC, DM };
183 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
184 ptyflush(); /* half-hearted */
185 init_termbuf();
186
187 if (slctab[SLC_AO].sptr &&
188 *slctab[SLC_AO].sptr != (cc_t)(_POSIX_VDISABLE))
189 {
190 *pfrontp++ =
191 (unsigned char)*slctab[SLC_AO].sptr;
192 }
193
194 netclear(); /* clear buffer back */
195 sendurg(msg, sizeof(msg));
196 DIAG(TD_OPTIONS, printoption("td: send IAC", DM));
197 break;
198 }
199
200 /*
201 * Erase Character and
202 * Erase Line
203 */
204 case EC:
205 case EL:
206 {
207 cc_t ch;
208 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
209 ptyflush(); /* half-hearted */
210 init_termbuf();
211 if (c == EC) ch = *slctab[SLC_EC].sptr;
212 else ch = *slctab[SLC_EL].sptr;
213 if (ch != (cc_t)(_POSIX_VDISABLE))
214 *pfrontp++ = (unsigned char)ch;
215 break;
216 }
217
218 /*
219 * Check for urgent data...
220 */
221 case DM:
222 DIAG(TD_OPTIONS, printoption("td: recv IAC", c));
223 SYNCHing = stilloob(net);
224 settimer(gotDM);
225 break;
226
227 /*
228 * Begin option subnegotiation...
229 */
230 case SB:
231 state = TS_SB;
232 SB_CLEAR();
233 continue;
234
235 case WILL:
236 state = TS_WILL;
237 continue;
238
239 case WONT:
240 state = TS_WONT;
241 continue;
242
243 case DO:
244 state = TS_DO;
245 continue;
246
247 case DONT:
248 state = TS_DONT;
249 continue;
250
251 case EOR:
252 if (his_state_is_will(TELOPT_EOR)) doeof();
253 break;
254
255 /*
256 * Handle RFC 10xx Telnet linemode option additions
257 * to command stream (EOF, SUSP, ABORT).
258 */
259 case xEOF:
260 doeof();
261 break;
262
263 case SUSP:
264 sendsusp();
265 break;
266
267 case ABORT:
268 sendbrk();
269 break;
270
271 case IAC:
272 *pfrontp++ = c;
273 break;
274 }
275 state = TS_DATA;
276 break;
277
278 case TS_SB:
279 if (c == IAC) {
280 state = TS_SE;
281 }
282 else {
283 SB_ACCUM(c);
284 }
285 break;
286
287 case TS_SE:
288 if (c != SE) {
289 if (c != IAC) {
290 /*
291 * bad form of suboption negotiation.
292 * handle it in such a way as to avoid
293 * damage to local state. Parse
294 * suboption buffer found so far,
295 * then treat remaining stream as
296 * another command sequence.
297 */
298
299 /* for DIAGNOSTICS */
300 SB_ACCUM(IAC);
301 SB_ACCUM(c);
302 subpointer -= 2;
303
304 SB_TERM();
305 suboption();
306 state = TS_IAC;
307 goto gotiac;
308 }
309 SB_ACCUM(c);
310 state = TS_SB;
311 }
312 else {
313 /* for DIAGNOSTICS */
314 SB_ACCUM(IAC);
315 SB_ACCUM(SE);
316 subpointer -= 2;
317
318 SB_TERM();
319 suboption(); /* handle sub-option */
320 state = TS_DATA;
321 }
322 break;
323
324 case TS_WILL:
325 willoption(c);
326 state = TS_DATA;
327 continue;
328
329 case TS_WONT:
330 wontoption(c);
331 state = TS_DATA;
332 continue;
333
334 case TS_DO:
335 dooption(c);
336 state = TS_DATA;
337 continue;
338
339 case TS_DONT:
340 dontoption(c);
341 state = TS_DATA;
342 continue;
343
344 default:
345 syslog(LOG_ERR, "telnetd: panic state=%d\n", state);
346 printf("telnetd: panic state=%d\n", state);
347 exit(1);
348 }
349 }
350}
351
352/*
353 * The will/wont/do/dont state machines are based on Dave Borman's
354 * Telnet option processing state machine.
355 *
356 * These correspond to the following states:
357 * my_state = the last negotiated state
358 * want_state = what I want the state to go to
359 * want_resp = how many requests I have sent
360 * All state defaults are negative, and resp defaults to 0.
361 *
362 * When initiating a request to change state to new_state:
363 *
364 * if ((want_resp == 0 && new_state == my_state) || want_state == new_state) {
365 * do nothing;
366 * } else {
367 * want_state = new_state;
368 * send new_state;
369 * want_resp++;
370 * }
371 *
372 * When receiving new_state:
373 *
374 * if (want_resp) {
375 * want_resp--;
376 * if (want_resp && (new_state == my_state))
377 * want_resp--;
378 * }
379 * if ((want_resp == 0) && (new_state != want_state)) {
380 * if (ok_to_switch_to new_state)
381 * want_state = new_state;
382 * else
383 * want_resp++;
384 * send want_state;
385 * }
386 * my_state = new_state;
387 *
388 * Note that new_state is implied in these functions by the function itself.
389 * will and do imply positive new_state, wont and dont imply negative.
390 *
391 * Finally, there is one catch. If we send a negative response to a
392 * positive request, my_state will be the positive while want_state will
393 * remain negative. my_state will revert to negative when the negative
394 * acknowlegment arrives from the peer. Thus, my_state generally tells
395 * us not only the last negotiated state, but also tells us what the peer
396 * wants to be doing as well. It is important to understand this difference
397 * as we may wish to be processing data streams based on our desired state
398 * (want_state) or based on what the peer thinks the state is (my_state).
399 *
400 * This all works fine because if the peer sends a positive request, the data
401 * that we receive prior to negative acknowlegment will probably be affected
402 * by the positive state, and we can process it as such (if we can; if we
403 * can't then it really doesn't matter). If it is that important, then the
404 * peer probably should be buffering until this option state negotiation
405 * is complete.
406 *
407 */
408void send_do(int option, int init) {
409 if (init) {
410 if ((do_dont_resp[option] == 0 && his_state_is_will(option)) ||
411 his_want_state_is_will(option))
412 return;
413 /*
414 * Special case for TELOPT_TM: We send a DO, but pretend
415 * that we sent a DONT, so that we can send more DOs if
416 * we want to.
417 */
418 if (option == TELOPT_TM)
419 set_his_want_state_wont(option);
420 else
421 set_his_want_state_will(option);
422 do_dont_resp[option]++;
423 }
424 netoprintf((char *)doopt, option);
425
426 DIAG(TD_OPTIONS, printoption("td: send do", option));
427}
428
429#ifdef AUTHENTICATE
430extern void auth_request();
431#endif
432
433#ifdef LINEMODE
434static void doclientstat(void);
435#endif
436
437#ifdef ENCRYPT
438extern void encrypt_send_support();
439#endif
440
441void willoption(int option) {
442 int changeok = 0;
443 void (*func)(void) = 0;
444
445 /*
446 * process input from peer.
447 */
448
449 DIAG(TD_OPTIONS, printoption("td: recv will", option));
450
451 if (do_dont_resp[option]) {
452 do_dont_resp[option]--;
453 if (do_dont_resp[option] && his_state_is_will(option))
454 do_dont_resp[option]--;
455 }
456 if (do_dont_resp[option] == 0) {
457 if (his_want_state_is_wont(option)) {
458 switch (option) {
459
460 case TELOPT_BINARY:
461 init_termbuf();
462 tty_binaryin(1);
463 set_termbuf();
464 changeok++;
465 break;
466
467 case TELOPT_ECHO:
468 /*
469 * See comments below for more info.
470 */
471 not42 = 0; /* looks like a 4.2 system */
472 break;
473
474 case TELOPT_TM:
475#if defined(LINEMODE) && defined(KLUDGELINEMODE)
476 /*
477 * This telnetd implementation does not really
478 * support timing marks, it just uses them to
479 * support the kludge linemode stuff. If we
480 * receive a will or wont TM in response to our
481 * do TM request that may have been sent to
482 * determine kludge linemode support, process
483 * it, otherwise TM should get a negative
484 * response back.
485 */
486 /*
487 * Handle the linemode kludge stuff.
488 * If we are not currently supporting any
489 * linemode at all, then we assume that this
490 * is the client telling us to use kludge
491 * linemode in response to our query. Set the
492 * linemode type that is to be supported, note
493 * that the client wishes to use linemode, and
494 * eat the will TM as though it never arrived.
495 */
496 if (lmodetype < KLUDGE_LINEMODE) {
497 lmodetype = KLUDGE_LINEMODE;
498 clientstat(TELOPT_LINEMODE, WILL, 0);
499 send_wont(TELOPT_SGA, 1);
500 }
501#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
502 /*
503 * We never respond to a WILL TM, and
504 * we leave the state WONT.
505 */
506 return;
507
508 case TELOPT_LFLOW:
509 /*
510 * If we are going to support flow control
511 * option, then don't worry peer that we can't
512 * change the flow control characters.
513 */
514 slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS;
515 slctab[SLC_XON].defset.flag |= SLC_DEFAULT;
516 slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS;
517 slctab[SLC_XOFF].defset.flag |= SLC_DEFAULT;
518 case TELOPT_TTYPE:
519 case TELOPT_SGA:
520 case TELOPT_NAWS:
521 case TELOPT_TSPEED:
522 case TELOPT_XDISPLOC:
523 case TELOPT_ENVIRON:
524 changeok++;
525 break;
526
527#ifdef LINEMODE
528 case TELOPT_LINEMODE:
529#ifdef KLUDGELINEMODE
530 /*
531 * Note client's desire to use linemode.
532 */
533 lmodetype = REAL_LINEMODE;
534#endif /* KLUDGELINEMODE */
535 func = doclientstat;
536 changeok++;
537 break;
538#endif /* LINEMODE */
539
540#ifdef AUTHENTICATE
541 case TELOPT_AUTHENTICATION:
542 func = auth_request;
543 changeok++;
544 break;
545#endif
546
547#ifdef ENCRYPT
548 case TELOPT_ENCRYPT:
549 func = encrypt_send_support;
550 changeok++;
551 break;
552#endif
553
554 default:
555 break;
556 }
557 if (changeok) {
558 set_his_want_state_will(option);
559 send_do(option, 0);
560 }
561 else {
562 do_dont_resp[option]++;
563 send_dont(option, 0);
564 }
565 }
566 else {
567 /*
568 * Option processing that should happen when
569 * we receive conformation of a change in
570 * state that we had requested.
571 */
572 switch (option) {
573 case TELOPT_ECHO:
574 not42 = 0; /* looks like a 4.2 system */
575 /*
576 * Egads, he responded "WILL ECHO". Turn
577 * it off right now!
578 */
579 send_dont(option, 1);
580 /*
581 * "WILL ECHO". Kludge upon kludge!
582 * A 4.2 client is now echoing user input at
583 * the tty. This is probably undesireable and
584 * it should be stopped. The client will
585 * respond WONT TM to the DO TM that we send to
586 * check for kludge linemode. When the WONT TM
587 * arrives, linemode will be turned off and a
588 * change propogated to the pty. This change
589 * will cause us to process the new pty state
590 * in localstat(), which will notice that
591 * linemode is off and send a WILL ECHO
592 * so that we are properly in character mode and
593 * all is well.
594 */
595 break;
596#ifdef LINEMODE
597 case TELOPT_LINEMODE:
598# ifdef KLUDGELINEMODE
599 /*
600 * Note client's desire to use linemode.
601 */
602 lmodetype = REAL_LINEMODE;
603# endif /* KLUDGELINEMODE */
604 func = doclientstat;
605 break;
606#endif /* LINEMODE */
607
608#ifdef AUTHENTICATE
609 case TELOPT_AUTHENTICATION:
610 func = auth_request;
611 break;
612#endif
613
614#ifdef ENCRYPT
615 case TELOPT_ENCRYPT:
616 func = encrypt_send_support;
617 break;
618#endif
619 }
620 }
621 }
622 set_his_state_will(option);
623 if (func) (*func)();
624}
625
626void send_dont(int option, int init) {
627 if (init) {
628 if ((do_dont_resp[option] == 0 && his_state_is_wont(option)) ||
629 his_want_state_is_wont(option))
630 return;
631 set_his_want_state_wont(option);
632 do_dont_resp[option]++;
633 }
634 netoprintf((char *) dont, option);
635
636 DIAG(TD_OPTIONS, printoption("td: send dont", option));
637}
638
639void wontoption(int option) {
640 /*
641 * Process client input.
642 */
643
644 DIAG(TD_OPTIONS, printoption("td: recv wont", option));
645
646 if (do_dont_resp[option]) {
647 do_dont_resp[option]--;
648 if (do_dont_resp[option] && his_state_is_wont(option))
649 do_dont_resp[option]--;
650 }
651 if (do_dont_resp[option] == 0) {
652 if (his_want_state_is_will(option)) {
653 /* it is always ok to change to negative state */
654 switch (option) {
655 case TELOPT_ECHO:
656 not42 = 1; /* doesn't seem to be a 4.2 system */
657 break;
658
659 case TELOPT_BINARY:
660 init_termbuf();
661 tty_binaryin(0);
662 set_termbuf();
663 break;
664
665#ifdef LINEMODE
666 case TELOPT_LINEMODE:
667#ifdef KLUDGELINEMODE
668 /*
669 * If real linemode is supported, then client is
670 * asking to turn linemode off.
671 */
672 if (lmodetype != REAL_LINEMODE)
673 break;
674 lmodetype = KLUDGE_LINEMODE;
675# endif /* KLUDGELINEMODE */
676 clientstat(TELOPT_LINEMODE, WONT, 0);
677 break;
678#endif /* LINEMODE */
679
680 case TELOPT_TM:
681 /*
682 * If we get a WONT TM, and had sent a DO TM,
683 * don't respond with a DONT TM, just leave it
684 * as is. Short circut the state machine to
685 * achive this.
686 */
687 set_his_want_state_wont(TELOPT_TM);
688 return;
689
690 case TELOPT_LFLOW:
691 /*
692 * If we are not going to support flow control
693 * option, then let peer know that we can't
694 * change the flow control characters.
695 */
696 slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS;
697 slctab[SLC_XON].defset.flag |= SLC_CANTCHANGE;
698 slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS;
699 slctab[SLC_XOFF].defset.flag |= SLC_CANTCHANGE;
700 break;
701
702#if defined(AUTHENTICATE)
703 case TELOPT_AUTHENTICATION:
704 auth_finished(0, AUTH_REJECT);
705 break;
706#endif
707
708 /*
709 * For options that we might spin waiting for
710 * sub-negotiation, if the client turns off the
711 * option rather than responding to the request,
712 * we have to treat it here as if we got a response
713 * to the sub-negotiation, (by updating the timers)
714 * so that we'll break out of the loop.
715 */
716 case TELOPT_TTYPE:
717 settimer(ttypesubopt);
718 break;
719
720 case TELOPT_TSPEED:
721 settimer(tspeedsubopt);
722 break;
723
724 case TELOPT_XDISPLOC:
725 settimer(xdisplocsubopt);
726 break;
727
728 case TELOPT_ENVIRON:
729 settimer(environsubopt);
730 break;
731
732 default:
733 break;
734 }
735 set_his_want_state_wont(option);
736 if (his_state_is_will(option)) send_dont(option, 0);
737 }
738 else {
739 switch (option) {
740 case TELOPT_TM:
741#if defined(LINEMODE) && defined(KLUDGELINEMODE)
742 if (lmodetype < REAL_LINEMODE) {
743 lmodetype = NO_LINEMODE;
744 clientstat(TELOPT_LINEMODE, WONT, 0);
745 send_will(TELOPT_SGA, 1);
746 send_will(TELOPT_ECHO, 1);
747 }
748#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
749 break;
750
751#if defined(AUTHENTICATE)
752 case TELOPT_AUTHENTICATION:
753 auth_finished(0, AUTH_REJECT);
754 break;
755#endif
756 default:
757 break;
758 }
759 }
760 }
761} /* end of wontoption */
762
763void send_will(int option, int init) {
764 if (init) {
765 if ((will_wont_resp[option] == 0 && my_state_is_will(option))||
766 my_want_state_is_will(option))
767 return;
768 set_my_want_state_will(option);
769 will_wont_resp[option]++;
770 }
771 netoprintf((char *) will, option);
772
773 DIAG(TD_OPTIONS, printoption("td: send will", option));
774}
775
776#if !defined(LINEMODE) || !defined(KLUDGELINEMODE)
777/*
778 * When we get a DONT SGA, we will try once to turn it
779 * back on. If the other side responds DONT SGA, we
780 * leave it at that. This is so that when we talk to
781 * clients that understand KLUDGELINEMODE but not LINEMODE,
782 * we'll keep them in char-at-a-time mode.
783 */
784int turn_on_sga = 0;
785#endif
786
787void dooption(int option) {
788 int changeok = 0;
789
790 /*
791 * Process client input.
792 */
793
794 DIAG(TD_OPTIONS, printoption("td: recv do", option));
795
796 if (will_wont_resp[option]) {
797 will_wont_resp[option]--;
798 if (will_wont_resp[option] && my_state_is_will(option))
799 will_wont_resp[option]--;
800 }
801 if ((will_wont_resp[option] == 0) && (my_want_state_is_wont(option))) {
802 switch (option) {
803 case TELOPT_ECHO:
804#ifdef LINEMODE
805#ifdef KLUDGELINEMODE
806 if (lmodetype == NO_LINEMODE)
807#else
808 if (his_state_is_wont(TELOPT_LINEMODE))
809#endif
810#endif
811 {
812 init_termbuf();
813 tty_setecho(1);
814 set_termbuf();
815 }
816 changeok++;
817 break;
818
819 case TELOPT_BINARY:
820 init_termbuf();
821 tty_binaryout(1);
822 set_termbuf();
823 changeok++;
824 break;
825
826 case TELOPT_SGA:
827#if defined(LINEMODE) && defined(KLUDGELINEMODE)
828 /*
829 * If kludge linemode is in use, then we must
830 * process an incoming do SGA for linemode
831 * purposes.
832 */
833 if (lmodetype == KLUDGE_LINEMODE) {
834 /*
835 * Receipt of "do SGA" in kludge
836 * linemode is the peer asking us to
837 * turn off linemode. Make note of
838 * the request.
839 */
840 clientstat(TELOPT_LINEMODE, WONT, 0);
841 /*
842 * If linemode did not get turned off
843 * then don't tell peer that we did.
844 * Breaking here forces a wont SGA to
845 * be returned.
846 */
847 if (linemode) break;
848 }
849#else
850 turn_on_sga = 0;
851#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
852 changeok++;
853 break;
854
855 case TELOPT_STATUS:
856 changeok++;
857 break;
858
859 case TELOPT_TM:
860 /*
861 * Special case for TM. We send a WILL, but
862 * pretend we sent a WONT.
863 */
864 send_will(option, 0);
865 set_my_want_state_wont(option);
866 set_my_state_wont(option);
867 return;
868
869 case TELOPT_LOGOUT:
870 /*
871 * When we get a LOGOUT option, respond
872 * with a WILL LOGOUT, make sure that
873 * it gets written out to the network,
874 * and then just go away...
875 */
876 set_my_want_state_will(TELOPT_LOGOUT);
877 send_will(TELOPT_LOGOUT, 0);
878 set_my_state_will(TELOPT_LOGOUT);
879 (void)netflush();
880 cleanup(0);
881 /* NOT REACHED */
882 break;
883
884#if defined(ENCRYPT)
885 case TELOPT_ENCRYPT:
886 changeok++;
887 break;
888#endif
889 case TELOPT_LINEMODE:
890 case TELOPT_TTYPE:
891 case TELOPT_NAWS:
892 case TELOPT_TSPEED:
893 case TELOPT_LFLOW:
894 case TELOPT_XDISPLOC:
895 case TELOPT_ENVIRON:
896 default:
897 break;
898 }
899 if (changeok) {
900 set_my_want_state_will(option);
901 send_will(option, 0);
902 }
903 else {
904 will_wont_resp[option]++;
905 send_wont(option, 0);
906 }
907 }
908 set_my_state_will(option);
909}
910
911void send_wont(int option, int init) {
912 if (init) {
913 if ((will_wont_resp[option] == 0 && my_state_is_wont(option)) ||
914 my_want_state_is_wont(option))
915 return;
916 set_my_want_state_wont(option);
917 will_wont_resp[option]++;
918 }
919 netoprintf((char *)wont, option);
920
921 DIAG(TD_OPTIONS, printoption("td: send wont", option));
922}
923
924void dontoption(int option) {
925 /*
926 * Process client input.
927 */
928 DIAG(TD_OPTIONS, printoption("td: recv dont", option));
929
930 if (will_wont_resp[option]) {
931 will_wont_resp[option]--;
932 if (will_wont_resp[option] && my_state_is_wont(option))
933 will_wont_resp[option]--;
934 }
935 if ((will_wont_resp[option] == 0) && (my_want_state_is_will(option))) {
936 switch (option) {
937 case TELOPT_BINARY:
938 init_termbuf();
939 tty_binaryout(0);
940 set_termbuf();
941 break;
942
943 case TELOPT_ECHO: /* we should stop echoing */
944#ifdef LINEMODE
945#ifdef KLUDGELINEMODE
946 if (lmodetype == NO_LINEMODE)
947#else
948 if (his_state_is_wont(TELOPT_LINEMODE))
949#endif
950#endif
951 {
952 init_termbuf();
953 tty_setecho(0);
954 set_termbuf();
955 }
956 break;
957
958 case TELOPT_SGA:
959#if defined(LINEMODE) && defined(KLUDGELINEMODE)
960 /*
961 * If kludge linemode is in use, then we
962 * must process an incoming do SGA for
963 * linemode purposes.
964 */
965 if (lmodetype == KLUDGE_LINEMODE) {
966 /*
967 * The client is asking us to turn
968 * linemode on.
969 */
970 clientstat(TELOPT_LINEMODE, WILL, 0);
971 /*
972 * If we did not turn line mode on,
973 * then what do we say? Will SGA?
974 * This violates design of telnet.
975 * Gross. Very Gross.
976 */
977 }
978 break;
979#else
980 set_my_want_state_wont(option);
981 if (my_state_is_will(option))
982 send_wont(option, 0);
983 set_my_state_wont(option);
984 if (turn_on_sga ^= 1) send_will(option,1);
985 return;
986#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
987
988 default:
989 break;
990 }
991
992 set_my_want_state_wont(option);
993 if (my_state_is_will(option))
994 send_wont(option, 0);
995 }
996 set_my_state_wont(option);
997}
998
999/*
1000 * suboption()
1001 *
1002 * Look at the sub-option buffer, and try to be helpful to the other
1003 * side.
1004 *
1005 * Currently we recognize:
1006 *
1007 * Terminal type is
1008 * Linemode
1009 * Window size
1010 * Terminal speed
1011 */
1012void suboption(void) {
1013 int subchar;
1014
1015 DIAG(TD_OPTIONS, {netflush(); printsub('<', subpointer, SB_LEN()+2);});
1016
1017 subchar = SB_GET();
1018 switch (subchar) {
1019 case TELOPT_TSPEED: {
1020 int xspeed, rspeed;
1021 if (his_state_is_wont(TELOPT_TSPEED)) /* Ignore if option disabled */
1022 break;
1023
1024 settimer(tspeedsubopt);
1025 if (SB_EOF() || SB_GET() != TELQUAL_IS) return;
1026 xspeed = atoi((char *)subpointer);
1027
1028 while (SB_GET() != ',' && !SB_EOF());
1029 if (SB_EOF()) return;
1030
1031 rspeed = atoi((char *)subpointer);
1032 clientstat(TELOPT_TSPEED, xspeed, rspeed);
1033 break;
1034 }
1035
1036 case TELOPT_TTYPE: { /* Yaaaay! */
1037 static char terminalname[41];
1038
1039 if (his_state_is_wont(TELOPT_TTYPE)) /* Ignore if option disabled */
1040 break;
1041 settimer(ttypesubopt);
1042
1043 if (SB_EOF() || SB_GET() != TELQUAL_IS) {
1044 return; /* ??? XXX but, this is the most robust */
1045 }
1046
1047 terminaltype = terminalname;
1048
1049 while ((terminaltype < (terminalname + sizeof (terminalname) -1) ) &&
1050 !SB_EOF())
1051 {
1052 int c;
1053 c = SB_GET();
1054 if (isupper(c)) {
1055 c = tolower(c);
1056 }
1057 *terminaltype++ = c; /* accumulate name */
1058 }
1059 *terminaltype = 0;
1060 terminaltype = terminalname;
1061 break;
1062 }
1063
1064 case TELOPT_NAWS: {
1065 int xwinsize, ywinsize;
1066 if (his_state_is_wont(TELOPT_NAWS)) /* Ignore if option disabled */
1067 break;
1068
1069 if (SB_EOF()) return;
1070 xwinsize = SB_GET() << 8;
1071 if (SB_EOF()) return;
1072 xwinsize |= SB_GET();
1073 if (SB_EOF()) return;
1074 ywinsize = SB_GET() << 8;
1075 if (SB_EOF()) return;
1076 ywinsize |= SB_GET();
1077 clientstat(TELOPT_NAWS, xwinsize, ywinsize);
1078 break;
1079 }
1080
1081#ifdef LINEMODE
1082 case TELOPT_LINEMODE: {
1083 register int request;
1084
1085 if (his_state_is_wont(TELOPT_LINEMODE)) /* Ignore if option disabled */
1086 break;
1087 /*
1088 * Process linemode suboptions.
1089 */
1090 if (SB_EOF())
1091 break; /* garbage was sent */
1092 request = SB_GET(); /* get will/wont */
1093
1094 if (SB_EOF())
1095 break; /* another garbage check */
1096
1097 if (request == LM_SLC) { /* SLC is not preceeded by WILL or WONT */
1098 /*
1099 * Process suboption buffer of slc's
1100 */
1101 start_slc(1);
1102 do_opt_slc(subpointer, subend - subpointer);
1103 (void) end_slc(0);
1104 break;
1105 } else if (request == LM_MODE) {
1106 if (SB_EOF())
1107 return;
1108 useeditmode = SB_GET(); /* get mode flag */
1109 clientstat(LM_MODE, 0, 0);
1110 break;
1111 }
1112
1113 if (SB_EOF())
1114 break;
1115 switch (SB_GET()) { /* what suboption? */
1116 case LM_FORWARDMASK:
1117 /*
1118 * According to spec, only server can send request for
1119 * forwardmask, and client can only return a positive response.
1120 * So don't worry about it.
1121 */
1122
1123 default:
1124 break;
1125 }
1126 break;
1127 } /* end of case TELOPT_LINEMODE */
1128#endif
1129 case TELOPT_STATUS: {
1130 int mode;
1131
1132 if (SB_EOF())
1133 break;
1134 mode = SB_GET();
1135 switch (mode) {
1136 case TELQUAL_SEND:
1137 if (my_state_is_will(TELOPT_STATUS))
1138 send_status();
1139 break;
1140
1141 case TELQUAL_IS:
1142 break;
1143
1144 default:
1145 break;
1146 }
1147 break;
1148 } /* end of case TELOPT_STATUS */
1149
1150 case TELOPT_XDISPLOC: {
1151 if (SB_EOF() || SB_GET() != TELQUAL_IS)
1152 return;
1153 settimer(xdisplocsubopt);
1154 subpointer[SB_LEN()] = '\0';
1155 (void)setenv("DISPLAY", (char *)subpointer, 1);
1156 break;
1157 } /* end of case TELOPT_XDISPLOC */
1158
1159 case TELOPT_ENVIRON: {
1160 register int c;
1161 register char *cp, *varp, *valp;
1162
1163 if (SB_EOF())
1164 return;
1165 c = SB_GET();
1166 if (c == TELQUAL_IS)
1167 settimer(environsubopt);
1168 else if (c != TELQUAL_INFO)
1169 return;
1170
1171 while (!SB_EOF() && SB_GET() != ENV_VAR)
1172 ;
1173
1174 if (SB_EOF())
1175 return;
1176
1177 cp = varp = (char *)subpointer;
1178 valp = 0;
1179
1180 while (!SB_EOF()) {
1181 switch (c = SB_GET()) {
1182 case ENV_VALUE:
1183 *cp = '\0';
1184 cp = valp = (char *)subpointer;
1185 break;
1186
1187 case ENV_VAR:
1188 *cp = '\0';
1189 if (envvarok(varp)) {
1190 if (valp)
1191 (void)setenv(varp, valp, 1);
1192 else
1193 unsetenv(varp);
1194 }
1195 cp = varp = (char *)subpointer;
1196 valp = 0;
1197 break;
1198
1199 case ENV_ESC:
1200 if (SB_EOF())
1201 break;
1202 c = SB_GET();
1203 /* FALL THROUGH */
1204 default:
1205 /* I think this test is correct... */
1206 if (cp < subbuffer+sizeof(subbuffer)-1) *cp++ = c;
1207 break;
1208 }
1209 }
1210 *cp = '\0';
1211 if (envvarok(varp)) {
1212 if (valp)
1213 (void)setenv(varp, valp, 1);
1214 else
1215 unsetenv(varp);
1216 }
1217 break;
1218 } /* end of case TELOPT_ENVIRON */
1219#if defined(AUTHENTICATE)
1220 case TELOPT_AUTHENTICATION:
1221 if (SB_EOF())
1222 break;
1223 switch(SB_GET()) {
1224 case TELQUAL_SEND:
1225 case TELQUAL_REPLY:
1226 /*
1227 * These are sent by us and cannot be sent by
1228 * the client.
1229 */
1230 break;
1231 case TELQUAL_IS:
1232 auth_is(subpointer, SB_LEN());
1233 break;
1234 case TELQUAL_NAME:
1235 auth_name(subpointer, SB_LEN());
1236 break;
1237 }
1238 break;
1239#endif
1240#if defined(ENCRYPT)
1241 case TELOPT_ENCRYPT:
1242 if (SB_EOF())
1243 break;
1244 switch(SB_GET()) {
1245 case ENCRYPT_SUPPORT:
1246 encrypt_support(subpointer, SB_LEN());
1247 break;
1248 case ENCRYPT_IS:
1249 encrypt_is(subpointer, SB_LEN());
1250 break;
1251 case ENCRYPT_REPLY:
1252 encrypt_reply(subpointer, SB_LEN());
1253 break;
1254 case ENCRYPT_START:
1255 encrypt_start(subpointer, SB_LEN());
1256 break;
1257 case ENCRYPT_END:
1258 encrypt_end();
1259 break;
1260 case ENCRYPT_REQSTART:
1261 encrypt_request_start(subpointer, SB_LEN());
1262 break;
1263 case ENCRYPT_REQEND:
1264 /*
1265 * We can always send an REQEND so that we cannot
1266 * get stuck encrypting. We should only get this
1267 * if we have been able to get in the correct mode
1268 * anyhow.
1269 */
1270 encrypt_request_end();
1271 break;
1272 case ENCRYPT_ENC_KEYID:
1273 encrypt_enc_keyid(subpointer, SB_LEN());
1274 break;
1275 case ENCRYPT_DEC_KEYID:
1276 encrypt_dec_keyid(subpointer, SB_LEN());
1277 break;
1278 default:
1279 break;
1280 }
1281 break;
1282#endif
1283
1284 default:
1285 break;
1286 } /* end of switch */
1287
1288} /* end of suboption */
1289
1290#ifdef LINEMODE
1291static void doclientstat(void) {
1292 clientstat(TELOPT_LINEMODE, WILL, 0);
1293}
1294#endif
1295
1296#define ADD(c) *ncp++ = c;
1297#define ADD_DATA(c) { *ncp++ = c; if (c == SE) *ncp++ = c; }
1298
1299void send_status(void) {
1300 unsigned char statusbuf[256];
1301 register unsigned char *ncp;
1302 register unsigned char i;
1303
1304 ncp = statusbuf;
1305
1306 netflush(); /* get rid of anything waiting to go out */
1307
1308 ADD(IAC);
1309 ADD(SB);
1310 ADD(TELOPT_STATUS);
1311 ADD(TELQUAL_IS);
1312
1313 /*
1314 * We check the want_state rather than the current state,
1315 * because if we received a DO/WILL for an option that we
1316 * don't support, and the other side didn't send a DONT/WONT
1317 * in response to our WONT/DONT, then the "state" will be
1318 * WILL/DO, and the "want_state" will be WONT/DONT. We
1319 * need to go by the latter.
1320 */
1321 for (i = 0; i < NTELOPTS; i++) {
1322 if (my_want_state_is_will(i)) {
1323 ADD(WILL);
1324 ADD_DATA(i);
1325 if (i == IAC) ADD(IAC);
1326 }
1327 if (his_want_state_is_will(i)) {
1328 ADD(DO);
1329 ADD_DATA(i);
1330 if (i == IAC) ADD(IAC);
1331 }
1332 }
1333
1334 if (his_want_state_is_will(TELOPT_LFLOW)) {
1335 ADD(SB);
1336 ADD(TELOPT_LFLOW);
1337 ADD(flowmode);
1338 ADD(SE);
1339 }
1340
1341#ifdef LINEMODE
1342 if (his_want_state_is_will(TELOPT_LINEMODE)) {
1343 unsigned char *cp, *cpe;
1344 int len;
1345
1346 ADD(SB);
1347 ADD(TELOPT_LINEMODE);
1348 ADD(LM_MODE);
1349 ADD_DATA(editmode);
1350 if (editmode == IAC) ADD(IAC);
1351 ADD(SE);
1352
1353 ADD(SB);
1354 ADD(TELOPT_LINEMODE);
1355 ADD(LM_SLC);
1356 start_slc(0);
1357 send_slc();
1358 len = end_slc(&cp);
1359 for (cpe = cp + len; cp < cpe; cp++) ADD_DATA(*cp);
1360 ADD(SE);
1361 }
1362#endif /* LINEMODE */
1363
1364 ADD(IAC);
1365 ADD(SE);
1366
1367 writenet(statusbuf, ncp - statusbuf);
1368 netflush(); /* Send it on its way */
1369
1370 DIAG(TD_OPTIONS, {printsub('>', statusbuf, ncp - statusbuf); netflush();});
1371}
1372
1373/* check that variable is safe to pass to login or shell */
1374#if 0 /* insecure version */
1375static int envvarok(char *varp) {
1376 if (strncmp(varp, "LD_", strlen("LD_")) &&
1377 strncmp(varp, "ELF_LD_", strlen("ELF_LD_")) &&
1378 strncmp(varp, "AOUT_LD_", strlen("AOUT_LD_")) &&
1379 strncmp(varp, "_RLD_", strlen("_RLD_")) &&
1380 strcmp(varp, "LIBPATH") &&
1381 strcmp(varp, "ENV") &&
1382 strcmp(varp, "IFS"))
1383 {
1384 return 1;
1385 }
1386 else {
1387 /* optionally syslog(LOG_INFO) here */
1388 return 0;
1389 }
1390}
1391
1392#else
1393static int envvarok(char *varp) {
1394 /*
1395 * Allow only these variables.
1396 */
1397 if (!strcmp(varp, "TERM")) return 1;
1398 if (!strcmp(varp, "DISPLAY")) return 1;
1399 if (!strcmp(varp, "USER")) return 1;
1400 if (!strcmp(varp, "LOGNAME")) return 1;
1401 if (!strcmp(varp, "POSIXLY_CORRECT")) return 1;
1402
1403 /* optionally syslog(LOG_INFO) here */
1404 return 0;
1405}
1406
1407#endif
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/sys_term.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/sys_term.c
new file mode 100644
index 0000000..4ec45bb
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/sys_term.c
@@ -0,0 +1,744 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)sys_term.c 5.16 (Berkeley) 3/22/91
36 */
37char st_rcsid[] =
38 "$Id: sys_term.c,v 1.17 1999/12/17 14:28:47 dholland Exp $";
39
40#include <utmp.h>
41
42#include "telnetd.h"
43#include "pathnames.h"
44
45#if defined(__GLIBC__) && (__GLIBC__ >= 2)
46/* mmm, nonstandard */
47#include <pty.h>
48#else
49int openpty(int *, int *, char *, struct termios *, struct winsize *);
50#endif
51
52#define ARCH64 ((sizeof(void *)) == 8)
53#define ARCH32 ((sizeof(void *)) == 4)
54
55#if defined(AUTHENTICATE)
56#include <libtelnet/auth.h>
57#endif
58
59static struct termios termbuf, termbuf2; /* pty control structure */
60
61/*static int cleanopen(char *line);*/
62
63/*
64 * init_termbuf()
65 * copy_termbuf(cp)
66 * set_termbuf()
67 *
68 * These three routines are used to get and set the "termbuf" structure
69 * to and from the kernel. init_termbuf() gets the current settings.
70 * copy_termbuf() hands in a new "termbuf" to write to the kernel, and
71 * set_termbuf() writes the structure into the kernel.
72 */
73
74void init_termbuf(void) {
75 tcgetattr(pty, &termbuf);
76 termbuf2 = termbuf;
77}
78
79#if defined(LINEMODE) && defined(TIOCPKT_IOCTL)
80/*
81 * ?
82 */
83void copy_termbuf(char *cp, int len) {
84 if (len > sizeof(termbuf)) len = sizeof(termbuf);
85 bcopy(cp, (char *)&termbuf, len);
86 termbuf2 = termbuf;
87}
88#endif /* defined(LINEMODE) && defined(TIOCPKT_IOCTL) */
89
90void set_termbuf(void) {
91 if (memcmp(&termbuf, &termbuf2, sizeof(termbuf))) {
92 tcsetattr(pty, TCSANOW, &termbuf);
93 }
94}
95
96
97/*
98 * spcset(func, valp, valpp)
99 *
100 * This function takes various special characters (func), and
101 * sets *valp to the current value of that character, and
102 * *valpp to point to where in the "termbuf" structure that
103 * value is kept.
104 *
105 * It returns the SLC_ level of support for this function.
106 */
107
108
109int spcset(int func, cc_t *valp, cc_t **valpp) {
110
111#define setval(a, b) *valp = termbuf.c_cc[a]; \
112 *valpp = &termbuf.c_cc[a]; \
113 return(b);
114#define defval(a) *valp = ((cc_t)a); *valpp = (cc_t *)0; return(SLC_DEFAULT);
115
116 switch(func) {
117 case SLC_EOF:
118 setval(VEOF, SLC_VARIABLE);
119 case SLC_EC:
120 setval(VERASE, SLC_VARIABLE);
121 case SLC_EL:
122 setval(VKILL, SLC_VARIABLE);
123 case SLC_IP:
124 setval(VINTR, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
125 case SLC_ABORT:
126 setval(VQUIT, SLC_VARIABLE|SLC_FLUSHIN|SLC_FLUSHOUT);
127 case SLC_XON:
128#ifdef VSTART
129 setval(VSTART, SLC_VARIABLE);
130#else
131 defval(0x13);
132#endif
133 case SLC_XOFF:
134#ifdef VSTOP
135 setval(VSTOP, SLC_VARIABLE);
136#else
137 defval(0x11);
138#endif
139 case SLC_EW:
140#ifdef VWERASE
141 setval(VWERASE, SLC_VARIABLE);
142#else
143 defval(0);
144#endif
145 case SLC_RP:
146#ifdef VREPRINT
147 setval(VREPRINT, SLC_VARIABLE);
148#else
149 defval(0);
150#endif
151 case SLC_LNEXT:
152#ifdef VLNEXT
153 setval(VLNEXT, SLC_VARIABLE);
154#else
155 defval(0);
156#endif
157 case SLC_AO:
158#if !defined(VDISCARD) && defined(VFLUSHO)
159# define VDISCARD VFLUSHO
160#endif
161#ifdef VDISCARD
162 setval(VDISCARD, SLC_VARIABLE|SLC_FLUSHOUT);
163#else
164 defval(0);
165#endif
166 case SLC_SUSP:
167#ifdef VSUSP
168 setval(VSUSP, SLC_VARIABLE|SLC_FLUSHIN);
169#else
170 defval(0);
171#endif
172#ifdef VEOL
173 case SLC_FORW1:
174 setval(VEOL, SLC_VARIABLE);
175#endif
176#ifdef VEOL2
177 case SLC_FORW2:
178 setval(VEOL2, SLC_VARIABLE);
179#endif
180 case SLC_AYT:
181#ifdef VSTATUS
182 setval(VSTATUS, SLC_VARIABLE);
183#else
184 defval(0);
185#endif
186
187 case SLC_BRK:
188 case SLC_SYNCH:
189 case SLC_EOR:
190 defval(0);
191
192 default:
193 *valp = 0;
194 *valpp = 0;
195 return(SLC_NOSUPPORT);
196 }
197}
198
199/*
200 * getpty()
201 *
202 * Allocate a pty. As a side effect, the external character
203 * array "line" contains the name of the slave side.
204 *
205 * Returns the file descriptor of the opened pty.
206 */
207static char linedata[PATH_MAX];
208char *line = linedata;
209
210static int ptyslavefd=-1;
211
212int getpty(void) {
213 int masterfd;
214
215 if (openpty(&masterfd, &ptyslavefd, line, NULL, NULL)) {
216 return -1;
217 }
218 return masterfd;
219}
220
221#ifdef LINEMODE
222/*
223 * tty_flowmode() Find out if flow control is enabled or disabled.
224 * tty_linemode() Find out if linemode (external processing) is enabled.
225 * tty_setlinemod(on) Turn on/off linemode.
226 * tty_isecho() Find out if echoing is turned on.
227 * tty_setecho(on) Enable/disable character echoing.
228 * tty_israw() Find out if terminal is in RAW mode.
229 * tty_binaryin(on) Turn on/off BINARY on input.
230 * tty_binaryout(on) Turn on/off BINARY on output.
231 * tty_isediting() Find out if line editing is enabled.
232 * tty_istrapsig() Find out if signal trapping is enabled.
233 * tty_setedit(on) Turn on/off line editing.
234 * tty_setsig(on) Turn on/off signal trapping.
235 * tty_issofttab() Find out if tab expansion is enabled.
236 * tty_setsofttab(on) Turn on/off soft tab expansion.
237 * tty_islitecho() Find out if typed control chars are echoed literally
238 * tty_setlitecho() Turn on/off literal echo of control chars
239 * tty_tspeed(val) Set transmit speed to val.
240 * tty_rspeed(val) Set receive speed to val.
241 */
242
243int tty_flowmode(void) {
244 return (termbuf.c_iflag & IXON ? 1 : 0);
245}
246
247int tty_linemode(void) {
248 return (termbuf.c_lflag & EXTPROC);
249}
250
251void tty_setlinemode(int on) {
252#ifdef TIOCEXT
253 set_termbuf();
254 ioctl(pty, TIOCEXT, (char *)&on);
255 init_termbuf();
256#else /* !TIOCEXT */
257# ifdef EXTPROC
258 if (on) termbuf.c_lflag |= EXTPROC;
259 else termbuf.c_lflag &= ~EXTPROC;
260# endif
261#endif /* TIOCEXT */
262}
263
264int tty_isecho(void) {
265 return (termbuf.c_lflag & ECHO);
266}
267#endif /* LINEMODE */
268
269void tty_setecho(int on) {
270 if (on) termbuf.c_lflag |= ECHO;
271 else termbuf.c_lflag &= ~ECHO;
272}
273
274#if defined(LINEMODE) && defined(KLUDGELINEMODE)
275int tty_israw(void) {
276 return(!(termbuf.c_lflag & ICANON));
277}
278#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
279
280void tty_binaryin(int on) {
281 if (on) {
282 termbuf.c_iflag &= ~ISTRIP;
283 }
284 else {
285 termbuf.c_iflag |= ISTRIP;
286 }
287}
288
289void tty_binaryout(int on) {
290 if (on) {
291 termbuf.c_cflag &= ~(CSIZE|PARENB);
292 termbuf.c_cflag |= CS8;
293 termbuf.c_oflag &= ~OPOST;
294 }
295 else {
296 termbuf.c_cflag &= ~CSIZE;
297 termbuf.c_cflag |= CS7|PARENB;
298 termbuf.c_oflag |= OPOST;
299 }
300}
301
302int tty_isbinaryin(void) {
303 return (!(termbuf.c_iflag & ISTRIP));
304}
305
306int tty_isbinaryout(void) {
307 return (!(termbuf.c_oflag&OPOST));
308}
309
310#ifdef LINEMODE
311int tty_isediting(void) {
312 return(termbuf.c_lflag & ICANON);
313}
314
315int tty_istrapsig(void) {
316 return(termbuf.c_lflag & ISIG);
317}
318
319void tty_setedit(int on) {
320 if (on) termbuf.c_lflag |= ICANON;
321 else termbuf.c_lflag &= ~ICANON;
322}
323
324void tty_setsig(int on) {
325 if (on) termbuf.c_lflag |= ISIG;
326 else termbuf.c_lflag &= ~ISIG;
327}
328#endif /* LINEMODE */
329
330int tty_issofttab(void) {
331#ifdef OXTABS
332 return (termbuf.c_oflag & OXTABS);
333#endif
334#ifdef TABDLY
335 return ((termbuf.c_oflag & TABDLY) == TAB3);
336#endif
337}
338
339void tty_setsofttab(int on) {
340 if (on) {
341#ifdef OXTABS
342 termbuf.c_oflag |= OXTABS;
343#endif
344#ifdef TABDLY
345 termbuf.c_oflag &= ~TABDLY;
346 termbuf.c_oflag |= TAB3;
347#endif
348 }
349 else {
350#ifdef OXTABS
351 termbuf.c_oflag &= ~OXTABS;
352#endif
353#ifdef TABDLY
354 termbuf.c_oflag &= ~TABDLY;
355 termbuf.c_oflag |= TAB0;
356#endif
357 }
358}
359
360int tty_islitecho(void) {
361 return (!(termbuf.c_lflag & ECHOCTL));
362}
363
364void tty_setlitecho(int on) {
365 if (on) termbuf.c_lflag &= ~ECHOCTL;
366 else termbuf.c_lflag |= ECHOCTL;
367}
368
369int tty_iscrnl(void) {
370 return (termbuf.c_iflag & ICRNL);
371}
372
373/*
374 * A table of available terminal speeds
375 */
376struct termspeeds {
377 int speed;
378 int value;
379} termspeeds[] = {
380 { 0, B0 }, { 50, B50 }, { 75, B75 },
381 { 110, B110 }, { 134, B134 }, { 150, B150 },
382 { 200, B200 }, { 300, B300 }, { 600, B600 },
383 { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 },
384 { 4800, B4800 }, { 9600, B9600 }, { 19200, B9600 },
385 { 38400, B9600 }, { -1, B9600 }
386};
387
388void tty_tspeed(int val) {
389 struct termspeeds *tp;
390 for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++);
391 cfsetospeed(&termbuf, tp->value);
392}
393
394void tty_rspeed(int val) {
395 struct termspeeds *tp;
396 for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++);
397 cfsetispeed(&termbuf, tp->value);
398}
399
400/*
401 * getptyslave()
402 *
403 * Open the slave side of the pty, and do any initialization
404 * that is necessary. The return value is a file descriptor
405 * for the slave side.
406 */
407#ifdef TIOCGWINSZ
408extern int def_row, def_col;
409#endif
410extern int def_tspeed, def_rspeed;
411
412static int getptyslave(void) {
413#if 0
414 register int t = -1;
415
416# ifdef LINEMODE
417 int waslm;
418# endif
419# ifdef TIOCGWINSZ
420 struct winsize ws;
421# endif
422 /*
423 * Opening the slave side may cause initilization of the
424 * kernel tty structure. We need remember the state of
425 * if linemode was turned on
426 * terminal window size
427 * terminal speed
428 * so that we can re-set them if we need to.
429 */
430# ifdef LINEMODE
431 waslm = tty_linemode();
432# endif
433
434
435 /*
436 * Make sure that we don't have a controlling tty, and
437 * that we are the session (process group) leader.
438 */
439 t = open(_PATH_TTY, O_RDWR);
440 if (t >= 0) {
441 ioctl(t, TIOCNOTTY, (char *)0);
442 close(t);
443 }
444
445 t = cleanopen(line);
446 if (t < 0) fatalperror(net, line);
447#endif /* 0 */
448
449 struct winsize ws;
450 int t = ptyslavefd;
451
452 /*
453 * set up the tty modes as we like them to be.
454 */
455 init_termbuf();
456# ifdef TIOCGWINSZ
457 if (def_row || def_col) {
458 bzero((char *)&ws, sizeof(ws));
459 ws.ws_col = def_col;
460 ws.ws_row = def_row;
461 ioctl(t, TIOCSWINSZ, (char *)&ws);
462 }
463# endif
464
465 /*
466 * Settings for all other termios/termio based
467 * systems, other than 4.4BSD. In 4.4BSD the
468 * kernel does the initial terminal setup.
469 *
470 * XXX what about linux?
471 */
472# ifndef OXTABS
473# define OXTABS 0
474# endif
475 termbuf.c_lflag |= ECHO;
476 termbuf.c_oflag |= OPOST|ONLCR|OXTABS;
477 termbuf.c_iflag |= ICRNL;
478 termbuf.c_iflag &= ~IXOFF;
479
480 tty_rspeed((def_rspeed > 0) ? def_rspeed : 9600);
481 tty_tspeed((def_tspeed > 0) ? def_tspeed : 9600);
482# ifdef LINEMODE
483 if (waslm) tty_setlinemode(1);
484# endif /* LINEMODE */
485
486 /*
487 * Set the tty modes, and make this our controlling tty.
488 */
489 set_termbuf();
490 if (login_tty(t) == -1) fatalperror(net, "login_tty");
491
492 if (net > 2) close(net);
493 if (pty > 2) close(pty);
494 return t;
495}
496
497#if 0
498#ifndef O_NOCTTY
499#define O_NOCTTY 0
500#endif
501/*
502 * Open the specified slave side of the pty,
503 * making sure that we have a clean tty.
504 */
505static int cleanopen(char *lyne) {
506 register int t;
507
508 /*
509 * Make sure that other people can't open the
510 * slave side of the connection.
511 */
512 chown(lyne, 0, 0);
513 chmod(lyne, 0600);
514
515#ifndef NO_REVOKE
516 revoke(lyne);
517#endif
518
519 t = open(lyne, O_RDWR|O_NOCTTY);
520 if (t < 0) return(-1);
521
522 /*
523 * Hangup anybody else using this ttyp, then reopen it for
524 * ourselves.
525 */
526# if !defined(__linux__)
527 /* this looks buggy to me, our ctty is really a pty at this point */
528 signal(SIGHUP, SIG_IGN);
529 vhangup();
530 signal(SIGHUP, SIG_DFL);
531 t = open(lyne, O_RDWR|O_NOCTTY);
532 if (t < 0) return(-1);
533# endif
534 return(t);
535}
536#endif /* 0 */
537
538int login_tty(int t) {
539 if (setsid() < 0) fatalperror(net, "setsid()");
540 if (ioctl(t, TIOCSCTTY, (char *)0) < 0) {
541 fatalperror(net, "ioctl(sctty)");
542 }
543 if (t != 0) dup2(t, 0);
544 if (t != 1) dup2(t, 1);
545 if (t != 2) dup2(t, 2);
546 if (t > 2) close(t);
547 return 0;
548}
549
550/*
551 * startslave(host)
552 *
553 * Given a hostname, do whatever
554 * is necessary to startup the login process on the slave side of the pty.
555 */
556
557/* ARGSUSED */
558void startslave(const char *host, int autologin, char *autoname) {
559 int i;
560
561#if defined(AUTHENTICATE)
562 if (!autoname || !autoname[0]) autologin = 0;
563 if (autologin < auth_level) {
564 fatal(net, "Authorization failed");
565 exit(1);
566 }
567#endif
568
569 i = fork();
570 if (i < 0) fatalperror(net, "fork");
571 if (i) {
572 /* parent */
573 signal(SIGHUP,SIG_IGN);
574 close(ptyslavefd);
575 }
576 else {
577 /* child */
578 signal(SIGHUP,SIG_IGN);
579 getptyslave();
580 start_login(host, autologin, autoname);
581 /*NOTREACHED*/
582 }
583}
584
585char *envinit[3];
586
587void init_env(void) {
588 char **envp;
589 envp = envinit;
590 if ((*envp = getenv("TZ"))!=NULL)
591 *envp++ -= 3;
592 *envp = 0;
593 environ = envinit;
594}
595
596/*
597 * start_login(host)
598 *
599 * Assuming that we are now running as a child processes, this
600 * function will turn us into the login process.
601 */
602
603struct argv_stuff {
604 const char **argv;
605 int argc;
606 int argmax;
607};
608
609static void addarg(struct argv_stuff *, const char *);
610static void initarg(struct argv_stuff *);
611
612void start_login(const char *host, int autologin, const char *name) {
613 struct argv_stuff avs;
614 char *const *argvfoo;
615 (void)autologin;
616
617 initarg(&avs);
618
619 /*
620 * -h : pass on name of host.
621 * WARNING: -h is accepted by login if and only if
622 * getuid() == 0.
623 * -p : don't clobber the environment (so terminal type stays set).
624 *
625 * -f : force this login, he has already been authenticated
626 */
627 addarg(&avs, loginprg);
628 addarg(&avs, "-h");
629 addarg(&avs, host);
630#if !defined(NO_LOGIN_P)
631 addarg(&avs, "-p");
632#endif
633#ifdef BFTPDAEMON
634 /*
635 * Are we working as the bftp daemon? If so, then ask login
636 * to start bftp instead of shell.
637 */
638 if (bftpd) {
639 addarg(&avs, "-e");
640 addarg(&avs, BFTPPATH);
641 }
642 else
643#endif
644 {
645#if defined (SecurID)
646 /*
647 * don't worry about the -f that might get sent.
648 * A -s is supposed to override it anyhow.
649 */
650 if (require_SecurID) addarg(&avs, "-s");
651#endif
652 if (*name=='-') {
653 syslog(LOG_ERR, "Attempt to login with an option!");
654 name = "";
655 }
656#if defined (AUTHENTICATE)
657 if (auth_level >= 0 && autologin == AUTH_VALID) {
658# if !defined(NO_LOGIN_F)
659 addarg(&avs, "-f");
660# endif
661 addarg(&avs, name);
662 }
663 else
664#endif
665 {
666 if (getenv("USER")) {
667 addarg(&avs, getenv("USER"));
668 if (*getenv("USER") == '-') {
669 write(1,"I don't hear you!\r\n",19);
670 syslog(LOG_ERR,"Attempt to login with an option!");
671 exit(1);
672 }
673 }
674 }
675 }
676 closelog();
677 /* execv() should really take char const* const *, but it can't */
678 /*argvfoo = argv*/;
679 memcpy(&argvfoo, &avs.argv, sizeof(argvfoo));
680 execv(loginprg, argvfoo);
681
682 openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
683 syslog(LOG_ERR, "%s: %m\n", loginprg);
684 closelog();
685 fatalperror(net, loginprg);
686}
687
688static void initarg(struct argv_stuff *avs) {
689 /*
690 * 10 entries and a null
691 */
692 avs->argmax = 11;
693 avs->argv = malloc(sizeof(avs->argv[0]) * avs->argmax);
694 if (avs->argv == NULL) {
695 fprintf(stderr, "Out of memory\n");
696 exit(1);
697 }
698 avs->argc = 0;
699 avs->argv[0] = NULL;
700}
701
702static void addarg(struct argv_stuff *avs, const char *val) {
703 if (avs->argc>=avs->argmax-1) {
704 avs->argmax += 10;
705 avs->argv = realloc(avs->argv, sizeof(avs->argv[0])*avs->argmax);
706 if (avs->argv == NULL) {
707 fprintf(stderr, "Out of memory\n");
708 exit(1);
709 }
710 }
711
712 avs->argv[avs->argc++] = val;
713 avs->argv[avs->argc] = NULL;
714}
715
716/*
717 * cleanup()
718 *
719 * This is the routine to call when we are all through, to
720 * clean up anything that needs to be cleaned up.
721 */
722void cleanup(int sig) {
723 char *p;
724 (void)sig;
725
726 p = line + sizeof("/dev/") - 1;
727 if (logout(p)) logwtmp(p, "", "");
728#ifdef PARANOID_TTYS
729 /*
730 * dholland 16-Aug-96 chmod the tty when not in use
731 * This will make it harder to attach unwanted stuff to it
732 * (which is a security risk) but will break some programs.
733 */
734 chmod(line, 0600);
735#else
736 chmod(line, 0666);
737#endif
738 chown(line, 0, 0);
739 *p = 'p';
740 chmod(line, 0666);
741 chown(line, 0, 0);
742 shutdown(net, 2);
743 exit(0);
744}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.8 b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.8
new file mode 100644
index 0000000..794e4f2
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.8
@@ -0,0 +1,486 @@
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" from: @(#)telnetd.8 6.8 (Berkeley) 4/20/91
33.\" $Id: telnetd.8,v 1.18 2000/07/30 23:57:10 dholland Exp $
34.\"
35.Dd December 29, 1996
36.Dt TELNETD 8
37.Os "Linux NetKit (0.17)"
38.Sh NAME
39.Nm telnetd
40.Nd DARPA
41.Tn telnet
42protocol server
43.Sh SYNOPSIS
44.Nm /usr/sbin/in.telnetd
45.Op Fl hns
46.Op Fl a Ar authmode
47.Op Fl D Ar debugmode
48.Op Fl L Ar loginprg
49.Op Fl S Ar tos
50.Op Fl X Ar authtype
51.Op Fl edebug
52.Op Fl debug Ar port
53.Sh DESCRIPTION
54The
55.Nm telnetd
56program is a server which supports the
57.Tn DARPA
58.Tn telnet
59interactive communication protocol.
60.Nm Telnetd
61is normally invoked by the internet server (see
62.Xr inetd 8 )
63for requests to connect to the
64.Tn telnet
65port as indicated by the
66.Pa /etc/services
67file (see
68.Xr services 5 ) .
69The
70.Fl debug
71option may be used to start up
72.Nm telnetd
73manually, instead of through
74.Xr inetd 8 .
75If started up this way,
76.Ar port
77may be specified to run
78.Nm telnetd
79on an alternate
80.Tn TCP
81port number.
82.Pp
83The
84.Nm telnetd
85program accepts the following options:
86.Bl -tag -width "-a authmode"
87.It Fl a Ar authmode
88This option may be used for specifying what mode should
89be used for authentication.
90Note that this option is only useful if
91.Nm telnetd
92has been compiled with support for authentication, which is not
93available in the current version. The following values of
94.Ar authmode
95are understood:
96.Bl -tag -width debug
97.It debug
98Turns on authentication debugging code.
99.It user
100Only allow connections when the remote user can provide valid
101authentication information to identify the remote user, and is allowed
102access to the specified account without providing a password.
103.It valid
104Only allow connections when the remote user can provide valid
105authentication information to identify the remote user. The
106.Xr login 1
107command will provide any additional user verification needed if the
108remote user is not allowed automatic access to the specified account.
109.It other
110Only allow connections that supply some authentication information.
111This option is currently not supported by any of the existing
112authentication mechanisms, and is thus the same as specifying
113.Cm valid .
114.It none
115This is the default state. Authentication information is not
116required. If no or insufficient authentication information is
117provided, then the
118.Xr login 1
119program will provide the necessary user verification.
120.It off
121This disables the authentication code. All user verification will
122happen through the
123.Xr login 1
124program.
125.El
126.It Fl D Ar debugmode
127This option may be used for debugging purposes. This allows
128.Nm telnetd
129to print out debugging information to the connection, allowing the
130user to see what
131.Nm telnetd
132is doing. There are several possible values for
133.Ar debugmode:
134.Bl -tag -width exercise
135.It Cm options
136Prints information about the negotiation of
137.Tn telnet
138options.
139.It Cm report
140Prints the
141.Cm options
142information, plus some additional information about what processing is
143going on.
144.It Cm netdata
145Displays the data stream received by
146.Nm telnetd.
147.It Cm ptydata
148Displays data written to the pty.
149.It Cm exercise
150Has not been implemented yet.
151.El
152.It Fl edebug
153If
154.Nm telnetd
155has been compiled with support for encryption, then the
156.Fl edebug
157option may be used to enable encryption debugging code.
158.It Fl h
159Disables the printing of host-specific information before
160login has been completed.
161.It Fl L Ar loginprg
162This option may be used to specify a different login program.
163By default,
164.Pa /usr/sbin/telnetlogin
165is used.
166.It Fl n
167Disable
168.Dv TCP
169keep-alives. Normally
170.Nm telnetd
171enables the
172.Tn TCP
173keep-alive mechanism to probe connections that
174have been idle for some period of time to determine
175if the client is still there, so that idle connections
176from machines that have crashed or can no longer
177be reached may be cleaned up.
178.It Fl s
179This option is only enabled if
180.Nm telnetd
181is compiled with support for
182.Tn SecurID
183cards.
184It causes the
185.Fl s
186option to be passed on to
187.Xr login 1 ,
188and thus is only useful if
189.Xr login 1
190supports the
191.Fl s
192flag to indicate that only
193.Tn SecurID
194validated logins are allowed. This is usually useful for controlling
195remote logins from outside of a firewall.
196.It Fl S Ar tos
197Sets the IP type-of-service (TOS) option for the telnet
198connection to the value
199.Ar tos .
200.It Fl X Ar authtype
201This option is only valid if
202.Nm telnetd
203has been built with support for the authentication option.
204It disables the use of
205.Ar authtype
206authentication, and
207can be used to temporarily disable
208a specific authentication type without having to recompile
209.Nm telnetd .
210.El
211.Pp
212If the file
213.Pa /etc/issue.net
214is present,
215.Nm telnetd
216will display its contents before the login prompt of a telnet session (see
217.Xr issue.net 5 ) .
218.Pp
219.Nm Telnetd
220operates by allocating a pseudo-terminal device (see
221.Xr pty 4 )
222for a client, then creating a login process which has
223the slave side of the pseudo-terminal as
224.Dv stdin ,
225.Dv stdout ,
226and
227.Dv stderr .
228.Nm Telnetd
229manipulates the master side of the pseudo-terminal,
230implementing the
231.Tn telnet
232protocol and passing characters
233between the remote client and the login process.
234.Pp
235When a
236.Tn telnet
237session is started up,
238.Nm telnetd
239sends
240.Tn telnet
241options to the client side indicating
242a willingness to do the
243following
244.Tn telnet
245options, which are described in more detail below:
246.Bd -literal -offset indent
247DO AUTHENTICATION
248WILL ENCRYPT
249DO TERMINAL TYPE
250DO TSPEED
251DO XDISPLOC
252DO NEW-ENVIRON
253DO ENVIRON
254WILL SUPPRESS GO AHEAD
255DO ECHO
256DO LINEMODE
257DO NAWS
258WILL STATUS
259DO LFLOW
260DO TIMING-MARK
261.Ed
262.Pp
263The pseudo-terminal allocated to the client is configured
264to operate in \*(lqcooked\*(rq mode, and with
265.Dv XTABS
266.Dv CRMOD
267enabled (see
268.Xr tty 4 ) .
269.Pp
270.Nm Telnetd
271has support for enabling locally the following
272.Tn telnet
273options:
274.Bl -tag -width "DO AUTHENTICATION"
275.It "WILL ECHO"
276When the
277.Dv LINEMODE
278option is enabled, a
279.Dv WILL ECHO
280or
281.Dv WONT ECHO
282will be sent to the client to indicate the
283current state of terminal echoing.
284When terminal echo is not desired, a
285.Dv WILL ECHO
286is sent to indicate that
287.Tn telnetd
288will take care of echoing any data that needs to be
289echoed to the terminal, and then nothing is echoed.
290When terminal echo is desired, a
291.Dv WONT ECHO
292is sent to indicate that
293.Tn telnetd
294will not be doing any terminal echoing, so the
295client should do any terminal echoing that is needed.
296.It "WILL BINARY"
297Indicates that the client is willing to send a
2988 bits of data, rather than the normal 7 bits
299of the Network Virtual Terminal.
300.It "WILL SGA"
301Indicates that it will not be sending
302.Dv IAC GA,
303go ahead, commands.
304.It "WILL STATUS"
305Indicates a willingness to send the client, upon
306request, of the current status of all
307.Tn TELNET
308options.
309.It "WILL TIMING-MARK"
310Whenever a
311.Dv DO TIMING-MARK
312command is received, it is always responded
313to with a
314.Dv WILL TIMING-MARK
315.It "WILL LOGOUT"
316When a
317.Dv DO LOGOUT
318is received, a
319.Dv WILL LOGOUT
320is sent in response, and the
321.Tn TELNET
322session is shut down.
323.It "WILL ENCRYPT"
324Only sent if
325.Nm telnetd
326is compiled with support for data encryption, and
327indicates a willingness to decrypt
328the data stream.
329.El
330.Pp
331.Nm Telnetd
332has support for enabling remotely the following
333.Tn TELNET
334options:
335.Bl -tag -width "DO AUTHENTICATION"
336.It "DO BINARY"
337Sent to indicate that
338.Tn telnetd
339is willing to receive an 8 bit data stream.
340.It "DO LFLOW"
341Requests that the client handle flow control
342characters remotely.
343.It "DO ECHO"
344This is not really supported, but is sent to identify a 4.2BSD
345.Xr telnet 1
346client, which will improperly respond with
347.Dv WILL ECHO.
348If a
349.Dv WILL ECHO
350is received, a
351.Dv DONT ECHO
352will be sent in response.
353.It "DO TERMINAL-TYPE"
354Indicates a desire to be able to request the
355name of the type of terminal that is attached
356to the client side of the connection.
357.It "DO SGA"
358Indicates that it does not need to receive
359.Dv IAC GA,
360the go ahead command.
361.It "DO NAWS"
362Requests that the client inform the server when
363the window (display) size changes.
364.It "DO TERMINAL-SPEED"
365Indicates a desire to be able to request information
366about the speed of the serial line to which
367the client is attached.
368.It "DO XDISPLOC"
369Indicates a desire to be able to request the name
370of the X windows display that is associated with
371the telnet client.
372.It "DO NEW-ENVIRON"
373Indicates a desire to be able to request environment
374variable information, as described in RFC 1572.
375.It "DO ENVIRON"
376Indicates a desire to be able to request environment
377variable information, as described in RFC 1408.
378.It "DO LINEMODE"
379Only sent if
380.Nm telnetd
381is compiled with support for linemode, and
382requests that the client do line by line processing.
383.It "DO TIMING-MARK"
384Only sent if
385.Nm telnetd
386is compiled with support for both linemode and
387kludge linemode, and the client responded with
388.Dv WONT LINEMODE.
389If the client responds with
390.Dv WILL TM,
391the it is assumed that the client supports
392kludge linemode.
393Note that the
394.Op Fl k
395option can be used to disable this.
396.It "DO AUTHENTICATION"
397Only sent if
398.Nm telnetd
399is compiled with support for authentication, and
400indicates a willingness to receive authentication
401information for automatic login.
402.It "DO ENCRYPT"
403Only sent if
404.Nm telnetd
405is compiled with support for data encryption, and
406indicates a willingness to decrypt
407the data stream.
408.Xr issue.net 5 ) .
409.Sh FILES
410.Pa /etc/services ,
411.Pa /etc/issue.net
412.Sh "SEE ALSO"
413.Xr telnet 1 ,
414.Xr login 1 ,
415.Xr issue.net 5 ,
416.Sh STANDARDS
417.Bl -tag -compact -width RFC-1572
418.It Cm RFC-854
419.Tn TELNET
420PROTOCOL SPECIFICATION
421.It Cm RFC-855
422TELNET OPTION SPECIFICATIONS
423.It Cm RFC-856
424TELNET BINARY TRANSMISSION
425.It Cm RFC-857
426TELNET ECHO OPTION
427.It Cm RFC-858
428TELNET SUPPRESS GO AHEAD OPTION
429.It Cm RFC-859
430TELNET STATUS OPTION
431.It Cm RFC-860
432TELNET TIMING MARK OPTION
433.It Cm RFC-861
434TELNET EXTENDED OPTIONS - LIST OPTION
435.It Cm RFC-885
436TELNET END OF RECORD OPTION
437.It Cm RFC-1073
438Telnet Window Size Option
439.It Cm RFC-1079
440Telnet Terminal Speed Option
441.It Cm RFC-1091
442Telnet Terminal-Type Option
443.It Cm RFC-1096
444Telnet X Display Location Option
445.It Cm RFC-1123
446Requirements for Internet Hosts -- Application and Support
447.It Cm RFC-1184
448Telnet Linemode Option
449.It Cm RFC-1372
450Telnet Remote Flow Control Option
451.It Cm RFC-1416
452Telnet Authentication Option
453.It Cm RFC-1411
454Telnet Authentication: Kerberos Version 4
455.It Cm RFC-1412
456Telnet Authentication: SPX
457.It Cm RFC-1571
458Telnet Environment Option Interoperability Issues
459.It Cm RFC-1572
460Telnet Environment Option
461.Sh BUGS
462Some
463.Tn TELNET
464commands are only partially implemented.
465.Pp
466Because of bugs in the original 4.2 BSD
467.Xr telnet 1 ,
468.Nm telnetd
469performs some dubious protocol exchanges to try to discover if the remote
470client is, in fact, a 4.2 BSD
471.Xr telnet 1 .
472.Pp
473Binary mode
474has no common interpretation except between similar operating systems
475(Unix in this case).
476.Pp
477The terminal type name received from the remote client is converted to
478lower case.
479.Pp
480.Nm Telnetd
481never sends
482.Tn TELNET
483.Dv IAC GA
484(go ahead) commands.
485.Pp
486The source code is not comprehensible.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.c
new file mode 100644
index 0000000..7ff330c
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.c
@@ -0,0 +1,1208 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34char copyright[] =
35 "@(#) Copyright (c) 1989 Regents of the University of California.\n"
36 "All rights reserved.\n";
37
38/*
39 * From: @(#)telnetd.c 5.48 (Berkeley) 3/1/91
40 */
41char telnetd_rcsid[] =
42 "$Id: telnetd.c,v 1.24 2000/04/12 21:36:12 dholland Exp $";
43
44#include "../version.h"
45
46#include <sys/socket.h>
47#include <netdb.h>
48#include <termcap.h>
49#include <netinet/in.h>
50/* #include <netinet/ip.h> */ /* Don't think this is used at all here */
51#include <arpa/inet.h>
52#include <assert.h>
53#include <poll.h>
54#include <fcntl.h>
55#include <unistd.h>
56#include "telnetd.h"
57#include "pathnames.h"
58#include "setproctitle.h"
59
60#if defined(AUTHENTICATE)
61#include <libtelnet/auth.h>
62#include <libtelnet/auth-proto.h>
63#include <libtelnet/misc-proto.h>
64int auth_level = 0;
65#endif
66#if defined(SecurID)
67int require_SecurID = 0;
68#endif
69
70/* In Linux, this is an enum */
71#if defined(__linux__) || defined(IPPROTO_IP)
72#define HAS_IPPROTO_IP
73#endif
74
75static void doit(struct sockaddr *who, socklen_t who_len);
76static int terminaltypeok(const char *s);
77
78/*
79 * I/O data buffers,
80 * pointers, and counters.
81 */
82char ptyibuf[BUFSIZ], *ptyip = ptyibuf;
83char ptyibuf2[BUFSIZ];
84
85int hostinfo = 1; /* do we print login banner? */
86
87int debug = 0;
88int keepalive = 1;
89#ifdef LOGIN_WRAPPER
90char *loginprg = LOGIN_WRAPPER;
91#else
92char *loginprg = _PATH_LOGIN;
93#endif
94char *progname;
95
96extern void usage(void);
97
98static void
99wait_for_connection(const char *service)
100{
101 struct addrinfo hints;
102 struct addrinfo *res, *addr;
103 struct pollfd *fds, *fdp;
104 int nfds;
105 int i;
106 int error;
107 int on = 1;
108
109 memset(&hints, 0, sizeof(hints));
110 hints.ai_family = PF_UNSPEC;
111 hints.ai_flags = AI_PASSIVE;
112 hints.ai_socktype = SOCK_STREAM;
113 error = getaddrinfo(NULL, service, &hints, &res);
114 if (error) {
115 fprintf(stderr, "telnetd: getaddrinfo: %s\n",
116 gai_strerror(error));
117 exit(1);
118 }
119
120 for (addr = res, nfds = 0; addr; addr = addr->ai_next, nfds++)
121 ;
122 fds = malloc(sizeof(struct pollfd) * nfds);
123 for (addr = res, fdp = fds; addr; addr = addr->ai_next, fdp++) {
124 int s;
125
126 if (addr->ai_family == AF_LOCAL) {
127nextaddr:
128 fdp--;
129 nfds--;
130 continue;
131 }
132
133 s = socket(addr->ai_family, SOCK_STREAM, 0);
134 if (s < 0) {
135 if (errno == EAFNOSUPPORT || errno == EINVAL) {
136 goto nextaddr;
137 }
138 perror("telnetd: socket");
139 exit(1);
140 }
141 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
142 if (bind(s, addr->ai_addr, addr->ai_addrlen) < 0) {
143 if (errno == EADDRINUSE) {
144 /* Must be Linux! */
145 close(s);
146 goto nextaddr;
147 }
148 perror("bind");
149 exit(1);
150 }
151 if (listen(s, 1)) {
152 perror("listen");
153 exit(1);
154 }
155 if (fcntl(s, F_SETFL, O_NONBLOCK)) {
156 perror("fcntl");
157 exit(1);
158 }
159
160 fdp->fd = s;
161 fdp->events = POLLIN;
162 }
163
164 freeaddrinfo(res);
165
166 while (1) {
167 if (poll(fds, nfds, -1) < 0) {
168 if (errno == EINTR) {
169 continue;
170 }
171 perror("poll");
172 exit(1);
173 }
174
175 for (i = 0, fdp = fds; i < nfds; i++, fdp++) {
176 int fd;
177
178 if (!(fdp->revents & POLLIN)) {
179 continue;
180 }
181
182 fd = accept(fdp->fd, 0, 0);
183 if (fd >= 0) {
184 dup2(fd, 0);
185 close(fd);
186 goto out;
187 }
188 if (errno != EAGAIN) {
189 perror("accept");
190 exit(1);
191 }
192 }
193 }
194
195out:
196 for (i = 0, fdp = fds; i < nfds; i++, fdp++) {
197 close(fdp->fd);
198 }
199 free(fds);
200}
201
202int
203main(int argc, char *argv[], char *env[])
204{
205 struct sockaddr_storage from;
206 int on = 1;
207 socklen_t fromlen;
208 register int ch;
209
210#if defined(HAS_IPPROTO_IP) && defined(IP_TOS)
211 int tos = -1;
212#endif
213
214 initsetproctitle(argc, argv, env);
215
216 pfrontp = pbackp = ptyobuf;
217 netip = netibuf;
218
219 progname = strdup(*argv);
220
221 while ((ch = getopt(argc, argv, "d:a:e:lhnr:I:D:B:sS:a:X:L:")) != EOF) {
222 switch(ch) {
223
224#ifdef AUTHENTICATE
225 case 'a':
226 /*
227 * Check for required authentication level
228 */
229 if (strcmp(optarg, "debug") == 0) {
230 extern int auth_debug_mode;
231 auth_debug_mode = 1;
232 } else if (strcasecmp(optarg, "none") == 0) {
233 auth_level = 0;
234 } else if (strcasecmp(optarg, "other") == 0) {
235 auth_level = AUTH_OTHER;
236 } else if (strcasecmp(optarg, "user") == 0) {
237 auth_level = AUTH_USER;
238 } else if (strcasecmp(optarg, "valid") == 0) {
239 auth_level = AUTH_VALID;
240 } else if (strcasecmp(optarg, "off") == 0) {
241 /*
242 * This hack turns off authentication
243 */
244 auth_level = -1;
245 } else {
246 fprintf(stderr,
247 "telnetd: unknown authorization level for -a\n");
248 }
249 break;
250#endif /* AUTHENTICATE */
251
252#ifdef BFTPDAEMON
253 case 'B':
254 bftpd++;
255 break;
256#endif /* BFTPDAEMON */
257
258 case 'd':
259 if (strcmp(optarg, "ebug") == 0) {
260 debug++;
261 break;
262 }
263 usage();
264 /* NOTREACHED */
265 break;
266
267#ifdef DIAGNOSTICS
268 case 'D':
269 /*
270 * Check for desired diagnostics capabilities.
271 */
272 if (!strcmp(optarg, "report")) {
273 diagnostic |= TD_REPORT|TD_OPTIONS;
274 } else if (!strcmp(optarg, "exercise")) {
275 diagnostic |= TD_EXERCISE;
276 } else if (!strcmp(optarg, "netdata")) {
277 diagnostic |= TD_NETDATA;
278 } else if (!strcmp(optarg, "ptydata")) {
279 diagnostic |= TD_PTYDATA;
280 } else if (!strcmp(optarg, "options")) {
281 diagnostic |= TD_OPTIONS;
282 } else {
283 usage();
284 /* NOT REACHED */
285 }
286 break;
287#endif /* DIAGNOSTICS */
288
289#ifdef AUTHENTICATE
290 case 'e':
291 if (strcmp(optarg, "debug") == 0) {
292 extern int auth_debug_mode;
293 auth_debug_mode = 1;
294 break;
295 }
296 usage();
297 /* NOTREACHED */
298 break;
299#endif /* AUTHENTICATE */
300
301 case 'h':
302 hostinfo = 0;
303 break;
304
305#ifdef LINEMODE
306 case 'l':
307 alwayslinemode = 1;
308 break;
309#endif /* LINEMODE */
310
311 case 'L':
312 loginprg = strdup(optarg);
313 /* XXX what if strdup fails? */
314 break;
315
316 case 'n':
317 keepalive = 0;
318 break;
319
320#ifdef SecurID
321 case 's':
322 /* SecurID required */
323 require_SecurID = 1;
324 break;
325#endif /* SecurID */
326 case 'S':
327#ifdef HAS_GETTOS
328 if ((tos = parsetos(optarg, "tcp")) < 0)
329 fprintf(stderr, "%s%s%s\n",
330 "telnetd: Bad TOS argument '", optarg,
331 "'; will try to use default TOS");
332#else
333 fprintf(stderr, "%s%s\n", "TOS option unavailable; ",
334 "-S flag not supported\n");
335#endif
336 break;
337
338#ifdef AUTHENTICATE
339 case 'X':
340 /*
341 * Check for invalid authentication types
342 */
343 auth_disable_name(optarg);
344 break;
345#endif /* AUTHENTICATE */
346
347 default:
348 fprintf(stderr, "telnetd: %c: unknown option\n", ch);
349 /* FALLTHROUGH */
350 case '?':
351 usage();
352 /* NOTREACHED */
353 }
354 }
355
356 argc -= optind;
357 argv += optind;
358
359 if (debug) {
360 if (argc > 1) {
361 usage();
362 /* NOTREACHED */
363 }
364
365 wait_for_connection((argc == 1) ? *argv : "telnet");
366 }
367
368 openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
369 fromlen = sizeof (from);
370 if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) {
371 fprintf(stderr, "%s: ", progname);
372 perror("getpeername");
373 _exit(1);
374 }
375 if (keepalive &&
376 setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)) < 0) {
377 syslog(LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
378 }
379
380#if defined(HAS_IPPROTO_IP) && defined(IP_TOS)
381 {
382# if defined(HAS_GETTOS)
383 struct tosent *tp;
384 if (tos < 0 && (tp = gettosbyname("telnet", "tcp")))
385 tos = tp->t_tos;
386# endif
387 if (tos < 0)
388 tos = 020; /* Low Delay bit */
389 if (tos
390 && (setsockopt(0, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0)
391 && (errno != ENOPROTOOPT) )
392 syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
393 }
394#endif /* defined(HAS_IPPROTO_IP) && defined(IP_TOS) */
395 net = 0;
396 netopen();
397 doit((struct sockaddr *)&from, fromlen);
398 /* NOTREACHED */
399 return 0;
400} /* end of main */
401
402void
403usage(void)
404{
405 fprintf(stderr, "Usage: telnetd");
406#ifdef AUTHENTICATE
407 fprintf(stderr, " [-a (debug|other|user|valid|off)]\n\t");
408#endif
409#ifdef BFTPDAEMON
410 fprintf(stderr, " [-B]");
411#endif
412 fprintf(stderr, " [-debug port]");
413#ifdef DIAGNOSTICS
414 fprintf(stderr, " [-D (options|report|exercise|netdata|ptydata)]\n\t");
415#endif
416#ifdef AUTHENTICATE
417 fprintf(stderr, " [-edebug]");
418#endif
419 fprintf(stderr, " [-h]");
420#ifdef LINEMODE
421 fprintf(stderr, " [-l]");
422#endif
423 fprintf(stderr, " [-L login_program]");
424 fprintf(stderr, " [-n]");
425#ifdef SecurID
426 fprintf(stderr, " [-s]");
427#endif
428#ifdef AUTHENTICATE
429 fprintf(stderr, " [-X auth-type]");
430#endif
431 fprintf(stderr, "\n");
432 exit(1);
433}
434
435/*
436 * getterminaltype
437 *
438 * Ask the other end to send along its terminal type and speed.
439 * Output is the variable terminaltype filled in.
440 */
441
442static void _gettermname(void);
443
444static
445int
446getterminaltype(char *name)
447{
448 int retval = -1;
449 (void)name;
450
451 settimer(baseline);
452#if defined(AUTHENTICATE)
453 /*
454 * Handle the Authentication option before we do anything else.
455 */
456 send_do(TELOPT_AUTHENTICATION, 1);
457 while (his_will_wont_is_changing(TELOPT_AUTHENTICATION))
458 ttloop();
459 if (his_state_is_will(TELOPT_AUTHENTICATION)) {
460 retval = auth_wait(name);
461 }
462#endif
463
464#if defined(ENCRYPT)
465 send_will(TELOPT_ENCRYPT, 1);
466#endif
467 send_do(TELOPT_TTYPE, 1);
468 send_do(TELOPT_TSPEED, 1);
469 send_do(TELOPT_XDISPLOC, 1);
470 send_do(TELOPT_ENVIRON, 1);
471 while (
472#if defined(ENCRYPT)
473 his_do_dont_is_changing(TELOPT_ENCRYPT) ||
474#endif
475 his_will_wont_is_changing(TELOPT_TTYPE) ||
476 his_will_wont_is_changing(TELOPT_TSPEED) ||
477 his_will_wont_is_changing(TELOPT_XDISPLOC) ||
478 his_will_wont_is_changing(TELOPT_ENVIRON)) {
479 ttloop();
480 }
481#if defined(ENCRYPT)
482 /*
483 * Wait for the negotiation of what type of encryption we can
484 * send with. If autoencrypt is not set, this will just return.
485 */
486 if (his_state_is_will(TELOPT_ENCRYPT)) {
487 encrypt_wait();
488 }
489#endif
490 if (his_state_is_will(TELOPT_TSPEED)) {
491 netoprintf("%c%c%c%c%c%c",
492 IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE);
493 }
494 if (his_state_is_will(TELOPT_XDISPLOC)) {
495 netoprintf("%c%c%c%c%c%c",
496 IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE);
497 }
498 if (his_state_is_will(TELOPT_ENVIRON)) {
499 netoprintf("%c%c%c%c%c%c",
500 IAC, SB, TELOPT_ENVIRON, TELQUAL_SEND, IAC, SE);
501 }
502 if (his_state_is_will(TELOPT_TTYPE)) {
503 netoprintf("%c%c%c%c%c%c",
504 IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE);
505 }
506 if (his_state_is_will(TELOPT_TSPEED)) {
507 while (sequenceIs(tspeedsubopt, baseline))
508 ttloop();
509 }
510 if (his_state_is_will(TELOPT_XDISPLOC)) {
511 while (sequenceIs(xdisplocsubopt, baseline))
512 ttloop();
513 }
514 if (his_state_is_will(TELOPT_ENVIRON)) {
515 while (sequenceIs(environsubopt, baseline))
516 ttloop();
517 }
518 if (his_state_is_will(TELOPT_TTYPE)) {
519 char first[256], last[256];
520
521 while (sequenceIs(ttypesubopt, baseline))
522 ttloop();
523
524 /*
525 * If the other side has already disabled the option, then
526 * we have to just go with what we (might) have already gotten.
527 */
528 if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) {
529 /*
530 * Due to state.c, terminaltype points to a static char[41].
531 * Therefore, this assert cannot fail, and therefore, strings
532 * arising from "terminaltype" can be safely strcpy'd into
533 * first[] or last[].
534 */
535 assert(strlen(terminaltype) < sizeof(first));
536
537 strcpy(first, terminaltype);
538
539 for(;;) {
540 /*
541 * Save the unknown name, and request the next name.
542 */
543 strcpy(last, terminaltype);
544
545 _gettermname();
546 assert(strlen(terminaltype) < sizeof(first));
547
548 if (terminaltypeok(terminaltype))
549 break;
550
551 if (!strcmp(last, terminaltype) ||
552 his_state_is_wont(TELOPT_TTYPE)) {
553 /*
554 * We've hit the end. If this is the same as
555 * the first name, just go with it.
556 */
557 if (!strcmp(first, terminaltype))
558 break;
559 /*
560 * Get the terminal name one more time, so that
561 * RFC1091 compliant telnets will cycle back to
562 * the start of the list.
563 */
564 _gettermname();
565 assert(strlen(terminaltype) < sizeof(first));
566
567 if (strcmp(first, terminaltype)) {
568 /*
569 * first[] came from terminaltype, so it must fit
570 * back in.
571 */
572 strcpy(terminaltype, first);
573 }
574 break;
575 }
576 }
577 }
578 }
579 return(retval);
580} /* end of getterminaltype */
581
582static
583void
584_gettermname(void)
585{
586 /*
587 * If the client turned off the option,
588 * we can't send another request, so we
589 * just return.
590 */
591 if (his_state_is_wont(TELOPT_TTYPE))
592 return;
593
594 settimer(baseline);
595 netoprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE);
596 while (sequenceIs(ttypesubopt, baseline))
597 ttloop();
598}
599
600static int
601terminaltypeok(const char *s)
602{
603 /* char buf[2048]; */
604
605 if (terminaltype == NULL)
606 return(1);
607
608 /*
609 * Fix from Chris Evans: if it has a / in it, termcap will
610 * treat it as a filename. Oops.
611 */
612 if (strchr(s, '/')) {
613 return 0;
614 }
615
616 /*
617 * If it's absurdly long, accept it without asking termcap.
618 *
619 * This means that it won't get seen again until after login,
620 * at which point exploiting buffer problems in termcap doesn't
621 * gain one anything.
622 *
623 * It's possible this limit ought to be raised to 128, but nothing
624 * in my termcap is more than 64, 64 is _plenty_ for most, and while
625 * buffers aren't likely to be smaller than 64, they might be 80 and
626 * thus less than 128.
627 */
628 if (strlen(s) > 63) {
629 return 0;
630 }
631
632 /*
633 * tgetent() will return 1 if the type is known, and
634 * 0 if it is not known. If it returns -1, it couldn't
635 * open the database. But if we can't open the database,
636 * it won't help to say we failed, because we won't be
637 * able to verify anything else. So, we treat -1 like 1.
638 */
639
640 /*
641 * Don't do this - tgetent is not really trustworthy. Assume
642 * the terminal type is one we know; terminal types are pretty
643 * standard now. And if it isn't, it's unlikely we're going to
644 * know anything else the remote telnet might send as an alias
645 * for it.
646 *
647 * if (tgetent(buf, s) == 0)
648 * return(0);
649 */
650 return(1);
651}
652
653#ifndef MAXHOSTNAMELEN
654#define MAXHOSTNAMELEN 64
655#endif /* MAXHOSTNAMELEN */
656
657char host_name[MAXHOSTNAMELEN];
658char remote_host_name[MAXHOSTNAMELEN];
659
660extern void telnet(int, int);
661
662/*
663 * Get a pty, scan input lines.
664 */
665static void
666doit(struct sockaddr *who, socklen_t who_len)
667{
668 const char *host;
669 int level;
670 char user_name[256];
671 int i;
672 struct addrinfo hints, *res;
673
674 /*
675 * Find an available pty to use.
676 */
677 pty = getpty();
678 if (pty < 0)
679 fatalperror(net, "getpty");
680
681 /* get name of connected client */
682 if (getnameinfo(who, who_len, remote_host_name,
683 sizeof(remote_host_name), 0, 0, 0)) {
684 syslog(LOG_ERR, "doit: getnameinfo: %m");
685 *remote_host_name = 0;
686 }
687
688 /* Disallow funnies. */
689 for (i=0; remote_host_name[i]; i++) {
690 if (remote_host_name[i]<=32 || remote_host_name[i]>126)
691 remote_host_name[i] = '?';
692 }
693 host = remote_host_name;
694
695 /* Get local host name */
696 gethostname(host_name, sizeof(host_name));
697 memset(&hints, 0, sizeof(hints));
698 hints.ai_family = PF_UNSPEC;
699 hints.ai_flags = AI_CANONNAME;
700 if ((i = getaddrinfo(host_name, 0, &hints, &res)))
701 syslog(LOG_WARNING, "doit: getaddrinfo: %s", gai_strerror(i));
702 else {
703 strncpy(host_name, res->ai_canonname, sizeof(host_name)-1);
704 host_name[sizeof(host_name)-1] = 0;
705 }
706
707#if defined(AUTHENTICATE) || defined(ENCRYPT)
708 auth_encrypt_init(host_name, host, "TELNETD", 1);
709#endif
710
711 init_env();
712 /*
713 * get terminal type.
714 */
715 *user_name = 0;
716 level = getterminaltype(user_name);
717 setenv("TERM", terminaltype ? terminaltype : "network", 1);
718
719 /* TODO list stuff provided by Laszlo Vecsey <master@internexus.net> */
720
721 /*
722 * Set REMOTEHOST environment variable
723 */
724 setproctitle("%s", host);
725 setenv("REMOTEHOST", host, 0);
726
727 /*
728 * Start up the login process on the slave side of the terminal
729 */
730 startslave(host, level, user_name);
731
732 telnet(net, pty); /* begin server processing */
733
734 /*NOTREACHED*/
735} /* end of doit */
736
737/*
738 * Main loop. Select from pty and network, and
739 * hand data to telnet receiver finite state machine.
740 */
741void telnet(int f, int p)
742{
743 int on = 1;
744 char *HE;
745 const char *IM;
746
747 /*
748 * Initialize the slc mapping table.
749 */
750 get_slc_defaults();
751
752 /*
753 * Do some tests where it is desireable to wait for a response.
754 * Rather than doing them slowly, one at a time, do them all
755 * at once.
756 */
757 if (my_state_is_wont(TELOPT_SGA))
758 send_will(TELOPT_SGA, 1);
759 /*
760 * Is the client side a 4.2 (NOT 4.3) system? We need to know this
761 * because 4.2 clients are unable to deal with TCP urgent data.
762 *
763 * To find out, we send out a "DO ECHO". If the remote system
764 * answers "WILL ECHO" it is probably a 4.2 client, and we note
765 * that fact ("WILL ECHO" ==> that the client will echo what
766 * WE, the server, sends it; it does NOT mean that the client will
767 * echo the terminal input).
768 */
769 send_do(TELOPT_ECHO, 1);
770
771#ifdef LINEMODE
772 if (his_state_is_wont(TELOPT_LINEMODE)) {
773 /*
774 * Query the peer for linemode support by trying to negotiate
775 * the linemode option.
776 */
777 linemode = 0;
778 editmode = 0;
779 send_do(TELOPT_LINEMODE, 1); /* send do linemode */
780 }
781#endif /* LINEMODE */
782
783 /*
784 * Send along a couple of other options that we wish to negotiate.
785 */
786 send_do(TELOPT_NAWS, 1);
787 send_will(TELOPT_STATUS, 1);
788 flowmode = 1; /* default flow control state */
789 send_do(TELOPT_LFLOW, 1);
790
791 /*
792 * Spin, waiting for a response from the DO ECHO. However,
793 * some REALLY DUMB telnets out there might not respond
794 * to the DO ECHO. So, we spin looking for NAWS, (most dumb
795 * telnets so far seem to respond with WONT for a DO that
796 * they don't understand...) because by the time we get the
797 * response, it will already have processed the DO ECHO.
798 * Kludge upon kludge.
799 */
800 while (his_will_wont_is_changing(TELOPT_NAWS)) {
801 ttloop();
802 }
803
804 /*
805 * But...
806 * The client might have sent a WILL NAWS as part of its
807 * startup code; if so, we'll be here before we get the
808 * response to the DO ECHO. We'll make the assumption
809 * that any implementation that understands about NAWS
810 * is a modern enough implementation that it will respond
811 * to our DO ECHO request; hence we'll do another spin
812 * waiting for the ECHO option to settle down, which is
813 * what we wanted to do in the first place...
814 */
815 if (his_want_state_is_will(TELOPT_ECHO) &&
816 his_state_is_will(TELOPT_NAWS)) {
817 while (his_will_wont_is_changing(TELOPT_ECHO))
818 ttloop();
819 }
820 /*
821 * On the off chance that the telnet client is broken and does not
822 * respond to the DO ECHO we sent, (after all, we did send the
823 * DO NAWS negotiation after the DO ECHO, and we won't get here
824 * until a response to the DO NAWS comes back) simulate the
825 * receipt of a will echo. This will also send a WONT ECHO
826 * to the client, since we assume that the client failed to
827 * respond because it believes that it is already in DO ECHO
828 * mode, which we do not want.
829 */
830 if (his_want_state_is_will(TELOPT_ECHO)) {
831 DIAG(TD_OPTIONS, netoprintf("td: simulating recv\r\n"););
832 willoption(TELOPT_ECHO);
833 }
834
835 /*
836 * Finally, to clean things up, we turn on our echo. This
837 * will break stupid 4.2 telnets out of local terminal echo.
838 */
839
840 if (my_state_is_wont(TELOPT_ECHO))
841 send_will(TELOPT_ECHO, 1);
842
843 /*
844 * Turn on packet mode
845 */
846 ioctl(p, TIOCPKT, (char *)&on);
847#if defined(LINEMODE) && defined(KLUDGELINEMODE)
848 /*
849 * Continuing line mode support. If client does not support
850 * real linemode, attempt to negotiate kludge linemode by sending
851 * the do timing mark sequence.
852 */
853 if (lmodetype < REAL_LINEMODE)
854 send_do(TELOPT_TM, 1);
855#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
856
857 /*
858 * Call telrcv() once to pick up anything received during
859 * terminal type negotiation, 4.2/4.3 determination, and
860 * linemode negotiation.
861 */
862 telrcv();
863
864 ioctl(f, FIONBIO, (char *)&on);
865 ioctl(p, FIONBIO, (char *)&on);
866
867#if defined(SO_OOBINLINE)
868 setsockopt(net, SOL_SOCKET, SO_OOBINLINE, &on, sizeof on);
869#endif /* defined(SO_OOBINLINE) */
870
871#ifdef SIGTSTP
872 signal(SIGTSTP, SIG_IGN);
873#endif
874#ifdef SIGTTOU
875 /*
876 * Ignoring SIGTTOU keeps the kernel from blocking us
877 * in ttioct() in /sys/tty.c.
878 */
879 signal(SIGTTOU, SIG_IGN);
880#endif
881
882 signal(SIGCHLD, cleanup);
883
884#ifdef TIOCNOTTY
885 {
886 register int t;
887 t = open(_PATH_TTY, O_RDWR);
888 if (t >= 0) {
889 (void) ioctl(t, TIOCNOTTY, (char *)0);
890 (void) close(t);
891 }
892 }
893#endif
894
895 /*
896 * Show banner that getty never gave.
897 *
898 * We put the banner in the pty input buffer. This way, it
899 * gets carriage return null processing, etc., just like all
900 * other pty --> client data.
901 */
902
903 if (getenv("USER"))
904 hostinfo = 0;
905
906 IM = DEFAULT_IM;
907 HE = 0;
908
909 edithost(HE, host_name);
910 if (hostinfo && *IM)
911 putf(IM, ptyibuf2);
912
913 if (pcc) strncat(ptyibuf2, ptyip, pcc+1);
914 ptyip = ptyibuf2;
915 pcc = strlen(ptyip);
916#ifdef LINEMODE
917 /*
918 * Last check to make sure all our states are correct.
919 */
920 init_termbuf();
921 localstat();
922#endif /* LINEMODE */
923
924 DIAG(TD_REPORT, netoprintf("td: Entering processing loop\r\n"););
925
926 for (;;) {
927 fd_set ibits, obits, xbits;
928 int c, hifd;
929
930 if (ncc < 0 && pcc < 0)
931 break;
932
933 FD_ZERO(&ibits);
934 FD_ZERO(&obits);
935 FD_ZERO(&xbits);
936 hifd=0;
937 /*
938 * Never look for input if there's still
939 * stuff in the corresponding output buffer
940 */
941 if (netbuflen(1) || pcc > 0) {
942 FD_SET(f, &obits);
943 if (f >= hifd) hifd = f+1;
944 }
945 else {
946 FD_SET(p, &ibits);
947 if (p >= hifd) hifd = p+1;
948 }
949 if (pfrontp - pbackp || ncc > 0) {
950 FD_SET(p, &obits);
951 if (p >= hifd) hifd = p+1;
952 }
953 else {
954 FD_SET(f, &ibits);
955 if (f >= hifd) hifd = f+1;
956 }
957 if (!SYNCHing) {
958 FD_SET(f, &xbits);
959 if (f >= hifd) hifd = f+1;
960 }
961 if ((c = select(hifd, &ibits, &obits, &xbits,
962 (struct timeval *)0)) < 1) {
963 if (c == -1) {
964 if (errno == EINTR) {
965 continue;
966 }
967 }
968 sleep(5);
969 continue;
970 }
971
972 /*
973 * Any urgent data?
974 */
975 if (FD_ISSET(net, &xbits)) {
976 SYNCHing = 1;
977 }
978
979 /*
980 * Something to read from the network...
981 */
982 if (FD_ISSET(net, &ibits)) {
983#if !defined(SO_OOBINLINE)
984 /*
985 * In 4.2 (and 4.3 beta) systems, the
986 * OOB indication and data handling in the kernel
987 * is such that if two separate TCP Urgent requests
988 * come in, one byte of TCP data will be overlaid.
989 * This is fatal for Telnet, but we try to live
990 * with it.
991 *
992 * In addition, in 4.2 (and...), a special protocol
993 * is needed to pick up the TCP Urgent data in
994 * the correct sequence.
995 *
996 * What we do is: if we think we are in urgent
997 * mode, we look to see if we are "at the mark".
998 * If we are, we do an OOB receive. If we run
999 * this twice, we will do the OOB receive twice,
1000 * but the second will fail, since the second
1001 * time we were "at the mark", but there wasn't
1002 * any data there (the kernel doesn't reset
1003 * "at the mark" until we do a normal read).
1004 * Once we've read the OOB data, we go ahead
1005 * and do normal reads.
1006 *
1007 * There is also another problem, which is that
1008 * since the OOB byte we read doesn't put us
1009 * out of OOB state, and since that byte is most
1010 * likely the TELNET DM (data mark), we would
1011 * stay in the TELNET SYNCH (SYNCHing) state.
1012 * So, clocks to the rescue. If we've "just"
1013 * received a DM, then we test for the
1014 * presence of OOB data when the receive OOB
1015 * fails (and AFTER we did the normal mode read
1016 * to clear "at the mark").
1017 */
1018 if (SYNCHing) {
1019 int atmark;
1020
1021 ioctl(net, SIOCATMARK, (char *)&atmark);
1022 if (atmark) {
1023 ncc = recv(net, netibuf, sizeof (netibuf), MSG_OOB);
1024 if ((ncc == -1) && (errno == EINVAL)) {
1025 ncc = read(net, netibuf, sizeof (netibuf));
1026 if (sequenceIs(didnetreceive, gotDM)) {
1027 SYNCHing = stilloob(net);
1028 }
1029 }
1030 }
1031 else {
1032 ncc = read(net, netibuf, sizeof (netibuf));
1033 }
1034 }
1035 else {
1036 ncc = read(net, netibuf, sizeof (netibuf));
1037 }
1038 settimer(didnetreceive);
1039#else /* !defined(SO_OOBINLINE)) */
1040 ncc = read(net, netibuf, sizeof (netibuf));
1041#endif /* !defined(SO_OOBINLINE)) */
1042 if (ncc < 0 && errno == EWOULDBLOCK)
1043 ncc = 0;
1044 else {
1045 if (ncc <= 0) {
1046 break;
1047 }
1048 netip = netibuf;
1049 }
1050 DIAG((TD_REPORT | TD_NETDATA),
1051 netoprintf("td: netread %d chars\r\n", ncc););
1052 DIAG(TD_NETDATA, printdata("nd", netip, ncc));
1053 }
1054
1055 /*
1056 * Something to read from the pty...
1057 */
1058 if (FD_ISSET(p, &ibits)) {
1059 pcc = read(p, ptyibuf, BUFSIZ);
1060 /*
1061 * On some systems, if we try to read something
1062 * off the master side before the slave side is
1063 * opened, we get EIO.
1064 */
1065 if (pcc < 0 && (errno == EWOULDBLOCK || errno == EIO)) {
1066 pcc = 0;
1067 }
1068 else {
1069 if (pcc <= 0)
1070 break;
1071#ifdef LINEMODE
1072 /*
1073 * If ioctl from pty, pass it through net
1074 */
1075 if (ptyibuf[0] & TIOCPKT_IOCTL) {
1076 copy_termbuf(ptyibuf+1, pcc-1);
1077 localstat();
1078 pcc = 1;
1079 }
1080#endif /* LINEMODE */
1081 if (ptyibuf[0] & TIOCPKT_FLUSHWRITE) {
1082 static const char msg[] = { IAC, DM };
1083 netclear(); /* clear buffer back */
1084#ifndef NO_URGENT
1085 /*
1086 * There are client telnets on some
1087 * operating systems get screwed up
1088 * royally if we send them urgent
1089 * mode data.
1090 */
1091 sendurg(msg, sizeof(msg));
1092#endif
1093 }
1094 if (his_state_is_will(TELOPT_LFLOW) &&
1095 (ptyibuf[0] &
1096 (TIOCPKT_NOSTOP|TIOCPKT_DOSTOP))) {
1097 netoprintf("%c%c%c%c%c%c",
1098 IAC, SB, TELOPT_LFLOW,
1099 ptyibuf[0] & TIOCPKT_DOSTOP ? 1 : 0,
1100 IAC, SE);
1101 }
1102 pcc--;
1103 ptyip = ptyibuf+1;
1104 }
1105 }
1106
1107 while (pcc > 0 && !netbuflen(0)) {
1108 c = *ptyip++ & 0377, pcc--;
1109 if (c == IAC)
1110 putc(c, netfile);
1111 putc(c, netfile);
1112 if ((c == '\r' ) && (my_state_is_wont(TELOPT_BINARY))) {
1113 if (pcc > 0 && ((*ptyip & 0377) == '\n')) {
1114 putc(*ptyip++ & 0377, netfile);
1115 pcc--;
1116 }
1117 else putc('\0', netfile);
1118 }
1119 }
1120
1121 if (FD_ISSET(f, &obits))
1122 netflush();
1123 if (ncc > 0)
1124 telrcv();
1125 if (FD_ISSET(p, &obits) && (pfrontp - pbackp) > 0)
1126 ptyflush();
1127 }
1128 cleanup(0);
1129} /* end of telnet */
1130
1131#ifndef TCSIG
1132# ifdef TIOCSIG
1133# define TCSIG TIOCSIG
1134# endif
1135#endif
1136
1137/*
1138 * Send interrupt to process on other side of pty.
1139 * If it is in raw mode, just write NULL;
1140 * otherwise, write intr char.
1141 */
1142void interrupt(void) {
1143 ptyflush(); /* half-hearted */
1144
1145#ifdef TCSIG
1146 (void) ioctl(pty, TCSIG, (char *)SIGINT);
1147#else /* TCSIG */
1148 init_termbuf();
1149 *pfrontp++ = slctab[SLC_IP].sptr ?
1150 (unsigned char)*slctab[SLC_IP].sptr : '\177';
1151#endif /* TCSIG */
1152}
1153
1154/*
1155 * Send quit to process on other side of pty.
1156 * If it is in raw mode, just write NULL;
1157 * otherwise, write quit char.
1158 */
1159void sendbrk(void) {
1160 ptyflush(); /* half-hearted */
1161#ifdef TCSIG
1162 (void) ioctl(pty, TCSIG, (char *)SIGQUIT);
1163#else /* TCSIG */
1164 init_termbuf();
1165 *pfrontp++ = slctab[SLC_ABORT].sptr ?
1166 (unsigned char)*slctab[SLC_ABORT].sptr : '\034';
1167#endif /* TCSIG */
1168}
1169
1170void sendsusp(void) {
1171#ifdef SIGTSTP
1172 ptyflush(); /* half-hearted */
1173# ifdef TCSIG
1174 (void) ioctl(pty, TCSIG, (char *)SIGTSTP);
1175# else /* TCSIG */
1176 *pfrontp++ = slctab[SLC_SUSP].sptr ?
1177 (unsigned char)*slctab[SLC_SUSP].sptr : '\032';
1178# endif /* TCSIG */
1179#endif /* SIGTSTP */
1180}
1181
1182/*
1183 * When we get an AYT, if ^T is enabled, use that. Otherwise,
1184 * just send back "[Yes]".
1185 */
1186void recv_ayt(void) {
1187#if defined(SIGINFO) && defined(TCSIG)
1188 if (slctab[SLC_AYT].sptr && *slctab[SLC_AYT].sptr != _POSIX_VDISABLE) {
1189 (void) ioctl(pty, TCSIG, (char *)SIGINFO);
1190 return;
1191 }
1192#endif
1193 netoprintf("\r\n[%s : yes]\r\n", host_name);
1194}
1195
1196void doeof(void) {
1197 init_termbuf();
1198
1199#if defined(LINEMODE) && (VEOF == VMIN)
1200 if (!tty_isediting()) {
1201 extern char oldeofc;
1202 *pfrontp++ = oldeofc;
1203 return;
1204 }
1205#endif
1206 *pfrontp++ = slctab[SLC_EOF].sptr ?
1207 (unsigned char)*slctab[SLC_EOF].sptr : '\004';
1208}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.h b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.h
new file mode 100644
index 0000000..4c66824
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/telnetd.h
@@ -0,0 +1,50 @@
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)telnetd.h 5.3 (Berkeley) 3/1/91
34 * $Id: telnetd.h,v 1.2 1999/03/27 07:46:21 dholland Exp $
35 */
36
37
38#include "defs.h"
39#include "ext.h"
40#include <errno.h>
41
42#ifdef DIAGNOSTICS
43#define DIAG(a,b) if (diagnostic & (a)) b
44#else
45#define DIAG(a,b)
46#endif
47
48/* other external variables */
49extern char **environ;
50
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/termstat.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/termstat.c
new file mode 100644
index 0000000..1871480
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/termstat.c
@@ -0,0 +1,588 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)termstat.c 5.10 (Berkeley) 3/22/91
36 */
37char termstat_rcsid[] =
38 "$Id: termstat.c,v 1.6 1999/12/12 14:59:45 dholland Exp $";
39
40#include "telnetd.h"
41
42/*
43 * local variables
44 */
45int def_tspeed = -1, def_rspeed = -1;
46#ifdef TIOCSWINSZ
47int def_row = 0, def_col = 0;
48#endif
49#ifdef LINEMODE
50static int _terminit = 0;
51#endif /* LINEMODE */
52
53#ifdef LINEMODE
54/*
55 * localstat
56 *
57 * This function handles all management of linemode.
58 *
59 * Linemode allows the client to do the local editing of data
60 * and send only complete lines to the server. Linemode state is
61 * based on the state of the pty driver. If the pty is set for
62 * external processing, then we can use linemode. Further, if we
63 * can use real linemode, then we can look at the edit control bits
64 * in the pty to determine what editing the client should do.
65 *
66 * Linemode support uses the following state flags to keep track of
67 * current and desired linemode state.
68 * alwayslinemode : true if -l was specified on the telnetd
69 * command line. It means to have linemode on as much as
70 * possible.
71 *
72 * lmodetype: signifies whether the client can
73 * handle real linemode, or if use of kludgeomatic linemode
74 * is preferred. It will be set to one of the following:
75 * REAL_LINEMODE : use linemode option
76 * KLUDGE_LINEMODE : use kludge linemode
77 * NO_LINEMODE : client is ignorant of linemode
78 *
79 * linemode, uselinemode : linemode is true if linemode
80 * is currently on, uselinemode is the state that we wish
81 * to be in. If another function wishes to turn linemode
82 * on or off, it sets or clears uselinemode.
83 *
84 * editmode, useeditmode : like linemode/uselinemode, but
85 * these contain the edit mode states (edit and trapsig).
86 *
87 * The state variables correspond to some of the state information
88 * in the pty.
89 * linemode:
90 * In real linemode, this corresponds to whether the pty
91 * expects external processing of incoming data.
92 * In kludge linemode, this more closely corresponds to the
93 * whether normal processing is on or not. (ICANON in
94 * system V, or COOKED mode in BSD.)
95 * If the -l option was specified (alwayslinemode), then
96 * an attempt is made to force external processing on at
97 * all times.
98 *
99 * The following heuristics are applied to determine linemode
100 * handling within the server.
101 * 1) Early on in starting up the server, an attempt is made
102 * to negotiate the linemode option. If this succeeds
103 * then lmodetype is set to REAL_LINEMODE and all linemode
104 * processing occurs in the context of the linemode option.
105 * 2) If the attempt to negotiate the linemode option failed,
106 * then we try to use kludge linemode. We test for this
107 * capability by sending "do Timing Mark". If a positive
108 * response comes back, then we assume that the client
109 * understands kludge linemode (ech!) and the
110 * lmodetype flag is set to KLUDGE_LINEMODE.
111 * 3) Otherwise, linemode is not supported at all and
112 * lmodetype remains set to NO_LINEMODE (which happens
113 * to be 0 for convenience).
114 * 4) At any time a command arrives that implies a higher
115 * state of linemode support in the client, we move to that
116 * linemode support.
117 *
118 * A short explanation of kludge linemode is in order here.
119 * 1) The heuristic to determine support for kludge linemode
120 * is to send a do timing mark. We assume that a client
121 * that supports timing marks also supports kludge linemode.
122 * A risky proposition at best.
123 * 2) Further negotiation of linemode is done by changing the
124 * the server's state regarding SGA. If server will SGA,
125 * then linemode is off, if server won't SGA, then linemode
126 * is on.
127 */
128 void
129localstat()
130{
131 void netflush();
132 int need_will_echo = 0;
133
134 /*
135 * Check for state of BINARY options.
136 */
137 if (tty_isbinaryin()) {
138 if (his_want_state_is_wont(TELOPT_BINARY))
139 send_do(TELOPT_BINARY, 1);
140 } else {
141 if (his_want_state_is_will(TELOPT_BINARY))
142 send_dont(TELOPT_BINARY, 1);
143 }
144
145 if (tty_isbinaryout()) {
146 if (my_want_state_is_wont(TELOPT_BINARY))
147 send_will(TELOPT_BINARY, 1);
148 } else {
149 if (my_want_state_is_will(TELOPT_BINARY))
150 send_wont(TELOPT_BINARY, 1);
151 }
152
153 /*
154 * Check for changes to flow control if client supports it.
155 */
156 if (his_state_is_will(TELOPT_LFLOW)) {
157 if (tty_flowmode() != flowmode) {
158 flowmode = tty_flowmode();
159 (void) netoprintf("%c%c%c%c%c%c", IAC, SB,
160 TELOPT_LFLOW, flowmode, IAC, SE);
161 }
162 }
163
164 /*
165 * Check linemode on/off state
166 */
167 uselinemode = tty_linemode();
168
169 /*
170 * If alwayslinemode is on, and pty is changing to turn it off, then
171 * force linemode back on.
172 */
173 if (alwayslinemode && linemode && !uselinemode) {
174 uselinemode = 1;
175 tty_setlinemode(uselinemode);
176 }
177
178#if defined(ENCRYPT)
179 /*
180 * If the terminal is not echoing, but editing is enabled,
181 * something like password input is going to happen, so
182 * if we the other side is not currently sending encrypted
183 * data, ask the other side to start encrypting.
184 */
185 if (his_state_is_will(TELOPT_ENCRYPT)) {
186 static int enc_passwd = 0;
187 if (uselinemode && !tty_isecho() && tty_isediting()
188 && (enc_passwd == 0) && !decrypt_input) {
189 encrypt_send_request_start();
190 enc_passwd = 1;
191 } else if (enc_passwd) {
192 encrypt_send_request_end();
193 enc_passwd = 0;
194 }
195 }
196#endif
197
198 /*
199 * Do echo mode handling as soon as we know what the
200 * linemode is going to be.
201 * If the pty has echo turned off, then tell the client that
202 * the server will echo. If echo is on, then the server
203 * will echo if in character mode, but in linemode the
204 * client should do local echoing. The state machine will
205 * not send anything if it is unnecessary, so don't worry
206 * about that here.
207 *
208 * If we need to send the WILL ECHO (because echo is off),
209 * then delay that until after we have changed the MODE.
210 * This way, when the user is turning off both editing
211 * and echo, the client will get editing turned off first.
212 * This keeps the client from going into encryption mode
213 * and then right back out if it is doing auto-encryption
214 * when passwords are being typed.
215 */
216 if (uselinemode) {
217 if (tty_isecho())
218 send_wont(TELOPT_ECHO, 1);
219 else
220 need_will_echo = 1;
221 }
222
223 /*
224 * If linemode is being turned off, send appropriate
225 * command and then we're all done.
226 */
227 if (!uselinemode && linemode) {
228# ifdef KLUDGELINEMODE
229 if (lmodetype == REAL_LINEMODE) {
230# endif /* KLUDGELINEMODE */
231 send_dont(TELOPT_LINEMODE, 1);
232# ifdef KLUDGELINEMODE
233 } else if (lmodetype == KLUDGE_LINEMODE)
234 send_will(TELOPT_SGA, 1);
235# endif /* KLUDGELINEMODE */
236 send_will(TELOPT_ECHO, 1);
237 linemode = uselinemode;
238 goto done;
239 }
240
241# ifdef KLUDGELINEMODE
242 /*
243 * If using real linemode check edit modes for possible later use.
244 * If we are in kludge linemode, do the SGA negotiation.
245 */
246 if (lmodetype == REAL_LINEMODE) {
247# endif /* KLUDGELINEMODE */
248 useeditmode = 0;
249 if (tty_isediting())
250 useeditmode |= MODE_EDIT;
251 if (tty_istrapsig())
252 useeditmode |= MODE_TRAPSIG;
253 if (tty_issofttab())
254 useeditmode |= MODE_SOFT_TAB;
255 if (tty_islitecho())
256 useeditmode |= MODE_LIT_ECHO;
257# ifdef KLUDGELINEMODE
258 } else if (lmodetype == KLUDGE_LINEMODE) {
259 if (tty_isediting() && uselinemode)
260 send_wont(TELOPT_SGA, 1);
261 else
262 send_will(TELOPT_SGA, 1);
263 }
264# endif /* KLUDGELINEMODE */
265
266 /*
267 * Negotiate linemode on if pty state has changed to turn it on.
268 * Send appropriate command and send along edit mode, then all done.
269 */
270 if (uselinemode && !linemode) {
271# ifdef KLUDGELINEMODE
272 if (lmodetype == KLUDGE_LINEMODE) {
273 send_wont(TELOPT_SGA, 1);
274 } else if (lmodetype == REAL_LINEMODE) {
275# endif /* KLUDGELINEMODE */
276 send_do(TELOPT_LINEMODE, 1);
277 /* send along edit modes */
278 (void) netoprintf("%c%c%c%c%c%c%c", IAC, SB,
279 TELOPT_LINEMODE, LM_MODE, useeditmode,
280 IAC, SE);
281 editmode = useeditmode;
282# ifdef KLUDGELINEMODE
283 }
284# endif /* KLUDGELINEMODE */
285 linemode = uselinemode;
286 goto done;
287 }
288
289# ifdef KLUDGELINEMODE
290 /*
291 * None of what follows is of any value if not using
292 * real linemode.
293 */
294 if (lmodetype < REAL_LINEMODE)
295 goto done;
296# endif /* KLUDGELINEMODE */
297
298 if (linemode && his_state_is_will(TELOPT_LINEMODE)) {
299 /*
300 * If edit mode changed, send edit mode.
301 */
302 if (useeditmode != editmode) {
303 /*
304 * Send along appropriate edit mode mask.
305 */
306 (void) netoprintf("%c%c%c%c%c%c%c", IAC, SB,
307 TELOPT_LINEMODE, LM_MODE, useeditmode,
308 IAC, SE);
309 editmode = useeditmode;
310 }
311
312
313 /*
314 * Check for changes to special characters in use.
315 */
316 start_slc(0);
317 check_slc();
318 (void) end_slc(0);
319 }
320
321done:
322 if (need_will_echo)
323 send_will(TELOPT_ECHO, 1);
324 /*
325 * Some things should be deferred until after the pty state has
326 * been set by the local process. Do those things that have been
327 * deferred now. This only happens once.
328 */
329 if (_terminit == 0) {
330 _terminit = 1;
331 defer_terminit();
332 }
333
334 netflush();
335 set_termbuf();
336 return;
337
338} /* end of localstat */
339#endif /* LINEMODE */
340
341
342/*
343 * clientstat
344 *
345 * Process linemode related requests from the client.
346 * Client can request a change to only one of linemode, editmode or slc's
347 * at a time, and if using kludge linemode, then only linemode may be
348 * affected.
349 */
350void clientstat(register int code, register int parm1, register int parm2)
351{
352 /*
353 * Get a copy of terminal characteristics.
354 */
355 init_termbuf();
356
357 /*
358 * Process request from client. code tells what it is.
359 */
360 switch (code) {
361#ifdef LINEMODE
362 case TELOPT_LINEMODE:
363 /*
364 * Don't do anything unless client is asking us to change
365 * modes.
366 */
367 uselinemode = (parm1 == WILL);
368 if (uselinemode != linemode) {
369# ifdef KLUDGELINEMODE
370 /*
371 * If using kludge linemode, make sure that
372 * we can do what the client asks.
373 * We can not turn off linemode if alwayslinemode
374 * and the ICANON bit is set.
375 */
376 if (lmodetype == KLUDGE_LINEMODE) {
377 if (alwayslinemode && tty_isediting()) {
378 uselinemode = 1;
379 }
380 }
381
382 /*
383 * Quit now if we can't do it.
384 */
385 if (uselinemode == linemode)
386 return;
387
388 /*
389 * If using real linemode and linemode is being
390 * turned on, send along the edit mode mask.
391 */
392 if (lmodetype == REAL_LINEMODE && uselinemode)
393# else /* KLUDGELINEMODE */
394 if (uselinemode)
395# endif /* KLUDGELINEMODE */
396 {
397 useeditmode = 0;
398 if (tty_isediting())
399 useeditmode |= MODE_EDIT;
400 if (tty_istrapsig)
401 useeditmode |= MODE_TRAPSIG;
402 if (tty_issofttab())
403 useeditmode |= MODE_SOFT_TAB;
404 if (tty_islitecho())
405 useeditmode |= MODE_LIT_ECHO;
406 (void) netoprintf("%c%c%c%c%c%c%c", IAC,
407 SB, TELOPT_LINEMODE, LM_MODE,
408 useeditmode, IAC, SE);
409 editmode = useeditmode;
410 }
411
412
413 tty_setlinemode(uselinemode);
414
415 linemode = uselinemode;
416
417 }
418 break;
419
420 case LM_MODE:
421 {
422 register int ack, changed;
423
424 /*
425 * Client has sent along a mode mask. If it agrees with
426 * what we are currently doing, ignore it; if not, it could
427 * be viewed as a request to change. Note that the server
428 * will change to the modes in an ack if it is different from
429 * what we currently have, but we will not ack the ack.
430 */
431 useeditmode &= MODE_MASK;
432 ack = (useeditmode & MODE_ACK);
433 useeditmode &= ~MODE_ACK;
434
435 if (changed = (useeditmode ^ editmode)) {
436 /*
437 * This check is for a timing problem. If the
438 * state of the tty has changed (due to the user
439 * application) we need to process that info
440 * before we write in the state contained in the
441 * ack!!! This gets out the new MODE request,
442 * and when the ack to that command comes back
443 * we'll set it and be in the right mode.
444 */
445 if (ack)
446 localstat();
447 if (changed & MODE_EDIT)
448 tty_setedit(useeditmode & MODE_EDIT);
449
450 if (changed & MODE_TRAPSIG)
451 tty_setsig(useeditmode & MODE_TRAPSIG);
452
453 if (changed & MODE_SOFT_TAB)
454 tty_setsofttab(useeditmode & MODE_SOFT_TAB);
455
456 if (changed & MODE_LIT_ECHO)
457 tty_setlitecho(useeditmode & MODE_LIT_ECHO);
458
459 set_termbuf();
460
461 if (!ack) {
462 (void) netoprintf("%c%c%c%c%c%c%c", IAC,
463 SB, TELOPT_LINEMODE, LM_MODE,
464 useeditmode|MODE_ACK,
465 IAC, SE);
466 }
467
468 editmode = useeditmode;
469 }
470
471 break;
472
473 } /* end of case LM_MODE */
474#endif /* LINEMODE */
475
476 case TELOPT_NAWS:
477#ifdef TIOCSWINSZ
478 {
479 struct winsize ws;
480
481 def_col = parm1;
482 def_row = parm2;
483#ifdef LINEMODE
484 /*
485 * Defer changing window size until after terminal is
486 * initialized.
487 */
488 if (terminit() == 0)
489 return;
490#endif /* LINEMODE */
491
492 /*
493 * Change window size as requested by client.
494 */
495
496 ws.ws_col = parm1;
497 ws.ws_row = parm2;
498 (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
499 }
500#endif /* TIOCSWINSZ */
501
502 break;
503
504 case TELOPT_TSPEED:
505 {
506 def_tspeed = parm1;
507 def_rspeed = parm2;
508#ifdef LINEMODE
509 /*
510 * Defer changing the terminal speed.
511 */
512 if (terminit() == 0)
513 return;
514#endif /* LINEMODE */
515 /*
516 * Change terminal speed as requested by client.
517 * We set the receive speed first, so that if we can't
518 * store seperate receive and transmit speeds, the transmit
519 * speed will take precedence.
520 */
521 tty_rspeed(parm2);
522 tty_tspeed(parm1);
523 set_termbuf();
524
525 break;
526
527 } /* end of case TELOPT_TSPEED */
528
529 default:
530 /* What? */
531 break;
532 } /* end of switch */
533
534 netflush();
535
536} /* end of clientstat */
537
538#ifdef LINEMODE
539/*
540 * defer_terminit
541 *
542 * Some things should not be done until after the login process has started
543 * and all the pty modes are set to what they are supposed to be. This
544 * function is called when the pty state has been processed for the first time.
545 * It calls other functions that do things that were deferred in each module.
546 */
547 void
548defer_terminit()
549{
550
551 /*
552 * local stuff that got deferred.
553 */
554 if (def_tspeed != -1) {
555 clientstat(TELOPT_TSPEED, def_tspeed, def_rspeed);
556 def_tspeed = def_rspeed = 0;
557 }
558
559#ifdef TIOCSWINSZ
560 if (def_col || def_row) {
561 struct winsize ws;
562
563 bzero((char *)&ws, sizeof(ws));
564 ws.ws_col = def_col;
565 ws.ws_row = def_row;
566 (void) ioctl(pty, TIOCSWINSZ, (char *)&ws);
567 }
568#endif
569
570 /*
571 * The only other module that currently defers anything.
572 */
573 deferslc();
574
575} /* end of defer_terminit */
576
577/*
578 * terminit
579 *
580 * Returns true if the pty state has been processed yet.
581 */
582 int
583terminit()
584{
585 return _terminit;
586
587} /* end of terminit */
588#endif /* LINEMODE */
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/utility.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/utility.c
new file mode 100644
index 0000000..c51e65d
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetd/utility.c
@@ -0,0 +1,1266 @@
1/*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * From: @(#)utility.c 5.8 (Berkeley) 3/22/91
36 */
37char util_rcsid[] =
38 "$Id: utility.c,v 1.11 1999/12/12 14:59:45 dholland Exp $";
39
40#define PRINTOPTIONS
41
42#include <stdarg.h>
43#include <sys/utsname.h>
44#include <sys/time.h>
45
46#ifdef AUTHENTICATE
47#include <libtelnet/auth.h>
48#endif
49
50#include "telnetd.h"
51
52struct buflist {
53 struct buflist *next;
54 char *buf;
55 size_t len;
56};
57
58static struct buflist head = { next: &head, buf: 0, len: 0 };
59static struct buflist *tail = &head;
60static size_t skip;
61static int trailing;
62static size_t listlen;
63static int doclear;
64static struct buflist *urg;
65
66/*
67 * ttloop
68 *
69 * A small subroutine to flush the network output buffer, get some data
70 * from the network, and pass it through the telnet state machine. We
71 * also flush the pty input buffer (by dropping its data) if it becomes
72 * too full.
73 */
74
75void
76ttloop(void)
77{
78
79 DIAG(TD_REPORT, netoprintf("td: ttloop\r\n"););
80
81 netflush();
82 ncc = read(net, netibuf, sizeof(netibuf));
83 if (ncc < 0) {
84 syslog(LOG_INFO, "ttloop: read: %m\n");
85 exit(1);
86 } else if (ncc == 0) {
87 syslog(LOG_INFO, "ttloop: peer died: EOF\n");
88 exit(1);
89 }
90 DIAG(TD_REPORT, netoprintf("td: ttloop read %d chars\r\n", ncc););
91 netip = netibuf;
92 telrcv(); /* state machine */
93 if (ncc > 0) {
94 pfrontp = pbackp = ptyobuf;
95 telrcv();
96 }
97} /* end of ttloop */
98
99/*
100 * Check a descriptor to see if out of band data exists on it.
101 */
102int stilloob(int s) /* socket number */
103{
104 static struct timeval timeout = { 0, 0 };
105 fd_set excepts;
106 int value;
107
108 do {
109 FD_ZERO(&excepts);
110 FD_SET(s, &excepts);
111 value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout);
112 } while ((value == -1) && (errno == EINTR));
113
114 if (value < 0) {
115 fatalperror(pty, "select");
116 }
117 if (FD_ISSET(s, &excepts)) {
118 return 1;
119 } else {
120 return 0;
121 }
122}
123
124void ptyflush(void)
125{
126 int n;
127
128 if ((n = pfrontp - pbackp) > 0) {
129 DIAG((TD_REPORT | TD_PTYDATA),
130 netoprintf("td: ptyflush %d chars\r\n", n););
131 DIAG(TD_PTYDATA, printdata("pd", pbackp, n));
132 n = write(pty, pbackp, n);
133 }
134 if (n < 0) {
135 if (errno == EWOULDBLOCK || errno == EINTR)
136 return;
137 cleanup(0);
138 }
139 pbackp += n;
140 if (pbackp == pfrontp)
141 pbackp = pfrontp = ptyobuf;
142}
143
144/*
145 * nextitem()
146 *
147 * Return the address of the next "item" in the TELNET data
148 * stream. This will be the address of the next character if
149 * the current address is a user data character, or it will
150 * be the address of the character following the TELNET command
151 * if the current address is a TELNET IAC ("I Am a Command")
152 * character.
153 */
154static
155const char *
156nextitem(
157 const unsigned char *current, const unsigned char *end,
158 const unsigned char *next, const unsigned char *nextend
159) {
160 if (*current++ != IAC) {
161 while (current < end && *current++ != IAC)
162 ;
163 goto out;
164 }
165
166 if (current >= end) {
167 current = next;
168 if (!current) {
169 return 0;
170 }
171 end = nextend;
172 next = 0;
173 }
174
175 switch (*current++) {
176 case DO:
177 case DONT:
178 case WILL:
179 case WONT:
180 current++;
181 break;
182 case SB: /* loop forever looking for the SE */
183 for (;;) {
184 int iac;
185
186 while (iac = 0, current < end) {
187 if (*current++ == IAC) {
188 if (current >= end) {
189 iac = 1;
190 break;
191 }
192iac:
193 if (*current++ == SE) {
194 goto out;
195 }
196 }
197 }
198
199 current = next;
200 if (!current) {
201 return 0;
202 }
203 end = nextend;
204 next = 0;
205 if (iac) {
206 goto iac;
207 }
208 }
209 }
210
211out:
212 return next ? next + (current - end) : current;
213} /* end of nextitem */
214
215
216/*
217 * netclear()
218 *
219 * We are about to do a TELNET SYNCH operation. Clear
220 * the path to the network.
221 *
222 * Things are a bit tricky since we may have sent the first
223 * byte or so of a previous TELNET command into the network.
224 * So, we have to scan the network buffer from the beginning
225 * until we are up to where we want to be.
226 *
227 * A side effect of what we do, just to keep things
228 * simple, is to clear the urgent data pointer. The principal
229 * caller should be setting the urgent data pointer AFTER calling
230 * us in any case.
231 */
232void netclear(void)
233{
234 doclear++;
235 netflush();
236 doclear--;
237} /* end of netclear */
238
239static void
240netwritebuf(void)
241{
242 struct iovec *vector;
243 struct iovec *v;
244 struct buflist *lp;
245 ssize_t n;
246 size_t len;
247
248 vector = malloc(listlen * sizeof(struct iovec));
249 if (!vector) {
250 return;
251 }
252
253 len = listlen - (doclear & trailing);
254 v = vector;
255 lp = head.next;
256 while (lp != &head) {
257 if (lp == urg) {
258 len = v - vector;
259 if (!len) {
260 n = send(net, lp->buf, 1, MSG_OOB);
261 if (n > 0) {
262 urg = 0;
263 }
264 goto epi;
265 }
266 break;
267 }
268 v->iov_base = lp->buf;
269 v->iov_len = lp->len;
270 v++;
271 lp = lp->next;
272 }
273
274 vector->iov_base = (char *)vector->iov_base + skip;
275 vector->iov_len -= skip;
276
277 n = writev(net, vector, len);
278
279epi:
280 free(vector);
281
282 if (n < 0) {
283 if (errno != EWOULDBLOCK && errno != EINTR)
284 cleanup(0);
285 return;
286 }
287
288 len = n + skip;
289
290 lp = head.next;
291 while (lp->len <= len) {
292 len -= lp->len;
293
294 head.next = lp->next;
295 listlen--;
296 free(lp->buf);
297 free(lp);
298
299 lp = head.next;
300 if (lp == &head) {
301 tail = &head;
302 break;
303 }
304 }
305
306 skip = len;
307}
308
309/*
310 * netflush
311 * Send as much data as possible to the network,
312 * handling requests for urgent data.
313 */
314void
315netflush(void)
316{
317 if (fflush(netfile)) {
318 /* out of memory? */
319 cleanup(0);
320 }
321 if (listlen) {
322 netwritebuf();
323 }
324}
325
326
327/*
328 * miscellaneous functions doing a variety of little jobs follow ...
329 */
330
331
332void
333fatal(int f, const char *msg)
334{
335 char buf[BUFSIZ];
336
337 (void) snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg);
338#if defined(ENCRYPT)
339 if (encrypt_output) {
340 /*
341 * Better turn off encryption first....
342 * Hope it flushes...
343 */
344 encrypt_send_end();
345 netflush();
346 }
347#endif
348 (void) write(f, buf, (int)strlen(buf));
349 sleep(1); /*XXX*/
350 exit(1);
351}
352
353void
354fatalperror(int f, const char *msg)
355{
356 char buf[BUFSIZ];
357 snprintf(buf, sizeof(buf), "%s: %s\r\n", msg, strerror(errno));
358 fatal(f, buf);
359}
360
361char *editedhost;
362struct utsname kerninfo;
363
364void
365edithost(const char *pat, const char *host)
366{
367 char *res;
368
369 uname(&kerninfo);
370
371 if (!pat)
372 pat = "";
373
374 res = realloc(editedhost, strlen(pat) + strlen(host) + 1);
375 if (!res) {
376 if (editedhost) {
377 free(editedhost);
378 editedhost = 0;
379 }
380 fprintf(stderr, "edithost: Out of memory\n");
381 return;
382 }
383 editedhost = res;
384
385 while (*pat) {
386 switch (*pat) {
387
388 case '#':
389 if (*host)
390 host++;
391 break;
392
393 case '@':
394 if (*host)
395 *res++ = *host++;
396 break;
397
398 default:
399 *res++ = *pat;
400 break;
401 }
402 pat++;
403 }
404 if (*host)
405 (void) strcpy(res, host);
406 else
407 *res = '\0';
408}
409
410static char *putlocation;
411
412static
413void
414putstr(const char *s)
415{
416 while (*s) putchr(*s++);
417}
418
419void putchr(int cc)
420{
421 *putlocation++ = cc;
422}
423
424static char fmtstr[] = { "%H:%M on %A, %d %B %Y" };
425
426void putf(const char *cp, char *where)
427{
428 char *slash;
429 time_t t;
430 char db[100];
431
432 if (where)
433 putlocation = where;
434
435 while (*cp) {
436 if (*cp != '%') {
437 putchr(*cp++);
438 continue;
439 }
440 switch (*++cp) {
441
442 case 't':
443 slash = strrchr(line, '/');
444 if (slash == NULL)
445 putstr(line);
446 else
447 putstr(slash+1);
448 break;
449
450 case 'h':
451 if (editedhost) {
452 putstr(editedhost);
453 }
454 break;
455
456 case 'd':
457 (void)time(&t);
458 (void)strftime(db, sizeof(db), fmtstr, localtime(&t));
459 putstr(db);
460 break;
461
462 case '%':
463 putchr('%');
464 break;
465
466 case 'D':
467 {
468 char buff[128];
469
470 if (getdomainname(buff,sizeof(buff)) < 0
471 || buff[0] == '\0'
472 || strcmp(buff, "(none)") == 0)
473 break;
474 putstr(buff);
475 }
476 break;
477
478 case 'i':
479 {
480 char buff[3];
481 FILE *fp;
482 int p, c;
483
484 if ((fp = fopen(ISSUE_FILE, "r")) == NULL)
485 break;
486 p = '\n';
487 while ((c = fgetc(fp)) != EOF) {
488 if (p == '\n' && c == '#') {
489 do {
490 c = fgetc(fp);
491 } while (c != EOF && c != '\n');
492 continue;
493 } else if (c == '%') {
494 buff[0] = c;
495 c = fgetc(fp);
496 if (c == EOF) break;
497 buff[1] = c;
498 buff[2] = '\0';
499 putf(buff, NULL);
500 } else {
501 if (c == '\n') putchr('\r');
502 putchr(c);
503 p = c;
504 }
505 };
506 (void) fclose(fp);
507 }
508 return; /* ignore remainder of the banner string */
509 /*NOTREACHED*/
510
511 case 's':
512 putstr(kerninfo.sysname);
513 break;
514
515 case 'm':
516 putstr(kerninfo.machine);
517 break;
518
519 case 'r':
520 putstr(kerninfo.release);
521 break;
522
523 case 'v':
524#ifdef __linux__
525 putstr(kerninfo.version);
526#else
527 puts(kerninfo.version);
528#endif
529 break;
530 }
531 cp++;
532 }
533}
534
535#ifdef DIAGNOSTICS
536/*
537 * Print telnet options and commands in plain text, if possible.
538 */
539void
540printoption(const char *fmt, int option)
541{
542 if (TELOPT_OK(option))
543 netoprintf("%s %s\r\n", fmt, TELOPT(option));
544 else if (TELCMD_OK(option))
545 netoprintf("%s %s\r\n", fmt, TELCMD(option));
546 else
547 netoprintf("%s %d\r\n", fmt, option);
548}
549
550/* direction: '<' or '>' */
551/* pointer: where suboption data sits */
552/* length: length of suboption data */
553void
554printsub(char direction, unsigned char *pointer, int length)
555{
556 register int i = -1;
557#ifdef AUTHENTICATE
558 char buf[512];
559#endif
560
561 if (!(diagnostic & TD_OPTIONS))
562 return;
563
564 if (direction) {
565 netoprintf("td: %s suboption ",
566 direction == '<' ? "recv" : "send");
567 if (length >= 3) {
568 register int j;
569
570 i = pointer[length-2];
571 j = pointer[length-1];
572
573 if (i != IAC || j != SE) {
574 netoprintf("(terminated by ");
575 if (TELOPT_OK(i))
576 netoprintf("%s ", TELOPT(i));
577 else if (TELCMD_OK(i))
578 netoprintf("%s ", TELCMD(i));
579 else
580 netoprintf("%d ", i);
581 if (TELOPT_OK(j))
582 netoprintf("%s", TELOPT(j));
583 else if (TELCMD_OK(j))
584 netoprintf("%s", TELCMD(j));
585 else
586 netoprintf("%d", j);
587 netoprintf(", not IAC SE!) ");
588 }
589 }
590 length -= 2;
591 }
592 if (length < 1) {
593 netoprintf("(Empty suboption???)");
594 return;
595 }
596 switch (pointer[0]) {
597 case TELOPT_TTYPE:
598 netoprintf("TERMINAL-TYPE ");
599 switch (pointer[1]) {
600 case TELQUAL_IS:
601 netoprintf("IS \"%.*s\"", length-2, (char *)pointer+2);
602 break;
603 case TELQUAL_SEND:
604 netoprintf("SEND");
605 break;
606 default:
607 netoprintf("- unknown qualifier %d (0x%x).",
608 pointer[1], pointer[1]);
609 }
610 break;
611 case TELOPT_TSPEED:
612 netoprintf("TERMINAL-SPEED");
613 if (length < 2) {
614 netoprintf(" (empty suboption???)");
615 break;
616 }
617 switch (pointer[1]) {
618 case TELQUAL_IS:
619 netoprintf(" IS %.*s", length-2, (char *)pointer+2);
620 break;
621 default:
622 if (pointer[1] == 1)
623 netoprintf(" SEND");
624 else
625 netoprintf(" %d (unknown)", pointer[1]);
626 for (i = 2; i < length; i++) {
627 netoprintf(" ?%d?", pointer[i]);
628 }
629 break;
630 }
631 break;
632
633 case TELOPT_LFLOW:
634 netoprintf("TOGGLE-FLOW-CONTROL");
635 if (length < 2) {
636 netoprintf(" (empty suboption???)");
637 break;
638 }
639 switch (pointer[1]) {
640 case 0:
641 netoprintf(" OFF"); break;
642 case 1:
643 netoprintf(" ON"); break;
644 default:
645 netoprintf(" %d (unknown)", pointer[1]);
646 }
647 for (i = 2; i < length; i++) {
648 netoprintf(" ?%d?", pointer[i]);
649 }
650 break;
651
652 case TELOPT_NAWS:
653 netoprintf("NAWS");
654 if (length < 2) {
655 netoprintf(" (empty suboption???)");
656 break;
657 }
658 if (length == 2) {
659 netoprintf(" ?%d?", pointer[1]);
660 break;
661 }
662 netoprintf(" %d %d (%d)",
663 pointer[1], pointer[2],
664 (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2])));
665 if (length == 4) {
666 netoprintf(" ?%d?", pointer[3]);
667 break;
668 }
669 netoprintf(" %d %d (%d)",
670 pointer[3], pointer[4],
671 (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4])));
672 for (i = 5; i < length; i++) {
673 netoprintf(" ?%d?", pointer[i]);
674 }
675 break;
676
677 case TELOPT_LINEMODE:
678 netoprintf("LINEMODE ");
679 if (length < 2) {
680 netoprintf(" (empty suboption???)");
681 break;
682 }
683 switch (pointer[1]) {
684 case WILL:
685 netoprintf("WILL ");
686 goto common;
687 case WONT:
688 netoprintf("WONT ");
689 goto common;
690 case DO:
691 netoprintf("DO ");
692 goto common;
693 case DONT:
694 netoprintf("DONT ");
695 common:
696 if (length < 3) {
697 netoprintf("(no option???)");
698 break;
699 }
700 switch (pointer[2]) {
701 case LM_FORWARDMASK:
702 netoprintf("Forward Mask");
703 for (i = 3; i < length; i++) {
704 netoprintf(" %x", pointer[i]);
705 }
706 break;
707 default:
708 netoprintf("%d (unknown)", pointer[2]);
709 for (i = 3; i < length; i++) {
710 netoprintf(" %d", pointer[i]);
711 }
712 break;
713 }
714 break;
715
716 case LM_SLC:
717 netoprintf("SLC");
718 for (i = 2; i < length - 2; i += 3) {
719 if (SLC_NAME_OK(pointer[i+SLC_FUNC]))
720 netoprintf(" %s", SLC_NAME(pointer[i+SLC_FUNC]));
721 else
722 netoprintf(" %d", pointer[i+SLC_FUNC]);
723 switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) {
724 case SLC_NOSUPPORT:
725 netoprintf(" NOSUPPORT"); break;
726 case SLC_CANTCHANGE:
727 netoprintf(" CANTCHANGE"); break;
728 case SLC_VARIABLE:
729 netoprintf(" VARIABLE"); break;
730 case SLC_DEFAULT:
731 netoprintf(" DEFAULT"); break;
732 }
733 netoprintf("%s%s%s",
734 pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "",
735 pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "",
736 pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : "");
737 if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN|
738 SLC_FLUSHOUT| SLC_LEVELBITS)) {
739 netoprintf("(0x%x)", pointer[i+SLC_FLAGS]);
740 }
741 netoprintf(" %d;", pointer[i+SLC_VALUE]);
742 if ((pointer[i+SLC_VALUE] == IAC) &&
743 (pointer[i+SLC_VALUE+1] == IAC))
744 i++;
745 }
746 for (; i < length; i++) {
747 netoprintf(" ?%d?", pointer[i]);
748 }
749 break;
750
751 case LM_MODE:
752 netoprintf("MODE ");
753 if (length < 3) {
754 netoprintf("(no mode???)");
755 break;
756 }
757 {
758 char tbuf[32];
759 snprintf(tbuf, sizeof(tbuf), "%s%s%s%s%s",
760 pointer[2]&MODE_EDIT ? "|EDIT" : "",
761 pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
762 pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "",
763 pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "",
764 pointer[2]&MODE_ACK ? "|ACK" : "");
765 netoprintf("%s", tbuf[1] ? &tbuf[1] : "0");
766 }
767 if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) {
768 netoprintf(" (0x%x)", pointer[2]);
769 }
770 for (i = 3; i < length; i++) {
771 netoprintf(" ?0x%x?", pointer[i]);
772 }
773 break;
774 default:
775 netoprintf("%d (unknown)", pointer[1]);
776 for (i = 2; i < length; i++) {
777 netoprintf(" %d", pointer[i]);
778 }
779 }
780 break;
781
782 case TELOPT_STATUS: {
783 const char *cp;
784 register int j, k;
785
786 netoprintf("STATUS");
787
788 switch (pointer[1]) {
789 default:
790 if (pointer[1] == TELQUAL_SEND)
791 netoprintf(" SEND");
792 else
793 netoprintf(" %d (unknown)", pointer[1]);
794 for (i = 2; i < length; i++) {
795 netoprintf(" ?%d?", pointer[i]);
796 }
797 break;
798 case TELQUAL_IS:
799 netoprintf(" IS\r\n");
800
801 for (i = 2; i < length; i++) {
802 switch(pointer[i]) {
803 case DO: cp = "DO"; goto common2;
804 case DONT: cp = "DONT"; goto common2;
805 case WILL: cp = "WILL"; goto common2;
806 case WONT: cp = "WONT"; goto common2;
807 common2:
808 i++;
809 if (TELOPT_OK((int)pointer[i]))
810 netoprintf(" %s %s", cp, TELOPT(pointer[i]));
811 else
812 netoprintf(" %s %d", cp, pointer[i]);
813
814 netoprintf("\r\n");
815 break;
816
817 case SB:
818 netoprintf(" SB ");
819 i++;
820 j = k = i;
821 while (j < length) {
822 if (pointer[j] == SE) {
823 if (j+1 == length)
824 break;
825 if (pointer[j+1] == SE)
826 j++;
827 else
828 break;
829 }
830 pointer[k++] = pointer[j++];
831 }
832 printsub(0, &pointer[i], k - i);
833 if (i < length) {
834 netoprintf(" SE");
835 i = j;
836 } else
837 i = j - 1;
838
839 netoprintf("\r\n");
840
841 break;
842
843 default:
844 netoprintf(" %d", pointer[i]);
845 break;
846 }
847 }
848 break;
849 }
850 break;
851 }
852
853 case TELOPT_XDISPLOC:
854 netoprintf("X-DISPLAY-LOCATION ");
855 switch (pointer[1]) {
856 case TELQUAL_IS:
857 netoprintf("IS \"%.*s\"", length-2, (char *)pointer+2);
858 break;
859 case TELQUAL_SEND:
860 netoprintf("SEND");
861 break;
862 default:
863 netoprintf("- unknown qualifier %d (0x%x).",
864 pointer[1], pointer[1]);
865 }
866 break;
867
868 case TELOPT_ENVIRON:
869 netoprintf("ENVIRON ");
870 switch (pointer[1]) {
871 case TELQUAL_IS:
872 netoprintf("IS ");
873 goto env_common;
874 case TELQUAL_SEND:
875 netoprintf("SEND ");
876 goto env_common;
877 case TELQUAL_INFO:
878 netoprintf("INFO ");
879 env_common:
880 {
881 register int noquote = 2;
882 for (i = 2; i < length; i++ ) {
883 switch (pointer[i]) {
884 case ENV_VAR:
885 if (pointer[1] == TELQUAL_SEND)
886 goto def_case;
887 netoprintf("\" VAR " + noquote);
888 noquote = 2;
889 break;
890
891 case ENV_VALUE:
892 netoprintf("\" VALUE " + noquote);
893 noquote = 2;
894 break;
895
896 case ENV_ESC:
897 netoprintf("\" ESC " + noquote);
898 noquote = 2;
899 break;
900
901 default:
902 def_case:
903 if (isprint(pointer[i]) && pointer[i] != '"') {
904 if (noquote) {
905 netoprintf("\"");
906 noquote = 0;
907 }
908 netoprintf("%c", pointer[i]);
909 } else {
910 netoprintf("\" %03o " + noquote,
911 pointer[i]);
912 noquote = 2;
913 }
914 break;
915 }
916 }
917 if (!noquote)
918 netoprintf("\"");
919 break;
920 }
921 }
922 break;
923
924#if defined(AUTHENTICATE)
925 case TELOPT_AUTHENTICATION:
926 netoprintf("AUTHENTICATION");
927
928 if (length < 2) {
929 netoprintf(" (empty suboption???)");
930 break;
931 }
932 switch (pointer[1]) {
933 case TELQUAL_REPLY:
934 case TELQUAL_IS:
935 netoprintf(" %s ", (pointer[1] == TELQUAL_IS) ?
936 "IS" : "REPLY");
937 if (AUTHTYPE_NAME_OK(pointer[2]))
938 netoprintf("%s ", AUTHTYPE_NAME(pointer[2]));
939 else
940 netoprintf("%d ", pointer[2]);
941 if (length < 3) {
942 netoprintf("(partial suboption???)");
943 break;
944 }
945 netoprintf("%s|%s",
946 ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
947 "CLIENT" : "SERVER",
948 ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
949 "MUTUAL" : "ONE-WAY");
950
951 auth_printsub(&pointer[1], length - 1, buf, sizeof(buf));
952 netoprintf("%s", buf);
953 break;
954
955 case TELQUAL_SEND:
956 i = 2;
957 netoprintf(" SEND ");
958 while (i < length) {
959 if (AUTHTYPE_NAME_OK(pointer[i]))
960 netoprintf("%s ", AUTHTYPE_NAME(pointer[i]));
961 else
962 netoprintf("%d ", pointer[i]);
963 if (++i >= length) {
964 netoprintf("(partial suboption???)");
965 break;
966 }
967 netoprintf("%s|%s ",
968 ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ?
969 "CLIENT" : "SERVER",
970 ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ?
971 "MUTUAL" : "ONE-WAY");
972 ++i;
973 }
974 break;
975
976 case TELQUAL_NAME:
977 i = 2;
978 netoprintf(" NAME \"");
979 /*
980 * Was:
981 * while (i < length)
982 * *nfrontp += pointer[i++];
983 * *nfrontp += '"';
984 *
985 * but I'm pretty sure that's wrong...
986 */
987 while (i < length)
988 netoprintf("%c", pointer[i++]);
989 netoprintf("\"");
990 break;
991
992 default:
993 for (i = 2; i < length; i++) {
994 netoprintf(" ?%d?", pointer[i]);
995 }
996 break;
997 }
998 break;
999#endif
1000
1001#if defined(ENCRYPT)
1002 case TELOPT_ENCRYPT:
1003 netoprintf("ENCRYPT");
1004 if (length < 2) {
1005 netoprintf(" (empty suboption???)");
1006 break;
1007 }
1008 switch (pointer[1]) {
1009 case ENCRYPT_START:
1010 netoprintf(" START");
1011 break;
1012
1013 case ENCRYPT_END:
1014 netoprintf(" END");
1015 break;
1016
1017 case ENCRYPT_REQSTART:
1018 netoprintf(" REQUEST-START");
1019 break;
1020
1021 case ENCRYPT_REQEND:
1022 netoprintf(" REQUEST-END");
1023 break;
1024
1025 case ENCRYPT_IS:
1026 case ENCRYPT_REPLY:
1027 netoprintf(" %s ", (pointer[1] == ENCRYPT_IS) ?
1028 "IS" : "REPLY");
1029 if (length < 3) {
1030 netoprintf(" (partial suboption???)");
1031 break;
1032 }
1033 if (ENCTYPE_NAME_OK(pointer[2]))
1034 netoprintf("%s ", ENCTYPE_NAME(pointer[2]));
1035 else
1036 netoprintf(" %d (unknown)", pointer[2]);
1037
1038 encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf));
1039 netoprintf("%s", buf);
1040 break;
1041
1042 case ENCRYPT_SUPPORT:
1043 i = 2;
1044 netoprintf(" SUPPORT ");
1045 while (i < length) {
1046 if (ENCTYPE_NAME_OK(pointer[i]))
1047 netoprintf("%s ", ENCTYPE_NAME(pointer[i]));
1048 else
1049 netoprintf("%d ", pointer[i]);
1050 i++;
1051 }
1052 break;
1053
1054 case ENCRYPT_ENC_KEYID:
1055 netoprintf(" ENC_KEYID", pointer[1]);
1056 goto encommon;
1057
1058 case ENCRYPT_DEC_KEYID:
1059 netoprintf(" DEC_KEYID", pointer[1]);
1060 goto encommon;
1061
1062 default:
1063 netoprintf(" %d (unknown)", pointer[1]);
1064 encommon:
1065 for (i = 2; i < length; i++) {
1066 netoprintf(" %d", pointer[i]);
1067 }
1068 break;
1069 }
1070 break;
1071#endif
1072
1073 default:
1074 if (TELOPT_OK(pointer[0]))
1075 netoprintf("%s (unknown)", TELOPT(pointer[0]));
1076 else
1077 netoprintf("%d (unknown)", pointer[i]);
1078 for (i = 1; i < length; i++) {
1079 netoprintf(" %d", pointer[i]);
1080 }
1081 break;
1082 }
1083 netoprintf("\r\n");
1084}
1085
1086/*
1087 * Dump a data buffer in hex and ascii to the output data stream.
1088 */
1089void
1090printdata(const char *tag, const char *ptr, int cnt)
1091{
1092 register int i;
1093 char xbuf[30];
1094
1095 while (cnt) {
1096 /* add a line of output */
1097 netoprintf("%s: ", tag);
1098 for (i = 0; i < 20 && cnt; i++) {
1099 netoprintf("%02x", *ptr);
1100 if (isprint(*ptr)) {
1101 xbuf[i] = *ptr;
1102 } else {
1103 xbuf[i] = '.';
1104 }
1105 if (i % 2) {
1106 netoprintf(" ");
1107 }
1108 cnt--;
1109 ptr++;
1110 }
1111 xbuf[i] = '\0';
1112 netoprintf(" %s\r\n", xbuf );
1113 }
1114}
1115#endif /* DIAGNOSTICS */
1116
1117static struct buflist *
1118addbuf(const char *buf, size_t len)
1119{
1120 struct buflist *bufl;
1121
1122 bufl = malloc(sizeof(struct buflist));
1123 if (!bufl) {
1124 return 0;
1125 }
1126 bufl->next = tail->next;
1127 bufl->buf = malloc(len);
1128 if (!bufl->buf) {
1129 free(bufl);
1130 return 0;
1131 }
1132 bufl->len = len;
1133
1134 tail = tail->next = bufl;
1135 listlen++;
1136
1137 memcpy(bufl->buf, buf, len);
1138 return bufl;
1139}
1140
1141static ssize_t
1142netwrite(void *cookie, const char *buf, size_t len)
1143{
1144 size_t ret;
1145 const char *const end = buf + len;
1146 int ltrailing = trailing;
1147 int ldoclear = doclear;
1148
1149#define wewant(p) ((*p&0xff) == IAC) && \
1150 ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL)
1151
1152 ret = 0;
1153
1154 if (ltrailing) {
1155 const char *p;
1156 size_t l;
1157 size_t m = tail->len;
1158
1159 p = nextitem(tail->buf, tail->buf + tail->len, buf, end);
1160 ltrailing = !p;
1161 if (ltrailing) {
1162 p = end;
1163 }
1164
1165 l = p - buf;
1166 tail->len += l;
1167 tail->buf = realloc(tail->buf, tail->len);
1168 if (!tail->buf) {
1169 return -1;
1170 }
1171
1172 memcpy(tail->buf + m, buf, l);
1173 buf += l;
1174 len -= l;
1175 ret += l;
1176 trailing = ltrailing;
1177 }
1178
1179 if (ldoclear) {
1180 struct buflist *lpprev;
1181
1182 skip = 0;
1183 lpprev = &head;
1184 for (;;) {
1185 struct buflist *lp;
1186
1187 lp = lpprev->next;
1188
1189 if (lp == &head) {
1190 tail = lpprev;
1191 break;
1192 }
1193
1194 if (lp == tail && ltrailing) {
1195 break;
1196 }
1197
1198 if (!wewant(lp->buf)) {
1199 lpprev->next = lp->next;
1200 listlen--;
1201 free(lp->buf);
1202 free(lp);
1203 } else {
1204 lpprev = lp;
1205 }
1206 }
1207 }
1208
1209 while (len) {
1210 const char *p;
1211 size_t l;
1212
1213 p = nextitem(buf, end, 0, 0);
1214 ltrailing = !p;
1215 if (ltrailing) {
1216 p = end;
1217 } else if (ldoclear) {
1218 if (!wewant(buf)) {
1219 l = p - buf;
1220 goto cont;
1221 }
1222 }
1223
1224 l = p - buf;
1225 if (!addbuf(buf, l)) {
1226 return ret ? ret : -1;
1227 }
1228 trailing = ltrailing;
1229
1230cont:
1231 buf += l;
1232 len -= l;
1233 ret += l;
1234 }
1235
1236 netwritebuf();
1237 return ret;
1238}
1239
1240void
1241netopen() {
1242 static const cookie_io_functions_t funcs = {
1243 read: 0, write: netwrite, seek: 0, close: 0
1244 };
1245
1246 netfile = fopencookie(0, "w", funcs);
1247}
1248
1249extern int not42;
1250void
1251sendurg(const char *buf, size_t len) {
1252 if (!not42) {
1253 fwrite(buf, 1, len, netfile);
1254 return;
1255 }
1256
1257 urg = addbuf(buf, len);
1258}
1259
1260size_t
1261netbuflen(int flush) {
1262 if (flush) {
1263 netflush();
1264 }
1265 return listlen;
1266}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/Makefile b/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/Makefile
new file mode 100644
index 0000000..74d2680
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/Makefile
@@ -0,0 +1,18 @@
1all: telnetlogin
2
3include ../MCONFIG
4include ../MRULES
5
6OBJS = telnetlogin.o
7
8telnetlogin: $(OBJS)
9 $(CC) $(LDFLAGS) $^ $(LIBS) -o $@
10
11$(OBJS): ../version.h
12
13install: telnetlogin
14 install -s -m4750 -oroot -gtelnetd telnetlogin $(INSTALLROOT)$(SBINDIR)
15 install -m$(MANMODE) telnetlogin.8 $(INSTALLROOT)$(MANDIR)/man8
16
17clean:
18 rm -f *.o telnetlogin
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/telnetlogin.8 b/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/telnetlogin.8
new file mode 100644
index 0000000..2433fd8
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/telnetlogin.8
@@ -0,0 +1,91 @@
1.\" Copyright (c) 2000 David A. Holland.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by David A. Holland.
15.\" 4. Neither the name of the Author nor the names of any contributors
16.\" may be used to endorse or promote products derived from this software
17.\" without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND ANY CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR ANY CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\" $Id: telnetlogin.8,v 1.4 2000/07/30 23:57:10 dholland Exp $
32.\"
33.Dd April 12, 2000
34.Dt TELNETLOGIN 8
35.Os "Linux NetKit (0.17)"
36.Sh NAME
37.Nm telnetlogin
38.Nd login wrapper for telnetd
39.Sh SYNOPSIS
40.Nm telnetlogin
41.Op Fl h Ar host
42.Op Fl p
43.Op Ar username
44.Sh DESCRIPTION
45.Nm telnetlogin
46is a setuid wrapper that runs
47.Xr login 1 .
48It is meant to be invoked by
49.Xr telnetd 8 ;
50the idea is to remove the necessity of running telnetd as root.
51.Pp
52.Nm telnetlogin
53should be installed mode 4750, user root, group telnetd. Then,
54telnetd may be run from
55.Pa /etc/inetd.conf
56as user ``nobody'', group ``telnetd'', and with the option
57.Fl L Ar path-to-telnetlogin .
58.Pp
59.Nm telnetlogin
60accepts only the subset of options to
61.Xr login 1
62shown above, in the order listed. This is the order
63.Nm telnetd 8
64normally provides them in.
65.Nm telnetlogin
66also does sanity checks on the environment variables
67.Ev TERM ,
68and
69.Ev REMOTEHOST .
70It also insists that the standard input, output, and error streams are
71open on a terminal, and that it is the process group leader of the
72foreground process of that terminal. After checking all of these
73conditions, checking the values of the above environment variables for
74reasonable values, resetting signal handlers, and so forth, it execs
75login.
76.Sh SEE ALSO
77.Xr login 1 ,
78.Xr inetd.conf 5 ,
79.Xr inetd 8 ,
80.Xr telnetd 8
81.Sh RESTRICTIONS
82.Nm telnetlogin
83does not permit the
84.Fl f
85option to login, so will not
86work with telnetds that perform authentication via Kerberos or SSL.
87.Pp
88THIS IS PRESENTLY EXPERIMENTAL CODE; USE WITH CAUTION.
89.Sh HISTORY
90.Nm telnetlogin
91was written during the development of NetKit 0.17.
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/telnetlogin.c b/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/telnetlogin.c
new file mode 100644
index 0000000..bf81c12
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/telnetlogin/telnetlogin.c
@@ -0,0 +1,230 @@
1/*
2 * Copyright (c) 2000 David A. Holland.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by David A. Holland.
16 * 4. Neither the name of the Author nor the names of any contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND ANY CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR ANY CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33char copyright[] =
34 "@(#) Copyright (c) 2000 David A. Holland.\n"
35 "All rights reserved.\n";
36
37char rcsid[] =
38 "$Id: telnetlogin.c,v 1.1 2000/04/13 01:07:22 dholland Exp $";
39#include "../version.h"
40
41#include <sys/types.h>
42#include <sys/stat.h>
43#include <sys/ioctl.h>
44#include <netdb.h>
45#include <fcntl.h>
46#include <ctype.h>
47#include <paths.h>
48#include <signal.h>
49#include <unistd.h>
50#include <stdlib.h>
51#include <string.h>
52#include <stdarg.h>
53#include <stdio.h>
54#include <syslog.h>
55
56#ifndef _PATH_LOGIN
57#define _PATH_LOGIN "/bin/login"
58#endif
59
60static const char *remhost = NULL;
61
62static void die(const char *fmt, ...) {
63 va_list ap;
64 openlog("telnetlogin", LOG_PID, LOG_AUTHPRIV);
65 va_start(ap, fmt);
66 vsyslog(LOG_CRIT, fmt, ap);
67 va_end(ap);
68 exit(1);
69}
70
71static int check_a_hostname(char *hname) {
72 int i=0;
73 /* should we check length? */
74 for (i=0; hname[i]; i++) {
75 if (hname[i]<=32 && hname[i]>126) return -1;
76 }
77 return 0;
78}
79
80static int check_term(char *termtype) {
81 int i;
82 if (strlen(termtype) > 32) return -1;
83 for (i=0; termtype[i]; i++) {
84 if (!isalnum(termtype[i]) && !strchr("+._-", termtype[i])) return -1;
85 }
86 return 0;
87}
88
89static int check_remotehost(char *val) {
90 if (check_a_hostname(val)) return -1;
91 if (remhost && strcmp(val, remhost)) return -1;
92 return 0;
93}
94
95struct {
96 const char *name;
97 int (*validator)(char *);
98} legal_envs[] = {
99 { "TERM", check_term },
100 { "REMOTEHOST", check_remotehost },
101 { NULL, NULL }
102};
103
104static void validate_tty(void) {
105 struct stat buf, buf2;
106 const char *tty;
107 pid_t pgrp;
108
109 tty = ttyname(0);
110 if (!tty) die("stdin not a tty");
111
112 if (fstat(0, &buf)) die("fstat stdin");
113 if (!S_ISCHR(buf.st_mode)) die("stdin not char device");
114
115 if (fstat(1, &buf2)) die("fstat stdout");
116 if (!S_ISCHR(buf2.st_mode)) die("stdout not char device");
117 if (buf.st_rdev!=buf2.st_rdev) die("stdout and stdin not same tty");
118
119 if (fstat(2, &buf2)) die("fstat stderr");
120 if (!S_ISCHR(buf2.st_mode)) die("stderr not char device");
121 if (buf.st_rdev!=buf2.st_rdev) die("stderr and stdin not same tty");
122
123 if (ioctl(0, TIOCGPGRP, &pgrp)) die("cannot get tty process group");
124 if (pgrp != getpgrp()) die("not foreground pgrp of tty");
125 if (pgrp != getpid()) die("not process group leader");
126}
127
128int main(int argc, char *argv[]) {
129 static char argv0[] = "login";
130 int argn, i, j;
131 const char *rh = NULL;
132 char **envs = __environ;
133
134 /* make as sure as possible no library routines or anything can use it */
135 __environ = NULL;
136
137 /* first, make sure our stdin/stdout/stderr are aimed somewhere */
138 i = open("/", O_RDONLY);
139 if (i<3) {
140 /* Oops. Can't even print an error message... */
141 exit(100);
142 }
143 close(i);
144
145 /* check args */
146 argn=1;
147 if (argc<1) {
148 die("Illegal args: argc < 1");
149 }
150 if (argn < argc && !strcmp(argv[argn], "-h")) {
151 argn++;
152 if (argn==argc) die("Illegal args: -h requires argument");
153 if (check_a_hostname(argv[argn])) die("Illegal remote host specified");
154 rh = argv[argn];
155 argn++;
156 }
157 if (argn < argc && !strcmp(argv[argn], "-p")) {
158 argn++;
159 }
160 if (argn < argc && argv[argn][0] != '-') {
161 argn++;
162 }
163 if (argn < argc) die("Illegal args: too many args");
164 argv[0] = argv0;
165
166 /* check environment */
167 if (envs) for (i=0; envs[i]; i++) {
168 char *testenv = envs[i];
169 size_t testlen = strlen(testenv);
170 for (j=0; legal_envs[j].name; j++) {
171 const char *okenv = legal_envs[j].name;
172 size_t oklen = strlen(okenv);
173 int sign;
174
175 if (testlen < oklen) continue;
176 if (testenv[oklen]!='=') continue;
177 if ((sign = memcmp(testenv, okenv, oklen)) < 0) {
178 continue;
179 } else if (sign > 0) {
180 break;
181 }
182 if (legal_envs[j].validator(testenv+oklen+1)) {
183 die("Invalid environment: bad value for %s", okenv);
184 }
185 break;
186 }
187 }
188
189 /* unignore all signals so they get cleared at exec time */
190 for (i=1; i<NSIG; i++) {
191 signal(i, SIG_DFL);
192 }
193
194 /* just in case */
195 if (chdir("/")) die("chdir to / failed");
196
197 /*
198 * don't do anything with uids and gids, as login is normally meant
199 * to be able to take care of them.
200 *
201 * but, should we insist that ruid==nobody?
202 */
203
204#ifdef debian
205 /*
206 * Debian's /bin/login doesn't work properly unless we're really root.
207 */
208 setuid(0);
209#endif
210
211 /*
212 * don't do anything with limits, itimers, or process priority either
213 */
214
215 /*
216 * should we check to make sure stdin=stdout=stderr and they're a tty
217 * and it's our controlling tty [hard] and we're the leader of the
218 * foreground process group?
219 *
220 * Yeah, we should.
221 */
222 validate_tty();
223
224 /*
225 * now exec login
226 * argv[0] was set up above.
227 */
228 execve(_PATH_LOGIN, argv, envs);
229 exit(255);
230}
diff --git a/exploits/7350855-netkit/netkit-telnet-0.17/version.h b/exploits/7350855-netkit/netkit-telnet-0.17/version.h
new file mode 100644
index 0000000..ad92951
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.17/version.h
@@ -0,0 +1,5 @@
1/*
2 * String to embed in binaries to identify package
3 */
4
5char pkg[]="$NetKit: netkit-telnet-0.17 $";
diff --git a/exploits/7350855-netkit/netkit-telnet_0.16-4potato.1.diff.gz b/exploits/7350855-netkit/netkit-telnet_0.16-4potato.1.diff.gz
new file mode 100644
index 0000000..834255f
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet_0.16-4potato.1.diff.gz
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet_0.16-4potato.1.dsc b/exploits/7350855-netkit/netkit-telnet_0.16-4potato.1.dsc
new file mode 100644
index 0000000..9c2f3f2
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet_0.16-4potato.1.dsc
@@ -0,0 +1,23 @@
1-----BEGIN PGP SIGNED MESSAGE-----
2
3Format: 1.0
4Source: netkit-telnet
5Version: 0.16-4potato.1
6Binary: telnet, telnetd
7Maintainer: Herbert Xu <herbert@debian.org>
8Architecture: any
9Standards-Version: 3.0.1
10Files:
11 d829b432eec6a2ff0d866869445f1303 130043 netkit-telnet_0.16.orig.tar.gz
12 f045357b3041d23be595b484355669b1 8327 netkit-telnet_0.16-4potato.1.diff.gz
13
14-----BEGIN PGP SIGNATURE-----
15Version: 2.6.3ia
16Charset: noconv
17
18iQCVAwUBOctRj4fMnsf5AzQhAQGUVAP+Lsk8f2sXSnIhQ/XrtQUjpVjJwpS3Nzrq
19SWPok5C2QjERmN8W3/HmrYl2y1/3VQ5z5sVyVA3bcx+IMvs0U1130LVmhDOlANrP
20wmsRQ+8v5XJ9MD7eZs7FWligqlLfAno1WGIKZenTyKMPXrYjZD6pKUwk/54gITKB
21g5nCfW7xGvM=
22=X0FD
23-----END PGP SIGNATURE-----
diff --git a/exploits/7350855-netkit/netkit-telnet_0.16.orig.tar.gz b/exploits/7350855-netkit/netkit-telnet_0.16.orig.tar.gz
new file mode 100644
index 0000000..d0f2b45
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet_0.16.orig.tar.gz
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet_0.17-14.diff.gz b/exploits/7350855-netkit/netkit-telnet_0.17-14.diff.gz
new file mode 100644
index 0000000..33b44a8
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet_0.17-14.diff.gz
Binary files differ
diff --git a/exploits/7350855-netkit/netkit-telnet_0.17-14.dsc b/exploits/7350855-netkit/netkit-telnet_0.17-14.dsc
new file mode 100644
index 0000000..bb6f1e7
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet_0.17-14.dsc
@@ -0,0 +1,24 @@
1-----BEGIN PGP SIGNED MESSAGE-----
2
3Format: 1.0
4Source: netkit-telnet
5Version: 0.17-14
6Binary: telnetd, telnet
7Maintainer: Herbert Xu <herbert@debian.org>
8Architecture: any
9Standards-Version: 3.5.6
10Build-Depends: debhelper, libncurses-dev
11Files:
12 d6beabaaf53fe6e382c42ce3faa05a36 133749 netkit-telnet_0.17.orig.tar.gz
13 db744ae7670fd74c2e59461f8dfbdab2 20569 netkit-telnet_0.17-14.diff.gz
14
15-----BEGIN PGP SIGNATURE-----
16Version: 2.6.3ia
17Charset: noconv
18
19iQCVAwUBO3WsSofMnsf5AzQhAQHEUwP/VRhkHF/UGnQuIs+mrwX3rUTMZm1Cca1e
20LEM76qyNNdaHWl+150onqjouiOr0J5JKw+GD8+aPIClu7MhO1cyiJ05rbW+bK9WB
21Pb08HRYbrgfFtgV7AcxTakGaO4rX5TvIv78YeIUfgIIPOXZujthF12xBNSkJ2OTr
22UMANDZanXhc=
23=yuuq
24-----END PGP SIGNATURE-----
diff --git a/exploits/7350855-netkit/netkit-telnet_0.17.orig.tar.gz b/exploits/7350855-netkit/netkit-telnet_0.17.orig.tar.gz
new file mode 100644
index 0000000..5e7284a
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet_0.17.orig.tar.gz
Binary files differ
diff --git a/exploits/7350855-netkit/telnetd-0.16.tgz b/exploits/7350855-netkit/telnetd-0.16.tgz
new file mode 100644
index 0000000..53c4909
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd-0.16.tgz
Binary files differ
diff --git a/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/lib/telnetd/login b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/lib/telnetd/login
new file mode 100644
index 0000000..deb821b
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/lib/telnetd/login
Binary files differ
diff --git a/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/changelog.Debian.gz b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/changelog.Debian.gz
new file mode 100644
index 0000000..c8f1138
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/changelog.Debian.gz
Binary files differ
diff --git a/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/changelog.gz b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/changelog.gz
new file mode 100644
index 0000000..d064fe7
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/changelog.gz
Binary files differ
diff --git a/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/copyright b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/copyright
new file mode 100644
index 0000000..94881eb
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/doc/telnetd/copyright
@@ -0,0 +1,18 @@
1This package was split from netstd by Herbert Xu herbert@debian.org on
2Mon, 28 Sep 1998 16:50:43 +1000.
3
4netstd was created by Peter Tobias tobias@et-inf.fho-emden.de on
5Wed, 20 Jul 1994 17:23:21 +0200.
6
7It was downloaded from ftp://ftp.uk.linux.org/pub/linux/Networking/telnet+ftp/.
8
9Copyright:
10
11Copyright (c) 1988, 1993 The Regents of the University of California.
12Copyright (c) 1995 David A. Holland
13Copyright (c) 1994 Peter Tobias (issue.net(5))
14Copyright (c) 1983, 1995 Eric P. Allman (setproctitle.[ch])
15
16The license can be found at /usr/doc/copyright/BSD.
17
18$Id: copyright,v 1.2 2000/03/08 01:14:59 herbert Exp $
diff --git a/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man5/issue.net.5.gz b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man5/issue.net.5.gz
new file mode 100644
index 0000000..ffcbe91
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man5/issue.net.5.gz
Binary files differ
diff --git a/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man8/in.telnetd.8.gz b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man8/in.telnetd.8.gz
new file mode 100644
index 0000000..42dec03
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man8/in.telnetd.8.gz
Binary files differ
diff --git a/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man8/telnetd.8.gz b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man8/telnetd.8.gz
new file mode 120000
index 0000000..c433e1e
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd-potato-0.16-4-bin/usr/share/man/man8/telnetd.8.gz
@@ -0,0 +1 @@
in.telnetd.8.gz \ No newline at end of file
diff --git a/exploits/7350855-netkit/telnetd_0.16-4potato.1.deb b/exploits/7350855-netkit/telnetd_0.16-4potato.1.deb
new file mode 100644
index 0000000..2798ed0
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd_0.16-4potato.1.deb
Binary files differ
diff --git a/exploits/7350855-netkit/telnetd_0.17-13_i386.deb b/exploits/7350855-netkit/telnetd_0.17-13_i386.deb
new file mode 100644
index 0000000..195cbaa
--- /dev/null
+++ b/exploits/7350855-netkit/telnetd_0.17-13_i386.deb
Binary files differ